xref: /rk3399_rockchip-uboot/include/misc.h (revision 008ec9b4bc06f98dd7efdc7d2f44eb066be036e6)
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 
19 /*
20  * Read the device to buffer, optional.
21  *
22  * @dev: the device
23  * @offset: offset to read the device
24  * @buf: pointer to data buffer
25  * @size: data size in bytes to read the device
26  * @return: 0 if OK, -ve on error
27  */
28 int misc_read(struct udevice *dev, int offset, void *buf, int size);
29 /*
30  * Write buffer to the device, optional.
31  *
32  * @dev: the device
33  * @offset: offset to write the device
34  * @buf: pointer to data buffer
35  * @size: data size in bytes to write the device
36  * @return: 0 if OK, -ve on error
37  */
38 int misc_write(struct udevice *dev, int offset, void *buf, int size);
39 /*
40  * Assert command to the device, optional.
41  *
42  * @dev: the device
43  * @request: command to be sent to the device
44  * @buf: pointer to buffer related to the request
45  * @return: 0 if OK, -ve on error
46  */
47 int misc_ioctl(struct udevice *dev, unsigned long request, void *buf);
48 
49 /*
50  * Send a message to the device and wait for a response.
51  *
52  * The caller provides the message type/ID and payload to be sent.
53  * The callee constructs any message header required, transmits it to the
54  * target, waits for a response, checks any error code in the response,
55  * strips any message header from the response, and returns the error code
56  * (or a parsed version of it) and the response message payload.
57  *
58  * @dev: the device.
59  * @msgid: the message ID/number to send.
60  * tx_msg: the request/transmit message payload.
61  * tx_size: the size of the buffer pointed at by tx_msg.
62  * rx_msg: the buffer to receive the response message payload. May be NULL if
63  *         the caller only cares about the error code.
64  * rx_size: the size of the buffer pointed at by rx_msg.
65  * @return the response message size if OK, -ve on error
66  */
67 int misc_call(struct udevice *dev, int msgid, void *tx_msg, int tx_size,
68 	      void *rx_msg, int rx_size);
69 
70 /*
71  * struct misc_ops - Driver model Misc operations
72  *
73  * The uclass interface is implemented by all miscellaneous devices which
74  * use driver model.
75  */
76 struct misc_ops {
77 	/*
78 	 * Read the device to buffer, optional.
79 	 *
80 	 * @dev: the device
81 	 * @offset: offset to read the device
82 	 * @buf: pointer to data buffer
83 	 * @size: data size in bytes to read the device
84 	 * @return: 0 if OK, -ve on error
85 	 */
86 	int (*read)(struct udevice *dev, int offset, void *buf, int size);
87 	/*
88 	 * Write buffer to the device, optional.
89 	 *
90 	 * @dev: the device
91 	 * @offset: offset to write the device
92 	 * @buf: pointer to data buffer
93 	 * @size: data size in bytes to write the device
94 	 * @return: 0 if OK, -ve on error
95 	 */
96 	int (*write)(struct udevice *dev, int offset, const void *buf,
97 		     int size);
98 	/*
99 	 * Assert command to the device, optional.
100 	 *
101 	 * @dev: the device
102 	 * @request: command to be sent to the device
103 	 * @buf: pointer to buffer related to the request
104 	 * @return: 0 if OK, -ve on error
105 	 */
106 	int (*ioctl)(struct udevice *dev, unsigned long request, void *buf);
107 	/*
108 	 * Send a message to the device and wait for a response.
109 	 *
110 	 * @dev: the device
111 	 * @msgid: the message ID/number to send
112 	 * tx_msg: the request/transmit message payload
113 	 * tx_size: the size of the buffer pointed at by tx_msg
114 	 * rx_msg: the buffer to receive the response message payload. May be
115 	 *         NULL if the caller only cares about the error code.
116 	 * rx_size: the size of the buffer pointed at by rx_msg
117 	 * @return the response message size if OK, -ve on error
118 	 */
119 	int (*call)(struct udevice *dev, int msgid, void *tx_msg, int tx_size,
120 		    void *rx_msg, int rx_size);
121 };
122 
123 #endif	/* _MISC_H_ */
124