thermal: pm8xxx-tm: Improve temp alarm logging and notification filtering
Modify the kernel log message which is output when the PMIC
temperature alarm triggers so that the current (or estimated)
PMIC die temperature is shown regardless of ADC type.
Also change the log message printing and userspace notification
logic so that they only happen when the PMIC temp alarm stage
differs from what was previously seen. This will reduce the
number of messages seen while the temperature fluctuates around
one of the thresholds.
Change-Id: I5ee2206ea05dee86666308d11dad1fc5560e58e0
Signed-off-by: David Collins <collinsd@codeaurora.org>
diff --git a/drivers/thermal/pm8xxx-tm.c b/drivers/thermal/pm8xxx-tm.c
index d50eb57..8d9ee86 100644
--- a/drivers/thermal/pm8xxx-tm.c
+++ b/drivers/thermal/pm8xxx-tm.c
@@ -69,6 +69,7 @@
struct device *dev;
struct thermal_zone_device *tz_dev;
unsigned long temp;
+ unsigned int prev_stage;
enum thermal_device_mode mode;
unsigned int thresh;
unsigned int stage;
@@ -423,29 +424,14 @@
{
struct pm8xxx_tm_chip *chip
= container_of(work, struct pm8xxx_tm_chip, irq_work);
- int rc;
+ unsigned long temp = 0;
+ int rc, stage, thresh;
u8 reg;
rc = pm8xxx_tm_read_ctrl(chip, ®);
if (rc < 0)
goto bail;
- if (chip->cdata.adc_type == PM8XXX_TM_ADC_NONE) {
- rc = pm8xxx_tm_update_temp_no_adc(chip);
- if (rc < 0)
- goto bail;
- pr_info("%s: Temp Alarm - stage=%u, threshold=%u, "
- "temp=%lu mC\n", chip->cdata.tm_name, chip->stage,
- chip->thresh, chip->temp);
- } else {
- chip->stage = (reg & TEMP_ALARM_CTRL_STATUS_MASK)
- >> TEMP_ALARM_CTRL_STATUS_SHIFT;
- chip->thresh = (reg & TEMP_ALARM_CTRL_THRESH_MASK)
- >> TEMP_ALARM_CTRL_THRESH_SHIFT;
- pr_info("%s: Temp Alarm - stage=%u, threshold=%u\n",
- chip->cdata.tm_name, chip->stage, chip->thresh);
- }
-
/* Clear status bits. */
if (reg & (TEMP_ALARM_CTRL_ST2_SD | TEMP_ALARM_CTRL_ST3_SD)) {
reg &= ~(TEMP_ALARM_CTRL_ST2_SD | TEMP_ALARM_CTRL_ST3_SD
@@ -454,10 +440,36 @@
pm8xxx_tm_write_ctrl(chip, reg);
}
+ stage = (reg & TEMP_ALARM_CTRL_STATUS_MASK)
+ >> TEMP_ALARM_CTRL_STATUS_SHIFT;
+ thresh = (reg & TEMP_ALARM_CTRL_THRESH_MASK)
+ >> TEMP_ALARM_CTRL_THRESH_SHIFT;
+
thermal_zone_device_update(chip->tz_dev);
- /* Notify user space */
- sysfs_notify(&chip->tz_dev->device.kobj, NULL, "type");
+ if (stage != chip->prev_stage) {
+ chip->prev_stage = stage;
+
+ switch (chip->cdata.adc_type) {
+ case PM8XXX_TM_ADC_NONE:
+ rc = pm8xxx_tz_get_temp_no_adc(chip->tz_dev, &temp);
+ break;
+ case PM8XXX_TM_ADC_PM8058_ADC:
+ rc = pm8xxx_tz_get_temp_pm8058_adc(chip->tz_dev, &temp);
+ break;
+ case PM8XXX_TM_ADC_PM8XXX_ADC:
+ rc = pm8xxx_tz_get_temp_pm8xxx_adc(chip->tz_dev, &temp);
+ break;
+ }
+ if (rc < 0)
+ goto bail;
+
+ pr_crit("%s: PMIC Temp Alarm - stage=%u, threshold=%u, temp=%lu mC\n",
+ chip->cdata.tm_name, stage, thresh, temp);
+
+ /* Notify user space */
+ sysfs_notify(&chip->tz_dev->device.kobj, NULL, "type");
+ }
bail:
enable_irq(chip->tempstat_irq);