[U-Boot] [PATCH] nios2: add gpio based status led driver

Scott McNutt
2010-04-20T13:19:31Z

Thomas,

Thomas Chou wrote:
> This patch adds a gpio based status led driver. The led mask
> is used to specify the gpio pin.
>
> Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
> ---
> board/altera/common/gpioled.c | 30 ++++++++++++++++++++++++++++++
> 1 files changed, 30 insertions(+), 0 deletions(-)
> create mode 100644 board/altera/common/gpioled.c
>
> diff --git a/board/altera/common/gpioled.c b/board/altera/common/gpioled.c
> new file mode 100644
> index 0000000..9a51fae
> --- /dev/null
> +++ b/board/altera/common/gpioled.c
> @@ -0,0 +1,30 @@
> +/*
> + * Status LED driver based on gpio
> + *
> + * Copyright (C) 2010 Thomas Chou <thomas@wytron.com.tw>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + */
> +
> +#include <common.h>
> +#include <status_led.h>
> +#include <asm/gpio.h>
> +
> +/* assume led is active low */
> +
> +void __led_init(led_id_t mask, int state)
> +{
> + gpio_direction_output(mask, (state == STATUS_LED_ON) ? 0 : 1);

The direction register only exists when the PIO core hardware
is configured in bidirectional mode.

> +void __led_set(led_id_t mask, int state)
> +{
> + gpio_set_value(mask, (state == STATUS_LED_ON) ? 0 : 1);
> +}
> +
> +void __led_toggle(led_id_t mask)
> +{
> + gpio_set_value(mask, !gpio_get_value (mask));
> +}

If the PIO core hardware is configured in output-only mode,
reading from data returns an undefined value.

As I recall, the older designs configured the LED PIO ports
as output only ... which is why board/altera/common/epled.c
was coded in such a manner.

Regards,
--Scott