pinctrl-bcm63268.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Driver for BCM63268 GPIO unit (pinctrl + GPIO)
  4. *
  5. * Copyright (C) 2021 Álvaro Fernández Rojas <[email protected]>
  6. * Copyright (C) 2016 Jonas Gorski <[email protected]>
  7. */
  8. #include <linux/bits.h>
  9. #include <linux/gpio/driver.h>
  10. #include <linux/kernel.h>
  11. #include <linux/of.h>
  12. #include <linux/pinctrl/pinmux.h>
  13. #include <linux/platform_device.h>
  14. #include <linux/regmap.h>
  15. #include "../pinctrl-utils.h"
  16. #include "pinctrl-bcm63xx.h"
  17. #define BCM63268_NUM_GPIOS 52
  18. #define BCM63268_NUM_LEDS 24
  19. #define BCM63268_LED_REG 0x10
  20. #define BCM63268_MODE_REG 0x18
  21. #define BCM63268_CTRL_REG 0x1c
  22. #define BCM63268_BASEMODE_REG 0x38
  23. #define BCM63268_BASEMODE_NAND BIT(2) /* GPIOs 2-7, 24-31 */
  24. #define BCM63268_BASEMODE_GPIO35 BIT(4) /* GPIO 35 */
  25. #define BCM63268_BASEMODE_DECTPD BIT(5) /* GPIOs 8/9 */
  26. #define BCM63268_BASEMODE_VDSL_PHY_0 BIT(6) /* GPIOs 10/11 */
  27. #define BCM63268_BASEMODE_VDSL_PHY_1 BIT(7) /* GPIOs 12/13 */
  28. #define BCM63268_BASEMODE_VDSL_PHY_2 BIT(8) /* GPIOs 24/25 */
  29. #define BCM63268_BASEMODE_VDSL_PHY_3 BIT(9) /* GPIOs 26/27 */
  30. enum bcm63268_pinctrl_reg {
  31. BCM63268_LEDCTRL,
  32. BCM63268_MODE,
  33. BCM63268_CTRL,
  34. BCM63268_BASEMODE,
  35. };
  36. struct bcm63268_function {
  37. const char *name;
  38. const char * const *groups;
  39. const unsigned num_groups;
  40. enum bcm63268_pinctrl_reg reg;
  41. uint32_t mask;
  42. };
  43. #define BCM63268_PIN(a, b, basemode) \
  44. { \
  45. .number = a, \
  46. .name = b, \
  47. .drv_data = (void *)(basemode) \
  48. }
  49. static const struct pinctrl_pin_desc bcm63268_pins[] = {
  50. PINCTRL_PIN(0, "gpio0"),
  51. PINCTRL_PIN(1, "gpio1"),
  52. BCM63268_PIN(2, "gpio2", BCM63268_BASEMODE_NAND),
  53. BCM63268_PIN(3, "gpio3", BCM63268_BASEMODE_NAND),
  54. BCM63268_PIN(4, "gpio4", BCM63268_BASEMODE_NAND),
  55. BCM63268_PIN(5, "gpio5", BCM63268_BASEMODE_NAND),
  56. BCM63268_PIN(6, "gpio6", BCM63268_BASEMODE_NAND),
  57. BCM63268_PIN(7, "gpio7", BCM63268_BASEMODE_NAND),
  58. BCM63268_PIN(8, "gpio8", BCM63268_BASEMODE_DECTPD),
  59. BCM63268_PIN(9, "gpio9", BCM63268_BASEMODE_DECTPD),
  60. BCM63268_PIN(10, "gpio10", BCM63268_BASEMODE_VDSL_PHY_0),
  61. BCM63268_PIN(11, "gpio11", BCM63268_BASEMODE_VDSL_PHY_0),
  62. BCM63268_PIN(12, "gpio12", BCM63268_BASEMODE_VDSL_PHY_1),
  63. BCM63268_PIN(13, "gpio13", BCM63268_BASEMODE_VDSL_PHY_1),
  64. PINCTRL_PIN(14, "gpio14"),
  65. PINCTRL_PIN(15, "gpio15"),
  66. PINCTRL_PIN(16, "gpio16"),
  67. PINCTRL_PIN(17, "gpio17"),
  68. PINCTRL_PIN(18, "gpio18"),
  69. PINCTRL_PIN(19, "gpio19"),
  70. PINCTRL_PIN(20, "gpio20"),
  71. PINCTRL_PIN(21, "gpio21"),
  72. PINCTRL_PIN(22, "gpio22"),
  73. PINCTRL_PIN(23, "gpio23"),
  74. BCM63268_PIN(24, "gpio24",
  75. BCM63268_BASEMODE_NAND | BCM63268_BASEMODE_VDSL_PHY_2),
  76. BCM63268_PIN(25, "gpio25",
  77. BCM63268_BASEMODE_NAND | BCM63268_BASEMODE_VDSL_PHY_2),
  78. BCM63268_PIN(26, "gpio26",
  79. BCM63268_BASEMODE_NAND | BCM63268_BASEMODE_VDSL_PHY_3),
  80. BCM63268_PIN(27, "gpio27",
  81. BCM63268_BASEMODE_NAND | BCM63268_BASEMODE_VDSL_PHY_3),
  82. BCM63268_PIN(28, "gpio28", BCM63268_BASEMODE_NAND),
  83. BCM63268_PIN(29, "gpio29", BCM63268_BASEMODE_NAND),
  84. BCM63268_PIN(30, "gpio30", BCM63268_BASEMODE_NAND),
  85. BCM63268_PIN(31, "gpio31", BCM63268_BASEMODE_NAND),
  86. PINCTRL_PIN(32, "gpio32"),
  87. PINCTRL_PIN(33, "gpio33"),
  88. PINCTRL_PIN(34, "gpio34"),
  89. PINCTRL_PIN(35, "gpio35"),
  90. PINCTRL_PIN(36, "gpio36"),
  91. PINCTRL_PIN(37, "gpio37"),
  92. PINCTRL_PIN(38, "gpio38"),
  93. PINCTRL_PIN(39, "gpio39"),
  94. PINCTRL_PIN(40, "gpio40"),
  95. PINCTRL_PIN(41, "gpio41"),
  96. PINCTRL_PIN(42, "gpio42"),
  97. PINCTRL_PIN(43, "gpio43"),
  98. PINCTRL_PIN(44, "gpio44"),
  99. PINCTRL_PIN(45, "gpio45"),
  100. PINCTRL_PIN(46, "gpio46"),
  101. PINCTRL_PIN(47, "gpio47"),
  102. PINCTRL_PIN(48, "gpio48"),
  103. PINCTRL_PIN(49, "gpio49"),
  104. PINCTRL_PIN(50, "gpio50"),
  105. PINCTRL_PIN(51, "gpio51"),
  106. };
  107. static unsigned gpio0_pins[] = { 0 };
  108. static unsigned gpio1_pins[] = { 1 };
  109. static unsigned gpio2_pins[] = { 2 };
  110. static unsigned gpio3_pins[] = { 3 };
  111. static unsigned gpio4_pins[] = { 4 };
  112. static unsigned gpio5_pins[] = { 5 };
  113. static unsigned gpio6_pins[] = { 6 };
  114. static unsigned gpio7_pins[] = { 7 };
  115. static unsigned gpio8_pins[] = { 8 };
  116. static unsigned gpio9_pins[] = { 9 };
  117. static unsigned gpio10_pins[] = { 10 };
  118. static unsigned gpio11_pins[] = { 11 };
  119. static unsigned gpio12_pins[] = { 12 };
  120. static unsigned gpio13_pins[] = { 13 };
  121. static unsigned gpio14_pins[] = { 14 };
  122. static unsigned gpio15_pins[] = { 15 };
  123. static unsigned gpio16_pins[] = { 16 };
  124. static unsigned gpio17_pins[] = { 17 };
  125. static unsigned gpio18_pins[] = { 18 };
  126. static unsigned gpio19_pins[] = { 19 };
  127. static unsigned gpio20_pins[] = { 20 };
  128. static unsigned gpio21_pins[] = { 21 };
  129. static unsigned gpio22_pins[] = { 22 };
  130. static unsigned gpio23_pins[] = { 23 };
  131. static unsigned gpio24_pins[] = { 24 };
  132. static unsigned gpio25_pins[] = { 25 };
  133. static unsigned gpio26_pins[] = { 26 };
  134. static unsigned gpio27_pins[] = { 27 };
  135. static unsigned gpio28_pins[] = { 28 };
  136. static unsigned gpio29_pins[] = { 29 };
  137. static unsigned gpio30_pins[] = { 30 };
  138. static unsigned gpio31_pins[] = { 31 };
  139. static unsigned gpio32_pins[] = { 32 };
  140. static unsigned gpio33_pins[] = { 33 };
  141. static unsigned gpio34_pins[] = { 34 };
  142. static unsigned gpio35_pins[] = { 35 };
  143. static unsigned gpio36_pins[] = { 36 };
  144. static unsigned gpio37_pins[] = { 37 };
  145. static unsigned gpio38_pins[] = { 38 };
  146. static unsigned gpio39_pins[] = { 39 };
  147. static unsigned gpio40_pins[] = { 40 };
  148. static unsigned gpio41_pins[] = { 41 };
  149. static unsigned gpio42_pins[] = { 42 };
  150. static unsigned gpio43_pins[] = { 43 };
  151. static unsigned gpio44_pins[] = { 44 };
  152. static unsigned gpio45_pins[] = { 45 };
  153. static unsigned gpio46_pins[] = { 46 };
  154. static unsigned gpio47_pins[] = { 47 };
  155. static unsigned gpio48_pins[] = { 48 };
  156. static unsigned gpio49_pins[] = { 49 };
  157. static unsigned gpio50_pins[] = { 50 };
  158. static unsigned gpio51_pins[] = { 51 };
  159. static unsigned nand_grp_pins[] = {
  160. 2, 3, 4, 5, 6, 7, 24,
  161. 25, 26, 27, 28, 29, 30, 31,
  162. };
  163. static unsigned dectpd_grp_pins[] = { 8, 9 };
  164. static unsigned vdsl_phy0_grp_pins[] = { 10, 11 };
  165. static unsigned vdsl_phy1_grp_pins[] = { 12, 13 };
  166. static unsigned vdsl_phy2_grp_pins[] = { 24, 25 };
  167. static unsigned vdsl_phy3_grp_pins[] = { 26, 27 };
  168. static struct pingroup bcm63268_groups[] = {
  169. BCM_PIN_GROUP(gpio0),
  170. BCM_PIN_GROUP(gpio1),
  171. BCM_PIN_GROUP(gpio2),
  172. BCM_PIN_GROUP(gpio3),
  173. BCM_PIN_GROUP(gpio4),
  174. BCM_PIN_GROUP(gpio5),
  175. BCM_PIN_GROUP(gpio6),
  176. BCM_PIN_GROUP(gpio7),
  177. BCM_PIN_GROUP(gpio8),
  178. BCM_PIN_GROUP(gpio9),
  179. BCM_PIN_GROUP(gpio10),
  180. BCM_PIN_GROUP(gpio11),
  181. BCM_PIN_GROUP(gpio12),
  182. BCM_PIN_GROUP(gpio13),
  183. BCM_PIN_GROUP(gpio14),
  184. BCM_PIN_GROUP(gpio15),
  185. BCM_PIN_GROUP(gpio16),
  186. BCM_PIN_GROUP(gpio17),
  187. BCM_PIN_GROUP(gpio18),
  188. BCM_PIN_GROUP(gpio19),
  189. BCM_PIN_GROUP(gpio20),
  190. BCM_PIN_GROUP(gpio21),
  191. BCM_PIN_GROUP(gpio22),
  192. BCM_PIN_GROUP(gpio23),
  193. BCM_PIN_GROUP(gpio24),
  194. BCM_PIN_GROUP(gpio25),
  195. BCM_PIN_GROUP(gpio26),
  196. BCM_PIN_GROUP(gpio27),
  197. BCM_PIN_GROUP(gpio28),
  198. BCM_PIN_GROUP(gpio29),
  199. BCM_PIN_GROUP(gpio30),
  200. BCM_PIN_GROUP(gpio31),
  201. BCM_PIN_GROUP(gpio32),
  202. BCM_PIN_GROUP(gpio33),
  203. BCM_PIN_GROUP(gpio34),
  204. BCM_PIN_GROUP(gpio35),
  205. BCM_PIN_GROUP(gpio36),
  206. BCM_PIN_GROUP(gpio37),
  207. BCM_PIN_GROUP(gpio38),
  208. BCM_PIN_GROUP(gpio39),
  209. BCM_PIN_GROUP(gpio40),
  210. BCM_PIN_GROUP(gpio41),
  211. BCM_PIN_GROUP(gpio42),
  212. BCM_PIN_GROUP(gpio43),
  213. BCM_PIN_GROUP(gpio44),
  214. BCM_PIN_GROUP(gpio45),
  215. BCM_PIN_GROUP(gpio46),
  216. BCM_PIN_GROUP(gpio47),
  217. BCM_PIN_GROUP(gpio48),
  218. BCM_PIN_GROUP(gpio49),
  219. BCM_PIN_GROUP(gpio50),
  220. BCM_PIN_GROUP(gpio51),
  221. /* multi pin groups */
  222. BCM_PIN_GROUP(nand_grp),
  223. BCM_PIN_GROUP(dectpd_grp),
  224. BCM_PIN_GROUP(vdsl_phy0_grp),
  225. BCM_PIN_GROUP(vdsl_phy1_grp),
  226. BCM_PIN_GROUP(vdsl_phy2_grp),
  227. BCM_PIN_GROUP(vdsl_phy3_grp),
  228. };
  229. static const char * const led_groups[] = {
  230. "gpio0",
  231. "gpio1",
  232. "gpio2",
  233. "gpio3",
  234. "gpio4",
  235. "gpio5",
  236. "gpio6",
  237. "gpio7",
  238. "gpio8",
  239. "gpio9",
  240. "gpio10",
  241. "gpio11",
  242. "gpio12",
  243. "gpio13",
  244. "gpio14",
  245. "gpio15",
  246. "gpio16",
  247. "gpio17",
  248. "gpio18",
  249. "gpio19",
  250. "gpio20",
  251. "gpio21",
  252. "gpio22",
  253. "gpio23",
  254. };
  255. static const char * const serial_led_clk_groups[] = {
  256. "gpio0",
  257. };
  258. static const char * const serial_led_data_groups[] = {
  259. "gpio1",
  260. };
  261. static const char * const hsspi_cs4_groups[] = {
  262. "gpio16",
  263. };
  264. static const char * const hsspi_cs5_groups[] = {
  265. "gpio17",
  266. };
  267. static const char * const hsspi_cs6_groups[] = {
  268. "gpio8",
  269. };
  270. static const char * const hsspi_cs7_groups[] = {
  271. "gpio9",
  272. };
  273. static const char * const uart1_scts_groups[] = {
  274. "gpio10",
  275. "gpio24",
  276. };
  277. static const char * const uart1_srts_groups[] = {
  278. "gpio11",
  279. "gpio25",
  280. };
  281. static const char * const uart1_sdin_groups[] = {
  282. "gpio12",
  283. "gpio26",
  284. };
  285. static const char * const uart1_sdout_groups[] = {
  286. "gpio13",
  287. "gpio27",
  288. };
  289. static const char * const ntr_pulse_in_groups[] = {
  290. "gpio14",
  291. "gpio28",
  292. };
  293. static const char * const dsl_ntr_pulse_out_groups[] = {
  294. "gpio15",
  295. "gpio29",
  296. };
  297. static const char * const adsl_spi_miso_groups[] = {
  298. "gpio18",
  299. };
  300. static const char * const adsl_spi_mosi_groups[] = {
  301. "gpio19",
  302. };
  303. static const char * const vreg_clk_groups[] = {
  304. "gpio22",
  305. };
  306. static const char * const pcie_clkreq_b_groups[] = {
  307. "gpio23",
  308. };
  309. static const char * const switch_led_clk_groups[] = {
  310. "gpio30",
  311. };
  312. static const char * const switch_led_data_groups[] = {
  313. "gpio31",
  314. };
  315. static const char * const wifi_groups[] = {
  316. "gpio32",
  317. "gpio33",
  318. "gpio34",
  319. "gpio35",
  320. "gpio36",
  321. "gpio37",
  322. "gpio38",
  323. "gpio39",
  324. "gpio40",
  325. "gpio41",
  326. "gpio42",
  327. "gpio43",
  328. "gpio44",
  329. "gpio45",
  330. "gpio46",
  331. "gpio47",
  332. "gpio48",
  333. "gpio49",
  334. "gpio50",
  335. "gpio51",
  336. };
  337. static const char * const nand_groups[] = {
  338. "nand_grp",
  339. };
  340. static const char * const dectpd_groups[] = {
  341. "dectpd_grp",
  342. };
  343. static const char * const vdsl_phy_override_0_groups[] = {
  344. "vdsl_phy_override_0_grp",
  345. };
  346. static const char * const vdsl_phy_override_1_groups[] = {
  347. "vdsl_phy_override_1_grp",
  348. };
  349. static const char * const vdsl_phy_override_2_groups[] = {
  350. "vdsl_phy_override_2_grp",
  351. };
  352. static const char * const vdsl_phy_override_3_groups[] = {
  353. "vdsl_phy_override_3_grp",
  354. };
  355. #define BCM63268_LED_FUN(n) \
  356. { \
  357. .name = #n, \
  358. .groups = n##_groups, \
  359. .num_groups = ARRAY_SIZE(n##_groups), \
  360. .reg = BCM63268_LEDCTRL, \
  361. }
  362. #define BCM63268_MODE_FUN(n) \
  363. { \
  364. .name = #n, \
  365. .groups = n##_groups, \
  366. .num_groups = ARRAY_SIZE(n##_groups), \
  367. .reg = BCM63268_MODE, \
  368. }
  369. #define BCM63268_CTRL_FUN(n) \
  370. { \
  371. .name = #n, \
  372. .groups = n##_groups, \
  373. .num_groups = ARRAY_SIZE(n##_groups), \
  374. .reg = BCM63268_CTRL, \
  375. }
  376. #define BCM63268_BASEMODE_FUN(n, val) \
  377. { \
  378. .name = #n, \
  379. .groups = n##_groups, \
  380. .num_groups = ARRAY_SIZE(n##_groups), \
  381. .reg = BCM63268_BASEMODE, \
  382. .mask = val, \
  383. }
  384. static const struct bcm63268_function bcm63268_funcs[] = {
  385. BCM63268_LED_FUN(led),
  386. BCM63268_MODE_FUN(serial_led_clk),
  387. BCM63268_MODE_FUN(serial_led_data),
  388. BCM63268_MODE_FUN(hsspi_cs6),
  389. BCM63268_MODE_FUN(hsspi_cs7),
  390. BCM63268_MODE_FUN(uart1_scts),
  391. BCM63268_MODE_FUN(uart1_srts),
  392. BCM63268_MODE_FUN(uart1_sdin),
  393. BCM63268_MODE_FUN(uart1_sdout),
  394. BCM63268_MODE_FUN(ntr_pulse_in),
  395. BCM63268_MODE_FUN(dsl_ntr_pulse_out),
  396. BCM63268_MODE_FUN(hsspi_cs4),
  397. BCM63268_MODE_FUN(hsspi_cs5),
  398. BCM63268_MODE_FUN(adsl_spi_miso),
  399. BCM63268_MODE_FUN(adsl_spi_mosi),
  400. BCM63268_MODE_FUN(vreg_clk),
  401. BCM63268_MODE_FUN(pcie_clkreq_b),
  402. BCM63268_MODE_FUN(switch_led_clk),
  403. BCM63268_MODE_FUN(switch_led_data),
  404. BCM63268_CTRL_FUN(wifi),
  405. BCM63268_BASEMODE_FUN(nand, BCM63268_BASEMODE_NAND),
  406. BCM63268_BASEMODE_FUN(dectpd, BCM63268_BASEMODE_DECTPD),
  407. BCM63268_BASEMODE_FUN(vdsl_phy_override_0,
  408. BCM63268_BASEMODE_VDSL_PHY_0),
  409. BCM63268_BASEMODE_FUN(vdsl_phy_override_1,
  410. BCM63268_BASEMODE_VDSL_PHY_1),
  411. BCM63268_BASEMODE_FUN(vdsl_phy_override_2,
  412. BCM63268_BASEMODE_VDSL_PHY_2),
  413. BCM63268_BASEMODE_FUN(vdsl_phy_override_3,
  414. BCM63268_BASEMODE_VDSL_PHY_3),
  415. };
  416. static int bcm63268_pinctrl_get_group_count(struct pinctrl_dev *pctldev)
  417. {
  418. return ARRAY_SIZE(bcm63268_groups);
  419. }
  420. static const char *bcm63268_pinctrl_get_group_name(struct pinctrl_dev *pctldev,
  421. unsigned group)
  422. {
  423. return bcm63268_groups[group].name;
  424. }
  425. static int bcm63268_pinctrl_get_group_pins(struct pinctrl_dev *pctldev,
  426. unsigned group,
  427. const unsigned **pins,
  428. unsigned *npins)
  429. {
  430. *pins = bcm63268_groups[group].pins;
  431. *npins = bcm63268_groups[group].npins;
  432. return 0;
  433. }
  434. static int bcm63268_pinctrl_get_func_count(struct pinctrl_dev *pctldev)
  435. {
  436. return ARRAY_SIZE(bcm63268_funcs);
  437. }
  438. static const char *bcm63268_pinctrl_get_func_name(struct pinctrl_dev *pctldev,
  439. unsigned selector)
  440. {
  441. return bcm63268_funcs[selector].name;
  442. }
  443. static int bcm63268_pinctrl_get_groups(struct pinctrl_dev *pctldev,
  444. unsigned selector,
  445. const char * const **groups,
  446. unsigned * const num_groups)
  447. {
  448. *groups = bcm63268_funcs[selector].groups;
  449. *num_groups = bcm63268_funcs[selector].num_groups;
  450. return 0;
  451. }
  452. static void bcm63268_set_gpio(struct bcm63xx_pinctrl *pc, unsigned pin)
  453. {
  454. const struct pinctrl_pin_desc *desc = &bcm63268_pins[pin];
  455. unsigned int basemode = (unsigned long) desc->drv_data;
  456. unsigned int mask = BIT(bcm63xx_bank_pin(pin));
  457. if (basemode)
  458. regmap_update_bits(pc->regs, BCM63268_BASEMODE_REG, basemode,
  459. 0);
  460. if (pin < BCM63XX_BANK_GPIOS) {
  461. /* base mode: 0 => gpio, 1 => mux function */
  462. regmap_update_bits(pc->regs, BCM63268_MODE_REG, mask, 0);
  463. /* pins 0-23 might be muxed to led */
  464. if (pin < BCM63268_NUM_LEDS)
  465. regmap_update_bits(pc->regs, BCM63268_LED_REG, mask,
  466. 0);
  467. } else if (pin < BCM63268_NUM_GPIOS) {
  468. /* ctrl reg: 0 => wifi function, 1 => gpio */
  469. regmap_update_bits(pc->regs, BCM63268_CTRL_REG, mask, mask);
  470. }
  471. }
  472. static int bcm63268_pinctrl_set_mux(struct pinctrl_dev *pctldev,
  473. unsigned selector, unsigned group)
  474. {
  475. struct bcm63xx_pinctrl *pc = pinctrl_dev_get_drvdata(pctldev);
  476. const struct pingroup *pg = &bcm63268_groups[group];
  477. const struct bcm63268_function *f = &bcm63268_funcs[selector];
  478. unsigned i;
  479. unsigned int reg;
  480. unsigned int val, mask;
  481. for (i = 0; i < pg->npins; i++)
  482. bcm63268_set_gpio(pc, pg->pins[i]);
  483. switch (f->reg) {
  484. case BCM63268_LEDCTRL:
  485. reg = BCM63268_LED_REG;
  486. mask = BIT(pg->pins[0]);
  487. val = BIT(pg->pins[0]);
  488. break;
  489. case BCM63268_MODE:
  490. reg = BCM63268_MODE_REG;
  491. mask = BIT(pg->pins[0]);
  492. val = BIT(pg->pins[0]);
  493. break;
  494. case BCM63268_CTRL:
  495. reg = BCM63268_CTRL_REG;
  496. mask = BIT(pg->pins[0]);
  497. val = 0;
  498. break;
  499. case BCM63268_BASEMODE:
  500. reg = BCM63268_BASEMODE_REG;
  501. mask = f->mask;
  502. val = f->mask;
  503. break;
  504. default:
  505. WARN_ON(1);
  506. return -EINVAL;
  507. }
  508. regmap_update_bits(pc->regs, reg, mask, val);
  509. return 0;
  510. }
  511. static int bcm63268_gpio_request_enable(struct pinctrl_dev *pctldev,
  512. struct pinctrl_gpio_range *range,
  513. unsigned offset)
  514. {
  515. struct bcm63xx_pinctrl *pc = pinctrl_dev_get_drvdata(pctldev);
  516. /* disable all functions using this pin */
  517. bcm63268_set_gpio(pc, offset);
  518. return 0;
  519. }
  520. static const struct pinctrl_ops bcm63268_pctl_ops = {
  521. .dt_free_map = pinctrl_utils_free_map,
  522. .dt_node_to_map = pinconf_generic_dt_node_to_map_pin,
  523. .get_group_name = bcm63268_pinctrl_get_group_name,
  524. .get_group_pins = bcm63268_pinctrl_get_group_pins,
  525. .get_groups_count = bcm63268_pinctrl_get_group_count,
  526. };
  527. static const struct pinmux_ops bcm63268_pmx_ops = {
  528. .get_function_groups = bcm63268_pinctrl_get_groups,
  529. .get_function_name = bcm63268_pinctrl_get_func_name,
  530. .get_functions_count = bcm63268_pinctrl_get_func_count,
  531. .gpio_request_enable = bcm63268_gpio_request_enable,
  532. .set_mux = bcm63268_pinctrl_set_mux,
  533. .strict = true,
  534. };
  535. static const struct bcm63xx_pinctrl_soc bcm63268_soc = {
  536. .ngpios = BCM63268_NUM_GPIOS,
  537. .npins = ARRAY_SIZE(bcm63268_pins),
  538. .pctl_ops = &bcm63268_pctl_ops,
  539. .pins = bcm63268_pins,
  540. .pmx_ops = &bcm63268_pmx_ops,
  541. };
  542. static int bcm63268_pinctrl_probe(struct platform_device *pdev)
  543. {
  544. return bcm63xx_pinctrl_probe(pdev, &bcm63268_soc, NULL);
  545. }
  546. static const struct of_device_id bcm63268_pinctrl_match[] = {
  547. { .compatible = "brcm,bcm63268-pinctrl", },
  548. { /* sentinel */ }
  549. };
  550. static struct platform_driver bcm63268_pinctrl_driver = {
  551. .probe = bcm63268_pinctrl_probe,
  552. .driver = {
  553. .name = "bcm63268-pinctrl",
  554. .of_match_table = bcm63268_pinctrl_match,
  555. },
  556. };
  557. builtin_platform_driver(bcm63268_pinctrl_driver);