blob: cda243389df3b4f728a14c3295a75fd67d6a9624 [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
Patrick Delaunay81313352021-04-27 11:02:19 +02008#define LOG_CATEGORY UCLASS_BUTTON
9
Philippe Reynes3483aa22020-07-24 18:19:45 +020010#include <button.h>
11#include <dm.h>
12#include <dm/uclass-internal.h>
13
14int button_get_by_label(const char *label, struct udevice **devp)
15{
16 struct udevice *dev;
17 struct uclass *uc;
18
19 uclass_id_foreach_dev(UCLASS_BUTTON, dev, uc) {
Simon Glass71fa5b42020-12-03 16:55:18 -070020 struct button_uc_plat *uc_plat = dev_get_uclass_plat(dev);
Philippe Reynes3483aa22020-07-24 18:19:45 +020021
22 /* Ignore the top-level button node */
23 if (uc_plat->label && !strcmp(label, uc_plat->label))
24 return uclass_get_device_tail(dev, 0, devp);
25 }
26
27 return -ENODEV;
28}
29
30enum button_state_t button_get_state(struct udevice *dev)
31{
32 struct button_ops *ops = button_get_ops(dev);
33
34 if (!ops->get_state)
35 return -ENOSYS;
36
37 return ops->get_state(dev);
38}
39
Dzmitry Sankouski157f2c52023-01-22 18:21:24 +030040int button_get_code(struct udevice *dev)
41{
42 struct button_ops *ops = button_get_ops(dev);
43
44 if (!ops->get_code)
45 return -ENOSYS;
46
47 return ops->get_code(dev);
48}
49
Philippe Reynes3483aa22020-07-24 18:19:45 +020050UCLASS_DRIVER(button) = {
51 .id = UCLASS_BUTTON,
52 .name = "button",
Simon Glass71fa5b42020-12-03 16:55:18 -070053 .per_device_plat_auto = sizeof(struct button_uc_plat),
Philippe Reynes3483aa22020-07-24 18:19:45 +020054};