mtk_cooler_cam.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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_CAM 1
  16. #if 1
  17. #define mtk_cooler_cam_dprintk(fmt, args...) pr_debug("thermal/cooler/cam " fmt, ##args)
  18. #else
  19. #define mtk_cooler_cam_dprintk(fmt, args...)
  20. #endif
  21. static struct thermal_cooling_device *cl_cam_dev[MAX_NUM_INSTANCE_MTK_COOLER_CAM] = { 0 };
  22. static unsigned long cl_cam_state[MAX_NUM_INSTANCE_MTK_COOLER_CAM] = { 0 };
  23. static unsigned int _cl_cam;
  24. #define MAX_LEN (256)
  25. static ssize_t _cl_cam_write(struct file *filp, const char __user *buf, size_t len, loff_t *data)
  26. {
  27. int ret = 0;
  28. char tmp[MAX_LEN] = { 0 };
  29. len = (len < (MAX_LEN - 1)) ? len : (MAX_LEN - 1);
  30. /* write data to the buffer */
  31. if (copy_from_user(tmp, buf, len))
  32. return -EFAULT;
  33. ret = kstrtouint(tmp, 10, &_cl_cam);
  34. if (ret)
  35. WARN_ON(1);
  36. mtk_cooler_cam_dprintk("%s %s = %d\n", __func__, tmp, _cl_cam);
  37. return len;
  38. }
  39. static int _cl_cam_read(struct seq_file *m, void *v)
  40. {
  41. seq_printf(m, "%d\n", _cl_cam);
  42. mtk_cooler_cam_dprintk("%s %d\n", __func__, _cl_cam);
  43. return 0;
  44. }
  45. static int _cl_cam_open(struct inode *inode, struct file *file)
  46. {
  47. return single_open(file, _cl_cam_read, PDE_DATA(inode));
  48. }
  49. static const struct file_operations _cl_cam_fops = {
  50. .owner = THIS_MODULE,
  51. .open = _cl_cam_open,
  52. .read = seq_read,
  53. .llseek = seq_lseek,
  54. .write = _cl_cam_write,
  55. .release = single_release,
  56. };
  57. static int mtk_cl_cam_get_max_state(struct thermal_cooling_device *cdev, unsigned long *state)
  58. {
  59. *state = 1;
  60. /* mtk_cooler_cam_dprintk("mtk_cl_cam_get_max_state() %s %d\n", cdev->type, *state); */
  61. return 0;
  62. }
  63. static int mtk_cl_cam_get_cur_state(struct thermal_cooling_device *cdev, unsigned long *state)
  64. {
  65. *state = *((unsigned long *)cdev->devdata);
  66. /* mtk_cooler_cam_dprintk("mtk_cl_cam_get_cur_state() %s %d\n", cdev->type, *state); */
  67. return 0;
  68. }
  69. static int mtk_cl_cam_set_cur_state(struct thermal_cooling_device *cdev, unsigned long state)
  70. {
  71. /* mtk_cooler_cam_dprintk("mtk_cl_cam_set_cur_state() %s %d\n", cdev->type, state); */
  72. *((unsigned long *)cdev->devdata) = state;
  73. if (1 == state)
  74. _cl_cam = 1;
  75. else
  76. _cl_cam = 0;
  77. return 0;
  78. }
  79. /* bind fan callbacks to fan device */
  80. static struct thermal_cooling_device_ops mtk_cl_cam_ops = {
  81. .get_max_state = mtk_cl_cam_get_max_state,
  82. .get_cur_state = mtk_cl_cam_get_cur_state,
  83. .set_cur_state = mtk_cl_cam_set_cur_state,
  84. };
  85. static int mtk_cooler_cam_register_ltf(void)
  86. {
  87. int i;
  88. mtk_cooler_cam_dprintk("register ltf\n");
  89. for (i = MAX_NUM_INSTANCE_MTK_COOLER_CAM; i-- > 0;) {
  90. char temp[20] = { 0 };
  91. sprintf(temp, "mtk-cl-cam%02d", i);
  92. cl_cam_dev[i] = mtk_thermal_cooling_device_register(temp,
  93. (void *)&cl_cam_state[i],
  94. &mtk_cl_cam_ops);
  95. }
  96. return 0;
  97. }
  98. static void mtk_cooler_cam_unregister_ltf(void)
  99. {
  100. int i;
  101. mtk_cooler_cam_dprintk("unregister ltf\n");
  102. for (i = MAX_NUM_INSTANCE_MTK_COOLER_CAM; i-- > 0;) {
  103. if (cl_cam_dev[i]) {
  104. mtk_thermal_cooling_device_unregister(cl_cam_dev[i]);
  105. cl_cam_dev[i] = NULL;
  106. cl_cam_state[i] = 0;
  107. }
  108. }
  109. }
  110. static int __init mtk_cooler_cam_init(void)
  111. {
  112. int err = 0;
  113. int i;
  114. for (i = MAX_NUM_INSTANCE_MTK_COOLER_CAM; i-- > 0;) {
  115. cl_cam_dev[i] = NULL;
  116. cl_cam_state[i] = 0;
  117. }
  118. mtk_cooler_cam_dprintk("init\n");
  119. {
  120. struct proc_dir_entry *entry;
  121. #if 0
  122. entry = create_proc_entry("driver/cl_cam", S_IRUGO | S_IWUSR, NULL);
  123. if (NULL != entry) {
  124. entry->read_proc = _cl_cam_read;
  125. entry->write_proc = _cl_cam_write;
  126. }
  127. #endif
  128. entry = proc_create("driver/cl_cam", S_IRUGO | S_IWUSR, NULL, &_cl_cam_fops);
  129. if (!entry)
  130. mtk_cooler_cam_dprintk("%s driver/cl_cam creation failed\n", __func__);
  131. }
  132. err = mtk_cooler_cam_register_ltf();
  133. if (err)
  134. goto err_unreg;
  135. return 0;
  136. err_unreg:
  137. mtk_cooler_cam_unregister_ltf();
  138. return err;
  139. }
  140. static void __exit mtk_cooler_cam_exit(void)
  141. {
  142. mtk_cooler_cam_dprintk("exit\n");
  143. mtk_cooler_cam_unregister_ltf();
  144. }
  145. module_init(mtk_cooler_cam_init);
  146. module_exit(mtk_cooler_cam_exit);