Merge tag 'v3.3.7' into 3.3/master
[zen-stable.git] / sound / soc / tegra / tegra_alc5632.c
blob4a0e805c4edd1b770cf84c85369be81d94375d2f
1 /*
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;
41 static int tegra_alc5632_asoc_hw_params(struct snd_pcm_substream *substream,
42 struct snd_pcm_hw_params *params)
44 struct snd_soc_pcm_runtime *rtd = substream->private_data;
45 struct snd_soc_dai *codec_dai = rtd->codec_dai;
46 struct snd_soc_codec *codec = rtd->codec;
47 struct snd_soc_card *card = codec->card;
48 struct tegra_alc5632 *alc5632 = snd_soc_card_get_drvdata(card);
49 int srate, mclk;
50 int err;
52 srate = params_rate(params);
53 mclk = 512 * srate;
55 err = tegra_asoc_utils_set_rate(&alc5632->util_data, srate, mclk);
56 if (err < 0) {
57 dev_err(card->dev, "Can't configure clocks\n");
58 return err;
61 err = snd_soc_dai_set_sysclk(codec_dai, 0, mclk,
62 SND_SOC_CLOCK_IN);
63 if (err < 0) {
64 dev_err(card->dev, "codec_dai clock not set\n");
65 return err;
68 return 0;
71 static struct snd_soc_ops tegra_alc5632_asoc_ops = {
72 .hw_params = tegra_alc5632_asoc_hw_params,
75 static struct snd_soc_jack tegra_alc5632_hs_jack;
77 static struct snd_soc_jack_pin tegra_alc5632_hs_jack_pins[] = {
79 .pin = "Headset Mic",
80 .mask = SND_JACK_MICROPHONE,
83 .pin = "Headset Stereophone",
84 .mask = SND_JACK_HEADPHONE,
88 static const struct snd_soc_dapm_widget tegra_alc5632_dapm_widgets[] = {
89 SND_SOC_DAPM_SPK("Int Spk", NULL),
90 SND_SOC_DAPM_HP("Headset Stereophone", NULL),
91 SND_SOC_DAPM_MIC("Headset Mic", NULL),
94 static const struct snd_soc_dapm_route tegra_alc5632_audio_map[] = {
95 /* Internal Speaker */
96 {"Int Spk", NULL, "SPKOUT"},
97 {"Int Spk", NULL, "SPKOUTN"},
99 /* Headset Mic */
100 {"MIC1", NULL, "MICBIAS1"},
101 {"MICBIAS1", NULL, "Headset Mic"},
103 /* Headset Stereophone */
104 {"Headset Stereophone", NULL, "HPR"},
105 {"Headset Stereophone", NULL, "HPL"},
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;
117 snd_soc_jack_new(codec, "Headset Jack", SND_JACK_HEADSET,
118 &tegra_alc5632_hs_jack);
119 snd_soc_jack_add_pins(&tegra_alc5632_hs_jack,
120 ARRAY_SIZE(tegra_alc5632_hs_jack_pins),
121 tegra_alc5632_hs_jack_pins);
123 snd_soc_dapm_force_enable_pin(dapm, "MICBIAS1");
125 return 0;
128 static struct snd_soc_dai_link tegra_alc5632_dai = {
129 .name = "ALC5632",
130 .stream_name = "ALC5632 PCM",
131 .codec_name = "alc5632.0-001e",
132 .platform_name = "tegra-pcm-audio",
133 .cpu_dai_name = "tegra-i2s.0",
134 .codec_dai_name = "alc5632-hifi",
135 .init = tegra_alc5632_asoc_init,
136 .ops = &tegra_alc5632_asoc_ops,
137 .dai_fmt = SND_SOC_DAIFMT_I2S
138 | SND_SOC_DAIFMT_NB_NF
139 | SND_SOC_DAIFMT_CBS_CFS,
142 static struct snd_soc_card snd_soc_tegra_alc5632 = {
143 .name = "tegra-alc5632",
144 .owner = THIS_MODULE,
145 .dai_link = &tegra_alc5632_dai,
146 .num_links = 1,
147 .controls = tegra_alc5632_controls,
148 .num_controls = ARRAY_SIZE(tegra_alc5632_controls),
149 .dapm_widgets = tegra_alc5632_dapm_widgets,
150 .num_dapm_widgets = ARRAY_SIZE(tegra_alc5632_dapm_widgets),
151 .dapm_routes = tegra_alc5632_audio_map,
152 .num_dapm_routes = ARRAY_SIZE(tegra_alc5632_audio_map),
153 .fully_routed = true,
156 static __devinit int tegra_alc5632_probe(struct platform_device *pdev)
158 struct snd_soc_card *card = &snd_soc_tegra_alc5632;
159 struct tegra_alc5632 *alc5632;
160 int ret;
162 alc5632 = devm_kzalloc(&pdev->dev,
163 sizeof(struct tegra_alc5632), GFP_KERNEL);
164 if (!alc5632) {
165 dev_err(&pdev->dev, "Can't allocate tegra_alc5632\n");
166 return -ENOMEM;
169 ret = tegra_asoc_utils_init(&alc5632->util_data, &pdev->dev);
170 if (ret)
171 return ret;
173 card->dev = &pdev->dev;
174 platform_set_drvdata(pdev, card);
175 snd_soc_card_set_drvdata(card, alc5632);
177 ret = snd_soc_register_card(card);
178 if (ret) {
179 dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n",
180 ret);
181 tegra_asoc_utils_fini(&alc5632->util_data);
182 return ret;
185 return 0;
188 static int __devexit tegra_alc5632_remove(struct platform_device *pdev)
190 struct snd_soc_card *card = platform_get_drvdata(pdev);
191 struct tegra_alc5632 *alc5632 = snd_soc_card_get_drvdata(card);
193 snd_soc_unregister_card(card);
195 tegra_asoc_utils_fini(&alc5632->util_data);
197 return 0;
200 static struct platform_driver tegra_alc5632_driver = {
201 .driver = {
202 .name = DRV_NAME,
203 .owner = THIS_MODULE,
204 .pm = &snd_soc_pm_ops,
206 .probe = tegra_alc5632_probe,
207 .remove = __devexit_p(tegra_alc5632_remove),
209 module_platform_driver(tegra_alc5632_driver);
211 MODULE_AUTHOR("Leon Romanovsky <leon@leon.nu>");
212 MODULE_DESCRIPTION("Tegra+ALC5632 machine ASoC driver");
213 MODULE_LICENSE("GPL");
214 MODULE_ALIAS("platform:" DRV_NAME);