pinctrl-cygnus-mux.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. // Copyright (C) 2014-2017 Broadcom
  3. /*
  4. * Broadcom Cygnus IOMUX driver
  5. *
  6. * This file contains the Cygnus IOMUX driver that supports group based PINMUX
  7. * configuration. Although PINMUX configuration is mainly group based, the
  8. * Cygnus IOMUX controller allows certain pins to be individually muxed to GPIO
  9. * function, and therefore be controlled by the Cygnus ASIU GPIO controller
  10. */
  11. #include <linux/err.h>
  12. #include <linux/io.h>
  13. #include <linux/of.h>
  14. #include <linux/slab.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/pinctrl/pinctrl.h>
  17. #include <linux/pinctrl/pinmux.h>
  18. #include <linux/pinctrl/pinconf.h>
  19. #include <linux/pinctrl/pinconf-generic.h>
  20. #include "../core.h"
  21. #include "../pinctrl-utils.h"
  22. #define CYGNUS_NUM_IOMUX_REGS 8
  23. #define CYGNUS_NUM_MUX_PER_REG 8
  24. #define CYGNUS_NUM_IOMUX (CYGNUS_NUM_IOMUX_REGS * \
  25. CYGNUS_NUM_MUX_PER_REG)
  26. /*
  27. * Cygnus IOMUX register description
  28. *
  29. * @offset: register offset for mux configuration of a group
  30. * @shift: bit shift for mux configuration of a group
  31. * @alt: alternate function to set to
  32. */
  33. struct cygnus_mux {
  34. unsigned int offset;
  35. unsigned int shift;
  36. unsigned int alt;
  37. };
  38. /*
  39. * Keep track of Cygnus IOMUX configuration and prevent double configuration
  40. *
  41. * @cygnus_mux: Cygnus IOMUX register description
  42. * @is_configured: flag to indicate whether a mux setting has already been
  43. * configured
  44. */
  45. struct cygnus_mux_log {
  46. struct cygnus_mux mux;
  47. bool is_configured;
  48. };
  49. /*
  50. * Group based IOMUX configuration
  51. *
  52. * @name: name of the group
  53. * @pins: array of pins used by this group
  54. * @num_pins: total number of pins used by this group
  55. * @mux: Cygnus group based IOMUX configuration
  56. */
  57. struct cygnus_pin_group {
  58. const char *name;
  59. const unsigned *pins;
  60. unsigned num_pins;
  61. struct cygnus_mux mux;
  62. };
  63. /*
  64. * Cygnus mux function and supported pin groups
  65. *
  66. * @name: name of the function
  67. * @groups: array of groups that can be supported by this function
  68. * @num_groups: total number of groups that can be supported by this function
  69. */
  70. struct cygnus_pin_function {
  71. const char *name;
  72. const char * const *groups;
  73. unsigned num_groups;
  74. };
  75. /*
  76. * Cygnus IOMUX pinctrl core
  77. *
  78. * @pctl: pointer to pinctrl_dev
  79. * @dev: pointer to device
  80. * @base0: first I/O register base of the Cygnus IOMUX controller
  81. * @base1: second I/O register base
  82. * @groups: pointer to array of groups
  83. * @num_groups: total number of groups
  84. * @functions: pointer to array of functions
  85. * @num_functions: total number of functions
  86. * @mux_log: pointer to the array of mux logs
  87. * @lock: lock to protect register access
  88. */
  89. struct cygnus_pinctrl {
  90. struct pinctrl_dev *pctl;
  91. struct device *dev;
  92. void __iomem *base0;
  93. void __iomem *base1;
  94. const struct cygnus_pin_group *groups;
  95. unsigned num_groups;
  96. const struct cygnus_pin_function *functions;
  97. unsigned num_functions;
  98. struct cygnus_mux_log *mux_log;
  99. spinlock_t lock;
  100. };
  101. /*
  102. * Certain pins can be individually muxed to GPIO function
  103. *
  104. * @is_supported: flag to indicate GPIO mux is supported for this pin
  105. * @offset: register offset for GPIO mux override of a pin
  106. * @shift: bit shift for GPIO mux override of a pin
  107. */
  108. struct cygnus_gpio_mux {
  109. int is_supported;
  110. unsigned int offset;
  111. unsigned int shift;
  112. };
  113. /*
  114. * Description of a pin in Cygnus
  115. *
  116. * @pin: pin number
  117. * @name: pin name
  118. * @gpio_mux: GPIO override related information
  119. */
  120. struct cygnus_pin {
  121. unsigned pin;
  122. char *name;
  123. struct cygnus_gpio_mux gpio_mux;
  124. };
  125. #define CYGNUS_PIN_DESC(p, n, i, o, s) \
  126. { \
  127. .pin = p, \
  128. .name = n, \
  129. .gpio_mux = { \
  130. .is_supported = i, \
  131. .offset = o, \
  132. .shift = s, \
  133. }, \
  134. }
  135. /*
  136. * List of pins in Cygnus
  137. */
  138. static struct cygnus_pin cygnus_pins[] = {
  139. CYGNUS_PIN_DESC(0, "ext_device_reset_n", 0, 0, 0),
  140. CYGNUS_PIN_DESC(1, "chip_mode0", 0, 0, 0),
  141. CYGNUS_PIN_DESC(2, "chip_mode1", 0, 0, 0),
  142. CYGNUS_PIN_DESC(3, "chip_mode2", 0, 0, 0),
  143. CYGNUS_PIN_DESC(4, "chip_mode3", 0, 0, 0),
  144. CYGNUS_PIN_DESC(5, "chip_mode4", 0, 0, 0),
  145. CYGNUS_PIN_DESC(6, "bsc0_scl", 0, 0, 0),
  146. CYGNUS_PIN_DESC(7, "bsc0_sda", 0, 0, 0),
  147. CYGNUS_PIN_DESC(8, "bsc1_scl", 0, 0, 0),
  148. CYGNUS_PIN_DESC(9, "bsc1_sda", 0, 0, 0),
  149. CYGNUS_PIN_DESC(10, "d1w_dq", 1, 0x28, 0),
  150. CYGNUS_PIN_DESC(11, "d1wowstz_l", 1, 0x4, 28),
  151. CYGNUS_PIN_DESC(12, "gpio0", 0, 0, 0),
  152. CYGNUS_PIN_DESC(13, "gpio1", 0, 0, 0),
  153. CYGNUS_PIN_DESC(14, "gpio2", 0, 0, 0),
  154. CYGNUS_PIN_DESC(15, "gpio3", 0, 0, 0),
  155. CYGNUS_PIN_DESC(16, "gpio4", 0, 0, 0),
  156. CYGNUS_PIN_DESC(17, "gpio5", 0, 0, 0),
  157. CYGNUS_PIN_DESC(18, "gpio6", 0, 0, 0),
  158. CYGNUS_PIN_DESC(19, "gpio7", 0, 0, 0),
  159. CYGNUS_PIN_DESC(20, "gpio8", 0, 0, 0),
  160. CYGNUS_PIN_DESC(21, "gpio9", 0, 0, 0),
  161. CYGNUS_PIN_DESC(22, "gpio10", 0, 0, 0),
  162. CYGNUS_PIN_DESC(23, "gpio11", 0, 0, 0),
  163. CYGNUS_PIN_DESC(24, "gpio12", 0, 0, 0),
  164. CYGNUS_PIN_DESC(25, "gpio13", 0, 0, 0),
  165. CYGNUS_PIN_DESC(26, "gpio14", 0, 0, 0),
  166. CYGNUS_PIN_DESC(27, "gpio15", 0, 0, 0),
  167. CYGNUS_PIN_DESC(28, "gpio16", 0, 0, 0),
  168. CYGNUS_PIN_DESC(29, "gpio17", 0, 0, 0),
  169. CYGNUS_PIN_DESC(30, "gpio18", 0, 0, 0),
  170. CYGNUS_PIN_DESC(31, "gpio19", 0, 0, 0),
  171. CYGNUS_PIN_DESC(32, "gpio20", 0, 0, 0),
  172. CYGNUS_PIN_DESC(33, "gpio21", 0, 0, 0),
  173. CYGNUS_PIN_DESC(34, "gpio22", 0, 0, 0),
  174. CYGNUS_PIN_DESC(35, "gpio23", 0, 0, 0),
  175. CYGNUS_PIN_DESC(36, "mdc", 0, 0, 0),
  176. CYGNUS_PIN_DESC(37, "mdio", 0, 0, 0),
  177. CYGNUS_PIN_DESC(38, "pwm0", 1, 0x10, 30),
  178. CYGNUS_PIN_DESC(39, "pwm1", 1, 0x10, 28),
  179. CYGNUS_PIN_DESC(40, "pwm2", 1, 0x10, 26),
  180. CYGNUS_PIN_DESC(41, "pwm3", 1, 0x10, 24),
  181. CYGNUS_PIN_DESC(42, "sc0_clk", 1, 0x10, 22),
  182. CYGNUS_PIN_DESC(43, "sc0_cmdvcc_l", 1, 0x10, 20),
  183. CYGNUS_PIN_DESC(44, "sc0_detect", 1, 0x10, 18),
  184. CYGNUS_PIN_DESC(45, "sc0_fcb", 1, 0x10, 16),
  185. CYGNUS_PIN_DESC(46, "sc0_io", 1, 0x10, 14),
  186. CYGNUS_PIN_DESC(47, "sc0_rst_l", 1, 0x10, 12),
  187. CYGNUS_PIN_DESC(48, "sc1_clk", 1, 0x10, 10),
  188. CYGNUS_PIN_DESC(49, "sc1_cmdvcc_l", 1, 0x10, 8),
  189. CYGNUS_PIN_DESC(50, "sc1_detect", 1, 0x10, 6),
  190. CYGNUS_PIN_DESC(51, "sc1_fcb", 1, 0x10, 4),
  191. CYGNUS_PIN_DESC(52, "sc1_io", 1, 0x10, 2),
  192. CYGNUS_PIN_DESC(53, "sc1_rst_l", 1, 0x10, 0),
  193. CYGNUS_PIN_DESC(54, "spi0_clk", 1, 0x18, 10),
  194. CYGNUS_PIN_DESC(55, "spi0_mosi", 1, 0x18, 6),
  195. CYGNUS_PIN_DESC(56, "spi0_miso", 1, 0x18, 8),
  196. CYGNUS_PIN_DESC(57, "spi0_ss", 1, 0x18, 4),
  197. CYGNUS_PIN_DESC(58, "spi1_clk", 1, 0x18, 2),
  198. CYGNUS_PIN_DESC(59, "spi1_mosi", 1, 0x1c, 30),
  199. CYGNUS_PIN_DESC(60, "spi1_miso", 1, 0x18, 0),
  200. CYGNUS_PIN_DESC(61, "spi1_ss", 1, 0x1c, 28),
  201. CYGNUS_PIN_DESC(62, "spi2_clk", 1, 0x1c, 26),
  202. CYGNUS_PIN_DESC(63, "spi2_mosi", 1, 0x1c, 22),
  203. CYGNUS_PIN_DESC(64, "spi2_miso", 1, 0x1c, 24),
  204. CYGNUS_PIN_DESC(65, "spi2_ss", 1, 0x1c, 20),
  205. CYGNUS_PIN_DESC(66, "spi3_clk", 1, 0x1c, 18),
  206. CYGNUS_PIN_DESC(67, "spi3_mosi", 1, 0x1c, 14),
  207. CYGNUS_PIN_DESC(68, "spi3_miso", 1, 0x1c, 16),
  208. CYGNUS_PIN_DESC(69, "spi3_ss", 1, 0x1c, 12),
  209. CYGNUS_PIN_DESC(70, "uart0_cts", 1, 0x1c, 10),
  210. CYGNUS_PIN_DESC(71, "uart0_rts", 1, 0x1c, 8),
  211. CYGNUS_PIN_DESC(72, "uart0_rx", 1, 0x1c, 6),
  212. CYGNUS_PIN_DESC(73, "uart0_tx", 1, 0x1c, 4),
  213. CYGNUS_PIN_DESC(74, "uart1_cts", 1, 0x1c, 2),
  214. CYGNUS_PIN_DESC(75, "uart1_dcd", 1, 0x1c, 0),
  215. CYGNUS_PIN_DESC(76, "uart1_dsr", 1, 0x20, 14),
  216. CYGNUS_PIN_DESC(77, "uart1_dtr", 1, 0x20, 12),
  217. CYGNUS_PIN_DESC(78, "uart1_ri", 1, 0x20, 10),
  218. CYGNUS_PIN_DESC(79, "uart1_rts", 1, 0x20, 8),
  219. CYGNUS_PIN_DESC(80, "uart1_rx", 1, 0x20, 6),
  220. CYGNUS_PIN_DESC(81, "uart1_tx", 1, 0x20, 4),
  221. CYGNUS_PIN_DESC(82, "uart3_rx", 1, 0x20, 2),
  222. CYGNUS_PIN_DESC(83, "uart3_tx", 1, 0x20, 0),
  223. CYGNUS_PIN_DESC(84, "sdio1_clk_sdcard", 1, 0x14, 6),
  224. CYGNUS_PIN_DESC(85, "sdio1_cmd", 1, 0x14, 4),
  225. CYGNUS_PIN_DESC(86, "sdio1_data0", 1, 0x14, 2),
  226. CYGNUS_PIN_DESC(87, "sdio1_data1", 1, 0x14, 0),
  227. CYGNUS_PIN_DESC(88, "sdio1_data2", 1, 0x18, 30),
  228. CYGNUS_PIN_DESC(89, "sdio1_data3", 1, 0x18, 28),
  229. CYGNUS_PIN_DESC(90, "sdio1_wp_n", 1, 0x18, 24),
  230. CYGNUS_PIN_DESC(91, "sdio1_card_rst", 1, 0x14, 10),
  231. CYGNUS_PIN_DESC(92, "sdio1_led_on", 1, 0x18, 26),
  232. CYGNUS_PIN_DESC(93, "sdio1_cd", 1, 0x14, 8),
  233. CYGNUS_PIN_DESC(94, "sdio0_clk_sdcard", 1, 0x14, 26),
  234. CYGNUS_PIN_DESC(95, "sdio0_cmd", 1, 0x14, 24),
  235. CYGNUS_PIN_DESC(96, "sdio0_data0", 1, 0x14, 22),
  236. CYGNUS_PIN_DESC(97, "sdio0_data1", 1, 0x14, 20),
  237. CYGNUS_PIN_DESC(98, "sdio0_data2", 1, 0x14, 18),
  238. CYGNUS_PIN_DESC(99, "sdio0_data3", 1, 0x14, 16),
  239. CYGNUS_PIN_DESC(100, "sdio0_wp_n", 1, 0x14, 12),
  240. CYGNUS_PIN_DESC(101, "sdio0_card_rst", 1, 0x14, 30),
  241. CYGNUS_PIN_DESC(102, "sdio0_led_on", 1, 0x14, 14),
  242. CYGNUS_PIN_DESC(103, "sdio0_cd", 1, 0x14, 28),
  243. CYGNUS_PIN_DESC(104, "sflash_clk", 1, 0x18, 22),
  244. CYGNUS_PIN_DESC(105, "sflash_cs_l", 1, 0x18, 20),
  245. CYGNUS_PIN_DESC(106, "sflash_mosi", 1, 0x18, 14),
  246. CYGNUS_PIN_DESC(107, "sflash_miso", 1, 0x18, 16),
  247. CYGNUS_PIN_DESC(108, "sflash_wp_n", 1, 0x18, 12),
  248. CYGNUS_PIN_DESC(109, "sflash_hold_n", 1, 0x18, 18),
  249. CYGNUS_PIN_DESC(110, "nand_ale", 1, 0xc, 30),
  250. CYGNUS_PIN_DESC(111, "nand_ce0_l", 1, 0xc, 28),
  251. CYGNUS_PIN_DESC(112, "nand_ce1_l", 1, 0xc, 26),
  252. CYGNUS_PIN_DESC(113, "nand_cle", 1, 0xc, 24),
  253. CYGNUS_PIN_DESC(114, "nand_dq0", 1, 0xc, 22),
  254. CYGNUS_PIN_DESC(115, "nand_dq1", 1, 0xc, 20),
  255. CYGNUS_PIN_DESC(116, "nand_dq2", 1, 0xc, 18),
  256. CYGNUS_PIN_DESC(117, "nand_dq3", 1, 0xc, 16),
  257. CYGNUS_PIN_DESC(118, "nand_dq4", 1, 0xc, 14),
  258. CYGNUS_PIN_DESC(119, "nand_dq5", 1, 0xc, 12),
  259. CYGNUS_PIN_DESC(120, "nand_dq6", 1, 0xc, 10),
  260. CYGNUS_PIN_DESC(121, "nand_dq7", 1, 0xc, 8),
  261. CYGNUS_PIN_DESC(122, "nand_rb_l", 1, 0xc, 6),
  262. CYGNUS_PIN_DESC(123, "nand_re_l", 1, 0xc, 4),
  263. CYGNUS_PIN_DESC(124, "nand_we_l", 1, 0xc, 2),
  264. CYGNUS_PIN_DESC(125, "nand_wp_l", 1, 0xc, 0),
  265. CYGNUS_PIN_DESC(126, "lcd_clac", 1, 0x4, 26),
  266. CYGNUS_PIN_DESC(127, "lcd_clcp", 1, 0x4, 24),
  267. CYGNUS_PIN_DESC(128, "lcd_cld0", 1, 0x4, 22),
  268. CYGNUS_PIN_DESC(129, "lcd_cld1", 1, 0x4, 0),
  269. CYGNUS_PIN_DESC(130, "lcd_cld10", 1, 0x4, 20),
  270. CYGNUS_PIN_DESC(131, "lcd_cld11", 1, 0x4, 18),
  271. CYGNUS_PIN_DESC(132, "lcd_cld12", 1, 0x4, 16),
  272. CYGNUS_PIN_DESC(133, "lcd_cld13", 1, 0x4, 14),
  273. CYGNUS_PIN_DESC(134, "lcd_cld14", 1, 0x4, 12),
  274. CYGNUS_PIN_DESC(135, "lcd_cld15", 1, 0x4, 10),
  275. CYGNUS_PIN_DESC(136, "lcd_cld16", 1, 0x4, 8),
  276. CYGNUS_PIN_DESC(137, "lcd_cld17", 1, 0x4, 6),
  277. CYGNUS_PIN_DESC(138, "lcd_cld18", 1, 0x4, 4),
  278. CYGNUS_PIN_DESC(139, "lcd_cld19", 1, 0x4, 2),
  279. CYGNUS_PIN_DESC(140, "lcd_cld2", 1, 0x8, 22),
  280. CYGNUS_PIN_DESC(141, "lcd_cld20", 1, 0x8, 30),
  281. CYGNUS_PIN_DESC(142, "lcd_cld21", 1, 0x8, 28),
  282. CYGNUS_PIN_DESC(143, "lcd_cld22", 1, 0x8, 26),
  283. CYGNUS_PIN_DESC(144, "lcd_cld23", 1, 0x8, 24),
  284. CYGNUS_PIN_DESC(145, "lcd_cld3", 1, 0x8, 20),
  285. CYGNUS_PIN_DESC(146, "lcd_cld4", 1, 0x8, 18),
  286. CYGNUS_PIN_DESC(147, "lcd_cld5", 1, 0x8, 16),
  287. CYGNUS_PIN_DESC(148, "lcd_cld6", 1, 0x8, 14),
  288. CYGNUS_PIN_DESC(149, "lcd_cld7", 1, 0x8, 12),
  289. CYGNUS_PIN_DESC(150, "lcd_cld8", 1, 0x8, 10),
  290. CYGNUS_PIN_DESC(151, "lcd_cld9", 1, 0x8, 8),
  291. CYGNUS_PIN_DESC(152, "lcd_clfp", 1, 0x8, 6),
  292. CYGNUS_PIN_DESC(153, "lcd_clle", 1, 0x8, 4),
  293. CYGNUS_PIN_DESC(154, "lcd_cllp", 1, 0x8, 2),
  294. CYGNUS_PIN_DESC(155, "lcd_clpower", 1, 0x8, 0),
  295. CYGNUS_PIN_DESC(156, "camera_vsync", 1, 0x4, 30),
  296. CYGNUS_PIN_DESC(157, "camera_trigger", 1, 0x0, 0),
  297. CYGNUS_PIN_DESC(158, "camera_strobe", 1, 0x0, 2),
  298. CYGNUS_PIN_DESC(159, "camera_standby", 1, 0x0, 4),
  299. CYGNUS_PIN_DESC(160, "camera_reset_n", 1, 0x0, 6),
  300. CYGNUS_PIN_DESC(161, "camera_pixdata9", 1, 0x0, 8),
  301. CYGNUS_PIN_DESC(162, "camera_pixdata8", 1, 0x0, 10),
  302. CYGNUS_PIN_DESC(163, "camera_pixdata7", 1, 0x0, 12),
  303. CYGNUS_PIN_DESC(164, "camera_pixdata6", 1, 0x0, 14),
  304. CYGNUS_PIN_DESC(165, "camera_pixdata5", 1, 0x0, 16),
  305. CYGNUS_PIN_DESC(166, "camera_pixdata4", 1, 0x0, 18),
  306. CYGNUS_PIN_DESC(167, "camera_pixdata3", 1, 0x0, 20),
  307. CYGNUS_PIN_DESC(168, "camera_pixdata2", 1, 0x0, 22),
  308. CYGNUS_PIN_DESC(169, "camera_pixdata1", 1, 0x0, 24),
  309. CYGNUS_PIN_DESC(170, "camera_pixdata0", 1, 0x0, 26),
  310. CYGNUS_PIN_DESC(171, "camera_pixclk", 1, 0x0, 28),
  311. CYGNUS_PIN_DESC(172, "camera_hsync", 1, 0x0, 30),
  312. CYGNUS_PIN_DESC(173, "camera_pll_ref_clk", 0, 0, 0),
  313. CYGNUS_PIN_DESC(174, "usb_id_indication", 0, 0, 0),
  314. CYGNUS_PIN_DESC(175, "usb_vbus_indication", 0, 0, 0),
  315. CYGNUS_PIN_DESC(176, "gpio0_3p3", 0, 0, 0),
  316. CYGNUS_PIN_DESC(177, "gpio1_3p3", 0, 0, 0),
  317. CYGNUS_PIN_DESC(178, "gpio2_3p3", 0, 0, 0),
  318. CYGNUS_PIN_DESC(179, "gpio3_3p3", 0, 0, 0),
  319. };
  320. /*
  321. * List of groups of pins
  322. */
  323. static const unsigned bsc1_pins[] = { 8, 9 };
  324. static const unsigned pcie_clkreq_pins[] = { 8, 9 };
  325. static const unsigned i2s2_0_pins[] = { 12 };
  326. static const unsigned i2s2_1_pins[] = { 13 };
  327. static const unsigned i2s2_2_pins[] = { 14 };
  328. static const unsigned i2s2_3_pins[] = { 15 };
  329. static const unsigned i2s2_4_pins[] = { 16 };
  330. static const unsigned pwm4_pins[] = { 17 };
  331. static const unsigned pwm5_pins[] = { 18 };
  332. static const unsigned key0_pins[] = { 20 };
  333. static const unsigned key1_pins[] = { 21 };
  334. static const unsigned key2_pins[] = { 22 };
  335. static const unsigned key3_pins[] = { 23 };
  336. static const unsigned key4_pins[] = { 24 };
  337. static const unsigned key5_pins[] = { 25 };
  338. static const unsigned key6_pins[] = { 26 };
  339. static const unsigned audio_dte0_pins[] = { 26 };
  340. static const unsigned key7_pins[] = { 27 };
  341. static const unsigned audio_dte1_pins[] = { 27 };
  342. static const unsigned key8_pins[] = { 28 };
  343. static const unsigned key9_pins[] = { 29 };
  344. static const unsigned key10_pins[] = { 30 };
  345. static const unsigned key11_pins[] = { 31 };
  346. static const unsigned key12_pins[] = { 32 };
  347. static const unsigned key13_pins[] = { 33 };
  348. static const unsigned key14_pins[] = { 34 };
  349. static const unsigned audio_dte2_pins[] = { 34 };
  350. static const unsigned key15_pins[] = { 35 };
  351. static const unsigned audio_dte3_pins[] = { 35 };
  352. static const unsigned pwm0_pins[] = { 38 };
  353. static const unsigned pwm1_pins[] = { 39 };
  354. static const unsigned pwm2_pins[] = { 40 };
  355. static const unsigned pwm3_pins[] = { 41 };
  356. static const unsigned sdio0_pins[] = { 94, 95, 96, 97, 98, 99 };
  357. static const unsigned smart_card0_pins[] = { 42, 43, 44, 46, 47 };
  358. static const unsigned i2s0_0_pins[] = { 42, 43, 44, 46 };
  359. static const unsigned spdif_pins[] = { 47 };
  360. static const unsigned smart_card1_pins[] = { 48, 49, 50, 52, 53 };
  361. static const unsigned i2s1_0_pins[] = { 48, 49, 50, 52 };
  362. static const unsigned spi0_pins[] = { 54, 55, 56, 57 };
  363. static const unsigned spi1_pins[] = { 58, 59, 60, 61 };
  364. static const unsigned spi2_pins[] = { 62, 63, 64, 65 };
  365. static const unsigned spi3_pins[] = { 66, 67, 68, 69 };
  366. static const unsigned sw_led0_0_pins[] = { 66, 67, 68, 69 };
  367. static const unsigned d1w_pins[] = { 10, 11 };
  368. static const unsigned uart4_pins[] = { 10, 11 };
  369. static const unsigned sw_led2_0_pins[] = { 10, 11 };
  370. static const unsigned lcd_pins[] = { 126, 127, 128, 129, 130, 131, 132, 133,
  371. 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147,
  372. 148, 149, 150, 151, 152, 153, 154, 155 };
  373. static const unsigned sram_0_pins[] = { 126, 127, 128, 129, 130, 131, 132, 133,
  374. 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147,
  375. 148, 149, 150, 151, 152, 153, 154, 155 };
  376. static const unsigned spi5_pins[] = { 141, 142, 143, 144 };
  377. static const unsigned uart0_pins[] = { 70, 71, 72, 73 };
  378. static const unsigned sw_led0_1_pins[] = { 70, 71, 72, 73 };
  379. static const unsigned uart1_dte_pins[] = { 75, 76, 77, 78 };
  380. static const unsigned uart2_pins[] = { 75, 76, 77, 78 };
  381. static const unsigned uart1_pins[] = { 74, 79, 80, 81 };
  382. static const unsigned uart3_pins[] = { 82, 83 };
  383. static const unsigned qspi_0_pins[] = { 104, 105, 106, 107 };
  384. static const unsigned nand_pins[] = { 110, 111, 112, 113, 114, 115, 116, 117,
  385. 118, 119, 120, 121, 122, 123, 124, 125 };
  386. static const unsigned sdio0_cd_pins[] = { 103 };
  387. static const unsigned sdio0_mmc_pins[] = { 100, 101, 102 };
  388. static const unsigned sdio1_data_0_pins[] = { 86, 87 };
  389. static const unsigned can0_pins[] = { 86, 87 };
  390. static const unsigned spi4_0_pins[] = { 86, 87 };
  391. static const unsigned sdio1_data_1_pins[] = { 88, 89 };
  392. static const unsigned can1_pins[] = { 88, 89 };
  393. static const unsigned spi4_1_pins[] = { 88, 89 };
  394. static const unsigned sdio1_cd_pins[] = { 93 };
  395. static const unsigned sdio1_led_pins[] = { 84, 85 };
  396. static const unsigned sw_led2_1_pins[] = { 84, 85 };
  397. static const unsigned sdio1_mmc_pins[] = { 90, 91, 92 };
  398. static const unsigned cam_led_pins[] = { 156, 157, 158, 159, 160 };
  399. static const unsigned sw_led1_pins[] = { 156, 157, 158, 159 };
  400. static const unsigned cam_0_pins[] = { 169, 170, 171, 169, 170 };
  401. static const unsigned cam_1_pins[] = { 161, 162, 163, 164, 165, 166, 167,
  402. 168 };
  403. static const unsigned sram_1_pins[] = { 161, 162, 163, 164, 165, 166, 167,
  404. 168 };
  405. static const unsigned qspi_1_pins[] = { 108, 109 };
  406. static const unsigned smart_card0_fcb_pins[] = { 45 };
  407. static const unsigned i2s0_1_pins[] = { 45 };
  408. static const unsigned smart_card1_fcb_pins[] = { 51 };
  409. static const unsigned i2s1_1_pins[] = { 51 };
  410. static const unsigned gpio0_3p3_pins[] = { 176 };
  411. static const unsigned usb0_oc_pins[] = { 176 };
  412. static const unsigned gpio1_3p3_pins[] = { 177 };
  413. static const unsigned usb1_oc_pins[] = { 177 };
  414. static const unsigned gpio2_3p3_pins[] = { 178 };
  415. static const unsigned usb2_oc_pins[] = { 178 };
  416. #define CYGNUS_PIN_GROUP(group_name, off, sh, al) \
  417. { \
  418. .name = __stringify(group_name) "_grp", \
  419. .pins = group_name ## _pins, \
  420. .num_pins = ARRAY_SIZE(group_name ## _pins), \
  421. .mux = { \
  422. .offset = off, \
  423. .shift = sh, \
  424. .alt = al, \
  425. } \
  426. }
  427. /*
  428. * List of Cygnus pin groups
  429. */
  430. static const struct cygnus_pin_group cygnus_pin_groups[] = {
  431. CYGNUS_PIN_GROUP(i2s2_0, 0x0, 0, 2),
  432. CYGNUS_PIN_GROUP(i2s2_1, 0x0, 4, 2),
  433. CYGNUS_PIN_GROUP(i2s2_2, 0x0, 8, 2),
  434. CYGNUS_PIN_GROUP(i2s2_3, 0x0, 12, 2),
  435. CYGNUS_PIN_GROUP(i2s2_4, 0x0, 16, 2),
  436. CYGNUS_PIN_GROUP(pwm4, 0x0, 20, 0),
  437. CYGNUS_PIN_GROUP(pwm5, 0x0, 24, 2),
  438. CYGNUS_PIN_GROUP(key0, 0x4, 0, 1),
  439. CYGNUS_PIN_GROUP(key1, 0x4, 4, 1),
  440. CYGNUS_PIN_GROUP(key2, 0x4, 8, 1),
  441. CYGNUS_PIN_GROUP(key3, 0x4, 12, 1),
  442. CYGNUS_PIN_GROUP(key4, 0x4, 16, 1),
  443. CYGNUS_PIN_GROUP(key5, 0x4, 20, 1),
  444. CYGNUS_PIN_GROUP(key6, 0x4, 24, 1),
  445. CYGNUS_PIN_GROUP(audio_dte0, 0x4, 24, 2),
  446. CYGNUS_PIN_GROUP(key7, 0x4, 28, 1),
  447. CYGNUS_PIN_GROUP(audio_dte1, 0x4, 28, 2),
  448. CYGNUS_PIN_GROUP(key8, 0x8, 0, 1),
  449. CYGNUS_PIN_GROUP(key9, 0x8, 4, 1),
  450. CYGNUS_PIN_GROUP(key10, 0x8, 8, 1),
  451. CYGNUS_PIN_GROUP(key11, 0x8, 12, 1),
  452. CYGNUS_PIN_GROUP(key12, 0x8, 16, 1),
  453. CYGNUS_PIN_GROUP(key13, 0x8, 20, 1),
  454. CYGNUS_PIN_GROUP(key14, 0x8, 24, 1),
  455. CYGNUS_PIN_GROUP(audio_dte2, 0x8, 24, 2),
  456. CYGNUS_PIN_GROUP(key15, 0x8, 28, 1),
  457. CYGNUS_PIN_GROUP(audio_dte3, 0x8, 28, 2),
  458. CYGNUS_PIN_GROUP(pwm0, 0xc, 0, 0),
  459. CYGNUS_PIN_GROUP(pwm1, 0xc, 4, 0),
  460. CYGNUS_PIN_GROUP(pwm2, 0xc, 8, 0),
  461. CYGNUS_PIN_GROUP(pwm3, 0xc, 12, 0),
  462. CYGNUS_PIN_GROUP(sdio0, 0xc, 16, 0),
  463. CYGNUS_PIN_GROUP(smart_card0, 0xc, 20, 0),
  464. CYGNUS_PIN_GROUP(i2s0_0, 0xc, 20, 1),
  465. CYGNUS_PIN_GROUP(spdif, 0xc, 20, 1),
  466. CYGNUS_PIN_GROUP(smart_card1, 0xc, 24, 0),
  467. CYGNUS_PIN_GROUP(i2s1_0, 0xc, 24, 1),
  468. CYGNUS_PIN_GROUP(spi0, 0x10, 0, 0),
  469. CYGNUS_PIN_GROUP(spi1, 0x10, 4, 0),
  470. CYGNUS_PIN_GROUP(spi2, 0x10, 8, 0),
  471. CYGNUS_PIN_GROUP(spi3, 0x10, 12, 0),
  472. CYGNUS_PIN_GROUP(sw_led0_0, 0x10, 12, 2),
  473. CYGNUS_PIN_GROUP(d1w, 0x10, 16, 0),
  474. CYGNUS_PIN_GROUP(uart4, 0x10, 16, 1),
  475. CYGNUS_PIN_GROUP(sw_led2_0, 0x10, 16, 2),
  476. CYGNUS_PIN_GROUP(lcd, 0x10, 20, 0),
  477. CYGNUS_PIN_GROUP(sram_0, 0x10, 20, 1),
  478. CYGNUS_PIN_GROUP(spi5, 0x10, 20, 2),
  479. CYGNUS_PIN_GROUP(uart0, 0x14, 0, 0),
  480. CYGNUS_PIN_GROUP(sw_led0_1, 0x14, 0, 2),
  481. CYGNUS_PIN_GROUP(uart1_dte, 0x14, 4, 0),
  482. CYGNUS_PIN_GROUP(uart2, 0x14, 4, 1),
  483. CYGNUS_PIN_GROUP(uart1, 0x14, 8, 0),
  484. CYGNUS_PIN_GROUP(uart3, 0x14, 12, 0),
  485. CYGNUS_PIN_GROUP(qspi_0, 0x14, 16, 0),
  486. CYGNUS_PIN_GROUP(nand, 0x14, 20, 0),
  487. CYGNUS_PIN_GROUP(sdio0_cd, 0x18, 0, 0),
  488. CYGNUS_PIN_GROUP(sdio0_mmc, 0x18, 4, 0),
  489. CYGNUS_PIN_GROUP(sdio1_data_0, 0x18, 8, 0),
  490. CYGNUS_PIN_GROUP(can0, 0x18, 8, 1),
  491. CYGNUS_PIN_GROUP(spi4_0, 0x18, 8, 2),
  492. CYGNUS_PIN_GROUP(sdio1_data_1, 0x18, 12, 0),
  493. CYGNUS_PIN_GROUP(can1, 0x18, 12, 1),
  494. CYGNUS_PIN_GROUP(spi4_1, 0x18, 12, 2),
  495. CYGNUS_PIN_GROUP(sdio1_cd, 0x18, 16, 0),
  496. CYGNUS_PIN_GROUP(sdio1_led, 0x18, 20, 0),
  497. CYGNUS_PIN_GROUP(sw_led2_1, 0x18, 20, 2),
  498. CYGNUS_PIN_GROUP(sdio1_mmc, 0x18, 24, 0),
  499. CYGNUS_PIN_GROUP(cam_led, 0x1c, 0, 0),
  500. CYGNUS_PIN_GROUP(sw_led1, 0x1c, 0, 1),
  501. CYGNUS_PIN_GROUP(cam_0, 0x1c, 4, 0),
  502. CYGNUS_PIN_GROUP(cam_1, 0x1c, 8, 0),
  503. CYGNUS_PIN_GROUP(sram_1, 0x1c, 8, 1),
  504. CYGNUS_PIN_GROUP(qspi_1, 0x1c, 12, 0),
  505. CYGNUS_PIN_GROUP(bsc1, 0x1c, 16, 0),
  506. CYGNUS_PIN_GROUP(pcie_clkreq, 0x1c, 16, 1),
  507. CYGNUS_PIN_GROUP(smart_card0_fcb, 0x20, 0, 0),
  508. CYGNUS_PIN_GROUP(i2s0_1, 0x20, 0, 1),
  509. CYGNUS_PIN_GROUP(smart_card1_fcb, 0x20, 4, 0),
  510. CYGNUS_PIN_GROUP(i2s1_1, 0x20, 4, 1),
  511. CYGNUS_PIN_GROUP(gpio0_3p3, 0x28, 0, 0),
  512. CYGNUS_PIN_GROUP(usb0_oc, 0x28, 0, 1),
  513. CYGNUS_PIN_GROUP(gpio1_3p3, 0x28, 4, 0),
  514. CYGNUS_PIN_GROUP(usb1_oc, 0x28, 4, 1),
  515. CYGNUS_PIN_GROUP(gpio2_3p3, 0x28, 8, 0),
  516. CYGNUS_PIN_GROUP(usb2_oc, 0x28, 8, 1),
  517. };
  518. /*
  519. * List of groups supported by functions
  520. */
  521. static const char * const i2s0_grps[] = { "i2s0_0_grp", "i2s0_1_grp" };
  522. static const char * const i2s1_grps[] = { "i2s1_0_grp", "i2s1_1_grp" };
  523. static const char * const i2s2_grps[] = { "i2s2_0_grp", "i2s2_1_grp",
  524. "i2s2_2_grp", "i2s2_3_grp", "i2s2_4_grp" };
  525. static const char * const spdif_grps[] = { "spdif_grp" };
  526. static const char * const pwm0_grps[] = { "pwm0_grp" };
  527. static const char * const pwm1_grps[] = { "pwm1_grp" };
  528. static const char * const pwm2_grps[] = { "pwm2_grp" };
  529. static const char * const pwm3_grps[] = { "pwm3_grp" };
  530. static const char * const pwm4_grps[] = { "pwm4_grp" };
  531. static const char * const pwm5_grps[] = { "pwm5_grp" };
  532. static const char * const key_grps[] = { "key0_grp", "key1_grp", "key2_grp",
  533. "key3_grp", "key4_grp", "key5_grp", "key6_grp", "key7_grp", "key8_grp",
  534. "key9_grp", "key10_grp", "key11_grp", "key12_grp", "key13_grp",
  535. "key14_grp", "key15_grp" };
  536. static const char * const audio_dte_grps[] = { "audio_dte0_grp",
  537. "audio_dte1_grp", "audio_dte2_grp", "audio_dte3_grp" };
  538. static const char * const smart_card0_grps[] = { "smart_card0_grp",
  539. "smart_card0_fcb_grp" };
  540. static const char * const smart_card1_grps[] = { "smart_card1_grp",
  541. "smart_card1_fcb_grp" };
  542. static const char * const spi0_grps[] = { "spi0_grp" };
  543. static const char * const spi1_grps[] = { "spi1_grp" };
  544. static const char * const spi2_grps[] = { "spi2_grp" };
  545. static const char * const spi3_grps[] = { "spi3_grp" };
  546. static const char * const spi4_grps[] = { "spi4_0_grp", "spi4_1_grp" };
  547. static const char * const spi5_grps[] = { "spi5_grp" };
  548. static const char * const sw_led0_grps[] = { "sw_led0_0_grp",
  549. "sw_led0_1_grp" };
  550. static const char * const sw_led1_grps[] = { "sw_led1_grp" };
  551. static const char * const sw_led2_grps[] = { "sw_led2_0_grp",
  552. "sw_led2_1_grp" };
  553. static const char * const d1w_grps[] = { "d1w_grp" };
  554. static const char * const lcd_grps[] = { "lcd_grp" };
  555. static const char * const sram_grps[] = { "sram_0_grp", "sram_1_grp" };
  556. static const char * const uart0_grps[] = { "uart0_grp" };
  557. static const char * const uart1_grps[] = { "uart1_grp", "uart1_dte_grp" };
  558. static const char * const uart2_grps[] = { "uart2_grp" };
  559. static const char * const uart3_grps[] = { "uart3_grp" };
  560. static const char * const uart4_grps[] = { "uart4_grp" };
  561. static const char * const qspi_grps[] = { "qspi_0_grp", "qspi_1_grp" };
  562. static const char * const nand_grps[] = { "nand_grp" };
  563. static const char * const sdio0_grps[] = { "sdio0_grp", "sdio0_cd_grp",
  564. "sdio0_mmc_grp" };
  565. static const char * const sdio1_grps[] = { "sdio1_data_0_grp",
  566. "sdio1_data_1_grp", "sdio1_cd_grp", "sdio1_led_grp", "sdio1_mmc_grp" };
  567. static const char * const can0_grps[] = { "can0_grp" };
  568. static const char * const can1_grps[] = { "can1_grp" };
  569. static const char * const cam_grps[] = { "cam_led_grp", "cam_0_grp",
  570. "cam_1_grp" };
  571. static const char * const bsc1_grps[] = { "bsc1_grp" };
  572. static const char * const pcie_clkreq_grps[] = { "pcie_clkreq_grp" };
  573. static const char * const usb0_oc_grps[] = { "usb0_oc_grp" };
  574. static const char * const usb1_oc_grps[] = { "usb1_oc_grp" };
  575. static const char * const usb2_oc_grps[] = { "usb2_oc_grp" };
  576. #define CYGNUS_PIN_FUNCTION(func) \
  577. { \
  578. .name = #func, \
  579. .groups = func ## _grps, \
  580. .num_groups = ARRAY_SIZE(func ## _grps), \
  581. }
  582. /*
  583. * List of supported functions in Cygnus
  584. */
  585. static const struct cygnus_pin_function cygnus_pin_functions[] = {
  586. CYGNUS_PIN_FUNCTION(i2s0),
  587. CYGNUS_PIN_FUNCTION(i2s1),
  588. CYGNUS_PIN_FUNCTION(i2s2),
  589. CYGNUS_PIN_FUNCTION(spdif),
  590. CYGNUS_PIN_FUNCTION(pwm0),
  591. CYGNUS_PIN_FUNCTION(pwm1),
  592. CYGNUS_PIN_FUNCTION(pwm2),
  593. CYGNUS_PIN_FUNCTION(pwm3),
  594. CYGNUS_PIN_FUNCTION(pwm4),
  595. CYGNUS_PIN_FUNCTION(pwm5),
  596. CYGNUS_PIN_FUNCTION(key),
  597. CYGNUS_PIN_FUNCTION(audio_dte),
  598. CYGNUS_PIN_FUNCTION(smart_card0),
  599. CYGNUS_PIN_FUNCTION(smart_card1),
  600. CYGNUS_PIN_FUNCTION(spi0),
  601. CYGNUS_PIN_FUNCTION(spi1),
  602. CYGNUS_PIN_FUNCTION(spi2),
  603. CYGNUS_PIN_FUNCTION(spi3),
  604. CYGNUS_PIN_FUNCTION(spi4),
  605. CYGNUS_PIN_FUNCTION(spi5),
  606. CYGNUS_PIN_FUNCTION(sw_led0),
  607. CYGNUS_PIN_FUNCTION(sw_led1),
  608. CYGNUS_PIN_FUNCTION(sw_led2),
  609. CYGNUS_PIN_FUNCTION(d1w),
  610. CYGNUS_PIN_FUNCTION(lcd),
  611. CYGNUS_PIN_FUNCTION(sram),
  612. CYGNUS_PIN_FUNCTION(uart0),
  613. CYGNUS_PIN_FUNCTION(uart1),
  614. CYGNUS_PIN_FUNCTION(uart2),
  615. CYGNUS_PIN_FUNCTION(uart3),
  616. CYGNUS_PIN_FUNCTION(uart4),
  617. CYGNUS_PIN_FUNCTION(qspi),
  618. CYGNUS_PIN_FUNCTION(nand),
  619. CYGNUS_PIN_FUNCTION(sdio0),
  620. CYGNUS_PIN_FUNCTION(sdio1),
  621. CYGNUS_PIN_FUNCTION(can0),
  622. CYGNUS_PIN_FUNCTION(can1),
  623. CYGNUS_PIN_FUNCTION(cam),
  624. CYGNUS_PIN_FUNCTION(bsc1),
  625. CYGNUS_PIN_FUNCTION(pcie_clkreq),
  626. CYGNUS_PIN_FUNCTION(usb0_oc),
  627. CYGNUS_PIN_FUNCTION(usb1_oc),
  628. CYGNUS_PIN_FUNCTION(usb2_oc),
  629. };
  630. static int cygnus_get_groups_count(struct pinctrl_dev *pctrl_dev)
  631. {
  632. struct cygnus_pinctrl *pinctrl = pinctrl_dev_get_drvdata(pctrl_dev);
  633. return pinctrl->num_groups;
  634. }
  635. static const char *cygnus_get_group_name(struct pinctrl_dev *pctrl_dev,
  636. unsigned selector)
  637. {
  638. struct cygnus_pinctrl *pinctrl = pinctrl_dev_get_drvdata(pctrl_dev);
  639. return pinctrl->groups[selector].name;
  640. }
  641. static int cygnus_get_group_pins(struct pinctrl_dev *pctrl_dev,
  642. unsigned selector, const unsigned **pins,
  643. unsigned *num_pins)
  644. {
  645. struct cygnus_pinctrl *pinctrl = pinctrl_dev_get_drvdata(pctrl_dev);
  646. *pins = pinctrl->groups[selector].pins;
  647. *num_pins = pinctrl->groups[selector].num_pins;
  648. return 0;
  649. }
  650. static void cygnus_pin_dbg_show(struct pinctrl_dev *pctrl_dev,
  651. struct seq_file *s, unsigned offset)
  652. {
  653. seq_printf(s, " %s", dev_name(pctrl_dev->dev));
  654. }
  655. static const struct pinctrl_ops cygnus_pinctrl_ops = {
  656. .get_groups_count = cygnus_get_groups_count,
  657. .get_group_name = cygnus_get_group_name,
  658. .get_group_pins = cygnus_get_group_pins,
  659. .pin_dbg_show = cygnus_pin_dbg_show,
  660. .dt_node_to_map = pinconf_generic_dt_node_to_map_group,
  661. .dt_free_map = pinctrl_utils_free_map,
  662. };
  663. static int cygnus_get_functions_count(struct pinctrl_dev *pctrl_dev)
  664. {
  665. struct cygnus_pinctrl *pinctrl = pinctrl_dev_get_drvdata(pctrl_dev);
  666. return pinctrl->num_functions;
  667. }
  668. static const char *cygnus_get_function_name(struct pinctrl_dev *pctrl_dev,
  669. unsigned selector)
  670. {
  671. struct cygnus_pinctrl *pinctrl = pinctrl_dev_get_drvdata(pctrl_dev);
  672. return pinctrl->functions[selector].name;
  673. }
  674. static int cygnus_get_function_groups(struct pinctrl_dev *pctrl_dev,
  675. unsigned selector,
  676. const char * const **groups,
  677. unsigned * const num_groups)
  678. {
  679. struct cygnus_pinctrl *pinctrl = pinctrl_dev_get_drvdata(pctrl_dev);
  680. *groups = pinctrl->functions[selector].groups;
  681. *num_groups = pinctrl->functions[selector].num_groups;
  682. return 0;
  683. }
  684. static int cygnus_pinmux_set(struct cygnus_pinctrl *pinctrl,
  685. const struct cygnus_pin_function *func,
  686. const struct cygnus_pin_group *grp,
  687. struct cygnus_mux_log *mux_log)
  688. {
  689. const struct cygnus_mux *mux = &grp->mux;
  690. int i;
  691. u32 val, mask = 0x7;
  692. unsigned long flags;
  693. for (i = 0; i < CYGNUS_NUM_IOMUX; i++) {
  694. if (mux->offset != mux_log[i].mux.offset ||
  695. mux->shift != mux_log[i].mux.shift)
  696. continue;
  697. /* match found if we reach here */
  698. /* if this is a new configuration, just do it! */
  699. if (!mux_log[i].is_configured)
  700. break;
  701. /*
  702. * IOMUX has been configured previously and one is trying to
  703. * configure it to a different function
  704. */
  705. if (mux_log[i].mux.alt != mux->alt) {
  706. dev_err(pinctrl->dev,
  707. "double configuration error detected!\n");
  708. dev_err(pinctrl->dev, "func:%s grp:%s\n",
  709. func->name, grp->name);
  710. return -EINVAL;
  711. } else {
  712. /*
  713. * One tries to configure it to the same function.
  714. * Just quit and don't bother
  715. */
  716. return 0;
  717. }
  718. }
  719. mux_log[i].mux.alt = mux->alt;
  720. mux_log[i].is_configured = true;
  721. spin_lock_irqsave(&pinctrl->lock, flags);
  722. val = readl(pinctrl->base0 + grp->mux.offset);
  723. val &= ~(mask << grp->mux.shift);
  724. val |= grp->mux.alt << grp->mux.shift;
  725. writel(val, pinctrl->base0 + grp->mux.offset);
  726. spin_unlock_irqrestore(&pinctrl->lock, flags);
  727. return 0;
  728. }
  729. static int cygnus_pinmux_set_mux(struct pinctrl_dev *pctrl_dev,
  730. unsigned func_select, unsigned grp_select)
  731. {
  732. struct cygnus_pinctrl *pinctrl = pinctrl_dev_get_drvdata(pctrl_dev);
  733. const struct cygnus_pin_function *func =
  734. &pinctrl->functions[func_select];
  735. const struct cygnus_pin_group *grp = &pinctrl->groups[grp_select];
  736. dev_dbg(pctrl_dev->dev, "func:%u name:%s grp:%u name:%s\n",
  737. func_select, func->name, grp_select, grp->name);
  738. dev_dbg(pctrl_dev->dev, "offset:0x%08x shift:%u alt:%u\n",
  739. grp->mux.offset, grp->mux.shift, grp->mux.alt);
  740. return cygnus_pinmux_set(pinctrl, func, grp, pinctrl->mux_log);
  741. }
  742. static int cygnus_gpio_request_enable(struct pinctrl_dev *pctrl_dev,
  743. struct pinctrl_gpio_range *range,
  744. unsigned pin)
  745. {
  746. struct cygnus_pinctrl *pinctrl = pinctrl_dev_get_drvdata(pctrl_dev);
  747. const struct cygnus_gpio_mux *mux = pctrl_dev->desc->pins[pin].drv_data;
  748. u32 val;
  749. unsigned long flags;
  750. /* not all pins support GPIO pinmux override */
  751. if (!mux->is_supported)
  752. return -ENOTSUPP;
  753. spin_lock_irqsave(&pinctrl->lock, flags);
  754. val = readl(pinctrl->base1 + mux->offset);
  755. val |= 0x3 << mux->shift;
  756. writel(val, pinctrl->base1 + mux->offset);
  757. spin_unlock_irqrestore(&pinctrl->lock, flags);
  758. dev_dbg(pctrl_dev->dev,
  759. "gpio request enable pin=%u offset=0x%x shift=%u\n",
  760. pin, mux->offset, mux->shift);
  761. return 0;
  762. }
  763. static void cygnus_gpio_disable_free(struct pinctrl_dev *pctrl_dev,
  764. struct pinctrl_gpio_range *range,
  765. unsigned pin)
  766. {
  767. struct cygnus_pinctrl *pinctrl = pinctrl_dev_get_drvdata(pctrl_dev);
  768. struct cygnus_gpio_mux *mux = pctrl_dev->desc->pins[pin].drv_data;
  769. u32 val;
  770. unsigned long flags;
  771. if (!mux->is_supported)
  772. return;
  773. spin_lock_irqsave(&pinctrl->lock, flags);
  774. val = readl(pinctrl->base1 + mux->offset);
  775. val &= ~(0x3 << mux->shift);
  776. writel(val, pinctrl->base1 + mux->offset);
  777. spin_unlock_irqrestore(&pinctrl->lock, flags);
  778. dev_err(pctrl_dev->dev,
  779. "gpio disable free pin=%u offset=0x%x shift=%u\n",
  780. pin, mux->offset, mux->shift);
  781. }
  782. static const struct pinmux_ops cygnus_pinmux_ops = {
  783. .get_functions_count = cygnus_get_functions_count,
  784. .get_function_name = cygnus_get_function_name,
  785. .get_function_groups = cygnus_get_function_groups,
  786. .set_mux = cygnus_pinmux_set_mux,
  787. .gpio_request_enable = cygnus_gpio_request_enable,
  788. .gpio_disable_free = cygnus_gpio_disable_free,
  789. };
  790. static struct pinctrl_desc cygnus_pinctrl_desc = {
  791. .name = "cygnus-pinmux",
  792. .pctlops = &cygnus_pinctrl_ops,
  793. .pmxops = &cygnus_pinmux_ops,
  794. };
  795. static int cygnus_mux_log_init(struct cygnus_pinctrl *pinctrl)
  796. {
  797. struct cygnus_mux_log *log;
  798. unsigned int i, j;
  799. pinctrl->mux_log = devm_kcalloc(pinctrl->dev, CYGNUS_NUM_IOMUX,
  800. sizeof(struct cygnus_mux_log),
  801. GFP_KERNEL);
  802. if (!pinctrl->mux_log)
  803. return -ENOMEM;
  804. for (i = 0; i < CYGNUS_NUM_IOMUX_REGS; i++) {
  805. for (j = 0; j < CYGNUS_NUM_MUX_PER_REG; j++) {
  806. log = &pinctrl->mux_log[i * CYGNUS_NUM_MUX_PER_REG
  807. + j];
  808. log->mux.offset = i * 4;
  809. log->mux.shift = j * 4;
  810. log->mux.alt = 0;
  811. log->is_configured = false;
  812. }
  813. }
  814. return 0;
  815. }
  816. static int cygnus_pinmux_probe(struct platform_device *pdev)
  817. {
  818. struct cygnus_pinctrl *pinctrl;
  819. int i, ret;
  820. struct pinctrl_pin_desc *pins;
  821. unsigned num_pins = ARRAY_SIZE(cygnus_pins);
  822. pinctrl = devm_kzalloc(&pdev->dev, sizeof(*pinctrl), GFP_KERNEL);
  823. if (!pinctrl)
  824. return -ENOMEM;
  825. pinctrl->dev = &pdev->dev;
  826. platform_set_drvdata(pdev, pinctrl);
  827. spin_lock_init(&pinctrl->lock);
  828. pinctrl->base0 = devm_platform_ioremap_resource(pdev, 0);
  829. if (IS_ERR(pinctrl->base0)) {
  830. dev_err(&pdev->dev, "unable to map I/O space\n");
  831. return PTR_ERR(pinctrl->base0);
  832. }
  833. pinctrl->base1 = devm_platform_ioremap_resource(pdev, 1);
  834. if (IS_ERR(pinctrl->base1)) {
  835. dev_err(&pdev->dev, "unable to map I/O space\n");
  836. return PTR_ERR(pinctrl->base1);
  837. }
  838. ret = cygnus_mux_log_init(pinctrl);
  839. if (ret) {
  840. dev_err(&pdev->dev, "unable to initialize IOMUX log\n");
  841. return ret;
  842. }
  843. pins = devm_kcalloc(&pdev->dev, num_pins, sizeof(*pins), GFP_KERNEL);
  844. if (!pins)
  845. return -ENOMEM;
  846. for (i = 0; i < num_pins; i++) {
  847. pins[i].number = cygnus_pins[i].pin;
  848. pins[i].name = cygnus_pins[i].name;
  849. pins[i].drv_data = &cygnus_pins[i].gpio_mux;
  850. }
  851. pinctrl->groups = cygnus_pin_groups;
  852. pinctrl->num_groups = ARRAY_SIZE(cygnus_pin_groups);
  853. pinctrl->functions = cygnus_pin_functions;
  854. pinctrl->num_functions = ARRAY_SIZE(cygnus_pin_functions);
  855. cygnus_pinctrl_desc.pins = pins;
  856. cygnus_pinctrl_desc.npins = num_pins;
  857. pinctrl->pctl = devm_pinctrl_register(&pdev->dev, &cygnus_pinctrl_desc,
  858. pinctrl);
  859. if (IS_ERR(pinctrl->pctl)) {
  860. dev_err(&pdev->dev, "unable to register Cygnus IOMUX pinctrl\n");
  861. return PTR_ERR(pinctrl->pctl);
  862. }
  863. return 0;
  864. }
  865. static const struct of_device_id cygnus_pinmux_of_match[] = {
  866. { .compatible = "brcm,cygnus-pinmux" },
  867. { }
  868. };
  869. static struct platform_driver cygnus_pinmux_driver = {
  870. .driver = {
  871. .name = "cygnus-pinmux",
  872. .of_match_table = cygnus_pinmux_of_match,
  873. .suppress_bind_attrs = true,
  874. },
  875. .probe = cygnus_pinmux_probe,
  876. };
  877. static int __init cygnus_pinmux_init(void)
  878. {
  879. return platform_driver_register(&cygnus_pinmux_driver);
  880. }
  881. arch_initcall(cygnus_pinmux_init);