]>
Commit | Line | Data |
---|---|---|
83d290c5 | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
4395e06e TC |
2 | /* |
3 | * Copyright (C) 2015 Thomas Chou <[email protected]> | |
4395e06e TC |
4 | */ |
5 | ||
6 | #ifndef _MISC_H_ | |
7 | #define _MISC_H_ | |
8 | ||
401d1c4f SG |
9 | struct udevice; |
10 | ||
3958bffe MS |
11 | /** |
12 | * misc_read() - Read the device to buffer, optional. | |
4395e06e TC |
13 | * @dev: the device |
14 | * @offset: offset to read the device | |
15 | * @buf: pointer to data buffer | |
16 | * @size: data size in bytes to read the device | |
3958bffe | 17 | * |
8729b1ae | 18 | * Return: number of bytes read if OK (may be 0 if EOF), -ve on error |
4395e06e TC |
19 | */ |
20 | int misc_read(struct udevice *dev, int offset, void *buf, int size); | |
3958bffe MS |
21 | |
22 | /** | |
23 | * misc_write() - Write buffer to the device, optional. | |
4395e06e TC |
24 | * @dev: the device |
25 | * @offset: offset to write the device | |
26 | * @buf: pointer to data buffer | |
27 | * @size: data size in bytes to write the device | |
3958bffe | 28 | * |
8729b1ae | 29 | * Return: number of bytes written if OK (may be < @size), -ve on error |
4395e06e | 30 | */ |
e44d2f5d | 31 | int misc_write(struct udevice *dev, int offset, const void *buf, int size); |
3958bffe MS |
32 | |
33 | /** | |
34 | * misc_ioctl() - Assert command to the device, optional. | |
4395e06e TC |
35 | * @dev: the device |
36 | * @request: command to be sent to the device | |
f5abb409 | 37 | * @buf: pointer to buffer related to the request |
3958bffe MS |
38 | * |
39 | * Return: 0 if OK, -ve on error | |
4395e06e TC |
40 | */ |
41 | int misc_ioctl(struct udevice *dev, unsigned long request, void *buf); | |
42 | ||
3958bffe MS |
43 | /** |
44 | * misc_call() - Send a message to the device and wait for a response. | |
45 | * @dev: the device. | |
46 | * @msgid: the message ID/number to send. | |
47 | * @tx_msg: the request/transmit message payload. | |
48 | * @tx_size: the size of the buffer pointed at by tx_msg. | |
49 | * @rx_msg: the buffer to receive the response message payload. May be NULL if | |
50 | * the caller only cares about the error code. | |
51 | * @rx_size: the size of the buffer pointed at by rx_msg. | |
b647f554 SW |
52 | * |
53 | * The caller provides the message type/ID and payload to be sent. | |
54 | * The callee constructs any message header required, transmits it to the | |
55 | * target, waits for a response, checks any error code in the response, | |
56 | * strips any message header from the response, and returns the error code | |
57 | * (or a parsed version of it) and the response message payload. | |
58 | * | |
3958bffe | 59 | * Return: the response message size if OK, -ve on error |
b647f554 SW |
60 | */ |
61 | int misc_call(struct udevice *dev, int msgid, void *tx_msg, int tx_size, | |
62 | void *rx_msg, int rx_size); | |
63 | ||
3958bffe | 64 | /** |
440bc11f MS |
65 | * misc_set_enabled() - Enable or disable a device. |
66 | * @dev: the device to enable or disable. | |
67 | * @val: the flag that tells the driver to either enable or disable the device. | |
68 | * | |
69 | * The semantics of "disable" and "enable" should be understood here as | |
70 | * activating or deactivating the device's primary function, hence a "disabled" | |
71 | * device should be dormant, but still answer to commands and queries. | |
72 | * | |
73 | * A probed device may start in a disabled or enabled state, depending on the | |
74 | * driver and hardware. | |
75 | * | |
76 | * Return: -ve on error, 0 if the previous state was "disabled", 1 if the | |
77 | * previous state was "enabled" | |
78 | */ | |
79 | int misc_set_enabled(struct udevice *dev, bool val); | |
80 | ||
81 | /* | |
4395e06e TC |
82 | * struct misc_ops - Driver model Misc operations |
83 | * | |
84 | * The uclass interface is implemented by all miscellaneous devices which | |
85 | * use driver model. | |
86 | */ | |
87 | struct misc_ops { | |
3958bffe | 88 | /** |
4395e06e | 89 | * Read the device to buffer, optional. |
4395e06e TC |
90 | * @dev: the device |
91 | * @offset: offset to read the device | |
92 | * @buf: pointer to data buffer | |
93 | * @size: data size in bytes to read the device | |
3958bffe | 94 | * |
8729b1ae | 95 | * Return: number of bytes read if OK (may be 0 if EOF), -ve on error |
4395e06e TC |
96 | */ |
97 | int (*read)(struct udevice *dev, int offset, void *buf, int size); | |
3958bffe MS |
98 | |
99 | /** | |
4395e06e | 100 | * Write buffer to the device, optional. |
4395e06e TC |
101 | * @dev: the device |
102 | * @offset: offset to write the device | |
103 | * @buf: pointer to data buffer | |
104 | * @size: data size in bytes to write the device | |
3958bffe | 105 | * |
8729b1ae | 106 | * Return: number of bytes written if OK (may be < @size), -ve on error |
4395e06e TC |
107 | */ |
108 | int (*write)(struct udevice *dev, int offset, const void *buf, | |
109 | int size); | |
3958bffe | 110 | /** |
4395e06e | 111 | * Assert command to the device, optional. |
4395e06e TC |
112 | * @dev: the device |
113 | * @request: command to be sent to the device | |
f5abb409 | 114 | * @buf: pointer to buffer related to the request |
3958bffe MS |
115 | * |
116 | * Return: 0 if OK, -ve on error | |
4395e06e TC |
117 | */ |
118 | int (*ioctl)(struct udevice *dev, unsigned long request, void *buf); | |
3958bffe MS |
119 | |
120 | /** | |
b647f554 | 121 | * Send a message to the device and wait for a response. |
b647f554 SW |
122 | * @dev: the device |
123 | * @msgid: the message ID/number to send | |
3958bffe MS |
124 | * @tx_msg: the request/transmit message payload |
125 | * @tx_size: the size of the buffer pointed at by tx_msg | |
126 | * @rx_msg: the buffer to receive the response message payload. May be | |
127 | * NULL if the caller only cares about the error code. | |
128 | * @rx_size: the size of the buffer pointed at by rx_msg | |
129 | * | |
130 | * Return: the response message size if OK, -ve on error | |
b647f554 SW |
131 | */ |
132 | int (*call)(struct udevice *dev, int msgid, void *tx_msg, int tx_size, | |
133 | void *rx_msg, int rx_size); | |
440bc11f MS |
134 | /** |
135 | * Enable or disable a device, optional. | |
136 | * @dev: the device to enable. | |
137 | * @val: the flag that tells the driver to either enable or disable the | |
138 | * device. | |
139 | * | |
140 | * Return: -ve on error, 0 if the previous state was "disabled", 1 if | |
141 | * the previous state was "enabled" | |
142 | */ | |
143 | int (*set_enabled)(struct udevice *dev, bool val); | |
4395e06e TC |
144 | }; |
145 | ||
146 | #endif /* _MISC_H_ */ |