Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Implementation of primary alsa driver code base for Intel HD Audio. |
| 4 | * |
| 5 | * Copyright(c) 2004 Intel Corporation. All rights reserved. |
| 6 | * |
| 7 | * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de> |
| 8 | * PeiSen Hou <pshou@realtek.com.tw> |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify it |
| 11 | * under the terms of the GNU General Public License as published by the Free |
| 12 | * Software Foundation; either version 2 of the License, or (at your option) |
| 13 | * any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 16 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 18 | * more details. |
| 19 | * |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | #include <linux/clocksource.h> |
| 24 | #include <linux/delay.h> |
Dylan Reid | f0b1df8 | 2014-02-28 15:41:29 -0800 | [diff] [blame] | 25 | #include <linux/interrupt.h> |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 26 | #include <linux/kernel.h> |
| 27 | #include <linux/module.h> |
Dylan Reid | 154867c | 2014-02-28 15:41:30 -0800 | [diff] [blame] | 28 | #include <linux/pm_runtime.h> |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 29 | #include <linux/slab.h> |
| 30 | #include <sound/core.h> |
| 31 | #include <sound/initval.h> |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 32 | #include "hda_controller.h" |
| 33 | |
Takashi Iwai | 43db4a5 | 2015-04-16 11:44:58 +0200 | [diff] [blame] | 34 | #define CREATE_TRACE_POINTS |
Libin Yang | 1848650 | 2015-05-12 09:43:21 +0800 | [diff] [blame^] | 35 | #include "hda_controller_trace.h" |
Takashi Iwai | 43db4a5 | 2015-04-16 11:44:58 +0200 | [diff] [blame] | 36 | |
Dylan Reid | 2b5fd6c | 2014-02-28 15:41:24 -0800 | [diff] [blame] | 37 | /* DSP lock helpers */ |
Takashi Iwai | 7833c3f | 2015-04-14 18:13:13 +0200 | [diff] [blame] | 38 | #define dsp_lock(dev) snd_hdac_dsp_lock(azx_stream(dev)) |
| 39 | #define dsp_unlock(dev) snd_hdac_dsp_unlock(azx_stream(dev)) |
| 40 | #define dsp_is_locked(dev) snd_hdac_stream_is_locked(azx_stream(dev)) |
Dylan Reid | 2b5fd6c | 2014-02-28 15:41:24 -0800 | [diff] [blame] | 41 | |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 42 | /* assign a stream for the PCM */ |
| 43 | static inline struct azx_dev * |
| 44 | azx_assign_device(struct azx *chip, struct snd_pcm_substream *substream) |
| 45 | { |
Takashi Iwai | 7833c3f | 2015-04-14 18:13:13 +0200 | [diff] [blame] | 46 | struct hdac_stream *s; |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 47 | |
Takashi Iwai | 7833c3f | 2015-04-14 18:13:13 +0200 | [diff] [blame] | 48 | s = snd_hdac_stream_assign(azx_bus(chip), substream); |
| 49 | if (!s) |
| 50 | return NULL; |
| 51 | return stream_to_azx_dev(s); |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | /* release the assigned stream */ |
| 55 | static inline void azx_release_device(struct azx_dev *azx_dev) |
| 56 | { |
Takashi Iwai | 7833c3f | 2015-04-14 18:13:13 +0200 | [diff] [blame] | 57 | snd_hdac_stream_release(azx_stream(azx_dev)); |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 58 | } |
| 59 | |
Takashi Iwai | 820cc6c | 2015-02-20 12:50:46 +0100 | [diff] [blame] | 60 | static inline struct hda_pcm_stream * |
| 61 | to_hda_pcm_stream(struct snd_pcm_substream *substream) |
| 62 | { |
| 63 | struct azx_pcm *apcm = snd_pcm_substream_chip(substream); |
| 64 | return &apcm->info->stream[substream->stream]; |
| 65 | } |
| 66 | |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 67 | static u64 azx_adjust_codec_delay(struct snd_pcm_substream *substream, |
| 68 | u64 nsec) |
| 69 | { |
| 70 | struct azx_pcm *apcm = snd_pcm_substream_chip(substream); |
Takashi Iwai | 820cc6c | 2015-02-20 12:50:46 +0100 | [diff] [blame] | 71 | struct hda_pcm_stream *hinfo = to_hda_pcm_stream(substream); |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 72 | u64 codec_frames, codec_nsecs; |
| 73 | |
| 74 | if (!hinfo->ops.get_delay) |
| 75 | return nsec; |
| 76 | |
| 77 | codec_frames = hinfo->ops.get_delay(hinfo, apcm->codec, substream); |
| 78 | codec_nsecs = div_u64(codec_frames * 1000000000LL, |
| 79 | substream->runtime->rate); |
| 80 | |
| 81 | if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) |
| 82 | return nsec + codec_nsecs; |
| 83 | |
| 84 | return (nsec > codec_nsecs) ? nsec - codec_nsecs : 0; |
| 85 | } |
| 86 | |
| 87 | /* |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 88 | * PCM ops |
| 89 | */ |
| 90 | |
| 91 | static int azx_pcm_close(struct snd_pcm_substream *substream) |
| 92 | { |
| 93 | struct azx_pcm *apcm = snd_pcm_substream_chip(substream); |
Takashi Iwai | 820cc6c | 2015-02-20 12:50:46 +0100 | [diff] [blame] | 94 | struct hda_pcm_stream *hinfo = to_hda_pcm_stream(substream); |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 95 | struct azx *chip = apcm->chip; |
| 96 | struct azx_dev *azx_dev = get_azx_dev(substream); |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 97 | |
Libin Yang | 1848650 | 2015-05-12 09:43:21 +0800 | [diff] [blame^] | 98 | trace_azx_pcm_close(chip, azx_dev); |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 99 | mutex_lock(&chip->open_mutex); |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 100 | azx_release_device(azx_dev); |
Takashi Iwai | 61ca410 | 2015-02-27 17:57:55 +0100 | [diff] [blame] | 101 | if (hinfo->ops.close) |
| 102 | hinfo->ops.close(hinfo, apcm->codec, substream); |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 103 | snd_hda_power_down(apcm->codec); |
| 104 | mutex_unlock(&chip->open_mutex); |
Takashi Iwai | 9a6246f | 2015-02-27 18:17:28 +0100 | [diff] [blame] | 105 | snd_hda_codec_pcm_put(apcm->info); |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 106 | return 0; |
| 107 | } |
| 108 | |
| 109 | static int azx_pcm_hw_params(struct snd_pcm_substream *substream, |
| 110 | struct snd_pcm_hw_params *hw_params) |
| 111 | { |
| 112 | struct azx_pcm *apcm = snd_pcm_substream_chip(substream); |
| 113 | struct azx *chip = apcm->chip; |
Takashi Iwai | 602518a2 | 2015-04-16 07:53:08 +0200 | [diff] [blame] | 114 | struct azx_dev *azx_dev = get_azx_dev(substream); |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 115 | int ret; |
| 116 | |
Libin Yang | 1848650 | 2015-05-12 09:43:21 +0800 | [diff] [blame^] | 117 | trace_azx_pcm_hw_params(chip, azx_dev); |
Takashi Iwai | 602518a2 | 2015-04-16 07:53:08 +0200 | [diff] [blame] | 118 | dsp_lock(azx_dev); |
| 119 | if (dsp_is_locked(azx_dev)) { |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 120 | ret = -EBUSY; |
| 121 | goto unlock; |
| 122 | } |
| 123 | |
Takashi Iwai | 602518a2 | 2015-04-16 07:53:08 +0200 | [diff] [blame] | 124 | azx_dev->core.bufsize = 0; |
| 125 | azx_dev->core.period_bytes = 0; |
| 126 | azx_dev->core.format_val = 0; |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 127 | ret = chip->ops->substream_alloc_pages(chip, substream, |
| 128 | params_buffer_bytes(hw_params)); |
| 129 | unlock: |
Takashi Iwai | 602518a2 | 2015-04-16 07:53:08 +0200 | [diff] [blame] | 130 | dsp_unlock(azx_dev); |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 131 | return ret; |
| 132 | } |
| 133 | |
| 134 | static int azx_pcm_hw_free(struct snd_pcm_substream *substream) |
| 135 | { |
| 136 | struct azx_pcm *apcm = snd_pcm_substream_chip(substream); |
| 137 | struct azx_dev *azx_dev = get_azx_dev(substream); |
| 138 | struct azx *chip = apcm->chip; |
Takashi Iwai | 820cc6c | 2015-02-20 12:50:46 +0100 | [diff] [blame] | 139 | struct hda_pcm_stream *hinfo = to_hda_pcm_stream(substream); |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 140 | int err; |
| 141 | |
| 142 | /* reset BDL address */ |
| 143 | dsp_lock(azx_dev); |
Takashi Iwai | ccc9886 | 2015-04-14 22:06:53 +0200 | [diff] [blame] | 144 | if (!dsp_is_locked(azx_dev)) |
| 145 | snd_hdac_stream_cleanup(azx_stream(azx_dev)); |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 146 | |
| 147 | snd_hda_codec_cleanup(apcm->codec, hinfo, substream); |
| 148 | |
| 149 | err = chip->ops->substream_free_pages(chip, substream); |
Takashi Iwai | 6d23c8f | 2015-04-17 13:34:30 +0200 | [diff] [blame] | 150 | azx_stream(azx_dev)->prepared = 0; |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 151 | dsp_unlock(azx_dev); |
| 152 | return err; |
| 153 | } |
| 154 | |
| 155 | static int azx_pcm_prepare(struct snd_pcm_substream *substream) |
| 156 | { |
| 157 | struct azx_pcm *apcm = snd_pcm_substream_chip(substream); |
| 158 | struct azx *chip = apcm->chip; |
| 159 | struct azx_dev *azx_dev = get_azx_dev(substream); |
Takashi Iwai | 820cc6c | 2015-02-20 12:50:46 +0100 | [diff] [blame] | 160 | struct hda_pcm_stream *hinfo = to_hda_pcm_stream(substream); |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 161 | struct snd_pcm_runtime *runtime = substream->runtime; |
Takashi Iwai | 0dd76f3 | 2015-04-18 09:59:38 +0200 | [diff] [blame] | 162 | unsigned int format_val, stream_tag; |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 163 | int err; |
| 164 | struct hda_spdif_out *spdif = |
| 165 | snd_hda_spdif_out_of_nid(apcm->codec, hinfo->nid); |
| 166 | unsigned short ctls = spdif ? spdif->ctls : 0; |
| 167 | |
Libin Yang | 1848650 | 2015-05-12 09:43:21 +0800 | [diff] [blame^] | 168 | trace_azx_pcm_prepare(chip, azx_dev); |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 169 | dsp_lock(azx_dev); |
| 170 | if (dsp_is_locked(azx_dev)) { |
| 171 | err = -EBUSY; |
| 172 | goto unlock; |
| 173 | } |
| 174 | |
Takashi Iwai | 7833c3f | 2015-04-14 18:13:13 +0200 | [diff] [blame] | 175 | snd_hdac_stream_reset(azx_stream(azx_dev)); |
Takashi Iwai | b7d023e | 2015-04-16 08:19:06 +0200 | [diff] [blame] | 176 | format_val = snd_hdac_calc_stream_format(runtime->rate, |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 177 | runtime->channels, |
| 178 | runtime->format, |
| 179 | hinfo->maxbps, |
| 180 | ctls); |
| 181 | if (!format_val) { |
| 182 | dev_err(chip->card->dev, |
| 183 | "invalid format_val, rate=%d, ch=%d, format=%d\n", |
| 184 | runtime->rate, runtime->channels, runtime->format); |
| 185 | err = -EINVAL; |
| 186 | goto unlock; |
| 187 | } |
| 188 | |
Takashi Iwai | 0dd76f3 | 2015-04-18 09:59:38 +0200 | [diff] [blame] | 189 | err = snd_hdac_stream_set_params(azx_stream(azx_dev), format_val); |
| 190 | if (err < 0) |
| 191 | goto unlock; |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 192 | |
Takashi Iwai | ccc9886 | 2015-04-14 22:06:53 +0200 | [diff] [blame] | 193 | snd_hdac_stream_setup(azx_stream(azx_dev)); |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 194 | |
Takashi Iwai | 7833c3f | 2015-04-14 18:13:13 +0200 | [diff] [blame] | 195 | stream_tag = azx_dev->core.stream_tag; |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 196 | /* CA-IBG chips need the playback stream starting from 1 */ |
| 197 | if ((chip->driver_caps & AZX_DCAPS_CTX_WORKAROUND) && |
| 198 | stream_tag > chip->capture_streams) |
| 199 | stream_tag -= chip->capture_streams; |
| 200 | err = snd_hda_codec_prepare(apcm->codec, hinfo, stream_tag, |
Takashi Iwai | 7833c3f | 2015-04-14 18:13:13 +0200 | [diff] [blame] | 201 | azx_dev->core.format_val, substream); |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 202 | |
| 203 | unlock: |
| 204 | if (!err) |
Takashi Iwai | 6d23c8f | 2015-04-17 13:34:30 +0200 | [diff] [blame] | 205 | azx_stream(azx_dev)->prepared = 1; |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 206 | dsp_unlock(azx_dev); |
| 207 | return err; |
| 208 | } |
| 209 | |
| 210 | static int azx_pcm_trigger(struct snd_pcm_substream *substream, int cmd) |
| 211 | { |
| 212 | struct azx_pcm *apcm = snd_pcm_substream_chip(substream); |
| 213 | struct azx *chip = apcm->chip; |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 214 | struct hdac_bus *bus = azx_bus(chip); |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 215 | struct azx_dev *azx_dev; |
| 216 | struct snd_pcm_substream *s; |
Takashi Iwai | ccc9886 | 2015-04-14 22:06:53 +0200 | [diff] [blame] | 217 | struct hdac_stream *hstr; |
| 218 | bool start; |
| 219 | int sbits = 0; |
| 220 | int sync_reg; |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 221 | |
| 222 | azx_dev = get_azx_dev(substream); |
Takashi Iwai | 43db4a5 | 2015-04-16 11:44:58 +0200 | [diff] [blame] | 223 | trace_azx_pcm_trigger(chip, azx_dev, cmd); |
| 224 | |
Takashi Iwai | ccc9886 | 2015-04-14 22:06:53 +0200 | [diff] [blame] | 225 | hstr = azx_stream(azx_dev); |
| 226 | if (chip->driver_caps & AZX_DCAPS_OLD_SSYNC) |
| 227 | sync_reg = AZX_REG_OLD_SSYNC; |
| 228 | else |
| 229 | sync_reg = AZX_REG_SSYNC; |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 230 | |
Takashi Iwai | 6d23c8f | 2015-04-17 13:34:30 +0200 | [diff] [blame] | 231 | if (dsp_is_locked(azx_dev) || !hstr->prepared) |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 232 | return -EPIPE; |
| 233 | |
| 234 | switch (cmd) { |
| 235 | case SNDRV_PCM_TRIGGER_START: |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 236 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
| 237 | case SNDRV_PCM_TRIGGER_RESUME: |
Takashi Iwai | ccc9886 | 2015-04-14 22:06:53 +0200 | [diff] [blame] | 238 | start = true; |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 239 | break; |
| 240 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
| 241 | case SNDRV_PCM_TRIGGER_SUSPEND: |
| 242 | case SNDRV_PCM_TRIGGER_STOP: |
Takashi Iwai | ccc9886 | 2015-04-14 22:06:53 +0200 | [diff] [blame] | 243 | start = false; |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 244 | break; |
| 245 | default: |
| 246 | return -EINVAL; |
| 247 | } |
| 248 | |
| 249 | snd_pcm_group_for_each_entry(s, substream) { |
| 250 | if (s->pcm->card != substream->pcm->card) |
| 251 | continue; |
| 252 | azx_dev = get_azx_dev(s); |
Takashi Iwai | 7833c3f | 2015-04-14 18:13:13 +0200 | [diff] [blame] | 253 | sbits |= 1 << azx_dev->core.index; |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 254 | snd_pcm_trigger_done(s, substream); |
| 255 | } |
| 256 | |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 257 | spin_lock(&bus->reg_lock); |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 258 | |
| 259 | /* first, set SYNC bits of corresponding streams */ |
Takashi Iwai | ccc9886 | 2015-04-14 22:06:53 +0200 | [diff] [blame] | 260 | snd_hdac_stream_sync_trigger(hstr, true, sbits, sync_reg); |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 261 | |
| 262 | snd_pcm_group_for_each_entry(s, substream) { |
| 263 | if (s->pcm->card != substream->pcm->card) |
| 264 | continue; |
| 265 | azx_dev = get_azx_dev(s); |
| 266 | if (start) { |
Takashi Iwai | 7833c3f | 2015-04-14 18:13:13 +0200 | [diff] [blame] | 267 | azx_dev->insufficient = 1; |
| 268 | snd_hdac_stream_start(azx_stream(azx_dev), true); |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 269 | } else { |
Takashi Iwai | 7833c3f | 2015-04-14 18:13:13 +0200 | [diff] [blame] | 270 | snd_hdac_stream_stop(azx_stream(azx_dev)); |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 271 | } |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 272 | } |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 273 | spin_unlock(&bus->reg_lock); |
Takashi Iwai | ccc9886 | 2015-04-14 22:06:53 +0200 | [diff] [blame] | 274 | |
| 275 | snd_hdac_stream_sync(hstr, start, sbits); |
| 276 | |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 277 | spin_lock(&bus->reg_lock); |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 278 | /* reset SYNC bits */ |
Takashi Iwai | ccc9886 | 2015-04-14 22:06:53 +0200 | [diff] [blame] | 279 | snd_hdac_stream_sync_trigger(hstr, false, sbits, sync_reg); |
| 280 | if (start) |
| 281 | snd_hdac_stream_timecounter_init(hstr, sbits); |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 282 | spin_unlock(&bus->reg_lock); |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 283 | return 0; |
| 284 | } |
| 285 | |
Takashi Iwai | b6050ef | 2014-06-26 16:50:16 +0200 | [diff] [blame] | 286 | unsigned int azx_get_pos_lpib(struct azx *chip, struct azx_dev *azx_dev) |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 287 | { |
Takashi Iwai | 7833c3f | 2015-04-14 18:13:13 +0200 | [diff] [blame] | 288 | return snd_hdac_stream_get_pos_lpib(azx_stream(azx_dev)); |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 289 | } |
Takashi Iwai | b6050ef | 2014-06-26 16:50:16 +0200 | [diff] [blame] | 290 | EXPORT_SYMBOL_GPL(azx_get_pos_lpib); |
| 291 | |
| 292 | unsigned int azx_get_pos_posbuf(struct azx *chip, struct azx_dev *azx_dev) |
| 293 | { |
Takashi Iwai | 7833c3f | 2015-04-14 18:13:13 +0200 | [diff] [blame] | 294 | return snd_hdac_stream_get_pos_posbuf(azx_stream(azx_dev)); |
Takashi Iwai | b6050ef | 2014-06-26 16:50:16 +0200 | [diff] [blame] | 295 | } |
| 296 | EXPORT_SYMBOL_GPL(azx_get_pos_posbuf); |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 297 | |
| 298 | unsigned int azx_get_position(struct azx *chip, |
Takashi Iwai | b6050ef | 2014-06-26 16:50:16 +0200 | [diff] [blame] | 299 | struct azx_dev *azx_dev) |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 300 | { |
Takashi Iwai | 7833c3f | 2015-04-14 18:13:13 +0200 | [diff] [blame] | 301 | struct snd_pcm_substream *substream = azx_dev->core.substream; |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 302 | unsigned int pos; |
| 303 | int stream = substream->stream; |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 304 | int delay = 0; |
| 305 | |
Takashi Iwai | b6050ef | 2014-06-26 16:50:16 +0200 | [diff] [blame] | 306 | if (chip->get_position[stream]) |
| 307 | pos = chip->get_position[stream](chip, azx_dev); |
| 308 | else /* use the position buffer as default */ |
| 309 | pos = azx_get_pos_posbuf(chip, azx_dev); |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 310 | |
Takashi Iwai | 7833c3f | 2015-04-14 18:13:13 +0200 | [diff] [blame] | 311 | if (pos >= azx_dev->core.bufsize) |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 312 | pos = 0; |
| 313 | |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 314 | if (substream->runtime) { |
Takashi Iwai | b6050ef | 2014-06-26 16:50:16 +0200 | [diff] [blame] | 315 | struct azx_pcm *apcm = snd_pcm_substream_chip(substream); |
Takashi Iwai | 820cc6c | 2015-02-20 12:50:46 +0100 | [diff] [blame] | 316 | struct hda_pcm_stream *hinfo = to_hda_pcm_stream(substream); |
Takashi Iwai | b6050ef | 2014-06-26 16:50:16 +0200 | [diff] [blame] | 317 | |
| 318 | if (chip->get_delay[stream]) |
| 319 | delay += chip->get_delay[stream](chip, azx_dev, pos); |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 320 | if (hinfo->ops.get_delay) |
| 321 | delay += hinfo->ops.get_delay(hinfo, apcm->codec, |
| 322 | substream); |
| 323 | substream->runtime->delay = delay; |
| 324 | } |
| 325 | |
Takashi Iwai | 43db4a5 | 2015-04-16 11:44:58 +0200 | [diff] [blame] | 326 | trace_azx_get_position(chip, azx_dev, pos, delay); |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 327 | return pos; |
| 328 | } |
| 329 | EXPORT_SYMBOL_GPL(azx_get_position); |
| 330 | |
| 331 | static snd_pcm_uframes_t azx_pcm_pointer(struct snd_pcm_substream *substream) |
| 332 | { |
| 333 | struct azx_pcm *apcm = snd_pcm_substream_chip(substream); |
| 334 | struct azx *chip = apcm->chip; |
| 335 | struct azx_dev *azx_dev = get_azx_dev(substream); |
| 336 | return bytes_to_frames(substream->runtime, |
Takashi Iwai | b6050ef | 2014-06-26 16:50:16 +0200 | [diff] [blame] | 337 | azx_get_position(chip, azx_dev)); |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 338 | } |
| 339 | |
Pierre-Louis Bossart | 9e94df3 | 2015-02-13 15:14:07 -0600 | [diff] [blame] | 340 | static int azx_get_time_info(struct snd_pcm_substream *substream, |
| 341 | struct timespec *system_ts, struct timespec *audio_ts, |
| 342 | struct snd_pcm_audio_tstamp_config *audio_tstamp_config, |
| 343 | struct snd_pcm_audio_tstamp_report *audio_tstamp_report) |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 344 | { |
| 345 | struct azx_dev *azx_dev = get_azx_dev(substream); |
| 346 | u64 nsec; |
| 347 | |
Pierre-Louis Bossart | 9e94df3 | 2015-02-13 15:14:07 -0600 | [diff] [blame] | 348 | if ((substream->runtime->hw.info & SNDRV_PCM_INFO_HAS_LINK_ATIME) && |
| 349 | (audio_tstamp_config->type_requested == SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK)) { |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 350 | |
Pierre-Louis Bossart | 9e94df3 | 2015-02-13 15:14:07 -0600 | [diff] [blame] | 351 | snd_pcm_gettime(substream->runtime, system_ts); |
| 352 | |
Takashi Iwai | 7833c3f | 2015-04-14 18:13:13 +0200 | [diff] [blame] | 353 | nsec = timecounter_read(&azx_dev->core.tc); |
Pierre-Louis Bossart | 9e94df3 | 2015-02-13 15:14:07 -0600 | [diff] [blame] | 354 | nsec = div_u64(nsec, 3); /* can be optimized */ |
| 355 | if (audio_tstamp_config->report_delay) |
| 356 | nsec = azx_adjust_codec_delay(substream, nsec); |
| 357 | |
| 358 | *audio_ts = ns_to_timespec(nsec); |
| 359 | |
| 360 | audio_tstamp_report->actual_type = SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK; |
| 361 | audio_tstamp_report->accuracy_report = 1; /* rest of structure is valid */ |
| 362 | audio_tstamp_report->accuracy = 42; /* 24 MHz WallClock == 42ns resolution */ |
| 363 | |
| 364 | } else |
| 365 | audio_tstamp_report->actual_type = SNDRV_PCM_AUDIO_TSTAMP_TYPE_DEFAULT; |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 366 | |
| 367 | return 0; |
| 368 | } |
| 369 | |
| 370 | static struct snd_pcm_hardware azx_pcm_hw = { |
| 371 | .info = (SNDRV_PCM_INFO_MMAP | |
| 372 | SNDRV_PCM_INFO_INTERLEAVED | |
| 373 | SNDRV_PCM_INFO_BLOCK_TRANSFER | |
| 374 | SNDRV_PCM_INFO_MMAP_VALID | |
| 375 | /* No full-resume yet implemented */ |
| 376 | /* SNDRV_PCM_INFO_RESUME |*/ |
| 377 | SNDRV_PCM_INFO_PAUSE | |
| 378 | SNDRV_PCM_INFO_SYNC_START | |
Pierre-Louis Bossart | 9e94df3 | 2015-02-13 15:14:07 -0600 | [diff] [blame] | 379 | SNDRV_PCM_INFO_HAS_WALL_CLOCK | /* legacy */ |
| 380 | SNDRV_PCM_INFO_HAS_LINK_ATIME | |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 381 | SNDRV_PCM_INFO_NO_PERIOD_WAKEUP), |
| 382 | .formats = SNDRV_PCM_FMTBIT_S16_LE, |
| 383 | .rates = SNDRV_PCM_RATE_48000, |
| 384 | .rate_min = 48000, |
| 385 | .rate_max = 48000, |
| 386 | .channels_min = 2, |
| 387 | .channels_max = 2, |
| 388 | .buffer_bytes_max = AZX_MAX_BUF_SIZE, |
| 389 | .period_bytes_min = 128, |
| 390 | .period_bytes_max = AZX_MAX_BUF_SIZE / 2, |
| 391 | .periods_min = 2, |
| 392 | .periods_max = AZX_MAX_FRAG, |
| 393 | .fifo_size = 0, |
| 394 | }; |
| 395 | |
| 396 | static int azx_pcm_open(struct snd_pcm_substream *substream) |
| 397 | { |
| 398 | struct azx_pcm *apcm = snd_pcm_substream_chip(substream); |
Takashi Iwai | 820cc6c | 2015-02-20 12:50:46 +0100 | [diff] [blame] | 399 | struct hda_pcm_stream *hinfo = to_hda_pcm_stream(substream); |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 400 | struct azx *chip = apcm->chip; |
| 401 | struct azx_dev *azx_dev; |
| 402 | struct snd_pcm_runtime *runtime = substream->runtime; |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 403 | int err; |
| 404 | int buff_step; |
| 405 | |
Takashi Iwai | 9a6246f | 2015-02-27 18:17:28 +0100 | [diff] [blame] | 406 | snd_hda_codec_pcm_get(apcm->info); |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 407 | mutex_lock(&chip->open_mutex); |
| 408 | azx_dev = azx_assign_device(chip, substream); |
Libin Yang | 1848650 | 2015-05-12 09:43:21 +0800 | [diff] [blame^] | 409 | trace_azx_pcm_open(chip, azx_dev); |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 410 | if (azx_dev == NULL) { |
Takashi Iwai | 61ca410 | 2015-02-27 17:57:55 +0100 | [diff] [blame] | 411 | err = -EBUSY; |
| 412 | goto unlock; |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 413 | } |
Takashi Iwai | ccc9886 | 2015-04-14 22:06:53 +0200 | [diff] [blame] | 414 | runtime->private_data = azx_dev; |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 415 | runtime->hw = azx_pcm_hw; |
| 416 | runtime->hw.channels_min = hinfo->channels_min; |
| 417 | runtime->hw.channels_max = hinfo->channels_max; |
| 418 | runtime->hw.formats = hinfo->formats; |
| 419 | runtime->hw.rates = hinfo->rates; |
| 420 | snd_pcm_limit_hw_rates(runtime); |
| 421 | snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS); |
| 422 | |
| 423 | /* avoid wrap-around with wall-clock */ |
| 424 | snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_TIME, |
| 425 | 20, |
| 426 | 178000000); |
| 427 | |
| 428 | if (chip->align_buffer_size) |
| 429 | /* constrain buffer sizes to be multiple of 128 |
| 430 | bytes. This is more efficient in terms of memory |
| 431 | access but isn't required by the HDA spec and |
| 432 | prevents users from specifying exact period/buffer |
| 433 | sizes. For example for 44.1kHz, a period size set |
| 434 | to 20ms will be rounded to 19.59ms. */ |
| 435 | buff_step = 128; |
| 436 | else |
| 437 | /* Don't enforce steps on buffer sizes, still need to |
| 438 | be multiple of 4 bytes (HDA spec). Tested on Intel |
| 439 | HDA controllers, may not work on all devices where |
| 440 | option needs to be disabled */ |
| 441 | buff_step = 4; |
| 442 | |
| 443 | snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, |
| 444 | buff_step); |
| 445 | snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, |
| 446 | buff_step); |
Takashi Iwai | cc72da7 | 2015-02-19 16:00:22 +0100 | [diff] [blame] | 447 | snd_hda_power_up(apcm->codec); |
Takashi Iwai | 61ca410 | 2015-02-27 17:57:55 +0100 | [diff] [blame] | 448 | if (hinfo->ops.open) |
| 449 | err = hinfo->ops.open(hinfo, apcm->codec, substream); |
| 450 | else |
| 451 | err = -ENODEV; |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 452 | if (err < 0) { |
| 453 | azx_release_device(azx_dev); |
Takashi Iwai | 61ca410 | 2015-02-27 17:57:55 +0100 | [diff] [blame] | 454 | goto powerdown; |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 455 | } |
| 456 | snd_pcm_limit_hw_rates(runtime); |
| 457 | /* sanity check */ |
| 458 | if (snd_BUG_ON(!runtime->hw.channels_min) || |
| 459 | snd_BUG_ON(!runtime->hw.channels_max) || |
| 460 | snd_BUG_ON(!runtime->hw.formats) || |
| 461 | snd_BUG_ON(!runtime->hw.rates)) { |
| 462 | azx_release_device(azx_dev); |
Takashi Iwai | 61ca410 | 2015-02-27 17:57:55 +0100 | [diff] [blame] | 463 | if (hinfo->ops.close) |
| 464 | hinfo->ops.close(hinfo, apcm->codec, substream); |
| 465 | err = -EINVAL; |
| 466 | goto powerdown; |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 467 | } |
| 468 | |
Pierre-Louis Bossart | 9e94df3 | 2015-02-13 15:14:07 -0600 | [diff] [blame] | 469 | /* disable LINK_ATIME timestamps for capture streams |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 470 | until we figure out how to handle digital inputs */ |
Pierre-Louis Bossart | 9e94df3 | 2015-02-13 15:14:07 -0600 | [diff] [blame] | 471 | if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) { |
| 472 | runtime->hw.info &= ~SNDRV_PCM_INFO_HAS_WALL_CLOCK; /* legacy */ |
| 473 | runtime->hw.info &= ~SNDRV_PCM_INFO_HAS_LINK_ATIME; |
| 474 | } |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 475 | |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 476 | snd_pcm_set_sync(substream); |
| 477 | mutex_unlock(&chip->open_mutex); |
| 478 | return 0; |
Takashi Iwai | 61ca410 | 2015-02-27 17:57:55 +0100 | [diff] [blame] | 479 | |
| 480 | powerdown: |
| 481 | snd_hda_power_down(apcm->codec); |
| 482 | unlock: |
| 483 | mutex_unlock(&chip->open_mutex); |
Takashi Iwai | 9a6246f | 2015-02-27 18:17:28 +0100 | [diff] [blame] | 484 | snd_hda_codec_pcm_put(apcm->info); |
Takashi Iwai | 61ca410 | 2015-02-27 17:57:55 +0100 | [diff] [blame] | 485 | return err; |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 486 | } |
| 487 | |
| 488 | static int azx_pcm_mmap(struct snd_pcm_substream *substream, |
| 489 | struct vm_area_struct *area) |
| 490 | { |
| 491 | struct azx_pcm *apcm = snd_pcm_substream_chip(substream); |
| 492 | struct azx *chip = apcm->chip; |
| 493 | if (chip->ops->pcm_mmap_prepare) |
| 494 | chip->ops->pcm_mmap_prepare(substream, area); |
| 495 | return snd_pcm_lib_default_mmap(substream, area); |
| 496 | } |
| 497 | |
| 498 | static struct snd_pcm_ops azx_pcm_ops = { |
| 499 | .open = azx_pcm_open, |
| 500 | .close = azx_pcm_close, |
| 501 | .ioctl = snd_pcm_lib_ioctl, |
| 502 | .hw_params = azx_pcm_hw_params, |
| 503 | .hw_free = azx_pcm_hw_free, |
| 504 | .prepare = azx_pcm_prepare, |
| 505 | .trigger = azx_pcm_trigger, |
| 506 | .pointer = azx_pcm_pointer, |
Pierre-Louis Bossart | 9e94df3 | 2015-02-13 15:14:07 -0600 | [diff] [blame] | 507 | .get_time_info = azx_get_time_info, |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 508 | .mmap = azx_pcm_mmap, |
| 509 | .page = snd_pcm_sgbuf_ops_page, |
| 510 | }; |
| 511 | |
| 512 | static void azx_pcm_free(struct snd_pcm *pcm) |
| 513 | { |
| 514 | struct azx_pcm *apcm = pcm->private_data; |
| 515 | if (apcm) { |
| 516 | list_del(&apcm->list); |
Takashi Iwai | 820cc6c | 2015-02-20 12:50:46 +0100 | [diff] [blame] | 517 | apcm->info->pcm = NULL; |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 518 | kfree(apcm); |
| 519 | } |
| 520 | } |
| 521 | |
| 522 | #define MAX_PREALLOC_SIZE (32 * 1024 * 1024) |
| 523 | |
Takashi Iwai | 0a50575 | 2015-04-16 23:25:02 +0200 | [diff] [blame] | 524 | int snd_hda_attach_pcm_stream(struct hda_bus *_bus, struct hda_codec *codec, |
| 525 | struct hda_pcm *cpcm) |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 526 | { |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 527 | struct hdac_bus *bus = &_bus->core; |
| 528 | struct azx *chip = bus_to_azx(bus); |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 529 | struct snd_pcm *pcm; |
| 530 | struct azx_pcm *apcm; |
| 531 | int pcm_dev = cpcm->device; |
| 532 | unsigned int size; |
| 533 | int s, err; |
| 534 | |
| 535 | list_for_each_entry(apcm, &chip->pcm_list, list) { |
| 536 | if (apcm->pcm->device == pcm_dev) { |
| 537 | dev_err(chip->card->dev, "PCM %d already exists\n", |
| 538 | pcm_dev); |
| 539 | return -EBUSY; |
| 540 | } |
| 541 | } |
| 542 | err = snd_pcm_new(chip->card, cpcm->name, pcm_dev, |
| 543 | cpcm->stream[SNDRV_PCM_STREAM_PLAYBACK].substreams, |
| 544 | cpcm->stream[SNDRV_PCM_STREAM_CAPTURE].substreams, |
| 545 | &pcm); |
| 546 | if (err < 0) |
| 547 | return err; |
| 548 | strlcpy(pcm->name, cpcm->name, sizeof(pcm->name)); |
| 549 | apcm = kzalloc(sizeof(*apcm), GFP_KERNEL); |
| 550 | if (apcm == NULL) |
| 551 | return -ENOMEM; |
| 552 | apcm->chip = chip; |
| 553 | apcm->pcm = pcm; |
| 554 | apcm->codec = codec; |
Takashi Iwai | 820cc6c | 2015-02-20 12:50:46 +0100 | [diff] [blame] | 555 | apcm->info = cpcm; |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 556 | pcm->private_data = apcm; |
| 557 | pcm->private_free = azx_pcm_free; |
| 558 | if (cpcm->pcm_type == HDA_PCM_TYPE_MODEM) |
| 559 | pcm->dev_class = SNDRV_PCM_CLASS_MODEM; |
| 560 | list_add_tail(&apcm->list, &chip->pcm_list); |
| 561 | cpcm->pcm = pcm; |
| 562 | for (s = 0; s < 2; s++) { |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 563 | if (cpcm->stream[s].substreams) |
| 564 | snd_pcm_set_ops(pcm, s, &azx_pcm_ops); |
| 565 | } |
| 566 | /* buffer pre-allocation */ |
| 567 | size = CONFIG_SND_HDA_PREALLOC_SIZE * 1024; |
| 568 | if (size > MAX_PREALLOC_SIZE) |
| 569 | size = MAX_PREALLOC_SIZE; |
| 570 | snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG, |
| 571 | chip->card->dev, |
| 572 | size, MAX_PREALLOC_SIZE); |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 573 | return 0; |
| 574 | } |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame] | 575 | |
Dylan Reid | 6e85ddd | 2014-02-28 15:41:25 -0800 | [diff] [blame] | 576 | static unsigned int azx_command_addr(u32 cmd) |
| 577 | { |
| 578 | unsigned int addr = cmd >> 28; |
| 579 | |
| 580 | if (addr >= AZX_MAX_CODECS) { |
| 581 | snd_BUG(); |
| 582 | addr = 0; |
| 583 | } |
| 584 | |
| 585 | return addr; |
| 586 | } |
| 587 | |
Dylan Reid | 6e85ddd | 2014-02-28 15:41:25 -0800 | [diff] [blame] | 588 | /* receive a response */ |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 589 | static int azx_rirb_get_response(struct hdac_bus *bus, unsigned int addr, |
Takashi Iwai | cad372f | 2015-03-25 17:57:00 +0100 | [diff] [blame] | 590 | unsigned int *res) |
Dylan Reid | 6e85ddd | 2014-02-28 15:41:25 -0800 | [diff] [blame] | 591 | { |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 592 | struct azx *chip = bus_to_azx(bus); |
| 593 | struct hda_bus *hbus = &chip->bus; |
Dylan Reid | 6e85ddd | 2014-02-28 15:41:25 -0800 | [diff] [blame] | 594 | unsigned long timeout; |
| 595 | unsigned long loopcounter; |
| 596 | int do_poll = 0; |
| 597 | |
| 598 | again: |
| 599 | timeout = jiffies + msecs_to_jiffies(1000); |
| 600 | |
| 601 | for (loopcounter = 0;; loopcounter++) { |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 602 | spin_lock_irq(&bus->reg_lock); |
| 603 | if (chip->polling_mode || do_poll) |
| 604 | snd_hdac_bus_update_rirb(bus); |
| 605 | if (!bus->rirb.cmds[addr]) { |
Dylan Reid | 6e85ddd | 2014-02-28 15:41:25 -0800 | [diff] [blame] | 606 | if (!do_poll) |
| 607 | chip->poll_count = 0; |
Takashi Iwai | cad372f | 2015-03-25 17:57:00 +0100 | [diff] [blame] | 608 | if (res) |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 609 | *res = bus->rirb.res[addr]; /* the last value */ |
| 610 | spin_unlock_irq(&bus->reg_lock); |
Takashi Iwai | cad372f | 2015-03-25 17:57:00 +0100 | [diff] [blame] | 611 | return 0; |
Dylan Reid | 6e85ddd | 2014-02-28 15:41:25 -0800 | [diff] [blame] | 612 | } |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 613 | spin_unlock_irq(&bus->reg_lock); |
Dylan Reid | 6e85ddd | 2014-02-28 15:41:25 -0800 | [diff] [blame] | 614 | if (time_after(jiffies, timeout)) |
| 615 | break; |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 616 | if (hbus->needs_damn_long_delay || loopcounter > 3000) |
Dylan Reid | 6e85ddd | 2014-02-28 15:41:25 -0800 | [diff] [blame] | 617 | msleep(2); /* temporary workaround */ |
| 618 | else { |
| 619 | udelay(10); |
| 620 | cond_resched(); |
| 621 | } |
| 622 | } |
| 623 | |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 624 | if (hbus->no_response_fallback) |
Takashi Iwai | cad372f | 2015-03-25 17:57:00 +0100 | [diff] [blame] | 625 | return -EIO; |
Dylan Reid | 6e85ddd | 2014-02-28 15:41:25 -0800 | [diff] [blame] | 626 | |
| 627 | if (!chip->polling_mode && chip->poll_count < 2) { |
| 628 | dev_dbg(chip->card->dev, |
| 629 | "azx_get_response timeout, polling the codec once: last cmd=0x%08x\n", |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 630 | bus->last_cmd[addr]); |
Dylan Reid | 6e85ddd | 2014-02-28 15:41:25 -0800 | [diff] [blame] | 631 | do_poll = 1; |
| 632 | chip->poll_count++; |
| 633 | goto again; |
| 634 | } |
| 635 | |
| 636 | |
| 637 | if (!chip->polling_mode) { |
| 638 | dev_warn(chip->card->dev, |
| 639 | "azx_get_response timeout, switching to polling mode: last cmd=0x%08x\n", |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 640 | bus->last_cmd[addr]); |
Dylan Reid | 6e85ddd | 2014-02-28 15:41:25 -0800 | [diff] [blame] | 641 | chip->polling_mode = 1; |
| 642 | goto again; |
| 643 | } |
| 644 | |
| 645 | if (chip->msi) { |
| 646 | dev_warn(chip->card->dev, |
| 647 | "No response from codec, disabling MSI: last cmd=0x%08x\n", |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 648 | bus->last_cmd[addr]); |
| 649 | if (chip->ops->disable_msi_reset_irq && |
Takashi Iwai | cad372f | 2015-03-25 17:57:00 +0100 | [diff] [blame] | 650 | chip->ops->disable_msi_reset_irq(chip) < 0) |
| 651 | return -EIO; |
Dylan Reid | 6e85ddd | 2014-02-28 15:41:25 -0800 | [diff] [blame] | 652 | goto again; |
| 653 | } |
| 654 | |
| 655 | if (chip->probing) { |
| 656 | /* If this critical timeout happens during the codec probing |
| 657 | * phase, this is likely an access to a non-existing codec |
| 658 | * slot. Better to return an error and reset the system. |
| 659 | */ |
Takashi Iwai | cad372f | 2015-03-25 17:57:00 +0100 | [diff] [blame] | 660 | return -EIO; |
Dylan Reid | 6e85ddd | 2014-02-28 15:41:25 -0800 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | /* a fatal communication error; need either to reset or to fallback |
| 664 | * to the single_cmd mode |
| 665 | */ |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 666 | if (hbus->allow_bus_reset && !hbus->response_reset && !hbus->in_reset) { |
| 667 | hbus->response_reset = 1; |
Takashi Iwai | cad372f | 2015-03-25 17:57:00 +0100 | [diff] [blame] | 668 | return -EAGAIN; /* give a chance to retry */ |
Dylan Reid | 6e85ddd | 2014-02-28 15:41:25 -0800 | [diff] [blame] | 669 | } |
| 670 | |
| 671 | dev_err(chip->card->dev, |
| 672 | "azx_get_response timeout, switching to single_cmd mode: last cmd=0x%08x\n", |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 673 | bus->last_cmd[addr]); |
Dylan Reid | 6e85ddd | 2014-02-28 15:41:25 -0800 | [diff] [blame] | 674 | chip->single_cmd = 1; |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 675 | hbus->response_reset = 0; |
| 676 | snd_hdac_bus_stop_cmd_io(bus); |
Takashi Iwai | cad372f | 2015-03-25 17:57:00 +0100 | [diff] [blame] | 677 | return -EIO; |
Dylan Reid | 6e85ddd | 2014-02-28 15:41:25 -0800 | [diff] [blame] | 678 | } |
| 679 | |
| 680 | /* |
| 681 | * Use the single immediate command instead of CORB/RIRB for simplicity |
| 682 | * |
| 683 | * Note: according to Intel, this is not preferred use. The command was |
| 684 | * intended for the BIOS only, and may get confused with unsolicited |
| 685 | * responses. So, we shouldn't use it for normal operation from the |
| 686 | * driver. |
| 687 | * I left the codes, however, for debugging/testing purposes. |
| 688 | */ |
| 689 | |
| 690 | /* receive a response */ |
| 691 | static int azx_single_wait_for_response(struct azx *chip, unsigned int addr) |
| 692 | { |
| 693 | int timeout = 50; |
| 694 | |
| 695 | while (timeout--) { |
| 696 | /* check IRV busy bit */ |
Takashi Iwai | fb1d8ac | 2014-06-26 17:54:37 +0200 | [diff] [blame] | 697 | if (azx_readw(chip, IRS) & AZX_IRS_VALID) { |
Dylan Reid | 6e85ddd | 2014-02-28 15:41:25 -0800 | [diff] [blame] | 698 | /* reuse rirb.res as the response return value */ |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 699 | azx_bus(chip)->rirb.res[addr] = azx_readl(chip, IR); |
Dylan Reid | 6e85ddd | 2014-02-28 15:41:25 -0800 | [diff] [blame] | 700 | return 0; |
| 701 | } |
| 702 | udelay(1); |
| 703 | } |
| 704 | if (printk_ratelimit()) |
| 705 | dev_dbg(chip->card->dev, "get_response timeout: IRS=0x%x\n", |
| 706 | azx_readw(chip, IRS)); |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 707 | azx_bus(chip)->rirb.res[addr] = -1; |
Dylan Reid | 6e85ddd | 2014-02-28 15:41:25 -0800 | [diff] [blame] | 708 | return -EIO; |
| 709 | } |
| 710 | |
| 711 | /* send a command */ |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 712 | static int azx_single_send_cmd(struct hdac_bus *bus, u32 val) |
Dylan Reid | 6e85ddd | 2014-02-28 15:41:25 -0800 | [diff] [blame] | 713 | { |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 714 | struct azx *chip = bus_to_azx(bus); |
Dylan Reid | 6e85ddd | 2014-02-28 15:41:25 -0800 | [diff] [blame] | 715 | unsigned int addr = azx_command_addr(val); |
| 716 | int timeout = 50; |
| 717 | |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 718 | bus->last_cmd[azx_command_addr(val)] = val; |
Dylan Reid | 6e85ddd | 2014-02-28 15:41:25 -0800 | [diff] [blame] | 719 | while (timeout--) { |
| 720 | /* check ICB busy bit */ |
Takashi Iwai | fb1d8ac | 2014-06-26 17:54:37 +0200 | [diff] [blame] | 721 | if (!((azx_readw(chip, IRS) & AZX_IRS_BUSY))) { |
Dylan Reid | 6e85ddd | 2014-02-28 15:41:25 -0800 | [diff] [blame] | 722 | /* Clear IRV valid bit */ |
| 723 | azx_writew(chip, IRS, azx_readw(chip, IRS) | |
Takashi Iwai | fb1d8ac | 2014-06-26 17:54:37 +0200 | [diff] [blame] | 724 | AZX_IRS_VALID); |
Dylan Reid | 6e85ddd | 2014-02-28 15:41:25 -0800 | [diff] [blame] | 725 | azx_writel(chip, IC, val); |
| 726 | azx_writew(chip, IRS, azx_readw(chip, IRS) | |
Takashi Iwai | fb1d8ac | 2014-06-26 17:54:37 +0200 | [diff] [blame] | 727 | AZX_IRS_BUSY); |
Dylan Reid | 6e85ddd | 2014-02-28 15:41:25 -0800 | [diff] [blame] | 728 | return azx_single_wait_for_response(chip, addr); |
| 729 | } |
| 730 | udelay(1); |
| 731 | } |
| 732 | if (printk_ratelimit()) |
| 733 | dev_dbg(chip->card->dev, |
| 734 | "send_cmd timeout: IRS=0x%x, val=0x%x\n", |
| 735 | azx_readw(chip, IRS), val); |
| 736 | return -EIO; |
| 737 | } |
| 738 | |
| 739 | /* receive a response */ |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 740 | static int azx_single_get_response(struct hdac_bus *bus, unsigned int addr, |
Takashi Iwai | cad372f | 2015-03-25 17:57:00 +0100 | [diff] [blame] | 741 | unsigned int *res) |
Dylan Reid | 6e85ddd | 2014-02-28 15:41:25 -0800 | [diff] [blame] | 742 | { |
Takashi Iwai | cad372f | 2015-03-25 17:57:00 +0100 | [diff] [blame] | 743 | if (res) |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 744 | *res = bus->rirb.res[addr]; |
Takashi Iwai | cad372f | 2015-03-25 17:57:00 +0100 | [diff] [blame] | 745 | return 0; |
Dylan Reid | 6e85ddd | 2014-02-28 15:41:25 -0800 | [diff] [blame] | 746 | } |
| 747 | |
| 748 | /* |
| 749 | * The below are the main callbacks from hda_codec. |
| 750 | * |
| 751 | * They are just the skeleton to call sub-callbacks according to the |
| 752 | * current setting of chip->single_cmd. |
| 753 | */ |
| 754 | |
| 755 | /* send a command */ |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 756 | static int azx_send_cmd(struct hdac_bus *bus, unsigned int val) |
Dylan Reid | 6e85ddd | 2014-02-28 15:41:25 -0800 | [diff] [blame] | 757 | { |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 758 | struct azx *chip = bus_to_azx(bus); |
Dylan Reid | 6e85ddd | 2014-02-28 15:41:25 -0800 | [diff] [blame] | 759 | |
| 760 | if (chip->disabled) |
| 761 | return 0; |
Dylan Reid | 6e85ddd | 2014-02-28 15:41:25 -0800 | [diff] [blame] | 762 | if (chip->single_cmd) |
| 763 | return azx_single_send_cmd(bus, val); |
| 764 | else |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 765 | return snd_hdac_bus_send_cmd(bus, val); |
Dylan Reid | 6e85ddd | 2014-02-28 15:41:25 -0800 | [diff] [blame] | 766 | } |
Dylan Reid | 6e85ddd | 2014-02-28 15:41:25 -0800 | [diff] [blame] | 767 | |
| 768 | /* get a response */ |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 769 | static int azx_get_response(struct hdac_bus *bus, unsigned int addr, |
Takashi Iwai | cad372f | 2015-03-25 17:57:00 +0100 | [diff] [blame] | 770 | unsigned int *res) |
Dylan Reid | 6e85ddd | 2014-02-28 15:41:25 -0800 | [diff] [blame] | 771 | { |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 772 | struct azx *chip = bus_to_azx(bus); |
| 773 | |
Dylan Reid | 6e85ddd | 2014-02-28 15:41:25 -0800 | [diff] [blame] | 774 | if (chip->disabled) |
| 775 | return 0; |
| 776 | if (chip->single_cmd) |
Takashi Iwai | cad372f | 2015-03-25 17:57:00 +0100 | [diff] [blame] | 777 | return azx_single_get_response(bus, addr, res); |
Dylan Reid | 6e85ddd | 2014-02-28 15:41:25 -0800 | [diff] [blame] | 778 | else |
Takashi Iwai | cad372f | 2015-03-25 17:57:00 +0100 | [diff] [blame] | 779 | return azx_rirb_get_response(bus, addr, res); |
Dylan Reid | 6e85ddd | 2014-02-28 15:41:25 -0800 | [diff] [blame] | 780 | } |
Dylan Reid | 6e85ddd | 2014-02-28 15:41:25 -0800 | [diff] [blame] | 781 | |
Mengdong Lin | 17eccb2 | 2015-04-29 17:43:29 +0800 | [diff] [blame] | 782 | static int azx_link_power(struct hdac_bus *bus, bool enable) |
| 783 | { |
| 784 | struct azx *chip = bus_to_azx(bus); |
| 785 | |
| 786 | if (chip->ops->link_power) |
| 787 | return chip->ops->link_power(chip, enable); |
| 788 | else |
| 789 | return -EINVAL; |
| 790 | } |
| 791 | |
Takashi Iwai | 7e8be1b | 2015-04-14 16:55:31 +0200 | [diff] [blame] | 792 | static const struct hdac_bus_ops bus_core_ops = { |
| 793 | .command = azx_send_cmd, |
| 794 | .get_response = azx_get_response, |
Mengdong Lin | 17eccb2 | 2015-04-29 17:43:29 +0800 | [diff] [blame] | 795 | .link_power = azx_link_power, |
Takashi Iwai | 7e8be1b | 2015-04-14 16:55:31 +0200 | [diff] [blame] | 796 | }; |
| 797 | |
Dylan Reid | 2b5fd6c | 2014-02-28 15:41:24 -0800 | [diff] [blame] | 798 | #ifdef CONFIG_SND_HDA_DSP_LOADER |
| 799 | /* |
| 800 | * DSP loading code (e.g. for CA0132) |
| 801 | */ |
| 802 | |
| 803 | /* use the first stream for loading DSP */ |
| 804 | static struct azx_dev * |
| 805 | azx_get_dsp_loader_dev(struct azx *chip) |
| 806 | { |
Takashi Iwai | 7833c3f | 2015-04-14 18:13:13 +0200 | [diff] [blame] | 807 | struct hdac_bus *bus = azx_bus(chip); |
| 808 | struct hdac_stream *s; |
| 809 | |
| 810 | list_for_each_entry(s, &bus->stream_list, list) |
| 811 | if (s->index == chip->playback_index_offset) |
| 812 | return stream_to_azx_dev(s); |
| 813 | |
| 814 | return NULL; |
Dylan Reid | 2b5fd6c | 2014-02-28 15:41:24 -0800 | [diff] [blame] | 815 | } |
| 816 | |
Takashi Iwai | 0a50575 | 2015-04-16 23:25:02 +0200 | [diff] [blame] | 817 | int snd_hda_codec_load_dsp_prepare(struct hda_codec *codec, unsigned int format, |
| 818 | unsigned int byte_size, |
| 819 | struct snd_dma_buffer *bufp) |
Dylan Reid | 2b5fd6c | 2014-02-28 15:41:24 -0800 | [diff] [blame] | 820 | { |
Takashi Iwai | 0a50575 | 2015-04-16 23:25:02 +0200 | [diff] [blame] | 821 | struct hdac_bus *bus = &codec->bus->core; |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 822 | struct azx *chip = bus_to_azx(bus); |
Dylan Reid | 2b5fd6c | 2014-02-28 15:41:24 -0800 | [diff] [blame] | 823 | struct azx_dev *azx_dev; |
Takashi Iwai | ccc9886 | 2015-04-14 22:06:53 +0200 | [diff] [blame] | 824 | struct hdac_stream *hstr; |
| 825 | bool saved = false; |
Dylan Reid | 2b5fd6c | 2014-02-28 15:41:24 -0800 | [diff] [blame] | 826 | int err; |
| 827 | |
| 828 | azx_dev = azx_get_dsp_loader_dev(chip); |
Takashi Iwai | ccc9886 | 2015-04-14 22:06:53 +0200 | [diff] [blame] | 829 | hstr = azx_stream(azx_dev); |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 830 | spin_lock_irq(&bus->reg_lock); |
Takashi Iwai | ccc9886 | 2015-04-14 22:06:53 +0200 | [diff] [blame] | 831 | if (hstr->opened) { |
| 832 | chip->saved_azx_dev = *azx_dev; |
| 833 | saved = true; |
Dylan Reid | 2b5fd6c | 2014-02-28 15:41:24 -0800 | [diff] [blame] | 834 | } |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 835 | spin_unlock_irq(&bus->reg_lock); |
Takashi Iwai | ccc9886 | 2015-04-14 22:06:53 +0200 | [diff] [blame] | 836 | |
| 837 | err = snd_hdac_dsp_prepare(hstr, format, byte_size, bufp); |
| 838 | if (err < 0) { |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 839 | spin_lock_irq(&bus->reg_lock); |
Takashi Iwai | ccc9886 | 2015-04-14 22:06:53 +0200 | [diff] [blame] | 840 | if (saved) |
| 841 | *azx_dev = chip->saved_azx_dev; |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 842 | spin_unlock_irq(&bus->reg_lock); |
Takashi Iwai | ccc9886 | 2015-04-14 22:06:53 +0200 | [diff] [blame] | 843 | return err; |
| 844 | } |
| 845 | |
Takashi Iwai | 6d23c8f | 2015-04-17 13:34:30 +0200 | [diff] [blame] | 846 | hstr->prepared = 0; |
Dylan Reid | 2b5fd6c | 2014-02-28 15:41:24 -0800 | [diff] [blame] | 847 | return err; |
| 848 | } |
Takashi Iwai | 0a50575 | 2015-04-16 23:25:02 +0200 | [diff] [blame] | 849 | EXPORT_SYMBOL_GPL(snd_hda_codec_load_dsp_prepare); |
Dylan Reid | 2b5fd6c | 2014-02-28 15:41:24 -0800 | [diff] [blame] | 850 | |
Takashi Iwai | 0a50575 | 2015-04-16 23:25:02 +0200 | [diff] [blame] | 851 | void snd_hda_codec_load_dsp_trigger(struct hda_codec *codec, bool start) |
Dylan Reid | 2b5fd6c | 2014-02-28 15:41:24 -0800 | [diff] [blame] | 852 | { |
Takashi Iwai | 0a50575 | 2015-04-16 23:25:02 +0200 | [diff] [blame] | 853 | struct hdac_bus *bus = &codec->bus->core; |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 854 | struct azx *chip = bus_to_azx(bus); |
Dylan Reid | 2b5fd6c | 2014-02-28 15:41:24 -0800 | [diff] [blame] | 855 | struct azx_dev *azx_dev = azx_get_dsp_loader_dev(chip); |
| 856 | |
Takashi Iwai | ccc9886 | 2015-04-14 22:06:53 +0200 | [diff] [blame] | 857 | snd_hdac_dsp_trigger(azx_stream(azx_dev), start); |
Dylan Reid | 2b5fd6c | 2014-02-28 15:41:24 -0800 | [diff] [blame] | 858 | } |
Takashi Iwai | 0a50575 | 2015-04-16 23:25:02 +0200 | [diff] [blame] | 859 | EXPORT_SYMBOL_GPL(snd_hda_codec_load_dsp_trigger); |
Dylan Reid | 2b5fd6c | 2014-02-28 15:41:24 -0800 | [diff] [blame] | 860 | |
Takashi Iwai | 0a50575 | 2015-04-16 23:25:02 +0200 | [diff] [blame] | 861 | void snd_hda_codec_load_dsp_cleanup(struct hda_codec *codec, |
| 862 | struct snd_dma_buffer *dmab) |
Dylan Reid | 2b5fd6c | 2014-02-28 15:41:24 -0800 | [diff] [blame] | 863 | { |
Takashi Iwai | 0a50575 | 2015-04-16 23:25:02 +0200 | [diff] [blame] | 864 | struct hdac_bus *bus = &codec->bus->core; |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 865 | struct azx *chip = bus_to_azx(bus); |
Dylan Reid | 2b5fd6c | 2014-02-28 15:41:24 -0800 | [diff] [blame] | 866 | struct azx_dev *azx_dev = azx_get_dsp_loader_dev(chip); |
Takashi Iwai | ccc9886 | 2015-04-14 22:06:53 +0200 | [diff] [blame] | 867 | struct hdac_stream *hstr = azx_stream(azx_dev); |
Dylan Reid | 2b5fd6c | 2014-02-28 15:41:24 -0800 | [diff] [blame] | 868 | |
Takashi Iwai | 0a50575 | 2015-04-16 23:25:02 +0200 | [diff] [blame] | 869 | if (!dmab->area || !hstr->locked) |
Dylan Reid | 2b5fd6c | 2014-02-28 15:41:24 -0800 | [diff] [blame] | 870 | return; |
| 871 | |
Takashi Iwai | ccc9886 | 2015-04-14 22:06:53 +0200 | [diff] [blame] | 872 | snd_hdac_dsp_cleanup(hstr, dmab); |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 873 | spin_lock_irq(&bus->reg_lock); |
Takashi Iwai | ccc9886 | 2015-04-14 22:06:53 +0200 | [diff] [blame] | 874 | if (hstr->opened) |
Dylan Reid | 2b5fd6c | 2014-02-28 15:41:24 -0800 | [diff] [blame] | 875 | *azx_dev = chip->saved_azx_dev; |
Takashi Iwai | ccc9886 | 2015-04-14 22:06:53 +0200 | [diff] [blame] | 876 | hstr->locked = false; |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 877 | spin_unlock_irq(&bus->reg_lock); |
Dylan Reid | 2b5fd6c | 2014-02-28 15:41:24 -0800 | [diff] [blame] | 878 | } |
Takashi Iwai | 0a50575 | 2015-04-16 23:25:02 +0200 | [diff] [blame] | 879 | EXPORT_SYMBOL_GPL(snd_hda_codec_load_dsp_cleanup); |
Dylan Reid | 2b5fd6c | 2014-02-28 15:41:24 -0800 | [diff] [blame] | 880 | #endif /* CONFIG_SND_HDA_DSP_LOADER */ |
| 881 | |
Dylan Reid | f43923f | 2014-02-28 15:41:27 -0800 | [diff] [blame] | 882 | /* |
| 883 | * reset and start the controller registers |
| 884 | */ |
Thierry Reding | 17c3ad0 | 2014-04-09 12:30:57 +0200 | [diff] [blame] | 885 | void azx_init_chip(struct azx *chip, bool full_reset) |
Dylan Reid | f43923f | 2014-02-28 15:41:27 -0800 | [diff] [blame] | 886 | { |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 887 | if (snd_hdac_bus_init_chip(azx_bus(chip), full_reset)) { |
| 888 | /* correct RINTCNT for CXT */ |
| 889 | if (chip->driver_caps & AZX_DCAPS_CTX_WORKAROUND) |
| 890 | azx_writew(chip, RINTCNT, 0xc0); |
| 891 | } |
Dylan Reid | f43923f | 2014-02-28 15:41:27 -0800 | [diff] [blame] | 892 | } |
| 893 | EXPORT_SYMBOL_GPL(azx_init_chip); |
| 894 | |
Takashi Iwai | 7833c3f | 2015-04-14 18:13:13 +0200 | [diff] [blame] | 895 | void azx_stop_all_streams(struct azx *chip) |
| 896 | { |
| 897 | struct hdac_bus *bus = azx_bus(chip); |
| 898 | struct hdac_stream *s; |
| 899 | |
| 900 | list_for_each_entry(s, &bus->stream_list, list) |
| 901 | snd_hdac_stream_stop(s); |
| 902 | } |
| 903 | EXPORT_SYMBOL_GPL(azx_stop_all_streams); |
| 904 | |
Dylan Reid | f43923f | 2014-02-28 15:41:27 -0800 | [diff] [blame] | 905 | void azx_stop_chip(struct azx *chip) |
| 906 | { |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 907 | snd_hdac_bus_stop_chip(azx_bus(chip)); |
Dylan Reid | f43923f | 2014-02-28 15:41:27 -0800 | [diff] [blame] | 908 | } |
Dylan Reid | 154867c | 2014-02-28 15:41:30 -0800 | [diff] [blame] | 909 | EXPORT_SYMBOL_GPL(azx_stop_chip); |
Dylan Reid | f43923f | 2014-02-28 15:41:27 -0800 | [diff] [blame] | 910 | |
Dylan Reid | f0b1df8 | 2014-02-28 15:41:29 -0800 | [diff] [blame] | 911 | /* |
| 912 | * interrupt handler |
| 913 | */ |
Takashi Iwai | 7833c3f | 2015-04-14 18:13:13 +0200 | [diff] [blame] | 914 | static void stream_update(struct hdac_bus *bus, struct hdac_stream *s) |
| 915 | { |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 916 | struct azx *chip = bus_to_azx(bus); |
Takashi Iwai | 7833c3f | 2015-04-14 18:13:13 +0200 | [diff] [blame] | 917 | struct azx_dev *azx_dev = stream_to_azx_dev(s); |
| 918 | |
| 919 | /* check whether this IRQ is really acceptable */ |
| 920 | if (!chip->ops->position_check || |
| 921 | chip->ops->position_check(chip, azx_dev)) { |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 922 | spin_unlock(&bus->reg_lock); |
| 923 | snd_pcm_period_elapsed(azx_stream(azx_dev)->substream); |
| 924 | spin_lock(&bus->reg_lock); |
Takashi Iwai | 7833c3f | 2015-04-14 18:13:13 +0200 | [diff] [blame] | 925 | } |
| 926 | } |
| 927 | |
Dylan Reid | f0b1df8 | 2014-02-28 15:41:29 -0800 | [diff] [blame] | 928 | irqreturn_t azx_interrupt(int irq, void *dev_id) |
| 929 | { |
| 930 | struct azx *chip = dev_id; |
Takashi Iwai | 7833c3f | 2015-04-14 18:13:13 +0200 | [diff] [blame] | 931 | struct hdac_bus *bus = azx_bus(chip); |
Dylan Reid | f0b1df8 | 2014-02-28 15:41:29 -0800 | [diff] [blame] | 932 | u32 status; |
Dylan Reid | f0b1df8 | 2014-02-28 15:41:29 -0800 | [diff] [blame] | 933 | |
Rafael J. Wysocki | 641d334 | 2014-12-13 00:42:18 +0100 | [diff] [blame] | 934 | #ifdef CONFIG_PM |
Takashi Iwai | 364aa71 | 2015-02-19 16:51:17 +0100 | [diff] [blame] | 935 | if (azx_has_pm_runtime(chip)) |
Dylan Reid | 7b0a48f | 2014-04-08 12:06:18 -0700 | [diff] [blame] | 936 | if (!pm_runtime_active(chip->card->dev)) |
Dylan Reid | f0b1df8 | 2014-02-28 15:41:29 -0800 | [diff] [blame] | 937 | return IRQ_NONE; |
| 938 | #endif |
| 939 | |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 940 | spin_lock(&bus->reg_lock); |
Dylan Reid | f0b1df8 | 2014-02-28 15:41:29 -0800 | [diff] [blame] | 941 | |
| 942 | if (chip->disabled) { |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 943 | spin_unlock(&bus->reg_lock); |
Dylan Reid | f0b1df8 | 2014-02-28 15:41:29 -0800 | [diff] [blame] | 944 | return IRQ_NONE; |
| 945 | } |
| 946 | |
| 947 | status = azx_readl(chip, INTSTS); |
| 948 | if (status == 0 || status == 0xffffffff) { |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 949 | spin_unlock(&bus->reg_lock); |
Dylan Reid | f0b1df8 | 2014-02-28 15:41:29 -0800 | [diff] [blame] | 950 | return IRQ_NONE; |
| 951 | } |
| 952 | |
Takashi Iwai | 7833c3f | 2015-04-14 18:13:13 +0200 | [diff] [blame] | 953 | snd_hdac_bus_handle_stream_irq(bus, status, stream_update); |
Dylan Reid | f0b1df8 | 2014-02-28 15:41:29 -0800 | [diff] [blame] | 954 | |
| 955 | /* clear rirb int */ |
| 956 | status = azx_readb(chip, RIRBSTS); |
| 957 | if (status & RIRB_INT_MASK) { |
| 958 | if (status & RIRB_INT_RESPONSE) { |
| 959 | if (chip->driver_caps & AZX_DCAPS_RIRB_PRE_DELAY) |
| 960 | udelay(80); |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 961 | snd_hdac_bus_update_rirb(bus); |
Dylan Reid | f0b1df8 | 2014-02-28 15:41:29 -0800 | [diff] [blame] | 962 | } |
| 963 | azx_writeb(chip, RIRBSTS, RIRB_INT_MASK); |
| 964 | } |
| 965 | |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 966 | spin_unlock(&bus->reg_lock); |
Dylan Reid | f0b1df8 | 2014-02-28 15:41:29 -0800 | [diff] [blame] | 967 | |
| 968 | return IRQ_HANDLED; |
| 969 | } |
| 970 | EXPORT_SYMBOL_GPL(azx_interrupt); |
| 971 | |
Dylan Reid | 154867c | 2014-02-28 15:41:30 -0800 | [diff] [blame] | 972 | /* |
| 973 | * Codec initerface |
| 974 | */ |
| 975 | |
| 976 | /* |
| 977 | * Probe the given codec address |
| 978 | */ |
| 979 | static int probe_codec(struct azx *chip, int addr) |
| 980 | { |
| 981 | unsigned int cmd = (addr << 28) | (AC_NODE_ROOT << 20) | |
| 982 | (AC_VERB_PARAMETERS << 8) | AC_PAR_VENDOR_ID; |
Takashi Iwai | 7833c3f | 2015-04-14 18:13:13 +0200 | [diff] [blame] | 983 | struct hdac_bus *bus = azx_bus(chip); |
Takashi Iwai | cad372f | 2015-03-25 17:57:00 +0100 | [diff] [blame] | 984 | int err; |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 985 | unsigned int res = -1; |
Dylan Reid | 154867c | 2014-02-28 15:41:30 -0800 | [diff] [blame] | 986 | |
Takashi Iwai | 7e8be1b | 2015-04-14 16:55:31 +0200 | [diff] [blame] | 987 | mutex_lock(&bus->cmd_mutex); |
Dylan Reid | 154867c | 2014-02-28 15:41:30 -0800 | [diff] [blame] | 988 | chip->probing = 1; |
Takashi Iwai | 7e8be1b | 2015-04-14 16:55:31 +0200 | [diff] [blame] | 989 | azx_send_cmd(bus, cmd); |
| 990 | err = azx_get_response(bus, addr, &res); |
Dylan Reid | 154867c | 2014-02-28 15:41:30 -0800 | [diff] [blame] | 991 | chip->probing = 0; |
Takashi Iwai | 7e8be1b | 2015-04-14 16:55:31 +0200 | [diff] [blame] | 992 | mutex_unlock(&bus->cmd_mutex); |
Takashi Iwai | cad372f | 2015-03-25 17:57:00 +0100 | [diff] [blame] | 993 | if (err < 0 || res == -1) |
Dylan Reid | 154867c | 2014-02-28 15:41:30 -0800 | [diff] [blame] | 994 | return -EIO; |
| 995 | dev_dbg(chip->card->dev, "codec #%d probed OK\n", addr); |
| 996 | return 0; |
| 997 | } |
| 998 | |
Takashi Iwai | 0a50575 | 2015-04-16 23:25:02 +0200 | [diff] [blame] | 999 | void snd_hda_bus_reset(struct hda_bus *bus) |
Dylan Reid | 154867c | 2014-02-28 15:41:30 -0800 | [diff] [blame] | 1000 | { |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 1001 | struct azx *chip = bus_to_azx(&bus->core); |
Dylan Reid | 154867c | 2014-02-28 15:41:30 -0800 | [diff] [blame] | 1002 | |
| 1003 | bus->in_reset = 1; |
| 1004 | azx_stop_chip(chip); |
Thierry Reding | 17c3ad0 | 2014-04-09 12:30:57 +0200 | [diff] [blame] | 1005 | azx_init_chip(chip, true); |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 1006 | if (bus->core.chip_init) |
Takashi Iwai | 0a50575 | 2015-04-16 23:25:02 +0200 | [diff] [blame] | 1007 | snd_hda_bus_reset_codecs(bus); |
Dylan Reid | 154867c | 2014-02-28 15:41:30 -0800 | [diff] [blame] | 1008 | bus->in_reset = 0; |
| 1009 | } |
| 1010 | |
Dylan Reid | 154867c | 2014-02-28 15:41:30 -0800 | [diff] [blame] | 1011 | static int get_jackpoll_interval(struct azx *chip) |
| 1012 | { |
| 1013 | int i; |
| 1014 | unsigned int j; |
| 1015 | |
| 1016 | if (!chip->jackpoll_ms) |
| 1017 | return 0; |
| 1018 | |
| 1019 | i = chip->jackpoll_ms[chip->dev_index]; |
| 1020 | if (i == 0) |
| 1021 | return 0; |
| 1022 | if (i < 50 || i > 60000) |
| 1023 | j = 0; |
| 1024 | else |
| 1025 | j = msecs_to_jiffies(i); |
| 1026 | if (j == 0) |
| 1027 | dev_warn(chip->card->dev, |
| 1028 | "jackpoll_ms value out of range: %d\n", i); |
| 1029 | return j; |
| 1030 | } |
| 1031 | |
Takashi Iwai | 96d2bd6 | 2015-02-19 18:12:22 +0100 | [diff] [blame] | 1032 | /* HD-audio bus initialization */ |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 1033 | int azx_bus_init(struct azx *chip, const char *model, |
| 1034 | const struct hdac_io_ops *io_ops) |
Dylan Reid | 154867c | 2014-02-28 15:41:30 -0800 | [diff] [blame] | 1035 | { |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 1036 | struct hda_bus *bus = &chip->bus; |
Takashi Iwai | 96d2bd6 | 2015-02-19 18:12:22 +0100 | [diff] [blame] | 1037 | int err; |
Dylan Reid | 154867c | 2014-02-28 15:41:30 -0800 | [diff] [blame] | 1038 | |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 1039 | err = snd_hdac_bus_init(&bus->core, chip->card->dev, &bus_core_ops, |
| 1040 | io_ops); |
Dylan Reid | 154867c | 2014-02-28 15:41:30 -0800 | [diff] [blame] | 1041 | if (err < 0) |
| 1042 | return err; |
| 1043 | |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 1044 | bus->card = chip->card; |
| 1045 | mutex_init(&bus->prepare_mutex); |
Takashi Iwai | ef74497 | 2015-02-17 13:56:29 +0100 | [diff] [blame] | 1046 | bus->pci = chip->pci; |
| 1047 | bus->modelname = model; |
Takashi Iwai | ccc9886 | 2015-04-14 22:06:53 +0200 | [diff] [blame] | 1048 | bus->core.snoop = azx_snoop(chip); |
| 1049 | if (chip->get_position[0] != azx_get_pos_lpib || |
| 1050 | chip->get_position[1] != azx_get_pos_lpib) |
| 1051 | bus->core.use_posbuf = true; |
| 1052 | if (chip->bdl_pos_adj) |
| 1053 | bus->core.bdl_pos_adj = chip->bdl_pos_adj[chip->dev_index]; |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 1054 | if (chip->driver_caps & AZX_DCAPS_CORBRP_SELF_CLEAR) |
| 1055 | bus->core.corbrp_self_clear = true; |
Takashi Iwai | ef74497 | 2015-02-17 13:56:29 +0100 | [diff] [blame] | 1056 | |
Dylan Reid | 154867c | 2014-02-28 15:41:30 -0800 | [diff] [blame] | 1057 | if (chip->driver_caps & AZX_DCAPS_RIRB_DELAY) { |
| 1058 | dev_dbg(chip->card->dev, "Enable delay in RIRB handling\n"); |
Takashi Iwai | ef74497 | 2015-02-17 13:56:29 +0100 | [diff] [blame] | 1059 | bus->needs_damn_long_delay = 1; |
Dylan Reid | 154867c | 2014-02-28 15:41:30 -0800 | [diff] [blame] | 1060 | } |
| 1061 | |
Takashi Iwai | 96d2bd6 | 2015-02-19 18:12:22 +0100 | [diff] [blame] | 1062 | /* AMD chipsets often cause the communication stalls upon certain |
| 1063 | * sequence like the pin-detection. It seems that forcing the synced |
| 1064 | * access works around the stall. Grrr... |
| 1065 | */ |
| 1066 | if (chip->driver_caps & AZX_DCAPS_SYNC_WRITE) { |
| 1067 | dev_dbg(chip->card->dev, "Enable sync_write for stable communication\n"); |
Takashi Iwai | d068ebc | 2015-03-02 23:22:59 +0100 | [diff] [blame] | 1068 | bus->core.sync_write = 1; |
Takashi Iwai | 96d2bd6 | 2015-02-19 18:12:22 +0100 | [diff] [blame] | 1069 | bus->allow_bus_reset = 1; |
| 1070 | } |
| 1071 | |
| 1072 | return 0; |
| 1073 | } |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 1074 | EXPORT_SYMBOL_GPL(azx_bus_init); |
Takashi Iwai | 96d2bd6 | 2015-02-19 18:12:22 +0100 | [diff] [blame] | 1075 | |
| 1076 | /* Probe codecs */ |
| 1077 | int azx_probe_codecs(struct azx *chip, unsigned int max_slots) |
| 1078 | { |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 1079 | struct hdac_bus *bus = azx_bus(chip); |
Takashi Iwai | 96d2bd6 | 2015-02-19 18:12:22 +0100 | [diff] [blame] | 1080 | int c, codecs, err; |
| 1081 | |
Dylan Reid | 154867c | 2014-02-28 15:41:30 -0800 | [diff] [blame] | 1082 | codecs = 0; |
| 1083 | if (!max_slots) |
| 1084 | max_slots = AZX_DEFAULT_CODECS; |
| 1085 | |
| 1086 | /* First try to probe all given codec slots */ |
| 1087 | for (c = 0; c < max_slots; c++) { |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 1088 | if ((bus->codec_mask & (1 << c)) & chip->codec_probe_mask) { |
Dylan Reid | 154867c | 2014-02-28 15:41:30 -0800 | [diff] [blame] | 1089 | if (probe_codec(chip, c) < 0) { |
| 1090 | /* Some BIOSen give you wrong codec addresses |
| 1091 | * that don't exist |
| 1092 | */ |
| 1093 | dev_warn(chip->card->dev, |
| 1094 | "Codec #%d probe error; disabling it...\n", c); |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 1095 | bus->codec_mask &= ~(1 << c); |
Dylan Reid | 154867c | 2014-02-28 15:41:30 -0800 | [diff] [blame] | 1096 | /* More badly, accessing to a non-existing |
| 1097 | * codec often screws up the controller chip, |
| 1098 | * and disturbs the further communications. |
| 1099 | * Thus if an error occurs during probing, |
| 1100 | * better to reset the controller chip to |
| 1101 | * get back to the sanity state. |
| 1102 | */ |
| 1103 | azx_stop_chip(chip); |
Thierry Reding | 17c3ad0 | 2014-04-09 12:30:57 +0200 | [diff] [blame] | 1104 | azx_init_chip(chip, true); |
Dylan Reid | 154867c | 2014-02-28 15:41:30 -0800 | [diff] [blame] | 1105 | } |
| 1106 | } |
| 1107 | } |
| 1108 | |
Dylan Reid | 154867c | 2014-02-28 15:41:30 -0800 | [diff] [blame] | 1109 | /* Then create codec instances */ |
| 1110 | for (c = 0; c < max_slots; c++) { |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 1111 | if ((bus->codec_mask & (1 << c)) & chip->codec_probe_mask) { |
Dylan Reid | 154867c | 2014-02-28 15:41:30 -0800 | [diff] [blame] | 1112 | struct hda_codec *codec; |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 1113 | err = snd_hda_codec_new(&chip->bus, chip->card, c, &codec); |
Dylan Reid | 154867c | 2014-02-28 15:41:30 -0800 | [diff] [blame] | 1114 | if (err < 0) |
| 1115 | continue; |
| 1116 | codec->jackpoll_interval = get_jackpoll_interval(chip); |
| 1117 | codec->beep_mode = chip->beep_mode; |
| 1118 | codecs++; |
| 1119 | } |
| 1120 | } |
| 1121 | if (!codecs) { |
| 1122 | dev_err(chip->card->dev, "no codecs initialized\n"); |
| 1123 | return -ENXIO; |
| 1124 | } |
| 1125 | return 0; |
| 1126 | } |
Takashi Iwai | 96d2bd6 | 2015-02-19 18:12:22 +0100 | [diff] [blame] | 1127 | EXPORT_SYMBOL_GPL(azx_probe_codecs); |
Dylan Reid | 154867c | 2014-02-28 15:41:30 -0800 | [diff] [blame] | 1128 | |
| 1129 | /* configure each codec instance */ |
| 1130 | int azx_codec_configure(struct azx *chip) |
| 1131 | { |
| 1132 | struct hda_codec *codec; |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 1133 | list_for_each_codec(codec, &chip->bus) { |
Dylan Reid | 154867c | 2014-02-28 15:41:30 -0800 | [diff] [blame] | 1134 | snd_hda_codec_configure(codec); |
| 1135 | } |
| 1136 | return 0; |
| 1137 | } |
| 1138 | EXPORT_SYMBOL_GPL(azx_codec_configure); |
| 1139 | |
Takashi Iwai | 7833c3f | 2015-04-14 18:13:13 +0200 | [diff] [blame] | 1140 | static int stream_direction(struct azx *chip, unsigned char index) |
Rafal Redzimski | 93e3423 | 2014-12-19 08:44:30 +0800 | [diff] [blame] | 1141 | { |
Takashi Iwai | 7833c3f | 2015-04-14 18:13:13 +0200 | [diff] [blame] | 1142 | if (index >= chip->capture_index_offset && |
| 1143 | index < chip->capture_index_offset + chip->capture_streams) |
| 1144 | return SNDRV_PCM_STREAM_CAPTURE; |
| 1145 | return SNDRV_PCM_STREAM_PLAYBACK; |
Rafal Redzimski | 93e3423 | 2014-12-19 08:44:30 +0800 | [diff] [blame] | 1146 | } |
| 1147 | |
Dylan Reid | 154867c | 2014-02-28 15:41:30 -0800 | [diff] [blame] | 1148 | /* initialize SD streams */ |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 1149 | int azx_init_streams(struct azx *chip) |
Dylan Reid | 154867c | 2014-02-28 15:41:30 -0800 | [diff] [blame] | 1150 | { |
| 1151 | int i; |
Takashi Iwai | 7833c3f | 2015-04-14 18:13:13 +0200 | [diff] [blame] | 1152 | int stream_tags[2] = { 0, 0 }; |
Dylan Reid | 154867c | 2014-02-28 15:41:30 -0800 | [diff] [blame] | 1153 | |
| 1154 | /* initialize each stream (aka device) |
| 1155 | * assign the starting bdl address to each stream (device) |
| 1156 | * and initialize |
| 1157 | */ |
| 1158 | for (i = 0; i < chip->num_streams; i++) { |
Takashi Iwai | 7833c3f | 2015-04-14 18:13:13 +0200 | [diff] [blame] | 1159 | struct azx_dev *azx_dev = kzalloc(sizeof(*azx_dev), GFP_KERNEL); |
| 1160 | int dir, tag; |
Rafal Redzimski | 93e3423 | 2014-12-19 08:44:30 +0800 | [diff] [blame] | 1161 | |
Takashi Iwai | 7833c3f | 2015-04-14 18:13:13 +0200 | [diff] [blame] | 1162 | if (!azx_dev) |
| 1163 | return -ENOMEM; |
| 1164 | |
| 1165 | dir = stream_direction(chip, i); |
Rafal Redzimski | 93e3423 | 2014-12-19 08:44:30 +0800 | [diff] [blame] | 1166 | /* stream tag must be unique throughout |
| 1167 | * the stream direction group, |
| 1168 | * valid values 1...15 |
| 1169 | * use separate stream tag if the flag |
| 1170 | * AZX_DCAPS_SEPARATE_STREAM_TAG is used |
| 1171 | */ |
| 1172 | if (chip->driver_caps & AZX_DCAPS_SEPARATE_STREAM_TAG) |
Takashi Iwai | 7833c3f | 2015-04-14 18:13:13 +0200 | [diff] [blame] | 1173 | tag = ++stream_tags[dir]; |
Rafal Redzimski | 93e3423 | 2014-12-19 08:44:30 +0800 | [diff] [blame] | 1174 | else |
Takashi Iwai | 7833c3f | 2015-04-14 18:13:13 +0200 | [diff] [blame] | 1175 | tag = i + 1; |
| 1176 | snd_hdac_stream_init(azx_bus(chip), azx_stream(azx_dev), |
| 1177 | i, dir, tag); |
Dylan Reid | 154867c | 2014-02-28 15:41:30 -0800 | [diff] [blame] | 1178 | } |
| 1179 | |
| 1180 | return 0; |
| 1181 | } |
Takashi Iwai | a41d122 | 2015-04-14 22:13:18 +0200 | [diff] [blame] | 1182 | EXPORT_SYMBOL_GPL(azx_init_streams); |
| 1183 | |
| 1184 | void azx_free_streams(struct azx *chip) |
| 1185 | { |
| 1186 | struct hdac_bus *bus = azx_bus(chip); |
| 1187 | struct hdac_stream *s; |
| 1188 | |
| 1189 | while (!list_empty(&bus->stream_list)) { |
| 1190 | s = list_first_entry(&bus->stream_list, struct hdac_stream, list); |
| 1191 | list_del(&s->list); |
| 1192 | kfree(stream_to_azx_dev(s)); |
| 1193 | } |
| 1194 | } |
| 1195 | EXPORT_SYMBOL_GPL(azx_free_streams); |