pinctrl-pistachio.c 41 KB

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