pinctrl-oxnas.c 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306
  1. /*
  2. * Oxford Semiconductor OXNAS SoC Family pinctrl driver
  3. *
  4. * Copyright (C) 2016 Neil Armstrong <narmstrong@baylibre.com>
  5. *
  6. * Based on pinctrl-pic32.c
  7. * Joshua Henderson, <joshua.henderson@microchip.com>
  8. * Copyright (C) 2015 Microchip Technology Inc. All rights reserved.
  9. *
  10. * This program is free software; you can distribute it and/or modify it
  11. * under the terms of the GNU General Public License (Version 2) as
  12. * published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope it will be useful, but WITHOUT
  15. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  16. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  17. * for more details.
  18. */
  19. #include <linux/gpio/driver.h>
  20. #include <linux/interrupt.h>
  21. #include <linux/io.h>
  22. #include <linux/irq.h>
  23. #include <linux/of.h>
  24. #include <linux/of_device.h>
  25. #include <linux/pinctrl/pinconf.h>
  26. #include <linux/pinctrl/pinconf-generic.h>
  27. #include <linux/pinctrl/pinctrl.h>
  28. #include <linux/pinctrl/pinmux.h>
  29. #include <linux/platform_device.h>
  30. #include <linux/slab.h>
  31. #include <linux/regmap.h>
  32. #include <linux/mfd/syscon.h>
  33. #include "pinctrl-utils.h"
  34. #define PINS_PER_BANK 32
  35. #define GPIO_BANK_START(bank) ((bank) * PINS_PER_BANK)
  36. /* OX810 Regmap Offsets */
  37. #define PINMUX_810_PRIMARY_SEL0 0x0c
  38. #define PINMUX_810_SECONDARY_SEL0 0x14
  39. #define PINMUX_810_TERTIARY_SEL0 0x8c
  40. #define PINMUX_810_PRIMARY_SEL1 0x10
  41. #define PINMUX_810_SECONDARY_SEL1 0x18
  42. #define PINMUX_810_TERTIARY_SEL1 0x90
  43. #define PINMUX_810_PULLUP_CTRL0 0xac
  44. #define PINMUX_810_PULLUP_CTRL1 0xb0
  45. /* OX820 Regmap Offsets */
  46. #define PINMUX_820_BANK_OFFSET 0x100000
  47. #define PINMUX_820_SECONDARY_SEL 0x14
  48. #define PINMUX_820_TERTIARY_SEL 0x8c
  49. #define PINMUX_820_QUATERNARY_SEL 0x94
  50. #define PINMUX_820_DEBUG_SEL 0x9c
  51. #define PINMUX_820_ALTERNATIVE_SEL 0xa4
  52. #define PINMUX_820_PULLUP_CTRL 0xac
  53. /* GPIO Registers */
  54. #define INPUT_VALUE 0x00
  55. #define OUTPUT_EN 0x04
  56. #define IRQ_PENDING 0x0c
  57. #define OUTPUT_SET 0x14
  58. #define OUTPUT_CLEAR 0x18
  59. #define OUTPUT_EN_SET 0x1c
  60. #define OUTPUT_EN_CLEAR 0x20
  61. #define RE_IRQ_ENABLE 0x28
  62. #define FE_IRQ_ENABLE 0x2c
  63. struct oxnas_function {
  64. const char *name;
  65. const char * const *groups;
  66. unsigned int ngroups;
  67. };
  68. struct oxnas_pin_group {
  69. const char *name;
  70. unsigned int pin;
  71. unsigned int bank;
  72. struct oxnas_desc_function *functions;
  73. };
  74. struct oxnas_desc_function {
  75. const char *name;
  76. unsigned int fct;
  77. };
  78. struct oxnas_gpio_bank {
  79. void __iomem *reg_base;
  80. struct gpio_chip gpio_chip;
  81. struct irq_chip irq_chip;
  82. unsigned int id;
  83. };
  84. struct oxnas_pinctrl {
  85. struct regmap *regmap;
  86. struct device *dev;
  87. struct pinctrl_dev *pctldev;
  88. const struct oxnas_function *functions;
  89. unsigned int nfunctions;
  90. const struct oxnas_pin_group *groups;
  91. unsigned int ngroups;
  92. struct oxnas_gpio_bank *gpio_banks;
  93. unsigned int nbanks;
  94. };
  95. struct oxnas_pinctrl_data {
  96. struct pinctrl_desc *desc;
  97. struct oxnas_pinctrl *pctl;
  98. };
  99. static const struct pinctrl_pin_desc oxnas_ox810se_pins[] = {
  100. PINCTRL_PIN(0, "gpio0"),
  101. PINCTRL_PIN(1, "gpio1"),
  102. PINCTRL_PIN(2, "gpio2"),
  103. PINCTRL_PIN(3, "gpio3"),
  104. PINCTRL_PIN(4, "gpio4"),
  105. PINCTRL_PIN(5, "gpio5"),
  106. PINCTRL_PIN(6, "gpio6"),
  107. PINCTRL_PIN(7, "gpio7"),
  108. PINCTRL_PIN(8, "gpio8"),
  109. PINCTRL_PIN(9, "gpio9"),
  110. PINCTRL_PIN(10, "gpio10"),
  111. PINCTRL_PIN(11, "gpio11"),
  112. PINCTRL_PIN(12, "gpio12"),
  113. PINCTRL_PIN(13, "gpio13"),
  114. PINCTRL_PIN(14, "gpio14"),
  115. PINCTRL_PIN(15, "gpio15"),
  116. PINCTRL_PIN(16, "gpio16"),
  117. PINCTRL_PIN(17, "gpio17"),
  118. PINCTRL_PIN(18, "gpio18"),
  119. PINCTRL_PIN(19, "gpio19"),
  120. PINCTRL_PIN(20, "gpio20"),
  121. PINCTRL_PIN(21, "gpio21"),
  122. PINCTRL_PIN(22, "gpio22"),
  123. PINCTRL_PIN(23, "gpio23"),
  124. PINCTRL_PIN(24, "gpio24"),
  125. PINCTRL_PIN(25, "gpio25"),
  126. PINCTRL_PIN(26, "gpio26"),
  127. PINCTRL_PIN(27, "gpio27"),
  128. PINCTRL_PIN(28, "gpio28"),
  129. PINCTRL_PIN(29, "gpio29"),
  130. PINCTRL_PIN(30, "gpio30"),
  131. PINCTRL_PIN(31, "gpio31"),
  132. PINCTRL_PIN(32, "gpio32"),
  133. PINCTRL_PIN(33, "gpio33"),
  134. PINCTRL_PIN(34, "gpio34"),
  135. };
  136. static const struct pinctrl_pin_desc oxnas_ox820_pins[] = {
  137. PINCTRL_PIN(0, "gpio0"),
  138. PINCTRL_PIN(1, "gpio1"),
  139. PINCTRL_PIN(2, "gpio2"),
  140. PINCTRL_PIN(3, "gpio3"),
  141. PINCTRL_PIN(4, "gpio4"),
  142. PINCTRL_PIN(5, "gpio5"),
  143. PINCTRL_PIN(6, "gpio6"),
  144. PINCTRL_PIN(7, "gpio7"),
  145. PINCTRL_PIN(8, "gpio8"),
  146. PINCTRL_PIN(9, "gpio9"),
  147. PINCTRL_PIN(10, "gpio10"),
  148. PINCTRL_PIN(11, "gpio11"),
  149. PINCTRL_PIN(12, "gpio12"),
  150. PINCTRL_PIN(13, "gpio13"),
  151. PINCTRL_PIN(14, "gpio14"),
  152. PINCTRL_PIN(15, "gpio15"),
  153. PINCTRL_PIN(16, "gpio16"),
  154. PINCTRL_PIN(17, "gpio17"),
  155. PINCTRL_PIN(18, "gpio18"),
  156. PINCTRL_PIN(19, "gpio19"),
  157. PINCTRL_PIN(20, "gpio20"),
  158. PINCTRL_PIN(21, "gpio21"),
  159. PINCTRL_PIN(22, "gpio22"),
  160. PINCTRL_PIN(23, "gpio23"),
  161. PINCTRL_PIN(24, "gpio24"),
  162. PINCTRL_PIN(25, "gpio25"),
  163. PINCTRL_PIN(26, "gpio26"),
  164. PINCTRL_PIN(27, "gpio27"),
  165. PINCTRL_PIN(28, "gpio28"),
  166. PINCTRL_PIN(29, "gpio29"),
  167. PINCTRL_PIN(30, "gpio30"),
  168. PINCTRL_PIN(31, "gpio31"),
  169. PINCTRL_PIN(32, "gpio32"),
  170. PINCTRL_PIN(33, "gpio33"),
  171. PINCTRL_PIN(34, "gpio34"),
  172. PINCTRL_PIN(35, "gpio35"),
  173. PINCTRL_PIN(36, "gpio36"),
  174. PINCTRL_PIN(37, "gpio37"),
  175. PINCTRL_PIN(38, "gpio38"),
  176. PINCTRL_PIN(39, "gpio39"),
  177. PINCTRL_PIN(40, "gpio40"),
  178. PINCTRL_PIN(41, "gpio41"),
  179. PINCTRL_PIN(42, "gpio42"),
  180. PINCTRL_PIN(43, "gpio43"),
  181. PINCTRL_PIN(44, "gpio44"),
  182. PINCTRL_PIN(45, "gpio45"),
  183. PINCTRL_PIN(46, "gpio46"),
  184. PINCTRL_PIN(47, "gpio47"),
  185. PINCTRL_PIN(48, "gpio48"),
  186. PINCTRL_PIN(49, "gpio49"),
  187. };
  188. static const char * const oxnas_ox810se_fct0_group[] = {
  189. "gpio0", "gpio1", "gpio2", "gpio3",
  190. "gpio4", "gpio5", "gpio6", "gpio7",
  191. "gpio8", "gpio9", "gpio10", "gpio11",
  192. "gpio12", "gpio13", "gpio14", "gpio15",
  193. "gpio16", "gpio17", "gpio18", "gpio19",
  194. "gpio20", "gpio21", "gpio22", "gpio23",
  195. "gpio24", "gpio25", "gpio26", "gpio27",
  196. "gpio28", "gpio29", "gpio30", "gpio31",
  197. "gpio32", "gpio33", "gpio34"
  198. };
  199. static const char * const oxnas_ox810se_fct3_group[] = {
  200. "gpio0", "gpio1", "gpio2", "gpio3",
  201. "gpio4", "gpio5", "gpio6", "gpio7",
  202. "gpio8", "gpio9",
  203. "gpio20",
  204. "gpio22", "gpio23", "gpio24", "gpio25",
  205. "gpio26", "gpio27", "gpio28", "gpio29",
  206. "gpio30", "gpio31", "gpio32", "gpio33",
  207. "gpio34"
  208. };
  209. static const char * const oxnas_ox820_fct0_group[] = {
  210. "gpio0", "gpio1", "gpio2", "gpio3",
  211. "gpio4", "gpio5", "gpio6", "gpio7",
  212. "gpio8", "gpio9", "gpio10", "gpio11",
  213. "gpio12", "gpio13", "gpio14", "gpio15",
  214. "gpio16", "gpio17", "gpio18", "gpio19",
  215. "gpio20", "gpio21", "gpio22", "gpio23",
  216. "gpio24", "gpio25", "gpio26", "gpio27",
  217. "gpio28", "gpio29", "gpio30", "gpio31",
  218. "gpio32", "gpio33", "gpio34", "gpio35",
  219. "gpio36", "gpio37", "gpio38", "gpio39",
  220. "gpio40", "gpio41", "gpio42", "gpio43",
  221. "gpio44", "gpio45", "gpio46", "gpio47",
  222. "gpio48", "gpio49"
  223. };
  224. static const char * const oxnas_ox820_fct1_group[] = {
  225. "gpio3", "gpio4",
  226. "gpio12", "gpio13", "gpio14", "gpio15",
  227. "gpio16", "gpio17", "gpio18", "gpio19",
  228. "gpio20", "gpio21", "gpio22", "gpio23",
  229. "gpio24"
  230. };
  231. static const char * const oxnas_ox820_fct4_group[] = {
  232. "gpio5", "gpio6", "gpio7", "gpio8",
  233. "gpio24", "gpio25", "gpio26", "gpio27",
  234. "gpio40", "gpio41", "gpio42", "gpio43"
  235. };
  236. static const char * const oxnas_ox820_fct5_group[] = {
  237. "gpio28", "gpio29", "gpio30", "gpio31"
  238. };
  239. #define FUNCTION(_name, _gr) \
  240. { \
  241. .name = #_name, \
  242. .groups = oxnas_##_gr##_group, \
  243. .ngroups = ARRAY_SIZE(oxnas_##_gr##_group), \
  244. }
  245. static const struct oxnas_function oxnas_ox810se_functions[] = {
  246. FUNCTION(gpio, ox810se_fct0),
  247. FUNCTION(fct3, ox810se_fct3),
  248. };
  249. static const struct oxnas_function oxnas_ox820_functions[] = {
  250. FUNCTION(gpio, ox820_fct0),
  251. FUNCTION(fct1, ox820_fct1),
  252. FUNCTION(fct4, ox820_fct4),
  253. FUNCTION(fct5, ox820_fct5),
  254. };
  255. #define OXNAS_PINCTRL_GROUP(_pin, _name, ...) \
  256. { \
  257. .name = #_name, \
  258. .pin = _pin, \
  259. .bank = _pin / PINS_PER_BANK, \
  260. .functions = (struct oxnas_desc_function[]){ \
  261. __VA_ARGS__, { } }, \
  262. }
  263. #define OXNAS_PINCTRL_FUNCTION(_name, _fct) \
  264. { \
  265. .name = #_name, \
  266. .fct = _fct, \
  267. }
  268. static const struct oxnas_pin_group oxnas_ox810se_groups[] = {
  269. OXNAS_PINCTRL_GROUP(0, gpio0,
  270. OXNAS_PINCTRL_FUNCTION(gpio, 0),
  271. OXNAS_PINCTRL_FUNCTION(fct3, 3)),
  272. OXNAS_PINCTRL_GROUP(1, gpio1,
  273. OXNAS_PINCTRL_FUNCTION(gpio, 0),
  274. OXNAS_PINCTRL_FUNCTION(fct3, 3)),
  275. OXNAS_PINCTRL_GROUP(2, gpio2,
  276. OXNAS_PINCTRL_FUNCTION(gpio, 0),
  277. OXNAS_PINCTRL_FUNCTION(fct3, 3)),
  278. OXNAS_PINCTRL_GROUP(3, gpio3,
  279. OXNAS_PINCTRL_FUNCTION(gpio, 0),
  280. OXNAS_PINCTRL_FUNCTION(fct3, 3)),
  281. OXNAS_PINCTRL_GROUP(4, gpio4,
  282. OXNAS_PINCTRL_FUNCTION(gpio, 0),
  283. OXNAS_PINCTRL_FUNCTION(fct3, 3)),
  284. OXNAS_PINCTRL_GROUP(5, gpio5,
  285. OXNAS_PINCTRL_FUNCTION(gpio, 0),
  286. OXNAS_PINCTRL_FUNCTION(fct3, 3)),
  287. OXNAS_PINCTRL_GROUP(6, gpio6,
  288. OXNAS_PINCTRL_FUNCTION(gpio, 0),
  289. OXNAS_PINCTRL_FUNCTION(fct3, 3)),
  290. OXNAS_PINCTRL_GROUP(7, gpio7,
  291. OXNAS_PINCTRL_FUNCTION(gpio, 0),
  292. OXNAS_PINCTRL_FUNCTION(fct3, 3)),
  293. OXNAS_PINCTRL_GROUP(8, gpio8,
  294. OXNAS_PINCTRL_FUNCTION(gpio, 0),
  295. OXNAS_PINCTRL_FUNCTION(fct3, 3)),
  296. OXNAS_PINCTRL_GROUP(9, gpio9,
  297. OXNAS_PINCTRL_FUNCTION(gpio, 0),
  298. OXNAS_PINCTRL_FUNCTION(fct3, 3)),
  299. OXNAS_PINCTRL_GROUP(10, gpio10,
  300. OXNAS_PINCTRL_FUNCTION(gpio, 0)),
  301. OXNAS_PINCTRL_GROUP(11, gpio11,
  302. OXNAS_PINCTRL_FUNCTION(gpio, 0)),
  303. OXNAS_PINCTRL_GROUP(12, gpio12,
  304. OXNAS_PINCTRL_FUNCTION(gpio, 0)),
  305. OXNAS_PINCTRL_GROUP(13, gpio13,
  306. OXNAS_PINCTRL_FUNCTION(gpio, 0)),
  307. OXNAS_PINCTRL_GROUP(14, gpio14,
  308. OXNAS_PINCTRL_FUNCTION(gpio, 0)),
  309. OXNAS_PINCTRL_GROUP(15, gpio15,
  310. OXNAS_PINCTRL_FUNCTION(gpio, 0)),
  311. OXNAS_PINCTRL_GROUP(16, gpio16,
  312. OXNAS_PINCTRL_FUNCTION(gpio, 0)),
  313. OXNAS_PINCTRL_GROUP(17, gpio17,
  314. OXNAS_PINCTRL_FUNCTION(gpio, 0)),
  315. OXNAS_PINCTRL_GROUP(18, gpio18,
  316. OXNAS_PINCTRL_FUNCTION(gpio, 0)),
  317. OXNAS_PINCTRL_GROUP(19, gpio19,
  318. OXNAS_PINCTRL_FUNCTION(gpio, 0)),
  319. OXNAS_PINCTRL_GROUP(20, gpio20,
  320. OXNAS_PINCTRL_FUNCTION(gpio, 0),
  321. OXNAS_PINCTRL_FUNCTION(fct3, 3)),
  322. OXNAS_PINCTRL_GROUP(21, gpio21,
  323. OXNAS_PINCTRL_FUNCTION(gpio, 0)),
  324. OXNAS_PINCTRL_GROUP(22, gpio22,
  325. OXNAS_PINCTRL_FUNCTION(gpio, 0),
  326. OXNAS_PINCTRL_FUNCTION(fct3, 3)),
  327. OXNAS_PINCTRL_GROUP(23, gpio23,
  328. OXNAS_PINCTRL_FUNCTION(gpio, 0),
  329. OXNAS_PINCTRL_FUNCTION(fct3, 3)),
  330. OXNAS_PINCTRL_GROUP(24, gpio24,
  331. OXNAS_PINCTRL_FUNCTION(gpio, 0),
  332. OXNAS_PINCTRL_FUNCTION(fct3, 3)),
  333. OXNAS_PINCTRL_GROUP(25, gpio25,
  334. OXNAS_PINCTRL_FUNCTION(gpio, 0),
  335. OXNAS_PINCTRL_FUNCTION(fct3, 3)),
  336. OXNAS_PINCTRL_GROUP(26, gpio26,
  337. OXNAS_PINCTRL_FUNCTION(gpio, 0),
  338. OXNAS_PINCTRL_FUNCTION(fct3, 3)),
  339. OXNAS_PINCTRL_GROUP(27, gpio27,
  340. OXNAS_PINCTRL_FUNCTION(gpio, 0),
  341. OXNAS_PINCTRL_FUNCTION(fct3, 3)),
  342. OXNAS_PINCTRL_GROUP(28, gpio28,
  343. OXNAS_PINCTRL_FUNCTION(gpio, 0),
  344. OXNAS_PINCTRL_FUNCTION(fct3, 3)),
  345. OXNAS_PINCTRL_GROUP(29, gpio29,
  346. OXNAS_PINCTRL_FUNCTION(gpio, 0),
  347. OXNAS_PINCTRL_FUNCTION(fct3, 3)),
  348. OXNAS_PINCTRL_GROUP(30, gpio30,
  349. OXNAS_PINCTRL_FUNCTION(gpio, 0),
  350. OXNAS_PINCTRL_FUNCTION(fct3, 3)),
  351. OXNAS_PINCTRL_GROUP(31, gpio31,
  352. OXNAS_PINCTRL_FUNCTION(gpio, 0),
  353. OXNAS_PINCTRL_FUNCTION(fct3, 3)),
  354. OXNAS_PINCTRL_GROUP(32, gpio32,
  355. OXNAS_PINCTRL_FUNCTION(gpio, 0),
  356. OXNAS_PINCTRL_FUNCTION(fct3, 3)),
  357. OXNAS_PINCTRL_GROUP(33, gpio33,
  358. OXNAS_PINCTRL_FUNCTION(gpio, 0),
  359. OXNAS_PINCTRL_FUNCTION(fct3, 3)),
  360. OXNAS_PINCTRL_GROUP(34, gpio34,
  361. OXNAS_PINCTRL_FUNCTION(gpio, 0),
  362. OXNAS_PINCTRL_FUNCTION(fct3, 3)),
  363. };
  364. static const struct oxnas_pin_group oxnas_ox820_groups[] = {
  365. OXNAS_PINCTRL_GROUP(0, gpio0,
  366. OXNAS_PINCTRL_FUNCTION(gpio, 0)),
  367. OXNAS_PINCTRL_GROUP(1, gpio1,
  368. OXNAS_PINCTRL_FUNCTION(gpio, 0)),
  369. OXNAS_PINCTRL_GROUP(2, gpio2,
  370. OXNAS_PINCTRL_FUNCTION(gpio, 0)),
  371. OXNAS_PINCTRL_GROUP(3, gpio3,
  372. OXNAS_PINCTRL_FUNCTION(gpio, 0),
  373. OXNAS_PINCTRL_FUNCTION(fct1, 1)),
  374. OXNAS_PINCTRL_GROUP(4, gpio4,
  375. OXNAS_PINCTRL_FUNCTION(gpio, 0),
  376. OXNAS_PINCTRL_FUNCTION(fct1, 1)),
  377. OXNAS_PINCTRL_GROUP(5, gpio5,
  378. OXNAS_PINCTRL_FUNCTION(gpio, 0),
  379. OXNAS_PINCTRL_FUNCTION(fct4, 4)),
  380. OXNAS_PINCTRL_GROUP(6, gpio6,
  381. OXNAS_PINCTRL_FUNCTION(gpio, 0),
  382. OXNAS_PINCTRL_FUNCTION(fct4, 4)),
  383. OXNAS_PINCTRL_GROUP(7, gpio7,
  384. OXNAS_PINCTRL_FUNCTION(gpio, 0),
  385. OXNAS_PINCTRL_FUNCTION(fct4, 4)),
  386. OXNAS_PINCTRL_GROUP(8, gpio8,
  387. OXNAS_PINCTRL_FUNCTION(gpio, 0),
  388. OXNAS_PINCTRL_FUNCTION(fct4, 4)),
  389. OXNAS_PINCTRL_GROUP(9, gpio9,
  390. OXNAS_PINCTRL_FUNCTION(gpio, 0)),
  391. OXNAS_PINCTRL_GROUP(10, gpio10,
  392. OXNAS_PINCTRL_FUNCTION(gpio, 0)),
  393. OXNAS_PINCTRL_GROUP(11, gpio11,
  394. OXNAS_PINCTRL_FUNCTION(gpio, 0)),
  395. OXNAS_PINCTRL_GROUP(12, gpio12,
  396. OXNAS_PINCTRL_FUNCTION(gpio, 0),
  397. OXNAS_PINCTRL_FUNCTION(fct1, 1)),
  398. OXNAS_PINCTRL_GROUP(13, gpio13,
  399. OXNAS_PINCTRL_FUNCTION(gpio, 0),
  400. OXNAS_PINCTRL_FUNCTION(fct1, 1)),
  401. OXNAS_PINCTRL_GROUP(14, gpio14,
  402. OXNAS_PINCTRL_FUNCTION(gpio, 0),
  403. OXNAS_PINCTRL_FUNCTION(fct1, 1)),
  404. OXNAS_PINCTRL_GROUP(15, gpio15,
  405. OXNAS_PINCTRL_FUNCTION(gpio, 0),
  406. OXNAS_PINCTRL_FUNCTION(fct1, 1)),
  407. OXNAS_PINCTRL_GROUP(16, gpio16,
  408. OXNAS_PINCTRL_FUNCTION(gpio, 0),
  409. OXNAS_PINCTRL_FUNCTION(fct1, 1)),
  410. OXNAS_PINCTRL_GROUP(17, gpio17,
  411. OXNAS_PINCTRL_FUNCTION(gpio, 0),
  412. OXNAS_PINCTRL_FUNCTION(fct1, 1)),
  413. OXNAS_PINCTRL_GROUP(18, gpio18,
  414. OXNAS_PINCTRL_FUNCTION(gpio, 0),
  415. OXNAS_PINCTRL_FUNCTION(fct1, 1)),
  416. OXNAS_PINCTRL_GROUP(19, gpio19,
  417. OXNAS_PINCTRL_FUNCTION(gpio, 0),
  418. OXNAS_PINCTRL_FUNCTION(fct1, 1)),
  419. OXNAS_PINCTRL_GROUP(20, gpio20,
  420. OXNAS_PINCTRL_FUNCTION(gpio, 0),
  421. OXNAS_PINCTRL_FUNCTION(fct1, 1)),
  422. OXNAS_PINCTRL_GROUP(21, gpio21,
  423. OXNAS_PINCTRL_FUNCTION(gpio, 0),
  424. OXNAS_PINCTRL_FUNCTION(fct1, 1)),
  425. OXNAS_PINCTRL_GROUP(22, gpio22,
  426. OXNAS_PINCTRL_FUNCTION(gpio, 0),
  427. OXNAS_PINCTRL_FUNCTION(fct1, 1)),
  428. OXNAS_PINCTRL_GROUP(23, gpio23,
  429. OXNAS_PINCTRL_FUNCTION(gpio, 0),
  430. OXNAS_PINCTRL_FUNCTION(fct1, 1)),
  431. OXNAS_PINCTRL_GROUP(24, gpio24,
  432. OXNAS_PINCTRL_FUNCTION(gpio, 0),
  433. OXNAS_PINCTRL_FUNCTION(fct1, 1),
  434. OXNAS_PINCTRL_FUNCTION(fct4, 5)),
  435. OXNAS_PINCTRL_GROUP(25, gpio25,
  436. OXNAS_PINCTRL_FUNCTION(gpio, 0),
  437. OXNAS_PINCTRL_FUNCTION(fct4, 4)),
  438. OXNAS_PINCTRL_GROUP(26, gpio26,
  439. OXNAS_PINCTRL_FUNCTION(gpio, 0),
  440. OXNAS_PINCTRL_FUNCTION(fct4, 4)),
  441. OXNAS_PINCTRL_GROUP(27, gpio27,
  442. OXNAS_PINCTRL_FUNCTION(gpio, 0),
  443. OXNAS_PINCTRL_FUNCTION(fct4, 4)),
  444. OXNAS_PINCTRL_GROUP(28, gpio28,
  445. OXNAS_PINCTRL_FUNCTION(gpio, 0),
  446. OXNAS_PINCTRL_FUNCTION(fct5, 5)),
  447. OXNAS_PINCTRL_GROUP(29, gpio29,
  448. OXNAS_PINCTRL_FUNCTION(gpio, 0),
  449. OXNAS_PINCTRL_FUNCTION(fct5, 5)),
  450. OXNAS_PINCTRL_GROUP(30, gpio30,
  451. OXNAS_PINCTRL_FUNCTION(gpio, 0),
  452. OXNAS_PINCTRL_FUNCTION(fct5, 5)),
  453. OXNAS_PINCTRL_GROUP(31, gpio31,
  454. OXNAS_PINCTRL_FUNCTION(gpio, 0),
  455. OXNAS_PINCTRL_FUNCTION(fct5, 5)),
  456. OXNAS_PINCTRL_GROUP(32, gpio32,
  457. OXNAS_PINCTRL_FUNCTION(gpio, 0)),
  458. OXNAS_PINCTRL_GROUP(33, gpio33,
  459. OXNAS_PINCTRL_FUNCTION(gpio, 0)),
  460. OXNAS_PINCTRL_GROUP(34, gpio34,
  461. OXNAS_PINCTRL_FUNCTION(gpio, 0)),
  462. OXNAS_PINCTRL_GROUP(35, gpio35,
  463. OXNAS_PINCTRL_FUNCTION(gpio, 0)),
  464. OXNAS_PINCTRL_GROUP(36, gpio36,
  465. OXNAS_PINCTRL_FUNCTION(gpio, 0)),
  466. OXNAS_PINCTRL_GROUP(37, gpio37,
  467. OXNAS_PINCTRL_FUNCTION(gpio, 0)),
  468. OXNAS_PINCTRL_GROUP(38, gpio38,
  469. OXNAS_PINCTRL_FUNCTION(gpio, 0)),
  470. OXNAS_PINCTRL_GROUP(39, gpio39,
  471. OXNAS_PINCTRL_FUNCTION(gpio, 0)),
  472. OXNAS_PINCTRL_GROUP(40, gpio40,
  473. OXNAS_PINCTRL_FUNCTION(gpio, 0),
  474. OXNAS_PINCTRL_FUNCTION(fct4, 4)),
  475. OXNAS_PINCTRL_GROUP(41, gpio41,
  476. OXNAS_PINCTRL_FUNCTION(gpio, 0),
  477. OXNAS_PINCTRL_FUNCTION(fct4, 4)),
  478. OXNAS_PINCTRL_GROUP(42, gpio42,
  479. OXNAS_PINCTRL_FUNCTION(gpio, 0),
  480. OXNAS_PINCTRL_FUNCTION(fct4, 4)),
  481. OXNAS_PINCTRL_GROUP(43, gpio43,
  482. OXNAS_PINCTRL_FUNCTION(gpio, 0),
  483. OXNAS_PINCTRL_FUNCTION(fct4, 4)),
  484. OXNAS_PINCTRL_GROUP(44, gpio44,
  485. OXNAS_PINCTRL_FUNCTION(gpio, 0)),
  486. OXNAS_PINCTRL_GROUP(45, gpio45,
  487. OXNAS_PINCTRL_FUNCTION(gpio, 0)),
  488. OXNAS_PINCTRL_GROUP(46, gpio46,
  489. OXNAS_PINCTRL_FUNCTION(gpio, 0)),
  490. OXNAS_PINCTRL_GROUP(47, gpio47,
  491. OXNAS_PINCTRL_FUNCTION(gpio, 0)),
  492. OXNAS_PINCTRL_GROUP(48, gpio48,
  493. OXNAS_PINCTRL_FUNCTION(gpio, 0)),
  494. OXNAS_PINCTRL_GROUP(49, gpio49,
  495. OXNAS_PINCTRL_FUNCTION(gpio, 0)),
  496. };
  497. static inline struct oxnas_gpio_bank *pctl_to_bank(struct oxnas_pinctrl *pctl,
  498. unsigned int pin)
  499. {
  500. return &pctl->gpio_banks[pin / PINS_PER_BANK];
  501. }
  502. static int oxnas_pinctrl_get_groups_count(struct pinctrl_dev *pctldev)
  503. {
  504. struct oxnas_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
  505. return pctl->ngroups;
  506. }
  507. static const char *oxnas_pinctrl_get_group_name(struct pinctrl_dev *pctldev,
  508. unsigned int group)
  509. {
  510. struct oxnas_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
  511. return pctl->groups[group].name;
  512. }
  513. static int oxnas_pinctrl_get_group_pins(struct pinctrl_dev *pctldev,
  514. unsigned int group,
  515. const unsigned int **pins,
  516. unsigned int *num_pins)
  517. {
  518. struct oxnas_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
  519. *pins = &pctl->groups[group].pin;
  520. *num_pins = 1;
  521. return 0;
  522. }
  523. static const struct pinctrl_ops oxnas_pinctrl_ops = {
  524. .get_groups_count = oxnas_pinctrl_get_groups_count,
  525. .get_group_name = oxnas_pinctrl_get_group_name,
  526. .get_group_pins = oxnas_pinctrl_get_group_pins,
  527. .dt_node_to_map = pinconf_generic_dt_node_to_map_pin,
  528. .dt_free_map = pinctrl_utils_free_map,
  529. };
  530. static int oxnas_pinmux_get_functions_count(struct pinctrl_dev *pctldev)
  531. {
  532. struct oxnas_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
  533. return pctl->nfunctions;
  534. }
  535. static const char *
  536. oxnas_pinmux_get_function_name(struct pinctrl_dev *pctldev, unsigned int func)
  537. {
  538. struct oxnas_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
  539. return pctl->functions[func].name;
  540. }
  541. static int oxnas_pinmux_get_function_groups(struct pinctrl_dev *pctldev,
  542. unsigned int func,
  543. const char * const **groups,
  544. unsigned int * const num_groups)
  545. {
  546. struct oxnas_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
  547. *groups = pctl->functions[func].groups;
  548. *num_groups = pctl->functions[func].ngroups;
  549. return 0;
  550. }
  551. static int oxnas_ox810se_pinmux_enable(struct pinctrl_dev *pctldev,
  552. unsigned int func, unsigned int group)
  553. {
  554. struct oxnas_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
  555. const struct oxnas_pin_group *pg = &pctl->groups[group];
  556. const struct oxnas_function *pf = &pctl->functions[func];
  557. const char *fname = pf->name;
  558. struct oxnas_desc_function *functions = pg->functions;
  559. u32 mask = BIT(pg->pin);
  560. while (functions->name) {
  561. if (!strcmp(functions->name, fname)) {
  562. dev_dbg(pctl->dev,
  563. "setting function %s bank %d pin %d fct %d mask %x\n",
  564. fname, pg->bank, pg->pin,
  565. functions->fct, mask);
  566. regmap_write_bits(pctl->regmap,
  567. (pg->bank ?
  568. PINMUX_810_PRIMARY_SEL1 :
  569. PINMUX_810_PRIMARY_SEL0),
  570. mask,
  571. (functions->fct == 1 ?
  572. mask : 0));
  573. regmap_write_bits(pctl->regmap,
  574. (pg->bank ?
  575. PINMUX_810_SECONDARY_SEL1 :
  576. PINMUX_810_SECONDARY_SEL0),
  577. mask,
  578. (functions->fct == 2 ?
  579. mask : 0));
  580. regmap_write_bits(pctl->regmap,
  581. (pg->bank ?
  582. PINMUX_810_TERTIARY_SEL1 :
  583. PINMUX_810_TERTIARY_SEL0),
  584. mask,
  585. (functions->fct == 3 ?
  586. mask : 0));
  587. return 0;
  588. }
  589. functions++;
  590. }
  591. dev_err(pctl->dev, "cannot mux pin %u to function %u\n", group, func);
  592. return -EINVAL;
  593. }
  594. static int oxnas_ox820_pinmux_enable(struct pinctrl_dev *pctldev,
  595. unsigned int func, unsigned int group)
  596. {
  597. struct oxnas_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
  598. const struct oxnas_pin_group *pg = &pctl->groups[group];
  599. const struct oxnas_function *pf = &pctl->functions[func];
  600. const char *fname = pf->name;
  601. struct oxnas_desc_function *functions = pg->functions;
  602. unsigned int offset = (pg->bank ? PINMUX_820_BANK_OFFSET : 0);
  603. u32 mask = BIT(pg->pin);
  604. while (functions->name) {
  605. if (!strcmp(functions->name, fname)) {
  606. dev_dbg(pctl->dev,
  607. "setting function %s bank %d pin %d fct %d mask %x\n",
  608. fname, pg->bank, pg->pin,
  609. functions->fct, mask);
  610. regmap_write_bits(pctl->regmap,
  611. offset + PINMUX_820_SECONDARY_SEL,
  612. mask,
  613. (functions->fct == 1 ?
  614. mask : 0));
  615. regmap_write_bits(pctl->regmap,
  616. offset + PINMUX_820_TERTIARY_SEL,
  617. mask,
  618. (functions->fct == 2 ?
  619. mask : 0));
  620. regmap_write_bits(pctl->regmap,
  621. offset + PINMUX_820_QUATERNARY_SEL,
  622. mask,
  623. (functions->fct == 3 ?
  624. mask : 0));
  625. regmap_write_bits(pctl->regmap,
  626. offset + PINMUX_820_DEBUG_SEL,
  627. mask,
  628. (functions->fct == 4 ?
  629. mask : 0));
  630. regmap_write_bits(pctl->regmap,
  631. offset + PINMUX_820_ALTERNATIVE_SEL,
  632. mask,
  633. (functions->fct == 5 ?
  634. mask : 0));
  635. return 0;
  636. }
  637. functions++;
  638. }
  639. dev_err(pctl->dev, "cannot mux pin %u to function %u\n", group, func);
  640. return -EINVAL;
  641. }
  642. static int oxnas_ox810se_gpio_request_enable(struct pinctrl_dev *pctldev,
  643. struct pinctrl_gpio_range *range,
  644. unsigned int offset)
  645. {
  646. struct oxnas_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
  647. struct oxnas_gpio_bank *bank = gpiochip_get_data(range->gc);
  648. u32 mask = BIT(offset - bank->gpio_chip.base);
  649. dev_dbg(pctl->dev, "requesting gpio %d in bank %d (id %d) with mask 0x%x\n",
  650. offset, bank->gpio_chip.base, bank->id, mask);
  651. regmap_write_bits(pctl->regmap,
  652. (bank->id ?
  653. PINMUX_810_PRIMARY_SEL1 :
  654. PINMUX_810_PRIMARY_SEL0),
  655. mask, 0);
  656. regmap_write_bits(pctl->regmap,
  657. (bank->id ?
  658. PINMUX_810_SECONDARY_SEL1 :
  659. PINMUX_810_SECONDARY_SEL0),
  660. mask, 0);
  661. regmap_write_bits(pctl->regmap,
  662. (bank->id ?
  663. PINMUX_810_TERTIARY_SEL1 :
  664. PINMUX_810_TERTIARY_SEL0),
  665. mask, 0);
  666. return 0;
  667. }
  668. static int oxnas_ox820_gpio_request_enable(struct pinctrl_dev *pctldev,
  669. struct pinctrl_gpio_range *range,
  670. unsigned int offset)
  671. {
  672. struct oxnas_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
  673. struct oxnas_gpio_bank *bank = gpiochip_get_data(range->gc);
  674. unsigned int bank_offset = (bank->id ? PINMUX_820_BANK_OFFSET : 0);
  675. u32 mask = BIT(offset - bank->gpio_chip.base);
  676. dev_dbg(pctl->dev, "requesting gpio %d in bank %d (id %d) with mask 0x%x\n",
  677. offset, bank->gpio_chip.base, bank->id, mask);
  678. regmap_write_bits(pctl->regmap,
  679. bank_offset + PINMUX_820_SECONDARY_SEL,
  680. mask, 0);
  681. regmap_write_bits(pctl->regmap,
  682. bank_offset + PINMUX_820_TERTIARY_SEL,
  683. mask, 0);
  684. regmap_write_bits(pctl->regmap,
  685. bank_offset + PINMUX_820_QUATERNARY_SEL,
  686. mask, 0);
  687. regmap_write_bits(pctl->regmap,
  688. bank_offset + PINMUX_820_DEBUG_SEL,
  689. mask, 0);
  690. regmap_write_bits(pctl->regmap,
  691. bank_offset + PINMUX_820_ALTERNATIVE_SEL,
  692. mask, 0);
  693. return 0;
  694. }
  695. static int oxnas_gpio_get_direction(struct gpio_chip *chip,
  696. unsigned int offset)
  697. {
  698. struct oxnas_gpio_bank *bank = gpiochip_get_data(chip);
  699. u32 mask = BIT(offset);
  700. return !(readl_relaxed(bank->reg_base + OUTPUT_EN) & mask);
  701. }
  702. static int oxnas_gpio_direction_input(struct gpio_chip *chip,
  703. unsigned int offset)
  704. {
  705. struct oxnas_gpio_bank *bank = gpiochip_get_data(chip);
  706. u32 mask = BIT(offset);
  707. writel_relaxed(mask, bank->reg_base + OUTPUT_EN_CLEAR);
  708. return 0;
  709. }
  710. static int oxnas_gpio_get(struct gpio_chip *chip, unsigned int offset)
  711. {
  712. struct oxnas_gpio_bank *bank = gpiochip_get_data(chip);
  713. u32 mask = BIT(offset);
  714. return (readl_relaxed(bank->reg_base + INPUT_VALUE) & mask) != 0;
  715. }
  716. static void oxnas_gpio_set(struct gpio_chip *chip, unsigned int offset,
  717. int value)
  718. {
  719. struct oxnas_gpio_bank *bank = gpiochip_get_data(chip);
  720. u32 mask = BIT(offset);
  721. if (value)
  722. writel_relaxed(mask, bank->reg_base + OUTPUT_SET);
  723. else
  724. writel_relaxed(mask, bank->reg_base + OUTPUT_CLEAR);
  725. }
  726. static int oxnas_gpio_direction_output(struct gpio_chip *chip,
  727. unsigned int offset, int value)
  728. {
  729. struct oxnas_gpio_bank *bank = gpiochip_get_data(chip);
  730. u32 mask = BIT(offset);
  731. oxnas_gpio_set(chip, offset, value);
  732. writel_relaxed(mask, bank->reg_base + OUTPUT_EN_SET);
  733. return 0;
  734. }
  735. static int oxnas_gpio_set_direction(struct pinctrl_dev *pctldev,
  736. struct pinctrl_gpio_range *range,
  737. unsigned int offset, bool input)
  738. {
  739. struct gpio_chip *chip = range->gc;
  740. if (input)
  741. oxnas_gpio_direction_input(chip, offset);
  742. else
  743. oxnas_gpio_direction_output(chip, offset, 0);
  744. return 0;
  745. }
  746. static const struct pinmux_ops oxnas_ox810se_pinmux_ops = {
  747. .get_functions_count = oxnas_pinmux_get_functions_count,
  748. .get_function_name = oxnas_pinmux_get_function_name,
  749. .get_function_groups = oxnas_pinmux_get_function_groups,
  750. .set_mux = oxnas_ox810se_pinmux_enable,
  751. .gpio_request_enable = oxnas_ox810se_gpio_request_enable,
  752. .gpio_set_direction = oxnas_gpio_set_direction,
  753. };
  754. static const struct pinmux_ops oxnas_ox820_pinmux_ops = {
  755. .get_functions_count = oxnas_pinmux_get_functions_count,
  756. .get_function_name = oxnas_pinmux_get_function_name,
  757. .get_function_groups = oxnas_pinmux_get_function_groups,
  758. .set_mux = oxnas_ox820_pinmux_enable,
  759. .gpio_request_enable = oxnas_ox820_gpio_request_enable,
  760. .gpio_set_direction = oxnas_gpio_set_direction,
  761. };
  762. static int oxnas_ox810se_pinconf_get(struct pinctrl_dev *pctldev,
  763. unsigned int pin, unsigned long *config)
  764. {
  765. struct oxnas_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
  766. struct oxnas_gpio_bank *bank = pctl_to_bank(pctl, pin);
  767. unsigned int param = pinconf_to_config_param(*config);
  768. u32 mask = BIT(pin - bank->gpio_chip.base);
  769. int ret;
  770. u32 arg;
  771. switch (param) {
  772. case PIN_CONFIG_BIAS_PULL_UP:
  773. ret = regmap_read(pctl->regmap,
  774. (bank->id ?
  775. PINMUX_810_PULLUP_CTRL1 :
  776. PINMUX_810_PULLUP_CTRL0),
  777. &arg);
  778. if (ret)
  779. return ret;
  780. arg = !!(arg & mask);
  781. break;
  782. default:
  783. return -ENOTSUPP;
  784. }
  785. *config = pinconf_to_config_packed(param, arg);
  786. return 0;
  787. }
  788. static int oxnas_ox820_pinconf_get(struct pinctrl_dev *pctldev,
  789. unsigned int pin, unsigned long *config)
  790. {
  791. struct oxnas_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
  792. struct oxnas_gpio_bank *bank = pctl_to_bank(pctl, pin);
  793. unsigned int param = pinconf_to_config_param(*config);
  794. unsigned int bank_offset = (bank->id ? PINMUX_820_BANK_OFFSET : 0);
  795. u32 mask = BIT(pin - bank->gpio_chip.base);
  796. int ret;
  797. u32 arg;
  798. switch (param) {
  799. case PIN_CONFIG_BIAS_PULL_UP:
  800. ret = regmap_read(pctl->regmap,
  801. bank_offset + PINMUX_820_PULLUP_CTRL,
  802. &arg);
  803. if (ret)
  804. return ret;
  805. arg = !!(arg & mask);
  806. break;
  807. default:
  808. return -ENOTSUPP;
  809. }
  810. *config = pinconf_to_config_packed(param, arg);
  811. return 0;
  812. }
  813. static int oxnas_ox810se_pinconf_set(struct pinctrl_dev *pctldev,
  814. unsigned int pin, unsigned long *configs,
  815. unsigned int num_configs)
  816. {
  817. struct oxnas_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
  818. struct oxnas_gpio_bank *bank = pctl_to_bank(pctl, pin);
  819. unsigned int param;
  820. u32 arg;
  821. unsigned int i;
  822. u32 offset = pin - bank->gpio_chip.base;
  823. u32 mask = BIT(offset);
  824. dev_dbg(pctl->dev, "setting pin %d bank %d mask 0x%x\n",
  825. pin, bank->gpio_chip.base, mask);
  826. for (i = 0; i < num_configs; i++) {
  827. param = pinconf_to_config_param(configs[i]);
  828. arg = pinconf_to_config_argument(configs[i]);
  829. switch (param) {
  830. case PIN_CONFIG_BIAS_PULL_UP:
  831. dev_dbg(pctl->dev, " pullup\n");
  832. regmap_write_bits(pctl->regmap,
  833. (bank->id ?
  834. PINMUX_810_PULLUP_CTRL1 :
  835. PINMUX_810_PULLUP_CTRL0),
  836. mask, mask);
  837. break;
  838. default:
  839. dev_err(pctl->dev, "Property %u not supported\n",
  840. param);
  841. return -ENOTSUPP;
  842. }
  843. }
  844. return 0;
  845. }
  846. static int oxnas_ox820_pinconf_set(struct pinctrl_dev *pctldev,
  847. unsigned int pin, unsigned long *configs,
  848. unsigned int num_configs)
  849. {
  850. struct oxnas_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
  851. struct oxnas_gpio_bank *bank = pctl_to_bank(pctl, pin);
  852. unsigned int bank_offset = (bank->id ? PINMUX_820_BANK_OFFSET : 0);
  853. unsigned int param;
  854. u32 arg;
  855. unsigned int i;
  856. u32 offset = pin - bank->gpio_chip.base;
  857. u32 mask = BIT(offset);
  858. dev_dbg(pctl->dev, "setting pin %d bank %d mask 0x%x\n",
  859. pin, bank->gpio_chip.base, mask);
  860. for (i = 0; i < num_configs; i++) {
  861. param = pinconf_to_config_param(configs[i]);
  862. arg = pinconf_to_config_argument(configs[i]);
  863. switch (param) {
  864. case PIN_CONFIG_BIAS_PULL_UP:
  865. dev_dbg(pctl->dev, " pullup\n");
  866. regmap_write_bits(pctl->regmap,
  867. bank_offset + PINMUX_820_PULLUP_CTRL,
  868. mask, mask);
  869. break;
  870. default:
  871. dev_err(pctl->dev, "Property %u not supported\n",
  872. param);
  873. return -ENOTSUPP;
  874. }
  875. }
  876. return 0;
  877. }
  878. static const struct pinconf_ops oxnas_ox810se_pinconf_ops = {
  879. .pin_config_get = oxnas_ox810se_pinconf_get,
  880. .pin_config_set = oxnas_ox810se_pinconf_set,
  881. .is_generic = true,
  882. };
  883. static const struct pinconf_ops oxnas_ox820_pinconf_ops = {
  884. .pin_config_get = oxnas_ox820_pinconf_get,
  885. .pin_config_set = oxnas_ox820_pinconf_set,
  886. .is_generic = true,
  887. };
  888. static void oxnas_gpio_irq_ack(struct irq_data *data)
  889. {
  890. struct gpio_chip *chip = irq_data_get_irq_chip_data(data);
  891. struct oxnas_gpio_bank *bank = gpiochip_get_data(chip);
  892. u32 mask = BIT(data->hwirq);
  893. writel(mask, bank->reg_base + IRQ_PENDING);
  894. }
  895. static void oxnas_gpio_irq_mask(struct irq_data *data)
  896. {
  897. struct gpio_chip *chip = irq_data_get_irq_chip_data(data);
  898. struct oxnas_gpio_bank *bank = gpiochip_get_data(chip);
  899. unsigned int type = irqd_get_trigger_type(data);
  900. u32 mask = BIT(data->hwirq);
  901. if (type & IRQ_TYPE_EDGE_RISING)
  902. writel(readl(bank->reg_base + RE_IRQ_ENABLE) & ~mask,
  903. bank->reg_base + RE_IRQ_ENABLE);
  904. if (type & IRQ_TYPE_EDGE_FALLING)
  905. writel(readl(bank->reg_base + FE_IRQ_ENABLE) & ~mask,
  906. bank->reg_base + FE_IRQ_ENABLE);
  907. }
  908. static void oxnas_gpio_irq_unmask(struct irq_data *data)
  909. {
  910. struct gpio_chip *chip = irq_data_get_irq_chip_data(data);
  911. struct oxnas_gpio_bank *bank = gpiochip_get_data(chip);
  912. unsigned int type = irqd_get_trigger_type(data);
  913. u32 mask = BIT(data->hwirq);
  914. if (type & IRQ_TYPE_EDGE_RISING)
  915. writel(readl(bank->reg_base + RE_IRQ_ENABLE) | mask,
  916. bank->reg_base + RE_IRQ_ENABLE);
  917. if (type & IRQ_TYPE_EDGE_FALLING)
  918. writel(readl(bank->reg_base + FE_IRQ_ENABLE) | mask,
  919. bank->reg_base + FE_IRQ_ENABLE);
  920. }
  921. static unsigned int oxnas_gpio_irq_startup(struct irq_data *data)
  922. {
  923. struct gpio_chip *chip = irq_data_get_irq_chip_data(data);
  924. oxnas_gpio_direction_input(chip, data->hwirq);
  925. oxnas_gpio_irq_unmask(data);
  926. return 0;
  927. }
  928. static int oxnas_gpio_irq_set_type(struct irq_data *data, unsigned int type)
  929. {
  930. if ((type & (IRQ_TYPE_EDGE_RISING|IRQ_TYPE_EDGE_FALLING)) == 0)
  931. return -EINVAL;
  932. irq_set_handler_locked(data, handle_edge_irq);
  933. return 0;
  934. }
  935. static void oxnas_gpio_irq_handler(struct irq_desc *desc)
  936. {
  937. struct gpio_chip *gc = irq_desc_get_handler_data(desc);
  938. struct oxnas_gpio_bank *bank = gpiochip_get_data(gc);
  939. struct irq_chip *chip = irq_desc_get_chip(desc);
  940. unsigned long stat;
  941. unsigned int pin;
  942. chained_irq_enter(chip, desc);
  943. stat = readl(bank->reg_base + IRQ_PENDING);
  944. for_each_set_bit(pin, &stat, BITS_PER_LONG)
  945. generic_handle_irq(irq_linear_revmap(gc->irqdomain, pin));
  946. chained_irq_exit(chip, desc);
  947. }
  948. #define GPIO_BANK(_bank) \
  949. { \
  950. .gpio_chip = { \
  951. .label = "GPIO" #_bank, \
  952. .request = gpiochip_generic_request, \
  953. .free = gpiochip_generic_free, \
  954. .get_direction = oxnas_gpio_get_direction, \
  955. .direction_input = oxnas_gpio_direction_input, \
  956. .direction_output = oxnas_gpio_direction_output, \
  957. .get = oxnas_gpio_get, \
  958. .set = oxnas_gpio_set, \
  959. .ngpio = PINS_PER_BANK, \
  960. .base = GPIO_BANK_START(_bank), \
  961. .owner = THIS_MODULE, \
  962. .can_sleep = 0, \
  963. }, \
  964. .irq_chip = { \
  965. .name = "GPIO" #_bank, \
  966. .irq_startup = oxnas_gpio_irq_startup, \
  967. .irq_ack = oxnas_gpio_irq_ack, \
  968. .irq_mask = oxnas_gpio_irq_mask, \
  969. .irq_unmask = oxnas_gpio_irq_unmask, \
  970. .irq_set_type = oxnas_gpio_irq_set_type, \
  971. }, \
  972. }
  973. static struct oxnas_gpio_bank oxnas_gpio_banks[] = {
  974. GPIO_BANK(0),
  975. GPIO_BANK(1),
  976. };
  977. static struct oxnas_pinctrl ox810se_pinctrl = {
  978. .functions = oxnas_ox810se_functions,
  979. .nfunctions = ARRAY_SIZE(oxnas_ox810se_functions),
  980. .groups = oxnas_ox810se_groups,
  981. .ngroups = ARRAY_SIZE(oxnas_ox810se_groups),
  982. .gpio_banks = oxnas_gpio_banks,
  983. .nbanks = ARRAY_SIZE(oxnas_gpio_banks),
  984. };
  985. static struct pinctrl_desc oxnas_ox810se_pinctrl_desc = {
  986. .name = "oxnas-pinctrl",
  987. .pins = oxnas_ox810se_pins,
  988. .npins = ARRAY_SIZE(oxnas_ox810se_pins),
  989. .pctlops = &oxnas_pinctrl_ops,
  990. .pmxops = &oxnas_ox810se_pinmux_ops,
  991. .confops = &oxnas_ox810se_pinconf_ops,
  992. .owner = THIS_MODULE,
  993. };
  994. static struct oxnas_pinctrl ox820_pinctrl = {
  995. .functions = oxnas_ox820_functions,
  996. .nfunctions = ARRAY_SIZE(oxnas_ox820_functions),
  997. .groups = oxnas_ox820_groups,
  998. .ngroups = ARRAY_SIZE(oxnas_ox820_groups),
  999. .gpio_banks = oxnas_gpio_banks,
  1000. .nbanks = ARRAY_SIZE(oxnas_gpio_banks),
  1001. };
  1002. static struct pinctrl_desc oxnas_ox820_pinctrl_desc = {
  1003. .name = "oxnas-pinctrl",
  1004. .pins = oxnas_ox820_pins,
  1005. .npins = ARRAY_SIZE(oxnas_ox820_pins),
  1006. .pctlops = &oxnas_pinctrl_ops,
  1007. .pmxops = &oxnas_ox820_pinmux_ops,
  1008. .confops = &oxnas_ox820_pinconf_ops,
  1009. .owner = THIS_MODULE,
  1010. };
  1011. static struct oxnas_pinctrl_data oxnas_ox810se_pinctrl_data = {
  1012. .desc = &oxnas_ox810se_pinctrl_desc,
  1013. .pctl = &ox810se_pinctrl,
  1014. };
  1015. static struct oxnas_pinctrl_data oxnas_ox820_pinctrl_data = {
  1016. .desc = &oxnas_ox820_pinctrl_desc,
  1017. .pctl = &ox820_pinctrl,
  1018. };
  1019. static const struct of_device_id oxnas_pinctrl_of_match[] = {
  1020. { .compatible = "oxsemi,ox810se-pinctrl",
  1021. .data = &oxnas_ox810se_pinctrl_data
  1022. },
  1023. { .compatible = "oxsemi,ox820-pinctrl",
  1024. .data = &oxnas_ox820_pinctrl_data,
  1025. },
  1026. { },
  1027. };
  1028. static int oxnas_pinctrl_probe(struct platform_device *pdev)
  1029. {
  1030. const struct of_device_id *id;
  1031. const struct oxnas_pinctrl_data *data;
  1032. struct oxnas_pinctrl *pctl;
  1033. id = of_match_node(oxnas_pinctrl_of_match, pdev->dev.of_node);
  1034. if (!id)
  1035. return -ENODEV;
  1036. data = id->data;
  1037. if (!data || !data->pctl || !data->desc)
  1038. return -EINVAL;
  1039. pctl = devm_kzalloc(&pdev->dev, sizeof(*pctl), GFP_KERNEL);
  1040. if (!pctl)
  1041. return -ENOMEM;
  1042. pctl->dev = &pdev->dev;
  1043. dev_set_drvdata(&pdev->dev, pctl);
  1044. pctl->regmap = syscon_regmap_lookup_by_phandle(pdev->dev.of_node,
  1045. "oxsemi,sys-ctrl");
  1046. if (IS_ERR(pctl->regmap)) {
  1047. dev_err(&pdev->dev, "failed to get sys ctrl regmap\n");
  1048. return -ENODEV;
  1049. }
  1050. pctl->functions = data->pctl->functions;
  1051. pctl->nfunctions = data->pctl->nfunctions;
  1052. pctl->groups = data->pctl->groups;
  1053. pctl->ngroups = data->pctl->ngroups;
  1054. pctl->gpio_banks = data->pctl->gpio_banks;
  1055. pctl->nbanks = data->pctl->nbanks;
  1056. pctl->pctldev = pinctrl_register(data->desc, &pdev->dev, pctl);
  1057. if (IS_ERR(pctl->pctldev)) {
  1058. dev_err(&pdev->dev, "Failed to register pinctrl device\n");
  1059. return PTR_ERR(pctl->pctldev);
  1060. }
  1061. return 0;
  1062. }
  1063. static int oxnas_gpio_probe(struct platform_device *pdev)
  1064. {
  1065. struct device_node *np = pdev->dev.of_node;
  1066. struct of_phandle_args pinspec;
  1067. struct oxnas_gpio_bank *bank;
  1068. unsigned int id, ngpios;
  1069. int irq, ret;
  1070. struct resource *res;
  1071. if (of_parse_phandle_with_fixed_args(np, "gpio-ranges",
  1072. 3, 0, &pinspec)) {
  1073. dev_err(&pdev->dev, "gpio-ranges property not found\n");
  1074. return -EINVAL;
  1075. }
  1076. id = pinspec.args[1] / PINS_PER_BANK;
  1077. ngpios = pinspec.args[2];
  1078. if (id >= ARRAY_SIZE(oxnas_gpio_banks)) {
  1079. dev_err(&pdev->dev, "invalid gpio-ranges base arg\n");
  1080. return -EINVAL;
  1081. }
  1082. if (ngpios > PINS_PER_BANK) {
  1083. dev_err(&pdev->dev, "invalid gpio-ranges count arg\n");
  1084. return -EINVAL;
  1085. }
  1086. bank = &oxnas_gpio_banks[id];
  1087. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1088. bank->reg_base = devm_ioremap_resource(&pdev->dev, res);
  1089. if (IS_ERR(bank->reg_base))
  1090. return PTR_ERR(bank->reg_base);
  1091. irq = platform_get_irq(pdev, 0);
  1092. if (irq < 0) {
  1093. dev_err(&pdev->dev, "irq get failed\n");
  1094. return irq;
  1095. }
  1096. bank->id = id;
  1097. bank->gpio_chip.parent = &pdev->dev;
  1098. bank->gpio_chip.of_node = np;
  1099. bank->gpio_chip.ngpio = ngpios;
  1100. ret = gpiochip_add_data(&bank->gpio_chip, bank);
  1101. if (ret < 0) {
  1102. dev_err(&pdev->dev, "Failed to add GPIO chip %u: %d\n",
  1103. id, ret);
  1104. return ret;
  1105. }
  1106. ret = gpiochip_irqchip_add(&bank->gpio_chip, &bank->irq_chip,
  1107. 0, handle_level_irq, IRQ_TYPE_NONE);
  1108. if (ret < 0) {
  1109. dev_err(&pdev->dev, "Failed to add IRQ chip %u: %d\n",
  1110. id, ret);
  1111. gpiochip_remove(&bank->gpio_chip);
  1112. return ret;
  1113. }
  1114. gpiochip_set_chained_irqchip(&bank->gpio_chip, &bank->irq_chip,
  1115. irq, oxnas_gpio_irq_handler);
  1116. return 0;
  1117. }
  1118. static struct platform_driver oxnas_pinctrl_driver = {
  1119. .driver = {
  1120. .name = "oxnas-pinctrl",
  1121. .of_match_table = oxnas_pinctrl_of_match,
  1122. .suppress_bind_attrs = true,
  1123. },
  1124. .probe = oxnas_pinctrl_probe,
  1125. };
  1126. static const struct of_device_id oxnas_gpio_of_match[] = {
  1127. { .compatible = "oxsemi,ox810se-gpio", },
  1128. { .compatible = "oxsemi,ox820-gpio", },
  1129. { },
  1130. };
  1131. static struct platform_driver oxnas_gpio_driver = {
  1132. .driver = {
  1133. .name = "oxnas-gpio",
  1134. .of_match_table = oxnas_gpio_of_match,
  1135. .suppress_bind_attrs = true,
  1136. },
  1137. .probe = oxnas_gpio_probe,
  1138. };
  1139. static int __init oxnas_gpio_register(void)
  1140. {
  1141. return platform_driver_register(&oxnas_gpio_driver);
  1142. }
  1143. arch_initcall(oxnas_gpio_register);
  1144. static int __init oxnas_pinctrl_register(void)
  1145. {
  1146. return platform_driver_register(&oxnas_pinctrl_driver);
  1147. }
  1148. arch_initcall(oxnas_pinctrl_register);