xref: /rk3399_rockchip-uboot/include/misc.h (revision dbfe5ed512963ad172d4b79e7369f60f69877ff4)
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 
10*dbfe5ed5SJoseph Chen #include <asm-generic/ioctl.h>
11*dbfe5ed5SJoseph Chen 
12*dbfe5ed5SJoseph Chen /*
13*dbfe5ed5SJoseph Chen  * Request command to be sent for misc_ioctl().
14*dbfe5ed5SJoseph Chen  */
15*dbfe5ed5SJoseph Chen #define IOCTL_REQ_START		_IO('m', 0x01)
16*dbfe5ed5SJoseph Chen #define IOCTL_REQ_STOP		_IO('m', 0x02)
17*dbfe5ed5SJoseph Chen #define IOCTL_REQ_POLL		_IO('m', 0x03)
18*dbfe5ed5SJoseph Chen 
194395e06eSThomas Chou /*
204395e06eSThomas Chou  * Read the device to buffer, optional.
214395e06eSThomas Chou  *
224395e06eSThomas Chou  * @dev: the device
234395e06eSThomas Chou  * @offset: offset to read the device
244395e06eSThomas Chou  * @buf: pointer to data buffer
254395e06eSThomas Chou  * @size: data size in bytes to read the device
264395e06eSThomas Chou  * @return: 0 if OK, -ve on error
274395e06eSThomas Chou  */
284395e06eSThomas Chou int misc_read(struct udevice *dev, int offset, void *buf, int size);
294395e06eSThomas Chou /*
304395e06eSThomas Chou  * Write buffer to the device, optional.
314395e06eSThomas Chou  *
324395e06eSThomas Chou  * @dev: the device
334395e06eSThomas Chou  * @offset: offset to write the device
344395e06eSThomas Chou  * @buf: pointer to data buffer
354395e06eSThomas Chou  * @size: data size in bytes to write the device
364395e06eSThomas Chou  * @return: 0 if OK, -ve on error
374395e06eSThomas Chou  */
384395e06eSThomas Chou int misc_write(struct udevice *dev, int offset, void *buf, int size);
394395e06eSThomas Chou /*
404395e06eSThomas Chou  * Assert command to the device, optional.
414395e06eSThomas Chou  *
424395e06eSThomas Chou  * @dev: the device
434395e06eSThomas Chou  * @request: command to be sent to the device
44f5abb409SRobert P. J. Day  * @buf: pointer to buffer related to the request
454395e06eSThomas Chou  * @return: 0 if OK, -ve on error
464395e06eSThomas Chou  */
474395e06eSThomas Chou int misc_ioctl(struct udevice *dev, unsigned long request, void *buf);
484395e06eSThomas Chou 
494395e06eSThomas Chou /*
50b647f554SStephen Warren  * Send a message to the device and wait for a response.
51b647f554SStephen Warren  *
52b647f554SStephen Warren  * The caller provides the message type/ID and payload to be sent.
53b647f554SStephen Warren  * The callee constructs any message header required, transmits it to the
54b647f554SStephen Warren  * target, waits for a response, checks any error code in the response,
55b647f554SStephen Warren  * strips any message header from the response, and returns the error code
56b647f554SStephen Warren  * (or a parsed version of it) and the response message payload.
57b647f554SStephen Warren  *
58b647f554SStephen Warren  * @dev: the device.
59b647f554SStephen Warren  * @msgid: the message ID/number to send.
60b647f554SStephen Warren  * tx_msg: the request/transmit message payload.
61b647f554SStephen Warren  * tx_size: the size of the buffer pointed at by tx_msg.
62b647f554SStephen Warren  * rx_msg: the buffer to receive the response message payload. May be NULL if
63b647f554SStephen Warren  *         the caller only cares about the error code.
64b647f554SStephen Warren  * rx_size: the size of the buffer pointed at by rx_msg.
65b647f554SStephen Warren  * @return the response message size if OK, -ve on error
66b647f554SStephen Warren  */
67b647f554SStephen Warren int misc_call(struct udevice *dev, int msgid, void *tx_msg, int tx_size,
68b647f554SStephen Warren 	      void *rx_msg, int rx_size);
69b647f554SStephen Warren 
70b647f554SStephen Warren /*
714395e06eSThomas Chou  * struct misc_ops - Driver model Misc operations
724395e06eSThomas Chou  *
734395e06eSThomas Chou  * The uclass interface is implemented by all miscellaneous devices which
744395e06eSThomas Chou  * use driver model.
754395e06eSThomas Chou  */
764395e06eSThomas Chou struct misc_ops {
774395e06eSThomas Chou 	/*
784395e06eSThomas Chou 	 * Read the device to buffer, optional.
794395e06eSThomas Chou 	 *
804395e06eSThomas Chou 	 * @dev: the device
814395e06eSThomas Chou 	 * @offset: offset to read the device
824395e06eSThomas Chou 	 * @buf: pointer to data buffer
834395e06eSThomas Chou 	 * @size: data size in bytes to read the device
844395e06eSThomas Chou 	 * @return: 0 if OK, -ve on error
854395e06eSThomas Chou 	 */
864395e06eSThomas Chou 	int (*read)(struct udevice *dev, int offset, void *buf, int size);
874395e06eSThomas Chou 	/*
884395e06eSThomas Chou 	 * Write buffer to the device, optional.
894395e06eSThomas Chou 	 *
904395e06eSThomas Chou 	 * @dev: the device
914395e06eSThomas Chou 	 * @offset: offset to write the device
924395e06eSThomas Chou 	 * @buf: pointer to data buffer
934395e06eSThomas Chou 	 * @size: data size in bytes to write the device
944395e06eSThomas Chou 	 * @return: 0 if OK, -ve on error
954395e06eSThomas Chou 	 */
964395e06eSThomas Chou 	int (*write)(struct udevice *dev, int offset, const void *buf,
974395e06eSThomas Chou 		     int size);
984395e06eSThomas Chou 	/*
994395e06eSThomas Chou 	 * Assert command to the device, optional.
1004395e06eSThomas Chou 	 *
1014395e06eSThomas Chou 	 * @dev: the device
1024395e06eSThomas Chou 	 * @request: command to be sent to the device
103f5abb409SRobert P. J. Day 	 * @buf: pointer to buffer related to the request
1044395e06eSThomas Chou 	 * @return: 0 if OK, -ve on error
1054395e06eSThomas Chou 	 */
1064395e06eSThomas Chou 	int (*ioctl)(struct udevice *dev, unsigned long request, void *buf);
107b647f554SStephen Warren 	/*
108b647f554SStephen Warren 	 * Send a message to the device and wait for a response.
109b647f554SStephen Warren 	 *
110b647f554SStephen Warren 	 * @dev: the device
111b647f554SStephen Warren 	 * @msgid: the message ID/number to send
112b647f554SStephen Warren 	 * tx_msg: the request/transmit message payload
113b647f554SStephen Warren 	 * tx_size: the size of the buffer pointed at by tx_msg
114b647f554SStephen Warren 	 * rx_msg: the buffer to receive the response message payload. May be
115b647f554SStephen Warren 	 *         NULL if the caller only cares about the error code.
116b647f554SStephen Warren 	 * rx_size: the size of the buffer pointed at by rx_msg
117b647f554SStephen Warren 	 * @return the response message size if OK, -ve on error
118b647f554SStephen Warren 	 */
119b647f554SStephen Warren 	int (*call)(struct udevice *dev, int msgid, void *tx_msg, int tx_size,
120b647f554SStephen Warren 		    void *rx_msg, int rx_size);
1214395e06eSThomas Chou };
1224395e06eSThomas Chou 
1234395e06eSThomas Chou #endif	/* _MISC_H_ */
124