Skip to content

Commit ae436fe

Browse files
masneybLinus Walleij
authored andcommitted
pinctrl: ssbi-gpio: convert to hierarchical IRQ helpers in gpio core
Now that the GPIO core has support for hierarchical IRQ chips, convert Qualcomm's ssbi-gpio over to use these new helpers to reduce duplicated code across drivers. Signed-off-by: Brian Masney <masneyb@onstation.org> Link: https://lore.kernel.org/r/20190914111010.24384-1-masneyb@onstation.org Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
1 parent be4c60b commit ae436fe

2 files changed

Lines changed: 34 additions & 88 deletions

File tree

‎drivers/pinctrl/qcom/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ config PINCTRL_QCOM_SSBI_PMIC
152152
select PINMUX
153153
select PINCONF
154154
select GENERIC_PINCONF
155+
select GPIOLIB_IRQCHIP
155156
select IRQ_DOMAIN_HIERARCHY
156157
help
157158
This is the pinctrl, pinmux, pinconf and gpiolib driver for the

‎drivers/pinctrl/qcom/pinctrl-ssbi-gpio.c‎

Lines changed: 33 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
/**
5757
* struct pm8xxx_pin_data - dynamic configuration for a pin
5858
* @reg: address of the control register
59-
* @irq: IRQ from the PMIC interrupt controller
6059
* @power_source: logical selected voltage source, mapping in static data
6160
* is used translate to register values
6261
* @mode: operating mode for the pin (input/output)
@@ -72,7 +71,6 @@
7271
*/
7372
struct pm8xxx_pin_data {
7473
unsigned reg;
75-
int irq;
7674
u8 power_source;
7775
u8 mode;
7876
bool open_drain;
@@ -93,9 +91,6 @@ struct pm8xxx_gpio {
9391

9492
struct pinctrl_desc desc;
9593
unsigned npins;
96-
97-
struct fwnode_handle *fwnode;
98-
struct irq_domain *domain;
9994
};
10095

10196
static const struct pinconf_generic_params pm8xxx_gpio_bindings[] = {
@@ -491,13 +486,16 @@ static int pm8xxx_gpio_get(struct gpio_chip *chip, unsigned offset)
491486
{
492487
struct pm8xxx_gpio *pctrl = gpiochip_get_data(chip);
493488
struct pm8xxx_pin_data *pin = pctrl->desc.pins[offset].drv_data;
489+
int ret, irq;
494490
bool state;
495-
int ret;
496491

497-
if (pin->mode == PM8XXX_GPIO_MODE_OUTPUT) {
498-
ret = pin->output_value;
499-
} else if (pin->irq >= 0) {
500-
ret = irq_get_irqchip_state(pin->irq, IRQCHIP_STATE_LINE_LEVEL, &state);
492+
if (pin->mode == PM8XXX_GPIO_MODE_OUTPUT)
493+
return pin->output_value;
494+
495+
irq = chip->to_irq(chip, offset);
496+
if (irq >= 0) {
497+
ret = irq_get_irqchip_state(irq, IRQCHIP_STATE_LINE_LEVEL,
498+
&state);
501499
if (!ret)
502500
ret = !!state;
503501
} else
@@ -535,37 +533,6 @@ static int pm8xxx_gpio_of_xlate(struct gpio_chip *chip,
535533
}
536534

537535

538-
static int pm8xxx_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
539-
{
540-
struct pm8xxx_gpio *pctrl = gpiochip_get_data(chip);
541-
struct pm8xxx_pin_data *pin = pctrl->desc.pins[offset].drv_data;
542-
struct irq_fwspec fwspec;
543-
int ret;
544-
545-
fwspec.fwnode = pctrl->fwnode;
546-
fwspec.param_count = 2;
547-
fwspec.param[0] = offset + PM8XXX_GPIO_PHYSICAL_OFFSET;
548-
fwspec.param[1] = IRQ_TYPE_EDGE_RISING;
549-
550-
ret = irq_create_fwspec_mapping(&fwspec);
551-
552-
/*
553-
* Cache the IRQ since pm8xxx_gpio_get() needs this to get determine the
554-
* line level.
555-
*/
556-
pin->irq = ret;
557-
558-
return ret;
559-
}
560-
561-
static void pm8xxx_gpio_free(struct gpio_chip *chip, unsigned int offset)
562-
{
563-
struct pm8xxx_gpio *pctrl = gpiochip_get_data(chip);
564-
struct pm8xxx_pin_data *pin = pctrl->desc.pins[offset].drv_data;
565-
566-
pin->irq = -1;
567-
}
568-
569536
#ifdef CONFIG_DEBUG_FS
570537
#include <linux/seq_file.h>
571538

@@ -624,13 +591,11 @@ static void pm8xxx_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip)
624591
#endif
625592

626593
static const struct gpio_chip pm8xxx_gpio_template = {
627-
.free = pm8xxx_gpio_free,
628594
.direction_input = pm8xxx_gpio_direction_input,
629595
.direction_output = pm8xxx_gpio_direction_output,
630596
.get = pm8xxx_gpio_get,
631597
.set = pm8xxx_gpio_set,
632598
.of_xlate = pm8xxx_gpio_of_xlate,
633-
.to_irq = pm8xxx_gpio_to_irq,
634599
.dbg_show = pm8xxx_gpio_dbg_show,
635600
.owner = THIS_MODULE,
636601
};
@@ -712,43 +677,24 @@ static int pm8xxx_domain_translate(struct irq_domain *domain,
712677
return 0;
713678
}
714679

715-
static int pm8xxx_domain_alloc(struct irq_domain *domain, unsigned int virq,
716-
unsigned int nr_irqs, void *data)
680+
static unsigned int pm8xxx_child_offset_to_irq(struct gpio_chip *chip,
681+
unsigned int offset)
717682
{
718-
struct pm8xxx_gpio *pctrl = container_of(domain->host_data,
719-
struct pm8xxx_gpio, chip);
720-
struct irq_fwspec *fwspec = data;
721-
struct irq_fwspec parent_fwspec;
722-
irq_hw_number_t hwirq;
723-
unsigned int type;
724-
int ret, i;
725-
726-
ret = pm8xxx_domain_translate(domain, fwspec, &hwirq, &type);
727-
if (ret)
728-
return ret;
729-
730-
for (i = 0; i < nr_irqs; i++)
731-
irq_domain_set_info(domain, virq + i, hwirq + i,
732-
&pm8xxx_irq_chip, pctrl, handle_level_irq,
733-
NULL, NULL);
683+
return offset + PM8XXX_GPIO_PHYSICAL_OFFSET;
684+
}
734685

735-
parent_fwspec.fwnode = domain->parent->fwnode;
736-
parent_fwspec.param_count = 2;
737-
parent_fwspec.param[0] = hwirq + 0xc0;
738-
parent_fwspec.param[1] = fwspec->param[1];
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)
691+
{
692+
*parent_hwirq = child_hwirq + 0xc0;
693+
*parent_type = child_type;
739694

740-
return irq_domain_alloc_irqs_parent(domain, virq, nr_irqs,
741-
&parent_fwspec);
695+
return 0;
742696
}
743697

744-
static const struct irq_domain_ops pm8xxx_domain_ops = {
745-
.activate = gpiochip_irq_domain_activate,
746-
.alloc = pm8xxx_domain_alloc,
747-
.deactivate = gpiochip_irq_domain_deactivate,
748-
.free = irq_domain_free_irqs_common,
749-
.translate = pm8xxx_domain_translate,
750-
};
751-
752698
static const struct of_device_id pm8xxx_gpio_of_match[] = {
753699
{ .compatible = "qcom,pm8018-gpio", .data = (void *) 6 },
754700
{ .compatible = "qcom,pm8038-gpio", .data = (void *) 12 },
@@ -765,6 +711,7 @@ static int pm8xxx_gpio_probe(struct platform_device *pdev)
765711
struct irq_domain *parent_domain;
766712
struct device_node *parent_node;
767713
struct pinctrl_pin_desc *pins;
714+
struct gpio_irq_chip *girq;
768715
struct pm8xxx_gpio *pctrl;
769716
int ret, i;
770717

@@ -800,7 +747,6 @@ static int pm8xxx_gpio_probe(struct platform_device *pdev)
800747

801748
for (i = 0; i < pctrl->desc.npins; i++) {
802749
pin_data[i].reg = SSBI_REG_ADDR_GPIO(i);
803-
pin_data[i].irq = -1;
804750

805751
ret = pm8xxx_pin_populate(pctrl, &pin_data[i]);
806752
if (ret)
@@ -841,19 +787,21 @@ static int pm8xxx_gpio_probe(struct platform_device *pdev)
841787
if (!parent_domain)
842788
return -ENXIO;
843789

844-
pctrl->fwnode = of_node_to_fwnode(pctrl->dev->of_node);
845-
pctrl->domain = irq_domain_create_hierarchy(parent_domain, 0,
846-
pctrl->chip.ngpio,
847-
pctrl->fwnode,
848-
&pm8xxx_domain_ops,
849-
&pctrl->chip);
850-
if (!pctrl->domain)
851-
return -ENODEV;
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_fwspec = gpiochip_populate_parent_fwspec_fourcell;
798+
girq->child_offset_to_irq = pm8xxx_child_offset_to_irq;
799+
girq->child_irq_domain_ops.translate = pm8xxx_domain_translate;
852800

853801
ret = gpiochip_add_data(&pctrl->chip, pctrl);
854802
if (ret) {
855803
dev_err(&pdev->dev, "failed register gpiochip\n");
856-
goto err_chip_add_data;
804+
return ret;
857805
}
858806

859807
/*
@@ -883,8 +831,6 @@ static int pm8xxx_gpio_probe(struct platform_device *pdev)
883831

884832
unregister_gpiochip:
885833
gpiochip_remove(&pctrl->chip);
886-
err_chip_add_data:
887-
irq_domain_remove(pctrl->domain);
888834

889835
return ret;
890836
}
@@ -894,7 +840,6 @@ static int pm8xxx_gpio_remove(struct platform_device *pdev)
894840
struct pm8xxx_gpio *pctrl = platform_get_drvdata(pdev);
895841

896842
gpiochip_remove(&pctrl->chip);
897-
irq_domain_remove(pctrl->domain);
898843

899844
return 0;
900845
}

0 commit comments

Comments
 (0)