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/driver.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-gpio.h>
31 #include "../pinctrl-utils.h"
34 #define PM8XXX_GPIO_MODE_ENABLED BIT(0)
35 #define PM8XXX_GPIO_MODE_INPUT 0
36 #define PM8XXX_GPIO_MODE_OUTPUT 2
39 #define PM8XXX_GPIO_PUSH_PULL 0
40 #define PM8XXX_GPIO_OPEN_DRAIN 1
43 #define PM8XXX_GPIO_BIAS_PU_30 0
44 #define PM8XXX_GPIO_BIAS_PU_1P5 1
45 #define PM8XXX_GPIO_BIAS_PU_31P5 2
46 #define PM8XXX_GPIO_BIAS_PU_1P5_30 3
47 #define PM8XXX_GPIO_BIAS_PD 4
48 #define PM8XXX_GPIO_BIAS_NP 5
51 #define SSBI_REG_ADDR_GPIO_BASE 0x150
52 #define SSBI_REG_ADDR_GPIO(n) (SSBI_REG_ADDR_GPIO_BASE + n)
54 #define PM8XXX_BANK_WRITE BIT(7)
56 #define PM8XXX_MAX_GPIOS 44
58 #define PM8XXX_GPIO_PHYSICAL_OFFSET 1
60 /* custom pinconf parameters */
61 #define PM8XXX_QCOM_DRIVE_STRENGH (PIN_CONFIG_END + 1)
62 #define PM8XXX_QCOM_PULL_UP_STRENGTH (PIN_CONFIG_END + 2)
65 * struct pm8xxx_pin_data - dynamic configuration for a pin
66 * @reg: address of the control register
67 * @irq: IRQ from the PMIC interrupt controller
68 * @power_source: logical selected voltage source, mapping in static data
69 * is used translate to register values
70 * @mode: operating mode for the pin (input/output)
71 * @open_drain: output buffer configured as open-drain (vs push-pull)
72 * @output_value: configured output value
73 * @bias: register view of configured bias
74 * @pull_up_strength: placeholder for selected pull up strength
75 * only used to configure bias when pull up is selected
76 * @output_strength: selector of output-strength
77 * @disable: pin disabled / configured as tristate
78 * @function: pinmux selector
79 * @inverted: pin logic is inverted
81 struct pm8xxx_pin_data {
98 struct regmap *regmap;
99 struct pinctrl_dev *pctrl;
100 struct gpio_chip chip;
102 struct pinctrl_desc desc;
105 struct fwnode_handle *fwnode;
106 struct irq_domain *domain;
109 static const struct pinconf_generic_params pm8xxx_gpio_bindings[] = {
110 {"qcom,drive-strength", PM8XXX_QCOM_DRIVE_STRENGH, 0},
111 {"qcom,pull-up-strength", PM8XXX_QCOM_PULL_UP_STRENGTH, 0},
114 #ifdef CONFIG_DEBUG_FS
115 static const struct pin_config_item pm8xxx_conf_items[ARRAY_SIZE(pm8xxx_gpio_bindings)] = {
116 PCONFDUMP(PM8XXX_QCOM_DRIVE_STRENGH, "drive-strength", NULL, true),
117 PCONFDUMP(PM8XXX_QCOM_PULL_UP_STRENGTH, "pull up strength", NULL, true),
121 static const char * const pm8xxx_groups[PM8XXX_MAX_GPIOS] = {
122 "gpio1", "gpio2", "gpio3", "gpio4", "gpio5", "gpio6", "gpio7", "gpio8",
123 "gpio9", "gpio10", "gpio11", "gpio12", "gpio13", "gpio14", "gpio15",
124 "gpio16", "gpio17", "gpio18", "gpio19", "gpio20", "gpio21", "gpio22",
125 "gpio23", "gpio24", "gpio25", "gpio26", "gpio27", "gpio28", "gpio29",
126 "gpio30", "gpio31", "gpio32", "gpio33", "gpio34", "gpio35", "gpio36",
127 "gpio37", "gpio38", "gpio39", "gpio40", "gpio41", "gpio42", "gpio43",
131 static const char * const pm8xxx_gpio_functions[] = {
132 PMIC_GPIO_FUNC_NORMAL, PMIC_GPIO_FUNC_PAIRED,
133 PMIC_GPIO_FUNC_FUNC1, PMIC_GPIO_FUNC_FUNC2,
134 PMIC_GPIO_FUNC_DTEST1, PMIC_GPIO_FUNC_DTEST2,
135 PMIC_GPIO_FUNC_DTEST3, PMIC_GPIO_FUNC_DTEST4,
138 static int pm8xxx_read_bank(struct pm8xxx_gpio *pctrl,
139 struct pm8xxx_pin_data *pin, int bank)
141 unsigned int val = bank << 4;
144 ret = regmap_write(pctrl->regmap, pin->reg, val);
146 dev_err(pctrl->dev, "failed to select bank %d\n", bank);
150 ret = regmap_read(pctrl->regmap, pin->reg, &val);
152 dev_err(pctrl->dev, "failed to read register %d\n", bank);
159 static int pm8xxx_write_bank(struct pm8xxx_gpio *pctrl,
160 struct pm8xxx_pin_data *pin,
166 val |= PM8XXX_BANK_WRITE;
169 ret = regmap_write(pctrl->regmap, pin->reg, val);
171 dev_err(pctrl->dev, "failed to write register\n");
176 static int pm8xxx_get_groups_count(struct pinctrl_dev *pctldev)
178 struct pm8xxx_gpio *pctrl = pinctrl_dev_get_drvdata(pctldev);
183 static const char *pm8xxx_get_group_name(struct pinctrl_dev *pctldev,
186 return pm8xxx_groups[group];
190 static int pm8xxx_get_group_pins(struct pinctrl_dev *pctldev,
192 const unsigned **pins,
195 struct pm8xxx_gpio *pctrl = pinctrl_dev_get_drvdata(pctldev);
197 *pins = &pctrl->desc.pins[group].number;
203 static const struct pinctrl_ops pm8xxx_pinctrl_ops = {
204 .get_groups_count = pm8xxx_get_groups_count,
205 .get_group_name = pm8xxx_get_group_name,
206 .get_group_pins = pm8xxx_get_group_pins,
207 .dt_node_to_map = pinconf_generic_dt_node_to_map_group,
208 .dt_free_map = pinctrl_utils_free_map,
211 static int pm8xxx_get_functions_count(struct pinctrl_dev *pctldev)
213 return ARRAY_SIZE(pm8xxx_gpio_functions);
216 static const char *pm8xxx_get_function_name(struct pinctrl_dev *pctldev,
219 return pm8xxx_gpio_functions[function];
222 static int pm8xxx_get_function_groups(struct pinctrl_dev *pctldev,
224 const char * const **groups,
225 unsigned * const num_groups)
227 struct pm8xxx_gpio *pctrl = pinctrl_dev_get_drvdata(pctldev);
229 *groups = pm8xxx_groups;
230 *num_groups = pctrl->npins;
234 static int pm8xxx_pinmux_set_mux(struct pinctrl_dev *pctldev,
238 struct pm8xxx_gpio *pctrl = pinctrl_dev_get_drvdata(pctldev);
239 struct pm8xxx_pin_data *pin = pctrl->desc.pins[group].drv_data;
242 pin->function = function;
243 val = pin->function << 1;
245 pm8xxx_write_bank(pctrl, pin, 4, val);
250 static const struct pinmux_ops pm8xxx_pinmux_ops = {
251 .get_functions_count = pm8xxx_get_functions_count,
252 .get_function_name = pm8xxx_get_function_name,
253 .get_function_groups = pm8xxx_get_function_groups,
254 .set_mux = pm8xxx_pinmux_set_mux,
257 static int pm8xxx_pin_config_get(struct pinctrl_dev *pctldev,
259 unsigned long *config)
261 struct pm8xxx_gpio *pctrl = pinctrl_dev_get_drvdata(pctldev);
262 struct pm8xxx_pin_data *pin = pctrl->desc.pins[offset].drv_data;
263 unsigned param = pinconf_to_config_param(*config);
267 case PIN_CONFIG_BIAS_DISABLE:
268 if (pin->bias != PM8XXX_GPIO_BIAS_NP)
272 case PIN_CONFIG_BIAS_PULL_DOWN:
273 if (pin->bias != PM8XXX_GPIO_BIAS_PD)
277 case PIN_CONFIG_BIAS_PULL_UP:
278 if (pin->bias > PM8XXX_GPIO_BIAS_PU_1P5_30)
282 case PM8XXX_QCOM_PULL_UP_STRENGTH:
283 arg = pin->pull_up_strength;
285 case PIN_CONFIG_BIAS_HIGH_IMPEDANCE:
290 case PIN_CONFIG_INPUT_ENABLE:
291 if (pin->mode != PM8XXX_GPIO_MODE_INPUT)
295 case PIN_CONFIG_OUTPUT:
296 if (pin->mode & PM8XXX_GPIO_MODE_OUTPUT)
297 arg = pin->output_value;
301 case PIN_CONFIG_POWER_SOURCE:
302 arg = pin->power_source;
304 case PM8XXX_QCOM_DRIVE_STRENGH:
305 arg = pin->output_strength;
307 case PIN_CONFIG_DRIVE_PUSH_PULL:
312 case PIN_CONFIG_DRIVE_OPEN_DRAIN:
313 if (!pin->open_drain)
321 *config = pinconf_to_config_packed(param, arg);
326 static int pm8xxx_pin_config_set(struct pinctrl_dev *pctldev,
328 unsigned long *configs,
329 unsigned num_configs)
331 struct pm8xxx_gpio *pctrl = pinctrl_dev_get_drvdata(pctldev);
332 struct pm8xxx_pin_data *pin = pctrl->desc.pins[offset].drv_data;
339 for (i = 0; i < num_configs; i++) {
340 param = pinconf_to_config_param(configs[i]);
341 arg = pinconf_to_config_argument(configs[i]);
344 case PIN_CONFIG_BIAS_DISABLE:
345 pin->bias = PM8XXX_GPIO_BIAS_NP;
350 case PIN_CONFIG_BIAS_PULL_DOWN:
351 pin->bias = PM8XXX_GPIO_BIAS_PD;
356 case PM8XXX_QCOM_PULL_UP_STRENGTH:
357 if (arg > PM8XXX_GPIO_BIAS_PU_1P5_30) {
358 dev_err(pctrl->dev, "invalid pull-up strength\n");
361 pin->pull_up_strength = arg;
363 case PIN_CONFIG_BIAS_PULL_UP:
364 pin->bias = pin->pull_up_strength;
369 case PIN_CONFIG_BIAS_HIGH_IMPEDANCE:
373 case PIN_CONFIG_INPUT_ENABLE:
374 pin->mode = PM8XXX_GPIO_MODE_INPUT;
375 banks |= BIT(0) | BIT(1);
377 case PIN_CONFIG_OUTPUT:
378 pin->mode = PM8XXX_GPIO_MODE_OUTPUT;
379 pin->output_value = !!arg;
380 banks |= BIT(0) | BIT(1);
382 case PIN_CONFIG_POWER_SOURCE:
383 pin->power_source = arg;
386 case PM8XXX_QCOM_DRIVE_STRENGH:
387 if (arg > PMIC_GPIO_STRENGTH_LOW) {
388 dev_err(pctrl->dev, "invalid drive strength\n");
391 pin->output_strength = arg;
394 case PIN_CONFIG_DRIVE_PUSH_PULL:
398 case PIN_CONFIG_DRIVE_OPEN_DRAIN:
404 "unsupported config parameter: %x\n",
410 if (banks & BIT(0)) {
411 val = pin->power_source << 1;
412 val |= PM8XXX_GPIO_MODE_ENABLED;
413 pm8xxx_write_bank(pctrl, pin, 0, val);
416 if (banks & BIT(1)) {
417 val = pin->mode << 2;
418 val |= pin->open_drain << 1;
419 val |= pin->output_value;
420 pm8xxx_write_bank(pctrl, pin, 1, val);
423 if (banks & BIT(2)) {
424 val = pin->bias << 1;
425 pm8xxx_write_bank(pctrl, pin, 2, val);
428 if (banks & BIT(3)) {
429 val = pin->output_strength << 2;
431 pm8xxx_write_bank(pctrl, pin, 3, val);
434 if (banks & BIT(4)) {
435 val = pin->function << 1;
436 pm8xxx_write_bank(pctrl, pin, 4, val);
439 if (banks & BIT(5)) {
443 pm8xxx_write_bank(pctrl, pin, 5, val);
449 static const struct pinconf_ops pm8xxx_pinconf_ops = {
451 .pin_config_group_get = pm8xxx_pin_config_get,
452 .pin_config_group_set = pm8xxx_pin_config_set,
455 static struct pinctrl_desc pm8xxx_pinctrl_desc = {
456 .name = "pm8xxx_gpio",
457 .pctlops = &pm8xxx_pinctrl_ops,
458 .pmxops = &pm8xxx_pinmux_ops,
459 .confops = &pm8xxx_pinconf_ops,
460 .owner = THIS_MODULE,
463 static int pm8xxx_gpio_direction_input(struct gpio_chip *chip,
466 struct pm8xxx_gpio *pctrl = gpiochip_get_data(chip);
467 struct pm8xxx_pin_data *pin = pctrl->desc.pins[offset].drv_data;
470 pin->mode = PM8XXX_GPIO_MODE_INPUT;
471 val = pin->mode << 2;
473 pm8xxx_write_bank(pctrl, pin, 1, val);
478 static int pm8xxx_gpio_direction_output(struct gpio_chip *chip,
482 struct pm8xxx_gpio *pctrl = gpiochip_get_data(chip);
483 struct pm8xxx_pin_data *pin = pctrl->desc.pins[offset].drv_data;
486 pin->mode = PM8XXX_GPIO_MODE_OUTPUT;
487 pin->output_value = !!value;
489 val = pin->mode << 2;
490 val |= pin->open_drain << 1;
491 val |= pin->output_value;
493 pm8xxx_write_bank(pctrl, pin, 1, val);
498 static int pm8xxx_gpio_get(struct gpio_chip *chip, unsigned offset)
500 struct pm8xxx_gpio *pctrl = gpiochip_get_data(chip);
501 struct pm8xxx_pin_data *pin = pctrl->desc.pins[offset].drv_data;
505 if (pin->mode == PM8XXX_GPIO_MODE_OUTPUT) {
506 ret = pin->output_value;
507 } else if (pin->irq >= 0) {
508 ret = irq_get_irqchip_state(pin->irq, IRQCHIP_STATE_LINE_LEVEL, &state);
517 static void pm8xxx_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
519 struct pm8xxx_gpio *pctrl = gpiochip_get_data(chip);
520 struct pm8xxx_pin_data *pin = pctrl->desc.pins[offset].drv_data;
523 pin->output_value = !!value;
525 val = pin->mode << 2;
526 val |= pin->open_drain << 1;
527 val |= pin->output_value;
529 pm8xxx_write_bank(pctrl, pin, 1, val);
532 static int pm8xxx_gpio_of_xlate(struct gpio_chip *chip,
533 const struct of_phandle_args *gpio_desc,
536 if (chip->of_gpio_n_cells < 2)
540 *flags = gpio_desc->args[1];
542 return gpio_desc->args[0] - PM8XXX_GPIO_PHYSICAL_OFFSET;
546 static int pm8xxx_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
548 struct pm8xxx_gpio *pctrl = gpiochip_get_data(chip);
549 struct pm8xxx_pin_data *pin = pctrl->desc.pins[offset].drv_data;
550 struct irq_fwspec fwspec;
553 fwspec.fwnode = pctrl->fwnode;
554 fwspec.param_count = 2;
555 fwspec.param[0] = offset + PM8XXX_GPIO_PHYSICAL_OFFSET;
556 fwspec.param[1] = IRQ_TYPE_EDGE_RISING;
558 ret = irq_create_fwspec_mapping(&fwspec);
561 * Cache the IRQ since pm8xxx_gpio_get() needs this to get determine the
569 static void pm8xxx_gpio_free(struct gpio_chip *chip, unsigned int offset)
571 struct pm8xxx_gpio *pctrl = gpiochip_get_data(chip);
572 struct pm8xxx_pin_data *pin = pctrl->desc.pins[offset].drv_data;
577 #ifdef CONFIG_DEBUG_FS
578 #include <linux/seq_file.h>
580 static void pm8xxx_gpio_dbg_show_one(struct seq_file *s,
581 struct pinctrl_dev *pctldev,
582 struct gpio_chip *chip,
586 struct pm8xxx_gpio *pctrl = gpiochip_get_data(chip);
587 struct pm8xxx_pin_data *pin = pctrl->desc.pins[offset].drv_data;
589 static const char * const modes[] = {
590 "in", "both", "out", "off"
592 static const char * const biases[] = {
593 "pull-up 30uA", "pull-up 1.5uA", "pull-up 31.5uA",
594 "pull-up 1.5uA + 30uA boost", "pull-down 10uA", "no pull"
596 static const char * const buffer_types[] = {
597 "push-pull", "open-drain"
599 static const char * const strengths[] = {
600 "no", "high", "medium", "low"
603 seq_printf(s, " gpio%-2d:", offset + PM8XXX_GPIO_PHYSICAL_OFFSET);
607 seq_printf(s, " %-4s", modes[pin->mode]);
608 seq_printf(s, " %-7s", pm8xxx_gpio_functions[pin->function]);
609 seq_printf(s, " VIN%d", pin->power_source);
610 seq_printf(s, " %-27s", biases[pin->bias]);
611 seq_printf(s, " %-10s", buffer_types[pin->open_drain]);
612 seq_printf(s, " %-4s", pin->output_value ? "high" : "low");
613 seq_printf(s, " %-7s", strengths[pin->output_strength]);
615 seq_puts(s, " inverted");
619 static void pm8xxx_gpio_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_gpio_dbg_show_one(s, NULL, chip, i, gpio);
631 #define pm8xxx_gpio_dbg_show NULL
634 static const struct gpio_chip pm8xxx_gpio_template = {
635 .free = pm8xxx_gpio_free,
636 .direction_input = pm8xxx_gpio_direction_input,
637 .direction_output = pm8xxx_gpio_direction_output,
638 .get = pm8xxx_gpio_get,
639 .set = pm8xxx_gpio_set,
640 .of_xlate = pm8xxx_gpio_of_xlate,
641 .to_irq = pm8xxx_gpio_to_irq,
642 .dbg_show = pm8xxx_gpio_dbg_show,
643 .owner = THIS_MODULE,
646 static int pm8xxx_pin_populate(struct pm8xxx_gpio *pctrl,
647 struct pm8xxx_pin_data *pin)
651 val = pm8xxx_read_bank(pctrl, pin, 0);
655 pin->power_source = (val >> 1) & 0x7;
657 val = pm8xxx_read_bank(pctrl, pin, 1);
661 pin->mode = (val >> 2) & 0x3;
662 pin->open_drain = !!(val & BIT(1));
663 pin->output_value = val & BIT(0);
665 val = pm8xxx_read_bank(pctrl, pin, 2);
669 pin->bias = (val >> 1) & 0x7;
670 if (pin->bias <= PM8XXX_GPIO_BIAS_PU_1P5_30)
671 pin->pull_up_strength = pin->bias;
673 pin->pull_up_strength = PM8XXX_GPIO_BIAS_PU_30;
675 val = pm8xxx_read_bank(pctrl, pin, 3);
679 pin->output_strength = (val >> 2) & 0x3;
680 pin->disable = val & BIT(0);
682 val = pm8xxx_read_bank(pctrl, pin, 4);
686 pin->function = (val >> 1) & 0x7;
688 val = pm8xxx_read_bank(pctrl, pin, 5);
692 pin->inverted = !(val & BIT(3));
697 static struct irq_chip pm8xxx_irq_chip = {
699 .irq_mask_ack = irq_chip_mask_ack_parent,
700 .irq_unmask = irq_chip_unmask_parent,
701 .irq_set_type = irq_chip_set_type_parent,
702 .flags = IRQCHIP_MASK_ON_SUSPEND | IRQCHIP_SKIP_SET_WAKE,
705 static int pm8xxx_domain_translate(struct irq_domain *domain,
706 struct irq_fwspec *fwspec,
707 unsigned long *hwirq,
710 struct pm8xxx_gpio *pctrl = container_of(domain->host_data,
711 struct pm8xxx_gpio, chip);
713 if (fwspec->param_count != 2 || fwspec->param[0] < 1 ||
714 fwspec->param[0] > pctrl->chip.ngpio)
717 *hwirq = fwspec->param[0] - PM8XXX_GPIO_PHYSICAL_OFFSET;
718 *type = fwspec->param[1];
723 static int pm8xxx_domain_alloc(struct irq_domain *domain, unsigned int virq,
724 unsigned int nr_irqs, void *data)
726 struct pm8xxx_gpio *pctrl = container_of(domain->host_data,
727 struct pm8xxx_gpio, chip);
728 struct irq_fwspec *fwspec = data;
729 struct irq_fwspec parent_fwspec;
730 irq_hw_number_t hwirq;
734 ret = pm8xxx_domain_translate(domain, fwspec, &hwirq, &type);
738 for (i = 0; i < nr_irqs; i++)
739 irq_domain_set_info(domain, virq + i, hwirq + i,
740 &pm8xxx_irq_chip, pctrl, handle_level_irq,
743 parent_fwspec.fwnode = domain->parent->fwnode;
744 parent_fwspec.param_count = 2;
745 parent_fwspec.param[0] = hwirq + 0xc0;
746 parent_fwspec.param[1] = fwspec->param[1];
748 return irq_domain_alloc_irqs_parent(domain, virq, nr_irqs,
752 static const struct irq_domain_ops pm8xxx_domain_ops = {
753 .activate = gpiochip_irq_domain_activate,
754 .alloc = pm8xxx_domain_alloc,
755 .deactivate = gpiochip_irq_domain_deactivate,
756 .free = irq_domain_free_irqs_common,
757 .translate = pm8xxx_domain_translate,
760 static const struct of_device_id pm8xxx_gpio_of_match[] = {
761 { .compatible = "qcom,pm8018-gpio", .data = (void *) 6 },
762 { .compatible = "qcom,pm8038-gpio", .data = (void *) 12 },
763 { .compatible = "qcom,pm8058-gpio", .data = (void *) 44 },
764 { .compatible = "qcom,pm8917-gpio", .data = (void *) 38 },
765 { .compatible = "qcom,pm8921-gpio", .data = (void *) 44 },
768 MODULE_DEVICE_TABLE(of, pm8xxx_gpio_of_match);
770 static int pm8xxx_gpio_probe(struct platform_device *pdev)
772 struct pm8xxx_pin_data *pin_data;
773 struct irq_domain *parent_domain;
774 struct device_node *parent_node;
775 struct pinctrl_pin_desc *pins;
776 struct pm8xxx_gpio *pctrl;
779 pctrl = devm_kzalloc(&pdev->dev, sizeof(*pctrl), GFP_KERNEL);
783 pctrl->dev = &pdev->dev;
784 pctrl->npins = (uintptr_t) device_get_match_data(&pdev->dev);
786 pctrl->regmap = dev_get_regmap(pdev->dev.parent, NULL);
787 if (!pctrl->regmap) {
788 dev_err(&pdev->dev, "parent regmap unavailable\n");
792 pctrl->desc = pm8xxx_pinctrl_desc;
793 pctrl->desc.npins = pctrl->npins;
795 pins = devm_kcalloc(&pdev->dev,
797 sizeof(struct pinctrl_pin_desc),
802 pin_data = devm_kcalloc(&pdev->dev,
804 sizeof(struct pm8xxx_pin_data),
809 for (i = 0; i < pctrl->desc.npins; i++) {
810 pin_data[i].reg = SSBI_REG_ADDR_GPIO(i);
811 pin_data[i].irq = -1;
813 ret = pm8xxx_pin_populate(pctrl, &pin_data[i]);
818 pins[i].name = pm8xxx_groups[i];
819 pins[i].drv_data = &pin_data[i];
821 pctrl->desc.pins = pins;
823 pctrl->desc.num_custom_params = ARRAY_SIZE(pm8xxx_gpio_bindings);
824 pctrl->desc.custom_params = pm8xxx_gpio_bindings;
825 #ifdef CONFIG_DEBUG_FS
826 pctrl->desc.custom_conf_items = pm8xxx_conf_items;
829 pctrl->pctrl = devm_pinctrl_register(&pdev->dev, &pctrl->desc, pctrl);
830 if (IS_ERR(pctrl->pctrl)) {
831 dev_err(&pdev->dev, "couldn't register pm8xxx gpio driver\n");
832 return PTR_ERR(pctrl->pctrl);
835 pctrl->chip = pm8xxx_gpio_template;
836 pctrl->chip.base = -1;
837 pctrl->chip.parent = &pdev->dev;
838 pctrl->chip.of_node = pdev->dev.of_node;
839 pctrl->chip.of_gpio_n_cells = 2;
840 pctrl->chip.label = dev_name(pctrl->dev);
841 pctrl->chip.ngpio = pctrl->npins;
843 parent_node = of_irq_find_parent(pctrl->dev->of_node);
847 parent_domain = irq_find_host(parent_node);
848 of_node_put(parent_node);
852 pctrl->fwnode = of_node_to_fwnode(pctrl->dev->of_node);
853 pctrl->domain = irq_domain_create_hierarchy(parent_domain, 0,
861 ret = gpiochip_add_data(&pctrl->chip, pctrl);
863 dev_err(&pdev->dev, "failed register gpiochip\n");
864 goto err_chip_add_data;
868 * For DeviceTree-supported systems, the gpio core checks the
869 * pinctrl's device node for the "gpio-ranges" property.
870 * If it is present, it takes care of adding the pin ranges
871 * for the driver. In this case the driver can skip ahead.
873 * In order to remain compatible with older, existing DeviceTree
874 * files which don't set the "gpio-ranges" property or systems that
875 * utilize ACPI the driver has to call gpiochip_add_pin_range().
877 if (!of_property_read_bool(pctrl->dev->of_node, "gpio-ranges")) {
878 ret = gpiochip_add_pin_range(&pctrl->chip, dev_name(pctrl->dev),
879 0, 0, pctrl->chip.ngpio);
881 dev_err(pctrl->dev, "failed to add pin range\n");
882 goto unregister_gpiochip;
886 platform_set_drvdata(pdev, pctrl);
888 dev_dbg(&pdev->dev, "Qualcomm pm8xxx gpio driver probed\n");
893 gpiochip_remove(&pctrl->chip);
895 irq_domain_remove(pctrl->domain);
900 static int pm8xxx_gpio_remove(struct platform_device *pdev)
902 struct pm8xxx_gpio *pctrl = platform_get_drvdata(pdev);
904 gpiochip_remove(&pctrl->chip);
905 irq_domain_remove(pctrl->domain);
910 static struct platform_driver pm8xxx_gpio_driver = {
912 .name = "qcom-ssbi-gpio",
913 .of_match_table = pm8xxx_gpio_of_match,
915 .probe = pm8xxx_gpio_probe,
916 .remove = pm8xxx_gpio_remove,
919 module_platform_driver(pm8xxx_gpio_driver);
921 MODULE_AUTHOR("Bjorn Andersson <bjorn.andersson@sonymobile.com>");
922 MODULE_DESCRIPTION("Qualcomm PM8xxx GPIO driver");
923 MODULE_LICENSE("GPL v2");