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-gpio.h>
23 #include "../pinctrl-utils.h"
26 #define PM8XXX_GPIO_MODE_ENABLED BIT(0)
27 #define PM8XXX_GPIO_MODE_INPUT 0
28 #define PM8XXX_GPIO_MODE_OUTPUT 2
31 #define PM8XXX_GPIO_PUSH_PULL 0
32 #define PM8XXX_GPIO_OPEN_DRAIN 1
35 #define PM8XXX_GPIO_BIAS_PU_30 0
36 #define PM8XXX_GPIO_BIAS_PU_1P5 1
37 #define PM8XXX_GPIO_BIAS_PU_31P5 2
38 #define PM8XXX_GPIO_BIAS_PU_1P5_30 3
39 #define PM8XXX_GPIO_BIAS_PD 4
40 #define PM8XXX_GPIO_BIAS_NP 5
43 #define SSBI_REG_ADDR_GPIO_BASE 0x150
44 #define SSBI_REG_ADDR_GPIO(n) (SSBI_REG_ADDR_GPIO_BASE + n)
46 #define PM8XXX_BANK_WRITE BIT(7)
48 #define PM8XXX_MAX_GPIOS 44
50 #define PM8XXX_GPIO_PHYSICAL_OFFSET 1
52 /* custom pinconf parameters */
53 #define PM8XXX_QCOM_DRIVE_STRENGH (PIN_CONFIG_END + 1)
54 #define PM8XXX_QCOM_PULL_UP_STRENGTH (PIN_CONFIG_END + 2)
57 * struct pm8xxx_pin_data - dynamic configuration for a pin
58 * @reg: address of the control register
59 * @power_source: logical selected voltage source, mapping in static data
60 * is used translate to register values
61 * @mode: operating mode for the pin (input/output)
62 * @open_drain: output buffer configured as open-drain (vs push-pull)
63 * @output_value: configured output value
64 * @bias: register view of configured bias
65 * @pull_up_strength: placeholder for selected pull up strength
66 * only used to configure bias when pull up is selected
67 * @output_strength: selector of output-strength
68 * @disable: pin disabled / configured as tristate
69 * @function: pinmux selector
70 * @inverted: pin logic is inverted
72 struct pm8xxx_pin_data
{
88 struct regmap
*regmap
;
89 struct pinctrl_dev
*pctrl
;
90 struct gpio_chip chip
;
92 struct pinctrl_desc desc
;
96 static const struct pinconf_generic_params pm8xxx_gpio_bindings
[] = {
97 {"qcom,drive-strength", PM8XXX_QCOM_DRIVE_STRENGH
, 0},
98 {"qcom,pull-up-strength", PM8XXX_QCOM_PULL_UP_STRENGTH
, 0},
101 #ifdef CONFIG_DEBUG_FS
102 static const struct pin_config_item pm8xxx_conf_items
[ARRAY_SIZE(pm8xxx_gpio_bindings
)] = {
103 PCONFDUMP(PM8XXX_QCOM_DRIVE_STRENGH
, "drive-strength", NULL
, true),
104 PCONFDUMP(PM8XXX_QCOM_PULL_UP_STRENGTH
, "pull up strength", NULL
, true),
108 static const char * const pm8xxx_groups
[PM8XXX_MAX_GPIOS
] = {
109 "gpio1", "gpio2", "gpio3", "gpio4", "gpio5", "gpio6", "gpio7", "gpio8",
110 "gpio9", "gpio10", "gpio11", "gpio12", "gpio13", "gpio14", "gpio15",
111 "gpio16", "gpio17", "gpio18", "gpio19", "gpio20", "gpio21", "gpio22",
112 "gpio23", "gpio24", "gpio25", "gpio26", "gpio27", "gpio28", "gpio29",
113 "gpio30", "gpio31", "gpio32", "gpio33", "gpio34", "gpio35", "gpio36",
114 "gpio37", "gpio38", "gpio39", "gpio40", "gpio41", "gpio42", "gpio43",
118 static const char * const pm8xxx_gpio_functions
[] = {
119 PMIC_GPIO_FUNC_NORMAL
, PMIC_GPIO_FUNC_PAIRED
,
120 PMIC_GPIO_FUNC_FUNC1
, PMIC_GPIO_FUNC_FUNC2
,
121 PMIC_GPIO_FUNC_DTEST1
, PMIC_GPIO_FUNC_DTEST2
,
122 PMIC_GPIO_FUNC_DTEST3
, PMIC_GPIO_FUNC_DTEST4
,
125 static int pm8xxx_read_bank(struct pm8xxx_gpio
*pctrl
,
126 struct pm8xxx_pin_data
*pin
, int bank
)
128 unsigned int val
= bank
<< 4;
131 ret
= regmap_write(pctrl
->regmap
, pin
->reg
, val
);
133 dev_err(pctrl
->dev
, "failed to select bank %d\n", bank
);
137 ret
= regmap_read(pctrl
->regmap
, pin
->reg
, &val
);
139 dev_err(pctrl
->dev
, "failed to read register %d\n", bank
);
146 static int pm8xxx_write_bank(struct pm8xxx_gpio
*pctrl
,
147 struct pm8xxx_pin_data
*pin
,
153 val
|= PM8XXX_BANK_WRITE
;
156 ret
= regmap_write(pctrl
->regmap
, pin
->reg
, val
);
158 dev_err(pctrl
->dev
, "failed to write register\n");
163 static int pm8xxx_get_groups_count(struct pinctrl_dev
*pctldev
)
165 struct pm8xxx_gpio
*pctrl
= pinctrl_dev_get_drvdata(pctldev
);
170 static const char *pm8xxx_get_group_name(struct pinctrl_dev
*pctldev
,
173 return pm8xxx_groups
[group
];
177 static int pm8xxx_get_group_pins(struct pinctrl_dev
*pctldev
,
179 const unsigned **pins
,
182 struct pm8xxx_gpio
*pctrl
= pinctrl_dev_get_drvdata(pctldev
);
184 *pins
= &pctrl
->desc
.pins
[group
].number
;
190 static const struct pinctrl_ops pm8xxx_pinctrl_ops
= {
191 .get_groups_count
= pm8xxx_get_groups_count
,
192 .get_group_name
= pm8xxx_get_group_name
,
193 .get_group_pins
= pm8xxx_get_group_pins
,
194 .dt_node_to_map
= pinconf_generic_dt_node_to_map_group
,
195 .dt_free_map
= pinctrl_utils_free_map
,
198 static int pm8xxx_get_functions_count(struct pinctrl_dev
*pctldev
)
200 return ARRAY_SIZE(pm8xxx_gpio_functions
);
203 static const char *pm8xxx_get_function_name(struct pinctrl_dev
*pctldev
,
206 return pm8xxx_gpio_functions
[function
];
209 static int pm8xxx_get_function_groups(struct pinctrl_dev
*pctldev
,
211 const char * const **groups
,
212 unsigned * const num_groups
)
214 struct pm8xxx_gpio
*pctrl
= pinctrl_dev_get_drvdata(pctldev
);
216 *groups
= pm8xxx_groups
;
217 *num_groups
= pctrl
->npins
;
221 static int pm8xxx_pinmux_set_mux(struct pinctrl_dev
*pctldev
,
225 struct pm8xxx_gpio
*pctrl
= pinctrl_dev_get_drvdata(pctldev
);
226 struct pm8xxx_pin_data
*pin
= pctrl
->desc
.pins
[group
].drv_data
;
229 pin
->function
= function
;
230 val
= pin
->function
<< 1;
232 pm8xxx_write_bank(pctrl
, pin
, 4, val
);
237 static const struct pinmux_ops pm8xxx_pinmux_ops
= {
238 .get_functions_count
= pm8xxx_get_functions_count
,
239 .get_function_name
= pm8xxx_get_function_name
,
240 .get_function_groups
= pm8xxx_get_function_groups
,
241 .set_mux
= pm8xxx_pinmux_set_mux
,
244 static int pm8xxx_pin_config_get(struct pinctrl_dev
*pctldev
,
246 unsigned long *config
)
248 struct pm8xxx_gpio
*pctrl
= pinctrl_dev_get_drvdata(pctldev
);
249 struct pm8xxx_pin_data
*pin
= pctrl
->desc
.pins
[offset
].drv_data
;
250 unsigned param
= pinconf_to_config_param(*config
);
254 case PIN_CONFIG_BIAS_DISABLE
:
255 if (pin
->bias
!= PM8XXX_GPIO_BIAS_NP
)
259 case PIN_CONFIG_BIAS_PULL_DOWN
:
260 if (pin
->bias
!= PM8XXX_GPIO_BIAS_PD
)
264 case PIN_CONFIG_BIAS_PULL_UP
:
265 if (pin
->bias
> PM8XXX_GPIO_BIAS_PU_1P5_30
)
269 case PM8XXX_QCOM_PULL_UP_STRENGTH
:
270 arg
= pin
->pull_up_strength
;
272 case PIN_CONFIG_BIAS_HIGH_IMPEDANCE
:
277 case PIN_CONFIG_INPUT_ENABLE
:
278 if (pin
->mode
!= PM8XXX_GPIO_MODE_INPUT
)
282 case PIN_CONFIG_OUTPUT
:
283 if (pin
->mode
& PM8XXX_GPIO_MODE_OUTPUT
)
284 arg
= pin
->output_value
;
288 case PIN_CONFIG_POWER_SOURCE
:
289 arg
= pin
->power_source
;
291 case PM8XXX_QCOM_DRIVE_STRENGH
:
292 arg
= pin
->output_strength
;
294 case PIN_CONFIG_DRIVE_PUSH_PULL
:
299 case PIN_CONFIG_DRIVE_OPEN_DRAIN
:
300 if (!pin
->open_drain
)
308 *config
= pinconf_to_config_packed(param
, arg
);
313 static int pm8xxx_pin_config_set(struct pinctrl_dev
*pctldev
,
315 unsigned long *configs
,
316 unsigned num_configs
)
318 struct pm8xxx_gpio
*pctrl
= pinctrl_dev_get_drvdata(pctldev
);
319 struct pm8xxx_pin_data
*pin
= pctrl
->desc
.pins
[offset
].drv_data
;
326 for (i
= 0; i
< num_configs
; i
++) {
327 param
= pinconf_to_config_param(configs
[i
]);
328 arg
= pinconf_to_config_argument(configs
[i
]);
331 case PIN_CONFIG_BIAS_DISABLE
:
332 pin
->bias
= PM8XXX_GPIO_BIAS_NP
;
337 case PIN_CONFIG_BIAS_PULL_DOWN
:
338 pin
->bias
= PM8XXX_GPIO_BIAS_PD
;
343 case PM8XXX_QCOM_PULL_UP_STRENGTH
:
344 if (arg
> PM8XXX_GPIO_BIAS_PU_1P5_30
) {
345 dev_err(pctrl
->dev
, "invalid pull-up strength\n");
348 pin
->pull_up_strength
= arg
;
350 case PIN_CONFIG_BIAS_PULL_UP
:
351 pin
->bias
= pin
->pull_up_strength
;
356 case PIN_CONFIG_BIAS_HIGH_IMPEDANCE
:
360 case PIN_CONFIG_INPUT_ENABLE
:
361 pin
->mode
= PM8XXX_GPIO_MODE_INPUT
;
362 banks
|= BIT(0) | BIT(1);
364 case PIN_CONFIG_OUTPUT
:
365 pin
->mode
= PM8XXX_GPIO_MODE_OUTPUT
;
366 pin
->output_value
= !!arg
;
367 banks
|= BIT(0) | BIT(1);
369 case PIN_CONFIG_POWER_SOURCE
:
370 pin
->power_source
= arg
;
373 case PM8XXX_QCOM_DRIVE_STRENGH
:
374 if (arg
> PMIC_GPIO_STRENGTH_LOW
) {
375 dev_err(pctrl
->dev
, "invalid drive strength\n");
378 pin
->output_strength
= arg
;
381 case PIN_CONFIG_DRIVE_PUSH_PULL
:
385 case PIN_CONFIG_DRIVE_OPEN_DRAIN
:
391 "unsupported config parameter: %x\n",
397 if (banks
& BIT(0)) {
398 val
= pin
->power_source
<< 1;
399 val
|= PM8XXX_GPIO_MODE_ENABLED
;
400 pm8xxx_write_bank(pctrl
, pin
, 0, val
);
403 if (banks
& BIT(1)) {
404 val
= pin
->mode
<< 2;
405 val
|= pin
->open_drain
<< 1;
406 val
|= pin
->output_value
;
407 pm8xxx_write_bank(pctrl
, pin
, 1, val
);
410 if (banks
& BIT(2)) {
411 val
= pin
->bias
<< 1;
412 pm8xxx_write_bank(pctrl
, pin
, 2, val
);
415 if (banks
& BIT(3)) {
416 val
= pin
->output_strength
<< 2;
418 pm8xxx_write_bank(pctrl
, pin
, 3, val
);
421 if (banks
& BIT(4)) {
422 val
= pin
->function
<< 1;
423 pm8xxx_write_bank(pctrl
, pin
, 4, val
);
426 if (banks
& BIT(5)) {
430 pm8xxx_write_bank(pctrl
, pin
, 5, val
);
436 static const struct pinconf_ops pm8xxx_pinconf_ops
= {
438 .pin_config_group_get
= pm8xxx_pin_config_get
,
439 .pin_config_group_set
= pm8xxx_pin_config_set
,
442 static const struct pinctrl_desc pm8xxx_pinctrl_desc
= {
443 .name
= "pm8xxx_gpio",
444 .pctlops
= &pm8xxx_pinctrl_ops
,
445 .pmxops
= &pm8xxx_pinmux_ops
,
446 .confops
= &pm8xxx_pinconf_ops
,
447 .owner
= THIS_MODULE
,
450 static int pm8xxx_gpio_direction_input(struct gpio_chip
*chip
,
453 struct pm8xxx_gpio
*pctrl
= gpiochip_get_data(chip
);
454 struct pm8xxx_pin_data
*pin
= pctrl
->desc
.pins
[offset
].drv_data
;
457 pin
->mode
= PM8XXX_GPIO_MODE_INPUT
;
458 val
= pin
->mode
<< 2;
460 pm8xxx_write_bank(pctrl
, pin
, 1, val
);
465 static int pm8xxx_gpio_direction_output(struct gpio_chip
*chip
,
469 struct pm8xxx_gpio
*pctrl
= gpiochip_get_data(chip
);
470 struct pm8xxx_pin_data
*pin
= pctrl
->desc
.pins
[offset
].drv_data
;
473 pin
->mode
= PM8XXX_GPIO_MODE_OUTPUT
;
474 pin
->output_value
= !!value
;
476 val
= pin
->mode
<< 2;
477 val
|= pin
->open_drain
<< 1;
478 val
|= pin
->output_value
;
480 pm8xxx_write_bank(pctrl
, pin
, 1, val
);
485 static int pm8xxx_gpio_get(struct gpio_chip
*chip
, unsigned offset
)
487 struct pm8xxx_gpio
*pctrl
= gpiochip_get_data(chip
);
488 struct pm8xxx_pin_data
*pin
= pctrl
->desc
.pins
[offset
].drv_data
;
492 if (pin
->mode
== PM8XXX_GPIO_MODE_OUTPUT
)
493 return pin
->output_value
;
495 irq
= chip
->to_irq(chip
, offset
);
497 ret
= irq_get_irqchip_state(irq
, IRQCHIP_STATE_LINE_LEVEL
,
507 static void pm8xxx_gpio_set(struct gpio_chip
*chip
, unsigned offset
, int value
)
509 struct pm8xxx_gpio
*pctrl
= gpiochip_get_data(chip
);
510 struct pm8xxx_pin_data
*pin
= pctrl
->desc
.pins
[offset
].drv_data
;
513 pin
->output_value
= !!value
;
515 val
= pin
->mode
<< 2;
516 val
|= pin
->open_drain
<< 1;
517 val
|= pin
->output_value
;
519 pm8xxx_write_bank(pctrl
, pin
, 1, val
);
522 static int pm8xxx_gpio_of_xlate(struct gpio_chip
*chip
,
523 const struct of_phandle_args
*gpio_desc
,
526 if (chip
->of_gpio_n_cells
< 2)
530 *flags
= gpio_desc
->args
[1];
532 return gpio_desc
->args
[0] - PM8XXX_GPIO_PHYSICAL_OFFSET
;
536 #ifdef CONFIG_DEBUG_FS
537 #include <linux/seq_file.h>
539 static void pm8xxx_gpio_dbg_show_one(struct seq_file
*s
,
540 struct pinctrl_dev
*pctldev
,
541 struct gpio_chip
*chip
,
545 struct pm8xxx_gpio
*pctrl
= gpiochip_get_data(chip
);
546 struct pm8xxx_pin_data
*pin
= pctrl
->desc
.pins
[offset
].drv_data
;
548 static const char * const modes
[] = {
549 "in", "both", "out", "off"
551 static const char * const biases
[] = {
552 "pull-up 30uA", "pull-up 1.5uA", "pull-up 31.5uA",
553 "pull-up 1.5uA + 30uA boost", "pull-down 10uA", "no pull"
555 static const char * const buffer_types
[] = {
556 "push-pull", "open-drain"
558 static const char * const strengths
[] = {
559 "no", "high", "medium", "low"
562 seq_printf(s
, " gpio%-2d:", offset
+ PM8XXX_GPIO_PHYSICAL_OFFSET
);
566 seq_printf(s
, " %-4s", modes
[pin
->mode
]);
567 seq_printf(s
, " %-7s", pm8xxx_gpio_functions
[pin
->function
]);
568 seq_printf(s
, " VIN%d", pin
->power_source
);
569 seq_printf(s
, " %-27s", biases
[pin
->bias
]);
570 seq_printf(s
, " %-10s", buffer_types
[pin
->open_drain
]);
571 seq_printf(s
, " %-4s", pin
->output_value
? "high" : "low");
572 seq_printf(s
, " %-7s", strengths
[pin
->output_strength
]);
574 seq_puts(s
, " inverted");
578 static void pm8xxx_gpio_dbg_show(struct seq_file
*s
, struct gpio_chip
*chip
)
580 unsigned gpio
= chip
->base
;
583 for (i
= 0; i
< chip
->ngpio
; i
++, gpio
++) {
584 pm8xxx_gpio_dbg_show_one(s
, NULL
, chip
, i
, gpio
);
590 #define pm8xxx_gpio_dbg_show NULL
593 static const struct gpio_chip pm8xxx_gpio_template
= {
594 .direction_input
= pm8xxx_gpio_direction_input
,
595 .direction_output
= pm8xxx_gpio_direction_output
,
596 .get
= pm8xxx_gpio_get
,
597 .set
= pm8xxx_gpio_set
,
598 .of_xlate
= pm8xxx_gpio_of_xlate
,
599 .dbg_show
= pm8xxx_gpio_dbg_show
,
600 .owner
= THIS_MODULE
,
603 static int pm8xxx_pin_populate(struct pm8xxx_gpio
*pctrl
,
604 struct pm8xxx_pin_data
*pin
)
608 val
= pm8xxx_read_bank(pctrl
, pin
, 0);
612 pin
->power_source
= (val
>> 1) & 0x7;
614 val
= pm8xxx_read_bank(pctrl
, pin
, 1);
618 pin
->mode
= (val
>> 2) & 0x3;
619 pin
->open_drain
= !!(val
& BIT(1));
620 pin
->output_value
= val
& BIT(0);
622 val
= pm8xxx_read_bank(pctrl
, pin
, 2);
626 pin
->bias
= (val
>> 1) & 0x7;
627 if (pin
->bias
<= PM8XXX_GPIO_BIAS_PU_1P5_30
)
628 pin
->pull_up_strength
= pin
->bias
;
630 pin
->pull_up_strength
= PM8XXX_GPIO_BIAS_PU_30
;
632 val
= pm8xxx_read_bank(pctrl
, pin
, 3);
636 pin
->output_strength
= (val
>> 2) & 0x3;
637 pin
->disable
= val
& BIT(0);
639 val
= pm8xxx_read_bank(pctrl
, pin
, 4);
643 pin
->function
= (val
>> 1) & 0x7;
645 val
= pm8xxx_read_bank(pctrl
, pin
, 5);
649 pin
->inverted
= !(val
& BIT(3));
654 static struct irq_chip pm8xxx_irq_chip
= {
656 .irq_mask_ack
= irq_chip_mask_ack_parent
,
657 .irq_unmask
= irq_chip_unmask_parent
,
658 .irq_set_type
= irq_chip_set_type_parent
,
659 .flags
= IRQCHIP_MASK_ON_SUSPEND
| IRQCHIP_SKIP_SET_WAKE
,
662 static int pm8xxx_domain_translate(struct irq_domain
*domain
,
663 struct irq_fwspec
*fwspec
,
664 unsigned long *hwirq
,
667 struct pm8xxx_gpio
*pctrl
= container_of(domain
->host_data
,
668 struct pm8xxx_gpio
, chip
);
670 if (fwspec
->param_count
!= 2 || fwspec
->param
[0] < 1 ||
671 fwspec
->param
[0] > pctrl
->chip
.ngpio
)
674 *hwirq
= fwspec
->param
[0] - PM8XXX_GPIO_PHYSICAL_OFFSET
;
675 *type
= fwspec
->param
[1];
680 static unsigned int pm8xxx_child_offset_to_irq(struct gpio_chip
*chip
,
683 return offset
+ PM8XXX_GPIO_PHYSICAL_OFFSET
;
686 static int pm8xxx_child_to_parent_hwirq(struct gpio_chip
*chip
,
687 unsigned int child_hwirq
,
688 unsigned int child_type
,
689 unsigned int *parent_hwirq
,
690 unsigned int *parent_type
)
692 *parent_hwirq
= child_hwirq
+ 0xc0;
693 *parent_type
= child_type
;
698 static const struct of_device_id pm8xxx_gpio_of_match
[] = {
699 { .compatible
= "qcom,pm8018-gpio", .data
= (void *) 6 },
700 { .compatible
= "qcom,pm8038-gpio", .data
= (void *) 12 },
701 { .compatible
= "qcom,pm8058-gpio", .data
= (void *) 44 },
702 { .compatible
= "qcom,pm8917-gpio", .data
= (void *) 38 },
703 { .compatible
= "qcom,pm8921-gpio", .data
= (void *) 44 },
706 MODULE_DEVICE_TABLE(of
, pm8xxx_gpio_of_match
);
708 static int pm8xxx_gpio_probe(struct platform_device
*pdev
)
710 struct pm8xxx_pin_data
*pin_data
;
711 struct irq_domain
*parent_domain
;
712 struct device_node
*parent_node
;
713 struct pinctrl_pin_desc
*pins
;
714 struct gpio_irq_chip
*girq
;
715 struct pm8xxx_gpio
*pctrl
;
718 pctrl
= devm_kzalloc(&pdev
->dev
, sizeof(*pctrl
), GFP_KERNEL
);
722 pctrl
->dev
= &pdev
->dev
;
723 pctrl
->npins
= (uintptr_t) device_get_match_data(&pdev
->dev
);
725 pctrl
->regmap
= dev_get_regmap(pdev
->dev
.parent
, NULL
);
726 if (!pctrl
->regmap
) {
727 dev_err(&pdev
->dev
, "parent regmap unavailable\n");
731 pctrl
->desc
= pm8xxx_pinctrl_desc
;
732 pctrl
->desc
.npins
= pctrl
->npins
;
734 pins
= devm_kcalloc(&pdev
->dev
,
736 sizeof(struct pinctrl_pin_desc
),
741 pin_data
= devm_kcalloc(&pdev
->dev
,
743 sizeof(struct pm8xxx_pin_data
),
748 for (i
= 0; i
< pctrl
->desc
.npins
; i
++) {
749 pin_data
[i
].reg
= SSBI_REG_ADDR_GPIO(i
);
751 ret
= pm8xxx_pin_populate(pctrl
, &pin_data
[i
]);
756 pins
[i
].name
= pm8xxx_groups
[i
];
757 pins
[i
].drv_data
= &pin_data
[i
];
759 pctrl
->desc
.pins
= pins
;
761 pctrl
->desc
.num_custom_params
= ARRAY_SIZE(pm8xxx_gpio_bindings
);
762 pctrl
->desc
.custom_params
= pm8xxx_gpio_bindings
;
763 #ifdef CONFIG_DEBUG_FS
764 pctrl
->desc
.custom_conf_items
= pm8xxx_conf_items
;
767 pctrl
->pctrl
= devm_pinctrl_register(&pdev
->dev
, &pctrl
->desc
, pctrl
);
768 if (IS_ERR(pctrl
->pctrl
)) {
769 dev_err(&pdev
->dev
, "couldn't register pm8xxx gpio driver\n");
770 return PTR_ERR(pctrl
->pctrl
);
773 pctrl
->chip
= pm8xxx_gpio_template
;
774 pctrl
->chip
.base
= -1;
775 pctrl
->chip
.parent
= &pdev
->dev
;
776 pctrl
->chip
.of_node
= pdev
->dev
.of_node
;
777 pctrl
->chip
.of_gpio_n_cells
= 2;
778 pctrl
->chip
.label
= dev_name(pctrl
->dev
);
779 pctrl
->chip
.ngpio
= pctrl
->npins
;
781 parent_node
= of_irq_find_parent(pctrl
->dev
->of_node
);
785 parent_domain
= irq_find_host(parent_node
);
786 of_node_put(parent_node
);
790 girq
= &pctrl
->chip
.irq
;
791 girq
->chip
= &pm8xxx_irq_chip
;
792 girq
->default_type
= IRQ_TYPE_NONE
;
793 girq
->handler
= handle_level_irq
;
794 girq
->fwnode
= of_node_to_fwnode(pctrl
->dev
->of_node
);
795 girq
->parent_domain
= parent_domain
;
796 girq
->child_to_parent_hwirq
= pm8xxx_child_to_parent_hwirq
;
797 girq
->populate_parent_alloc_arg
= gpiochip_populate_parent_fwspec_twocell
;
798 girq
->child_offset_to_irq
= pm8xxx_child_offset_to_irq
;
799 girq
->child_irq_domain_ops
.translate
= pm8xxx_domain_translate
;
801 ret
= gpiochip_add_data(&pctrl
->chip
, pctrl
);
803 dev_err(&pdev
->dev
, "failed register gpiochip\n");
808 * For DeviceTree-supported systems, the gpio core checks the
809 * pinctrl's device node for the "gpio-ranges" property.
810 * If it is present, it takes care of adding the pin ranges
811 * for the driver. In this case the driver can skip ahead.
813 * In order to remain compatible with older, existing DeviceTree
814 * files which don't set the "gpio-ranges" property or systems that
815 * utilize ACPI the driver has to call gpiochip_add_pin_range().
817 if (!of_property_read_bool(pctrl
->dev
->of_node
, "gpio-ranges")) {
818 ret
= gpiochip_add_pin_range(&pctrl
->chip
, dev_name(pctrl
->dev
),
819 0, 0, pctrl
->chip
.ngpio
);
821 dev_err(pctrl
->dev
, "failed to add pin range\n");
822 goto unregister_gpiochip
;
826 platform_set_drvdata(pdev
, pctrl
);
828 dev_dbg(&pdev
->dev
, "Qualcomm pm8xxx gpio driver probed\n");
833 gpiochip_remove(&pctrl
->chip
);
838 static int pm8xxx_gpio_remove(struct platform_device
*pdev
)
840 struct pm8xxx_gpio
*pctrl
= platform_get_drvdata(pdev
);
842 gpiochip_remove(&pctrl
->chip
);
847 static struct platform_driver pm8xxx_gpio_driver
= {
849 .name
= "qcom-ssbi-gpio",
850 .of_match_table
= pm8xxx_gpio_of_match
,
852 .probe
= pm8xxx_gpio_probe
,
853 .remove
= pm8xxx_gpio_remove
,
856 module_platform_driver(pm8xxx_gpio_driver
);
858 MODULE_AUTHOR("Bjorn Andersson <bjorn.andersson@sonymobile.com>");
859 MODULE_DESCRIPTION("Qualcomm PM8xxx GPIO driver");
860 MODULE_LICENSE("GPL v2");