Lines Matching +full:dai +full:- +full:tdm +full:- +full:tdm +full:- +full:slot +full:- +full:with

1 // SPDX-License-Identifier: GPL-2.0-only
12 #define UNIPERIF_READER_I2S_IN 0 /* reader id connected to I2S/TDM TX bus */
41 * stream lock to avoid race condition with trigger callback.
49 spin_lock(&reader->irq_lock); in uni_reader_irq_handler()
50 if (!reader->substream) in uni_reader_irq_handler()
53 snd_pcm_stream_lock(reader->substream); in uni_reader_irq_handler()
54 if (reader->state == UNIPERIF_STATE_STOPPED) { in uni_reader_irq_handler()
56 dev_warn(reader->dev, "unexpected IRQ\n"); in uni_reader_irq_handler()
66 dev_err(reader->dev, "FIFO error detected\n"); in uni_reader_irq_handler()
68 snd_pcm_stop(reader->substream, SNDRV_PCM_STATE_XRUN); in uni_reader_irq_handler()
74 snd_pcm_stream_unlock(reader->substream); in uni_reader_irq_handler()
76 spin_unlock(&reader->irq_lock); in uni_reader_irq_handler()
86 /* Force slot width to 32 in I2S mode */ in uni_reader_prepare_pcm()
87 if ((reader->daifmt & SND_SOC_DAIFMT_FORMAT_MASK) in uni_reader_prepare_pcm()
91 switch (runtime->format) { in uni_reader_prepare_pcm()
112 dev_err(reader->dev, "subframe format not supported\n"); in uni_reader_prepare_pcm()
113 return -EINVAL; in uni_reader_prepare_pcm()
117 switch (runtime->format) { in uni_reader_prepare_pcm()
132 dev_err(reader->dev, "format not supported\n"); in uni_reader_prepare_pcm()
133 return -EINVAL; in uni_reader_prepare_pcm()
137 if ((runtime->channels % 2) || (runtime->channels < 2) || in uni_reader_prepare_pcm()
138 (runtime->channels > 10)) { in uni_reader_prepare_pcm()
139 dev_err(reader->dev, "%s: invalid nb of channels\n", __func__); in uni_reader_prepare_pcm()
140 return -EINVAL; in uni_reader_prepare_pcm()
143 SET_UNIPERIF_I2S_FMT_NUM_CH(reader, runtime->channels / 2); in uni_reader_prepare_pcm()
152 int frame_size; /* user tdm frame size in bytes */ in uni_reader_prepare_tdm()
163 /* number of words inserted on the TDM line */ in uni_reader_prepare_tdm()
187 struct snd_soc_dai *dai) in uni_reader_prepare() argument
189 struct sti_uniperiph_data *priv = snd_soc_dai_get_drvdata(dai); in uni_reader_prepare()
190 struct uniperif *reader = priv->dai_data.uni; in uni_reader_prepare()
191 struct snd_pcm_runtime *runtime = substream->runtime; in uni_reader_prepare()
195 if (reader->state != UNIPERIF_STATE_STOPPED) { in uni_reader_prepare()
196 dev_err(reader->dev, "%s: invalid reader state %d\n", __func__, in uni_reader_prepare()
197 reader->state); in uni_reader_prepare()
198 return -EINVAL; in uni_reader_prepare()
202 if (reader->type == SND_ST_UNIPERIF_TYPE_TDM) { in uni_reader_prepare()
207 transfer_size = runtime->channels * UNIPERIF_FIFO_FRAMES; in uni_reader_prepare()
211 if (reader->ver < SND_ST_UNIPERIF_VERSION_UNI_PLR_TOP_1_0) in uni_reader_prepare()
212 trigger_limit = UNIPERIF_FIFO_SIZE - transfer_size; in uni_reader_prepare()
225 dev_err(reader->dev, "invalid trigger limit %d\n", in uni_reader_prepare()
227 return -EINVAL; in uni_reader_prepare()
239 switch (reader->daifmt & SND_SOC_DAIFMT_FORMAT_MASK) { in uni_reader_prepare()
253 dev_err(reader->dev, "format not supported\n"); in uni_reader_prepare()
254 return -EINVAL; in uni_reader_prepare()
258 switch (reader->daifmt & SND_SOC_DAIFMT_INV_MASK) { in uni_reader_prepare()
288 if (reader->underflow_enabled) { in uni_reader_prepare()
300 if (reader->state != UNIPERIF_STATE_STOPPED) { in uni_reader_start()
301 dev_err(reader->dev, "%s: invalid reader state\n", __func__); in uni_reader_start()
302 return -EINVAL; in uni_reader_start()
313 reader->state = UNIPERIF_STATE_STARTED; in uni_reader_start()
320 if (reader->state == UNIPERIF_STATE_STOPPED) { in uni_reader_stop()
321 dev_err(reader->dev, "%s: invalid reader state\n", __func__); in uni_reader_stop()
322 return -EINVAL; in uni_reader_stop()
332 reader->state = UNIPERIF_STATE_STOPPED; in uni_reader_stop()
338 int cmd, struct snd_soc_dai *dai) in uni_reader_trigger() argument
340 struct sti_uniperiph_data *priv = snd_soc_dai_get_drvdata(dai); in uni_reader_trigger()
341 struct uniperif *reader = priv->dai_data.uni; in uni_reader_trigger()
349 return -EINVAL; in uni_reader_trigger()
354 struct snd_soc_dai *dai) in uni_reader_startup() argument
356 struct sti_uniperiph_data *priv = snd_soc_dai_get_drvdata(dai); in uni_reader_startup()
357 struct uniperif *reader = priv->dai_data.uni; in uni_reader_startup()
361 spin_lock_irqsave(&reader->irq_lock, flags); in uni_reader_startup()
362 reader->substream = substream; in uni_reader_startup()
363 spin_unlock_irqrestore(&reader->irq_lock, flags); in uni_reader_startup()
368 /* refine hw constraint in tdm mode */ in uni_reader_startup()
369 ret = snd_pcm_hw_rule_add(substream->runtime, 0, in uni_reader_startup()
373 -1); in uni_reader_startup()
377 return snd_pcm_hw_rule_add(substream->runtime, 0, in uni_reader_startup()
381 -1); in uni_reader_startup()
385 struct snd_soc_dai *dai) in uni_reader_shutdown() argument
387 struct sti_uniperiph_data *priv = snd_soc_dai_get_drvdata(dai); in uni_reader_shutdown()
388 struct uniperif *reader = priv->dai_data.uni; in uni_reader_shutdown()
391 spin_lock_irqsave(&reader->irq_lock, flags); in uni_reader_shutdown()
392 if (reader->state != UNIPERIF_STATE_STOPPED) { in uni_reader_shutdown()
396 reader->substream = NULL; in uni_reader_shutdown()
397 spin_unlock_irqrestore(&reader->irq_lock, flags); in uni_reader_shutdown()
416 reader->dev = &pdev->dev; in uni_reader_init()
417 reader->state = UNIPERIF_STATE_STOPPED; in uni_reader_init()
418 reader->dai_ops = &uni_reader_dai_ops; in uni_reader_init()
421 reader->hw = &uni_tdm_hw; in uni_reader_init()
423 reader->hw = &uni_reader_pcm_hw; in uni_reader_init()
425 ret = devm_request_irq(&pdev->dev, reader->irq, in uni_reader_init()
427 dev_name(&pdev->dev), reader); in uni_reader_init()
429 dev_err(&pdev->dev, "Failed to request IRQ\n"); in uni_reader_init()
430 return -EBUSY; in uni_reader_init()
433 spin_lock_init(&reader->irq_lock); in uni_reader_init()