[U-Boot] [PATCH 1/2] gpio: Add GPIO driver framework for Marvell SoCs

Prafulla Wadaskar prafulla at marvell.com
Fri Jul 22 00:45:51 CEST 2011



> -----Original Message-----
> From: Ajay Bhargav [mailto:ajay.bhargav at einfochips.com]
> Sent: Thursday, July 21, 2011 11:10 AM
> To: Prafulla Wadaskar
> Cc: u-boot at lists.denx.de; Ajay Bhargav
> Subject: [PATCH 1/2] gpio: Add GPIO driver framework for Marvell SoCs
> 
> This patch adds generic GPIO driver framework support for Marvell SoCs.
> 
> To enable GPIO driver define CONFIG_MV_GPIO and for GPIO commands
> define CONFIG_CMD_GPIO in your board configuration file.
> 
> Signed-off-by: Ajay Bhargav <ajay.bhargav at einfochips.com>
> ---
>  drivers/gpio/Makefile |    1 +
>  drivers/gpio/mvgpio.c |  125
> +++++++++++++++++++++++++++++++++++++++++++++++++
>  include/mvgpio.h      |   52 ++++++++++++++++++++
>  3 files changed, 178 insertions(+), 0 deletions(-)
>  create mode 100644 drivers/gpio/mvgpio.c
>  create mode 100644 include/mvgpio.h
> 
> diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
> index 62ec97d..c6f652f 100644
> --- a/drivers/gpio/Makefile
> +++ b/drivers/gpio/Makefile
> @@ -28,6 +28,7 @@ LIB 	:= $(obj)libgpio.o
>  COBJS-$(CONFIG_AT91_GPIO)	+= at91_gpio.o
>  COBJS-$(CONFIG_KIRKWOOD_GPIO)	+= kw_gpio.o
>  COBJS-$(CONFIG_MARVELL_MFP)	+= mvmfp.o
> +COBJS-$(CONFIG_MV_GPIO)		+= mvgpio.o
>  COBJS-$(CONFIG_MXC_GPIO)	+= mxc_gpio.o
>  COBJS-$(CONFIG_PCA953X)		+= pca953x.o
>  COBJS-$(CONFIG_S5P)		+= s5p_gpio.o
> diff --git a/drivers/gpio/mvgpio.c b/drivers/gpio/mvgpio.c
> new file mode 100644
> index 0000000..d64f0db
> --- /dev/null
> +++ b/drivers/gpio/mvgpio.c
> @@ -0,0 +1,125 @@
> +/*
> + * (C) Copyright 2011
> + * eInfochips Ltd. <www.einfochips.com>
> + * Written-by: Ajay Bhargav <ajay.bhargav at einfochips.com>
> + *
> + * (C) Copyright 2010
> + * Marvell Semiconductor <www.marvell.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., 51 Franklin Street, Fifth Floor, Boston,
> + * MA 02110-1301 USA
> + */
> +
> +#include <common.h>
> +#include <asm/io.h>
> +#include <asm/errno.h>
> +#include <asm/gpio.h>
> +
> +char gpio_names[MV_MAX_GPIO][GPIO_LABEL_MAX];
> +
> +static int get_gpio_base(int bank)

Please define this function as 

static struct gpio_reg *get_gpio_base(int gp)

> +{
> +	switch (bank) {
> +	case 0:
> +		return GPIO_BANK0_BASE;
> +	case 1:
> +		return GPIO_BANK1_BASE;
> +	case 2:
> +		return GPIO_BANK2_BASE;
> +	case 3:
> +		return GPIO_BANK3_BASE;
> +	}
> +	return 0;
> +}

And make it part of gpio.h

> +
> +int gpio_request(int gp, const char *label)
> +{
> +	if (gp >= MV_MAX_GPIO)
> +		return -EINVAL;
> +
> +	if (strlen(gpio_names[gp]) == 0) {
> +		strncpy(gpio_names[gp], label, GPIO_LABEL_MAX);
> +		gpio_names[gp][GPIO_LABEL_MAX - 1] = '\0';
> +	} else {
> +		return -EBUSY;
> +	}
> +	return 0;
> +}
> +
> +void gpio_free(int gp)
> +{
> +	gpio_names[gp][0] = '\0';
> +}
> +
> +void gpio_toggle_value(int gp)
> +{
> +	gpio_set_value(gp, !gpio_get_value(gp));
> +}
> +
> +int gpio_direction_input(int gp)
> +{
> +	struct gpio_reg *gpio_reg_bank;
> +
> +	if (gp >= MV_MAX_GPIO)
> +		return -EINVAL;
> +
> +	gpio_reg_bank = (struct gpio_reg *) get_gpio_base(GPIO_TO_REG(gp));
> +	writel(GPIO_TO_BIT(gp), &gpio_reg_bank->gcdr);
> +	return 0;
> +}
> +
> +int gpio_direction_output(int gp, int value)
> +{
> +	struct gpio_reg *gpio_reg_bank;
> +
> +	if (gp >= MV_MAX_GPIO)
> +		return -EINVAL;
> +
> +	gpio_reg_bank = (struct gpio_reg *) get_gpio_base(GPIO_TO_REG(gp));
> +	writel(GPIO_TO_BIT(gp), &gpio_reg_bank->gsdr);
> +	gpio_set_value(gp, value);
> +	return 0;
> +}
> +
> +int gpio_get_value(int gp)
> +{
> +	struct gpio_reg *gpio_reg_bank;
> +	u32 gp_val;
> +
> +	if (gp >= MV_MAX_GPIO)

It is good to display some error message here.

> +		return -EINVAL;
> +
> +	gpio_reg_bank = (struct gpio_reg *) get_gpio_base(GPIO_TO_REG(gp));
> +	gp_val = readl(&gpio_reg_bank->gplr);
> +
> +	return GPIO_VAL(gp, gp_val);
> +}
> +
> +void gpio_set_value(int gp, int value)
> +{
> +	struct gpio_reg *gpio_reg_bank;
> +
> +	if (gp >= MV_MAX_GPIO)

It is good to display some error message here.

Regards..
Prafulla. . .


More information about the U-Boot mailing list