[U-Boot] [PATCH] nios2 : convert altera_pio to driver model

Marek Vasut marex at denx.de
Thu Sep 24 20:04:52 CEST 2015


On Thursday, September 24, 2015 at 11:15:05 AM, Thomas Chou wrote:
> Convert altera_pio to driver model.
> 
> Signed-off-by: Thomas Chou <thomas at wytron.com.tw>

Hi,

now this is quite a nice patch :-)

> ---
>  arch/nios2/dts/3c120_devboard.dts          |  38 ++++
>  arch/nios2/include/asm/gpio.h              |  80 +-------
>  board/altera/nios2-generic/nios2-generic.c |   7 -
>  configs/nios2-generic_defconfig            |   2 +
>  drivers/gpio/Kconfig                       |   7 +
>  drivers/gpio/altera_pio.c                  | 316
> +++++++---------------------- include/configs/nios2-generic.h            |
>  20 --
>  7 files changed, 124 insertions(+), 346 deletions(-)
> 

[...]

> +static int altera_pio_get_value(struct udevice *dev, unsigned pin)
>  {
> -	int i;
> -	int j;
> -	int gidx;
> -	u32 mask;
> +	struct altera_pio_platdata *plat = dev_get_platdata(dev);
> +	struct altera_pio_regs *const regs = plat->regs;
> 
> -	for (i = 0; i < pio_num; ++i) {
> -		printf("Altera PIO % 2d, @0x%08x, "
> -			"width: %u, label: %s\n",
> -		       i, pios[i].base, pios[i].width, pios[i].label);
> -		gidx = pios[i].gidx;
> -		for (j = gidx; j < (gidx + pios[i].width); ++j) {
> -			mask = 1 << (j - gidx);
> -			printf("\tGPIO % 4d: %s %s [%c] %s\n",
> -				gpios[j].num,
> -				gpios[j].pio->sh_dir & mask ? "out" : " in",
> -				gpio_get_value(gpios[j].num) ? "set" : "clr",
> -				altera_pio_is_gidx_used(j) ? 'x' : ' ',
> -				gpios[j].reqlabel);
> -		}
> -	}
> +	return !!(readl(&regs->data) & (1 << pin));

You can drop the double negation here, the API design is done such that
0 is log. low and non-zero is log. high .

[...]

Thanks!


More information about the U-Boot mailing list