Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Thomas Chou | b1ed686 | 2015-10-07 20:20:51 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2015 Thomas Chou <thomas@wytron.com.tw> |
Thomas Chou | b1ed686 | 2015-10-07 20:20:51 +0800 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #ifndef _MISC_H_ |
| 7 | #define _MISC_H_ |
| 8 | |
Mario Six | 70943d6 | 2018-07-31 14:24:12 +0200 | [diff] [blame] | 9 | /** |
| 10 | * misc_read() - Read the device to buffer, optional. |
Thomas Chou | b1ed686 | 2015-10-07 20:20:51 +0800 | [diff] [blame] | 11 | * @dev: the device |
| 12 | * @offset: offset to read the device |
| 13 | * @buf: pointer to data buffer |
| 14 | * @size: data size in bytes to read the device |
Mario Six | 70943d6 | 2018-07-31 14:24:12 +0200 | [diff] [blame] | 15 | * |
Simon Glass | 587dc40 | 2018-11-06 15:21:39 -0700 | [diff] [blame^] | 16 | * Return: number of bytes read if OK (may be 0 if EOF), -ve on error |
Thomas Chou | b1ed686 | 2015-10-07 20:20:51 +0800 | [diff] [blame] | 17 | */ |
| 18 | int misc_read(struct udevice *dev, int offset, void *buf, int size); |
Mario Six | 70943d6 | 2018-07-31 14:24:12 +0200 | [diff] [blame] | 19 | |
| 20 | /** |
| 21 | * misc_write() - Write buffer to the device, optional. |
Thomas Chou | b1ed686 | 2015-10-07 20:20:51 +0800 | [diff] [blame] | 22 | * @dev: the device |
| 23 | * @offset: offset to write the device |
| 24 | * @buf: pointer to data buffer |
| 25 | * @size: data size in bytes to write the device |
Mario Six | 70943d6 | 2018-07-31 14:24:12 +0200 | [diff] [blame] | 26 | * |
Simon Glass | 587dc40 | 2018-11-06 15:21:39 -0700 | [diff] [blame^] | 27 | * Return: number of bytes written if OK (may be < @size), -ve on error |
Thomas Chou | b1ed686 | 2015-10-07 20:20:51 +0800 | [diff] [blame] | 28 | */ |
| 29 | int misc_write(struct udevice *dev, int offset, void *buf, int size); |
Mario Six | 70943d6 | 2018-07-31 14:24:12 +0200 | [diff] [blame] | 30 | |
| 31 | /** |
| 32 | * misc_ioctl() - Assert command to the device, optional. |
Thomas Chou | b1ed686 | 2015-10-07 20:20:51 +0800 | [diff] [blame] | 33 | * @dev: the device |
| 34 | * @request: command to be sent to the device |
Robert P. J. Day | 21c11c5 | 2015-12-14 06:28:51 -0500 | [diff] [blame] | 35 | * @buf: pointer to buffer related to the request |
Mario Six | 70943d6 | 2018-07-31 14:24:12 +0200 | [diff] [blame] | 36 | * |
| 37 | * Return: 0 if OK, -ve on error |
Thomas Chou | b1ed686 | 2015-10-07 20:20:51 +0800 | [diff] [blame] | 38 | */ |
| 39 | int misc_ioctl(struct udevice *dev, unsigned long request, void *buf); |
| 40 | |
Mario Six | 70943d6 | 2018-07-31 14:24:12 +0200 | [diff] [blame] | 41 | /** |
| 42 | * misc_call() - Send a message to the device and wait for a response. |
| 43 | * @dev: the device. |
| 44 | * @msgid: the message ID/number to send. |
| 45 | * @tx_msg: the request/transmit message payload. |
| 46 | * @tx_size: the size of the buffer pointed at by tx_msg. |
| 47 | * @rx_msg: the buffer to receive the response message payload. May be NULL if |
| 48 | * the caller only cares about the error code. |
| 49 | * @rx_size: the size of the buffer pointed at by rx_msg. |
Stephen Warren | 0163269 | 2016-08-08 09:41:33 -0600 | [diff] [blame] | 50 | * |
| 51 | * The caller provides the message type/ID and payload to be sent. |
| 52 | * The callee constructs any message header required, transmits it to the |
| 53 | * target, waits for a response, checks any error code in the response, |
| 54 | * strips any message header from the response, and returns the error code |
| 55 | * (or a parsed version of it) and the response message payload. |
| 56 | * |
Mario Six | 70943d6 | 2018-07-31 14:24:12 +0200 | [diff] [blame] | 57 | * Return: the response message size if OK, -ve on error |
Stephen Warren | 0163269 | 2016-08-08 09:41:33 -0600 | [diff] [blame] | 58 | */ |
| 59 | int misc_call(struct udevice *dev, int msgid, void *tx_msg, int tx_size, |
| 60 | void *rx_msg, int rx_size); |
| 61 | |
Mario Six | 70943d6 | 2018-07-31 14:24:12 +0200 | [diff] [blame] | 62 | /** |
Mario Six | 8909ad2 | 2018-07-31 14:24:13 +0200 | [diff] [blame] | 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 | /* |
Thomas Chou | b1ed686 | 2015-10-07 20:20:51 +0800 | [diff] [blame] | 80 | * struct misc_ops - Driver model Misc operations |
| 81 | * |
| 82 | * The uclass interface is implemented by all miscellaneous devices which |
| 83 | * use driver model. |
| 84 | */ |
| 85 | struct misc_ops { |
Mario Six | 70943d6 | 2018-07-31 14:24:12 +0200 | [diff] [blame] | 86 | /** |
Thomas Chou | b1ed686 | 2015-10-07 20:20:51 +0800 | [diff] [blame] | 87 | * Read the device to buffer, optional. |
Thomas Chou | b1ed686 | 2015-10-07 20:20:51 +0800 | [diff] [blame] | 88 | * @dev: the device |
| 89 | * @offset: offset to read the device |
| 90 | * @buf: pointer to data buffer |
| 91 | * @size: data size in bytes to read the device |
Mario Six | 70943d6 | 2018-07-31 14:24:12 +0200 | [diff] [blame] | 92 | * |
Simon Glass | 587dc40 | 2018-11-06 15:21:39 -0700 | [diff] [blame^] | 93 | * Return: number of bytes read if OK (may be 0 if EOF), -ve on error |
Thomas Chou | b1ed686 | 2015-10-07 20:20:51 +0800 | [diff] [blame] | 94 | */ |
| 95 | int (*read)(struct udevice *dev, int offset, void *buf, int size); |
Mario Six | 70943d6 | 2018-07-31 14:24:12 +0200 | [diff] [blame] | 96 | |
| 97 | /** |
Thomas Chou | b1ed686 | 2015-10-07 20:20:51 +0800 | [diff] [blame] | 98 | * Write buffer to the device, optional. |
Thomas Chou | b1ed686 | 2015-10-07 20:20:51 +0800 | [diff] [blame] | 99 | * @dev: the device |
| 100 | * @offset: offset to write the device |
| 101 | * @buf: pointer to data buffer |
| 102 | * @size: data size in bytes to write the device |
Mario Six | 70943d6 | 2018-07-31 14:24:12 +0200 | [diff] [blame] | 103 | * |
Simon Glass | 587dc40 | 2018-11-06 15:21:39 -0700 | [diff] [blame^] | 104 | * Return: number of bytes written if OK (may be < @size), -ve on error |
Thomas Chou | b1ed686 | 2015-10-07 20:20:51 +0800 | [diff] [blame] | 105 | */ |
| 106 | int (*write)(struct udevice *dev, int offset, const void *buf, |
| 107 | int size); |
Mario Six | 70943d6 | 2018-07-31 14:24:12 +0200 | [diff] [blame] | 108 | /** |
Thomas Chou | b1ed686 | 2015-10-07 20:20:51 +0800 | [diff] [blame] | 109 | * Assert command to the device, optional. |
Thomas Chou | b1ed686 | 2015-10-07 20:20:51 +0800 | [diff] [blame] | 110 | * @dev: the device |
| 111 | * @request: command to be sent to the device |
Robert P. J. Day | 21c11c5 | 2015-12-14 06:28:51 -0500 | [diff] [blame] | 112 | * @buf: pointer to buffer related to the request |
Mario Six | 70943d6 | 2018-07-31 14:24:12 +0200 | [diff] [blame] | 113 | * |
| 114 | * Return: 0 if OK, -ve on error |
Thomas Chou | b1ed686 | 2015-10-07 20:20:51 +0800 | [diff] [blame] | 115 | */ |
| 116 | int (*ioctl)(struct udevice *dev, unsigned long request, void *buf); |
Mario Six | 70943d6 | 2018-07-31 14:24:12 +0200 | [diff] [blame] | 117 | |
| 118 | /** |
Stephen Warren | 0163269 | 2016-08-08 09:41:33 -0600 | [diff] [blame] | 119 | * Send a message to the device and wait for a response. |
Stephen Warren | 0163269 | 2016-08-08 09:41:33 -0600 | [diff] [blame] | 120 | * @dev: the device |
| 121 | * @msgid: the message ID/number to send |
Mario Six | 70943d6 | 2018-07-31 14:24:12 +0200 | [diff] [blame] | 122 | * @tx_msg: the request/transmit message payload |
| 123 | * @tx_size: the size of the buffer pointed at by tx_msg |
| 124 | * @rx_msg: the buffer to receive the response message payload. May be |
| 125 | * NULL if the caller only cares about the error code. |
| 126 | * @rx_size: the size of the buffer pointed at by rx_msg |
| 127 | * |
| 128 | * Return: the response message size if OK, -ve on error |
Stephen Warren | 0163269 | 2016-08-08 09:41:33 -0600 | [diff] [blame] | 129 | */ |
| 130 | int (*call)(struct udevice *dev, int msgid, void *tx_msg, int tx_size, |
| 131 | void *rx_msg, int rx_size); |
Mario Six | 8909ad2 | 2018-07-31 14:24:13 +0200 | [diff] [blame] | 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); |
Thomas Chou | b1ed686 | 2015-10-07 20:20:51 +0800 | [diff] [blame] | 142 | }; |
| 143 | |
| 144 | #endif /* _MISC_H_ */ |