ASoC: rt5640: Add RL6231 class device shared support for RT5640, RT5645 and RT5651
[deliverable/linux.git] / sound / soc / codecs / rt5645.c
index 37ec468ab0e749199eae5509708bee45f732581c..caa55199eb87afdb4938808ba3b66d8ad1e2c206 100644 (file)
@@ -26,6 +26,7 @@
 #include <sound/initval.h>
 #include <sound/tlv.h>
 
+#include "rl6231.h"
 #include "rt5645.h"
 
 #define RT5645_DEVICE_ID 0x6308
@@ -50,6 +51,10 @@ static const struct regmap_range_cfg rt5645_ranges[] = {
 
 static const struct reg_default init_list[] = {
        {RT5645_PR_BASE + 0x3d, 0x3600},
+       {RT5645_PR_BASE + 0x1c, 0xfd20},
+       {RT5645_PR_BASE + 0x20, 0x611f},
+       {RT5645_PR_BASE + 0x21, 0x4040},
+       {RT5645_PR_BASE + 0x23, 0x0004},
 };
 #define RT5645_INIT_REG_LEN ARRAY_SIZE(init_list)
 
@@ -238,9 +243,9 @@ static bool rt5645_volatile_register(struct device *dev, unsigned int reg)
        case RT5645_VENDOR_ID:
        case RT5645_VENDOR_ID1:
        case RT5645_VENDOR_ID2:
-               return 1;
+               return true;
        default:
-               return 0;
+               return false;
        }
 }
 
@@ -387,9 +392,9 @@ static bool rt5645_readable_register(struct device *dev, unsigned int reg)
        case RT5645_VENDOR_ID:
        case RT5645_VENDOR_ID1:
        case RT5645_VENDOR_ID2:
-               return 1;
+               return true;
        default:
-               return 0;
+               return false;
        }
 }
 
@@ -515,30 +520,15 @@ static const struct snd_kcontrol_new rt5645_snd_controls[] = {
  * @kcontrol: The kcontrol of this widget.
  * @event: Event id.
  *
- * Choose dmic clock between 1MHz and 3MHz.
- * It is better for clock to approximate 3MHz.
  */
 static int set_dmic_clk(struct snd_soc_dapm_widget *w,
        struct snd_kcontrol *kcontrol, int event)
 {
        struct snd_soc_codec *codec = w->codec;
        struct rt5645_priv *rt5645 = snd_soc_codec_get_drvdata(codec);
-       int div[] = {2, 3, 4, 6, 8, 12};
-       int idx = -EINVAL, i;
-       int rate, red, bound, temp;
-
-       rate = rt5645->sysclk;
-       red = 3000000 * 12;
-       for (i = 0; i < ARRAY_SIZE(div); i++) {
-               bound = div[i] * 3000000;
-               if (rate > bound)
-                       continue;
-               temp = bound - rate;
-               if (temp < red) {
-                       red = temp;
-                       idx = i;
-               }
-       }
+       int idx = -EINVAL;
+
+       idx = rl6231_calc_dmic_clk(rt5645->sysclk);
 
        if (idx < 0)
                dev_err(codec->dev, "Failed to set DMIC clock\n");
@@ -1928,8 +1918,8 @@ static int rt5645_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
                        RT5645_I2S_MS_MASK | RT5645_I2S_BP_MASK |
                        RT5645_I2S_DF_MASK, reg_val);
                break;
-       case  RT5645_AIF2:
-               snd_soc_update_bits(codec, RT5645_I2S1_SDP,
+       case RT5645_AIF2:
+               snd_soc_update_bits(codec, RT5645_I2S2_SDP,
                        RT5645_I2S_MS_MASK | RT5645_I2S_BP_MASK |
                        RT5645_I2S_DF_MASK, reg_val);
                break;
@@ -2205,10 +2195,6 @@ static int rt5645_probe(struct snd_soc_codec *codec)
        rt5645_set_bias_level(codec, SND_SOC_BIAS_OFF);
 
        snd_soc_update_bits(codec, RT5645_CHARGE_PUMP, 0x0300, 0x0200);
-       snd_soc_write(codec, RT5645_PR_BASE + 0x1c, 0xfd20);
-       snd_soc_write(codec, RT5645_PR_BASE + 0x20, 0x611f);
-       snd_soc_write(codec, RT5645_PR_BASE + 0x21, 0x4040);
-       snd_soc_write(codec, RT5645_PR_BASE + 0x23, 0x0004);
 
        return 0;
 }
@@ -2235,7 +2221,7 @@ static int rt5645_resume(struct snd_soc_codec *codec)
        struct rt5645_priv *rt5645 = snd_soc_codec_get_drvdata(codec);
 
        regcache_cache_only(rt5645->regmap, false);
-       snd_soc_cache_sync(codec);
+       regcache_sync(rt5645->regmap);
 
        return 0;
 }
@@ -2248,7 +2234,7 @@ static int rt5645_resume(struct snd_soc_codec *codec)
 #define RT5645_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
                        SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S8)
 
-struct snd_soc_dai_ops rt5645_aif_dai_ops = {
+static struct snd_soc_dai_ops rt5645_aif_dai_ops = {
        .hw_params = rt5645_hw_params,
        .set_fmt = rt5645_set_dai_fmt,
        .set_sysclk = rt5645_set_dai_sysclk,
@@ -2256,7 +2242,7 @@ struct snd_soc_dai_ops rt5645_aif_dai_ops = {
        .set_pll = rt5645_set_dai_pll,
 };
 
-struct snd_soc_dai_driver rt5645_dai[] = {
+static struct snd_soc_dai_driver rt5645_dai[] = {
        {
                .name = "rt5645-aif1",
                .id = RT5645_AIF1,
@@ -2459,7 +2445,7 @@ static int rt5645_i2c_remove(struct i2c_client *i2c)
        return 0;
 }
 
-struct i2c_driver rt5645_i2c_driver = {
+static struct i2c_driver rt5645_i2c_driver = {
        .driver = {
                .name = "rt5645",
                .owner = THIS_MODULE,
This page took 0.025735 seconds and 5 git commands to generate.