ASoC: rt5640: Use the platform data for DMIC settings
authorOder Chiou <oder_chiou@realtek.com>
Fri, 28 Mar 2014 02:46:18 +0000 (10:46 +0800)
committerMark Brown <broonie@linaro.org>
Mon, 14 Apr 2014 16:27:41 +0000 (17:27 +0100)
The patch uses the platform data for DMIC settings.

Signed-off-by: Oder Chiou <oder_chiou@realtek.com>
Signed-off-by: Mark Brown <broonie@linaro.org>
include/sound/rt5640.h
sound/soc/codecs/rt5640.c

index 27cc75ed67f87a321b21b0cd247cad0ab6b371cf..59d26dd81e45333e1730910a30493df4480059d5 100644 (file)
@@ -16,6 +16,10 @@ struct rt5640_platform_data {
        bool in1_diff;
        bool in2_diff;
 
+       bool dmic_en;
+       bool dmic1_data_pin; /* 0 = IN1P; 1 = GPIO3 */
+       bool dmic2_data_pin; /* 0 = IN1N; 1 = GPIO4 */
+
        int ldo1_en; /* GPIO for LDO1_EN */
 };
 
index f0717db3e93536f7333bf47f88fc593a5e806e79..6ede622ad44fbc456646b3c8914eac79a713887d 100644 (file)
@@ -872,54 +872,6 @@ static SOC_ENUM_SINGLE_DECL(rt5640_sdi_sel_enum, RT5640_I2S2_SDP,
 static const struct snd_kcontrol_new rt5640_sdi_mux =
        SOC_DAPM_ENUM("SDI select", rt5640_sdi_sel_enum);
 
-static int rt5640_set_dmic1_event(struct snd_soc_dapm_widget *w,
-       struct snd_kcontrol *kcontrol, int event)
-{
-       struct snd_soc_codec *codec = w->codec;
-
-       switch (event) {
-       case SND_SOC_DAPM_PRE_PMU:
-               snd_soc_update_bits(codec, RT5640_GPIO_CTRL1,
-                       RT5640_GP2_PIN_MASK | RT5640_GP3_PIN_MASK,
-                       RT5640_GP2_PIN_DMIC1_SCL | RT5640_GP3_PIN_DMIC1_SDA);
-               snd_soc_update_bits(codec, RT5640_DMIC,
-                       RT5640_DMIC_1L_LH_MASK | RT5640_DMIC_1R_LH_MASK |
-                       RT5640_DMIC_1_DP_MASK,
-                       RT5640_DMIC_1L_LH_FALLING | RT5640_DMIC_1R_LH_RISING |
-                       RT5640_DMIC_1_DP_IN1P);
-               break;
-
-       default:
-               return 0;
-       }
-
-       return 0;
-}
-
-static int rt5640_set_dmic2_event(struct snd_soc_dapm_widget *w,
-       struct snd_kcontrol *kcontrol, int event)
-{
-       struct snd_soc_codec *codec = w->codec;
-
-       switch (event) {
-       case SND_SOC_DAPM_PRE_PMU:
-               snd_soc_update_bits(codec, RT5640_GPIO_CTRL1,
-                       RT5640_GP2_PIN_MASK | RT5640_GP4_PIN_MASK,
-                       RT5640_GP2_PIN_DMIC1_SCL | RT5640_GP4_PIN_DMIC2_SDA);
-               snd_soc_update_bits(codec, RT5640_DMIC,
-                       RT5640_DMIC_2L_LH_MASK | RT5640_DMIC_2R_LH_MASK |
-                       RT5640_DMIC_2_DP_MASK,
-                       RT5640_DMIC_2L_LH_FALLING | RT5640_DMIC_2R_LH_RISING |
-                       RT5640_DMIC_2_DP_IN1N);
-               break;
-
-       default:
-               return 0;
-       }
-
-       return 0;
-}
-
 static void hp_amp_power_on(struct snd_soc_codec *codec)
 {
        struct rt5640_priv *rt5640 = snd_soc_codec_get_drvdata(codec);
@@ -1054,12 +1006,10 @@ static const struct snd_soc_dapm_widget rt5640_dapm_widgets[] = {
 
        SND_SOC_DAPM_SUPPLY("DMIC CLK", SND_SOC_NOPM, 0, 0,
                set_dmic_clk, SND_SOC_DAPM_PRE_PMU),
-       SND_SOC_DAPM_SUPPLY("DMIC1 Power", RT5640_DMIC,
-               RT5640_DMIC_1_EN_SFT, 0, rt5640_set_dmic1_event,
-               SND_SOC_DAPM_PRE_PMU),
-       SND_SOC_DAPM_SUPPLY("DMIC2 Power", RT5640_DMIC,
-               RT5640_DMIC_2_EN_SFT, 0, rt5640_set_dmic2_event,
-               SND_SOC_DAPM_PRE_PMU),
+       SND_SOC_DAPM_SUPPLY("DMIC1 Power", RT5640_DMIC, RT5640_DMIC_1_EN_SFT, 0,
+               NULL, 0),
+       SND_SOC_DAPM_SUPPLY("DMIC2 Power", RT5640_DMIC, RT5640_DMIC_2_EN_SFT, 0,
+               NULL, 0),
        /* Boost */
        SND_SOC_DAPM_PGA("BST1", RT5640_PWR_ANLG2,
                RT5640_PWR_BST1_BIT, 0, NULL, 0),
@@ -2187,6 +2137,25 @@ static int rt5640_i2c_probe(struct i2c_client *i2c,
                regmap_update_bits(rt5640->regmap, RT5640_IN3_IN4,
                                        RT5640_IN_DF2, RT5640_IN_DF2);
 
+       if (rt5640->pdata.dmic_en) {
+               regmap_update_bits(rt5640->regmap, RT5640_GPIO_CTRL1,
+                       RT5640_GP2_PIN_MASK, RT5640_GP2_PIN_DMIC1_SCL);
+
+               if (rt5640->pdata.dmic1_data_pin) {
+                       regmap_update_bits(rt5640->regmap, RT5640_DMIC,
+                               RT5640_DMIC_1_DP_MASK, RT5640_DMIC_1_DP_GPIO3);
+                       regmap_update_bits(rt5640->regmap, RT5640_GPIO_CTRL1,
+                               RT5640_GP3_PIN_MASK, RT5640_GP3_PIN_DMIC1_SDA);
+               }
+
+               if (rt5640->pdata.dmic2_data_pin) {
+                       regmap_update_bits(rt5640->regmap, RT5640_DMIC,
+                               RT5640_DMIC_2_DP_MASK, RT5640_DMIC_2_DP_GPIO4);
+                       regmap_update_bits(rt5640->regmap, RT5640_GPIO_CTRL1,
+                               RT5640_GP4_PIN_MASK, RT5640_GP4_PIN_DMIC2_SDA);
+               }
+       }
+
        rt5640->hp_mute = 1;
 
        ret = snd_soc_register_codec(&i2c->dev, &soc_codec_dev_rt5640,