Commit 7034ef5f authored by Mark Brown's avatar Mark Brown

Merge remote-tracking branches 'asoc/topic/atmel-classd' and 'asoc/topic/da7213' into asoc-next

* Atmel ClassD driver under ALSA SoC architecture
Required properties:
- compatible
Should be "atmel,sama5d2-classd".
- reg
Should contain ClassD registers location and length.
- interrupts
Should contain the IRQ line for the ClassD.
- dmas
One DMA specifiers as described in atmel-dma.txt and dma.txt files.
- dma-names
Must be "tx".
- clock-names
Tuple listing input clock names.
Required elements: "pclk", "gclk" and "aclk".
- clocks
Please refer to clock-bindings.txt.
Optional properties:
- pinctrl-names, pinctrl-0
Please refer to pinctrl-bindings.txt.
- atmel,model
The user-visible name of this sound complex.
The default value is "CLASSD".
- atmel,pwm-type
PWM modulation type, "single" or "diff".
The default value is "single".
- atmel,non-overlap-time
Set non-overlapping time, the unit is nanosecond(ns).
There are four values,
<5>, <10>, <15>, <20>, the default value is <10>.
Non-overlapping will be disabled if not specified.
Example:
classd: classd@fc048000 {
compatible = "atmel,sama5d2-classd";
reg = <0xfc048000 0x100>;
interrupts = <59 IRQ_TYPE_LEVEL_HIGH 7>;
dmas = <&dma0
(AT91_XDMAC_DT_MEM_IF(0) | AT91_XDMAC_DT_PER_IF(1)
| AT91_XDMAC_DT_PERID(47))>;
dma-names = "tx";
clocks = <&classd_clk>, <&classd_gclk>, <&audio_pll_pmc>;
clock-names = "pclk", "gclk", "aclk";
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_classd_default>;
atmel,model = "classd @ SAMA5D2-Xplained";
atmel,pwm-type = "diff";
atmel,non-overlap-time = <10>;
};
Dialog Semiconductor DA7213 Audio Codec bindings
======
Required properties:
- compatible : Should be "dlg,da7213"
- reg: Specifies the I2C slave address
Optional properties:
- clocks : phandle and clock specifier for codec MCLK.
- clock-names : Clock name string for 'clocks' attribute, should be "mclk".
- dlg,micbias1-lvl : Voltage (mV) for Mic Bias 1
[<1600>, <2200>, <2500>, <3000>]
- dlg,micbias2-lvl : Voltage (mV) for Mic Bias 2
[<1600>, <2200>, <2500>, <3000>]
- dlg,dmic-data-sel : DMIC channel select based on clock edge.
["lrise_rfall", "lfall_rrise"]
- dlg,dmic-samplephase : When to sample audio from DMIC.
["on_clkedge", "between_clkedge"]
- dlg,dmic-clkrate : DMIC clock frequency (Hz).
[<1500000>, <3000000>]
======
Example:
codec_i2c: da7213@1a {
compatible = "dlg,da7213";
reg = <0x1a>;
clocks = <&clks 201>;
clock-names = "mclk";
dlg,micbias1-lvl = <2500>;
dlg,micbias2-lvl = <2500>;
dlg,dmic-data-sel = "lrise_rfall";
dlg,dmic-samplephase = "between_clkedge";
dlg,dmic-clkrate = <3000000>;
};
......@@ -44,9 +44,6 @@ struct da7213_platform_data {
enum da7213_dmic_data_sel dmic_data_sel;
enum da7213_dmic_samplephase dmic_samplephase;
enum da7213_dmic_clk_rate dmic_clk_rate;
/* MCLK squaring config */
bool mclk_squaring;
};
#endif /* _DA7213_PDATA_H */
......@@ -59,4 +59,13 @@ config SND_AT91_SOC_SAM9X5_WM8731
help
Say Y if you want to add support for audio SoC on an
at91sam9x5 based board that is using WM8731 codec.
config SND_ATMEL_SOC_CLASSD
tristate "Atmel ASoC driver for boards using CLASSD"
depends on ARCH_AT91 || COMPILE_TEST
select SND_ATMEL_SOC_DMA
select REGMAP_MMIO
help
Say Y if you want to add support for Atmel ASoC driver for boards using
CLASSD.
endif
......@@ -11,7 +11,9 @@ obj-$(CONFIG_SND_ATMEL_SOC_SSC) += snd-soc-atmel_ssc_dai.o
snd-soc-sam9g20-wm8731-objs := sam9g20_wm8731.o
snd-atmel-soc-wm8904-objs := atmel_wm8904.o
snd-soc-sam9x5-wm8731-objs := sam9x5_wm8731.o
snd-atmel-soc-classd-objs := atmel-classd.o
obj-$(CONFIG_SND_AT91_SOC_SAM9G20_WM8731) += snd-soc-sam9g20-wm8731.o
obj-$(CONFIG_SND_ATMEL_SOC_WM8904) += snd-atmel-soc-wm8904.o
obj-$(CONFIG_SND_AT91_SOC_SAM9X5_WM8731) += snd-soc-sam9x5-wm8731.o
obj-$(CONFIG_SND_ATMEL_SOC_CLASSD) += snd-atmel-soc-classd.o
This diff is collapsed.
#ifndef __ATMEL_CLASSD_H_
#define __ATMEL_CLASSD_H_
#define CLASSD_CR 0x00000000
#define CLASSD_CR_RESET 0x1
#define CLASSD_MR 0x00000004
#define CLASSD_MR_LEN_DIS 0x0
#define CLASSD_MR_LEN_EN 0x1
#define CLASSD_MR_LEN_MASK (0x1 << 0)
#define CLASSD_MR_LEN_SHIFT (0)
#define CLASSD_MR_LMUTE_DIS 0x0
#define CLASSD_MR_LMUTE_EN 0x1
#define CLASSD_MR_LMUTE_SHIFT (0x1)
#define CLASSD_MR_LMUTE_MASK (0x1 << 1)
#define CLASSD_MR_REN_DIS 0x0
#define CLASSD_MR_REN_EN 0x1
#define CLASSD_MR_REN_MASK (0x1 << 4)
#define CLASSD_MR_REN_SHIFT (4)
#define CLASSD_MR_RMUTE_DIS 0x0
#define CLASSD_MR_RMUTE_EN 0x1
#define CLASSD_MR_RMUTE_SHIFT (0x5)
#define CLASSD_MR_RMUTE_MASK (0x1 << 5)
#define CLASSD_MR_PWMTYP_SINGLE 0x0
#define CLASSD_MR_PWMTYP_DIFF 0x1
#define CLASSD_MR_PWMTYP_MASK (0x1 << 8)
#define CLASSD_MR_PWMTYP_SHIFT (8)
#define CLASSD_MR_NON_OVERLAP_DIS 0x0
#define CLASSD_MR_NON_OVERLAP_EN 0x1
#define CLASSD_MR_NON_OVERLAP_MASK (0x1 << 16)
#define CLASSD_MR_NON_OVERLAP_SHIFT (16)
#define CLASSD_MR_NOVR_VAL_5NS 0x0
#define CLASSD_MR_NOVR_VAL_10NS 0x1
#define CLASSD_MR_NOVR_VAL_15NS 0x2
#define CLASSD_MR_NOVR_VAL_20NS 0x3
#define CLASSD_MR_NOVR_VAL_MASK (0x3 << 20)
#define CLASSD_MR_NOVR_VAL_SHIFT (20)
#define CLASSD_INTPMR 0x00000008
#define CLASSD_INTPMR_ATTL_MASK (0x3f << 0)
#define CLASSD_INTPMR_ATTL_SHIFT (0)
#define CLASSD_INTPMR_ATTR_MASK (0x3f << 8)
#define CLASSD_INTPMR_ATTR_SHIFT (8)
#define CLASSD_INTPMR_DSP_CLK_FREQ_12M288 0x0
#define CLASSD_INTPMR_DSP_CLK_FREQ_11M2896 0x1
#define CLASSD_INTPMR_DSP_CLK_FREQ_MASK (0x1 << 16)
#define CLASSD_INTPMR_DSP_CLK_FREQ_SHIFT (16)
#define CLASSD_INTPMR_DEEMP_DIS 0x0
#define CLASSD_INTPMR_DEEMP_EN 0x1
#define CLASSD_INTPMR_DEEMP_MASK (0x1 << 18)
#define CLASSD_INTPMR_DEEMP_SHIFT (18)
#define CLASSD_INTPMR_SWAP_LEFT_ON_LSB 0x0
#define CLASSD_INTPMR_SWAP_RIGHT_ON_LSB 0x1
#define CLASSD_INTPMR_SWAP_MASK (0x1 << 19)
#define CLASSD_INTPMR_SWAP_SHIFT (19)
#define CLASSD_INTPMR_FRAME_8K 0x0
#define CLASSD_INTPMR_FRAME_16K 0x1
#define CLASSD_INTPMR_FRAME_32K 0x2
#define CLASSD_INTPMR_FRAME_48K 0x3
#define CLASSD_INTPMR_FRAME_96K 0x4
#define CLASSD_INTPMR_FRAME_22K 0x5
#define CLASSD_INTPMR_FRAME_44K 0x6
#define CLASSD_INTPMR_FRAME_88K 0x7
#define CLASSD_INTPMR_FRAME_MASK (0x7 << 20)
#define CLASSD_INTPMR_FRAME_SHIFT (20)
#define CLASSD_INTPMR_EQCFG_FLAT 0x0
#define CLASSD_INTPMR_EQCFG_B_BOOST_12 0x1
#define CLASSD_INTPMR_EQCFG_B_BOOST_6 0x2
#define CLASSD_INTPMR_EQCFG_B_CUT_12 0x3
#define CLASSD_INTPMR_EQCFG_B_CUT_6 0x4
#define CLASSD_INTPMR_EQCFG_M_BOOST_3 0x5
#define CLASSD_INTPMR_EQCFG_M_BOOST_8 0x6
#define CLASSD_INTPMR_EQCFG_M_CUT_3 0x7
#define CLASSD_INTPMR_EQCFG_M_CUT_8 0x8
#define CLASSD_INTPMR_EQCFG_T_BOOST_12 0x9
#define CLASSD_INTPMR_EQCFG_T_BOOST_6 0xa
#define CLASSD_INTPMR_EQCFG_T_CUT_12 0xb
#define CLASSD_INTPMR_EQCFG_T_CUT_6 0xc
#define CLASSD_INTPMR_EQCFG_SHIFT (24)
#define CLASSD_INTPMR_MONO_DIS 0x0
#define CLASSD_INTPMR_MONO_EN 0x1
#define CLASSD_INTPMR_MONO_MASK (0x1 << 28)
#define CLASSD_INTPMR_MONO_SHIFT (28)
#define CLASSD_INTPMR_MONO_MODE_MIX 0x0
#define CLASSD_INTPMR_MONO_MODE_SAT 0x1
#define CLASSD_INTPMR_MONO_MODE_LEFT 0x2
#define CLASSD_INTPMR_MONO_MODE_RIGHT 0x3
#define CLASSD_INTPMR_MONO_MODE_MASK (0x3 << 29)
#define CLASSD_INTPMR_MONO_MODE_SHIFT (29)
#define CLASSD_INTSR 0x0000000c
#define CLASSD_THR 0x00000010
#define CLASSD_IER 0x00000014
#define CLASSD_IDR 0x00000018
#define CLASSD_IMR 0x0000001c
#define CLASSD_ISR 0x00000020
#define CLASSD_WPMR 0x000000e4
#endif
......@@ -12,6 +12,7 @@
* option) any later version.
*/
#include <linux/clk.h>
#include <linux/delay.h>
#include <linux/i2c.h>
#include <linux/regmap.h>
......@@ -1222,23 +1223,44 @@ static int da7213_set_dai_sysclk(struct snd_soc_dai *codec_dai,
{
struct snd_soc_codec *codec = codec_dai->codec;
struct da7213_priv *da7213 = snd_soc_codec_get_drvdata(codec);
int ret = 0;
switch (clk_id) {
case DA7213_CLKSRC_MCLK:
if ((freq == 32768) ||
((freq >= 5000000) && (freq <= 54000000))) {
da7213->mclk_rate = freq;
if ((da7213->clk_src == clk_id) && (da7213->mclk_rate == freq))
return 0;
} else {
if (((freq < 5000000) && (freq != 32768)) || (freq > 54000000)) {
dev_err(codec_dai->dev, "Unsupported MCLK value %d\n",
freq);
return -EINVAL;
}
switch (clk_id) {
case DA7213_CLKSRC_MCLK:
da7213->mclk_squarer_en = false;
break;
case DA7213_CLKSRC_MCLK_SQR:
da7213->mclk_squarer_en = true;
break;
default:
dev_err(codec_dai->dev, "Unknown clock source %d\n", clk_id);
return -EINVAL;
}
da7213->clk_src = clk_id;
if (da7213->mclk) {
freq = clk_round_rate(da7213->mclk, freq);
ret = clk_set_rate(da7213->mclk, freq);
if (ret) {
dev_err(codec_dai->dev, "Failed to set clock rate %d\n",
freq);
return ret;
}
}
da7213->mclk_rate = freq;
return 0;
}
/* Supported PLL input frequencies are 5MHz - 54MHz. */
......@@ -1366,12 +1388,25 @@ static struct snd_soc_dai_driver da7213_dai = {
static int da7213_set_bias_level(struct snd_soc_codec *codec,
enum snd_soc_bias_level level)
{
struct da7213_priv *da7213 = snd_soc_codec_get_drvdata(codec);
int ret;
switch (level) {
case SND_SOC_BIAS_ON:
case SND_SOC_BIAS_PREPARE:
break;
case SND_SOC_BIAS_STANDBY:
if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) {
/* MCLK */
if (da7213->mclk) {
ret = clk_prepare_enable(da7213->mclk);
if (ret) {
dev_err(codec->dev,
"Failed to enable mclk\n");
return ret;
}
}
/* Enable VMID reference & master bias */
snd_soc_update_bits(codec, DA7213_REFERENCES,
DA7213_VMID_EN | DA7213_BIAS_EN,
......@@ -1382,15 +1417,127 @@ static int da7213_set_bias_level(struct snd_soc_codec *codec,
/* Disable VMID reference & master bias */
snd_soc_update_bits(codec, DA7213_REFERENCES,
DA7213_VMID_EN | DA7213_BIAS_EN, 0);
/* MCLK */
if (da7213->mclk)
clk_disable_unprepare(da7213->mclk);
break;
}
return 0;
}
/* DT */
static const struct of_device_id da7213_of_match[] = {
{ .compatible = "dlg,da7213", },
{ }
};
MODULE_DEVICE_TABLE(of, da7213_of_match);
static enum da7213_micbias_voltage
da7213_of_micbias_lvl(struct snd_soc_codec *codec, u32 val)
{
switch (val) {
case 1600:
return DA7213_MICBIAS_1_6V;
case 2200:
return DA7213_MICBIAS_2_2V;
case 2500:
return DA7213_MICBIAS_2_5V;
case 3000:
return DA7213_MICBIAS_3_0V;
default:
dev_warn(codec->dev, "Invalid micbias level\n");
return DA7213_MICBIAS_2_2V;
}
}
static enum da7213_dmic_data_sel
da7213_of_dmic_data_sel(struct snd_soc_codec *codec, const char *str)
{
if (!strcmp(str, "lrise_rfall")) {
return DA7213_DMIC_DATA_LRISE_RFALL;
} else if (!strcmp(str, "lfall_rrise")) {
return DA7213_DMIC_DATA_LFALL_RRISE;
} else {
dev_warn(codec->dev, "Invalid DMIC data select type\n");
return DA7213_DMIC_DATA_LRISE_RFALL;
}
}
static enum da7213_dmic_samplephase
da7213_of_dmic_samplephase(struct snd_soc_codec *codec, const char *str)
{
if (!strcmp(str, "on_clkedge")) {
return DA7213_DMIC_SAMPLE_ON_CLKEDGE;
} else if (!strcmp(str, "between_clkedge")) {
return DA7213_DMIC_SAMPLE_BETWEEN_CLKEDGE;
} else {
dev_warn(codec->dev, "Invalid DMIC sample phase\n");
return DA7213_DMIC_SAMPLE_ON_CLKEDGE;
}
}
static enum da7213_dmic_clk_rate
da7213_of_dmic_clkrate(struct snd_soc_codec *codec, u32 val)
{
switch (val) {
case 1500000:
return DA7213_DMIC_CLK_1_5MHZ;
case 3000000:
return DA7213_DMIC_CLK_3_0MHZ;
default:
dev_warn(codec->dev, "Invalid DMIC clock rate\n");
return DA7213_DMIC_CLK_1_5MHZ;
}
}
static struct da7213_platform_data
*da7213_of_to_pdata(struct snd_soc_codec *codec)
{
struct device_node *np = codec->dev->of_node;
struct da7213_platform_data *pdata;
const char *of_str;
u32 of_val32;
pdata = devm_kzalloc(codec->dev, sizeof(*pdata), GFP_KERNEL);
if (!pdata) {
dev_warn(codec->dev, "Failed to allocate memory for pdata\n");
return NULL;
}
if (of_property_read_u32(np, "dlg,micbias1-lvl", &of_val32) >= 0)
pdata->micbias1_lvl = da7213_of_micbias_lvl(codec, of_val32);
else
pdata->micbias1_lvl = DA7213_MICBIAS_2_2V;
if (of_property_read_u32(np, "dlg,micbias2-lvl", &of_val32) >= 0)
pdata->micbias2_lvl = da7213_of_micbias_lvl(codec, of_val32);
else
pdata->micbias2_lvl = DA7213_MICBIAS_2_2V;
if (!of_property_read_string(np, "dlg,dmic-data-sel", &of_str))
pdata->dmic_data_sel = da7213_of_dmic_data_sel(codec, of_str);
else
pdata->dmic_data_sel = DA7213_DMIC_DATA_LRISE_RFALL;
if (!of_property_read_string(np, "dlg,dmic-samplephase", &of_str))
pdata->dmic_samplephase =
da7213_of_dmic_samplephase(codec, of_str);
else
pdata->dmic_samplephase = DA7213_DMIC_SAMPLE_ON_CLKEDGE;
if (of_property_read_u32(np, "dlg,dmic-clkrate", &of_val32) >= 0)
pdata->dmic_clk_rate = da7213_of_dmic_clkrate(codec, of_val32);
else
pdata->dmic_clk_rate = DA7213_DMIC_CLK_3_0MHZ;
return pdata;
}
static int da7213_probe(struct snd_soc_codec *codec)
{
struct da7213_priv *da7213 = snd_soc_codec_get_drvdata(codec);
struct da7213_platform_data *pdata = da7213->pdata;
/* Default to using ALC auto offset calibration mode. */
snd_soc_update_bits(codec, DA7213_ALC_CTRL1,
......@@ -1450,8 +1597,15 @@ static int da7213_probe(struct snd_soc_codec *codec)
snd_soc_update_bits(codec, DA7213_LINE_CTRL,
DA7213_LINE_AMP_OE, DA7213_LINE_AMP_OE);
/* Handle DT/Platform data */
if (codec->dev->of_node)
da7213->pdata = da7213_of_to_pdata(codec);
else
da7213->pdata = dev_get_platdata(codec->dev);
/* Set platform data values */
if (da7213->pdata) {
struct da7213_platform_data *pdata = da7213->pdata;
u8 micbias_lvl = 0, dmic_cfg = 0;
/* Set Mic Bias voltages */
......@@ -1503,10 +1657,17 @@ static int da7213_probe(struct snd_soc_codec *codec)
DA7213_DMIC_DATA_SEL_MASK |
DA7213_DMIC_SAMPLEPHASE_MASK |
DA7213_DMIC_CLK_RATE_MASK, dmic_cfg);
}
/* Set MCLK squaring */
da7213->mclk_squarer_en = pdata->mclk_squaring;
/* Check if MCLK provided */
da7213->mclk = devm_clk_get(codec->dev, "mclk");
if (IS_ERR(da7213->mclk)) {
if (PTR_ERR(da7213->mclk) != -ENOENT)
return PTR_ERR(da7213->mclk);
else
da7213->mclk = NULL;
}
return 0;
}
......@@ -1537,7 +1698,6 @@ static int da7213_i2c_probe(struct i2c_client *i2c,
const struct i2c_device_id *id)
{
struct da7213_priv *da7213;
struct da7213_platform_data *pdata = dev_get_platdata(&i2c->dev);
int ret;
da7213 = devm_kzalloc(&i2c->dev, sizeof(struct da7213_priv),
......@@ -1545,9 +1705,6 @@ static int da7213_i2c_probe(struct i2c_client *i2c,
if (!da7213)
return -ENOMEM;
if (pdata)
da7213->pdata = pdata;
i2c_set_clientdata(i2c, da7213);
da7213->regmap = devm_regmap_init_i2c(i2c, &da7213_regmap_config);
......@@ -1582,6 +1739,7 @@ MODULE_DEVICE_TABLE(i2c, da7213_i2c_id);
static struct i2c_driver da7213_i2c_driver = {
.driver = {
.name = "da7213",
.of_match_table = of_match_ptr(da7213_of_match),
},
.probe = da7213_i2c_probe,
.remove = da7213_remove,
......
......@@ -13,6 +13,7 @@
#ifndef _DA7213_H
#define _DA7213_H
#include <linux/clk.h>
#include <linux/regmap.h>
#include <sound/da7213.h>
......@@ -504,14 +505,17 @@
#define DA7213_PLL_INDIV_20_40_MHZ_VAL 8
#define DA7213_PLL_INDIV_40_54_MHZ_VAL 16
enum clk_src {
DA7213_CLKSRC_MCLK
enum da7213_clk_src {
DA7213_CLKSRC_MCLK = 0,
DA7213_CLKSRC_MCLK_SQR,
};
/* Codec private data */
struct da7213_priv {
struct regmap *regmap;
struct clk *mclk;
unsigned int mclk_rate;
int clk_src;
bool master;
bool mclk_squarer_en;
bool srm_en;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment