14395e06eSThomas Chou /* 24395e06eSThomas Chou * Copyright (C) 2015 Thomas Chou <thomas@wytron.com.tw> 34395e06eSThomas Chou * 44395e06eSThomas Chou * SPDX-License-Identifier: GPL-2.0+ 54395e06eSThomas Chou */ 64395e06eSThomas Chou 74395e06eSThomas Chou #ifndef _MISC_H_ 84395e06eSThomas Chou #define _MISC_H_ 94395e06eSThomas Chou 10dbfe5ed5SJoseph Chen #include <asm-generic/ioctl.h> 11dbfe5ed5SJoseph Chen 12dbfe5ed5SJoseph Chen /* 13dbfe5ed5SJoseph Chen * Request command to be sent for misc_ioctl(). 14dbfe5ed5SJoseph Chen */ 15dbfe5ed5SJoseph Chen #define IOCTL_REQ_START _IO('m', 0x01) 16dbfe5ed5SJoseph Chen #define IOCTL_REQ_STOP _IO('m', 0x02) 17dbfe5ed5SJoseph Chen #define IOCTL_REQ_POLL _IO('m', 0x03) 1874dce6feSJason Zhu #define IOCTL_REQ_CAPABILITY _IO('m', 0x04) 19656bdb59SJoseph Chen #define IOCTL_REQ_DATA_SIZE _IO('m', 0x05) 2007f8bbdbSXuhui Lin #define IOCTL_REQ_KEYLAD_INIT _IO('m', 0x06) 2107f8bbdbSXuhui Lin #define IOCTL_REQ_KEYLAD_DEINIT _IO('m', 0x07) 22dbfe5ed5SJoseph Chen 235b7d3298SJason Zhu enum misc_mode { 245b7d3298SJason Zhu DECOM_LZ4 = BIT(0), 255b7d3298SJason Zhu DECOM_GZIP = BIT(1), 265b7d3298SJason Zhu DECOM_ZLIB = BIT(2), 275b7d3298SJason Zhu OTP_S = BIT(3), 285b7d3298SJason Zhu OTP_NS = BIT(4), 295b7d3298SJason Zhu }; 305b7d3298SJason Zhu 314395e06eSThomas Chou /* 324395e06eSThomas Chou * Read the device to buffer, optional. 334395e06eSThomas Chou * 344395e06eSThomas Chou * @dev: the device 354395e06eSThomas Chou * @offset: offset to read the device 364395e06eSThomas Chou * @buf: pointer to data buffer 374395e06eSThomas Chou * @size: data size in bytes to read the device 384395e06eSThomas Chou * @return: 0 if OK, -ve on error 394395e06eSThomas Chou */ 404395e06eSThomas Chou int misc_read(struct udevice *dev, int offset, void *buf, int size); 414395e06eSThomas Chou /* 424395e06eSThomas Chou * Write buffer to the device, optional. 434395e06eSThomas Chou * 444395e06eSThomas Chou * @dev: the device 454395e06eSThomas Chou * @offset: offset to write the device 464395e06eSThomas Chou * @buf: pointer to data buffer 474395e06eSThomas Chou * @size: data size in bytes to write the device 484395e06eSThomas Chou * @return: 0 if OK, -ve on error 494395e06eSThomas Chou */ 504395e06eSThomas Chou int misc_write(struct udevice *dev, int offset, void *buf, int size); 514395e06eSThomas Chou /* 524395e06eSThomas Chou * Assert command to the device, optional. 534395e06eSThomas Chou * 544395e06eSThomas Chou * @dev: the device 554395e06eSThomas Chou * @request: command to be sent to the device 56f5abb409SRobert P. J. Day * @buf: pointer to buffer related to the request 574395e06eSThomas Chou * @return: 0 if OK, -ve on error 584395e06eSThomas Chou */ 594395e06eSThomas Chou int misc_ioctl(struct udevice *dev, unsigned long request, void *buf); 604395e06eSThomas Chou 614395e06eSThomas Chou /* 62b647f554SStephen Warren * Send a message to the device and wait for a response. 63b647f554SStephen Warren * 64b647f554SStephen Warren * The caller provides the message type/ID and payload to be sent. 65b647f554SStephen Warren * The callee constructs any message header required, transmits it to the 66b647f554SStephen Warren * target, waits for a response, checks any error code in the response, 67b647f554SStephen Warren * strips any message header from the response, and returns the error code 68b647f554SStephen Warren * (or a parsed version of it) and the response message payload. 69b647f554SStephen Warren * 70b647f554SStephen Warren * @dev: the device. 71b647f554SStephen Warren * @msgid: the message ID/number to send. 72b647f554SStephen Warren * tx_msg: the request/transmit message payload. 73b647f554SStephen Warren * tx_size: the size of the buffer pointed at by tx_msg. 74b647f554SStephen Warren * rx_msg: the buffer to receive the response message payload. May be NULL if 75b647f554SStephen Warren * the caller only cares about the error code. 76b647f554SStephen Warren * rx_size: the size of the buffer pointed at by rx_msg. 77b647f554SStephen Warren * @return the response message size if OK, -ve on error 78b647f554SStephen Warren */ 79b647f554SStephen Warren int misc_call(struct udevice *dev, int msgid, void *tx_msg, int tx_size, 80b647f554SStephen Warren void *rx_msg, int rx_size); 81b647f554SStephen Warren 82b647f554SStephen Warren /* 83374c241cSJoseph Chen * Get a misc device by capability 84374c241cSJoseph Chen * 85374c241cSJoseph Chen * The caller can get a misc device according to capability request, the driver 86374c241cSJoseph Chen * must implement the IOCTL_REQ_CAPABILITY callback. 87374c241cSJoseph Chen * 88374c241cSJoseph Chen * @capability: the value of enum misc_mode. 89374c241cSJoseph Chen * @return the require device if OK, NULL on error 90374c241cSJoseph Chen */ 91374c241cSJoseph Chen struct udevice *misc_get_device_by_capability(u32 capability); 92374c241cSJoseph Chen 93374c241cSJoseph Chen /* 944395e06eSThomas Chou * struct misc_ops - Driver model Misc operations 954395e06eSThomas Chou * 964395e06eSThomas Chou * The uclass interface is implemented by all miscellaneous devices which 974395e06eSThomas Chou * use driver model. 984395e06eSThomas Chou */ 994395e06eSThomas Chou struct misc_ops { 1004395e06eSThomas Chou /* 1014395e06eSThomas Chou * Read the device to buffer, optional. 1024395e06eSThomas Chou * 1034395e06eSThomas Chou * @dev: the device 1044395e06eSThomas Chou * @offset: offset to read the device 1054395e06eSThomas Chou * @buf: pointer to data buffer 1064395e06eSThomas Chou * @size: data size in bytes to read the device 1074395e06eSThomas Chou * @return: 0 if OK, -ve on error 1084395e06eSThomas Chou */ 1094395e06eSThomas Chou int (*read)(struct udevice *dev, int offset, void *buf, int size); 1104395e06eSThomas Chou /* 1114395e06eSThomas Chou * Write buffer to the device, optional. 1124395e06eSThomas Chou * 1134395e06eSThomas Chou * @dev: the device 1144395e06eSThomas Chou * @offset: offset to write the device 1154395e06eSThomas Chou * @buf: pointer to data buffer 1164395e06eSThomas Chou * @size: data size in bytes to write the device 1174395e06eSThomas Chou * @return: 0 if OK, -ve on error 1184395e06eSThomas Chou */ 1194395e06eSThomas Chou int (*write)(struct udevice *dev, int offset, const void *buf, 1204395e06eSThomas Chou int size); 1214395e06eSThomas Chou /* 1224395e06eSThomas Chou * Assert command to the device, optional. 1234395e06eSThomas Chou * 1244395e06eSThomas Chou * @dev: the device 1254395e06eSThomas Chou * @request: command to be sent to the device 126f5abb409SRobert P. J. Day * @buf: pointer to buffer related to the request 1274395e06eSThomas Chou * @return: 0 if OK, -ve on error 1284395e06eSThomas Chou */ 1294395e06eSThomas Chou int (*ioctl)(struct udevice *dev, unsigned long request, void *buf); 130b647f554SStephen Warren /* 131b647f554SStephen Warren * Send a message to the device and wait for a response. 132b647f554SStephen Warren * 133b647f554SStephen Warren * @dev: the device 134b647f554SStephen Warren * @msgid: the message ID/number to send 135b647f554SStephen Warren * tx_msg: the request/transmit message payload 136b647f554SStephen Warren * tx_size: the size of the buffer pointed at by tx_msg 137b647f554SStephen Warren * rx_msg: the buffer to receive the response message payload. May be 138b647f554SStephen Warren * NULL if the caller only cares about the error code. 139b647f554SStephen Warren * rx_size: the size of the buffer pointed at by rx_msg 140b647f554SStephen Warren * @return the response message size if OK, -ve on error 141b647f554SStephen Warren */ 142b647f554SStephen Warren int (*call)(struct udevice *dev, int msgid, void *tx_msg, int tx_size, 143b647f554SStephen Warren void *rx_msg, int rx_size); 1444395e06eSThomas Chou }; 1454395e06eSThomas Chou 1461cef1b20SJoseph Chen /* generic layer for otp */ 1471cef1b20SJoseph Chen struct udevice *misc_otp_get_device(u32 capability); 1481cef1b20SJoseph Chen int misc_otp_read(struct udevice *dev, int offset, void *buf, int size); 1491cef1b20SJoseph Chen int misc_otp_write(struct udevice *dev, int offset, const void *buf, int size); 150368f3065SXuhui Lin int misc_otp_ioctl(struct udevice *dev, unsigned long request, void *buf); 151*b80b67f1SXuhui Lin int misc_otp_write_verify(struct udevice *dev, int offset, const uint8_t *write_buf, int size); 1521cef1b20SJoseph Chen 1531cef1b20SJoseph Chen /* generic layer for decompress */ 1541cef1b20SJoseph Chen struct decom_param { 1551cef1b20SJoseph Chen unsigned long addr_src; 1561cef1b20SJoseph Chen unsigned long addr_dst; 157e1e885d3SJoseph Chen u64 size_src; /* compressed */ 158e1e885d3SJoseph Chen u64 size_dst; /* decompressed, to be filled for output */ 1591cef1b20SJoseph Chen enum misc_mode mode; 1602bce72c8SJoseph Chen u32 flags; 1611cef1b20SJoseph Chen }; 1621cef1b20SJoseph Chen 1632bce72c8SJoseph Chen /* function flags for decompress */ 1642bce72c8SJoseph Chen #define DCOMP_FLG_IRQ_ONESHOT BIT(0) 1652bce72c8SJoseph Chen 166656bdb59SJoseph Chen void misc_decompress_async(u8 comp); 167656bdb59SJoseph Chen void misc_decompress_sync(u8 comp); 168656bdb59SJoseph Chen int misc_decompress_cleanup(void); 169656bdb59SJoseph Chen int misc_decompress_process(unsigned long dst, unsigned long src, 170656bdb59SJoseph Chen unsigned long src_len, u32 cap, bool sync, 1712bce72c8SJoseph Chen u64 *size, u32 flags); 1724395e06eSThomas Chou #endif /* _MISC_H_ */ 173