pinctrl-merrifield.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965
  1. /*
  2. * Intel Merrifield SoC pinctrl driver
  3. *
  4. * Copyright (C) 2016, Intel Corporation
  5. * Author: Andy Shevchenko <andriy.shevchenko@linux.intel.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. #include <linux/bitops.h>
  12. #include <linux/err.h>
  13. #include <linux/io.h>
  14. #include <linux/module.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/pinctrl/pinconf.h>
  17. #include <linux/pinctrl/pinconf-generic.h>
  18. #include <linux/pinctrl/pinctrl.h>
  19. #include <linux/pinctrl/pinmux.h>
  20. #include "pinctrl-intel.h"
  21. #define MRFLD_FAMILY_NR 64
  22. #define MRFLD_FAMILY_LEN 0x400
  23. #define SLEW_OFFSET 0x000
  24. #define BUFCFG_OFFSET 0x100
  25. #define MISC_OFFSET 0x300
  26. #define BUFCFG_PINMODE_SHIFT 0
  27. #define BUFCFG_PINMODE_MASK GENMASK(2, 0)
  28. #define BUFCFG_PINMODE_GPIO 0
  29. #define BUFCFG_PUPD_VAL_SHIFT 4
  30. #define BUFCFG_PUPD_VAL_MASK GENMASK(5, 4)
  31. #define BUFCFG_PUPD_VAL_2K 0
  32. #define BUFCFG_PUPD_VAL_20K 1
  33. #define BUFCFG_PUPD_VAL_50K 2
  34. #define BUFCFG_PUPD_VAL_910 3
  35. #define BUFCFG_PU_EN BIT(8)
  36. #define BUFCFG_PD_EN BIT(9)
  37. #define BUFCFG_Px_EN_MASK GENMASK(9, 8)
  38. #define BUFCFG_SLEWSEL BIT(10)
  39. #define BUFCFG_OVINEN BIT(12)
  40. #define BUFCFG_OVINEN_EN BIT(13)
  41. #define BUFCFG_OVINEN_MASK GENMASK(13, 12)
  42. #define BUFCFG_OVOUTEN BIT(14)
  43. #define BUFCFG_OVOUTEN_EN BIT(15)
  44. #define BUFCFG_OVOUTEN_MASK GENMASK(15, 14)
  45. #define BUFCFG_INDATAOV_VAL BIT(16)
  46. #define BUFCFG_INDATAOV_EN BIT(17)
  47. #define BUFCFG_INDATAOV_MASK GENMASK(17, 16)
  48. #define BUFCFG_OUTDATAOV_VAL BIT(18)
  49. #define BUFCFG_OUTDATAOV_EN BIT(19)
  50. #define BUFCFG_OUTDATAOV_MASK GENMASK(19, 18)
  51. #define BUFCFG_OD_EN BIT(21)
  52. /**
  53. * struct mrfld_family - Intel pin family description
  54. * @barno: MMIO BAR number where registers for this family reside
  55. * @pin_base: Starting pin of pins in this family
  56. * @npins: Number of pins in this family
  57. * @protected: True if family is protected by access
  58. * @regs: family specific common registers
  59. */
  60. struct mrfld_family {
  61. unsigned int barno;
  62. unsigned int pin_base;
  63. size_t npins;
  64. bool protected;
  65. void __iomem *regs;
  66. };
  67. #define MRFLD_FAMILY(b, s, e) \
  68. { \
  69. .barno = (b), \
  70. .pin_base = (s), \
  71. .npins = (e) - (s) + 1, \
  72. }
  73. #define MRFLD_FAMILY_PROTECTED(b, s, e) \
  74. { \
  75. .barno = (b), \
  76. .pin_base = (s), \
  77. .npins = (e) - (s) + 1, \
  78. .protected = true, \
  79. }
  80. static const struct pinctrl_pin_desc mrfld_pins[] = {
  81. /* Family 0: OCP2SSC (0 pins) */
  82. /* Family 1: ULPI (13 pins) */
  83. PINCTRL_PIN(0, "ULPI_CLK"),
  84. PINCTRL_PIN(1, "ULPI_D0"),
  85. PINCTRL_PIN(2, "ULPI_D1"),
  86. PINCTRL_PIN(3, "ULPI_D2"),
  87. PINCTRL_PIN(4, "ULPI_D3"),
  88. PINCTRL_PIN(5, "ULPI_D4"),
  89. PINCTRL_PIN(6, "ULPI_D5"),
  90. PINCTRL_PIN(7, "ULPI_D6"),
  91. PINCTRL_PIN(8, "ULPI_D7"),
  92. PINCTRL_PIN(9, "ULPI_DIR"),
  93. PINCTRL_PIN(10, "ULPI_NXT"),
  94. PINCTRL_PIN(11, "ULPI_REFCLK"),
  95. PINCTRL_PIN(12, "ULPI_STP"),
  96. /* Family 2: eMMC (24 pins) */
  97. PINCTRL_PIN(13, "EMMC_CLK"),
  98. PINCTRL_PIN(14, "EMMC_CMD"),
  99. PINCTRL_PIN(15, "EMMC_D0"),
  100. PINCTRL_PIN(16, "EMMC_D1"),
  101. PINCTRL_PIN(17, "EMMC_D2"),
  102. PINCTRL_PIN(18, "EMMC_D3"),
  103. PINCTRL_PIN(19, "EMMC_D4"),
  104. PINCTRL_PIN(20, "EMMC_D5"),
  105. PINCTRL_PIN(21, "EMMC_D6"),
  106. PINCTRL_PIN(22, "EMMC_D7"),
  107. PINCTRL_PIN(23, "EMMC_RST_N"),
  108. PINCTRL_PIN(24, "GP154"),
  109. PINCTRL_PIN(25, "GP155"),
  110. PINCTRL_PIN(26, "GP156"),
  111. PINCTRL_PIN(27, "GP157"),
  112. PINCTRL_PIN(28, "GP158"),
  113. PINCTRL_PIN(29, "GP159"),
  114. PINCTRL_PIN(30, "GP160"),
  115. PINCTRL_PIN(31, "GP161"),
  116. PINCTRL_PIN(32, "GP162"),
  117. PINCTRL_PIN(33, "GP163"),
  118. PINCTRL_PIN(34, "GP97"),
  119. PINCTRL_PIN(35, "GP14"),
  120. PINCTRL_PIN(36, "GP15"),
  121. /* Family 3: SDIO (20 pins) */
  122. PINCTRL_PIN(37, "GP77_SD_CD"),
  123. PINCTRL_PIN(38, "GP78_SD_CLK"),
  124. PINCTRL_PIN(39, "GP79_SD_CMD"),
  125. PINCTRL_PIN(40, "GP80_SD_D0"),
  126. PINCTRL_PIN(41, "GP81_SD_D1"),
  127. PINCTRL_PIN(42, "GP82_SD_D2"),
  128. PINCTRL_PIN(43, "GP83_SD_D3"),
  129. PINCTRL_PIN(44, "GP84_SD_LS_CLK_FB"),
  130. PINCTRL_PIN(45, "GP85_SD_LS_CMD_DIR"),
  131. PINCTRL_PIN(46, "GP86_SD_LVL_D_DIR"),
  132. PINCTRL_PIN(47, "GP88_SD_LS_SEL"),
  133. PINCTRL_PIN(48, "GP87_SD_PD"),
  134. PINCTRL_PIN(49, "GP89_SD_WP"),
  135. PINCTRL_PIN(50, "GP90_SDIO_CLK"),
  136. PINCTRL_PIN(51, "GP91_SDIO_CMD"),
  137. PINCTRL_PIN(52, "GP92_SDIO_D0"),
  138. PINCTRL_PIN(53, "GP93_SDIO_D1"),
  139. PINCTRL_PIN(54, "GP94_SDIO_D2"),
  140. PINCTRL_PIN(55, "GP95_SDIO_D3"),
  141. PINCTRL_PIN(56, "GP96_SDIO_PD"),
  142. /* Family 4: HSI (8 pins) */
  143. PINCTRL_PIN(57, "HSI_ACDATA"),
  144. PINCTRL_PIN(58, "HSI_ACFLAG"),
  145. PINCTRL_PIN(59, "HSI_ACREADY"),
  146. PINCTRL_PIN(60, "HSI_ACWAKE"),
  147. PINCTRL_PIN(61, "HSI_CADATA"),
  148. PINCTRL_PIN(62, "HSI_CAFLAG"),
  149. PINCTRL_PIN(63, "HSI_CAREADY"),
  150. PINCTRL_PIN(64, "HSI_CAWAKE"),
  151. /* Family 5: SSP Audio (14 pins) */
  152. PINCTRL_PIN(65, "GP70"),
  153. PINCTRL_PIN(66, "GP71"),
  154. PINCTRL_PIN(67, "GP32_I2S_0_CLK"),
  155. PINCTRL_PIN(68, "GP33_I2S_0_FS"),
  156. PINCTRL_PIN(69, "GP34_I2S_0_RXD"),
  157. PINCTRL_PIN(70, "GP35_I2S_0_TXD"),
  158. PINCTRL_PIN(71, "GP36_I2S_1_CLK"),
  159. PINCTRL_PIN(72, "GP37_I2S_1_FS"),
  160. PINCTRL_PIN(73, "GP38_I2S_1_RXD"),
  161. PINCTRL_PIN(74, "GP39_I2S_1_TXD"),
  162. PINCTRL_PIN(75, "GP40_I2S_2_CLK"),
  163. PINCTRL_PIN(76, "GP41_I2S_2_FS"),
  164. PINCTRL_PIN(77, "GP42_I2S_2_RXD"),
  165. PINCTRL_PIN(78, "GP43_I2S_2_TXD"),
  166. /* Family 6: GP SSP (22 pins) */
  167. PINCTRL_PIN(79, "GP120_SPI_3_CLK"),
  168. PINCTRL_PIN(80, "GP121_SPI_3_SS"),
  169. PINCTRL_PIN(81, "GP122_SPI_3_RXD"),
  170. PINCTRL_PIN(82, "GP123_SPI_3_TXD"),
  171. PINCTRL_PIN(83, "GP102_SPI_4_CLK"),
  172. PINCTRL_PIN(84, "GP103_SPI_4_SS_0"),
  173. PINCTRL_PIN(85, "GP104_SPI_4_SS_1"),
  174. PINCTRL_PIN(86, "GP105_SPI_4_SS_2"),
  175. PINCTRL_PIN(87, "GP106_SPI_4_SS_3"),
  176. PINCTRL_PIN(88, "GP107_SPI_4_RXD"),
  177. PINCTRL_PIN(89, "GP108_SPI_4_TXD"),
  178. PINCTRL_PIN(90, "GP109_SPI_5_CLK"),
  179. PINCTRL_PIN(91, "GP110_SPI_5_SS_0"),
  180. PINCTRL_PIN(92, "GP111_SPI_5_SS_1"),
  181. PINCTRL_PIN(93, "GP112_SPI_5_SS_2"),
  182. PINCTRL_PIN(94, "GP113_SPI_5_SS_3"),
  183. PINCTRL_PIN(95, "GP114_SPI_5_RXD"),
  184. PINCTRL_PIN(96, "GP115_SPI_5_TXD"),
  185. PINCTRL_PIN(97, "GP116_SPI_6_CLK"),
  186. PINCTRL_PIN(98, "GP117_SPI_6_SS"),
  187. PINCTRL_PIN(99, "GP118_SPI_6_RXD"),
  188. PINCTRL_PIN(100, "GP119_SPI_6_TXD"),
  189. /* Family 7: I2C (14 pins) */
  190. PINCTRL_PIN(101, "GP19_I2C_1_SCL"),
  191. PINCTRL_PIN(102, "GP20_I2C_1_SDA"),
  192. PINCTRL_PIN(103, "GP21_I2C_2_SCL"),
  193. PINCTRL_PIN(104, "GP22_I2C_2_SDA"),
  194. PINCTRL_PIN(105, "GP17_I2C_3_SCL_HDMI"),
  195. PINCTRL_PIN(106, "GP18_I2C_3_SDA_HDMI"),
  196. PINCTRL_PIN(107, "GP23_I2C_4_SCL"),
  197. PINCTRL_PIN(108, "GP24_I2C_4_SDA"),
  198. PINCTRL_PIN(109, "GP25_I2C_5_SCL"),
  199. PINCTRL_PIN(110, "GP26_I2C_5_SDA"),
  200. PINCTRL_PIN(111, "GP27_I2C_6_SCL"),
  201. PINCTRL_PIN(112, "GP28_I2C_6_SDA"),
  202. PINCTRL_PIN(113, "GP29_I2C_7_SCL"),
  203. PINCTRL_PIN(114, "GP30_I2C_7_SDA"),
  204. /* Family 8: UART (12 pins) */
  205. PINCTRL_PIN(115, "GP124_UART_0_CTS"),
  206. PINCTRL_PIN(116, "GP125_UART_0_RTS"),
  207. PINCTRL_PIN(117, "GP126_UART_0_RX"),
  208. PINCTRL_PIN(118, "GP127_UART_0_TX"),
  209. PINCTRL_PIN(119, "GP128_UART_1_CTS"),
  210. PINCTRL_PIN(120, "GP129_UART_1_RTS"),
  211. PINCTRL_PIN(121, "GP130_UART_1_RX"),
  212. PINCTRL_PIN(122, "GP131_UART_1_TX"),
  213. PINCTRL_PIN(123, "GP132_UART_2_CTS"),
  214. PINCTRL_PIN(124, "GP133_UART_2_RTS"),
  215. PINCTRL_PIN(125, "GP134_UART_2_RX"),
  216. PINCTRL_PIN(126, "GP135_UART_2_TX"),
  217. /* Family 9: GPIO South (19 pins) */
  218. PINCTRL_PIN(127, "GP177"),
  219. PINCTRL_PIN(128, "GP178"),
  220. PINCTRL_PIN(129, "GP179"),
  221. PINCTRL_PIN(130, "GP180"),
  222. PINCTRL_PIN(131, "GP181"),
  223. PINCTRL_PIN(132, "GP182_PWM2"),
  224. PINCTRL_PIN(133, "GP183_PWM3"),
  225. PINCTRL_PIN(134, "GP184"),
  226. PINCTRL_PIN(135, "GP185"),
  227. PINCTRL_PIN(136, "GP186"),
  228. PINCTRL_PIN(137, "GP187"),
  229. PINCTRL_PIN(138, "GP188"),
  230. PINCTRL_PIN(139, "GP189"),
  231. PINCTRL_PIN(140, "GP64_FAST_INT0"),
  232. PINCTRL_PIN(141, "GP65_FAST_INT1"),
  233. PINCTRL_PIN(142, "GP66_FAST_INT2"),
  234. PINCTRL_PIN(143, "GP67_FAST_INT3"),
  235. PINCTRL_PIN(144, "GP12_PWM0"),
  236. PINCTRL_PIN(145, "GP13_PWM1"),
  237. /* Family 10: Camera Sideband (12 pins) */
  238. PINCTRL_PIN(146, "GP0"),
  239. PINCTRL_PIN(147, "GP1"),
  240. PINCTRL_PIN(148, "GP2"),
  241. PINCTRL_PIN(149, "GP3"),
  242. PINCTRL_PIN(150, "GP4"),
  243. PINCTRL_PIN(151, "GP5"),
  244. PINCTRL_PIN(152, "GP6"),
  245. PINCTRL_PIN(153, "GP7"),
  246. PINCTRL_PIN(154, "GP8"),
  247. PINCTRL_PIN(155, "GP9"),
  248. PINCTRL_PIN(156, "GP10"),
  249. PINCTRL_PIN(157, "GP11"),
  250. /* Family 11: Clock (22 pins) */
  251. PINCTRL_PIN(158, "GP137"),
  252. PINCTRL_PIN(159, "GP138"),
  253. PINCTRL_PIN(160, "GP139"),
  254. PINCTRL_PIN(161, "GP140"),
  255. PINCTRL_PIN(162, "GP141"),
  256. PINCTRL_PIN(163, "GP142"),
  257. PINCTRL_PIN(164, "GP16_HDMI_HPD"),
  258. PINCTRL_PIN(165, "GP68_DSI_A_TE"),
  259. PINCTRL_PIN(166, "GP69_DSI_C_TE"),
  260. PINCTRL_PIN(167, "OSC_CLK_CTRL0"),
  261. PINCTRL_PIN(168, "OSC_CLK_CTRL1"),
  262. PINCTRL_PIN(169, "OSC_CLK0"),
  263. PINCTRL_PIN(170, "OSC_CLK1"),
  264. PINCTRL_PIN(171, "OSC_CLK2"),
  265. PINCTRL_PIN(172, "OSC_CLK3"),
  266. PINCTRL_PIN(173, "OSC_CLK4"),
  267. PINCTRL_PIN(174, "RESETOUT"),
  268. PINCTRL_PIN(175, "PMODE"),
  269. PINCTRL_PIN(176, "PRDY"),
  270. PINCTRL_PIN(177, "PREQ"),
  271. PINCTRL_PIN(178, "GP190"),
  272. PINCTRL_PIN(179, "GP191"),
  273. /* Family 12: MSIC (15 pins) */
  274. PINCTRL_PIN(180, "I2C_0_SCL"),
  275. PINCTRL_PIN(181, "I2C_0_SDA"),
  276. PINCTRL_PIN(182, "IERR"),
  277. PINCTRL_PIN(183, "JTAG_TCK"),
  278. PINCTRL_PIN(184, "JTAG_TDI"),
  279. PINCTRL_PIN(185, "JTAG_TDO"),
  280. PINCTRL_PIN(186, "JTAG_TMS"),
  281. PINCTRL_PIN(187, "JTAG_TRST"),
  282. PINCTRL_PIN(188, "PROCHOT"),
  283. PINCTRL_PIN(189, "RTC_CLK"),
  284. PINCTRL_PIN(190, "SVID_ALERT"),
  285. PINCTRL_PIN(191, "SVID_CLK"),
  286. PINCTRL_PIN(192, "SVID_D"),
  287. PINCTRL_PIN(193, "THERMTRIP"),
  288. PINCTRL_PIN(194, "STANDBY"),
  289. /* Family 13: Keyboard (20 pins) */
  290. PINCTRL_PIN(195, "GP44"),
  291. PINCTRL_PIN(196, "GP45"),
  292. PINCTRL_PIN(197, "GP46"),
  293. PINCTRL_PIN(198, "GP47"),
  294. PINCTRL_PIN(199, "GP48"),
  295. PINCTRL_PIN(200, "GP49"),
  296. PINCTRL_PIN(201, "GP50"),
  297. PINCTRL_PIN(202, "GP51"),
  298. PINCTRL_PIN(203, "GP52"),
  299. PINCTRL_PIN(204, "GP53"),
  300. PINCTRL_PIN(205, "GP54"),
  301. PINCTRL_PIN(206, "GP55"),
  302. PINCTRL_PIN(207, "GP56"),
  303. PINCTRL_PIN(208, "GP57"),
  304. PINCTRL_PIN(209, "GP58"),
  305. PINCTRL_PIN(210, "GP59"),
  306. PINCTRL_PIN(211, "GP60"),
  307. PINCTRL_PIN(212, "GP61"),
  308. PINCTRL_PIN(213, "GP62"),
  309. PINCTRL_PIN(214, "GP63"),
  310. /* Family 14: GPIO North (13 pins) */
  311. PINCTRL_PIN(215, "GP164"),
  312. PINCTRL_PIN(216, "GP165"),
  313. PINCTRL_PIN(217, "GP166"),
  314. PINCTRL_PIN(218, "GP167"),
  315. PINCTRL_PIN(219, "GP168_MJTAG_TCK"),
  316. PINCTRL_PIN(220, "GP169_MJTAG_TDI"),
  317. PINCTRL_PIN(221, "GP170_MJTAG_TDO"),
  318. PINCTRL_PIN(222, "GP171_MJTAG_TMS"),
  319. PINCTRL_PIN(223, "GP172_MJTAG_TRST"),
  320. PINCTRL_PIN(224, "GP173"),
  321. PINCTRL_PIN(225, "GP174"),
  322. PINCTRL_PIN(226, "GP175"),
  323. PINCTRL_PIN(227, "GP176"),
  324. /* Family 15: PTI (5 pins) */
  325. PINCTRL_PIN(228, "GP72_PTI_CLK"),
  326. PINCTRL_PIN(229, "GP73_PTI_D0"),
  327. PINCTRL_PIN(230, "GP74_PTI_D1"),
  328. PINCTRL_PIN(231, "GP75_PTI_D2"),
  329. PINCTRL_PIN(232, "GP76_PTI_D3"),
  330. /* Family 16: USB3 (0 pins) */
  331. /* Family 17: HSIC (0 pins) */
  332. /* Family 18: Broadcast (0 pins) */
  333. };
  334. static const unsigned int mrfld_sdio_pins[] = { 50, 51, 52, 53, 54, 55, 56 };
  335. static const unsigned int mrfld_spi5_pins[] = { 90, 91, 92, 93, 94, 95, 96 };
  336. static const unsigned int mrfld_uart0_pins[] = { 115, 116, 117, 118 };
  337. static const unsigned int mrfld_uart1_pins[] = { 119, 120, 121, 122 };
  338. static const unsigned int mrfld_uart2_pins[] = { 123, 124, 125, 126 };
  339. static const unsigned int mrfld_pwm0_pins[] = { 144 };
  340. static const unsigned int mrfld_pwm1_pins[] = { 145 };
  341. static const unsigned int mrfld_pwm2_pins[] = { 132 };
  342. static const unsigned int mrfld_pwm3_pins[] = { 133 };
  343. static const struct intel_pingroup mrfld_groups[] = {
  344. PIN_GROUP("sdio_grp", mrfld_sdio_pins, 1),
  345. PIN_GROUP("spi5_grp", mrfld_spi5_pins, 1),
  346. PIN_GROUP("uart0_grp", mrfld_uart0_pins, 1),
  347. PIN_GROUP("uart1_grp", mrfld_uart1_pins, 1),
  348. PIN_GROUP("uart2_grp", mrfld_uart2_pins, 1),
  349. PIN_GROUP("pwm0_grp", mrfld_pwm0_pins, 1),
  350. PIN_GROUP("pwm1_grp", mrfld_pwm1_pins, 1),
  351. PIN_GROUP("pwm2_grp", mrfld_pwm2_pins, 1),
  352. PIN_GROUP("pwm3_grp", mrfld_pwm3_pins, 1),
  353. };
  354. static const char * const mrfld_sdio_groups[] = { "sdio_grp" };
  355. static const char * const mrfld_spi5_groups[] = { "spi5_grp" };
  356. static const char * const mrfld_uart0_groups[] = { "uart0_grp" };
  357. static const char * const mrfld_uart1_groups[] = { "uart1_grp" };
  358. static const char * const mrfld_uart2_groups[] = { "uart2_grp" };
  359. static const char * const mrfld_pwm0_groups[] = { "pwm0_grp" };
  360. static const char * const mrfld_pwm1_groups[] = { "pwm1_grp" };
  361. static const char * const mrfld_pwm2_groups[] = { "pwm2_grp" };
  362. static const char * const mrfld_pwm3_groups[] = { "pwm3_grp" };
  363. static const struct intel_function mrfld_functions[] = {
  364. FUNCTION("sdio", mrfld_sdio_groups),
  365. FUNCTION("spi5", mrfld_spi5_groups),
  366. FUNCTION("uart0", mrfld_uart0_groups),
  367. FUNCTION("uart1", mrfld_uart1_groups),
  368. FUNCTION("uart2", mrfld_uart2_groups),
  369. FUNCTION("pwm0", mrfld_pwm0_groups),
  370. FUNCTION("pwm1", mrfld_pwm1_groups),
  371. FUNCTION("pwm2", mrfld_pwm2_groups),
  372. FUNCTION("pwm3", mrfld_pwm3_groups),
  373. };
  374. static const struct mrfld_family mrfld_families[] = {
  375. MRFLD_FAMILY(1, 0, 12),
  376. MRFLD_FAMILY(2, 13, 36),
  377. MRFLD_FAMILY(3, 37, 56),
  378. MRFLD_FAMILY(4, 57, 64),
  379. MRFLD_FAMILY(5, 65, 78),
  380. MRFLD_FAMILY(6, 79, 100),
  381. MRFLD_FAMILY_PROTECTED(7, 101, 114),
  382. MRFLD_FAMILY(8, 115, 126),
  383. MRFLD_FAMILY(9, 127, 145),
  384. MRFLD_FAMILY(10, 146, 157),
  385. MRFLD_FAMILY(11, 158, 179),
  386. MRFLD_FAMILY_PROTECTED(12, 180, 194),
  387. MRFLD_FAMILY(13, 195, 214),
  388. MRFLD_FAMILY(14, 215, 227),
  389. MRFLD_FAMILY(15, 228, 232),
  390. };
  391. /**
  392. * struct mrfld_pinctrl - Intel Merrifield pinctrl private structure
  393. * @dev: Pointer to the device structure
  394. * @lock: Lock to serialize register access
  395. * @pctldesc: Pin controller description
  396. * @pctldev: Pointer to the pin controller device
  397. * @families: Array of families this pinctrl handles
  398. * @nfamilies: Number of families in the array
  399. * @functions: Array of functions
  400. * @nfunctions: Number of functions in the array
  401. * @groups: Array of pin groups
  402. * @ngroups: Number of groups in the array
  403. * @pins: Array of pins this pinctrl controls
  404. * @npins: Number of pins in the array
  405. */
  406. struct mrfld_pinctrl {
  407. struct device *dev;
  408. raw_spinlock_t lock;
  409. struct pinctrl_desc pctldesc;
  410. struct pinctrl_dev *pctldev;
  411. /* Pin controller configuration */
  412. const struct mrfld_family *families;
  413. size_t nfamilies;
  414. const struct intel_function *functions;
  415. size_t nfunctions;
  416. const struct intel_pingroup *groups;
  417. size_t ngroups;
  418. const struct pinctrl_pin_desc *pins;
  419. size_t npins;
  420. };
  421. #define pin_to_bufno(f, p) ((p) - (f)->pin_base)
  422. static const struct mrfld_family *mrfld_get_family(struct mrfld_pinctrl *mp,
  423. unsigned int pin)
  424. {
  425. const struct mrfld_family *family;
  426. unsigned int i;
  427. for (i = 0; i < mp->nfamilies; i++) {
  428. family = &mp->families[i];
  429. if (pin >= family->pin_base &&
  430. pin < family->pin_base + family->npins)
  431. return family;
  432. }
  433. dev_warn(mp->dev, "failed to find family for pin %u\n", pin);
  434. return NULL;
  435. }
  436. static bool mrfld_buf_available(struct mrfld_pinctrl *mp, unsigned int pin)
  437. {
  438. const struct mrfld_family *family;
  439. family = mrfld_get_family(mp, pin);
  440. if (!family)
  441. return false;
  442. return !family->protected;
  443. }
  444. static void __iomem *mrfld_get_bufcfg(struct mrfld_pinctrl *mp, unsigned int pin)
  445. {
  446. const struct mrfld_family *family;
  447. unsigned int bufno;
  448. family = mrfld_get_family(mp, pin);
  449. if (!family)
  450. return NULL;
  451. bufno = pin_to_bufno(family, pin);
  452. return family->regs + BUFCFG_OFFSET + bufno * 4;
  453. }
  454. static int mrfld_get_groups_count(struct pinctrl_dev *pctldev)
  455. {
  456. struct mrfld_pinctrl *mp = pinctrl_dev_get_drvdata(pctldev);
  457. return mp->ngroups;
  458. }
  459. static const char *mrfld_get_group_name(struct pinctrl_dev *pctldev,
  460. unsigned int group)
  461. {
  462. struct mrfld_pinctrl *mp = pinctrl_dev_get_drvdata(pctldev);
  463. return mp->groups[group].name;
  464. }
  465. static int mrfld_get_group_pins(struct pinctrl_dev *pctldev, unsigned int group,
  466. const unsigned int **pins, unsigned int *npins)
  467. {
  468. struct mrfld_pinctrl *mp = pinctrl_dev_get_drvdata(pctldev);
  469. *pins = mp->groups[group].pins;
  470. *npins = mp->groups[group].npins;
  471. return 0;
  472. }
  473. static void mrfld_pin_dbg_show(struct pinctrl_dev *pctldev, struct seq_file *s,
  474. unsigned int pin)
  475. {
  476. struct mrfld_pinctrl *mp = pinctrl_dev_get_drvdata(pctldev);
  477. void __iomem *bufcfg;
  478. u32 value, mode;
  479. if (!mrfld_buf_available(mp, pin)) {
  480. seq_puts(s, "not available");
  481. return;
  482. }
  483. bufcfg = mrfld_get_bufcfg(mp, pin);
  484. value = readl(bufcfg);
  485. mode = (value & BUFCFG_PINMODE_MASK) >> BUFCFG_PINMODE_SHIFT;
  486. if (!mode)
  487. seq_puts(s, "GPIO ");
  488. else
  489. seq_printf(s, "mode %d ", mode);
  490. seq_printf(s, "0x%08x", value);
  491. }
  492. static const struct pinctrl_ops mrfld_pinctrl_ops = {
  493. .get_groups_count = mrfld_get_groups_count,
  494. .get_group_name = mrfld_get_group_name,
  495. .get_group_pins = mrfld_get_group_pins,
  496. .pin_dbg_show = mrfld_pin_dbg_show,
  497. };
  498. static int mrfld_get_functions_count(struct pinctrl_dev *pctldev)
  499. {
  500. struct mrfld_pinctrl *mp = pinctrl_dev_get_drvdata(pctldev);
  501. return mp->nfunctions;
  502. }
  503. static const char *mrfld_get_function_name(struct pinctrl_dev *pctldev,
  504. unsigned int function)
  505. {
  506. struct mrfld_pinctrl *mp = pinctrl_dev_get_drvdata(pctldev);
  507. return mp->functions[function].name;
  508. }
  509. static int mrfld_get_function_groups(struct pinctrl_dev *pctldev,
  510. unsigned int function,
  511. const char * const **groups,
  512. unsigned int * const ngroups)
  513. {
  514. struct mrfld_pinctrl *mp = pinctrl_dev_get_drvdata(pctldev);
  515. *groups = mp->functions[function].groups;
  516. *ngroups = mp->functions[function].ngroups;
  517. return 0;
  518. }
  519. static void mrfld_update_bufcfg(struct mrfld_pinctrl *mp, unsigned int pin,
  520. u32 bits, u32 mask)
  521. {
  522. void __iomem *bufcfg;
  523. u32 value;
  524. bufcfg = mrfld_get_bufcfg(mp, pin);
  525. value = readl(bufcfg);
  526. value &= ~mask;
  527. value |= bits & mask;
  528. writel(value, bufcfg);
  529. }
  530. static int mrfld_pinmux_set_mux(struct pinctrl_dev *pctldev,
  531. unsigned int function,
  532. unsigned int group)
  533. {
  534. struct mrfld_pinctrl *mp = pinctrl_dev_get_drvdata(pctldev);
  535. const struct intel_pingroup *grp = &mp->groups[group];
  536. u32 bits = grp->mode << BUFCFG_PINMODE_SHIFT;
  537. u32 mask = BUFCFG_PINMODE_MASK;
  538. unsigned long flags;
  539. unsigned int i;
  540. /*
  541. * All pins in the groups needs to be accessible and writable
  542. * before we can enable the mux for this group.
  543. */
  544. for (i = 0; i < grp->npins; i++) {
  545. if (!mrfld_buf_available(mp, grp->pins[i]))
  546. return -EBUSY;
  547. }
  548. /* Now enable the mux setting for each pin in the group */
  549. raw_spin_lock_irqsave(&mp->lock, flags);
  550. for (i = 0; i < grp->npins; i++)
  551. mrfld_update_bufcfg(mp, grp->pins[i], bits, mask);
  552. raw_spin_unlock_irqrestore(&mp->lock, flags);
  553. return 0;
  554. }
  555. static int mrfld_gpio_request_enable(struct pinctrl_dev *pctldev,
  556. struct pinctrl_gpio_range *range,
  557. unsigned int pin)
  558. {
  559. struct mrfld_pinctrl *mp = pinctrl_dev_get_drvdata(pctldev);
  560. u32 bits = BUFCFG_PINMODE_GPIO << BUFCFG_PINMODE_SHIFT;
  561. u32 mask = BUFCFG_PINMODE_MASK;
  562. unsigned long flags;
  563. if (!mrfld_buf_available(mp, pin))
  564. return -EBUSY;
  565. raw_spin_lock_irqsave(&mp->lock, flags);
  566. mrfld_update_bufcfg(mp, pin, bits, mask);
  567. raw_spin_unlock_irqrestore(&mp->lock, flags);
  568. return 0;
  569. }
  570. static const struct pinmux_ops mrfld_pinmux_ops = {
  571. .get_functions_count = mrfld_get_functions_count,
  572. .get_function_name = mrfld_get_function_name,
  573. .get_function_groups = mrfld_get_function_groups,
  574. .set_mux = mrfld_pinmux_set_mux,
  575. .gpio_request_enable = mrfld_gpio_request_enable,
  576. };
  577. static int mrfld_config_get(struct pinctrl_dev *pctldev, unsigned int pin,
  578. unsigned long *config)
  579. {
  580. struct mrfld_pinctrl *mp = pinctrl_dev_get_drvdata(pctldev);
  581. enum pin_config_param param = pinconf_to_config_param(*config);
  582. u32 value, term;
  583. u16 arg = 0;
  584. if (!mrfld_buf_available(mp, pin))
  585. return -ENOTSUPP;
  586. value = readl(mrfld_get_bufcfg(mp, pin));
  587. term = (value & BUFCFG_PUPD_VAL_MASK) >> BUFCFG_PUPD_VAL_SHIFT;
  588. switch (param) {
  589. case PIN_CONFIG_BIAS_DISABLE:
  590. if (value & BUFCFG_Px_EN_MASK)
  591. return -EINVAL;
  592. break;
  593. case PIN_CONFIG_BIAS_PULL_UP:
  594. if ((value & BUFCFG_Px_EN_MASK) != BUFCFG_PU_EN)
  595. return -EINVAL;
  596. switch (term) {
  597. case BUFCFG_PUPD_VAL_910:
  598. arg = 910;
  599. break;
  600. case BUFCFG_PUPD_VAL_2K:
  601. arg = 2000;
  602. break;
  603. case BUFCFG_PUPD_VAL_20K:
  604. arg = 20000;
  605. break;
  606. case BUFCFG_PUPD_VAL_50K:
  607. arg = 50000;
  608. break;
  609. }
  610. break;
  611. case PIN_CONFIG_BIAS_PULL_DOWN:
  612. if ((value & BUFCFG_Px_EN_MASK) != BUFCFG_PD_EN)
  613. return -EINVAL;
  614. switch (term) {
  615. case BUFCFG_PUPD_VAL_910:
  616. arg = 910;
  617. break;
  618. case BUFCFG_PUPD_VAL_2K:
  619. arg = 2000;
  620. break;
  621. case BUFCFG_PUPD_VAL_20K:
  622. arg = 20000;
  623. break;
  624. case BUFCFG_PUPD_VAL_50K:
  625. arg = 50000;
  626. break;
  627. }
  628. break;
  629. case PIN_CONFIG_DRIVE_OPEN_DRAIN:
  630. if (!(value & BUFCFG_OD_EN))
  631. return -EINVAL;
  632. break;
  633. case PIN_CONFIG_SLEW_RATE:
  634. if (!(value & BUFCFG_SLEWSEL))
  635. arg = 0;
  636. else
  637. arg = 1;
  638. break;
  639. default:
  640. return -ENOTSUPP;
  641. }
  642. *config = pinconf_to_config_packed(param, arg);
  643. return 0;
  644. }
  645. static int mrfld_config_set_pin(struct mrfld_pinctrl *mp, unsigned int pin,
  646. unsigned long config)
  647. {
  648. unsigned int param = pinconf_to_config_param(config);
  649. unsigned int arg = pinconf_to_config_argument(config);
  650. u32 bits = 0, mask = 0;
  651. unsigned long flags;
  652. switch (param) {
  653. case PIN_CONFIG_BIAS_DISABLE:
  654. mask |= BUFCFG_Px_EN_MASK | BUFCFG_PUPD_VAL_MASK;
  655. break;
  656. case PIN_CONFIG_BIAS_PULL_UP:
  657. mask |= BUFCFG_Px_EN_MASK | BUFCFG_PUPD_VAL_MASK;
  658. bits |= BUFCFG_PU_EN;
  659. /* Set default strength value in case none is given */
  660. if (arg == 1)
  661. arg = 20000;
  662. switch (arg) {
  663. case 50000:
  664. bits |= BUFCFG_PUPD_VAL_50K << BUFCFG_PUPD_VAL_SHIFT;
  665. break;
  666. case 20000:
  667. bits |= BUFCFG_PUPD_VAL_20K << BUFCFG_PUPD_VAL_SHIFT;
  668. break;
  669. case 2000:
  670. bits |= BUFCFG_PUPD_VAL_2K << BUFCFG_PUPD_VAL_SHIFT;
  671. break;
  672. default:
  673. return -EINVAL;
  674. }
  675. break;
  676. case PIN_CONFIG_BIAS_PULL_DOWN:
  677. mask |= BUFCFG_Px_EN_MASK | BUFCFG_PUPD_VAL_MASK;
  678. bits |= BUFCFG_PD_EN;
  679. /* Set default strength value in case none is given */
  680. if (arg == 1)
  681. arg = 20000;
  682. switch (arg) {
  683. case 50000:
  684. bits |= BUFCFG_PUPD_VAL_50K << BUFCFG_PUPD_VAL_SHIFT;
  685. break;
  686. case 20000:
  687. bits |= BUFCFG_PUPD_VAL_20K << BUFCFG_PUPD_VAL_SHIFT;
  688. break;
  689. case 2000:
  690. bits |= BUFCFG_PUPD_VAL_2K << BUFCFG_PUPD_VAL_SHIFT;
  691. break;
  692. default:
  693. return -EINVAL;
  694. }
  695. break;
  696. case PIN_CONFIG_DRIVE_OPEN_DRAIN:
  697. mask |= BUFCFG_OD_EN;
  698. if (arg)
  699. bits |= BUFCFG_OD_EN;
  700. break;
  701. case PIN_CONFIG_SLEW_RATE:
  702. mask |= BUFCFG_SLEWSEL;
  703. if (arg)
  704. bits |= BUFCFG_SLEWSEL;
  705. break;
  706. }
  707. raw_spin_lock_irqsave(&mp->lock, flags);
  708. mrfld_update_bufcfg(mp, pin, bits, mask);
  709. raw_spin_unlock_irqrestore(&mp->lock, flags);
  710. return 0;
  711. }
  712. static int mrfld_config_set(struct pinctrl_dev *pctldev, unsigned int pin,
  713. unsigned long *configs, unsigned int nconfigs)
  714. {
  715. struct mrfld_pinctrl *mp = pinctrl_dev_get_drvdata(pctldev);
  716. unsigned int i;
  717. int ret;
  718. if (!mrfld_buf_available(mp, pin))
  719. return -ENOTSUPP;
  720. for (i = 0; i < nconfigs; i++) {
  721. switch (pinconf_to_config_param(configs[i])) {
  722. case PIN_CONFIG_BIAS_DISABLE:
  723. case PIN_CONFIG_BIAS_PULL_UP:
  724. case PIN_CONFIG_BIAS_PULL_DOWN:
  725. case PIN_CONFIG_DRIVE_OPEN_DRAIN:
  726. case PIN_CONFIG_SLEW_RATE:
  727. ret = mrfld_config_set_pin(mp, pin, configs[i]);
  728. if (ret)
  729. return ret;
  730. break;
  731. default:
  732. return -ENOTSUPP;
  733. }
  734. }
  735. return 0;
  736. }
  737. static int mrfld_config_group_get(struct pinctrl_dev *pctldev,
  738. unsigned int group, unsigned long *config)
  739. {
  740. const unsigned int *pins;
  741. unsigned int npins;
  742. int ret;
  743. ret = mrfld_get_group_pins(pctldev, group, &pins, &npins);
  744. if (ret)
  745. return ret;
  746. ret = mrfld_config_get(pctldev, pins[0], config);
  747. if (ret)
  748. return ret;
  749. return 0;
  750. }
  751. static int mrfld_config_group_set(struct pinctrl_dev *pctldev,
  752. unsigned int group, unsigned long *configs,
  753. unsigned int num_configs)
  754. {
  755. const unsigned int *pins;
  756. unsigned int npins;
  757. int i, ret;
  758. ret = mrfld_get_group_pins(pctldev, group, &pins, &npins);
  759. if (ret)
  760. return ret;
  761. for (i = 0; i < npins; i++) {
  762. ret = mrfld_config_set(pctldev, pins[i], configs, num_configs);
  763. if (ret)
  764. return ret;
  765. }
  766. return 0;
  767. }
  768. static const struct pinconf_ops mrfld_pinconf_ops = {
  769. .is_generic = true,
  770. .pin_config_get = mrfld_config_get,
  771. .pin_config_set = mrfld_config_set,
  772. .pin_config_group_get = mrfld_config_group_get,
  773. .pin_config_group_set = mrfld_config_group_set,
  774. };
  775. static const struct pinctrl_desc mrfld_pinctrl_desc = {
  776. .pctlops = &mrfld_pinctrl_ops,
  777. .pmxops = &mrfld_pinmux_ops,
  778. .confops = &mrfld_pinconf_ops,
  779. .owner = THIS_MODULE,
  780. };
  781. static int mrfld_pinctrl_probe(struct platform_device *pdev)
  782. {
  783. struct mrfld_family *families;
  784. struct mrfld_pinctrl *mp;
  785. struct resource *mem;
  786. void __iomem *regs;
  787. size_t nfamilies;
  788. unsigned int i;
  789. mp = devm_kzalloc(&pdev->dev, sizeof(*mp), GFP_KERNEL);
  790. if (!mp)
  791. return -ENOMEM;
  792. mp->dev = &pdev->dev;
  793. raw_spin_lock_init(&mp->lock);
  794. mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  795. regs = devm_ioremap_resource(&pdev->dev, mem);
  796. if (IS_ERR(regs))
  797. return PTR_ERR(regs);
  798. /*
  799. * Make a copy of the families which we can use to hold pointers
  800. * to the registers.
  801. */
  802. nfamilies = ARRAY_SIZE(mrfld_families),
  803. families = devm_kmemdup(&pdev->dev, mrfld_families,
  804. sizeof(mrfld_families),
  805. GFP_KERNEL);
  806. if (!families)
  807. return -ENOMEM;
  808. /* Splice memory resource by chunk per family */
  809. for (i = 0; i < nfamilies; i++) {
  810. struct mrfld_family *family = &families[i];
  811. family->regs = regs + family->barno * MRFLD_FAMILY_LEN;
  812. }
  813. mp->families = families;
  814. mp->nfamilies = nfamilies;
  815. mp->functions = mrfld_functions;
  816. mp->nfunctions = ARRAY_SIZE(mrfld_functions);
  817. mp->groups = mrfld_groups;
  818. mp->ngroups = ARRAY_SIZE(mrfld_groups);
  819. mp->pctldesc = mrfld_pinctrl_desc;
  820. mp->pctldesc.name = dev_name(&pdev->dev);
  821. mp->pctldesc.pins = mrfld_pins;
  822. mp->pctldesc.npins = ARRAY_SIZE(mrfld_pins);
  823. mp->pctldev = devm_pinctrl_register(&pdev->dev, &mp->pctldesc, mp);
  824. if (IS_ERR(mp->pctldev)) {
  825. dev_err(&pdev->dev, "failed to register pinctrl driver\n");
  826. return PTR_ERR(mp->pctldev);
  827. }
  828. platform_set_drvdata(pdev, mp);
  829. return 0;
  830. }
  831. static struct platform_driver mrfld_pinctrl_driver = {
  832. .probe = mrfld_pinctrl_probe,
  833. .driver = {
  834. .name = "pinctrl-merrifield",
  835. },
  836. };
  837. static int __init mrfld_pinctrl_init(void)
  838. {
  839. return platform_driver_register(&mrfld_pinctrl_driver);
  840. }
  841. subsys_initcall(mrfld_pinctrl_init);
  842. static void __exit mrfld_pinctrl_exit(void)
  843. {
  844. platform_driver_unregister(&mrfld_pinctrl_driver);
  845. }
  846. module_exit(mrfld_pinctrl_exit);
  847. MODULE_AUTHOR("Andy Shevchenko <andriy.shevchenko@linux.intel.com>");
  848. MODULE_DESCRIPTION("Intel Merrifield SoC pinctrl driver");
  849. MODULE_LICENSE("GPL v2");
  850. MODULE_ALIAS("platform:pinctrl-merrifield");