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
,
624 if (codec
->hw_write(codec
->control_data
, data
, 2) == 2)
631 * Load equalizer DSP coefficient configurations registers
633 static void m98095_eq_band(struct snd_soc_codec
*codec
, unsigned int dai
,
634 unsigned int band
, u16
*coefs
)
642 /* Load the base register address */
643 eq_reg
= dai
? M98095_142_DAI2_EQ_BASE
: M98095_110_DAI1_EQ_BASE
;
645 /* Add the band address offset, note adjustment for word address */
646 eq_reg
+= band
* (M98095_COEFS_PER_BAND
<< 1);
648 /* Step through the registers and coefs */
649 for (i
= 0; i
< M98095_COEFS_PER_BAND
; i
++) {
650 max98095_hw_write(codec
, eq_reg
++, M98095_BYTE1(coefs
[i
]));
651 max98095_hw_write(codec
, eq_reg
++, M98095_BYTE0(coefs
[i
]));
656 * Load biquad filter coefficient configurations registers
658 static void m98095_biquad_band(struct snd_soc_codec
*codec
, unsigned int dai
,
659 unsigned int band
, u16
*coefs
)
667 /* Load the base register address */
668 bq_reg
= dai
? M98095_17E_DAI2_BQ_BASE
: M98095_174_DAI1_BQ_BASE
;
670 /* Add the band address offset, note adjustment for word address */
671 bq_reg
+= band
* (M98095_COEFS_PER_BAND
<< 1);
673 /* Step through the registers and coefs */
674 for (i
= 0; i
< M98095_COEFS_PER_BAND
; i
++) {
675 max98095_hw_write(codec
, bq_reg
++, M98095_BYTE1(coefs
[i
]));
676 max98095_hw_write(codec
, bq_reg
++, M98095_BYTE0(coefs
[i
]));
680 static const char * const max98095_fltr_mode
[] = { "Voice", "Music" };
681 static const struct soc_enum max98095_dai1_filter_mode_enum
[] = {
682 SOC_ENUM_SINGLE(M98095_02E_DAI1_FILTERS
, 7, 2, max98095_fltr_mode
),
684 static const struct soc_enum max98095_dai2_filter_mode_enum
[] = {
685 SOC_ENUM_SINGLE(M98095_038_DAI2_FILTERS
, 7, 2, max98095_fltr_mode
),
688 static const char * const max98095_extmic_text
[] = { "None", "MIC1", "MIC2" };
690 static const struct soc_enum max98095_extmic_enum
=
691 SOC_ENUM_SINGLE(M98095_087_CFG_MIC
, 0, 3, max98095_extmic_text
);
693 static const struct snd_kcontrol_new max98095_extmic_mux
=
694 SOC_DAPM_ENUM("External MIC Mux", max98095_extmic_enum
);
696 static const char * const max98095_linein_text
[] = { "INA", "INB" };
698 static const struct soc_enum max98095_linein_enum
=
699 SOC_ENUM_SINGLE(M98095_086_CFG_LINE
, 6, 2, max98095_linein_text
);
701 static const struct snd_kcontrol_new max98095_linein_mux
=
702 SOC_DAPM_ENUM("Linein Input Mux", max98095_linein_enum
);
704 static const char * const max98095_line_mode_text
[] = {
705 "Stereo", "Differential"};
707 static const struct soc_enum max98095_linein_mode_enum
=
708 SOC_ENUM_SINGLE(M98095_086_CFG_LINE
, 7, 2, max98095_line_mode_text
);
710 static const struct soc_enum max98095_lineout_mode_enum
=
711 SOC_ENUM_SINGLE(M98095_086_CFG_LINE
, 4, 2, max98095_line_mode_text
);
713 static const char * const max98095_dai_fltr
[] = {
714 "Off", "Elliptical-HPF-16k", "Butterworth-HPF-16k",
715 "Elliptical-HPF-8k", "Butterworth-HPF-8k", "Butterworth-HPF-Fs/240"};
716 static const struct soc_enum max98095_dai1_dac_filter_enum
[] = {
717 SOC_ENUM_SINGLE(M98095_02E_DAI1_FILTERS
, 0, 6, max98095_dai_fltr
),
719 static const struct soc_enum max98095_dai2_dac_filter_enum
[] = {
720 SOC_ENUM_SINGLE(M98095_038_DAI2_FILTERS
, 0, 6, max98095_dai_fltr
),
722 static const struct soc_enum max98095_dai3_dac_filter_enum
[] = {
723 SOC_ENUM_SINGLE(M98095_042_DAI3_FILTERS
, 0, 6, max98095_dai_fltr
),
726 static int max98095_mic1pre_set(struct snd_kcontrol
*kcontrol
,
727 struct snd_ctl_elem_value
*ucontrol
)
729 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
730 struct max98095_priv
*max98095
= snd_soc_codec_get_drvdata(codec
);
731 unsigned int sel
= ucontrol
->value
.integer
.value
[0];
733 max98095
->mic1pre
= sel
;
734 snd_soc_update_bits(codec
, M98095_05F_LVL_MIC1
, M98095_MICPRE_MASK
,
735 (1+sel
)<<M98095_MICPRE_SHIFT
);
740 static int max98095_mic1pre_get(struct snd_kcontrol
*kcontrol
,
741 struct snd_ctl_elem_value
*ucontrol
)
743 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
744 struct max98095_priv
*max98095
= snd_soc_codec_get_drvdata(codec
);
746 ucontrol
->value
.integer
.value
[0] = max98095
->mic1pre
;
750 static int max98095_mic2pre_set(struct snd_kcontrol
*kcontrol
,
751 struct snd_ctl_elem_value
*ucontrol
)
753 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
754 struct max98095_priv
*max98095
= snd_soc_codec_get_drvdata(codec
);
755 unsigned int sel
= ucontrol
->value
.integer
.value
[0];
757 max98095
->mic2pre
= sel
;
758 snd_soc_update_bits(codec
, M98095_060_LVL_MIC2
, M98095_MICPRE_MASK
,
759 (1+sel
)<<M98095_MICPRE_SHIFT
);
764 static int max98095_mic2pre_get(struct snd_kcontrol
*kcontrol
,
765 struct snd_ctl_elem_value
*ucontrol
)
767 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
768 struct max98095_priv
*max98095
= snd_soc_codec_get_drvdata(codec
);
770 ucontrol
->value
.integer
.value
[0] = max98095
->mic2pre
;
774 static const unsigned int max98095_micboost_tlv
[] = {
775 TLV_DB_RANGE_HEAD(2),
776 0, 1, TLV_DB_SCALE_ITEM(0, 2000, 0),
777 2, 2, TLV_DB_SCALE_ITEM(3000, 0, 0),
780 static const DECLARE_TLV_DB_SCALE(max98095_mic_tlv
, 0, 100, 0);
781 static const DECLARE_TLV_DB_SCALE(max98095_adc_tlv
, -1200, 100, 0);
782 static const DECLARE_TLV_DB_SCALE(max98095_adcboost_tlv
, 0, 600, 0);
784 static const unsigned int max98095_hp_tlv
[] = {
785 TLV_DB_RANGE_HEAD(5),
786 0, 6, TLV_DB_SCALE_ITEM(-6700, 400, 0),
787 7, 14, TLV_DB_SCALE_ITEM(-4000, 300, 0),
788 15, 21, TLV_DB_SCALE_ITEM(-1700, 200, 0),
789 22, 27, TLV_DB_SCALE_ITEM(-400, 100, 0),
790 28, 31, TLV_DB_SCALE_ITEM(150, 50, 0),
793 static const unsigned int max98095_spk_tlv
[] = {
794 TLV_DB_RANGE_HEAD(4),
795 0, 10, TLV_DB_SCALE_ITEM(-5900, 400, 0),
796 11, 18, TLV_DB_SCALE_ITEM(-1700, 200, 0),
797 19, 27, TLV_DB_SCALE_ITEM(-200, 100, 0),
798 28, 39, TLV_DB_SCALE_ITEM(650, 50, 0),
801 static const unsigned int max98095_rcv_lout_tlv
[] = {
802 TLV_DB_RANGE_HEAD(5),
803 0, 6, TLV_DB_SCALE_ITEM(-6200, 400, 0),
804 7, 14, TLV_DB_SCALE_ITEM(-3500, 300, 0),
805 15, 21, TLV_DB_SCALE_ITEM(-1200, 200, 0),
806 22, 27, TLV_DB_SCALE_ITEM(100, 100, 0),
807 28, 31, TLV_DB_SCALE_ITEM(650, 50, 0),
810 static const unsigned int max98095_lin_tlv
[] = {
811 TLV_DB_RANGE_HEAD(3),
812 0, 2, TLV_DB_SCALE_ITEM(-600, 300, 0),
813 3, 3, TLV_DB_SCALE_ITEM(300, 1100, 0),
814 4, 5, TLV_DB_SCALE_ITEM(1400, 600, 0),
817 static const struct snd_kcontrol_new max98095_snd_controls
[] = {
819 SOC_DOUBLE_R_TLV("Headphone Volume", M98095_064_LVL_HP_L
,
820 M98095_065_LVL_HP_R
, 0, 31, 0, max98095_hp_tlv
),
822 SOC_DOUBLE_R_TLV("Speaker Volume", M98095_067_LVL_SPK_L
,
823 M98095_068_LVL_SPK_R
, 0, 39, 0, max98095_spk_tlv
),
825 SOC_SINGLE_TLV("Receiver Volume", M98095_066_LVL_RCV
,
826 0, 31, 0, max98095_rcv_lout_tlv
),
828 SOC_DOUBLE_R_TLV("Lineout Volume", M98095_062_LVL_LINEOUT1
,
829 M98095_063_LVL_LINEOUT2
, 0, 31, 0, max98095_rcv_lout_tlv
),
831 SOC_DOUBLE_R("Headphone Switch", M98095_064_LVL_HP_L
,
832 M98095_065_LVL_HP_R
, 7, 1, 1),
834 SOC_DOUBLE_R("Speaker Switch", M98095_067_LVL_SPK_L
,
835 M98095_068_LVL_SPK_R
, 7, 1, 1),
837 SOC_SINGLE("Receiver Switch", M98095_066_LVL_RCV
, 7, 1, 1),
839 SOC_DOUBLE_R("Lineout Switch", M98095_062_LVL_LINEOUT1
,
840 M98095_063_LVL_LINEOUT2
, 7, 1, 1),
842 SOC_SINGLE_TLV("MIC1 Volume", M98095_05F_LVL_MIC1
, 0, 20, 1,
845 SOC_SINGLE_TLV("MIC2 Volume", M98095_060_LVL_MIC2
, 0, 20, 1,
848 SOC_SINGLE_EXT_TLV("MIC1 Boost Volume",
849 M98095_05F_LVL_MIC1
, 5, 2, 0,
850 max98095_mic1pre_get
, max98095_mic1pre_set
,
851 max98095_micboost_tlv
),
852 SOC_SINGLE_EXT_TLV("MIC2 Boost Volume",
853 M98095_060_LVL_MIC2
, 5, 2, 0,
854 max98095_mic2pre_get
, max98095_mic2pre_set
,
855 max98095_micboost_tlv
),
857 SOC_SINGLE_TLV("Linein Volume", M98095_061_LVL_LINEIN
, 0, 5, 1,
860 SOC_SINGLE_TLV("ADCL Volume", M98095_05D_LVL_ADC_L
, 0, 15, 1,
862 SOC_SINGLE_TLV("ADCR Volume", M98095_05E_LVL_ADC_R
, 0, 15, 1,
865 SOC_SINGLE_TLV("ADCL Boost Volume", M98095_05D_LVL_ADC_L
, 4, 3, 0,
866 max98095_adcboost_tlv
),
867 SOC_SINGLE_TLV("ADCR Boost Volume", M98095_05E_LVL_ADC_R
, 4, 3, 0,
868 max98095_adcboost_tlv
),
870 SOC_SINGLE("EQ1 Switch", M98095_088_CFG_LEVEL
, 0, 1, 0),
871 SOC_SINGLE("EQ2 Switch", M98095_088_CFG_LEVEL
, 1, 1, 0),
873 SOC_SINGLE("Biquad1 Switch", M98095_088_CFG_LEVEL
, 2, 1, 0),
874 SOC_SINGLE("Biquad2 Switch", M98095_088_CFG_LEVEL
, 3, 1, 0),
876 SOC_ENUM("DAI1 Filter Mode", max98095_dai1_filter_mode_enum
),
877 SOC_ENUM("DAI2 Filter Mode", max98095_dai2_filter_mode_enum
),
878 SOC_ENUM("DAI1 DAC Filter", max98095_dai1_dac_filter_enum
),
879 SOC_ENUM("DAI2 DAC Filter", max98095_dai2_dac_filter_enum
),
880 SOC_ENUM("DAI3 DAC Filter", max98095_dai3_dac_filter_enum
),
882 SOC_ENUM("Linein Mode", max98095_linein_mode_enum
),
883 SOC_ENUM("Lineout Mode", max98095_lineout_mode_enum
),
886 /* Left speaker mixer switch */
887 static const struct snd_kcontrol_new max98095_left_speaker_mixer_controls
[] = {
888 SOC_DAPM_SINGLE("Left DAC1 Switch", M98095_050_MIX_SPK_LEFT
, 0, 1, 0),
889 SOC_DAPM_SINGLE("Right DAC1 Switch", M98095_050_MIX_SPK_LEFT
, 6, 1, 0),
890 SOC_DAPM_SINGLE("Mono DAC2 Switch", M98095_050_MIX_SPK_LEFT
, 3, 1, 0),
891 SOC_DAPM_SINGLE("Mono DAC3 Switch", M98095_050_MIX_SPK_LEFT
, 3, 1, 0),
892 SOC_DAPM_SINGLE("MIC1 Switch", M98095_050_MIX_SPK_LEFT
, 4, 1, 0),
893 SOC_DAPM_SINGLE("MIC2 Switch", M98095_050_MIX_SPK_LEFT
, 5, 1, 0),
894 SOC_DAPM_SINGLE("IN1 Switch", M98095_050_MIX_SPK_LEFT
, 1, 1, 0),
895 SOC_DAPM_SINGLE("IN2 Switch", M98095_050_MIX_SPK_LEFT
, 2, 1, 0),
898 /* Right speaker mixer switch */
899 static const struct snd_kcontrol_new max98095_right_speaker_mixer_controls
[] = {
900 SOC_DAPM_SINGLE("Left DAC1 Switch", M98095_051_MIX_SPK_RIGHT
, 6, 1, 0),
901 SOC_DAPM_SINGLE("Right DAC1 Switch", M98095_051_MIX_SPK_RIGHT
, 0, 1, 0),
902 SOC_DAPM_SINGLE("Mono DAC2 Switch", M98095_051_MIX_SPK_RIGHT
, 3, 1, 0),
903 SOC_DAPM_SINGLE("Mono DAC3 Switch", M98095_051_MIX_SPK_RIGHT
, 3, 1, 0),
904 SOC_DAPM_SINGLE("MIC1 Switch", M98095_051_MIX_SPK_RIGHT
, 5, 1, 0),
905 SOC_DAPM_SINGLE("MIC2 Switch", M98095_051_MIX_SPK_RIGHT
, 4, 1, 0),
906 SOC_DAPM_SINGLE("IN1 Switch", M98095_051_MIX_SPK_RIGHT
, 1, 1, 0),
907 SOC_DAPM_SINGLE("IN2 Switch", M98095_051_MIX_SPK_RIGHT
, 2, 1, 0),
910 /* Left headphone mixer switch */
911 static const struct snd_kcontrol_new max98095_left_hp_mixer_controls
[] = {
912 SOC_DAPM_SINGLE("Left DAC1 Switch", M98095_04C_MIX_HP_LEFT
, 0, 1, 0),
913 SOC_DAPM_SINGLE("Right DAC1 Switch", M98095_04C_MIX_HP_LEFT
, 5, 1, 0),
914 SOC_DAPM_SINGLE("MIC1 Switch", M98095_04C_MIX_HP_LEFT
, 3, 1, 0),
915 SOC_DAPM_SINGLE("MIC2 Switch", M98095_04C_MIX_HP_LEFT
, 4, 1, 0),
916 SOC_DAPM_SINGLE("IN1 Switch", M98095_04C_MIX_HP_LEFT
, 1, 1, 0),
917 SOC_DAPM_SINGLE("IN2 Switch", M98095_04C_MIX_HP_LEFT
, 2, 1, 0),
920 /* Right headphone mixer switch */
921 static const struct snd_kcontrol_new max98095_right_hp_mixer_controls
[] = {
922 SOC_DAPM_SINGLE("Left DAC1 Switch", M98095_04D_MIX_HP_RIGHT
, 5, 1, 0),
923 SOC_DAPM_SINGLE("Right DAC1 Switch", M98095_04D_MIX_HP_RIGHT
, 0, 1, 0),
924 SOC_DAPM_SINGLE("MIC1 Switch", M98095_04D_MIX_HP_RIGHT
, 3, 1, 0),
925 SOC_DAPM_SINGLE("MIC2 Switch", M98095_04D_MIX_HP_RIGHT
, 4, 1, 0),
926 SOC_DAPM_SINGLE("IN1 Switch", M98095_04D_MIX_HP_RIGHT
, 1, 1, 0),
927 SOC_DAPM_SINGLE("IN2 Switch", M98095_04D_MIX_HP_RIGHT
, 2, 1, 0),
930 /* Receiver earpiece mixer switch */
931 static const struct snd_kcontrol_new max98095_mono_rcv_mixer_controls
[] = {
932 SOC_DAPM_SINGLE("Left DAC1 Switch", M98095_04F_MIX_RCV
, 0, 1, 0),
933 SOC_DAPM_SINGLE("Right DAC1 Switch", M98095_04F_MIX_RCV
, 5, 1, 0),
934 SOC_DAPM_SINGLE("MIC1 Switch", M98095_04F_MIX_RCV
, 3, 1, 0),
935 SOC_DAPM_SINGLE("MIC2 Switch", M98095_04F_MIX_RCV
, 4, 1, 0),
936 SOC_DAPM_SINGLE("IN1 Switch", M98095_04F_MIX_RCV
, 1, 1, 0),
937 SOC_DAPM_SINGLE("IN2 Switch", M98095_04F_MIX_RCV
, 2, 1, 0),
940 /* Left lineout mixer switch */
941 static const struct snd_kcontrol_new max98095_left_lineout_mixer_controls
[] = {
942 SOC_DAPM_SINGLE("Left DAC1 Switch", M98095_053_MIX_LINEOUT1
, 5, 1, 0),
943 SOC_DAPM_SINGLE("Right DAC1 Switch", M98095_053_MIX_LINEOUT1
, 0, 1, 0),
944 SOC_DAPM_SINGLE("MIC1 Switch", M98095_053_MIX_LINEOUT1
, 3, 1, 0),
945 SOC_DAPM_SINGLE("MIC2 Switch", M98095_053_MIX_LINEOUT1
, 4, 1, 0),
946 SOC_DAPM_SINGLE("IN1 Switch", M98095_053_MIX_LINEOUT1
, 1, 1, 0),
947 SOC_DAPM_SINGLE("IN2 Switch", M98095_053_MIX_LINEOUT1
, 2, 1, 0),
950 /* Right lineout mixer switch */
951 static const struct snd_kcontrol_new max98095_right_lineout_mixer_controls
[] = {
952 SOC_DAPM_SINGLE("Left DAC1 Switch", M98095_054_MIX_LINEOUT2
, 0, 1, 0),
953 SOC_DAPM_SINGLE("Right DAC1 Switch", M98095_054_MIX_LINEOUT2
, 5, 1, 0),
954 SOC_DAPM_SINGLE("MIC1 Switch", M98095_054_MIX_LINEOUT2
, 3, 1, 0),
955 SOC_DAPM_SINGLE("MIC2 Switch", M98095_054_MIX_LINEOUT2
, 4, 1, 0),
956 SOC_DAPM_SINGLE("IN1 Switch", M98095_054_MIX_LINEOUT2
, 1, 1, 0),
957 SOC_DAPM_SINGLE("IN2 Switch", M98095_054_MIX_LINEOUT2
, 2, 1, 0),
960 /* Left ADC mixer switch */
961 static const struct snd_kcontrol_new max98095_left_ADC_mixer_controls
[] = {
962 SOC_DAPM_SINGLE("MIC1 Switch", M98095_04A_MIX_ADC_LEFT
, 7, 1, 0),
963 SOC_DAPM_SINGLE("MIC2 Switch", M98095_04A_MIX_ADC_LEFT
, 6, 1, 0),
964 SOC_DAPM_SINGLE("IN1 Switch", M98095_04A_MIX_ADC_LEFT
, 3, 1, 0),
965 SOC_DAPM_SINGLE("IN2 Switch", M98095_04A_MIX_ADC_LEFT
, 2, 1, 0),
968 /* Right ADC mixer switch */
969 static const struct snd_kcontrol_new max98095_right_ADC_mixer_controls
[] = {
970 SOC_DAPM_SINGLE("MIC1 Switch", M98095_04B_MIX_ADC_RIGHT
, 7, 1, 0),
971 SOC_DAPM_SINGLE("MIC2 Switch", M98095_04B_MIX_ADC_RIGHT
, 6, 1, 0),
972 SOC_DAPM_SINGLE("IN1 Switch", M98095_04B_MIX_ADC_RIGHT
, 3, 1, 0),
973 SOC_DAPM_SINGLE("IN2 Switch", M98095_04B_MIX_ADC_RIGHT
, 2, 1, 0),
976 static int max98095_mic_event(struct snd_soc_dapm_widget
*w
,
977 struct snd_kcontrol
*kcontrol
, int event
)
979 struct snd_soc_codec
*codec
= w
->codec
;
980 struct max98095_priv
*max98095
= snd_soc_codec_get_drvdata(codec
);
983 case SND_SOC_DAPM_POST_PMU
:
984 if (w
->reg
== M98095_05F_LVL_MIC1
) {
985 snd_soc_update_bits(codec
, w
->reg
, M98095_MICPRE_MASK
,
986 (1+max98095
->mic1pre
)<<M98095_MICPRE_SHIFT
);
988 snd_soc_update_bits(codec
, w
->reg
, M98095_MICPRE_MASK
,
989 (1+max98095
->mic2pre
)<<M98095_MICPRE_SHIFT
);
992 case SND_SOC_DAPM_POST_PMD
:
993 snd_soc_update_bits(codec
, w
->reg
, M98095_MICPRE_MASK
, 0);
1003 * The line inputs are stereo inputs with the left and right
1004 * channels sharing a common PGA power control signal.
1006 static int max98095_line_pga(struct snd_soc_dapm_widget
*w
,
1007 int event
, u8 channel
)
1009 struct snd_soc_codec
*codec
= w
->codec
;
1010 struct max98095_priv
*max98095
= snd_soc_codec_get_drvdata(codec
);
1013 BUG_ON(!((channel
== 1) || (channel
== 2)));
1015 state
= &max98095
->lin_state
;
1018 case SND_SOC_DAPM_POST_PMU
:
1020 snd_soc_update_bits(codec
, w
->reg
,
1021 (1 << w
->shift
), (1 << w
->shift
));
1023 case SND_SOC_DAPM_POST_PMD
:
1026 snd_soc_update_bits(codec
, w
->reg
,
1027 (1 << w
->shift
), 0);
1037 static int max98095_pga_in1_event(struct snd_soc_dapm_widget
*w
,
1038 struct snd_kcontrol
*k
, int event
)
1040 return max98095_line_pga(w
, event
, 1);
1043 static int max98095_pga_in2_event(struct snd_soc_dapm_widget
*w
,
1044 struct snd_kcontrol
*k
, int event
)
1046 return max98095_line_pga(w
, event
, 2);
1050 * The stereo line out mixer outputs to two stereo line outs.
1051 * The 2nd pair has a separate set of enables.
1053 static int max98095_lineout_event(struct snd_soc_dapm_widget
*w
,
1054 struct snd_kcontrol
*kcontrol
, int event
)
1056 struct snd_soc_codec
*codec
= w
->codec
;
1059 case SND_SOC_DAPM_POST_PMU
:
1060 snd_soc_update_bits(codec
, w
->reg
,
1061 (1 << (w
->shift
+2)), (1 << (w
->shift
+2)));
1063 case SND_SOC_DAPM_POST_PMD
:
1064 snd_soc_update_bits(codec
, w
->reg
,
1065 (1 << (w
->shift
+2)), 0);
1074 static const struct snd_soc_dapm_widget max98095_dapm_widgets
[] = {
1076 SND_SOC_DAPM_ADC("ADCL", "HiFi Capture", M98095_090_PWR_EN_IN
, 0, 0),
1077 SND_SOC_DAPM_ADC("ADCR", "HiFi Capture", M98095_090_PWR_EN_IN
, 1, 0),
1079 SND_SOC_DAPM_DAC("DACL1", "HiFi Playback",
1080 M98095_091_PWR_EN_OUT
, 0, 0),
1081 SND_SOC_DAPM_DAC("DACR1", "HiFi Playback",
1082 M98095_091_PWR_EN_OUT
, 1, 0),
1083 SND_SOC_DAPM_DAC("DACM2", "Aux Playback",
1084 M98095_091_PWR_EN_OUT
, 2, 0),
1085 SND_SOC_DAPM_DAC("DACM3", "Voice Playback",
1086 M98095_091_PWR_EN_OUT
, 2, 0),
1088 SND_SOC_DAPM_PGA("HP Left Out", M98095_091_PWR_EN_OUT
,
1090 SND_SOC_DAPM_PGA("HP Right Out", M98095_091_PWR_EN_OUT
,
1093 SND_SOC_DAPM_PGA("SPK Left Out", M98095_091_PWR_EN_OUT
,
1095 SND_SOC_DAPM_PGA("SPK Right Out", M98095_091_PWR_EN_OUT
,
1098 SND_SOC_DAPM_PGA("RCV Mono Out", M98095_091_PWR_EN_OUT
,
1101 SND_SOC_DAPM_PGA_E("LINE Left Out", M98095_092_PWR_EN_OUT
,
1102 0, 0, NULL
, 0, max98095_lineout_event
, SND_SOC_DAPM_PRE_PMD
),
1103 SND_SOC_DAPM_PGA_E("LINE Right Out", M98095_092_PWR_EN_OUT
,
1104 1, 0, NULL
, 0, max98095_lineout_event
, SND_SOC_DAPM_PRE_PMD
),
1106 SND_SOC_DAPM_MUX("External MIC", SND_SOC_NOPM
, 0, 0,
1107 &max98095_extmic_mux
),
1109 SND_SOC_DAPM_MUX("Linein Mux", SND_SOC_NOPM
, 0, 0,
1110 &max98095_linein_mux
),
1112 SND_SOC_DAPM_MIXER("Left Headphone Mixer", SND_SOC_NOPM
, 0, 0,
1113 &max98095_left_hp_mixer_controls
[0],
1114 ARRAY_SIZE(max98095_left_hp_mixer_controls
)),
1116 SND_SOC_DAPM_MIXER("Right Headphone Mixer", SND_SOC_NOPM
, 0, 0,
1117 &max98095_right_hp_mixer_controls
[0],
1118 ARRAY_SIZE(max98095_right_hp_mixer_controls
)),
1120 SND_SOC_DAPM_MIXER("Left Speaker Mixer", SND_SOC_NOPM
, 0, 0,
1121 &max98095_left_speaker_mixer_controls
[0],
1122 ARRAY_SIZE(max98095_left_speaker_mixer_controls
)),
1124 SND_SOC_DAPM_MIXER("Right Speaker Mixer", SND_SOC_NOPM
, 0, 0,
1125 &max98095_right_speaker_mixer_controls
[0],
1126 ARRAY_SIZE(max98095_right_speaker_mixer_controls
)),
1128 SND_SOC_DAPM_MIXER("Receiver Mixer", SND_SOC_NOPM
, 0, 0,
1129 &max98095_mono_rcv_mixer_controls
[0],
1130 ARRAY_SIZE(max98095_mono_rcv_mixer_controls
)),
1132 SND_SOC_DAPM_MIXER("Left Lineout Mixer", SND_SOC_NOPM
, 0, 0,
1133 &max98095_left_lineout_mixer_controls
[0],
1134 ARRAY_SIZE(max98095_left_lineout_mixer_controls
)),
1136 SND_SOC_DAPM_MIXER("Right Lineout Mixer", SND_SOC_NOPM
, 0, 0,
1137 &max98095_right_lineout_mixer_controls
[0],
1138 ARRAY_SIZE(max98095_right_lineout_mixer_controls
)),
1140 SND_SOC_DAPM_MIXER("Left ADC Mixer", SND_SOC_NOPM
, 0, 0,
1141 &max98095_left_ADC_mixer_controls
[0],
1142 ARRAY_SIZE(max98095_left_ADC_mixer_controls
)),
1144 SND_SOC_DAPM_MIXER("Right ADC Mixer", SND_SOC_NOPM
, 0, 0,
1145 &max98095_right_ADC_mixer_controls
[0],
1146 ARRAY_SIZE(max98095_right_ADC_mixer_controls
)),
1148 SND_SOC_DAPM_PGA_E("MIC1 Input", M98095_05F_LVL_MIC1
,
1149 5, 0, NULL
, 0, max98095_mic_event
,
1150 SND_SOC_DAPM_POST_PMU
| SND_SOC_DAPM_POST_PMD
),
1152 SND_SOC_DAPM_PGA_E("MIC2 Input", M98095_060_LVL_MIC2
,
1153 5, 0, NULL
, 0, max98095_mic_event
,
1154 SND_SOC_DAPM_POST_PMU
| SND_SOC_DAPM_POST_PMD
),
1156 SND_SOC_DAPM_PGA_E("IN1 Input", M98095_090_PWR_EN_IN
,
1157 7, 0, NULL
, 0, max98095_pga_in1_event
,
1158 SND_SOC_DAPM_POST_PMU
| SND_SOC_DAPM_POST_PMD
),
1160 SND_SOC_DAPM_PGA_E("IN2 Input", M98095_090_PWR_EN_IN
,
1161 7, 0, NULL
, 0, max98095_pga_in2_event
,
1162 SND_SOC_DAPM_POST_PMU
| SND_SOC_DAPM_POST_PMD
),
1164 SND_SOC_DAPM_MICBIAS("MICBIAS1", M98095_090_PWR_EN_IN
, 2, 0),
1165 SND_SOC_DAPM_MICBIAS("MICBIAS2", M98095_090_PWR_EN_IN
, 3, 0),
1167 SND_SOC_DAPM_OUTPUT("HPL"),
1168 SND_SOC_DAPM_OUTPUT("HPR"),
1169 SND_SOC_DAPM_OUTPUT("SPKL"),
1170 SND_SOC_DAPM_OUTPUT("SPKR"),
1171 SND_SOC_DAPM_OUTPUT("RCV"),
1172 SND_SOC_DAPM_OUTPUT("OUT1"),
1173 SND_SOC_DAPM_OUTPUT("OUT2"),
1174 SND_SOC_DAPM_OUTPUT("OUT3"),
1175 SND_SOC_DAPM_OUTPUT("OUT4"),
1177 SND_SOC_DAPM_INPUT("MIC1"),
1178 SND_SOC_DAPM_INPUT("MIC2"),
1179 SND_SOC_DAPM_INPUT("INA1"),
1180 SND_SOC_DAPM_INPUT("INA2"),
1181 SND_SOC_DAPM_INPUT("INB1"),
1182 SND_SOC_DAPM_INPUT("INB2"),
1185 static const struct snd_soc_dapm_route max98095_audio_map
[] = {
1186 /* Left headphone output mixer */
1187 {"Left Headphone Mixer", "Left DAC1 Switch", "DACL1"},
1188 {"Left Headphone Mixer", "Right DAC1 Switch", "DACR1"},
1189 {"Left Headphone Mixer", "MIC1 Switch", "MIC1 Input"},
1190 {"Left Headphone Mixer", "MIC2 Switch", "MIC2 Input"},
1191 {"Left Headphone Mixer", "IN1 Switch", "IN1 Input"},
1192 {"Left Headphone Mixer", "IN2 Switch", "IN2 Input"},
1194 /* Right headphone output mixer */
1195 {"Right Headphone Mixer", "Left DAC1 Switch", "DACL1"},
1196 {"Right Headphone Mixer", "Right DAC1 Switch", "DACR1"},
1197 {"Right Headphone Mixer", "MIC1 Switch", "MIC1 Input"},
1198 {"Right Headphone Mixer", "MIC2 Switch", "MIC2 Input"},
1199 {"Right Headphone Mixer", "IN1 Switch", "IN1 Input"},
1200 {"Right Headphone Mixer", "IN2 Switch", "IN2 Input"},
1202 /* Left speaker output mixer */
1203 {"Left Speaker Mixer", "Left DAC1 Switch", "DACL1"},
1204 {"Left Speaker Mixer", "Right DAC1 Switch", "DACR1"},
1205 {"Left Speaker Mixer", "Mono DAC2 Switch", "DACM2"},
1206 {"Left Speaker Mixer", "Mono DAC3 Switch", "DACM3"},
1207 {"Left Speaker Mixer", "MIC1 Switch", "MIC1 Input"},
1208 {"Left Speaker Mixer", "MIC2 Switch", "MIC2 Input"},
1209 {"Left Speaker Mixer", "IN1 Switch", "IN1 Input"},
1210 {"Left Speaker Mixer", "IN2 Switch", "IN2 Input"},
1212 /* Right speaker output mixer */
1213 {"Right Speaker Mixer", "Left DAC1 Switch", "DACL1"},
1214 {"Right Speaker Mixer", "Right DAC1 Switch", "DACR1"},
1215 {"Right Speaker Mixer", "Mono DAC2 Switch", "DACM2"},
1216 {"Right Speaker Mixer", "Mono DAC3 Switch", "DACM3"},
1217 {"Right Speaker Mixer", "MIC1 Switch", "MIC1 Input"},
1218 {"Right Speaker Mixer", "MIC2 Switch", "MIC2 Input"},
1219 {"Right Speaker Mixer", "IN1 Switch", "IN1 Input"},
1220 {"Right Speaker Mixer", "IN2 Switch", "IN2 Input"},
1222 /* Earpiece/Receiver output mixer */
1223 {"Receiver Mixer", "Left DAC1 Switch", "DACL1"},
1224 {"Receiver Mixer", "Right DAC1 Switch", "DACR1"},
1225 {"Receiver Mixer", "MIC1 Switch", "MIC1 Input"},
1226 {"Receiver Mixer", "MIC2 Switch", "MIC2 Input"},
1227 {"Receiver Mixer", "IN1 Switch", "IN1 Input"},
1228 {"Receiver Mixer", "IN2 Switch", "IN2 Input"},
1230 /* Left Lineout output mixer */
1231 {"Left Lineout Mixer", "Left DAC1 Switch", "DACL1"},
1232 {"Left Lineout Mixer", "Right DAC1 Switch", "DACR1"},
1233 {"Left Lineout Mixer", "MIC1 Switch", "MIC1 Input"},
1234 {"Left Lineout Mixer", "MIC2 Switch", "MIC2 Input"},
1235 {"Left Lineout Mixer", "IN1 Switch", "IN1 Input"},
1236 {"Left Lineout Mixer", "IN2 Switch", "IN2 Input"},
1238 /* Right lineout output mixer */
1239 {"Right Lineout Mixer", "Left DAC1 Switch", "DACL1"},
1240 {"Right Lineout Mixer", "Right DAC1 Switch", "DACR1"},
1241 {"Right Lineout Mixer", "MIC1 Switch", "MIC1 Input"},
1242 {"Right Lineout Mixer", "MIC2 Switch", "MIC2 Input"},
1243 {"Right Lineout Mixer", "IN1 Switch", "IN1 Input"},
1244 {"Right Lineout Mixer", "IN2 Switch", "IN2 Input"},
1246 {"HP Left Out", NULL
, "Left Headphone Mixer"},
1247 {"HP Right Out", NULL
, "Right Headphone Mixer"},
1248 {"SPK Left Out", NULL
, "Left Speaker Mixer"},
1249 {"SPK Right Out", NULL
, "Right Speaker Mixer"},
1250 {"RCV Mono Out", NULL
, "Receiver Mixer"},
1251 {"LINE Left Out", NULL
, "Left Lineout Mixer"},
1252 {"LINE Right Out", NULL
, "Right Lineout Mixer"},
1254 {"HPL", NULL
, "HP Left Out"},
1255 {"HPR", NULL
, "HP Right Out"},
1256 {"SPKL", NULL
, "SPK Left Out"},
1257 {"SPKR", NULL
, "SPK Right Out"},
1258 {"RCV", NULL
, "RCV Mono Out"},
1259 {"OUT1", NULL
, "LINE Left Out"},
1260 {"OUT2", NULL
, "LINE Right Out"},
1261 {"OUT3", NULL
, "LINE Left Out"},
1262 {"OUT4", NULL
, "LINE Right Out"},
1264 /* Left ADC input mixer */
1265 {"Left ADC Mixer", "MIC1 Switch", "MIC1 Input"},
1266 {"Left ADC Mixer", "MIC2 Switch", "MIC2 Input"},
1267 {"Left ADC Mixer", "IN1 Switch", "IN1 Input"},
1268 {"Left ADC Mixer", "IN2 Switch", "IN2 Input"},
1270 /* Right ADC input mixer */
1271 {"Right ADC Mixer", "MIC1 Switch", "MIC1 Input"},
1272 {"Right ADC Mixer", "MIC2 Switch", "MIC2 Input"},
1273 {"Right ADC Mixer", "IN1 Switch", "IN1 Input"},
1274 {"Right ADC Mixer", "IN2 Switch", "IN2 Input"},
1277 {"ADCL", NULL
, "Left ADC Mixer"},
1278 {"ADCR", NULL
, "Right ADC Mixer"},
1280 {"IN1 Input", NULL
, "INA1"},
1281 {"IN2 Input", NULL
, "INA2"},
1283 {"MIC1 Input", NULL
, "MIC1"},
1284 {"MIC2 Input", NULL
, "MIC2"},
1287 static int max98095_add_widgets(struct snd_soc_codec
*codec
)
1289 snd_soc_add_controls(codec
, max98095_snd_controls
,
1290 ARRAY_SIZE(max98095_snd_controls
));
1295 /* codec mclk clock divider coefficients */
1296 static const struct {
1312 static int rate_value(int rate
, u8
*value
)
1316 for (i
= 0; i
< ARRAY_SIZE(rate_table
); i
++) {
1317 if (rate_table
[i
].rate
>= rate
) {
1318 *value
= rate_table
[i
].sr
;
1322 *value
= rate_table
[0].sr
;
1326 static int max98095_dai1_hw_params(struct snd_pcm_substream
*substream
,
1327 struct snd_pcm_hw_params
*params
,
1328 struct snd_soc_dai
*dai
)
1330 struct snd_soc_codec
*codec
= dai
->codec
;
1331 struct max98095_priv
*max98095
= snd_soc_codec_get_drvdata(codec
);
1332 struct max98095_cdata
*cdata
;
1333 unsigned long long ni
;
1337 cdata
= &max98095
->dai
[0];
1339 rate
= params_rate(params
);
1341 switch (params_format(params
)) {
1342 case SNDRV_PCM_FORMAT_S16_LE
:
1343 snd_soc_update_bits(codec
, M98095_02A_DAI1_FORMAT
,
1346 case SNDRV_PCM_FORMAT_S24_LE
:
1347 snd_soc_update_bits(codec
, M98095_02A_DAI1_FORMAT
,
1348 M98095_DAI_WS
, M98095_DAI_WS
);
1354 if (rate_value(rate
, ®val
))
1357 snd_soc_update_bits(codec
, M98095_027_DAI1_CLKMODE
,
1358 M98095_CLKMODE_MASK
, regval
);
1361 /* Configure NI when operating as master */
1362 if (snd_soc_read(codec
, M98095_02A_DAI1_FORMAT
) & M98095_DAI_MAS
) {
1363 if (max98095
->sysclk
== 0) {
1364 dev_err(codec
->dev
, "Invalid system clock frequency\n");
1367 ni
= 65536ULL * (rate
< 50000 ? 96ULL : 48ULL)
1368 * (unsigned long long int)rate
;
1369 do_div(ni
, (unsigned long long int)max98095
->sysclk
);
1370 snd_soc_write(codec
, M98095_028_DAI1_CLKCFG_HI
,
1372 snd_soc_write(codec
, M98095_029_DAI1_CLKCFG_LO
,
1376 /* Update sample rate mode */
1378 snd_soc_update_bits(codec
, M98095_02E_DAI1_FILTERS
,
1381 snd_soc_update_bits(codec
, M98095_02E_DAI1_FILTERS
,
1382 M98095_DAI_DHF
, M98095_DAI_DHF
);
1387 static int max98095_dai2_hw_params(struct snd_pcm_substream
*substream
,
1388 struct snd_pcm_hw_params
*params
,
1389 struct snd_soc_dai
*dai
)
1391 struct snd_soc_codec
*codec
= dai
->codec
;
1392 struct max98095_priv
*max98095
= snd_soc_codec_get_drvdata(codec
);
1393 struct max98095_cdata
*cdata
;
1394 unsigned long long ni
;
1398 cdata
= &max98095
->dai
[1];
1400 rate
= params_rate(params
);
1402 switch (params_format(params
)) {
1403 case SNDRV_PCM_FORMAT_S16_LE
:
1404 snd_soc_update_bits(codec
, M98095_034_DAI2_FORMAT
,
1407 case SNDRV_PCM_FORMAT_S24_LE
:
1408 snd_soc_update_bits(codec
, M98095_034_DAI2_FORMAT
,
1409 M98095_DAI_WS
, M98095_DAI_WS
);
1415 if (rate_value(rate
, ®val
))
1418 snd_soc_update_bits(codec
, M98095_031_DAI2_CLKMODE
,
1419 M98095_CLKMODE_MASK
, regval
);
1422 /* Configure NI when operating as master */
1423 if (snd_soc_read(codec
, M98095_034_DAI2_FORMAT
) & M98095_DAI_MAS
) {
1424 if (max98095
->sysclk
== 0) {
1425 dev_err(codec
->dev
, "Invalid system clock frequency\n");
1428 ni
= 65536ULL * (rate
< 50000 ? 96ULL : 48ULL)
1429 * (unsigned long long int)rate
;
1430 do_div(ni
, (unsigned long long int)max98095
->sysclk
);
1431 snd_soc_write(codec
, M98095_032_DAI2_CLKCFG_HI
,
1433 snd_soc_write(codec
, M98095_033_DAI2_CLKCFG_LO
,
1437 /* Update sample rate mode */
1439 snd_soc_update_bits(codec
, M98095_038_DAI2_FILTERS
,
1442 snd_soc_update_bits(codec
, M98095_038_DAI2_FILTERS
,
1443 M98095_DAI_DHF
, M98095_DAI_DHF
);
1448 static int max98095_dai3_hw_params(struct snd_pcm_substream
*substream
,
1449 struct snd_pcm_hw_params
*params
,
1450 struct snd_soc_dai
*dai
)
1452 struct snd_soc_codec
*codec
= dai
->codec
;
1453 struct max98095_priv
*max98095
= snd_soc_codec_get_drvdata(codec
);
1454 struct max98095_cdata
*cdata
;
1455 unsigned long long ni
;
1459 cdata
= &max98095
->dai
[2];
1461 rate
= params_rate(params
);
1463 switch (params_format(params
)) {
1464 case SNDRV_PCM_FORMAT_S16_LE
:
1465 snd_soc_update_bits(codec
, M98095_03E_DAI3_FORMAT
,
1468 case SNDRV_PCM_FORMAT_S24_LE
:
1469 snd_soc_update_bits(codec
, M98095_03E_DAI3_FORMAT
,
1470 M98095_DAI_WS
, M98095_DAI_WS
);
1476 if (rate_value(rate
, ®val
))
1479 snd_soc_update_bits(codec
, M98095_03B_DAI3_CLKMODE
,
1480 M98095_CLKMODE_MASK
, regval
);
1483 /* Configure NI when operating as master */
1484 if (snd_soc_read(codec
, M98095_03E_DAI3_FORMAT
) & M98095_DAI_MAS
) {
1485 if (max98095
->sysclk
== 0) {
1486 dev_err(codec
->dev
, "Invalid system clock frequency\n");
1489 ni
= 65536ULL * (rate
< 50000 ? 96ULL : 48ULL)
1490 * (unsigned long long int)rate
;
1491 do_div(ni
, (unsigned long long int)max98095
->sysclk
);
1492 snd_soc_write(codec
, M98095_03C_DAI3_CLKCFG_HI
,
1494 snd_soc_write(codec
, M98095_03D_DAI3_CLKCFG_LO
,
1498 /* Update sample rate mode */
1500 snd_soc_update_bits(codec
, M98095_042_DAI3_FILTERS
,
1503 snd_soc_update_bits(codec
, M98095_042_DAI3_FILTERS
,
1504 M98095_DAI_DHF
, M98095_DAI_DHF
);
1509 static int max98095_dai_set_sysclk(struct snd_soc_dai
*dai
,
1510 int clk_id
, unsigned int freq
, int dir
)
1512 struct snd_soc_codec
*codec
= dai
->codec
;
1513 struct max98095_priv
*max98095
= snd_soc_codec_get_drvdata(codec
);
1515 /* Requested clock frequency is already setup */
1516 if (freq
== max98095
->sysclk
)
1519 /* Setup clocks for slave mode, and using the PLL
1520 * PSCLK = 0x01 (when master clk is 10MHz to 20MHz)
1521 * 0x02 (when master clk is 20MHz to 40MHz)..
1522 * 0x03 (when master clk is 40MHz to 60MHz)..
1524 if ((freq
>= 10000000) && (freq
< 20000000)) {
1525 snd_soc_write(codec
, M98095_026_SYS_CLK
, 0x10);
1526 } else if ((freq
>= 20000000) && (freq
< 40000000)) {
1527 snd_soc_write(codec
, M98095_026_SYS_CLK
, 0x20);
1528 } else if ((freq
>= 40000000) && (freq
< 60000000)) {
1529 snd_soc_write(codec
, M98095_026_SYS_CLK
, 0x30);
1531 dev_err(codec
->dev
, "Invalid master clock frequency\n");
1535 dev_dbg(dai
->dev
, "Clock source is %d at %uHz\n", clk_id
, freq
);
1537 max98095
->sysclk
= freq
;
1541 static int max98095_dai1_set_fmt(struct snd_soc_dai
*codec_dai
,
1544 struct snd_soc_codec
*codec
= codec_dai
->codec
;
1545 struct max98095_priv
*max98095
= snd_soc_codec_get_drvdata(codec
);
1546 struct max98095_cdata
*cdata
;
1549 cdata
= &max98095
->dai
[0];
1551 if (fmt
!= cdata
->fmt
) {
1554 switch (fmt
& SND_SOC_DAIFMT_MASTER_MASK
) {
1555 case SND_SOC_DAIFMT_CBS_CFS
:
1556 /* Slave mode PLL */
1557 snd_soc_write(codec
, M98095_028_DAI1_CLKCFG_HI
,
1559 snd_soc_write(codec
, M98095_029_DAI1_CLKCFG_LO
,
1562 case SND_SOC_DAIFMT_CBM_CFM
:
1563 /* Set to master mode */
1564 regval
|= M98095_DAI_MAS
;
1566 case SND_SOC_DAIFMT_CBS_CFM
:
1567 case SND_SOC_DAIFMT_CBM_CFS
:
1569 dev_err(codec
->dev
, "Clock mode unsupported");
1573 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
1574 case SND_SOC_DAIFMT_I2S
:
1575 regval
|= M98095_DAI_DLY
;
1577 case SND_SOC_DAIFMT_LEFT_J
:
1583 switch (fmt
& SND_SOC_DAIFMT_INV_MASK
) {
1584 case SND_SOC_DAIFMT_NB_NF
:
1586 case SND_SOC_DAIFMT_NB_IF
:
1587 regval
|= M98095_DAI_WCI
;
1589 case SND_SOC_DAIFMT_IB_NF
:
1590 regval
|= M98095_DAI_BCI
;
1592 case SND_SOC_DAIFMT_IB_IF
:
1593 regval
|= M98095_DAI_BCI
|M98095_DAI_WCI
;
1599 snd_soc_update_bits(codec
, M98095_02A_DAI1_FORMAT
,
1600 M98095_DAI_MAS
| M98095_DAI_DLY
| M98095_DAI_BCI
|
1601 M98095_DAI_WCI
, regval
);
1603 snd_soc_write(codec
, M98095_02B_DAI1_CLOCK
, M98095_DAI_BSEL64
);
1609 static int max98095_dai2_set_fmt(struct snd_soc_dai
*codec_dai
,
1612 struct snd_soc_codec
*codec
= codec_dai
->codec
;
1613 struct max98095_priv
*max98095
= snd_soc_codec_get_drvdata(codec
);
1614 struct max98095_cdata
*cdata
;
1617 cdata
= &max98095
->dai
[1];
1619 if (fmt
!= cdata
->fmt
) {
1622 switch (fmt
& SND_SOC_DAIFMT_MASTER_MASK
) {
1623 case SND_SOC_DAIFMT_CBS_CFS
:
1624 /* Slave mode PLL */
1625 snd_soc_write(codec
, M98095_032_DAI2_CLKCFG_HI
,
1627 snd_soc_write(codec
, M98095_033_DAI2_CLKCFG_LO
,
1630 case SND_SOC_DAIFMT_CBM_CFM
:
1631 /* Set to master mode */
1632 regval
|= M98095_DAI_MAS
;
1634 case SND_SOC_DAIFMT_CBS_CFM
:
1635 case SND_SOC_DAIFMT_CBM_CFS
:
1637 dev_err(codec
->dev
, "Clock mode unsupported");
1641 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
1642 case SND_SOC_DAIFMT_I2S
:
1643 regval
|= M98095_DAI_DLY
;
1645 case SND_SOC_DAIFMT_LEFT_J
:
1651 switch (fmt
& SND_SOC_DAIFMT_INV_MASK
) {
1652 case SND_SOC_DAIFMT_NB_NF
:
1654 case SND_SOC_DAIFMT_NB_IF
:
1655 regval
|= M98095_DAI_WCI
;
1657 case SND_SOC_DAIFMT_IB_NF
:
1658 regval
|= M98095_DAI_BCI
;
1660 case SND_SOC_DAIFMT_IB_IF
:
1661 regval
|= M98095_DAI_BCI
|M98095_DAI_WCI
;
1667 snd_soc_update_bits(codec
, M98095_034_DAI2_FORMAT
,
1668 M98095_DAI_MAS
| M98095_DAI_DLY
| M98095_DAI_BCI
|
1669 M98095_DAI_WCI
, regval
);
1671 snd_soc_write(codec
, M98095_035_DAI2_CLOCK
,
1678 static int max98095_dai3_set_fmt(struct snd_soc_dai
*codec_dai
,
1681 struct snd_soc_codec
*codec
= codec_dai
->codec
;
1682 struct max98095_priv
*max98095
= snd_soc_codec_get_drvdata(codec
);
1683 struct max98095_cdata
*cdata
;
1686 cdata
= &max98095
->dai
[2];
1688 if (fmt
!= cdata
->fmt
) {
1691 switch (fmt
& SND_SOC_DAIFMT_MASTER_MASK
) {
1692 case SND_SOC_DAIFMT_CBS_CFS
:
1693 /* Slave mode PLL */
1694 snd_soc_write(codec
, M98095_03C_DAI3_CLKCFG_HI
,
1696 snd_soc_write(codec
, M98095_03D_DAI3_CLKCFG_LO
,
1699 case SND_SOC_DAIFMT_CBM_CFM
:
1700 /* Set to master mode */
1701 regval
|= M98095_DAI_MAS
;
1703 case SND_SOC_DAIFMT_CBS_CFM
:
1704 case SND_SOC_DAIFMT_CBM_CFS
:
1706 dev_err(codec
->dev
, "Clock mode unsupported");
1710 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
1711 case SND_SOC_DAIFMT_I2S
:
1712 regval
|= M98095_DAI_DLY
;
1714 case SND_SOC_DAIFMT_LEFT_J
:
1720 switch (fmt
& SND_SOC_DAIFMT_INV_MASK
) {
1721 case SND_SOC_DAIFMT_NB_NF
:
1723 case SND_SOC_DAIFMT_NB_IF
:
1724 regval
|= M98095_DAI_WCI
;
1726 case SND_SOC_DAIFMT_IB_NF
:
1727 regval
|= M98095_DAI_BCI
;
1729 case SND_SOC_DAIFMT_IB_IF
:
1730 regval
|= M98095_DAI_BCI
|M98095_DAI_WCI
;
1736 snd_soc_update_bits(codec
, M98095_03E_DAI3_FORMAT
,
1737 M98095_DAI_MAS
| M98095_DAI_DLY
| M98095_DAI_BCI
|
1738 M98095_DAI_WCI
, regval
);
1740 snd_soc_write(codec
, M98095_03F_DAI3_CLOCK
,
1747 static int max98095_set_bias_level(struct snd_soc_codec
*codec
,
1748 enum snd_soc_bias_level level
)
1753 case SND_SOC_BIAS_ON
:
1756 case SND_SOC_BIAS_PREPARE
:
1759 case SND_SOC_BIAS_STANDBY
:
1760 if (codec
->dapm
.bias_level
== SND_SOC_BIAS_OFF
) {
1761 ret
= snd_soc_cache_sync(codec
);
1764 dev_err(codec
->dev
, "Failed to sync cache: %d\n", ret
);
1769 snd_soc_update_bits(codec
, M98095_090_PWR_EN_IN
,
1770 M98095_MBEN
, M98095_MBEN
);
1773 case SND_SOC_BIAS_OFF
:
1774 snd_soc_update_bits(codec
, M98095_090_PWR_EN_IN
,
1776 codec
->cache_sync
= 1;
1779 codec
->dapm
.bias_level
= level
;
1783 #define MAX98095_RATES SNDRV_PCM_RATE_8000_96000
1784 #define MAX98095_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE)
1786 static struct snd_soc_dai_ops max98095_dai1_ops
= {
1787 .set_sysclk
= max98095_dai_set_sysclk
,
1788 .set_fmt
= max98095_dai1_set_fmt
,
1789 .hw_params
= max98095_dai1_hw_params
,
1792 static struct snd_soc_dai_ops max98095_dai2_ops
= {
1793 .set_sysclk
= max98095_dai_set_sysclk
,
1794 .set_fmt
= max98095_dai2_set_fmt
,
1795 .hw_params
= max98095_dai2_hw_params
,
1798 static struct snd_soc_dai_ops max98095_dai3_ops
= {
1799 .set_sysclk
= max98095_dai_set_sysclk
,
1800 .set_fmt
= max98095_dai3_set_fmt
,
1801 .hw_params
= max98095_dai3_hw_params
,
1804 static struct snd_soc_dai_driver max98095_dai
[] = {
1808 .stream_name
= "HiFi Playback",
1811 .rates
= MAX98095_RATES
,
1812 .formats
= MAX98095_FORMATS
,
1815 .stream_name
= "HiFi Capture",
1818 .rates
= MAX98095_RATES
,
1819 .formats
= MAX98095_FORMATS
,
1821 .ops
= &max98095_dai1_ops
,
1826 .stream_name
= "Aux Playback",
1829 .rates
= MAX98095_RATES
,
1830 .formats
= MAX98095_FORMATS
,
1832 .ops
= &max98095_dai2_ops
,
1837 .stream_name
= "Voice Playback",
1840 .rates
= MAX98095_RATES
,
1841 .formats
= MAX98095_FORMATS
,
1843 .ops
= &max98095_dai3_ops
,
1848 static int max98095_get_eq_channel(const char *name
)
1850 if (strcmp(name
, "EQ1 Mode") == 0)
1852 if (strcmp(name
, "EQ2 Mode") == 0)
1857 static int max98095_put_eq_enum(struct snd_kcontrol
*kcontrol
,
1858 struct snd_ctl_elem_value
*ucontrol
)
1860 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1861 struct max98095_priv
*max98095
= snd_soc_codec_get_drvdata(codec
);
1862 struct max98095_pdata
*pdata
= max98095
->pdata
;
1863 int channel
= max98095_get_eq_channel(kcontrol
->id
.name
);
1864 struct max98095_cdata
*cdata
;
1865 int sel
= ucontrol
->value
.integer
.value
[0];
1866 struct max98095_eq_cfg
*coef_set
;
1867 int fs
, best
, best_val
, i
;
1868 int regmask
, regsave
;
1870 BUG_ON(channel
> 1);
1872 if (!pdata
|| !max98095
->eq_textcnt
)
1875 if (sel
>= pdata
->eq_cfgcnt
)
1878 cdata
= &max98095
->dai
[channel
];
1879 cdata
->eq_sel
= sel
;
1882 /* Find the selected configuration with nearest sample rate */
1885 for (i
= 0; i
< pdata
->eq_cfgcnt
; i
++) {
1886 if (strcmp(pdata
->eq_cfg
[i
].name
, max98095
->eq_texts
[sel
]) == 0 &&
1887 abs(pdata
->eq_cfg
[i
].rate
- fs
) < best_val
) {
1889 best_val
= abs(pdata
->eq_cfg
[i
].rate
- fs
);
1893 dev_dbg(codec
->dev
, "Selected %s/%dHz for %dHz sample rate\n",
1894 pdata
->eq_cfg
[best
].name
,
1895 pdata
->eq_cfg
[best
].rate
, fs
);
1897 coef_set
= &pdata
->eq_cfg
[best
];
1899 regmask
= (channel
== 0) ? M98095_EQ1EN
: M98095_EQ2EN
;
1901 /* Disable filter while configuring, and save current on/off state */
1902 regsave
= snd_soc_read(codec
, M98095_088_CFG_LEVEL
);
1903 snd_soc_update_bits(codec
, M98095_088_CFG_LEVEL
, regmask
, 0);
1905 mutex_lock(&codec
->mutex
);
1906 snd_soc_update_bits(codec
, M98095_00F_HOST_CFG
, M98095_SEG
, M98095_SEG
);
1907 m98095_eq_band(codec
, channel
, 0, coef_set
->band1
);
1908 m98095_eq_band(codec
, channel
, 1, coef_set
->band2
);
1909 m98095_eq_band(codec
, channel
, 2, coef_set
->band3
);
1910 m98095_eq_band(codec
, channel
, 3, coef_set
->band4
);
1911 m98095_eq_band(codec
, channel
, 4, coef_set
->band5
);
1912 snd_soc_update_bits(codec
, M98095_00F_HOST_CFG
, M98095_SEG
, 0);
1913 mutex_unlock(&codec
->mutex
);
1915 /* Restore the original on/off state */
1916 snd_soc_update_bits(codec
, M98095_088_CFG_LEVEL
, regmask
, regsave
);
1920 static int max98095_get_eq_enum(struct snd_kcontrol
*kcontrol
,
1921 struct snd_ctl_elem_value
*ucontrol
)
1923 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1924 struct max98095_priv
*max98095
= snd_soc_codec_get_drvdata(codec
);
1925 int channel
= max98095_get_eq_channel(kcontrol
->id
.name
);
1926 struct max98095_cdata
*cdata
;
1928 cdata
= &max98095
->dai
[channel
];
1929 ucontrol
->value
.enumerated
.item
[0] = cdata
->eq_sel
;
1934 static void max98095_handle_eq_pdata(struct snd_soc_codec
*codec
)
1936 struct max98095_priv
*max98095
= snd_soc_codec_get_drvdata(codec
);
1937 struct max98095_pdata
*pdata
= max98095
->pdata
;
1938 struct max98095_eq_cfg
*cfg
;
1939 unsigned int cfgcnt
;
1944 struct snd_kcontrol_new controls
[] = {
1945 SOC_ENUM_EXT("EQ1 Mode",
1947 max98095_get_eq_enum
,
1948 max98095_put_eq_enum
),
1949 SOC_ENUM_EXT("EQ2 Mode",
1951 max98095_get_eq_enum
,
1952 max98095_put_eq_enum
),
1955 cfg
= pdata
->eq_cfg
;
1956 cfgcnt
= pdata
->eq_cfgcnt
;
1958 /* Setup an array of texts for the equalizer enum.
1959 * This is based on Mark Brown's equalizer driver code.
1961 max98095
->eq_textcnt
= 0;
1962 max98095
->eq_texts
= NULL
;
1963 for (i
= 0; i
< cfgcnt
; i
++) {
1964 for (j
= 0; j
< max98095
->eq_textcnt
; j
++) {
1965 if (strcmp(cfg
[i
].name
, max98095
->eq_texts
[j
]) == 0)
1969 if (j
!= max98095
->eq_textcnt
)
1972 /* Expand the array */
1973 t
= krealloc(max98095
->eq_texts
,
1974 sizeof(char *) * (max98095
->eq_textcnt
+ 1),
1979 /* Store the new entry */
1980 t
[max98095
->eq_textcnt
] = cfg
[i
].name
;
1981 max98095
->eq_textcnt
++;
1982 max98095
->eq_texts
= t
;
1985 /* Now point the soc_enum to .texts array items */
1986 max98095
->eq_enum
.texts
= max98095
->eq_texts
;
1987 max98095
->eq_enum
.max
= max98095
->eq_textcnt
;
1989 ret
= snd_soc_add_controls(codec
, controls
, ARRAY_SIZE(controls
));
1991 dev_err(codec
->dev
, "Failed to add EQ control: %d\n", ret
);
1994 static const char *bq_mode_name
[] = {"Biquad1 Mode", "Biquad2 Mode"};
1996 static int max98095_get_bq_channel(struct snd_soc_codec
*codec
,
2001 for (i
= 0; i
< ARRAY_SIZE(bq_mode_name
); i
++)
2002 if (strcmp(name
, bq_mode_name
[i
]) == 0)
2005 /* Shouldn't happen */
2006 dev_err(codec
->dev
, "Bad biquad channel name '%s'\n", name
);
2010 static int max98095_put_bq_enum(struct snd_kcontrol
*kcontrol
,
2011 struct snd_ctl_elem_value
*ucontrol
)
2013 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2014 struct max98095_priv
*max98095
= snd_soc_codec_get_drvdata(codec
);
2015 struct max98095_pdata
*pdata
= max98095
->pdata
;
2016 int channel
= max98095_get_bq_channel(codec
, kcontrol
->id
.name
);
2017 struct max98095_cdata
*cdata
;
2018 int sel
= ucontrol
->value
.integer
.value
[0];
2019 struct max98095_biquad_cfg
*coef_set
;
2020 int fs
, best
, best_val
, i
;
2021 int regmask
, regsave
;
2026 if (!pdata
|| !max98095
->bq_textcnt
)
2029 if (sel
>= pdata
->bq_cfgcnt
)
2032 cdata
= &max98095
->dai
[channel
];
2033 cdata
->bq_sel
= sel
;
2036 /* Find the selected configuration with nearest sample rate */
2039 for (i
= 0; i
< pdata
->bq_cfgcnt
; i
++) {
2040 if (strcmp(pdata
->bq_cfg
[i
].name
, max98095
->bq_texts
[sel
]) == 0 &&
2041 abs(pdata
->bq_cfg
[i
].rate
- fs
) < best_val
) {
2043 best_val
= abs(pdata
->bq_cfg
[i
].rate
- fs
);
2047 dev_dbg(codec
->dev
, "Selected %s/%dHz for %dHz sample rate\n",
2048 pdata
->bq_cfg
[best
].name
,
2049 pdata
->bq_cfg
[best
].rate
, fs
);
2051 coef_set
= &pdata
->bq_cfg
[best
];
2053 regmask
= (channel
== 0) ? M98095_BQ1EN
: M98095_BQ2EN
;
2055 /* Disable filter while configuring, and save current on/off state */
2056 regsave
= snd_soc_read(codec
, M98095_088_CFG_LEVEL
);
2057 snd_soc_update_bits(codec
, M98095_088_CFG_LEVEL
, regmask
, 0);
2059 mutex_lock(&codec
->mutex
);
2060 snd_soc_update_bits(codec
, M98095_00F_HOST_CFG
, M98095_SEG
, M98095_SEG
);
2061 m98095_biquad_band(codec
, channel
, 0, coef_set
->band1
);
2062 m98095_biquad_band(codec
, channel
, 1, coef_set
->band2
);
2063 snd_soc_update_bits(codec
, M98095_00F_HOST_CFG
, M98095_SEG
, 0);
2064 mutex_unlock(&codec
->mutex
);
2066 /* Restore the original on/off state */
2067 snd_soc_update_bits(codec
, M98095_088_CFG_LEVEL
, regmask
, regsave
);
2071 static int max98095_get_bq_enum(struct snd_kcontrol
*kcontrol
,
2072 struct snd_ctl_elem_value
*ucontrol
)
2074 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2075 struct max98095_priv
*max98095
= snd_soc_codec_get_drvdata(codec
);
2076 int channel
= max98095_get_bq_channel(codec
, kcontrol
->id
.name
);
2077 struct max98095_cdata
*cdata
;
2082 cdata
= &max98095
->dai
[channel
];
2083 ucontrol
->value
.enumerated
.item
[0] = cdata
->bq_sel
;
2088 static void max98095_handle_bq_pdata(struct snd_soc_codec
*codec
)
2090 struct max98095_priv
*max98095
= snd_soc_codec_get_drvdata(codec
);
2091 struct max98095_pdata
*pdata
= max98095
->pdata
;
2092 struct max98095_biquad_cfg
*cfg
;
2093 unsigned int cfgcnt
;
2098 struct snd_kcontrol_new controls
[] = {
2099 SOC_ENUM_EXT((char *)bq_mode_name
[0],
2101 max98095_get_bq_enum
,
2102 max98095_put_bq_enum
),
2103 SOC_ENUM_EXT((char *)bq_mode_name
[1],
2105 max98095_get_bq_enum
,
2106 max98095_put_bq_enum
),
2108 BUILD_BUG_ON(ARRAY_SIZE(controls
) != ARRAY_SIZE(bq_mode_name
));
2110 cfg
= pdata
->bq_cfg
;
2111 cfgcnt
= pdata
->bq_cfgcnt
;
2113 /* Setup an array of texts for the biquad enum.
2114 * This is based on Mark Brown's equalizer driver code.
2116 max98095
->bq_textcnt
= 0;
2117 max98095
->bq_texts
= NULL
;
2118 for (i
= 0; i
< cfgcnt
; i
++) {
2119 for (j
= 0; j
< max98095
->bq_textcnt
; j
++) {
2120 if (strcmp(cfg
[i
].name
, max98095
->bq_texts
[j
]) == 0)
2124 if (j
!= max98095
->bq_textcnt
)
2127 /* Expand the array */
2128 t
= krealloc(max98095
->bq_texts
,
2129 sizeof(char *) * (max98095
->bq_textcnt
+ 1),
2134 /* Store the new entry */
2135 t
[max98095
->bq_textcnt
] = cfg
[i
].name
;
2136 max98095
->bq_textcnt
++;
2137 max98095
->bq_texts
= t
;
2140 /* Now point the soc_enum to .texts array items */
2141 max98095
->bq_enum
.texts
= max98095
->bq_texts
;
2142 max98095
->bq_enum
.max
= max98095
->bq_textcnt
;
2144 ret
= snd_soc_add_controls(codec
, controls
, ARRAY_SIZE(controls
));
2146 dev_err(codec
->dev
, "Failed to add Biquad control: %d\n", ret
);
2149 static void max98095_handle_pdata(struct snd_soc_codec
*codec
)
2151 struct max98095_priv
*max98095
= snd_soc_codec_get_drvdata(codec
);
2152 struct max98095_pdata
*pdata
= max98095
->pdata
;
2156 dev_dbg(codec
->dev
, "No platform data\n");
2160 /* Configure mic for analog/digital mic mode */
2161 if (pdata
->digmic_left_mode
)
2162 regval
|= M98095_DIGMIC_L
;
2164 if (pdata
->digmic_right_mode
)
2165 regval
|= M98095_DIGMIC_R
;
2167 snd_soc_write(codec
, M98095_087_CFG_MIC
, regval
);
2169 /* Configure equalizers */
2170 if (pdata
->eq_cfgcnt
)
2171 max98095_handle_eq_pdata(codec
);
2173 /* Configure bi-quad filters */
2174 if (pdata
->bq_cfgcnt
)
2175 max98095_handle_bq_pdata(codec
);
2179 static int max98095_suspend(struct snd_soc_codec
*codec
, pm_message_t state
)
2181 max98095_set_bias_level(codec
, SND_SOC_BIAS_OFF
);
2186 static int max98095_resume(struct snd_soc_codec
*codec
)
2188 max98095_set_bias_level(codec
, SND_SOC_BIAS_STANDBY
);
2193 #define max98095_suspend NULL
2194 #define max98095_resume NULL
2197 static int max98095_reset(struct snd_soc_codec
*codec
)
2201 /* Gracefully reset the DSP core and the codec hardware
2202 * in a proper sequence */
2203 ret
= snd_soc_write(codec
, M98095_00F_HOST_CFG
, 0);
2205 dev_err(codec
->dev
, "Failed to reset DSP: %d\n", ret
);
2209 ret
= snd_soc_write(codec
, M98095_097_PWR_SYS
, 0);
2211 dev_err(codec
->dev
, "Failed to reset codec: %d\n", ret
);
2215 /* Reset to hardware default for registers, as there is not
2216 * a soft reset hardware control register */
2217 for (i
= M98095_010_HOST_INT_CFG
; i
< M98095_REG_MAX_CACHED
; i
++) {
2218 ret
= snd_soc_write(codec
, i
, max98095_reg_def
[i
]);
2220 dev_err(codec
->dev
, "Failed to reset: %d\n", ret
);
2228 static int max98095_probe(struct snd_soc_codec
*codec
)
2230 struct max98095_priv
*max98095
= snd_soc_codec_get_drvdata(codec
);
2231 struct max98095_cdata
*cdata
;
2234 ret
= snd_soc_codec_set_cache_io(codec
, 8, 8, SND_SOC_I2C
);
2236 dev_err(codec
->dev
, "Failed to set cache I/O: %d\n", ret
);
2240 /* reset the codec, the DSP core, and disable all interrupts */
2241 max98095_reset(codec
);
2243 /* initialize private data */
2245 max98095
->sysclk
= (unsigned)-1;
2246 max98095
->eq_textcnt
= 0;
2247 max98095
->bq_textcnt
= 0;
2249 cdata
= &max98095
->dai
[0];
2250 cdata
->rate
= (unsigned)-1;
2251 cdata
->fmt
= (unsigned)-1;
2255 cdata
= &max98095
->dai
[1];
2256 cdata
->rate
= (unsigned)-1;
2257 cdata
->fmt
= (unsigned)-1;
2261 cdata
= &max98095
->dai
[2];
2262 cdata
->rate
= (unsigned)-1;
2263 cdata
->fmt
= (unsigned)-1;
2267 max98095
->lin_state
= 0;
2268 max98095
->mic1pre
= 0;
2269 max98095
->mic2pre
= 0;
2271 ret
= snd_soc_read(codec
, M98095_0FF_REV_ID
);
2273 dev_err(codec
->dev
, "Failure reading hardware revision: %d\n",
2277 dev_info(codec
->dev
, "Hardware revision: %c\n", ret
- 0x40 + 'A');
2279 snd_soc_write(codec
, M98095_097_PWR_SYS
, M98095_PWRSV
);
2281 /* initialize registers cache to hardware default */
2282 max98095_set_bias_level(codec
, SND_SOC_BIAS_STANDBY
);
2284 snd_soc_write(codec
, M98095_048_MIX_DAC_LR
,
2285 M98095_DAI1L_TO_DACL
|M98095_DAI1R_TO_DACR
);
2287 snd_soc_write(codec
, M98095_049_MIX_DAC_M
,
2288 M98095_DAI2M_TO_DACM
|M98095_DAI3M_TO_DACM
);
2290 snd_soc_write(codec
, M98095_092_PWR_EN_OUT
, M98095_SPK_SPREADSPECTRUM
);
2291 snd_soc_write(codec
, M98095_045_CFG_DSP
, M98095_DSPNORMAL
);
2292 snd_soc_write(codec
, M98095_04E_CFG_HP
, M98095_HPNORMAL
);
2294 snd_soc_write(codec
, M98095_02C_DAI1_IOCFG
,
2295 M98095_S1NORMAL
|M98095_SDATA
);
2297 snd_soc_write(codec
, M98095_036_DAI2_IOCFG
,
2298 M98095_S2NORMAL
|M98095_SDATA
);
2300 snd_soc_write(codec
, M98095_040_DAI3_IOCFG
,
2301 M98095_S3NORMAL
|M98095_SDATA
);
2303 max98095_handle_pdata(codec
);
2305 /* take the codec out of the shut down */
2306 snd_soc_update_bits(codec
, M98095_097_PWR_SYS
, M98095_SHDNRUN
,
2309 max98095_add_widgets(codec
);
2315 static int max98095_remove(struct snd_soc_codec
*codec
)
2317 max98095_set_bias_level(codec
, SND_SOC_BIAS_OFF
);
2322 static struct snd_soc_codec_driver soc_codec_dev_max98095
= {
2323 .probe
= max98095_probe
,
2324 .remove
= max98095_remove
,
2325 .suspend
= max98095_suspend
,
2326 .resume
= max98095_resume
,
2327 .set_bias_level
= max98095_set_bias_level
,
2328 .reg_cache_size
= ARRAY_SIZE(max98095_reg_def
),
2329 .reg_word_size
= sizeof(u8
),
2330 .reg_cache_default
= max98095_reg_def
,
2331 .readable_register
= max98095_readable
,
2332 .volatile_register
= max98095_volatile
,
2333 .dapm_widgets
= max98095_dapm_widgets
,
2334 .num_dapm_widgets
= ARRAY_SIZE(max98095_dapm_widgets
),
2335 .dapm_routes
= max98095_audio_map
,
2336 .num_dapm_routes
= ARRAY_SIZE(max98095_audio_map
),
2339 static int max98095_i2c_probe(struct i2c_client
*i2c
,
2340 const struct i2c_device_id
*id
)
2342 struct max98095_priv
*max98095
;
2345 max98095
= kzalloc(sizeof(struct max98095_priv
), GFP_KERNEL
);
2346 if (max98095
== NULL
)
2349 max98095
->devtype
= id
->driver_data
;
2350 i2c_set_clientdata(i2c
, max98095
);
2351 max98095
->pdata
= i2c
->dev
.platform_data
;
2353 ret
= snd_soc_register_codec(&i2c
->dev
, &soc_codec_dev_max98095
,
2354 max98095_dai
, ARRAY_SIZE(max98095_dai
));
2360 static int __devexit
max98095_i2c_remove(struct i2c_client
*client
)
2362 snd_soc_unregister_codec(&client
->dev
);
2363 kfree(i2c_get_clientdata(client
));
2368 static const struct i2c_device_id max98095_i2c_id
[] = {
2369 { "max98095", MAX98095
},
2372 MODULE_DEVICE_TABLE(i2c
, max98095_i2c_id
);
2374 static struct i2c_driver max98095_i2c_driver
= {
2377 .owner
= THIS_MODULE
,
2379 .probe
= max98095_i2c_probe
,
2380 .remove
= __devexit_p(max98095_i2c_remove
),
2381 .id_table
= max98095_i2c_id
,
2384 static int __init
max98095_init(void)
2388 ret
= i2c_add_driver(&max98095_i2c_driver
);
2390 pr_err("Failed to register max98095 I2C driver: %d\n", ret
);
2394 module_init(max98095_init
);
2396 static void __exit
max98095_exit(void)
2398 i2c_del_driver(&max98095_i2c_driver
);
2400 module_exit(max98095_exit
);
2402 MODULE_DESCRIPTION("ALSA SoC MAX98095 driver");
2403 MODULE_AUTHOR("Peter Hsiang");
2404 MODULE_LICENSE("GPL");