Lines Matching +full:ac97 +full:- +full:controller

1 // SPDX-License-Identifier: GPL-2.0-only
3 * tegra20_ac97.c - Tegra20 AC97 platform driver
33 #define DRV_NAME "tegra20-ac97"
37 static void tegra20_ac97_codec_reset(struct snd_ac97 *ac97) in tegra20_ac97_codec_reset() argument
43 gpio_set_value(workdata->reset_gpio, 0); in tegra20_ac97_codec_reset()
46 gpio_set_value(workdata->reset_gpio, 1); in tegra20_ac97_codec_reset()
52 regmap_read(workdata->regmap, TEGRA20_AC97_STATUS1, &readback); in tegra20_ac97_codec_reset()
59 static void tegra20_ac97_codec_warm_reset(struct snd_ac97 *ac97) in tegra20_ac97_codec_warm_reset() argument
66 * the controller cmd is not working, have to toggle sync line in tegra20_ac97_codec_warm_reset()
69 gpio_request(workdata->sync_gpio, "codec-sync"); in tegra20_ac97_codec_warm_reset()
71 gpio_direction_output(workdata->sync_gpio, 1); in tegra20_ac97_codec_warm_reset()
74 gpio_set_value(workdata->sync_gpio, 0); in tegra20_ac97_codec_warm_reset()
76 gpio_free(workdata->sync_gpio); in tegra20_ac97_codec_warm_reset()
81 regmap_read(workdata->regmap, TEGRA20_AC97_STATUS1, &readback); in tegra20_ac97_codec_warm_reset()
94 regmap_write(workdata->regmap, TEGRA20_AC97_CMD, in tegra20_ac97_codec_read()
102 regmap_read(workdata->regmap, TEGRA20_AC97_STATUS1, &readback); in tegra20_ac97_codec_read()
118 regmap_write(workdata->regmap, TEGRA20_AC97_CMD, in tegra20_ac97_codec_write()
128 regmap_read(workdata->regmap, TEGRA20_AC97_CMD, &readback); in tegra20_ac97_codec_write()
142 static inline void tegra20_ac97_start_playback(struct tegra20_ac97 *ac97) in tegra20_ac97_start_playback() argument
144 regmap_update_bits(ac97->regmap, TEGRA20_AC97_FIFO1_SCR, in tegra20_ac97_start_playback()
148 regmap_update_bits(ac97->regmap, TEGRA20_AC97_CTRL, in tegra20_ac97_start_playback()
155 static inline void tegra20_ac97_stop_playback(struct tegra20_ac97 *ac97) in tegra20_ac97_stop_playback() argument
157 regmap_update_bits(ac97->regmap, TEGRA20_AC97_FIFO1_SCR, in tegra20_ac97_stop_playback()
160 regmap_update_bits(ac97->regmap, TEGRA20_AC97_CTRL, in tegra20_ac97_stop_playback()
164 static inline void tegra20_ac97_start_capture(struct tegra20_ac97 *ac97) in tegra20_ac97_start_capture() argument
166 regmap_update_bits(ac97->regmap, TEGRA20_AC97_FIFO1_SCR, in tegra20_ac97_start_capture()
171 static inline void tegra20_ac97_stop_capture(struct tegra20_ac97 *ac97) in tegra20_ac97_stop_capture() argument
173 regmap_update_bits(ac97->regmap, TEGRA20_AC97_FIFO1_SCR, in tegra20_ac97_stop_capture()
180 struct tegra20_ac97 *ac97 = snd_soc_dai_get_drvdata(dai); in tegra20_ac97_trigger() local
186 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) in tegra20_ac97_trigger()
187 tegra20_ac97_start_playback(ac97); in tegra20_ac97_trigger()
189 tegra20_ac97_start_capture(ac97); in tegra20_ac97_trigger()
194 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) in tegra20_ac97_trigger()
195 tegra20_ac97_stop_playback(ac97); in tegra20_ac97_trigger()
197 tegra20_ac97_stop_capture(ac97); in tegra20_ac97_trigger()
200 return -EINVAL; in tegra20_ac97_trigger()
208 struct tegra20_ac97 *ac97 = snd_soc_dai_get_drvdata(dai); in tegra20_ac97_probe() local
210 snd_soc_dai_init_dma_data(dai, &ac97->playback_dma_data, in tegra20_ac97_probe()
211 &ac97->capture_dma_data); in tegra20_ac97_probe()
222 .name = "tegra-ac97-pcm",
304 struct tegra20_ac97 *ac97; in tegra20_ac97_platform_probe() local
309 ac97 = devm_kzalloc(&pdev->dev, sizeof(struct tegra20_ac97), in tegra20_ac97_platform_probe()
311 if (!ac97) { in tegra20_ac97_platform_probe()
312 ret = -ENOMEM; in tegra20_ac97_platform_probe()
315 dev_set_drvdata(&pdev->dev, ac97); in tegra20_ac97_platform_probe()
317 ac97->reset = devm_reset_control_get_exclusive(&pdev->dev, "ac97"); in tegra20_ac97_platform_probe()
318 if (IS_ERR(ac97->reset)) { in tegra20_ac97_platform_probe()
319 dev_err(&pdev->dev, "Can't retrieve ac97 reset\n"); in tegra20_ac97_platform_probe()
320 ret = PTR_ERR(ac97->reset); in tegra20_ac97_platform_probe()
324 ac97->clk_ac97 = devm_clk_get(&pdev->dev, NULL); in tegra20_ac97_platform_probe()
325 if (IS_ERR(ac97->clk_ac97)) { in tegra20_ac97_platform_probe()
326 dev_err(&pdev->dev, "Can't retrieve ac97 clock\n"); in tegra20_ac97_platform_probe()
327 ret = PTR_ERR(ac97->clk_ac97); in tegra20_ac97_platform_probe()
337 ac97->regmap = devm_regmap_init_mmio(&pdev->dev, regs, in tegra20_ac97_platform_probe()
339 if (IS_ERR(ac97->regmap)) { in tegra20_ac97_platform_probe()
340 dev_err(&pdev->dev, "regmap init failed\n"); in tegra20_ac97_platform_probe()
341 ret = PTR_ERR(ac97->regmap); in tegra20_ac97_platform_probe()
345 ac97->reset_gpio = of_get_named_gpio(pdev->dev.of_node, in tegra20_ac97_platform_probe()
346 "nvidia,codec-reset-gpio", 0); in tegra20_ac97_platform_probe()
347 if (gpio_is_valid(ac97->reset_gpio)) { in tegra20_ac97_platform_probe()
348 ret = devm_gpio_request_one(&pdev->dev, ac97->reset_gpio, in tegra20_ac97_platform_probe()
349 GPIOF_OUT_INIT_HIGH, "codec-reset"); in tegra20_ac97_platform_probe()
351 dev_err(&pdev->dev, "could not get codec-reset GPIO\n"); in tegra20_ac97_platform_probe()
355 dev_err(&pdev->dev, "no codec-reset GPIO supplied\n"); in tegra20_ac97_platform_probe()
356 ret = -EINVAL; in tegra20_ac97_platform_probe()
360 ac97->sync_gpio = of_get_named_gpio(pdev->dev.of_node, in tegra20_ac97_platform_probe()
361 "nvidia,codec-sync-gpio", 0); in tegra20_ac97_platform_probe()
362 if (!gpio_is_valid(ac97->sync_gpio)) { in tegra20_ac97_platform_probe()
363 dev_err(&pdev->dev, "no codec-sync GPIO supplied\n"); in tegra20_ac97_platform_probe()
364 ret = -EINVAL; in tegra20_ac97_platform_probe()
368 ac97->capture_dma_data.addr = mem->start + TEGRA20_AC97_FIFO_RX1; in tegra20_ac97_platform_probe()
369 ac97->capture_dma_data.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; in tegra20_ac97_platform_probe()
370 ac97->capture_dma_data.maxburst = 4; in tegra20_ac97_platform_probe()
372 ac97->playback_dma_data.addr = mem->start + TEGRA20_AC97_FIFO_TX1; in tegra20_ac97_platform_probe()
373 ac97->playback_dma_data.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; in tegra20_ac97_platform_probe()
374 ac97->playback_dma_data.maxburst = 4; in tegra20_ac97_platform_probe()
376 ret = reset_control_assert(ac97->reset); in tegra20_ac97_platform_probe()
378 dev_err(&pdev->dev, "Failed to assert AC'97 reset: %d\n", ret); in tegra20_ac97_platform_probe()
382 ret = clk_prepare_enable(ac97->clk_ac97); in tegra20_ac97_platform_probe()
384 dev_err(&pdev->dev, "clk_enable failed: %d\n", ret); in tegra20_ac97_platform_probe()
390 ret = reset_control_deassert(ac97->reset); in tegra20_ac97_platform_probe()
392 dev_err(&pdev->dev, "Failed to deassert AC'97 reset: %d\n", ret); in tegra20_ac97_platform_probe()
398 dev_err(&pdev->dev, "Failed to set AC'97 ops: %d\n", ret); in tegra20_ac97_platform_probe()
402 ret = snd_soc_register_component(&pdev->dev, &tegra20_ac97_component, in tegra20_ac97_platform_probe()
405 dev_err(&pdev->dev, "Could not register DAI: %d\n", ret); in tegra20_ac97_platform_probe()
406 ret = -ENOMEM; in tegra20_ac97_platform_probe()
410 ret = tegra_pcm_platform_register(&pdev->dev); in tegra20_ac97_platform_probe()
412 dev_err(&pdev->dev, "Could not register PCM: %d\n", ret); in tegra20_ac97_platform_probe()
416 /* XXX: crufty ASoC AC97 API - only one AC97 codec allowed */ in tegra20_ac97_platform_probe()
417 workdata = ac97; in tegra20_ac97_platform_probe()
422 snd_soc_unregister_component(&pdev->dev); in tegra20_ac97_platform_probe()
424 clk_disable_unprepare(ac97->clk_ac97); in tegra20_ac97_platform_probe()
433 struct tegra20_ac97 *ac97 = dev_get_drvdata(&pdev->dev); in tegra20_ac97_platform_remove() local
435 tegra_pcm_platform_unregister(&pdev->dev); in tegra20_ac97_platform_remove()
436 snd_soc_unregister_component(&pdev->dev); in tegra20_ac97_platform_remove()
438 clk_disable_unprepare(ac97->clk_ac97); in tegra20_ac97_platform_remove()
444 { .compatible = "nvidia,tegra20-ac97", },
459 MODULE_DESCRIPTION("Tegra20 AC97 ASoC driver");