blob: 6f042625c9fcba545b932af233e6ca13a67853ed [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Thomas Choub1ed6862015-10-07 20:20:51 +08002/*
3 * Copyright (C) 2015 Thomas Chou <thomas@wytron.com.tw>
Thomas Choub1ed6862015-10-07 20:20:51 +08004 */
5
6#ifndef _MISC_H_
7#define _MISC_H_
8
Simon Glass3ba929a2020-10-30 21:38:53 -06009struct udevice;
10
Mario Six70943d62018-07-31 14:24:12 +020011/**
12 * misc_read() - Read the device to buffer, optional.
Thomas Choub1ed6862015-10-07 20:20:51 +080013 * @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
Mario Six70943d62018-07-31 14:24:12 +020017 *
Simon Glass587dc402018-11-06 15:21:39 -070018 * Return: number of bytes read if OK (may be 0 if EOF), -ve on error
Thomas Choub1ed6862015-10-07 20:20:51 +080019 */
20int misc_read(struct udevice *dev, int offset, void *buf, int size);
Mario Six70943d62018-07-31 14:24:12 +020021
22/**
23 * misc_write() - Write buffer to the device, optional.
Thomas Choub1ed6862015-10-07 20:20:51 +080024 * @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
Mario Six70943d62018-07-31 14:24:12 +020028 *
Simon Glass587dc402018-11-06 15:21:39 -070029 * Return: number of bytes written if OK (may be < @size), -ve on error
Thomas Choub1ed6862015-10-07 20:20:51 +080030 */
John Keepingd6570352022-01-11 17:04:49 +000031int misc_write(struct udevice *dev, int offset, const void *buf, int size);
Mario Six70943d62018-07-31 14:24:12 +020032
33/**
34 * misc_ioctl() - Assert command to the device, optional.
Thomas Choub1ed6862015-10-07 20:20:51 +080035 * @dev: the device
36 * @request: command to be sent to the device
Robert P. J. Day21c11c52015-12-14 06:28:51 -050037 * @buf: pointer to buffer related to the request
Mario Six70943d62018-07-31 14:24:12 +020038 *
39 * Return: 0 if OK, -ve on error
Thomas Choub1ed6862015-10-07 20:20:51 +080040 */
41int misc_ioctl(struct udevice *dev, unsigned long request, void *buf);
42
Mario Six70943d62018-07-31 14:24:12 +020043/**
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.
Stephen Warren01632692016-08-08 09:41:33 -060052 *
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 *
Mario Six70943d62018-07-31 14:24:12 +020059 * Return: the response message size if OK, -ve on error
Stephen Warren01632692016-08-08 09:41:33 -060060 */
61int misc_call(struct udevice *dev, int msgid, void *tx_msg, int tx_size,
62 void *rx_msg, int rx_size);
63
Mario Six70943d62018-07-31 14:24:12 +020064/**
Mario Six8909ad22018-07-31 14:24:13 +020065 * 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 */
79int misc_set_enabled(struct udevice *dev, bool val);
80
81/*
Thomas Choub1ed6862015-10-07 20:20:51 +080082 * struct misc_ops - Driver model Misc operations
83 *
84 * The uclass interface is implemented by all miscellaneous devices which
85 * use driver model.
86 */
87struct misc_ops {
Mario Six70943d62018-07-31 14:24:12 +020088 /**
Thomas Choub1ed6862015-10-07 20:20:51 +080089 * Read the device to buffer, optional.
Thomas Choub1ed6862015-10-07 20:20:51 +080090 * @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
Mario Six70943d62018-07-31 14:24:12 +020094 *
Simon Glass587dc402018-11-06 15:21:39 -070095 * Return: number of bytes read if OK (may be 0 if EOF), -ve on error
Thomas Choub1ed6862015-10-07 20:20:51 +080096 */
97 int (*read)(struct udevice *dev, int offset, void *buf, int size);
Mario Six70943d62018-07-31 14:24:12 +020098
99 /**
Thomas Choub1ed6862015-10-07 20:20:51 +0800100 * Write buffer to the device, optional.
Thomas Choub1ed6862015-10-07 20:20:51 +0800101 * @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
Mario Six70943d62018-07-31 14:24:12 +0200105 *
Simon Glass587dc402018-11-06 15:21:39 -0700106 * Return: number of bytes written if OK (may be < @size), -ve on error
Thomas Choub1ed6862015-10-07 20:20:51 +0800107 */
108 int (*write)(struct udevice *dev, int offset, const void *buf,
109 int size);
Mario Six70943d62018-07-31 14:24:12 +0200110 /**
Thomas Choub1ed6862015-10-07 20:20:51 +0800111 * Assert command to the device, optional.
Thomas Choub1ed6862015-10-07 20:20:51 +0800112 * @dev: the device
113 * @request: command to be sent to the device
Robert P. J. Day21c11c52015-12-14 06:28:51 -0500114 * @buf: pointer to buffer related to the request
Mario Six70943d62018-07-31 14:24:12 +0200115 *
116 * Return: 0 if OK, -ve on error
Thomas Choub1ed6862015-10-07 20:20:51 +0800117 */
118 int (*ioctl)(struct udevice *dev, unsigned long request, void *buf);
Mario Six70943d62018-07-31 14:24:12 +0200119
120 /**
Stephen Warren01632692016-08-08 09:41:33 -0600121 * Send a message to the device and wait for a response.
Stephen Warren01632692016-08-08 09:41:33 -0600122 * @dev: the device
123 * @msgid: the message ID/number to send
Mario Six70943d62018-07-31 14:24:12 +0200124 * @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
Stephen Warren01632692016-08-08 09:41:33 -0600131 */
132 int (*call)(struct udevice *dev, int msgid, void *tx_msg, int tx_size,
133 void *rx_msg, int rx_size);
Mario Six8909ad22018-07-31 14:24:13 +0200134 /**
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);
Thomas Choub1ed6862015-10-07 20:20:51 +0800144};
145
146#endif /* _MISC_H_ */