thermal: Add QPNP PMIC temperature alarm driver
Subsystems (3)
PATCH v2 1/1 thermal: Add QPNP PMIC temperature alarm driver
Add support for the temperature alarm peripheral found inside Qualcomm plug-and-play (QPNP) PMIC chips. The temperature alarm peripheral outputs a pulse on an interrupt line whenever the thermal over temperature stage value changes. Implement an ISR to manage this interrupt.
Register a thermal zone device in sysfs with multiple trip points corresponding to the physical threshold temperatures between over temperature stages. The temperature reported by this thermal zone device should reflect the actual PMIC die temperature if an ADC is present on the given PMIC. If no ADC is present, then the reported temperature should be estimated from the over temperature stage value.
Send a notification to userspace via sysfs_notify() whenever the over temperature stage value changes.
---
Changes:
- Rely on VADC driver to convert and report PMIC die temperature in mili Celsius
- Remove label property and use device node name for thermal zone name
- Fix Kconfig dependencies
.../bindings/thermal/qpnp-temp-alarm.txt | 25 + drivers/thermal/Kconfig | 13 + drivers/thermal/Makefile | 1 + drivers/thermal/qpnp-temp-alarm.c | 518 +++++++++++++++++++++ 4 files changed, 557 insertions(+) create mode 100644 Documentation/devicetree/bindings/thermal/qpnp-temp-alarm.txt create mode 100644 drivers/thermal/qpnp-temp-alarm.c
Documentation/devicetree/bindings/thermal/qpnp-temp-alarm.txt new file +25 -0
@@ -0,0 +1,25 @@ +Qualcomm QPNP PMIC Temperature Alarm + +QPNP temperature alarm peripherals are found inside of Qualcomm PMIC chips +that utilize the Qualcomm SPMI implementation. These peripherals provide an +interrupt signal and status register to identify high PMIC die temperature. + +Required properties: +- compatible: Should contain "qcom,spmi-temp-alarm". +- reg: Specifies the SPMI address of the temperature alarm device. +- interrupts: PMIC temperature alarm interrupt + +Optional properties: +- io-channels: Should contain IIO channel specifier for the ADC channel, + which report chip die temperature. +- io-channel-names: Should contain "thermal". + +Example: + + thermal-alarm@2400 { + compatible = "qcom,spmi-temp-alarm"; + reg = <0x2400>; + interrupts = <0 0x24 0 IRQ_TYPE_EDGE_RISING>; + io-channels = <&pm8941_vadc VADC_DIE_TEMP>; + io-channel-names = "thermal"; + };
drivers/thermal/Kconfig +13 -0
@@ -248,4 +248,17 @@ depends on ARCH_STI && OF source "drivers/thermal/st/Kconfig" endmenu +config QPNP_TEMP_ALARM + tristate "Qualcomm QPNP Temperature Alarm" + depends on OF && SPMI && IIO + select REGMAP_SPMI + help + This enables a thermal sysfs driver for Qualcomm plug-and-play (QPNP) + PMIC devices. It shows up in sysfs as a thermal zone with multiple + trip points. The temperature reported by the thermal zone reflects the + real time die temperature if an ADC is present or an estimate of the + temperature based upon the over temperature stage value. Enabling the + thermal zone device via the mode file results in shifting PMIC over + temperature shutdown control from hardware to software. + endif
drivers/thermal/Makefile +1 -0
@@ -33,3 +33,4 @@ obj-$(CONFIG_INTEL_SOC_DTS_THERMAL) += intel_soc_dts_thermal.o obj-$(CONFIG_TI_SOC_THERMAL) += ti-soc-thermal/ obj-$(CONFIG_ACPI_INT3403_THERMAL) += int3403_thermal.o obj-$(CONFIG_ST_THERMAL) += st/ +obj-$(CONFIG_QPNP_TEMP_ALARM) += qpnp-temp-alarm.o
drivers/thermal/qpnp-temp-alarm.c new file +518 -0
518 lines not on this page · raw message
Signature · 1 line
1.9.1
Quoted 6 lines · Ivan T. Ivanov
Add support for the temperature alarm peripheral found inside Qualcomm plug-and-play (QPNP) PMIC chips. The temperature alarm peripheral outputs a pulse on an interrupt line whenever the thermal over temperature stage value changes. Implement an ISR to manage this interrupt.
<snip>
Quoted 4 lines
+ * This function updates the internal temp value based on the
+ * current thermal stage and threshold as well as the previous stage
+ */drivers/thermal/qpnp-temp-alarm.c new file +1
-0+static int qpnp_tm_update_temp_no_adc (struct qpnp_tm_chip *chip)
drivers/thermal/qpnp-temp-alarm.c line 135
Quoted 10 lines
drivers/thermal/qpnp-temp-alarm.c new file +10
-0+{ +unsigned int stage; +int rc; +u8 reg; + + rc =qpnp_tm_read (chip,QPNP_TM_REG_STATUS , ®); +if (rc <0 ) +return rc; + + stage = reg &STATUS_STAGE_MASK ;
During compilation, getting a waring as below,
drivers/thermal/qpnp-temp-alarm.c: In function ‘qpnp_tm_update_temp_no_adc’:drivers/thermal/qpnp-temp-alarm.c:135:8: warning: ‘reg’ may be used uninitialized in this function [-Wmaybe-uninitialized]
stage = reg & STATUS_STAGE_MASK;
Quoted 18 lines
drivers/thermal/qpnp-temp-alarm.c new file +18
-0+ +if (stage > chip->stage) { +/* increasing stage, use lower bound */ + chip->temp = (stage -1 ) *TEMP_STAGE_STEP + + chip->thresh *TEMP_THRESH_STEP + +TEMP_STAGE_HYSTERESIS +TEMP_THRESH_MIN ; + }else if (stage < chip->stage) { +/* decreasing stage, use upper bound */ + chip->temp = stage *TEMP_STAGE_STEP + + chip->thresh *TEMP_THRESH_STEP - +TEMP_STAGE_HYSTERESIS +TEMP_THRESH_MIN ; + } + + chip->stage = stage; + +return 0 ; +} +
<snip>
drivers/thermal/qpnp-temp-alarm.c line 499
Quoted 7 lines
drivers/thermal/qpnp-temp-alarm.c new file +7
-0+ +#define QPNP_TM_PM_OPS (&qpnp_tm_pm_ops) +#else +#define QPNP_TM_PM_OPS NULL +#endif + +static struct of_device_id qpnp_tm_match_table[] = {
It must be static const struct of_device_id, because all OF functions handle it as const.
Thanks,
--Kiran
Quoted 20 lines
drivers/thermal/qpnp-temp-alarm.c new file +19
-0+ { .compatible = "qcom,spmi-temp-alarm" }, + { } +}; +MODULE_DEVICE_TABLE (of, qpnp_tm_match_table); + +static struct platform_driver qpnp_tm_driver = { + .driver = { + .name ="spmi-temp-alarm" , + .of_match_table = qpnp_tm_match_table, + .pm =QPNP_TM_PM_OPS , + }, + .probe = qpnp_tm_probe, + .remove = qpnp_tm_remove, +}; +module_platform_driver (qpnp_tm_driver); + +MODULE_ALIAS ("platform:spmi-temp-alarm" ); +MODULE_DESCRIPTION ("QPNP PMIC Temperature Alarm driver" ); +MODULE_LICENSE ("GPL v2" );
Quoted 27 lines · Kiran Padwal
Quoted 6 lines · Ivan T. Ivanov
Add support for the temperature alarm peripheral found inside Qualcomm plug-and-play (QPNP) PMIC chips. The temperature alarm peripheral outputs a pulse on an interrupt line whenever the thermal over temperature stage value changes. Implement an ISR to manage this interrupt.
<snip>
Quoted 4 lines
+ * This function updates the internal temp value based on the
+ * current thermal stage and threshold as well as the previous stage
+ */drivers/thermal/qpnp-temp-alarm.c new file +1
-0+static int qpnp_tm_update_temp_no_adc (struct qpnp_tm_chip *chip)drivers/thermal/qpnp-temp-alarm.c line 135
Quoted 10 lines
drivers/thermal/qpnp-temp-alarm.c new file +10
-0+{ +unsigned int stage; +int rc; +u8 reg; + + rc =qpnp_tm_read (chip,QPNP_TM_REG_STATUS , ®); +if (rc <0 ) +return rc; + + stage = reg &STATUS_STAGE_MASK ;During compilation, getting a waring as below,
Quoted 3 lines
drivers/thermal/qpnp-temp-alarm.c: In function ‘qpnp_tm_update_temp_no_adc’:drivers/thermal/qpnp-temp-alarm.c:135:8: warning: ‘reg’ may be used uninitialized in this function [-Wmaybe-uninitialized]
stage = reg &STATUS_STAGE_MASK;
Could you share compiler version and options which you are using. I am unable to trigger this warning. Looking code I can not see how this could happen.
Quoted 22 lines
Quoted 19 lines
drivers/thermal/qpnp-temp-alarm.c new file +18
-0+ +if (stage > chip->stage) { +/* increasing stage, use lower bound */ + chip->temp = (stage -1 ) *TEMP_STAGE_STEP + + chip->thresh *TEMP_THRESH_STEP + +TEMP_STAGE_HYSTERESIS +TEMP_THRESH_MIN ; + }else if (stage < chip->stage) { +/* decreasing stage, use upper bound */ + chip->temp = stage *TEMP_STAGE_STEP + + chip->thresh *TEMP_THRESH_STEP - +TEMP_STAGE_HYSTERESIS +TEMP_THRESH_MIN ; + } + + chip->stage = stage; + +return 0 ; +} +<snip>
Quoted 9 lines
drivers/thermal/qpnp-temp-alarm.c line 499
Quoted 7 lines
drivers/thermal/qpnp-temp-alarm.c new file +7
-0+ +#define QPNP_TM_PM_OPS (&qpnp_tm_pm_ops) +#else +#define QPNP_TM_PM_OPS NULL +#endif + +static struct of_device_id qpnp_tm_match_table[] = {It must be static const struct
of_device_id, because all OF functions handle it as const.
Sure, will fix it.
Thank you,
Ivan
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 28 lines · Ivan T. Ivanov
Quoted 27 lines · Kiran Padwal
Quoted 6 lines · Ivan T. Ivanov
Add support for the temperature alarm peripheral found inside Qualcomm plug-and-play (QPNP) PMIC chips. The temperature alarm peripheral outputs a pulse on an interrupt line whenever the thermal over temperature stage value changes. Implement an ISR to manage this interrupt.
<snip>
Quoted 4 lines
+ * This function updates the internal temp value based on the
+ * current thermal stage and threshold as well as the previous stage
+ */drivers/thermal/qpnp-temp-alarm.c new file +1
-0+static int qpnp_tm_update_temp_no_adc (struct qpnp_tm_chip *chip)drivers/thermal/qpnp-temp-alarm.c line 135
Quoted 10 lines
drivers/thermal/qpnp-temp-alarm.c new file +10
-0+{ +unsigned int stage; +int rc; +u8 reg; + + rc =qpnp_tm_read (chip,QPNP_TM_REG_STATUS , ®); +if (rc <0 ) +return rc; + + stage = reg &STATUS_STAGE_MASK ;During compilation, getting a waring as below,
Quoted 7 lines
Quoted 3 lines
drivers/thermal/qpnp-temp-alarm.c: In function ‘qpnp_tm_update_temp_no_adc’:drivers/thermal/qpnp-temp-alarm.c:135:8: warning: ‘reg’ may be used uninitialized in this function [-Wmaybe-uninitialized]
stage = reg &STATUS_STAGE_MASK;Could you share compiler version and options which you are using. I am unable to trigger this warning. Looking code I can not see how this could happen.
I have Linaro cross tool chain with version-4.8.3 and I am simply doing "make zImage" without any option.
Thanks,
--Kiran
Quoted 43 lines
Quoted 23 lines
Quoted 20 lines
drivers/thermal/qpnp-temp-alarm.c new file +18
-0+ +if (stage > chip->stage) { +/* increasing stage, use lower bound */ + chip->temp = (stage -1 ) *TEMP_STAGE_STEP + + chip->thresh *TEMP_THRESH_STEP + +TEMP_STAGE_HYSTERESIS +TEMP_THRESH_MIN ; + }else if (stage < chip->stage) { +/* decreasing stage, use upper bound */ + chip->temp = stage *TEMP_STAGE_STEP + + chip->thresh *TEMP_THRESH_STEP - +TEMP_STAGE_HYSTERESIS +TEMP_THRESH_MIN ; + } + + chip->stage = stage; + +return 0 ; +} +<snip>
Quoted 9 lines
drivers/thermal/qpnp-temp-alarm.c line 499
Quoted 7 lines
drivers/thermal/qpnp-temp-alarm.c new file +7
-0+ +#define QPNP_TM_PM_OPS (&qpnp_tm_pm_ops) +#else +#define QPNP_TM_PM_OPS NULL +#endif + +static struct of_device_id qpnp_tm_match_table[] = {It must be static const struct
of_device_id, because all OF functions handle it as const.Sure, will fix it.
Thank you,
Ivan--
To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 33 lines · Kiran Padwal
Quoted 32 lines · Ivan T. Ivanov
Quoted 30 lines · Kiran Padwal
Quoted 6 lines · Ivan T. Ivanov
Add support for the temperature alarm peripheral found inside Qualcomm plug-and-play (QPNP) PMIC chips. The temperature alarm peripheral outputs a pulse on an interrupt line whenever the thermal over temperature stage value changes. Implement an ISR to manage this interrupt.
<snip>
Quoted 4 lines
+ * This function updates the internal temp value based on the
+ * current thermal stage and threshold as well as the previous stage
+ */drivers/thermal/qpnp-temp-alarm.c new file +1
-0+static int qpnp_tm_update_temp_no_adc (struct qpnp_tm_chip *chip)drivers/thermal/qpnp-temp-alarm.c line 135
Quoted 10 lines
drivers/thermal/qpnp-temp-alarm.c new file +10
-0+{ +unsigned int stage; +int rc; +u8 reg; + + rc =qpnp_tm_read (chip,QPNP_TM_REG_STATUS , ®); +if (rc <0 ) +return rc; + + stage = reg &STATUS_STAGE_MASK ;During compilation, getting a waring as below,
drivers/thermal/qpnp-temp-alarm.c: In function ‘qpnp_tm_update_temp_no_adc’:drivers/thermal/qpnp-temp-alarm.c:135:8: warning: ‘reg’ may be used uninitialized in this function [-Wmaybe-uninitialized]
stage = reg &STATUS_STAGE_MASK;
Quoted 5 lines
Quoted 3 lines
Could you share compiler version and options which you are using. I am unable to trigger this warning. Looking code I can not see how this could happen.
I have Linaro cross tool chain with version-4.8.3 and I am simply doing "make zImage" without any option.
Hm, no warnings with arm-unknown-linux-gnueabi-gcc (GCC) 4.6.3 and arm-linux-gnueabihf-gcc (crosstool-NG linaro-1.13.1-4.9-2014.09, but indeed arm-linux-gnueabihf-gcc (crosstool-NG linaro-1.13.1-4.8-2014.03.
I will say that this is false positive :-). Please update your tool-chain.
Regards,
Ivan
Quoted 38 lines · Ivan T. Ivanov
Quoted 37 lines · Kiran Padwal
Quoted 35 lines · Ivan T. Ivanov
Quoted 27 lines · Kiran Padwal
Quoted 6 lines · Ivan T. Ivanov
Add support for the temperature alarm peripheral found inside Qualcomm plug-and-play (QPNP) PMIC chips. The temperature alarm peripheral outputs a pulse on an interrupt line whenever the thermal over temperature stage value changes. Implement an ISR to manage this interrupt.
<snip>
Quoted 4 lines
+ * This function updates the internal temp value based on the
+ * current thermal stage and threshold as well as the previous stage
+ */drivers/thermal/qpnp-temp-alarm.c new file +1
-0+static int qpnp_tm_update_temp_no_adc (struct qpnp_tm_chip *chip)drivers/thermal/qpnp-temp-alarm.c line 135
Quoted 10 lines
drivers/thermal/qpnp-temp-alarm.c new file +10
-0+{ +unsigned int stage; +int rc; +u8 reg; + + rc =qpnp_tm_read (chip,QPNP_TM_REG_STATUS , ®); +if (rc <0 ) +return rc; + + stage = reg &STATUS_STAGE_MASK ;During compilation, getting a waring as below,
Quoted 3 lines
drivers/thermal/qpnp-temp-alarm.c: In function ‘qpnp_tm_update_temp_no_adc’:drivers/thermal/qpnp-temp-alarm.c:135:8: warning: ‘reg’ may be used uninitialized in this function [-Wmaybe-uninitialized]
stage = reg &STATUS_STAGE_MASK;Could you share compiler version and options which you are using. I am unable to trigger this warning. Looking code I can not see how this could happen.
Quoted 8 lines
Quoted 1 line
I have Linaro cross tool chain with version-4.8.3 and I am simply doing "make zImage" without any option.
Hm, no warnings with arm-unknown-linux-gnueabi-gcc (GCC) 4.6.3 and arm-linux-gnueabihf-gcc (crosstool-NG linaro-1.13.1-4.9-2014.09, but indeed arm-linux-gnueabihf-gcc (crosstool-NG linaro-1.13.1-4.8-2014.03.
I will say that this is false positive :-). Please update your tool-chain.
Thanks to verify, I will do that.
Thanks,
--Kiran
Quoted 8 lines · Ivan T. Ivanov
Quoted 2 lines · Kiran Padwal
I have Linaro cross tool chain with version-4.8.3 and I am simply doing "make zImage" without any option.
Hm, no warnings with arm-unknown-linux-gnueabi-gcc (GCC) 4.6.3 and arm-linux-gnueabihf-gcc (crosstool-NG linaro-1.13.1-4.9-2014.09, but indeed arm-linux-gnueabihf-gcc (crosstool-NG linaro-1.13.1-4.8-2014.03.
I will say that this is false positive :-). Please update your tool-chain.
Hopefully you're joking. Once this merges someone will find the warning and complain. Telling them to upgrade their compiler isn't going to work.
I wonder if checking for rc != 0 instead of rc < 0 would silence the warning? Or get rid of the entire wrapper function and just use regmap functions directly.
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
Quoted 4 lines · Stephen Boyd
Quoted 3 lines · Ivan T. Ivanov
Quoted 2 lines · Kiran Padwal
I have Linaro cross tool chain with version-4.8.3 and I am simply doing "make zImage" without any option.
Quoted 8 lines
Quoted 5 lines
Hm, no warnings with arm-unknown-linux-gnueabi-gcc (GCC) 4.6.3 and arm-linux-gnueabihf-gcc (crosstool-NG linaro-1.13.1-4.9-2014.09, but indeed arm-linux-gnueabihf-gcc (crosstool-NG linaro-1.13.1-4.8-2014.03.
I will say that this is false positive :-). Please update your tool-chain.
Hopefully you're joking. Once this merges someone will find the warning and complain. Telling them to upgrade their compiler isn't going to work.
If it is known to be buggy why not?
Quoted 3 lines
I wonder if checking for rc != 0 instead of rc < 0 would silence the warning?
No. Anyway, will find some way to silence this warning.
Thanks,
Ivan