Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Thomas Chou | 4395e06 | 2015-10-07 20:20:51 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2015 Thomas Chou <thomas@wytron.com.tw> |
Thomas Chou | 4395e06 | 2015-10-07 20:20:51 +0800 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #ifndef _MISC_H_ |
| 7 | #define _MISC_H_ |
| 8 | |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 9 | struct udevice; |
| 10 | |
Mario Six | 3958bff | 2018-07-31 14:24:12 +0200 | [diff] [blame] | 11 | /** |
| 12 | * misc_read() - Read the device to buffer, optional. |
Thomas Chou | 4395e06 | 2015-10-07 20:20:51 +0800 | [diff] [blame] | 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 |
Mario Six | 3958bff | 2018-07-31 14:24:12 +0200 | [diff] [blame] | 17 | * |
Simon Glass | 8729b1a | 2018-11-06 15:21:39 -0700 | [diff] [blame] | 18 | * Return: number of bytes read if OK (may be 0 if EOF), -ve on error |
Thomas Chou | 4395e06 | 2015-10-07 20:20:51 +0800 | [diff] [blame] | 19 | */ |
| 20 | int misc_read(struct udevice *dev, int offset, void *buf, int size); |
Mario Six | 3958bff | 2018-07-31 14:24:12 +0200 | [diff] [blame] | 21 | |
| 22 | /** |
| 23 | * misc_write() - Write buffer to the device, optional. |
Thomas Chou | 4395e06 | 2015-10-07 20:20:51 +0800 | [diff] [blame] | 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 |
Mario Six | 3958bff | 2018-07-31 14:24:12 +0200 | [diff] [blame] | 28 | * |
Simon Glass | 8729b1a | 2018-11-06 15:21:39 -0700 | [diff] [blame] | 29 | * Return: number of bytes written if OK (may be < @size), -ve on error |
Thomas Chou | 4395e06 | 2015-10-07 20:20:51 +0800 | [diff] [blame] | 30 | */ |
John Keeping | e44d2f5 | 2022-01-11 17:04:49 +0000 | [diff] [blame] | 31 | int misc_write(struct udevice *dev, int offset, const void *buf, int size); |
Mario Six | 3958bff | 2018-07-31 14:24:12 +0200 | [diff] [blame] | 32 | |
| 33 | /** |
| 34 | * misc_ioctl() - Assert command to the device, optional. |
Thomas Chou | 4395e06 | 2015-10-07 20:20:51 +0800 | [diff] [blame] | 35 | * @dev: the device |
| 36 | * @request: command to be sent to the device |
Robert P. J. Day | f5abb40 | 2015-12-14 06:28:51 -0500 | [diff] [blame] | 37 | * @buf: pointer to buffer related to the request |
Mario Six | 3958bff | 2018-07-31 14:24:12 +0200 | [diff] [blame] | 38 | * |
| 39 | * Return: 0 if OK, -ve on error |
Thomas Chou | 4395e06 | 2015-10-07 20:20:51 +0800 | [diff] [blame] | 40 | */ |
| 41 | int misc_ioctl(struct udevice *dev, unsigned long request, void *buf); |
| 42 | |
Mario Six | 3958bff | 2018-07-31 14:24:12 +0200 | [diff] [blame] | 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. |
Stephen Warren | b647f55 | 2016-08-08 09:41:33 -0600 | [diff] [blame] | 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 | * |
Mario Six | 3958bff | 2018-07-31 14:24:12 +0200 | [diff] [blame] | 59 | * Return: the response message size if OK, -ve on error |
Stephen Warren | b647f55 | 2016-08-08 09:41:33 -0600 | [diff] [blame] | 60 | */ |
| 61 | int misc_call(struct udevice *dev, int msgid, void *tx_msg, int tx_size, |
| 62 | void *rx_msg, int rx_size); |
| 63 | |
Mario Six | 3958bff | 2018-07-31 14:24:12 +0200 | [diff] [blame] | 64 | /** |
Mario Six | 440bc11 | 2018-07-31 14:24:13 +0200 | [diff] [blame] | 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 | /* |
Thomas Chou | 4395e06 | 2015-10-07 20:20:51 +0800 | [diff] [blame] | 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 { |
Mario Six | 3958bff | 2018-07-31 14:24:12 +0200 | [diff] [blame] | 88 | /** |
Thomas Chou | 4395e06 | 2015-10-07 20:20:51 +0800 | [diff] [blame] | 89 | * Read the device to buffer, optional. |
Thomas Chou | 4395e06 | 2015-10-07 20:20:51 +0800 | [diff] [blame] | 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 |
Mario Six | 3958bff | 2018-07-31 14:24:12 +0200 | [diff] [blame] | 94 | * |
Simon Glass | 8729b1a | 2018-11-06 15:21:39 -0700 | [diff] [blame] | 95 | * Return: number of bytes read if OK (may be 0 if EOF), -ve on error |
Thomas Chou | 4395e06 | 2015-10-07 20:20:51 +0800 | [diff] [blame] | 96 | */ |
| 97 | int (*read)(struct udevice *dev, int offset, void *buf, int size); |
Mario Six | 3958bff | 2018-07-31 14:24:12 +0200 | [diff] [blame] | 98 | |
| 99 | /** |
Thomas Chou | 4395e06 | 2015-10-07 20:20:51 +0800 | [diff] [blame] | 100 | * Write buffer to the device, optional. |
Thomas Chou | 4395e06 | 2015-10-07 20:20:51 +0800 | [diff] [blame] | 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 |
Mario Six | 3958bff | 2018-07-31 14:24:12 +0200 | [diff] [blame] | 105 | * |
Simon Glass | 8729b1a | 2018-11-06 15:21:39 -0700 | [diff] [blame] | 106 | * Return: number of bytes written if OK (may be < @size), -ve on error |
Thomas Chou | 4395e06 | 2015-10-07 20:20:51 +0800 | [diff] [blame] | 107 | */ |
| 108 | int (*write)(struct udevice *dev, int offset, const void *buf, |
| 109 | int size); |
Mario Six | 3958bff | 2018-07-31 14:24:12 +0200 | [diff] [blame] | 110 | /** |
Thomas Chou | 4395e06 | 2015-10-07 20:20:51 +0800 | [diff] [blame] | 111 | * Assert command to the device, optional. |
Thomas Chou | 4395e06 | 2015-10-07 20:20:51 +0800 | [diff] [blame] | 112 | * @dev: the device |
| 113 | * @request: command to be sent to the device |
Robert P. J. Day | f5abb40 | 2015-12-14 06:28:51 -0500 | [diff] [blame] | 114 | * @buf: pointer to buffer related to the request |
Mario Six | 3958bff | 2018-07-31 14:24:12 +0200 | [diff] [blame] | 115 | * |
| 116 | * Return: 0 if OK, -ve on error |
Thomas Chou | 4395e06 | 2015-10-07 20:20:51 +0800 | [diff] [blame] | 117 | */ |
| 118 | int (*ioctl)(struct udevice *dev, unsigned long request, void *buf); |
Mario Six | 3958bff | 2018-07-31 14:24:12 +0200 | [diff] [blame] | 119 | |
| 120 | /** |
Stephen Warren | b647f55 | 2016-08-08 09:41:33 -0600 | [diff] [blame] | 121 | * Send a message to the device and wait for a response. |
Stephen Warren | b647f55 | 2016-08-08 09:41:33 -0600 | [diff] [blame] | 122 | * @dev: the device |
| 123 | * @msgid: the message ID/number to send |
Mario Six | 3958bff | 2018-07-31 14:24:12 +0200 | [diff] [blame] | 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 |
Stephen Warren | b647f55 | 2016-08-08 09:41:33 -0600 | [diff] [blame] | 131 | */ |
| 132 | int (*call)(struct udevice *dev, int msgid, void *tx_msg, int tx_size, |
| 133 | void *rx_msg, int rx_size); |
Mario Six | 440bc11 | 2018-07-31 14:24:13 +0200 | [diff] [blame] | 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); |
Thomas Chou | 4395e06 | 2015-10-07 20:20:51 +0800 | [diff] [blame] | 144 | }; |
| 145 | |
| 146 | #endif /* _MISC_H_ */ |