gov_low_limits.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * Copyright (C) 2012 Intel Corp
  3. * Copyright (C) 2012 Durgadoss R <[email protected]>
  4. * Copyright (c) 2017, The Linux Foundation. All rights reserved.
  5. *
  6. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; version 2 of the License.
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  18. */
  19. #include <linux/thermal.h>
  20. #include <trace/events/thermal.h>
  21. #include "thermal_core.h"
  22. static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip)
  23. {
  24. int trip_temp, trip_hyst;
  25. enum thermal_trip_type trip_type;
  26. struct thermal_instance *instance;
  27. bool throttle;
  28. int old_target;
  29. tz->ops->get_trip_temp(tz, trip, &trip_temp);
  30. tz->ops->get_trip_type(tz, trip, &trip_type);
  31. if (tz->ops->get_trip_hyst) {
  32. tz->ops->get_trip_hyst(tz, trip, &trip_hyst);
  33. trip_hyst = trip_temp + trip_hyst;
  34. } else {
  35. trip_hyst = trip_temp;
  36. }
  37. mutex_lock(&tz->lock);
  38. list_for_each_entry(instance, &tz->thermal_instances, tz_node) {
  39. if (instance->trip != trip)
  40. continue;
  41. if ((tz->temperature <= trip_temp) ||
  42. (instance->target != THERMAL_NO_TARGET
  43. && tz->temperature < trip_hyst))
  44. throttle = true;
  45. else
  46. throttle = false;
  47. dev_dbg(&tz->device,
  48. "Trip%d[type=%d,temp=%d,hyst=%d],throttle=%d\n",
  49. trip, trip_type, trip_temp, trip_hyst, throttle);
  50. old_target = instance->target;
  51. instance->target = (throttle) ? instance->upper
  52. : THERMAL_NO_TARGET;
  53. dev_dbg(&instance->cdev->device, "old_target=%d, target=%d\n",
  54. old_target, (int)instance->target);
  55. if (old_target == instance->target)
  56. continue;
  57. if (old_target == THERMAL_NO_TARGET &&
  58. instance->target != THERMAL_NO_TARGET) {
  59. trace_thermal_zone_trip(tz, trip, trip_type, true);
  60. tz->passive += 1;
  61. } else if (old_target != THERMAL_NO_TARGET &&
  62. instance->target == THERMAL_NO_TARGET) {
  63. trace_thermal_zone_trip(tz, trip, trip_type, false);
  64. tz->passive -= 1;
  65. }
  66. instance->cdev->updated = false; /* cdev needs update */
  67. }
  68. mutex_unlock(&tz->lock);
  69. }
  70. /**
  71. * low_limits_throttle - throttles devices associated with the given zone
  72. * @tz - thermal_zone_device
  73. * @trip - the trip point
  74. *
  75. * Throttling Logic: If the sensor reading goes below a trip point, the
  76. * pre-defined mitigation will be applied for the cooling device.
  77. * If the sensor reading goes above the trip hysteresis, the
  78. * mitigation will be removed.
  79. */
  80. static int low_limits_throttle(struct thermal_zone_device *tz, int trip)
  81. {
  82. struct thermal_instance *instance;
  83. thermal_zone_trip_update(tz, trip);
  84. mutex_lock(&tz->lock);
  85. list_for_each_entry(instance, &tz->thermal_instances, tz_node)
  86. thermal_cdev_update(instance->cdev);
  87. mutex_unlock(&tz->lock);
  88. return 0;
  89. }
  90. static struct thermal_governor thermal_gov_low_limits_floor = {
  91. .name = "low_limits_floor",
  92. .throttle = low_limits_throttle,
  93. .min_state_throttle = 1,
  94. };
  95. static struct thermal_governor thermal_gov_low_limits_cap = {
  96. .name = "low_limits_cap",
  97. .throttle = low_limits_throttle,
  98. };
  99. int thermal_gov_low_limits_register(void)
  100. {
  101. thermal_register_governor(&thermal_gov_low_limits_cap);
  102. return thermal_register_governor(&thermal_gov_low_limits_floor);
  103. }
  104. void thermal_gov_low_limits_unregister(void)
  105. {
  106. thermal_unregister_governor(&thermal_gov_low_limits_cap);
  107. thermal_unregister_governor(&thermal_gov_low_limits_floor);
  108. }