]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blobdiff - sound/soc/codecs/wm8962.c
Merge remote-tracking branches 'asoc/topic/wm8961', 'asoc/topic/wm8962', 'asoc/topic...
[mirror_ubuntu-zesty-kernel.git] / sound / soc / codecs / wm8962.c
index 11d80f3b61372d357870b44432d5e1f1c9f6e25c..62af9dc59fc5866d8e66bea8dad7525ac69a1ded 100644 (file)
@@ -74,7 +74,7 @@ struct wm8962_priv {
        struct regulator_bulk_data supplies[WM8962_NUM_SUPPLIES];
        struct notifier_block disable_nb[WM8962_NUM_SUPPLIES];
 
-#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
+#if IS_ENABLED(CONFIG_INPUT)
        struct input_dev *beep;
        struct work_struct beep_work;
        int beep_rate;
@@ -1479,7 +1479,9 @@ static const DECLARE_TLV_DB_SCALE(eq_tlv, -1200, 100, 0);
 
 static int wm8962_dsp2_write_config(struct snd_soc_codec *codec)
 {
-       return regcache_sync_region(codec->control_data,
+       struct wm8962_priv *wm8962 = snd_soc_codec_get_drvdata(codec);
+
+       return regcache_sync_region(wm8962->regmap,
                                    WM8962_HDBASS_AI_1, WM8962_MAX_REGISTER);
 }
 
@@ -1658,16 +1660,16 @@ static const char *cap_hpf_mode_text[] = {
        "Hi-fi", "Application"
 };
 
-static const struct soc_enum cap_hpf_mode =
-       SOC_ENUM_SINGLE(WM8962_ADC_DAC_CONTROL_2, 10, 2, cap_hpf_mode_text);
+static SOC_ENUM_SINGLE_DECL(cap_hpf_mode,
+                           WM8962_ADC_DAC_CONTROL_2, 10, cap_hpf_mode_text);
 
 
 static const char *cap_lhpf_mode_text[] = {
        "LPF", "HPF"
 };
 
-static const struct soc_enum cap_lhpf_mode =
-       SOC_ENUM_SINGLE(WM8962_LHPF1, 1, 2, cap_lhpf_mode_text);
+static SOC_ENUM_SINGLE_DECL(cap_lhpf_mode,
+                           WM8962_LHPF1, 1, cap_lhpf_mode_text);
 
 static const struct snd_kcontrol_new wm8962_snd_controls[] = {
 SOC_DOUBLE("Input Mixer Switch", WM8962_INPUT_MIXER_CONTROL_1, 3, 2, 1, 1),
@@ -1758,6 +1760,9 @@ SOC_DOUBLE_R_TLV("EQ4 Volume", WM8962_EQ3, WM8962_EQ23,
                 WM8962_EQL_B4_GAIN_SHIFT, 31, 0, eq_tlv),
 SOC_DOUBLE_R_TLV("EQ5 Volume", WM8962_EQ3, WM8962_EQ23,
                 WM8962_EQL_B5_GAIN_SHIFT, 31, 0, eq_tlv),
+SND_SOC_BYTES("EQL Coefficients", WM8962_EQ4, 18),
+SND_SOC_BYTES("EQR Coefficients", WM8962_EQ24, 18),
+
 
 SOC_SINGLE("3D Switch", WM8962_THREED1, 0, 1, 0),
 SND_SOC_BYTES_MASK("3D Coefficients", WM8962_THREED1, 4, WM8962_THREED_ENA),
@@ -1775,6 +1780,11 @@ WM8962_DSP2_ENABLE("HPF2 Switch", WM8962_HPF2_ENA_SHIFT),
 SND_SOC_BYTES("HPF Coefficients", WM8962_LHPF2, 1),
 WM8962_DSP2_ENABLE("HD Bass Switch", WM8962_HDBASS_ENA_SHIFT),
 SND_SOC_BYTES("HD Bass Coefficients", WM8962_HDBASS_AI_1, 30),
+
+SOC_DOUBLE("ALC Switch", WM8962_ALC1, WM8962_ALCL_ENA_SHIFT,
+               WM8962_ALCR_ENA_SHIFT, 1, 0),
+SND_SOC_BYTES_MASK("ALC Coefficients", WM8962_ALC1, 4,
+               WM8962_ALCL_ENA_MASK | WM8962_ALCR_ENA_MASK),
 };
 
 static const struct snd_kcontrol_new wm8962_spk_mono_controls[] = {
@@ -1845,7 +1855,7 @@ static int cp_event(struct snd_soc_dapm_widget *w,
                break;
 
        default:
-               BUG();
+               WARN(1, "Invalid event %d\n", event);
                return -EINVAL;
        }
 
@@ -1937,7 +1947,7 @@ static int hp_event(struct snd_soc_dapm_widget *w,
                break;
 
        default:
-               BUG();
+               WARN(1, "Invalid event %d\n", event);
                return -EINVAL;
        
        }
@@ -1966,7 +1976,7 @@ static int out_pga_event(struct snd_soc_dapm_widget *w,
                reg = WM8962_SPKOUTL_VOLUME;
                break;
        default:
-               BUG();
+               WARN(1, "Invalid shift %d\n", w->shift);
                return -EINVAL;
        }
 
@@ -1974,7 +1984,7 @@ static int out_pga_event(struct snd_soc_dapm_widget *w,
        case SND_SOC_DAPM_POST_PMU:
                return snd_soc_write(codec, reg, snd_soc_read(codec, reg));
        default:
-               BUG();
+               WARN(1, "Invalid event %d\n", event);
                return -EINVAL;
        }
 }
@@ -1997,7 +2007,7 @@ static int dsp2_event(struct snd_soc_dapm_widget *w,
                break;
 
        default:
-               BUG();
+               WARN(1, "Invalid event %d\n", event);
                return -EINVAL;
        }
 
@@ -2006,40 +2016,40 @@ static int dsp2_event(struct snd_soc_dapm_widget *w,
 
 static const char *st_text[] = { "None", "Left", "Right" };
 
-static const struct soc_enum str_enum =
-       SOC_ENUM_SINGLE(WM8962_DAC_DSP_MIXING_1, 2, 3, st_text);
+static SOC_ENUM_SINGLE_DECL(str_enum,
+                           WM8962_DAC_DSP_MIXING_1, 2, st_text);
 
 static const struct snd_kcontrol_new str_mux =
        SOC_DAPM_ENUM("Right Sidetone", str_enum);
 
-static const struct soc_enum stl_enum =
-       SOC_ENUM_SINGLE(WM8962_DAC_DSP_MIXING_2, 2, 3, st_text);
+static SOC_ENUM_SINGLE_DECL(stl_enum,
+                           WM8962_DAC_DSP_MIXING_2, 2, st_text);
 
 static const struct snd_kcontrol_new stl_mux =
        SOC_DAPM_ENUM("Left Sidetone", stl_enum);
 
 static const char *outmux_text[] = { "DAC", "Mixer" };
 
-static const struct soc_enum spkoutr_enum =
-       SOC_ENUM_SINGLE(WM8962_SPEAKER_MIXER_2, 7, 2, outmux_text);
+static SOC_ENUM_SINGLE_DECL(spkoutr_enum,
+                           WM8962_SPEAKER_MIXER_2, 7, outmux_text);
 
 static const struct snd_kcontrol_new spkoutr_mux =
        SOC_DAPM_ENUM("SPKOUTR Mux", spkoutr_enum);
 
-static const struct soc_enum spkoutl_enum =
-       SOC_ENUM_SINGLE(WM8962_SPEAKER_MIXER_1, 7, 2, outmux_text);
+static SOC_ENUM_SINGLE_DECL(spkoutl_enum,
+                           WM8962_SPEAKER_MIXER_1, 7, outmux_text);
 
 static const struct snd_kcontrol_new spkoutl_mux =
        SOC_DAPM_ENUM("SPKOUTL Mux", spkoutl_enum);
 
-static const struct soc_enum hpoutr_enum =
-       SOC_ENUM_SINGLE(WM8962_HEADPHONE_MIXER_2, 7, 2, outmux_text);
+static SOC_ENUM_SINGLE_DECL(hpoutr_enum,
+                           WM8962_HEADPHONE_MIXER_2, 7, outmux_text);
 
 static const struct snd_kcontrol_new hpoutr_mux =
        SOC_DAPM_ENUM("HPOUTR Mux", hpoutr_enum);
 
-static const struct soc_enum hpoutl_enum =
-       SOC_ENUM_SINGLE(WM8962_HEADPHONE_MIXER_1, 7, 2, outmux_text);
+static SOC_ENUM_SINGLE_DECL(hpoutl_enum,
+                           WM8962_HEADPHONE_MIXER_1, 7, outmux_text);
 
 static const struct snd_kcontrol_new hpoutl_mux =
        SOC_DAPM_ENUM("HPOUTL Mux", hpoutl_enum);
@@ -2431,7 +2441,20 @@ static void wm8962_configure_bclk(struct snd_soc_codec *codec)
        snd_soc_update_bits(codec, WM8962_CLOCKING_4,
                            WM8962_SYSCLK_RATE_MASK, clocking4);
 
+       /* DSPCLK_DIV can be only generated correctly after enabling SYSCLK.
+        * So we here provisionally enable it and then disable it afterward
+        * if current bias_level hasn't reached SND_SOC_BIAS_ON.
+        */
+       if (codec->dapm.bias_level != SND_SOC_BIAS_ON)
+               snd_soc_update_bits(codec, WM8962_CLOCKING2,
+                               WM8962_SYSCLK_ENA_MASK, WM8962_SYSCLK_ENA);
+
        dspclk = snd_soc_read(codec, WM8962_CLOCKING1);
+
+       if (codec->dapm.bias_level != SND_SOC_BIAS_ON)
+               snd_soc_update_bits(codec, WM8962_CLOCKING2,
+                               WM8962_SYSCLK_ENA_MASK, 0);
+
        if (dspclk < 0) {
                dev_err(codec->dev, "Failed to read DSPCLK: %d\n", dspclk);
                return;
@@ -2863,9 +2886,13 @@ static int wm8962_set_fll(struct snd_soc_codec *codec, int fll_id, int source,
        snd_soc_write(codec, WM8962_FLL_CONTROL_7, fll_div.lambda);
        snd_soc_write(codec, WM8962_FLL_CONTROL_8, fll_div.n);
 
-       try_wait_for_completion(&wm8962->fll_lock);
+       reinit_completion(&wm8962->fll_lock);
 
-       pm_runtime_get_sync(codec->dev);
+       ret = pm_runtime_get_sync(codec->dev);
+       if (ret < 0) {
+               dev_err(codec->dev, "Failed to resume device: %d\n", ret);
+               return ret;
+       }
 
        snd_soc_update_bits(codec, WM8962_FLL_CONTROL_1,
                            WM8962_FLL_FRAC | WM8962_FLL_REFCLK_SRC_MASK |
@@ -2873,8 +2900,6 @@ static int wm8962_set_fll(struct snd_soc_codec *codec, int fll_id, int source,
 
        dev_dbg(codec->dev, "FLL configured for %dHz->%dHz\n", Fref, Fout);
 
-       ret = 0;
-
        /* This should be a massive overestimate but go even
         * higher if we'll error out
         */
@@ -2888,14 +2913,17 @@ static int wm8962_set_fll(struct snd_soc_codec *codec, int fll_id, int source,
 
        if (timeout == 0 && wm8962->irq) {
                dev_err(codec->dev, "FLL lock timed out");
-               ret = -ETIMEDOUT;
+               snd_soc_update_bits(codec, WM8962_FLL_CONTROL_1,
+                                   WM8962_FLL_ENA, 0);
+               pm_runtime_put(codec->dev);
+               return -ETIMEDOUT;
        }
 
        wm8962->fll_fref = Fref;
        wm8962->fll_fout = Fout;
        wm8962->fll_src = source;
 
-       return ret;
+       return 0;
 }
 
 static int wm8962_mute(struct snd_soc_dai *dai, int mute)
@@ -2982,9 +3010,16 @@ static irqreturn_t wm8962_irq(int irq, void *data)
        unsigned int active;
        int reg, ret;
 
+       ret = pm_runtime_get_sync(dev);
+       if (ret < 0) {
+               dev_err(dev, "Failed to resume: %d\n", ret);
+               return IRQ_NONE;
+       }
+
        ret = regmap_read(wm8962->regmap, WM8962_INTERRUPT_STATUS_2_MASK,
                          &mask);
        if (ret != 0) {
+               pm_runtime_put(dev);
                dev_err(dev, "Failed to read interrupt mask: %d\n",
                        ret);
                return IRQ_NONE;
@@ -2992,14 +3027,17 @@ static irqreturn_t wm8962_irq(int irq, void *data)
 
        ret = regmap_read(wm8962->regmap, WM8962_INTERRUPT_STATUS_2, &active);
        if (ret != 0) {
+               pm_runtime_put(dev);
                dev_err(dev, "Failed to read interrupt: %d\n", ret);
                return IRQ_NONE;
        }
 
        active &= ~mask;
 
-       if (!active)
+       if (!active) {
+               pm_runtime_put(dev);
                return IRQ_NONE;
+       }
 
        /* Acknowledge the interrupts */
        ret = regmap_write(wm8962->regmap, WM8962_INTERRUPT_STATUS_2, active);
@@ -3049,6 +3087,8 @@ static irqreturn_t wm8962_irq(int irq, void *data)
                                   msecs_to_jiffies(250));
        }
 
+       pm_runtime_put(dev);
+
        return IRQ_HANDLED;
 }
 
@@ -3068,6 +3108,7 @@ static irqreturn_t wm8962_irq(int irq, void *data)
 int wm8962_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack)
 {
        struct wm8962_priv *wm8962 = snd_soc_codec_get_drvdata(codec);
+       struct snd_soc_dapm_context *dapm = &codec->dapm;
        int irq_mask, enable;
 
        wm8962->jack = jack;
@@ -3088,19 +3129,23 @@ int wm8962_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack)
        snd_soc_jack_report(wm8962->jack, 0,
                            SND_JACK_MICROPHONE | SND_JACK_BTN_0);
 
+       snd_soc_dapm_mutex_lock(dapm);
+
        if (jack) {
-               snd_soc_dapm_force_enable_pin(&codec->dapm, "SYSCLK");
-               snd_soc_dapm_force_enable_pin(&codec->dapm, "MICBIAS");
+               snd_soc_dapm_force_enable_pin_unlocked(dapm, "SYSCLK");
+               snd_soc_dapm_force_enable_pin_unlocked(dapm, "MICBIAS");
        } else {
-               snd_soc_dapm_disable_pin(&codec->dapm, "SYSCLK");
-               snd_soc_dapm_disable_pin(&codec->dapm, "MICBIAS");
+               snd_soc_dapm_disable_pin_unlocked(dapm, "SYSCLK");
+               snd_soc_dapm_disable_pin_unlocked(dapm, "MICBIAS");
        }
 
+       snd_soc_dapm_mutex_unlock(dapm);
+
        return 0;
 }
 EXPORT_SYMBOL_GPL(wm8962_mic_detect);
 
-#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
+#if IS_ENABLED(CONFIG_INPUT)
 static int beep_rates[] = {
        500, 1000, 2000, 4000,
 };
@@ -3242,7 +3287,7 @@ static void wm8962_free_beep(struct snd_soc_codec *codec)
 }
 #endif
 
-static void wm8962_set_gpio_mode(struct snd_soc_codec *codec, int gpio)
+static void wm8962_set_gpio_mode(struct wm8962_priv *wm8962, int gpio)
 {
        int mask = 0;
        int val = 0;
@@ -3263,8 +3308,8 @@ static void wm8962_set_gpio_mode(struct snd_soc_codec *codec, int gpio)
        }
 
        if (mask)
-               snd_soc_update_bits(codec, WM8962_ANALOGUE_CLOCKING1,
-                                   mask, val);
+               regmap_update_bits(wm8962->regmap, WM8962_ANALOGUE_CLOCKING1,
+                                  mask, val);
 }
 
 #ifdef CONFIG_GPIOLIB
@@ -3276,7 +3321,6 @@ static inline struct wm8962_priv *gpio_to_wm8962(struct gpio_chip *chip)
 static int wm8962_gpio_request(struct gpio_chip *chip, unsigned offset)
 {
        struct wm8962_priv *wm8962 = gpio_to_wm8962(chip);
-       struct snd_soc_codec *codec = wm8962->codec;
 
        /* The WM8962 GPIOs aren't linearly numbered.  For simplicity
         * we export linear numbers and error out if the unsupported
@@ -3292,7 +3336,7 @@ static int wm8962_gpio_request(struct gpio_chip *chip, unsigned offset)
                return -EINVAL;
        }
 
-       wm8962_set_gpio_mode(codec, offset + 1);
+       wm8962_set_gpio_mode(wm8962, offset + 1);
 
        return 0;
 }
@@ -3376,8 +3420,7 @@ static int wm8962_probe(struct snd_soc_codec *codec)
 {
        int ret;
        struct wm8962_priv *wm8962 = snd_soc_codec_get_drvdata(codec);
-       struct wm8962_pdata *pdata = &wm8962->pdata;
-       int i, trigger, irq_pol;
+       int i;
        bool dmicclk, dmicdat;
 
        wm8962->codec = codec;
@@ -3409,75 +3452,6 @@ static int wm8962_probe(struct snd_soc_codec *codec)
                }
        }
 
-       /* SYSCLK defaults to on; make sure it is off so we can safely
-        * write to registers if the device is declocked.
-        */
-       snd_soc_update_bits(codec, WM8962_CLOCKING2, WM8962_SYSCLK_ENA, 0);
-
-       /* Ensure we have soft control over all registers */
-       snd_soc_update_bits(codec, WM8962_CLOCKING2,
-                           WM8962_CLKREG_OVD, WM8962_CLKREG_OVD);
-
-       /* Ensure that the oscillator and PLLs are disabled */
-       snd_soc_update_bits(codec, WM8962_PLL2,
-                           WM8962_OSC_ENA | WM8962_PLL2_ENA | WM8962_PLL3_ENA,
-                           0);
-
-       /* Apply static configuration for GPIOs */
-       for (i = 0; i < ARRAY_SIZE(pdata->gpio_init); i++)
-               if (pdata->gpio_init[i]) {
-                       wm8962_set_gpio_mode(codec, i + 1);
-                       snd_soc_write(codec, 0x200 + i,
-                                       pdata->gpio_init[i] & 0xffff);
-               }
-
-
-       /* Put the speakers into mono mode? */
-       if (pdata->spk_mono)
-               snd_soc_update_bits(codec, WM8962_CLASS_D_CONTROL_2,
-                               WM8962_SPK_MONO_MASK, WM8962_SPK_MONO);
-
-       /* Micbias setup, detection enable and detection
-        * threasholds. */
-       if (pdata->mic_cfg)
-               snd_soc_update_bits(codec, WM8962_ADDITIONAL_CONTROL_4,
-                                   WM8962_MICDET_ENA |
-                                   WM8962_MICDET_THR_MASK |
-                                   WM8962_MICSHORT_THR_MASK |
-                                   WM8962_MICBIAS_LVL,
-                                   pdata->mic_cfg);
-
-       /* Latch volume update bits */
-       snd_soc_update_bits(codec, WM8962_LEFT_INPUT_VOLUME,
-                           WM8962_IN_VU, WM8962_IN_VU);
-       snd_soc_update_bits(codec, WM8962_RIGHT_INPUT_VOLUME,
-                           WM8962_IN_VU, WM8962_IN_VU);
-       snd_soc_update_bits(codec, WM8962_LEFT_ADC_VOLUME,
-                           WM8962_ADC_VU, WM8962_ADC_VU);
-       snd_soc_update_bits(codec, WM8962_RIGHT_ADC_VOLUME,
-                           WM8962_ADC_VU, WM8962_ADC_VU);
-       snd_soc_update_bits(codec, WM8962_LEFT_DAC_VOLUME,
-                           WM8962_DAC_VU, WM8962_DAC_VU);
-       snd_soc_update_bits(codec, WM8962_RIGHT_DAC_VOLUME,
-                           WM8962_DAC_VU, WM8962_DAC_VU);
-       snd_soc_update_bits(codec, WM8962_SPKOUTL_VOLUME,
-                           WM8962_SPKOUT_VU, WM8962_SPKOUT_VU);
-       snd_soc_update_bits(codec, WM8962_SPKOUTR_VOLUME,
-                           WM8962_SPKOUT_VU, WM8962_SPKOUT_VU);
-       snd_soc_update_bits(codec, WM8962_HPOUTL_VOLUME,
-                           WM8962_HPOUT_VU, WM8962_HPOUT_VU);
-       snd_soc_update_bits(codec, WM8962_HPOUTR_VOLUME,
-                           WM8962_HPOUT_VU, WM8962_HPOUT_VU);
-
-       /* Stereo control for EQ */
-       snd_soc_update_bits(codec, WM8962_EQ1, WM8962_EQ_SHARED_COEFF, 0);
-
-       /* Don't debouce interrupts so we don't need SYSCLK */
-       snd_soc_update_bits(codec, WM8962_IRQ_DEBOUNCE,
-                           WM8962_FLL_LOCK_DB | WM8962_PLL3_LOCK_DB |
-                           WM8962_PLL2_LOCK_DB | WM8962_TEMP_SHUT_DB,
-                           0);
-
        wm8962_add_widgets(codec);
 
        /* Save boards having to disable DMIC when not in use */
@@ -3506,36 +3480,6 @@ static int wm8962_probe(struct snd_soc_codec *codec)
        wm8962_init_beep(codec);
        wm8962_init_gpio(codec);
 
-       if (wm8962->irq) {
-               if (pdata->irq_active_low) {
-                       trigger = IRQF_TRIGGER_LOW;
-                       irq_pol = WM8962_IRQ_POL;
-               } else {
-                       trigger = IRQF_TRIGGER_HIGH;
-                       irq_pol = 0;
-               }
-
-               snd_soc_update_bits(codec, WM8962_INTERRUPT_CONTROL,
-                                   WM8962_IRQ_POL, irq_pol);
-
-               ret = request_threaded_irq(wm8962->irq, NULL, wm8962_irq,
-                                          trigger | IRQF_ONESHOT,
-                                          "wm8962", codec->dev);
-               if (ret != 0) {
-                       dev_err(codec->dev, "Failed to request IRQ %d: %d\n",
-                               wm8962->irq, ret);
-                       wm8962->irq = 0;
-                       /* Non-fatal */
-               } else {
-                       /* Enable some IRQs by default */
-                       snd_soc_update_bits(codec,
-                                           WM8962_INTERRUPT_STATUS_2_MASK,
-                                           WM8962_FLL_LOCK_EINT |
-                                           WM8962_TEMP_SHUT_EINT |
-                                           WM8962_FIFOS_ERR_EINT, 0);
-               }
-       }
-
        return 0;
 }
 
@@ -3544,9 +3488,6 @@ static int wm8962_remove(struct snd_soc_codec *codec)
        struct wm8962_priv *wm8962 = snd_soc_codec_get_drvdata(codec);
        int i;
 
-       if (wm8962->irq)
-               free_irq(wm8962->irq, codec);
-
        cancel_delayed_work_sync(&wm8962->mic_work);
 
        wm8962_free_gpio(codec);
@@ -3619,7 +3560,7 @@ static int wm8962_i2c_probe(struct i2c_client *i2c,
        struct wm8962_pdata *pdata = dev_get_platdata(&i2c->dev);
        struct wm8962_priv *wm8962;
        unsigned int reg;
-       int ret, i;
+       int ret, i, irq_pol, trigger;
 
        wm8962 = devm_kzalloc(&i2c->dev, sizeof(struct wm8962_priv),
                              GFP_KERNEL);
@@ -3704,6 +3645,77 @@ static int wm8962_i2c_probe(struct i2c_client *i2c,
                goto err_enable;
        }
 
+       /* SYSCLK defaults to on; make sure it is off so we can safely
+        * write to registers if the device is declocked.
+        */
+       regmap_update_bits(wm8962->regmap, WM8962_CLOCKING2,
+                          WM8962_SYSCLK_ENA, 0);
+
+       /* Ensure we have soft control over all registers */
+       regmap_update_bits(wm8962->regmap, WM8962_CLOCKING2,
+                          WM8962_CLKREG_OVD, WM8962_CLKREG_OVD);
+
+       /* Ensure that the oscillator and PLLs are disabled */
+       regmap_update_bits(wm8962->regmap, WM8962_PLL2,
+                          WM8962_OSC_ENA | WM8962_PLL2_ENA | WM8962_PLL3_ENA,
+                          0);
+
+       /* Apply static configuration for GPIOs */
+       for (i = 0; i < ARRAY_SIZE(wm8962->pdata.gpio_init); i++)
+               if (wm8962->pdata.gpio_init[i]) {
+                       wm8962_set_gpio_mode(wm8962, i + 1);
+                       regmap_write(wm8962->regmap, 0x200 + i,
+                                    wm8962->pdata.gpio_init[i] & 0xffff);
+               }
+
+
+       /* Put the speakers into mono mode? */
+       if (wm8962->pdata.spk_mono)
+               regmap_update_bits(wm8962->regmap, WM8962_CLASS_D_CONTROL_2,
+                                  WM8962_SPK_MONO_MASK, WM8962_SPK_MONO);
+
+       /* Micbias setup, detection enable and detection
+        * threasholds. */
+       if (wm8962->pdata.mic_cfg)
+               regmap_update_bits(wm8962->regmap, WM8962_ADDITIONAL_CONTROL_4,
+                                  WM8962_MICDET_ENA |
+                                  WM8962_MICDET_THR_MASK |
+                                  WM8962_MICSHORT_THR_MASK |
+                                  WM8962_MICBIAS_LVL,
+                                  wm8962->pdata.mic_cfg);
+
+       /* Latch volume update bits */
+       regmap_update_bits(wm8962->regmap, WM8962_LEFT_INPUT_VOLUME,
+                          WM8962_IN_VU, WM8962_IN_VU);
+       regmap_update_bits(wm8962->regmap, WM8962_RIGHT_INPUT_VOLUME,
+                          WM8962_IN_VU, WM8962_IN_VU);
+       regmap_update_bits(wm8962->regmap, WM8962_LEFT_ADC_VOLUME,
+                          WM8962_ADC_VU, WM8962_ADC_VU);
+       regmap_update_bits(wm8962->regmap, WM8962_RIGHT_ADC_VOLUME,
+                          WM8962_ADC_VU, WM8962_ADC_VU);
+       regmap_update_bits(wm8962->regmap, WM8962_LEFT_DAC_VOLUME,
+                          WM8962_DAC_VU, WM8962_DAC_VU);
+       regmap_update_bits(wm8962->regmap, WM8962_RIGHT_DAC_VOLUME,
+                          WM8962_DAC_VU, WM8962_DAC_VU);
+       regmap_update_bits(wm8962->regmap, WM8962_SPKOUTL_VOLUME,
+                          WM8962_SPKOUT_VU, WM8962_SPKOUT_VU);
+       regmap_update_bits(wm8962->regmap, WM8962_SPKOUTR_VOLUME,
+                          WM8962_SPKOUT_VU, WM8962_SPKOUT_VU);
+       regmap_update_bits(wm8962->regmap, WM8962_HPOUTL_VOLUME,
+                          WM8962_HPOUT_VU, WM8962_HPOUT_VU);
+       regmap_update_bits(wm8962->regmap, WM8962_HPOUTR_VOLUME,
+                          WM8962_HPOUT_VU, WM8962_HPOUT_VU);
+
+       /* Stereo control for EQ */
+       regmap_update_bits(wm8962->regmap, WM8962_EQ1,
+                          WM8962_EQ_SHARED_COEFF, 0);
+
+       /* Don't debouce interrupts so we don't need SYSCLK */
+       regmap_update_bits(wm8962->regmap, WM8962_IRQ_DEBOUNCE,
+                          WM8962_FLL_LOCK_DB | WM8962_PLL3_LOCK_DB |
+                          WM8962_PLL2_LOCK_DB | WM8962_TEMP_SHUT_DB,
+                          0);
+
        if (wm8962->pdata.in4_dc_measure) {
                ret = regmap_register_patch(wm8962->regmap,
                                            wm8962_dc_measure,
@@ -3714,6 +3726,37 @@ static int wm8962_i2c_probe(struct i2c_client *i2c,
                                ret);
        }
 
+       if (wm8962->irq) {
+               if (wm8962->pdata.irq_active_low) {
+                       trigger = IRQF_TRIGGER_LOW;
+                       irq_pol = WM8962_IRQ_POL;
+               } else {
+                       trigger = IRQF_TRIGGER_HIGH;
+                       irq_pol = 0;
+               }
+
+               regmap_update_bits(wm8962->regmap, WM8962_INTERRUPT_CONTROL,
+                                  WM8962_IRQ_POL, irq_pol);
+
+               ret = devm_request_threaded_irq(&i2c->dev, wm8962->irq, NULL,
+                                               wm8962_irq,
+                                               trigger | IRQF_ONESHOT,
+                                               "wm8962", &i2c->dev);
+               if (ret != 0) {
+                       dev_err(&i2c->dev, "Failed to request IRQ %d: %d\n",
+                               wm8962->irq, ret);
+                       wm8962->irq = 0;
+                       /* Non-fatal */
+               } else {
+                       /* Enable some IRQs by default */
+                       regmap_update_bits(wm8962->regmap,
+                                          WM8962_INTERRUPT_STATUS_2_MASK,
+                                          WM8962_FLL_LOCK_EINT |
+                                          WM8962_TEMP_SHUT_EINT |
+                                          WM8962_FIFOS_ERR_EINT, 0);
+               }
+       }
+
        pm_runtime_enable(&i2c->dev);
        pm_request_idle(&i2c->dev);
 
@@ -3722,6 +3765,8 @@ static int wm8962_i2c_probe(struct i2c_client *i2c,
        if (ret < 0)
                goto err_enable;
 
+       regcache_cache_only(wm8962->regmap, true);
+
        /* The drivers should power up as needed */
        regulator_bulk_disable(ARRAY_SIZE(wm8962->supplies), wm8962->supplies);