1 /* 2 * Copyright (C) 2015 Thomas Chou <thomas@wytron.com.tw> 3 * 4 * SPDX-License-Identifier: GPL-2.0+ 5 */ 6 7 #ifndef _MISC_H_ 8 #define _MISC_H_ 9 10 #include <asm-generic/ioctl.h> 11 12 /* 13 * Request command to be sent for misc_ioctl(). 14 */ 15 #define IOCTL_REQ_START _IO('m', 0x01) 16 #define IOCTL_REQ_STOP _IO('m', 0x02) 17 #define IOCTL_REQ_POLL _IO('m', 0x03) 18 #define IOCTL_REQ_CAPABILITY _IO('m', 0x04) 19 20 /* 21 * Read the device to buffer, optional. 22 * 23 * @dev: the device 24 * @offset: offset to read the device 25 * @buf: pointer to data buffer 26 * @size: data size in bytes to read the device 27 * @return: 0 if OK, -ve on error 28 */ 29 int misc_read(struct udevice *dev, int offset, void *buf, int size); 30 /* 31 * Write buffer to the device, optional. 32 * 33 * @dev: the device 34 * @offset: offset to write the device 35 * @buf: pointer to data buffer 36 * @size: data size in bytes to write the device 37 * @return: 0 if OK, -ve on error 38 */ 39 int misc_write(struct udevice *dev, int offset, void *buf, int size); 40 /* 41 * Assert command to the device, optional. 42 * 43 * @dev: the device 44 * @request: command to be sent to the device 45 * @buf: pointer to buffer related to the request 46 * @return: 0 if OK, -ve on error 47 */ 48 int misc_ioctl(struct udevice *dev, unsigned long request, void *buf); 49 50 /* 51 * Send a message to the device and wait for a response. 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 * 59 * @dev: the device. 60 * @msgid: the message ID/number to send. 61 * tx_msg: the request/transmit message payload. 62 * tx_size: the size of the buffer pointed at by tx_msg. 63 * rx_msg: the buffer to receive the response message payload. May be NULL if 64 * the caller only cares about the error code. 65 * rx_size: the size of the buffer pointed at by rx_msg. 66 * @return the response message size if OK, -ve on error 67 */ 68 int misc_call(struct udevice *dev, int msgid, void *tx_msg, int tx_size, 69 void *rx_msg, int rx_size); 70 71 /* 72 * struct misc_ops - Driver model Misc operations 73 * 74 * The uclass interface is implemented by all miscellaneous devices which 75 * use driver model. 76 */ 77 struct misc_ops { 78 /* 79 * Read the device to buffer, optional. 80 * 81 * @dev: the device 82 * @offset: offset to read the device 83 * @buf: pointer to data buffer 84 * @size: data size in bytes to read the device 85 * @return: 0 if OK, -ve on error 86 */ 87 int (*read)(struct udevice *dev, int offset, void *buf, int size); 88 /* 89 * Write buffer to the device, optional. 90 * 91 * @dev: the device 92 * @offset: offset to write the device 93 * @buf: pointer to data buffer 94 * @size: data size in bytes to write the device 95 * @return: 0 if OK, -ve on error 96 */ 97 int (*write)(struct udevice *dev, int offset, const void *buf, 98 int size); 99 /* 100 * Assert command to the device, optional. 101 * 102 * @dev: the device 103 * @request: command to be sent to the device 104 * @buf: pointer to buffer related to the request 105 * @return: 0 if OK, -ve on error 106 */ 107 int (*ioctl)(struct udevice *dev, unsigned long request, void *buf); 108 /* 109 * Send a message to the device and wait for a response. 110 * 111 * @dev: the device 112 * @msgid: the message ID/number to send 113 * tx_msg: the request/transmit message payload 114 * tx_size: the size of the buffer pointed at by tx_msg 115 * rx_msg: the buffer to receive the response message payload. May be 116 * NULL if the caller only cares about the error code. 117 * rx_size: the size of the buffer pointed at by rx_msg 118 * @return the response message size if OK, -ve on error 119 */ 120 int (*call)(struct udevice *dev, int msgid, void *tx_msg, int tx_size, 121 void *rx_msg, int rx_size); 122 }; 123 124 #endif /* _MISC_H_ */ 125