backward_compatible.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Copyright (C) 2015 MediaTek Inc.
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  14. #include <linux/module.h>
  15. #include <linux/thermal.h>
  16. #include "thermal_core.h"
  17. /**
  18. * backward_compatible_throttle
  19. * @tz - thermal_zone_device
  20. *
  21. * This function update the cooler state by monitoring the current
  22. * temperature and trip points
  23. */
  24. static int backward_compatible_throttle(struct thermal_zone_device *tz,
  25. int trip)
  26. {
  27. int trip_temp;
  28. struct thermal_instance *instance;
  29. if (trip == THERMAL_TRIPS_NONE)
  30. trip_temp = tz->forced_passive;
  31. else
  32. tz->ops->get_trip_temp(tz, trip, &trip_temp);
  33. list_for_each_entry(instance, &tz->thermal_instances, tz_node) {
  34. if (instance->trip != trip)
  35. continue;
  36. if (tz->temperature >= trip_temp)
  37. instance->target = 1;
  38. else
  39. instance->target = 0;
  40. instance->cdev->updated = false;
  41. thermal_cdev_update(instance->cdev);
  42. }
  43. return 0;
  44. }
  45. static struct thermal_governor thermal_gov_backward_compatible = {
  46. .name = "backward_compatible",
  47. .throttle = backward_compatible_throttle,
  48. };
  49. static int __init thermal_gov_backward_compatible_init(void)
  50. {
  51. return thermal_register_governor(&thermal_gov_backward_compatible);
  52. }
  53. static void __exit thermal_gov_backward_compatible_exit(void)
  54. {
  55. thermal_unregister_governor(&thermal_gov_backward_compatible);
  56. }
  57. /* This should load after thermal framework */
  58. fs_initcall(thermal_gov_backward_compatible_init);
  59. module_exit(thermal_gov_backward_compatible_exit);
  60. MODULE_AUTHOR("Weiyi Lu");
  61. MODULE_DESCRIPTION("A backward compatible Thermal governor");
  62. MODULE_LICENSE("GPL");