2 * wm8995.c -- WM8995 ALSA SoC Audio driver
4 * Copyright 2010 Wolfson Microelectronics plc
6 * Author: Dimitris Papastamos <dp@opensource.wolfsonmicro.com>
8 * Based on wm8994.c and wm_hubs.c by Mark Brown
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
15 #include <linux/module.h>
16 #include <linux/moduleparam.h>
17 #include <linux/init.h>
18 #include <linux/delay.h>
20 #include <linux/i2c.h>
21 #include <linux/regmap.h>
22 #include <linux/spi/spi.h>
23 #include <linux/regulator/consumer.h>
24 #include <linux/slab.h>
25 #include <sound/core.h>
26 #include <sound/pcm.h>
27 #include <sound/pcm_params.h>
28 #include <sound/soc.h>
29 #include <sound/soc-dapm.h>
30 #include <sound/initval.h>
31 #include <sound/tlv.h>
35 #define WM8995_NUM_SUPPLIES 8
36 static const char *wm8995_supply_names
[WM8995_NUM_SUPPLIES
] = {
47 static struct reg_default wm8995_reg_defaults
[] = {
381 struct regmap
*regmap
;
385 struct fll_config fll
[2], fll_suspend
[2];
386 struct regulator_bulk_data supplies
[WM8995_NUM_SUPPLIES
];
387 struct notifier_block disable_nb
[WM8995_NUM_SUPPLIES
];
388 struct snd_soc_codec
*codec
;
392 * We can't use the same notifier block for more than one supply and
393 * there's no way I can see to get from a callback to the caller
394 * except container_of().
396 #define WM8995_REGULATOR_EVENT(n) \
397 static int wm8995_regulator_event_##n(struct notifier_block *nb, \
398 unsigned long event, void *data) \
400 struct wm8995_priv *wm8995 = container_of(nb, struct wm8995_priv, \
402 if (event & REGULATOR_EVENT_DISABLE) { \
403 regcache_mark_dirty(wm8995->regmap); \
408 WM8995_REGULATOR_EVENT(0)
409 WM8995_REGULATOR_EVENT(1)
410 WM8995_REGULATOR_EVENT(2)
411 WM8995_REGULATOR_EVENT(3)
412 WM8995_REGULATOR_EVENT(4)
413 WM8995_REGULATOR_EVENT(5)
414 WM8995_REGULATOR_EVENT(6)
415 WM8995_REGULATOR_EVENT(7)
417 static const DECLARE_TLV_DB_SCALE(digital_tlv
, -7200, 75, 1);
418 static const DECLARE_TLV_DB_SCALE(in1lr_pga_tlv
, -1650, 150, 0);
419 static const DECLARE_TLV_DB_SCALE(in1l_boost_tlv
, 0, 600, 0);
420 static const DECLARE_TLV_DB_SCALE(sidetone_tlv
, -3600, 150, 0);
422 static const char *in1l_text
[] = {
423 "Differential", "Single-ended IN1LN", "Single-ended IN1LP"
426 static const SOC_ENUM_SINGLE_DECL(in1l_enum
, WM8995_LEFT_LINE_INPUT_CONTROL
,
429 static const char *in1r_text
[] = {
430 "Differential", "Single-ended IN1RN", "Single-ended IN1RP"
433 static const SOC_ENUM_SINGLE_DECL(in1r_enum
, WM8995_LEFT_LINE_INPUT_CONTROL
,
436 static const char *dmic_src_text
[] = {
437 "DMICDAT1", "DMICDAT2", "DMICDAT3"
440 static const SOC_ENUM_SINGLE_DECL(dmic_src1_enum
, WM8995_POWER_MANAGEMENT_5
,
442 static const SOC_ENUM_SINGLE_DECL(dmic_src2_enum
, WM8995_POWER_MANAGEMENT_5
,
445 static const struct snd_kcontrol_new wm8995_snd_controls
[] = {
446 SOC_DOUBLE_R_TLV("DAC1 Volume", WM8995_DAC1_LEFT_VOLUME
,
447 WM8995_DAC1_RIGHT_VOLUME
, 0, 96, 0, digital_tlv
),
448 SOC_DOUBLE_R("DAC1 Switch", WM8995_DAC1_LEFT_VOLUME
,
449 WM8995_DAC1_RIGHT_VOLUME
, 9, 1, 1),
451 SOC_DOUBLE_R_TLV("DAC2 Volume", WM8995_DAC2_LEFT_VOLUME
,
452 WM8995_DAC2_RIGHT_VOLUME
, 0, 96, 0, digital_tlv
),
453 SOC_DOUBLE_R("DAC2 Switch", WM8995_DAC2_LEFT_VOLUME
,
454 WM8995_DAC2_RIGHT_VOLUME
, 9, 1, 1),
456 SOC_DOUBLE_R_TLV("AIF1DAC1 Volume", WM8995_AIF1_DAC1_LEFT_VOLUME
,
457 WM8995_AIF1_DAC1_RIGHT_VOLUME
, 0, 96, 0, digital_tlv
),
458 SOC_DOUBLE_R_TLV("AIF1DAC2 Volume", WM8995_AIF1_DAC2_LEFT_VOLUME
,
459 WM8995_AIF1_DAC2_RIGHT_VOLUME
, 0, 96, 0, digital_tlv
),
460 SOC_DOUBLE_R_TLV("AIF2DAC Volume", WM8995_AIF2_DAC_LEFT_VOLUME
,
461 WM8995_AIF2_DAC_RIGHT_VOLUME
, 0, 96, 0, digital_tlv
),
463 SOC_DOUBLE_R_TLV("IN1LR Volume", WM8995_LEFT_LINE_INPUT_1_VOLUME
,
464 WM8995_RIGHT_LINE_INPUT_1_VOLUME
, 0, 31, 0, in1lr_pga_tlv
),
466 SOC_SINGLE_TLV("IN1L Boost", WM8995_LEFT_LINE_INPUT_CONTROL
,
467 4, 3, 0, in1l_boost_tlv
),
469 SOC_ENUM("IN1L Mode", in1l_enum
),
470 SOC_ENUM("IN1R Mode", in1r_enum
),
472 SOC_ENUM("DMIC1 SRC", dmic_src1_enum
),
473 SOC_ENUM("DMIC2 SRC", dmic_src2_enum
),
475 SOC_DOUBLE_TLV("DAC1 Sidetone Volume", WM8995_DAC1_MIXER_VOLUMES
, 0, 5,
476 24, 0, sidetone_tlv
),
477 SOC_DOUBLE_TLV("DAC2 Sidetone Volume", WM8995_DAC2_MIXER_VOLUMES
, 0, 5,
478 24, 0, sidetone_tlv
),
480 SOC_DOUBLE_R_TLV("AIF1ADC1 Volume", WM8995_AIF1_ADC1_LEFT_VOLUME
,
481 WM8995_AIF1_ADC1_RIGHT_VOLUME
, 0, 96, 0, digital_tlv
),
482 SOC_DOUBLE_R_TLV("AIF1ADC2 Volume", WM8995_AIF1_ADC2_LEFT_VOLUME
,
483 WM8995_AIF1_ADC2_RIGHT_VOLUME
, 0, 96, 0, digital_tlv
),
484 SOC_DOUBLE_R_TLV("AIF2ADC Volume", WM8995_AIF2_ADC_LEFT_VOLUME
,
485 WM8995_AIF2_ADC_RIGHT_VOLUME
, 0, 96, 0, digital_tlv
)
488 static void wm8995_update_class_w(struct snd_soc_codec
*codec
)
491 int source
= 0; /* GCC flow analysis can't track enable */
494 /* We also need the same setting for L/R and only one path */
495 reg
= snd_soc_read(codec
, WM8995_DAC1_LEFT_MIXER_ROUTING
);
497 case WM8995_AIF2DACL_TO_DAC1L
:
498 dev_dbg(codec
->dev
, "Class W source AIF2DAC\n");
499 source
= 2 << WM8995_CP_DYN_SRC_SEL_SHIFT
;
501 case WM8995_AIF1DAC2L_TO_DAC1L
:
502 dev_dbg(codec
->dev
, "Class W source AIF1DAC2\n");
503 source
= 1 << WM8995_CP_DYN_SRC_SEL_SHIFT
;
505 case WM8995_AIF1DAC1L_TO_DAC1L
:
506 dev_dbg(codec
->dev
, "Class W source AIF1DAC1\n");
507 source
= 0 << WM8995_CP_DYN_SRC_SEL_SHIFT
;
510 dev_dbg(codec
->dev
, "DAC mixer setting: %x\n", reg
);
515 reg_r
= snd_soc_read(codec
, WM8995_DAC1_RIGHT_MIXER_ROUTING
);
517 dev_dbg(codec
->dev
, "Left and right DAC mixers different\n");
522 dev_dbg(codec
->dev
, "Class W enabled\n");
523 snd_soc_update_bits(codec
, WM8995_CLASS_W_1
,
524 WM8995_CP_DYN_PWR_MASK
|
525 WM8995_CP_DYN_SRC_SEL_MASK
,
526 source
| WM8995_CP_DYN_PWR
);
528 dev_dbg(codec
->dev
, "Class W disabled\n");
529 snd_soc_update_bits(codec
, WM8995_CLASS_W_1
,
530 WM8995_CP_DYN_PWR_MASK
, 0);
534 static int check_clk_sys(struct snd_soc_dapm_widget
*source
,
535 struct snd_soc_dapm_widget
*sink
)
540 reg
= snd_soc_read(source
->codec
, WM8995_CLOCKING_1
);
541 /* Check what we're currently using for CLK_SYS */
542 if (reg
& WM8995_SYSCLK_SRC
)
546 return !strcmp(source
->name
, clk
);
549 static int wm8995_put_class_w(struct snd_kcontrol
*kcontrol
,
550 struct snd_ctl_elem_value
*ucontrol
)
552 struct snd_soc_codec
*codec
= snd_soc_dapm_kcontrol_codec(kcontrol
);
555 ret
= snd_soc_dapm_put_volsw(kcontrol
, ucontrol
);
556 wm8995_update_class_w(codec
);
560 static int hp_supply_event(struct snd_soc_dapm_widget
*w
,
561 struct snd_kcontrol
*kcontrol
, int event
)
563 struct snd_soc_codec
*codec
;
564 struct wm8995_priv
*wm8995
;
567 wm8995
= snd_soc_codec_get_drvdata(codec
);
570 case SND_SOC_DAPM_PRE_PMU
:
571 /* Enable the headphone amp */
572 snd_soc_update_bits(codec
, WM8995_POWER_MANAGEMENT_1
,
573 WM8995_HPOUT1L_ENA_MASK
|
574 WM8995_HPOUT1R_ENA_MASK
,
578 /* Enable the second stage */
579 snd_soc_update_bits(codec
, WM8995_ANALOGUE_HP_1
,
580 WM8995_HPOUT1L_DLY_MASK
|
581 WM8995_HPOUT1R_DLY_MASK
,
585 case SND_SOC_DAPM_PRE_PMD
:
586 snd_soc_update_bits(codec
, WM8995_CHARGE_PUMP_1
,
587 WM8995_CP_ENA_MASK
, 0);
594 static void dc_servo_cmd(struct snd_soc_codec
*codec
,
595 unsigned int reg
, unsigned int val
, unsigned int mask
)
599 dev_dbg(codec
->dev
, "%s: reg = %#x, val = %#x, mask = %#x\n",
600 __func__
, reg
, val
, mask
);
602 snd_soc_write(codec
, reg
, val
);
605 val
= snd_soc_read(codec
, WM8995_DC_SERVO_READBACK_0
);
606 if ((val
& mask
) == mask
)
610 dev_err(codec
->dev
, "Timed out waiting for DC Servo\n");
613 static int hp_event(struct snd_soc_dapm_widget
*w
,
614 struct snd_kcontrol
*kcontrol
, int event
)
616 struct snd_soc_codec
*codec
;
620 reg
= snd_soc_read(codec
, WM8995_ANALOGUE_HP_1
);
623 case SND_SOC_DAPM_POST_PMU
:
624 snd_soc_update_bits(codec
, WM8995_CHARGE_PUMP_1
,
625 WM8995_CP_ENA_MASK
, WM8995_CP_ENA
);
629 snd_soc_update_bits(codec
, WM8995_POWER_MANAGEMENT_1
,
630 WM8995_HPOUT1L_ENA_MASK
|
631 WM8995_HPOUT1R_ENA_MASK
,
632 WM8995_HPOUT1L_ENA
| WM8995_HPOUT1R_ENA
);
636 reg
|= WM8995_HPOUT1L_DLY
| WM8995_HPOUT1R_DLY
;
637 snd_soc_write(codec
, WM8995_ANALOGUE_HP_1
, reg
);
639 snd_soc_write(codec
, WM8995_DC_SERVO_1
, WM8995_DCS_ENA_CHAN_0
|
640 WM8995_DCS_ENA_CHAN_1
);
642 dc_servo_cmd(codec
, WM8995_DC_SERVO_2
,
643 WM8995_DCS_TRIG_STARTUP_0
|
644 WM8995_DCS_TRIG_STARTUP_1
,
645 WM8995_DCS_TRIG_DAC_WR_0
|
646 WM8995_DCS_TRIG_DAC_WR_1
);
648 reg
|= WM8995_HPOUT1R_OUTP
| WM8995_HPOUT1R_RMV_SHORT
|
649 WM8995_HPOUT1L_OUTP
| WM8995_HPOUT1L_RMV_SHORT
;
650 snd_soc_write(codec
, WM8995_ANALOGUE_HP_1
, reg
);
653 case SND_SOC_DAPM_PRE_PMD
:
654 snd_soc_update_bits(codec
, WM8995_ANALOGUE_HP_1
,
655 WM8995_HPOUT1L_OUTP_MASK
|
656 WM8995_HPOUT1R_OUTP_MASK
|
657 WM8995_HPOUT1L_RMV_SHORT_MASK
|
658 WM8995_HPOUT1R_RMV_SHORT_MASK
, 0);
660 snd_soc_update_bits(codec
, WM8995_ANALOGUE_HP_1
,
661 WM8995_HPOUT1L_DLY_MASK
|
662 WM8995_HPOUT1R_DLY_MASK
, 0);
664 snd_soc_write(codec
, WM8995_DC_SERVO_1
, 0);
666 snd_soc_update_bits(codec
, WM8995_POWER_MANAGEMENT_1
,
667 WM8995_HPOUT1L_ENA_MASK
|
668 WM8995_HPOUT1R_ENA_MASK
,
676 static int configure_aif_clock(struct snd_soc_codec
*codec
, int aif
)
678 struct wm8995_priv
*wm8995
;
683 wm8995
= snd_soc_codec_get_drvdata(codec
);
690 switch (wm8995
->sysclk
[aif
]) {
691 case WM8995_SYSCLK_MCLK1
:
692 rate
= wm8995
->mclk
[0];
694 case WM8995_SYSCLK_MCLK2
:
696 rate
= wm8995
->mclk
[1];
698 case WM8995_SYSCLK_FLL1
:
700 rate
= wm8995
->fll
[0].out
;
702 case WM8995_SYSCLK_FLL2
:
704 rate
= wm8995
->fll
[1].out
;
710 if (rate
>= 13500000) {
712 reg1
|= WM8995_AIF1CLK_DIV
;
714 dev_dbg(codec
->dev
, "Dividing AIF%d clock to %dHz\n",
718 wm8995
->aifclk
[aif
] = rate
;
720 snd_soc_update_bits(codec
, WM8995_AIF1_CLOCKING_1
+ offset
,
721 WM8995_AIF1CLK_SRC_MASK
| WM8995_AIF1CLK_DIV_MASK
,
726 static int configure_clock(struct snd_soc_codec
*codec
)
728 struct wm8995_priv
*wm8995
;
731 wm8995
= snd_soc_codec_get_drvdata(codec
);
733 /* Bring up the AIF clocks first */
734 configure_aif_clock(codec
, 0);
735 configure_aif_clock(codec
, 1);
738 * Then switch CLK_SYS over to the higher of them; a change
739 * can only happen as a result of a clocking change which can
740 * only be made outside of DAPM so we can safely redo the
744 /* If they're equal it doesn't matter which is used */
745 if (wm8995
->aifclk
[0] == wm8995
->aifclk
[1])
748 if (wm8995
->aifclk
[0] < wm8995
->aifclk
[1])
749 new = WM8995_SYSCLK_SRC
;
753 change
= snd_soc_update_bits(codec
, WM8995_CLOCKING_1
,
754 WM8995_SYSCLK_SRC_MASK
, new);
758 snd_soc_dapm_sync(&codec
->dapm
);
763 static int clk_sys_event(struct snd_soc_dapm_widget
*w
,
764 struct snd_kcontrol
*kcontrol
, int event
)
766 struct snd_soc_codec
*codec
;
771 case SND_SOC_DAPM_PRE_PMU
:
772 return configure_clock(codec
);
774 case SND_SOC_DAPM_POST_PMD
:
775 configure_clock(codec
);
782 static const char *sidetone_text
[] = {
783 "ADC/DMIC1", "DMIC2",
786 static const struct soc_enum sidetone1_enum
=
787 SOC_ENUM_SINGLE(WM8995_SIDETONE
, 0, 2, sidetone_text
);
789 static const struct snd_kcontrol_new sidetone1_mux
=
790 SOC_DAPM_ENUM("Left Sidetone Mux", sidetone1_enum
);
792 static const struct soc_enum sidetone2_enum
=
793 SOC_ENUM_SINGLE(WM8995_SIDETONE
, 1, 2, sidetone_text
);
795 static const struct snd_kcontrol_new sidetone2_mux
=
796 SOC_DAPM_ENUM("Right Sidetone Mux", sidetone2_enum
);
798 static const struct snd_kcontrol_new aif1adc1l_mix
[] = {
799 SOC_DAPM_SINGLE("ADC/DMIC Switch", WM8995_AIF1_ADC1_LEFT_MIXER_ROUTING
,
801 SOC_DAPM_SINGLE("AIF2 Switch", WM8995_AIF1_ADC1_LEFT_MIXER_ROUTING
,
805 static const struct snd_kcontrol_new aif1adc1r_mix
[] = {
806 SOC_DAPM_SINGLE("ADC/DMIC Switch", WM8995_AIF1_ADC1_RIGHT_MIXER_ROUTING
,
808 SOC_DAPM_SINGLE("AIF2 Switch", WM8995_AIF1_ADC1_RIGHT_MIXER_ROUTING
,
812 static const struct snd_kcontrol_new aif1adc2l_mix
[] = {
813 SOC_DAPM_SINGLE("DMIC Switch", WM8995_AIF1_ADC2_LEFT_MIXER_ROUTING
,
815 SOC_DAPM_SINGLE("AIF2 Switch", WM8995_AIF1_ADC2_LEFT_MIXER_ROUTING
,
819 static const struct snd_kcontrol_new aif1adc2r_mix
[] = {
820 SOC_DAPM_SINGLE("DMIC Switch", WM8995_AIF1_ADC2_RIGHT_MIXER_ROUTING
,
822 SOC_DAPM_SINGLE("AIF2 Switch", WM8995_AIF1_ADC2_RIGHT_MIXER_ROUTING
,
826 static const struct snd_kcontrol_new dac1l_mix
[] = {
827 WM8995_CLASS_W_SWITCH("Right Sidetone Switch", WM8995_DAC1_LEFT_MIXER_ROUTING
,
829 WM8995_CLASS_W_SWITCH("Left Sidetone Switch", WM8995_DAC1_LEFT_MIXER_ROUTING
,
831 WM8995_CLASS_W_SWITCH("AIF2 Switch", WM8995_DAC1_LEFT_MIXER_ROUTING
,
833 WM8995_CLASS_W_SWITCH("AIF1.2 Switch", WM8995_DAC1_LEFT_MIXER_ROUTING
,
835 WM8995_CLASS_W_SWITCH("AIF1.1 Switch", WM8995_DAC1_LEFT_MIXER_ROUTING
,
839 static const struct snd_kcontrol_new dac1r_mix
[] = {
840 WM8995_CLASS_W_SWITCH("Right Sidetone Switch", WM8995_DAC1_RIGHT_MIXER_ROUTING
,
842 WM8995_CLASS_W_SWITCH("Left Sidetone Switch", WM8995_DAC1_RIGHT_MIXER_ROUTING
,
844 WM8995_CLASS_W_SWITCH("AIF2 Switch", WM8995_DAC1_RIGHT_MIXER_ROUTING
,
846 WM8995_CLASS_W_SWITCH("AIF1.2 Switch", WM8995_DAC1_RIGHT_MIXER_ROUTING
,
848 WM8995_CLASS_W_SWITCH("AIF1.1 Switch", WM8995_DAC1_RIGHT_MIXER_ROUTING
,
852 static const struct snd_kcontrol_new aif2dac2l_mix
[] = {
853 SOC_DAPM_SINGLE("Right Sidetone Switch", WM8995_DAC2_LEFT_MIXER_ROUTING
,
855 SOC_DAPM_SINGLE("Left Sidetone Switch", WM8995_DAC2_LEFT_MIXER_ROUTING
,
857 SOC_DAPM_SINGLE("AIF2 Switch", WM8995_DAC2_LEFT_MIXER_ROUTING
,
859 SOC_DAPM_SINGLE("AIF1.2 Switch", WM8995_DAC2_LEFT_MIXER_ROUTING
,
861 SOC_DAPM_SINGLE("AIF1.1 Switch", WM8995_DAC2_LEFT_MIXER_ROUTING
,
865 static const struct snd_kcontrol_new aif2dac2r_mix
[] = {
866 SOC_DAPM_SINGLE("Right Sidetone Switch", WM8995_DAC2_RIGHT_MIXER_ROUTING
,
868 SOC_DAPM_SINGLE("Left Sidetone Switch", WM8995_DAC2_RIGHT_MIXER_ROUTING
,
870 SOC_DAPM_SINGLE("AIF2 Switch", WM8995_DAC2_RIGHT_MIXER_ROUTING
,
872 SOC_DAPM_SINGLE("AIF1.2 Switch", WM8995_DAC2_RIGHT_MIXER_ROUTING
,
874 SOC_DAPM_SINGLE("AIF1.1 Switch", WM8995_DAC2_RIGHT_MIXER_ROUTING
,
878 static const struct snd_kcontrol_new in1l_pga
=
879 SOC_DAPM_SINGLE("IN1L Switch", WM8995_POWER_MANAGEMENT_2
, 5, 1, 0);
881 static const struct snd_kcontrol_new in1r_pga
=
882 SOC_DAPM_SINGLE("IN1R Switch", WM8995_POWER_MANAGEMENT_2
, 4, 1, 0);
884 static const char *adc_mux_text
[] = {
889 static const struct soc_enum adc_enum
=
890 SOC_ENUM_SINGLE(0, 0, 2, adc_mux_text
);
892 static const struct snd_kcontrol_new adcl_mux
=
893 SOC_DAPM_ENUM_VIRT("ADCL Mux", adc_enum
);
895 static const struct snd_kcontrol_new adcr_mux
=
896 SOC_DAPM_ENUM_VIRT("ADCR Mux", adc_enum
);
898 static const char *spk_src_text
[] = {
899 "DAC1L", "DAC1R", "DAC2L", "DAC2R"
902 static const SOC_ENUM_SINGLE_DECL(spk1l_src_enum
, WM8995_LEFT_PDM_SPEAKER_1
,
904 static const SOC_ENUM_SINGLE_DECL(spk1r_src_enum
, WM8995_RIGHT_PDM_SPEAKER_1
,
906 static const SOC_ENUM_SINGLE_DECL(spk2l_src_enum
, WM8995_LEFT_PDM_SPEAKER_2
,
908 static const SOC_ENUM_SINGLE_DECL(spk2r_src_enum
, WM8995_RIGHT_PDM_SPEAKER_2
,
911 static const struct snd_kcontrol_new spk1l_mux
=
912 SOC_DAPM_ENUM("SPK1L SRC", spk1l_src_enum
);
913 static const struct snd_kcontrol_new spk1r_mux
=
914 SOC_DAPM_ENUM("SPK1R SRC", spk1r_src_enum
);
915 static const struct snd_kcontrol_new spk2l_mux
=
916 SOC_DAPM_ENUM("SPK2L SRC", spk2l_src_enum
);
917 static const struct snd_kcontrol_new spk2r_mux
=
918 SOC_DAPM_ENUM("SPK2R SRC", spk2r_src_enum
);
920 static const struct snd_soc_dapm_widget wm8995_dapm_widgets
[] = {
921 SND_SOC_DAPM_INPUT("DMIC1DAT"),
922 SND_SOC_DAPM_INPUT("DMIC2DAT"),
924 SND_SOC_DAPM_INPUT("IN1L"),
925 SND_SOC_DAPM_INPUT("IN1R"),
927 SND_SOC_DAPM_MIXER("IN1L PGA", SND_SOC_NOPM
, 0, 0,
929 SND_SOC_DAPM_MIXER("IN1R PGA", SND_SOC_NOPM
, 0, 0,
932 SND_SOC_DAPM_SUPPLY("MICBIAS1", WM8995_POWER_MANAGEMENT_1
, 8, 0,
934 SND_SOC_DAPM_SUPPLY("MICBIAS2", WM8995_POWER_MANAGEMENT_1
, 9, 0,
937 SND_SOC_DAPM_SUPPLY("AIF1CLK", WM8995_AIF1_CLOCKING_1
, 0, 0, NULL
, 0),
938 SND_SOC_DAPM_SUPPLY("AIF2CLK", WM8995_AIF2_CLOCKING_1
, 0, 0, NULL
, 0),
939 SND_SOC_DAPM_SUPPLY("DSP1CLK", WM8995_CLOCKING_1
, 3, 0, NULL
, 0),
940 SND_SOC_DAPM_SUPPLY("DSP2CLK", WM8995_CLOCKING_1
, 2, 0, NULL
, 0),
941 SND_SOC_DAPM_SUPPLY("SYSDSPCLK", WM8995_CLOCKING_1
, 1, 0, NULL
, 0),
942 SND_SOC_DAPM_SUPPLY("CLK_SYS", SND_SOC_NOPM
, 0, 0, clk_sys_event
,
943 SND_SOC_DAPM_POST_PMU
| SND_SOC_DAPM_PRE_PMD
),
945 SND_SOC_DAPM_AIF_OUT("AIF1ADC1L", "AIF1 Capture", 0,
946 WM8995_POWER_MANAGEMENT_3
, 9, 0),
947 SND_SOC_DAPM_AIF_OUT("AIF1ADC1R", "AIF1 Capture", 0,
948 WM8995_POWER_MANAGEMENT_3
, 8, 0),
949 SND_SOC_DAPM_AIF_OUT("AIF1ADCDAT", "AIF1 Capture", 0,
951 SND_SOC_DAPM_AIF_OUT("AIF1ADC2L", "AIF1 Capture",
952 0, WM8995_POWER_MANAGEMENT_3
, 11, 0),
953 SND_SOC_DAPM_AIF_OUT("AIF1ADC2R", "AIF1 Capture",
954 0, WM8995_POWER_MANAGEMENT_3
, 10, 0),
956 SND_SOC_DAPM_VIRT_MUX("ADCL Mux", SND_SOC_NOPM
, 1, 0,
958 SND_SOC_DAPM_VIRT_MUX("ADCR Mux", SND_SOC_NOPM
, 0, 0,
961 SND_SOC_DAPM_ADC("DMIC2L", NULL
, WM8995_POWER_MANAGEMENT_3
, 5, 0),
962 SND_SOC_DAPM_ADC("DMIC2R", NULL
, WM8995_POWER_MANAGEMENT_3
, 4, 0),
963 SND_SOC_DAPM_ADC("DMIC1L", NULL
, WM8995_POWER_MANAGEMENT_3
, 3, 0),
964 SND_SOC_DAPM_ADC("DMIC1R", NULL
, WM8995_POWER_MANAGEMENT_3
, 2, 0),
966 SND_SOC_DAPM_ADC("ADCL", NULL
, WM8995_POWER_MANAGEMENT_3
, 1, 0),
967 SND_SOC_DAPM_ADC("ADCR", NULL
, WM8995_POWER_MANAGEMENT_3
, 0, 0),
969 SND_SOC_DAPM_MIXER("AIF1ADC1L Mixer", SND_SOC_NOPM
, 0, 0,
970 aif1adc1l_mix
, ARRAY_SIZE(aif1adc1l_mix
)),
971 SND_SOC_DAPM_MIXER("AIF1ADC1R Mixer", SND_SOC_NOPM
, 0, 0,
972 aif1adc1r_mix
, ARRAY_SIZE(aif1adc1r_mix
)),
973 SND_SOC_DAPM_MIXER("AIF1ADC2L Mixer", SND_SOC_NOPM
, 0, 0,
974 aif1adc2l_mix
, ARRAY_SIZE(aif1adc2l_mix
)),
975 SND_SOC_DAPM_MIXER("AIF1ADC2R Mixer", SND_SOC_NOPM
, 0, 0,
976 aif1adc2r_mix
, ARRAY_SIZE(aif1adc2r_mix
)),
978 SND_SOC_DAPM_AIF_IN("AIF1DAC1L", NULL
, 0, WM8995_POWER_MANAGEMENT_4
,
980 SND_SOC_DAPM_AIF_IN("AIF1DAC1R", NULL
, 0, WM8995_POWER_MANAGEMENT_4
,
982 SND_SOC_DAPM_AIF_IN("AIF1DACDAT", "AIF1 Playback", 0, SND_SOC_NOPM
,
985 SND_SOC_DAPM_AIF_IN("AIF1DAC2L", NULL
, 0, WM8995_POWER_MANAGEMENT_4
,
987 SND_SOC_DAPM_AIF_IN("AIF1DAC2R", NULL
, 0, WM8995_POWER_MANAGEMENT_4
,
990 SND_SOC_DAPM_MIXER("AIF2DAC2L Mixer", SND_SOC_NOPM
, 0, 0,
991 aif2dac2l_mix
, ARRAY_SIZE(aif2dac2l_mix
)),
992 SND_SOC_DAPM_MIXER("AIF2DAC2R Mixer", SND_SOC_NOPM
, 0, 0,
993 aif2dac2r_mix
, ARRAY_SIZE(aif2dac2r_mix
)),
995 SND_SOC_DAPM_DAC("DAC2L", NULL
, WM8995_POWER_MANAGEMENT_4
, 3, 0),
996 SND_SOC_DAPM_DAC("DAC2R", NULL
, WM8995_POWER_MANAGEMENT_4
, 2, 0),
997 SND_SOC_DAPM_DAC("DAC1L", NULL
, WM8995_POWER_MANAGEMENT_4
, 1, 0),
998 SND_SOC_DAPM_DAC("DAC1R", NULL
, WM8995_POWER_MANAGEMENT_4
, 0, 0),
1000 SND_SOC_DAPM_MIXER("DAC1L Mixer", SND_SOC_NOPM
, 0, 0, dac1l_mix
,
1001 ARRAY_SIZE(dac1l_mix
)),
1002 SND_SOC_DAPM_MIXER("DAC1R Mixer", SND_SOC_NOPM
, 0, 0, dac1r_mix
,
1003 ARRAY_SIZE(dac1r_mix
)),
1005 SND_SOC_DAPM_MUX("Left Sidetone", SND_SOC_NOPM
, 0, 0, &sidetone1_mux
),
1006 SND_SOC_DAPM_MUX("Right Sidetone", SND_SOC_NOPM
, 0, 0, &sidetone2_mux
),
1008 SND_SOC_DAPM_PGA_E("Headphone PGA", SND_SOC_NOPM
, 0, 0, NULL
, 0,
1009 hp_event
, SND_SOC_DAPM_POST_PMU
| SND_SOC_DAPM_PRE_PMD
),
1011 SND_SOC_DAPM_SUPPLY("Headphone Supply", SND_SOC_NOPM
, 0, 0,
1012 hp_supply_event
, SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_PRE_PMD
),
1014 SND_SOC_DAPM_MUX("SPK1L Driver", WM8995_LEFT_PDM_SPEAKER_1
,
1016 SND_SOC_DAPM_MUX("SPK1R Driver", WM8995_RIGHT_PDM_SPEAKER_1
,
1018 SND_SOC_DAPM_MUX("SPK2L Driver", WM8995_LEFT_PDM_SPEAKER_2
,
1020 SND_SOC_DAPM_MUX("SPK2R Driver", WM8995_RIGHT_PDM_SPEAKER_2
,
1023 SND_SOC_DAPM_SUPPLY("LDO2", WM8995_POWER_MANAGEMENT_2
, 1, 0, NULL
, 0),
1025 SND_SOC_DAPM_OUTPUT("HP1L"),
1026 SND_SOC_DAPM_OUTPUT("HP1R"),
1027 SND_SOC_DAPM_OUTPUT("SPK1L"),
1028 SND_SOC_DAPM_OUTPUT("SPK1R"),
1029 SND_SOC_DAPM_OUTPUT("SPK2L"),
1030 SND_SOC_DAPM_OUTPUT("SPK2R")
1033 static const struct snd_soc_dapm_route wm8995_intercon
[] = {
1034 { "CLK_SYS", NULL
, "AIF1CLK", check_clk_sys
},
1035 { "CLK_SYS", NULL
, "AIF2CLK", check_clk_sys
},
1037 { "DSP1CLK", NULL
, "CLK_SYS" },
1038 { "DSP2CLK", NULL
, "CLK_SYS" },
1039 { "SYSDSPCLK", NULL
, "CLK_SYS" },
1041 { "AIF1ADC1L", NULL
, "AIF1CLK" },
1042 { "AIF1ADC1L", NULL
, "DSP1CLK" },
1043 { "AIF1ADC1R", NULL
, "AIF1CLK" },
1044 { "AIF1ADC1R", NULL
, "DSP1CLK" },
1045 { "AIF1ADC1R", NULL
, "SYSDSPCLK" },
1047 { "AIF1ADC2L", NULL
, "AIF1CLK" },
1048 { "AIF1ADC2L", NULL
, "DSP1CLK" },
1049 { "AIF1ADC2R", NULL
, "AIF1CLK" },
1050 { "AIF1ADC2R", NULL
, "DSP1CLK" },
1051 { "AIF1ADC2R", NULL
, "SYSDSPCLK" },
1053 { "DMIC1L", NULL
, "DMIC1DAT" },
1054 { "DMIC1L", NULL
, "CLK_SYS" },
1055 { "DMIC1R", NULL
, "DMIC1DAT" },
1056 { "DMIC1R", NULL
, "CLK_SYS" },
1057 { "DMIC2L", NULL
, "DMIC2DAT" },
1058 { "DMIC2L", NULL
, "CLK_SYS" },
1059 { "DMIC2R", NULL
, "DMIC2DAT" },
1060 { "DMIC2R", NULL
, "CLK_SYS" },
1062 { "ADCL", NULL
, "AIF1CLK" },
1063 { "ADCL", NULL
, "DSP1CLK" },
1064 { "ADCL", NULL
, "SYSDSPCLK" },
1066 { "ADCR", NULL
, "AIF1CLK" },
1067 { "ADCR", NULL
, "DSP1CLK" },
1068 { "ADCR", NULL
, "SYSDSPCLK" },
1070 { "IN1L PGA", "IN1L Switch", "IN1L" },
1071 { "IN1R PGA", "IN1R Switch", "IN1R" },
1072 { "IN1L PGA", NULL
, "LDO2" },
1073 { "IN1R PGA", NULL
, "LDO2" },
1075 { "ADCL", NULL
, "IN1L PGA" },
1076 { "ADCR", NULL
, "IN1R PGA" },
1078 { "ADCL Mux", "ADC", "ADCL" },
1079 { "ADCL Mux", "DMIC", "DMIC1L" },
1080 { "ADCR Mux", "ADC", "ADCR" },
1081 { "ADCR Mux", "DMIC", "DMIC1R" },
1084 { "AIF1ADC1L", NULL
, "AIF1ADC1L Mixer" },
1085 { "AIF1ADC1L Mixer", "ADC/DMIC Switch", "ADCL Mux" },
1087 { "AIF1ADC1R", NULL
, "AIF1ADC1R Mixer" },
1088 { "AIF1ADC1R Mixer", "ADC/DMIC Switch", "ADCR Mux" },
1090 { "AIF1ADC2L", NULL
, "AIF1ADC2L Mixer" },
1091 { "AIF1ADC2L Mixer", "DMIC Switch", "DMIC2L" },
1093 { "AIF1ADC2R", NULL
, "AIF1ADC2R Mixer" },
1094 { "AIF1ADC2R Mixer", "DMIC Switch", "DMIC2R" },
1097 { "Left Sidetone", "ADC/DMIC1", "AIF1ADC1L" },
1098 { "Left Sidetone", "DMIC2", "AIF1ADC2L" },
1099 { "Right Sidetone", "ADC/DMIC1", "AIF1ADC1R" },
1100 { "Right Sidetone", "DMIC2", "AIF1ADC2R" },
1102 { "AIF1DAC1L", NULL
, "AIF1CLK" },
1103 { "AIF1DAC1L", NULL
, "DSP1CLK" },
1104 { "AIF1DAC1R", NULL
, "AIF1CLK" },
1105 { "AIF1DAC1R", NULL
, "DSP1CLK" },
1106 { "AIF1DAC1R", NULL
, "SYSDSPCLK" },
1108 { "AIF1DAC2L", NULL
, "AIF1CLK" },
1109 { "AIF1DAC2L", NULL
, "DSP1CLK" },
1110 { "AIF1DAC2R", NULL
, "AIF1CLK" },
1111 { "AIF1DAC2R", NULL
, "DSP1CLK" },
1112 { "AIF1DAC2R", NULL
, "SYSDSPCLK" },
1114 { "DAC1L", NULL
, "AIF1CLK" },
1115 { "DAC1L", NULL
, "DSP1CLK" },
1116 { "DAC1L", NULL
, "SYSDSPCLK" },
1118 { "DAC1R", NULL
, "AIF1CLK" },
1119 { "DAC1R", NULL
, "DSP1CLK" },
1120 { "DAC1R", NULL
, "SYSDSPCLK" },
1122 { "AIF1DAC1L", NULL
, "AIF1DACDAT" },
1123 { "AIF1DAC1R", NULL
, "AIF1DACDAT" },
1124 { "AIF1DAC2L", NULL
, "AIF1DACDAT" },
1125 { "AIF1DAC2R", NULL
, "AIF1DACDAT" },
1128 { "DAC1L", NULL
, "DAC1L Mixer" },
1129 { "DAC1L Mixer", "AIF1.1 Switch", "AIF1DAC1L" },
1130 { "DAC1L Mixer", "AIF1.2 Switch", "AIF1DAC2L" },
1131 { "DAC1L Mixer", "Left Sidetone Switch", "Left Sidetone" },
1132 { "DAC1L Mixer", "Right Sidetone Switch", "Right Sidetone" },
1134 { "DAC1R", NULL
, "DAC1R Mixer" },
1135 { "DAC1R Mixer", "AIF1.1 Switch", "AIF1DAC1R" },
1136 { "DAC1R Mixer", "AIF1.2 Switch", "AIF1DAC2R" },
1137 { "DAC1R Mixer", "Left Sidetone Switch", "Left Sidetone" },
1138 { "DAC1R Mixer", "Right Sidetone Switch", "Right Sidetone" },
1140 /* DAC2/AIF2 outputs */
1141 { "DAC2L", NULL
, "AIF2DAC2L Mixer" },
1142 { "AIF2DAC2L Mixer", "AIF1.2 Switch", "AIF1DAC2L" },
1143 { "AIF2DAC2L Mixer", "AIF1.1 Switch", "AIF1DAC1L" },
1145 { "DAC2R", NULL
, "AIF2DAC2R Mixer" },
1146 { "AIF2DAC2R Mixer", "AIF1.2 Switch", "AIF1DAC2R" },
1147 { "AIF2DAC2R Mixer", "AIF1.1 Switch", "AIF1DAC1R" },
1150 { "Headphone PGA", NULL
, "DAC1L" },
1151 { "Headphone PGA", NULL
, "DAC1R" },
1153 { "Headphone PGA", NULL
, "DAC2L" },
1154 { "Headphone PGA", NULL
, "DAC2R" },
1156 { "Headphone PGA", NULL
, "Headphone Supply" },
1157 { "Headphone PGA", NULL
, "CLK_SYS" },
1158 { "Headphone PGA", NULL
, "LDO2" },
1160 { "HP1L", NULL
, "Headphone PGA" },
1161 { "HP1R", NULL
, "Headphone PGA" },
1163 { "SPK1L Driver", "DAC1L", "DAC1L" },
1164 { "SPK1L Driver", "DAC1R", "DAC1R" },
1165 { "SPK1L Driver", "DAC2L", "DAC2L" },
1166 { "SPK1L Driver", "DAC2R", "DAC2R" },
1167 { "SPK1L Driver", NULL
, "CLK_SYS" },
1169 { "SPK1R Driver", "DAC1L", "DAC1L" },
1170 { "SPK1R Driver", "DAC1R", "DAC1R" },
1171 { "SPK1R Driver", "DAC2L", "DAC2L" },
1172 { "SPK1R Driver", "DAC2R", "DAC2R" },
1173 { "SPK1R Driver", NULL
, "CLK_SYS" },
1175 { "SPK2L Driver", "DAC1L", "DAC1L" },
1176 { "SPK2L Driver", "DAC1R", "DAC1R" },
1177 { "SPK2L Driver", "DAC2L", "DAC2L" },
1178 { "SPK2L Driver", "DAC2R", "DAC2R" },
1179 { "SPK2L Driver", NULL
, "CLK_SYS" },
1181 { "SPK2R Driver", "DAC1L", "DAC1L" },
1182 { "SPK2R Driver", "DAC1R", "DAC1R" },
1183 { "SPK2R Driver", "DAC2L", "DAC2L" },
1184 { "SPK2R Driver", "DAC2R", "DAC2R" },
1185 { "SPK2R Driver", NULL
, "CLK_SYS" },
1187 { "SPK1L", NULL
, "SPK1L Driver" },
1188 { "SPK1R", NULL
, "SPK1R Driver" },
1189 { "SPK2L", NULL
, "SPK2L Driver" },
1190 { "SPK2R", NULL
, "SPK2R Driver" }
1193 static bool wm8995_readable(struct device
*dev
, unsigned int reg
)
1196 case WM8995_SOFTWARE_RESET
:
1197 case WM8995_POWER_MANAGEMENT_1
:
1198 case WM8995_POWER_MANAGEMENT_2
:
1199 case WM8995_POWER_MANAGEMENT_3
:
1200 case WM8995_POWER_MANAGEMENT_4
:
1201 case WM8995_POWER_MANAGEMENT_5
:
1202 case WM8995_LEFT_LINE_INPUT_1_VOLUME
:
1203 case WM8995_RIGHT_LINE_INPUT_1_VOLUME
:
1204 case WM8995_LEFT_LINE_INPUT_CONTROL
:
1205 case WM8995_DAC1_LEFT_VOLUME
:
1206 case WM8995_DAC1_RIGHT_VOLUME
:
1207 case WM8995_DAC2_LEFT_VOLUME
:
1208 case WM8995_DAC2_RIGHT_VOLUME
:
1209 case WM8995_OUTPUT_VOLUME_ZC_1
:
1210 case WM8995_MICBIAS_1
:
1211 case WM8995_MICBIAS_2
:
1214 case WM8995_ACCESSORY_DETECT_MODE1
:
1215 case WM8995_ACCESSORY_DETECT_MODE2
:
1216 case WM8995_HEADPHONE_DETECT1
:
1217 case WM8995_HEADPHONE_DETECT2
:
1218 case WM8995_MIC_DETECT_1
:
1219 case WM8995_MIC_DETECT_2
:
1220 case WM8995_CHARGE_PUMP_1
:
1221 case WM8995_CLASS_W_1
:
1222 case WM8995_DC_SERVO_1
:
1223 case WM8995_DC_SERVO_2
:
1224 case WM8995_DC_SERVO_3
:
1225 case WM8995_DC_SERVO_5
:
1226 case WM8995_DC_SERVO_6
:
1227 case WM8995_DC_SERVO_7
:
1228 case WM8995_DC_SERVO_READBACK_0
:
1229 case WM8995_ANALOGUE_HP_1
:
1230 case WM8995_ANALOGUE_HP_2
:
1231 case WM8995_CHIP_REVISION
:
1232 case WM8995_CONTROL_INTERFACE_1
:
1233 case WM8995_CONTROL_INTERFACE_2
:
1234 case WM8995_WRITE_SEQUENCER_CTRL_1
:
1235 case WM8995_WRITE_SEQUENCER_CTRL_2
:
1236 case WM8995_AIF1_CLOCKING_1
:
1237 case WM8995_AIF1_CLOCKING_2
:
1238 case WM8995_AIF2_CLOCKING_1
:
1239 case WM8995_AIF2_CLOCKING_2
:
1240 case WM8995_CLOCKING_1
:
1241 case WM8995_CLOCKING_2
:
1242 case WM8995_AIF1_RATE
:
1243 case WM8995_AIF2_RATE
:
1244 case WM8995_RATE_STATUS
:
1245 case WM8995_FLL1_CONTROL_1
:
1246 case WM8995_FLL1_CONTROL_2
:
1247 case WM8995_FLL1_CONTROL_3
:
1248 case WM8995_FLL1_CONTROL_4
:
1249 case WM8995_FLL1_CONTROL_5
:
1250 case WM8995_FLL2_CONTROL_1
:
1251 case WM8995_FLL2_CONTROL_2
:
1252 case WM8995_FLL2_CONTROL_3
:
1253 case WM8995_FLL2_CONTROL_4
:
1254 case WM8995_FLL2_CONTROL_5
:
1255 case WM8995_AIF1_CONTROL_1
:
1256 case WM8995_AIF1_CONTROL_2
:
1257 case WM8995_AIF1_MASTER_SLAVE
:
1258 case WM8995_AIF1_BCLK
:
1259 case WM8995_AIF1ADC_LRCLK
:
1260 case WM8995_AIF1DAC_LRCLK
:
1261 case WM8995_AIF1DAC_DATA
:
1262 case WM8995_AIF1ADC_DATA
:
1263 case WM8995_AIF2_CONTROL_1
:
1264 case WM8995_AIF2_CONTROL_2
:
1265 case WM8995_AIF2_MASTER_SLAVE
:
1266 case WM8995_AIF2_BCLK
:
1267 case WM8995_AIF2ADC_LRCLK
:
1268 case WM8995_AIF2DAC_LRCLK
:
1269 case WM8995_AIF2DAC_DATA
:
1270 case WM8995_AIF2ADC_DATA
:
1271 case WM8995_AIF1_ADC1_LEFT_VOLUME
:
1272 case WM8995_AIF1_ADC1_RIGHT_VOLUME
:
1273 case WM8995_AIF1_DAC1_LEFT_VOLUME
:
1274 case WM8995_AIF1_DAC1_RIGHT_VOLUME
:
1275 case WM8995_AIF1_ADC2_LEFT_VOLUME
:
1276 case WM8995_AIF1_ADC2_RIGHT_VOLUME
:
1277 case WM8995_AIF1_DAC2_LEFT_VOLUME
:
1278 case WM8995_AIF1_DAC2_RIGHT_VOLUME
:
1279 case WM8995_AIF1_ADC1_FILTERS
:
1280 case WM8995_AIF1_ADC2_FILTERS
:
1281 case WM8995_AIF1_DAC1_FILTERS_1
:
1282 case WM8995_AIF1_DAC1_FILTERS_2
:
1283 case WM8995_AIF1_DAC2_FILTERS_1
:
1284 case WM8995_AIF1_DAC2_FILTERS_2
:
1285 case WM8995_AIF1_DRC1_1
:
1286 case WM8995_AIF1_DRC1_2
:
1287 case WM8995_AIF1_DRC1_3
:
1288 case WM8995_AIF1_DRC1_4
:
1289 case WM8995_AIF1_DRC1_5
:
1290 case WM8995_AIF1_DRC2_1
:
1291 case WM8995_AIF1_DRC2_2
:
1292 case WM8995_AIF1_DRC2_3
:
1293 case WM8995_AIF1_DRC2_4
:
1294 case WM8995_AIF1_DRC2_5
:
1295 case WM8995_AIF1_DAC1_EQ_GAINS_1
:
1296 case WM8995_AIF1_DAC1_EQ_GAINS_2
:
1297 case WM8995_AIF1_DAC1_EQ_BAND_1_A
:
1298 case WM8995_AIF1_DAC1_EQ_BAND_1_B
:
1299 case WM8995_AIF1_DAC1_EQ_BAND_1_PG
:
1300 case WM8995_AIF1_DAC1_EQ_BAND_2_A
:
1301 case WM8995_AIF1_DAC1_EQ_BAND_2_B
:
1302 case WM8995_AIF1_DAC1_EQ_BAND_2_C
:
1303 case WM8995_AIF1_DAC1_EQ_BAND_2_PG
:
1304 case WM8995_AIF1_DAC1_EQ_BAND_3_A
:
1305 case WM8995_AIF1_DAC1_EQ_BAND_3_B
:
1306 case WM8995_AIF1_DAC1_EQ_BAND_3_C
:
1307 case WM8995_AIF1_DAC1_EQ_BAND_3_PG
:
1308 case WM8995_AIF1_DAC1_EQ_BAND_4_A
:
1309 case WM8995_AIF1_DAC1_EQ_BAND_4_B
:
1310 case WM8995_AIF1_DAC1_EQ_BAND_4_C
:
1311 case WM8995_AIF1_DAC1_EQ_BAND_4_PG
:
1312 case WM8995_AIF1_DAC1_EQ_BAND_5_A
:
1313 case WM8995_AIF1_DAC1_EQ_BAND_5_B
:
1314 case WM8995_AIF1_DAC1_EQ_BAND_5_PG
:
1315 case WM8995_AIF1_DAC2_EQ_GAINS_1
:
1316 case WM8995_AIF1_DAC2_EQ_GAINS_2
:
1317 case WM8995_AIF1_DAC2_EQ_BAND_1_A
:
1318 case WM8995_AIF1_DAC2_EQ_BAND_1_B
:
1319 case WM8995_AIF1_DAC2_EQ_BAND_1_PG
:
1320 case WM8995_AIF1_DAC2_EQ_BAND_2_A
:
1321 case WM8995_AIF1_DAC2_EQ_BAND_2_B
:
1322 case WM8995_AIF1_DAC2_EQ_BAND_2_C
:
1323 case WM8995_AIF1_DAC2_EQ_BAND_2_PG
:
1324 case WM8995_AIF1_DAC2_EQ_BAND_3_A
:
1325 case WM8995_AIF1_DAC2_EQ_BAND_3_B
:
1326 case WM8995_AIF1_DAC2_EQ_BAND_3_C
:
1327 case WM8995_AIF1_DAC2_EQ_BAND_3_PG
:
1328 case WM8995_AIF1_DAC2_EQ_BAND_4_A
:
1329 case WM8995_AIF1_DAC2_EQ_BAND_4_B
:
1330 case WM8995_AIF1_DAC2_EQ_BAND_4_C
:
1331 case WM8995_AIF1_DAC2_EQ_BAND_4_PG
:
1332 case WM8995_AIF1_DAC2_EQ_BAND_5_A
:
1333 case WM8995_AIF1_DAC2_EQ_BAND_5_B
:
1334 case WM8995_AIF1_DAC2_EQ_BAND_5_PG
:
1335 case WM8995_AIF2_ADC_LEFT_VOLUME
:
1336 case WM8995_AIF2_ADC_RIGHT_VOLUME
:
1337 case WM8995_AIF2_DAC_LEFT_VOLUME
:
1338 case WM8995_AIF2_DAC_RIGHT_VOLUME
:
1339 case WM8995_AIF2_ADC_FILTERS
:
1340 case WM8995_AIF2_DAC_FILTERS_1
:
1341 case WM8995_AIF2_DAC_FILTERS_2
:
1342 case WM8995_AIF2_DRC_1
:
1343 case WM8995_AIF2_DRC_2
:
1344 case WM8995_AIF2_DRC_3
:
1345 case WM8995_AIF2_DRC_4
:
1346 case WM8995_AIF2_DRC_5
:
1347 case WM8995_AIF2_EQ_GAINS_1
:
1348 case WM8995_AIF2_EQ_GAINS_2
:
1349 case WM8995_AIF2_EQ_BAND_1_A
:
1350 case WM8995_AIF2_EQ_BAND_1_B
:
1351 case WM8995_AIF2_EQ_BAND_1_PG
:
1352 case WM8995_AIF2_EQ_BAND_2_A
:
1353 case WM8995_AIF2_EQ_BAND_2_B
:
1354 case WM8995_AIF2_EQ_BAND_2_C
:
1355 case WM8995_AIF2_EQ_BAND_2_PG
:
1356 case WM8995_AIF2_EQ_BAND_3_A
:
1357 case WM8995_AIF2_EQ_BAND_3_B
:
1358 case WM8995_AIF2_EQ_BAND_3_C
:
1359 case WM8995_AIF2_EQ_BAND_3_PG
:
1360 case WM8995_AIF2_EQ_BAND_4_A
:
1361 case WM8995_AIF2_EQ_BAND_4_B
:
1362 case WM8995_AIF2_EQ_BAND_4_C
:
1363 case WM8995_AIF2_EQ_BAND_4_PG
:
1364 case WM8995_AIF2_EQ_BAND_5_A
:
1365 case WM8995_AIF2_EQ_BAND_5_B
:
1366 case WM8995_AIF2_EQ_BAND_5_PG
:
1367 case WM8995_DAC1_MIXER_VOLUMES
:
1368 case WM8995_DAC1_LEFT_MIXER_ROUTING
:
1369 case WM8995_DAC1_RIGHT_MIXER_ROUTING
:
1370 case WM8995_DAC2_MIXER_VOLUMES
:
1371 case WM8995_DAC2_LEFT_MIXER_ROUTING
:
1372 case WM8995_DAC2_RIGHT_MIXER_ROUTING
:
1373 case WM8995_AIF1_ADC1_LEFT_MIXER_ROUTING
:
1374 case WM8995_AIF1_ADC1_RIGHT_MIXER_ROUTING
:
1375 case WM8995_AIF1_ADC2_LEFT_MIXER_ROUTING
:
1376 case WM8995_AIF1_ADC2_RIGHT_MIXER_ROUTING
:
1377 case WM8995_DAC_SOFTMUTE
:
1378 case WM8995_OVERSAMPLING
:
1379 case WM8995_SIDETONE
:
1389 case WM8995_GPIO_10
:
1390 case WM8995_GPIO_11
:
1391 case WM8995_GPIO_12
:
1392 case WM8995_GPIO_13
:
1393 case WM8995_GPIO_14
:
1394 case WM8995_PULL_CONTROL_1
:
1395 case WM8995_PULL_CONTROL_2
:
1396 case WM8995_INTERRUPT_STATUS_1
:
1397 case WM8995_INTERRUPT_STATUS_2
:
1398 case WM8995_INTERRUPT_RAW_STATUS_2
:
1399 case WM8995_INTERRUPT_STATUS_1_MASK
:
1400 case WM8995_INTERRUPT_STATUS_2_MASK
:
1401 case WM8995_INTERRUPT_CONTROL
:
1402 case WM8995_LEFT_PDM_SPEAKER_1
:
1403 case WM8995_RIGHT_PDM_SPEAKER_1
:
1404 case WM8995_PDM_SPEAKER_1_MUTE_SEQUENCE
:
1405 case WM8995_LEFT_PDM_SPEAKER_2
:
1406 case WM8995_RIGHT_PDM_SPEAKER_2
:
1407 case WM8995_PDM_SPEAKER_2_MUTE_SEQUENCE
:
1414 static bool wm8995_volatile(struct device
*dev
, unsigned int reg
)
1417 case WM8995_SOFTWARE_RESET
:
1418 case WM8995_DC_SERVO_READBACK_0
:
1419 case WM8995_INTERRUPT_STATUS_1
:
1420 case WM8995_INTERRUPT_STATUS_2
:
1421 case WM8995_INTERRUPT_CONTROL
:
1422 case WM8995_ACCESSORY_DETECT_MODE1
:
1423 case WM8995_ACCESSORY_DETECT_MODE2
:
1424 case WM8995_HEADPHONE_DETECT1
:
1425 case WM8995_HEADPHONE_DETECT2
:
1426 case WM8995_RATE_STATUS
:
1433 static int wm8995_aif_mute(struct snd_soc_dai
*dai
, int mute
)
1435 struct snd_soc_codec
*codec
= dai
->codec
;
1440 mute_reg
= WM8995_AIF1_DAC1_FILTERS_1
;
1443 mute_reg
= WM8995_AIF2_DAC_FILTERS_1
;
1449 snd_soc_update_bits(codec
, mute_reg
, WM8995_AIF1DAC1_MUTE_MASK
,
1450 !!mute
<< WM8995_AIF1DAC1_MUTE_SHIFT
);
1454 static int wm8995_set_dai_fmt(struct snd_soc_dai
*dai
, unsigned int fmt
)
1456 struct snd_soc_codec
*codec
;
1463 switch (fmt
& SND_SOC_DAIFMT_MASTER_MASK
) {
1464 case SND_SOC_DAIFMT_CBS_CFS
:
1466 case SND_SOC_DAIFMT_CBM_CFM
:
1467 master
= WM8995_AIF1_MSTR
;
1470 dev_err(dai
->dev
, "Unknown master/slave configuration\n");
1475 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
1476 case SND_SOC_DAIFMT_DSP_B
:
1477 aif
|= WM8995_AIF1_LRCLK_INV
;
1478 case SND_SOC_DAIFMT_DSP_A
:
1479 aif
|= (0x3 << WM8995_AIF1_FMT_SHIFT
);
1481 case SND_SOC_DAIFMT_I2S
:
1482 aif
|= (0x2 << WM8995_AIF1_FMT_SHIFT
);
1484 case SND_SOC_DAIFMT_RIGHT_J
:
1486 case SND_SOC_DAIFMT_LEFT_J
:
1487 aif
|= (0x1 << WM8995_AIF1_FMT_SHIFT
);
1490 dev_err(dai
->dev
, "Unknown dai format\n");
1494 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
1495 case SND_SOC_DAIFMT_DSP_A
:
1496 case SND_SOC_DAIFMT_DSP_B
:
1497 /* frame inversion not valid for DSP modes */
1498 switch (fmt
& SND_SOC_DAIFMT_INV_MASK
) {
1499 case SND_SOC_DAIFMT_NB_NF
:
1501 case SND_SOC_DAIFMT_IB_NF
:
1502 aif
|= WM8995_AIF1_BCLK_INV
;
1509 case SND_SOC_DAIFMT_I2S
:
1510 case SND_SOC_DAIFMT_RIGHT_J
:
1511 case SND_SOC_DAIFMT_LEFT_J
:
1512 switch (fmt
& SND_SOC_DAIFMT_INV_MASK
) {
1513 case SND_SOC_DAIFMT_NB_NF
:
1515 case SND_SOC_DAIFMT_IB_IF
:
1516 aif
|= WM8995_AIF1_BCLK_INV
| WM8995_AIF1_LRCLK_INV
;
1518 case SND_SOC_DAIFMT_IB_NF
:
1519 aif
|= WM8995_AIF1_BCLK_INV
;
1521 case SND_SOC_DAIFMT_NB_IF
:
1522 aif
|= WM8995_AIF1_LRCLK_INV
;
1532 snd_soc_update_bits(codec
, WM8995_AIF1_CONTROL_1
,
1533 WM8995_AIF1_BCLK_INV_MASK
|
1534 WM8995_AIF1_LRCLK_INV_MASK
|
1535 WM8995_AIF1_FMT_MASK
, aif
);
1536 snd_soc_update_bits(codec
, WM8995_AIF1_MASTER_SLAVE
,
1537 WM8995_AIF1_MSTR_MASK
, master
);
1541 static const int srs
[] = {
1542 8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100,
1546 static const int fs_ratios
[] = {
1548 128, 192, 256, 384, 512, 768, 1024, 1408, 1536
1551 static const int bclk_divs
[] = {
1552 10, 15, 20, 30, 40, 55, 60, 80, 110, 120, 160, 220, 240, 320, 440, 480
1555 static int wm8995_hw_params(struct snd_pcm_substream
*substream
,
1556 struct snd_pcm_hw_params
*params
,
1557 struct snd_soc_dai
*dai
)
1559 struct snd_soc_codec
*codec
;
1560 struct wm8995_priv
*wm8995
;
1568 int i
, rate_val
, best
, best_val
, cur_val
;
1571 wm8995
= snd_soc_codec_get_drvdata(codec
);
1575 aif1_reg
= WM8995_AIF1_CONTROL_1
;
1576 bclk_reg
= WM8995_AIF1_BCLK
;
1577 rate_reg
= WM8995_AIF1_RATE
;
1578 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
/* ||
1579 wm8995->lrclk_shared[0] */) {
1580 lrclk_reg
= WM8995_AIF1DAC_LRCLK
;
1582 lrclk_reg
= WM8995_AIF1ADC_LRCLK
;
1583 dev_dbg(codec
->dev
, "AIF1 using split LRCLK\n");
1587 aif1_reg
= WM8995_AIF2_CONTROL_1
;
1588 bclk_reg
= WM8995_AIF2_BCLK
;
1589 rate_reg
= WM8995_AIF2_RATE
;
1590 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
/* ||
1591 wm8995->lrclk_shared[1] */) {
1592 lrclk_reg
= WM8995_AIF2DAC_LRCLK
;
1594 lrclk_reg
= WM8995_AIF2ADC_LRCLK
;
1595 dev_dbg(codec
->dev
, "AIF2 using split LRCLK\n");
1602 bclk_rate
= snd_soc_params_to_bclk(params
);
1607 switch (params_format(params
)) {
1608 case SNDRV_PCM_FORMAT_S16_LE
:
1610 case SNDRV_PCM_FORMAT_S20_3LE
:
1611 aif1
|= (0x1 << WM8995_AIF1_WL_SHIFT
);
1613 case SNDRV_PCM_FORMAT_S24_LE
:
1614 aif1
|= (0x2 << WM8995_AIF1_WL_SHIFT
);
1616 case SNDRV_PCM_FORMAT_S32_LE
:
1617 aif1
|= (0x3 << WM8995_AIF1_WL_SHIFT
);
1620 dev_err(dai
->dev
, "Unsupported word length %u\n",
1621 params_format(params
));
1625 /* try to find a suitable sample rate */
1626 for (i
= 0; i
< ARRAY_SIZE(srs
); ++i
)
1627 if (srs
[i
] == params_rate(params
))
1629 if (i
== ARRAY_SIZE(srs
)) {
1630 dev_err(dai
->dev
, "Sample rate %d is not supported\n",
1631 params_rate(params
));
1634 rate_val
= i
<< WM8995_AIF1_SR_SHIFT
;
1636 dev_dbg(dai
->dev
, "Sample rate is %dHz\n", srs
[i
]);
1637 dev_dbg(dai
->dev
, "AIF%dCLK is %dHz, target BCLK %dHz\n",
1638 dai
->id
+ 1, wm8995
->aifclk
[dai
->id
], bclk_rate
);
1640 /* AIFCLK/fs ratio; look for a close match in either direction */
1642 best_val
= abs((fs_ratios
[1] * params_rate(params
))
1643 - wm8995
->aifclk
[dai
->id
]);
1644 for (i
= 2; i
< ARRAY_SIZE(fs_ratios
); i
++) {
1645 cur_val
= abs((fs_ratios
[i
] * params_rate(params
))
1646 - wm8995
->aifclk
[dai
->id
]);
1647 if (cur_val
>= best_val
)
1654 dev_dbg(dai
->dev
, "Selected AIF%dCLK/fs = %d\n",
1655 dai
->id
+ 1, fs_ratios
[best
]);
1658 * We may not get quite the right frequency if using
1659 * approximate clocks so look for the closest match that is
1660 * higher than the target (we need to ensure that there enough
1661 * BCLKs to clock out the samples).
1665 for (i
= 0; i
< ARRAY_SIZE(bclk_divs
); i
++) {
1666 cur_val
= (wm8995
->aifclk
[dai
->id
] * 10 / bclk_divs
[i
]) - bclk_rate
;
1667 if (cur_val
< 0) /* BCLK table is sorted */
1671 bclk
|= best
<< WM8995_AIF1_BCLK_DIV_SHIFT
;
1673 bclk_rate
= wm8995
->aifclk
[dai
->id
] * 10 / bclk_divs
[best
];
1674 dev_dbg(dai
->dev
, "Using BCLK_DIV %d for actual BCLK %dHz\n",
1675 bclk_divs
[best
], bclk_rate
);
1677 lrclk
= bclk_rate
/ params_rate(params
);
1678 dev_dbg(dai
->dev
, "Using LRCLK rate %d for actual LRCLK %dHz\n",
1679 lrclk
, bclk_rate
/ lrclk
);
1681 snd_soc_update_bits(codec
, aif1_reg
,
1682 WM8995_AIF1_WL_MASK
, aif1
);
1683 snd_soc_update_bits(codec
, bclk_reg
,
1684 WM8995_AIF1_BCLK_DIV_MASK
, bclk
);
1685 snd_soc_update_bits(codec
, lrclk_reg
,
1686 WM8995_AIF1DAC_RATE_MASK
, lrclk
);
1687 snd_soc_update_bits(codec
, rate_reg
,
1688 WM8995_AIF1_SR_MASK
|
1689 WM8995_AIF1CLK_RATE_MASK
, rate_val
);
1693 static int wm8995_set_tristate(struct snd_soc_dai
*codec_dai
, int tristate
)
1695 struct snd_soc_codec
*codec
= codec_dai
->codec
;
1698 switch (codec_dai
->id
) {
1700 reg
= WM8995_AIF1_MASTER_SLAVE
;
1701 mask
= WM8995_AIF1_TRI
;
1704 reg
= WM8995_AIF2_MASTER_SLAVE
;
1705 mask
= WM8995_AIF2_TRI
;
1708 reg
= WM8995_POWER_MANAGEMENT_5
;
1709 mask
= WM8995_AIF3_TRI
;
1720 return snd_soc_update_bits(codec
, reg
, mask
, val
);
1723 /* The size in bits of the FLL divide multiplied by 10
1724 * to allow rounding later */
1725 #define FIXED_FLL_SIZE ((1 << 16) * 10)
1735 static int wm8995_get_fll_config(struct fll_div
*fll
,
1736 int freq_in
, int freq_out
)
1739 unsigned int K
, Ndiv
, Nmod
;
1741 pr_debug("FLL input=%dHz, output=%dHz\n", freq_in
, freq_out
);
1743 /* Scale the input frequency down to <= 13.5MHz */
1744 fll
->clk_ref_div
= 0;
1745 while (freq_in
> 13500000) {
1749 if (fll
->clk_ref_div
> 3)
1752 pr_debug("CLK_REF_DIV=%d, Fref=%dHz\n", fll
->clk_ref_div
, freq_in
);
1754 /* Scale the output to give 90MHz<=Fvco<=100MHz */
1756 while (freq_out
* (fll
->outdiv
+ 1) < 90000000) {
1758 if (fll
->outdiv
> 63)
1761 freq_out
*= fll
->outdiv
+ 1;
1762 pr_debug("OUTDIV=%d, Fvco=%dHz\n", fll
->outdiv
, freq_out
);
1764 if (freq_in
> 1000000) {
1765 fll
->fll_fratio
= 0;
1766 } else if (freq_in
> 256000) {
1767 fll
->fll_fratio
= 1;
1769 } else if (freq_in
> 128000) {
1770 fll
->fll_fratio
= 2;
1772 } else if (freq_in
> 64000) {
1773 fll
->fll_fratio
= 3;
1776 fll
->fll_fratio
= 4;
1779 pr_debug("FLL_FRATIO=%d, Fref=%dHz\n", fll
->fll_fratio
, freq_in
);
1781 /* Now, calculate N.K */
1782 Ndiv
= freq_out
/ freq_in
;
1785 Nmod
= freq_out
% freq_in
;
1786 pr_debug("Nmod=%d\n", Nmod
);
1788 /* Calculate fractional part - scale up so we can round. */
1789 Kpart
= FIXED_FLL_SIZE
* (long long)Nmod
;
1791 do_div(Kpart
, freq_in
);
1793 K
= Kpart
& 0xFFFFFFFF;
1798 /* Move down to proper range now rounding is done */
1801 pr_debug("N=%x K=%x\n", fll
->n
, fll
->k
);
1806 static int wm8995_set_fll(struct snd_soc_dai
*dai
, int id
,
1807 int src
, unsigned int freq_in
,
1808 unsigned int freq_out
)
1810 struct snd_soc_codec
*codec
;
1811 struct wm8995_priv
*wm8995
;
1812 int reg_offset
, ret
;
1814 u16 reg
, aif1
, aif2
;
1817 wm8995
= snd_soc_codec_get_drvdata(codec
);
1819 aif1
= snd_soc_read(codec
, WM8995_AIF1_CLOCKING_1
)
1820 & WM8995_AIF1CLK_ENA
;
1822 aif2
= snd_soc_read(codec
, WM8995_AIF2_CLOCKING_1
)
1823 & WM8995_AIF2CLK_ENA
;
1840 /* Allow no source specification when stopping */
1844 case WM8995_FLL_SRC_MCLK1
:
1845 case WM8995_FLL_SRC_MCLK2
:
1846 case WM8995_FLL_SRC_LRCLK
:
1847 case WM8995_FLL_SRC_BCLK
:
1853 /* Are we changing anything? */
1854 if (wm8995
->fll
[id
].src
== src
&&
1855 wm8995
->fll
[id
].in
== freq_in
&& wm8995
->fll
[id
].out
== freq_out
)
1858 /* If we're stopping the FLL redo the old config - no
1859 * registers will actually be written but we avoid GCC flow
1860 * analysis bugs spewing warnings.
1863 ret
= wm8995_get_fll_config(&fll
, freq_in
, freq_out
);
1865 ret
= wm8995_get_fll_config(&fll
, wm8995
->fll
[id
].in
,
1866 wm8995
->fll
[id
].out
);
1870 /* Gate the AIF clocks while we reclock */
1871 snd_soc_update_bits(codec
, WM8995_AIF1_CLOCKING_1
,
1872 WM8995_AIF1CLK_ENA_MASK
, 0);
1873 snd_soc_update_bits(codec
, WM8995_AIF2_CLOCKING_1
,
1874 WM8995_AIF2CLK_ENA_MASK
, 0);
1876 /* We always need to disable the FLL while reconfiguring */
1877 snd_soc_update_bits(codec
, WM8995_FLL1_CONTROL_1
+ reg_offset
,
1878 WM8995_FLL1_ENA_MASK
, 0);
1880 reg
= (fll
.outdiv
<< WM8995_FLL1_OUTDIV_SHIFT
) |
1881 (fll
.fll_fratio
<< WM8995_FLL1_FRATIO_SHIFT
);
1882 snd_soc_update_bits(codec
, WM8995_FLL1_CONTROL_2
+ reg_offset
,
1883 WM8995_FLL1_OUTDIV_MASK
|
1884 WM8995_FLL1_FRATIO_MASK
, reg
);
1886 snd_soc_write(codec
, WM8995_FLL1_CONTROL_3
+ reg_offset
, fll
.k
);
1888 snd_soc_update_bits(codec
, WM8995_FLL1_CONTROL_4
+ reg_offset
,
1890 fll
.n
<< WM8995_FLL1_N_SHIFT
);
1892 snd_soc_update_bits(codec
, WM8995_FLL1_CONTROL_5
+ reg_offset
,
1893 WM8995_FLL1_REFCLK_DIV_MASK
|
1894 WM8995_FLL1_REFCLK_SRC_MASK
,
1895 (fll
.clk_ref_div
<< WM8995_FLL1_REFCLK_DIV_SHIFT
) |
1899 snd_soc_update_bits(codec
, WM8995_FLL1_CONTROL_1
+ reg_offset
,
1900 WM8995_FLL1_ENA_MASK
, WM8995_FLL1_ENA
);
1902 wm8995
->fll
[id
].in
= freq_in
;
1903 wm8995
->fll
[id
].out
= freq_out
;
1904 wm8995
->fll
[id
].src
= src
;
1906 /* Enable any gated AIF clocks */
1907 snd_soc_update_bits(codec
, WM8995_AIF1_CLOCKING_1
,
1908 WM8995_AIF1CLK_ENA_MASK
, aif1
);
1909 snd_soc_update_bits(codec
, WM8995_AIF2_CLOCKING_1
,
1910 WM8995_AIF2CLK_ENA_MASK
, aif2
);
1912 configure_clock(codec
);
1917 static int wm8995_set_dai_sysclk(struct snd_soc_dai
*dai
,
1918 int clk_id
, unsigned int freq
, int dir
)
1920 struct snd_soc_codec
*codec
;
1921 struct wm8995_priv
*wm8995
;
1924 wm8995
= snd_soc_codec_get_drvdata(codec
);
1931 /* AIF3 shares clocking with AIF1/2 */
1936 case WM8995_SYSCLK_MCLK1
:
1937 wm8995
->sysclk
[dai
->id
] = WM8995_SYSCLK_MCLK1
;
1938 wm8995
->mclk
[0] = freq
;
1939 dev_dbg(dai
->dev
, "AIF%d using MCLK1 at %uHz\n",
1942 case WM8995_SYSCLK_MCLK2
:
1943 wm8995
->sysclk
[dai
->id
] = WM8995_SYSCLK_MCLK1
;
1944 wm8995
->mclk
[1] = freq
;
1945 dev_dbg(dai
->dev
, "AIF%d using MCLK2 at %uHz\n",
1948 case WM8995_SYSCLK_FLL1
:
1949 wm8995
->sysclk
[dai
->id
] = WM8995_SYSCLK_FLL1
;
1950 dev_dbg(dai
->dev
, "AIF%d using FLL1\n", dai
->id
+ 1);
1952 case WM8995_SYSCLK_FLL2
:
1953 wm8995
->sysclk
[dai
->id
] = WM8995_SYSCLK_FLL2
;
1954 dev_dbg(dai
->dev
, "AIF%d using FLL2\n", dai
->id
+ 1);
1956 case WM8995_SYSCLK_OPCLK
:
1958 dev_err(dai
->dev
, "Unknown clock source %d\n", clk_id
);
1962 configure_clock(codec
);
1967 static int wm8995_set_bias_level(struct snd_soc_codec
*codec
,
1968 enum snd_soc_bias_level level
)
1970 struct wm8995_priv
*wm8995
;
1973 wm8995
= snd_soc_codec_get_drvdata(codec
);
1975 case SND_SOC_BIAS_ON
:
1976 case SND_SOC_BIAS_PREPARE
:
1978 case SND_SOC_BIAS_STANDBY
:
1979 if (codec
->dapm
.bias_level
== SND_SOC_BIAS_OFF
) {
1980 ret
= regulator_bulk_enable(ARRAY_SIZE(wm8995
->supplies
),
1985 ret
= regcache_sync(wm8995
->regmap
);
1988 "Failed to sync cache: %d\n", ret
);
1992 snd_soc_update_bits(codec
, WM8995_POWER_MANAGEMENT_1
,
1993 WM8995_BG_ENA_MASK
, WM8995_BG_ENA
);
1996 case SND_SOC_BIAS_OFF
:
1997 snd_soc_update_bits(codec
, WM8995_POWER_MANAGEMENT_1
,
1998 WM8995_BG_ENA_MASK
, 0);
1999 regulator_bulk_disable(ARRAY_SIZE(wm8995
->supplies
),
2004 codec
->dapm
.bias_level
= level
;
2009 static int wm8995_suspend(struct snd_soc_codec
*codec
)
2011 wm8995_set_bias_level(codec
, SND_SOC_BIAS_OFF
);
2015 static int wm8995_resume(struct snd_soc_codec
*codec
)
2017 wm8995_set_bias_level(codec
, SND_SOC_BIAS_STANDBY
);
2021 #define wm8995_suspend NULL
2022 #define wm8995_resume NULL
2025 static int wm8995_remove(struct snd_soc_codec
*codec
)
2027 struct wm8995_priv
*wm8995
;
2030 wm8995
= snd_soc_codec_get_drvdata(codec
);
2031 wm8995_set_bias_level(codec
, SND_SOC_BIAS_OFF
);
2033 for (i
= 0; i
< ARRAY_SIZE(wm8995
->supplies
); ++i
)
2034 regulator_unregister_notifier(wm8995
->supplies
[i
].consumer
,
2035 &wm8995
->disable_nb
[i
]);
2037 regulator_bulk_free(ARRAY_SIZE(wm8995
->supplies
), wm8995
->supplies
);
2041 static int wm8995_probe(struct snd_soc_codec
*codec
)
2043 struct wm8995_priv
*wm8995
;
2047 wm8995
= snd_soc_codec_get_drvdata(codec
);
2048 wm8995
->codec
= codec
;
2050 codec
->control_data
= wm8995
->regmap
;
2051 ret
= snd_soc_codec_set_cache_io(codec
, 16, 16, SND_SOC_REGMAP
);
2053 dev_err(codec
->dev
, "Failed to set cache i/o: %d\n", ret
);
2057 for (i
= 0; i
< ARRAY_SIZE(wm8995
->supplies
); i
++)
2058 wm8995
->supplies
[i
].supply
= wm8995_supply_names
[i
];
2060 ret
= regulator_bulk_get(codec
->dev
, ARRAY_SIZE(wm8995
->supplies
),
2063 dev_err(codec
->dev
, "Failed to request supplies: %d\n", ret
);
2067 wm8995
->disable_nb
[0].notifier_call
= wm8995_regulator_event_0
;
2068 wm8995
->disable_nb
[1].notifier_call
= wm8995_regulator_event_1
;
2069 wm8995
->disable_nb
[2].notifier_call
= wm8995_regulator_event_2
;
2070 wm8995
->disable_nb
[3].notifier_call
= wm8995_regulator_event_3
;
2071 wm8995
->disable_nb
[4].notifier_call
= wm8995_regulator_event_4
;
2072 wm8995
->disable_nb
[5].notifier_call
= wm8995_regulator_event_5
;
2073 wm8995
->disable_nb
[6].notifier_call
= wm8995_regulator_event_6
;
2074 wm8995
->disable_nb
[7].notifier_call
= wm8995_regulator_event_7
;
2076 /* This should really be moved into the regulator core */
2077 for (i
= 0; i
< ARRAY_SIZE(wm8995
->supplies
); i
++) {
2078 ret
= regulator_register_notifier(wm8995
->supplies
[i
].consumer
,
2079 &wm8995
->disable_nb
[i
]);
2082 "Failed to register regulator notifier: %d\n",
2087 ret
= regulator_bulk_enable(ARRAY_SIZE(wm8995
->supplies
),
2090 dev_err(codec
->dev
, "Failed to enable supplies: %d\n", ret
);
2094 ret
= snd_soc_read(codec
, WM8995_SOFTWARE_RESET
);
2096 dev_err(codec
->dev
, "Failed to read device ID: %d\n", ret
);
2097 goto err_reg_enable
;
2100 if (ret
!= 0x8995) {
2101 dev_err(codec
->dev
, "Invalid device ID: %#x\n", ret
);
2103 goto err_reg_enable
;
2106 ret
= snd_soc_write(codec
, WM8995_SOFTWARE_RESET
, 0);
2108 dev_err(codec
->dev
, "Failed to issue reset: %d\n", ret
);
2109 goto err_reg_enable
;
2112 wm8995_set_bias_level(codec
, SND_SOC_BIAS_STANDBY
);
2114 /* Latch volume updates (right only; we always do left then right). */
2115 snd_soc_update_bits(codec
, WM8995_AIF1_DAC1_RIGHT_VOLUME
,
2116 WM8995_AIF1DAC1_VU_MASK
, WM8995_AIF1DAC1_VU
);
2117 snd_soc_update_bits(codec
, WM8995_AIF1_DAC2_RIGHT_VOLUME
,
2118 WM8995_AIF1DAC2_VU_MASK
, WM8995_AIF1DAC2_VU
);
2119 snd_soc_update_bits(codec
, WM8995_AIF2_DAC_RIGHT_VOLUME
,
2120 WM8995_AIF2DAC_VU_MASK
, WM8995_AIF2DAC_VU
);
2121 snd_soc_update_bits(codec
, WM8995_AIF1_ADC1_RIGHT_VOLUME
,
2122 WM8995_AIF1ADC1_VU_MASK
, WM8995_AIF1ADC1_VU
);
2123 snd_soc_update_bits(codec
, WM8995_AIF1_ADC2_RIGHT_VOLUME
,
2124 WM8995_AIF1ADC2_VU_MASK
, WM8995_AIF1ADC2_VU
);
2125 snd_soc_update_bits(codec
, WM8995_AIF2_ADC_RIGHT_VOLUME
,
2126 WM8995_AIF2ADC_VU_MASK
, WM8995_AIF1ADC2_VU
);
2127 snd_soc_update_bits(codec
, WM8995_DAC1_RIGHT_VOLUME
,
2128 WM8995_DAC1_VU_MASK
, WM8995_DAC1_VU
);
2129 snd_soc_update_bits(codec
, WM8995_DAC2_RIGHT_VOLUME
,
2130 WM8995_DAC2_VU_MASK
, WM8995_DAC2_VU
);
2131 snd_soc_update_bits(codec
, WM8995_RIGHT_LINE_INPUT_1_VOLUME
,
2132 WM8995_IN1_VU_MASK
, WM8995_IN1_VU
);
2134 wm8995_update_class_w(codec
);
2136 snd_soc_add_codec_controls(codec
, wm8995_snd_controls
,
2137 ARRAY_SIZE(wm8995_snd_controls
));
2138 snd_soc_dapm_new_controls(&codec
->dapm
, wm8995_dapm_widgets
,
2139 ARRAY_SIZE(wm8995_dapm_widgets
));
2140 snd_soc_dapm_add_routes(&codec
->dapm
, wm8995_intercon
,
2141 ARRAY_SIZE(wm8995_intercon
));
2146 regulator_bulk_disable(ARRAY_SIZE(wm8995
->supplies
), wm8995
->supplies
);
2148 regulator_bulk_free(ARRAY_SIZE(wm8995
->supplies
), wm8995
->supplies
);
2152 #define WM8995_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
2153 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
2155 static const struct snd_soc_dai_ops wm8995_aif1_dai_ops
= {
2156 .set_sysclk
= wm8995_set_dai_sysclk
,
2157 .set_fmt
= wm8995_set_dai_fmt
,
2158 .hw_params
= wm8995_hw_params
,
2159 .digital_mute
= wm8995_aif_mute
,
2160 .set_pll
= wm8995_set_fll
,
2161 .set_tristate
= wm8995_set_tristate
,
2164 static const struct snd_soc_dai_ops wm8995_aif2_dai_ops
= {
2165 .set_sysclk
= wm8995_set_dai_sysclk
,
2166 .set_fmt
= wm8995_set_dai_fmt
,
2167 .hw_params
= wm8995_hw_params
,
2168 .digital_mute
= wm8995_aif_mute
,
2169 .set_pll
= wm8995_set_fll
,
2170 .set_tristate
= wm8995_set_tristate
,
2173 static const struct snd_soc_dai_ops wm8995_aif3_dai_ops
= {
2174 .set_tristate
= wm8995_set_tristate
,
2177 static struct snd_soc_dai_driver wm8995_dai
[] = {
2179 .name
= "wm8995-aif1",
2181 .stream_name
= "AIF1 Playback",
2184 .rates
= SNDRV_PCM_RATE_8000_96000
,
2185 .formats
= WM8995_FORMATS
2188 .stream_name
= "AIF1 Capture",
2191 .rates
= SNDRV_PCM_RATE_8000_48000
,
2192 .formats
= WM8995_FORMATS
2194 .ops
= &wm8995_aif1_dai_ops
2197 .name
= "wm8995-aif2",
2199 .stream_name
= "AIF2 Playback",
2202 .rates
= SNDRV_PCM_RATE_8000_96000
,
2203 .formats
= WM8995_FORMATS
2206 .stream_name
= "AIF2 Capture",
2209 .rates
= SNDRV_PCM_RATE_8000_48000
,
2210 .formats
= WM8995_FORMATS
2212 .ops
= &wm8995_aif2_dai_ops
2215 .name
= "wm8995-aif3",
2217 .stream_name
= "AIF3 Playback",
2220 .rates
= SNDRV_PCM_RATE_8000_96000
,
2221 .formats
= WM8995_FORMATS
2224 .stream_name
= "AIF3 Capture",
2227 .rates
= SNDRV_PCM_RATE_8000_48000
,
2228 .formats
= WM8995_FORMATS
2230 .ops
= &wm8995_aif3_dai_ops
2234 static struct snd_soc_codec_driver soc_codec_dev_wm8995
= {
2235 .probe
= wm8995_probe
,
2236 .remove
= wm8995_remove
,
2237 .suspend
= wm8995_suspend
,
2238 .resume
= wm8995_resume
,
2239 .set_bias_level
= wm8995_set_bias_level
,
2240 .idle_bias_off
= true,
2243 static struct regmap_config wm8995_regmap
= {
2247 .max_register
= WM8995_MAX_REGISTER
,
2248 .reg_defaults
= wm8995_reg_defaults
,
2249 .num_reg_defaults
= ARRAY_SIZE(wm8995_reg_defaults
),
2250 .volatile_reg
= wm8995_volatile
,
2251 .readable_reg
= wm8995_readable
,
2252 .cache_type
= REGCACHE_RBTREE
,
2255 #if defined(CONFIG_SPI_MASTER)
2256 static int wm8995_spi_probe(struct spi_device
*spi
)
2258 struct wm8995_priv
*wm8995
;
2261 wm8995
= devm_kzalloc(&spi
->dev
, sizeof(*wm8995
), GFP_KERNEL
);
2265 spi_set_drvdata(spi
, wm8995
);
2267 wm8995
->regmap
= devm_regmap_init_spi(spi
, &wm8995_regmap
);
2268 if (IS_ERR(wm8995
->regmap
)) {
2269 ret
= PTR_ERR(wm8995
->regmap
);
2270 dev_err(&spi
->dev
, "Failed to register regmap: %d\n", ret
);
2274 ret
= snd_soc_register_codec(&spi
->dev
,
2275 &soc_codec_dev_wm8995
, wm8995_dai
,
2276 ARRAY_SIZE(wm8995_dai
));
2280 static int wm8995_spi_remove(struct spi_device
*spi
)
2282 snd_soc_unregister_codec(&spi
->dev
);
2286 static struct spi_driver wm8995_spi_driver
= {
2289 .owner
= THIS_MODULE
,
2291 .probe
= wm8995_spi_probe
,
2292 .remove
= wm8995_spi_remove
2296 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
2297 static int wm8995_i2c_probe(struct i2c_client
*i2c
,
2298 const struct i2c_device_id
*id
)
2300 struct wm8995_priv
*wm8995
;
2303 wm8995
= devm_kzalloc(&i2c
->dev
, sizeof(*wm8995
), GFP_KERNEL
);
2307 i2c_set_clientdata(i2c
, wm8995
);
2309 wm8995
->regmap
= devm_regmap_init_i2c(i2c
, &wm8995_regmap
);
2310 if (IS_ERR(wm8995
->regmap
)) {
2311 ret
= PTR_ERR(wm8995
->regmap
);
2312 dev_err(&i2c
->dev
, "Failed to register regmap: %d\n", ret
);
2316 ret
= snd_soc_register_codec(&i2c
->dev
,
2317 &soc_codec_dev_wm8995
, wm8995_dai
,
2318 ARRAY_SIZE(wm8995_dai
));
2320 dev_err(&i2c
->dev
, "Failed to register CODEC: %d\n", ret
);
2325 static int wm8995_i2c_remove(struct i2c_client
*client
)
2327 snd_soc_unregister_codec(&client
->dev
);
2331 static const struct i2c_device_id wm8995_i2c_id
[] = {
2336 MODULE_DEVICE_TABLE(i2c
, wm8995_i2c_id
);
2338 static struct i2c_driver wm8995_i2c_driver
= {
2341 .owner
= THIS_MODULE
,
2343 .probe
= wm8995_i2c_probe
,
2344 .remove
= wm8995_i2c_remove
,
2345 .id_table
= wm8995_i2c_id
2349 static int __init
wm8995_modinit(void)
2353 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
2354 ret
= i2c_add_driver(&wm8995_i2c_driver
);
2356 printk(KERN_ERR
"Failed to register wm8995 I2C driver: %d\n",
2360 #if defined(CONFIG_SPI_MASTER)
2361 ret
= spi_register_driver(&wm8995_spi_driver
);
2363 printk(KERN_ERR
"Failed to register wm8995 SPI driver: %d\n",
2370 module_init(wm8995_modinit
);
2372 static void __exit
wm8995_exit(void)
2374 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
2375 i2c_del_driver(&wm8995_i2c_driver
);
2377 #if defined(CONFIG_SPI_MASTER)
2378 spi_unregister_driver(&wm8995_spi_driver
);
2382 module_exit(wm8995_exit
);
2384 MODULE_DESCRIPTION("ASoC WM8995 driver");
2385 MODULE_AUTHOR("Dimitris Papastamos <dp@opensource.wolfsonmicro.com>");
2386 MODULE_LICENSE("GPL");