button.h 1.3 KB

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