pinctrl-pistachio.c 41 KB

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