thermal: Add QPNP PMIC temperature alarm driver
Subsystems (3)
PATCH v3 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 since v2:
- Fixed review comments from Kiran Padwal
- Files renamed from qpnp-* to qcom-spmi-* to be inline with other PMIC sub-function drivers like qcom-spmi-iadc and qcom-spmi-vadc.
v2: http://www.gossamer-threads.com/lists/linux/kernel/2017366
.../bindings/thermal/qcom-spmi-temp-alarm.txt | 26 ++ drivers/thermal/Kconfig | 13 + drivers/thermal/Makefile | 1 + drivers/thermal/qcom-spmi-temp-alarm.c | 517 +++++++++++++++++++++ 4 files changed, 557 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 +26 -0
@@ -0,0 +1,26 @@ +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 + +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 0x100>; + 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 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 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_QCOM_SPMI_TEMP_ALARM) += qcom-spmi-temp-alarm.o
drivers/thermal/qcom-spmi-temp-alarm.c new file +517 -0
517 lines not on this page · raw message
Signature · 1 line
1.9.1
No responses. Probably because maintainers are
in CC: and not in To:, fixing this.
Ivan
Quoted 664 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.
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.Cc David Collins <[email protected]>Signed-off-by Ivan T. Ivanov <[email protected]>---
Changes since v2:
- Fixed review comments from Kiran Padwal
- Files renamed from qpnp-* to qcom-spmi-* to be inline with other PMIC sub-function drivers like qcom-spmi-iadc and qcom-spmi-vadc.v2: http://www.gossamer-threads.com/lists/linux/kernel/2017366
.../bindings/thermal/qcom-spmi-temp-alarm.txt | 26 ++ drivers/thermal/Kconfig | 13 + drivers/thermal/Makefile | 1 + drivers/thermal/qcom-spmi-temp-alarm.c | 517 +++++++++++++++++++++ 4 files changed, 557 insertions(+) create mode 100644 Documentation/devicetree/bindings/thermal/qcom-spmi-temp-alarm.txt create mode 100644 drivers/thermal/qcom-spmi-temp-alarm.c(quoted diff) +0
-0
a/Documentation/devicetree/bindings/thermal/qcom-spmi-temp-alarm.txtb/Documentation/devicetree/bindings/thermal/qcom-spmi-temp-alarm.txtnew file mode 100644
index 0000000..afa908c
---/dev/null
+++b/Documentation/devicetree/bindings/thermal/qcom-spmi-temp-alarm.txtDocumentation/devicetree/bindings/thermal/qcom-spmi-temp-alarm.txt new file +3
-0@@ -0,0 +1,26 @@ +Qualcomm QPNP PMIC Temperature Alarm + +QPNP temperature alarm peripherals are found inside of QualcommPMIC chips
+that utilize the Qualcomm SPMI implementation. These peripherals provide an
+interrupt signal and status register to identify high PMIC die temperature.Documentation/devicetree/bindings/thermal/qcom-spmi-temp-alarm.txt new file +4
-0+ +Required properties: +- compatible: Should contain "qcom,spmi-temp-alarm". +- reg: Specifies the SPMI address and length of thecontroller's
Documentation/devicetree/bindings/thermal/qcom-spmi-temp-alarm.txt new file +5
-0+ registers. +- interrupts: PMIC temperature alarm interrupt + +Optional properties: +- io-channels: Should contain IIO channel specifier for the ADCchannel,
Documentation/devicetree/bindings/thermal/qcom-spmi-temp-alarm.txt new file +12
-0+ which report chip die temperature. +- io-channel-names: Should contain "thermal". + +Example: + + thermal-alarm@2400 { + compatible = "qcom,spmi-temp-alarm"; + reg = <0x2400 0x100>; + interrupts = <0 0x24 0 IRQ_TYPE_EDGE_RISING>; + io-channels = <&pm8941_vadc VADC_DIE_TEMP>; + io-channel-names = "thermal"; + };drivers/thermal/Kconfig +7
-0@@ -248,4 +248,17 @@ 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 zone withmultiple
+ 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 overdrivers/thermal/Kconfig +2
-0+ temperature shutdown control from hardware to software. + endifdrivers/thermal/Makefile +0
-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/drivers/thermal/Makefile +1
-0+obj-$(CONFIG_QCOM_SPMI_TEMP_ALARM) += qcom-spmi-temp-alarm.odrivers/thermal/qcom-spmi-temp-alarm.c new file +2
-0@@ -0,0 +1,517 @@ +/* +* Copyright (c) 2011-2014, 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.
+ */drivers/thermal/qcom-spmi-temp-alarm.c new file +57
-0+ +#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_SHUTDOWN_CTRL2 0x42 +#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_OVERRIDE_STAGE3 0x80 +#define SHUTDOWN_CTRL1_OVERRIDE_STAGE2 0x40 +#define SHUTDOWN_CTRL1_THRESHOLD_MASK 0x03 + +#define SHUTDOWN_CTRL2_CLEAR_STAGE3 0x80 +#define SHUTDOWN_CTRL2_CLEAR_STAGE2 0x40 + +#define ALARM_CTRL_FORCE_ENABLE 0x80 +#define ALARM_CTRL_FOLLOW_HW_ENABLE 0x01 + +/* +* 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 +#define THRESH_MAX 3 + +/* Trip points from most critical to least critical */ +#define TRIP_STAGE3 0 +#define TRIP_STAGE2 1 +#define TRIP_STAGE1 2 +#define TRIP_NUM 3 + +/* Delay between TEMP_STAT IRQ going high and status value changing in ms */
drivers/thermal/qcom-spmi-temp-alarm.c new file +3
-0+#define READ_DELAY_MS 40 + +/* Temperature in Milli Celsius reported during stage 0 if no ADC is present */
drivers/thermal/qcom-spmi-temp-alarm.c new file +17
-0+#define DEFAULT_TEMP 37000 + +struct qpnp_tm_chip { +struct delayed_workwork ; +struct regmap *map; +struct device *dev; +struct thermal_zone_device *tz_dev; +enum thermal_device_modemode ; +long temp; +unsigned intthresh; +unsigned intstage; +unsigned intprev_stage; +unsigned intbase; +struct iio_channel *adc; +}; + +static int qpnp_tm_read(struct qpnp_tm_chip *chip, u16 addr, u8*data)
drivers/thermal/qcom-spmi-temp-alarm.c new file +13
-0+{ +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, u8data)
drivers/thermal/qcom-spmi-temp-alarm.c new file +5
-0+{ +return regmap_write (chip->map, chip->base + addr, data); +} + +static int qpnp_tm_shutdown_override(struct qpnp_tm_chip *chip,bool enable)
drivers/thermal/qcom-spmi-temp-alarm.c new file +105
-0+{ +u8 reg; + + reg = chip->thresh &SHUTDOWN_CTRL1_THRESHOLD_MASK ; + +if (enable) { + reg |=SHUTDOWN_CTRL1_OVERRIDE_STAGE2 ; + reg |=SHUTDOWN_CTRL1_OVERRIDE_STAGE3 ; + } + +return qpnp_tm_write (chip,QPNP_TM_REG_SHUTDOWN_CTRL1 , reg); +} + +/* +* 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 ; + }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 ; +} + +static int qpnp_tz_get_temp (struct thermal_zone_device *thermal, +unsigned long *temp) +{ +struct qpnp_tm_chip *chip = thermal->devdata; +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 int qpnp_tz_get_mode (struct thermal_zone_device *thermal, +enum thermal_device_mode *mode) +{ +struct qpnp_tm_chip *chip = thermal->devdata; + +if (!mode) +return -EINVAL ; + + *mode = chip->mode; + +return 0 ; +} + +static int qpnp_tz_set_mode (struct thermal_zone_device *thermal, +enum thermal_device_mode mode) +{ +struct qpnp_tm_chip *chip = thermal->devdata; +int ret; + +if (mode == chip->mode) +return 0 ; + +if (mode ==THERMAL_DEVICE_ENABLED ) + ret =qpnp_tm_shutdown_override (chip, true); +else + ret =qpnp_tm_shutdown_override (chip, false); + + chip->mode = mode; + +return ret; +} + +static int qpnp_tz_get_trip_type(struct thermal_zone_device*thermal, int trip,
drivers/thermal/qcom-spmi-temp-alarm.c new file +23
-0+ enum thermal_trip_type *type) +{ +if (trip <0 || !type) +return -EINVAL ; + +switch (trip) { +case TRIP_STAGE3 : + *type =THERMAL_TRIP_CRITICAL ; +break ; +case TRIP_STAGE2 : + *type =THERMAL_TRIP_HOT ; +break ; +case TRIP_STAGE1 : + *type =THERMAL_TRIP_HOT ; +break ; +default : +return -EINVAL ; + } + +return 0 ; +} + +static int qpnp_tz_get_trip_temp(struct thermal_zone_device*thermal, int trip,
drivers/thermal/qcom-spmi-temp-alarm.c new file +9
-0+ unsigned long *temp) +{ +struct qpnp_tm_chip *chip = thermal->devdata; +int thresh_temp; + +if (trip <0 || !temp) +return -EINVAL ; + + thresh_temp = chip->thresh * TEMP_THRESH_STEP +
TEMP_THRESH_MIN;drivers/thermal/qcom-spmi-temp-alarm.c new file +20
-0+ +switch (trip) { +case TRIP_STAGE3 : + thresh_temp +=2 *TEMP_STAGE_STEP ; +break ; +case TRIP_STAGE2 : + thresh_temp +=TEMP_STAGE_STEP ; +break ; +case TRIP_STAGE1 : +break ; +default : +return -EINVAL ; + } + + *temp = thresh_temp; + +return 0 ; +} + +static int qpnp_tz_get_crit_temp(struct thermal_zone_device*thermal,
drivers/thermal/qcom-spmi-temp-alarm.c new file +18
-0+ unsigned long *temp) +{ +struct qpnp_tm_chip *chip = thermal->devdata; + +if (!temp) +return -EINVAL ; + + *temp = chip->thresh *TEMP_THRESH_STEP +TEMP_THRESH_MIN + +2 *TEMP_STAGE_STEP ; + +return 0 ; +} + +static irqreturn_t qpnp_tm_isr (int irq,void *data) +{ +struct qpnp_tm_chip *chip = data; + + schedule_delayed_work(&chip->work,
msecs_to_jiffies(READ_DELAY_MS)+ 1);drivers/thermal/qcom-spmi-temp-alarm.c new file +36
-0+ +return IRQ_HANDLED ; +} + +static void qpnp_tm_work (struct work_struct *work) +{ +struct delayed_work *dwork; +struct qpnp_tm_chip *chip; +int ret, mili_celsius; +u8 reg; + + dwork = container_of(work, struct delayed_work, work); + chip = container_of(dwork, struct qpnp_tm_chip, work); + +if (IS_ERR (chip->adc)) { + ret =qpnp_tm_update_temp_no_adc (chip); +if (ret <0 ) +return ; + }else { + ret =qpnp_tm_read (chip,QPNP_TM_REG_STATUS , ®); +if (ret <0 ) +return ; + + chip->stage = reg &STATUS_STAGE_MASK ; + + ret =iio_read_channel_processed (chip->adc, &mili_celsius); +if (ret <0 ) +return ; + + chip->temp = mili_celsius; + } + +if (chip->stage != chip->prev_stage) { + chip->prev_stage = chip->stage; + + dev_warn(chip->dev, "Thermal alarm stage %u, threshold %u,temp %ld mC\n",
drivers/thermal/qcom-spmi-temp-alarm.c new file +11
-0+ chip->stage, chip->thresh, chip->temp); + +thermal_zone_device_update (chip->tz_dev); + +/* Notify user space */ +sysfs_notify (&chip->tz_dev->device.kobj,NULL ,"type" ); + } +} + +/* +* This function initializes the internal temp value based on only the
+ * current thermal stage and threshold. Setup threshold control and
+ * disable shutdown override.
+ */drivers/thermal/qcom-spmi-temp-alarm.c new file +21
-0+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
drivers/thermal/qcom-spmi-temp-alarm.c new file +65
-0+* 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 struct thermal_zone_device_ops qpnp_tz_ops = { + .get_temp= qpnp_tz_get_temp, + .get_mode= qpnp_tz_get_mode, + .set_mode= qpnp_tz_set_mode, + .get_trip_type= qpnp_tz_get_trip_type, + .get_trip_temp= qpnp_tz_get_trip_temp, + .get_crit_temp= qpnp_tz_get_crit_temp, +}; + +static int qpnp_tm_probe (struct platform_device *pdev) +{ +struct qpnp_tm_chip *chip; +struct device_node *node; +u8 type, subtype; +int ret, irq, res[2 ]; + + 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->dev = &pdev->dev; +INIT_DELAYED_WORK (&chip->work, qpnp_tm_work); + + chip->map =dev_get_regmap (chip->dev->parent,NULL ); +if (!chip->map) +return -ENXIO ; + + ret =of_property_read_u32_array (node,"reg" , res,2 ); +if (ret <0 ) +return ret; + + 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" ); +return ret; + } + + ret =qpnp_tm_read (chip,QPNP_TM_REG_SUBTYPE , &subtype); +if (ret <0 ) { +dev_err (&pdev->dev,"could not read subtype\n" ); +return ret; + } + +if (type !=QPNP_TM_TYPE || subtype !=QPNP_TM_SUBTYPE ) { + dev_err(&pdev->dev, "invalid type 0x%02x or subtype0x%02x\n",
drivers/thermal/qcom-spmi-temp-alarm.c new file +19
-0+ type, subtype); +return -ENODEV ; + } + + irq =platform_get_irq (pdev,0 ); +if (irq <0 ) +return irq; + + chip->adc =iio_channel_get (chip->dev,"thermal" ); +if (PTR_ERR (chip->adc) == -EPROBE_DEFER ) +return PTR_ERR (chip->adc); + + ret =qpnp_tm_init (chip); +if (ret <0 ) { +dev_err (&pdev->dev,"init failed\n" ); +return ret; + } + +/* Start in HW control. Switch to SW control when user changes mode. */
drivers/thermal/qcom-spmi-temp-alarm.c new file +3
-0+ chip->mode =THERMAL_DEVICE_DISABLED ; + + chip->tz_dev = thermal_zone_device_register(node->name,
TRIP_NUM, 0,drivers/thermal/qcom-spmi-temp-alarm.c new file +8
-0+ chip, &qpnp_tz_ops,NULL , + 0, 0); +if (IS_ERR (chip->tz_dev)) { +dev_err (&pdev->dev,"TZ registration failed\n" ); +return PTR_ERR (chip->tz_dev); + } + + ret = devm_request_irq(chip->dev, irq, qpnp_tm_isr, 0,
node->name,drivers/thermal/qcom-spmi-temp-alarm.c new file +24
-0+ chip); +if (ret <0 ) +thermal_zone_device_unregister (chip->tz_dev); + +return ret; +} + +static int qpnp_tm_remove (struct platform_device *pdev) +{ +struct qpnp_tm_chip *chip =dev_get_drvdata (&pdev->dev); + +cancel_delayed_work_sync (&chip->work); +thermal_zone_device_unregister (chip->tz_dev); +qpnp_tm_shutdown_override (chip, false); + +return 0 ; +} + +#ifdef CONFIG_PM_SLEEP +static int qpnp_tm_suspend (struct device *dev) +{ +struct qpnp_tm_chip *chip =dev_get_drvdata (dev); + +/* Clear override bits in suspend to allow hardware control */
drivers/thermal/qcom-spmi-temp-alarm.c new file +45
-0+qpnp_tm_shutdown_override (chip, false); + +return 0 ; +} + +static int qpnp_tm_resume (struct device *dev) +{ +struct qpnp_tm_chip *chip =dev_get_drvdata (dev); + +/* Override hardware actions so software can control */ +if (chip->mode ==THERMAL_DEVICE_ENABLED ) +qpnp_tm_shutdown_override (chip, true); + +return 0 ; +} + +static const struct dev_pm_ops qpnp_tm_pm_ops = { +SET_SYSTEM_SLEEP_PM_OPS (qpnp_tm_suspend, qpnp_tm_resume) +}; + +#define QPNP_TM_PM_OPS (&qpnp_tm_pm_ops) +#else +#define QPNP_TM_PM_OPS NULL +#endif + +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, + .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" );
ping?
Quoted 670 lines · Ivan T. Ivanov
No responses. Probably because maintainers are
in CC: and not in To:, fixing this.Ivan
Quoted 663 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.
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.Cc David Collins <[email protected]>Signed-off-by Ivan T. Ivanov <[email protected]>---
Changes since v2:
- Fixed review comments from Kiran Padwal
- Files renamed from qpnp-* to qcom-spmi-* to be inline with other PMIC sub-function drivers like qcom-spmi-iadc and qcom-spmi-vadc.v2: http://www.gossamer-threads.com/lists/linux/kernel/2017366
.../bindings/thermal/qcom-spmi-temp-alarm.txt | 26 ++ drivers/thermal/Kconfig | 13 + drivers/thermal/Makefile | 1 + drivers/thermal/qcom-spmi-temp-alarm.c | 517 +++++++++++++++++++++ 4 files changed, 557 insertions(+) create mode 100644 Documentation/devicetree/bindings/thermal/qcom-spmi-temp-alarm.txt create mode 100644 drivers/thermal/qcom-spmi-temp-alarm.cdiff --git
a/Documentation/devicetree/bindings/thermal/qcom-spmi-temp-alarm.txtb/Documentation/devicetree/bindings/thermal/qcom-spmi-temp-alarm.txtnew file mode 100644
index 0000000..afa908c
---/dev/null
+++b/Documentation/devicetree/bindings/thermal/qcom-spmi-temp-alarm.txtDocumentation/devicetree/bindings/thermal/qcom-spmi-temp-alarm.txt new file +3
-0@@ -0,0 +1,26 @@ +Qualcomm QPNP PMIC Temperature Alarm + +QPNP temperature alarm peripherals are found inside of QualcommPMIC chips
+that utilize the Qualcomm SPMI implementation. These peripherals provide an
+interrupt signal and status register to identify high PMIC die temperature.Documentation/devicetree/bindings/thermal/qcom-spmi-temp-alarm.txt new file +4
-0+ +Required properties: +- compatible: Should contain "qcom,spmi-temp-alarm". +- reg: Specifies the SPMI address and length of thecontroller's
Documentation/devicetree/bindings/thermal/qcom-spmi-temp-alarm.txt new file +5
-0+ registers. +- interrupts: PMIC temperature alarm interrupt + +Optional properties: +- io-channels: Should contain IIO channel specifier for the ADCchannel,
Documentation/devicetree/bindings/thermal/qcom-spmi-temp-alarm.txt new file +12
-0+ which report chip die temperature. +- io-channel-names: Should contain "thermal". + +Example: + + thermal-alarm@2400 { + compatible = "qcom,spmi-temp-alarm"; + reg = <0x2400 0x100>; + interrupts = <0 0x24 0 IRQ_TYPE_EDGE_RISING>; + io-channels = <&pm8941_vadc VADC_DIE_TEMP>; + io-channel-names = "thermal"; + };drivers/thermal/Kconfig +7
-0@@ -248,4 +248,17 @@ 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 zone withmultiple
+ 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 overdrivers/thermal/Kconfig +2
-0+ temperature shutdown control from hardware to software. + endifdrivers/thermal/Makefile +0
-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/drivers/thermal/Makefile +1
-0+obj-$(CONFIG_QCOM_SPMI_TEMP_ALARM) += qcom-spmi-temp-alarm.odrivers/thermal/qcom-spmi-temp-alarm.c new file +2
-0@@ -0,0 +1,517 @@ +/* +* Copyright (c) 2011-2014, 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.
+ */drivers/thermal/qcom-spmi-temp-alarm.c new file +57
-0+ +#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_SHUTDOWN_CTRL2 0x42 +#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_OVERRIDE_STAGE3 0x80 +#define SHUTDOWN_CTRL1_OVERRIDE_STAGE2 0x40 +#define SHUTDOWN_CTRL1_THRESHOLD_MASK 0x03 + +#define SHUTDOWN_CTRL2_CLEAR_STAGE3 0x80 +#define SHUTDOWN_CTRL2_CLEAR_STAGE2 0x40 + +#define ALARM_CTRL_FORCE_ENABLE 0x80 +#define ALARM_CTRL_FOLLOW_HW_ENABLE 0x01 + +/* +* 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 +#define THRESH_MAX 3 + +/* Trip points from most critical to least critical */ +#define TRIP_STAGE3 0 +#define TRIP_STAGE2 1 +#define TRIP_STAGE1 2 +#define TRIP_NUM 3 + +/* Delay between TEMP_STAT IRQ going high and status value changing in ms */
drivers/thermal/qcom-spmi-temp-alarm.c new file +3
-0+#define READ_DELAY_MS 40 + +/* Temperature in Milli Celsius reported during stage 0 if no ADC is present */
drivers/thermal/qcom-spmi-temp-alarm.c new file +17
-0+#define DEFAULT_TEMP 37000 + +struct qpnp_tm_chip { +struct delayed_workwork ; +struct regmap *map; +struct device *dev; +struct thermal_zone_device *tz_dev; +enum thermal_device_modemode ; +long temp; +unsigned intthresh; +unsigned intstage; +unsigned intprev_stage; +unsigned intbase; +struct iio_channel *adc; +}; + +static int qpnp_tm_read(struct qpnp_tm_chip *chip, u16 addr, u8*data)
drivers/thermal/qcom-spmi-temp-alarm.c new file +13
-0+{ +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, u8data)
drivers/thermal/qcom-spmi-temp-alarm.c new file +5
-0+{ +return regmap_write (chip->map, chip->base + addr, data); +} + +static int qpnp_tm_shutdown_override(struct qpnp_tm_chip *chip,bool enable)
drivers/thermal/qcom-spmi-temp-alarm.c new file +105
-0+{ +u8 reg; + + reg = chip->thresh &SHUTDOWN_CTRL1_THRESHOLD_MASK ; + +if (enable) { + reg |=SHUTDOWN_CTRL1_OVERRIDE_STAGE2 ; + reg |=SHUTDOWN_CTRL1_OVERRIDE_STAGE3 ; + } + +return qpnp_tm_write (chip,QPNP_TM_REG_SHUTDOWN_CTRL1 , reg); +} + +/* +* 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 ; + }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 ; +} + +static int qpnp_tz_get_temp (struct thermal_zone_device *thermal, +unsigned long *temp) +{ +struct qpnp_tm_chip *chip = thermal->devdata; +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 int qpnp_tz_get_mode (struct thermal_zone_device *thermal, +enum thermal_device_mode *mode) +{ +struct qpnp_tm_chip *chip = thermal->devdata; + +if (!mode) +return -EINVAL ; + + *mode = chip->mode; + +return 0 ; +} + +static int qpnp_tz_set_mode (struct thermal_zone_device *thermal, +enum thermal_device_mode mode) +{ +struct qpnp_tm_chip *chip = thermal->devdata; +int ret; + +if (mode == chip->mode) +return 0 ; + +if (mode ==THERMAL_DEVICE_ENABLED ) + ret =qpnp_tm_shutdown_override (chip, true); +else + ret =qpnp_tm_shutdown_override (chip, false); + + chip->mode = mode; + +return ret; +} + +static int qpnp_tz_get_trip_type(struct thermal_zone_device*thermal, int trip,
drivers/thermal/qcom-spmi-temp-alarm.c new file +23
-0+ enum thermal_trip_type *type) +{ +if (trip <0 || !type) +return -EINVAL ; + +switch (trip) { +case TRIP_STAGE3 : + *type =THERMAL_TRIP_CRITICAL ; +break ; +case TRIP_STAGE2 : + *type =THERMAL_TRIP_HOT ; +break ; +case TRIP_STAGE1 : + *type =THERMAL_TRIP_HOT ; +break ; +default : +return -EINVAL ; + } + +return 0 ; +} + +static int qpnp_tz_get_trip_temp(struct thermal_zone_device*thermal, int trip,
drivers/thermal/qcom-spmi-temp-alarm.c new file +9
-0+ unsigned long *temp) +{ +struct qpnp_tm_chip *chip = thermal->devdata; +int thresh_temp; + +if (trip <0 || !temp) +return -EINVAL ; + + thresh_temp = chip->thresh * TEMP_THRESH_STEP +
TEMP_THRESH_MIN;drivers/thermal/qcom-spmi-temp-alarm.c new file +20
-0+ +switch (trip) { +case TRIP_STAGE3 : + thresh_temp +=2 *TEMP_STAGE_STEP ; +break ; +case TRIP_STAGE2 : + thresh_temp +=TEMP_STAGE_STEP ; +break ; +case TRIP_STAGE1 : +break ; +default : +return -EINVAL ; + } + + *temp = thresh_temp; + +return 0 ; +} + +static int qpnp_tz_get_crit_temp(struct thermal_zone_device*thermal,
drivers/thermal/qcom-spmi-temp-alarm.c new file +18
-0+ unsigned long *temp) +{ +struct qpnp_tm_chip *chip = thermal->devdata; + +if (!temp) +return -EINVAL ; + + *temp = chip->thresh *TEMP_THRESH_STEP +TEMP_THRESH_MIN + +2 *TEMP_STAGE_STEP ; + +return 0 ; +} + +static irqreturn_t qpnp_tm_isr (int irq,void *data) +{ +struct qpnp_tm_chip *chip = data; + + schedule_delayed_work(&chip->work,
msecs_to_jiffies(READ_DELAY_MS)+ 1);drivers/thermal/qcom-spmi-temp-alarm.c new file +36
-0+ +return IRQ_HANDLED ; +} + +static void qpnp_tm_work (struct work_struct *work) +{ +struct delayed_work *dwork; +struct qpnp_tm_chip *chip; +int ret, mili_celsius; +u8 reg; + + dwork = container_of(work, struct delayed_work, work); + chip = container_of(dwork, struct qpnp_tm_chip, work); + +if (IS_ERR (chip->adc)) { + ret =qpnp_tm_update_temp_no_adc (chip); +if (ret <0 ) +return ; + }else { + ret =qpnp_tm_read (chip,QPNP_TM_REG_STATUS , ®); +if (ret <0 ) +return ; + + chip->stage = reg &STATUS_STAGE_MASK ; + + ret =iio_read_channel_processed (chip->adc, &mili_celsius); +if (ret <0 ) +return ; + + chip->temp = mili_celsius; + } + +if (chip->stage != chip->prev_stage) { + chip->prev_stage = chip->stage; + + dev_warn(chip->dev, "Thermal alarm stage %u, threshold %u,temp %ld mC\n",
drivers/thermal/qcom-spmi-temp-alarm.c new file +11
-0+ chip->stage, chip->thresh, chip->temp); + +thermal_zone_device_update (chip->tz_dev); + +/* Notify user space */ +sysfs_notify (&chip->tz_dev->device.kobj,NULL ,"type" ); + } +} + +/* +* This function initializes the internal temp value based on only the
+ * current thermal stage and threshold. Setup threshold control and
+ * disable shutdown override.
+ */drivers/thermal/qcom-spmi-temp-alarm.c new file +21
-0+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
drivers/thermal/qcom-spmi-temp-alarm.c new file +65
-0+* 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 struct thermal_zone_device_ops qpnp_tz_ops = { + .get_temp= qpnp_tz_get_temp, + .get_mode= qpnp_tz_get_mode, + .set_mode= qpnp_tz_set_mode, + .get_trip_type= qpnp_tz_get_trip_type, + .get_trip_temp= qpnp_tz_get_trip_temp, + .get_crit_temp= qpnp_tz_get_crit_temp, +}; + +static int qpnp_tm_probe (struct platform_device *pdev) +{ +struct qpnp_tm_chip *chip; +struct device_node *node; +u8 type, subtype; +int ret, irq, res[2 ]; + + 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->dev = &pdev->dev; +INIT_DELAYED_WORK (&chip->work, qpnp_tm_work); + + chip->map =dev_get_regmap (chip->dev->parent,NULL ); +if (!chip->map) +return -ENXIO ; + + ret =of_property_read_u32_array (node,"reg" , res,2 ); +if (ret <0 ) +return ret; + + 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" ); +return ret; + } + + ret =qpnp_tm_read (chip,QPNP_TM_REG_SUBTYPE , &subtype); +if (ret <0 ) { +dev_err (&pdev->dev,"could not read subtype\n" ); +return ret; + } + +if (type !=QPNP_TM_TYPE || subtype !=QPNP_TM_SUBTYPE ) { + dev_err(&pdev->dev, "invalid type 0x%02x or subtype0x%02x\n",
drivers/thermal/qcom-spmi-temp-alarm.c new file +19
-0+ type, subtype); +return -ENODEV ; + } + + irq =platform_get_irq (pdev,0 ); +if (irq <0 ) +return irq; + + chip->adc =iio_channel_get (chip->dev,"thermal" ); +if (PTR_ERR (chip->adc) == -EPROBE_DEFER ) +return PTR_ERR (chip->adc); + + ret =qpnp_tm_init (chip); +if (ret <0 ) { +dev_err (&pdev->dev,"init failed\n" ); +return ret; + } + +/* Start in HW control. Switch to SW control when user changes mode. */
drivers/thermal/qcom-spmi-temp-alarm.c new file +3
-0+ chip->mode =THERMAL_DEVICE_DISABLED ; + + chip->tz_dev = thermal_zone_device_register(node->name,
TRIP_NUM, 0,drivers/thermal/qcom-spmi-temp-alarm.c new file +8
-0+ chip, &qpnp_tz_ops,NULL , + 0, 0); +if (IS_ERR (chip->tz_dev)) { +dev_err (&pdev->dev,"TZ registration failed\n" ); +return PTR_ERR (chip->tz_dev); + } + + ret = devm_request_irq(chip->dev, irq, qpnp_tm_isr, 0,
node->name,drivers/thermal/qcom-spmi-temp-alarm.c new file +24
-0+ chip); +if (ret <0 ) +thermal_zone_device_unregister (chip->tz_dev); + +return ret; +} + +static int qpnp_tm_remove (struct platform_device *pdev) +{ +struct qpnp_tm_chip *chip =dev_get_drvdata (&pdev->dev); + +cancel_delayed_work_sync (&chip->work); +thermal_zone_device_unregister (chip->tz_dev); +qpnp_tm_shutdown_override (chip, false); + +return 0 ; +} + +#ifdef CONFIG_PM_SLEEP +static int qpnp_tm_suspend (struct device *dev) +{ +struct qpnp_tm_chip *chip =dev_get_drvdata (dev); + +/* Clear override bits in suspend to allow hardware control */
drivers/thermal/qcom-spmi-temp-alarm.c new file +45
-0+qpnp_tm_shutdown_override (chip, false); + +return 0 ; +} + +static int qpnp_tm_resume (struct device *dev) +{ +struct qpnp_tm_chip *chip =dev_get_drvdata (dev); + +/* Override hardware actions so software can control */ +if (chip->mode ==THERMAL_DEVICE_ENABLED ) +qpnp_tm_shutdown_override (chip, true); + +return 0 ; +} + +static const struct dev_pm_ops qpnp_tm_pm_ops = { +SET_SYSTEM_SLEEP_PM_OPS (qpnp_tm_suspend, qpnp_tm_resume) +}; + +#define QPNP_TM_PM_OPS (&qpnp_tm_pm_ops) +#else +#define QPNP_TM_PM_OPS NULL +#endif + +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, + .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" );
Hello Ivan
Quoted 14 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.
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.
Quoted 3 lines
Send a notification to userspace via
sysfs_notify()whenever the over temperature stage value changes.
Thanks for sending your driver.
Quoted 285 lines
Cc David Collins <[email protected]>Signed-off-by Ivan T. Ivanov <[email protected]>---
Changes since v2:
- Fixed review comments from Kiran Padwal
- Files renamed from qpnp-* to qcom-spmi-* to be inline with other PMIC sub-function drivers like qcom-spmi-iadc and qcom-spmi-vadc.v2: http://www.gossamer-threads.com/lists/linux/kernel/2017366
.../bindings/thermal/qcom-spmi-temp-alarm.txt | 26 ++ drivers/thermal/Kconfig | 13 + drivers/thermal/Makefile | 1 + drivers/thermal/qcom-spmi-temp-alarm.c | 517 +++++++++++++++++++++ 4 files changed, 557 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 +26
-0@@ -0,0 +1,26 @@ +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 + +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 0x100>; + 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 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 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. + endifdrivers/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_QCOM_SPMI_TEMP_ALARM) += qcom-spmi-temp-alarm.odrivers/thermal/qcom-spmi-temp-alarm.c new file +195
-0@@ -0,0 +1,517 @@ +/* +* Copyright (c) 2011-2014, 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_SHUTDOWN_CTRL2 0x42 +#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_OVERRIDE_STAGE3 0x80 +#define SHUTDOWN_CTRL1_OVERRIDE_STAGE2 0x40 +#define SHUTDOWN_CTRL1_THRESHOLD_MASK 0x03 + +#define SHUTDOWN_CTRL2_CLEAR_STAGE3 0x80 +#define SHUTDOWN_CTRL2_CLEAR_STAGE2 0x40 + +#define ALARM_CTRL_FORCE_ENABLE 0x80 +#define ALARM_CTRL_FOLLOW_HW_ENABLE 0x01 + +/* +* 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 +#define THRESH_MAX 3 + +/* Trip points from most critical to least critical */ +#define TRIP_STAGE3 0 +#define TRIP_STAGE2 1 +#define TRIP_STAGE1 2 +#define TRIP_NUM 3 + +/* Delay between TEMP_STAT IRQ going high and status value changing in ms */ +#define READ_DELAY_MS 40 + +/* Temperature in Milli Celsius reported during stage 0 if no ADC is present */ +#define DEFAULT_TEMP 37000 + +struct qpnp_tm_chip { +struct delayed_work work; +struct regmap *map; +struct device *dev; +struct thermal_zone_device *tz_dev; +enum thermal_device_mode mode; +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); +} + +static int qpnp_tm_shutdown_override (struct qpnp_tm_chip *chip,bool enable) +{ +u8 reg; + + reg = chip->thresh &SHUTDOWN_CTRL1_THRESHOLD_MASK ; + +if (enable) { + reg |=SHUTDOWN_CTRL1_OVERRIDE_STAGE2 ; + reg |=SHUTDOWN_CTRL1_OVERRIDE_STAGE3 ; + } + +return qpnp_tm_write (chip,QPNP_TM_REG_SHUTDOWN_CTRL1 , reg); +} + +/* +* 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 ; + }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 ; +} + +static int qpnp_tz_get_temp (struct thermal_zone_device *thermal, +unsigned long *temp) +{ +struct qpnp_tm_chip *chip = thermal->devdata; +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 int qpnp_tz_get_mode (struct thermal_zone_device *thermal, +enum thermal_device_mode *mode) +{ +struct qpnp_tm_chip *chip = thermal->devdata; + +if (!mode) +return -EINVAL ; + + *mode = chip->mode; + +return 0 ; +} + +static int qpnp_tz_set_mode (struct thermal_zone_device *thermal, +enum thermal_device_mode mode) +{
drivers/thermal/qcom-spmi-temp-alarm.c line 205
Quoted 10 lines
drivers/thermal/qcom-spmi-temp-alarm.c new file +10
-0+struct qpnp_tm_chip *chip = thermal->devdata; +int ret; + +if (mode == chip->mode) +return 0 ; + +if (mode ==THERMAL_DEVICE_ENABLED ) + ret =qpnp_tm_shutdown_override (chip, true); +else + ret =qpnp_tm_shutdown_override (chip, false);
Can you please elaborate a little more why you need to switch these when mode changes?
Quoted 226 lines
drivers/thermal/qcom-spmi-temp-alarm.c new file +226
-0+ + chip->mode = mode; + +return ret; +} + +static int qpnp_tz_get_trip_type (struct thermal_zone_device *thermal,int trip, +enum thermal_trip_type *type) +{ +if (trip <0 || !type) +return -EINVAL ; + +switch (trip) { +case TRIP_STAGE3 : + *type =THERMAL_TRIP_CRITICAL ; +break ; +case TRIP_STAGE2 : + *type =THERMAL_TRIP_HOT ; +break ; +case TRIP_STAGE1 : + *type =THERMAL_TRIP_HOT ; +break ; +default : +return -EINVAL ; + } + +return 0 ; +} + +static int qpnp_tz_get_trip_temp (struct thermal_zone_device *thermal,int trip, +unsigned long *temp) +{ +struct qpnp_tm_chip *chip = thermal->devdata; +int thresh_temp; + +if (trip <0 || !temp) +return -EINVAL ; + + thresh_temp = chip->thresh *TEMP_THRESH_STEP +TEMP_THRESH_MIN ; + +switch (trip) { +case TRIP_STAGE3 : + thresh_temp +=2 *TEMP_STAGE_STEP ; +break ; +case TRIP_STAGE2 : + thresh_temp +=TEMP_STAGE_STEP ; +break ; +case TRIP_STAGE1 : +break ; +default : +return -EINVAL ; + } + + *temp = thresh_temp; + +return 0 ; +} + +static int qpnp_tz_get_crit_temp (struct thermal_zone_device *thermal, +unsigned long *temp) +{ +struct qpnp_tm_chip *chip = thermal->devdata; + +if (!temp) +return -EINVAL ; + + *temp = chip->thresh *TEMP_THRESH_STEP +TEMP_THRESH_MIN + +2 *TEMP_STAGE_STEP ; + +return 0 ; +} + +static irqreturn_t qpnp_tm_isr (int irq,void *data) +{ +struct qpnp_tm_chip *chip = data; + +schedule_delayed_work (&chip->work,msecs_to_jiffies (READ_DELAY_MS ) +1 ); + +return IRQ_HANDLED ; +} + +static void qpnp_tm_work (struct work_struct *work) +{ +struct delayed_work *dwork; +struct qpnp_tm_chip *chip; +int ret, mili_celsius; +u8 reg; + + dwork = container_of(work, struct delayed_work, work); + chip = container_of(dwork, struct qpnp_tm_chip, work); + +if (IS_ERR (chip->adc)) { + ret =qpnp_tm_update_temp_no_adc (chip); +if (ret <0 ) +return ; + }else { + ret =qpnp_tm_read (chip,QPNP_TM_REG_STATUS , ®); +if (ret <0 ) +return ; + + chip->stage = reg &STATUS_STAGE_MASK ; + + ret =iio_read_channel_processed (chip->adc, &mili_celsius); +if (ret <0 ) +return ; + + chip->temp = mili_celsius; + } + +if (chip->stage != chip->prev_stage) { + chip->prev_stage = chip->stage; + +dev_warn (chip->dev,"Thermal alarm stage %u, threshold %u, temp %ld mC\n" , + chip->stage, chip->thresh, chip->temp); + +thermal_zone_device_update (chip->tz_dev); + +/* Notify user space */ +sysfs_notify (&chip->tz_dev->device.kobj,NULL ,"type" ); + } +} + +/* +* 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 struct thermal_zone_device_ops qpnp_tz_ops = { + .get_temp = qpnp_tz_get_temp, + .get_mode = qpnp_tz_get_mode, + .set_mode = qpnp_tz_set_mode, + .get_trip_type = qpnp_tz_get_trip_type, + .get_trip_temp = qpnp_tz_get_trip_temp, + .get_crit_temp = qpnp_tz_get_crit_temp, +}; + +static int qpnp_tm_probe (struct platform_device *pdev) +{ +struct qpnp_tm_chip *chip; +struct device_node *node; +u8 type, subtype; +int ret, irq, res[2 ]; + + 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->dev = &pdev->dev; +INIT_DELAYED_WORK (&chip->work, qpnp_tm_work); + + chip->map =dev_get_regmap (chip->dev->parent,NULL ); +if (!chip->map) +return -ENXIO ; + + ret =of_property_read_u32_array (node,"reg" , res,2 ); +if (ret <0 ) +return ret; + + 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" ); +return ret; + } + + ret =qpnp_tm_read (chip,QPNP_TM_REG_SUBTYPE , &subtype); +if (ret <0 ) { +dev_err (&pdev->dev,"could not read subtype\n" ); +return ret; + } + +if (type !=QPNP_TM_TYPE || subtype !=QPNP_TM_SUBTYPE ) { +dev_err (&pdev->dev,"invalid type 0x%02x or subtype 0x%02x\n" , + type, subtype); +return -ENODEV ; + } + + irq =platform_get_irq (pdev,0 ); +if (irq <0 ) +return irq; + + chip->adc =iio_channel_get (chip->dev,"thermal" ); +if (PTR_ERR (chip->adc) == -EPROBE_DEFER ) +return PTR_ERR (chip->adc); + + ret =qpnp_tm_init (chip);
drivers/thermal/qcom-spmi-temp-alarm.c line 441
Quoted 10 lines
drivers/thermal/qcom-spmi-temp-alarm.c new file +10
-0+if (ret <0 ) { +dev_err (&pdev->dev,"init failed\n" ); +return ret; + } + +/* Start in HW control. Switch to SW control when user changes mode. */ + chip->mode =THERMAL_DEVICE_DISABLED ; + + chip->tz_dev = thermal_zone_device_register(node->name, TRIP_NUM, 0, + chip, &qpnp_tz_ops, NULL,
Have you considered using of-thermal instead of doing your own specific thermal zone registration? Having a glance look in this driver, most of the operation are covered by of-thermal. Ahy concerns using of-thermal in your case?
drivers/thermal/qcom-spmi-temp-alarm.c line 449
Quoted 8 lines
drivers/thermal/qcom-spmi-temp-alarm.c new file +8
-0+ 0, 0); +if (IS_ERR (chip->tz_dev)) { +dev_err (&pdev->dev,"TZ registration failed\n" ); +return PTR_ERR (chip->tz_dev); + } + + ret =devm_request_irq (chip->dev, irq, qpnp_tm_isr,0 , node->name, + chip);
The IRQ handling would probably be kept in your driver.
Quoted 71 lines
drivers/thermal/qcom-spmi-temp-alarm.c new file +68
-0+if (ret <0 ) +thermal_zone_device_unregister (chip->tz_dev); + +return ret; +} + +static int qpnp_tm_remove (struct platform_device *pdev) +{ +struct qpnp_tm_chip *chip =dev_get_drvdata (&pdev->dev); + +cancel_delayed_work_sync (&chip->work); +thermal_zone_device_unregister (chip->tz_dev); +qpnp_tm_shutdown_override (chip, false); + +return 0 ; +} + +#ifdef CONFIG_PM_SLEEP +static int qpnp_tm_suspend (struct device *dev) +{ +struct qpnp_tm_chip *chip =dev_get_drvdata (dev); + +/* Clear override bits in suspend to allow hardware control */ +qpnp_tm_shutdown_override (chip, false); + +return 0 ; +} + +static int qpnp_tm_resume (struct device *dev) +{ +struct qpnp_tm_chip *chip =dev_get_drvdata (dev); + +/* Override hardware actions so software can control */ +if (chip->mode ==THERMAL_DEVICE_ENABLED ) +qpnp_tm_shutdown_override (chip, true); + +return 0 ; +} + +static const struct dev_pm_ops qpnp_tm_pm_ops = { +SET_SYSTEM_SLEEP_PM_OPS (qpnp_tm_suspend, qpnp_tm_resume) +}; + +#define QPNP_TM_PM_OPS (&qpnp_tm_pm_ops) +#else +#define QPNP_TM_PM_OPS NULL +#endif + +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, + .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" );Signature · 1 line
1.9.1
Hi Eduardo,
Quoted 3 lines · Eduardo Valentin
Hello Ivan
<snip>
Quoted 11 lines
Quoted 11 lines
drivers/thermal/qcom-spmi-temp-alarm.c new file +10
-0+ +static int qpnp_tz_set_mode (struct thermal_zone_device *thermal, +enum thermal_device_mode mode) +{ +struct qpnp_tm_chip *chip = thermal->devdata; +int ret; + +if (mode == chip->mode) +return 0 ; +
Quoted 8 lines
drivers/thermal/qcom-spmi-temp-alarm.c line 205
Quoted 4 lines
drivers/thermal/qcom-spmi-temp-alarm.c new file +4
-0+if (mode ==THERMAL_DEVICE_ENABLED ) + ret =qpnp_tm_shutdown_override (chip, true); +else + ret =qpnp_tm_shutdown_override (chip, false);Can you please elaborate a little more why you need to switch these when mode changes?
My understanding is that PMIC hardware have predefined shutdown sequence in case of overheat. In non override mode, hardware itself will take care for shunting down PMIC, which directly will shutdown also and main CPU's, while when override is enabled software running on main CPU's, will take care for system shutdown.
Quoted 8 lines
Quoted 8 lines
drivers/thermal/qcom-spmi-temp-alarm.c new file +6
-0+ + chip->mode = mode; + +return ret; +} +
<snip>
Quoted 9 lines
Quoted 9 lines
drivers/thermal/qcom-spmi-temp-alarm.c new file +8
-0+ +static int qpnp_tm_probe (struct platform_device *pdev) +{ +struct qpnp_tm_chip *chip; +struct device_node *node; +u8 type, subtype; +int ret, irq, res[2 ]; +
<snip>
Quoted 9 lines
drivers/thermal/qcom-spmi-temp-alarm.c line 441
Quoted 3 lines
drivers/thermal/qcom-spmi-temp-alarm.c new file +3
-0+ + chip->tz_dev = thermal_zone_device_register(node->name, TRIP_NUM, 0, + chip, &qpnp_tz_ops, NULL,Have you considered using of-thermal instead of doing your own specific thermal zone registration? Having a glance look in this driver, most of the operation are covered by of-thermal. Ahy concerns using of-thermal in your case?
I just followed implementation found in "armada_thermal", "db8500-thermal", "dove_thermal", "imx_thermal", "kirkwood_thermal"...
Will look at of-thermal.
Thank you,
Ivan
Quoted 1 line · Ivan T. Ivanov
+
Quoted 9 lines
Quoted 8 lines
drivers/thermal/qcom-spmi-temp-alarm.c line 441
Quoted 2 lines
drivers/thermal/qcom-spmi-temp-alarm.c new file +2
-0+ chip->tz_dev = thermal_zone_device_register(node->name, TRIP_NUM, 0, + chip, &qpnp_tz_ops, NULL,Have you considered using of-thermal instead of doing your own specific thermal zone registration? Having a glance look in this driver, most of the operation are covered by of-thermal. Ahy concerns using of-thermal in your case?
Quoted 5 lines
I just followed implementation found in "
armada_thermal", "db8500-thermal", "dove_thermal", "imx_thermal", "kirkwood_thermal"...Will look at of-thermal.
Hm, the 15 drivers, which register its own thermal zone, against 4, which use of-thermal registration and one of them is OMAP, which have fallback to its own zone registration :-). Anyway. I am afraid that if I use just thermal_zone_of_sensor_register(), driver will lost ability to switch off hardware controlled shutdown sequence, which make it useless IMHO.
I don't see how driver can benefits from nice things provided by of-thermal. There is no colling device associated with PMIC chip, pooling delays are of no use, device uses interrupt, trip pints are predefined in hardware...
Please advice.
Regards,
Ivan
Quoted 13 lines · Ivan T. Ivanov
Quoted 1 line · Ivan T. Ivanov
+
Quoted 9 lines
Quoted 8 lines
drivers/thermal/qcom-spmi-temp-alarm.c line 441
Quoted 2 lines
drivers/thermal/qcom-spmi-temp-alarm.c new file +2
-0+ chip->tz_dev = thermal_zone_device_register(node->name, TRIP_NUM, 0, + chip, &qpnp_tz_ops, NULL,Have you considered using of-thermal instead of doing your own specific thermal zone registration? Having a glance look in this driver, most of the operation are covered by of-thermal. Ahy concerns using of-thermal in your case?
Quoted 7 lines
Quoted 5 lines
I just followed implementation found in "
armada_thermal", "db8500-thermal", "dove_thermal", "imx_thermal", "kirkwood_thermal"...Will look at of-thermal.
Hm, the 15 drivers, which register its own thermal zone, against 4, which
Yes, and the reasoning is pretty simple: of-thermal is not imposed standard, and not all platform have decided to move to using it. However, DT is being used more and more frequently. So, given you already have DT support, considering using of-thermal is a good thing to do.
Besides, you are with hands on your driver, might make sense to add its support while you are there.
Quoted 2 lines
use of-thermal registration and one of them is OMAP, which have fallback to its own zone registration :-). Anyway. I am afraid that if I use just
The fallback is because non-dt booting has not been dropped from OMAP, AFAIK.
Quoted 2 lines
thermal_zone_of_sensor_register(), driver will lost ability to switch off hardware controlled shutdown sequence, which make it useless IMHO.
Any special sequence or callback you want to consider to improve of-thermal support?
For instance, getting a callback for mode change events would enable you to get a better support for hardware controlled shutdown sequence?
Quoted 4 lines
I don't see how driver can benefits from nice things provided by of-thermal. There is no colling device associated with PMIC chip, pooling delays are of no use, device uses interrupt, trip pints are predefined in hardware...
I see. However, using it may make this driver even simpler, as you would simply describe it in DT and the notification you want would be taken care by the core part of the framework.
Quoted 5 lines
Please advice.
Regards,
Ivan