wdenk | 5c952cf | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2004, Psyent Corporation <www.psyent.com> |
| 3 | * Scott McNutt <smcnutt@psyent.com> |
| 4 | * |
Wolfgang Denk | 3765b3e | 2013-10-07 13:07:26 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | 5c952cf | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
Scott McNutt | 3d22d0b | 2006-06-08 12:03:21 -0400 | [diff] [blame] | 9 | #include <asm/io.h> |
wdenk | 5c952cf | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 10 | #include <nios2-io.h> |
| 11 | #include <status_led.h> |
| 12 | |
| 13 | /* The LED port is configured as output only, so we |
| 14 | * must track the state manually. |
| 15 | */ |
| 16 | static led_id_t val = 0; |
| 17 | |
| 18 | void __led_init (led_id_t mask, int state) |
| 19 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 20 | nios_pio_t *pio = (nios_pio_t *)CONFIG_SYS_LEDPIO_ADDR; |
wdenk | 5c952cf | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 21 | |
| 22 | if (state == STATUS_LED_ON) |
| 23 | val &= ~mask; |
| 24 | else |
| 25 | val |= mask; |
Scott McNutt | 3ea0037 | 2010-03-21 21:24:43 -0400 | [diff] [blame] | 26 | writel (val, &pio->data); |
wdenk | 5c952cf | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | void __led_set (led_id_t mask, int state) |
| 30 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 31 | nios_pio_t *pio = (nios_pio_t *)CONFIG_SYS_LEDPIO_ADDR; |
wdenk | 5c952cf | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 32 | |
| 33 | if (state == STATUS_LED_ON) |
| 34 | val &= ~mask; |
| 35 | else |
| 36 | val |= mask; |
Scott McNutt | 3ea0037 | 2010-03-21 21:24:43 -0400 | [diff] [blame] | 37 | writel (val, &pio->data); |
wdenk | 5c952cf | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | void __led_toggle (led_id_t mask) |
| 41 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 42 | nios_pio_t *pio = (nios_pio_t *)CONFIG_SYS_LEDPIO_ADDR; |
wdenk | 5c952cf | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 43 | |
| 44 | val ^= mask; |
Scott McNutt | 3ea0037 | 2010-03-21 21:24:43 -0400 | [diff] [blame] | 45 | writel (val, &pio->data); |
wdenk | 5c952cf | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 46 | } |