aboutsummaryrefslogtreecommitdiffstats
path: root/board/samsung/midas/led.c
blob: 3bad781add1e059835a9cf9cdef4fab64364b2f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <common.h>
#include <dm/uclass.h>
#include <led.h>
#include "midas.h"

DECLARE_GLOBAL_DATA_PTR;

static const char *leds[] = {
	[RED] = "red",
	[GREEN] = "green",
	[BLUE] = "blue",
};

static int midas_set_led(const char *name, enum led_state_t state)
{
	struct udevice *dev;
	int ret;

	ret = led_get_by_label(name, &dev);
	if (ret) {
		printf("%s: get led %s failed: %d\n", __func__, name, ret);
		return ret;
	}

	return led_set_state(dev, state);
}

int midas_led_action(int mask, enum led_state_t state)
{
	int ret;
	for (int i = 0; i < ARRAY_SIZE(leds); i++) {
		if (mask & (1 << i)) {
			ret = midas_set_led(leds[i], state);
			if (ret) {
				return ret;
			}
		}
	}

	return 0;
}