Lines Matching +full:assigned +full:- +full:resolution +full:- +full:bits

1 // SPDX-License-Identifier: GPL-2.0-or-later
21 /* for art-tsc conversion */
50 /* release the assigned stream */
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()
154 unsigned int format_val, stream_tag, bits; in azx_pcm_prepare() local
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 bits = snd_hdac_stream_format_bits(runtime->format, SNDRV_PCM_SUBFORMAT_STD, hinfo->maxbps); in azx_pcm_prepare()
170 format_val = snd_hdac_spdif_stream_format(runtime->channels, bits, runtime->rate, ctls); in azx_pcm_prepare()
172 dev_err(chip->card->dev, in azx_pcm_prepare()
174 runtime->rate, runtime->channels, runtime->format); in azx_pcm_prepare()
175 err = -EINVAL; in azx_pcm_prepare()
185 stream_tag = azx_dev->core.stream_tag; in azx_pcm_prepare()
186 /* CA-IBG chips need the playback stream starting from 1 */ in azx_pcm_prepare()
187 if ((chip->driver_caps & AZX_DCAPS_CTX_WORKAROUND) && in azx_pcm_prepare()
188 stream_tag > chip->capture_streams) in azx_pcm_prepare()
189 stream_tag -= chip->capture_streams; in azx_pcm_prepare()
190 err = snd_hda_codec_prepare(apcm->codec, hinfo, stream_tag, in azx_pcm_prepare()
191 azx_dev->core.format_val, substream); in azx_pcm_prepare()
195 azx_stream(azx_dev)->prepared = 1; in azx_pcm_prepare()
203 struct azx *chip = apcm->chip; in azx_pcm_trigger()
216 if (chip->driver_caps & AZX_DCAPS_OLD_SSYNC) in azx_pcm_trigger()
221 if (dsp_is_locked(azx_dev) || !hstr->prepared) in azx_pcm_trigger()
222 return -EPIPE; in azx_pcm_trigger()
236 return -EINVAL; in azx_pcm_trigger()
240 if (s->pcm->card != substream->pcm->card) in azx_pcm_trigger()
243 sbits |= 1 << azx_dev->core.index; in azx_pcm_trigger()
247 spin_lock(&bus->reg_lock); in azx_pcm_trigger()
249 /* first, set SYNC bits of corresponding streams */ in azx_pcm_trigger()
253 if (s->pcm->card != substream->pcm->card) in azx_pcm_trigger()
257 azx_dev->insufficient = 1; in azx_pcm_trigger()
263 spin_unlock(&bus->reg_lock); in azx_pcm_trigger()
267 spin_lock(&bus->reg_lock); in azx_pcm_trigger()
268 /* reset SYNC bits */ in azx_pcm_trigger()
272 spin_unlock(&bus->reg_lock); in azx_pcm_trigger()
291 struct snd_pcm_substream *substream = azx_dev->core.substream; in azx_get_position()
293 int stream = substream->stream; in azx_get_position()
296 if (chip->get_position[stream]) in azx_get_position()
297 pos = chip->get_position[stream](chip, azx_dev); in azx_get_position()
301 if (pos >= azx_dev->core.bufsize) in azx_get_position()
304 if (substream->runtime) { in azx_get_position()
308 if (chip->get_delay[stream]) in azx_get_position()
309 delay += chip->get_delay[stream](chip, azx_dev, pos); in azx_get_position()
310 if (hinfo->ops.get_delay) in azx_get_position()
311 delay += hinfo->ops.get_delay(hinfo, apcm->codec, in azx_get_position()
313 substream->runtime->delay = delay; in azx_get_position()
324 struct azx *chip = apcm->chip; in azx_pcm_pointer()
326 return bytes_to_frames(substream->runtime, in azx_pcm_pointer()
344 * rem can’t overflow because both are 32-bit values
368 struct azx *chip = apcm->chip; in azx_get_sync_time()
378 runtime = substream->runtime; in azx_get_sync_time()
380 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) in azx_get_sync_time()
389 (azx_dev->core.stream_tag - 1); in azx_get_sync_time()
400 timeout--; in azx_get_sync_time()
404 dev_err(chip->card->dev, "GTSCC capture Timedout!\n"); in azx_get_sync_time()
405 return -EIO; in azx_get_sync_time()
434 if (wallclk_cycles < HDA_MAX_CYCLE_VALUE - HDA_MAX_CYCLE_OFFSET in azx_get_sync_time()
448 dev_err_ratelimited(chip->card->dev, in azx_get_sync_time()
450 return -EIO; in azx_get_sync_time()
454 NSEC_PER_SEC, runtime->rate)); in azx_get_sync_time()
456 ((HDA_MAX_CYCLE_VALUE + 1) * runtime->rate)); in azx_get_sync_time()
467 return -ENXIO; in azx_get_sync_time()
481 if (runtime->hw.info & SNDRV_PCM_INFO_HAS_LINK_SYNCHRONIZED_ATIME) in is_link_time_supported()
482 if (ts->type_requested == SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK_SYNCHRONIZED) in is_link_time_supported()
494 struct snd_pcm_runtime *runtime = substream->runtime; in azx_get_time_info()
499 if ((substream->runtime->hw.info & SNDRV_PCM_INFO_HAS_LINK_ATIME) && in azx_get_time_info()
500 (audio_tstamp_config->type_requested == SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK)) { in azx_get_time_info()
502 snd_pcm_gettime(substream->runtime, system_ts); in azx_get_time_info()
504 nsec = timecounter_read(&azx_dev->core.tc); in azx_get_time_info()
505 if (audio_tstamp_config->report_delay) in azx_get_time_info()
510 audio_tstamp_report->actual_type = SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK; in azx_get_time_info()
511 audio_tstamp_report->accuracy_report = 1; /* rest of structure is valid */ in azx_get_time_info()
512 audio_tstamp_report->accuracy = 42; /* 24 MHz WallClock == 42ns resolution */ in azx_get_time_info()
520 switch (runtime->tstamp_type) { in azx_get_time_info()
522 return -EINVAL; in azx_get_time_info()
536 audio_tstamp_report->actual_type = in azx_get_time_info()
538 audio_tstamp_report->accuracy_report = 1; in azx_get_time_info()
539 /* 24 MHz WallClock == 42ns resolution */ in azx_get_time_info()
540 audio_tstamp_report->accuracy = 42; in azx_get_time_info()
543 audio_tstamp_report->actual_type = SNDRV_PCM_AUDIO_TSTAMP_TYPE_DEFAULT; in azx_get_time_info()
554 /* No full-resume yet implemented */
579 struct azx *chip = apcm->chip; in azx_pcm_open()
581 struct snd_pcm_runtime *runtime = substream->runtime; in azx_pcm_open()
585 snd_hda_codec_pcm_get(apcm->info); in azx_pcm_open()
586 mutex_lock(&chip->open_mutex); in azx_pcm_open()
590 err = -EBUSY; in azx_pcm_open()
593 runtime->private_data = azx_dev; in azx_pcm_open()
595 runtime->hw = azx_pcm_hw; in azx_pcm_open()
596 if (chip->gts_present) in azx_pcm_open()
597 runtime->hw.info |= SNDRV_PCM_INFO_HAS_LINK_SYNCHRONIZED_ATIME; in azx_pcm_open()
598 runtime->hw.channels_min = hinfo->channels_min; in azx_pcm_open()
599 runtime->hw.channels_max = hinfo->channels_max; in azx_pcm_open()
600 runtime->hw.formats = hinfo->formats; in azx_pcm_open()
601 runtime->hw.rates = hinfo->rates; in azx_pcm_open()
605 /* avoid wrap-around with wall-clock */ in azx_pcm_open()
610 if (chip->align_buffer_size) in azx_pcm_open()
629 snd_hda_power_up(apcm->codec); in azx_pcm_open()
630 if (hinfo->ops.open) in azx_pcm_open()
631 err = hinfo->ops.open(hinfo, apcm->codec, substream); in azx_pcm_open()
633 err = -ENODEV; in azx_pcm_open()
640 if (snd_BUG_ON(!runtime->hw.channels_min) || in azx_pcm_open()
641 snd_BUG_ON(!runtime->hw.channels_max) || in azx_pcm_open()
642 snd_BUG_ON(!runtime->hw.formats) || in azx_pcm_open()
643 snd_BUG_ON(!runtime->hw.rates)) { in azx_pcm_open()
645 if (hinfo->ops.close) in azx_pcm_open()
646 hinfo->ops.close(hinfo, apcm->codec, substream); in azx_pcm_open()
647 err = -EINVAL; in azx_pcm_open()
653 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) { in azx_pcm_open()
654 runtime->hw.info &= ~SNDRV_PCM_INFO_HAS_WALL_CLOCK; /* legacy */ in azx_pcm_open()
655 runtime->hw.info &= ~SNDRV_PCM_INFO_HAS_LINK_ATIME; in azx_pcm_open()
659 mutex_unlock(&chip->open_mutex); in azx_pcm_open()
663 snd_hda_power_down(apcm->codec); in azx_pcm_open()
665 mutex_unlock(&chip->open_mutex); in azx_pcm_open()
666 snd_hda_codec_pcm_put(apcm->info); in azx_pcm_open()
683 struct azx_pcm *apcm = pcm->private_data; in azx_pcm_free()
685 list_del(&apcm->list); in azx_pcm_free()
686 apcm->info->pcm = NULL; in azx_pcm_free()
696 struct hdac_bus *bus = &_bus->core; in snd_hda_attach_pcm_stream()
700 int pcm_dev = cpcm->device; in snd_hda_attach_pcm_stream()
705 list_for_each_entry(apcm, &chip->pcm_list, list) { in snd_hda_attach_pcm_stream()
706 if (apcm->pcm->device == pcm_dev) { in snd_hda_attach_pcm_stream()
707 dev_err(chip->card->dev, "PCM %d already exists\n", in snd_hda_attach_pcm_stream()
709 return -EBUSY; in snd_hda_attach_pcm_stream()
712 err = snd_pcm_new(chip->card, cpcm->name, pcm_dev, in snd_hda_attach_pcm_stream()
713 cpcm->stream[SNDRV_PCM_STREAM_PLAYBACK].substreams, in snd_hda_attach_pcm_stream()
714 cpcm->stream[SNDRV_PCM_STREAM_CAPTURE].substreams, in snd_hda_attach_pcm_stream()
718 strscpy(pcm->name, cpcm->name, sizeof(pcm->name)); in snd_hda_attach_pcm_stream()
721 snd_device_free(chip->card, pcm); in snd_hda_attach_pcm_stream()
722 return -ENOMEM; in snd_hda_attach_pcm_stream()
724 apcm->chip = chip; in snd_hda_attach_pcm_stream()
725 apcm->pcm = pcm; in snd_hda_attach_pcm_stream()
726 apcm->codec = codec; in snd_hda_attach_pcm_stream()
727 apcm->info = cpcm; in snd_hda_attach_pcm_stream()
728 pcm->private_data = apcm; in snd_hda_attach_pcm_stream()
729 pcm->private_free = azx_pcm_free; in snd_hda_attach_pcm_stream()
730 if (cpcm->pcm_type == HDA_PCM_TYPE_MODEM) in snd_hda_attach_pcm_stream()
731 pcm->dev_class = SNDRV_PCM_CLASS_MODEM; in snd_hda_attach_pcm_stream()
732 list_add_tail(&apcm->list, &chip->pcm_list); in snd_hda_attach_pcm_stream()
733 cpcm->pcm = pcm; in snd_hda_attach_pcm_stream()
735 if (cpcm->stream[s].substreams) in snd_hda_attach_pcm_stream()
738 /* buffer pre-allocation */ in snd_hda_attach_pcm_stream()
742 if (chip->uc_buffer) in snd_hda_attach_pcm_stream()
744 snd_pcm_set_managed_buffer_all(pcm, type, chip->card->dev, in snd_hda_attach_pcm_stream()
766 struct hda_bus *hbus = &chip->bus; in azx_rirb_get_response()
774 if (hbus->no_response_fallback) in azx_rirb_get_response()
775 return -EIO; in azx_rirb_get_response()
777 if (!bus->polling_mode) { in azx_rirb_get_response()
778 dev_warn(chip->card->dev, in azx_rirb_get_response()
780 bus->last_cmd[addr]); in azx_rirb_get_response()
781 bus->polling_mode = 1; in azx_rirb_get_response()
785 if (chip->msi) { in azx_rirb_get_response()
786 dev_warn(chip->card->dev, in azx_rirb_get_response()
788 bus->last_cmd[addr]); in azx_rirb_get_response()
789 if (chip->ops->disable_msi_reset_irq && in azx_rirb_get_response()
790 chip->ops->disable_msi_reset_irq(chip) < 0) in azx_rirb_get_response()
791 return -EIO; in azx_rirb_get_response()
795 if (chip->probing) { in azx_rirb_get_response()
797 * phase, this is likely an access to a non-existing codec in azx_rirb_get_response()
800 return -EIO; in azx_rirb_get_response()
804 if (!chip->fallback_to_single_cmd) in azx_rirb_get_response()
805 return -EIO; in azx_rirb_get_response()
810 if (hbus->allow_bus_reset && !hbus->response_reset && !hbus->in_reset) { in azx_rirb_get_response()
811 hbus->response_reset = 1; in azx_rirb_get_response()
812 dev_err(chip->card->dev, in azx_rirb_get_response()
814 bus->last_cmd[addr]); in azx_rirb_get_response()
815 return -EAGAIN; /* give a chance to retry */ in azx_rirb_get_response()
818 dev_err(chip->card->dev, in azx_rirb_get_response()
820 bus->last_cmd[addr]); in azx_rirb_get_response()
821 chip->single_cmd = 1; in azx_rirb_get_response()
822 hbus->response_reset = 0; in azx_rirb_get_response()
824 return -EIO; in azx_rirb_get_response()
842 while (timeout--) { in azx_single_wait_for_response()
846 azx_bus(chip)->rirb.res[addr] = azx_readl(chip, IR); in azx_single_wait_for_response()
852 dev_dbg(chip->card->dev, "get_response timeout: IRS=0x%x\n", in azx_single_wait_for_response()
854 azx_bus(chip)->rirb.res[addr] = -1; in azx_single_wait_for_response()
855 return -EIO; in azx_single_wait_for_response()
865 bus->last_cmd[azx_command_addr(val)] = val; in azx_single_send_cmd()
866 while (timeout--) { in azx_single_send_cmd()
880 dev_dbg(chip->card->dev, in azx_single_send_cmd()
883 return -EIO; in azx_single_send_cmd()
891 *res = bus->rirb.res[addr]; in azx_single_get_response()
898 * They are just the skeleton to call sub-callbacks according to the
899 * current setting of chip->single_cmd.
907 if (chip->disabled) in azx_send_cmd()
909 if (chip->single_cmd) in azx_send_cmd()
921 if (chip->disabled) in azx_get_response()
923 if (chip->single_cmd) in azx_get_response()
946 list_for_each_entry(s, &bus->stream_list, list) in azx_get_dsp_loader_dev()
947 if (s->index == chip->playback_index_offset) in azx_get_dsp_loader_dev()
957 struct hdac_bus *bus = &codec->bus->core; in snd_hda_codec_load_dsp_prepare()
966 spin_lock_irq(&bus->reg_lock); in snd_hda_codec_load_dsp_prepare()
967 if (hstr->opened) { in snd_hda_codec_load_dsp_prepare()
968 chip->saved_azx_dev = *azx_dev; in snd_hda_codec_load_dsp_prepare()
971 spin_unlock_irq(&bus->reg_lock); in snd_hda_codec_load_dsp_prepare()
975 spin_lock_irq(&bus->reg_lock); in snd_hda_codec_load_dsp_prepare()
977 *azx_dev = chip->saved_azx_dev; in snd_hda_codec_load_dsp_prepare()
978 spin_unlock_irq(&bus->reg_lock); in snd_hda_codec_load_dsp_prepare()
982 hstr->prepared = 0; in snd_hda_codec_load_dsp_prepare()
989 struct hdac_bus *bus = &codec->bus->core; in snd_hda_codec_load_dsp_trigger()
1000 struct hdac_bus *bus = &codec->bus->core; in snd_hda_codec_load_dsp_cleanup()
1005 if (!dmab->area || !hstr->locked) in snd_hda_codec_load_dsp_cleanup()
1009 spin_lock_irq(&bus->reg_lock); in snd_hda_codec_load_dsp_cleanup()
1010 if (hstr->opened) in snd_hda_codec_load_dsp_cleanup()
1011 *azx_dev = chip->saved_azx_dev; in snd_hda_codec_load_dsp_cleanup()
1012 hstr->locked = false; in snd_hda_codec_load_dsp_cleanup()
1013 spin_unlock_irq(&bus->reg_lock); in snd_hda_codec_load_dsp_cleanup()
1025 if (chip->driver_caps & AZX_DCAPS_CTX_WORKAROUND) in azx_init_chip()
1054 if (!chip->ops->position_check || in stream_update()
1055 chip->ops->position_check(chip, azx_dev)) { in stream_update()
1056 spin_unlock(&bus->reg_lock); in stream_update()
1057 snd_pcm_period_elapsed(azx_stream(azx_dev)->substream); in stream_update()
1058 spin_lock(&bus->reg_lock); in stream_update()
1072 if (!pm_runtime_active(chip->card->dev)) in azx_interrupt()
1076 spin_lock(&bus->reg_lock); in azx_interrupt()
1078 if (chip->disabled) in azx_interrupt()
1104 if (chip->driver_caps & AZX_DCAPS_CTX_WORKAROUND) in azx_interrupt()
1112 spin_unlock(&bus->reg_lock); in azx_interrupt()
1131 unsigned int res = -1; in probe_codec()
1133 mutex_lock(&bus->cmd_mutex); in probe_codec()
1134 chip->probing = 1; in probe_codec()
1137 chip->probing = 0; in probe_codec()
1138 mutex_unlock(&bus->cmd_mutex); in probe_codec()
1139 if (err < 0 || res == -1) in probe_codec()
1140 return -EIO; in probe_codec()
1141 dev_dbg(chip->card->dev, "codec #%d probed OK\n", addr); in probe_codec()
1147 struct azx *chip = bus_to_azx(&bus->core); in snd_hda_bus_reset()
1149 bus->in_reset = 1; in snd_hda_bus_reset()
1152 if (bus->core.chip_init) in snd_hda_bus_reset()
1154 bus->in_reset = 0; in snd_hda_bus_reset()
1157 /* HD-audio bus initialization */
1160 struct hda_bus *bus = &chip->bus; in azx_bus_init()
1163 err = snd_hdac_bus_init(&bus->core, chip->card->dev, &bus_core_ops); in azx_bus_init()
1167 bus->card = chip->card; in azx_bus_init()
1168 mutex_init(&bus->prepare_mutex); in azx_bus_init()
1169 bus->pci = chip->pci; in azx_bus_init()
1170 bus->modelname = model; in azx_bus_init()
1171 bus->mixer_assigned = -1; in azx_bus_init()
1172 bus->core.snoop = azx_snoop(chip); in azx_bus_init()
1173 if (chip->get_position[0] != azx_get_pos_lpib || in azx_bus_init()
1174 chip->get_position[1] != azx_get_pos_lpib) in azx_bus_init()
1175 bus->core.use_posbuf = true; in azx_bus_init()
1176 bus->core.bdl_pos_adj = chip->bdl_pos_adj; in azx_bus_init()
1177 if (chip->driver_caps & AZX_DCAPS_CORBRP_SELF_CLEAR) in azx_bus_init()
1178 bus->core.corbrp_self_clear = true; in azx_bus_init()
1180 if (chip->driver_caps & AZX_DCAPS_4K_BDLE_BOUNDARY) in azx_bus_init()
1181 bus->core.align_bdle_4k = true; in azx_bus_init()
1184 bus->core.sync_write = 1; in azx_bus_init()
1202 if ((bus->codec_mask & (1 << c)) & chip->codec_probe_mask) { in azx_probe_codecs()
1207 dev_warn(chip->card->dev, in azx_probe_codecs()
1209 bus->codec_mask &= ~(1 << c); in azx_probe_codecs()
1211 if (bus->codec_mask == 0) in azx_probe_codecs()
1213 /* More badly, accessing to a non-existing in azx_probe_codecs()
1228 if ((bus->codec_mask & (1 << c)) & chip->codec_probe_mask) { in azx_probe_codecs()
1230 err = snd_hda_codec_new(&chip->bus, chip->card, c, &codec); in azx_probe_codecs()
1233 codec->jackpoll_interval = chip->jackpoll_interval; in azx_probe_codecs()
1234 codec->beep_mode = chip->beep_mode; in azx_probe_codecs()
1235 codec->ctl_dev_id = chip->ctl_dev_id; in azx_probe_codecs()
1240 dev_err(chip->card->dev, "no codecs initialized\n"); in azx_probe_codecs()
1241 return -ENXIO; in azx_probe_codecs()
1253 list_for_each_codec(codec, &chip->bus) { in azx_codec_configure()
1260 list_for_each_codec_safe(codec, next, &chip->bus) { in azx_codec_configure()
1261 if (!codec->configured) { in azx_codec_configure()
1263 snd_hdac_device_unregister(&codec->core); in azx_codec_configure()
1268 return success ? 0 : -ENODEV; in azx_codec_configure()
1274 if (index >= chip->capture_index_offset && in stream_direction()
1275 index < chip->capture_index_offset + chip->capture_streams) in stream_direction()
1290 for (i = 0; i < chip->num_streams; i++) { in azx_init_streams()
1295 return -ENOMEM; in azx_init_streams()
1304 if (chip->driver_caps & AZX_DCAPS_SEPARATE_STREAM_TAG) in azx_init_streams()
1321 while (!list_empty(&bus->stream_list)) { in azx_free_streams()
1322 s = list_first_entry(&bus->stream_list, struct hdac_stream, list); in azx_free_streams()
1323 list_del(&s->list); in azx_free_streams()