From: "Andreas Bießmann" <andreas.devel@googlemail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 1/4] gpio: atmel: fix code to use pointer for pio port
Date: Wed, 21 Aug 2013 17:08:13 +0200 [thread overview]
Message-ID: <5214D7DD.2060205@gmail.com> (raw)
In-Reply-To: <1376375912-13835-2-git-send-email-voice.shen@atmel.com>
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
> + 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
> + 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()?
> + 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()
> 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.
Best regards
Andreas Bie?mann
next prev parent reply other threads:[~2013-08-21 15:08 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 [this message]
2013-08-22 3:15 ` Bo Shen
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=5214D7DD.2060205@gmail.com \
--to=andreas.devel@googlemail.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