Lines Matching refs:spdifrx
251 struct stm32_spdifrx_data *spdifrx = (struct stm32_spdifrx_data *)data; in stm32_spdifrx_dma_complete() local
252 struct platform_device *pdev = spdifrx->pdev; in stm32_spdifrx_dma_complete()
253 u32 *p_start = (u32 *)spdifrx->dmab->area; in stm32_spdifrx_dma_complete()
256 u16 *ub_ptr = (short *)spdifrx->ub; in stm32_spdifrx_dma_complete()
259 regmap_update_bits(spdifrx->regmap, STM32_SPDIFRX_CR, in stm32_spdifrx_dma_complete()
263 if (!spdifrx->dmab->area) in stm32_spdifrx_dma_complete()
278 spdifrx->cs[i] = (unsigned char)SPDIFRX_CSR_CSGET(*ptr); in stm32_spdifrx_dma_complete()
287 complete(&spdifrx->cs_completion); in stm32_spdifrx_dma_complete()
290 static int stm32_spdifrx_dma_ctrl_start(struct stm32_spdifrx_data *spdifrx) in stm32_spdifrx_dma_ctrl_start() argument
295 spdifrx->desc = dmaengine_prep_slave_single(spdifrx->ctrl_chan, in stm32_spdifrx_dma_ctrl_start()
296 spdifrx->dmab->addr, in stm32_spdifrx_dma_ctrl_start()
300 if (!spdifrx->desc) in stm32_spdifrx_dma_ctrl_start()
303 spdifrx->desc->callback = stm32_spdifrx_dma_complete; in stm32_spdifrx_dma_ctrl_start()
304 spdifrx->desc->callback_param = spdifrx; in stm32_spdifrx_dma_ctrl_start()
305 cookie = dmaengine_submit(spdifrx->desc); in stm32_spdifrx_dma_ctrl_start()
310 dma_async_issue_pending(spdifrx->ctrl_chan); in stm32_spdifrx_dma_ctrl_start()
315 static void stm32_spdifrx_dma_ctrl_stop(struct stm32_spdifrx_data *spdifrx) in stm32_spdifrx_dma_ctrl_stop() argument
317 dmaengine_terminate_async(spdifrx->ctrl_chan); in stm32_spdifrx_dma_ctrl_stop()
320 static int stm32_spdifrx_start_sync(struct stm32_spdifrx_data *spdifrx) in stm32_spdifrx_start_sync() argument
326 ret = regmap_update_bits(spdifrx->regmap, STM32_SPDIFRX_IMR, imr, imr); in stm32_spdifrx_start_sync()
330 spin_lock(&spdifrx->lock); in stm32_spdifrx_start_sync()
332 spdifrx->refcount++; in stm32_spdifrx_start_sync()
334 regmap_read(spdifrx->regmap, STM32_SPDIFRX_CR, &cr); in stm32_spdifrx_start_sync()
341 dev_dbg(&spdifrx->pdev->dev, "start synchronization\n"); in stm32_spdifrx_start_sync()
356 ret = regmap_update_bits(spdifrx->regmap, STM32_SPDIFRX_CR, in stm32_spdifrx_start_sync()
359 dev_err(&spdifrx->pdev->dev, in stm32_spdifrx_start_sync()
363 spin_unlock(&spdifrx->lock); in stm32_spdifrx_start_sync()
368 static void stm32_spdifrx_stop(struct stm32_spdifrx_data *spdifrx) in stm32_spdifrx_stop() argument
372 spin_lock(&spdifrx->lock); in stm32_spdifrx_stop()
374 if (--spdifrx->refcount) { in stm32_spdifrx_stop()
375 spin_unlock(&spdifrx->lock); in stm32_spdifrx_stop()
382 regmap_update_bits(spdifrx->regmap, STM32_SPDIFRX_CR, cr_mask, cr); in stm32_spdifrx_stop()
384 regmap_update_bits(spdifrx->regmap, STM32_SPDIFRX_IMR, in stm32_spdifrx_stop()
387 regmap_update_bits(spdifrx->regmap, STM32_SPDIFRX_IFCR, in stm32_spdifrx_stop()
391 regmap_read(spdifrx->regmap, STM32_SPDIFRX_DR, ®); in stm32_spdifrx_stop()
392 regmap_read(spdifrx->regmap, STM32_SPDIFRX_CSR, ®); in stm32_spdifrx_stop()
394 spin_unlock(&spdifrx->lock); in stm32_spdifrx_stop()
398 struct stm32_spdifrx_data *spdifrx) in stm32_spdifrx_dma_ctrl_register() argument
402 spdifrx->ctrl_chan = dma_request_chan(dev, "rx-ctrl"); in stm32_spdifrx_dma_ctrl_register()
403 if (IS_ERR(spdifrx->ctrl_chan)) { in stm32_spdifrx_dma_ctrl_register()
405 return PTR_ERR(spdifrx->ctrl_chan); in stm32_spdifrx_dma_ctrl_register()
408 spdifrx->dmab = devm_kzalloc(dev, sizeof(struct snd_dma_buffer), in stm32_spdifrx_dma_ctrl_register()
410 if (!spdifrx->dmab) in stm32_spdifrx_dma_ctrl_register()
413 spdifrx->dmab->dev.type = SNDRV_DMA_TYPE_DEV_IRAM; in stm32_spdifrx_dma_ctrl_register()
414 spdifrx->dmab->dev.dev = dev; in stm32_spdifrx_dma_ctrl_register()
415 ret = snd_dma_alloc_pages(spdifrx->dmab->dev.type, dev, in stm32_spdifrx_dma_ctrl_register()
416 SPDIFRX_CSR_BUF_LENGTH, spdifrx->dmab); in stm32_spdifrx_dma_ctrl_register()
422 spdifrx->slave_config.direction = DMA_DEV_TO_MEM; in stm32_spdifrx_dma_ctrl_register()
423 spdifrx->slave_config.src_addr = (dma_addr_t)(spdifrx->phys_addr + in stm32_spdifrx_dma_ctrl_register()
425 spdifrx->slave_config.dst_addr = spdifrx->dmab->addr; in stm32_spdifrx_dma_ctrl_register()
426 spdifrx->slave_config.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; in stm32_spdifrx_dma_ctrl_register()
427 spdifrx->slave_config.src_maxburst = 1; in stm32_spdifrx_dma_ctrl_register()
429 ret = dmaengine_slave_config(spdifrx->ctrl_chan, in stm32_spdifrx_dma_ctrl_register()
430 &spdifrx->slave_config); in stm32_spdifrx_dma_ctrl_register()
433 spdifrx->ctrl_chan = NULL; in stm32_spdifrx_dma_ctrl_register()
474 static int stm32_spdifrx_get_ctrl_data(struct stm32_spdifrx_data *spdifrx) in stm32_spdifrx_get_ctrl_data() argument
478 memset(spdifrx->cs, 0, SPDIFRX_CS_BYTES_NB); in stm32_spdifrx_get_ctrl_data()
479 memset(spdifrx->ub, 0, SPDIFRX_UB_BYTES_NB); in stm32_spdifrx_get_ctrl_data()
481 pinctrl_pm_select_default_state(&spdifrx->pdev->dev); in stm32_spdifrx_get_ctrl_data()
483 ret = stm32_spdifrx_dma_ctrl_start(spdifrx); in stm32_spdifrx_get_ctrl_data()
487 ret = clk_prepare_enable(spdifrx->kclk); in stm32_spdifrx_get_ctrl_data()
489 dev_err(&spdifrx->pdev->dev, "Enable kclk failed: %d\n", ret); in stm32_spdifrx_get_ctrl_data()
493 ret = regmap_update_bits(spdifrx->regmap, STM32_SPDIFRX_CR, in stm32_spdifrx_get_ctrl_data()
498 ret = stm32_spdifrx_start_sync(spdifrx); in stm32_spdifrx_get_ctrl_data()
502 if (wait_for_completion_interruptible_timeout(&spdifrx->cs_completion, in stm32_spdifrx_get_ctrl_data()
505 dev_dbg(&spdifrx->pdev->dev, "Failed to get control data\n"); in stm32_spdifrx_get_ctrl_data()
509 stm32_spdifrx_stop(spdifrx); in stm32_spdifrx_get_ctrl_data()
510 stm32_spdifrx_dma_ctrl_stop(spdifrx); in stm32_spdifrx_get_ctrl_data()
513 clk_disable_unprepare(spdifrx->kclk); in stm32_spdifrx_get_ctrl_data()
514 pinctrl_pm_select_sleep_state(&spdifrx->pdev->dev); in stm32_spdifrx_get_ctrl_data()
523 struct stm32_spdifrx_data *spdifrx = snd_soc_dai_get_drvdata(cpu_dai); in stm32_spdifrx_capture_get() local
525 stm32_spdifrx_get_ctrl_data(spdifrx); in stm32_spdifrx_capture_get()
527 ucontrol->value.iec958.status[0] = spdifrx->cs[0]; in stm32_spdifrx_capture_get()
528 ucontrol->value.iec958.status[1] = spdifrx->cs[1]; in stm32_spdifrx_capture_get()
529 ucontrol->value.iec958.status[2] = spdifrx->cs[2]; in stm32_spdifrx_capture_get()
530 ucontrol->value.iec958.status[3] = spdifrx->cs[3]; in stm32_spdifrx_capture_get()
531 ucontrol->value.iec958.status[4] = spdifrx->cs[4]; in stm32_spdifrx_capture_get()
540 struct stm32_spdifrx_data *spdifrx = snd_soc_dai_get_drvdata(cpu_dai); in stm32_spdif_user_bits_get() local
542 stm32_spdifrx_get_ctrl_data(spdifrx); in stm32_spdif_user_bits_get()
544 ucontrol->value.iec958.status[0] = spdifrx->ub[0]; in stm32_spdif_user_bits_get()
545 ucontrol->value.iec958.status[1] = spdifrx->ub[1]; in stm32_spdif_user_bits_get()
546 ucontrol->value.iec958.status[2] = spdifrx->ub[2]; in stm32_spdif_user_bits_get()
547 ucontrol->value.iec958.status[3] = spdifrx->ub[3]; in stm32_spdif_user_bits_get()
548 ucontrol->value.iec958.status[4] = spdifrx->ub[4]; in stm32_spdif_user_bits_get()
595 struct stm32_spdifrx_data *spdifrx = dev_get_drvdata(cpu_dai->dev); in stm32_spdifrx_dai_probe() local
597 spdifrx->dma_params.addr = (dma_addr_t)(spdifrx->phys_addr + in stm32_spdifrx_dai_probe()
599 spdifrx->dma_params.maxburst = 1; in stm32_spdifrx_dai_probe()
601 snd_soc_dai_init_dma_data(cpu_dai, NULL, &spdifrx->dma_params); in stm32_spdifrx_dai_probe()
665 struct stm32_spdifrx_data *spdifrx = (struct stm32_spdifrx_data *)devid; in stm32_spdifrx_isr() local
666 struct snd_pcm_substream *substream = spdifrx->substream; in stm32_spdifrx_isr()
667 struct platform_device *pdev = spdifrx->pdev; in stm32_spdifrx_isr()
672 regmap_read(spdifrx->regmap, STM32_SPDIFRX_SR, &sr); in stm32_spdifrx_isr()
673 regmap_read(spdifrx->regmap, STM32_SPDIFRX_IMR, &imr); in stm32_spdifrx_isr()
688 regmap_update_bits(spdifrx->regmap, STM32_SPDIFRX_IFCR, in stm32_spdifrx_isr()
709 regmap_update_bits(spdifrx->regmap, STM32_SPDIFRX_CR, in stm32_spdifrx_isr()
731 regmap_update_bits(spdifrx->regmap, STM32_SPDIFRX_CR, in stm32_spdifrx_isr()
749 struct stm32_spdifrx_data *spdifrx = snd_soc_dai_get_drvdata(cpu_dai); in stm32_spdifrx_startup() local
752 spdifrx->substream = substream; in stm32_spdifrx_startup()
754 ret = clk_prepare_enable(spdifrx->kclk); in stm32_spdifrx_startup()
756 dev_err(&spdifrx->pdev->dev, "Enable kclk failed: %d\n", ret); in stm32_spdifrx_startup()
765 struct stm32_spdifrx_data *spdifrx = snd_soc_dai_get_drvdata(cpu_dai); in stm32_spdifrx_hw_params() local
777 dev_err(&spdifrx->pdev->dev, "Unexpected data format\n"); in stm32_spdifrx_hw_params()
786 spdifrx->dma_params.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; in stm32_spdifrx_hw_params()
787 snd_soc_dai_init_dma_data(cpu_dai, NULL, &spdifrx->dma_params); in stm32_spdifrx_hw_params()
789 return regmap_update_bits(spdifrx->regmap, STM32_SPDIFRX_CR, in stm32_spdifrx_hw_params()
797 struct stm32_spdifrx_data *spdifrx = snd_soc_dai_get_drvdata(cpu_dai); in stm32_spdifrx_trigger() local
804 regmap_update_bits(spdifrx->regmap, STM32_SPDIFRX_IMR, in stm32_spdifrx_trigger()
807 regmap_update_bits(spdifrx->regmap, STM32_SPDIFRX_CR, in stm32_spdifrx_trigger()
810 ret = stm32_spdifrx_start_sync(spdifrx); in stm32_spdifrx_trigger()
815 stm32_spdifrx_stop(spdifrx); in stm32_spdifrx_trigger()
827 struct stm32_spdifrx_data *spdifrx = snd_soc_dai_get_drvdata(cpu_dai); in stm32_spdifrx_shutdown() local
829 spdifrx->substream = NULL; in stm32_spdifrx_shutdown()
830 clk_disable_unprepare(spdifrx->kclk); in stm32_spdifrx_shutdown()
882 struct stm32_spdifrx_data *spdifrx) in stm32_spdifrx_parse_of() argument
893 spdifrx->regmap_conf = in stm32_spdifrx_parse_of()
899 spdifrx->base = devm_ioremap_resource(&pdev->dev, res); in stm32_spdifrx_parse_of()
900 if (IS_ERR(spdifrx->base)) in stm32_spdifrx_parse_of()
901 return PTR_ERR(spdifrx->base); in stm32_spdifrx_parse_of()
903 spdifrx->phys_addr = res->start; in stm32_spdifrx_parse_of()
905 spdifrx->kclk = devm_clk_get(&pdev->dev, "kclk"); in stm32_spdifrx_parse_of()
906 if (IS_ERR(spdifrx->kclk)) { in stm32_spdifrx_parse_of()
908 return PTR_ERR(spdifrx->kclk); in stm32_spdifrx_parse_of()
911 spdifrx->irq = platform_get_irq(pdev, 0); in stm32_spdifrx_parse_of()
912 if (spdifrx->irq < 0) in stm32_spdifrx_parse_of()
913 return spdifrx->irq; in stm32_spdifrx_parse_of()
920 struct stm32_spdifrx_data *spdifrx; in stm32_spdifrx_probe() local
926 spdifrx = devm_kzalloc(&pdev->dev, sizeof(*spdifrx), GFP_KERNEL); in stm32_spdifrx_probe()
927 if (!spdifrx) in stm32_spdifrx_probe()
930 spdifrx->pdev = pdev; in stm32_spdifrx_probe()
931 init_completion(&spdifrx->cs_completion); in stm32_spdifrx_probe()
932 spin_lock_init(&spdifrx->lock); in stm32_spdifrx_probe()
934 platform_set_drvdata(pdev, spdifrx); in stm32_spdifrx_probe()
936 ret = stm32_spdifrx_parse_of(pdev, spdifrx); in stm32_spdifrx_probe()
940 spdifrx->regmap = devm_regmap_init_mmio_clk(&pdev->dev, "kclk", in stm32_spdifrx_probe()
941 spdifrx->base, in stm32_spdifrx_probe()
942 spdifrx->regmap_conf); in stm32_spdifrx_probe()
943 if (IS_ERR(spdifrx->regmap)) { in stm32_spdifrx_probe()
945 return PTR_ERR(spdifrx->regmap); in stm32_spdifrx_probe()
948 ret = devm_request_irq(&pdev->dev, spdifrx->irq, stm32_spdifrx_isr, 0, in stm32_spdifrx_probe()
949 dev_name(&pdev->dev), spdifrx); in stm32_spdifrx_probe()
969 ret = stm32_spdifrx_dma_ctrl_register(&pdev->dev, spdifrx); in stm32_spdifrx_probe()
980 ret = regmap_read(spdifrx->regmap, STM32_SPDIFRX_IDR, &idr); in stm32_spdifrx_probe()
985 ret = regmap_read(spdifrx->regmap, STM32_SPDIFRX_VERR, &ver); in stm32_spdifrx_probe()
995 if (!IS_ERR(spdifrx->ctrl_chan)) in stm32_spdifrx_probe()
996 dma_release_channel(spdifrx->ctrl_chan); in stm32_spdifrx_probe()
997 if (spdifrx->dmab) in stm32_spdifrx_probe()
998 snd_dma_free_pages(spdifrx->dmab); in stm32_spdifrx_probe()
1005 struct stm32_spdifrx_data *spdifrx = platform_get_drvdata(pdev); in stm32_spdifrx_remove() local
1007 if (spdifrx->ctrl_chan) in stm32_spdifrx_remove()
1008 dma_release_channel(spdifrx->ctrl_chan); in stm32_spdifrx_remove()
1010 if (spdifrx->dmab) in stm32_spdifrx_remove()
1011 snd_dma_free_pages(spdifrx->dmab); in stm32_spdifrx_remove()
1021 struct stm32_spdifrx_data *spdifrx = dev_get_drvdata(dev); in stm32_spdifrx_suspend() local
1023 regcache_cache_only(spdifrx->regmap, true); in stm32_spdifrx_suspend()
1024 regcache_mark_dirty(spdifrx->regmap); in stm32_spdifrx_suspend()
1031 struct stm32_spdifrx_data *spdifrx = dev_get_drvdata(dev); in stm32_spdifrx_resume() local
1033 regcache_cache_only(spdifrx->regmap, false); in stm32_spdifrx_resume()
1035 return regcache_sync(spdifrx->regmap); in stm32_spdifrx_resume()