[PATCH v2 1/3] gpio/mxc: get gpio range/base from gpio core
Grant Likely
grant.likely at secretlab.ca
Wed Jul 6 03:24:13 EST 2011
On Tue, Jul 5, 2011 at 10:56 AM, Sascha Hauer <s.hauer at pengutronix.de> wrote:
> On Tue, Jul 05, 2011 at 11:19:24PM +0800, Shawn Guo wrote:
>> Instead of assigning the gpio range based on pdev->id, the patch
>> makes changes to get the range from gpio core that is dynamically
>> allocated.
>>
>> As a result, the uses of pdev->id can be removed from the driver.
>> This will make dt migration of the driver easier.
>>
>> Signed-off-by: Shawn Guo <shawn.guo at linaro.org>
>> Cc: Grant Likely <grant.likely at secretlab.ca>
>> Cc: Sascha Hauer <s.hauer at pengutronix.de>
>> ---
>> arch/arm/plat-mxc/include/mach/gpio.h | 13 +++++++++----
>> arch/arm/plat-mxc/include/mach/irqs.h | 21 +++------------------
>> drivers/gpio/gpio-mxc.c | 18 ++++++++++--------
>> 3 files changed, 22 insertions(+), 30 deletions(-)
>>
>> diff --git a/arch/arm/plat-mxc/include/mach/gpio.h b/arch/arm/plat-mxc/include/mach/gpio.h
>> index 31c820c..abdf5d7 100644
>> --- a/arch/arm/plat-mxc/include/mach/gpio.h
>> +++ b/arch/arm/plat-mxc/include/mach/gpio.h
>> @@ -23,10 +23,15 @@
>> #include <mach/hardware.h>
>> #include <asm-generic/gpio.h>
>>
>> -
>> -/* There's a off-by-one betweem the gpio bank number and the gpiochip */
>> -/* range e.g. GPIO_1_5 is gpio 5 under linux */
>> -#define IMX_GPIO_NR(bank, nr) (((bank) - 1) * 32 + (nr))
>> +/*
>> + * There's a off-by-one betweem the gpio bank number and the gpiochip
>> + * range e.g. GPIO_1_5 is gpio 5 under linux.
>> + *
>> + * When gpio core allocates gpio range for a bank, it starts from the
>> + * end of the total range. That is to say, bank 0 will get a higher
>> + * gpio range than bank 1.
>> + */
>> +#define IMX_GPIO_NR(bank, nr) (ARCH_NR_GPIOS - (bank) * 32 + (nr))
>
> That is not a good idea. First of all not all boards use this macro.
> This could be fixed, but it is a no go to allocate the gpios dynamically
> and add a macro which makes assumptions on the range which gets
> allocated.
Plus it makes the assumption that the imx gpio controllers will be the
first ones registered, and that the allocation scheme will not change
some time in the future. You don't actually need to change this
anyway since existing static platform_device registrations can still
use the pdev->id value. It is only the DT use case that should
dynamically assign the gpio number because all uses in that case can
use a DT gpio specifier instead of a hard coded number.
g.
>
> Sascha
>
> --
> Pengutronix e.K. | |
> Industrial Linux Solutions | http://www.pengutronix.de/ |
> Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
> Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
>
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
>
--
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
More information about the devicetree-discuss
mailing list