Skip to contentSkip to conversation

ASoC: add RT286 CODEC driver

PATCH In review [email protected] 2 participants 2 messages Jun 20, 2014 – Jul 4, 2014

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v7 1/1 ASoC: add RT286 CODEC driver

From: Bard Liao <[email protected]>

This patch adds Realtek ALC286 codec driver.

ALC286 is a dual mode codec, which can run as HD-A or I2S mode. It is controlled by HD-A verb commands via I2C protocol.
The following is the I/O difference between ALC286 and general I2S codecs.
1. A HD-A verb command contains three parts, NID, VID, and PID. And an I2S command contains only two parts: address and data.
2. Not only the register address is written, but the read command also includes the entire write command.
3. rt286 uses different registers for read and write the same bits.

We map verb command to regmap structure. However, we read most registers from cache to prevent the asymmetry read/write issue in rt286.

---
The jack detection function is done by Lewandowski Gustaw. So I add Gustaw's Signed-off-by line in this patch

The difference between this version and previous version is listed below.
* Use regmap for IO control.

---
 include/sound/rt286.h     |   19 +
 sound/soc/codecs/Kconfig  |    4 +
 sound/soc/codecs/Makefile |    2 +
 sound/soc/codecs/rt286.c  | 1208 +++++++++++++++++++++++++++++++++++++++++++++
 sound/soc/codecs/rt286.h  |  193 ++++++++
 5 files changed, 1426 insertions(+)
 create mode 100644 include/sound/rt286.h
 create mode 100644 sound/soc/codecs/rt286.c
 create mode 100644 sound/soc/codecs/rt286.h
include/sound/rt286.h new file +19 -0
new file mode 100644
index 0000000..eb773d1
@@ -0,0 +1,19 @@
+/*
+ * linux/sound/rt286.h -- Platform data for RT286
+ *
+ * Copyright 2013 Realtek Microelectronics
+ *
+ * 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_RT286_H
+#define __LINUX_SND_RT286_H
+
+struct rt286_platform_data {
+	bool cbj_en; /*combo jack enable*/
+	bool gpio2_en; /*GPIO2 enable*/
+};
+
+#endif
sound/soc/codecs/Kconfig +4 -0
index 7541fa7..1c5eee3 100644
@@ -74,6 +74,7 @@ config SND_SOC_ALL_CODECS
 	select SND_SOC_PCM3008
 	select SND_SOC_PCM512x_I2C if I2C
 	select SND_SOC_PCM512x_SPI if SPI_MASTER
+	select SND_SOC_RT286 if I2C
 	select SND_SOC_RT5631 if I2C
 	select SND_SOC_RT5640 if I2C
 	select SND_SOC_RT5645 if I2C
@@ -451,6 +452,9 @@ config SND_SOC_RL6231
 	default m if SND_SOC_RT5651=m
 	default m if SND_SOC_RT5677=m
 
+config SND_SOC_RT286
+	tristate
+
 config SND_SOC_RT5631
 	tristate
 
sound/soc/codecs/Makefile +2 -0
index 1bd6e1c..3302f95 100644
@@ -68,6 +68,7 @@ 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-rt286-objs := rt286.o
 snd-soc-rt5631-objs := rt5631.o
 snd-soc-rt5640-objs := rt5640.o
 snd-soc-rt5645-objs := rt5645.o
@@ -235,6 +236,7 @@ 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_RT286)	+= snd-soc-rt286.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
sound/soc/codecs/rt286.c new file +1208 -0

1,208 lines not on this page · raw message

sound/soc/codecs/rt286.h new file +193 -0

193 lines not on this page · raw message

Signature · 1 line
1.8.1.1.439.g50a6b54
maintainer
#1 lore raw
Quoted 3 lines · On Fri, Jun 20, 2014 at 02:41:13PM +0800, [email protected] wrote:

From: Bard Liao <[email protected]>

This patch adds Realtek ALC286 codec driver.

I've applied this but there are small number of remaining issues which should be fixed - please send followup patches for them.

sound/soc/codecs/rt286.c line 961

Quoted 12 lines
sound/soc/codecs/rt286.c new file +12 -0
+static int rt286_probe(struct snd_soc_codec *codec)
+{
+	struct rt286_priv *rt286 = snd_soc_codec_get_drvdata(codec);
+	int i, ret;
+
+	ret = snd_soc_read(codec,
+		RT286_GET_PARAM(AC_NODE_ROOT, AC_PAR_VENDOR_ID));
+	if (ret != RT286_VENDOR_ID) {
+		dev_err(codec->dev,
+			"Device with ID register %x is not rt286\n", ret);
+		return -ENODEV;
+	}

Most of this probe function doesn't depend on ASoC at all and so should be done at the I2C level probe not here - that way errors are detected earlier and the device is initialised even if the sound card as a whole isn't ready yet.

sound/soc/codecs/rt286.c line 981

Quoted 12 lines
sound/soc/codecs/rt286.c new file +12 -0
+	if (!rt286->pdata.cbj_en) {
+		snd_soc_write(codec, RT286_CBJ_CTRL2, 0x0000);
+		snd_soc_write(codec, RT286_MIC1_DET_CTRL, 0x0816);
+		snd_soc_write(codec, RT286_MISC_CTRL1, 0x0000);
+		snd_soc_update_bits(codec,
+					RT286_CBJ_CTRL1, 0xf000, 0xb000);
+	} else {
+		snd_soc_update_bits(codec,
+					RT286_CBJ_CTRL1, 0xf000, 0x5000);
+	}
+
+	mdelay(10);

I notice that the resume doesn't have these delays in it - is that not a problem if the device lost power over suspend?

sound/soc/codecs/rt286.c line 997

Quoted 2 lines
sound/soc/codecs/rt286.c new file +2 -0
+	rt286->i2c->irq = 0;
+	if (rt286->i2c->irq) {

The assignment looks like some test code which was left in by mistake.

sound/soc/codecs/rt286.c line 1008

Quoted 3 lines
sound/soc/codecs/rt286.c new file +3 -0
+		ret = request_threaded_irq(rt286->i2c->irq, NULL, rt286_irq,
+			IRQF_TRIGGER_HIGH | IRQF_ONESHOT, "rt286", rt286);
+		if (ret != 0) {

This is only released in the I2C level remove() (the the fix should be to move the request to the I2C level probe()).