upload tizen1.0 source
[kernel/linux-2.6.36.git] / sound / soc / s3c24xx / mc1n2_path.h
1 /*
2  * sound/soc/s3c24xx/mc1n2_path.h
3  */
4 #include <linux/slab.h>
5
6 #define DAPM_OFF                        0
7 #define DAPM_ON                         1
8
9 #define CODEC_START                     21
10 #define CODEC_END                       22
11 #define MICBIAS                         23
12
13 #define TO_NONE                         0
14 #define CODEC_TO_SPEAKER                1
15 #define CODEC_TO_HEADPHONE              2
16 #define CODEC_TO_RECEIVER               3
17 #define CAPTURE_FROM_MAIN_MIC           4
18
19 struct mode_ctl_list{
20         char name[35];
21         unsigned int state1;
22         unsigned int state2;
23 };
24
25
26 #if defined(CONFIG_SND_S5PC210_SOC_FRASER_MC1N2_YAMAHA) \
27         || defined(CONFIG_SND_S5PC210_SOC_SLP7_SLP10_MC1N2)     \
28         || defined(CONFIG_SND_S5PC210_SOC_C1_MC1N2)     \
29         || defined(CONFIG_SND_S5PC210_SOC_U1_U1HD_MC1N2)
30
31 /* Enable/Disable the power of codec */
32 #define ENABLE_CODEC                    "Enable Codec"
33 #define DISABLE_CODEC                   "Disable Codec"
34
35 /* Playback controls*/
36 #define DAC_PLAYBACK_SWITCH             "DAC Playback Switch"
37 #define DACMAIN_SRC                     "DACMAIN SRC"
38 #define DACVOICE_SRC                    "DACVOICE SRC"
39 #define DIGITAL_MIXER_DIR0_SWITCH       "DIGITAL MIXER Dir0 Switch"
40 #define DIR0_ATT_SWITCH                 "DIR#0 ATT Switch"
41 #define DIR0_SWITCH                     "DIR#0 Switch"
42 #define SPL_DAC_MIXMODE                 "SPL DAC MIXMODE"
43 #define SPL_MIXER_DAC_SWITCH            "SPL MIXER Dac Switch"
44 #define SPR_DAC_MIXMODE                 "SPR DAC MIXMODE"
45 #define SPR_MIXER_DAC_SWITCH            "SPR MIXER Dac Switch"
46 #define SPEAKER_PLAYBACK_SWITCH         "Speaker Playback Switch"
47 #define VOICE_PLAYBACK_SWITCH           "Voice Playback Switch"
48
49 #define MASTER_PLAYBACK_SWITCH          "Master Playback Switch"
50 #define MASTER_PLAYBACK_VOLUME          "Master Playback Volume"
51 #define DAC_PLAYBACK_SWITCH             "DAC Playback Switch"
52 #define DAC_PLAYBACK_VOLUME             "DAC Playback Volume"
53 #define DIR0_ATT_VOLUME                 "DIR#0 ATT Volume"
54 #define DIR0_VOLUME                     "DIR#0 Volume"
55 #define SPEAKER_PLAYBACK_VOLUME         "Speaker Playback Volume"
56 #define VOICE_PLAYBACK_VOLUME           "Voice Playback Volume"
57
58 #define DACMAIN_SRC                     "DACMAIN SRC"
59 #define DIGITAL_MIXER_DIR1_SWITCH       "DIGITAL MIXER Dir1 Switch"
60 #define DIR1_ATT_SWITCH                 "DIR#1 ATT Switch"
61 #define DIR1_SWITCH                     "DIR#1 Switch"
62 #define DIR1_ATT_VOLUME                 "DIR#1 ATT Volume"
63 #define DIR1_VOLUME                     "DIR#1 Volume"
64
65 /* Capture 
66  * - DIT0 (mainmci_to_ap, mainmic_to_ap_gain)
67  * - DIT1 (mainmic_to_cp, mainmic_to_cp_gain)
68  */
69 #define MB1_SWITCH                      "MB1 Switch"
70 #define MB2_SWITCH                      "MB2 Switch"
71 #define MB3_SWITCH                      "MB3 Switch"
72 #define ADCL_MIXER_MIC1_SWITCH          "ADCL MIXER Mic1 Switch"
73 #define ADCR_MIXER_MIC1_SWITCH          "ADCR MIXER Mic1 Switch"
74 #define ADC_PDM_SEL                     "ADC PDM SEL"
75
76 #define MIC_1_GAIN_VOLUME               "Mic 1 Gain Volume"
77 #define AD_ATT_SWITCH                   "AD ATT Switch"
78 #define AD_ATT_VOLUME                   "AD ATT Volume"
79 #define AD_ANALOG_SWITCH                "AD Analog Switch"
80 #define AD_ANALOG_VOLUME                "AD Analog Volume"
81 #define AD_DIGITAL_SWITCH               "AD Digital Switch"
82 #define AD_DIGITAL_VOLUME               "AD Digital Volume"
83 #define AE_SRC                          "AE SRC"
84 #define AENG6_SWITCH                    "AENG6 Switch"
85 #define AENG6_VOLUME                    "AENG6 Volume"
86
87 #define DIT0_SRC                        "DIT0 SRC"
88 #define DIT0_CAPTURE_SWITCH             "DIT#0 Capture Switch"
89 #define DIT0_CAPTURE_VOLUME             "DIT#0 Capture Volume"
90
91 #define DIT1_SRC                        "DIT1 SRC"
92 #define DIT1_CAPTURE_SWITCH             "DIT#1 Capture Switch"
93 #define DIT1_CAPTURE_VOLUME             "DIT#1 Capture Volume"
94
95 static struct mode_ctl_list start_stereo_ctl_list[] = {
96         {ENABLE_CODEC, DAPM_ON, DAPM_ON},
97         /* Playback to Speaker
98          * - DIR0 (ap_to_speaker, ap_to_speaker_gain) : Music playback
99          * - DIR1 (cp_to_speaker, cp_to_speaker_gain) : Voice-call
100          */
101         {SPL_DAC_MIXMODE, DAPM_ON, DAPM_ON},
102         {SPR_DAC_MIXMODE, DAPM_ON, DAPM_ON},
103         {SPEAKER_PLAYBACK_SWITCH, DAPM_ON, DAPM_ON},
104         {VOICE_PLAYBACK_SWITCH, DAPM_ON, DAPM_ON},
105         {MASTER_PLAYBACK_SWITCH, DAPM_ON, DAPM_ON},
106         {DAC_PLAYBACK_SWITCH, DAPM_ON, DAPM_ON},
107         {SPL_MIXER_DAC_SWITCH, DAPM_ON, DAPM_ON},
108         {SPR_MIXER_DAC_SWITCH, DAPM_ON, DAPM_ON},
109
110         {MASTER_PLAYBACK_VOLUME, 80, 80},
111         {DAC_PLAYBACK_VOLUME, 70, 70},
112         {SPEAKER_PLAYBACK_VOLUME, 31, 31},
113         {VOICE_PLAYBACK_VOLUME, 70, 70},
114
115         {DACMAIN_SRC, 5, 5},    /* MIXER */
116         {DIGITAL_MIXER_DIR0_SWITCH, DAPM_ON, DAPM_ON},
117         {DIR0_ATT_SWITCH, DAPM_ON, DAPM_ON},
118         {DIR0_SWITCH, DAPM_ON, DAPM_ON},
119         {DIR0_ATT_VOLUME, 70, 70},
120         {DIR0_VOLUME, 70, 70},
121
122         {DACVOICE_SRC, 3, 3},   /* DIR0 */
123         {DIGITAL_MIXER_DIR1_SWITCH, DAPM_ON, DAPM_ON},
124         {DIR1_ATT_SWITCH, DAPM_ON, DAPM_ON},
125         {DIR1_SWITCH, DAPM_ON, DAPM_ON},
126         {DIR1_ATT_VOLUME, 70,70},
127         {DIR1_VOLUME, 70, 70},
128
129
130         /* Capture from Mainmic
131          * - DIT0 (mainmic_to_ap, mainmic_to_ap_gain) : Voice recording
132          * - DIT1 (mainmic_to_cp, mainmic_to_cp_gain) : Voice-call
133          */
134         {MB1_SWITCH, DAPM_ON, DAPM_ON},
135         {ADCL_MIXER_MIC1_SWITCH, DAPM_ON, DAPM_ON},
136         {ADCR_MIXER_MIC1_SWITCH, DAPM_ON, DAPM_ON},
137         {ADC_PDM_SEL, 0, 0},
138         {MIC_1_GAIN_VOLUME, 3, 3},
139         {AD_ATT_SWITCH, DAPM_ON, DAPM_ON},
140         {AD_ATT_VOLUME, 70, 70},
141         {AD_ANALOG_SWITCH, DAPM_ON, DAPM_ON},
142         {AD_ANALOG_VOLUME, 31, 31},
143         {AD_DIGITAL_SWITCH, DAPM_ON, DAPM_ON},
144         {AD_DIGITAL_VOLUME, 80, 80},
145         {AE_SRC, 1, 1},
146         {AENG6_SWITCH, DAPM_ON, DAPM_ON},
147         {AENG6_VOLUME, 70, 70},
148
149         {DIT0_SRC, 1, 1},
150         {DIT0_CAPTURE_SWITCH, DAPM_ON, DAPM_ON},
151         {DIT0_CAPTURE_VOLUME, 70, 70},
152
153         {DIT1_SRC, 1, 1},
154         {DIT1_CAPTURE_SWITCH, DAPM_ON, DAPM_ON},
155         {DIT1_CAPTURE_VOLUME, 70, 70},
156
157         {DISABLE_CODEC, DAPM_OFF, DAPM_OFF},
158 };
159 #endif
160
161
162 #ifdef CONFIG_SND_S5PC210_SOC_FRASER_MC1N2
163
164 #define DACMAIN_SRC_MUX "DACMAIN SRC Mux"
165 #define DACVOICE_SRC_MUX "DACVOICE SRC Mux"
166 #define SPL_MIXER_DACL_SWITCH "SPL Mixer DACL Switch"
167 #define SPR_MIXER_DACR_SWITCH "SPR Mixer DACR Switch"
168
169 #define MASTER_PLAYBACK_VOLUME "Master Playback Volume"
170 #define DAC_PLAYBACK_VOLUME "DAC Playback Volume"
171 #define DIR0_VOLUME "DIR#0 Volume"
172 #define DIR0_ATT_VOLUME "DIR#0 ATT Volume"
173 #define SPEAKER_PLAYBACK_VOLUME "Speaker Playback Volume"
174 #define VOICE_PLAYBACK_VOLUME "Voice Playback Volume"
175
176 #define ADCL_MIXER_MIC1_SWITCH "ADCL Mixer MIC1 Switch"
177 #define ADCR_MIXER_MIC1_SWITCH "ADCR Mixer MIC1 Switch"
178 #define AENG6_SRC_MUX "AENG6 SRC Mux"
179 #define DIT0_SRC_MUX "DIT0 SRC Mux"
180 #define MBS1_SWITCH "MBS1 Switch"
181
182 #define MIC1_GAIN_VOLUME "Mic1 Gain Volume"
183 #define AD_ATT_VOLUME "AD ATT Volume"
184 #define AD_ANALOG_VOLUME "AD Analog Volume"
185 #define AD_DIGITAL_VOLUME "AD Digital Volume"
186 #define AENG6_VOLUME "AENG6 Volume"
187 #define DIT0_CAPTURE_VOLUME "DIT#0 Capture Volume"
188
189 static struct mode_ctl_list start_stereo_ctl_list[] = {
190         {DACMAIN_SRC_MUX, 3, 3},
191         {DACVOICE_SRC_MUX, 3, 3},
192         {SPL_MIXER_DACL_SWITCH, DAPM_ON, DAPM_ON},
193         {SPR_MIXER_DACR_SWITCH, DAPM_ON, DAPM_ON},
194
195         {MASTER_PLAYBACK_VOLUME, 93, 93},
196         {DAC_PLAYBACK_VOLUME, 93, 93},
197         {DIR0_VOLUME, 93, 93},
198         {DIR0_ATT_VOLUME, 93, 93},
199         {SPEAKER_PLAYBACK_VOLUME, 31, 31},
200         {VOICE_PLAYBACK_VOLUME, 80, 80},
201
202         {ADCL_MIXER_MIC1_SWITCH, DAPM_ON, DAPM_ON},
203         {ADCR_MIXER_MIC1_SWITCH, DAPM_ON, DAPM_ON},
204         {AENG6_SRC_MUX, 0, 0},
205         {DIT0_SRC_MUX, 1, 1},
206         {MBS1_SWITCH, DAPM_ON, DAPM_ON},
207
208         {MIC1_GAIN_VOLUME, 3, 3},
209         {AD_ATT_VOLUME, 93, 93},
210         {AD_ANALOG_VOLUME, 31, 31},
211         {AD_DIGITAL_VOLUME, 93, 93},
212         {AENG6_VOLUME, 93, 93},
213         {DIT0_CAPTURE_VOLUME, 93, 93},
214 };
215 #endif
216
217 static struct mode_ctl_list end_ctl_list[] = {
218 };
219
220 /* CODEC_TO_SPEAKER */
221 static struct mode_ctl_list spk_ctl_list[] = {
222 };
223
224 static struct snd_kcontrol *snd_ctl_find_name(struct snd_card *card, char *name)
225 {
226         struct snd_kcontrol *kctl;
227
228         list_for_each_entry(kctl, &card->controls, list) {
229                 if (!strcmp(kctl->id.name, name))
230                         return kctl;
231         }
232         return NULL;
233 }
234
235 static inline int set_sound_path(struct snd_soc_codec *codec, unsigned int mode,
236                 unsigned int invert)
237 {
238         struct snd_kcontrol *kctl;
239         struct snd_ctl_elem_value *uctl;
240         struct mode_ctl_list *ctl_list = NULL;
241         int i, ctl_list_size = 0;
242
243         uctl = kzalloc(sizeof(struct snd_ctl_elem_value), GFP_KERNEL);
244
245         switch (mode) {
246         case CODEC_START:
247                 ctl_list = start_stereo_ctl_list;
248                 ctl_list_size = ARRAY_SIZE(start_stereo_ctl_list);
249                 break;
250         case CODEC_END:
251                 ctl_list = end_ctl_list;
252                 ctl_list_size = ARRAY_SIZE(end_ctl_list);
253                 break;
254
255         /* Disable internal path */
256         case TO_NONE:
257                 set_sound_path(codec, CODEC_TO_SPEAKER, DAPM_OFF);
258                 break;
259
260         /* Enable internal path */
261         /* - Playback */
262         case CODEC_TO_SPEAKER:
263                 ctl_list = spk_ctl_list;
264                 ctl_list_size = ARRAY_SIZE(spk_ctl_list);
265                 break;
266
267         default:
268                 return -EINVAL;
269         }
270
271         if (ctl_list == NULL)
272                 return -EINVAL;
273
274         for (i = 0 ; i < ctl_list_size ; i++) {
275                 /* Invert */
276                 if ((invert == DAPM_OFF) && (mode != CODEC_START) &&
277                                 (mode != CODEC_END)) {
278                         uctl->value.integer.value[0] = ~(ctl_list[i].state1);
279                         uctl->value.integer.value[1] = ~(ctl_list[i].state2);
280                 /* Normal */
281                 } else {
282                         uctl->value.integer.value[0] = ctl_list[i].state1;
283                         uctl->value.integer.value[1] = ctl_list[i].state2;
284                 }
285
286                 kctl = snd_ctl_find_name(codec->card, ctl_list[i].name);
287                 kctl->put(kctl, uctl);
288         }
289
290         kfree(uctl);
291
292         return 1;
293 }