pinctrl-ns2-mux.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114
  1. /* Copyright (C) 2016 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 Northstar2 IOMUX driver that supports group
  13. * based PINMUX configuration. The PWM is functional only when the
  14. * corresponding mfio pin group is selected as gpio.
  15. */
  16. #include <linux/err.h>
  17. #include <linux/io.h>
  18. #include <linux/of.h>
  19. #include <linux/pinctrl/pinconf.h>
  20. #include <linux/pinctrl/pinconf-generic.h>
  21. #include <linux/pinctrl/pinctrl.h>
  22. #include <linux/pinctrl/pinmux.h>
  23. #include <linux/platform_device.h>
  24. #include <linux/slab.h>
  25. #include "../core.h"
  26. #include "../pinctrl-utils.h"
  27. #define NS2_NUM_IOMUX 19
  28. #define NS2_NUM_PWM_MUX 4
  29. #define NS2_PIN_MUX_BASE0 0x00
  30. #define NS2_PIN_MUX_BASE1 0x01
  31. #define NS2_PIN_CONF_BASE 0x02
  32. #define NS2_MUX_PAD_FUNC1_OFFSET 0x04
  33. #define NS2_PIN_SRC_MASK 0x01
  34. #define NS2_PIN_PULL_MASK 0x03
  35. #define NS2_PIN_DRIVE_STRENGTH_MASK 0x07
  36. #define NS2_PIN_PULL_UP 0x01
  37. #define NS2_PIN_PULL_DOWN 0x02
  38. #define NS2_PIN_INPUT_EN_MASK 0x01
  39. /*
  40. * Northstar2 IOMUX register description
  41. *
  42. * @base: base address number
  43. * @offset: register offset for mux configuration of a group
  44. * @shift: bit shift for mux configuration of a group
  45. * @mask: mask bits
  46. * @alt: alternate function to set to
  47. */
  48. struct ns2_mux {
  49. unsigned int base;
  50. unsigned int offset;
  51. unsigned int shift;
  52. unsigned int mask;
  53. unsigned int alt;
  54. };
  55. /*
  56. * Keep track of Northstar2 IOMUX configuration and prevent double
  57. * configuration
  58. *
  59. * @ns2_mux: Northstar2 IOMUX register description
  60. * @is_configured: flag to indicate whether a mux setting has already
  61. * been configured
  62. */
  63. struct ns2_mux_log {
  64. struct ns2_mux mux;
  65. bool is_configured;
  66. };
  67. /*
  68. * Group based IOMUX configuration
  69. *
  70. * @name: name of the group
  71. * @pins: array of pins used by this group
  72. * @num_pins: total number of pins used by this group
  73. * @mux: Northstar2 group based IOMUX configuration
  74. */
  75. struct ns2_pin_group {
  76. const char *name;
  77. const unsigned int *pins;
  78. const unsigned int num_pins;
  79. const struct ns2_mux mux;
  80. };
  81. /*
  82. * Northstar2 mux function and supported pin groups
  83. *
  84. * @name: name of the function
  85. * @groups: array of groups that can be supported by this function
  86. * @num_groups: total number of groups that can be supported by function
  87. */
  88. struct ns2_pin_function {
  89. const char *name;
  90. const char * const *groups;
  91. const unsigned int num_groups;
  92. };
  93. /*
  94. * Northstar2 IOMUX pinctrl core
  95. *
  96. * @pctl: pointer to pinctrl_dev
  97. * @dev: pointer to device
  98. * @base0: first IOMUX register base
  99. * @base1: second IOMUX register base
  100. * @pinconf_base: configuration register base
  101. * @groups: pointer to array of groups
  102. * @num_groups: total number of groups
  103. * @functions: pointer to array of functions
  104. * @num_functions: total number of functions
  105. * @mux_log: pointer to the array of mux logs
  106. * @lock: lock to protect register access
  107. */
  108. struct ns2_pinctrl {
  109. struct pinctrl_dev *pctl;
  110. struct device *dev;
  111. void __iomem *base0;
  112. void __iomem *base1;
  113. void __iomem *pinconf_base;
  114. const struct ns2_pin_group *groups;
  115. unsigned int num_groups;
  116. const struct ns2_pin_function *functions;
  117. unsigned int num_functions;
  118. struct ns2_mux_log *mux_log;
  119. spinlock_t lock;
  120. };
  121. /*
  122. * Pin configuration info
  123. *
  124. * @base: base address number
  125. * @offset: register offset from base
  126. * @src_shift: slew rate control bit shift in the register
  127. * @input_en: input enable control bit shift
  128. * @pull_shift: pull-up/pull-down control bit shift in the register
  129. * @drive_shift: drive strength control bit shift in the register
  130. */
  131. struct ns2_pinconf {
  132. unsigned int base;
  133. unsigned int offset;
  134. unsigned int src_shift;
  135. unsigned int input_en;
  136. unsigned int pull_shift;
  137. unsigned int drive_shift;
  138. };
  139. /*
  140. * Description of a pin in Northstar2
  141. *
  142. * @pin: pin number
  143. * @name: pin name
  144. * @pin_conf: pin configuration structure
  145. */
  146. struct ns2_pin {
  147. unsigned int pin;
  148. char *name;
  149. struct ns2_pinconf pin_conf;
  150. };
  151. #define NS2_PIN_DESC(p, n, b, o, s, i, pu, d) \
  152. { \
  153. .pin = p, \
  154. .name = n, \
  155. .pin_conf = { \
  156. .base = b, \
  157. .offset = o, \
  158. .src_shift = s, \
  159. .input_en = i, \
  160. .pull_shift = pu, \
  161. .drive_shift = d, \
  162. } \
  163. }
  164. /*
  165. * List of pins in Northstar2
  166. */
  167. static struct ns2_pin ns2_pins[] = {
  168. NS2_PIN_DESC(0, "mfio_0", -1, 0, 0, 0, 0, 0),
  169. NS2_PIN_DESC(1, "mfio_1", -1, 0, 0, 0, 0, 0),
  170. NS2_PIN_DESC(2, "mfio_2", -1, 0, 0, 0, 0, 0),
  171. NS2_PIN_DESC(3, "mfio_3", -1, 0, 0, 0, 0, 0),
  172. NS2_PIN_DESC(4, "mfio_4", -1, 0, 0, 0, 0, 0),
  173. NS2_PIN_DESC(5, "mfio_5", -1, 0, 0, 0, 0, 0),
  174. NS2_PIN_DESC(6, "mfio_6", -1, 0, 0, 0, 0, 0),
  175. NS2_PIN_DESC(7, "mfio_7", -1, 0, 0, 0, 0, 0),
  176. NS2_PIN_DESC(8, "mfio_8", -1, 0, 0, 0, 0, 0),
  177. NS2_PIN_DESC(9, "mfio_9", -1, 0, 0, 0, 0, 0),
  178. NS2_PIN_DESC(10, "mfio_10", -1, 0, 0, 0, 0, 0),
  179. NS2_PIN_DESC(11, "mfio_11", -1, 0, 0, 0, 0, 0),
  180. NS2_PIN_DESC(12, "mfio_12", -1, 0, 0, 0, 0, 0),
  181. NS2_PIN_DESC(13, "mfio_13", -1, 0, 0, 0, 0, 0),
  182. NS2_PIN_DESC(14, "mfio_14", -1, 0, 0, 0, 0, 0),
  183. NS2_PIN_DESC(15, "mfio_15", -1, 0, 0, 0, 0, 0),
  184. NS2_PIN_DESC(16, "mfio_16", -1, 0, 0, 0, 0, 0),
  185. NS2_PIN_DESC(17, "mfio_17", -1, 0, 0, 0, 0, 0),
  186. NS2_PIN_DESC(18, "mfio_18", -1, 0, 0, 0, 0, 0),
  187. NS2_PIN_DESC(19, "mfio_19", -1, 0, 0, 0, 0, 0),
  188. NS2_PIN_DESC(20, "mfio_20", -1, 0, 0, 0, 0, 0),
  189. NS2_PIN_DESC(21, "mfio_21", -1, 0, 0, 0, 0, 0),
  190. NS2_PIN_DESC(22, "mfio_22", -1, 0, 0, 0, 0, 0),
  191. NS2_PIN_DESC(23, "mfio_23", -1, 0, 0, 0, 0, 0),
  192. NS2_PIN_DESC(24, "mfio_24", -1, 0, 0, 0, 0, 0),
  193. NS2_PIN_DESC(25, "mfio_25", -1, 0, 0, 0, 0, 0),
  194. NS2_PIN_DESC(26, "mfio_26", -1, 0, 0, 0, 0, 0),
  195. NS2_PIN_DESC(27, "mfio_27", -1, 0, 0, 0, 0, 0),
  196. NS2_PIN_DESC(28, "mfio_28", -1, 0, 0, 0, 0, 0),
  197. NS2_PIN_DESC(29, "mfio_29", -1, 0, 0, 0, 0, 0),
  198. NS2_PIN_DESC(30, "mfio_30", -1, 0, 0, 0, 0, 0),
  199. NS2_PIN_DESC(31, "mfio_31", -1, 0, 0, 0, 0, 0),
  200. NS2_PIN_DESC(32, "mfio_32", -1, 0, 0, 0, 0, 0),
  201. NS2_PIN_DESC(33, "mfio_33", -1, 0, 0, 0, 0, 0),
  202. NS2_PIN_DESC(34, "mfio_34", -1, 0, 0, 0, 0, 0),
  203. NS2_PIN_DESC(35, "mfio_35", -1, 0, 0, 0, 0, 0),
  204. NS2_PIN_DESC(36, "mfio_36", -1, 0, 0, 0, 0, 0),
  205. NS2_PIN_DESC(37, "mfio_37", -1, 0, 0, 0, 0, 0),
  206. NS2_PIN_DESC(38, "mfio_38", -1, 0, 0, 0, 0, 0),
  207. NS2_PIN_DESC(39, "mfio_39", -1, 0, 0, 0, 0, 0),
  208. NS2_PIN_DESC(40, "mfio_40", -1, 0, 0, 0, 0, 0),
  209. NS2_PIN_DESC(41, "mfio_41", -1, 0, 0, 0, 0, 0),
  210. NS2_PIN_DESC(42, "mfio_42", -1, 0, 0, 0, 0, 0),
  211. NS2_PIN_DESC(43, "mfio_43", -1, 0, 0, 0, 0, 0),
  212. NS2_PIN_DESC(44, "mfio_44", -1, 0, 0, 0, 0, 0),
  213. NS2_PIN_DESC(45, "mfio_45", -1, 0, 0, 0, 0, 0),
  214. NS2_PIN_DESC(46, "mfio_46", -1, 0, 0, 0, 0, 0),
  215. NS2_PIN_DESC(47, "mfio_47", -1, 0, 0, 0, 0, 0),
  216. NS2_PIN_DESC(48, "mfio_48", -1, 0, 0, 0, 0, 0),
  217. NS2_PIN_DESC(49, "mfio_49", -1, 0, 0, 0, 0, 0),
  218. NS2_PIN_DESC(50, "mfio_50", -1, 0, 0, 0, 0, 0),
  219. NS2_PIN_DESC(51, "mfio_51", -1, 0, 0, 0, 0, 0),
  220. NS2_PIN_DESC(52, "mfio_52", -1, 0, 0, 0, 0, 0),
  221. NS2_PIN_DESC(53, "mfio_53", -1, 0, 0, 0, 0, 0),
  222. NS2_PIN_DESC(54, "mfio_54", -1, 0, 0, 0, 0, 0),
  223. NS2_PIN_DESC(55, "mfio_55", -1, 0, 0, 0, 0, 0),
  224. NS2_PIN_DESC(56, "mfio_56", -1, 0, 0, 0, 0, 0),
  225. NS2_PIN_DESC(57, "mfio_57", -1, 0, 0, 0, 0, 0),
  226. NS2_PIN_DESC(58, "mfio_58", -1, 0, 0, 0, 0, 0),
  227. NS2_PIN_DESC(59, "mfio_59", -1, 0, 0, 0, 0, 0),
  228. NS2_PIN_DESC(60, "mfio_60", -1, 0, 0, 0, 0, 0),
  229. NS2_PIN_DESC(61, "mfio_61", -1, 0, 0, 0, 0, 0),
  230. NS2_PIN_DESC(62, "mfio_62", -1, 0, 0, 0, 0, 0),
  231. NS2_PIN_DESC(63, "qspi_wp", 2, 0x0, 31, 30, 27, 24),
  232. NS2_PIN_DESC(64, "qspi_hold", 2, 0x0, 23, 22, 19, 16),
  233. NS2_PIN_DESC(65, "qspi_cs", 2, 0x0, 15, 14, 11, 8),
  234. NS2_PIN_DESC(66, "qspi_sck", 2, 0x0, 7, 6, 3, 0),
  235. NS2_PIN_DESC(67, "uart3_sin", 2, 0x04, 31, 30, 27, 24),
  236. NS2_PIN_DESC(68, "uart3_sout", 2, 0x04, 23, 22, 19, 16),
  237. NS2_PIN_DESC(69, "qspi_mosi", 2, 0x04, 15, 14, 11, 8),
  238. NS2_PIN_DESC(70, "qspi_miso", 2, 0x04, 7, 6, 3, 0),
  239. NS2_PIN_DESC(71, "spi0_fss", 2, 0x08, 31, 30, 27, 24),
  240. NS2_PIN_DESC(72, "spi0_rxd", 2, 0x08, 23, 22, 19, 16),
  241. NS2_PIN_DESC(73, "spi0_txd", 2, 0x08, 15, 14, 11, 8),
  242. NS2_PIN_DESC(74, "spi0_sck", 2, 0x08, 7, 6, 3, 0),
  243. NS2_PIN_DESC(75, "spi1_fss", 2, 0x0c, 31, 30, 27, 24),
  244. NS2_PIN_DESC(76, "spi1_rxd", 2, 0x0c, 23, 22, 19, 16),
  245. NS2_PIN_DESC(77, "spi1_txd", 2, 0x0c, 15, 14, 11, 8),
  246. NS2_PIN_DESC(78, "spi1_sck", 2, 0x0c, 7, 6, 3, 0),
  247. NS2_PIN_DESC(79, "sdio0_data7", 2, 0x10, 31, 30, 27, 24),
  248. NS2_PIN_DESC(80, "sdio0_emmc_rst", 2, 0x10, 23, 22, 19, 16),
  249. NS2_PIN_DESC(81, "sdio0_led_on", 2, 0x10, 15, 14, 11, 8),
  250. NS2_PIN_DESC(82, "sdio0_wp", 2, 0x10, 7, 6, 3, 0),
  251. NS2_PIN_DESC(83, "sdio0_data3", 2, 0x14, 31, 30, 27, 24),
  252. NS2_PIN_DESC(84, "sdio0_data4", 2, 0x14, 23, 22, 19, 16),
  253. NS2_PIN_DESC(85, "sdio0_data5", 2, 0x14, 15, 14, 11, 8),
  254. NS2_PIN_DESC(86, "sdio0_data6", 2, 0x14, 7, 6, 3, 0),
  255. NS2_PIN_DESC(87, "sdio0_cmd", 2, 0x18, 31, 30, 27, 24),
  256. NS2_PIN_DESC(88, "sdio0_data0", 2, 0x18, 23, 22, 19, 16),
  257. NS2_PIN_DESC(89, "sdio0_data1", 2, 0x18, 15, 14, 11, 8),
  258. NS2_PIN_DESC(90, "sdio0_data2", 2, 0x18, 7, 6, 3, 0),
  259. NS2_PIN_DESC(91, "sdio1_led_on", 2, 0x1c, 31, 30, 27, 24),
  260. NS2_PIN_DESC(92, "sdio1_wp", 2, 0x1c, 23, 22, 19, 16),
  261. NS2_PIN_DESC(93, "sdio0_cd_l", 2, 0x1c, 15, 14, 11, 8),
  262. NS2_PIN_DESC(94, "sdio0_clk", 2, 0x1c, 7, 6, 3, 0),
  263. NS2_PIN_DESC(95, "sdio1_data5", 2, 0x20, 31, 30, 27, 24),
  264. NS2_PIN_DESC(96, "sdio1_data6", 2, 0x20, 23, 22, 19, 16),
  265. NS2_PIN_DESC(97, "sdio1_data7", 2, 0x20, 15, 14, 11, 8),
  266. NS2_PIN_DESC(98, "sdio1_emmc_rst", 2, 0x20, 7, 6, 3, 0),
  267. NS2_PIN_DESC(99, "sdio1_data1", 2, 0x24, 31, 30, 27, 24),
  268. NS2_PIN_DESC(100, "sdio1_data2", 2, 0x24, 23, 22, 19, 16),
  269. NS2_PIN_DESC(101, "sdio1_data3", 2, 0x24, 15, 14, 11, 8),
  270. NS2_PIN_DESC(102, "sdio1_data4", 2, 0x24, 7, 6, 3, 0),
  271. NS2_PIN_DESC(103, "sdio1_cd_l", 2, 0x28, 31, 30, 27, 24),
  272. NS2_PIN_DESC(104, "sdio1_clk", 2, 0x28, 23, 22, 19, 16),
  273. NS2_PIN_DESC(105, "sdio1_cmd", 2, 0x28, 15, 14, 11, 8),
  274. NS2_PIN_DESC(106, "sdio1_data0", 2, 0x28, 7, 6, 3, 0),
  275. NS2_PIN_DESC(107, "ext_mdio_0", 2, 0x2c, 15, 14, 11, 8),
  276. NS2_PIN_DESC(108, "ext_mdc_0", 2, 0x2c, 7, 6, 3, 0),
  277. NS2_PIN_DESC(109, "usb3_p1_vbus_ppc", 2, 0x34, 31, 30, 27, 24),
  278. NS2_PIN_DESC(110, "usb3_p1_overcurrent", 2, 0x34, 23, 22, 19, 16),
  279. NS2_PIN_DESC(111, "usb3_p0_vbus_ppc", 2, 0x34, 15, 14, 11, 8),
  280. NS2_PIN_DESC(112, "usb3_p0_overcurrent", 2, 0x34, 7, 6, 3, 0),
  281. NS2_PIN_DESC(113, "usb2_presence_indication", 2, 0x38, 31, 30, 27, 24),
  282. NS2_PIN_DESC(114, "usb2_vbus_present", 2, 0x38, 23, 22, 19, 16),
  283. NS2_PIN_DESC(115, "usb2_vbus_ppc", 2, 0x38, 15, 14, 11, 8),
  284. NS2_PIN_DESC(116, "usb2_overcurrent", 2, 0x38, 7, 6, 3, 0),
  285. NS2_PIN_DESC(117, "sata_led1", 2, 0x3c, 15, 14, 11, 8),
  286. NS2_PIN_DESC(118, "sata_led0", 2, 0x3c, 7, 6, 3, 0),
  287. };
  288. /*
  289. * List of groups of pins
  290. */
  291. static const unsigned int nand_pins[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
  292. 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23};
  293. static const unsigned int nor_data_pins[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
  294. 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25};
  295. static const unsigned int gpio_0_1_pins[] = {24, 25};
  296. static const unsigned int pwm_0_pins[] = {24};
  297. static const unsigned int pwm_1_pins[] = {25};
  298. static const unsigned int uart1_ext_clk_pins[] = {26};
  299. static const unsigned int nor_adv_pins[] = {26};
  300. static const unsigned int gpio_2_5_pins[] = {27, 28, 29, 30};
  301. static const unsigned int pcie_ab1_clk_wak_pins[] = {27, 28, 29, 30};
  302. static const unsigned int nor_addr_0_3_pins[] = {27, 28, 29, 30};
  303. static const unsigned int pwm_2_pins[] = {27};
  304. static const unsigned int pwm_3_pins[] = {28};
  305. static const unsigned int gpio_6_7_pins[] = {31, 32};
  306. static const unsigned int pcie_a3_clk_wak_pins[] = {31, 32};
  307. static const unsigned int nor_addr_4_5_pins[] = {31, 32};
  308. static const unsigned int gpio_8_9_pins[] = {33, 34};
  309. static const unsigned int pcie_b3_clk_wak_pins[] = {33, 34};
  310. static const unsigned int nor_addr_6_7_pins[] = {33, 34};
  311. static const unsigned int gpio_10_11_pins[] = {35, 36};
  312. static const unsigned int pcie_b2_clk_wak_pins[] = {35, 36};
  313. static const unsigned int nor_addr_8_9_pins[] = {35, 36};
  314. static const unsigned int gpio_12_13_pins[] = {37, 38};
  315. static const unsigned int pcie_a2_clk_wak_pins[] = {37, 38};
  316. static const unsigned int nor_addr_10_11_pins[] = {37, 38};
  317. static const unsigned int gpio_14_17_pins[] = {39, 40, 41, 42};
  318. static const unsigned int uart0_modem_pins[] = {39, 40, 41, 42};
  319. static const unsigned int nor_addr_12_15_pins[] = {39, 40, 41, 42};
  320. static const unsigned int gpio_18_19_pins[] = {43, 44};
  321. static const unsigned int uart0_rts_cts_pins[] = {43, 44};
  322. static const unsigned int gpio_20_21_pins[] = {45, 46};
  323. static const unsigned int uart0_in_out_pins[] = {45, 46};
  324. static const unsigned int gpio_22_23_pins[] = {47, 48};
  325. static const unsigned int uart1_dcd_dsr_pins[] = {47, 48};
  326. static const unsigned int gpio_24_25_pins[] = {49, 50};
  327. static const unsigned int uart1_ri_dtr_pins[] = {49, 50};
  328. static const unsigned int gpio_26_27_pins[] = {51, 52};
  329. static const unsigned int uart1_rts_cts_pins[] = {51, 52};
  330. static const unsigned int gpio_28_29_pins[] = {53, 54};
  331. static const unsigned int uart1_in_out_pins[] = {53, 54};
  332. static const unsigned int gpio_30_31_pins[] = {55, 56};
  333. static const unsigned int uart2_rts_cts_pins[] = {55, 56};
  334. #define NS2_PIN_GROUP(group_name, ba, off, sh, ma, al) \
  335. { \
  336. .name = __stringify(group_name) "_grp", \
  337. .pins = group_name ## _pins, \
  338. .num_pins = ARRAY_SIZE(group_name ## _pins), \
  339. .mux = { \
  340. .base = ba, \
  341. .offset = off, \
  342. .shift = sh, \
  343. .mask = ma, \
  344. .alt = al, \
  345. } \
  346. }
  347. /*
  348. * List of Northstar2 pin groups
  349. */
  350. static const struct ns2_pin_group ns2_pin_groups[] = {
  351. NS2_PIN_GROUP(nand, 0, 0, 31, 1, 0),
  352. NS2_PIN_GROUP(nor_data, 0, 0, 31, 1, 1),
  353. NS2_PIN_GROUP(gpio_0_1, 0, 0, 31, 1, 0),
  354. NS2_PIN_GROUP(uart1_ext_clk, 0, 4, 30, 3, 1),
  355. NS2_PIN_GROUP(nor_adv, 0, 4, 30, 3, 2),
  356. NS2_PIN_GROUP(gpio_2_5, 0, 4, 28, 3, 0),
  357. NS2_PIN_GROUP(pcie_ab1_clk_wak, 0, 4, 28, 3, 1),
  358. NS2_PIN_GROUP(nor_addr_0_3, 0, 4, 28, 3, 2),
  359. NS2_PIN_GROUP(gpio_6_7, 0, 4, 26, 3, 0),
  360. NS2_PIN_GROUP(pcie_a3_clk_wak, 0, 4, 26, 3, 1),
  361. NS2_PIN_GROUP(nor_addr_4_5, 0, 4, 26, 3, 2),
  362. NS2_PIN_GROUP(gpio_8_9, 0, 4, 24, 3, 0),
  363. NS2_PIN_GROUP(pcie_b3_clk_wak, 0, 4, 24, 3, 1),
  364. NS2_PIN_GROUP(nor_addr_6_7, 0, 4, 24, 3, 2),
  365. NS2_PIN_GROUP(gpio_10_11, 0, 4, 22, 3, 0),
  366. NS2_PIN_GROUP(pcie_b2_clk_wak, 0, 4, 22, 3, 1),
  367. NS2_PIN_GROUP(nor_addr_8_9, 0, 4, 22, 3, 2),
  368. NS2_PIN_GROUP(gpio_12_13, 0, 4, 20, 3, 0),
  369. NS2_PIN_GROUP(pcie_a2_clk_wak, 0, 4, 20, 3, 1),
  370. NS2_PIN_GROUP(nor_addr_10_11, 0, 4, 20, 3, 2),
  371. NS2_PIN_GROUP(gpio_14_17, 0, 4, 18, 3, 0),
  372. NS2_PIN_GROUP(uart0_modem, 0, 4, 18, 3, 1),
  373. NS2_PIN_GROUP(nor_addr_12_15, 0, 4, 18, 3, 2),
  374. NS2_PIN_GROUP(gpio_18_19, 0, 4, 16, 3, 0),
  375. NS2_PIN_GROUP(uart0_rts_cts, 0, 4, 16, 3, 1),
  376. NS2_PIN_GROUP(gpio_20_21, 0, 4, 14, 3, 0),
  377. NS2_PIN_GROUP(uart0_in_out, 0, 4, 14, 3, 1),
  378. NS2_PIN_GROUP(gpio_22_23, 0, 4, 12, 3, 0),
  379. NS2_PIN_GROUP(uart1_dcd_dsr, 0, 4, 12, 3, 1),
  380. NS2_PIN_GROUP(gpio_24_25, 0, 4, 10, 3, 0),
  381. NS2_PIN_GROUP(uart1_ri_dtr, 0, 4, 10, 3, 1),
  382. NS2_PIN_GROUP(gpio_26_27, 0, 4, 8, 3, 0),
  383. NS2_PIN_GROUP(uart1_rts_cts, 0, 4, 8, 3, 1),
  384. NS2_PIN_GROUP(gpio_28_29, 0, 4, 6, 3, 0),
  385. NS2_PIN_GROUP(uart1_in_out, 0, 4, 6, 3, 1),
  386. NS2_PIN_GROUP(gpio_30_31, 0, 4, 4, 3, 0),
  387. NS2_PIN_GROUP(uart2_rts_cts, 0, 4, 4, 3, 1),
  388. NS2_PIN_GROUP(pwm_0, 1, 0, 0, 1, 1),
  389. NS2_PIN_GROUP(pwm_1, 1, 0, 1, 1, 1),
  390. NS2_PIN_GROUP(pwm_2, 1, 0, 2, 1, 1),
  391. NS2_PIN_GROUP(pwm_3, 1, 0, 3, 1, 1),
  392. };
  393. /*
  394. * List of groups supported by functions
  395. */
  396. static const char * const nand_grps[] = {"nand_grp"};
  397. static const char * const nor_grps[] = {"nor_data_grp", "nor_adv_grp",
  398. "nor_addr_0_3_grp", "nor_addr_4_5_grp", "nor_addr_6_7_grp",
  399. "nor_addr_8_9_grp", "nor_addr_10_11_grp", "nor_addr_12_15_grp"};
  400. static const char * const gpio_grps[] = {"gpio_0_1_grp", "gpio_2_5_grp",
  401. "gpio_6_7_grp", "gpio_8_9_grp", "gpio_10_11_grp", "gpio_12_13_grp",
  402. "gpio_14_17_grp", "gpio_18_19_grp", "gpio_20_21_grp", "gpio_22_23_grp",
  403. "gpio_24_25_grp", "gpio_26_27_grp", "gpio_28_29_grp",
  404. "gpio_30_31_grp"};
  405. static const char * const pcie_grps[] = {"pcie_ab1_clk_wak_grp",
  406. "pcie_a3_clk_wak_grp", "pcie_b3_clk_wak_grp", "pcie_b2_clk_wak_grp",
  407. "pcie_a2_clk_wak_grp"};
  408. static const char * const uart0_grps[] = {"uart0_modem_grp",
  409. "uart0_rts_cts_grp", "uart0_in_out_grp"};
  410. static const char * const uart1_grps[] = {"uart1_ext_clk_grp",
  411. "uart1_dcd_dsr_grp", "uart1_ri_dtr_grp", "uart1_rts_cts_grp",
  412. "uart1_in_out_grp"};
  413. static const char * const uart2_grps[] = {"uart2_rts_cts_grp"};
  414. static const char * const pwm_grps[] = {"pwm_0_grp", "pwm_1_grp",
  415. "pwm_2_grp", "pwm_3_grp"};
  416. #define NS2_PIN_FUNCTION(func) \
  417. { \
  418. .name = #func, \
  419. .groups = func ## _grps, \
  420. .num_groups = ARRAY_SIZE(func ## _grps), \
  421. }
  422. /*
  423. * List of supported functions
  424. */
  425. static const struct ns2_pin_function ns2_pin_functions[] = {
  426. NS2_PIN_FUNCTION(nand),
  427. NS2_PIN_FUNCTION(nor),
  428. NS2_PIN_FUNCTION(gpio),
  429. NS2_PIN_FUNCTION(pcie),
  430. NS2_PIN_FUNCTION(uart0),
  431. NS2_PIN_FUNCTION(uart1),
  432. NS2_PIN_FUNCTION(uart2),
  433. NS2_PIN_FUNCTION(pwm),
  434. };
  435. static int ns2_get_groups_count(struct pinctrl_dev *pctrl_dev)
  436. {
  437. struct ns2_pinctrl *pinctrl = pinctrl_dev_get_drvdata(pctrl_dev);
  438. return pinctrl->num_groups;
  439. }
  440. static const char *ns2_get_group_name(struct pinctrl_dev *pctrl_dev,
  441. unsigned int selector)
  442. {
  443. struct ns2_pinctrl *pinctrl = pinctrl_dev_get_drvdata(pctrl_dev);
  444. return pinctrl->groups[selector].name;
  445. }
  446. static int ns2_get_group_pins(struct pinctrl_dev *pctrl_dev,
  447. unsigned int selector, const unsigned int **pins,
  448. unsigned int *num_pins)
  449. {
  450. struct ns2_pinctrl *pinctrl = pinctrl_dev_get_drvdata(pctrl_dev);
  451. *pins = pinctrl->groups[selector].pins;
  452. *num_pins = pinctrl->groups[selector].num_pins;
  453. return 0;
  454. }
  455. static void ns2_pin_dbg_show(struct pinctrl_dev *pctrl_dev,
  456. struct seq_file *s, unsigned int offset)
  457. {
  458. seq_printf(s, " %s", dev_name(pctrl_dev->dev));
  459. }
  460. static const struct pinctrl_ops ns2_pinctrl_ops = {
  461. .get_groups_count = ns2_get_groups_count,
  462. .get_group_name = ns2_get_group_name,
  463. .get_group_pins = ns2_get_group_pins,
  464. .pin_dbg_show = ns2_pin_dbg_show,
  465. .dt_node_to_map = pinconf_generic_dt_node_to_map_pin,
  466. .dt_free_map = pinctrl_utils_free_map,
  467. };
  468. static int ns2_get_functions_count(struct pinctrl_dev *pctrl_dev)
  469. {
  470. struct ns2_pinctrl *pinctrl = pinctrl_dev_get_drvdata(pctrl_dev);
  471. return pinctrl->num_functions;
  472. }
  473. static const char *ns2_get_function_name(struct pinctrl_dev *pctrl_dev,
  474. unsigned int selector)
  475. {
  476. struct ns2_pinctrl *pinctrl = pinctrl_dev_get_drvdata(pctrl_dev);
  477. return pinctrl->functions[selector].name;
  478. }
  479. static int ns2_get_function_groups(struct pinctrl_dev *pctrl_dev,
  480. unsigned int selector,
  481. const char * const **groups,
  482. unsigned int * const num_groups)
  483. {
  484. struct ns2_pinctrl *pinctrl = pinctrl_dev_get_drvdata(pctrl_dev);
  485. *groups = pinctrl->functions[selector].groups;
  486. *num_groups = pinctrl->functions[selector].num_groups;
  487. return 0;
  488. }
  489. static int ns2_pinmux_set(struct ns2_pinctrl *pinctrl,
  490. const struct ns2_pin_function *func,
  491. const struct ns2_pin_group *grp,
  492. struct ns2_mux_log *mux_log)
  493. {
  494. const struct ns2_mux *mux = &grp->mux;
  495. int i;
  496. u32 val, mask;
  497. unsigned long flags;
  498. void __iomem *base_address;
  499. for (i = 0; i < NS2_NUM_IOMUX; i++) {
  500. if ((mux->shift != mux_log[i].mux.shift) ||
  501. (mux->base != mux_log[i].mux.base) ||
  502. (mux->offset != mux_log[i].mux.offset))
  503. continue;
  504. /* if this is a new configuration, just do it! */
  505. if (!mux_log[i].is_configured)
  506. break;
  507. /*
  508. * IOMUX has been configured previously and one is trying to
  509. * configure it to a different function
  510. */
  511. if (mux_log[i].mux.alt != mux->alt) {
  512. dev_err(pinctrl->dev,
  513. "double configuration error detected!\n");
  514. dev_err(pinctrl->dev, "func:%s grp:%s\n",
  515. func->name, grp->name);
  516. return -EINVAL;
  517. }
  518. return 0;
  519. }
  520. if (i == NS2_NUM_IOMUX)
  521. return -EINVAL;
  522. mask = mux->mask;
  523. mux_log[i].mux.alt = mux->alt;
  524. mux_log[i].is_configured = true;
  525. switch (mux->base) {
  526. case NS2_PIN_MUX_BASE0:
  527. base_address = pinctrl->base0;
  528. break;
  529. case NS2_PIN_MUX_BASE1:
  530. base_address = pinctrl->base1;
  531. break;
  532. default:
  533. return -EINVAL;
  534. }
  535. spin_lock_irqsave(&pinctrl->lock, flags);
  536. val = readl(base_address + grp->mux.offset);
  537. val &= ~(mask << grp->mux.shift);
  538. val |= grp->mux.alt << grp->mux.shift;
  539. writel(val, (base_address + grp->mux.offset));
  540. spin_unlock_irqrestore(&pinctrl->lock, flags);
  541. return 0;
  542. }
  543. static int ns2_pinmux_enable(struct pinctrl_dev *pctrl_dev,
  544. unsigned int func_select, unsigned int grp_select)
  545. {
  546. struct ns2_pinctrl *pinctrl = pinctrl_dev_get_drvdata(pctrl_dev);
  547. const struct ns2_pin_function *func;
  548. const struct ns2_pin_group *grp;
  549. if (grp_select > pinctrl->num_groups ||
  550. func_select > pinctrl->num_functions)
  551. return -EINVAL;
  552. func = &pinctrl->functions[func_select];
  553. grp = &pinctrl->groups[grp_select];
  554. dev_dbg(pctrl_dev->dev, "func:%u name:%s grp:%u name:%s\n",
  555. func_select, func->name, grp_select, grp->name);
  556. dev_dbg(pctrl_dev->dev, "offset:0x%08x shift:%u alt:%u\n",
  557. grp->mux.offset, grp->mux.shift, grp->mux.alt);
  558. return ns2_pinmux_set(pinctrl, func, grp, pinctrl->mux_log);
  559. }
  560. static int ns2_pin_set_enable(struct pinctrl_dev *pctrldev, unsigned int pin,
  561. u16 enable)
  562. {
  563. struct ns2_pinctrl *pinctrl = pinctrl_dev_get_drvdata(pctrldev);
  564. struct ns2_pin *pin_data = pctrldev->desc->pins[pin].drv_data;
  565. unsigned long flags;
  566. u32 val;
  567. void __iomem *base_address;
  568. base_address = pinctrl->pinconf_base;
  569. spin_lock_irqsave(&pinctrl->lock, flags);
  570. val = readl(base_address + pin_data->pin_conf.offset);
  571. val &= ~(NS2_PIN_SRC_MASK << pin_data->pin_conf.input_en);
  572. if (!enable)
  573. val |= NS2_PIN_INPUT_EN_MASK << pin_data->pin_conf.input_en;
  574. writel(val, (base_address + pin_data->pin_conf.offset));
  575. spin_unlock_irqrestore(&pinctrl->lock, flags);
  576. dev_dbg(pctrldev->dev, "pin:%u set enable:%d\n", pin, enable);
  577. return 0;
  578. }
  579. static int ns2_pin_get_enable(struct pinctrl_dev *pctrldev, unsigned int pin)
  580. {
  581. struct ns2_pinctrl *pinctrl = pinctrl_dev_get_drvdata(pctrldev);
  582. struct ns2_pin *pin_data = pctrldev->desc->pins[pin].drv_data;
  583. unsigned long flags;
  584. int enable;
  585. spin_lock_irqsave(&pinctrl->lock, flags);
  586. enable = readl(pinctrl->pinconf_base + pin_data->pin_conf.offset);
  587. enable = (enable >> pin_data->pin_conf.input_en) &
  588. NS2_PIN_INPUT_EN_MASK;
  589. spin_unlock_irqrestore(&pinctrl->lock, flags);
  590. if (!enable)
  591. enable = NS2_PIN_INPUT_EN_MASK;
  592. else
  593. enable = 0;
  594. dev_dbg(pctrldev->dev, "pin:%u get disable:%d\n", pin, enable);
  595. return enable;
  596. }
  597. static int ns2_pin_set_slew(struct pinctrl_dev *pctrldev, unsigned int pin,
  598. u16 slew)
  599. {
  600. struct ns2_pinctrl *pinctrl = pinctrl_dev_get_drvdata(pctrldev);
  601. struct ns2_pin *pin_data = pctrldev->desc->pins[pin].drv_data;
  602. unsigned long flags;
  603. u32 val;
  604. void __iomem *base_address;
  605. base_address = pinctrl->pinconf_base;
  606. spin_lock_irqsave(&pinctrl->lock, flags);
  607. val = readl(base_address + pin_data->pin_conf.offset);
  608. val &= ~(NS2_PIN_SRC_MASK << pin_data->pin_conf.src_shift);
  609. if (slew)
  610. val |= NS2_PIN_SRC_MASK << pin_data->pin_conf.src_shift;
  611. writel(val, (base_address + pin_data->pin_conf.offset));
  612. spin_unlock_irqrestore(&pinctrl->lock, flags);
  613. dev_dbg(pctrldev->dev, "pin:%u set slew:%d\n", pin, slew);
  614. return 0;
  615. }
  616. static int ns2_pin_get_slew(struct pinctrl_dev *pctrldev, unsigned int pin,
  617. u16 *slew)
  618. {
  619. struct ns2_pinctrl *pinctrl = pinctrl_dev_get_drvdata(pctrldev);
  620. struct ns2_pin *pin_data = pctrldev->desc->pins[pin].drv_data;
  621. unsigned long flags;
  622. u32 val;
  623. spin_lock_irqsave(&pinctrl->lock, flags);
  624. val = readl(pinctrl->pinconf_base + pin_data->pin_conf.offset);
  625. *slew = (val >> pin_data->pin_conf.src_shift) & NS2_PIN_SRC_MASK;
  626. spin_unlock_irqrestore(&pinctrl->lock, flags);
  627. dev_dbg(pctrldev->dev, "pin:%u get slew:%d\n", pin, *slew);
  628. return 0;
  629. }
  630. static int ns2_pin_set_pull(struct pinctrl_dev *pctrldev, unsigned int pin,
  631. bool pull_up, bool pull_down)
  632. {
  633. struct ns2_pinctrl *pinctrl = pinctrl_dev_get_drvdata(pctrldev);
  634. struct ns2_pin *pin_data = pctrldev->desc->pins[pin].drv_data;
  635. unsigned long flags;
  636. u32 val;
  637. void __iomem *base_address;
  638. base_address = pinctrl->pinconf_base;
  639. spin_lock_irqsave(&pinctrl->lock, flags);
  640. val = readl(base_address + pin_data->pin_conf.offset);
  641. val &= ~(NS2_PIN_PULL_MASK << pin_data->pin_conf.pull_shift);
  642. if (pull_up == true)
  643. val |= NS2_PIN_PULL_UP << pin_data->pin_conf.pull_shift;
  644. if (pull_down == true)
  645. val |= NS2_PIN_PULL_DOWN << pin_data->pin_conf.pull_shift;
  646. writel(val, (base_address + pin_data->pin_conf.offset));
  647. spin_unlock_irqrestore(&pinctrl->lock, flags);
  648. dev_dbg(pctrldev->dev, "pin:%u set pullup:%d pulldown: %d\n",
  649. pin, pull_up, pull_down);
  650. return 0;
  651. }
  652. static void ns2_pin_get_pull(struct pinctrl_dev *pctrldev,
  653. unsigned int pin, bool *pull_up,
  654. bool *pull_down)
  655. {
  656. struct ns2_pinctrl *pinctrl = pinctrl_dev_get_drvdata(pctrldev);
  657. struct ns2_pin *pin_data = pctrldev->desc->pins[pin].drv_data;
  658. unsigned long flags;
  659. u32 val;
  660. spin_lock_irqsave(&pinctrl->lock, flags);
  661. val = readl(pinctrl->pinconf_base + pin_data->pin_conf.offset);
  662. val = (val >> pin_data->pin_conf.pull_shift) & NS2_PIN_PULL_MASK;
  663. *pull_up = false;
  664. *pull_down = false;
  665. if (val == NS2_PIN_PULL_UP)
  666. *pull_up = true;
  667. if (val == NS2_PIN_PULL_DOWN)
  668. *pull_down = true;
  669. spin_unlock_irqrestore(&pinctrl->lock, flags);
  670. }
  671. static int ns2_pin_set_strength(struct pinctrl_dev *pctrldev, unsigned int pin,
  672. u16 strength)
  673. {
  674. struct ns2_pinctrl *pinctrl = pinctrl_dev_get_drvdata(pctrldev);
  675. struct ns2_pin *pin_data = pctrldev->desc->pins[pin].drv_data;
  676. u32 val;
  677. unsigned long flags;
  678. void __iomem *base_address;
  679. /* make sure drive strength is supported */
  680. if (strength < 2 || strength > 16 || (strength % 2))
  681. return -ENOTSUPP;
  682. base_address = pinctrl->pinconf_base;
  683. spin_lock_irqsave(&pinctrl->lock, flags);
  684. val = readl(base_address + pin_data->pin_conf.offset);
  685. val &= ~(NS2_PIN_DRIVE_STRENGTH_MASK << pin_data->pin_conf.drive_shift);
  686. val |= ((strength / 2) - 1) << pin_data->pin_conf.drive_shift;
  687. writel(val, (base_address + pin_data->pin_conf.offset));
  688. spin_unlock_irqrestore(&pinctrl->lock, flags);
  689. dev_dbg(pctrldev->dev, "pin:%u set drive strength:%d mA\n",
  690. pin, strength);
  691. return 0;
  692. }
  693. static int ns2_pin_get_strength(struct pinctrl_dev *pctrldev, unsigned int pin,
  694. u16 *strength)
  695. {
  696. struct ns2_pinctrl *pinctrl = pinctrl_dev_get_drvdata(pctrldev);
  697. struct ns2_pin *pin_data = pctrldev->desc->pins[pin].drv_data;
  698. u32 val;
  699. unsigned long flags;
  700. spin_lock_irqsave(&pinctrl->lock, flags);
  701. val = readl(pinctrl->pinconf_base + pin_data->pin_conf.offset);
  702. *strength = (val >> pin_data->pin_conf.drive_shift) &
  703. NS2_PIN_DRIVE_STRENGTH_MASK;
  704. *strength = (*strength + 1) * 2;
  705. spin_unlock_irqrestore(&pinctrl->lock, flags);
  706. dev_dbg(pctrldev->dev, "pin:%u get drive strength:%d mA\n",
  707. pin, *strength);
  708. return 0;
  709. }
  710. static int ns2_pin_config_get(struct pinctrl_dev *pctldev, unsigned int pin,
  711. unsigned long *config)
  712. {
  713. struct ns2_pin *pin_data = pctldev->desc->pins[pin].drv_data;
  714. enum pin_config_param param = pinconf_to_config_param(*config);
  715. bool pull_up, pull_down;
  716. u16 arg = 0;
  717. int ret;
  718. if (pin_data->pin_conf.base == -1)
  719. return -ENOTSUPP;
  720. switch (param) {
  721. case PIN_CONFIG_BIAS_DISABLE:
  722. ns2_pin_get_pull(pctldev, pin, &pull_up, &pull_down);
  723. if ((pull_up == false) && (pull_down == false))
  724. return 0;
  725. else
  726. return -EINVAL;
  727. case PIN_CONFIG_BIAS_PULL_UP:
  728. ns2_pin_get_pull(pctldev, pin, &pull_up, &pull_down);
  729. if (pull_up)
  730. return 0;
  731. else
  732. return -EINVAL;
  733. case PIN_CONFIG_BIAS_PULL_DOWN:
  734. ns2_pin_get_pull(pctldev, pin, &pull_up, &pull_down);
  735. if (pull_down)
  736. return 0;
  737. else
  738. return -EINVAL;
  739. case PIN_CONFIG_DRIVE_STRENGTH:
  740. ret = ns2_pin_get_strength(pctldev, pin, &arg);
  741. if (ret)
  742. return ret;
  743. *config = pinconf_to_config_packed(param, arg);
  744. return 0;
  745. case PIN_CONFIG_SLEW_RATE:
  746. ret = ns2_pin_get_slew(pctldev, pin, &arg);
  747. if (ret)
  748. return ret;
  749. *config = pinconf_to_config_packed(param, arg);
  750. return 0;
  751. case PIN_CONFIG_INPUT_ENABLE:
  752. ret = ns2_pin_get_enable(pctldev, pin);
  753. if (ret)
  754. return 0;
  755. else
  756. return -EINVAL;
  757. default:
  758. return -ENOTSUPP;
  759. }
  760. }
  761. static int ns2_pin_config_set(struct pinctrl_dev *pctrldev, unsigned int pin,
  762. unsigned long *configs, unsigned int num_configs)
  763. {
  764. struct ns2_pin *pin_data = pctrldev->desc->pins[pin].drv_data;
  765. enum pin_config_param param;
  766. unsigned int i;
  767. u16 arg;
  768. int ret = -ENOTSUPP;
  769. if (pin_data->pin_conf.base == -1)
  770. return -ENOTSUPP;
  771. for (i = 0; i < num_configs; i++) {
  772. param = pinconf_to_config_param(configs[i]);
  773. arg = pinconf_to_config_argument(configs[i]);
  774. switch (param) {
  775. case PIN_CONFIG_BIAS_DISABLE:
  776. ret = ns2_pin_set_pull(pctrldev, pin, false, false);
  777. if (ret < 0)
  778. goto out;
  779. break;
  780. case PIN_CONFIG_BIAS_PULL_UP:
  781. ret = ns2_pin_set_pull(pctrldev, pin, true, false);
  782. if (ret < 0)
  783. goto out;
  784. break;
  785. case PIN_CONFIG_BIAS_PULL_DOWN:
  786. ret = ns2_pin_set_pull(pctrldev, pin, false, true);
  787. if (ret < 0)
  788. goto out;
  789. break;
  790. case PIN_CONFIG_DRIVE_STRENGTH:
  791. ret = ns2_pin_set_strength(pctrldev, pin, arg);
  792. if (ret < 0)
  793. goto out;
  794. break;
  795. case PIN_CONFIG_SLEW_RATE:
  796. ret = ns2_pin_set_slew(pctrldev, pin, arg);
  797. if (ret < 0)
  798. goto out;
  799. break;
  800. case PIN_CONFIG_INPUT_ENABLE:
  801. ret = ns2_pin_set_enable(pctrldev, pin, arg);
  802. if (ret < 0)
  803. goto out;
  804. break;
  805. default:
  806. dev_err(pctrldev->dev, "invalid configuration\n");
  807. return -ENOTSUPP;
  808. }
  809. }
  810. out:
  811. return ret;
  812. }
  813. static const struct pinmux_ops ns2_pinmux_ops = {
  814. .get_functions_count = ns2_get_functions_count,
  815. .get_function_name = ns2_get_function_name,
  816. .get_function_groups = ns2_get_function_groups,
  817. .set_mux = ns2_pinmux_enable,
  818. };
  819. static const struct pinconf_ops ns2_pinconf_ops = {
  820. .is_generic = true,
  821. .pin_config_get = ns2_pin_config_get,
  822. .pin_config_set = ns2_pin_config_set,
  823. };
  824. static struct pinctrl_desc ns2_pinctrl_desc = {
  825. .name = "ns2-pinmux",
  826. .pctlops = &ns2_pinctrl_ops,
  827. .pmxops = &ns2_pinmux_ops,
  828. .confops = &ns2_pinconf_ops,
  829. };
  830. static int ns2_mux_log_init(struct ns2_pinctrl *pinctrl)
  831. {
  832. struct ns2_mux_log *log;
  833. unsigned int i;
  834. pinctrl->mux_log = devm_kcalloc(pinctrl->dev, NS2_NUM_IOMUX,
  835. sizeof(struct ns2_mux_log),
  836. GFP_KERNEL);
  837. if (!pinctrl->mux_log)
  838. return -ENOMEM;
  839. for (i = 0; i < NS2_NUM_IOMUX; i++)
  840. pinctrl->mux_log[i].is_configured = false;
  841. /* Group 0 uses bit 31 in the IOMUX_PAD_FUNCTION_0 register */
  842. log = &pinctrl->mux_log[0];
  843. log->mux.base = NS2_PIN_MUX_BASE0;
  844. log->mux.offset = 0;
  845. log->mux.shift = 31;
  846. log->mux.alt = 0;
  847. /*
  848. * Groups 1 through 14 use two bits each in the
  849. * IOMUX_PAD_FUNCTION_1 register starting with
  850. * bit position 30.
  851. */
  852. for (i = 1; i < (NS2_NUM_IOMUX - NS2_NUM_PWM_MUX); i++) {
  853. log = &pinctrl->mux_log[i];
  854. log->mux.base = NS2_PIN_MUX_BASE0;
  855. log->mux.offset = NS2_MUX_PAD_FUNC1_OFFSET;
  856. log->mux.shift = 32 - (i * 2);
  857. log->mux.alt = 0;
  858. }
  859. /*
  860. * Groups 15 through 18 use one bit each in the
  861. * AUX_SEL register.
  862. */
  863. for (i = 0; i < NS2_NUM_PWM_MUX; i++) {
  864. log = &pinctrl->mux_log[(NS2_NUM_IOMUX - NS2_NUM_PWM_MUX) + i];
  865. log->mux.base = NS2_PIN_MUX_BASE1;
  866. log->mux.offset = 0;
  867. log->mux.shift = i;
  868. log->mux.alt = 0;
  869. }
  870. return 0;
  871. }
  872. static int ns2_pinmux_probe(struct platform_device *pdev)
  873. {
  874. struct ns2_pinctrl *pinctrl;
  875. struct resource *res;
  876. int i, ret;
  877. struct pinctrl_pin_desc *pins;
  878. unsigned int num_pins = ARRAY_SIZE(ns2_pins);
  879. pinctrl = devm_kzalloc(&pdev->dev, sizeof(*pinctrl), GFP_KERNEL);
  880. if (!pinctrl)
  881. return -ENOMEM;
  882. pinctrl->dev = &pdev->dev;
  883. platform_set_drvdata(pdev, pinctrl);
  884. spin_lock_init(&pinctrl->lock);
  885. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  886. pinctrl->base0 = devm_ioremap_resource(&pdev->dev, res);
  887. if (IS_ERR(pinctrl->base0))
  888. return PTR_ERR(pinctrl->base0);
  889. res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  890. pinctrl->base1 = devm_ioremap_nocache(&pdev->dev, res->start,
  891. resource_size(res));
  892. if (!pinctrl->base1) {
  893. dev_err(&pdev->dev, "unable to map I/O space\n");
  894. return -ENOMEM;
  895. }
  896. res = platform_get_resource(pdev, IORESOURCE_MEM, 2);
  897. pinctrl->pinconf_base = devm_ioremap_resource(&pdev->dev, res);
  898. if (IS_ERR(pinctrl->pinconf_base))
  899. return PTR_ERR(pinctrl->pinconf_base);
  900. ret = ns2_mux_log_init(pinctrl);
  901. if (ret) {
  902. dev_err(&pdev->dev, "unable to initialize IOMUX log\n");
  903. return ret;
  904. }
  905. pins = devm_kcalloc(&pdev->dev, num_pins, sizeof(*pins), GFP_KERNEL);
  906. if (!pins)
  907. return -ENOMEM;
  908. for (i = 0; i < num_pins; i++) {
  909. pins[i].number = ns2_pins[i].pin;
  910. pins[i].name = ns2_pins[i].name;
  911. pins[i].drv_data = &ns2_pins[i];
  912. }
  913. pinctrl->groups = ns2_pin_groups;
  914. pinctrl->num_groups = ARRAY_SIZE(ns2_pin_groups);
  915. pinctrl->functions = ns2_pin_functions;
  916. pinctrl->num_functions = ARRAY_SIZE(ns2_pin_functions);
  917. ns2_pinctrl_desc.pins = pins;
  918. ns2_pinctrl_desc.npins = num_pins;
  919. pinctrl->pctl = pinctrl_register(&ns2_pinctrl_desc, &pdev->dev,
  920. pinctrl);
  921. if (IS_ERR(pinctrl->pctl)) {
  922. dev_err(&pdev->dev, "unable to register IOMUX pinctrl\n");
  923. return PTR_ERR(pinctrl->pctl);
  924. }
  925. return 0;
  926. }
  927. static const struct of_device_id ns2_pinmux_of_match[] = {
  928. {.compatible = "brcm,ns2-pinmux"},
  929. { }
  930. };
  931. static struct platform_driver ns2_pinmux_driver = {
  932. .driver = {
  933. .name = "ns2-pinmux",
  934. .of_match_table = ns2_pinmux_of_match,
  935. },
  936. .probe = ns2_pinmux_probe,
  937. };
  938. static int __init ns2_pinmux_init(void)
  939. {
  940. return platform_driver_register(&ns2_pinmux_driver);
  941. }
  942. arch_initcall(ns2_pinmux_init);