blob: f1acdc57cfd80ac2dc9d537b434426158f005bfc [file] [log] [blame]
Philipp Zabel73772262009-03-19 09:34:46 +01001/*
2 * SoC audio for HTC Magician
3 *
4 * Copyright (c) 2006 Philipp Zabel <philipp.zabel@gmail.com>
5 *
6 * based on spitz.c,
7 * Authors: Liam Girdwood <lrg@slimlogic.co.uk>
8 * Richard Purdie <richard@openedhand.com>
9 *
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation; either version 2 of the License, or (at your
13 * option) any later version.
14 *
15 */
16
17#include <linux/module.h>
18#include <linux/timer.h>
19#include <linux/interrupt.h>
20#include <linux/platform_device.h>
21#include <linux/delay.h>
22#include <linux/gpio.h>
Philipp Zabel1abd9182009-06-15 22:18:23 +020023#include <linux/i2c.h>
Philipp Zabel73772262009-03-19 09:34:46 +010024
25#include <sound/core.h>
26#include <sound/pcm.h>
27#include <sound/pcm_params.h>
28#include <sound/soc.h>
29#include <sound/soc-dapm.h>
Philipp Zabel1abd9182009-06-15 22:18:23 +020030#include <sound/uda1380.h>
Philipp Zabel73772262009-03-19 09:34:46 +010031
Philipp Zabel73772262009-03-19 09:34:46 +010032#include <mach/magician.h>
33#include <asm/mach-types.h>
34#include "../codecs/uda1380.h"
Philipp Zabel73772262009-03-19 09:34:46 +010035#include "pxa2xx-i2s.h"
36#include "pxa-ssp.h"
37
38#define MAGICIAN_MIC 0
39#define MAGICIAN_MIC_EXT 1
40
41static int magician_hp_switch;
42static int magician_spk_switch = 1;
43static int magician_in_sel = MAGICIAN_MIC;
44
45static void magician_ext_control(struct snd_soc_codec *codec)
46{
Liam Girdwoodce6120c2010-11-05 15:53:46 +020047 struct snd_soc_dapm_context *dapm = &codec->dapm;
48
Philipp Zabel73772262009-03-19 09:34:46 +010049 if (magician_spk_switch)
Liam Girdwoodce6120c2010-11-05 15:53:46 +020050 snd_soc_dapm_enable_pin(dapm, "Speaker");
Philipp Zabel73772262009-03-19 09:34:46 +010051 else
Liam Girdwoodce6120c2010-11-05 15:53:46 +020052 snd_soc_dapm_disable_pin(dapm, "Speaker");
Philipp Zabel73772262009-03-19 09:34:46 +010053 if (magician_hp_switch)
Liam Girdwoodce6120c2010-11-05 15:53:46 +020054 snd_soc_dapm_enable_pin(dapm, "Headphone Jack");
Philipp Zabel73772262009-03-19 09:34:46 +010055 else
Liam Girdwoodce6120c2010-11-05 15:53:46 +020056 snd_soc_dapm_disable_pin(dapm, "Headphone Jack");
Philipp Zabel73772262009-03-19 09:34:46 +010057
58 switch (magician_in_sel) {
59 case MAGICIAN_MIC:
Liam Girdwoodce6120c2010-11-05 15:53:46 +020060 snd_soc_dapm_disable_pin(dapm, "Headset Mic");
61 snd_soc_dapm_enable_pin(dapm, "Call Mic");
Philipp Zabel73772262009-03-19 09:34:46 +010062 break;
63 case MAGICIAN_MIC_EXT:
Liam Girdwoodce6120c2010-11-05 15:53:46 +020064 snd_soc_dapm_disable_pin(dapm, "Call Mic");
65 snd_soc_dapm_enable_pin(dapm, "Headset Mic");
Philipp Zabel73772262009-03-19 09:34:46 +010066 break;
67 }
68
Liam Girdwoodce6120c2010-11-05 15:53:46 +020069 snd_soc_dapm_sync(dapm);
Philipp Zabel73772262009-03-19 09:34:46 +010070}
71
72static int magician_startup(struct snd_pcm_substream *substream)
73{
74 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000075 struct snd_soc_codec *codec = rtd->codec;
Philipp Zabel73772262009-03-19 09:34:46 +010076
77 /* check the jack status at stream startup */
78 magician_ext_control(codec);
79
80 return 0;
81}
82
83/*
84 * Magician uses SSP port for playback.
85 */
86static int magician_playback_hw_params(struct snd_pcm_substream *substream,
87 struct snd_pcm_hw_params *params)
88{
89 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000090 struct snd_soc_dai *codec_dai = rtd->codec_dai;
91 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
Philipp Zabel73772262009-03-19 09:34:46 +010092 unsigned int acps, acds, width, rate;
93 unsigned int div4 = PXA_SSP_CLK_SCDB_4;
94 int ret = 0;
95
96 rate = params_rate(params);
97 width = snd_pcm_format_physical_width(params_format(params));
98
99 /*
100 * rate = SSPSCLK / (2 * width(16 or 32))
101 * SSPSCLK = (ACPS / ACDS) / SSPSCLKDIV(div4 or div1)
102 */
103 switch (params_rate(params)) {
104 case 8000:
105 /* off by a factor of 2: bug in the PXA27x audio clock? */
106 acps = 32842000;
107 switch (width) {
108 case 16:
109 /* 513156 Hz ~= _2_ * 8000 Hz * 32 (+0.23%) */
110 acds = PXA_SSP_CLK_AUDIO_DIV_16;
111 break;
Takashi Iwai2bf27782009-05-15 12:20:52 +0200112 default: /* 32 */
Philipp Zabel73772262009-03-19 09:34:46 +0100113 /* 1026312 Hz ~= _2_ * 8000 Hz * 64 (+0.23%) */
114 acds = PXA_SSP_CLK_AUDIO_DIV_8;
115 }
116 break;
117 case 11025:
118 acps = 5622000;
119 switch (width) {
120 case 16:
121 /* 351375 Hz ~= 11025 Hz * 32 (-0.41%) */
122 acds = PXA_SSP_CLK_AUDIO_DIV_4;
123 break;
Takashi Iwai2bf27782009-05-15 12:20:52 +0200124 default: /* 32 */
Philipp Zabel73772262009-03-19 09:34:46 +0100125 /* 702750 Hz ~= 11025 Hz * 64 (-0.41%) */
126 acds = PXA_SSP_CLK_AUDIO_DIV_2;
127 }
128 break;
129 case 22050:
130 acps = 5622000;
131 switch (width) {
132 case 16:
133 /* 702750 Hz ~= 22050 Hz * 32 (-0.41%) */
134 acds = PXA_SSP_CLK_AUDIO_DIV_2;
135 break;
Takashi Iwai2bf27782009-05-15 12:20:52 +0200136 default: /* 32 */
Philipp Zabel73772262009-03-19 09:34:46 +0100137 /* 1405500 Hz ~= 22050 Hz * 64 (-0.41%) */
138 acds = PXA_SSP_CLK_AUDIO_DIV_1;
139 }
140 break;
141 case 44100:
142 acps = 5622000;
143 switch (width) {
144 case 16:
145 /* 1405500 Hz ~= 44100 Hz * 32 (-0.41%) */
146 acds = PXA_SSP_CLK_AUDIO_DIV_2;
147 break;
Takashi Iwai2bf27782009-05-15 12:20:52 +0200148 default: /* 32 */
Philipp Zabel73772262009-03-19 09:34:46 +0100149 /* 2811000 Hz ~= 44100 Hz * 64 (-0.41%) */
150 acds = PXA_SSP_CLK_AUDIO_DIV_1;
151 }
152 break;
153 case 48000:
154 acps = 12235000;
155 switch (width) {
156 case 16:
157 /* 1529375 Hz ~= 48000 Hz * 32 (-0.44%) */
158 acds = PXA_SSP_CLK_AUDIO_DIV_2;
159 break;
Takashi Iwai2bf27782009-05-15 12:20:52 +0200160 default: /* 32 */
Philipp Zabel73772262009-03-19 09:34:46 +0100161 /* 3058750 Hz ~= 48000 Hz * 64 (-0.44%) */
162 acds = PXA_SSP_CLK_AUDIO_DIV_1;
163 }
164 break;
165 case 96000:
Takashi Iwai2bf27782009-05-15 12:20:52 +0200166 default:
Philipp Zabel73772262009-03-19 09:34:46 +0100167 acps = 12235000;
168 switch (width) {
169 case 16:
170 /* 3058750 Hz ~= 96000 Hz * 32 (-0.44%) */
171 acds = PXA_SSP_CLK_AUDIO_DIV_1;
172 break;
Takashi Iwai2bf27782009-05-15 12:20:52 +0200173 default: /* 32 */
Philipp Zabel73772262009-03-19 09:34:46 +0100174 /* 6117500 Hz ~= 96000 Hz * 64 (-0.44%) */
175 acds = PXA_SSP_CLK_AUDIO_DIV_2;
176 div4 = PXA_SSP_CLK_SCDB_1;
177 break;
178 }
179 break;
180 }
181
182 /* set codec DAI configuration */
183 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_MSB |
184 SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
185 if (ret < 0)
186 return ret;
187
188 /* set cpu DAI configuration */
189 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_DSP_A |
Philipp Zabel33745fb2009-06-14 12:51:30 +0200190 SND_SOC_DAIFMT_NB_IF | SND_SOC_DAIFMT_CBS_CFS);
Philipp Zabel73772262009-03-19 09:34:46 +0100191 if (ret < 0)
192 return ret;
193
Daniel Ribeiroa5479e32009-06-15 21:44:31 -0300194 ret = snd_soc_dai_set_tdm_slot(cpu_dai, 1, 0, 1, width);
Philipp Zabel73772262009-03-19 09:34:46 +0100195 if (ret < 0)
196 return ret;
197
198 /* set audio clock as clock source */
199 ret = snd_soc_dai_set_sysclk(cpu_dai, PXA_SSP_CLK_AUDIO, 0,
200 SND_SOC_CLOCK_OUT);
201 if (ret < 0)
202 return ret;
203
204 /* set the SSP audio system clock ACDS divider */
205 ret = snd_soc_dai_set_clkdiv(cpu_dai,
206 PXA_SSP_AUDIO_DIV_ACDS, acds);
207 if (ret < 0)
208 return ret;
209
210 /* set the SSP audio system clock SCDB divider4 */
211 ret = snd_soc_dai_set_clkdiv(cpu_dai,
212 PXA_SSP_AUDIO_DIV_SCDB, div4);
213 if (ret < 0)
214 return ret;
215
216 /* set SSP audio pll clock */
Mark Brown85488032009-09-05 18:52:16 +0100217 ret = snd_soc_dai_set_pll(cpu_dai, 0, 0, 0, acps);
Philipp Zabel73772262009-03-19 09:34:46 +0100218 if (ret < 0)
219 return ret;
220
221 return 0;
222}
223
224/*
225 * Magician uses I2S for capture.
226 */
227static int magician_capture_hw_params(struct snd_pcm_substream *substream,
228 struct snd_pcm_hw_params *params)
229{
230 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000231 struct snd_soc_dai *codec_dai = rtd->codec_dai;
232 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
Philipp Zabel73772262009-03-19 09:34:46 +0100233 int ret = 0;
234
235 /* set codec DAI configuration */
236 ret = snd_soc_dai_set_fmt(codec_dai,
237 SND_SOC_DAIFMT_MSB | SND_SOC_DAIFMT_NB_NF |
238 SND_SOC_DAIFMT_CBS_CFS);
239 if (ret < 0)
240 return ret;
241
242 /* set cpu DAI configuration */
243 ret = snd_soc_dai_set_fmt(cpu_dai,
244 SND_SOC_DAIFMT_MSB | SND_SOC_DAIFMT_NB_NF |
245 SND_SOC_DAIFMT_CBS_CFS);
246 if (ret < 0)
247 return ret;
248
249 /* set the I2S system clock as output */
250 ret = snd_soc_dai_set_sysclk(cpu_dai, PXA2XX_I2S_SYSCLK, 0,
251 SND_SOC_CLOCK_OUT);
252 if (ret < 0)
253 return ret;
254
255 return 0;
256}
257
258static struct snd_soc_ops magician_capture_ops = {
259 .startup = magician_startup,
260 .hw_params = magician_capture_hw_params,
261};
262
263static struct snd_soc_ops magician_playback_ops = {
264 .startup = magician_startup,
265 .hw_params = magician_playback_hw_params,
266};
267
268static int magician_get_hp(struct snd_kcontrol *kcontrol,
269 struct snd_ctl_elem_value *ucontrol)
270{
271 ucontrol->value.integer.value[0] = magician_hp_switch;
272 return 0;
273}
274
275static int magician_set_hp(struct snd_kcontrol *kcontrol,
276 struct snd_ctl_elem_value *ucontrol)
277{
278 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
279
280 if (magician_hp_switch == ucontrol->value.integer.value[0])
281 return 0;
282
283 magician_hp_switch = ucontrol->value.integer.value[0];
284 magician_ext_control(codec);
285 return 1;
286}
287
288static int magician_get_spk(struct snd_kcontrol *kcontrol,
289 struct snd_ctl_elem_value *ucontrol)
290{
291 ucontrol->value.integer.value[0] = magician_spk_switch;
292 return 0;
293}
294
295static int magician_set_spk(struct snd_kcontrol *kcontrol,
296 struct snd_ctl_elem_value *ucontrol)
297{
298 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
299
300 if (magician_spk_switch == ucontrol->value.integer.value[0])
301 return 0;
302
303 magician_spk_switch = ucontrol->value.integer.value[0];
304 magician_ext_control(codec);
305 return 1;
306}
307
308static int magician_get_input(struct snd_kcontrol *kcontrol,
309 struct snd_ctl_elem_value *ucontrol)
310{
311 ucontrol->value.integer.value[0] = magician_in_sel;
312 return 0;
313}
314
315static int magician_set_input(struct snd_kcontrol *kcontrol,
316 struct snd_ctl_elem_value *ucontrol)
317{
318 if (magician_in_sel == ucontrol->value.integer.value[0])
319 return 0;
320
321 magician_in_sel = ucontrol->value.integer.value[0];
322
323 switch (magician_in_sel) {
324 case MAGICIAN_MIC:
325 gpio_set_value(EGPIO_MAGICIAN_IN_SEL1, 1);
326 break;
327 case MAGICIAN_MIC_EXT:
328 gpio_set_value(EGPIO_MAGICIAN_IN_SEL1, 0);
329 }
330
331 return 1;
332}
333
334static int magician_spk_power(struct snd_soc_dapm_widget *w,
335 struct snd_kcontrol *k, int event)
336{
337 gpio_set_value(EGPIO_MAGICIAN_SPK_POWER, SND_SOC_DAPM_EVENT_ON(event));
338 return 0;
339}
340
341static int magician_hp_power(struct snd_soc_dapm_widget *w,
342 struct snd_kcontrol *k, int event)
343{
344 gpio_set_value(EGPIO_MAGICIAN_EP_POWER, SND_SOC_DAPM_EVENT_ON(event));
345 return 0;
346}
347
348static int magician_mic_bias(struct snd_soc_dapm_widget *w,
349 struct snd_kcontrol *k, int event)
350{
351 gpio_set_value(EGPIO_MAGICIAN_MIC_POWER, SND_SOC_DAPM_EVENT_ON(event));
352 return 0;
353}
354
355/* magician machine dapm widgets */
356static const struct snd_soc_dapm_widget uda1380_dapm_widgets[] = {
357 SND_SOC_DAPM_HP("Headphone Jack", magician_hp_power),
358 SND_SOC_DAPM_SPK("Speaker", magician_spk_power),
359 SND_SOC_DAPM_MIC("Call Mic", magician_mic_bias),
360 SND_SOC_DAPM_MIC("Headset Mic", magician_mic_bias),
361};
362
363/* magician machine audio_map */
364static const struct snd_soc_dapm_route audio_map[] = {
365
366 /* Headphone connected to VOUTL, VOUTR */
367 {"Headphone Jack", NULL, "VOUTL"},
368 {"Headphone Jack", NULL, "VOUTR"},
369
370 /* Speaker connected to VOUTL, VOUTR */
371 {"Speaker", NULL, "VOUTL"},
372 {"Speaker", NULL, "VOUTR"},
373
374 /* Mics are connected to VINM */
375 {"VINM", NULL, "Headset Mic"},
376 {"VINM", NULL, "Call Mic"},
377};
378
379static const char *input_select[] = {"Call Mic", "Headset Mic"};
380static const struct soc_enum magician_in_sel_enum =
381 SOC_ENUM_SINGLE_EXT(2, input_select);
382
383static const struct snd_kcontrol_new uda1380_magician_controls[] = {
384 SOC_SINGLE_BOOL_EXT("Headphone Switch",
385 (unsigned long)&magician_hp_switch,
386 magician_get_hp, magician_set_hp),
387 SOC_SINGLE_BOOL_EXT("Speaker Switch",
388 (unsigned long)&magician_spk_switch,
389 magician_get_spk, magician_set_spk),
390 SOC_ENUM_EXT("Input Select", magician_in_sel_enum,
391 magician_get_input, magician_set_input),
392};
393
394/*
395 * Logic for a uda1380 as connected on a HTC Magician
396 */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000397static int magician_uda1380_init(struct snd_soc_pcm_runtime *rtd)
Philipp Zabel73772262009-03-19 09:34:46 +0100398{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000399 struct snd_soc_codec *codec = rtd->codec;
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200400 struct snd_soc_dapm_context *dapm = &codec->dapm;
Philipp Zabel73772262009-03-19 09:34:46 +0100401 int err;
402
403 /* NC codec pins */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200404 snd_soc_dapm_nc_pin(dapm, "VOUTLHP");
405 snd_soc_dapm_nc_pin(dapm, "VOUTRHP");
Philipp Zabel73772262009-03-19 09:34:46 +0100406
407 /* FIXME: is anything connected here? */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200408 snd_soc_dapm_nc_pin(dapm, "VINL");
409 snd_soc_dapm_nc_pin(dapm, "VINR");
Philipp Zabel73772262009-03-19 09:34:46 +0100410
411 /* Add magician specific controls */
412 err = snd_soc_add_controls(codec, uda1380_magician_controls,
413 ARRAY_SIZE(uda1380_magician_controls));
414 if (err < 0)
415 return err;
416
417 /* Add magician specific widgets */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200418 snd_soc_dapm_new_controls(dapm, uda1380_dapm_widgets,
Philipp Zabel73772262009-03-19 09:34:46 +0100419 ARRAY_SIZE(uda1380_dapm_widgets));
420
421 /* Set up magician specific audio path interconnects */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200422 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
Philipp Zabel73772262009-03-19 09:34:46 +0100423
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200424 snd_soc_dapm_sync(dapm);
Philipp Zabel73772262009-03-19 09:34:46 +0100425 return 0;
426}
427
428/* magician digital audio interface glue - connects codec <--> CPU */
429static struct snd_soc_dai_link magician_dai[] = {
430{
431 .name = "uda1380",
432 .stream_name = "UDA1380 Playback",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000433 .cpu_dai_name = "pxa-ssp-dai.0",
434 .codec_dai_name = "uda1380-hifi-playback",
435 .platform_name = "pxa-pcm-audio",
436 .codec_name = "uda1380-codec.0-0018",
Philipp Zabel73772262009-03-19 09:34:46 +0100437 .init = magician_uda1380_init,
438 .ops = &magician_playback_ops,
439},
440{
441 .name = "uda1380",
442 .stream_name = "UDA1380 Capture",
Ian Larteya2a00862010-08-20 17:18:43 +0100443 .cpu_dai_name = "pxa2xx-i2s",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000444 .codec_dai_name = "uda1380-hifi-capture",
445 .platform_name = "pxa-pcm-audio",
446 .codec_name = "uda1380-codec.0-0018",
Philipp Zabel73772262009-03-19 09:34:46 +0100447 .ops = &magician_capture_ops,
448}
449};
450
451/* magician audio machine driver */
452static struct snd_soc_card snd_soc_card_magician = {
453 .name = "Magician",
454 .dai_link = magician_dai,
455 .num_links = ARRAY_SIZE(magician_dai),
Philipp Zabel73772262009-03-19 09:34:46 +0100456
Philipp Zabel73772262009-03-19 09:34:46 +0100457};
458
459static struct platform_device *magician_snd_device;
460
Philipp Zabel1abd9182009-06-15 22:18:23 +0200461/*
462 * FIXME: move into magician board file once merged into the pxa tree
463 */
464static struct uda1380_platform_data uda1380_info = {
465 .gpio_power = EGPIO_MAGICIAN_CODEC_POWER,
466 .gpio_reset = EGPIO_MAGICIAN_CODEC_RESET,
467 .dac_clk = UDA1380_DAC_CLK_WSPLL,
468};
469
470static struct i2c_board_info i2c_board_info[] = {
471 {
472 I2C_BOARD_INFO("uda1380", 0x18),
473 .platform_data = &uda1380_info,
474 },
475};
476
Philipp Zabel73772262009-03-19 09:34:46 +0100477static int __init magician_init(void)
478{
479 int ret;
Philipp Zabel1abd9182009-06-15 22:18:23 +0200480 struct i2c_adapter *adapter;
481 struct i2c_client *client;
Philipp Zabel73772262009-03-19 09:34:46 +0100482
483 if (!machine_is_magician())
484 return -ENODEV;
485
Philipp Zabel1abd9182009-06-15 22:18:23 +0200486 adapter = i2c_get_adapter(0);
487 if (!adapter)
488 return -ENODEV;
489 client = i2c_new_device(adapter, i2c_board_info);
490 i2c_put_adapter(adapter);
491 if (!client)
492 return -ENODEV;
493
Philipp Zabel73772262009-03-19 09:34:46 +0100494 ret = gpio_request(EGPIO_MAGICIAN_SPK_POWER, "SPK_POWER");
495 if (ret)
496 goto err_request_spk;
497 ret = gpio_request(EGPIO_MAGICIAN_EP_POWER, "EP_POWER");
498 if (ret)
499 goto err_request_ep;
500 ret = gpio_request(EGPIO_MAGICIAN_MIC_POWER, "MIC_POWER");
501 if (ret)
502 goto err_request_mic;
503 ret = gpio_request(EGPIO_MAGICIAN_IN_SEL0, "IN_SEL0");
504 if (ret)
505 goto err_request_in_sel0;
506 ret = gpio_request(EGPIO_MAGICIAN_IN_SEL1, "IN_SEL1");
507 if (ret)
508 goto err_request_in_sel1;
509
Philipp Zabel73772262009-03-19 09:34:46 +0100510 gpio_set_value(EGPIO_MAGICIAN_IN_SEL0, 0);
511
Philipp Zabel73772262009-03-19 09:34:46 +0100512 magician_snd_device = platform_device_alloc("soc-audio", -1);
513 if (!magician_snd_device) {
514 ret = -ENOMEM;
515 goto err_pdev;
516 }
517
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000518 platform_set_drvdata(magician_snd_device, &snd_soc_card_magician);
Philipp Zabel73772262009-03-19 09:34:46 +0100519 ret = platform_device_add(magician_snd_device);
520 if (ret) {
521 platform_device_put(magician_snd_device);
522 goto err_pdev;
523 }
524
525 return 0;
526
527err_pdev:
528 gpio_free(EGPIO_MAGICIAN_IN_SEL1);
529err_request_in_sel1:
530 gpio_free(EGPIO_MAGICIAN_IN_SEL0);
531err_request_in_sel0:
532 gpio_free(EGPIO_MAGICIAN_MIC_POWER);
533err_request_mic:
534 gpio_free(EGPIO_MAGICIAN_EP_POWER);
535err_request_ep:
536 gpio_free(EGPIO_MAGICIAN_SPK_POWER);
537err_request_spk:
Philipp Zabel73772262009-03-19 09:34:46 +0100538 return ret;
539}
540
541static void __exit magician_exit(void)
542{
543 platform_device_unregister(magician_snd_device);
544
545 gpio_set_value(EGPIO_MAGICIAN_SPK_POWER, 0);
546 gpio_set_value(EGPIO_MAGICIAN_EP_POWER, 0);
547 gpio_set_value(EGPIO_MAGICIAN_MIC_POWER, 0);
Philipp Zabel73772262009-03-19 09:34:46 +0100548
549 gpio_free(EGPIO_MAGICIAN_IN_SEL1);
550 gpio_free(EGPIO_MAGICIAN_IN_SEL0);
551 gpio_free(EGPIO_MAGICIAN_MIC_POWER);
552 gpio_free(EGPIO_MAGICIAN_EP_POWER);
553 gpio_free(EGPIO_MAGICIAN_SPK_POWER);
Philipp Zabel73772262009-03-19 09:34:46 +0100554}
555
556module_init(magician_init);
557module_exit(magician_exit);
558
559MODULE_AUTHOR("Philipp Zabel");
560MODULE_DESCRIPTION("ALSA SoC Magician");
561MODULE_LICENSE("GPL");