2 * Copyright (c) 2015, Sony Mobile Communications AB.
3 * Copyright (c) 2013, The Linux Foundation. All rights reserved.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 and
7 * only version 2 as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
15 #include <linux/module.h>
16 #include <linux/platform_device.h>
17 #include <linux/pinctrl/pinctrl.h>
18 #include <linux/pinctrl/pinmux.h>
19 #include <linux/pinctrl/pinconf.h>
20 #include <linux/pinctrl/pinconf-generic.h>
21 #include <linux/slab.h>
22 #include <linux/regmap.h>
23 #include <linux/gpio.h>
24 #include <linux/interrupt.h>
25 #include <linux/of_device.h>
26 #include <linux/of_irq.h>
28 #include <dt-bindings/pinctrl/qcom,pmic-mpp.h>
31 #include "../pinctrl-utils.h"
34 #define SSBI_REG_ADDR_MPP_BASE 0x50
35 #define SSBI_REG_ADDR_MPP(n) (SSBI_REG_ADDR_MPP_BASE + n)
38 #define PM8XXX_MPP_TYPE_D_INPUT 0
39 #define PM8XXX_MPP_TYPE_D_OUTPUT 1
40 #define PM8XXX_MPP_TYPE_D_BI_DIR 2
41 #define PM8XXX_MPP_TYPE_A_INPUT 3
42 #define PM8XXX_MPP_TYPE_A_OUTPUT 4
43 #define PM8XXX_MPP_TYPE_SINK 5
44 #define PM8XXX_MPP_TYPE_DTEST_SINK 6
45 #define PM8XXX_MPP_TYPE_DTEST_OUTPUT 7
47 /* Digital Input: control */
48 #define PM8XXX_MPP_DIN_TO_INT 0
49 #define PM8XXX_MPP_DIN_TO_DBUS1 1
50 #define PM8XXX_MPP_DIN_TO_DBUS2 2
51 #define PM8XXX_MPP_DIN_TO_DBUS3 3
53 /* Digital Output: control */
54 #define PM8XXX_MPP_DOUT_CTRL_LOW 0
55 #define PM8XXX_MPP_DOUT_CTRL_HIGH 1
56 #define PM8XXX_MPP_DOUT_CTRL_MPP 2
57 #define PM8XXX_MPP_DOUT_CTRL_INV_MPP 3
59 /* Bidirectional: control */
60 #define PM8XXX_MPP_BI_PULLUP_1KOHM 0
61 #define PM8XXX_MPP_BI_PULLUP_OPEN 1
62 #define PM8XXX_MPP_BI_PULLUP_10KOHM 2
63 #define PM8XXX_MPP_BI_PULLUP_30KOHM 3
65 /* Analog Output: control */
66 #define PM8XXX_MPP_AOUT_CTRL_DISABLE 0
67 #define PM8XXX_MPP_AOUT_CTRL_ENABLE 1
68 #define PM8XXX_MPP_AOUT_CTRL_MPP_HIGH_EN 2
69 #define PM8XXX_MPP_AOUT_CTRL_MPP_LOW_EN 3
71 /* Current Sink: control */
72 #define PM8XXX_MPP_CS_CTRL_DISABLE 0
73 #define PM8XXX_MPP_CS_CTRL_ENABLE 1
74 #define PM8XXX_MPP_CS_CTRL_MPP_HIGH_EN 2
75 #define PM8XXX_MPP_CS_CTRL_MPP_LOW_EN 3
77 /* DTEST Current Sink: control */
78 #define PM8XXX_MPP_DTEST_CS_CTRL_EN1 0
79 #define PM8XXX_MPP_DTEST_CS_CTRL_EN2 1
80 #define PM8XXX_MPP_DTEST_CS_CTRL_EN3 2
81 #define PM8XXX_MPP_DTEST_CS_CTRL_EN4 3
83 /* DTEST Digital Output: control */
84 #define PM8XXX_MPP_DTEST_DBUS1 0
85 #define PM8XXX_MPP_DTEST_DBUS2 1
86 #define PM8XXX_MPP_DTEST_DBUS3 2
87 #define PM8XXX_MPP_DTEST_DBUS4 3
89 /* custom pinconf parameters */
90 #define PM8XXX_CONFIG_AMUX (PIN_CONFIG_END + 1)
91 #define PM8XXX_CONFIG_DTEST_SELECTOR (PIN_CONFIG_END + 2)
92 #define PM8XXX_CONFIG_ALEVEL (PIN_CONFIG_END + 3)
93 #define PM8XXX_CONFIG_PAIRED (PIN_CONFIG_END + 4)
96 * struct pm8xxx_pin_data - dynamic configuration for a pin
97 * @reg: address of the control register
98 * @irq: IRQ from the PMIC interrupt controller
99 * @mode: operating mode for the pin (digital, analog or current sink)
100 * @input: pin is input
101 * @output: pin is output
102 * @high_z: pin is floating
103 * @paired: mpp operates in paired mode
104 * @output_value: logical output value of the mpp
105 * @power_source: selected power source
106 * @dtest: DTEST route selector
107 * @amux: input muxing in analog mode
108 * @aout_level: selector of the output in analog mode
109 * @drive_strength: drive strength of the current sink
110 * @pullup: pull up value, when in digital bidirectional mode
112 struct pm8xxx_pin_data
{
134 struct regmap
*regmap
;
135 struct pinctrl_dev
*pctrl
;
136 struct gpio_chip chip
;
138 struct pinctrl_desc desc
;
142 static const struct pinconf_generic_params pm8xxx_mpp_bindings
[] = {
143 {"qcom,amux-route", PM8XXX_CONFIG_AMUX
, 0},
144 {"qcom,analog-level", PM8XXX_CONFIG_ALEVEL
, 0},
145 {"qcom,dtest", PM8XXX_CONFIG_DTEST_SELECTOR
, 0},
146 {"qcom,paired", PM8XXX_CONFIG_PAIRED
, 0},
149 #ifdef CONFIG_DEBUG_FS
150 static const struct pin_config_item pm8xxx_conf_items
[] = {
151 PCONFDUMP(PM8XXX_CONFIG_AMUX
, "analog mux", NULL
, true),
152 PCONFDUMP(PM8XXX_CONFIG_ALEVEL
, "analog level", NULL
, true),
153 PCONFDUMP(PM8XXX_CONFIG_DTEST_SELECTOR
, "dtest", NULL
, true),
154 PCONFDUMP(PM8XXX_CONFIG_PAIRED
, "paired", NULL
, false),
158 #define PM8XXX_MAX_MPPS 12
159 static const char * const pm8xxx_groups
[PM8XXX_MAX_MPPS
] = {
160 "mpp1", "mpp2", "mpp3", "mpp4", "mpp5", "mpp6", "mpp7", "mpp8",
161 "mpp9", "mpp10", "mpp11", "mpp12",
164 #define PM8XXX_MPP_DIGITAL 0
165 #define PM8XXX_MPP_ANALOG 1
166 #define PM8XXX_MPP_SINK 2
168 static const char * const pm8xxx_mpp_functions
[] = {
169 "digital", "analog", "sink",
172 static int pm8xxx_mpp_update(struct pm8xxx_mpp
*pctrl
,
173 struct pm8xxx_pin_data
*pin
)
182 case PM8XXX_MPP_DIGITAL
:
184 type
= PM8XXX_MPP_TYPE_DTEST_OUTPUT
;
185 ctrl
= pin
->dtest
- 1;
186 } else if (pin
->input
&& pin
->output
) {
187 type
= PM8XXX_MPP_TYPE_D_BI_DIR
;
189 ctrl
= PM8XXX_MPP_BI_PULLUP_OPEN
;
190 else if (pin
->pullup
== 600)
191 ctrl
= PM8XXX_MPP_BI_PULLUP_1KOHM
;
192 else if (pin
->pullup
== 10000)
193 ctrl
= PM8XXX_MPP_BI_PULLUP_10KOHM
;
195 ctrl
= PM8XXX_MPP_BI_PULLUP_30KOHM
;
196 } else if (pin
->input
) {
197 type
= PM8XXX_MPP_TYPE_D_INPUT
;
201 ctrl
= PM8XXX_MPP_DIN_TO_INT
;
203 type
= PM8XXX_MPP_TYPE_D_OUTPUT
;
204 ctrl
= !!pin
->output_value
;
209 level
= pin
->power_source
;
211 case PM8XXX_MPP_ANALOG
:
213 type
= PM8XXX_MPP_TYPE_A_OUTPUT
;
214 level
= pin
->aout_level
;
215 ctrl
= pin
->output_value
;
219 type
= PM8XXX_MPP_TYPE_A_INPUT
;
224 case PM8XXX_MPP_SINK
:
225 level
= (pin
->drive_strength
/ 5) - 1;
227 type
= PM8XXX_MPP_TYPE_DTEST_SINK
;
228 ctrl
= pin
->dtest
- 1;
230 type
= PM8XXX_MPP_TYPE_SINK
;
231 ctrl
= pin
->output_value
;
240 val
= type
<< 5 | level
<< 2 | ctrl
;
241 ret
= regmap_write(pctrl
->regmap
, pin
->reg
, val
);
243 dev_err(pctrl
->dev
, "failed to write register\n");
248 static int pm8xxx_get_groups_count(struct pinctrl_dev
*pctldev
)
250 struct pm8xxx_mpp
*pctrl
= pinctrl_dev_get_drvdata(pctldev
);
255 static const char *pm8xxx_get_group_name(struct pinctrl_dev
*pctldev
,
258 return pm8xxx_groups
[group
];
262 static int pm8xxx_get_group_pins(struct pinctrl_dev
*pctldev
,
264 const unsigned **pins
,
267 struct pm8xxx_mpp
*pctrl
= pinctrl_dev_get_drvdata(pctldev
);
269 *pins
= &pctrl
->desc
.pins
[group
].number
;
275 static const struct pinctrl_ops pm8xxx_pinctrl_ops
= {
276 .get_groups_count
= pm8xxx_get_groups_count
,
277 .get_group_name
= pm8xxx_get_group_name
,
278 .get_group_pins
= pm8xxx_get_group_pins
,
279 .dt_node_to_map
= pinconf_generic_dt_node_to_map_group
,
280 .dt_free_map
= pinctrl_utils_free_map
,
283 static int pm8xxx_get_functions_count(struct pinctrl_dev
*pctldev
)
285 return ARRAY_SIZE(pm8xxx_mpp_functions
);
288 static const char *pm8xxx_get_function_name(struct pinctrl_dev
*pctldev
,
291 return pm8xxx_mpp_functions
[function
];
294 static int pm8xxx_get_function_groups(struct pinctrl_dev
*pctldev
,
296 const char * const **groups
,
297 unsigned * const num_groups
)
299 struct pm8xxx_mpp
*pctrl
= pinctrl_dev_get_drvdata(pctldev
);
301 *groups
= pm8xxx_groups
;
302 *num_groups
= pctrl
->npins
;
306 static int pm8xxx_pinmux_set_mux(struct pinctrl_dev
*pctldev
,
310 struct pm8xxx_mpp
*pctrl
= pinctrl_dev_get_drvdata(pctldev
);
311 struct pm8xxx_pin_data
*pin
= pctrl
->desc
.pins
[group
].drv_data
;
313 pin
->mode
= function
;
314 pm8xxx_mpp_update(pctrl
, pin
);
319 static const struct pinmux_ops pm8xxx_pinmux_ops
= {
320 .get_functions_count
= pm8xxx_get_functions_count
,
321 .get_function_name
= pm8xxx_get_function_name
,
322 .get_function_groups
= pm8xxx_get_function_groups
,
323 .set_mux
= pm8xxx_pinmux_set_mux
,
326 static int pm8xxx_pin_config_get(struct pinctrl_dev
*pctldev
,
328 unsigned long *config
)
330 struct pm8xxx_mpp
*pctrl
= pinctrl_dev_get_drvdata(pctldev
);
331 struct pm8xxx_pin_data
*pin
= pctrl
->desc
.pins
[offset
].drv_data
;
332 unsigned param
= pinconf_to_config_param(*config
);
336 case PIN_CONFIG_BIAS_PULL_UP
:
339 case PIN_CONFIG_BIAS_HIGH_IMPEDANCE
:
342 case PIN_CONFIG_INPUT_ENABLE
:
345 case PIN_CONFIG_OUTPUT
:
346 arg
= pin
->output_value
;
348 case PIN_CONFIG_POWER_SOURCE
:
349 arg
= pin
->power_source
;
351 case PIN_CONFIG_DRIVE_STRENGTH
:
352 arg
= pin
->drive_strength
;
354 case PM8XXX_CONFIG_DTEST_SELECTOR
:
357 case PM8XXX_CONFIG_AMUX
:
360 case PM8XXX_CONFIG_ALEVEL
:
361 arg
= pin
->aout_level
;
363 case PM8XXX_CONFIG_PAIRED
:
370 *config
= pinconf_to_config_packed(param
, arg
);
375 static int pm8xxx_pin_config_set(struct pinctrl_dev
*pctldev
,
377 unsigned long *configs
,
378 unsigned num_configs
)
380 struct pm8xxx_mpp
*pctrl
= pinctrl_dev_get_drvdata(pctldev
);
381 struct pm8xxx_pin_data
*pin
= pctrl
->desc
.pins
[offset
].drv_data
;
386 for (i
= 0; i
< num_configs
; i
++) {
387 param
= pinconf_to_config_param(configs
[i
]);
388 arg
= pinconf_to_config_argument(configs
[i
]);
391 case PIN_CONFIG_BIAS_PULL_UP
:
394 case PIN_CONFIG_BIAS_HIGH_IMPEDANCE
:
397 case PIN_CONFIG_INPUT_ENABLE
:
400 case PIN_CONFIG_OUTPUT
:
402 pin
->output_value
= !!arg
;
404 case PIN_CONFIG_POWER_SOURCE
:
405 pin
->power_source
= arg
;
407 case PIN_CONFIG_DRIVE_STRENGTH
:
408 pin
->drive_strength
= arg
;
410 case PM8XXX_CONFIG_DTEST_SELECTOR
:
413 case PM8XXX_CONFIG_AMUX
:
416 case PM8XXX_CONFIG_ALEVEL
:
417 pin
->aout_level
= arg
;
419 case PM8XXX_CONFIG_PAIRED
:
424 "unsupported config parameter: %x\n",
430 pm8xxx_mpp_update(pctrl
, pin
);
435 static const struct pinconf_ops pm8xxx_pinconf_ops
= {
437 .pin_config_group_get
= pm8xxx_pin_config_get
,
438 .pin_config_group_set
= pm8xxx_pin_config_set
,
441 static struct pinctrl_desc pm8xxx_pinctrl_desc
= {
442 .name
= "pm8xxx_mpp",
443 .pctlops
= &pm8xxx_pinctrl_ops
,
444 .pmxops
= &pm8xxx_pinmux_ops
,
445 .confops
= &pm8xxx_pinconf_ops
,
446 .owner
= THIS_MODULE
,
449 static int pm8xxx_mpp_direction_input(struct gpio_chip
*chip
,
452 struct pm8xxx_mpp
*pctrl
= gpiochip_get_data(chip
);
453 struct pm8xxx_pin_data
*pin
= pctrl
->desc
.pins
[offset
].drv_data
;
456 case PM8XXX_MPP_DIGITAL
:
459 case PM8XXX_MPP_ANALOG
:
463 case PM8XXX_MPP_SINK
:
467 pm8xxx_mpp_update(pctrl
, pin
);
472 static int pm8xxx_mpp_direction_output(struct gpio_chip
*chip
,
476 struct pm8xxx_mpp
*pctrl
= gpiochip_get_data(chip
);
477 struct pm8xxx_pin_data
*pin
= pctrl
->desc
.pins
[offset
].drv_data
;
480 case PM8XXX_MPP_DIGITAL
:
483 case PM8XXX_MPP_ANALOG
:
487 case PM8XXX_MPP_SINK
:
493 pm8xxx_mpp_update(pctrl
, pin
);
498 static int pm8xxx_mpp_get(struct gpio_chip
*chip
, unsigned offset
)
500 struct pm8xxx_mpp
*pctrl
= gpiochip_get_data(chip
);
501 struct pm8xxx_pin_data
*pin
= pctrl
->desc
.pins
[offset
].drv_data
;
506 return !!pin
->output_value
;
508 ret
= irq_get_irqchip_state(pin
->irq
, IRQCHIP_STATE_LINE_LEVEL
, &state
);
515 static void pm8xxx_mpp_set(struct gpio_chip
*chip
, unsigned offset
, int value
)
517 struct pm8xxx_mpp
*pctrl
= gpiochip_get_data(chip
);
518 struct pm8xxx_pin_data
*pin
= pctrl
->desc
.pins
[offset
].drv_data
;
520 pin
->output_value
= !!value
;
522 pm8xxx_mpp_update(pctrl
, pin
);
525 static int pm8xxx_mpp_of_xlate(struct gpio_chip
*chip
,
526 const struct of_phandle_args
*gpio_desc
,
529 if (chip
->of_gpio_n_cells
< 2)
533 *flags
= gpio_desc
->args
[1];
535 return gpio_desc
->args
[0] - 1;
539 static int pm8xxx_mpp_to_irq(struct gpio_chip
*chip
, unsigned offset
)
541 struct pm8xxx_mpp
*pctrl
= gpiochip_get_data(chip
);
542 struct pm8xxx_pin_data
*pin
= pctrl
->desc
.pins
[offset
].drv_data
;
547 #ifdef CONFIG_DEBUG_FS
548 #include <linux/seq_file.h>
550 static void pm8xxx_mpp_dbg_show_one(struct seq_file
*s
,
551 struct pinctrl_dev
*pctldev
,
552 struct gpio_chip
*chip
,
556 struct pm8xxx_mpp
*pctrl
= gpiochip_get_data(chip
);
557 struct pm8xxx_pin_data
*pin
= pctrl
->desc
.pins
[offset
].drv_data
;
559 static const char * const aout_lvls
[] = {
560 "1v25", "1v25_2", "0v625", "0v3125", "mpp", "abus1", "abus2",
564 static const char * const amuxs
[] = {
565 "amux5", "amux6", "amux7", "amux8", "amux9", "abus1", "abus2",
569 seq_printf(s
, " mpp%-2d:", offset
+ 1);
572 case PM8XXX_MPP_DIGITAL
:
573 seq_puts(s
, " digital ");
575 seq_printf(s
, "dtest%d\n", pin
->dtest
);
576 } else if (pin
->input
&& pin
->output
) {
578 seq_puts(s
, "bi-dir high-z");
580 seq_printf(s
, "bi-dir %dOhm", pin
->pullup
);
581 } else if (pin
->input
) {
583 seq_printf(s
, "in dtest%d", pin
->dtest
);
585 seq_puts(s
, "in gpio");
586 } else if (pin
->output
) {
590 seq_puts(s
, pin
->output_value
?
593 seq_puts(s
, pin
->output_value
?
594 "inverted" : "follow");
598 case PM8XXX_MPP_ANALOG
:
599 seq_puts(s
, " analog ");
601 seq_printf(s
, "out %s ", aout_lvls
[pin
->aout_level
]);
603 seq_puts(s
, pin
->output_value
?
606 seq_puts(s
, pin
->output_value
?
607 "inverted" : "follow");
610 seq_printf(s
, "input mux %s", amuxs
[pin
->amux
]);
613 case PM8XXX_MPP_SINK
:
614 seq_printf(s
, " sink %dmA ", pin
->drive_strength
);
616 seq_printf(s
, "dtest%d", pin
->dtest
);
619 seq_puts(s
, pin
->output_value
?
622 seq_puts(s
, pin
->output_value
?
623 "inverted" : "follow");
631 static void pm8xxx_mpp_dbg_show(struct seq_file
*s
, struct gpio_chip
*chip
)
633 unsigned gpio
= chip
->base
;
636 for (i
= 0; i
< chip
->ngpio
; i
++, gpio
++) {
637 pm8xxx_mpp_dbg_show_one(s
, NULL
, chip
, i
, gpio
);
643 #define pm8xxx_mpp_dbg_show NULL
646 static struct gpio_chip pm8xxx_mpp_template
= {
647 .direction_input
= pm8xxx_mpp_direction_input
,
648 .direction_output
= pm8xxx_mpp_direction_output
,
649 .get
= pm8xxx_mpp_get
,
650 .set
= pm8xxx_mpp_set
,
651 .of_xlate
= pm8xxx_mpp_of_xlate
,
652 .to_irq
= pm8xxx_mpp_to_irq
,
653 .dbg_show
= pm8xxx_mpp_dbg_show
,
654 .owner
= THIS_MODULE
,
657 static int pm8xxx_pin_populate(struct pm8xxx_mpp
*pctrl
,
658 struct pm8xxx_pin_data
*pin
)
666 ret
= regmap_read(pctrl
->regmap
, pin
->reg
, &val
);
668 dev_err(pctrl
->dev
, "failed to read register\n");
672 type
= (val
>> 5) & 7;
673 level
= (val
>> 2) & 7;
677 case PM8XXX_MPP_TYPE_D_INPUT
:
678 pin
->mode
= PM8XXX_MPP_DIGITAL
;
680 pin
->power_source
= level
;
683 case PM8XXX_MPP_TYPE_D_OUTPUT
:
684 pin
->mode
= PM8XXX_MPP_DIGITAL
;
686 pin
->power_source
= level
;
687 pin
->output_value
= !!(ctrl
& BIT(0));
688 pin
->paired
= !!(ctrl
& BIT(1));
690 case PM8XXX_MPP_TYPE_D_BI_DIR
:
691 pin
->mode
= PM8XXX_MPP_DIGITAL
;
694 pin
->power_source
= level
;
696 case PM8XXX_MPP_BI_PULLUP_1KOHM
:
699 case PM8XXX_MPP_BI_PULLUP_OPEN
:
702 case PM8XXX_MPP_BI_PULLUP_10KOHM
:
705 case PM8XXX_MPP_BI_PULLUP_30KOHM
:
710 case PM8XXX_MPP_TYPE_A_INPUT
:
711 pin
->mode
= PM8XXX_MPP_ANALOG
;
715 case PM8XXX_MPP_TYPE_A_OUTPUT
:
716 pin
->mode
= PM8XXX_MPP_ANALOG
;
718 pin
->aout_level
= level
;
719 pin
->output_value
= !!(ctrl
& BIT(0));
720 pin
->paired
= !!(ctrl
& BIT(1));
722 case PM8XXX_MPP_TYPE_SINK
:
723 pin
->mode
= PM8XXX_MPP_SINK
;
724 pin
->drive_strength
= 5 * (level
+ 1);
725 pin
->output_value
= !!(ctrl
& BIT(0));
726 pin
->paired
= !!(ctrl
& BIT(1));
728 case PM8XXX_MPP_TYPE_DTEST_SINK
:
729 pin
->mode
= PM8XXX_MPP_SINK
;
730 pin
->dtest
= ctrl
+ 1;
731 pin
->drive_strength
= 5 * (level
+ 1);
733 case PM8XXX_MPP_TYPE_DTEST_OUTPUT
:
734 pin
->mode
= PM8XXX_MPP_DIGITAL
;
735 pin
->power_source
= level
;
744 static const struct of_device_id pm8xxx_mpp_of_match
[] = {
745 { .compatible
= "qcom,pm8018-mpp" },
746 { .compatible
= "qcom,pm8038-mpp" },
747 { .compatible
= "qcom,pm8058-mpp" },
748 { .compatible
= "qcom,pm8917-mpp" },
749 { .compatible
= "qcom,pm8821-mpp" },
750 { .compatible
= "qcom,pm8921-mpp" },
751 { .compatible
= "qcom,ssbi-mpp" },
754 MODULE_DEVICE_TABLE(of
, pm8xxx_mpp_of_match
);
756 static int pm8xxx_mpp_probe(struct platform_device
*pdev
)
758 struct pm8xxx_pin_data
*pin_data
;
759 struct pinctrl_pin_desc
*pins
;
760 struct pm8xxx_mpp
*pctrl
;
764 pctrl
= devm_kzalloc(&pdev
->dev
, sizeof(*pctrl
), GFP_KERNEL
);
768 pctrl
->dev
= &pdev
->dev
;
769 npins
= platform_irq_count(pdev
);
774 pctrl
->npins
= npins
;
776 pctrl
->regmap
= dev_get_regmap(pdev
->dev
.parent
, NULL
);
777 if (!pctrl
->regmap
) {
778 dev_err(&pdev
->dev
, "parent regmap unavailable\n");
782 pctrl
->desc
= pm8xxx_pinctrl_desc
;
783 pctrl
->desc
.npins
= pctrl
->npins
;
785 pins
= devm_kcalloc(&pdev
->dev
,
787 sizeof(struct pinctrl_pin_desc
),
792 pin_data
= devm_kcalloc(&pdev
->dev
,
794 sizeof(struct pm8xxx_pin_data
),
799 for (i
= 0; i
< pctrl
->desc
.npins
; i
++) {
800 pin_data
[i
].reg
= SSBI_REG_ADDR_MPP(i
);
801 pin_data
[i
].irq
= platform_get_irq(pdev
, i
);
802 if (pin_data
[i
].irq
< 0) {
804 "missing interrupts for pin %d\n", i
);
805 return pin_data
[i
].irq
;
808 ret
= pm8xxx_pin_populate(pctrl
, &pin_data
[i
]);
813 pins
[i
].name
= pm8xxx_groups
[i
];
814 pins
[i
].drv_data
= &pin_data
[i
];
816 pctrl
->desc
.pins
= pins
;
818 pctrl
->desc
.num_custom_params
= ARRAY_SIZE(pm8xxx_mpp_bindings
);
819 pctrl
->desc
.custom_params
= pm8xxx_mpp_bindings
;
820 #ifdef CONFIG_DEBUG_FS
821 pctrl
->desc
.custom_conf_items
= pm8xxx_conf_items
;
824 pctrl
->pctrl
= devm_pinctrl_register(&pdev
->dev
, &pctrl
->desc
, pctrl
);
825 if (IS_ERR(pctrl
->pctrl
)) {
826 dev_err(&pdev
->dev
, "couldn't register pm8xxx mpp driver\n");
827 return PTR_ERR(pctrl
->pctrl
);
830 pctrl
->chip
= pm8xxx_mpp_template
;
831 pctrl
->chip
.base
= -1;
832 pctrl
->chip
.parent
= &pdev
->dev
;
833 pctrl
->chip
.of_node
= pdev
->dev
.of_node
;
834 pctrl
->chip
.of_gpio_n_cells
= 2;
835 pctrl
->chip
.label
= dev_name(pctrl
->dev
);
836 pctrl
->chip
.ngpio
= pctrl
->npins
;
837 ret
= gpiochip_add_data(&pctrl
->chip
, pctrl
);
839 dev_err(&pdev
->dev
, "failed register gpiochip\n");
843 ret
= gpiochip_add_pin_range(&pctrl
->chip
,
844 dev_name(pctrl
->dev
),
845 0, 0, pctrl
->chip
.ngpio
);
847 dev_err(pctrl
->dev
, "failed to add pin range\n");
848 goto unregister_gpiochip
;
851 platform_set_drvdata(pdev
, pctrl
);
853 dev_dbg(&pdev
->dev
, "Qualcomm pm8xxx mpp driver probed\n");
858 gpiochip_remove(&pctrl
->chip
);
863 static int pm8xxx_mpp_remove(struct platform_device
*pdev
)
865 struct pm8xxx_mpp
*pctrl
= platform_get_drvdata(pdev
);
867 gpiochip_remove(&pctrl
->chip
);
872 static struct platform_driver pm8xxx_mpp_driver
= {
874 .name
= "qcom-ssbi-mpp",
875 .of_match_table
= pm8xxx_mpp_of_match
,
877 .probe
= pm8xxx_mpp_probe
,
878 .remove
= pm8xxx_mpp_remove
,
881 module_platform_driver(pm8xxx_mpp_driver
);
883 MODULE_AUTHOR("Bjorn Andersson <bjorn.andersson@sonymobile.com>");
884 MODULE_DESCRIPTION("Qualcomm PM8xxx MPP driver");
885 MODULE_LICENSE("GPL v2");