blob: 68f8e64d61abbabd3a7631db1246c53e50af916b [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Thomas Chou4395e062015-10-07 20:20:51 +08002/*
3 * Copyright (C) 2015 Thomas Chou <thomas@wytron.com.tw>
Thomas Chou4395e062015-10-07 20:20:51 +08004 */
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 */
18int 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 */
28int 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
Robert P. J. Dayf5abb402015-12-14 06:28:51 -050034 * @buf: pointer to buffer related to the request
Thomas Chou4395e062015-10-07 20:20:51 +080035 * @return: 0 if OK, -ve on error
36 */
37int misc_ioctl(struct udevice *dev, unsigned long request, void *buf);
38
39/*
Stephen Warrenb647f552016-08-08 09:41:33 -060040 * 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 */
57int misc_call(struct udevice *dev, int msgid, void *tx_msg, int tx_size,
58 void *rx_msg, int rx_size);
59
60/*
Thomas Chou4395e062015-10-07 20:20:51 +080061 * struct misc_ops - Driver model Misc operations
62 *
63 * The uclass interface is implemented by all miscellaneous devices which
64 * use driver model.
65 */
66struct 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
Robert P. J. Dayf5abb402015-12-14 06:28:51 -050093 * @buf: pointer to buffer related to the request
Thomas Chou4395e062015-10-07 20:20:51 +080094 * @return: 0 if OK, -ve on error
95 */
96 int (*ioctl)(struct udevice *dev, unsigned long request, void *buf);
Stephen Warrenb647f552016-08-08 09:41:33 -060097 /*
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);
Thomas Chou4395e062015-10-07 20:20:51 +0800111};
112
113#endif /* _MISC_H_ */