blob: 1fd6a41b9162f6d743a1606c42a3edb6be25ea0d [file] [log] [blame]
Stephen Warrena8bf1ba2011-01-07 22:36:16 -07001/*
Stephen Warrendc0a50af2011-04-12 11:40:36 -06002 * tegra_wm8903.c - Tegra machine ASoC driver for boards using WM8903 codec.
Stephen Warrena8bf1ba2011-01-07 22:36:16 -07003 *
4 * Author: Stephen Warren <swarren@nvidia.com>
Stephen Warren518de862012-03-20 14:55:49 -06005 * Copyright (C) 2010-2012 - NVIDIA, Inc.
Stephen Warrena8bf1ba2011-01-07 22:36:16 -07006 *
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>
Stephen Warren72de2b12011-01-28 14:26:36 -070032
Stephen Warrena8bf1ba2011-01-07 22:36:16 -070033#include <linux/module.h>
Stephen Warren72de2b12011-01-28 14:26:36 -070034#include <linux/platform_device.h>
35#include <linux/slab.h>
Stephen Warren6e267642011-01-28 14:26:37 -070036#include <linux/gpio.h>
Stephen Warren07cdf362011-12-12 15:55:36 -070037#include <linux/of_gpio.h>
Stephen Warren6e267642011-01-28 14:26:37 -070038
Stephen Warren4651d552011-04-12 11:28:59 -060039#include <mach/tegra_wm8903_pdata.h>
Stephen Warren72de2b12011-01-28 14:26:36 -070040
Stephen Warrena8bf1ba2011-01-07 22:36:16 -070041#include <sound/core.h>
Stephen Warrenf7d3e402011-02-03 13:56:13 -070042#include <sound/jack.h>
Stephen Warrena8bf1ba2011-01-07 22:36:16 -070043#include <sound/pcm.h>
44#include <sound/pcm_params.h>
45#include <sound/soc.h>
46
Stephen Warren41b5f9b2011-02-10 15:37:16 -070047#include "../codecs/wm8903.h"
48
Stephen Warrena8bf1ba2011-01-07 22:36:16 -070049#include "tegra_asoc_utils.h"
50
Stephen Warren7b33af22011-04-12 11:29:00 -060051#define DRV_NAME "tegra-snd-wm8903"
Stephen Warrena8bf1ba2011-01-07 22:36:16 -070052
Stephen Warrendc0a50af2011-04-12 11:40:36 -060053struct tegra_wm8903 {
Stephen Warren07cdf362011-12-12 15:55:36 -070054 struct tegra_wm8903_platform_data pdata;
Stephen Warrend64e57c2011-01-28 14:26:40 -070055 struct tegra_asoc_utils_data util_data;
Stephen Warren72de2b12011-01-28 14:26:36 -070056};
Stephen Warrena8bf1ba2011-01-07 22:36:16 -070057
Stephen Warrendc0a50af2011-04-12 11:40:36 -060058static int tegra_wm8903_hw_params(struct snd_pcm_substream *substream,
Stephen Warrena8bf1ba2011-01-07 22:36:16 -070059 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;
Stephen Warrenc244d472011-01-28 14:26:39 -070064 struct snd_soc_codec *codec = rtd->codec;
65 struct snd_soc_card *card = codec->card;
Stephen Warrendc0a50af2011-04-12 11:40:36 -060066 struct tegra_wm8903 *machine = snd_soc_card_get_drvdata(card);
Stephen Warren07541392011-04-19 15:25:09 -060067 int srate, mclk;
Stephen Warrena8bf1ba2011-01-07 22:36:16 -070068 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
Stephen Warren07541392011-04-19 15:25:09 -060085 err = tegra_asoc_utils_set_rate(&machine->util_data, srate, mclk);
Stephen Warrena8bf1ba2011-01-07 22:36:16 -070086 if (err < 0) {
Stephen Warrenc244d472011-01-28 14:26:39 -070087 dev_err(card->dev, "Can't configure clocks\n");
Stephen Warrena8bf1ba2011-01-07 22:36:16 -070088 return err;
89 }
90
91 err = snd_soc_dai_set_fmt(codec_dai,
92 SND_SOC_DAIFMT_I2S |
93 SND_SOC_DAIFMT_NB_NF |
94 SND_SOC_DAIFMT_CBS_CFS);
95 if (err < 0) {
Stephen Warrenc244d472011-01-28 14:26:39 -070096 dev_err(card->dev, "codec_dai fmt not set\n");
Stephen Warrena8bf1ba2011-01-07 22:36:16 -070097 return err;
98 }
99
100 err = snd_soc_dai_set_fmt(cpu_dai,
101 SND_SOC_DAIFMT_I2S |
102 SND_SOC_DAIFMT_NB_NF |
103 SND_SOC_DAIFMT_CBS_CFS);
104 if (err < 0) {
Stephen Warrenc244d472011-01-28 14:26:39 -0700105 dev_err(card->dev, "cpu_dai fmt not set\n");
Stephen Warrena8bf1ba2011-01-07 22:36:16 -0700106 return err;
107 }
108
Stephen Warren07541392011-04-19 15:25:09 -0600109 err = snd_soc_dai_set_sysclk(codec_dai, 0, mclk,
110 SND_SOC_CLOCK_IN);
111 if (err < 0) {
112 dev_err(card->dev, "codec_dai clock not set\n");
113 return err;
Stephen Warrena8bf1ba2011-01-07 22:36:16 -0700114 }
115
116 return 0;
117}
118
Stephen Warrendc0a50af2011-04-12 11:40:36 -0600119static struct snd_soc_ops tegra_wm8903_ops = {
120 .hw_params = tegra_wm8903_hw_params,
Stephen Warrena8bf1ba2011-01-07 22:36:16 -0700121};
122
Stephen Warrendc0a50af2011-04-12 11:40:36 -0600123static struct snd_soc_jack tegra_wm8903_hp_jack;
Stephen Warrenf7d3e402011-02-03 13:56:13 -0700124
Stephen Warrendc0a50af2011-04-12 11:40:36 -0600125static struct snd_soc_jack_pin tegra_wm8903_hp_jack_pins[] = {
Stephen Warrenf7d3e402011-02-03 13:56:13 -0700126 {
127 .pin = "Headphone Jack",
128 .mask = SND_JACK_HEADPHONE,
129 },
130};
131
Stephen Warren3eb25f92011-04-12 11:40:38 -0600132static struct snd_soc_jack_gpio tegra_wm8903_hp_jack_gpio = {
133 .name = "headphone detect",
134 .report = SND_JACK_HEADPHONE,
135 .debounce_time = 150,
136 .invert = 1,
Stephen Warrenf7d3e402011-02-03 13:56:13 -0700137};
138
Stephen Warrendc0a50af2011-04-12 11:40:36 -0600139static struct snd_soc_jack tegra_wm8903_mic_jack;
Stephen Warren41b5f9b2011-02-10 15:37:16 -0700140
Stephen Warrendc0a50af2011-04-12 11:40:36 -0600141static struct snd_soc_jack_pin tegra_wm8903_mic_jack_pins[] = {
Stephen Warren41b5f9b2011-02-10 15:37:16 -0700142 {
143 .pin = "Mic Jack",
144 .mask = SND_JACK_MICROPHONE,
145 },
146};
147
Stephen Warrendc0a50af2011-04-12 11:40:36 -0600148static int tegra_wm8903_event_int_spk(struct snd_soc_dapm_widget *w,
Stephen Warren6e267642011-01-28 14:26:37 -0700149 struct snd_kcontrol *k, int event)
150{
Stephen Warrena32955d2011-04-19 15:25:10 -0600151 struct snd_soc_dapm_context *dapm = w->dapm;
152 struct snd_soc_card *card = dapm->card;
Stephen Warrendc0a50af2011-04-12 11:40:36 -0600153 struct tegra_wm8903 *machine = snd_soc_card_get_drvdata(card);
Stephen Warren07cdf362011-12-12 15:55:36 -0700154 struct tegra_wm8903_platform_data *pdata = &machine->pdata;
Stephen Warren6e267642011-01-28 14:26:37 -0700155
Stephen Warren14df4152012-05-22 16:08:53 -0600156 if (!gpio_is_valid(pdata->gpio_spkr_en))
Stephen Warren773b1d32011-04-12 11:40:39 -0600157 return 0;
158
Stephen Warren6e267642011-01-28 14:26:37 -0700159 gpio_set_value_cansleep(pdata->gpio_spkr_en,
Stephen Warrenf9eabc32011-01-31 11:00:17 -0700160 SND_SOC_DAPM_EVENT_ON(event));
Stephen Warren6e267642011-01-28 14:26:37 -0700161
162 return 0;
163}
164
Stephen Warren773b1d32011-04-12 11:40:39 -0600165static int tegra_wm8903_event_hp(struct snd_soc_dapm_widget *w,
166 struct snd_kcontrol *k, int event)
167{
Stephen Warrena32955d2011-04-19 15:25:10 -0600168 struct snd_soc_dapm_context *dapm = w->dapm;
169 struct snd_soc_card *card = dapm->card;
Stephen Warren773b1d32011-04-12 11:40:39 -0600170 struct tegra_wm8903 *machine = snd_soc_card_get_drvdata(card);
Stephen Warren07cdf362011-12-12 15:55:36 -0700171 struct tegra_wm8903_platform_data *pdata = &machine->pdata;
Stephen Warren773b1d32011-04-12 11:40:39 -0600172
Stephen Warren14df4152012-05-22 16:08:53 -0600173 if (!gpio_is_valid(pdata->gpio_hp_mute))
Stephen Warren773b1d32011-04-12 11:40:39 -0600174 return 0;
175
176 gpio_set_value_cansleep(pdata->gpio_hp_mute,
177 !SND_SOC_DAPM_EVENT_ON(event));
178
179 return 0;
180}
181
Stephen Warrendc0a50af2011-04-12 11:40:36 -0600182static const struct snd_soc_dapm_widget tegra_wm8903_dapm_widgets[] = {
183 SND_SOC_DAPM_SPK("Int Spk", tegra_wm8903_event_int_spk),
Stephen Warren773b1d32011-04-12 11:40:39 -0600184 SND_SOC_DAPM_HP("Headphone Jack", tegra_wm8903_event_hp),
Stephen Warren62ffac42011-01-13 15:22:08 -0700185 SND_SOC_DAPM_MIC("Mic Jack", NULL),
186};
187
188static const struct snd_soc_dapm_route harmony_audio_map[] = {
189 {"Headphone Jack", NULL, "HPOUTR"},
190 {"Headphone Jack", NULL, "HPOUTL"},
Stephen Warren6e267642011-01-28 14:26:37 -0700191 {"Int Spk", NULL, "ROP"},
192 {"Int Spk", NULL, "RON"},
193 {"Int Spk", NULL, "LOP"},
194 {"Int Spk", NULL, "LON"},
Mark Brown5032dc32011-11-27 12:20:08 +0000195 {"Mic Jack", NULL, "MICBIAS"},
196 {"IN1L", NULL, "Mic Jack"},
Stephen Warren62ffac42011-01-13 15:22:08 -0700197};
198
Stephen Warren773b1d32011-04-12 11:40:39 -0600199static const struct snd_soc_dapm_route seaboard_audio_map[] = {
200 {"Headphone Jack", NULL, "HPOUTR"},
201 {"Headphone Jack", NULL, "HPOUTL"},
202 {"Int Spk", NULL, "ROP"},
203 {"Int Spk", NULL, "RON"},
204 {"Int Spk", NULL, "LOP"},
205 {"Int Spk", NULL, "LON"},
Mark Brown5032dc32011-11-27 12:20:08 +0000206 {"Mic Jack", NULL, "MICBIAS"},
207 {"IN1R", NULL, "Mic Jack"},
Stephen Warren773b1d32011-04-12 11:40:39 -0600208};
209
210static const struct snd_soc_dapm_route kaen_audio_map[] = {
211 {"Headphone Jack", NULL, "HPOUTR"},
212 {"Headphone Jack", NULL, "HPOUTL"},
213 {"Int Spk", NULL, "ROP"},
214 {"Int Spk", NULL, "RON"},
215 {"Int Spk", NULL, "LOP"},
216 {"Int Spk", NULL, "LON"},
Mark Brown5032dc32011-11-27 12:20:08 +0000217 {"Mic Jack", NULL, "MICBIAS"},
218 {"IN2R", NULL, "Mic Jack"},
Stephen Warren773b1d32011-04-12 11:40:39 -0600219};
220
221static const struct snd_soc_dapm_route aebl_audio_map[] = {
222 {"Headphone Jack", NULL, "HPOUTR"},
223 {"Headphone Jack", NULL, "HPOUTL"},
224 {"Int Spk", NULL, "LINEOUTR"},
225 {"Int Spk", NULL, "LINEOUTL"},
Mark Brown5032dc32011-11-27 12:20:08 +0000226 {"Mic Jack", NULL, "MICBIAS"},
227 {"IN1R", NULL, "Mic Jack"},
Stephen Warren773b1d32011-04-12 11:40:39 -0600228};
229
Stephen Warrendc0a50af2011-04-12 11:40:36 -0600230static const struct snd_kcontrol_new tegra_wm8903_controls[] = {
Stephen Warren3d8bc392011-02-03 13:56:14 -0700231 SOC_DAPM_PIN_SWITCH("Int Spk"),
232};
233
Stephen Warrendc0a50af2011-04-12 11:40:36 -0600234static int tegra_wm8903_init(struct snd_soc_pcm_runtime *rtd)
Stephen Warren62ffac42011-01-13 15:22:08 -0700235{
236 struct snd_soc_codec *codec = rtd->codec;
237 struct snd_soc_dapm_context *dapm = &codec->dapm;
Stephen Warren6e267642011-01-28 14:26:37 -0700238 struct snd_soc_card *card = codec->card;
Stephen Warrendc0a50af2011-04-12 11:40:36 -0600239 struct tegra_wm8903 *machine = snd_soc_card_get_drvdata(card);
Stephen Warren07cdf362011-12-12 15:55:36 -0700240 struct tegra_wm8903_platform_data *pdata = &machine->pdata;
Stephen Warrenbf1b1322011-02-10 15:37:18 -0700241
Stephen Warren773b1d32011-04-12 11:40:39 -0600242 if (gpio_is_valid(pdata->gpio_hp_det)) {
243 tegra_wm8903_hp_jack_gpio.gpio = pdata->gpio_hp_det;
244 snd_soc_jack_new(codec, "Headphone Jack", SND_JACK_HEADPHONE,
245 &tegra_wm8903_hp_jack);
246 snd_soc_jack_add_pins(&tegra_wm8903_hp_jack,
247 ARRAY_SIZE(tegra_wm8903_hp_jack_pins),
248 tegra_wm8903_hp_jack_pins);
249 snd_soc_jack_add_gpios(&tegra_wm8903_hp_jack,
250 1,
251 &tegra_wm8903_hp_jack_gpio);
252 }
Stephen Warrenf7d3e402011-02-03 13:56:13 -0700253
Stephen Warren41b5f9b2011-02-10 15:37:16 -0700254 snd_soc_jack_new(codec, "Mic Jack", SND_JACK_MICROPHONE,
Stephen Warrendc0a50af2011-04-12 11:40:36 -0600255 &tegra_wm8903_mic_jack);
256 snd_soc_jack_add_pins(&tegra_wm8903_mic_jack,
257 ARRAY_SIZE(tegra_wm8903_mic_jack_pins),
258 tegra_wm8903_mic_jack_pins);
259 wm8903_mic_detect(codec, &tegra_wm8903_mic_jack, SND_JACK_MICROPHONE,
260 0);
Stephen Warren41b5f9b2011-02-10 15:37:16 -0700261
Mark Brown5032dc32011-11-27 12:20:08 +0000262 snd_soc_dapm_force_enable_pin(dapm, "MICBIAS");
Stephen Warren41b5f9b2011-02-10 15:37:16 -0700263
Stephen Warren62ffac42011-01-13 15:22:08 -0700264 return 0;
265}
266
Stephen Warrendc0a50af2011-04-12 11:40:36 -0600267static struct snd_soc_dai_link tegra_wm8903_dai = {
Stephen Warrena8bf1ba2011-01-07 22:36:16 -0700268 .name = "WM8903",
269 .stream_name = "WM8903 PCM",
Mark Brown4b592c92011-02-09 13:47:06 +0000270 .codec_name = "wm8903.0-001a",
Stephen Warren896637a2012-04-06 10:30:52 -0600271 .platform_name = "tegra20-i2s.0",
272 .cpu_dai_name = "tegra20-i2s.0",
Stephen Warrena8bf1ba2011-01-07 22:36:16 -0700273 .codec_dai_name = "wm8903-hifi",
Stephen Warrendc0a50af2011-04-12 11:40:36 -0600274 .init = tegra_wm8903_init,
275 .ops = &tegra_wm8903_ops,
Stephen Warrena8bf1ba2011-01-07 22:36:16 -0700276};
277
Stephen Warrendc0a50af2011-04-12 11:40:36 -0600278static struct snd_soc_card snd_soc_tegra_wm8903 = {
279 .name = "tegra-wm8903",
Axel Linb16eaf92011-12-22 21:23:01 +0800280 .owner = THIS_MODULE,
Stephen Warrendc0a50af2011-04-12 11:40:36 -0600281 .dai_link = &tegra_wm8903_dai,
Stephen Warrena8bf1ba2011-01-07 22:36:16 -0700282 .num_links = 1,
Stephen Warrendea8b6e2011-04-19 15:25:12 -0600283
284 .controls = tegra_wm8903_controls,
285 .num_controls = ARRAY_SIZE(tegra_wm8903_controls),
286 .dapm_widgets = tegra_wm8903_dapm_widgets,
287 .num_dapm_widgets = ARRAY_SIZE(tegra_wm8903_dapm_widgets),
Stephen Warren6e5fdba2011-11-23 12:42:05 -0700288 .fully_routed = true,
Stephen Warrena8bf1ba2011-01-07 22:36:16 -0700289};
290
Stephen Warrendc0a50af2011-04-12 11:40:36 -0600291static __devinit int tegra_wm8903_driver_probe(struct platform_device *pdev)
Stephen Warrena8bf1ba2011-01-07 22:36:16 -0700292{
Stephen Warrenf51022f2012-05-22 16:08:54 -0600293 struct device_node *np = pdev->dev.of_node;
Stephen Warrendc0a50af2011-04-12 11:40:36 -0600294 struct snd_soc_card *card = &snd_soc_tegra_wm8903;
295 struct tegra_wm8903 *machine;
Stephen Warrenf51022f2012-05-22 16:08:54 -0600296 struct tegra_wm8903_platform_data *pdata;
Stephen Warrena8bf1ba2011-01-07 22:36:16 -0700297 int ret;
298
Stephen Warren07cdf362011-12-12 15:55:36 -0700299 if (!pdev->dev.platform_data && !pdev->dev.of_node) {
Stephen Warren773b1d32011-04-12 11:40:39 -0600300 dev_err(&pdev->dev, "No platform data supplied\n");
Stephen Warren6e267642011-01-28 14:26:37 -0700301 return -EINVAL;
302 }
303
Stephen Warrene4e4c182011-11-22 18:21:20 -0700304 machine = devm_kzalloc(&pdev->dev, sizeof(struct tegra_wm8903),
305 GFP_KERNEL);
Stephen Warrendc0a50af2011-04-12 11:40:36 -0600306 if (!machine) {
307 dev_err(&pdev->dev, "Can't allocate tegra_wm8903 struct\n");
Stephen Warrene4e4c182011-11-22 18:21:20 -0700308 ret = -ENOMEM;
309 goto err;
Stephen Warren72de2b12011-01-28 14:26:36 -0700310 }
Stephen Warrenf51022f2012-05-22 16:08:54 -0600311 pdata = &machine->pdata;
Stephen Warren72de2b12011-01-28 14:26:36 -0700312
313 card->dev = &pdev->dev;
314 platform_set_drvdata(pdev, card);
Stephen Warrendc0a50af2011-04-12 11:40:36 -0600315 snd_soc_card_set_drvdata(card, machine);
Stephen Warren72de2b12011-01-28 14:26:36 -0700316
Stephen Warrenf51022f2012-05-22 16:08:54 -0600317 if (pdev->dev.platform_data) {
318 memcpy(pdata, card->dev->platform_data, sizeof(*pdata));
319 } else if (np) {
320 pdata->gpio_spkr_en = of_get_named_gpio(np,
321 "nvidia,spkr-en-gpios", 0);
322 if (pdata->gpio_spkr_en == -ENODEV)
323 return -EPROBE_DEFER;
324
325 pdata->gpio_hp_mute = of_get_named_gpio(np,
326 "nvidia,hp-mute-gpios", 0);
327 if (pdata->gpio_hp_mute == -ENODEV)
328 return -EPROBE_DEFER;
329
330 pdata->gpio_hp_det = of_get_named_gpio(np,
331 "nvidia,hp-det-gpios", 0);
332 if (pdata->gpio_hp_det == -ENODEV)
333 return -EPROBE_DEFER;
334
335 pdata->gpio_int_mic_en = of_get_named_gpio(np,
336 "nvidia,int-mic-en-gpios", 0);
337 if (pdata->gpio_int_mic_en == -ENODEV)
338 return -EPROBE_DEFER;
339
340 pdata->gpio_ext_mic_en = of_get_named_gpio(np,
341 "nvidia,ext-mic-en-gpios", 0);
342 if (pdata->gpio_ext_mic_en == -ENODEV)
343 return -EPROBE_DEFER;
344 }
345
346 if (np) {
Stephen Warren07cdf362011-12-12 15:55:36 -0700347 ret = snd_soc_of_parse_card_name(card, "nvidia,model");
348 if (ret)
349 goto err;
350
351 ret = snd_soc_of_parse_audio_routing(card,
352 "nvidia,audio-routing");
353 if (ret)
354 goto err;
355
356 tegra_wm8903_dai.codec_name = NULL;
Stephen Warrenf51022f2012-05-22 16:08:54 -0600357 tegra_wm8903_dai.codec_of_node = of_parse_phandle(np,
358 "nvidia,audio-codec", 0);
Stephen Warren07cdf362011-12-12 15:55:36 -0700359 if (!tegra_wm8903_dai.codec_of_node) {
360 dev_err(&pdev->dev,
361 "Property 'nvidia,audio-codec' missing or invalid\n");
362 ret = -EINVAL;
363 goto err;
364 }
365
366 tegra_wm8903_dai.cpu_dai_name = NULL;
Stephen Warrenf51022f2012-05-22 16:08:54 -0600367 tegra_wm8903_dai.cpu_dai_of_node = of_parse_phandle(np,
368 "nvidia,i2s-controller", 0);
Stephen Warren07cdf362011-12-12 15:55:36 -0700369 if (!tegra_wm8903_dai.cpu_dai_of_node) {
370 dev_err(&pdev->dev,
371 "Property 'nvidia,i2s-controller' missing or invalid\n");
372 ret = -EINVAL;
373 goto err;
374 }
375
Stephen Warren518de862012-03-20 14:55:49 -0600376 tegra_wm8903_dai.platform_name = NULL;
377 tegra_wm8903_dai.platform_of_node =
378 tegra_wm8903_dai.cpu_dai_of_node;
Stephen Warrendea8b6e2011-04-19 15:25:12 -0600379 } else {
Stephen Warren07cdf362011-12-12 15:55:36 -0700380 if (machine_is_harmony()) {
381 card->dapm_routes = harmony_audio_map;
382 card->num_dapm_routes = ARRAY_SIZE(harmony_audio_map);
383 } else if (machine_is_seaboard()) {
384 card->dapm_routes = seaboard_audio_map;
385 card->num_dapm_routes = ARRAY_SIZE(seaboard_audio_map);
386 } else if (machine_is_kaen()) {
387 card->dapm_routes = kaen_audio_map;
388 card->num_dapm_routes = ARRAY_SIZE(kaen_audio_map);
389 } else {
390 card->dapm_routes = aebl_audio_map;
391 card->num_dapm_routes = ARRAY_SIZE(aebl_audio_map);
392 }
Stephen Warrendea8b6e2011-04-19 15:25:12 -0600393 }
394
Stephen Warrenf51022f2012-05-22 16:08:54 -0600395 if (gpio_is_valid(pdata->gpio_spkr_en)) {
Stephen Warrene2d287c2012-05-22 16:08:55 -0600396 ret = devm_gpio_request_one(&pdev->dev, pdata->gpio_spkr_en,
397 GPIOF_OUT_INIT_LOW, "spkr_en");
Stephen Warrenf51022f2012-05-22 16:08:54 -0600398 if (ret) {
399 dev_err(card->dev, "cannot get spkr_en gpio\n");
400 return ret;
401 }
Stephen Warrenf51022f2012-05-22 16:08:54 -0600402 }
403
404 if (gpio_is_valid(pdata->gpio_hp_mute)) {
Stephen Warrene2d287c2012-05-22 16:08:55 -0600405 ret = devm_gpio_request_one(&pdev->dev, pdata->gpio_hp_mute,
406 GPIOF_OUT_INIT_HIGH, "hp_mute");
Stephen Warrenf51022f2012-05-22 16:08:54 -0600407 if (ret) {
408 dev_err(card->dev, "cannot get hp_mute gpio\n");
409 return ret;
410 }
Stephen Warrenf51022f2012-05-22 16:08:54 -0600411 }
412
413 if (gpio_is_valid(pdata->gpio_int_mic_en)) {
Stephen Warrene2d287c2012-05-22 16:08:55 -0600414 /* Disable int mic; enable signal is active-high */
415 ret = devm_gpio_request_one(&pdev->dev, pdata->gpio_int_mic_en,
416 GPIOF_OUT_INIT_LOW, "int_mic_en");
Stephen Warrenf51022f2012-05-22 16:08:54 -0600417 if (ret) {
418 dev_err(card->dev, "cannot get int_mic_en gpio\n");
419 return ret;
420 }
Stephen Warrenf51022f2012-05-22 16:08:54 -0600421 }
422
423 if (gpio_is_valid(pdata->gpio_ext_mic_en)) {
Stephen Warrene2d287c2012-05-22 16:08:55 -0600424 /* Enable ext mic; enable signal is active-low */
425 ret = devm_gpio_request_one(&pdev->dev, pdata->gpio_ext_mic_en,
426 GPIOF_OUT_INIT_LOW, "ext_mic_en");
Stephen Warrenf51022f2012-05-22 16:08:54 -0600427 if (ret) {
428 dev_err(card->dev, "cannot get ext_mic_en gpio\n");
429 return ret;
430 }
Stephen Warrenf51022f2012-05-22 16:08:54 -0600431 }
432
Stephen Warren07cdf362011-12-12 15:55:36 -0700433 ret = tegra_asoc_utils_init(&machine->util_data, &pdev->dev);
434 if (ret)
Stephen Warren518de862012-03-20 14:55:49 -0600435 goto err;
Stephen Warren07cdf362011-12-12 15:55:36 -0700436
Stephen Warren72de2b12011-01-28 14:26:36 -0700437 ret = snd_soc_register_card(card);
Stephen Warrena8bf1ba2011-01-07 22:36:16 -0700438 if (ret) {
Stephen Warren72de2b12011-01-28 14:26:36 -0700439 dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n",
Stephen Warrena8bf1ba2011-01-07 22:36:16 -0700440 ret);
Stephen Warrenacb83032011-04-19 15:25:08 -0600441 goto err_fini_utils;
Stephen Warrena8bf1ba2011-01-07 22:36:16 -0700442 }
443
444 return 0;
445
Stephen Warrenacb83032011-04-19 15:25:08 -0600446err_fini_utils:
Stephen Warrendc0a50af2011-04-12 11:40:36 -0600447 tegra_asoc_utils_fini(&machine->util_data);
Stephen Warrene4e4c182011-11-22 18:21:20 -0700448err:
Stephen Warrena8bf1ba2011-01-07 22:36:16 -0700449 return ret;
450}
Stephen Warrena8bf1ba2011-01-07 22:36:16 -0700451
Stephen Warrendc0a50af2011-04-12 11:40:36 -0600452static int __devexit tegra_wm8903_driver_remove(struct platform_device *pdev)
Stephen Warrena8bf1ba2011-01-07 22:36:16 -0700453{
Stephen Warren72de2b12011-01-28 14:26:36 -0700454 struct snd_soc_card *card = platform_get_drvdata(pdev);
Stephen Warrendc0a50af2011-04-12 11:40:36 -0600455 struct tegra_wm8903 *machine = snd_soc_card_get_drvdata(card);
Stephen Warren72de2b12011-01-28 14:26:36 -0700456
Stephen Warrene44fbbd2012-05-22 16:08:56 -0600457 snd_soc_jack_free_gpios(&tegra_wm8903_hp_jack, 1,
458 &tegra_wm8903_hp_jack_gpio);
Stephen Warren29591ed2011-08-04 16:44:43 -0600459
460 snd_soc_unregister_card(card);
461
462 tegra_asoc_utils_fini(&machine->util_data);
Stephen Warren6e267642011-01-28 14:26:37 -0700463
Stephen Warren72de2b12011-01-28 14:26:36 -0700464 return 0;
Stephen Warrena8bf1ba2011-01-07 22:36:16 -0700465}
Stephen Warren72de2b12011-01-28 14:26:36 -0700466
Stephen Warren07cdf362011-12-12 15:55:36 -0700467static const struct of_device_id tegra_wm8903_of_match[] __devinitconst = {
468 { .compatible = "nvidia,tegra-audio-wm8903", },
469 {},
470};
471
Stephen Warrendc0a50af2011-04-12 11:40:36 -0600472static struct platform_driver tegra_wm8903_driver = {
Stephen Warren72de2b12011-01-28 14:26:36 -0700473 .driver = {
474 .name = DRV_NAME,
475 .owner = THIS_MODULE,
Stephen Warrendeb26072011-04-05 19:35:30 -0600476 .pm = &snd_soc_pm_ops,
Stephen Warren07cdf362011-12-12 15:55:36 -0700477 .of_match_table = tegra_wm8903_of_match,
Stephen Warren72de2b12011-01-28 14:26:36 -0700478 },
Stephen Warrendc0a50af2011-04-12 11:40:36 -0600479 .probe = tegra_wm8903_driver_probe,
480 .remove = __devexit_p(tegra_wm8903_driver_remove),
Stephen Warren72de2b12011-01-28 14:26:36 -0700481};
Stephen Warrene4e4c182011-11-22 18:21:20 -0700482module_platform_driver(tegra_wm8903_driver);
Stephen Warrena8bf1ba2011-01-07 22:36:16 -0700483
484MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>");
Stephen Warrendc0a50af2011-04-12 11:40:36 -0600485MODULE_DESCRIPTION("Tegra+WM8903 machine ASoC driver");
Stephen Warrena8bf1ba2011-01-07 22:36:16 -0700486MODULE_LICENSE("GPL");
Stephen Warren8eb34202011-02-10 15:37:19 -0700487MODULE_ALIAS("platform:" DRV_NAME);
Stephen Warren07cdf362011-12-12 15:55:36 -0700488MODULE_DEVICE_TABLE(of, tegra_wm8903_of_match);