]> git.karo-electronics.de Git - karo-tx-linux.git/blob - include/sound/hdaudio_ext.h
ALSA: hdac: Add support for hda DMA Resume capability
[karo-tx-linux.git] / include / sound / hdaudio_ext.h
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  * @drsmcap: dma resume capabilities pointer
16  * @hlink_list: link list of HDA links
17  */
18 struct 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;
27         void __iomem *drsmcap;
28
29         struct list_head hlink_list;
30 };
31
32 int 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
36 void snd_hdac_ext_bus_exit(struct hdac_ext_bus *sbus);
37 int snd_hdac_ext_bus_device_init(struct hdac_ext_bus *sbus, int addr);
38 void snd_hdac_ext_bus_device_exit(struct hdac_device *hdev);
39 void snd_hdac_ext_bus_device_remove(struct hdac_ext_bus *ebus);
40
41 #define ebus_to_hbus(ebus)      (&(ebus)->bus)
42 #define hbus_to_ebus(_bus) \
43         container_of(_bus, struct hdac_ext_bus, bus)
44
45 #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
52 int snd_hdac_ext_bus_parse_capabilities(struct hdac_ext_bus *sbus);
53 void snd_hdac_ext_bus_ppcap_enable(struct hdac_ext_bus *chip, bool enable);
54 void snd_hdac_ext_bus_ppcap_int_enable(struct hdac_ext_bus *chip, bool enable);
55
56 void snd_hdac_ext_stream_spbcap_enable(struct hdac_ext_bus *chip,
57                                  bool enable, int index);
58
59 int snd_hdac_ext_bus_get_ml_capabilities(struct hdac_ext_bus *bus);
60 struct hdac_ext_link *snd_hdac_ext_bus_get_link(struct hdac_ext_bus *bus,
61                                                 const char *codec_name);
62
63 enum 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
69 /**
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
75  * @spib_addr: software position in buffers stream pointer
76  * @fifo_addr: software position Max fifos stream pointer
77  * @dpibr_addr: DMA position in buffer resume pointer
78  * @dpib: DMA position in buffer
79  * @lpib: Linear position in buffer
80  * @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  */
85 struct hdac_ext_stream {
86         struct hdac_stream hstream;
87
88         void __iomem *pphc_addr;
89         void __iomem *pplc_addr;
90
91         void __iomem *spib_addr;
92         void __iomem *fifo_addr;
93
94         void __iomem *dpibr_addr;
95
96         u32 dpib;
97         u32 lpib;
98         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
109 void snd_hdac_ext_stream_init(struct hdac_ext_bus *bus,
110                                 struct hdac_ext_stream *stream, int idx,
111                                 int direction, int tag);
112 int snd_hdac_ext_stream_init_all(struct hdac_ext_bus *ebus, int start_idx,
113                 int num_stream, int dir);
114 void snd_hdac_stream_free_all(struct hdac_ext_bus *ebus);
115 void snd_hdac_link_free_all(struct hdac_ext_bus *ebus);
116 struct hdac_ext_stream *snd_hdac_ext_stream_assign(struct hdac_ext_bus *bus,
117                                            struct snd_pcm_substream *substream,
118                                            int type);
119 void snd_hdac_ext_stream_release(struct hdac_ext_stream *azx_dev, int type);
120 void snd_hdac_ext_stream_decouple(struct hdac_ext_bus *bus,
121                                 struct hdac_ext_stream *azx_dev, bool decouple);
122 void snd_hdac_ext_stop_streams(struct hdac_ext_bus *sbus);
123
124 int snd_hdac_ext_stream_set_spib(struct hdac_ext_bus *ebus,
125                                  struct hdac_ext_stream *stream, u32 value);
126 int snd_hdac_ext_stream_get_spbmaxfifo(struct hdac_ext_bus *ebus,
127                                  struct hdac_ext_stream *stream);
128 void snd_hdac_ext_stream_drsm_enable(struct hdac_ext_bus *ebus,
129                                 bool enable, int index);
130 int snd_hdac_ext_stream_set_dpibr(struct hdac_ext_bus *ebus,
131                                 struct hdac_ext_stream *stream, u32 value);
132 int snd_hdac_ext_stream_set_lpib(struct hdac_ext_stream *stream, u32 value);
133
134 void snd_hdac_ext_link_stream_start(struct hdac_ext_stream *hstream);
135 void snd_hdac_ext_link_stream_clear(struct hdac_ext_stream *hstream);
136 void snd_hdac_ext_link_stream_reset(struct hdac_ext_stream *hstream);
137 int snd_hdac_ext_link_stream_setup(struct hdac_ext_stream *stream, int fmt);
138
139 struct 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
148 int snd_hdac_ext_bus_link_power_up(struct hdac_ext_link *link);
149 int snd_hdac_ext_bus_link_power_down(struct hdac_ext_link *link);
150 int snd_hdac_ext_bus_link_power_down_all(struct hdac_ext_bus *ebus);
151 void snd_hdac_ext_link_set_stream_id(struct hdac_ext_link *link,
152                                  int stream);
153 void snd_hdac_ext_link_clear_stream_id(struct hdac_ext_link *link,
154                                  int stream);
155
156 /* update register macro */
157 #define snd_hdac_updatel(addr, reg, mask, val)          \
158         writel(((readl(addr + reg) & ~(mask)) | (val)), \
159                 addr + reg)
160
161 #define snd_hdac_updatew(addr, reg, mask, val)          \
162         writew(((readw(addr + reg) & ~(mask)) | (val)), \
163                 addr + reg)
164
165
166 struct hdac_ext_device;
167
168 /* ops common to all codec drivers */
169 struct hdac_ext_codec_ops {
170         int (*build_controls)(struct hdac_ext_device *dev);
171         int (*init)(struct hdac_ext_device *dev);
172         void (*free)(struct hdac_ext_device *dev);
173 };
174
175 struct hda_dai_map {
176         char *dai_name;
177         hda_nid_t nid;
178         u32     maxbps;
179 };
180
181 #define HDA_MAX_NIDS 16
182
183 /**
184  * struct hdac_ext_device - HDAC Ext device
185  *
186  * @hdac: hdac core device
187  * @nid_list - the dai map which matches the dai-name with the nid
188  * @map_cur_idx - the idx in use in dai_map
189  * @ops - the hda codec ops common to all codec drivers
190  * @pvt_data - private data, for asoc contains asoc codec object
191  */
192 struct hdac_ext_device {
193         struct hdac_device hdac;
194         struct hdac_ext_bus *ebus;
195
196         /* soc-dai to nid map */
197         struct hda_dai_map nid_list[HDA_MAX_NIDS];
198         unsigned int map_cur_idx;
199
200         /* codec ops */
201         struct hdac_ext_codec_ops ops;
202
203         struct snd_card *card;
204         void *scodec;
205         void *private_data;
206 };
207
208 struct hdac_ext_dma_params {
209         u32 format;
210         u8 stream_tag;
211 };
212 #define to_ehdac_device(dev) (container_of((dev), \
213                                  struct hdac_ext_device, hdac))
214 /*
215  * HD-audio codec base driver
216  */
217 struct hdac_ext_driver {
218         struct hdac_driver hdac;
219
220         int     (*probe)(struct hdac_ext_device *dev);
221         int     (*remove)(struct hdac_ext_device *dev);
222         void    (*shutdown)(struct hdac_ext_device *dev);
223 };
224
225 int snd_hda_ext_driver_register(struct hdac_ext_driver *drv);
226 void snd_hda_ext_driver_unregister(struct hdac_ext_driver *drv);
227
228 #define to_ehdac_driver(_drv) container_of(_drv, struct hdac_ext_driver, hdac)
229
230 #endif /* __SOUND_HDAUDIO_EXT_H */