Lines Matching +full:no +full:- +full:read +full:- +full:rollover

1 // SPDX-License-Identifier: GPL-2.0-or-later
21 /* for art-tsc conversion */
60 return &apcm->info->stream[substream->stream]; in to_hda_pcm_stream()
70 if (!hinfo->ops.get_delay) in azx_adjust_codec_delay()
73 codec_frames = hinfo->ops.get_delay(hinfo, apcm->codec, substream); in azx_adjust_codec_delay()
75 substream->runtime->rate); in azx_adjust_codec_delay()
77 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) in azx_adjust_codec_delay()
80 return (nsec > codec_nsecs) ? nsec - codec_nsecs : 0; in azx_adjust_codec_delay()
91 struct azx *chip = apcm->chip; in azx_pcm_close()
95 mutex_lock(&chip->open_mutex); in azx_pcm_close()
97 if (hinfo->ops.close) in azx_pcm_close()
98 hinfo->ops.close(hinfo, apcm->codec, substream); in azx_pcm_close()
99 snd_hda_power_down(apcm->codec); in azx_pcm_close()
100 mutex_unlock(&chip->open_mutex); in azx_pcm_close()
101 snd_hda_codec_pcm_put(apcm->info); in azx_pcm_close()
109 struct azx *chip = apcm->chip; in azx_pcm_hw_params()
116 ret = -EBUSY; in azx_pcm_hw_params()
120 azx_dev->core.bufsize = 0; in azx_pcm_hw_params()
121 azx_dev->core.period_bytes = 0; in azx_pcm_hw_params()
122 azx_dev->core.format_val = 0; in azx_pcm_hw_params()
140 snd_hda_codec_cleanup(apcm->codec, hinfo, substream); in azx_pcm_hw_free()
142 azx_stream(azx_dev)->prepared = 0; in azx_pcm_hw_free()
150 struct azx *chip = apcm->chip; in azx_pcm_prepare()
153 struct snd_pcm_runtime *runtime = substream->runtime; in azx_pcm_prepare()
157 snd_hda_spdif_out_of_nid(apcm->codec, hinfo->nid); in azx_pcm_prepare()
158 unsigned short ctls = spdif ? spdif->ctls : 0; in azx_pcm_prepare()
163 err = -EBUSY; in azx_pcm_prepare()
168 format_val = snd_hdac_calc_stream_format(runtime->rate, in azx_pcm_prepare()
169 runtime->channels, in azx_pcm_prepare()
170 runtime->format, in azx_pcm_prepare()
171 hinfo->maxbps, in azx_pcm_prepare()
174 dev_err(chip->card->dev, in azx_pcm_prepare()
176 runtime->rate, runtime->channels, runtime->format); in azx_pcm_prepare()
177 err = -EINVAL; in azx_pcm_prepare()
187 stream_tag = azx_dev->core.stream_tag; in azx_pcm_prepare()
188 /* CA-IBG chips need the playback stream starting from 1 */ in azx_pcm_prepare()
189 if ((chip->driver_caps & AZX_DCAPS_CTX_WORKAROUND) && in azx_pcm_prepare()
190 stream_tag > chip->capture_streams) in azx_pcm_prepare()
191 stream_tag -= chip->capture_streams; in azx_pcm_prepare()
192 err = snd_hda_codec_prepare(apcm->codec, hinfo, stream_tag, in azx_pcm_prepare()
193 azx_dev->core.format_val, substream); in azx_pcm_prepare()
197 azx_stream(azx_dev)->prepared = 1; in azx_pcm_prepare()
205 struct azx *chip = apcm->chip; in azx_pcm_trigger()
218 if (chip->driver_caps & AZX_DCAPS_OLD_SSYNC) in azx_pcm_trigger()
223 if (dsp_is_locked(azx_dev) || !hstr->prepared) in azx_pcm_trigger()
224 return -EPIPE; in azx_pcm_trigger()
238 return -EINVAL; in azx_pcm_trigger()
242 if (s->pcm->card != substream->pcm->card) in azx_pcm_trigger()
245 sbits |= 1 << azx_dev->core.index; in azx_pcm_trigger()
249 spin_lock(&bus->reg_lock); in azx_pcm_trigger()
255 if (s->pcm->card != substream->pcm->card) in azx_pcm_trigger()
259 azx_dev->insufficient = 1; in azx_pcm_trigger()
265 spin_unlock(&bus->reg_lock); in azx_pcm_trigger()
269 spin_lock(&bus->reg_lock); in azx_pcm_trigger()
274 spin_unlock(&bus->reg_lock); in azx_pcm_trigger()
293 struct snd_pcm_substream *substream = azx_dev->core.substream; in azx_get_position()
295 int stream = substream->stream; in azx_get_position()
298 if (chip->get_position[stream]) in azx_get_position()
299 pos = chip->get_position[stream](chip, azx_dev); in azx_get_position()
303 if (pos >= azx_dev->core.bufsize) in azx_get_position()
306 if (substream->runtime) { in azx_get_position()
310 if (chip->get_delay[stream]) in azx_get_position()
311 delay += chip->get_delay[stream](chip, azx_dev, pos); in azx_get_position()
312 if (hinfo->ops.get_delay) in azx_get_position()
313 delay += hinfo->ops.get_delay(hinfo, apcm->codec, in azx_get_position()
315 substream->runtime->delay = delay; in azx_get_position()
326 struct azx *chip = apcm->chip; in azx_pcm_pointer()
328 return bytes_to_frames(substream->runtime, in azx_pcm_pointer()
346 * rem can’t overflow because both are 32-bit values
370 struct azx *chip = apcm->chip; in azx_get_sync_time()
380 runtime = substream->runtime; in azx_get_sync_time()
382 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) in azx_get_sync_time()
391 (azx_dev->core.stream_tag - 1); in azx_get_sync_time()
402 timeout--; in azx_get_sync_time()
406 dev_err(chip->card->dev, "GTSCC capture Timedout!\n"); in azx_get_sync_time()
407 return -EIO; in azx_get_sync_time()
410 /* Read wall clock counter */ in azx_get_sync_time()
413 /* Read TSC counter */ in azx_get_sync_time()
417 /* Read Link counter */ in azx_get_sync_time()
421 /* Ack: registers read done */ in azx_get_sync_time()
431 * An error occurs near frame "rollover". The clocks in in azx_get_sync_time()
436 if (wallclk_cycles < HDA_MAX_CYCLE_VALUE - HDA_MAX_CYCLE_OFFSET in azx_get_sync_time()
441 * Sleep before we read again, else we may again get in azx_get_sync_time()
450 dev_err_ratelimited(chip->card->dev, in azx_get_sync_time()
452 return -EIO; in azx_get_sync_time()
456 NSEC_PER_SEC, runtime->rate)); in azx_get_sync_time()
458 ((HDA_MAX_CYCLE_VALUE + 1) * runtime->rate)); in azx_get_sync_time()
469 return -ENXIO; in azx_get_sync_time()
483 if (runtime->hw.info & SNDRV_PCM_INFO_HAS_LINK_SYNCHRONIZED_ATIME) in is_link_time_supported()
484 if (ts->type_requested == SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK_SYNCHRONIZED) in is_link_time_supported()
496 struct snd_pcm_runtime *runtime = substream->runtime; in azx_get_time_info()
501 if ((substream->runtime->hw.info & SNDRV_PCM_INFO_HAS_LINK_ATIME) && in azx_get_time_info()
502 (audio_tstamp_config->type_requested == SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK)) { in azx_get_time_info()
504 snd_pcm_gettime(substream->runtime, system_ts); in azx_get_time_info()
506 nsec = timecounter_read(&azx_dev->core.tc); in azx_get_time_info()
508 if (audio_tstamp_config->report_delay) in azx_get_time_info()
513 audio_tstamp_report->actual_type = SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK; in azx_get_time_info()
514 audio_tstamp_report->accuracy_report = 1; /* rest of structure is valid */ in azx_get_time_info()
515 audio_tstamp_report->accuracy = 42; /* 24 MHz WallClock == 42ns resolution */ in azx_get_time_info()
523 switch (runtime->tstamp_type) { in azx_get_time_info()
525 return -EINVAL; in azx_get_time_info()
539 audio_tstamp_report->actual_type = in azx_get_time_info()
541 audio_tstamp_report->accuracy_report = 1; in azx_get_time_info()
543 audio_tstamp_report->accuracy = 42; in azx_get_time_info()
546 audio_tstamp_report->actual_type = SNDRV_PCM_AUDIO_TSTAMP_TYPE_DEFAULT; in azx_get_time_info()
557 /* No full-resume yet implemented */
582 struct azx *chip = apcm->chip; in azx_pcm_open()
584 struct snd_pcm_runtime *runtime = substream->runtime; in azx_pcm_open()
588 snd_hda_codec_pcm_get(apcm->info); in azx_pcm_open()
589 mutex_lock(&chip->open_mutex); in azx_pcm_open()
593 err = -EBUSY; in azx_pcm_open()
596 runtime->private_data = azx_dev; in azx_pcm_open()
598 runtime->hw = azx_pcm_hw; in azx_pcm_open()
599 if (chip->gts_present) in azx_pcm_open()
600 runtime->hw.info |= SNDRV_PCM_INFO_HAS_LINK_SYNCHRONIZED_ATIME; in azx_pcm_open()
601 runtime->hw.channels_min = hinfo->channels_min; in azx_pcm_open()
602 runtime->hw.channels_max = hinfo->channels_max; in azx_pcm_open()
603 runtime->hw.formats = hinfo->formats; in azx_pcm_open()
604 runtime->hw.rates = hinfo->rates; in azx_pcm_open()
608 /* avoid wrap-around with wall-clock */ in azx_pcm_open()
613 if (chip->align_buffer_size) in azx_pcm_open()
632 snd_hda_power_up(apcm->codec); in azx_pcm_open()
633 if (hinfo->ops.open) in azx_pcm_open()
634 err = hinfo->ops.open(hinfo, apcm->codec, substream); in azx_pcm_open()
636 err = -ENODEV; in azx_pcm_open()
643 if (snd_BUG_ON(!runtime->hw.channels_min) || in azx_pcm_open()
644 snd_BUG_ON(!runtime->hw.channels_max) || in azx_pcm_open()
645 snd_BUG_ON(!runtime->hw.formats) || in azx_pcm_open()
646 snd_BUG_ON(!runtime->hw.rates)) { in azx_pcm_open()
648 if (hinfo->ops.close) in azx_pcm_open()
649 hinfo->ops.close(hinfo, apcm->codec, substream); in azx_pcm_open()
650 err = -EINVAL; in azx_pcm_open()
656 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) { in azx_pcm_open()
657 runtime->hw.info &= ~SNDRV_PCM_INFO_HAS_WALL_CLOCK; /* legacy */ in azx_pcm_open()
658 runtime->hw.info &= ~SNDRV_PCM_INFO_HAS_LINK_ATIME; in azx_pcm_open()
662 mutex_unlock(&chip->open_mutex); in azx_pcm_open()
666 snd_hda_power_down(apcm->codec); in azx_pcm_open()
668 mutex_unlock(&chip->open_mutex); in azx_pcm_open()
669 snd_hda_codec_pcm_put(apcm->info); in azx_pcm_open()
686 struct azx_pcm *apcm = pcm->private_data; in azx_pcm_free()
688 list_del(&apcm->list); in azx_pcm_free()
689 apcm->info->pcm = NULL; in azx_pcm_free()
699 struct hdac_bus *bus = &_bus->core; in snd_hda_attach_pcm_stream()
703 int pcm_dev = cpcm->device; in snd_hda_attach_pcm_stream()
708 list_for_each_entry(apcm, &chip->pcm_list, list) { in snd_hda_attach_pcm_stream()
709 if (apcm->pcm->device == pcm_dev) { in snd_hda_attach_pcm_stream()
710 dev_err(chip->card->dev, "PCM %d already exists\n", in snd_hda_attach_pcm_stream()
712 return -EBUSY; in snd_hda_attach_pcm_stream()
715 err = snd_pcm_new(chip->card, cpcm->name, pcm_dev, in snd_hda_attach_pcm_stream()
716 cpcm->stream[SNDRV_PCM_STREAM_PLAYBACK].substreams, in snd_hda_attach_pcm_stream()
717 cpcm->stream[SNDRV_PCM_STREAM_CAPTURE].substreams, in snd_hda_attach_pcm_stream()
721 strscpy(pcm->name, cpcm->name, sizeof(pcm->name)); in snd_hda_attach_pcm_stream()
724 snd_device_free(chip->card, pcm); in snd_hda_attach_pcm_stream()
725 return -ENOMEM; in snd_hda_attach_pcm_stream()
727 apcm->chip = chip; in snd_hda_attach_pcm_stream()
728 apcm->pcm = pcm; in snd_hda_attach_pcm_stream()
729 apcm->codec = codec; in snd_hda_attach_pcm_stream()
730 apcm->info = cpcm; in snd_hda_attach_pcm_stream()
731 pcm->private_data = apcm; in snd_hda_attach_pcm_stream()
732 pcm->private_free = azx_pcm_free; in snd_hda_attach_pcm_stream()
733 if (cpcm->pcm_type == HDA_PCM_TYPE_MODEM) in snd_hda_attach_pcm_stream()
734 pcm->dev_class = SNDRV_PCM_CLASS_MODEM; in snd_hda_attach_pcm_stream()
735 list_add_tail(&apcm->list, &chip->pcm_list); in snd_hda_attach_pcm_stream()
736 cpcm->pcm = pcm; in snd_hda_attach_pcm_stream()
738 if (cpcm->stream[s].substreams) in snd_hda_attach_pcm_stream()
741 /* buffer pre-allocation */ in snd_hda_attach_pcm_stream()
745 if (chip->uc_buffer) in snd_hda_attach_pcm_stream()
747 snd_pcm_set_managed_buffer_all(pcm, type, chip->card->dev, in snd_hda_attach_pcm_stream()
769 struct hda_bus *hbus = &chip->bus; in azx_rirb_get_response()
777 if (hbus->no_response_fallback) in azx_rirb_get_response()
778 return -EIO; in azx_rirb_get_response()
780 if (!bus->polling_mode) { in azx_rirb_get_response()
781 dev_warn(chip->card->dev, in azx_rirb_get_response()
783 bus->last_cmd[addr]); in azx_rirb_get_response()
784 bus->polling_mode = 1; in azx_rirb_get_response()
788 if (chip->msi) { in azx_rirb_get_response()
789 dev_warn(chip->card->dev, in azx_rirb_get_response()
790 "No response from codec, disabling MSI: last cmd=0x%08x\n", in azx_rirb_get_response()
791 bus->last_cmd[addr]); in azx_rirb_get_response()
792 if (chip->ops->disable_msi_reset_irq && in azx_rirb_get_response()
793 chip->ops->disable_msi_reset_irq(chip) < 0) in azx_rirb_get_response()
794 return -EIO; in azx_rirb_get_response()
798 if (chip->probing) { in azx_rirb_get_response()
800 * phase, this is likely an access to a non-existing codec in azx_rirb_get_response()
803 return -EIO; in azx_rirb_get_response()
806 /* no fallback mechanism? */ in azx_rirb_get_response()
807 if (!chip->fallback_to_single_cmd) in azx_rirb_get_response()
808 return -EIO; in azx_rirb_get_response()
813 if (hbus->allow_bus_reset && !hbus->response_reset && !hbus->in_reset) { in azx_rirb_get_response()
814 hbus->response_reset = 1; in azx_rirb_get_response()
815 dev_err(chip->card->dev, in azx_rirb_get_response()
816 "No response from codec, resetting bus: last cmd=0x%08x\n", in azx_rirb_get_response()
817 bus->last_cmd[addr]); in azx_rirb_get_response()
818 return -EAGAIN; /* give a chance to retry */ in azx_rirb_get_response()
821 dev_err(chip->card->dev, in azx_rirb_get_response()
823 bus->last_cmd[addr]); in azx_rirb_get_response()
824 chip->single_cmd = 1; in azx_rirb_get_response()
825 hbus->response_reset = 0; in azx_rirb_get_response()
827 return -EIO; in azx_rirb_get_response()
845 while (timeout--) { in azx_single_wait_for_response()
849 azx_bus(chip)->rirb.res[addr] = azx_readl(chip, IR); in azx_single_wait_for_response()
855 dev_dbg(chip->card->dev, "get_response timeout: IRS=0x%x\n", in azx_single_wait_for_response()
857 azx_bus(chip)->rirb.res[addr] = -1; in azx_single_wait_for_response()
858 return -EIO; in azx_single_wait_for_response()
868 bus->last_cmd[azx_command_addr(val)] = val; in azx_single_send_cmd()
869 while (timeout--) { in azx_single_send_cmd()
883 dev_dbg(chip->card->dev, in azx_single_send_cmd()
886 return -EIO; in azx_single_send_cmd()
894 *res = bus->rirb.res[addr]; in azx_single_get_response()
901 * They are just the skeleton to call sub-callbacks according to the
902 * current setting of chip->single_cmd.
910 if (chip->disabled) in azx_send_cmd()
912 if (chip->single_cmd) in azx_send_cmd()
924 if (chip->disabled) in azx_get_response()
926 if (chip->single_cmd) in azx_get_response()
949 list_for_each_entry(s, &bus->stream_list, list) in azx_get_dsp_loader_dev()
950 if (s->index == chip->playback_index_offset) in azx_get_dsp_loader_dev()
960 struct hdac_bus *bus = &codec->bus->core; in snd_hda_codec_load_dsp_prepare()
969 spin_lock_irq(&bus->reg_lock); in snd_hda_codec_load_dsp_prepare()
970 if (hstr->opened) { in snd_hda_codec_load_dsp_prepare()
971 chip->saved_azx_dev = *azx_dev; in snd_hda_codec_load_dsp_prepare()
974 spin_unlock_irq(&bus->reg_lock); in snd_hda_codec_load_dsp_prepare()
978 spin_lock_irq(&bus->reg_lock); in snd_hda_codec_load_dsp_prepare()
980 *azx_dev = chip->saved_azx_dev; in snd_hda_codec_load_dsp_prepare()
981 spin_unlock_irq(&bus->reg_lock); in snd_hda_codec_load_dsp_prepare()
985 hstr->prepared = 0; in snd_hda_codec_load_dsp_prepare()
992 struct hdac_bus *bus = &codec->bus->core; in snd_hda_codec_load_dsp_trigger()
1003 struct hdac_bus *bus = &codec->bus->core; in snd_hda_codec_load_dsp_cleanup()
1008 if (!dmab->area || !hstr->locked) in snd_hda_codec_load_dsp_cleanup()
1012 spin_lock_irq(&bus->reg_lock); in snd_hda_codec_load_dsp_cleanup()
1013 if (hstr->opened) in snd_hda_codec_load_dsp_cleanup()
1014 *azx_dev = chip->saved_azx_dev; in snd_hda_codec_load_dsp_cleanup()
1015 hstr->locked = false; in snd_hda_codec_load_dsp_cleanup()
1016 spin_unlock_irq(&bus->reg_lock); in snd_hda_codec_load_dsp_cleanup()
1028 if (chip->driver_caps & AZX_DCAPS_CTX_WORKAROUND) in azx_init_chip()
1039 list_for_each_entry(s, &bus->stream_list, list) in azx_stop_all_streams()
1059 if (!chip->ops->position_check || in stream_update()
1060 chip->ops->position_check(chip, azx_dev)) { in stream_update()
1061 spin_unlock(&bus->reg_lock); in stream_update()
1062 snd_pcm_period_elapsed(azx_stream(azx_dev)->substream); in stream_update()
1063 spin_lock(&bus->reg_lock); in stream_update()
1077 if (!pm_runtime_active(chip->card->dev)) in azx_interrupt()
1081 spin_lock(&bus->reg_lock); in azx_interrupt()
1083 if (chip->disabled) in azx_interrupt()
1099 * Clearing the interrupt status here ensures that no in azx_interrupt()
1100 * interrupt gets masked after the RIRB wp is read in in azx_interrupt()
1109 if (chip->driver_caps & AZX_DCAPS_CTX_WORKAROUND) in azx_interrupt()
1117 spin_unlock(&bus->reg_lock); in azx_interrupt()
1136 unsigned int res = -1; in probe_codec()
1138 mutex_lock(&bus->cmd_mutex); in probe_codec()
1139 chip->probing = 1; in probe_codec()
1142 chip->probing = 0; in probe_codec()
1143 mutex_unlock(&bus->cmd_mutex); in probe_codec()
1144 if (err < 0 || res == -1) in probe_codec()
1145 return -EIO; in probe_codec()
1146 dev_dbg(chip->card->dev, "codec #%d probed OK\n", addr); in probe_codec()
1152 struct azx *chip = bus_to_azx(&bus->core); in snd_hda_bus_reset()
1154 bus->in_reset = 1; in snd_hda_bus_reset()
1157 if (bus->core.chip_init) in snd_hda_bus_reset()
1159 bus->in_reset = 0; in snd_hda_bus_reset()
1162 /* HD-audio bus initialization */
1165 struct hda_bus *bus = &chip->bus; in azx_bus_init()
1168 err = snd_hdac_bus_init(&bus->core, chip->card->dev, &bus_core_ops); in azx_bus_init()
1172 bus->card = chip->card; in azx_bus_init()
1173 mutex_init(&bus->prepare_mutex); in azx_bus_init()
1174 bus->pci = chip->pci; in azx_bus_init()
1175 bus->modelname = model; in azx_bus_init()
1176 bus->mixer_assigned = -1; in azx_bus_init()
1177 bus->core.snoop = azx_snoop(chip); in azx_bus_init()
1178 if (chip->get_position[0] != azx_get_pos_lpib || in azx_bus_init()
1179 chip->get_position[1] != azx_get_pos_lpib) in azx_bus_init()
1180 bus->core.use_posbuf = true; in azx_bus_init()
1181 bus->core.bdl_pos_adj = chip->bdl_pos_adj; in azx_bus_init()
1182 if (chip->driver_caps & AZX_DCAPS_CORBRP_SELF_CLEAR) in azx_bus_init()
1183 bus->core.corbrp_self_clear = true; in azx_bus_init()
1185 if (chip->driver_caps & AZX_DCAPS_4K_BDLE_BOUNDARY) in azx_bus_init()
1186 bus->core.align_bdle_4k = true; in azx_bus_init()
1189 bus->core.sync_write = 1; in azx_bus_init()
1207 if ((bus->codec_mask & (1 << c)) & chip->codec_probe_mask) { in azx_probe_codecs()
1212 dev_warn(chip->card->dev, in azx_probe_codecs()
1214 bus->codec_mask &= ~(1 << c); in azx_probe_codecs()
1215 /* More badly, accessing to a non-existing in azx_probe_codecs()
1230 if ((bus->codec_mask & (1 << c)) & chip->codec_probe_mask) { in azx_probe_codecs()
1232 err = snd_hda_codec_new(&chip->bus, chip->card, c, &codec); in azx_probe_codecs()
1235 codec->jackpoll_interval = chip->jackpoll_interval; in azx_probe_codecs()
1236 codec->beep_mode = chip->beep_mode; in azx_probe_codecs()
1241 dev_err(chip->card->dev, "no codecs initialized\n"); in azx_probe_codecs()
1242 return -ENXIO; in azx_probe_codecs()
1254 list_for_each_codec(codec, &chip->bus) { in azx_codec_configure()
1261 list_for_each_codec_safe(codec, next, &chip->bus) { in azx_codec_configure()
1262 if (!codec->configured) { in azx_codec_configure()
1264 snd_hdac_device_unregister(&codec->core); in azx_codec_configure()
1269 return success ? 0 : -ENODEV; in azx_codec_configure()
1275 if (index >= chip->capture_index_offset && in stream_direction()
1276 index < chip->capture_index_offset + chip->capture_streams) in stream_direction()
1291 for (i = 0; i < chip->num_streams; i++) { in azx_init_streams()
1296 return -ENOMEM; in azx_init_streams()
1305 if (chip->driver_caps & AZX_DCAPS_SEPARATE_STREAM_TAG) in azx_init_streams()
1322 while (!list_empty(&bus->stream_list)) { in azx_free_streams()
1323 s = list_first_entry(&bus->stream_list, struct hdac_stream, list); in azx_free_streams()
1324 list_del(&s->list); in azx_free_streams()