pinctrl-dove.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. /*
  2. * Marvell Dove pinctrl driver based on mvebu pinctrl core
  3. *
  4. * Author: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. */
  11. #include <linux/err.h>
  12. #include <linux/init.h>
  13. #include <linux/io.h>
  14. #include <linux/module.h>
  15. #include <linux/bitops.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/clk.h>
  18. #include <linux/of.h>
  19. #include <linux/of_device.h>
  20. #include <linux/pinctrl/pinctrl.h>
  21. #include "pinctrl-mvebu.h"
  22. #define DOVE_SB_REGS_VIRT_BASE IOMEM(0xfde00000)
  23. #define DOVE_MPP_VIRT_BASE (DOVE_SB_REGS_VIRT_BASE + 0xd0200)
  24. #define DOVE_PMU_MPP_GENERAL_CTRL (DOVE_MPP_VIRT_BASE + 0x10)
  25. #define DOVE_AU0_AC97_SEL BIT(16)
  26. #define DOVE_GLOBAL_CONFIG_1 (DOVE_SB_REGS_VIRT_BASE + 0xe802C)
  27. #define DOVE_TWSI_ENABLE_OPTION1 BIT(7)
  28. #define DOVE_GLOBAL_CONFIG_2 (DOVE_SB_REGS_VIRT_BASE + 0xe8030)
  29. #define DOVE_TWSI_ENABLE_OPTION2 BIT(20)
  30. #define DOVE_TWSI_ENABLE_OPTION3 BIT(21)
  31. #define DOVE_TWSI_OPTION3_GPIO BIT(22)
  32. #define DOVE_SSP_CTRL_STATUS_1 (DOVE_SB_REGS_VIRT_BASE + 0xe8034)
  33. #define DOVE_SSP_ON_AU1 BIT(0)
  34. #define DOVE_MPP_GENERAL_VIRT_BASE (DOVE_SB_REGS_VIRT_BASE + 0xe803c)
  35. #define DOVE_AU1_SPDIFO_GPIO_EN BIT(1)
  36. #define DOVE_NAND_GPIO_EN BIT(0)
  37. #define DOVE_GPIO_LO_VIRT_BASE (DOVE_SB_REGS_VIRT_BASE + 0xd0400)
  38. #define DOVE_MPP_CTRL4_VIRT_BASE (DOVE_GPIO_LO_VIRT_BASE + 0x40)
  39. #define DOVE_SPI_GPIO_SEL BIT(5)
  40. #define DOVE_UART1_GPIO_SEL BIT(4)
  41. #define DOVE_AU1_GPIO_SEL BIT(3)
  42. #define DOVE_CAM_GPIO_SEL BIT(2)
  43. #define DOVE_SD1_GPIO_SEL BIT(1)
  44. #define DOVE_SD0_GPIO_SEL BIT(0)
  45. #define MPPS_PER_REG 8
  46. #define MPP_BITS 4
  47. #define MPP_MASK 0xf
  48. #define CONFIG_PMU BIT(4)
  49. static int dove_pmu_mpp_ctrl_get(struct mvebu_mpp_ctrl *ctrl,
  50. unsigned long *config)
  51. {
  52. unsigned off = (ctrl->pid / MPPS_PER_REG) * MPP_BITS;
  53. unsigned shift = (ctrl->pid % MPPS_PER_REG) * MPP_BITS;
  54. unsigned long pmu = readl(DOVE_PMU_MPP_GENERAL_CTRL);
  55. unsigned long mpp = readl(DOVE_MPP_VIRT_BASE + off);
  56. if (pmu & (1 << ctrl->pid))
  57. *config = CONFIG_PMU;
  58. else
  59. *config = (mpp >> shift) & MPP_MASK;
  60. return 0;
  61. }
  62. static int dove_pmu_mpp_ctrl_set(struct mvebu_mpp_ctrl *ctrl,
  63. unsigned long config)
  64. {
  65. unsigned off = (ctrl->pid / MPPS_PER_REG) * MPP_BITS;
  66. unsigned shift = (ctrl->pid % MPPS_PER_REG) * MPP_BITS;
  67. unsigned long pmu = readl(DOVE_PMU_MPP_GENERAL_CTRL);
  68. unsigned long mpp = readl(DOVE_MPP_VIRT_BASE + off);
  69. if (config == CONFIG_PMU)
  70. writel(pmu | (1 << ctrl->pid), DOVE_PMU_MPP_GENERAL_CTRL);
  71. else {
  72. writel(pmu & ~(1 << ctrl->pid), DOVE_PMU_MPP_GENERAL_CTRL);
  73. mpp &= ~(MPP_MASK << shift);
  74. mpp |= config << shift;
  75. writel(mpp, DOVE_MPP_VIRT_BASE + off);
  76. }
  77. return 0;
  78. }
  79. static int dove_mpp4_ctrl_get(struct mvebu_mpp_ctrl *ctrl,
  80. unsigned long *config)
  81. {
  82. unsigned long mpp4 = readl(DOVE_MPP_CTRL4_VIRT_BASE);
  83. unsigned long mask;
  84. switch (ctrl->pid) {
  85. case 24: /* mpp_camera */
  86. mask = DOVE_CAM_GPIO_SEL;
  87. break;
  88. case 40: /* mpp_sdio0 */
  89. mask = DOVE_SD0_GPIO_SEL;
  90. break;
  91. case 46: /* mpp_sdio1 */
  92. mask = DOVE_SD1_GPIO_SEL;
  93. break;
  94. case 58: /* mpp_spi0 */
  95. mask = DOVE_SPI_GPIO_SEL;
  96. break;
  97. case 62: /* mpp_uart1 */
  98. mask = DOVE_UART1_GPIO_SEL;
  99. break;
  100. default:
  101. return -EINVAL;
  102. }
  103. *config = ((mpp4 & mask) != 0);
  104. return 0;
  105. }
  106. static int dove_mpp4_ctrl_set(struct mvebu_mpp_ctrl *ctrl,
  107. unsigned long config)
  108. {
  109. unsigned long mpp4 = readl(DOVE_MPP_CTRL4_VIRT_BASE);
  110. unsigned long mask;
  111. switch (ctrl->pid) {
  112. case 24: /* mpp_camera */
  113. mask = DOVE_CAM_GPIO_SEL;
  114. break;
  115. case 40: /* mpp_sdio0 */
  116. mask = DOVE_SD0_GPIO_SEL;
  117. break;
  118. case 46: /* mpp_sdio1 */
  119. mask = DOVE_SD1_GPIO_SEL;
  120. break;
  121. case 58: /* mpp_spi0 */
  122. mask = DOVE_SPI_GPIO_SEL;
  123. break;
  124. case 62: /* mpp_uart1 */
  125. mask = DOVE_UART1_GPIO_SEL;
  126. break;
  127. default:
  128. return -EINVAL;
  129. }
  130. mpp4 &= ~mask;
  131. if (config)
  132. mpp4 |= mask;
  133. writel(mpp4, DOVE_MPP_CTRL4_VIRT_BASE);
  134. return 0;
  135. }
  136. static int dove_nand_ctrl_get(struct mvebu_mpp_ctrl *ctrl,
  137. unsigned long *config)
  138. {
  139. unsigned long gmpp = readl(DOVE_MPP_GENERAL_VIRT_BASE);
  140. *config = ((gmpp & DOVE_NAND_GPIO_EN) != 0);
  141. return 0;
  142. }
  143. static int dove_nand_ctrl_set(struct mvebu_mpp_ctrl *ctrl,
  144. unsigned long config)
  145. {
  146. unsigned long gmpp = readl(DOVE_MPP_GENERAL_VIRT_BASE);
  147. gmpp &= ~DOVE_NAND_GPIO_EN;
  148. if (config)
  149. gmpp |= DOVE_NAND_GPIO_EN;
  150. writel(gmpp, DOVE_MPP_GENERAL_VIRT_BASE);
  151. return 0;
  152. }
  153. static int dove_audio0_ctrl_get(struct mvebu_mpp_ctrl *ctrl,
  154. unsigned long *config)
  155. {
  156. unsigned long pmu = readl(DOVE_PMU_MPP_GENERAL_CTRL);
  157. *config = ((pmu & DOVE_AU0_AC97_SEL) != 0);
  158. return 0;
  159. }
  160. static int dove_audio0_ctrl_set(struct mvebu_mpp_ctrl *ctrl,
  161. unsigned long config)
  162. {
  163. unsigned long pmu = readl(DOVE_PMU_MPP_GENERAL_CTRL);
  164. pmu &= ~DOVE_AU0_AC97_SEL;
  165. if (config)
  166. pmu |= DOVE_AU0_AC97_SEL;
  167. writel(pmu, DOVE_PMU_MPP_GENERAL_CTRL);
  168. return 0;
  169. }
  170. static int dove_audio1_ctrl_get(struct mvebu_mpp_ctrl *ctrl,
  171. unsigned long *config)
  172. {
  173. unsigned long mpp4 = readl(DOVE_MPP_CTRL4_VIRT_BASE);
  174. unsigned long sspc1 = readl(DOVE_SSP_CTRL_STATUS_1);
  175. unsigned long gmpp = readl(DOVE_MPP_GENERAL_VIRT_BASE);
  176. unsigned long gcfg2 = readl(DOVE_GLOBAL_CONFIG_2);
  177. *config = 0;
  178. if (mpp4 & DOVE_AU1_GPIO_SEL)
  179. *config |= BIT(3);
  180. if (sspc1 & DOVE_SSP_ON_AU1)
  181. *config |= BIT(2);
  182. if (gmpp & DOVE_AU1_SPDIFO_GPIO_EN)
  183. *config |= BIT(1);
  184. if (gcfg2 & DOVE_TWSI_OPTION3_GPIO)
  185. *config |= BIT(0);
  186. /* SSP/TWSI only if I2S1 not set*/
  187. if ((*config & BIT(3)) == 0)
  188. *config &= ~(BIT(2) | BIT(0));
  189. /* TWSI only if SPDIFO not set*/
  190. if ((*config & BIT(1)) == 0)
  191. *config &= ~BIT(0);
  192. return 0;
  193. }
  194. static int dove_audio1_ctrl_set(struct mvebu_mpp_ctrl *ctrl,
  195. unsigned long config)
  196. {
  197. unsigned long mpp4 = readl(DOVE_MPP_CTRL4_VIRT_BASE);
  198. unsigned long sspc1 = readl(DOVE_SSP_CTRL_STATUS_1);
  199. unsigned long gmpp = readl(DOVE_MPP_GENERAL_VIRT_BASE);
  200. unsigned long gcfg2 = readl(DOVE_GLOBAL_CONFIG_2);
  201. /*
  202. * clear all audio1 related bits before configure
  203. */
  204. gcfg2 &= ~DOVE_TWSI_OPTION3_GPIO;
  205. gmpp &= ~DOVE_AU1_SPDIFO_GPIO_EN;
  206. sspc1 &= ~DOVE_SSP_ON_AU1;
  207. mpp4 &= ~DOVE_AU1_GPIO_SEL;
  208. if (config & BIT(0))
  209. gcfg2 |= DOVE_TWSI_OPTION3_GPIO;
  210. if (config & BIT(1))
  211. gmpp |= DOVE_AU1_SPDIFO_GPIO_EN;
  212. if (config & BIT(2))
  213. sspc1 |= DOVE_SSP_ON_AU1;
  214. if (config & BIT(3))
  215. mpp4 |= DOVE_AU1_GPIO_SEL;
  216. writel(mpp4, DOVE_MPP_CTRL4_VIRT_BASE);
  217. writel(sspc1, DOVE_SSP_CTRL_STATUS_1);
  218. writel(gmpp, DOVE_MPP_GENERAL_VIRT_BASE);
  219. writel(gcfg2, DOVE_GLOBAL_CONFIG_2);
  220. return 0;
  221. }
  222. /* mpp[52:57] gpio pins depend heavily on current config;
  223. * gpio_req does not try to mux in gpio capabilities to not
  224. * break other functions. If you require all mpps as gpio
  225. * enforce gpio setting by pinctrl mapping.
  226. */
  227. static int dove_audio1_ctrl_gpio_req(struct mvebu_mpp_ctrl *ctrl, u8 pid)
  228. {
  229. unsigned long config;
  230. dove_audio1_ctrl_get(ctrl, &config);
  231. switch (config) {
  232. case 0x02: /* i2s1 : gpio[56:57] */
  233. case 0x0e: /* ssp : gpio[56:57] */
  234. if (pid >= 56)
  235. return 0;
  236. return -ENOTSUPP;
  237. case 0x08: /* spdifo : gpio[52:55] */
  238. case 0x0b: /* twsi : gpio[52:55] */
  239. if (pid <= 55)
  240. return 0;
  241. return -ENOTSUPP;
  242. case 0x0a: /* all gpio */
  243. return 0;
  244. /* 0x00 : i2s1/spdifo : no gpio */
  245. /* 0x0c : ssp/spdifo : no gpio */
  246. /* 0x0f : ssp/twsi : no gpio */
  247. }
  248. return -ENOTSUPP;
  249. }
  250. /* mpp[52:57] has gpio pins capable of in and out */
  251. static int dove_audio1_ctrl_gpio_dir(struct mvebu_mpp_ctrl *ctrl, u8 pid,
  252. bool input)
  253. {
  254. if (pid < 52 || pid > 57)
  255. return -ENOTSUPP;
  256. return 0;
  257. }
  258. static int dove_twsi_ctrl_get(struct mvebu_mpp_ctrl *ctrl,
  259. unsigned long *config)
  260. {
  261. unsigned long gcfg1 = readl(DOVE_GLOBAL_CONFIG_1);
  262. unsigned long gcfg2 = readl(DOVE_GLOBAL_CONFIG_2);
  263. *config = 0;
  264. if (gcfg1 & DOVE_TWSI_ENABLE_OPTION1)
  265. *config = 1;
  266. else if (gcfg2 & DOVE_TWSI_ENABLE_OPTION2)
  267. *config = 2;
  268. else if (gcfg2 & DOVE_TWSI_ENABLE_OPTION3)
  269. *config = 3;
  270. return 0;
  271. }
  272. static int dove_twsi_ctrl_set(struct mvebu_mpp_ctrl *ctrl,
  273. unsigned long config)
  274. {
  275. unsigned long gcfg1 = readl(DOVE_GLOBAL_CONFIG_1);
  276. unsigned long gcfg2 = readl(DOVE_GLOBAL_CONFIG_2);
  277. gcfg1 &= ~DOVE_TWSI_ENABLE_OPTION1;
  278. gcfg2 &= ~(DOVE_TWSI_ENABLE_OPTION2 | DOVE_TWSI_ENABLE_OPTION2);
  279. switch (config) {
  280. case 1:
  281. gcfg1 |= DOVE_TWSI_ENABLE_OPTION1;
  282. break;
  283. case 2:
  284. gcfg2 |= DOVE_TWSI_ENABLE_OPTION2;
  285. break;
  286. case 3:
  287. gcfg2 |= DOVE_TWSI_ENABLE_OPTION3;
  288. break;
  289. }
  290. writel(gcfg1, DOVE_GLOBAL_CONFIG_1);
  291. writel(gcfg2, DOVE_GLOBAL_CONFIG_2);
  292. return 0;
  293. }
  294. static struct mvebu_mpp_ctrl dove_mpp_controls[] = {
  295. MPP_FUNC_CTRL(0, 0, "mpp0", dove_pmu_mpp_ctrl),
  296. MPP_FUNC_CTRL(1, 1, "mpp1", dove_pmu_mpp_ctrl),
  297. MPP_FUNC_CTRL(2, 2, "mpp2", dove_pmu_mpp_ctrl),
  298. MPP_FUNC_CTRL(3, 3, "mpp3", dove_pmu_mpp_ctrl),
  299. MPP_FUNC_CTRL(4, 4, "mpp4", dove_pmu_mpp_ctrl),
  300. MPP_FUNC_CTRL(5, 5, "mpp5", dove_pmu_mpp_ctrl),
  301. MPP_FUNC_CTRL(6, 6, "mpp6", dove_pmu_mpp_ctrl),
  302. MPP_FUNC_CTRL(7, 7, "mpp7", dove_pmu_mpp_ctrl),
  303. MPP_FUNC_CTRL(8, 8, "mpp8", dove_pmu_mpp_ctrl),
  304. MPP_FUNC_CTRL(9, 9, "mpp9", dove_pmu_mpp_ctrl),
  305. MPP_FUNC_CTRL(10, 10, "mpp10", dove_pmu_mpp_ctrl),
  306. MPP_FUNC_CTRL(11, 11, "mpp11", dove_pmu_mpp_ctrl),
  307. MPP_FUNC_CTRL(12, 12, "mpp12", dove_pmu_mpp_ctrl),
  308. MPP_FUNC_CTRL(13, 13, "mpp13", dove_pmu_mpp_ctrl),
  309. MPP_FUNC_CTRL(14, 14, "mpp14", dove_pmu_mpp_ctrl),
  310. MPP_FUNC_CTRL(15, 15, "mpp15", dove_pmu_mpp_ctrl),
  311. MPP_REG_CTRL(16, 23),
  312. MPP_FUNC_CTRL(24, 39, "mpp_camera", dove_mpp4_ctrl),
  313. MPP_FUNC_CTRL(40, 45, "mpp_sdio0", dove_mpp4_ctrl),
  314. MPP_FUNC_CTRL(46, 51, "mpp_sdio1", dove_mpp4_ctrl),
  315. MPP_FUNC_GPIO_CTRL(52, 57, "mpp_audio1", dove_audio1_ctrl),
  316. MPP_FUNC_CTRL(58, 61, "mpp_spi0", dove_mpp4_ctrl),
  317. MPP_FUNC_CTRL(62, 63, "mpp_uart1", dove_mpp4_ctrl),
  318. MPP_FUNC_CTRL(64, 71, "mpp_nand", dove_nand_ctrl),
  319. MPP_FUNC_CTRL(72, 72, "audio0", dove_audio0_ctrl),
  320. MPP_FUNC_CTRL(73, 73, "twsi", dove_twsi_ctrl),
  321. };
  322. static struct mvebu_mpp_mode dove_mpp_modes[] = {
  323. MPP_MODE(0,
  324. MPP_FUNCTION(0x00, "gpio", NULL),
  325. MPP_FUNCTION(0x02, "uart2", "rts"),
  326. MPP_FUNCTION(0x03, "sdio0", "cd"),
  327. MPP_FUNCTION(0x0f, "lcd0", "pwm"),
  328. MPP_FUNCTION(0x10, "pmu", NULL)),
  329. MPP_MODE(1,
  330. MPP_FUNCTION(0x00, "gpio", NULL),
  331. MPP_FUNCTION(0x02, "uart2", "cts"),
  332. MPP_FUNCTION(0x03, "sdio0", "wp"),
  333. MPP_FUNCTION(0x0f, "lcd1", "pwm"),
  334. MPP_FUNCTION(0x10, "pmu", NULL)),
  335. MPP_MODE(2,
  336. MPP_FUNCTION(0x00, "gpio", NULL),
  337. MPP_FUNCTION(0x01, "sata", "prsnt"),
  338. MPP_FUNCTION(0x02, "uart2", "txd"),
  339. MPP_FUNCTION(0x03, "sdio0", "buspwr"),
  340. MPP_FUNCTION(0x04, "uart1", "rts"),
  341. MPP_FUNCTION(0x10, "pmu", NULL)),
  342. MPP_MODE(3,
  343. MPP_FUNCTION(0x00, "gpio", NULL),
  344. MPP_FUNCTION(0x01, "sata", "act"),
  345. MPP_FUNCTION(0x02, "uart2", "rxd"),
  346. MPP_FUNCTION(0x03, "sdio0", "ledctrl"),
  347. MPP_FUNCTION(0x04, "uart1", "cts"),
  348. MPP_FUNCTION(0x0f, "lcd-spi", "cs1"),
  349. MPP_FUNCTION(0x10, "pmu", NULL)),
  350. MPP_MODE(4,
  351. MPP_FUNCTION(0x00, "gpio", NULL),
  352. MPP_FUNCTION(0x02, "uart3", "rts"),
  353. MPP_FUNCTION(0x03, "sdio1", "cd"),
  354. MPP_FUNCTION(0x04, "spi1", "miso"),
  355. MPP_FUNCTION(0x10, "pmu", NULL)),
  356. MPP_MODE(5,
  357. MPP_FUNCTION(0x00, "gpio", NULL),
  358. MPP_FUNCTION(0x02, "uart3", "cts"),
  359. MPP_FUNCTION(0x03, "sdio1", "wp"),
  360. MPP_FUNCTION(0x04, "spi1", "cs"),
  361. MPP_FUNCTION(0x10, "pmu", NULL)),
  362. MPP_MODE(6,
  363. MPP_FUNCTION(0x00, "gpio", NULL),
  364. MPP_FUNCTION(0x02, "uart3", "txd"),
  365. MPP_FUNCTION(0x03, "sdio1", "buspwr"),
  366. MPP_FUNCTION(0x04, "spi1", "mosi"),
  367. MPP_FUNCTION(0x10, "pmu", NULL)),
  368. MPP_MODE(7,
  369. MPP_FUNCTION(0x00, "gpio", NULL),
  370. MPP_FUNCTION(0x02, "uart3", "rxd"),
  371. MPP_FUNCTION(0x03, "sdio1", "ledctrl"),
  372. MPP_FUNCTION(0x04, "spi1", "sck"),
  373. MPP_FUNCTION(0x10, "pmu", NULL)),
  374. MPP_MODE(8,
  375. MPP_FUNCTION(0x00, "gpio", NULL),
  376. MPP_FUNCTION(0x01, "watchdog", "rstout"),
  377. MPP_FUNCTION(0x10, "pmu", NULL)),
  378. MPP_MODE(9,
  379. MPP_FUNCTION(0x00, "gpio", NULL),
  380. MPP_FUNCTION(0x05, "pex1", "clkreq"),
  381. MPP_FUNCTION(0x10, "pmu", NULL)),
  382. MPP_MODE(10,
  383. MPP_FUNCTION(0x00, "gpio", NULL),
  384. MPP_FUNCTION(0x05, "ssp", "sclk"),
  385. MPP_FUNCTION(0x10, "pmu", NULL)),
  386. MPP_MODE(11,
  387. MPP_FUNCTION(0x00, "gpio", NULL),
  388. MPP_FUNCTION(0x01, "sata", "prsnt"),
  389. MPP_FUNCTION(0x02, "sata-1", "act"),
  390. MPP_FUNCTION(0x03, "sdio0", "ledctrl"),
  391. MPP_FUNCTION(0x04, "sdio1", "ledctrl"),
  392. MPP_FUNCTION(0x05, "pex0", "clkreq"),
  393. MPP_FUNCTION(0x10, "pmu", NULL)),
  394. MPP_MODE(12,
  395. MPP_FUNCTION(0x00, "gpio", NULL),
  396. MPP_FUNCTION(0x01, "sata", "act"),
  397. MPP_FUNCTION(0x02, "uart2", "rts"),
  398. MPP_FUNCTION(0x03, "audio0", "extclk"),
  399. MPP_FUNCTION(0x04, "sdio1", "cd"),
  400. MPP_FUNCTION(0x10, "pmu", NULL)),
  401. MPP_MODE(13,
  402. MPP_FUNCTION(0x00, "gpio", NULL),
  403. MPP_FUNCTION(0x02, "uart2", "cts"),
  404. MPP_FUNCTION(0x03, "audio1", "extclk"),
  405. MPP_FUNCTION(0x04, "sdio1", "wp"),
  406. MPP_FUNCTION(0x05, "ssp", "extclk"),
  407. MPP_FUNCTION(0x10, "pmu", NULL)),
  408. MPP_MODE(14,
  409. MPP_FUNCTION(0x00, "gpio", NULL),
  410. MPP_FUNCTION(0x02, "uart2", "txd"),
  411. MPP_FUNCTION(0x04, "sdio1", "buspwr"),
  412. MPP_FUNCTION(0x05, "ssp", "rxd"),
  413. MPP_FUNCTION(0x10, "pmu", NULL)),
  414. MPP_MODE(15,
  415. MPP_FUNCTION(0x00, "gpio", NULL),
  416. MPP_FUNCTION(0x02, "uart2", "rxd"),
  417. MPP_FUNCTION(0x04, "sdio1", "ledctrl"),
  418. MPP_FUNCTION(0x05, "ssp", "sfrm"),
  419. MPP_FUNCTION(0x10, "pmu", NULL)),
  420. MPP_MODE(16,
  421. MPP_FUNCTION(0x00, "gpio", NULL),
  422. MPP_FUNCTION(0x02, "uart3", "rts"),
  423. MPP_FUNCTION(0x03, "sdio0", "cd"),
  424. MPP_FUNCTION(0x04, "lcd-spi", "cs1"),
  425. MPP_FUNCTION(0x05, "ac97", "sdi1")),
  426. MPP_MODE(17,
  427. MPP_FUNCTION(0x00, "gpio", NULL),
  428. MPP_FUNCTION(0x01, "ac97-1", "sysclko"),
  429. MPP_FUNCTION(0x02, "uart3", "cts"),
  430. MPP_FUNCTION(0x03, "sdio0", "wp"),
  431. MPP_FUNCTION(0x04, "twsi", "sda"),
  432. MPP_FUNCTION(0x05, "ac97", "sdi2")),
  433. MPP_MODE(18,
  434. MPP_FUNCTION(0x00, "gpio", NULL),
  435. MPP_FUNCTION(0x02, "uart3", "txd"),
  436. MPP_FUNCTION(0x03, "sdio0", "buspwr"),
  437. MPP_FUNCTION(0x04, "lcd0", "pwm"),
  438. MPP_FUNCTION(0x05, "ac97", "sdi3")),
  439. MPP_MODE(19,
  440. MPP_FUNCTION(0x00, "gpio", NULL),
  441. MPP_FUNCTION(0x02, "uart3", "rxd"),
  442. MPP_FUNCTION(0x03, "sdio0", "ledctrl"),
  443. MPP_FUNCTION(0x04, "twsi", "sck")),
  444. MPP_MODE(20,
  445. MPP_FUNCTION(0x00, "gpio", NULL),
  446. MPP_FUNCTION(0x01, "ac97", "sysclko"),
  447. MPP_FUNCTION(0x02, "lcd-spi", "miso"),
  448. MPP_FUNCTION(0x03, "sdio1", "cd"),
  449. MPP_FUNCTION(0x05, "sdio0", "cd"),
  450. MPP_FUNCTION(0x06, "spi1", "miso")),
  451. MPP_MODE(21,
  452. MPP_FUNCTION(0x00, "gpio", NULL),
  453. MPP_FUNCTION(0x01, "uart1", "rts"),
  454. MPP_FUNCTION(0x02, "lcd-spi", "cs0"),
  455. MPP_FUNCTION(0x03, "sdio1", "wp"),
  456. MPP_FUNCTION(0x04, "ssp", "sfrm"),
  457. MPP_FUNCTION(0x05, "sdio0", "wp"),
  458. MPP_FUNCTION(0x06, "spi1", "cs")),
  459. MPP_MODE(22,
  460. MPP_FUNCTION(0x00, "gpio", NULL),
  461. MPP_FUNCTION(0x01, "uart1", "cts"),
  462. MPP_FUNCTION(0x02, "lcd-spi", "mosi"),
  463. MPP_FUNCTION(0x03, "sdio1", "buspwr"),
  464. MPP_FUNCTION(0x04, "ssp", "txd"),
  465. MPP_FUNCTION(0x05, "sdio0", "buspwr"),
  466. MPP_FUNCTION(0x06, "spi1", "mosi")),
  467. MPP_MODE(23,
  468. MPP_FUNCTION(0x00, "gpio", NULL),
  469. MPP_FUNCTION(0x02, "lcd-spi", "sck"),
  470. MPP_FUNCTION(0x03, "sdio1", "ledctrl"),
  471. MPP_FUNCTION(0x04, "ssp", "sclk"),
  472. MPP_FUNCTION(0x05, "sdio0", "ledctrl"),
  473. MPP_FUNCTION(0x06, "spi1", "sck")),
  474. MPP_MODE(24,
  475. MPP_FUNCTION(0x00, "camera", NULL),
  476. MPP_FUNCTION(0x01, "gpio", NULL)),
  477. MPP_MODE(40,
  478. MPP_FUNCTION(0x00, "sdio0", NULL),
  479. MPP_FUNCTION(0x01, "gpio", NULL)),
  480. MPP_MODE(46,
  481. MPP_FUNCTION(0x00, "sdio1", NULL),
  482. MPP_FUNCTION(0x01, "gpio", NULL)),
  483. MPP_MODE(52,
  484. MPP_FUNCTION(0x00, "i2s1/spdifo", NULL),
  485. MPP_FUNCTION(0x02, "i2s1", NULL),
  486. MPP_FUNCTION(0x08, "spdifo", NULL),
  487. MPP_FUNCTION(0x0a, "gpio", NULL),
  488. MPP_FUNCTION(0x0b, "twsi", NULL),
  489. MPP_FUNCTION(0x0c, "ssp/spdifo", NULL),
  490. MPP_FUNCTION(0x0e, "ssp", NULL),
  491. MPP_FUNCTION(0x0f, "ssp/twsi", NULL)),
  492. MPP_MODE(58,
  493. MPP_FUNCTION(0x00, "spi0", NULL),
  494. MPP_FUNCTION(0x01, "gpio", NULL)),
  495. MPP_MODE(62,
  496. MPP_FUNCTION(0x00, "uart1", NULL),
  497. MPP_FUNCTION(0x01, "gpio", NULL)),
  498. MPP_MODE(64,
  499. MPP_FUNCTION(0x00, "nand", NULL),
  500. MPP_FUNCTION(0x01, "gpo", NULL)),
  501. MPP_MODE(72,
  502. MPP_FUNCTION(0x00, "i2s", NULL),
  503. MPP_FUNCTION(0x01, "ac97", NULL)),
  504. MPP_MODE(73,
  505. MPP_FUNCTION(0x00, "twsi-none", NULL),
  506. MPP_FUNCTION(0x01, "twsi-opt1", NULL),
  507. MPP_FUNCTION(0x02, "twsi-opt2", NULL),
  508. MPP_FUNCTION(0x03, "twsi-opt3", NULL)),
  509. };
  510. static struct pinctrl_gpio_range dove_mpp_gpio_ranges[] = {
  511. MPP_GPIO_RANGE(0, 0, 0, 32),
  512. MPP_GPIO_RANGE(1, 32, 32, 32),
  513. MPP_GPIO_RANGE(2, 64, 64, 8),
  514. };
  515. static struct mvebu_pinctrl_soc_info dove_pinctrl_info = {
  516. .controls = dove_mpp_controls,
  517. .ncontrols = ARRAY_SIZE(dove_mpp_controls),
  518. .modes = dove_mpp_modes,
  519. .nmodes = ARRAY_SIZE(dove_mpp_modes),
  520. .gpioranges = dove_mpp_gpio_ranges,
  521. .ngpioranges = ARRAY_SIZE(dove_mpp_gpio_ranges),
  522. .variant = 0,
  523. };
  524. static struct clk *clk;
  525. static struct of_device_id dove_pinctrl_of_match[] = {
  526. { .compatible = "marvell,dove-pinctrl", .data = &dove_pinctrl_info },
  527. { }
  528. };
  529. static int dove_pinctrl_probe(struct platform_device *pdev)
  530. {
  531. const struct of_device_id *match =
  532. of_match_device(dove_pinctrl_of_match, &pdev->dev);
  533. pdev->dev.platform_data = (void *)match->data;
  534. /*
  535. * General MPP Configuration Register is part of pdma registers.
  536. * grab clk to make sure it is ticking.
  537. */
  538. clk = devm_clk_get(&pdev->dev, NULL);
  539. if (IS_ERR(clk)) {
  540. dev_err(&pdev->dev, "Unable to get pdma clock");
  541. return PTR_RET(clk);
  542. }
  543. clk_prepare_enable(clk);
  544. return mvebu_pinctrl_probe(pdev);
  545. }
  546. static int dove_pinctrl_remove(struct platform_device *pdev)
  547. {
  548. int ret;
  549. ret = mvebu_pinctrl_remove(pdev);
  550. if (!IS_ERR(clk))
  551. clk_disable_unprepare(clk);
  552. return ret;
  553. }
  554. static struct platform_driver dove_pinctrl_driver = {
  555. .driver = {
  556. .name = "dove-pinctrl",
  557. .owner = THIS_MODULE,
  558. .of_match_table = of_match_ptr(dove_pinctrl_of_match),
  559. },
  560. .probe = dove_pinctrl_probe,
  561. .remove = dove_pinctrl_remove,
  562. };
  563. module_platform_driver(dove_pinctrl_driver);
  564. MODULE_AUTHOR("Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>");
  565. MODULE_DESCRIPTION("Marvell Dove pinctrl driver");
  566. MODULE_LICENSE("GPL v2");