pinctrl-cygnus-mux.c 34 KB

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