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 
8 #include <common.h>
9 #include <button.h>
10 #include <dm.h>
11 #include <dm/uclass-internal.h>
12 
button_get_by_label(const char * label,struct udevice ** devp)13 int button_get_by_label(const char *label, struct udevice **devp)
14 {
15 	struct udevice *dev;
16 	struct uclass *uc;
17 
18 	uclass_id_foreach_dev(UCLASS_BUTTON, dev, uc) {
19 		struct button_uc_plat *uc_plat = dev_get_uclass_plat(dev);
20 
21 		/* Ignore the top-level button node */
22 		if (uc_plat->label && !strcmp(label, uc_plat->label))
23 			return uclass_get_device_tail(dev, 0, devp);
24 	}
25 
26 	return -ENODEV;
27 }
28 
button_get_state(struct udevice * dev)29 enum button_state_t button_get_state(struct udevice *dev)
30 {
31 	struct button_ops *ops = button_get_ops(dev);
32 
33 	if (!ops->get_state)
34 		return -ENOSYS;
35 
36 	return ops->get_state(dev);
37 }
38 
39 UCLASS_DRIVER(button) = {
40 	.id		= UCLASS_BUTTON,
41 	.name		= "button",
42 	.per_device_plat_auto	= sizeof(struct button_uc_plat),
43 };
44