From: Maxime Ripard <maxime.ripard@free-electrons.com>
To: Linus Walleij <linus.walleij@linaro.org>
Cc: linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, Arnd Bergmann <arnd@arndb.de>,
Olof Johansson <olof@lixom.net>,
Grant Likely <grant.likely@secretlab.ca>,
Rob Herring <rob.herring@calxeda.com>,
Rob Landley <rob@landley.net>,
devicetree-discuss@lists.ozlabs.org, linux-doc@vger.kernel.org
Subject: Re: [PATCH 1/2] ARM: sunxi: gpio: Add Allwinner SoCs GPIO drivers
Date: Sat, 12 Jan 2013 10:06:44 +0100 [thread overview]
Message-ID: <50F127A4.907@free-electrons.com> (raw)
In-Reply-To: <CACRpkda0yhVvCW9edWBi3XusfS4NaiWqKsoCfLpT9+X5iO-GXg@mail.gmail.com>
Hi Linus,
On 10/01/2013 12:06, Linus Walleij wrote:
> On Fri, Jan 4, 2013 at 5:45 PM, Maxime Ripard
> <maxime.ripard@free-electrons.com> wrote:
>> +static int __devinit
>> +sunxi_pinctrl_register_gpio_ranges(struct sunxi_pinctrl *pctl)
>> +{
>> + int id = 0, base = 0, npins = 1, i, prev_pin = -1;
>> + struct pinctrl_gpio_range *range;
>> +
>> + for (i = 0; i < pctl->desc->npins; i++) {
>> + const struct sunxi_desc_pin *pin = pctl->desc->pins + i;
>> + unsigned pin_num = pin->pin.number;
>> +
>> + if (prev_pin < 0) {
>> + prev_pin = pin_num;
>> + base = pin_num;
>> + } else if (prev_pin + 1 != pin_num) {
>> + range = devm_kzalloc(pctl->dev,
>> + sizeof(*range),
>> + GFP_KERNEL);
>> + if (!range)
>> + return -ENOMEM;
>> +
>> + range->name = "sunxi";
>> + range->id = id;
>> + range->base = base;
>> + range->pin_base = base;
>> + range->npins = npins;
>> +
>> + pinctrl_add_gpio_range(pctl->pctl_dev, range);
>> +
>> + id++;
>> + npins = 1;
>> + prev_pin = pin_num;
>> + base = prev_pin;
>> + } else {
>> + prev_pin++;
>> + npins++;
>> + }
>> + }
>> +
>> + range = devm_kzalloc(pctl->dev, sizeof(*range),
>> + GFP_KERNEL);
>> + if (!range)
>> + return -ENOMEM;
>> +
>> + range->name = "sunxi";
>> + range->id = id;
>> + range->base = base;
>> + range->pin_base = base;
>> + range->npins = npins;
>> +
>> + pinctrl_add_gpio_range(pctl->pctl_dev, range);
>> +
>> + return 0;
>> +}
>
> Really hairy way to add ranges right?
Yes... I didn't find any best way to do so. It was either that or
duplicate the already existing informations we had about the pins ranges
into a ranges array, which is pretty error-prone.
I guess I could add some comments though.
> Registering ranges from the pinctrl side is deprecated and discouraged.
>
> Instead register the ranges from the GPIO driver.
>
> Use gpiochip_add_pin_range() from the GPIO driver.
>
> An example is provided in
> drivers/pinctrl/pinctrl-coh901.c
Ok, will do. But we need to find a way to share the pins arrays between
the pinctrl and gpio drivers then.
Maybe add a pinctrl-sunxi-pins.h file? or merge the pinctrl and gpio
drivers?
I'm kind of reluctant to merging the drivers into one single messy file,
but if that's the way to go, fine.
>
> After you have done this, you can probably get rid of this as well:
>
> +static int __init sunxi_gpio_init(void)
> +{
> + return platform_driver_register(&sunxi_gpio_driver);
> +}
> +postcore_initcall(sunxi_gpio_init);
>
> This will become a simple module_init() if you are handling
> deferred probe correctly.
Ok. Thanks for your review!
Maxime
--
Maxime Ripard, Free Electrons
Kernel, drivers, real-time and embedded Linux
development, consulting, training and support.
http://free-electrons.com
next prev parent reply other threads:[~2013-01-12 9:06 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-04 16:45 [PATCH 0/2] Add GPIO driver for Allwinner SoCs Maxime Ripard
2013-01-04 16:45 ` [PATCH 1/2] ARM: sunxi: gpio: Add Allwinner SoCs GPIO drivers Maxime Ripard
2013-01-10 11:06 ` Linus Walleij
2013-01-12 9:06 ` Maxime Ripard [this message]
2013-01-17 11:06 ` Linus Walleij
2013-01-04 16:45 ` [PATCH 2/2] ARM: sunxi: Add the GPIOs node to the device tree Maxime Ripard
2013-01-05 15:35 ` [PATCH 0/2] Add GPIO driver for Allwinner SoCs Olof Johansson
2013-01-10 11:13 ` Linus Walleij
2013-01-12 8:54 ` Maxime Ripard
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=50F127A4.907@free-electrons.com \
--to=maxime.ripard@free-electrons.com \
--cc=arnd@arndb.de \
--cc=devicetree-discuss@lists.ozlabs.org \
--cc=grant.likely@secretlab.ca \
--cc=linus.walleij@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=olof@lixom.net \
--cc=rob.herring@calxeda.com \
--cc=rob@landley.net \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox