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