mtk_cooler_vrt.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. #ifdef pr_fmt
  2. #undef pr_fmt
  3. #endif
  4. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  5. #include <linux/version.h>
  6. #include <linux/kernel.h>
  7. #include <linux/module.h>
  8. #include <linux/printk.h>
  9. #include <linux/types.h>
  10. #include <linux/kobject.h>
  11. #include <linux/proc_fs.h>
  12. #include <linux/seq_file.h>
  13. #include <asm/uaccess.h>
  14. #include "mt-plat/mtk_thermal_monitor.h"
  15. #define MAX_NUM_INSTANCE_MTK_COOLER_VRT 1
  16. #if 1
  17. #define mtk_cooler_vrt_dprintk(fmt, args...) \
  18. pr_debug("thermal/cooler/vrt " fmt, ##args)
  19. #else
  20. #define mtk_cooler_vrt_dprintk(fmt, args...)
  21. #endif
  22. static struct thermal_cooling_device *cl_vrt_dev[MAX_NUM_INSTANCE_MTK_COOLER_VRT] = { 0 };
  23. static unsigned long cl_vrt_state[MAX_NUM_INSTANCE_MTK_COOLER_VRT] = { 0 };
  24. static unsigned int _cl_vrt;
  25. #define MAX_LEN (256)
  26. static ssize_t _cl_vrt_write(struct file *filp, const char __user *buf, size_t len, loff_t *data)
  27. {
  28. int ret = 0;
  29. char tmp[MAX_LEN] = { 0 };
  30. len = (len < (MAX_LEN - 1)) ? len : (MAX_LEN - 1);
  31. /* write data to the buffer */
  32. if (copy_from_user(tmp, buf, len))
  33. return -EFAULT;
  34. ret = kstrtouint(tmp, 10, &_cl_vrt);
  35. if (ret)
  36. WARN_ON(1);
  37. mtk_cooler_vrt_dprintk("%s %s = %d\n", __func__, tmp, _cl_vrt);
  38. return len;
  39. }
  40. static int _cl_vrt_read(struct seq_file *m, void *v)
  41. {
  42. seq_printf(m, "%d\n", _cl_vrt);
  43. mtk_cooler_vrt_dprintk("%s %d\n", __func__, _cl_vrt);
  44. return 0;
  45. }
  46. static int _cl_vrt_open(struct inode *inode, struct file *file)
  47. {
  48. return single_open(file, _cl_vrt_read, PDE_DATA(inode));
  49. }
  50. static const struct file_operations _cl_vrt_fops = {
  51. .owner = THIS_MODULE,
  52. .open = _cl_vrt_open,
  53. .read = seq_read,
  54. .llseek = seq_lseek,
  55. .write = _cl_vrt_write,
  56. .release = single_release,
  57. };
  58. static int mtk_cl_vrt_get_max_state(struct thermal_cooling_device *cdev, unsigned long *state)
  59. {
  60. *state = 1;
  61. /* mtk_cooler_vrt_dprintk("mtk_cl_vrt_get_max_state() %s %d\n", cdev->type, *state); */
  62. return 0;
  63. }
  64. static int mtk_cl_vrt_get_cur_state(struct thermal_cooling_device *cdev, unsigned long *state)
  65. {
  66. *state = *((unsigned long *)cdev->devdata);
  67. /* mtk_cooler_vrt_dprintk("mtk_cl_vrt_get_cur_state() %s %d\n", cdev->type, *state); */
  68. return 0;
  69. }
  70. static int mtk_cl_vrt_set_cur_state(struct thermal_cooling_device *cdev, unsigned long state)
  71. {
  72. /* mtk_cooler_vrt_dprintk("mtk_cl_vrt_set_cur_state() %s %d\n", cdev->type, state); */
  73. *((unsigned long *)cdev->devdata) = state;
  74. if (1 == state)
  75. _cl_vrt = 1;
  76. else
  77. _cl_vrt = 0;
  78. return 0;
  79. }
  80. /* bind fan callbacks to fan device */
  81. static struct thermal_cooling_device_ops mtk_cl_vrt_ops = {
  82. .get_max_state = mtk_cl_vrt_get_max_state,
  83. .get_cur_state = mtk_cl_vrt_get_cur_state,
  84. .set_cur_state = mtk_cl_vrt_set_cur_state,
  85. };
  86. static int mtk_cooler_vrt_register_ltf(void)
  87. {
  88. int i;
  89. mtk_cooler_vrt_dprintk("register ltf\n");
  90. for (i = MAX_NUM_INSTANCE_MTK_COOLER_VRT; i-- > 0;) {
  91. char temp[20] = { 0 };
  92. sprintf(temp, "mtk-cl-vrt%02d", i);
  93. cl_vrt_dev[i] = mtk_thermal_cooling_device_register(temp,
  94. (void *)&cl_vrt_state[i],
  95. &mtk_cl_vrt_ops);
  96. }
  97. return 0;
  98. }
  99. static void mtk_cooler_vrt_unregister_ltf(void)
  100. {
  101. int i;
  102. mtk_cooler_vrt_dprintk("unregister ltf\n");
  103. for (i = MAX_NUM_INSTANCE_MTK_COOLER_VRT; i-- > 0;) {
  104. if (cl_vrt_dev[i]) {
  105. mtk_thermal_cooling_device_unregister(cl_vrt_dev[i]);
  106. cl_vrt_dev[i] = NULL;
  107. cl_vrt_state[i] = 0;
  108. }
  109. }
  110. }
  111. static int __init mtk_cooler_vrt_init(void)
  112. {
  113. int err = 0;
  114. int i;
  115. for (i = MAX_NUM_INSTANCE_MTK_COOLER_VRT; i-- > 0;) {
  116. cl_vrt_dev[i] = NULL;
  117. cl_vrt_state[i] = 0;
  118. }
  119. mtk_cooler_vrt_dprintk("init\n");
  120. {
  121. struct proc_dir_entry *entry;
  122. #if 0
  123. entry = create_proc_entry("driver/cl_vrt", S_IRUGO | S_IWUSR, NULL);
  124. if (NULL != entry) {
  125. entry->read_proc = _cl_vrt_read;
  126. entry->write_proc = _cl_vrt_write;
  127. }
  128. #endif
  129. entry = proc_create("driver/cl_vrt", S_IRUGO | S_IWUSR, NULL, &_cl_vrt_fops);
  130. if (!entry)
  131. mtk_cooler_vrt_dprintk("%s driver/cl_vrt creation failed\n", __func__);
  132. }
  133. err = mtk_cooler_vrt_register_ltf();
  134. if (err)
  135. goto err_unreg;
  136. return 0;
  137. err_unreg:
  138. mtk_cooler_vrt_unregister_ltf();
  139. return err;
  140. }
  141. static void __exit mtk_cooler_vrt_exit(void)
  142. {
  143. mtk_cooler_vrt_dprintk("exit\n");
  144. mtk_cooler_vrt_unregister_ltf();
  145. }
  146. module_init(mtk_cooler_vrt_init);
  147. module_exit(mtk_cooler_vrt_exit);