xref: /OK3568_Linux_fs/u-boot/include/misc.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Copyright (C) 2015 Thomas Chou <thomas@wytron.com.tw>
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * SPDX-License-Identifier:	GPL-2.0+
5*4882a593Smuzhiyun  */
6*4882a593Smuzhiyun 
7*4882a593Smuzhiyun #ifndef _MISC_H_
8*4882a593Smuzhiyun #define _MISC_H_
9*4882a593Smuzhiyun 
10*4882a593Smuzhiyun #include <asm-generic/ioctl.h>
11*4882a593Smuzhiyun 
12*4882a593Smuzhiyun /*
13*4882a593Smuzhiyun  * Request command to be sent for misc_ioctl().
14*4882a593Smuzhiyun  */
15*4882a593Smuzhiyun #define IOCTL_REQ_START		_IO('m', 0x01)
16*4882a593Smuzhiyun #define IOCTL_REQ_STOP		_IO('m', 0x02)
17*4882a593Smuzhiyun #define IOCTL_REQ_POLL		_IO('m', 0x03)
18*4882a593Smuzhiyun #define IOCTL_REQ_CAPABILITY	_IO('m', 0x04)
19*4882a593Smuzhiyun #define IOCTL_REQ_DATA_SIZE	_IO('m', 0x05)
20*4882a593Smuzhiyun 
21*4882a593Smuzhiyun enum misc_mode {
22*4882a593Smuzhiyun 	DECOM_LZ4	= BIT(0),
23*4882a593Smuzhiyun 	DECOM_GZIP	= BIT(1),
24*4882a593Smuzhiyun 	DECOM_ZLIB	= BIT(2),
25*4882a593Smuzhiyun 	OTP_S		= BIT(3),
26*4882a593Smuzhiyun 	OTP_NS		= BIT(4),
27*4882a593Smuzhiyun };
28*4882a593Smuzhiyun 
29*4882a593Smuzhiyun /*
30*4882a593Smuzhiyun  * Read the device to buffer, optional.
31*4882a593Smuzhiyun  *
32*4882a593Smuzhiyun  * @dev: the device
33*4882a593Smuzhiyun  * @offset: offset to read the device
34*4882a593Smuzhiyun  * @buf: pointer to data buffer
35*4882a593Smuzhiyun  * @size: data size in bytes to read the device
36*4882a593Smuzhiyun  * @return: 0 if OK, -ve on error
37*4882a593Smuzhiyun  */
38*4882a593Smuzhiyun int misc_read(struct udevice *dev, int offset, void *buf, int size);
39*4882a593Smuzhiyun /*
40*4882a593Smuzhiyun  * Write buffer to the device, optional.
41*4882a593Smuzhiyun  *
42*4882a593Smuzhiyun  * @dev: the device
43*4882a593Smuzhiyun  * @offset: offset to write the device
44*4882a593Smuzhiyun  * @buf: pointer to data buffer
45*4882a593Smuzhiyun  * @size: data size in bytes to write the device
46*4882a593Smuzhiyun  * @return: 0 if OK, -ve on error
47*4882a593Smuzhiyun  */
48*4882a593Smuzhiyun int misc_write(struct udevice *dev, int offset, void *buf, int size);
49*4882a593Smuzhiyun /*
50*4882a593Smuzhiyun  * Assert command to the device, optional.
51*4882a593Smuzhiyun  *
52*4882a593Smuzhiyun  * @dev: the device
53*4882a593Smuzhiyun  * @request: command to be sent to the device
54*4882a593Smuzhiyun  * @buf: pointer to buffer related to the request
55*4882a593Smuzhiyun  * @return: 0 if OK, -ve on error
56*4882a593Smuzhiyun  */
57*4882a593Smuzhiyun int misc_ioctl(struct udevice *dev, unsigned long request, void *buf);
58*4882a593Smuzhiyun 
59*4882a593Smuzhiyun /*
60*4882a593Smuzhiyun  * Send a message to the device and wait for a response.
61*4882a593Smuzhiyun  *
62*4882a593Smuzhiyun  * The caller provides the message type/ID and payload to be sent.
63*4882a593Smuzhiyun  * The callee constructs any message header required, transmits it to the
64*4882a593Smuzhiyun  * target, waits for a response, checks any error code in the response,
65*4882a593Smuzhiyun  * strips any message header from the response, and returns the error code
66*4882a593Smuzhiyun  * (or a parsed version of it) and the response message payload.
67*4882a593Smuzhiyun  *
68*4882a593Smuzhiyun  * @dev: the device.
69*4882a593Smuzhiyun  * @msgid: the message ID/number to send.
70*4882a593Smuzhiyun  * tx_msg: the request/transmit message payload.
71*4882a593Smuzhiyun  * tx_size: the size of the buffer pointed at by tx_msg.
72*4882a593Smuzhiyun  * rx_msg: the buffer to receive the response message payload. May be NULL if
73*4882a593Smuzhiyun  *         the caller only cares about the error code.
74*4882a593Smuzhiyun  * rx_size: the size of the buffer pointed at by rx_msg.
75*4882a593Smuzhiyun  * @return the response message size if OK, -ve on error
76*4882a593Smuzhiyun  */
77*4882a593Smuzhiyun int misc_call(struct udevice *dev, int msgid, void *tx_msg, int tx_size,
78*4882a593Smuzhiyun 	      void *rx_msg, int rx_size);
79*4882a593Smuzhiyun 
80*4882a593Smuzhiyun /*
81*4882a593Smuzhiyun  * Get a misc device by capability
82*4882a593Smuzhiyun  *
83*4882a593Smuzhiyun  * The caller can get a misc device according to capability request, the driver
84*4882a593Smuzhiyun  * must implement the IOCTL_REQ_CAPABILITY callback.
85*4882a593Smuzhiyun  *
86*4882a593Smuzhiyun  * @capability: the value of enum misc_mode.
87*4882a593Smuzhiyun  * @return the require device if OK, NULL on error
88*4882a593Smuzhiyun  */
89*4882a593Smuzhiyun struct udevice *misc_get_device_by_capability(u32 capability);
90*4882a593Smuzhiyun 
91*4882a593Smuzhiyun /*
92*4882a593Smuzhiyun  * struct misc_ops - Driver model Misc operations
93*4882a593Smuzhiyun  *
94*4882a593Smuzhiyun  * The uclass interface is implemented by all miscellaneous devices which
95*4882a593Smuzhiyun  * use driver model.
96*4882a593Smuzhiyun  */
97*4882a593Smuzhiyun struct misc_ops {
98*4882a593Smuzhiyun 	/*
99*4882a593Smuzhiyun 	 * Read the device to buffer, optional.
100*4882a593Smuzhiyun 	 *
101*4882a593Smuzhiyun 	 * @dev: the device
102*4882a593Smuzhiyun 	 * @offset: offset to read the device
103*4882a593Smuzhiyun 	 * @buf: pointer to data buffer
104*4882a593Smuzhiyun 	 * @size: data size in bytes to read the device
105*4882a593Smuzhiyun 	 * @return: 0 if OK, -ve on error
106*4882a593Smuzhiyun 	 */
107*4882a593Smuzhiyun 	int (*read)(struct udevice *dev, int offset, void *buf, int size);
108*4882a593Smuzhiyun 	/*
109*4882a593Smuzhiyun 	 * Write buffer to the device, optional.
110*4882a593Smuzhiyun 	 *
111*4882a593Smuzhiyun 	 * @dev: the device
112*4882a593Smuzhiyun 	 * @offset: offset to write the device
113*4882a593Smuzhiyun 	 * @buf: pointer to data buffer
114*4882a593Smuzhiyun 	 * @size: data size in bytes to write the device
115*4882a593Smuzhiyun 	 * @return: 0 if OK, -ve on error
116*4882a593Smuzhiyun 	 */
117*4882a593Smuzhiyun 	int (*write)(struct udevice *dev, int offset, const void *buf,
118*4882a593Smuzhiyun 		     int size);
119*4882a593Smuzhiyun 	/*
120*4882a593Smuzhiyun 	 * Assert command to the device, optional.
121*4882a593Smuzhiyun 	 *
122*4882a593Smuzhiyun 	 * @dev: the device
123*4882a593Smuzhiyun 	 * @request: command to be sent to the device
124*4882a593Smuzhiyun 	 * @buf: pointer to buffer related to the request
125*4882a593Smuzhiyun 	 * @return: 0 if OK, -ve on error
126*4882a593Smuzhiyun 	 */
127*4882a593Smuzhiyun 	int (*ioctl)(struct udevice *dev, unsigned long request, void *buf);
128*4882a593Smuzhiyun 	/*
129*4882a593Smuzhiyun 	 * Send a message to the device and wait for a response.
130*4882a593Smuzhiyun 	 *
131*4882a593Smuzhiyun 	 * @dev: the device
132*4882a593Smuzhiyun 	 * @msgid: the message ID/number to send
133*4882a593Smuzhiyun 	 * tx_msg: the request/transmit message payload
134*4882a593Smuzhiyun 	 * tx_size: the size of the buffer pointed at by tx_msg
135*4882a593Smuzhiyun 	 * rx_msg: the buffer to receive the response message payload. May be
136*4882a593Smuzhiyun 	 *         NULL if the caller only cares about the error code.
137*4882a593Smuzhiyun 	 * rx_size: the size of the buffer pointed at by rx_msg
138*4882a593Smuzhiyun 	 * @return the response message size if OK, -ve on error
139*4882a593Smuzhiyun 	 */
140*4882a593Smuzhiyun 	int (*call)(struct udevice *dev, int msgid, void *tx_msg, int tx_size,
141*4882a593Smuzhiyun 		    void *rx_msg, int rx_size);
142*4882a593Smuzhiyun };
143*4882a593Smuzhiyun 
144*4882a593Smuzhiyun /* generic layer for otp */
145*4882a593Smuzhiyun struct udevice *misc_otp_get_device(u32 capability);
146*4882a593Smuzhiyun int misc_otp_read(struct udevice *dev, int offset, void *buf, int size);
147*4882a593Smuzhiyun int misc_otp_write(struct udevice *dev, int offset, const void *buf, int size);
148*4882a593Smuzhiyun 
149*4882a593Smuzhiyun /* generic layer for decompress */
150*4882a593Smuzhiyun struct decom_param {
151*4882a593Smuzhiyun 	unsigned long addr_src;
152*4882a593Smuzhiyun 	unsigned long addr_dst;
153*4882a593Smuzhiyun 	u64 size_src;	/* compressed */
154*4882a593Smuzhiyun 	u64 size_dst;	/* decompressed, to be filled for output */
155*4882a593Smuzhiyun 	enum misc_mode mode;
156*4882a593Smuzhiyun 	u32 flags;
157*4882a593Smuzhiyun };
158*4882a593Smuzhiyun 
159*4882a593Smuzhiyun /* function flags for decompress */
160*4882a593Smuzhiyun #define DCOMP_FLG_IRQ_ONESHOT	BIT(0)
161*4882a593Smuzhiyun 
162*4882a593Smuzhiyun void misc_decompress_async(u8 comp);
163*4882a593Smuzhiyun void misc_decompress_sync(u8 comp);
164*4882a593Smuzhiyun int misc_decompress_cleanup(void);
165*4882a593Smuzhiyun int misc_decompress_process(unsigned long dst, unsigned long src,
166*4882a593Smuzhiyun 			    unsigned long src_len, u32 cap, bool sync,
167*4882a593Smuzhiyun 			    u64 *size, u32 flags);
168*4882a593Smuzhiyun #endif	/* _MISC_H_ */
169