Simon Glass | 5917112 | 2015-06-23 15:38:45 -0600 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2015 Google, Inc |
| 3 | * Written by Simon Glass <sjg@chromium.org> |
| 4 | * |
| 5 | * SPDX-License-Identifier: GPL-2.0+ |
| 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <dm.h> |
| 10 | #include <errno.h> |
| 11 | #include <led.h> |
| 12 | #include <dm/root.h> |
| 13 | #include <dm/uclass-internal.h> |
| 14 | |
| 15 | int led_get_by_label(const char *label, struct udevice **devp) |
| 16 | { |
| 17 | struct udevice *dev; |
| 18 | struct uclass *uc; |
| 19 | int ret; |
| 20 | |
| 21 | ret = uclass_get(UCLASS_LED, &uc); |
| 22 | if (ret) |
| 23 | return ret; |
| 24 | uclass_foreach_dev(dev, uc) { |
| 25 | struct led_uclass_plat *uc_plat = dev_get_uclass_platdata(dev); |
| 26 | |
| 27 | if (!strcmp(label, uc_plat->label)) |
| 28 | return uclass_get_device_tail(dev, 0, devp); |
| 29 | } |
| 30 | |
| 31 | return -ENOENT; |
| 32 | } |
| 33 | |
| 34 | int led_set_on(struct udevice *dev, int on) |
| 35 | { |
| 36 | struct led_ops *ops = led_get_ops(dev); |
| 37 | |
| 38 | if (!ops->set_on) |
| 39 | return -ENOSYS; |
| 40 | |
| 41 | return ops->set_on(dev, on); |
| 42 | } |
| 43 | |
| 44 | UCLASS_DRIVER(led) = { |
| 45 | .id = UCLASS_LED, |
| 46 | .name = "led", |
| 47 | .per_device_platdata_auto_alloc_size = sizeof(struct led_uclass_plat), |
| 48 | }; |