misc.h 3.6 KB

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