Philippe Reynes | 3483aa2 | 2020-07-24 18:19:45 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
| 2 | /* |
| 3 | * Copyright (C) 2020 Philippe Reynes <philippe.reynes@softathome.com> |
| 4 | */ |
| 5 | |
| 6 | #ifndef __BUTTON_H |
| 7 | #define __BUTTON_H |
| 8 | |
Neil Armstrong | 0a322d9 | 2021-02-19 08:31:47 +0100 | [diff] [blame] | 9 | struct udevice; |
| 10 | |
Philippe Reynes | 3483aa2 | 2020-07-24 18:19:45 +0200 | [diff] [blame] | 11 | /** |
| 12 | * struct button_uc_plat - Platform data the uclass stores about each device |
| 13 | * |
| 14 | * @label: Button label |
| 15 | */ |
| 16 | struct button_uc_plat { |
| 17 | const char *label; |
| 18 | }; |
| 19 | |
| 20 | /** |
| 21 | * enum button_state_t - State used for button |
| 22 | * - BUTTON_OFF - Button is not pressed |
| 23 | * - BUTTON_ON - Button is pressed |
| 24 | * - BUTTON_COUNT - Number of button state |
| 25 | */ |
| 26 | enum button_state_t { |
| 27 | BUTTON_OFF = 0, |
| 28 | BUTTON_ON = 1, |
| 29 | BUTTON_COUNT, |
| 30 | }; |
| 31 | |
| 32 | struct button_ops { |
| 33 | /** |
| 34 | * get_state() - get the state of a button |
| 35 | * |
| 36 | * @dev: button device to change |
| 37 | * @return button state button_state_t, or -ve on error |
| 38 | */ |
| 39 | enum button_state_t (*get_state)(struct udevice *dev); |
Dzmitry Sankouski | 157f2c5 | 2023-01-22 18:21:24 +0300 | [diff] [blame] | 40 | |
| 41 | /** |
| 42 | * get_code() - get linux event code of a button |
| 43 | * |
| 44 | * @dev: button device to change |
| 45 | * @return button code, or -ENODATA on error |
| 46 | */ |
| 47 | int (*get_code)(struct udevice *dev); |
Philippe Reynes | 3483aa2 | 2020-07-24 18:19:45 +0200 | [diff] [blame] | 48 | }; |
| 49 | |
| 50 | #define button_get_ops(dev) ((struct button_ops *)(dev)->driver->ops) |
| 51 | |
| 52 | /** |
| 53 | * button_get_by_label() - Find a button device by label |
| 54 | * |
| 55 | * @label: button label to look up |
| 56 | * @devp: Returns the associated device, if found |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 57 | * Return: 0 if found, -ENODEV if not found, other -ve on error |
Philippe Reynes | 3483aa2 | 2020-07-24 18:19:45 +0200 | [diff] [blame] | 58 | */ |
| 59 | int button_get_by_label(const char *label, struct udevice **devp); |
| 60 | |
| 61 | /** |
| 62 | * button_get_state() - get the state of a button |
| 63 | * |
| 64 | * @dev: button device to change |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 65 | * Return: button state button_state_t, or -ve on error |
Philippe Reynes | 3483aa2 | 2020-07-24 18:19:45 +0200 | [diff] [blame] | 66 | */ |
| 67 | enum button_state_t button_get_state(struct udevice *dev); |
| 68 | |
Dzmitry Sankouski | 157f2c5 | 2023-01-22 18:21:24 +0300 | [diff] [blame] | 69 | /** |
| 70 | * button_get_code() - get linux event code of a button |
| 71 | * |
| 72 | * @dev: button device to change |
| 73 | * @return button code, or -ve on error |
| 74 | */ |
| 75 | int button_get_code(struct udevice *dev); |
| 76 | |
Caleb Connolly | 2259c29 | 2024-01-09 11:51:09 +0000 | [diff] [blame] | 77 | #if IS_ENABLED(CONFIG_BUTTON_CMD) |
| 78 | /* Process button command mappings specified in the environment, |
| 79 | * running the commands for buttons which are pressed |
| 80 | */ |
| 81 | void process_button_cmds(void); |
| 82 | #else |
| 83 | static inline void process_button_cmds(void) {} |
| 84 | #endif /* CONFIG_BUTTON_CMD */ |
| 85 | |
Philippe Reynes | 3483aa2 | 2020-07-24 18:19:45 +0200 | [diff] [blame] | 86 | #endif |