xref: /OK3568_Linux_fs/kernel/include/sound/hdaudio_ext.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun #ifndef __SOUND_HDAUDIO_EXT_H
3*4882a593Smuzhiyun #define __SOUND_HDAUDIO_EXT_H
4*4882a593Smuzhiyun 
5*4882a593Smuzhiyun #include <sound/hdaudio.h>
6*4882a593Smuzhiyun 
7*4882a593Smuzhiyun int snd_hdac_ext_bus_init(struct hdac_bus *bus, struct device *dev,
8*4882a593Smuzhiyun 		      const struct hdac_bus_ops *ops,
9*4882a593Smuzhiyun 		      const struct hdac_ext_bus_ops *ext_ops);
10*4882a593Smuzhiyun 
11*4882a593Smuzhiyun void snd_hdac_ext_bus_exit(struct hdac_bus *bus);
12*4882a593Smuzhiyun int snd_hdac_ext_bus_device_init(struct hdac_bus *bus, int addr,
13*4882a593Smuzhiyun 				struct hdac_device *hdev, int type);
14*4882a593Smuzhiyun void snd_hdac_ext_bus_device_exit(struct hdac_device *hdev);
15*4882a593Smuzhiyun void snd_hdac_ext_bus_device_remove(struct hdac_bus *bus);
16*4882a593Smuzhiyun 
17*4882a593Smuzhiyun #define HDA_CODEC_REV_EXT_ENTRY(_vid, _rev, _name, drv_data) \
18*4882a593Smuzhiyun 	{ .vendor_id = (_vid), .rev_id = (_rev), .name = (_name), \
19*4882a593Smuzhiyun 	  .api_version = HDA_DEV_ASOC, \
20*4882a593Smuzhiyun 	  .driver_data = (unsigned long)(drv_data) }
21*4882a593Smuzhiyun #define HDA_CODEC_EXT_ENTRY(_vid, _revid, _name, _drv_data) \
22*4882a593Smuzhiyun 	HDA_CODEC_REV_EXT_ENTRY(_vid, _revid, _name, _drv_data)
23*4882a593Smuzhiyun 
24*4882a593Smuzhiyun void snd_hdac_ext_bus_ppcap_enable(struct hdac_bus *chip, bool enable);
25*4882a593Smuzhiyun void snd_hdac_ext_bus_ppcap_int_enable(struct hdac_bus *chip, bool enable);
26*4882a593Smuzhiyun 
27*4882a593Smuzhiyun void snd_hdac_ext_stream_spbcap_enable(struct hdac_bus *chip,
28*4882a593Smuzhiyun 				 bool enable, int index);
29*4882a593Smuzhiyun 
30*4882a593Smuzhiyun int snd_hdac_ext_bus_get_ml_capabilities(struct hdac_bus *bus);
31*4882a593Smuzhiyun struct hdac_ext_link *snd_hdac_ext_bus_get_link(struct hdac_bus *bus,
32*4882a593Smuzhiyun 						const char *codec_name);
33*4882a593Smuzhiyun 
34*4882a593Smuzhiyun enum hdac_ext_stream_type {
35*4882a593Smuzhiyun 	HDAC_EXT_STREAM_TYPE_COUPLED = 0,
36*4882a593Smuzhiyun 	HDAC_EXT_STREAM_TYPE_HOST,
37*4882a593Smuzhiyun 	HDAC_EXT_STREAM_TYPE_LINK
38*4882a593Smuzhiyun };
39*4882a593Smuzhiyun 
40*4882a593Smuzhiyun /**
41*4882a593Smuzhiyun  * hdac_ext_stream: HDAC extended stream for extended HDA caps
42*4882a593Smuzhiyun  *
43*4882a593Smuzhiyun  * @hstream: hdac_stream
44*4882a593Smuzhiyun  * @pphc_addr: processing pipe host stream pointer
45*4882a593Smuzhiyun  * @pplc_addr: processing pipe link stream pointer
46*4882a593Smuzhiyun  * @spib_addr: software position in buffers stream pointer
47*4882a593Smuzhiyun  * @fifo_addr: software position Max fifos stream pointer
48*4882a593Smuzhiyun  * @dpibr_addr: DMA position in buffer resume pointer
49*4882a593Smuzhiyun  * @dpib: DMA position in buffer
50*4882a593Smuzhiyun  * @lpib: Linear position in buffer
51*4882a593Smuzhiyun  * @decoupled: stream host and link is decoupled
52*4882a593Smuzhiyun  * @link_locked: link is locked
53*4882a593Smuzhiyun  * @link_prepared: link is prepared
54*4882a593Smuzhiyun  * link_substream: link substream
55*4882a593Smuzhiyun  */
56*4882a593Smuzhiyun struct hdac_ext_stream {
57*4882a593Smuzhiyun 	struct hdac_stream hstream;
58*4882a593Smuzhiyun 
59*4882a593Smuzhiyun 	void __iomem *pphc_addr;
60*4882a593Smuzhiyun 	void __iomem *pplc_addr;
61*4882a593Smuzhiyun 
62*4882a593Smuzhiyun 	void __iomem *spib_addr;
63*4882a593Smuzhiyun 	void __iomem *fifo_addr;
64*4882a593Smuzhiyun 
65*4882a593Smuzhiyun 	void __iomem *dpibr_addr;
66*4882a593Smuzhiyun 
67*4882a593Smuzhiyun 	u32 dpib;
68*4882a593Smuzhiyun 	u32 lpib;
69*4882a593Smuzhiyun 	bool decoupled:1;
70*4882a593Smuzhiyun 	bool link_locked:1;
71*4882a593Smuzhiyun 	bool link_prepared;
72*4882a593Smuzhiyun 
73*4882a593Smuzhiyun 	struct snd_pcm_substream *link_substream;
74*4882a593Smuzhiyun };
75*4882a593Smuzhiyun 
76*4882a593Smuzhiyun #define hdac_stream(s)		(&(s)->hstream)
77*4882a593Smuzhiyun #define stream_to_hdac_ext_stream(s) \
78*4882a593Smuzhiyun 	container_of(s, struct hdac_ext_stream, hstream)
79*4882a593Smuzhiyun 
80*4882a593Smuzhiyun void snd_hdac_ext_stream_init(struct hdac_bus *bus,
81*4882a593Smuzhiyun 				struct hdac_ext_stream *stream, int idx,
82*4882a593Smuzhiyun 				int direction, int tag);
83*4882a593Smuzhiyun int snd_hdac_ext_stream_init_all(struct hdac_bus *bus, int start_idx,
84*4882a593Smuzhiyun 		int num_stream, int dir);
85*4882a593Smuzhiyun void snd_hdac_stream_free_all(struct hdac_bus *bus);
86*4882a593Smuzhiyun void snd_hdac_link_free_all(struct hdac_bus *bus);
87*4882a593Smuzhiyun struct hdac_ext_stream *snd_hdac_ext_stream_assign(struct hdac_bus *bus,
88*4882a593Smuzhiyun 					   struct snd_pcm_substream *substream,
89*4882a593Smuzhiyun 					   int type);
90*4882a593Smuzhiyun void snd_hdac_ext_stream_release(struct hdac_ext_stream *azx_dev, int type);
91*4882a593Smuzhiyun void snd_hdac_ext_stream_decouple_locked(struct hdac_bus *bus,
92*4882a593Smuzhiyun 				  struct hdac_ext_stream *azx_dev, bool decouple);
93*4882a593Smuzhiyun void snd_hdac_ext_stream_decouple(struct hdac_bus *bus,
94*4882a593Smuzhiyun 				struct hdac_ext_stream *azx_dev, bool decouple);
95*4882a593Smuzhiyun void snd_hdac_ext_stop_streams(struct hdac_bus *bus);
96*4882a593Smuzhiyun 
97*4882a593Smuzhiyun int snd_hdac_ext_stream_set_spib(struct hdac_bus *bus,
98*4882a593Smuzhiyun 				 struct hdac_ext_stream *stream, u32 value);
99*4882a593Smuzhiyun int snd_hdac_ext_stream_get_spbmaxfifo(struct hdac_bus *bus,
100*4882a593Smuzhiyun 				 struct hdac_ext_stream *stream);
101*4882a593Smuzhiyun void snd_hdac_ext_stream_drsm_enable(struct hdac_bus *bus,
102*4882a593Smuzhiyun 				bool enable, int index);
103*4882a593Smuzhiyun int snd_hdac_ext_stream_set_dpibr(struct hdac_bus *bus,
104*4882a593Smuzhiyun 				struct hdac_ext_stream *stream, u32 value);
105*4882a593Smuzhiyun int snd_hdac_ext_stream_set_lpib(struct hdac_ext_stream *stream, u32 value);
106*4882a593Smuzhiyun 
107*4882a593Smuzhiyun void snd_hdac_ext_link_stream_start(struct hdac_ext_stream *hstream);
108*4882a593Smuzhiyun void snd_hdac_ext_link_stream_clear(struct hdac_ext_stream *hstream);
109*4882a593Smuzhiyun void snd_hdac_ext_link_stream_reset(struct hdac_ext_stream *hstream);
110*4882a593Smuzhiyun int snd_hdac_ext_link_stream_setup(struct hdac_ext_stream *stream, int fmt);
111*4882a593Smuzhiyun 
112*4882a593Smuzhiyun struct hdac_ext_link {
113*4882a593Smuzhiyun 	struct hdac_bus *bus;
114*4882a593Smuzhiyun 	int index;
115*4882a593Smuzhiyun 	void __iomem *ml_addr; /* link output stream reg pointer */
116*4882a593Smuzhiyun 	u32 lcaps;   /* link capablities */
117*4882a593Smuzhiyun 	u16 lsdiid;  /* link sdi identifier */
118*4882a593Smuzhiyun 
119*4882a593Smuzhiyun 	int ref_count;
120*4882a593Smuzhiyun 
121*4882a593Smuzhiyun 	struct list_head list;
122*4882a593Smuzhiyun };
123*4882a593Smuzhiyun 
124*4882a593Smuzhiyun int snd_hdac_ext_bus_link_power_up(struct hdac_ext_link *link);
125*4882a593Smuzhiyun int snd_hdac_ext_bus_link_power_down(struct hdac_ext_link *link);
126*4882a593Smuzhiyun int snd_hdac_ext_bus_link_power_up_all(struct hdac_bus *bus);
127*4882a593Smuzhiyun int snd_hdac_ext_bus_link_power_down_all(struct hdac_bus *bus);
128*4882a593Smuzhiyun void snd_hdac_ext_link_set_stream_id(struct hdac_ext_link *link,
129*4882a593Smuzhiyun 				 int stream);
130*4882a593Smuzhiyun void snd_hdac_ext_link_clear_stream_id(struct hdac_ext_link *link,
131*4882a593Smuzhiyun 				 int stream);
132*4882a593Smuzhiyun 
133*4882a593Smuzhiyun int snd_hdac_ext_bus_link_get(struct hdac_bus *bus, struct hdac_ext_link *link);
134*4882a593Smuzhiyun int snd_hdac_ext_bus_link_put(struct hdac_bus *bus, struct hdac_ext_link *link);
135*4882a593Smuzhiyun 
136*4882a593Smuzhiyun /* update register macro */
137*4882a593Smuzhiyun #define snd_hdac_updatel(addr, reg, mask, val)		\
138*4882a593Smuzhiyun 	writel(((readl(addr + reg) & ~(mask)) | (val)), \
139*4882a593Smuzhiyun 		addr + reg)
140*4882a593Smuzhiyun 
141*4882a593Smuzhiyun #define snd_hdac_updatew(addr, reg, mask, val)		\
142*4882a593Smuzhiyun 	writew(((readw(addr + reg) & ~(mask)) | (val)), \
143*4882a593Smuzhiyun 		addr + reg)
144*4882a593Smuzhiyun 
145*4882a593Smuzhiyun 
146*4882a593Smuzhiyun struct hdac_ext_device;
147*4882a593Smuzhiyun 
148*4882a593Smuzhiyun /* ops common to all codec drivers */
149*4882a593Smuzhiyun struct hdac_ext_codec_ops {
150*4882a593Smuzhiyun 	int (*build_controls)(struct hdac_ext_device *dev);
151*4882a593Smuzhiyun 	int (*init)(struct hdac_ext_device *dev);
152*4882a593Smuzhiyun 	void (*free)(struct hdac_ext_device *dev);
153*4882a593Smuzhiyun };
154*4882a593Smuzhiyun 
155*4882a593Smuzhiyun struct hda_dai_map {
156*4882a593Smuzhiyun 	char *dai_name;
157*4882a593Smuzhiyun 	hda_nid_t nid;
158*4882a593Smuzhiyun 	u32	maxbps;
159*4882a593Smuzhiyun };
160*4882a593Smuzhiyun 
161*4882a593Smuzhiyun struct hdac_ext_dma_params {
162*4882a593Smuzhiyun 	u32 format;
163*4882a593Smuzhiyun 	u8 stream_tag;
164*4882a593Smuzhiyun };
165*4882a593Smuzhiyun 
166*4882a593Smuzhiyun int snd_hda_ext_driver_register(struct hdac_driver *drv);
167*4882a593Smuzhiyun void snd_hda_ext_driver_unregister(struct hdac_driver *drv);
168*4882a593Smuzhiyun 
169*4882a593Smuzhiyun #endif /* __SOUND_HDAUDIO_EXT_H */
170