pinctrl-imx7ulp.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. /*
  2. * Copyright (C) 2016 Freescale Semiconductor, Inc.
  3. * Copyright (C) 2017 NXP
  4. *
  5. * Author: Dong Aisheng <aisheng.dong@nxp.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. */
  12. #include <linux/err.h>
  13. #include <linux/init.h>
  14. #include <linux/io.h>
  15. #include <linux/module.h>
  16. #include <linux/of.h>
  17. #include <linux/of_device.h>
  18. #include <linux/pinctrl/pinctrl.h>
  19. #include "pinctrl-imx.h"
  20. enum imx7ulp_pads {
  21. IMX7ULP_PAD_PTC0 = 0,
  22. IMX7ULP_PAD_PTC1,
  23. IMX7ULP_PAD_PTC2,
  24. IMX7ULP_PAD_PTC3,
  25. IMX7ULP_PAD_PTC4,
  26. IMX7ULP_PAD_PTC5,
  27. IMX7ULP_PAD_PTC6,
  28. IMX7ULP_PAD_PTC7,
  29. IMX7ULP_PAD_PTC8,
  30. IMX7ULP_PAD_PTC9,
  31. IMX7ULP_PAD_PTC10,
  32. IMX7ULP_PAD_PTC11,
  33. IMX7ULP_PAD_PTC12,
  34. IMX7ULP_PAD_PTC13,
  35. IMX7ULP_PAD_PTC14,
  36. IMX7ULP_PAD_PTC15,
  37. IMX7ULP_PAD_PTC16,
  38. IMX7ULP_PAD_PTC17,
  39. IMX7ULP_PAD_PTC18,
  40. IMX7ULP_PAD_PTC19,
  41. IMX7ULP_PAD_RESERVE0,
  42. IMX7ULP_PAD_RESERVE1,
  43. IMX7ULP_PAD_RESERVE2,
  44. IMX7ULP_PAD_RESERVE3,
  45. IMX7ULP_PAD_RESERVE4,
  46. IMX7ULP_PAD_RESERVE5,
  47. IMX7ULP_PAD_RESERVE6,
  48. IMX7ULP_PAD_RESERVE7,
  49. IMX7ULP_PAD_RESERVE8,
  50. IMX7ULP_PAD_RESERVE9,
  51. IMX7ULP_PAD_RESERVE10,
  52. IMX7ULP_PAD_RESERVE11,
  53. IMX7ULP_PAD_PTD0,
  54. IMX7ULP_PAD_PTD1,
  55. IMX7ULP_PAD_PTD2,
  56. IMX7ULP_PAD_PTD3,
  57. IMX7ULP_PAD_PTD4,
  58. IMX7ULP_PAD_PTD5,
  59. IMX7ULP_PAD_PTD6,
  60. IMX7ULP_PAD_PTD7,
  61. IMX7ULP_PAD_PTD8,
  62. IMX7ULP_PAD_PTD9,
  63. IMX7ULP_PAD_PTD10,
  64. IMX7ULP_PAD_PTD11,
  65. IMX7ULP_PAD_RESERVE12,
  66. IMX7ULP_PAD_RESERVE13,
  67. IMX7ULP_PAD_RESERVE14,
  68. IMX7ULP_PAD_RESERVE15,
  69. IMX7ULP_PAD_RESERVE16,
  70. IMX7ULP_PAD_RESERVE17,
  71. IMX7ULP_PAD_RESERVE18,
  72. IMX7ULP_PAD_RESERVE19,
  73. IMX7ULP_PAD_RESERVE20,
  74. IMX7ULP_PAD_RESERVE21,
  75. IMX7ULP_PAD_RESERVE22,
  76. IMX7ULP_PAD_RESERVE23,
  77. IMX7ULP_PAD_RESERVE24,
  78. IMX7ULP_PAD_RESERVE25,
  79. IMX7ULP_PAD_RESERVE26,
  80. IMX7ULP_PAD_RESERVE27,
  81. IMX7ULP_PAD_RESERVE28,
  82. IMX7ULP_PAD_RESERVE29,
  83. IMX7ULP_PAD_RESERVE30,
  84. IMX7ULP_PAD_RESERVE31,
  85. IMX7ULP_PAD_PTE0,
  86. IMX7ULP_PAD_PTE1,
  87. IMX7ULP_PAD_PTE2,
  88. IMX7ULP_PAD_PTE3,
  89. IMX7ULP_PAD_PTE4,
  90. IMX7ULP_PAD_PTE5,
  91. IMX7ULP_PAD_PTE6,
  92. IMX7ULP_PAD_PTE7,
  93. IMX7ULP_PAD_PTE8,
  94. IMX7ULP_PAD_PTE9,
  95. IMX7ULP_PAD_PTE10,
  96. IMX7ULP_PAD_PTE11,
  97. IMX7ULP_PAD_PTE12,
  98. IMX7ULP_PAD_PTE13,
  99. IMX7ULP_PAD_PTE14,
  100. IMX7ULP_PAD_PTE15,
  101. IMX7ULP_PAD_RESERVE32,
  102. IMX7ULP_PAD_RESERVE33,
  103. IMX7ULP_PAD_RESERVE34,
  104. IMX7ULP_PAD_RESERVE35,
  105. IMX7ULP_PAD_RESERVE36,
  106. IMX7ULP_PAD_RESERVE37,
  107. IMX7ULP_PAD_RESERVE38,
  108. IMX7ULP_PAD_RESERVE39,
  109. IMX7ULP_PAD_RESERVE40,
  110. IMX7ULP_PAD_RESERVE41,
  111. IMX7ULP_PAD_RESERVE42,
  112. IMX7ULP_PAD_RESERVE43,
  113. IMX7ULP_PAD_RESERVE44,
  114. IMX7ULP_PAD_RESERVE45,
  115. IMX7ULP_PAD_RESERVE46,
  116. IMX7ULP_PAD_RESERVE47,
  117. IMX7ULP_PAD_PTF0,
  118. IMX7ULP_PAD_PTF1,
  119. IMX7ULP_PAD_PTF2,
  120. IMX7ULP_PAD_PTF3,
  121. IMX7ULP_PAD_PTF4,
  122. IMX7ULP_PAD_PTF5,
  123. IMX7ULP_PAD_PTF6,
  124. IMX7ULP_PAD_PTF7,
  125. IMX7ULP_PAD_PTF8,
  126. IMX7ULP_PAD_PTF9,
  127. IMX7ULP_PAD_PTF10,
  128. IMX7ULP_PAD_PTF11,
  129. IMX7ULP_PAD_PTF12,
  130. IMX7ULP_PAD_PTF13,
  131. IMX7ULP_PAD_PTF14,
  132. IMX7ULP_PAD_PTF15,
  133. IMX7ULP_PAD_PTF16,
  134. IMX7ULP_PAD_PTF17,
  135. IMX7ULP_PAD_PTF18,
  136. IMX7ULP_PAD_PTF19,
  137. };
  138. /* Pad names for the pinmux subsystem */
  139. static const struct pinctrl_pin_desc imx7ulp_pinctrl_pads[] = {
  140. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTC0),
  141. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTC1),
  142. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTC2),
  143. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTC3),
  144. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTC4),
  145. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTC5),
  146. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTC6),
  147. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTC7),
  148. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTC8),
  149. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTC9),
  150. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTC10),
  151. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTC11),
  152. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTC12),
  153. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTC13),
  154. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTC14),
  155. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTC15),
  156. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTC16),
  157. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTC17),
  158. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTC18),
  159. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTC19),
  160. IMX_PINCTRL_PIN(IMX7ULP_PAD_RESERVE0),
  161. IMX_PINCTRL_PIN(IMX7ULP_PAD_RESERVE1),
  162. IMX_PINCTRL_PIN(IMX7ULP_PAD_RESERVE2),
  163. IMX_PINCTRL_PIN(IMX7ULP_PAD_RESERVE3),
  164. IMX_PINCTRL_PIN(IMX7ULP_PAD_RESERVE4),
  165. IMX_PINCTRL_PIN(IMX7ULP_PAD_RESERVE5),
  166. IMX_PINCTRL_PIN(IMX7ULP_PAD_RESERVE6),
  167. IMX_PINCTRL_PIN(IMX7ULP_PAD_RESERVE7),
  168. IMX_PINCTRL_PIN(IMX7ULP_PAD_RESERVE8),
  169. IMX_PINCTRL_PIN(IMX7ULP_PAD_RESERVE9),
  170. IMX_PINCTRL_PIN(IMX7ULP_PAD_RESERVE10),
  171. IMX_PINCTRL_PIN(IMX7ULP_PAD_RESERVE11),
  172. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTD0),
  173. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTD1),
  174. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTD2),
  175. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTD3),
  176. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTD4),
  177. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTD5),
  178. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTD6),
  179. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTD7),
  180. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTD8),
  181. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTD9),
  182. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTD10),
  183. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTD11),
  184. IMX_PINCTRL_PIN(IMX7ULP_PAD_RESERVE12),
  185. IMX_PINCTRL_PIN(IMX7ULP_PAD_RESERVE13),
  186. IMX_PINCTRL_PIN(IMX7ULP_PAD_RESERVE14),
  187. IMX_PINCTRL_PIN(IMX7ULP_PAD_RESERVE15),
  188. IMX_PINCTRL_PIN(IMX7ULP_PAD_RESERVE16),
  189. IMX_PINCTRL_PIN(IMX7ULP_PAD_RESERVE17),
  190. IMX_PINCTRL_PIN(IMX7ULP_PAD_RESERVE18),
  191. IMX_PINCTRL_PIN(IMX7ULP_PAD_RESERVE19),
  192. IMX_PINCTRL_PIN(IMX7ULP_PAD_RESERVE20),
  193. IMX_PINCTRL_PIN(IMX7ULP_PAD_RESERVE21),
  194. IMX_PINCTRL_PIN(IMX7ULP_PAD_RESERVE22),
  195. IMX_PINCTRL_PIN(IMX7ULP_PAD_RESERVE23),
  196. IMX_PINCTRL_PIN(IMX7ULP_PAD_RESERVE24),
  197. IMX_PINCTRL_PIN(IMX7ULP_PAD_RESERVE25),
  198. IMX_PINCTRL_PIN(IMX7ULP_PAD_RESERVE26),
  199. IMX_PINCTRL_PIN(IMX7ULP_PAD_RESERVE27),
  200. IMX_PINCTRL_PIN(IMX7ULP_PAD_RESERVE28),
  201. IMX_PINCTRL_PIN(IMX7ULP_PAD_RESERVE29),
  202. IMX_PINCTRL_PIN(IMX7ULP_PAD_RESERVE30),
  203. IMX_PINCTRL_PIN(IMX7ULP_PAD_RESERVE31),
  204. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTE0),
  205. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTE1),
  206. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTE2),
  207. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTE3),
  208. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTE4),
  209. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTE5),
  210. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTE6),
  211. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTE7),
  212. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTE8),
  213. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTE9),
  214. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTE10),
  215. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTE11),
  216. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTE12),
  217. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTE13),
  218. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTE14),
  219. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTE15),
  220. IMX_PINCTRL_PIN(IMX7ULP_PAD_RESERVE32),
  221. IMX_PINCTRL_PIN(IMX7ULP_PAD_RESERVE33),
  222. IMX_PINCTRL_PIN(IMX7ULP_PAD_RESERVE34),
  223. IMX_PINCTRL_PIN(IMX7ULP_PAD_RESERVE35),
  224. IMX_PINCTRL_PIN(IMX7ULP_PAD_RESERVE36),
  225. IMX_PINCTRL_PIN(IMX7ULP_PAD_RESERVE37),
  226. IMX_PINCTRL_PIN(IMX7ULP_PAD_RESERVE38),
  227. IMX_PINCTRL_PIN(IMX7ULP_PAD_RESERVE39),
  228. IMX_PINCTRL_PIN(IMX7ULP_PAD_RESERVE40),
  229. IMX_PINCTRL_PIN(IMX7ULP_PAD_RESERVE41),
  230. IMX_PINCTRL_PIN(IMX7ULP_PAD_RESERVE42),
  231. IMX_PINCTRL_PIN(IMX7ULP_PAD_RESERVE43),
  232. IMX_PINCTRL_PIN(IMX7ULP_PAD_RESERVE44),
  233. IMX_PINCTRL_PIN(IMX7ULP_PAD_RESERVE45),
  234. IMX_PINCTRL_PIN(IMX7ULP_PAD_RESERVE46),
  235. IMX_PINCTRL_PIN(IMX7ULP_PAD_RESERVE47),
  236. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTF0),
  237. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTF1),
  238. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTF2),
  239. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTF3),
  240. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTF4),
  241. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTF5),
  242. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTF6),
  243. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTF7),
  244. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTF8),
  245. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTF9),
  246. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTF10),
  247. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTF11),
  248. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTF12),
  249. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTF13),
  250. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTF14),
  251. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTF15),
  252. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTF16),
  253. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTF17),
  254. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTF18),
  255. IMX_PINCTRL_PIN(IMX7ULP_PAD_PTF19),
  256. };
  257. #define BM_OBE_ENABLED BIT(17)
  258. #define BM_IBE_ENABLED BIT(16)
  259. #define BM_LK_ENABLED BIT(15)
  260. #define BM_MUX_MODE 0xf00
  261. #define BP_MUX_MODE 8
  262. #define BM_PULL_ENABLED BIT(1)
  263. struct imx_cfg_params_decode imx7ulp_cfg_decodes[] = {
  264. IMX_CFG_PARAMS_DECODE(PIN_CONFIG_DRIVE_STRENGTH, BIT(6), 6),
  265. IMX_CFG_PARAMS_DECODE(PIN_CONFIG_DRIVE_PUSH_PULL, BIT(5), 5),
  266. IMX_CFG_PARAMS_DECODE(PIN_CONFIG_SLEW_RATE, BIT(2), 2),
  267. IMX_CFG_PARAMS_DECODE(PIN_CONFIG_BIAS_DISABLE, BIT(1), 1),
  268. IMX_CFG_PARAMS_DECODE(PIN_CONFIG_BIAS_PULL_UP, BIT(0), 0),
  269. IMX_CFG_PARAMS_DECODE_INVERT(PIN_CONFIG_DRIVE_OPEN_DRAIN, BIT(5), 5),
  270. IMX_CFG_PARAMS_DECODE_INVERT(PIN_CONFIG_BIAS_PULL_DOWN, BIT(0), 0),
  271. };
  272. static void imx7ulp_cfg_params_fixup(unsigned long *configs,
  273. unsigned int num_configs,
  274. u32 *raw_config)
  275. {
  276. enum pin_config_param param;
  277. u32 param_val;
  278. int i;
  279. /* lock field disabled */
  280. *raw_config &= ~BM_LK_ENABLED;
  281. for (i = 0; i < num_configs; i++) {
  282. param = pinconf_to_config_param(configs[i]);
  283. param_val = pinconf_to_config_argument(configs[i]);
  284. if ((param == PIN_CONFIG_BIAS_PULL_UP) ||
  285. (param == PIN_CONFIG_BIAS_PULL_DOWN)) {
  286. /* pull enabled */
  287. *raw_config |= BM_PULL_ENABLED;
  288. return;
  289. }
  290. }
  291. }
  292. static int imx7ulp_pmx_gpio_set_direction(struct pinctrl_dev *pctldev,
  293. struct pinctrl_gpio_range *range,
  294. unsigned offset, bool input)
  295. {
  296. struct imx_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev);
  297. struct imx_pinctrl_soc_info *info = ipctl->info;
  298. const struct imx_pin_reg *pin_reg;
  299. u32 reg;
  300. pin_reg = &info->pin_regs[offset];
  301. if (pin_reg->mux_reg == -1)
  302. return -EINVAL;
  303. reg = readl(ipctl->base + pin_reg->mux_reg);
  304. if (input)
  305. reg = (reg & ~BM_OBE_ENABLED) | BM_IBE_ENABLED;
  306. else
  307. reg = (reg & ~BM_IBE_ENABLED) | BM_OBE_ENABLED;
  308. writel(reg, ipctl->base + pin_reg->mux_reg);
  309. return 0;
  310. }
  311. static struct imx_pinctrl_soc_info imx7ulp_pinctrl_info = {
  312. .pins = imx7ulp_pinctrl_pads,
  313. .npins = ARRAY_SIZE(imx7ulp_pinctrl_pads),
  314. .flags = ZERO_OFFSET_VALID | SHARE_MUX_CONF_REG,
  315. .gpio_set_direction = imx7ulp_pmx_gpio_set_direction,
  316. .mux_mask = BM_MUX_MODE,
  317. .mux_shift = BP_MUX_MODE,
  318. .generic_pinconf = true,
  319. .decodes = imx7ulp_cfg_decodes,
  320. .num_decodes = ARRAY_SIZE(imx7ulp_cfg_decodes),
  321. .fixup = imx7ulp_cfg_params_fixup,
  322. };
  323. static const struct of_device_id imx7ulp_pinctrl_of_match[] = {
  324. { .compatible = "fsl,imx7ulp-iomuxc1", },
  325. { /* sentinel */ }
  326. };
  327. static int imx7ulp_pinctrl_probe(struct platform_device *pdev)
  328. {
  329. return imx_pinctrl_probe(pdev, &imx7ulp_pinctrl_info);
  330. }
  331. static struct platform_driver imx7ulp_pinctrl_driver = {
  332. .driver = {
  333. .name = "imx7ulp-pinctrl",
  334. .of_match_table = of_match_ptr(imx7ulp_pinctrl_of_match),
  335. .suppress_bind_attrs = true,
  336. },
  337. .probe = imx7ulp_pinctrl_probe,
  338. };
  339. static int __init imx7ulp_pinctrl_init(void)
  340. {
  341. return platform_driver_register(&imx7ulp_pinctrl_driver);
  342. }
  343. arch_initcall(imx7ulp_pinctrl_init);