xref: /rk3399_rockchip-uboot/include/misc.h (revision 1cef1b20c4e10aadfa427e1de63a0750321327ea)
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)
19dbfe5ed5SJoseph Chen 
205b7d3298SJason Zhu enum misc_mode {
215b7d3298SJason Zhu 	DECOM_LZ4	= BIT(0),
225b7d3298SJason Zhu 	DECOM_GZIP	= BIT(1),
235b7d3298SJason Zhu 	DECOM_ZLIB	= BIT(2),
245b7d3298SJason Zhu 	OTP_S		= BIT(3),
255b7d3298SJason Zhu 	OTP_NS		= BIT(4),
265b7d3298SJason Zhu };
275b7d3298SJason Zhu 
284395e06eSThomas Chou /*
294395e06eSThomas Chou  * Read the device to buffer, optional.
304395e06eSThomas Chou  *
314395e06eSThomas Chou  * @dev: the device
324395e06eSThomas Chou  * @offset: offset to read the device
334395e06eSThomas Chou  * @buf: pointer to data buffer
344395e06eSThomas Chou  * @size: data size in bytes to read the device
354395e06eSThomas Chou  * @return: 0 if OK, -ve on error
364395e06eSThomas Chou  */
374395e06eSThomas Chou int misc_read(struct udevice *dev, int offset, void *buf, int size);
384395e06eSThomas Chou /*
394395e06eSThomas Chou  * Write buffer to the device, optional.
404395e06eSThomas Chou  *
414395e06eSThomas Chou  * @dev: the device
424395e06eSThomas Chou  * @offset: offset to write the device
434395e06eSThomas Chou  * @buf: pointer to data buffer
444395e06eSThomas Chou  * @size: data size in bytes to write the device
454395e06eSThomas Chou  * @return: 0 if OK, -ve on error
464395e06eSThomas Chou  */
474395e06eSThomas Chou int misc_write(struct udevice *dev, int offset, void *buf, int size);
484395e06eSThomas Chou /*
494395e06eSThomas Chou  * Assert command to the device, optional.
504395e06eSThomas Chou  *
514395e06eSThomas Chou  * @dev: the device
524395e06eSThomas Chou  * @request: command to be sent to the device
53f5abb409SRobert P. J. Day  * @buf: pointer to buffer related to the request
544395e06eSThomas Chou  * @return: 0 if OK, -ve on error
554395e06eSThomas Chou  */
564395e06eSThomas Chou int misc_ioctl(struct udevice *dev, unsigned long request, void *buf);
574395e06eSThomas Chou 
584395e06eSThomas Chou /*
59b647f554SStephen Warren  * Send a message to the device and wait for a response.
60b647f554SStephen Warren  *
61b647f554SStephen Warren  * The caller provides the message type/ID and payload to be sent.
62b647f554SStephen Warren  * The callee constructs any message header required, transmits it to the
63b647f554SStephen Warren  * target, waits for a response, checks any error code in the response,
64b647f554SStephen Warren  * strips any message header from the response, and returns the error code
65b647f554SStephen Warren  * (or a parsed version of it) and the response message payload.
66b647f554SStephen Warren  *
67b647f554SStephen Warren  * @dev: the device.
68b647f554SStephen Warren  * @msgid: the message ID/number to send.
69b647f554SStephen Warren  * tx_msg: the request/transmit message payload.
70b647f554SStephen Warren  * tx_size: the size of the buffer pointed at by tx_msg.
71b647f554SStephen Warren  * rx_msg: the buffer to receive the response message payload. May be NULL if
72b647f554SStephen Warren  *         the caller only cares about the error code.
73b647f554SStephen Warren  * rx_size: the size of the buffer pointed at by rx_msg.
74b647f554SStephen Warren  * @return the response message size if OK, -ve on error
75b647f554SStephen Warren  */
76b647f554SStephen Warren int misc_call(struct udevice *dev, int msgid, void *tx_msg, int tx_size,
77b647f554SStephen Warren 	      void *rx_msg, int rx_size);
78b647f554SStephen Warren 
79b647f554SStephen Warren /*
804395e06eSThomas Chou  * struct misc_ops - Driver model Misc operations
814395e06eSThomas Chou  *
824395e06eSThomas Chou  * The uclass interface is implemented by all miscellaneous devices which
834395e06eSThomas Chou  * use driver model.
844395e06eSThomas Chou  */
854395e06eSThomas Chou struct misc_ops {
864395e06eSThomas Chou 	/*
874395e06eSThomas Chou 	 * Read the device to buffer, optional.
884395e06eSThomas Chou 	 *
894395e06eSThomas Chou 	 * @dev: the device
904395e06eSThomas Chou 	 * @offset: offset to read the device
914395e06eSThomas Chou 	 * @buf: pointer to data buffer
924395e06eSThomas Chou 	 * @size: data size in bytes to read the device
934395e06eSThomas Chou 	 * @return: 0 if OK, -ve on error
944395e06eSThomas Chou 	 */
954395e06eSThomas Chou 	int (*read)(struct udevice *dev, int offset, void *buf, int size);
964395e06eSThomas Chou 	/*
974395e06eSThomas Chou 	 * Write buffer to the device, optional.
984395e06eSThomas Chou 	 *
994395e06eSThomas Chou 	 * @dev: the device
1004395e06eSThomas Chou 	 * @offset: offset to write the device
1014395e06eSThomas Chou 	 * @buf: pointer to data buffer
1024395e06eSThomas Chou 	 * @size: data size in bytes to write the device
1034395e06eSThomas Chou 	 * @return: 0 if OK, -ve on error
1044395e06eSThomas Chou 	 */
1054395e06eSThomas Chou 	int (*write)(struct udevice *dev, int offset, const void *buf,
1064395e06eSThomas Chou 		     int size);
1074395e06eSThomas Chou 	/*
1084395e06eSThomas Chou 	 * Assert command to the device, optional.
1094395e06eSThomas Chou 	 *
1104395e06eSThomas Chou 	 * @dev: the device
1114395e06eSThomas Chou 	 * @request: command to be sent to the device
112f5abb409SRobert P. J. Day 	 * @buf: pointer to buffer related to the request
1134395e06eSThomas Chou 	 * @return: 0 if OK, -ve on error
1144395e06eSThomas Chou 	 */
1154395e06eSThomas Chou 	int (*ioctl)(struct udevice *dev, unsigned long request, void *buf);
116b647f554SStephen Warren 	/*
117b647f554SStephen Warren 	 * Send a message to the device and wait for a response.
118b647f554SStephen Warren 	 *
119b647f554SStephen Warren 	 * @dev: the device
120b647f554SStephen Warren 	 * @msgid: the message ID/number to send
121b647f554SStephen Warren 	 * tx_msg: the request/transmit message payload
122b647f554SStephen Warren 	 * tx_size: the size of the buffer pointed at by tx_msg
123b647f554SStephen Warren 	 * rx_msg: the buffer to receive the response message payload. May be
124b647f554SStephen Warren 	 *         NULL if the caller only cares about the error code.
125b647f554SStephen Warren 	 * rx_size: the size of the buffer pointed at by rx_msg
126b647f554SStephen Warren 	 * @return the response message size if OK, -ve on error
127b647f554SStephen Warren 	 */
128b647f554SStephen Warren 	int (*call)(struct udevice *dev, int msgid, void *tx_msg, int tx_size,
129b647f554SStephen Warren 		    void *rx_msg, int rx_size);
1304395e06eSThomas Chou };
1314395e06eSThomas Chou 
132*1cef1b20SJoseph Chen /* generic layer for otp */
133*1cef1b20SJoseph Chen struct udevice *misc_otp_get_device(u32 capability);
134*1cef1b20SJoseph Chen int misc_otp_read(struct udevice *dev, int offset, void *buf, int size);
135*1cef1b20SJoseph Chen int misc_otp_write(struct udevice *dev, int offset, const void *buf, int size);
136*1cef1b20SJoseph Chen 
137*1cef1b20SJoseph Chen /* generic layer for decompress */
138*1cef1b20SJoseph Chen struct decom_param {
139*1cef1b20SJoseph Chen 	unsigned long addr_src;
140*1cef1b20SJoseph Chen 	unsigned long addr_dst;
141*1cef1b20SJoseph Chen 	unsigned long size;
142*1cef1b20SJoseph Chen 	enum misc_mode mode;
143*1cef1b20SJoseph Chen };
144*1cef1b20SJoseph Chen 
145*1cef1b20SJoseph Chen struct udevice *misc_decompress_get_device(u32 capability);
146*1cef1b20SJoseph Chen int misc_decompress_start(struct udevice *dev, unsigned long src,
147*1cef1b20SJoseph Chen 			  unsigned long dst, unsigned long size);
148*1cef1b20SJoseph Chen int misc_decompress_stop(struct udevice *dev);
149*1cef1b20SJoseph Chen int misc_decompress_is_complete(struct udevice *dev);
150*1cef1b20SJoseph Chen 
1514395e06eSThomas Chou #endif	/* _MISC_H_ */
152