Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/lethal/fbdev...
[deliverable/linux.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 snd_soc_dapm_sync(dapm);
121
122 return 0;
123 }
124
125 static struct snd_soc_dai_link smdk_dai[] = {
126 { /* Primary DAI i/f */
127 .name = "WM8994 AIF1",
128 .stream_name = "Pri_Dai",
129 .cpu_dai_name = "samsung-i2s.0",
130 .codec_dai_name = "wm8994-aif1",
131 .platform_name = "samsung-audio",
132 .codec_name = "wm8994-codec",
133 .init = smdk_wm8994_init_paiftx,
134 .ops = &smdk_ops,
135 }, { /* Sec_Fifo Playback i/f */
136 .name = "Sec_FIFO TX",
137 .stream_name = "Sec_Dai",
138 .cpu_dai_name = "samsung-i2s.4",
139 .codec_dai_name = "wm8994-aif1",
140 .platform_name = "samsung-audio",
141 .codec_name = "wm8994-codec",
142 .ops = &smdk_ops,
143 },
144 };
145
146 static struct snd_soc_card smdk = {
147 .name = "SMDK-I2S",
148 .dai_link = smdk_dai,
149 .num_links = ARRAY_SIZE(smdk_dai),
150 };
151
152 static struct platform_device *smdk_snd_device;
153
154 static int __init smdk_audio_init(void)
155 {
156 int ret;
157
158 smdk_snd_device = platform_device_alloc("soc-audio", -1);
159 if (!smdk_snd_device)
160 return -ENOMEM;
161
162 platform_set_drvdata(smdk_snd_device, &smdk);
163
164 ret = platform_device_add(smdk_snd_device);
165 if (ret)
166 platform_device_put(smdk_snd_device);
167
168 return ret;
169 }
170 module_init(smdk_audio_init);
171
172 static void __exit smdk_audio_exit(void)
173 {
174 platform_device_unregister(smdk_snd_device);
175 }
176 module_exit(smdk_audio_exit);
177
178 MODULE_DESCRIPTION("ALSA SoC SMDK WM8994");
179 MODULE_LICENSE("GPL");
This page took 0.046212 seconds and 6 git commands to generate.