button-uclass.c 969 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // 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. #define LOG_CATEGORY UCLASS_BUTTON
  8. #include <common.h>
  9. #include <button.h>
  10. #include <dm.h>
  11. #include <dm/uclass-internal.h>
  12. int button_get_by_label(const char *label, struct udevice **devp)
  13. {
  14. struct udevice *dev;
  15. struct uclass *uc;
  16. uclass_id_foreach_dev(UCLASS_BUTTON, dev, uc) {
  17. struct button_uc_plat *uc_plat = dev_get_uclass_plat(dev);
  18. /* Ignore the top-level button node */
  19. if (uc_plat->label && !strcmp(label, uc_plat->label))
  20. return uclass_get_device_tail(dev, 0, devp);
  21. }
  22. return -ENODEV;
  23. }
  24. enum button_state_t button_get_state(struct udevice *dev)
  25. {
  26. struct button_ops *ops = button_get_ops(dev);
  27. if (!ops->get_state)
  28. return -ENOSYS;
  29. return ops->get_state(dev);
  30. }
  31. UCLASS_DRIVER(button) = {
  32. .id = UCLASS_BUTTON,
  33. .name = "button",
  34. .per_device_plat_auto = sizeof(struct button_uc_plat),
  35. };