Commit 440bc11f2e10dd80c7f5e717bc52daff73091bd5
Committed by
Anatolij Gustschin
1 parent
3958bffeb3
Exists in
smarc_8mq_lf_v2020.04
and in
11 other branches
misc: uclass: Add enable/disable function
Add generic enable/disable function to the misc uclass. Reviewed-by: Simon Glass <sjg@chromium.org> Signed-off-by: Mario Six <mario.six@gdsys.cc>
Showing 2 changed files with 37 additions and 0 deletions Side-by-side Diff
drivers/misc/misc-uclass.c
... | ... | @@ -55,6 +55,16 @@ |
55 | 55 | return ops->call(dev, msgid, tx_msg, tx_size, rx_msg, rx_size); |
56 | 56 | } |
57 | 57 | |
58 | +int misc_set_enabled(struct udevice *dev, bool val) | |
59 | +{ | |
60 | + const struct misc_ops *ops = device_get_ops(dev); | |
61 | + | |
62 | + if (!ops->set_enabled) | |
63 | + return -ENOSYS; | |
64 | + | |
65 | + return ops->set_enabled(dev, val); | |
66 | +} | |
67 | + | |
58 | 68 | UCLASS_DRIVER(misc) = { |
59 | 69 | .id = UCLASS_MISC, |
60 | 70 | .name = "misc", |
include/misc.h
... | ... | @@ -60,6 +60,23 @@ |
60 | 60 | void *rx_msg, int rx_size); |
61 | 61 | |
62 | 62 | /** |
63 | + * misc_set_enabled() - Enable or disable a device. | |
64 | + * @dev: the device to enable or disable. | |
65 | + * @val: the flag that tells the driver to either enable or disable the device. | |
66 | + * | |
67 | + * The semantics of "disable" and "enable" should be understood here as | |
68 | + * activating or deactivating the device's primary function, hence a "disabled" | |
69 | + * device should be dormant, but still answer to commands and queries. | |
70 | + * | |
71 | + * A probed device may start in a disabled or enabled state, depending on the | |
72 | + * driver and hardware. | |
73 | + * | |
74 | + * Return: -ve on error, 0 if the previous state was "disabled", 1 if the | |
75 | + * previous state was "enabled" | |
76 | + */ | |
77 | +int misc_set_enabled(struct udevice *dev, bool val); | |
78 | + | |
79 | +/* | |
63 | 80 | * struct misc_ops - Driver model Misc operations |
64 | 81 | * |
65 | 82 | * The uclass interface is implemented by all miscellaneous devices which |
... | ... | @@ -112,6 +129,16 @@ |
112 | 129 | */ |
113 | 130 | int (*call)(struct udevice *dev, int msgid, void *tx_msg, int tx_size, |
114 | 131 | void *rx_msg, int rx_size); |
132 | + /** | |
133 | + * Enable or disable a device, optional. | |
134 | + * @dev: the device to enable. | |
135 | + * @val: the flag that tells the driver to either enable or disable the | |
136 | + * device. | |
137 | + * | |
138 | + * Return: -ve on error, 0 if the previous state was "disabled", 1 if | |
139 | + * the previous state was "enabled" | |
140 | + */ | |
141 | + int (*set_enabled)(struct udevice *dev, bool val); | |
115 | 142 | }; |
116 | 143 | |
117 | 144 | #endif /* _MISC_H_ */ |