CHROMIUM: ASoC: samsung: don't configure smdk audio everywhere
[cascardo/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 #include <linux/module.h>
13 #include <linux/of.h>
14
15  /*
16   * Default CFG switch settings to use this driver:
17   *     SMDKV310: CFG5-1000, CFG7-111111
18   */
19
20  /*
21   * Configure audio route as :-
22   * $ amixer sset 'DAC1' on,on
23   * $ amixer sset 'Right Headphone Mux' 'DAC'
24   * $ amixer sset 'Left Headphone Mux' 'DAC'
25   * $ amixer sset 'DAC1R Mixer AIF1.1' on
26   * $ amixer sset 'DAC1L Mixer AIF1.1' on
27   * $ amixer sset 'IN2L' on
28   * $ amixer sset 'IN2L PGA IN2LN' on
29   * $ amixer sset 'MIXINL IN2L' on
30   * $ amixer sset 'AIF1ADC1L Mixer ADC/DMIC' on
31   * $ amixer sset 'IN2R' on
32   * $ amixer sset 'IN2R PGA IN2RN' on
33   * $ amixer sset 'MIXINR IN2R' on
34   * $ amixer sset 'AIF1ADC1R Mixer ADC/DMIC' on
35   */
36
37 /* SMDK has a 16.934MHZ crystal attached to WM8994 */
38 #define SMDK_WM8994_FREQ 16934000
39
40 static int smdk_hw_params(struct snd_pcm_substream *substream,
41         struct snd_pcm_hw_params *params)
42 {
43         struct snd_soc_pcm_runtime *rtd = substream->private_data;
44         struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
45         struct snd_soc_dai *codec_dai = rtd->codec_dai;
46         unsigned int pll_out;
47         int ret;
48
49         /* AIF1CLK should be >=3MHz for optimal performance */
50         if (params_format(params) == SNDRV_PCM_FORMAT_S24_LE)
51                 pll_out = params_rate(params) * 384;
52         else if (params_rate(params) == 8000 || params_rate(params) == 11025)
53                 pll_out = params_rate(params) * 512;
54         else
55                 pll_out = params_rate(params) * 256;
56
57         ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
58                                          | SND_SOC_DAIFMT_NB_NF
59                                          | SND_SOC_DAIFMT_CBM_CFM);
60         if (ret < 0)
61                 return ret;
62
63         ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S
64                                          | SND_SOC_DAIFMT_NB_NF
65                                          | SND_SOC_DAIFMT_CBM_CFM);
66         if (ret < 0)
67                 return ret;
68
69         ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL1, WM8994_FLL_SRC_MCLK1,
70                                         SMDK_WM8994_FREQ, pll_out);
71         if (ret < 0)
72                 return ret;
73
74         ret = snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_FLL1,
75                                         pll_out, SND_SOC_CLOCK_IN);
76         if (ret < 0)
77                 return ret;
78
79         return 0;
80 }
81
82 /*
83  * SMDK WM8994 DAI operations.
84  */
85 static struct snd_soc_ops smdk_ops = {
86         .hw_params = smdk_hw_params,
87 };
88
89 static int smdk_wm8994_init_paiftx(struct snd_soc_pcm_runtime *rtd)
90 {
91         struct snd_soc_codec *codec = rtd->codec;
92         struct snd_soc_dapm_context *dapm = &codec->dapm;
93
94         /* HeadPhone */
95         snd_soc_dapm_enable_pin(dapm, "HPOUT1R");
96         snd_soc_dapm_enable_pin(dapm, "HPOUT1L");
97
98         /* MicIn */
99         snd_soc_dapm_enable_pin(dapm, "IN1LN");
100         snd_soc_dapm_enable_pin(dapm, "IN1RN");
101
102         /* LineIn */
103         snd_soc_dapm_enable_pin(dapm, "IN2LN");
104         snd_soc_dapm_enable_pin(dapm, "IN2RN");
105
106         /* Other pins NC */
107         snd_soc_dapm_nc_pin(dapm, "HPOUT2P");
108         snd_soc_dapm_nc_pin(dapm, "HPOUT2N");
109         snd_soc_dapm_nc_pin(dapm, "SPKOUTLN");
110         snd_soc_dapm_nc_pin(dapm, "SPKOUTLP");
111         snd_soc_dapm_nc_pin(dapm, "SPKOUTRP");
112         snd_soc_dapm_nc_pin(dapm, "SPKOUTRN");
113         snd_soc_dapm_nc_pin(dapm, "LINEOUT1N");
114         snd_soc_dapm_nc_pin(dapm, "LINEOUT1P");
115         snd_soc_dapm_nc_pin(dapm, "LINEOUT2N");
116         snd_soc_dapm_nc_pin(dapm, "LINEOUT2P");
117         snd_soc_dapm_nc_pin(dapm, "IN1LP");
118         snd_soc_dapm_nc_pin(dapm, "IN2LP:VXRN");
119         snd_soc_dapm_nc_pin(dapm, "IN1RP");
120         snd_soc_dapm_nc_pin(dapm, "IN2RP:VXRP");
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         .owner = THIS_MODULE,
149         .dai_link = smdk_dai,
150         .num_links = ARRAY_SIZE(smdk_dai),
151 };
152
153 static struct platform_device *smdk_snd_device;
154
155 static int __init smdk_audio_init(void)
156 {
157         int ret;
158
159         if (!of_machine_is_compatible("samsung,smdk5250"))
160                 return -ENODEV;
161
162         smdk_snd_device = platform_device_alloc("soc-audio", -1);
163         if (!smdk_snd_device)
164                 return -ENOMEM;
165
166         platform_set_drvdata(smdk_snd_device, &smdk);
167
168         ret = platform_device_add(smdk_snd_device);
169         if (ret)
170                 platform_device_put(smdk_snd_device);
171
172         return ret;
173 }
174 module_init(smdk_audio_init);
175
176 static void __exit smdk_audio_exit(void)
177 {
178         platform_device_unregister(smdk_snd_device);
179 }
180 module_exit(smdk_audio_exit);
181
182 MODULE_DESCRIPTION("ALSA SoC SMDK WM8994");
183 MODULE_LICENSE("GPL");