perfmgr_touch.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. #include <linux/proc_fs.h>
  2. #include <linux/seq_file.h>
  3. #include <linux/kallsyms.h>
  4. #include <linux/utsname.h>
  5. #include <linux/module.h>
  6. #include <linux/moduleparam.h>
  7. #include <asm/uaccess.h>
  8. #include <linux/printk.h>
  9. #include <linux/string.h>
  10. #include <linux/notifier.h>
  11. #include <linux/slab.h>
  12. #include <linux/kthread.h>
  13. #include <linux/input.h>
  14. #include <linux/platform_device.h>
  15. #include "perfmgr.h"
  16. /*--------------------------------------------*/
  17. #define SEQ_printf(m, x...)\
  18. do {\
  19. if (m)\
  20. seq_printf(m, x);\
  21. else\
  22. pr_emerg(x);\
  23. } while (0)
  24. #undef TAG
  25. #define TAG "[PERFMGR]"
  26. #define MAX_CORE (8)
  27. #define MAX_FREQ (20000000)
  28. struct touch_boost {
  29. spinlock_t touch_lock;
  30. wait_queue_head_t wq;
  31. struct task_struct *thread;
  32. int touch_event;
  33. atomic_t event;
  34. };
  35. /*--------------------------------------------*/
  36. static struct touch_boost tboost;
  37. static int perf_mgr_touch_enable = 1;
  38. static int perf_mgr_touch_core = 1;
  39. static int perf_mgr_touch_freq = 1;
  40. /*--------------------FUNCTION----------------*/
  41. static int tboost_thread(void *ptr)
  42. {
  43. int event, core, freq;
  44. unsigned long flags;
  45. set_user_nice(current, -10);
  46. while (!kthread_should_stop()) {
  47. while (!atomic_read(&tboost.event))
  48. wait_event(tboost.wq, atomic_read(&tboost.event));
  49. atomic_dec(&tboost.event);
  50. spin_lock_irqsave(&tboost.touch_lock, flags);
  51. event = tboost.touch_event;
  52. core = perf_mgr_touch_core;
  53. freq = perf_mgr_touch_freq;
  54. spin_unlock_irqrestore(&tboost.touch_lock, flags);
  55. #ifdef MTK_BOOST_SUPPORT
  56. perfmgr_boost(event, core, freq);
  57. #endif
  58. }
  59. return 0;
  60. }
  61. static ssize_t perfmgr_tb_enable_write(struct file *filp, const char *ubuf,
  62. size_t cnt, loff_t *data)
  63. {
  64. char buf[64];
  65. unsigned long val;
  66. int ret;
  67. unsigned long flags;
  68. if (cnt >= sizeof(buf))
  69. return -EINVAL;
  70. if (copy_from_user(&buf, ubuf, cnt))
  71. return -EFAULT;
  72. buf[cnt] = 0;
  73. ret = kstrtoul(buf, 10, &val);
  74. if (ret < 0)
  75. return ret;
  76. if (val > 1)
  77. return -1;
  78. spin_lock_irqsave(&tboost.touch_lock, flags);
  79. perf_mgr_touch_enable = val;
  80. spin_unlock_irqrestore(&tboost.touch_lock, flags);
  81. return cnt;
  82. }
  83. static int perfmgr_tb_enable_show(struct seq_file *m, void *v)
  84. {
  85. SEQ_printf(m, "%d\n", perf_mgr_touch_enable);
  86. return 0;
  87. }
  88. static int perfmgr_tb_enable_open(struct inode *inode, struct file *file)
  89. {
  90. return single_open(file, perfmgr_tb_enable_show, inode->i_private);
  91. }
  92. static const struct file_operations perfmgr_tb_enable_fops = {
  93. .open = perfmgr_tb_enable_open,
  94. .write = perfmgr_tb_enable_write,
  95. .read = seq_read,
  96. .llseek = seq_lseek,
  97. .release = single_release,
  98. };
  99. static ssize_t perfmgr_tb_core_write(struct file *filp, const char *ubuf,
  100. size_t cnt, loff_t *data)
  101. {
  102. char buf[64];
  103. unsigned long val;
  104. int ret;
  105. unsigned long flags;
  106. if (cnt >= sizeof(buf))
  107. return -EINVAL;
  108. if (copy_from_user(&buf, ubuf, cnt))
  109. return -EFAULT;
  110. buf[cnt] = 0;
  111. ret = kstrtoul(buf, 10, &val);
  112. if (ret < 0)
  113. return ret;
  114. if (val > MAX_CORE)
  115. return -1;
  116. spin_lock_irqsave(&tboost.touch_lock, flags);
  117. perf_mgr_touch_core = val;
  118. spin_unlock_irqrestore(&tboost.touch_lock, flags);
  119. return cnt;
  120. }
  121. static int perfmgr_tb_core_show(struct seq_file *m, void *v)
  122. {
  123. SEQ_printf(m, "%d\n", perf_mgr_touch_core);
  124. return 0;
  125. }
  126. static int perfmgr_tb_core_open(struct inode *inode, struct file *file)
  127. {
  128. return single_open(file, perfmgr_tb_core_show, inode->i_private);
  129. }
  130. static const struct file_operations perfmgr_tb_core_fops = {
  131. .open = perfmgr_tb_core_open,
  132. .write = perfmgr_tb_core_write,
  133. .read = seq_read,
  134. .llseek = seq_lseek,
  135. .release = single_release,
  136. };
  137. static ssize_t perfmgr_tb_freq_write(struct file *filp, const char *ubuf,
  138. size_t cnt, loff_t *data)
  139. {
  140. char buf[64];
  141. unsigned long val;
  142. int ret;
  143. unsigned long flags;
  144. if (cnt >= sizeof(buf))
  145. return -EINVAL;
  146. if (copy_from_user(&buf, ubuf, cnt))
  147. return -EFAULT;
  148. buf[cnt] = 0;
  149. ret = kstrtoul(buf, 10, &val);
  150. if (ret < 0)
  151. return ret;
  152. if (val > MAX_FREQ)
  153. return -1;
  154. spin_lock_irqsave(&tboost.touch_lock, flags);
  155. perf_mgr_touch_freq = val;
  156. spin_unlock_irqrestore(&tboost.touch_lock, flags);
  157. return cnt;
  158. }
  159. static int perfmgr_tb_freq_show(struct seq_file *m, void *v)
  160. {
  161. SEQ_printf(m, "%d\n", perf_mgr_touch_freq);
  162. return 0;
  163. }
  164. static int perfmgr_tb_freq_open(struct inode *inode, struct file *file)
  165. {
  166. return single_open(file, perfmgr_tb_freq_show, inode->i_private);
  167. }
  168. static const struct file_operations perfmgr_tb_freq_fops = {
  169. .open = perfmgr_tb_freq_open,
  170. .write = perfmgr_tb_freq_write,
  171. .read = seq_read,
  172. .llseek = seq_lseek,
  173. .release = single_release,
  174. };
  175. static void dbs_input_event(struct input_handle *handle, unsigned int type,
  176. unsigned int code, int value)
  177. {
  178. unsigned long flags;
  179. if (!perf_mgr_touch_enable)
  180. return;
  181. if ((type == EV_KEY) && (code == BTN_TOUCH)) {
  182. pr_debug(TAG"input cb, type:%d, code:%d, value:%d\n", type, code, value);
  183. spin_lock_irqsave(&tboost.touch_lock, flags);
  184. tboost.touch_event = value;
  185. spin_unlock_irqrestore(&tboost.touch_lock, flags);
  186. atomic_inc(&tboost.event);
  187. wake_up(&tboost.wq);
  188. }
  189. }
  190. static int dbs_input_connect(struct input_handler *handler,
  191. struct input_dev *dev, const struct input_device_id *id)
  192. {
  193. struct input_handle *handle;
  194. int error;
  195. handle = kzalloc(sizeof(struct input_handle), GFP_KERNEL);
  196. if (!handle)
  197. return -ENOMEM;
  198. handle->dev = dev;
  199. handle->handler = handler;
  200. handle->name = "perfmgr";
  201. error = input_register_handle(handle);
  202. if (error)
  203. goto err2;
  204. error = input_open_device(handle);
  205. if (error)
  206. goto err1;
  207. return 0;
  208. err1:
  209. input_unregister_handle(handle);
  210. err2:
  211. kfree(handle);
  212. return error;
  213. }
  214. static void dbs_input_disconnect(struct input_handle *handle)
  215. {
  216. input_close_device(handle);
  217. input_unregister_handle(handle);
  218. kfree(handle);
  219. }
  220. static const struct input_device_id dbs_ids[] = {
  221. {.driver_info = 1},
  222. {},
  223. };
  224. static struct input_handler dbs_input_handler = {
  225. .event = dbs_input_event,
  226. .connect = dbs_input_connect,
  227. .disconnect = dbs_input_disconnect,
  228. .name = "cpufreq_ond",
  229. .id_table = dbs_ids,
  230. };
  231. /*--------------------INIT------------------------*/
  232. int init_perfmgr_touch(void)
  233. {
  234. struct proc_dir_entry *touch_dir = NULL;
  235. int handle;
  236. #ifdef MTK_BOOST_SUPPORT
  237. perf_mgr_touch_core = perfmgr_get_target_core();
  238. perf_mgr_touch_freq = perfmgr_get_target_freq();
  239. #endif
  240. touch_dir = proc_mkdir("perfmgr/touch", NULL);
  241. /* touch */
  242. proc_create("tb_enable", 0644, touch_dir, &perfmgr_tb_enable_fops);
  243. proc_create("tb_core", 0644, touch_dir, &perfmgr_tb_core_fops);
  244. proc_create("tb_freq", 0644, touch_dir, &perfmgr_tb_freq_fops);
  245. spin_lock_init(&tboost.touch_lock);
  246. init_waitqueue_head(&tboost.wq);
  247. atomic_set(&tboost.event, 0);
  248. tboost.thread = (struct task_struct *)kthread_run(tboost_thread, &tboost, "touch_boost");
  249. if (IS_ERR(tboost.thread))
  250. return -EINVAL;
  251. handle = input_register_handler(&dbs_input_handler);
  252. return 0;
  253. }
  254. int perfmgr_touch_suspend(void)
  255. {
  256. /*pr_debug(TAG"perfmgr_touch_suspend\n");*/
  257. #ifdef MTK_BOOST_SUPPORT
  258. perfmgr_boost(0, 0, 0);
  259. #endif
  260. return 0;
  261. }
  262. /*MODULE_LICENSE("GPL");*/
  263. /*MODULE_AUTHOR("MTK");*/
  264. /*MODULE_DESCRIPTION("The fliper function");*/