1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Copyright (C) 2015 Thomas Chou <thomas@wytron.com.tw>
12 * misc_read() - Read the device to buffer, optional.
14 * @offset: offset to read the device
15 * @buf: pointer to data buffer
16 * @size: data size in bytes to read the device
18 * Return: number of bytes read if OK (may be 0 if EOF), -ve on error
20 int misc_read(struct udevice *dev, int offset, void *buf, int size);
23 * misc_write() - Write buffer to the device, optional.
25 * @offset: offset to write the device
26 * @buf: pointer to data buffer
27 * @size: data size in bytes to write the device
29 * Return: number of bytes written if OK (may be < @size), -ve on error
31 int misc_write(struct udevice *dev, int offset, void *buf, int size);
34 * misc_ioctl() - Assert command to the device, optional.
36 * @request: command to be sent to the device
37 * @buf: pointer to buffer related to the request
39 * Return: 0 if OK, -ve on error
41 int misc_ioctl(struct udevice *dev, unsigned long request, void *buf);
44 * misc_call() - Send a message to the device and wait for a response.
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.
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.
59 * Return: the response message size if OK, -ve on error
61 int misc_call(struct udevice *dev, int msgid, void *tx_msg, int tx_size,
62 void *rx_msg, int rx_size);
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.
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.
73 * A probed device may start in a disabled or enabled state, depending on the
74 * driver and hardware.
76 * Return: -ve on error, 0 if the previous state was "disabled", 1 if the
77 * previous state was "enabled"
79 int misc_set_enabled(struct udevice *dev, bool val);
82 * struct misc_ops - Driver model Misc operations
84 * The uclass interface is implemented by all miscellaneous devices which
89 * Read the device to buffer, optional.
91 * @offset: offset to read the device
92 * @buf: pointer to data buffer
93 * @size: data size in bytes to read the device
95 * Return: number of bytes read if OK (may be 0 if EOF), -ve on error
97 int (*read)(struct udevice *dev, int offset, void *buf, int size);
100 * Write buffer to the device, optional.
102 * @offset: offset to write the device
103 * @buf: pointer to data buffer
104 * @size: data size in bytes to write the device
106 * Return: number of bytes written if OK (may be < @size), -ve on error
108 int (*write)(struct udevice *dev, int offset, const void *buf,
111 * Assert command to the device, optional.
113 * @request: command to be sent to the device
114 * @buf: pointer to buffer related to the request
116 * Return: 0 if OK, -ve on error
118 int (*ioctl)(struct udevice *dev, unsigned long request, void *buf);
121 * Send a message to the device and wait for a response.
123 * @msgid: the message ID/number to send
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
130 * Return: the response message size if OK, -ve on error
132 int (*call)(struct udevice *dev, int msgid, void *tx_msg, int tx_size,
133 void *rx_msg, int rx_size);
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
140 * Return: -ve on error, 0 if the previous state was "disabled", 1 if
141 * the previous state was "enabled"
143 int (*set_enabled)(struct udevice *dev, bool val);
146 #endif /* _MISC_H_ */