ASoC: rt5640: Add RL6231 class device shared support for RT5640, RT5645 and RT5651
authorOder Chiou <oder_chiou@realtek.com>
Tue, 20 May 2014 07:01:53 +0000 (15:01 +0800)
committerMark Brown <broonie@linaro.org>
Sun, 1 Jun 2014 19:04:30 +0000 (20:04 +0100)
The patch adds the RL6231 class device shared support for RT5640, RT5645 and
RT5651. The function of the DMIC clock calculation can be shared by RL6231
shared support.

Signed-off-by: Oder Chiou <oder_chiou@realtek.com>
Signed-off-by: Mark Brown <broonie@linaro.org>
sound/soc/codecs/Kconfig
sound/soc/codecs/Makefile
sound/soc/codecs/rl6231.c [new file with mode: 0644]
sound/soc/codecs/rl6231.h [new file with mode: 0644]
sound/soc/codecs/rt5640.c
sound/soc/codecs/rt5645.c
sound/soc/codecs/rt5651.c

index d29f19b..d224ef3 100644 (file)
@@ -392,6 +392,15 @@ config SND_SOC_PCM512x_SPI
        select SND_SOC_PCM512x
        select REGMAP_SPI
 
+config SND_SOC_RL6231
+       tristate
+       default y if SND_SOC_RT5640=y
+       default y if SND_SOC_RT5645=y
+       default y if SND_SOC_RT5651=y
+       default m if SND_SOC_RT5640=m
+       default m if SND_SOC_RT5645=m
+       default m if SND_SOC_RT5651=m
+
 config SND_SOC_RT5631
        tristate
 
index a3d12b4..c50165e 100644 (file)
@@ -58,6 +58,7 @@ snd-soc-pcm3008-objs := pcm3008.o
 snd-soc-pcm512x-objs := pcm512x.o
 snd-soc-pcm512x-i2c-objs := pcm512x-i2c.o
 snd-soc-pcm512x-spi-objs := pcm512x-spi.o
+snd-soc-rl6231-objs := rl6231.o
 snd-soc-rt5631-objs := rt5631.o
 snd-soc-rt5640-objs := rt5640.o
 snd-soc-rt5645-objs := rt5645.o
@@ -211,6 +212,7 @@ obj-$(CONFIG_SND_SOC_PCM3008)       += snd-soc-pcm3008.o
 obj-$(CONFIG_SND_SOC_PCM512x)  += snd-soc-pcm512x.o
 obj-$(CONFIG_SND_SOC_PCM512x_I2C)      += snd-soc-pcm512x-i2c.o
 obj-$(CONFIG_SND_SOC_PCM512x_SPI)      += snd-soc-pcm512x-spi.o
+obj-$(CONFIG_SND_SOC_RL6231)   += snd-soc-rl6231.o
 obj-$(CONFIG_SND_SOC_RT5631)   += snd-soc-rt5631.o
 obj-$(CONFIG_SND_SOC_RT5640)   += snd-soc-rt5640.o
 obj-$(CONFIG_SND_SOC_RT5645)   += snd-soc-rt5645.o
diff --git a/sound/soc/codecs/rl6231.c b/sound/soc/codecs/rl6231.c
new file mode 100644 (file)
index 0000000..13ac551
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * rl6231.c - RL6231 class device shared support
+ *
+ * Copyright 2014 Realtek Semiconductor Corp.
+ *
+ * Author: Oder Chiou <oder_chiou@realtek.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/init.h>
+#include <linux/delay.h>
+#include <linux/pm.h>
+#include <linux/gpio.h>
+#include <linux/i2c.h>
+#include <linux/regmap.h>
+#include <linux/of.h>
+#include <linux/of_gpio.h>
+#include <linux/platform_device.h>
+#include <linux/spi/spi.h>
+#include <linux/acpi.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <sound/soc.h>
+#include <sound/soc-dapm.h>
+#include <sound/initval.h>
+#include <sound/tlv.h>
+
+#include "rl6231.h"
+
+/**
+ * rl6231_calc_dmic_clk - Calculate the parameter of dmic.
+ *
+ * @rate: base clock rate.
+ *
+ * Choose dmic clock between 1MHz and 3MHz.
+ * It is better for clock to approximate 3MHz.
+ */
+int rl6231_calc_dmic_clk(int rate)
+{
+       int div[] = {2, 3, 4, 6, 8, 12}, idx = -EINVAL;
+       int i, red, bound, temp;
+
+       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;
+               }
+       }
+
+       return idx;
+}
+EXPORT_SYMBOL_GPL(rl6231_calc_dmic_clk);
+
+MODULE_DESCRIPTION("RL6231 class device shared support");
+MODULE_AUTHOR("Oder Chiou <oder_chiou@realtek.com>");
+MODULE_LICENSE("GPL v2");
diff --git a/sound/soc/codecs/rl6231.h b/sound/soc/codecs/rl6231.h
new file mode 100644 (file)
index 0000000..00032db
--- /dev/null
@@ -0,0 +1,18 @@
+/*
+ * rl6231.h - RL6231 class device shared support
+ *
+ * Copyright 2014 Realtek Semiconductor Corp.
+ *
+ * Author: Oder Chiou <oder_chiou@realtek.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef __RL6231_H__
+#define __RL6231_H__
+
+int rl6231_calc_dmic_clk(int rate);
+
+#endif /* __RL6231_H__ */
index ddefd5a..d586228 100644 (file)
@@ -30,6 +30,7 @@
 #include <sound/initval.h>
 #include <sound/tlv.h>
 
+#include "rl6231.h"
 #include "rt5640.h"
 
 #define RT5640_DEVICE_ID 0x6231
@@ -452,30 +453,16 @@ static const struct snd_kcontrol_new rt5640_specific_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 rt5640_priv *rt5640 = snd_soc_codec_get_drvdata(codec);
-       int div[] = {2, 3, 4, 6, 8, 12};
-       int idx = -EINVAL, i;
-       int rate, red, bound, temp;
-
-       rate = rt5640->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(rt5640->sysclk);
+
        if (idx < 0)
                dev_err(codec->dev, "Failed to set DMIC clock\n");
        else
index ab97d72..caa5519 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
@@ -519,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");
index 9c88d89..7a7bec6 100644 (file)
@@ -26,6 +26,7 @@
 #include <sound/initval.h>
 #include <sound/tlv.h>
 
+#include "rl6231.h"
 #include "rt5651.h"
 
 #define RT5651_DEVICE_ID_VALUE 0x6281
@@ -371,29 +372,16 @@ static const struct snd_kcontrol_new rt5651_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 rt5651_priv *rt5651 = snd_soc_codec_get_drvdata(codec);
-       int div[] = {2, 3, 4, 6, 8, 12}, idx = -EINVAL;
-       int i, rate, red, bound, temp;
-
-       rate = rt5651->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(rt5651->sysclk);
+
        if (idx < 0)
                dev_err(codec->dev, "Failed to set DMIC clock\n");
        else