pt_platform.c 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051
  1. /*
  2. * pt_platform.c
  3. * Parade TrueTouch(TM) Standard Product Platform Module.
  4. * For use with Parade touchscreen controllers.
  5. * Supported parts include:
  6. * TMA5XX
  7. * TMA448
  8. * TMA445A
  9. * TT21XXX
  10. * TT31XXX
  11. * TT4XXXX
  12. * TT7XXX
  13. * TC3XXX
  14. *
  15. * Copyright (C) 2015-2020 Parade Technologies
  16. *
  17. * This program is free software; you can redistribute it and/or
  18. * modify it under the terms of the GNU General Public License
  19. * version 2, and only version 2, as published by the
  20. * Free Software Foundation.
  21. *
  22. * This program is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU General Public License for more details.
  26. *
  27. * Contact Parade Technologies at www.paradetech.com <[email protected]>
  28. */
  29. #include "pt_regs.h"
  30. #include "pt_platform.h"
  31. #ifdef CONFIG_TOUCHSCREEN_PARADE_PLATFORM_FW_UPGRADE
  32. /* FW for Panel ID = 0x00 */
  33. #include "pt_fw_pid00.h"
  34. static struct pt_touch_firmware pt_firmware_pid00 = {
  35. .img = pt_img_pid00,
  36. .size = ARRAY_SIZE(pt_img_pid00),
  37. .ver = pt_ver_pid00,
  38. .vsize = ARRAY_SIZE(pt_ver_pid00),
  39. .panel_id = 0x00,
  40. };
  41. /* FW for Panel ID = 0x01 */
  42. #include "pt_fw_pid01.h"
  43. static struct pt_touch_firmware pt_firmware_pid01 = {
  44. .img = pt_img_pid01,
  45. .size = ARRAY_SIZE(pt_img_pid01),
  46. .ver = pt_ver_pid01,
  47. .vsize = ARRAY_SIZE(pt_ver_pid01),
  48. .panel_id = 0x01,
  49. };
  50. /* FW for Panel ID not enabled (legacy) */
  51. #include "pt_fw.h"
  52. static struct pt_touch_firmware pt_firmware = {
  53. .img = pt_img,
  54. .size = ARRAY_SIZE(pt_img),
  55. .ver = pt_ver,
  56. .vsize = ARRAY_SIZE(pt_ver),
  57. };
  58. #else
  59. /* FW for Panel ID not enabled (legacy) */
  60. static struct pt_touch_firmware pt_firmware = {
  61. .img = NULL,
  62. .size = 0,
  63. .ver = NULL,
  64. .vsize = 0,
  65. };
  66. #endif
  67. #ifdef CONFIG_TOUCHSCREEN_PARADE_PLATFORM_TTCONFIG_UPGRADE
  68. /* TT Config for Panel ID = 0x00 */
  69. #include "pt_params_pid00.h"
  70. static struct touch_settings pt_sett_param_regs_pid00 = {
  71. .data = (uint8_t *)&pt_param_regs_pid00[0],
  72. .size = ARRAY_SIZE(pt_param_regs_pid00),
  73. .tag = 0,
  74. };
  75. static struct touch_settings pt_sett_param_size_pid00 = {
  76. .data = (uint8_t *)&pt_param_size_pid00[0],
  77. .size = ARRAY_SIZE(pt_param_size_pid00),
  78. .tag = 0,
  79. };
  80. static struct pt_touch_config pt_ttconfig_pid00 = {
  81. .param_regs = &pt_sett_param_regs_pid00,
  82. .param_size = &pt_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 "pt_params_pid01.h"
  89. static struct touch_settings pt_sett_param_regs_pid01 = {
  90. .data = (uint8_t *)&pt_param_regs_pid01[0],
  91. .size = ARRAY_SIZE(pt_param_regs_pid01),
  92. .tag = 0,
  93. };
  94. static struct touch_settings pt_sett_param_size_pid01 = {
  95. .data = (uint8_t *)&pt_param_size_pid01[0],
  96. .size = ARRAY_SIZE(pt_param_size_pid01),
  97. .tag = 0,
  98. };
  99. static struct pt_touch_config pt_ttconfig_pid01 = {
  100. .param_regs = &pt_sett_param_regs_pid01,
  101. .param_size = &pt_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 "pt_params.h"
  108. static struct touch_settings pt_sett_param_regs = {
  109. .data = (uint8_t *)&pt_param_regs[0],
  110. .size = ARRAY_SIZE(pt_param_regs),
  111. .tag = 0,
  112. };
  113. static struct touch_settings pt_sett_param_size = {
  114. .data = (uint8_t *)&pt_param_size[0],
  115. .size = ARRAY_SIZE(pt_param_size),
  116. .tag = 0,
  117. };
  118. static struct pt_touch_config pt_ttconfig = {
  119. .param_regs = &pt_sett_param_regs,
  120. .param_size = &pt_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 pt_touch_config pt_ttconfig = {
  127. .param_regs = NULL,
  128. .param_size = NULL,
  129. .fw_ver = NULL,
  130. .fw_vsize = 0,
  131. };
  132. #endif
  133. static struct pt_touch_firmware *pt_firmwares[] = {
  134. #ifdef CONFIG_TOUCHSCREEN_PARADE_PLATFORM_FW_UPGRADE
  135. &pt_firmware_pid00,
  136. &pt_firmware_pid01,
  137. #endif
  138. NULL, /* Last item should always be NULL */
  139. };
  140. static struct pt_touch_config *pt_ttconfigs[] = {
  141. #ifdef CONFIG_TOUCHSCREEN_PARADE_PLATFORM_TTCONFIG_UPGRADE
  142. &pt_ttconfig_pid00,
  143. &pt_ttconfig_pid01,
  144. #endif
  145. NULL, /* Last item should always be NULL */
  146. };
  147. struct pt_loader_platform_data _pt_loader_platform_data = {
  148. .fw = &pt_firmware,
  149. .ttconfig = &pt_ttconfig,
  150. .fws = pt_firmwares,
  151. .ttconfigs = pt_ttconfigs,
  152. .flags = PT_LOADER_FLAG_NONE,
  153. };
  154. /*******************************************************************************
  155. * FUNCTION: pt_xres
  156. *
  157. * SUMMARY: Toggles the reset gpio (TP_XRES) to perform a HW reset
  158. *
  159. * RETURN:
  160. * 0 = success
  161. * !0 = fail
  162. *
  163. * PARAMETERS:
  164. * *pdata - pointer to the platform data structure
  165. * *dev - pointer to Device structure
  166. ******************************************************************************/
  167. int pt_xres(struct pt_core_platform_data *pdata,
  168. struct device *dev)
  169. {
  170. int rst_gpio = pdata->rst_gpio;
  171. int rc = 0;
  172. int ddi_rst_gpio = pdata->ddi_rst_gpio;
  173. pt_debug(dev, DL_WARN, "%s: 20ms HARD RESET on gpio=%d\n",
  174. __func__, pdata->rst_gpio);
  175. /* Toggling only TP_XRES as DDI_XRES resets the entire part */
  176. gpio_set_value(rst_gpio, 1);
  177. if (ddi_rst_gpio)
  178. gpio_set_value(ddi_rst_gpio, 1);
  179. usleep_range(3000, 4000);
  180. gpio_set_value(rst_gpio, 0);
  181. usleep_range(6000, 7000);
  182. gpio_set_value(rst_gpio, 1);
  183. if (ddi_rst_gpio)
  184. gpio_set_value(ddi_rst_gpio, 1);
  185. /* Sleep to allow the DUT to boot */
  186. usleep_range(3000, 4000);
  187. return rc;
  188. }
  189. #ifdef PT_PINCTRL_EN
  190. /*******************************************************************************
  191. * FUNCTION: pt_pinctrl_init
  192. *
  193. * SUMMARY: Pinctrl method to obtain pin state handler for TP_RST, IRQ
  194. *
  195. * RETURN:
  196. * 0 = success
  197. * !0 = fail
  198. *
  199. * PARAMETERS:
  200. * *pdata - pointer to the platform data structure
  201. * *dev - pointer to Device structure
  202. ******************************************************************************/
  203. static int pt_pinctrl_init(struct pt_core_platform_data *pdata,
  204. struct device *dev)
  205. {
  206. int ret = 0;
  207. pdata->pinctrl = devm_pinctrl_get(dev);
  208. if (IS_ERR_OR_NULL(pdata->pinctrl)) {
  209. pt_debug(dev, DL_ERROR,
  210. "Failed to get pinctrl, please check dts");
  211. ret = PTR_ERR(pdata->pinctrl);
  212. goto err_pinctrl_get;
  213. }
  214. pdata->pins_active =
  215. pinctrl_lookup_state(pdata->pinctrl, "pmx_ts_active");
  216. if (IS_ERR_OR_NULL(pdata->pins_active)) {
  217. pt_debug(dev, DL_ERROR, "pmx_ts_active not found");
  218. ret = PTR_ERR(pdata->pins_active);
  219. goto err_pinctrl_lookup;
  220. }
  221. pdata->pins_suspend =
  222. pinctrl_lookup_state(pdata->pinctrl, "pmx_ts_suspend");
  223. if (IS_ERR_OR_NULL(pdata->pins_suspend)) {
  224. pt_debug(dev, DL_ERROR, "pmx_ts_suspend not found");
  225. ret = PTR_ERR(pdata->pins_suspend);
  226. goto err_pinctrl_lookup;
  227. }
  228. pdata->pins_release =
  229. pinctrl_lookup_state(pdata->pinctrl, "pmx_ts_release");
  230. if (IS_ERR_OR_NULL(pdata->pins_release)) {
  231. pt_debug(dev, DL_ERROR, "pmx_ts_release not found");
  232. ret = PTR_ERR(pdata->pins_release);
  233. goto err_pinctrl_lookup;
  234. }
  235. return 0;
  236. err_pinctrl_lookup:
  237. devm_pinctrl_put(pdata->pinctrl);
  238. err_pinctrl_get:
  239. pdata->pinctrl = NULL;
  240. pdata->pins_release = NULL;
  241. pdata->pins_suspend = NULL;
  242. pdata->pins_active = NULL;
  243. return ret;
  244. }
  245. /*******************************************************************************
  246. * FUNCTION: pt_pinctrl_select_normal
  247. *
  248. * SUMMARY: Pinctrl method to configure drive mode for TP_RST, IRQ - normal
  249. *
  250. * RETURN:
  251. * 0 = success
  252. * !0 = fail
  253. *
  254. * PARAMETERS:
  255. * *pdata - pointer to the platform data structure
  256. * *dev - pointer to Device structure
  257. ******************************************************************************/
  258. static int pt_pinctrl_select_normal(struct pt_core_platform_data *pdata,
  259. struct device *dev)
  260. {
  261. int ret = 0;
  262. if (pdata->pinctrl && pdata->pins_active) {
  263. ret = pinctrl_select_state(pdata->pinctrl, pdata->pins_active);
  264. if (ret < 0) {
  265. pt_debug(dev, DL_ERROR, "Set normal pin state error=%d",
  266. ret);
  267. }
  268. }
  269. return ret;
  270. }
  271. /*******************************************************************************
  272. * FUNCTION: pt_pinctrl_select_suspend
  273. *
  274. * SUMMARY: Pinctrl method to configure drive mode for TP_RST, IRQ - suspend
  275. *
  276. * RETURN:
  277. * 0 = success
  278. * !0 = fail
  279. *
  280. * PARAMETERS:
  281. * *pdata - pointer to the platform data structure
  282. * *dev - pointer to Device structure
  283. ******************************************************************************/
  284. static int pt_pinctrl_select_suspend(struct pt_core_platform_data *pdata,
  285. struct device *dev)
  286. {
  287. int ret = 0;
  288. if (pdata->pinctrl && pdata->pins_suspend) {
  289. ret = pinctrl_select_state(pdata->pinctrl, pdata->pins_suspend);
  290. if (ret < 0) {
  291. pt_debug(dev, DL_ERROR,
  292. "Set suspend pin state error=%d", ret);
  293. }
  294. }
  295. return ret;
  296. }
  297. /*******************************************************************************
  298. * FUNCTION: pt_pinctrl_select_release
  299. *
  300. * SUMMARY: Pinctrl method to configure drive mode for TP_RST, IRQ - release
  301. *
  302. * RETURN:
  303. * 0 = success
  304. * !0 = fail
  305. *
  306. * PARAMETERS:
  307. * *pdata - pointer to the platform data structure
  308. * *dev - pointer to Device structure
  309. ******************************************************************************/
  310. static int pt_pinctrl_select_release(struct pt_core_platform_data *pdata,
  311. struct device *dev)
  312. {
  313. int ret = 0;
  314. if (pdata->pinctrl) {
  315. if (IS_ERR_OR_NULL(pdata->pins_release)) {
  316. devm_pinctrl_put(pdata->pinctrl);
  317. pdata->pinctrl = NULL;
  318. } else {
  319. ret = pinctrl_select_state(pdata->pinctrl,
  320. pdata->pins_release);
  321. if (ret < 0)
  322. pt_debug(dev, DL_ERROR,
  323. "Set gesture pin state error=%d", ret);
  324. }
  325. }
  326. return ret;
  327. }
  328. #endif /* PT_PINCTRL_EN */
  329. /*******************************************************************************
  330. * FUNCTION: pt_init
  331. *
  332. * SUMMARY: Set up/free gpios for TP_RST, IRQ, DDI_RST.
  333. *
  334. * RETURN:
  335. * 0 = success
  336. * !0 = fail
  337. *
  338. * PARAMETERS:
  339. * *pdata - pointer to the platform data structure
  340. * on - flag to set up or free gpios(0:free; !0:set up)
  341. * *dev - pointer to Device structure
  342. ******************************************************************************/
  343. int pt_init(struct pt_core_platform_data *pdata,
  344. int on, struct device *dev)
  345. {
  346. int rst_gpio = pdata->rst_gpio;
  347. int irq_gpio = pdata->irq_gpio;
  348. int ddi_rst_gpio = pdata->ddi_rst_gpio;
  349. int rc = 0;
  350. #ifdef PT_PINCTRL_EN
  351. if (on) {
  352. rc = pt_pinctrl_init(pdata, dev);
  353. if (!rc) {
  354. pt_pinctrl_select_normal(pdata, dev);
  355. } else {
  356. pt_debug(dev, DL_ERROR,
  357. "%s: Failed to request pinctrl\n", __func__);
  358. }
  359. }
  360. #endif
  361. if (on && rst_gpio) {
  362. /* Configure RST GPIO */
  363. pt_debug(dev, DL_WARN, "%s: Request RST GPIO %d",
  364. __func__, rst_gpio);
  365. rc = gpio_request(rst_gpio, NULL);
  366. if (rc < 0) {
  367. gpio_free(rst_gpio);
  368. rc = gpio_request(rst_gpio, NULL);
  369. }
  370. if (rc < 0) {
  371. pt_debug(dev, DL_ERROR,
  372. "%s: Failed requesting RST GPIO %d\n",
  373. __func__, rst_gpio);
  374. goto fail_rst_gpio;
  375. } else {
  376. /*
  377. * Set the GPIO direction and the starting level
  378. * The start level is high because the DUT needs
  379. * to stay in reset during power up.
  380. */
  381. rc = gpio_direction_output(rst_gpio, 1);
  382. if (rc < 0) {
  383. pt_debug(dev, DL_ERROR,
  384. "%s: Output Setup ERROR: RST GPIO %d\n",
  385. __func__, rst_gpio);
  386. goto fail_rst_gpio;
  387. }
  388. }
  389. }
  390. if (on && irq_gpio) {
  391. /* Configure IRQ GPIO */
  392. pt_debug(dev, DL_WARN, "%s: Request IRQ GPIO %d",
  393. __func__, irq_gpio);
  394. rc = gpio_request(irq_gpio, NULL);
  395. if (rc < 0) {
  396. gpio_free(irq_gpio);
  397. rc = gpio_request(irq_gpio, NULL);
  398. }
  399. if (rc < 0) {
  400. pt_debug(dev, DL_ERROR,
  401. "%s: Failed requesting IRQ GPIO %d\n",
  402. __func__, irq_gpio);
  403. goto fail_irq_gpio;
  404. } else {
  405. /* Set the GPIO direction */
  406. rc = gpio_direction_input(irq_gpio);
  407. if (rc < 0) {
  408. pt_debug(dev, DL_ERROR,
  409. "%s: Input Setup ERROR: IRQ GPIO %d\n",
  410. __func__, irq_gpio);
  411. goto fail_irq_gpio;
  412. }
  413. }
  414. }
  415. if (on && ddi_rst_gpio) {
  416. /* Configure DDI RST GPIO */
  417. pt_debug(dev, DL_WARN, "%s: Request DDI RST GPIO %d",
  418. __func__, ddi_rst_gpio);
  419. rc = gpio_request(ddi_rst_gpio, NULL);
  420. if (rc < 0) {
  421. gpio_free(ddi_rst_gpio);
  422. rc = gpio_request(ddi_rst_gpio, NULL);
  423. }
  424. if (rc < 0) {
  425. pt_debug(dev, DL_ERROR,
  426. "%s: Failed requesting DDI RST GPIO %d\n",
  427. __func__, ddi_rst_gpio);
  428. goto fail_ddi_rst_gpio;
  429. } else {
  430. /* Set the GPIO direction and the starting level */
  431. rc = gpio_direction_output(ddi_rst_gpio, 0);
  432. if (rc < 0) {
  433. pt_debug(dev, DL_ERROR,
  434. "%s: Output Setup ERROR: RST GPIO %d\n",
  435. __func__, ddi_rst_gpio);
  436. goto fail_ddi_rst_gpio;
  437. }
  438. }
  439. }
  440. if (!on) {
  441. /* "on" not set, therefore free all gpio's */
  442. if (ddi_rst_gpio)
  443. gpio_free(ddi_rst_gpio);
  444. if (irq_gpio)
  445. gpio_free(irq_gpio);
  446. if (rst_gpio)
  447. gpio_free(rst_gpio);
  448. #ifdef PT_PINCTRL_EN
  449. pt_pinctrl_select_release(pdata, dev);
  450. #endif
  451. }
  452. /* All GPIO's created successfully */
  453. goto success;
  454. fail_ddi_rst_gpio:
  455. pt_debug(dev, DL_ERROR,
  456. "%s: ERROR - GPIO setup Failure, freeing DDI_XRES GPIO %d\n",
  457. __func__, ddi_rst_gpio);
  458. gpio_free(ddi_rst_gpio);
  459. fail_irq_gpio:
  460. pt_debug(dev, DL_ERROR,
  461. "%s: ERROR - GPIO setup Failure, freeing IRQ GPIO %d\n",
  462. __func__, irq_gpio);
  463. gpio_free(irq_gpio);
  464. fail_rst_gpio:
  465. pt_debug(dev, DL_ERROR,
  466. "%s: ERROR - GPIO setup Failure, freeing TP_XRES GPIO %d\n",
  467. __func__, rst_gpio);
  468. gpio_free(rst_gpio);
  469. success:
  470. pt_debug(dev, DL_INFO,
  471. "%s: SUCCESS - Configured DDI_XRES GPIO %d, IRQ GPIO %d, TP_XRES GPIO %d\n",
  472. __func__, ddi_rst_gpio, irq_gpio, rst_gpio);
  473. return rc;
  474. }
  475. /*******************************************************************************
  476. * FUNCTION: pt_wakeup
  477. *
  478. * SUMMARY: Resume power for "power on/off" sleep strategy which against to
  479. * "deepsleep" strategy.
  480. *
  481. * RETURN:
  482. * 0 = success
  483. * !0 = fail
  484. *
  485. * PARAMETERS:
  486. * *pdata - pointer to the platform data structure
  487. * *dev - pointer to Device structure
  488. * *ignore_irq - pointer to atomic structure to allow the host ignoring false
  489. * IRQ during power up
  490. ******************************************************************************/
  491. static int pt_wakeup(struct pt_core_platform_data *pdata,
  492. struct device *dev, atomic_t *ignore_irq)
  493. {
  494. /* Example for TT7XXX */
  495. int rc = 0;
  496. #ifdef PT_PINCTRL_EN
  497. rc = pt_pinctrl_select_normal(pdata, dev);
  498. if (rc)
  499. pr_err("%s: GPIO pins activation error: rc=%d\n",
  500. __func__, rc);
  501. #endif
  502. #ifdef TT7XXX_EXAMPLE
  503. pt_debug(dev, DL_INFO,
  504. "%s: Enable defined pwr: VDDI, VCC\n", __func__);
  505. /*
  506. * Force part into RESET by holding XRES#(TP_XRES)
  507. * while powering it up
  508. */
  509. if (pdata->rst_gpio)
  510. gpio_set_value(pdata->rst_gpio, 0);
  511. /* Turn on VDDI [Digital Interface] (+1.8v) */
  512. if (pdata->vddi_gpio) {
  513. rc = gpio_request(pdata->vddi_gpio, NULL);
  514. if (rc < 0) {
  515. gpio_free(pdata->vddi_gpio);
  516. rc = gpio_request(pdata->vddi_gpio, NULL);
  517. }
  518. if (rc < 0) {
  519. pr_err("%s: Failed requesting VDDI GPIO %d\n",
  520. __func__, pdata->vddi_gpio);
  521. }
  522. rc = gpio_direction_output(pdata->vddi_gpio, 1);
  523. if (rc)
  524. pr_err("%s: setcfg for VDDI GPIO %d failed\n",
  525. __func__, pdata->vddi_gpio);
  526. gpio_free(pdata->vddi_gpio);
  527. usleep_range(3000, 4000);
  528. }
  529. /* Turn on VCC */
  530. if (pdata->vcc_gpio) {
  531. rc = gpio_request(pdata->vcc_gpio, NULL);
  532. if (rc < 0) {
  533. gpio_free(pdata->vcc_gpio);
  534. rc = gpio_request(pdata->vcc_gpio, NULL);
  535. }
  536. if (rc < 0) {
  537. pr_err("%s: Failed requesting VCC GPIO %d\n",
  538. __func__, pdata->vcc_gpio);
  539. }
  540. rc = gpio_direction_output(pdata->vcc_gpio, 1);
  541. if (rc)
  542. pr_err("%s: setcfg for VCC GPIO %d failed\n",
  543. __func__, pdata->vcc_gpio);
  544. gpio_free(pdata->vcc_gpio);
  545. usleep_range(3000, 4000);
  546. }
  547. usleep_range(12000, 15000);
  548. /* Force part out of RESET by releasing XRES#(TP_XRES) */
  549. if (pdata->rst_gpio)
  550. gpio_set_value(pdata->rst_gpio, 1);
  551. #else
  552. pt_debug(dev, DL_INFO, "%s: Enable defined pwr\n", __func__);
  553. #endif
  554. return rc;
  555. }
  556. /*******************************************************************************
  557. * FUNCTION: pt_sleep
  558. *
  559. * SUMMARY: Suspend power for "power on/off" sleep strategy which against to
  560. * "deepsleep" strategy.
  561. *
  562. * RETURN:
  563. * 0 = success
  564. * !0 = fail
  565. *
  566. * PARAMETERS:
  567. * *pdata - pointer to the platform data structure
  568. * *dev - pointer to Device structure
  569. * *ignore_irq - pointer to atomic structure to allow the host ignoring false
  570. * IRQ during power down
  571. ******************************************************************************/
  572. static int pt_sleep(struct pt_core_platform_data *pdata,
  573. struct device *dev, atomic_t *ignore_irq)
  574. {
  575. /* Example for TT7XXX */
  576. int rc = 0;
  577. #ifdef TT7XXX_EXAMPLE
  578. pt_debug(dev, DL_INFO,
  579. "%s: Turn off defined pwr: VCC, VDDI\n", __func__);
  580. /*
  581. * Force part into RESET by holding XRES#(TP_XRES)
  582. * while powering it up
  583. */
  584. if (pdata->rst_gpio)
  585. gpio_set_value(pdata->rst_gpio, 0);
  586. /* Turn off VCC */
  587. if (pdata->vcc_gpio) {
  588. rc = gpio_request(pdata->vcc_gpio, NULL);
  589. if (rc < 0) {
  590. gpio_free(pdata->vcc_gpio);
  591. rc = gpio_request(pdata->vcc_gpio, NULL);
  592. }
  593. if (rc < 0) {
  594. pr_err("%s: Failed requesting VCC GPIO %d\n",
  595. __func__, pdata->vcc_gpio);
  596. }
  597. rc = gpio_direction_output(pdata->vcc_gpio, 0);
  598. if (rc)
  599. pr_err("%s: setcfg for VCC GPIO %d failed\n",
  600. __func__, pdata->vcc_gpio);
  601. gpio_free(pdata->vcc_gpio);
  602. }
  603. /* Turn off VDDI [Digital Interface] (+1.8v) */
  604. if (pdata->vddi_gpio) {
  605. rc = gpio_request(pdata->vddi_gpio, NULL);
  606. if (rc < 0) {
  607. gpio_free(pdata->vddi_gpio);
  608. rc = gpio_request(pdata->vddi_gpio, NULL);
  609. }
  610. if (rc < 0) {
  611. pr_err("%s: Failed requesting VDDI GPIO %d\n",
  612. __func__, pdata->vddi_gpio);
  613. }
  614. rc = gpio_direction_output(pdata->vddi_gpio, 0);
  615. if (rc)
  616. pr_err("%s: setcfg for VDDI GPIO %d failed\n",
  617. __func__, pdata->vddi_gpio);
  618. gpio_free(pdata->vddi_gpio);
  619. usleep_range(10000, 12000);
  620. }
  621. #else
  622. pt_debug(dev, DL_INFO, "%s: Turn off defined pwr\n", __func__);
  623. #endif
  624. #ifdef PT_PINCTRL_EN
  625. rc = pt_pinctrl_select_suspend(pdata, dev);
  626. if (rc)
  627. pr_err("%s: GPIO pins suspend error: rc=%d\n",
  628. __func__, rc);
  629. #endif
  630. return rc;
  631. }
  632. /*******************************************************************************
  633. * FUNCTION: pt_power
  634. *
  635. * SUMMARY: Wrapper function to resume/suspend power with function
  636. * pt_wakeup()/pt_sleep().
  637. *
  638. * RETURN:
  639. * 0 = success
  640. * !0 = fail
  641. *
  642. * PARAMETERS:
  643. * *pdata - pointer to the platform data structure
  644. * on - flag to remsume/suspend power(0:resume; 1:suspend)
  645. * *dev - pointer to Device structure
  646. * *ignore_irq - pointer to atomic structure to allow the host ignoring false
  647. * IRQ during power up/down
  648. ******************************************************************************/
  649. int pt_power(struct pt_core_platform_data *pdata,
  650. int on, struct device *dev, atomic_t *ignore_irq)
  651. {
  652. if (on)
  653. return pt_wakeup(pdata, dev, ignore_irq);
  654. return pt_sleep(pdata, dev, ignore_irq);
  655. }
  656. /*******************************************************************************
  657. * FUNCTION: pt_irq_stat
  658. *
  659. * SUMMARY: Obtain the level state of IRQ gpio.
  660. *
  661. * RETURN:
  662. * level state of IRQ gpio
  663. *
  664. * PARAMETERS:
  665. * *pdata - pointer to the platform data structure
  666. * *dev - pointer to Device structure
  667. ******************************************************************************/
  668. int pt_irq_stat(struct pt_core_platform_data *pdata,
  669. struct device *dev)
  670. {
  671. return gpio_get_value(pdata->irq_gpio);
  672. }
  673. #ifdef PT_DETECT_HW
  674. /*******************************************************************************
  675. * FUNCTION: pt_detect
  676. *
  677. * SUMMARY: Detect the I2C device by reading one byte(FW sentiel) after the
  678. * reset operation.
  679. *
  680. * RETURN:
  681. * 0 - detected
  682. * !0 - undetected
  683. *
  684. * PARAMETERS:
  685. * *pdata - pointer to the platform data structure
  686. * *dev - pointer to Device structure
  687. * read - pointer to the function to perform a read operation
  688. ******************************************************************************/
  689. int pt_detect(struct pt_core_platform_data *pdata,
  690. struct device *dev, pt_platform_read read)
  691. {
  692. int retry = 3;
  693. int rc;
  694. char buf[1];
  695. while (retry--) {
  696. /* Perform reset, wait for 100 ms and perform read */
  697. pt_debug(dev, DL_WARN, "%s: Performing a reset\n",
  698. __func__);
  699. pdata->xres(pdata, dev);
  700. msleep(100);
  701. rc = read(dev, buf, 1);
  702. if (!rc)
  703. return 0;
  704. pt_debug(dev, DL_ERROR, "%s: Read unsuccessful, try=%d\n",
  705. __func__, 3 - retry);
  706. }
  707. return rc;
  708. }
  709. #endif
  710. /*******************************************************************************
  711. * FUNCTION: pt_setup_power
  712. *
  713. * SUMMARY: Turn on/turn off voltage regulator
  714. *
  715. * RETURN:
  716. * 0 = success
  717. * !0 = failure
  718. *
  719. * PARAMETERS:
  720. * *pdata - pointer to core platform data
  721. * on - flag to decide power state,PT_MT_POWER_ON/PT_MT_POWER_OFF
  722. * *dev - pointer to device
  723. ******************************************************************************/
  724. int pt_setup_power(struct pt_core_platform_data *pdata, int on,
  725. struct device *dev)
  726. {
  727. int en_vcc = pdata->vcc_gpio;
  728. int en_vddi = pdata->vddi_gpio;
  729. int en_avdd = pdata->avdd_gpio;
  730. int en_avee = pdata->avee_gpio;
  731. int rc = 0;
  732. /*
  733. * For TDDI parts, force part into RESET by holding DDI XRES
  734. * while powering it up
  735. */
  736. if (pdata->ddi_rst_gpio)
  737. gpio_set_value(pdata->ddi_rst_gpio, 0);
  738. /*
  739. * Force part into RESET by holding XRES#(TP_XRES)
  740. * while powering it up
  741. */
  742. if (pdata->rst_gpio)
  743. gpio_set_value(pdata->rst_gpio, 0);
  744. if (on == PT_MT_POWER_ON) {
  745. /*
  746. * Enable GPIOs to turn on voltage regulators to pwr up DUT
  747. * - TC device power up order: VDDI, VCC, AVDD, AVEE
  748. * - TT device power up order: VDDI, VCC
  749. * NOTE: VDDI must be stable for >10ms before XRES is released
  750. */
  751. pt_debug(dev, DL_INFO,
  752. "%s: Enable defined pwr: VDDI, VCC, AVDD, AVEE\n", __func__);
  753. /* Turn on VDDI [Digital Interface] (+1.8v) */
  754. if (pdata->vddi_gpio) {
  755. rc = gpio_request(en_vddi, NULL);
  756. if (rc < 0) {
  757. gpio_free(en_vddi);
  758. rc = gpio_request(en_vddi, NULL);
  759. }
  760. if (rc < 0) {
  761. pr_err("%s: Failed requesting VDDI GPIO %d\n",
  762. __func__, en_vddi);
  763. }
  764. rc = gpio_direction_output(en_vddi, 1);
  765. if (rc)
  766. pr_err("%s: setcfg for VDDI GPIO %d failed\n",
  767. __func__, en_vddi);
  768. gpio_free(en_vddi);
  769. usleep_range(3000, 4000);
  770. }
  771. /* Turn on VCC */
  772. if (pdata->vcc_gpio) {
  773. rc = gpio_request(en_vcc, NULL);
  774. if (rc < 0) {
  775. gpio_free(en_vcc);
  776. rc = gpio_request(en_vcc, NULL);
  777. }
  778. if (rc < 0) {
  779. pr_err("%s: Failed requesting VCC GPIO %d\n",
  780. __func__, en_vcc);
  781. }
  782. rc = gpio_direction_output(en_vcc, 1);
  783. if (rc)
  784. pr_err("%s: setcfg for VCC GPIO %d failed\n",
  785. __func__, en_vcc);
  786. gpio_free(en_vcc);
  787. usleep_range(3000, 4000);
  788. }
  789. /* Turn on AVDD (+5.0v) */
  790. if (pdata->avdd_gpio) {
  791. rc = gpio_request(en_avdd, NULL);
  792. if (rc < 0) {
  793. gpio_free(en_avdd);
  794. rc = gpio_request(en_avdd, NULL);
  795. }
  796. if (rc < 0) {
  797. pr_err("%s: Failed requesting AVDD GPIO %d\n",
  798. __func__, en_avdd);
  799. }
  800. rc = gpio_direction_output(en_avdd, 1);
  801. if (rc)
  802. pr_err("%s: setcfg for AVDD GPIO %d failed\n",
  803. __func__, en_avdd);
  804. gpio_free(en_avdd);
  805. usleep_range(3000, 4000);
  806. }
  807. /* Turn on AVEE (-5.0v) */
  808. if (pdata->avee_gpio) {
  809. rc = gpio_request(en_avee, NULL);
  810. if (rc < 0) {
  811. gpio_free(en_avee);
  812. rc = gpio_request(en_avee, NULL);
  813. }
  814. if (rc < 0) {
  815. pr_err("%s: Failed requesting AVEE GPIO %d\n",
  816. __func__, en_avee);
  817. }
  818. rc = gpio_direction_output(en_avee, 1);
  819. if (rc)
  820. pr_err("%s: setcfg for AVEE GPIO %d failed\n",
  821. __func__, en_avee);
  822. gpio_free(en_avee);
  823. usleep_range(3000, 4000);
  824. }
  825. } else {
  826. /*
  827. * Disable GPIOs to turn off voltage regulators to pwr down
  828. * TC device The power down order is: AVEE, AVDD, VDDI
  829. * TT device The power down order is: VCC, VDDI
  830. *
  831. * Note:Turn off some of regulators may effect display
  832. * parts for TDDI chip
  833. */
  834. pt_debug(dev, DL_INFO,
  835. "%s: Turn off defined pwr: VCC, AVEE, AVDD, VDDI\n", __func__);
  836. /* Turn off VCC */
  837. if (pdata->vcc_gpio) {
  838. rc = gpio_request(en_vcc, NULL);
  839. if (rc < 0) {
  840. gpio_free(en_vcc);
  841. rc = gpio_request(en_vcc, NULL);
  842. }
  843. if (rc < 0) {
  844. pr_err("%s: Failed requesting VCC GPIO %d\n",
  845. __func__, en_vcc);
  846. }
  847. rc = gpio_direction_output(en_vcc, 0);
  848. if (rc)
  849. pr_err("%s: setcfg for VCC GPIO %d failed\n",
  850. __func__, en_vcc);
  851. gpio_free(en_vcc);
  852. }
  853. /* Turn off AVEE (-5.0v) */
  854. if (pdata->avee_gpio) {
  855. rc = gpio_request(en_avee, NULL);
  856. if (rc < 0) {
  857. gpio_free(en_avee);
  858. rc = gpio_request(en_avee, NULL);
  859. }
  860. if (rc < 0) {
  861. pr_err("%s: Failed requesting AVEE GPIO %d\n",
  862. __func__, en_avee);
  863. }
  864. rc = gpio_direction_output(en_avee, 0);
  865. if (rc)
  866. pr_err("%s: setcfg for AVEE GPIO %d failed\n",
  867. __func__, en_avee);
  868. gpio_free(en_avee);
  869. }
  870. /* Turn off AVDD (+5.0v) */
  871. if (pdata->avdd_gpio) {
  872. rc = gpio_request(en_avdd, NULL);
  873. if (rc < 0) {
  874. gpio_free(en_avdd);
  875. rc = gpio_request(en_avdd, NULL);
  876. }
  877. if (rc < 0) {
  878. pr_err("%s: Failed requesting AVDD GPIO %d\n",
  879. __func__, en_avdd);
  880. }
  881. rc = gpio_direction_output(en_avdd, 0);
  882. if (rc)
  883. pr_err("%s: setcfg for AVDD GPIO %d failed\n",
  884. __func__, en_avdd);
  885. gpio_free(en_avdd);
  886. }
  887. /* Turn off VDDI [Digital Interface] (+1.8v) */
  888. if (pdata->vddi_gpio) {
  889. rc = gpio_request(en_vddi, NULL);
  890. if (rc < 0) {
  891. gpio_free(en_vddi);
  892. rc = gpio_request(en_vddi, NULL);
  893. }
  894. if (rc < 0) {
  895. pr_err("%s: Failed requesting VDDI GPIO %d\n",
  896. __func__, en_vddi);
  897. }
  898. rc = gpio_direction_output(en_vddi, 0);
  899. if (rc)
  900. pr_err("%s: setcfg for VDDI GPIO %d failed\n",
  901. __func__, en_vddi);
  902. gpio_free(en_vddi);
  903. usleep_range(10000, 12000);
  904. }
  905. }
  906. /* Force part out of RESET by releasing XRES#(TP_XRES) */
  907. if (pdata->rst_gpio)
  908. gpio_set_value(pdata->rst_gpio, 1);
  909. /* Force part out of RESET by releasing DDI XRES */
  910. if (pdata->ddi_rst_gpio)
  911. gpio_set_value(pdata->ddi_rst_gpio, 1);
  912. return rc;
  913. }
  914. /*******************************************************************************
  915. * FUNCTION: pt_setup_irq
  916. *
  917. * SUMMARY: Configure the IRQ GPIO used by the TT DUT
  918. *
  919. * RETURN:
  920. * 0 = success
  921. * !0 = failure
  922. *
  923. * PARAMETERS:
  924. * *pdata - pointer to core platform data
  925. * on - flag to setup interrupt process work(PT_MT_IRQ_FREE/)
  926. * *dev - pointer to device
  927. ******************************************************************************/
  928. int pt_setup_irq(struct pt_core_platform_data *pdata, int on,
  929. struct device *dev)
  930. {
  931. struct pt_core_data *cd = dev_get_drvdata(dev);
  932. unsigned long irq_flags;
  933. int rc = 0;
  934. if (on == PT_MT_IRQ_REG) {
  935. /*
  936. * When TTDL has direct access to the GPIO the irq_stat function
  937. * will be defined and the gpio_to_irq conversion must be
  938. * performed. e.g. For CHROMEOS this is not the case, the irq is
  939. * passed in directly.
  940. */
  941. if (pdata->irq_stat) {
  942. /* Initialize IRQ */
  943. dev_vdbg(dev, "%s: Value Passed to gpio_to_irq =%d\n",
  944. __func__, pdata->irq_gpio);
  945. cd->irq = gpio_to_irq(pdata->irq_gpio);
  946. dev_vdbg(dev,
  947. "%s: Value Returned from gpio_to_irq =%d\n",
  948. __func__, cd->irq);
  949. }
  950. if (cd->irq < 0)
  951. return -EINVAL;
  952. cd->irq_enabled = true;
  953. pt_debug(dev, DL_INFO, "%s: initialize threaded irq=%d\n",
  954. __func__, cd->irq);
  955. if (pdata->level_irq_udelay > 0)
  956. /* use level triggered interrupts */
  957. irq_flags = IRQF_TRIGGER_LOW;
  958. else
  959. /* use edge triggered interrupts */
  960. irq_flags = IRQF_TRIGGER_FALLING;
  961. rc = request_threaded_irq(cd->irq, NULL, pt_irq,
  962. irq_flags | IRQF_ONESHOT, dev_name(dev), cd);
  963. if (rc < 0)
  964. pt_debug(dev, DL_ERROR,
  965. "%s: Error, could not request irq\n", __func__);
  966. } else {
  967. disable_irq_nosync(cd->irq);
  968. free_irq(cd->irq, cd);
  969. }
  970. return rc;
  971. }