ASoC: Tegra: Harmony: Fix indentation issue.
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / sound / soc / tegra / harmony.c
blobb5311a3ee95f49ae5994e0c2c7790eb8fbf0ab70
1 /*
2 * harmony.c - Harmony machine ASoC driver
4 * Author: Stephen Warren <swarren@nvidia.com>
5 * Copyright (C) 2010-2011 - NVIDIA, Inc.
7 * Based on code copyright/by:
9 * (c) 2009, 2010 Nvidia Graphics Pvt. Ltd.
11 * Copyright 2007 Wolfson Microelectronics PLC.
12 * Author: Graeme Gregory
13 * graeme.gregory@wolfsonmicro.com or linux@wolfsonmicro.com
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * version 2 as published by the Free Software Foundation.
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
27 * 02110-1301 USA
31 #include <asm/mach-types.h>
33 #include <linux/module.h>
34 #include <linux/platform_device.h>
35 #include <linux/slab.h>
36 #include <linux/gpio.h>
38 #include <mach/harmony_audio.h>
40 #include <sound/core.h>
41 #include <sound/pcm.h>
42 #include <sound/pcm_params.h>
43 #include <sound/soc.h>
45 #include "tegra_das.h"
46 #include "tegra_i2s.h"
47 #include "tegra_pcm.h"
48 #include "tegra_asoc_utils.h"
50 #define DRV_NAME "tegra-snd-harmony"
51 #define PREFIX DRV_NAME ": "
53 struct tegra_harmony {
54 struct harmony_audio_platform_data *pdata;
55 int gpio_spkr_en_requested;
58 static int harmony_asoc_hw_params(struct snd_pcm_substream *substream,
59 struct snd_pcm_hw_params *params)
61 struct snd_soc_pcm_runtime *rtd = substream->private_data;
62 struct snd_soc_dai *codec_dai = rtd->codec_dai;
63 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
64 int srate, mclk, mclk_change;
65 int err;
67 srate = params_rate(params);
68 switch (srate) {
69 case 64000:
70 case 88200:
71 case 96000:
72 mclk = 128 * srate;
73 break;
74 default:
75 mclk = 256 * srate;
76 break;
78 /* FIXME: Codec only requires >= 3MHz if OSR==0 */
79 while (mclk < 6000000)
80 mclk *= 2;
82 err = tegra_asoc_utils_set_rate(srate, mclk, &mclk_change);
83 if (err < 0) {
84 pr_err(PREFIX "Can't configure clocks\n");
85 return err;
88 err = snd_soc_dai_set_fmt(codec_dai,
89 SND_SOC_DAIFMT_I2S |
90 SND_SOC_DAIFMT_NB_NF |
91 SND_SOC_DAIFMT_CBS_CFS);
92 if (err < 0) {
93 pr_err(PREFIX "codec_dai fmt not set\n");
94 return err;
97 err = snd_soc_dai_set_fmt(cpu_dai,
98 SND_SOC_DAIFMT_I2S |
99 SND_SOC_DAIFMT_NB_NF |
100 SND_SOC_DAIFMT_CBS_CFS);
101 if (err < 0) {
102 pr_err(PREFIX "cpu_dai fmt not set\n");
103 return err;
106 if (mclk_change) {
107 err = snd_soc_dai_set_sysclk(codec_dai, 0, mclk,
108 SND_SOC_CLOCK_IN);
109 if (err < 0) {
110 pr_err(PREFIX "codec_dai clock not set\n");
111 return err;
115 return 0;
118 static struct snd_soc_ops harmony_asoc_ops = {
119 .hw_params = harmony_asoc_hw_params,
122 static int harmony_event_int_spk(struct snd_soc_dapm_widget *w,
123 struct snd_kcontrol *k, int event)
125 struct snd_soc_codec *codec = w->codec;
126 struct snd_soc_card *card = codec->card;
127 struct tegra_harmony *harmony = snd_soc_card_get_drvdata(card);
128 struct harmony_audio_platform_data *pdata = harmony->pdata;
130 gpio_set_value_cansleep(pdata->gpio_spkr_en,
131 !!SND_SOC_DAPM_EVENT_ON(event));
133 return 0;
136 static const struct snd_soc_dapm_widget harmony_dapm_widgets[] = {
137 SND_SOC_DAPM_SPK("Int Spk", harmony_event_int_spk),
138 SND_SOC_DAPM_HP("Headphone Jack", NULL),
139 SND_SOC_DAPM_MIC("Mic Jack", NULL),
142 static const struct snd_soc_dapm_route harmony_audio_map[] = {
143 {"Headphone Jack", NULL, "HPOUTR"},
144 {"Headphone Jack", NULL, "HPOUTL"},
145 {"Int Spk", NULL, "ROP"},
146 {"Int Spk", NULL, "RON"},
147 {"Int Spk", NULL, "LOP"},
148 {"Int Spk", NULL, "LON"},
149 {"Mic Bias", NULL, "Mic Jack"},
150 {"IN1L", NULL, "Mic Bias"},
153 static int harmony_asoc_init(struct snd_soc_pcm_runtime *rtd)
155 struct snd_soc_codec *codec = rtd->codec;
156 struct snd_soc_dapm_context *dapm = &codec->dapm;
157 struct snd_soc_card *card = codec->card;
158 struct tegra_harmony *harmony = snd_soc_card_get_drvdata(card);
159 struct harmony_audio_platform_data *pdata = harmony->pdata;
160 int ret;
162 ret = gpio_request(pdata->gpio_spkr_en, "spkr_en");
163 if (ret) {
164 dev_err(card->dev, "cannot get spkr_en gpio\n");
165 return ret;
167 harmony->gpio_spkr_en_requested = 1;
169 gpio_direction_output(pdata->gpio_spkr_en, 0);
171 snd_soc_dapm_new_controls(dapm, harmony_dapm_widgets,
172 ARRAY_SIZE(harmony_dapm_widgets));
174 snd_soc_dapm_add_routes(dapm, harmony_audio_map,
175 ARRAY_SIZE(harmony_audio_map));
177 snd_soc_dapm_enable_pin(dapm, "Headphone Jack");
178 snd_soc_dapm_enable_pin(dapm, "Int Spk");
179 snd_soc_dapm_enable_pin(dapm, "Mic Jack");
180 snd_soc_dapm_sync(dapm);
182 return 0;
185 static struct snd_soc_dai_link harmony_wm8903_dai = {
186 .name = "WM8903",
187 .stream_name = "WM8903 PCM",
188 .codec_name = "wm8903-codec.0-001a",
189 .platform_name = "tegra-pcm-audio",
190 .cpu_dai_name = "tegra-i2s.0",
191 .codec_dai_name = "wm8903-hifi",
192 .init = harmony_asoc_init,
193 .ops = &harmony_asoc_ops,
196 static struct snd_soc_card snd_soc_harmony = {
197 .name = "tegra-harmony",
198 .dai_link = &harmony_wm8903_dai,
199 .num_links = 1,
202 static __devinit int tegra_snd_harmony_probe(struct platform_device *pdev)
204 struct snd_soc_card *card = &snd_soc_harmony;
205 struct tegra_harmony *harmony;
206 struct harmony_audio_platform_data *pdata;
207 int ret;
209 if (!machine_is_harmony()) {
210 dev_err(&pdev->dev, "Not running on Tegra Harmony!\n");
211 return -ENODEV;
214 pdata = pdev->dev.platform_data;
215 if (!pdata) {
216 dev_err(&pdev->dev, "no platform data supplied\n");
217 return -EINVAL;
220 harmony = kzalloc(sizeof(struct tegra_harmony), GFP_KERNEL);
221 if (!harmony) {
222 dev_err(&pdev->dev, "Can't allocate tegra_harmony\n");
223 return -ENOMEM;
226 harmony->pdata = pdata;
228 ret = tegra_asoc_utils_init();
229 if (ret)
230 goto err_free_harmony;
232 card->dev = &pdev->dev;
233 platform_set_drvdata(pdev, card);
234 snd_soc_card_set_drvdata(card, harmony);
236 ret = snd_soc_register_card(card);
237 if (ret) {
238 dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n",
239 ret);
240 goto err_clear_drvdata;
243 return 0;
245 err_clear_drvdata:
246 snd_soc_card_set_drvdata(card, NULL);
247 platform_set_drvdata(pdev, NULL);
248 card->dev = NULL;
249 tegra_asoc_utils_fini();
250 err_free_harmony:
251 kfree(harmony);
252 return ret;
255 static int __devexit tegra_snd_harmony_remove(struct platform_device *pdev)
257 struct snd_soc_card *card = platform_get_drvdata(pdev);
258 struct tegra_harmony *harmony = snd_soc_card_get_drvdata(card);
259 struct harmony_audio_platform_data *pdata = harmony->pdata;
261 snd_soc_unregister_card(card);
263 snd_soc_card_set_drvdata(card, NULL);
264 platform_set_drvdata(pdev, NULL);
265 card->dev = NULL;
267 tegra_asoc_utils_fini();
269 if (harmony->gpio_spkr_en_requested)
270 gpio_free(pdata->gpio_spkr_en);
272 kfree(harmony);
274 return 0;
277 static struct platform_driver tegra_snd_harmony_driver = {
278 .driver = {
279 .name = DRV_NAME,
280 .owner = THIS_MODULE,
282 .probe = tegra_snd_harmony_probe,
283 .remove = __devexit_p(tegra_snd_harmony_remove),
286 static int __init snd_tegra_harmony_init(void)
288 return platform_driver_register(&tegra_snd_harmony_driver);
290 module_init(snd_tegra_harmony_init);
292 static void __exit snd_tegra_harmony_exit(void)
294 platform_driver_unregister(&tegra_snd_harmony_driver);
296 module_exit(snd_tegra_harmony_exit);
298 MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>");
299 MODULE_DESCRIPTION("Harmony machine ASoC driver");
300 MODULE_LICENSE("GPL");