thermal: Add QPNP PMIC temperature alarm driver
Subsystems (3)
PATCH v4 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.
Register a thermal sensor. The temperature reported by this thermal sensor 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.
---
Changes since v3:
- Driver register thermal sensor instead thermal zone. Device thermal zone should be properly described in DT files according thermal.txt document.
- Dropped support for software override PMIC shutdown sequence and related bit definitions. If software did not take action for clean device shutdown, until critical temperature is reached, PMIC chip will execute internal pre-programed shutdown sequence.
v3: http://comments.gmane.org/gmane.linux.ports.arm.msm/10071
.../bindings/thermal/qcom-spmi-temp-alarm.txt | 57 ++++ drivers/thermal/Kconfig | 11 + drivers/thermal/Makefile | 1 + drivers/thermal/qcom-spmi-temp-alarm.c | 311 +++++++++++++++++++++ 4 files changed, 380 insertions(+) create mode 100644 Documentation/devicetree/bindings/thermal/qcom-spmi-temp-alarm.txt create mode 100644 drivers/thermal/qcom-spmi-temp-alarm.c
Documentation/devicetree/bindings/thermal/qcom-spmi-temp-alarm.txt new file +57 -0
@@ -0,0 +1,57 @@ +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 and length of the controller's + registers. +- interrupts: PMIC temperature alarm interrupt. +- #thermal-sensor-cells: Should be 0. See thermal.txt for a description. + +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: + + pm8941_temp: thermal-alarm@2400 { + compatible = "qcom,spmi-temp-alarm"; + reg = <0x2400 0x100>; + interrupts = <0 0x24 0 IRQ_TYPE_EDGE_RISING>; + #thermal-sensor-cells = <0>; + + io-channels = <&pm8941_vadc VADC_DIE_TEMP>; + io-channel-names = "thermal"; + }; + + thermal-zones { + pm8941 { + polling-delay-passive = <250>; + polling-delay = <1000>; + + thermal-sensors = <&pm8941_temp>; + + trips { + passive { + temperature = <1050000>; + hysteresis = <2000>; + type = "passive"; + }; + alert { + temperature = <125000>; + hysteresis = <2000>; + type = "hot"; + }; + crit { + temperature = <145000>; + hysteresis = <2000>; + type = "critical"; + }; + }; + }; + }; +
drivers/thermal/Kconfig +11 -0
@@ -299,4 +299,15 @@ depends on ARCH_STI && OF source "drivers/thermal/st/Kconfig" endmenu +config QCOM_SPMI_TEMP_ALARM + tristate "Qualcomm SPMI PMIC 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 sensor with multiple + trip points. The temperature reported by the thermal sensor reflects the + real time die temperature if an ADC is present or an estimate of the + temperature based upon the over temperature stage value. + endif
drivers/thermal/Makefile +1 -0
@@ -22,6 +22,7 @@ thermal_sys-$(CONFIG_CPU_THERMAL) += cpu_cooling.o thermal_sys-$(CONFIG_CLOCK_THERMAL) += clock_cooling.o # platform thermal drivers +obj-$(CONFIG_QCOM_SPMI_TEMP_ALARM) += qcom-spmi-temp-alarm.o obj-$(CONFIG_SPEAR_THERMAL) += spear_thermal.o obj-$(CONFIG_ROCKCHIP_THERMAL) += rockchip_thermal.o obj-$(CONFIG_RCAR_THERMAL) += rcar_thermal.o
drivers/thermal/qcom-spmi-temp-alarm.c new file +311 -0
311 lines not on this page · raw message
--
1.9.1
--
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 15 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.
Register a thermal sensor. The temperature reported by this thermal sensor 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.
Cc David Collins <[email protected]>Signed-off-by Ivan T. Ivanov <[email protected]>---
<snip>
Quoted 14 lines
drivers/thermal/qcom-spmi-temp-alarm.c new file +14
-0+ + ret =qpnp_tm_init (chip); +if (ret <0 ) { +dev_err (&pdev->dev,"init failed\n" ); + goto fail; + } + + chip->tz_dev =thermal_zone_of_sensor_register (&pdev->dev,0 , chip, + &qpnp_tm_sensor_ops); +if (IS_ERR (chip->tz_dev)) { +dev_err (&pdev->dev,"failed to register sensor\n" ); + ret =PTR_ERR (chip->tz_dev); + goto fail; + }
drivers/thermal/qcom-spmi-temp-alarm.c line 274
Quoted 10 lines
drivers/thermal/qcom-spmi-temp-alarm.c new file +10
-0+ + ret =devm_request_threaded_irq (&pdev->dev, irq,NULL , qpnp_tm_isr, +IRQF_ONESHOT , node->name, chip); +if (ret <0 ) + goto unreg; + +return 0 ; + +unreg: +thermal_zone_of_sensor_unregister (&pdev->dev, chip->tz_dev);
Any problem to request_irq before thermal_zone_of_sensor_register? It will avoid having thermal sensor unregister call.
Quoted 6 lines
drivers/thermal/qcom-spmi-temp-alarm.c new file +6
-0+fail: +if (!IS_ERR (chip->adc)) +iio_channel_release (chip->adc); + +return ret; +}
<snip>
Signature · 2 lines
regards, Stan
Quoted 14 lines · Stanimir Varbanov
Quoted 14 lines
drivers/thermal/qcom-spmi-temp-alarm.c new file +13
-0+ + chip->tz_dev =thermal_zone_of_sensor_register (&pdev->dev,0 , chip, + &qpnp_tm_sensor_ops); +if (IS_ERR (chip->tz_dev)) { +dev_err (&pdev->dev,"failed to register sensor\n" ); + ret =PTR_ERR (chip->tz_dev); + goto fail; + } + + ret =devm_request_threaded_irq (&pdev->dev, irq,NULL , qpnp_tm_isr, +IRQF_ONESHOT , node->name, chip); +if (ret <0 ) + goto unreg;
Quoted 8 lines
drivers/thermal/qcom-spmi-temp-alarm.c line 274
Quoted 5 lines
drivers/thermal/qcom-spmi-temp-alarm.c new file +5
-0+ +return 0 ; + +unreg: +thermal_zone_of_sensor_unregister (&pdev->dev, chip->tz_dev);Any problem to
request_irqbeforethermal_zone_of_sensor_register? It will avoid having thermal sensor unregister call.
Right, will reorder the calls.
Ivan
Quoted 11 lines
Quoted 7 lines
drivers/thermal/qcom-spmi-temp-alarm.c new file +6
-0+fail: +if (!IS_ERR (chip->adc)) +iio_channel_release (chip->adc); + +return ret; +}<snip>
Ivan,
Quoted 11 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.
Register a thermal sensor. The temperature reported by this thermal sensor 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.
Quoted 8 lines
Cc David Collins <[email protected]>Signed-off-by Ivan T. Ivanov <[email protected]>---
Changes since v3:
- Driver register thermal sensor instead thermal zone. Device thermal zone should be properly described in DT files according thermal.txt document.
Thanks a lot for keeping this up. I believe the driver looks smaller and cleaner now, don't you agree?
Quoted 5 lines
- Dropped support for software override PMIC shutdown sequence and related bit definitions. If software did not take action for clean device shutdown, until critical temperature is reached, PMIC chip will execute internal pre-programed shutdown sequence.
OK. Let me know if this functionality is crucial and needs further discussion.
I have two very minor comments as follows.
Quoted 62 lines
v3: http://comments.gmane.org/gmane.linux.ports.arm.msm/10071
.../bindings/thermal/qcom-spmi-temp-alarm.txt | 57 ++++ drivers/thermal/Kconfig | 11 + drivers/thermal/Makefile | 1 + drivers/thermal/qcom-spmi-temp-alarm.c | 311 +++++++++++++++++++++ 4 files changed, 380 insertions(+) create mode 100644 Documentation/devicetree/bindings/thermal/qcom-spmi-temp-alarm.txt create mode 100644 drivers/thermal/qcom-spmi-temp-alarm.cDocumentation/devicetree/bindings/thermal/qcom-spmi-temp-alarm.txt new file +46
-0@@ -0,0 +1,57 @@ +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 and length of the controller's + registers. +- interrupts: PMIC temperature alarm interrupt. +- #thermal-sensor-cells: Should be 0. See thermal.txt for a description. + +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: + + pm8941_temp: thermal-alarm@2400 { + compatible = "qcom,spmi-temp-alarm"; + reg = <0x2400 0x100>; + interrupts = <0 0x24 0 IRQ_TYPE_EDGE_RISING>; + #thermal-sensor-cells = <0>; + + io-channels = <&pm8941_vadc VADC_DIE_TEMP>; + io-channel-names = "thermal"; + }; + + thermal-zones { + pm8941 { + polling-delay-passive = <250>; + polling-delay = <1000>; + + thermal-sensors = <&pm8941_temp>; + + trips { + passive { + temperature = <1050000>; + hysteresis = <2000>; + type = "passive"; + }; + alert { + temperature = <125000>; + hysteresis = <2000>;
Documentation/devicetree/bindings/thermal/qcom-spmi-temp-alarm.txt line 56
Quoted 10 lines
Documentation/devicetree/bindings/thermal/qcom-spmi-temp-alarm.txt new file +10
-0+ type = "hot"; + }; + crit { + temperature = <145000>; + hysteresis = <2000>; + type = "critical"; + }; + }; + }; + };
Do you have the appropriate DT changes under architecture code too?
I mean, I am fine picking these changes, but should this series include also a minor inclusion under arch/arm/boot/dts too, given that you already did the hard part?
Quoted 142 lines
Documentation/devicetree/bindings/thermal/qcom-spmi-temp-alarm.txt new file +1
-0+drivers/thermal/Kconfig +11
-0@@ -299,4 +299,15 @@ depends on ARCH_STI && OF source "drivers/thermal/st/Kconfig" endmenu +config QCOM_SPMI_TEMP_ALARM + tristate "Qualcomm SPMI PMIC 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 sensor with multiple + trip points. The temperature reported by the thermal sensor reflects the + real time die temperature if an ADC is present or an estimate of the + temperature based upon the over temperature stage value. + endifdrivers/thermal/Makefile +1
-0@@ -22,6 +22,7 @@ thermal_sys-$(CONFIG_CPU_THERMAL) += cpu_cooling.o thermal_sys-$(CONFIG_CLOCK_THERMAL) += clock_cooling.o # platform thermal drivers +obj-$(CONFIG_QCOM_SPMI_TEMP_ALARM) += qcom-spmi-temp-alarm.o obj-$(CONFIG_SPEAR_THERMAL) += spear_thermal.o obj-$(CONFIG_ROCKCHIP_THERMAL) += rockchip_thermal.o obj-$(CONFIG_RCAR_THERMAL) += rcar_thermal.odrivers/thermal/qcom-spmi-temp-alarm.c new file +103
-0@@ -0,0 +1,311 @@ +/* +* Copyright (c) 2011-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/delay.h> +#include <linux/err.h> +#include <linux/iio/consumer.h> +#include <linux/interrupt.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/of_device.h> +#include <linux/platform_device.h> +#include <linux/regmap.h> +#include <linux/thermal.h> + +#define QPNP_TM_REG_TYPE 0x04 +#define QPNP_TM_REG_SUBTYPE 0x05 +#define QPNP_TM_REG_STATUS 0x08 +#define QPNP_TM_REG_SHUTDOWN_CTRL1 0x40 +#define QPNP_TM_REG_ALARM_CTRL 0x46 + +#define QPNP_TM_TYPE 0x09 +#define QPNP_TM_SUBTYPE 0x08 + +#define STATUS_STAGE_MASK 0x03 + +#define SHUTDOWN_CTRL1_THRESHOLD_MASK 0x03 + +#define ALARM_CTRL_FORCE_ENABLE 0x80 + +/* +* Trip point values based on threshold control +* 0 = {105 C, 125 C, 145 C} +* 1 = {110 C, 130 C, 150 C} +* 2 = {115 C, 135 C, 155 C} +* 3 = {120 C, 140 C, 160 C} +*/ +#define TEMP_STAGE_STEP 20000/* Stage step: 20.000 C */ +#define TEMP_STAGE_HYSTERESIS 2000 + +#define TEMP_THRESH_MIN 105000/* Threshold Min: 105 C */ +#define TEMP_THRESH_STEP 5000/* Threshold step: 5 C */ + +#define THRESH_MIN 0 + +/* Temperature in Milli Celsius reported during stage 0 if no ADC is present */ +#define DEFAULT_TEMP 37000 + +struct qpnp_tm_chip { +struct regmap *map; +struct thermal_zone_device *tz_dev; +long temp; +unsigned int thresh; +unsigned int stage; +unsigned int prev_stage; +unsigned int base; +struct iio_channel *adc; +}; + +static int qpnp_tm_read (struct qpnp_tm_chip *chip,u16 addr,u8 *data) +{ +unsigned int val; +int ret; + + ret =regmap_read (chip->map, chip->base + addr, &val); +if (ret <0 ) +return ret; + + *data = val; +return 0 ; +} + +static int qpnp_tm_write (struct qpnp_tm_chip *chip,u16 addr,u8 data) +{ +return regmap_write (chip->map, chip->base + addr, data); +} + +/* +* This function updates the internal temp value based on the +* current thermal stage and threshold as well as the previous stage +*/ +static int qpnp_tm_update_temp_no_adc (struct qpnp_tm_chip *chip) +{ +unsigned int stage; +int ret; +u8 reg =0 ; + + ret =qpnp_tm_read (chip,QPNP_TM_REG_STATUS , ®); +if (ret <0 ) +return ret; + + stage = reg &STATUS_STAGE_MASK ; + +if (stage > chip->stage) {
drivers/thermal/qcom-spmi-temp-alarm.c line 113
Quoted 10 lines
drivers/thermal/qcom-spmi-temp-alarm.c new file +10
-0+/* 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 ; + }
For my own edification, no change in state means no change in temperature too, right?
Quoted 144 lines
drivers/thermal/qcom-spmi-temp-alarm.c new file +144
-0+ + chip->stage = stage; + +return 0 ; +} + +static int qpnp_tm_get_temp (void *data,long *temp) +{ +struct qpnp_tm_chip *chip = data; +int ret, mili_celsius; + +if (!temp) +return -EINVAL ; + +if (IS_ERR (chip->adc)) { + ret =qpnp_tm_update_temp_no_adc (chip); +if (ret <0 ) +return ret; + }else { + ret =iio_read_channel_processed (chip->adc, &mili_celsius); +if (ret <0 ) +return ret; + + chip->temp = mili_celsius; + } + + *temp = chip->temp <0 ?0 : chip->temp; + +return 0 ; +} + +static const struct thermal_zone_of_device_ops qpnp_tm_sensor_ops = { + .get_temp = qpnp_tm_get_temp, +}; + +static irqreturn_t qpnp_tm_isr (int irq,void *data) +{ +struct qpnp_tm_chip *chip = data; + +thermal_zone_device_update (chip->tz_dev); + +return IRQ_HANDLED ; +} + +/* +* This function initializes the internal temp value based on only the +* current thermal stage and threshold. Setup threshold control and +* disable shutdown override. +*/ +static int qpnp_tm_init (struct qpnp_tm_chip *chip) +{ +int ret; +u8 reg; + + chip->thresh =THRESH_MIN ; + chip->temp =DEFAULT_TEMP ; + + ret =qpnp_tm_read (chip,QPNP_TM_REG_STATUS , ®); +if (ret <0 ) +return ret; + + chip->stage = reg &STATUS_STAGE_MASK ; + +if (chip->stage) + chip->temp = chip->thresh *TEMP_THRESH_STEP + + (chip->stage -1 ) *TEMP_STAGE_STEP + +TEMP_THRESH_MIN ; + +/* +* Set threshold and disable software override of stage 2 and 3 +* shutdowns. +*/ + reg = chip->thresh &SHUTDOWN_CTRL1_THRESHOLD_MASK ; + ret =qpnp_tm_write (chip,QPNP_TM_REG_SHUTDOWN_CTRL1 , reg); +if (ret <0 ) +return ret; + +/* Enable the thermal alarm PMIC module in always-on mode. */ + reg =ALARM_CTRL_FORCE_ENABLE ; + ret =qpnp_tm_write (chip,QPNP_TM_REG_ALARM_CTRL , reg); + +return ret; +} + +static int qpnp_tm_probe (struct platform_device *pdev) +{ +struct qpnp_tm_chip *chip; +struct device_node *node; +u8 type, subtype; +u32 res[2 ]; +int ret, irq; + + node = pdev->dev.of_node; + + chip =devm_kzalloc (&pdev->dev,sizeof (*chip),GFP_KERNEL ); +if (!chip) +return -ENOMEM ; + +dev_set_drvdata (&pdev->dev, chip); + + chip->map =dev_get_regmap (pdev->dev.parent,NULL ); +if (!chip->map) +return -ENXIO ; + + ret =of_property_read_u32_array (node,"reg" , res,2 ); +if (ret <0 ) +return ret; + +/* ADC based measurements are optional */ + chip->adc =iio_channel_get (&pdev->dev,"thermal" ); +if (PTR_ERR (chip->adc) == -EPROBE_DEFER ) +return PTR_ERR (chip->adc); + + irq =platform_get_irq (pdev,0 ); +if (irq <0 ) +return irq; + + chip->base = res[0 ]; + + ret =qpnp_tm_read (chip,QPNP_TM_REG_TYPE , &type); +if (ret <0 ) { +dev_err (&pdev->dev,"could not read type\n" ); + goto fail; + } + + ret =qpnp_tm_read (chip,QPNP_TM_REG_SUBTYPE , &subtype); +if (ret <0 ) { +dev_err (&pdev->dev,"could not read subtype\n" ); + goto fail; + } + +if (type !=QPNP_TM_TYPE || subtype !=QPNP_TM_SUBTYPE ) { +dev_err (&pdev->dev,"invalid type 0x%02x or subtype 0x%02x\n" , + type, subtype); + ret = -ENODEV ; + goto fail; + } + + ret =qpnp_tm_init (chip); +if (ret <0 ) { +dev_err (&pdev->dev,"init failed\n" ); + goto fail; + } +
drivers/thermal/qcom-spmi-temp-alarm.c line 267
Quoted 10 lines
drivers/thermal/qcom-spmi-temp-alarm.c new file +10
-0+ chip->tz_dev =thermal_zone_of_sensor_register (&pdev->dev,0 , chip, + &qpnp_tm_sensor_ops); +if (IS_ERR (chip->tz_dev)) { +dev_err (&pdev->dev,"failed to register sensor\n" ); + ret =PTR_ERR (chip->tz_dev); + goto fail; + } + + ret =devm_request_threaded_irq (&pdev->dev, irq,NULL , qpnp_tm_isr, +IRQF_ONESHOT , node->name, chip);
What if we request this IRQ before registering the of thermal zone sensor? I believe it makes more sense conceptually, as you mean, you register into upper layers once your driver is fully ready to do so.
Any objections changing the order?
drivers/thermal/qcom-spmi-temp-alarm.c line 274
Quoted 7 lines
drivers/thermal/qcom-spmi-temp-alarm.c new file +7
-0+if (ret <0 ) + goto unreg; + +return 0 ; + +unreg: +thermal_zone_of_sensor_unregister (&pdev->dev, chip->tz_dev);
As mentioned by Stanimir Varban, you may also remove the above, since the irq is devm.
Quoted 40 lines
drivers/thermal/qcom-spmi-temp-alarm.c new file +37
-1+fail: +if (!IS_ERR (chip->adc)) +iio_channel_release (chip->adc); + +return ret; +} + +static int qpnp_tm_remove (struct platform_device *pdev) +{ +struct qpnp_tm_chip *chip =dev_get_drvdata (&pdev->dev); + +thermal_zone_of_sensor_unregister (&pdev->dev, chip->tz_dev); +if (!IS_ERR (chip->adc)) +iio_channel_release (chip->adc); + +return 0 ; +} + +static const struct of_device_id qpnp_tm_match_table[] = { + { .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, + }, + .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" ); --1.9.1
Hi Eduardo,
Quoted 18 lines · Eduardo Valentin
Ivan,
Quoted 15 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.
Register a thermal sensor. The temperature reported by this thermal sensor 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.
Cc David Collins <[email protected]>Signed-off-by Ivan T. Ivanov <[email protected]>---
Quoted 7 lines
Quoted 4 lines
Changes since v3:
- Driver register thermal sensor instead thermal zone. Device thermal zone should be properly described in DT files according thermal.txt document.
Thanks a lot for keeping this up. I believe the driver looks smaller and cleaner now, don't you agree?
Yep.
Quoted 9 lines
Quoted 6 lines
- Dropped support for software override PMIC shutdown sequence and related bit definitions. If software did not take action for clean device shutdown, until critical temperature is reached, PMIC chip will execute internal pre-programed shutdown sequence.
OK. Let me know if this functionality is crucial and needs further discussion.
Unless I miss something, I think that this functionality is used only for the purpose of debugging.
Quoted 81 lines
I have two very minor comments as follows.
Quoted 63 lines
v3: http://comments.gmane.org/gmane.linux.ports.arm.msm/10071
.../bindings/thermal/qcom-spmi-temp-alarm.txt | 57 ++++ drivers/thermal/Kconfig | 11 + drivers/thermal/Makefile | 1 + drivers/thermal/qcom-spmi-temp-alarm.c | 311 +++++++++++++++++++++ 4 files changed, 380 insertions(+) create mode 100644 Documentation/devicetree/bindings/thermal/qcom-spmi-temp-alarm.txt create mode 100644 drivers/thermal/qcom-spmi-temp-alarm.cDocumentation/devicetree/bindings/thermal/qcom-spmi-temp-alarm.txt new file +46
-0@@ -0,0 +1,57 @@ +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 and length of the controller's + registers. +- interrupts: PMIC temperature alarm interrupt. +- #thermal-sensor-cells: Should be 0. See thermal.txt for a description. + +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: + + pm8941_temp: thermal-alarm@2400 { + compatible = "qcom,spmi-temp-alarm"; + reg = <0x2400 0x100>; + interrupts = <0 0x24 0 IRQ_TYPE_EDGE_RISING>; + #thermal-sensor-cells = <0>; + + io-channels = <&pm8941_vadc VADC_DIE_TEMP>; + io-channel-names = "thermal"; + }; + + thermal-zones { + pm8941 { + polling-delay-passive = <250>; + polling-delay = <1000>; + + thermal-sensors = <&pm8941_temp>; + + trips { + passive { + temperature = <1050000>; + hysteresis = <2000>; + type = "passive"; + }; + alert { + temperature = <125000>; + hysteresis = <2000>;Documentation/devicetree/bindings/thermal/qcom-spmi-temp-alarm.txt line 56
Quoted 10 lines
Documentation/devicetree/bindings/thermal/qcom-spmi-temp-alarm.txt new file +10
-0+ type = "hot"; + }; + crit { + temperature = <145000>; + hysteresis = <2000>; + type = "critical"; + }; + }; + }; + };Do you have the appropriate DT changes under architecture code too?
Quoted 3 lines
I mean, I am fine picking these changes, but should this series include also a minor inclusion under
arch/arm/boot/dtstoo, given that you already did the hard part?
We don't have any DT files for these PMIC's upstream. Probably is time to start adding them. I have waiting to have some drivers accepted before pushing such changes. But not we have 2 types of ADC, RTC, GPIO's, MPP's and hopefully Thermal :-). I would like this to be a separate effort.
Quoted 25 lines
Quoted 25 lines
Documentation/devicetree/bindings/thermal/qcom-spmi-temp-alarm.txt new file +21
-0+ * This function updates the internal temp value based on the + * current thermal stage and threshold as well as the previous stage + */ +static int qpnp_tm_update_temp_no_adc(struct qpnp_tm_chip *chip) +{ + unsigned int stage; + int ret; + u8 reg = 0; + + ret = qpnp_tm_read(chip, QPNP_TM_REG_STATUS, ®); + if (ret < 0) + return ret; + + stage = reg & STATUS_STAGE_MASK; + + 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;Documentation/devicetree/bindings/thermal/qcom-spmi-temp-alarm.txt new file +3
-0+ } else if (stage < chip->stage) { + /* decreasing stage, use upper bound */ + chip->temp = stage * TEMP_STAGE_STEP +
Quoted 8 lines
Quoted 5 lines
Documentation/devicetree/bindings/thermal/qcom-spmi-temp-alarm.txt new file +2
-1+ chip->thresh * TEMP_THRESH_STEP - + TEMP_STAGE_HYSTERESIS +
TEMP_THRESH_MIN;
+ }For my own edification, no change in state means no change in temperature too, right?
More or less, just no way to estimate exact temperature between stages.
Quoted 7 lines
Quoted 7 lines
Documentation/devicetree/bindings/thermal/qcom-spmi-temp-alarm.txt new file +6
-0+ + chip->stage = stage; + + return 0; +} +
<snip>
Quoted 75 lines
Quoted 60 lines
Documentation/devicetree/bindings/thermal/qcom-spmi-temp-alarm.txt new file +60
-0+static int qpnp_tm_probe(struct platform_device *pdev) +{ + struct qpnp_tm_chip *chip; + struct device_node *node; + u8 type, subtype; + u32 res[2]; + int ret, irq; + + node = pdev->dev.of_node; + + chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL); + if (!chip) + return -ENOMEM; + + dev_set_drvdata(&pdev->dev, chip); + + chip->map = dev_get_regmap(pdev->dev.parent, NULL); + if (!chip->map) + return -ENXIO; + + ret = of_property_read_u32_array(node, "reg", res, 2); + if (ret < 0) + return ret; + + /* ADC based measurements are optional */ + chip->adc = iio_channel_get(&pdev->dev, "thermal"); + if (PTR_ERR(chip->adc) == -EPROBE_DEFER) + return PTR_ERR(chip->adc); + + irq = platform_get_irq(pdev, 0); + if (irq < 0) + return irq; + + chip->base = res[0]; + + ret = qpnp_tm_read(chip, QPNP_TM_REG_TYPE, &type); + if (ret < 0) { + dev_err(&pdev->dev, "could not read type\n"); + goto fail; + } + + ret = qpnp_tm_read(chip, QPNP_TM_REG_SUBTYPE, &subtype); + if (ret < 0) { + dev_err(&pdev->dev, "could not read subtype\n"); + goto fail; + } + + if (type != QPNP_TM_TYPE || subtype != QPNP_TM_SUBTYPE) { + dev_err(&pdev->dev, "invalid type 0x%02x or subtype 0x%02x\n", + type, subtype); + ret = -ENODEV; + goto fail; + } + + ret = qpnp_tm_init(chip); + if (ret < 0) { + dev_err(&pdev->dev, "init failed\n"); + goto fail; + } +Documentation/devicetree/bindings/thermal/qcom-spmi-temp-alarm.txt
Quoted 10 lines
Documentation/devicetree/bindings/thermal/qcom-spmi-temp-alarm.txt new file +10
-0+ chip->tz_dev = thermal_zone_of_sensor_register(&pdev->dev, 0, chip, + &qpnp_tm_sensor_ops); + if (IS_ERR(chip->tz_dev)) { + dev_err(&pdev->dev, "failed to register sensor\n"); + ret = PTR_ERR(chip->tz_dev); + goto fail; + } + + ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, qpnp_tm_isr, + IRQF_ONESHOT, node->name, chip);What if we request this IRQ before registering the of thermal zone sensor? I believe it makes more sense conceptually, as you mean, you register into upper layers once your driver is fully ready to do so.
Quoted 1 line
Any objections changing the order?
Sure.
Quoted 11 lines
Documentation/devicetree/bindings/thermal/qcom-spmi-temp-alarm.txt
Quoted 8 lines
Documentation/devicetree/bindings/thermal/qcom-spmi-temp-alarm.txt new file +7
-0+ if (ret < 0) + goto unreg; + + return 0; + +unreg: + thermal_zone_of_sensor_unregister(&pdev->dev, chip->tz_dev);As mentioned by Stanimir Varban, you may also remove the above, since the irq is devm.
Sure. s/Varban/Varbanov/ ;-)
Thank you.
Ivan
Quoted 39 lines · Ivan T. Ivanov
Hi Eduardo,
Quoted 18 lines · Eduardo Valentin
Ivan,
Quoted 15 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.
Register a thermal sensor. The temperature reported by this thermal sensor 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.
Cc David Collins <[email protected]>Signed-off-by Ivan T. Ivanov <[email protected]>---
Quoted 7 lines
Quoted 4 lines
Changes since v3:
- Driver register thermal sensor instead thermal zone. Device thermal zone should be properly described in DT files according thermal.txt document.
Thanks a lot for keeping this up. I believe the driver looks smaller and cleaner now, don't you agree?
Yep.
Quoted 7 lines
Quoted 6 lines
- Dropped support for software override PMIC shutdown sequence and related bit definitions. If software did not take action for clean device shutdown, until critical temperature is reached, PMIC chip will execute internal pre-programed shutdown sequence.
Quoted 5 lines
Quoted 2 lines
OK. Let me know if this functionality is crucial and needs further discussion.
Unless I miss something, I think that this functionality is used only for the purpose of debugging.
OK Great!
Quoted 82 lines
Quoted 82 lines
I have two very minor comments as follows.
Quoted 63 lines
v3: http://comments.gmane.org/gmane.linux.ports.arm.msm/10071
.../bindings/thermal/qcom-spmi-temp-alarm.txt | 57 ++++ drivers/thermal/Kconfig | 11 + drivers/thermal/Makefile | 1 + drivers/thermal/qcom-spmi-temp-alarm.c | 311 +++++++++++++++++++++ 4 files changed, 380 insertions(+) create mode 100644 Documentation/devicetree/bindings/thermal/qcom-spmi-temp-alarm.txt create mode 100644 drivers/thermal/qcom-spmi-temp-alarm.cDocumentation/devicetree/bindings/thermal/qcom-spmi-temp-alarm.txt new file +46
-0@@ -0,0 +1,57 @@ +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 and length of the controller's + registers. +- interrupts: PMIC temperature alarm interrupt. +- #thermal-sensor-cells: Should be 0. See thermal.txt for a description. + +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: + + pm8941_temp: thermal-alarm@2400 { + compatible = "qcom,spmi-temp-alarm"; + reg = <0x2400 0x100>; + interrupts = <0 0x24 0 IRQ_TYPE_EDGE_RISING>; + #thermal-sensor-cells = <0>; + + io-channels = <&pm8941_vadc VADC_DIE_TEMP>; + io-channel-names = "thermal"; + }; + + thermal-zones { + pm8941 { + polling-delay-passive = <250>; + polling-delay = <1000>; + + thermal-sensors = <&pm8941_temp>; + + trips { + passive { + temperature = <1050000>; + hysteresis = <2000>; + type = "passive"; + }; + alert { + temperature = <125000>; + hysteresis = <2000>;Documentation/devicetree/bindings/thermal/qcom-spmi-temp-alarm.txt line 56
Quoted 10 lines
Documentation/devicetree/bindings/thermal/qcom-spmi-temp-alarm.txt new file +10
-0+ type = "hot"; + }; + crit { + temperature = <145000>; + hysteresis = <2000>; + type = "critical"; + }; + }; + }; + };Do you have the appropriate DT changes under architecture code too?
Quoted 8 lines
Quoted 3 lines
I mean, I am fine picking these changes, but should this series include also a minor inclusion under
arch/arm/boot/dtstoo, given that you already did the hard part?We don't have any DT files for these PMIC's upstream. Probably is time to start adding them. I have waiting to have some drivers accepted before pushing such changes. But not we have 2 types of ADC, RTC, GPIO's, MPP's and hopefully Thermal :-). I would like this to be a separate effort.
I am fine if you take the approach of doing it in two steps. It is just that your series can be better reviewed if you include the DT changes.
Quoted 36 lines
Quoted 27 lines
Quoted 27 lines
Documentation/devicetree/bindings/thermal/qcom-spmi-temp-alarm.txt new file +21
-0+ * This function updates the internal temp value based on the + * current thermal stage and threshold as well as the previous stage + */ +static int qpnp_tm_update_temp_no_adc(struct qpnp_tm_chip *chip) +{ + unsigned int stage; + int ret; + u8 reg = 0; + + ret = qpnp_tm_read(chip, QPNP_TM_REG_STATUS, ®); + if (ret < 0) + return ret; + + stage = reg & STATUS_STAGE_MASK; + + 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;Documentation/devicetree/bindings/thermal/qcom-spmi-temp-alarm.txt new file +3
-0+ } else if (stage < chip->stage) { + /* decreasing stage, use upper bound */ + chip->temp = stage * TEMP_STAGE_STEP +Quoted 8 lines
Quoted 5 lines
Documentation/devicetree/bindings/thermal/qcom-spmi-temp-alarm.txt new file +2
-1+ chip->thresh * TEMP_THRESH_STEP - + TEMP_STAGE_HYSTERESIS +
TEMP_THRESH_MIN;
+ }For my own edification, no change in state means no change in temperature too, right?
Quoted 2 lines
More or less, just no way to estimate exact temperature between stages.
OK.
Quoted 86 lines
Quoted 8 lines
Quoted 8 lines
Documentation/devicetree/bindings/thermal/qcom-spmi-temp-alarm.txt new file +6
-0+ + chip->stage = stage; + + return 0; +} +<snip>
Quoted 75 lines
Quoted 60 lines
Documentation/devicetree/bindings/thermal/qcom-spmi-temp-alarm.txt new file +60
-0+static int qpnp_tm_probe(struct platform_device *pdev) +{ + struct qpnp_tm_chip *chip; + struct device_node *node; + u8 type, subtype; + u32 res[2]; + int ret, irq; + + node = pdev->dev.of_node; + + chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL); + if (!chip) + return -ENOMEM; + + dev_set_drvdata(&pdev->dev, chip); + + chip->map = dev_get_regmap(pdev->dev.parent, NULL); + if (!chip->map) + return -ENXIO; + + ret = of_property_read_u32_array(node, "reg", res, 2); + if (ret < 0) + return ret; + + /* ADC based measurements are optional */ + chip->adc = iio_channel_get(&pdev->dev, "thermal"); + if (PTR_ERR(chip->adc) == -EPROBE_DEFER) + return PTR_ERR(chip->adc); + + irq = platform_get_irq(pdev, 0); + if (irq < 0) + return irq; + + chip->base = res[0]; + + ret = qpnp_tm_read(chip, QPNP_TM_REG_TYPE, &type); + if (ret < 0) { + dev_err(&pdev->dev, "could not read type\n"); + goto fail; + } + + ret = qpnp_tm_read(chip, QPNP_TM_REG_SUBTYPE, &subtype); + if (ret < 0) { + dev_err(&pdev->dev, "could not read subtype\n"); + goto fail; + } + + if (type != QPNP_TM_TYPE || subtype != QPNP_TM_SUBTYPE) { + dev_err(&pdev->dev, "invalid type 0x%02x or subtype 0x%02x\n", + type, subtype); + ret = -ENODEV; + goto fail; + } + + ret = qpnp_tm_init(chip); + if (ret < 0) { + dev_err(&pdev->dev, "init failed\n"); + goto fail; + } +Documentation/devicetree/bindings/thermal/qcom-spmi-temp-alarm.txt
Quoted 10 lines
Documentation/devicetree/bindings/thermal/qcom-spmi-temp-alarm.txt new file +10
-0+ chip->tz_dev = thermal_zone_of_sensor_register(&pdev->dev, 0, chip, + &qpnp_tm_sensor_ops); + if (IS_ERR(chip->tz_dev)) { + dev_err(&pdev->dev, "failed to register sensor\n"); + ret = PTR_ERR(chip->tz_dev); + goto fail; + } + + ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, qpnp_tm_isr, + IRQF_ONESHOT, node->name, chip);What if we request this IRQ before registering the of thermal zone sensor? I believe it makes more sense conceptually, as you mean, you register into upper layers once your driver is fully ready to do so.
Quoted 3 lines
Quoted 1 line
Any objections changing the order?
Sure.
Good!
Quoted 13 lines
Quoted 12 lines
Documentation/devicetree/bindings/thermal/qcom-spmi-temp-alarm.txt
Quoted 9 lines
Documentation/devicetree/bindings/thermal/qcom-spmi-temp-alarm.txt new file +7
-0+ if (ret < 0) + goto unreg; + + return 0; + +unreg: + thermal_zone_of_sensor_unregister(&pdev->dev, chip->tz_dev);As mentioned by Stanimir Varban, you may also remove the above, since the irq is devm.
Quoted 1 line
Sure. s/Varban/Varbanov/ ;-)
Ohh.. my bad. Sorry Varbanov. Fixing next time! :-)
Quoted 3 lines
Thank you.
Ivan
BR,
Eduardo Valentin