xref: /openbmc/linux/include/sound/hdaudio_ext.h (revision 552b8b36)
1 #ifndef __SOUND_HDAUDIO_EXT_H
2 #define __SOUND_HDAUDIO_EXT_H
3 
4 #include <sound/hdaudio.h>
5 
6 /**
7  * hdac_ext_bus: HDAC extended bus for extended HDA caps
8  *
9  * @bus: hdac bus
10  * @num_streams: streams supported
11  * @ppcap: pp capabilities pointer
12  * @spbcap: SPIB capabilities pointer
13  * @mlcap: MultiLink capabilities pointer
14  * @gtscap: gts capabilities pointer
15  * @hlink_list: link list of HDA links
16  */
17 struct hdac_ext_bus {
18 	struct hdac_bus bus;
19 	int num_streams;
20 	int idx;
21 
22 	void __iomem *ppcap;
23 	void __iomem *spbcap;
24 	void __iomem *mlcap;
25 	void __iomem *gtscap;
26 
27 	struct list_head hlink_list;
28 };
29 
30 int snd_hdac_ext_bus_init(struct hdac_ext_bus *sbus, struct device *dev,
31 		      const struct hdac_bus_ops *ops,
32 		      const struct hdac_io_ops *io_ops);
33 
34 void snd_hdac_ext_bus_exit(struct hdac_ext_bus *sbus);
35 int snd_hdac_ext_bus_device_init(struct hdac_ext_bus *sbus, int addr);
36 void snd_hdac_ext_bus_device_exit(struct hdac_device *hdev);
37 void snd_hdac_ext_bus_device_remove(struct hdac_ext_bus *ebus);
38 
39 #define ebus_to_hbus(ebus)	(&(ebus)->bus)
40 #define hbus_to_ebus(_bus) \
41 	container_of(_bus, struct hdac_ext_bus, bus)
42 
43 int snd_hdac_ext_bus_parse_capabilities(struct hdac_ext_bus *sbus);
44 void snd_hdac_ext_bus_ppcap_enable(struct hdac_ext_bus *chip, bool enable);
45 void snd_hdac_ext_bus_ppcap_int_enable(struct hdac_ext_bus *chip, bool enable);
46 
47 void snd_hdac_ext_stream_spbcap_enable(struct hdac_ext_bus *chip,
48 				 bool enable, int index);
49 
50 int snd_hdac_ext_bus_get_ml_capabilities(struct hdac_ext_bus *bus);
51 struct hdac_ext_link *snd_hdac_ext_bus_get_link(struct hdac_ext_bus *bus,
52 						const char *codec_name);
53 
54 enum hdac_ext_stream_type {
55 	HDAC_EXT_STREAM_TYPE_COUPLED = 0,
56 	HDAC_EXT_STREAM_TYPE_HOST,
57 	HDAC_EXT_STREAM_TYPE_LINK
58 };
59 
60 /**
61  * hdac_ext_stream: HDAC extended stream for extended HDA caps
62  *
63  * @hstream: hdac_stream
64  * @pphc_addr: processing pipe host stream pointer
65  * @pplc_addr: processing pipe link stream pointer
66  * @spib_addr: software position in buffers stream pointer
67  * @fifo_addr: software position Max fifos stream pointer
68  * @decoupled: stream host and link is decoupled
69  * @link_locked: link is locked
70  * @link_prepared: link is prepared
71  * link_substream: link substream
72  */
73 struct hdac_ext_stream {
74 	struct hdac_stream hstream;
75 
76 	void __iomem *pphc_addr;
77 	void __iomem *pplc_addr;
78 
79 	void __iomem *spib_addr;
80 	void __iomem *fifo_addr;
81 
82 	bool decoupled:1;
83 	bool link_locked:1;
84 	bool link_prepared;
85 
86 	struct snd_pcm_substream *link_substream;
87 };
88 
89 #define hdac_stream(s)		(&(s)->hstream)
90 #define stream_to_hdac_ext_stream(s) \
91 	container_of(s, struct hdac_ext_stream, hstream)
92 
93 void snd_hdac_ext_stream_init(struct hdac_ext_bus *bus,
94 				struct hdac_ext_stream *stream, int idx,
95 				int direction, int tag);
96 int snd_hdac_ext_stream_init_all(struct hdac_ext_bus *ebus, int start_idx,
97 		int num_stream, int dir);
98 void snd_hdac_stream_free_all(struct hdac_ext_bus *ebus);
99 void snd_hdac_link_free_all(struct hdac_ext_bus *ebus);
100 struct hdac_ext_stream *snd_hdac_ext_stream_assign(struct hdac_ext_bus *bus,
101 					   struct snd_pcm_substream *substream,
102 					   int type);
103 void snd_hdac_ext_stream_release(struct hdac_ext_stream *azx_dev, int type);
104 void snd_hdac_ext_stream_decouple(struct hdac_ext_bus *bus,
105 				struct hdac_ext_stream *azx_dev, bool decouple);
106 void snd_hdac_ext_stop_streams(struct hdac_ext_bus *sbus);
107 
108 int snd_hdac_ext_stream_set_spib(struct hdac_ext_bus *ebus,
109 				 struct hdac_ext_stream *stream, u32 value);
110 int snd_hdac_ext_stream_get_spbmaxfifo(struct hdac_ext_bus *ebus,
111 				 struct hdac_ext_stream *stream);
112 
113 void snd_hdac_ext_link_stream_start(struct hdac_ext_stream *hstream);
114 void snd_hdac_ext_link_stream_clear(struct hdac_ext_stream *hstream);
115 void snd_hdac_ext_link_stream_reset(struct hdac_ext_stream *hstream);
116 int snd_hdac_ext_link_stream_setup(struct hdac_ext_stream *stream, int fmt);
117 
118 struct hdac_ext_link {
119 	struct hdac_bus *bus;
120 	int index;
121 	void __iomem *ml_addr; /* link output stream reg pointer */
122 	u32 lcaps;   /* link capablities */
123 	u16 lsdiid;  /* link sdi identifier */
124 	struct list_head list;
125 };
126 
127 int snd_hdac_ext_bus_link_power_up(struct hdac_ext_link *link);
128 int snd_hdac_ext_bus_link_power_down(struct hdac_ext_link *link);
129 int snd_hdac_ext_bus_link_power_down_all(struct hdac_ext_bus *ebus);
130 void snd_hdac_ext_link_set_stream_id(struct hdac_ext_link *link,
131 				 int stream);
132 void snd_hdac_ext_link_clear_stream_id(struct hdac_ext_link *link,
133 				 int stream);
134 
135 /* update register macro */
136 #define snd_hdac_updatel(addr, reg, mask, val)		\
137 	writel(((readl(addr + reg) & ~(mask)) | (val)), \
138 		addr + reg)
139 
140 #define snd_hdac_updatew(addr, reg, mask, val)		\
141 	writew(((readw(addr + reg) & ~(mask)) | (val)), \
142 		addr + reg)
143 
144 
145 struct hdac_ext_device;
146 
147 /* ops common to all codec drivers */
148 struct hdac_ext_codec_ops {
149 	int (*build_controls)(struct hdac_ext_device *dev);
150 	int (*init)(struct hdac_ext_device *dev);
151 	void (*free)(struct hdac_ext_device *dev);
152 };
153 
154 struct hda_dai_map {
155 	char *dai_name;
156 	hda_nid_t nid;
157 	u32	maxbps;
158 };
159 
160 #define HDA_MAX_NIDS 16
161 
162 /**
163  * struct hdac_ext_device - HDAC Ext device
164  *
165  * @hdac: hdac core device
166  * @nid_list - the dai map which matches the dai-name with the nid
167  * @map_cur_idx - the idx in use in dai_map
168  * @ops - the hda codec ops common to all codec drivers
169  * @pvt_data - private data, for asoc contains asoc codec object
170  */
171 struct hdac_ext_device {
172 	struct hdac_device hdac;
173 	struct hdac_ext_bus *ebus;
174 
175 	/* soc-dai to nid map */
176 	struct hda_dai_map nid_list[HDA_MAX_NIDS];
177 	unsigned int map_cur_idx;
178 
179 	/* codec ops */
180 	struct hdac_ext_codec_ops ops;
181 
182 	void *private_data;
183 };
184 
185 #define to_ehdac_device(dev) (container_of((dev), \
186 				 struct hdac_ext_device, hdac))
187 /*
188  * HD-audio codec base driver
189  */
190 struct hdac_ext_driver {
191 	struct hdac_driver hdac;
192 
193 	int	(*probe)(struct hdac_ext_device *dev);
194 	int	(*remove)(struct hdac_ext_device *dev);
195 	void	(*shutdown)(struct hdac_ext_device *dev);
196 };
197 
198 int snd_hda_ext_driver_register(struct hdac_ext_driver *drv);
199 void snd_hda_ext_driver_unregister(struct hdac_ext_driver *drv);
200 
201 #define to_ehdac_driver(_drv) container_of(_drv, struct hdac_ext_driver, hdac)
202 
203 #endif /* __SOUND_HDAUDIO_EXT_H */
204