pinctrl-tps6594.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Pinmux and GPIO driver for tps6594 PMIC
  4. *
  5. * Copyright (C) 2023 BayLibre Incorporated - https://www.baylibre.com/
  6. */
  7. #include <linux/gpio/driver.h>
  8. #include <linux/gpio/regmap.h>
  9. #include <linux/module.h>
  10. #include <linux/pinctrl/pinmux.h>
  11. #include <linux/platform_device.h>
  12. #include <linux/mod_devicetable.h>
  13. #include <linux/mfd/tps6594.h>
  14. #define TPS6594_PINCTRL_GPIO_FUNCTION 0
  15. #define TPS6594_PINCTRL_SCL_I2C2_CS_SPI_FUNCTION 1
  16. #define TPS6594_PINCTRL_TRIG_WDOG_FUNCTION 1
  17. #define TPS6594_PINCTRL_CLK32KOUT_FUNCTION 1
  18. #define TPS6594_PINCTRL_SCLK_SPMI_FUNCTION 1
  19. #define TPS6594_PINCTRL_SDATA_SPMI_FUNCTION 1
  20. #define TPS6594_PINCTRL_NERR_MCU_FUNCTION 1
  21. #define TPS6594_PINCTRL_PDOG_FUNCTION 1
  22. #define TPS6594_PINCTRL_SYNCCLKIN_FUNCTION 1
  23. #define TPS6594_PINCTRL_NRSTOUT_SOC_FUNCTION 2
  24. #define TPS6594_PINCTRL_SYNCCLKOUT_FUNCTION 2
  25. #define TPS6594_PINCTRL_SDA_I2C2_SDO_SPI_FUNCTION 2
  26. #define TPS6594_PINCTRL_NERR_SOC_FUNCTION 2
  27. #define TPS6594_PINCTRL_DISABLE_WDOG_FUNCTION 3
  28. #define TPS6594_PINCTRL_NSLEEP1_FUNCTION 4
  29. #define TPS6594_PINCTRL_NSLEEP2_FUNCTION 5
  30. #define TPS6594_PINCTRL_WKUP1_FUNCTION 6
  31. #define TPS6594_PINCTRL_WKUP2_FUNCTION 7
  32. /* Special muxval for recalcitrant pins */
  33. #define TPS6594_PINCTRL_DISABLE_WDOG_FUNCTION_GPIO8 2
  34. #define TPS6594_PINCTRL_SYNCCLKOUT_FUNCTION_GPIO8 3
  35. #define TPS6594_PINCTRL_CLK32KOUT_FUNCTION_GPIO9 3
  36. /* TPS65224 pin muxval */
  37. #define TPS65224_PINCTRL_SDA_I2C2_SDO_SPI_FUNCTION 1
  38. #define TPS65224_PINCTRL_SCL_I2C2_CS_SPI_FUNCTION 1
  39. #define TPS65224_PINCTRL_VMON1_FUNCTION 1
  40. #define TPS65224_PINCTRL_VMON2_FUNCTION 1
  41. #define TPS65224_PINCTRL_WKUP_FUNCTION 1
  42. #define TPS65224_PINCTRL_NSLEEP2_FUNCTION 2
  43. #define TPS65224_PINCTRL_NSLEEP1_FUNCTION 2
  44. #define TPS65224_PINCTRL_SYNCCLKIN_FUNCTION 2
  45. #define TPS65224_PINCTRL_NERR_MCU_FUNCTION 2
  46. #define TPS65224_PINCTRL_NINT_FUNCTION 3
  47. #define TPS65224_PINCTRL_TRIG_WDOG_FUNCTION 3
  48. #define TPS65224_PINCTRL_PB_FUNCTION 3
  49. #define TPS65224_PINCTRL_ADC_IN_FUNCTION 3
  50. /* TPS65224 Special muxval for recalcitrant pins */
  51. #define TPS65224_PINCTRL_NSLEEP2_FUNCTION_GPIO5 1
  52. #define TPS65224_PINCTRL_WKUP_FUNCTION_GPIO5 4
  53. #define TPS65224_PINCTRL_SYNCCLKIN_FUNCTION_GPIO5 3
  54. #define TPS6594_OFFSET_GPIO_SEL 5
  55. #define TPS65224_NGPIO_PER_REG 6
  56. #define TPS6594_NGPIO_PER_REG 8
  57. #define FUNCTION(dev_name, fname, v) \
  58. { \
  59. .pinfunction = PINCTRL_PINFUNCTION(#fname, \
  60. dev_name##_##fname##_func_group_names, \
  61. ARRAY_SIZE(dev_name##_##fname##_func_group_names)),\
  62. .muxval = v, \
  63. }
  64. static const struct pinctrl_pin_desc tps6594_pins[] = {
  65. PINCTRL_PIN(0, "GPIO0"), PINCTRL_PIN(1, "GPIO1"),
  66. PINCTRL_PIN(2, "GPIO2"), PINCTRL_PIN(3, "GPIO3"),
  67. PINCTRL_PIN(4, "GPIO4"), PINCTRL_PIN(5, "GPIO5"),
  68. PINCTRL_PIN(6, "GPIO6"), PINCTRL_PIN(7, "GPIO7"),
  69. PINCTRL_PIN(8, "GPIO8"), PINCTRL_PIN(9, "GPIO9"),
  70. PINCTRL_PIN(10, "GPIO10"),
  71. };
  72. static const char *const tps6594_gpio_func_group_names[] = {
  73. "GPIO0", "GPIO1", "GPIO2", "GPIO3", "GPIO4", "GPIO5",
  74. "GPIO6", "GPIO7", "GPIO8", "GPIO9", "GPIO10",
  75. };
  76. static const char *const tps6594_nsleep1_func_group_names[] = {
  77. "GPIO0", "GPIO1", "GPIO2", "GPIO3", "GPIO4", "GPIO5",
  78. "GPIO6", "GPIO7", "GPIO8", "GPIO9", "GPIO10",
  79. };
  80. static const char *const tps6594_nsleep2_func_group_names[] = {
  81. "GPIO0", "GPIO1", "GPIO2", "GPIO3", "GPIO4", "GPIO5",
  82. "GPIO6", "GPIO7", "GPIO8", "GPIO9", "GPIO10",
  83. };
  84. static const char *const tps6594_wkup1_func_group_names[] = {
  85. "GPIO0", "GPIO1", "GPIO2", "GPIO3", "GPIO4", "GPIO5",
  86. "GPIO6", "GPIO7", "GPIO8", "GPIO9", "GPIO10",
  87. };
  88. static const char *const tps6594_wkup2_func_group_names[] = {
  89. "GPIO0", "GPIO1", "GPIO2", "GPIO3", "GPIO4", "GPIO5",
  90. "GPIO6", "GPIO7", "GPIO8", "GPIO9", "GPIO10",
  91. };
  92. static const char *const tps6594_scl_i2c2_cs_spi_func_group_names[] = {
  93. "GPIO0",
  94. "GPIO1",
  95. };
  96. static const char *const tps6594_nrstout_soc_func_group_names[] = {
  97. "GPIO0",
  98. "GPIO10",
  99. };
  100. static const char *const tps6594_trig_wdog_func_group_names[] = {
  101. "GPIO1",
  102. "GPIO10",
  103. };
  104. static const char *const tps6594_sda_i2c2_sdo_spi_func_group_names[] = {
  105. "GPIO1",
  106. };
  107. static const char *const tps6594_clk32kout_func_group_names[] = {
  108. "GPIO2",
  109. "GPIO3",
  110. "GPIO7",
  111. };
  112. static const char *const tps6594_nerr_soc_func_group_names[] = {
  113. "GPIO2",
  114. };
  115. static const char *const tps6594_sclk_spmi_func_group_names[] = {
  116. "GPIO4",
  117. };
  118. static const char *const tps6594_sdata_spmi_func_group_names[] = {
  119. "GPIO5",
  120. };
  121. static const char *const tps6594_nerr_mcu_func_group_names[] = {
  122. "GPIO6",
  123. };
  124. static const char *const tps6594_syncclkout_func_group_names[] = {
  125. "GPIO7",
  126. "GPIO9",
  127. };
  128. static const char *const tps6594_disable_wdog_func_group_names[] = {
  129. "GPIO7",
  130. "GPIO8",
  131. };
  132. static const char *const tps6594_pdog_func_group_names[] = {
  133. "GPIO8",
  134. };
  135. static const char *const tps6594_syncclkin_func_group_names[] = {
  136. "GPIO9",
  137. };
  138. static const struct pinctrl_pin_desc tps65224_pins[] = {
  139. PINCTRL_PIN(0, "GPIO0"), PINCTRL_PIN(1, "GPIO1"),
  140. PINCTRL_PIN(2, "GPIO2"), PINCTRL_PIN(3, "GPIO3"),
  141. PINCTRL_PIN(4, "GPIO4"), PINCTRL_PIN(5, "GPIO5"),
  142. };
  143. static const char *const tps65224_gpio_func_group_names[] = {
  144. "GPIO0", "GPIO1", "GPIO2", "GPIO3", "GPIO4", "GPIO5",
  145. };
  146. static const char *const tps65224_sda_i2c2_sdo_spi_func_group_names[] = {
  147. "GPIO0",
  148. };
  149. static const char *const tps65224_nsleep2_func_group_names[] = {
  150. "GPIO0", "GPIO5",
  151. };
  152. static const char *const tps65224_nint_func_group_names[] = {
  153. "GPIO0",
  154. };
  155. static const char *const tps65224_scl_i2c2_cs_spi_func_group_names[] = {
  156. "GPIO1",
  157. };
  158. static const char *const tps65224_nsleep1_func_group_names[] = {
  159. "GPIO1", "GPIO2", "GPIO3",
  160. };
  161. static const char *const tps65224_trig_wdog_func_group_names[] = {
  162. "GPIO1",
  163. };
  164. static const char *const tps65224_vmon1_func_group_names[] = {
  165. "GPIO2",
  166. };
  167. static const char *const tps65224_pb_func_group_names[] = {
  168. "GPIO2",
  169. };
  170. static const char *const tps65224_vmon2_func_group_names[] = {
  171. "GPIO3",
  172. };
  173. static const char *const tps65224_adc_in_func_group_names[] = {
  174. "GPIO3", "GPIO4",
  175. };
  176. static const char *const tps65224_wkup_func_group_names[] = {
  177. "GPIO4", "GPIO5",
  178. };
  179. static const char *const tps65224_syncclkin_func_group_names[] = {
  180. "GPIO4", "GPIO5",
  181. };
  182. static const char *const tps65224_nerr_mcu_func_group_names[] = {
  183. "GPIO5",
  184. };
  185. static const char *const tps652g1_cs_spi_func_group_names[] = {
  186. "GPIO1",
  187. };
  188. struct tps6594_pinctrl_function {
  189. struct pinfunction pinfunction;
  190. u8 muxval;
  191. };
  192. struct muxval_remap {
  193. unsigned int group;
  194. u8 muxval;
  195. u8 remap;
  196. };
  197. static struct muxval_remap tps65224_muxval_remap[] = {
  198. {5, TPS6594_PINCTRL_DISABLE_WDOG_FUNCTION, TPS65224_PINCTRL_WKUP_FUNCTION_GPIO5},
  199. {5, TPS65224_PINCTRL_SYNCCLKIN_FUNCTION, TPS65224_PINCTRL_SYNCCLKIN_FUNCTION_GPIO5},
  200. {5, TPS65224_PINCTRL_NSLEEP2_FUNCTION, TPS65224_PINCTRL_NSLEEP2_FUNCTION_GPIO5},
  201. };
  202. static struct muxval_remap tps6594_muxval_remap[] = {
  203. {8, TPS6594_PINCTRL_DISABLE_WDOG_FUNCTION, TPS6594_PINCTRL_DISABLE_WDOG_FUNCTION_GPIO8},
  204. {8, TPS6594_PINCTRL_SYNCCLKOUT_FUNCTION, TPS6594_PINCTRL_SYNCCLKOUT_FUNCTION_GPIO8},
  205. {9, TPS6594_PINCTRL_CLK32KOUT_FUNCTION, TPS6594_PINCTRL_CLK32KOUT_FUNCTION_GPIO9},
  206. };
  207. static const struct tps6594_pinctrl_function pinctrl_functions[] = {
  208. FUNCTION(tps6594, gpio, TPS6594_PINCTRL_GPIO_FUNCTION),
  209. FUNCTION(tps6594, nsleep1, TPS6594_PINCTRL_NSLEEP1_FUNCTION),
  210. FUNCTION(tps6594, nsleep2, TPS6594_PINCTRL_NSLEEP2_FUNCTION),
  211. FUNCTION(tps6594, wkup1, TPS6594_PINCTRL_WKUP1_FUNCTION),
  212. FUNCTION(tps6594, wkup2, TPS6594_PINCTRL_WKUP2_FUNCTION),
  213. FUNCTION(tps6594, scl_i2c2_cs_spi, TPS6594_PINCTRL_SCL_I2C2_CS_SPI_FUNCTION),
  214. FUNCTION(tps6594, nrstout_soc, TPS6594_PINCTRL_NRSTOUT_SOC_FUNCTION),
  215. FUNCTION(tps6594, trig_wdog, TPS6594_PINCTRL_TRIG_WDOG_FUNCTION),
  216. FUNCTION(tps6594, sda_i2c2_sdo_spi, TPS6594_PINCTRL_SDA_I2C2_SDO_SPI_FUNCTION),
  217. FUNCTION(tps6594, clk32kout, TPS6594_PINCTRL_CLK32KOUT_FUNCTION),
  218. FUNCTION(tps6594, nerr_soc, TPS6594_PINCTRL_NERR_SOC_FUNCTION),
  219. FUNCTION(tps6594, sclk_spmi, TPS6594_PINCTRL_SCLK_SPMI_FUNCTION),
  220. FUNCTION(tps6594, sdata_spmi, TPS6594_PINCTRL_SDATA_SPMI_FUNCTION),
  221. FUNCTION(tps6594, nerr_mcu, TPS6594_PINCTRL_NERR_MCU_FUNCTION),
  222. FUNCTION(tps6594, syncclkout, TPS6594_PINCTRL_SYNCCLKOUT_FUNCTION),
  223. FUNCTION(tps6594, disable_wdog, TPS6594_PINCTRL_DISABLE_WDOG_FUNCTION),
  224. FUNCTION(tps6594, pdog, TPS6594_PINCTRL_PDOG_FUNCTION),
  225. FUNCTION(tps6594, syncclkin, TPS6594_PINCTRL_SYNCCLKIN_FUNCTION),
  226. };
  227. static const struct tps6594_pinctrl_function tps65224_pinctrl_functions[] = {
  228. FUNCTION(tps65224, gpio, TPS6594_PINCTRL_GPIO_FUNCTION),
  229. FUNCTION(tps65224, sda_i2c2_sdo_spi, TPS65224_PINCTRL_SDA_I2C2_SDO_SPI_FUNCTION),
  230. FUNCTION(tps65224, nsleep2, TPS65224_PINCTRL_NSLEEP2_FUNCTION),
  231. FUNCTION(tps65224, nint, TPS65224_PINCTRL_NINT_FUNCTION),
  232. FUNCTION(tps65224, scl_i2c2_cs_spi, TPS65224_PINCTRL_SCL_I2C2_CS_SPI_FUNCTION),
  233. FUNCTION(tps65224, nsleep1, TPS65224_PINCTRL_NSLEEP1_FUNCTION),
  234. FUNCTION(tps65224, trig_wdog, TPS65224_PINCTRL_TRIG_WDOG_FUNCTION),
  235. FUNCTION(tps65224, vmon1, TPS65224_PINCTRL_VMON1_FUNCTION),
  236. FUNCTION(tps65224, pb, TPS65224_PINCTRL_PB_FUNCTION),
  237. FUNCTION(tps65224, vmon2, TPS65224_PINCTRL_VMON2_FUNCTION),
  238. FUNCTION(tps65224, adc_in, TPS65224_PINCTRL_ADC_IN_FUNCTION),
  239. FUNCTION(tps65224, wkup, TPS65224_PINCTRL_WKUP_FUNCTION),
  240. FUNCTION(tps65224, syncclkin, TPS65224_PINCTRL_SYNCCLKIN_FUNCTION),
  241. FUNCTION(tps65224, nerr_mcu, TPS65224_PINCTRL_NERR_MCU_FUNCTION),
  242. };
  243. static const struct tps6594_pinctrl_function tps652g1_pinctrl_functions[] = {
  244. FUNCTION(tps65224, gpio, TPS6594_PINCTRL_GPIO_FUNCTION),
  245. FUNCTION(tps65224, sda_i2c2_sdo_spi, TPS65224_PINCTRL_SDA_I2C2_SDO_SPI_FUNCTION),
  246. FUNCTION(tps65224, nsleep2, TPS65224_PINCTRL_NSLEEP2_FUNCTION),
  247. FUNCTION(tps65224, nint, TPS65224_PINCTRL_NINT_FUNCTION),
  248. FUNCTION(tps652g1, cs_spi, TPS65224_PINCTRL_SCL_I2C2_CS_SPI_FUNCTION),
  249. FUNCTION(tps65224, nsleep1, TPS65224_PINCTRL_NSLEEP1_FUNCTION),
  250. FUNCTION(tps65224, pb, TPS65224_PINCTRL_PB_FUNCTION),
  251. FUNCTION(tps65224, wkup, TPS65224_PINCTRL_WKUP_FUNCTION),
  252. FUNCTION(tps65224, syncclkin, TPS65224_PINCTRL_SYNCCLKIN_FUNCTION),
  253. };
  254. struct tps6594_pinctrl {
  255. struct tps6594 *tps;
  256. struct gpio_regmap *gpio_regmap;
  257. struct pinctrl_dev *pctl_dev;
  258. const struct tps6594_pinctrl_function *funcs;
  259. const struct pinctrl_pin_desc *pins;
  260. int func_cnt;
  261. int num_pins;
  262. u8 mux_sel_mask;
  263. unsigned int remap_cnt;
  264. struct muxval_remap *remap;
  265. };
  266. static struct tps6594_pinctrl tps652g1_template_pinctrl = {
  267. .funcs = tps652g1_pinctrl_functions,
  268. .func_cnt = ARRAY_SIZE(tps652g1_pinctrl_functions),
  269. .pins = tps65224_pins,
  270. .num_pins = ARRAY_SIZE(tps65224_pins),
  271. .mux_sel_mask = TPS65224_MASK_GPIO_SEL,
  272. .remap = tps65224_muxval_remap,
  273. .remap_cnt = ARRAY_SIZE(tps65224_muxval_remap),
  274. };
  275. static struct tps6594_pinctrl tps65224_template_pinctrl = {
  276. .funcs = tps65224_pinctrl_functions,
  277. .func_cnt = ARRAY_SIZE(tps65224_pinctrl_functions),
  278. .pins = tps65224_pins,
  279. .num_pins = ARRAY_SIZE(tps65224_pins),
  280. .mux_sel_mask = TPS65224_MASK_GPIO_SEL,
  281. .remap = tps65224_muxval_remap,
  282. .remap_cnt = ARRAY_SIZE(tps65224_muxval_remap),
  283. };
  284. static struct tps6594_pinctrl tps6594_template_pinctrl = {
  285. .funcs = pinctrl_functions,
  286. .func_cnt = ARRAY_SIZE(pinctrl_functions),
  287. .pins = tps6594_pins,
  288. .num_pins = ARRAY_SIZE(tps6594_pins),
  289. .mux_sel_mask = TPS6594_MASK_GPIO_SEL,
  290. .remap = tps6594_muxval_remap,
  291. .remap_cnt = ARRAY_SIZE(tps6594_muxval_remap),
  292. };
  293. static int tps6594_gpio_regmap_xlate(struct gpio_regmap *gpio,
  294. unsigned int base, unsigned int offset,
  295. unsigned int *reg, unsigned int *mask)
  296. {
  297. unsigned int line = offset % 8;
  298. unsigned int stride = offset / 8;
  299. switch (base) {
  300. case TPS6594_REG_GPIOX_CONF(0):
  301. *reg = TPS6594_REG_GPIOX_CONF(offset);
  302. *mask = TPS6594_BIT_GPIO_DIR;
  303. return 0;
  304. case TPS6594_REG_GPIO_IN_1:
  305. case TPS6594_REG_GPIO_OUT_1:
  306. *reg = base + stride;
  307. *mask = BIT(line);
  308. return 0;
  309. default:
  310. return -EINVAL;
  311. }
  312. }
  313. static int tps6594_pmx_func_cnt(struct pinctrl_dev *pctldev)
  314. {
  315. struct tps6594_pinctrl *pinctrl = pinctrl_dev_get_drvdata(pctldev);
  316. return pinctrl->func_cnt;
  317. }
  318. static const char *tps6594_pmx_func_name(struct pinctrl_dev *pctldev,
  319. unsigned int selector)
  320. {
  321. struct tps6594_pinctrl *pinctrl = pinctrl_dev_get_drvdata(pctldev);
  322. return pinctrl->funcs[selector].pinfunction.name;
  323. }
  324. static int tps6594_pmx_func_groups(struct pinctrl_dev *pctldev,
  325. unsigned int selector,
  326. const char *const **groups,
  327. unsigned int *num_groups)
  328. {
  329. struct tps6594_pinctrl *pinctrl = pinctrl_dev_get_drvdata(pctldev);
  330. *groups = pinctrl->funcs[selector].pinfunction.groups;
  331. *num_groups = pinctrl->funcs[selector].pinfunction.ngroups;
  332. return 0;
  333. }
  334. static int tps6594_pmx_set(struct tps6594_pinctrl *pinctrl, unsigned int pin,
  335. u8 muxval)
  336. {
  337. u8 mux_sel_val = muxval << TPS6594_OFFSET_GPIO_SEL;
  338. u8 mux_sel_mask = pinctrl->mux_sel_mask;
  339. if (pinctrl->tps->chip_id == TPS65224 && pin == 5) {
  340. /* GPIO6 has a different mask in TPS65224*/
  341. mux_sel_mask = TPS65224_MASK_GPIO_SEL_GPIO6;
  342. }
  343. return regmap_update_bits(pinctrl->tps->regmap,
  344. TPS6594_REG_GPIOX_CONF(pin),
  345. mux_sel_mask, mux_sel_val);
  346. }
  347. static int tps6594_pmx_set_mux(struct pinctrl_dev *pctldev,
  348. unsigned int function, unsigned int group)
  349. {
  350. struct tps6594_pinctrl *pinctrl = pinctrl_dev_get_drvdata(pctldev);
  351. u8 muxval = pinctrl->funcs[function].muxval;
  352. unsigned int remap_cnt = pinctrl->remap_cnt;
  353. struct muxval_remap *remap = pinctrl->remap;
  354. for (unsigned int i = 0; i < remap_cnt; i++) {
  355. if (group == remap[i].group && muxval == remap[i].muxval) {
  356. muxval = remap[i].remap;
  357. break;
  358. }
  359. }
  360. return tps6594_pmx_set(pinctrl, group, muxval);
  361. }
  362. static int tps6594_pmx_gpio_set_direction(struct pinctrl_dev *pctldev,
  363. struct pinctrl_gpio_range *range,
  364. unsigned int offset, bool input)
  365. {
  366. struct tps6594_pinctrl *pinctrl = pinctrl_dev_get_drvdata(pctldev);
  367. u8 muxval = pinctrl->funcs[TPS6594_PINCTRL_GPIO_FUNCTION].muxval;
  368. return tps6594_pmx_set(pinctrl, offset, muxval);
  369. }
  370. static const struct pinmux_ops tps6594_pmx_ops = {
  371. .get_functions_count = tps6594_pmx_func_cnt,
  372. .get_function_name = tps6594_pmx_func_name,
  373. .get_function_groups = tps6594_pmx_func_groups,
  374. .set_mux = tps6594_pmx_set_mux,
  375. .gpio_set_direction = tps6594_pmx_gpio_set_direction,
  376. .strict = true,
  377. };
  378. static int tps6594_groups_cnt(struct pinctrl_dev *pctldev)
  379. {
  380. struct tps6594_pinctrl *pinctrl = pinctrl_dev_get_drvdata(pctldev);
  381. return pinctrl->num_pins;
  382. }
  383. static int tps6594_group_pins(struct pinctrl_dev *pctldev,
  384. unsigned int selector, const unsigned int **pins,
  385. unsigned int *num_pins)
  386. {
  387. struct tps6594_pinctrl *pinctrl = pinctrl_dev_get_drvdata(pctldev);
  388. *pins = &pinctrl->pins[selector].number;
  389. *num_pins = 1;
  390. return 0;
  391. }
  392. static const char *tps6594_group_name(struct pinctrl_dev *pctldev,
  393. unsigned int selector)
  394. {
  395. struct tps6594_pinctrl *pinctrl = pinctrl_dev_get_drvdata(pctldev);
  396. return pinctrl->pins[selector].name;
  397. }
  398. static const struct pinctrl_ops tps6594_pctrl_ops = {
  399. .dt_node_to_map = pinconf_generic_dt_node_to_map_group,
  400. .dt_free_map = pinconf_generic_dt_free_map,
  401. .get_groups_count = tps6594_groups_cnt,
  402. .get_group_name = tps6594_group_name,
  403. .get_group_pins = tps6594_group_pins,
  404. };
  405. static int tps6594_pinctrl_probe(struct platform_device *pdev)
  406. {
  407. struct tps6594 *tps = dev_get_drvdata(pdev->dev.parent);
  408. struct device *dev = &pdev->dev;
  409. struct tps6594_pinctrl *pinctrl;
  410. struct pinctrl_desc *pctrl_desc;
  411. struct gpio_regmap_config config = {};
  412. pctrl_desc = devm_kzalloc(dev, sizeof(*pctrl_desc), GFP_KERNEL);
  413. if (!pctrl_desc)
  414. return -ENOMEM;
  415. pinctrl = devm_kzalloc(dev, sizeof(*pinctrl), GFP_KERNEL);
  416. if (!pinctrl)
  417. return -ENOMEM;
  418. switch (tps->chip_id) {
  419. case TPS652G1:
  420. pctrl_desc->pins = tps65224_pins;
  421. pctrl_desc->npins = ARRAY_SIZE(tps65224_pins);
  422. *pinctrl = tps652g1_template_pinctrl;
  423. config.ngpio = ARRAY_SIZE(tps65224_gpio_func_group_names);
  424. config.ngpio_per_reg = TPS65224_NGPIO_PER_REG;
  425. break;
  426. case TPS65224:
  427. pctrl_desc->pins = tps65224_pins;
  428. pctrl_desc->npins = ARRAY_SIZE(tps65224_pins);
  429. *pinctrl = tps65224_template_pinctrl;
  430. config.ngpio = ARRAY_SIZE(tps65224_gpio_func_group_names);
  431. config.ngpio_per_reg = TPS65224_NGPIO_PER_REG;
  432. break;
  433. case TPS6593:
  434. case TPS6594:
  435. case LP8764:
  436. pctrl_desc->pins = tps6594_pins;
  437. pctrl_desc->npins = ARRAY_SIZE(tps6594_pins);
  438. *pinctrl = tps6594_template_pinctrl;
  439. config.ngpio = ARRAY_SIZE(tps6594_gpio_func_group_names);
  440. config.ngpio_per_reg = TPS6594_NGPIO_PER_REG;
  441. break;
  442. default:
  443. break;
  444. }
  445. pinctrl->tps = tps;
  446. pctrl_desc->name = dev_name(dev);
  447. pctrl_desc->owner = THIS_MODULE;
  448. pctrl_desc->pctlops = &tps6594_pctrl_ops;
  449. pctrl_desc->pmxops = &tps6594_pmx_ops;
  450. config.parent = tps->dev;
  451. config.regmap = tps->regmap;
  452. config.reg_dat_base = TPS6594_REG_GPIO_IN_1;
  453. config.reg_set_base = TPS6594_REG_GPIO_OUT_1;
  454. config.reg_dir_out_base = TPS6594_REG_GPIOX_CONF(0);
  455. config.reg_mask_xlate = tps6594_gpio_regmap_xlate;
  456. pinctrl->pctl_dev = devm_pinctrl_register(dev, pctrl_desc, pinctrl);
  457. if (IS_ERR(pinctrl->pctl_dev))
  458. return dev_err_probe(dev, PTR_ERR(pinctrl->pctl_dev),
  459. "Couldn't register pinctrl driver\n");
  460. pinctrl->gpio_regmap = devm_gpio_regmap_register(dev, &config);
  461. if (IS_ERR(pinctrl->gpio_regmap))
  462. return dev_err_probe(dev, PTR_ERR(pinctrl->gpio_regmap),
  463. "Couldn't register gpio_regmap driver\n");
  464. return 0;
  465. }
  466. static const struct platform_device_id tps6594_pinctrl_id_table[] = {
  467. { "tps6594-pinctrl", },
  468. {}
  469. };
  470. MODULE_DEVICE_TABLE(platform, tps6594_pinctrl_id_table);
  471. static struct platform_driver tps6594_pinctrl_driver = {
  472. .probe = tps6594_pinctrl_probe,
  473. .driver = {
  474. .name = "tps6594-pinctrl",
  475. },
  476. .id_table = tps6594_pinctrl_id_table,
  477. };
  478. module_platform_driver(tps6594_pinctrl_driver);
  479. MODULE_AUTHOR("Esteban Blanc <eblanc@baylibre.com>");
  480. MODULE_AUTHOR("Nirmala Devi Mal Nadar <m.nirmaladevi@ltts.com>");
  481. MODULE_DESCRIPTION("TPS6594 pinctrl and GPIO driver");
  482. MODULE_LICENSE("GPL");