pinctrl-mt7628.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2019 MediaTek Inc. All Rights Reserved.
  4. *
  5. * Author: Weijie Gao <weijie.gao@mediatek.com>
  6. */
  7. #include <common.h>
  8. #include <dm.h>
  9. #include <asm/global_data.h>
  10. #include <dm/pinctrl.h>
  11. #include <linux/bitops.h>
  12. #include <linux/io.h>
  13. #include "pinctrl-mtmips-common.h"
  14. DECLARE_GLOBAL_DATA_PTR;
  15. #define AGPIO_OFS 0
  16. #define GPIOMODE1_OFS 0x24
  17. #define GPIOMODE2_OFS 0x28
  18. #define EPHY4_1_PAD_SHIFT 17
  19. #define EPHY4_1_PAD_MASK 0x0f
  20. #define EPHY0_SHIFT 16
  21. #define RF_OLT_MODE_SHIFT 12
  22. #define N9_EINT_SRC_SHIFT 9
  23. #define WLED_OD_SHIFT 8
  24. #define REF_CLKO_PAD_SHIFT 4
  25. #define I2S_CLK_PAD_SHIFT 3
  26. #define I2S_WS_PAD_SHIFT 2
  27. #define I2S_SDO_PAD_SHIFT 1
  28. #define I2S_SDI_PAD_SHIFT 0
  29. #define GM4_MASK 3
  30. #define P4LED_K_SHIFT 26
  31. #define P3LED_K_SHIFT 24
  32. #define P2LED_K_SHIFT 22
  33. #define P1LED_K_SHIFT 20
  34. #define P0LED_K_SHIFT 18
  35. #define WLED_K_SHIFT 16
  36. #define P4LED_A_SHIFT 10
  37. #define P3LED_A_SHIFT 8
  38. #define P2LED_A_SHIFT 6
  39. #define P1LED_A_SHIFT 4
  40. #define P0LED_A_SHIFT 2
  41. #define WLED_A_SHIFT 0
  42. #define PWM1_SHIFT 30
  43. #define PWM0_SHIFT 28
  44. #define UART2_SHIFT 26
  45. #define UART1_SHIFT 24
  46. #define I2C_SHIFT 20
  47. #define REFCLK_SHIFT 18
  48. #define PERST_SHIFT 16
  49. #define ESD_SHIFT 15
  50. #define WDT_SHIFT 14
  51. #define SPI_SHIFT 12
  52. #define SDMODE_SHIFT 10
  53. #define UART0_SHIFT 8
  54. #define I2S_SHIFT 6
  55. #define SPI_CS1_SHIFT 4
  56. #define SPIS_SHIFT 2
  57. #define GPIO0_SHIFT 0
  58. #define PAD_PU_G0_REG 0x00
  59. #define PAD_PU_G1_REG 0x04
  60. #define PAD_PD_G0_REG 0x10
  61. #define PAD_PD_G1_REG 0x14
  62. #define PAD_SR_G0_REG 0x20
  63. #define PAD_SR_G1_REG 0x24
  64. #define PAD_SMT_G0_REG 0x30
  65. #define PAD_SMT_G1_REG 0x34
  66. #define PAD_E2_G0_REG 0x40
  67. #define PAD_E2_G1_REG 0x44
  68. #define PAD_E4_G0_REG 0x50
  69. #define PAD_E4_G1_REG 0x54
  70. #define PAD_E8_G0_REG 0x60
  71. #define PAD_E8_G1_REG 0x64
  72. #define PIN_CONFIG_DRIVE_STRENGTH_28 (PIN_CONFIG_END + 1)
  73. #define PIN_CONFIG_DRIVE_STRENGTH_4G (PIN_CONFIG_END + 2)
  74. struct mt7628_pinctrl_priv {
  75. struct mtmips_pinctrl_priv mp;
  76. void __iomem *pcbase;
  77. };
  78. #if CONFIG_IS_ENABLED(PINMUX)
  79. static const struct mtmips_pmx_func ephy4_1_pad_grp[] = {
  80. FUNC("digital", 0xf),
  81. FUNC("analog", 0),
  82. };
  83. static const struct mtmips_pmx_func ephy0_grp[] = {
  84. FUNC("disable", 1),
  85. FUNC("enable", 0),
  86. };
  87. static const struct mtmips_pmx_func rf_olt_grp[] = {
  88. FUNC("enable", 1),
  89. FUNC("disable", 0),
  90. };
  91. static const struct mtmips_pmx_func n9_eint_src_grp[] = {
  92. FUNC("gpio", 1),
  93. FUNC("utif", 0),
  94. };
  95. static const struct mtmips_pmx_func wlen_od_grp[] = {
  96. FUNC("enable", 1),
  97. FUNC("disable", 0),
  98. };
  99. static const struct mtmips_pmx_func ref_clko_grp[] = {
  100. FUNC("digital", 1),
  101. FUNC("analog", 0),
  102. };
  103. static const struct mtmips_pmx_func i2s_clk_grp[] = {
  104. FUNC("digital", 1),
  105. FUNC("analog", 0),
  106. };
  107. static const struct mtmips_pmx_func i2s_ws_grp[] = {
  108. FUNC("digital", 1),
  109. FUNC("analog", 0),
  110. };
  111. static const struct mtmips_pmx_func i2s_sdo_grp[] = {
  112. FUNC("digital", 1),
  113. FUNC("analog", 0),
  114. };
  115. static const struct mtmips_pmx_func i2s_sdi_grp[] = {
  116. FUNC("digital", 1),
  117. FUNC("analog", 0),
  118. };
  119. static const struct mtmips_pmx_func pwm1_grp[] = {
  120. FUNC("sdxc d6", 3),
  121. FUNC("utif", 2),
  122. FUNC("gpio", 1),
  123. FUNC("pwm1", 0),
  124. };
  125. static const struct mtmips_pmx_func pwm0_grp[] = {
  126. FUNC("sdxc d7", 3),
  127. FUNC("utif", 2),
  128. FUNC("gpio", 1),
  129. FUNC("pwm0", 0),
  130. };
  131. static const struct mtmips_pmx_func uart2_grp[] = {
  132. FUNC("sdxc d5 d4", 3),
  133. FUNC("pwm", 2),
  134. FUNC("gpio", 1),
  135. FUNC("uart2", 0),
  136. };
  137. static const struct mtmips_pmx_func uart1_grp[] = {
  138. FUNC("sw_r", 3),
  139. FUNC("pwm", 2),
  140. FUNC("gpio", 1),
  141. FUNC("uart1", 0),
  142. };
  143. static const struct mtmips_pmx_func i2c_grp[] = {
  144. FUNC("-", 3),
  145. FUNC("debug", 2),
  146. FUNC("gpio", 1),
  147. FUNC("i2c", 0),
  148. };
  149. static const struct mtmips_pmx_func refclk_grp[] = {
  150. FUNC("gpio", 1),
  151. FUNC("refclk", 0),
  152. };
  153. static const struct mtmips_pmx_func perst_grp[] = {
  154. FUNC("gpio", 1),
  155. FUNC("perst", 0),
  156. };
  157. static const struct mtmips_pmx_func esd_grp[] = {
  158. FUNC("router", 1),
  159. FUNC("iot", 0),
  160. };
  161. static const struct mtmips_pmx_func wdt_grp[] = {
  162. FUNC("gpio", 1),
  163. FUNC("wdt", 0),
  164. };
  165. static const struct mtmips_pmx_func spi_grp[] = {
  166. FUNC("gpio", 1),
  167. FUNC("spi", 0),
  168. };
  169. static const struct mtmips_pmx_func sd_mode_grp[] = {
  170. FUNC("n9 jtag", 3),
  171. FUNC("utif1", 2),
  172. FUNC("gpio", 1),
  173. FUNC("sdxc", 0),
  174. };
  175. static const struct mtmips_pmx_func uart0_grp[] = {
  176. FUNC("-", 3),
  177. FUNC("-", 2),
  178. FUNC("gpio", 1),
  179. FUNC("uart0", 0),
  180. };
  181. static const struct mtmips_pmx_func i2s_grp[] = {
  182. FUNC("antenna", 3),
  183. FUNC("pcm", 2),
  184. FUNC("gpio", 1),
  185. FUNC("i2s", 0),
  186. };
  187. static const struct mtmips_pmx_func spi_cs1_grp[] = {
  188. FUNC("-", 3),
  189. FUNC("refclk", 2),
  190. FUNC("gpio", 1),
  191. FUNC("spi cs1", 0),
  192. };
  193. static const struct mtmips_pmx_func spis_grp[] = {
  194. FUNC("pwm_uart2", 3),
  195. FUNC("utif", 2),
  196. FUNC("gpio", 1),
  197. FUNC("spis", 0),
  198. };
  199. static const struct mtmips_pmx_func gpio0_grp[] = {
  200. FUNC("perst", 3),
  201. FUNC("refclk", 2),
  202. FUNC("gpio", 1),
  203. FUNC("gpio0", 0),
  204. };
  205. static const struct mtmips_pmx_func wled_a_grp[] = {
  206. FUNC("-", 3),
  207. FUNC("-", 2),
  208. FUNC("gpio", 1),
  209. FUNC("led", 0),
  210. };
  211. static const struct mtmips_pmx_func p0led_a_grp[] = {
  212. FUNC("jtag", 3),
  213. FUNC("rsvd", 2),
  214. FUNC("gpio", 1),
  215. FUNC("led", 0),
  216. };
  217. static const struct mtmips_pmx_func p1led_a_grp[] = {
  218. FUNC("jtag", 3),
  219. FUNC("utif", 2),
  220. FUNC("gpio", 1),
  221. FUNC("led", 0),
  222. };
  223. static const struct mtmips_pmx_func p2led_a_grp[] = {
  224. FUNC("jtag", 3),
  225. FUNC("utif", 2),
  226. FUNC("gpio", 1),
  227. FUNC("led", 0),
  228. };
  229. static const struct mtmips_pmx_func p3led_a_grp[] = {
  230. FUNC("jtag", 3),
  231. FUNC("utif", 2),
  232. FUNC("gpio", 1),
  233. FUNC("led", 0),
  234. };
  235. static const struct mtmips_pmx_func p4led_a_grp[] = {
  236. FUNC("jtag", 3),
  237. FUNC("utif", 2),
  238. FUNC("gpio", 1),
  239. FUNC("led", 0),
  240. };
  241. static const struct mtmips_pmx_func wled_k_grp[] = {
  242. FUNC("-", 3),
  243. FUNC("-", 2),
  244. FUNC("gpio", 1),
  245. FUNC("led", 0),
  246. };
  247. static const struct mtmips_pmx_func p0led_k_grp[] = {
  248. FUNC("jtag", 3),
  249. FUNC("rsvd", 2),
  250. FUNC("gpio", 1),
  251. FUNC("led", 0),
  252. };
  253. static const struct mtmips_pmx_func p1led_k_grp[] = {
  254. FUNC("jtag", 3),
  255. FUNC("utif", 2),
  256. FUNC("gpio", 1),
  257. FUNC("led", 0),
  258. };
  259. static const struct mtmips_pmx_func p2led_k_grp[] = {
  260. FUNC("jtag", 3),
  261. FUNC("utif", 2),
  262. FUNC("gpio", 1),
  263. FUNC("led", 0),
  264. };
  265. static const struct mtmips_pmx_func p3led_k_grp[] = {
  266. FUNC("jtag", 3),
  267. FUNC("utif", 2),
  268. FUNC("gpio", 1),
  269. FUNC("led", 0),
  270. };
  271. static const struct mtmips_pmx_func p4led_k_grp[] = {
  272. FUNC("jtag", 3),
  273. FUNC("utif", 2),
  274. FUNC("gpio", 1),
  275. FUNC("led", 0),
  276. };
  277. static const struct mtmips_pmx_group mt7628_pinmux_data[] = {
  278. GRP("ephy4_1_pad", ephy4_1_pad_grp, AGPIO_OFS, EPHY4_1_PAD_SHIFT,
  279. EPHY4_1_PAD_MASK),
  280. GRP("ephy0", ephy0_grp, AGPIO_OFS, EPHY0_SHIFT, 1),
  281. GRP("rf_olt", rf_olt_grp, AGPIO_OFS, RF_OLT_MODE_SHIFT, 1),
  282. GRP("n9_eint_src", n9_eint_src_grp, AGPIO_OFS, N9_EINT_SRC_SHIFT, 1),
  283. GRP("wlen_od", wlen_od_grp, AGPIO_OFS, WLED_OD_SHIFT, 1),
  284. GRP("ref_clko_pad", ref_clko_grp, AGPIO_OFS, REF_CLKO_PAD_SHIFT, 1),
  285. GRP("i2s_clk_pad", i2s_clk_grp, AGPIO_OFS, I2S_CLK_PAD_SHIFT, 1),
  286. GRP("i2s_ws_pad", i2s_ws_grp, AGPIO_OFS, I2S_WS_PAD_SHIFT, 1),
  287. GRP("i2s_sdo_pad", i2s_sdo_grp, AGPIO_OFS, I2S_SDO_PAD_SHIFT, 1),
  288. GRP("i2s_sdi_pad", i2s_sdi_grp, AGPIO_OFS, I2S_SDI_PAD_SHIFT, 1),
  289. GRP("pwm1", pwm1_grp, GPIOMODE1_OFS, PWM1_SHIFT, GM4_MASK),
  290. GRP("pwm0", pwm0_grp, GPIOMODE1_OFS, PWM0_SHIFT, GM4_MASK),
  291. GRP("uart2", uart2_grp, GPIOMODE1_OFS, UART2_SHIFT, GM4_MASK),
  292. GRP("uart1", uart1_grp, GPIOMODE1_OFS, UART1_SHIFT, GM4_MASK),
  293. GRP("i2c", i2c_grp, GPIOMODE1_OFS, I2C_SHIFT, GM4_MASK),
  294. GRP("refclk", refclk_grp, GPIOMODE1_OFS, REFCLK_SHIFT, 1),
  295. GRP("perst", perst_grp, GPIOMODE1_OFS, PERST_SHIFT, 1),
  296. GRP("sd router", esd_grp, GPIOMODE1_OFS, ESD_SHIFT, 1),
  297. GRP("wdt", wdt_grp, GPIOMODE1_OFS, WDT_SHIFT, 1),
  298. GRP("spi", spi_grp, GPIOMODE1_OFS, SPI_SHIFT, 1),
  299. GRP("sdmode", sd_mode_grp, GPIOMODE1_OFS, SDMODE_SHIFT, GM4_MASK),
  300. GRP("uart0", uart0_grp, GPIOMODE1_OFS, UART0_SHIFT, GM4_MASK),
  301. GRP("i2s", i2s_grp, GPIOMODE1_OFS, I2S_SHIFT, GM4_MASK),
  302. GRP("spi cs1", spi_cs1_grp, GPIOMODE1_OFS, SPI_CS1_SHIFT, GM4_MASK),
  303. GRP("spis", spis_grp, GPIOMODE1_OFS, SPIS_SHIFT, GM4_MASK),
  304. GRP("gpio0", gpio0_grp, GPIOMODE1_OFS, GPIO0_SHIFT, GM4_MASK),
  305. GRP("wled_a", wled_a_grp, GPIOMODE2_OFS, WLED_A_SHIFT, GM4_MASK),
  306. GRP("p0led_a", p0led_a_grp, GPIOMODE2_OFS, P0LED_A_SHIFT, GM4_MASK),
  307. GRP("p1led_a", p1led_a_grp, GPIOMODE2_OFS, P1LED_A_SHIFT, GM4_MASK),
  308. GRP("p2led_a", p2led_a_grp, GPIOMODE2_OFS, P2LED_A_SHIFT, GM4_MASK),
  309. GRP("p3led_a", p3led_a_grp, GPIOMODE2_OFS, P3LED_A_SHIFT, GM4_MASK),
  310. GRP("p4led_a", p4led_a_grp, GPIOMODE2_OFS, P4LED_A_SHIFT, GM4_MASK),
  311. GRP("wled_k", wled_k_grp, GPIOMODE2_OFS, WLED_K_SHIFT, GM4_MASK),
  312. GRP("p0led_k", p0led_k_grp, GPIOMODE2_OFS, P0LED_K_SHIFT, GM4_MASK),
  313. GRP("p1led_k", p1led_k_grp, GPIOMODE2_OFS, P1LED_K_SHIFT, GM4_MASK),
  314. GRP("p2led_k", p2led_k_grp, GPIOMODE2_OFS, P2LED_K_SHIFT, GM4_MASK),
  315. GRP("p3led_k", p3led_k_grp, GPIOMODE2_OFS, P3LED_K_SHIFT, GM4_MASK),
  316. GRP("p4led_k", p4led_k_grp, GPIOMODE2_OFS, P4LED_K_SHIFT, GM4_MASK),
  317. };
  318. static int mt7628_get_groups_count(struct udevice *dev)
  319. {
  320. return ARRAY_SIZE(mt7628_pinmux_data);
  321. }
  322. static const char *mt7628_get_group_name(struct udevice *dev,
  323. unsigned int selector)
  324. {
  325. return mt7628_pinmux_data[selector].name;
  326. }
  327. #endif /* CONFIG_IS_ENABLED(PINMUX) */
  328. #if CONFIG_IS_ENABLED(PINCONF)
  329. static const struct pinconf_param mt7628_conf_params[] = {
  330. { "bias-disable", PIN_CONFIG_BIAS_DISABLE, 0 },
  331. { "bias-pull-up", PIN_CONFIG_BIAS_PULL_UP, 1 },
  332. { "bias-pull-down", PIN_CONFIG_BIAS_PULL_DOWN, 1 },
  333. { "input-schmitt-enable", PIN_CONFIG_INPUT_SCHMITT_ENABLE, 1 },
  334. { "input-schmitt-disable", PIN_CONFIG_INPUT_SCHMITT_ENABLE, 0 },
  335. { "drive-strength-28", PIN_CONFIG_DRIVE_STRENGTH_28, 0 },
  336. { "drive-strength-4g", PIN_CONFIG_DRIVE_STRENGTH_4G, 0 },
  337. { "slew-rate", PIN_CONFIG_SLEW_RATE, 0 },
  338. };
  339. static const char *const mt7628_pins[] = {
  340. "i2s_sdi",
  341. "i2s_sdo",
  342. "i2s_ws",
  343. "i2s_clk",
  344. "i2s_sclk",
  345. "i2c_sd",
  346. "spi_cs1",
  347. "spi_clk",
  348. "spi_mosi",
  349. "spi_miso",
  350. "spi_cs0",
  351. "gpio0",
  352. "uart0_txd",
  353. "uart0_rxd",
  354. "spis_cs",
  355. "spis_clk",
  356. "spis_miso",
  357. "spis_mosi",
  358. "pwm_ch0",
  359. "pwm_ch1",
  360. "uart2_txd",
  361. "uart2_rxd",
  362. "sd_wp",
  363. "sd_cd",
  364. "sd_d1",
  365. "sd_d0",
  366. "sd_clk",
  367. "sd_cmd",
  368. "sd_d3",
  369. "sd_d2",
  370. "ephy_led4_k",
  371. "ephy_led3_k",
  372. "ephy_led2_k",
  373. "ephy_led1_k",
  374. "ephy_led0_k",
  375. "wled_k",
  376. "perst_n",
  377. "co_clko",
  378. "wdt",
  379. "ephy_led4_a",
  380. "ephy_led3_a",
  381. "ephy_led2_a",
  382. "ephy_led1_a",
  383. "ephy_led0_a",
  384. "wled_a",
  385. "uart1_txd",
  386. "uart1_rxd",
  387. };
  388. static const u32 mt7628_drv_strength_28_tbl[] = {2, 4, 6, 8};
  389. static const u32 mt7628_drv_strength_4g_tbl[] = {4, 8, 12, 16};
  390. static int mt7628_set_drv_strength(void __iomem *base, u32 val, u32 bit,
  391. const u32 tbl[], u32 reg_lo, u32 reg_hi)
  392. {
  393. int i;
  394. for (i = 0; i < 4; i++)
  395. if (tbl[i] == val)
  396. break;
  397. if (i >= 4)
  398. return -EINVAL;
  399. clrsetbits_32(base + reg_lo, BIT(bit), (i & 1) << bit);
  400. clrsetbits_32(base + reg_hi, BIT(bit), ((i >> 1) & 1) << bit);
  401. return 0;
  402. }
  403. static int mt7628_get_pins_count(struct udevice *dev)
  404. {
  405. return ARRAY_SIZE(mt7628_pins);
  406. }
  407. static const char *mt7628_get_pin_name(struct udevice *dev,
  408. unsigned int selector)
  409. {
  410. return mt7628_pins[selector];
  411. }
  412. static int mt7628_pinconf_set(struct udevice *dev, unsigned int pin_selector,
  413. unsigned int param, unsigned int argument)
  414. {
  415. struct mt7628_pinctrl_priv *priv = dev_get_priv(dev);
  416. u32 offs, bit;
  417. int ret = 0;
  418. offs = (pin_selector / 32) * 4;
  419. bit = pin_selector % 32;
  420. switch (param) {
  421. case PIN_CONFIG_BIAS_DISABLE:
  422. clrbits_32(priv->pcbase + offs + PAD_PU_G0_REG, BIT(bit));
  423. clrbits_32(priv->pcbase + offs + PAD_PD_G0_REG, BIT(bit));
  424. break;
  425. case PIN_CONFIG_BIAS_PULL_UP:
  426. setbits_32(priv->pcbase + offs + PAD_PU_G0_REG, BIT(bit));
  427. clrbits_32(priv->pcbase + offs + PAD_PD_G0_REG, BIT(bit));
  428. break;
  429. case PIN_CONFIG_BIAS_PULL_DOWN:
  430. clrbits_32(priv->pcbase + offs + PAD_PU_G0_REG, BIT(bit));
  431. setbits_32(priv->pcbase + offs + PAD_PD_G0_REG, BIT(bit));
  432. break;
  433. case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
  434. clrsetbits_32(priv->pcbase + offs + PAD_SMT_G0_REG,
  435. BIT(bit), (!!argument) << bit);
  436. break;
  437. case PIN_CONFIG_DRIVE_STRENGTH_28:
  438. ret = mt7628_set_drv_strength(priv->pcbase + offs, argument,
  439. bit, mt7628_drv_strength_28_tbl,
  440. PAD_E2_G0_REG, PAD_E4_G0_REG);
  441. break;
  442. case PIN_CONFIG_DRIVE_STRENGTH_4G:
  443. ret = mt7628_set_drv_strength(priv->pcbase + offs, argument,
  444. bit, mt7628_drv_strength_4g_tbl,
  445. PAD_E4_G0_REG, PAD_E8_G0_REG);
  446. break;
  447. case PIN_CONFIG_SLEW_RATE:
  448. clrsetbits_32(priv->pcbase + offs + PAD_SR_G0_REG,
  449. BIT(bit), (!!argument) << bit);
  450. break;
  451. default:
  452. ret = -EINVAL;
  453. }
  454. return ret;
  455. }
  456. #endif
  457. static int mt7628_pinctrl_probe(struct udevice *dev)
  458. {
  459. struct mt7628_pinctrl_priv *priv = dev_get_priv(dev);
  460. int ret = 0;
  461. #if CONFIG_IS_ENABLED(PINMUX)
  462. ret = mtmips_pinctrl_probe(&priv->mp, ARRAY_SIZE(mt7628_pinmux_data),
  463. mt7628_pinmux_data);
  464. #endif /* CONFIG_IS_ENABLED(PINMUX) */
  465. return ret;
  466. }
  467. static int mt7628_pinctrl_of_to_plat(struct udevice *dev)
  468. {
  469. struct mt7628_pinctrl_priv *priv = dev_get_priv(dev);
  470. priv->mp.base = (void __iomem *)dev_remap_addr_index(dev, 0);
  471. if (!priv->mp.base)
  472. return -EINVAL;
  473. priv->pcbase = (void __iomem *)dev_remap_addr_index(dev, 1);
  474. if (!priv->pcbase)
  475. return -EINVAL;
  476. return 0;
  477. }
  478. static const struct pinctrl_ops mt7628_pinctrl_ops = {
  479. #if CONFIG_IS_ENABLED(PINMUX)
  480. .get_groups_count = mt7628_get_groups_count,
  481. .get_group_name = mt7628_get_group_name,
  482. .get_functions_count = mtmips_get_functions_count,
  483. .get_function_name = mtmips_get_function_name,
  484. .pinmux_group_set = mtmips_pinmux_group_set,
  485. #endif /* CONFIG_IS_ENABLED(PINMUX) */
  486. #if CONFIG_IS_ENABLED(PINCONF)
  487. .pinconf_num_params = ARRAY_SIZE(mt7628_conf_params),
  488. .pinconf_params = mt7628_conf_params,
  489. .get_pins_count = mt7628_get_pins_count,
  490. .get_pin_name = mt7628_get_pin_name,
  491. .pinconf_set = mt7628_pinconf_set,
  492. #endif /* CONFIG_IS_ENABLED(PINCONF) */
  493. .set_state = pinctrl_generic_set_state,
  494. };
  495. static const struct udevice_id mt7628_pinctrl_ids[] = {
  496. { .compatible = "mediatek,mt7628-pinctrl" },
  497. { }
  498. };
  499. U_BOOT_DRIVER(mt7628_pinctrl) = {
  500. .name = "mt7628-pinctrl",
  501. .id = UCLASS_PINCTRL,
  502. .of_match = mt7628_pinctrl_ids,
  503. .of_to_plat = mt7628_pinctrl_of_to_plat,
  504. .ops = &mt7628_pinctrl_ops,
  505. .probe = mt7628_pinctrl_probe,
  506. .priv_auto = sizeof(struct mt7628_pinctrl_priv),
  507. };