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