blob: 07fa59237feb032e3e6dcb6660cca6d17b5679e4 [file] [log] [blame]
Jeeja KPdfe66a12015-06-11 14:11:47 +05301#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
Jeeja KPa9c48f72015-12-18 15:11:59 +053015 * @drsmcap: dma resume capabilities pointer
Jeeja KPdfe66a12015-06-11 14:11:47 +053016 * @hlink_list: link list of HDA links
17 */
18struct hdac_ext_bus {
19 struct hdac_bus bus;
20 int num_streams;
21 int idx;
22
23 void __iomem *ppcap;
24 void __iomem *spbcap;
25 void __iomem *mlcap;
26 void __iomem *gtscap;
Jeeja KPa9c48f72015-12-18 15:11:59 +053027 void __iomem *drsmcap;
Jeeja KPdfe66a12015-06-11 14:11:47 +053028
29 struct list_head hlink_list;
30};
31
32int snd_hdac_ext_bus_init(struct hdac_ext_bus *sbus, struct device *dev,
33 const struct hdac_bus_ops *ops,
34 const struct hdac_io_ops *io_ops);
35
36void snd_hdac_ext_bus_exit(struct hdac_ext_bus *sbus);
37int snd_hdac_ext_bus_device_init(struct hdac_ext_bus *sbus, int addr);
38void snd_hdac_ext_bus_device_exit(struct hdac_device *hdev);
Vinod Koulee2d51b2015-08-21 15:47:40 +053039void snd_hdac_ext_bus_device_remove(struct hdac_ext_bus *ebus);
Jeeja KPdfe66a12015-06-11 14:11:47 +053040
41#define ebus_to_hbus(ebus) (&(ebus)->bus)
42#define hbus_to_ebus(_bus) \
43 container_of(_bus, struct hdac_ext_bus, bus)
44
Subhransu S. Prustyb6e84c92015-10-19 16:58:46 +053045#define HDA_CODEC_REV_EXT_ENTRY(_vid, _rev, _name, drv_data) \
46 { .vendor_id = (_vid), .rev_id = (_rev), .name = (_name), \
47 .api_version = HDA_DEV_ASOC, \
48 .driver_data = (unsigned long)(drv_data) }
49#define HDA_CODEC_EXT_ENTRY(_vid, _revid, _name, _drv_data) \
50 HDA_CODEC_REV_EXT_ENTRY(_vid, _revid, _name, _drv_data)
51
Jeeja KPdfe66a12015-06-11 14:11:47 +053052int snd_hdac_ext_bus_parse_capabilities(struct hdac_ext_bus *sbus);
53void snd_hdac_ext_bus_ppcap_enable(struct hdac_ext_bus *chip, bool enable);
54void snd_hdac_ext_bus_ppcap_int_enable(struct hdac_ext_bus *chip, bool enable);
55
Jeeja KP0b00a562015-06-11 14:11:48 +053056void snd_hdac_ext_stream_spbcap_enable(struct hdac_ext_bus *chip,
57 bool enable, int index);
58
59int snd_hdac_ext_bus_get_ml_capabilities(struct hdac_ext_bus *bus);
Jeeja KP0b00a562015-06-11 14:11:48 +053060struct hdac_ext_link *snd_hdac_ext_bus_get_link(struct hdac_ext_bus *bus,
61 const char *codec_name);
62
63enum hdac_ext_stream_type {
64 HDAC_EXT_STREAM_TYPE_COUPLED = 0,
65 HDAC_EXT_STREAM_TYPE_HOST,
66 HDAC_EXT_STREAM_TYPE_LINK
67};
68
Jeeja KPdf203a42015-06-11 14:11:49 +053069/**
70 * hdac_ext_stream: HDAC extended stream for extended HDA caps
71 *
72 * @hstream: hdac_stream
73 * @pphc_addr: processing pipe host stream pointer
74 * @pplc_addr: processing pipe link stream pointer
Jeeja KPee8bc4d2015-08-21 21:36:20 +053075 * @spib_addr: software position in buffers stream pointer
76 * @fifo_addr: software position Max fifos stream pointer
Jeeja KPa9c48f72015-12-18 15:11:59 +053077 * @dpibr_addr: DMA position in buffer resume pointer
78 * @dpib: DMA position in buffer
79 * @lpib: Linear position in buffer
Jeeja KPdf203a42015-06-11 14:11:49 +053080 * @decoupled: stream host and link is decoupled
81 * @link_locked: link is locked
82 * @link_prepared: link is prepared
83 * link_substream: link substream
84 */
85struct hdac_ext_stream {
86 struct hdac_stream hstream;
87
88 void __iomem *pphc_addr;
89 void __iomem *pplc_addr;
90
Jeeja KPee8bc4d2015-08-21 21:36:20 +053091 void __iomem *spib_addr;
92 void __iomem *fifo_addr;
93
Jeeja KPa9c48f72015-12-18 15:11:59 +053094 void __iomem *dpibr_addr;
95
96 u32 dpib;
97 u32 lpib;
Jeeja KPdf203a42015-06-11 14:11:49 +053098 bool decoupled:1;
99 bool link_locked:1;
100 bool link_prepared;
101
102 struct snd_pcm_substream *link_substream;
103};
104
105#define hdac_stream(s) (&(s)->hstream)
106#define stream_to_hdac_ext_stream(s) \
107 container_of(s, struct hdac_ext_stream, hstream)
108
109void snd_hdac_ext_stream_init(struct hdac_ext_bus *bus,
110 struct hdac_ext_stream *stream, int idx,
111 int direction, int tag);
Vinod Koule7a34842015-06-17 11:20:16 +0530112int snd_hdac_ext_stream_init_all(struct hdac_ext_bus *ebus, int start_idx,
113 int num_stream, int dir);
114void snd_hdac_stream_free_all(struct hdac_ext_bus *ebus);
Vinod Koulbab44452015-06-17 11:20:17 +0530115void snd_hdac_link_free_all(struct hdac_ext_bus *ebus);
Jeeja KPdf203a42015-06-11 14:11:49 +0530116struct hdac_ext_stream *snd_hdac_ext_stream_assign(struct hdac_ext_bus *bus,
117 struct snd_pcm_substream *substream,
118 int type);
119void snd_hdac_ext_stream_release(struct hdac_ext_stream *azx_dev, int type);
120void snd_hdac_ext_stream_decouple(struct hdac_ext_bus *bus,
121 struct hdac_ext_stream *azx_dev, bool decouple);
122void snd_hdac_ext_stop_streams(struct hdac_ext_bus *sbus);
123
Jeeja KPee8bc4d2015-08-21 21:36:20 +0530124int snd_hdac_ext_stream_set_spib(struct hdac_ext_bus *ebus,
125 struct hdac_ext_stream *stream, u32 value);
Vinod Koul54d1d2f2015-08-23 11:52:50 +0530126int snd_hdac_ext_stream_get_spbmaxfifo(struct hdac_ext_bus *ebus,
Jeeja KPee8bc4d2015-08-21 21:36:20 +0530127 struct hdac_ext_stream *stream);
Jeeja KPa9c48f72015-12-18 15:11:59 +0530128void snd_hdac_ext_stream_drsm_enable(struct hdac_ext_bus *ebus,
129 bool enable, int index);
130int snd_hdac_ext_stream_set_dpibr(struct hdac_ext_bus *ebus,
131 struct hdac_ext_stream *stream, u32 value);
132int snd_hdac_ext_stream_set_lpib(struct hdac_ext_stream *stream, u32 value);
Jeeja KPee8bc4d2015-08-21 21:36:20 +0530133
Jeeja KPdf203a42015-06-11 14:11:49 +0530134void snd_hdac_ext_link_stream_start(struct hdac_ext_stream *hstream);
135void snd_hdac_ext_link_stream_clear(struct hdac_ext_stream *hstream);
136void snd_hdac_ext_link_stream_reset(struct hdac_ext_stream *hstream);
137int snd_hdac_ext_link_stream_setup(struct hdac_ext_stream *stream, int fmt);
138
Jeeja KP0b00a562015-06-11 14:11:48 +0530139struct hdac_ext_link {
140 struct hdac_bus *bus;
141 int index;
142 void __iomem *ml_addr; /* link output stream reg pointer */
143 u32 lcaps; /* link capablities */
144 u16 lsdiid; /* link sdi identifier */
145 struct list_head list;
146};
147
148int snd_hdac_ext_bus_link_power_up(struct hdac_ext_link *link);
149int snd_hdac_ext_bus_link_power_down(struct hdac_ext_link *link);
Vinod Koul6706a192015-12-18 15:12:02 +0530150int snd_hdac_ext_bus_link_power_up_all(struct hdac_ext_bus *ebus);
Jeeja KPc5b0c092015-08-21 21:36:18 +0530151int snd_hdac_ext_bus_link_power_down_all(struct hdac_ext_bus *ebus);
Jeeja KP0b00a562015-06-11 14:11:48 +0530152void snd_hdac_ext_link_set_stream_id(struct hdac_ext_link *link,
153 int stream);
154void snd_hdac_ext_link_clear_stream_id(struct hdac_ext_link *link,
155 int stream);
156
157/* update register macro */
158#define snd_hdac_updatel(addr, reg, mask, val) \
159 writel(((readl(addr + reg) & ~(mask)) | (val)), \
160 addr + reg)
161
Jeeja KPdf203a42015-06-11 14:11:49 +0530162#define snd_hdac_updatew(addr, reg, mask, val) \
163 writew(((readw(addr + reg) & ~(mask)) | (val)), \
164 addr + reg)
165
Vinod Koula512f562015-08-21 15:47:41 +0530166
167struct hdac_ext_device;
168
169/* ops common to all codec drivers */
170struct hdac_ext_codec_ops {
171 int (*build_controls)(struct hdac_ext_device *dev);
172 int (*init)(struct hdac_ext_device *dev);
173 void (*free)(struct hdac_ext_device *dev);
174};
175
176struct hda_dai_map {
177 char *dai_name;
178 hda_nid_t nid;
179 u32 maxbps;
180};
181
182#define HDA_MAX_NIDS 16
183
184/**
185 * struct hdac_ext_device - HDAC Ext device
186 *
187 * @hdac: hdac core device
188 * @nid_list - the dai map which matches the dai-name with the nid
189 * @map_cur_idx - the idx in use in dai_map
190 * @ops - the hda codec ops common to all codec drivers
191 * @pvt_data - private data, for asoc contains asoc codec object
192 */
193struct hdac_ext_device {
194 struct hdac_device hdac;
195 struct hdac_ext_bus *ebus;
196
197 /* soc-dai to nid map */
198 struct hda_dai_map nid_list[HDA_MAX_NIDS];
199 unsigned int map_cur_idx;
200
201 /* codec ops */
202 struct hdac_ext_codec_ops ops;
203
Subhransu S. Prusty1e83b042015-11-10 18:42:05 +0530204 struct snd_card *card;
205 void *scodec;
Vinod Koula512f562015-08-21 15:47:41 +0530206 void *private_data;
207};
208
Subhransu S. Prusty1e83b042015-11-10 18:42:05 +0530209struct hdac_ext_dma_params {
210 u32 format;
211 u8 stream_tag;
212};
Vinod Koula512f562015-08-21 15:47:41 +0530213#define to_ehdac_device(dev) (container_of((dev), \
214 struct hdac_ext_device, hdac))
Vinod Kould51783c2015-08-21 15:47:42 +0530215/*
216 * HD-audio codec base driver
217 */
218struct hdac_ext_driver {
219 struct hdac_driver hdac;
220
221 int (*probe)(struct hdac_ext_device *dev);
222 int (*remove)(struct hdac_ext_device *dev);
223 void (*shutdown)(struct hdac_ext_device *dev);
224};
225
226int snd_hda_ext_driver_register(struct hdac_ext_driver *drv);
227void snd_hda_ext_driver_unregister(struct hdac_ext_driver *drv);
228
229#define to_ehdac_driver(_drv) container_of(_drv, struct hdac_ext_driver, hdac)
Vinod Koula512f562015-08-21 15:47:41 +0530230
Jeeja KPdfe66a12015-06-11 14:11:47 +0530231#endif /* __SOUND_HDAUDIO_EXT_H */