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 const 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 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 SOC_ENUM_SINGLE_DECL(in1r_enum
, WM8995_LEFT_LINE_INPUT_CONTROL
,
436 static const char *dmic_src_text
[] = {
437 "DMICDAT1", "DMICDAT2", "DMICDAT3"
440 static SOC_ENUM_SINGLE_DECL(dmic_src1_enum
, WM8995_POWER_MANAGEMENT_5
,
442 static 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
)
537 struct snd_soc_codec
*codec
= snd_soc_dapm_to_codec(source
->dapm
);
541 reg
= snd_soc_read(codec
, WM8995_CLOCKING_1
);
542 /* Check what we're currently using for CLK_SYS */
543 if (reg
& WM8995_SYSCLK_SRC
)
547 return !strcmp(source
->name
, clk
);
550 static int wm8995_put_class_w(struct snd_kcontrol
*kcontrol
,
551 struct snd_ctl_elem_value
*ucontrol
)
553 struct snd_soc_codec
*codec
= snd_soc_dapm_kcontrol_codec(kcontrol
);
556 ret
= snd_soc_dapm_put_volsw(kcontrol
, ucontrol
);
557 wm8995_update_class_w(codec
);
561 static int hp_supply_event(struct snd_soc_dapm_widget
*w
,
562 struct snd_kcontrol
*kcontrol
, int event
)
564 struct snd_soc_codec
*codec
= snd_soc_dapm_to_codec(w
->dapm
);
567 case SND_SOC_DAPM_PRE_PMU
:
568 /* Enable the headphone amp */
569 snd_soc_update_bits(codec
, WM8995_POWER_MANAGEMENT_1
,
570 WM8995_HPOUT1L_ENA_MASK
|
571 WM8995_HPOUT1R_ENA_MASK
,
575 /* Enable the second stage */
576 snd_soc_update_bits(codec
, WM8995_ANALOGUE_HP_1
,
577 WM8995_HPOUT1L_DLY_MASK
|
578 WM8995_HPOUT1R_DLY_MASK
,
582 case SND_SOC_DAPM_PRE_PMD
:
583 snd_soc_update_bits(codec
, WM8995_CHARGE_PUMP_1
,
584 WM8995_CP_ENA_MASK
, 0);
591 static void dc_servo_cmd(struct snd_soc_codec
*codec
,
592 unsigned int reg
, unsigned int val
, unsigned int mask
)
596 dev_dbg(codec
->dev
, "%s: reg = %#x, val = %#x, mask = %#x\n",
597 __func__
, reg
, val
, mask
);
599 snd_soc_write(codec
, reg
, val
);
602 val
= snd_soc_read(codec
, WM8995_DC_SERVO_READBACK_0
);
603 if ((val
& mask
) == mask
)
607 dev_err(codec
->dev
, "Timed out waiting for DC Servo\n");
610 static int hp_event(struct snd_soc_dapm_widget
*w
,
611 struct snd_kcontrol
*kcontrol
, int event
)
613 struct snd_soc_codec
*codec
= snd_soc_dapm_to_codec(w
->dapm
);
616 reg
= snd_soc_read(codec
, WM8995_ANALOGUE_HP_1
);
619 case SND_SOC_DAPM_POST_PMU
:
620 snd_soc_update_bits(codec
, WM8995_CHARGE_PUMP_1
,
621 WM8995_CP_ENA_MASK
, WM8995_CP_ENA
);
625 snd_soc_update_bits(codec
, WM8995_POWER_MANAGEMENT_1
,
626 WM8995_HPOUT1L_ENA_MASK
|
627 WM8995_HPOUT1R_ENA_MASK
,
628 WM8995_HPOUT1L_ENA
| WM8995_HPOUT1R_ENA
);
632 reg
|= WM8995_HPOUT1L_DLY
| WM8995_HPOUT1R_DLY
;
633 snd_soc_write(codec
, WM8995_ANALOGUE_HP_1
, reg
);
635 snd_soc_write(codec
, WM8995_DC_SERVO_1
, WM8995_DCS_ENA_CHAN_0
|
636 WM8995_DCS_ENA_CHAN_1
);
638 dc_servo_cmd(codec
, WM8995_DC_SERVO_2
,
639 WM8995_DCS_TRIG_STARTUP_0
|
640 WM8995_DCS_TRIG_STARTUP_1
,
641 WM8995_DCS_TRIG_DAC_WR_0
|
642 WM8995_DCS_TRIG_DAC_WR_1
);
644 reg
|= WM8995_HPOUT1R_OUTP
| WM8995_HPOUT1R_RMV_SHORT
|
645 WM8995_HPOUT1L_OUTP
| WM8995_HPOUT1L_RMV_SHORT
;
646 snd_soc_write(codec
, WM8995_ANALOGUE_HP_1
, reg
);
649 case SND_SOC_DAPM_PRE_PMD
:
650 snd_soc_update_bits(codec
, WM8995_ANALOGUE_HP_1
,
651 WM8995_HPOUT1L_OUTP_MASK
|
652 WM8995_HPOUT1R_OUTP_MASK
|
653 WM8995_HPOUT1L_RMV_SHORT_MASK
|
654 WM8995_HPOUT1R_RMV_SHORT_MASK
, 0);
656 snd_soc_update_bits(codec
, WM8995_ANALOGUE_HP_1
,
657 WM8995_HPOUT1L_DLY_MASK
|
658 WM8995_HPOUT1R_DLY_MASK
, 0);
660 snd_soc_write(codec
, WM8995_DC_SERVO_1
, 0);
662 snd_soc_update_bits(codec
, WM8995_POWER_MANAGEMENT_1
,
663 WM8995_HPOUT1L_ENA_MASK
|
664 WM8995_HPOUT1R_ENA_MASK
,
672 static int configure_aif_clock(struct snd_soc_codec
*codec
, int aif
)
674 struct wm8995_priv
*wm8995
;
679 wm8995
= snd_soc_codec_get_drvdata(codec
);
686 switch (wm8995
->sysclk
[aif
]) {
687 case WM8995_SYSCLK_MCLK1
:
688 rate
= wm8995
->mclk
[0];
690 case WM8995_SYSCLK_MCLK2
:
692 rate
= wm8995
->mclk
[1];
694 case WM8995_SYSCLK_FLL1
:
696 rate
= wm8995
->fll
[0].out
;
698 case WM8995_SYSCLK_FLL2
:
700 rate
= wm8995
->fll
[1].out
;
706 if (rate
>= 13500000) {
708 reg1
|= WM8995_AIF1CLK_DIV
;
710 dev_dbg(codec
->dev
, "Dividing AIF%d clock to %dHz\n",
714 wm8995
->aifclk
[aif
] = rate
;
716 snd_soc_update_bits(codec
, WM8995_AIF1_CLOCKING_1
+ offset
,
717 WM8995_AIF1CLK_SRC_MASK
| WM8995_AIF1CLK_DIV_MASK
,
722 static int configure_clock(struct snd_soc_codec
*codec
)
724 struct snd_soc_dapm_context
*dapm
= snd_soc_codec_get_dapm(codec
);
725 struct wm8995_priv
*wm8995
;
728 wm8995
= snd_soc_codec_get_drvdata(codec
);
730 /* Bring up the AIF clocks first */
731 configure_aif_clock(codec
, 0);
732 configure_aif_clock(codec
, 1);
735 * Then switch CLK_SYS over to the higher of them; a change
736 * can only happen as a result of a clocking change which can
737 * only be made outside of DAPM so we can safely redo the
741 /* If they're equal it doesn't matter which is used */
742 if (wm8995
->aifclk
[0] == wm8995
->aifclk
[1])
745 if (wm8995
->aifclk
[0] < wm8995
->aifclk
[1])
746 new = WM8995_SYSCLK_SRC
;
750 change
= snd_soc_update_bits(codec
, WM8995_CLOCKING_1
,
751 WM8995_SYSCLK_SRC_MASK
, new);
755 snd_soc_dapm_sync(dapm
);
760 static int clk_sys_event(struct snd_soc_dapm_widget
*w
,
761 struct snd_kcontrol
*kcontrol
, int event
)
763 struct snd_soc_codec
*codec
= snd_soc_dapm_to_codec(w
->dapm
);
766 case SND_SOC_DAPM_PRE_PMU
:
767 return configure_clock(codec
);
769 case SND_SOC_DAPM_POST_PMD
:
770 configure_clock(codec
);
777 static const char *sidetone_text
[] = {
778 "ADC/DMIC1", "DMIC2",
781 static SOC_ENUM_SINGLE_DECL(sidetone1_enum
, WM8995_SIDETONE
, 0, sidetone_text
);
783 static const struct snd_kcontrol_new sidetone1_mux
=
784 SOC_DAPM_ENUM("Left Sidetone Mux", sidetone1_enum
);
786 static SOC_ENUM_SINGLE_DECL(sidetone2_enum
, WM8995_SIDETONE
, 1, sidetone_text
);
788 static const struct snd_kcontrol_new sidetone2_mux
=
789 SOC_DAPM_ENUM("Right Sidetone Mux", sidetone2_enum
);
791 static const struct snd_kcontrol_new aif1adc1l_mix
[] = {
792 SOC_DAPM_SINGLE("ADC/DMIC Switch", WM8995_AIF1_ADC1_LEFT_MIXER_ROUTING
,
794 SOC_DAPM_SINGLE("AIF2 Switch", WM8995_AIF1_ADC1_LEFT_MIXER_ROUTING
,
798 static const struct snd_kcontrol_new aif1adc1r_mix
[] = {
799 SOC_DAPM_SINGLE("ADC/DMIC Switch", WM8995_AIF1_ADC1_RIGHT_MIXER_ROUTING
,
801 SOC_DAPM_SINGLE("AIF2 Switch", WM8995_AIF1_ADC1_RIGHT_MIXER_ROUTING
,
805 static const struct snd_kcontrol_new aif1adc2l_mix
[] = {
806 SOC_DAPM_SINGLE("DMIC Switch", WM8995_AIF1_ADC2_LEFT_MIXER_ROUTING
,
808 SOC_DAPM_SINGLE("AIF2 Switch", WM8995_AIF1_ADC2_LEFT_MIXER_ROUTING
,
812 static const struct snd_kcontrol_new aif1adc2r_mix
[] = {
813 SOC_DAPM_SINGLE("DMIC Switch", WM8995_AIF1_ADC2_RIGHT_MIXER_ROUTING
,
815 SOC_DAPM_SINGLE("AIF2 Switch", WM8995_AIF1_ADC2_RIGHT_MIXER_ROUTING
,
819 static const struct snd_kcontrol_new dac1l_mix
[] = {
820 WM8995_CLASS_W_SWITCH("Right Sidetone Switch", WM8995_DAC1_LEFT_MIXER_ROUTING
,
822 WM8995_CLASS_W_SWITCH("Left Sidetone Switch", WM8995_DAC1_LEFT_MIXER_ROUTING
,
824 WM8995_CLASS_W_SWITCH("AIF2 Switch", WM8995_DAC1_LEFT_MIXER_ROUTING
,
826 WM8995_CLASS_W_SWITCH("AIF1.2 Switch", WM8995_DAC1_LEFT_MIXER_ROUTING
,
828 WM8995_CLASS_W_SWITCH("AIF1.1 Switch", WM8995_DAC1_LEFT_MIXER_ROUTING
,
832 static const struct snd_kcontrol_new dac1r_mix
[] = {
833 WM8995_CLASS_W_SWITCH("Right Sidetone Switch", WM8995_DAC1_RIGHT_MIXER_ROUTING
,
835 WM8995_CLASS_W_SWITCH("Left Sidetone Switch", WM8995_DAC1_RIGHT_MIXER_ROUTING
,
837 WM8995_CLASS_W_SWITCH("AIF2 Switch", WM8995_DAC1_RIGHT_MIXER_ROUTING
,
839 WM8995_CLASS_W_SWITCH("AIF1.2 Switch", WM8995_DAC1_RIGHT_MIXER_ROUTING
,
841 WM8995_CLASS_W_SWITCH("AIF1.1 Switch", WM8995_DAC1_RIGHT_MIXER_ROUTING
,
845 static const struct snd_kcontrol_new aif2dac2l_mix
[] = {
846 SOC_DAPM_SINGLE("Right Sidetone Switch", WM8995_DAC2_LEFT_MIXER_ROUTING
,
848 SOC_DAPM_SINGLE("Left Sidetone Switch", WM8995_DAC2_LEFT_MIXER_ROUTING
,
850 SOC_DAPM_SINGLE("AIF2 Switch", WM8995_DAC2_LEFT_MIXER_ROUTING
,
852 SOC_DAPM_SINGLE("AIF1.2 Switch", WM8995_DAC2_LEFT_MIXER_ROUTING
,
854 SOC_DAPM_SINGLE("AIF1.1 Switch", WM8995_DAC2_LEFT_MIXER_ROUTING
,
858 static const struct snd_kcontrol_new aif2dac2r_mix
[] = {
859 SOC_DAPM_SINGLE("Right Sidetone Switch", WM8995_DAC2_RIGHT_MIXER_ROUTING
,
861 SOC_DAPM_SINGLE("Left Sidetone Switch", WM8995_DAC2_RIGHT_MIXER_ROUTING
,
863 SOC_DAPM_SINGLE("AIF2 Switch", WM8995_DAC2_RIGHT_MIXER_ROUTING
,
865 SOC_DAPM_SINGLE("AIF1.2 Switch", WM8995_DAC2_RIGHT_MIXER_ROUTING
,
867 SOC_DAPM_SINGLE("AIF1.1 Switch", WM8995_DAC2_RIGHT_MIXER_ROUTING
,
871 static const struct snd_kcontrol_new in1l_pga
=
872 SOC_DAPM_SINGLE("IN1L Switch", WM8995_POWER_MANAGEMENT_2
, 5, 1, 0);
874 static const struct snd_kcontrol_new in1r_pga
=
875 SOC_DAPM_SINGLE("IN1R Switch", WM8995_POWER_MANAGEMENT_2
, 4, 1, 0);
877 static const char *adc_mux_text
[] = {
882 static SOC_ENUM_SINGLE_VIRT_DECL(adc_enum
, adc_mux_text
);
884 static const struct snd_kcontrol_new adcl_mux
=
885 SOC_DAPM_ENUM("ADCL Mux", adc_enum
);
887 static const struct snd_kcontrol_new adcr_mux
=
888 SOC_DAPM_ENUM("ADCR Mux", adc_enum
);
890 static const char *spk_src_text
[] = {
891 "DAC1L", "DAC1R", "DAC2L", "DAC2R"
894 static SOC_ENUM_SINGLE_DECL(spk1l_src_enum
, WM8995_LEFT_PDM_SPEAKER_1
,
896 static SOC_ENUM_SINGLE_DECL(spk1r_src_enum
, WM8995_RIGHT_PDM_SPEAKER_1
,
898 static SOC_ENUM_SINGLE_DECL(spk2l_src_enum
, WM8995_LEFT_PDM_SPEAKER_2
,
900 static SOC_ENUM_SINGLE_DECL(spk2r_src_enum
, WM8995_RIGHT_PDM_SPEAKER_2
,
903 static const struct snd_kcontrol_new spk1l_mux
=
904 SOC_DAPM_ENUM("SPK1L SRC", spk1l_src_enum
);
905 static const struct snd_kcontrol_new spk1r_mux
=
906 SOC_DAPM_ENUM("SPK1R SRC", spk1r_src_enum
);
907 static const struct snd_kcontrol_new spk2l_mux
=
908 SOC_DAPM_ENUM("SPK2L SRC", spk2l_src_enum
);
909 static const struct snd_kcontrol_new spk2r_mux
=
910 SOC_DAPM_ENUM("SPK2R SRC", spk2r_src_enum
);
912 static const struct snd_soc_dapm_widget wm8995_dapm_widgets
[] = {
913 SND_SOC_DAPM_INPUT("DMIC1DAT"),
914 SND_SOC_DAPM_INPUT("DMIC2DAT"),
916 SND_SOC_DAPM_INPUT("IN1L"),
917 SND_SOC_DAPM_INPUT("IN1R"),
919 SND_SOC_DAPM_MIXER("IN1L PGA", SND_SOC_NOPM
, 0, 0,
921 SND_SOC_DAPM_MIXER("IN1R PGA", SND_SOC_NOPM
, 0, 0,
924 SND_SOC_DAPM_SUPPLY("MICBIAS1", WM8995_POWER_MANAGEMENT_1
, 8, 0,
926 SND_SOC_DAPM_SUPPLY("MICBIAS2", WM8995_POWER_MANAGEMENT_1
, 9, 0,
929 SND_SOC_DAPM_SUPPLY("AIF1CLK", WM8995_AIF1_CLOCKING_1
, 0, 0, NULL
, 0),
930 SND_SOC_DAPM_SUPPLY("AIF2CLK", WM8995_AIF2_CLOCKING_1
, 0, 0, NULL
, 0),
931 SND_SOC_DAPM_SUPPLY("DSP1CLK", WM8995_CLOCKING_1
, 3, 0, NULL
, 0),
932 SND_SOC_DAPM_SUPPLY("DSP2CLK", WM8995_CLOCKING_1
, 2, 0, NULL
, 0),
933 SND_SOC_DAPM_SUPPLY("SYSDSPCLK", WM8995_CLOCKING_1
, 1, 0, NULL
, 0),
934 SND_SOC_DAPM_SUPPLY("CLK_SYS", SND_SOC_NOPM
, 0, 0, clk_sys_event
,
935 SND_SOC_DAPM_POST_PMU
| SND_SOC_DAPM_PRE_PMD
),
937 SND_SOC_DAPM_AIF_OUT("AIF1ADC1L", "AIF1 Capture", 0,
938 WM8995_POWER_MANAGEMENT_3
, 9, 0),
939 SND_SOC_DAPM_AIF_OUT("AIF1ADC1R", "AIF1 Capture", 0,
940 WM8995_POWER_MANAGEMENT_3
, 8, 0),
941 SND_SOC_DAPM_AIF_OUT("AIF1ADCDAT", "AIF1 Capture", 0,
943 SND_SOC_DAPM_AIF_OUT("AIF1ADC2L", "AIF1 Capture",
944 0, WM8995_POWER_MANAGEMENT_3
, 11, 0),
945 SND_SOC_DAPM_AIF_OUT("AIF1ADC2R", "AIF1 Capture",
946 0, WM8995_POWER_MANAGEMENT_3
, 10, 0),
948 SND_SOC_DAPM_MUX("ADCL Mux", SND_SOC_NOPM
, 1, 0, &adcl_mux
),
949 SND_SOC_DAPM_MUX("ADCR Mux", SND_SOC_NOPM
, 0, 0, &adcr_mux
),
951 SND_SOC_DAPM_ADC("DMIC2L", NULL
, WM8995_POWER_MANAGEMENT_3
, 5, 0),
952 SND_SOC_DAPM_ADC("DMIC2R", NULL
, WM8995_POWER_MANAGEMENT_3
, 4, 0),
953 SND_SOC_DAPM_ADC("DMIC1L", NULL
, WM8995_POWER_MANAGEMENT_3
, 3, 0),
954 SND_SOC_DAPM_ADC("DMIC1R", NULL
, WM8995_POWER_MANAGEMENT_3
, 2, 0),
956 SND_SOC_DAPM_ADC("ADCL", NULL
, WM8995_POWER_MANAGEMENT_3
, 1, 0),
957 SND_SOC_DAPM_ADC("ADCR", NULL
, WM8995_POWER_MANAGEMENT_3
, 0, 0),
959 SND_SOC_DAPM_MIXER("AIF1ADC1L Mixer", SND_SOC_NOPM
, 0, 0,
960 aif1adc1l_mix
, ARRAY_SIZE(aif1adc1l_mix
)),
961 SND_SOC_DAPM_MIXER("AIF1ADC1R Mixer", SND_SOC_NOPM
, 0, 0,
962 aif1adc1r_mix
, ARRAY_SIZE(aif1adc1r_mix
)),
963 SND_SOC_DAPM_MIXER("AIF1ADC2L Mixer", SND_SOC_NOPM
, 0, 0,
964 aif1adc2l_mix
, ARRAY_SIZE(aif1adc2l_mix
)),
965 SND_SOC_DAPM_MIXER("AIF1ADC2R Mixer", SND_SOC_NOPM
, 0, 0,
966 aif1adc2r_mix
, ARRAY_SIZE(aif1adc2r_mix
)),
968 SND_SOC_DAPM_AIF_IN("AIF1DAC1L", NULL
, 0, WM8995_POWER_MANAGEMENT_4
,
970 SND_SOC_DAPM_AIF_IN("AIF1DAC1R", NULL
, 0, WM8995_POWER_MANAGEMENT_4
,
972 SND_SOC_DAPM_AIF_IN("AIF1DACDAT", "AIF1 Playback", 0, SND_SOC_NOPM
,
975 SND_SOC_DAPM_AIF_IN("AIF1DAC2L", NULL
, 0, WM8995_POWER_MANAGEMENT_4
,
977 SND_SOC_DAPM_AIF_IN("AIF1DAC2R", NULL
, 0, WM8995_POWER_MANAGEMENT_4
,
980 SND_SOC_DAPM_MIXER("AIF2DAC2L Mixer", SND_SOC_NOPM
, 0, 0,
981 aif2dac2l_mix
, ARRAY_SIZE(aif2dac2l_mix
)),
982 SND_SOC_DAPM_MIXER("AIF2DAC2R Mixer", SND_SOC_NOPM
, 0, 0,
983 aif2dac2r_mix
, ARRAY_SIZE(aif2dac2r_mix
)),
985 SND_SOC_DAPM_DAC("DAC2L", NULL
, WM8995_POWER_MANAGEMENT_4
, 3, 0),
986 SND_SOC_DAPM_DAC("DAC2R", NULL
, WM8995_POWER_MANAGEMENT_4
, 2, 0),
987 SND_SOC_DAPM_DAC("DAC1L", NULL
, WM8995_POWER_MANAGEMENT_4
, 1, 0),
988 SND_SOC_DAPM_DAC("DAC1R", NULL
, WM8995_POWER_MANAGEMENT_4
, 0, 0),
990 SND_SOC_DAPM_MIXER("DAC1L Mixer", SND_SOC_NOPM
, 0, 0, dac1l_mix
,
991 ARRAY_SIZE(dac1l_mix
)),
992 SND_SOC_DAPM_MIXER("DAC1R Mixer", SND_SOC_NOPM
, 0, 0, dac1r_mix
,
993 ARRAY_SIZE(dac1r_mix
)),
995 SND_SOC_DAPM_MUX("Left Sidetone", SND_SOC_NOPM
, 0, 0, &sidetone1_mux
),
996 SND_SOC_DAPM_MUX("Right Sidetone", SND_SOC_NOPM
, 0, 0, &sidetone2_mux
),
998 SND_SOC_DAPM_PGA_E("Headphone PGA", SND_SOC_NOPM
, 0, 0, NULL
, 0,
999 hp_event
, SND_SOC_DAPM_POST_PMU
| SND_SOC_DAPM_PRE_PMD
),
1001 SND_SOC_DAPM_SUPPLY("Headphone Supply", SND_SOC_NOPM
, 0, 0,
1002 hp_supply_event
, SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_PRE_PMD
),
1004 SND_SOC_DAPM_MUX("SPK1L Driver", WM8995_LEFT_PDM_SPEAKER_1
,
1006 SND_SOC_DAPM_MUX("SPK1R Driver", WM8995_RIGHT_PDM_SPEAKER_1
,
1008 SND_SOC_DAPM_MUX("SPK2L Driver", WM8995_LEFT_PDM_SPEAKER_2
,
1010 SND_SOC_DAPM_MUX("SPK2R Driver", WM8995_RIGHT_PDM_SPEAKER_2
,
1013 SND_SOC_DAPM_SUPPLY("LDO2", WM8995_POWER_MANAGEMENT_2
, 1, 0, NULL
, 0),
1015 SND_SOC_DAPM_OUTPUT("HP1L"),
1016 SND_SOC_DAPM_OUTPUT("HP1R"),
1017 SND_SOC_DAPM_OUTPUT("SPK1L"),
1018 SND_SOC_DAPM_OUTPUT("SPK1R"),
1019 SND_SOC_DAPM_OUTPUT("SPK2L"),
1020 SND_SOC_DAPM_OUTPUT("SPK2R")
1023 static const struct snd_soc_dapm_route wm8995_intercon
[] = {
1024 { "CLK_SYS", NULL
, "AIF1CLK", check_clk_sys
},
1025 { "CLK_SYS", NULL
, "AIF2CLK", check_clk_sys
},
1027 { "DSP1CLK", NULL
, "CLK_SYS" },
1028 { "DSP2CLK", NULL
, "CLK_SYS" },
1029 { "SYSDSPCLK", NULL
, "CLK_SYS" },
1031 { "AIF1ADC1L", NULL
, "AIF1CLK" },
1032 { "AIF1ADC1L", NULL
, "DSP1CLK" },
1033 { "AIF1ADC1R", NULL
, "AIF1CLK" },
1034 { "AIF1ADC1R", NULL
, "DSP1CLK" },
1035 { "AIF1ADC1R", NULL
, "SYSDSPCLK" },
1037 { "AIF1ADC2L", NULL
, "AIF1CLK" },
1038 { "AIF1ADC2L", NULL
, "DSP1CLK" },
1039 { "AIF1ADC2R", NULL
, "AIF1CLK" },
1040 { "AIF1ADC2R", NULL
, "DSP1CLK" },
1041 { "AIF1ADC2R", NULL
, "SYSDSPCLK" },
1043 { "DMIC1L", NULL
, "DMIC1DAT" },
1044 { "DMIC1L", NULL
, "CLK_SYS" },
1045 { "DMIC1R", NULL
, "DMIC1DAT" },
1046 { "DMIC1R", NULL
, "CLK_SYS" },
1047 { "DMIC2L", NULL
, "DMIC2DAT" },
1048 { "DMIC2L", NULL
, "CLK_SYS" },
1049 { "DMIC2R", NULL
, "DMIC2DAT" },
1050 { "DMIC2R", NULL
, "CLK_SYS" },
1052 { "ADCL", NULL
, "AIF1CLK" },
1053 { "ADCL", NULL
, "DSP1CLK" },
1054 { "ADCL", NULL
, "SYSDSPCLK" },
1056 { "ADCR", NULL
, "AIF1CLK" },
1057 { "ADCR", NULL
, "DSP1CLK" },
1058 { "ADCR", NULL
, "SYSDSPCLK" },
1060 { "IN1L PGA", "IN1L Switch", "IN1L" },
1061 { "IN1R PGA", "IN1R Switch", "IN1R" },
1062 { "IN1L PGA", NULL
, "LDO2" },
1063 { "IN1R PGA", NULL
, "LDO2" },
1065 { "ADCL", NULL
, "IN1L PGA" },
1066 { "ADCR", NULL
, "IN1R PGA" },
1068 { "ADCL Mux", "ADC", "ADCL" },
1069 { "ADCL Mux", "DMIC", "DMIC1L" },
1070 { "ADCR Mux", "ADC", "ADCR" },
1071 { "ADCR Mux", "DMIC", "DMIC1R" },
1074 { "AIF1ADC1L", NULL
, "AIF1ADC1L Mixer" },
1075 { "AIF1ADC1L Mixer", "ADC/DMIC Switch", "ADCL Mux" },
1077 { "AIF1ADC1R", NULL
, "AIF1ADC1R Mixer" },
1078 { "AIF1ADC1R Mixer", "ADC/DMIC Switch", "ADCR Mux" },
1080 { "AIF1ADC2L", NULL
, "AIF1ADC2L Mixer" },
1081 { "AIF1ADC2L Mixer", "DMIC Switch", "DMIC2L" },
1083 { "AIF1ADC2R", NULL
, "AIF1ADC2R Mixer" },
1084 { "AIF1ADC2R Mixer", "DMIC Switch", "DMIC2R" },
1087 { "Left Sidetone", "ADC/DMIC1", "AIF1ADC1L" },
1088 { "Left Sidetone", "DMIC2", "AIF1ADC2L" },
1089 { "Right Sidetone", "ADC/DMIC1", "AIF1ADC1R" },
1090 { "Right Sidetone", "DMIC2", "AIF1ADC2R" },
1092 { "AIF1DAC1L", NULL
, "AIF1CLK" },
1093 { "AIF1DAC1L", NULL
, "DSP1CLK" },
1094 { "AIF1DAC1R", NULL
, "AIF1CLK" },
1095 { "AIF1DAC1R", NULL
, "DSP1CLK" },
1096 { "AIF1DAC1R", NULL
, "SYSDSPCLK" },
1098 { "AIF1DAC2L", NULL
, "AIF1CLK" },
1099 { "AIF1DAC2L", NULL
, "DSP1CLK" },
1100 { "AIF1DAC2R", NULL
, "AIF1CLK" },
1101 { "AIF1DAC2R", NULL
, "DSP1CLK" },
1102 { "AIF1DAC2R", NULL
, "SYSDSPCLK" },
1104 { "DAC1L", NULL
, "AIF1CLK" },
1105 { "DAC1L", NULL
, "DSP1CLK" },
1106 { "DAC1L", NULL
, "SYSDSPCLK" },
1108 { "DAC1R", NULL
, "AIF1CLK" },
1109 { "DAC1R", NULL
, "DSP1CLK" },
1110 { "DAC1R", NULL
, "SYSDSPCLK" },
1112 { "AIF1DAC1L", NULL
, "AIF1DACDAT" },
1113 { "AIF1DAC1R", NULL
, "AIF1DACDAT" },
1114 { "AIF1DAC2L", NULL
, "AIF1DACDAT" },
1115 { "AIF1DAC2R", NULL
, "AIF1DACDAT" },
1118 { "DAC1L", NULL
, "DAC1L Mixer" },
1119 { "DAC1L Mixer", "AIF1.1 Switch", "AIF1DAC1L" },
1120 { "DAC1L Mixer", "AIF1.2 Switch", "AIF1DAC2L" },
1121 { "DAC1L Mixer", "Left Sidetone Switch", "Left Sidetone" },
1122 { "DAC1L Mixer", "Right Sidetone Switch", "Right Sidetone" },
1124 { "DAC1R", NULL
, "DAC1R Mixer" },
1125 { "DAC1R Mixer", "AIF1.1 Switch", "AIF1DAC1R" },
1126 { "DAC1R Mixer", "AIF1.2 Switch", "AIF1DAC2R" },
1127 { "DAC1R Mixer", "Left Sidetone Switch", "Left Sidetone" },
1128 { "DAC1R Mixer", "Right Sidetone Switch", "Right Sidetone" },
1130 /* DAC2/AIF2 outputs */
1131 { "DAC2L", NULL
, "AIF2DAC2L Mixer" },
1132 { "AIF2DAC2L Mixer", "AIF1.2 Switch", "AIF1DAC2L" },
1133 { "AIF2DAC2L Mixer", "AIF1.1 Switch", "AIF1DAC1L" },
1135 { "DAC2R", NULL
, "AIF2DAC2R Mixer" },
1136 { "AIF2DAC2R Mixer", "AIF1.2 Switch", "AIF1DAC2R" },
1137 { "AIF2DAC2R Mixer", "AIF1.1 Switch", "AIF1DAC1R" },
1140 { "Headphone PGA", NULL
, "DAC1L" },
1141 { "Headphone PGA", NULL
, "DAC1R" },
1143 { "Headphone PGA", NULL
, "DAC2L" },
1144 { "Headphone PGA", NULL
, "DAC2R" },
1146 { "Headphone PGA", NULL
, "Headphone Supply" },
1147 { "Headphone PGA", NULL
, "CLK_SYS" },
1148 { "Headphone PGA", NULL
, "LDO2" },
1150 { "HP1L", NULL
, "Headphone PGA" },
1151 { "HP1R", NULL
, "Headphone PGA" },
1153 { "SPK1L Driver", "DAC1L", "DAC1L" },
1154 { "SPK1L Driver", "DAC1R", "DAC1R" },
1155 { "SPK1L Driver", "DAC2L", "DAC2L" },
1156 { "SPK1L Driver", "DAC2R", "DAC2R" },
1157 { "SPK1L Driver", NULL
, "CLK_SYS" },
1159 { "SPK1R Driver", "DAC1L", "DAC1L" },
1160 { "SPK1R Driver", "DAC1R", "DAC1R" },
1161 { "SPK1R Driver", "DAC2L", "DAC2L" },
1162 { "SPK1R Driver", "DAC2R", "DAC2R" },
1163 { "SPK1R Driver", NULL
, "CLK_SYS" },
1165 { "SPK2L Driver", "DAC1L", "DAC1L" },
1166 { "SPK2L Driver", "DAC1R", "DAC1R" },
1167 { "SPK2L Driver", "DAC2L", "DAC2L" },
1168 { "SPK2L Driver", "DAC2R", "DAC2R" },
1169 { "SPK2L Driver", NULL
, "CLK_SYS" },
1171 { "SPK2R Driver", "DAC1L", "DAC1L" },
1172 { "SPK2R Driver", "DAC1R", "DAC1R" },
1173 { "SPK2R Driver", "DAC2L", "DAC2L" },
1174 { "SPK2R Driver", "DAC2R", "DAC2R" },
1175 { "SPK2R Driver", NULL
, "CLK_SYS" },
1177 { "SPK1L", NULL
, "SPK1L Driver" },
1178 { "SPK1R", NULL
, "SPK1R Driver" },
1179 { "SPK2L", NULL
, "SPK2L Driver" },
1180 { "SPK2R", NULL
, "SPK2R Driver" }
1183 static bool wm8995_readable(struct device
*dev
, unsigned int reg
)
1186 case WM8995_SOFTWARE_RESET
:
1187 case WM8995_POWER_MANAGEMENT_1
:
1188 case WM8995_POWER_MANAGEMENT_2
:
1189 case WM8995_POWER_MANAGEMENT_3
:
1190 case WM8995_POWER_MANAGEMENT_4
:
1191 case WM8995_POWER_MANAGEMENT_5
:
1192 case WM8995_LEFT_LINE_INPUT_1_VOLUME
:
1193 case WM8995_RIGHT_LINE_INPUT_1_VOLUME
:
1194 case WM8995_LEFT_LINE_INPUT_CONTROL
:
1195 case WM8995_DAC1_LEFT_VOLUME
:
1196 case WM8995_DAC1_RIGHT_VOLUME
:
1197 case WM8995_DAC2_LEFT_VOLUME
:
1198 case WM8995_DAC2_RIGHT_VOLUME
:
1199 case WM8995_OUTPUT_VOLUME_ZC_1
:
1200 case WM8995_MICBIAS_1
:
1201 case WM8995_MICBIAS_2
:
1204 case WM8995_ACCESSORY_DETECT_MODE1
:
1205 case WM8995_ACCESSORY_DETECT_MODE2
:
1206 case WM8995_HEADPHONE_DETECT1
:
1207 case WM8995_HEADPHONE_DETECT2
:
1208 case WM8995_MIC_DETECT_1
:
1209 case WM8995_MIC_DETECT_2
:
1210 case WM8995_CHARGE_PUMP_1
:
1211 case WM8995_CLASS_W_1
:
1212 case WM8995_DC_SERVO_1
:
1213 case WM8995_DC_SERVO_2
:
1214 case WM8995_DC_SERVO_3
:
1215 case WM8995_DC_SERVO_5
:
1216 case WM8995_DC_SERVO_6
:
1217 case WM8995_DC_SERVO_7
:
1218 case WM8995_DC_SERVO_READBACK_0
:
1219 case WM8995_ANALOGUE_HP_1
:
1220 case WM8995_ANALOGUE_HP_2
:
1221 case WM8995_CHIP_REVISION
:
1222 case WM8995_CONTROL_INTERFACE_1
:
1223 case WM8995_CONTROL_INTERFACE_2
:
1224 case WM8995_WRITE_SEQUENCER_CTRL_1
:
1225 case WM8995_WRITE_SEQUENCER_CTRL_2
:
1226 case WM8995_AIF1_CLOCKING_1
:
1227 case WM8995_AIF1_CLOCKING_2
:
1228 case WM8995_AIF2_CLOCKING_1
:
1229 case WM8995_AIF2_CLOCKING_2
:
1230 case WM8995_CLOCKING_1
:
1231 case WM8995_CLOCKING_2
:
1232 case WM8995_AIF1_RATE
:
1233 case WM8995_AIF2_RATE
:
1234 case WM8995_RATE_STATUS
:
1235 case WM8995_FLL1_CONTROL_1
:
1236 case WM8995_FLL1_CONTROL_2
:
1237 case WM8995_FLL1_CONTROL_3
:
1238 case WM8995_FLL1_CONTROL_4
:
1239 case WM8995_FLL1_CONTROL_5
:
1240 case WM8995_FLL2_CONTROL_1
:
1241 case WM8995_FLL2_CONTROL_2
:
1242 case WM8995_FLL2_CONTROL_3
:
1243 case WM8995_FLL2_CONTROL_4
:
1244 case WM8995_FLL2_CONTROL_5
:
1245 case WM8995_AIF1_CONTROL_1
:
1246 case WM8995_AIF1_CONTROL_2
:
1247 case WM8995_AIF1_MASTER_SLAVE
:
1248 case WM8995_AIF1_BCLK
:
1249 case WM8995_AIF1ADC_LRCLK
:
1250 case WM8995_AIF1DAC_LRCLK
:
1251 case WM8995_AIF1DAC_DATA
:
1252 case WM8995_AIF1ADC_DATA
:
1253 case WM8995_AIF2_CONTROL_1
:
1254 case WM8995_AIF2_CONTROL_2
:
1255 case WM8995_AIF2_MASTER_SLAVE
:
1256 case WM8995_AIF2_BCLK
:
1257 case WM8995_AIF2ADC_LRCLK
:
1258 case WM8995_AIF2DAC_LRCLK
:
1259 case WM8995_AIF2DAC_DATA
:
1260 case WM8995_AIF2ADC_DATA
:
1261 case WM8995_AIF1_ADC1_LEFT_VOLUME
:
1262 case WM8995_AIF1_ADC1_RIGHT_VOLUME
:
1263 case WM8995_AIF1_DAC1_LEFT_VOLUME
:
1264 case WM8995_AIF1_DAC1_RIGHT_VOLUME
:
1265 case WM8995_AIF1_ADC2_LEFT_VOLUME
:
1266 case WM8995_AIF1_ADC2_RIGHT_VOLUME
:
1267 case WM8995_AIF1_DAC2_LEFT_VOLUME
:
1268 case WM8995_AIF1_DAC2_RIGHT_VOLUME
:
1269 case WM8995_AIF1_ADC1_FILTERS
:
1270 case WM8995_AIF1_ADC2_FILTERS
:
1271 case WM8995_AIF1_DAC1_FILTERS_1
:
1272 case WM8995_AIF1_DAC1_FILTERS_2
:
1273 case WM8995_AIF1_DAC2_FILTERS_1
:
1274 case WM8995_AIF1_DAC2_FILTERS_2
:
1275 case WM8995_AIF1_DRC1_1
:
1276 case WM8995_AIF1_DRC1_2
:
1277 case WM8995_AIF1_DRC1_3
:
1278 case WM8995_AIF1_DRC1_4
:
1279 case WM8995_AIF1_DRC1_5
:
1280 case WM8995_AIF1_DRC2_1
:
1281 case WM8995_AIF1_DRC2_2
:
1282 case WM8995_AIF1_DRC2_3
:
1283 case WM8995_AIF1_DRC2_4
:
1284 case WM8995_AIF1_DRC2_5
:
1285 case WM8995_AIF1_DAC1_EQ_GAINS_1
:
1286 case WM8995_AIF1_DAC1_EQ_GAINS_2
:
1287 case WM8995_AIF1_DAC1_EQ_BAND_1_A
:
1288 case WM8995_AIF1_DAC1_EQ_BAND_1_B
:
1289 case WM8995_AIF1_DAC1_EQ_BAND_1_PG
:
1290 case WM8995_AIF1_DAC1_EQ_BAND_2_A
:
1291 case WM8995_AIF1_DAC1_EQ_BAND_2_B
:
1292 case WM8995_AIF1_DAC1_EQ_BAND_2_C
:
1293 case WM8995_AIF1_DAC1_EQ_BAND_2_PG
:
1294 case WM8995_AIF1_DAC1_EQ_BAND_3_A
:
1295 case WM8995_AIF1_DAC1_EQ_BAND_3_B
:
1296 case WM8995_AIF1_DAC1_EQ_BAND_3_C
:
1297 case WM8995_AIF1_DAC1_EQ_BAND_3_PG
:
1298 case WM8995_AIF1_DAC1_EQ_BAND_4_A
:
1299 case WM8995_AIF1_DAC1_EQ_BAND_4_B
:
1300 case WM8995_AIF1_DAC1_EQ_BAND_4_C
:
1301 case WM8995_AIF1_DAC1_EQ_BAND_4_PG
:
1302 case WM8995_AIF1_DAC1_EQ_BAND_5_A
:
1303 case WM8995_AIF1_DAC1_EQ_BAND_5_B
:
1304 case WM8995_AIF1_DAC1_EQ_BAND_5_PG
:
1305 case WM8995_AIF1_DAC2_EQ_GAINS_1
:
1306 case WM8995_AIF1_DAC2_EQ_GAINS_2
:
1307 case WM8995_AIF1_DAC2_EQ_BAND_1_A
:
1308 case WM8995_AIF1_DAC2_EQ_BAND_1_B
:
1309 case WM8995_AIF1_DAC2_EQ_BAND_1_PG
:
1310 case WM8995_AIF1_DAC2_EQ_BAND_2_A
:
1311 case WM8995_AIF1_DAC2_EQ_BAND_2_B
:
1312 case WM8995_AIF1_DAC2_EQ_BAND_2_C
:
1313 case WM8995_AIF1_DAC2_EQ_BAND_2_PG
:
1314 case WM8995_AIF1_DAC2_EQ_BAND_3_A
:
1315 case WM8995_AIF1_DAC2_EQ_BAND_3_B
:
1316 case WM8995_AIF1_DAC2_EQ_BAND_3_C
:
1317 case WM8995_AIF1_DAC2_EQ_BAND_3_PG
:
1318 case WM8995_AIF1_DAC2_EQ_BAND_4_A
:
1319 case WM8995_AIF1_DAC2_EQ_BAND_4_B
:
1320 case WM8995_AIF1_DAC2_EQ_BAND_4_C
:
1321 case WM8995_AIF1_DAC2_EQ_BAND_4_PG
:
1322 case WM8995_AIF1_DAC2_EQ_BAND_5_A
:
1323 case WM8995_AIF1_DAC2_EQ_BAND_5_B
:
1324 case WM8995_AIF1_DAC2_EQ_BAND_5_PG
:
1325 case WM8995_AIF2_ADC_LEFT_VOLUME
:
1326 case WM8995_AIF2_ADC_RIGHT_VOLUME
:
1327 case WM8995_AIF2_DAC_LEFT_VOLUME
:
1328 case WM8995_AIF2_DAC_RIGHT_VOLUME
:
1329 case WM8995_AIF2_ADC_FILTERS
:
1330 case WM8995_AIF2_DAC_FILTERS_1
:
1331 case WM8995_AIF2_DAC_FILTERS_2
:
1332 case WM8995_AIF2_DRC_1
:
1333 case WM8995_AIF2_DRC_2
:
1334 case WM8995_AIF2_DRC_3
:
1335 case WM8995_AIF2_DRC_4
:
1336 case WM8995_AIF2_DRC_5
:
1337 case WM8995_AIF2_EQ_GAINS_1
:
1338 case WM8995_AIF2_EQ_GAINS_2
:
1339 case WM8995_AIF2_EQ_BAND_1_A
:
1340 case WM8995_AIF2_EQ_BAND_1_B
:
1341 case WM8995_AIF2_EQ_BAND_1_PG
:
1342 case WM8995_AIF2_EQ_BAND_2_A
:
1343 case WM8995_AIF2_EQ_BAND_2_B
:
1344 case WM8995_AIF2_EQ_BAND_2_C
:
1345 case WM8995_AIF2_EQ_BAND_2_PG
:
1346 case WM8995_AIF2_EQ_BAND_3_A
:
1347 case WM8995_AIF2_EQ_BAND_3_B
:
1348 case WM8995_AIF2_EQ_BAND_3_C
:
1349 case WM8995_AIF2_EQ_BAND_3_PG
:
1350 case WM8995_AIF2_EQ_BAND_4_A
:
1351 case WM8995_AIF2_EQ_BAND_4_B
:
1352 case WM8995_AIF2_EQ_BAND_4_C
:
1353 case WM8995_AIF2_EQ_BAND_4_PG
:
1354 case WM8995_AIF2_EQ_BAND_5_A
:
1355 case WM8995_AIF2_EQ_BAND_5_B
:
1356 case WM8995_AIF2_EQ_BAND_5_PG
:
1357 case WM8995_DAC1_MIXER_VOLUMES
:
1358 case WM8995_DAC1_LEFT_MIXER_ROUTING
:
1359 case WM8995_DAC1_RIGHT_MIXER_ROUTING
:
1360 case WM8995_DAC2_MIXER_VOLUMES
:
1361 case WM8995_DAC2_LEFT_MIXER_ROUTING
:
1362 case WM8995_DAC2_RIGHT_MIXER_ROUTING
:
1363 case WM8995_AIF1_ADC1_LEFT_MIXER_ROUTING
:
1364 case WM8995_AIF1_ADC1_RIGHT_MIXER_ROUTING
:
1365 case WM8995_AIF1_ADC2_LEFT_MIXER_ROUTING
:
1366 case WM8995_AIF1_ADC2_RIGHT_MIXER_ROUTING
:
1367 case WM8995_DAC_SOFTMUTE
:
1368 case WM8995_OVERSAMPLING
:
1369 case WM8995_SIDETONE
:
1379 case WM8995_GPIO_10
:
1380 case WM8995_GPIO_11
:
1381 case WM8995_GPIO_12
:
1382 case WM8995_GPIO_13
:
1383 case WM8995_GPIO_14
:
1384 case WM8995_PULL_CONTROL_1
:
1385 case WM8995_PULL_CONTROL_2
:
1386 case WM8995_INTERRUPT_STATUS_1
:
1387 case WM8995_INTERRUPT_STATUS_2
:
1388 case WM8995_INTERRUPT_RAW_STATUS_2
:
1389 case WM8995_INTERRUPT_STATUS_1_MASK
:
1390 case WM8995_INTERRUPT_STATUS_2_MASK
:
1391 case WM8995_INTERRUPT_CONTROL
:
1392 case WM8995_LEFT_PDM_SPEAKER_1
:
1393 case WM8995_RIGHT_PDM_SPEAKER_1
:
1394 case WM8995_PDM_SPEAKER_1_MUTE_SEQUENCE
:
1395 case WM8995_LEFT_PDM_SPEAKER_2
:
1396 case WM8995_RIGHT_PDM_SPEAKER_2
:
1397 case WM8995_PDM_SPEAKER_2_MUTE_SEQUENCE
:
1404 static bool wm8995_volatile(struct device
*dev
, unsigned int reg
)
1407 case WM8995_SOFTWARE_RESET
:
1408 case WM8995_DC_SERVO_READBACK_0
:
1409 case WM8995_INTERRUPT_STATUS_1
:
1410 case WM8995_INTERRUPT_STATUS_2
:
1411 case WM8995_INTERRUPT_CONTROL
:
1412 case WM8995_ACCESSORY_DETECT_MODE1
:
1413 case WM8995_ACCESSORY_DETECT_MODE2
:
1414 case WM8995_HEADPHONE_DETECT1
:
1415 case WM8995_HEADPHONE_DETECT2
:
1416 case WM8995_RATE_STATUS
:
1423 static int wm8995_aif_mute(struct snd_soc_dai
*dai
, int mute
)
1425 struct snd_soc_codec
*codec
= dai
->codec
;
1430 mute_reg
= WM8995_AIF1_DAC1_FILTERS_1
;
1433 mute_reg
= WM8995_AIF2_DAC_FILTERS_1
;
1439 snd_soc_update_bits(codec
, mute_reg
, WM8995_AIF1DAC1_MUTE_MASK
,
1440 !!mute
<< WM8995_AIF1DAC1_MUTE_SHIFT
);
1444 static int wm8995_set_dai_fmt(struct snd_soc_dai
*dai
, unsigned int fmt
)
1446 struct snd_soc_codec
*codec
;
1453 switch (fmt
& SND_SOC_DAIFMT_MASTER_MASK
) {
1454 case SND_SOC_DAIFMT_CBS_CFS
:
1456 case SND_SOC_DAIFMT_CBM_CFM
:
1457 master
= WM8995_AIF1_MSTR
;
1460 dev_err(dai
->dev
, "Unknown master/slave configuration\n");
1465 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
1466 case SND_SOC_DAIFMT_DSP_B
:
1467 aif
|= WM8995_AIF1_LRCLK_INV
;
1468 case SND_SOC_DAIFMT_DSP_A
:
1469 aif
|= (0x3 << WM8995_AIF1_FMT_SHIFT
);
1471 case SND_SOC_DAIFMT_I2S
:
1472 aif
|= (0x2 << WM8995_AIF1_FMT_SHIFT
);
1474 case SND_SOC_DAIFMT_RIGHT_J
:
1476 case SND_SOC_DAIFMT_LEFT_J
:
1477 aif
|= (0x1 << WM8995_AIF1_FMT_SHIFT
);
1480 dev_err(dai
->dev
, "Unknown dai format\n");
1484 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
1485 case SND_SOC_DAIFMT_DSP_A
:
1486 case SND_SOC_DAIFMT_DSP_B
:
1487 /* frame inversion not valid for DSP modes */
1488 switch (fmt
& SND_SOC_DAIFMT_INV_MASK
) {
1489 case SND_SOC_DAIFMT_NB_NF
:
1491 case SND_SOC_DAIFMT_IB_NF
:
1492 aif
|= WM8995_AIF1_BCLK_INV
;
1499 case SND_SOC_DAIFMT_I2S
:
1500 case SND_SOC_DAIFMT_RIGHT_J
:
1501 case SND_SOC_DAIFMT_LEFT_J
:
1502 switch (fmt
& SND_SOC_DAIFMT_INV_MASK
) {
1503 case SND_SOC_DAIFMT_NB_NF
:
1505 case SND_SOC_DAIFMT_IB_IF
:
1506 aif
|= WM8995_AIF1_BCLK_INV
| WM8995_AIF1_LRCLK_INV
;
1508 case SND_SOC_DAIFMT_IB_NF
:
1509 aif
|= WM8995_AIF1_BCLK_INV
;
1511 case SND_SOC_DAIFMT_NB_IF
:
1512 aif
|= WM8995_AIF1_LRCLK_INV
;
1522 snd_soc_update_bits(codec
, WM8995_AIF1_CONTROL_1
,
1523 WM8995_AIF1_BCLK_INV_MASK
|
1524 WM8995_AIF1_LRCLK_INV_MASK
|
1525 WM8995_AIF1_FMT_MASK
, aif
);
1526 snd_soc_update_bits(codec
, WM8995_AIF1_MASTER_SLAVE
,
1527 WM8995_AIF1_MSTR_MASK
, master
);
1531 static const int srs
[] = {
1532 8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100,
1536 static const int fs_ratios
[] = {
1538 128, 192, 256, 384, 512, 768, 1024, 1408, 1536
1541 static const int bclk_divs
[] = {
1542 10, 15, 20, 30, 40, 55, 60, 80, 110, 120, 160, 220, 240, 320, 440, 480
1545 static int wm8995_hw_params(struct snd_pcm_substream
*substream
,
1546 struct snd_pcm_hw_params
*params
,
1547 struct snd_soc_dai
*dai
)
1549 struct snd_soc_codec
*codec
;
1550 struct wm8995_priv
*wm8995
;
1558 int i
, rate_val
, best
, best_val
, cur_val
;
1561 wm8995
= snd_soc_codec_get_drvdata(codec
);
1565 aif1_reg
= WM8995_AIF1_CONTROL_1
;
1566 bclk_reg
= WM8995_AIF1_BCLK
;
1567 rate_reg
= WM8995_AIF1_RATE
;
1568 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
/* ||
1569 wm8995->lrclk_shared[0] */) {
1570 lrclk_reg
= WM8995_AIF1DAC_LRCLK
;
1572 lrclk_reg
= WM8995_AIF1ADC_LRCLK
;
1573 dev_dbg(codec
->dev
, "AIF1 using split LRCLK\n");
1577 aif1_reg
= WM8995_AIF2_CONTROL_1
;
1578 bclk_reg
= WM8995_AIF2_BCLK
;
1579 rate_reg
= WM8995_AIF2_RATE
;
1580 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
/* ||
1581 wm8995->lrclk_shared[1] */) {
1582 lrclk_reg
= WM8995_AIF2DAC_LRCLK
;
1584 lrclk_reg
= WM8995_AIF2ADC_LRCLK
;
1585 dev_dbg(codec
->dev
, "AIF2 using split LRCLK\n");
1592 bclk_rate
= snd_soc_params_to_bclk(params
);
1597 switch (params_width(params
)) {
1601 aif1
|= (0x1 << WM8995_AIF1_WL_SHIFT
);
1604 aif1
|= (0x2 << WM8995_AIF1_WL_SHIFT
);
1607 aif1
|= (0x3 << WM8995_AIF1_WL_SHIFT
);
1610 dev_err(dai
->dev
, "Unsupported word length %u\n",
1611 params_width(params
));
1615 /* try to find a suitable sample rate */
1616 for (i
= 0; i
< ARRAY_SIZE(srs
); ++i
)
1617 if (srs
[i
] == params_rate(params
))
1619 if (i
== ARRAY_SIZE(srs
)) {
1620 dev_err(dai
->dev
, "Sample rate %d is not supported\n",
1621 params_rate(params
));
1624 rate_val
= i
<< WM8995_AIF1_SR_SHIFT
;
1626 dev_dbg(dai
->dev
, "Sample rate is %dHz\n", srs
[i
]);
1627 dev_dbg(dai
->dev
, "AIF%dCLK is %dHz, target BCLK %dHz\n",
1628 dai
->id
+ 1, wm8995
->aifclk
[dai
->id
], bclk_rate
);
1630 /* AIFCLK/fs ratio; look for a close match in either direction */
1632 best_val
= abs((fs_ratios
[1] * params_rate(params
))
1633 - wm8995
->aifclk
[dai
->id
]);
1634 for (i
= 2; i
< ARRAY_SIZE(fs_ratios
); i
++) {
1635 cur_val
= abs((fs_ratios
[i
] * params_rate(params
))
1636 - wm8995
->aifclk
[dai
->id
]);
1637 if (cur_val
>= best_val
)
1644 dev_dbg(dai
->dev
, "Selected AIF%dCLK/fs = %d\n",
1645 dai
->id
+ 1, fs_ratios
[best
]);
1648 * We may not get quite the right frequency if using
1649 * approximate clocks so look for the closest match that is
1650 * higher than the target (we need to ensure that there enough
1651 * BCLKs to clock out the samples).
1655 for (i
= 0; i
< ARRAY_SIZE(bclk_divs
); i
++) {
1656 cur_val
= (wm8995
->aifclk
[dai
->id
] * 10 / bclk_divs
[i
]) - bclk_rate
;
1657 if (cur_val
< 0) /* BCLK table is sorted */
1661 bclk
|= best
<< WM8995_AIF1_BCLK_DIV_SHIFT
;
1663 bclk_rate
= wm8995
->aifclk
[dai
->id
] * 10 / bclk_divs
[best
];
1664 dev_dbg(dai
->dev
, "Using BCLK_DIV %d for actual BCLK %dHz\n",
1665 bclk_divs
[best
], bclk_rate
);
1667 lrclk
= bclk_rate
/ params_rate(params
);
1668 dev_dbg(dai
->dev
, "Using LRCLK rate %d for actual LRCLK %dHz\n",
1669 lrclk
, bclk_rate
/ lrclk
);
1671 snd_soc_update_bits(codec
, aif1_reg
,
1672 WM8995_AIF1_WL_MASK
, aif1
);
1673 snd_soc_update_bits(codec
, bclk_reg
,
1674 WM8995_AIF1_BCLK_DIV_MASK
, bclk
);
1675 snd_soc_update_bits(codec
, lrclk_reg
,
1676 WM8995_AIF1DAC_RATE_MASK
, lrclk
);
1677 snd_soc_update_bits(codec
, rate_reg
,
1678 WM8995_AIF1_SR_MASK
|
1679 WM8995_AIF1CLK_RATE_MASK
, rate_val
);
1683 static int wm8995_set_tristate(struct snd_soc_dai
*codec_dai
, int tristate
)
1685 struct snd_soc_codec
*codec
= codec_dai
->codec
;
1688 switch (codec_dai
->id
) {
1690 reg
= WM8995_AIF1_MASTER_SLAVE
;
1691 mask
= WM8995_AIF1_TRI
;
1694 reg
= WM8995_AIF2_MASTER_SLAVE
;
1695 mask
= WM8995_AIF2_TRI
;
1698 reg
= WM8995_POWER_MANAGEMENT_5
;
1699 mask
= WM8995_AIF3_TRI
;
1710 return snd_soc_update_bits(codec
, reg
, mask
, val
);
1713 /* The size in bits of the FLL divide multiplied by 10
1714 * to allow rounding later */
1715 #define FIXED_FLL_SIZE ((1 << 16) * 10)
1725 static int wm8995_get_fll_config(struct fll_div
*fll
,
1726 int freq_in
, int freq_out
)
1729 unsigned int K
, Ndiv
, Nmod
;
1731 pr_debug("FLL input=%dHz, output=%dHz\n", freq_in
, freq_out
);
1733 /* Scale the input frequency down to <= 13.5MHz */
1734 fll
->clk_ref_div
= 0;
1735 while (freq_in
> 13500000) {
1739 if (fll
->clk_ref_div
> 3)
1742 pr_debug("CLK_REF_DIV=%d, Fref=%dHz\n", fll
->clk_ref_div
, freq_in
);
1744 /* Scale the output to give 90MHz<=Fvco<=100MHz */
1746 while (freq_out
* (fll
->outdiv
+ 1) < 90000000) {
1748 if (fll
->outdiv
> 63)
1751 freq_out
*= fll
->outdiv
+ 1;
1752 pr_debug("OUTDIV=%d, Fvco=%dHz\n", fll
->outdiv
, freq_out
);
1754 if (freq_in
> 1000000) {
1755 fll
->fll_fratio
= 0;
1756 } else if (freq_in
> 256000) {
1757 fll
->fll_fratio
= 1;
1759 } else if (freq_in
> 128000) {
1760 fll
->fll_fratio
= 2;
1762 } else if (freq_in
> 64000) {
1763 fll
->fll_fratio
= 3;
1766 fll
->fll_fratio
= 4;
1769 pr_debug("FLL_FRATIO=%d, Fref=%dHz\n", fll
->fll_fratio
, freq_in
);
1771 /* Now, calculate N.K */
1772 Ndiv
= freq_out
/ freq_in
;
1775 Nmod
= freq_out
% freq_in
;
1776 pr_debug("Nmod=%d\n", Nmod
);
1778 /* Calculate fractional part - scale up so we can round. */
1779 Kpart
= FIXED_FLL_SIZE
* (long long)Nmod
;
1781 do_div(Kpart
, freq_in
);
1783 K
= Kpart
& 0xFFFFFFFF;
1788 /* Move down to proper range now rounding is done */
1791 pr_debug("N=%x K=%x\n", fll
->n
, fll
->k
);
1796 static int wm8995_set_fll(struct snd_soc_dai
*dai
, int id
,
1797 int src
, unsigned int freq_in
,
1798 unsigned int freq_out
)
1800 struct snd_soc_codec
*codec
;
1801 struct wm8995_priv
*wm8995
;
1802 int reg_offset
, ret
;
1804 u16 reg
, aif1
, aif2
;
1807 wm8995
= snd_soc_codec_get_drvdata(codec
);
1809 aif1
= snd_soc_read(codec
, WM8995_AIF1_CLOCKING_1
)
1810 & WM8995_AIF1CLK_ENA
;
1812 aif2
= snd_soc_read(codec
, WM8995_AIF2_CLOCKING_1
)
1813 & WM8995_AIF2CLK_ENA
;
1830 /* Allow no source specification when stopping */
1834 case WM8995_FLL_SRC_MCLK1
:
1835 case WM8995_FLL_SRC_MCLK2
:
1836 case WM8995_FLL_SRC_LRCLK
:
1837 case WM8995_FLL_SRC_BCLK
:
1843 /* Are we changing anything? */
1844 if (wm8995
->fll
[id
].src
== src
&&
1845 wm8995
->fll
[id
].in
== freq_in
&& wm8995
->fll
[id
].out
== freq_out
)
1848 /* If we're stopping the FLL redo the old config - no
1849 * registers will actually be written but we avoid GCC flow
1850 * analysis bugs spewing warnings.
1853 ret
= wm8995_get_fll_config(&fll
, freq_in
, freq_out
);
1855 ret
= wm8995_get_fll_config(&fll
, wm8995
->fll
[id
].in
,
1856 wm8995
->fll
[id
].out
);
1860 /* Gate the AIF clocks while we reclock */
1861 snd_soc_update_bits(codec
, WM8995_AIF1_CLOCKING_1
,
1862 WM8995_AIF1CLK_ENA_MASK
, 0);
1863 snd_soc_update_bits(codec
, WM8995_AIF2_CLOCKING_1
,
1864 WM8995_AIF2CLK_ENA_MASK
, 0);
1866 /* We always need to disable the FLL while reconfiguring */
1867 snd_soc_update_bits(codec
, WM8995_FLL1_CONTROL_1
+ reg_offset
,
1868 WM8995_FLL1_ENA_MASK
, 0);
1870 reg
= (fll
.outdiv
<< WM8995_FLL1_OUTDIV_SHIFT
) |
1871 (fll
.fll_fratio
<< WM8995_FLL1_FRATIO_SHIFT
);
1872 snd_soc_update_bits(codec
, WM8995_FLL1_CONTROL_2
+ reg_offset
,
1873 WM8995_FLL1_OUTDIV_MASK
|
1874 WM8995_FLL1_FRATIO_MASK
, reg
);
1876 snd_soc_write(codec
, WM8995_FLL1_CONTROL_3
+ reg_offset
, fll
.k
);
1878 snd_soc_update_bits(codec
, WM8995_FLL1_CONTROL_4
+ reg_offset
,
1880 fll
.n
<< WM8995_FLL1_N_SHIFT
);
1882 snd_soc_update_bits(codec
, WM8995_FLL1_CONTROL_5
+ reg_offset
,
1883 WM8995_FLL1_REFCLK_DIV_MASK
|
1884 WM8995_FLL1_REFCLK_SRC_MASK
,
1885 (fll
.clk_ref_div
<< WM8995_FLL1_REFCLK_DIV_SHIFT
) |
1889 snd_soc_update_bits(codec
, WM8995_FLL1_CONTROL_1
+ reg_offset
,
1890 WM8995_FLL1_ENA_MASK
, WM8995_FLL1_ENA
);
1892 wm8995
->fll
[id
].in
= freq_in
;
1893 wm8995
->fll
[id
].out
= freq_out
;
1894 wm8995
->fll
[id
].src
= src
;
1896 /* Enable any gated AIF clocks */
1897 snd_soc_update_bits(codec
, WM8995_AIF1_CLOCKING_1
,
1898 WM8995_AIF1CLK_ENA_MASK
, aif1
);
1899 snd_soc_update_bits(codec
, WM8995_AIF2_CLOCKING_1
,
1900 WM8995_AIF2CLK_ENA_MASK
, aif2
);
1902 configure_clock(codec
);
1907 static int wm8995_set_dai_sysclk(struct snd_soc_dai
*dai
,
1908 int clk_id
, unsigned int freq
, int dir
)
1910 struct snd_soc_codec
*codec
;
1911 struct wm8995_priv
*wm8995
;
1914 wm8995
= snd_soc_codec_get_drvdata(codec
);
1921 /* AIF3 shares clocking with AIF1/2 */
1926 case WM8995_SYSCLK_MCLK1
:
1927 wm8995
->sysclk
[dai
->id
] = WM8995_SYSCLK_MCLK1
;
1928 wm8995
->mclk
[0] = freq
;
1929 dev_dbg(dai
->dev
, "AIF%d using MCLK1 at %uHz\n",
1932 case WM8995_SYSCLK_MCLK2
:
1933 wm8995
->sysclk
[dai
->id
] = WM8995_SYSCLK_MCLK2
;
1934 wm8995
->mclk
[1] = freq
;
1935 dev_dbg(dai
->dev
, "AIF%d using MCLK2 at %uHz\n",
1938 case WM8995_SYSCLK_FLL1
:
1939 wm8995
->sysclk
[dai
->id
] = WM8995_SYSCLK_FLL1
;
1940 dev_dbg(dai
->dev
, "AIF%d using FLL1\n", dai
->id
+ 1);
1942 case WM8995_SYSCLK_FLL2
:
1943 wm8995
->sysclk
[dai
->id
] = WM8995_SYSCLK_FLL2
;
1944 dev_dbg(dai
->dev
, "AIF%d using FLL2\n", dai
->id
+ 1);
1946 case WM8995_SYSCLK_OPCLK
:
1948 dev_err(dai
->dev
, "Unknown clock source %d\n", clk_id
);
1952 configure_clock(codec
);
1957 static int wm8995_set_bias_level(struct snd_soc_codec
*codec
,
1958 enum snd_soc_bias_level level
)
1960 struct wm8995_priv
*wm8995
;
1963 wm8995
= snd_soc_codec_get_drvdata(codec
);
1965 case SND_SOC_BIAS_ON
:
1966 case SND_SOC_BIAS_PREPARE
:
1968 case SND_SOC_BIAS_STANDBY
:
1969 if (snd_soc_codec_get_bias_level(codec
) == SND_SOC_BIAS_OFF
) {
1970 ret
= regulator_bulk_enable(ARRAY_SIZE(wm8995
->supplies
),
1975 ret
= regcache_sync(wm8995
->regmap
);
1978 "Failed to sync cache: %d\n", ret
);
1982 snd_soc_update_bits(codec
, WM8995_POWER_MANAGEMENT_1
,
1983 WM8995_BG_ENA_MASK
, WM8995_BG_ENA
);
1986 case SND_SOC_BIAS_OFF
:
1987 snd_soc_update_bits(codec
, WM8995_POWER_MANAGEMENT_1
,
1988 WM8995_BG_ENA_MASK
, 0);
1989 regulator_bulk_disable(ARRAY_SIZE(wm8995
->supplies
),
1997 static int wm8995_remove(struct snd_soc_codec
*codec
)
1999 struct wm8995_priv
*wm8995
;
2002 wm8995
= snd_soc_codec_get_drvdata(codec
);
2004 for (i
= 0; i
< ARRAY_SIZE(wm8995
->supplies
); ++i
)
2005 regulator_unregister_notifier(wm8995
->supplies
[i
].consumer
,
2006 &wm8995
->disable_nb
[i
]);
2008 regulator_bulk_free(ARRAY_SIZE(wm8995
->supplies
), wm8995
->supplies
);
2012 static int wm8995_probe(struct snd_soc_codec
*codec
)
2014 struct wm8995_priv
*wm8995
;
2018 wm8995
= snd_soc_codec_get_drvdata(codec
);
2019 wm8995
->codec
= codec
;
2021 for (i
= 0; i
< ARRAY_SIZE(wm8995
->supplies
); i
++)
2022 wm8995
->supplies
[i
].supply
= wm8995_supply_names
[i
];
2024 ret
= regulator_bulk_get(codec
->dev
, ARRAY_SIZE(wm8995
->supplies
),
2027 dev_err(codec
->dev
, "Failed to request supplies: %d\n", ret
);
2031 wm8995
->disable_nb
[0].notifier_call
= wm8995_regulator_event_0
;
2032 wm8995
->disable_nb
[1].notifier_call
= wm8995_regulator_event_1
;
2033 wm8995
->disable_nb
[2].notifier_call
= wm8995_regulator_event_2
;
2034 wm8995
->disable_nb
[3].notifier_call
= wm8995_regulator_event_3
;
2035 wm8995
->disable_nb
[4].notifier_call
= wm8995_regulator_event_4
;
2036 wm8995
->disable_nb
[5].notifier_call
= wm8995_regulator_event_5
;
2037 wm8995
->disable_nb
[6].notifier_call
= wm8995_regulator_event_6
;
2038 wm8995
->disable_nb
[7].notifier_call
= wm8995_regulator_event_7
;
2040 /* This should really be moved into the regulator core */
2041 for (i
= 0; i
< ARRAY_SIZE(wm8995
->supplies
); i
++) {
2042 ret
= regulator_register_notifier(wm8995
->supplies
[i
].consumer
,
2043 &wm8995
->disable_nb
[i
]);
2046 "Failed to register regulator notifier: %d\n",
2051 ret
= regulator_bulk_enable(ARRAY_SIZE(wm8995
->supplies
),
2054 dev_err(codec
->dev
, "Failed to enable supplies: %d\n", ret
);
2058 ret
= snd_soc_read(codec
, WM8995_SOFTWARE_RESET
);
2060 dev_err(codec
->dev
, "Failed to read device ID: %d\n", ret
);
2061 goto err_reg_enable
;
2064 if (ret
!= 0x8995) {
2065 dev_err(codec
->dev
, "Invalid device ID: %#x\n", ret
);
2067 goto err_reg_enable
;
2070 ret
= snd_soc_write(codec
, WM8995_SOFTWARE_RESET
, 0);
2072 dev_err(codec
->dev
, "Failed to issue reset: %d\n", ret
);
2073 goto err_reg_enable
;
2076 /* Latch volume updates (right only; we always do left then right). */
2077 snd_soc_update_bits(codec
, WM8995_AIF1_DAC1_RIGHT_VOLUME
,
2078 WM8995_AIF1DAC1_VU_MASK
, WM8995_AIF1DAC1_VU
);
2079 snd_soc_update_bits(codec
, WM8995_AIF1_DAC2_RIGHT_VOLUME
,
2080 WM8995_AIF1DAC2_VU_MASK
, WM8995_AIF1DAC2_VU
);
2081 snd_soc_update_bits(codec
, WM8995_AIF2_DAC_RIGHT_VOLUME
,
2082 WM8995_AIF2DAC_VU_MASK
, WM8995_AIF2DAC_VU
);
2083 snd_soc_update_bits(codec
, WM8995_AIF1_ADC1_RIGHT_VOLUME
,
2084 WM8995_AIF1ADC1_VU_MASK
, WM8995_AIF1ADC1_VU
);
2085 snd_soc_update_bits(codec
, WM8995_AIF1_ADC2_RIGHT_VOLUME
,
2086 WM8995_AIF1ADC2_VU_MASK
, WM8995_AIF1ADC2_VU
);
2087 snd_soc_update_bits(codec
, WM8995_AIF2_ADC_RIGHT_VOLUME
,
2088 WM8995_AIF2ADC_VU_MASK
, WM8995_AIF1ADC2_VU
);
2089 snd_soc_update_bits(codec
, WM8995_DAC1_RIGHT_VOLUME
,
2090 WM8995_DAC1_VU_MASK
, WM8995_DAC1_VU
);
2091 snd_soc_update_bits(codec
, WM8995_DAC2_RIGHT_VOLUME
,
2092 WM8995_DAC2_VU_MASK
, WM8995_DAC2_VU
);
2093 snd_soc_update_bits(codec
, WM8995_RIGHT_LINE_INPUT_1_VOLUME
,
2094 WM8995_IN1_VU_MASK
, WM8995_IN1_VU
);
2096 wm8995_update_class_w(codec
);
2101 regulator_bulk_disable(ARRAY_SIZE(wm8995
->supplies
), wm8995
->supplies
);
2103 regulator_bulk_free(ARRAY_SIZE(wm8995
->supplies
), wm8995
->supplies
);
2107 #define WM8995_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
2108 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
2110 static const struct snd_soc_dai_ops wm8995_aif1_dai_ops
= {
2111 .set_sysclk
= wm8995_set_dai_sysclk
,
2112 .set_fmt
= wm8995_set_dai_fmt
,
2113 .hw_params
= wm8995_hw_params
,
2114 .digital_mute
= wm8995_aif_mute
,
2115 .set_pll
= wm8995_set_fll
,
2116 .set_tristate
= wm8995_set_tristate
,
2119 static const struct snd_soc_dai_ops wm8995_aif2_dai_ops
= {
2120 .set_sysclk
= wm8995_set_dai_sysclk
,
2121 .set_fmt
= wm8995_set_dai_fmt
,
2122 .hw_params
= wm8995_hw_params
,
2123 .digital_mute
= wm8995_aif_mute
,
2124 .set_pll
= wm8995_set_fll
,
2125 .set_tristate
= wm8995_set_tristate
,
2128 static const struct snd_soc_dai_ops wm8995_aif3_dai_ops
= {
2129 .set_tristate
= wm8995_set_tristate
,
2132 static struct snd_soc_dai_driver wm8995_dai
[] = {
2134 .name
= "wm8995-aif1",
2136 .stream_name
= "AIF1 Playback",
2139 .rates
= SNDRV_PCM_RATE_8000_96000
,
2140 .formats
= WM8995_FORMATS
2143 .stream_name
= "AIF1 Capture",
2146 .rates
= SNDRV_PCM_RATE_8000_48000
,
2147 .formats
= WM8995_FORMATS
2149 .ops
= &wm8995_aif1_dai_ops
2152 .name
= "wm8995-aif2",
2154 .stream_name
= "AIF2 Playback",
2157 .rates
= SNDRV_PCM_RATE_8000_96000
,
2158 .formats
= WM8995_FORMATS
2161 .stream_name
= "AIF2 Capture",
2164 .rates
= SNDRV_PCM_RATE_8000_48000
,
2165 .formats
= WM8995_FORMATS
2167 .ops
= &wm8995_aif2_dai_ops
2170 .name
= "wm8995-aif3",
2172 .stream_name
= "AIF3 Playback",
2175 .rates
= SNDRV_PCM_RATE_8000_96000
,
2176 .formats
= WM8995_FORMATS
2179 .stream_name
= "AIF3 Capture",
2182 .rates
= SNDRV_PCM_RATE_8000_48000
,
2183 .formats
= WM8995_FORMATS
2185 .ops
= &wm8995_aif3_dai_ops
2189 static const struct snd_soc_codec_driver soc_codec_dev_wm8995
= {
2190 .probe
= wm8995_probe
,
2191 .remove
= wm8995_remove
,
2192 .set_bias_level
= wm8995_set_bias_level
,
2193 .idle_bias_off
= true,
2195 .component_driver
= {
2196 .controls
= wm8995_snd_controls
,
2197 .num_controls
= ARRAY_SIZE(wm8995_snd_controls
),
2198 .dapm_widgets
= wm8995_dapm_widgets
,
2199 .num_dapm_widgets
= ARRAY_SIZE(wm8995_dapm_widgets
),
2200 .dapm_routes
= wm8995_intercon
,
2201 .num_dapm_routes
= ARRAY_SIZE(wm8995_intercon
),
2205 static const struct regmap_config wm8995_regmap
= {
2209 .max_register
= WM8995_MAX_REGISTER
,
2210 .reg_defaults
= wm8995_reg_defaults
,
2211 .num_reg_defaults
= ARRAY_SIZE(wm8995_reg_defaults
),
2212 .volatile_reg
= wm8995_volatile
,
2213 .readable_reg
= wm8995_readable
,
2214 .cache_type
= REGCACHE_RBTREE
,
2217 #if defined(CONFIG_SPI_MASTER)
2218 static int wm8995_spi_probe(struct spi_device
*spi
)
2220 struct wm8995_priv
*wm8995
;
2223 wm8995
= devm_kzalloc(&spi
->dev
, sizeof(*wm8995
), GFP_KERNEL
);
2227 spi_set_drvdata(spi
, wm8995
);
2229 wm8995
->regmap
= devm_regmap_init_spi(spi
, &wm8995_regmap
);
2230 if (IS_ERR(wm8995
->regmap
)) {
2231 ret
= PTR_ERR(wm8995
->regmap
);
2232 dev_err(&spi
->dev
, "Failed to register regmap: %d\n", ret
);
2236 ret
= snd_soc_register_codec(&spi
->dev
,
2237 &soc_codec_dev_wm8995
, wm8995_dai
,
2238 ARRAY_SIZE(wm8995_dai
));
2242 static int wm8995_spi_remove(struct spi_device
*spi
)
2244 snd_soc_unregister_codec(&spi
->dev
);
2248 static struct spi_driver wm8995_spi_driver
= {
2252 .probe
= wm8995_spi_probe
,
2253 .remove
= wm8995_spi_remove
2257 #if IS_ENABLED(CONFIG_I2C)
2258 static int wm8995_i2c_probe(struct i2c_client
*i2c
,
2259 const struct i2c_device_id
*id
)
2261 struct wm8995_priv
*wm8995
;
2264 wm8995
= devm_kzalloc(&i2c
->dev
, sizeof(*wm8995
), GFP_KERNEL
);
2268 i2c_set_clientdata(i2c
, wm8995
);
2270 wm8995
->regmap
= devm_regmap_init_i2c(i2c
, &wm8995_regmap
);
2271 if (IS_ERR(wm8995
->regmap
)) {
2272 ret
= PTR_ERR(wm8995
->regmap
);
2273 dev_err(&i2c
->dev
, "Failed to register regmap: %d\n", ret
);
2277 ret
= snd_soc_register_codec(&i2c
->dev
,
2278 &soc_codec_dev_wm8995
, wm8995_dai
,
2279 ARRAY_SIZE(wm8995_dai
));
2281 dev_err(&i2c
->dev
, "Failed to register CODEC: %d\n", ret
);
2286 static int wm8995_i2c_remove(struct i2c_client
*client
)
2288 snd_soc_unregister_codec(&client
->dev
);
2292 static const struct i2c_device_id wm8995_i2c_id
[] = {
2297 MODULE_DEVICE_TABLE(i2c
, wm8995_i2c_id
);
2299 static struct i2c_driver wm8995_i2c_driver
= {
2303 .probe
= wm8995_i2c_probe
,
2304 .remove
= wm8995_i2c_remove
,
2305 .id_table
= wm8995_i2c_id
2309 static int __init
wm8995_modinit(void)
2313 #if IS_ENABLED(CONFIG_I2C)
2314 ret
= i2c_add_driver(&wm8995_i2c_driver
);
2316 printk(KERN_ERR
"Failed to register wm8995 I2C driver: %d\n",
2320 #if defined(CONFIG_SPI_MASTER)
2321 ret
= spi_register_driver(&wm8995_spi_driver
);
2323 printk(KERN_ERR
"Failed to register wm8995 SPI driver: %d\n",
2330 module_init(wm8995_modinit
);
2332 static void __exit
wm8995_exit(void)
2334 #if IS_ENABLED(CONFIG_I2C)
2335 i2c_del_driver(&wm8995_i2c_driver
);
2337 #if defined(CONFIG_SPI_MASTER)
2338 spi_unregister_driver(&wm8995_spi_driver
);
2342 module_exit(wm8995_exit
);
2344 MODULE_DESCRIPTION("ASoC WM8995 driver");
2345 MODULE_AUTHOR("Dimitris Papastamos <dp@opensource.wolfsonmicro.com>");
2346 MODULE_LICENSE("GPL");