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 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); 30 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 35 }; 36 37 /** 38 * hdac_ext_stream: HDAC extended stream for extended HDA caps 39 * 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 47 */ 48 struct hdac_ext_stream { 49 struct hdac_stream hstream; 50 51 void __iomem *pphc_addr; 52 void __iomem *pplc_addr; 53 54 bool decoupled:1; 55 bool link_locked:1; 56 bool link_prepared; 57 58 struct snd_pcm_substream *link_substream; 59 }; 60 61 #define hdac_stream(s) (&(s)->hstream) 62 #define stream_to_hdac_ext_stream(s) \ 63 container_of(s, struct hdac_ext_stream, hstream) 64 65 int snd_hdac_ext_stream_init_all(struct hdac_bus *bus, int start_idx, 66 int num_stream, int dir); 67 void snd_hdac_ext_stream_free_all(struct hdac_bus *bus); 68 void snd_hdac_ext_link_free_all(struct hdac_bus *bus); 69 struct hdac_ext_stream *snd_hdac_ext_stream_assign(struct hdac_bus *bus, 70 struct snd_pcm_substream *substream, 71 int type); 72 void snd_hdac_ext_stream_release(struct hdac_ext_stream *hext_stream, int type); 73 void snd_hdac_ext_stream_decouple_locked(struct hdac_bus *bus, 74 struct hdac_ext_stream *hext_stream, bool decouple); 75 void snd_hdac_ext_stream_decouple(struct hdac_bus *bus, 76 struct hdac_ext_stream *azx_dev, bool decouple); 77 78 void snd_hdac_ext_stream_start(struct hdac_ext_stream *hext_stream); 79 void snd_hdac_ext_stream_clear(struct hdac_ext_stream *hext_stream); 80 void snd_hdac_ext_stream_reset(struct hdac_ext_stream *hext_stream); 81 int snd_hdac_ext_stream_setup(struct hdac_ext_stream *hext_stream, int fmt); 82 83 struct hdac_ext_link { 84 struct hdac_bus *bus; 85 int index; 86 void __iomem *ml_addr; /* link output stream reg pointer */ 87 u32 lcaps; /* link capablities */ 88 u16 lsdiid; /* link sdi identifier */ 89 90 int ref_count; 91 92 struct list_head list; 93 }; 94 95 int snd_hdac_ext_bus_link_power_up(struct hdac_ext_link *hlink); 96 int snd_hdac_ext_bus_link_power_down(struct hdac_ext_link *hlink); 97 int snd_hdac_ext_bus_link_power_up_all(struct hdac_bus *bus); 98 int snd_hdac_ext_bus_link_power_down_all(struct hdac_bus *bus); 99 void snd_hdac_ext_bus_link_set_stream_id(struct hdac_ext_link *hlink, 100 int stream); 101 void snd_hdac_ext_bus_link_clear_stream_id(struct hdac_ext_link *hlink, 102 int stream); 103 104 int snd_hdac_ext_bus_link_get(struct hdac_bus *bus, struct hdac_ext_link *hlink); 105 int snd_hdac_ext_bus_link_put(struct hdac_bus *bus, struct hdac_ext_link *hlink); 106 107 void snd_hdac_ext_bus_link_power(struct hdac_device *codec, bool enable); 108 109 #define snd_hdac_adsp_writeb(chip, reg, value) \ 110 snd_hdac_reg_writeb(chip, (chip)->dsp_ba + (reg), value) 111 #define snd_hdac_adsp_readb(chip, reg) \ 112 snd_hdac_reg_readb(chip, (chip)->dsp_ba + (reg)) 113 #define snd_hdac_adsp_writew(chip, reg, value) \ 114 snd_hdac_reg_writew(chip, (chip)->dsp_ba + (reg), value) 115 #define snd_hdac_adsp_readw(chip, reg) \ 116 snd_hdac_reg_readw(chip, (chip)->dsp_ba + (reg)) 117 #define snd_hdac_adsp_writel(chip, reg, value) \ 118 snd_hdac_reg_writel(chip, (chip)->dsp_ba + (reg), value) 119 #define snd_hdac_adsp_readl(chip, reg) \ 120 snd_hdac_reg_readl(chip, (chip)->dsp_ba + (reg)) 121 #define snd_hdac_adsp_writeq(chip, reg, value) \ 122 snd_hdac_reg_writeq(chip, (chip)->dsp_ba + (reg), value) 123 #define snd_hdac_adsp_readq(chip, reg) \ 124 snd_hdac_reg_readq(chip, (chip)->dsp_ba + (reg)) 125 126 #define snd_hdac_adsp_updateb(chip, reg, mask, val) \ 127 snd_hdac_adsp_writeb(chip, reg, \ 128 (snd_hdac_adsp_readb(chip, reg) & ~(mask)) | (val)) 129 #define snd_hdac_adsp_updatew(chip, reg, mask, val) \ 130 snd_hdac_adsp_writew(chip, reg, \ 131 (snd_hdac_adsp_readw(chip, reg) & ~(mask)) | (val)) 132 #define snd_hdac_adsp_updatel(chip, reg, mask, val) \ 133 snd_hdac_adsp_writel(chip, reg, \ 134 (snd_hdac_adsp_readl(chip, reg) & ~(mask)) | (val)) 135 #define snd_hdac_adsp_updateq(chip, reg, mask, val) \ 136 snd_hdac_adsp_writeq(chip, reg, \ 137 (snd_hdac_adsp_readq(chip, reg) & ~(mask)) | (val)) 138 139 #define snd_hdac_adsp_readb_poll(chip, reg, val, cond, delay_us, timeout_us) \ 140 readb_poll_timeout((chip)->dsp_ba + (reg), val, cond, \ 141 delay_us, timeout_us) 142 #define snd_hdac_adsp_readw_poll(chip, reg, val, cond, delay_us, timeout_us) \ 143 readw_poll_timeout((chip)->dsp_ba + (reg), val, cond, \ 144 delay_us, timeout_us) 145 #define snd_hdac_adsp_readl_poll(chip, reg, val, cond, delay_us, timeout_us) \ 146 readl_poll_timeout((chip)->dsp_ba + (reg), val, cond, \ 147 delay_us, timeout_us) 148 #define snd_hdac_adsp_readq_poll(chip, reg, val, cond, delay_us, timeout_us) \ 149 readq_poll_timeout((chip)->dsp_ba + (reg), val, cond, \ 150 delay_us, timeout_us) 151 152 struct hdac_ext_device; 153 154 /* ops common to all codec drivers */ 155 struct hdac_ext_codec_ops { 156 int (*build_controls)(struct hdac_ext_device *dev); 157 int (*init)(struct hdac_ext_device *dev); 158 void (*free)(struct hdac_ext_device *dev); 159 }; 160 161 struct hda_dai_map { 162 char *dai_name; 163 hda_nid_t nid; 164 u32 maxbps; 165 }; 166 167 struct hdac_ext_dma_params { 168 u32 format; 169 u8 stream_tag; 170 }; 171 172 int snd_hda_ext_driver_register(struct hdac_driver *drv); 173 void snd_hda_ext_driver_unregister(struct hdac_driver *drv); 174 175 #endif /* __SOUND_HDAUDIO_EXT_H */ 176