button.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright (C) 2020 Philippe Reynes <philippe.reynes@softathome.com>
  4. */
  5. #ifndef __BUTTON_H
  6. #define __BUTTON_H
  7. struct udevice;
  8. /**
  9. * struct button_uc_plat - Platform data the uclass stores about each device
  10. *
  11. * @label: Button label
  12. */
  13. struct button_uc_plat {
  14. const char *label;
  15. };
  16. /**
  17. * enum button_state_t - State used for button
  18. * - BUTTON_OFF - Button is not pressed
  19. * - BUTTON_ON - Button is pressed
  20. * - BUTTON_COUNT - Number of button state
  21. */
  22. enum button_state_t {
  23. BUTTON_OFF = 0,
  24. BUTTON_ON = 1,
  25. BUTTON_COUNT,
  26. };
  27. struct button_ops {
  28. /**
  29. * get_state() - get the state of a button
  30. *
  31. * @dev: button device to change
  32. * @return button state button_state_t, or -ve on error
  33. */
  34. enum button_state_t (*get_state)(struct udevice *dev);
  35. };
  36. #define button_get_ops(dev) ((struct button_ops *)(dev)->driver->ops)
  37. /**
  38. * button_get_by_label() - Find a button device by label
  39. *
  40. * @label: button label to look up
  41. * @devp: Returns the associated device, if found
  42. * @return 0 if found, -ENODEV if not found, other -ve on error
  43. */
  44. int button_get_by_label(const char *label, struct udevice **devp);
  45. /**
  46. * button_get_state() - get the state of a button
  47. *
  48. * @dev: button device to change
  49. * @return button state button_state_t, or -ve on error
  50. */
  51. enum button_state_t button_get_state(struct udevice *dev);
  52. #endif