aboutsummaryrefslogtreecommitdiffstats
path: root/sound
diff options
context:
space:
mode:
authorOder Chiou <oder_chiou@realtek.com>2014-05-20 03:01:53 -0400
committerMark Brown <broonie@linaro.org>2014-06-01 15:04:30 -0400
commit49ef7925c237a2f9da327ea3481dd5bba54693e8 (patch)
treee31b2b7c9e284d5797f72956fc4e7ab3cfec9ec7 /sound
parent15f78ea67fa712392daebc262821d9fe29705cfa (diff)
ASoC: rt5640: Add RL6231 class device shared support for RT5640, RT5645 and RT5651
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>
Diffstat (limited to 'sound')
-rw-r--r--sound/soc/codecs/Kconfig9
-rw-r--r--sound/soc/codecs/Makefile2
-rw-r--r--sound/soc/codecs/rl6231.c67
-rw-r--r--sound/soc/codecs/rl6231.h18
-rw-r--r--sound/soc/codecs/rt5640.c23
-rw-r--r--sound/soc/codecs/rt5645.c22
-rw-r--r--sound/soc/codecs/rt5651.c22
7 files changed, 110 insertions, 53 deletions
diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
index d29f19b44638..d224ef3bfb5e 100644
--- a/sound/soc/codecs/Kconfig
+++ b/sound/soc/codecs/Kconfig
@@ -392,6 +392,15 @@ config SND_SOC_PCM512x_SPI
392 select SND_SOC_PCM512x 392 select SND_SOC_PCM512x
393 select REGMAP_SPI 393 select REGMAP_SPI
394 394
395config SND_SOC_RL6231
396 tristate
397 default y if SND_SOC_RT5640=y
398 default y if SND_SOC_RT5645=y
399 default y if SND_SOC_RT5651=y
400 default m if SND_SOC_RT5640=m
401 default m if SND_SOC_RT5645=m
402 default m if SND_SOC_RT5651=m
403
395config SND_SOC_RT5631 404config SND_SOC_RT5631
396 tristate 405 tristate
397 406
diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile
index a3d12b4af1e7..c50165e97ebe 100644
--- a/sound/soc/codecs/Makefile
+++ b/sound/soc/codecs/Makefile
@@ -58,6 +58,7 @@ snd-soc-pcm3008-objs := pcm3008.o
58snd-soc-pcm512x-objs := pcm512x.o 58snd-soc-pcm512x-objs := pcm512x.o
59snd-soc-pcm512x-i2c-objs := pcm512x-i2c.o 59snd-soc-pcm512x-i2c-objs := pcm512x-i2c.o
60snd-soc-pcm512x-spi-objs := pcm512x-spi.o 60snd-soc-pcm512x-spi-objs := pcm512x-spi.o
61snd-soc-rl6231-objs := rl6231.o
61snd-soc-rt5631-objs := rt5631.o 62snd-soc-rt5631-objs := rt5631.o
62snd-soc-rt5640-objs := rt5640.o 63snd-soc-rt5640-objs := rt5640.o
63snd-soc-rt5645-objs := rt5645.o 64snd-soc-rt5645-objs := rt5645.o
@@ -211,6 +212,7 @@ obj-$(CONFIG_SND_SOC_PCM3008) += snd-soc-pcm3008.o
211obj-$(CONFIG_SND_SOC_PCM512x) += snd-soc-pcm512x.o 212obj-$(CONFIG_SND_SOC_PCM512x) += snd-soc-pcm512x.o
212obj-$(CONFIG_SND_SOC_PCM512x_I2C) += snd-soc-pcm512x-i2c.o 213obj-$(CONFIG_SND_SOC_PCM512x_I2C) += snd-soc-pcm512x-i2c.o
213obj-$(CONFIG_SND_SOC_PCM512x_SPI) += snd-soc-pcm512x-spi.o 214obj-$(CONFIG_SND_SOC_PCM512x_SPI) += snd-soc-pcm512x-spi.o
215obj-$(CONFIG_SND_SOC_RL6231) += snd-soc-rl6231.o
214obj-$(CONFIG_SND_SOC_RT5631) += snd-soc-rt5631.o 216obj-$(CONFIG_SND_SOC_RT5631) += snd-soc-rt5631.o
215obj-$(CONFIG_SND_SOC_RT5640) += snd-soc-rt5640.o 217obj-$(CONFIG_SND_SOC_RT5640) += snd-soc-rt5640.o
216obj-$(CONFIG_SND_SOC_RT5645) += snd-soc-rt5645.o 218obj-$(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
index 000000000000..13ac551f6c79
--- /dev/null
+++ b/sound/soc/codecs/rl6231.c
@@ -0,0 +1,67 @@
1/*
2 * rl6231.c - RL6231 class device shared support
3 *
4 * Copyright 2014 Realtek Semiconductor Corp.
5 *
6 * Author: Oder Chiou <oder_chiou@realtek.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 */
12
13#include <linux/module.h>
14#include <linux/moduleparam.h>
15#include <linux/init.h>
16#include <linux/delay.h>
17#include <linux/pm.h>
18#include <linux/gpio.h>
19#include <linux/i2c.h>
20#include <linux/regmap.h>
21#include <linux/of.h>
22#include <linux/of_gpio.h>
23#include <linux/platform_device.h>
24#include <linux/spi/spi.h>
25#include <linux/acpi.h>
26#include <sound/core.h>
27#include <sound/pcm.h>
28#include <sound/pcm_params.h>
29#include <sound/soc.h>
30#include <sound/soc-dapm.h>
31#include <sound/initval.h>
32#include <sound/tlv.h>
33
34#include "rl6231.h"
35
36/**
37 * rl6231_calc_dmic_clk - Calculate the parameter of dmic.
38 *
39 * @rate: base clock rate.
40 *
41 * Choose dmic clock between 1MHz and 3MHz.
42 * It is better for clock to approximate 3MHz.
43 */
44int rl6231_calc_dmic_clk(int rate)
45{
46 int div[] = {2, 3, 4, 6, 8, 12}, idx = -EINVAL;
47 int i, red, bound, temp;
48
49 red = 3000000 * 12;
50 for (i = 0; i < ARRAY_SIZE(div); i++) {
51 bound = div[i] * 3000000;
52 if (rate > bound)
53 continue;
54 temp = bound - rate;
55 if (temp < red) {
56 red = temp;
57 idx = i;
58 }
59 }
60
61 return idx;
62}
63EXPORT_SYMBOL_GPL(rl6231_calc_dmic_clk);
64
65MODULE_DESCRIPTION("RL6231 class device shared support");
66MODULE_AUTHOR("Oder Chiou <oder_chiou@realtek.com>");
67MODULE_LICENSE("GPL v2");
diff --git a/sound/soc/codecs/rl6231.h b/sound/soc/codecs/rl6231.h
new file mode 100644
index 000000000000..00032dba1aa9
--- /dev/null
+++ b/sound/soc/codecs/rl6231.h
@@ -0,0 +1,18 @@
1/*
2 * rl6231.h - RL6231 class device shared support
3 *
4 * Copyright 2014 Realtek Semiconductor Corp.
5 *
6 * Author: Oder Chiou <oder_chiou@realtek.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 */
12
13#ifndef __RL6231_H__
14#define __RL6231_H__
15
16int rl6231_calc_dmic_clk(int rate);
17
18#endif /* __RL6231_H__ */
diff --git a/sound/soc/codecs/rt5640.c b/sound/soc/codecs/rt5640.c
index ddefd5a476d0..d586228ae5b9 100644
--- a/sound/soc/codecs/rt5640.c
+++ b/sound/soc/codecs/rt5640.c
@@ -30,6 +30,7 @@
30#include <sound/initval.h> 30#include <sound/initval.h>
31#include <sound/tlv.h> 31#include <sound/tlv.h>
32 32
33#include "rl6231.h"
33#include "rt5640.h" 34#include "rt5640.h"
34 35
35#define RT5640_DEVICE_ID 0x6231 36#define RT5640_DEVICE_ID 0x6231
@@ -452,30 +453,16 @@ static const struct snd_kcontrol_new rt5640_specific_snd_controls[] = {
452 * @kcontrol: The kcontrol of this widget. 453 * @kcontrol: The kcontrol of this widget.
453 * @event: Event id. 454 * @event: Event id.
454 * 455 *
455 * Choose dmic clock between 1MHz and 3MHz.
456 * It is better for clock to approximate 3MHz.
457 */ 456 */
458static int set_dmic_clk(struct snd_soc_dapm_widget *w, 457static int set_dmic_clk(struct snd_soc_dapm_widget *w,
459 struct snd_kcontrol *kcontrol, int event) 458 struct snd_kcontrol *kcontrol, int event)
460{ 459{
461 struct snd_soc_codec *codec = w->codec; 460 struct snd_soc_codec *codec = w->codec;
462 struct rt5640_priv *rt5640 = snd_soc_codec_get_drvdata(codec); 461 struct rt5640_priv *rt5640 = snd_soc_codec_get_drvdata(codec);
463 int div[] = {2, 3, 4, 6, 8, 12}; 462 int idx = -EINVAL;
464 int idx = -EINVAL, i; 463
465 int rate, red, bound, temp; 464 idx = rl6231_calc_dmic_clk(rt5640->sysclk);
466 465
467 rate = rt5640->sysclk;
468 red = 3000000 * 12;
469 for (i = 0; i < ARRAY_SIZE(div); i++) {
470 bound = div[i] * 3000000;
471 if (rate > bound)
472 continue;
473 temp = bound - rate;
474 if (temp < red) {
475 red = temp;
476 idx = i;
477 }
478 }
479 if (idx < 0) 466 if (idx < 0)
480 dev_err(codec->dev, "Failed to set DMIC clock\n"); 467 dev_err(codec->dev, "Failed to set DMIC clock\n");
481 else 468 else
diff --git a/sound/soc/codecs/rt5645.c b/sound/soc/codecs/rt5645.c
index ab97d722e15d..caa55199eb87 100644
--- a/sound/soc/codecs/rt5645.c
+++ b/sound/soc/codecs/rt5645.c
@@ -26,6 +26,7 @@
26#include <sound/initval.h> 26#include <sound/initval.h>
27#include <sound/tlv.h> 27#include <sound/tlv.h>
28 28
29#include "rl6231.h"
29#include "rt5645.h" 30#include "rt5645.h"
30 31
31#define RT5645_DEVICE_ID 0x6308 32#define RT5645_DEVICE_ID 0x6308
@@ -519,30 +520,15 @@ static const struct snd_kcontrol_new rt5645_snd_controls[] = {
519 * @kcontrol: The kcontrol of this widget. 520 * @kcontrol: The kcontrol of this widget.
520 * @event: Event id. 521 * @event: Event id.
521 * 522 *
522 * Choose dmic clock between 1MHz and 3MHz.
523 * It is better for clock to approximate 3MHz.
524 */ 523 */
525static int set_dmic_clk(struct snd_soc_dapm_widget *w, 524static int set_dmic_clk(struct snd_soc_dapm_widget *w,
526 struct snd_kcontrol *kcontrol, int event) 525 struct snd_kcontrol *kcontrol, int event)
527{ 526{
528 struct snd_soc_codec *codec = w->codec; 527 struct snd_soc_codec *codec = w->codec;
529 struct rt5645_priv *rt5645 = snd_soc_codec_get_drvdata(codec); 528 struct rt5645_priv *rt5645 = snd_soc_codec_get_drvdata(codec);
530 int div[] = {2, 3, 4, 6, 8, 12}; 529 int idx = -EINVAL;
531 int idx = -EINVAL, i; 530
532 int rate, red, bound, temp; 531 idx = rl6231_calc_dmic_clk(rt5645->sysclk);
533
534 rate = rt5645->sysclk;
535 red = 3000000 * 12;
536 for (i = 0; i < ARRAY_SIZE(div); i++) {
537 bound = div[i] * 3000000;
538 if (rate > bound)
539 continue;
540 temp = bound - rate;
541 if (temp < red) {
542 red = temp;
543 idx = i;
544 }
545 }
546 532
547 if (idx < 0) 533 if (idx < 0)
548 dev_err(codec->dev, "Failed to set DMIC clock\n"); 534 dev_err(codec->dev, "Failed to set DMIC clock\n");
diff --git a/sound/soc/codecs/rt5651.c b/sound/soc/codecs/rt5651.c
index 9c88d89f41f0..7a7bec6f26e6 100644
--- a/sound/soc/codecs/rt5651.c
+++ b/sound/soc/codecs/rt5651.c
@@ -26,6 +26,7 @@
26#include <sound/initval.h> 26#include <sound/initval.h>
27#include <sound/tlv.h> 27#include <sound/tlv.h>
28 28
29#include "rl6231.h"
29#include "rt5651.h" 30#include "rt5651.h"
30 31
31#define RT5651_DEVICE_ID_VALUE 0x6281 32#define RT5651_DEVICE_ID_VALUE 0x6281
@@ -371,29 +372,16 @@ static const struct snd_kcontrol_new rt5651_snd_controls[] = {
371 * @kcontrol: The kcontrol of this widget. 372 * @kcontrol: The kcontrol of this widget.
372 * @event: Event id. 373 * @event: Event id.
373 * 374 *
374 * Choose dmic clock between 1MHz and 3MHz.
375 * It is better for clock to approximate 3MHz.
376 */ 375 */
377static int set_dmic_clk(struct snd_soc_dapm_widget *w, 376static int set_dmic_clk(struct snd_soc_dapm_widget *w,
378 struct snd_kcontrol *kcontrol, int event) 377 struct snd_kcontrol *kcontrol, int event)
379{ 378{
380 struct snd_soc_codec *codec = w->codec; 379 struct snd_soc_codec *codec = w->codec;
381 struct rt5651_priv *rt5651 = snd_soc_codec_get_drvdata(codec); 380 struct rt5651_priv *rt5651 = snd_soc_codec_get_drvdata(codec);
382 int div[] = {2, 3, 4, 6, 8, 12}, idx = -EINVAL; 381 int idx = -EINVAL;
383 int i, rate, red, bound, temp; 382
384 383 idx = rl6231_calc_dmic_clk(rt5651->sysclk);
385 rate = rt5651->sysclk; 384
386 red = 3000000 * 12;
387 for (i = 0; i < ARRAY_SIZE(div); i++) {
388 bound = div[i] * 3000000;
389 if (rate > bound)
390 continue;
391 temp = bound - rate;
392 if (temp < red) {
393 red = temp;
394 idx = i;
395 }
396 }
397 if (idx < 0) 385 if (idx < 0)
398 dev_err(codec->dev, "Failed to set DMIC clock\n"); 386 dev_err(codec->dev, "Failed to set DMIC clock\n");
399 else 387 else