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/platform_device.h>
15 #include <linux/pinctrl/machine.h>
16 #include <linux/pinctrl/pinctrl.h>
17 #include <linux/pinctrl/pinconf-generic.h>
18 #include <linux/pinctrl/pinconf.h>
19 #include <linux/pinctrl/pinmux.h>
21 #include <linux/slab.h>
25 #include "pinctrl-utils.h"
27 #define PALMAS_PIN_GPIO0_ID 0
28 #define PALMAS_PIN_GPIO1_VBUS_LED1_PWM1 1
29 #define PALMAS_PIN_GPIO2_REGEN_LED2_PWM2 2
30 #define PALMAS_PIN_GPIO3_CHRG_DET 3
31 #define PALMAS_PIN_GPIO4_SYSEN1 4
32 #define PALMAS_PIN_GPIO5_CLK32KGAUDIO_USB_PSEL 5
33 #define PALMAS_PIN_GPIO6_SYSEN2 6
34 #define PALMAS_PIN_GPIO7_MSECURE_PWRHOLD 7
35 #define PALMAS_PIN_GPIO8_SIM1RSTI 8
36 #define PALMAS_PIN_GPIO9_LOW_VBAT 9
37 #define PALMAS_PIN_GPIO10_WIRELESS_CHRG1 10
38 #define PALMAS_PIN_GPIO11_RCM 11
39 #define PALMAS_PIN_GPIO12_SIM2RSTO 12
40 #define PALMAS_PIN_GPIO13 13
41 #define PALMAS_PIN_GPIO14 14
42 #define PALMAS_PIN_GPIO15_SIM2RSTI 15
43 #define PALMAS_PIN_VAC 16
44 #define PALMAS_PIN_POWERGOOD_USB_PSEL 17
45 #define PALMAS_PIN_NRESWARM 18
46 #define PALMAS_PIN_PWRDOWN 19
47 #define PALMAS_PIN_GPADC_START 20
48 #define PALMAS_PIN_RESET_IN 21
49 #define PALMAS_PIN_NSLEEP 22
50 #define PALMAS_PIN_ENABLE1 23
51 #define PALMAS_PIN_ENABLE2 24
52 #define PALMAS_PIN_INT 25
53 #define PALMAS_PIN_NUM (PALMAS_PIN_INT + 1)
55 struct palmas_pin_function
{
57 const char * const *groups
;
61 struct palmas_pctrl_chip_info
{
63 struct pinctrl_dev
*pctl
;
64 struct palmas
*palmas
;
65 int pins_current_opt
[PALMAS_PIN_NUM
];
66 const struct palmas_pin_function
*functions
;
67 unsigned num_functions
;
68 const struct palmas_pingroup
*pin_groups
;
70 const struct pinctrl_pin_desc
*pins
;
74 static const struct pinctrl_pin_desc palmas_pins_desc
[] = {
75 PINCTRL_PIN(PALMAS_PIN_GPIO0_ID
, "gpio0"),
76 PINCTRL_PIN(PALMAS_PIN_GPIO1_VBUS_LED1_PWM1
, "gpio1"),
77 PINCTRL_PIN(PALMAS_PIN_GPIO2_REGEN_LED2_PWM2
, "gpio2"),
78 PINCTRL_PIN(PALMAS_PIN_GPIO3_CHRG_DET
, "gpio3"),
79 PINCTRL_PIN(PALMAS_PIN_GPIO4_SYSEN1
, "gpio4"),
80 PINCTRL_PIN(PALMAS_PIN_GPIO5_CLK32KGAUDIO_USB_PSEL
, "gpio5"),
81 PINCTRL_PIN(PALMAS_PIN_GPIO6_SYSEN2
, "gpio6"),
82 PINCTRL_PIN(PALMAS_PIN_GPIO7_MSECURE_PWRHOLD
, "gpio7"),
83 PINCTRL_PIN(PALMAS_PIN_GPIO8_SIM1RSTI
, "gpio8"),
84 PINCTRL_PIN(PALMAS_PIN_GPIO9_LOW_VBAT
, "gpio9"),
85 PINCTRL_PIN(PALMAS_PIN_GPIO10_WIRELESS_CHRG1
, "gpio10"),
86 PINCTRL_PIN(PALMAS_PIN_GPIO11_RCM
, "gpio11"),
87 PINCTRL_PIN(PALMAS_PIN_GPIO12_SIM2RSTO
, "gpio12"),
88 PINCTRL_PIN(PALMAS_PIN_GPIO13
, "gpio13"),
89 PINCTRL_PIN(PALMAS_PIN_GPIO14
, "gpio14"),
90 PINCTRL_PIN(PALMAS_PIN_GPIO15_SIM2RSTI
, "gpio15"),
91 PINCTRL_PIN(PALMAS_PIN_VAC
, "vac"),
92 PINCTRL_PIN(PALMAS_PIN_POWERGOOD_USB_PSEL
, "powergood"),
93 PINCTRL_PIN(PALMAS_PIN_NRESWARM
, "nreswarm"),
94 PINCTRL_PIN(PALMAS_PIN_PWRDOWN
, "pwrdown"),
95 PINCTRL_PIN(PALMAS_PIN_GPADC_START
, "gpadc_start"),
96 PINCTRL_PIN(PALMAS_PIN_RESET_IN
, "reset_in"),
97 PINCTRL_PIN(PALMAS_PIN_NSLEEP
, "nsleep"),
98 PINCTRL_PIN(PALMAS_PIN_ENABLE1
, "enable1"),
99 PINCTRL_PIN(PALMAS_PIN_ENABLE2
, "enable2"),
100 PINCTRL_PIN(PALMAS_PIN_INT
, "int"),
103 static const char * const opt0_groups
[] = {
132 static const char * const opt1_groups
[] = {
151 static const char * const opt2_groups
[] = {
158 static const char * const opt3_groups
[] = {
163 static const char * const gpio_groups
[] = {
182 static const char * const led_groups
[] = {
187 static const char * const pwm_groups
[] = {
192 static const char * const regen_groups
[] = {
196 static const char * const sysen_groups
[] = {
201 static const char * const clk32kgaudio_groups
[] = {
205 static const char * const id_groups
[] = {
209 static const char * const vbus_det_groups
[] = {
213 static const char * const chrg_det_groups
[] = {
217 static const char * const vac_groups
[] = {
221 static const char * const vacok_groups
[] = {
225 static const char * const powergood_groups
[] = {
229 static const char * const usb_psel_groups
[] = {
234 static const char * const msecure_groups
[] = {
238 static const char * const pwrhold_groups
[] = {
242 static const char * const int_groups
[] = {
246 static const char * const nreswarm_groups
[] = {
250 static const char * const simrsto_groups
[] = {
254 static const char * const simrsti_groups
[] = {
259 static const char * const low_vbat_groups
[] = {
263 static const char * const wireless_chrg1_groups
[] = {
267 static const char * const rcm_groups
[] = {
271 static const char * const pwrdown_groups
[] = {
275 static const char * const gpadc_start_groups
[] = {
279 static const char * const reset_in_groups
[] = {
283 static const char * const nsleep_groups
[] = {
287 static const char * const enable_groups
[] = {
292 #define FUNCTION_GROUPS \
293 FUNCTION_GROUP(opt0, OPTION0), \
294 FUNCTION_GROUP(opt1, OPTION1), \
295 FUNCTION_GROUP(opt2, OPTION2), \
296 FUNCTION_GROUP(opt3, OPTION3), \
297 FUNCTION_GROUP(gpio, GPIO), \
298 FUNCTION_GROUP(led, LED), \
299 FUNCTION_GROUP(pwm, PWM), \
300 FUNCTION_GROUP(regen, REGEN), \
301 FUNCTION_GROUP(sysen, SYSEN), \
302 FUNCTION_GROUP(clk32kgaudio, CLK32KGAUDIO), \
303 FUNCTION_GROUP(id, ID), \
304 FUNCTION_GROUP(vbus_det, VBUS_DET), \
305 FUNCTION_GROUP(chrg_det, CHRG_DET), \
306 FUNCTION_GROUP(vac, VAC), \
307 FUNCTION_GROUP(vacok, VACOK), \
308 FUNCTION_GROUP(powergood, POWERGOOD), \
309 FUNCTION_GROUP(usb_psel, USB_PSEL), \
310 FUNCTION_GROUP(msecure, MSECURE), \
311 FUNCTION_GROUP(pwrhold, PWRHOLD), \
312 FUNCTION_GROUP(int, INT), \
313 FUNCTION_GROUP(nreswarm, NRESWARM), \
314 FUNCTION_GROUP(simrsto, SIMRSTO), \
315 FUNCTION_GROUP(simrsti, SIMRSTI), \
316 FUNCTION_GROUP(low_vbat, LOW_VBAT), \
317 FUNCTION_GROUP(wireless_chrg1, WIRELESS_CHRG1), \
318 FUNCTION_GROUP(rcm, RCM), \
319 FUNCTION_GROUP(pwrdown, PWRDOWN), \
320 FUNCTION_GROUP(gpadc_start, GPADC_START), \
321 FUNCTION_GROUP(reset_in, RESET_IN), \
322 FUNCTION_GROUP(nsleep, NSLEEP), \
323 FUNCTION_GROUP(enable, ENABLE)
325 static const struct palmas_pin_function palmas_pin_function
[] = {
326 #undef FUNCTION_GROUP
327 #define FUNCTION_GROUP(fname, mux) \
330 .groups = fname##_groups, \
331 .ngroups = ARRAY_SIZE(fname##_groups), \
338 #undef FUNCTION_GROUP
339 #define FUNCTION_GROUP(fname, mux) PALMAS_PINMUX_##mux
341 PALMAS_PINMUX_NA
= 0xFFFF,
344 struct palmas_pins_pullup_dn_info
{
345 int pullup_dn_reg_base
;
346 int pullup_dn_reg_add
;
353 struct palmas_pins_od_info
{
361 struct palmas_pin_info
{
362 enum palmas_pinmux mux_opt
;
363 const struct palmas_pins_pullup_dn_info
*pud_info
;
364 const struct palmas_pins_od_info
*od_info
;
367 struct palmas_pingroup
{
369 const unsigned pins
[1];
371 unsigned mux_reg_base
;
372 unsigned mux_reg_add
;
373 unsigned mux_reg_mask
;
374 unsigned mux_bit_shift
;
375 const struct palmas_pin_info
*opt
[4];
378 #define PULL_UP_DN(_name, _rbase, _add, _mask, _nv, _uv, _dv) \
379 static const struct palmas_pins_pullup_dn_info pud_##_name##_info = { \
380 .pullup_dn_reg_base = PALMAS_##_rbase##_BASE, \
381 .pullup_dn_reg_add = _add, \
382 .pullup_dn_mask = _mask, \
384 .pull_up_val = _uv, \
385 .pull_dn_val = _dv, \
388 PULL_UP_DN(nreswarm
, PU_PD_OD
, PALMAS_PU_PD_INPUT_CTRL1
, 0x2, 0x0, 0x2, -1);
389 PULL_UP_DN(pwrdown
, PU_PD_OD
, PALMAS_PU_PD_INPUT_CTRL1
, 0x4, 0x0, -1, 0x4);
390 PULL_UP_DN(gpadc_start
, PU_PD_OD
, PALMAS_PU_PD_INPUT_CTRL1
, 0x30, 0x0, 0x20, 0x10);
391 PULL_UP_DN(reset_in
, PU_PD_OD
, PALMAS_PU_PD_INPUT_CTRL1
, 0x40, 0x0, -1, 0x40);
392 PULL_UP_DN(nsleep
, PU_PD_OD
, PALMAS_PU_PD_INPUT_CTRL2
, 0x3, 0x0, 0x2, 0x1);
393 PULL_UP_DN(enable1
, PU_PD_OD
, PALMAS_PU_PD_INPUT_CTRL2
, 0xC, 0x0, 0x8, 0x4);
394 PULL_UP_DN(enable2
, PU_PD_OD
, PALMAS_PU_PD_INPUT_CTRL2
, 0x30, 0x0, 0x20, 0x10);
395 PULL_UP_DN(vacok
, PU_PD_OD
, PALMAS_PU_PD_INPUT_CTRL3
, 0x40, 0x0, -1, 0x40);
396 PULL_UP_DN(chrg_det
, PU_PD_OD
, PALMAS_PU_PD_INPUT_CTRL3
, 0x10, 0x0, -1, 0x10);
397 PULL_UP_DN(pwrhold
, PU_PD_OD
, PALMAS_PU_PD_INPUT_CTRL3
, 0x4, 0x0, -1, 0x4);
398 PULL_UP_DN(msecure
, PU_PD_OD
, PALMAS_PU_PD_INPUT_CTRL3
, 0x1, 0x0, -1, 0x1);
399 PULL_UP_DN(id
, USB_OTG
, PALMAS_USB_ID_CTRL_SET
, 0x40, 0x0, 0x40, -1);
400 PULL_UP_DN(gpio0
, GPIO
, PALMAS_PU_PD_GPIO_CTRL1
, 0x04, 0, -1, 1);
401 PULL_UP_DN(gpio1
, GPIO
, PALMAS_PU_PD_GPIO_CTRL1
, 0x0C, 0, 0x8, 0x4);
402 PULL_UP_DN(gpio2
, GPIO
, PALMAS_PU_PD_GPIO_CTRL1
, 0x30, 0x0, 0x20, 0x10);
403 PULL_UP_DN(gpio3
, GPIO
, PALMAS_PU_PD_GPIO_CTRL1
, 0x40, 0x0, -1, 0x40);
404 PULL_UP_DN(gpio4
, GPIO
, PALMAS_PU_PD_GPIO_CTRL2
, 0x03, 0x0, 0x2, 0x1);
405 PULL_UP_DN(gpio5
, GPIO
, PALMAS_PU_PD_GPIO_CTRL2
, 0x0c, 0x0, 0x8, 0x4);
406 PULL_UP_DN(gpio6
, GPIO
, PALMAS_PU_PD_GPIO_CTRL2
, 0x30, 0x0, 0x20, 0x10);
407 PULL_UP_DN(gpio7
, GPIO
, PALMAS_PU_PD_GPIO_CTRL2
, 0x40, 0x0, -1, 0x40);
408 PULL_UP_DN(gpio9
, GPIO
, PALMAS_PU_PD_GPIO_CTRL3
, 0x0C, 0x0, 0x8, 0x4);
409 PULL_UP_DN(gpio10
, GPIO
, PALMAS_PU_PD_GPIO_CTRL3
, 0x30, 0x0, 0x20, 0x10);
410 PULL_UP_DN(gpio11
, GPIO
, PALMAS_PU_PD_GPIO_CTRL3
, 0xC0, 0x0, 0x80, 0x40);
411 PULL_UP_DN(gpio13
, GPIO
, PALMAS_PU_PD_GPIO_CTRL4
, 0x04, 0x0, -1, 0x04);
412 PULL_UP_DN(gpio14
, GPIO
, PALMAS_PU_PD_GPIO_CTRL4
, 0x30, 0x0, 0x20, 0x10);
414 #define OD_INFO(_name, _rbase, _add, _mask, _ev, _dv) \
415 static const struct palmas_pins_od_info od_##_name##_info = { \
416 .od_reg_base = PALMAS_##_rbase##_BASE, \
417 .od_reg_add = _add, \
423 OD_INFO(gpio1
, GPIO
, PALMAS_OD_OUTPUT_GPIO_CTRL
, 0x1, 0x1, 0x0);
424 OD_INFO(gpio2
, GPIO
, PALMAS_OD_OUTPUT_GPIO_CTRL
, 0x2, 0x2, 0x0);
425 OD_INFO(gpio5
, GPIO
, PALMAS_OD_OUTPUT_GPIO_CTRL
, 0x20, 0x20, 0x0);
426 OD_INFO(gpio10
, GPIO
, PALMAS_OD_OUTPUT_GPIO_CTRL2
, 0x04, 0x04, 0x0);
427 OD_INFO(gpio13
, GPIO
, PALMAS_OD_OUTPUT_GPIO_CTRL2
, 0x20, 0x20, 0x0);
428 OD_INFO(int, PU_PD_OD
, PALMAS_OD_OUTPUT_CTRL
, 0x8, 0x8, 0x0);
429 OD_INFO(pwm1
, PU_PD_OD
, PALMAS_OD_OUTPUT_CTRL
, 0x20, 0x20, 0x0);
430 OD_INFO(pwm2
, PU_PD_OD
, PALMAS_OD_OUTPUT_CTRL
, 0x80, 0x80, 0x0);
431 OD_INFO(vbus_det
, PU_PD_OD
, PALMAS_OD_OUTPUT_CTRL
, 0x40, 0x40, 0x0);
433 #define PIN_INFO(_name, _id, _pud_info, _od_info) \
434 static const struct palmas_pin_info pin_##_name##_info = { \
435 .mux_opt = PALMAS_PINMUX_##_id, \
436 .pud_info = _pud_info, \
437 .od_info = _od_info \
440 PIN_INFO(gpio0
, GPIO
, &pud_gpio0_info
, NULL
);
441 PIN_INFO(gpio1
, GPIO
, &pud_gpio1_info
, &od_gpio1_info
);
442 PIN_INFO(gpio2
, GPIO
, &pud_gpio2_info
, &od_gpio2_info
);
443 PIN_INFO(gpio3
, GPIO
, &pud_gpio3_info
, NULL
);
444 PIN_INFO(gpio4
, GPIO
, &pud_gpio4_info
, NULL
);
445 PIN_INFO(gpio5
, GPIO
, &pud_gpio5_info
, &od_gpio5_info
);
446 PIN_INFO(gpio6
, GPIO
, &pud_gpio6_info
, NULL
);
447 PIN_INFO(gpio7
, GPIO
, &pud_gpio7_info
, NULL
);
448 PIN_INFO(gpio8
, GPIO
, NULL
, NULL
);
449 PIN_INFO(gpio9
, GPIO
, &pud_gpio9_info
, NULL
);
450 PIN_INFO(gpio10
, GPIO
, &pud_gpio10_info
, &od_gpio10_info
);
451 PIN_INFO(gpio11
, GPIO
, &pud_gpio11_info
, NULL
);
452 PIN_INFO(gpio12
, GPIO
, NULL
, NULL
);
453 PIN_INFO(gpio13
, GPIO
, &pud_gpio13_info
, &od_gpio13_info
);
454 PIN_INFO(gpio14
, GPIO
, &pud_gpio14_info
, NULL
);
455 PIN_INFO(gpio15
, GPIO
, NULL
, NULL
);
456 PIN_INFO(id
, ID
, &pud_id_info
, NULL
);
457 PIN_INFO(led1
, LED
, NULL
, NULL
);
458 PIN_INFO(led2
, LED
, NULL
, NULL
);
459 PIN_INFO(regen
, REGEN
, NULL
, NULL
);
460 PIN_INFO(sysen1
, SYSEN
, NULL
, NULL
);
461 PIN_INFO(sysen2
, SYSEN
, NULL
, NULL
);
462 PIN_INFO(int, INT
, NULL
, &od_int_info
);
463 PIN_INFO(pwm1
, PWM
, NULL
, &od_pwm1_info
);
464 PIN_INFO(pwm2
, PWM
, NULL
, &od_pwm2_info
);
465 PIN_INFO(vacok
, VACOK
, &pud_vacok_info
, NULL
);
466 PIN_INFO(chrg_det
, CHRG_DET
, &pud_chrg_det_info
, NULL
);
467 PIN_INFO(pwrhold
, PWRHOLD
, &pud_pwrhold_info
, NULL
);
468 PIN_INFO(msecure
, MSECURE
, &pud_msecure_info
, NULL
);
469 PIN_INFO(nreswarm
, NA
, &pud_nreswarm_info
, NULL
);
470 PIN_INFO(pwrdown
, NA
, &pud_pwrdown_info
, NULL
);
471 PIN_INFO(gpadc_start
, NA
, &pud_gpadc_start_info
, NULL
);
472 PIN_INFO(reset_in
, NA
, &pud_reset_in_info
, NULL
);
473 PIN_INFO(nsleep
, NA
, &pud_nsleep_info
, NULL
);
474 PIN_INFO(enable1
, NA
, &pud_enable1_info
, NULL
);
475 PIN_INFO(enable2
, NA
, &pud_enable2_info
, NULL
);
476 PIN_INFO(clk32kgaudio
, CLK32KGAUDIO
, NULL
, NULL
);
477 PIN_INFO(usb_psel
, USB_PSEL
, NULL
, NULL
);
478 PIN_INFO(vac
, VAC
, NULL
, NULL
);
479 PIN_INFO(powergood
, POWERGOOD
, NULL
, NULL
);
480 PIN_INFO(vbus_det
, VBUS_DET
, NULL
, &od_vbus_det_info
);
481 PIN_INFO(sim1rsti
, SIMRSTI
, NULL
, NULL
);
482 PIN_INFO(low_vbat
, LOW_VBAT
, NULL
, NULL
);
483 PIN_INFO(rcm
, RCM
, NULL
, NULL
);
484 PIN_INFO(sim2rsto
, SIMRSTO
, NULL
, NULL
);
485 PIN_INFO(sim2rsti
, SIMRSTI
, NULL
, NULL
);
486 PIN_INFO(wireless_chrg1
, WIRELESS_CHRG1
, NULL
, NULL
);
488 #define PALMAS_PRIMARY_SECONDARY_NONE 0
489 #define PALMAS_NONE_BASE 0
490 #define PALMAS_PRIMARY_SECONDARY_INPUT3 PALMAS_PU_PD_INPUT_CTRL3
492 #define PALMAS_PINGROUP(pg_name, pin_id, base, reg, _mask, _bshift, o0, o1, o2, o3) \
495 .pins = {PALMAS_PIN_##pin_id}, \
497 .mux_reg_base = PALMAS_##base##_BASE, \
498 .mux_reg_add = PALMAS_PRIMARY_SECONDARY_##reg, \
499 .mux_reg_mask = _mask, \
500 .mux_bit_shift = _bshift, \
509 static const struct palmas_pingroup tps65913_pingroups
[] = {
510 PALMAS_PINGROUP(gpio0
, GPIO0_ID
, PU_PD_OD
, PAD1
, 0x4, 0x2, &pin_gpio0_info
, &pin_id_info
, NULL
, NULL
),
511 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
),
512 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
),
513 PALMAS_PINGROUP(gpio3
, GPIO3_CHRG_DET
, PU_PD_OD
, PAD1
, 0x80, 0x7, &pin_gpio3_info
, &pin_chrg_det_info
, NULL
, NULL
),
514 PALMAS_PINGROUP(gpio4
, GPIO4_SYSEN1
, PU_PD_OD
, PAD1
, 0x01, 0x0, &pin_gpio4_info
, &pin_sysen1_info
, NULL
, NULL
),
515 PALMAS_PINGROUP(gpio5
, GPIO5_CLK32KGAUDIO_USB_PSEL
, PU_PD_OD
, PAD2
, 0x6, 0x1, &pin_gpio5_info
, &pin_clk32kgaudio_info
, &pin_usb_psel_info
, NULL
),
516 PALMAS_PINGROUP(gpio6
, GPIO6_SYSEN2
, PU_PD_OD
, PAD2
, 0x08, 0x3, &pin_gpio6_info
, &pin_sysen2_info
, NULL
, NULL
),
517 PALMAS_PINGROUP(gpio7
, GPIO7_MSECURE_PWRHOLD
, PU_PD_OD
, PAD2
, 0x30, 0x4, &pin_gpio7_info
, &pin_msecure_info
, &pin_pwrhold_info
, NULL
),
518 PALMAS_PINGROUP(vac
, VAC
, PU_PD_OD
, PAD1
, 0x02, 0x1, &pin_vac_info
, &pin_vacok_info
, NULL
, NULL
),
519 PALMAS_PINGROUP(powergood
, POWERGOOD_USB_PSEL
, PU_PD_OD
, PAD1
, 0x01, 0x0, &pin_powergood_info
, &pin_usb_psel_info
, NULL
, NULL
),
520 PALMAS_PINGROUP(nreswarm
, NRESWARM
, NONE
, NONE
, 0x0, 0x0, &pin_nreswarm_info
, NULL
, NULL
, NULL
),
521 PALMAS_PINGROUP(pwrdown
, PWRDOWN
, NONE
, NONE
, 0x0, 0x0, &pin_pwrdown_info
, NULL
, NULL
, NULL
),
522 PALMAS_PINGROUP(gpadc_start
, GPADC_START
, NONE
, NONE
, 0x0, 0x0, &pin_gpadc_start_info
, NULL
, NULL
, NULL
),
523 PALMAS_PINGROUP(reset_in
, RESET_IN
, NONE
, NONE
, 0x0, 0x0, &pin_reset_in_info
, NULL
, NULL
, NULL
),
524 PALMAS_PINGROUP(nsleep
, NSLEEP
, NONE
, NONE
, 0x0, 0x0, &pin_nsleep_info
, NULL
, NULL
, NULL
),
525 PALMAS_PINGROUP(enable1
, ENABLE1
, NONE
, NONE
, 0x0, 0x0, &pin_enable1_info
, NULL
, NULL
, NULL
),
526 PALMAS_PINGROUP(enable2
, ENABLE2
, NONE
, NONE
, 0x0, 0x0, &pin_enable2_info
, NULL
, NULL
, NULL
),
527 PALMAS_PINGROUP(int, INT
, NONE
, NONE
, 0x0, 0x0, &pin_int_info
, NULL
, NULL
, NULL
),
530 static const struct palmas_pingroup tps80036_pingroups
[] = {
531 PALMAS_PINGROUP(gpio0
, GPIO0_ID
, PU_PD_OD
, PAD1
, 0x4, 0x2, &pin_gpio0_info
, &pin_id_info
, NULL
, NULL
),
532 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
),
533 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
),
534 PALMAS_PINGROUP(gpio3
, GPIO3_CHRG_DET
, PU_PD_OD
, PAD1
, 0x80, 0x7, &pin_gpio3_info
, &pin_chrg_det_info
, NULL
, NULL
),
535 PALMAS_PINGROUP(gpio4
, GPIO4_SYSEN1
, PU_PD_OD
, PAD1
, 0x01, 0x0, &pin_gpio4_info
, &pin_sysen1_info
, NULL
, NULL
),
536 PALMAS_PINGROUP(gpio5
, GPIO5_CLK32KGAUDIO_USB_PSEL
, PU_PD_OD
, PAD2
, 0x6, 0x1, &pin_gpio5_info
, &pin_clk32kgaudio_info
, &pin_usb_psel_info
, NULL
),
537 PALMAS_PINGROUP(gpio6
, GPIO6_SYSEN2
, PU_PD_OD
, PAD2
, 0x08, 0x3, &pin_gpio6_info
, &pin_sysen2_info
, NULL
, NULL
),
538 PALMAS_PINGROUP(gpio7
, GPIO7_MSECURE_PWRHOLD
, PU_PD_OD
, PAD2
, 0x30, 0x4, &pin_gpio7_info
, &pin_msecure_info
, &pin_pwrhold_info
, NULL
),
539 PALMAS_PINGROUP(gpio8
, GPIO8_SIM1RSTI
, PU_PD_OD
, PAD4
, 0x01, 0x0, &pin_gpio8_info
, &pin_sim1rsti_info
, NULL
, NULL
),
540 PALMAS_PINGROUP(gpio9
, GPIO9_LOW_VBAT
, PU_PD_OD
, PAD4
, 0x02, 0x1, &pin_gpio9_info
, &pin_low_vbat_info
, NULL
, NULL
),
541 PALMAS_PINGROUP(gpio10
, GPIO10_WIRELESS_CHRG1
, PU_PD_OD
, PAD4
, 0x04, 0x2, &pin_gpio10_info
, &pin_wireless_chrg1_info
, NULL
, NULL
),
542 PALMAS_PINGROUP(gpio11
, GPIO11_RCM
, PU_PD_OD
, PAD4
, 0x08, 0x3, &pin_gpio11_info
, &pin_rcm_info
, NULL
, NULL
),
543 PALMAS_PINGROUP(gpio12
, GPIO12_SIM2RSTO
, PU_PD_OD
, PAD4
, 0x10, 0x4, &pin_gpio12_info
, &pin_sim2rsto_info
, NULL
, NULL
),
544 PALMAS_PINGROUP(gpio13
, GPIO13
, NONE
, NONE
, 0x00, 0x0, &pin_gpio13_info
, NULL
, NULL
, NULL
),
545 PALMAS_PINGROUP(gpio14
, GPIO14
, NONE
, NONE
, 0x00, 0x0, &pin_gpio14_info
, NULL
, NULL
, NULL
),
546 PALMAS_PINGROUP(gpio15
, GPIO15_SIM2RSTI
, PU_PD_OD
, PAD4
, 0x80, 0x7, &pin_gpio15_info
, &pin_sim2rsti_info
, NULL
, NULL
),
547 PALMAS_PINGROUP(vac
, VAC
, PU_PD_OD
, PAD1
, 0x02, 0x1, &pin_vac_info
, &pin_vacok_info
, NULL
, NULL
),
548 PALMAS_PINGROUP(powergood
, POWERGOOD_USB_PSEL
, PU_PD_OD
, PAD1
, 0x01, 0x0, &pin_powergood_info
, &pin_usb_psel_info
, NULL
, NULL
),
549 PALMAS_PINGROUP(nreswarm
, NRESWARM
, NONE
, NONE
, 0x0, 0x0, &pin_nreswarm_info
, NULL
, NULL
, NULL
),
550 PALMAS_PINGROUP(pwrdown
, PWRDOWN
, NONE
, NONE
, 0x0, 0x0, &pin_pwrdown_info
, NULL
, NULL
, NULL
),
551 PALMAS_PINGROUP(gpadc_start
, GPADC_START
, NONE
, NONE
, 0x0, 0x0, &pin_gpadc_start_info
, NULL
, NULL
, NULL
),
552 PALMAS_PINGROUP(reset_in
, RESET_IN
, NONE
, NONE
, 0x0, 0x0, &pin_reset_in_info
, NULL
, NULL
, NULL
),
553 PALMAS_PINGROUP(nsleep
, NSLEEP
, NONE
, NONE
, 0x0, 0x0, &pin_nsleep_info
, NULL
, NULL
, NULL
),
554 PALMAS_PINGROUP(enable1
, ENABLE1
, NONE
, NONE
, 0x0, 0x0, &pin_enable1_info
, NULL
, NULL
, NULL
),
555 PALMAS_PINGROUP(enable2
, ENABLE2
, NONE
, NONE
, 0x0, 0x0, &pin_enable2_info
, NULL
, NULL
, NULL
),
556 PALMAS_PINGROUP(int, INT
, NONE
, NONE
, 0x0, 0x0, &pin_int_info
, NULL
, NULL
, NULL
),
559 static int palmas_pinctrl_get_pin_mux(struct palmas_pctrl_chip_info
*pci
)
561 const struct palmas_pingroup
*g
;
566 for (i
= 0; i
< pci
->num_pin_groups
; ++i
) {
567 g
= &pci
->pin_groups
[i
];
568 if (g
->mux_reg_base
== PALMAS_NONE_BASE
) {
569 pci
->pins_current_opt
[i
] = 0;
572 ret
= palmas_read(pci
->palmas
, g
->mux_reg_base
,
573 g
->mux_reg_add
, &val
);
575 dev_err(pci
->dev
, "mux_reg 0x%02x read failed: %d\n",
576 g
->mux_reg_add
, ret
);
579 val
&= g
->mux_reg_mask
;
580 pci
->pins_current_opt
[i
] = val
>> g
->mux_bit_shift
;
585 static int palmas_pinctrl_set_dvfs1(struct palmas_pctrl_chip_info
*pci
,
591 val
= enable
? PALMAS_PRIMARY_SECONDARY_PAD3_DVFS1
: 0;
592 ret
= palmas_update_bits(pci
->palmas
, PALMAS_PU_PD_OD_BASE
,
593 PALMAS_PRIMARY_SECONDARY_PAD3
,
594 PALMAS_PRIMARY_SECONDARY_PAD3_DVFS1
, val
);
596 dev_err(pci
->dev
, "SECONDARY_PAD3 update failed %d\n", ret
);
600 static int palmas_pinctrl_set_dvfs2(struct palmas_pctrl_chip_info
*pci
,
606 val
= enable
? PALMAS_PRIMARY_SECONDARY_PAD3_DVFS2
: 0;
607 ret
= palmas_update_bits(pci
->palmas
, PALMAS_PU_PD_OD_BASE
,
608 PALMAS_PRIMARY_SECONDARY_PAD3
,
609 PALMAS_PRIMARY_SECONDARY_PAD3_DVFS2
, val
);
611 dev_err(pci
->dev
, "SECONDARY_PAD3 update failed %d\n", ret
);
615 static int palmas_pinctrl_get_groups_count(struct pinctrl_dev
*pctldev
)
617 struct palmas_pctrl_chip_info
*pci
= pinctrl_dev_get_drvdata(pctldev
);
619 return pci
->num_pin_groups
;
622 static const char *palmas_pinctrl_get_group_name(struct pinctrl_dev
*pctldev
,
625 struct palmas_pctrl_chip_info
*pci
= pinctrl_dev_get_drvdata(pctldev
);
627 return pci
->pin_groups
[group
].name
;
630 static int palmas_pinctrl_get_group_pins(struct pinctrl_dev
*pctldev
,
631 unsigned group
, const unsigned **pins
, unsigned *num_pins
)
633 struct palmas_pctrl_chip_info
*pci
= pinctrl_dev_get_drvdata(pctldev
);
635 *pins
= pci
->pin_groups
[group
].pins
;
636 *num_pins
= pci
->pin_groups
[group
].npins
;
640 static const struct pinctrl_ops palmas_pinctrl_ops
= {
641 .get_groups_count
= palmas_pinctrl_get_groups_count
,
642 .get_group_name
= palmas_pinctrl_get_group_name
,
643 .get_group_pins
= palmas_pinctrl_get_group_pins
,
644 .dt_node_to_map
= pinconf_generic_dt_node_to_map_pin
,
645 .dt_free_map
= pinctrl_utils_free_map
,
648 static int palmas_pinctrl_get_funcs_count(struct pinctrl_dev
*pctldev
)
650 struct palmas_pctrl_chip_info
*pci
= pinctrl_dev_get_drvdata(pctldev
);
652 return pci
->num_functions
;
655 static const char *palmas_pinctrl_get_func_name(struct pinctrl_dev
*pctldev
,
658 struct palmas_pctrl_chip_info
*pci
= pinctrl_dev_get_drvdata(pctldev
);
660 return pci
->functions
[function
].name
;
663 static int palmas_pinctrl_get_func_groups(struct pinctrl_dev
*pctldev
,
664 unsigned function
, const char * const **groups
,
665 unsigned * const num_groups
)
667 struct palmas_pctrl_chip_info
*pci
= pinctrl_dev_get_drvdata(pctldev
);
669 *groups
= pci
->functions
[function
].groups
;
670 *num_groups
= pci
->functions
[function
].ngroups
;
674 static int palmas_pinctrl_set_mux(struct pinctrl_dev
*pctldev
,
678 struct palmas_pctrl_chip_info
*pci
= pinctrl_dev_get_drvdata(pctldev
);
679 const struct palmas_pingroup
*g
;
683 g
= &pci
->pin_groups
[group
];
685 /* If direct option is provided here */
686 if (function
<= PALMAS_PINMUX_OPTION3
) {
687 if (!g
->opt
[function
]) {
688 dev_err(pci
->dev
, "Pin %s does not support option %d\n",
694 for (i
= 0; i
< ARRAY_SIZE(g
->opt
); i
++) {
697 if (g
->opt
[i
]->mux_opt
== function
)
700 if (WARN_ON(i
== ARRAY_SIZE(g
->opt
))) {
701 dev_err(pci
->dev
, "Pin %s does not support option %d\n",
707 if (g
->mux_reg_base
== PALMAS_NONE_BASE
) {
713 dev_dbg(pci
->dev
, "%s(): Base0x%02x:0x%02x:0x%02x:0x%02x\n",
714 __func__
, g
->mux_reg_base
, g
->mux_reg_add
,
715 g
->mux_reg_mask
, i
<< g
->mux_bit_shift
);
717 ret
= palmas_update_bits(pci
->palmas
, g
->mux_reg_base
, g
->mux_reg_add
,
718 g
->mux_reg_mask
, i
<< g
->mux_bit_shift
);
720 dev_err(pci
->dev
, "Reg 0x%02x update failed: %d\n",
721 g
->mux_reg_add
, ret
);
724 pci
->pins_current_opt
[group
] = i
;
728 static const struct pinmux_ops palmas_pinmux_ops
= {
729 .get_functions_count
= palmas_pinctrl_get_funcs_count
,
730 .get_function_name
= palmas_pinctrl_get_func_name
,
731 .get_function_groups
= palmas_pinctrl_get_func_groups
,
732 .set_mux
= palmas_pinctrl_set_mux
,
735 static int palmas_pinconf_get(struct pinctrl_dev
*pctldev
,
736 unsigned pin
, unsigned long *config
)
738 struct palmas_pctrl_chip_info
*pci
= pinctrl_dev_get_drvdata(pctldev
);
739 enum pin_config_param param
= pinconf_to_config_param(*config
);
740 const struct palmas_pingroup
*g
;
741 const struct palmas_pin_info
*opt
;
749 for (group_nr
= 0; group_nr
< pci
->num_pin_groups
; ++group_nr
) {
750 if (pci
->pin_groups
[group_nr
].pins
[0] == pin
)
754 if (group_nr
== pci
->num_pin_groups
) {
756 "Pinconf is not supported for pin-id %d\n", pin
);
760 g
= &pci
->pin_groups
[group_nr
];
761 opt
= g
->opt
[pci
->pins_current_opt
[group_nr
]];
764 "Pinconf is not supported for pin %s\n", g
->name
);
769 case PIN_CONFIG_BIAS_DISABLE
:
770 case PIN_CONFIG_BIAS_PULL_UP
:
771 case PIN_CONFIG_BIAS_PULL_DOWN
:
772 if (!opt
->pud_info
) {
774 "PULL control not supported for pin %s\n",
778 base
= opt
->pud_info
->pullup_dn_reg_base
;
779 add
= opt
->pud_info
->pullup_dn_reg_add
;
780 ret
= palmas_read(pci
->palmas
, base
, add
, &val
);
782 dev_err(pci
->dev
, "Reg 0x%02x read failed: %d\n",
787 rval
= val
& opt
->pud_info
->pullup_dn_mask
;
789 if ((opt
->pud_info
->normal_val
>= 0) &&
790 (opt
->pud_info
->normal_val
== rval
) &&
791 (param
== PIN_CONFIG_BIAS_DISABLE
))
793 else if ((opt
->pud_info
->pull_up_val
>= 0) &&
794 (opt
->pud_info
->pull_up_val
== rval
) &&
795 (param
== PIN_CONFIG_BIAS_PULL_UP
))
797 else if ((opt
->pud_info
->pull_dn_val
>= 0) &&
798 (opt
->pud_info
->pull_dn_val
== rval
) &&
799 (param
== PIN_CONFIG_BIAS_PULL_DOWN
))
803 case PIN_CONFIG_DRIVE_OPEN_DRAIN
:
806 "OD control not supported for pin %s\n",
810 base
= opt
->od_info
->od_reg_base
;
811 add
= opt
->od_info
->od_reg_add
;
812 ret
= palmas_read(pci
->palmas
, base
, add
, &val
);
814 dev_err(pci
->dev
, "Reg 0x%02x read failed: %d\n",
818 rval
= val
& opt
->od_info
->od_mask
;
820 if ((opt
->od_info
->od_disable
>= 0) &&
821 (opt
->od_info
->od_disable
== rval
))
823 else if ((opt
->od_info
->od_enable
>= 0) &&
824 (opt
->od_info
->od_enable
== rval
))
828 "OD control not supported for pin %s\n",
835 dev_err(pci
->dev
, "Properties not supported\n");
839 *config
= pinconf_to_config_packed(param
, (u16
)arg
);
843 static int palmas_pinconf_set(struct pinctrl_dev
*pctldev
,
844 unsigned pin
, unsigned long *configs
,
845 unsigned num_configs
)
847 struct palmas_pctrl_chip_info
*pci
= pinctrl_dev_get_drvdata(pctldev
);
848 enum pin_config_param param
;
850 const struct palmas_pingroup
*g
;
851 const struct palmas_pin_info
*opt
;
858 for (group_nr
= 0; group_nr
< pci
->num_pin_groups
; ++group_nr
) {
859 if (pci
->pin_groups
[group_nr
].pins
[0] == pin
)
863 if (group_nr
== pci
->num_pin_groups
) {
865 "Pinconf is not supported for pin-id %d\n", pin
);
869 g
= &pci
->pin_groups
[group_nr
];
870 opt
= g
->opt
[pci
->pins_current_opt
[group_nr
]];
873 "Pinconf is not supported for pin %s\n", g
->name
);
877 for (i
= 0; i
< num_configs
; i
++) {
878 param
= pinconf_to_config_param(configs
[i
]);
879 param_val
= pinconf_to_config_argument(configs
[i
]);
882 case PIN_CONFIG_BIAS_DISABLE
:
883 case PIN_CONFIG_BIAS_PULL_UP
:
884 case PIN_CONFIG_BIAS_PULL_DOWN
:
885 if (!opt
->pud_info
) {
887 "PULL control not supported for pin %s\n",
891 base
= opt
->pud_info
->pullup_dn_reg_base
;
892 add
= opt
->pud_info
->pullup_dn_reg_add
;
893 mask
= opt
->pud_info
->pullup_dn_mask
;
895 if (param
== PIN_CONFIG_BIAS_DISABLE
)
896 rval
= opt
->pud_info
->normal_val
;
897 else if (param
== PIN_CONFIG_BIAS_PULL_UP
)
898 rval
= opt
->pud_info
->pull_up_val
;
900 rval
= opt
->pud_info
->pull_dn_val
;
904 "PULL control not supported for pin %s\n",
910 case PIN_CONFIG_DRIVE_OPEN_DRAIN
:
913 "OD control not supported for pin %s\n",
917 base
= opt
->od_info
->od_reg_base
;
918 add
= opt
->od_info
->od_reg_add
;
919 mask
= opt
->od_info
->od_mask
;
921 rval
= opt
->od_info
->od_disable
;
923 rval
= opt
->od_info
->od_enable
;
926 "OD control not supported for pin %s\n",
932 dev_err(pci
->dev
, "Properties not supported\n");
936 dev_dbg(pci
->dev
, "%s(): Add0x%02x:0x%02x:0x%02x:0x%02x\n",
937 __func__
, base
, add
, mask
, rval
);
938 ret
= palmas_update_bits(pci
->palmas
, base
, add
, mask
, rval
);
940 dev_err(pci
->dev
, "Reg 0x%02x update failed: %d\n",
944 } /* for each config */
949 static const struct pinconf_ops palmas_pinconf_ops
= {
950 .pin_config_get
= palmas_pinconf_get
,
951 .pin_config_set
= palmas_pinconf_set
,
954 static struct pinctrl_desc palmas_pinctrl_desc
= {
955 .pctlops
= &palmas_pinctrl_ops
,
956 .pmxops
= &palmas_pinmux_ops
,
957 .confops
= &palmas_pinconf_ops
,
958 .owner
= THIS_MODULE
,
961 struct palmas_pinctrl_data
{
962 const struct palmas_pingroup
*pin_groups
;
966 static struct palmas_pinctrl_data tps65913_pinctrl_data
= {
967 .pin_groups
= tps65913_pingroups
,
968 .num_pin_groups
= ARRAY_SIZE(tps65913_pingroups
),
971 static struct palmas_pinctrl_data tps80036_pinctrl_data
= {
972 .pin_groups
= tps80036_pingroups
,
973 .num_pin_groups
= ARRAY_SIZE(tps80036_pingroups
),
976 static const struct of_device_id palmas_pinctrl_of_match
[] = {
977 { .compatible
= "ti,palmas-pinctrl", .data
= &tps65913_pinctrl_data
},
978 { .compatible
= "ti,tps65913-pinctrl", .data
= &tps65913_pinctrl_data
},
979 { .compatible
= "ti,tps80036-pinctrl", .data
= &tps80036_pinctrl_data
},
982 MODULE_DEVICE_TABLE(of
, palmas_pinctrl_of_match
);
984 static int palmas_pinctrl_probe(struct platform_device
*pdev
)
986 struct palmas_pctrl_chip_info
*pci
;
987 const struct palmas_pinctrl_data
*pinctrl_data
= &tps65913_pinctrl_data
;
989 bool enable_dvfs1
= false;
990 bool enable_dvfs2
= false;
992 if (pdev
->dev
.of_node
) {
993 pinctrl_data
= of_device_get_match_data(&pdev
->dev
);
994 enable_dvfs1
= of_property_read_bool(pdev
->dev
.of_node
,
995 "ti,palmas-enable-dvfs1");
996 enable_dvfs2
= of_property_read_bool(pdev
->dev
.of_node
,
997 "ti,palmas-enable-dvfs2");
1000 pci
= devm_kzalloc(&pdev
->dev
, sizeof(*pci
), GFP_KERNEL
);
1004 pci
->dev
= &pdev
->dev
;
1005 pci
->palmas
= dev_get_drvdata(pdev
->dev
.parent
);
1007 pci
->pins
= palmas_pins_desc
;
1008 pci
->num_pins
= ARRAY_SIZE(palmas_pins_desc
);
1009 pci
->functions
= palmas_pin_function
;
1010 pci
->num_functions
= ARRAY_SIZE(palmas_pin_function
);
1011 pci
->pin_groups
= pinctrl_data
->pin_groups
;
1012 pci
->num_pin_groups
= pinctrl_data
->num_pin_groups
;
1014 platform_set_drvdata(pdev
, pci
);
1016 palmas_pinctrl_set_dvfs1(pci
, enable_dvfs1
);
1017 palmas_pinctrl_set_dvfs2(pci
, enable_dvfs2
);
1018 ret
= palmas_pinctrl_get_pin_mux(pci
);
1021 "Reading pinctrol option register failed: %d\n", ret
);
1025 palmas_pinctrl_desc
.name
= dev_name(&pdev
->dev
);
1026 palmas_pinctrl_desc
.pins
= palmas_pins_desc
;
1027 palmas_pinctrl_desc
.npins
= ARRAY_SIZE(palmas_pins_desc
);
1028 pci
->pctl
= devm_pinctrl_register(&pdev
->dev
, &palmas_pinctrl_desc
,
1030 if (IS_ERR(pci
->pctl
)) {
1031 dev_err(&pdev
->dev
, "Couldn't register pinctrl driver\n");
1032 return PTR_ERR(pci
->pctl
);
1037 static struct platform_driver palmas_pinctrl_driver
= {
1039 .name
= "palmas-pinctrl",
1040 .of_match_table
= palmas_pinctrl_of_match
,
1042 .probe
= palmas_pinctrl_probe
,
1045 module_platform_driver(palmas_pinctrl_driver
);
1047 MODULE_DESCRIPTION("Palmas pin control driver");
1048 MODULE_AUTHOR("Laxman Dewangan<ldewangan@nvidia.com>");
1049 MODULE_ALIAS("platform:palmas-pinctrl");
1050 MODULE_LICENSE("GPL v2");