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