pinctrl-pistachio.c 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Pistachio SoC pinctrl driver
  4. *
  5. * Copyright (C) 2014 Imagination Technologies Ltd.
  6. * Copyright (C) 2014 Google, Inc.
  7. */
  8. #include <linux/gpio/driver.h>
  9. #include <linux/interrupt.h>
  10. #include <linux/io.h>
  11. #include <linux/irq.h>
  12. #include <linux/mod_devicetable.h>
  13. #include <linux/pinctrl/pinconf.h>
  14. #include <linux/pinctrl/pinconf-generic.h>
  15. #include <linux/pinctrl/pinctrl.h>
  16. #include <linux/pinctrl/pinmux.h>
  17. #include <linux/platform_device.h>
  18. #include <linux/property.h>
  19. #include <linux/slab.h>
  20. #include <linux/spinlock.h>
  21. #include "pinctrl-utils.h"
  22. #define PADS_SCHMITT_EN0 0x000
  23. #define PADS_SCHMITT_EN_REG(pin) (PADS_SCHMITT_EN0 + 0x4 * ((pin) / 32))
  24. #define PADS_SCHMITT_EN_BIT(pin) BIT((pin) % 32)
  25. #define PADS_PU_PD0 0x040
  26. #define PADS_PU_PD_REG(pin) (PADS_PU_PD0 + 0x4 * ((pin) / 16))
  27. #define PADS_PU_PD_SHIFT(pin) (2 * ((pin) % 16))
  28. #define PADS_PU_PD_MASK 0x3
  29. #define PADS_PU_PD_HIGHZ 0x0
  30. #define PADS_PU_PD_UP 0x1
  31. #define PADS_PU_PD_DOWN 0x2
  32. #define PADS_PU_PD_BUS 0x3
  33. #define PADS_FUNCTION_SELECT0 0x0c0
  34. #define PADS_FUNCTION_SELECT1 0x0c4
  35. #define PADS_FUNCTION_SELECT2 0x0c8
  36. #define PADS_SCENARIO_SELECT 0x0f8
  37. #define PADS_SLEW_RATE0 0x100
  38. #define PADS_SLEW_RATE_REG(pin) (PADS_SLEW_RATE0 + 0x4 * ((pin) / 32))
  39. #define PADS_SLEW_RATE_BIT(pin) BIT((pin) % 32)
  40. #define PADS_DRIVE_STRENGTH0 0x120
  41. #define PADS_DRIVE_STRENGTH_REG(pin) \
  42. (PADS_DRIVE_STRENGTH0 + 0x4 * ((pin) / 16))
  43. #define PADS_DRIVE_STRENGTH_SHIFT(pin) (2 * ((pin) % 16))
  44. #define PADS_DRIVE_STRENGTH_MASK 0x3
  45. #define PADS_DRIVE_STRENGTH_2MA 0x0
  46. #define PADS_DRIVE_STRENGTH_4MA 0x1
  47. #define PADS_DRIVE_STRENGTH_8MA 0x2
  48. #define PADS_DRIVE_STRENGTH_12MA 0x3
  49. #define GPIO_BANK_BASE(bank) (0x200 + 0x24 * (bank))
  50. #define GPIO_BIT_EN 0x00
  51. #define GPIO_OUTPUT_EN 0x04
  52. #define GPIO_OUTPUT 0x08
  53. #define GPIO_INPUT 0x0c
  54. #define GPIO_INPUT_POLARITY 0x10
  55. #define GPIO_INTERRUPT_TYPE 0x14
  56. #define GPIO_INTERRUPT_TYPE_LEVEL 0x0
  57. #define GPIO_INTERRUPT_TYPE_EDGE 0x1
  58. #define GPIO_INTERRUPT_EDGE 0x18
  59. #define GPIO_INTERRUPT_EDGE_SINGLE 0x0
  60. #define GPIO_INTERRUPT_EDGE_DUAL 0x1
  61. #define GPIO_INTERRUPT_EN 0x1c
  62. #define GPIO_INTERRUPT_STATUS 0x20
  63. struct pistachio_function {
  64. const char *name;
  65. const char * const *groups;
  66. unsigned int ngroups;
  67. const int *scenarios;
  68. unsigned int nscenarios;
  69. unsigned int scenario_reg;
  70. unsigned int scenario_shift;
  71. unsigned int scenario_mask;
  72. };
  73. struct pistachio_pin_group {
  74. const char *name;
  75. unsigned int pin;
  76. int mux_option[3];
  77. int mux_reg;
  78. int mux_shift;
  79. int mux_mask;
  80. };
  81. struct pistachio_gpio_bank {
  82. struct pistachio_pinctrl *pctl;
  83. void __iomem *base;
  84. unsigned int pin_base;
  85. unsigned int npins;
  86. struct gpio_chip gpio_chip;
  87. struct irq_chip irq_chip;
  88. };
  89. struct pistachio_pinctrl {
  90. struct device *dev;
  91. void __iomem *base;
  92. struct pinctrl_dev *pctldev;
  93. const struct pinctrl_pin_desc *pins;
  94. unsigned int npins;
  95. const struct pistachio_function *functions;
  96. unsigned int nfunctions;
  97. const struct pistachio_pin_group *groups;
  98. unsigned int ngroups;
  99. struct pistachio_gpio_bank *gpio_banks;
  100. unsigned int nbanks;
  101. };
  102. #define PISTACHIO_PIN_MFIO(p) (p)
  103. #define PISTACHIO_PIN_TCK 90
  104. #define PISTACHIO_PIN_TRSTN 91
  105. #define PISTACHIO_PIN_TDI 92
  106. #define PISTACHIO_PIN_TMS 93
  107. #define PISTACHIO_PIN_TDO 94
  108. #define PISTACHIO_PIN_JTAG_COMPLY 95
  109. #define PISTACHIO_PIN_SAFE_MODE 96
  110. #define PISTACHIO_PIN_POR_DISABLE 97
  111. #define PISTACHIO_PIN_RESETN 98
  112. #define MFIO_PIN_DESC(p) PINCTRL_PIN(PISTACHIO_PIN_MFIO(p), "mfio" #p)
  113. static const struct pinctrl_pin_desc pistachio_pins[] = {
  114. MFIO_PIN_DESC(0),
  115. MFIO_PIN_DESC(1),
  116. MFIO_PIN_DESC(2),
  117. MFIO_PIN_DESC(3),
  118. MFIO_PIN_DESC(4),
  119. MFIO_PIN_DESC(5),
  120. MFIO_PIN_DESC(6),
  121. MFIO_PIN_DESC(7),
  122. MFIO_PIN_DESC(8),
  123. MFIO_PIN_DESC(9),
  124. MFIO_PIN_DESC(10),
  125. MFIO_PIN_DESC(11),
  126. MFIO_PIN_DESC(12),
  127. MFIO_PIN_DESC(13),
  128. MFIO_PIN_DESC(14),
  129. MFIO_PIN_DESC(15),
  130. MFIO_PIN_DESC(16),
  131. MFIO_PIN_DESC(17),
  132. MFIO_PIN_DESC(18),
  133. MFIO_PIN_DESC(19),
  134. MFIO_PIN_DESC(20),
  135. MFIO_PIN_DESC(21),
  136. MFIO_PIN_DESC(22),
  137. MFIO_PIN_DESC(23),
  138. MFIO_PIN_DESC(24),
  139. MFIO_PIN_DESC(25),
  140. MFIO_PIN_DESC(26),
  141. MFIO_PIN_DESC(27),
  142. MFIO_PIN_DESC(28),
  143. MFIO_PIN_DESC(29),
  144. MFIO_PIN_DESC(30),
  145. MFIO_PIN_DESC(31),
  146. MFIO_PIN_DESC(32),
  147. MFIO_PIN_DESC(33),
  148. MFIO_PIN_DESC(34),
  149. MFIO_PIN_DESC(35),
  150. MFIO_PIN_DESC(36),
  151. MFIO_PIN_DESC(37),
  152. MFIO_PIN_DESC(38),
  153. MFIO_PIN_DESC(39),
  154. MFIO_PIN_DESC(40),
  155. MFIO_PIN_DESC(41),
  156. MFIO_PIN_DESC(42),
  157. MFIO_PIN_DESC(43),
  158. MFIO_PIN_DESC(44),
  159. MFIO_PIN_DESC(45),
  160. MFIO_PIN_DESC(46),
  161. MFIO_PIN_DESC(47),
  162. MFIO_PIN_DESC(48),
  163. MFIO_PIN_DESC(49),
  164. MFIO_PIN_DESC(50),
  165. MFIO_PIN_DESC(51),
  166. MFIO_PIN_DESC(52),
  167. MFIO_PIN_DESC(53),
  168. MFIO_PIN_DESC(54),
  169. MFIO_PIN_DESC(55),
  170. MFIO_PIN_DESC(56),
  171. MFIO_PIN_DESC(57),
  172. MFIO_PIN_DESC(58),
  173. MFIO_PIN_DESC(59),
  174. MFIO_PIN_DESC(60),
  175. MFIO_PIN_DESC(61),
  176. MFIO_PIN_DESC(62),
  177. MFIO_PIN_DESC(63),
  178. MFIO_PIN_DESC(64),
  179. MFIO_PIN_DESC(65),
  180. MFIO_PIN_DESC(66),
  181. MFIO_PIN_DESC(67),
  182. MFIO_PIN_DESC(68),
  183. MFIO_PIN_DESC(69),
  184. MFIO_PIN_DESC(70),
  185. MFIO_PIN_DESC(71),
  186. MFIO_PIN_DESC(72),
  187. MFIO_PIN_DESC(73),
  188. MFIO_PIN_DESC(74),
  189. MFIO_PIN_DESC(75),
  190. MFIO_PIN_DESC(76),
  191. MFIO_PIN_DESC(77),
  192. MFIO_PIN_DESC(78),
  193. MFIO_PIN_DESC(79),
  194. MFIO_PIN_DESC(80),
  195. MFIO_PIN_DESC(81),
  196. MFIO_PIN_DESC(82),
  197. MFIO_PIN_DESC(83),
  198. MFIO_PIN_DESC(84),
  199. MFIO_PIN_DESC(85),
  200. MFIO_PIN_DESC(86),
  201. MFIO_PIN_DESC(87),
  202. MFIO_PIN_DESC(88),
  203. MFIO_PIN_DESC(89),
  204. PINCTRL_PIN(PISTACHIO_PIN_TCK, "tck"),
  205. PINCTRL_PIN(PISTACHIO_PIN_TRSTN, "trstn"),
  206. PINCTRL_PIN(PISTACHIO_PIN_TDI, "tdi"),
  207. PINCTRL_PIN(PISTACHIO_PIN_TMS, "tms"),
  208. PINCTRL_PIN(PISTACHIO_PIN_TDO, "tdo"),
  209. PINCTRL_PIN(PISTACHIO_PIN_JTAG_COMPLY, "jtag_comply"),
  210. PINCTRL_PIN(PISTACHIO_PIN_SAFE_MODE, "safe_mode"),
  211. PINCTRL_PIN(PISTACHIO_PIN_POR_DISABLE, "por_disable"),
  212. PINCTRL_PIN(PISTACHIO_PIN_RESETN, "resetn"),
  213. };
  214. static const char * const pistachio_spim0_groups[] = {
  215. "mfio1", "mfio2", "mfio8", "mfio9", "mfio10", "mfio28", "mfio29",
  216. "mfio30", "mfio55", "mfio56", "mfio57",
  217. };
  218. static const char * const pistachio_spim1_groups[] = {
  219. "mfio0", "mfio1", "mfio2", "mfio3", "mfio4", "mfio5", "mfio6",
  220. "mfio7", "mfio31", "mfio55", "mfio56", "mfio57", "mfio58",
  221. };
  222. static const char * const pistachio_spis_groups[] = {
  223. "mfio11", "mfio12", "mfio13", "mfio14",
  224. };
  225. static const char *const pistachio_sdhost_groups[] = {
  226. "mfio15", "mfio16", "mfio17", "mfio18", "mfio19", "mfio20",
  227. "mfio21", "mfio22", "mfio23", "mfio24", "mfio25", "mfio26",
  228. "mfio27",
  229. };
  230. static const char * const pistachio_i2c0_groups[] = {
  231. "mfio28", "mfio29",
  232. };
  233. static const char * const pistachio_i2c1_groups[] = {
  234. "mfio30", "mfio31",
  235. };
  236. static const char * const pistachio_i2c2_groups[] = {
  237. "mfio32", "mfio33",
  238. };
  239. static const char * const pistachio_i2c3_groups[] = {
  240. "mfio34", "mfio35",
  241. };
  242. static const char * const pistachio_audio_clk_in_groups[] = {
  243. "mfio36",
  244. };
  245. static const char * const pistachio_i2s_out_groups[] = {
  246. "mfio36", "mfio37", "mfio38", "mfio39", "mfio40", "mfio41",
  247. "mfio42", "mfio43", "mfio44",
  248. };
  249. static const char * const pistachio_debug_raw_cca_ind_groups[] = {
  250. "mfio37",
  251. };
  252. static const char * const pistachio_debug_ed_sec20_cca_ind_groups[] = {
  253. "mfio38",
  254. };
  255. static const char * const pistachio_debug_ed_sec40_cca_ind_groups[] = {
  256. "mfio39",
  257. };
  258. static const char * const pistachio_debug_agc_done_0_groups[] = {
  259. "mfio40",
  260. };
  261. static const char * const pistachio_debug_agc_done_1_groups[] = {
  262. "mfio41",
  263. };
  264. static const char * const pistachio_debug_ed_cca_ind_groups[] = {
  265. "mfio42",
  266. };
  267. static const char * const pistachio_debug_s2l_done_groups[] = {
  268. "mfio43",
  269. };
  270. static const char * const pistachio_i2s_dac_clk_groups[] = {
  271. "mfio45",
  272. };
  273. static const char * const pistachio_audio_sync_groups[] = {
  274. "mfio45",
  275. };
  276. static const char * const pistachio_audio_trigger_groups[] = {
  277. "mfio46",
  278. };
  279. static const char * const pistachio_i2s_in_groups[] = {
  280. "mfio47", "mfio48", "mfio49", "mfio50", "mfio51", "mfio52",
  281. "mfio53", "mfio54",
  282. };
  283. static const char * const pistachio_uart0_groups[] = {
  284. "mfio55", "mfio56", "mfio57", "mfio58",
  285. };
  286. static const char * const pistachio_uart1_groups[] = {
  287. "mfio59", "mfio60", "mfio1", "mfio2",
  288. };
  289. static const char * const pistachio_spdif_out_groups[] = {
  290. "mfio61",
  291. };
  292. static const char * const pistachio_spdif_in_groups[] = {
  293. "mfio62", "mfio54",
  294. };
  295. static const int pistachio_spdif_in_scenarios[] = {
  296. PISTACHIO_PIN_MFIO(62),
  297. PISTACHIO_PIN_MFIO(54),
  298. };
  299. static const char * const pistachio_eth_groups[] = {
  300. "mfio63", "mfio64", "mfio65", "mfio66", "mfio67", "mfio68",
  301. "mfio69", "mfio70", "mfio71",
  302. };
  303. static const char * const pistachio_ir_groups[] = {
  304. "mfio72",
  305. };
  306. static const char * const pistachio_pwmpdm_groups[] = {
  307. "mfio73", "mfio74", "mfio75", "mfio76",
  308. };
  309. static const char * const pistachio_mips_trace_clk_groups[] = {
  310. "mfio15", "mfio63", "mfio73",
  311. };
  312. static const char * const pistachio_mips_trace_dint_groups[] = {
  313. "mfio16", "mfio64", "mfio74",
  314. };
  315. static const int pistachio_mips_trace_dint_scenarios[] = {
  316. PISTACHIO_PIN_MFIO(16),
  317. PISTACHIO_PIN_MFIO(64),
  318. PISTACHIO_PIN_MFIO(74),
  319. };
  320. static const char * const pistachio_mips_trace_trigout_groups[] = {
  321. "mfio17", "mfio65", "mfio75",
  322. };
  323. static const char * const pistachio_mips_trace_trigin_groups[] = {
  324. "mfio18", "mfio66", "mfio76",
  325. };
  326. static const int pistachio_mips_trace_trigin_scenarios[] = {
  327. PISTACHIO_PIN_MFIO(18),
  328. PISTACHIO_PIN_MFIO(66),
  329. PISTACHIO_PIN_MFIO(76),
  330. };
  331. static const char * const pistachio_mips_trace_dm_groups[] = {
  332. "mfio19", "mfio67", "mfio77",
  333. };
  334. static const char * const pistachio_mips_probe_n_groups[] = {
  335. "mfio20", "mfio68", "mfio78",
  336. };
  337. static const int pistachio_mips_probe_n_scenarios[] = {
  338. PISTACHIO_PIN_MFIO(20),
  339. PISTACHIO_PIN_MFIO(68),
  340. PISTACHIO_PIN_MFIO(78),
  341. };
  342. static const char * const pistachio_mips_trace_data_groups[] = {
  343. "mfio15", "mfio16", "mfio17", "mfio18", "mfio19", "mfio20",
  344. "mfio21", "mfio22", "mfio63", "mfio64", "mfio65", "mfio66",
  345. "mfio67", "mfio68", "mfio69", "mfio70", "mfio79", "mfio80",
  346. "mfio81", "mfio82", "mfio83", "mfio84", "mfio85", "mfio86",
  347. };
  348. static const char * const pistachio_sram_debug_groups[] = {
  349. "mfio73", "mfio74",
  350. };
  351. static const char * const pistachio_rom_debug_groups[] = {
  352. "mfio75", "mfio76",
  353. };
  354. static const char * const pistachio_rpu_debug_groups[] = {
  355. "mfio77", "mfio78",
  356. };
  357. static const char * const pistachio_mips_debug_groups[] = {
  358. "mfio79", "mfio80",
  359. };
  360. static const char * const pistachio_eth_debug_groups[] = {
  361. "mfio81", "mfio82",
  362. };
  363. static const char * const pistachio_usb_debug_groups[] = {
  364. "mfio83", "mfio84",
  365. };
  366. static const char * const pistachio_sdhost_debug_groups[] = {
  367. "mfio85", "mfio86",
  368. };
  369. static const char * const pistachio_socif_debug_groups[] = {
  370. "mfio87", "mfio88",
  371. };
  372. static const char * const pistachio_mdc_debug_groups[] = {
  373. "mfio77", "mfio78",
  374. };
  375. static const char * const pistachio_ddr_debug_groups[] = {
  376. "mfio79", "mfio80",
  377. };
  378. static const char * const pistachio_dreq0_groups[] = {
  379. "mfio81",
  380. };
  381. static const char * const pistachio_dreq1_groups[] = {
  382. "mfio82",
  383. };
  384. static const char * const pistachio_dreq2_groups[] = {
  385. "mfio87",
  386. };
  387. static const char * const pistachio_dreq3_groups[] = {
  388. "mfio88",
  389. };
  390. static const char * const pistachio_dreq4_groups[] = {
  391. "mfio89",
  392. };
  393. static const char * const pistachio_dreq5_groups[] = {
  394. "mfio89",
  395. };
  396. static const char * const pistachio_mips_pll_lock_groups[] = {
  397. "mfio83",
  398. };
  399. static const char * const pistachio_audio_pll_lock_groups[] = {
  400. "mfio84",
  401. };
  402. static const char * const pistachio_rpu_v_pll_lock_groups[] = {
  403. "mfio85",
  404. };
  405. static const char * const pistachio_rpu_l_pll_lock_groups[] = {
  406. "mfio86",
  407. };
  408. static const char * const pistachio_sys_pll_lock_groups[] = {
  409. "mfio87",
  410. };
  411. static const char * const pistachio_wifi_pll_lock_groups[] = {
  412. "mfio88",
  413. };
  414. static const char * const pistachio_bt_pll_lock_groups[] = {
  415. "mfio89",
  416. };
  417. #define FUNCTION(_name) \
  418. { \
  419. .name = #_name, \
  420. .groups = pistachio_##_name##_groups, \
  421. .ngroups = ARRAY_SIZE(pistachio_##_name##_groups), \
  422. }
  423. #define FUNCTION_SCENARIO(_name, _reg, _shift, _mask) \
  424. { \
  425. .name = #_name, \
  426. .groups = pistachio_##_name##_groups, \
  427. .ngroups = ARRAY_SIZE(pistachio_##_name##_groups), \
  428. .scenarios = pistachio_##_name##_scenarios, \
  429. .nscenarios = ARRAY_SIZE(pistachio_##_name##_scenarios),\
  430. .scenario_reg = _reg, \
  431. .scenario_shift = _shift, \
  432. .scenario_mask = _mask, \
  433. }
  434. enum pistachio_mux_option {
  435. PISTACHIO_FUNCTION_NONE = -1,
  436. PISTACHIO_FUNCTION_SPIM0,
  437. PISTACHIO_FUNCTION_SPIM1,
  438. PISTACHIO_FUNCTION_SPIS,
  439. PISTACHIO_FUNCTION_SDHOST,
  440. PISTACHIO_FUNCTION_I2C0,
  441. PISTACHIO_FUNCTION_I2C1,
  442. PISTACHIO_FUNCTION_I2C2,
  443. PISTACHIO_FUNCTION_I2C3,
  444. PISTACHIO_FUNCTION_AUDIO_CLK_IN,
  445. PISTACHIO_FUNCTION_I2S_OUT,
  446. PISTACHIO_FUNCTION_I2S_DAC_CLK,
  447. PISTACHIO_FUNCTION_AUDIO_SYNC,
  448. PISTACHIO_FUNCTION_AUDIO_TRIGGER,
  449. PISTACHIO_FUNCTION_I2S_IN,
  450. PISTACHIO_FUNCTION_UART0,
  451. PISTACHIO_FUNCTION_UART1,
  452. PISTACHIO_FUNCTION_SPDIF_OUT,
  453. PISTACHIO_FUNCTION_SPDIF_IN,
  454. PISTACHIO_FUNCTION_ETH,
  455. PISTACHIO_FUNCTION_IR,
  456. PISTACHIO_FUNCTION_PWMPDM,
  457. PISTACHIO_FUNCTION_MIPS_TRACE_CLK,
  458. PISTACHIO_FUNCTION_MIPS_TRACE_DINT,
  459. PISTACHIO_FUNCTION_MIPS_TRACE_TRIGOUT,
  460. PISTACHIO_FUNCTION_MIPS_TRACE_TRIGIN,
  461. PISTACHIO_FUNCTION_MIPS_TRACE_DM,
  462. PISTACHIO_FUNCTION_MIPS_TRACE_PROBE_N,
  463. PISTACHIO_FUNCTION_MIPS_TRACE_DATA,
  464. PISTACHIO_FUNCTION_SRAM_DEBUG,
  465. PISTACHIO_FUNCTION_ROM_DEBUG,
  466. PISTACHIO_FUNCTION_RPU_DEBUG,
  467. PISTACHIO_FUNCTION_MIPS_DEBUG,
  468. PISTACHIO_FUNCTION_ETH_DEBUG,
  469. PISTACHIO_FUNCTION_USB_DEBUG,
  470. PISTACHIO_FUNCTION_SDHOST_DEBUG,
  471. PISTACHIO_FUNCTION_SOCIF_DEBUG,
  472. PISTACHIO_FUNCTION_MDC_DEBUG,
  473. PISTACHIO_FUNCTION_DDR_DEBUG,
  474. PISTACHIO_FUNCTION_DREQ0,
  475. PISTACHIO_FUNCTION_DREQ1,
  476. PISTACHIO_FUNCTION_DREQ2,
  477. PISTACHIO_FUNCTION_DREQ3,
  478. PISTACHIO_FUNCTION_DREQ4,
  479. PISTACHIO_FUNCTION_DREQ5,
  480. PISTACHIO_FUNCTION_MIPS_PLL_LOCK,
  481. PISTACHIO_FUNCTION_AUDIO_PLL_LOCK,
  482. PISTACHIO_FUNCTION_RPU_V_PLL_LOCK,
  483. PISTACHIO_FUNCTION_RPU_L_PLL_LOCK,
  484. PISTACHIO_FUNCTION_SYS_PLL_LOCK,
  485. PISTACHIO_FUNCTION_WIFI_PLL_LOCK,
  486. PISTACHIO_FUNCTION_BT_PLL_LOCK,
  487. PISTACHIO_FUNCTION_DEBUG_RAW_CCA_IND,
  488. PISTACHIO_FUNCTION_DEBUG_ED_SEC20_CCA_IND,
  489. PISTACHIO_FUNCTION_DEBUG_ED_SEC40_CCA_IND,
  490. PISTACHIO_FUNCTION_DEBUG_AGC_DONE_0,
  491. PISTACHIO_FUNCTION_DEBUG_AGC_DONE_1,
  492. PISTACHIO_FUNCTION_DEBUG_ED_CCA_IND,
  493. PISTACHIO_FUNCTION_DEBUG_S2L_DONE,
  494. };
  495. static const struct pistachio_function pistachio_functions[] = {
  496. FUNCTION(spim0),
  497. FUNCTION(spim1),
  498. FUNCTION(spis),
  499. FUNCTION(sdhost),
  500. FUNCTION(i2c0),
  501. FUNCTION(i2c1),
  502. FUNCTION(i2c2),
  503. FUNCTION(i2c3),
  504. FUNCTION(audio_clk_in),
  505. FUNCTION(i2s_out),
  506. FUNCTION(i2s_dac_clk),
  507. FUNCTION(audio_sync),
  508. FUNCTION(audio_trigger),
  509. FUNCTION(i2s_in),
  510. FUNCTION(uart0),
  511. FUNCTION(uart1),
  512. FUNCTION(spdif_out),
  513. FUNCTION_SCENARIO(spdif_in, PADS_SCENARIO_SELECT, 0, 0x1),
  514. FUNCTION(eth),
  515. FUNCTION(ir),
  516. FUNCTION(pwmpdm),
  517. FUNCTION(mips_trace_clk),
  518. FUNCTION_SCENARIO(mips_trace_dint, PADS_SCENARIO_SELECT, 1, 0x3),
  519. FUNCTION(mips_trace_trigout),
  520. FUNCTION_SCENARIO(mips_trace_trigin, PADS_SCENARIO_SELECT, 3, 0x3),
  521. FUNCTION(mips_trace_dm),
  522. FUNCTION_SCENARIO(mips_probe_n, PADS_SCENARIO_SELECT, 5, 0x3),
  523. FUNCTION(mips_trace_data),
  524. FUNCTION(sram_debug),
  525. FUNCTION(rom_debug),
  526. FUNCTION(rpu_debug),
  527. FUNCTION(mips_debug),
  528. FUNCTION(eth_debug),
  529. FUNCTION(usb_debug),
  530. FUNCTION(sdhost_debug),
  531. FUNCTION(socif_debug),
  532. FUNCTION(mdc_debug),
  533. FUNCTION(ddr_debug),
  534. FUNCTION(dreq0),
  535. FUNCTION(dreq1),
  536. FUNCTION(dreq2),
  537. FUNCTION(dreq3),
  538. FUNCTION(dreq4),
  539. FUNCTION(dreq5),
  540. FUNCTION(mips_pll_lock),
  541. FUNCTION(audio_pll_lock),
  542. FUNCTION(rpu_v_pll_lock),
  543. FUNCTION(rpu_l_pll_lock),
  544. FUNCTION(sys_pll_lock),
  545. FUNCTION(wifi_pll_lock),
  546. FUNCTION(bt_pll_lock),
  547. FUNCTION(debug_raw_cca_ind),
  548. FUNCTION(debug_ed_sec20_cca_ind),
  549. FUNCTION(debug_ed_sec40_cca_ind),
  550. FUNCTION(debug_agc_done_0),
  551. FUNCTION(debug_agc_done_1),
  552. FUNCTION(debug_ed_cca_ind),
  553. FUNCTION(debug_s2l_done),
  554. };
  555. #define PIN_GROUP(_pin, _name) \
  556. { \
  557. .name = #_name, \
  558. .pin = PISTACHIO_PIN_##_pin, \
  559. .mux_option = { \
  560. PISTACHIO_FUNCTION_NONE, \
  561. PISTACHIO_FUNCTION_NONE, \
  562. PISTACHIO_FUNCTION_NONE, \
  563. }, \
  564. .mux_reg = -1, \
  565. .mux_shift = -1, \
  566. .mux_mask = -1, \
  567. }
  568. #define MFIO_PIN_GROUP(_pin, _func) \
  569. { \
  570. .name = "mfio" #_pin, \
  571. .pin = PISTACHIO_PIN_MFIO(_pin), \
  572. .mux_option = { \
  573. PISTACHIO_FUNCTION_##_func, \
  574. PISTACHIO_FUNCTION_NONE, \
  575. PISTACHIO_FUNCTION_NONE, \
  576. }, \
  577. .mux_reg = -1, \
  578. .mux_shift = -1, \
  579. .mux_mask = -1, \
  580. }
  581. #define MFIO_MUX_PIN_GROUP(_pin, _f0, _f1, _f2, _reg, _shift, _mask) \
  582. { \
  583. .name = "mfio" #_pin, \
  584. .pin = PISTACHIO_PIN_MFIO(_pin), \
  585. .mux_option = { \
  586. PISTACHIO_FUNCTION_##_f0, \
  587. PISTACHIO_FUNCTION_##_f1, \
  588. PISTACHIO_FUNCTION_##_f2, \
  589. }, \
  590. .mux_reg = _reg, \
  591. .mux_shift = _shift, \
  592. .mux_mask = _mask, \
  593. }
  594. static const struct pistachio_pin_group pistachio_groups[] = {
  595. MFIO_PIN_GROUP(0, SPIM1),
  596. MFIO_MUX_PIN_GROUP(1, SPIM1, SPIM0, UART1,
  597. PADS_FUNCTION_SELECT0, 0, 0x3),
  598. MFIO_MUX_PIN_GROUP(2, SPIM1, SPIM0, UART1,
  599. PADS_FUNCTION_SELECT0, 2, 0x3),
  600. MFIO_PIN_GROUP(3, SPIM1),
  601. MFIO_PIN_GROUP(4, SPIM1),
  602. MFIO_PIN_GROUP(5, SPIM1),
  603. MFIO_PIN_GROUP(6, SPIM1),
  604. MFIO_PIN_GROUP(7, SPIM1),
  605. MFIO_PIN_GROUP(8, SPIM0),
  606. MFIO_PIN_GROUP(9, SPIM0),
  607. MFIO_PIN_GROUP(10, SPIM0),
  608. MFIO_PIN_GROUP(11, SPIS),
  609. MFIO_PIN_GROUP(12, SPIS),
  610. MFIO_PIN_GROUP(13, SPIS),
  611. MFIO_PIN_GROUP(14, SPIS),
  612. MFIO_MUX_PIN_GROUP(15, SDHOST, MIPS_TRACE_CLK, MIPS_TRACE_DATA,
  613. PADS_FUNCTION_SELECT0, 4, 0x3),
  614. MFIO_MUX_PIN_GROUP(16, SDHOST, MIPS_TRACE_DINT, MIPS_TRACE_DATA,
  615. PADS_FUNCTION_SELECT0, 6, 0x3),
  616. MFIO_MUX_PIN_GROUP(17, SDHOST, MIPS_TRACE_TRIGOUT, MIPS_TRACE_DATA,
  617. PADS_FUNCTION_SELECT0, 8, 0x3),
  618. MFIO_MUX_PIN_GROUP(18, SDHOST, MIPS_TRACE_TRIGIN, MIPS_TRACE_DATA,
  619. PADS_FUNCTION_SELECT0, 10, 0x3),
  620. MFIO_MUX_PIN_GROUP(19, SDHOST, MIPS_TRACE_DM, MIPS_TRACE_DATA,
  621. PADS_FUNCTION_SELECT0, 12, 0x3),
  622. MFIO_MUX_PIN_GROUP(20, SDHOST, MIPS_TRACE_PROBE_N, MIPS_TRACE_DATA,
  623. PADS_FUNCTION_SELECT0, 14, 0x3),
  624. MFIO_MUX_PIN_GROUP(21, SDHOST, NONE, MIPS_TRACE_DATA,
  625. PADS_FUNCTION_SELECT0, 16, 0x3),
  626. MFIO_MUX_PIN_GROUP(22, SDHOST, NONE, MIPS_TRACE_DATA,
  627. PADS_FUNCTION_SELECT0, 18, 0x3),
  628. MFIO_PIN_GROUP(23, SDHOST),
  629. MFIO_PIN_GROUP(24, SDHOST),
  630. MFIO_PIN_GROUP(25, SDHOST),
  631. MFIO_PIN_GROUP(26, SDHOST),
  632. MFIO_PIN_GROUP(27, SDHOST),
  633. MFIO_MUX_PIN_GROUP(28, I2C0, SPIM0, NONE,
  634. PADS_FUNCTION_SELECT0, 20, 0x1),
  635. MFIO_MUX_PIN_GROUP(29, I2C0, SPIM0, NONE,
  636. PADS_FUNCTION_SELECT0, 21, 0x1),
  637. MFIO_MUX_PIN_GROUP(30, I2C1, SPIM0, NONE,
  638. PADS_FUNCTION_SELECT0, 22, 0x1),
  639. MFIO_MUX_PIN_GROUP(31, I2C1, SPIM1, NONE,
  640. PADS_FUNCTION_SELECT0, 23, 0x1),
  641. MFIO_PIN_GROUP(32, I2C2),
  642. MFIO_PIN_GROUP(33, I2C2),
  643. MFIO_PIN_GROUP(34, I2C3),
  644. MFIO_PIN_GROUP(35, I2C3),
  645. MFIO_MUX_PIN_GROUP(36, I2S_OUT, AUDIO_CLK_IN, NONE,
  646. PADS_FUNCTION_SELECT0, 24, 0x1),
  647. MFIO_MUX_PIN_GROUP(37, I2S_OUT, DEBUG_RAW_CCA_IND, NONE,
  648. PADS_FUNCTION_SELECT0, 25, 0x1),
  649. MFIO_MUX_PIN_GROUP(38, I2S_OUT, DEBUG_ED_SEC20_CCA_IND, NONE,
  650. PADS_FUNCTION_SELECT0, 26, 0x1),
  651. MFIO_MUX_PIN_GROUP(39, I2S_OUT, DEBUG_ED_SEC40_CCA_IND, NONE,
  652. PADS_FUNCTION_SELECT0, 27, 0x1),
  653. MFIO_MUX_PIN_GROUP(40, I2S_OUT, DEBUG_AGC_DONE_0, NONE,
  654. PADS_FUNCTION_SELECT0, 28, 0x1),
  655. MFIO_MUX_PIN_GROUP(41, I2S_OUT, DEBUG_AGC_DONE_1, NONE,
  656. PADS_FUNCTION_SELECT0, 29, 0x1),
  657. MFIO_MUX_PIN_GROUP(42, I2S_OUT, DEBUG_ED_CCA_IND, NONE,
  658. PADS_FUNCTION_SELECT0, 30, 0x1),
  659. MFIO_MUX_PIN_GROUP(43, I2S_OUT, DEBUG_S2L_DONE, NONE,
  660. PADS_FUNCTION_SELECT0, 31, 0x1),
  661. MFIO_PIN_GROUP(44, I2S_OUT),
  662. MFIO_MUX_PIN_GROUP(45, I2S_DAC_CLK, AUDIO_SYNC, NONE,
  663. PADS_FUNCTION_SELECT1, 0, 0x1),
  664. MFIO_PIN_GROUP(46, AUDIO_TRIGGER),
  665. MFIO_PIN_GROUP(47, I2S_IN),
  666. MFIO_PIN_GROUP(48, I2S_IN),
  667. MFIO_PIN_GROUP(49, I2S_IN),
  668. MFIO_PIN_GROUP(50, I2S_IN),
  669. MFIO_PIN_GROUP(51, I2S_IN),
  670. MFIO_PIN_GROUP(52, I2S_IN),
  671. MFIO_PIN_GROUP(53, I2S_IN),
  672. MFIO_MUX_PIN_GROUP(54, I2S_IN, NONE, SPDIF_IN,
  673. PADS_FUNCTION_SELECT1, 1, 0x3),
  674. MFIO_MUX_PIN_GROUP(55, UART0, SPIM0, SPIM1,
  675. PADS_FUNCTION_SELECT1, 3, 0x3),
  676. MFIO_MUX_PIN_GROUP(56, UART0, SPIM0, SPIM1,
  677. PADS_FUNCTION_SELECT1, 5, 0x3),
  678. MFIO_MUX_PIN_GROUP(57, UART0, SPIM0, SPIM1,
  679. PADS_FUNCTION_SELECT1, 7, 0x3),
  680. MFIO_MUX_PIN_GROUP(58, UART0, SPIM1, NONE,
  681. PADS_FUNCTION_SELECT1, 9, 0x1),
  682. MFIO_PIN_GROUP(59, UART1),
  683. MFIO_PIN_GROUP(60, UART1),
  684. MFIO_PIN_GROUP(61, SPDIF_OUT),
  685. MFIO_PIN_GROUP(62, SPDIF_IN),
  686. MFIO_MUX_PIN_GROUP(63, ETH, MIPS_TRACE_CLK, MIPS_TRACE_DATA,
  687. PADS_FUNCTION_SELECT1, 10, 0x3),
  688. MFIO_MUX_PIN_GROUP(64, ETH, MIPS_TRACE_DINT, MIPS_TRACE_DATA,
  689. PADS_FUNCTION_SELECT1, 12, 0x3),
  690. MFIO_MUX_PIN_GROUP(65, ETH, MIPS_TRACE_TRIGOUT, MIPS_TRACE_DATA,
  691. PADS_FUNCTION_SELECT1, 14, 0x3),
  692. MFIO_MUX_PIN_GROUP(66, ETH, MIPS_TRACE_TRIGIN, MIPS_TRACE_DATA,
  693. PADS_FUNCTION_SELECT1, 16, 0x3),
  694. MFIO_MUX_PIN_GROUP(67, ETH, MIPS_TRACE_DM, MIPS_TRACE_DATA,
  695. PADS_FUNCTION_SELECT1, 18, 0x3),
  696. MFIO_MUX_PIN_GROUP(68, ETH, MIPS_TRACE_PROBE_N, MIPS_TRACE_DATA,
  697. PADS_FUNCTION_SELECT1, 20, 0x3),
  698. MFIO_MUX_PIN_GROUP(69, ETH, NONE, MIPS_TRACE_DATA,
  699. PADS_FUNCTION_SELECT1, 22, 0x3),
  700. MFIO_MUX_PIN_GROUP(70, ETH, NONE, MIPS_TRACE_DATA,
  701. PADS_FUNCTION_SELECT1, 24, 0x3),
  702. MFIO_PIN_GROUP(71, ETH),
  703. MFIO_PIN_GROUP(72, IR),
  704. MFIO_MUX_PIN_GROUP(73, PWMPDM, MIPS_TRACE_CLK, SRAM_DEBUG,
  705. PADS_FUNCTION_SELECT1, 26, 0x3),
  706. MFIO_MUX_PIN_GROUP(74, PWMPDM, MIPS_TRACE_DINT, SRAM_DEBUG,
  707. PADS_FUNCTION_SELECT1, 28, 0x3),
  708. MFIO_MUX_PIN_GROUP(75, PWMPDM, MIPS_TRACE_TRIGOUT, ROM_DEBUG,
  709. PADS_FUNCTION_SELECT1, 30, 0x3),
  710. MFIO_MUX_PIN_GROUP(76, PWMPDM, MIPS_TRACE_TRIGIN, ROM_DEBUG,
  711. PADS_FUNCTION_SELECT2, 0, 0x3),
  712. MFIO_MUX_PIN_GROUP(77, MDC_DEBUG, MIPS_TRACE_DM, RPU_DEBUG,
  713. PADS_FUNCTION_SELECT2, 2, 0x3),
  714. MFIO_MUX_PIN_GROUP(78, MDC_DEBUG, MIPS_TRACE_PROBE_N, RPU_DEBUG,
  715. PADS_FUNCTION_SELECT2, 4, 0x3),
  716. MFIO_MUX_PIN_GROUP(79, DDR_DEBUG, MIPS_TRACE_DATA, MIPS_DEBUG,
  717. PADS_FUNCTION_SELECT2, 6, 0x3),
  718. MFIO_MUX_PIN_GROUP(80, DDR_DEBUG, MIPS_TRACE_DATA, MIPS_DEBUG,
  719. PADS_FUNCTION_SELECT2, 8, 0x3),
  720. MFIO_MUX_PIN_GROUP(81, DREQ0, MIPS_TRACE_DATA, ETH_DEBUG,
  721. PADS_FUNCTION_SELECT2, 10, 0x3),
  722. MFIO_MUX_PIN_GROUP(82, DREQ1, MIPS_TRACE_DATA, ETH_DEBUG,
  723. PADS_FUNCTION_SELECT2, 12, 0x3),
  724. MFIO_MUX_PIN_GROUP(83, MIPS_PLL_LOCK, MIPS_TRACE_DATA, USB_DEBUG,
  725. PADS_FUNCTION_SELECT2, 14, 0x3),
  726. MFIO_MUX_PIN_GROUP(84, AUDIO_PLL_LOCK, MIPS_TRACE_DATA, USB_DEBUG,
  727. PADS_FUNCTION_SELECT2, 16, 0x3),
  728. MFIO_MUX_PIN_GROUP(85, RPU_V_PLL_LOCK, MIPS_TRACE_DATA, SDHOST_DEBUG,
  729. PADS_FUNCTION_SELECT2, 18, 0x3),
  730. MFIO_MUX_PIN_GROUP(86, RPU_L_PLL_LOCK, MIPS_TRACE_DATA, SDHOST_DEBUG,
  731. PADS_FUNCTION_SELECT2, 20, 0x3),
  732. MFIO_MUX_PIN_GROUP(87, SYS_PLL_LOCK, DREQ2, SOCIF_DEBUG,
  733. PADS_FUNCTION_SELECT2, 22, 0x3),
  734. MFIO_MUX_PIN_GROUP(88, WIFI_PLL_LOCK, DREQ3, SOCIF_DEBUG,
  735. PADS_FUNCTION_SELECT2, 24, 0x3),
  736. MFIO_MUX_PIN_GROUP(89, BT_PLL_LOCK, DREQ4, DREQ5,
  737. PADS_FUNCTION_SELECT2, 26, 0x3),
  738. PIN_GROUP(TCK, "tck"),
  739. PIN_GROUP(TRSTN, "trstn"),
  740. PIN_GROUP(TDI, "tdi"),
  741. PIN_GROUP(TMS, "tms"),
  742. PIN_GROUP(TDO, "tdo"),
  743. PIN_GROUP(JTAG_COMPLY, "jtag_comply"),
  744. PIN_GROUP(SAFE_MODE, "safe_mode"),
  745. PIN_GROUP(POR_DISABLE, "por_disable"),
  746. PIN_GROUP(RESETN, "resetn"),
  747. };
  748. static inline u32 pctl_readl(struct pistachio_pinctrl *pctl, u32 reg)
  749. {
  750. return readl(pctl->base + reg);
  751. }
  752. static inline void pctl_writel(struct pistachio_pinctrl *pctl, u32 val, u32 reg)
  753. {
  754. writel(val, pctl->base + reg);
  755. }
  756. static inline struct pistachio_gpio_bank *irqd_to_bank(struct irq_data *d)
  757. {
  758. return gpiochip_get_data(irq_data_get_irq_chip_data(d));
  759. }
  760. static inline u32 gpio_readl(struct pistachio_gpio_bank *bank, u32 reg)
  761. {
  762. return readl(bank->base + reg);
  763. }
  764. static inline void gpio_writel(struct pistachio_gpio_bank *bank, u32 val,
  765. u32 reg)
  766. {
  767. writel(val, bank->base + reg);
  768. }
  769. static inline void gpio_mask_writel(struct pistachio_gpio_bank *bank,
  770. u32 reg, unsigned int bit, u32 val)
  771. {
  772. /*
  773. * For most of the GPIO registers, bit 16 + X must be set in order to
  774. * write bit X.
  775. */
  776. gpio_writel(bank, (0x10000 | val) << bit, reg);
  777. }
  778. static inline void gpio_enable(struct pistachio_gpio_bank *bank,
  779. unsigned offset)
  780. {
  781. gpio_mask_writel(bank, GPIO_BIT_EN, offset, 1);
  782. }
  783. static inline void gpio_disable(struct pistachio_gpio_bank *bank,
  784. unsigned offset)
  785. {
  786. gpio_mask_writel(bank, GPIO_BIT_EN, offset, 0);
  787. }
  788. static int pistachio_pinctrl_get_groups_count(struct pinctrl_dev *pctldev)
  789. {
  790. struct pistachio_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
  791. return pctl->ngroups;
  792. }
  793. static const char *pistachio_pinctrl_get_group_name(struct pinctrl_dev *pctldev,
  794. unsigned group)
  795. {
  796. struct pistachio_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
  797. return pctl->groups[group].name;
  798. }
  799. static int pistachio_pinctrl_get_group_pins(struct pinctrl_dev *pctldev,
  800. unsigned group,
  801. const unsigned **pins,
  802. unsigned *num_pins)
  803. {
  804. struct pistachio_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
  805. *pins = &pctl->groups[group].pin;
  806. *num_pins = 1;
  807. return 0;
  808. }
  809. static const struct pinctrl_ops pistachio_pinctrl_ops = {
  810. .get_groups_count = pistachio_pinctrl_get_groups_count,
  811. .get_group_name = pistachio_pinctrl_get_group_name,
  812. .get_group_pins = pistachio_pinctrl_get_group_pins,
  813. .dt_node_to_map = pinconf_generic_dt_node_to_map_pin,
  814. .dt_free_map = pinctrl_utils_free_map,
  815. };
  816. static int pistachio_pinmux_get_functions_count(struct pinctrl_dev *pctldev)
  817. {
  818. struct pistachio_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
  819. return pctl->nfunctions;
  820. }
  821. static const char *
  822. pistachio_pinmux_get_function_name(struct pinctrl_dev *pctldev, unsigned func)
  823. {
  824. struct pistachio_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
  825. return pctl->functions[func].name;
  826. }
  827. static int pistachio_pinmux_get_function_groups(struct pinctrl_dev *pctldev,
  828. unsigned func,
  829. const char * const **groups,
  830. unsigned * const num_groups)
  831. {
  832. struct pistachio_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
  833. *groups = pctl->functions[func].groups;
  834. *num_groups = pctl->functions[func].ngroups;
  835. return 0;
  836. }
  837. static int pistachio_pinmux_enable(struct pinctrl_dev *pctldev,
  838. unsigned func, unsigned group)
  839. {
  840. struct pistachio_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
  841. const struct pistachio_pin_group *pg = &pctl->groups[group];
  842. const struct pistachio_function *pf = &pctl->functions[func];
  843. struct pinctrl_gpio_range *range;
  844. unsigned int i;
  845. u32 val;
  846. if (pg->mux_reg > 0) {
  847. for (i = 0; i < ARRAY_SIZE(pg->mux_option); i++) {
  848. if (pg->mux_option[i] == func)
  849. break;
  850. }
  851. if (i == ARRAY_SIZE(pg->mux_option)) {
  852. dev_err(pctl->dev, "Cannot mux pin %u to function %u\n",
  853. group, func);
  854. return -EINVAL;
  855. }
  856. val = pctl_readl(pctl, pg->mux_reg);
  857. val &= ~(pg->mux_mask << pg->mux_shift);
  858. val |= i << pg->mux_shift;
  859. pctl_writel(pctl, val, pg->mux_reg);
  860. if (pf->scenarios) {
  861. for (i = 0; i < pf->nscenarios; i++) {
  862. if (pf->scenarios[i] == group)
  863. break;
  864. }
  865. if (WARN_ON(i == pf->nscenarios))
  866. return -EINVAL;
  867. val = pctl_readl(pctl, pf->scenario_reg);
  868. val &= ~(pf->scenario_mask << pf->scenario_shift);
  869. val |= i << pf->scenario_shift;
  870. pctl_writel(pctl, val, pf->scenario_reg);
  871. }
  872. }
  873. range = pinctrl_find_gpio_range_from_pin(pctl->pctldev, pg->pin);
  874. if (range)
  875. gpio_disable(gpiochip_get_data(range->gc), pg->pin - range->pin_base);
  876. return 0;
  877. }
  878. static const struct pinmux_ops pistachio_pinmux_ops = {
  879. .get_functions_count = pistachio_pinmux_get_functions_count,
  880. .get_function_name = pistachio_pinmux_get_function_name,
  881. .get_function_groups = pistachio_pinmux_get_function_groups,
  882. .set_mux = pistachio_pinmux_enable,
  883. };
  884. static int pistachio_pinconf_get(struct pinctrl_dev *pctldev, unsigned pin,
  885. unsigned long *config)
  886. {
  887. struct pistachio_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
  888. enum pin_config_param param = pinconf_to_config_param(*config);
  889. u32 val, arg;
  890. switch (param) {
  891. case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
  892. val = pctl_readl(pctl, PADS_SCHMITT_EN_REG(pin));
  893. arg = !!(val & PADS_SCHMITT_EN_BIT(pin));
  894. break;
  895. case PIN_CONFIG_BIAS_HIGH_IMPEDANCE:
  896. val = pctl_readl(pctl, PADS_PU_PD_REG(pin)) >>
  897. PADS_PU_PD_SHIFT(pin);
  898. arg = (val & PADS_PU_PD_MASK) == PADS_PU_PD_HIGHZ;
  899. break;
  900. case PIN_CONFIG_BIAS_PULL_UP:
  901. val = pctl_readl(pctl, PADS_PU_PD_REG(pin)) >>
  902. PADS_PU_PD_SHIFT(pin);
  903. arg = (val & PADS_PU_PD_MASK) == PADS_PU_PD_UP;
  904. break;
  905. case PIN_CONFIG_BIAS_PULL_DOWN:
  906. val = pctl_readl(pctl, PADS_PU_PD_REG(pin)) >>
  907. PADS_PU_PD_SHIFT(pin);
  908. arg = (val & PADS_PU_PD_MASK) == PADS_PU_PD_DOWN;
  909. break;
  910. case PIN_CONFIG_BIAS_BUS_HOLD:
  911. val = pctl_readl(pctl, PADS_PU_PD_REG(pin)) >>
  912. PADS_PU_PD_SHIFT(pin);
  913. arg = (val & PADS_PU_PD_MASK) == PADS_PU_PD_BUS;
  914. break;
  915. case PIN_CONFIG_SLEW_RATE:
  916. val = pctl_readl(pctl, PADS_SLEW_RATE_REG(pin));
  917. arg = !!(val & PADS_SLEW_RATE_BIT(pin));
  918. break;
  919. case PIN_CONFIG_DRIVE_STRENGTH:
  920. val = pctl_readl(pctl, PADS_DRIVE_STRENGTH_REG(pin)) >>
  921. PADS_DRIVE_STRENGTH_SHIFT(pin);
  922. switch (val & PADS_DRIVE_STRENGTH_MASK) {
  923. case PADS_DRIVE_STRENGTH_2MA:
  924. arg = 2;
  925. break;
  926. case PADS_DRIVE_STRENGTH_4MA:
  927. arg = 4;
  928. break;
  929. case PADS_DRIVE_STRENGTH_8MA:
  930. arg = 8;
  931. break;
  932. case PADS_DRIVE_STRENGTH_12MA:
  933. default:
  934. arg = 12;
  935. break;
  936. }
  937. break;
  938. default:
  939. dev_dbg(pctl->dev, "Property %u not supported\n", param);
  940. return -ENOTSUPP;
  941. }
  942. *config = pinconf_to_config_packed(param, arg);
  943. return 0;
  944. }
  945. static int pistachio_pinconf_set(struct pinctrl_dev *pctldev, unsigned pin,
  946. unsigned long *configs, unsigned num_configs)
  947. {
  948. struct pistachio_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
  949. enum pin_config_param param;
  950. u32 drv, val, arg;
  951. unsigned int i;
  952. for (i = 0; i < num_configs; i++) {
  953. param = pinconf_to_config_param(configs[i]);
  954. arg = pinconf_to_config_argument(configs[i]);
  955. switch (param) {
  956. case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
  957. val = pctl_readl(pctl, PADS_SCHMITT_EN_REG(pin));
  958. if (arg)
  959. val |= PADS_SCHMITT_EN_BIT(pin);
  960. else
  961. val &= ~PADS_SCHMITT_EN_BIT(pin);
  962. pctl_writel(pctl, val, PADS_SCHMITT_EN_REG(pin));
  963. break;
  964. case PIN_CONFIG_BIAS_HIGH_IMPEDANCE:
  965. val = pctl_readl(pctl, PADS_PU_PD_REG(pin));
  966. val &= ~(PADS_PU_PD_MASK << PADS_PU_PD_SHIFT(pin));
  967. val |= PADS_PU_PD_HIGHZ << PADS_PU_PD_SHIFT(pin);
  968. pctl_writel(pctl, val, PADS_PU_PD_REG(pin));
  969. break;
  970. case PIN_CONFIG_BIAS_PULL_UP:
  971. val = pctl_readl(pctl, PADS_PU_PD_REG(pin));
  972. val &= ~(PADS_PU_PD_MASK << PADS_PU_PD_SHIFT(pin));
  973. val |= PADS_PU_PD_UP << PADS_PU_PD_SHIFT(pin);
  974. pctl_writel(pctl, val, PADS_PU_PD_REG(pin));
  975. break;
  976. case PIN_CONFIG_BIAS_PULL_DOWN:
  977. val = pctl_readl(pctl, PADS_PU_PD_REG(pin));
  978. val &= ~(PADS_PU_PD_MASK << PADS_PU_PD_SHIFT(pin));
  979. val |= PADS_PU_PD_DOWN << PADS_PU_PD_SHIFT(pin);
  980. pctl_writel(pctl, val, PADS_PU_PD_REG(pin));
  981. break;
  982. case PIN_CONFIG_BIAS_BUS_HOLD:
  983. val = pctl_readl(pctl, PADS_PU_PD_REG(pin));
  984. val &= ~(PADS_PU_PD_MASK << PADS_PU_PD_SHIFT(pin));
  985. val |= PADS_PU_PD_BUS << PADS_PU_PD_SHIFT(pin);
  986. pctl_writel(pctl, val, PADS_PU_PD_REG(pin));
  987. break;
  988. case PIN_CONFIG_SLEW_RATE:
  989. val = pctl_readl(pctl, PADS_SLEW_RATE_REG(pin));
  990. if (arg)
  991. val |= PADS_SLEW_RATE_BIT(pin);
  992. else
  993. val &= ~PADS_SLEW_RATE_BIT(pin);
  994. pctl_writel(pctl, val, PADS_SLEW_RATE_REG(pin));
  995. break;
  996. case PIN_CONFIG_DRIVE_STRENGTH:
  997. val = pctl_readl(pctl, PADS_DRIVE_STRENGTH_REG(pin));
  998. val &= ~(PADS_DRIVE_STRENGTH_MASK <<
  999. PADS_DRIVE_STRENGTH_SHIFT(pin));
  1000. switch (arg) {
  1001. case 2:
  1002. drv = PADS_DRIVE_STRENGTH_2MA;
  1003. break;
  1004. case 4:
  1005. drv = PADS_DRIVE_STRENGTH_4MA;
  1006. break;
  1007. case 8:
  1008. drv = PADS_DRIVE_STRENGTH_8MA;
  1009. break;
  1010. case 12:
  1011. drv = PADS_DRIVE_STRENGTH_12MA;
  1012. break;
  1013. default:
  1014. dev_err(pctl->dev,
  1015. "Drive strength %umA not supported\n",
  1016. arg);
  1017. return -EINVAL;
  1018. }
  1019. val |= drv << PADS_DRIVE_STRENGTH_SHIFT(pin);
  1020. pctl_writel(pctl, val, PADS_DRIVE_STRENGTH_REG(pin));
  1021. break;
  1022. default:
  1023. dev_err(pctl->dev, "Property %u not supported\n",
  1024. param);
  1025. return -ENOTSUPP;
  1026. }
  1027. }
  1028. return 0;
  1029. }
  1030. static const struct pinconf_ops pistachio_pinconf_ops = {
  1031. .pin_config_get = pistachio_pinconf_get,
  1032. .pin_config_set = pistachio_pinconf_set,
  1033. .is_generic = true,
  1034. };
  1035. static struct pinctrl_desc pistachio_pinctrl_desc = {
  1036. .name = "pistachio-pinctrl",
  1037. .pctlops = &pistachio_pinctrl_ops,
  1038. .pmxops = &pistachio_pinmux_ops,
  1039. .confops = &pistachio_pinconf_ops,
  1040. };
  1041. static int pistachio_gpio_get_direction(struct gpio_chip *chip, unsigned offset)
  1042. {
  1043. struct pistachio_gpio_bank *bank = gpiochip_get_data(chip);
  1044. if (gpio_readl(bank, GPIO_OUTPUT_EN) & BIT(offset))
  1045. return GPIO_LINE_DIRECTION_OUT;
  1046. return GPIO_LINE_DIRECTION_IN;
  1047. }
  1048. static int pistachio_gpio_get(struct gpio_chip *chip, unsigned offset)
  1049. {
  1050. struct pistachio_gpio_bank *bank = gpiochip_get_data(chip);
  1051. u32 reg;
  1052. if (gpio_readl(bank, GPIO_OUTPUT_EN) & BIT(offset))
  1053. reg = GPIO_OUTPUT;
  1054. else
  1055. reg = GPIO_INPUT;
  1056. return !!(gpio_readl(bank, reg) & BIT(offset));
  1057. }
  1058. static void pistachio_gpio_set(struct gpio_chip *chip, unsigned offset,
  1059. int value)
  1060. {
  1061. struct pistachio_gpio_bank *bank = gpiochip_get_data(chip);
  1062. gpio_mask_writel(bank, GPIO_OUTPUT, offset, !!value);
  1063. }
  1064. static int pistachio_gpio_direction_input(struct gpio_chip *chip,
  1065. unsigned offset)
  1066. {
  1067. struct pistachio_gpio_bank *bank = gpiochip_get_data(chip);
  1068. gpio_mask_writel(bank, GPIO_OUTPUT_EN, offset, 0);
  1069. gpio_enable(bank, offset);
  1070. return 0;
  1071. }
  1072. static int pistachio_gpio_direction_output(struct gpio_chip *chip,
  1073. unsigned offset, int value)
  1074. {
  1075. struct pistachio_gpio_bank *bank = gpiochip_get_data(chip);
  1076. pistachio_gpio_set(chip, offset, value);
  1077. gpio_mask_writel(bank, GPIO_OUTPUT_EN, offset, 1);
  1078. gpio_enable(bank, offset);
  1079. return 0;
  1080. }
  1081. static void pistachio_gpio_irq_ack(struct irq_data *data)
  1082. {
  1083. struct pistachio_gpio_bank *bank = irqd_to_bank(data);
  1084. gpio_mask_writel(bank, GPIO_INTERRUPT_STATUS, data->hwirq, 0);
  1085. }
  1086. static void pistachio_gpio_irq_mask(struct irq_data *data)
  1087. {
  1088. struct pistachio_gpio_bank *bank = irqd_to_bank(data);
  1089. gpio_mask_writel(bank, GPIO_INTERRUPT_EN, data->hwirq, 0);
  1090. }
  1091. static void pistachio_gpio_irq_unmask(struct irq_data *data)
  1092. {
  1093. struct pistachio_gpio_bank *bank = irqd_to_bank(data);
  1094. gpio_mask_writel(bank, GPIO_INTERRUPT_EN, data->hwirq, 1);
  1095. }
  1096. static unsigned int pistachio_gpio_irq_startup(struct irq_data *data)
  1097. {
  1098. struct gpio_chip *chip = irq_data_get_irq_chip_data(data);
  1099. pistachio_gpio_direction_input(chip, data->hwirq);
  1100. pistachio_gpio_irq_unmask(data);
  1101. return 0;
  1102. }
  1103. static int pistachio_gpio_irq_set_type(struct irq_data *data, unsigned int type)
  1104. {
  1105. struct pistachio_gpio_bank *bank = irqd_to_bank(data);
  1106. switch (type & IRQ_TYPE_SENSE_MASK) {
  1107. case IRQ_TYPE_EDGE_RISING:
  1108. gpio_mask_writel(bank, GPIO_INPUT_POLARITY, data->hwirq, 1);
  1109. gpio_mask_writel(bank, GPIO_INTERRUPT_TYPE, data->hwirq,
  1110. GPIO_INTERRUPT_TYPE_EDGE);
  1111. gpio_mask_writel(bank, GPIO_INTERRUPT_EDGE, data->hwirq,
  1112. GPIO_INTERRUPT_EDGE_SINGLE);
  1113. break;
  1114. case IRQ_TYPE_EDGE_FALLING:
  1115. gpio_mask_writel(bank, GPIO_INPUT_POLARITY, data->hwirq, 0);
  1116. gpio_mask_writel(bank, GPIO_INTERRUPT_TYPE, data->hwirq,
  1117. GPIO_INTERRUPT_TYPE_EDGE);
  1118. gpio_mask_writel(bank, GPIO_INTERRUPT_EDGE, data->hwirq,
  1119. GPIO_INTERRUPT_EDGE_SINGLE);
  1120. break;
  1121. case IRQ_TYPE_EDGE_BOTH:
  1122. gpio_mask_writel(bank, GPIO_INTERRUPT_TYPE, data->hwirq,
  1123. GPIO_INTERRUPT_TYPE_EDGE);
  1124. gpio_mask_writel(bank, GPIO_INTERRUPT_EDGE, data->hwirq,
  1125. GPIO_INTERRUPT_EDGE_DUAL);
  1126. break;
  1127. case IRQ_TYPE_LEVEL_HIGH:
  1128. gpio_mask_writel(bank, GPIO_INPUT_POLARITY, data->hwirq, 1);
  1129. gpio_mask_writel(bank, GPIO_INTERRUPT_TYPE, data->hwirq,
  1130. GPIO_INTERRUPT_TYPE_LEVEL);
  1131. break;
  1132. case IRQ_TYPE_LEVEL_LOW:
  1133. gpio_mask_writel(bank, GPIO_INPUT_POLARITY, data->hwirq, 0);
  1134. gpio_mask_writel(bank, GPIO_INTERRUPT_TYPE, data->hwirq,
  1135. GPIO_INTERRUPT_TYPE_LEVEL);
  1136. break;
  1137. default:
  1138. return -EINVAL;
  1139. }
  1140. if (type & IRQ_TYPE_LEVEL_MASK)
  1141. irq_set_handler_locked(data, handle_level_irq);
  1142. else
  1143. irq_set_handler_locked(data, handle_edge_irq);
  1144. return 0;
  1145. }
  1146. static void pistachio_gpio_irq_handler(struct irq_desc *desc)
  1147. {
  1148. struct gpio_chip *gc = irq_desc_get_handler_data(desc);
  1149. struct pistachio_gpio_bank *bank = gpiochip_get_data(gc);
  1150. struct irq_chip *chip = irq_desc_get_chip(desc);
  1151. unsigned long pending;
  1152. unsigned int pin;
  1153. chained_irq_enter(chip, desc);
  1154. pending = gpio_readl(bank, GPIO_INTERRUPT_STATUS) &
  1155. gpio_readl(bank, GPIO_INTERRUPT_EN);
  1156. for_each_set_bit(pin, &pending, 16)
  1157. generic_handle_domain_irq(gc->irq.domain, pin);
  1158. chained_irq_exit(chip, desc);
  1159. }
  1160. #define GPIO_BANK(_bank, _pin_base, _npins) \
  1161. { \
  1162. .pin_base = _pin_base, \
  1163. .npins = _npins, \
  1164. .gpio_chip = { \
  1165. .label = "GPIO" #_bank, \
  1166. .request = gpiochip_generic_request, \
  1167. .free = gpiochip_generic_free, \
  1168. .get_direction = pistachio_gpio_get_direction, \
  1169. .direction_input = pistachio_gpio_direction_input, \
  1170. .direction_output = pistachio_gpio_direction_output, \
  1171. .get = pistachio_gpio_get, \
  1172. .set = pistachio_gpio_set, \
  1173. .base = _pin_base, \
  1174. .ngpio = _npins, \
  1175. }, \
  1176. .irq_chip = { \
  1177. .name = "GPIO" #_bank, \
  1178. .irq_startup = pistachio_gpio_irq_startup, \
  1179. .irq_ack = pistachio_gpio_irq_ack, \
  1180. .irq_mask = pistachio_gpio_irq_mask, \
  1181. .irq_unmask = pistachio_gpio_irq_unmask, \
  1182. .irq_set_type = pistachio_gpio_irq_set_type, \
  1183. }, \
  1184. }
  1185. static struct pistachio_gpio_bank pistachio_gpio_banks[] = {
  1186. GPIO_BANK(0, PISTACHIO_PIN_MFIO(0), 16),
  1187. GPIO_BANK(1, PISTACHIO_PIN_MFIO(16), 16),
  1188. GPIO_BANK(2, PISTACHIO_PIN_MFIO(32), 16),
  1189. GPIO_BANK(3, PISTACHIO_PIN_MFIO(48), 16),
  1190. GPIO_BANK(4, PISTACHIO_PIN_MFIO(64), 16),
  1191. GPIO_BANK(5, PISTACHIO_PIN_MFIO(80), 10),
  1192. };
  1193. static int pistachio_gpio_register(struct pistachio_pinctrl *pctl)
  1194. {
  1195. struct pistachio_gpio_bank *bank;
  1196. unsigned int i;
  1197. int irq, ret = 0;
  1198. for (i = 0; i < pctl->nbanks; i++) {
  1199. char child_name[sizeof("gpioXX")];
  1200. struct fwnode_handle *child;
  1201. struct gpio_irq_chip *girq;
  1202. snprintf(child_name, sizeof(child_name), "gpio%d", i);
  1203. child = device_get_named_child_node(pctl->dev, child_name);
  1204. if (!child) {
  1205. dev_err(pctl->dev, "No node for bank %u\n", i);
  1206. ret = -ENODEV;
  1207. goto err;
  1208. }
  1209. if (!fwnode_property_present(child, "gpio-controller")) {
  1210. fwnode_handle_put(child);
  1211. dev_err(pctl->dev,
  1212. "No gpio-controller property for bank %u\n", i);
  1213. ret = -ENODEV;
  1214. goto err;
  1215. }
  1216. ret = fwnode_irq_get(child, 0);
  1217. if (ret < 0) {
  1218. fwnode_handle_put(child);
  1219. dev_err(pctl->dev, "Failed to retrieve IRQ for bank %u\n", i);
  1220. goto err;
  1221. }
  1222. if (!ret) {
  1223. fwnode_handle_put(child);
  1224. dev_err(pctl->dev, "No IRQ for bank %u\n", i);
  1225. ret = -EINVAL;
  1226. goto err;
  1227. }
  1228. irq = ret;
  1229. bank = &pctl->gpio_banks[i];
  1230. bank->pctl = pctl;
  1231. bank->base = pctl->base + GPIO_BANK_BASE(i);
  1232. bank->gpio_chip.parent = pctl->dev;
  1233. bank->gpio_chip.fwnode = child;
  1234. girq = &bank->gpio_chip.irq;
  1235. girq->chip = &bank->irq_chip;
  1236. girq->parent_handler = pistachio_gpio_irq_handler;
  1237. girq->num_parents = 1;
  1238. girq->parents = devm_kcalloc(pctl->dev, 1,
  1239. sizeof(*girq->parents),
  1240. GFP_KERNEL);
  1241. if (!girq->parents) {
  1242. ret = -ENOMEM;
  1243. goto err;
  1244. }
  1245. girq->parents[0] = irq;
  1246. girq->default_type = IRQ_TYPE_NONE;
  1247. girq->handler = handle_level_irq;
  1248. ret = gpiochip_add_data(&bank->gpio_chip, bank);
  1249. if (ret < 0) {
  1250. dev_err(pctl->dev, "Failed to add GPIO chip %u: %d\n",
  1251. i, ret);
  1252. goto err;
  1253. }
  1254. ret = gpiochip_add_pin_range(&bank->gpio_chip,
  1255. dev_name(pctl->dev), 0,
  1256. bank->pin_base, bank->npins);
  1257. if (ret < 0) {
  1258. dev_err(pctl->dev, "Failed to add GPIO range %u: %d\n",
  1259. i, ret);
  1260. gpiochip_remove(&bank->gpio_chip);
  1261. goto err;
  1262. }
  1263. }
  1264. return 0;
  1265. err:
  1266. for (; i > 0; i--) {
  1267. bank = &pctl->gpio_banks[i - 1];
  1268. gpiochip_remove(&bank->gpio_chip);
  1269. }
  1270. return ret;
  1271. }
  1272. static const struct of_device_id pistachio_pinctrl_of_match[] = {
  1273. { .compatible = "img,pistachio-system-pinctrl", },
  1274. { },
  1275. };
  1276. static int pistachio_pinctrl_probe(struct platform_device *pdev)
  1277. {
  1278. struct pistachio_pinctrl *pctl;
  1279. pctl = devm_kzalloc(&pdev->dev, sizeof(*pctl), GFP_KERNEL);
  1280. if (!pctl)
  1281. return -ENOMEM;
  1282. pctl->dev = &pdev->dev;
  1283. dev_set_drvdata(&pdev->dev, pctl);
  1284. pctl->base = devm_platform_ioremap_resource(pdev, 0);
  1285. if (IS_ERR(pctl->base))
  1286. return PTR_ERR(pctl->base);
  1287. pctl->pins = pistachio_pins;
  1288. pctl->npins = ARRAY_SIZE(pistachio_pins);
  1289. pctl->functions = pistachio_functions;
  1290. pctl->nfunctions = ARRAY_SIZE(pistachio_functions);
  1291. pctl->groups = pistachio_groups;
  1292. pctl->ngroups = ARRAY_SIZE(pistachio_groups);
  1293. pctl->gpio_banks = pistachio_gpio_banks;
  1294. pctl->nbanks = ARRAY_SIZE(pistachio_gpio_banks);
  1295. pistachio_pinctrl_desc.pins = pctl->pins;
  1296. pistachio_pinctrl_desc.npins = pctl->npins;
  1297. pctl->pctldev = devm_pinctrl_register(&pdev->dev, &pistachio_pinctrl_desc,
  1298. pctl);
  1299. if (IS_ERR(pctl->pctldev)) {
  1300. dev_err(&pdev->dev, "Failed to register pinctrl device\n");
  1301. return PTR_ERR(pctl->pctldev);
  1302. }
  1303. return pistachio_gpio_register(pctl);
  1304. }
  1305. static struct platform_driver pistachio_pinctrl_driver = {
  1306. .driver = {
  1307. .name = "pistachio-pinctrl",
  1308. .of_match_table = pistachio_pinctrl_of_match,
  1309. .suppress_bind_attrs = true,
  1310. },
  1311. .probe = pistachio_pinctrl_probe,
  1312. };
  1313. static int __init pistachio_pinctrl_register(void)
  1314. {
  1315. return platform_driver_register(&pistachio_pinctrl_driver);
  1316. }
  1317. arch_initcall(pistachio_pinctrl_register);