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