Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jikos/trivial
[linux-3.10.git] / sound / soc / codecs / wm8993.c
index ff9b63b..2981afa 100644 (file)
@@ -218,6 +218,8 @@ struct wm8993_priv {
        struct snd_soc_codec codec;
        int master;
        int sysclk_source;
+       int tdm_slots;
+       int tdm_width;
        unsigned int mclk_rate;
        unsigned int sysclk_rate;
        unsigned int fs;
@@ -420,7 +422,7 @@ static int fll_factors(struct _fll_div *fll_div, unsigned int Fref,
        return 0;
 }
 
-static int wm8993_set_fll(struct snd_soc_dai *dai, int fll_id,
+static int wm8993_set_fll(struct snd_soc_dai *dai, int fll_id, int source,
                          unsigned int Fref, unsigned int Fout)
 {
        struct snd_soc_codec *codec = dai->codec;
@@ -519,7 +521,7 @@ static int configure_clock(struct snd_soc_codec *codec)
                dev_dbg(codec->dev, "Using %dHz MCLK\n", wm8993->mclk_rate);
 
                reg = wm8993_read(codec, WM8993_CLOCKING_2);
-               reg &= ~WM8993_SYSCLK_SRC;
+               reg &= ~(WM8993_MCLK_DIV | WM8993_SYSCLK_SRC);
                if (wm8993->mclk_rate > 13500000) {
                        reg |= WM8993_MCLK_DIV;
                        wm8993->sysclk_rate = wm8993->mclk_rate / 2;
@@ -527,8 +529,6 @@ static int configure_clock(struct snd_soc_codec *codec)
                        reg &= ~WM8993_MCLK_DIV;
                        wm8993->sysclk_rate = wm8993->mclk_rate;
                }
-               reg &= ~WM8993_MCLK_DIV;
-               reg &= ~(WM8993_MCLK_DIV | WM8993_SYSCLK_SRC);
                wm8993_write(codec, WM8993_CLOCKING_2, reg);
                break;
 
@@ -689,7 +689,7 @@ SOC_DOUBLE_TLV("Digital Sidetone Volume", WM8993_DIGITAL_SIDE_TONE,
 
 SOC_SINGLE("DRC Switch", WM8993_DRC_CONTROL_1, 15, 1, 0),
 SOC_ENUM("DRC Path", drc_path),
-SOC_SINGLE_TLV("DRC Compressor Threashold Volume", WM8993_DRC_CONTROL_2,
+SOC_SINGLE_TLV("DRC Compressor Threshold Volume", WM8993_DRC_CONTROL_2,
               2, 60, 1, drc_comp_threash),
 SOC_SINGLE_TLV("DRC Compressor Amplitude Volume", WM8993_DRC_CONTROL_3,
               11, 30, 1, drc_comp_amp),
@@ -709,7 +709,7 @@ SOC_SINGLE_TLV("DRC Quick Release Volume", WM8993_DRC_CONTROL_3, 2, 3, 0,
 SOC_ENUM("DRC Quick Release Rate", drc_qr_rate),
 SOC_SINGLE("DRC Smoothing Switch", WM8993_DRC_CONTROL_1, 11, 1, 0),
 SOC_SINGLE("DRC Smoothing Hysteresis Switch", WM8993_DRC_CONTROL_1, 8, 1, 0),
-SOC_ENUM("DRC Smoothing Hysteresis Threashold", drc_smooth),
+SOC_ENUM("DRC Smoothing Hysteresis Threshold", drc_smooth),
 SOC_SINGLE_TLV("DRC Startup Volume", WM8993_DRC_CONTROL_4, 8, 18, 0,
               drc_startup_tlv),
 
@@ -1189,24 +1189,30 @@ static int wm8993_hw_params(struct snd_pcm_substream *substream,
        /* What BCLK do we need? */
        wm8993->fs = params_rate(params);
        wm8993->bclk = 2 * wm8993->fs;
-       switch (params_format(params)) {
-       case SNDRV_PCM_FORMAT_S16_LE:
-               wm8993->bclk *= 16;
-               break;
-       case SNDRV_PCM_FORMAT_S20_3LE:
-               wm8993->bclk *= 20;
-               aif1 |= 0x8;
-               break;
-       case SNDRV_PCM_FORMAT_S24_LE:
-               wm8993->bclk *= 24;
-               aif1 |= 0x10;
-               break;
-       case SNDRV_PCM_FORMAT_S32_LE:
-               wm8993->bclk *= 32;
-               aif1 |= 0x18;
-               break;
-       default:
-               return -EINVAL;
+       if (wm8993->tdm_slots) {
+               dev_dbg(codec->dev, "Configuring for %d %d bit TDM slots\n",
+                       wm8993->tdm_slots, wm8993->tdm_width);
+               wm8993->bclk *= wm8993->tdm_width * wm8993->tdm_slots;
+       } else {
+               switch (params_format(params)) {
+               case SNDRV_PCM_FORMAT_S16_LE:
+                       wm8993->bclk *= 16;
+                       break;
+               case SNDRV_PCM_FORMAT_S20_3LE:
+                       wm8993->bclk *= 20;
+                       aif1 |= 0x8;
+                       break;
+               case SNDRV_PCM_FORMAT_S24_LE:
+                       wm8993->bclk *= 24;
+                       aif1 |= 0x10;
+                       break;
+               case SNDRV_PCM_FORMAT_S32_LE:
+                       wm8993->bclk *= 32;
+                       aif1 |= 0x18;
+                       break;
+               default:
+                       return -EINVAL;
+               }
        }
 
        dev_dbg(codec->dev, "Target BCLK is %dHz\n", wm8993->bclk);
@@ -1325,12 +1331,67 @@ static int wm8993_digital_mute(struct snd_soc_dai *codec_dai, int mute)
        return 0;
 }
 
+static int wm8993_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask,
+                              unsigned int rx_mask, int slots, int slot_width)
+{
+       struct snd_soc_codec *codec = dai->codec;
+       struct wm8993_priv *wm8993 = codec->private_data;
+       int aif1 = 0;
+       int aif2 = 0;
+
+       /* Don't need to validate anything if we're turning off TDM */
+       if (slots == 0) {
+               wm8993->tdm_slots = 0;
+               goto out;
+       }
+
+       /* Note that we allow configurations we can't handle ourselves - 
+        * for example, we can generate clocks for slots 2 and up even if
+        * we can't use those slots ourselves.
+        */
+       aif1 |= WM8993_AIFADC_TDM;
+       aif2 |= WM8993_AIFDAC_TDM;
+
+       switch (rx_mask) {
+       case 3:
+               break;
+       case 0xc:
+               aif1 |= WM8993_AIFADC_TDM_CHAN;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+
+       switch (tx_mask) {
+       case 3:
+               break;
+       case 0xc:
+               aif2 |= WM8993_AIFDAC_TDM_CHAN;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+out:
+       wm8993->tdm_width = slot_width;
+       wm8993->tdm_slots = slots / 2;
+
+       snd_soc_update_bits(codec, WM8993_AUDIO_INTERFACE_1,
+                           WM8993_AIFADC_TDM | WM8993_AIFADC_TDM_CHAN, aif1);
+       snd_soc_update_bits(codec, WM8993_AUDIO_INTERFACE_2,
+                           WM8993_AIFDAC_TDM | WM8993_AIFDAC_TDM_CHAN, aif2);
+
+       return 0;
+}
+
 static struct snd_soc_dai_ops wm8993_ops = {
        .set_sysclk = wm8993_set_sysclk,
        .set_fmt = wm8993_set_dai_fmt,
        .hw_params = wm8993_hw_params,
        .digital_mute = wm8993_digital_mute,
        .set_pll = wm8993_set_fll,
+       .set_tdm_slot = wm8993_set_tdm_slot,
 };
 
 #define WM8993_RATES SNDRV_PCM_RATE_8000_48000
@@ -1403,19 +1464,8 @@ static int wm8993_probe(struct platform_device *pdev)
        wm_hubs_add_analogue_routes(codec, wm8993->pdata.lineout1_diff,
                                    wm8993->pdata.lineout2_diff);
 
-       snd_soc_dapm_new_widgets(codec);
-
-       ret = snd_soc_init_card(socdev);
-       if (ret < 0) {
-               dev_err(codec->dev, "failed to register card\n");
-               goto card_err;
-       }
-
        return ret;
 
-card_err:
-       snd_soc_free_pcms(socdev);
-       snd_soc_dapm_free(socdev);
 err:
        return ret;
 }
@@ -1511,33 +1561,15 @@ static int wm8993_i2c_probe(struct i2c_client *i2c,
        /* Use automatic clock configuration */
        snd_soc_update_bits(codec, WM8993_CLOCKING_4, WM8993_SR_MODE, 0);
 
-       if (!wm8993->pdata.lineout1_diff)
-               snd_soc_update_bits(codec, WM8993_LINE_MIXER1,
-                                   WM8993_LINEOUT1_MODE,
-                                   WM8993_LINEOUT1_MODE);
-       if (!wm8993->pdata.lineout2_diff)
-               snd_soc_update_bits(codec, WM8993_LINE_MIXER2,
-                                   WM8993_LINEOUT2_MODE,
-                                   WM8993_LINEOUT2_MODE);
-
-       if (wm8993->pdata.lineout1fb)
-               snd_soc_update_bits(codec, WM8993_ADDITIONAL_CONTROL,
-                                   WM8993_LINEOUT1_FB, WM8993_LINEOUT1_FB);
-
-       if (wm8993->pdata.lineout2fb)
-               snd_soc_update_bits(codec, WM8993_ADDITIONAL_CONTROL,
-                                   WM8993_LINEOUT2_FB, WM8993_LINEOUT2_FB);
-
-       /* Apply the microphone bias/detection configuration - the
-        * platform data is directly applicable to the register. */
-       snd_soc_update_bits(codec, WM8993_MICBIAS,
-                           WM8993_JD_SCTHR_MASK | WM8993_JD_THR_MASK |
-                           WM8993_MICB1_LVL | WM8993_MICB2_LVL,
-                           wm8993->pdata.jd_scthr << WM8993_JD_SCTHR_SHIFT |
-                           wm8993->pdata.jd_thr << WM8993_JD_THR_SHIFT |
-                           wm8993->pdata.micbias1_lvl |
-                           wm8993->pdata.micbias1_lvl << 1);
-
+       wm_hubs_handle_analogue_pdata(codec, wm8993->pdata.lineout1_diff,
+                                     wm8993->pdata.lineout2_diff,
+                                     wm8993->pdata.lineout1fb,
+                                     wm8993->pdata.lineout2fb,
+                                     wm8993->pdata.jd_scthr,
+                                     wm8993->pdata.jd_thr,
+                                     wm8993->pdata.micbias1_lvl,
+                                     wm8993->pdata.micbias2_lvl);
+                            
        ret = wm8993_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
        if (ret != 0)
                goto err;