cyttsp5_platform.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. /*
  2. * cyttsp5_platform.c
  3. * Parade TrueTouch(TM) Standard Product V5 Platform Module.
  4. * For use with Parade touchscreen controllers.
  5. * Supported parts include:
  6. * CYTMA5XX
  7. * CYTMA448
  8. * CYTMA445A
  9. * CYTT21XXX
  10. * CYTT31XXX
  11. *
  12. * Copyright (C) 2015 Parade Technologies
  13. * Copyright (C) 2013-2015 Cypress Semiconductor
  14. *
  15. * This program is free software; you can redistribute it and/or
  16. * modify it under the terms of the GNU General Public License
  17. * version 2, and only version 2, as published by the
  18. * Free Software Foundation.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * Contact Parade Technologies at www.paradetech.com <ttdrivers@paradetech.com>
  26. *
  27. */
  28. #include "cyttsp5_regs.h"
  29. //#include <linux/cyttsp5_platform.h>
  30. #include "cyttsp5_platform.h"
  31. #ifdef CONFIG_TOUCHSCREEN_CYPRESS_CYTTSP5_PLATFORM_FW_UPGRADE
  32. /* FW for Panel ID = 0x00 */
  33. #include "cyttsp5_fw_pid00.h"
  34. static struct cyttsp5_touch_firmware cyttsp5_firmware_pid00 = {
  35. .img = cyttsp4_img_pid00,
  36. .size = ARRAY_SIZE(cyttsp4_img_pid00),
  37. .ver = cyttsp4_ver_pid00,
  38. .vsize = ARRAY_SIZE(cyttsp4_ver_pid00),
  39. .panel_id = 0x00,
  40. };
  41. /* FW for Panel ID = 0x01 */
  42. #include "cyttsp5_fw_pid01.h"
  43. static struct cyttsp5_touch_firmware cyttsp5_firmware_pid01 = {
  44. .img = cyttsp4_img_pid01,
  45. .size = ARRAY_SIZE(cyttsp4_img_pid01),
  46. .ver = cyttsp4_ver_pid01,
  47. .vsize = ARRAY_SIZE(cyttsp4_ver_pid01),
  48. .panel_id = 0x01,
  49. };
  50. /* FW for Panel ID not enabled (legacy) */
  51. #include "cyttsp5_fw.h"
  52. static struct cyttsp5_touch_firmware cyttsp5_firmware = {
  53. .img = cyttsp4_img,
  54. .size = ARRAY_SIZE(cyttsp4_img),
  55. .ver = cyttsp4_ver,
  56. .vsize = ARRAY_SIZE(cyttsp4_ver),
  57. };
  58. #else
  59. /* FW for Panel ID not enabled (legacy) */
  60. static struct cyttsp5_touch_firmware cyttsp5_firmware = {
  61. .img = NULL,
  62. .size = 0,
  63. .ver = NULL,
  64. .vsize = 0,
  65. };
  66. #endif
  67. #ifdef CONFIG_TOUCHSCREEN_CYPRESS_CYTTSP5_PLATFORM_TTCONFIG_UPGRADE
  68. /* TT Config for Panel ID = 0x00 */
  69. #include "cyttsp5_params_pid00.h"
  70. static struct touch_settings cyttsp5_sett_param_regs_pid00 = {
  71. .data = (uint8_t *)&cyttsp4_param_regs_pid00[0],
  72. .size = ARRAY_SIZE(cyttsp4_param_regs_pid00),
  73. .tag = 0,
  74. };
  75. static struct touch_settings cyttsp5_sett_param_size_pid00 = {
  76. .data = (uint8_t *)&cyttsp4_param_size_pid00[0],
  77. .size = ARRAY_SIZE(cyttsp4_param_size_pid00),
  78. .tag = 0,
  79. };
  80. static struct cyttsp5_touch_config cyttsp5_ttconfig_pid00 = {
  81. .param_regs = &cyttsp5_sett_param_regs_pid00,
  82. .param_size = &cyttsp5_sett_param_size_pid00,
  83. .fw_ver = ttconfig_fw_ver_pid00,
  84. .fw_vsize = ARRAY_SIZE(ttconfig_fw_ver_pid00),
  85. .panel_id = 0x00,
  86. };
  87. /* TT Config for Panel ID = 0x01 */
  88. #include "cyttsp5_params_pid01.h"
  89. static struct touch_settings cyttsp5_sett_param_regs_pid01 = {
  90. .data = (uint8_t *)&cyttsp4_param_regs_pid01[0],
  91. .size = ARRAY_SIZE(cyttsp4_param_regs_pid01),
  92. .tag = 0,
  93. };
  94. static struct touch_settings cyttsp5_sett_param_size_pid01 = {
  95. .data = (uint8_t *)&cyttsp4_param_size_pid01[0],
  96. .size = ARRAY_SIZE(cyttsp4_param_size_pid01),
  97. .tag = 0,
  98. };
  99. static struct cyttsp5_touch_config cyttsp5_ttconfig_pid01 = {
  100. .param_regs = &cyttsp5_sett_param_regs_pid01,
  101. .param_size = &cyttsp5_sett_param_size_pid01,
  102. .fw_ver = ttconfig_fw_ver_pid01,
  103. .fw_vsize = ARRAY_SIZE(ttconfig_fw_ver_pid01),
  104. .panel_id = 0x01,
  105. };
  106. /* TT Config for Panel ID not enabled (legacy)*/
  107. #include "cyttsp5_params.h"
  108. static struct touch_settings cyttsp5_sett_param_regs = {
  109. .data = (uint8_t *)&cyttsp4_param_regs[0],
  110. .size = ARRAY_SIZE(cyttsp4_param_regs),
  111. .tag = 0,
  112. };
  113. static struct touch_settings cyttsp5_sett_param_size = {
  114. .data = (uint8_t *)&cyttsp4_param_size[0],
  115. .size = ARRAY_SIZE(cyttsp4_param_size),
  116. .tag = 0,
  117. };
  118. static struct cyttsp5_touch_config cyttsp5_ttconfig = {
  119. .param_regs = &cyttsp5_sett_param_regs,
  120. .param_size = &cyttsp5_sett_param_size,
  121. .fw_ver = ttconfig_fw_ver,
  122. .fw_vsize = ARRAY_SIZE(ttconfig_fw_ver),
  123. };
  124. #else
  125. /* TT Config for Panel ID not enabled (legacy)*/
  126. static struct cyttsp5_touch_config cyttsp5_ttconfig = {
  127. .param_regs = NULL,
  128. .param_size = NULL,
  129. .fw_ver = NULL,
  130. .fw_vsize = 0,
  131. };
  132. #endif
  133. static struct cyttsp5_touch_firmware *cyttsp5_firmwares[] = {
  134. #ifdef CONFIG_TOUCHSCREEN_CYPRESS_CYTTSP5_PLATFORM_FW_UPGRADE
  135. &cyttsp5_firmware_pid00,
  136. &cyttsp5_firmware_pid01,
  137. #endif
  138. NULL, /* Last item should always be NULL */
  139. };
  140. static struct cyttsp5_touch_config *cyttsp5_ttconfigs[] = {
  141. #ifdef CONFIG_TOUCHSCREEN_CYPRESS_CYTTSP5_PLATFORM_TTCONFIG_UPGRADE
  142. &cyttsp5_ttconfig_pid00,
  143. &cyttsp5_ttconfig_pid01,
  144. #endif
  145. NULL, /* Last item should always be NULL */
  146. };
  147. struct cyttsp5_loader_platform_data _cyttsp5_loader_platform_data = {
  148. .fw = &cyttsp5_firmware,
  149. .ttconfig = &cyttsp5_ttconfig,
  150. .fws = cyttsp5_firmwares,
  151. .ttconfigs = cyttsp5_ttconfigs,
  152. .flags = CY_LOADER_FLAG_NONE,
  153. };
  154. int cyttsp5_xres(struct cyttsp5_core_platform_data *pdata,
  155. struct device *dev)
  156. {
  157. int rst_gpio = pdata->rst_gpio;
  158. int rc = 0;
  159. gpio_set_value(rst_gpio, 1);
  160. msleep(20);
  161. gpio_set_value(rst_gpio, 0);
  162. msleep(40);
  163. gpio_set_value(rst_gpio, 1);
  164. msleep(20);
  165. dev_info(dev,
  166. "%s: RESET CYTTSP gpio=%d r=%d\n", __func__,
  167. pdata->rst_gpio, rc);
  168. return rc;
  169. }
  170. int cyttsp5_init(struct cyttsp5_core_platform_data *pdata,
  171. int on, struct device *dev)
  172. {
  173. int rst_gpio = pdata->rst_gpio;
  174. int irq_gpio = pdata->irq_gpio;
  175. int rc = 0;
  176. if (on) {
  177. rc = gpio_request(rst_gpio, NULL);
  178. if (rc < 0) {
  179. gpio_free(rst_gpio);
  180. rc = gpio_request(rst_gpio, NULL);
  181. }
  182. if (rc < 0) {
  183. dev_err(dev,
  184. "%s: Fail request gpio=%d\n", __func__,
  185. rst_gpio);
  186. } else {
  187. rc = gpio_direction_output(rst_gpio, 1);
  188. if (rc < 0) {
  189. pr_err("%s: Fail set output gpio=%d\n",
  190. __func__, rst_gpio);
  191. gpio_free(rst_gpio);
  192. } else {
  193. rc = gpio_request(irq_gpio, NULL);
  194. if (rc < 0) {
  195. gpio_free(irq_gpio);
  196. rc = gpio_request(irq_gpio,
  197. NULL);
  198. }
  199. if (rc < 0) {
  200. dev_err(dev,
  201. "%s: Fail request gpio=%d\n",
  202. __func__, irq_gpio);
  203. gpio_free(rst_gpio);
  204. } else {
  205. gpio_direction_input(irq_gpio);
  206. }
  207. }
  208. }
  209. } else {
  210. gpio_free(rst_gpio);
  211. gpio_free(irq_gpio);
  212. }
  213. dev_info(dev, "%s: INIT CYTTSP RST gpio=%d and IRQ gpio=%d r=%d\n",
  214. __func__, rst_gpio, irq_gpio, rc);
  215. return rc;
  216. }
  217. static int cyttsp5_wakeup(struct cyttsp5_core_platform_data *pdata,
  218. struct device *dev, atomic_t *ignore_irq)
  219. {
  220. return 0;
  221. }
  222. static int cyttsp5_sleep(struct cyttsp5_core_platform_data *pdata,
  223. struct device *dev, atomic_t *ignore_irq)
  224. {
  225. return 0;
  226. }
  227. int cyttsp5_power(struct cyttsp5_core_platform_data *pdata,
  228. int on, struct device *dev, atomic_t *ignore_irq)
  229. {
  230. if (on)
  231. return cyttsp5_wakeup(pdata, dev, ignore_irq);
  232. return cyttsp5_sleep(pdata, dev, ignore_irq);
  233. }
  234. int cyttsp5_irq_stat(struct cyttsp5_core_platform_data *pdata,
  235. struct device *dev)
  236. {
  237. return gpio_get_value(pdata->irq_gpio);
  238. }
  239. #ifdef CYTTSP5_DETECT_HW
  240. int cyttsp5_detect(struct cyttsp5_core_platform_data *pdata,
  241. struct device *dev, cyttsp5_platform_read read)
  242. {
  243. int retry = 3;
  244. int rc;
  245. char buf[1];
  246. while (retry--) {
  247. /* Perform reset, wait for 100 ms and perform read */
  248. parade_debug(dev, DEBUG_LEVEL_2, "%s: Performing a reset\n",
  249. __func__);
  250. pdata->xres(pdata, dev);
  251. msleep(100);
  252. rc = read(dev, buf, 1);
  253. if (!rc)
  254. return 0;
  255. parade_debug(dev, DEBUG_LEVEL_2, "%s: Read unsuccessful, try=%d\n",
  256. __func__, 3 - retry);
  257. }
  258. return rc;
  259. }
  260. #endif