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>
This commit is contained in:
parent
15f78ea67f
commit
49ef7925c2
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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");
|
|
@ -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__ */
|
|
@ -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;
|
||||
int idx = -EINVAL;
|
||||
|
||||
idx = rl6231_calc_dmic_clk(rt5640->sysclk);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
if (idx < 0)
|
||||
dev_err(codec->dev, "Failed to set DMIC clock\n");
|
||||
else
|
||||
|
|
|
@ -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;
|
||||
int idx = -EINVAL;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
idx = rl6231_calc_dmic_clk(rt5645->sysclk);
|
||||
|
||||
if (idx < 0)
|
||||
dev_err(codec->dev, "Failed to set DMIC clock\n");
|
||||
|
|
|
@ -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;
|
||||
int idx = -EINVAL;
|
||||
|
||||
idx = rl6231_calc_dmic_clk(rt5651->sysclk);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
if (idx < 0)
|
||||
dev_err(codec->dev, "Failed to set DMIC clock\n");
|
||||
else
|
||||
|
|
Loading…
Reference in New Issue