]>
Commit | Line | Data |
---|---|---|
30d66db7 PR |
1 | // SPDX-License-Identifier: GPL-2.0+ |
2 | /* | |
3 | * Copyright (C) 2020 Philippe Reynes <philippe.reynes@softathome.com> | |
4 | * | |
5 | * Based on led-uclass.c | |
6 | */ | |
7 | ||
b953ec2b PD |
8 | #define LOG_CATEGORY UCLASS_BUTTON |
9 | ||
d678a59d | 10 | #include <common.h> |
30d66db7 PR |
11 | #include <button.h> |
12 | #include <dm.h> | |
13 | #include <dm/uclass-internal.h> | |
14 | ||
15 | int button_get_by_label(const char *label, struct udevice **devp) | |
16 | { | |
17 | struct udevice *dev; | |
18 | struct uclass *uc; | |
19 | ||
20 | uclass_id_foreach_dev(UCLASS_BUTTON, dev, uc) { | |
caa4daa2 | 21 | struct button_uc_plat *uc_plat = dev_get_uclass_plat(dev); |
30d66db7 PR |
22 | |
23 | /* Ignore the top-level button node */ | |
24 | if (uc_plat->label && !strcmp(label, uc_plat->label)) | |
25 | return uclass_get_device_tail(dev, 0, devp); | |
26 | } | |
27 | ||
28 | return -ENODEV; | |
29 | } | |
30 | ||
31 | enum button_state_t button_get_state(struct udevice *dev) | |
32 | { | |
33 | struct button_ops *ops = button_get_ops(dev); | |
34 | ||
35 | if (!ops->get_state) | |
36 | return -ENOSYS; | |
37 | ||
38 | return ops->get_state(dev); | |
39 | } | |
40 | ||
ea6fdc13 DS |
41 | int button_get_code(struct udevice *dev) |
42 | { | |
43 | struct button_ops *ops = button_get_ops(dev); | |
44 | ||
45 | if (!ops->get_code) | |
46 | return -ENOSYS; | |
47 | ||
48 | return ops->get_code(dev); | |
49 | } | |
50 | ||
30d66db7 PR |
51 | UCLASS_DRIVER(button) = { |
52 | .id = UCLASS_BUTTON, | |
53 | .name = "button", | |
caa4daa2 | 54 | .per_device_plat_auto = sizeof(struct button_uc_plat), |
30d66db7 | 55 | }; |