dln2.h 3.5 KB

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