2 * max98095.c -- MAX98095 ALSA SoC Audio driver
4 * Copyright 2011 Maxim Integrated Products
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
11 #include <linux/module.h>
12 #include <linux/moduleparam.h>
13 #include <linux/kernel.h>
14 #include <linux/init.h>
15 #include <linux/delay.h>
17 #include <linux/i2c.h>
18 #include <linux/platform_device.h>
19 #include <sound/core.h>
20 #include <sound/pcm.h>
21 #include <sound/pcm_params.h>
22 #include <sound/soc.h>
23 #include <sound/initval.h>
24 #include <sound/tlv.h>
25 #include <linux/slab.h>
26 #include <asm/div64.h>
27 #include <sound/max98095.h>
34 struct max98095_cdata
{
41 struct max98095_priv
{
42 enum max98095_type devtype
;
43 struct max98095_pdata
*pdata
;
45 struct max98095_cdata dai
[3];
46 const char **eq_texts
;
47 const char **bq_texts
;
48 struct soc_enum eq_enum
;
49 struct soc_enum bq_enum
;
57 static const u8 max98095_reg_def
[M98095_REG_CNT
] = {
319 } max98095_access
[M98095_REG_CNT
] = {
320 { 0x00, 0x00 }, /* 00 */
321 { 0xFF, 0x00 }, /* 01 */
322 { 0xFF, 0x00 }, /* 02 */
323 { 0xFF, 0x00 }, /* 03 */
324 { 0xFF, 0x00 }, /* 04 */
325 { 0xFF, 0x00 }, /* 05 */
326 { 0xFF, 0x00 }, /* 06 */
327 { 0xFF, 0x00 }, /* 07 */
328 { 0xFF, 0x00 }, /* 08 */
329 { 0xFF, 0x00 }, /* 09 */
330 { 0xFF, 0x00 }, /* 0A */
331 { 0xFF, 0x00 }, /* 0B */
332 { 0xFF, 0x00 }, /* 0C */
333 { 0xFF, 0x00 }, /* 0D */
334 { 0xFF, 0x00 }, /* 0E */
335 { 0xFF, 0x9F }, /* 0F */
336 { 0xFF, 0xFF }, /* 10 */
337 { 0xFF, 0xFF }, /* 11 */
338 { 0xFF, 0xFF }, /* 12 */
339 { 0xFF, 0xFF }, /* 13 */
340 { 0xFF, 0xFF }, /* 14 */
341 { 0xFF, 0xFF }, /* 15 */
342 { 0xFF, 0xFF }, /* 16 */
343 { 0xFF, 0xFF }, /* 17 */
344 { 0xFF, 0xFF }, /* 18 */
345 { 0xFF, 0xFF }, /* 19 */
346 { 0xFF, 0xFF }, /* 1A */
347 { 0xFF, 0xFF }, /* 1B */
348 { 0xFF, 0xFF }, /* 1C */
349 { 0xFF, 0xFF }, /* 1D */
350 { 0xFF, 0x77 }, /* 1E */
351 { 0xFF, 0x77 }, /* 1F */
352 { 0xFF, 0x77 }, /* 20 */
353 { 0xFF, 0x77 }, /* 21 */
354 { 0xFF, 0x77 }, /* 22 */
355 { 0xFF, 0x77 }, /* 23 */
356 { 0xFF, 0xFF }, /* 24 */
357 { 0xFF, 0x7F }, /* 25 */
358 { 0xFF, 0x31 }, /* 26 */
359 { 0xFF, 0xFF }, /* 27 */
360 { 0xFF, 0xFF }, /* 28 */
361 { 0xFF, 0xFF }, /* 29 */
362 { 0xFF, 0xF7 }, /* 2A */
363 { 0xFF, 0x2F }, /* 2B */
364 { 0xFF, 0xEF }, /* 2C */
365 { 0xFF, 0xFF }, /* 2D */
366 { 0xFF, 0xFF }, /* 2E */
367 { 0xFF, 0xFF }, /* 2F */
368 { 0xFF, 0xFF }, /* 30 */
369 { 0xFF, 0xFF }, /* 31 */
370 { 0xFF, 0xFF }, /* 32 */
371 { 0xFF, 0xFF }, /* 33 */
372 { 0xFF, 0xF7 }, /* 34 */
373 { 0xFF, 0x2F }, /* 35 */
374 { 0xFF, 0xCF }, /* 36 */
375 { 0xFF, 0xFF }, /* 37 */
376 { 0xFF, 0xFF }, /* 38 */
377 { 0xFF, 0xFF }, /* 39 */
378 { 0xFF, 0xFF }, /* 3A */
379 { 0xFF, 0xFF }, /* 3B */
380 { 0xFF, 0xFF }, /* 3C */
381 { 0xFF, 0xFF }, /* 3D */
382 { 0xFF, 0xF7 }, /* 3E */
383 { 0xFF, 0x2F }, /* 3F */
384 { 0xFF, 0xCF }, /* 40 */
385 { 0xFF, 0xFF }, /* 41 */
386 { 0xFF, 0x77 }, /* 42 */
387 { 0xFF, 0xFF }, /* 43 */
388 { 0xFF, 0xFF }, /* 44 */
389 { 0xFF, 0xFF }, /* 45 */
390 { 0xFF, 0xFF }, /* 46 */
391 { 0xFF, 0xFF }, /* 47 */
392 { 0xFF, 0xFF }, /* 48 */
393 { 0xFF, 0x0F }, /* 49 */
394 { 0xFF, 0xFF }, /* 4A */
395 { 0xFF, 0xFF }, /* 4B */
396 { 0xFF, 0x3F }, /* 4C */
397 { 0xFF, 0x3F }, /* 4D */
398 { 0xFF, 0x3F }, /* 4E */
399 { 0xFF, 0xFF }, /* 4F */
400 { 0xFF, 0x7F }, /* 50 */
401 { 0xFF, 0x7F }, /* 51 */
402 { 0xFF, 0x0F }, /* 52 */
403 { 0xFF, 0x3F }, /* 53 */
404 { 0xFF, 0x3F }, /* 54 */
405 { 0xFF, 0x3F }, /* 55 */
406 { 0xFF, 0xFF }, /* 56 */
407 { 0xFF, 0xFF }, /* 57 */
408 { 0xFF, 0xBF }, /* 58 */
409 { 0xFF, 0x1F }, /* 59 */
410 { 0xFF, 0xBF }, /* 5A */
411 { 0xFF, 0x1F }, /* 5B */
412 { 0xFF, 0xBF }, /* 5C */
413 { 0xFF, 0x3F }, /* 5D */
414 { 0xFF, 0x3F }, /* 5E */
415 { 0xFF, 0x7F }, /* 5F */
416 { 0xFF, 0x7F }, /* 60 */
417 { 0xFF, 0x47 }, /* 61 */
418 { 0xFF, 0x9F }, /* 62 */
419 { 0xFF, 0x9F }, /* 63 */
420 { 0xFF, 0x9F }, /* 64 */
421 { 0xFF, 0x9F }, /* 65 */
422 { 0xFF, 0x9F }, /* 66 */
423 { 0xFF, 0xBF }, /* 67 */
424 { 0xFF, 0xBF }, /* 68 */
425 { 0xFF, 0xFF }, /* 69 */
426 { 0xFF, 0xFF }, /* 6A */
427 { 0xFF, 0x7F }, /* 6B */
428 { 0xFF, 0xF7 }, /* 6C */
429 { 0xFF, 0xFF }, /* 6D */
430 { 0xFF, 0xFF }, /* 6E */
431 { 0xFF, 0x1F }, /* 6F */
432 { 0xFF, 0xF7 }, /* 70 */
433 { 0xFF, 0xFF }, /* 71 */
434 { 0xFF, 0xFF }, /* 72 */
435 { 0xFF, 0x1F }, /* 73 */
436 { 0xFF, 0xF7 }, /* 74 */
437 { 0xFF, 0xFF }, /* 75 */
438 { 0xFF, 0xFF }, /* 76 */
439 { 0xFF, 0x1F }, /* 77 */
440 { 0xFF, 0xF7 }, /* 78 */
441 { 0xFF, 0xFF }, /* 79 */
442 { 0xFF, 0xFF }, /* 7A */
443 { 0xFF, 0x1F }, /* 7B */
444 { 0xFF, 0xF7 }, /* 7C */
445 { 0xFF, 0xFF }, /* 7D */
446 { 0xFF, 0xFF }, /* 7E */
447 { 0xFF, 0x1F }, /* 7F */
448 { 0xFF, 0xF7 }, /* 80 */
449 { 0xFF, 0xFF }, /* 81 */
450 { 0xFF, 0xFF }, /* 82 */
451 { 0xFF, 0x1F }, /* 83 */
452 { 0xFF, 0x7F }, /* 84 */
453 { 0xFF, 0x0F }, /* 85 */
454 { 0xFF, 0xD8 }, /* 86 */
455 { 0xFF, 0xFF }, /* 87 */
456 { 0xFF, 0xEF }, /* 88 */
457 { 0xFF, 0xFE }, /* 89 */
458 { 0xFF, 0xFE }, /* 8A */
459 { 0xFF, 0xFF }, /* 8B */
460 { 0xFF, 0xFF }, /* 8C */
461 { 0xFF, 0x3F }, /* 8D */
462 { 0xFF, 0xFF }, /* 8E */
463 { 0xFF, 0x3F }, /* 8F */
464 { 0xFF, 0x8F }, /* 90 */
465 { 0xFF, 0xFF }, /* 91 */
466 { 0xFF, 0x3F }, /* 92 */
467 { 0xFF, 0xFF }, /* 93 */
468 { 0xFF, 0xFF }, /* 94 */
469 { 0xFF, 0x0F }, /* 95 */
470 { 0xFF, 0x3F }, /* 96 */
471 { 0xFF, 0x8C }, /* 97 */
472 { 0x00, 0x00 }, /* 98 */
473 { 0x00, 0x00 }, /* 99 */
474 { 0x00, 0x00 }, /* 9A */
475 { 0x00, 0x00 }, /* 9B */
476 { 0x00, 0x00 }, /* 9C */
477 { 0x00, 0x00 }, /* 9D */
478 { 0x00, 0x00 }, /* 9E */
479 { 0x00, 0x00 }, /* 9F */
480 { 0x00, 0x00 }, /* A0 */
481 { 0x00, 0x00 }, /* A1 */
482 { 0x00, 0x00 }, /* A2 */
483 { 0x00, 0x00 }, /* A3 */
484 { 0x00, 0x00 }, /* A4 */
485 { 0x00, 0x00 }, /* A5 */
486 { 0x00, 0x00 }, /* A6 */
487 { 0x00, 0x00 }, /* A7 */
488 { 0x00, 0x00 }, /* A8 */
489 { 0x00, 0x00 }, /* A9 */
490 { 0x00, 0x00 }, /* AA */
491 { 0x00, 0x00 }, /* AB */
492 { 0x00, 0x00 }, /* AC */
493 { 0x00, 0x00 }, /* AD */
494 { 0x00, 0x00 }, /* AE */
495 { 0x00, 0x00 }, /* AF */
496 { 0x00, 0x00 }, /* B0 */
497 { 0x00, 0x00 }, /* B1 */
498 { 0x00, 0x00 }, /* B2 */
499 { 0x00, 0x00 }, /* B3 */
500 { 0x00, 0x00 }, /* B4 */
501 { 0x00, 0x00 }, /* B5 */
502 { 0x00, 0x00 }, /* B6 */
503 { 0x00, 0x00 }, /* B7 */
504 { 0x00, 0x00 }, /* B8 */
505 { 0x00, 0x00 }, /* B9 */
506 { 0x00, 0x00 }, /* BA */
507 { 0x00, 0x00 }, /* BB */
508 { 0x00, 0x00 }, /* BC */
509 { 0x00, 0x00 }, /* BD */
510 { 0x00, 0x00 }, /* BE */
511 { 0x00, 0x00 }, /* BF */
512 { 0x00, 0x00 }, /* C0 */
513 { 0x00, 0x00 }, /* C1 */
514 { 0x00, 0x00 }, /* C2 */
515 { 0x00, 0x00 }, /* C3 */
516 { 0x00, 0x00 }, /* C4 */
517 { 0x00, 0x00 }, /* C5 */
518 { 0x00, 0x00 }, /* C6 */
519 { 0x00, 0x00 }, /* C7 */
520 { 0x00, 0x00 }, /* C8 */
521 { 0x00, 0x00 }, /* C9 */
522 { 0x00, 0x00 }, /* CA */
523 { 0x00, 0x00 }, /* CB */
524 { 0x00, 0x00 }, /* CC */
525 { 0x00, 0x00 }, /* CD */
526 { 0x00, 0x00 }, /* CE */
527 { 0x00, 0x00 }, /* CF */
528 { 0x00, 0x00 }, /* D0 */
529 { 0x00, 0x00 }, /* D1 */
530 { 0x00, 0x00 }, /* D2 */
531 { 0x00, 0x00 }, /* D3 */
532 { 0x00, 0x00 }, /* D4 */
533 { 0x00, 0x00 }, /* D5 */
534 { 0x00, 0x00 }, /* D6 */
535 { 0x00, 0x00 }, /* D7 */
536 { 0x00, 0x00 }, /* D8 */
537 { 0x00, 0x00 }, /* D9 */
538 { 0x00, 0x00 }, /* DA */
539 { 0x00, 0x00 }, /* DB */
540 { 0x00, 0x00 }, /* DC */
541 { 0x00, 0x00 }, /* DD */
542 { 0x00, 0x00 }, /* DE */
543 { 0x00, 0x00 }, /* DF */
544 { 0x00, 0x00 }, /* E0 */
545 { 0x00, 0x00 }, /* E1 */
546 { 0x00, 0x00 }, /* E2 */
547 { 0x00, 0x00 }, /* E3 */
548 { 0x00, 0x00 }, /* E4 */
549 { 0x00, 0x00 }, /* E5 */
550 { 0x00, 0x00 }, /* E6 */
551 { 0x00, 0x00 }, /* E7 */
552 { 0x00, 0x00 }, /* E8 */
553 { 0x00, 0x00 }, /* E9 */
554 { 0x00, 0x00 }, /* EA */
555 { 0x00, 0x00 }, /* EB */
556 { 0x00, 0x00 }, /* EC */
557 { 0x00, 0x00 }, /* ED */
558 { 0x00, 0x00 }, /* EE */
559 { 0x00, 0x00 }, /* EF */
560 { 0x00, 0x00 }, /* F0 */
561 { 0x00, 0x00 }, /* F1 */
562 { 0x00, 0x00 }, /* F2 */
563 { 0x00, 0x00 }, /* F3 */
564 { 0x00, 0x00 }, /* F4 */
565 { 0x00, 0x00 }, /* F5 */
566 { 0x00, 0x00 }, /* F6 */
567 { 0x00, 0x00 }, /* F7 */
568 { 0x00, 0x00 }, /* F8 */
569 { 0x00, 0x00 }, /* F9 */
570 { 0x00, 0x00 }, /* FA */
571 { 0x00, 0x00 }, /* FB */
572 { 0x00, 0x00 }, /* FC */
573 { 0x00, 0x00 }, /* FD */
574 { 0x00, 0x00 }, /* FE */
575 { 0xFF, 0x00 }, /* FF */
578 static int max98095_readable(struct snd_soc_codec
*codec
, unsigned int reg
)
580 if (reg
>= M98095_REG_CNT
)
582 return max98095_access
[reg
].readable
!= 0;
585 static int max98095_volatile(struct snd_soc_codec
*codec
, unsigned int reg
)
587 if (reg
> M98095_REG_MAX_CACHED
)
591 case M98095_000_HOST_DATA
:
592 case M98095_001_HOST_INT_STS
:
593 case M98095_002_HOST_RSP_STS
:
594 case M98095_003_HOST_CMD_STS
:
595 case M98095_004_CODEC_STS
:
596 case M98095_005_DAI1_ALC_STS
:
597 case M98095_006_DAI2_ALC_STS
:
598 case M98095_007_JACK_AUTO_STS
:
599 case M98095_008_JACK_MANUAL_STS
:
600 case M98095_009_JACK_VBAT_STS
:
601 case M98095_00A_ACC_ADC_STS
:
602 case M98095_00B_MIC_NG_AGC_STS
:
603 case M98095_00C_SPK_L_VOLT_STS
:
604 case M98095_00D_SPK_R_VOLT_STS
:
605 case M98095_00E_TEMP_SENSOR_STS
:
613 * Filter coefficients are in a separate register segment
614 * and they share the address space of the normal registers.
615 * The coefficient registers do not need or share the cache.
617 static int max98095_hw_write(struct snd_soc_codec
*codec
, unsigned int reg
,
622 codec
->cache_bypass
= 1;
623 ret
= snd_soc_write(codec
, reg
, value
);
624 codec
->cache_bypass
= 0;
626 return ret
? -EIO
: 0;
630 * Load equalizer DSP coefficient configurations registers
632 static void m98095_eq_band(struct snd_soc_codec
*codec
, unsigned int dai
,
633 unsigned int band
, u16
*coefs
)
641 /* Load the base register address */
642 eq_reg
= dai
? M98095_142_DAI2_EQ_BASE
: M98095_110_DAI1_EQ_BASE
;
644 /* Add the band address offset, note adjustment for word address */
645 eq_reg
+= band
* (M98095_COEFS_PER_BAND
<< 1);
647 /* Step through the registers and coefs */
648 for (i
= 0; i
< M98095_COEFS_PER_BAND
; i
++) {
649 max98095_hw_write(codec
, eq_reg
++, M98095_BYTE1(coefs
[i
]));
650 max98095_hw_write(codec
, eq_reg
++, M98095_BYTE0(coefs
[i
]));
655 * Load biquad filter coefficient configurations registers
657 static void m98095_biquad_band(struct snd_soc_codec
*codec
, unsigned int dai
,
658 unsigned int band
, u16
*coefs
)
666 /* Load the base register address */
667 bq_reg
= dai
? M98095_17E_DAI2_BQ_BASE
: M98095_174_DAI1_BQ_BASE
;
669 /* Add the band address offset, note adjustment for word address */
670 bq_reg
+= band
* (M98095_COEFS_PER_BAND
<< 1);
672 /* Step through the registers and coefs */
673 for (i
= 0; i
< M98095_COEFS_PER_BAND
; i
++) {
674 max98095_hw_write(codec
, bq_reg
++, M98095_BYTE1(coefs
[i
]));
675 max98095_hw_write(codec
, bq_reg
++, M98095_BYTE0(coefs
[i
]));
679 static const char * const max98095_fltr_mode
[] = { "Voice", "Music" };
680 static const struct soc_enum max98095_dai1_filter_mode_enum
[] = {
681 SOC_ENUM_SINGLE(M98095_02E_DAI1_FILTERS
, 7, 2, max98095_fltr_mode
),
683 static const struct soc_enum max98095_dai2_filter_mode_enum
[] = {
684 SOC_ENUM_SINGLE(M98095_038_DAI2_FILTERS
, 7, 2, max98095_fltr_mode
),
687 static const char * const max98095_extmic_text
[] = { "None", "MIC1", "MIC2" };
689 static const struct soc_enum max98095_extmic_enum
=
690 SOC_ENUM_SINGLE(M98095_087_CFG_MIC
, 0, 3, max98095_extmic_text
);
692 static const struct snd_kcontrol_new max98095_extmic_mux
=
693 SOC_DAPM_ENUM("External MIC Mux", max98095_extmic_enum
);
695 static const char * const max98095_linein_text
[] = { "INA", "INB" };
697 static const struct soc_enum max98095_linein_enum
=
698 SOC_ENUM_SINGLE(M98095_086_CFG_LINE
, 6, 2, max98095_linein_text
);
700 static const struct snd_kcontrol_new max98095_linein_mux
=
701 SOC_DAPM_ENUM("Linein Input Mux", max98095_linein_enum
);
703 static const char * const max98095_line_mode_text
[] = {
704 "Stereo", "Differential"};
706 static const struct soc_enum max98095_linein_mode_enum
=
707 SOC_ENUM_SINGLE(M98095_086_CFG_LINE
, 7, 2, max98095_line_mode_text
);
709 static const struct soc_enum max98095_lineout_mode_enum
=
710 SOC_ENUM_SINGLE(M98095_086_CFG_LINE
, 4, 2, max98095_line_mode_text
);
712 static const char * const max98095_dai_fltr
[] = {
713 "Off", "Elliptical-HPF-16k", "Butterworth-HPF-16k",
714 "Elliptical-HPF-8k", "Butterworth-HPF-8k", "Butterworth-HPF-Fs/240"};
715 static const struct soc_enum max98095_dai1_dac_filter_enum
[] = {
716 SOC_ENUM_SINGLE(M98095_02E_DAI1_FILTERS
, 0, 6, max98095_dai_fltr
),
718 static const struct soc_enum max98095_dai2_dac_filter_enum
[] = {
719 SOC_ENUM_SINGLE(M98095_038_DAI2_FILTERS
, 0, 6, max98095_dai_fltr
),
721 static const struct soc_enum max98095_dai3_dac_filter_enum
[] = {
722 SOC_ENUM_SINGLE(M98095_042_DAI3_FILTERS
, 0, 6, max98095_dai_fltr
),
725 static int max98095_mic1pre_set(struct snd_kcontrol
*kcontrol
,
726 struct snd_ctl_elem_value
*ucontrol
)
728 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
729 struct max98095_priv
*max98095
= snd_soc_codec_get_drvdata(codec
);
730 unsigned int sel
= ucontrol
->value
.integer
.value
[0];
732 max98095
->mic1pre
= sel
;
733 snd_soc_update_bits(codec
, M98095_05F_LVL_MIC1
, M98095_MICPRE_MASK
,
734 (1+sel
)<<M98095_MICPRE_SHIFT
);
739 static int max98095_mic1pre_get(struct snd_kcontrol
*kcontrol
,
740 struct snd_ctl_elem_value
*ucontrol
)
742 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
743 struct max98095_priv
*max98095
= snd_soc_codec_get_drvdata(codec
);
745 ucontrol
->value
.integer
.value
[0] = max98095
->mic1pre
;
749 static int max98095_mic2pre_set(struct snd_kcontrol
*kcontrol
,
750 struct snd_ctl_elem_value
*ucontrol
)
752 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
753 struct max98095_priv
*max98095
= snd_soc_codec_get_drvdata(codec
);
754 unsigned int sel
= ucontrol
->value
.integer
.value
[0];
756 max98095
->mic2pre
= sel
;
757 snd_soc_update_bits(codec
, M98095_060_LVL_MIC2
, M98095_MICPRE_MASK
,
758 (1+sel
)<<M98095_MICPRE_SHIFT
);
763 static int max98095_mic2pre_get(struct snd_kcontrol
*kcontrol
,
764 struct snd_ctl_elem_value
*ucontrol
)
766 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
767 struct max98095_priv
*max98095
= snd_soc_codec_get_drvdata(codec
);
769 ucontrol
->value
.integer
.value
[0] = max98095
->mic2pre
;
773 static const unsigned int max98095_micboost_tlv
[] = {
774 TLV_DB_RANGE_HEAD(2),
775 0, 1, TLV_DB_SCALE_ITEM(0, 2000, 0),
776 2, 2, TLV_DB_SCALE_ITEM(3000, 0, 0),
779 static const DECLARE_TLV_DB_SCALE(max98095_mic_tlv
, 0, 100, 0);
780 static const DECLARE_TLV_DB_SCALE(max98095_adc_tlv
, -1200, 100, 0);
781 static const DECLARE_TLV_DB_SCALE(max98095_adcboost_tlv
, 0, 600, 0);
783 static const unsigned int max98095_hp_tlv
[] = {
784 TLV_DB_RANGE_HEAD(5),
785 0, 6, TLV_DB_SCALE_ITEM(-6700, 400, 0),
786 7, 14, TLV_DB_SCALE_ITEM(-4000, 300, 0),
787 15, 21, TLV_DB_SCALE_ITEM(-1700, 200, 0),
788 22, 27, TLV_DB_SCALE_ITEM(-400, 100, 0),
789 28, 31, TLV_DB_SCALE_ITEM(150, 50, 0),
792 static const unsigned int max98095_spk_tlv
[] = {
793 TLV_DB_RANGE_HEAD(4),
794 0, 10, TLV_DB_SCALE_ITEM(-5900, 400, 0),
795 11, 18, TLV_DB_SCALE_ITEM(-1700, 200, 0),
796 19, 27, TLV_DB_SCALE_ITEM(-200, 100, 0),
797 28, 39, TLV_DB_SCALE_ITEM(650, 50, 0),
800 static const unsigned int max98095_rcv_lout_tlv
[] = {
801 TLV_DB_RANGE_HEAD(5),
802 0, 6, TLV_DB_SCALE_ITEM(-6200, 400, 0),
803 7, 14, TLV_DB_SCALE_ITEM(-3500, 300, 0),
804 15, 21, TLV_DB_SCALE_ITEM(-1200, 200, 0),
805 22, 27, TLV_DB_SCALE_ITEM(100, 100, 0),
806 28, 31, TLV_DB_SCALE_ITEM(650, 50, 0),
809 static const unsigned int max98095_lin_tlv
[] = {
810 TLV_DB_RANGE_HEAD(3),
811 0, 2, TLV_DB_SCALE_ITEM(-600, 300, 0),
812 3, 3, TLV_DB_SCALE_ITEM(300, 1100, 0),
813 4, 5, TLV_DB_SCALE_ITEM(1400, 600, 0),
816 static const struct snd_kcontrol_new max98095_snd_controls
[] = {
818 SOC_DOUBLE_R_TLV("Headphone Volume", M98095_064_LVL_HP_L
,
819 M98095_065_LVL_HP_R
, 0, 31, 0, max98095_hp_tlv
),
821 SOC_DOUBLE_R_TLV("Speaker Volume", M98095_067_LVL_SPK_L
,
822 M98095_068_LVL_SPK_R
, 0, 39, 0, max98095_spk_tlv
),
824 SOC_SINGLE_TLV("Receiver Volume", M98095_066_LVL_RCV
,
825 0, 31, 0, max98095_rcv_lout_tlv
),
827 SOC_DOUBLE_R_TLV("Lineout Volume", M98095_062_LVL_LINEOUT1
,
828 M98095_063_LVL_LINEOUT2
, 0, 31, 0, max98095_rcv_lout_tlv
),
830 SOC_DOUBLE_R("Headphone Switch", M98095_064_LVL_HP_L
,
831 M98095_065_LVL_HP_R
, 7, 1, 1),
833 SOC_DOUBLE_R("Speaker Switch", M98095_067_LVL_SPK_L
,
834 M98095_068_LVL_SPK_R
, 7, 1, 1),
836 SOC_SINGLE("Receiver Switch", M98095_066_LVL_RCV
, 7, 1, 1),
838 SOC_DOUBLE_R("Lineout Switch", M98095_062_LVL_LINEOUT1
,
839 M98095_063_LVL_LINEOUT2
, 7, 1, 1),
841 SOC_SINGLE_TLV("MIC1 Volume", M98095_05F_LVL_MIC1
, 0, 20, 1,
844 SOC_SINGLE_TLV("MIC2 Volume", M98095_060_LVL_MIC2
, 0, 20, 1,
847 SOC_SINGLE_EXT_TLV("MIC1 Boost Volume",
848 M98095_05F_LVL_MIC1
, 5, 2, 0,
849 max98095_mic1pre_get
, max98095_mic1pre_set
,
850 max98095_micboost_tlv
),
851 SOC_SINGLE_EXT_TLV("MIC2 Boost Volume",
852 M98095_060_LVL_MIC2
, 5, 2, 0,
853 max98095_mic2pre_get
, max98095_mic2pre_set
,
854 max98095_micboost_tlv
),
856 SOC_SINGLE_TLV("Linein Volume", M98095_061_LVL_LINEIN
, 0, 5, 1,
859 SOC_SINGLE_TLV("ADCL Volume", M98095_05D_LVL_ADC_L
, 0, 15, 1,
861 SOC_SINGLE_TLV("ADCR Volume", M98095_05E_LVL_ADC_R
, 0, 15, 1,
864 SOC_SINGLE_TLV("ADCL Boost Volume", M98095_05D_LVL_ADC_L
, 4, 3, 0,
865 max98095_adcboost_tlv
),
866 SOC_SINGLE_TLV("ADCR Boost Volume", M98095_05E_LVL_ADC_R
, 4, 3, 0,
867 max98095_adcboost_tlv
),
869 SOC_SINGLE("EQ1 Switch", M98095_088_CFG_LEVEL
, 0, 1, 0),
870 SOC_SINGLE("EQ2 Switch", M98095_088_CFG_LEVEL
, 1, 1, 0),
872 SOC_SINGLE("Biquad1 Switch", M98095_088_CFG_LEVEL
, 2, 1, 0),
873 SOC_SINGLE("Biquad2 Switch", M98095_088_CFG_LEVEL
, 3, 1, 0),
875 SOC_ENUM("DAI1 Filter Mode", max98095_dai1_filter_mode_enum
),
876 SOC_ENUM("DAI2 Filter Mode", max98095_dai2_filter_mode_enum
),
877 SOC_ENUM("DAI1 DAC Filter", max98095_dai1_dac_filter_enum
),
878 SOC_ENUM("DAI2 DAC Filter", max98095_dai2_dac_filter_enum
),
879 SOC_ENUM("DAI3 DAC Filter", max98095_dai3_dac_filter_enum
),
881 SOC_ENUM("Linein Mode", max98095_linein_mode_enum
),
882 SOC_ENUM("Lineout Mode", max98095_lineout_mode_enum
),
885 /* Left speaker mixer switch */
886 static const struct snd_kcontrol_new max98095_left_speaker_mixer_controls
[] = {
887 SOC_DAPM_SINGLE("Left DAC1 Switch", M98095_050_MIX_SPK_LEFT
, 0, 1, 0),
888 SOC_DAPM_SINGLE("Right DAC1 Switch", M98095_050_MIX_SPK_LEFT
, 6, 1, 0),
889 SOC_DAPM_SINGLE("Mono DAC2 Switch", M98095_050_MIX_SPK_LEFT
, 3, 1, 0),
890 SOC_DAPM_SINGLE("Mono DAC3 Switch", M98095_050_MIX_SPK_LEFT
, 3, 1, 0),
891 SOC_DAPM_SINGLE("MIC1 Switch", M98095_050_MIX_SPK_LEFT
, 4, 1, 0),
892 SOC_DAPM_SINGLE("MIC2 Switch", M98095_050_MIX_SPK_LEFT
, 5, 1, 0),
893 SOC_DAPM_SINGLE("IN1 Switch", M98095_050_MIX_SPK_LEFT
, 1, 1, 0),
894 SOC_DAPM_SINGLE("IN2 Switch", M98095_050_MIX_SPK_LEFT
, 2, 1, 0),
897 /* Right speaker mixer switch */
898 static const struct snd_kcontrol_new max98095_right_speaker_mixer_controls
[] = {
899 SOC_DAPM_SINGLE("Left DAC1 Switch", M98095_051_MIX_SPK_RIGHT
, 6, 1, 0),
900 SOC_DAPM_SINGLE("Right DAC1 Switch", M98095_051_MIX_SPK_RIGHT
, 0, 1, 0),
901 SOC_DAPM_SINGLE("Mono DAC2 Switch", M98095_051_MIX_SPK_RIGHT
, 3, 1, 0),
902 SOC_DAPM_SINGLE("Mono DAC3 Switch", M98095_051_MIX_SPK_RIGHT
, 3, 1, 0),
903 SOC_DAPM_SINGLE("MIC1 Switch", M98095_051_MIX_SPK_RIGHT
, 5, 1, 0),
904 SOC_DAPM_SINGLE("MIC2 Switch", M98095_051_MIX_SPK_RIGHT
, 4, 1, 0),
905 SOC_DAPM_SINGLE("IN1 Switch", M98095_051_MIX_SPK_RIGHT
, 1, 1, 0),
906 SOC_DAPM_SINGLE("IN2 Switch", M98095_051_MIX_SPK_RIGHT
, 2, 1, 0),
909 /* Left headphone mixer switch */
910 static const struct snd_kcontrol_new max98095_left_hp_mixer_controls
[] = {
911 SOC_DAPM_SINGLE("Left DAC1 Switch", M98095_04C_MIX_HP_LEFT
, 0, 1, 0),
912 SOC_DAPM_SINGLE("Right DAC1 Switch", M98095_04C_MIX_HP_LEFT
, 5, 1, 0),
913 SOC_DAPM_SINGLE("MIC1 Switch", M98095_04C_MIX_HP_LEFT
, 3, 1, 0),
914 SOC_DAPM_SINGLE("MIC2 Switch", M98095_04C_MIX_HP_LEFT
, 4, 1, 0),
915 SOC_DAPM_SINGLE("IN1 Switch", M98095_04C_MIX_HP_LEFT
, 1, 1, 0),
916 SOC_DAPM_SINGLE("IN2 Switch", M98095_04C_MIX_HP_LEFT
, 2, 1, 0),
919 /* Right headphone mixer switch */
920 static const struct snd_kcontrol_new max98095_right_hp_mixer_controls
[] = {
921 SOC_DAPM_SINGLE("Left DAC1 Switch", M98095_04D_MIX_HP_RIGHT
, 5, 1, 0),
922 SOC_DAPM_SINGLE("Right DAC1 Switch", M98095_04D_MIX_HP_RIGHT
, 0, 1, 0),
923 SOC_DAPM_SINGLE("MIC1 Switch", M98095_04D_MIX_HP_RIGHT
, 3, 1, 0),
924 SOC_DAPM_SINGLE("MIC2 Switch", M98095_04D_MIX_HP_RIGHT
, 4, 1, 0),
925 SOC_DAPM_SINGLE("IN1 Switch", M98095_04D_MIX_HP_RIGHT
, 1, 1, 0),
926 SOC_DAPM_SINGLE("IN2 Switch", M98095_04D_MIX_HP_RIGHT
, 2, 1, 0),
929 /* Receiver earpiece mixer switch */
930 static const struct snd_kcontrol_new max98095_mono_rcv_mixer_controls
[] = {
931 SOC_DAPM_SINGLE("Left DAC1 Switch", M98095_04F_MIX_RCV
, 0, 1, 0),
932 SOC_DAPM_SINGLE("Right DAC1 Switch", M98095_04F_MIX_RCV
, 5, 1, 0),
933 SOC_DAPM_SINGLE("MIC1 Switch", M98095_04F_MIX_RCV
, 3, 1, 0),
934 SOC_DAPM_SINGLE("MIC2 Switch", M98095_04F_MIX_RCV
, 4, 1, 0),
935 SOC_DAPM_SINGLE("IN1 Switch", M98095_04F_MIX_RCV
, 1, 1, 0),
936 SOC_DAPM_SINGLE("IN2 Switch", M98095_04F_MIX_RCV
, 2, 1, 0),
939 /* Left lineout mixer switch */
940 static const struct snd_kcontrol_new max98095_left_lineout_mixer_controls
[] = {
941 SOC_DAPM_SINGLE("Left DAC1 Switch", M98095_053_MIX_LINEOUT1
, 5, 1, 0),
942 SOC_DAPM_SINGLE("Right DAC1 Switch", M98095_053_MIX_LINEOUT1
, 0, 1, 0),
943 SOC_DAPM_SINGLE("MIC1 Switch", M98095_053_MIX_LINEOUT1
, 3, 1, 0),
944 SOC_DAPM_SINGLE("MIC2 Switch", M98095_053_MIX_LINEOUT1
, 4, 1, 0),
945 SOC_DAPM_SINGLE("IN1 Switch", M98095_053_MIX_LINEOUT1
, 1, 1, 0),
946 SOC_DAPM_SINGLE("IN2 Switch", M98095_053_MIX_LINEOUT1
, 2, 1, 0),
949 /* Right lineout mixer switch */
950 static const struct snd_kcontrol_new max98095_right_lineout_mixer_controls
[] = {
951 SOC_DAPM_SINGLE("Left DAC1 Switch", M98095_054_MIX_LINEOUT2
, 0, 1, 0),
952 SOC_DAPM_SINGLE("Right DAC1 Switch", M98095_054_MIX_LINEOUT2
, 5, 1, 0),
953 SOC_DAPM_SINGLE("MIC1 Switch", M98095_054_MIX_LINEOUT2
, 3, 1, 0),
954 SOC_DAPM_SINGLE("MIC2 Switch", M98095_054_MIX_LINEOUT2
, 4, 1, 0),
955 SOC_DAPM_SINGLE("IN1 Switch", M98095_054_MIX_LINEOUT2
, 1, 1, 0),
956 SOC_DAPM_SINGLE("IN2 Switch", M98095_054_MIX_LINEOUT2
, 2, 1, 0),
959 /* Left ADC mixer switch */
960 static const struct snd_kcontrol_new max98095_left_ADC_mixer_controls
[] = {
961 SOC_DAPM_SINGLE("MIC1 Switch", M98095_04A_MIX_ADC_LEFT
, 7, 1, 0),
962 SOC_DAPM_SINGLE("MIC2 Switch", M98095_04A_MIX_ADC_LEFT
, 6, 1, 0),
963 SOC_DAPM_SINGLE("IN1 Switch", M98095_04A_MIX_ADC_LEFT
, 3, 1, 0),
964 SOC_DAPM_SINGLE("IN2 Switch", M98095_04A_MIX_ADC_LEFT
, 2, 1, 0),
967 /* Right ADC mixer switch */
968 static const struct snd_kcontrol_new max98095_right_ADC_mixer_controls
[] = {
969 SOC_DAPM_SINGLE("MIC1 Switch", M98095_04B_MIX_ADC_RIGHT
, 7, 1, 0),
970 SOC_DAPM_SINGLE("MIC2 Switch", M98095_04B_MIX_ADC_RIGHT
, 6, 1, 0),
971 SOC_DAPM_SINGLE("IN1 Switch", M98095_04B_MIX_ADC_RIGHT
, 3, 1, 0),
972 SOC_DAPM_SINGLE("IN2 Switch", M98095_04B_MIX_ADC_RIGHT
, 2, 1, 0),
975 static int max98095_mic_event(struct snd_soc_dapm_widget
*w
,
976 struct snd_kcontrol
*kcontrol
, int event
)
978 struct snd_soc_codec
*codec
= w
->codec
;
979 struct max98095_priv
*max98095
= snd_soc_codec_get_drvdata(codec
);
982 case SND_SOC_DAPM_POST_PMU
:
983 if (w
->reg
== M98095_05F_LVL_MIC1
) {
984 snd_soc_update_bits(codec
, w
->reg
, M98095_MICPRE_MASK
,
985 (1+max98095
->mic1pre
)<<M98095_MICPRE_SHIFT
);
987 snd_soc_update_bits(codec
, w
->reg
, M98095_MICPRE_MASK
,
988 (1+max98095
->mic2pre
)<<M98095_MICPRE_SHIFT
);
991 case SND_SOC_DAPM_POST_PMD
:
992 snd_soc_update_bits(codec
, w
->reg
, M98095_MICPRE_MASK
, 0);
1002 * The line inputs are stereo inputs with the left and right
1003 * channels sharing a common PGA power control signal.
1005 static int max98095_line_pga(struct snd_soc_dapm_widget
*w
,
1006 int event
, u8 channel
)
1008 struct snd_soc_codec
*codec
= w
->codec
;
1009 struct max98095_priv
*max98095
= snd_soc_codec_get_drvdata(codec
);
1012 BUG_ON(!((channel
== 1) || (channel
== 2)));
1014 state
= &max98095
->lin_state
;
1017 case SND_SOC_DAPM_POST_PMU
:
1019 snd_soc_update_bits(codec
, w
->reg
,
1020 (1 << w
->shift
), (1 << w
->shift
));
1022 case SND_SOC_DAPM_POST_PMD
:
1025 snd_soc_update_bits(codec
, w
->reg
,
1026 (1 << w
->shift
), 0);
1036 static int max98095_pga_in1_event(struct snd_soc_dapm_widget
*w
,
1037 struct snd_kcontrol
*k
, int event
)
1039 return max98095_line_pga(w
, event
, 1);
1042 static int max98095_pga_in2_event(struct snd_soc_dapm_widget
*w
,
1043 struct snd_kcontrol
*k
, int event
)
1045 return max98095_line_pga(w
, event
, 2);
1049 * The stereo line out mixer outputs to two stereo line outs.
1050 * The 2nd pair has a separate set of enables.
1052 static int max98095_lineout_event(struct snd_soc_dapm_widget
*w
,
1053 struct snd_kcontrol
*kcontrol
, int event
)
1055 struct snd_soc_codec
*codec
= w
->codec
;
1058 case SND_SOC_DAPM_POST_PMU
:
1059 snd_soc_update_bits(codec
, w
->reg
,
1060 (1 << (w
->shift
+2)), (1 << (w
->shift
+2)));
1062 case SND_SOC_DAPM_POST_PMD
:
1063 snd_soc_update_bits(codec
, w
->reg
,
1064 (1 << (w
->shift
+2)), 0);
1073 static const struct snd_soc_dapm_widget max98095_dapm_widgets
[] = {
1075 SND_SOC_DAPM_ADC("ADCL", "HiFi Capture", M98095_090_PWR_EN_IN
, 0, 0),
1076 SND_SOC_DAPM_ADC("ADCR", "HiFi Capture", M98095_090_PWR_EN_IN
, 1, 0),
1078 SND_SOC_DAPM_DAC("DACL1", "HiFi Playback",
1079 M98095_091_PWR_EN_OUT
, 0, 0),
1080 SND_SOC_DAPM_DAC("DACR1", "HiFi Playback",
1081 M98095_091_PWR_EN_OUT
, 1, 0),
1082 SND_SOC_DAPM_DAC("DACM2", "Aux Playback",
1083 M98095_091_PWR_EN_OUT
, 2, 0),
1084 SND_SOC_DAPM_DAC("DACM3", "Voice Playback",
1085 M98095_091_PWR_EN_OUT
, 2, 0),
1087 SND_SOC_DAPM_PGA("HP Left Out", M98095_091_PWR_EN_OUT
,
1089 SND_SOC_DAPM_PGA("HP Right Out", M98095_091_PWR_EN_OUT
,
1092 SND_SOC_DAPM_PGA("SPK Left Out", M98095_091_PWR_EN_OUT
,
1094 SND_SOC_DAPM_PGA("SPK Right Out", M98095_091_PWR_EN_OUT
,
1097 SND_SOC_DAPM_PGA("RCV Mono Out", M98095_091_PWR_EN_OUT
,
1100 SND_SOC_DAPM_PGA_E("LINE Left Out", M98095_092_PWR_EN_OUT
,
1101 0, 0, NULL
, 0, max98095_lineout_event
, SND_SOC_DAPM_PRE_PMD
),
1102 SND_SOC_DAPM_PGA_E("LINE Right Out", M98095_092_PWR_EN_OUT
,
1103 1, 0, NULL
, 0, max98095_lineout_event
, SND_SOC_DAPM_PRE_PMD
),
1105 SND_SOC_DAPM_MUX("External MIC", SND_SOC_NOPM
, 0, 0,
1106 &max98095_extmic_mux
),
1108 SND_SOC_DAPM_MUX("Linein Mux", SND_SOC_NOPM
, 0, 0,
1109 &max98095_linein_mux
),
1111 SND_SOC_DAPM_MIXER("Left Headphone Mixer", SND_SOC_NOPM
, 0, 0,
1112 &max98095_left_hp_mixer_controls
[0],
1113 ARRAY_SIZE(max98095_left_hp_mixer_controls
)),
1115 SND_SOC_DAPM_MIXER("Right Headphone Mixer", SND_SOC_NOPM
, 0, 0,
1116 &max98095_right_hp_mixer_controls
[0],
1117 ARRAY_SIZE(max98095_right_hp_mixer_controls
)),
1119 SND_SOC_DAPM_MIXER("Left Speaker Mixer", SND_SOC_NOPM
, 0, 0,
1120 &max98095_left_speaker_mixer_controls
[0],
1121 ARRAY_SIZE(max98095_left_speaker_mixer_controls
)),
1123 SND_SOC_DAPM_MIXER("Right Speaker Mixer", SND_SOC_NOPM
, 0, 0,
1124 &max98095_right_speaker_mixer_controls
[0],
1125 ARRAY_SIZE(max98095_right_speaker_mixer_controls
)),
1127 SND_SOC_DAPM_MIXER("Receiver Mixer", SND_SOC_NOPM
, 0, 0,
1128 &max98095_mono_rcv_mixer_controls
[0],
1129 ARRAY_SIZE(max98095_mono_rcv_mixer_controls
)),
1131 SND_SOC_DAPM_MIXER("Left Lineout Mixer", SND_SOC_NOPM
, 0, 0,
1132 &max98095_left_lineout_mixer_controls
[0],
1133 ARRAY_SIZE(max98095_left_lineout_mixer_controls
)),
1135 SND_SOC_DAPM_MIXER("Right Lineout Mixer", SND_SOC_NOPM
, 0, 0,
1136 &max98095_right_lineout_mixer_controls
[0],
1137 ARRAY_SIZE(max98095_right_lineout_mixer_controls
)),
1139 SND_SOC_DAPM_MIXER("Left ADC Mixer", SND_SOC_NOPM
, 0, 0,
1140 &max98095_left_ADC_mixer_controls
[0],
1141 ARRAY_SIZE(max98095_left_ADC_mixer_controls
)),
1143 SND_SOC_DAPM_MIXER("Right ADC Mixer", SND_SOC_NOPM
, 0, 0,
1144 &max98095_right_ADC_mixer_controls
[0],
1145 ARRAY_SIZE(max98095_right_ADC_mixer_controls
)),
1147 SND_SOC_DAPM_PGA_E("MIC1 Input", M98095_05F_LVL_MIC1
,
1148 5, 0, NULL
, 0, max98095_mic_event
,
1149 SND_SOC_DAPM_POST_PMU
| SND_SOC_DAPM_POST_PMD
),
1151 SND_SOC_DAPM_PGA_E("MIC2 Input", M98095_060_LVL_MIC2
,
1152 5, 0, NULL
, 0, max98095_mic_event
,
1153 SND_SOC_DAPM_POST_PMU
| SND_SOC_DAPM_POST_PMD
),
1155 SND_SOC_DAPM_PGA_E("IN1 Input", M98095_090_PWR_EN_IN
,
1156 7, 0, NULL
, 0, max98095_pga_in1_event
,
1157 SND_SOC_DAPM_POST_PMU
| SND_SOC_DAPM_POST_PMD
),
1159 SND_SOC_DAPM_PGA_E("IN2 Input", M98095_090_PWR_EN_IN
,
1160 7, 0, NULL
, 0, max98095_pga_in2_event
,
1161 SND_SOC_DAPM_POST_PMU
| SND_SOC_DAPM_POST_PMD
),
1163 SND_SOC_DAPM_MICBIAS("MICBIAS1", M98095_090_PWR_EN_IN
, 2, 0),
1164 SND_SOC_DAPM_MICBIAS("MICBIAS2", M98095_090_PWR_EN_IN
, 3, 0),
1166 SND_SOC_DAPM_OUTPUT("HPL"),
1167 SND_SOC_DAPM_OUTPUT("HPR"),
1168 SND_SOC_DAPM_OUTPUT("SPKL"),
1169 SND_SOC_DAPM_OUTPUT("SPKR"),
1170 SND_SOC_DAPM_OUTPUT("RCV"),
1171 SND_SOC_DAPM_OUTPUT("OUT1"),
1172 SND_SOC_DAPM_OUTPUT("OUT2"),
1173 SND_SOC_DAPM_OUTPUT("OUT3"),
1174 SND_SOC_DAPM_OUTPUT("OUT4"),
1176 SND_SOC_DAPM_INPUT("MIC1"),
1177 SND_SOC_DAPM_INPUT("MIC2"),
1178 SND_SOC_DAPM_INPUT("INA1"),
1179 SND_SOC_DAPM_INPUT("INA2"),
1180 SND_SOC_DAPM_INPUT("INB1"),
1181 SND_SOC_DAPM_INPUT("INB2"),
1184 static const struct snd_soc_dapm_route max98095_audio_map
[] = {
1185 /* Left headphone output mixer */
1186 {"Left Headphone Mixer", "Left DAC1 Switch", "DACL1"},
1187 {"Left Headphone Mixer", "Right DAC1 Switch", "DACR1"},
1188 {"Left Headphone Mixer", "MIC1 Switch", "MIC1 Input"},
1189 {"Left Headphone Mixer", "MIC2 Switch", "MIC2 Input"},
1190 {"Left Headphone Mixer", "IN1 Switch", "IN1 Input"},
1191 {"Left Headphone Mixer", "IN2 Switch", "IN2 Input"},
1193 /* Right headphone output mixer */
1194 {"Right Headphone Mixer", "Left DAC1 Switch", "DACL1"},
1195 {"Right Headphone Mixer", "Right DAC1 Switch", "DACR1"},
1196 {"Right Headphone Mixer", "MIC1 Switch", "MIC1 Input"},
1197 {"Right Headphone Mixer", "MIC2 Switch", "MIC2 Input"},
1198 {"Right Headphone Mixer", "IN1 Switch", "IN1 Input"},
1199 {"Right Headphone Mixer", "IN2 Switch", "IN2 Input"},
1201 /* Left speaker output mixer */
1202 {"Left Speaker Mixer", "Left DAC1 Switch", "DACL1"},
1203 {"Left Speaker Mixer", "Right DAC1 Switch", "DACR1"},
1204 {"Left Speaker Mixer", "Mono DAC2 Switch", "DACM2"},
1205 {"Left Speaker Mixer", "Mono DAC3 Switch", "DACM3"},
1206 {"Left Speaker Mixer", "MIC1 Switch", "MIC1 Input"},
1207 {"Left Speaker Mixer", "MIC2 Switch", "MIC2 Input"},
1208 {"Left Speaker Mixer", "IN1 Switch", "IN1 Input"},
1209 {"Left Speaker Mixer", "IN2 Switch", "IN2 Input"},
1211 /* Right speaker output mixer */
1212 {"Right Speaker Mixer", "Left DAC1 Switch", "DACL1"},
1213 {"Right Speaker Mixer", "Right DAC1 Switch", "DACR1"},
1214 {"Right Speaker Mixer", "Mono DAC2 Switch", "DACM2"},
1215 {"Right Speaker Mixer", "Mono DAC3 Switch", "DACM3"},
1216 {"Right Speaker Mixer", "MIC1 Switch", "MIC1 Input"},
1217 {"Right Speaker Mixer", "MIC2 Switch", "MIC2 Input"},
1218 {"Right Speaker Mixer", "IN1 Switch", "IN1 Input"},
1219 {"Right Speaker Mixer", "IN2 Switch", "IN2 Input"},
1221 /* Earpiece/Receiver output mixer */
1222 {"Receiver Mixer", "Left DAC1 Switch", "DACL1"},
1223 {"Receiver Mixer", "Right DAC1 Switch", "DACR1"},
1224 {"Receiver Mixer", "MIC1 Switch", "MIC1 Input"},
1225 {"Receiver Mixer", "MIC2 Switch", "MIC2 Input"},
1226 {"Receiver Mixer", "IN1 Switch", "IN1 Input"},
1227 {"Receiver Mixer", "IN2 Switch", "IN2 Input"},
1229 /* Left Lineout output mixer */
1230 {"Left Lineout Mixer", "Left DAC1 Switch", "DACL1"},
1231 {"Left Lineout Mixer", "Right DAC1 Switch", "DACR1"},
1232 {"Left Lineout Mixer", "MIC1 Switch", "MIC1 Input"},
1233 {"Left Lineout Mixer", "MIC2 Switch", "MIC2 Input"},
1234 {"Left Lineout Mixer", "IN1 Switch", "IN1 Input"},
1235 {"Left Lineout Mixer", "IN2 Switch", "IN2 Input"},
1237 /* Right lineout output mixer */
1238 {"Right Lineout Mixer", "Left DAC1 Switch", "DACL1"},
1239 {"Right Lineout Mixer", "Right DAC1 Switch", "DACR1"},
1240 {"Right Lineout Mixer", "MIC1 Switch", "MIC1 Input"},
1241 {"Right Lineout Mixer", "MIC2 Switch", "MIC2 Input"},
1242 {"Right Lineout Mixer", "IN1 Switch", "IN1 Input"},
1243 {"Right Lineout Mixer", "IN2 Switch", "IN2 Input"},
1245 {"HP Left Out", NULL
, "Left Headphone Mixer"},
1246 {"HP Right Out", NULL
, "Right Headphone Mixer"},
1247 {"SPK Left Out", NULL
, "Left Speaker Mixer"},
1248 {"SPK Right Out", NULL
, "Right Speaker Mixer"},
1249 {"RCV Mono Out", NULL
, "Receiver Mixer"},
1250 {"LINE Left Out", NULL
, "Left Lineout Mixer"},
1251 {"LINE Right Out", NULL
, "Right Lineout Mixer"},
1253 {"HPL", NULL
, "HP Left Out"},
1254 {"HPR", NULL
, "HP Right Out"},
1255 {"SPKL", NULL
, "SPK Left Out"},
1256 {"SPKR", NULL
, "SPK Right Out"},
1257 {"RCV", NULL
, "RCV Mono Out"},
1258 {"OUT1", NULL
, "LINE Left Out"},
1259 {"OUT2", NULL
, "LINE Right Out"},
1260 {"OUT3", NULL
, "LINE Left Out"},
1261 {"OUT4", NULL
, "LINE Right Out"},
1263 /* Left ADC input mixer */
1264 {"Left ADC Mixer", "MIC1 Switch", "MIC1 Input"},
1265 {"Left ADC Mixer", "MIC2 Switch", "MIC2 Input"},
1266 {"Left ADC Mixer", "IN1 Switch", "IN1 Input"},
1267 {"Left ADC Mixer", "IN2 Switch", "IN2 Input"},
1269 /* Right ADC input mixer */
1270 {"Right ADC Mixer", "MIC1 Switch", "MIC1 Input"},
1271 {"Right ADC Mixer", "MIC2 Switch", "MIC2 Input"},
1272 {"Right ADC Mixer", "IN1 Switch", "IN1 Input"},
1273 {"Right ADC Mixer", "IN2 Switch", "IN2 Input"},
1276 {"ADCL", NULL
, "Left ADC Mixer"},
1277 {"ADCR", NULL
, "Right ADC Mixer"},
1279 {"IN1 Input", NULL
, "INA1"},
1280 {"IN2 Input", NULL
, "INA2"},
1282 {"MIC1 Input", NULL
, "MIC1"},
1283 {"MIC2 Input", NULL
, "MIC2"},
1286 static int max98095_add_widgets(struct snd_soc_codec
*codec
)
1288 snd_soc_add_controls(codec
, max98095_snd_controls
,
1289 ARRAY_SIZE(max98095_snd_controls
));
1294 /* codec mclk clock divider coefficients */
1295 static const struct {
1311 static int rate_value(int rate
, u8
*value
)
1315 for (i
= 0; i
< ARRAY_SIZE(rate_table
); i
++) {
1316 if (rate_table
[i
].rate
>= rate
) {
1317 *value
= rate_table
[i
].sr
;
1321 *value
= rate_table
[0].sr
;
1325 static int max98095_dai1_hw_params(struct snd_pcm_substream
*substream
,
1326 struct snd_pcm_hw_params
*params
,
1327 struct snd_soc_dai
*dai
)
1329 struct snd_soc_codec
*codec
= dai
->codec
;
1330 struct max98095_priv
*max98095
= snd_soc_codec_get_drvdata(codec
);
1331 struct max98095_cdata
*cdata
;
1332 unsigned long long ni
;
1336 cdata
= &max98095
->dai
[0];
1338 rate
= params_rate(params
);
1340 switch (params_format(params
)) {
1341 case SNDRV_PCM_FORMAT_S16_LE
:
1342 snd_soc_update_bits(codec
, M98095_02A_DAI1_FORMAT
,
1345 case SNDRV_PCM_FORMAT_S24_LE
:
1346 snd_soc_update_bits(codec
, M98095_02A_DAI1_FORMAT
,
1347 M98095_DAI_WS
, M98095_DAI_WS
);
1353 if (rate_value(rate
, ®val
))
1356 snd_soc_update_bits(codec
, M98095_027_DAI1_CLKMODE
,
1357 M98095_CLKMODE_MASK
, regval
);
1360 /* Configure NI when operating as master */
1361 if (snd_soc_read(codec
, M98095_02A_DAI1_FORMAT
) & M98095_DAI_MAS
) {
1362 if (max98095
->sysclk
== 0) {
1363 dev_err(codec
->dev
, "Invalid system clock frequency\n");
1366 ni
= 65536ULL * (rate
< 50000 ? 96ULL : 48ULL)
1367 * (unsigned long long int)rate
;
1368 do_div(ni
, (unsigned long long int)max98095
->sysclk
);
1369 snd_soc_write(codec
, M98095_028_DAI1_CLKCFG_HI
,
1371 snd_soc_write(codec
, M98095_029_DAI1_CLKCFG_LO
,
1375 /* Update sample rate mode */
1377 snd_soc_update_bits(codec
, M98095_02E_DAI1_FILTERS
,
1380 snd_soc_update_bits(codec
, M98095_02E_DAI1_FILTERS
,
1381 M98095_DAI_DHF
, M98095_DAI_DHF
);
1386 static int max98095_dai2_hw_params(struct snd_pcm_substream
*substream
,
1387 struct snd_pcm_hw_params
*params
,
1388 struct snd_soc_dai
*dai
)
1390 struct snd_soc_codec
*codec
= dai
->codec
;
1391 struct max98095_priv
*max98095
= snd_soc_codec_get_drvdata(codec
);
1392 struct max98095_cdata
*cdata
;
1393 unsigned long long ni
;
1397 cdata
= &max98095
->dai
[1];
1399 rate
= params_rate(params
);
1401 switch (params_format(params
)) {
1402 case SNDRV_PCM_FORMAT_S16_LE
:
1403 snd_soc_update_bits(codec
, M98095_034_DAI2_FORMAT
,
1406 case SNDRV_PCM_FORMAT_S24_LE
:
1407 snd_soc_update_bits(codec
, M98095_034_DAI2_FORMAT
,
1408 M98095_DAI_WS
, M98095_DAI_WS
);
1414 if (rate_value(rate
, ®val
))
1417 snd_soc_update_bits(codec
, M98095_031_DAI2_CLKMODE
,
1418 M98095_CLKMODE_MASK
, regval
);
1421 /* Configure NI when operating as master */
1422 if (snd_soc_read(codec
, M98095_034_DAI2_FORMAT
) & M98095_DAI_MAS
) {
1423 if (max98095
->sysclk
== 0) {
1424 dev_err(codec
->dev
, "Invalid system clock frequency\n");
1427 ni
= 65536ULL * (rate
< 50000 ? 96ULL : 48ULL)
1428 * (unsigned long long int)rate
;
1429 do_div(ni
, (unsigned long long int)max98095
->sysclk
);
1430 snd_soc_write(codec
, M98095_032_DAI2_CLKCFG_HI
,
1432 snd_soc_write(codec
, M98095_033_DAI2_CLKCFG_LO
,
1436 /* Update sample rate mode */
1438 snd_soc_update_bits(codec
, M98095_038_DAI2_FILTERS
,
1441 snd_soc_update_bits(codec
, M98095_038_DAI2_FILTERS
,
1442 M98095_DAI_DHF
, M98095_DAI_DHF
);
1447 static int max98095_dai3_hw_params(struct snd_pcm_substream
*substream
,
1448 struct snd_pcm_hw_params
*params
,
1449 struct snd_soc_dai
*dai
)
1451 struct snd_soc_codec
*codec
= dai
->codec
;
1452 struct max98095_priv
*max98095
= snd_soc_codec_get_drvdata(codec
);
1453 struct max98095_cdata
*cdata
;
1454 unsigned long long ni
;
1458 cdata
= &max98095
->dai
[2];
1460 rate
= params_rate(params
);
1462 switch (params_format(params
)) {
1463 case SNDRV_PCM_FORMAT_S16_LE
:
1464 snd_soc_update_bits(codec
, M98095_03E_DAI3_FORMAT
,
1467 case SNDRV_PCM_FORMAT_S24_LE
:
1468 snd_soc_update_bits(codec
, M98095_03E_DAI3_FORMAT
,
1469 M98095_DAI_WS
, M98095_DAI_WS
);
1475 if (rate_value(rate
, ®val
))
1478 snd_soc_update_bits(codec
, M98095_03B_DAI3_CLKMODE
,
1479 M98095_CLKMODE_MASK
, regval
);
1482 /* Configure NI when operating as master */
1483 if (snd_soc_read(codec
, M98095_03E_DAI3_FORMAT
) & M98095_DAI_MAS
) {
1484 if (max98095
->sysclk
== 0) {
1485 dev_err(codec
->dev
, "Invalid system clock frequency\n");
1488 ni
= 65536ULL * (rate
< 50000 ? 96ULL : 48ULL)
1489 * (unsigned long long int)rate
;
1490 do_div(ni
, (unsigned long long int)max98095
->sysclk
);
1491 snd_soc_write(codec
, M98095_03C_DAI3_CLKCFG_HI
,
1493 snd_soc_write(codec
, M98095_03D_DAI3_CLKCFG_LO
,
1497 /* Update sample rate mode */
1499 snd_soc_update_bits(codec
, M98095_042_DAI3_FILTERS
,
1502 snd_soc_update_bits(codec
, M98095_042_DAI3_FILTERS
,
1503 M98095_DAI_DHF
, M98095_DAI_DHF
);
1508 static int max98095_dai_set_sysclk(struct snd_soc_dai
*dai
,
1509 int clk_id
, unsigned int freq
, int dir
)
1511 struct snd_soc_codec
*codec
= dai
->codec
;
1512 struct max98095_priv
*max98095
= snd_soc_codec_get_drvdata(codec
);
1514 /* Requested clock frequency is already setup */
1515 if (freq
== max98095
->sysclk
)
1518 /* Setup clocks for slave mode, and using the PLL
1519 * PSCLK = 0x01 (when master clk is 10MHz to 20MHz)
1520 * 0x02 (when master clk is 20MHz to 40MHz)..
1521 * 0x03 (when master clk is 40MHz to 60MHz)..
1523 if ((freq
>= 10000000) && (freq
< 20000000)) {
1524 snd_soc_write(codec
, M98095_026_SYS_CLK
, 0x10);
1525 } else if ((freq
>= 20000000) && (freq
< 40000000)) {
1526 snd_soc_write(codec
, M98095_026_SYS_CLK
, 0x20);
1527 } else if ((freq
>= 40000000) && (freq
< 60000000)) {
1528 snd_soc_write(codec
, M98095_026_SYS_CLK
, 0x30);
1530 dev_err(codec
->dev
, "Invalid master clock frequency\n");
1534 dev_dbg(dai
->dev
, "Clock source is %d at %uHz\n", clk_id
, freq
);
1536 max98095
->sysclk
= freq
;
1540 static int max98095_dai1_set_fmt(struct snd_soc_dai
*codec_dai
,
1543 struct snd_soc_codec
*codec
= codec_dai
->codec
;
1544 struct max98095_priv
*max98095
= snd_soc_codec_get_drvdata(codec
);
1545 struct max98095_cdata
*cdata
;
1548 cdata
= &max98095
->dai
[0];
1550 if (fmt
!= cdata
->fmt
) {
1553 switch (fmt
& SND_SOC_DAIFMT_MASTER_MASK
) {
1554 case SND_SOC_DAIFMT_CBS_CFS
:
1555 /* Slave mode PLL */
1556 snd_soc_write(codec
, M98095_028_DAI1_CLKCFG_HI
,
1558 snd_soc_write(codec
, M98095_029_DAI1_CLKCFG_LO
,
1561 case SND_SOC_DAIFMT_CBM_CFM
:
1562 /* Set to master mode */
1563 regval
|= M98095_DAI_MAS
;
1565 case SND_SOC_DAIFMT_CBS_CFM
:
1566 case SND_SOC_DAIFMT_CBM_CFS
:
1568 dev_err(codec
->dev
, "Clock mode unsupported");
1572 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
1573 case SND_SOC_DAIFMT_I2S
:
1574 regval
|= M98095_DAI_DLY
;
1576 case SND_SOC_DAIFMT_LEFT_J
:
1582 switch (fmt
& SND_SOC_DAIFMT_INV_MASK
) {
1583 case SND_SOC_DAIFMT_NB_NF
:
1585 case SND_SOC_DAIFMT_NB_IF
:
1586 regval
|= M98095_DAI_WCI
;
1588 case SND_SOC_DAIFMT_IB_NF
:
1589 regval
|= M98095_DAI_BCI
;
1591 case SND_SOC_DAIFMT_IB_IF
:
1592 regval
|= M98095_DAI_BCI
|M98095_DAI_WCI
;
1598 snd_soc_update_bits(codec
, M98095_02A_DAI1_FORMAT
,
1599 M98095_DAI_MAS
| M98095_DAI_DLY
| M98095_DAI_BCI
|
1600 M98095_DAI_WCI
, regval
);
1602 snd_soc_write(codec
, M98095_02B_DAI1_CLOCK
, M98095_DAI_BSEL64
);
1608 static int max98095_dai2_set_fmt(struct snd_soc_dai
*codec_dai
,
1611 struct snd_soc_codec
*codec
= codec_dai
->codec
;
1612 struct max98095_priv
*max98095
= snd_soc_codec_get_drvdata(codec
);
1613 struct max98095_cdata
*cdata
;
1616 cdata
= &max98095
->dai
[1];
1618 if (fmt
!= cdata
->fmt
) {
1621 switch (fmt
& SND_SOC_DAIFMT_MASTER_MASK
) {
1622 case SND_SOC_DAIFMT_CBS_CFS
:
1623 /* Slave mode PLL */
1624 snd_soc_write(codec
, M98095_032_DAI2_CLKCFG_HI
,
1626 snd_soc_write(codec
, M98095_033_DAI2_CLKCFG_LO
,
1629 case SND_SOC_DAIFMT_CBM_CFM
:
1630 /* Set to master mode */
1631 regval
|= M98095_DAI_MAS
;
1633 case SND_SOC_DAIFMT_CBS_CFM
:
1634 case SND_SOC_DAIFMT_CBM_CFS
:
1636 dev_err(codec
->dev
, "Clock mode unsupported");
1640 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
1641 case SND_SOC_DAIFMT_I2S
:
1642 regval
|= M98095_DAI_DLY
;
1644 case SND_SOC_DAIFMT_LEFT_J
:
1650 switch (fmt
& SND_SOC_DAIFMT_INV_MASK
) {
1651 case SND_SOC_DAIFMT_NB_NF
:
1653 case SND_SOC_DAIFMT_NB_IF
:
1654 regval
|= M98095_DAI_WCI
;
1656 case SND_SOC_DAIFMT_IB_NF
:
1657 regval
|= M98095_DAI_BCI
;
1659 case SND_SOC_DAIFMT_IB_IF
:
1660 regval
|= M98095_DAI_BCI
|M98095_DAI_WCI
;
1666 snd_soc_update_bits(codec
, M98095_034_DAI2_FORMAT
,
1667 M98095_DAI_MAS
| M98095_DAI_DLY
| M98095_DAI_BCI
|
1668 M98095_DAI_WCI
, regval
);
1670 snd_soc_write(codec
, M98095_035_DAI2_CLOCK
,
1677 static int max98095_dai3_set_fmt(struct snd_soc_dai
*codec_dai
,
1680 struct snd_soc_codec
*codec
= codec_dai
->codec
;
1681 struct max98095_priv
*max98095
= snd_soc_codec_get_drvdata(codec
);
1682 struct max98095_cdata
*cdata
;
1685 cdata
= &max98095
->dai
[2];
1687 if (fmt
!= cdata
->fmt
) {
1690 switch (fmt
& SND_SOC_DAIFMT_MASTER_MASK
) {
1691 case SND_SOC_DAIFMT_CBS_CFS
:
1692 /* Slave mode PLL */
1693 snd_soc_write(codec
, M98095_03C_DAI3_CLKCFG_HI
,
1695 snd_soc_write(codec
, M98095_03D_DAI3_CLKCFG_LO
,
1698 case SND_SOC_DAIFMT_CBM_CFM
:
1699 /* Set to master mode */
1700 regval
|= M98095_DAI_MAS
;
1702 case SND_SOC_DAIFMT_CBS_CFM
:
1703 case SND_SOC_DAIFMT_CBM_CFS
:
1705 dev_err(codec
->dev
, "Clock mode unsupported");
1709 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
1710 case SND_SOC_DAIFMT_I2S
:
1711 regval
|= M98095_DAI_DLY
;
1713 case SND_SOC_DAIFMT_LEFT_J
:
1719 switch (fmt
& SND_SOC_DAIFMT_INV_MASK
) {
1720 case SND_SOC_DAIFMT_NB_NF
:
1722 case SND_SOC_DAIFMT_NB_IF
:
1723 regval
|= M98095_DAI_WCI
;
1725 case SND_SOC_DAIFMT_IB_NF
:
1726 regval
|= M98095_DAI_BCI
;
1728 case SND_SOC_DAIFMT_IB_IF
:
1729 regval
|= M98095_DAI_BCI
|M98095_DAI_WCI
;
1735 snd_soc_update_bits(codec
, M98095_03E_DAI3_FORMAT
,
1736 M98095_DAI_MAS
| M98095_DAI_DLY
| M98095_DAI_BCI
|
1737 M98095_DAI_WCI
, regval
);
1739 snd_soc_write(codec
, M98095_03F_DAI3_CLOCK
,
1746 static int max98095_set_bias_level(struct snd_soc_codec
*codec
,
1747 enum snd_soc_bias_level level
)
1752 case SND_SOC_BIAS_ON
:
1755 case SND_SOC_BIAS_PREPARE
:
1758 case SND_SOC_BIAS_STANDBY
:
1759 if (codec
->dapm
.bias_level
== SND_SOC_BIAS_OFF
) {
1760 ret
= snd_soc_cache_sync(codec
);
1763 dev_err(codec
->dev
, "Failed to sync cache: %d\n", ret
);
1768 snd_soc_update_bits(codec
, M98095_090_PWR_EN_IN
,
1769 M98095_MBEN
, M98095_MBEN
);
1772 case SND_SOC_BIAS_OFF
:
1773 snd_soc_update_bits(codec
, M98095_090_PWR_EN_IN
,
1775 codec
->cache_sync
= 1;
1778 codec
->dapm
.bias_level
= level
;
1782 #define MAX98095_RATES SNDRV_PCM_RATE_8000_96000
1783 #define MAX98095_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE)
1785 static struct snd_soc_dai_ops max98095_dai1_ops
= {
1786 .set_sysclk
= max98095_dai_set_sysclk
,
1787 .set_fmt
= max98095_dai1_set_fmt
,
1788 .hw_params
= max98095_dai1_hw_params
,
1791 static struct snd_soc_dai_ops max98095_dai2_ops
= {
1792 .set_sysclk
= max98095_dai_set_sysclk
,
1793 .set_fmt
= max98095_dai2_set_fmt
,
1794 .hw_params
= max98095_dai2_hw_params
,
1797 static struct snd_soc_dai_ops max98095_dai3_ops
= {
1798 .set_sysclk
= max98095_dai_set_sysclk
,
1799 .set_fmt
= max98095_dai3_set_fmt
,
1800 .hw_params
= max98095_dai3_hw_params
,
1803 static struct snd_soc_dai_driver max98095_dai
[] = {
1807 .stream_name
= "HiFi Playback",
1810 .rates
= MAX98095_RATES
,
1811 .formats
= MAX98095_FORMATS
,
1814 .stream_name
= "HiFi Capture",
1817 .rates
= MAX98095_RATES
,
1818 .formats
= MAX98095_FORMATS
,
1820 .ops
= &max98095_dai1_ops
,
1825 .stream_name
= "Aux Playback",
1828 .rates
= MAX98095_RATES
,
1829 .formats
= MAX98095_FORMATS
,
1831 .ops
= &max98095_dai2_ops
,
1836 .stream_name
= "Voice Playback",
1839 .rates
= MAX98095_RATES
,
1840 .formats
= MAX98095_FORMATS
,
1842 .ops
= &max98095_dai3_ops
,
1847 static int max98095_get_eq_channel(const char *name
)
1849 if (strcmp(name
, "EQ1 Mode") == 0)
1851 if (strcmp(name
, "EQ2 Mode") == 0)
1856 static int max98095_put_eq_enum(struct snd_kcontrol
*kcontrol
,
1857 struct snd_ctl_elem_value
*ucontrol
)
1859 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1860 struct max98095_priv
*max98095
= snd_soc_codec_get_drvdata(codec
);
1861 struct max98095_pdata
*pdata
= max98095
->pdata
;
1862 int channel
= max98095_get_eq_channel(kcontrol
->id
.name
);
1863 struct max98095_cdata
*cdata
;
1864 int sel
= ucontrol
->value
.integer
.value
[0];
1865 struct max98095_eq_cfg
*coef_set
;
1866 int fs
, best
, best_val
, i
;
1867 int regmask
, regsave
;
1869 BUG_ON(channel
> 1);
1871 if (!pdata
|| !max98095
->eq_textcnt
)
1874 if (sel
>= pdata
->eq_cfgcnt
)
1877 cdata
= &max98095
->dai
[channel
];
1878 cdata
->eq_sel
= sel
;
1881 /* Find the selected configuration with nearest sample rate */
1884 for (i
= 0; i
< pdata
->eq_cfgcnt
; i
++) {
1885 if (strcmp(pdata
->eq_cfg
[i
].name
, max98095
->eq_texts
[sel
]) == 0 &&
1886 abs(pdata
->eq_cfg
[i
].rate
- fs
) < best_val
) {
1888 best_val
= abs(pdata
->eq_cfg
[i
].rate
- fs
);
1892 dev_dbg(codec
->dev
, "Selected %s/%dHz for %dHz sample rate\n",
1893 pdata
->eq_cfg
[best
].name
,
1894 pdata
->eq_cfg
[best
].rate
, fs
);
1896 coef_set
= &pdata
->eq_cfg
[best
];
1898 regmask
= (channel
== 0) ? M98095_EQ1EN
: M98095_EQ2EN
;
1900 /* Disable filter while configuring, and save current on/off state */
1901 regsave
= snd_soc_read(codec
, M98095_088_CFG_LEVEL
);
1902 snd_soc_update_bits(codec
, M98095_088_CFG_LEVEL
, regmask
, 0);
1904 mutex_lock(&codec
->mutex
);
1905 snd_soc_update_bits(codec
, M98095_00F_HOST_CFG
, M98095_SEG
, M98095_SEG
);
1906 m98095_eq_band(codec
, channel
, 0, coef_set
->band1
);
1907 m98095_eq_band(codec
, channel
, 1, coef_set
->band2
);
1908 m98095_eq_band(codec
, channel
, 2, coef_set
->band3
);
1909 m98095_eq_band(codec
, channel
, 3, coef_set
->band4
);
1910 m98095_eq_band(codec
, channel
, 4, coef_set
->band5
);
1911 snd_soc_update_bits(codec
, M98095_00F_HOST_CFG
, M98095_SEG
, 0);
1912 mutex_unlock(&codec
->mutex
);
1914 /* Restore the original on/off state */
1915 snd_soc_update_bits(codec
, M98095_088_CFG_LEVEL
, regmask
, regsave
);
1919 static int max98095_get_eq_enum(struct snd_kcontrol
*kcontrol
,
1920 struct snd_ctl_elem_value
*ucontrol
)
1922 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1923 struct max98095_priv
*max98095
= snd_soc_codec_get_drvdata(codec
);
1924 int channel
= max98095_get_eq_channel(kcontrol
->id
.name
);
1925 struct max98095_cdata
*cdata
;
1927 cdata
= &max98095
->dai
[channel
];
1928 ucontrol
->value
.enumerated
.item
[0] = cdata
->eq_sel
;
1933 static void max98095_handle_eq_pdata(struct snd_soc_codec
*codec
)
1935 struct max98095_priv
*max98095
= snd_soc_codec_get_drvdata(codec
);
1936 struct max98095_pdata
*pdata
= max98095
->pdata
;
1937 struct max98095_eq_cfg
*cfg
;
1938 unsigned int cfgcnt
;
1943 struct snd_kcontrol_new controls
[] = {
1944 SOC_ENUM_EXT("EQ1 Mode",
1946 max98095_get_eq_enum
,
1947 max98095_put_eq_enum
),
1948 SOC_ENUM_EXT("EQ2 Mode",
1950 max98095_get_eq_enum
,
1951 max98095_put_eq_enum
),
1954 cfg
= pdata
->eq_cfg
;
1955 cfgcnt
= pdata
->eq_cfgcnt
;
1957 /* Setup an array of texts for the equalizer enum.
1958 * This is based on Mark Brown's equalizer driver code.
1960 max98095
->eq_textcnt
= 0;
1961 max98095
->eq_texts
= NULL
;
1962 for (i
= 0; i
< cfgcnt
; i
++) {
1963 for (j
= 0; j
< max98095
->eq_textcnt
; j
++) {
1964 if (strcmp(cfg
[i
].name
, max98095
->eq_texts
[j
]) == 0)
1968 if (j
!= max98095
->eq_textcnt
)
1971 /* Expand the array */
1972 t
= krealloc(max98095
->eq_texts
,
1973 sizeof(char *) * (max98095
->eq_textcnt
+ 1),
1978 /* Store the new entry */
1979 t
[max98095
->eq_textcnt
] = cfg
[i
].name
;
1980 max98095
->eq_textcnt
++;
1981 max98095
->eq_texts
= t
;
1984 /* Now point the soc_enum to .texts array items */
1985 max98095
->eq_enum
.texts
= max98095
->eq_texts
;
1986 max98095
->eq_enum
.max
= max98095
->eq_textcnt
;
1988 ret
= snd_soc_add_controls(codec
, controls
, ARRAY_SIZE(controls
));
1990 dev_err(codec
->dev
, "Failed to add EQ control: %d\n", ret
);
1993 static const char *bq_mode_name
[] = {"Biquad1 Mode", "Biquad2 Mode"};
1995 static int max98095_get_bq_channel(struct snd_soc_codec
*codec
,
2000 for (i
= 0; i
< ARRAY_SIZE(bq_mode_name
); i
++)
2001 if (strcmp(name
, bq_mode_name
[i
]) == 0)
2004 /* Shouldn't happen */
2005 dev_err(codec
->dev
, "Bad biquad channel name '%s'\n", name
);
2009 static int max98095_put_bq_enum(struct snd_kcontrol
*kcontrol
,
2010 struct snd_ctl_elem_value
*ucontrol
)
2012 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2013 struct max98095_priv
*max98095
= snd_soc_codec_get_drvdata(codec
);
2014 struct max98095_pdata
*pdata
= max98095
->pdata
;
2015 int channel
= max98095_get_bq_channel(codec
, kcontrol
->id
.name
);
2016 struct max98095_cdata
*cdata
;
2017 int sel
= ucontrol
->value
.integer
.value
[0];
2018 struct max98095_biquad_cfg
*coef_set
;
2019 int fs
, best
, best_val
, i
;
2020 int regmask
, regsave
;
2025 if (!pdata
|| !max98095
->bq_textcnt
)
2028 if (sel
>= pdata
->bq_cfgcnt
)
2031 cdata
= &max98095
->dai
[channel
];
2032 cdata
->bq_sel
= sel
;
2035 /* Find the selected configuration with nearest sample rate */
2038 for (i
= 0; i
< pdata
->bq_cfgcnt
; i
++) {
2039 if (strcmp(pdata
->bq_cfg
[i
].name
, max98095
->bq_texts
[sel
]) == 0 &&
2040 abs(pdata
->bq_cfg
[i
].rate
- fs
) < best_val
) {
2042 best_val
= abs(pdata
->bq_cfg
[i
].rate
- fs
);
2046 dev_dbg(codec
->dev
, "Selected %s/%dHz for %dHz sample rate\n",
2047 pdata
->bq_cfg
[best
].name
,
2048 pdata
->bq_cfg
[best
].rate
, fs
);
2050 coef_set
= &pdata
->bq_cfg
[best
];
2052 regmask
= (channel
== 0) ? M98095_BQ1EN
: M98095_BQ2EN
;
2054 /* Disable filter while configuring, and save current on/off state */
2055 regsave
= snd_soc_read(codec
, M98095_088_CFG_LEVEL
);
2056 snd_soc_update_bits(codec
, M98095_088_CFG_LEVEL
, regmask
, 0);
2058 mutex_lock(&codec
->mutex
);
2059 snd_soc_update_bits(codec
, M98095_00F_HOST_CFG
, M98095_SEG
, M98095_SEG
);
2060 m98095_biquad_band(codec
, channel
, 0, coef_set
->band1
);
2061 m98095_biquad_band(codec
, channel
, 1, coef_set
->band2
);
2062 snd_soc_update_bits(codec
, M98095_00F_HOST_CFG
, M98095_SEG
, 0);
2063 mutex_unlock(&codec
->mutex
);
2065 /* Restore the original on/off state */
2066 snd_soc_update_bits(codec
, M98095_088_CFG_LEVEL
, regmask
, regsave
);
2070 static int max98095_get_bq_enum(struct snd_kcontrol
*kcontrol
,
2071 struct snd_ctl_elem_value
*ucontrol
)
2073 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2074 struct max98095_priv
*max98095
= snd_soc_codec_get_drvdata(codec
);
2075 int channel
= max98095_get_bq_channel(codec
, kcontrol
->id
.name
);
2076 struct max98095_cdata
*cdata
;
2081 cdata
= &max98095
->dai
[channel
];
2082 ucontrol
->value
.enumerated
.item
[0] = cdata
->bq_sel
;
2087 static void max98095_handle_bq_pdata(struct snd_soc_codec
*codec
)
2089 struct max98095_priv
*max98095
= snd_soc_codec_get_drvdata(codec
);
2090 struct max98095_pdata
*pdata
= max98095
->pdata
;
2091 struct max98095_biquad_cfg
*cfg
;
2092 unsigned int cfgcnt
;
2097 struct snd_kcontrol_new controls
[] = {
2098 SOC_ENUM_EXT((char *)bq_mode_name
[0],
2100 max98095_get_bq_enum
,
2101 max98095_put_bq_enum
),
2102 SOC_ENUM_EXT((char *)bq_mode_name
[1],
2104 max98095_get_bq_enum
,
2105 max98095_put_bq_enum
),
2107 BUILD_BUG_ON(ARRAY_SIZE(controls
) != ARRAY_SIZE(bq_mode_name
));
2109 cfg
= pdata
->bq_cfg
;
2110 cfgcnt
= pdata
->bq_cfgcnt
;
2112 /* Setup an array of texts for the biquad enum.
2113 * This is based on Mark Brown's equalizer driver code.
2115 max98095
->bq_textcnt
= 0;
2116 max98095
->bq_texts
= NULL
;
2117 for (i
= 0; i
< cfgcnt
; i
++) {
2118 for (j
= 0; j
< max98095
->bq_textcnt
; j
++) {
2119 if (strcmp(cfg
[i
].name
, max98095
->bq_texts
[j
]) == 0)
2123 if (j
!= max98095
->bq_textcnt
)
2126 /* Expand the array */
2127 t
= krealloc(max98095
->bq_texts
,
2128 sizeof(char *) * (max98095
->bq_textcnt
+ 1),
2133 /* Store the new entry */
2134 t
[max98095
->bq_textcnt
] = cfg
[i
].name
;
2135 max98095
->bq_textcnt
++;
2136 max98095
->bq_texts
= t
;
2139 /* Now point the soc_enum to .texts array items */
2140 max98095
->bq_enum
.texts
= max98095
->bq_texts
;
2141 max98095
->bq_enum
.max
= max98095
->bq_textcnt
;
2143 ret
= snd_soc_add_controls(codec
, controls
, ARRAY_SIZE(controls
));
2145 dev_err(codec
->dev
, "Failed to add Biquad control: %d\n", ret
);
2148 static void max98095_handle_pdata(struct snd_soc_codec
*codec
)
2150 struct max98095_priv
*max98095
= snd_soc_codec_get_drvdata(codec
);
2151 struct max98095_pdata
*pdata
= max98095
->pdata
;
2155 dev_dbg(codec
->dev
, "No platform data\n");
2159 /* Configure mic for analog/digital mic mode */
2160 if (pdata
->digmic_left_mode
)
2161 regval
|= M98095_DIGMIC_L
;
2163 if (pdata
->digmic_right_mode
)
2164 regval
|= M98095_DIGMIC_R
;
2166 snd_soc_write(codec
, M98095_087_CFG_MIC
, regval
);
2168 /* Configure equalizers */
2169 if (pdata
->eq_cfgcnt
)
2170 max98095_handle_eq_pdata(codec
);
2172 /* Configure bi-quad filters */
2173 if (pdata
->bq_cfgcnt
)
2174 max98095_handle_bq_pdata(codec
);
2178 static int max98095_suspend(struct snd_soc_codec
*codec
, pm_message_t state
)
2180 max98095_set_bias_level(codec
, SND_SOC_BIAS_OFF
);
2185 static int max98095_resume(struct snd_soc_codec
*codec
)
2187 max98095_set_bias_level(codec
, SND_SOC_BIAS_STANDBY
);
2192 #define max98095_suspend NULL
2193 #define max98095_resume NULL
2196 static int max98095_reset(struct snd_soc_codec
*codec
)
2200 /* Gracefully reset the DSP core and the codec hardware
2201 * in a proper sequence */
2202 ret
= snd_soc_write(codec
, M98095_00F_HOST_CFG
, 0);
2204 dev_err(codec
->dev
, "Failed to reset DSP: %d\n", ret
);
2208 ret
= snd_soc_write(codec
, M98095_097_PWR_SYS
, 0);
2210 dev_err(codec
->dev
, "Failed to reset codec: %d\n", ret
);
2214 /* Reset to hardware default for registers, as there is not
2215 * a soft reset hardware control register */
2216 for (i
= M98095_010_HOST_INT_CFG
; i
< M98095_REG_MAX_CACHED
; i
++) {
2217 ret
= snd_soc_write(codec
, i
, max98095_reg_def
[i
]);
2219 dev_err(codec
->dev
, "Failed to reset: %d\n", ret
);
2227 static int max98095_probe(struct snd_soc_codec
*codec
)
2229 struct max98095_priv
*max98095
= snd_soc_codec_get_drvdata(codec
);
2230 struct max98095_cdata
*cdata
;
2233 ret
= snd_soc_codec_set_cache_io(codec
, 8, 8, SND_SOC_I2C
);
2235 dev_err(codec
->dev
, "Failed to set cache I/O: %d\n", ret
);
2239 /* reset the codec, the DSP core, and disable all interrupts */
2240 max98095_reset(codec
);
2242 /* initialize private data */
2244 max98095
->sysclk
= (unsigned)-1;
2245 max98095
->eq_textcnt
= 0;
2246 max98095
->bq_textcnt
= 0;
2248 cdata
= &max98095
->dai
[0];
2249 cdata
->rate
= (unsigned)-1;
2250 cdata
->fmt
= (unsigned)-1;
2254 cdata
= &max98095
->dai
[1];
2255 cdata
->rate
= (unsigned)-1;
2256 cdata
->fmt
= (unsigned)-1;
2260 cdata
= &max98095
->dai
[2];
2261 cdata
->rate
= (unsigned)-1;
2262 cdata
->fmt
= (unsigned)-1;
2266 max98095
->lin_state
= 0;
2267 max98095
->mic1pre
= 0;
2268 max98095
->mic2pre
= 0;
2270 ret
= snd_soc_read(codec
, M98095_0FF_REV_ID
);
2272 dev_err(codec
->dev
, "Failure reading hardware revision: %d\n",
2276 dev_info(codec
->dev
, "Hardware revision: %c\n", ret
- 0x40 + 'A');
2278 snd_soc_write(codec
, M98095_097_PWR_SYS
, M98095_PWRSV
);
2280 /* initialize registers cache to hardware default */
2281 max98095_set_bias_level(codec
, SND_SOC_BIAS_STANDBY
);
2283 snd_soc_write(codec
, M98095_048_MIX_DAC_LR
,
2284 M98095_DAI1L_TO_DACL
|M98095_DAI1R_TO_DACR
);
2286 snd_soc_write(codec
, M98095_049_MIX_DAC_M
,
2287 M98095_DAI2M_TO_DACM
|M98095_DAI3M_TO_DACM
);
2289 snd_soc_write(codec
, M98095_092_PWR_EN_OUT
, M98095_SPK_SPREADSPECTRUM
);
2290 snd_soc_write(codec
, M98095_045_CFG_DSP
, M98095_DSPNORMAL
);
2291 snd_soc_write(codec
, M98095_04E_CFG_HP
, M98095_HPNORMAL
);
2293 snd_soc_write(codec
, M98095_02C_DAI1_IOCFG
,
2294 M98095_S1NORMAL
|M98095_SDATA
);
2296 snd_soc_write(codec
, M98095_036_DAI2_IOCFG
,
2297 M98095_S2NORMAL
|M98095_SDATA
);
2299 snd_soc_write(codec
, M98095_040_DAI3_IOCFG
,
2300 M98095_S3NORMAL
|M98095_SDATA
);
2302 max98095_handle_pdata(codec
);
2304 /* take the codec out of the shut down */
2305 snd_soc_update_bits(codec
, M98095_097_PWR_SYS
, M98095_SHDNRUN
,
2308 max98095_add_widgets(codec
);
2314 static int max98095_remove(struct snd_soc_codec
*codec
)
2316 max98095_set_bias_level(codec
, SND_SOC_BIAS_OFF
);
2321 static struct snd_soc_codec_driver soc_codec_dev_max98095
= {
2322 .probe
= max98095_probe
,
2323 .remove
= max98095_remove
,
2324 .suspend
= max98095_suspend
,
2325 .resume
= max98095_resume
,
2326 .set_bias_level
= max98095_set_bias_level
,
2327 .reg_cache_size
= ARRAY_SIZE(max98095_reg_def
),
2328 .reg_word_size
= sizeof(u8
),
2329 .reg_cache_default
= max98095_reg_def
,
2330 .readable_register
= max98095_readable
,
2331 .volatile_register
= max98095_volatile
,
2332 .dapm_widgets
= max98095_dapm_widgets
,
2333 .num_dapm_widgets
= ARRAY_SIZE(max98095_dapm_widgets
),
2334 .dapm_routes
= max98095_audio_map
,
2335 .num_dapm_routes
= ARRAY_SIZE(max98095_audio_map
),
2338 static int max98095_i2c_probe(struct i2c_client
*i2c
,
2339 const struct i2c_device_id
*id
)
2341 struct max98095_priv
*max98095
;
2344 max98095
= kzalloc(sizeof(struct max98095_priv
), GFP_KERNEL
);
2345 if (max98095
== NULL
)
2348 max98095
->devtype
= id
->driver_data
;
2349 i2c_set_clientdata(i2c
, max98095
);
2350 max98095
->pdata
= i2c
->dev
.platform_data
;
2352 ret
= snd_soc_register_codec(&i2c
->dev
, &soc_codec_dev_max98095
,
2353 max98095_dai
, ARRAY_SIZE(max98095_dai
));
2359 static int __devexit
max98095_i2c_remove(struct i2c_client
*client
)
2361 snd_soc_unregister_codec(&client
->dev
);
2362 kfree(i2c_get_clientdata(client
));
2367 static const struct i2c_device_id max98095_i2c_id
[] = {
2368 { "max98095", MAX98095
},
2371 MODULE_DEVICE_TABLE(i2c
, max98095_i2c_id
);
2373 static struct i2c_driver max98095_i2c_driver
= {
2376 .owner
= THIS_MODULE
,
2378 .probe
= max98095_i2c_probe
,
2379 .remove
= __devexit_p(max98095_i2c_remove
),
2380 .id_table
= max98095_i2c_id
,
2383 static int __init
max98095_init(void)
2387 ret
= i2c_add_driver(&max98095_i2c_driver
);
2389 pr_err("Failed to register max98095 I2C driver: %d\n", ret
);
2393 module_init(max98095_init
);
2395 static void __exit
max98095_exit(void)
2397 i2c_del_driver(&max98095_i2c_driver
);
2399 module_exit(max98095_exit
);
2401 MODULE_DESCRIPTION("ALSA SoC MAX98095 driver");
2402 MODULE_AUTHOR("Peter Hsiang");
2403 MODULE_LICENSE("GPL");