button-uclass.c 933 B

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