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>
21 #include <linux/of_gpio.h>
23 #include <sound/core.h>
24 #include <sound/jack.h>
25 #include <sound/pcm.h>
26 #include <sound/pcm_params.h>
27 #include <sound/soc.h>
29 #include "../codecs/alc5632.h"
31 #include "tegra_das.h"
32 #include "tegra_i2s.h"
33 #include "tegra_pcm.h"
34 #include "tegra_asoc_utils.h"
36 #define DRV_NAME "tegra-alc5632"
38 #define GPIO_HP_DET BIT(0)
40 struct tegra_alc5632 {
41 struct tegra_asoc_utils_data util_data;
42 struct platform_device *pcm_dev;
47 static int tegra_alc5632_asoc_hw_params(struct snd_pcm_substream *substream,
48 struct snd_pcm_hw_params *params)
50 struct snd_soc_pcm_runtime *rtd = substream->private_data;
51 struct snd_soc_dai *codec_dai = rtd->codec_dai;
52 struct snd_soc_codec *codec = rtd->codec;
53 struct snd_soc_card *card = codec->card;
54 struct tegra_alc5632 *alc5632 = snd_soc_card_get_drvdata(card);
58 srate = params_rate(params);
61 err = tegra_asoc_utils_set_rate(&alc5632->util_data, srate, mclk);
63 dev_err(card->dev, "Can't configure clocks\n");
67 err = snd_soc_dai_set_sysclk(codec_dai, 0, mclk,
70 dev_err(card->dev, "codec_dai clock not set\n");
77 static struct snd_soc_ops tegra_alc5632_asoc_ops = {
78 .hw_params = tegra_alc5632_asoc_hw_params,
81 static struct snd_soc_jack tegra_alc5632_hs_jack;
83 static struct snd_soc_jack_pin tegra_alc5632_hs_jack_pins[] = {
86 .mask = SND_JACK_MICROPHONE,
89 .pin = "Headset Stereophone",
90 .mask = SND_JACK_HEADPHONE,
94 static struct snd_soc_jack_gpio tegra_alc5632_hp_jack_gpio = {
95 .name = "Headset detection",
96 .report = SND_JACK_HEADSET,
101 static const struct snd_soc_dapm_widget tegra_alc5632_dapm_widgets[] = {
102 SND_SOC_DAPM_SPK("Int Spk", NULL),
103 SND_SOC_DAPM_HP("Headset Stereophone", NULL),
104 SND_SOC_DAPM_MIC("Headset Mic", NULL),
105 SND_SOC_DAPM_MIC("Digital Mic", NULL),
108 static const struct snd_kcontrol_new tegra_alc5632_controls[] = {
109 SOC_DAPM_PIN_SWITCH("Int Spk"),
112 static int tegra_alc5632_asoc_init(struct snd_soc_pcm_runtime *rtd)
114 struct snd_soc_codec *codec = rtd->codec;
115 struct snd_soc_dapm_context *dapm = &codec->dapm;
116 struct device_node *np = codec->card->dev->of_node;
117 struct tegra_alc5632 *machine = snd_soc_card_get_drvdata(codec->card);
119 snd_soc_jack_new(codec, "Headset Jack", SND_JACK_HEADSET,
120 &tegra_alc5632_hs_jack);
121 snd_soc_jack_add_pins(&tegra_alc5632_hs_jack,
122 ARRAY_SIZE(tegra_alc5632_hs_jack_pins),
123 tegra_alc5632_hs_jack_pins);
125 machine->gpio_hp_det = of_get_named_gpio(np, "nvidia,hp-det-gpios", 0);
127 if (gpio_is_valid(machine->gpio_hp_det)) {
128 tegra_alc5632_hp_jack_gpio.gpio = machine->gpio_hp_det;
129 snd_soc_jack_add_gpios(&tegra_alc5632_hs_jack,
131 &tegra_alc5632_hp_jack_gpio);
132 machine->gpio_requested |= GPIO_HP_DET;
135 snd_soc_dapm_force_enable_pin(dapm, "MICBIAS1");
140 static struct snd_soc_dai_link tegra_alc5632_dai = {
142 .stream_name = "ALC5632 PCM",
143 .platform_name = "tegra-pcm-audio",
144 .codec_dai_name = "alc5632-hifi",
145 .init = tegra_alc5632_asoc_init,
146 .ops = &tegra_alc5632_asoc_ops,
147 .dai_fmt = SND_SOC_DAIFMT_I2S
148 | SND_SOC_DAIFMT_NB_NF
149 | SND_SOC_DAIFMT_CBS_CFS,
152 static struct snd_soc_card snd_soc_tegra_alc5632 = {
153 .name = "tegra-alc5632",
154 .owner = THIS_MODULE,
155 .dai_link = &tegra_alc5632_dai,
157 .controls = tegra_alc5632_controls,
158 .num_controls = ARRAY_SIZE(tegra_alc5632_controls),
159 .dapm_widgets = tegra_alc5632_dapm_widgets,
160 .num_dapm_widgets = ARRAY_SIZE(tegra_alc5632_dapm_widgets),
161 .fully_routed = true,
164 static __devinit int tegra_alc5632_probe(struct platform_device *pdev)
166 struct snd_soc_card *card = &snd_soc_tegra_alc5632;
167 struct tegra_alc5632 *alc5632;
170 alc5632 = devm_kzalloc(&pdev->dev,
171 sizeof(struct tegra_alc5632), GFP_KERNEL);
173 dev_err(&pdev->dev, "Can't allocate tegra_alc5632\n");
178 card->dev = &pdev->dev;
179 platform_set_drvdata(pdev, card);
180 snd_soc_card_set_drvdata(card, alc5632);
182 alc5632->pcm_dev = ERR_PTR(-EINVAL);
184 if (!(pdev->dev.of_node)) {
185 dev_err(&pdev->dev, "Must be instantiated using device tree\n");
190 ret = snd_soc_of_parse_card_name(card, "nvidia,model");
194 ret = snd_soc_of_parse_audio_routing(card, "nvidia,audio-routing");
198 tegra_alc5632_dai.codec_of_node = of_parse_phandle(
199 pdev->dev.of_node, "nvidia,audio-codec", 0);
201 if (!tegra_alc5632_dai.codec_of_node) {
203 "Property 'nvidia,audio-codec' missing or invalid\n");
208 tegra_alc5632_dai.cpu_dai_of_node = of_parse_phandle(
209 pdev->dev.of_node, "nvidia,i2s-controller", 0);
210 if (!tegra_alc5632_dai.cpu_dai_of_node) {
212 "Property 'nvidia,i2s-controller' missing or invalid\n");
217 alc5632->pcm_dev = platform_device_register_simple(
218 "tegra-pcm-audio", -1, NULL, 0);
219 if (IS_ERR(alc5632->pcm_dev)) {
221 "Can't instantiate tegra-pcm-audio\n");
222 ret = PTR_ERR(alc5632->pcm_dev);
226 ret = tegra_asoc_utils_init(&alc5632->util_data, &pdev->dev);
230 ret = snd_soc_register_card(card);
232 dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n",
240 tegra_asoc_utils_fini(&alc5632->util_data);
242 if (!IS_ERR(alc5632->pcm_dev))
243 platform_device_unregister(alc5632->pcm_dev);
248 static int __devexit tegra_alc5632_remove(struct platform_device *pdev)
250 struct snd_soc_card *card = platform_get_drvdata(pdev);
251 struct tegra_alc5632 *machine = snd_soc_card_get_drvdata(card);
253 if (machine->gpio_requested & GPIO_HP_DET)
254 snd_soc_jack_free_gpios(&tegra_alc5632_hs_jack,
256 &tegra_alc5632_hp_jack_gpio);
257 machine->gpio_requested = 0;
259 snd_soc_unregister_card(card);
261 tegra_asoc_utils_fini(&machine->util_data);
262 if (!IS_ERR(machine->pcm_dev))
263 platform_device_unregister(machine->pcm_dev);
268 static const struct of_device_id tegra_alc5632_of_match[] __devinitconst = {
269 { .compatible = "nvidia,tegra-audio-alc5632", },
273 static struct platform_driver tegra_alc5632_driver = {
276 .owner = THIS_MODULE,
277 .pm = &snd_soc_pm_ops,
278 .of_match_table = tegra_alc5632_of_match,
280 .probe = tegra_alc5632_probe,
281 .remove = __devexit_p(tegra_alc5632_remove),
283 module_platform_driver(tegra_alc5632_driver);
285 MODULE_AUTHOR("Leon Romanovsky <leon@leon.nu>");
286 MODULE_DESCRIPTION("Tegra+ALC5632 machine ASoC driver");
287 MODULE_LICENSE("GPL");
288 MODULE_ALIAS("platform:" DRV_NAME);
289 MODULE_DEVICE_TABLE(of, tegra_alc5632_of_match);