Loading...
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef __SOUND_HDAUDIO_EXT_H
3#define __SOUND_HDAUDIO_EXT_H
4
5#include <sound/hdaudio.h>
6
7int snd_hdac_ext_bus_init(struct hdac_bus *bus, struct device *dev,
8 const struct hdac_bus_ops *ops,
9 const struct hdac_ext_bus_ops *ext_ops);
10
11void snd_hdac_ext_bus_exit(struct hdac_bus *bus);
12void snd_hdac_ext_bus_device_remove(struct hdac_bus *bus);
13
14#define HDA_CODEC_REV_EXT_ENTRY(_vid, _rev, _name, drv_data) \
15 { .vendor_id = (_vid), .rev_id = (_rev), .name = (_name), \
16 .api_version = HDA_DEV_ASOC, \
17 .driver_data = (unsigned long)(drv_data) }
18#define HDA_CODEC_EXT_ENTRY(_vid, _revid, _name, _drv_data) \
19 HDA_CODEC_REV_EXT_ENTRY(_vid, _revid, _name, _drv_data)
20
21void snd_hdac_ext_bus_ppcap_enable(struct hdac_bus *chip, bool enable);
22void snd_hdac_ext_bus_ppcap_int_enable(struct hdac_bus *chip, bool enable);
23
24int snd_hdac_ext_bus_get_ml_capabilities(struct hdac_bus *bus);
25struct hdac_ext_link *snd_hdac_ext_bus_get_hlink_by_addr(struct hdac_bus *bus, int addr);
26struct hdac_ext_link *snd_hdac_ext_bus_get_hlink_by_name(struct hdac_bus *bus,
27 const char *codec_name);
28
29enum hdac_ext_stream_type {
30 HDAC_EXT_STREAM_TYPE_COUPLED = 0,
31 HDAC_EXT_STREAM_TYPE_HOST,
32 HDAC_EXT_STREAM_TYPE_LINK
33};
34
35/**
36 * hdac_ext_stream: HDAC extended stream for extended HDA caps
37 *
38 * @hstream: hdac_stream
39 * @pphc_addr: processing pipe host stream pointer
40 * @pplc_addr: processing pipe link stream pointer
41 * @decoupled: stream host and link is decoupled
42 * @link_locked: link is locked
43 * @link_prepared: link is prepared
44 * @link_substream: link substream
45 */
46struct hdac_ext_stream {
47 struct hdac_stream hstream;
48
49 void __iomem *pphc_addr;
50 void __iomem *pplc_addr;
51
52 u32 pphcllpl;
53 u32 pphcllpu;
54 u32 pphcldpl;
55 u32 pphcldpu;
56
57 u32 pplcllpl;
58 u32 pplcllpu;
59
60 bool decoupled:1;
61 bool link_locked:1;
62 bool link_prepared;
63
64 int (*host_setup)(struct hdac_stream *, bool);
65
66 struct snd_pcm_substream *link_substream;
67};
68
69#define hdac_stream(s) (&(s)->hstream)
70#define stream_to_hdac_ext_stream(s) \
71 container_of(s, struct hdac_ext_stream, hstream)
72
73int snd_hdac_ext_stream_init_all(struct hdac_bus *bus, int start_idx,
74 int num_stream, int dir);
75void snd_hdac_ext_stream_free_all(struct hdac_bus *bus);
76void snd_hdac_ext_link_free_all(struct hdac_bus *bus);
77struct hdac_ext_stream *snd_hdac_ext_stream_assign(struct hdac_bus *bus,
78 struct snd_pcm_substream *substream,
79 int type);
80void snd_hdac_ext_stream_release(struct hdac_ext_stream *hext_stream, int type);
81struct hdac_ext_stream *snd_hdac_ext_cstream_assign(struct hdac_bus *bus,
82 struct snd_compr_stream *cstream);
83void snd_hdac_ext_stream_decouple_locked(struct hdac_bus *bus,
84 struct hdac_ext_stream *hext_stream, bool decouple);
85void snd_hdac_ext_stream_decouple(struct hdac_bus *bus,
86 struct hdac_ext_stream *azx_dev, bool decouple);
87
88void snd_hdac_ext_stream_start(struct hdac_ext_stream *hext_stream);
89void snd_hdac_ext_stream_clear(struct hdac_ext_stream *hext_stream);
90void snd_hdac_ext_stream_reset(struct hdac_ext_stream *hext_stream);
91int snd_hdac_ext_stream_setup(struct hdac_ext_stream *hext_stream, int fmt);
92int snd_hdac_ext_host_stream_setup(struct hdac_ext_stream *hext_stream, bool code_loading);
93
94struct hdac_ext_link {
95 struct hdac_bus *bus;
96 int index;
97 void __iomem *ml_addr; /* link output stream reg pointer */
98 u32 lcaps; /* link capablities */
99 u16 lsdiid; /* link sdi identifier */
100
101 int ref_count;
102
103 struct list_head list;
104};
105
106int snd_hdac_ext_bus_link_power_up(struct hdac_ext_link *hlink);
107int snd_hdac_ext_bus_link_power_down(struct hdac_ext_link *hlink);
108int snd_hdac_ext_bus_link_power_up_all(struct hdac_bus *bus);
109int snd_hdac_ext_bus_link_power_down_all(struct hdac_bus *bus);
110void snd_hdac_ext_bus_link_set_stream_id(struct hdac_ext_link *hlink,
111 int stream);
112void snd_hdac_ext_bus_link_clear_stream_id(struct hdac_ext_link *hlink,
113 int stream);
114
115int snd_hdac_ext_bus_link_get(struct hdac_bus *bus, struct hdac_ext_link *hlink);
116int snd_hdac_ext_bus_link_put(struct hdac_bus *bus, struct hdac_ext_link *hlink);
117
118void snd_hdac_ext_bus_link_power(struct hdac_device *codec, bool enable);
119
120struct hdac_ext_device;
121
122/* ops common to all codec drivers */
123struct hdac_ext_codec_ops {
124 int (*build_controls)(struct hdac_ext_device *dev);
125 int (*init)(struct hdac_ext_device *dev);
126 void (*free)(struct hdac_ext_device *dev);
127};
128
129struct hda_dai_map {
130 char *dai_name;
131 hda_nid_t nid;
132 u32 maxbps;
133};
134
135struct hdac_ext_dma_params {
136 u32 format;
137 u8 stream_tag;
138};
139
140int snd_hda_ext_driver_register(struct hdac_driver *drv);
141void snd_hda_ext_driver_unregister(struct hdac_driver *drv);
142
143#endif /* __SOUND_HDAUDIO_EXT_H */
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef __SOUND_HDAUDIO_EXT_H
3#define __SOUND_HDAUDIO_EXT_H
4
5#include <sound/hdaudio.h>
6
7/**
8 * hdac_ext_bus: HDAC extended bus for extended HDA caps
9 *
10 * @bus: hdac bus
11 * @num_streams: streams supported
12 * @hlink_list: link list of HDA links
13 * @lock: lock for link mgmt
14 * @cmd_dma_state: state of cmd DMAs: CORB and RIRB
15 */
16struct hdac_ext_bus {
17 struct hdac_bus bus;
18 int num_streams;
19 int idx;
20
21 struct list_head hlink_list;
22
23 struct mutex lock;
24 bool cmd_dma_state;
25};
26
27int snd_hdac_ext_bus_init(struct hdac_ext_bus *sbus, struct device *dev,
28 const struct hdac_bus_ops *ops,
29 const struct hdac_io_ops *io_ops);
30
31void snd_hdac_ext_bus_exit(struct hdac_ext_bus *sbus);
32int snd_hdac_ext_bus_device_init(struct hdac_ext_bus *sbus, int addr);
33void snd_hdac_ext_bus_device_exit(struct hdac_device *hdev);
34void snd_hdac_ext_bus_device_remove(struct hdac_ext_bus *ebus);
35
36#define ebus_to_hbus(ebus) (&(ebus)->bus)
37#define hbus_to_ebus(_bus) \
38 container_of(_bus, struct hdac_ext_bus, bus)
39
40#define HDA_CODEC_REV_EXT_ENTRY(_vid, _rev, _name, drv_data) \
41 { .vendor_id = (_vid), .rev_id = (_rev), .name = (_name), \
42 .api_version = HDA_DEV_ASOC, \
43 .driver_data = (unsigned long)(drv_data) }
44#define HDA_CODEC_EXT_ENTRY(_vid, _revid, _name, _drv_data) \
45 HDA_CODEC_REV_EXT_ENTRY(_vid, _revid, _name, _drv_data)
46
47void snd_hdac_ext_bus_ppcap_enable(struct hdac_ext_bus *chip, bool enable);
48void snd_hdac_ext_bus_ppcap_int_enable(struct hdac_ext_bus *chip, bool enable);
49
50void snd_hdac_ext_stream_spbcap_enable(struct hdac_ext_bus *chip,
51 bool enable, int index);
52
53int snd_hdac_ext_bus_get_ml_capabilities(struct hdac_ext_bus *bus);
54struct hdac_ext_link *snd_hdac_ext_bus_get_link(struct hdac_ext_bus *bus,
55 const char *codec_name);
56
57enum hdac_ext_stream_type {
58 HDAC_EXT_STREAM_TYPE_COUPLED = 0,
59 HDAC_EXT_STREAM_TYPE_HOST,
60 HDAC_EXT_STREAM_TYPE_LINK
61};
62
63/**
64 * hdac_ext_stream: HDAC extended stream for extended HDA caps
65 *
66 * @hstream: hdac_stream
67 * @pphc_addr: processing pipe host stream pointer
68 * @pplc_addr: processing pipe link stream pointer
69 * @spib_addr: software position in buffers stream pointer
70 * @fifo_addr: software position Max fifos stream pointer
71 * @dpibr_addr: DMA position in buffer resume pointer
72 * @dpib: DMA position in buffer
73 * @lpib: Linear position in buffer
74 * @decoupled: stream host and link is decoupled
75 * @link_locked: link is locked
76 * @link_prepared: link is prepared
77 * link_substream: link substream
78 */
79struct hdac_ext_stream {
80 struct hdac_stream hstream;
81
82 void __iomem *pphc_addr;
83 void __iomem *pplc_addr;
84
85 void __iomem *spib_addr;
86 void __iomem *fifo_addr;
87
88 void __iomem *dpibr_addr;
89
90 u32 dpib;
91 u32 lpib;
92 bool decoupled:1;
93 bool link_locked:1;
94 bool link_prepared;
95
96 struct snd_pcm_substream *link_substream;
97};
98
99#define hdac_stream(s) (&(s)->hstream)
100#define stream_to_hdac_ext_stream(s) \
101 container_of(s, struct hdac_ext_stream, hstream)
102
103void snd_hdac_ext_stream_init(struct hdac_ext_bus *bus,
104 struct hdac_ext_stream *stream, int idx,
105 int direction, int tag);
106int snd_hdac_ext_stream_init_all(struct hdac_ext_bus *ebus, int start_idx,
107 int num_stream, int dir);
108void snd_hdac_stream_free_all(struct hdac_ext_bus *ebus);
109void snd_hdac_link_free_all(struct hdac_ext_bus *ebus);
110struct hdac_ext_stream *snd_hdac_ext_stream_assign(struct hdac_ext_bus *bus,
111 struct snd_pcm_substream *substream,
112 int type);
113void snd_hdac_ext_stream_release(struct hdac_ext_stream *azx_dev, int type);
114void snd_hdac_ext_stream_decouple(struct hdac_ext_bus *bus,
115 struct hdac_ext_stream *azx_dev, bool decouple);
116void snd_hdac_ext_stop_streams(struct hdac_ext_bus *sbus);
117
118int snd_hdac_ext_stream_set_spib(struct hdac_ext_bus *ebus,
119 struct hdac_ext_stream *stream, u32 value);
120int snd_hdac_ext_stream_get_spbmaxfifo(struct hdac_ext_bus *ebus,
121 struct hdac_ext_stream *stream);
122void snd_hdac_ext_stream_drsm_enable(struct hdac_ext_bus *ebus,
123 bool enable, int index);
124int snd_hdac_ext_stream_set_dpibr(struct hdac_ext_bus *ebus,
125 struct hdac_ext_stream *stream, u32 value);
126int snd_hdac_ext_stream_set_lpib(struct hdac_ext_stream *stream, u32 value);
127
128void snd_hdac_ext_link_stream_start(struct hdac_ext_stream *hstream);
129void snd_hdac_ext_link_stream_clear(struct hdac_ext_stream *hstream);
130void snd_hdac_ext_link_stream_reset(struct hdac_ext_stream *hstream);
131int snd_hdac_ext_link_stream_setup(struct hdac_ext_stream *stream, int fmt);
132
133struct hdac_ext_link {
134 struct hdac_bus *bus;
135 int index;
136 void __iomem *ml_addr; /* link output stream reg pointer */
137 u32 lcaps; /* link capablities */
138 u16 lsdiid; /* link sdi identifier */
139
140 int ref_count;
141
142 struct list_head list;
143};
144
145int snd_hdac_ext_bus_link_power_up(struct hdac_ext_link *link);
146int snd_hdac_ext_bus_link_power_down(struct hdac_ext_link *link);
147int snd_hdac_ext_bus_link_power_up_all(struct hdac_ext_bus *ebus);
148int snd_hdac_ext_bus_link_power_down_all(struct hdac_ext_bus *ebus);
149void snd_hdac_ext_link_set_stream_id(struct hdac_ext_link *link,
150 int stream);
151void snd_hdac_ext_link_clear_stream_id(struct hdac_ext_link *link,
152 int stream);
153
154int snd_hdac_ext_bus_link_get(struct hdac_ext_bus *ebus,
155 struct hdac_ext_link *link);
156int snd_hdac_ext_bus_link_put(struct hdac_ext_bus *ebus,
157 struct hdac_ext_link *link);
158
159/* update register macro */
160#define snd_hdac_updatel(addr, reg, mask, val) \
161 writel(((readl(addr + reg) & ~(mask)) | (val)), \
162 addr + reg)
163
164#define snd_hdac_updatew(addr, reg, mask, val) \
165 writew(((readw(addr + reg) & ~(mask)) | (val)), \
166 addr + reg)
167
168
169struct hdac_ext_device;
170
171/* ops common to all codec drivers */
172struct hdac_ext_codec_ops {
173 int (*build_controls)(struct hdac_ext_device *dev);
174 int (*init)(struct hdac_ext_device *dev);
175 void (*free)(struct hdac_ext_device *dev);
176};
177
178struct hda_dai_map {
179 char *dai_name;
180 hda_nid_t nid;
181 u32 maxbps;
182};
183
184#define HDA_MAX_NIDS 16
185
186/**
187 * struct hdac_ext_device - HDAC Ext device
188 *
189 * @hdac: hdac core device
190 * @nid_list - the dai map which matches the dai-name with the nid
191 * @map_cur_idx - the idx in use in dai_map
192 * @ops - the hda codec ops common to all codec drivers
193 * @pvt_data - private data, for asoc contains asoc codec object
194 */
195struct hdac_ext_device {
196 struct hdac_device hdev;
197 struct hdac_ext_bus *ebus;
198
199 /* soc-dai to nid map */
200 struct hda_dai_map nid_list[HDA_MAX_NIDS];
201 unsigned int map_cur_idx;
202
203 /* codec ops */
204 struct hdac_ext_codec_ops ops;
205
206 struct snd_card *card;
207 void *scodec;
208 void *private_data;
209};
210
211struct hdac_ext_dma_params {
212 u32 format;
213 u8 stream_tag;
214};
215#define to_ehdac_device(dev) (container_of((dev), \
216 struct hdac_ext_device, hdev))
217/*
218 * HD-audio codec base driver
219 */
220struct hdac_ext_driver {
221 struct hdac_driver hdac;
222
223 int (*probe)(struct hdac_ext_device *dev);
224 int (*remove)(struct hdac_ext_device *dev);
225 void (*shutdown)(struct hdac_ext_device *dev);
226};
227
228int snd_hda_ext_driver_register(struct hdac_ext_driver *drv);
229void snd_hda_ext_driver_unregister(struct hdac_ext_driver *drv);
230
231#define to_ehdac_driver(_drv) container_of(_drv, struct hdac_ext_driver, hdac)
232
233#endif /* __SOUND_HDAUDIO_EXT_H */