mtk_cooler_kshutdown.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #ifdef pr_fmt
  2. #undef pr_fmt
  3. #endif
  4. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  5. #include <linux/kernel.h>
  6. #include <linux/module.h>
  7. #include <linux/printk.h>
  8. #include <linux/types.h>
  9. #include <linux/kobject.h>
  10. #include "mt-plat/mtk_thermal_monitor.h"
  11. #if 1
  12. #define mtk_cooler_kshutdown_dprintk(fmt, args...) pr_debug("thermal/cooler/kshutdown " fmt, ##args)
  13. #else
  14. #define mtk_cooler_kshutdown_dprintk(fmt, args...)
  15. #endif
  16. #define MAX_NUM_INSTANCE_MTK_COOLER_KSHUTDOWN 3
  17. static struct thermal_cooling_device *cl_kshutdown_dev[MAX_NUM_INSTANCE_MTK_COOLER_KSHUTDOWN] = { 0 };
  18. static unsigned long cl_kshutdown_state[MAX_NUM_INSTANCE_MTK_COOLER_KSHUTDOWN] = { 0 };
  19. static int mtk_cl_kshutdown_get_max_state(struct thermal_cooling_device *cdev, unsigned long *state)
  20. {
  21. *state = 1;
  22. /* mtk_cooler_kshutdown_dprintk("mtk_cl_kshutdown_get_max_state() %s %d\n", cdev->type, *state); */
  23. return 0;
  24. }
  25. static int mtk_cl_kshutdown_get_cur_state(struct thermal_cooling_device *cdev, unsigned long *state)
  26. {
  27. #if 1 /* cannot use this way for now since devdata is used by mtk_thermal_monitor */
  28. *state = *((unsigned long *)cdev->devdata);
  29. #else
  30. *state = cl_kshutdown_state[(int)cdev->type[16]];
  31. #endif
  32. /* mtk_cooler_kshutdown_dprintk("mtk_cl_kshutdown_get_cur_state() %s %d\n", cdev->type, *state); */
  33. return 0;
  34. }
  35. static int mtk_cl_kshutdown_set_cur_state(struct thermal_cooling_device *cdev, unsigned long state)
  36. {
  37. /* mtk_cooler_kshutdown_dprintk("mtk_cl_kshutdown_set_cur_state() %s %d\n", cdev->type, state); */
  38. #if 1
  39. *((unsigned long *)cdev->devdata) = state;
  40. #else
  41. cl_kshutdown_state[(int)cdev->type[16]] = state;
  42. #endif
  43. if (1 == state) {
  44. mtk_cooler_kshutdown_dprintk("%s %s invokes machine_power_off\n", __func__,
  45. cdev->type);
  46. machine_power_off();
  47. }
  48. return 0;
  49. }
  50. /* bind fan callbacks to fan device */
  51. static struct thermal_cooling_device_ops mtk_cl_kshutdown_ops = {
  52. .get_max_state = mtk_cl_kshutdown_get_max_state,
  53. .get_cur_state = mtk_cl_kshutdown_get_cur_state,
  54. .set_cur_state = mtk_cl_kshutdown_set_cur_state,
  55. };
  56. static int mtk_cooler_kshutdown_register_ltf(void)
  57. {
  58. int i;
  59. mtk_cooler_kshutdown_dprintk("register ltf\n");
  60. for (i = MAX_NUM_INSTANCE_MTK_COOLER_KSHUTDOWN; i-- > 0;) {
  61. char temp[20] = { 0 };
  62. sprintf(temp, "mtk-cl-kshutdown%02d", i);
  63. cl_kshutdown_dev[i] = mtk_thermal_cooling_device_register(temp,
  64. (void *)
  65. &cl_kshutdown_state[i],
  66. &mtk_cl_kshutdown_ops);
  67. }
  68. #if 0
  69. cl_kshutdown_dev = mtk_thermal_cooling_device_register("mtk-cl-shutdown",
  70. NULL, &mtk_cl_kshutdown_ops);
  71. #endif
  72. return 0;
  73. }
  74. static void mtk_cooler_kshutdown_unregister_ltf(void)
  75. {
  76. int i;
  77. mtk_cooler_kshutdown_dprintk("unregister ltf\n");
  78. for (i = MAX_NUM_INSTANCE_MTK_COOLER_KSHUTDOWN; i-- > 0;) {
  79. if (cl_kshutdown_dev[i]) {
  80. mtk_thermal_cooling_device_unregister(cl_kshutdown_dev[i]);
  81. cl_kshutdown_dev[i] = NULL;
  82. cl_kshutdown_state[i] = 0;
  83. }
  84. }
  85. #if 0
  86. if (cl_kshutdown_dev) {
  87. mtk_thermal_cooling_device_unregister(cl_kshutdown_dev);
  88. cl_kshutdown_dev = NULL;
  89. }
  90. #endif
  91. }
  92. static int __init mtk_cooler_kshutdown_init(void)
  93. {
  94. int err = 0;
  95. int i;
  96. for (i = MAX_NUM_INSTANCE_MTK_COOLER_KSHUTDOWN; i-- > 0;) {
  97. cl_kshutdown_dev[i] = NULL;
  98. cl_kshutdown_state[i] = 0;
  99. }
  100. /* cl_kshutdown_dev = NULL; */
  101. mtk_cooler_kshutdown_dprintk("init\n");
  102. err = mtk_cooler_kshutdown_register_ltf();
  103. if (err)
  104. goto err_unreg;
  105. return 0;
  106. err_unreg:
  107. mtk_cooler_kshutdown_unregister_ltf();
  108. return err;
  109. }
  110. static void __exit mtk_cooler_kshutdown_exit(void)
  111. {
  112. mtk_cooler_kshutdown_dprintk("exit\n");
  113. mtk_cooler_kshutdown_unregister_ltf();
  114. }
  115. module_init(mtk_cooler_kshutdown_init);
  116. module_exit(mtk_cooler_kshutdown_exit);