[U-Boot] [PATCH 06/22] ARM sunxi: Basic GPIO driver

Marek Vasut marex at denx.de
Sun Nov 25 19:14:45 CET 2012


Dear Henrik Nordström,

> GPIO driver for Allwinner sun4i/sun5i family of SoCs
> 
> GPIO Pins are named by their symbolic pin names P<g><#>
> such as PH19 or H19.
> 
> Note: This do not perform any validation if the pin is in use
> for some other I/O function. Use with care.
> ---
>  arch/arm/include/asm/arch-sunxi/gpio.h |    2 +
>  drivers/gpio/Makefile                  |    1 +
>  drivers/gpio/sunxi_gpio.c              |  116
> ++++++++++++++++++++++++++++++++ include/configs/sunxi-common.h         | 
>   4 +
>  4 files changed, 123 insertions(+), 0 deletions(-)
>  create mode 100644 drivers/gpio/sunxi_gpio.c
> 
> diff --git a/arch/arm/include/asm/arch-sunxi/gpio.h
> b/arch/arm/include/asm/arch-sunxi/gpio.h index fceee6b..a3f8a74 100644
> --- a/arch/arm/include/asm/arch-sunxi/gpio.h
> +++ b/arch/arm/include/asm/arch-sunxi/gpio.h
> @@ -160,5 +160,7 @@ enum sunxi_gpio_number {
> 
>  int sunxi_gpio_set_cfgpin(u32 pin, u32 val);
>  int sunxi_gpio_get_cfgpin(u32 pin);
> +int name_to_gpio(const char *name);
> +#define name_to_gpio	name_to_gpio
> 
>  #endif /* _SUNXI_GPIO_H */
> diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
> index d50ac3b..6d692e6 100644
> --- a/drivers/gpio/Makefile
> +++ b/drivers/gpio/Makefile
> @@ -45,6 +45,7 @@ COBJS-$(CONFIG_OMAP_GPIO)	+= omap_gpio.o
>  COBJS-$(CONFIG_DB8500_GPIO)	+= db8500_gpio.o
>  COBJS-$(CONFIG_BCM2835_GPIO)	+= bcm2835_gpio.o
>  COBJS-$(CONFIG_S3C2440_GPIO)	+= s3c2440_gpio.o
> +COBJS-$(CONFIG_SUNXI_GPIO)	+= sunxi_gpio.o
> 
>  COBJS	:= $(COBJS-y)
>  SRCS 	:= $(COBJS:.o=.c)
> diff --git a/drivers/gpio/sunxi_gpio.c b/drivers/gpio/sunxi_gpio.c
> new file mode 100644
> index 0000000..d99071e
> --- /dev/null
> +++ b/drivers/gpio/sunxi_gpio.c
> @@ -0,0 +1,116 @@
> +/*
> + * (C) Copyright 2007-2011
> + * Allwinner Technology Co., Ltd. <www.allwinnertech.com>
> + * Tom Cubie <tangliang at allwinnertech.com>
> + *
> + * See file CREDITS for list of people who contributed to this
> + * project.
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License as
> + * published by the Free Software Foundation; either version 2 of
> + * the License, or (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
> + * MA 02111-1307 USA
> + */
> +
> +#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 =
> +	    &((struct sunxi_gpio_reg *)SUNXI_PIO_BASE)->gpio_bank[bank];
> +
> +	dat = readl(&pio->dat);
> +	if (val)
> +		dat |= 1 << num;
> +	else
> +		dat &= ~(1 << num);


clrbits_le32() / setbits_le32() ...

> +	writel(dat, &pio->dat);
> +
> +	return 0;
> +}
[...]

Best regards,
Marek Vasut


More information about the U-Boot mailing list