pinctrl-pistachio.c 41 KB

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