mtk_tpd.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  1. /******************************************************************************
  2. * mtk_tpd.c - MTK Android Linux Touch Panel Device Driver *
  3. * *
  4. * Copyright 2008-2009 MediaTek Co.,Ltd. *
  5. * *
  6. * DESCRIPTION: *
  7. * this file provide basic touch panel event to input sub system *
  8. * *
  9. * AUTHOR: *
  10. * Kirby.Wu (mtk02247) *
  11. * *
  12. * NOTE: *
  13. * 1. Sensitivity for touch screen should be set to edge-sensitive. *
  14. * But in this driver it is assumed to be done by interrupt core, *
  15. * though not done yet. Interrupt core may provide interface to *
  16. * let drivers set the sensitivity in the future. In this case, *
  17. * this driver should set the sensitivity of the corresponding IRQ *
  18. * line itself. *
  19. ******************************************************************************/
  20. #include "tpd.h"
  21. #include <linux/slab.h>
  22. #include <linux/device.h>
  23. #include <linux/miscdevice.h>
  24. #include <linux/device.h>
  25. #include <linux/slab.h>
  26. #include <linux/uaccess.h>
  27. #include <linux/fb.h>
  28. #ifdef CONFIG_COMPAT
  29. #include <linux/compat.h>
  30. #endif
  31. #if defined(CONFIG_MTK_S3320) || defined(CONFIG_MTK_S3320_50) \
  32. || defined(CONFIG_MTK_S3320_47) || defined(CONFIG_MTK_MIT200) \
  33. || defined(CONFIG_TOUCHSCREEN_SYNAPTICS_S3528) || defined(CONFIG_MTK_S7020)
  34. #include <linux/input/mt.h>
  35. #endif /* CONFIG_MTK_S3320 */
  36. /* for magnify velocity******************************************** */
  37. #define TOUCH_IOC_MAGIC 'A'
  38. #define TPD_GET_VELOCITY_CUSTOM_X _IO(TOUCH_IOC_MAGIC, 0)
  39. #define TPD_GET_VELOCITY_CUSTOM_Y _IO(TOUCH_IOC_MAGIC, 1)
  40. #define TPD_GET_FILTER_PARA _IOWR(TOUCH_IOC_MAGIC, 2, struct tpd_filter_t)
  41. #ifdef CONFIG_COMPAT
  42. #define COMPAT_TPD_GET_FILTER_PARA _IOWR(TOUCH_IOC_MAGIC, 2, struct tpd_filter_t)
  43. #endif
  44. struct tpd_filter_t tpd_filter;
  45. struct tpd_dts_info tpd_dts_data;
  46. struct pinctrl *pinctrl1;
  47. struct pinctrl_state *pins_default;
  48. struct pinctrl_state *eint_as_int, *eint_output0, *eint_output1, *rst_output0, *rst_output1;
  49. struct of_device_id touch_of_match[] = {
  50. { .compatible = "mediatek,mt6735-touch", },
  51. { .compatible = "mediatek,mt6580-touch", },
  52. { .compatible = "mediatek,mt8173-touch", },
  53. { .compatible = "mediatek,mt6755-touch", },
  54. { .compatible = "mediatek,mt6797-touch", },
  55. { .compatible = "mediatek,mt8163-touch", },
  56. {},
  57. };
  58. void tpd_get_dts_info(void)
  59. {
  60. struct device_node *node1 = NULL;
  61. int key_dim_local[16], i;
  62. node1 = of_find_matching_node(node1, touch_of_match);
  63. if (node1) {
  64. of_property_read_u32(node1, "tpd-key-dim-local", &tpd_dts_data.touch_max_num);
  65. of_property_read_u32(node1, "use-tpd-button", &tpd_dts_data.use_tpd_button);
  66. pr_info("[tpd]use-tpd-button = %d\n", tpd_dts_data.use_tpd_button);
  67. of_property_read_u32_array(node1, "tpd-resolution",
  68. tpd_dts_data.tpd_resolution, ARRAY_SIZE(tpd_dts_data.tpd_resolution));
  69. of_property_read_u32_array(node1, "tpd-convert-ratio",
  70. tpd_dts_data.tpd_convert_ratio, ARRAY_SIZE(tpd_dts_data.tpd_convert_ratio));
  71. if (tpd_dts_data.use_tpd_button) {
  72. of_property_read_u32(node1, "tpd-key-num", &tpd_dts_data.tpd_key_num);
  73. of_property_read_u32_array(node1, "tpd-key-local",
  74. tpd_dts_data.tpd_key_local, ARRAY_SIZE(tpd_dts_data.tpd_key_local));
  75. of_property_read_u32_array(node1, "tpd-key-dim-local",
  76. key_dim_local, ARRAY_SIZE(key_dim_local));
  77. memcpy(tpd_dts_data.tpd_key_dim_local, key_dim_local, sizeof(key_dim_local));
  78. for (i = 0; i < 4; i++) {
  79. pr_info("[tpd]key[%d].key_x = %d\n", i, tpd_dts_data.tpd_key_dim_local[i].key_x);
  80. pr_info("[tpd]key[%d].key_y = %d\n", i, tpd_dts_data.tpd_key_dim_local[i].key_y);
  81. pr_info("[tpd]key[%d].key_W = %d\n", i, tpd_dts_data.tpd_key_dim_local[i].key_width);
  82. pr_info("[tpd]key[%d].key_H = %d\n", i, tpd_dts_data.tpd_key_dim_local[i].key_height);
  83. }
  84. }
  85. of_property_read_u32(node1, "tpd-filter-enable", &tpd_dts_data.touch_filter.enable);
  86. if (tpd_dts_data.touch_filter.enable) {
  87. of_property_read_u32(node1, "tpd-filter-pixel-density",
  88. &tpd_dts_data.touch_filter.pixel_density);
  89. of_property_read_u32_array(node1, "tpd-filter-custom-prameters",
  90. (u32 *)tpd_dts_data.touch_filter.W_W, ARRAY_SIZE(tpd_dts_data.touch_filter.W_W));
  91. of_property_read_u32_array(node1, "tpd-filter-custom-speed",
  92. tpd_dts_data.touch_filter.VECLOCITY_THRESHOLD,
  93. ARRAY_SIZE(tpd_dts_data.touch_filter.VECLOCITY_THRESHOLD));
  94. }
  95. memcpy(&tpd_filter, &tpd_dts_data.touch_filter, sizeof(tpd_filter));
  96. pr_info("[tpd]tpd-filter-enable = %d, pixel_density = %d\n",
  97. tpd_filter.enable, tpd_filter.pixel_density);
  98. } else {
  99. pr_err("[tpd]%s can't find touch compatible custom node\n", __func__);
  100. }
  101. }
  102. static DEFINE_MUTEX(tpd_set_gpio_mutex);
  103. void tpd_gpio_as_int(int pin)
  104. {
  105. mutex_lock(&tpd_set_gpio_mutex);
  106. TPD_DEBUG("[tpd]tpd_gpio_as_int\n");
  107. if (pin == 1)
  108. pinctrl_select_state(pinctrl1, eint_as_int);
  109. mutex_unlock(&tpd_set_gpio_mutex);
  110. }
  111. void tpd_gpio_output(int pin, int level)
  112. {
  113. mutex_lock(&tpd_set_gpio_mutex);
  114. TPD_DEBUG("[tpd]tpd_gpio_output pin = %d, level = %d\n", pin, level);
  115. if (pin == 1) {
  116. if (level)
  117. pinctrl_select_state(pinctrl1, eint_output1);
  118. else
  119. pinctrl_select_state(pinctrl1, eint_output0);
  120. } else {
  121. if (level)
  122. pinctrl_select_state(pinctrl1, rst_output1);
  123. else
  124. pinctrl_select_state(pinctrl1, rst_output0);
  125. }
  126. mutex_unlock(&tpd_set_gpio_mutex);
  127. }
  128. int tpd_get_gpio_info(struct platform_device *pdev)
  129. {
  130. int ret;
  131. TPD_DEBUG("[tpd %d] mt_tpd_pinctrl+++++++++++++++++\n", pdev->id);
  132. pinctrl1 = devm_pinctrl_get(&pdev->dev);
  133. if (IS_ERR(pinctrl1)) {
  134. ret = PTR_ERR(pinctrl1);
  135. dev_err(&pdev->dev, "fwq Cannot find touch pinctrl1!\n");
  136. return ret;
  137. }
  138. pins_default = pinctrl_lookup_state(pinctrl1, "default");
  139. if (IS_ERR(pins_default)) {
  140. ret = PTR_ERR(pins_default);
  141. dev_err(&pdev->dev, "fwq Cannot find touch pinctrl default %d!\n", ret);
  142. }
  143. eint_as_int = pinctrl_lookup_state(pinctrl1, "state_eint_as_int");
  144. if (IS_ERR(eint_as_int)) {
  145. ret = PTR_ERR(eint_as_int);
  146. dev_err(&pdev->dev, "fwq Cannot find touch pinctrl state_eint_as_int!\n");
  147. return ret;
  148. }
  149. eint_output0 = pinctrl_lookup_state(pinctrl1, "state_eint_output0");
  150. if (IS_ERR(eint_output0)) {
  151. ret = PTR_ERR(eint_output0);
  152. dev_err(&pdev->dev, "fwq Cannot find touch pinctrl state_eint_output0!\n");
  153. return ret;
  154. }
  155. eint_output1 = pinctrl_lookup_state(pinctrl1, "state_eint_output1");
  156. if (IS_ERR(eint_output1)) {
  157. ret = PTR_ERR(eint_output1);
  158. dev_err(&pdev->dev, "fwq Cannot find touch pinctrl state_eint_output1!\n");
  159. return ret;
  160. }
  161. rst_output0 = pinctrl_lookup_state(pinctrl1, "state_rst_output0");
  162. if (IS_ERR(rst_output0)) {
  163. ret = PTR_ERR(rst_output0);
  164. dev_err(&pdev->dev, "fwq Cannot find touch pinctrl state_rst_output0!\n");
  165. return ret;
  166. }
  167. rst_output1 = pinctrl_lookup_state(pinctrl1, "state_rst_output1");
  168. if (IS_ERR(rst_output1)) {
  169. ret = PTR_ERR(rst_output1);
  170. dev_err(&pdev->dev, "fwq Cannot find touch pinctrl state_rst_output1!\n");
  171. return ret;
  172. }
  173. TPD_DEBUG("[tpd%d] mt_tpd_pinctrl----------\n", pdev->id);
  174. return 0;
  175. }
  176. static int tpd_misc_open(struct inode *inode, struct file *file)
  177. {
  178. return nonseekable_open(inode, file);
  179. }
  180. static int tpd_misc_release(struct inode *inode, struct file *file)
  181. {
  182. return 0;
  183. }
  184. #ifdef CONFIG_COMPAT
  185. static long tpd_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  186. {
  187. long ret;
  188. void __user *arg32 = compat_ptr(arg);
  189. if (!file->f_op || !file->f_op->unlocked_ioctl)
  190. return -ENOTTY;
  191. switch (cmd) {
  192. case COMPAT_TPD_GET_FILTER_PARA:
  193. if (arg32 == NULL) {
  194. pr_err("invalid argument.");
  195. return -EINVAL;
  196. }
  197. ret = file->f_op->unlocked_ioctl(file, TPD_GET_FILTER_PARA,
  198. (unsigned long)arg32);
  199. if (ret) {
  200. pr_err("TPD_GET_FILTER_PARA unlocked_ioctl failed.");
  201. return ret;
  202. }
  203. break;
  204. default:
  205. pr_err("tpd: unknown IOCTL: 0x%08x\n", cmd);
  206. ret = -ENOIOCTLCMD;
  207. break;
  208. }
  209. return ret;
  210. }
  211. #endif
  212. static long tpd_unlocked_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  213. {
  214. /* char strbuf[256]; */
  215. void __user *data;
  216. long err = 0;
  217. if (_IOC_DIR(cmd) & _IOC_READ)
  218. err = !access_ok(VERIFY_WRITE, (void __user *)arg, _IOC_SIZE(cmd));
  219. else if (_IOC_DIR(cmd) & _IOC_WRITE)
  220. err = !access_ok(VERIFY_READ, (void __user *)arg, _IOC_SIZE(cmd));
  221. if (err) {
  222. pr_err("tpd: access error: %08X, (%2d, %2d)\n", cmd, _IOC_DIR(cmd), _IOC_SIZE(cmd));
  223. return -EFAULT;
  224. }
  225. switch (cmd) {
  226. case TPD_GET_VELOCITY_CUSTOM_X:
  227. data = (void __user *)arg;
  228. if (data == NULL) {
  229. err = -EINVAL;
  230. break;
  231. }
  232. if (copy_to_user(data, &tpd_v_magnify_x, sizeof(tpd_v_magnify_x))) {
  233. err = -EFAULT;
  234. break;
  235. }
  236. break;
  237. case TPD_GET_VELOCITY_CUSTOM_Y:
  238. data = (void __user *)arg;
  239. if (data == NULL) {
  240. err = -EINVAL;
  241. break;
  242. }
  243. if (copy_to_user(data, &tpd_v_magnify_y, sizeof(tpd_v_magnify_y))) {
  244. err = -EFAULT;
  245. break;
  246. }
  247. break;
  248. case TPD_GET_FILTER_PARA:
  249. data = (void __user *) arg;
  250. if (data == NULL) {
  251. err = -EINVAL;
  252. pr_err("tpd: TPD_GET_FILTER_PARA IOCTL CMD: data is null\n");
  253. break;
  254. }
  255. if (copy_to_user(data, &tpd_filter, sizeof(struct tpd_filter_t))) {
  256. pr_err("tpd: TPD_GET_FILTER_PARA IOCTL CMD: copy data error\n");
  257. err = -EFAULT;
  258. break;
  259. }
  260. break;
  261. default:
  262. pr_err("tpd: unknown IOCTL: 0x%08x\n", cmd);
  263. err = -ENOIOCTLCMD;
  264. break;
  265. }
  266. return err;
  267. }
  268. static struct work_struct touch_resume_work;
  269. static struct workqueue_struct *touch_resume_workqueue;
  270. static const struct file_operations tpd_fops = {
  271. /* .owner = THIS_MODULE, */
  272. .open = tpd_misc_open,
  273. .release = tpd_misc_release,
  274. .unlocked_ioctl = tpd_unlocked_ioctl,
  275. #ifdef CONFIG_COMPAT
  276. .compat_ioctl = tpd_compat_ioctl,
  277. #endif
  278. };
  279. /*----------------------------------------------------------------------------*/
  280. static struct miscdevice tpd_misc_device = {
  281. .minor = MISC_DYNAMIC_MINOR,
  282. .name = "touch",
  283. .fops = &tpd_fops,
  284. };
  285. /* ********************************************** */
  286. /* #endif */
  287. /* function definitions */
  288. static int __init tpd_device_init(void);
  289. static void __exit tpd_device_exit(void);
  290. static int tpd_probe(struct platform_device *pdev);
  291. static int tpd_remove(struct platform_device *pdev);
  292. static int tpd_suspend_flag;
  293. int tpd_register_flag = 0;
  294. /* global variable definitions */
  295. struct tpd_device *tpd = 0;
  296. static struct tpd_driver_t tpd_driver_list[TP_DRV_MAX_COUNT]; /* = {0}; */
  297. struct platform_device tpd_device = {
  298. .name = TPD_DEVICE,
  299. .id = -1,
  300. };
  301. const struct dev_pm_ops tpd_pm_ops = {
  302. .suspend = NULL,
  303. .resume = NULL,
  304. };
  305. static struct platform_driver tpd_driver = {
  306. .remove = tpd_remove,
  307. .shutdown = NULL,
  308. .probe = tpd_probe,
  309. .driver = {
  310. .name = TPD_DEVICE,
  311. .pm = &tpd_pm_ops,
  312. .owner = THIS_MODULE,
  313. .of_match_table = touch_of_match,
  314. },
  315. };
  316. static struct tpd_driver_t *g_tpd_drv;
  317. /* hh: use fb_notifier */
  318. static struct notifier_block tpd_fb_notifier;
  319. /* use fb_notifier */
  320. static void touch_resume_workqueue_callback(struct work_struct *work)
  321. {
  322. TPD_DEBUG("GTP touch_resume_workqueue_callback\n");
  323. g_tpd_drv->resume(NULL);
  324. tpd_suspend_flag = 0;
  325. }
  326. static int tpd_fb_notifier_callback(struct notifier_block *self, unsigned long event, void *data)
  327. {
  328. struct fb_event *evdata = NULL;
  329. int blank;
  330. int err = 0;
  331. TPD_DEBUG("tpd_fb_notifier_callback\n");
  332. evdata = data;
  333. /* If we aren't interested in this event, skip it immediately ... */
  334. if (event != FB_EVENT_BLANK)
  335. return 0;
  336. blank = *(int *)evdata->data;
  337. TPD_DMESG("fb_notify(blank=%d)\n", blank);
  338. switch (blank) {
  339. case FB_BLANK_UNBLANK:
  340. TPD_DMESG("LCD ON Notify\n");
  341. if (g_tpd_drv && tpd_suspend_flag) {
  342. err = queue_work(touch_resume_workqueue, &touch_resume_work);
  343. if (!err) {
  344. TPD_DMESG("start touch_resume_workqueue failed\n");
  345. return err;
  346. }
  347. }
  348. break;
  349. case FB_BLANK_POWERDOWN:
  350. TPD_DMESG("LCD OFF Notify\n");
  351. if (g_tpd_drv)
  352. err = cancel_work_sync(&touch_resume_work);
  353. if (!err)
  354. TPD_DMESG("cancel touch_resume_workqueue err = %d\n", err);
  355. g_tpd_drv->suspend(NULL);
  356. tpd_suspend_flag = 1;
  357. break;
  358. default:
  359. break;
  360. }
  361. return 0;
  362. }
  363. /* Add driver: if find TPD_TYPE_CAPACITIVE driver successfully, loading it */
  364. int tpd_driver_add(struct tpd_driver_t *tpd_drv)
  365. {
  366. int i;
  367. if (g_tpd_drv != NULL) {
  368. TPD_DMESG("touch driver exist\n");
  369. return -1;
  370. }
  371. /* check parameter */
  372. if (tpd_drv == NULL)
  373. return -1;
  374. tpd_drv->tpd_have_button = tpd_dts_data.use_tpd_button;
  375. /* R-touch */
  376. if (strcmp(tpd_drv->tpd_device_name, "generic") == 0) {
  377. tpd_driver_list[0].tpd_device_name = tpd_drv->tpd_device_name;
  378. tpd_driver_list[0].tpd_local_init = tpd_drv->tpd_local_init;
  379. tpd_driver_list[0].suspend = tpd_drv->suspend;
  380. tpd_driver_list[0].resume = tpd_drv->resume;
  381. tpd_driver_list[0].tpd_have_button = tpd_drv->tpd_have_button;
  382. return 0;
  383. }
  384. for (i = 1; i < TP_DRV_MAX_COUNT; i++) {
  385. /* add tpd driver into list */
  386. if (tpd_driver_list[i].tpd_device_name == NULL) {
  387. tpd_driver_list[i].tpd_device_name = tpd_drv->tpd_device_name;
  388. tpd_driver_list[i].tpd_local_init = tpd_drv->tpd_local_init;
  389. tpd_driver_list[i].suspend = tpd_drv->suspend;
  390. tpd_driver_list[i].resume = tpd_drv->resume;
  391. tpd_driver_list[i].tpd_have_button = tpd_drv->tpd_have_button;
  392. tpd_driver_list[i].attrs = tpd_drv->attrs;
  393. #if 0
  394. if (tpd_drv->tpd_local_init() == 0) {
  395. TPD_DMESG("load %s successfully\n",
  396. tpd_driver_list[i].tpd_device_name);
  397. g_tpd_drv = &tpd_driver_list[i];
  398. }
  399. #endif
  400. break;
  401. }
  402. if (strcmp(tpd_driver_list[i].tpd_device_name, tpd_drv->tpd_device_name) == 0)
  403. return 1; /* driver exist */
  404. }
  405. return 0;
  406. }
  407. int tpd_driver_remove(struct tpd_driver_t *tpd_drv)
  408. {
  409. int i = 0;
  410. /* check parameter */
  411. if (tpd_drv == NULL)
  412. return -1;
  413. for (i = 0; i < TP_DRV_MAX_COUNT; i++) {
  414. /* find it */
  415. if (strcmp(tpd_driver_list[i].tpd_device_name, tpd_drv->tpd_device_name) == 0) {
  416. memset(&tpd_driver_list[i], 0, sizeof(struct tpd_driver_t));
  417. break;
  418. }
  419. }
  420. return 0;
  421. }
  422. static void tpd_create_attributes(struct device *dev, struct tpd_attrs *attrs)
  423. {
  424. int num = attrs->num;
  425. for (; num > 0;)
  426. device_create_file(dev, attrs->attr[--num]);
  427. }
  428. /* touch panel probe */
  429. static int tpd_probe(struct platform_device *pdev)
  430. {
  431. int touch_type = 1; /* 0:R-touch, 1: Cap-touch */
  432. int i = 0;
  433. #ifndef CONFIG_CUSTOM_LCM_X
  434. #ifdef CONFIG_LCM_WIDTH
  435. unsigned long tpd_res_x = 0, tpd_res_y = 0;
  436. int ret = 0;
  437. #endif
  438. #endif
  439. TPD_DMESG("enter %s, %d\n", __func__, __LINE__);
  440. if (misc_register(&tpd_misc_device))
  441. pr_err("mtk_tpd: tpd_misc_device register failed\n");
  442. tpd_get_gpio_info(pdev);
  443. tpd = kmalloc(sizeof(struct tpd_device), GFP_KERNEL);
  444. if (tpd == NULL)
  445. return -ENOMEM;
  446. memset(tpd, 0, sizeof(struct tpd_device));
  447. /* allocate input device */
  448. tpd->dev = input_allocate_device();
  449. if (tpd->dev == NULL) {
  450. kfree(tpd);
  451. return -ENOMEM;
  452. }
  453. /* TPD_RES_X = simple_strtoul(LCM_WIDTH, NULL, 0); */
  454. /* TPD_RES_Y = simple_strtoul(LCM_HEIGHT, NULL, 0); */
  455. #ifdef CONFIG_MTK_LCM_PHYSICAL_ROTATION
  456. if (0 == strncmp(CONFIG_MTK_LCM_PHYSICAL_ROTATION, "90", 2)
  457. || 0 == strncmp(CONFIG_MTK_LCM_PHYSICAL_ROTATION, "270", 3)) {
  458. #ifdef CONFIG_MTK_FB /*Fix build errors,as some projects cannot support these apis while bring up*/
  459. TPD_RES_Y = DISP_GetScreenWidth();
  460. TPD_RES_X = DISP_GetScreenHeight();
  461. #endif
  462. } else
  463. #endif
  464. {
  465. #ifdef CONFIG_CUSTOM_LCM_X
  466. #ifndef CONFIG_MTK_FPGA
  467. #ifdef CONFIG_MTK_FB /*Fix build errors,as some projects cannot support these apis while bring up*/
  468. TPD_RES_X = DISP_GetScreenWidth();
  469. TPD_RES_Y = DISP_GetScreenHeight();
  470. #endif
  471. #endif
  472. #else
  473. #ifdef CONFIG_LCM_WIDTH
  474. ret = kstrtoul(CONFIG_LCM_WIDTH, 0, &tpd_res_x);
  475. if (ret < 0) {
  476. pr_err("Touch down get lcm_x failed");
  477. return ret;
  478. }
  479. TPD_RES_X = tpd_res_x;
  480. ret = kstrtoul(CONFIG_LCM_HEIGHT, 0, &tpd_res_x);*/
  481. if (ret < 0) {
  482. pr_err("Touch down get lcm_y failed");
  483. return ret;
  484. }
  485. TPD_RES_Y = tpd_res_y;
  486. #endif
  487. #endif
  488. }
  489. if (2560 == TPD_RES_X)
  490. TPD_RES_X = 2048;
  491. if (1600 == TPD_RES_Y)
  492. TPD_RES_Y = 1536;
  493. pr_info("mtk_tpd: TPD_RES_X = %lu, TPD_RES_Y = %lu\n", TPD_RES_X, TPD_RES_Y);
  494. tpd_mode = TPD_MODE_NORMAL;
  495. tpd_mode_axis = 0;
  496. tpd_mode_min = TPD_RES_Y / 2;
  497. tpd_mode_max = TPD_RES_Y;
  498. tpd_mode_keypad_tolerance = TPD_RES_X * TPD_RES_X / 1600;
  499. /* struct input_dev dev initialization and registration */
  500. tpd->dev->name = TPD_DEVICE;
  501. set_bit(EV_ABS, tpd->dev->evbit);
  502. set_bit(EV_KEY, tpd->dev->evbit);
  503. set_bit(ABS_X, tpd->dev->absbit);
  504. set_bit(ABS_Y, tpd->dev->absbit);
  505. set_bit(ABS_PRESSURE, tpd->dev->absbit);
  506. #if !defined(CONFIG_MTK_S3320) && !defined(CONFIG_MTK_S3320_47)\
  507. && !defined(CONFIG_MTK_S3320_50) && !defined(CONFIG_MTK_MIT200) \
  508. && !defined(CONFIG_TOUCHSCREEN_SYNAPTICS_S3528) && !defined(CONFIG_MTK_S7020)
  509. set_bit(BTN_TOUCH, tpd->dev->keybit);
  510. #endif /* CONFIG_MTK_S3320 */
  511. set_bit(INPUT_PROP_DIRECT, tpd->dev->propbit);
  512. /* save dev for regulator_get() before tpd_local_init() */
  513. tpd->tpd_dev = &pdev->dev;
  514. for (i = 1; i < TP_DRV_MAX_COUNT; i++) {
  515. /* add tpd driver into list */
  516. if (tpd_driver_list[i].tpd_device_name != NULL) {
  517. tpd_driver_list[i].tpd_local_init();
  518. /* msleep(1); */
  519. if (tpd_load_status == 1) {
  520. TPD_DMESG("[mtk-tpd]tpd_probe, tpd_driver_name=%s\n",
  521. tpd_driver_list[i].tpd_device_name);
  522. g_tpd_drv = &tpd_driver_list[i];
  523. break;
  524. }
  525. }
  526. }
  527. if (g_tpd_drv == NULL) {
  528. if (tpd_driver_list[0].tpd_device_name != NULL) {
  529. g_tpd_drv = &tpd_driver_list[0];
  530. /* touch_type:0: r-touch, 1: C-touch */
  531. touch_type = 0;
  532. g_tpd_drv->tpd_local_init();
  533. TPD_DMESG("[mtk-tpd]Generic touch panel driver\n");
  534. } else {
  535. TPD_DMESG("[mtk-tpd]cap touch and Generic touch both are not loaded!!\n");
  536. return 0;
  537. }
  538. }
  539. touch_resume_workqueue = create_singlethread_workqueue("touch_resume");
  540. INIT_WORK(&touch_resume_work, touch_resume_workqueue_callback);
  541. /* use fb_notifier */
  542. tpd_fb_notifier.notifier_call = tpd_fb_notifier_callback;
  543. if (fb_register_client(&tpd_fb_notifier))
  544. TPD_DMESG("register fb_notifier fail!\n");
  545. /* TPD_TYPE_CAPACITIVE handle */
  546. if (touch_type == 1) {
  547. set_bit(ABS_MT_TRACKING_ID, tpd->dev->absbit);
  548. set_bit(ABS_MT_TOUCH_MAJOR, tpd->dev->absbit);
  549. set_bit(ABS_MT_TOUCH_MINOR, tpd->dev->absbit);
  550. set_bit(ABS_MT_POSITION_X, tpd->dev->absbit);
  551. set_bit(ABS_MT_POSITION_Y, tpd->dev->absbit);
  552. input_set_abs_params(tpd->dev, ABS_MT_POSITION_X, 0, TPD_RES_X, 0, 0);
  553. input_set_abs_params(tpd->dev, ABS_MT_POSITION_Y, 0, TPD_RES_Y, 0, 0);
  554. #if defined(CONFIG_MTK_S3320) || defined(CONFIG_MTK_S3320_47) \
  555. || defined(CONFIG_MTK_S3320_50) || defined(CONFIG_MTK_MIT200) \
  556. || defined(CONFIG_TOUCHSCREEN_SYNAPTICS_S3528) || defined(CONFIG_MTK_S7020)
  557. input_set_abs_params(tpd->dev, ABS_MT_PRESSURE, 0, 255, 0, 0);
  558. input_set_abs_params(tpd->dev, ABS_MT_WIDTH_MAJOR, 0, 15, 0, 0);
  559. input_set_abs_params(tpd->dev, ABS_MT_WIDTH_MINOR, 0, 15, 0, 0);
  560. input_mt_init_slots(tpd->dev, 10, 0);
  561. #else
  562. input_set_abs_params(tpd->dev, ABS_MT_TOUCH_MAJOR, 0, 100, 0, 0);
  563. input_set_abs_params(tpd->dev, ABS_MT_TOUCH_MINOR, 0, 100, 0, 0);
  564. #endif /* CONFIG_MTK_S3320 */
  565. TPD_DMESG("Cap touch panel driver\n");
  566. }
  567. input_set_abs_params(tpd->dev, ABS_X, 0, TPD_RES_X, 0, 0);
  568. input_set_abs_params(tpd->dev, ABS_Y, 0, TPD_RES_Y, 0, 0);
  569. input_abs_set_res(tpd->dev, ABS_X, TPD_RES_X);
  570. input_abs_set_res(tpd->dev, ABS_Y, TPD_RES_Y);
  571. input_set_abs_params(tpd->dev, ABS_PRESSURE, 0, 255, 0, 0);
  572. input_set_abs_params(tpd->dev, ABS_MT_TRACKING_ID, 0, 10, 0, 0);
  573. if (input_register_device(tpd->dev))
  574. TPD_DMESG("input_register_device failed.(tpd)\n");
  575. else
  576. tpd_register_flag = 1;
  577. if (g_tpd_drv->tpd_have_button)
  578. tpd_button_init();
  579. if (g_tpd_drv->attrs.num)
  580. tpd_create_attributes(&pdev->dev, &g_tpd_drv->attrs);
  581. return 0;
  582. }
  583. static int tpd_remove(struct platform_device *pdev)
  584. {
  585. input_unregister_device(tpd->dev);
  586. return 0;
  587. }
  588. /* called when loaded into kernel */
  589. static int __init tpd_device_init(void)
  590. {
  591. TPD_DEBUG("MediaTek touch panel driver init\n");
  592. if (platform_driver_register(&tpd_driver) != 0) {
  593. TPD_DMESG("unable to register touch panel driver.\n");
  594. return -1;
  595. }
  596. return 0;
  597. }
  598. /* should never be called */
  599. static void __exit tpd_device_exit(void)
  600. {
  601. TPD_DMESG("MediaTek touch panel driver exit\n");
  602. /* input_unregister_device(tpd->dev); */
  603. platform_driver_unregister(&tpd_driver);
  604. }
  605. late_initcall(tpd_device_init);
  606. module_exit(tpd_device_exit);
  607. MODULE_LICENSE("GPL");
  608. MODULE_DESCRIPTION("MediaTek touch panel driver");
  609. MODULE_AUTHOR("Kirby Wu<kirby.wu@mediatek.com>");