2 * tegra_alc5632.c -- Toshiba AC100(PAZ00) machine ASoC driver
4 * Copyright (C) 2011 The AC100 Kernel Team <ac100@lists.lauchpad.net>
6 * Authors: Leon Romanovsky <leon@leon.nu>
7 * Andrey Danin <danindrey@mail.ru>
8 * Marc Dietrich <marvin24@gmx.de>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
15 #include <asm/mach-types.h>
17 #include <linux/module.h>
18 #include <linux/platform_device.h>
19 #include <linux/slab.h>
20 #include <linux/gpio.h>
22 #include <sound/core.h>
23 #include <sound/jack.h>
24 #include <sound/pcm.h>
25 #include <sound/pcm_params.h>
26 #include <sound/soc.h>
28 #include "../codecs/alc5632.h"
30 #include "tegra_das.h"
31 #include "tegra_i2s.h"
32 #include "tegra_pcm.h"
33 #include "tegra_asoc_utils.h"
35 #define DRV_NAME "tegra-alc5632"
37 struct tegra_alc5632 {
38 struct tegra_asoc_utils_data util_data;
39 struct platform_device *pcm_dev;
42 static int tegra_alc5632_asoc_hw_params(struct snd_pcm_substream *substream,
43 struct snd_pcm_hw_params *params)
45 struct snd_soc_pcm_runtime *rtd = substream->private_data;
46 struct snd_soc_dai *codec_dai = rtd->codec_dai;
47 struct snd_soc_codec *codec = rtd->codec;
48 struct snd_soc_card *card = codec->card;
49 struct tegra_alc5632 *alc5632 = snd_soc_card_get_drvdata(card);
53 srate = params_rate(params);
56 err = tegra_asoc_utils_set_rate(&alc5632->util_data, srate, mclk);
58 dev_err(card->dev, "Can't configure clocks\n");
62 err = snd_soc_dai_set_sysclk(codec_dai, 0, mclk,
65 dev_err(card->dev, "codec_dai clock not set\n");
72 static struct snd_soc_ops tegra_alc5632_asoc_ops = {
73 .hw_params = tegra_alc5632_asoc_hw_params,
76 static struct snd_soc_jack tegra_alc5632_hs_jack;
78 static struct snd_soc_jack_pin tegra_alc5632_hs_jack_pins[] = {
81 .mask = SND_JACK_MICROPHONE,
84 .pin = "Headset Stereophone",
85 .mask = SND_JACK_HEADPHONE,
89 static const struct snd_soc_dapm_widget tegra_alc5632_dapm_widgets[] = {
90 SND_SOC_DAPM_SPK("Int Spk", NULL),
91 SND_SOC_DAPM_HP("Headset Stereophone", NULL),
92 SND_SOC_DAPM_MIC("Headset Mic", NULL),
95 static const struct snd_soc_dapm_route tegra_alc5632_audio_map[] = {
96 /* Internal Speaker */
97 {"Int Spk", NULL, "SPKOUT"},
98 {"Int Spk", NULL, "SPKOUTN"},
101 {"MIC1", NULL, "MICBIAS1"},
102 {"MICBIAS1", NULL, "Headset Mic"},
104 /* Headset Stereophone */
105 {"Headset Stereophone", NULL, "HPR"},
106 {"Headset Stereophone", NULL, "HPL"},
109 static const struct snd_kcontrol_new tegra_alc5632_controls[] = {
110 SOC_DAPM_PIN_SWITCH("Int Spk"),
113 static int tegra_alc5632_asoc_init(struct snd_soc_pcm_runtime *rtd)
115 struct snd_soc_codec *codec = rtd->codec;
116 struct snd_soc_dapm_context *dapm = &codec->dapm;
118 snd_soc_jack_new(codec, "Headset Jack", SND_JACK_HEADSET,
119 &tegra_alc5632_hs_jack);
120 snd_soc_jack_add_pins(&tegra_alc5632_hs_jack,
121 ARRAY_SIZE(tegra_alc5632_hs_jack_pins),
122 tegra_alc5632_hs_jack_pins);
124 snd_soc_dapm_force_enable_pin(dapm, "MICBIAS1");
129 static struct snd_soc_dai_link tegra_alc5632_dai = {
131 .stream_name = "ALC5632 PCM",
132 .platform_name = "tegra-pcm-audio",
133 .codec_dai_name = "alc5632-hifi",
134 .init = tegra_alc5632_asoc_init,
135 .ops = &tegra_alc5632_asoc_ops,
136 .dai_fmt = SND_SOC_DAIFMT_I2S
137 | SND_SOC_DAIFMT_NB_NF
138 | SND_SOC_DAIFMT_CBS_CFS,
141 static struct snd_soc_card snd_soc_tegra_alc5632 = {
142 .name = "tegra-alc5632",
143 .owner = THIS_MODULE,
144 .dai_link = &tegra_alc5632_dai,
146 .controls = tegra_alc5632_controls,
147 .num_controls = ARRAY_SIZE(tegra_alc5632_controls),
148 .dapm_widgets = tegra_alc5632_dapm_widgets,
149 .num_dapm_widgets = ARRAY_SIZE(tegra_alc5632_dapm_widgets),
150 .dapm_routes = tegra_alc5632_audio_map,
151 .num_dapm_routes = ARRAY_SIZE(tegra_alc5632_audio_map),
152 .fully_routed = true,
155 static __devinit int tegra_alc5632_probe(struct platform_device *pdev)
157 struct snd_soc_card *card = &snd_soc_tegra_alc5632;
158 struct tegra_alc5632 *alc5632;
161 alc5632 = devm_kzalloc(&pdev->dev,
162 sizeof(struct tegra_alc5632), GFP_KERNEL);
164 dev_err(&pdev->dev, "Can't allocate tegra_alc5632\n");
169 card->dev = &pdev->dev;
170 platform_set_drvdata(pdev, card);
171 snd_soc_card_set_drvdata(card, alc5632);
173 alc5632->pcm_dev = ERR_PTR(-EINVAL);
175 if (!(pdev->dev.of_node)) {
176 dev_err(&pdev->dev, "Must be instantiated using device tree\n");
181 ret = snd_soc_of_parse_card_name(card, "nvidia,model");
185 ret = snd_soc_of_parse_audio_routing(card, "nvidia,audio-routing");
189 tegra_alc5632_dai.codec_of_node = of_parse_phandle(
190 pdev->dev.of_node, "nvidia,audio-codec", 0);
192 if (!tegra_alc5632_dai.codec_of_node) {
194 "Property 'nvidia,audio-codec' missing or invalid\n");
199 tegra_alc5632_dai.cpu_dai_of_node = of_parse_phandle(
200 pdev->dev.of_node, "nvidia,i2s-controller", 0);
201 if (!tegra_alc5632_dai.cpu_dai_of_node) {
203 "Property 'nvidia,i2s-controller' missing or invalid\n");
208 alc5632->pcm_dev = platform_device_register_simple(
209 "tegra-pcm-audio", -1, NULL, 0);
210 if (IS_ERR(alc5632->pcm_dev)) {
212 "Can't instantiate tegra-pcm-audio\n");
213 ret = PTR_ERR(alc5632->pcm_dev);
217 ret = tegra_asoc_utils_init(&alc5632->util_data, &pdev->dev);
221 ret = snd_soc_register_card(card);
223 dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n",
231 tegra_asoc_utils_fini(&alc5632->util_data);
233 if (!IS_ERR(alc5632->pcm_dev))
234 platform_device_unregister(alc5632->pcm_dev);
239 static int __devexit tegra_alc5632_remove(struct platform_device *pdev)
241 struct snd_soc_card *card = platform_get_drvdata(pdev);
242 struct tegra_alc5632 *alc5632 = snd_soc_card_get_drvdata(card);
244 snd_soc_unregister_card(card);
246 tegra_asoc_utils_fini(&alc5632->util_data);
247 if (!IS_ERR(alc5632->pcm_dev))
248 platform_device_unregister(alc5632->pcm_dev);
253 static const struct of_device_id tegra_alc5632_of_match[] __devinitconst = {
254 { .compatible = "nvidia,tegra-audio-alc5632", },
258 static struct platform_driver tegra_alc5632_driver = {
261 .owner = THIS_MODULE,
262 .pm = &snd_soc_pm_ops,
263 .of_match_table = tegra_alc5632_of_match,
265 .probe = tegra_alc5632_probe,
266 .remove = __devexit_p(tegra_alc5632_remove),
268 module_platform_driver(tegra_alc5632_driver);
270 MODULE_AUTHOR("Leon Romanovsky <leon@leon.nu>");
271 MODULE_DESCRIPTION("Tegra+ALC5632 machine ASoC driver");
272 MODULE_LICENSE("GPL");
273 MODULE_ALIAS("platform:" DRV_NAME);
274 MODULE_DEVICE_TABLE(of, tegra_alc5632_of_match);