2020-07-24 16:19:45 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2020 Philippe Reynes <philippe.reynes@softathome.com>
|
|
|
|
*
|
|
|
|
* Based on led-uclass.c
|
|
|
|
*/
|
|
|
|
|
2021-04-27 09:02:19 +00:00
|
|
|
#define LOG_CATEGORY UCLASS_BUTTON
|
|
|
|
|
2020-07-24 16:19:45 +00:00
|
|
|
#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) {
|
2020-12-03 23:55:18 +00:00
|
|
|
struct button_uc_plat *uc_plat = dev_get_uclass_plat(dev);
|
2020-07-24 16:19:45 +00:00
|
|
|
|
|
|
|
/* 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);
|
|
|
|
}
|
|
|
|
|
2023-01-22 15:21:24 +00:00
|
|
|
int button_get_code(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct button_ops *ops = button_get_ops(dev);
|
|
|
|
|
|
|
|
if (!ops->get_code)
|
|
|
|
return -ENOSYS;
|
|
|
|
|
|
|
|
return ops->get_code(dev);
|
|
|
|
}
|
|
|
|
|
2020-07-24 16:19:45 +00:00
|
|
|
UCLASS_DRIVER(button) = {
|
|
|
|
.id = UCLASS_BUTTON,
|
|
|
|
.name = "button",
|
2020-12-03 23:55:18 +00:00
|
|
|
.per_device_plat_auto = sizeof(struct button_uc_plat),
|
2020-07-24 16:19:45 +00:00
|
|
|
};
|