blob: e06d3eb7da5a395b8c971a2ff5bcd6ee5027a32c [file] [log] [blame]
Philippe Reynes3483aa22020-07-24 18:19:45 +02001// 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
13int 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) {
Simon Glass71fa5b42020-12-03 16:55:18 -070019 struct button_uc_plat *uc_plat = dev_get_uclass_plat(dev);
Philippe Reynes3483aa22020-07-24 18:19:45 +020020
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
29enum 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
39UCLASS_DRIVER(button) = {
40 .id = UCLASS_BUTTON,
41 .name = "button",
Simon Glass71fa5b42020-12-03 16:55:18 -070042 .per_device_plat_auto = sizeof(struct button_uc_plat),
Philippe Reynes3483aa22020-07-24 18:19:45 +020043};