blob: 1fd71e5a9eb96e6aa4c61180747709ceaf5beed8 [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
Stephen Warrena8bf1ba2011-01-07 22:36:16 -070031#include <linux/module.h>
Stephen Warren72de2b12011-01-28 14:26:36 -070032#include <linux/platform_device.h>
33#include <linux/slab.h>
Stephen Warren6e267642011-01-28 14:26:37 -070034#include <linux/gpio.h>
Stephen Warren07cdf362011-12-12 15:55:36 -070035#include <linux/of_gpio.h>
Stephen Warren6e267642011-01-28 14:26:37 -070036
Stephen Warren4651d552011-04-12 11:28:59 -060037#include <mach/tegra_wm8903_pdata.h>
Stephen Warren72de2b12011-01-28 14:26:36 -070038
Stephen Warrena8bf1ba2011-01-07 22:36:16 -070039#include <sound/core.h>
Stephen Warrenf7d3e402011-02-03 13:56:13 -070040#include <sound/jack.h>
Stephen Warrena8bf1ba2011-01-07 22:36:16 -070041#include <sound/pcm.h>
42#include <sound/pcm_params.h>
43#include <sound/soc.h>
44
Stephen Warren41b5f9b2011-02-10 15:37:16 -070045#include "../codecs/wm8903.h"
46
Stephen Warrena8bf1ba2011-01-07 22:36:16 -070047#include "tegra_asoc_utils.h"
48
Stephen Warren7b33af22011-04-12 11:29:00 -060049#define DRV_NAME "tegra-snd-wm8903"
Stephen Warrena8bf1ba2011-01-07 22:36:16 -070050
Stephen Warrendc0a50af2011-04-12 11:40:36 -060051struct tegra_wm8903 {
Stephen Warren07cdf362011-12-12 15:55:36 -070052 struct tegra_wm8903_platform_data pdata;
Stephen Warrend64e57c2011-01-28 14:26:40 -070053 struct tegra_asoc_utils_data util_data;
Stephen Warren72de2b12011-01-28 14:26:36 -070054};
Stephen Warrena8bf1ba2011-01-07 22:36:16 -070055
Stephen Warrendc0a50af2011-04-12 11:40:36 -060056static int tegra_wm8903_hw_params(struct snd_pcm_substream *substream,
Stephen Warrena8bf1ba2011-01-07 22:36:16 -070057 struct snd_pcm_hw_params *params)
58{
59 struct snd_soc_pcm_runtime *rtd = substream->private_data;
60 struct snd_soc_dai *codec_dai = rtd->codec_dai;
61 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
Stephen Warrenc244d472011-01-28 14:26:39 -070062 struct snd_soc_codec *codec = rtd->codec;
63 struct snd_soc_card *card = codec->card;
Stephen Warrendc0a50af2011-04-12 11:40:36 -060064 struct tegra_wm8903 *machine = snd_soc_card_get_drvdata(card);
Stephen Warren07541392011-04-19 15:25:09 -060065 int srate, mclk;
Stephen Warrena8bf1ba2011-01-07 22:36:16 -070066 int err;
67
68 srate = params_rate(params);
69 switch (srate) {
70 case 64000:
71 case 88200:
72 case 96000:
73 mclk = 128 * srate;
74 break;
75 default:
76 mclk = 256 * srate;
77 break;
78 }
79 /* FIXME: Codec only requires >= 3MHz if OSR==0 */
80 while (mclk < 6000000)
81 mclk *= 2;
82
Stephen Warren07541392011-04-19 15:25:09 -060083 err = tegra_asoc_utils_set_rate(&machine->util_data, srate, mclk);
Stephen Warrena8bf1ba2011-01-07 22:36:16 -070084 if (err < 0) {
Stephen Warrenc244d472011-01-28 14:26:39 -070085 dev_err(card->dev, "Can't configure clocks\n");
Stephen Warrena8bf1ba2011-01-07 22:36:16 -070086 return err;
87 }
88
89 err = snd_soc_dai_set_fmt(codec_dai,
90 SND_SOC_DAIFMT_I2S |
91 SND_SOC_DAIFMT_NB_NF |
92 SND_SOC_DAIFMT_CBS_CFS);
93 if (err < 0) {
Stephen Warrenc244d472011-01-28 14:26:39 -070094 dev_err(card->dev, "codec_dai fmt not set\n");
Stephen Warrena8bf1ba2011-01-07 22:36:16 -070095 return err;
96 }
97
98 err = snd_soc_dai_set_fmt(cpu_dai,
99 SND_SOC_DAIFMT_I2S |
100 SND_SOC_DAIFMT_NB_NF |
101 SND_SOC_DAIFMT_CBS_CFS);
102 if (err < 0) {
Stephen Warrenc244d472011-01-28 14:26:39 -0700103 dev_err(card->dev, "cpu_dai fmt not set\n");
Stephen Warrena8bf1ba2011-01-07 22:36:16 -0700104 return err;
105 }
106
Stephen Warren07541392011-04-19 15:25:09 -0600107 err = snd_soc_dai_set_sysclk(codec_dai, 0, mclk,
108 SND_SOC_CLOCK_IN);
109 if (err < 0) {
110 dev_err(card->dev, "codec_dai clock not set\n");
111 return err;
Stephen Warrena8bf1ba2011-01-07 22:36:16 -0700112 }
113
114 return 0;
115}
116
Stephen Warrendc0a50af2011-04-12 11:40:36 -0600117static struct snd_soc_ops tegra_wm8903_ops = {
118 .hw_params = tegra_wm8903_hw_params,
Stephen Warrena8bf1ba2011-01-07 22:36:16 -0700119};
120
Stephen Warrendc0a50af2011-04-12 11:40:36 -0600121static struct snd_soc_jack tegra_wm8903_hp_jack;
Stephen Warrenf7d3e402011-02-03 13:56:13 -0700122
Stephen Warrendc0a50af2011-04-12 11:40:36 -0600123static struct snd_soc_jack_pin tegra_wm8903_hp_jack_pins[] = {
Stephen Warrenf7d3e402011-02-03 13:56:13 -0700124 {
125 .pin = "Headphone Jack",
126 .mask = SND_JACK_HEADPHONE,
127 },
128};
129
Stephen Warren3eb25f92011-04-12 11:40:38 -0600130static struct snd_soc_jack_gpio tegra_wm8903_hp_jack_gpio = {
131 .name = "headphone detect",
132 .report = SND_JACK_HEADPHONE,
133 .debounce_time = 150,
134 .invert = 1,
Stephen Warrenf7d3e402011-02-03 13:56:13 -0700135};
136
Stephen Warrendc0a50af2011-04-12 11:40:36 -0600137static struct snd_soc_jack tegra_wm8903_mic_jack;
Stephen Warren41b5f9b2011-02-10 15:37:16 -0700138
Stephen Warrendc0a50af2011-04-12 11:40:36 -0600139static struct snd_soc_jack_pin tegra_wm8903_mic_jack_pins[] = {
Stephen Warren41b5f9b2011-02-10 15:37:16 -0700140 {
141 .pin = "Mic Jack",
142 .mask = SND_JACK_MICROPHONE,
143 },
144};
145
Stephen Warrendc0a50af2011-04-12 11:40:36 -0600146static int tegra_wm8903_event_int_spk(struct snd_soc_dapm_widget *w,
Stephen Warren6e267642011-01-28 14:26:37 -0700147 struct snd_kcontrol *k, int event)
148{
Stephen Warrena32955d2011-04-19 15:25:10 -0600149 struct snd_soc_dapm_context *dapm = w->dapm;
150 struct snd_soc_card *card = dapm->card;
Stephen Warrendc0a50af2011-04-12 11:40:36 -0600151 struct tegra_wm8903 *machine = snd_soc_card_get_drvdata(card);
Stephen Warren07cdf362011-12-12 15:55:36 -0700152 struct tegra_wm8903_platform_data *pdata = &machine->pdata;
Stephen Warren6e267642011-01-28 14:26:37 -0700153
Stephen Warren14df4152012-05-22 16:08:53 -0600154 if (!gpio_is_valid(pdata->gpio_spkr_en))
Stephen Warren773b1d32011-04-12 11:40:39 -0600155 return 0;
156
Stephen Warren6e267642011-01-28 14:26:37 -0700157 gpio_set_value_cansleep(pdata->gpio_spkr_en,
Stephen Warrenf9eabc32011-01-31 11:00:17 -0700158 SND_SOC_DAPM_EVENT_ON(event));
Stephen Warren6e267642011-01-28 14:26:37 -0700159
160 return 0;
161}
162
Stephen Warren773b1d32011-04-12 11:40:39 -0600163static int tegra_wm8903_event_hp(struct snd_soc_dapm_widget *w,
164 struct snd_kcontrol *k, int event)
165{
Stephen Warrena32955d2011-04-19 15:25:10 -0600166 struct snd_soc_dapm_context *dapm = w->dapm;
167 struct snd_soc_card *card = dapm->card;
Stephen Warren773b1d32011-04-12 11:40:39 -0600168 struct tegra_wm8903 *machine = snd_soc_card_get_drvdata(card);
Stephen Warren07cdf362011-12-12 15:55:36 -0700169 struct tegra_wm8903_platform_data *pdata = &machine->pdata;
Stephen Warren773b1d32011-04-12 11:40:39 -0600170
Stephen Warren14df4152012-05-22 16:08:53 -0600171 if (!gpio_is_valid(pdata->gpio_hp_mute))
Stephen Warren773b1d32011-04-12 11:40:39 -0600172 return 0;
173
174 gpio_set_value_cansleep(pdata->gpio_hp_mute,
175 !SND_SOC_DAPM_EVENT_ON(event));
176
177 return 0;
178}
179
Stephen Warrendc0a50af2011-04-12 11:40:36 -0600180static const struct snd_soc_dapm_widget tegra_wm8903_dapm_widgets[] = {
181 SND_SOC_DAPM_SPK("Int Spk", tegra_wm8903_event_int_spk),
Stephen Warren773b1d32011-04-12 11:40:39 -0600182 SND_SOC_DAPM_HP("Headphone Jack", tegra_wm8903_event_hp),
Stephen Warren62ffac42011-01-13 15:22:08 -0700183 SND_SOC_DAPM_MIC("Mic Jack", NULL),
184};
185
186static const struct snd_soc_dapm_route harmony_audio_map[] = {
187 {"Headphone Jack", NULL, "HPOUTR"},
188 {"Headphone Jack", NULL, "HPOUTL"},
Stephen Warren6e267642011-01-28 14:26:37 -0700189 {"Int Spk", NULL, "ROP"},
190 {"Int Spk", NULL, "RON"},
191 {"Int Spk", NULL, "LOP"},
192 {"Int Spk", NULL, "LON"},
Mark Brown5032dc32011-11-27 12:20:08 +0000193 {"Mic Jack", NULL, "MICBIAS"},
194 {"IN1L", NULL, "Mic Jack"},
Stephen Warren62ffac42011-01-13 15:22:08 -0700195};
196
Stephen Warrendc0a50af2011-04-12 11:40:36 -0600197static const struct snd_kcontrol_new tegra_wm8903_controls[] = {
Stephen Warren3d8bc392011-02-03 13:56:14 -0700198 SOC_DAPM_PIN_SWITCH("Int Spk"),
199};
200
Stephen Warrendc0a50af2011-04-12 11:40:36 -0600201static int tegra_wm8903_init(struct snd_soc_pcm_runtime *rtd)
Stephen Warren62ffac42011-01-13 15:22:08 -0700202{
203 struct snd_soc_codec *codec = rtd->codec;
204 struct snd_soc_dapm_context *dapm = &codec->dapm;
Stephen Warren6e267642011-01-28 14:26:37 -0700205 struct snd_soc_card *card = codec->card;
Stephen Warrendc0a50af2011-04-12 11:40:36 -0600206 struct tegra_wm8903 *machine = snd_soc_card_get_drvdata(card);
Stephen Warren07cdf362011-12-12 15:55:36 -0700207 struct tegra_wm8903_platform_data *pdata = &machine->pdata;
Stephen Warrenbf1b1322011-02-10 15:37:18 -0700208
Stephen Warren773b1d32011-04-12 11:40:39 -0600209 if (gpio_is_valid(pdata->gpio_hp_det)) {
210 tegra_wm8903_hp_jack_gpio.gpio = pdata->gpio_hp_det;
211 snd_soc_jack_new(codec, "Headphone Jack", SND_JACK_HEADPHONE,
212 &tegra_wm8903_hp_jack);
213 snd_soc_jack_add_pins(&tegra_wm8903_hp_jack,
214 ARRAY_SIZE(tegra_wm8903_hp_jack_pins),
215 tegra_wm8903_hp_jack_pins);
216 snd_soc_jack_add_gpios(&tegra_wm8903_hp_jack,
217 1,
218 &tegra_wm8903_hp_jack_gpio);
219 }
Stephen Warrenf7d3e402011-02-03 13:56:13 -0700220
Stephen Warren41b5f9b2011-02-10 15:37:16 -0700221 snd_soc_jack_new(codec, "Mic Jack", SND_JACK_MICROPHONE,
Stephen Warrendc0a50af2011-04-12 11:40:36 -0600222 &tegra_wm8903_mic_jack);
223 snd_soc_jack_add_pins(&tegra_wm8903_mic_jack,
224 ARRAY_SIZE(tegra_wm8903_mic_jack_pins),
225 tegra_wm8903_mic_jack_pins);
226 wm8903_mic_detect(codec, &tegra_wm8903_mic_jack, SND_JACK_MICROPHONE,
227 0);
Stephen Warren41b5f9b2011-02-10 15:37:16 -0700228
Mark Brown5032dc32011-11-27 12:20:08 +0000229 snd_soc_dapm_force_enable_pin(dapm, "MICBIAS");
Stephen Warren41b5f9b2011-02-10 15:37:16 -0700230
Stephen Warren62ffac42011-01-13 15:22:08 -0700231 return 0;
232}
233
Stephen Warrendc0a50af2011-04-12 11:40:36 -0600234static struct snd_soc_dai_link tegra_wm8903_dai = {
Stephen Warrena8bf1ba2011-01-07 22:36:16 -0700235 .name = "WM8903",
236 .stream_name = "WM8903 PCM",
Mark Brown4b592c92011-02-09 13:47:06 +0000237 .codec_name = "wm8903.0-001a",
Stephen Warren896637a2012-04-06 10:30:52 -0600238 .platform_name = "tegra20-i2s.0",
239 .cpu_dai_name = "tegra20-i2s.0",
Stephen Warrena8bf1ba2011-01-07 22:36:16 -0700240 .codec_dai_name = "wm8903-hifi",
Stephen Warrendc0a50af2011-04-12 11:40:36 -0600241 .init = tegra_wm8903_init,
242 .ops = &tegra_wm8903_ops,
Stephen Warrena8bf1ba2011-01-07 22:36:16 -0700243};
244
Stephen Warrendc0a50af2011-04-12 11:40:36 -0600245static struct snd_soc_card snd_soc_tegra_wm8903 = {
246 .name = "tegra-wm8903",
Axel Linb16eaf92011-12-22 21:23:01 +0800247 .owner = THIS_MODULE,
Stephen Warrendc0a50af2011-04-12 11:40:36 -0600248 .dai_link = &tegra_wm8903_dai,
Stephen Warrena8bf1ba2011-01-07 22:36:16 -0700249 .num_links = 1,
Stephen Warrendea8b6e2011-04-19 15:25:12 -0600250
251 .controls = tegra_wm8903_controls,
252 .num_controls = ARRAY_SIZE(tegra_wm8903_controls),
253 .dapm_widgets = tegra_wm8903_dapm_widgets,
254 .num_dapm_widgets = ARRAY_SIZE(tegra_wm8903_dapm_widgets),
Stephen Warren6e5fdba2011-11-23 12:42:05 -0700255 .fully_routed = true,
Stephen Warrena8bf1ba2011-01-07 22:36:16 -0700256};
257
Stephen Warrendc0a50af2011-04-12 11:40:36 -0600258static __devinit int tegra_wm8903_driver_probe(struct platform_device *pdev)
Stephen Warrena8bf1ba2011-01-07 22:36:16 -0700259{
Stephen Warrenf51022f2012-05-22 16:08:54 -0600260 struct device_node *np = pdev->dev.of_node;
Stephen Warrendc0a50af2011-04-12 11:40:36 -0600261 struct snd_soc_card *card = &snd_soc_tegra_wm8903;
262 struct tegra_wm8903 *machine;
Stephen Warrenf51022f2012-05-22 16:08:54 -0600263 struct tegra_wm8903_platform_data *pdata;
Stephen Warrena8bf1ba2011-01-07 22:36:16 -0700264 int ret;
265
Stephen Warren07cdf362011-12-12 15:55:36 -0700266 if (!pdev->dev.platform_data && !pdev->dev.of_node) {
Stephen Warren773b1d32011-04-12 11:40:39 -0600267 dev_err(&pdev->dev, "No platform data supplied\n");
Stephen Warren6e267642011-01-28 14:26:37 -0700268 return -EINVAL;
269 }
270
Stephen Warrene4e4c182011-11-22 18:21:20 -0700271 machine = devm_kzalloc(&pdev->dev, sizeof(struct tegra_wm8903),
272 GFP_KERNEL);
Stephen Warrendc0a50af2011-04-12 11:40:36 -0600273 if (!machine) {
274 dev_err(&pdev->dev, "Can't allocate tegra_wm8903 struct\n");
Stephen Warrene4e4c182011-11-22 18:21:20 -0700275 ret = -ENOMEM;
276 goto err;
Stephen Warren72de2b12011-01-28 14:26:36 -0700277 }
Stephen Warrenf51022f2012-05-22 16:08:54 -0600278 pdata = &machine->pdata;
Stephen Warren72de2b12011-01-28 14:26:36 -0700279
280 card->dev = &pdev->dev;
281 platform_set_drvdata(pdev, card);
Stephen Warrendc0a50af2011-04-12 11:40:36 -0600282 snd_soc_card_set_drvdata(card, machine);
Stephen Warren72de2b12011-01-28 14:26:36 -0700283
Stephen Warrenf51022f2012-05-22 16:08:54 -0600284 if (pdev->dev.platform_data) {
285 memcpy(pdata, card->dev->platform_data, sizeof(*pdata));
286 } else if (np) {
287 pdata->gpio_spkr_en = of_get_named_gpio(np,
288 "nvidia,spkr-en-gpios", 0);
289 if (pdata->gpio_spkr_en == -ENODEV)
290 return -EPROBE_DEFER;
291
292 pdata->gpio_hp_mute = of_get_named_gpio(np,
293 "nvidia,hp-mute-gpios", 0);
294 if (pdata->gpio_hp_mute == -ENODEV)
295 return -EPROBE_DEFER;
296
297 pdata->gpio_hp_det = of_get_named_gpio(np,
298 "nvidia,hp-det-gpios", 0);
299 if (pdata->gpio_hp_det == -ENODEV)
300 return -EPROBE_DEFER;
301
302 pdata->gpio_int_mic_en = of_get_named_gpio(np,
303 "nvidia,int-mic-en-gpios", 0);
304 if (pdata->gpio_int_mic_en == -ENODEV)
305 return -EPROBE_DEFER;
306
307 pdata->gpio_ext_mic_en = of_get_named_gpio(np,
308 "nvidia,ext-mic-en-gpios", 0);
309 if (pdata->gpio_ext_mic_en == -ENODEV)
310 return -EPROBE_DEFER;
311 }
312
313 if (np) {
Stephen Warren07cdf362011-12-12 15:55:36 -0700314 ret = snd_soc_of_parse_card_name(card, "nvidia,model");
315 if (ret)
316 goto err;
317
318 ret = snd_soc_of_parse_audio_routing(card,
319 "nvidia,audio-routing");
320 if (ret)
321 goto err;
322
323 tegra_wm8903_dai.codec_name = NULL;
Stephen Warrenf51022f2012-05-22 16:08:54 -0600324 tegra_wm8903_dai.codec_of_node = of_parse_phandle(np,
325 "nvidia,audio-codec", 0);
Stephen Warren07cdf362011-12-12 15:55:36 -0700326 if (!tegra_wm8903_dai.codec_of_node) {
327 dev_err(&pdev->dev,
328 "Property 'nvidia,audio-codec' missing or invalid\n");
329 ret = -EINVAL;
330 goto err;
331 }
332
333 tegra_wm8903_dai.cpu_dai_name = NULL;
Stephen Warrenbc926572012-05-25 18:22:11 -0600334 tegra_wm8903_dai.cpu_of_node = of_parse_phandle(np,
Stephen Warrenf51022f2012-05-22 16:08:54 -0600335 "nvidia,i2s-controller", 0);
Stephen Warrenbc926572012-05-25 18:22:11 -0600336 if (!tegra_wm8903_dai.cpu_of_node) {
Stephen Warren07cdf362011-12-12 15:55:36 -0700337 dev_err(&pdev->dev,
338 "Property 'nvidia,i2s-controller' missing or invalid\n");
339 ret = -EINVAL;
340 goto err;
341 }
342
Stephen Warren518de862012-03-20 14:55:49 -0600343 tegra_wm8903_dai.platform_name = NULL;
344 tegra_wm8903_dai.platform_of_node =
Stephen Warrenbc926572012-05-25 18:22:11 -0600345 tegra_wm8903_dai.cpu_of_node;
Stephen Warrendea8b6e2011-04-19 15:25:12 -0600346 } else {
Stephen Warrenb350ecb2012-05-22 16:11:19 -0600347 card->dapm_routes = harmony_audio_map;
348 card->num_dapm_routes = ARRAY_SIZE(harmony_audio_map);
Stephen Warrendea8b6e2011-04-19 15:25:12 -0600349 }
350
Stephen Warrenf51022f2012-05-22 16:08:54 -0600351 if (gpio_is_valid(pdata->gpio_spkr_en)) {
Stephen Warrene2d287c2012-05-22 16:08:55 -0600352 ret = devm_gpio_request_one(&pdev->dev, pdata->gpio_spkr_en,
353 GPIOF_OUT_INIT_LOW, "spkr_en");
Stephen Warrenf51022f2012-05-22 16:08:54 -0600354 if (ret) {
355 dev_err(card->dev, "cannot get spkr_en gpio\n");
356 return ret;
357 }
Stephen Warrenf51022f2012-05-22 16:08:54 -0600358 }
359
360 if (gpio_is_valid(pdata->gpio_hp_mute)) {
Stephen Warrene2d287c2012-05-22 16:08:55 -0600361 ret = devm_gpio_request_one(&pdev->dev, pdata->gpio_hp_mute,
362 GPIOF_OUT_INIT_HIGH, "hp_mute");
Stephen Warrenf51022f2012-05-22 16:08:54 -0600363 if (ret) {
364 dev_err(card->dev, "cannot get hp_mute gpio\n");
365 return ret;
366 }
Stephen Warrenf51022f2012-05-22 16:08:54 -0600367 }
368
369 if (gpio_is_valid(pdata->gpio_int_mic_en)) {
Stephen Warrene2d287c2012-05-22 16:08:55 -0600370 /* Disable int mic; enable signal is active-high */
371 ret = devm_gpio_request_one(&pdev->dev, pdata->gpio_int_mic_en,
372 GPIOF_OUT_INIT_LOW, "int_mic_en");
Stephen Warrenf51022f2012-05-22 16:08:54 -0600373 if (ret) {
374 dev_err(card->dev, "cannot get int_mic_en gpio\n");
375 return ret;
376 }
Stephen Warrenf51022f2012-05-22 16:08:54 -0600377 }
378
379 if (gpio_is_valid(pdata->gpio_ext_mic_en)) {
Stephen Warrene2d287c2012-05-22 16:08:55 -0600380 /* Enable ext mic; enable signal is active-low */
381 ret = devm_gpio_request_one(&pdev->dev, pdata->gpio_ext_mic_en,
382 GPIOF_OUT_INIT_LOW, "ext_mic_en");
Stephen Warrenf51022f2012-05-22 16:08:54 -0600383 if (ret) {
384 dev_err(card->dev, "cannot get ext_mic_en gpio\n");
385 return ret;
386 }
Stephen Warrenf51022f2012-05-22 16:08:54 -0600387 }
388
Stephen Warren07cdf362011-12-12 15:55:36 -0700389 ret = tegra_asoc_utils_init(&machine->util_data, &pdev->dev);
390 if (ret)
Stephen Warren518de862012-03-20 14:55:49 -0600391 goto err;
Stephen Warren07cdf362011-12-12 15:55:36 -0700392
Stephen Warren72de2b12011-01-28 14:26:36 -0700393 ret = snd_soc_register_card(card);
Stephen Warrena8bf1ba2011-01-07 22:36:16 -0700394 if (ret) {
Stephen Warren72de2b12011-01-28 14:26:36 -0700395 dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n",
Stephen Warrena8bf1ba2011-01-07 22:36:16 -0700396 ret);
Stephen Warrenacb83032011-04-19 15:25:08 -0600397 goto err_fini_utils;
Stephen Warrena8bf1ba2011-01-07 22:36:16 -0700398 }
399
400 return 0;
401
Stephen Warrenacb83032011-04-19 15:25:08 -0600402err_fini_utils:
Stephen Warrendc0a50af2011-04-12 11:40:36 -0600403 tegra_asoc_utils_fini(&machine->util_data);
Stephen Warrene4e4c182011-11-22 18:21:20 -0700404err:
Stephen Warrena8bf1ba2011-01-07 22:36:16 -0700405 return ret;
406}
Stephen Warrena8bf1ba2011-01-07 22:36:16 -0700407
Stephen Warrendc0a50af2011-04-12 11:40:36 -0600408static int __devexit tegra_wm8903_driver_remove(struct platform_device *pdev)
Stephen Warrena8bf1ba2011-01-07 22:36:16 -0700409{
Stephen Warren72de2b12011-01-28 14:26:36 -0700410 struct snd_soc_card *card = platform_get_drvdata(pdev);
Stephen Warrendc0a50af2011-04-12 11:40:36 -0600411 struct tegra_wm8903 *machine = snd_soc_card_get_drvdata(card);
Stephen Warren72de2b12011-01-28 14:26:36 -0700412
Stephen Warrene44fbbd2012-05-22 16:08:56 -0600413 snd_soc_jack_free_gpios(&tegra_wm8903_hp_jack, 1,
414 &tegra_wm8903_hp_jack_gpio);
Stephen Warren29591ed2011-08-04 16:44:43 -0600415
416 snd_soc_unregister_card(card);
417
418 tegra_asoc_utils_fini(&machine->util_data);
Stephen Warren6e267642011-01-28 14:26:37 -0700419
Stephen Warren72de2b12011-01-28 14:26:36 -0700420 return 0;
Stephen Warrena8bf1ba2011-01-07 22:36:16 -0700421}
Stephen Warren72de2b12011-01-28 14:26:36 -0700422
Stephen Warren07cdf362011-12-12 15:55:36 -0700423static const struct of_device_id tegra_wm8903_of_match[] __devinitconst = {
424 { .compatible = "nvidia,tegra-audio-wm8903", },
425 {},
426};
427
Stephen Warrendc0a50af2011-04-12 11:40:36 -0600428static struct platform_driver tegra_wm8903_driver = {
Stephen Warren72de2b12011-01-28 14:26:36 -0700429 .driver = {
430 .name = DRV_NAME,
431 .owner = THIS_MODULE,
Stephen Warrendeb26072011-04-05 19:35:30 -0600432 .pm = &snd_soc_pm_ops,
Stephen Warren07cdf362011-12-12 15:55:36 -0700433 .of_match_table = tegra_wm8903_of_match,
Stephen Warren72de2b12011-01-28 14:26:36 -0700434 },
Stephen Warrendc0a50af2011-04-12 11:40:36 -0600435 .probe = tegra_wm8903_driver_probe,
436 .remove = __devexit_p(tegra_wm8903_driver_remove),
Stephen Warren72de2b12011-01-28 14:26:36 -0700437};
Stephen Warrene4e4c182011-11-22 18:21:20 -0700438module_platform_driver(tegra_wm8903_driver);
Stephen Warrena8bf1ba2011-01-07 22:36:16 -0700439
440MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>");
Stephen Warrendc0a50af2011-04-12 11:40:36 -0600441MODULE_DESCRIPTION("Tegra+WM8903 machine ASoC driver");
Stephen Warrena8bf1ba2011-01-07 22:36:16 -0700442MODULE_LICENSE("GPL");
Stephen Warren8eb34202011-02-10 15:37:19 -0700443MODULE_ALIAS("platform:" DRV_NAME);
Stephen Warren07cdf362011-12-12 15:55:36 -0700444MODULE_DEVICE_TABLE(of, tegra_wm8903_of_match);