1 // SPDX-License-Identifier: GPL-2.0-only
3 * pinctrl-palmas.c -- TI PALMAS series pin control driver.
5 * Copyright (c) 2013, NVIDIA Corporation.
7 * Author: Laxman Dewangan <ldewangan@nvidia.com>
10 #include <linux/delay.h>
11 #include <linux/module.h>
12 #include <linux/mfd/palmas.h>
14 #include <linux/of_device.h>
15 #include <linux/platform_device.h>
16 #include <linux/pinctrl/machine.h>
17 #include <linux/pinctrl/pinctrl.h>
18 #include <linux/pinctrl/pinconf-generic.h>
19 #include <linux/pinctrl/pinconf.h>
20 #include <linux/pinctrl/pinmux.h>
22 #include <linux/slab.h>
26 #include "pinctrl-utils.h"
28 #define PALMAS_PIN_GPIO0_ID 0
29 #define PALMAS_PIN_GPIO1_VBUS_LED1_PWM1 1
30 #define PALMAS_PIN_GPIO2_REGEN_LED2_PWM2 2
31 #define PALMAS_PIN_GPIO3_CHRG_DET 3
32 #define PALMAS_PIN_GPIO4_SYSEN1 4
33 #define PALMAS_PIN_GPIO5_CLK32KGAUDIO_USB_PSEL 5
34 #define PALMAS_PIN_GPIO6_SYSEN2 6
35 #define PALMAS_PIN_GPIO7_MSECURE_PWRHOLD 7
36 #define PALMAS_PIN_GPIO8_SIM1RSTI 8
37 #define PALMAS_PIN_GPIO9_LOW_VBAT 9
38 #define PALMAS_PIN_GPIO10_WIRELESS_CHRG1 10
39 #define PALMAS_PIN_GPIO11_RCM 11
40 #define PALMAS_PIN_GPIO12_SIM2RSTO 12
41 #define PALMAS_PIN_GPIO13 13
42 #define PALMAS_PIN_GPIO14 14
43 #define PALMAS_PIN_GPIO15_SIM2RSTI 15
44 #define PALMAS_PIN_VAC 16
45 #define PALMAS_PIN_POWERGOOD_USB_PSEL 17
46 #define PALMAS_PIN_NRESWARM 18
47 #define PALMAS_PIN_PWRDOWN 19
48 #define PALMAS_PIN_GPADC_START 20
49 #define PALMAS_PIN_RESET_IN 21
50 #define PALMAS_PIN_NSLEEP 22
51 #define PALMAS_PIN_ENABLE1 23
52 #define PALMAS_PIN_ENABLE2 24
53 #define PALMAS_PIN_INT 25
54 #define PALMAS_PIN_NUM (PALMAS_PIN_INT + 1)
56 struct palmas_pin_function {
58 const char * const *groups;
62 struct palmas_pctrl_chip_info {
64 struct pinctrl_dev *pctl;
65 struct palmas *palmas;
66 int pins_current_opt[PALMAS_PIN_NUM];
67 const struct palmas_pin_function *functions;
68 unsigned num_functions;
69 const struct palmas_pingroup *pin_groups;
71 const struct pinctrl_pin_desc *pins;
75 static const struct pinctrl_pin_desc palmas_pins_desc[] = {
76 PINCTRL_PIN(PALMAS_PIN_GPIO0_ID, "gpio0"),
77 PINCTRL_PIN(PALMAS_PIN_GPIO1_VBUS_LED1_PWM1, "gpio1"),
78 PINCTRL_PIN(PALMAS_PIN_GPIO2_REGEN_LED2_PWM2, "gpio2"),
79 PINCTRL_PIN(PALMAS_PIN_GPIO3_CHRG_DET, "gpio3"),
80 PINCTRL_PIN(PALMAS_PIN_GPIO4_SYSEN1, "gpio4"),
81 PINCTRL_PIN(PALMAS_PIN_GPIO5_CLK32KGAUDIO_USB_PSEL, "gpio5"),
82 PINCTRL_PIN(PALMAS_PIN_GPIO6_SYSEN2, "gpio6"),
83 PINCTRL_PIN(PALMAS_PIN_GPIO7_MSECURE_PWRHOLD, "gpio7"),
84 PINCTRL_PIN(PALMAS_PIN_GPIO8_SIM1RSTI, "gpio8"),
85 PINCTRL_PIN(PALMAS_PIN_GPIO9_LOW_VBAT, "gpio9"),
86 PINCTRL_PIN(PALMAS_PIN_GPIO10_WIRELESS_CHRG1, "gpio10"),
87 PINCTRL_PIN(PALMAS_PIN_GPIO11_RCM, "gpio11"),
88 PINCTRL_PIN(PALMAS_PIN_GPIO12_SIM2RSTO, "gpio12"),
89 PINCTRL_PIN(PALMAS_PIN_GPIO13, "gpio13"),
90 PINCTRL_PIN(PALMAS_PIN_GPIO14, "gpio14"),
91 PINCTRL_PIN(PALMAS_PIN_GPIO15_SIM2RSTI, "gpio15"),
92 PINCTRL_PIN(PALMAS_PIN_VAC, "vac"),
93 PINCTRL_PIN(PALMAS_PIN_POWERGOOD_USB_PSEL, "powergood"),
94 PINCTRL_PIN(PALMAS_PIN_NRESWARM, "nreswarm"),
95 PINCTRL_PIN(PALMAS_PIN_PWRDOWN, "pwrdown"),
96 PINCTRL_PIN(PALMAS_PIN_GPADC_START, "gpadc_start"),
97 PINCTRL_PIN(PALMAS_PIN_RESET_IN, "reset_in"),
98 PINCTRL_PIN(PALMAS_PIN_NSLEEP, "nsleep"),
99 PINCTRL_PIN(PALMAS_PIN_ENABLE1, "enable1"),
100 PINCTRL_PIN(PALMAS_PIN_ENABLE2, "enable2"),
101 PINCTRL_PIN(PALMAS_PIN_INT, "int"),
104 static const char * const opt0_groups[] = {
133 static const char * const opt1_groups[] = {
152 static const char * const opt2_groups[] = {
159 static const char * const opt3_groups[] = {
164 static const char * const gpio_groups[] = {
183 static const char * const led_groups[] = {
188 static const char * const pwm_groups[] = {
193 static const char * const regen_groups[] = {
197 static const char * const sysen_groups[] = {
202 static const char * const clk32kgaudio_groups[] = {
206 static const char * const id_groups[] = {
210 static const char * const vbus_det_groups[] = {
214 static const char * const chrg_det_groups[] = {
218 static const char * const vac_groups[] = {
222 static const char * const vacok_groups[] = {
226 static const char * const powergood_groups[] = {
230 static const char * const usb_psel_groups[] = {
235 static const char * const msecure_groups[] = {
239 static const char * const pwrhold_groups[] = {
243 static const char * const int_groups[] = {
247 static const char * const nreswarm_groups[] = {
251 static const char * const simrsto_groups[] = {
255 static const char * const simrsti_groups[] = {
260 static const char * const low_vbat_groups[] = {
264 static const char * const wireless_chrg1_groups[] = {
268 static const char * const rcm_groups[] = {
272 static const char * const pwrdown_groups[] = {
276 static const char * const gpadc_start_groups[] = {
280 static const char * const reset_in_groups[] = {
284 static const char * const nsleep_groups[] = {
288 static const char * const enable_groups[] = {
293 #define FUNCTION_GROUPS \
294 FUNCTION_GROUP(opt0, OPTION0), \
295 FUNCTION_GROUP(opt1, OPTION1), \
296 FUNCTION_GROUP(opt2, OPTION2), \
297 FUNCTION_GROUP(opt3, OPTION3), \
298 FUNCTION_GROUP(gpio, GPIO), \
299 FUNCTION_GROUP(led, LED), \
300 FUNCTION_GROUP(pwm, PWM), \
301 FUNCTION_GROUP(regen, REGEN), \
302 FUNCTION_GROUP(sysen, SYSEN), \
303 FUNCTION_GROUP(clk32kgaudio, CLK32KGAUDIO), \
304 FUNCTION_GROUP(id, ID), \
305 FUNCTION_GROUP(vbus_det, VBUS_DET), \
306 FUNCTION_GROUP(chrg_det, CHRG_DET), \
307 FUNCTION_GROUP(vac, VAC), \
308 FUNCTION_GROUP(vacok, VACOK), \
309 FUNCTION_GROUP(powergood, POWERGOOD), \
310 FUNCTION_GROUP(usb_psel, USB_PSEL), \
311 FUNCTION_GROUP(msecure, MSECURE), \
312 FUNCTION_GROUP(pwrhold, PWRHOLD), \
313 FUNCTION_GROUP(int, INT), \
314 FUNCTION_GROUP(nreswarm, NRESWARM), \
315 FUNCTION_GROUP(simrsto, SIMRSTO), \
316 FUNCTION_GROUP(simrsti, SIMRSTI), \
317 FUNCTION_GROUP(low_vbat, LOW_VBAT), \
318 FUNCTION_GROUP(wireless_chrg1, WIRELESS_CHRG1), \
319 FUNCTION_GROUP(rcm, RCM), \
320 FUNCTION_GROUP(pwrdown, PWRDOWN), \
321 FUNCTION_GROUP(gpadc_start, GPADC_START), \
322 FUNCTION_GROUP(reset_in, RESET_IN), \
323 FUNCTION_GROUP(nsleep, NSLEEP), \
324 FUNCTION_GROUP(enable, ENABLE)
326 static const struct palmas_pin_function palmas_pin_function[] = {
327 #undef FUNCTION_GROUP
328 #define FUNCTION_GROUP(fname, mux) \
331 .groups = fname##_groups, \
332 .ngroups = ARRAY_SIZE(fname##_groups), \
339 #undef FUNCTION_GROUP
340 #define FUNCTION_GROUP(fname, mux) PALMAS_PINMUX_##mux
342 PALMAS_PINMUX_NA = 0xFFFF,
345 struct palmas_pins_pullup_dn_info {
346 int pullup_dn_reg_base;
347 int pullup_dn_reg_add;
354 struct palmas_pins_od_info {
362 struct palmas_pin_info {
363 enum palmas_pinmux mux_opt;
364 const struct palmas_pins_pullup_dn_info *pud_info;
365 const struct palmas_pins_od_info *od_info;
368 struct palmas_pingroup {
370 const unsigned pins[1];
372 unsigned mux_reg_base;
373 unsigned mux_reg_add;
374 unsigned mux_reg_mask;
375 unsigned mux_bit_shift;
376 const struct palmas_pin_info *opt[4];
379 #define PULL_UP_DN(_name, _rbase, _add, _mask, _nv, _uv, _dv) \
380 static const struct palmas_pins_pullup_dn_info pud_##_name##_info = { \
381 .pullup_dn_reg_base = PALMAS_##_rbase##_BASE, \
382 .pullup_dn_reg_add = _add, \
383 .pullup_dn_mask = _mask, \
385 .pull_up_val = _uv, \
386 .pull_dn_val = _dv, \
389 PULL_UP_DN(nreswarm, PU_PD_OD, PALMAS_PU_PD_INPUT_CTRL1, 0x2, 0x0, 0x2, -1);
390 PULL_UP_DN(pwrdown, PU_PD_OD, PALMAS_PU_PD_INPUT_CTRL1, 0x4, 0x0, -1, 0x4);
391 PULL_UP_DN(gpadc_start, PU_PD_OD, PALMAS_PU_PD_INPUT_CTRL1, 0x30, 0x0, 0x20, 0x10);
392 PULL_UP_DN(reset_in, PU_PD_OD, PALMAS_PU_PD_INPUT_CTRL1, 0x40, 0x0, -1, 0x40);
393 PULL_UP_DN(nsleep, PU_PD_OD, PALMAS_PU_PD_INPUT_CTRL2, 0x3, 0x0, 0x2, 0x1);
394 PULL_UP_DN(enable1, PU_PD_OD, PALMAS_PU_PD_INPUT_CTRL2, 0xC, 0x0, 0x8, 0x4);
395 PULL_UP_DN(enable2, PU_PD_OD, PALMAS_PU_PD_INPUT_CTRL2, 0x30, 0x0, 0x20, 0x10);
396 PULL_UP_DN(vacok, PU_PD_OD, PALMAS_PU_PD_INPUT_CTRL3, 0x40, 0x0, -1, 0x40);
397 PULL_UP_DN(chrg_det, PU_PD_OD, PALMAS_PU_PD_INPUT_CTRL3, 0x10, 0x0, -1, 0x10);
398 PULL_UP_DN(pwrhold, PU_PD_OD, PALMAS_PU_PD_INPUT_CTRL3, 0x4, 0x0, -1, 0x4);
399 PULL_UP_DN(msecure, PU_PD_OD, PALMAS_PU_PD_INPUT_CTRL3, 0x1, 0x0, -1, 0x1);
400 PULL_UP_DN(id, USB_OTG, PALMAS_USB_ID_CTRL_SET, 0x40, 0x0, 0x40, -1);
401 PULL_UP_DN(gpio0, GPIO, PALMAS_PU_PD_GPIO_CTRL1, 0x04, 0, -1, 1);
402 PULL_UP_DN(gpio1, GPIO, PALMAS_PU_PD_GPIO_CTRL1, 0x0C, 0, 0x8, 0x4);
403 PULL_UP_DN(gpio2, GPIO, PALMAS_PU_PD_GPIO_CTRL1, 0x30, 0x0, 0x20, 0x10);
404 PULL_UP_DN(gpio3, GPIO, PALMAS_PU_PD_GPIO_CTRL1, 0x40, 0x0, -1, 0x40);
405 PULL_UP_DN(gpio4, GPIO, PALMAS_PU_PD_GPIO_CTRL2, 0x03, 0x0, 0x2, 0x1);
406 PULL_UP_DN(gpio5, GPIO, PALMAS_PU_PD_GPIO_CTRL2, 0x0c, 0x0, 0x8, 0x4);
407 PULL_UP_DN(gpio6, GPIO, PALMAS_PU_PD_GPIO_CTRL2, 0x30, 0x0, 0x20, 0x10);
408 PULL_UP_DN(gpio7, GPIO, PALMAS_PU_PD_GPIO_CTRL2, 0x40, 0x0, -1, 0x40);
409 PULL_UP_DN(gpio9, GPIO, PALMAS_PU_PD_GPIO_CTRL3, 0x0C, 0x0, 0x8, 0x4);
410 PULL_UP_DN(gpio10, GPIO, PALMAS_PU_PD_GPIO_CTRL3, 0x30, 0x0, 0x20, 0x10);
411 PULL_UP_DN(gpio11, GPIO, PALMAS_PU_PD_GPIO_CTRL3, 0xC0, 0x0, 0x80, 0x40);
412 PULL_UP_DN(gpio13, GPIO, PALMAS_PU_PD_GPIO_CTRL4, 0x04, 0x0, -1, 0x04);
413 PULL_UP_DN(gpio14, GPIO, PALMAS_PU_PD_GPIO_CTRL4, 0x30, 0x0, 0x20, 0x10);
415 #define OD_INFO(_name, _rbase, _add, _mask, _ev, _dv) \
416 static const struct palmas_pins_od_info od_##_name##_info = { \
417 .od_reg_base = PALMAS_##_rbase##_BASE, \
418 .od_reg_add = _add, \
424 OD_INFO(gpio1, GPIO, PALMAS_OD_OUTPUT_GPIO_CTRL, 0x1, 0x1, 0x0);
425 OD_INFO(gpio2, GPIO, PALMAS_OD_OUTPUT_GPIO_CTRL, 0x2, 0x2, 0x0);
426 OD_INFO(gpio5, GPIO, PALMAS_OD_OUTPUT_GPIO_CTRL, 0x20, 0x20, 0x0);
427 OD_INFO(gpio10, GPIO, PALMAS_OD_OUTPUT_GPIO_CTRL2, 0x04, 0x04, 0x0);
428 OD_INFO(gpio13, GPIO, PALMAS_OD_OUTPUT_GPIO_CTRL2, 0x20, 0x20, 0x0);
429 OD_INFO(int, PU_PD_OD, PALMAS_OD_OUTPUT_CTRL, 0x8, 0x8, 0x0);
430 OD_INFO(pwm1, PU_PD_OD, PALMAS_OD_OUTPUT_CTRL, 0x20, 0x20, 0x0);
431 OD_INFO(pwm2, PU_PD_OD, PALMAS_OD_OUTPUT_CTRL, 0x80, 0x80, 0x0);
432 OD_INFO(vbus_det, PU_PD_OD, PALMAS_OD_OUTPUT_CTRL, 0x40, 0x40, 0x0);
434 #define PIN_INFO(_name, _id, _pud_info, _od_info) \
435 static const struct palmas_pin_info pin_##_name##_info = { \
436 .mux_opt = PALMAS_PINMUX_##_id, \
437 .pud_info = _pud_info, \
438 .od_info = _od_info \
441 PIN_INFO(gpio0, GPIO, &pud_gpio0_info, NULL);
442 PIN_INFO(gpio1, GPIO, &pud_gpio1_info, &od_gpio1_info);
443 PIN_INFO(gpio2, GPIO, &pud_gpio2_info, &od_gpio2_info);
444 PIN_INFO(gpio3, GPIO, &pud_gpio3_info, NULL);
445 PIN_INFO(gpio4, GPIO, &pud_gpio4_info, NULL);
446 PIN_INFO(gpio5, GPIO, &pud_gpio5_info, &od_gpio5_info);
447 PIN_INFO(gpio6, GPIO, &pud_gpio6_info, NULL);
448 PIN_INFO(gpio7, GPIO, &pud_gpio7_info, NULL);
449 PIN_INFO(gpio8, GPIO, NULL, NULL);
450 PIN_INFO(gpio9, GPIO, &pud_gpio9_info, NULL);
451 PIN_INFO(gpio10, GPIO, &pud_gpio10_info, &od_gpio10_info);
452 PIN_INFO(gpio11, GPIO, &pud_gpio11_info, NULL);
453 PIN_INFO(gpio12, GPIO, NULL, NULL);
454 PIN_INFO(gpio13, GPIO, &pud_gpio13_info, &od_gpio13_info);
455 PIN_INFO(gpio14, GPIO, &pud_gpio14_info, NULL);
456 PIN_INFO(gpio15, GPIO, NULL, NULL);
457 PIN_INFO(id, ID, &pud_id_info, NULL);
458 PIN_INFO(led1, LED, NULL, NULL);
459 PIN_INFO(led2, LED, NULL, NULL);
460 PIN_INFO(regen, REGEN, NULL, NULL);
461 PIN_INFO(sysen1, SYSEN, NULL, NULL);
462 PIN_INFO(sysen2, SYSEN, NULL, NULL);
463 PIN_INFO(int, INT, NULL, &od_int_info);
464 PIN_INFO(pwm1, PWM, NULL, &od_pwm1_info);
465 PIN_INFO(pwm2, PWM, NULL, &od_pwm2_info);
466 PIN_INFO(vacok, VACOK, &pud_vacok_info, NULL);
467 PIN_INFO(chrg_det, CHRG_DET, &pud_chrg_det_info, NULL);
468 PIN_INFO(pwrhold, PWRHOLD, &pud_pwrhold_info, NULL);
469 PIN_INFO(msecure, MSECURE, &pud_msecure_info, NULL);
470 PIN_INFO(nreswarm, NA, &pud_nreswarm_info, NULL);
471 PIN_INFO(pwrdown, NA, &pud_pwrdown_info, NULL);
472 PIN_INFO(gpadc_start, NA, &pud_gpadc_start_info, NULL);
473 PIN_INFO(reset_in, NA, &pud_reset_in_info, NULL);
474 PIN_INFO(nsleep, NA, &pud_nsleep_info, NULL);
475 PIN_INFO(enable1, NA, &pud_enable1_info, NULL);
476 PIN_INFO(enable2, NA, &pud_enable2_info, NULL);
477 PIN_INFO(clk32kgaudio, CLK32KGAUDIO, NULL, NULL);
478 PIN_INFO(usb_psel, USB_PSEL, NULL, NULL);
479 PIN_INFO(vac, VAC, NULL, NULL);
480 PIN_INFO(powergood, POWERGOOD, NULL, NULL);
481 PIN_INFO(vbus_det, VBUS_DET, NULL, &od_vbus_det_info);
482 PIN_INFO(sim1rsti, SIMRSTI, NULL, NULL);
483 PIN_INFO(low_vbat, LOW_VBAT, NULL, NULL);
484 PIN_INFO(rcm, RCM, NULL, NULL);
485 PIN_INFO(sim2rsto, SIMRSTO, NULL, NULL);
486 PIN_INFO(sim2rsti, SIMRSTI, NULL, NULL);
487 PIN_INFO(wireless_chrg1, WIRELESS_CHRG1, NULL, NULL);
489 #define PALMAS_PRIMARY_SECONDARY_NONE 0
490 #define PALMAS_NONE_BASE 0
491 #define PALMAS_PRIMARY_SECONDARY_INPUT3 PALMAS_PU_PD_INPUT_CTRL3
493 #define PALMAS_PINGROUP(pg_name, pin_id, base, reg, _mask, _bshift, o0, o1, o2, o3) \
496 .pins = {PALMAS_PIN_##pin_id}, \
498 .mux_reg_base = PALMAS_##base##_BASE, \
499 .mux_reg_add = PALMAS_PRIMARY_SECONDARY_##reg, \
500 .mux_reg_mask = _mask, \
501 .mux_bit_shift = _bshift, \
510 static const struct palmas_pingroup tps65913_pingroups[] = {
511 PALMAS_PINGROUP(gpio0, GPIO0_ID, PU_PD_OD, PAD1, 0x4, 0x2, &pin_gpio0_info, &pin_id_info, NULL, NULL),
512 PALMAS_PINGROUP(gpio1, GPIO1_VBUS_LED1_PWM1, PU_PD_OD, PAD1, 0x18, 0x3, &pin_gpio1_info, &pin_vbus_det_info, &pin_led1_info, &pin_pwm1_info),
513 PALMAS_PINGROUP(gpio2, GPIO2_REGEN_LED2_PWM2, PU_PD_OD, PAD1, 0x60, 0x5, &pin_gpio2_info, &pin_regen_info, &pin_led2_info, &pin_pwm2_info),
514 PALMAS_PINGROUP(gpio3, GPIO3_CHRG_DET, PU_PD_OD, PAD1, 0x80, 0x7, &pin_gpio3_info, &pin_chrg_det_info, NULL, NULL),
515 PALMAS_PINGROUP(gpio4, GPIO4_SYSEN1, PU_PD_OD, PAD1, 0x01, 0x0, &pin_gpio4_info, &pin_sysen1_info, NULL, NULL),
516 PALMAS_PINGROUP(gpio5, GPIO5_CLK32KGAUDIO_USB_PSEL, PU_PD_OD, PAD2, 0x6, 0x1, &pin_gpio5_info, &pin_clk32kgaudio_info, &pin_usb_psel_info, NULL),
517 PALMAS_PINGROUP(gpio6, GPIO6_SYSEN2, PU_PD_OD, PAD2, 0x08, 0x3, &pin_gpio6_info, &pin_sysen2_info, NULL, NULL),
518 PALMAS_PINGROUP(gpio7, GPIO7_MSECURE_PWRHOLD, PU_PD_OD, PAD2, 0x30, 0x4, &pin_gpio7_info, &pin_msecure_info, &pin_pwrhold_info, NULL),
519 PALMAS_PINGROUP(vac, VAC, PU_PD_OD, PAD1, 0x02, 0x1, &pin_vac_info, &pin_vacok_info, NULL, NULL),
520 PALMAS_PINGROUP(powergood, POWERGOOD_USB_PSEL, PU_PD_OD, PAD1, 0x01, 0x0, &pin_powergood_info, &pin_usb_psel_info, NULL, NULL),
521 PALMAS_PINGROUP(nreswarm, NRESWARM, NONE, NONE, 0x0, 0x0, &pin_nreswarm_info, NULL, NULL, NULL),
522 PALMAS_PINGROUP(pwrdown, PWRDOWN, NONE, NONE, 0x0, 0x0, &pin_pwrdown_info, NULL, NULL, NULL),
523 PALMAS_PINGROUP(gpadc_start, GPADC_START, NONE, NONE, 0x0, 0x0, &pin_gpadc_start_info, NULL, NULL, NULL),
524 PALMAS_PINGROUP(reset_in, RESET_IN, NONE, NONE, 0x0, 0x0, &pin_reset_in_info, NULL, NULL, NULL),
525 PALMAS_PINGROUP(nsleep, NSLEEP, NONE, NONE, 0x0, 0x0, &pin_nsleep_info, NULL, NULL, NULL),
526 PALMAS_PINGROUP(enable1, ENABLE1, NONE, NONE, 0x0, 0x0, &pin_enable1_info, NULL, NULL, NULL),
527 PALMAS_PINGROUP(enable2, ENABLE2, NONE, NONE, 0x0, 0x0, &pin_enable2_info, NULL, NULL, NULL),
528 PALMAS_PINGROUP(int, INT, NONE, NONE, 0x0, 0x0, &pin_int_info, NULL, NULL, NULL),
531 static const struct palmas_pingroup tps80036_pingroups[] = {
532 PALMAS_PINGROUP(gpio0, GPIO0_ID, PU_PD_OD, PAD1, 0x4, 0x2, &pin_gpio0_info, &pin_id_info, NULL, NULL),
533 PALMAS_PINGROUP(gpio1, GPIO1_VBUS_LED1_PWM1, PU_PD_OD, PAD1, 0x18, 0x3, &pin_gpio1_info, &pin_vbus_det_info, &pin_led1_info, &pin_pwm1_info),
534 PALMAS_PINGROUP(gpio2, GPIO2_REGEN_LED2_PWM2, PU_PD_OD, PAD1, 0x60, 0x5, &pin_gpio2_info, &pin_regen_info, &pin_led2_info, &pin_pwm2_info),
535 PALMAS_PINGROUP(gpio3, GPIO3_CHRG_DET, PU_PD_OD, PAD1, 0x80, 0x7, &pin_gpio3_info, &pin_chrg_det_info, NULL, NULL),
536 PALMAS_PINGROUP(gpio4, GPIO4_SYSEN1, PU_PD_OD, PAD1, 0x01, 0x0, &pin_gpio4_info, &pin_sysen1_info, NULL, NULL),
537 PALMAS_PINGROUP(gpio5, GPIO5_CLK32KGAUDIO_USB_PSEL, PU_PD_OD, PAD2, 0x6, 0x1, &pin_gpio5_info, &pin_clk32kgaudio_info, &pin_usb_psel_info, NULL),
538 PALMAS_PINGROUP(gpio6, GPIO6_SYSEN2, PU_PD_OD, PAD2, 0x08, 0x3, &pin_gpio6_info, &pin_sysen2_info, NULL, NULL),
539 PALMAS_PINGROUP(gpio7, GPIO7_MSECURE_PWRHOLD, PU_PD_OD, PAD2, 0x30, 0x4, &pin_gpio7_info, &pin_msecure_info, &pin_pwrhold_info, NULL),
540 PALMAS_PINGROUP(gpio8, GPIO8_SIM1RSTI, PU_PD_OD, PAD4, 0x01, 0x0, &pin_gpio8_info, &pin_sim1rsti_info, NULL, NULL),
541 PALMAS_PINGROUP(gpio9, GPIO9_LOW_VBAT, PU_PD_OD, PAD4, 0x02, 0x1, &pin_gpio9_info, &pin_low_vbat_info, NULL, NULL),
542 PALMAS_PINGROUP(gpio10, GPIO10_WIRELESS_CHRG1, PU_PD_OD, PAD4, 0x04, 0x2, &pin_gpio10_info, &pin_wireless_chrg1_info, NULL, NULL),
543 PALMAS_PINGROUP(gpio11, GPIO11_RCM, PU_PD_OD, PAD4, 0x08, 0x3, &pin_gpio11_info, &pin_rcm_info, NULL, NULL),
544 PALMAS_PINGROUP(gpio12, GPIO12_SIM2RSTO, PU_PD_OD, PAD4, 0x10, 0x4, &pin_gpio12_info, &pin_sim2rsto_info, NULL, NULL),
545 PALMAS_PINGROUP(gpio13, GPIO13, NONE, NONE, 0x00, 0x0, &pin_gpio13_info, NULL, NULL, NULL),
546 PALMAS_PINGROUP(gpio14, GPIO14, NONE, NONE, 0x00, 0x0, &pin_gpio14_info, NULL, NULL, NULL),
547 PALMAS_PINGROUP(gpio15, GPIO15_SIM2RSTI, PU_PD_OD, PAD4, 0x80, 0x7, &pin_gpio15_info, &pin_sim2rsti_info, NULL, NULL),
548 PALMAS_PINGROUP(vac, VAC, PU_PD_OD, PAD1, 0x02, 0x1, &pin_vac_info, &pin_vacok_info, NULL, NULL),
549 PALMAS_PINGROUP(powergood, POWERGOOD_USB_PSEL, PU_PD_OD, PAD1, 0x01, 0x0, &pin_powergood_info, &pin_usb_psel_info, NULL, NULL),
550 PALMAS_PINGROUP(nreswarm, NRESWARM, NONE, NONE, 0x0, 0x0, &pin_nreswarm_info, NULL, NULL, NULL),
551 PALMAS_PINGROUP(pwrdown, PWRDOWN, NONE, NONE, 0x0, 0x0, &pin_pwrdown_info, NULL, NULL, NULL),
552 PALMAS_PINGROUP(gpadc_start, GPADC_START, NONE, NONE, 0x0, 0x0, &pin_gpadc_start_info, NULL, NULL, NULL),
553 PALMAS_PINGROUP(reset_in, RESET_IN, NONE, NONE, 0x0, 0x0, &pin_reset_in_info, NULL, NULL, NULL),
554 PALMAS_PINGROUP(nsleep, NSLEEP, NONE, NONE, 0x0, 0x0, &pin_nsleep_info, NULL, NULL, NULL),
555 PALMAS_PINGROUP(enable1, ENABLE1, NONE, NONE, 0x0, 0x0, &pin_enable1_info, NULL, NULL, NULL),
556 PALMAS_PINGROUP(enable2, ENABLE2, NONE, NONE, 0x0, 0x0, &pin_enable2_info, NULL, NULL, NULL),
557 PALMAS_PINGROUP(int, INT, NONE, NONE, 0x0, 0x0, &pin_int_info, NULL, NULL, NULL),
560 static int palmas_pinctrl_get_pin_mux(struct palmas_pctrl_chip_info *pci)
562 const struct palmas_pingroup *g;
567 for (i = 0; i < pci->num_pin_groups; ++i) {
568 g = &pci->pin_groups[i];
569 if (g->mux_reg_base == PALMAS_NONE_BASE) {
570 pci->pins_current_opt[i] = 0;
573 ret = palmas_read(pci->palmas, g->mux_reg_base,
574 g->mux_reg_add, &val);
576 dev_err(pci->dev, "mux_reg 0x%02x read failed: %d\n",
577 g->mux_reg_add, ret);
580 val &= g->mux_reg_mask;
581 pci->pins_current_opt[i] = val >> g->mux_bit_shift;
586 static int palmas_pinctrl_set_dvfs1(struct palmas_pctrl_chip_info *pci,
592 val = enable ? PALMAS_PRIMARY_SECONDARY_PAD3_DVFS1 : 0;
593 ret = palmas_update_bits(pci->palmas, PALMAS_PU_PD_OD_BASE,
594 PALMAS_PRIMARY_SECONDARY_PAD3,
595 PALMAS_PRIMARY_SECONDARY_PAD3_DVFS1, val);
597 dev_err(pci->dev, "SECONDARY_PAD3 update failed %d\n", ret);
601 static int palmas_pinctrl_set_dvfs2(struct palmas_pctrl_chip_info *pci,
607 val = enable ? PALMAS_PRIMARY_SECONDARY_PAD3_DVFS2 : 0;
608 ret = palmas_update_bits(pci->palmas, PALMAS_PU_PD_OD_BASE,
609 PALMAS_PRIMARY_SECONDARY_PAD3,
610 PALMAS_PRIMARY_SECONDARY_PAD3_DVFS2, val);
612 dev_err(pci->dev, "SECONDARY_PAD3 update failed %d\n", ret);
616 static int palmas_pinctrl_get_groups_count(struct pinctrl_dev *pctldev)
618 struct palmas_pctrl_chip_info *pci = pinctrl_dev_get_drvdata(pctldev);
620 return pci->num_pin_groups;
623 static const char *palmas_pinctrl_get_group_name(struct pinctrl_dev *pctldev,
626 struct palmas_pctrl_chip_info *pci = pinctrl_dev_get_drvdata(pctldev);
628 return pci->pin_groups[group].name;
631 static int palmas_pinctrl_get_group_pins(struct pinctrl_dev *pctldev,
632 unsigned group, const unsigned **pins, unsigned *num_pins)
634 struct palmas_pctrl_chip_info *pci = pinctrl_dev_get_drvdata(pctldev);
636 *pins = pci->pin_groups[group].pins;
637 *num_pins = pci->pin_groups[group].npins;
641 static const struct pinctrl_ops palmas_pinctrl_ops = {
642 .get_groups_count = palmas_pinctrl_get_groups_count,
643 .get_group_name = palmas_pinctrl_get_group_name,
644 .get_group_pins = palmas_pinctrl_get_group_pins,
645 .dt_node_to_map = pinconf_generic_dt_node_to_map_pin,
646 .dt_free_map = pinctrl_utils_free_map,
649 static int palmas_pinctrl_get_funcs_count(struct pinctrl_dev *pctldev)
651 struct palmas_pctrl_chip_info *pci = pinctrl_dev_get_drvdata(pctldev);
653 return pci->num_functions;
656 static const char *palmas_pinctrl_get_func_name(struct pinctrl_dev *pctldev,
659 struct palmas_pctrl_chip_info *pci = pinctrl_dev_get_drvdata(pctldev);
661 return pci->functions[function].name;
664 static int palmas_pinctrl_get_func_groups(struct pinctrl_dev *pctldev,
665 unsigned function, const char * const **groups,
666 unsigned * const num_groups)
668 struct palmas_pctrl_chip_info *pci = pinctrl_dev_get_drvdata(pctldev);
670 *groups = pci->functions[function].groups;
671 *num_groups = pci->functions[function].ngroups;
675 static int palmas_pinctrl_set_mux(struct pinctrl_dev *pctldev,
679 struct palmas_pctrl_chip_info *pci = pinctrl_dev_get_drvdata(pctldev);
680 const struct palmas_pingroup *g;
684 g = &pci->pin_groups[group];
686 /* If direct option is provided here */
687 if (function <= PALMAS_PINMUX_OPTION3) {
688 if (!g->opt[function]) {
689 dev_err(pci->dev, "Pin %s does not support option %d\n",
695 for (i = 0; i < ARRAY_SIZE(g->opt); i++) {
698 if (g->opt[i]->mux_opt == function)
701 if (WARN_ON(i == ARRAY_SIZE(g->opt))) {
702 dev_err(pci->dev, "Pin %s does not support option %d\n",
708 if (g->mux_reg_base == PALMAS_NONE_BASE) {
714 dev_dbg(pci->dev, "%s(): Base0x%02x:0x%02x:0x%02x:0x%02x\n",
715 __func__, g->mux_reg_base, g->mux_reg_add,
716 g->mux_reg_mask, i << g->mux_bit_shift);
718 ret = palmas_update_bits(pci->palmas, g->mux_reg_base, g->mux_reg_add,
719 g->mux_reg_mask, i << g->mux_bit_shift);
721 dev_err(pci->dev, "Reg 0x%02x update failed: %d\n",
722 g->mux_reg_add, ret);
725 pci->pins_current_opt[group] = i;
729 static const struct pinmux_ops palmas_pinmux_ops = {
730 .get_functions_count = palmas_pinctrl_get_funcs_count,
731 .get_function_name = palmas_pinctrl_get_func_name,
732 .get_function_groups = palmas_pinctrl_get_func_groups,
733 .set_mux = palmas_pinctrl_set_mux,
736 static int palmas_pinconf_get(struct pinctrl_dev *pctldev,
737 unsigned pin, unsigned long *config)
739 struct palmas_pctrl_chip_info *pci = pinctrl_dev_get_drvdata(pctldev);
740 enum pin_config_param param = pinconf_to_config_param(*config);
741 const struct palmas_pingroup *g;
742 const struct palmas_pin_info *opt;
750 for (group_nr = 0; group_nr < pci->num_pin_groups; ++group_nr) {
751 if (pci->pin_groups[group_nr].pins[0] == pin)
755 if (group_nr == pci->num_pin_groups) {
757 "Pinconf is not supported for pin-id %d\n", pin);
761 g = &pci->pin_groups[group_nr];
762 opt = g->opt[pci->pins_current_opt[group_nr]];
765 "Pinconf is not supported for pin %s\n", g->name);
770 case PIN_CONFIG_BIAS_DISABLE:
771 case PIN_CONFIG_BIAS_PULL_UP:
772 case PIN_CONFIG_BIAS_PULL_DOWN:
773 if (!opt->pud_info) {
775 "PULL control not supported for pin %s\n",
779 base = opt->pud_info->pullup_dn_reg_base;
780 add = opt->pud_info->pullup_dn_reg_add;
781 ret = palmas_read(pci->palmas, base, add, &val);
783 dev_err(pci->dev, "Reg 0x%02x read failed: %d\n",
788 rval = val & opt->pud_info->pullup_dn_mask;
790 if ((opt->pud_info->normal_val >= 0) &&
791 (opt->pud_info->normal_val == rval) &&
792 (param == PIN_CONFIG_BIAS_DISABLE))
794 else if ((opt->pud_info->pull_up_val >= 0) &&
795 (opt->pud_info->pull_up_val == rval) &&
796 (param == PIN_CONFIG_BIAS_PULL_UP))
798 else if ((opt->pud_info->pull_dn_val >= 0) &&
799 (opt->pud_info->pull_dn_val == rval) &&
800 (param == PIN_CONFIG_BIAS_PULL_DOWN))
804 case PIN_CONFIG_DRIVE_OPEN_DRAIN:
807 "OD control not supported for pin %s\n",
811 base = opt->od_info->od_reg_base;
812 add = opt->od_info->od_reg_add;
813 ret = palmas_read(pci->palmas, base, add, &val);
815 dev_err(pci->dev, "Reg 0x%02x read failed: %d\n",
819 rval = val & opt->od_info->od_mask;
821 if ((opt->od_info->od_disable >= 0) &&
822 (opt->od_info->od_disable == rval))
824 else if ((opt->od_info->od_enable >= 0) &&
825 (opt->od_info->od_enable == rval))
829 "OD control not supported for pin %s\n",
836 dev_err(pci->dev, "Properties not supported\n");
840 *config = pinconf_to_config_packed(param, (u16)arg);
844 static int palmas_pinconf_set(struct pinctrl_dev *pctldev,
845 unsigned pin, unsigned long *configs,
846 unsigned num_configs)
848 struct palmas_pctrl_chip_info *pci = pinctrl_dev_get_drvdata(pctldev);
849 enum pin_config_param param;
851 const struct palmas_pingroup *g;
852 const struct palmas_pin_info *opt;
859 for (group_nr = 0; group_nr < pci->num_pin_groups; ++group_nr) {
860 if (pci->pin_groups[group_nr].pins[0] == pin)
864 if (group_nr == pci->num_pin_groups) {
866 "Pinconf is not supported for pin-id %d\n", pin);
870 g = &pci->pin_groups[group_nr];
871 opt = g->opt[pci->pins_current_opt[group_nr]];
874 "Pinconf is not supported for pin %s\n", g->name);
878 for (i = 0; i < num_configs; i++) {
879 param = pinconf_to_config_param(configs[i]);
880 param_val = pinconf_to_config_argument(configs[i]);
883 case PIN_CONFIG_BIAS_DISABLE:
884 case PIN_CONFIG_BIAS_PULL_UP:
885 case PIN_CONFIG_BIAS_PULL_DOWN:
886 if (!opt->pud_info) {
888 "PULL control not supported for pin %s\n",
892 base = opt->pud_info->pullup_dn_reg_base;
893 add = opt->pud_info->pullup_dn_reg_add;
894 mask = opt->pud_info->pullup_dn_mask;
896 if (param == PIN_CONFIG_BIAS_DISABLE)
897 rval = opt->pud_info->normal_val;
898 else if (param == PIN_CONFIG_BIAS_PULL_UP)
899 rval = opt->pud_info->pull_up_val;
901 rval = opt->pud_info->pull_dn_val;
905 "PULL control not supported for pin %s\n",
911 case PIN_CONFIG_DRIVE_OPEN_DRAIN:
914 "OD control not supported for pin %s\n",
918 base = opt->od_info->od_reg_base;
919 add = opt->od_info->od_reg_add;
920 mask = opt->od_info->od_mask;
922 rval = opt->od_info->od_disable;
924 rval = opt->od_info->od_enable;
927 "OD control not supported for pin %s\n",
933 dev_err(pci->dev, "Properties not supported\n");
937 dev_dbg(pci->dev, "%s(): Add0x%02x:0x%02x:0x%02x:0x%02x\n",
938 __func__, base, add, mask, rval);
939 ret = palmas_update_bits(pci->palmas, base, add, mask, rval);
941 dev_err(pci->dev, "Reg 0x%02x update failed: %d\n",
945 } /* for each config */
950 static const struct pinconf_ops palmas_pinconf_ops = {
951 .pin_config_get = palmas_pinconf_get,
952 .pin_config_set = palmas_pinconf_set,
955 static struct pinctrl_desc palmas_pinctrl_desc = {
956 .pctlops = &palmas_pinctrl_ops,
957 .pmxops = &palmas_pinmux_ops,
958 .confops = &palmas_pinconf_ops,
959 .owner = THIS_MODULE,
962 struct palmas_pinctrl_data {
963 const struct palmas_pingroup *pin_groups;
967 static struct palmas_pinctrl_data tps65913_pinctrl_data = {
968 .pin_groups = tps65913_pingroups,
969 .num_pin_groups = ARRAY_SIZE(tps65913_pingroups),
972 static struct palmas_pinctrl_data tps80036_pinctrl_data = {
973 .pin_groups = tps80036_pingroups,
974 .num_pin_groups = ARRAY_SIZE(tps80036_pingroups),
977 static const struct of_device_id palmas_pinctrl_of_match[] = {
978 { .compatible = "ti,palmas-pinctrl", .data = &tps65913_pinctrl_data},
979 { .compatible = "ti,tps65913-pinctrl", .data = &tps65913_pinctrl_data},
980 { .compatible = "ti,tps80036-pinctrl", .data = &tps80036_pinctrl_data},
983 MODULE_DEVICE_TABLE(of, palmas_pinctrl_of_match);
985 static int palmas_pinctrl_probe(struct platform_device *pdev)
987 struct palmas_pctrl_chip_info *pci;
988 const struct palmas_pinctrl_data *pinctrl_data = &tps65913_pinctrl_data;
990 bool enable_dvfs1 = false;
991 bool enable_dvfs2 = false;
993 if (pdev->dev.of_node) {
994 pinctrl_data = of_device_get_match_data(&pdev->dev);
995 enable_dvfs1 = of_property_read_bool(pdev->dev.of_node,
996 "ti,palmas-enable-dvfs1");
997 enable_dvfs2 = of_property_read_bool(pdev->dev.of_node,
998 "ti,palmas-enable-dvfs2");
1001 pci = devm_kzalloc(&pdev->dev, sizeof(*pci), GFP_KERNEL);
1005 pci->dev = &pdev->dev;
1006 pci->palmas = dev_get_drvdata(pdev->dev.parent);
1008 pci->pins = palmas_pins_desc;
1009 pci->num_pins = ARRAY_SIZE(palmas_pins_desc);
1010 pci->functions = palmas_pin_function;
1011 pci->num_functions = ARRAY_SIZE(palmas_pin_function);
1012 pci->pin_groups = pinctrl_data->pin_groups;
1013 pci->num_pin_groups = pinctrl_data->num_pin_groups;
1015 platform_set_drvdata(pdev, pci);
1017 palmas_pinctrl_set_dvfs1(pci, enable_dvfs1);
1018 palmas_pinctrl_set_dvfs2(pci, enable_dvfs2);
1019 ret = palmas_pinctrl_get_pin_mux(pci);
1022 "Reading pinctrol option register failed: %d\n", ret);
1026 palmas_pinctrl_desc.name = dev_name(&pdev->dev);
1027 palmas_pinctrl_desc.pins = palmas_pins_desc;
1028 palmas_pinctrl_desc.npins = ARRAY_SIZE(palmas_pins_desc);
1029 pci->pctl = devm_pinctrl_register(&pdev->dev, &palmas_pinctrl_desc,
1031 if (IS_ERR(pci->pctl)) {
1032 dev_err(&pdev->dev, "Couldn't register pinctrl driver\n");
1033 return PTR_ERR(pci->pctl);
1038 static struct platform_driver palmas_pinctrl_driver = {
1040 .name = "palmas-pinctrl",
1041 .of_match_table = palmas_pinctrl_of_match,
1043 .probe = palmas_pinctrl_probe,
1046 module_platform_driver(palmas_pinctrl_driver);
1048 MODULE_DESCRIPTION("Palmas pin control driver");
1049 MODULE_AUTHOR("Laxman Dewangan<ldewangan@nvidia.com>");
1050 MODULE_ALIAS("platform:palmas-pinctrl");
1051 MODULE_LICENSE("GPL v2");