[ALSA] neo1973: ASoC include pathname fix
[safe/jmp/linux-2.6] / sound / soc / s3c24xx / neo1973_wm8753.c
1 /*
2  * neo1973_wm8753.c  --  SoC audio for Neo1973
3  *
4  * Copyright 2007 Wolfson Microelectronics PLC.
5  * Author: Graeme Gregory
6  *         graeme.gregory@wolfsonmicro.com or linux@wolfsonmicro.com
7  *
8  *  This program is free software; you can redistribute  it and/or modify it
9  *  under  the terms of  the GNU General  Public License as published by the
10  *  Free Software Foundation;  either version 2 of the  License, or (at your
11  *  option) any later version.
12  *
13  *  Revision history
14  *    20th Jan 2007   Initial version.
15  *    05th Feb 2007   Rename all to Neo1973
16  *
17  */
18
19 #include <linux/module.h>
20 #include <linux/moduleparam.h>
21 #include <linux/timer.h>
22 #include <linux/interrupt.h>
23 #include <linux/platform_device.h>
24 #include <linux/i2c.h>
25 #include <sound/driver.h>
26 #include <sound/core.h>
27 #include <sound/pcm.h>
28 #include <sound/soc.h>
29 #include <sound/soc-dapm.h>
30
31 #include <asm/mach-types.h>
32 #include <asm/hardware/scoop.h>
33 #include <asm/arch/regs-clock.h>
34 #include <asm/arch/regs-gpio.h>
35 #include <asm/hardware.h>
36 #include <asm/arch/audio.h>
37 #include <asm/io.h>
38 #include <asm/arch/spi-gpio.h>
39
40 #include <asm/plat-s3c24xx/regs-iis.h>
41
42 #include "../codecs/wm8753.h"
43 #include "lm4857.h"
44 #include "s3c24xx-pcm.h"
45 #include "s3c24xx-i2s.h"
46
47 /* define the scenarios */
48 #define NEO_AUDIO_OFF                   0
49 #define NEO_GSM_CALL_AUDIO_HANDSET      1
50 #define NEO_GSM_CALL_AUDIO_HEADSET      2
51 #define NEO_GSM_CALL_AUDIO_BLUETOOTH    3
52 #define NEO_STEREO_TO_SPEAKERS          4
53 #define NEO_STEREO_TO_HEADPHONES        5
54 #define NEO_CAPTURE_HANDSET             6
55 #define NEO_CAPTURE_HEADSET             7
56 #define NEO_CAPTURE_BLUETOOTH           8
57
58 static struct snd_soc_machine neo1973;
59 static struct i2c_client *i2c;
60
61 static int neo1973_hifi_hw_params(struct snd_pcm_substream *substream,
62         struct snd_pcm_hw_params *params)
63 {
64         struct snd_soc_pcm_runtime *rtd = substream->private_data;
65         struct snd_soc_codec_dai *codec_dai = rtd->dai->codec_dai;
66         struct snd_soc_cpu_dai *cpu_dai = rtd->dai->cpu_dai;
67         unsigned int pll_out = 0, bclk = 0;
68         int ret = 0;
69         unsigned long iis_clkrate;
70
71         iis_clkrate = s3c24xx_i2s_get_clockrate();
72
73         switch (params_rate(params)) {
74         case 8000:
75         case 16000:
76                 pll_out = 12288000;
77                 break;
78         case 48000:
79                 bclk = WM8753_BCLK_DIV_4;
80                 pll_out = 12288000;
81                 break;
82         case 96000:
83                 bclk = WM8753_BCLK_DIV_2;
84                 pll_out = 12288000;
85                 break;
86         case 11025:
87                 bclk = WM8753_BCLK_DIV_16;
88                 pll_out = 11289600;
89                 break;
90         case 22050:
91                 bclk = WM8753_BCLK_DIV_8;
92                 pll_out = 11289600;
93                 break;
94         case 44100:
95                 bclk = WM8753_BCLK_DIV_4;
96                 pll_out = 11289600;
97                 break;
98         case 88200:
99                 bclk = WM8753_BCLK_DIV_2;
100                 pll_out = 11289600;
101                 break;
102         }
103
104         /* set codec DAI configuration */
105         ret = codec_dai->dai_ops.set_fmt(codec_dai,
106                 SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
107                 SND_SOC_DAIFMT_CBM_CFM);
108         if (ret < 0)
109                 return ret;
110
111         /* set cpu DAI configuration */
112         ret = cpu_dai->dai_ops.set_fmt(cpu_dai,
113                 SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
114                 SND_SOC_DAIFMT_CBM_CFM);
115         if (ret < 0)
116                 return ret;
117
118         /* set the codec system clock for DAC and ADC */
119         ret = codec_dai->dai_ops.set_sysclk(codec_dai, WM8753_MCLK, pll_out,
120                 SND_SOC_CLOCK_IN);
121         if (ret < 0)
122                 return ret;
123
124         /* set MCLK division for sample rate */
125         ret = cpu_dai->dai_ops.set_clkdiv(cpu_dai, S3C24XX_DIV_MCLK,
126                 S3C2410_IISMOD_32FS );
127         if (ret < 0)
128                 return ret;
129
130         /* set codec BCLK division for sample rate */
131         ret = codec_dai->dai_ops.set_clkdiv(codec_dai, WM8753_BCLKDIV, bclk);
132         if (ret < 0)
133                 return ret;
134
135         /* set prescaler division for sample rate */
136         ret = cpu_dai->dai_ops.set_clkdiv(cpu_dai, S3C24XX_DIV_PRESCALER,
137                 S3C24XX_PRESCALE(4,4));
138         if (ret < 0)
139                 return ret;
140
141         /* codec PLL input is PCLK/4 */
142         ret = codec_dai->dai_ops.set_pll(codec_dai, WM8753_PLL1,
143                 iis_clkrate / 4, pll_out);
144         if (ret < 0)
145                 return ret;
146
147         return 0;
148 }
149
150 static int neo1973_hifi_hw_free(struct snd_pcm_substream *substream)
151 {
152         struct snd_soc_pcm_runtime *rtd = substream->private_data;
153         struct snd_soc_codec_dai *codec_dai = rtd->dai->codec_dai;
154
155         /* disable the PLL */
156         return codec_dai->dai_ops.set_pll(codec_dai, WM8753_PLL1, 0, 0);
157 }
158
159 /*
160  * Neo1973 WM8753 HiFi DAI opserations.
161  */
162 static struct snd_soc_ops neo1973_hifi_ops = {
163         .hw_params = neo1973_hifi_hw_params,
164         .hw_free = neo1973_hifi_hw_free,
165 };
166
167 static int neo1973_voice_hw_params(struct snd_pcm_substream *substream,
168         struct snd_pcm_hw_params *params)
169 {
170         struct snd_soc_pcm_runtime *rtd = substream->private_data;
171         struct snd_soc_codec_dai *codec_dai = rtd->dai->codec_dai;
172         unsigned int pcmdiv = 0;
173         int ret = 0;
174         unsigned long iis_clkrate;
175
176         iis_clkrate = s3c24xx_i2s_get_clockrate();
177
178         if (params_rate(params) != 8000)
179                 return -EINVAL;
180         if (params_channels(params) != 1)
181                 return -EINVAL;
182
183         pcmdiv = WM8753_PCM_DIV_6; /* 2.048 MHz */
184
185         /* todo: gg check mode (DSP_B) against CSR datasheet */
186         /* set codec DAI configuration */
187         ret = codec_dai->dai_ops.set_fmt(codec_dai, SND_SOC_DAIFMT_DSP_B |
188                 SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
189         if (ret < 0)
190                 return ret;
191
192         /* set the codec system clock for DAC and ADC */
193         ret = codec_dai->dai_ops.set_sysclk(codec_dai, WM8753_PCMCLK, 12288000,
194                 SND_SOC_CLOCK_IN);
195         if (ret < 0)
196                 return ret;
197
198         /* set codec PCM division for sample rate */
199         ret = codec_dai->dai_ops.set_clkdiv(codec_dai, WM8753_PCMDIV, pcmdiv);
200         if (ret < 0)
201                 return ret;
202
203         /* configue and enable PLL for 12.288MHz output */
204         ret = codec_dai->dai_ops.set_pll(codec_dai, WM8753_PLL2,
205                 iis_clkrate / 4, 12288000);
206         if (ret < 0)
207                 return ret;
208
209         return 0;
210 }
211
212 static int neo1973_voice_hw_free(struct snd_pcm_substream *substream)
213 {
214         struct snd_soc_pcm_runtime *rtd = substream->private_data;
215         struct snd_soc_codec_dai *codec_dai = rtd->dai->codec_dai;
216
217         /* disable the PLL */
218         return codec_dai->dai_ops.set_pll(codec_dai, WM8753_PLL2, 0, 0);
219 }
220
221 static struct snd_soc_ops neo1973_voice_ops = {
222         .hw_params = neo1973_voice_hw_params,
223         .hw_free = neo1973_voice_hw_free,
224 };
225
226 static int neo1973_scenario = 0;
227
228 static int neo1973_get_scenario(struct snd_kcontrol *kcontrol,
229         struct snd_ctl_elem_value *ucontrol)
230 {
231         ucontrol->value.integer.value[0] = neo1973_scenario;
232         return 0;
233 }
234
235 static int set_scenario_endpoints(struct snd_soc_codec *codec, int scenario)
236 {
237         switch(neo1973_scenario) {
238         case NEO_AUDIO_OFF:
239                 snd_soc_dapm_set_endpoint(codec, "Audio Out",    0);
240                 snd_soc_dapm_set_endpoint(codec, "GSM Line Out", 0);
241                 snd_soc_dapm_set_endpoint(codec, "GSM Line In",  0);
242                 snd_soc_dapm_set_endpoint(codec, "Headset Mic",  0);
243                 snd_soc_dapm_set_endpoint(codec, "Call Mic",     0);
244                 break;
245         case NEO_GSM_CALL_AUDIO_HANDSET:
246                 snd_soc_dapm_set_endpoint(codec, "Audio Out",    1);
247                 snd_soc_dapm_set_endpoint(codec, "GSM Line Out", 1);
248                 snd_soc_dapm_set_endpoint(codec, "GSM Line In",  1);
249                 snd_soc_dapm_set_endpoint(codec, "Headset Mic",  0);
250                 snd_soc_dapm_set_endpoint(codec, "Call Mic",     1);
251                 break;
252         case NEO_GSM_CALL_AUDIO_HEADSET:
253                 snd_soc_dapm_set_endpoint(codec, "Audio Out",    1);
254                 snd_soc_dapm_set_endpoint(codec, "GSM Line Out", 1);
255                 snd_soc_dapm_set_endpoint(codec, "GSM Line In",  1);
256                 snd_soc_dapm_set_endpoint(codec, "Headset Mic",  1);
257                 snd_soc_dapm_set_endpoint(codec, "Call Mic",     0);
258                 break;
259         case NEO_GSM_CALL_AUDIO_BLUETOOTH:
260                 snd_soc_dapm_set_endpoint(codec, "Audio Out",    0);
261                 snd_soc_dapm_set_endpoint(codec, "GSM Line Out", 1);
262                 snd_soc_dapm_set_endpoint(codec, "GSM Line In",  1);
263                 snd_soc_dapm_set_endpoint(codec, "Headset Mic",  0);
264                 snd_soc_dapm_set_endpoint(codec, "Call Mic",     0);
265                 break;
266         case NEO_STEREO_TO_SPEAKERS:
267                 snd_soc_dapm_set_endpoint(codec, "Audio Out",    1);
268                 snd_soc_dapm_set_endpoint(codec, "GSM Line Out", 0);
269                 snd_soc_dapm_set_endpoint(codec, "GSM Line In",  0);
270                 snd_soc_dapm_set_endpoint(codec, "Headset Mic",  0);
271                 snd_soc_dapm_set_endpoint(codec, "Call Mic",     0);
272                 break;
273         case NEO_STEREO_TO_HEADPHONES:
274                 snd_soc_dapm_set_endpoint(codec, "Audio Out",    1);
275                 snd_soc_dapm_set_endpoint(codec, "GSM Line Out", 0);
276                 snd_soc_dapm_set_endpoint(codec, "GSM Line In",  0);
277                 snd_soc_dapm_set_endpoint(codec, "Headset Mic",  0);
278                 snd_soc_dapm_set_endpoint(codec, "Call Mic",     0);
279                 break;
280         case NEO_CAPTURE_HANDSET:
281                 snd_soc_dapm_set_endpoint(codec, "Audio Out",    0);
282                 snd_soc_dapm_set_endpoint(codec, "GSM Line Out", 0);
283                 snd_soc_dapm_set_endpoint(codec, "GSM Line In",  0);
284                 snd_soc_dapm_set_endpoint(codec, "Headset Mic",  0);
285                 snd_soc_dapm_set_endpoint(codec, "Call Mic",     1);
286                 break;
287         case NEO_CAPTURE_HEADSET:
288                 snd_soc_dapm_set_endpoint(codec, "Audio Out",    0);
289                 snd_soc_dapm_set_endpoint(codec, "GSM Line Out", 0);
290                 snd_soc_dapm_set_endpoint(codec, "GSM Line In",  0);
291                 snd_soc_dapm_set_endpoint(codec, "Headset Mic",  1);
292                 snd_soc_dapm_set_endpoint(codec, "Call Mic",     0);
293                 break;
294         case NEO_CAPTURE_BLUETOOTH:
295                 snd_soc_dapm_set_endpoint(codec, "Audio Out",    0);
296                 snd_soc_dapm_set_endpoint(codec, "GSM Line Out", 0);
297                 snd_soc_dapm_set_endpoint(codec, "GSM Line In",  0);
298                 snd_soc_dapm_set_endpoint(codec, "Headset Mic",  0);
299                 snd_soc_dapm_set_endpoint(codec, "Call Mic",     0);
300                 break;
301         default:
302                 snd_soc_dapm_set_endpoint(codec, "Audio Out",    0);
303                 snd_soc_dapm_set_endpoint(codec, "GSM Line Out", 0);
304                 snd_soc_dapm_set_endpoint(codec, "GSM Line In",  0);
305                 snd_soc_dapm_set_endpoint(codec, "Headset Mic",  0);
306                 snd_soc_dapm_set_endpoint(codec, "Call Mic",     0);
307         }
308
309         snd_soc_dapm_sync_endpoints(codec);
310
311         return 0;
312 }
313
314 static int neo1973_set_scenario(struct snd_kcontrol *kcontrol,
315         struct snd_ctl_elem_value *ucontrol)
316 {
317         struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
318
319         if (neo1973_scenario == ucontrol->value.integer.value[0])
320                 return 0;
321
322         neo1973_scenario = ucontrol->value.integer.value[0];
323         set_scenario_endpoints(codec, neo1973_scenario);
324         return 1;
325 }
326
327 static u8 lm4857_regs[4] = {0x00, 0x40, 0x80, 0xC0};
328
329 static void lm4857_write_regs(void)
330 {
331         if (i2c_master_send(i2c, lm4857_regs, 4) != 4)
332                 printk(KERN_ERR "lm4857: i2c write failed\n");
333 }
334
335 static int lm4857_get_reg(struct snd_kcontrol *kcontrol,
336         struct snd_ctl_elem_value *ucontrol)
337 {
338         int reg=kcontrol->private_value & 0xFF;
339         int shift = (kcontrol->private_value >> 8) & 0x0F;
340         int mask = (kcontrol->private_value >> 16) & 0xFF;
341
342         ucontrol->value.integer.value[0] = (lm4857_regs[reg] >> shift) & mask;
343         return 0;
344 }
345
346 static int lm4857_set_reg(struct snd_kcontrol *kcontrol,
347         struct snd_ctl_elem_value *ucontrol)
348 {
349         int reg = kcontrol->private_value & 0xFF;
350         int shift = (kcontrol->private_value >> 8) & 0x0F;
351         int mask = (kcontrol->private_value >> 16) & 0xFF;
352
353         if (((lm4857_regs[reg] >> shift ) & mask) ==
354                 ucontrol->value.integer.value[0])
355                 return 0;
356
357         lm4857_regs[reg] &= ~ (mask << shift);
358         lm4857_regs[reg] |= ucontrol->value.integer.value[0] << shift;
359         lm4857_write_regs();
360         return 1;
361 }
362
363 static int lm4857_get_mode(struct snd_kcontrol *kcontrol,
364         struct snd_ctl_elem_value *ucontrol)
365 {
366         u8 value = lm4857_regs[LM4857_CTRL] & 0x0F;
367
368         if (value)
369                 value -= 5;
370
371         ucontrol->value.integer.value[0] = value;
372         return 0;
373 }
374
375 static int lm4857_set_mode(struct snd_kcontrol *kcontrol,
376         struct snd_ctl_elem_value *ucontrol)
377 {
378         u8 value = ucontrol->value.integer.value[0];
379
380         if (value)
381                 value += 5;
382
383         if ((lm4857_regs[LM4857_CTRL] & 0x0F) == value)
384                 return 0;
385
386         lm4857_regs[LM4857_CTRL] &= 0xF0;
387         lm4857_regs[LM4857_CTRL] |= value;
388         lm4857_write_regs();
389         return 1;
390 }
391
392 static const struct snd_soc_dapm_widget wm8753_dapm_widgets[] = {
393         SND_SOC_DAPM_LINE("Audio Out", NULL),
394         SND_SOC_DAPM_LINE("GSM Line Out", NULL),
395         SND_SOC_DAPM_LINE("GSM Line In", NULL),
396         SND_SOC_DAPM_MIC("Headset Mic", NULL),
397         SND_SOC_DAPM_MIC("Call Mic", NULL),
398 };
399
400
401 /* example machine audio_mapnections */
402 static const char* audio_map[][3] = {
403
404         /* Connections to the lm4857 amp */
405         {"Audio Out", NULL, "LOUT1"},
406         {"Audio Out", NULL, "ROUT1"},
407
408         /* Connections to the GSM Module */
409         {"GSM Line Out", NULL, "MONO1"},
410         {"GSM Line Out", NULL, "MONO2"},
411         {"RXP", NULL, "GSM Line In"},
412         {"RXN", NULL, "GSM Line In"},
413
414         /* Connections to Headset */
415         {"MIC1", NULL, "Mic Bias"},
416         {"Mic Bias", NULL, "Headset Mic"},
417
418         /* Call Mic */
419         {"MIC2", NULL, "Mic Bias"},
420         {"MIC2N", NULL, "Mic Bias"},
421         {"Mic Bias", NULL, "Call Mic"},
422
423         /* Connect the ALC pins */
424         {"ACIN", NULL, "ACOP"},
425
426         {NULL, NULL, NULL},
427 };
428
429 static const char *lm4857_mode[] = {
430         "Off",
431         "Call Speaker",
432         "Stereo Speakers",
433         "Stereo Speakers + Headphones",
434         "Headphones"
435 };
436
437 static const struct soc_enum lm4857_mode_enum[] = {
438         SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(lm4857_mode), lm4857_mode),
439 };
440
441 static const char *neo_scenarios[] = {
442         "Off",
443         "GSM Handset",
444         "GSM Headset",
445         "GSM Bluetooth",
446         "Speakers",
447         "Headphones",
448         "Capture Handset",
449         "Capture Headset",
450         "Capture Bluetooth"
451 };
452
453 static const struct soc_enum neo_scenario_enum[] = {
454         SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(neo_scenarios),neo_scenarios),
455 };
456
457 static const struct snd_kcontrol_new wm8753_neo1973_controls[] = {
458         SOC_SINGLE_EXT("Amp Left Playback Volume", LM4857_LVOL, 0, 31, 0,
459                 lm4857_get_reg, lm4857_set_reg),
460         SOC_SINGLE_EXT("Amp Right Playback Volume", LM4857_RVOL, 0, 31, 0,
461                 lm4857_get_reg, lm4857_set_reg),
462         SOC_SINGLE_EXT("Amp Mono Playback Volume", LM4857_MVOL, 0, 31, 0,
463                 lm4857_get_reg, lm4857_set_reg),
464         SOC_ENUM_EXT("Amp Mode", lm4857_mode_enum[0],
465                 lm4857_get_mode, lm4857_set_mode),
466         SOC_ENUM_EXT("Neo Mode", neo_scenario_enum[0],
467                 neo1973_get_scenario, neo1973_set_scenario),
468         SOC_SINGLE_EXT("Amp Spk 3D Playback Switch", LM4857_LVOL, 5, 1, 0,
469                 lm4857_get_reg, lm4857_set_reg),
470         SOC_SINGLE_EXT("Amp HP 3d Playback Switch", LM4857_RVOL, 5, 1, 0,
471                 lm4857_get_reg, lm4857_set_reg),
472         SOC_SINGLE_EXT("Amp Fast Wakeup Playback Switch", LM4857_CTRL, 5, 1, 0,
473                 lm4857_get_reg, lm4857_set_reg),
474         SOC_SINGLE_EXT("Amp Earpiece 6dB Playback Switch", LM4857_CTRL, 4, 1, 0,
475                 lm4857_get_reg, lm4857_set_reg),
476 };
477
478 /*
479  * This is an example machine initialisation for a wm8753 connected to a
480  * neo1973 II. It is missing logic to detect hp/mic insertions and logic
481  * to re-route the audio in such an event.
482  */
483 static int neo1973_wm8753_init(struct snd_soc_codec *codec)
484 {
485         int i, err;
486
487         /* set up NC codec pins */
488         snd_soc_dapm_set_endpoint(codec, "LOUT2", 0);
489         snd_soc_dapm_set_endpoint(codec, "ROUT2", 0);
490         snd_soc_dapm_set_endpoint(codec, "OUT3",  0);
491         snd_soc_dapm_set_endpoint(codec, "OUT4",  0);
492         snd_soc_dapm_set_endpoint(codec, "LINE1", 0);
493         snd_soc_dapm_set_endpoint(codec, "LINE2", 0);
494
495
496         /* set endpoints to default mode */
497         set_scenario_endpoints(codec, NEO_AUDIO_OFF);
498
499         /* Add neo1973 specific widgets */
500         for (i = 0; i < ARRAY_SIZE(wm8753_dapm_widgets); i++)
501                 snd_soc_dapm_new_control(codec, &wm8753_dapm_widgets[i]);
502
503         /* add neo1973 specific controls */
504         for (i = 0; i < ARRAY_SIZE(wm8753_neo1973_controls); i++) {
505                 err = snd_ctl_add(codec->card,
506                                 snd_soc_cnew(&wm8753_neo1973_controls[i],
507                                 codec, NULL));
508                 if (err < 0)
509                         return err;
510         }
511
512         /* set up neo1973 specific audio path audio_mapnects */
513         for (i = 0; audio_map[i][0] != NULL; i++) {
514                 snd_soc_dapm_connect_input(codec, audio_map[i][0],
515                         audio_map[i][1], audio_map[i][2]);
516         }
517
518         snd_soc_dapm_sync_endpoints(codec);
519         return 0;
520 }
521
522 /*
523  * BT Codec DAI
524  */
525 static struct snd_soc_cpu_dai bt_dai =
526 {       .name = "Bluetooth",
527         .id = 0,
528         .type = SND_SOC_DAI_PCM,
529         .playback = {
530                 .channels_min = 1,
531                 .channels_max = 1,
532                 .rates = SNDRV_PCM_RATE_8000,
533                 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
534         .capture = {
535                 .channels_min = 1,
536                 .channels_max = 1,
537                 .rates = SNDRV_PCM_RATE_8000,
538                 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
539 };
540
541 static struct snd_soc_dai_link neo1973_dai[] = {
542 { /* Hifi Playback - for similatious use with voice below */
543         .name = "WM8753",
544         .stream_name = "WM8753 HiFi",
545         .cpu_dai = &s3c24xx_i2s_dai,
546         .codec_dai = &wm8753_dai[WM8753_DAI_HIFI],
547         .init = neo1973_wm8753_init,
548         .ops = &neo1973_hifi_ops,
549 },
550 { /* Voice via BT */
551         .name = "Bluetooth",
552         .stream_name = "Voice",
553         .cpu_dai = &bt_dai,
554         .codec_dai = &wm8753_dai[WM8753_DAI_VOICE],
555         .ops = &neo1973_voice_ops,
556 },
557 };
558
559 static struct snd_soc_machine neo1973 = {
560         .name = "neo1973",
561         .dai_link = neo1973_dai,
562         .num_links = ARRAY_SIZE(neo1973_dai),
563 };
564
565 static struct wm8753_setup_data neo1973_wm8753_setup = {
566         .i2c_address = 0x1a,
567 };
568
569 static struct snd_soc_device neo1973_snd_devdata = {
570         .machine = &neo1973,
571         .platform = &s3c24xx_soc_platform,
572         .codec_dev = &soc_codec_dev_wm8753,
573         .codec_data = &neo1973_wm8753_setup,
574 };
575
576 static struct i2c_client client_template;
577
578 static const unsigned short normal_i2c[] = { 0x7C, I2C_CLIENT_END };
579
580 /* Magic definition of all other variables and things */
581 I2C_CLIENT_INSMOD;
582
583 static int lm4857_amp_probe(struct i2c_adapter *adap, int addr, int kind)
584 {
585         int ret;
586
587         client_template.adapter = adap;
588         client_template.addr = addr;
589
590         i2c = kmemdup(&client_template, sizeof(client_template), GFP_KERNEL);
591         if (i2c == NULL)
592                 return -ENOMEM;
593
594         ret = i2c_attach_client(i2c);
595         if (ret < 0) {
596                 printk(KERN_ERR "LM4857 failed to attach at addr %x\n", addr);
597                 goto exit_err;
598         }
599
600         lm4857_write_regs();
601         return ret;
602
603 exit_err:
604         kfree(i2c);
605         return ret;
606 }
607
608 static int lm4857_i2c_detach(struct i2c_client *client)
609 {
610         i2c_detach_client(client);
611         kfree(client);
612         return 0;
613 }
614
615 static int lm4857_i2c_attach(struct i2c_adapter *adap)
616 {
617         return i2c_probe(adap, &addr_data, lm4857_amp_probe);
618 }
619
620 /* corgi i2c codec control layer */
621 static struct i2c_driver lm4857_i2c_driver = {
622         .driver = {
623                 .name = "LM4857 I2C Amp",
624                 .owner = THIS_MODULE,
625         },
626         .id =             I2C_DRIVERID_LM4857,
627         .attach_adapter = lm4857_i2c_attach,
628         .detach_client =  lm4857_i2c_detach,
629         .command =        NULL,
630 };
631
632 static struct i2c_client client_template = {
633         .name =   "LM4857",
634         .driver = &lm4857_i2c_driver,
635 };
636
637 static struct platform_device *neo1973_snd_device;
638
639 static int __init neo1973_init(void)
640 {
641         int ret;
642
643         neo1973_snd_device = platform_device_alloc("soc-audio", -1);
644         if (!neo1973_snd_device)
645                 return -ENOMEM;
646
647         platform_set_drvdata(neo1973_snd_device, &neo1973_snd_devdata);
648         neo1973_snd_devdata.dev = &neo1973_snd_device->dev;
649         ret = platform_device_add(neo1973_snd_device);
650
651         if (ret)
652                 platform_device_put(neo1973_snd_device);
653
654         ret = i2c_add_driver(&lm4857_i2c_driver);
655         if (ret != 0)
656                 printk(KERN_ERR "can't add i2c driver");
657
658         return ret;
659 }
660
661 static void __exit neo1973_exit(void)
662 {
663         platform_device_unregister(neo1973_snd_device);
664 }
665
666 module_init(neo1973_init);
667 module_exit(neo1973_exit);
668
669 /* Module information */
670 MODULE_AUTHOR("Graeme Gregory, graeme.gregory@wolfsonmicro.com, www.wolfsonmicro.com");
671 MODULE_DESCRIPTION("ALSA SoC WM8753 Neo1973");
672 MODULE_LICENSE("GPL");