xref: /rk3399_rockchip-uboot/include/misc.h (revision b647f55420310beb8f576e23f3b6a69745126f71)
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 
104395e06eSThomas Chou /*
114395e06eSThomas Chou  * Read the device to buffer, optional.
124395e06eSThomas Chou  *
134395e06eSThomas Chou  * @dev: the device
144395e06eSThomas Chou  * @offset: offset to read the device
154395e06eSThomas Chou  * @buf: pointer to data buffer
164395e06eSThomas Chou  * @size: data size in bytes to read the device
174395e06eSThomas Chou  * @return: 0 if OK, -ve on error
184395e06eSThomas Chou  */
194395e06eSThomas Chou int misc_read(struct udevice *dev, int offset, void *buf, int size);
204395e06eSThomas Chou /*
214395e06eSThomas Chou  * Write buffer to the device, optional.
224395e06eSThomas Chou  *
234395e06eSThomas Chou  * @dev: the device
244395e06eSThomas Chou  * @offset: offset to write the device
254395e06eSThomas Chou  * @buf: pointer to data buffer
264395e06eSThomas Chou  * @size: data size in bytes to write the device
274395e06eSThomas Chou  * @return: 0 if OK, -ve on error
284395e06eSThomas Chou  */
294395e06eSThomas Chou int misc_write(struct udevice *dev, int offset, void *buf, int size);
304395e06eSThomas Chou /*
314395e06eSThomas Chou  * Assert command to the device, optional.
324395e06eSThomas Chou  *
334395e06eSThomas Chou  * @dev: the device
344395e06eSThomas Chou  * @request: command to be sent to the device
35f5abb409SRobert P. J. Day  * @buf: pointer to buffer related to the request
364395e06eSThomas Chou  * @return: 0 if OK, -ve on error
374395e06eSThomas Chou  */
384395e06eSThomas Chou int misc_ioctl(struct udevice *dev, unsigned long request, void *buf);
394395e06eSThomas Chou 
404395e06eSThomas Chou /*
41*b647f554SStephen Warren  * Send a message to the device and wait for a response.
42*b647f554SStephen Warren  *
43*b647f554SStephen Warren  * The caller provides the message type/ID and payload to be sent.
44*b647f554SStephen Warren  * The callee constructs any message header required, transmits it to the
45*b647f554SStephen Warren  * target, waits for a response, checks any error code in the response,
46*b647f554SStephen Warren  * strips any message header from the response, and returns the error code
47*b647f554SStephen Warren  * (or a parsed version of it) and the response message payload.
48*b647f554SStephen Warren  *
49*b647f554SStephen Warren  * @dev: the device.
50*b647f554SStephen Warren  * @msgid: the message ID/number to send.
51*b647f554SStephen Warren  * tx_msg: the request/transmit message payload.
52*b647f554SStephen Warren  * tx_size: the size of the buffer pointed at by tx_msg.
53*b647f554SStephen Warren  * rx_msg: the buffer to receive the response message payload. May be NULL if
54*b647f554SStephen Warren  *         the caller only cares about the error code.
55*b647f554SStephen Warren  * rx_size: the size of the buffer pointed at by rx_msg.
56*b647f554SStephen Warren  * @return the response message size if OK, -ve on error
57*b647f554SStephen Warren  */
58*b647f554SStephen Warren int misc_call(struct udevice *dev, int msgid, void *tx_msg, int tx_size,
59*b647f554SStephen Warren 	      void *rx_msg, int rx_size);
60*b647f554SStephen Warren 
61*b647f554SStephen Warren /*
624395e06eSThomas Chou  * struct misc_ops - Driver model Misc operations
634395e06eSThomas Chou  *
644395e06eSThomas Chou  * The uclass interface is implemented by all miscellaneous devices which
654395e06eSThomas Chou  * use driver model.
664395e06eSThomas Chou  */
674395e06eSThomas Chou struct misc_ops {
684395e06eSThomas Chou 	/*
694395e06eSThomas Chou 	 * Read the device to buffer, optional.
704395e06eSThomas Chou 	 *
714395e06eSThomas Chou 	 * @dev: the device
724395e06eSThomas Chou 	 * @offset: offset to read the device
734395e06eSThomas Chou 	 * @buf: pointer to data buffer
744395e06eSThomas Chou 	 * @size: data size in bytes to read the device
754395e06eSThomas Chou 	 * @return: 0 if OK, -ve on error
764395e06eSThomas Chou 	 */
774395e06eSThomas Chou 	int (*read)(struct udevice *dev, int offset, void *buf, int size);
784395e06eSThomas Chou 	/*
794395e06eSThomas Chou 	 * Write buffer to the device, optional.
804395e06eSThomas Chou 	 *
814395e06eSThomas Chou 	 * @dev: the device
824395e06eSThomas Chou 	 * @offset: offset to write the device
834395e06eSThomas Chou 	 * @buf: pointer to data buffer
844395e06eSThomas Chou 	 * @size: data size in bytes to write the device
854395e06eSThomas Chou 	 * @return: 0 if OK, -ve on error
864395e06eSThomas Chou 	 */
874395e06eSThomas Chou 	int (*write)(struct udevice *dev, int offset, const void *buf,
884395e06eSThomas Chou 		     int size);
894395e06eSThomas Chou 	/*
904395e06eSThomas Chou 	 * Assert command to the device, optional.
914395e06eSThomas Chou 	 *
924395e06eSThomas Chou 	 * @dev: the device
934395e06eSThomas Chou 	 * @request: command to be sent to the device
94f5abb409SRobert P. J. Day 	 * @buf: pointer to buffer related to the request
954395e06eSThomas Chou 	 * @return: 0 if OK, -ve on error
964395e06eSThomas Chou 	 */
974395e06eSThomas Chou 	int (*ioctl)(struct udevice *dev, unsigned long request, void *buf);
98*b647f554SStephen Warren 	/*
99*b647f554SStephen Warren 	 * Send a message to the device and wait for a response.
100*b647f554SStephen Warren 	 *
101*b647f554SStephen Warren 	 * @dev: the device
102*b647f554SStephen Warren 	 * @msgid: the message ID/number to send
103*b647f554SStephen Warren 	 * tx_msg: the request/transmit message payload
104*b647f554SStephen Warren 	 * tx_size: the size of the buffer pointed at by tx_msg
105*b647f554SStephen Warren 	 * rx_msg: the buffer to receive the response message payload. May be
106*b647f554SStephen Warren 	 *         NULL if the caller only cares about the error code.
107*b647f554SStephen Warren 	 * rx_size: the size of the buffer pointed at by rx_msg
108*b647f554SStephen Warren 	 * @return the response message size if OK, -ve on error
109*b647f554SStephen Warren 	 */
110*b647f554SStephen Warren 	int (*call)(struct udevice *dev, int msgid, void *tx_msg, int tx_size,
111*b647f554SStephen Warren 		    void *rx_msg, int rx_size);
1124395e06eSThomas Chou };
1134395e06eSThomas Chou 
1144395e06eSThomas Chou #endif	/* _MISC_H_ */
115