Rockchip soc thermal driver
Subsystems (3)
v5 cover Rockchip soc thermal driver
The Patch fix some code-style from Eduardo's and Heiko's omments.
But, The rui.zhang, Eduardo and Heiko are talking about hw-shut-temp The Patch isn't still fix it.
Changes in v5:
* address comments from Eduardo Valentin,rui.zhang and Heiko Stubner:
- with BIT() macro
- manage clocks in suspend/resume.
- license is fixed as GPLv2 .
- #include "thermal_core.h"->#include <linux/thermal.h>
- use the generic trip-points.the hw-shut-temp isn't generic trip-points.
- The method of binding and unbinding be fixed.
- The pin-name tsadc->otp_out
Changes in v4:
* address comments from Jonathan Cameron,huangtao and zhaoyifeng:
- this series thermal driver still be put in driver/thermal/
- modify the thermal driver description.
Changes in v3:(add dts configure)
* address comments from Dmitry Torokhov and Arnd Bergmann:
- fix clock-names in rockchip-thermal.txt
- remove rockchip_thermal_control() in rockchip_set_mode()
- fix some code style.
- add dts configure.
Changes in v2:
* address comments from Heiko Stubner:
- fix dt-bindings in rockchip-thermal.txt
- remove Author mark
- rename TSADC_XXX->TSADCV2_XXX,it eill ready to merge compatible other SoCs.
- fix a identation
- remove clk_set_rate(),it's no necessary.
- fix the SIMPLE_DEV_PM_OPS() function style.
Tested on rk3288 SDK board
Caesar Wang (4):
thermal: rockchip: add driver for Thermal
dt-bindings: document Rockchip thermal
ARM: dts: add main Thermal info to rk3288
ARM: dts: enable Thermal on rk3288-evb board
.../bindings/thermal/rockchip-thermal.txt | 41 ++ arch/arm/boot/dts/rk3288-evb.dtsi | 18 + arch/arm/boot/dts/rk3288.dtsi | 18 + drivers/thermal/Kconfig | 9 + drivers/thermal/Makefile | 1 + drivers/thermal/rockchip_thermal.c | 790 +++++++++++++++++++++ 6 files changed, 877 insertions(+) create mode 100644 Documentation/devicetree/bindings/thermal/rockchip-thermal.txt create mode 100644 drivers/thermal/rockchip_thermal.c
Signature · 1 line
1.9.1
PATCH v5 1/4 thermal: rockchip: add driver for Thermal
Thermal is TS-ADC Controller module supports
user-defined mode and automatic mode.
User-defined mode refers,TSADC all the control signals entirely by software writing to register for direct control.
Automaic mode refers to the module automatically poll TSADC output, and the results were checked.If you find that the temperature High in a period of time,an interrupt is generated to the processor down-measures taken;If the temperature over a period of time High, the resulting TSHUT gave CRU module,let it reset the entire chip, or via GPIO give PMIC.
--- drivers/thermal/Kconfig | 9 + drivers/thermal/Makefile | 1 + drivers/thermal/rockchip_thermal.c | 790 +++++++++++++++++++++++++++++++++++++ 3 files changed, 800 insertions(+) create mode 100644 drivers/thermal/rockchip_thermal.c
drivers/thermal/Kconfig +9 -0
@@ -133,6 +133,15 @@ config SPEAR_THERMAL Enable this to plug the SPEAr thermal sensor driver into the Linux thermal framework. +config ROCKCHIP_THERMAL + tristate "Rockchip thermal driver" + depends on ARCH_ROCKCHIP + help + Support for Temperature Sensor ADC (TS-ADC) found on Rockchip SoCs. + It supports one critical trip point and one passive trip point. The + cpufreq is used as the cooling device to throttle CPUs when the + passive trip is crossed. + config RCAR_THERMAL tristate "Renesas R-Car thermal driver" depends on ARCH_SHMOBILE || COMPILE_TEST
drivers/thermal/Makefile +1 -0
@@ -19,6 +19,7 @@ thermal_sys-$(CONFIG_CPU_THERMAL) += cpu_cooling.o # platform thermal drivers obj-$(CONFIG_SPEAR_THERMAL) += spear_thermal.o +obj-$(CONFIG_ROCKCHIP_THERMAL) += rockchip_thermal.o obj-$(CONFIG_RCAR_THERMAL) += rcar_thermal.o obj-$(CONFIG_KIRKWOOD_THERMAL) += kirkwood_thermal.o obj-y += samsung/
drivers/thermal/rockchip_thermal.c new file +790 -0
790 lines not on this page · raw message
Signature · 1 line
1.9.1
Re: [PATCH v5 1/4] thermal: rockchip: add driver for Thermal
Hi Caesar,
Quoted 28 lines · Caesar Wang
Thermal is TS-ADC Controller module supports
user-defined mode and automatic mode.User-defined mode refers,TSADC all the control signals entirely by software writing to register for direct control.
Automaic mode refers to the module automatically poll TSADC output, and the results were checked.If you find that the temperature High in a period of time,an interrupt is generated to the processor down-measures taken;If the temperature over a period of time High, the resulting TSHUT gave CRU module,let it reset the entire chip, or via GPIO give PMIC.
Signed-off-by zhaoyifeng <[email protected]>Signed-off-by Caesar Wang <[email protected]>--- drivers/thermal/Kconfig | 9 + drivers/thermal/Makefile | 1 + drivers/thermal/rockchip_thermal.c | 790 +++++++++++++++++++++++++++++++++++++ 3 files changed, 800 insertions(+) create mode 100644 drivers/thermal/rockchip_thermal.cdrivers/thermal/Kconfig +0
-0@@ -133,6 +133,15 @@ config SPEAR_THERMAL Enable this to plug the SPEAr thermal sensor driver into the Linux
drivers/thermal/Kconfig config SPEAR_THERMAL · line 143
Quoted 10 lines
drivers/thermal/Kconfig +8
-0thermal framework. +config ROCKCHIP_THERMAL + tristate "Rockchip thermal driver" + depends on ARCH_ROCKCHIP + help + Support for Temperature Sensor ADC (TS-ADC) found on Rockchip SoCs. + It supports one critical trip point and one passive trip point. The + cpufreq is used as the cooling device to throttle CPUs when the + passive trip is crossed.
Nit: the wording is a bit awkward. Maybe we should say something like the following:
Rockchip thermal driver provides support for Temperature Sensor ADC (TS-ADC) found on Rockchip SoCs. It supports one critical trip point and one passive trip point. Cpufreq is used as the cooling device and will throttle CPUs when the temperature crosses the passive trip point.
Quoted 24 lines
drivers/thermal/Kconfig +1
-0+ config RCAR_THERMAL tristate "Renesas R-Car thermal driver" depends on ARCH_SHMOBILE || COMPILE_TESTdrivers/thermal/Makefile +1
-0@@ -19,6 +19,7 @@ thermal_sys-$(CONFIG_CPU_THERMAL) += cpu_cooling.o # platform thermal drivers obj-$(CONFIG_SPEAR_THERMAL) += spear_thermal.o +obj-$(CONFIG_ROCKCHIP_THERMAL) += rockchip_thermal.o obj-$(CONFIG_RCAR_THERMAL) += rcar_thermal.o obj-$(CONFIG_KIRKWOOD_THERMAL) += kirkwood_thermal.o obj-y += samsung/drivers/thermal/rockchip_thermal.c new file +2
-0@@ -0,0 +1,790 @@ +/* +* Copyright (c) 2014, Fuzhou Rockchip Electronics Co., Ltd
drivers/thermal/rockchip_thermal.c line 12
Quoted 10 lines
drivers/thermal/rockchip_thermal.c new file +10
-0+* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +*
Nit: drop this one line.
Quoted 148 lines
drivers/thermal/rockchip_thermal.c new file +148
-0+*/ + +#include <linux/clk.h> +#include <linux/io.h> +#include <linux/interrupt.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/of_address.h> +#include <linux/of_irq.h> +#include <linux/platform_device.h> +#include <linux/regulator/consumer.h> +#include <linux/cpu_cooling.h> +#include <linux/thermal.h> + +struct rockchip_thermal_data { +const struct rockchip_tsadc_platform_data *pdata; +struct rockchip_thsens_platform_data *trip_tab; +struct thermal_zone_device *tz; +struct thermal_cooling_device *cdev; +enum thermal_device_mode mode; +void __iomem *regs; + +signed long temp_passive; +signed long temp_critical; +signed long temp_force_shut; +signed long alarm_temp; +signed long last_temp; +bool irq_enabled; +int irq; +struct clk *clk; +struct clk *pclk; +}; + +struct rockchip_tsadc_platform_data { +u8 irq_en; +signed long temp_passive; +signed long temp_critical; +signed long temp_force_shut; +int passive_delay; +int polling_delay; + +int (*irq_handle)(void __iomem *reg); +int (*initialize)(void __iomem *reg,signed long temp_force_shut); +int (*control)(void __iomem *reg,bool on); +u32 (*code_to_temp)(int temp); +u32 (*temp_to_code)(int temp); +void (*set_alarm_temp)(void __iomem *regs,signed long temp); +}; + +/*TSADC V2 Sensor info define:*/ +#define TSADCV2_AUTO_CON 0x04 +#define TSADCV2_INT_EN 0x08 +#define TSADCV2_INT_PD 0x0c +#define TSADCV2_DATA1 0x24 +#define TSADCV2_COMP1_INT 0x34 +#define TSADCV2_COMP1_SHUT 0x44 +#define TSADCV2_AUTO_PERIOD 0x68 +#define TSADCV2_AUTO_PERIOD_HT 0x6c + +#define TSADCV2_AUTO_SRC1_EN BIT(5) +#define TSADCV2_AUTO_EN BIT(0) +#define TSADCV2_AUTO_DISABLE ~BIT(0) +#define TSADCV2_AUTO_STAS_BUSY BIT(16) +#define TSADCV2_AUTO_STAS_BUSY_MASK BIT(16) +#define TSADCV2_SHUT_2GPIO_SRC1_EN BIT(5) +#define TSADCV2_INT_SRC1_EN BIT(1) +#define TSADCV2_SHUT_SRC1_STATUS BIT(5) +#define TSADCV2_INT_SRC1_STATUS BIT(1) +#define TSADCV2_INT_PD_CLEAR ~BIT(8) + +#define TSADCV2_DATA_MASK 0xfff +#define TSADCV2_HIGHT_INT_DEBOUNCE 0x60 +#define TSADCV2_HIGHT_TSHUT_DEBOUNCE 0x64 +#define TSADCV2_HIGHT_INT_DEBOUNCE_TIME 0x0a +#define TSADCV2_HIGHT_TSHUT_DEBOUNCE_TIME 0x0a +#define TSADCV2_AUTO_PERIOD_TIME 0x03e8 +#define TSADCV2_AUTO_PERIOD_HT_TIME 0x64 + +#define COOLING_DEV_MAX 8 + +struct rockchip_trip_point { +signed long temp; +enum thermal_trip_type type; +char cdev_name[COOLING_DEV_MAX ][THERMAL_NAME_LENGTH ]; +}; + +struct rockchip_thsens_platform_data { +struct rockchip_trip_point trip_points[THERMAL_MAX_TRIPS ]; +int num_trips; +}; + +struct tsadc_table { +int code; +int temp; +}; + +static const struct tsadc_table v2_code_table[] = { + {TSADCV2_DATA_MASK ,-40 }, + {3800 ,-40 }, + {3792 ,-35 }, + {3783 ,-30 }, + {3774 ,-25 }, + {3765 ,-20 }, + {3756 ,-15 }, + {3747 ,-10 }, + {3737 ,-5 }, + {3728 ,0 }, + {3718 ,5 }, + {3708 ,10 }, + {3698 ,15 }, + {3688 ,20 }, + {3678 ,25 }, + {3667 ,30 }, + {3656 ,35 }, + {3645 ,40 }, + {3634 ,45 }, + {3623 ,50 }, + {3611 ,55 }, + {3600 ,60 }, + {3588 ,65 }, + {3575 ,70 }, + {3563 ,75 }, + {3550 ,80 }, + {3537 ,85 }, + {3524 ,90 }, + {3510 ,95 }, + {3496 ,100 }, + {3482 ,105 }, + {3467 ,110 }, + {3452 ,115 }, + {3437 ,120 }, + {3421 ,125 }, + {0 ,125 }, +}; + +static int rk_tsadcv2_irq_handle (void __iomem *regs) +{ +u32 val; + + val =readl_relaxed (regs +TSADCV2_INT_PD ); +writel_relaxed (val &TSADCV2_INT_PD_CLEAR , regs +TSADCV2_INT_PD ); + +return 0 ; +} + +static u32 rk_tsadcv2_temp_to_code (int temp) +{ +int i;
drivers/thermal/rockchip_thermal.c line 170
Quoted 10 lines
drivers/thermal/rockchip_thermal.c new file +10
-0+ +for (i =0 ; i <ARRAY_SIZE (v2_code_table) -1 ; i++) { +if (temp <= v2_code_table[i].temp) +return v2_code_table[i].code; + } + +return 0 ; +} + +static u32 rk_tsadcv2_code_to_temp (int code)
The code table lists temperature as integer and I see negative values specified there. Are you sure that we want to convert it to u32?
Also, shouldn't the code be unsigned or u32?
drivers/thermal/rockchip_thermal.c line 179
Quoted 10 lines
drivers/thermal/rockchip_thermal.c new file +9
-0+{ +int i; + +for (i =0 ; i <ARRAY_SIZE (v2_code_table) -1 ; i++) { +if (code >= v2_code_table[i].code) +return v2_code_table[i].temp; + } + +return 0 ;
I think if we do not find the code we should be returning max temperature, not 0. And also WARN_ON() as this should not be happening.
Quoted 556 lines
drivers/thermal/rockchip_thermal.c new file +556
-0+} + +static int rk_tsadcv2_initialize (void __iomem *regs, +signed long temp_force_shut) +{ +int shutdown_value; + + shutdown_value =rk_tsadcv2_temp_to_code (temp_force_shut); +/* Enable measurements at ~ 10 Hz */ +writel_relaxed (0 , regs +TSADCV2_AUTO_CON ); +writel_relaxed (TSADCV2_AUTO_PERIOD_TIME , regs +TSADCV2_AUTO_PERIOD ); +writel_relaxed (TSADCV2_AUTO_PERIOD_HT_TIME , regs + +TSADCV2_AUTO_PERIOD_HT ); +writel_relaxed (shutdown_value, regs +TSADCV2_COMP1_SHUT ); +writel_relaxed (TSADCV2_HIGHT_INT_DEBOUNCE_TIME , regs + +TSADCV2_HIGHT_INT_DEBOUNCE ); +writel_relaxed (TSADCV2_HIGHT_TSHUT_DEBOUNCE_TIME , regs + +TSADCV2_HIGHT_TSHUT_DEBOUNCE ); +writel_relaxed (TSADCV2_SHUT_2GPIO_SRC1_EN |TSADCV2_INT_SRC1_EN , regs + +TSADCV2_INT_EN ); +writel_relaxed (TSADCV2_AUTO_SRC1_EN |TSADCV2_AUTO_EN , regs + +TSADCV2_AUTO_CON ); + +return 0 ; +} + +static int rk_tsadcv2_control (void __iomem *regs,bool on) +{ +u32 val; + +if (on) { + val =readl_relaxed (regs +TSADCV2_AUTO_CON ); +writel_relaxed (val |TSADCV2_AUTO_EN , regs +TSADCV2_AUTO_CON ); + }else { + val =readl_relaxed (regs +TSADCV2_AUTO_CON ); +writel_relaxed (val &TSADCV2_AUTO_DISABLE , + regs +TSADCV2_AUTO_CON ); + } + +return 0 ; +} + +static void rk_tsadcv2_alarm_temp (void __iomem *regs,signed long alarm_temp) +{ +int alarm_value; + + alarm_value =rk_tsadcv2_temp_to_code (alarm_temp); +writel_relaxed (alarm_value, regs +TSADCV2_COMP1_INT ); +} + +static const struct rockchip_tsadc_platform_data rk3288_tsadc_data = { + .irq_en =1 , + .temp_passive =85000 , + .temp_critical =100000 , + .temp_force_shut =120000 , + .passive_delay =2000 , + .polling_delay =1000 , + .irq_handle = rk_tsadcv2_irq_handle, + .initialize = rk_tsadcv2_initialize, + .control = rk_tsadcv2_control, + .code_to_temp = rk_tsadcv2_code_to_temp, + .temp_to_code = rk_tsadcv2_temp_to_code, + .set_alarm_temp = rk_tsadcv2_alarm_temp, +}; + +static const struct of_device_id of_rockchip_thermal_match[] = { + { + .compatible ="rockchip,rk3288-tsadc" , + .data = (void *)&rk3288_tsadc_data, + }, + {/* end */ }, +}; +MODULE_DEVICE_TABLE (of, of_rockchip_thermal_match); + +static void rockchip_set_alarm_temp (struct rockchip_thermal_data *data, +signed long alarm_temp) +{ +const struct rockchip_tsadc_platform_data *p_tsadc_data = data->pdata; + + data->alarm_temp = alarm_temp; +if (p_tsadc_data->set_alarm_temp) + p_tsadc_data->set_alarm_temp (data->regs, alarm_temp); +} + +static int rockchip_get_temp (struct thermal_zone_device *tz, +unsigned long *temp) +{ +struct rockchip_thermal_data *data = tz->devdata; +const struct rockchip_tsadc_platform_data *p_tsadc_data = data->pdata; +u32 val; + + val =readl_relaxed (data->regs +TSADCV2_DATA1 ); + *temp = p_tsadc_data->code_to_temp (val); + +/* Update alarm value to next higher trip point */ +if (data->alarm_temp == data->temp_passive && *temp >= + data->temp_passive) +rockchip_set_alarm_temp (data, data->temp_critical); + +if (data->alarm_temp == data->temp_critical && *temp < + data->temp_passive) { +rockchip_set_alarm_temp (data, data->temp_passive); +dev_dbg (&tz->device,"thermal alarm off: T < %lu\n" , + data->alarm_temp /1000 ); + } + +if (*temp != data->last_temp) { +dev_dbg (&tz->device,"millicelsius: %ld\n" , *temp); + data->last_temp = *temp; + } + +/* Reenable alarm IRQ if temperature below alarm temperature */ +if (!data->irq_enabled && *temp < data->alarm_temp) { + data->irq_enabled = true; +enable_irq (data->irq); + } + +return 0 ; +} + +static int rockchip_thermal_initialize (struct rockchip_thermal_data *data) +{ +const struct rockchip_tsadc_platform_data *p_tsadc_data = data->pdata; + +if (p_tsadc_data->initialize) + p_tsadc_data->initialize (data->regs, data->temp_force_shut); +rockchip_set_alarm_temp (data, data->temp_passive); + +return 0 ; +} + +static void rockchip_thermal_control (struct rockchip_thermal_data *data, +bool on) +{ +const struct rockchip_tsadc_platform_data *p_tsadc_data = data->pdata; + +if (p_tsadc_data->control) + p_tsadc_data->control (data->regs, on); + +if (on) { + data->irq_enabled = true; + data->mode =THERMAL_DEVICE_ENABLED ; + }else { + data->irq_enabled = false; + data->mode =THERMAL_DEVICE_DISABLED ; + } +} + +static int rockchip_get_mode (struct thermal_zone_device *tz, +enum thermal_device_mode *mode) +{ +struct rockchip_thermal_data *data = tz->devdata; + + *mode = data->mode; + +return 0 ; +} + +static int rockchip_set_mode (struct thermal_zone_device *tz, +enum thermal_device_mode mode) +{ +struct rockchip_thermal_data *data = tz->devdata; +const struct rockchip_tsadc_platform_data *p_tsadc_data = data->pdata; + +if (mode ==THERMAL_DEVICE_ENABLED ) { + tz->polling_delay = p_tsadc_data->polling_delay; + tz->passive_delay = p_tsadc_data->passive_delay; +if (!data->irq_enabled) { + data->irq_enabled = true; +enable_irq (data->irq); + } + }else { + tz->polling_delay =0 ; + tz->passive_delay =0 ; +if (data->irq_enabled) { +disable_irq (data->irq); + data->irq_enabled = false; + } + } + + data->mode = mode; +thermal_zone_device_update (tz); + +return 0 ; +} + +static int rockchip_get_trip_type (struct thermal_zone_device *tz,int trip, +enum thermal_trip_type *type) +{ +struct rockchip_thermal_data *data = tz->devdata; +struct rockchip_thsens_platform_data *ptrips = data->trip_tab; + +if (trip >= ptrips->num_trips) +return -EINVAL ; + + *type = ptrips->trip_points[trip].type; + +return 0 ; +} + +static int rockchip_get_crit_temp (struct thermal_zone_device *tz, +unsigned long *temp) +{ +struct rockchip_thermal_data *data = tz->devdata; + + *temp = data->temp_critical; + +return 0 ; +} + +static int rockchip_get_trip_temp (struct thermal_zone_device *tz,int trip, +unsigned long *temp) +{ +struct rockchip_thermal_data *data = tz->devdata; +struct rockchip_thsens_platform_data *ptrips = data->trip_tab; + +if (trip >= ptrips->num_trips) +return -EINVAL ; + *temp = ptrips->trip_points[trip].temp; + +return 0 ; +} + +static int rockchip_set_trip_temp (struct thermal_zone_device *tz,int trip, +unsigned long temp) +{ +struct rockchip_thermal_data *data = tz->devdata; +struct rockchip_thsens_platform_data *ptrips = data->trip_tab; + +if (trip >= ptrips->num_trips) +return -EINVAL ; + + data->temp_passive = temp; +rockchip_set_alarm_temp (data, temp); + +return 0 ; +} + +/* Local function to check if thermal zone matches cooling devices */ +static int rockchip_thermal_match_cdev (struct thermal_cooling_device *cdev, +struct rockchip_trip_point *trip_point) +{ +int i; + +if (!strlen (cdev->type)) +return -EINVAL ; + +for (i =0 ; i <COOLING_DEV_MAX ; i++) { +if (!strcmp (trip_point->cdev_name[i], cdev->type)) +return 0 ; + } + +return -ENODEV ; +} + +/* Callback to bind cooling device to thermal zone */ +static int rockchip_cdev_bind (struct thermal_zone_device *tz, +struct thermal_cooling_device *cdev) +{ +struct rockchip_thermal_data *data = tz->devdata; +struct rockchip_thsens_platform_data *ptrips = data->trip_tab; +unsigned long max_state, upper, lower; +int i, ret = -EINVAL ; + + cdev->ops->get_max_state (cdev, &max_state); + +for (i =0 ; i < ptrips->num_trips; i++) { +if (rockchip_thermal_match_cdev (cdev, &ptrips->trip_points[i])) +continue ; + + lower = i > max_state ? max_state : i; + upper = lower; + + ret =thermal_zone_bind_cooling_device (tz, i, cdev, + upper, lower); + +dev_info (&cdev->device,"%s bind to %d: %d-%s\n" , cdev->type, + i, ret, ret ?"fail" :"succeed" ); + } + +return ret; +} + +/* Callback to unbind cooling device from thermal zone */ +static int rockchip_cdev_unbind (struct thermal_zone_device *tz, +struct thermal_cooling_device *cdev) +{ +struct rockchip_thermal_data *data = tz->devdata; +struct rockchip_thsens_platform_data *ptrips = data->trip_tab; +int i, ret = -EINVAL ; + +for (i =0 ; i < ptrips->num_trips; i++) { +if (rockchip_thermal_match_cdev (cdev, &ptrips->trip_points[i])) +continue ; + + ret =thermal_zone_unbind_cooling_device (tz, i, cdev); + +dev_info (&cdev->device,"%s unbind from %d: %s\n" , cdev->type, + i, ret ?"fail" :"succeed" ); + } + +return ret; +} + +static struct thermal_zone_device_ops rockchip_tz_ops = { + .bind = rockchip_cdev_bind, + .unbind = rockchip_cdev_unbind, + .get_temp = rockchip_get_temp, + .get_mode = rockchip_get_mode, + .set_mode = rockchip_set_mode, + .get_trip_type = rockchip_get_trip_type, + .get_trip_temp = rockchip_get_trip_temp, + .get_crit_temp = rockchip_get_crit_temp, + .set_trip_temp = rockchip_set_trip_temp, +}; + +static irqreturn_t rockchip_thermal_alarm_irq_thread (int irq,void *dev) +{ +struct rockchip_thermal_data *data = data; +const struct rockchip_tsadc_platform_data *p_tsadc_data = data->pdata; + +dev_dbg (&data->tz->device,"THERMAL ALARM: T > %lu\n" , + data->alarm_temp /1000 ); + +if (p_tsadc_data->irq_en && p_tsadc_data->irq_handle) + p_tsadc_data->irq_handle (data->regs); + +thermal_zone_device_update (data->tz); + +return IRQ_HANDLED ; +} + +static struct rockchip_thsens_platform_data * +rockchip_thermal_parse_dt (struct platform_device *pdev) +{ +struct rockchip_thsens_platform_data *ptrips; +struct device_node *np = pdev->dev.of_node; +char prop_name[32 ]; +const char *tmp_str; +u32 tmp_data; +int i, j; + + ptrips =devm_kzalloc (&pdev->dev,sizeof (*ptrips),GFP_KERNEL ); +if (!ptrips) +return NULL ; + +if (of_property_read_u32 (np,"num-trips" , &tmp_data)) + goto err_parse_dt; + +if (tmp_data >THERMAL_MAX_TRIPS ) + goto err_parse_dt; + + ptrips->num_trips = tmp_data; + +for (i =0 ; i < ptrips->num_trips; i++) { +sprintf (prop_name,"trip%d-temp" , i); +if (of_property_read_u32 (np, prop_name, &tmp_data)) + goto err_parse_dt; + + ptrips->trip_points[i].temp = tmp_data; +sprintf (prop_name,"trip%d-type" , i); +if (of_property_read_string (np, prop_name, &tmp_str)) + goto err_parse_dt; + +if (!strcmp (tmp_str,"active" )) + ptrips->trip_points[i].type =THERMAL_TRIP_ACTIVE ; +else if (!strcmp (tmp_str,"passive" )) + ptrips->trip_points[i].type =THERMAL_TRIP_PASSIVE ; +else if (!strcmp (tmp_str,"hot" )) + ptrips->trip_points[i].type =THERMAL_TRIP_HOT ; +else if (!strcmp (tmp_str,"critical" )) + ptrips->trip_points[i].type =THERMAL_TRIP_CRITICAL ; +else + goto err_parse_dt; + +sprintf (prop_name,"trip%d-cdev-num" , i); +if (of_property_read_u32 (np, prop_name, &tmp_data)) + goto err_parse_dt; + +if (tmp_data >COOLING_DEV_MAX ) + goto err_parse_dt; + +for (j =0 ; j < tmp_data; j++) { +sprintf (prop_name,"trip%d-cdev-name%d" , i, j); +if (of_property_read_string (np, prop_name, &tmp_str)) + goto err_parse_dt; + +if (strlen (tmp_str) >=THERMAL_NAME_LENGTH ) + goto err_parse_dt; + +strcpy (ptrips->trip_points[i].cdev_name[j], tmp_str); + } + } +return ptrips; + +err_parse_dt: +dev_err (&pdev->dev,"Parsing device tree data error.\n" ); +return NULL ; +} + +static int rockchip_thermal_probe (struct platform_device *pdev) +{ +struct rockchip_thermal_data *data; +const struct rockchip_tsadc_platform_data *p_tsadc_data; +const struct of_device_id *match; +struct rockchip_thsens_platform_data *ptrips =NULL ; +struct cpumask clip_cpus; +struct resource *res; +struct device_node *np = pdev->dev.of_node; + +int ret, temp; + + ptrips =rockchip_thermal_parse_dt (pdev); +if (!ptrips) +return -EINVAL ; + + data =devm_kzalloc (&pdev->dev,sizeof (struct rockchip_thermal_data ), +GFP_KERNEL ); +if (!data) +return -ENOMEM ; + + data->trip_tab = ptrips; + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + data->regs =devm_ioremap_resource (&pdev->dev, res); +if (IS_ERR (data->regs)) { +dev_err (&pdev->dev,"Could not get tsadc source, %p\n" , + data->regs); +return PTR_ERR (data->regs); + } + + match =of_match_node (of_rockchip_thermal_match, np); +if (!match) +return -ENXIO ; + data->pdata = (const struct rockchip_tsadc_platform_data *)match->data; +if (!data->pdata) +return -EINVAL ; + p_tsadc_data = data->pdata; + + data->clk =devm_clk_get (&pdev->dev,"tsadc" ); +if (IS_ERR (data->clk)) { +dev_err (&pdev->dev,"failed to get tsadc clock\n" ); +return PTR_ERR (data->clk); + } + + data->pclk =devm_clk_get (&pdev->dev,"apb_pclk" ); +if (IS_ERR (data->pclk)) { +dev_err (&pdev->dev,"failed to get tsadc pclk\n" ); +return PTR_ERR (data->pclk); + } + +/* +* Use a default of 10KHz for the converter clock. +* This may become user-configurable in the future. +*/ + ret =clk_set_rate (data->clk,10000 ); +if (ret <0 ) { +dev_err (&pdev->dev,"failed to set tsadc clk rate, %d\n" , ret); +return ret; + } + + ret =clk_prepare_enable (data->clk); +if (ret <0 ) { +dev_err (&pdev->dev,"failed to enable converter clock\n" ); + goto err_clk; + } + + ret =clk_prepare_enable (data->pclk); +if (ret <0 ) { +dev_err (&pdev->dev,"failed to enable pclk\n" ); + goto err_pclk; + } + +platform_set_drvdata (pdev, data); + +if (of_property_read_u32 (pdev->dev.of_node,"hw-shut-temp" , &temp)) { +dev_warn (&pdev->dev, +"Missing default force shut down temp property in the DT.\n" ); + data->temp_force_shut = p_tsadc_data->temp_force_shut; + }else { + data->temp_force_shut = temp; + } + + data->temp_passive = ptrips->trip_points[0 ].temp; + data->temp_critical = ptrips->trip_points[1 ].temp; + +cpumask_set_cpu (0 , &clip_cpus); + data->cdev =of_cpufreq_cooling_register (np, &clip_cpus); +if (IS_ERR (data->cdev)) { +dev_err (&pdev->dev,"failed to register cpufreq cooling device\n" ); + goto disable_clk; + } + + data->tz =thermal_zone_device_register ("rockchip_thermal" , + ptrips->num_trips, +0 , data, + &rockchip_tz_ops,NULL , + p_tsadc_data->passive_delay, + p_tsadc_data->polling_delay); +if (IS_ERR (data->tz)) { +dev_err (&pdev->dev,"failed to register thermal zone device\n" ); + goto fail_cpufreq_register; + } + +if (p_tsadc_data->irq_en) { + data->irq =platform_get_irq (pdev,0 ); +if (data->irq <0 ) { +dev_err (&pdev->dev,"no irq resource?\n" ); + goto fail_irq; + } + + ret =devm_request_threaded_irq (&pdev->dev, data->irq, +NULL , &rockchip_thermal_alarm_irq_thread, +IRQF_ONESHOT ,"rockchip_thermal" , + data); +if (ret <0 ) { +dev_err (&pdev->dev, +"failed to request tsadc irq: %d\n" , ret); + goto fail_thermal_unregister; + } + } + +rockchip_thermal_initialize (data); +rockchip_thermal_control (data, true); + +return 0 ; + +fail_thermal_unregister: +thermal_zone_device_unregister (data->tz); +fail_irq: +fail_cpufreq_register: +cpufreq_cooling_unregister (data->cdev); +disable_clk: +err_pclk: +clk_disable_unprepare (data->pclk); +err_clk: +clk_disable_unprepare (data->clk); + +return ret; +} + +static int rockchip_thermal_remove (struct platform_device *pdev) +{ +struct rockchip_thermal_data *data =platform_get_drvdata (pdev); + +rockchip_thermal_control (data, false); + +thermal_zone_device_unregister (data->tz); +cpufreq_cooling_unregister (data->cdev); + +clk_disable_unprepare (data->clk); +clk_disable_unprepare (data->pclk); + +return 0 ; +} +
drivers/thermal/rockchip_thermal.c line 745
Quoted 10 lines
drivers/thermal/rockchip_thermal.c new file +10
-0+#ifdef CONFIG_PM_SLEEP +static int rockchip_thermal_suspend (struct device *dev) +{ +struct platform_device *pdev =to_platform_device (dev); +struct rockchip_thermal_data *data =platform_get_drvdata (pdev); + +rockchip_thermal_control (data, false); + +clk_disable_unprepare (data->clk); +clk_disable_unprepare (data->pclk);
Nit: I do not think you need to "unprepare" clocks in suspend, just disabling them should be fine.
drivers/thermal/rockchip_thermal.c line 756
Quoted 11 lines
drivers/thermal/rockchip_thermal.c new file +11
-0+ +return 0 ; +} + +static int rockchip_thermal_resume (struct device *dev) +{ +struct platform_device *pdev =to_platform_device (dev); +struct rockchip_thermal_data *data =platform_get_drvdata (pdev); +int ret; + + ret =clk_prepare_enable (data->pclk);
And simply clk_enable() here.
Quoted 38 lines
drivers/thermal/rockchip_thermal.c new file +34
-0+if (ret) +return ret; + + ret =clk_prepare_enable (data->clk); +if (ret) +return ret; + +rockchip_thermal_initialize (data); +rockchip_thermal_control (data, true); + +return 0 ; +} +#endif + +static SIMPLE_DEV_PM_OPS(rockchip_thermal_pm_ops, + rockchip_thermal_suspend, rockchip_thermal_resume); + +static struct platform_driver rockchip_thermal_driver = { + .driver = { + .name ="rockchip-thermal" , + .owner =THIS_MODULE , + .pm = &rockchip_thermal_pm_ops, + .of_match_table = of_rockchip_thermal_match, + }, + .probe = rockchip_thermal_probe, + .remove = rockchip_thermal_remove, +}; + +module_platform_driver (rockchip_thermal_driver); + +MODULE_DESCRIPTION ("ROCKCHIP THERMAL Driver" ); +MODULE_AUTHOR ("Rockchip, Inc." ); +MODULE_LICENSE ("GPL v2" ); +MODULE_ALIAS ("platform:rockchip-thermal" );Signature · 1 line
1.9.1
Thanks.
Signature · 1 line
Dmitry
Re: [PATCH v5 1/4] thermal: rockchip: add driver for Thermal
Dear Dmitry,
? 2014?09?18? 01:02, Dmitry Torokhov ??:
Quoted 44 lines
Hi Caesar,
Quoted 28 lines · Caesar Wang
Thermal is TS-ADC Controller module supports
user-defined mode and automatic mode.User-defined mode refers,TSADC all the control signals entirely by software writing to register for direct control.
Automaic mode refers to the module automatically poll TSADC output, and the results were checked.If you find that the temperature High in a period of time,an interrupt is generated to the processor down-measures taken;If the temperature over a period of time High, the resulting TSHUT gave CRU module,let it reset the entire chip, or via GPIO give PMIC.
Signed-off-by zhaoyifeng <[email protected]>Signed-off-by Caesar Wang <[email protected]>--- drivers/thermal/Kconfig | 9 + drivers/thermal/Makefile | 1 + drivers/thermal/rockchip_thermal.c | 790 +++++++++++++++++++++++++++++++++++++ 3 files changed, 800 insertions(+)create mode 100644
drivers/thermal/rockchip_thermal.cdrivers/thermal/Kconfig +0
-0@@ -133,6 +133,15 @@ config SPEAR_THERMAL Enable this to plug the SPEAr thermal sensor driver into the Linuxdrivers/thermal/Kconfig config SPEAR_THERMAL · line 143
Quoted 10 lines
drivers/thermal/Kconfig +8
-0thermal framework. +config ROCKCHIP_THERMAL + tristate "Rockchip thermal driver" + depends on ARCH_ROCKCHIP + help + Support for Temperature Sensor ADC (TS-ADC) found on Rockchip SoCs. + It supports one critical trip point and one passive trip point. The + cpufreq is used as the cooling device to throttle CPUs when the + passive trip is crossed.Nit: the wording is a bit awkward. Maybe we should say something like the following:
Quoted 6 lines
Rockchip thermal driver provides support for Temperature Sensor ADC (TS-ADC) found on Rockchip SoCs. It supports one critical trip point and one passive trip point. Cpufreq is used as the cooling device and will throttle CPUs when the temperature crosses the passive trip point.
OK,It looks nice.
Quoted 27 lines
Quoted 27 lines
drivers/thermal/Kconfig +1
-0+ config RCAR_THERMAL tristate "Renesas R-Car thermal driver" depends on ARCH_SHMOBILE || COMPILE_TESTdrivers/thermal/Makefile +1
-0@@ -19,6 +19,7 @@ thermal_sys-$(CONFIG_CPU_THERMAL) += cpu_cooling.o # platform thermal drivers obj-$(CONFIG_SPEAR_THERMAL) += spear_thermal.o +obj-$(CONFIG_ROCKCHIP_THERMAL) += rockchip_thermal.o obj-$(CONFIG_RCAR_THERMAL) += rcar_thermal.o obj-$(CONFIG_KIRKWOOD_THERMAL) += kirkwood_thermal.o obj-y += samsung/drivers/thermal/rockchip_thermal.c new file +5
-0@@ -0,0 +1,790 @@ +/* +* Copyright (c) 2014, Fuzhou Rockchip Electronics Co., Ltd +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License,
Quoted 8 lines
drivers/thermal/rockchip_thermal.c line 12
Quoted 7 lines
drivers/thermal/rockchip_thermal.c new file +7
-0+* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* Nit: drop this one line.
OK
Quoted 161 lines
Quoted 148 lines
drivers/thermal/rockchip_thermal.c new file +148
-0+*/ + +#include <linux/clk.h> +#include <linux/io.h> +#include <linux/interrupt.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/of_address.h> +#include <linux/of_irq.h> +#include <linux/platform_device.h> +#include <linux/regulator/consumer.h> +#include <linux/cpu_cooling.h> +#include <linux/thermal.h> + +struct rockchip_thermal_data { +const struct rockchip_tsadc_platform_data *pdata; +struct rockchip_thsens_platform_data *trip_tab; +struct thermal_zone_device *tz; +struct thermal_cooling_device *cdev; +enum thermal_device_mode mode; +void __iomem *regs; + +signed long temp_passive; +signed long temp_critical; +signed long temp_force_shut; +signed long alarm_temp; +signed long last_temp; +bool irq_enabled; +int irq; +struct clk *clk; +struct clk *pclk; +}; + +struct rockchip_tsadc_platform_data { +u8 irq_en; +signed long temp_passive; +signed long temp_critical; +signed long temp_force_shut; +int passive_delay; +int polling_delay; + +int (*irq_handle)(void __iomem *reg); +int (*initialize)(void __iomem *reg,signed long temp_force_shut); +int (*control)(void __iomem *reg,bool on); +u32 (*code_to_temp)(int temp); +u32 (*temp_to_code)(int temp); +void (*set_alarm_temp)(void __iomem *regs,signed long temp); +}; + +/*TSADC V2 Sensor info define:*/ +#define TSADCV2_AUTO_CON 0x04 +#define TSADCV2_INT_EN 0x08 +#define TSADCV2_INT_PD 0x0c +#define TSADCV2_DATA1 0x24 +#define TSADCV2_COMP1_INT 0x34 +#define TSADCV2_COMP1_SHUT 0x44 +#define TSADCV2_AUTO_PERIOD 0x68 +#define TSADCV2_AUTO_PERIOD_HT 0x6c + +#define TSADCV2_AUTO_SRC1_EN BIT(5) +#define TSADCV2_AUTO_EN BIT(0) +#define TSADCV2_AUTO_DISABLE ~BIT(0) +#define TSADCV2_AUTO_STAS_BUSY BIT(16) +#define TSADCV2_AUTO_STAS_BUSY_MASK BIT(16) +#define TSADCV2_SHUT_2GPIO_SRC1_EN BIT(5) +#define TSADCV2_INT_SRC1_EN BIT(1) +#define TSADCV2_SHUT_SRC1_STATUS BIT(5) +#define TSADCV2_INT_SRC1_STATUS BIT(1) +#define TSADCV2_INT_PD_CLEAR ~BIT(8) + +#define TSADCV2_DATA_MASK 0xfff +#define TSADCV2_HIGHT_INT_DEBOUNCE 0x60 +#define TSADCV2_HIGHT_TSHUT_DEBOUNCE 0x64 +#define TSADCV2_HIGHT_INT_DEBOUNCE_TIME 0x0a +#define TSADCV2_HIGHT_TSHUT_DEBOUNCE_TIME 0x0a +#define TSADCV2_AUTO_PERIOD_TIME 0x03e8 +#define TSADCV2_AUTO_PERIOD_HT_TIME 0x64 + +#define COOLING_DEV_MAX 8 + +struct rockchip_trip_point { +signed long temp; +enum thermal_trip_type type; +char cdev_name[COOLING_DEV_MAX ][THERMAL_NAME_LENGTH ]; +}; + +struct rockchip_thsens_platform_data { +struct rockchip_trip_point trip_points[THERMAL_MAX_TRIPS ]; +int num_trips; +}; + +struct tsadc_table { +int code; +int temp; +}; + +static const struct tsadc_table v2_code_table[] = { + {TSADCV2_DATA_MASK ,-40 }, + {3800 ,-40 }, + {3792 ,-35 }, + {3783 ,-30 }, + {3774 ,-25 }, + {3765 ,-20 }, + {3756 ,-15 }, + {3747 ,-10 }, + {3737 ,-5 }, + {3728 ,0 }, + {3718 ,5 }, + {3708 ,10 }, + {3698 ,15 }, + {3688 ,20 }, + {3678 ,25 }, + {3667 ,30 }, + {3656 ,35 }, + {3645 ,40 }, + {3634 ,45 }, + {3623 ,50 }, + {3611 ,55 }, + {3600 ,60 }, + {3588 ,65 }, + {3575 ,70 }, + {3563 ,75 }, + {3550 ,80 }, + {3537 ,85 }, + {3524 ,90 }, + {3510 ,95 }, + {3496 ,100 }, + {3482 ,105 }, + {3467 ,110 }, + {3452 ,115 }, + {3437 ,120 }, + {3421 ,125 }, + {0 ,125 }, +}; + +static int rk_tsadcv2_irq_handle (void __iomem *regs) +{ +u32 val; + + val =readl_relaxed (regs +TSADCV2_INT_PD ); +writel_relaxed (val &TSADCV2_INT_PD_CLEAR , regs +TSADCV2_INT_PD ); + +return 0 ; +} + +static u32 rk_tsadcv2_temp_to_code (int temp) +{ +int i;drivers/thermal/rockchip_thermal.c line 170
Quoted 10 lines
drivers/thermal/rockchip_thermal.c new file +10
-0+ +for (i =0 ; i <ARRAY_SIZE (v2_code_table) -1 ; i++) { +if (temp <= v2_code_table[i].temp) +return v2_code_table[i].code; + } + +return 0 ; +} + +static u32 rk_tsadcv2_code_to_temp (int code)The code table lists temperature as integer and I see negative values specified there. Are you sure that we want to convert it to u32?
Quoted 2 lines
Also, shouldn't the code be unsigned or u32?
I should fix it as the follows:
...
static int rk_tsadcv2_code_to_temp(int code)
Quoted 11 lines
drivers/thermal/rockchip_thermal.c line 179
Quoted 9 lines
drivers/thermal/rockchip_thermal.c new file +9
-0+{ +int i; + +for (i =0 ; i <ARRAY_SIZE (v2_code_table) -1 ; i++) { +if (code >= v2_code_table[i].code) +return v2_code_table[i].temp; + } + +return 0 ;I think if we do not find the code we should be returning max temperature, not 0.
Agree.
Quoted 2 lines
And also
WARN_ON()as this should not be happening.
Maybe,I will fix it as the follows:
pr_warn("Don't find code from v2_code_table\n");
return 125;
Do you agree?
Quoted 560 lines
Quoted 560 lines
drivers/thermal/rockchip_thermal.c new file +560
-0+} + +static int rk_tsadcv2_initialize (void __iomem *regs, +signed long temp_force_shut) +{ +int shutdown_value; + + shutdown_value =rk_tsadcv2_temp_to_code (temp_force_shut); +/* Enable measurements at ~ 10 Hz */ +writel_relaxed (0 , regs +TSADCV2_AUTO_CON ); +writel_relaxed (TSADCV2_AUTO_PERIOD_TIME , regs +TSADCV2_AUTO_PERIOD ); +writel_relaxed (TSADCV2_AUTO_PERIOD_HT_TIME , regs + +TSADCV2_AUTO_PERIOD_HT ); +writel_relaxed (shutdown_value, regs +TSADCV2_COMP1_SHUT ); +writel_relaxed (TSADCV2_HIGHT_INT_DEBOUNCE_TIME , regs + +TSADCV2_HIGHT_INT_DEBOUNCE ); +writel_relaxed (TSADCV2_HIGHT_TSHUT_DEBOUNCE_TIME , regs + +TSADCV2_HIGHT_TSHUT_DEBOUNCE ); +writel_relaxed (TSADCV2_SHUT_2GPIO_SRC1_EN |TSADCV2_INT_SRC1_EN , regs + +TSADCV2_INT_EN ); +writel_relaxed (TSADCV2_AUTO_SRC1_EN |TSADCV2_AUTO_EN , regs + +TSADCV2_AUTO_CON ); + +return 0 ; +} + +static int rk_tsadcv2_control (void __iomem *regs,bool on) +{ +u32 val; + +if (on) { + val =readl_relaxed (regs +TSADCV2_AUTO_CON ); +writel_relaxed (val |TSADCV2_AUTO_EN , regs +TSADCV2_AUTO_CON ); + }else { + val =readl_relaxed (regs +TSADCV2_AUTO_CON ); +writel_relaxed (val &TSADCV2_AUTO_DISABLE , + regs +TSADCV2_AUTO_CON ); + } + +return 0 ; +} + +static void rk_tsadcv2_alarm_temp (void __iomem *regs,signed long alarm_temp) +{ +int alarm_value; + + alarm_value =rk_tsadcv2_temp_to_code (alarm_temp); +writel_relaxed (alarm_value, regs +TSADCV2_COMP1_INT ); +} + +static const struct rockchip_tsadc_platform_data rk3288_tsadc_data = { + .irq_en =1 , + .temp_passive =85000 , + .temp_critical =100000 , + .temp_force_shut =120000 , + .passive_delay =2000 , + .polling_delay =1000 , + .irq_handle = rk_tsadcv2_irq_handle, + .initialize = rk_tsadcv2_initialize, + .control = rk_tsadcv2_control, + .code_to_temp = rk_tsadcv2_code_to_temp, + .temp_to_code = rk_tsadcv2_temp_to_code, + .set_alarm_temp = rk_tsadcv2_alarm_temp, +}; + +static const struct of_device_id of_rockchip_thermal_match[] = { + { + .compatible ="rockchip,rk3288-tsadc" , + .data = (void *)&rk3288_tsadc_data, + }, + {/* end */ }, +}; +MODULE_DEVICE_TABLE (of, of_rockchip_thermal_match); + +static void rockchip_set_alarm_temp (struct rockchip_thermal_data *data, +signed long alarm_temp) +{ +const struct rockchip_tsadc_platform_data *p_tsadc_data = data->pdata; + + data->alarm_temp = alarm_temp; +if (p_tsadc_data->set_alarm_temp) + p_tsadc_data->set_alarm_temp (data->regs, alarm_temp); +} + +static int rockchip_get_temp (struct thermal_zone_device *tz, +unsigned long *temp) +{ +struct rockchip_thermal_data *data = tz->devdata; +const struct rockchip_tsadc_platform_data *p_tsadc_data = data->pdata; +u32 val; + + val =readl_relaxed (data->regs +TSADCV2_DATA1 ); + *temp = p_tsadc_data->code_to_temp (val); + +/* Update alarm value to next higher trip point */ +if (data->alarm_temp == data->temp_passive && *temp >= + data->temp_passive) +rockchip_set_alarm_temp (data, data->temp_critical); + +if (data->alarm_temp == data->temp_critical && *temp < + data->temp_passive) { +rockchip_set_alarm_temp (data, data->temp_passive); +dev_dbg (&tz->device,"thermal alarm off: T < %lu\n" , + data->alarm_temp /1000 ); + } + +if (*temp != data->last_temp) { +dev_dbg (&tz->device,"millicelsius: %ld\n" , *temp); + data->last_temp = *temp; + } + +/* Reenable alarm IRQ if temperature below alarm temperature */ +if (!data->irq_enabled && *temp < data->alarm_temp) { + data->irq_enabled = true; +enable_irq (data->irq); + } + +return 0 ; +} + +static int rockchip_thermal_initialize (struct rockchip_thermal_data *data) +{ +const struct rockchip_tsadc_platform_data *p_tsadc_data = data->pdata; + +if (p_tsadc_data->initialize) + p_tsadc_data->initialize (data->regs, data->temp_force_shut); +rockchip_set_alarm_temp (data, data->temp_passive); + +return 0 ; +} + +static void rockchip_thermal_control (struct rockchip_thermal_data *data, +bool on) +{ +const struct rockchip_tsadc_platform_data *p_tsadc_data = data->pdata; + +if (p_tsadc_data->control) + p_tsadc_data->control (data->regs, on); + +if (on) { + data->irq_enabled = true; + data->mode =THERMAL_DEVICE_ENABLED ; + }else { + data->irq_enabled = false; + data->mode =THERMAL_DEVICE_DISABLED ; + } +} + +static int rockchip_get_mode (struct thermal_zone_device *tz, +enum thermal_device_mode *mode) +{ +struct rockchip_thermal_data *data = tz->devdata; + + *mode = data->mode; + +return 0 ; +} + +static int rockchip_set_mode (struct thermal_zone_device *tz, +enum thermal_device_mode mode) +{ +struct rockchip_thermal_data *data = tz->devdata; +const struct rockchip_tsadc_platform_data *p_tsadc_data = data->pdata; + +if (mode ==THERMAL_DEVICE_ENABLED ) { + tz->polling_delay = p_tsadc_data->polling_delay; + tz->passive_delay = p_tsadc_data->passive_delay; +if (!data->irq_enabled) { + data->irq_enabled = true; +enable_irq (data->irq); + } + }else { + tz->polling_delay =0 ; + tz->passive_delay =0 ; +if (data->irq_enabled) { +disable_irq (data->irq); + data->irq_enabled = false; + } + } + + data->mode = mode; +thermal_zone_device_update (tz); + +return 0 ; +} + +static int rockchip_get_trip_type (struct thermal_zone_device *tz,int trip, +enum thermal_trip_type *type) +{ +struct rockchip_thermal_data *data = tz->devdata; +struct rockchip_thsens_platform_data *ptrips = data->trip_tab; + +if (trip >= ptrips->num_trips) +return -EINVAL ; + + *type = ptrips->trip_points[trip].type; + +return 0 ; +} + +static int rockchip_get_crit_temp (struct thermal_zone_device *tz, +unsigned long *temp) +{ +struct rockchip_thermal_data *data = tz->devdata; + + *temp = data->temp_critical; + +return 0 ; +} + +static int rockchip_get_trip_temp (struct thermal_zone_device *tz,int trip, +unsigned long *temp) +{ +struct rockchip_thermal_data *data = tz->devdata; +struct rockchip_thsens_platform_data *ptrips = data->trip_tab; + +if (trip >= ptrips->num_trips) +return -EINVAL ; + *temp = ptrips->trip_points[trip].temp; + +return 0 ; +} + +static int rockchip_set_trip_temp (struct thermal_zone_device *tz,int trip, +unsigned long temp) +{ +struct rockchip_thermal_data *data = tz->devdata; +struct rockchip_thsens_platform_data *ptrips = data->trip_tab; + +if (trip >= ptrips->num_trips) +return -EINVAL ; + + data->temp_passive = temp; +rockchip_set_alarm_temp (data, temp); + +return 0 ; +} + +/* Local function to check if thermal zone matches cooling devices */ +static int rockchip_thermal_match_cdev (struct thermal_cooling_device *cdev, +struct rockchip_trip_point *trip_point) +{ +int i; + +if (!strlen (cdev->type)) +return -EINVAL ; + +for (i =0 ; i <COOLING_DEV_MAX ; i++) { +if (!strcmp (trip_point->cdev_name[i], cdev->type)) +return 0 ; + } + +return -ENODEV ; +} + +/* Callback to bind cooling device to thermal zone */ +static int rockchip_cdev_bind (struct thermal_zone_device *tz, +struct thermal_cooling_device *cdev) +{ +struct rockchip_thermal_data *data = tz->devdata; +struct rockchip_thsens_platform_data *ptrips = data->trip_tab; +unsigned long max_state, upper, lower; +int i, ret = -EINVAL ; + + cdev->ops->get_max_state (cdev, &max_state); + +for (i =0 ; i < ptrips->num_trips; i++) { +if (rockchip_thermal_match_cdev (cdev, &ptrips->trip_points[i])) +continue ; + + lower = i > max_state ? max_state : i; + upper = lower; + + ret =thermal_zone_bind_cooling_device (tz, i, cdev, + upper, lower); + +dev_info (&cdev->device,"%s bind to %d: %d-%s\n" , cdev->type, + i, ret, ret ?"fail" :"succeed" ); + } + +return ret; +} + +/* Callback to unbind cooling device from thermal zone */ +static int rockchip_cdev_unbind (struct thermal_zone_device *tz, +struct thermal_cooling_device *cdev) +{ +struct rockchip_thermal_data *data = tz->devdata; +struct rockchip_thsens_platform_data *ptrips = data->trip_tab; +int i, ret = -EINVAL ; + +for (i =0 ; i < ptrips->num_trips; i++) { +if (rockchip_thermal_match_cdev (cdev, &ptrips->trip_points[i])) +continue ; + + ret =thermal_zone_unbind_cooling_device (tz, i, cdev); + +dev_info (&cdev->device,"%s unbind from %d: %s\n" , cdev->type, + i, ret ?"fail" :"succeed" ); + } + +return ret; +} + +static struct thermal_zone_device_ops rockchip_tz_ops = { + .bind = rockchip_cdev_bind, + .unbind = rockchip_cdev_unbind, + .get_temp = rockchip_get_temp, + .get_mode = rockchip_get_mode, + .set_mode = rockchip_set_mode, + .get_trip_type = rockchip_get_trip_type, + .get_trip_temp = rockchip_get_trip_temp, + .get_crit_temp = rockchip_get_crit_temp, + .set_trip_temp = rockchip_set_trip_temp, +}; + +static irqreturn_t rockchip_thermal_alarm_irq_thread (int irq,void *dev) +{ +struct rockchip_thermal_data *data = data; +const struct rockchip_tsadc_platform_data *p_tsadc_data = data->pdata; + +dev_dbg (&data->tz->device,"THERMAL ALARM: T > %lu\n" , + data->alarm_temp /1000 ); + +if (p_tsadc_data->irq_en && p_tsadc_data->irq_handle) + p_tsadc_data->irq_handle (data->regs); + +thermal_zone_device_update (data->tz); + +return IRQ_HANDLED ; +} + +static struct rockchip_thsens_platform_data * +rockchip_thermal_parse_dt (struct platform_device *pdev) +{ +struct rockchip_thsens_platform_data *ptrips; +struct device_node *np = pdev->dev.of_node; +char prop_name[32 ]; +const char *tmp_str; +u32 tmp_data; +int i, j; + + ptrips =devm_kzalloc (&pdev->dev,sizeof (*ptrips),GFP_KERNEL ); +if (!ptrips) +return NULL ; + +if (of_property_read_u32 (np,"num-trips" , &tmp_data)) + goto err_parse_dt; + +if (tmp_data >THERMAL_MAX_TRIPS ) + goto err_parse_dt; + + ptrips->num_trips = tmp_data; + +for (i =0 ; i < ptrips->num_trips; i++) { +sprintf (prop_name,"trip%d-temp" , i); +if (of_property_read_u32 (np, prop_name, &tmp_data)) + goto err_parse_dt; + + ptrips->trip_points[i].temp = tmp_data; +sprintf (prop_name,"trip%d-type" , i); +if (of_property_read_string (np, prop_name, &tmp_str)) + goto err_parse_dt; + +if (!strcmp (tmp_str,"active" )) + ptrips->trip_points[i].type =THERMAL_TRIP_ACTIVE ; +else if (!strcmp (tmp_str,"passive" )) + ptrips->trip_points[i].type =THERMAL_TRIP_PASSIVE ; +else if (!strcmp (tmp_str,"hot" )) + ptrips->trip_points[i].type =THERMAL_TRIP_HOT ; +else if (!strcmp (tmp_str,"critical" )) + ptrips->trip_points[i].type =THERMAL_TRIP_CRITICAL ; +else + goto err_parse_dt; + +sprintf (prop_name,"trip%d-cdev-num" , i); +if (of_property_read_u32 (np, prop_name, &tmp_data)) + goto err_parse_dt; + +if (tmp_data >COOLING_DEV_MAX ) + goto err_parse_dt; + +for (j =0 ; j < tmp_data; j++) { +sprintf (prop_name,"trip%d-cdev-name%d" , i, j); +if (of_property_read_string (np, prop_name, &tmp_str)) + goto err_parse_dt; + +if (strlen (tmp_str) >=THERMAL_NAME_LENGTH ) + goto err_parse_dt; + +strcpy (ptrips->trip_points[i].cdev_name[j], tmp_str); + } + } +return ptrips; + +err_parse_dt: +dev_err (&pdev->dev,"Parsing device tree data error.\n" ); +return NULL ; +} + +static int rockchip_thermal_probe (struct platform_device *pdev) +{ +struct rockchip_thermal_data *data; +const struct rockchip_tsadc_platform_data *p_tsadc_data; +const struct of_device_id *match; +struct rockchip_thsens_platform_data *ptrips =NULL ; +struct cpumask clip_cpus; +struct resource *res; +struct device_node *np = pdev->dev.of_node; + +int ret, temp; + + ptrips =rockchip_thermal_parse_dt (pdev); +if (!ptrips) +return -EINVAL ; + + data =devm_kzalloc (&pdev->dev,sizeof (struct rockchip_thermal_data ), +GFP_KERNEL ); +if (!data) +return -ENOMEM ; + + data->trip_tab = ptrips; + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + data->regs =devm_ioremap_resource (&pdev->dev, res); +if (IS_ERR (data->regs)) { +dev_err (&pdev->dev,"Could not get tsadc source, %p\n" , + data->regs); +return PTR_ERR (data->regs); + } + + match =of_match_node (of_rockchip_thermal_match, np); +if (!match) +return -ENXIO ; + data->pdata = (const struct rockchip_tsadc_platform_data *)match->data; +if (!data->pdata) +return -EINVAL ; + p_tsadc_data = data->pdata; + + data->clk =devm_clk_get (&pdev->dev,"tsadc" ); +if (IS_ERR (data->clk)) { +dev_err (&pdev->dev,"failed to get tsadc clock\n" ); +return PTR_ERR (data->clk); + } + + data->pclk =devm_clk_get (&pdev->dev,"apb_pclk" ); +if (IS_ERR (data->pclk)) { +dev_err (&pdev->dev,"failed to get tsadc pclk\n" ); +return PTR_ERR (data->pclk); + } + +/* +* Use a default of 10KHz for the converter clock. +* This may become user-configurable in the future. +*/ + ret =clk_set_rate (data->clk,10000 ); +if (ret <0 ) { +dev_err (&pdev->dev,"failed to set tsadc clk rate, %d\n" , ret); +return ret; + } + + ret =clk_prepare_enable (data->clk); +if (ret <0 ) { +dev_err (&pdev->dev,"failed to enable converter clock\n" ); + goto err_clk; + } + + ret =clk_prepare_enable (data->pclk); +if (ret <0 ) { +dev_err (&pdev->dev,"failed to enable pclk\n" ); + goto err_pclk; + } + +platform_set_drvdata (pdev, data); + +if (of_property_read_u32 (pdev->dev.of_node,"hw-shut-temp" , &temp)) { +dev_warn (&pdev->dev, +"Missing default force shut down temp property in the DT.\n" ); + data->temp_force_shut = p_tsadc_data->temp_force_shut; + }else { + data->temp_force_shut = temp; + } + + data->temp_passive = ptrips->trip_points[0 ].temp; + data->temp_critical = ptrips->trip_points[1 ].temp; + +cpumask_set_cpu (0 , &clip_cpus); + data->cdev =of_cpufreq_cooling_register (np, &clip_cpus); +if (IS_ERR (data->cdev)) { +dev_err (&pdev->dev,"failed to register cpufreq cooling device\n" ); + goto disable_clk; + } + + data->tz =thermal_zone_device_register ("rockchip_thermal" , + ptrips->num_trips, +0 , data, + &rockchip_tz_ops,NULL , + p_tsadc_data->passive_delay, + p_tsadc_data->polling_delay); +if (IS_ERR (data->tz)) { +dev_err (&pdev->dev,"failed to register thermal zone device\n" ); + goto fail_cpufreq_register; + } + +if (p_tsadc_data->irq_en) { + data->irq =platform_get_irq (pdev,0 ); +if (data->irq <0 ) { +dev_err (&pdev->dev,"no irq resource?\n" ); + goto fail_irq; + } + + ret =devm_request_threaded_irq (&pdev->dev, data->irq, +NULL , &rockchip_thermal_alarm_irq_thread, +IRQF_ONESHOT ,"rockchip_thermal" , + data); +if (ret <0 ) { +dev_err (&pdev->dev, +"failed to request tsadc irq: %d\n" , ret); + goto fail_thermal_unregister; + } + } + +rockchip_thermal_initialize (data); +rockchip_thermal_control (data, true); + +return 0 ; + +fail_thermal_unregister: +thermal_zone_device_unregister (data->tz); +fail_irq: +fail_cpufreq_register: +cpufreq_cooling_unregister (data->cdev); +disable_clk: +err_pclk: +clk_disable_unprepare (data->pclk); +err_clk: +clk_disable_unprepare (data->clk); + +return ret; +} + +static int rockchip_thermal_remove (struct platform_device *pdev) +{ +struct rockchip_thermal_data *data =platform_get_drvdata (pdev); + +rockchip_thermal_control (data, false); + +thermal_zone_device_unregister (data->tz); +cpufreq_cooling_unregister (data->cdev); + +clk_disable_unprepare (data->clk); +clk_disable_unprepare (data->pclk); + +return 0 ; +} + +#ifdef CONFIG_PM_SLEEP +static int rockchip_thermal_suspend (struct device *dev) +{ +struct platform_device *pdev =to_platform_device (dev);
Quoted 9 lines
drivers/thermal/rockchip_thermal.c line 731
Quoted 6 lines
drivers/thermal/rockchip_thermal.c new file +6
-0+struct rockchip_thermal_data *data =platform_get_drvdata (pdev); + +rockchip_thermal_control (data, false); + +clk_disable_unprepare (data->clk); +clk_disable_unprepare (data->pclk);Nit: I do not think you need to "unprepare" clocks in suspend, just disabling them should be fine.
You are right.
Quoted 4 lines
Quoted 4 lines
drivers/thermal/rockchip_thermal.c new file +4
-0+ +return 0 ; +} +
Quoted 9 lines
drivers/thermal/rockchip_thermal.c line 756
Quoted 7 lines
drivers/thermal/rockchip_thermal.c new file +7
-0+static int rockchip_thermal_resume (struct device *dev) +{ +struct platform_device *pdev =to_platform_device (dev); +struct rockchip_thermal_data *data =platform_get_drvdata (pdev); +int ret; + + ret =clk_prepare_enable (data->pclk);And simply
clk_enable()here.
Ditto.
Thanks your comments.
Quoted 40 lines
Quoted 38 lines
drivers/thermal/rockchip_thermal.c new file +34
-0+if (ret) +return ret; + + ret =clk_prepare_enable (data->clk); +if (ret) +return ret; + +rockchip_thermal_initialize (data); +rockchip_thermal_control (data, true); + +return 0 ; +} +#endif + +static SIMPLE_DEV_PM_OPS(rockchip_thermal_pm_ops, + rockchip_thermal_suspend, rockchip_thermal_resume); + +static struct platform_driver rockchip_thermal_driver = { + .driver = { + .name ="rockchip-thermal" , + .owner =THIS_MODULE , + .pm = &rockchip_thermal_pm_ops, + .of_match_table = of_rockchip_thermal_match, + }, + .probe = rockchip_thermal_probe, + .remove = rockchip_thermal_remove, +}; + +module_platform_driver (rockchip_thermal_driver); + +MODULE_DESCRIPTION ("ROCKCHIP THERMAL Driver" ); +MODULE_AUTHOR ("Rockchip, Inc." ); +MODULE_LICENSE ("GPL v2" ); +MODULE_ALIAS ("platform:rockchip-thermal" );Signature · 1 line
1.9.1Thanks.
Signature · 2 lines
Best regards, Caesar
Re: [PATCH v5 1/4] thermal: rockchip: add driver for Thermal
Hi Caesar,
Quoted 19 lines · Caesar Wang
Dear Dmitry,
? 2014?09?18? 01:02, Dmitry Torokhov ??:
Quoted 14 lines
Hi Caesar,
drivers/thermal/rockchip_thermal.c line 179
Quoted 9 lines · Caesar Wang
drivers/thermal/rockchip_thermal.c new file +9
-0+{ +int i; + +for (i =0 ; i <ARRAY_SIZE (v2_code_table) -1 ; i++) { +if (code >= v2_code_table[i].code) +return v2_code_table[i].temp; + } + +return 0 ;I think if we do not find the code we should be returning max temperature, not 0.
Agree.
Quoted 8 lines
Quoted 2 lines
And also
WARN_ON()as this should not be happening.Maybe,I will fix it as the follows:
pr_warn("Don't find code from v2_code_table\n");
return 125;Do you agree?
Sounds good.
Thanks.
Signature · 1 line
Dmitry
PATCH v5 2/4 dt-bindings: document Rockchip thermal
In reply to Caesar WangThis add the necessary binding documentation for the thermal found on Rockchip SoCs
--- .../bindings/thermal/rockchip-thermal.txt | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 Documentation/devicetree/bindings/thermal/rockchip-thermal.txt
Documentation/devicetree/bindings/thermal/rockchip-thermal.txt new file +41 -0
@@ -0,0 +1,41 @@ +* Temperature Sensor ADC (TSADC) on rockchip SoCs + +Required properties: +- compatible: "rockchip,rk3288-tsadc" +- reg: physical base address of the controller and length of memory mapped + region. +- interrupts: The interrupt number to the cpu. The interrupt specifier format + depends on the interrupt controller. +- clocks: Must contain an entry for each entry in clock-names. +- clock-names: Shall be "tsadc" for the converter-clock, and "apb_pclk" for + the peripheral clock. +- num-trips: number of total trip points, this is required, set it 0 if none, + if greater than 0, the following properties must be defined; +- tripN-temp: temperature of trip point N, should be in ascending order; +- tripN-type: type of trip point N, should be one of "active" "passive" "hot" + "critical"; +- tripN-cdev-num: number of the cooling devices which can be bound to trip + point N, this is required if trip point N is defined, set it 0 if none, + otherwise the following cooling device names must be defined; +- tripN-cdev-nameM: name of the No. M cooling device of trip point N; + +Example: +tsadc: tsadc at ff280000 { + compatible = "rockchip,rk3288-tsadc"; + reg = <0xff280000 0x100>; + interrupts = <GIC_SPI 37 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&cru SCLK_TSADC>, <&cru PCLK_TSADC>; + clock-names = "tsadc", "apb_pclk"; + + num-trips = <2>; + + trip0-temp = <80>; + trip0-type = "passive"; + trip0-cdev-num = <1>; + trip0-cdev-name0 = "thermal-cpufreq-0"; + + trip1-temp = <100>; + trip1-type = "critical"; + trip1-cdev-num = <1>; + trip1-cdev-name0 = "thermal-cpufreq-0"; +};
Signature · 1 line
1.9.1
Re: [PATCH v5 2/4] dt-bindings: document Rockchip thermal
Caesar,
Quoted 19 lines · Caesar Wang
This add the necessary binding documentation for the thermal found on Rockchip SoCs
Signed-off-by zhaoyifeng <[email protected]>Signed-off-by Caesar Wang <[email protected]>--- .../bindings/thermal/rockchip-thermal.txt | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 Documentation/devicetree/bindings/thermal/rockchip-thermal.txtDocumentation/devicetree/bindings/thermal/rockchip-thermal.txt new file +3
-0@@ -0,0 +1,41 @@ +* Temperature Sensor ADC (TSADC) on rockchip SoCs + +Required properties:
Documentation/devicetree/bindings/thermal/rockchip-thermal.txt line 13
Quoted 10 lines
Documentation/devicetree/bindings/thermal/rockchip-thermal.txt new file +10
-0+- compatible: "rockchip,rk3288-tsadc" +- reg: physical base address of the controller and length of memory mapped + region. +- interrupts: The interrupt number to the cpu. The interrupt specifier format + depends on the interrupt controller. +- clocks: Must contain an entry for each entry in clock-names. +- clock-names: Shall be "tsadc" for the converter-clock, and "apb_pclk" for + the peripheral clock. +- num-trips: number of total trip points, this is required, set it 0 if none, + if greater than 0, the following properties must be defined;
nit: there is whitespace damage (space before tab) on the line before this one. It's more obvious in the patch you uploaded to gerrit which highlights this in red:
Did you run your patches through checkpatch before submitting?
-Doug
Re: [PATCH v5 2/4] dt-bindings: document Rockchip thermal
Quoted 37 lines · Doug Anderson
Caesar,
Quoted 19 lines · Caesar Wang
This add the necessary binding documentation for the thermal found on Rockchip SoCs
Signed-off-by zhaoyifeng <[email protected]>Signed-off-by Caesar Wang <[email protected]>--- .../bindings/thermal/rockchip-thermal.txt | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 Documentation/devicetree/bindings/thermal/rockchip-thermal.txtDocumentation/devicetree/bindings/thermal/rockchip-thermal.txt new file +3
-0@@ -0,0 +1,41 @@ +* Temperature Sensor ADC (TSADC) on rockchip SoCs + +Required properties:Documentation/devicetree/bindings/thermal/rockchip-thermal.txt line 13
Quoted 10 lines
Documentation/devicetree/bindings/thermal/rockchip-thermal.txt new file +10
-0+- compatible: "rockchip,rk3288-tsadc" +- reg: physical base address of the controller and length of memory mapped + region. +- interrupts: The interrupt number to the cpu. The interrupt specifier format + depends on the interrupt controller. +- clocks: Must contain an entry for each entry in clock-names. +- clock-names: Shall be "tsadc" for the converter-clock, and "apb_pclk" for + the peripheral clock. +- num-trips: number of total trip points, this is required, set it 0 if none, + if greater than 0, the following properties must be defined;nit: there is whitespace damage (space before tab) on the line before this one. It's more obvious in the patch you uploaded to gerrit which highlights this in red:
Quoted 3 lines
Did you run your patches through checkpatch before submitting?
FWIW vim users like me can put the following in their .vimrc file to have whitespace damage visible right away:
:highlight RedundantSpaces ctermbg=red guibg=red
:match RedundantSpaces /\s\+$\| \+\ze\t/
Thanks.
Signature · 1 line
Dmitry
Re: [PATCH v5 2/4] dt-bindings: document Rockchip thermal
? 2014?09?18? 04:13, Dmitry Torokhov ??:
Quoted 39 lines · Doug Anderson
Quoted 38 lines
Caesar,
Quoted 19 lines · Caesar Wang
This add the necessary binding documentation for the thermal found on Rockchip SoCs
Signed-off-by zhaoyifeng <[email protected]>Signed-off-by Caesar Wang <[email protected]>--- .../bindings/thermal/rockchip-thermal.txt | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+)create mode 100644
Documentation/devicetree/bindings/thermal/rockchip-thermal.txtDocumentation/devicetree/bindings/thermal/rockchip-thermal.txt new file +3
-0@@ -0,0 +1,41 @@ +* Temperature Sensor ADC (TSADC) on rockchip SoCs + +Required properties:Documentation/devicetree/bindings/thermal/rockchip-thermal.txt line 13
Quoted 10 lines
Documentation/devicetree/bindings/thermal/rockchip-thermal.txt new file +10
-0+- compatible: "rockchip,rk3288-tsadc" +- reg: physical base address of the controller and length of memory mapped + region. +- interrupts: The interrupt number to the cpu. The interrupt specifier format + depends on the interrupt controller. +- clocks: Must contain an entry for each entry in clock-names. +- clock-names: Shall be "tsadc" for the converter-clock, and "apb_pclk" for + the peripheral clock. +- num-trips: number of total trip points, this is required, set it 0 if none, + if greater than 0, the following properties must be defined;nit: there is whitespace damage (space before tab) on the line before this one. It's more obvious in the patch you uploaded to gerrit which highlights this in red:
Quoted 8 lines
Quoted 1 line
Did you run your patches through checkpatch before submitting?
FWIW vim users like me can put the following in their .vimrc file to have whitespace damage visible right away:
:highlight RedundantSpaces ctermbg=red guibg=red
:match RedundantSpaces /\s\+$\| \+\ze\t/Thanks.
It's a very useful, Thank you for sharing.
Signature · 2 lines
Best regards, Caesar
Re: [PATCH v5 2/4] dt-bindings: document Rockchip thermal
In reply to Caesar WangQuoted 2 lines · Caesar Wang
This add the necessary binding documentation for the thermal found on Rockchip SoCs
Hi Caesar,
is there any reason to not use the existing thermal bindings? You can find a description in Documentation/devicetree/bindings/thermal/thermal.txt and example code in omap, or in the patches for Tegra recently posted by Mikko Perttunen.
Regards,
Tomeu
Quoted 62 lines
Signed-off-by zhaoyifeng <[email protected]>Signed-off-by Caesar Wang <[email protected]>--- .../bindings/thermal/rockchip-thermal.txt | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 Documentation/devicetree/bindings/thermal/rockchip-thermal.txtDocumentation/devicetree/bindings/thermal/rockchip-thermal.txt new file +41
-1@@ -0,0 +1,41 @@ +* Temperature Sensor ADC (TSADC) on rockchip SoCs + +Required properties: +- compatible: "rockchip,rk3288-tsadc" +- reg: physical base address of the controller and length of memory mapped + region. +- interrupts: The interrupt number to the cpu. The interrupt specifier format + depends on the interrupt controller. +- clocks: Must contain an entry for each entry in clock-names. +- clock-names: Shall be "tsadc" for the converter-clock, and "apb_pclk" for + the peripheral clock. +- num-trips: number of total trip points, this is required, set it 0 if none, + if greater than 0, the following properties must be defined; +- tripN-temp: temperature of trip point N, should be in ascending order; +- tripN-type: type of trip point N, should be one of "active" "passive" "hot" + "critical"; +- tripN-cdev-num: number of the cooling devices which can be bound to trip + point N, this is required if trip point N is defined, set it 0 if none, + otherwise the following cooling device names must be defined; +- tripN-cdev-nameM: name of the No. M cooling device of trip point N; + +Example: +tsadc: tsadc at ff280000 { + compatible = "rockchip,rk3288-tsadc"; + reg = <0xff280000 0x100>; + interrupts = <GIC_SPI 37 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&cru SCLK_TSADC>, <&cru PCLK_TSADC>; + clock-names = "tsadc", "apb_pclk"; + + num-trips = <2>; + + trip0-temp = <80>; + trip0-type = "passive"; + trip0-cdev-num = <1>; + trip0-cdev-name0 = "thermal-cpufreq-0"; + + trip1-temp = <100>; + trip1-type = "critical"; + trip1-cdev-num = <1>; + trip1-cdev-name0 = "thermal-cpufreq-0"; +}; --1.9.1
--
To unsubscribe from this list: send the line "unsubscribe linux-pm" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v5 2/4] dt-bindings: document Rockchip thermal
Tomeu,
? 2014?09?18? 17:27, Tomeu Vizoso ??:
Quoted 11 lines · Caesar Wang
Quoted 2 lines
This add the necessary binding documentation for the thermal found on Rockchip SoCs
Hi Caesar,
is there any reason to not use the existing thermal bindings? You can find a description in
Documentation/devicetree/bindings/thermal/thermal.txtand example code in omap, or in the patches for Tegra recently posted by Mikko Perttunen.
Quoted 3 lines
Regards,
Tomeu
Why should I use the existing thermal bindings?
I believe omap,tegar and rockchip are the three seperate thermals driver.
So far, I submitted the series Patchs for rockchip thermal.
Quoted 65 lines
Quoted 63 lines
Signed-off-by zhaoyifeng <[email protected]>Signed-off-by Caesar Wang <[email protected]>--- .../bindings/thermal/rockchip-thermal.txt | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+)create mode 100644
Documentation/devicetree/bindings/thermal/rockchip-thermal.txtDocumentation/devicetree/bindings/thermal/rockchip-thermal.txt new file +41
-1@@ -0,0 +1,41 @@ +* Temperature Sensor ADC (TSADC) on rockchip SoCs + +Required properties: +- compatible: "rockchip,rk3288-tsadc" +- reg: physical base address of the controller and length of memory mapped + region. +- interrupts: The interrupt number to the cpu. The interrupt specifier format + depends on the interrupt controller. +- clocks: Must contain an entry for each entry in clock-names. +- clock-names: Shall be "tsadc" for the converter-clock, and "apb_pclk" for + the peripheral clock. +- num-trips: number of total trip points, this is required, set it 0 if none, + if greater than 0, the following properties must be defined; +- tripN-temp: temperature of trip point N, should be in ascending order; +- tripN-type: type of trip point N, should be one of "active" "passive" "hot" + "critical"; +- tripN-cdev-num: number of the cooling devices which can be bound to trip + point N, this is required if trip point N is defined, set it 0 if none, + otherwise the following cooling device names must be defined; +- tripN-cdev-nameM: name of the No. M cooling device of trip point N; + +Example: +tsadc: tsadc at ff280000 { + compatible = "rockchip,rk3288-tsadc"; + reg = <0xff280000 0x100>; + interrupts = <GIC_SPI 37 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&cru SCLK_TSADC>, <&cru PCLK_TSADC>; + clock-names = "tsadc", "apb_pclk"; + + num-trips = <2>; + + trip0-temp = <80>; + trip0-type = "passive"; + trip0-cdev-num = <1>; + trip0-cdev-name0 = "thermal-cpufreq-0"; + + trip1-temp = <100>; + trip1-type = "critical"; + trip1-cdev-num = <1>; + trip1-cdev-name0 = "thermal-cpufreq-0"; +}; --1.9.1
--
To unsubscribe from this list: send the line "unsubscribe linux-pm" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 2 lines
Best regards, Caesar
Re: [PATCH v5 2/4] dt-bindings: document Rockchip thermal
Quoted 18 lines · Caesar Wang
Tomeu,
? 2014?09?18? 17:27, Tomeu Vizoso ??:
Quoted 15 lines
Quoted 3 lines · Caesar Wang
This add the necessary binding documentation for the thermal found on Rockchip SoCs
Hi Caesar,
is there any reason to not use the existing thermal bindings? You can find a description in
Documentation/devicetree/bindings/thermal/thermal.txtand example code in omap, or in the patches for Tegra recently posted by Mikko Perttunen.
Quoted 6 lines
Quoted 3 lines
Regards,
Tomeu
Why should I use the existing thermal bindings?
Because otherwise, you are asking to merge duplicated code. There's a generic way to define thermal zones, trip points, cooling devices, etc. And also code to parse and plug them together. Why add soc-specific code to do the same?
Quoted 1 line
I believe omap,tegar and rockchip are the three seperate thermals driver.
Yes, and OMAP is already using the generic bindings, and the proposed patches for Tegra as well, and I think it would make sense for Rockchip to also use them (unless I'm missing something).
Regards,
Tomeu
Quoted 87 lines
So far, I submitted the series Patchs for rockchip thermal.
Quoted 72 lines
Quoted 72 lines
Signed-off-by zhaoyifeng <[email protected]>Signed-off-by Caesar Wang <[email protected]>--- .../bindings/thermal/rockchip-thermal.txt | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+)create mode 100644
Documentation/devicetree/bindings/thermal/rockchip-thermal.txtdiff --git
a/Documentation/devicetree/bindings/thermal/rockchip-thermal.txtb/Documentation/devicetree/bindings/thermal/rockchip-thermal.txtnew file mode 100644
index 0000000..6fc8bc3Documentation/devicetree/bindings/thermal/rockchip-thermal.txt new file +5
-0@@ -0,0 +1,41 @@ +* Temperature Sensor ADC (TSADC) on rockchip SoCs + +Required properties: +- compatible: "rockchip,rk3288-tsadc" +- reg: physical base address of the controller and length of memorymapped
+ region.
+- interrupts: The interrupt number to the cpu. The interrupt specifier format
+ depends on the interrupt controller.+- clocks: Must contain an entry for each entry in clock-names. +- clock-names: Shall be "tsadc" for the converter-clock, and "apb_pclk"for
+ the peripheral clock.
+- num-trips: number of total trip points, this is required, set it 0 if none,
+ if greater than 0, the following properties must be
defined;+- tripN-temp: temperature of trip point N, should be in ascending order; +- tripN-type: type of trip point N, should be one of "active" "passive""hot"
+ "critical";
+- tripN-cdev-num: number of the cooling devices which can be bound to trip
+ point N, this is required if trip point N is defined,
set it 0 if none,
+ otherwise the following cooling device names must be
defined;
+- tripN-cdev-nameM: name of the No. M cooling device of trip point N;Documentation/devicetree/bindings/thermal/rockchip-thermal.txt new file +21
-1+ +Example: +tsadc: tsadc at ff280000 { + compatible = "rockchip,rk3288-tsadc"; + reg = <0xff280000 0x100>; + interrupts = <GIC_SPI 37 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&cru SCLK_TSADC>, <&cru PCLK_TSADC>; + clock-names = "tsadc", "apb_pclk"; + + num-trips = <2>; + + trip0-temp = <80>; + trip0-type = "passive"; + trip0-cdev-num = <1>; + trip0-cdev-name0 = "thermal-cpufreq-0"; + + trip1-temp = <100>; + trip1-type = "critical"; + trip1-cdev-num = <1>; + trip1-cdev-name0 = "thermal-cpufreq-0"; +}; --1.9.1
Quoted 7 lines
Quoted 4 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-pm" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html--
Best regards,
Caesar
Re: [PATCH v5 2/4] dt-bindings: document Rockchip thermal
Quoted 31 lines · Tomeu Vizoso
Quoted 18 lines · Caesar Wang
Tomeu,
? 2014?09?18? 17:27, Tomeu Vizoso ??:
Quoted 15 lines
Quoted 3 lines · Caesar Wang
This add the necessary binding documentation for the thermal found on Rockchip SoCs
Hi Caesar,
is there any reason to not use the existing thermal bindings? You can find a description in
Documentation/devicetree/bindings/thermal/thermal.txtand example code in omap, or in the patches for Tegra recently posted by Mikko Perttunen.Quoted 6 lines
Quoted 3 lines
Regards,
Tomeu
Why should I use the existing thermal bindings?
Because otherwise, you are asking to merge duplicated code. There's a generic way to define thermal zones, trip points, cooling devices, etc. And also code to parse and plug them together. Why add soc-specific code to do the same?
Quoted 5 lines
Quoted 1 line
I believe omap,tegar and rockchip are the three seperate thermals driver.
Yes, and OMAP is already using the generic bindings, and the proposed patches for Tegra as well, and I think it would make sense for Rockchip to also use them (unless I'm missing something).
You are talking about drivers/thermal/of-thermal.c, right? Yes, I think Rockchip should be using the same generic framework if possible.
Thanks.
Signature · 1 line
Dmitry
PATCH v5 3/4 ARM: dts: add main Thermal info to rk3288
In reply to Caesar Wang--- arch/arm/boot/dts/rk3288.dtsi | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
arch/arm/boot/dts/rk3288.dtsi +18 -0
@@ -215,6 +215,17 @@ status = "disabled"; }; + tsadc: tsadc at ff280000 { + compatible = "rockchip,rk3288-tsadc"; + reg = <0xff280000 0x100>; + interrupts = <GIC_SPI 37 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&cru SCLK_TSADC>, <&cru PCLK_TSADC>; + clock-names = "tsadc", "apb_pclk"; + pinctrl-names = "default"; + pinctrl-1 = <&otp_out>; + status = "disabled"; + }; + usb_host0_ehci: usb at ff500000 { compatible = "generic-ehci"; reg = <0xff500000 0x100>;
@@ -611,5 +622,12 @@ rockchip,pins = <5 15 3 &pcfg_pull_none>; }; }; + + tsadc { + otp_out: otp-out { + rockchip,pins = <0 10 RK_FUNC_1 &pcfg_pull_up>; + }; + }; + }; };
Signature · 1 line
1.9.1
PATCH v5 4/4 ARM: dts: enable Thermal on rk3288-evb board
In reply to Caesar Wang--- arch/arm/boot/dts/rk3288-evb.dtsi | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
arch/arm/boot/dts/rk3288-evb.dtsi +18 -0
@@ -101,6 +101,24 @@ status = "okay"; }; +&tsadc { + num-trips = <2>; + + trip0-temp = <80>; + trip0-type = "passive"; + trip0-cdev-num = <1>; + trip0-cdev-name0 = "thermal-cpufreq-0"; + + trip1-temp = <100>; + trip1-type = "critical"; + trip1-cdev-num = <1>; + trip1-cdev-name0 = "thermal-cpufreq-0"; + + hw-shut-temp = <120>; + + status = "okay"; +}; + &pinctrl { buttons { pwrbtn: pwrbtn {
Signature · 1 line
1.9.1