Lines Matching +full:i2s +full:- +full:regs
1 // SPDX-License-Identifier: GPL-2.0-only
3 * tegra30_i2s.c - Tegra30 I2S driver
6 * Copyright (c) 2010-2012, NVIDIA CORPORATION. All rights reserved.
10 * Copyright (c) 2009-2010, NVIDIA Corporation.
36 #define DRV_NAME "tegra30-i2s"
40 struct tegra30_i2s *i2s = dev_get_drvdata(dev); in tegra30_i2s_runtime_suspend() local
42 regcache_cache_only(i2s->regmap, true); in tegra30_i2s_runtime_suspend()
44 clk_disable_unprepare(i2s->clk_i2s); in tegra30_i2s_runtime_suspend()
51 struct tegra30_i2s *i2s = dev_get_drvdata(dev); in tegra30_i2s_runtime_resume() local
54 ret = clk_prepare_enable(i2s->clk_i2s); in tegra30_i2s_runtime_resume()
60 regcache_cache_only(i2s->regmap, false); in tegra30_i2s_runtime_resume()
61 regcache_mark_dirty(i2s->regmap); in tegra30_i2s_runtime_resume()
63 ret = regcache_sync(i2s->regmap); in tegra30_i2s_runtime_resume()
70 clk_disable_unprepare(i2s->clk_i2s); in tegra30_i2s_runtime_resume()
78 struct tegra30_i2s *i2s = snd_soc_dai_get_drvdata(dai); in tegra30_i2s_set_fmt() local
85 return -EINVAL; in tegra30_i2s_set_fmt()
96 return -EINVAL; in tegra30_i2s_set_fmt()
123 return -EINVAL; in tegra30_i2s_set_fmt()
126 pm_runtime_get_sync(dai->dev); in tegra30_i2s_set_fmt()
127 regmap_update_bits(i2s->regmap, TEGRA30_I2S_CTRL, mask, val); in tegra30_i2s_set_fmt()
128 pm_runtime_put(dai->dev); in tegra30_i2s_set_fmt()
137 struct device *dev = dai->dev; in tegra30_i2s_hw_params()
138 struct tegra30_i2s *i2s = snd_soc_dai_get_drvdata(dai); in tegra30_i2s_hw_params() local
144 return -EINVAL; in tegra30_i2s_hw_params()
153 return -EINVAL; in tegra30_i2s_hw_params()
156 regmap_update_bits(i2s->regmap, TEGRA30_I2S_CTRL, mask, val); in tegra30_i2s_hw_params()
163 bitcnt = (i2sclock / (2 * srate)) - 1; in tegra30_i2s_hw_params()
165 return -EINVAL; in tegra30_i2s_hw_params()
167 ret = clk_set_rate(i2s->clk_i2s, i2sclock); in tegra30_i2s_hw_params()
169 dev_err(dev, "Can't set I2S clock rate: %d\n", ret); in tegra30_i2s_hw_params()
178 regmap_write(i2s->regmap, TEGRA30_I2S_TIMING, val); in tegra30_i2s_hw_params()
191 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { in tegra30_i2s_hw_params()
199 i2s->soc_data->set_audio_cif(i2s->regmap, reg, &cif_conf); in tegra30_i2s_hw_params()
203 regmap_write(i2s->regmap, TEGRA30_I2S_OFFSET, val); in tegra30_i2s_hw_params()
208 static void tegra30_i2s_start_playback(struct tegra30_i2s *i2s) in tegra30_i2s_start_playback() argument
210 tegra30_ahub_enable_tx_fifo(i2s->playback_fifo_cif); in tegra30_i2s_start_playback()
211 regmap_update_bits(i2s->regmap, TEGRA30_I2S_CTRL, in tegra30_i2s_start_playback()
216 static void tegra30_i2s_stop_playback(struct tegra30_i2s *i2s) in tegra30_i2s_stop_playback() argument
218 tegra30_ahub_disable_tx_fifo(i2s->playback_fifo_cif); in tegra30_i2s_stop_playback()
219 regmap_update_bits(i2s->regmap, TEGRA30_I2S_CTRL, in tegra30_i2s_stop_playback()
223 static void tegra30_i2s_start_capture(struct tegra30_i2s *i2s) in tegra30_i2s_start_capture() argument
225 tegra30_ahub_enable_rx_fifo(i2s->capture_fifo_cif); in tegra30_i2s_start_capture()
226 regmap_update_bits(i2s->regmap, TEGRA30_I2S_CTRL, in tegra30_i2s_start_capture()
231 static void tegra30_i2s_stop_capture(struct tegra30_i2s *i2s) in tegra30_i2s_stop_capture() argument
233 regmap_update_bits(i2s->regmap, TEGRA30_I2S_CTRL, in tegra30_i2s_stop_capture()
235 tegra30_ahub_disable_rx_fifo(i2s->capture_fifo_cif); in tegra30_i2s_stop_capture()
241 struct tegra30_i2s *i2s = snd_soc_dai_get_drvdata(dai); in tegra30_i2s_trigger() local
247 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) in tegra30_i2s_trigger()
248 tegra30_i2s_start_playback(i2s); in tegra30_i2s_trigger()
250 tegra30_i2s_start_capture(i2s); in tegra30_i2s_trigger()
255 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) in tegra30_i2s_trigger()
256 tegra30_i2s_stop_playback(i2s); in tegra30_i2s_trigger()
258 tegra30_i2s_stop_capture(i2s); in tegra30_i2s_trigger()
261 return -EINVAL; in tegra30_i2s_trigger()
271 struct tegra30_i2s *i2s = snd_soc_dai_get_drvdata(dai); in tegra30_i2s_set_tdm() local
274 dev_dbg(dai->dev, "%s: txmask=0x%08x rxmask=0x%08x slots=%d width=%d\n", in tegra30_i2s_set_tdm()
283 ((slots - 1) << TEGRA30_I2S_SLOT_CTRL_TOTAL_SLOTS_SHIFT); in tegra30_i2s_set_tdm()
285 pm_runtime_get_sync(dai->dev); in tegra30_i2s_set_tdm()
286 regmap_update_bits(i2s->regmap, TEGRA30_I2S_SLOT_CTRL, mask, val); in tegra30_i2s_set_tdm()
288 regmap_update_bits(i2s->regmap, TEGRA30_I2S_CH_CTRL, in tegra30_i2s_set_tdm()
290 pm_runtime_put(dai->dev); in tegra30_i2s_set_tdm()
297 struct tegra30_i2s *i2s = snd_soc_dai_get_drvdata(dai); in tegra30_i2s_probe() local
299 snd_soc_dai_init_dma_data(dai, &i2s->playback_dma_data, in tegra30_i2s_probe()
300 &i2s->capture_dma_data); in tegra30_i2s_probe()
401 { .compatible = "nvidia,tegra124-i2s", .data = &tegra124_i2s_config },
402 { .compatible = "nvidia,tegra30-i2s", .data = &tegra30_i2s_config },
408 struct tegra30_i2s *i2s; in tegra30_i2s_platform_probe() local
411 void __iomem *regs; in tegra30_i2s_platform_probe() local
414 i2s = devm_kzalloc(&pdev->dev, sizeof(struct tegra30_i2s), GFP_KERNEL); in tegra30_i2s_platform_probe()
415 if (!i2s) { in tegra30_i2s_platform_probe()
416 ret = -ENOMEM; in tegra30_i2s_platform_probe()
419 dev_set_drvdata(&pdev->dev, i2s); in tegra30_i2s_platform_probe()
421 soc_data = of_device_get_match_data(&pdev->dev); in tegra30_i2s_platform_probe()
423 dev_err(&pdev->dev, "Error: No device match found\n"); in tegra30_i2s_platform_probe()
424 ret = -ENODEV; in tegra30_i2s_platform_probe()
427 i2s->soc_data = soc_data; in tegra30_i2s_platform_probe()
429 i2s->dai = tegra30_i2s_dai_template; in tegra30_i2s_platform_probe()
430 i2s->dai.name = dev_name(&pdev->dev); in tegra30_i2s_platform_probe()
432 ret = of_property_read_u32_array(pdev->dev.of_node, in tegra30_i2s_platform_probe()
433 "nvidia,ahub-cif-ids", cif_ids, in tegra30_i2s_platform_probe()
438 i2s->playback_i2s_cif = cif_ids[0]; in tegra30_i2s_platform_probe()
439 i2s->capture_i2s_cif = cif_ids[1]; in tegra30_i2s_platform_probe()
441 i2s->clk_i2s = devm_clk_get(&pdev->dev, NULL); in tegra30_i2s_platform_probe()
442 if (IS_ERR(i2s->clk_i2s)) { in tegra30_i2s_platform_probe()
443 dev_err(&pdev->dev, "Can't retrieve i2s clock\n"); in tegra30_i2s_platform_probe()
444 ret = PTR_ERR(i2s->clk_i2s); in tegra30_i2s_platform_probe()
448 regs = devm_platform_ioremap_resource(pdev, 0); in tegra30_i2s_platform_probe()
449 if (IS_ERR(regs)) { in tegra30_i2s_platform_probe()
450 ret = PTR_ERR(regs); in tegra30_i2s_platform_probe()
454 i2s->regmap = devm_regmap_init_mmio(&pdev->dev, regs, in tegra30_i2s_platform_probe()
456 if (IS_ERR(i2s->regmap)) { in tegra30_i2s_platform_probe()
457 dev_err(&pdev->dev, "regmap init failed\n"); in tegra30_i2s_platform_probe()
458 ret = PTR_ERR(i2s->regmap); in tegra30_i2s_platform_probe()
461 regcache_cache_only(i2s->regmap, true); in tegra30_i2s_platform_probe()
463 pm_runtime_enable(&pdev->dev); in tegra30_i2s_platform_probe()
465 i2s->playback_dma_data.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; in tegra30_i2s_platform_probe()
466 i2s->playback_dma_data.maxburst = 4; in tegra30_i2s_platform_probe()
467 ret = tegra30_ahub_allocate_tx_fifo(&i2s->playback_fifo_cif, in tegra30_i2s_platform_probe()
468 i2s->playback_dma_chan, in tegra30_i2s_platform_probe()
469 sizeof(i2s->playback_dma_chan), in tegra30_i2s_platform_probe()
470 &i2s->playback_dma_data.addr); in tegra30_i2s_platform_probe()
472 dev_err(&pdev->dev, "Could not alloc TX FIFO: %d\n", ret); in tegra30_i2s_platform_probe()
475 ret = tegra30_ahub_set_rx_cif_source(i2s->playback_i2s_cif, in tegra30_i2s_platform_probe()
476 i2s->playback_fifo_cif); in tegra30_i2s_platform_probe()
478 dev_err(&pdev->dev, "Could not route TX FIFO: %d\n", ret); in tegra30_i2s_platform_probe()
482 i2s->capture_dma_data.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; in tegra30_i2s_platform_probe()
483 i2s->capture_dma_data.maxburst = 4; in tegra30_i2s_platform_probe()
484 ret = tegra30_ahub_allocate_rx_fifo(&i2s->capture_fifo_cif, in tegra30_i2s_platform_probe()
485 i2s->capture_dma_chan, in tegra30_i2s_platform_probe()
486 sizeof(i2s->capture_dma_chan), in tegra30_i2s_platform_probe()
487 &i2s->capture_dma_data.addr); in tegra30_i2s_platform_probe()
489 dev_err(&pdev->dev, "Could not alloc RX FIFO: %d\n", ret); in tegra30_i2s_platform_probe()
492 ret = tegra30_ahub_set_rx_cif_source(i2s->capture_fifo_cif, in tegra30_i2s_platform_probe()
493 i2s->capture_i2s_cif); in tegra30_i2s_platform_probe()
495 dev_err(&pdev->dev, "Could not route TX FIFO: %d\n", ret); in tegra30_i2s_platform_probe()
499 ret = snd_soc_register_component(&pdev->dev, &tegra30_i2s_component, in tegra30_i2s_platform_probe()
500 &i2s->dai, 1); in tegra30_i2s_platform_probe()
502 dev_err(&pdev->dev, "Could not register DAI: %d\n", ret); in tegra30_i2s_platform_probe()
503 ret = -ENOMEM; in tegra30_i2s_platform_probe()
507 ret = tegra_pcm_platform_register_with_chan_names(&pdev->dev, in tegra30_i2s_platform_probe()
508 &i2s->dma_config, i2s->playback_dma_chan, in tegra30_i2s_platform_probe()
509 i2s->capture_dma_chan); in tegra30_i2s_platform_probe()
511 dev_err(&pdev->dev, "Could not register PCM: %d\n", ret); in tegra30_i2s_platform_probe()
518 snd_soc_unregister_component(&pdev->dev); in tegra30_i2s_platform_probe()
520 tegra30_ahub_unset_rx_cif_source(i2s->capture_fifo_cif); in tegra30_i2s_platform_probe()
522 tegra30_ahub_free_rx_fifo(i2s->capture_fifo_cif); in tegra30_i2s_platform_probe()
524 tegra30_ahub_unset_rx_cif_source(i2s->playback_i2s_cif); in tegra30_i2s_platform_probe()
526 tegra30_ahub_free_tx_fifo(i2s->playback_fifo_cif); in tegra30_i2s_platform_probe()
528 pm_runtime_disable(&pdev->dev); in tegra30_i2s_platform_probe()
535 struct tegra30_i2s *i2s = dev_get_drvdata(&pdev->dev); in tegra30_i2s_platform_remove() local
537 tegra_pcm_platform_unregister(&pdev->dev); in tegra30_i2s_platform_remove()
538 snd_soc_unregister_component(&pdev->dev); in tegra30_i2s_platform_remove()
540 tegra30_ahub_unset_rx_cif_source(i2s->capture_fifo_cif); in tegra30_i2s_platform_remove()
541 tegra30_ahub_free_rx_fifo(i2s->capture_fifo_cif); in tegra30_i2s_platform_remove()
543 tegra30_ahub_unset_rx_cif_source(i2s->playback_i2s_cif); in tegra30_i2s_platform_remove()
544 tegra30_ahub_free_tx_fifo(i2s->playback_fifo_cif); in tegra30_i2s_platform_remove()
546 pm_runtime_disable(&pdev->dev); in tegra30_i2s_platform_remove()
568 MODULE_DESCRIPTION("Tegra30 I2S ASoC driver");