[U-Boot] [PATCH 1/2] mpc83xx: Add a GPIO driver for the MPC83XX family

Kim Phillips kim.phillips at freescale.com
Wed Aug 10 00:54:43 CEST 2011


On Tue, 9 Aug 2011 17:31:29 -0500
Joe Hershberger <joe.hershberger at ni.com> wrote:

> diff --git a/arch/powerpc/include/asm/gpio.h b/arch/powerpc/include/asm/gpio.h
> new file mode 100644
> index 0000000..eb071d1
> --- /dev/null
> +++ b/arch/powerpc/include/asm/gpio.h
> @@ -0,0 +1,38 @@
> +/*
> + * Copyright (c) 2011, NVIDIA Corp. All rights reserved.
> + * 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
> + */
> +
> +#ifndef _GPIO_H_
> +#define _GPIO_H_
> +
> +#include <asm/arch/gpio.h>
> +/*
> + * Generic GPIO API
> + */
> +
> +int gpio_request(int gp, const char *label);
> +void gpio_free(int gp);
> +void gpio_toggle_value(int gp);
> +int gpio_direction_input(int gp);
> +int gpio_direction_output(int gp, int value);
> +int gpio_get_value(int gp);
> +void gpio_set_value(int gp, int value);
> +
> +#endif	/* _GPIO_H_ */

looks like this GPIO API-definition file is starting to be copied
for each arch, and there's nothing arch-specific in it. As such, it
probably belongs in include/asm-generic/, not arch/powerpc.  Other
arches need fixing in this area, too.

> +/* set GPIO pin 'gp' as an input */
> +int gpio_direction_input(int gp)
> +{
> +	volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;

no volatile

> +	unsigned int ctrlr;
> +	unsigned int line;
> +	unsigned int lineMask;

no camelCase

> +
> +	/* 32-bits per controller */
> +	ctrlr = gp >> 5;
> +	line = gp & (0x1F);
> +
> +	/* Big endian */
> +	lineMask = 1 << (31 - line);
> +
> +	im->gpio[ctrlr].dir &= ~lineMask;

must use i/o accessors and/or clr/setbits_be32, please fix
everywhere.

> +	/* Update the local output buffer soft copy */
> +	gpio_output_value[ctrlr] =
> +		(gpio_output_value[ctrlr] & ~lineMask) | (value ? lineMask : 0);

what's the use of having a local output buffer soft copy?  I don't
see it being used anywhere.

Kim



More information about the U-Boot mailing list