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