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