qcom: Add support for TSENS driver
Subsystems (7)
v2 cover qcom: Add support for TSENS driver
Changes since v1:
* Created virtual tsens device from gcc driver for 8960, with DT having a single node for gcc and tsens
* Minor fixes with rebasing on 4.3-rc1
Changes since RFC:
* Added support for 8916 and 8084
* Based off the latest nvmem framework patches [1]
* Minor review fixes for comments mostly from Lina
This is an attempt to have a single TSENS driver for the different versions of the TSENS IP that exist, on different qcom msm/apq SoCs'
Support is added for msm8916, msm8960 and msm8974 families.
A lot of the work is based of original code from Stephen Boyd and Siddartha Mohanadoss. I have also picked some of what Narendran Rajan did in his attempt to upstream the support for 8960 family. I could not keep the original authorship on any of the patches because I ended up moving the code around quite a bit in an effort to have a single driver for the various devices. I would be glad to change the authorship for any of the patches if needed.
Rajendra Nayak (9):
thermal: qcom: tsens: Add a skeletal TSENS drivers
thermal: qcom: tsens-8916: Add support for 8916 family of SoCs
thermal: qcom: tsens-8974: Add support for 8974 family of SoCs
clk: qcom: create virtual child device for TSENS
thermal: qcom: tsens-8960: Add support for 8960 family of SoCs
arm: dts: msm8974: Add thermal zones, tsens and qfprom nodes
arm: dts: apq8064: Add thermal zones, tsens and qfprom nodes
arm: dts: apq8084: Add thermal zones, tsens and qfprom nodes
arm64: dts: msm8916: Add thermal zones, tsens and qfprom nodes
.../devicetree/bindings/thermal/qcom-tsens.txt | 36 +++ arch/arm/boot/dts/qcom-apq8064.dtsi | 101 +++++++ arch/arm/boot/dts/qcom-apq8084.dtsi | 105 ++++++++ arch/arm/boot/dts/qcom-msm8974.dtsi | 105 ++++++++ arch/arm64/boot/dts/qcom/msm8916.dtsi | 66 +++++ drivers/clk/qcom/gcc-msm8960.c | 23 +- drivers/thermal/Kconfig | 5 + drivers/thermal/Makefile | 1 + drivers/thermal/qcom/Kconfig | 10 + drivers/thermal/qcom/Makefile | 2 + drivers/thermal/qcom/tsens-8916.c | 107 ++++++++ drivers/thermal/qcom/tsens-8960.c | 291 +++++++++++++++++++++ drivers/thermal/qcom/tsens-8974.c | 239 +++++++++++++++++ drivers/thermal/qcom/tsens-common.c | 130 +++++++++ drivers/thermal/qcom/tsens.c | 215 +++++++++++++++ drivers/thermal/qcom/tsens.h | 69 +++++ 16 files changed, 1504 insertions(+), 1 deletion(-) create mode 100644 Documentation/devicetree/bindings/thermal/qcom-tsens.txt create mode 100644 drivers/thermal/qcom/Kconfig create mode 100644 drivers/thermal/qcom/Makefile create mode 100644 drivers/thermal/qcom/tsens-8916.c create mode 100644 drivers/thermal/qcom/tsens-8960.c create mode 100644 drivers/thermal/qcom/tsens-8974.c create mode 100644 drivers/thermal/qcom/tsens-common.c create mode 100644 drivers/thermal/qcom/tsens.c create mode 100644 drivers/thermal/qcom/tsens.h
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
PATCH v2 1/9 thermal: qcom: tsens: Add a skeletal TSENS drivers
TSENS is Qualcomms' thermal temperature sensor device. It supports reading temperatures from multiple thermal sensors present on various QCOM SoCs.
Calibration data is generally read from a non-volatile memory (eeprom) device.
Add a skeleton driver with all the necessary abstractions so a variety of qcom device families which support TSENS can add driver extensions.
Also add the required device tree bindings which can be used to describe the TSENS device in DT.
--- .../devicetree/bindings/thermal/qcom-tsens.txt | 36 ++++ drivers/thermal/Kconfig | 5 + drivers/thermal/Makefile | 1 + drivers/thermal/qcom/Kconfig | 10 + drivers/thermal/qcom/Makefile | 2 + drivers/thermal/qcom/tsens.c | 208 +++++++++++++++++++++ drivers/thermal/qcom/tsens.h | 58 ++++++ 7 files changed, 320 insertions(+) create mode 100644 Documentation/devicetree/bindings/thermal/qcom-tsens.txt create mode 100644 drivers/thermal/qcom/Kconfig create mode 100644 drivers/thermal/qcom/Makefile create mode 100644 drivers/thermal/qcom/tsens.c create mode 100644 drivers/thermal/qcom/tsens.h
Documentation/devicetree/bindings/thermal/qcom-tsens.txt new file +36 -0
@@ -0,0 +1,36 @@ +* QCOM SoC Temperature Sensor (TSENS) + +Required properties: +- compatible : + - "qcom,msm8916-tsens" : For 8916 Family of SoCs + - "qcom,msm8974-tsens" : For 8974 Family of SoCs + +- reg: Address range of the thermal registers +- qcom,tsens-slopes : Must contain slope value for each of the sensors controlled + by this device +- #thermal-sensor-cells : Should be 1. See ./thermal.txt for a description. +- Refer to Documentation/devicetree/bindings/nvmem/nvmem.txt to know how to specify +nvmem cells + +Optional properties: +- qcom,sensor-id: List of sensor instances used in a given SoC. A TSENS IP can + have a fixed number of sensors (like 11) but a given SoC can + use only 5 of these and they might not always the first 5. They + could be sensors 0, 1, 4, 8 and 9. This property is used to + describe the subset of the sensors used. If this property is + missing they are assumed to be the first 'n' sensors numbered + sequentially in which case the number of sensors defaults to + the number of slope values. + +Example: +tsens: thermal-sensor at 900000 { + compatible = "qcom,msm8916-tsens"; + qcom,tsens-slopes = <1176 1176 1154 1176 1111 + 1132 1132 1199 1132 1199 + 1132>; + nvmem-cells = <&tsens_caldata>, <&tsens_calsel>; + nvmem-cell-names = "caldata", "calsel"; + qcom,tsens-slopes = <3200 3200 3200 3200 3200>; + qcom,sensor-id = <0 1 2 4 5>; + #thermal-sensor-cells = <1>; + };
drivers/thermal/Kconfig +5 -0
@@ -373,4 +373,9 @@ config QCOM_SPMI_TEMP_ALARM real time die temperature if an ADC is present or an estimate of the temperature based upon the over temperature stage value. +menu "Qualcomm thermal drivers" +depends on ARCH_QCOM && OF +source "drivers/thermal/qcom/Kconfig" +endmenu + endif
drivers/thermal/Makefile +1 -0
@@ -43,5 +43,6 @@ obj-$(CONFIG_TI_SOC_THERMAL) += ti-soc-thermal/ obj-$(CONFIG_INT340X_THERMAL) += int340x_thermal/ obj-$(CONFIG_INTEL_PCH_THERMAL) += intel_pch_thermal.o obj-$(CONFIG_ST_THERMAL) += st/ +obj-$(CONFIG_QCOM_TSENS) += qcom/ obj-$(CONFIG_TEGRA_SOCTHERM) += tegra_soctherm.o obj-$(CONFIG_HISI_THERMAL) += hisi_thermal.o
drivers/thermal/qcom/Kconfig new file +10 -0
@@ -0,0 +1,10 @@ +config QCOM_TSENS + tristate "Qualcomm TSENS Temperature Alarm" + depends on THERMAL + depends on QCOM_QFPROM + help + This enables the thermal sysfs driver for the TSENS device. It shows + up in Sysfs as a thermal zone with multiple trip points. Disabling the + thermal zone device via the mode file results in disabling the sensor. + Also able to set threshold temperature for both hot and cold and update + when a threshold is reached.
drivers/thermal/qcom/Makefile new file +2 -0
@@ -0,0 +1,2 @@ +obj-$(CONFIG_QCOM_TSENS) += qcom_tsens.o +qcom_tsens-y += tsens.o
drivers/thermal/qcom/tsens.c new file +208 -0
208 lines not on this page · raw message
drivers/thermal/qcom/tsens.h new file +58 -0
58 lines not on this page · raw message
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
PATCH v2 2/9 thermal: qcom: tsens-8916: Add support for 8916 family of SoCs
In reply to Rajendra NayakAdd support to calibrate sensors on 8916 family and also add common functions to read temperature from sensors (This can be reused on other SoCs having similar TSENS device)
The calibration data is read from eeprom using the generic nvmem framework apis.
Based on the original code by Siddartha Mohanadoss and Stephen Boyd.
--- drivers/thermal/qcom/Makefile | 2 +- drivers/thermal/qcom/tsens-8916.c | 107 +++++++++++++++++++++++++++++ drivers/thermal/qcom/tsens-common.c | 130 ++++++++++++++++++++++++++++++++++++ drivers/thermal/qcom/tsens.c | 1 + drivers/thermal/qcom/tsens.h | 11 +++ 5 files changed, 250 insertions(+), 1 deletion(-) create mode 100644 drivers/thermal/qcom/tsens-8916.c create mode 100644 drivers/thermal/qcom/tsens-common.c
drivers/thermal/qcom/Makefile +1 -1
@@ -1,2 +1,2 @@ obj-$(CONFIG_QCOM_TSENS) += qcom_tsens.o -qcom_tsens-y += tsens.o +qcom_tsens-y += tsens.o tsens-common.o tsens-8916.o
drivers/thermal/qcom/tsens-8916.c new file +107 -0
107 lines not on this page · raw message
drivers/thermal/qcom/tsens-common.c new file +130 -0
130 lines not on this page · raw message
drivers/thermal/qcom/tsens.c +1 -0
@@ -71,6 +71,7 @@ static SIMPLE_DEV_PM_OPS(tsens_pm_ops, tsens_suspend, tsens_resume);static const struct of_device_id tsens_table[] = { { .compatible ="qcom,msm8916-tsens" , + .data = &ops_8916, }, { .compatible ="qcom,msm8974-tsens" , },
drivers/thermal/qcom/tsens.h +11 -0
@@ -13,6 +13,10 @@#ifndef __QCOM_TSENS_H__#define __QCOM_TSENS_H__ +#define ONE_PT_CALIB 0x1 +#define ONE_PT_CALIB2 0x2 +#define TWO_PT_CALIB 0x3 +struct tsens_device ; struct tsens_sensor {
@@ -55,4 +59,11 @@ struct tsens_device { struct tsens_sensor sensor[0]; }; +char *qfprom_read (struct device *,const char *); +void compute_intercept_slope (struct tsens_device *,u32 *,u32 *,u32 ); +int init_common (struct tsens_device *); +int get_temp_common (struct tsens_device *,int ,int *); + +extern const struct tsens_ops ops_8916; +#endif /* __QCOM_TSENS_H__ */
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
PATCH v2 3/9 thermal: qcom: tsens-8974: Add support for 8974 family of SoCs
In reply to Rajendra NayakAdd .calibrate support for 8974 family as part of tsens_ops.
Based on the original code by Siddartha Mohanadoss and Stephen Boyd.
--- drivers/thermal/qcom/Makefile | 2 +- drivers/thermal/qcom/tsens-8974.c | 239 ++++++++++++++++++++++++++++++++++++++ drivers/thermal/qcom/tsens.c | 1 + drivers/thermal/qcom/tsens.h | 2 +- 4 files changed, 242 insertions(+), 2 deletions(-) create mode 100644 drivers/thermal/qcom/tsens-8974.c
drivers/thermal/qcom/Makefile +1 -1
@@ -1,2 +1,2 @@ obj-$(CONFIG_QCOM_TSENS) += qcom_tsens.o -qcom_tsens-y += tsens.o tsens-common.o tsens-8916.o +qcom_tsens-y += tsens.o tsens-common.o tsens-8916.o tsens-8974.o
drivers/thermal/qcom/tsens-8974.c new file +239 -0
239 lines not on this page · raw message
drivers/thermal/qcom/tsens.c +1 -0
@@ -74,6 +74,7 @@ static const struct of_device_id tsens_table[] = { .data = &ops_8916, }, { .compatible = "qcom,msm8974-tsens", + .data = &ops_8974, }, {} };
drivers/thermal/qcom/tsens.h +1 -1
@@ -64,6 +64,6 @@ void compute_intercept_slope(struct tsens_device *, u32 *, u32 *, u32);int init_common (struct tsens_device *);int get_temp_common (struct tsens_device *,int ,int *); -extern const struct tsens_ops ops_8916; +extern const struct tsens_ops ops_8916, ops_8974;#endif /* __QCOM_TSENS_H__ */
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
PATCH v2 4/9 clk: qcom: create virtual child device for TSENS
In reply to Rajendra Nayak8960 family of devices have TSENS as part of GCC in hardware. Hence DT would represent a GCC node with GCC properties as well as TSENS. Create a virtual platform child device here for TSENS so the driver can probe it and use the parent (GCC) to extract DT properties.
--- drivers/clk/qcom/gcc-msm8960.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)
drivers/clk/qcom/gcc-msm8960.c +22 -1
@@ -3506,6 +3506,8 @@ static int gcc_msm8960_probe(struct platform_device *pdev)struct clk *clk;struct device *dev = &pdev->dev;const struct of_device_id *match; +struct platform_device *tsens; +int ret; match =of_match_device (gcc_msm8960_match_table, &pdev->dev);if (!match)
@@ -3520,7 +3522,26 @@ static int gcc_msm8960_probe(struct platform_device *pdev)if (IS_ERR (clk))return PTR_ERR (clk); -return qcom_cc_probe (pdev, match->data); + ret =qcom_cc_probe (pdev, match->data); +if (ret) +return ret; + + tsens =platform_device_alloc ("qcom-tsens" ,-1 ); +if (!tsens) { + ret = -ENOMEM ; + goto err_alloc; + } + + tsens->dev.parent = &pdev->dev; + ret =platform_device_add (tsens); +if (ret) + goto err_add; +return 0 ; +err_add: +platform_device_put (tsens); +err_alloc: +qcom_cc_remove (pdev); +return ret; }static int gcc_msm8960_remove (struct platform_device *pdev)
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
PATCH v2 5/9 thermal: qcom: tsens-8960: Add support for 8960 family of SoCs
In reply to Rajendra Nayak8960 family of SoCs have the TSENS device as part of GCC, hence the driver probes the virtual child device created by GCC and uses the parent to extract all DT properties and reuses the GCC regmap.
Also GCC/TSENS are part of a domain thats not always ON. Hence add .suspend and .resume hooks to save and restore some of the inited register context.
Also 8960 family have some of the TSENS init sequence thats required to be done by the HLOS driver (some later versions of TSENS do not export these registers to non-secure world, and hence need these initializations to be done by secure bootloaders)
8660 from the same family has just one sensor and hence some register offset/layout differences which need special handling in the driver.
Based on the original code from Siddartha Mohanadoss, Stephen Boyd and Narendran Rajan.
--- drivers/thermal/qcom/Makefile | 2 +- drivers/thermal/qcom/tsens-8960.c | 291 ++++++++++++++++++++++++++++++++++++++ drivers/thermal/qcom/tsens.c | 13 +- drivers/thermal/qcom/tsens.h | 2 +- 4 files changed, 302 insertions(+), 6 deletions(-) create mode 100644 drivers/thermal/qcom/tsens-8960.c
drivers/thermal/qcom/Makefile +1 -1
@@ -1,2 +1,2 @@ obj-$(CONFIG_QCOM_TSENS) += qcom_tsens.o -qcom_tsens-y += tsens.o tsens-common.o tsens-8916.o tsens-8974.o +qcom_tsens-y += tsens.o tsens-common.o tsens-8916.o tsens-8974.o tsens-8960.o
drivers/thermal/qcom/tsens-8960.c new file +291 -0
291 lines not on this page · raw message
drivers/thermal/qcom/tsens.c +9 -4
@@ -128,7 +128,11 @@ static int tsens_probe(struct platform_device *pdev)struct tsens_device *tmdev;const struct of_device_id *id; - dev = &pdev->dev; +if (pdev->dev.of_node) + dev = &pdev->dev; +else + dev = pdev->dev.parent; + np = dev->of_node; num =of_property_count_u32_elems (np,"qcom,tsens-slopes" );
@@ -150,10 +154,11 @@ static int tsens_probe(struct platform_device *pdev) &s->slope); id =of_match_node (tsens_table, np); -if (!id) -return -ENODEV ; +if (id) + tmdev->ops = id->data; +else + tmdev->ops = &ops_8960; - tmdev->ops = id->data;if (!tmdev->ops || !tmdev->ops->init || !tmdev->ops->calibrate || !tmdev->ops->get_temp)return -EINVAL ;
drivers/thermal/qcom/tsens.h +1 -1
@@ -64,6 +64,6 @@ void compute_intercept_slope(struct tsens_device *, u32 *, u32 *, u32);int init_common (struct tsens_device *);int get_temp_common (struct tsens_device *,int ,int *); -extern const struct tsens_ops ops_8916, ops_8974; +extern const struct tsens_ops ops_8960, ops_8916, ops_8974;#endif /* __QCOM_TSENS_H__ */
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
PATCH v2 6/9 arm: dts: msm8974: Add thermal zones, tsens and qfprom nodes
In reply to Rajendra NayakAdd thermal zones, tsens and qfprom nodes
--- arch/arm/boot/dts/qcom-msm8974.dtsi | 105 ++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+)
arch/arm/boot/dts/qcom-msm8974.dtsi +105 -0
@@ -86,6 +86,88 @@ }; }; + thermal-zones { + cpu-thermal0 { + polling-delay-passive = <250>; + polling-delay = <1000>; + + thermal-sensors = <&tsens 5>; + + trips { + cpu_alert0: trip at 0 { + temperature = <75000>; + hysteresis = <2000>; + type = "passive"; + }; + cpu_crit0: trip at 1 { + temperature = <95000>; + hysteresis = <2000>; + type = "critical"; + }; + }; + }; + + cpu-thermal1 { + polling-delay-passive = <250>; + polling-delay = <1000>; + + thermal-sensors = <&tsens 6>; + + trips { + cpu_alert1: trip at 0 { + temperature = <75000>; + hysteresis = <2000>; + type = "passive"; + }; + cpu_crit1: trip at 1 { + temperature = <95000>; + hysteresis = <2000>; + type = "critical"; + }; + }; + }; + + cpu-thermal2 { + polling-delay-passive = <250>; + polling-delay = <1000>; + + thermal-sensors = <&tsens 7>; + + trips { + cpu_alert2: trip at 0 { + temperature = <75000>; + hysteresis = <2000>; + type = "passive"; + }; + cpu_crit2: trip at 1 { + temperature = <95000>; + hysteresis = <2000>; + type = "critical"; + }; + }; + }; + + cpu-thermal3 { + polling-delay-passive = <250>; + polling-delay = <1000>; + + thermal-sensors = <&tsens 8>; + + trips { + cpu_alert3: trip at 0 { + temperature = <75000>; + hysteresis = <2000>; + type = "passive"; + }; + cpu_crit3: trip at 1 { + temperature = <95000>; + hysteresis = <2000>; + type = "critical"; + }; + }; + }; + }; + cpu-pmu { compatible = "qcom,krait-pmu"; interrupts = <1 7 0xf04>;
@@ -114,6 +196,29 @@ <0xf9002000 0x1000>; }; + qfprom: qfprom at fc4bc000 { + #address-cells = <1>; + #size-cells = <1>; + compatible = "qcom,qfprom"; + reg = <0xfc4bc000 0x1000>; + tsens_calib: calib at d0 { + reg = <0xd0 0x18>; + }; + tsens_backup: backup at 440 { + reg = <0x440 0x10>; + }; + }; + + tsens: thermal-sensor at fc4a8000 { + compatible = "qcom,msm8974-tsens"; + reg = <0xfc4a8000 0x2000>; + nvmem-cells = <&tsens_calib>, <&tsens_backup>; + nvmem-cell-names = "calib", "calib_backup"; + qcom,tsens-slopes = <3200 3200 3200 3200 3200 3200 + 3200 3200 3200 3200 3200>; + #thermal-sensor-cells = <1>; + }; + timer at f9020000 { #address-cells = <1>; #size-cells = <1>;
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
PATCH v2 7/9 arm: dts: apq8064: Add thermal zones, tsens and qfprom nodes
In reply to Rajendra NayakTSENS is part of GCC, hence add TSENS properties as part of GCC node. Also add thermal zones and qfprom nodes.
--- arch/arm/boot/dts/qcom-apq8064.dtsi | 101 ++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+)
arch/arm/boot/dts/qcom-apq8064.dtsi +101 -0
@@ -75,6 +75,88 @@ }; }; + thermal-zones { + cpu-thermal0 { + polling-delay-passive = <250>; + polling-delay = <1000>; + + thermal-sensors = <&gcc 7>; + + trips { + cpu_alert0: trip at 0 { + temperature = <75000>; + hysteresis = <2000>; + type = "passive"; + }; + cpu_crit0: trip at 1 { + temperature = <95000>; + hysteresis = <2000>; + type = "critical"; + }; + }; + }; + + cpu-thermal1 { + polling-delay-passive = <250>; + polling-delay = <1000>; + + thermal-sensors = <&gcc 8>; + + trips { + cpu_alert1: trip at 0 { + temperature = <75000>; + hysteresis = <2000>; + type = "passive"; + }; + cpu_crit1: trip at 1 { + temperature = <95000>; + hysteresis = <2000>; + type = "critical"; + }; + }; + }; + + cpu-thermal2 { + polling-delay-passive = <250>; + polling-delay = <1000>; + + thermal-sensors = <&gcc 9>; + + trips { + cpu_alert2: trip at 0 { + temperature = <75000>; + hysteresis = <2000>; + type = "passive"; + }; + cpu_crit2: trip at 1 { + temperature = <95000>; + hysteresis = <2000>; + type = "critical"; + }; + }; + }; + + cpu-thermal3 { + polling-delay-passive = <250>; + polling-delay = <1000>; + + thermal-sensors = <&gcc 10>; + + trips { + cpu_alert3: trip at 0 { + temperature = <75000>; + hysteresis = <2000>; + type = "passive"; + }; + cpu_crit3: trip at 1 { + temperature = <95000>; + hysteresis = <2000>; + type = "critical"; + }; + }; + }; + }; + cpu-pmu { compatible = "qcom,krait-pmu"; interrupts = <1 10 0x304>;
@@ -364,11 +446,30 @@ }; }; + qfprom: qfprom at 00700000 { + compatible = "qcom,qfprom"; + reg = <0x00700000 0x1000>; + #address-cells = <1>; + #size-cells = <1>; + ranges; + tsens_calib: calib { + reg = <0x404 0x10>; + }; + tsens_backup: backup_calib { + reg = <0x414 0x10>; + }; + }; + gcc: clock-controller at 900000 { compatible = "qcom,gcc-apq8064"; reg = <0x00900000 0x4000>; + nvmem-cells = <&tsens_calib>, <&tsens_backup>; + nvmem-cell-names = "calib", "calib_backup"; + qcom,tsens-slopes = <1176 1176 1154 1176 1111 + 1132 1132 1199 1132 1199 1132>; #clock-cells = <1>; #reset-cells = <1>; + #thermal-sensor-cells = <1>; }; lcc: clock-controller at 28000000 {
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
PATCH v2 8/9 arm: dts: apq8084: Add thermal zones, tsens and qfprom nodes
In reply to Rajendra NayakAdd thermal zones, tsens and qfprom nodes
--- arch/arm/boot/dts/qcom-apq8084.dtsi | 105 ++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+)
arch/arm/boot/dts/qcom-apq8084.dtsi +105 -0
@@ -75,6 +75,88 @@ }; }; + thermal-zones { + cpu-thermal0 { + polling-delay-passive = <250>; + polling-delay = <1000>; + + thermal-sensors = <&tsens 5>; + + trips { + cpu_alert0: trip at 0 { + temperature = <75000>; + hysteresis = <2000>; + type = "passive"; + }; + cpu_crit0: trip at 1 { + temperature = <95000>; + hysteresis = <2000>; + type = "critical"; + }; + }; + }; + + cpu-thermal1 { + polling-delay-passive = <250>; + polling-delay = <1000>; + + thermal-sensors = <&tsens 6>; + + trips { + cpu_alert1: trip at 0 { + temperature = <75000>; + hysteresis = <2000>; + type = "passive"; + }; + cpu_crit1: trip at 1 { + temperature = <95000>; + hysteresis = <2000>; + type = "critical"; + }; + }; + }; + + cpu-thermal2 { + polling-delay-passive = <250>; + polling-delay = <1000>; + + thermal-sensors = <&tsens 7>; + + trips { + cpu_alert2: trip at 0 { + temperature = <75000>; + hysteresis = <2000>; + type = "passive"; + }; + cpu_crit2: trip at 1 { + temperature = <95000>; + hysteresis = <2000>; + type = "critical"; + }; + }; + }; + + cpu-thermal3 { + polling-delay-passive = <250>; + polling-delay = <1000>; + + thermal-sensors = <&tsens 8>; + + trips { + cpu_alert3: trip at 0 { + temperature = <75000>; + hysteresis = <2000>; + type = "passive"; + }; + cpu_crit3: trip at 1 { + temperature = <95000>; + hysteresis = <2000>; + type = "critical"; + }; + }; + }; + }; + cpu-pmu { compatible = "qcom,krait-pmu"; interrupts = <1 7 0xf04>;
@@ -103,6 +185,29 @@ <0xf9002000 0x1000>; }; + qfprom: qfprom at fc4bc000 { + #address-cells = <1>; + #size-cells = <1>; + compatible = "qcom,qfprom"; + reg = <0xfc4bc000 0x1000>; + tsens_calib: calib at d0 { + reg = <0xd0 0x18>; + }; + tsens_backup: backup at 440 { + reg = <0x440 0x10>; + }; + }; + + tsens: thermal-sensor at fc4a8000 { + compatible = "qcom,msm8974-tsens"; + reg = <0xfc4a8000 0x2000>; + nvmem-cells = <&tsens_calib>, <&tsens_backup>; + nvmem-cell-names = "calib", "calib_backup"; + qcom,tsens-slopes = <3200 3200 3200 3200 3200 3200 + 3200 3200 3200 3200 3200>; + #thermal-sensor-cells = <1>; + }; + timer at f9020000 { #address-cells = <1>; #size-cells = <1>;
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
PATCH v2 9/9 arm64: dts: msm8916: Add thermal zones, tsens and qfprom nodes
In reply to Rajendra NayakAdd thermal zones, tsens and qfprom nodes
--- arch/arm64/boot/dts/qcom/msm8916.dtsi | 66 +++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+)
arch/arm64/boot/dts/qcom/msm8916.dtsi +66 -0
@@ -68,6 +68,49 @@ }; }; + thermal-zones { + cpu-thermal0 { + polling-delay-passive = <250>; + polling-delay = <1000>; + + thermal-sensors = <&tsens 4>; + + trips { + cpu_alert0: trip at 0 { + temperature = <100000>; + hysteresis = <2000>; + type = "passive"; + }; + cpu_crit0: trip at 1 { + temperature = <125000>; + hysteresis = <2000>; + type = "critical"; + }; + }; + }; + + cpu-thermal1 { + polling-delay-passive = <250>; + polling-delay = <1000>; + + thermal-sensors = <&tsens 3>; + + trips { + cpu_alert1: trip at 0 { + temperature = <100000>; + hysteresis = <2000>; + type = "passive"; + }; + cpu_crit1: trip at 1 { + temperature = <125000>; + hysteresis = <2000>; + type = "critical"; + }; + }; + }; + + }; + timer { compatible = "arm,armv8-timer"; interrupts = <GIC_PPI 2 (GIC_CPU_MASK_SIMPLE(4) | IRQ_TYPE_LEVEL_LOW)>,
@@ -392,6 +435,29 @@ interrupt-controller; #interrupt-cells = <4>; }; + + qfprom: qfprom at 5c000 { + compatible = "qcom,qfprom"; + reg = <0x5c000 0x1000>; + #address-cells = <1>; + #size-cells = <1>; + tsens_caldata: caldata at d0 { + reg = <0xd0 0x8>; + }; + tsens_calsel: calsel at ec { + reg = <0xec 0x4>; + }; + }; + + tsens: thermal-sensor at 4a8000 { + compatible = "qcom,msm8916-tsens"; + reg = <0x4a8000 0x2000>; + nvmem-cells = <&tsens_caldata>, <&tsens_calsel>; + nvmem-cell-names = "calib", "calib_sel"; + qcom,tsens-slopes = <3200 3200 3200 3200 3200>; + qcom,sensor-id = <0 1 2 4 5>; + #thermal-sensor-cells = <1>; + }; }; };
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
PATCH v2 1/9 thermal: qcom: tsens: Add a skeletal TSENS drivers
In reply to Rajendra NayakHi Rajendra,
I have some comments on the code below (purely based on code review).
Quoted 62 lines · Rajendra Nayak
TSENS is Qualcomms' thermal temperature sensor device. It supports reading temperatures from multiple thermal sensors present on various QCOM SoCs.
Calibration data is generally read from a non-volatile memory (eeprom) device.Add a skeleton driver with all the necessary abstractions so a variety of qcom device families which support TSENS can add driver extensions.
Also add the required device tree bindings which can be used to describe the TSENS device in DT.
Signed-off-by Rajendra Nayak <[email protected]>Reviewed-by Lina Iyer <[email protected]>--- .../devicetree/bindings/thermal/qcom-tsens.txt | 36 ++++ drivers/thermal/Kconfig | 5 + drivers/thermal/Makefile | 1 + drivers/thermal/qcom/Kconfig | 10 + drivers/thermal/qcom/Makefile | 2 + drivers/thermal/qcom/tsens.c | 208 +++++++++++++++++++++ drivers/thermal/qcom/tsens.h | 58 ++++++ 7 files changed, 320 insertions(+) create mode 100644 Documentation/devicetree/bindings/thermal/qcom-tsens.txt create mode 100644 drivers/thermal/qcom/Kconfig create mode 100644 drivers/thermal/qcom/Makefile create mode 100644 drivers/thermal/qcom/tsens.c create mode 100644 drivers/thermal/qcom/tsens.hDocumentation/devicetree/bindings/thermal/qcom-tsens.txt new file +26
-0@@ -0,0 +1,36 @@ +* QCOM SoC Temperature Sensor (TSENS) + +Required properties: +- compatible : + - "qcom,msm8916-tsens" : For 8916 Family of SoCs + - "qcom,msm8974-tsens" : For 8974 Family of SoCs + +- reg: Address range of the thermal registers +- qcom,tsens-slopes : Must contain slope value for each of the sensors controlled + by this device +- #thermal-sensor-cells : Should be 1. See ./thermal.txt for a description. +- Refer to Documentation/devicetree/bindings/nvmem/nvmem.txt to know how to specify +nvmem cells + +Optional properties: +- qcom,sensor-id: List of sensor instances used in a given SoC. A TSENS IP can + have a fixed number of sensors (like 11) but a given SoC can + use only 5 of these and they might not always the first 5. They + could be sensors 0, 1, 4, 8 and 9. This property is used to + describe the subset of the sensors used. If this property is + missing they are assumed to be the first 'n' sensors numbered + sequentially in which case the number of sensors defaults to + the number of slope values. + +Example: +tsens: thermal-sensor at 900000 {
Documentation/devicetree/bindings/thermal/qcom-tsens.txt line 36
Quoted 10 lines
Documentation/devicetree/bindings/thermal/qcom-tsens.txt new file +10
-0+ compatible = "qcom,msm8916-tsens"; + qcom,tsens-slopes = <1176 1176 1154 1176 1111 + 1132 1132 1199 1132 1199 + 1132>; + nvmem-cells = <&tsens_caldata>, <&tsens_calsel>; + nvmem-cell-names = "caldata", "calsel"; + qcom,tsens-slopes = <3200 3200 3200 3200 3200>; + qcom,sensor-id = <0 1 2 4 5>; + #thermal-sensor-cells = <1>; + };
The qcom,tsens-slopes property appears twice in the above example.
[...]
Quoted 63 lines
drivers/thermal/qcom/tsens.c new file +57
-0@@ -0,0 +1,208 @@ +/* +* Copyright (c) 2015, The Linux Foundation. All rights reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 and +* only version 2 as published by the Free Software Foundation. +* +* This program is distributed in the hope that 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. +* +*/ + +#include <linux/err.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/platform_device.h> +#include <linux/pm.h> +#include <linux/slab.h> +#include <linux/thermal.h> +#include "tsens.h" + +static int tsens_get_temp (void *data,int *temp) +{ +const struct tsens_sensor *s = data; +struct tsens_device *tmdev = s->tmdev; + +return tmdev->ops->get_temp (tmdev, s->id, temp); +} + +static int tsens_get_trend (void *data,long *temp) +{ +const struct tsens_sensor *s = data; +struct tsens_device *tmdev = s->tmdev; + +if (tmdev->ops->get_trend) +return tmdev->ops->get_trend (tmdev, s->id, temp); + +return -ENOSYS ; +} + +#ifdef CONFIG_PM +static int tsens_suspend (struct device *dev) +{ +struct tsens_device *tmdev =dev_get_drvdata (dev); + +if (tmdev->ops && tmdev->ops->suspend) +return tmdev->ops->suspend (tmdev); + +return 0 ; +} + +static int tsens_resume (struct device *dev) +{ +struct tsens_device *tmdev =dev_get_drvdata (dev); +
drivers/thermal/qcom/tsens.c line 67
Quoted 10 lines
drivers/thermal/qcom/tsens.c new file +10
-0+if (tmdev->ops && tmdev->ops->resume) +return tmdev->ops->resume (tmdev); + +return 0 ; +} + +static SIMPLE_DEV_PM_OPS(tsens_pm_ops, tsens_suspend, tsens_resume); +#define TSENS_PM_OPS (&tsens_pm_ops) + +#else /* CONFIG_PM_SLEEP */
^
drivers/thermal/qcom/tsens.c line 69
Quoted 2 lines
drivers/thermal/qcom/tsens.c new file +2
-0+#define TSENS_PM_OPS NULL +#endif /* CONFIG_PM_SLEEP */
^
The comments don't match the #ifdef above. I maybe wrong but looking at other drivers it looks like you don't need the #else part. You should be able to use the tsens_pm_ops without having to set it to NULL.
Quoted 25 lines
drivers/thermal/qcom/tsens.c new file +25
-0+ +static const struct of_device_id tsens_table[] = { + { + .compatible ="qcom,msm8916-tsens" , + }, { + .compatible ="qcom,msm8974-tsens" , + }, + {} +}; +MODULE_DEVICE_TABLE (of, tsens_table); + +static const struct thermal_zone_of_device_ops tsens_of_ops = { + .get_temp = tsens_get_temp, + .get_trend = tsens_get_trend, +}; + +static int tsens_register (struct tsens_device *tmdev) +{ +int i, ret; +struct thermal_zone_device *tzd; +u32 *hw_id, n = tmdev->num_sensors; +struct device_node *np = tmdev->dev->of_node; + + hw_id =devm_kcalloc (tmdev->dev, n,sizeof (u32),GFP_KERNEL ); +if (!hw_id)
drivers/thermal/qcom/tsens.c line 104
Quoted 10 lines
drivers/thermal/qcom/tsens.c new file +10
-0+return -ENOMEM ; + + ret =of_property_read_u32_array (np,"qcom,sensor-id" , hw_id, n); +if (ret) +for (i =0 ; i < tmdev->num_sensors; i++) + tmdev->sensor[i].hw_id = i; +else +for (i =0 ; i < tmdev->num_sensors; i++) + tmdev->sensor[i].hw_id = hw_id[i]; +
You could move the check for vaild for valid sensor ids in the device tree (ret) inside a single for loop. In that case the loop above could be merged into the iteration over the sensors below.
Quoted 16 lines
drivers/thermal/qcom/tsens.c new file +16
-0+for (i =0 ; i < tmdev->num_sensors; i++) { + tmdev->sensor[i].tmdev = tmdev; + tmdev->sensor[i].id = i; + tzd =thermal_zone_of_sensor_register (tmdev->dev, i, + &tmdev->sensor[i], + &tsens_of_ops); +if (IS_ERR (tzd)) +continue ; + tmdev->sensor[i].tzd = tzd; +if (tmdev->ops->enable) + tmdev->ops->enable (tmdev, i); + } +return 0 ; +} + +static int tsens_probe (struct platform_device *pdev)
drivers/thermal/qcom/tsens.c line 130
Quoted 10 lines
drivers/thermal/qcom/tsens.c new file +10
-0+{ +int ret, i, num; +struct device *dev; +struct device_node *np; +struct tsens_sensor *s; +struct tsens_device *tmdev; +const struct of_device_id *id; + + dev = &pdev->dev; + np = dev->of_node;
These assignments can be done with the declaration above.
Thanks,
Punit
Quoted 78 lines
drivers/thermal/qcom/tsens.c new file +78
-0+ + num =of_property_count_u32_elems (np,"qcom,tsens-slopes" ); +if (num <=0 ) { +dev_err (dev,"invalid tsens slopes\n" ); +return -EINVAL ; + } + + tmdev =devm_kzalloc (dev,sizeof (*tmdev) + + num *sizeof (*s),GFP_KERNEL ); +if (!tmdev) +return -ENOMEM ; + + tmdev->dev = dev; + tmdev->num_sensors = num; + +for (i =0 , s = tmdev->sensor; i < tmdev->num_sensors; i++, s++) +of_property_read_u32_index (np,"qcom,tsens-slopes" , i, + &s->slope); + + id =of_match_node (tsens_table, np); +if (!id) +return -ENODEV ; + + tmdev->ops = id->data; +if (!tmdev->ops || !tmdev->ops->init || !tmdev->ops->calibrate || + !tmdev->ops->get_temp) +return -EINVAL ; + + ret = tmdev->ops->init (tmdev); +if (ret <0 ) { +dev_err (dev,"tsens init failed\n" ); +return ret; + } + + ret = tmdev->ops->calibrate (tmdev); +if (ret <0 ) { +dev_err (dev,"tsens calibration failed\n" ); +return ret; + } + + ret =tsens_register (tmdev); + +platform_set_drvdata (pdev, tmdev); + +return ret; +} + +static int tsens_remove (struct platform_device *pdev) +{ +int i; +struct tsens_device *tmdev =platform_get_drvdata (pdev); +struct thermal_zone_device *tzd; + +if (tmdev->ops->disable) + tmdev->ops->disable (tmdev); + +for (i =0 ; i < tmdev->num_sensors; i++) { + tzd = tmdev->sensor[i].tzd; +thermal_zone_of_sensor_unregister (&pdev->dev, tzd); + } + +return 0 ; +} + +static struct platform_driver tsens_driver = { + .probe = tsens_probe, + .remove = tsens_remove, + .driver = { + .name ="qcom-tsens" , + .pm =TSENS_PM_OPS , + .of_match_table = tsens_table, + }, +}; +module_platform_driver (tsens_driver); + +MODULE_LICENSE ("GPL v2" ); +MODULE_DESCRIPTION ("QCOM Temperature Sensor driver" ); +MODULE_ALIAS ("platform:qcom-tsens" );
[...]
PATCH v2 2/9 thermal: qcom: tsens-8916: Add support for 8916 family of SoCs
In reply to Rajendra NayakHi Rajendra,
One comment below.
Quoted 19 lines · Rajendra Nayak
Add support to calibrate sensors on 8916 family and also add common functions to read temperature from sensors (This can be reused on other SoCs having similar TSENS device)
The calibration data is read from eeprom using the generic nvmem framework apis.Based on the original code by Siddartha Mohanadoss and Stephen Boyd.
Signed-off-by Rajendra Nayak <[email protected]>--- drivers/thermal/qcom/Makefile | 2 +- drivers/thermal/qcom/tsens-8916.c | 107 +++++++++++++++++++++++++++++ drivers/thermal/qcom/tsens-common.c | 130 ++++++++++++++++++++++++++++++++++++ drivers/thermal/qcom/tsens.c | 1 + drivers/thermal/qcom/tsens.h | 11 +++ 5 files changed, 250 insertions(+), 1 deletion(-) create mode 100644 drivers/thermal/qcom/tsens-8916.c create mode 100644 drivers/thermal/qcom/tsens-common.c
[...]
Quoted 105 lines
drivers/thermal/qcom/tsens-common.c new file +99
-0@@ -0,0 +1,130 @@ +/* +* Copyright (c) 2015, The Linux Foundation. All rights reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 and +* only version 2 as published by the Free Software Foundation. +* +* This program is distributed in the hope that 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. +* +*/ + +#include <linux/platform_device.h> +#include <linux/nvmem-consumer.h> +#include <linux/err.h> +#include <linux/io.h> +#include <linux/of_address.h> +#include <linux/regmap.h> +#include "tsens.h" + +#define S0_ST_ADDR 0x1030 +#define SN_ADDR_OFFSET 0x4 +#define SN_ST_TEMP_MASK 0x3ff +#define CAL_DEGC_PT1 30 +#define CAL_DEGC_PT2 120 +#define SLOPE_FACTOR 1000 + +char *qfprom_read (struct device *dev,const char *cname) +{ +struct nvmem_cell *cell; +ssize_t data; +char *ret; + + cell =nvmem_cell_get (dev, cname); +if (IS_ERR (cell)) +return ERR_CAST (cell); + + ret =nvmem_cell_read (cell, &data); +nvmem_cell_put (cell); +return ret; +} + +void compute_intercept_slope (struct tsens_device *tmdev,u32 *p1, +u32 *p2,u32 mode) +{ +int i; +int num, den; + +for (i =0 ; i < tmdev->num_sensors; i++) { +dev_dbg (tmdev->dev, +"sensor%d - data_point1:%#x data_point2:%#x\n" , + i, p1[i], p2[i]); + +if (mode ==TWO_PT_CALIB ) { +/* +* slope (m) = adc_code2 - adc_code1 (y2 - y1)/ +* temp_120_degc - temp_30_degc (x2 - x1) +*/ + num = p2[i] - p1[i]; + num *=SLOPE_FACTOR ; + den =CAL_DEGC_PT2 -CAL_DEGC_PT1 ; + tmdev->sensor[i].slope = num / den; + } + + tmdev->sensor[i].offset = (p1[i] *SLOPE_FACTOR ) - + (CAL_DEGC_PT1 * + tmdev->sensor[i].slope); +dev_dbg (tmdev->dev,"offset:%d\n" , tmdev->sensor[i].offset); + } +} + +static inline int code_to_degc (u32 adc_code,const struct tsens_sensor *s) +{ +int degc, num, den; + + num = (adc_code *SLOPE_FACTOR ) - s->offset; + den = s->slope; + +if (num >0 ) + degc = num + (den /2 ); +else if (num <0 ) + degc = num - (den /2 ); +else + degc = num; + + degc /= den; + +return degc; +} + +int get_temp_common (struct tsens_device *tmdev,int id,int *temp) +{ +struct tsens_sensor *s = &tmdev->sensor[id]; +u32 code; +unsigned int sensor_addr; +int last_temp =0 , ret; +
drivers/thermal/qcom/tsens-common.c line 109
Quoted 10 lines
drivers/thermal/qcom/tsens-common.c new file +10
-0+ sensor_addr =S0_ST_ADDR + s->hw_id *SN_ADDR_OFFSET ; + ret =regmap_read (tmdev->map, sensor_addr, &code); +if (ret) +return ret; + last_temp = code &SN_ST_TEMP_MASK ; + + *temp =code_to_degc (last_temp, s) *1000 ; + +return 0 ; +}
The way this function is coded the temperature will only ever change by 1C (i.e., 1000mC). Is there a chance that you're losing precision in the code_to_degc conversion that could be preserved perhaps?
This is useful in scenarios where you use the power allocator governor and the greater precision allows better power budget estimation.
Quoted 21 lines
drivers/thermal/qcom/tsens-common.c new file +21
-0+ +static const struct regmap_config tsens_config = { + .reg_bits =32 , + .val_bits =32 , + .reg_stride =4 , +}; + +int init_common (struct tsens_device *tmdev) +{ +void __iomem *base; + + base =of_iomap (tmdev->dev->of_node,0 ); +if (IS_ERR (base)) +return -EINVAL ; + + tmdev->map =devm_regmap_init_mmio (tmdev->dev, base, &tsens_config); +if (!tmdev->map) +return -ENODEV ; + +return 0 ; +}
[...]
PATCH v2 4/9 clk: qcom: create virtual child device for TSENS
In reply to Rajendra NayakQuoted 9 lines · Rajendra Nayak
drivers/clk/qcom/gcc-msm8960.c +4
-1@@ -3520,7 +3522,26 @@ static int gcc_msm8960_probe(struct platform_device *pdev)if (IS_ERR (clk))return PTR_ERR (clk); -return qcom_cc_probe (pdev, match->data); + ret =qcom_cc_probe (pdev, match->data); +if (ret) +return ret; +
drivers/clk/qcom/gcc-msm8960.c static int gcc_msm8960_probe(struct platform_device *pdev) · line 3538
Quoted 10 lines
drivers/clk/qcom/gcc-msm8960.c +10
-0+ tsens =platform_device_alloc ("qcom-tsens" ,-1 ); +if (!tsens) { + ret = -ENOMEM ; + goto err_alloc; + } + + tsens->dev.parent = &pdev->dev; + ret =platform_device_add (tsens); +if (ret) + goto err_add;
platform_device_register_data() instead of all these lines? We should probably remove the device when this driver is removed too.
Quoted 1 line
drivers/clk/qcom/gcc-msm8960.c +1
-0+return 0 ;
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
PATCH v2 1/9 thermal: qcom: tsens: Add a skeletal TSENS drivers
In reply to Punit Agrawal[]..
Quoted 6 lines
Quoted 6 lines
Documentation/devicetree/bindings/thermal/qcom-tsens.txt new file +6
-0+Example: +tsens: thermal-sensor at 900000 { + compatible = "qcom,msm8916-tsens"; + qcom,tsens-slopes = <1176 1176 1154 1176 1111 + 1132 1132 1199 1132 1199 + 1132>;
Quoted 8 lines
Documentation/devicetree/bindings/thermal/qcom-tsens.txt line 36
Quoted 6 lines
Documentation/devicetree/bindings/thermal/qcom-tsens.txt new file +6
-0+ nvmem-cells = <&tsens_caldata>, <&tsens_calsel>; + nvmem-cell-names = "caldata", "calsel"; + qcom,tsens-slopes = <3200 3200 3200 3200 3200>; + qcom,sensor-id = <0 1 2 4 5>; + #thermal-sensor-cells = <1>; + };The qcom,tsens-slopes property appears twice in the above example.
sure, will fix.
Quoted 29 lines
[...]
Quoted 15 lines
drivers/thermal/qcom/tsens.c new file +15
-0+#ifdef CONFIG_PM +static int tsens_suspend (struct device *dev) +{ +struct tsens_device *tmdev =dev_get_drvdata (dev); + +if (tmdev->ops && tmdev->ops->suspend) +return tmdev->ops->suspend (tmdev); + +return 0 ; +} + +static int tsens_resume (struct device *dev) +{ +struct tsens_device *tmdev =dev_get_drvdata (dev); +drivers/thermal/qcom/tsens.c line 67
Quoted 10 lines
drivers/thermal/qcom/tsens.c new file +10
-0+if (tmdev->ops && tmdev->ops->resume) +return tmdev->ops->resume (tmdev); + +return 0 ; +} + +static SIMPLE_DEV_PM_OPS(tsens_pm_ops, tsens_suspend, tsens_resume); +#define TSENS_PM_OPS (&tsens_pm_ops) + +#else /* CONFIG_PM_SLEEP */ ^
Quoted 7 lines
drivers/thermal/qcom/tsens.c line 69
Quoted 2 lines
drivers/thermal/qcom/tsens.c new file +2
-0+#define TSENS_PM_OPS NULL +#endif /* CONFIG_PM_SLEEP */ ^The comments don't match the #ifdef above. I maybe wrong but looking at other drivers it looks like you don't need the #else part. You should be able to use the
tsens_pm_opswithout having to set it to NULL.
yes, I should be able to avoid the #else and thanks for catching the mismatched comments.
Quoted 32 lines
Quoted 32 lines
drivers/thermal/qcom/tsens.c new file +31
-0+ +static const struct of_device_id tsens_table[] = { + { + .compatible ="qcom,msm8916-tsens" , + }, { + .compatible ="qcom,msm8974-tsens" , + }, + {} +}; +MODULE_DEVICE_TABLE (of, tsens_table); + +static const struct thermal_zone_of_device_ops tsens_of_ops = { + .get_temp = tsens_get_temp, + .get_trend = tsens_get_trend, +}; + +static int tsens_register (struct tsens_device *tmdev) +{ +int i, ret; +struct thermal_zone_device *tzd; +u32 *hw_id, n = tmdev->num_sensors; +struct device_node *np = tmdev->dev->of_node; + + hw_id =devm_kcalloc (tmdev->dev, n,sizeof (u32),GFP_KERNEL ); +if (!hw_id) +return -ENOMEM ; + + ret =of_property_read_u32_array (np,"qcom,sensor-id" , hw_id, n); +if (ret) +for (i =0 ; i < tmdev->num_sensors; i++) + tmdev->sensor[i].hw_id = i;
Quoted 8 lines
drivers/thermal/qcom/tsens.c line 104
Quoted 4 lines
drivers/thermal/qcom/tsens.c new file +4
-0+else +for (i =0 ; i < tmdev->num_sensors; i++) + tmdev->sensor[i].hw_id = hw_id[i]; +You could move the check for vaild for valid sensor ids in the device tree (ret) inside a single for loop. In that case the loop above could be merged into the iteration over the sensors below.
sure, seems like a reasonable optimization to avoid a few loops.
Quoted 21 lines
Quoted 21 lines
drivers/thermal/qcom/tsens.c new file +20
-0+for (i =0 ; i < tmdev->num_sensors; i++) { + tmdev->sensor[i].tmdev = tmdev; + tmdev->sensor[i].id = i; + tzd =thermal_zone_of_sensor_register (tmdev->dev, i, + &tmdev->sensor[i], + &tsens_of_ops); +if (IS_ERR (tzd)) +continue ; + tmdev->sensor[i].tzd = tzd; +if (tmdev->ops->enable) + tmdev->ops->enable (tmdev, i); + } +return 0 ; +} + +static int tsens_probe (struct platform_device *pdev) +{ +int ret, i, num; +struct device *dev; +struct device_node *np;
Quoted 8 lines
drivers/thermal/qcom/tsens.c line 130
Quoted 6 lines
drivers/thermal/qcom/tsens.c new file +6
-0+struct tsens_sensor *s; +struct tsens_device *tmdev; +const struct of_device_id *id; + + dev = &pdev->dev; + np = dev->of_node;These assignments can be done with the declaration above.
I just have these assignments done conditionally in later patches (5/9), so left them here.
Thanks for taking time to review.
regards,
Rajendra
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
PATCH v2 2/9 thermal: qcom: tsens-8916: Add support for 8916 family of SoCs
In reply to Punit Agrawal[]..
Quoted 41 lines
Quoted 26 lines
drivers/thermal/qcom/tsens-common.c new file +26
-0+static inline int code_to_degc (u32 adc_code,const struct tsens_sensor *s) +{ +int degc, num, den; + + num = (adc_code *SLOPE_FACTOR ) - s->offset; + den = s->slope; + +if (num >0 ) + degc = num + (den /2 ); +else if (num <0 ) + degc = num - (den /2 ); +else + degc = num; + + degc /= den; + +return degc; +} + +int get_temp_common (struct tsens_device *tmdev,int id,int *temp) +{ +struct tsens_sensor *s = &tmdev->sensor[id]; +u32 code; +unsigned int sensor_addr; +int last_temp =0 , ret; +drivers/thermal/qcom/tsens-common.c line 109
Quoted 10 lines
drivers/thermal/qcom/tsens-common.c new file +10
-0+ sensor_addr =S0_ST_ADDR + s->hw_id *SN_ADDR_OFFSET ; + ret =regmap_read (tmdev->map, sensor_addr, &code); +if (ret) +return ret; + last_temp = code &SN_ST_TEMP_MASK ; + + *temp =code_to_degc (last_temp, s) *1000 ; + +return 0 ; +}The way this function is coded the temperature will only ever change by 1C (i.e., 1000mC). Is there a chance that you're losing precision in the
code_to_degcconversion that could be preserved perhaps?
Quoted 2 lines
This is useful in scenarios where you use the power allocator governor and the greater precision allows better power budget estimation.
I'll take a look to see if we can get better precision. Thanks.
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
PATCH v2 4/9 clk: qcom: create virtual child device for TSENS
In reply to Stephen BoydQuoted 16 lines · Stephen Boyd
Quoted 15 lines · Rajendra Nayak
drivers/clk/qcom/gcc-msm8960.c +10
-1@@ -3520,7 +3522,26 @@ static int gcc_msm8960_probe(struct platform_device *pdev)if (IS_ERR (clk))return PTR_ERR (clk); -return qcom_cc_probe (pdev, match->data); + ret =qcom_cc_probe (pdev, match->data); +if (ret) +return ret; + + tsens =platform_device_alloc ("qcom-tsens" ,-1 ); +if (!tsens) { + ret = -ENOMEM ; + goto err_alloc; + } +
Quoted 8 lines
drivers/clk/qcom/gcc-msm8960.c static int gcc_msm8960_probe(struct platform_device *pdev) · line 3538
Quoted 4 lines
drivers/clk/qcom/gcc-msm8960.c +4
-0+ tsens->dev.parent = &pdev->dev; + ret =platform_device_add (tsens); +if (ret) + goto err_add;
platform_device_register_data()instead of all these lines? We should probably remove the device when this driver is removed too.
Thanks Stephen, I'll fix it.
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
PATCH v2 2/9 thermal: qcom: tsens-8916: Add support for 8916 family of SoCs
In reply to Rajendra NayakQuoted 43 lines · Rajendra Nayak
[]..
Quoted 41 lines
Quoted 26 lines
drivers/thermal/qcom/tsens-common.c new file +26
-0+static inline int code_to_degc (u32 adc_code,const struct tsens_sensor *s) +{ +int degc, num, den; + + num = (adc_code *SLOPE_FACTOR ) - s->offset; + den = s->slope; + +if (num >0 ) + degc = num + (den /2 ); +else if (num <0 ) + degc = num - (den /2 ); +else + degc = num; + + degc /= den; + +return degc; +} + +int get_temp_common (struct tsens_device *tmdev,int id,int *temp) +{ +struct tsens_sensor *s = &tmdev->sensor[id]; +u32 code; +unsigned int sensor_addr; +int last_temp =0 , ret; +drivers/thermal/qcom/tsens-common.c line 109
Quoted 10 lines
drivers/thermal/qcom/tsens-common.c new file +10
-0+ sensor_addr =S0_ST_ADDR + s->hw_id *SN_ADDR_OFFSET ; + ret =regmap_read (tmdev->map, sensor_addr, &code); +if (ret) +return ret; + last_temp = code &SN_ST_TEMP_MASK ; + + *temp =code_to_degc (last_temp, s) *1000 ; + +return 0 ; +}The way this function is coded the temperature will only ever change by 1C (i.e., 1000mC). Is there a chance that you're losing precision in the
code_to_degcconversion that could be preserved perhaps?
Quoted 4 lines
Quoted 2 lines
This is useful in scenarios where you use the power allocator governor and the greater precision allows better power budget estimation.
I'll take a look to see if we can get better precision. Thanks.
I checked, and it does not look like these devices can support better precision than degC.
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
PATCH v2 2/9 thermal: qcom: tsens-8916: Add support for 8916 family of SoCs
Quoted 44 lines · Rajendra Nayak
Quoted 43 lines · Rajendra Nayak
[]..
Quoted 41 lines
Quoted 26 lines
drivers/thermal/qcom/tsens-common.c new file +26
-0+static inline int code_to_degc (u32 adc_code,const struct tsens_sensor *s) +{ +int degc, num, den; + + num = (adc_code *SLOPE_FACTOR ) - s->offset; + den = s->slope; + +if (num >0 ) + degc = num + (den /2 ); +else if (num <0 ) + degc = num - (den /2 ); +else + degc = num; + + degc /= den; + +return degc; +} + +int get_temp_common (struct tsens_device *tmdev,int id,int *temp) +{ +struct tsens_sensor *s = &tmdev->sensor[id]; +u32 code; +unsigned int sensor_addr; +int last_temp =0 , ret; +drivers/thermal/qcom/tsens-common.c line 109
Quoted 10 lines
drivers/thermal/qcom/tsens-common.c new file +10
-0+ sensor_addr =S0_ST_ADDR + s->hw_id *SN_ADDR_OFFSET ; + ret =regmap_read (tmdev->map, sensor_addr, &code); +if (ret) +return ret; + last_temp = code &SN_ST_TEMP_MASK ; + + *temp =code_to_degc (last_temp, s) *1000 ; + +return 0 ; +}The way this function is coded the temperature will only ever change by 1C (i.e., 1000mC). Is there a chance that you're losing precision in the
code_to_degcconversion that could be preserved perhaps?
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
This is useful in scenarios where you use the power allocator governor and the greater precision allows better power budget estimation.
I'll take a look to see if we can get better precision. Thanks.
I checked, and it does not look like these devices can support better precision than degC.
Ah well. Thanks for checking!