blob: 67dcc36cd621d407df19a4fd2c5f5106dcdc5863 [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>
Philipp Zabel1abd9182009-06-15 22:18:23 +020029#include <sound/uda1380.h>
Philipp Zabel73772262009-03-19 09:34:46 +010030
Philipp Zabel73772262009-03-19 09:34:46 +010031#include <mach/magician.h>
32#include <asm/mach-types.h>
33#include "../codecs/uda1380.h"
Philipp Zabel73772262009-03-19 09:34:46 +010034#include "pxa2xx-i2s.h"
35#include "pxa-ssp.h"
36
37#define MAGICIAN_MIC 0
38#define MAGICIAN_MIC_EXT 1
39
40static int magician_hp_switch;
41static int magician_spk_switch = 1;
42static int magician_in_sel = MAGICIAN_MIC;
43
44static void magician_ext_control(struct snd_soc_codec *codec)
45{
Liam Girdwoodce6120c2010-11-05 15:53:46 +020046 struct snd_soc_dapm_context *dapm = &codec->dapm;
47
Philipp Zabel73772262009-03-19 09:34:46 +010048 if (magician_spk_switch)
Liam Girdwoodce6120c2010-11-05 15:53:46 +020049 snd_soc_dapm_enable_pin(dapm, "Speaker");
Philipp Zabel73772262009-03-19 09:34:46 +010050 else
Liam Girdwoodce6120c2010-11-05 15:53:46 +020051 snd_soc_dapm_disable_pin(dapm, "Speaker");
Philipp Zabel73772262009-03-19 09:34:46 +010052 if (magician_hp_switch)
Liam Girdwoodce6120c2010-11-05 15:53:46 +020053 snd_soc_dapm_enable_pin(dapm, "Headphone Jack");
Philipp Zabel73772262009-03-19 09:34:46 +010054 else
Liam Girdwoodce6120c2010-11-05 15:53:46 +020055 snd_soc_dapm_disable_pin(dapm, "Headphone Jack");
Philipp Zabel73772262009-03-19 09:34:46 +010056
57 switch (magician_in_sel) {
58 case MAGICIAN_MIC:
Liam Girdwoodce6120c2010-11-05 15:53:46 +020059 snd_soc_dapm_disable_pin(dapm, "Headset Mic");
60 snd_soc_dapm_enable_pin(dapm, "Call Mic");
Philipp Zabel73772262009-03-19 09:34:46 +010061 break;
62 case MAGICIAN_MIC_EXT:
Liam Girdwoodce6120c2010-11-05 15:53:46 +020063 snd_soc_dapm_disable_pin(dapm, "Call Mic");
64 snd_soc_dapm_enable_pin(dapm, "Headset Mic");
Philipp Zabel73772262009-03-19 09:34:46 +010065 break;
66 }
67
Liam Girdwoodce6120c2010-11-05 15:53:46 +020068 snd_soc_dapm_sync(dapm);
Philipp Zabel73772262009-03-19 09:34:46 +010069}
70
71static int magician_startup(struct snd_pcm_substream *substream)
72{
73 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000074 struct snd_soc_codec *codec = rtd->codec;
Philipp Zabel73772262009-03-19 09:34:46 +010075
Mark Brown71a29562010-11-05 13:50:48 -040076 mutex_lock(&codec->mutex);
77
Philipp Zabel73772262009-03-19 09:34:46 +010078 /* check the jack status at stream startup */
79 magician_ext_control(codec);
80
Mark Brown71a29562010-11-05 13:50:48 -040081 mutex_unlock(&codec->mutex);
82
Philipp Zabel73772262009-03-19 09:34:46 +010083 return 0;
84}
85
86/*
87 * Magician uses SSP port for playback.
88 */
89static int magician_playback_hw_params(struct snd_pcm_substream *substream,
90 struct snd_pcm_hw_params *params)
91{
92 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000093 struct snd_soc_dai *codec_dai = rtd->codec_dai;
94 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
Philipp Zabel73772262009-03-19 09:34:46 +010095 unsigned int acps, acds, width, rate;
96 unsigned int div4 = PXA_SSP_CLK_SCDB_4;
97 int ret = 0;
98
99 rate = params_rate(params);
100 width = snd_pcm_format_physical_width(params_format(params));
101
102 /*
103 * rate = SSPSCLK / (2 * width(16 or 32))
104 * SSPSCLK = (ACPS / ACDS) / SSPSCLKDIV(div4 or div1)
105 */
106 switch (params_rate(params)) {
107 case 8000:
108 /* off by a factor of 2: bug in the PXA27x audio clock? */
109 acps = 32842000;
110 switch (width) {
111 case 16:
112 /* 513156 Hz ~= _2_ * 8000 Hz * 32 (+0.23%) */
113 acds = PXA_SSP_CLK_AUDIO_DIV_16;
114 break;
Takashi Iwai2bf27782009-05-15 12:20:52 +0200115 default: /* 32 */
Philipp Zabel73772262009-03-19 09:34:46 +0100116 /* 1026312 Hz ~= _2_ * 8000 Hz * 64 (+0.23%) */
117 acds = PXA_SSP_CLK_AUDIO_DIV_8;
118 }
119 break;
120 case 11025:
121 acps = 5622000;
122 switch (width) {
123 case 16:
124 /* 351375 Hz ~= 11025 Hz * 32 (-0.41%) */
125 acds = PXA_SSP_CLK_AUDIO_DIV_4;
126 break;
Takashi Iwai2bf27782009-05-15 12:20:52 +0200127 default: /* 32 */
Philipp Zabel73772262009-03-19 09:34:46 +0100128 /* 702750 Hz ~= 11025 Hz * 64 (-0.41%) */
129 acds = PXA_SSP_CLK_AUDIO_DIV_2;
130 }
131 break;
132 case 22050:
133 acps = 5622000;
134 switch (width) {
135 case 16:
136 /* 702750 Hz ~= 22050 Hz * 32 (-0.41%) */
137 acds = PXA_SSP_CLK_AUDIO_DIV_2;
138 break;
Takashi Iwai2bf27782009-05-15 12:20:52 +0200139 default: /* 32 */
Philipp Zabel73772262009-03-19 09:34:46 +0100140 /* 1405500 Hz ~= 22050 Hz * 64 (-0.41%) */
141 acds = PXA_SSP_CLK_AUDIO_DIV_1;
142 }
143 break;
144 case 44100:
145 acps = 5622000;
146 switch (width) {
147 case 16:
148 /* 1405500 Hz ~= 44100 Hz * 32 (-0.41%) */
149 acds = PXA_SSP_CLK_AUDIO_DIV_2;
150 break;
Takashi Iwai2bf27782009-05-15 12:20:52 +0200151 default: /* 32 */
Philipp Zabel73772262009-03-19 09:34:46 +0100152 /* 2811000 Hz ~= 44100 Hz * 64 (-0.41%) */
153 acds = PXA_SSP_CLK_AUDIO_DIV_1;
154 }
155 break;
156 case 48000:
157 acps = 12235000;
158 switch (width) {
159 case 16:
160 /* 1529375 Hz ~= 48000 Hz * 32 (-0.44%) */
161 acds = PXA_SSP_CLK_AUDIO_DIV_2;
162 break;
Takashi Iwai2bf27782009-05-15 12:20:52 +0200163 default: /* 32 */
Philipp Zabel73772262009-03-19 09:34:46 +0100164 /* 3058750 Hz ~= 48000 Hz * 64 (-0.44%) */
165 acds = PXA_SSP_CLK_AUDIO_DIV_1;
166 }
167 break;
168 case 96000:
Takashi Iwai2bf27782009-05-15 12:20:52 +0200169 default:
Philipp Zabel73772262009-03-19 09:34:46 +0100170 acps = 12235000;
171 switch (width) {
172 case 16:
173 /* 3058750 Hz ~= 96000 Hz * 32 (-0.44%) */
174 acds = PXA_SSP_CLK_AUDIO_DIV_1;
175 break;
Takashi Iwai2bf27782009-05-15 12:20:52 +0200176 default: /* 32 */
Philipp Zabel73772262009-03-19 09:34:46 +0100177 /* 6117500 Hz ~= 96000 Hz * 64 (-0.44%) */
178 acds = PXA_SSP_CLK_AUDIO_DIV_2;
179 div4 = PXA_SSP_CLK_SCDB_1;
180 break;
181 }
182 break;
183 }
184
185 /* set codec DAI configuration */
186 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_MSB |
187 SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
188 if (ret < 0)
189 return ret;
190
191 /* set cpu DAI configuration */
192 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_DSP_A |
Philipp Zabel33745fb2009-06-14 12:51:30 +0200193 SND_SOC_DAIFMT_NB_IF | SND_SOC_DAIFMT_CBS_CFS);
Philipp Zabel73772262009-03-19 09:34:46 +0100194 if (ret < 0)
195 return ret;
196
Daniel Ribeiroa5479e32009-06-15 21:44:31 -0300197 ret = snd_soc_dai_set_tdm_slot(cpu_dai, 1, 0, 1, width);
Philipp Zabel73772262009-03-19 09:34:46 +0100198 if (ret < 0)
199 return ret;
200
201 /* set audio clock as clock source */
202 ret = snd_soc_dai_set_sysclk(cpu_dai, PXA_SSP_CLK_AUDIO, 0,
203 SND_SOC_CLOCK_OUT);
204 if (ret < 0)
205 return ret;
206
207 /* set the SSP audio system clock ACDS divider */
208 ret = snd_soc_dai_set_clkdiv(cpu_dai,
209 PXA_SSP_AUDIO_DIV_ACDS, acds);
210 if (ret < 0)
211 return ret;
212
213 /* set the SSP audio system clock SCDB divider4 */
214 ret = snd_soc_dai_set_clkdiv(cpu_dai,
215 PXA_SSP_AUDIO_DIV_SCDB, div4);
216 if (ret < 0)
217 return ret;
218
219 /* set SSP audio pll clock */
Mark Brown85488032009-09-05 18:52:16 +0100220 ret = snd_soc_dai_set_pll(cpu_dai, 0, 0, 0, acps);
Philipp Zabel73772262009-03-19 09:34:46 +0100221 if (ret < 0)
222 return ret;
223
224 return 0;
225}
226
227/*
228 * Magician uses I2S for capture.
229 */
230static int magician_capture_hw_params(struct snd_pcm_substream *substream,
231 struct snd_pcm_hw_params *params)
232{
233 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000234 struct snd_soc_dai *codec_dai = rtd->codec_dai;
235 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
Philipp Zabel73772262009-03-19 09:34:46 +0100236 int ret = 0;
237
238 /* set codec DAI configuration */
239 ret = snd_soc_dai_set_fmt(codec_dai,
240 SND_SOC_DAIFMT_MSB | SND_SOC_DAIFMT_NB_NF |
241 SND_SOC_DAIFMT_CBS_CFS);
242 if (ret < 0)
243 return ret;
244
245 /* set cpu DAI configuration */
246 ret = snd_soc_dai_set_fmt(cpu_dai,
247 SND_SOC_DAIFMT_MSB | SND_SOC_DAIFMT_NB_NF |
248 SND_SOC_DAIFMT_CBS_CFS);
249 if (ret < 0)
250 return ret;
251
252 /* set the I2S system clock as output */
253 ret = snd_soc_dai_set_sysclk(cpu_dai, PXA2XX_I2S_SYSCLK, 0,
254 SND_SOC_CLOCK_OUT);
255 if (ret < 0)
256 return ret;
257
258 return 0;
259}
260
261static struct snd_soc_ops magician_capture_ops = {
262 .startup = magician_startup,
263 .hw_params = magician_capture_hw_params,
264};
265
266static struct snd_soc_ops magician_playback_ops = {
267 .startup = magician_startup,
268 .hw_params = magician_playback_hw_params,
269};
270
271static int magician_get_hp(struct snd_kcontrol *kcontrol,
272 struct snd_ctl_elem_value *ucontrol)
273{
274 ucontrol->value.integer.value[0] = magician_hp_switch;
275 return 0;
276}
277
278static int magician_set_hp(struct snd_kcontrol *kcontrol,
279 struct snd_ctl_elem_value *ucontrol)
280{
281 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
282
283 if (magician_hp_switch == ucontrol->value.integer.value[0])
284 return 0;
285
286 magician_hp_switch = ucontrol->value.integer.value[0];
287 magician_ext_control(codec);
288 return 1;
289}
290
291static int magician_get_spk(struct snd_kcontrol *kcontrol,
292 struct snd_ctl_elem_value *ucontrol)
293{
294 ucontrol->value.integer.value[0] = magician_spk_switch;
295 return 0;
296}
297
298static int magician_set_spk(struct snd_kcontrol *kcontrol,
299 struct snd_ctl_elem_value *ucontrol)
300{
301 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
302
303 if (magician_spk_switch == ucontrol->value.integer.value[0])
304 return 0;
305
306 magician_spk_switch = ucontrol->value.integer.value[0];
307 magician_ext_control(codec);
308 return 1;
309}
310
311static int magician_get_input(struct snd_kcontrol *kcontrol,
312 struct snd_ctl_elem_value *ucontrol)
313{
314 ucontrol->value.integer.value[0] = magician_in_sel;
315 return 0;
316}
317
318static int magician_set_input(struct snd_kcontrol *kcontrol,
319 struct snd_ctl_elem_value *ucontrol)
320{
321 if (magician_in_sel == ucontrol->value.integer.value[0])
322 return 0;
323
324 magician_in_sel = ucontrol->value.integer.value[0];
325
326 switch (magician_in_sel) {
327 case MAGICIAN_MIC:
328 gpio_set_value(EGPIO_MAGICIAN_IN_SEL1, 1);
329 break;
330 case MAGICIAN_MIC_EXT:
331 gpio_set_value(EGPIO_MAGICIAN_IN_SEL1, 0);
332 }
333
334 return 1;
335}
336
337static int magician_spk_power(struct snd_soc_dapm_widget *w,
338 struct snd_kcontrol *k, int event)
339{
340 gpio_set_value(EGPIO_MAGICIAN_SPK_POWER, SND_SOC_DAPM_EVENT_ON(event));
341 return 0;
342}
343
344static int magician_hp_power(struct snd_soc_dapm_widget *w,
345 struct snd_kcontrol *k, int event)
346{
347 gpio_set_value(EGPIO_MAGICIAN_EP_POWER, SND_SOC_DAPM_EVENT_ON(event));
348 return 0;
349}
350
351static int magician_mic_bias(struct snd_soc_dapm_widget *w,
352 struct snd_kcontrol *k, int event)
353{
354 gpio_set_value(EGPIO_MAGICIAN_MIC_POWER, SND_SOC_DAPM_EVENT_ON(event));
355 return 0;
356}
357
358/* magician machine dapm widgets */
359static const struct snd_soc_dapm_widget uda1380_dapm_widgets[] = {
360 SND_SOC_DAPM_HP("Headphone Jack", magician_hp_power),
361 SND_SOC_DAPM_SPK("Speaker", magician_spk_power),
362 SND_SOC_DAPM_MIC("Call Mic", magician_mic_bias),
363 SND_SOC_DAPM_MIC("Headset Mic", magician_mic_bias),
364};
365
366/* magician machine audio_map */
367static const struct snd_soc_dapm_route audio_map[] = {
368
369 /* Headphone connected to VOUTL, VOUTR */
370 {"Headphone Jack", NULL, "VOUTL"},
371 {"Headphone Jack", NULL, "VOUTR"},
372
373 /* Speaker connected to VOUTL, VOUTR */
374 {"Speaker", NULL, "VOUTL"},
375 {"Speaker", NULL, "VOUTR"},
376
377 /* Mics are connected to VINM */
378 {"VINM", NULL, "Headset Mic"},
379 {"VINM", NULL, "Call Mic"},
380};
381
382static const char *input_select[] = {"Call Mic", "Headset Mic"};
383static const struct soc_enum magician_in_sel_enum =
384 SOC_ENUM_SINGLE_EXT(2, input_select);
385
386static const struct snd_kcontrol_new uda1380_magician_controls[] = {
387 SOC_SINGLE_BOOL_EXT("Headphone Switch",
388 (unsigned long)&magician_hp_switch,
389 magician_get_hp, magician_set_hp),
390 SOC_SINGLE_BOOL_EXT("Speaker Switch",
391 (unsigned long)&magician_spk_switch,
392 magician_get_spk, magician_set_spk),
393 SOC_ENUM_EXT("Input Select", magician_in_sel_enum,
394 magician_get_input, magician_set_input),
395};
396
397/*
398 * Logic for a uda1380 as connected on a HTC Magician
399 */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000400static int magician_uda1380_init(struct snd_soc_pcm_runtime *rtd)
Philipp Zabel73772262009-03-19 09:34:46 +0100401{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000402 struct snd_soc_codec *codec = rtd->codec;
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200403 struct snd_soc_dapm_context *dapm = &codec->dapm;
Philipp Zabel73772262009-03-19 09:34:46 +0100404 int err;
405
406 /* NC codec pins */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200407 snd_soc_dapm_nc_pin(dapm, "VOUTLHP");
408 snd_soc_dapm_nc_pin(dapm, "VOUTRHP");
Philipp Zabel73772262009-03-19 09:34:46 +0100409
410 /* FIXME: is anything connected here? */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200411 snd_soc_dapm_nc_pin(dapm, "VINL");
412 snd_soc_dapm_nc_pin(dapm, "VINR");
Philipp Zabel73772262009-03-19 09:34:46 +0100413
414 /* Add magician specific controls */
415 err = snd_soc_add_controls(codec, uda1380_magician_controls,
416 ARRAY_SIZE(uda1380_magician_controls));
417 if (err < 0)
418 return err;
419
420 /* Add magician specific widgets */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200421 snd_soc_dapm_new_controls(dapm, uda1380_dapm_widgets,
Philipp Zabel73772262009-03-19 09:34:46 +0100422 ARRAY_SIZE(uda1380_dapm_widgets));
423
424 /* Set up magician specific audio path interconnects */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200425 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
Philipp Zabel73772262009-03-19 09:34:46 +0100426
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200427 snd_soc_dapm_sync(dapm);
Philipp Zabel73772262009-03-19 09:34:46 +0100428 return 0;
429}
430
431/* magician digital audio interface glue - connects codec <--> CPU */
432static struct snd_soc_dai_link magician_dai[] = {
433{
434 .name = "uda1380",
435 .stream_name = "UDA1380 Playback",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000436 .cpu_dai_name = "pxa-ssp-dai.0",
437 .codec_dai_name = "uda1380-hifi-playback",
438 .platform_name = "pxa-pcm-audio",
439 .codec_name = "uda1380-codec.0-0018",
Philipp Zabel73772262009-03-19 09:34:46 +0100440 .init = magician_uda1380_init,
441 .ops = &magician_playback_ops,
442},
443{
444 .name = "uda1380",
445 .stream_name = "UDA1380 Capture",
Ian Larteya2a00862010-08-20 17:18:43 +0100446 .cpu_dai_name = "pxa2xx-i2s",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000447 .codec_dai_name = "uda1380-hifi-capture",
448 .platform_name = "pxa-pcm-audio",
449 .codec_name = "uda1380-codec.0-0018",
Philipp Zabel73772262009-03-19 09:34:46 +0100450 .ops = &magician_capture_ops,
451}
452};
453
454/* magician audio machine driver */
455static struct snd_soc_card snd_soc_card_magician = {
456 .name = "Magician",
457 .dai_link = magician_dai,
458 .num_links = ARRAY_SIZE(magician_dai),
Philipp Zabel73772262009-03-19 09:34:46 +0100459
Philipp Zabel73772262009-03-19 09:34:46 +0100460};
461
462static struct platform_device *magician_snd_device;
463
Philipp Zabel1abd9182009-06-15 22:18:23 +0200464/*
465 * FIXME: move into magician board file once merged into the pxa tree
466 */
467static struct uda1380_platform_data uda1380_info = {
468 .gpio_power = EGPIO_MAGICIAN_CODEC_POWER,
469 .gpio_reset = EGPIO_MAGICIAN_CODEC_RESET,
470 .dac_clk = UDA1380_DAC_CLK_WSPLL,
471};
472
473static struct i2c_board_info i2c_board_info[] = {
474 {
475 I2C_BOARD_INFO("uda1380", 0x18),
476 .platform_data = &uda1380_info,
477 },
478};
479
Philipp Zabel73772262009-03-19 09:34:46 +0100480static int __init magician_init(void)
481{
482 int ret;
Philipp Zabel1abd9182009-06-15 22:18:23 +0200483 struct i2c_adapter *adapter;
484 struct i2c_client *client;
Philipp Zabel73772262009-03-19 09:34:46 +0100485
486 if (!machine_is_magician())
487 return -ENODEV;
488
Philipp Zabel1abd9182009-06-15 22:18:23 +0200489 adapter = i2c_get_adapter(0);
490 if (!adapter)
491 return -ENODEV;
492 client = i2c_new_device(adapter, i2c_board_info);
493 i2c_put_adapter(adapter);
494 if (!client)
495 return -ENODEV;
496
Philipp Zabel73772262009-03-19 09:34:46 +0100497 ret = gpio_request(EGPIO_MAGICIAN_SPK_POWER, "SPK_POWER");
498 if (ret)
499 goto err_request_spk;
500 ret = gpio_request(EGPIO_MAGICIAN_EP_POWER, "EP_POWER");
501 if (ret)
502 goto err_request_ep;
503 ret = gpio_request(EGPIO_MAGICIAN_MIC_POWER, "MIC_POWER");
504 if (ret)
505 goto err_request_mic;
506 ret = gpio_request(EGPIO_MAGICIAN_IN_SEL0, "IN_SEL0");
507 if (ret)
508 goto err_request_in_sel0;
509 ret = gpio_request(EGPIO_MAGICIAN_IN_SEL1, "IN_SEL1");
510 if (ret)
511 goto err_request_in_sel1;
512
Philipp Zabel73772262009-03-19 09:34:46 +0100513 gpio_set_value(EGPIO_MAGICIAN_IN_SEL0, 0);
514
Philipp Zabel73772262009-03-19 09:34:46 +0100515 magician_snd_device = platform_device_alloc("soc-audio", -1);
516 if (!magician_snd_device) {
517 ret = -ENOMEM;
518 goto err_pdev;
519 }
520
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000521 platform_set_drvdata(magician_snd_device, &snd_soc_card_magician);
Philipp Zabel73772262009-03-19 09:34:46 +0100522 ret = platform_device_add(magician_snd_device);
523 if (ret) {
524 platform_device_put(magician_snd_device);
525 goto err_pdev;
526 }
527
528 return 0;
529
530err_pdev:
531 gpio_free(EGPIO_MAGICIAN_IN_SEL1);
532err_request_in_sel1:
533 gpio_free(EGPIO_MAGICIAN_IN_SEL0);
534err_request_in_sel0:
535 gpio_free(EGPIO_MAGICIAN_MIC_POWER);
536err_request_mic:
537 gpio_free(EGPIO_MAGICIAN_EP_POWER);
538err_request_ep:
539 gpio_free(EGPIO_MAGICIAN_SPK_POWER);
540err_request_spk:
Philipp Zabel73772262009-03-19 09:34:46 +0100541 return ret;
542}
543
544static void __exit magician_exit(void)
545{
546 platform_device_unregister(magician_snd_device);
547
548 gpio_set_value(EGPIO_MAGICIAN_SPK_POWER, 0);
549 gpio_set_value(EGPIO_MAGICIAN_EP_POWER, 0);
550 gpio_set_value(EGPIO_MAGICIAN_MIC_POWER, 0);
Philipp Zabel73772262009-03-19 09:34:46 +0100551
552 gpio_free(EGPIO_MAGICIAN_IN_SEL1);
553 gpio_free(EGPIO_MAGICIAN_IN_SEL0);
554 gpio_free(EGPIO_MAGICIAN_MIC_POWER);
555 gpio_free(EGPIO_MAGICIAN_EP_POWER);
556 gpio_free(EGPIO_MAGICIAN_SPK_POWER);
Philipp Zabel73772262009-03-19 09:34:46 +0100557}
558
559module_init(magician_init);
560module_exit(magician_exit);
561
562MODULE_AUTHOR("Philipp Zabel");
563MODULE_DESCRIPTION("ALSA SoC Magician");
564MODULE_LICENSE("GPL");