diff options
author | Philippe Reynes <philippe.reynes@softathome.com> | 2020-07-24 18:19:45 +0200 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2020-07-28 19:30:39 -0600 |
commit | 30d66db78725e8396a3bd255cc51592c6cd7879d (patch) | |
tree | 90d70ab789bfb6e85522a989ca9631174bf45a60 /include/button.h | |
parent | 037a56d6b1e2a2ce45454b2629800ee5e7f6b46e (diff) | |
download | u-boot-30d66db78725e8396a3bd255cc51592c6cd7879d.tar.gz |
dm: button: add an uclass for button
Add a new uclass for button that implements two functions:
- button_get_by_label
- button_get_status
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Diffstat (limited to 'include/button.h')
-rw-r--r-- | include/button.h | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/include/button.h b/include/button.h new file mode 100644 index 0000000000..688b63b082 --- /dev/null +++ b/include/button.h @@ -0,0 +1,59 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (C) 2020 Philippe Reynes <philippe.reynes@softathome.com> + */ + +#ifndef __BUTTON_H +#define __BUTTON_H + +/** + * struct button_uc_plat - Platform data the uclass stores about each device + * + * @label: Button label + */ +struct button_uc_plat { + const char *label; +}; + +/** + * enum button_state_t - State used for button + * - BUTTON_OFF - Button is not pressed + * - BUTTON_ON - Button is pressed + * - BUTTON_COUNT - Number of button state + */ +enum button_state_t { + BUTTON_OFF = 0, + BUTTON_ON = 1, + BUTTON_COUNT, +}; + +struct button_ops { + /** + * get_state() - get the state of a button + * + * @dev: button device to change + * @return button state button_state_t, or -ve on error + */ + enum button_state_t (*get_state)(struct udevice *dev); +}; + +#define button_get_ops(dev) ((struct button_ops *)(dev)->driver->ops) + +/** + * button_get_by_label() - Find a button device by label + * + * @label: button label to look up + * @devp: Returns the associated device, if found + * @return 0 if found, -ENODEV if not found, other -ve on error + */ +int button_get_by_label(const char *label, struct udevice **devp); + +/** + * button_get_state() - get the state of a button + * + * @dev: button device to change + * @return button state button_state_t, or -ve on error + */ +enum button_state_t button_get_state(struct udevice *dev); + +#endif |