1 /*
2 * intelmid_vm_control.c - Intel Sound card driver for MID
3 *
4 * Copyright (C) 2010 Intel Corp
5 * Authors: Vinod Koul <vinod.koul@intel.com>
6 *
7 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 2 of the License.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 *
22 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
23 *
24 * This file contains the control operations of msic vendors
25 */
26
27 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
28
29 #include <linux/pci.h>
30 #include <linux/file.h>
31 #include "intel_sst.h"
32 #include "intel_sst_ioctl.h"
33 #include "intelmid_snd_control.h"
34
msic_init_card(void)35 static int msic_init_card(void)
36 {
37 struct sc_reg_access sc_access[] = {
38 /* dmic configuration */
39 {0x241, 0x85, 0},
40 {0x242, 0x02, 0},
41 /* audio paths config */
42 {0x24C, 0x10, 0},
43 {0x24D, 0x32, 0},
44 /* PCM2 interface slots */
45 /* preconfigured slots for 0-5 both tx, rx */
46 {0x272, 0x10, 0},
47 {0x273, 0x32, 0},
48 {0x274, 0xFF, 0},
49 {0x275, 0x10, 0},
50 {0x276, 0x32, 0},
51 {0x277, 0x54, 0},
52 /*Sinc5 decimator*/
53 {0x24E, 0x28, 0},
54 /*TI vibra w/a settings*/
55 {0x384, 0x80, 0},
56 {0x385, 0x80, 0},
57 /*vibra settings*/
58 {0x267, 0x00, 0},
59 {0x26A, 0x10, 0},
60 {0x261, 0x00, 0},
61 {0x264, 0x10, 0},
62 /* pcm port setting */
63 {0x278, 0x00, 0},
64 {0x27B, 0x01, 0},
65 {0x27C, 0x0a, 0},
66 /* Set vol HSLRVOLCTRL, IHFVOL */
67 {0x259, 0x04, 0},
68 {0x25A, 0x04, 0},
69 {0x25B, 0x04, 0},
70 {0x25C, 0x04, 0},
71 /* HSEPRXCTRL Enable the headset left and right FIR filters */
72 {0x250, 0x30, 0},
73 /* HSMIXER */
74 {0x256, 0x11, 0},
75 /* amic configuration */
76 {0x249, 0x09, 0x0},
77 {0x24A, 0x09, 0x0},
78 /* unmask ocaudio/accdet interrupts */
79 {0x1d, 0x00, 0x00},
80 {0x1e, 0x00, 0x00},
81 };
82 snd_msic_ops.card_status = SND_CARD_INIT_DONE;
83 sst_sc_reg_access(sc_access, PMIC_WRITE, 30);
84 snd_msic_ops.pb_on = 0;
85 snd_msic_ops.cap_on = 0;
86 snd_msic_ops.input_dev_id = DMIC; /*def dev*/
87 snd_msic_ops.output_dev_id = STEREO_HEADPHONE;
88 pr_debug("msic init complete!!\n");
89 return 0;
90 }
91
msic_power_up_pb(unsigned int device)92 static int msic_power_up_pb(unsigned int device)
93 {
94 struct sc_reg_access sc_access1[] = {
95 /* turn on the audio power supplies */
96 {0x0DB, 0x05, 0},
97 /* VHSP */
98 {0x0DC, 0xFF, 0},
99 /* VHSN */
100 {0x0DD, 0x3F, 0},
101 /* turn on PLL */
102 {0x240, 0x21, 0},
103 };
104 struct sc_reg_access sc_access2[] = {
105 /* disable driver */
106 {0x25D, 0x0, 0x43},
107 /* DAC CONFIG ; both HP, LP on */
108 {0x257, 0x03, 0x03},
109 };
110 struct sc_reg_access sc_access3[] = {
111 /* HSEPRXCTRL Enable the headset left and right FIR filters */
112 {0x250, 0x30, 0},
113 /* HSMIXER */
114 {0x256, 0x11, 0},
115 };
116 struct sc_reg_access sc_access4[] = {
117 /* enable driver */
118 {0x25D, 0x3, 0x3},
119 /* unmute the headset */
120 { 0x259, 0x80, 0x80},
121 { 0x25A, 0x80, 0x80},
122 };
123 struct sc_reg_access sc_access_vihf[] = {
124 /* VIHF ON */
125 {0x0C9, 0x2D, 0x00},
126 };
127 struct sc_reg_access sc_access22[] = {
128 /* disable driver */
129 {0x25D, 0x00, 0x0C},
130 /*Filer DAC enable*/
131 {0x251, 0x03, 0x03},
132 {0x257, 0x0C, 0x0C},
133 };
134 struct sc_reg_access sc_access32[] = {
135 /*enable drv*/
136 {0x25D, 0x0C, 0x0c},
137 };
138 struct sc_reg_access sc_access42[] = {
139 /*unmute headset*/
140 {0x25B, 0x80, 0x80},
141 {0x25C, 0x80, 0x80},
142 };
143 struct sc_reg_access sc_access23[] = {
144 /* disable driver */
145 {0x25D, 0x0, 0x43},
146 /* DAC CONFIG ; both HP, LP on */
147 {0x257, 0x03, 0x03},
148 };
149 struct sc_reg_access sc_access43[] = {
150 /* enable driver */
151 {0x25D, 0x40, 0x40},
152 /* unmute the headset */
153 { 0x259, 0x80, 0x80},
154 { 0x25A, 0x80, 0x80},
155 };
156 struct sc_reg_access sc_access_vib[] = {
157 /* enable driver, ADC */
158 {0x25D, 0x10, 0x10},
159 {0x264, 0x02, 0x02},
160 };
161 struct sc_reg_access sc_access_hap[] = {
162 /* enable driver, ADC */
163 {0x25D, 0x20, 0x20},
164 {0x26A, 0x02, 0x02},
165 };
166 struct sc_reg_access sc_access_pcm2[] = {
167 /* enable pcm 2 */
168 {0x27C, 0x1, 0x1},
169 };
170 int retval = 0;
171
172 if (snd_msic_ops.card_status == SND_CARD_UN_INIT) {
173 retval = msic_init_card();
174 if (retval)
175 return retval;
176 }
177
178 pr_debug("powering up pb.... Device %d\n", device);
179 sst_sc_reg_access(sc_access1, PMIC_WRITE, 4);
180 switch (device) {
181 case SND_SST_DEVICE_HEADSET:
182 if (snd_msic_ops.output_dev_id == STEREO_HEADPHONE) {
183 sst_sc_reg_access(sc_access2, PMIC_READ_MODIFY, 2);
184 sst_sc_reg_access(sc_access3, PMIC_WRITE, 2);
185 sst_sc_reg_access(sc_access4, PMIC_READ_MODIFY, 3);
186 } else {
187 sst_sc_reg_access(sc_access23, PMIC_READ_MODIFY, 2);
188 sst_sc_reg_access(sc_access3, PMIC_WRITE, 2);
189 sst_sc_reg_access(sc_access43, PMIC_READ_MODIFY, 3);
190 }
191 snd_msic_ops.pb_on = 1;
192 break;
193
194 case SND_SST_DEVICE_IHF:
195 sst_sc_reg_access(sc_access_vihf, PMIC_WRITE, 1);
196 sst_sc_reg_access(sc_access22, PMIC_READ_MODIFY, 3);
197 sst_sc_reg_access(sc_access32, PMIC_READ_MODIFY, 1);
198 sst_sc_reg_access(sc_access42, PMIC_READ_MODIFY, 2);
199 break;
200
201 case SND_SST_DEVICE_VIBRA:
202 sst_sc_reg_access(sc_access_vib, PMIC_READ_MODIFY, 2);
203 break;
204
205 case SND_SST_DEVICE_HAPTIC:
206 sst_sc_reg_access(sc_access_hap, PMIC_READ_MODIFY, 2);
207 break;
208
209 default:
210 pr_warn("Wrong Device %d, selected %d\n",
211 device, snd_msic_ops.output_dev_id);
212 }
213 return sst_sc_reg_access(sc_access_pcm2, PMIC_READ_MODIFY, 1);
214 }
215
msic_power_up_cp(unsigned int device)216 static int msic_power_up_cp(unsigned int device)
217 {
218 struct sc_reg_access sc_access[] = {
219 /* turn on the audio power supplies */
220 {0x0DB, 0x05, 0},
221 /* VHSP */
222 {0x0DC, 0xFF, 0},
223 /* VHSN */
224 {0x0DD, 0x3F, 0},
225 /* turn on PLL */
226 {0x240, 0x21, 0},
227
228 /* Turn on DMIC supply */
229 {0x247, 0xA0, 0x0},
230 {0x240, 0x21, 0x0},
231 {0x24C, 0x10, 0x0},
232
233 /* mic demux enable */
234 {0x245, 0x3F, 0x0},
235 {0x246, 0x7, 0x0},
236
237 };
238 struct sc_reg_access sc_access_amic[] = {
239 /* turn on the audio power supplies */
240 {0x0DB, 0x05, 0},
241 /* VHSP */
242 {0x0DC, 0xFF, 0},
243 /* VHSN */
244 {0x0DD, 0x3F, 0},
245 /* turn on PLL */
246 {0x240, 0x21, 0},
247 /*ADC EN*/
248 {0x248, 0x05, 0x0},
249 {0x24C, 0x76, 0x0},
250 /*MIC EN*/
251 {0x249, 0x09, 0x0},
252 {0x24A, 0x09, 0x0},
253 /* Turn on AMIC supply */
254 {0x247, 0xFC, 0x0},
255
256 };
257 struct sc_reg_access sc_access2[] = {
258 /* enable pcm 2 */
259 {0x27C, 0x1, 0x1},
260 };
261 struct sc_reg_access sc_access3[] = {
262 /*wait for mic to stabalize before turning on audio channels*/
263 {0x24F, 0x3C, 0x0},
264 };
265 int retval = 0;
266
267 if (snd_msic_ops.card_status == SND_CARD_UN_INIT) {
268 retval = msic_init_card();
269 if (retval)
270 return retval;
271 }
272
273 pr_debug("powering up cp....%d\n", snd_msic_ops.input_dev_id);
274 sst_sc_reg_access(sc_access2, PMIC_READ_MODIFY, 1);
275 snd_msic_ops.cap_on = 1;
276 if (snd_msic_ops.input_dev_id == AMIC)
277 sst_sc_reg_access(sc_access_amic, PMIC_WRITE, 9);
278 else
279 sst_sc_reg_access(sc_access, PMIC_WRITE, 9);
280 return sst_sc_reg_access(sc_access3, PMIC_WRITE, 1);
281
282 }
283
msic_power_down(void)284 static int msic_power_down(void)
285 {
286 int retval = 0;
287
288 pr_debug("powering dn msic\n");
289 snd_msic_ops.pb_on = 0;
290 snd_msic_ops.cap_on = 0;
291 return retval;
292 }
293
msic_power_down_pb(void)294 static int msic_power_down_pb(void)
295 {
296 int retval = 0;
297
298 pr_debug("powering dn pb....\n");
299 snd_msic_ops.pb_on = 0;
300 return retval;
301 }
302
msic_power_down_cp(void)303 static int msic_power_down_cp(void)
304 {
305 int retval = 0;
306
307 pr_debug("powering dn cp....\n");
308 snd_msic_ops.cap_on = 0;
309 return retval;
310 }
311
msic_set_selected_output_dev(u8 value)312 static int msic_set_selected_output_dev(u8 value)
313 {
314 int retval = 0;
315
316 pr_debug("msic set selected output:%d\n", value);
317 snd_msic_ops.output_dev_id = value;
318 if (snd_msic_ops.pb_on)
319 msic_power_up_pb(SND_SST_DEVICE_HEADSET);
320 return retval;
321 }
322
msic_set_selected_input_dev(u8 value)323 static int msic_set_selected_input_dev(u8 value)
324 {
325
326 struct sc_reg_access sc_access_dmic[] = {
327 {0x24C, 0x10, 0x0},
328 };
329 struct sc_reg_access sc_access_amic[] = {
330 {0x24C, 0x76, 0x0},
331
332 };
333 int retval = 0;
334
335 pr_debug("msic_set_selected_input_dev:%d\n", value);
336 snd_msic_ops.input_dev_id = value;
337 switch (value) {
338 case AMIC:
339 pr_debug("Selecting AMIC1\n");
340 retval = sst_sc_reg_access(sc_access_amic, PMIC_WRITE, 1);
341 break;
342 case DMIC:
343 pr_debug("Selecting DMIC1\n");
344 retval = sst_sc_reg_access(sc_access_dmic, PMIC_WRITE, 1);
345 break;
346 default:
347 return -EINVAL;
348
349 }
350 if (snd_msic_ops.cap_on)
351 retval = msic_power_up_cp(SND_SST_DEVICE_CAPTURE);
352 return retval;
353 }
354
msic_set_pcm_voice_params(void)355 static int msic_set_pcm_voice_params(void)
356 {
357 return 0;
358 }
359
msic_set_pcm_audio_params(int sfreq,int word_size,int num_channel)360 static int msic_set_pcm_audio_params(int sfreq, int word_size, int num_channel)
361 {
362 return 0;
363 }
364
msic_set_audio_port(int status)365 static int msic_set_audio_port(int status)
366 {
367 return 0;
368 }
369
msic_set_voice_port(int status)370 static int msic_set_voice_port(int status)
371 {
372 return 0;
373 }
374
msic_set_mute(int dev_id,u8 value)375 static int msic_set_mute(int dev_id, u8 value)
376 {
377 return 0;
378 }
379
msic_set_vol(int dev_id,int value)380 static int msic_set_vol(int dev_id, int value)
381 {
382 return 0;
383 }
384
msic_get_mute(int dev_id,u8 * value)385 static int msic_get_mute(int dev_id, u8 *value)
386 {
387 return 0;
388 }
389
msic_get_vol(int dev_id,int * value)390 static int msic_get_vol(int dev_id, int *value)
391 {
392 return 0;
393 }
394
395 struct snd_pmic_ops snd_msic_ops = {
396 .set_input_dev = msic_set_selected_input_dev,
397 .set_output_dev = msic_set_selected_output_dev,
398 .set_mute = msic_set_mute,
399 .get_mute = msic_get_mute,
400 .set_vol = msic_set_vol,
401 .get_vol = msic_get_vol,
402 .init_card = msic_init_card,
403 .set_pcm_audio_params = msic_set_pcm_audio_params,
404 .set_pcm_voice_params = msic_set_pcm_voice_params,
405 .set_voice_port = msic_set_voice_port,
406 .set_audio_port = msic_set_audio_port,
407 .power_up_pmic_pb = msic_power_up_pb,
408 .power_up_pmic_cp = msic_power_up_cp,
409 .power_down_pmic_pb = msic_power_down_pb,
410 .power_down_pmic_cp = msic_power_down_cp,
411 .power_down_pmic = msic_power_down,
412 };
413