Skip to contentSkip to conversation

ASoC: rt5514: add rt5514 codec driver

PATCH Superseded Oder Chiou 2 participants 2 messages Jan 19, 2016 – Jan 29, 2016

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Oder Chiou

author maintainer
#0 lore raw

PATCH 1/1 ASoC: rt5514: add rt5514 codec driver

This is the initial codec driver for rt5514.

---
 Documentation/devicetree/bindings/sound/rt5514.txt |   25 +
 sound/soc/codecs/Kconfig                           |    6 +
 sound/soc/codecs/Makefile                          |    2 +
 sound/soc/codecs/rt5514.c                          | 1047 ++++++++++++++++++++
 sound/soc/codecs/rt5514.h                          |  252 +++++
 5 files changed, 1332 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/rt5514.txt
 create mode 100644 sound/soc/codecs/rt5514.c
 create mode 100644 sound/soc/codecs/rt5514.h
Documentation/devicetree/bindings/sound/rt5514.txt new file +25 -0
new file mode 100644
index 0000000..e24436f
@@ -0,0 +1,25 @@
+RT5514 audio CODEC
+
+This device supports I2C only.
+
+Required properties:
+
+- compatible : "realtek,rt5514".
+
+- reg : The I2C address of the device.
+
+Pins on the device (for linking into audio routes) for RT5514:
+
+  * DMIC1L
+  * DMIC1R
+  * DMIC2L
+  * DMIC2R
+  * AMICL
+  * AMICR
+
+Example:
+
+codec: rt5514@57 {
+	compatible = "realtek,rt5514";
+	reg = <0x57>;
+};
sound/soc/codecs/Kconfig +6 -0
index 50693c8..dabd479 100644
@@ -95,6 +95,7 @@ config SND_SOC_ALL_CODECS
 	select SND_SOC_PCM512x_SPI if SPI_MASTER
 	select SND_SOC_RT286 if I2C
 	select SND_SOC_RT298 if I2C
+	select SND_SOC_RT5514 if I2C
 	select SND_SOC_RT5616 if I2C
 	select SND_SOC_RT5631 if I2C
 	select SND_SOC_RT5640 if I2C
@@ -565,6 +566,7 @@ config SND_SOC_PCM512x_SPI
 
 config SND_SOC_RL6231
 	tristate
+	default y if SND_SOC_RT5514=y
 	default y if SND_SOC_RT5616=y
 	default y if SND_SOC_RT5640=y
 	default y if SND_SOC_RT5645=y
@@ -572,6 +574,7 @@ config SND_SOC_RL6231
 	default y if SND_SOC_RT5659=y
 	default y if SND_SOC_RT5670=y
 	default y if SND_SOC_RT5677=y
+	default m if SND_SOC_RT5514=m
 	default m if SND_SOC_RT5616=m
 	default m if SND_SOC_RT5640=m
 	default m if SND_SOC_RT5645=m
@@ -595,6 +598,9 @@ config SND_SOC_RT298
 	tristate
 	depends on I2C
 
+config SND_SOC_RT5514
+	tristate
+
 config SND_SOC_RT5616
 	tristate
 
sound/soc/codecs/Makefile +2 -0
index d44f7d3..79f95dd 100644
@@ -92,6 +92,7 @@ snd-soc-rl6231-objs := rl6231.o
 snd-soc-rl6347a-objs := rl6347a.o
 snd-soc-rt286-objs := rt286.o
 snd-soc-rt298-objs := rt298.o
+snd-soc-rt5514-objs := rt5514.o
 snd-soc-rt5616-objs := rt5616.o
 snd-soc-rt5631-objs := rt5631.o
 snd-soc-rt5640-objs := rt5640.o
@@ -296,6 +297,7 @@ obj-$(CONFIG_SND_SOC_RL6231)	+= snd-soc-rl6231.o
 obj-$(CONFIG_SND_SOC_RL6347A)	+= snd-soc-rl6347a.o
 obj-$(CONFIG_SND_SOC_RT286)	+= snd-soc-rt286.o
 obj-$(CONFIG_SND_SOC_RT298)	+= snd-soc-rt298.o
+obj-$(CONFIG_SND_SOC_RT5514)	+= snd-soc-rt5514.o
 obj-$(CONFIG_SND_SOC_RT5616)	+= snd-soc-rt5616.o
 obj-$(CONFIG_SND_SOC_RT5631)	+= snd-soc-rt5631.o
 obj-$(CONFIG_SND_SOC_RT5640)	+= snd-soc-rt5640.o
sound/soc/codecs/rt5514.c new file +1047 -0

1,047 lines not on this page · raw message

sound/soc/codecs/rt5514.h new file +252 -0

252 lines not on this page · raw message

Signature · 1 line
1.8.1.1.439.g50a6b54
maintainer
#1 lore raw

sound/soc/codecs/rt5514.c line 313

Quoted 2 lines · Oder Chiou
sound/soc/codecs/rt5514.c new file +2 -0
+	pr_warn("Base clock rate %d is too high\n", rate);
+	return -EINVAL;

dev_warn()

Quoted 10 lines
sound/soc/codecs/rt5514.c new file +10 -0
+static int rt5514_adc_power_event(struct snd_soc_dapm_widget *w,
+	struct snd_kcontrol *kcontrol, int event)
+{
+	struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
+	struct rt5514_priv *rt5514 = snd_soc_codec_get_drvdata(codec);
+
+	switch (event) {
+	case SND_SOC_DAPM_PRE_PMU:
+		regmap_update_bits(rt5514->regmap, RT5514_PWR_ANA1,
+			RT5514_POW_LDO18_IN | RT5514_POW_LDO18_ADC |

sound/soc/codecs/rt5514.c line 353

Quoted 10 lines
sound/soc/codecs/rt5514.c new file +10 -0
+			RT5514_POW_LDO21 | RT5514_POW_BG_LDO18_IN |
+			RT5514_POW_BG_LDO21,
+			RT5514_POW_LDO18_IN | RT5514_POW_LDO18_ADC |
+			RT5514_POW_LDO21 | RT5514_POW_BG_LDO18_IN |
+			RT5514_POW_BG_LDO21);
+		regmap_update_bits(rt5514->regmap, RT5514_PWR_ANA2,
+			RT5514_POW_BG_MBIAS | RT5514_POW_MBIAS |
+			RT5514_POW_VREF2 | RT5514_POW_VREF1,
+			RT5514_POW_BG_MBIAS | RT5514_POW_MBIAS |
+			RT5514_POW_VREF2 | RT5514_POW_VREF1);

This looks suspicously like there are a lot of supplies here that could be handled by supply widgets?

sound/soc/codecs/rt5514.c line 598

Quoted 1 line
sound/soc/codecs/rt5514.c new file +1 -0
+	bclk_ms = frame_size > 32 ? 1 : 0;

Please write normal if statements, it makes things easier to read.

Quoted 5 lines
sound/soc/codecs/rt5514.c new file +5 -0
+static int rt5514_remove(struct snd_soc_codec *codec)
+{
+	return 0;
+}
+

sound/soc/codecs/rt5514.c line 846

Quoted 10 lines
sound/soc/codecs/rt5514.c new file +10 -0
+#ifdef CONFIG_PM
+static int rt5514_suspend(struct snd_soc_codec *codec)
+{
+	return 0;
+}
+
+static int rt5514_resume(struct snd_soc_codec *codec)
+{
+	return 0;
+}

Just remove empty functions.

sound/soc/codecs/rt5514.c line 857

Quoted 6 lines
sound/soc/codecs/rt5514.c new file +6 -0
+static int rt5514_i2c_read(void *context, unsigned int reg, unsigned int *val)
+{
+	struct i2c_client *client = context;
+	struct rt5514_priv *rt5514 = i2c_get_clientdata(client);
+
+	regmap_read(rt5514->regmap_physical, reg | RT5514_DSP_MAPPING, val);

Some comments or something in the changelog explaining what's going on with this multi-level register map would be good. The naming of these functions is a bit odd, I'd expect _i2c_ for the physical regmap but actually these are for accessing the DSP register map AIUI?

I *think* this is OK but the explanation would help me be sure (and hopefully anyone working with the driver in the future).

sound/soc/codecs/rt5514.c line 957

Quoted 4 lines
sound/soc/codecs/rt5514.c new file +4 -0
+static void rt5514_reset(struct rt5514_priv *rt5514)
+{
+	regmap_write(rt5514->regmap_physical, 0x1800101c, 0x00000000);
+	regmap_write(rt5514->regmap_physical, 0x18001100, 0x0000031f);

This is a fun set of magic numbers! I'm wondering if it might be better as a regmap patch? Normally patches are corrections to the register settings that get applied after something is reset but perhaps this also applies here (or to some of the sequence)... It's the fact that it's a large set of magic numbers getting written in around reset, it looks like some of the purpose is the same.