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