misc.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * Copyright (C) 2015 Thomas Chou <thomas@wytron.com.tw>
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #ifndef _MISC_H_
  7. #define _MISC_H_
  8. /*
  9. * Read the device to buffer, optional.
  10. *
  11. * @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
  15. * @return: 0 if OK, -ve on error
  16. */
  17. int misc_read(struct udevice *dev, int offset, void *buf, int size);
  18. /*
  19. * Write buffer to the device, optional.
  20. *
  21. * @dev: the device
  22. * @offset: offset to write the device
  23. * @buf: pointer to data buffer
  24. * @size: data size in bytes to write the device
  25. * @return: 0 if OK, -ve on error
  26. */
  27. int misc_write(struct udevice *dev, int offset, void *buf, int size);
  28. /*
  29. * Assert command to the device, optional.
  30. *
  31. * @dev: the device
  32. * @request: command to be sent to the device
  33. * @buf: pointer to buffer related to the request
  34. * @return: 0 if OK, -ve on error
  35. */
  36. int misc_ioctl(struct udevice *dev, unsigned long request, void *buf);
  37. /*
  38. * Send a message to the device and wait for a response.
  39. *
  40. * The caller provides the message type/ID and payload to be sent.
  41. * The callee constructs any message header required, transmits it to the
  42. * target, waits for a response, checks any error code in the response,
  43. * strips any message header from the response, and returns the error code
  44. * (or a parsed version of it) and the response message payload.
  45. *
  46. * @dev: the device.
  47. * @msgid: the message ID/number to send.
  48. * tx_msg: the request/transmit message payload.
  49. * tx_size: the size of the buffer pointed at by tx_msg.
  50. * rx_msg: the buffer to receive the response message payload. May be NULL if
  51. * the caller only cares about the error code.
  52. * rx_size: the size of the buffer pointed at by rx_msg.
  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. * struct misc_ops - Driver model Misc operations
  59. *
  60. * The uclass interface is implemented by all miscellaneous devices which
  61. * use driver model.
  62. */
  63. struct misc_ops {
  64. /*
  65. * Read the device to buffer, optional.
  66. *
  67. * @dev: the device
  68. * @offset: offset to read the device
  69. * @buf: pointer to data buffer
  70. * @size: data size in bytes to read the device
  71. * @return: 0 if OK, -ve on error
  72. */
  73. int (*read)(struct udevice *dev, int offset, void *buf, int size);
  74. /*
  75. * Write buffer to the device, optional.
  76. *
  77. * @dev: the device
  78. * @offset: offset to write the device
  79. * @buf: pointer to data buffer
  80. * @size: data size in bytes to write the device
  81. * @return: 0 if OK, -ve on error
  82. */
  83. int (*write)(struct udevice *dev, int offset, const void *buf,
  84. int size);
  85. /*
  86. * Assert command to the device, optional.
  87. *
  88. * @dev: the device
  89. * @request: command to be sent to the device
  90. * @buf: pointer to buffer related to the request
  91. * @return: 0 if OK, -ve on error
  92. */
  93. int (*ioctl)(struct udevice *dev, unsigned long request, void *buf);
  94. /*
  95. * Send a message to the device and wait for a response.
  96. *
  97. * @dev: the device
  98. * @msgid: the message ID/number to send
  99. * tx_msg: the request/transmit message payload
  100. * tx_size: the size of the buffer pointed at by tx_msg
  101. * rx_msg: the buffer to receive the response message payload. May be
  102. * NULL if the caller only cares about the error code.
  103. * rx_size: the size of the buffer pointed at by rx_msg
  104. * @return the response message size if OK, -ve on error
  105. */
  106. int (*call)(struct udevice *dev, int msgid, void *tx_msg, int tx_size,
  107. void *rx_msg, int rx_size);
  108. };
  109. #endif /* _MISC_H_ */