misc.h 4.8 KB

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