backward_compatible.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  2. #include <linux/module.h>
  3. #include <linux/thermal.h>
  4. #include "thermal_core.h"
  5. /**
  6. * backward_compatible_throttle
  7. * @tz - thermal_zone_device
  8. *
  9. * This function update the cooler state by monitoring the current temperature and trip points
  10. */
  11. static int backward_compatible_throttle(struct thermal_zone_device *tz, int trip)
  12. {
  13. long trip_temp;
  14. struct thermal_instance *instance;
  15. if (trip == THERMAL_TRIPS_NONE)
  16. trip_temp = tz->forced_passive;
  17. else
  18. tz->ops->get_trip_temp(tz, trip, &trip_temp);
  19. /* mutex_lock(&tz->lock); */
  20. list_for_each_entry(instance, &tz->thermal_instances, tz_node) {
  21. if (instance->trip != trip)
  22. continue;
  23. if (tz->temperature >= trip_temp)
  24. instance->target = 1;
  25. else
  26. instance->target = 0;
  27. instance->cdev->updated = false;
  28. thermal_cdev_update(instance->cdev);
  29. }
  30. /* mutex_unlock(&tz->lock); */
  31. return 0;
  32. }
  33. static struct thermal_governor thermal_gov_backward_compatible = {
  34. .name = "backward_compatible",
  35. .throttle = backward_compatible_throttle,
  36. /* .owner = THIS_MODULE, */
  37. };
  38. static int __init thermal_gov_backward_compatible_init(void)
  39. {
  40. return thermal_register_governor(&thermal_gov_backward_compatible);
  41. }
  42. static void __exit thermal_gov_backward_compatible_exit(void)
  43. {
  44. thermal_unregister_governor(&thermal_gov_backward_compatible);
  45. }
  46. /* This should load after thermal framework */
  47. fs_initcall(thermal_gov_backward_compatible_init);
  48. module_exit(thermal_gov_backward_compatible_exit);
  49. MODULE_AUTHOR("Weiyi Lu");
  50. MODULE_DESCRIPTION("A backward compatible Thermal governor");
  51. MODULE_LICENSE("GPL");