xref: /openbmc/linux/sound/soc/sprd/sprd-mcdt.h (revision 8f762fe5)
1 // SPDX-License-Identifier: GPL-2.0
2 
3 #ifndef __SPRD_MCDT_H
4 #define __SPRD_MCDT_H
5 
6 enum sprd_mcdt_channel_type {
7 	SPRD_MCDT_DAC_CHAN,
8 	SPRD_MCDT_ADC_CHAN,
9 	SPRD_MCDT_UNKNOWN_CHAN,
10 };
11 
12 enum sprd_mcdt_dma_chan {
13 	SPRD_MCDT_DMA_CH0,
14 	SPRD_MCDT_DMA_CH1,
15 	SPRD_MCDT_DMA_CH2,
16 	SPRD_MCDT_DMA_CH3,
17 	SPRD_MCDT_DMA_CH4,
18 };
19 
20 struct sprd_mcdt_chan_callback {
21 	void (*notify)(void *data);
22 	void *data;
23 };
24 
25 /**
26  * struct sprd_mcdt_chan - this struct represents a single channel instance
27  * @mcdt: the mcdt controller
28  * @id: channel id
29  * @fifo_phys: channel fifo physical address which is used for DMA transfer
30  * @type: channel type
31  * @cb: channel fifo interrupt's callback interface to notify the fifo events
32  * @dma_enable: indicate if use DMA mode to transfer data
33  * @int_enable: indicate if use interrupt mode to notify users to read or
34  * write data manually
35  * @list: used to link into the global list
36  *
37  * Note: users should not modify any members of this structure.
38  */
39 struct sprd_mcdt_chan {
40 	struct sprd_mcdt_dev *mcdt;
41 	u8 id;
42 	unsigned long fifo_phys;
43 	enum sprd_mcdt_channel_type type;
44 	enum sprd_mcdt_dma_chan dma_chan;
45 	struct sprd_mcdt_chan_callback *cb;
46 	bool dma_enable;
47 	bool int_enable;
48 	struct list_head list;
49 };
50 
51 #ifdef CONFIG_SND_SOC_SPRD_MCDT
52 struct sprd_mcdt_chan *sprd_mcdt_request_chan(u8 channel,
53 					      enum sprd_mcdt_channel_type type);
54 void sprd_mcdt_free_chan(struct sprd_mcdt_chan *chan);
55 
56 int sprd_mcdt_chan_write(struct sprd_mcdt_chan *chan, char *tx_buf, u32 size);
57 int sprd_mcdt_chan_read(struct sprd_mcdt_chan *chan, char *rx_buf, u32 size);
58 int sprd_mcdt_chan_int_enable(struct sprd_mcdt_chan *chan, u32 water_mark,
59 			      struct sprd_mcdt_chan_callback *cb);
60 void sprd_mcdt_chan_int_disable(struct sprd_mcdt_chan *chan);
61 
62 int sprd_mcdt_chan_dma_enable(struct sprd_mcdt_chan *chan,
63 			      enum sprd_mcdt_dma_chan dma_chan, u32 water_mark);
64 void sprd_mcdt_chan_dma_disable(struct sprd_mcdt_chan *chan);
65 
66 #else
67 
68 struct sprd_mcdt_chan *sprd_mcdt_request_chan(u8 channel,
69 					      enum sprd_mcdt_channel_type type)
70 {
71 	return NULL;
72 }
73 
74 void sprd_mcdt_free_chan(struct sprd_mcdt_chan *chan)
75 { }
76 
77 int sprd_mcdt_chan_write(struct sprd_mcdt_chan *chan, char *tx_buf, u32 size)
78 {
79 	return -EINVAL;
80 }
81 
82 int sprd_mcdt_chan_read(struct sprd_mcdt_chan *chan, char *rx_buf, u32 size)
83 {
84 	return 0;
85 }
86 
87 int sprd_mcdt_chan_int_enable(struct sprd_mcdt_chan *chan, u32 water_mark,
88 			      struct sprd_mcdt_chan_callback *cb)
89 {
90 	return -EINVAL;
91 }
92 
93 void sprd_mcdt_chan_int_disable(struct sprd_mcdt_chan *chan)
94 { }
95 
96 int sprd_mcdt_chan_dma_enable(struct sprd_mcdt_chan *chan,
97 			      enum sprd_mcdt_dma_chan dma_chan, u32 water_mark)
98 {
99 	return -EINVAL;
100 }
101 
102 void sprd_mcdt_chan_dma_disable(struct sprd_mcdt_chan *chan)
103 { }
104 
105 #endif
106 
107 #endif /* __SPRD_MCDT_H */
108