diff options
| author | Tom Rini <trini@konsulko.com> | 2020-07-29 21:16:08 -0400 |
|---|---|---|
| committer | Tom Rini <trini@konsulko.com> | 2020-07-29 21:16:08 -0400 |
| commit | 719f42190d5f0238cb01ef2ffba8af2285f7bc7a (patch) | |
| tree | c789716a82ab552e0d0c1a9242fda7c41b04c238 /drivers/button/button-uclass.c | |
| parent | 7cb2060b4e63a89c50739dc8a9fcd5d73f86f0be (diff) | |
| parent | b9390ce51cb46f4b4acda320e7ea8e0bd120e4b8 (diff) | |
Merge tag 'dm-pull-28jul20' of git://git.denx.de/u-boot-dm
Use binman instead of one of the Rockchip build scripts
Refactor to allow any arch to create SPI-flash images
New button uclass
Diffstat (limited to 'drivers/button/button-uclass.c')
| -rw-r--r-- | drivers/button/button-uclass.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/drivers/button/button-uclass.c b/drivers/button/button-uclass.c new file mode 100644 index 0000000000..1c742c265c --- /dev/null +++ b/drivers/button/button-uclass.c @@ -0,0 +1,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), +}; |
