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