From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?ISO-8859-1?Q?Andreas_Bie=DFmann?= Date: Thu, 22 Aug 2013 08:34:46 +0200 Subject: [U-Boot] [PATCH 3/4] gpio: atmel: add gpio common API support In-Reply-To: <521583B3.7070404@atmel.com> References: <1376375912-13835-1-git-send-email-voice.shen@atmel.com> <1376375912-13835-4-git-send-email-voice.shen@atmel.com> <5214D951.5030101@gmail.com> <521583B3.7070404@atmel.com> Message-ID: <5215B106.7090707@googlemail.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Hi Bo, On 22.08.13 05:21, Bo Shen wrote: > Hi Andreas, > > On 8/21/2013 23:14, Andreas Bie?mann wrote: >> On 08/13/2013 08:38 AM, Bo Shen wrote: >>> add gpio common API support for gpio command >>> >>> Signed-off-by: Bo Shen >>> --- >>> drivers/gpio/at91_gpio.c | 43 >>> +++++++++++++++++++++++++++++++++++++++++++ >>> 1 file changed, 43 insertions(+) >>> >>> diff --git a/drivers/gpio/at91_gpio.c b/drivers/gpio/at91_gpio.c >>> index 15f396f..3de0844 100644 >>> --- a/drivers/gpio/at91_gpio.c >>> +++ b/drivers/gpio/at91_gpio.c >>> @@ -363,3 +363,46 @@ int at91_get_pio_value(unsigned port, unsigned pin) >>> >>> return pdsr != 0; >>> } >>> + >>> +/* Common GPIO API */ >>> + >>> +#define at91_gpio_to_port(gpio) (gpio / 32) >>> +#define at91_gpio_to_pin(gpio) (gpio % 32) >>> + >>> +int gpio_request(unsigned gpio, const char *label) >>> +{ >>> + return 0; >>> +} >>> + >>> +int gpio_free(unsigned gpio) >>> +{ >>> + return 0; >>> +} >>> + >>> +int gpio_direction_input(unsigned gpio) >>> +{ >>> + at91_set_pio_input(at91_gpio_to_port(gpio), >>> + at91_gpio_to_pin(gpio), 0); >>> + return 0; >>> +} >>> + >>> +int gpio_direction_output(unsigned gpio, int value) >>> +{ >>> + at91_set_pio_output(at91_gpio_to_port(gpio), >>> + at91_gpio_to_pin(gpio), value); >>> + return 0; >>> +} >>> + >>> +int gpio_get_value(unsigned gpio) >>> +{ >>> + return (int) at91_get_pio_value(at91_gpio_to_port(gpio), >>> + at91_gpio_to_pin(gpio)); >> >> why cast to int here? > > Actually no need, as the at91_get_pio_value() return value is int. > I will remove the cast in next version. I could change this also when applying. >>> +} >>> + >>> +int gpio_set_value(unsigned gpio, int value) >>> +{ >>> + at91_set_pio_value(at91_gpio_to_port(gpio), >>> + at91_gpio_to_pin(gpio), value); >>> + >>> + return 0; >>> +} >>> >> >> Great, I love this. But wasn't there some define for generic GPIO? > > I am not fully get your meaning, what you mean "define for generic > GPIO"? define gpio pin number (?) My fault, I thought there is some CONFIG_XXX for the 'generic GPIO API' (gpio_set_value/gpio_get_value/gpio_direction_input/...). It seems there is no such define, at91 gpio did just miss the time when this API was introduced. I'm fine if you just send a v2 of the 1/4 patch. I can remove the cast in here and will _not_ apply 2/4 cause it breaks boards. Best regards Andreas Bie?mann