1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef __SOUND_HDAUDIO_EXT_H 3 #define __SOUND_HDAUDIO_EXT_H 4 5 #include <linux/io-64-nonatomic-lo-hi.h> 6 #include <linux/iopoll.h> 7 #include <sound/hdaudio.h> 8 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); 12 13 void snd_hdac_ext_bus_exit(struct hdac_bus *bus); 14 void snd_hdac_ext_bus_device_remove(struct hdac_bus *bus); 15 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) 22 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); 25 26 void snd_hdac_ext_stream_spbcap_enable(struct hdac_bus *chip, 27 bool enable, int index); 28 29 int snd_hdac_ext_bus_get_ml_capabilities(struct hdac_bus *bus); 30 struct hdac_ext_link *snd_hdac_ext_bus_link_at(struct hdac_bus *bus, int addr); 31 struct hdac_ext_link *snd_hdac_ext_bus_get_link(struct hdac_bus *bus, 32 const char *codec_name); 33 34 enum hdac_ext_stream_type { 35 HDAC_EXT_STREAM_TYPE_COUPLED = 0, 36 HDAC_EXT_STREAM_TYPE_HOST, 37 HDAC_EXT_STREAM_TYPE_LINK 38 }; 39 40 /** 41 * hdac_ext_stream: HDAC extended stream for extended HDA caps 42 * 43 * @hstream: hdac_stream 44 * @pphc_addr: processing pipe host stream pointer 45 * @pplc_addr: processing pipe link stream pointer 46 * @spib_addr: software position in buffers stream pointer 47 * @fifo_addr: software position Max fifos stream pointer 48 * @dpibr_addr: DMA position in buffer resume pointer 49 * @dpib: DMA position in buffer 50 * @lpib: Linear position in buffer 51 * @decoupled: stream host and link is decoupled 52 * @link_locked: link is locked 53 * @link_prepared: link is prepared 54 * @link_substream: link substream 55 */ 56 struct hdac_ext_stream { 57 struct hdac_stream hstream; 58 59 void __iomem *pphc_addr; 60 void __iomem *pplc_addr; 61 62 void __iomem *spib_addr; 63 void __iomem *fifo_addr; 64 65 void __iomem *dpibr_addr; 66 67 u32 dpib; 68 u32 lpib; 69 bool decoupled:1; 70 bool link_locked:1; 71 bool link_prepared; 72 73 struct snd_pcm_substream *link_substream; 74 }; 75 76 #define hdac_stream(s) (&(s)->hstream) 77 #define stream_to_hdac_ext_stream(s) \ 78 container_of(s, struct hdac_ext_stream, hstream) 79 80 int snd_hdac_ext_stream_init_all(struct hdac_bus *bus, int start_idx, 81 int num_stream, int dir); 82 void snd_hdac_ext_stream_free_all(struct hdac_bus *bus); 83 void snd_hdac_link_free_all(struct hdac_bus *bus); 84 struct hdac_ext_stream *snd_hdac_ext_stream_assign(struct hdac_bus *bus, 85 struct snd_pcm_substream *substream, 86 int type); 87 void snd_hdac_ext_stream_release(struct hdac_ext_stream *hext_stream, int type); 88 void snd_hdac_ext_stream_decouple_locked(struct hdac_bus *bus, 89 struct hdac_ext_stream *hext_stream, bool decouple); 90 void snd_hdac_ext_stream_decouple(struct hdac_bus *bus, 91 struct hdac_ext_stream *azx_dev, bool decouple); 92 93 int snd_hdac_ext_stream_set_spib(struct hdac_bus *bus, 94 struct hdac_ext_stream *hext_stream, u32 value); 95 int snd_hdac_ext_stream_get_spbmaxfifo(struct hdac_bus *bus, 96 struct hdac_ext_stream *hext_stream); 97 void snd_hdac_ext_stream_drsm_enable(struct hdac_bus *bus, 98 bool enable, int index); 99 int snd_hdac_ext_stream_set_dpibr(struct hdac_bus *bus, 100 struct hdac_ext_stream *hext_stream, u32 value); 101 int snd_hdac_ext_stream_set_lpib(struct hdac_ext_stream *hext_stream, u32 value); 102 103 void snd_hdac_ext_link_stream_start(struct hdac_ext_stream *hext_stream); 104 void snd_hdac_ext_link_stream_clear(struct hdac_ext_stream *hext_stream); 105 void snd_hdac_ext_link_stream_reset(struct hdac_ext_stream *hext_stream); 106 int snd_hdac_ext_link_stream_setup(struct hdac_ext_stream *hext_stream, int fmt); 107 108 struct hdac_ext_link { 109 struct hdac_bus *bus; 110 int index; 111 void __iomem *ml_addr; /* link output stream reg pointer */ 112 u32 lcaps; /* link capablities */ 113 u16 lsdiid; /* link sdi identifier */ 114 115 int ref_count; 116 117 struct list_head list; 118 }; 119 120 int snd_hdac_ext_bus_link_power_up(struct hdac_ext_link *link); 121 int snd_hdac_ext_bus_link_power_down(struct hdac_ext_link *link); 122 int snd_hdac_ext_bus_link_power_up_all(struct hdac_bus *bus); 123 int snd_hdac_ext_bus_link_power_down_all(struct hdac_bus *bus); 124 void snd_hdac_ext_link_set_stream_id(struct hdac_ext_link *link, 125 int stream); 126 void snd_hdac_ext_link_clear_stream_id(struct hdac_ext_link *link, 127 int stream); 128 129 int snd_hdac_ext_bus_link_get(struct hdac_bus *bus, struct hdac_ext_link *link); 130 int snd_hdac_ext_bus_link_put(struct hdac_bus *bus, struct hdac_ext_link *link); 131 132 void snd_hdac_ext_bus_link_power(struct hdac_device *codec, bool enable); 133 134 /* update register macro */ 135 #define snd_hdac_updatel(addr, reg, mask, val) \ 136 writel(((readl(addr + reg) & ~(mask)) | (val)), \ 137 addr + reg) 138 139 #define snd_hdac_updatew(addr, reg, mask, val) \ 140 writew(((readw(addr + reg) & ~(mask)) | (val)), \ 141 addr + reg) 142 143 #define snd_hdac_adsp_writeb(chip, reg, value) \ 144 snd_hdac_reg_writeb(chip, (chip)->dsp_ba + (reg), value) 145 #define snd_hdac_adsp_readb(chip, reg) \ 146 snd_hdac_reg_readb(chip, (chip)->dsp_ba + (reg)) 147 #define snd_hdac_adsp_writew(chip, reg, value) \ 148 snd_hdac_reg_writew(chip, (chip)->dsp_ba + (reg), value) 149 #define snd_hdac_adsp_readw(chip, reg) \ 150 snd_hdac_reg_readw(chip, (chip)->dsp_ba + (reg)) 151 #define snd_hdac_adsp_writel(chip, reg, value) \ 152 snd_hdac_reg_writel(chip, (chip)->dsp_ba + (reg), value) 153 #define snd_hdac_adsp_readl(chip, reg) \ 154 snd_hdac_reg_readl(chip, (chip)->dsp_ba + (reg)) 155 #define snd_hdac_adsp_writeq(chip, reg, value) \ 156 snd_hdac_reg_writeq(chip, (chip)->dsp_ba + (reg), value) 157 #define snd_hdac_adsp_readq(chip, reg) \ 158 snd_hdac_reg_readq(chip, (chip)->dsp_ba + (reg)) 159 160 #define snd_hdac_adsp_updateb(chip, reg, mask, val) \ 161 snd_hdac_adsp_writeb(chip, reg, \ 162 (snd_hdac_adsp_readb(chip, reg) & ~(mask)) | (val)) 163 #define snd_hdac_adsp_updatew(chip, reg, mask, val) \ 164 snd_hdac_adsp_writew(chip, reg, \ 165 (snd_hdac_adsp_readw(chip, reg) & ~(mask)) | (val)) 166 #define snd_hdac_adsp_updatel(chip, reg, mask, val) \ 167 snd_hdac_adsp_writel(chip, reg, \ 168 (snd_hdac_adsp_readl(chip, reg) & ~(mask)) | (val)) 169 #define snd_hdac_adsp_updateq(chip, reg, mask, val) \ 170 snd_hdac_adsp_writeq(chip, reg, \ 171 (snd_hdac_adsp_readq(chip, reg) & ~(mask)) | (val)) 172 173 #define snd_hdac_adsp_readb_poll(chip, reg, val, cond, delay_us, timeout_us) \ 174 readb_poll_timeout((chip)->dsp_ba + (reg), val, cond, \ 175 delay_us, timeout_us) 176 #define snd_hdac_adsp_readw_poll(chip, reg, val, cond, delay_us, timeout_us) \ 177 readw_poll_timeout((chip)->dsp_ba + (reg), val, cond, \ 178 delay_us, timeout_us) 179 #define snd_hdac_adsp_readl_poll(chip, reg, val, cond, delay_us, timeout_us) \ 180 readl_poll_timeout((chip)->dsp_ba + (reg), val, cond, \ 181 delay_us, timeout_us) 182 #define snd_hdac_adsp_readq_poll(chip, reg, val, cond, delay_us, timeout_us) \ 183 readq_poll_timeout((chip)->dsp_ba + (reg), val, cond, \ 184 delay_us, timeout_us) 185 186 struct hdac_ext_device; 187 188 /* ops common to all codec drivers */ 189 struct hdac_ext_codec_ops { 190 int (*build_controls)(struct hdac_ext_device *dev); 191 int (*init)(struct hdac_ext_device *dev); 192 void (*free)(struct hdac_ext_device *dev); 193 }; 194 195 struct hda_dai_map { 196 char *dai_name; 197 hda_nid_t nid; 198 u32 maxbps; 199 }; 200 201 struct hdac_ext_dma_params { 202 u32 format; 203 u8 stream_tag; 204 }; 205 206 int snd_hda_ext_driver_register(struct hdac_driver *drv); 207 void snd_hda_ext_driver_unregister(struct hdac_driver *drv); 208 209 #endif /* __SOUND_HDAUDIO_EXT_H */ 210