59
53
WM8994_AIF2_EQ_GAINS_1,
62
struct wm8994_micdet {
63
struct snd_soc_jack *jack;
68
/* codec private data */
70
struct wm_hubs_data hubs;
71
enum snd_soc_control_type control_type;
73
struct snd_soc_codec *codec;
78
struct fll_config fll[2], fll_suspend[2];
85
/* Platform dependant DRC configuration */
86
const char **drc_texts;
87
int drc_cfg[WM8994_NUM_DRC];
88
struct soc_enum drc_enum;
90
/* Platform dependant ReTune mobile configuration */
91
int num_retune_mobile_texts;
92
const char **retune_mobile_texts;
93
int retune_mobile_cfg[WM8994_NUM_EQ];
94
struct soc_enum retune_mobile_enum;
96
/* Platform dependant MBC configuration */
98
const char **mbc_texts;
99
struct soc_enum mbc_enum;
101
struct wm8994_micdet micdet[2];
103
wm8958_micdet_cb jack_cb;
109
struct wm8994_pdata *pdata;
111
unsigned int aif1clk_enable:1;
112
unsigned int aif2clk_enable:1;
114
unsigned int aif1clk_disable:1;
115
unsigned int aif2clk_disable:1;
118
static int wm8994_readable(unsigned int reg)
56
static int wm8994_readable(struct snd_soc_codec *codec, unsigned int reg)
58
struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
59
struct wm8994 *control = wm8994->control_data;
121
62
case WM8994_GPIO_1:
122
63
case WM8994_GPIO_2:
575
525
static const struct soc_enum adc_osr =
576
526
SOC_ENUM_SINGLE(WM8994_OVERSAMPLING, 1, 2, osr_text);
578
static void wm8958_mbc_apply(struct snd_soc_codec *codec, int mbc, int start)
580
struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
581
struct wm8994_pdata *pdata = wm8994->pdata;
582
int pwr_reg = snd_soc_read(codec, WM8994_POWER_MANAGEMENT_5);
583
int ena, reg, aif, i;
587
pwr_reg &= (WM8994_AIF1DAC1L_ENA | WM8994_AIF1DAC1R_ENA);
591
pwr_reg &= (WM8994_AIF1DAC2L_ENA | WM8994_AIF1DAC2R_ENA);
595
pwr_reg &= (WM8994_AIF2DACL_ENA | WM8994_AIF2DACR_ENA);
603
/* We can only enable the MBC if the AIF is enabled and we
604
* want it to be enabled. */
605
ena = pwr_reg && wm8994->mbc_ena[mbc];
607
reg = snd_soc_read(codec, WM8958_DSP2_PROGRAM);
609
dev_dbg(codec->dev, "MBC %d startup: %d, power: %x, DSP: %x\n",
610
mbc, start, pwr_reg, reg);
613
/* If the DSP is already running then noop */
614
if (reg & WM8958_DSP2_ENA)
617
/* Switch the clock over to the appropriate AIF */
618
snd_soc_update_bits(codec, WM8994_CLOCKING_1,
619
WM8958_DSP2CLK_SRC | WM8958_DSP2CLK_ENA,
620
aif << WM8958_DSP2CLK_SRC_SHIFT |
623
snd_soc_update_bits(codec, WM8958_DSP2_PROGRAM,
624
WM8958_DSP2_ENA, WM8958_DSP2_ENA);
626
/* If we've got user supplied MBC settings use them */
627
if (pdata && pdata->num_mbc_cfgs) {
628
struct wm8958_mbc_cfg *cfg
629
= &pdata->mbc_cfgs[wm8994->mbc_cfg];
631
for (i = 0; i < ARRAY_SIZE(cfg->coeff_regs); i++)
632
snd_soc_write(codec, i + WM8958_MBC_BAND_1_K_1,
635
for (i = 0; i < ARRAY_SIZE(cfg->cutoff_regs); i++)
637
i + WM8958_MBC_BAND_2_LOWER_CUTOFF_C1_1,
638
cfg->cutoff_regs[i]);
642
snd_soc_write(codec, WM8958_DSP2_EXECCONTROL,
646
snd_soc_update_bits(codec, WM8958_DSP2_CONFIG,
647
WM8958_MBC_ENA | WM8958_MBC_SEL_MASK,
648
mbc << WM8958_MBC_SEL_SHIFT |
651
/* If the DSP is already stopped then noop */
652
if (!(reg & WM8958_DSP2_ENA))
655
snd_soc_update_bits(codec, WM8958_DSP2_CONFIG,
657
snd_soc_update_bits(codec, WM8958_DSP2_PROGRAM,
659
snd_soc_update_bits(codec, WM8994_CLOCKING_1,
660
WM8958_DSP2CLK_ENA, 0);
664
static int wm8958_aif_ev(struct snd_soc_dapm_widget *w,
665
struct snd_kcontrol *kcontrol, int event)
667
struct snd_soc_codec *codec = w->codec;
689
case SND_SOC_DAPM_POST_PMU:
690
wm8958_mbc_apply(codec, mbc, 1);
692
case SND_SOC_DAPM_POST_PMD:
693
wm8958_mbc_apply(codec, mbc, 0);
700
static int wm8958_put_mbc_enum(struct snd_kcontrol *kcontrol,
701
struct snd_ctl_elem_value *ucontrol)
703
struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
704
struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
705
struct wm8994_pdata *pdata = wm8994->pdata;
706
int value = ucontrol->value.integer.value[0];
709
/* Don't allow on the fly reconfiguration */
710
reg = snd_soc_read(codec, WM8994_CLOCKING_1);
711
if (reg < 0 || reg & WM8958_DSP2CLK_ENA)
714
if (value >= pdata->num_mbc_cfgs)
717
wm8994->mbc_cfg = value;
722
static int wm8958_get_mbc_enum(struct snd_kcontrol *kcontrol,
723
struct snd_ctl_elem_value *ucontrol)
725
struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
726
struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
728
ucontrol->value.enumerated.item[0] = wm8994->mbc_cfg;
733
static int wm8958_mbc_info(struct snd_kcontrol *kcontrol,
734
struct snd_ctl_elem_info *uinfo)
736
uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
738
uinfo->value.integer.min = 0;
739
uinfo->value.integer.max = 1;
743
static int wm8958_mbc_get(struct snd_kcontrol *kcontrol,
744
struct snd_ctl_elem_value *ucontrol)
746
int mbc = kcontrol->private_value;
747
struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
748
struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
750
ucontrol->value.integer.value[0] = wm8994->mbc_ena[mbc];
755
static int wm8958_mbc_put(struct snd_kcontrol *kcontrol,
756
struct snd_ctl_elem_value *ucontrol)
758
int mbc = kcontrol->private_value;
760
struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
761
struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
763
if (ucontrol->value.integer.value[0] > 1)
766
for (i = 0; i < ARRAY_SIZE(wm8994->mbc_ena); i++) {
767
if (mbc != i && wm8994->mbc_ena[i]) {
768
dev_dbg(codec->dev, "MBC %d active already\n", mbc);
773
wm8994->mbc_ena[mbc] = ucontrol->value.integer.value[0];
775
wm8958_mbc_apply(codec, mbc, wm8994->mbc_ena[mbc]);
780
#define WM8958_MBC_SWITCH(xname, xval) {\
781
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
782
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,\
783
.info = wm8958_mbc_info, \
784
.get = wm8958_mbc_get, .put = wm8958_mbc_put, \
785
.private_value = xval }
787
528
static const struct snd_kcontrol_new wm8994_snd_controls[] = {
788
529
SOC_DOUBLE_R_TLV("AIF1ADC1 Volume", WM8994_AIF1_ADC1_LEFT_VOLUME,
789
530
WM8994_AIF1_ADC1_RIGHT_VOLUME,
2850
2635
dev_dbg(codec->dev, "%d ReTune Mobile configurations\n",
2851
2636
pdata->num_retune_mobile_cfgs);
2853
if (pdata->num_mbc_cfgs) {
2854
struct snd_kcontrol_new control[] = {
2855
SOC_ENUM_EXT("MBC Mode", wm8994->mbc_enum,
2856
wm8958_get_mbc_enum, wm8958_put_mbc_enum),
2859
/* We need an array of texts for the enum API */
2860
wm8994->mbc_texts = kmalloc(sizeof(char *)
2861
* pdata->num_mbc_cfgs, GFP_KERNEL);
2862
if (!wm8994->mbc_texts) {
2863
dev_err(wm8994->codec->dev,
2864
"Failed to allocate %d MBC config texts\n",
2865
pdata->num_mbc_cfgs);
2869
for (i = 0; i < pdata->num_mbc_cfgs; i++)
2870
wm8994->mbc_texts[i] = pdata->mbc_cfgs[i].name;
2872
wm8994->mbc_enum.max = pdata->num_mbc_cfgs;
2873
wm8994->mbc_enum.texts = wm8994->mbc_texts;
2875
ret = snd_soc_add_controls(wm8994->codec, control, 1);
2877
dev_err(wm8994->codec->dev,
2878
"Failed to add MBC mode controls: %d\n", ret);
2881
2638
if (pdata->num_retune_mobile_cfgs)
2882
2639
wm8994_handle_retune_mobile_pdata(wm8994);
2884
2641
snd_soc_add_controls(wm8994->codec, wm8994_eq_controls,
2885
2642
ARRAY_SIZE(wm8994_eq_controls));
2644
for (i = 0; i < ARRAY_SIZE(pdata->micbias); i++) {
2645
if (pdata->micbias[i]) {
2646
snd_soc_write(codec, WM8958_MICBIAS1 + i,
2647
pdata->micbias[i] & 0xffff);
2993
2757
int report = 0;
2995
2759
/* If nothing present then clear our statuses */
2996
if (!(status & WM8958_MICD_STS)) {
2997
wm8994->jack_is_video = false;
2998
wm8994->jack_is_mic = false;
2760
if (!(status & WM8958_MICD_STS))
3002
/* Assume anything over 475 ohms is a microphone and remember
3003
* that we've seen one (since buttons override it) */
3005
wm8994->jack_is_mic = true;
3006
if (wm8994->jack_is_mic)
3007
report |= SND_JACK_MICROPHONE;
3009
/* Video has an impedence of approximately 75 ohms; assume
3010
* this isn't used as a button and remember it since buttons
3013
wm8994->jack_is_video = true;
3014
if (wm8994->jack_is_video)
3015
report |= SND_JACK_VIDEOOUT;
2763
report = SND_JACK_MICROPHONE;
3017
2765
/* Everything else is buttons; just assign slots */
3019
2767
report |= SND_JACK_BTN_0;
3021
report |= SND_JACK_BTN_1;
3023
report |= SND_JACK_BTN_2;
3025
report |= SND_JACK_BTN_3;
3027
report |= SND_JACK_BTN_4;
3029
report |= SND_JACK_BTN_5;
3032
2770
snd_soc_jack_report(wm8994->micdet[0].jack, report,
3033
SND_JACK_BTN_0 | SND_JACK_BTN_1 | SND_JACK_BTN_2 |
3034
SND_JACK_BTN_3 | SND_JACK_BTN_4 | SND_JACK_BTN_5 |
3035
SND_JACK_MICROPHONE | SND_JACK_VIDEOOUT);
2771
SND_JACK_BTN_0 | SND_JACK_MICROPHONE);
3259
3006
wm8994_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
3261
3008
/* Latch volume updates (right only; we always do left then right). */
3009
snd_soc_update_bits(codec, WM8994_AIF1_DAC1_LEFT_VOLUME,
3010
WM8994_AIF1DAC1_VU, WM8994_AIF1DAC1_VU);
3262
3011
snd_soc_update_bits(codec, WM8994_AIF1_DAC1_RIGHT_VOLUME,
3263
3012
WM8994_AIF1DAC1_VU, WM8994_AIF1DAC1_VU);
3013
snd_soc_update_bits(codec, WM8994_AIF1_DAC2_LEFT_VOLUME,
3014
WM8994_AIF1DAC2_VU, WM8994_AIF1DAC2_VU);
3264
3015
snd_soc_update_bits(codec, WM8994_AIF1_DAC2_RIGHT_VOLUME,
3265
3016
WM8994_AIF1DAC2_VU, WM8994_AIF1DAC2_VU);
3017
snd_soc_update_bits(codec, WM8994_AIF2_DAC_LEFT_VOLUME,
3018
WM8994_AIF2DAC_VU, WM8994_AIF2DAC_VU);
3266
3019
snd_soc_update_bits(codec, WM8994_AIF2_DAC_RIGHT_VOLUME,
3267
3020
WM8994_AIF2DAC_VU, WM8994_AIF2DAC_VU);
3021
snd_soc_update_bits(codec, WM8994_AIF1_ADC1_LEFT_VOLUME,
3022
WM8994_AIF1ADC1_VU, WM8994_AIF1ADC1_VU);
3268
3023
snd_soc_update_bits(codec, WM8994_AIF1_ADC1_RIGHT_VOLUME,
3269
3024
WM8994_AIF1ADC1_VU, WM8994_AIF1ADC1_VU);
3025
snd_soc_update_bits(codec, WM8994_AIF1_ADC2_LEFT_VOLUME,
3026
WM8994_AIF1ADC2_VU, WM8994_AIF1ADC2_VU);
3270
3027
snd_soc_update_bits(codec, WM8994_AIF1_ADC2_RIGHT_VOLUME,
3271
3028
WM8994_AIF1ADC2_VU, WM8994_AIF1ADC2_VU);
3029
snd_soc_update_bits(codec, WM8994_AIF2_ADC_LEFT_VOLUME,
3030
WM8994_AIF2ADC_VU, WM8994_AIF1ADC2_VU);
3272
3031
snd_soc_update_bits(codec, WM8994_AIF2_ADC_RIGHT_VOLUME,
3273
3032
WM8994_AIF2ADC_VU, WM8994_AIF1ADC2_VU);
3033
snd_soc_update_bits(codec, WM8994_DAC1_LEFT_VOLUME,
3034
WM8994_DAC1_VU, WM8994_DAC1_VU);
3274
3035
snd_soc_update_bits(codec, WM8994_DAC1_RIGHT_VOLUME,
3275
3036
WM8994_DAC1_VU, WM8994_DAC1_VU);
3037
snd_soc_update_bits(codec, WM8994_DAC2_LEFT_VOLUME,
3038
WM8994_DAC2_VU, WM8994_DAC2_VU);
3276
3039
snd_soc_update_bits(codec, WM8994_DAC2_RIGHT_VOLUME,
3277
3040
WM8994_DAC2_VU, WM8994_DAC2_VU);
3326
3089
snd_soc_add_controls(codec, wm8958_snd_controls,
3327
3090
ARRAY_SIZE(wm8958_snd_controls));
3328
snd_soc_dapm_new_controls(dapm, wm8994_lateclk_widgets,
3329
ARRAY_SIZE(wm8994_lateclk_widgets));
3330
snd_soc_dapm_new_controls(dapm, wm8994_adc_widgets,
3331
ARRAY_SIZE(wm8994_adc_widgets));
3332
snd_soc_dapm_new_controls(dapm, wm8994_dac_widgets,
3333
ARRAY_SIZE(wm8994_dac_widgets));
3334
3091
snd_soc_dapm_new_controls(dapm, wm8958_dapm_widgets,
3335
3092
ARRAY_SIZE(wm8958_dapm_widgets));
3093
if (wm8994->revision < 1) {
3094
snd_soc_dapm_new_controls(dapm, wm8994_lateclk_revd_widgets,
3095
ARRAY_SIZE(wm8994_lateclk_revd_widgets));
3096
snd_soc_dapm_new_controls(dapm, wm8994_adc_revd_widgets,
3097
ARRAY_SIZE(wm8994_adc_revd_widgets));
3098
snd_soc_dapm_new_controls(dapm, wm8994_dac_revd_widgets,
3099
ARRAY_SIZE(wm8994_dac_revd_widgets));
3101
snd_soc_dapm_new_controls(dapm, wm8994_lateclk_widgets,
3102
ARRAY_SIZE(wm8994_lateclk_widgets));
3103
snd_soc_dapm_new_controls(dapm, wm8994_adc_widgets,
3104
ARRAY_SIZE(wm8994_adc_widgets));
3105
snd_soc_dapm_new_controls(dapm, wm8994_dac_widgets,
3106
ARRAY_SIZE(wm8994_dac_widgets));