pinctrl-pistachio.c 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485
  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 *irqd_to_bank(struct irq_data *d)
  761. {
  762. return gpiochip_get_data(irq_data_get_irq_chip_data(d));
  763. }
  764. static inline u32 gpio_readl(struct pistachio_gpio_bank *bank, u32 reg)
  765. {
  766. return readl(bank->base + reg);
  767. }
  768. static inline void gpio_writel(struct pistachio_gpio_bank *bank, u32 val,
  769. u32 reg)
  770. {
  771. writel(val, bank->base + reg);
  772. }
  773. static inline void gpio_mask_writel(struct pistachio_gpio_bank *bank,
  774. u32 reg, unsigned int bit, u32 val)
  775. {
  776. /*
  777. * For most of the GPIO registers, bit 16 + X must be set in order to
  778. * write bit X.
  779. */
  780. gpio_writel(bank, (0x10000 | val) << bit, reg);
  781. }
  782. static inline void gpio_enable(struct pistachio_gpio_bank *bank,
  783. unsigned offset)
  784. {
  785. gpio_mask_writel(bank, GPIO_BIT_EN, offset, 1);
  786. }
  787. static inline void gpio_disable(struct pistachio_gpio_bank *bank,
  788. unsigned offset)
  789. {
  790. gpio_mask_writel(bank, GPIO_BIT_EN, offset, 0);
  791. }
  792. static int pistachio_pinctrl_get_groups_count(struct pinctrl_dev *pctldev)
  793. {
  794. struct pistachio_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
  795. return pctl->ngroups;
  796. }
  797. static const char *pistachio_pinctrl_get_group_name(struct pinctrl_dev *pctldev,
  798. unsigned group)
  799. {
  800. struct pistachio_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
  801. return pctl->groups[group].name;
  802. }
  803. static int pistachio_pinctrl_get_group_pins(struct pinctrl_dev *pctldev,
  804. unsigned group,
  805. const unsigned **pins,
  806. unsigned *num_pins)
  807. {
  808. struct pistachio_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
  809. *pins = &pctl->groups[group].pin;
  810. *num_pins = 1;
  811. return 0;
  812. }
  813. static const struct pinctrl_ops pistachio_pinctrl_ops = {
  814. .get_groups_count = pistachio_pinctrl_get_groups_count,
  815. .get_group_name = pistachio_pinctrl_get_group_name,
  816. .get_group_pins = pistachio_pinctrl_get_group_pins,
  817. .dt_node_to_map = pinconf_generic_dt_node_to_map_pin,
  818. .dt_free_map = pinctrl_utils_free_map,
  819. };
  820. static int pistachio_pinmux_get_functions_count(struct pinctrl_dev *pctldev)
  821. {
  822. struct pistachio_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
  823. return pctl->nfunctions;
  824. }
  825. static const char *
  826. pistachio_pinmux_get_function_name(struct pinctrl_dev *pctldev, unsigned func)
  827. {
  828. struct pistachio_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
  829. return pctl->functions[func].name;
  830. }
  831. static int pistachio_pinmux_get_function_groups(struct pinctrl_dev *pctldev,
  832. unsigned func,
  833. const char * const **groups,
  834. unsigned * const num_groups)
  835. {
  836. struct pistachio_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
  837. *groups = pctl->functions[func].groups;
  838. *num_groups = pctl->functions[func].ngroups;
  839. return 0;
  840. }
  841. static int pistachio_pinmux_enable(struct pinctrl_dev *pctldev,
  842. unsigned func, unsigned group)
  843. {
  844. struct pistachio_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
  845. const struct pistachio_pin_group *pg = &pctl->groups[group];
  846. const struct pistachio_function *pf = &pctl->functions[func];
  847. struct pinctrl_gpio_range *range;
  848. unsigned int i;
  849. u32 val;
  850. if (pg->mux_reg > 0) {
  851. for (i = 0; i < ARRAY_SIZE(pg->mux_option); i++) {
  852. if (pg->mux_option[i] == func)
  853. break;
  854. }
  855. if (i == ARRAY_SIZE(pg->mux_option)) {
  856. dev_err(pctl->dev, "Cannot mux pin %u to function %u\n",
  857. group, func);
  858. return -EINVAL;
  859. }
  860. val = pctl_readl(pctl, pg->mux_reg);
  861. val &= ~(pg->mux_mask << pg->mux_shift);
  862. val |= i << pg->mux_shift;
  863. pctl_writel(pctl, val, pg->mux_reg);
  864. if (pf->scenarios) {
  865. for (i = 0; i < pf->nscenarios; i++) {
  866. if (pf->scenarios[i] == group)
  867. break;
  868. }
  869. if (WARN_ON(i == pf->nscenarios))
  870. return -EINVAL;
  871. val = pctl_readl(pctl, pf->scenario_reg);
  872. val &= ~(pf->scenario_mask << pf->scenario_shift);
  873. val |= i << pf->scenario_shift;
  874. pctl_writel(pctl, val, pf->scenario_reg);
  875. }
  876. }
  877. range = pinctrl_find_gpio_range_from_pin(pctl->pctldev, pg->pin);
  878. if (range)
  879. gpio_disable(gpiochip_get_data(range->gc), pg->pin - range->pin_base);
  880. return 0;
  881. }
  882. static const struct pinmux_ops pistachio_pinmux_ops = {
  883. .get_functions_count = pistachio_pinmux_get_functions_count,
  884. .get_function_name = pistachio_pinmux_get_function_name,
  885. .get_function_groups = pistachio_pinmux_get_function_groups,
  886. .set_mux = pistachio_pinmux_enable,
  887. };
  888. static int pistachio_pinconf_get(struct pinctrl_dev *pctldev, unsigned pin,
  889. unsigned long *config)
  890. {
  891. struct pistachio_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
  892. enum pin_config_param param = pinconf_to_config_param(*config);
  893. u32 val, arg;
  894. switch (param) {
  895. case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
  896. val = pctl_readl(pctl, PADS_SCHMITT_EN_REG(pin));
  897. arg = !!(val & PADS_SCHMITT_EN_BIT(pin));
  898. break;
  899. case PIN_CONFIG_BIAS_HIGH_IMPEDANCE:
  900. val = pctl_readl(pctl, PADS_PU_PD_REG(pin)) >>
  901. PADS_PU_PD_SHIFT(pin);
  902. arg = (val & PADS_PU_PD_MASK) == PADS_PU_PD_HIGHZ;
  903. break;
  904. case PIN_CONFIG_BIAS_PULL_UP:
  905. val = pctl_readl(pctl, PADS_PU_PD_REG(pin)) >>
  906. PADS_PU_PD_SHIFT(pin);
  907. arg = (val & PADS_PU_PD_MASK) == PADS_PU_PD_UP;
  908. break;
  909. case PIN_CONFIG_BIAS_PULL_DOWN:
  910. val = pctl_readl(pctl, PADS_PU_PD_REG(pin)) >>
  911. PADS_PU_PD_SHIFT(pin);
  912. arg = (val & PADS_PU_PD_MASK) == PADS_PU_PD_DOWN;
  913. break;
  914. case PIN_CONFIG_BIAS_BUS_HOLD:
  915. val = pctl_readl(pctl, PADS_PU_PD_REG(pin)) >>
  916. PADS_PU_PD_SHIFT(pin);
  917. arg = (val & PADS_PU_PD_MASK) == PADS_PU_PD_BUS;
  918. break;
  919. case PIN_CONFIG_SLEW_RATE:
  920. val = pctl_readl(pctl, PADS_SLEW_RATE_REG(pin));
  921. arg = !!(val & PADS_SLEW_RATE_BIT(pin));
  922. break;
  923. case PIN_CONFIG_DRIVE_STRENGTH:
  924. val = pctl_readl(pctl, PADS_DRIVE_STRENGTH_REG(pin)) >>
  925. PADS_DRIVE_STRENGTH_SHIFT(pin);
  926. switch (val & PADS_DRIVE_STRENGTH_MASK) {
  927. case PADS_DRIVE_STRENGTH_2MA:
  928. arg = 2;
  929. break;
  930. case PADS_DRIVE_STRENGTH_4MA:
  931. arg = 4;
  932. break;
  933. case PADS_DRIVE_STRENGTH_8MA:
  934. arg = 8;
  935. break;
  936. case PADS_DRIVE_STRENGTH_12MA:
  937. default:
  938. arg = 12;
  939. break;
  940. }
  941. break;
  942. default:
  943. dev_dbg(pctl->dev, "Property %u not supported\n", param);
  944. return -ENOTSUPP;
  945. }
  946. *config = pinconf_to_config_packed(param, arg);
  947. return 0;
  948. }
  949. static int pistachio_pinconf_set(struct pinctrl_dev *pctldev, unsigned pin,
  950. unsigned long *configs, unsigned num_configs)
  951. {
  952. struct pistachio_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
  953. enum pin_config_param param;
  954. u32 drv, val, arg;
  955. unsigned int i;
  956. for (i = 0; i < num_configs; i++) {
  957. param = pinconf_to_config_param(configs[i]);
  958. arg = pinconf_to_config_argument(configs[i]);
  959. switch (param) {
  960. case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
  961. val = pctl_readl(pctl, PADS_SCHMITT_EN_REG(pin));
  962. if (arg)
  963. val |= PADS_SCHMITT_EN_BIT(pin);
  964. else
  965. val &= ~PADS_SCHMITT_EN_BIT(pin);
  966. pctl_writel(pctl, val, PADS_SCHMITT_EN_REG(pin));
  967. break;
  968. case PIN_CONFIG_BIAS_HIGH_IMPEDANCE:
  969. val = pctl_readl(pctl, PADS_PU_PD_REG(pin));
  970. val &= ~(PADS_PU_PD_MASK << PADS_PU_PD_SHIFT(pin));
  971. val |= PADS_PU_PD_HIGHZ << PADS_PU_PD_SHIFT(pin);
  972. pctl_writel(pctl, val, PADS_PU_PD_REG(pin));
  973. break;
  974. case PIN_CONFIG_BIAS_PULL_UP:
  975. val = pctl_readl(pctl, PADS_PU_PD_REG(pin));
  976. val &= ~(PADS_PU_PD_MASK << PADS_PU_PD_SHIFT(pin));
  977. val |= PADS_PU_PD_UP << PADS_PU_PD_SHIFT(pin);
  978. pctl_writel(pctl, val, PADS_PU_PD_REG(pin));
  979. break;
  980. case PIN_CONFIG_BIAS_PULL_DOWN:
  981. val = pctl_readl(pctl, PADS_PU_PD_REG(pin));
  982. val &= ~(PADS_PU_PD_MASK << PADS_PU_PD_SHIFT(pin));
  983. val |= PADS_PU_PD_DOWN << PADS_PU_PD_SHIFT(pin);
  984. pctl_writel(pctl, val, PADS_PU_PD_REG(pin));
  985. break;
  986. case PIN_CONFIG_BIAS_BUS_HOLD:
  987. val = pctl_readl(pctl, PADS_PU_PD_REG(pin));
  988. val &= ~(PADS_PU_PD_MASK << PADS_PU_PD_SHIFT(pin));
  989. val |= PADS_PU_PD_BUS << PADS_PU_PD_SHIFT(pin);
  990. pctl_writel(pctl, val, PADS_PU_PD_REG(pin));
  991. break;
  992. case PIN_CONFIG_SLEW_RATE:
  993. val = pctl_readl(pctl, PADS_SLEW_RATE_REG(pin));
  994. if (arg)
  995. val |= PADS_SLEW_RATE_BIT(pin);
  996. else
  997. val &= ~PADS_SLEW_RATE_BIT(pin);
  998. pctl_writel(pctl, val, PADS_SLEW_RATE_REG(pin));
  999. break;
  1000. case PIN_CONFIG_DRIVE_STRENGTH:
  1001. val = pctl_readl(pctl, PADS_DRIVE_STRENGTH_REG(pin));
  1002. val &= ~(PADS_DRIVE_STRENGTH_MASK <<
  1003. PADS_DRIVE_STRENGTH_SHIFT(pin));
  1004. switch (arg) {
  1005. case 2:
  1006. drv = PADS_DRIVE_STRENGTH_2MA;
  1007. break;
  1008. case 4:
  1009. drv = PADS_DRIVE_STRENGTH_4MA;
  1010. break;
  1011. case 8:
  1012. drv = PADS_DRIVE_STRENGTH_8MA;
  1013. break;
  1014. case 12:
  1015. drv = PADS_DRIVE_STRENGTH_12MA;
  1016. break;
  1017. default:
  1018. dev_err(pctl->dev,
  1019. "Drive strength %umA not supported\n",
  1020. arg);
  1021. return -EINVAL;
  1022. }
  1023. val |= drv << PADS_DRIVE_STRENGTH_SHIFT(pin);
  1024. pctl_writel(pctl, val, PADS_DRIVE_STRENGTH_REG(pin));
  1025. break;
  1026. default:
  1027. dev_err(pctl->dev, "Property %u not supported\n",
  1028. param);
  1029. return -ENOTSUPP;
  1030. }
  1031. }
  1032. return 0;
  1033. }
  1034. static const struct pinconf_ops pistachio_pinconf_ops = {
  1035. .pin_config_get = pistachio_pinconf_get,
  1036. .pin_config_set = pistachio_pinconf_set,
  1037. .is_generic = true,
  1038. };
  1039. static struct pinctrl_desc pistachio_pinctrl_desc = {
  1040. .name = "pistachio-pinctrl",
  1041. .pctlops = &pistachio_pinctrl_ops,
  1042. .pmxops = &pistachio_pinmux_ops,
  1043. .confops = &pistachio_pinconf_ops,
  1044. };
  1045. static int pistachio_gpio_get_direction(struct gpio_chip *chip, unsigned offset)
  1046. {
  1047. struct pistachio_gpio_bank *bank = gpiochip_get_data(chip);
  1048. return !(gpio_readl(bank, GPIO_OUTPUT_EN) & BIT(offset));
  1049. }
  1050. static int pistachio_gpio_get(struct gpio_chip *chip, unsigned offset)
  1051. {
  1052. struct pistachio_gpio_bank *bank = gpiochip_get_data(chip);
  1053. u32 reg;
  1054. if (gpio_readl(bank, GPIO_OUTPUT_EN) & BIT(offset))
  1055. reg = GPIO_OUTPUT;
  1056. else
  1057. reg = GPIO_INPUT;
  1058. return !!(gpio_readl(bank, reg) & BIT(offset));
  1059. }
  1060. static void pistachio_gpio_set(struct gpio_chip *chip, unsigned offset,
  1061. int value)
  1062. {
  1063. struct pistachio_gpio_bank *bank = gpiochip_get_data(chip);
  1064. gpio_mask_writel(bank, GPIO_OUTPUT, offset, !!value);
  1065. }
  1066. static int pistachio_gpio_direction_input(struct gpio_chip *chip,
  1067. unsigned offset)
  1068. {
  1069. struct pistachio_gpio_bank *bank = gpiochip_get_data(chip);
  1070. gpio_mask_writel(bank, GPIO_OUTPUT_EN, offset, 0);
  1071. gpio_enable(bank, offset);
  1072. return 0;
  1073. }
  1074. static int pistachio_gpio_direction_output(struct gpio_chip *chip,
  1075. unsigned offset, int value)
  1076. {
  1077. struct pistachio_gpio_bank *bank = gpiochip_get_data(chip);
  1078. pistachio_gpio_set(chip, offset, value);
  1079. gpio_mask_writel(bank, GPIO_OUTPUT_EN, offset, 1);
  1080. gpio_enable(bank, offset);
  1081. return 0;
  1082. }
  1083. static void pistachio_gpio_irq_ack(struct irq_data *data)
  1084. {
  1085. struct pistachio_gpio_bank *bank = irqd_to_bank(data);
  1086. gpio_mask_writel(bank, GPIO_INTERRUPT_STATUS, data->hwirq, 0);
  1087. }
  1088. static void pistachio_gpio_irq_mask(struct irq_data *data)
  1089. {
  1090. struct pistachio_gpio_bank *bank = irqd_to_bank(data);
  1091. gpio_mask_writel(bank, GPIO_INTERRUPT_EN, data->hwirq, 0);
  1092. }
  1093. static void pistachio_gpio_irq_unmask(struct irq_data *data)
  1094. {
  1095. struct pistachio_gpio_bank *bank = irqd_to_bank(data);
  1096. gpio_mask_writel(bank, GPIO_INTERRUPT_EN, data->hwirq, 1);
  1097. }
  1098. static unsigned int pistachio_gpio_irq_startup(struct irq_data *data)
  1099. {
  1100. struct gpio_chip *chip = irq_data_get_irq_chip_data(data);
  1101. pistachio_gpio_direction_input(chip, data->hwirq);
  1102. pistachio_gpio_irq_unmask(data);
  1103. return 0;
  1104. }
  1105. static int pistachio_gpio_irq_set_type(struct irq_data *data, unsigned int type)
  1106. {
  1107. struct pistachio_gpio_bank *bank = irqd_to_bank(data);
  1108. switch (type & IRQ_TYPE_SENSE_MASK) {
  1109. case IRQ_TYPE_EDGE_RISING:
  1110. gpio_mask_writel(bank, GPIO_INPUT_POLARITY, data->hwirq, 1);
  1111. gpio_mask_writel(bank, GPIO_INTERRUPT_TYPE, data->hwirq,
  1112. GPIO_INTERRUPT_TYPE_EDGE);
  1113. gpio_mask_writel(bank, GPIO_INTERRUPT_EDGE, data->hwirq,
  1114. GPIO_INTERRUPT_EDGE_SINGLE);
  1115. break;
  1116. case IRQ_TYPE_EDGE_FALLING:
  1117. gpio_mask_writel(bank, GPIO_INPUT_POLARITY, data->hwirq, 0);
  1118. gpio_mask_writel(bank, GPIO_INTERRUPT_TYPE, data->hwirq,
  1119. GPIO_INTERRUPT_TYPE_EDGE);
  1120. gpio_mask_writel(bank, GPIO_INTERRUPT_EDGE, data->hwirq,
  1121. GPIO_INTERRUPT_EDGE_SINGLE);
  1122. break;
  1123. case IRQ_TYPE_EDGE_BOTH:
  1124. gpio_mask_writel(bank, GPIO_INTERRUPT_TYPE, data->hwirq,
  1125. GPIO_INTERRUPT_TYPE_EDGE);
  1126. gpio_mask_writel(bank, GPIO_INTERRUPT_EDGE, data->hwirq,
  1127. GPIO_INTERRUPT_EDGE_DUAL);
  1128. break;
  1129. case IRQ_TYPE_LEVEL_HIGH:
  1130. gpio_mask_writel(bank, GPIO_INPUT_POLARITY, data->hwirq, 1);
  1131. gpio_mask_writel(bank, GPIO_INTERRUPT_TYPE, data->hwirq,
  1132. GPIO_INTERRUPT_TYPE_LEVEL);
  1133. break;
  1134. case IRQ_TYPE_LEVEL_LOW:
  1135. gpio_mask_writel(bank, GPIO_INPUT_POLARITY, data->hwirq, 0);
  1136. gpio_mask_writel(bank, GPIO_INTERRUPT_TYPE, data->hwirq,
  1137. GPIO_INTERRUPT_TYPE_LEVEL);
  1138. break;
  1139. default:
  1140. return -EINVAL;
  1141. }
  1142. if (type & IRQ_TYPE_LEVEL_MASK)
  1143. irq_set_handler_locked(data, handle_level_irq);
  1144. else
  1145. irq_set_handler_locked(data, handle_edge_irq);
  1146. return 0;
  1147. }
  1148. static void pistachio_gpio_irq_handler(struct irq_desc *desc)
  1149. {
  1150. struct gpio_chip *gc = irq_desc_get_handler_data(desc);
  1151. struct pistachio_gpio_bank *bank = gpiochip_get_data(gc);
  1152. struct irq_chip *chip = irq_desc_get_chip(desc);
  1153. unsigned long pending;
  1154. unsigned int pin;
  1155. chained_irq_enter(chip, desc);
  1156. pending = gpio_readl(bank, GPIO_INTERRUPT_STATUS) &
  1157. gpio_readl(bank, GPIO_INTERRUPT_EN);
  1158. for_each_set_bit(pin, &pending, 16)
  1159. generic_handle_irq(irq_linear_revmap(gc->irqdomain, pin));
  1160. chained_irq_exit(chip, desc);
  1161. }
  1162. #define GPIO_BANK(_bank, _pin_base, _npins) \
  1163. { \
  1164. .pin_base = _pin_base, \
  1165. .npins = _npins, \
  1166. .gpio_chip = { \
  1167. .label = "GPIO" #_bank, \
  1168. .request = gpiochip_generic_request, \
  1169. .free = gpiochip_generic_free, \
  1170. .get_direction = pistachio_gpio_get_direction, \
  1171. .direction_input = pistachio_gpio_direction_input, \
  1172. .direction_output = pistachio_gpio_direction_output, \
  1173. .get = pistachio_gpio_get, \
  1174. .set = pistachio_gpio_set, \
  1175. .base = _pin_base, \
  1176. .ngpio = _npins, \
  1177. }, \
  1178. .irq_chip = { \
  1179. .name = "GPIO" #_bank, \
  1180. .irq_startup = pistachio_gpio_irq_startup, \
  1181. .irq_ack = pistachio_gpio_irq_ack, \
  1182. .irq_mask = pistachio_gpio_irq_mask, \
  1183. .irq_unmask = pistachio_gpio_irq_unmask, \
  1184. .irq_set_type = pistachio_gpio_irq_set_type, \
  1185. }, \
  1186. }
  1187. static struct pistachio_gpio_bank pistachio_gpio_banks[] = {
  1188. GPIO_BANK(0, PISTACHIO_PIN_MFIO(0), 16),
  1189. GPIO_BANK(1, PISTACHIO_PIN_MFIO(16), 16),
  1190. GPIO_BANK(2, PISTACHIO_PIN_MFIO(32), 16),
  1191. GPIO_BANK(3, PISTACHIO_PIN_MFIO(48), 16),
  1192. GPIO_BANK(4, PISTACHIO_PIN_MFIO(64), 16),
  1193. GPIO_BANK(5, PISTACHIO_PIN_MFIO(80), 10),
  1194. };
  1195. static int pistachio_gpio_register(struct pistachio_pinctrl *pctl)
  1196. {
  1197. struct device_node *node = pctl->dev->of_node;
  1198. struct pistachio_gpio_bank *bank;
  1199. unsigned int i;
  1200. int irq, ret = 0;
  1201. for (i = 0; i < pctl->nbanks; i++) {
  1202. char child_name[sizeof("gpioXX")];
  1203. struct device_node *child;
  1204. snprintf(child_name, sizeof(child_name), "gpio%d", i);
  1205. child = of_get_child_by_name(node, child_name);
  1206. if (!child) {
  1207. dev_err(pctl->dev, "No node for bank %u\n", i);
  1208. ret = -ENODEV;
  1209. goto err;
  1210. }
  1211. if (!of_find_property(child, "gpio-controller", NULL)) {
  1212. dev_err(pctl->dev,
  1213. "No gpio-controller property for bank %u\n", i);
  1214. of_node_put(child);
  1215. ret = -ENODEV;
  1216. goto err;
  1217. }
  1218. irq = irq_of_parse_and_map(child, 0);
  1219. if (irq < 0) {
  1220. dev_err(pctl->dev, "No IRQ for bank %u: %d\n", i, irq);
  1221. of_node_put(child);
  1222. ret = irq;
  1223. goto err;
  1224. }
  1225. bank = &pctl->gpio_banks[i];
  1226. bank->pctl = pctl;
  1227. bank->base = pctl->base + GPIO_BANK_BASE(i);
  1228. bank->gpio_chip.parent = pctl->dev;
  1229. bank->gpio_chip.of_node = child;
  1230. ret = gpiochip_add_data(&bank->gpio_chip, bank);
  1231. if (ret < 0) {
  1232. dev_err(pctl->dev, "Failed to add GPIO chip %u: %d\n",
  1233. i, ret);
  1234. goto err;
  1235. }
  1236. ret = gpiochip_irqchip_add(&bank->gpio_chip, &bank->irq_chip,
  1237. 0, handle_level_irq, IRQ_TYPE_NONE);
  1238. if (ret < 0) {
  1239. dev_err(pctl->dev, "Failed to add IRQ chip %u: %d\n",
  1240. i, ret);
  1241. gpiochip_remove(&bank->gpio_chip);
  1242. goto err;
  1243. }
  1244. gpiochip_set_chained_irqchip(&bank->gpio_chip, &bank->irq_chip,
  1245. irq, pistachio_gpio_irq_handler);
  1246. ret = gpiochip_add_pin_range(&bank->gpio_chip,
  1247. dev_name(pctl->dev), 0,
  1248. bank->pin_base, bank->npins);
  1249. if (ret < 0) {
  1250. dev_err(pctl->dev, "Failed to add GPIO range %u: %d\n",
  1251. i, ret);
  1252. gpiochip_remove(&bank->gpio_chip);
  1253. goto err;
  1254. }
  1255. }
  1256. return 0;
  1257. err:
  1258. for (; i > 0; i--) {
  1259. bank = &pctl->gpio_banks[i - 1];
  1260. gpiochip_remove(&bank->gpio_chip);
  1261. }
  1262. return ret;
  1263. }
  1264. static const struct of_device_id pistachio_pinctrl_of_match[] = {
  1265. { .compatible = "img,pistachio-system-pinctrl", },
  1266. { },
  1267. };
  1268. static int pistachio_pinctrl_probe(struct platform_device *pdev)
  1269. {
  1270. struct pistachio_pinctrl *pctl;
  1271. struct resource *res;
  1272. pctl = devm_kzalloc(&pdev->dev, sizeof(*pctl), GFP_KERNEL);
  1273. if (!pctl)
  1274. return -ENOMEM;
  1275. pctl->dev = &pdev->dev;
  1276. dev_set_drvdata(&pdev->dev, pctl);
  1277. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1278. pctl->base = devm_ioremap_resource(&pdev->dev, res);
  1279. if (IS_ERR(pctl->base))
  1280. return PTR_ERR(pctl->base);
  1281. pctl->pins = pistachio_pins;
  1282. pctl->npins = ARRAY_SIZE(pistachio_pins);
  1283. pctl->functions = pistachio_functions;
  1284. pctl->nfunctions = ARRAY_SIZE(pistachio_functions);
  1285. pctl->groups = pistachio_groups;
  1286. pctl->ngroups = ARRAY_SIZE(pistachio_groups);
  1287. pctl->gpio_banks = pistachio_gpio_banks;
  1288. pctl->nbanks = ARRAY_SIZE(pistachio_gpio_banks);
  1289. pistachio_pinctrl_desc.pins = pctl->pins;
  1290. pistachio_pinctrl_desc.npins = pctl->npins;
  1291. pctl->pctldev = devm_pinctrl_register(&pdev->dev, &pistachio_pinctrl_desc,
  1292. pctl);
  1293. if (IS_ERR(pctl->pctldev)) {
  1294. dev_err(&pdev->dev, "Failed to register pinctrl device\n");
  1295. return PTR_ERR(pctl->pctldev);
  1296. }
  1297. return pistachio_gpio_register(pctl);
  1298. }
  1299. static struct platform_driver pistachio_pinctrl_driver = {
  1300. .driver = {
  1301. .name = "pistachio-pinctrl",
  1302. .of_match_table = pistachio_pinctrl_of_match,
  1303. .suppress_bind_attrs = true,
  1304. },
  1305. .probe = pistachio_pinctrl_probe,
  1306. };
  1307. static int __init pistachio_pinctrl_register(void)
  1308. {
  1309. return platform_driver_register(&pistachio_pinctrl_driver);
  1310. }
  1311. arch_initcall(pistachio_pinctrl_register);