Convert CONFIG_SAMSUNG_ONENAND to Kconfig
[platform/kernel/u-boot.git] / include / misc.h
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 struct udevice;
10
11 /**
12  * misc_read() - Read the device to buffer, optional.
13  * @dev: the device
14  * @offset: offset to read the device
15  * @buf: pointer to data buffer
16  * @size: data size in bytes to read the device
17  *
18  * Return: number of bytes read if OK (may be 0 if EOF), -ve on error
19  */
20 int misc_read(struct udevice *dev, int offset, void *buf, int size);
21
22 /**
23  * misc_write() - Write buffer to the device, optional.
24  * @dev: the device
25  * @offset: offset to write the device
26  * @buf: pointer to data buffer
27  * @size: data size in bytes to write the device
28  *
29  * Return: number of bytes written if OK (may be < @size), -ve on error
30  */
31 int misc_write(struct udevice *dev, int offset, const void *buf, int size);
32
33 /**
34  * misc_ioctl() - Assert command to the device, optional.
35  * @dev: the device
36  * @request: command to be sent to the device
37  * @buf: pointer to buffer related to the request
38  *
39  * Return: 0 if OK, -ve on error
40  */
41 int misc_ioctl(struct udevice *dev, unsigned long request, void *buf);
42
43 /**
44  * misc_call() - Send a message to the device and wait for a response.
45  * @dev: the device.
46  * @msgid: the message ID/number to send.
47  * @tx_msg: the request/transmit message payload.
48  * @tx_size: the size of the buffer pointed at by tx_msg.
49  * @rx_msg: the buffer to receive the response message payload. May be NULL if
50  *          the caller only cares about the error code.
51  * @rx_size: the size of the buffer pointed at by rx_msg.
52  *
53  * The caller provides the message type/ID and payload to be sent.
54  * The callee constructs any message header required, transmits it to the
55  * target, waits for a response, checks any error code in the response,
56  * strips any message header from the response, and returns the error code
57  * (or a parsed version of it) and the response message payload.
58  *
59  * Return: the response message size if OK, -ve on error
60  */
61 int misc_call(struct udevice *dev, int msgid, void *tx_msg, int tx_size,
62               void *rx_msg, int rx_size);
63
64 /**
65  * misc_set_enabled() - Enable or disable a device.
66  * @dev: the device to enable or disable.
67  * @val: the flag that tells the driver to either enable or disable the device.
68  *
69  * The semantics of "disable" and "enable" should be understood here as
70  * activating or deactivating the device's primary function, hence a "disabled"
71  * device should be dormant, but still answer to commands and queries.
72  *
73  * A probed device may start in a disabled or enabled state, depending on the
74  * driver and hardware.
75  *
76  * Return: -ve on error, 0 if the previous state was "disabled", 1 if the
77  *         previous state was "enabled"
78  */
79 int misc_set_enabled(struct udevice *dev, bool val);
80
81 /*
82  * struct misc_ops - Driver model Misc operations
83  *
84  * The uclass interface is implemented by all miscellaneous devices which
85  * use driver model.
86  */
87 struct misc_ops {
88         /**
89          * Read the device to buffer, optional.
90          * @dev: the device
91          * @offset: offset to read the device
92          * @buf: pointer to data buffer
93          * @size: data size in bytes to read the device
94          *
95          * Return: number of bytes read if OK (may be 0 if EOF), -ve on error
96          */
97         int (*read)(struct udevice *dev, int offset, void *buf, int size);
98
99         /**
100          * Write buffer to the device, optional.
101          * @dev: the device
102          * @offset: offset to write the device
103          * @buf: pointer to data buffer
104          * @size: data size in bytes to write the device
105          *
106          * Return: number of bytes written if OK (may be < @size), -ve on error
107          */
108         int (*write)(struct udevice *dev, int offset, const void *buf,
109                      int size);
110         /**
111          * Assert command to the device, optional.
112          * @dev: the device
113          * @request: command to be sent to the device
114          * @buf: pointer to buffer related to the request
115          *
116          * Return: 0 if OK, -ve on error
117          */
118         int (*ioctl)(struct udevice *dev, unsigned long request, void *buf);
119
120         /**
121          * Send a message to the device and wait for a response.
122          * @dev: the device
123          * @msgid: the message ID/number to send
124          * @tx_msg: the request/transmit message payload
125          * @tx_size: the size of the buffer pointed at by tx_msg
126          * @rx_msg: the buffer to receive the response message payload. May be
127          *          NULL if the caller only cares about the error code.
128          * @rx_size: the size of the buffer pointed at by rx_msg
129          *
130          * Return: the response message size if OK, -ve on error
131          */
132         int (*call)(struct udevice *dev, int msgid, void *tx_msg, int tx_size,
133                     void *rx_msg, int rx_size);
134         /**
135          * Enable or disable a device, optional.
136          * @dev: the device to enable.
137          * @val: the flag that tells the driver to either enable or disable the
138          *       device.
139          *
140          * Return: -ve on error, 0 if the previous state was "disabled", 1 if
141          *         the previous state was "enabled"
142          */
143         int (*set_enabled)(struct udevice *dev, bool val);
144 };
145
146 #endif  /* _MISC_H_ */