gpio: dwapb: Split out dwapb_get_irq() helper
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Wed, 15 Apr 2020 14:15:32 +0000 (17:15 +0300)
committerLinus Walleij <linus.walleij@linaro.org>
Fri, 17 Apr 2020 10:30:06 +0000 (12:30 +0200)
Split out dwapb_get_irq() helper for better readability and maintenance.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Tested-by: Serge Semin <fancer.lancer@gmail.com>
Reviewed-by: Serge Semin <fancer.lancer@gmail.com>
Link: https://lore.kernel.org/r/20200415141534.31240-13-andriy.shevchenko@linux.intel.com
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
drivers/gpio/gpio-dwapb.c

index 98e1ffc..31d29ec 100644 (file)
@@ -528,14 +528,38 @@ static void dwapb_gpio_unregister(struct dwapb_gpio *gpio)
                        gpiochip_remove(&gpio->ports[m].gc);
 }
 
-static struct dwapb_platform_data *
-dwapb_gpio_get_pdata(struct device *dev)
+static void dwapb_get_irq(struct device *dev, struct fwnode_handle *fwnode,
+                         struct dwapb_port_property *pp)
+{
+       struct device_node *np = NULL;
+       int j;
+
+       if (fwnode_property_read_bool(fwnode, "interrupt-controller"))
+               np = to_of_node(fwnode);
+
+       for (j = 0; j < pp->ngpio; j++) {
+               pp->irq[j] = -ENXIO;
+
+               if (np)
+                       pp->irq[j] = of_irq_get(np, j);
+               else if (has_acpi_companion(dev))
+                       pp->irq[j] = platform_get_irq(to_platform_device(dev), j);
+
+               if (pp->irq[j] >= 0)
+                       pp->has_irq = true;
+       }
+
+       if (!pp->has_irq)
+               dev_warn(dev, "no irq for port%d\n", pp->idx);
+}
+
+static struct dwapb_platform_data *dwapb_gpio_get_pdata(struct device *dev)
 {
        struct fwnode_handle *fwnode;
        struct dwapb_platform_data *pdata;
        struct dwapb_port_property *pp;
        int nports;
-       int i, j;
+       int i;
 
        nports = device_get_child_node_count(dev);
        if (nports == 0)
@@ -553,8 +577,6 @@ dwapb_gpio_get_pdata(struct device *dev)
 
        i = 0;
        device_for_each_child_node(dev, fwnode)  {
-               struct device_node *np = NULL;
-
                pp = &pdata->properties[i++];
                pp->fwnode = fwnode;
 
@@ -581,28 +603,8 @@ dwapb_gpio_get_pdata(struct device *dev)
                 * Only port A can provide interrupts in all configurations of
                 * the IP.
                 */
-               if (pp->idx != 0)
-                       continue;
-
-               if (dev->of_node && fwnode_property_read_bool(fwnode,
-                                                 "interrupt-controller")) {
-                       np = to_of_node(fwnode);
-               }
-
-               for (j = 0; j < pp->ngpio; j++) {
-                       pp->irq[j] = -ENXIO;
-
-                       if (np)
-                               pp->irq[j] = of_irq_get(np, j);
-                       else if (has_acpi_companion(dev))
-                               pp->irq[j] = platform_get_irq(to_platform_device(dev), j);
-
-                       if (pp->irq[j] >= 0)
-                               pp->has_irq = true;
-               }
-
-               if (!pp->has_irq)
-                       dev_warn(dev, "no irq for port%d\n", pp->idx);
+               if (pp->idx == 0)
+                       dwapb_get_irq(dev, fwnode, pp);
        }
 
        return pdata;