pinctrl-dove.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  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 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. if (config & BIT(0))
  202. gcfg2 |= DOVE_TWSI_OPTION3_GPIO;
  203. if (config & BIT(1))
  204. gmpp |= DOVE_AU1_SPDIFO_GPIO_EN;
  205. if (config & BIT(2))
  206. sspc1 |= DOVE_SSP_ON_AU1;
  207. if (config & BIT(3))
  208. mpp4 |= DOVE_AU1_GPIO_SEL;
  209. writel(mpp4, DOVE_MPP_CTRL4_VIRT_BASE);
  210. writel(sspc1, DOVE_SSP_CTRL_STATUS_1);
  211. writel(gmpp, DOVE_MPP_GENERAL_VIRT_BASE);
  212. writel(gcfg2, DOVE_GLOBAL_CONFIG_2);
  213. return 0;
  214. }
  215. /* mpp[52:57] gpio pins depend heavily on current config;
  216. * gpio_req does not try to mux in gpio capabilities to not
  217. * break other functions. If you require all mpps as gpio
  218. * enforce gpio setting by pinctrl mapping.
  219. */
  220. static int dove_audio1_ctrl_gpio_req(struct mvebu_mpp_ctrl *ctrl, u8 pid)
  221. {
  222. unsigned long config;
  223. dove_audio1_ctrl_get(ctrl, &config);
  224. switch (config) {
  225. case 0x02: /* i2s1 : gpio[56:57] */
  226. case 0x0e: /* ssp : gpio[56:57] */
  227. if (pid >= 56)
  228. return 0;
  229. return -ENOTSUPP;
  230. case 0x08: /* spdifo : gpio[52:55] */
  231. case 0x0b: /* twsi : gpio[52:55] */
  232. if (pid <= 55)
  233. return 0;
  234. return -ENOTSUPP;
  235. case 0x0a: /* all gpio */
  236. return 0;
  237. /* 0x00 : i2s1/spdifo : no gpio */
  238. /* 0x0c : ssp/spdifo : no gpio */
  239. /* 0x0f : ssp/twsi : no gpio */
  240. }
  241. return -ENOTSUPP;
  242. }
  243. /* mpp[52:57] has gpio pins capable of in and out */
  244. static int dove_audio1_ctrl_gpio_dir(struct mvebu_mpp_ctrl *ctrl, u8 pid,
  245. bool input)
  246. {
  247. if (pid < 52 || pid > 57)
  248. return -ENOTSUPP;
  249. return 0;
  250. }
  251. static int dove_twsi_ctrl_get(struct mvebu_mpp_ctrl *ctrl,
  252. unsigned long *config)
  253. {
  254. unsigned long gcfg1 = readl(DOVE_GLOBAL_CONFIG_1);
  255. unsigned long gcfg2 = readl(DOVE_GLOBAL_CONFIG_2);
  256. *config = 0;
  257. if (gcfg1 & DOVE_TWSI_ENABLE_OPTION1)
  258. *config = 1;
  259. else if (gcfg2 & DOVE_TWSI_ENABLE_OPTION2)
  260. *config = 2;
  261. else if (gcfg2 & DOVE_TWSI_ENABLE_OPTION3)
  262. *config = 3;
  263. return 0;
  264. }
  265. static int dove_twsi_ctrl_set(struct mvebu_mpp_ctrl *ctrl,
  266. unsigned long config)
  267. {
  268. unsigned long gcfg1 = readl(DOVE_GLOBAL_CONFIG_1);
  269. unsigned long gcfg2 = readl(DOVE_GLOBAL_CONFIG_2);
  270. gcfg1 &= ~DOVE_TWSI_ENABLE_OPTION1;
  271. gcfg2 &= ~(DOVE_TWSI_ENABLE_OPTION2 | DOVE_TWSI_ENABLE_OPTION2);
  272. switch (config) {
  273. case 1:
  274. gcfg1 |= DOVE_TWSI_ENABLE_OPTION1;
  275. break;
  276. case 2:
  277. gcfg2 |= DOVE_TWSI_ENABLE_OPTION2;
  278. break;
  279. case 3:
  280. gcfg2 |= DOVE_TWSI_ENABLE_OPTION3;
  281. break;
  282. }
  283. writel(gcfg1, DOVE_GLOBAL_CONFIG_1);
  284. writel(gcfg2, DOVE_GLOBAL_CONFIG_2);
  285. return 0;
  286. }
  287. static struct mvebu_mpp_ctrl dove_mpp_controls[] = {
  288. MPP_FUNC_CTRL(0, 0, "mpp0", dove_pmu_mpp_ctrl),
  289. MPP_FUNC_CTRL(1, 1, "mpp1", dove_pmu_mpp_ctrl),
  290. MPP_FUNC_CTRL(2, 2, "mpp2", dove_pmu_mpp_ctrl),
  291. MPP_FUNC_CTRL(3, 3, "mpp3", dove_pmu_mpp_ctrl),
  292. MPP_FUNC_CTRL(4, 4, "mpp4", dove_pmu_mpp_ctrl),
  293. MPP_FUNC_CTRL(5, 5, "mpp5", dove_pmu_mpp_ctrl),
  294. MPP_FUNC_CTRL(6, 6, "mpp6", dove_pmu_mpp_ctrl),
  295. MPP_FUNC_CTRL(7, 7, "mpp7", dove_pmu_mpp_ctrl),
  296. MPP_FUNC_CTRL(8, 8, "mpp8", dove_pmu_mpp_ctrl),
  297. MPP_FUNC_CTRL(9, 9, "mpp9", dove_pmu_mpp_ctrl),
  298. MPP_FUNC_CTRL(10, 10, "mpp10", dove_pmu_mpp_ctrl),
  299. MPP_FUNC_CTRL(11, 11, "mpp11", dove_pmu_mpp_ctrl),
  300. MPP_FUNC_CTRL(12, 12, "mpp12", dove_pmu_mpp_ctrl),
  301. MPP_FUNC_CTRL(13, 13, "mpp13", dove_pmu_mpp_ctrl),
  302. MPP_FUNC_CTRL(14, 14, "mpp14", dove_pmu_mpp_ctrl),
  303. MPP_FUNC_CTRL(15, 15, "mpp15", dove_pmu_mpp_ctrl),
  304. MPP_REG_CTRL(16, 23),
  305. MPP_FUNC_CTRL(24, 39, "mpp_camera", dove_mpp4_ctrl),
  306. MPP_FUNC_CTRL(40, 45, "mpp_sdio0", dove_mpp4_ctrl),
  307. MPP_FUNC_CTRL(46, 51, "mpp_sdio1", dove_mpp4_ctrl),
  308. MPP_FUNC_GPIO_CTRL(52, 57, "mpp_audio1", dove_audio1_ctrl),
  309. MPP_FUNC_CTRL(58, 61, "mpp_spi0", dove_mpp4_ctrl),
  310. MPP_FUNC_CTRL(62, 63, "mpp_uart1", dove_mpp4_ctrl),
  311. MPP_FUNC_CTRL(64, 71, "mpp_nand", dove_nand_ctrl),
  312. MPP_FUNC_CTRL(72, 72, "audio0", dove_audio0_ctrl),
  313. MPP_FUNC_CTRL(73, 73, "twsi", dove_twsi_ctrl),
  314. };
  315. static struct mvebu_mpp_mode dove_mpp_modes[] = {
  316. MPP_MODE(0,
  317. MPP_FUNCTION(0x00, "gpio", NULL),
  318. MPP_FUNCTION(0x02, "uart2", "rts"),
  319. MPP_FUNCTION(0x03, "sdio0", "cd"),
  320. MPP_FUNCTION(0x0f, "lcd0", "pwm"),
  321. MPP_FUNCTION(0x10, "pmu", NULL)),
  322. MPP_MODE(1,
  323. MPP_FUNCTION(0x00, "gpio", NULL),
  324. MPP_FUNCTION(0x02, "uart2", "cts"),
  325. MPP_FUNCTION(0x03, "sdio0", "wp"),
  326. MPP_FUNCTION(0x0f, "lcd1", "pwm"),
  327. MPP_FUNCTION(0x10, "pmu", NULL)),
  328. MPP_MODE(2,
  329. MPP_FUNCTION(0x00, "gpio", NULL),
  330. MPP_FUNCTION(0x01, "sata", "prsnt"),
  331. MPP_FUNCTION(0x02, "uart2", "txd"),
  332. MPP_FUNCTION(0x03, "sdio0", "buspwr"),
  333. MPP_FUNCTION(0x04, "uart1", "rts"),
  334. MPP_FUNCTION(0x10, "pmu", NULL)),
  335. MPP_MODE(3,
  336. MPP_FUNCTION(0x00, "gpio", NULL),
  337. MPP_FUNCTION(0x01, "sata", "act"),
  338. MPP_FUNCTION(0x02, "uart2", "rxd"),
  339. MPP_FUNCTION(0x03, "sdio0", "ledctrl"),
  340. MPP_FUNCTION(0x04, "uart1", "cts"),
  341. MPP_FUNCTION(0x0f, "lcd-spi", "cs1"),
  342. MPP_FUNCTION(0x10, "pmu", NULL)),
  343. MPP_MODE(4,
  344. MPP_FUNCTION(0x00, "gpio", NULL),
  345. MPP_FUNCTION(0x02, "uart3", "rts"),
  346. MPP_FUNCTION(0x03, "sdio1", "cd"),
  347. MPP_FUNCTION(0x04, "spi1", "miso"),
  348. MPP_FUNCTION(0x10, "pmu", NULL)),
  349. MPP_MODE(5,
  350. MPP_FUNCTION(0x00, "gpio", NULL),
  351. MPP_FUNCTION(0x02, "uart3", "cts"),
  352. MPP_FUNCTION(0x03, "sdio1", "wp"),
  353. MPP_FUNCTION(0x04, "spi1", "cs"),
  354. MPP_FUNCTION(0x10, "pmu", NULL)),
  355. MPP_MODE(6,
  356. MPP_FUNCTION(0x00, "gpio", NULL),
  357. MPP_FUNCTION(0x02, "uart3", "txd"),
  358. MPP_FUNCTION(0x03, "sdio1", "buspwr"),
  359. MPP_FUNCTION(0x04, "spi1", "mosi"),
  360. MPP_FUNCTION(0x10, "pmu", NULL)),
  361. MPP_MODE(7,
  362. MPP_FUNCTION(0x00, "gpio", NULL),
  363. MPP_FUNCTION(0x02, "uart3", "rxd"),
  364. MPP_FUNCTION(0x03, "sdio1", "ledctrl"),
  365. MPP_FUNCTION(0x04, "spi1", "sck"),
  366. MPP_FUNCTION(0x10, "pmu", NULL)),
  367. MPP_MODE(8,
  368. MPP_FUNCTION(0x00, "gpio", NULL),
  369. MPP_FUNCTION(0x01, "watchdog", "rstout"),
  370. MPP_FUNCTION(0x10, "pmu", NULL)),
  371. MPP_MODE(9,
  372. MPP_FUNCTION(0x00, "gpio", NULL),
  373. MPP_FUNCTION(0x05, "pex1", "clkreq"),
  374. MPP_FUNCTION(0x10, "pmu", NULL)),
  375. MPP_MODE(10,
  376. MPP_FUNCTION(0x00, "gpio", NULL),
  377. MPP_FUNCTION(0x05, "ssp", "sclk"),
  378. MPP_FUNCTION(0x10, "pmu", NULL)),
  379. MPP_MODE(11,
  380. MPP_FUNCTION(0x00, "gpio", NULL),
  381. MPP_FUNCTION(0x01, "sata", "prsnt"),
  382. MPP_FUNCTION(0x02, "sata-1", "act"),
  383. MPP_FUNCTION(0x03, "sdio0", "ledctrl"),
  384. MPP_FUNCTION(0x04, "sdio1", "ledctrl"),
  385. MPP_FUNCTION(0x05, "pex0", "clkreq"),
  386. MPP_FUNCTION(0x10, "pmu", NULL)),
  387. MPP_MODE(12,
  388. MPP_FUNCTION(0x00, "gpio", NULL),
  389. MPP_FUNCTION(0x01, "sata", "act"),
  390. MPP_FUNCTION(0x02, "uart2", "rts"),
  391. MPP_FUNCTION(0x03, "audio0", "extclk"),
  392. MPP_FUNCTION(0x04, "sdio1", "cd"),
  393. MPP_FUNCTION(0x10, "pmu", NULL)),
  394. MPP_MODE(13,
  395. MPP_FUNCTION(0x00, "gpio", NULL),
  396. MPP_FUNCTION(0x02, "uart2", "cts"),
  397. MPP_FUNCTION(0x03, "audio1", "extclk"),
  398. MPP_FUNCTION(0x04, "sdio1", "wp"),
  399. MPP_FUNCTION(0x05, "ssp", "extclk"),
  400. MPP_FUNCTION(0x10, "pmu", NULL)),
  401. MPP_MODE(14,
  402. MPP_FUNCTION(0x00, "gpio", NULL),
  403. MPP_FUNCTION(0x02, "uart2", "txd"),
  404. MPP_FUNCTION(0x04, "sdio1", "buspwr"),
  405. MPP_FUNCTION(0x05, "ssp", "rxd"),
  406. MPP_FUNCTION(0x10, "pmu", NULL)),
  407. MPP_MODE(15,
  408. MPP_FUNCTION(0x00, "gpio", NULL),
  409. MPP_FUNCTION(0x02, "uart2", "rxd"),
  410. MPP_FUNCTION(0x04, "sdio1", "ledctrl"),
  411. MPP_FUNCTION(0x05, "ssp", "sfrm"),
  412. MPP_FUNCTION(0x10, "pmu", NULL)),
  413. MPP_MODE(16,
  414. MPP_FUNCTION(0x00, "gpio", NULL),
  415. MPP_FUNCTION(0x02, "uart3", "rts"),
  416. MPP_FUNCTION(0x03, "sdio0", "cd"),
  417. MPP_FUNCTION(0x04, "lcd-spi", "cs1"),
  418. MPP_FUNCTION(0x05, "ac97", "sdi1")),
  419. MPP_MODE(17,
  420. MPP_FUNCTION(0x00, "gpio", NULL),
  421. MPP_FUNCTION(0x01, "ac97-1", "sysclko"),
  422. MPP_FUNCTION(0x02, "uart3", "cts"),
  423. MPP_FUNCTION(0x03, "sdio0", "wp"),
  424. MPP_FUNCTION(0x04, "twsi", "sda"),
  425. MPP_FUNCTION(0x05, "ac97", "sdi2")),
  426. MPP_MODE(18,
  427. MPP_FUNCTION(0x00, "gpio", NULL),
  428. MPP_FUNCTION(0x02, "uart3", "txd"),
  429. MPP_FUNCTION(0x03, "sdio0", "buspwr"),
  430. MPP_FUNCTION(0x04, "lcd0", "pwm"),
  431. MPP_FUNCTION(0x05, "ac97", "sdi3")),
  432. MPP_MODE(19,
  433. MPP_FUNCTION(0x00, "gpio", NULL),
  434. MPP_FUNCTION(0x02, "uart3", "rxd"),
  435. MPP_FUNCTION(0x03, "sdio0", "ledctrl"),
  436. MPP_FUNCTION(0x04, "twsi", "sck")),
  437. MPP_MODE(20,
  438. MPP_FUNCTION(0x00, "gpio", NULL),
  439. MPP_FUNCTION(0x01, "ac97", "sysclko"),
  440. MPP_FUNCTION(0x02, "lcd-spi", "miso"),
  441. MPP_FUNCTION(0x03, "sdio1", "cd"),
  442. MPP_FUNCTION(0x05, "sdio0", "cd"),
  443. MPP_FUNCTION(0x06, "spi1", "miso")),
  444. MPP_MODE(21,
  445. MPP_FUNCTION(0x00, "gpio", NULL),
  446. MPP_FUNCTION(0x01, "uart1", "rts"),
  447. MPP_FUNCTION(0x02, "lcd-spi", "cs0"),
  448. MPP_FUNCTION(0x03, "sdio1", "wp"),
  449. MPP_FUNCTION(0x04, "ssp", "sfrm"),
  450. MPP_FUNCTION(0x05, "sdio0", "wp"),
  451. MPP_FUNCTION(0x06, "spi1", "cs")),
  452. MPP_MODE(22,
  453. MPP_FUNCTION(0x00, "gpio", NULL),
  454. MPP_FUNCTION(0x01, "uart1", "cts"),
  455. MPP_FUNCTION(0x02, "lcd-spi", "mosi"),
  456. MPP_FUNCTION(0x03, "sdio1", "buspwr"),
  457. MPP_FUNCTION(0x04, "ssp", "txd"),
  458. MPP_FUNCTION(0x05, "sdio0", "buspwr"),
  459. MPP_FUNCTION(0x06, "spi1", "mosi")),
  460. MPP_MODE(23,
  461. MPP_FUNCTION(0x00, "gpio", NULL),
  462. MPP_FUNCTION(0x02, "lcd-spi", "sck"),
  463. MPP_FUNCTION(0x03, "sdio1", "ledctrl"),
  464. MPP_FUNCTION(0x04, "ssp", "sclk"),
  465. MPP_FUNCTION(0x05, "sdio0", "ledctrl"),
  466. MPP_FUNCTION(0x06, "spi1", "sck")),
  467. MPP_MODE(24,
  468. MPP_FUNCTION(0x00, "camera", NULL),
  469. MPP_FUNCTION(0x01, "gpio", NULL)),
  470. MPP_MODE(40,
  471. MPP_FUNCTION(0x00, "sdio0", NULL),
  472. MPP_FUNCTION(0x01, "gpio", NULL)),
  473. MPP_MODE(46,
  474. MPP_FUNCTION(0x00, "sdio1", NULL),
  475. MPP_FUNCTION(0x01, "gpio", NULL)),
  476. MPP_MODE(52,
  477. MPP_FUNCTION(0x00, "i2s1/spdifo", NULL),
  478. MPP_FUNCTION(0x02, "i2s1", NULL),
  479. MPP_FUNCTION(0x08, "spdifo", NULL),
  480. MPP_FUNCTION(0x0a, "gpio", NULL),
  481. MPP_FUNCTION(0x0b, "twsi", NULL),
  482. MPP_FUNCTION(0x0c, "ssp/spdifo", NULL),
  483. MPP_FUNCTION(0x0e, "ssp", NULL),
  484. MPP_FUNCTION(0x0f, "ssp/twsi", NULL)),
  485. MPP_MODE(58,
  486. MPP_FUNCTION(0x00, "spi0", NULL),
  487. MPP_FUNCTION(0x01, "gpio", NULL)),
  488. MPP_MODE(62,
  489. MPP_FUNCTION(0x00, "uart1", NULL),
  490. MPP_FUNCTION(0x01, "gpio", NULL)),
  491. MPP_MODE(64,
  492. MPP_FUNCTION(0x00, "nand", NULL),
  493. MPP_FUNCTION(0x01, "gpo", NULL)),
  494. MPP_MODE(72,
  495. MPP_FUNCTION(0x00, "i2s", NULL),
  496. MPP_FUNCTION(0x01, "ac97", NULL)),
  497. MPP_MODE(73,
  498. MPP_FUNCTION(0x00, "twsi-none", NULL),
  499. MPP_FUNCTION(0x01, "twsi-opt1", NULL),
  500. MPP_FUNCTION(0x02, "twsi-opt2", NULL),
  501. MPP_FUNCTION(0x03, "twsi-opt3", NULL)),
  502. };
  503. static struct pinctrl_gpio_range dove_mpp_gpio_ranges[] = {
  504. MPP_GPIO_RANGE(0, 0, 0, 32),
  505. MPP_GPIO_RANGE(1, 32, 32, 32),
  506. MPP_GPIO_RANGE(2, 64, 64, 8),
  507. };
  508. static struct mvebu_pinctrl_soc_info dove_pinctrl_info = {
  509. .controls = dove_mpp_controls,
  510. .ncontrols = ARRAY_SIZE(dove_mpp_controls),
  511. .modes = dove_mpp_modes,
  512. .nmodes = ARRAY_SIZE(dove_mpp_modes),
  513. .gpioranges = dove_mpp_gpio_ranges,
  514. .ngpioranges = ARRAY_SIZE(dove_mpp_gpio_ranges),
  515. .variant = 0,
  516. };
  517. static struct clk *clk;
  518. static struct of_device_id dove_pinctrl_of_match[] __devinitdata = {
  519. { .compatible = "marvell,dove-pinctrl", .data = &dove_pinctrl_info },
  520. { }
  521. };
  522. static int __devinit dove_pinctrl_probe(struct platform_device *pdev)
  523. {
  524. const struct of_device_id *match =
  525. of_match_device(dove_pinctrl_of_match, &pdev->dev);
  526. pdev->dev.platform_data = match->data;
  527. /*
  528. * General MPP Configuration Register is part of pdma registers.
  529. * grab clk to make sure it is ticking.
  530. */
  531. clk = devm_clk_get(&pdev->dev, NULL);
  532. if (!IS_ERR(clk))
  533. clk_prepare_enable(clk);
  534. return mvebu_pinctrl_probe(pdev);
  535. }
  536. static int __devexit dove_pinctrl_remove(struct platform_device *pdev)
  537. {
  538. int ret;
  539. ret = mvebu_pinctrl_remove(pdev);
  540. if (!IS_ERR(clk))
  541. clk_disable_unprepare(clk);
  542. return ret;
  543. }
  544. static struct platform_driver dove_pinctrl_driver = {
  545. .driver = {
  546. .name = "dove-pinctrl",
  547. .owner = THIS_MODULE,
  548. .of_match_table = of_match_ptr(dove_pinctrl_of_match),
  549. },
  550. .probe = dove_pinctrl_probe,
  551. .remove = __devexit_p(dove_pinctrl_remove),
  552. };
  553. module_platform_driver(dove_pinctrl_driver);
  554. MODULE_AUTHOR("Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>");
  555. MODULE_DESCRIPTION("Marvell Dove pinctrl driver");
  556. MODULE_LICENSE("GPL v2");