xref: /linux-6.15/include/linux/mfd/dln2.h (revision b2441318)
1*b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
2338a1281SOctavian Purdila #ifndef __LINUX_USB_DLN2_H
3338a1281SOctavian Purdila #define __LINUX_USB_DLN2_H
4338a1281SOctavian Purdila 
5338a1281SOctavian Purdila #define DLN2_CMD(cmd, id)		((cmd) | ((id) << 8))
6338a1281SOctavian Purdila 
7338a1281SOctavian Purdila struct dln2_platform_data {
8338a1281SOctavian Purdila 	u16 handle;		/* sub-driver handle (internally used only) */
9338a1281SOctavian Purdila 	u8 port;		/* I2C/SPI port */
10338a1281SOctavian Purdila };
11338a1281SOctavian Purdila 
12338a1281SOctavian Purdila /**
13338a1281SOctavian Purdila  * dln2_event_cb_t - event callback function signature
14338a1281SOctavian Purdila  *
15338a1281SOctavian Purdila  * @pdev - the sub-device that registered this callback
16338a1281SOctavian Purdila  * @echo - the echo header field received in the message
17338a1281SOctavian Purdila  * @data - the data payload
18338a1281SOctavian Purdila  * @len  - the data payload length
19338a1281SOctavian Purdila  *
20338a1281SOctavian Purdila  * The callback function is called in interrupt context and the data payload is
21338a1281SOctavian Purdila  * only valid during the call. If the user needs later access of the data, it
22338a1281SOctavian Purdila  * must copy it.
23338a1281SOctavian Purdila  */
24338a1281SOctavian Purdila 
25338a1281SOctavian Purdila typedef void (*dln2_event_cb_t)(struct platform_device *pdev, u16 echo,
26338a1281SOctavian Purdila 				const void *data, int len);
27338a1281SOctavian Purdila 
28338a1281SOctavian Purdila /**
29338a1281SOctavian Purdila  * dl2n_register_event_cb - register a callback function for an event
30338a1281SOctavian Purdila  *
31338a1281SOctavian Purdila  * @pdev - the sub-device that registers the callback
32338a1281SOctavian Purdila  * @event - the event for which to register a callback
33338a1281SOctavian Purdila  * @event_cb - the callback function
34338a1281SOctavian Purdila  *
35338a1281SOctavian Purdila  * @return 0 in case of success, negative value in case of error
36338a1281SOctavian Purdila  */
37338a1281SOctavian Purdila int dln2_register_event_cb(struct platform_device *pdev, u16 event,
38338a1281SOctavian Purdila 			   dln2_event_cb_t event_cb);
39338a1281SOctavian Purdila 
40338a1281SOctavian Purdila /**
41338a1281SOctavian Purdila  * dln2_unregister_event_cb - unregister the callback function for an event
42338a1281SOctavian Purdila  *
43338a1281SOctavian Purdila  * @pdev - the sub-device that registered the callback
44338a1281SOctavian Purdila  * @event - the event for which to register a callback
45338a1281SOctavian Purdila  */
46338a1281SOctavian Purdila void dln2_unregister_event_cb(struct platform_device *pdev, u16 event);
47338a1281SOctavian Purdila 
48338a1281SOctavian Purdila /**
49338a1281SOctavian Purdila  * dln2_transfer - issue a DLN2 command and wait for a response and the
50338a1281SOctavian Purdila  * associated data
51338a1281SOctavian Purdila  *
52338a1281SOctavian Purdila  * @pdev - the sub-device which is issuing this transfer
53338a1281SOctavian Purdila  * @cmd - the command to be sent to the device
54338a1281SOctavian Purdila  * @obuf - the buffer to be sent to the device; it can be NULL if the user
55338a1281SOctavian Purdila  *	doesn't need to transmit data with this command
56338a1281SOctavian Purdila  * @obuf_len - the size of the buffer to be sent to the device
57338a1281SOctavian Purdila  * @ibuf - any data associated with the response will be copied here; it can be
58338a1281SOctavian Purdila  *	NULL if the user doesn't need the response data
59338a1281SOctavian Purdila  * @ibuf_len - must be initialized to the input buffer size; it will be modified
60338a1281SOctavian Purdila  *	to indicate the actual data transferred;
61338a1281SOctavian Purdila  *
62338a1281SOctavian Purdila  * @return 0 for success, negative value for errors
63338a1281SOctavian Purdila  */
64338a1281SOctavian Purdila int dln2_transfer(struct platform_device *pdev, u16 cmd,
65338a1281SOctavian Purdila 		  const void *obuf, unsigned obuf_len,
66338a1281SOctavian Purdila 		  void *ibuf, unsigned *ibuf_len);
67338a1281SOctavian Purdila 
68338a1281SOctavian Purdila /**
69338a1281SOctavian Purdila  * dln2_transfer_rx - variant of @dln2_transfer() where TX buffer is not needed
70338a1281SOctavian Purdila  *
71338a1281SOctavian Purdila  * @pdev - the sub-device which is issuing this transfer
72338a1281SOctavian Purdila  * @cmd - the command to be sent to the device
73338a1281SOctavian Purdila  * @ibuf - any data associated with the response will be copied here; it can be
74338a1281SOctavian Purdila  *	NULL if the user doesn't need the response data
75338a1281SOctavian Purdila  * @ibuf_len - must be initialized to the input buffer size; it will be modified
76338a1281SOctavian Purdila  *	to indicate the actual data transferred;
77338a1281SOctavian Purdila  *
78338a1281SOctavian Purdila  * @return 0 for success, negative value for errors
79338a1281SOctavian Purdila  */
80338a1281SOctavian Purdila 
dln2_transfer_rx(struct platform_device * pdev,u16 cmd,void * ibuf,unsigned * ibuf_len)81338a1281SOctavian Purdila static inline int dln2_transfer_rx(struct platform_device *pdev, u16 cmd,
82338a1281SOctavian Purdila 				   void *ibuf, unsigned *ibuf_len)
83338a1281SOctavian Purdila {
84338a1281SOctavian Purdila 	return dln2_transfer(pdev, cmd, NULL, 0, ibuf, ibuf_len);
85338a1281SOctavian Purdila }
86338a1281SOctavian Purdila 
87338a1281SOctavian Purdila /**
88338a1281SOctavian Purdila  * dln2_transfer_tx - variant of @dln2_transfer() where RX buffer is not needed
89338a1281SOctavian Purdila  *
90338a1281SOctavian Purdila  * @pdev - the sub-device which is issuing this transfer
91338a1281SOctavian Purdila  * @cmd - the command to be sent to the device
92338a1281SOctavian Purdila  * @obuf - the buffer to be sent to the device; it can be NULL if the
93338a1281SOctavian Purdila  *	user doesn't need to transmit data with this command
94338a1281SOctavian Purdila  * @obuf_len - the size of the buffer to be sent to the device
95338a1281SOctavian Purdila  *
96338a1281SOctavian Purdila  * @return 0 for success, negative value for errors
97338a1281SOctavian Purdila  */
dln2_transfer_tx(struct platform_device * pdev,u16 cmd,const void * obuf,unsigned obuf_len)98338a1281SOctavian Purdila static inline int dln2_transfer_tx(struct platform_device *pdev, u16 cmd,
99338a1281SOctavian Purdila 				   const void *obuf, unsigned obuf_len)
100338a1281SOctavian Purdila {
101338a1281SOctavian Purdila 	return dln2_transfer(pdev, cmd, obuf, obuf_len, NULL, NULL);
102338a1281SOctavian Purdila }
103338a1281SOctavian Purdila 
104338a1281SOctavian Purdila #endif
105