blob: ce2f05dfd4cb744fc0fa94785109443684c265dd [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
Mario Six3958bff2018-07-31 14:24:12 +02009/**
10 * misc_read() - Read the device to buffer, optional.
Thomas Chou4395e062015-10-07 20:20:51 +080011 * @dev: the device
12 * @offset: offset to read the device
13 * @buf: pointer to data buffer
14 * @size: data size in bytes to read the device
Mario Six3958bff2018-07-31 14:24:12 +020015 *
16 * Return: 0 if OK, -ve on error
Thomas Chou4395e062015-10-07 20:20:51 +080017 */
18int misc_read(struct udevice *dev, int offset, void *buf, int size);
Mario Six3958bff2018-07-31 14:24:12 +020019
20/**
21 * misc_write() - Write buffer to the device, optional.
Thomas Chou4395e062015-10-07 20:20:51 +080022 * @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
Mario Six3958bff2018-07-31 14:24:12 +020026 *
27 * Return: 0 if OK, -ve on error
Thomas Chou4395e062015-10-07 20:20:51 +080028 */
29int misc_write(struct udevice *dev, int offset, void *buf, int size);
Mario Six3958bff2018-07-31 14:24:12 +020030
31/**
32 * misc_ioctl() - Assert command to the device, optional.
Thomas Chou4395e062015-10-07 20:20:51 +080033 * @dev: the device
34 * @request: command to be sent to the device
Robert P. J. Dayf5abb402015-12-14 06:28:51 -050035 * @buf: pointer to buffer related to the request
Mario Six3958bff2018-07-31 14:24:12 +020036 *
37 * Return: 0 if OK, -ve on error
Thomas Chou4395e062015-10-07 20:20:51 +080038 */
39int misc_ioctl(struct udevice *dev, unsigned long request, void *buf);
40
Mario Six3958bff2018-07-31 14:24:12 +020041/**
42 * misc_call() - Send a message to the device and wait for a response.
43 * @dev: the device.
44 * @msgid: the message ID/number to send.
45 * @tx_msg: the request/transmit message payload.
46 * @tx_size: the size of the buffer pointed at by tx_msg.
47 * @rx_msg: the buffer to receive the response message payload. May be NULL if
48 * the caller only cares about the error code.
49 * @rx_size: the size of the buffer pointed at by rx_msg.
Stephen Warrenb647f552016-08-08 09:41:33 -060050 *
51 * The caller provides the message type/ID and payload to be sent.
52 * The callee constructs any message header required, transmits it to the
53 * target, waits for a response, checks any error code in the response,
54 * strips any message header from the response, and returns the error code
55 * (or a parsed version of it) and the response message payload.
56 *
Mario Six3958bff2018-07-31 14:24:12 +020057 * Return: the response message size if OK, -ve on error
Stephen Warrenb647f552016-08-08 09:41:33 -060058 */
59int misc_call(struct udevice *dev, int msgid, void *tx_msg, int tx_size,
60 void *rx_msg, int rx_size);
61
Mario Six3958bff2018-07-31 14:24:12 +020062/**
Thomas Chou4395e062015-10-07 20:20:51 +080063 * struct misc_ops - Driver model Misc operations
64 *
65 * The uclass interface is implemented by all miscellaneous devices which
66 * use driver model.
67 */
68struct misc_ops {
Mario Six3958bff2018-07-31 14:24:12 +020069 /**
Thomas Chou4395e062015-10-07 20:20:51 +080070 * Read the device to buffer, optional.
Thomas Chou4395e062015-10-07 20:20:51 +080071 * @dev: the device
72 * @offset: offset to read the device
73 * @buf: pointer to data buffer
74 * @size: data size in bytes to read the device
Mario Six3958bff2018-07-31 14:24:12 +020075 *
76 * Return: 0 if OK, -ve on error
Thomas Chou4395e062015-10-07 20:20:51 +080077 */
78 int (*read)(struct udevice *dev, int offset, void *buf, int size);
Mario Six3958bff2018-07-31 14:24:12 +020079
80 /**
Thomas Chou4395e062015-10-07 20:20:51 +080081 * Write buffer to the device, optional.
Thomas Chou4395e062015-10-07 20:20:51 +080082 * @dev: the device
83 * @offset: offset to write the device
84 * @buf: pointer to data buffer
85 * @size: data size in bytes to write the device
Mario Six3958bff2018-07-31 14:24:12 +020086 *
87 * Return: 0 if OK, -ve on error
Thomas Chou4395e062015-10-07 20:20:51 +080088 */
89 int (*write)(struct udevice *dev, int offset, const void *buf,
90 int size);
Mario Six3958bff2018-07-31 14:24:12 +020091 /**
Thomas Chou4395e062015-10-07 20:20:51 +080092 * Assert command to the device, optional.
Thomas Chou4395e062015-10-07 20:20:51 +080093 * @dev: the device
94 * @request: command to be sent to the device
Robert P. J. Dayf5abb402015-12-14 06:28:51 -050095 * @buf: pointer to buffer related to the request
Mario Six3958bff2018-07-31 14:24:12 +020096 *
97 * Return: 0 if OK, -ve on error
Thomas Chou4395e062015-10-07 20:20:51 +080098 */
99 int (*ioctl)(struct udevice *dev, unsigned long request, void *buf);
Mario Six3958bff2018-07-31 14:24:12 +0200100
101 /**
Stephen Warrenb647f552016-08-08 09:41:33 -0600102 * Send a message to the device and wait for a response.
Stephen Warrenb647f552016-08-08 09:41:33 -0600103 * @dev: the device
104 * @msgid: the message ID/number to send
Mario Six3958bff2018-07-31 14:24:12 +0200105 * @tx_msg: the request/transmit message payload
106 * @tx_size: the size of the buffer pointed at by tx_msg
107 * @rx_msg: the buffer to receive the response message payload. May be
108 * NULL if the caller only cares about the error code.
109 * @rx_size: the size of the buffer pointed at by rx_msg
110 *
111 * Return: the response message size if OK, -ve on error
Stephen Warrenb647f552016-08-08 09:41:33 -0600112 */
113 int (*call)(struct udevice *dev, int msgid, void *tx_msg, int tx_size,
114 void *rx_msg, int rx_size);
Thomas Chou4395e062015-10-07 20:20:51 +0800115};
116
117#endif /* _MISC_H_ */