Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

thermal: Enhance thermal_zone_device_update for events

Added one additional parameter to thermal_zone_device_update() to provide
caller with an optional capability to specify reason.
Currently this event is used by user space governor to trigger different
processing based on event code. Also it saves an additional call to read
temperature when the event is received.
The following events are cuurently defined:
- Unspecified event
- New temperature sample
- Trip point violated
- Trip point changed
- thermal device up and down
- thermal device power capability changed

Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Signed-off-by: Zhang Rui <rui.zhang@intel.com>

authored by

Srinivas Pandruvada and committed by
Zhang Rui
0e70f466 040a3ead

+60 -30
+2 -1
drivers/acpi/thermal.c
··· 520 520 if (!tz->tz_enabled) 521 521 return; 522 522 523 - thermal_zone_device_update(tz->thermal_zone); 523 + thermal_zone_device_update(tz->thermal_zone, 524 + THERMAL_EVENT_UNSPECIFIED); 524 525 } 525 526 526 527 /* sys I/F for generic thermal sysfs support */
+1 -1
drivers/platform/x86/acerhdf.c
··· 405 405 kernelmode = 1; 406 406 407 407 thz_dev->polling_delay = interval*1000; 408 - thermal_zone_device_update(thz_dev); 408 + thermal_zone_device_update(thz_dev, THERMAL_EVENT_UNSPECIFIED); 409 409 pr_notice("kernel mode fan control ON\n"); 410 410 } 411 411
+2 -1
drivers/regulator/max8973-regulator.c
··· 495 495 { 496 496 struct max8973_chip *mchip = data; 497 497 498 - thermal_zone_device_update(mchip->tz_device); 498 + thermal_zone_device_update(mchip->tz_device, 499 + THERMAL_EVENT_UNSPECIFIED); 499 500 500 501 return IRQ_HANDLED; 501 502 }
+1 -1
drivers/thermal/db8500_thermal.c
··· 306 306 if (cur_mode == THERMAL_DEVICE_DISABLED) 307 307 return; 308 308 309 - thermal_zone_device_update(pzone->therm_dev); 309 + thermal_zone_device_update(pzone->therm_dev, THERMAL_EVENT_UNSPECIFIED); 310 310 dev_dbg(&pzone->therm_dev->device, "thermal work finished.\n"); 311 311 } 312 312
+2 -1
drivers/thermal/hisi_thermal.c
··· 237 237 if (!data->sensors[i].tzd) 238 238 continue; 239 239 240 - thermal_zone_device_update(data->sensors[i].tzd); 240 + thermal_zone_device_update(data->sensors[i].tzd, 241 + THERMAL_EVENT_UNSPECIFIED); 241 242 } 242 243 243 244 return IRQ_HANDLED;
+2 -2
drivers/thermal/imx_thermal.c
··· 246 246 } 247 247 248 248 data->mode = mode; 249 - thermal_zone_device_update(tz); 249 + thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); 250 250 251 251 return 0; 252 252 } ··· 457 457 dev_dbg(&data->tz->device, "THERMAL ALARM: T > %d\n", 458 458 data->alarm_temp / 1000); 459 459 460 - thermal_zone_device_update(data->tz); 460 + thermal_zone_device_update(data->tz, THERMAL_EVENT_UNSPECIFIED); 461 461 462 462 return IRQ_HANDLED; 463 463 }
+1 -1
drivers/thermal/int340x_thermal/int340x_thermal_zone.h
··· 62 62 static inline void int340x_thermal_zone_device_update( 63 63 struct int34x_thermal_zone *tzone) 64 64 { 65 - thermal_zone_device_update(tzone->zone); 65 + thermal_zone_device_update(tzone->zone, THERMAL_EVENT_UNSPECIFIED); 66 66 } 67 67 68 68 #endif
+2 -1
drivers/thermal/intel_bxt_pmic_thermal.c
··· 204 204 trip = td->maps[i].trip_config[j].trip_num; 205 205 tzd = thermal_zone_get_zone_by_name(td->maps[i].handle); 206 206 if (!IS_ERR(tzd)) 207 - thermal_zone_device_update(tzd); 207 + thermal_zone_device_update(tzd, 208 + THERMAL_EVENT_UNSPECIFIED); 208 209 209 210 /* Clear the appropriate irq */ 210 211 regmap_write(regmap, reg, reg_val & mask);
+2 -1
drivers/thermal/intel_soc_dts_iosf.c
··· 391 391 392 392 for (i = 0; i < SOC_MAX_DTS_SENSORS; ++i) { 393 393 pr_debug("TZD update for zone %d\n", i); 394 - thermal_zone_device_update(sensors->soc_dts[i].tzone); 394 + thermal_zone_device_update(sensors->soc_dts[i].tzone, 395 + THERMAL_EVENT_UNSPECIFIED); 395 396 } 396 397 } else 397 398 spin_unlock_irqrestore(&sensors->intr_notify_lock, flags);
+2 -1
drivers/thermal/max77620_thermal.c
··· 82 82 else if (irq == mtherm->irq_tjalarm2) 83 83 dev_crit(mtherm->dev, "Junction Temp Alarm2(140C) occurred\n"); 84 84 85 - thermal_zone_device_update(mtherm->tz_device); 85 + thermal_zone_device_update(mtherm->tz_device, 86 + THERMAL_EVENT_UNSPECIFIED); 86 87 87 88 return IRQ_HANDLED; 88 89 }
+1 -1
drivers/thermal/of-thermal.c
··· 286 286 mutex_unlock(&tz->lock); 287 287 288 288 data->mode = mode; 289 - thermal_zone_device_update(tz); 289 + thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); 290 290 291 291 return 0; 292 292 }
+1 -1
drivers/thermal/qcom-spmi-temp-alarm.c
··· 150 150 { 151 151 struct qpnp_tm_chip *chip = data; 152 152 153 - thermal_zone_device_update(chip->tz_dev); 153 + thermal_zone_device_update(chip->tz_dev, THERMAL_EVENT_UNSPECIFIED); 154 154 155 155 return IRQ_HANDLED; 156 156 }
+2 -1
drivers/thermal/rcar_thermal.c
··· 358 358 return; 359 359 360 360 if (nctemp != cctemp) 361 - thermal_zone_device_update(priv->zone); 361 + thermal_zone_device_update(priv->zone, 362 + THERMAL_EVENT_UNSPECIFIED); 362 363 } 363 364 364 365 static u32 rcar_thermal_had_changed(struct rcar_thermal_priv *priv, u32 status)
+2 -1
drivers/thermal/rockchip_thermal.c
··· 873 873 thermal->chip->irq_ack(thermal->regs); 874 874 875 875 for (i = 0; i < thermal->chip->chn_num; i++) 876 - thermal_zone_device_update(thermal->sensors[i].tzd); 876 + thermal_zone_device_update(thermal->sensors[i].tzd, 877 + THERMAL_EVENT_UNSPECIFIED); 877 878 878 879 return IRQ_HANDLED; 879 880 }
+1 -1
drivers/thermal/samsung/exynos_tmu.c
··· 225 225 return; 226 226 } 227 227 228 - thermal_zone_device_update(tz); 228 + thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); 229 229 230 230 mutex_lock(&tz->lock); 231 231 /* Find the level for which trip happened */
+2 -1
drivers/thermal/st/st_thermal_memmap.c
··· 42 42 { 43 43 struct st_thermal_sensor *sensor = sdata; 44 44 45 - thermal_zone_device_update(sensor->thermal_dev); 45 + thermal_zone_device_update(sensor->thermal_dev, 46 + THERMAL_EVENT_UNSPECIFIED); 46 47 47 48 return IRQ_HANDLED; 48 49 }
+13 -8
drivers/thermal/thermal_core.c
··· 607 607 pos->initialized = false; 608 608 } 609 609 610 - void thermal_zone_device_update(struct thermal_zone_device *tz) 610 + void thermal_zone_device_update(struct thermal_zone_device *tz, 611 + enum thermal_notify_event event) 611 612 { 612 613 int count; 613 614 ··· 622 621 623 622 thermal_zone_set_trips(tz); 624 623 624 + tz->notify_event = event; 625 + 625 626 for (count = 0; count < tz->trips; count++) 626 627 handle_thermal_trip(tz, count); 627 628 } ··· 634 631 struct thermal_zone_device *tz = container_of(work, struct 635 632 thermal_zone_device, 636 633 poll_queue.work); 637 - thermal_zone_device_update(tz); 634 + thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); 638 635 } 639 636 640 637 /* sys I/F for thermal zone */ ··· 758 755 if (ret) 759 756 return ret; 760 757 761 - thermal_zone_device_update(tz); 758 + thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); 762 759 763 760 return count; 764 761 } ··· 880 877 881 878 tz->forced_passive = state; 882 879 883 - thermal_zone_device_update(tz); 880 + thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); 884 881 885 882 return count; 886 883 } ··· 971 968 } 972 969 973 970 if (!ret) 974 - thermal_zone_device_update(tz); 971 + thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); 975 972 976 973 return ret ? ret : count; 977 974 } ··· 1567 1564 mutex_lock(&thermal_list_lock); 1568 1565 list_for_each_entry(pos, &thermal_tz_list, node) 1569 1566 if (atomic_cmpxchg(&pos->need_update, 1, 0)) 1570 - thermal_zone_device_update(pos); 1567 + thermal_zone_device_update(pos, 1568 + THERMAL_EVENT_UNSPECIFIED); 1571 1569 mutex_unlock(&thermal_list_lock); 1572 1570 1573 1571 return cdev; ··· 2011 2007 thermal_zone_device_reset(tz); 2012 2008 /* Update the new thermal zone and mark it as already updated. */ 2013 2009 if (atomic_cmpxchg(&tz->need_update, 1, 0)) 2014 - thermal_zone_device_update(tz); 2010 + thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); 2015 2011 2016 2012 return tz; 2017 2013 ··· 2298 2294 atomic_set(&in_suspend, 0); 2299 2295 list_for_each_entry(tz, &thermal_tz_list, node) { 2300 2296 thermal_zone_device_reset(tz); 2301 - thermal_zone_device_update(tz); 2297 + thermal_zone_device_update(tz, 2298 + THERMAL_EVENT_UNSPECIFIED); 2302 2299 } 2303 2300 break; 2304 2301 default:
+2 -2
drivers/thermal/ti-soc-thermal/ti-thermal-common.c
··· 52 52 struct ti_thermal_data *data = container_of(work, 53 53 struct ti_thermal_data, thermal_wq); 54 54 55 - thermal_zone_device_update(data->ti_thermal); 55 + thermal_zone_device_update(data->ti_thermal, THERMAL_EVENT_UNSPECIFIED); 56 56 57 57 dev_dbg(&data->ti_thermal->device, "updated thermal zone %s\n", 58 58 data->ti_thermal->type); ··· 205 205 data->mode = mode; 206 206 ti_bandgap_write_update_interval(bgp, data->sensor_id, 207 207 data->ti_thermal->polling_delay); 208 - thermal_zone_device_update(data->ti_thermal); 208 + thermal_zone_device_update(data->ti_thermal, THERMAL_EVENT_UNSPECIFIED); 209 209 dev_dbg(&thermal->device, "thermal polling set for duration=%d msec\n", 210 210 data->ti_thermal->polling_delay); 211 211
+2 -1
drivers/thermal/x86_pkg_temp_thermal.c
··· 348 348 } 349 349 if (notify) { 350 350 pr_debug("thermal_zone_device_update\n"); 351 - thermal_zone_device_update(phdev->tzone); 351 + thermal_zone_device_update(phdev->tzone, 352 + THERMAL_EVENT_UNSPECIFIED); 352 353 } 353 354 } 354 355
+17 -2
include/linux/thermal.h
··· 92 92 THERMAL_TREND_DROP_FULL, /* apply lowest cooling action */ 93 93 }; 94 94 95 + /* Thermal notification reason */ 96 + enum thermal_notify_event { 97 + THERMAL_EVENT_UNSPECIFIED, /* Unspecified event */ 98 + THERMAL_EVENT_TEMP_SAMPLE, /* New Temperature sample */ 99 + THERMAL_TRIP_VIOLATED, /* TRIP Point violation */ 100 + THERMAL_TRIP_CHANGED, /* TRIP Point temperature changed */ 101 + THERMAL_DEVICE_DOWN, /* Thermal device is down */ 102 + THERMAL_DEVICE_UP, /* Thermal device is up after a down event */ 103 + THERMAL_DEVICE_POWER_CAPABILITY_CHANGED, /* power capability changed */ 104 + }; 105 + 95 106 struct thermal_zone_device_ops { 96 107 int (*bind) (struct thermal_zone_device *, 97 108 struct thermal_cooling_device *); ··· 198 187 * @lock: lock to protect thermal_instances list 199 188 * @node: node in thermal_tz_list (in thermal_core.c) 200 189 * @poll_queue: delayed work for polling 190 + * @notify_event: Last notification event 201 191 */ 202 192 struct thermal_zone_device { 203 193 int id; ··· 229 217 struct mutex lock; 230 218 struct list_head node; 231 219 struct delayed_work poll_queue; 220 + enum thermal_notify_event notify_event; 232 221 }; 233 222 234 223 /** ··· 449 436 unsigned int); 450 437 int thermal_zone_unbind_cooling_device(struct thermal_zone_device *, int, 451 438 struct thermal_cooling_device *); 452 - void thermal_zone_device_update(struct thermal_zone_device *); 439 + void thermal_zone_device_update(struct thermal_zone_device *, 440 + enum thermal_notify_event); 453 441 void thermal_zone_set_trips(struct thermal_zone_device *); 454 442 455 443 struct thermal_cooling_device *thermal_cooling_device_register(char *, void *, ··· 501 487 struct thermal_zone_device *tz, int trip, 502 488 struct thermal_cooling_device *cdev) 503 489 { return -ENODEV; } 504 - static inline void thermal_zone_device_update(struct thermal_zone_device *tz) 490 + static inline void thermal_zone_device_update(struct thermal_zone_device *tz, 491 + enum thermal_notify_event event) 505 492 { } 506 493 static inline void thermal_zone_set_trips(struct thermal_zone_device *tz) 507 494 { }