wmt_gpio.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. /*
  2. * Copyright (C) 2011-2014 MediaTek Inc.
  3. *
  4. * This program is free software: you can redistribute it and/or modify it under the terms of the
  5. * GNU General Public License version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  8. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. * See the GNU General Public License for more details.
  10. *
  11. * You should have received a copy of the GNU General Public License along with this program.
  12. * If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #include "wmt_gpio.h"
  15. /*******************************************************************************
  16. * C O M P I L E R F L A G S
  17. ********************************************************************************
  18. */
  19. /*******************************************************************************
  20. * M A C R O S
  21. ********************************************************************************
  22. */
  23. /*******************************************************************************
  24. * P U B L I C D A T A
  25. ********************************************************************************
  26. */
  27. const PUINT8 gpio_state_name[GPIO_PIN_ID_MAX][GPIO_STATE_MAX] = {{"gpio_ldo_en_pull_dis",
  28. "",
  29. "",
  30. "",
  31. "",
  32. "",
  33. "",
  34. "",
  35. "gpio_ldo_en_in_pulldown",
  36. ""},
  37. {"gpio_pmuv28_pull_dis",
  38. "",
  39. "",
  40. "",
  41. "",
  42. "",
  43. "",
  44. "",
  45. "gpio_pmuv28_in_pulldown",
  46. ""},
  47. {"gpio_pmu_en_pull_dis",
  48. "",
  49. "",
  50. "",
  51. "",
  52. "",
  53. "",
  54. "",
  55. "gpio_pmu_en_in_pulldown",
  56. ""},
  57. {"gpio_rst_pull_dis",
  58. "",
  59. "",
  60. "",
  61. "",
  62. "",
  63. "",
  64. "",
  65. "",
  66. ""},
  67. {"",
  68. "",
  69. "",
  70. "",
  71. "",
  72. "",
  73. "",
  74. "",
  75. "gpio_bgf_eint_in_pulldown",
  76. "gpio_bgf_eint_in_pullup"},
  77. {"",
  78. "",
  79. "",
  80. "",
  81. "",
  82. "",
  83. "",
  84. "gpio_wifi_eint_in_pull_dis",
  85. "",
  86. "gpio_wifi_eint_in_pullup"},
  87. {"",
  88. "",
  89. "",
  90. "",
  91. "",
  92. "",
  93. "",
  94. "",
  95. "gpio_all_eint_in_pulldown",
  96. "gpio_all_eint_in_pullup"},
  97. {"gpio_urxd_uart_pull_dis",
  98. "",
  99. "",
  100. "",
  101. "",
  102. "",
  103. "",
  104. "gpio_urxd_gpio_in_pull_dis",
  105. "",
  106. "gpio_urxd_gpio_in_pullup"},
  107. {"gpio_utxd_uart_pull_dis",
  108. "",
  109. "",
  110. "",
  111. "",
  112. "",
  113. "",
  114. "",
  115. "",
  116. ""},
  117. {"gpio_pcm_daiclk_pull_dis",
  118. "",
  119. "",
  120. "",
  121. "",
  122. "",
  123. "",
  124. "",
  125. "",
  126. ""},
  127. {"gpio_pcm_daipcmin_pull_dis",
  128. "",
  129. "",
  130. "",
  131. "",
  132. "",
  133. "",
  134. "",
  135. "",
  136. ""},
  137. {"gpio_pcm_daipcmout_pull_dis",
  138. "",
  139. "",
  140. "",
  141. "",
  142. "",
  143. "",
  144. "",
  145. "",
  146. ""},
  147. {"gpio_pcm_daisync_pull_dis",
  148. "",
  149. "",
  150. "",
  151. "",
  152. "",
  153. "",
  154. "",
  155. "",
  156. ""},
  157. {"gpio_i2s_ck_pull_dis",
  158. "",
  159. "",
  160. "",
  161. "",
  162. "",
  163. "",
  164. "",
  165. "",
  166. ""},
  167. {"gpio_i2s_ws_pull_dis",
  168. "",
  169. "",
  170. "",
  171. "",
  172. "",
  173. "",
  174. "",
  175. "",
  176. ""},
  177. {"gpio_i2s_dat_pull_dis",
  178. "",
  179. "",
  180. "",
  181. "",
  182. "",
  183. "",
  184. "",
  185. "",
  186. ""},
  187. {"gpio_gps_sync_pull_dis",
  188. "",
  189. "",
  190. "",
  191. "",
  192. "",
  193. "",
  194. "",
  195. "",
  196. ""},
  197. {"gpio_gps_lna_pull_dis",
  198. "",
  199. "",
  200. "",
  201. "",
  202. "",
  203. "",
  204. "",
  205. "",
  206. ""}
  207. };
  208. const PUINT8 gpio_pin_name[GPIO_PIN_ID_MAX] = {"gpio_combo_ldo_en_pin",
  209. "gpio_combo_pmuv28_en_pin",
  210. "gpio_combo_pmu_en_pin",
  211. "gpio_combo_rst_pin",
  212. "gpio_combo_bgf_eint_pin",
  213. "gpio_wifi_eint_pin",
  214. "gpio_all_eint_pin",
  215. "gpio_combo_urxd_pin",
  216. "gpio_combo_utxd_pin",
  217. "gpio_pcm_daiclk_pin",
  218. "gpio_pcm_daipcmin_pin",
  219. "gpio_pcm_daipcmout_pin",
  220. "gpio_pcm_daisync_pin",
  221. "gpio_combo_i2s_ck_pin",
  222. "gpio_combo_i2s_ws_pin",
  223. "gpio_combo_i2s_dat_pin",
  224. "gpio_gps_sync_pin",
  225. "gpio_gps_lna_pin"};
  226. GPIO_CTRL_INFO gpio_ctrl_info;
  227. /*******************************************************************************
  228. * F U N C T I O N S
  229. ********************************************************************************
  230. */
  231. INT32 wmt_gpio_init(struct platform_device *pdev)
  232. {
  233. INT32 iret = 0;
  234. UINT32 i, j;
  235. struct device_node *node;
  236. node = of_find_compatible_node(NULL, NULL, "mediatek,connectivity-combo");
  237. if (!node) {
  238. for (i = 0; i < GPIO_PIN_ID_MAX; i++)
  239. gpio_ctrl_info.gpio_ctrl_state[i].gpio_num = DEFAULT_PIN_ID;
  240. pr_err("wmt_gpio:can't find device tree node!\n");
  241. iret = -1;
  242. goto err;
  243. }
  244. gpio_ctrl_info.pinctrl_info = devm_pinctrl_get(&pdev->dev);
  245. if (gpio_ctrl_info.pinctrl_info) {
  246. for (i = 0; i < GPIO_PIN_ID_MAX; i++) {
  247. gpio_ctrl_info.gpio_ctrl_state[i].gpio_num = of_get_named_gpio(node,
  248. gpio_pin_name[i], 0);
  249. if (gpio_ctrl_info.gpio_ctrl_state[i].gpio_num < 0)
  250. gpio_ctrl_info.gpio_ctrl_state[i].gpio_num = DEFAULT_PIN_ID;
  251. if (DEFAULT_PIN_ID != gpio_ctrl_info.gpio_ctrl_state[i].gpio_num) {
  252. for (j = 0; j < GPIO_STATE_MAX; j++) {
  253. if (0 != strlen(gpio_state_name[i][j])) {
  254. gpio_ctrl_info.gpio_ctrl_state[i].gpio_state[j] =
  255. pinctrl_lookup_state(gpio_ctrl_info.pinctrl_info,
  256. gpio_state_name[i][j]);
  257. } else
  258. gpio_ctrl_info.gpio_ctrl_state[i].gpio_state[j] = NULL;
  259. }
  260. }
  261. }
  262. pr_err("wmt_gpio: gpio init start!\n");
  263. if (gpio_ctrl_info.gpio_ctrl_state[GPIO_COMBO_PMU_EN_PIN].gpio_state[GPIO_PULL_DIS]) {
  264. pinctrl_select_state(gpio_ctrl_info.pinctrl_info,
  265. gpio_ctrl_info.gpio_ctrl_state[GPIO_COMBO_PMU_EN_PIN].
  266. gpio_state[GPIO_PULL_DIS]);
  267. pr_err("wmt_gpio:set GPIO_COMBO_PMU_EN_PIN to GPIO_PULL_DIS done!\n");
  268. } else
  269. pr_err("wmt_gpio:set GPIO_COMBO_PMU_EN_PIN to GPIO_PULL_DIS fail, is NULL!\n");
  270. if (DEFAULT_PIN_ID != gpio_ctrl_info.gpio_ctrl_state[GPIO_COMBO_PMU_EN_PIN].gpio_num) {
  271. gpio_direction_output(gpio_ctrl_info.gpio_ctrl_state[GPIO_COMBO_PMU_EN_PIN].gpio_num,
  272. 0);
  273. pr_err("wmt_gpio:set GPIO_COMBO_PMU_EN_PIN out to 0: %d!\n",
  274. gpio_get_value(gpio_ctrl_info.gpio_ctrl_state[GPIO_COMBO_PMU_EN_PIN].gpio_num));
  275. }
  276. if (gpio_ctrl_info.gpio_ctrl_state[GPIO_COMBO_RST_PIN].gpio_state[GPIO_PULL_DIS]) {
  277. pinctrl_select_state(gpio_ctrl_info.pinctrl_info,
  278. gpio_ctrl_info.gpio_ctrl_state[GPIO_COMBO_RST_PIN].gpio_state[GPIO_PULL_DIS]);
  279. pr_err("wmt_gpio:set GPIO_COMBO_RST_PIN to GPIO_PULL_DIS done!\n");
  280. } else
  281. pr_err("wmt_gpio:set GPIO_COMBO_RST_PIN to GPIO_PULL_DIS fail, is NULL!\n");
  282. if (DEFAULT_PIN_ID != gpio_ctrl_info.gpio_ctrl_state[GPIO_COMBO_RST_PIN].gpio_num) {
  283. gpio_direction_output(gpio_ctrl_info.gpio_ctrl_state[GPIO_COMBO_RST_PIN].gpio_num,
  284. 0);
  285. pr_err("wmt_gpio:set GPIO_COMBO_RST_PIN out to 0: %d!\n",
  286. gpio_get_value(gpio_ctrl_info.gpio_ctrl_state[GPIO_COMBO_RST_PIN].gpio_num));
  287. }
  288. if (gpio_ctrl_info.gpio_ctrl_state[GPIO_WIFI_EINT_PIN].gpio_state[GPIO_IN_PULLUP]) {
  289. pinctrl_select_state(gpio_ctrl_info.pinctrl_info,
  290. gpio_ctrl_info.gpio_ctrl_state[GPIO_WIFI_EINT_PIN].gpio_state[GPIO_IN_PULLUP]);
  291. pr_err("wmt_gpio:set GPIO_WIFI_EINT_PIN to GPIO_IN_PULLUP done!\n");
  292. } else
  293. pr_err("wmt_gpio:set GPIO_WIFI_EINT_PIN to GPIO_IN_PULLUP fail, is NULL!\n");
  294. if (gpio_ctrl_info.gpio_ctrl_state[GPIO_PCM_DAICLK_PIN].gpio_state[GPIO_PULL_DIS]) {
  295. pinctrl_select_state(gpio_ctrl_info.pinctrl_info,
  296. gpio_ctrl_info.gpio_ctrl_state[GPIO_PCM_DAICLK_PIN].gpio_state[GPIO_PULL_DIS]);
  297. pr_err("wmt_gpio:set GPIO_PCM_DAICLK_PIN to GPIO_PULL_DIS done!\n");
  298. } else
  299. pr_err("wmt_gpio:set GPIO_PCM_DAICLK_PIN to GPIO_PULL_DIS fail, is NULL!\n");
  300. if (gpio_ctrl_info.gpio_ctrl_state[GPIO_PCM_DAIPCMIN_PIN].gpio_state[GPIO_PULL_DIS]) {
  301. pinctrl_select_state(gpio_ctrl_info.pinctrl_info,
  302. gpio_ctrl_info.gpio_ctrl_state[GPIO_PCM_DAIPCMIN_PIN].
  303. gpio_state[GPIO_PULL_DIS]);
  304. pr_err("wmt_gpio:set GPIO_PCM_DAIPCMIN_PIN to GPIO_PULL_DIS done!\n");
  305. } else
  306. pr_err("wmt_gpio:set GPIO_PCM_DAIPCMIN_PIN to GPIO_PULL_DIS fail, is NULL!\n");
  307. if (gpio_ctrl_info.gpio_ctrl_state[GPIO_PCM_DAIPCMOUT_PIN].gpio_state[GPIO_PULL_DIS]) {
  308. pinctrl_select_state(gpio_ctrl_info.pinctrl_info,
  309. gpio_ctrl_info.gpio_ctrl_state[GPIO_PCM_DAIPCMOUT_PIN].
  310. gpio_state[GPIO_PULL_DIS]);
  311. pr_err("wmt_gpio:set GPIO_PCM_DAIPCMOUT_PIN to GPIO_PULL_DIS done!\n");
  312. } else
  313. pr_err("wmt_gpio:set GPIO_PCM_DAIPCMOUT_PIN to GPIO_PULL_DIS fail, is NULL!\n");
  314. if (gpio_ctrl_info.gpio_ctrl_state[GPIO_PCM_DAISYNC_PIN].gpio_state[GPIO_PULL_DIS]) {
  315. pinctrl_select_state(gpio_ctrl_info.pinctrl_info,
  316. gpio_ctrl_info.gpio_ctrl_state[GPIO_PCM_DAISYNC_PIN].
  317. gpio_state[GPIO_PULL_DIS]);
  318. pr_err("wmt_gpio:set GPIO_PCM_DAISYNC_PIN to GPIO_PULL_DIS done!\n");
  319. } else
  320. pr_err("wmt_gpio:set GPIO_PCM_DAISYNC_PIN to GPIO_PULL_DIS fail, is NULL!\n");
  321. pr_err("wmt_gpio: gpio init done!\n");
  322. } else {
  323. pr_err("wmt_gpio:can't find pinctrl dev!\n");
  324. iret = -1;
  325. }
  326. err:
  327. return iret;
  328. }
  329. INT32 wmt_gpio_deinit(VOID)
  330. {
  331. INT32 iret = 0;
  332. UINT32 i;
  333. UINT32 j;
  334. for (i = 0; i < GPIO_PIN_ID_MAX; i++) {
  335. gpio_ctrl_info.gpio_ctrl_state[i].gpio_num = DEFAULT_PIN_ID;
  336. if (DEFAULT_PIN_ID != gpio_ctrl_info.gpio_ctrl_state[i].gpio_num) {
  337. for (j = 0; j < GPIO_STATE_MAX; j++) {
  338. if (0 != strlen(gpio_state_name[i][j]))
  339. gpio_ctrl_info.gpio_ctrl_state[i].gpio_state[j] = NULL;
  340. }
  341. }
  342. }
  343. if (gpio_ctrl_info.pinctrl_info) {
  344. devm_pinctrl_put(gpio_ctrl_info.pinctrl_info);
  345. gpio_ctrl_info.pinctrl_info = NULL;
  346. }
  347. return iret;
  348. }