aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging/intel_sst/intelmid_msic_control.c
blob: 10073c5b5f644f7ed05cd5287c2ba753e378da76 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
/*
 *  intelmid_vm_control.c - Intel Sound card driver for MID
 *
 *  Copyright (C) 2010 Intel Corp
 *  Authors:	Vinod Koul <vinod.koul@intel.com>
 *
 *  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; version 2 of the License.
 *
 *  This program is distributed in the hope that it will be useful, but
 *  WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
 *
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 *
 * This file contains the control operations of msic vendors
 */

#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

#include <linux/pci.h>
#include <linux/file.h>
#include <linux/delay.h>
#include "intel_sst.h"
#include "intelmid_snd_control.h"

static int msic_init_card(void)
{
	struct sc_reg_access sc_access[] = {
		/* dmic configuration */
		{0x241, 0x85, 0},
		{0x242, 0x02, 0},
		/* audio paths config */
		{0x24C, 0x10, 0},
		{0x24D, 0x32, 0},
		/* PCM2 interface slots */
		/* preconfigured slots for 0-5 both tx, rx */
		{0x272, 0x10, 0},
		{0x273, 0x32, 0},
		{0x274, 0xFF, 0},
		{0x275, 0x10, 0},
		{0x276, 0x32, 0},
		{0x277, 0x54, 0},
		/*Sinc5 decimator*/
		{0x24E, 0x28, 0},
		/*TI vibra w/a settings*/
		{0x384, 0x80, 0},
		{0x385, 0x80, 0},
		{0x267, 0x00, 0},
		{0x261, 0x00, 0},
		/* pcm port setting */
		{0x278, 0x00, 0},
		{0x27B, 0x01, 0},
		{0x27C, 0x0a, 0},
		/* Set vol HSLRVOLCTRL, IHFVOL */
		{0x259, 0x08, 0},
		{0x25A, 0x08, 0},
		{0x25B, 0x08, 0},
		{0x25C, 0x08, 0},
		/* HSEPRXCTRL  Enable the headset left and right FIR filters  */
		{0x250, 0x30, 0},
		/* HSMIXER */
		{0x256, 0x11, 0},
		/* amic configuration */
		{0x249, 0x01, 0x0},
		{0x24A, 0x01, 0x0},
		/* unmask ocaudio/accdet interrupts */
		{0x1d, 0x00, 0x00},
		{0x1e, 0x00, 0x00},
	};
	snd_msic_ops.card_status = SND_CARD_INIT_DONE;
	sst_sc_reg_access(sc_access, PMIC_WRITE, 28);
	snd_msic_ops.pb_on = 0;
	snd_msic_ops.pbhs_on = 0;
	snd_msic_ops.cap_on = 0;
	snd_msic_ops.input_dev_id = DMIC; /*def dev*/
	snd_msic_ops.output_dev_id = STEREO_HEADPHONE;
	pr_debug("msic init complete!!\n");
	return 0;
}
static int msic_line_out_restore(u8 value)
{
	struct sc_reg_access hs_drv_en[] = {
		{0x25d, 0x03, 0x03},
	};
	struct sc_reg_access ep_drv_en[] = {
		{0x25d, 0x40, 0x40},
	};
	struct sc_reg_access ihf_drv_en[] = {
		{0x25d, 0x0c, 0x0c},
	};
	struct sc_reg_access vib1_drv_en[] = {
		{0x25d, 0x10, 0x10},
	};
	struct sc_reg_access vib2_drv_en[] = {
		{0x25d, 0x20, 0x20},
	};
	int retval = 0;

	pr_debug("msic_lineout_restore_lineout_dev:%d\n", value);

	switch (value) {
	case HEADSET:
		pr_debug("Selecting Lineout-HEADSET-restore\n");
		if (snd_msic_ops.output_dev_id == STEREO_HEADPHONE)
			retval = sst_sc_reg_access(hs_drv_en,
							PMIC_READ_MODIFY, 1);
		else
			retval = sst_sc_reg_access(ep_drv_en,
							PMIC_READ_MODIFY, 1);
		break;
	case IHF:
		pr_debug("Selecting Lineout-IHF-restore\n");
		retval = sst_sc_reg_access(ihf_drv_en, PMIC_READ_MODIFY, 1);
		break;
	case VIBRA1:
		pr_debug("Selecting Lineout-Vibra1-restore\n");
		retval = sst_sc_reg_access(vib1_drv_en, PMIC_READ_MODIFY, 1);
		break;
	case VIBRA2:
		pr_debug("Selecting Lineout-VIBRA2-restore\n");
		retval = sst_sc_reg_access(vib2_drv_en, PMIC_READ_MODIFY, 1);
		break;
	case NONE:
		pr_debug("Selecting Lineout-NONE-restore\n");
		break;
	default:
		return -EINVAL;
	}
	return retval;
}
static int msic_get_lineout_prvstate(void)
{
	struct sc_reg_access hs_ihf_drv[2] = {
		{0x257, 0x0, 0x0},
		{0x25d, 0x0, 0x0},
	};
	struct sc_reg_access vib1drv[2] = {
		{0x264, 0x0, 0x0},
		{0x25D, 0x0, 0x0},
	};
	struct sc_reg_access vib2drv[2] = {
		{0x26A, 0x0, 0x0},
		{0x25D, 0x0, 0x0},
	};
	int retval = 0, drv_en, dac_en, dev_id, mask;
	for (dev_id = 0; dev_id < snd_msic_ops.line_out_names_cnt; dev_id++) {
		switch (dev_id) {
		case HEADSET:
			pr_debug("msic_get_lineout_prvs_state: HEADSET\n");
			sst_sc_reg_access(hs_ihf_drv, PMIC_READ, 2);

			mask = (MASK0|MASK1);
			dac_en = (hs_ihf_drv[0].value) & mask;

			mask = ((MASK0|MASK1)|MASK6);
			drv_en = (hs_ihf_drv[1].value) & mask;

			if (dac_en && (!drv_en)) {
				snd_msic_ops.prev_lineout_dev_id = HEADSET;
				return retval;
			}
			break;
		case IHF:
			pr_debug("msic_get_lineout_prvstate: IHF\n");
			sst_sc_reg_access(hs_ihf_drv, PMIC_READ, 2);

			mask = (MASK2 | MASK3);
			dac_en = (hs_ihf_drv[0].value) & mask;

			mask = (MASK2 | MASK3);
			drv_en = (hs_ihf_drv[1].value) & mask;

			if (dac_en && (!drv_en)) {
				snd_msic_ops.prev_lineout_dev_id = IHF;
				return retval;
			}
			break;
		case VIBRA1:
			pr_debug("msic_get_lineout_prvstate: vibra1\n");
			sst_sc_reg_access(vib1drv, PMIC_READ, 2);

			mask = MASK1;
			dac_en = (vib1drv[0].value) & mask;

			mask = MASK4;
			drv_en = (vib1drv[1].value) & mask;

			if (dac_en && (!drv_en)) {
				snd_msic_ops.prev_lineout_dev_id = VIBRA1;
				return retval;
			}
			break;
		case VIBRA2:
			pr_debug("msic_get_lineout_prvstate: vibra2\n");
			sst_sc_reg_access(vib2drv, PMIC_READ, 2);

			mask = MASK1;
			dac_en = (vib2drv[0].value) & mask;

			mask = MASK5;
			drv_en = ((vib2drv[1].value) & mask);

			if (dac_en && (!drv_en)) {
				snd_msic_ops.prev_lineout_dev_id = VIBRA2;
				return retval;
			}
			break;
		case NONE:
			pr_debug("msic_get_lineout_prvstate: NONE\n");
			snd_msic_ops.prev_lineout_dev_id = NONE;
			return retval;
		default:
			pr_debug("Invalid device id\n");
			snd_msic_ops.prev_lineout_dev_id = NONE;
			return -EINVAL;
		}
	}
	return retval;
}
static int msic_set_selected_lineout_dev(u8 value)
{
	struct sc_reg_access lout_hs[] = {
		{0x25e, 0x33, 0xFF},
		{0x25d, 0x0, 0x43},
	};
	struct sc_reg_access lout_ihf[] = {
		{0x25e, 0x55, 0xff},
		{0x25d, 0x0, 0x0c},
	};
	struct sc_reg_access lout_vibra1[] = {

		{0x25e, 0x61, 0xff},
		{0x25d, 0x0, 0x10},
	};
	struct sc_reg_access lout_vibra2[] = {

		{0x25e, 0x16, 0xff},
		{0x25d, 0x0, 0x20},
	};
	struct sc_reg_access lout_def[] = {
		{0x25e, 0x66, 0x0},
	};
	int retval = 0;

	pr_debug("msic_set_selected_lineout_dev:%d\n", value);
	msic_get_lineout_prvstate();
	msic_line_out_restore(snd_msic_ops.prev_lineout_dev_id);
	snd_msic_ops.lineout_dev_id = value;

	switch (value) {
	case HEADSET:
		pr_debug("Selecting Lineout-HEADSET\n");
		if (snd_msic_ops.pb_on)
			retval = sst_sc_reg_access(lout_hs,
					PMIC_READ_MODIFY, 2);
		break;
	case IHF:
		pr_debug("Selecting Lineout-IHF\n");
		if (snd_msic_ops.pb_on)
			retval = sst_sc_reg_access(lout_ihf,
							PMIC_READ_MODIFY, 2);
		break;
	case VIBRA1:
		pr_debug("Selecting Lineout-Vibra1\n");
		if (snd_msic_ops.pb_on)
			retval = sst_sc_reg_access(lout_vibra1,
							PMIC_READ_MODIFY, 2);
		break;
	case VIBRA2:
		pr_debug("Selecting Lineout-VIBRA2\n");
		if (snd_msic_ops.pb_on)
			retval = sst_sc_reg_access(lout_vibra2,
							PMIC_READ_MODIFY, 2);
		break;
	case NONE:
		pr_debug("Selecting Lineout-NONE\n");
			retval = sst_sc_reg_access(lout_def,
							PMIC_WRITE, 1);
		break;
	default:
		return -EINVAL;
	}
	return retval;
}


static int msic_power_up_pb(unsigned int device)
{
	struct sc_reg_access vaud[] = {
		/* turn on the audio power supplies */
		{0x0DB, 0x07, 0},
	};
	struct sc_reg_access pll[] = {
		/* turn on PLL */
		{0x240, 0x20, 0},
	};
	struct sc_reg_access vhs[] = {
		/*  VHSP */
		{0x0DC, 0xFF, 0},
		/*  VHSN */
		{0x0DD, 0x3F, 0},
	};
	struct sc_reg_access hsdac[] = {
		/*  disable driver */
		{0x25D, 0x0, 0x43},
		/* DAC CONFIG ; both HP, LP on */
		{0x257, 0x03, 0x03},
	};
	struct sc_reg_access hs_filter[] = {
		/* HSEPRXCTRL  Enable the headset left and right FIR filters  */
		{0x250, 0x30, 0},
		/* HSMIXER */
		{0x256, 0x11, 0},
	};
	struct sc_reg_access hs_enable[] = {
		/* enable driver */
		{0x25D, 0x3, 0x3},
		{0x26C, 0x0, 0x2},
		/* unmute the headset */
		{ 0x259, 0x80, 0x80},
		{ 0x25A, 0x80, 0x80},
	};
	struct sc_reg_access vihf[] = {
		/*  VIHF ON */
		{0x0C9, 0x27, 0x00},
	};
	struct sc_reg_access ihf_filter[] = {
		/*  disable driver */
		{0x25D, 0x00, 0x0C},
		/*Filer DAC enable*/
		{0x251, 0x03, 0x03},
		{0x257, 0x0C, 0x0C},
	};
	struct sc_reg_access ihf_en[] = {
		/*enable drv*/
		{0x25D, 0x0C, 0x0c},
	};
	struct sc_reg_access ihf_unmute[] = {
		/*unmute headset*/
		{0x25B, 0x80, 0x80},
		{0x25C, 0x80, 0x80},
	};
	struct sc_reg_access epdac[] = {
		/*  disable driver */
		{0x25D, 0x0, 0x43},
		/* DAC CONFIG ; both HP, LP on */
		{0x257, 0x03, 0x03},
	};
	struct sc_reg_access ep_enable[] = {
		/* enable driver */
		{0x25D, 0x40, 0x40},
		/* unmute the headset */
		{ 0x259, 0x80, 0x80},
		{ 0x25A, 0x80, 0x80},
	};
	struct sc_reg_access vib1_en[] = {
		/* enable driver, ADC */
		{0x25D, 0x10, 0x10},
		{0x264, 0x02, 0x82},
	};
	struct sc_reg_access vib2_en[] = {
		/* enable driver, ADC */
		{0x25D, 0x20, 0x20},
		{0x26A, 0x02, 0x82},
	};
	struct sc_reg_access pcm2_en[] = {
		/* enable pcm 2 */
		{0x27C, 0x1, 0x1},
	};
	int retval = 0;

	if (snd_msic_ops.card_status == SND_CARD_UN_INIT) {
		retval = msic_init_card();
		if (retval)
			return retval;
	}

	pr_debug("powering up pb.... Device %d\n", device);
	sst_sc_reg_access(vaud, PMIC_WRITE, 1);
	msleep(1);
	sst_sc_reg_access(pll, PMIC_WRITE, 1);
	msleep(1);
	switch (device) {
	case SND_SST_DEVICE_HEADSET:
		snd_msic_ops.pb_on = 1;
		snd_msic_ops.pbhs_on = 1;
		if (snd_msic_ops.output_dev_id == STEREO_HEADPHONE) {
			sst_sc_reg_access(vhs, PMIC_WRITE, 2);
			sst_sc_reg_access(hsdac, PMIC_READ_MODIFY, 2);
			sst_sc_reg_access(hs_filter, PMIC_WRITE, 2);
			sst_sc_reg_access(hs_enable, PMIC_READ_MODIFY, 4);
		} else {
			sst_sc_reg_access(epdac, PMIC_READ_MODIFY, 2);
			sst_sc_reg_access(hs_filter, PMIC_WRITE, 2);
			sst_sc_reg_access(ep_enable, PMIC_READ_MODIFY, 3);
		}
		if (snd_msic_ops.lineout_dev_id == HEADSET)
			msic_set_selected_lineout_dev(HEADSET);
		break;
	case SND_SST_DEVICE_IHF:
		snd_msic_ops.pb_on = 1;
		sst_sc_reg_access(vihf, PMIC_WRITE, 1);
		sst_sc_reg_access(ihf_filter, PMIC_READ_MODIFY, 3);
		sst_sc_reg_access(ihf_en, PMIC_READ_MODIFY, 1);
		sst_sc_reg_access(ihf_unmute, PMIC_READ_MODIFY, 2);
		if (snd_msic_ops.lineout_dev_id == IHF)
			msic_set_selected_lineout_dev(IHF);
		break;

	case SND_SST_DEVICE_VIBRA:
		snd_msic_ops.pb_on = 1;
		sst_sc_reg_access(vib1_en, PMIC_READ_MODIFY, 2);
		if (snd_msic_ops.lineout_dev_id == VIBRA1)
			msic_set_selected_lineout_dev(VIBRA1);
		break;

	case SND_SST_DEVICE_HAPTIC:
		snd_msic_ops.pb_on = 1;
		sst_sc_reg_access(vib2_en, PMIC_READ_MODIFY, 2);
		if (snd_msic_ops.lineout_dev_id == VIBRA2)
			msic_set_selected_lineout_dev(VIBRA2);
		break;

	default:
		pr_warn("Wrong Device %d, selected %d\n",
			       device, snd_msic_ops.output_dev_id);
	}
	return sst_sc_reg_access(pcm2_en, PMIC_READ_MODIFY, 1);
}

static int msic_power_up_cp(unsigned int device)
{
	struct sc_reg_access vaud[] = {
		/* turn on the audio power supplies */
		{0x0DB, 0x07, 0},
	};
	struct sc_reg_access pll[] = {
		/* turn on PLL */
		{0x240, 0x20, 0},
	};
	struct sc_reg_access dmic_bias[] = {
		/*  Turn on AMIC supply  */
		{0x247, 0xA0, 0xA0},
	};
	struct sc_reg_access dmic[] = {
		/* mic demux enable */
		{0x245, 0x3F, 0x3F},
		{0x246, 0x07, 0x07},

	};
	struct sc_reg_access amic_bias[] = {
		/*  Turn on AMIC supply  */
		{0x247, 0xFC, 0xFC},
	};
	struct sc_reg_access amic[] = {
		/*MIC EN*/
		{0x249, 0x01, 0x01},
		{0x24A, 0x01, 0x01},
		/*ADC EN*/
		{0x248, 0x05, 0x0F},

	};
	struct sc_reg_access pcm2[] = {
		/* enable pcm 2 */
		{0x27C, 0x1, 0x1},
	};
	struct sc_reg_access tx_on[] = {
		/*wait for mic to stabalize before turning on audio channels*/
		{0x24F, 0x3C, 0x0},
	};
	int retval = 0;

	if (snd_msic_ops.card_status == SND_CARD_UN_INIT) {
		retval = msic_init_card();
		if (retval)
			return retval;
	}

	pr_debug("powering up cp....%d\n", snd_msic_ops.input_dev_id);
	sst_sc_reg_access(vaud, PMIC_WRITE, 1);
	msleep(500);/*FIXME need optimzed value here*/
	sst_sc_reg_access(pll, PMIC_WRITE, 1);
	msleep(1);
	snd_msic_ops.cap_on = 1;
	if (snd_msic_ops.input_dev_id == AMIC) {
		sst_sc_reg_access(amic_bias, PMIC_READ_MODIFY, 1);
		msleep(1);
		sst_sc_reg_access(amic, PMIC_READ_MODIFY, 3);
	} else {
		sst_sc_reg_access(dmic_bias, PMIC_READ_MODIFY, 1);
		msleep(1);
		sst_sc_reg_access(dmic, PMIC_READ_MODIFY, 2);
	}
	msleep(1);
	sst_sc_reg_access(tx_on, PMIC_WRITE, 1);
	return sst_sc_reg_access(pcm2, PMIC_READ_MODIFY, 1);
}

static int msic_power_down(void)
{
	struct sc_reg_access power_dn[] = {
		/*  VHSP */
		{0x0DC, 0xC4, 0},
		/*  VHSN */
		{0x0DD, 0x04, 0},
		/*  VIHF */
		{0x0C9, 0x24, 0},
	};
	struct sc_reg_access pll[] = {
		/* turn off PLL*/
		{0x240, 0x00, 0x0},
	};
	struct sc_reg_access vaud[] = {
		/* turn off VAUD*/
		{0x0DB, 0x04, 0},
	};

	pr_debug("powering dn msic\n");
	snd_msic_ops.pbhs_on = 0;
	snd_msic_ops.pb_on = 0;
	snd_msic_ops.cap_on = 0;
	sst_sc_reg_access(power_dn, PMIC_WRITE, 3);
	msleep(1);
	sst_sc_reg_access(pll, PMIC_WRITE, 1);
	msleep(1);
	sst_sc_reg_access(vaud, PMIC_WRITE, 1);
	return 0;
}

static int msic_power_down_pb(unsigned int device)
{
	struct sc_reg_access drv_enable[] = {
		{0x25D, 0x00, 0x00},
	};
	struct sc_reg_access hs_mute[] = {
		{0x259, 0x80, 0x80},
		{0x25A, 0x80, 0x80},
		{0x26C, 0x02, 0x02},
	};
	struct sc_reg_access hs_off[] = {
		{0x257, 0x00, 0x03},
		{0x250, 0x00, 0x30},
	};
	struct sc_reg_access ihf_mute[] = {
		{0x25B, 0x80, 0x80},
		{0x25C, 0x80, 0x80},
	};
	struct sc_reg_access ihf_off[] = {
		{0x257, 0x00, 0x0C},
		{0x251, 0x00, 0x03},
	};
	struct sc_reg_access vib1_off[] = {
		{0x264, 0x00, 0x82},
	};
	struct sc_reg_access vib2_off[] = {
		{0x26A, 0x00, 0x82},
	};
	struct sc_reg_access lout_off[] = {
		{0x25e, 0x66, 0x00},
	};



	pr_debug("powering dn pb for device %d\n", device);
	switch (device) {
	case SND_SST_DEVICE_HEADSET:
		snd_msic_ops.pbhs_on = 0;
		sst_sc_reg_access(hs_mute, PMIC_READ_MODIFY, 3);
		drv_enable[0].mask = 0x43;
		sst_sc_reg_access(drv_enable, PMIC_READ_MODIFY, 1);
		sst_sc_reg_access(hs_off, PMIC_READ_MODIFY, 2);
		if (snd_msic_ops.lineout_dev_id == HEADSET)
			sst_sc_reg_access(lout_off, PMIC_WRITE, 1);
		break;

	case SND_SST_DEVICE_IHF:
		sst_sc_reg_access(ihf_mute, PMIC_READ_MODIFY, 2);
		drv_enable[0].mask = 0x0C;
		sst_sc_reg_access(drv_enable, PMIC_READ_MODIFY, 1);
		sst_sc_reg_access(ihf_off, PMIC_READ_MODIFY, 2);
		if (snd_msic_ops.lineout_dev_id == IHF)
			sst_sc_reg_access(lout_off, PMIC_WRITE, 1);
		break;

	case SND_SST_DEVICE_VIBRA:
		sst_sc_reg_access(vib1_off, PMIC_READ_MODIFY, 1);
		drv_enable[0].mask = 0x10;
		sst_sc_reg_access(drv_enable, PMIC_READ_MODIFY, 1);
		if (snd_msic_ops.lineout_dev_id == VIBRA1)
			sst_sc_reg_access(lout_off, PMIC_WRITE, 1);
		break;

	case SND_SST_DEVICE_HAPTIC:
		sst_sc_reg_access(vib2_off, PMIC_READ_MODIFY, 1);
		drv_enable[0].mask = 0x20;
		sst_sc_reg_access(drv_enable, PMIC_READ_MODIFY, 1);
		if (snd_msic_ops.lineout_dev_id == VIBRA2)
			sst_sc_reg_access(lout_off, PMIC_WRITE, 1);
		break;
	}
	return 0;
}

static int msic_power_down_cp(unsigned int device)
{
	struct sc_reg_access dmic[] = {
		{0x247, 0x00, 0xA0},
		{0x245, 0x00, 0x38},
		{0x246, 0x00, 0x07},
	};
	struct sc_reg_access amic[] = {
		{0x248, 0x00, 0x05},
		{0x249, 0x00, 0x01},
		{0x24A, 0x00, 0x01},
		{0x247, 0x00, 0xA3},
	};
	struct sc_reg_access tx_off[] = {
		{0x24F, 0x00, 0x3C},
	};

	pr_debug("powering dn cp....\n");
	snd_msic_ops.cap_on = 0;
	sst_sc_reg_access(tx_off, PMIC_READ_MODIFY, 1);
	if (snd_msic_ops.input_dev_id == DMIC)
		sst_sc_reg_access(dmic, PMIC_READ_MODIFY, 3);
	else
		sst_sc_reg_access(amic, PMIC_READ_MODIFY, 4);
	return 0;
}

static int msic_set_selected_output_dev(u8 value)
{
	int retval = 0;

	pr_debug("msic set selected output:%d\n", value);
	snd_msic_ops.output_dev_id = value;
	if (snd_msic_ops.pbhs_on)
		msic_power_up_pb(SND_SST_DEVICE_HEADSET);
	return retval;
}

static int msic_set_selected_input_dev(u8 value)
{

	struct sc_reg_access sc_access_dmic[] = {
		{0x24C, 0x10, 0x0},
	};
	struct sc_reg_access sc_access_amic[] = {
		{0x24C, 0x76, 0x0},

	};
	int retval = 0;

	pr_debug("msic_set_selected_input_dev:%d\n", value);
	snd_msic_ops.input_dev_id = value;
	switch (value) {
	case AMIC:
		pr_debug("Selecting AMIC1\n");
		retval = sst_sc_reg_access(sc_access_amic, PMIC_WRITE, 1);
		break;
	case DMIC:
		pr_debug("Selecting DMIC1\n");
		retval = sst_sc_reg_access(sc_access_dmic, PMIC_WRITE, 1);
		break;
	default:
		return -EINVAL;

	}
	if (snd_msic_ops.cap_on)
		retval = msic_power_up_cp(SND_SST_DEVICE_CAPTURE);
	return retval;
}

static int msic_set_pcm_voice_params(void)
{
	return 0;
}

static int msic_set_pcm_audio_params(int sfreq, int word_size, int num_channel)
{
	return 0;
}

static int msic_set_audio_port(int status)
{
	return 0;
}

static int msic_set_voice_port(int status)
{
	return 0;
}

static int msic_set_mute(int dev_id, u8 value)
{
	return 0;
}

static int msic_set_vol(int dev_id, int value)
{
	return 0;
}

static int msic_get_mute(int dev_id, u8 *value)
{
	return 0;
}

static int msic_get_vol(int dev_id, int *value)
{
	return 0;
}

struct snd_pmic_ops snd_msic_ops = {
	.set_input_dev	=	msic_set_selected_input_dev,
	.set_output_dev =	msic_set_selected_output_dev,
	.set_lineout_dev =	msic_set_selected_lineout_dev,
	.set_mute	=	msic_set_mute,
	.get_mute	=	msic_get_mute,
	.set_vol	=	msic_set_vol,
	.get_vol	=	msic_get_vol,
	.init_card	=	msic_init_card,
	.set_pcm_audio_params	= msic_set_pcm_audio_params,
	.set_pcm_voice_params	= msic_set_pcm_voice_params,
	.set_voice_port = msic_set_voice_port,
	.set_audio_port = msic_set_audio_port,
	.power_up_pmic_pb =	msic_power_up_pb,
	.power_up_pmic_cp =	msic_power_up_cp,
	.power_down_pmic_pb =	msic_power_down_pb,
	.power_down_pmic_cp =	msic_power_down_cp,
	.power_down_pmic =	msic_power_down,
};