pinctrl-merrifield.c 26 KB

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