Skip to contentSkip to conversation

ASoC: rt5660: add rt5660 codec driver

PATCH Superseded Oder Chiou 2 participants 3 messages Aug 23, 2016 – Sep 19, 2016 1 message not in the archive

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Oder Chiou

author maintainer
#0 lore raw

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

This is the initial codec driver for rt5660

---
 Documentation/devicetree/bindings/sound/rt5660.txt |   50 +
 include/sound/rt5660.h                             |   31 +
 sound/soc/codecs/Kconfig                           |    6 +
 sound/soc/codecs/Makefile                          |    2 +
 sound/soc/codecs/rt5660.c                          | 1364 ++++++++++++++++++++
 sound/soc/codecs/rt5660.h                          |  847 ++++++++++++
 6 files changed, 2300 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/rt5660.txt
 create mode 100644 include/sound/rt5660.h
 create mode 100644 sound/soc/codecs/rt5660.c
 create mode 100644 sound/soc/codecs/rt5660.h
Documentation/devicetree/bindings/sound/rt5660.txt new file +50 -0
new file mode 100644
index 0000000..c6cdb0d
@@ -0,0 +1,50 @@
+RT5660 audio CODEC
+
+This device supports I2C only.
+
+Required properties:
+
+- compatible : "realtek,rt5660".
+
+- reg : The I2C address of the device.
+
+Optional properties:
+
+- clocks: The phandle of the master clock to the CODEC
+- clock-names: Should be "mclk"
+
+- realtek,in1-differential
+- realtek,in3-differential
+  Boolean. Indicate MIC1/3 input are differential, rather than single-ended.
+
+- realtek,use-ldo2
+  Boolean. Use LDO2 for MICVDD
+
+- realtek,poweroff-in-suspend
+  Boolean. If the codec will be powered off in suspend, the resume should be
+  added delay time for waiting codec power ready.
+
+- realtek,dmic1-data-pin
+  0: dmic1 is not used
+  1: using GPIO2 pin as dmic1 data pin
+  2: using IN1P pin as dmic1 data pin
+
+Pins on the device (for linking into audio routes) for RT5660:
+
+  * DMIC L1
+  * DMIC R1
+  * IN1P
+  * IN1N
+  * IN2P
+  * IN3P
+  * IN3N
+  * SPO
+  * LOUTL
+  * LOUTR
+
+Example:
+
+rt5660 {
+	compatible = "realtek,rt5660";
+	reg = <0x1c>;
+};
include/sound/rt5660.h new file +31 -0
new file mode 100644
index 0000000..065f83a
@@ -0,0 +1,31 @@
+/*
+ * linux/sound/rt5660.h -- Platform data for RT5660
+ *
+ * Copyright 2016 Realtek Semiconductor Corp.
+ * Author: Oder Chiou <[email protected]>
+ *
+ * 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 __LINUX_SND_RT5660_H
+#define __LINUX_SND_RT5660_H
+
+enum rt5660_dmic1_data_pin {
+	RT5660_DMIC1_NULL,
+	RT5660_DMIC1_DATA_GPIO2,
+	RT5660_DMIC1_DATA_IN1P,
+};
+
+struct rt5660_platform_data {
+	/* IN1 & IN3 can optionally be differential */
+	bool in1_diff;
+	bool in3_diff;
+	bool use_ldo2;
+	bool poweroff_codec_in_suspend;
+
+	enum rt5660_dmic1_data_pin dmic1_data_pin;
+};
+
+#endif
sound/soc/codecs/Kconfig +6 -0
index 1cd6ab3..890affe 100644
@@ -112,6 +112,7 @@ config SND_SOC_ALL_CODECS
 	select SND_SOC_RT5645 if I2C
 	select SND_SOC_RT5651 if I2C
 	select SND_SOC_RT5659 if I2C
+	select SND_SOC_RT5660 if I2C
 	select SND_SOC_RT5670 if I2C
 	select SND_SOC_RT5677 if I2C && SPI_MASTER
 	select SND_SOC_SGTL5000 if I2C
@@ -645,6 +646,7 @@ config SND_SOC_RL6231
 	default y if SND_SOC_RT5645=y
 	default y if SND_SOC_RT5651=y
 	default y if SND_SOC_RT5659=y
+	default y if SND_SOC_RT5660=y
 	default y if SND_SOC_RT5670=y
 	default y if SND_SOC_RT5677=y
 	default m if SND_SOC_RT5514=m
@@ -653,6 +655,7 @@ config SND_SOC_RL6231
 	default m if SND_SOC_RT5645=m
 	default m if SND_SOC_RT5651=m
 	default m if SND_SOC_RT5659=m
+	default m if SND_SOC_RT5660=m
 	default m if SND_SOC_RT5670=m
 	default m if SND_SOC_RT5677=m
 
@@ -697,6 +700,9 @@ config SND_SOC_RT5651
 config SND_SOC_RT5659
 	tristate
 
+config SND_SOC_RT5660
+	tristate
+
 config SND_SOC_RT5670
 	tristate
 
sound/soc/codecs/Makefile +2 -0
index 58036af..68fed20 100644
@@ -112,6 +112,7 @@ snd-soc-rt5640-objs := rt5640.o
 snd-soc-rt5645-objs := rt5645.o
 snd-soc-rt5651-objs := rt5651.o
 snd-soc-rt5659-objs := rt5659.o
+snd-soc-rt5660-objs := rt5660.o
 snd-soc-rt5670-objs := rt5670.o
 snd-soc-rt5677-objs := rt5677.o
 snd-soc-rt5677-spi-objs := rt5677-spi.o
@@ -333,6 +334,7 @@ obj-$(CONFIG_SND_SOC_RT5640)	+= snd-soc-rt5640.o
 obj-$(CONFIG_SND_SOC_RT5645)	+= snd-soc-rt5645.o
 obj-$(CONFIG_SND_SOC_RT5651)	+= snd-soc-rt5651.o
 obj-$(CONFIG_SND_SOC_RT5659)	+= snd-soc-rt5659.o
+obj-$(CONFIG_SND_SOC_RT5660)	+= snd-soc-rt5660.o
 obj-$(CONFIG_SND_SOC_RT5670)	+= snd-soc-rt5670.o
 obj-$(CONFIG_SND_SOC_RT5677)	+= snd-soc-rt5677.o
 obj-$(CONFIG_SND_SOC_RT5677_SPI)	+= snd-soc-rt5677-spi.o
sound/soc/codecs/rt5660.c new file +1364 -0

1,364 lines not on this page · raw message

sound/soc/codecs/rt5660.h new file +847 -0

847 lines not on this page · raw message

Signature · 1 line
1.8.1.1.439.g50a6b54
maintainer
#1 lore raw
Quoted 1 line · Oder Chiou

+- realtek,use-ldo2

This would more normally be done by making LDO2 a regulator via the normal regulator framework - look at how the arizona drivers handle DCVDD for an example, it provides a default supply mapping which makes things really easy for users. Right now it's not clear to me looking at the code that the driver works for systems that don't use an internal LDO as there's nothing that enables MICVDD.

sound/soc/codecs/rt5660.c line 1141

Quoted 8 lines
sound/soc/codecs/rt5660.c new file +8 -0
+static int rt5660_probe(struct snd_soc_codec *codec)
+{
+	struct rt5660_priv *rt5660 = snd_soc_codec_get_drvdata(codec);
+
+	/* Check if MCLK provided */
+	rt5660->mclk = devm_clk_get(codec->dev, "mclk");
+	if (PTR_ERR(rt5660->mclk) == -EPROBE_DEFER)
+		return -EPROBE_DEFER;

This should be in the I2C level probe so we don't have the device showing as probing there without the resources it needs being present as that makes things confusing for people.

sound/soc/codecs/rt5660.c line 1337

Quoted 13 lines
sound/soc/codecs/rt5660.c new file +13 -0
+	if (rt5660->pdata.dmic1_data_pin) {
+		regmap_update_bits(rt5660->regmap, RT5660_GPIO_CTRL1,
+			RT5660_GP1_PIN_MASK, RT5660_GP1_PIN_DMIC1_SCL);
+
+		if (rt5660->pdata.dmic1_data_pin == RT5660_DMIC1_DATA_GPIO2)
+			regmap_update_bits(rt5660->regmap, RT5660_DMIC_CTRL1,
+				RT5660_SEL_DMIC_DATA_MASK,
+				RT5660_SEL_DMIC_DATA_GPIO2);
+		else if (rt5660->pdata.dmic1_data_pin == RT5660_DMIC1_DATA_IN1P)
+			regmap_update_bits(rt5660->regmap, RT5660_DMIC_CTRL1,
+				RT5660_SEL_DMIC_DATA_MASK,
+				RT5660_SEL_DMIC_DATA_IN1P);
+	}

We do a reset when we unregister at the CODEC level - that'll overwrite these settings won't it?

Otherwise this looks good.

A message that is not in the archive (sent off-list or not yet received): 7EB0DE829A537248AF2ED30C97D12694010056A8@RTITMBSV03.realtek.com.tw

maintainer
#3 lore raw
Quoted 11 lines · Oder Chiou
Quoted 10 lines · Oder Chiou
Quoted 2 lines

+- realtek,use-ldo2

This would more normally be done by making LDO2 a regulator via the normal regulator framework - look at how the arizona drivers handle DCVDD for an example, it provides a default supply mapping which makes things really easy for users. Right now it's not clear to me looking at the code that the driver works for systems that don't use an internal LDO as there's nothing that enables MICVDD.

Quoted 2 lines

The LDO2 is not a regulator, and it is an internal LDO of codec that controlled by register setting. Normally, the MICVDD is connected to 3.3V

It's an internal regulator in the CODEC.

Quoted 4 lines

VDD directly, and it isn't controlled by regulator. The option "realtek,use-ldo2" is depend on the customer that can decide that the MICVDD is provided by external 3.3V VDD or internal LDO2 for it. If they used the internal LDO2, the pin of MICVDD can be floated.

Sure, that's exactly what it looks like so my comments above apply.

Quoted 4 lines
Quoted 2 lines

We do a reset when we unregister at the CODEC level - that'll overwrite these settings won't it?

We have done it in the function "rt5660_remove".

Right, and if the user removes and reloads the driver then the reset will happen.