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/gpio/driver.h>
8 #include <linux/interrupt.h>
9 #include <linux/module.h>
11 #include <linux/of_irq.h>
12 #include <linux/platform_device.h>
13 #include <linux/regmap.h>
14 #include <linux/seq_file.h>
15 #include <linux/slab.h>
17 #include <linux/pinctrl/pinconf-generic.h>
18 #include <linux/pinctrl/pinconf.h>
19 #include <linux/pinctrl/pinctrl.h>
20 #include <linux/pinctrl/pinmux.h>
22 #include <dt-bindings/pinctrl/qcom,pmic-mpp.h>
25 #include "../pinctrl-utils.h"
28 #define SSBI_REG_ADDR_MPP_BASE 0x50
29 #define SSBI_REG_ADDR_MPP(n) (SSBI_REG_ADDR_MPP_BASE + n)
32 #define PM8XXX_MPP_TYPE_D_INPUT 0
33 #define PM8XXX_MPP_TYPE_D_OUTPUT 1
34 #define PM8XXX_MPP_TYPE_D_BI_DIR 2
35 #define PM8XXX_MPP_TYPE_A_INPUT 3
36 #define PM8XXX_MPP_TYPE_A_OUTPUT 4
37 #define PM8XXX_MPP_TYPE_SINK 5
38 #define PM8XXX_MPP_TYPE_DTEST_SINK 6
39 #define PM8XXX_MPP_TYPE_DTEST_OUTPUT 7
41 /* Digital Input: control */
42 #define PM8XXX_MPP_DIN_TO_INT 0
43 #define PM8XXX_MPP_DIN_TO_DBUS1 1
44 #define PM8XXX_MPP_DIN_TO_DBUS2 2
45 #define PM8XXX_MPP_DIN_TO_DBUS3 3
47 /* Digital Output: control */
48 #define PM8XXX_MPP_DOUT_CTRL_LOW 0
49 #define PM8XXX_MPP_DOUT_CTRL_HIGH 1
50 #define PM8XXX_MPP_DOUT_CTRL_MPP 2
51 #define PM8XXX_MPP_DOUT_CTRL_INV_MPP 3
53 /* Bidirectional: control */
54 #define PM8XXX_MPP_BI_PULLUP_1KOHM 0
55 #define PM8XXX_MPP_BI_PULLUP_OPEN 1
56 #define PM8XXX_MPP_BI_PULLUP_10KOHM 2
57 #define PM8XXX_MPP_BI_PULLUP_30KOHM 3
59 /* Analog Output: control */
60 #define PM8XXX_MPP_AOUT_CTRL_DISABLE 0
61 #define PM8XXX_MPP_AOUT_CTRL_ENABLE 1
62 #define PM8XXX_MPP_AOUT_CTRL_MPP_HIGH_EN 2
63 #define PM8XXX_MPP_AOUT_CTRL_MPP_LOW_EN 3
65 /* Current Sink: control */
66 #define PM8XXX_MPP_CS_CTRL_DISABLE 0
67 #define PM8XXX_MPP_CS_CTRL_ENABLE 1
68 #define PM8XXX_MPP_CS_CTRL_MPP_HIGH_EN 2
69 #define PM8XXX_MPP_CS_CTRL_MPP_LOW_EN 3
71 /* DTEST Current Sink: control */
72 #define PM8XXX_MPP_DTEST_CS_CTRL_EN1 0
73 #define PM8XXX_MPP_DTEST_CS_CTRL_EN2 1
74 #define PM8XXX_MPP_DTEST_CS_CTRL_EN3 2
75 #define PM8XXX_MPP_DTEST_CS_CTRL_EN4 3
77 /* DTEST Digital Output: control */
78 #define PM8XXX_MPP_DTEST_DBUS1 0
79 #define PM8XXX_MPP_DTEST_DBUS2 1
80 #define PM8XXX_MPP_DTEST_DBUS3 2
81 #define PM8XXX_MPP_DTEST_DBUS4 3
83 /* custom pinconf parameters */
84 #define PM8XXX_CONFIG_AMUX (PIN_CONFIG_END + 1)
85 #define PM8XXX_CONFIG_DTEST_SELECTOR (PIN_CONFIG_END + 2)
86 #define PM8XXX_CONFIG_ALEVEL (PIN_CONFIG_END + 3)
87 #define PM8XXX_CONFIG_PAIRED (PIN_CONFIG_END + 4)
90 * struct pm8xxx_pin_data - dynamic configuration for a pin
91 * @reg: address of the control register
92 * @mode: operating mode for the pin (digital, analog or current sink)
93 * @input: pin is input
94 * @output: pin is output
95 * @high_z: pin is floating
96 * @paired: mpp operates in paired mode
97 * @output_value: logical output value of the mpp
98 * @power_source: selected power source
99 * @dtest: DTEST route selector
100 * @amux: input muxing in analog mode
101 * @aout_level: selector of the output in analog mode
102 * @drive_strength: drive strength of the current sink
103 * @pullup: pull up value, when in digital bidirectional mode
105 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 #define PM8XXX_MPP_PHYSICAL_OFFSET 1
153 static const char * const pm8xxx_groups
[PM8XXX_MAX_MPPS
] = {
154 "mpp1", "mpp2", "mpp3", "mpp4", "mpp5", "mpp6", "mpp7", "mpp8",
155 "mpp9", "mpp10", "mpp11", "mpp12",
158 #define PM8XXX_MPP_DIGITAL 0
159 #define PM8XXX_MPP_ANALOG 1
160 #define PM8XXX_MPP_SINK 2
162 static const char * const pm8xxx_mpp_functions
[] = {
163 "digital", "analog", "sink",
166 static int pm8xxx_mpp_update(struct pm8xxx_mpp
*pctrl
,
167 struct pm8xxx_pin_data
*pin
)
176 case PM8XXX_MPP_DIGITAL
:
178 type
= PM8XXX_MPP_TYPE_DTEST_OUTPUT
;
179 ctrl
= pin
->dtest
- 1;
180 } else if (pin
->input
&& pin
->output
) {
181 type
= PM8XXX_MPP_TYPE_D_BI_DIR
;
183 ctrl
= PM8XXX_MPP_BI_PULLUP_OPEN
;
184 else if (pin
->pullup
== 600)
185 ctrl
= PM8XXX_MPP_BI_PULLUP_1KOHM
;
186 else if (pin
->pullup
== 10000)
187 ctrl
= PM8XXX_MPP_BI_PULLUP_10KOHM
;
189 ctrl
= PM8XXX_MPP_BI_PULLUP_30KOHM
;
190 } else if (pin
->input
) {
191 type
= PM8XXX_MPP_TYPE_D_INPUT
;
195 ctrl
= PM8XXX_MPP_DIN_TO_INT
;
197 type
= PM8XXX_MPP_TYPE_D_OUTPUT
;
198 ctrl
= !!pin
->output_value
;
203 level
= pin
->power_source
;
205 case PM8XXX_MPP_ANALOG
:
207 type
= PM8XXX_MPP_TYPE_A_OUTPUT
;
208 level
= pin
->aout_level
;
209 ctrl
= pin
->output_value
;
213 type
= PM8XXX_MPP_TYPE_A_INPUT
;
218 case PM8XXX_MPP_SINK
:
219 level
= (pin
->drive_strength
/ 5) - 1;
221 type
= PM8XXX_MPP_TYPE_DTEST_SINK
;
222 ctrl
= pin
->dtest
- 1;
224 type
= PM8XXX_MPP_TYPE_SINK
;
225 ctrl
= pin
->output_value
;
234 val
= type
<< 5 | level
<< 2 | ctrl
;
235 ret
= regmap_write(pctrl
->regmap
, pin
->reg
, val
);
237 dev_err(pctrl
->dev
, "failed to write register\n");
242 static int pm8xxx_get_groups_count(struct pinctrl_dev
*pctldev
)
244 struct pm8xxx_mpp
*pctrl
= pinctrl_dev_get_drvdata(pctldev
);
249 static const char *pm8xxx_get_group_name(struct pinctrl_dev
*pctldev
,
252 return pm8xxx_groups
[group
];
256 static int pm8xxx_get_group_pins(struct pinctrl_dev
*pctldev
,
258 const unsigned **pins
,
261 struct pm8xxx_mpp
*pctrl
= pinctrl_dev_get_drvdata(pctldev
);
263 *pins
= &pctrl
->desc
.pins
[group
].number
;
269 static const struct pinctrl_ops pm8xxx_pinctrl_ops
= {
270 .get_groups_count
= pm8xxx_get_groups_count
,
271 .get_group_name
= pm8xxx_get_group_name
,
272 .get_group_pins
= pm8xxx_get_group_pins
,
273 .dt_node_to_map
= pinconf_generic_dt_node_to_map_group
,
274 .dt_free_map
= pinctrl_utils_free_map
,
277 static int pm8xxx_get_functions_count(struct pinctrl_dev
*pctldev
)
279 return ARRAY_SIZE(pm8xxx_mpp_functions
);
282 static const char *pm8xxx_get_function_name(struct pinctrl_dev
*pctldev
,
285 return pm8xxx_mpp_functions
[function
];
288 static int pm8xxx_get_function_groups(struct pinctrl_dev
*pctldev
,
290 const char * const **groups
,
291 unsigned * const num_groups
)
293 struct pm8xxx_mpp
*pctrl
= pinctrl_dev_get_drvdata(pctldev
);
295 *groups
= pm8xxx_groups
;
296 *num_groups
= pctrl
->npins
;
300 static int pm8xxx_pinmux_set_mux(struct pinctrl_dev
*pctldev
,
304 struct pm8xxx_mpp
*pctrl
= pinctrl_dev_get_drvdata(pctldev
);
305 struct pm8xxx_pin_data
*pin
= pctrl
->desc
.pins
[group
].drv_data
;
307 pin
->mode
= function
;
308 pm8xxx_mpp_update(pctrl
, pin
);
313 static const struct pinmux_ops pm8xxx_pinmux_ops
= {
314 .get_functions_count
= pm8xxx_get_functions_count
,
315 .get_function_name
= pm8xxx_get_function_name
,
316 .get_function_groups
= pm8xxx_get_function_groups
,
317 .set_mux
= pm8xxx_pinmux_set_mux
,
320 static int pm8xxx_pin_config_get(struct pinctrl_dev
*pctldev
,
322 unsigned long *config
)
324 struct pm8xxx_mpp
*pctrl
= pinctrl_dev_get_drvdata(pctldev
);
325 struct pm8xxx_pin_data
*pin
= pctrl
->desc
.pins
[offset
].drv_data
;
326 unsigned param
= pinconf_to_config_param(*config
);
330 case PIN_CONFIG_BIAS_PULL_UP
:
333 case PIN_CONFIG_BIAS_HIGH_IMPEDANCE
:
336 case PIN_CONFIG_INPUT_ENABLE
:
339 case PIN_CONFIG_OUTPUT
:
340 arg
= pin
->output_value
;
342 case PIN_CONFIG_POWER_SOURCE
:
343 arg
= pin
->power_source
;
345 case PIN_CONFIG_DRIVE_STRENGTH
:
346 arg
= pin
->drive_strength
;
348 case PM8XXX_CONFIG_DTEST_SELECTOR
:
351 case PM8XXX_CONFIG_AMUX
:
354 case PM8XXX_CONFIG_ALEVEL
:
355 arg
= pin
->aout_level
;
357 case PM8XXX_CONFIG_PAIRED
:
364 *config
= pinconf_to_config_packed(param
, arg
);
369 static int pm8xxx_pin_config_set(struct pinctrl_dev
*pctldev
,
371 unsigned long *configs
,
372 unsigned num_configs
)
374 struct pm8xxx_mpp
*pctrl
= pinctrl_dev_get_drvdata(pctldev
);
375 struct pm8xxx_pin_data
*pin
= pctrl
->desc
.pins
[offset
].drv_data
;
380 for (i
= 0; i
< num_configs
; i
++) {
381 param
= pinconf_to_config_param(configs
[i
]);
382 arg
= pinconf_to_config_argument(configs
[i
]);
385 case PIN_CONFIG_BIAS_PULL_UP
:
388 case PIN_CONFIG_BIAS_HIGH_IMPEDANCE
:
391 case PIN_CONFIG_INPUT_ENABLE
:
394 case PIN_CONFIG_OUTPUT
:
396 pin
->output_value
= !!arg
;
398 case PIN_CONFIG_POWER_SOURCE
:
399 pin
->power_source
= arg
;
401 case PIN_CONFIG_DRIVE_STRENGTH
:
402 pin
->drive_strength
= arg
;
404 case PM8XXX_CONFIG_DTEST_SELECTOR
:
407 case PM8XXX_CONFIG_AMUX
:
410 case PM8XXX_CONFIG_ALEVEL
:
411 pin
->aout_level
= arg
;
413 case PM8XXX_CONFIG_PAIRED
:
418 "unsupported config parameter: %x\n",
424 pm8xxx_mpp_update(pctrl
, pin
);
429 static const struct pinconf_ops pm8xxx_pinconf_ops
= {
431 .pin_config_group_get
= pm8xxx_pin_config_get
,
432 .pin_config_group_set
= pm8xxx_pin_config_set
,
435 static const struct pinctrl_desc pm8xxx_pinctrl_desc
= {
436 .name
= "pm8xxx_mpp",
437 .pctlops
= &pm8xxx_pinctrl_ops
,
438 .pmxops
= &pm8xxx_pinmux_ops
,
439 .confops
= &pm8xxx_pinconf_ops
,
440 .owner
= THIS_MODULE
,
443 static int pm8xxx_mpp_direction_input(struct gpio_chip
*chip
,
446 struct pm8xxx_mpp
*pctrl
= gpiochip_get_data(chip
);
447 struct pm8xxx_pin_data
*pin
= pctrl
->desc
.pins
[offset
].drv_data
;
450 case PM8XXX_MPP_DIGITAL
:
453 case PM8XXX_MPP_ANALOG
:
457 case PM8XXX_MPP_SINK
:
461 pm8xxx_mpp_update(pctrl
, pin
);
466 static int pm8xxx_mpp_direction_output(struct gpio_chip
*chip
,
470 struct pm8xxx_mpp
*pctrl
= gpiochip_get_data(chip
);
471 struct pm8xxx_pin_data
*pin
= pctrl
->desc
.pins
[offset
].drv_data
;
474 case PM8XXX_MPP_DIGITAL
:
477 case PM8XXX_MPP_ANALOG
:
481 case PM8XXX_MPP_SINK
:
487 pm8xxx_mpp_update(pctrl
, pin
);
492 static int pm8xxx_mpp_get(struct gpio_chip
*chip
, unsigned offset
)
494 struct pm8xxx_mpp
*pctrl
= gpiochip_get_data(chip
);
495 struct pm8xxx_pin_data
*pin
= pctrl
->desc
.pins
[offset
].drv_data
;
500 return !!pin
->output_value
;
502 irq
= chip
->to_irq(chip
, offset
);
506 ret
= irq_get_irqchip_state(irq
, IRQCHIP_STATE_LINE_LEVEL
, &state
);
513 static void pm8xxx_mpp_set(struct gpio_chip
*chip
, unsigned offset
, int value
)
515 struct pm8xxx_mpp
*pctrl
= gpiochip_get_data(chip
);
516 struct pm8xxx_pin_data
*pin
= pctrl
->desc
.pins
[offset
].drv_data
;
518 pin
->output_value
= !!value
;
520 pm8xxx_mpp_update(pctrl
, pin
);
523 static int pm8xxx_mpp_of_xlate(struct gpio_chip
*chip
,
524 const struct of_phandle_args
*gpio_desc
,
527 if (chip
->of_gpio_n_cells
< 2)
531 *flags
= gpio_desc
->args
[1];
533 return gpio_desc
->args
[0] - PM8XXX_MPP_PHYSICAL_OFFSET
;
537 #ifdef CONFIG_DEBUG_FS
539 static void pm8xxx_mpp_dbg_show_one(struct seq_file
*s
,
540 struct pinctrl_dev
*pctldev
,
541 struct gpio_chip
*chip
,
545 struct pm8xxx_mpp
*pctrl
= gpiochip_get_data(chip
);
546 struct pm8xxx_pin_data
*pin
= pctrl
->desc
.pins
[offset
].drv_data
;
548 static const char * const aout_lvls
[] = {
549 "1v25", "1v25_2", "0v625", "0v3125", "mpp", "abus1", "abus2",
553 static const char * const amuxs
[] = {
554 "amux5", "amux6", "amux7", "amux8", "amux9", "abus1", "abus2",
558 seq_printf(s
, " mpp%-2d:", offset
+ PM8XXX_MPP_PHYSICAL_OFFSET
);
561 case PM8XXX_MPP_DIGITAL
:
562 seq_puts(s
, " digital ");
564 seq_printf(s
, "dtest%d\n", pin
->dtest
);
565 } else if (pin
->input
&& pin
->output
) {
567 seq_puts(s
, "bi-dir high-z");
569 seq_printf(s
, "bi-dir %dOhm", pin
->pullup
);
570 } else if (pin
->input
) {
572 seq_printf(s
, "in dtest%d", pin
->dtest
);
574 seq_puts(s
, "in gpio");
575 } else if (pin
->output
) {
579 seq_puts(s
, pin
->output_value
?
582 seq_puts(s
, pin
->output_value
?
583 "inverted" : "follow");
587 case PM8XXX_MPP_ANALOG
:
588 seq_puts(s
, " analog ");
590 seq_printf(s
, "out %s ", aout_lvls
[pin
->aout_level
]);
592 seq_puts(s
, pin
->output_value
?
595 seq_puts(s
, pin
->output_value
?
596 "inverted" : "follow");
599 seq_printf(s
, "input mux %s", amuxs
[pin
->amux
]);
602 case PM8XXX_MPP_SINK
:
603 seq_printf(s
, " sink %dmA ", pin
->drive_strength
);
605 seq_printf(s
, "dtest%d", pin
->dtest
);
608 seq_puts(s
, pin
->output_value
?
611 seq_puts(s
, pin
->output_value
?
612 "inverted" : "follow");
619 static void pm8xxx_mpp_dbg_show(struct seq_file
*s
, struct gpio_chip
*chip
)
621 unsigned gpio
= chip
->base
;
624 for (i
= 0; i
< chip
->ngpio
; i
++, gpio
++) {
625 pm8xxx_mpp_dbg_show_one(s
, NULL
, chip
, i
, gpio
);
631 #define pm8xxx_mpp_dbg_show NULL
634 static const struct gpio_chip pm8xxx_mpp_template
= {
635 .direction_input
= pm8xxx_mpp_direction_input
,
636 .direction_output
= pm8xxx_mpp_direction_output
,
637 .get
= pm8xxx_mpp_get
,
638 .set
= pm8xxx_mpp_set
,
639 .of_xlate
= pm8xxx_mpp_of_xlate
,
640 .dbg_show
= pm8xxx_mpp_dbg_show
,
641 .owner
= THIS_MODULE
,
644 static int pm8xxx_pin_populate(struct pm8xxx_mpp
*pctrl
,
645 struct pm8xxx_pin_data
*pin
)
653 ret
= regmap_read(pctrl
->regmap
, pin
->reg
, &val
);
655 dev_err(pctrl
->dev
, "failed to read register\n");
659 type
= (val
>> 5) & 7;
660 level
= (val
>> 2) & 7;
664 case PM8XXX_MPP_TYPE_D_INPUT
:
665 pin
->mode
= PM8XXX_MPP_DIGITAL
;
667 pin
->power_source
= level
;
670 case PM8XXX_MPP_TYPE_D_OUTPUT
:
671 pin
->mode
= PM8XXX_MPP_DIGITAL
;
673 pin
->power_source
= level
;
674 pin
->output_value
= !!(ctrl
& BIT(0));
675 pin
->paired
= !!(ctrl
& BIT(1));
677 case PM8XXX_MPP_TYPE_D_BI_DIR
:
678 pin
->mode
= PM8XXX_MPP_DIGITAL
;
681 pin
->power_source
= level
;
683 case PM8XXX_MPP_BI_PULLUP_1KOHM
:
686 case PM8XXX_MPP_BI_PULLUP_OPEN
:
689 case PM8XXX_MPP_BI_PULLUP_10KOHM
:
692 case PM8XXX_MPP_BI_PULLUP_30KOHM
:
697 case PM8XXX_MPP_TYPE_A_INPUT
:
698 pin
->mode
= PM8XXX_MPP_ANALOG
;
702 case PM8XXX_MPP_TYPE_A_OUTPUT
:
703 pin
->mode
= PM8XXX_MPP_ANALOG
;
705 pin
->aout_level
= level
;
706 pin
->output_value
= !!(ctrl
& BIT(0));
707 pin
->paired
= !!(ctrl
& BIT(1));
709 case PM8XXX_MPP_TYPE_SINK
:
710 pin
->mode
= PM8XXX_MPP_SINK
;
711 pin
->drive_strength
= 5 * (level
+ 1);
712 pin
->output_value
= !!(ctrl
& BIT(0));
713 pin
->paired
= !!(ctrl
& BIT(1));
715 case PM8XXX_MPP_TYPE_DTEST_SINK
:
716 pin
->mode
= PM8XXX_MPP_SINK
;
717 pin
->dtest
= ctrl
+ 1;
718 pin
->drive_strength
= 5 * (level
+ 1);
720 case PM8XXX_MPP_TYPE_DTEST_OUTPUT
:
721 pin
->mode
= PM8XXX_MPP_DIGITAL
;
722 pin
->power_source
= level
;
731 static int pm8xxx_mpp_domain_translate(struct irq_domain
*domain
,
732 struct irq_fwspec
*fwspec
,
733 unsigned long *hwirq
,
736 struct pm8xxx_mpp
*pctrl
= container_of(domain
->host_data
,
737 struct pm8xxx_mpp
, chip
);
739 if (fwspec
->param_count
!= 2 ||
740 fwspec
->param
[0] < PM8XXX_MPP_PHYSICAL_OFFSET
||
741 fwspec
->param
[0] > pctrl
->chip
.ngpio
)
744 *hwirq
= fwspec
->param
[0] - PM8XXX_MPP_PHYSICAL_OFFSET
;
745 *type
= fwspec
->param
[1];
750 static unsigned int pm8xxx_mpp_child_offset_to_irq(struct gpio_chip
*chip
,
753 return offset
+ PM8XXX_MPP_PHYSICAL_OFFSET
;
756 static int pm8821_mpp_child_to_parent_hwirq(struct gpio_chip
*chip
,
757 unsigned int child_hwirq
,
758 unsigned int child_type
,
759 unsigned int *parent_hwirq
,
760 unsigned int *parent_type
)
762 *parent_hwirq
= child_hwirq
+ 24;
763 *parent_type
= child_type
;
768 static int pm8xxx_mpp_child_to_parent_hwirq(struct gpio_chip
*chip
,
769 unsigned int child_hwirq
,
770 unsigned int child_type
,
771 unsigned int *parent_hwirq
,
772 unsigned int *parent_type
)
774 *parent_hwirq
= child_hwirq
+ 0x80;
775 *parent_type
= child_type
;
780 static void pm8xxx_mpp_irq_disable(struct irq_data
*d
)
782 struct gpio_chip
*gc
= irq_data_get_irq_chip_data(d
);
784 gpiochip_disable_irq(gc
, irqd_to_hwirq(d
));
787 static void pm8xxx_mpp_irq_enable(struct irq_data
*d
)
789 struct gpio_chip
*gc
= irq_data_get_irq_chip_data(d
);
791 gpiochip_enable_irq(gc
, irqd_to_hwirq(d
));
794 static const struct irq_chip pm8xxx_mpp_irq_chip
= {
796 .irq_mask_ack
= irq_chip_mask_ack_parent
,
797 .irq_unmask
= irq_chip_unmask_parent
,
798 .irq_disable
= pm8xxx_mpp_irq_disable
,
799 .irq_enable
= pm8xxx_mpp_irq_enable
,
800 .irq_set_type
= irq_chip_set_type_parent
,
801 .flags
= IRQCHIP_MASK_ON_SUSPEND
| IRQCHIP_SKIP_SET_WAKE
|
803 GPIOCHIP_IRQ_RESOURCE_HELPERS
,
806 static const struct of_device_id pm8xxx_mpp_of_match
[] = {
807 { .compatible
= "qcom,pm8018-mpp", .data
= (void *) 6 },
808 { .compatible
= "qcom,pm8038-mpp", .data
= (void *) 6 },
809 { .compatible
= "qcom,pm8058-mpp", .data
= (void *) 12 },
810 { .compatible
= "qcom,pm8821-mpp", .data
= (void *) 4 },
811 { .compatible
= "qcom,pm8917-mpp", .data
= (void *) 10 },
812 { .compatible
= "qcom,pm8921-mpp", .data
= (void *) 12 },
815 MODULE_DEVICE_TABLE(of
, pm8xxx_mpp_of_match
);
817 static int pm8xxx_mpp_probe(struct platform_device
*pdev
)
819 struct pm8xxx_pin_data
*pin_data
;
820 struct irq_domain
*parent_domain
;
821 struct device_node
*parent_node
;
822 struct pinctrl_pin_desc
*pins
;
823 struct gpio_irq_chip
*girq
;
824 struct pm8xxx_mpp
*pctrl
;
828 pctrl
= devm_kzalloc(&pdev
->dev
, sizeof(*pctrl
), GFP_KERNEL
);
832 pctrl
->dev
= &pdev
->dev
;
833 pctrl
->npins
= (uintptr_t) device_get_match_data(&pdev
->dev
);
835 pctrl
->regmap
= dev_get_regmap(pdev
->dev
.parent
, NULL
);
836 if (!pctrl
->regmap
) {
837 dev_err(&pdev
->dev
, "parent regmap unavailable\n");
841 pctrl
->desc
= pm8xxx_pinctrl_desc
;
842 pctrl
->desc
.npins
= pctrl
->npins
;
844 pins
= devm_kcalloc(&pdev
->dev
,
846 sizeof(struct pinctrl_pin_desc
),
851 pin_data
= devm_kcalloc(&pdev
->dev
,
853 sizeof(struct pm8xxx_pin_data
),
858 for (i
= 0; i
< pctrl
->desc
.npins
; i
++) {
859 pin_data
[i
].reg
= SSBI_REG_ADDR_MPP(i
);
861 ret
= pm8xxx_pin_populate(pctrl
, &pin_data
[i
]);
866 pins
[i
].name
= pm8xxx_groups
[i
];
867 pins
[i
].drv_data
= &pin_data
[i
];
869 pctrl
->desc
.pins
= pins
;
871 pctrl
->desc
.num_custom_params
= ARRAY_SIZE(pm8xxx_mpp_bindings
);
872 pctrl
->desc
.custom_params
= pm8xxx_mpp_bindings
;
873 #ifdef CONFIG_DEBUG_FS
874 pctrl
->desc
.custom_conf_items
= pm8xxx_conf_items
;
877 pctrl
->pctrl
= devm_pinctrl_register(&pdev
->dev
, &pctrl
->desc
, pctrl
);
878 if (IS_ERR(pctrl
->pctrl
)) {
879 dev_err(&pdev
->dev
, "couldn't register pm8xxx mpp driver\n");
880 return PTR_ERR(pctrl
->pctrl
);
883 pctrl
->chip
= pm8xxx_mpp_template
;
884 pctrl
->chip
.base
= -1;
885 pctrl
->chip
.parent
= &pdev
->dev
;
886 pctrl
->chip
.of_gpio_n_cells
= 2;
887 pctrl
->chip
.label
= dev_name(pctrl
->dev
);
888 pctrl
->chip
.ngpio
= pctrl
->npins
;
890 parent_node
= of_irq_find_parent(pctrl
->dev
->of_node
);
894 parent_domain
= irq_find_host(parent_node
);
895 of_node_put(parent_node
);
899 girq
= &pctrl
->chip
.irq
;
900 gpio_irq_chip_set_chip(girq
, &pm8xxx_mpp_irq_chip
);
901 girq
->default_type
= IRQ_TYPE_NONE
;
902 girq
->handler
= handle_level_irq
;
903 girq
->fwnode
= dev_fwnode(pctrl
->dev
);
904 girq
->parent_domain
= parent_domain
;
905 if (of_device_is_compatible(pdev
->dev
.of_node
, "qcom,pm8821-mpp"))
906 girq
->child_to_parent_hwirq
= pm8821_mpp_child_to_parent_hwirq
;
908 girq
->child_to_parent_hwirq
= pm8xxx_mpp_child_to_parent_hwirq
;
909 girq
->populate_parent_alloc_arg
= gpiochip_populate_parent_fwspec_twocell
;
910 girq
->child_offset_to_irq
= pm8xxx_mpp_child_offset_to_irq
;
911 girq
->child_irq_domain_ops
.translate
= pm8xxx_mpp_domain_translate
;
913 ret
= gpiochip_add_data(&pctrl
->chip
, pctrl
);
915 dev_err(&pdev
->dev
, "failed register gpiochip\n");
919 ret
= gpiochip_add_pin_range(&pctrl
->chip
,
920 dev_name(pctrl
->dev
),
921 0, 0, pctrl
->chip
.ngpio
);
923 dev_err(pctrl
->dev
, "failed to add pin range\n");
924 goto unregister_gpiochip
;
927 platform_set_drvdata(pdev
, pctrl
);
929 dev_dbg(&pdev
->dev
, "Qualcomm pm8xxx mpp driver probed\n");
934 gpiochip_remove(&pctrl
->chip
);
939 static void pm8xxx_mpp_remove(struct platform_device
*pdev
)
941 struct pm8xxx_mpp
*pctrl
= platform_get_drvdata(pdev
);
943 gpiochip_remove(&pctrl
->chip
);
946 static struct platform_driver pm8xxx_mpp_driver
= {
948 .name
= "qcom-ssbi-mpp",
949 .of_match_table
= pm8xxx_mpp_of_match
,
951 .probe
= pm8xxx_mpp_probe
,
952 .remove
= pm8xxx_mpp_remove
,
955 module_platform_driver(pm8xxx_mpp_driver
);
957 MODULE_AUTHOR("Bjorn Andersson <bjorn.andersson@sonymobile.com>");
958 MODULE_DESCRIPTION("Qualcomm PM8xxx MPP driver");
959 MODULE_LICENSE("GPL v2");