button.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. * get_code() - get linux event code of a button
  37. *
  38. * @dev: button device to change
  39. * @return button code, or -ENODATA on error
  40. */
  41. int (*get_code)(struct udevice *dev);
  42. };
  43. #define button_get_ops(dev) ((struct button_ops *)(dev)->driver->ops)
  44. /**
  45. * button_get_by_label() - Find a button device by label
  46. *
  47. * @label: button label to look up
  48. * @devp: Returns the associated device, if found
  49. * Return: 0 if found, -ENODEV if not found, other -ve on error
  50. */
  51. int button_get_by_label(const char *label, struct udevice **devp);
  52. /**
  53. * button_get_state() - get the state of a button
  54. *
  55. * @dev: button device to change
  56. * Return: button state button_state_t, or -ve on error
  57. */
  58. enum button_state_t button_get_state(struct udevice *dev);
  59. /**
  60. * button_get_code() - get linux event code of a button
  61. *
  62. * @dev: button device to change
  63. * @return button code, or -ve on error
  64. */
  65. int button_get_code(struct udevice *dev);
  66. #endif