^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * tegra20_wm9712.c - Tegra machine ASoC driver for boards using WM9712 codec.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright 2012 Lucas Stach <dev@lynxeye.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Partly based on code copyright/by:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Copyright 2011,2012 Toradex Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/gpio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/of_gpio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <sound/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <sound/jack.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <sound/pcm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <sound/pcm_params.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <sound/soc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include "tegra_asoc_utils.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #define DRV_NAME "tegra-snd-wm9712"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) struct tegra_wm9712 {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) struct platform_device *codec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) struct tegra_asoc_utils_data util_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) static const struct snd_soc_dapm_widget tegra_wm9712_dapm_widgets[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) SND_SOC_DAPM_HP("Headphone", NULL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) SND_SOC_DAPM_LINE("LineIn", NULL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) SND_SOC_DAPM_MIC("Mic", NULL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) static int tegra_wm9712_init(struct snd_soc_pcm_runtime *rtd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) return snd_soc_dapm_force_enable_pin(&rtd->card->dapm, "Mic Bias");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) SND_SOC_DAILINK_DEFS(hifi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) DAILINK_COMP_ARRAY(COMP_EMPTY()),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) DAILINK_COMP_ARRAY(COMP_CODEC("wm9712-codec", "wm9712-hifi")),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) DAILINK_COMP_ARRAY(COMP_EMPTY()));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) static struct snd_soc_dai_link tegra_wm9712_dai = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) .name = "AC97 HiFi",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) .stream_name = "AC97 HiFi",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) .init = tegra_wm9712_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) SND_SOC_DAILINK_REG(hifi),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) static struct snd_soc_card snd_soc_tegra_wm9712 = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) .name = "tegra-wm9712",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) .driver_name = "tegra",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) .dai_link = &tegra_wm9712_dai,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) .num_links = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) .dapm_widgets = tegra_wm9712_dapm_widgets,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) .num_dapm_widgets = ARRAY_SIZE(tegra_wm9712_dapm_widgets),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) .fully_routed = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) static int tegra_wm9712_driver_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) struct device_node *np = pdev->dev.of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) struct snd_soc_card *card = &snd_soc_tegra_wm9712;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) struct tegra_wm9712 *machine;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) machine = devm_kzalloc(&pdev->dev, sizeof(struct tegra_wm9712),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) if (!machine)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) card->dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) snd_soc_card_set_drvdata(card, machine);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) machine->codec = platform_device_alloc("wm9712-codec", -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) if (!machine->codec) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) dev_err(&pdev->dev, "Can't allocate wm9712 platform device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) ret = platform_device_add(machine->codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) goto codec_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) ret = snd_soc_of_parse_card_name(card, "nvidia,model");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) goto codec_unregister;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) ret = snd_soc_of_parse_audio_routing(card, "nvidia,audio-routing");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) goto codec_unregister;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) tegra_wm9712_dai.cpus->of_node = of_parse_phandle(np,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) "nvidia,ac97-controller", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) if (!tegra_wm9712_dai.cpus->of_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) dev_err(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) "Property 'nvidia,ac97-controller' missing or invalid\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) goto codec_unregister;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) tegra_wm9712_dai.platforms->of_node = tegra_wm9712_dai.cpus->of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) ret = tegra_asoc_utils_init(&machine->util_data, &pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) goto codec_unregister;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) ret = tegra_asoc_utils_set_ac97_rate(&machine->util_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) goto codec_unregister;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) ret = snd_soc_register_card(card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) goto codec_unregister;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) codec_unregister:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) platform_device_del(machine->codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) codec_put:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) platform_device_put(machine->codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) static int tegra_wm9712_driver_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) struct snd_soc_card *card = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) struct tegra_wm9712 *machine = snd_soc_card_get_drvdata(card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) snd_soc_unregister_card(card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) platform_device_unregister(machine->codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) static const struct of_device_id tegra_wm9712_of_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) { .compatible = "nvidia,tegra-audio-wm9712", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) static struct platform_driver tegra_wm9712_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) .name = DRV_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) .pm = &snd_soc_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) .of_match_table = tegra_wm9712_of_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) .probe = tegra_wm9712_driver_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) .remove = tegra_wm9712_driver_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) module_platform_driver(tegra_wm9712_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) MODULE_AUTHOR("Lucas Stach");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) MODULE_DESCRIPTION("Tegra+WM9712 machine ASoC driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) MODULE_LICENSE("GPL v2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) MODULE_ALIAS("platform:" DRV_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) MODULE_DEVICE_TABLE(of, tegra_wm9712_of_match);