1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __SOUND_HDAUDIO_EXT_H
3 #define __SOUND_HDAUDIO_EXT_H
5 #include <linux/io-64-nonatomic-lo-hi.h>
6 #include <linux/iopoll.h>
7 #include <sound/hdaudio.h>
9 int snd_hdac_ext_bus_init(struct hdac_bus *bus, struct device *dev,
10 const struct hdac_bus_ops *ops,
11 const struct hdac_ext_bus_ops *ext_ops);
13 void snd_hdac_ext_bus_exit(struct hdac_bus *bus);
14 void snd_hdac_ext_bus_device_remove(struct hdac_bus *bus);
16 #define HDA_CODEC_REV_EXT_ENTRY(_vid, _rev, _name, drv_data) \
17 { .vendor_id = (_vid), .rev_id = (_rev), .name = (_name), \
18 .api_version = HDA_DEV_ASOC, \
19 .driver_data = (unsigned long)(drv_data) }
20 #define HDA_CODEC_EXT_ENTRY(_vid, _revid, _name, _drv_data) \
21 HDA_CODEC_REV_EXT_ENTRY(_vid, _revid, _name, _drv_data)
23 void snd_hdac_ext_bus_ppcap_enable(struct hdac_bus *chip, bool enable);
24 void snd_hdac_ext_bus_ppcap_int_enable(struct hdac_bus *chip, bool enable);
26 int snd_hdac_ext_bus_get_ml_capabilities(struct hdac_bus *bus);
27 struct hdac_ext_link *snd_hdac_ext_bus_get_hlink_by_addr(struct hdac_bus *bus, int addr);
28 struct hdac_ext_link *snd_hdac_ext_bus_get_hlink_by_name(struct hdac_bus *bus,
29 const char *codec_name);
31 enum hdac_ext_stream_type {
32 HDAC_EXT_STREAM_TYPE_COUPLED = 0,
33 HDAC_EXT_STREAM_TYPE_HOST,
34 HDAC_EXT_STREAM_TYPE_LINK
38 * hdac_ext_stream: HDAC extended stream for extended HDA caps
40 * @hstream: hdac_stream
41 * @pphc_addr: processing pipe host stream pointer
42 * @pplc_addr: processing pipe link stream pointer
43 * @decoupled: stream host and link is decoupled
44 * @link_locked: link is locked
45 * @link_prepared: link is prepared
46 * @link_substream: link substream
48 struct hdac_ext_stream {
49 struct hdac_stream hstream;
51 void __iomem *pphc_addr;
52 void __iomem *pplc_addr;
63 struct snd_pcm_substream *link_substream;
66 #define hdac_stream(s) (&(s)->hstream)
67 #define stream_to_hdac_ext_stream(s) \
68 container_of(s, struct hdac_ext_stream, hstream)
70 int snd_hdac_ext_stream_init_all(struct hdac_bus *bus, int start_idx,
71 int num_stream, int dir);
72 void snd_hdac_ext_stream_free_all(struct hdac_bus *bus);
73 void snd_hdac_ext_link_free_all(struct hdac_bus *bus);
74 struct hdac_ext_stream *snd_hdac_ext_stream_assign(struct hdac_bus *bus,
75 struct snd_pcm_substream *substream,
77 void snd_hdac_ext_stream_release(struct hdac_ext_stream *hext_stream, int type);
78 void snd_hdac_ext_stream_decouple_locked(struct hdac_bus *bus,
79 struct hdac_ext_stream *hext_stream, bool decouple);
80 void snd_hdac_ext_stream_decouple(struct hdac_bus *bus,
81 struct hdac_ext_stream *azx_dev, bool decouple);
83 void snd_hdac_ext_stream_start(struct hdac_ext_stream *hext_stream);
84 void snd_hdac_ext_stream_clear(struct hdac_ext_stream *hext_stream);
85 void snd_hdac_ext_stream_reset(struct hdac_ext_stream *hext_stream);
86 int snd_hdac_ext_stream_setup(struct hdac_ext_stream *hext_stream, int fmt);
88 struct hdac_ext_link {
91 void __iomem *ml_addr; /* link output stream reg pointer */
92 u32 lcaps; /* link capablities */
93 u16 lsdiid; /* link sdi identifier */
97 struct list_head list;
100 int snd_hdac_ext_bus_link_power_up(struct hdac_ext_link *hlink);
101 int snd_hdac_ext_bus_link_power_down(struct hdac_ext_link *hlink);
102 int snd_hdac_ext_bus_link_power_up_all(struct hdac_bus *bus);
103 int snd_hdac_ext_bus_link_power_down_all(struct hdac_bus *bus);
104 void snd_hdac_ext_bus_link_set_stream_id(struct hdac_ext_link *hlink,
106 void snd_hdac_ext_bus_link_clear_stream_id(struct hdac_ext_link *hlink,
109 int snd_hdac_ext_bus_link_get(struct hdac_bus *bus, struct hdac_ext_link *hlink);
110 int snd_hdac_ext_bus_link_put(struct hdac_bus *bus, struct hdac_ext_link *hlink);
112 void snd_hdac_ext_bus_link_power(struct hdac_device *codec, bool enable);
114 #define snd_hdac_adsp_writeb(chip, reg, value) \
115 snd_hdac_reg_writeb(chip, (chip)->dsp_ba + (reg), value)
116 #define snd_hdac_adsp_readb(chip, reg) \
117 snd_hdac_reg_readb(chip, (chip)->dsp_ba + (reg))
118 #define snd_hdac_adsp_writew(chip, reg, value) \
119 snd_hdac_reg_writew(chip, (chip)->dsp_ba + (reg), value)
120 #define snd_hdac_adsp_readw(chip, reg) \
121 snd_hdac_reg_readw(chip, (chip)->dsp_ba + (reg))
122 #define snd_hdac_adsp_writel(chip, reg, value) \
123 snd_hdac_reg_writel(chip, (chip)->dsp_ba + (reg), value)
124 #define snd_hdac_adsp_readl(chip, reg) \
125 snd_hdac_reg_readl(chip, (chip)->dsp_ba + (reg))
126 #define snd_hdac_adsp_writeq(chip, reg, value) \
127 snd_hdac_reg_writeq(chip, (chip)->dsp_ba + (reg), value)
128 #define snd_hdac_adsp_readq(chip, reg) \
129 snd_hdac_reg_readq(chip, (chip)->dsp_ba + (reg))
131 #define snd_hdac_adsp_updateb(chip, reg, mask, val) \
132 snd_hdac_adsp_writeb(chip, reg, \
133 (snd_hdac_adsp_readb(chip, reg) & ~(mask)) | (val))
134 #define snd_hdac_adsp_updatew(chip, reg, mask, val) \
135 snd_hdac_adsp_writew(chip, reg, \
136 (snd_hdac_adsp_readw(chip, reg) & ~(mask)) | (val))
137 #define snd_hdac_adsp_updatel(chip, reg, mask, val) \
138 snd_hdac_adsp_writel(chip, reg, \
139 (snd_hdac_adsp_readl(chip, reg) & ~(mask)) | (val))
140 #define snd_hdac_adsp_updateq(chip, reg, mask, val) \
141 snd_hdac_adsp_writeq(chip, reg, \
142 (snd_hdac_adsp_readq(chip, reg) & ~(mask)) | (val))
144 #define snd_hdac_adsp_readb_poll(chip, reg, val, cond, delay_us, timeout_us) \
145 readb_poll_timeout((chip)->dsp_ba + (reg), val, cond, \
146 delay_us, timeout_us)
147 #define snd_hdac_adsp_readw_poll(chip, reg, val, cond, delay_us, timeout_us) \
148 readw_poll_timeout((chip)->dsp_ba + (reg), val, cond, \
149 delay_us, timeout_us)
150 #define snd_hdac_adsp_readl_poll(chip, reg, val, cond, delay_us, timeout_us) \
151 readl_poll_timeout((chip)->dsp_ba + (reg), val, cond, \
152 delay_us, timeout_us)
153 #define snd_hdac_adsp_readq_poll(chip, reg, val, cond, delay_us, timeout_us) \
154 readq_poll_timeout((chip)->dsp_ba + (reg), val, cond, \
155 delay_us, timeout_us)
157 struct hdac_ext_device;
159 /* ops common to all codec drivers */
160 struct hdac_ext_codec_ops {
161 int (*build_controls)(struct hdac_ext_device *dev);
162 int (*init)(struct hdac_ext_device *dev);
163 void (*free)(struct hdac_ext_device *dev);
172 struct hdac_ext_dma_params {
177 int snd_hda_ext_driver_register(struct hdac_driver *drv);
178 void snd_hda_ext_driver_unregister(struct hdac_driver *drv);
180 #endif /* __SOUND_HDAUDIO_EXT_H */