Lines Matching +full:switch +full:- +full:freq +full:- +full:select
1 // SPDX-License-Identifier: GPL-2.0-only
17 * Some hardware-related definitions
27 #define UNIPERIF_PLAYER_CLK_ADJ_MIN -999999
68 spin_lock(&player->irq_lock); in uni_player_irq_handler()
69 if (!player->substream) in uni_player_irq_handler()
72 snd_pcm_stream_lock(player->substream); in uni_player_irq_handler()
73 if (player->state == UNIPERIF_STATE_STOPPED) in uni_player_irq_handler()
82 dev_err(player->dev, "FIFO underflow error detected\n"); in uni_player_irq_handler()
85 if (player->underflow_enabled) { in uni_player_irq_handler()
87 player->state = UNIPERIF_STATE_UNDERFLOW; in uni_player_irq_handler()
94 snd_pcm_stop(player->substream, SNDRV_PCM_STATE_XRUN); in uni_player_irq_handler()
102 dev_err(player->dev, "DMA error detected\n"); in uni_player_irq_handler()
108 snd_pcm_stop(player->substream, SNDRV_PCM_STATE_XRUN); in uni_player_irq_handler()
115 if (!player->underflow_enabled) { in uni_player_irq_handler()
116 dev_err(player->dev, in uni_player_irq_handler()
118 ret = -EPERM; in uni_player_irq_handler()
123 dev_dbg(player->dev, "Underflow recovered (%d LR clocks max)\n", in uni_player_irq_handler()
130 player->state = UNIPERIF_STATE_STARTED; in uni_player_irq_handler()
138 dev_err(player->dev, "Underflow recovery failed\n"); in uni_player_irq_handler()
141 snd_pcm_stop(player->substream, SNDRV_PCM_STATE_XRUN); in uni_player_irq_handler()
147 snd_pcm_stream_unlock(player->substream); in uni_player_irq_handler()
149 spin_unlock(&player->irq_lock); in uni_player_irq_handler()
157 int adjustment = player->clk_adj; in uni_player_clk_set_rate()
161 * F = f + --------- * f = f + d in uni_player_clk_set_rate()
165 * d = --------- * f in uni_player_clk_set_rate()
169 * f - nominal rate in uni_player_clk_set_rate()
170 * a - adjustment in ppm (parts per milion) in uni_player_clk_set_rate()
171 * F - rate to be set in synthesizer in uni_player_clk_set_rate()
172 * d - delta (difference) between f and F in uni_player_clk_set_rate()
176 delta = -1; in uni_player_clk_set_rate()
177 adjustment = -adjustment; in uni_player_clk_set_rate()
188 return -EINVAL; in uni_player_clk_set_rate()
190 ret = clk_set_rate(player->clk, rate_adjusted); in uni_player_clk_set_rate()
194 rate_achieved = clk_get_rate(player->clk); in uni_player_clk_set_rate()
197 return -EINVAL; in uni_player_clk_set_rate()
203 delta = rate_achieved - rate; in uni_player_clk_set_rate()
206 delta = -delta; in uni_player_clk_set_rate()
207 adjustment = -1; in uni_player_clk_set_rate()
214 player->clk_adj = adjustment; in uni_player_clk_set_rate()
230 switch (runtime->rate) { in uni_player_set_channel_status()
232 player->stream_settings.iec958.status[3] = in uni_player_set_channel_status()
236 player->stream_settings.iec958.status[3] = in uni_player_set_channel_status()
240 player->stream_settings.iec958.status[3] = in uni_player_set_channel_status()
244 player->stream_settings.iec958.status[3] = in uni_player_set_channel_status()
248 player->stream_settings.iec958.status[3] = in uni_player_set_channel_status()
252 player->stream_settings.iec958.status[3] = in uni_player_set_channel_status()
256 player->stream_settings.iec958.status[3] = in uni_player_set_channel_status()
260 player->stream_settings.iec958.status[3] = in uni_player_set_channel_status()
264 player->stream_settings.iec958.status[3] = in uni_player_set_channel_status()
269 player->stream_settings.iec958.status[3] = in uni_player_set_channel_status()
276 * Use audio mode status to select PCM or encoded mode in uni_player_set_channel_status()
278 if (player->stream_settings.iec958.status[0] & IEC958_AES0_NONAUDIO) in uni_player_set_channel_status()
279 player->stream_settings.encoding_mode = in uni_player_set_channel_status()
282 player->stream_settings.encoding_mode = in uni_player_set_channel_status()
285 if (player->stream_settings.encoding_mode == in uni_player_set_channel_status()
296 player->stream_settings.iec958.status[0 + (n * 4)] & 0xf; in uni_player_set_channel_status()
298 player->stream_settings.iec958.status[1 + (n * 4)] << 8; in uni_player_set_channel_status()
300 player->stream_settings.iec958.status[2 + (n * 4)] << 16; in uni_player_set_channel_status()
302 player->stream_settings.iec958.status[3 + (n * 4)] << 24; in uni_player_set_channel_status()
307 if (player->ver < SND_ST_UNIPERIF_VERSION_UNI_PLR_TOP_1_0) in uni_player_set_channel_status()
318 clk_div = player->mclk / runtime->rate; in uni_player_prepare_iec958()
320 /* Oversampling must be multiple of 128 as iec958 frame is 32-bits */ in uni_player_prepare_iec958()
322 dev_err(player->dev, "%s: invalid clk_div %d\n", in uni_player_prepare_iec958()
324 return -EINVAL; in uni_player_prepare_iec958()
327 switch (runtime->format) { in uni_player_prepare_iec958()
331 /* 16-bits per sub-frame */ in uni_player_prepare_iec958()
333 /* Set 16-bit sample precision */ in uni_player_prepare_iec958()
339 /* 32-bits per sub-frame */ in uni_player_prepare_iec958()
341 /* Set 24-bit sample precision */ in uni_player_prepare_iec958()
345 dev_err(player->dev, "format not supported\n"); in uni_player_prepare_iec958()
346 return -EINVAL; in uni_player_prepare_iec958()
366 mutex_lock(&player->ctrl_lock); in uni_player_prepare_iec958()
369 mutex_unlock(&player->ctrl_lock); in uni_player_prepare_iec958()
374 /* Disable one-bit audio mode */ in uni_player_prepare_iec958()
386 if (player->stream_settings.encoding_mode == in uni_player_prepare_iec958()
392 SET_UNIPERIF_I2S_FMT_NUM_CH(player, runtime->channels / 2); in uni_player_prepare_iec958()
408 if (player->ver < SND_ST_UNIPERIF_VERSION_UNI_PLR_TOP_1_0) in uni_player_prepare_iec958()
422 if ((player->daifmt & SND_SOC_DAIFMT_FORMAT_MASK) == in uni_player_prepare_pcm()
426 slot_width = snd_pcm_format_width(runtime->format); in uni_player_prepare_pcm()
428 output_frame_size = slot_width * runtime->channels; in uni_player_prepare_pcm()
430 clk_div = player->mclk / runtime->rate; in uni_player_prepare_pcm()
436 dev_err(player->dev, "%s: invalid clk_div\n", __func__); in uni_player_prepare_pcm()
437 return -EINVAL; in uni_player_prepare_pcm()
441 dev_err(player->dev, "%s: invalid clk_div\n", __func__); in uni_player_prepare_pcm()
442 return -EINVAL; in uni_player_prepare_pcm()
447 * on output - Transfer 16 or 32 bits from FIFO in uni_player_prepare_pcm()
449 switch (slot_width) { in uni_player_prepare_pcm()
459 dev_err(player->dev, "subframe format not supported\n"); in uni_player_prepare_pcm()
460 return -EINVAL; in uni_player_prepare_pcm()
464 switch (runtime->format) { in uni_player_prepare_pcm()
473 * on the left than zeros (if less than 32 bytes)"... ;-) in uni_player_prepare_pcm()
479 dev_err(player->dev, "format not supported\n"); in uni_player_prepare_pcm()
480 return -EINVAL; in uni_player_prepare_pcm()
490 if ((runtime->channels % 2) || (runtime->channels < 2) || in uni_player_prepare_pcm()
491 (runtime->channels > 10)) { in uni_player_prepare_pcm()
492 dev_err(player->dev, "%s: invalid nb of channels\n", __func__); in uni_player_prepare_pcm()
493 return -EINVAL; in uni_player_prepare_pcm()
496 SET_UNIPERIF_I2S_FMT_NUM_CH(player, runtime->channels / 2); in uni_player_prepare_pcm()
498 /* Set 1-bit audio format to disabled */ in uni_player_prepare_pcm()
517 int freq, ret; in uni_player_prepare_tdm() local
548 freq = runtime->rate * tdm_frame_size * 8; in uni_player_prepare_tdm()
549 mutex_lock(&player->ctrl_lock); in uni_player_prepare_tdm()
550 ret = uni_player_clk_set_rate(player, freq); in uni_player_prepare_tdm()
552 player->mclk = freq; in uni_player_prepare_tdm()
553 mutex_unlock(&player->ctrl_lock); in uni_player_prepare_tdm()
564 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; in uni_player_ctl_iec958_info()
565 uinfo->count = 1; in uni_player_ctl_iec958_info()
575 struct uniperif *player = priv->dai_data.uni; in uni_player_ctl_iec958_get()
576 struct snd_aes_iec958 *iec958 = &player->stream_settings.iec958; in uni_player_ctl_iec958_get()
578 mutex_lock(&player->ctrl_lock); in uni_player_ctl_iec958_get()
579 ucontrol->value.iec958.status[0] = iec958->status[0]; in uni_player_ctl_iec958_get()
580 ucontrol->value.iec958.status[1] = iec958->status[1]; in uni_player_ctl_iec958_get()
581 ucontrol->value.iec958.status[2] = iec958->status[2]; in uni_player_ctl_iec958_get()
582 ucontrol->value.iec958.status[3] = iec958->status[3]; in uni_player_ctl_iec958_get()
583 mutex_unlock(&player->ctrl_lock); in uni_player_ctl_iec958_get()
592 struct uniperif *player = priv->dai_data.uni; in uni_player_ctl_iec958_put()
593 struct snd_aes_iec958 *iec958 = &player->stream_settings.iec958; in uni_player_ctl_iec958_put()
596 mutex_lock(&player->ctrl_lock); in uni_player_ctl_iec958_put()
597 iec958->status[0] = ucontrol->value.iec958.status[0]; in uni_player_ctl_iec958_put()
598 iec958->status[1] = ucontrol->value.iec958.status[1]; in uni_player_ctl_iec958_put()
599 iec958->status[2] = ucontrol->value.iec958.status[2]; in uni_player_ctl_iec958_put()
600 iec958->status[3] = ucontrol->value.iec958.status[3]; in uni_player_ctl_iec958_put()
602 spin_lock_irqsave(&player->irq_lock, flags); in uni_player_ctl_iec958_put()
603 if (player->substream && player->substream->runtime) in uni_player_ctl_iec958_put()
605 player->substream->runtime); in uni_player_ctl_iec958_put()
609 spin_unlock_irqrestore(&player->irq_lock, flags); in uni_player_ctl_iec958_put()
610 mutex_unlock(&player->ctrl_lock); in uni_player_ctl_iec958_put()
629 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; in snd_sti_clk_adjustment_info()
630 uinfo->count = 1; in snd_sti_clk_adjustment_info()
631 uinfo->value.integer.min = UNIPERIF_PLAYER_CLK_ADJ_MIN; in snd_sti_clk_adjustment_info()
632 uinfo->value.integer.max = UNIPERIF_PLAYER_CLK_ADJ_MAX; in snd_sti_clk_adjustment_info()
633 uinfo->value.integer.step = 1; in snd_sti_clk_adjustment_info()
643 struct uniperif *player = priv->dai_data.uni; in snd_sti_clk_adjustment_get()
645 mutex_lock(&player->ctrl_lock); in snd_sti_clk_adjustment_get()
646 ucontrol->value.integer.value[0] = player->clk_adj; in snd_sti_clk_adjustment_get()
647 mutex_unlock(&player->ctrl_lock); in snd_sti_clk_adjustment_get()
657 struct uniperif *player = priv->dai_data.uni; in snd_sti_clk_adjustment_put()
660 if ((ucontrol->value.integer.value[0] < UNIPERIF_PLAYER_CLK_ADJ_MIN) || in snd_sti_clk_adjustment_put()
661 (ucontrol->value.integer.value[0] > UNIPERIF_PLAYER_CLK_ADJ_MAX)) in snd_sti_clk_adjustment_put()
662 return -EINVAL; in snd_sti_clk_adjustment_put()
664 mutex_lock(&player->ctrl_lock); in snd_sti_clk_adjustment_put()
665 player->clk_adj = ucontrol->value.integer.value[0]; in snd_sti_clk_adjustment_put()
667 if (player->mclk) in snd_sti_clk_adjustment_put()
668 ret = uni_player_clk_set_rate(player, player->mclk); in snd_sti_clk_adjustment_put()
669 mutex_unlock(&player->ctrl_lock); in snd_sti_clk_adjustment_put()
676 .name = "PCM Playback Oversampling Freq. Adjustment",
695 struct uniperif *player = priv->dai_data.uni; in uni_player_startup()
699 spin_lock_irqsave(&player->irq_lock, flags); in uni_player_startup()
700 player->substream = substream; in uni_player_startup()
701 spin_unlock_irqrestore(&player->irq_lock, flags); in uni_player_startup()
703 player->clk_adj = 0; in uni_player_startup()
709 ret = snd_pcm_hw_rule_add(substream->runtime, 0, in uni_player_startup()
713 -1); in uni_player_startup()
717 return snd_pcm_hw_rule_add(substream->runtime, 0, in uni_player_startup()
721 -1); in uni_player_startup()
725 unsigned int freq, int dir) in uni_player_set_sysclk() argument
728 struct uniperif *player = priv->dai_data.uni; in uni_player_set_sysclk()
735 return -EINVAL; in uni_player_set_sysclk()
737 mutex_lock(&player->ctrl_lock); in uni_player_set_sysclk()
738 ret = uni_player_clk_set_rate(player, freq); in uni_player_set_sysclk()
740 player->mclk = freq; in uni_player_set_sysclk()
741 mutex_unlock(&player->ctrl_lock); in uni_player_set_sysclk()
750 struct uniperif *player = priv->dai_data.uni; in uni_player_prepare()
751 struct snd_pcm_runtime *runtime = substream->runtime; in uni_player_prepare()
756 if (player->state != UNIPERIF_STATE_STOPPED) { in uni_player_prepare()
757 dev_err(player->dev, "%s: invalid player state %d\n", __func__, in uni_player_prepare()
758 player->state); in uni_player_prepare()
759 return -EINVAL; in uni_player_prepare()
763 if (player->type == SND_ST_UNIPERIF_TYPE_TDM) { in uni_player_prepare()
768 transfer_size = runtime->channels * UNIPERIF_FIFO_FRAMES; in uni_player_prepare()
772 if (player->ver < SND_ST_UNIPERIF_VERSION_UNI_PLR_TOP_1_0) { in uni_player_prepare()
773 trigger_limit = UNIPERIF_FIFO_SIZE - transfer_size; in uni_player_prepare()
786 dev_err(player->dev, "invalid trigger limit %d\n", in uni_player_prepare()
788 return -EINVAL; in uni_player_prepare()
794 switch (player->type) { in uni_player_prepare()
808 dev_err(player->dev, "invalid player type\n"); in uni_player_prepare()
809 return -EINVAL; in uni_player_prepare()
815 switch (player->daifmt & SND_SOC_DAIFMT_INV_MASK) { in uni_player_prepare()
834 switch (player->daifmt & SND_SOC_DAIFMT_FORMAT_MASK) { in uni_player_prepare()
848 dev_err(player->dev, "format not supported\n"); in uni_player_prepare()
849 return -EINVAL; in uni_player_prepare()
863 if (player->state != UNIPERIF_STATE_STOPPED) { in uni_player_start()
864 dev_err(player->dev, "%s: invalid player state\n", __func__); in uni_player_start()
865 return -EINVAL; in uni_player_start()
868 ret = clk_prepare_enable(player->clk); in uni_player_start()
870 dev_err(player->dev, "%s: Failed to enable clock\n", __func__); in uni_player_start()
882 if (player->underflow_enabled) { in uni_player_start()
889 clk_disable_unprepare(player->clk); in uni_player_start()
907 if (player->ver < SND_ST_UNIPERIF_VERSION_UNI_PLR_TOP_1_0) in uni_player_start()
912 if (player->ver < SND_ST_UNIPERIF_VERSION_UNI_PLR_TOP_1_0) in uni_player_start()
918 player->state = UNIPERIF_STATE_STARTED; in uni_player_start()
928 if (player->state == UNIPERIF_STATE_STOPPED) { in uni_player_stop()
929 dev_err(player->dev, "%s: invalid player state\n", __func__); in uni_player_stop()
930 return -EINVAL; in uni_player_stop()
944 clk_disable_unprepare(player->clk); in uni_player_stop()
947 player->state = UNIPERIF_STATE_STOPPED; in uni_player_stop()
956 /* Select the frequency synthesizer clock */ in uni_player_resume()
957 if (player->clk_sel) { in uni_player_resume()
958 ret = regmap_field_write(player->clk_sel, 1); in uni_player_resume()
960 dev_err(player->dev, in uni_player_resume()
961 "%s: Failed to select freq synth clock\n", in uni_player_resume()
980 struct uniperif *player = priv->dai_data.uni; in uni_player_trigger()
982 switch (cmd) { in uni_player_trigger()
990 return -EINVAL; in uni_player_trigger()
998 struct uniperif *player = priv->dai_data.uni; in uni_player_shutdown()
1001 spin_lock_irqsave(&player->irq_lock, flags); in uni_player_shutdown()
1002 if (player->state != UNIPERIF_STATE_STOPPED) in uni_player_shutdown()
1006 player->substream = NULL; in uni_player_shutdown()
1007 spin_unlock_irqrestore(&player->irq_lock, flags); in uni_player_shutdown()
1013 struct device_node *node = pdev->dev.of_node; in uni_player_parse_dt_audio_glue()
1018 8 + player->id, in uni_player_parse_dt_audio_glue()
1019 8 + player->id), in uni_player_parse_dt_audio_glue()
1027 dev_err(&pdev->dev, "sti-audio-clk-glue syscf not found\n"); in uni_player_parse_dt_audio_glue()
1031 player->clk_sel = regmap_field_alloc(regmap, regfield[0]); in uni_player_parse_dt_audio_glue()
1032 player->valid_sel = regmap_field_alloc(regmap, regfield[1]); in uni_player_parse_dt_audio_glue()
1054 player->dev = &pdev->dev; in uni_player_init()
1055 player->state = UNIPERIF_STATE_STOPPED; in uni_player_init()
1056 player->dai_ops = &uni_player_dai_ops; in uni_player_init()
1058 /* Get PCM_CLK_SEL & PCMP_VALID_SEL from audio-glue-ctrl SoC reg */ in uni_player_init()
1062 dev_err(player->dev, "Failed to parse DeviceTree\n"); in uni_player_init()
1067 if (player->ver >= SND_ST_UNIPERIF_VERSION_UNI_PLR_TOP_1_0) in uni_player_init()
1068 player->underflow_enabled = 1; in uni_player_init()
1071 player->hw = &uni_tdm_hw; in uni_player_init()
1073 player->hw = &uni_player_pcm_hw; in uni_player_init()
1076 player->clk = of_clk_get(pdev->dev.of_node, 0); in uni_player_init()
1077 if (IS_ERR(player->clk)) { in uni_player_init()
1078 dev_err(player->dev, "Failed to get clock\n"); in uni_player_init()
1079 return PTR_ERR(player->clk); in uni_player_init()
1082 /* Select the frequency synthesizer clock */ in uni_player_init()
1083 if (player->clk_sel) { in uni_player_init()
1084 ret = regmap_field_write(player->clk_sel, 1); in uni_player_init()
1086 dev_err(player->dev, in uni_player_init()
1087 "%s: Failed to select freq synth clock\n", in uni_player_init()
1094 if (player->valid_sel && in uni_player_init()
1095 (player->id == UNIPERIF_PLAYER_I2S_OUT)) { in uni_player_init()
1096 ret = regmap_field_write(player->valid_sel, player->id); in uni_player_init()
1098 dev_err(player->dev, in uni_player_init()
1104 ret = devm_request_irq(&pdev->dev, player->irq, in uni_player_init()
1106 dev_name(&pdev->dev), player); in uni_player_init()
1108 dev_err(player->dev, "unable to request IRQ %d\n", player->irq); in uni_player_init()
1112 mutex_init(&player->ctrl_lock); in uni_player_init()
1113 spin_lock_init(&player->irq_lock); in uni_player_init()
1125 player->stream_settings.iec958.status[0] = 0x00; in uni_player_init()
1127 player->stream_settings.iec958.status[1] = in uni_player_init()
1130 player->stream_settings.iec958.status[2] = in uni_player_init()
1133 player->stream_settings.iec958.status[3] = in uni_player_init()
1135 /* Max sample word 24-bit, sample word length not indicated */ in uni_player_init()
1136 player->stream_settings.iec958.status[4] = in uni_player_init()
1140 player->num_ctrls = ARRAY_SIZE(snd_sti_iec_ctl); in uni_player_init()
1141 player->snd_ctrls = snd_sti_iec_ctl[0]; in uni_player_init()
1143 player->num_ctrls = ARRAY_SIZE(snd_sti_pcm_ctl); in uni_player_init()
1144 player->snd_ctrls = snd_sti_pcm_ctl[0]; in uni_player_init()