您的位置:首页 > 移动开发 > Android开发

[RK3288][Android6.0] TS-ADC驱动流程小结

2017-02-13 11:01 761 查看
Platform: RK3288

OS: Android 6.0

Kernel: 3.10.92

RK3288使用TSADC(Temperature-Sensor ADC)来测量CPU温度,支持两种模式:

用户自定义模式: 主动控制读取温度.

自动模式: 自动检测温度,达到阀值就自动报告.

rk3288.dtsi中的device配置:

tsadc: tsadc@ff280000 {

    compatible = "rockchip,tsadc";

    reg = <0xff280000 0x100>;

    interrupts = <GIC_SPI 37 IRQ_TYPE_LEVEL_HIGH>;

    #io-channel-cells = <1>;

    io-channel-ranges;

    clock-frequency = <10000>;

    clocks = <&clk_tsadc>, <&clk_gates7 2>;

    clock-names = "tsadc", "pclk_tsadc";

    pinctrl-names = "default", "tsadc_int";

    pinctrl-0 = <&tsadc_gpio>;

    pinctrl-1 = <&tsadc_int>;

    tsadc-ht-temp = <120>; //关机阀值

    tsadc-ht-reset-cru = <1>;

    tsadc-ht-pull-gpio = <0>;

    status = "okay";

};

rockchip_tsadc.c:

tsadc温度控制驱动文件.
rockchip-hwmon.c:

基于hwmon(HW Monitor)的驱动实现,也就是说tsadc使用hwmon提供接口到userspace.

rockchip_temp_probe ->     rockchip-hwmon.c

    rockchip_hwmon_init -> rockchip_tsadc.c

        request_threaded_irq    //申请一个中断线程,对应函数是rockchip_tsadc_auto_ht_interrupt()

        create_singlethread_workqueue    //创建workqueue thread,对应函数是rockchip_tsadc_auto_ht_work

        of_property_read_u32    //读取dts中的tsadc-ht-temp, tsadc-ht-reset-cru,tsadc-ht-pull-gpio

        rockchip_tsadc_set_auto_temp    //设置为自动温度探测模式,参数channel表示只针对此channel设置,rk3288 cpu对应是channel 1.

            rockchip_tsadc_auto_mode_set   ->  //设置中断和关机的温度, 分别对应的是80和120度

        data->ops.read_sensor = rockchip_rk3288_tsadc_get_temp;    //读取温度函数接口定义.

        INIT_DEFERRABLE_WORK(&data->work, tsadc_monitor);    //温度变化时更新sysfs中的alarm node信息.

        sysfs_create_group    //在tsadc device下创建sysfs,attr为rockchip_temp_group, 按照SENSOR_DEVICE_ATTR格式来定义,不过最终用的都是sysfs文件创建那一套.

        hwmon_device_register    //hwmon device注册, 会在/sys/class/hwmon下看到.

当达到80°的时候,中断被触发:

rockchip_tsadc_auto_ht_interrupt ->

    queue_work(dev->workqueue, &dev->auto_ht_irq_work) ->     //给workqueue执行

        rockchip_tsadc_auto_ht_work ->

            tsadc_readl        //读取中断状态

            pm_power_off    //过温就执行关机

实际测试中断并没有被触发(注意TSADC_TEMP_INT_EN的值是0),不过修改关机温度(tsadc-ht-temp)确实会关机,是TSSHUT触发直接硬件关机了。rockchip_tsadc_set_cmpn_shut_vale()设置了关机的阀值,参数就是tsadc-ht-temp对应的值。



命令行读取cpu温度:

root@rk3288:/ # cat sys/devices/ff280000.tsadc/temp1_input                     

54

或者

root@rk3288:/sys/class/hwmon/hwmon0/device # cat temp1_input                                        

55

平台上一共有四路sensor读取内部温度, 0保留,1读取cpu,2读取gpu, 3未知。

有趣的是,文档说系统有三路sensor,但是寄存器却给出了4路配置,醉了...

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: