Merge git://github.com/herbertx/crypto
[pandora-kernel.git] / sound / soc / samsung / smdk_wm8994.c
1 /*
2  *  smdk_wm8994.c
3  *
4  *  This program is free software; you can redistribute  it and/or modify it
5  *  under  the terms of  the GNU General  Public License as published by the
6  *  Free Software Foundation;  either version 2 of the  License, or (at your
7  *  option) any later version.
8  */
9
10 #include "../codecs/wm8994.h"
11 #include <sound/pcm_params.h>
12
13  /*
14   * Default CFG switch settings to use this driver:
15   *     SMDKV310: CFG5-1000, CFG7-111111
16   */
17
18  /*
19   * Configure audio route as :-
20   * $ amixer sset 'DAC1' on,on
21   * $ amixer sset 'Right Headphone Mux' 'DAC'
22   * $ amixer sset 'Left Headphone Mux' 'DAC'
23   * $ amixer sset 'DAC1R Mixer AIF1.1' on
24   * $ amixer sset 'DAC1L Mixer AIF1.1' on
25   * $ amixer sset 'IN2L' on
26   * $ amixer sset 'IN2L PGA IN2LN' on
27   * $ amixer sset 'MIXINL IN2L' on
28   * $ amixer sset 'AIF1ADC1L Mixer ADC/DMIC' on
29   * $ amixer sset 'IN2R' on
30   * $ amixer sset 'IN2R PGA IN2RN' on
31   * $ amixer sset 'MIXINR IN2R' on
32   * $ amixer sset 'AIF1ADC1R Mixer ADC/DMIC' on
33   */
34
35 /* SMDK has a 16.934MHZ crystal attached to WM8994 */
36 #define SMDK_WM8994_FREQ 16934000
37
38 static int smdk_hw_params(struct snd_pcm_substream *substream,
39         struct snd_pcm_hw_params *params)
40 {
41         struct snd_soc_pcm_runtime *rtd = substream->private_data;
42         struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
43         struct snd_soc_dai *codec_dai = rtd->codec_dai;
44         unsigned int pll_out;
45         int ret;
46
47         /* AIF1CLK should be >=3MHz for optimal performance */
48         if (params_format(params) == SNDRV_PCM_FORMAT_S24_LE)
49                 pll_out = params_rate(params) * 384;
50         else if (params_rate(params) == 8000 || params_rate(params) == 11025)
51                 pll_out = params_rate(params) * 512;
52         else
53                 pll_out = params_rate(params) * 256;
54
55         ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
56                                          | SND_SOC_DAIFMT_NB_NF
57                                          | SND_SOC_DAIFMT_CBM_CFM);
58         if (ret < 0)
59                 return ret;
60
61         ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S
62                                          | SND_SOC_DAIFMT_NB_NF
63                                          | SND_SOC_DAIFMT_CBM_CFM);
64         if (ret < 0)
65                 return ret;
66
67         ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL1, WM8994_FLL_SRC_MCLK1,
68                                         SMDK_WM8994_FREQ, pll_out);
69         if (ret < 0)
70                 return ret;
71
72         ret = snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_FLL1,
73                                         pll_out, SND_SOC_CLOCK_IN);
74         if (ret < 0)
75                 return ret;
76
77         return 0;
78 }
79
80 /*
81  * SMDK WM8994 DAI operations.
82  */
83 static struct snd_soc_ops smdk_ops = {
84         .hw_params = smdk_hw_params,
85 };
86
87 static int smdk_wm8994_init_paiftx(struct snd_soc_pcm_runtime *rtd)
88 {
89         struct snd_soc_codec *codec = rtd->codec;
90         struct snd_soc_dapm_context *dapm = &codec->dapm;
91
92         /* HeadPhone */
93         snd_soc_dapm_enable_pin(dapm, "HPOUT1R");
94         snd_soc_dapm_enable_pin(dapm, "HPOUT1L");
95
96         /* MicIn */
97         snd_soc_dapm_enable_pin(dapm, "IN1LN");
98         snd_soc_dapm_enable_pin(dapm, "IN1RN");
99
100         /* LineIn */
101         snd_soc_dapm_enable_pin(dapm, "IN2LN");
102         snd_soc_dapm_enable_pin(dapm, "IN2RN");
103
104         /* Other pins NC */
105         snd_soc_dapm_nc_pin(dapm, "HPOUT2P");
106         snd_soc_dapm_nc_pin(dapm, "HPOUT2N");
107         snd_soc_dapm_nc_pin(dapm, "SPKOUTLN");
108         snd_soc_dapm_nc_pin(dapm, "SPKOUTLP");
109         snd_soc_dapm_nc_pin(dapm, "SPKOUTRP");
110         snd_soc_dapm_nc_pin(dapm, "SPKOUTRN");
111         snd_soc_dapm_nc_pin(dapm, "LINEOUT1N");
112         snd_soc_dapm_nc_pin(dapm, "LINEOUT1P");
113         snd_soc_dapm_nc_pin(dapm, "LINEOUT2N");
114         snd_soc_dapm_nc_pin(dapm, "LINEOUT2P");
115         snd_soc_dapm_nc_pin(dapm, "IN1LP");
116         snd_soc_dapm_nc_pin(dapm, "IN2LP:VXRN");
117         snd_soc_dapm_nc_pin(dapm, "IN1RP");
118         snd_soc_dapm_nc_pin(dapm, "IN2RP:VXRP");
119
120         return 0;
121 }
122
123 static struct snd_soc_dai_link smdk_dai[] = {
124         { /* Primary DAI i/f */
125                 .name = "WM8994 AIF1",
126                 .stream_name = "Pri_Dai",
127                 .cpu_dai_name = "samsung-i2s.0",
128                 .codec_dai_name = "wm8994-aif1",
129                 .platform_name = "samsung-audio",
130                 .codec_name = "wm8994-codec",
131                 .init = smdk_wm8994_init_paiftx,
132                 .ops = &smdk_ops,
133         }, { /* Sec_Fifo Playback i/f */
134                 .name = "Sec_FIFO TX",
135                 .stream_name = "Sec_Dai",
136                 .cpu_dai_name = "samsung-i2s.4",
137                 .codec_dai_name = "wm8994-aif1",
138                 .platform_name = "samsung-audio",
139                 .codec_name = "wm8994-codec",
140                 .ops = &smdk_ops,
141         },
142 };
143
144 static struct snd_soc_card smdk = {
145         .name = "SMDK-I2S",
146         .dai_link = smdk_dai,
147         .num_links = ARRAY_SIZE(smdk_dai),
148 };
149
150 static struct platform_device *smdk_snd_device;
151
152 static int __init smdk_audio_init(void)
153 {
154         int ret;
155
156         smdk_snd_device = platform_device_alloc("soc-audio", -1);
157         if (!smdk_snd_device)
158                 return -ENOMEM;
159
160         platform_set_drvdata(smdk_snd_device, &smdk);
161
162         ret = platform_device_add(smdk_snd_device);
163         if (ret)
164                 platform_device_put(smdk_snd_device);
165
166         return ret;
167 }
168 module_init(smdk_audio_init);
169
170 static void __exit smdk_audio_exit(void)
171 {
172         platform_device_unregister(smdk_snd_device);
173 }
174 module_exit(smdk_audio_exit);
175
176 MODULE_DESCRIPTION("ALSA SoC SMDK WM8994");
177 MODULE_LICENSE("GPL");