dln2.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __LINUX_USB_DLN2_H
  3. #define __LINUX_USB_DLN2_H
  4. #define DLN2_CMD(cmd, id) ((cmd) | ((id) << 8))
  5. struct dln2_platform_data {
  6. u16 handle; /* sub-driver handle (internally used only) */
  7. u8 port; /* I2C/SPI port */
  8. };
  9. /**
  10. * dln2_event_cb_t - event callback function signature
  11. *
  12. * @pdev - the sub-device that registered this callback
  13. * @echo - the echo header field received in the message
  14. * @data - the data payload
  15. * @len - the data payload length
  16. *
  17. * The callback function is called in interrupt context and the data payload is
  18. * only valid during the call. If the user needs later access of the data, it
  19. * must copy it.
  20. */
  21. typedef void (*dln2_event_cb_t)(struct platform_device *pdev, u16 echo,
  22. const void *data, int len);
  23. /**
  24. * dl2n_register_event_cb - register a callback function for an event
  25. *
  26. * @pdev - the sub-device that registers the callback
  27. * @event - the event for which to register a callback
  28. * @event_cb - the callback function
  29. *
  30. * @return 0 in case of success, negative value in case of error
  31. */
  32. int dln2_register_event_cb(struct platform_device *pdev, u16 event,
  33. dln2_event_cb_t event_cb);
  34. /**
  35. * dln2_unregister_event_cb - unregister the callback function for an event
  36. *
  37. * @pdev - the sub-device that registered the callback
  38. * @event - the event for which to register a callback
  39. */
  40. void dln2_unregister_event_cb(struct platform_device *pdev, u16 event);
  41. /**
  42. * dln2_transfer - issue a DLN2 command and wait for a response and the
  43. * associated data
  44. *
  45. * @pdev - the sub-device which is issuing this transfer
  46. * @cmd - the command to be sent to the device
  47. * @obuf - the buffer to be sent to the device; it can be NULL if the user
  48. * doesn't need to transmit data with this command
  49. * @obuf_len - the size of the buffer to be sent to the device
  50. * @ibuf - any data associated with the response will be copied here; it can be
  51. * NULL if the user doesn't need the response data
  52. * @ibuf_len - must be initialized to the input buffer size; it will be modified
  53. * to indicate the actual data transferred;
  54. *
  55. * @return 0 for success, negative value for errors
  56. */
  57. int dln2_transfer(struct platform_device *pdev, u16 cmd,
  58. const void *obuf, unsigned obuf_len,
  59. void *ibuf, unsigned *ibuf_len);
  60. /**
  61. * dln2_transfer_rx - variant of @dln2_transfer() where TX buffer is not needed
  62. *
  63. * @pdev - the sub-device which is issuing this transfer
  64. * @cmd - the command to be sent to the device
  65. * @ibuf - any data associated with the response will be copied here; it can be
  66. * NULL if the user doesn't need the response data
  67. * @ibuf_len - must be initialized to the input buffer size; it will be modified
  68. * to indicate the actual data transferred;
  69. *
  70. * @return 0 for success, negative value for errors
  71. */
  72. static inline int dln2_transfer_rx(struct platform_device *pdev, u16 cmd,
  73. void *ibuf, unsigned *ibuf_len)
  74. {
  75. return dln2_transfer(pdev, cmd, NULL, 0, ibuf, ibuf_len);
  76. }
  77. /**
  78. * dln2_transfer_tx - variant of @dln2_transfer() where RX buffer is not needed
  79. *
  80. * @pdev - the sub-device which is issuing this transfer
  81. * @cmd - the command to be sent to the device
  82. * @obuf - the buffer to be sent to the device; it can be NULL if the
  83. * user doesn't need to transmit data with this command
  84. * @obuf_len - the size of the buffer to be sent to the device
  85. *
  86. * @return 0 for success, negative value for errors
  87. */
  88. static inline int dln2_transfer_tx(struct platform_device *pdev, u16 cmd,
  89. const void *obuf, unsigned obuf_len)
  90. {
  91. return dln2_transfer(pdev, cmd, obuf, obuf_len, NULL, NULL);
  92. }
  93. #endif