From: jamie@jamieiles.com (Jamie Iles)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 3/6] ARM: at91/gpio: add DT support
Date: Fri, 16 Dec 2011 10:11:47 +0000 [thread overview]
Message-ID: <20111216101147.GA3230@totoro> (raw)
In-Reply-To: <876f676ec80d2db927e379654be76171ca496422.1323975517.git.nicolas.ferre@atmel.com>
Hi Nicolas, Jean-Christophe,
This looks pretty good to me, but a couple of minor comments inline.
Jamie
On Thu, Dec 15, 2011 at 08:16:05PM +0100, Nicolas Ferre wrote:
> From: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
>
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> Signed-off-by: Nicolas Ferre <nicolas.ferre@atmel.com>
> ---
[...]
> diff --git a/arch/arm/mach-at91/gpio.c b/arch/arm/mach-at91/gpio.c
> index 7ffb893..edb453a 100644
> --- a/arch/arm/mach-at91/gpio.c
> +++ b/arch/arm/mach-at91/gpio.c
> @@ -21,6 +21,7 @@
> #include <linux/module.h>
> #include <linux/io.h>
> #include <linux/irqdomain.h>
> +#include <linux/of_address.h>
>
> #include <mach/hardware.h>
> #include <mach/at91_pio.h>
> @@ -624,40 +625,122 @@ static void at91_gpiolib_dbg_show(struct seq_file *s, struct gpio_chip *chip)
> }
> }
>
> +#ifdef CONFIG_OF_GPIO
> +static void __init of_at91_gpio_init_one(struct device_node *np)
> +{
> + int alias_id;
> + struct at91_gpio_chip *at91_gpio;
> + const unsigned int *intspec;
> +
> + if (!np)
> + return;
> +
> + alias_id = of_alias_get_id(np, "gpio");
> + if (alias_id >= MAX_GPIO_BANKS) {
> + pr_err("at91_gpio, failed alias id(%d) > MAX_GPIO_BANKS(%d), ignoring.\n",
> + alias_id, MAX_GPIO_BANKS);
> + return;
> + }
> +
> + at91_gpio = &gpio_chip[alias_id];
> + at91_gpio->chip.base = alias_id * at91_gpio->chip.ngpio;
> +
> + at91_gpio->regbase = of_iomap(np, 0);
> + if (!at91_gpio->regbase) {
> + pr_err("at91_gpio.%d, failed to map registers, ignoring.\n",
> + alias_id);
> + return;
> + }
> +
> + /* Get the interrupts property */
> + intspec = of_get_property(np, "interrupts", NULL);
> + BUG_ON(!intspec);
> + at91_gpio->id = be32_to_cpup(intspec);
Use of_property_read_u32()? Also, BUG_ON() seems a bit harsh, better to
print a warning and return an error.
> +
> + at91_gpio->clock = clk_get_sys(NULL, at91_gpio->chip.label);
> + if (!at91_gpio->clock) {
> + pr_err("at91_gpio.%d, failed to get clock, ignoring.\n",
> + alias_id);
> + return;
Perhaps unmap the regs here?
> + }
> +
> + /* enable PIO controller's clock */
> + clk_enable(at91_gpio->clock);
Missing return value check.
> +
> + at91_gpio->chip.of_node = np;
> + gpio_banks = max(gpio_banks, alias_id + 1);
> +}
> +
> +static int __init of_at91_gpio_init(void)
> +{
> + struct device_node *np = NULL;
> +
> + /*
> + * This isn't ideal, but it gets things hooked up until this
> + * driver is converted into a platform_device
> + */
> + do {
> + np = of_find_compatible_node(np, NULL, "atmel,at91rm9200-gpio");
> +
> + of_at91_gpio_init_one(np);
> + } while (np);
for_each_compatible_node9)?
> +
> + return gpio_banks > 0 ? 0 : -EINVAL;
> +}
> +#else
> +static int __init of_at91_gpio_init(void)
> +{
> + return -EINVAL;
> +}
> +#endif
> +
> +static void __init at91_gpio_init_one(int i, u32 regbase, int id)
> +{
> + struct at91_gpio_chip *at91_gpio = &gpio_chip[i];
> +
> + at91_gpio->chip.base = i * at91_gpio->chip.ngpio;
> + at91_gpio->id = id;
> +
> + at91_gpio->regbase = ioremap(regbase, 512);
> + if (!at91_gpio->regbase) {
> + pr_err("at91_gpio.%d, failed to map registers, ignoring.\n", i);
> + return;
> + }
> +
> + at91_gpio->clock = clk_get_sys(NULL, at91_gpio->chip.label);
> + if (!at91_gpio->clock) {
> + pr_err("at91_gpio.%d, failed to get clock, ignoring.\n", i);
> + return;
> + }
> +
> + /* enable PIO controller's clock */
> + clk_enable(at91_gpio->clock);
Missing return value check?
> + gpio_banks = max(gpio_banks, i + 1);
> +}
> +
> /*
> * Called from the processor-specific init to enable GPIO pin support.
> */
> void __init at91_gpio_init(struct at91_gpio_bank *data, int nr_banks)
> {
> - unsigned i;
> + unsigned i;
> struct at91_gpio_chip *at91_gpio, *last = NULL;
>
> BUG_ON(nr_banks > MAX_GPIO_BANKS);
>
> - gpio_banks = nr_banks;
> + if (of_at91_gpio_init() < 0) {
> + /* no GPIO controller found in device tree */
> + for (i = 0; i < nr_banks; i++)
> + at91_gpio_init_one(i, data[i].regbase, data[i].id);
> + }
>
> - for (i = 0; i < nr_banks; i++) {
> + for (i = 0; i < gpio_banks; i++) {
> at91_gpio = &gpio_chip[i];
>
> - at91_gpio->id = data[i].id;
> - at91_gpio->chip.base = i * 32;
> -
> - at91_gpio->regbase = ioremap(data[i].regbase, 512);
> - if (!at91_gpio->regbase) {
> - pr_err("at91_gpio.%d, failed to map registers, ignoring.\n", i);
> - continue;
> - }
> -
> - at91_gpio->clock = clk_get_sys(NULL, at91_gpio->chip.label);
> - if (!at91_gpio->clock) {
> - pr_err("at91_gpio.%d, failed to get clock, ignoring.\n", i);
> - continue;
> - }
> -
> - /* enable PIO controller's clock */
> - clk_enable(at91_gpio->clock);
> -
> - /* AT91SAM9263_ID_PIOCDE groups PIOC, PIOD, PIOE */
> + /*
> + * GPIO controller are grouped on some SoC:
> + * PIOC, PIOD and PIOE can share the same IRQ line
> + */
> if (last && last->id == at91_gpio->id)
> last->next = at91_gpio;
> last = at91_gpio;
> --
> 1.7.5.4
>
WARNING: multiple messages have this Message-ID (diff)
From: Jamie Iles <jamie-wmLquQDDieKakBO8gow8eQ@public.gmane.org>
To: Nicolas Ferre <nicolas.ferre-AIFe0yeh4nAAvxtiuMwx3w@public.gmane.org>
Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org,
tglx-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
Subject: Re: [PATCH 3/6] ARM: at91/gpio: add DT support
Date: Fri, 16 Dec 2011 10:11:47 +0000 [thread overview]
Message-ID: <20111216101147.GA3230@totoro> (raw)
In-Reply-To: <876f676ec80d2db927e379654be76171ca496422.1323975517.git.nicolas.ferre-AIFe0yeh4nAAvxtiuMwx3w@public.gmane.org>
Hi Nicolas, Jean-Christophe,
This looks pretty good to me, but a couple of minor comments inline.
Jamie
On Thu, Dec 15, 2011 at 08:16:05PM +0100, Nicolas Ferre wrote:
> From: Jean-Christophe PLAGNIOL-VILLARD <plagnioj-sclMFOaUSTBWk0Htik3J/w@public.gmane.org>
>
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj-sclMFOaUSTBWk0Htik3J/w@public.gmane.org>
> Signed-off-by: Nicolas Ferre <nicolas.ferre-AIFe0yeh4nAAvxtiuMwx3w@public.gmane.org>
> ---
[...]
> diff --git a/arch/arm/mach-at91/gpio.c b/arch/arm/mach-at91/gpio.c
> index 7ffb893..edb453a 100644
> --- a/arch/arm/mach-at91/gpio.c
> +++ b/arch/arm/mach-at91/gpio.c
> @@ -21,6 +21,7 @@
> #include <linux/module.h>
> #include <linux/io.h>
> #include <linux/irqdomain.h>
> +#include <linux/of_address.h>
>
> #include <mach/hardware.h>
> #include <mach/at91_pio.h>
> @@ -624,40 +625,122 @@ static void at91_gpiolib_dbg_show(struct seq_file *s, struct gpio_chip *chip)
> }
> }
>
> +#ifdef CONFIG_OF_GPIO
> +static void __init of_at91_gpio_init_one(struct device_node *np)
> +{
> + int alias_id;
> + struct at91_gpio_chip *at91_gpio;
> + const unsigned int *intspec;
> +
> + if (!np)
> + return;
> +
> + alias_id = of_alias_get_id(np, "gpio");
> + if (alias_id >= MAX_GPIO_BANKS) {
> + pr_err("at91_gpio, failed alias id(%d) > MAX_GPIO_BANKS(%d), ignoring.\n",
> + alias_id, MAX_GPIO_BANKS);
> + return;
> + }
> +
> + at91_gpio = &gpio_chip[alias_id];
> + at91_gpio->chip.base = alias_id * at91_gpio->chip.ngpio;
> +
> + at91_gpio->regbase = of_iomap(np, 0);
> + if (!at91_gpio->regbase) {
> + pr_err("at91_gpio.%d, failed to map registers, ignoring.\n",
> + alias_id);
> + return;
> + }
> +
> + /* Get the interrupts property */
> + intspec = of_get_property(np, "interrupts", NULL);
> + BUG_ON(!intspec);
> + at91_gpio->id = be32_to_cpup(intspec);
Use of_property_read_u32()? Also, BUG_ON() seems a bit harsh, better to
print a warning and return an error.
> +
> + at91_gpio->clock = clk_get_sys(NULL, at91_gpio->chip.label);
> + if (!at91_gpio->clock) {
> + pr_err("at91_gpio.%d, failed to get clock, ignoring.\n",
> + alias_id);
> + return;
Perhaps unmap the regs here?
> + }
> +
> + /* enable PIO controller's clock */
> + clk_enable(at91_gpio->clock);
Missing return value check.
> +
> + at91_gpio->chip.of_node = np;
> + gpio_banks = max(gpio_banks, alias_id + 1);
> +}
> +
> +static int __init of_at91_gpio_init(void)
> +{
> + struct device_node *np = NULL;
> +
> + /*
> + * This isn't ideal, but it gets things hooked up until this
> + * driver is converted into a platform_device
> + */
> + do {
> + np = of_find_compatible_node(np, NULL, "atmel,at91rm9200-gpio");
> +
> + of_at91_gpio_init_one(np);
> + } while (np);
for_each_compatible_node9)?
> +
> + return gpio_banks > 0 ? 0 : -EINVAL;
> +}
> +#else
> +static int __init of_at91_gpio_init(void)
> +{
> + return -EINVAL;
> +}
> +#endif
> +
> +static void __init at91_gpio_init_one(int i, u32 regbase, int id)
> +{
> + struct at91_gpio_chip *at91_gpio = &gpio_chip[i];
> +
> + at91_gpio->chip.base = i * at91_gpio->chip.ngpio;
> + at91_gpio->id = id;
> +
> + at91_gpio->regbase = ioremap(regbase, 512);
> + if (!at91_gpio->regbase) {
> + pr_err("at91_gpio.%d, failed to map registers, ignoring.\n", i);
> + return;
> + }
> +
> + at91_gpio->clock = clk_get_sys(NULL, at91_gpio->chip.label);
> + if (!at91_gpio->clock) {
> + pr_err("at91_gpio.%d, failed to get clock, ignoring.\n", i);
> + return;
> + }
> +
> + /* enable PIO controller's clock */
> + clk_enable(at91_gpio->clock);
Missing return value check?
> + gpio_banks = max(gpio_banks, i + 1);
> +}
> +
> /*
> * Called from the processor-specific init to enable GPIO pin support.
> */
> void __init at91_gpio_init(struct at91_gpio_bank *data, int nr_banks)
> {
> - unsigned i;
> + unsigned i;
> struct at91_gpio_chip *at91_gpio, *last = NULL;
>
> BUG_ON(nr_banks > MAX_GPIO_BANKS);
>
> - gpio_banks = nr_banks;
> + if (of_at91_gpio_init() < 0) {
> + /* no GPIO controller found in device tree */
> + for (i = 0; i < nr_banks; i++)
> + at91_gpio_init_one(i, data[i].regbase, data[i].id);
> + }
>
> - for (i = 0; i < nr_banks; i++) {
> + for (i = 0; i < gpio_banks; i++) {
> at91_gpio = &gpio_chip[i];
>
> - at91_gpio->id = data[i].id;
> - at91_gpio->chip.base = i * 32;
> -
> - at91_gpio->regbase = ioremap(data[i].regbase, 512);
> - if (!at91_gpio->regbase) {
> - pr_err("at91_gpio.%d, failed to map registers, ignoring.\n", i);
> - continue;
> - }
> -
> - at91_gpio->clock = clk_get_sys(NULL, at91_gpio->chip.label);
> - if (!at91_gpio->clock) {
> - pr_err("at91_gpio.%d, failed to get clock, ignoring.\n", i);
> - continue;
> - }
> -
> - /* enable PIO controller's clock */
> - clk_enable(at91_gpio->clock);
> -
> - /* AT91SAM9263_ID_PIOCDE groups PIOC, PIOD, PIOE */
> + /*
> + * GPIO controller are grouped on some SoC:
> + * PIOC, PIOD and PIOE can share the same IRQ line
> + */
> if (last && last->id == at91_gpio->id)
> last->next = at91_gpio;
> last = at91_gpio;
> --
> 1.7.5.4
>
next prev parent reply other threads:[~2011-12-16 10:11 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-15 19:16 [PATCH 0/6] ARM: at91: irqdomain and device tree for AIC and GPIO Nicolas Ferre
2011-12-15 19:16 ` Nicolas Ferre
2011-12-15 19:16 ` [PATCH v4 1/6] ARM: at91/aic: add irq domain and device tree support Nicolas Ferre
2011-12-15 19:16 ` Nicolas Ferre
2012-01-04 19:40 ` Grant Likely
2012-01-04 19:40 ` Grant Likely
2012-01-05 16:26 ` Nicolas Ferre
2012-01-05 16:26 ` Nicolas Ferre
2012-01-05 18:02 ` Grant Likely
2012-01-05 18:02 ` Grant Likely
2011-12-15 19:16 ` [PATCH 2/6] ARM: at91/gpio: add irqdomain to gpio interrupts Nicolas Ferre
2011-12-15 19:16 ` Nicolas Ferre
2012-01-04 19:42 ` Grant Likely
2012-01-04 19:42 ` Grant Likely
2011-12-15 19:16 ` [PATCH 3/6] ARM: at91/gpio: add DT support Nicolas Ferre
2011-12-15 19:16 ` Nicolas Ferre
2011-12-16 10:11 ` Jamie Iles [this message]
2011-12-16 10:11 ` Jamie Iles
2012-01-03 16:25 ` Nicolas Ferre
2012-01-03 16:25 ` Nicolas Ferre
2012-01-03 18:34 ` [PATCH v2 " Nicolas Ferre
2012-01-03 18:34 ` Nicolas Ferre
2012-01-04 19:45 ` Grant Likely
2012-01-04 19:45 ` Grant Likely
2012-01-04 22:04 ` Russell King - ARM Linux
2012-01-04 22:04 ` Russell King - ARM Linux
2012-01-05 19:42 ` [PATCH v3 " Nicolas Ferre
2012-01-05 19:42 ` Nicolas Ferre
2012-01-05 17:50 ` Nicolas Ferre
2012-01-05 17:50 ` Nicolas Ferre
2012-01-05 20:03 ` [PATCH v4 " Nicolas Ferre
2012-01-05 20:03 ` Nicolas Ferre
2011-12-15 19:16 ` [PATCH 4/6] ARM: at91/gpio: add .to_irq gpio_chip handler and rework irq_to_gpio Nicolas Ferre
2011-12-15 19:16 ` Nicolas Ferre
2012-01-04 19:47 ` Grant Likely
2012-01-04 19:47 ` Grant Likely
2011-12-15 19:16 ` [PATCH 5/6] ARM: at91/gpio: remove the static specification of gpio_chip.base Nicolas Ferre
2011-12-15 19:16 ` Nicolas Ferre
2012-01-04 19:47 ` Grant Likely
2012-01-04 19:47 ` Grant Likely
2011-12-15 19:16 ` [PATCH 6/6] ARM: at91/board-dt: remove AIC irq domain from board file Nicolas Ferre
2011-12-15 19:16 ` Nicolas Ferre
2012-01-04 19:48 ` Grant Likely
2012-01-04 19:48 ` Grant Likely
2011-12-16 1:53 ` [PATCH 0/6] ARM: at91: irqdomain and device tree for AIC and GPIO Rob Herring
2011-12-16 1:53 ` Rob Herring
2011-12-16 16:29 ` Nicolas Ferre
2011-12-16 16:29 ` Nicolas Ferre
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20111216101147.GA3230@totoro \
--to=jamie@jamieiles.com \
--cc=linux-arm-kernel@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.