From: Bo Shen <voice.shen@atmel.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 1/4] gpio: atmel: fix code to use pointer for pio port
Date: Thu, 22 Aug 2013 11:15:20 +0800 [thread overview]
Message-ID: <52158248.9090801@atmel.com> (raw)
In-Reply-To: <5214D7DD.2060205@gmail.com>
Hi Andreas,
On 8/21/2013 23:08, Andreas Bie?mann wrote:
> Hi Bo,
>
> On 08/13/2013 08:38 AM, Bo Shen wrote:
>> fix code to use pointer for pio port as the warning message suggested
>> remove the warning message
>>
>> Signed-off-by: Bo Shen <voice.shen@atmel.com>
>> ---
>> drivers/gpio/at91_gpio.c | 232 ++++++++++++++++++++++++++--------------------
>> 1 file changed, 134 insertions(+), 98 deletions(-)
>>
>> diff --git a/drivers/gpio/at91_gpio.c b/drivers/gpio/at91_gpio.c
>> index 2322914..15f396f 100644
>> --- a/drivers/gpio/at91_gpio.c
>> +++ b/drivers/gpio/at91_gpio.c
>> @@ -8,16 +8,6 @@
>> * SPDX-License-Identifier: GPL-2.0+
>> */
>>
>> -/*
>> - * WARNING:
>> - *
>> - * As the code is right now, it expects all PIO ports A,B,C,...
>> - * to be evenly spaced in the memory map:
>> - * ATMEL_BASE_PIOA + port * sizeof at91pio_t
>> - * This might not necessaryly be true in future Atmel SoCs.
>> - * This code should be fixed to use a pointer array to the ports.
>> - */
>> -
>> #include <config.h>
>> #include <common.h>
>> #include <asm/io.h>
>> @@ -25,19 +15,52 @@
>> #include <asm/arch/hardware.h>
>> #include <asm/arch/at91_pio.h>
>>
>> +static unsigned at91_pio_get_port(unsigned port)
>> +{
>> + unsigned at91_port;
>> +
>> + switch (port) {
>> + case AT91_PIO_PORTA:
>> + at91_port = ATMEL_BASE_PIOA;
>> + break;
>> + case AT91_PIO_PORTB:
>> + at91_port = ATMEL_BASE_PIOB;
>> + break;
>> + case AT91_PIO_PORTC:
>> + at91_port = ATMEL_BASE_PIOC;
>> + break;
>> + #if (ATMEL_PIO_PORTS > 3)
>
> fix indention
OK. Thanks.
>> + case AT91_PIO_PORTD:
>> + at91_port = ATMEL_BASE_PIOD;
>> + break;
>> + #endif
>> + #if (ATMEL_PIO_PORTS > 4)
>
> nit ... if ATMEL_PIO_PORTS is > 4 it also matches '>3'
>
> if >3
> if >4
> endif
> endif
OK, I will change style as is.
>> + case AT91_PIO_PORTE:
>> + at91_port = ATMEL_BASE_PIOE;
>> + break;
>> + #endif
>> + default:
>> + at91_port = 0;
>> + break;
>> + }
>> +
>> + return at91_port;
>> +}
>> +
>> int at91_set_pio_pullup(unsigned port, unsigned pin, int use_pullup)
>> {
>> - at91_pio_t *pio = (at91_pio_t *) ATMEL_BASE_PIOA;
>> - u32 mask;
>> + at91_port_t *at91_port = (at91_port_t *)at91_pio_get_port(port);
>
> This cast here is annoying, can't we just change the return type of
> at91_pio_get_port()?
I will change the return type of at91_pio_get_port().
>> + u32 mask;
>>
>> if ((port < ATMEL_PIO_PORTS) && (pin < 32)) {
>
> if (at91_port && (pin < 32))
>
> The logic for correct range of port is delegated to at91_pio_get_port()
Yes, this check should be in at91_pio_get_port();
>> mask = 1 << pin;
>> if (use_pullup)
>> - writel(1 << pin, &pio->port[port].puer);
>> + writel(1 << pin, &at91_port->puer);
>> else
>> - writel(1 << pin, &pio->port[port].pudr);
>> - writel(mask, &pio->port[port].per);
>> + writel(1 << pin, &at91_port->pudr);
>> + writel(mask, &at91_port->per);
>> }
>> +
>
> I wonder if we should break the current usage and return another value
> (-ENODEV ?) on error.
>
>> return 0;
>> }
>
> <snip>
>
> Please adopt all places in this file with mentioned changes and tell me
> your opinion about erroneous return value.
For the erroneous return value, actually we never check it (consider it
always successfully). So, I think now we just keep it as is, and
consider a proper method after this patch set. Would it be OK?
> Best regards
>
> Andreas Bie?mann
>
Best Regards,
Bo Shen
next prev parent reply other threads:[~2013-08-22 3:15 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-13 6:38 [U-Boot] [PATCH 0/4] gpio: atmel: fix code to use pointer for pio port Bo Shen
2013-08-13 6:38 ` [U-Boot] [PATCH 1/4] " Bo Shen
2013-08-21 15:08 ` Andreas Bießmann
2013-08-22 3:15 ` Bo Shen [this message]
2013-08-22 6:26 ` Andreas Bießmann
2013-08-22 7:03 ` Bo Shen
2013-08-22 7:24 ` [U-Boot] [PATCH v2] " Bo Shen
2013-08-22 15:01 ` [U-Boot] [U-Boot,v2] " Andreas Bießmann
2013-08-13 6:38 ` [U-Boot] [PATCH 2/4] gpio: atmel: remove the at91_pio definition Bo Shen
2013-08-21 15:10 ` Andreas Bießmann
2013-08-13 6:38 ` [U-Boot] [PATCH 3/4] gpio: atmel: add gpio common API support Bo Shen
2013-08-21 15:14 ` Andreas Bießmann
2013-08-22 3:21 ` Bo Shen
2013-08-22 6:34 ` Andreas Bießmann
2013-08-22 7:06 ` Bo Shen
2013-08-22 15:01 ` [U-Boot] [U-Boot,3/4] " Andreas Bießmann
2013-08-13 6:38 ` [U-Boot] [PATCH 4/4] gpio: atmel: add copyright and remove error header info Bo Shen
2013-08-21 15:17 ` Andreas Bießmann
2013-08-21 17:20 ` Jens Scharsig
2013-08-21 17:20 ` Jens Scharsig
2013-08-22 15:01 ` [U-Boot] [U-Boot,4/4] " Andreas Bießmann
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=52158248.9090801@atmel.com \
--to=voice.shen@atmel.com \
--cc=u-boot@lists.denx.de \
/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