ASoC: Optimise configuration of WM8903 DC servo
[sfrench/cifs-2.6.git] / sound / soc / codecs / wm8903.c
index 8cf571f1a803d3ae7b1b1e561aedb01470cc19dd..de0a58507202ed7cb96964c43213560a54b09ef6 100644 (file)
@@ -217,7 +217,6 @@ struct wm8903_priv {
        int sysclk;
 
        /* Reference counts */
-       int charge_pump_users;
        int class_w_users;
        int playback_active;
        int capture_active;
@@ -373,6 +372,15 @@ static void wm8903_reset(struct snd_soc_codec *codec)
 #define WM8903_OUTPUT_INT   0x2
 #define WM8903_OUTPUT_IN    0x1
 
+static int wm8903_cp_event(struct snd_soc_dapm_widget *w,
+                          struct snd_kcontrol *kcontrol, int event)
+{
+       WARN_ON(event != SND_SOC_DAPM_POST_PMU);
+       mdelay(4);
+
+       return 0;
+}
+
 /*
  * Event for headphone and line out amplifier power changes.  Special
  * power up/down sequences are required in order to maximise pop/click
@@ -382,12 +390,9 @@ static int wm8903_output_event(struct snd_soc_dapm_widget *w,
                               struct snd_kcontrol *kcontrol, int event)
 {
        struct snd_soc_codec *codec = w->codec;
-       struct wm8903_priv *wm8903 = codec->private_data;
-       struct i2c_client *i2c = codec->control_data;
        u16 val;
        u16 reg;
        int shift;
-       u16 cp_reg = wm8903_read(codec, WM8903_CHARGE_PUMP_0);
 
        switch (w->reg) {
        case WM8903_POWER_MANAGEMENT_2:
@@ -419,18 +424,6 @@ static int wm8903_output_event(struct snd_soc_dapm_widget *w,
                /* Short the output */
                val &= ~(WM8903_OUTPUT_SHORT << shift);
                wm8903_write(codec, reg, val);
-
-               wm8903->charge_pump_users++;
-
-               dev_dbg(&i2c->dev, "Charge pump use count now %d\n",
-                       wm8903->charge_pump_users);
-
-               if (wm8903->charge_pump_users == 1) {
-                       dev_dbg(&i2c->dev, "Enabling charge pump\n");
-                       wm8903_write(codec, WM8903_CHARGE_PUMP_0,
-                                    cp_reg | WM8903_CP_ENA);
-                       mdelay(4);
-               }
        }
 
        if (event & SND_SOC_DAPM_POST_PMU) {
@@ -464,19 +457,6 @@ static int wm8903_output_event(struct snd_soc_dapm_widget *w,
                wm8903_write(codec, reg, val);
        }
 
-       if (event & SND_SOC_DAPM_POST_PMD) {
-               wm8903->charge_pump_users--;
-
-               dev_dbg(&i2c->dev, "Charge pump use count now %d\n",
-                       wm8903->charge_pump_users);
-
-               if (wm8903->charge_pump_users == 0) {
-                       dev_dbg(&i2c->dev, "Disabling charge pump\n");
-                       wm8903_write(codec, WM8903_CHARGE_PUMP_0,
-                                    cp_reg & ~WM8903_CP_ENA);
-               }
-       }
-
        return 0;
 }
 
@@ -844,26 +824,29 @@ SND_SOC_DAPM_MIXER("Right Speaker Mixer", WM8903_POWER_MANAGEMENT_4, 0, 0,
 SND_SOC_DAPM_PGA_E("Left Headphone Output PGA", WM8903_POWER_MANAGEMENT_2,
                   1, 0, NULL, 0, wm8903_output_event,
                   SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
-                  SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
+                  SND_SOC_DAPM_PRE_PMD),
 SND_SOC_DAPM_PGA_E("Right Headphone Output PGA", WM8903_POWER_MANAGEMENT_2,
                   0, 0, NULL, 0, wm8903_output_event,
                   SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
-                  SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
+                  SND_SOC_DAPM_PRE_PMD),
 
 SND_SOC_DAPM_PGA_E("Left Line Output PGA", WM8903_POWER_MANAGEMENT_3, 1, 0,
                   NULL, 0, wm8903_output_event,
                   SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
-                  SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
+                  SND_SOC_DAPM_PRE_PMD),
 SND_SOC_DAPM_PGA_E("Right Line Output PGA", WM8903_POWER_MANAGEMENT_3, 0, 0,
                   NULL, 0, wm8903_output_event,
                   SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
-                  SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
+                  SND_SOC_DAPM_PRE_PMD),
 
 SND_SOC_DAPM_PGA("Left Speaker PGA", WM8903_POWER_MANAGEMENT_5, 1, 0,
                 NULL, 0),
 SND_SOC_DAPM_PGA("Right Speaker PGA", WM8903_POWER_MANAGEMENT_5, 0, 0,
                 NULL, 0),
 
+SND_SOC_DAPM_SUPPLY("Charge Pump", WM8903_CHARGE_PUMP_0, 0, 0,
+                   wm8903_cp_event, SND_SOC_DAPM_POST_PMU),
+SND_SOC_DAPM_SUPPLY("CLK_DSP", WM8903_CLOCK_RATES_2, 1, 0, NULL, 0),
 };
 
 static const struct snd_soc_dapm_route intercon[] = {
@@ -909,7 +892,12 @@ static const struct snd_soc_dapm_route intercon[] = {
        { "Right Input PGA", NULL, "Right Input Mode Mux" },
 
        { "ADCL", NULL, "Left Input PGA" },
+       { "ADCL", NULL, "CLK_DSP" },
        { "ADCR", NULL, "Right Input PGA" },
+       { "ADCR", NULL, "CLK_DSP" },
+
+       { "DACL", NULL, "CLK_DSP" },
+       { "DACR", NULL, "CLK_DSP" },
 
        { "Left Output Mixer", "Left Bypass Switch", "Left Input PGA" },
        { "Left Output Mixer", "Right Bypass Switch", "Right Input PGA" },
@@ -951,6 +939,11 @@ static const struct snd_soc_dapm_route intercon[] = {
 
        { "ROP", NULL, "Right Speaker PGA" },
        { "RON", NULL, "Right Speaker PGA" },
+
+       { "Left Headphone Output PGA", NULL, "Charge Pump" },
+       { "Right Headphone Output PGA", NULL, "Charge Pump" },
+       { "Left Line Output PGA", NULL, "Charge Pump" },
+       { "Right Line Output PGA", NULL, "Charge Pump" },
 };
 
 static int wm8903_add_widgets(struct snd_soc_codec *codec)
@@ -985,6 +978,11 @@ static int wm8903_set_bias_level(struct snd_soc_codec *codec,
                        wm8903_write(codec, WM8903_CLOCK_RATES_2,
                                     WM8903_CLK_SYS_ENA);
 
+                       /* Change DC servo dither level in startup sequence */
+                       wm8903_write(codec, WM8903_WRITE_SEQUENCER_0, 0x11);
+                       wm8903_write(codec, WM8903_WRITE_SEQUENCER_1, 0x1257);
+                       wm8903_write(codec, WM8903_WRITE_SEQUENCER_2, 0x2);
+
                        wm8903_run_sequence(codec, 0);
                        wm8903_sync_reg_cache(codec, codec->reg_cache);
 
@@ -1523,6 +1521,7 @@ struct snd_soc_dai wm8903_dai = {
                 .formats = WM8903_FORMATS,
         },
        .ops = &wm8903_dai_ops,
+       .symmetric_rates = 1,
 };
 EXPORT_SYMBOL_GPL(wm8903_dai);