Lines Matching +full:dai +full:- +full:format

1 // SPDX-License-Identifier: GPL-2.0-only
15 * User frame size shall be 2, 4, 6 or 8 32-bits words length
80 { .compatible = "st,stih407-uni-player-hdmi",
83 { .compatible = "st,stih407-uni-player-pcm-out",
86 { .compatible = "st,stih407-uni-player-dac",
89 { .compatible = "st,stih407-uni-player-spdif",
92 { .compatible = "st,stih407-uni-reader-pcm_in",
95 { .compatible = "st,stih407-uni-reader-hdmi",
109 if (uni->ver < SND_ST_UNIPERIF_VERSION_UNI_PLR_TOP_1_0) { in sti_uniperiph_reset()
112 count--; in sti_uniperiph_reset()
117 dev_err(uni->dev, "Failed to reset uniperif\n"); in sti_uniperiph_reset()
118 return -EIO; in sti_uniperiph_reset()
124 int sti_uniperiph_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask, in sti_uniperiph_set_tdm_slot() argument
128 struct sti_uniperiph_data *priv = snd_soc_dai_get_drvdata(dai); in sti_uniperiph_set_tdm_slot()
129 struct uniperif *uni = priv->dai_data.uni; in sti_uniperiph_set_tdm_slot()
133 dev_err(uni->dev, "cpu dai not in tdm mode\n"); in sti_uniperiph_set_tdm_slot()
134 return -EINVAL; in sti_uniperiph_set_tdm_slot()
138 uni->tdm_slot.slots = slots; in sti_uniperiph_set_tdm_slot()
139 uni->tdm_slot.slot_width = slot_width; in sti_uniperiph_set_tdm_slot()
141 uni->tdm_slot.mask = (tx_mask != 0) ? tx_mask : rx_mask; in sti_uniperiph_set_tdm_slot()
144 for (i = 0, avail_slots = 0; i < uni->tdm_slot.slots; i++) { in sti_uniperiph_set_tdm_slot()
145 if ((uni->tdm_slot.mask >> i) & 0x01) in sti_uniperiph_set_tdm_slot()
148 uni->tdm_slot.avail_slots = avail_slots; in sti_uniperiph_set_tdm_slot()
151 frame_size = uni->tdm_slot.avail_slots * uni->tdm_slot.slot_width / 8; in sti_uniperiph_set_tdm_slot()
156 dev_err(uni->dev, "frame size not allowed: %d bytes\n", in sti_uniperiph_set_tdm_slot()
158 return -EINVAL; in sti_uniperiph_set_tdm_slot()
167 struct uniperif *uni = rule->private; in sti_uniperiph_fix_tdm_chan()
170 t.min = uni->tdm_slot.avail_slots; in sti_uniperiph_fix_tdm_chan()
171 t.max = uni->tdm_slot.avail_slots; in sti_uniperiph_fix_tdm_chan()
176 return snd_interval_refine(hw_param_interval(params, rule->var), &t); in sti_uniperiph_fix_tdm_chan()
182 struct uniperif *uni = rule->private; in sti_uniperiph_fix_tdm_format()
183 struct snd_mask *maskp = hw_param_mask(params, rule->var); in sti_uniperiph_fix_tdm_format()
184 u64 format; in sti_uniperiph_fix_tdm_format() local
186 switch (uni->tdm_slot.slot_width) { in sti_uniperiph_fix_tdm_format()
188 format = SNDRV_PCM_FMTBIT_S16_LE; in sti_uniperiph_fix_tdm_format()
191 format = SNDRV_PCM_FMTBIT_S32_LE; in sti_uniperiph_fix_tdm_format()
194 dev_err(uni->dev, "format not supported: %d bits\n", in sti_uniperiph_fix_tdm_format()
195 uni->tdm_slot.slot_width); in sti_uniperiph_fix_tdm_format()
196 return -EINVAL; in sti_uniperiph_fix_tdm_format()
199 maskp->bits[0] &= (u_int32_t)format; in sti_uniperiph_fix_tdm_format()
200 maskp->bits[1] &= (u_int32_t)(format >> 32); in sti_uniperiph_fix_tdm_format()
202 memset(maskp->bits + 2, 0, (SNDRV_MASK_MAX - 64) / 8); in sti_uniperiph_fix_tdm_format()
204 if (!maskp->bits[0] && !maskp->bits[1]) in sti_uniperiph_fix_tdm_format()
205 return -EINVAL; in sti_uniperiph_fix_tdm_format()
213 int slot_width = uni->tdm_slot.slot_width / 8; in sti_uniperiph_get_tdm_word_pos()
214 int slots_num = uni->tdm_slot.slots; in sti_uniperiph_get_tdm_word_pos()
215 unsigned int slots_mask = uni->tdm_slot.mask; in sti_uniperiph_get_tdm_word_pos()
253 * This function is used to create Ctrl associated to DAI but also pcm device.
256 static int sti_uniperiph_dai_create_ctrl(struct snd_soc_dai *dai) in sti_uniperiph_dai_create_ctrl() argument
258 struct sti_uniperiph_data *priv = snd_soc_dai_get_drvdata(dai); in sti_uniperiph_dai_create_ctrl()
259 struct uniperif *uni = priv->dai_data.uni; in sti_uniperiph_dai_create_ctrl()
263 if (!uni->num_ctrls) in sti_uniperiph_dai_create_ctrl()
266 for (i = 0; i < uni->num_ctrls; i++) { in sti_uniperiph_dai_create_ctrl()
271 ctrl = &uni->snd_ctrls[i]; in sti_uniperiph_dai_create_ctrl()
272 ctrl->index = uni->id; in sti_uniperiph_dai_create_ctrl()
273 ctrl->device = uni->id; in sti_uniperiph_dai_create_ctrl()
276 return snd_soc_add_dai_controls(dai, uni->snd_ctrls, uni->num_ctrls); in sti_uniperiph_dai_create_ctrl()
280 * DAI
284 struct snd_soc_dai *dai) in sti_uniperiph_dai_hw_params() argument
286 struct sti_uniperiph_data *priv = snd_soc_dai_get_drvdata(dai); in sti_uniperiph_dai_hw_params()
287 struct uniperif *uni = priv->dai_data.uni; in sti_uniperiph_dai_hw_params()
291 if (uni->type == SND_ST_UNIPERIF_TYPE_TDM) in sti_uniperiph_dai_hw_params()
292 /* transfer size = user frame size (in 32-bits FIFO cell) */ in sti_uniperiph_dai_hw_params()
297 dma_data = snd_soc_dai_get_dma_data(dai, substream); in sti_uniperiph_dai_hw_params()
298 dma_data->maxburst = transfer_size; in sti_uniperiph_dai_hw_params()
303 int sti_uniperiph_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) in sti_uniperiph_dai_set_fmt() argument
305 struct sti_uniperiph_data *priv = snd_soc_dai_get_drvdata(dai); in sti_uniperiph_dai_set_fmt()
307 priv->dai_data.uni->daifmt = fmt; in sti_uniperiph_dai_set_fmt()
315 struct uniperif *uni = priv->dai_data.uni; in sti_uniperiph_suspend()
319 if (uni->state != UNIPERIF_STATE_STOPPED) { in sti_uniperiph_suspend()
320 dev_err(uni->dev, "%s: invalid uni state( %d)\n", in sti_uniperiph_suspend()
321 __func__, (int)uni->state); in sti_uniperiph_suspend()
322 return -EBUSY; in sti_uniperiph_suspend()
326 ret = pinctrl_pm_select_sleep_state(uni->dev); in sti_uniperiph_suspend()
328 dev_err(uni->dev, "%s: failed to select pinctrl state\n", in sti_uniperiph_suspend()
337 struct uniperif *uni = priv->dai_data.uni; in sti_uniperiph_resume()
340 if (priv->dai_data.stream == SNDRV_PCM_STREAM_PLAYBACK) { in sti_uniperiph_resume()
347 ret = pinctrl_pm_select_default_state(uni->dev); in sti_uniperiph_resume()
349 dev_err(uni->dev, "%s: failed to select pinctrl state\n", in sti_uniperiph_resume()
355 int sti_uniperiph_dai_probe(struct snd_soc_dai *dai) in sti_uniperiph_dai_probe() argument
357 struct sti_uniperiph_data *priv = snd_soc_dai_get_drvdata(dai); in sti_uniperiph_dai_probe()
358 struct sti_uniperiph_dai *dai_data = &priv->dai_data; in sti_uniperiph_dai_probe()
361 if (priv->dai_data.stream == SNDRV_PCM_STREAM_PLAYBACK) in sti_uniperiph_dai_probe()
362 snd_soc_dai_init_dma_data(dai, &dai_data->dma_data, NULL); in sti_uniperiph_dai_probe()
364 snd_soc_dai_init_dma_data(dai, NULL, &dai_data->dma_data); in sti_uniperiph_dai_probe()
366 dai_data->dma_data.addr = dai_data->uni->fifo_phys_address; in sti_uniperiph_dai_probe()
367 dai_data->dma_data.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; in sti_uniperiph_dai_probe()
369 return sti_uniperiph_dai_create_ctrl(dai); in sti_uniperiph_dai_probe()
390 struct device *dev = &priv->pdev->dev; in sti_uniperiph_cpu_dai_of()
391 struct sti_uniperiph_dai *dai_data = &priv->dai_data; in sti_uniperiph_cpu_dai_of()
392 struct snd_soc_dai_driver *dai = priv->dai; in sti_uniperiph_cpu_dai_of() local
402 if (!of_id->data) { in sti_uniperiph_cpu_dai_of()
404 return -EINVAL; in sti_uniperiph_cpu_dai_of()
406 dev_data = (struct sti_uniperiph_dev_data *)of_id->data; in sti_uniperiph_cpu_dai_of()
410 return -ENOMEM; in sti_uniperiph_cpu_dai_of()
412 uni->id = dev_data->id; in sti_uniperiph_cpu_dai_of()
413 uni->ver = dev_data->version; in sti_uniperiph_cpu_dai_of()
415 *dai = sti_uniperiph_dai_template; in sti_uniperiph_cpu_dai_of()
416 dai->name = dev_data->dai_names; in sti_uniperiph_cpu_dai_of()
419 uni->base = devm_platform_get_and_ioremap_resource(priv->pdev, 0, &uni->mem_region); in sti_uniperiph_cpu_dai_of()
420 if (IS_ERR(uni->base)) in sti_uniperiph_cpu_dai_of()
421 return PTR_ERR(uni->base); in sti_uniperiph_cpu_dai_of()
423 uni->fifo_phys_address = uni->mem_region->start + in sti_uniperiph_cpu_dai_of()
426 uni->irq = platform_get_irq(priv->pdev, 0); in sti_uniperiph_cpu_dai_of()
427 if (uni->irq < 0) in sti_uniperiph_cpu_dai_of()
428 return -ENXIO; in sti_uniperiph_cpu_dai_of()
430 uni->type = dev_data->type; in sti_uniperiph_cpu_dai_of()
433 if (dev_data->type & SND_ST_UNIPERIF_TYPE_TDM) { in sti_uniperiph_cpu_dai_of()
434 if (!of_property_read_string(node, "st,tdm-mode", &mode)) in sti_uniperiph_cpu_dai_of()
435 uni->type = SND_ST_UNIPERIF_TYPE_TDM; in sti_uniperiph_cpu_dai_of()
437 uni->type = SND_ST_UNIPERIF_TYPE_PCM; in sti_uniperiph_cpu_dai_of()
440 dai_data->uni = uni; in sti_uniperiph_cpu_dai_of()
441 dai_data->stream = dev_data->stream; in sti_uniperiph_cpu_dai_of()
443 if (priv->dai_data.stream == SNDRV_PCM_STREAM_PLAYBACK) { in sti_uniperiph_cpu_dai_of()
444 ret = uni_player_init(priv->pdev, uni); in sti_uniperiph_cpu_dai_of()
445 stream = &dai->playback; in sti_uniperiph_cpu_dai_of()
447 ret = uni_reader_init(priv->pdev, uni); in sti_uniperiph_cpu_dai_of()
448 stream = &dai->capture; in sti_uniperiph_cpu_dai_of()
453 dai->ops = uni->dai_ops; in sti_uniperiph_cpu_dai_of()
455 stream->stream_name = dai->name; in sti_uniperiph_cpu_dai_of()
456 stream->channels_min = uni->hw->channels_min; in sti_uniperiph_cpu_dai_of()
457 stream->channels_max = uni->hw->channels_max; in sti_uniperiph_cpu_dai_of()
458 stream->rates = uni->hw->rates; in sti_uniperiph_cpu_dai_of()
459 stream->formats = uni->hw->formats; in sti_uniperiph_cpu_dai_of()
467 struct device_node *node = pdev->dev.of_node; in sti_uniperiph_probe()
471 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); in sti_uniperiph_probe()
473 return -ENOMEM; in sti_uniperiph_probe()
474 priv->dai = devm_kzalloc(&pdev->dev, sizeof(*priv->dai), GFP_KERNEL); in sti_uniperiph_probe()
475 if (!priv->dai) in sti_uniperiph_probe()
476 return -ENOMEM; in sti_uniperiph_probe()
478 priv->pdev = pdev; in sti_uniperiph_probe()
484 dev_set_drvdata(&pdev->dev, priv); in sti_uniperiph_probe()
486 ret = devm_snd_soc_register_component(&pdev->dev, in sti_uniperiph_probe()
488 priv->dai, 1); in sti_uniperiph_probe()
492 return devm_snd_dmaengine_pcm_register(&pdev->dev, NULL, 0); in sti_uniperiph_probe()
497 .name = "sti-uniperiph-dai",
504 MODULE_DESCRIPTION("uniperipheral DAI driver");