pt_platform.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281
  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 <linux/pt_platform.h>
  31. #include <linux/regulator/consumer.h>
  32. #ifdef PT_PTSBC_SUPPORT
  33. #include <linux/init-input.h>
  34. #endif
  35. #ifdef CONFIG_TOUCHSCREEN_PARADE_PLATFORM_FW_UPGRADE
  36. /* FW for Panel ID = 0x00 */
  37. #include "pt_fw_pid00.h"
  38. static struct pt_touch_firmware pt_firmware_pid00 = {
  39. .img = pt_img_pid00,
  40. .size = ARRAY_SIZE(pt_img_pid00),
  41. .ver = pt_ver_pid00,
  42. .vsize = ARRAY_SIZE(pt_ver_pid00),
  43. .panel_id = 0x00,
  44. };
  45. /* FW for Panel ID = 0x01 */
  46. #include "pt_fw_pid01.h"
  47. static struct pt_touch_firmware pt_firmware_pid01 = {
  48. .img = pt_img_pid01,
  49. .size = ARRAY_SIZE(pt_img_pid01),
  50. .ver = pt_ver_pid01,
  51. .vsize = ARRAY_SIZE(pt_ver_pid01),
  52. .panel_id = 0x01,
  53. };
  54. /* FW for Panel ID not enabled (legacy) */
  55. #include "pt_fw.h"
  56. static struct pt_touch_firmware pt_firmware = {
  57. .img = pt_img,
  58. .size = ARRAY_SIZE(pt_img),
  59. .ver = pt_ver,
  60. .vsize = ARRAY_SIZE(pt_ver),
  61. };
  62. #else
  63. /* FW for Panel ID not enabled (legacy) */
  64. static struct pt_touch_firmware pt_firmware = {
  65. .img = NULL,
  66. .size = 0,
  67. .ver = NULL,
  68. .vsize = 0,
  69. };
  70. #endif
  71. #ifdef CONFIG_TOUCHSCREEN_PARADE_PLATFORM_TTCONFIG_UPGRADE
  72. /* TT Config for Panel ID = 0x00 */
  73. #include "pt_params_pid00.h"
  74. static struct touch_settings pt_sett_param_regs_pid00 = {
  75. .data = (uint8_t *)&pt_param_regs_pid00[0],
  76. .size = ARRAY_SIZE(pt_param_regs_pid00),
  77. .tag = 0,
  78. };
  79. static struct touch_settings pt_sett_param_size_pid00 = {
  80. .data = (uint8_t *)&pt_param_size_pid00[0],
  81. .size = ARRAY_SIZE(pt_param_size_pid00),
  82. .tag = 0,
  83. };
  84. static struct pt_touch_config pt_ttconfig_pid00 = {
  85. .param_regs = &pt_sett_param_regs_pid00,
  86. .param_size = &pt_sett_param_size_pid00,
  87. .fw_ver = ttconfig_fw_ver_pid00,
  88. .fw_vsize = ARRAY_SIZE(ttconfig_fw_ver_pid00),
  89. .panel_id = 0x00,
  90. };
  91. /* TT Config for Panel ID = 0x01 */
  92. #include "pt_params_pid01.h"
  93. static struct touch_settings pt_sett_param_regs_pid01 = {
  94. .data = (uint8_t *)&pt_param_regs_pid01[0],
  95. .size = ARRAY_SIZE(pt_param_regs_pid01),
  96. .tag = 0,
  97. };
  98. static struct touch_settings pt_sett_param_size_pid01 = {
  99. .data = (uint8_t *)&pt_param_size_pid01[0],
  100. .size = ARRAY_SIZE(pt_param_size_pid01),
  101. .tag = 0,
  102. };
  103. static struct pt_touch_config pt_ttconfig_pid01 = {
  104. .param_regs = &pt_sett_param_regs_pid01,
  105. .param_size = &pt_sett_param_size_pid01,
  106. .fw_ver = ttconfig_fw_ver_pid01,
  107. .fw_vsize = ARRAY_SIZE(ttconfig_fw_ver_pid01),
  108. .panel_id = 0x01,
  109. };
  110. /* TT Config for Panel ID not enabled (legacy)*/
  111. #include "pt_params.h"
  112. static struct touch_settings pt_sett_param_regs = {
  113. .data = (uint8_t *)&pt_param_regs[0],
  114. .size = ARRAY_SIZE(pt_param_regs),
  115. .tag = 0,
  116. };
  117. static struct touch_settings pt_sett_param_size = {
  118. .data = (uint8_t *)&pt_param_size[0],
  119. .size = ARRAY_SIZE(pt_param_size),
  120. .tag = 0,
  121. };
  122. static struct pt_touch_config pt_ttconfig = {
  123. .param_regs = &pt_sett_param_regs,
  124. .param_size = &pt_sett_param_size,
  125. .fw_ver = ttconfig_fw_ver,
  126. .fw_vsize = ARRAY_SIZE(ttconfig_fw_ver),
  127. };
  128. #else
  129. /* TT Config for Panel ID not enabled (legacy)*/
  130. static struct pt_touch_config pt_ttconfig = {
  131. .param_regs = NULL,
  132. .param_size = NULL,
  133. .fw_ver = NULL,
  134. .fw_vsize = 0,
  135. };
  136. #endif
  137. static struct pt_touch_firmware *pt_firmwares[] = {
  138. #ifdef CONFIG_TOUCHSCREEN_PARADE_PLATFORM_FW_UPGRADE
  139. &pt_firmware_pid00,
  140. &pt_firmware_pid01,
  141. #endif
  142. NULL, /* Last item should always be NULL */
  143. };
  144. static struct pt_touch_config *pt_ttconfigs[] = {
  145. #ifdef CONFIG_TOUCHSCREEN_PARADE_PLATFORM_TTCONFIG_UPGRADE
  146. &pt_ttconfig_pid00,
  147. &pt_ttconfig_pid01,
  148. #endif
  149. NULL, /* Last item should always be NULL */
  150. };
  151. struct pt_loader_platform_data _pt_loader_platform_data = {
  152. .fw = &pt_firmware,
  153. .ttconfig = &pt_ttconfig,
  154. .fws = pt_firmwares,
  155. .ttconfigs = pt_ttconfigs,
  156. .flags = PT_LOADER_FLAG_NONE,
  157. };
  158. /*******************************************************************************
  159. * FUNCTION: pt_xres
  160. *
  161. * SUMMARY: Toggles the reset gpio (TP_XRES) to perform a HW reset
  162. *
  163. * RETURN:
  164. * 0 = success
  165. * !0 = fail
  166. *
  167. * PARAMETERS:
  168. * *pdata - pointer to the platform data structure
  169. * *dev - pointer to Device structure
  170. ******************************************************************************/
  171. int pt_xres(struct pt_core_platform_data *pdata,
  172. struct device *dev)
  173. {
  174. int rst_gpio = pdata->rst_gpio;
  175. int rc = 0;
  176. int ddi_rst_gpio = pdata->ddi_rst_gpio;
  177. pt_debug(dev, DL_WARN, "%s: 20ms HARD RESET on gpio=%d\n",
  178. __func__, pdata->rst_gpio);
  179. /* Toggling only TP_XRES as DDI_XRES resets the entire part */
  180. gpio_set_value(rst_gpio, 1);
  181. if (ddi_rst_gpio)
  182. gpio_set_value(ddi_rst_gpio, 1);
  183. usleep_range(3000, 4000);
  184. gpio_set_value(rst_gpio, 0);
  185. usleep_range(6000, 7000);
  186. gpio_set_value(rst_gpio, 1);
  187. if (ddi_rst_gpio)
  188. gpio_set_value(ddi_rst_gpio, 1);
  189. /* Sleep to allow the DUT to boot */
  190. usleep_range(3000, 4000);
  191. return rc;
  192. }
  193. #ifdef PT_PINCTRL_EN
  194. /*******************************************************************************
  195. * FUNCTION: pt_pinctrl_init
  196. *
  197. * SUMMARY: Pinctrl method to obtain pin state handler for TP_RST, IRQ
  198. *
  199. * RETURN:
  200. * 0 = success
  201. * !0 = fail
  202. *
  203. * PARAMETERS:
  204. * *pdata - pointer to the platform data structure
  205. * *dev - pointer to Device structure
  206. ******************************************************************************/
  207. static int pt_pinctrl_init(struct pt_core_platform_data *pdata,
  208. struct device *dev)
  209. {
  210. int ret = 0;
  211. pdata->pinctrl = devm_pinctrl_get(dev);
  212. if (IS_ERR_OR_NULL(pdata->pinctrl)) {
  213. pt_debug(dev, DL_ERROR,
  214. "Failed to get pinctrl, please check dts");
  215. ret = PTR_ERR(pdata->pinctrl);
  216. goto err_pinctrl_get;
  217. }
  218. pdata->pins_active =
  219. pinctrl_lookup_state(pdata->pinctrl, "pmx_ts_active");
  220. if (IS_ERR_OR_NULL(pdata->pins_active)) {
  221. pt_debug(dev, DL_ERROR, "pmx_ts_active not found");
  222. ret = PTR_ERR(pdata->pins_active);
  223. goto err_pinctrl_lookup;
  224. }
  225. pdata->pins_suspend =
  226. pinctrl_lookup_state(pdata->pinctrl, "pmx_ts_suspend");
  227. if (IS_ERR_OR_NULL(pdata->pins_suspend)) {
  228. pt_debug(dev, DL_ERROR, "pmx_ts_suspend not found");
  229. ret = PTR_ERR(pdata->pins_suspend);
  230. goto err_pinctrl_lookup;
  231. }
  232. pdata->pins_release =
  233. pinctrl_lookup_state(pdata->pinctrl, "pmx_ts_release");
  234. if (IS_ERR_OR_NULL(pdata->pins_release)) {
  235. pt_debug(dev, DL_ERROR, "pmx_ts_release not found");
  236. ret = PTR_ERR(pdata->pins_release);
  237. goto err_pinctrl_lookup;
  238. }
  239. return 0;
  240. err_pinctrl_lookup:
  241. devm_pinctrl_put(pdata->pinctrl);
  242. err_pinctrl_get:
  243. pdata->pinctrl = NULL;
  244. pdata->pins_release = NULL;
  245. pdata->pins_suspend = NULL;
  246. pdata->pins_active = NULL;
  247. return ret;
  248. }
  249. /*******************************************************************************
  250. * FUNCTION: pt_pinctrl_select_normal
  251. *
  252. * SUMMARY: Pinctrl method to configure drive mode for TP_RST, IRQ - normal
  253. *
  254. * RETURN:
  255. * 0 = success
  256. * !0 = fail
  257. *
  258. * PARAMETERS:
  259. * *pdata - pointer to the platform data structure
  260. * *dev - pointer to Device structure
  261. ******************************************************************************/
  262. static int pt_pinctrl_select_normal(struct pt_core_platform_data *pdata,
  263. struct device *dev)
  264. {
  265. int ret = 0;
  266. if (pdata->pinctrl && pdata->pins_active) {
  267. ret = pinctrl_select_state(pdata->pinctrl, pdata->pins_active);
  268. if (ret < 0) {
  269. pt_debug(dev, DL_ERROR, "Set normal pin state error=%d",
  270. ret);
  271. }
  272. }
  273. return ret;
  274. }
  275. /*******************************************************************************
  276. * FUNCTION: pt_pinctrl_select_suspend
  277. *
  278. * SUMMARY: Pinctrl method to configure drive mode for TP_RST, IRQ - suspend
  279. *
  280. * RETURN:
  281. * 0 = success
  282. * !0 = fail
  283. *
  284. * PARAMETERS:
  285. * *pdata - pointer to the platform data structure
  286. * *dev - pointer to Device structure
  287. ******************************************************************************/
  288. static int pt_pinctrl_select_suspend(struct pt_core_platform_data *pdata,
  289. struct device *dev)
  290. {
  291. int ret = 0;
  292. if (pdata->pinctrl && pdata->pins_suspend) {
  293. ret = pinctrl_select_state(pdata->pinctrl, pdata->pins_suspend);
  294. if (ret < 0) {
  295. pt_debug(dev, DL_ERROR,
  296. "Set suspend pin state error=%d", ret);
  297. }
  298. }
  299. return ret;
  300. }
  301. /*******************************************************************************
  302. * FUNCTION: pt_pinctrl_select_release
  303. *
  304. * SUMMARY: Pinctrl method to configure drive mode for TP_RST, IRQ - release
  305. *
  306. * RETURN:
  307. * 0 = success
  308. * !0 = fail
  309. *
  310. * PARAMETERS:
  311. * *pdata - pointer to the platform data structure
  312. * *dev - pointer to Device structure
  313. ******************************************************************************/
  314. static int pt_pinctrl_select_release(struct pt_core_platform_data *pdata,
  315. struct device *dev)
  316. {
  317. int ret = 0;
  318. if (pdata->pinctrl) {
  319. if (IS_ERR_OR_NULL(pdata->pins_release)) {
  320. devm_pinctrl_put(pdata->pinctrl);
  321. pdata->pinctrl = NULL;
  322. } else {
  323. ret = pinctrl_select_state(pdata->pinctrl,
  324. pdata->pins_release);
  325. if (ret < 0)
  326. pt_debug(dev, DL_ERROR,
  327. "Set gesture pin state error=%d", ret);
  328. }
  329. }
  330. return ret;
  331. }
  332. #endif /* PT_PINCTRL_EN */
  333. #ifdef PT_REGULATOR_EN
  334. #define PT_VCC_MIN_UV (2800000)
  335. #define PT_VCC_MAX_UV (3300000)
  336. #define PT_VDDI_MIN_UV (1800000)
  337. #define PT_VDDI_MAX_UV (1900000)
  338. /*******************************************************************************
  339. * FUNCTION: pt_regulator_init
  340. *
  341. * SUMMARY: With regulator framework to get regulator handle and setup voltage
  342. * level.
  343. *
  344. * NOTE: The function only contains setup for VCC and VDDI since AVDD AVEE is
  345. * usually used by TDDI products while the power is setup on other driver.
  346. *
  347. * RETURN:
  348. * 0 = success
  349. * !0 = fail
  350. *
  351. * PARAMETERS:
  352. * *pdata - pointer to the platform data structure
  353. * *dev - pointer to Device structure
  354. ******************************************************************************/
  355. static int pt_regulator_init(struct pt_core_platform_data *pdata,
  356. struct device *dev)
  357. {
  358. int rc = 0;
  359. pdata->vcc = devm_regulator_get(dev, "vcc");
  360. if (IS_ERR(pdata->vcc)) {
  361. rc = PTR_ERR(pdata->vcc);
  362. pt_debug(dev, DL_ERROR, "get vcc regulator failed,rc=%d", rc);
  363. return rc;
  364. }
  365. if (regulator_count_voltages(pdata->vcc) > 0) {
  366. rc = regulator_set_voltage(pdata->vcc, PT_VCC_MIN_UV,
  367. PT_VCC_MAX_UV);
  368. if (rc) {
  369. pt_debug(dev, DL_ERROR,
  370. "set vcc regulator failed rc=%d", rc);
  371. goto error_set_vcc;
  372. }
  373. }
  374. pdata->vddi = devm_regulator_get(dev, "vddi");
  375. if (IS_ERR(pdata->vddi)) {
  376. rc = PTR_ERR(pdata->vddi);
  377. pt_debug(dev, DL_ERROR, "get vddi regulator failed,rc=%d", rc);
  378. goto error_get_vcc;
  379. }
  380. if (regulator_count_voltages(pdata->vddi) > 0) {
  381. rc = regulator_set_voltage(pdata->vddi, PT_VDDI_MIN_UV,
  382. PT_VDDI_MAX_UV);
  383. if (rc) {
  384. pt_debug(dev, DL_ERROR,
  385. "set vddi regulator failed rc=%d", rc);
  386. goto error_set_vddi;
  387. }
  388. }
  389. return 0;
  390. error_set_vddi:
  391. devm_regulator_put(pdata->vddi);
  392. error_get_vcc:
  393. /*
  394. * regulator_set_voltage always select minimum legal voltage between
  395. * min_uV and max_uV. To set the minuV to 0 means to restore the default
  396. * value of regulator. Since regulator_set_voltage is the part to
  397. * release regulator source, it's not necessary to check the returned
  398. * value of it.
  399. */
  400. if (regulator_count_voltages(pdata->vcc) > 0)
  401. regulator_set_voltage(pdata->vcc, 0, PT_VCC_MAX_UV);
  402. error_set_vcc:
  403. devm_regulator_put(pdata->vcc);
  404. return rc;
  405. }
  406. /*******************************************************************************
  407. * FUNCTION: pt_setup_power_by_regulator
  408. *
  409. * SUMMARY: With regulator framework to set power on/off.
  410. *
  411. * NOTE: The function only contains setup for VCC and VDDI since AVDD AVEE is
  412. * usually used by TDDI products while the power is setup on other driver.
  413. *
  414. * NOTE: The timing sequence is the EXAMPLE ONLY for TT7XXX:
  415. * power up order : VDDI, VCC
  416. * power down order : VCC, VDDI
  417. *
  418. * RETURN:
  419. * 0 = success
  420. * !0 = fail
  421. *
  422. * PARAMETERS:
  423. * *pdata - pointer to the platform data structure
  424. * on - flag to decide power state,PT_MT_POWER_ON/PT_MT_POWER_OFF
  425. * *dev - pointer to Device structure
  426. ******************************************************************************/
  427. static int pt_setup_power_by_regulator(struct pt_core_platform_data *pdata,
  428. int on, struct device *dev)
  429. {
  430. int rc = 0;
  431. if (IS_ERR(pdata->vddi) || IS_ERR(pdata->vcc)) {
  432. pt_debug(dev, DL_ERROR, "vddi or vcc is not valid\n");
  433. return -EINVAL;
  434. }
  435. if (on == PT_MT_POWER_ON) {
  436. rc = regulator_enable(pdata->vddi);
  437. if (rc) {
  438. pt_debug(dev, DL_ERROR,
  439. "enable vddi regulator failed,rc=%d", rc);
  440. }
  441. /* Ensure the power goes stable */
  442. usleep_range(3000, 4000);
  443. rc = regulator_enable(pdata->vcc);
  444. if (rc) {
  445. pt_debug(dev, DL_ERROR,
  446. "enable vcc regulator failed,rc=%d", rc);
  447. }
  448. /* Ensure the power goes stable */
  449. usleep_range(3000, 4000);
  450. } else {
  451. rc = regulator_disable(pdata->vcc);
  452. if (rc) {
  453. pt_debug(dev, DL_ERROR,
  454. "disable vcc regulator failed,rc=%d", rc);
  455. }
  456. rc = regulator_disable(pdata->vddi);
  457. if (rc) {
  458. pt_debug(dev, DL_ERROR,
  459. "disable vddi regulator failed,rc=%d", rc);
  460. }
  461. /* Ensure the power ramp down completely */
  462. usleep_range(10000, 12000);
  463. }
  464. return rc;
  465. }
  466. /*******************************************************************************
  467. * FUNCTION: pt_regulator_release
  468. *
  469. * SUMMARY: With regulator framework to release regulator resource
  470. *
  471. * NOTE: The regulator MUST be disabled before this call.
  472. * NOTE: The function only contains setup for VCC and VDDI since AVDD AVEE is
  473. * usually used by TDDI products while the power is setup on other driver.
  474. *
  475. * RETURN:
  476. * 0 = success
  477. * !0 = fail
  478. *
  479. * PARAMETERS:
  480. * *pdata - pointer to the platform data structure
  481. * *dev - pointer to Device structure
  482. ******************************************************************************/
  483. static int pt_regulator_release(struct pt_core_platform_data *pdata,
  484. struct device *dev)
  485. {
  486. if (IS_ERR(pdata->vddi) || IS_ERR(pdata->vcc))
  487. return -EINVAL;
  488. /*
  489. * regulator_set_voltage always select minimum legal voltage between
  490. * min_uV and max_uV. To set the minuV to 0 means to restore the default
  491. * value of regulator. Since regulator_set_voltage is the part to
  492. * release regulator source, it's not necessary to check the returned
  493. * value of it.
  494. */
  495. if (regulator_count_voltages(pdata->vddi) > 0)
  496. regulator_set_voltage(pdata->vddi, 0, PT_VDDI_MAX_UV);
  497. devm_regulator_put(pdata->vddi);
  498. if (regulator_count_voltages(pdata->vcc) > 0)
  499. regulator_set_voltage(pdata->vcc, 0, PT_VCC_MAX_UV);
  500. devm_regulator_put(pdata->vcc);
  501. return 0;
  502. }
  503. #endif /* PT_REGULATOR_EN */
  504. /*******************************************************************************
  505. * FUNCTION: pt_init
  506. *
  507. * SUMMARY: Set up/free gpios for TP_RST, IRQ, DDI_RST.
  508. *
  509. * RETURN:
  510. * 0 = success
  511. * !0 = fail
  512. *
  513. * PARAMETERS:
  514. * *pdata - pointer to the platform data structure
  515. * on - flag to set up or free gpios(0:free; !0:set up)
  516. * *dev - pointer to Device structure
  517. ******************************************************************************/
  518. int pt_init(struct pt_core_platform_data *pdata,
  519. int on, struct device *dev)
  520. {
  521. int rst_gpio = pdata->rst_gpio;
  522. int irq_gpio = pdata->irq_gpio;
  523. int ddi_rst_gpio = pdata->ddi_rst_gpio;
  524. int rc = 0;
  525. if (on) {
  526. #ifdef PT_PINCTRL_EN
  527. rc = pt_pinctrl_init(pdata, dev);
  528. if (!rc) {
  529. pt_pinctrl_select_normal(pdata, dev);
  530. } else {
  531. pt_debug(dev, DL_ERROR,
  532. "%s: Failed to request pinctrl\n", __func__);
  533. }
  534. #endif
  535. #ifdef PT_REGULATOR_EN
  536. rc = pt_regulator_init(pdata, dev);
  537. if (rc) {
  538. pt_debug(dev, DL_ERROR,
  539. "%s: Failed requesting regulator rc=%d",
  540. __func__, rc);
  541. }
  542. #endif
  543. }
  544. if (on && rst_gpio) {
  545. /* Configure RST GPIO */
  546. pt_debug(dev, DL_WARN, "%s: Request RST GPIO %d",
  547. __func__, rst_gpio);
  548. rc = gpio_request(rst_gpio, NULL);
  549. if (rc < 0) {
  550. gpio_free(rst_gpio);
  551. rc = gpio_request(rst_gpio, NULL);
  552. }
  553. if (rc < 0) {
  554. pt_debug(dev, DL_ERROR,
  555. "%s: Failed requesting RST GPIO %d\n",
  556. __func__, rst_gpio);
  557. goto fail_rst_gpio;
  558. } else {
  559. /*
  560. * Set the GPIO direction and the starting level
  561. * The start level is high because the DUT needs
  562. * to stay in reset during power up.
  563. */
  564. rc = gpio_direction_output(rst_gpio, 1);
  565. if (rc < 0) {
  566. pt_debug(dev, DL_ERROR,
  567. "%s: Output Setup ERROR: RST GPIO %d\n",
  568. __func__, rst_gpio);
  569. goto fail_rst_gpio;
  570. }
  571. }
  572. }
  573. if (on && irq_gpio) {
  574. /* Configure IRQ GPIO */
  575. pt_debug(dev, DL_WARN, "%s: Request IRQ GPIO %d",
  576. __func__, irq_gpio);
  577. rc = gpio_request(irq_gpio, NULL);
  578. if (rc < 0) {
  579. gpio_free(irq_gpio);
  580. rc = gpio_request(irq_gpio, NULL);
  581. }
  582. if (rc < 0) {
  583. pt_debug(dev, DL_ERROR,
  584. "%s: Failed requesting IRQ GPIO %d\n",
  585. __func__, irq_gpio);
  586. goto fail_irq_gpio;
  587. } else {
  588. /* Set the GPIO direction */
  589. rc = gpio_direction_input(irq_gpio);
  590. if (rc < 0) {
  591. pt_debug(dev, DL_ERROR,
  592. "%s: Input Setup ERROR: IRQ GPIO %d\n",
  593. __func__, irq_gpio);
  594. goto fail_irq_gpio;
  595. }
  596. }
  597. }
  598. if (on && ddi_rst_gpio) {
  599. /* Configure DDI RST GPIO */
  600. pt_debug(dev, DL_WARN, "%s: Request DDI RST GPIO %d",
  601. __func__, ddi_rst_gpio);
  602. rc = gpio_request(ddi_rst_gpio, NULL);
  603. if (rc < 0) {
  604. gpio_free(ddi_rst_gpio);
  605. rc = gpio_request(ddi_rst_gpio, NULL);
  606. }
  607. if (rc < 0) {
  608. pt_debug(dev, DL_ERROR,
  609. "%s: Failed requesting DDI RST GPIO %d\n",
  610. __func__, ddi_rst_gpio);
  611. goto fail_ddi_rst_gpio;
  612. } else {
  613. /* Set the GPIO direction and the starting level */
  614. rc = gpio_direction_output(ddi_rst_gpio, 0);
  615. if (rc < 0) {
  616. pt_debug(dev, DL_ERROR,
  617. "%s: Output Setup ERROR: RST GPIO %d\n",
  618. __func__, ddi_rst_gpio);
  619. goto fail_ddi_rst_gpio;
  620. }
  621. }
  622. }
  623. if (!on) {
  624. /* "on" not set, therefore free all gpio's */
  625. if (ddi_rst_gpio)
  626. gpio_free(ddi_rst_gpio);
  627. if (irq_gpio)
  628. gpio_free(irq_gpio);
  629. if (rst_gpio)
  630. gpio_free(rst_gpio);
  631. #ifdef PT_REGULATOR_EN
  632. pt_regulator_release(pdata, dev);
  633. #endif
  634. #ifdef PT_PINCTRL_EN
  635. pt_pinctrl_select_release(pdata, dev);
  636. #endif
  637. }
  638. /* All GPIO's created successfully */
  639. goto success;
  640. fail_ddi_rst_gpio:
  641. pt_debug(dev, DL_ERROR,
  642. "%s: ERROR - GPIO setup Failure, freeing DDI_XRES GPIO %d\n",
  643. __func__, ddi_rst_gpio);
  644. gpio_free(ddi_rst_gpio);
  645. fail_irq_gpio:
  646. pt_debug(dev, DL_ERROR,
  647. "%s: ERROR - GPIO setup Failure, freeing IRQ GPIO %d\n",
  648. __func__, irq_gpio);
  649. gpio_free(irq_gpio);
  650. fail_rst_gpio:
  651. pt_debug(dev, DL_ERROR,
  652. "%s: ERROR - GPIO setup Failure, freeing TP_XRES GPIO %d\n",
  653. __func__, rst_gpio);
  654. gpio_free(rst_gpio);
  655. success:
  656. pt_debug(dev, DL_INFO,
  657. "%s: SUCCESS - Configured DDI_XRES GPIO %d, IRQ GPIO %d, TP_XRES GPIO %d\n",
  658. __func__, ddi_rst_gpio, irq_gpio, rst_gpio);
  659. return rc;
  660. }
  661. /*******************************************************************************
  662. * FUNCTION: pt_irq_stat
  663. *
  664. * SUMMARY: Obtain the level state of IRQ gpio.
  665. *
  666. * RETURN:
  667. * level state of IRQ gpio
  668. *
  669. * PARAMETERS:
  670. * *pdata - pointer to the platform data structure
  671. * *dev - pointer to Device structure
  672. ******************************************************************************/
  673. int pt_irq_stat(struct pt_core_platform_data *pdata,
  674. struct device *dev)
  675. {
  676. return gpio_get_value(pdata->irq_gpio);
  677. }
  678. #ifdef PT_DETECT_HW
  679. /*******************************************************************************
  680. * FUNCTION: pt_detect
  681. *
  682. * SUMMARY: Detect the I2C device by reading one byte(FW sentiel) after the
  683. * reset operation.
  684. *
  685. * RETURN:
  686. * 0 - detected
  687. * !0 - undetected
  688. *
  689. * PARAMETERS:
  690. * *pdata - pointer to the platform data structure
  691. * *dev - pointer to Device structure
  692. * read - pointer to the function to perform a read operation
  693. ******************************************************************************/
  694. int pt_detect(struct pt_core_platform_data *pdata,
  695. struct device *dev, pt_platform_read read)
  696. {
  697. int retry = 3;
  698. int rc;
  699. char buf[1];
  700. while (retry--) {
  701. /* Perform reset, wait for 100 ms and perform read */
  702. pt_debug(dev, DL_WARN, "%s: Performing a reset\n",
  703. __func__);
  704. pdata->xres(pdata, dev);
  705. msleep(100);
  706. rc = read(dev, buf, 1);
  707. if (!rc)
  708. return 0;
  709. pt_debug(dev, DL_ERROR, "%s: Read unsuccessful, try=%d\n",
  710. __func__, 3 - retry);
  711. }
  712. return rc;
  713. }
  714. #endif
  715. #ifndef PT_REGULATOR_EN
  716. /*******************************************************************************
  717. * FUNCTION: pt_setup_power_by_gpio
  718. *
  719. * SUMMARY: With GPIOs to control LDO directly to set power on/off.
  720. *
  721. * RETURN:
  722. * 0 = success
  723. * !0 = fail
  724. *
  725. * PARAMETERS:
  726. * *pdata - pointer to the platform data structure
  727. * on - flag to decide power state,PT_MT_POWER_ON/PT_MT_POWER_OFF
  728. * *dev - pointer to Device structure
  729. ******************************************************************************/
  730. static int pt_setup_power_by_gpio(struct pt_core_platform_data *pdata,
  731. int on, struct device *dev)
  732. {
  733. int rc = 0;
  734. int en_vcc = pdata->vcc_gpio;
  735. int en_vddi = pdata->vddi_gpio;
  736. int en_avdd = pdata->avdd_gpio;
  737. int en_avee = pdata->avee_gpio;
  738. if (on == PT_MT_POWER_ON) {
  739. /*
  740. * Enable GPIOs to turn on voltage regulators to pwr up DUT
  741. * - TC device power up order: VDDI, VCC, AVDD, AVEE
  742. * - TT device power up order: VDDI, VCC
  743. * NOTE: VDDI must be stable for >10ms before XRES is released
  744. */
  745. pt_debug(dev, DL_INFO,
  746. "%s: Enable defined pwr: VDDI, VCC, AVDD, AVEE\n", __func__);
  747. /* Turn on VDDI [Digital Interface] (+1.8v) */
  748. if (pdata->vddi_gpio) {
  749. rc = gpio_request(en_vddi, NULL);
  750. if (rc < 0) {
  751. gpio_free(en_vddi);
  752. rc = gpio_request(en_vddi, NULL);
  753. }
  754. if (rc < 0) {
  755. pr_err("%s: Failed requesting VDDI GPIO %d\n",
  756. __func__, en_vddi);
  757. }
  758. rc = gpio_direction_output(en_vddi, 1);
  759. if (rc)
  760. pr_err("%s: setcfg for VDDI GPIO %d failed\n",
  761. __func__, en_vddi);
  762. gpio_free(en_vddi);
  763. usleep_range(3000, 4000);
  764. }
  765. /* Turn on VCC */
  766. if (pdata->vcc_gpio) {
  767. rc = gpio_request(en_vcc, NULL);
  768. if (rc < 0) {
  769. gpio_free(en_vcc);
  770. rc = gpio_request(en_vcc, NULL);
  771. }
  772. if (rc < 0) {
  773. pr_err("%s: Failed requesting VCC GPIO %d\n",
  774. __func__, en_vcc);
  775. }
  776. rc = gpio_direction_output(en_vcc, 1);
  777. if (rc)
  778. pr_err("%s: setcfg for VCC GPIO %d failed\n",
  779. __func__, en_vcc);
  780. gpio_free(en_vcc);
  781. usleep_range(3000, 4000);
  782. }
  783. /* Turn on AVDD (+5.0v) */
  784. if (pdata->avdd_gpio) {
  785. rc = gpio_request(en_avdd, NULL);
  786. if (rc < 0) {
  787. gpio_free(en_avdd);
  788. rc = gpio_request(en_avdd, NULL);
  789. }
  790. if (rc < 0) {
  791. pr_err("%s: Failed requesting AVDD GPIO %d\n",
  792. __func__, en_avdd);
  793. }
  794. rc = gpio_direction_output(en_avdd, 1);
  795. if (rc)
  796. pr_err("%s: setcfg for AVDD GPIO %d failed\n",
  797. __func__, en_avdd);
  798. gpio_free(en_avdd);
  799. usleep_range(3000, 4000);
  800. }
  801. /* Turn on AVEE (-5.0v) */
  802. if (pdata->avee_gpio) {
  803. rc = gpio_request(en_avee, NULL);
  804. if (rc < 0) {
  805. gpio_free(en_avee);
  806. rc = gpio_request(en_avee, NULL);
  807. }
  808. if (rc < 0) {
  809. pr_err("%s: Failed requesting AVEE GPIO %d\n",
  810. __func__, en_avee);
  811. }
  812. rc = gpio_direction_output(en_avee, 1);
  813. if (rc)
  814. pr_err("%s: setcfg for AVEE GPIO %d failed\n",
  815. __func__, en_avee);
  816. gpio_free(en_avee);
  817. usleep_range(3000, 4000);
  818. }
  819. } else {
  820. /*
  821. * Disable GPIOs to turn off voltage regulators to pwr down
  822. * TC device The power down order is: AVEE, AVDD, VDDI
  823. * TT device The power down order is: VCC, VDDI
  824. *
  825. * Note:Turn off some of regulators may effect display
  826. * parts for TDDI chip
  827. */
  828. pt_debug(dev, DL_INFO,
  829. "%s: Turn off defined pwr: VCC, AVEE, AVDD, VDDI\n", __func__);
  830. /* Turn off VCC */
  831. if (pdata->vcc_gpio) {
  832. rc = gpio_request(en_vcc, NULL);
  833. if (rc < 0) {
  834. gpio_free(en_vcc);
  835. rc = gpio_request(en_vcc, NULL);
  836. }
  837. if (rc < 0) {
  838. pr_err("%s: Failed requesting VCC GPIO %d\n",
  839. __func__, en_vcc);
  840. }
  841. rc = gpio_direction_output(en_vcc, 0);
  842. if (rc)
  843. pr_err("%s: setcfg for VCC GPIO %d failed\n",
  844. __func__, en_vcc);
  845. gpio_free(en_vcc);
  846. }
  847. /* Turn off AVEE (-5.0v) */
  848. if (pdata->avee_gpio) {
  849. rc = gpio_request(en_avee, NULL);
  850. if (rc < 0) {
  851. gpio_free(en_avee);
  852. rc = gpio_request(en_avee, NULL);
  853. }
  854. if (rc < 0) {
  855. pr_err("%s: Failed requesting AVEE GPIO %d\n",
  856. __func__, en_avee);
  857. }
  858. rc = gpio_direction_output(en_avee, 0);
  859. if (rc)
  860. pr_err("%s: setcfg for AVEE GPIO %d failed\n",
  861. __func__, en_avee);
  862. gpio_free(en_avee);
  863. }
  864. /* Turn off AVDD (+5.0v) */
  865. if (pdata->avdd_gpio) {
  866. rc = gpio_request(en_avdd, NULL);
  867. if (rc < 0) {
  868. gpio_free(en_avdd);
  869. rc = gpio_request(en_avdd, NULL);
  870. }
  871. if (rc < 0) {
  872. pr_err("%s: Failed requesting AVDD GPIO %d\n",
  873. __func__, en_avdd);
  874. }
  875. rc = gpio_direction_output(en_avdd, 0);
  876. if (rc)
  877. pr_err("%s: setcfg for AVDD GPIO %d failed\n",
  878. __func__, en_avdd);
  879. gpio_free(en_avdd);
  880. }
  881. /* Turn off VDDI [Digital Interface] (+1.8v) */
  882. if (pdata->vddi_gpio) {
  883. rc = gpio_request(en_vddi, NULL);
  884. if (rc < 0) {
  885. gpio_free(en_vddi);
  886. rc = gpio_request(en_vddi, NULL);
  887. }
  888. if (rc < 0) {
  889. pr_err("%s: Failed requesting VDDI GPIO %d\n",
  890. __func__, en_vddi);
  891. }
  892. rc = gpio_direction_output(en_vddi, 0);
  893. if (rc)
  894. pr_err("%s: setcfg for VDDI GPIO %d failed\n",
  895. __func__, en_vddi);
  896. gpio_free(en_vddi);
  897. usleep_range(10000, 12000);
  898. }
  899. }
  900. return rc;
  901. }
  902. #endif /* PT_REGULATOR_EN */
  903. /*******************************************************************************
  904. * FUNCTION: pt_setup_power
  905. *
  906. * SUMMARY: Turn on/turn off voltage regulator
  907. *
  908. * RETURN:
  909. * 0 = success
  910. * !0 = failure
  911. *
  912. * PARAMETERS:
  913. * *pdata - pointer to core platform data
  914. * on - flag to decide power state,PT_MT_POWER_ON/PT_MT_POWER_OFF
  915. * *dev - pointer to device
  916. ******************************************************************************/
  917. int pt_setup_power(struct pt_core_platform_data *pdata, int on,
  918. struct device *dev)
  919. {
  920. int rc = 0;
  921. /*
  922. * For TDDI parts, force part into RESET by holding DDI XRES
  923. * while powering it up
  924. */
  925. if (pdata->ddi_rst_gpio)
  926. gpio_set_value(pdata->ddi_rst_gpio, 0);
  927. /*
  928. * Force part into RESET by holding XRES#(TP_XRES)
  929. * while powering it up
  930. */
  931. if (pdata->rst_gpio)
  932. gpio_set_value(pdata->rst_gpio, 0);
  933. #ifdef PT_REGULATOR_EN
  934. rc = pt_setup_power_by_regulator(pdata, on, dev);
  935. if (rc) {
  936. pt_debug(dev, DL_ERROR,
  937. "%s: Failed setup power by regulator rc=%d",
  938. __func__, rc);
  939. }
  940. #else /* PT_REGULATOR_EN */
  941. rc = pt_setup_power_by_gpio(pdata, on, dev);
  942. if (rc) {
  943. pt_debug(dev, DL_ERROR,
  944. "%s: Failed setup power by gpio rc=%d",
  945. __func__, rc);
  946. }
  947. #endif /* PT_REGULATOR_EN */
  948. /* Force part out of RESET by releasing XRES#(TP_XRES) */
  949. if (pdata->rst_gpio)
  950. gpio_set_value(pdata->rst_gpio, 1);
  951. /* Force part out of RESET by releasing DDI XRES */
  952. if (pdata->ddi_rst_gpio)
  953. gpio_set_value(pdata->ddi_rst_gpio, 1);
  954. return rc;
  955. }
  956. /*******************************************************************************
  957. * FUNCTION: pt_wakeup
  958. *
  959. * SUMMARY: Resume power for "power on/off" sleep strategy which against to
  960. * "deepsleep" strategy.
  961. *
  962. * RETURN:
  963. * 0 = success
  964. * !0 = fail
  965. *
  966. * PARAMETERS:
  967. * *pdata - pointer to the platform data structure
  968. * *dev - pointer to Device structure
  969. * *ignore_irq - pointer to atomic structure to allow the host ignoring false
  970. * IRQ during power up
  971. ******************************************************************************/
  972. static int pt_wakeup(struct pt_core_platform_data *pdata,
  973. struct device *dev, atomic_t *ignore_irq)
  974. {
  975. int rc = 0;
  976. #ifdef PT_PINCTRL_EN
  977. pt_pinctrl_select_normal(pdata, dev);
  978. #endif
  979. rc = pt_setup_power(pdata, PT_MT_POWER_ON, dev);
  980. if (rc)
  981. pt_debug(dev, DL_ERROR, "%s: Failed setup power\n", __func__);
  982. return rc;
  983. }
  984. /*******************************************************************************
  985. * FUNCTION: pt_sleep
  986. *
  987. * SUMMARY: Suspend power for "power on/off" sleep strategy which against to
  988. * "deepsleep" strategy.
  989. *
  990. * RETURN:
  991. * 0 = success
  992. * !0 = fail
  993. *
  994. * PARAMETERS:
  995. * *pdata - pointer to the platform data structure
  996. * *dev - pointer to Device structure
  997. * *ignore_irq - pointer to atomic structure to allow the host ignoring false
  998. * IRQ during power down
  999. ******************************************************************************/
  1000. static int pt_sleep(struct pt_core_platform_data *pdata,
  1001. struct device *dev, atomic_t *ignore_irq)
  1002. {
  1003. int rc = 0;
  1004. rc = pt_setup_power(pdata, PT_MT_POWER_OFF, dev);
  1005. if (rc)
  1006. pt_debug(dev, DL_ERROR, "%s: Failed setup power\n", __func__);
  1007. #ifdef PT_PINCTRL_EN
  1008. pt_pinctrl_select_suspend(pdata, dev);
  1009. #endif
  1010. return rc;
  1011. }
  1012. /*******************************************************************************
  1013. * FUNCTION: pt_power
  1014. *
  1015. * SUMMARY: Wrapper function to resume/suspend power with function
  1016. * pt_wakeup()/pt_sleep().
  1017. *
  1018. * RETURN:
  1019. * 0 = success
  1020. * !0 = fail
  1021. *
  1022. * PARAMETERS:
  1023. * *pdata - pointer to the platform data structure
  1024. * on - flag to remsume/suspend power(0:resume; 1:suspend)
  1025. * *dev - pointer to Device structure
  1026. * *ignore_irq - pointer to atomic structure to allow the host ignoring false
  1027. * IRQ during power up/down
  1028. ******************************************************************************/
  1029. int pt_power(struct pt_core_platform_data *pdata,
  1030. int on, struct device *dev, atomic_t *ignore_irq)
  1031. {
  1032. if (on)
  1033. return pt_wakeup(pdata, dev, ignore_irq);
  1034. return pt_sleep(pdata, dev, ignore_irq);
  1035. }
  1036. #ifdef PT_PTSBC_SUPPORT
  1037. static struct workqueue_struct *parade_wq;
  1038. static u32 int_handle;
  1039. /*******************************************************************************
  1040. * FUNCTION: pt_irq_work_function
  1041. *
  1042. * SUMMARY: Work function for queued IRQ activity
  1043. *
  1044. * RETURN: Void
  1045. *
  1046. * PARAMETERS:
  1047. * *work - pointer to work structure
  1048. ******************************************************************************/
  1049. static void pt_irq_work_function(struct work_struct *work)
  1050. {
  1051. struct pt_core_data *cd = container_of(work,
  1052. struct pt_core_data, irq_work);
  1053. pt_irq(cd->irq, (void *)cd);
  1054. }
  1055. /*******************************************************************************
  1056. * FUNCTION: pt_irq_wrapper
  1057. *
  1058. * SUMMARY: Wrapper function for IRQ to queue the irq_work function
  1059. *
  1060. * RETURN:
  1061. * 0 = success
  1062. * !0 = failure
  1063. *
  1064. * PARAMETERS:
  1065. * *handle - void pointer to contain the core_data pointer
  1066. ******************************************************************************/
  1067. peint_handle *pt_irq_wrapper(void *handle)
  1068. {
  1069. struct pt_core_data *cd = (struct pt_core_data *)handle;
  1070. queue_work(parade_wq, &cd->irq_work);
  1071. return 0;
  1072. }
  1073. #endif /* PT_PTSBC_SUPPORT */
  1074. /*******************************************************************************
  1075. * FUNCTION: pt_setup_irq
  1076. *
  1077. * SUMMARY: Configure the IRQ GPIO used by the TT DUT
  1078. *
  1079. * RETURN:
  1080. * 0 = success
  1081. * !0 = failure
  1082. *
  1083. * PARAMETERS:
  1084. * *pdata - pointer to core platform data
  1085. * on - flag to setup interrupt process work(PT_MT_IRQ_FREE/)
  1086. * *dev - pointer to device
  1087. ******************************************************************************/
  1088. int pt_setup_irq(struct pt_core_platform_data *pdata, int on,
  1089. struct device *dev)
  1090. {
  1091. struct pt_core_data *cd = dev_get_drvdata(dev);
  1092. unsigned long irq_flags;
  1093. int rc = 0;
  1094. if (on == PT_MT_IRQ_REG) {
  1095. /*
  1096. * When TTDL has direct access to the GPIO the irq_stat function
  1097. * will be defined and the gpio_to_irq conversion must be
  1098. * performed. e.g. For CHROMEOS this is not the case, the irq is
  1099. * passed in directly.
  1100. */
  1101. if (pdata->irq_stat) {
  1102. /* Initialize IRQ */
  1103. dev_vdbg(dev, "%s: Value Passed to gpio_to_irq =%d\n",
  1104. __func__, pdata->irq_gpio);
  1105. cd->irq = gpio_to_irq(pdata->irq_gpio);
  1106. dev_vdbg(dev,
  1107. "%s: Value Returned from gpio_to_irq =%d\n",
  1108. __func__, cd->irq);
  1109. }
  1110. if (cd->irq < 0)
  1111. return -EINVAL;
  1112. cd->irq_enabled = true;
  1113. pt_debug(dev, DL_INFO, "%s: initialize threaded irq=%d\n",
  1114. __func__, cd->irq);
  1115. if (pdata->level_irq_udelay > 0)
  1116. #ifdef PT_PTSBC_SUPPORT
  1117. /* use level triggered interrupts */
  1118. irq_flags = TRIG_LEVL_LOW;
  1119. else
  1120. /* use edge triggered interrupts */
  1121. irq_flags = TRIG_EDGE_NEGATIVE;
  1122. #else
  1123. /* use level triggered interrupts */
  1124. irq_flags = IRQF_TRIGGER_LOW | IRQF_ONESHOT;
  1125. else
  1126. /* use edge triggered interrupts */
  1127. irq_flags = IRQF_TRIGGER_FALLING | IRQF_ONESHOT;
  1128. #endif /* PT_PTSBC_SUPPORT */
  1129. #ifdef PT_PTSBC_SUPPORT
  1130. /* Adding new work queue to cd struct */
  1131. INIT_WORK(&cd->irq_work, pt_irq_work_function);
  1132. parade_wq = create_singlethread_workqueue("parade_wq");
  1133. if (!parade_wq)
  1134. pt_debug(dev, DL_ERROR, "%s Create workqueue failed.\n",
  1135. __func__);
  1136. int_handle = sw_gpio_irq_request(pdata->irq_gpio, irq_flags,
  1137. (peint_handle)pt_irq_wrapper, cd);
  1138. if (!int_handle) {
  1139. pt_debug(dev, DL_ERROR,
  1140. "%s: PARADE could not request irq\n", __func__);
  1141. rc = -1;
  1142. } else {
  1143. rc = 0;
  1144. /* clk=0: 32Khz; clk=1: 24Mhz*/
  1145. ctp_set_int_port_rate(pdata->irq_gpio, 1);
  1146. /*
  1147. * Debounce INT Line by clock divider: 2^n. E.g. The
  1148. * para:0x03 means the period of interrupt controller is
  1149. * 0.33 us = (2^3)/24. It has ability to measure the
  1150. * high/low width of the pulse bigger than 1 us.
  1151. */
  1152. ctp_set_int_port_deb(pdata->irq_gpio, 0x03);
  1153. pt_debug(cd->dev, DL_INFO,
  1154. "%s: Parade sw_gpio_irq_request SUCCESS\n",
  1155. __func__);
  1156. }
  1157. #else
  1158. rc = request_threaded_irq(cd->irq, NULL, pt_irq,
  1159. irq_flags, dev_name(dev), cd);
  1160. if (rc < 0)
  1161. pt_debug(dev, DL_ERROR,
  1162. "%s: Error, could not request irq\n", __func__);
  1163. #endif /* PT_PTSBC_SUPPORT */
  1164. } else {
  1165. disable_irq_nosync(cd->irq);
  1166. #ifndef PT_PTSBC_SUPPORT
  1167. free_irq(cd->irq, cd);
  1168. #else
  1169. sw_gpio_irq_free(int_handle);
  1170. cancel_work_sync(&cd->irq_work);
  1171. destroy_workqueue(parade_wq);
  1172. #endif /* PT_PTSBC_SUPPORT */
  1173. }
  1174. return rc;
  1175. }