|
|
中文 / EN
|
We have both Temperature sensor and successive approximation Register
TS-ADC(Temperature Sensor): Support to 2 channel TS-ADC, the clock frequency must be less than 800KHZ.
SAR-ADC(Successive Approximation):It can convert the analog input signal into 10-bit binary digital codes at maximum conversion rate of 1MSPS with 13MHz A/D converter clock. It can support up to 6 channels input.
I would use the SAR-ADC in this tutorial giving you a view about how to attach a sensor here.
A sample of device tree
rk_headset: rk-headset { compatible = "rockchip_headset"; headset_gpio = <&gpio4 28 GPIO_ACTIVE_HIGH>; spk_con_gpio = <&gpio0 11 GPIO_ACTIVE_HIGH>; pinctrl-names = "default"; pinctrl-0 = <&hp_det>; io-channels = <&saradc 2>; };
You can find the driver file here: "drivers/headset_observe/rockchip_headset_core.c"
We define the specific programming model for the device.
static const struct of_device_id rockchip_headset_of_match[] = { { .compatible = "rockchip_headset", }, {}, };
platform_driver struct for platform device:
static struct platform_driver rockchip_headset_driver = { .probe = rockchip_headset_probe, .remove = rockchip_headset_remove, .resume = rockchip_headset_resume, .suspend = rockchip_headset_suspend, .driver = { .name = "rockchip_headset", .owner = THIS_MODULE, .of_match_table = of_match_ptr(rockchip_headset_of_match), }, };
Getting description of all that is needed to access channel here
pdata->chan = iio_channel_get(&pdev->dev, NULL);
How to get the ADC result:
iio_read_channel_raw() would read from a given channel, return the result following this calculation:
Vref / (2^n-1) = Vresult / raw
Vref: the reference voltage
n: resolution
Vresult: the final result of
raw: the raw value from ADC register
So for a reference of 1.8V and ADC result of 568 while the resolution is 10 bits:
Vresult = (1800mv * 568) / 1023