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