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