183d290c5STom Rini /* SPDX-License-Identifier: GPL-2.0+ */ 24395e06eSThomas Chou /* 34395e06eSThomas Chou * Copyright (C) 2015 Thomas Chou <thomas@wytron.com.tw> 44395e06eSThomas Chou */ 54395e06eSThomas Chou 64395e06eSThomas Chou #ifndef _MISC_H_ 74395e06eSThomas Chou #define _MISC_H_ 84395e06eSThomas Chou 93958bffeSMario Six /** 103958bffeSMario Six * misc_read() - Read the device to buffer, optional. 114395e06eSThomas Chou * @dev: the device 124395e06eSThomas Chou * @offset: offset to read the device 134395e06eSThomas Chou * @buf: pointer to data buffer 144395e06eSThomas Chou * @size: data size in bytes to read the device 153958bffeSMario Six * 16*8729b1aeSSimon Glass * Return: number of bytes read if OK (may be 0 if EOF), -ve on error 174395e06eSThomas Chou */ 184395e06eSThomas Chou int misc_read(struct udevice *dev, int offset, void *buf, int size); 193958bffeSMario Six 203958bffeSMario Six /** 213958bffeSMario Six * misc_write() - Write buffer to the device, optional. 224395e06eSThomas Chou * @dev: the device 234395e06eSThomas Chou * @offset: offset to write the device 244395e06eSThomas Chou * @buf: pointer to data buffer 254395e06eSThomas Chou * @size: data size in bytes to write the device 263958bffeSMario Six * 27*8729b1aeSSimon Glass * Return: number of bytes written if OK (may be < @size), -ve on error 284395e06eSThomas Chou */ 294395e06eSThomas Chou int misc_write(struct udevice *dev, int offset, void *buf, int size); 303958bffeSMario Six 313958bffeSMario Six /** 323958bffeSMario Six * misc_ioctl() - Assert command to the device, optional. 334395e06eSThomas Chou * @dev: the device 344395e06eSThomas Chou * @request: command to be sent to the device 35f5abb409SRobert P. J. Day * @buf: pointer to buffer related to the request 363958bffeSMario Six * 373958bffeSMario Six * Return: 0 if OK, -ve on error 384395e06eSThomas Chou */ 394395e06eSThomas Chou int misc_ioctl(struct udevice *dev, unsigned long request, void *buf); 404395e06eSThomas Chou 413958bffeSMario Six /** 423958bffeSMario Six * misc_call() - Send a message to the device and wait for a response. 433958bffeSMario Six * @dev: the device. 443958bffeSMario Six * @msgid: the message ID/number to send. 453958bffeSMario Six * @tx_msg: the request/transmit message payload. 463958bffeSMario Six * @tx_size: the size of the buffer pointed at by tx_msg. 473958bffeSMario Six * @rx_msg: the buffer to receive the response message payload. May be NULL if 483958bffeSMario Six * the caller only cares about the error code. 493958bffeSMario Six * @rx_size: the size of the buffer pointed at by rx_msg. 50b647f554SStephen Warren * 51b647f554SStephen Warren * The caller provides the message type/ID and payload to be sent. 52b647f554SStephen Warren * The callee constructs any message header required, transmits it to the 53b647f554SStephen Warren * target, waits for a response, checks any error code in the response, 54b647f554SStephen Warren * strips any message header from the response, and returns the error code 55b647f554SStephen Warren * (or a parsed version of it) and the response message payload. 56b647f554SStephen Warren * 573958bffeSMario Six * Return: the response message size if OK, -ve on error 58b647f554SStephen Warren */ 59b647f554SStephen Warren int misc_call(struct udevice *dev, int msgid, void *tx_msg, int tx_size, 60b647f554SStephen Warren void *rx_msg, int rx_size); 61b647f554SStephen Warren 623958bffeSMario Six /** 63440bc11fSMario Six * misc_set_enabled() - Enable or disable a device. 64440bc11fSMario Six * @dev: the device to enable or disable. 65440bc11fSMario Six * @val: the flag that tells the driver to either enable or disable the device. 66440bc11fSMario Six * 67440bc11fSMario Six * The semantics of "disable" and "enable" should be understood here as 68440bc11fSMario Six * activating or deactivating the device's primary function, hence a "disabled" 69440bc11fSMario Six * device should be dormant, but still answer to commands and queries. 70440bc11fSMario Six * 71440bc11fSMario Six * A probed device may start in a disabled or enabled state, depending on the 72440bc11fSMario Six * driver and hardware. 73440bc11fSMario Six * 74440bc11fSMario Six * Return: -ve on error, 0 if the previous state was "disabled", 1 if the 75440bc11fSMario Six * previous state was "enabled" 76440bc11fSMario Six */ 77440bc11fSMario Six int misc_set_enabled(struct udevice *dev, bool val); 78440bc11fSMario Six 79440bc11fSMario Six /* 804395e06eSThomas Chou * struct misc_ops - Driver model Misc operations 814395e06eSThomas Chou * 824395e06eSThomas Chou * The uclass interface is implemented by all miscellaneous devices which 834395e06eSThomas Chou * use driver model. 844395e06eSThomas Chou */ 854395e06eSThomas Chou struct misc_ops { 863958bffeSMario Six /** 874395e06eSThomas Chou * Read the device to buffer, optional. 884395e06eSThomas Chou * @dev: the device 894395e06eSThomas Chou * @offset: offset to read the device 904395e06eSThomas Chou * @buf: pointer to data buffer 914395e06eSThomas Chou * @size: data size in bytes to read the device 923958bffeSMario Six * 93*8729b1aeSSimon Glass * Return: number of bytes read if OK (may be 0 if EOF), -ve on error 944395e06eSThomas Chou */ 954395e06eSThomas Chou int (*read)(struct udevice *dev, int offset, void *buf, int size); 963958bffeSMario Six 973958bffeSMario Six /** 984395e06eSThomas Chou * Write buffer to the device, optional. 994395e06eSThomas Chou * @dev: the device 1004395e06eSThomas Chou * @offset: offset to write the device 1014395e06eSThomas Chou * @buf: pointer to data buffer 1024395e06eSThomas Chou * @size: data size in bytes to write the device 1033958bffeSMario Six * 104*8729b1aeSSimon Glass * Return: number of bytes written if OK (may be < @size), -ve on error 1054395e06eSThomas Chou */ 1064395e06eSThomas Chou int (*write)(struct udevice *dev, int offset, const void *buf, 1074395e06eSThomas Chou int size); 1083958bffeSMario Six /** 1094395e06eSThomas Chou * Assert command to the device, optional. 1104395e06eSThomas Chou * @dev: the device 1114395e06eSThomas Chou * @request: command to be sent to the device 112f5abb409SRobert P. J. Day * @buf: pointer to buffer related to the request 1133958bffeSMario Six * 1143958bffeSMario Six * Return: 0 if OK, -ve on error 1154395e06eSThomas Chou */ 1164395e06eSThomas Chou int (*ioctl)(struct udevice *dev, unsigned long request, void *buf); 1173958bffeSMario Six 1183958bffeSMario Six /** 119b647f554SStephen Warren * Send a message to the device and wait for a response. 120b647f554SStephen Warren * @dev: the device 121b647f554SStephen Warren * @msgid: the message ID/number to send 1223958bffeSMario Six * @tx_msg: the request/transmit message payload 1233958bffeSMario Six * @tx_size: the size of the buffer pointed at by tx_msg 1243958bffeSMario Six * @rx_msg: the buffer to receive the response message payload. May be 125b647f554SStephen Warren * NULL if the caller only cares about the error code. 1263958bffeSMario Six * @rx_size: the size of the buffer pointed at by rx_msg 1273958bffeSMario Six * 1283958bffeSMario Six * Return: the response message size if OK, -ve on error 129b647f554SStephen Warren */ 130b647f554SStephen Warren int (*call)(struct udevice *dev, int msgid, void *tx_msg, int tx_size, 131b647f554SStephen Warren void *rx_msg, int rx_size); 132440bc11fSMario Six /** 133440bc11fSMario Six * Enable or disable a device, optional. 134440bc11fSMario Six * @dev: the device to enable. 135440bc11fSMario Six * @val: the flag that tells the driver to either enable or disable the 136440bc11fSMario Six * device. 137440bc11fSMario Six * 138440bc11fSMario Six * Return: -ve on error, 0 if the previous state was "disabled", 1 if 139440bc11fSMario Six * the previous state was "enabled" 140440bc11fSMario Six */ 141440bc11fSMario Six int (*set_enabled)(struct udevice *dev, bool val); 1424395e06eSThomas Chou }; 1434395e06eSThomas Chou 1444395e06eSThomas Chou #endif /* _MISC_H_ */ 145