ASoC: Tegra: Harmony: Remove redundant !!
[deliverable/linux.git] / sound / soc / tegra / harmony.c
CommitLineData
a8bf1ba1
SW
1/*
2 * harmony.c - Harmony machine ASoC driver
3 *
4 * Author: Stephen Warren <swarren@nvidia.com>
72de2b1a 5 * Copyright (C) 2010-2011 - NVIDIA, Inc.
a8bf1ba1
SW
6 *
7 * Based on code copyright/by:
8 *
9 * (c) 2009, 2010 Nvidia Graphics Pvt. Ltd.
10 *
11 * Copyright 2007 Wolfson Microelectronics PLC.
12 * Author: Graeme Gregory
13 * graeme.gregory@wolfsonmicro.com or linux@wolfsonmicro.com
14 *
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.
18 *
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.
23 *
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
28 *
29 */
30
31#include <asm/mach-types.h>
72de2b1a 32
a8bf1ba1 33#include <linux/module.h>
72de2b1a
SW
34#include <linux/platform_device.h>
35#include <linux/slab.h>
6e267645
SW
36#include <linux/gpio.h>
37
38#include <mach/harmony_audio.h>
72de2b1a 39
a8bf1ba1
SW
40#include <sound/core.h>
41#include <sound/pcm.h>
42#include <sound/pcm_params.h>
43#include <sound/soc.h>
44
45#include "tegra_das.h"
46#include "tegra_i2s.h"
47#include "tegra_pcm.h"
48#include "tegra_asoc_utils.h"
49
72de2b1a 50#define DRV_NAME "tegra-snd-harmony"
a8bf1ba1 51
72de2b1a 52struct tegra_harmony {
d64e57ce 53 struct tegra_asoc_utils_data util_data;
6e267645
SW
54 struct harmony_audio_platform_data *pdata;
55 int gpio_spkr_en_requested;
72de2b1a 56};
a8bf1ba1
SW
57
58static int harmony_asoc_hw_params(struct snd_pcm_substream *substream,
59 struct snd_pcm_hw_params *params)
60{
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;
c244d477
SW
64 struct snd_soc_codec *codec = rtd->codec;
65 struct snd_soc_card *card = codec->card;
d64e57ce 66 struct tegra_harmony *harmony = snd_soc_card_get_drvdata(card);
a8bf1ba1
SW
67 int srate, mclk, mclk_change;
68 int err;
69
70 srate = params_rate(params);
71 switch (srate) {
72 case 64000:
73 case 88200:
74 case 96000:
75 mclk = 128 * srate;
76 break;
77 default:
78 mclk = 256 * srate;
79 break;
80 }
81 /* FIXME: Codec only requires >= 3MHz if OSR==0 */
82 while (mclk < 6000000)
83 mclk *= 2;
84
d64e57ce
SW
85 err = tegra_asoc_utils_set_rate(&harmony->util_data, srate, mclk,
86 &mclk_change);
a8bf1ba1 87 if (err < 0) {
c244d477 88 dev_err(card->dev, "Can't configure clocks\n");
a8bf1ba1
SW
89 return err;
90 }
91
92 err = snd_soc_dai_set_fmt(codec_dai,
93 SND_SOC_DAIFMT_I2S |
94 SND_SOC_DAIFMT_NB_NF |
95 SND_SOC_DAIFMT_CBS_CFS);
96 if (err < 0) {
c244d477 97 dev_err(card->dev, "codec_dai fmt not set\n");
a8bf1ba1
SW
98 return err;
99 }
100
101 err = snd_soc_dai_set_fmt(cpu_dai,
102 SND_SOC_DAIFMT_I2S |
103 SND_SOC_DAIFMT_NB_NF |
104 SND_SOC_DAIFMT_CBS_CFS);
105 if (err < 0) {
c244d477 106 dev_err(card->dev, "cpu_dai fmt not set\n");
a8bf1ba1
SW
107 return err;
108 }
109
110 if (mclk_change) {
bc72fe0c
SW
111 err = snd_soc_dai_set_sysclk(codec_dai, 0, mclk,
112 SND_SOC_CLOCK_IN);
113 if (err < 0) {
c244d477 114 dev_err(card->dev, "codec_dai clock not set\n");
bc72fe0c
SW
115 return err;
116 }
a8bf1ba1
SW
117 }
118
119 return 0;
120}
121
122static struct snd_soc_ops harmony_asoc_ops = {
123 .hw_params = harmony_asoc_hw_params,
124};
125
6e267645
SW
126static int harmony_event_int_spk(struct snd_soc_dapm_widget *w,
127 struct snd_kcontrol *k, int event)
128{
129 struct snd_soc_codec *codec = w->codec;
130 struct snd_soc_card *card = codec->card;
131 struct tegra_harmony *harmony = snd_soc_card_get_drvdata(card);
132 struct harmony_audio_platform_data *pdata = harmony->pdata;
133
134 gpio_set_value_cansleep(pdata->gpio_spkr_en,
f9eabc3d 135 SND_SOC_DAPM_EVENT_ON(event));
6e267645
SW
136
137 return 0;
138}
139
62ffac4d 140static const struct snd_soc_dapm_widget harmony_dapm_widgets[] = {
6e267645 141 SND_SOC_DAPM_SPK("Int Spk", harmony_event_int_spk),
62ffac4d
SW
142 SND_SOC_DAPM_HP("Headphone Jack", NULL),
143 SND_SOC_DAPM_MIC("Mic Jack", NULL),
144};
145
146static const struct snd_soc_dapm_route harmony_audio_map[] = {
147 {"Headphone Jack", NULL, "HPOUTR"},
148 {"Headphone Jack", NULL, "HPOUTL"},
6e267645
SW
149 {"Int Spk", NULL, "ROP"},
150 {"Int Spk", NULL, "RON"},
151 {"Int Spk", NULL, "LOP"},
152 {"Int Spk", NULL, "LON"},
62ffac4d
SW
153 {"Mic Bias", NULL, "Mic Jack"},
154 {"IN1L", NULL, "Mic Bias"},
155};
156
157static int harmony_asoc_init(struct snd_soc_pcm_runtime *rtd)
158{
159 struct snd_soc_codec *codec = rtd->codec;
160 struct snd_soc_dapm_context *dapm = &codec->dapm;
6e267645
SW
161 struct snd_soc_card *card = codec->card;
162 struct tegra_harmony *harmony = snd_soc_card_get_drvdata(card);
163 struct harmony_audio_platform_data *pdata = harmony->pdata;
164 int ret;
165
166 ret = gpio_request(pdata->gpio_spkr_en, "spkr_en");
167 if (ret) {
168 dev_err(card->dev, "cannot get spkr_en gpio\n");
169 return ret;
170 }
171 harmony->gpio_spkr_en_requested = 1;
172
173 gpio_direction_output(pdata->gpio_spkr_en, 0);
62ffac4d
SW
174
175 snd_soc_dapm_new_controls(dapm, harmony_dapm_widgets,
176 ARRAY_SIZE(harmony_dapm_widgets));
177
178 snd_soc_dapm_add_routes(dapm, harmony_audio_map,
179 ARRAY_SIZE(harmony_audio_map));
180
181 snd_soc_dapm_enable_pin(dapm, "Headphone Jack");
6e267645 182 snd_soc_dapm_enable_pin(dapm, "Int Spk");
62ffac4d
SW
183 snd_soc_dapm_enable_pin(dapm, "Mic Jack");
184 snd_soc_dapm_sync(dapm);
185
186 return 0;
187}
188
a8bf1ba1
SW
189static struct snd_soc_dai_link harmony_wm8903_dai = {
190 .name = "WM8903",
191 .stream_name = "WM8903 PCM",
192 .codec_name = "wm8903-codec.0-001a",
193 .platform_name = "tegra-pcm-audio",
194 .cpu_dai_name = "tegra-i2s.0",
195 .codec_dai_name = "wm8903-hifi",
62ffac4d 196 .init = harmony_asoc_init,
a8bf1ba1
SW
197 .ops = &harmony_asoc_ops,
198};
199
200static struct snd_soc_card snd_soc_harmony = {
201 .name = "tegra-harmony",
202 .dai_link = &harmony_wm8903_dai,
203 .num_links = 1,
204};
205
72de2b1a 206static __devinit int tegra_snd_harmony_probe(struct platform_device *pdev)
a8bf1ba1 207{
72de2b1a
SW
208 struct snd_soc_card *card = &snd_soc_harmony;
209 struct tegra_harmony *harmony;
6e267645 210 struct harmony_audio_platform_data *pdata;
a8bf1ba1
SW
211 int ret;
212
213 if (!machine_is_harmony()) {
72de2b1a 214 dev_err(&pdev->dev, "Not running on Tegra Harmony!\n");
a8bf1ba1
SW
215 return -ENODEV;
216 }
217
6e267645
SW
218 pdata = pdev->dev.platform_data;
219 if (!pdata) {
220 dev_err(&pdev->dev, "no platform data supplied\n");
221 return -EINVAL;
222 }
223
72de2b1a
SW
224 harmony = kzalloc(sizeof(struct tegra_harmony), GFP_KERNEL);
225 if (!harmony) {
226 dev_err(&pdev->dev, "Can't allocate tegra_harmony\n");
227 return -ENOMEM;
a8bf1ba1
SW
228 }
229
6e267645
SW
230 harmony->pdata = pdata;
231
d64e57ce 232 ret = tegra_asoc_utils_init(&harmony->util_data, &pdev->dev);
72de2b1a
SW
233 if (ret)
234 goto err_free_harmony;
a8bf1ba1 235
72de2b1a
SW
236 card->dev = &pdev->dev;
237 platform_set_drvdata(pdev, card);
238 snd_soc_card_set_drvdata(card, harmony);
a8bf1ba1 239
72de2b1a 240 ret = snd_soc_register_card(card);
a8bf1ba1 241 if (ret) {
72de2b1a 242 dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n",
a8bf1ba1 243 ret);
72de2b1a 244 goto err_clear_drvdata;
a8bf1ba1
SW
245 }
246
247 return 0;
248
72de2b1a
SW
249err_clear_drvdata:
250 snd_soc_card_set_drvdata(card, NULL);
251 platform_set_drvdata(pdev, NULL);
252 card->dev = NULL;
d64e57ce 253 tegra_asoc_utils_fini(&harmony->util_data);
72de2b1a
SW
254err_free_harmony:
255 kfree(harmony);
a8bf1ba1
SW
256 return ret;
257}
a8bf1ba1 258
72de2b1a 259static int __devexit tegra_snd_harmony_remove(struct platform_device *pdev)
a8bf1ba1 260{
72de2b1a
SW
261 struct snd_soc_card *card = platform_get_drvdata(pdev);
262 struct tegra_harmony *harmony = snd_soc_card_get_drvdata(card);
6e267645 263 struct harmony_audio_platform_data *pdata = harmony->pdata;
72de2b1a
SW
264
265 snd_soc_unregister_card(card);
266
267 snd_soc_card_set_drvdata(card, NULL);
268 platform_set_drvdata(pdev, NULL);
269 card->dev = NULL;
a8bf1ba1 270
d64e57ce 271 tegra_asoc_utils_fini(&harmony->util_data);
72de2b1a 272
6e267645
SW
273 if (harmony->gpio_spkr_en_requested)
274 gpio_free(pdata->gpio_spkr_en);
275
72de2b1a
SW
276 kfree(harmony);
277
278 return 0;
279}
280
281static struct platform_driver tegra_snd_harmony_driver = {
282 .driver = {
283 .name = DRV_NAME,
284 .owner = THIS_MODULE,
285 },
286 .probe = tegra_snd_harmony_probe,
287 .remove = __devexit_p(tegra_snd_harmony_remove),
288};
289
290static int __init snd_tegra_harmony_init(void)
291{
292 return platform_driver_register(&tegra_snd_harmony_driver);
293}
294module_init(snd_tegra_harmony_init);
295
296static void __exit snd_tegra_harmony_exit(void)
297{
298 platform_driver_unregister(&tegra_snd_harmony_driver);
a8bf1ba1 299}
72de2b1a 300module_exit(snd_tegra_harmony_exit);
a8bf1ba1
SW
301
302MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>");
303MODULE_DESCRIPTION("Harmony machine ASoC driver");
304MODULE_LICENSE("GPL");
This page took 0.074983 seconds and 5 git commands to generate.