MCU: VIM3: fixup temperature read issue
authorNick Xie <nick@khadas.com>
Wed, 26 Jun 2019 06:40:22 +0000 (14:40 +0800)
committerNick Xie <nick@khadas.com>
Wed, 26 Jun 2019 06:40:22 +0000 (14:40 +0800)
Signed-off-by: Nick Xie <nick@khadas.com>
drivers/amlogic/thermal/meson_tsensor.c
drivers/misc/khadas-mcu.c

index 1869983..1e2733c 100644 (file)
@@ -149,6 +149,8 @@ struct meson_tsensor_data {
        void (*tsensor_update_irqs)(struct meson_tsensor_data *data);
 };
 
+static struct meson_tsensor_data *g_tsensor_data_ptr;
+
 static void meson_report_trigger(struct meson_tsensor_data *p)
 {
        char data[10], *envp[] = { data, NULL };
@@ -510,6 +512,21 @@ static int meson_get_temp(void *p, int *temp)
        return 0;
 }
 
+int meson_get_temperature(void)
+{
+       int temp;
+       int ret;
+
+       ret = meson_get_temp(g_tsensor_data_ptr, &temp);
+       if (ret) {
+               printk("meson_get_temp failed!\n");
+               return ret;
+       }
+
+       return temp / 1000;
+}
+EXPORT_SYMBOL(meson_get_temperature);
+
 static void meson_tsensor_work(struct work_struct *work)
 {
 
@@ -679,6 +696,8 @@ static int meson_tsensor_probe(struct platform_device *pdev)
        platform_set_drvdata(pdev, data);
        mutex_init(&data->lock);
 
+       g_tsensor_data_ptr = data;
+
        data->clk = devm_clk_get(&pdev->dev, "ts_comp");
        if (IS_ERR(data->clk)) {
                dev_err(&pdev->dev, "Failed to get tsclock\n");
index 95ca930..558d5ec 100644 (file)
@@ -211,13 +211,17 @@ static void khadas_fan_level_set(struct khadas_fan_data *fan_data, int level)
 }
 
 extern int get_cpu_temp(void);
+extern int meson_get_temperature(void);
 static void fan_work_func(struct work_struct *_work)
 {
        if (is_mcu_fan_control_available()) {
                int temp = -EINVAL;
                struct khadas_fan_data *fan_data = &g_mcu_data->fan_data;
 
-               temp = get_cpu_temp();
+               if (KHADAS_BOARD_VIM2 == g_mcu_data->fan_data.board)
+                       temp = get_cpu_temp();
+               else if (KHADAS_BOARD_VIM3 == g_mcu_data->fan_data.board)
+                       temp = meson_get_temperature();
 
                if(temp != -EINVAL){
                        if(temp < fan_data->trig_temp_level0 ) {
@@ -348,7 +352,11 @@ static ssize_t show_fan_temp(struct class *cls,
                         struct class_attribute *attr, char *buf)
 {
        int temp = -EINVAL;
-    temp = get_cpu_temp();
+
+       if (KHADAS_BOARD_VIM2 == g_mcu_data->fan_data.board)
+               temp = get_cpu_temp();
+       else if (KHADAS_BOARD_VIM3 == g_mcu_data->fan_data.board)
+               temp = meson_get_temperature();
 
        return sprintf(buf, "cpu_temp:%d\nFan trigger temperature: level0:%d level1:%d level2:%d\n", temp, g_mcu_data->fan_data.trig_temp_level0, g_mcu_data->fan_data.trig_temp_level1, g_mcu_data->fan_data.trig_temp_level2);
 }