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 enum misc_mode { 21 DECOM_LZ4 = BIT(0), 22 DECOM_GZIP = BIT(1), 23 DECOM_ZLIB = BIT(2), 24 OTP_S = BIT(3), 25 OTP_NS = BIT(4), 26 }; 27 28 /* 29 * Read the device to buffer, optional. 30 * 31 * @dev: the device 32 * @offset: offset to read the device 33 * @buf: pointer to data buffer 34 * @size: data size in bytes to read the device 35 * @return: 0 if OK, -ve on error 36 */ 37 int misc_read(struct udevice *dev, int offset, void *buf, int size); 38 /* 39 * Write buffer to the device, optional. 40 * 41 * @dev: the device 42 * @offset: offset to write the device 43 * @buf: pointer to data buffer 44 * @size: data size in bytes to write the device 45 * @return: 0 if OK, -ve on error 46 */ 47 int misc_write(struct udevice *dev, int offset, void *buf, int size); 48 /* 49 * Assert command to the device, optional. 50 * 51 * @dev: the device 52 * @request: command to be sent to the device 53 * @buf: pointer to buffer related to the request 54 * @return: 0 if OK, -ve on error 55 */ 56 int misc_ioctl(struct udevice *dev, unsigned long request, void *buf); 57 58 /* 59 * Send a message to the device and wait for a response. 60 * 61 * The caller provides the message type/ID and payload to be sent. 62 * The callee constructs any message header required, transmits it to the 63 * target, waits for a response, checks any error code in the response, 64 * strips any message header from the response, and returns the error code 65 * (or a parsed version of it) and the response message payload. 66 * 67 * @dev: the device. 68 * @msgid: the message ID/number to send. 69 * tx_msg: the request/transmit message payload. 70 * tx_size: the size of the buffer pointed at by tx_msg. 71 * rx_msg: the buffer to receive the response message payload. May be NULL if 72 * the caller only cares about the error code. 73 * rx_size: the size of the buffer pointed at by rx_msg. 74 * @return the response message size if OK, -ve on error 75 */ 76 int misc_call(struct udevice *dev, int msgid, void *tx_msg, int tx_size, 77 void *rx_msg, int rx_size); 78 79 /* 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 { 86 /* 87 * Read the device to buffer, optional. 88 * 89 * @dev: the device 90 * @offset: offset to read the device 91 * @buf: pointer to data buffer 92 * @size: data size in bytes to read the device 93 * @return: 0 if OK, -ve on error 94 */ 95 int (*read)(struct udevice *dev, int offset, void *buf, int size); 96 /* 97 * Write buffer to the device, optional. 98 * 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 103 * @return: 0 if OK, -ve on error 104 */ 105 int (*write)(struct udevice *dev, int offset, const void *buf, 106 int size); 107 /* 108 * Assert command to the device, optional. 109 * 110 * @dev: the device 111 * @request: command to be sent to the device 112 * @buf: pointer to buffer related to the request 113 * @return: 0 if OK, -ve on error 114 */ 115 int (*ioctl)(struct udevice *dev, unsigned long request, void *buf); 116 /* 117 * Send a message to the device and wait for a response. 118 * 119 * @dev: the device 120 * @msgid: the message ID/number to send 121 * tx_msg: the request/transmit message payload 122 * tx_size: the size of the buffer pointed at by tx_msg 123 * rx_msg: the buffer to receive the response message payload. May be 124 * NULL if the caller only cares about the error code. 125 * rx_size: the size of the buffer pointed at by rx_msg 126 * @return the response message size if OK, -ve on error 127 */ 128 int (*call)(struct udevice *dev, int msgid, void *tx_msg, int tx_size, 129 void *rx_msg, int rx_size); 130 }; 131 132 /* generic layer for otp */ 133 struct udevice *misc_otp_get_device(u32 capability); 134 int misc_otp_read(struct udevice *dev, int offset, void *buf, int size); 135 int misc_otp_write(struct udevice *dev, int offset, const void *buf, int size); 136 137 /* generic layer for decompress */ 138 struct decom_param { 139 unsigned long addr_src; 140 unsigned long addr_dst; 141 unsigned long size; 142 enum misc_mode mode; 143 }; 144 145 struct udevice *misc_decompress_get_device(u32 capability); 146 int misc_decompress_start(struct udevice *dev, unsigned long src, 147 unsigned long dst, unsigned long size); 148 int misc_decompress_stop(struct udevice *dev); 149 int misc_decompress_is_complete(struct udevice *dev); 150 151 #endif /* _MISC_H_ */ 152