summaryrefslogtreecommitdiff
path: root/drivers/button/button-uclass.c
blob: 1c742c265cfd1afd4e5abfdcbb332e2ac6bda92d (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
43
// SPDX-License-Identifier: GPL-2.0+
/*
 * Copyright (C) 2020 Philippe Reynes <philippe.reynes@softathome.com>
 *
 * Based on led-uclass.c
 */

#include <common.h>
#include <button.h>
#include <dm.h>
#include <dm/uclass-internal.h>

int button_get_by_label(const char *label, struct udevice **devp)
{
	struct udevice *dev;
	struct uclass *uc;

	uclass_id_foreach_dev(UCLASS_BUTTON, dev, uc) {
		struct button_uc_plat *uc_plat = dev_get_uclass_platdata(dev);

		/* Ignore the top-level button node */
		if (uc_plat->label && !strcmp(label, uc_plat->label))
			return uclass_get_device_tail(dev, 0, devp);
	}

	return -ENODEV;
}

enum button_state_t button_get_state(struct udevice *dev)
{
	struct button_ops *ops = button_get_ops(dev);

	if (!ops->get_state)
		return -ENOSYS;

	return ops->get_state(dev);
}

UCLASS_DRIVER(button) = {
	.id		= UCLASS_BUTTON,
	.name		= "button",
	.per_device_platdata_auto_alloc_size = sizeof(struct button_uc_plat),
};