Skip to content

Commit

Permalink
drivers/gpio: gpio-nomadik: Apply Device Tree bindings
Browse files Browse the repository at this point in the history
This creates Device Tree bindings for the Nomadik GPIO driver.

Acked-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
  • Loading branch information
Lee Jones authored and Linus Walleij committed Apr 24, 2012
1 parent 1baa574 commit 513c27f
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
12 changes: 12 additions & 0 deletions arch/arm/mach-ux500/board-mop500.c
Original file line number Diff line number Diff line change
Expand Up @@ -746,10 +746,22 @@ MACHINE_END
#ifdef CONFIG_MACH_UX500_DT

struct of_dev_auxdata u8500_auxdata_lookup[] __initdata = {
/* Requires DMA and call-back bindings. */
OF_DEV_AUXDATA("arm,pl011", 0x80120000, "uart0", &uart0_plat),
OF_DEV_AUXDATA("arm,pl011", 0x80121000, "uart1", &uart1_plat),
OF_DEV_AUXDATA("arm,pl011", 0x80007000, "uart2", &uart2_plat),
/* Requires DMA bindings. */
OF_DEV_AUXDATA("arm,pl022", 0x80002000, "ssp0", &ssp0_plat),
/* Requires clock name bindings. */
OF_DEV_AUXDATA("st,nomadik-gpio", 0x8012e000, "gpio.0", NULL),
OF_DEV_AUXDATA("st,nomadik-gpio", 0x8012e080, "gpio.1", NULL),
OF_DEV_AUXDATA("st,nomadik-gpio", 0x8000e000, "gpio.2", NULL),
OF_DEV_AUXDATA("st,nomadik-gpio", 0x8000e080, "gpio.3", NULL),
OF_DEV_AUXDATA("st,nomadik-gpio", 0x8000e100, "gpio.4", NULL),
OF_DEV_AUXDATA("st,nomadik-gpio", 0x8000e180, "gpio.5", NULL),
OF_DEV_AUXDATA("st,nomadik-gpio", 0x8011e000, "gpio.6", NULL),
OF_DEV_AUXDATA("st,nomadik-gpio", 0x8011e080, "gpio.7", NULL),
OF_DEV_AUXDATA("st,nomadik-gpio", 0xa03fe000, "gpio.8", NULL),
{},
};

Expand Down
41 changes: 38 additions & 3 deletions drivers/gpio/gpio-nomadik.c
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,7 @@ void nmk_gpio_read_pull(int gpio_bank, u32 *pull_up)
static int __devinit nmk_gpio_probe(struct platform_device *dev)
{
struct nmk_gpio_platform_data *pdata = dev->dev.platform_data;
struct device_node *np = dev->dev.of_node;
struct nmk_gpio_chip *nmk_chip;
struct gpio_chip *chip;
struct resource *res;
Expand All @@ -1141,8 +1142,28 @@ static int __devinit nmk_gpio_probe(struct platform_device *dev)
int irq;
int ret;

if (!pdata)
if (!pdata && !np) {
dev_err(&dev->dev, "No platform data or device tree found\n");
return -ENODEV;
}

if (np) {
pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
if (!pdata)
return -ENOMEM;

if (of_get_property(np, "supports-sleepmode", NULL))
pdata->supports_sleepmode = true;

if (of_property_read_u32(np, "gpio-bank", &dev->id)) {
dev_err(&dev->dev, "gpio-bank property not found\n");
ret = -EINVAL;
goto out_dt;
}

pdata->first_gpio = dev->id * NMK_GPIO_PER_CHIP;
pdata->num_gpio = NMK_GPIO_PER_CHIP;
}

res = platform_get_resource(dev, IORESOURCE_MEM, 0);
if (!res) {
Expand Down Expand Up @@ -1185,6 +1206,7 @@ static int __devinit nmk_gpio_probe(struct platform_device *dev)
ret = -ENOMEM;
goto out_clk;
}

/*
* The virt address in nmk_chip->addr is in the nomadik register space,
* so we can simply convert the resource address, without remapping
Expand All @@ -1211,19 +1233,22 @@ static int __devinit nmk_gpio_probe(struct platform_device *dev)
nmk_chip->lowemi = readl_relaxed(nmk_chip->addr + NMK_GPIO_LOWEMI);
clk_disable(nmk_chip->clk);

chip->of_node = np;

ret = gpiochip_add(&nmk_chip->chip);
if (ret)
goto out_free;

BUG_ON(nmk_chip->bank >= ARRAY_SIZE(nmk_gpio_chips));

nmk_gpio_chips[nmk_chip->bank] = nmk_chip;

platform_set_drvdata(dev, nmk_chip);

nmk_gpio_init_irq(nmk_chip);

dev_info(&dev->dev, "at address %p\n",
nmk_chip->addr);
dev_info(&dev->dev, "at address %p\n", nmk_chip->addr);

return 0;

out_free:
Expand All @@ -1238,13 +1263,23 @@ static int __devinit nmk_gpio_probe(struct platform_device *dev)
out:
dev_err(&dev->dev, "Failure %i for GPIO %i-%i\n", ret,
pdata->first_gpio, pdata->first_gpio+31);
out_dt:
if (np)
kfree(pdata);

return ret;
}

static const struct of_device_id nmk_gpio_match[] = {
{ .compatible = "st,nomadik-gpio", },
{}
};

static struct platform_driver nmk_gpio_driver = {
.driver = {
.owner = THIS_MODULE,
.name = "gpio",
.of_match_table = nmk_gpio_match,
},
.probe = nmk_gpio_probe,
};
Expand Down

0 comments on commit 513c27f

Please sign in to comment.