public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Hans de Goede <hdegoede@redhat.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 4/6] sunxi: add gpio driver
Date: Sun, 08 Jun 2014 14:19:26 +0200	[thread overview]
Message-ID: <539454CE.5080507@redhat.com> (raw)
In-Reply-To: <1401991217-1252-4-git-send-email-ijc@hellion.org.uk>

Hi,

On 06/05/2014 08:00 PM, Ian Campbell wrote:
> This patch enables CONFIG_CMD_GPIO for the Allwinner (sunxi) platform as well
> as providing the common gpio API (gpio_request/free, direction in/out, get/set
> etc).
> 
> Signed-off-by: Chen-Yu Tsai <wens@csie.org>
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> Signed-off-by: Ma Haijun <mahaijuns@gmail.com>
> Signed-off-by: Oliver Schinagl <oliver@schinagl.nl>
> Signed-off-by: Ian Campbell <ijc@hellion.org.uk>
> Cc: Henrik Nordstr?m <henrik@henriknordstrom.net>
> Cc: Tom Cubie <Mr.hipboi@gmail.com>
> ---
>  arch/arm/include/asm/arch-sunxi/gpio.h |   2 +
>  drivers/gpio/Makefile                  |   1 +
>  drivers/gpio/sunxi_gpio.c              | 102 +++++++++++++++++++++++++++++++++
>  include/configs/sunxi-common.h         |   4 ++
>  4 files changed, 109 insertions(+)
>  create mode 100644 drivers/gpio/sunxi_gpio.c

Looks good:

Acked-by: Hans de Goede <hdegoede@redhat.com>

Regards,

Hans


> 
> diff --git a/arch/arm/include/asm/arch-sunxi/gpio.h b/arch/arm/include/asm/arch-sunxi/gpio.h
> index 892479c..f7f3d8c 100644
> --- a/arch/arm/include/asm/arch-sunxi/gpio.h
> +++ b/arch/arm/include/asm/arch-sunxi/gpio.h
> @@ -143,5 +143,7 @@ int sunxi_gpio_set_cfgpin(u32 pin, u32 val);
>  int sunxi_gpio_get_cfgpin(u32 pin);
>  int sunxi_gpio_set_drv(u32 pin, u32 val);
>  int sunxi_gpio_set_pull(u32 pin, u32 val);
> +int sunxi_name_to_gpio(const char *name);
> +#define name_to_gpio(name) sunxi_name_to_gpio(name)
>  
>  #endif /* _SUNXI_GPIO_H */
> diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
> index 4e001e1..86813b9 100644
> --- a/drivers/gpio/Makefile
> +++ b/drivers/gpio/Makefile
> @@ -34,3 +34,4 @@ obj-$(CONFIG_XILINX_GPIO)	+= xilinx_gpio.o
>  obj-$(CONFIG_ADI_GPIO2)	+= adi_gpio2.o
>  obj-$(CONFIG_TCA642X)		+= tca642x.o
>  oby-$(CONFIG_SX151X)		+= sx151x.o
> +obj-$(CONFIG_SUNXI_GPIO)	+= sunxi_gpio.o
> diff --git a/drivers/gpio/sunxi_gpio.c b/drivers/gpio/sunxi_gpio.c
> new file mode 100644
> index 0000000..0c50a8f
> --- /dev/null
> +++ b/drivers/gpio/sunxi_gpio.c
> @@ -0,0 +1,102 @@
> +/*
> + * (C) Copyright 2012 Henrik Nordstrom <henrik@henriknordstrom.net>
> + *
> + * Based on earlier arch/arm/cpu/armv7/sunxi/gpio.c:
> + *
> + * (C) Copyright 2007-2011
> + * Allwinner Technology Co., Ltd. <www.allwinnertech.com>
> + * Tom Cubie <tangliang@allwinnertech.com>
> + *
> + * SPDX-License-Identifier:	GPL-2.0+
> + */
> +
> +#include <common.h>
> +#include <asm/io.h>
> +#include <asm/gpio.h>
> +
> +static int sunxi_gpio_output(u32 pin, u32 val)
> +{
> +	u32 dat;
> +	u32 bank = GPIO_BANK(pin);
> +	u32 num = GPIO_NUM(pin);
> +	struct sunxi_gpio *pio = BANK_TO_GPIO(bank);
> +
> +	dat = readl(&pio->dat);
> +	if (val)
> +		dat |= 0x1 << num;
> +	else
> +		dat &= ~(0x1 << num);
> +
> +	writel(dat, &pio->dat);
> +
> +	return 0;
> +}
> +
> +static int sunxi_gpio_input(u32 pin)
> +{
> +	u32 dat;
> +	u32 bank = GPIO_BANK(pin);
> +	u32 num = GPIO_NUM(pin);
> +	struct sunxi_gpio *pio = BANK_TO_GPIO(bank);
> +
> +	dat = readl(&pio->dat);
> +	dat >>= num;
> +
> +	return dat & 0x1;
> +}
> +
> +int gpio_request(unsigned gpio, const char *label)
> +{
> +	return 0;
> +}
> +
> +int gpio_free(unsigned gpio)
> +{
> +	return 0;
> +}
> +
> +int gpio_direction_input(unsigned gpio)
> +{
> +	sunxi_gpio_set_cfgpin(gpio, SUNXI_GPIO_INPUT);
> +
> +	return sunxi_gpio_input(gpio);
> +}
> +
> +int gpio_direction_output(unsigned gpio, int value)
> +{
> +	sunxi_gpio_set_cfgpin(gpio, SUNXI_GPIO_OUTPUT);
> +
> +	return sunxi_gpio_output(gpio, value);
> +}
> +
> +int gpio_get_value(unsigned gpio)
> +{
> +	return sunxi_gpio_input(gpio);
> +}
> +
> +int gpio_set_value(unsigned gpio, int value)
> +{
> +	return sunxi_gpio_output(gpio, value);
> +}
> +
> +int sunxi_name_to_gpio(const char *name)
> +{
> +	int group = 0;
> +	int groupsize = 9 * 32;
> +	long pin;
> +	char *eptr;
> +	if (*name == 'P' || *name == 'p')
> +		name++;
> +	if (*name >= 'A') {
> +		group = *name - (*name > 'a' ? 'a' : 'A');
> +		groupsize = 32;
> +		name++;
> +	}
> +
> +	pin = simple_strtol(name, &eptr, 10);
> +	if (!*name || *eptr)
> +		return -1;
> +	if (pin < 0 || pin > groupsize || group >= 9)
> +		return -1;
> +	return group * 32 + pin;
> +}
> diff --git a/include/configs/sunxi-common.h b/include/configs/sunxi-common.h
> index a9d104a..ebb9f7a 100644
> --- a/include/configs/sunxi-common.h
> +++ b/include/configs/sunxi-common.h
> @@ -179,6 +179,10 @@
>  #define CONFIG_CONS_INDEX              1       /* UART0 */
>  #endif
>  
> +/* GPIO */
> +#define CONFIG_SUNXI_GPIO
> +#define CONFIG_CMD_GPIO
> +
>  /* Ethernet support */
>  #ifdef CONFIG_SUNXI_EMAC
>  #define CONFIG_MII			/* MII PHY management		*/
> 

  reply	other threads:[~2014-06-08 12:19 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-05 17:59 [U-Boot] [PATCH v2 0/6] sunxi: GPIO, AHCI and Cubieboard 2 support Ian Campbell
2014-06-05 18:00 ` [U-Boot] [PATCH 1/6] AHCI: Increase link timeout to 200ms Ian Campbell
2014-06-05 18:00 ` [U-Boot] [PATCH 2/6] board_r: run scsi init() on ARM too Ian Campbell
2014-06-05 18:00 ` [U-Boot] [PATCH 3/6] sunxi: add Cubieboard2 support Ian Campbell
2014-07-24  3:12   ` Siarhei Siamashka
2014-07-24  3:18     ` Chen-Yu Tsai
2014-07-24 12:47       ` Siarhei Siamashka
2014-07-24 15:00         ` Tom Rini
2014-07-24 21:40           ` Siarhei Siamashka
2014-07-25 13:39             ` Tom Rini
2014-07-24  6:45     ` Ian Campbell
2014-07-24 21:12       ` Siarhei Siamashka
2014-07-25  6:52         ` Ian Campbell
2014-07-25 13:46           ` Tom Rini
2014-07-26 12:15           ` Siarhei Siamashka
2014-06-05 18:00 ` [U-Boot] [PATCH 4/6] sunxi: add gpio driver Ian Campbell
2014-06-08 12:19   ` Hans de Goede [this message]
2014-06-05 18:00 ` [U-Boot] [PATCH 5/6] sunxi: use setbits_le32 to enable the DMA clock Ian Campbell
2014-06-08 12:19   ` Hans de Goede
2014-06-05 18:00 ` [U-Boot] [PATCH 6/6] ahci: provide sunxi SATA driver using AHCI platform framework Ian Campbell

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=539454CE.5080507@redhat.com \
    --to=hdegoede@redhat.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