wdenk | 7539dea | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2000-2003 |
| 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
Wolfgang Denk | bd8ec7e | 2013-10-07 13:07:26 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | 7539dea | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <status_led.h> |
| 10 | |
| 11 | /* |
| 12 | * The purpose of this code is to signal the operational status of a |
| 13 | * target which usually boots over the network; while running in |
| 14 | * U-Boot, a status LED is blinking. As soon as a valid BOOTP reply |
| 15 | * message has been received, the LED is turned off. The Linux |
| 16 | * kernel, once it is running, will start blinking the LED again, |
| 17 | * with another frequency. |
| 18 | */ |
| 19 | |
| 20 | /* ------------------------------------------------------------------------- */ |
| 21 | |
wdenk | 7539dea | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 22 | typedef struct { |
| 23 | led_id_t mask; |
| 24 | int state; |
| 25 | int period; |
| 26 | int cnt; |
| 27 | } led_dev_t; |
| 28 | |
| 29 | led_dev_t led_dev[] = { |
Uri Mashiach | 4892d39 | 2017-01-19 10:51:45 +0200 | [diff] [blame^] | 30 | { CONFIG_LED_STATUS_BIT, |
| 31 | CONFIG_LED_STATUS_STATE, |
| 32 | LED_STATUS_PERIOD, |
| 33 | 0, |
| 34 | }, |
| 35 | #if defined(CONFIG_LED_STATUS1) |
| 36 | { CONFIG_LED_STATUS_BIT1, |
| 37 | CONFIG_LED_STATUS_STATE1, |
| 38 | LED_STATUS_PERIOD1, |
| 39 | 0, |
| 40 | }, |
wdenk | 7539dea | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 41 | #endif |
Uri Mashiach | 4892d39 | 2017-01-19 10:51:45 +0200 | [diff] [blame^] | 42 | #if defined(CONFIG_LED_STATUS2) |
| 43 | { CONFIG_LED_STATUS_BIT2, |
| 44 | CONFIG_LED_STATUS_STATE2, |
| 45 | LED_STATUS_PERIOD2, |
| 46 | 0, |
| 47 | }, |
wdenk | 7539dea | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 48 | #endif |
Uri Mashiach | 4892d39 | 2017-01-19 10:51:45 +0200 | [diff] [blame^] | 49 | #if defined(CONFIG_LED_STATUS3) |
| 50 | { CONFIG_LED_STATUS_BIT3, |
| 51 | CONFIG_LED_STATUS_STATE3, |
| 52 | LED_STATUS_PERIOD3, |
| 53 | 0, |
| 54 | }, |
wdenk | 7539dea | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 55 | #endif |
Uri Mashiach | 4892d39 | 2017-01-19 10:51:45 +0200 | [diff] [blame^] | 56 | #if defined(CONFIG_LED_STATUS4) |
| 57 | { CONFIG_LED_STATUS_BIT4, |
| 58 | CONFIG_LED_STATUS_STATE4, |
| 59 | LED_STATUS_PERIOD4, |
| 60 | 0, |
| 61 | }, |
Stefan Roese | 448e9df | 2015-03-11 09:51:39 +0100 | [diff] [blame] | 62 | #endif |
Uri Mashiach | 4892d39 | 2017-01-19 10:51:45 +0200 | [diff] [blame^] | 63 | #if defined(CONFIG_LED_STATUS5) |
| 64 | { CONFIG_LED_STATUS_BIT5, |
| 65 | CONFIG_LED_STATUS_STATE5, |
| 66 | LED_STATUS_PERIOD5, |
| 67 | 0, |
| 68 | }, |
Stefan Roese | 448e9df | 2015-03-11 09:51:39 +0100 | [diff] [blame] | 69 | #endif |
wdenk | 7539dea | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | #define MAX_LED_DEV (sizeof(led_dev)/sizeof(led_dev_t)) |
| 73 | |
| 74 | static int status_led_init_done = 0; |
| 75 | |
Bernhard Nortmann | c5dcb4a | 2015-08-21 15:13:21 +0200 | [diff] [blame] | 76 | void status_led_init(void) |
wdenk | 7539dea | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 77 | { |
| 78 | led_dev_t *ld; |
| 79 | int i; |
| 80 | |
| 81 | for (i = 0, ld = led_dev; i < MAX_LED_DEV; i++, ld++) |
| 82 | __led_init (ld->mask, ld->state); |
| 83 | status_led_init_done = 1; |
| 84 | } |
| 85 | |
| 86 | void status_led_tick (ulong timestamp) |
| 87 | { |
| 88 | led_dev_t *ld; |
| 89 | int i; |
| 90 | |
| 91 | if (!status_led_init_done) |
| 92 | status_led_init (); |
| 93 | |
| 94 | for (i = 0, ld = led_dev; i < MAX_LED_DEV; i++, ld++) { |
| 95 | |
Uri Mashiach | 4892d39 | 2017-01-19 10:51:45 +0200 | [diff] [blame^] | 96 | if (ld->state != CONFIG_LED_STATUS_BLINKING) |
wdenk | 7539dea | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 97 | continue; |
| 98 | |
| 99 | if (++ld->cnt >= ld->period) { |
| 100 | __led_toggle (ld->mask); |
| 101 | ld->cnt -= ld->period; |
| 102 | } |
| 103 | |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | void status_led_set (int led, int state) |
| 108 | { |
| 109 | led_dev_t *ld; |
| 110 | |
| 111 | if (led < 0 || led >= MAX_LED_DEV) |
| 112 | return; |
| 113 | |
| 114 | if (!status_led_init_done) |
| 115 | status_led_init (); |
| 116 | |
| 117 | ld = &led_dev[led]; |
| 118 | |
| 119 | ld->state = state; |
Uri Mashiach | 4892d39 | 2017-01-19 10:51:45 +0200 | [diff] [blame^] | 120 | if (state == CONFIG_LED_STATUS_BLINKING) { |
wdenk | 7539dea | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 121 | ld->cnt = 0; /* always start with full period */ |
Uri Mashiach | 4892d39 | 2017-01-19 10:51:45 +0200 | [diff] [blame^] | 122 | state = CONFIG_LED_STATUS_ON; /* always start with LED _ON_ */ |
wdenk | 7539dea | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 123 | } |
| 124 | __led_set (ld->mask, state); |
| 125 | } |