pinctrl: npcm7xx: Switch to use for_each_gpiochip_node() helper
Switch the code to use for_each_gpiochip_node() helper. While at it, in order to avoid additional churn in the future, do the following: - use a temporary variable for struct device pointer to shorten a few lines - get rid of a temporary variable for vIRQ number, assign it directly - switch to fwnode APIs where it makes sense Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
This commit is contained in:
parent
5e455dd933
commit
0173ce55e5
@ -17,6 +17,7 @@
|
||||
#include <linux/pinctrl/pinctrl.h>
|
||||
#include <linux/pinctrl/pinmux.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/property.h>
|
||||
#include <linux/regmap.h>
|
||||
|
||||
/* GCR registers */
|
||||
@ -1862,88 +1863,69 @@ static int npcm7xx_gpio_of(struct npcm7xx_pinctrl *pctrl)
|
||||
{
|
||||
int ret = -ENXIO;
|
||||
struct resource res;
|
||||
int id = 0, irq;
|
||||
struct device_node *np;
|
||||
struct of_phandle_args pinspec;
|
||||
struct device *dev = pctrl->dev;
|
||||
struct fwnode_reference_args args;
|
||||
struct fwnode_handle *child;
|
||||
int id = 0;
|
||||
|
||||
for_each_available_child_of_node(pctrl->dev->of_node, np)
|
||||
if (of_find_property(np, "gpio-controller", NULL)) {
|
||||
ret = of_address_to_resource(np, 0, &res);
|
||||
if (ret < 0) {
|
||||
dev_err(pctrl->dev,
|
||||
"Resource fail for GPIO bank %u\n", id);
|
||||
return ret;
|
||||
}
|
||||
for_each_gpiochip_node(dev, child) {
|
||||
struct device_node *np = to_of_node(child);
|
||||
|
||||
pctrl->gpio_bank[id].base =
|
||||
ioremap(res.start, resource_size(&res));
|
||||
|
||||
irq = irq_of_parse_and_map(np, 0);
|
||||
if (irq < 0) {
|
||||
dev_err(pctrl->dev,
|
||||
"No IRQ for GPIO bank %u\n", id);
|
||||
ret = irq;
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = bgpio_init(&pctrl->gpio_bank[id].gc,
|
||||
pctrl->dev, 4,
|
||||
pctrl->gpio_bank[id].base +
|
||||
NPCM7XX_GP_N_DIN,
|
||||
pctrl->gpio_bank[id].base +
|
||||
NPCM7XX_GP_N_DOUT,
|
||||
NULL,
|
||||
NULL,
|
||||
pctrl->gpio_bank[id].base +
|
||||
NPCM7XX_GP_N_IEM,
|
||||
BGPIOF_READ_OUTPUT_REG_SET);
|
||||
if (ret) {
|
||||
dev_err(pctrl->dev, "bgpio_init() failed\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = of_parse_phandle_with_fixed_args(np,
|
||||
"gpio-ranges", 3,
|
||||
0, &pinspec);
|
||||
if (ret < 0) {
|
||||
dev_err(pctrl->dev,
|
||||
"gpio-ranges fail for GPIO bank %u\n",
|
||||
id);
|
||||
return ret;
|
||||
}
|
||||
|
||||
pctrl->gpio_bank[id].irq = irq;
|
||||
pctrl->gpio_bank[id].irq_chip = npcmgpio_irqchip;
|
||||
pctrl->gpio_bank[id].gc.parent = pctrl->dev;
|
||||
pctrl->gpio_bank[id].irqbase =
|
||||
id * NPCM7XX_GPIO_PER_BANK;
|
||||
pctrl->gpio_bank[id].pinctrl_id = pinspec.args[0];
|
||||
pctrl->gpio_bank[id].gc.base = pinspec.args[1];
|
||||
pctrl->gpio_bank[id].gc.ngpio = pinspec.args[2];
|
||||
pctrl->gpio_bank[id].gc.owner = THIS_MODULE;
|
||||
pctrl->gpio_bank[id].gc.label =
|
||||
devm_kasprintf(pctrl->dev, GFP_KERNEL, "%pOF",
|
||||
np);
|
||||
if (pctrl->gpio_bank[id].gc.label == NULL)
|
||||
return -ENOMEM;
|
||||
|
||||
pctrl->gpio_bank[id].gc.dbg_show = npcmgpio_dbg_show;
|
||||
pctrl->gpio_bank[id].direction_input =
|
||||
pctrl->gpio_bank[id].gc.direction_input;
|
||||
pctrl->gpio_bank[id].gc.direction_input =
|
||||
npcmgpio_direction_input;
|
||||
pctrl->gpio_bank[id].direction_output =
|
||||
pctrl->gpio_bank[id].gc.direction_output;
|
||||
pctrl->gpio_bank[id].gc.direction_output =
|
||||
npcmgpio_direction_output;
|
||||
pctrl->gpio_bank[id].request =
|
||||
pctrl->gpio_bank[id].gc.request;
|
||||
pctrl->gpio_bank[id].gc.request = npcmgpio_gpio_request;
|
||||
pctrl->gpio_bank[id].gc.free = npcmgpio_gpio_free;
|
||||
pctrl->gpio_bank[id].gc.of_node = np;
|
||||
id++;
|
||||
ret = of_address_to_resource(np, 0, &res);
|
||||
if (ret < 0) {
|
||||
dev_err(dev, "Resource fail for GPIO bank %u\n", id);
|
||||
return ret;
|
||||
}
|
||||
|
||||
pctrl->gpio_bank[id].base = ioremap(res.start, resource_size(&res));
|
||||
|
||||
ret = bgpio_init(&pctrl->gpio_bank[id].gc, dev, 4,
|
||||
pctrl->gpio_bank[id].base + NPCM7XX_GP_N_DIN,
|
||||
pctrl->gpio_bank[id].base + NPCM7XX_GP_N_DOUT,
|
||||
NULL,
|
||||
NULL,
|
||||
pctrl->gpio_bank[id].base + NPCM7XX_GP_N_IEM,
|
||||
BGPIOF_READ_OUTPUT_REG_SET);
|
||||
if (ret) {
|
||||
dev_err(dev, "bgpio_init() failed\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = fwnode_property_get_reference_args(child, "gpio-ranges", NULL, 3, 0, &args);
|
||||
if (ret < 0) {
|
||||
dev_err(dev, "gpio-ranges fail for GPIO bank %u\n", id);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = irq_of_parse_and_map(np, 0);
|
||||
if (ret < 0) {
|
||||
dev_err(dev, "No IRQ for GPIO bank %u\n", id);
|
||||
return ret;
|
||||
}
|
||||
pctrl->gpio_bank[id].irq = ret;
|
||||
pctrl->gpio_bank[id].irq_chip = npcmgpio_irqchip;
|
||||
pctrl->gpio_bank[id].irqbase = id * NPCM7XX_GPIO_PER_BANK;
|
||||
pctrl->gpio_bank[id].pinctrl_id = args.args[0];
|
||||
pctrl->gpio_bank[id].gc.base = args.args[1];
|
||||
pctrl->gpio_bank[id].gc.ngpio = args.args[2];
|
||||
pctrl->gpio_bank[id].gc.owner = THIS_MODULE;
|
||||
pctrl->gpio_bank[id].gc.parent = dev;
|
||||
pctrl->gpio_bank[id].gc.fwnode = child;
|
||||
pctrl->gpio_bank[id].gc.label = devm_kasprintf(dev, GFP_KERNEL, "%pfw", child);
|
||||
if (pctrl->gpio_bank[id].gc.label == NULL)
|
||||
return -ENOMEM;
|
||||
|
||||
pctrl->gpio_bank[id].gc.dbg_show = npcmgpio_dbg_show;
|
||||
pctrl->gpio_bank[id].direction_input = pctrl->gpio_bank[id].gc.direction_input;
|
||||
pctrl->gpio_bank[id].gc.direction_input = npcmgpio_direction_input;
|
||||
pctrl->gpio_bank[id].direction_output = pctrl->gpio_bank[id].gc.direction_output;
|
||||
pctrl->gpio_bank[id].gc.direction_output = npcmgpio_direction_output;
|
||||
pctrl->gpio_bank[id].request = pctrl->gpio_bank[id].gc.request;
|
||||
pctrl->gpio_bank[id].gc.request = npcmgpio_gpio_request;
|
||||
pctrl->gpio_bank[id].gc.free = npcmgpio_gpio_free;
|
||||
id++;
|
||||
}
|
||||
|
||||
pctrl->bank_num = id;
|
||||
return ret;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user