1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2015, Sony Mobile Communications AB.
4 * Copyright (c) 2013, The Linux Foundation. All rights reserved.
7 #include <linux/module.h>
8 #include <linux/platform_device.h>
9 #include <linux/pinctrl/pinctrl.h>
10 #include <linux/pinctrl/pinmux.h>
11 #include <linux/pinctrl/pinconf.h>
12 #include <linux/pinctrl/pinconf-generic.h>
13 #include <linux/slab.h>
14 #include <linux/regmap.h>
15 #include <linux/gpio/driver.h>
16 #include <linux/interrupt.h>
17 #include <linux/of_device.h>
18 #include <linux/of_irq.h>
20 #include <dt-bindings/pinctrl/qcom,pmic-mpp.h>
23 #include "../pinctrl-utils.h"
26 #define SSBI_REG_ADDR_MPP_BASE 0x50
27 #define SSBI_REG_ADDR_MPP(n) (SSBI_REG_ADDR_MPP_BASE + n)
30 #define PM8XXX_MPP_TYPE_D_INPUT 0
31 #define PM8XXX_MPP_TYPE_D_OUTPUT 1
32 #define PM8XXX_MPP_TYPE_D_BI_DIR 2
33 #define PM8XXX_MPP_TYPE_A_INPUT 3
34 #define PM8XXX_MPP_TYPE_A_OUTPUT 4
35 #define PM8XXX_MPP_TYPE_SINK 5
36 #define PM8XXX_MPP_TYPE_DTEST_SINK 6
37 #define PM8XXX_MPP_TYPE_DTEST_OUTPUT 7
39 /* Digital Input: control */
40 #define PM8XXX_MPP_DIN_TO_INT 0
41 #define PM8XXX_MPP_DIN_TO_DBUS1 1
42 #define PM8XXX_MPP_DIN_TO_DBUS2 2
43 #define PM8XXX_MPP_DIN_TO_DBUS3 3
45 /* Digital Output: control */
46 #define PM8XXX_MPP_DOUT_CTRL_LOW 0
47 #define PM8XXX_MPP_DOUT_CTRL_HIGH 1
48 #define PM8XXX_MPP_DOUT_CTRL_MPP 2
49 #define PM8XXX_MPP_DOUT_CTRL_INV_MPP 3
51 /* Bidirectional: control */
52 #define PM8XXX_MPP_BI_PULLUP_1KOHM 0
53 #define PM8XXX_MPP_BI_PULLUP_OPEN 1
54 #define PM8XXX_MPP_BI_PULLUP_10KOHM 2
55 #define PM8XXX_MPP_BI_PULLUP_30KOHM 3
57 /* Analog Output: control */
58 #define PM8XXX_MPP_AOUT_CTRL_DISABLE 0
59 #define PM8XXX_MPP_AOUT_CTRL_ENABLE 1
60 #define PM8XXX_MPP_AOUT_CTRL_MPP_HIGH_EN 2
61 #define PM8XXX_MPP_AOUT_CTRL_MPP_LOW_EN 3
63 /* Current Sink: control */
64 #define PM8XXX_MPP_CS_CTRL_DISABLE 0
65 #define PM8XXX_MPP_CS_CTRL_ENABLE 1
66 #define PM8XXX_MPP_CS_CTRL_MPP_HIGH_EN 2
67 #define PM8XXX_MPP_CS_CTRL_MPP_LOW_EN 3
69 /* DTEST Current Sink: control */
70 #define PM8XXX_MPP_DTEST_CS_CTRL_EN1 0
71 #define PM8XXX_MPP_DTEST_CS_CTRL_EN2 1
72 #define PM8XXX_MPP_DTEST_CS_CTRL_EN3 2
73 #define PM8XXX_MPP_DTEST_CS_CTRL_EN4 3
75 /* DTEST Digital Output: control */
76 #define PM8XXX_MPP_DTEST_DBUS1 0
77 #define PM8XXX_MPP_DTEST_DBUS2 1
78 #define PM8XXX_MPP_DTEST_DBUS3 2
79 #define PM8XXX_MPP_DTEST_DBUS4 3
81 /* custom pinconf parameters */
82 #define PM8XXX_CONFIG_AMUX (PIN_CONFIG_END + 1)
83 #define PM8XXX_CONFIG_DTEST_SELECTOR (PIN_CONFIG_END + 2)
84 #define PM8XXX_CONFIG_ALEVEL (PIN_CONFIG_END + 3)
85 #define PM8XXX_CONFIG_PAIRED (PIN_CONFIG_END + 4)
88 * struct pm8xxx_pin_data - dynamic configuration for a pin
89 * @reg: address of the control register
90 * @irq: IRQ from the PMIC interrupt controller
91 * @mode: operating mode for the pin (digital, analog or current sink)
92 * @input: pin is input
93 * @output: pin is output
94 * @high_z: pin is floating
95 * @paired: mpp operates in paired mode
96 * @output_value: logical output value of the mpp
97 * @power_source: selected power source
98 * @dtest: DTEST route selector
99 * @amux: input muxing in analog mode
100 * @aout_level: selector of the output in analog mode
101 * @drive_strength: drive strength of the current sink
102 * @pullup: pull up value, when in digital bidirectional mode
104 struct pm8xxx_pin_data
{
126 struct regmap
*regmap
;
127 struct pinctrl_dev
*pctrl
;
128 struct gpio_chip chip
;
130 struct pinctrl_desc desc
;
134 static const struct pinconf_generic_params pm8xxx_mpp_bindings
[] = {
135 {"qcom,amux-route", PM8XXX_CONFIG_AMUX
, 0},
136 {"qcom,analog-level", PM8XXX_CONFIG_ALEVEL
, 0},
137 {"qcom,dtest", PM8XXX_CONFIG_DTEST_SELECTOR
, 0},
138 {"qcom,paired", PM8XXX_CONFIG_PAIRED
, 0},
141 #ifdef CONFIG_DEBUG_FS
142 static const struct pin_config_item pm8xxx_conf_items
[] = {
143 PCONFDUMP(PM8XXX_CONFIG_AMUX
, "analog mux", NULL
, true),
144 PCONFDUMP(PM8XXX_CONFIG_ALEVEL
, "analog level", NULL
, true),
145 PCONFDUMP(PM8XXX_CONFIG_DTEST_SELECTOR
, "dtest", NULL
, true),
146 PCONFDUMP(PM8XXX_CONFIG_PAIRED
, "paired", NULL
, false),
150 #define PM8XXX_MAX_MPPS 12
151 static const char * const pm8xxx_groups
[PM8XXX_MAX_MPPS
] = {
152 "mpp1", "mpp2", "mpp3", "mpp4", "mpp5", "mpp6", "mpp7", "mpp8",
153 "mpp9", "mpp10", "mpp11", "mpp12",
156 #define PM8XXX_MPP_DIGITAL 0
157 #define PM8XXX_MPP_ANALOG 1
158 #define PM8XXX_MPP_SINK 2
160 static const char * const pm8xxx_mpp_functions
[] = {
161 "digital", "analog", "sink",
164 static int pm8xxx_mpp_update(struct pm8xxx_mpp
*pctrl
,
165 struct pm8xxx_pin_data
*pin
)
174 case PM8XXX_MPP_DIGITAL
:
176 type
= PM8XXX_MPP_TYPE_DTEST_OUTPUT
;
177 ctrl
= pin
->dtest
- 1;
178 } else if (pin
->input
&& pin
->output
) {
179 type
= PM8XXX_MPP_TYPE_D_BI_DIR
;
181 ctrl
= PM8XXX_MPP_BI_PULLUP_OPEN
;
182 else if (pin
->pullup
== 600)
183 ctrl
= PM8XXX_MPP_BI_PULLUP_1KOHM
;
184 else if (pin
->pullup
== 10000)
185 ctrl
= PM8XXX_MPP_BI_PULLUP_10KOHM
;
187 ctrl
= PM8XXX_MPP_BI_PULLUP_30KOHM
;
188 } else if (pin
->input
) {
189 type
= PM8XXX_MPP_TYPE_D_INPUT
;
193 ctrl
= PM8XXX_MPP_DIN_TO_INT
;
195 type
= PM8XXX_MPP_TYPE_D_OUTPUT
;
196 ctrl
= !!pin
->output_value
;
201 level
= pin
->power_source
;
203 case PM8XXX_MPP_ANALOG
:
205 type
= PM8XXX_MPP_TYPE_A_OUTPUT
;
206 level
= pin
->aout_level
;
207 ctrl
= pin
->output_value
;
211 type
= PM8XXX_MPP_TYPE_A_INPUT
;
216 case PM8XXX_MPP_SINK
:
217 level
= (pin
->drive_strength
/ 5) - 1;
219 type
= PM8XXX_MPP_TYPE_DTEST_SINK
;
220 ctrl
= pin
->dtest
- 1;
222 type
= PM8XXX_MPP_TYPE_SINK
;
223 ctrl
= pin
->output_value
;
232 val
= type
<< 5 | level
<< 2 | ctrl
;
233 ret
= regmap_write(pctrl
->regmap
, pin
->reg
, val
);
235 dev_err(pctrl
->dev
, "failed to write register\n");
240 static int pm8xxx_get_groups_count(struct pinctrl_dev
*pctldev
)
242 struct pm8xxx_mpp
*pctrl
= pinctrl_dev_get_drvdata(pctldev
);
247 static const char *pm8xxx_get_group_name(struct pinctrl_dev
*pctldev
,
250 return pm8xxx_groups
[group
];
254 static int pm8xxx_get_group_pins(struct pinctrl_dev
*pctldev
,
256 const unsigned **pins
,
259 struct pm8xxx_mpp
*pctrl
= pinctrl_dev_get_drvdata(pctldev
);
261 *pins
= &pctrl
->desc
.pins
[group
].number
;
267 static const struct pinctrl_ops pm8xxx_pinctrl_ops
= {
268 .get_groups_count
= pm8xxx_get_groups_count
,
269 .get_group_name
= pm8xxx_get_group_name
,
270 .get_group_pins
= pm8xxx_get_group_pins
,
271 .dt_node_to_map
= pinconf_generic_dt_node_to_map_group
,
272 .dt_free_map
= pinctrl_utils_free_map
,
275 static int pm8xxx_get_functions_count(struct pinctrl_dev
*pctldev
)
277 return ARRAY_SIZE(pm8xxx_mpp_functions
);
280 static const char *pm8xxx_get_function_name(struct pinctrl_dev
*pctldev
,
283 return pm8xxx_mpp_functions
[function
];
286 static int pm8xxx_get_function_groups(struct pinctrl_dev
*pctldev
,
288 const char * const **groups
,
289 unsigned * const num_groups
)
291 struct pm8xxx_mpp
*pctrl
= pinctrl_dev_get_drvdata(pctldev
);
293 *groups
= pm8xxx_groups
;
294 *num_groups
= pctrl
->npins
;
298 static int pm8xxx_pinmux_set_mux(struct pinctrl_dev
*pctldev
,
302 struct pm8xxx_mpp
*pctrl
= pinctrl_dev_get_drvdata(pctldev
);
303 struct pm8xxx_pin_data
*pin
= pctrl
->desc
.pins
[group
].drv_data
;
305 pin
->mode
= function
;
306 pm8xxx_mpp_update(pctrl
, pin
);
311 static const struct pinmux_ops pm8xxx_pinmux_ops
= {
312 .get_functions_count
= pm8xxx_get_functions_count
,
313 .get_function_name
= pm8xxx_get_function_name
,
314 .get_function_groups
= pm8xxx_get_function_groups
,
315 .set_mux
= pm8xxx_pinmux_set_mux
,
318 static int pm8xxx_pin_config_get(struct pinctrl_dev
*pctldev
,
320 unsigned long *config
)
322 struct pm8xxx_mpp
*pctrl
= pinctrl_dev_get_drvdata(pctldev
);
323 struct pm8xxx_pin_data
*pin
= pctrl
->desc
.pins
[offset
].drv_data
;
324 unsigned param
= pinconf_to_config_param(*config
);
328 case PIN_CONFIG_BIAS_PULL_UP
:
331 case PIN_CONFIG_BIAS_HIGH_IMPEDANCE
:
334 case PIN_CONFIG_INPUT_ENABLE
:
337 case PIN_CONFIG_OUTPUT
:
338 arg
= pin
->output_value
;
340 case PIN_CONFIG_POWER_SOURCE
:
341 arg
= pin
->power_source
;
343 case PIN_CONFIG_DRIVE_STRENGTH
:
344 arg
= pin
->drive_strength
;
346 case PM8XXX_CONFIG_DTEST_SELECTOR
:
349 case PM8XXX_CONFIG_AMUX
:
352 case PM8XXX_CONFIG_ALEVEL
:
353 arg
= pin
->aout_level
;
355 case PM8XXX_CONFIG_PAIRED
:
362 *config
= pinconf_to_config_packed(param
, arg
);
367 static int pm8xxx_pin_config_set(struct pinctrl_dev
*pctldev
,
369 unsigned long *configs
,
370 unsigned num_configs
)
372 struct pm8xxx_mpp
*pctrl
= pinctrl_dev_get_drvdata(pctldev
);
373 struct pm8xxx_pin_data
*pin
= pctrl
->desc
.pins
[offset
].drv_data
;
378 for (i
= 0; i
< num_configs
; i
++) {
379 param
= pinconf_to_config_param(configs
[i
]);
380 arg
= pinconf_to_config_argument(configs
[i
]);
383 case PIN_CONFIG_BIAS_PULL_UP
:
386 case PIN_CONFIG_BIAS_HIGH_IMPEDANCE
:
389 case PIN_CONFIG_INPUT_ENABLE
:
392 case PIN_CONFIG_OUTPUT
:
394 pin
->output_value
= !!arg
;
396 case PIN_CONFIG_POWER_SOURCE
:
397 pin
->power_source
= arg
;
399 case PIN_CONFIG_DRIVE_STRENGTH
:
400 pin
->drive_strength
= arg
;
402 case PM8XXX_CONFIG_DTEST_SELECTOR
:
405 case PM8XXX_CONFIG_AMUX
:
408 case PM8XXX_CONFIG_ALEVEL
:
409 pin
->aout_level
= arg
;
411 case PM8XXX_CONFIG_PAIRED
:
416 "unsupported config parameter: %x\n",
422 pm8xxx_mpp_update(pctrl
, pin
);
427 static const struct pinconf_ops pm8xxx_pinconf_ops
= {
429 .pin_config_group_get
= pm8xxx_pin_config_get
,
430 .pin_config_group_set
= pm8xxx_pin_config_set
,
433 static const struct pinctrl_desc pm8xxx_pinctrl_desc
= {
434 .name
= "pm8xxx_mpp",
435 .pctlops
= &pm8xxx_pinctrl_ops
,
436 .pmxops
= &pm8xxx_pinmux_ops
,
437 .confops
= &pm8xxx_pinconf_ops
,
438 .owner
= THIS_MODULE
,
441 static int pm8xxx_mpp_direction_input(struct gpio_chip
*chip
,
444 struct pm8xxx_mpp
*pctrl
= gpiochip_get_data(chip
);
445 struct pm8xxx_pin_data
*pin
= pctrl
->desc
.pins
[offset
].drv_data
;
448 case PM8XXX_MPP_DIGITAL
:
451 case PM8XXX_MPP_ANALOG
:
455 case PM8XXX_MPP_SINK
:
459 pm8xxx_mpp_update(pctrl
, pin
);
464 static int pm8xxx_mpp_direction_output(struct gpio_chip
*chip
,
468 struct pm8xxx_mpp
*pctrl
= gpiochip_get_data(chip
);
469 struct pm8xxx_pin_data
*pin
= pctrl
->desc
.pins
[offset
].drv_data
;
472 case PM8XXX_MPP_DIGITAL
:
475 case PM8XXX_MPP_ANALOG
:
479 case PM8XXX_MPP_SINK
:
485 pm8xxx_mpp_update(pctrl
, pin
);
490 static int pm8xxx_mpp_get(struct gpio_chip
*chip
, unsigned offset
)
492 struct pm8xxx_mpp
*pctrl
= gpiochip_get_data(chip
);
493 struct pm8xxx_pin_data
*pin
= pctrl
->desc
.pins
[offset
].drv_data
;
498 return !!pin
->output_value
;
500 ret
= irq_get_irqchip_state(pin
->irq
, IRQCHIP_STATE_LINE_LEVEL
, &state
);
507 static void pm8xxx_mpp_set(struct gpio_chip
*chip
, unsigned offset
, int value
)
509 struct pm8xxx_mpp
*pctrl
= gpiochip_get_data(chip
);
510 struct pm8xxx_pin_data
*pin
= pctrl
->desc
.pins
[offset
].drv_data
;
512 pin
->output_value
= !!value
;
514 pm8xxx_mpp_update(pctrl
, pin
);
517 static int pm8xxx_mpp_of_xlate(struct gpio_chip
*chip
,
518 const struct of_phandle_args
*gpio_desc
,
521 if (chip
->of_gpio_n_cells
< 2)
525 *flags
= gpio_desc
->args
[1];
527 return gpio_desc
->args
[0] - 1;
531 static int pm8xxx_mpp_to_irq(struct gpio_chip
*chip
, unsigned offset
)
533 struct pm8xxx_mpp
*pctrl
= gpiochip_get_data(chip
);
534 struct pm8xxx_pin_data
*pin
= pctrl
->desc
.pins
[offset
].drv_data
;
539 #ifdef CONFIG_DEBUG_FS
540 #include <linux/seq_file.h>
542 static void pm8xxx_mpp_dbg_show_one(struct seq_file
*s
,
543 struct pinctrl_dev
*pctldev
,
544 struct gpio_chip
*chip
,
548 struct pm8xxx_mpp
*pctrl
= gpiochip_get_data(chip
);
549 struct pm8xxx_pin_data
*pin
= pctrl
->desc
.pins
[offset
].drv_data
;
551 static const char * const aout_lvls
[] = {
552 "1v25", "1v25_2", "0v625", "0v3125", "mpp", "abus1", "abus2",
556 static const char * const amuxs
[] = {
557 "amux5", "amux6", "amux7", "amux8", "amux9", "abus1", "abus2",
561 seq_printf(s
, " mpp%-2d:", offset
+ 1);
564 case PM8XXX_MPP_DIGITAL
:
565 seq_puts(s
, " digital ");
567 seq_printf(s
, "dtest%d\n", pin
->dtest
);
568 } else if (pin
->input
&& pin
->output
) {
570 seq_puts(s
, "bi-dir high-z");
572 seq_printf(s
, "bi-dir %dOhm", pin
->pullup
);
573 } else if (pin
->input
) {
575 seq_printf(s
, "in dtest%d", pin
->dtest
);
577 seq_puts(s
, "in gpio");
578 } else if (pin
->output
) {
582 seq_puts(s
, pin
->output_value
?
585 seq_puts(s
, pin
->output_value
?
586 "inverted" : "follow");
590 case PM8XXX_MPP_ANALOG
:
591 seq_puts(s
, " analog ");
593 seq_printf(s
, "out %s ", aout_lvls
[pin
->aout_level
]);
595 seq_puts(s
, pin
->output_value
?
598 seq_puts(s
, pin
->output_value
?
599 "inverted" : "follow");
602 seq_printf(s
, "input mux %s", amuxs
[pin
->amux
]);
605 case PM8XXX_MPP_SINK
:
606 seq_printf(s
, " sink %dmA ", pin
->drive_strength
);
608 seq_printf(s
, "dtest%d", pin
->dtest
);
611 seq_puts(s
, pin
->output_value
?
614 seq_puts(s
, pin
->output_value
?
615 "inverted" : "follow");
623 static void pm8xxx_mpp_dbg_show(struct seq_file
*s
, struct gpio_chip
*chip
)
625 unsigned gpio
= chip
->base
;
628 for (i
= 0; i
< chip
->ngpio
; i
++, gpio
++) {
629 pm8xxx_mpp_dbg_show_one(s
, NULL
, chip
, i
, gpio
);
635 #define pm8xxx_mpp_dbg_show NULL
638 static const struct gpio_chip pm8xxx_mpp_template
= {
639 .direction_input
= pm8xxx_mpp_direction_input
,
640 .direction_output
= pm8xxx_mpp_direction_output
,
641 .get
= pm8xxx_mpp_get
,
642 .set
= pm8xxx_mpp_set
,
643 .of_xlate
= pm8xxx_mpp_of_xlate
,
644 .to_irq
= pm8xxx_mpp_to_irq
,
645 .dbg_show
= pm8xxx_mpp_dbg_show
,
646 .owner
= THIS_MODULE
,
649 static int pm8xxx_pin_populate(struct pm8xxx_mpp
*pctrl
,
650 struct pm8xxx_pin_data
*pin
)
658 ret
= regmap_read(pctrl
->regmap
, pin
->reg
, &val
);
660 dev_err(pctrl
->dev
, "failed to read register\n");
664 type
= (val
>> 5) & 7;
665 level
= (val
>> 2) & 7;
669 case PM8XXX_MPP_TYPE_D_INPUT
:
670 pin
->mode
= PM8XXX_MPP_DIGITAL
;
672 pin
->power_source
= level
;
675 case PM8XXX_MPP_TYPE_D_OUTPUT
:
676 pin
->mode
= PM8XXX_MPP_DIGITAL
;
678 pin
->power_source
= level
;
679 pin
->output_value
= !!(ctrl
& BIT(0));
680 pin
->paired
= !!(ctrl
& BIT(1));
682 case PM8XXX_MPP_TYPE_D_BI_DIR
:
683 pin
->mode
= PM8XXX_MPP_DIGITAL
;
686 pin
->power_source
= level
;
688 case PM8XXX_MPP_BI_PULLUP_1KOHM
:
691 case PM8XXX_MPP_BI_PULLUP_OPEN
:
694 case PM8XXX_MPP_BI_PULLUP_10KOHM
:
697 case PM8XXX_MPP_BI_PULLUP_30KOHM
:
702 case PM8XXX_MPP_TYPE_A_INPUT
:
703 pin
->mode
= PM8XXX_MPP_ANALOG
;
707 case PM8XXX_MPP_TYPE_A_OUTPUT
:
708 pin
->mode
= PM8XXX_MPP_ANALOG
;
710 pin
->aout_level
= level
;
711 pin
->output_value
= !!(ctrl
& BIT(0));
712 pin
->paired
= !!(ctrl
& BIT(1));
714 case PM8XXX_MPP_TYPE_SINK
:
715 pin
->mode
= PM8XXX_MPP_SINK
;
716 pin
->drive_strength
= 5 * (level
+ 1);
717 pin
->output_value
= !!(ctrl
& BIT(0));
718 pin
->paired
= !!(ctrl
& BIT(1));
720 case PM8XXX_MPP_TYPE_DTEST_SINK
:
721 pin
->mode
= PM8XXX_MPP_SINK
;
722 pin
->dtest
= ctrl
+ 1;
723 pin
->drive_strength
= 5 * (level
+ 1);
725 case PM8XXX_MPP_TYPE_DTEST_OUTPUT
:
726 pin
->mode
= PM8XXX_MPP_DIGITAL
;
727 pin
->power_source
= level
;
736 static const struct of_device_id pm8xxx_mpp_of_match
[] = {
737 { .compatible
= "qcom,pm8018-mpp" },
738 { .compatible
= "qcom,pm8038-mpp" },
739 { .compatible
= "qcom,pm8058-mpp" },
740 { .compatible
= "qcom,pm8917-mpp" },
741 { .compatible
= "qcom,pm8821-mpp" },
742 { .compatible
= "qcom,pm8921-mpp" },
743 { .compatible
= "qcom,ssbi-mpp" },
746 MODULE_DEVICE_TABLE(of
, pm8xxx_mpp_of_match
);
748 static int pm8xxx_mpp_probe(struct platform_device
*pdev
)
750 struct pm8xxx_pin_data
*pin_data
;
751 struct pinctrl_pin_desc
*pins
;
752 struct pm8xxx_mpp
*pctrl
;
756 pctrl
= devm_kzalloc(&pdev
->dev
, sizeof(*pctrl
), GFP_KERNEL
);
760 pctrl
->dev
= &pdev
->dev
;
761 npins
= platform_irq_count(pdev
);
766 pctrl
->npins
= npins
;
768 pctrl
->regmap
= dev_get_regmap(pdev
->dev
.parent
, NULL
);
769 if (!pctrl
->regmap
) {
770 dev_err(&pdev
->dev
, "parent regmap unavailable\n");
774 pctrl
->desc
= pm8xxx_pinctrl_desc
;
775 pctrl
->desc
.npins
= pctrl
->npins
;
777 pins
= devm_kcalloc(&pdev
->dev
,
779 sizeof(struct pinctrl_pin_desc
),
784 pin_data
= devm_kcalloc(&pdev
->dev
,
786 sizeof(struct pm8xxx_pin_data
),
791 for (i
= 0; i
< pctrl
->desc
.npins
; i
++) {
792 pin_data
[i
].reg
= SSBI_REG_ADDR_MPP(i
);
793 pin_data
[i
].irq
= platform_get_irq(pdev
, i
);
794 if (pin_data
[i
].irq
< 0)
795 return pin_data
[i
].irq
;
797 ret
= pm8xxx_pin_populate(pctrl
, &pin_data
[i
]);
802 pins
[i
].name
= pm8xxx_groups
[i
];
803 pins
[i
].drv_data
= &pin_data
[i
];
805 pctrl
->desc
.pins
= pins
;
807 pctrl
->desc
.num_custom_params
= ARRAY_SIZE(pm8xxx_mpp_bindings
);
808 pctrl
->desc
.custom_params
= pm8xxx_mpp_bindings
;
809 #ifdef CONFIG_DEBUG_FS
810 pctrl
->desc
.custom_conf_items
= pm8xxx_conf_items
;
813 pctrl
->pctrl
= devm_pinctrl_register(&pdev
->dev
, &pctrl
->desc
, pctrl
);
814 if (IS_ERR(pctrl
->pctrl
)) {
815 dev_err(&pdev
->dev
, "couldn't register pm8xxx mpp driver\n");
816 return PTR_ERR(pctrl
->pctrl
);
819 pctrl
->chip
= pm8xxx_mpp_template
;
820 pctrl
->chip
.base
= -1;
821 pctrl
->chip
.parent
= &pdev
->dev
;
822 pctrl
->chip
.of_node
= pdev
->dev
.of_node
;
823 pctrl
->chip
.of_gpio_n_cells
= 2;
824 pctrl
->chip
.label
= dev_name(pctrl
->dev
);
825 pctrl
->chip
.ngpio
= pctrl
->npins
;
826 ret
= gpiochip_add_data(&pctrl
->chip
, pctrl
);
828 dev_err(&pdev
->dev
, "failed register gpiochip\n");
832 ret
= gpiochip_add_pin_range(&pctrl
->chip
,
833 dev_name(pctrl
->dev
),
834 0, 0, pctrl
->chip
.ngpio
);
836 dev_err(pctrl
->dev
, "failed to add pin range\n");
837 goto unregister_gpiochip
;
840 platform_set_drvdata(pdev
, pctrl
);
842 dev_dbg(&pdev
->dev
, "Qualcomm pm8xxx mpp driver probed\n");
847 gpiochip_remove(&pctrl
->chip
);
852 static int pm8xxx_mpp_remove(struct platform_device
*pdev
)
854 struct pm8xxx_mpp
*pctrl
= platform_get_drvdata(pdev
);
856 gpiochip_remove(&pctrl
->chip
);
861 static struct platform_driver pm8xxx_mpp_driver
= {
863 .name
= "qcom-ssbi-mpp",
864 .of_match_table
= pm8xxx_mpp_of_match
,
866 .probe
= pm8xxx_mpp_probe
,
867 .remove
= pm8xxx_mpp_remove
,
870 module_platform_driver(pm8xxx_mpp_driver
);
872 MODULE_AUTHOR("Bjorn Andersson <bjorn.andersson@sonymobile.com>");
873 MODULE_DESCRIPTION("Qualcomm PM8xxx MPP driver");
874 MODULE_LICENSE("GPL v2");