All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 0/4] Audio Codec Driver of RK3036 SoC
@ 2015-10-13  1:01 ` Shunqian Zheng
  0 siblings, 0 replies; 28+ messages in thread
From: Shunqian Zheng @ 2015-10-13  1:01 UTC (permalink / raw)
  To: robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak, heiko,
	lgirdwood, broonie, perex, tiwai, benzh
  Cc: linux-arm-kernel, linux-kernel, linux-rockchip, alsa-devel,
	ZhengShunQian

From: ZhengShunQian <zhengsq@rock-chips.com>

Base on the other seris of RK3036 clk patches, which is not landed yet,
this patches add the RK3036 SoC codec driver.

Rockchip RK3036 SoC integrated with an Inno audio codec. It supports
the following features:
o. 24bit DAC
o. Support 16Ω to 32Ω headphone output and speaker output
o. Support Mono, Stereo channel
o. Sampling rate of 8/12/16/24/32/44.1/48/96KHz

While there are some features like dapm and s2r are still WIP,
I would like to send these patches now and get some feedback.

Thank you for your review.

ZhengShunQian (4):
  ASoC: codec: Inno codec driver for RK3036 SoC
  ASoC: RK3036: Add binding doc of inno-rk3036 codec driver
  ASoC: Add codec machine driver for RK3036
  ASoC: RK3036: Add binding doc for audio machine driver

 .../devicetree/bindings/sound/inno-rk3036.txt      |  20 +
 .../devicetree/bindings/sound/rockchip-rk3036.txt  |  14 +
 sound/soc/codecs/Kconfig                           |   4 +
 sound/soc/codecs/Makefile                          |   2 +
 sound/soc/codecs/inno_rk3036.c                     | 439 +++++++++++++++++++++
 sound/soc/codecs/inno_rk3036.h                     | 308 +++++++++++++++
 sound/soc/rockchip/Kconfig                         |  10 +
 sound/soc/rockchip/Makefile                        |   2 +
 sound/soc/rockchip/rockchip_rk3036.c               | 147 +++++++
 9 files changed, 946 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/inno-rk3036.txt
 create mode 100644 Documentation/devicetree/bindings/sound/rockchip-rk3036.txt
 create mode 100644 sound/soc/codecs/inno_rk3036.c
 create mode 100644 sound/soc/codecs/inno_rk3036.h
 create mode 100644 sound/soc/rockchip/rockchip_rk3036.c

-- 
1.9.1


^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH v1 0/4] Audio Codec Driver of RK3036 SoC
@ 2015-10-13  1:01 ` Shunqian Zheng
  0 siblings, 0 replies; 28+ messages in thread
From: Shunqian Zheng @ 2015-10-13  1:01 UTC (permalink / raw)
  To: linux-arm-kernel

From: ZhengShunQian <zhengsq@rock-chips.com>

Base on the other seris of RK3036 clk patches, which is not landed yet,
this patches add the RK3036 SoC codec driver.

Rockchip RK3036 SoC integrated with an Inno audio codec. It supports
the following features:
o. 24bit DAC
o. Support 16? to 32? headphone output and speaker output
o. Support Mono, Stereo channel
o. Sampling rate of 8/12/16/24/32/44.1/48/96KHz

While there are some features like dapm and s2r are still WIP,
I would like to send these patches now and get some feedback.

Thank you for your review.

ZhengShunQian (4):
  ASoC: codec: Inno codec driver for RK3036 SoC
  ASoC: RK3036: Add binding doc of inno-rk3036 codec driver
  ASoC: Add codec machine driver for RK3036
  ASoC: RK3036: Add binding doc for audio machine driver

 .../devicetree/bindings/sound/inno-rk3036.txt      |  20 +
 .../devicetree/bindings/sound/rockchip-rk3036.txt  |  14 +
 sound/soc/codecs/Kconfig                           |   4 +
 sound/soc/codecs/Makefile                          |   2 +
 sound/soc/codecs/inno_rk3036.c                     | 439 +++++++++++++++++++++
 sound/soc/codecs/inno_rk3036.h                     | 308 +++++++++++++++
 sound/soc/rockchip/Kconfig                         |  10 +
 sound/soc/rockchip/Makefile                        |   2 +
 sound/soc/rockchip/rockchip_rk3036.c               | 147 +++++++
 9 files changed, 946 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/inno-rk3036.txt
 create mode 100644 Documentation/devicetree/bindings/sound/rockchip-rk3036.txt
 create mode 100644 sound/soc/codecs/inno_rk3036.c
 create mode 100644 sound/soc/codecs/inno_rk3036.h
 create mode 100644 sound/soc/rockchip/rockchip_rk3036.c

-- 
1.9.1

^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH v1 1/4] ASoC: codec: Inno codec driver for RK3036 SoC
  2015-10-13  1:01 ` Shunqian Zheng
@ 2015-10-13  1:01   ` Shunqian Zheng
  -1 siblings, 0 replies; 28+ messages in thread
From: Shunqian Zheng @ 2015-10-13  1:01 UTC (permalink / raw)
  To: robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak, heiko,
	lgirdwood, broonie, perex, tiwai, benzh
  Cc: linux-arm-kernel, linux-kernel, linux-rockchip, alsa-devel,
	ZhengShunQian

From: ZhengShunQian <zhengsq@rock-chips.com>

RK3036 SoC integrated with an Inno audio codec. This driver
config the base function of codec. And the dapm is still WIP.

Signed-off-by: ZhengShunQian <zhengsq@rock-chips.com>
---
 sound/soc/codecs/Kconfig       |   4 +
 sound/soc/codecs/Makefile      |   2 +
 sound/soc/codecs/inno_rk3036.c | 439 +++++++++++++++++++++++++++++++++++++++++
 sound/soc/codecs/inno_rk3036.h | 308 +++++++++++++++++++++++++++++
 4 files changed, 753 insertions(+)
 create mode 100644 sound/soc/codecs/inno_rk3036.c
 create mode 100644 sound/soc/codecs/inno_rk3036.h

diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
index cfdafc4..e3cd3e7 100644
--- a/sound/soc/codecs/Kconfig
+++ b/sound/soc/codecs/Kconfig
@@ -471,6 +471,10 @@ config SND_SOC_GTM601
 config SND_SOC_ICS43432
 	tristate
 
+config SND_SOC_INNO_RK3036
+	tristate "Inno codec driver for RK3036 SoC"
+	depends on ARCH_ROCKCHIP
+
 config SND_SOC_ISABELLE
         tristate
 
diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile
index f632fc4..2f6bc6c 100644
--- a/sound/soc/codecs/Makefile
+++ b/sound/soc/codecs/Makefile
@@ -60,6 +60,7 @@ snd-soc-es8328-i2c-objs := es8328-i2c.o
 snd-soc-es8328-spi-objs := es8328-spi.o
 snd-soc-gtm601-objs := gtm601.o
 snd-soc-ics43432-objs := ics43432.o
+snd-soc-inno-rk3036-objs := inno_rk3036.o
 snd-soc-isabelle-objs := isabelle.o
 snd-soc-jz4740-codec-objs := jz4740.o
 snd-soc-l3-objs := l3.o
@@ -255,6 +256,7 @@ obj-$(CONFIG_SND_SOC_ES8328_I2C)+= snd-soc-es8328-i2c.o
 obj-$(CONFIG_SND_SOC_ES8328_SPI)+= snd-soc-es8328-spi.o
 obj-$(CONFIG_SND_SOC_GTM601)    += snd-soc-gtm601.o
 obj-$(CONFIG_SND_SOC_ICS43432)	+= snd-soc-ics43432.o
+obj-$(CONFIG_SND_SOC_INNO_RK3036)	+= snd-soc-inno-rk3036.o
 obj-$(CONFIG_SND_SOC_ISABELLE)	+= snd-soc-isabelle.o
 obj-$(CONFIG_SND_SOC_JZ4740_CODEC)	+= snd-soc-jz4740-codec.o
 obj-$(CONFIG_SND_SOC_L3)	+= snd-soc-l3.o
diff --git a/sound/soc/codecs/inno_rk3036.c b/sound/soc/codecs/inno_rk3036.c
new file mode 100644
index 0000000..e8e7356
--- /dev/null
+++ b/sound/soc/codecs/inno_rk3036.c
@@ -0,0 +1,439 @@
+/*
+ * Driver of Inno codec for rk3036 by Rockchip Inc.
+ *
+ * Author: Rockchip Inc.
+ * Author: Zheng ShunQian<zhengsq@rock-chips.com>
+ */
+
+#define DEBUG
+
+#include <sound/soc.h>
+#include <sound/soc-dai.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+
+#include <linux/platform_device.h>
+#include <linux/of.h>
+#include <linux/clk.h>
+#include <linux/regmap.h>
+#include <linux/device.h>
+#include <linux/delay.h>
+#include <linux/mfd/syscon.h>
+#include <linux/module.h>
+#include <linux/io.h>
+
+#include "inno_rk3036.h"
+
+struct rk3036_codec_priv {
+	void __iomem *base;
+	struct clk *pclk;
+	struct regmap *regmap;
+	struct device *dev;
+};
+
+static int rk3036_codec_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id,
+				       unsigned int fre, int dir)
+{
+	/* Nothing to be done here */
+	return 0;
+}
+
+static int rk3036_codec_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
+{
+	struct snd_soc_codec *codec = dai->codec;
+	unsigned int reg01_val = 0,  reg02_val = 0, reg03_val = 0;
+
+	dev_dbg(codec->dev, "rk3036_codec dai set fmt : %08x\n", fmt);
+
+	switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
+	case SND_SOC_DAIFMT_CBS_CFS:
+		reg01_val |= INNO_REG_01_PINDIR_IN_SLAVE |
+			     INNO_REG_01_I2SMODE_SLAVE;
+		break;
+	case SND_SOC_DAIFMT_CBM_CFM:
+		reg01_val |= INNO_REG_01_PINDIR_OUT_MASTER |
+			     INNO_REG_01_I2SMODE_MASTER;
+		break;
+	default:
+		dev_err(codec->dev, "invalid fmt\n");
+		return -EINVAL;
+	}
+
+	switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
+	case SND_SOC_DAIFMT_DSP_A:
+		reg02_val |= INNO_REG_02_DACM_PCM;
+		break;
+	case SND_SOC_DAIFMT_I2S:
+		reg02_val |= INNO_REG_02_DACM_I2S;
+		break;
+	case SND_SOC_DAIFMT_RIGHT_J:
+		reg02_val |= INNO_REG_02_DACM_RJM;
+		break;
+	case SND_SOC_DAIFMT_LEFT_J:
+		reg02_val |= INNO_REG_02_DACM_LJM;
+		break;
+	default:
+		dev_err(codec->dev, "set dai format failed\n");
+		return -EINVAL;
+	}
+
+	switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
+	case SND_SOC_DAIFMT_NB_NF:
+		reg02_val |= INNO_REG_02_LRCP_NORMAL;
+		reg03_val |= INNO_REG_03_BCP_NORMAL;
+		break;
+	case SND_SOC_DAIFMT_IB_IF:
+		reg02_val |= INNO_REG_02_LRCP_REVERSAL;
+		reg03_val |= INNO_REG_03_BCP_REVERSAL;
+		break;
+	case SND_SOC_DAIFMT_IB_NF:
+		reg02_val |= INNO_REG_02_LRCP_REVERSAL;
+		reg03_val |= INNO_REG_03_BCP_NORMAL;
+		break;
+	case SND_SOC_DAIFMT_NB_IF:
+		reg02_val |= INNO_REG_02_LRCP_NORMAL;
+		reg03_val |= INNO_REG_03_BCP_REVERSAL;
+		break;
+	default:
+		dev_err(codec->dev, "set dai format failed\n");
+		return -EINVAL;
+	}
+
+	snd_soc_update_bits(codec, INNO_REG_01, INNO_REG_01_I2SMODE_MASK |
+			    INNO_REG_01_PINDIR_MASK, reg01_val);
+	snd_soc_update_bits(codec, INNO_REG_02, INNO_REG_02_LRCP_MASK |
+			    INNO_REG_02_DACM_MASK, reg02_val);
+	snd_soc_update_bits(codec, INNO_REG_03, INNO_REG_03_BCP_MASK,
+			    reg03_val);
+	return 0;
+}
+
+static int rk3036_codec_dai_digital_mute(struct snd_soc_dai *dai, int mute)
+{
+	struct snd_soc_codec *codec = dai->codec;
+	unsigned int val = 0;
+
+	dev_dbg(codec->dev, "rk3036_codec dai mute : %d\n", mute);
+	if (mute)
+		val |= INNO_REG_09_HP_OUTR_MUTE_YES |
+		       INNO_REG_09_HP_OUTL_MUTE_YES;
+	else
+		val |= INNO_REG_09_HP_OUTR_MUTE_NO |
+		       INNO_REG_09_HP_OUTL_MUTE_NO;
+
+	snd_soc_update_bits(codec, INNO_REG_09, INNO_REG_09_HP_OUTR_MUTE_MASK |
+			    INNO_REG_09_HP_OUTL_MUTE_MASK, val);
+	return 0;
+}
+
+static int rk3036_codec_dai_hw_params(struct snd_pcm_substream *substream,
+				      struct snd_pcm_hw_params *hw_params,
+				      struct snd_soc_dai *dai)
+{
+	struct snd_soc_codec *codec = dai->codec;
+	unsigned int reg02_val = 0, reg03_val = 0;
+
+	dev_dbg(codec->dev, "rk3036_codec dai hw_params");
+
+	switch (params_format(hw_params)) {
+	case SNDRV_PCM_FORMAT_S16_LE:
+		reg02_val |= INNO_REG_02_VWL_16BIT;
+		break;
+	case SNDRV_PCM_FORMAT_S20_3LE:
+		reg02_val |= INNO_REG_02_VWL_20BIT;
+		break;
+	case SNDRV_PCM_FORMAT_S24_LE:
+		reg02_val |= INNO_REG_02_VWL_24BIT;
+		break;
+	case SNDRV_PCM_FORMAT_S32_LE:
+		reg02_val |= INNO_REG_02_VWL_32BIT;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	reg02_val |= INNO_REG_02_LRCP_NORMAL;
+	reg03_val |= INNO_REG_03_FWL_32BIT | INNO_REG_03_DACR_WORK;
+
+	snd_soc_update_bits(codec, INNO_REG_02, INNO_REG_02_LRCP_MASK |
+			    INNO_REG_02_VWL_MASK, reg02_val);
+	snd_soc_update_bits(codec, INNO_REG_03, INNO_REG_03_DACR_MASK |
+			    INNO_REG_03_FWL_MASK, reg03_val);
+	return 0;
+}
+
+#define RK3036_CODEC_RATES (SNDRV_PCM_RATE_8000  | \
+			    SNDRV_PCM_RATE_16000 | \
+			    SNDRV_PCM_RATE_32000 | \
+			    SNDRV_PCM_RATE_44100 | \
+			    SNDRV_PCM_RATE_48000 | \
+			    SNDRV_PCM_RATE_96000)
+
+#define RK3036_CODEC_FMTS (SNDRV_PCM_FMTBIT_S16_LE  | \
+			   SNDRV_PCM_FMTBIT_S20_3LE | \
+			   SNDRV_PCM_FMTBIT_S24_LE  | \
+			   SNDRV_PCM_FMTBIT_S32_LE)
+
+struct snd_soc_dai_ops rk3036_codec_dai_ops = {
+	.set_sysclk	= rk3036_codec_dai_set_sysclk,
+	.set_fmt	= rk3036_codec_dai_set_fmt,
+	.digital_mute	= rk3036_codec_dai_digital_mute,
+	.hw_params	= rk3036_codec_dai_hw_params,
+};
+
+struct snd_soc_dai_driver rk3036_codec_dai_driver[] = {
+	{
+		.name = "rk3036-codec-dai",
+		.playback = {
+			.stream_name = "Playback",
+			.channels_min = 1,
+			.channels_max = 2,
+			.rates = RK3036_CODEC_RATES,
+			.formats = RK3036_CODEC_FMTS,
+		},
+		.ops = &rk3036_codec_dai_ops,
+		.symmetric_rates = 1,
+	},
+};
+
+static void rk3036_codec_reset(struct snd_soc_codec *codec)
+{
+	dev_dbg(codec->dev, "rk3036_codec reset\n");
+	snd_soc_write(codec, INNO_REG_00,
+		      INNO_REG_00_CSR_RESET | INNO_REG_00_CDCR_RESET);
+	mdelay(10);
+	snd_soc_write(codec, INNO_REG_00,
+		      INNO_REG_00_CSR_WORK | INNO_REG_00_CDCR_WORK);
+	mdelay(10);
+}
+
+static void rk3036_codec_power_off(struct snd_soc_codec *codec)
+{
+	struct inno_reg_val *reg_val;
+	int i;
+
+	dev_dbg(codec->dev, "rk3036_codec power off\n");
+	/* set a big current for capacitor charging. */
+	snd_soc_write(codec, INNO_REG_10, INNO_REG_10_MAX_CUR);
+	/* start discharge. */
+	snd_soc_write(codec, INNO_REG_06, INNO_REG_06_DAC_DISCHARGE);
+
+	for (i = 0; i < ARRAY_SIZE(inno_codec_close_path); i++) {
+		reg_val = &inno_codec_open_path[i];
+		snd_soc_write(codec, reg_val->reg, reg_val->val);
+		mdelay(5);
+	}
+}
+
+static void rk3036_codec_power_on(struct snd_soc_codec *codec)
+{
+	struct inno_reg_val *reg_val;
+	int i;
+
+	dev_dbg(codec->dev, "rk3036_codec power on\n");
+	/* set a big current for capacitor discharging. */
+	snd_soc_write(codec, INNO_REG_10, INNO_REG_10_MAX_CUR);
+	mdelay(10);
+	/* start precharge */
+	snd_soc_write(codec, INNO_REG_06, INNO_REG_06_DAC_PRECHARGE);
+	mdelay(100);
+
+	for (i = 0; i < ARRAY_SIZE(inno_codec_open_path); i++) {
+		reg_val = &inno_codec_open_path[i];
+		snd_soc_write(codec, reg_val->reg, reg_val->val);
+		mdelay(5);
+	}
+}
+
+static int rk3036_codec_probe(struct snd_soc_codec *codec)
+{
+	dev_dbg(codec->dev, "rk3036_codec probe\n");
+
+	rk3036_codec_reset(codec);
+
+	rk3036_codec_power_off(codec);
+	/* wait for capacitor discharge finished. */
+	mdelay(10);
+
+	rk3036_codec_power_on(codec);
+
+	return 0;
+}
+
+static int rk3036_codec_remove(struct snd_soc_codec *codec)
+{
+	dev_dbg(codec->dev, "rk3036_codec remove\n");
+	rk3036_codec_power_off(codec);
+
+	return 0;
+}
+
+static int rk3036_codec_set_bias_level(struct snd_soc_codec *codec,
+				       enum snd_soc_bias_level level)
+{
+	dev_dbg(codec->dev, "rk3036_codec set bias\n");
+	switch (level) {
+	case SND_SOC_BIAS_ON:
+		break;
+
+	case SND_SOC_BIAS_PREPARE:
+		break;
+
+	case SND_SOC_BIAS_STANDBY:
+		break;
+
+	case SND_SOC_BIAS_OFF:
+		break;
+	}
+
+	return 0;
+}
+
+static struct regmap *rk3036_codec_get_regmap(struct device *dev)
+{
+	struct rk3036_codec_priv *priv = dev_get_drvdata(dev);
+
+	dev_dbg(dev, "rk3036_codec get regmap\n");
+	return priv->regmap;
+}
+
+static struct snd_soc_codec_driver rk3036_codec_driver = {
+	.probe		= rk3036_codec_probe,
+	.remove		= rk3036_codec_remove,
+	.set_bias_level	= rk3036_codec_set_bias_level,
+	.get_regmap	= rk3036_codec_get_regmap,
+};
+
+static int codec_reg_read(void *context, unsigned int reg, unsigned int *val)
+{
+	struct rk3036_codec_priv *priv = context;
+	void __iomem *base = priv->base;
+
+	*val = readl(base + reg);
+	return 0;
+}
+
+static int codec_reg_write(void *context, unsigned int reg, unsigned int val)
+{
+	struct rk3036_codec_priv *priv = context;
+	void __iomem *base = priv->base;
+
+	dev_dbg(priv->dev, "write %08x to %08x\n", val, reg);
+	writel(val, base + reg);
+	return 0;
+}
+
+static struct regmap_bus codec_regmap_bus = {
+	.reg_read = codec_reg_read,
+	.reg_write = codec_reg_write,
+	.reg_format_endian_default = REGMAP_ENDIAN_NATIVE,
+	.val_format_endian_default = REGMAP_ENDIAN_NATIVE,
+};
+
+static struct regmap_config rk3036_codec_regmap_config = {
+	.reg_bits = 32,
+	.reg_stride = 4,
+	.val_bits = 8,
+};
+
+static int rk3036_codec_platform_probe(struct platform_device *pdev)
+{
+	struct rk3036_codec_priv *priv;
+	struct device_node *of_node = pdev->dev.of_node;
+	struct resource *res;
+	void __iomem *base;
+	struct regmap *grf;
+	int ret;
+
+	dev_dbg(&pdev->dev, "rk3036_codec platform probe\n");
+	priv = devm_kzalloc(&pdev->dev, sizeof(struct rk3036_codec_priv),
+			    GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	base = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(base))
+		return PTR_ERR(base);
+
+	priv->base = base;
+	priv->regmap = devm_regmap_init(&pdev->dev, &codec_regmap_bus, priv,
+					&rk3036_codec_regmap_config);
+	if (IS_ERR(priv->regmap)) {
+		dev_err(&pdev->dev, "init regmap failed\n");
+		return PTR_ERR(priv->regmap);
+	}
+
+	grf = syscon_regmap_lookup_by_phandle(of_node, "rockchip,grf");
+	if (IS_ERR(grf)) {
+		dev_err(&pdev->dev, "needs 'rockchip,grf' property\n");
+		return PTR_ERR(grf);
+	}
+	ret = regmap_write(grf, 0x00140, BIT(16 + 10) | BIT(10));
+	if (ret != 0) {
+		dev_err(&pdev->dev, "Could not write to GRF: %d\n", ret);
+		return ret;
+	}
+
+	priv->pclk = devm_clk_get(&pdev->dev, "acodec_pclk");
+	if (IS_ERR(priv->pclk))
+		return PTR_ERR(priv->pclk);
+
+	ret = clk_prepare_enable(priv->pclk);
+	if (ret < 0) {
+		dev_err(&pdev->dev, "failed to enable clk\n");
+		return ret;
+	}
+
+	priv->dev = &pdev->dev;
+	dev_set_drvdata(&pdev->dev, priv);
+
+	ret = snd_soc_register_codec(&pdev->dev, &rk3036_codec_driver,
+				     rk3036_codec_dai_driver,
+				     ARRAY_SIZE(rk3036_codec_dai_driver));
+	if (ret) {
+		clk_disable_unprepare(priv->pclk);
+		dev_set_drvdata(&pdev->dev, NULL);
+	}
+
+	return ret;
+}
+
+static int rk3036_codec_platform_remove(struct platform_device *pdev)
+{
+	struct rk3036_codec_priv *priv = dev_get_drvdata(&pdev->dev);
+
+	dev_dbg(&pdev->dev, "rk3036_codec platform remove\n");
+	snd_soc_unregister_codec(&pdev->dev);
+	clk_disable_unprepare(priv->pclk);
+
+	return 0;
+}
+
+static void rk3036_codec_platform_shutdown(struct platform_device *pdev)
+{
+	/*TODO:*/
+}
+
+static const struct of_device_id rk3036_codec_of_match[] = {
+	{ .compatible = "rk3036-codec", },
+	{}
+};
+MODULE_DEVICE_TABLE(of, rk3036_codec_of_match);
+
+static struct platform_driver rk3036_codec_platform_driver = {
+	.driver = {
+		.name = "rk3036-codec-platform",
+		.owner = THIS_MODULE,
+		.of_match_table = of_match_ptr(rk3036_codec_of_match),
+	},
+	.probe = rk3036_codec_platform_probe,
+	.remove = rk3036_codec_platform_remove,
+	.shutdown = rk3036_codec_platform_shutdown,
+};
+
+module_platform_driver(rk3036_codec_platform_driver);
+
+MODULE_AUTHOR("Rockchip Inc.");
+MODULE_DESCRIPTION("Rockchip rk3036 codec driver");
+MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/inno_rk3036.h b/sound/soc/codecs/inno_rk3036.h
new file mode 100644
index 0000000..8b01a9b
--- /dev/null
+++ b/sound/soc/codecs/inno_rk3036.h
@@ -0,0 +1,308 @@
+/*
+ * Driver of Inno Codec for rk3036 by Rockchip Inc.
+ * Author: Zheng ShunQian<zhengsq@rock-chips.com>
+ */
+
+#ifndef _INNO_RK3036_CODEC_H
+#define _INNO_RK3036_CODEC_H
+
+/* codec registers */
+#define INNO_REG_00	0x00
+#define INNO_REG_01	0x0c
+#define INNO_REG_02	0x10
+#define INNO_REG_03	0x14
+#define INNO_REG_04	0x88
+#define INNO_REG_05	0x8c
+#define INNO_REG_06	0x90
+#define INNO_REG_07	0x94
+#define INNO_REG_08	0x98
+#define INNO_REG_09	0x9c
+#define INNO_REG_10	0xa0
+
+/* register bit filed */
+#define INNO_REG_00_CSR_RESET		(0x0 << 0) /*codec system reset*/
+#define INNO_REG_00_CSR_WORK		(0x1 << 0)
+#define INNO_REG_00_CDCR_RESET		(0x0 << 1) /*codec digital core reset*/
+#define INNO_REG_00_CDCR_WORK		(0x1 << 1)
+#define INNO_REG_00_PRB_DISABLE		(0x0 << 6) /*power reset bypass*/
+#define INNO_REG_00_PRB_ENABLE		(0x1 << 6)
+
+#define INNO_REG_01_I2SMODE_MASK	(0x1 << 4)
+#define INNO_REG_01_I2SMODE_SLAVE	(0x0 << 4)
+#define INNO_REG_01_I2SMODE_MASTER	(0x1 << 4)
+#define INNO_REG_01_PINDIR_MASK		(0x1 << 5)
+#define INNO_REG_01_PINDIR_IN_SLAVE	(0x0 << 5) /*direction of pin*/
+#define INNO_REG_01_PINDIR_OUT_MASTER	(0x1 << 5)
+
+#define INNO_REG_02_LRS_MASK		(0x1 << 2)
+#define INNO_REG_02_LRS_NORMAL		(0x0 << 2) /*DAC Left Right Swap*/
+#define INNO_REG_02_LRS_SWAP		(0x1 << 2)
+#define INNO_REG_02_DACM_MASK		(0x3 << 3)
+#define INNO_REG_02_DACM_PCM		(0x3 << 3) /*DAC Mode*/
+#define INNO_REG_02_DACM_I2S		(0x2 << 3)
+#define INNO_REG_02_DACM_LJM		(0x1 << 3)
+#define INNO_REG_02_DACM_RJM		(0x0 << 3)
+#define INNO_REG_02_VWL_MASK		(0x3 << 5)
+#define INNO_REG_02_VWL_32BIT		(0x3 << 5) /*1/2Frame Valid Word Len*/
+#define INNO_REG_02_VWL_24BIT		(0x2 << 5)
+#define INNO_REG_02_VWL_20BIT		(0x1 << 5)
+#define INNO_REG_02_VWL_16BIT		(0x0 << 5)
+#define INNO_REG_02_LRCP_MASK		(0x1 << 7)
+#define INNO_REG_02_LRCP_NORMAL		(0x0 << 7) /*Left Right Polarity*/
+#define INNO_REG_02_LRCP_REVERSAL	(0x1 << 7)
+
+#define INNO_REG_03_BCP_MASK		(0x1 << 0)
+#define INNO_REG_03_BCP_NORMAL		(0x0 << 0) /*DAC bit clock polarity*/
+#define INNO_REG_03_BCP_REVERSAL	(0x1 << 0)
+#define INNO_REG_03_DACR_MASK		(0x1 << 1)
+#define INNO_REG_03_DACR_RESET		(0x0 << 1) /*DAC Reset*/
+#define INNO_REG_03_DACR_WORK		(0x1 << 1)
+#define INNO_REG_03_FWL_MASK		(0x3 << 2)
+#define INNO_REG_03_FWL_32BIT		(0x3 << 2) /*1/2Frame Word Length*/
+#define INNO_REG_03_FWL_24BIT		(0x2 << 2)
+#define INNO_REG_03_FWL_20BIT		(0x1 << 2)
+#define INNO_REG_03_FWL_16BIT		(0x0 << 2)
+
+#define INNO_REG_04_DACR_WORK		(0x1 << 0) /*DAC Right Module*/
+#define INNO_REG_04_DACR_STOP		(0x0 << 0)
+#define INNO_REG_04_DACL_WORK		(0x1 << 1) /*DAC Left Module*/
+#define INNO_REG_04_DACL_STOP		(0x0 << 1)
+#define INNO_REG_04_DACR_CLK_WORK	(0x1 << 2) /*DAC Right CLK*/
+#define INNO_REG_04_DACR_CLK_STOP	(0x0 << 2)
+#define INNO_REG_04_DACL_CLK_WORK	(0x1 << 3) /*DAC Left CLK*/
+#define INNO_REG_04_DACL_CLK_STOP	(0x0 << 3)
+#define INNO_REG_04_DACR_RV_WORK	(0x1 << 4) /*DAC Right Ref Voltage*/
+#define INNO_REG_04_DACR_RV_STOP	(0x0 << 4)
+#define INNO_REG_04_DACL_RV_WORK	(0x1 << 5) /*DAC Left Ref Voltage*/
+#define INNO_REG_04_DACL_RV_STOP	(0x0 << 5)
+
+#define INNO_REG_05_HPOUTR_EN_WORK	(0x1 << 0) /*HeadPhone Output Right*/
+#define INNO_REG_05_HPOUTR_EN_STOP	(0x0 << 0)
+#define INNO_REG_05_HPOUTL_EN_WORK	(0x1 << 1) /*HeadPhone Output Left*/
+#define INNO_REG_05_HPOUTL_EN_STOP	(0x0 << 1)
+#define INNO_REG_05_HPOUTR_WORK		(0x1 << 2) /*Init HP out right*/
+#define INNO_REG_05_HPOUTR_INIT		(0x0 << 2)
+#define INNO_REG_05_HPOUTL_WORK		(0x1 << 3) /*Init HP out left*/
+#define INNO_REG_05_HPOUTL_INIT		(0x0 << 3)
+
+#define INNO_REG_06_VOUTR_CZ_WORK	(0x1 << 0) /*Cross-Zero detection*/
+#define INNO_REG_06_VOUTR_CZ_STOP	(0x0 << 0)
+#define INNO_REG_06_VOUTL_CZ_WORK	(0x1 << 1) /*Cross-Zero detection*/
+#define INNO_REG_06_VOUTL_CZ_STOP	(0x0 << 1)
+#define INNO_REG_06_DACR_HL_RV_WORK	(0x1 << 2) /*High & Low Ref Voltage*/
+#define INNO_REG_06_DACR_HL_RV_STOP	(0x0 << 2)
+#define INNO_REG_06_DACL_HL_RV_WORK	(0x1 << 3) /*High & Low Ref Voltage*/
+#define INNO_REG_06_DACL_HL_RV_STOP	(0x0 << 3)
+#define INNO_REG_06_DAC_PRECHARGE	(0x0 << 4) /*PreCharge control for DAC*/
+#define INNO_REG_06_DAC_DISCHARGE	(0x1 << 4)
+#define INNO_REG_06_DAC_EN_WORK		(0x1 << 5) /*Enable Signal for DAC*/
+#define INNO_REG_06_DAC_EN_STOP		(0x0 << 5)
+
+/* Gain of output, 1.5db step: -39db(0x0) ~ 0db(0x1a) ~ 6db(0x1f) */
+#define INNO_REG_07_HPOUTL_GAIN_0DB	0x1a
+#define INNO_REG_07_HPOUTL_GAIN_N39DB	0x0
+#define INNO_REG_08_HPOUTR_GAIN_0DB	0x1a
+#define INNO_REG_08_HPOUTR_GAIN_N39DB	0x0
+
+#define INNO_REG_09_HP_OUTR_POP_PRECHARGE	(0x1 << 0)
+#define INNO_REG_09_HP_OUTR_POP_WORK		(0x2 << 0)
+#define INNO_REG_09_HP_OUTL_POP_PRECHARGE	(0x1 << 2)
+#define INNO_REG_09_HP_OUTL_POP_WORK		(0x2 << 2)
+#define INNO_REG_09_HP_OUTR_MUTE_MASK	(0x1 << 4)
+#define INNO_REG_09_HP_OUTR_MUTE_NO	(0x1 << 4)
+#define INNO_REG_09_HP_OUTR_MUTE_YES	(0x0 << 4)
+#define INNO_REG_09_HP_OUTL_MUTE_MASK	(0x1 << 5)
+#define INNO_REG_09_HP_OUTL_MUTE_NO	(0x1 << 5)
+#define INNO_REG_09_HP_OUTL_MUTE_YES	(0x0 << 5)
+#define INNO_REG_09_DACR_INIT		(0x0 << 6)
+#define INNO_REG_09_DACR_WORK		(0x1 << 6)
+#define INNO_REG_09_DACL_INIT		(0x0 << 7)
+#define INNO_REG_09_DACL_WORK		(0x1 << 7)
+
+#define INNO_REG_09_POWERON (INNO_REG_09_HP_OUTR_POP_WORK | \
+			      INNO_REG_09_HP_OUTL_POP_WORK | \
+			      INNO_REG_09_HP_OUTR_MUTE_YES | \
+			      INNO_REG_09_HP_OUTL_MUTE_YES | \
+			      INNO_REG_09_DACR_WORK        | \
+			      INNO_REG_09_DACL_WORK)
+
+#define INNO_REG_10_CHARGE_SEL_CUR_400I_YES	(0x0 << 0)
+#define INNO_REG_10_CHARGE_SEL_CUR_400I_NO	(0x1 << 0)
+#define INNO_REG_10_CHARGE_SEL_CUR_260I_YES	(0x0 << 1)
+#define INNO_REG_10_CHARGE_SEL_CUR_260I_NO	(0x1 << 1)
+#define INNO_REG_10_CHARGE_SEL_CUR_130I_YES	(0x0 << 2)
+#define INNO_REG_10_CHARGE_SEL_CUR_130I_NO	(0x1 << 2)
+#define INNO_REG_10_CHARGE_SEL_CUR_100I_YES	(0x0 << 3)
+#define INNO_REG_10_CHARGE_SEL_CUR_100I_NO	(0x1 << 3)
+#define INNO_REG_10_CHARGE_SEL_CUR_050I_YES	(0x0 << 4)
+#define INNO_REG_10_CHARGE_SEL_CUR_050I_NO	(0x1 << 4)
+#define INNO_REG_10_CHARGE_SEL_CUR_027I_YES	(0x0 << 5)
+#define INNO_REG_10_CHARGE_SEL_CUR_027I_NO	(0x1 << 5)
+
+#define INNO_REG_10_MAX_CUR (INNO_REG_10_CHARGE_SEL_CUR_400I_YES | \
+			     INNO_REG_10_CHARGE_SEL_CUR_260I_YES | \
+			     INNO_REG_10_CHARGE_SEL_CUR_130I_YES | \
+			     INNO_REG_10_CHARGE_SEL_CUR_100I_YES | \
+			     INNO_REG_10_CHARGE_SEL_CUR_050I_YES | \
+			     INNO_REG_10_CHARGE_SEL_CUR_027I_YES)
+
+struct inno_reg_val {
+	int reg;
+	int val;
+};
+
+struct inno_reg_val inno_codec_open_path[] = {
+	{ /* open current source */
+		.reg = INNO_REG_06,
+		.val = INNO_REG_06_DAC_EN_WORK     |
+		       INNO_REG_06_DAC_PRECHARGE   |
+		       INNO_REG_06_DACL_HL_RV_STOP |
+		       INNO_REG_06_DACR_HL_RV_STOP |
+		       INNO_REG_06_VOUTR_CZ_STOP   |
+		       INNO_REG_06_VOUTL_CZ_STOP,
+	},
+	{ /* power on DAC path reference voltage */
+		.reg = INNO_REG_04,
+		.val = INNO_REG_04_DACR_RV_WORK    |
+		       INNO_REG_04_DACL_RV_WORK    |
+		       INNO_REG_04_DACL_CLK_STOP   |
+		       INNO_REG_04_DACR_CLK_STOP   |
+		       INNO_REG_04_DACL_STOP       |
+		       INNO_REG_04_DACR_STOP,
+	},
+	{ /* PoP precharge work */
+		.reg = INNO_REG_09,
+		.val = INNO_REG_09_DACL_INIT        |
+		       INNO_REG_09_DACR_INIT        |
+		       INNO_REG_09_HP_OUTL_MUTE_YES |
+		       INNO_REG_09_HP_OUTR_MUTE_YES |
+		       INNO_REG_09_HP_OUTR_POP_WORK |
+		       INNO_REG_09_HP_OUTL_POP_WORK,
+	},
+	{ /* start up HPOUTL HPOUTR */
+		.reg = INNO_REG_05,
+		.val = INNO_REG_05_HPOUTR_EN_WORK  |
+		       INNO_REG_05_HPOUTL_EN_WORK  |
+		       INNO_REG_05_HPOUTR_INIT     |
+		       INNO_REG_05_HPOUTL_INIT,
+	},
+	{ /* now the HPOUTL HPOUTR init OK */
+		.reg = INNO_REG_05,
+		.val = INNO_REG_05_HPOUTR_EN_WORK  |
+		       INNO_REG_05_HPOUTL_EN_WORK  |
+		       INNO_REG_05_HPOUTR_WORK     |
+		       INNO_REG_05_HPOUTL_WORK,
+	},
+	{ /* start up special reference voltage of DACL DACR */
+		.reg = INNO_REG_06,
+		.val = INNO_REG_06_DAC_EN_WORK     |
+		       INNO_REG_06_DAC_PRECHARGE   |
+		       INNO_REG_06_DACL_HL_RV_WORK |
+		       INNO_REG_06_DACR_HL_RV_WORK |
+		       INNO_REG_06_VOUTL_CZ_STOP   |
+		       INNO_REG_06_VOUTR_CZ_STOP,
+	},
+	{ /* start up clock module of LR channel */
+		.reg = INNO_REG_04,
+		.val = INNO_REG_04_DACR_STOP       |
+		       INNO_REG_04_DACL_STOP       |
+		       INNO_REG_04_DACR_CLK_WORK   |
+		       INNO_REG_04_DACL_CLK_WORK   |
+		       INNO_REG_04_DACR_RV_WORK    |
+		       INNO_REG_04_DACL_RV_WORK,
+	},
+	{ /* start up DACL DACR module */
+		.reg = INNO_REG_04,
+		.val = INNO_REG_04_DACR_WORK       |
+		       INNO_REG_04_DACL_WORK       |
+		       INNO_REG_04_DACR_CLK_WORK   |
+		       INNO_REG_04_DACL_CLK_WORK   |
+		       INNO_REG_04_DACR_RV_WORK    |
+		       INNO_REG_04_DACL_RV_WORK,
+	},
+	{ /* end of the init state of DACL DACR */
+		.reg = INNO_REG_09,
+		.val = INNO_REG_09_POWERON,
+	},
+	{ /* set the gain of headphone output */
+		.reg = INNO_REG_07,
+		.val = INNO_REG_07_HPOUTL_GAIN_0DB,
+	},
+	{ /* set the gain of headphone output */
+		.reg = INNO_REG_08,
+		.val = INNO_REG_08_HPOUTR_GAIN_0DB,
+	},
+	{ /* end of the init state of DACL DACR */
+		.reg = INNO_REG_09,
+		.val = INNO_REG_09_DACL_WORK       |
+		       INNO_REG_09_DACR_WORK       |
+		       INNO_REG_09_HP_OUTL_MUTE_NO |
+		       INNO_REG_09_HP_OUTR_MUTE_NO |
+		       INNO_REG_09_HP_OUTR_POP_WORK |
+		       INNO_REG_09_HP_OUTL_POP_WORK,
+	},
+};
+
+struct inno_reg_val inno_codec_close_path[] = {
+	{
+		.reg = INNO_REG_06,
+		.val = INNO_REG_06_DAC_EN_WORK     |
+		       INNO_REG_06_DAC_PRECHARGE   |
+		       INNO_REG_06_DACL_HL_RV_WORK |
+		       INNO_REG_06_DACR_HL_RV_WORK |
+		       INNO_REG_06_VOUTL_CZ_STOP   |
+		       INNO_REG_06_VOUTR_CZ_STOP,
+	},
+	{
+		.reg = INNO_REG_07,
+		.val = INNO_REG_07_HPOUTL_GAIN_N39DB,
+	},
+	{
+		.reg = INNO_REG_08,
+		.val = INNO_REG_08_HPOUTR_GAIN_N39DB,
+	},
+	{
+		.reg = INNO_REG_09,
+		.val = INNO_REG_09_POWERON,
+	},
+	{
+		.reg = INNO_REG_05,
+		.val = INNO_REG_05_HPOUTR_EN_WORK  |
+		       INNO_REG_05_HPOUTL_EN_WORK  |
+		       INNO_REG_05_HPOUTR_INIT     |
+		       INNO_REG_05_HPOUTL_INIT,
+	},
+	{
+		.reg = INNO_REG_09,
+		.val = INNO_REG_09_DACL_WORK       |
+		       INNO_REG_09_DACR_WORK       |
+		       INNO_REG_09_HP_OUTL_MUTE_YES |
+		       INNO_REG_09_HP_OUTR_MUTE_YES |
+		       INNO_REG_09_HP_OUTR_POP_PRECHARGE |
+		       INNO_REG_09_HP_OUTL_POP_PRECHARGE,
+	},
+	{
+		.reg = INNO_REG_04,
+		.val = INNO_REG_04_DACR_RV_STOP    |
+		       INNO_REG_04_DACL_RV_STOP    |
+		       INNO_REG_04_DACL_CLK_STOP   |
+		       INNO_REG_04_DACR_CLK_STOP   |
+		       INNO_REG_04_DACL_STOP       |
+		       INNO_REG_04_DACR_STOP,
+	},
+	{
+		.reg = INNO_REG_06,
+		.val = INNO_REG_06_DAC_DISCHARGE,
+	},
+	{
+		.reg = INNO_REG_09,
+		.val = INNO_REG_09_DACL_INIT       |
+		       INNO_REG_09_DACR_INIT       |
+		       INNO_REG_09_HP_OUTL_MUTE_YES |
+		       INNO_REG_09_HP_OUTR_MUTE_YES |
+		       INNO_REG_09_HP_OUTR_POP_PRECHARGE |
+		       INNO_REG_09_HP_OUTL_POP_PRECHARGE,
+	},
+};
+
+#endif
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v1 1/4] ASoC: codec: Inno codec driver for RK3036 SoC
@ 2015-10-13  1:01   ` Shunqian Zheng
  0 siblings, 0 replies; 28+ messages in thread
From: Shunqian Zheng @ 2015-10-13  1:01 UTC (permalink / raw)
  To: linux-arm-kernel

From: ZhengShunQian <zhengsq@rock-chips.com>

RK3036 SoC integrated with an Inno audio codec. This driver
config the base function of codec. And the dapm is still WIP.

Signed-off-by: ZhengShunQian <zhengsq@rock-chips.com>
---
 sound/soc/codecs/Kconfig       |   4 +
 sound/soc/codecs/Makefile      |   2 +
 sound/soc/codecs/inno_rk3036.c | 439 +++++++++++++++++++++++++++++++++++++++++
 sound/soc/codecs/inno_rk3036.h | 308 +++++++++++++++++++++++++++++
 4 files changed, 753 insertions(+)
 create mode 100644 sound/soc/codecs/inno_rk3036.c
 create mode 100644 sound/soc/codecs/inno_rk3036.h

diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
index cfdafc4..e3cd3e7 100644
--- a/sound/soc/codecs/Kconfig
+++ b/sound/soc/codecs/Kconfig
@@ -471,6 +471,10 @@ config SND_SOC_GTM601
 config SND_SOC_ICS43432
 	tristate
 
+config SND_SOC_INNO_RK3036
+	tristate "Inno codec driver for RK3036 SoC"
+	depends on ARCH_ROCKCHIP
+
 config SND_SOC_ISABELLE
         tristate
 
diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile
index f632fc4..2f6bc6c 100644
--- a/sound/soc/codecs/Makefile
+++ b/sound/soc/codecs/Makefile
@@ -60,6 +60,7 @@ snd-soc-es8328-i2c-objs := es8328-i2c.o
 snd-soc-es8328-spi-objs := es8328-spi.o
 snd-soc-gtm601-objs := gtm601.o
 snd-soc-ics43432-objs := ics43432.o
+snd-soc-inno-rk3036-objs := inno_rk3036.o
 snd-soc-isabelle-objs := isabelle.o
 snd-soc-jz4740-codec-objs := jz4740.o
 snd-soc-l3-objs := l3.o
@@ -255,6 +256,7 @@ obj-$(CONFIG_SND_SOC_ES8328_I2C)+= snd-soc-es8328-i2c.o
 obj-$(CONFIG_SND_SOC_ES8328_SPI)+= snd-soc-es8328-spi.o
 obj-$(CONFIG_SND_SOC_GTM601)    += snd-soc-gtm601.o
 obj-$(CONFIG_SND_SOC_ICS43432)	+= snd-soc-ics43432.o
+obj-$(CONFIG_SND_SOC_INNO_RK3036)	+= snd-soc-inno-rk3036.o
 obj-$(CONFIG_SND_SOC_ISABELLE)	+= snd-soc-isabelle.o
 obj-$(CONFIG_SND_SOC_JZ4740_CODEC)	+= snd-soc-jz4740-codec.o
 obj-$(CONFIG_SND_SOC_L3)	+= snd-soc-l3.o
diff --git a/sound/soc/codecs/inno_rk3036.c b/sound/soc/codecs/inno_rk3036.c
new file mode 100644
index 0000000..e8e7356
--- /dev/null
+++ b/sound/soc/codecs/inno_rk3036.c
@@ -0,0 +1,439 @@
+/*
+ * Driver of Inno codec for rk3036 by Rockchip Inc.
+ *
+ * Author: Rockchip Inc.
+ * Author: Zheng ShunQian<zhengsq@rock-chips.com>
+ */
+
+#define DEBUG
+
+#include <sound/soc.h>
+#include <sound/soc-dai.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+
+#include <linux/platform_device.h>
+#include <linux/of.h>
+#include <linux/clk.h>
+#include <linux/regmap.h>
+#include <linux/device.h>
+#include <linux/delay.h>
+#include <linux/mfd/syscon.h>
+#include <linux/module.h>
+#include <linux/io.h>
+
+#include "inno_rk3036.h"
+
+struct rk3036_codec_priv {
+	void __iomem *base;
+	struct clk *pclk;
+	struct regmap *regmap;
+	struct device *dev;
+};
+
+static int rk3036_codec_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id,
+				       unsigned int fre, int dir)
+{
+	/* Nothing to be done here */
+	return 0;
+}
+
+static int rk3036_codec_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
+{
+	struct snd_soc_codec *codec = dai->codec;
+	unsigned int reg01_val = 0,  reg02_val = 0, reg03_val = 0;
+
+	dev_dbg(codec->dev, "rk3036_codec dai set fmt : %08x\n", fmt);
+
+	switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
+	case SND_SOC_DAIFMT_CBS_CFS:
+		reg01_val |= INNO_REG_01_PINDIR_IN_SLAVE |
+			     INNO_REG_01_I2SMODE_SLAVE;
+		break;
+	case SND_SOC_DAIFMT_CBM_CFM:
+		reg01_val |= INNO_REG_01_PINDIR_OUT_MASTER |
+			     INNO_REG_01_I2SMODE_MASTER;
+		break;
+	default:
+		dev_err(codec->dev, "invalid fmt\n");
+		return -EINVAL;
+	}
+
+	switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
+	case SND_SOC_DAIFMT_DSP_A:
+		reg02_val |= INNO_REG_02_DACM_PCM;
+		break;
+	case SND_SOC_DAIFMT_I2S:
+		reg02_val |= INNO_REG_02_DACM_I2S;
+		break;
+	case SND_SOC_DAIFMT_RIGHT_J:
+		reg02_val |= INNO_REG_02_DACM_RJM;
+		break;
+	case SND_SOC_DAIFMT_LEFT_J:
+		reg02_val |= INNO_REG_02_DACM_LJM;
+		break;
+	default:
+		dev_err(codec->dev, "set dai format failed\n");
+		return -EINVAL;
+	}
+
+	switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
+	case SND_SOC_DAIFMT_NB_NF:
+		reg02_val |= INNO_REG_02_LRCP_NORMAL;
+		reg03_val |= INNO_REG_03_BCP_NORMAL;
+		break;
+	case SND_SOC_DAIFMT_IB_IF:
+		reg02_val |= INNO_REG_02_LRCP_REVERSAL;
+		reg03_val |= INNO_REG_03_BCP_REVERSAL;
+		break;
+	case SND_SOC_DAIFMT_IB_NF:
+		reg02_val |= INNO_REG_02_LRCP_REVERSAL;
+		reg03_val |= INNO_REG_03_BCP_NORMAL;
+		break;
+	case SND_SOC_DAIFMT_NB_IF:
+		reg02_val |= INNO_REG_02_LRCP_NORMAL;
+		reg03_val |= INNO_REG_03_BCP_REVERSAL;
+		break;
+	default:
+		dev_err(codec->dev, "set dai format failed\n");
+		return -EINVAL;
+	}
+
+	snd_soc_update_bits(codec, INNO_REG_01, INNO_REG_01_I2SMODE_MASK |
+			    INNO_REG_01_PINDIR_MASK, reg01_val);
+	snd_soc_update_bits(codec, INNO_REG_02, INNO_REG_02_LRCP_MASK |
+			    INNO_REG_02_DACM_MASK, reg02_val);
+	snd_soc_update_bits(codec, INNO_REG_03, INNO_REG_03_BCP_MASK,
+			    reg03_val);
+	return 0;
+}
+
+static int rk3036_codec_dai_digital_mute(struct snd_soc_dai *dai, int mute)
+{
+	struct snd_soc_codec *codec = dai->codec;
+	unsigned int val = 0;
+
+	dev_dbg(codec->dev, "rk3036_codec dai mute : %d\n", mute);
+	if (mute)
+		val |= INNO_REG_09_HP_OUTR_MUTE_YES |
+		       INNO_REG_09_HP_OUTL_MUTE_YES;
+	else
+		val |= INNO_REG_09_HP_OUTR_MUTE_NO |
+		       INNO_REG_09_HP_OUTL_MUTE_NO;
+
+	snd_soc_update_bits(codec, INNO_REG_09, INNO_REG_09_HP_OUTR_MUTE_MASK |
+			    INNO_REG_09_HP_OUTL_MUTE_MASK, val);
+	return 0;
+}
+
+static int rk3036_codec_dai_hw_params(struct snd_pcm_substream *substream,
+				      struct snd_pcm_hw_params *hw_params,
+				      struct snd_soc_dai *dai)
+{
+	struct snd_soc_codec *codec = dai->codec;
+	unsigned int reg02_val = 0, reg03_val = 0;
+
+	dev_dbg(codec->dev, "rk3036_codec dai hw_params");
+
+	switch (params_format(hw_params)) {
+	case SNDRV_PCM_FORMAT_S16_LE:
+		reg02_val |= INNO_REG_02_VWL_16BIT;
+		break;
+	case SNDRV_PCM_FORMAT_S20_3LE:
+		reg02_val |= INNO_REG_02_VWL_20BIT;
+		break;
+	case SNDRV_PCM_FORMAT_S24_LE:
+		reg02_val |= INNO_REG_02_VWL_24BIT;
+		break;
+	case SNDRV_PCM_FORMAT_S32_LE:
+		reg02_val |= INNO_REG_02_VWL_32BIT;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	reg02_val |= INNO_REG_02_LRCP_NORMAL;
+	reg03_val |= INNO_REG_03_FWL_32BIT | INNO_REG_03_DACR_WORK;
+
+	snd_soc_update_bits(codec, INNO_REG_02, INNO_REG_02_LRCP_MASK |
+			    INNO_REG_02_VWL_MASK, reg02_val);
+	snd_soc_update_bits(codec, INNO_REG_03, INNO_REG_03_DACR_MASK |
+			    INNO_REG_03_FWL_MASK, reg03_val);
+	return 0;
+}
+
+#define RK3036_CODEC_RATES (SNDRV_PCM_RATE_8000  | \
+			    SNDRV_PCM_RATE_16000 | \
+			    SNDRV_PCM_RATE_32000 | \
+			    SNDRV_PCM_RATE_44100 | \
+			    SNDRV_PCM_RATE_48000 | \
+			    SNDRV_PCM_RATE_96000)
+
+#define RK3036_CODEC_FMTS (SNDRV_PCM_FMTBIT_S16_LE  | \
+			   SNDRV_PCM_FMTBIT_S20_3LE | \
+			   SNDRV_PCM_FMTBIT_S24_LE  | \
+			   SNDRV_PCM_FMTBIT_S32_LE)
+
+struct snd_soc_dai_ops rk3036_codec_dai_ops = {
+	.set_sysclk	= rk3036_codec_dai_set_sysclk,
+	.set_fmt	= rk3036_codec_dai_set_fmt,
+	.digital_mute	= rk3036_codec_dai_digital_mute,
+	.hw_params	= rk3036_codec_dai_hw_params,
+};
+
+struct snd_soc_dai_driver rk3036_codec_dai_driver[] = {
+	{
+		.name = "rk3036-codec-dai",
+		.playback = {
+			.stream_name = "Playback",
+			.channels_min = 1,
+			.channels_max = 2,
+			.rates = RK3036_CODEC_RATES,
+			.formats = RK3036_CODEC_FMTS,
+		},
+		.ops = &rk3036_codec_dai_ops,
+		.symmetric_rates = 1,
+	},
+};
+
+static void rk3036_codec_reset(struct snd_soc_codec *codec)
+{
+	dev_dbg(codec->dev, "rk3036_codec reset\n");
+	snd_soc_write(codec, INNO_REG_00,
+		      INNO_REG_00_CSR_RESET | INNO_REG_00_CDCR_RESET);
+	mdelay(10);
+	snd_soc_write(codec, INNO_REG_00,
+		      INNO_REG_00_CSR_WORK | INNO_REG_00_CDCR_WORK);
+	mdelay(10);
+}
+
+static void rk3036_codec_power_off(struct snd_soc_codec *codec)
+{
+	struct inno_reg_val *reg_val;
+	int i;
+
+	dev_dbg(codec->dev, "rk3036_codec power off\n");
+	/* set a big current for capacitor charging. */
+	snd_soc_write(codec, INNO_REG_10, INNO_REG_10_MAX_CUR);
+	/* start discharge. */
+	snd_soc_write(codec, INNO_REG_06, INNO_REG_06_DAC_DISCHARGE);
+
+	for (i = 0; i < ARRAY_SIZE(inno_codec_close_path); i++) {
+		reg_val = &inno_codec_open_path[i];
+		snd_soc_write(codec, reg_val->reg, reg_val->val);
+		mdelay(5);
+	}
+}
+
+static void rk3036_codec_power_on(struct snd_soc_codec *codec)
+{
+	struct inno_reg_val *reg_val;
+	int i;
+
+	dev_dbg(codec->dev, "rk3036_codec power on\n");
+	/* set a big current for capacitor discharging. */
+	snd_soc_write(codec, INNO_REG_10, INNO_REG_10_MAX_CUR);
+	mdelay(10);
+	/* start precharge */
+	snd_soc_write(codec, INNO_REG_06, INNO_REG_06_DAC_PRECHARGE);
+	mdelay(100);
+
+	for (i = 0; i < ARRAY_SIZE(inno_codec_open_path); i++) {
+		reg_val = &inno_codec_open_path[i];
+		snd_soc_write(codec, reg_val->reg, reg_val->val);
+		mdelay(5);
+	}
+}
+
+static int rk3036_codec_probe(struct snd_soc_codec *codec)
+{
+	dev_dbg(codec->dev, "rk3036_codec probe\n");
+
+	rk3036_codec_reset(codec);
+
+	rk3036_codec_power_off(codec);
+	/* wait for capacitor discharge finished. */
+	mdelay(10);
+
+	rk3036_codec_power_on(codec);
+
+	return 0;
+}
+
+static int rk3036_codec_remove(struct snd_soc_codec *codec)
+{
+	dev_dbg(codec->dev, "rk3036_codec remove\n");
+	rk3036_codec_power_off(codec);
+
+	return 0;
+}
+
+static int rk3036_codec_set_bias_level(struct snd_soc_codec *codec,
+				       enum snd_soc_bias_level level)
+{
+	dev_dbg(codec->dev, "rk3036_codec set bias\n");
+	switch (level) {
+	case SND_SOC_BIAS_ON:
+		break;
+
+	case SND_SOC_BIAS_PREPARE:
+		break;
+
+	case SND_SOC_BIAS_STANDBY:
+		break;
+
+	case SND_SOC_BIAS_OFF:
+		break;
+	}
+
+	return 0;
+}
+
+static struct regmap *rk3036_codec_get_regmap(struct device *dev)
+{
+	struct rk3036_codec_priv *priv = dev_get_drvdata(dev);
+
+	dev_dbg(dev, "rk3036_codec get regmap\n");
+	return priv->regmap;
+}
+
+static struct snd_soc_codec_driver rk3036_codec_driver = {
+	.probe		= rk3036_codec_probe,
+	.remove		= rk3036_codec_remove,
+	.set_bias_level	= rk3036_codec_set_bias_level,
+	.get_regmap	= rk3036_codec_get_regmap,
+};
+
+static int codec_reg_read(void *context, unsigned int reg, unsigned int *val)
+{
+	struct rk3036_codec_priv *priv = context;
+	void __iomem *base = priv->base;
+
+	*val = readl(base + reg);
+	return 0;
+}
+
+static int codec_reg_write(void *context, unsigned int reg, unsigned int val)
+{
+	struct rk3036_codec_priv *priv = context;
+	void __iomem *base = priv->base;
+
+	dev_dbg(priv->dev, "write %08x to %08x\n", val, reg);
+	writel(val, base + reg);
+	return 0;
+}
+
+static struct regmap_bus codec_regmap_bus = {
+	.reg_read = codec_reg_read,
+	.reg_write = codec_reg_write,
+	.reg_format_endian_default = REGMAP_ENDIAN_NATIVE,
+	.val_format_endian_default = REGMAP_ENDIAN_NATIVE,
+};
+
+static struct regmap_config rk3036_codec_regmap_config = {
+	.reg_bits = 32,
+	.reg_stride = 4,
+	.val_bits = 8,
+};
+
+static int rk3036_codec_platform_probe(struct platform_device *pdev)
+{
+	struct rk3036_codec_priv *priv;
+	struct device_node *of_node = pdev->dev.of_node;
+	struct resource *res;
+	void __iomem *base;
+	struct regmap *grf;
+	int ret;
+
+	dev_dbg(&pdev->dev, "rk3036_codec platform probe\n");
+	priv = devm_kzalloc(&pdev->dev, sizeof(struct rk3036_codec_priv),
+			    GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	base = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(base))
+		return PTR_ERR(base);
+
+	priv->base = base;
+	priv->regmap = devm_regmap_init(&pdev->dev, &codec_regmap_bus, priv,
+					&rk3036_codec_regmap_config);
+	if (IS_ERR(priv->regmap)) {
+		dev_err(&pdev->dev, "init regmap failed\n");
+		return PTR_ERR(priv->regmap);
+	}
+
+	grf = syscon_regmap_lookup_by_phandle(of_node, "rockchip,grf");
+	if (IS_ERR(grf)) {
+		dev_err(&pdev->dev, "needs 'rockchip,grf' property\n");
+		return PTR_ERR(grf);
+	}
+	ret = regmap_write(grf, 0x00140, BIT(16 + 10) | BIT(10));
+	if (ret != 0) {
+		dev_err(&pdev->dev, "Could not write to GRF: %d\n", ret);
+		return ret;
+	}
+
+	priv->pclk = devm_clk_get(&pdev->dev, "acodec_pclk");
+	if (IS_ERR(priv->pclk))
+		return PTR_ERR(priv->pclk);
+
+	ret = clk_prepare_enable(priv->pclk);
+	if (ret < 0) {
+		dev_err(&pdev->dev, "failed to enable clk\n");
+		return ret;
+	}
+
+	priv->dev = &pdev->dev;
+	dev_set_drvdata(&pdev->dev, priv);
+
+	ret = snd_soc_register_codec(&pdev->dev, &rk3036_codec_driver,
+				     rk3036_codec_dai_driver,
+				     ARRAY_SIZE(rk3036_codec_dai_driver));
+	if (ret) {
+		clk_disable_unprepare(priv->pclk);
+		dev_set_drvdata(&pdev->dev, NULL);
+	}
+
+	return ret;
+}
+
+static int rk3036_codec_platform_remove(struct platform_device *pdev)
+{
+	struct rk3036_codec_priv *priv = dev_get_drvdata(&pdev->dev);
+
+	dev_dbg(&pdev->dev, "rk3036_codec platform remove\n");
+	snd_soc_unregister_codec(&pdev->dev);
+	clk_disable_unprepare(priv->pclk);
+
+	return 0;
+}
+
+static void rk3036_codec_platform_shutdown(struct platform_device *pdev)
+{
+	/*TODO:*/
+}
+
+static const struct of_device_id rk3036_codec_of_match[] = {
+	{ .compatible = "rk3036-codec", },
+	{}
+};
+MODULE_DEVICE_TABLE(of, rk3036_codec_of_match);
+
+static struct platform_driver rk3036_codec_platform_driver = {
+	.driver = {
+		.name = "rk3036-codec-platform",
+		.owner = THIS_MODULE,
+		.of_match_table = of_match_ptr(rk3036_codec_of_match),
+	},
+	.probe = rk3036_codec_platform_probe,
+	.remove = rk3036_codec_platform_remove,
+	.shutdown = rk3036_codec_platform_shutdown,
+};
+
+module_platform_driver(rk3036_codec_platform_driver);
+
+MODULE_AUTHOR("Rockchip Inc.");
+MODULE_DESCRIPTION("Rockchip rk3036 codec driver");
+MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/inno_rk3036.h b/sound/soc/codecs/inno_rk3036.h
new file mode 100644
index 0000000..8b01a9b
--- /dev/null
+++ b/sound/soc/codecs/inno_rk3036.h
@@ -0,0 +1,308 @@
+/*
+ * Driver of Inno Codec for rk3036 by Rockchip Inc.
+ * Author: Zheng ShunQian<zhengsq@rock-chips.com>
+ */
+
+#ifndef _INNO_RK3036_CODEC_H
+#define _INNO_RK3036_CODEC_H
+
+/* codec registers */
+#define INNO_REG_00	0x00
+#define INNO_REG_01	0x0c
+#define INNO_REG_02	0x10
+#define INNO_REG_03	0x14
+#define INNO_REG_04	0x88
+#define INNO_REG_05	0x8c
+#define INNO_REG_06	0x90
+#define INNO_REG_07	0x94
+#define INNO_REG_08	0x98
+#define INNO_REG_09	0x9c
+#define INNO_REG_10	0xa0
+
+/* register bit filed */
+#define INNO_REG_00_CSR_RESET		(0x0 << 0) /*codec system reset*/
+#define INNO_REG_00_CSR_WORK		(0x1 << 0)
+#define INNO_REG_00_CDCR_RESET		(0x0 << 1) /*codec digital core reset*/
+#define INNO_REG_00_CDCR_WORK		(0x1 << 1)
+#define INNO_REG_00_PRB_DISABLE		(0x0 << 6) /*power reset bypass*/
+#define INNO_REG_00_PRB_ENABLE		(0x1 << 6)
+
+#define INNO_REG_01_I2SMODE_MASK	(0x1 << 4)
+#define INNO_REG_01_I2SMODE_SLAVE	(0x0 << 4)
+#define INNO_REG_01_I2SMODE_MASTER	(0x1 << 4)
+#define INNO_REG_01_PINDIR_MASK		(0x1 << 5)
+#define INNO_REG_01_PINDIR_IN_SLAVE	(0x0 << 5) /*direction of pin*/
+#define INNO_REG_01_PINDIR_OUT_MASTER	(0x1 << 5)
+
+#define INNO_REG_02_LRS_MASK		(0x1 << 2)
+#define INNO_REG_02_LRS_NORMAL		(0x0 << 2) /*DAC Left Right Swap*/
+#define INNO_REG_02_LRS_SWAP		(0x1 << 2)
+#define INNO_REG_02_DACM_MASK		(0x3 << 3)
+#define INNO_REG_02_DACM_PCM		(0x3 << 3) /*DAC Mode*/
+#define INNO_REG_02_DACM_I2S		(0x2 << 3)
+#define INNO_REG_02_DACM_LJM		(0x1 << 3)
+#define INNO_REG_02_DACM_RJM		(0x0 << 3)
+#define INNO_REG_02_VWL_MASK		(0x3 << 5)
+#define INNO_REG_02_VWL_32BIT		(0x3 << 5) /*1/2Frame Valid Word Len*/
+#define INNO_REG_02_VWL_24BIT		(0x2 << 5)
+#define INNO_REG_02_VWL_20BIT		(0x1 << 5)
+#define INNO_REG_02_VWL_16BIT		(0x0 << 5)
+#define INNO_REG_02_LRCP_MASK		(0x1 << 7)
+#define INNO_REG_02_LRCP_NORMAL		(0x0 << 7) /*Left Right Polarity*/
+#define INNO_REG_02_LRCP_REVERSAL	(0x1 << 7)
+
+#define INNO_REG_03_BCP_MASK		(0x1 << 0)
+#define INNO_REG_03_BCP_NORMAL		(0x0 << 0) /*DAC bit clock polarity*/
+#define INNO_REG_03_BCP_REVERSAL	(0x1 << 0)
+#define INNO_REG_03_DACR_MASK		(0x1 << 1)
+#define INNO_REG_03_DACR_RESET		(0x0 << 1) /*DAC Reset*/
+#define INNO_REG_03_DACR_WORK		(0x1 << 1)
+#define INNO_REG_03_FWL_MASK		(0x3 << 2)
+#define INNO_REG_03_FWL_32BIT		(0x3 << 2) /*1/2Frame Word Length*/
+#define INNO_REG_03_FWL_24BIT		(0x2 << 2)
+#define INNO_REG_03_FWL_20BIT		(0x1 << 2)
+#define INNO_REG_03_FWL_16BIT		(0x0 << 2)
+
+#define INNO_REG_04_DACR_WORK		(0x1 << 0) /*DAC Right Module*/
+#define INNO_REG_04_DACR_STOP		(0x0 << 0)
+#define INNO_REG_04_DACL_WORK		(0x1 << 1) /*DAC Left Module*/
+#define INNO_REG_04_DACL_STOP		(0x0 << 1)
+#define INNO_REG_04_DACR_CLK_WORK	(0x1 << 2) /*DAC Right CLK*/
+#define INNO_REG_04_DACR_CLK_STOP	(0x0 << 2)
+#define INNO_REG_04_DACL_CLK_WORK	(0x1 << 3) /*DAC Left CLK*/
+#define INNO_REG_04_DACL_CLK_STOP	(0x0 << 3)
+#define INNO_REG_04_DACR_RV_WORK	(0x1 << 4) /*DAC Right Ref Voltage*/
+#define INNO_REG_04_DACR_RV_STOP	(0x0 << 4)
+#define INNO_REG_04_DACL_RV_WORK	(0x1 << 5) /*DAC Left Ref Voltage*/
+#define INNO_REG_04_DACL_RV_STOP	(0x0 << 5)
+
+#define INNO_REG_05_HPOUTR_EN_WORK	(0x1 << 0) /*HeadPhone Output Right*/
+#define INNO_REG_05_HPOUTR_EN_STOP	(0x0 << 0)
+#define INNO_REG_05_HPOUTL_EN_WORK	(0x1 << 1) /*HeadPhone Output Left*/
+#define INNO_REG_05_HPOUTL_EN_STOP	(0x0 << 1)
+#define INNO_REG_05_HPOUTR_WORK		(0x1 << 2) /*Init HP out right*/
+#define INNO_REG_05_HPOUTR_INIT		(0x0 << 2)
+#define INNO_REG_05_HPOUTL_WORK		(0x1 << 3) /*Init HP out left*/
+#define INNO_REG_05_HPOUTL_INIT		(0x0 << 3)
+
+#define INNO_REG_06_VOUTR_CZ_WORK	(0x1 << 0) /*Cross-Zero detection*/
+#define INNO_REG_06_VOUTR_CZ_STOP	(0x0 << 0)
+#define INNO_REG_06_VOUTL_CZ_WORK	(0x1 << 1) /*Cross-Zero detection*/
+#define INNO_REG_06_VOUTL_CZ_STOP	(0x0 << 1)
+#define INNO_REG_06_DACR_HL_RV_WORK	(0x1 << 2) /*High & Low Ref Voltage*/
+#define INNO_REG_06_DACR_HL_RV_STOP	(0x0 << 2)
+#define INNO_REG_06_DACL_HL_RV_WORK	(0x1 << 3) /*High & Low Ref Voltage*/
+#define INNO_REG_06_DACL_HL_RV_STOP	(0x0 << 3)
+#define INNO_REG_06_DAC_PRECHARGE	(0x0 << 4) /*PreCharge control for DAC*/
+#define INNO_REG_06_DAC_DISCHARGE	(0x1 << 4)
+#define INNO_REG_06_DAC_EN_WORK		(0x1 << 5) /*Enable Signal for DAC*/
+#define INNO_REG_06_DAC_EN_STOP		(0x0 << 5)
+
+/* Gain of output, 1.5db step: -39db(0x0) ~ 0db(0x1a) ~ 6db(0x1f) */
+#define INNO_REG_07_HPOUTL_GAIN_0DB	0x1a
+#define INNO_REG_07_HPOUTL_GAIN_N39DB	0x0
+#define INNO_REG_08_HPOUTR_GAIN_0DB	0x1a
+#define INNO_REG_08_HPOUTR_GAIN_N39DB	0x0
+
+#define INNO_REG_09_HP_OUTR_POP_PRECHARGE	(0x1 << 0)
+#define INNO_REG_09_HP_OUTR_POP_WORK		(0x2 << 0)
+#define INNO_REG_09_HP_OUTL_POP_PRECHARGE	(0x1 << 2)
+#define INNO_REG_09_HP_OUTL_POP_WORK		(0x2 << 2)
+#define INNO_REG_09_HP_OUTR_MUTE_MASK	(0x1 << 4)
+#define INNO_REG_09_HP_OUTR_MUTE_NO	(0x1 << 4)
+#define INNO_REG_09_HP_OUTR_MUTE_YES	(0x0 << 4)
+#define INNO_REG_09_HP_OUTL_MUTE_MASK	(0x1 << 5)
+#define INNO_REG_09_HP_OUTL_MUTE_NO	(0x1 << 5)
+#define INNO_REG_09_HP_OUTL_MUTE_YES	(0x0 << 5)
+#define INNO_REG_09_DACR_INIT		(0x0 << 6)
+#define INNO_REG_09_DACR_WORK		(0x1 << 6)
+#define INNO_REG_09_DACL_INIT		(0x0 << 7)
+#define INNO_REG_09_DACL_WORK		(0x1 << 7)
+
+#define INNO_REG_09_POWERON (INNO_REG_09_HP_OUTR_POP_WORK | \
+			      INNO_REG_09_HP_OUTL_POP_WORK | \
+			      INNO_REG_09_HP_OUTR_MUTE_YES | \
+			      INNO_REG_09_HP_OUTL_MUTE_YES | \
+			      INNO_REG_09_DACR_WORK        | \
+			      INNO_REG_09_DACL_WORK)
+
+#define INNO_REG_10_CHARGE_SEL_CUR_400I_YES	(0x0 << 0)
+#define INNO_REG_10_CHARGE_SEL_CUR_400I_NO	(0x1 << 0)
+#define INNO_REG_10_CHARGE_SEL_CUR_260I_YES	(0x0 << 1)
+#define INNO_REG_10_CHARGE_SEL_CUR_260I_NO	(0x1 << 1)
+#define INNO_REG_10_CHARGE_SEL_CUR_130I_YES	(0x0 << 2)
+#define INNO_REG_10_CHARGE_SEL_CUR_130I_NO	(0x1 << 2)
+#define INNO_REG_10_CHARGE_SEL_CUR_100I_YES	(0x0 << 3)
+#define INNO_REG_10_CHARGE_SEL_CUR_100I_NO	(0x1 << 3)
+#define INNO_REG_10_CHARGE_SEL_CUR_050I_YES	(0x0 << 4)
+#define INNO_REG_10_CHARGE_SEL_CUR_050I_NO	(0x1 << 4)
+#define INNO_REG_10_CHARGE_SEL_CUR_027I_YES	(0x0 << 5)
+#define INNO_REG_10_CHARGE_SEL_CUR_027I_NO	(0x1 << 5)
+
+#define INNO_REG_10_MAX_CUR (INNO_REG_10_CHARGE_SEL_CUR_400I_YES | \
+			     INNO_REG_10_CHARGE_SEL_CUR_260I_YES | \
+			     INNO_REG_10_CHARGE_SEL_CUR_130I_YES | \
+			     INNO_REG_10_CHARGE_SEL_CUR_100I_YES | \
+			     INNO_REG_10_CHARGE_SEL_CUR_050I_YES | \
+			     INNO_REG_10_CHARGE_SEL_CUR_027I_YES)
+
+struct inno_reg_val {
+	int reg;
+	int val;
+};
+
+struct inno_reg_val inno_codec_open_path[] = {
+	{ /* open current source */
+		.reg = INNO_REG_06,
+		.val = INNO_REG_06_DAC_EN_WORK     |
+		       INNO_REG_06_DAC_PRECHARGE   |
+		       INNO_REG_06_DACL_HL_RV_STOP |
+		       INNO_REG_06_DACR_HL_RV_STOP |
+		       INNO_REG_06_VOUTR_CZ_STOP   |
+		       INNO_REG_06_VOUTL_CZ_STOP,
+	},
+	{ /* power on DAC path reference voltage */
+		.reg = INNO_REG_04,
+		.val = INNO_REG_04_DACR_RV_WORK    |
+		       INNO_REG_04_DACL_RV_WORK    |
+		       INNO_REG_04_DACL_CLK_STOP   |
+		       INNO_REG_04_DACR_CLK_STOP   |
+		       INNO_REG_04_DACL_STOP       |
+		       INNO_REG_04_DACR_STOP,
+	},
+	{ /* PoP precharge work */
+		.reg = INNO_REG_09,
+		.val = INNO_REG_09_DACL_INIT        |
+		       INNO_REG_09_DACR_INIT        |
+		       INNO_REG_09_HP_OUTL_MUTE_YES |
+		       INNO_REG_09_HP_OUTR_MUTE_YES |
+		       INNO_REG_09_HP_OUTR_POP_WORK |
+		       INNO_REG_09_HP_OUTL_POP_WORK,
+	},
+	{ /* start up HPOUTL HPOUTR */
+		.reg = INNO_REG_05,
+		.val = INNO_REG_05_HPOUTR_EN_WORK  |
+		       INNO_REG_05_HPOUTL_EN_WORK  |
+		       INNO_REG_05_HPOUTR_INIT     |
+		       INNO_REG_05_HPOUTL_INIT,
+	},
+	{ /* now the HPOUTL HPOUTR init OK */
+		.reg = INNO_REG_05,
+		.val = INNO_REG_05_HPOUTR_EN_WORK  |
+		       INNO_REG_05_HPOUTL_EN_WORK  |
+		       INNO_REG_05_HPOUTR_WORK     |
+		       INNO_REG_05_HPOUTL_WORK,
+	},
+	{ /* start up special reference voltage of DACL DACR */
+		.reg = INNO_REG_06,
+		.val = INNO_REG_06_DAC_EN_WORK     |
+		       INNO_REG_06_DAC_PRECHARGE   |
+		       INNO_REG_06_DACL_HL_RV_WORK |
+		       INNO_REG_06_DACR_HL_RV_WORK |
+		       INNO_REG_06_VOUTL_CZ_STOP   |
+		       INNO_REG_06_VOUTR_CZ_STOP,
+	},
+	{ /* start up clock module of LR channel */
+		.reg = INNO_REG_04,
+		.val = INNO_REG_04_DACR_STOP       |
+		       INNO_REG_04_DACL_STOP       |
+		       INNO_REG_04_DACR_CLK_WORK   |
+		       INNO_REG_04_DACL_CLK_WORK   |
+		       INNO_REG_04_DACR_RV_WORK    |
+		       INNO_REG_04_DACL_RV_WORK,
+	},
+	{ /* start up DACL DACR module */
+		.reg = INNO_REG_04,
+		.val = INNO_REG_04_DACR_WORK       |
+		       INNO_REG_04_DACL_WORK       |
+		       INNO_REG_04_DACR_CLK_WORK   |
+		       INNO_REG_04_DACL_CLK_WORK   |
+		       INNO_REG_04_DACR_RV_WORK    |
+		       INNO_REG_04_DACL_RV_WORK,
+	},
+	{ /* end of the init state of DACL DACR */
+		.reg = INNO_REG_09,
+		.val = INNO_REG_09_POWERON,
+	},
+	{ /* set the gain of headphone output */
+		.reg = INNO_REG_07,
+		.val = INNO_REG_07_HPOUTL_GAIN_0DB,
+	},
+	{ /* set the gain of headphone output */
+		.reg = INNO_REG_08,
+		.val = INNO_REG_08_HPOUTR_GAIN_0DB,
+	},
+	{ /* end of the init state of DACL DACR */
+		.reg = INNO_REG_09,
+		.val = INNO_REG_09_DACL_WORK       |
+		       INNO_REG_09_DACR_WORK       |
+		       INNO_REG_09_HP_OUTL_MUTE_NO |
+		       INNO_REG_09_HP_OUTR_MUTE_NO |
+		       INNO_REG_09_HP_OUTR_POP_WORK |
+		       INNO_REG_09_HP_OUTL_POP_WORK,
+	},
+};
+
+struct inno_reg_val inno_codec_close_path[] = {
+	{
+		.reg = INNO_REG_06,
+		.val = INNO_REG_06_DAC_EN_WORK     |
+		       INNO_REG_06_DAC_PRECHARGE   |
+		       INNO_REG_06_DACL_HL_RV_WORK |
+		       INNO_REG_06_DACR_HL_RV_WORK |
+		       INNO_REG_06_VOUTL_CZ_STOP   |
+		       INNO_REG_06_VOUTR_CZ_STOP,
+	},
+	{
+		.reg = INNO_REG_07,
+		.val = INNO_REG_07_HPOUTL_GAIN_N39DB,
+	},
+	{
+		.reg = INNO_REG_08,
+		.val = INNO_REG_08_HPOUTR_GAIN_N39DB,
+	},
+	{
+		.reg = INNO_REG_09,
+		.val = INNO_REG_09_POWERON,
+	},
+	{
+		.reg = INNO_REG_05,
+		.val = INNO_REG_05_HPOUTR_EN_WORK  |
+		       INNO_REG_05_HPOUTL_EN_WORK  |
+		       INNO_REG_05_HPOUTR_INIT     |
+		       INNO_REG_05_HPOUTL_INIT,
+	},
+	{
+		.reg = INNO_REG_09,
+		.val = INNO_REG_09_DACL_WORK       |
+		       INNO_REG_09_DACR_WORK       |
+		       INNO_REG_09_HP_OUTL_MUTE_YES |
+		       INNO_REG_09_HP_OUTR_MUTE_YES |
+		       INNO_REG_09_HP_OUTR_POP_PRECHARGE |
+		       INNO_REG_09_HP_OUTL_POP_PRECHARGE,
+	},
+	{
+		.reg = INNO_REG_04,
+		.val = INNO_REG_04_DACR_RV_STOP    |
+		       INNO_REG_04_DACL_RV_STOP    |
+		       INNO_REG_04_DACL_CLK_STOP   |
+		       INNO_REG_04_DACR_CLK_STOP   |
+		       INNO_REG_04_DACL_STOP       |
+		       INNO_REG_04_DACR_STOP,
+	},
+	{
+		.reg = INNO_REG_06,
+		.val = INNO_REG_06_DAC_DISCHARGE,
+	},
+	{
+		.reg = INNO_REG_09,
+		.val = INNO_REG_09_DACL_INIT       |
+		       INNO_REG_09_DACR_INIT       |
+		       INNO_REG_09_HP_OUTL_MUTE_YES |
+		       INNO_REG_09_HP_OUTR_MUTE_YES |
+		       INNO_REG_09_HP_OUTR_POP_PRECHARGE |
+		       INNO_REG_09_HP_OUTL_POP_PRECHARGE,
+	},
+};
+
+#endif
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v1 2/4] ASoC: RK3036: Add binding doc of inno-rk3036 codec driver
  2015-10-13  1:01 ` Shunqian Zheng
@ 2015-10-13  1:01   ` Shunqian Zheng
  -1 siblings, 0 replies; 28+ messages in thread
From: Shunqian Zheng @ 2015-10-13  1:01 UTC (permalink / raw)
  To: robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak, heiko,
	lgirdwood, broonie, perex, tiwai, benzh
  Cc: linux-arm-kernel, linux-kernel, linux-rockchip, alsa-devel,
	ZhengShunQian

From: ZhengShunQian <zhengsq@rock-chips.com>

This patch add the binding document of inno-rk3036
audio codec driver.

Signed-off-by: ZhengShunQian <zhengsq@rock-chips.com>
---
 .../devicetree/bindings/sound/inno-rk3036.txt        | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/inno-rk3036.txt

diff --git a/Documentation/devicetree/bindings/sound/inno-rk3036.txt b/Documentation/devicetree/bindings/sound/inno-rk3036.txt
new file mode 100644
index 0000000..57eb7bc
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/inno-rk3036.txt
@@ -0,0 +1,20 @@
+Inno audio codec for RK3036
+
+Inno audio codec is integrated inside RK3036 SoC.
+
+Required properties:
+- compatible : Should be "rk3036-codec".
+- reg : The registers of codec.
+- clock-names : Should be "acodec_pclk".
+- clocks : The clock of codec.
+- rockchip,grf : The phandle of grf device node.
+
+Example:
+
+	acodec: acodec-ana@20030000 {
+		compatible = "rk3036-codec";
+		reg = <0x20030000 0x4000>;
+		rockchip,grf = <&grf>;
+		clock-names = "acodec_pclk";
+		clocks = <&cru ACLK_VCODEC>;
+	};
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v1 2/4] ASoC: RK3036: Add binding doc of inno-rk3036 codec driver
@ 2015-10-13  1:01   ` Shunqian Zheng
  0 siblings, 0 replies; 28+ messages in thread
From: Shunqian Zheng @ 2015-10-13  1:01 UTC (permalink / raw)
  To: linux-arm-kernel

From: ZhengShunQian <zhengsq@rock-chips.com>

This patch add the binding document of inno-rk3036
audio codec driver.

Signed-off-by: ZhengShunQian <zhengsq@rock-chips.com>
---
 .../devicetree/bindings/sound/inno-rk3036.txt        | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/inno-rk3036.txt

diff --git a/Documentation/devicetree/bindings/sound/inno-rk3036.txt b/Documentation/devicetree/bindings/sound/inno-rk3036.txt
new file mode 100644
index 0000000..57eb7bc
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/inno-rk3036.txt
@@ -0,0 +1,20 @@
+Inno audio codec for RK3036
+
+Inno audio codec is integrated inside RK3036 SoC.
+
+Required properties:
+- compatible : Should be "rk3036-codec".
+- reg : The registers of codec.
+- clock-names : Should be "acodec_pclk".
+- clocks : The clock of codec.
+- rockchip,grf : The phandle of grf device node.
+
+Example:
+
+	acodec: acodec-ana at 20030000 {
+		compatible = "rk3036-codec";
+		reg = <0x20030000 0x4000>;
+		rockchip,grf = <&grf>;
+		clock-names = "acodec_pclk";
+		clocks = <&cru ACLK_VCODEC>;
+	};
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v1 3/4] ASoC: Add codec machine driver for RK3036
@ 2015-10-13  1:01   ` Shunqian Zheng
  0 siblings, 0 replies; 28+ messages in thread
From: Shunqian Zheng @ 2015-10-13  1:01 UTC (permalink / raw)
  To: robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak, heiko,
	lgirdwood, broonie, perex, tiwai, benzh
  Cc: linux-arm-kernel, linux-kernel, linux-rockchip, alsa-devel,
	ZhengShunQian

From: ZhengShunQian <zhengsq@rock-chips.com>

This patch add the machine driver for rk3036.

RK3036 SoC is integrated with Inno codec,
this patch should work for all RK3036 board.

Signed-off-by: ZhengShunQian <zhengsq@rock-chips.com>
---
 sound/soc/rockchip/Kconfig           |  10 +++
 sound/soc/rockchip/Makefile          |   2 +
 sound/soc/rockchip/rockchip_rk3036.c | 147 +++++++++++++++++++++++++++++++++++
 3 files changed, 159 insertions(+)
 create mode 100644 sound/soc/rockchip/rockchip_rk3036.c

diff --git a/sound/soc/rockchip/Kconfig b/sound/soc/rockchip/Kconfig
index 5709057..3d48bda 100644
--- a/sound/soc/rockchip/Kconfig
+++ b/sound/soc/rockchip/Kconfig
@@ -33,3 +33,13 @@ config SND_SOC_ROCKCHIP_RT5645
 	help
 	  Say Y or M here if you want to add support for SoC audio on Rockchip
 	  boards using the RT5645/RT5650 codec, such as Veyron.
+
+config SND_SOC_ROCKCHIP_RK3036
+	tristate "ASoC support for RK3036 inner codec"
+	depends on SND_SOC_ROCKCHIP
+	select SND_SOC_ROCKCHIP_I2S
+	help
+	  Say Y or M here if you want to add support for SoC audio on Rockchip
+	  RK3036.
+
+
diff --git a/sound/soc/rockchip/Makefile b/sound/soc/rockchip/Makefile
index e9ba558..9a770c8 100644
--- a/sound/soc/rockchip/Makefile
+++ b/sound/soc/rockchip/Makefile
@@ -4,7 +4,9 @@ snd-soc-rockchip-i2s-objs := rockchip_i2s.o
 obj-$(CONFIG_SND_SOC_ROCKCHIP_I2S) += snd-soc-rockchip-i2s.o
 
 snd-soc-rockchip-max98090-objs := rockchip_max98090.o
+snd-soc-rockchip-rk3036-objs := rockchip_rk3036.o
 snd-soc-rockchip-rt5645-objs := rockchip_rt5645.o
 
 obj-$(CONFIG_SND_SOC_ROCKCHIP_MAX98090) += snd-soc-rockchip-max98090.o
+obj-$(CONFIG_SND_SOC_ROCKCHIP_RK3036) += snd-soc-rockchip-rk3036.o
 obj-$(CONFIG_SND_SOC_ROCKCHIP_RT5645) += snd-soc-rockchip-rt5645.o
diff --git a/sound/soc/rockchip/rockchip_rk3036.c b/sound/soc/rockchip/rockchip_rk3036.c
new file mode 100644
index 0000000..3747d90
--- /dev/null
+++ b/sound/soc/rockchip/rockchip_rk3036.c
@@ -0,0 +1,147 @@
+/*
+ * Machine driver for rk3036 audio codec.
+ *
+ * Copyright (c) 2015, ROCKCHIP CORPORATION.  All rights reserved.
+ *
+ * Author: Zheng ShunQian<zhengsq@rock-chips.com>
+ */
+
+#include <linux/device.h>
+#include <linux/of.h>
+#include <linux/module.h>
+
+#include <sound/soc.h>
+#include <sound/pcm.h>
+#include <sound/soc-dapm.h>
+
+static int rk3036_hw_params(struct snd_pcm_substream *substream,
+			    struct snd_pcm_hw_params *params)
+{
+	struct snd_soc_pcm_runtime *rtd = substream->private_data;
+	struct snd_soc_dai *codec_dai = rtd->codec_dai;
+	struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
+	unsigned int dai_fmt = rtd->dai_link->dai_fmt;
+	int mclk, ret;
+
+	dev_dbg(rtd->dev, "codec machine: %s\n", __func__);
+	/* set codec DAI configuration */
+	ret = snd_soc_dai_set_fmt(codec_dai, dai_fmt);
+	if (ret < 0)
+		return ret;
+
+	/* set cpu DAI configuration */
+	ret = snd_soc_dai_set_fmt(cpu_dai, dai_fmt);
+	if (ret < 0)
+		return ret;
+
+	switch (params_rate(params)) {
+	case 8000:
+	case 16000:
+	case 24000:
+	case 32000:
+	case 48000:
+		mclk = 12288000;
+		break;
+	case 44100:
+		mclk = 11289600;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	/*Set the system clk for codec*/
+	ret = snd_soc_dai_set_sysclk(codec_dai, 0, mclk, SND_SOC_CLOCK_IN);
+	if (ret < 0)
+		return ret;
+
+	ret = snd_soc_dai_set_sysclk(cpu_dai, 0, mclk, SND_SOC_CLOCK_OUT);
+	if (ret < 0)
+		return ret;
+
+	return 0;
+}
+
+static struct snd_soc_ops rk3036_ops = {
+	  .hw_params = rk3036_hw_params,
+};
+
+static int rk30_rk3036_codec_init(struct snd_soc_pcm_runtime *rtd)
+{
+	return 0;
+}
+
+static struct snd_soc_dai_link rk3036_dai = {
+	.name = "INNO-RK3036",
+	.stream_name = "RK3036 CODEC PCM",
+	.codec_dai_name = "rk3036-codec-dai",
+	.init = rk30_rk3036_codec_init,
+	.ops = &rk3036_ops,
+	/* set codec as slave */
+	.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
+		   SND_SOC_DAIFMT_CBS_CFS,
+};
+
+static struct snd_soc_card rockchip_rk3036_snd_card = {
+	.name = "ROCKCHIP-I2S",
+	.dai_link = &rk3036_dai,
+	.num_links = 1,
+};
+
+static int rockchip_rk3036_audio_probe(struct platform_device *pdev)
+{
+	struct snd_soc_card *card = &rockchip_rk3036_snd_card;
+	struct device_node *np = pdev->dev.of_node;
+
+	platform_set_drvdata(pdev, card);
+	card->dev = &pdev->dev;
+
+	rk3036_dai.codec_of_node = of_parse_phandle(np,
+			"rockchip,audio-codec", 0);
+	if (!rk3036_dai.codec_of_node) {
+		dev_err(&pdev->dev, "Property 'rockchip,audio-codec' "
+			"missing or invalid\n");
+		return -EINVAL;
+	}
+
+	rk3036_dai.cpu_of_node = of_parse_phandle(np,
+			"rockchip,i2s-controller", 0);
+	if (!rk3036_dai.cpu_of_node) {
+		dev_err(&pdev->dev, "Property 'rockchip,i2s-controller' "
+			"missing or invalid\n");
+		return -EINVAL;
+	}
+
+	rk3036_dai.platform_of_node = rk3036_dai.cpu_of_node;
+
+	return snd_soc_register_card(card);
+}
+
+static int rockchip_rk3036_audio_remove(struct platform_device *pdev)
+{
+	struct snd_soc_card *card = platform_get_drvdata(pdev);
+
+	snd_soc_unregister_card(card);
+
+	return 0;
+}
+
+static const struct of_device_id rockchip_rk3036_of_match[] = {
+		{ .compatible = "rockchip,rk3036-audio", },
+		{},
+};
+MODULE_DEVICE_TABLE(of, rockchip_rk3036_of_match);
+
+static struct platform_driver rockchip_rk3036_audio_driver = {
+	.driver = {
+		.name   = "rk3036-audio",
+		.owner  = THIS_MODULE,
+		.of_match_table = of_match_ptr(rockchip_rk3036_of_match),
+	},
+	.probe      = rockchip_rk3036_audio_probe,
+	.remove     = rockchip_rk3036_audio_remove,
+};
+module_platform_driver(rockchip_rk3036_audio_driver);
+
+MODULE_AUTHOR("Rockchip Inc.");
+MODULE_DESCRIPTION("Rockchip RK3036 Inno codec machine ASoC driver");
+MODULE_LICENSE("GPL");
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v1 3/4] ASoC: Add codec machine driver for RK3036
@ 2015-10-13  1:01   ` Shunqian Zheng
  0 siblings, 0 replies; 28+ messages in thread
From: Shunqian Zheng @ 2015-10-13  1:01 UTC (permalink / raw)
  To: robh+dt-DgEjT+Ai2ygdnm+yROfE0A, pawel.moll-5wv7dgnIgG8,
	mark.rutland-5wv7dgnIgG8, ijc+devicetree-KcIKpvwj1kUDXYZnReoRVg,
	galak-sgV2jX0FEOL9JmXXK+q4OQ, heiko-4mtYJXux2i+zQB+pC5nmwQ,
	lgirdwood-Re5JQEeQqe8AvxtiuMwx3w, broonie-DgEjT+Ai2ygdnm+yROfE0A,
	perex-/Fr2/VpizcU, tiwai-IBi9RG/b67k,
	benzh-F7+t8E8rja9g9hUCZPvPmw
  Cc: linux-rockchip-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	alsa-devel-K7yf7f+aM1XWsZ/bQMPhNw, ZhengShunQian,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r

From: ZhengShunQian <zhengsq-TNX95d0MmH7DzftRWevZcw@public.gmane.org>

This patch add the machine driver for rk3036.

RK3036 SoC is integrated with Inno codec,
this patch should work for all RK3036 board.

Signed-off-by: ZhengShunQian <zhengsq-TNX95d0MmH7DzftRWevZcw@public.gmane.org>
---
 sound/soc/rockchip/Kconfig           |  10 +++
 sound/soc/rockchip/Makefile          |   2 +
 sound/soc/rockchip/rockchip_rk3036.c | 147 +++++++++++++++++++++++++++++++++++
 3 files changed, 159 insertions(+)
 create mode 100644 sound/soc/rockchip/rockchip_rk3036.c

diff --git a/sound/soc/rockchip/Kconfig b/sound/soc/rockchip/Kconfig
index 5709057..3d48bda 100644
--- a/sound/soc/rockchip/Kconfig
+++ b/sound/soc/rockchip/Kconfig
@@ -33,3 +33,13 @@ config SND_SOC_ROCKCHIP_RT5645
 	help
 	  Say Y or M here if you want to add support for SoC audio on Rockchip
 	  boards using the RT5645/RT5650 codec, such as Veyron.
+
+config SND_SOC_ROCKCHIP_RK3036
+	tristate "ASoC support for RK3036 inner codec"
+	depends on SND_SOC_ROCKCHIP
+	select SND_SOC_ROCKCHIP_I2S
+	help
+	  Say Y or M here if you want to add support for SoC audio on Rockchip
+	  RK3036.
+
+
diff --git a/sound/soc/rockchip/Makefile b/sound/soc/rockchip/Makefile
index e9ba558..9a770c8 100644
--- a/sound/soc/rockchip/Makefile
+++ b/sound/soc/rockchip/Makefile
@@ -4,7 +4,9 @@ snd-soc-rockchip-i2s-objs := rockchip_i2s.o
 obj-$(CONFIG_SND_SOC_ROCKCHIP_I2S) += snd-soc-rockchip-i2s.o
 
 snd-soc-rockchip-max98090-objs := rockchip_max98090.o
+snd-soc-rockchip-rk3036-objs := rockchip_rk3036.o
 snd-soc-rockchip-rt5645-objs := rockchip_rt5645.o
 
 obj-$(CONFIG_SND_SOC_ROCKCHIP_MAX98090) += snd-soc-rockchip-max98090.o
+obj-$(CONFIG_SND_SOC_ROCKCHIP_RK3036) += snd-soc-rockchip-rk3036.o
 obj-$(CONFIG_SND_SOC_ROCKCHIP_RT5645) += snd-soc-rockchip-rt5645.o
diff --git a/sound/soc/rockchip/rockchip_rk3036.c b/sound/soc/rockchip/rockchip_rk3036.c
new file mode 100644
index 0000000..3747d90
--- /dev/null
+++ b/sound/soc/rockchip/rockchip_rk3036.c
@@ -0,0 +1,147 @@
+/*
+ * Machine driver for rk3036 audio codec.
+ *
+ * Copyright (c) 2015, ROCKCHIP CORPORATION.  All rights reserved.
+ *
+ * Author: Zheng ShunQian<zhengsq-TNX95d0MmH7DzftRWevZcw@public.gmane.org>
+ */
+
+#include <linux/device.h>
+#include <linux/of.h>
+#include <linux/module.h>
+
+#include <sound/soc.h>
+#include <sound/pcm.h>
+#include <sound/soc-dapm.h>
+
+static int rk3036_hw_params(struct snd_pcm_substream *substream,
+			    struct snd_pcm_hw_params *params)
+{
+	struct snd_soc_pcm_runtime *rtd = substream->private_data;
+	struct snd_soc_dai *codec_dai = rtd->codec_dai;
+	struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
+	unsigned int dai_fmt = rtd->dai_link->dai_fmt;
+	int mclk, ret;
+
+	dev_dbg(rtd->dev, "codec machine: %s\n", __func__);
+	/* set codec DAI configuration */
+	ret = snd_soc_dai_set_fmt(codec_dai, dai_fmt);
+	if (ret < 0)
+		return ret;
+
+	/* set cpu DAI configuration */
+	ret = snd_soc_dai_set_fmt(cpu_dai, dai_fmt);
+	if (ret < 0)
+		return ret;
+
+	switch (params_rate(params)) {
+	case 8000:
+	case 16000:
+	case 24000:
+	case 32000:
+	case 48000:
+		mclk = 12288000;
+		break;
+	case 44100:
+		mclk = 11289600;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	/*Set the system clk for codec*/
+	ret = snd_soc_dai_set_sysclk(codec_dai, 0, mclk, SND_SOC_CLOCK_IN);
+	if (ret < 0)
+		return ret;
+
+	ret = snd_soc_dai_set_sysclk(cpu_dai, 0, mclk, SND_SOC_CLOCK_OUT);
+	if (ret < 0)
+		return ret;
+
+	return 0;
+}
+
+static struct snd_soc_ops rk3036_ops = {
+	  .hw_params = rk3036_hw_params,
+};
+
+static int rk30_rk3036_codec_init(struct snd_soc_pcm_runtime *rtd)
+{
+	return 0;
+}
+
+static struct snd_soc_dai_link rk3036_dai = {
+	.name = "INNO-RK3036",
+	.stream_name = "RK3036 CODEC PCM",
+	.codec_dai_name = "rk3036-codec-dai",
+	.init = rk30_rk3036_codec_init,
+	.ops = &rk3036_ops,
+	/* set codec as slave */
+	.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
+		   SND_SOC_DAIFMT_CBS_CFS,
+};
+
+static struct snd_soc_card rockchip_rk3036_snd_card = {
+	.name = "ROCKCHIP-I2S",
+	.dai_link = &rk3036_dai,
+	.num_links = 1,
+};
+
+static int rockchip_rk3036_audio_probe(struct platform_device *pdev)
+{
+	struct snd_soc_card *card = &rockchip_rk3036_snd_card;
+	struct device_node *np = pdev->dev.of_node;
+
+	platform_set_drvdata(pdev, card);
+	card->dev = &pdev->dev;
+
+	rk3036_dai.codec_of_node = of_parse_phandle(np,
+			"rockchip,audio-codec", 0);
+	if (!rk3036_dai.codec_of_node) {
+		dev_err(&pdev->dev, "Property 'rockchip,audio-codec' "
+			"missing or invalid\n");
+		return -EINVAL;
+	}
+
+	rk3036_dai.cpu_of_node = of_parse_phandle(np,
+			"rockchip,i2s-controller", 0);
+	if (!rk3036_dai.cpu_of_node) {
+		dev_err(&pdev->dev, "Property 'rockchip,i2s-controller' "
+			"missing or invalid\n");
+		return -EINVAL;
+	}
+
+	rk3036_dai.platform_of_node = rk3036_dai.cpu_of_node;
+
+	return snd_soc_register_card(card);
+}
+
+static int rockchip_rk3036_audio_remove(struct platform_device *pdev)
+{
+	struct snd_soc_card *card = platform_get_drvdata(pdev);
+
+	snd_soc_unregister_card(card);
+
+	return 0;
+}
+
+static const struct of_device_id rockchip_rk3036_of_match[] = {
+		{ .compatible = "rockchip,rk3036-audio", },
+		{},
+};
+MODULE_DEVICE_TABLE(of, rockchip_rk3036_of_match);
+
+static struct platform_driver rockchip_rk3036_audio_driver = {
+	.driver = {
+		.name   = "rk3036-audio",
+		.owner  = THIS_MODULE,
+		.of_match_table = of_match_ptr(rockchip_rk3036_of_match),
+	},
+	.probe      = rockchip_rk3036_audio_probe,
+	.remove     = rockchip_rk3036_audio_remove,
+};
+module_platform_driver(rockchip_rk3036_audio_driver);
+
+MODULE_AUTHOR("Rockchip Inc.");
+MODULE_DESCRIPTION("Rockchip RK3036 Inno codec machine ASoC driver");
+MODULE_LICENSE("GPL");
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v1 3/4] ASoC: Add codec machine driver for RK3036
@ 2015-10-13  1:01   ` Shunqian Zheng
  0 siblings, 0 replies; 28+ messages in thread
From: Shunqian Zheng @ 2015-10-13  1:01 UTC (permalink / raw)
  To: linux-arm-kernel

From: ZhengShunQian <zhengsq@rock-chips.com>

This patch add the machine driver for rk3036.

RK3036 SoC is integrated with Inno codec,
this patch should work for all RK3036 board.

Signed-off-by: ZhengShunQian <zhengsq@rock-chips.com>
---
 sound/soc/rockchip/Kconfig           |  10 +++
 sound/soc/rockchip/Makefile          |   2 +
 sound/soc/rockchip/rockchip_rk3036.c | 147 +++++++++++++++++++++++++++++++++++
 3 files changed, 159 insertions(+)
 create mode 100644 sound/soc/rockchip/rockchip_rk3036.c

diff --git a/sound/soc/rockchip/Kconfig b/sound/soc/rockchip/Kconfig
index 5709057..3d48bda 100644
--- a/sound/soc/rockchip/Kconfig
+++ b/sound/soc/rockchip/Kconfig
@@ -33,3 +33,13 @@ config SND_SOC_ROCKCHIP_RT5645
 	help
 	  Say Y or M here if you want to add support for SoC audio on Rockchip
 	  boards using the RT5645/RT5650 codec, such as Veyron.
+
+config SND_SOC_ROCKCHIP_RK3036
+	tristate "ASoC support for RK3036 inner codec"
+	depends on SND_SOC_ROCKCHIP
+	select SND_SOC_ROCKCHIP_I2S
+	help
+	  Say Y or M here if you want to add support for SoC audio on Rockchip
+	  RK3036.
+
+
diff --git a/sound/soc/rockchip/Makefile b/sound/soc/rockchip/Makefile
index e9ba558..9a770c8 100644
--- a/sound/soc/rockchip/Makefile
+++ b/sound/soc/rockchip/Makefile
@@ -4,7 +4,9 @@ snd-soc-rockchip-i2s-objs := rockchip_i2s.o
 obj-$(CONFIG_SND_SOC_ROCKCHIP_I2S) += snd-soc-rockchip-i2s.o
 
 snd-soc-rockchip-max98090-objs := rockchip_max98090.o
+snd-soc-rockchip-rk3036-objs := rockchip_rk3036.o
 snd-soc-rockchip-rt5645-objs := rockchip_rt5645.o
 
 obj-$(CONFIG_SND_SOC_ROCKCHIP_MAX98090) += snd-soc-rockchip-max98090.o
+obj-$(CONFIG_SND_SOC_ROCKCHIP_RK3036) += snd-soc-rockchip-rk3036.o
 obj-$(CONFIG_SND_SOC_ROCKCHIP_RT5645) += snd-soc-rockchip-rt5645.o
diff --git a/sound/soc/rockchip/rockchip_rk3036.c b/sound/soc/rockchip/rockchip_rk3036.c
new file mode 100644
index 0000000..3747d90
--- /dev/null
+++ b/sound/soc/rockchip/rockchip_rk3036.c
@@ -0,0 +1,147 @@
+/*
+ * Machine driver for rk3036 audio codec.
+ *
+ * Copyright (c) 2015, ROCKCHIP CORPORATION.  All rights reserved.
+ *
+ * Author: Zheng ShunQian<zhengsq@rock-chips.com>
+ */
+
+#include <linux/device.h>
+#include <linux/of.h>
+#include <linux/module.h>
+
+#include <sound/soc.h>
+#include <sound/pcm.h>
+#include <sound/soc-dapm.h>
+
+static int rk3036_hw_params(struct snd_pcm_substream *substream,
+			    struct snd_pcm_hw_params *params)
+{
+	struct snd_soc_pcm_runtime *rtd = substream->private_data;
+	struct snd_soc_dai *codec_dai = rtd->codec_dai;
+	struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
+	unsigned int dai_fmt = rtd->dai_link->dai_fmt;
+	int mclk, ret;
+
+	dev_dbg(rtd->dev, "codec machine: %s\n", __func__);
+	/* set codec DAI configuration */
+	ret = snd_soc_dai_set_fmt(codec_dai, dai_fmt);
+	if (ret < 0)
+		return ret;
+
+	/* set cpu DAI configuration */
+	ret = snd_soc_dai_set_fmt(cpu_dai, dai_fmt);
+	if (ret < 0)
+		return ret;
+
+	switch (params_rate(params)) {
+	case 8000:
+	case 16000:
+	case 24000:
+	case 32000:
+	case 48000:
+		mclk = 12288000;
+		break;
+	case 44100:
+		mclk = 11289600;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	/*Set the system clk for codec*/
+	ret = snd_soc_dai_set_sysclk(codec_dai, 0, mclk, SND_SOC_CLOCK_IN);
+	if (ret < 0)
+		return ret;
+
+	ret = snd_soc_dai_set_sysclk(cpu_dai, 0, mclk, SND_SOC_CLOCK_OUT);
+	if (ret < 0)
+		return ret;
+
+	return 0;
+}
+
+static struct snd_soc_ops rk3036_ops = {
+	  .hw_params = rk3036_hw_params,
+};
+
+static int rk30_rk3036_codec_init(struct snd_soc_pcm_runtime *rtd)
+{
+	return 0;
+}
+
+static struct snd_soc_dai_link rk3036_dai = {
+	.name = "INNO-RK3036",
+	.stream_name = "RK3036 CODEC PCM",
+	.codec_dai_name = "rk3036-codec-dai",
+	.init = rk30_rk3036_codec_init,
+	.ops = &rk3036_ops,
+	/* set codec as slave */
+	.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
+		   SND_SOC_DAIFMT_CBS_CFS,
+};
+
+static struct snd_soc_card rockchip_rk3036_snd_card = {
+	.name = "ROCKCHIP-I2S",
+	.dai_link = &rk3036_dai,
+	.num_links = 1,
+};
+
+static int rockchip_rk3036_audio_probe(struct platform_device *pdev)
+{
+	struct snd_soc_card *card = &rockchip_rk3036_snd_card;
+	struct device_node *np = pdev->dev.of_node;
+
+	platform_set_drvdata(pdev, card);
+	card->dev = &pdev->dev;
+
+	rk3036_dai.codec_of_node = of_parse_phandle(np,
+			"rockchip,audio-codec", 0);
+	if (!rk3036_dai.codec_of_node) {
+		dev_err(&pdev->dev, "Property 'rockchip,audio-codec' "
+			"missing or invalid\n");
+		return -EINVAL;
+	}
+
+	rk3036_dai.cpu_of_node = of_parse_phandle(np,
+			"rockchip,i2s-controller", 0);
+	if (!rk3036_dai.cpu_of_node) {
+		dev_err(&pdev->dev, "Property 'rockchip,i2s-controller' "
+			"missing or invalid\n");
+		return -EINVAL;
+	}
+
+	rk3036_dai.platform_of_node = rk3036_dai.cpu_of_node;
+
+	return snd_soc_register_card(card);
+}
+
+static int rockchip_rk3036_audio_remove(struct platform_device *pdev)
+{
+	struct snd_soc_card *card = platform_get_drvdata(pdev);
+
+	snd_soc_unregister_card(card);
+
+	return 0;
+}
+
+static const struct of_device_id rockchip_rk3036_of_match[] = {
+		{ .compatible = "rockchip,rk3036-audio", },
+		{},
+};
+MODULE_DEVICE_TABLE(of, rockchip_rk3036_of_match);
+
+static struct platform_driver rockchip_rk3036_audio_driver = {
+	.driver = {
+		.name   = "rk3036-audio",
+		.owner  = THIS_MODULE,
+		.of_match_table = of_match_ptr(rockchip_rk3036_of_match),
+	},
+	.probe      = rockchip_rk3036_audio_probe,
+	.remove     = rockchip_rk3036_audio_remove,
+};
+module_platform_driver(rockchip_rk3036_audio_driver);
+
+MODULE_AUTHOR("Rockchip Inc.");
+MODULE_DESCRIPTION("Rockchip RK3036 Inno codec machine ASoC driver");
+MODULE_LICENSE("GPL");
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v1 4/4] ASoC: RK3036: Add binding doc for audio machine driver
  2015-10-13  1:01 ` Shunqian Zheng
@ 2015-10-13  1:01   ` Shunqian Zheng
  -1 siblings, 0 replies; 28+ messages in thread
From: Shunqian Zheng @ 2015-10-13  1:01 UTC (permalink / raw)
  To: robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak, heiko,
	lgirdwood, broonie, perex, tiwai, benzh
  Cc: linux-arm-kernel, linux-kernel, linux-rockchip, alsa-devel,
	ZhengShunQian

From: ZhengShunQian <zhengsq@rock-chips.com>

This patch add binding document for RK3036 SoC audio
machine driver.

Signed-off-by: ZhengShunQian <zhengsq@rock-chips.com>
---
 .../devicetree/bindings/sound/rockchip-rk3036.txt          | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/rockchip-rk3036.txt

diff --git a/Documentation/devicetree/bindings/sound/rockchip-rk3036.txt b/Documentation/devicetree/bindings/sound/rockchip-rk3036.txt
new file mode 100644
index 0000000..53d5738
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/rockchip-rk3036.txt
@@ -0,0 +1,14 @@
+RK3036 SoC with Inno audio codec integrated
+
+Required properties:
+- compatible: Should be "rockchip,rk3036-audio".
+- rockchip,i2s-controller: The phandle of the Rockchip I2S controller.
+- rockchip,audio-codec: The phandle of the Inno-rk3036 audio codec.
+
+Example:
+
+	sound {
+		compatible = "rockchip,rk3036-audio";
+		rockchip,i2s-controller = <&i2s>;
+		rockchip,audio-codec = <&acodec>;
+	};
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v1 4/4] ASoC: RK3036: Add binding doc for audio machine driver
@ 2015-10-13  1:01   ` Shunqian Zheng
  0 siblings, 0 replies; 28+ messages in thread
From: Shunqian Zheng @ 2015-10-13  1:01 UTC (permalink / raw)
  To: linux-arm-kernel

From: ZhengShunQian <zhengsq@rock-chips.com>

This patch add binding document for RK3036 SoC audio
machine driver.

Signed-off-by: ZhengShunQian <zhengsq@rock-chips.com>
---
 .../devicetree/bindings/sound/rockchip-rk3036.txt          | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/rockchip-rk3036.txt

diff --git a/Documentation/devicetree/bindings/sound/rockchip-rk3036.txt b/Documentation/devicetree/bindings/sound/rockchip-rk3036.txt
new file mode 100644
index 0000000..53d5738
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/rockchip-rk3036.txt
@@ -0,0 +1,14 @@
+RK3036 SoC with Inno audio codec integrated
+
+Required properties:
+- compatible: Should be "rockchip,rk3036-audio".
+- rockchip,i2s-controller: The phandle of the Rockchip I2S controller.
+- rockchip,audio-codec: The phandle of the Inno-rk3036 audio codec.
+
+Example:
+
+	sound {
+		compatible = "rockchip,rk3036-audio";
+		rockchip,i2s-controller = <&i2s>;
+		rockchip,audio-codec = <&acodec>;
+	};
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* Re: [alsa-devel] [PATCH v1 1/4] ASoC: codec: Inno codec driver for RK3036 SoC
  2015-10-13  1:01   ` Shunqian Zheng
  (?)
@ 2015-10-19  6:56     ` Ricard Wanderlof
  -1 siblings, 0 replies; 28+ messages in thread
From: Ricard Wanderlof @ 2015-10-19  6:56 UTC (permalink / raw)
  To: Shunqian Zheng
  Cc: robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak, heiko,
	lgirdwood, broonie, perex, tiwai, benzh, linux-rockchip,
	alsa-devel, linux-kernel, linux-arm-kernel


On Tue, 13 Oct 2015, Shunqian Zheng wrote:

> +static const struct of_device_id rk3036_codec_of_match[] = {
> +       { .compatible = "rk3036-codec", },
> +       {}
> +};
> +MODULE_DEVICE_TABLE(of, rk3036_codec_of_match);

Isn't a compatible string normally in the form "rockchip,rk3036-codec" ?

/Ricard
-- 
Ricard Wolf Wanderlöf                           ricardw(at)axis.com
Axis Communications AB, Lund, Sweden            www.axis.com
Phone +46 46 272 2016                           Fax +46 46 13 61 30

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [alsa-devel] [PATCH v1 1/4] ASoC: codec: Inno codec driver for RK3036 SoC
@ 2015-10-19  6:56     ` Ricard Wanderlof
  0 siblings, 0 replies; 28+ messages in thread
From: Ricard Wanderlof @ 2015-10-19  6:56 UTC (permalink / raw)
  To: Shunqian Zheng
  Cc: robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak, heiko,
	lgirdwood, broonie, perex, tiwai, benzh, linux-rockchip,
	alsa-devel, linux-kernel, linux-arm-kernel


On Tue, 13 Oct 2015, Shunqian Zheng wrote:

> +static const struct of_device_id rk3036_codec_of_match[] = {
> +       { .compatible = "rk3036-codec", },
> +       {}
> +};
> +MODULE_DEVICE_TABLE(of, rk3036_codec_of_match);

Isn't a compatible string normally in the form "rockchip,rk3036-codec" ?

/Ricard
-- 
Ricard Wolf Wanderlöf                           ricardw(at)axis.com
Axis Communications AB, Lund, Sweden            www.axis.com
Phone +46 46 272 2016                           Fax +46 46 13 61 30

^ permalink raw reply	[flat|nested] 28+ messages in thread

* [alsa-devel] [PATCH v1 1/4] ASoC: codec: Inno codec driver for RK3036 SoC
@ 2015-10-19  6:56     ` Ricard Wanderlof
  0 siblings, 0 replies; 28+ messages in thread
From: Ricard Wanderlof @ 2015-10-19  6:56 UTC (permalink / raw)
  To: linux-arm-kernel


On Tue, 13 Oct 2015, Shunqian Zheng wrote:

> +static const struct of_device_id rk3036_codec_of_match[] = {
> +       { .compatible = "rk3036-codec", },
> +       {}
> +};
> +MODULE_DEVICE_TABLE(of, rk3036_codec_of_match);

Isn't a compatible string normally in the form "rockchip,rk3036-codec" ?

/Ricard
-- 
Ricard Wolf Wanderl?f                           ricardw(at)axis.com
Axis Communications AB, Lund, Sweden            www.axis.com
Phone +46 46 272 2016                           Fax +46 46 13 61 30

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH v1 3/4] ASoC: Add codec machine driver for RK3036
  2015-10-13  1:01   ` Shunqian Zheng
@ 2015-10-19 12:12     ` Sjoerd Simons
  -1 siblings, 0 replies; 28+ messages in thread
From: Sjoerd Simons @ 2015-10-19 12:12 UTC (permalink / raw)
  To: Shunqian Zheng, robh+dt, pawel.moll, mark.rutland,
	ijc+devicetree, galak, heiko, lgirdwood, broonie, perex, tiwai,
	benzh
  Cc: linux-rockchip, alsa-devel, linux-kernel, linux-arm-kernel

On Tue, 2015-10-13 at 09:01 +0800, Shunqian Zheng wrote:
> From: ZhengShunQian <zhengsq@rock-chips.com>
> 
> This patch add the machine driver for rk3036.

Does this need a machine driver? Can't the simple-card machine driver
be used for this ? (From the looks of it that would only mean the
clocking setup for the cpu dai would need to move into the i2s driver?)


> RK3036 SoC is integrated with Inno codec,
> this patch should work for all RK3036 board.
> 
> Signed-off-by: ZhengShunQian <zhengsq@rock-chips.com>
> ---
>  sound/soc/rockchip/Kconfig           |  10 +++
>  sound/soc/rockchip/Makefile          |   2 +
>  sound/soc/rockchip/rockchip_rk3036.c | 147
> +++++++++++++++++++++++++++++++++++
>  3 files changed, 159 insertions(+)
>  create mode 100644 sound/soc/rockchip/rockchip_rk3036.c
> 
> diff --git a/sound/soc/rockchip/Kconfig b/sound/soc/rockchip/Kconfig
> index 5709057..3d48bda 100644
> --- a/sound/soc/rockchip/Kconfig
> +++ b/sound/soc/rockchip/Kconfig
> @@ -33,3 +33,13 @@ config SND_SOC_ROCKCHIP_RT5645
>  	help
>  	  Say Y or M here if you want to add support for SoC audio
> on Rockchip
>  	  boards using the RT5645/RT5650 codec, such as Veyron.
> +
> +config SND_SOC_ROCKCHIP_RK3036
> +	tristate "ASoC support for RK3036 inner codec"
> +	depends on SND_SOC_ROCKCHIP
> +	select SND_SOC_ROCKCHIP_I2S
> +	help
> +	  Say Y or M here if you want to add support for SoC audio
> on Rockchip
> +	  RK3036.
> +
> +
> diff --git a/sound/soc/rockchip/Makefile
> b/sound/soc/rockchip/Makefile
> index e9ba558..9a770c8 100644
> --- a/sound/soc/rockchip/Makefile
> +++ b/sound/soc/rockchip/Makefile
> @@ -4,7 +4,9 @@ snd-soc-rockchip-i2s-objs := rockchip_i2s.o
>  obj-$(CONFIG_SND_SOC_ROCKCHIP_I2S) += snd-soc-rockchip-i2s.o
>  
>  snd-soc-rockchip-max98090-objs := rockchip_max98090.o
> +snd-soc-rockchip-rk3036-objs := rockchip_rk3036.o
>  snd-soc-rockchip-rt5645-objs := rockchip_rt5645.o
>  
>  obj-$(CONFIG_SND_SOC_ROCKCHIP_MAX98090) += snd-soc-rockchip-
> max98090.o
> +obj-$(CONFIG_SND_SOC_ROCKCHIP_RK3036) += snd-soc-rockchip-rk3036.o
>  obj-$(CONFIG_SND_SOC_ROCKCHIP_RT5645) += snd-soc-rockchip-rt5645.o
> diff --git a/sound/soc/rockchip/rockchip_rk3036.c
> b/sound/soc/rockchip/rockchip_rk3036.c
> new file mode 100644
> index 0000000..3747d90
> --- /dev/null
> +++ b/sound/soc/rockchip/rockchip_rk3036.c
> @@ -0,0 +1,147 @@
> +/*
> + * Machine driver for rk3036 audio codec.
> + *
> + * Copyright (c) 2015, ROCKCHIP CORPORATION.  All rights reserved.
> + *
> + * Author: Zheng ShunQian<zhengsq@rock-chips.com>
> + */
> +
> +#include <linux/device.h>
> +#include <linux/of.h>
> +#include <linux/module.h>
> +
> +#include <sound/soc.h>
> +#include <sound/pcm.h>
> +#include <sound/soc-dapm.h>
> +
> +static int rk3036_hw_params(struct snd_pcm_substream *substream,
> +			    struct snd_pcm_hw_params *params)
> +{
> +	struct snd_soc_pcm_runtime *rtd = substream->private_data;
> +	struct snd_soc_dai *codec_dai = rtd->codec_dai;
> +	struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
> +	unsigned int dai_fmt = rtd->dai_link->dai_fmt;
> +	int mclk, ret;
> +
> +	dev_dbg(rtd->dev, "codec machine: %s\n", __func__);
> +	/* set codec DAI configuration */
> +	ret = snd_soc_dai_set_fmt(codec_dai, dai_fmt);
> +	if (ret < 0)
> +		return ret;
> +
> +	/* set cpu DAI configuration */
> +	ret = snd_soc_dai_set_fmt(cpu_dai, dai_fmt);
> +	if (ret < 0)
> +		return ret;
> +
> +	switch (params_rate(params)) {
> +	case 8000:
> +	case 16000:
> +	case 24000:
> +	case 32000:
> +	case 48000:
> +		mclk = 12288000;
> +		break;
> +	case 44100:
> +		mclk = 11289600;
> +		break;
> +	default:
> +		return -EINVAL;
> +	}
> +
> +	/*Set the system clk for codec*/
> +	ret = snd_soc_dai_set_sysclk(codec_dai, 0, mclk,
> SND_SOC_CLOCK_IN);
> +	if (ret < 0)
> +		return ret;
> +
> +	ret = snd_soc_dai_set_sysclk(cpu_dai, 0, mclk,
> SND_SOC_CLOCK_OUT);
> +	if (ret < 0)
> +		return ret;
> +
> +	return 0;
> +}
> +
> +static struct snd_soc_ops rk3036_ops = {
> +	  .hw_params = rk3036_hw_params,
> +};
> +
> +static int rk30_rk3036_codec_init(struct snd_soc_pcm_runtime *rtd)
> +{
> +	return 0;
> +}
> +
> +static struct snd_soc_dai_link rk3036_dai = {
> +	.name = "INNO-RK3036",
> +	.stream_name = "RK3036 CODEC PCM",
> +	.codec_dai_name = "rk3036-codec-dai",
> +	.init = rk30_rk3036_codec_init,
> +	.ops = &rk3036_ops,
> +	/* set codec as slave */
> +	.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
> +		   SND_SOC_DAIFMT_CBS_CFS,
> +};
> +
> +static struct snd_soc_card rockchip_rk3036_snd_card = {
> +	.name = "ROCKCHIP-I2S",
> +	.dai_link = &rk3036_dai,
> +	.num_links = 1,
> +};
> +
> +static int rockchip_rk3036_audio_probe(struct platform_device *pdev)
> +{
> +	struct snd_soc_card *card = &rockchip_rk3036_snd_card;
> +	struct device_node *np = pdev->dev.of_node;
> +
> +	platform_set_drvdata(pdev, card);
> +	card->dev = &pdev->dev;
> +
> +	rk3036_dai.codec_of_node = of_parse_phandle(np,
> +			"rockchip,audio-codec", 0);
> +	if (!rk3036_dai.codec_of_node) {
> +		dev_err(&pdev->dev, "Property 'rockchip,audio-codec' 
> "
> +			"missing or invalid\n");
> +		return -EINVAL;
> +	}
> +
> +	rk3036_dai.cpu_of_node = of_parse_phandle(np,
> +			"rockchip,i2s-controller", 0);
> +	if (!rk3036_dai.cpu_of_node) {
> +		dev_err(&pdev->dev, "Property 'rockchip,i2s-
> controller' "
> +			"missing or invalid\n");
> +		return -EINVAL;
> +	}
> +
> +	rk3036_dai.platform_of_node = rk3036_dai.cpu_of_node;
> +
> +	return snd_soc_register_card(card);
> +}
> +
> +static int rockchip_rk3036_audio_remove(struct platform_device
> *pdev)
> +{
> +	struct snd_soc_card *card = platform_get_drvdata(pdev);
> +
> +	snd_soc_unregister_card(card);
> +
> +	return 0;
> +}
> +
> +static const struct of_device_id rockchip_rk3036_of_match[] = {
> +		{ .compatible = "rockchip,rk3036-audio", },
> +		{},
> +};
> +MODULE_DEVICE_TABLE(of, rockchip_rk3036_of_match);
> +
> +static struct platform_driver rockchip_rk3036_audio_driver = {
> +	.driver = {
> +		.name   = "rk3036-audio",
> +		.owner  = THIS_MODULE,
> +		.of_match_table =
> of_match_ptr(rockchip_rk3036_of_match),
> +	},
> +	.probe      = rockchip_rk3036_audio_probe,
> +	.remove     = rockchip_rk3036_audio_remove,
> +};
> +module_platform_driver(rockchip_rk3036_audio_driver);
> +
> +MODULE_AUTHOR("Rockchip Inc.");
> +MODULE_DESCRIPTION("Rockchip RK3036 Inno codec machine ASoC
> driver");
> +MODULE_LICENSE("GPL");

-- 
Sjoerd Simons
Collabora Ltd.

^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH v1 3/4] ASoC: Add codec machine driver for RK3036
@ 2015-10-19 12:12     ` Sjoerd Simons
  0 siblings, 0 replies; 28+ messages in thread
From: Sjoerd Simons @ 2015-10-19 12:12 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, 2015-10-13 at 09:01 +0800, Shunqian Zheng wrote:
> From: ZhengShunQian <zhengsq@rock-chips.com>
> 
> This patch add the machine driver for rk3036.

Does this need a machine driver? Can't the simple-card machine driver
be used for this ? (From the looks of it that would only mean the
clocking setup for the cpu dai would need to move into the i2s driver?)


> RK3036 SoC is integrated with Inno codec,
> this patch should work for all RK3036 board.
> 
> Signed-off-by: ZhengShunQian <zhengsq@rock-chips.com>
> ---
> ?sound/soc/rockchip/Kconfig???????????|??10 +++
> ?sound/soc/rockchip/Makefile??????????|???2 +
> ?sound/soc/rockchip/rockchip_rk3036.c | 147
> +++++++++++++++++++++++++++++++++++
> ?3 files changed, 159 insertions(+)
> ?create mode 100644 sound/soc/rockchip/rockchip_rk3036.c
> 
> diff --git a/sound/soc/rockchip/Kconfig b/sound/soc/rockchip/Kconfig
> index 5709057..3d48bda 100644
> --- a/sound/soc/rockchip/Kconfig
> +++ b/sound/soc/rockchip/Kconfig
> @@ -33,3 +33,13 @@ config SND_SOC_ROCKCHIP_RT5645
> ?	help
> ?	??Say Y or M here if you want to add support for SoC audio
> on Rockchip
> ?	??boards using the RT5645/RT5650 codec, such as Veyron.
> +
> +config SND_SOC_ROCKCHIP_RK3036
> +	tristate "ASoC support for RK3036 inner codec"
> +	depends on SND_SOC_ROCKCHIP
> +	select SND_SOC_ROCKCHIP_I2S
> +	help
> +	??Say Y or M here if you want to add support for SoC audio
> on Rockchip
> +	??RK3036.
> +
> +
> diff --git a/sound/soc/rockchip/Makefile
> b/sound/soc/rockchip/Makefile
> index e9ba558..9a770c8 100644
> --- a/sound/soc/rockchip/Makefile
> +++ b/sound/soc/rockchip/Makefile
> @@ -4,7 +4,9 @@ snd-soc-rockchip-i2s-objs := rockchip_i2s.o
> ?obj-$(CONFIG_SND_SOC_ROCKCHIP_I2S) += snd-soc-rockchip-i2s.o
> ?
> ?snd-soc-rockchip-max98090-objs := rockchip_max98090.o
> +snd-soc-rockchip-rk3036-objs := rockchip_rk3036.o
> ?snd-soc-rockchip-rt5645-objs := rockchip_rt5645.o
> ?
> ?obj-$(CONFIG_SND_SOC_ROCKCHIP_MAX98090) += snd-soc-rockchip-
> max98090.o
> +obj-$(CONFIG_SND_SOC_ROCKCHIP_RK3036) += snd-soc-rockchip-rk3036.o
> ?obj-$(CONFIG_SND_SOC_ROCKCHIP_RT5645) += snd-soc-rockchip-rt5645.o
> diff --git a/sound/soc/rockchip/rockchip_rk3036.c
> b/sound/soc/rockchip/rockchip_rk3036.c
> new file mode 100644
> index 0000000..3747d90
> --- /dev/null
> +++ b/sound/soc/rockchip/rockchip_rk3036.c
> @@ -0,0 +1,147 @@
> +/*
> + * Machine driver for rk3036 audio codec.
> + *
> + * Copyright (c) 2015, ROCKCHIP CORPORATION.??All rights reserved.
> + *
> + * Author: Zheng ShunQian<zhengsq@rock-chips.com>
> + */
> +
> +#include <linux/device.h>
> +#include <linux/of.h>
> +#include <linux/module.h>
> +
> +#include <sound/soc.h>
> +#include <sound/pcm.h>
> +#include <sound/soc-dapm.h>
> +
> +static int rk3036_hw_params(struct snd_pcm_substream *substream,
> +			????struct snd_pcm_hw_params *params)
> +{
> +	struct snd_soc_pcm_runtime *rtd = substream->private_data;
> +	struct snd_soc_dai *codec_dai = rtd->codec_dai;
> +	struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
> +	unsigned int dai_fmt = rtd->dai_link->dai_fmt;
> +	int mclk, ret;
> +
> +	dev_dbg(rtd->dev, "codec machine: %s\n", __func__);
> +	/* set codec DAI configuration */
> +	ret = snd_soc_dai_set_fmt(codec_dai, dai_fmt);
> +	if (ret < 0)
> +		return ret;
> +
> +	/* set cpu DAI configuration */
> +	ret = snd_soc_dai_set_fmt(cpu_dai, dai_fmt);
> +	if (ret < 0)
> +		return ret;
> +
> +	switch (params_rate(params)) {
> +	case 8000:
> +	case 16000:
> +	case 24000:
> +	case 32000:
> +	case 48000:
> +		mclk = 12288000;
> +		break;
> +	case 44100:
> +		mclk = 11289600;
> +		break;
> +	default:
> +		return -EINVAL;
> +	}
> +
> +	/*Set the system clk for codec*/
> +	ret = snd_soc_dai_set_sysclk(codec_dai, 0, mclk,
> SND_SOC_CLOCK_IN);
> +	if (ret < 0)
> +		return ret;
> +
> +	ret = snd_soc_dai_set_sysclk(cpu_dai, 0, mclk,
> SND_SOC_CLOCK_OUT);
> +	if (ret < 0)
> +		return ret;
> +
> +	return 0;
> +}
> +
> +static struct snd_soc_ops rk3036_ops = {
> +	??.hw_params = rk3036_hw_params,
> +};
> +
> +static int rk30_rk3036_codec_init(struct snd_soc_pcm_runtime *rtd)
> +{
> +	return 0;
> +}
> +
> +static struct snd_soc_dai_link rk3036_dai = {
> +	.name = "INNO-RK3036",
> +	.stream_name = "RK3036 CODEC PCM",
> +	.codec_dai_name = "rk3036-codec-dai",
> +	.init = rk30_rk3036_codec_init,
> +	.ops = &rk3036_ops,
> +	/* set codec as slave */
> +	.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
> +		???SND_SOC_DAIFMT_CBS_CFS,
> +};
> +
> +static struct snd_soc_card rockchip_rk3036_snd_card = {
> +	.name = "ROCKCHIP-I2S",
> +	.dai_link = &rk3036_dai,
> +	.num_links = 1,
> +};
> +
> +static int rockchip_rk3036_audio_probe(struct platform_device *pdev)
> +{
> +	struct snd_soc_card *card = &rockchip_rk3036_snd_card;
> +	struct device_node *np = pdev->dev.of_node;
> +
> +	platform_set_drvdata(pdev, card);
> +	card->dev = &pdev->dev;
> +
> +	rk3036_dai.codec_of_node = of_parse_phandle(np,
> +			"rockchip,audio-codec", 0);
> +	if (!rk3036_dai.codec_of_node) {
> +		dev_err(&pdev->dev, "Property 'rockchip,audio-codec' 
> "
> +			"missing or invalid\n");
> +		return -EINVAL;
> +	}
> +
> +	rk3036_dai.cpu_of_node = of_parse_phandle(np,
> +			"rockchip,i2s-controller", 0);
> +	if (!rk3036_dai.cpu_of_node) {
> +		dev_err(&pdev->dev, "Property 'rockchip,i2s-
> controller' "
> +			"missing or invalid\n");
> +		return -EINVAL;
> +	}
> +
> +	rk3036_dai.platform_of_node = rk3036_dai.cpu_of_node;
> +
> +	return snd_soc_register_card(card);
> +}
> +
> +static int rockchip_rk3036_audio_remove(struct platform_device
> *pdev)
> +{
> +	struct snd_soc_card *card = platform_get_drvdata(pdev);
> +
> +	snd_soc_unregister_card(card);
> +
> +	return 0;
> +}
> +
> +static const struct of_device_id rockchip_rk3036_of_match[] = {
> +		{ .compatible = "rockchip,rk3036-audio", },
> +		{},
> +};
> +MODULE_DEVICE_TABLE(of, rockchip_rk3036_of_match);
> +
> +static struct platform_driver rockchip_rk3036_audio_driver = {
> +	.driver = {
> +		.name???= "rk3036-audio",
> +		.owner??= THIS_MODULE,
> +		.of_match_table =
> of_match_ptr(rockchip_rk3036_of_match),
> +	},
> +	.probe??????= rockchip_rk3036_audio_probe,
> +	.remove?????= rockchip_rk3036_audio_remove,
> +};
> +module_platform_driver(rockchip_rk3036_audio_driver);
> +
> +MODULE_AUTHOR("Rockchip Inc.");
> +MODULE_DESCRIPTION("Rockchip RK3036 Inno codec machine ASoC
> driver");
> +MODULE_LICENSE("GPL");

-- 
Sjoerd Simons
Collabora Ltd.

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [alsa-devel] [PATCH v1 1/4] ASoC: codec: Inno codec driver for RK3036 SoC
  2015-10-19  6:56     ` Ricard Wanderlof
  (?)
@ 2015-10-19 18:54       ` Mark Brown
  -1 siblings, 0 replies; 28+ messages in thread
From: Mark Brown @ 2015-10-19 18:54 UTC (permalink / raw)
  To: Ricard Wanderlof
  Cc: Shunqian Zheng, robh+dt, pawel.moll, mark.rutland,
	ijc+devicetree, galak, heiko, lgirdwood, perex, tiwai, benzh,
	linux-rockchip, alsa-devel, linux-kernel, linux-arm-kernel

[-- Attachment #1: Type: text/plain, Size: 412 bytes --]

On Mon, Oct 19, 2015 at 08:56:51AM +0200, Ricard Wanderlof wrote:
> On Tue, 13 Oct 2015, Shunqian Zheng wrote:

> > +static const struct of_device_id rk3036_codec_of_match[] = {
> > +       { .compatible = "rk3036-codec", },
> > +       {}
> > +};
> > +MODULE_DEVICE_TABLE(of, rk3036_codec_of_match);

> Isn't a compatible string normally in the form "rockchip,rk3036-codec" ?

Yes, it needs vendor namespacing.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [alsa-devel] [PATCH v1 1/4] ASoC: codec: Inno codec driver for RK3036 SoC
@ 2015-10-19 18:54       ` Mark Brown
  0 siblings, 0 replies; 28+ messages in thread
From: Mark Brown @ 2015-10-19 18:54 UTC (permalink / raw)
  To: Ricard Wanderlof
  Cc: Shunqian Zheng, robh+dt, pawel.moll, mark.rutland,
	ijc+devicetree, galak, heiko, lgirdwood, perex, tiwai, benzh,
	linux-rockchip, alsa-devel, linux-kernel, linux-arm-kernel

[-- Attachment #1: Type: text/plain, Size: 412 bytes --]

On Mon, Oct 19, 2015 at 08:56:51AM +0200, Ricard Wanderlof wrote:
> On Tue, 13 Oct 2015, Shunqian Zheng wrote:

> > +static const struct of_device_id rk3036_codec_of_match[] = {
> > +       { .compatible = "rk3036-codec", },
> > +       {}
> > +};
> > +MODULE_DEVICE_TABLE(of, rk3036_codec_of_match);

> Isn't a compatible string normally in the form "rockchip,rk3036-codec" ?

Yes, it needs vendor namespacing.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply	[flat|nested] 28+ messages in thread

* [alsa-devel] [PATCH v1 1/4] ASoC: codec: Inno codec driver for RK3036 SoC
@ 2015-10-19 18:54       ` Mark Brown
  0 siblings, 0 replies; 28+ messages in thread
From: Mark Brown @ 2015-10-19 18:54 UTC (permalink / raw)
  To: linux-arm-kernel

On Mon, Oct 19, 2015 at 08:56:51AM +0200, Ricard Wanderlof wrote:
> On Tue, 13 Oct 2015, Shunqian Zheng wrote:

> > +static const struct of_device_id rk3036_codec_of_match[] = {
> > +       { .compatible = "rk3036-codec", },
> > +       {}
> > +};
> > +MODULE_DEVICE_TABLE(of, rk3036_codec_of_match);

> Isn't a compatible string normally in the form "rockchip,rk3036-codec" ?

Yes, it needs vendor namespacing.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20151019/950c4444/attachment.sig>

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH v1 1/4] ASoC: codec: Inno codec driver for RK3036 SoC
  2015-10-13  1:01   ` Shunqian Zheng
@ 2015-10-19 19:09     ` Mark Brown
  -1 siblings, 0 replies; 28+ messages in thread
From: Mark Brown @ 2015-10-19 19:09 UTC (permalink / raw)
  To: Shunqian Zheng
  Cc: robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak, heiko,
	lgirdwood, perex, tiwai, benzh, linux-arm-kernel, linux-kernel,
	linux-rockchip, alsa-devel

[-- Attachment #1: Type: text/plain, Size: 3003 bytes --]

On Tue, Oct 13, 2015 at 09:01:06AM +0800, Shunqian Zheng wrote:

> +config SND_SOC_INNO_RK3036
> +	tristate "Inno codec driver for RK3036 SoC"
> +	depends on ARCH_ROCKCHIP
> +

There doesn't appear to be any build dependency here so can we have an
|| COMPILE_TEST please and also add to SND_SOC_ALL_CODECS.

> +#define DEBUG

Please remove this for upstream.

> +static int rk3036_codec_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id,
> +				       unsigned int fre, int dir)
> +{
> +	/* Nothing to be done here */
> +	return 0;
> +}

Remove empty functions, if they can be empty they can just be omitted.

> +static int rk3036_codec_dai_digital_mute(struct snd_soc_dai *dai, int mute)
> +{
> +	struct snd_soc_codec *codec = dai->codec;
> +	unsigned int val = 0;
> +
> +	dev_dbg(codec->dev, "rk3036_codec dai mute : %d\n", mute);
> +	if (mute)
> +		val |= INNO_REG_09_HP_OUTR_MUTE_YES |
> +		       INNO_REG_09_HP_OUTL_MUTE_YES;
> +	else
> +		val |= INNO_REG_09_HP_OUTR_MUTE_NO |
> +		       INNO_REG_09_HP_OUTL_MUTE_NO;

Does the device actually need muting to avoid audio issues?  If not it
looks like this is something that might be better made a user visible
control instead.

> +static void rk3036_codec_power_off(struct snd_soc_codec *codec)
> +{
> +	struct inno_reg_val *reg_val;
> +	int i;

> +static void rk3036_codec_power_on(struct snd_soc_codec *codec)
> +{
> +	struct inno_reg_val *reg_val;
> +	int i;

I'd expect to see these be part of the set_bias_level() operation.

> +	dev_dbg(codec->dev, "rk3036_codec power on\n");
> +	/* set a big current for capacitor discharging. */
> +	snd_soc_write(codec, INNO_REG_10, INNO_REG_10_MAX_CUR);
> +	mdelay(10);
> +	/* start precharge */
> +	snd_soc_write(codec, INNO_REG_06, INNO_REG_06_DAC_PRECHARGE);
> +	mdelay(100);
> +
> +	for (i = 0; i < ARRAY_SIZE(inno_codec_open_path); i++) {
> +		reg_val = &inno_codec_open_path[i];
> +		snd_soc_write(codec, reg_val->reg, reg_val->val);
> +		mdelay(5);
> +	}

This looks suspicious...  why isn't the power up sequence managed via
DAPM?

> +static struct regmap *rk3036_codec_get_regmap(struct device *dev)
> +{
> +	struct rk3036_codec_priv *priv = dev_get_drvdata(dev);
> +
> +	dev_dbg(dev, "rk3036_codec get regmap\n");
> +	return priv->regmap;
> +}

There's already dev_get_regmap().

> +static int codec_reg_read(void *context, unsigned int reg, unsigned int *val)
> +{
> +	struct rk3036_codec_priv *priv = context;
> +	void __iomem *base = priv->base;
> +
> +	*val = readl(base + reg);
> +	return 0;
> +}

> +static struct regmap_bus codec_regmap_bus = {
> +	.reg_read = codec_reg_read,
> +	.reg_write = codec_reg_write,

This looks like it's just regmap_mmio, why not just use that?

> +	ret = regmap_write(grf, 0x00140, BIT(16 + 10) | BIT(10));
> +	if (ret != 0) {

Can we have some defines for this rather than all the magic numbers?

> +static void rk3036_codec_platform_shutdown(struct platform_device *pdev)
> +{
> +	/*TODO:*/
> +}

If you use DAPM you shouldn't need to do anything here.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH v1 1/4] ASoC: codec: Inno codec driver for RK3036 SoC
@ 2015-10-19 19:09     ` Mark Brown
  0 siblings, 0 replies; 28+ messages in thread
From: Mark Brown @ 2015-10-19 19:09 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, Oct 13, 2015 at 09:01:06AM +0800, Shunqian Zheng wrote:

> +config SND_SOC_INNO_RK3036
> +	tristate "Inno codec driver for RK3036 SoC"
> +	depends on ARCH_ROCKCHIP
> +

There doesn't appear to be any build dependency here so can we have an
|| COMPILE_TEST please and also add to SND_SOC_ALL_CODECS.

> +#define DEBUG

Please remove this for upstream.

> +static int rk3036_codec_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id,
> +				       unsigned int fre, int dir)
> +{
> +	/* Nothing to be done here */
> +	return 0;
> +}

Remove empty functions, if they can be empty they can just be omitted.

> +static int rk3036_codec_dai_digital_mute(struct snd_soc_dai *dai, int mute)
> +{
> +	struct snd_soc_codec *codec = dai->codec;
> +	unsigned int val = 0;
> +
> +	dev_dbg(codec->dev, "rk3036_codec dai mute : %d\n", mute);
> +	if (mute)
> +		val |= INNO_REG_09_HP_OUTR_MUTE_YES |
> +		       INNO_REG_09_HP_OUTL_MUTE_YES;
> +	else
> +		val |= INNO_REG_09_HP_OUTR_MUTE_NO |
> +		       INNO_REG_09_HP_OUTL_MUTE_NO;

Does the device actually need muting to avoid audio issues?  If not it
looks like this is something that might be better made a user visible
control instead.

> +static void rk3036_codec_power_off(struct snd_soc_codec *codec)
> +{
> +	struct inno_reg_val *reg_val;
> +	int i;

> +static void rk3036_codec_power_on(struct snd_soc_codec *codec)
> +{
> +	struct inno_reg_val *reg_val;
> +	int i;

I'd expect to see these be part of the set_bias_level() operation.

> +	dev_dbg(codec->dev, "rk3036_codec power on\n");
> +	/* set a big current for capacitor discharging. */
> +	snd_soc_write(codec, INNO_REG_10, INNO_REG_10_MAX_CUR);
> +	mdelay(10);
> +	/* start precharge */
> +	snd_soc_write(codec, INNO_REG_06, INNO_REG_06_DAC_PRECHARGE);
> +	mdelay(100);
> +
> +	for (i = 0; i < ARRAY_SIZE(inno_codec_open_path); i++) {
> +		reg_val = &inno_codec_open_path[i];
> +		snd_soc_write(codec, reg_val->reg, reg_val->val);
> +		mdelay(5);
> +	}

This looks suspicious...  why isn't the power up sequence managed via
DAPM?

> +static struct regmap *rk3036_codec_get_regmap(struct device *dev)
> +{
> +	struct rk3036_codec_priv *priv = dev_get_drvdata(dev);
> +
> +	dev_dbg(dev, "rk3036_codec get regmap\n");
> +	return priv->regmap;
> +}

There's already dev_get_regmap().

> +static int codec_reg_read(void *context, unsigned int reg, unsigned int *val)
> +{
> +	struct rk3036_codec_priv *priv = context;
> +	void __iomem *base = priv->base;
> +
> +	*val = readl(base + reg);
> +	return 0;
> +}

> +static struct regmap_bus codec_regmap_bus = {
> +	.reg_read = codec_reg_read,
> +	.reg_write = codec_reg_write,

This looks like it's just regmap_mmio, why not just use that?

> +	ret = regmap_write(grf, 0x00140, BIT(16 + 10) | BIT(10));
> +	if (ret != 0) {

Can we have some defines for this rather than all the magic numbers?

> +static void rk3036_codec_platform_shutdown(struct platform_device *pdev)
> +{
> +	/*TODO:*/
> +}

If you use DAPM you shouldn't need to do anything here.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20151019/e5b6a9c2/attachment.sig>

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH v1 3/4] ASoC: Add codec machine driver for RK3036
  2015-10-13  1:01   ` Shunqian Zheng
@ 2015-10-19 19:13     ` Mark Brown
  -1 siblings, 0 replies; 28+ messages in thread
From: Mark Brown @ 2015-10-19 19:13 UTC (permalink / raw)
  To: Shunqian Zheng
  Cc: robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak, heiko,
	lgirdwood, perex, tiwai, benzh, linux-arm-kernel, linux-kernel,
	linux-rockchip, alsa-devel

[-- Attachment #1: Type: text/plain, Size: 473 bytes --]

On Tue, Oct 13, 2015 at 09:01:08AM +0800, Shunqian Zheng wrote:
> From: ZhengShunQian <zhengsq@rock-chips.com>
> 
> This patch add the machine driver for rk3036.

Like Sjoerd said this looks like it migh be better just using
simple-card, if not...

> +	ret = snd_soc_dai_set_fmt(codec_dai, dai_fmt);
> +	if (ret < 0)
> +		return ret;
> +
> +	/* set cpu DAI configuration */
> +	ret = snd_soc_dai_set_fmt(cpu_dai, dai_fmt);

Set this in the dai_link struct.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH v1 3/4] ASoC: Add codec machine driver for RK3036
@ 2015-10-19 19:13     ` Mark Brown
  0 siblings, 0 replies; 28+ messages in thread
From: Mark Brown @ 2015-10-19 19:13 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, Oct 13, 2015 at 09:01:08AM +0800, Shunqian Zheng wrote:
> From: ZhengShunQian <zhengsq@rock-chips.com>
> 
> This patch add the machine driver for rk3036.

Like Sjoerd said this looks like it migh be better just using
simple-card, if not...

> +	ret = snd_soc_dai_set_fmt(codec_dai, dai_fmt);
> +	if (ret < 0)
> +		return ret;
> +
> +	/* set cpu DAI configuration */
> +	ret = snd_soc_dai_set_fmt(cpu_dai, dai_fmt);

Set this in the dai_link struct.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20151019/1c449c1f/attachment.sig>

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH v1 3/4] ASoC: Add codec machine driver for RK3036
  2015-10-19 19:13     ` Mark Brown
  (?)
@ 2015-10-24  3:18       ` Shunqian Zheng
  -1 siblings, 0 replies; 28+ messages in thread
From: Shunqian Zheng @ 2015-10-24  3:18 UTC (permalink / raw)
  To: Mark Brown
  Cc: robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak, heiko,
	lgirdwood, perex, tiwai, benzh, linux-arm-kernel, linux-kernel,
	linux-rockchip, alsa-devel

Mark & Sjoerd,

On 2015年10月20日 03:13, Mark Brown wrote:
> On Tue, Oct 13, 2015 at 09:01:08AM +0800, Shunqian Zheng wrote:
>> From: ZhengShunQian <zhengsq@rock-chips.com>
>>
>> This patch add the machine driver for rk3036.
> Like Sjoerd said this looks like it migh be better just using
> simple-card, if not...
Yes, simple-card works fine, I think I need to learn more and resend 
patches.

Thank you very much,
Shunqian
>
>> +	ret = snd_soc_dai_set_fmt(codec_dai, dai_fmt);
>> +	if (ret < 0)
>> +		return ret;
>> +
>> +	/* set cpu DAI configuration */
>> +	ret = snd_soc_dai_set_fmt(cpu_dai, dai_fmt);
> Set this in the dai_link struct.



^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH v1 3/4] ASoC: Add codec machine driver for RK3036
@ 2015-10-24  3:18       ` Shunqian Zheng
  0 siblings, 0 replies; 28+ messages in thread
From: Shunqian Zheng @ 2015-10-24  3:18 UTC (permalink / raw)
  To: Mark Brown
  Cc: mark.rutland, alsa-devel, heiko, pawel.moll, ijc+devicetree,
	linux-kernel, tiwai, lgirdwood, benzh, robh+dt, galak,
	linux-rockchip, linux-arm-kernel

Mark & Sjoerd,

On 2015年10月20日 03:13, Mark Brown wrote:
> On Tue, Oct 13, 2015 at 09:01:08AM +0800, Shunqian Zheng wrote:
>> From: ZhengShunQian <zhengsq@rock-chips.com>
>>
>> This patch add the machine driver for rk3036.
> Like Sjoerd said this looks like it migh be better just using
> simple-card, if not...
Yes, simple-card works fine, I think I need to learn more and resend 
patches.

Thank you very much,
Shunqian
>
>> +	ret = snd_soc_dai_set_fmt(codec_dai, dai_fmt);
>> +	if (ret < 0)
>> +		return ret;
>> +
>> +	/* set cpu DAI configuration */
>> +	ret = snd_soc_dai_set_fmt(cpu_dai, dai_fmt);
> Set this in the dai_link struct.


_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH v1 3/4] ASoC: Add codec machine driver for RK3036
@ 2015-10-24  3:18       ` Shunqian Zheng
  0 siblings, 0 replies; 28+ messages in thread
From: Shunqian Zheng @ 2015-10-24  3:18 UTC (permalink / raw)
  To: linux-arm-kernel

Mark & Sjoerd,

On 2015?10?20? 03:13, Mark Brown wrote:
> On Tue, Oct 13, 2015 at 09:01:08AM +0800, Shunqian Zheng wrote:
>> From: ZhengShunQian <zhengsq@rock-chips.com>
>>
>> This patch add the machine driver for rk3036.
> Like Sjoerd said this looks like it migh be better just using
> simple-card, if not...
Yes, simple-card works fine, I think I need to learn more and resend 
patches.

Thank you very much,
Shunqian
>
>> +	ret = snd_soc_dai_set_fmt(codec_dai, dai_fmt);
>> +	if (ret < 0)
>> +		return ret;
>> +
>> +	/* set cpu DAI configuration */
>> +	ret = snd_soc_dai_set_fmt(cpu_dai, dai_fmt);
> Set this in the dai_link struct.

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH v1 1/4] ASoC: codec: Inno codec driver for RK3036 SoC
  2015-10-19 19:09     ` Mark Brown
@ 2015-11-05  9:52       ` Shunqian Zheng
  -1 siblings, 0 replies; 28+ messages in thread
From: Shunqian Zheng @ 2015-11-05  9:52 UTC (permalink / raw)
  To: Mark Brown
  Cc: robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak, heiko,
	lgirdwood, perex, tiwai, benzh, linux-arm-kernel, linux-kernel,
	linux-rockchip, alsa-devel

Mark,
I sended the v2 patches and fixed the follows,

On 2015年10月20日 03:09, Mark Brown wrote:
> On Tue, Oct 13, 2015 at 09:01:06AM +0800, Shunqian Zheng wrote:
>
>> +config SND_SOC_INNO_RK3036
>> +	tristate "Inno codec driver for RK3036 SoC"
>> +	depends on ARCH_ROCKCHIP
>> +
> There doesn't appear to be any build dependency here so can we have an
> || COMPILE_TEST please and also add to SND_SOC_ALL_CODECS.
Delete the dependency and add to SND_SOC_ALL_CODECS.
>
>> +#define DEBUG
> Please remove this for upstream.
Removed.
>
>> +static int rk3036_codec_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id,
>> +				       unsigned int fre, int dir)
>> +{
>> +	/* Nothing to be done here */
>> +	return 0;
>> +}
> Remove empty functions, if they can be empty they can just be omitted.
Removed.
>
>> +static int rk3036_codec_dai_digital_mute(struct snd_soc_dai *dai, int mute)
>> +{
>> +	struct snd_soc_codec *codec = dai->codec;
>> +	unsigned int val = 0;
>> +
>> +	dev_dbg(codec->dev, "rk3036_codec dai mute : %d\n", mute);
>> +	if (mute)
>> +		val |= INNO_REG_09_HP_OUTR_MUTE_YES |
>> +		       INNO_REG_09_HP_OUTL_MUTE_YES;
>> +	else
>> +		val |= INNO_REG_09_HP_OUTR_MUTE_NO |
>> +		       INNO_REG_09_HP_OUTL_MUTE_NO;
> Does the device actually need muting to avoid audio issues?  If not it
> looks like this is something that might be better made a user visible
> control instead.
Make mute as a control.
>
>> +static void rk3036_codec_power_off(struct snd_soc_codec *codec)
>> +{
>> +	struct inno_reg_val *reg_val;
>> +	int i;
>> +static void rk3036_codec_power_on(struct snd_soc_codec *codec)
>> +{
>> +	struct inno_reg_val *reg_val;
>> +	int i;
> I'd expect to see these be part of the set_bias_level() operation.
Move the part of setting precharge current  to set_bias_level()
>
>> +	dev_dbg(codec->dev, "rk3036_codec power on\n");
>> +	/* set a big current for capacitor discharging. */
>> +	snd_soc_write(codec, INNO_REG_10, INNO_REG_10_MAX_CUR);
>> +	mdelay(10);
>> +	/* start precharge */
>> +	snd_soc_write(codec, INNO_REG_06, INNO_REG_06_DAC_PRECHARGE);
>> +	mdelay(100);
>> +
>> +	for (i = 0; i < ARRAY_SIZE(inno_codec_open_path); i++) {
>> +		reg_val = &inno_codec_open_path[i];
>> +		snd_soc_write(codec, reg_val->reg, reg_val->val);
>> +		mdelay(5);
>> +	}
> This looks suspicious...  why isn't the power up sequence managed via
> DAPM?
Use DAPM to manage the power up path.
>
>> +static struct regmap *rk3036_codec_get_regmap(struct device *dev)
>> +{
>> +	struct rk3036_codec_priv *priv = dev_get_drvdata(dev);
>> +
>> +	dev_dbg(dev, "rk3036_codec get regmap\n");
>> +	return priv->regmap;
>> +}
> There's already dev_get_regmap().
Delete this functions.
>
>> +static int codec_reg_read(void *context, unsigned int reg, unsigned int *val)
>> +{
>> +	struct rk3036_codec_priv *priv = context;
>> +	void __iomem *base = priv->base;
>> +
>> +	*val = readl(base + reg);
>> +	return 0;
>> +}
>> +static struct regmap_bus codec_regmap_bus = {
>> +	.reg_read = codec_reg_read,
>> +	.reg_write = codec_reg_write,
> This looks like it's just regmap_mmio, why not just use that?
Use the devm_regmap_init_mmio().
>
>> +	ret = regmap_write(grf, 0x00140, BIT(16 + 10) | BIT(10));
>> +	if (ret != 0) {
> Can we have some defines for this rather than all the magic numbers?
Define some macros for grf select.
>
>> +static void rk3036_codec_platform_shutdown(struct platform_device *pdev)
>> +{
>> +	/*TODO:*/
>> +}
> If you use DAPM you shouldn't need to do anything here.
Delete it.

Thank you very much,
Shunqian



^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH v1 1/4] ASoC: codec: Inno codec driver for RK3036 SoC
@ 2015-11-05  9:52       ` Shunqian Zheng
  0 siblings, 0 replies; 28+ messages in thread
From: Shunqian Zheng @ 2015-11-05  9:52 UTC (permalink / raw)
  To: linux-arm-kernel

Mark,
I sended the v2 patches and fixed the follows,

On 2015?10?20? 03:09, Mark Brown wrote:
> On Tue, Oct 13, 2015 at 09:01:06AM +0800, Shunqian Zheng wrote:
>
>> +config SND_SOC_INNO_RK3036
>> +	tristate "Inno codec driver for RK3036 SoC"
>> +	depends on ARCH_ROCKCHIP
>> +
> There doesn't appear to be any build dependency here so can we have an
> || COMPILE_TEST please and also add to SND_SOC_ALL_CODECS.
Delete the dependency and add to SND_SOC_ALL_CODECS.
>
>> +#define DEBUG
> Please remove this for upstream.
Removed.
>
>> +static int rk3036_codec_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id,
>> +				       unsigned int fre, int dir)
>> +{
>> +	/* Nothing to be done here */
>> +	return 0;
>> +}
> Remove empty functions, if they can be empty they can just be omitted.
Removed.
>
>> +static int rk3036_codec_dai_digital_mute(struct snd_soc_dai *dai, int mute)
>> +{
>> +	struct snd_soc_codec *codec = dai->codec;
>> +	unsigned int val = 0;
>> +
>> +	dev_dbg(codec->dev, "rk3036_codec dai mute : %d\n", mute);
>> +	if (mute)
>> +		val |= INNO_REG_09_HP_OUTR_MUTE_YES |
>> +		       INNO_REG_09_HP_OUTL_MUTE_YES;
>> +	else
>> +		val |= INNO_REG_09_HP_OUTR_MUTE_NO |
>> +		       INNO_REG_09_HP_OUTL_MUTE_NO;
> Does the device actually need muting to avoid audio issues?  If not it
> looks like this is something that might be better made a user visible
> control instead.
Make mute as a control.
>
>> +static void rk3036_codec_power_off(struct snd_soc_codec *codec)
>> +{
>> +	struct inno_reg_val *reg_val;
>> +	int i;
>> +static void rk3036_codec_power_on(struct snd_soc_codec *codec)
>> +{
>> +	struct inno_reg_val *reg_val;
>> +	int i;
> I'd expect to see these be part of the set_bias_level() operation.
Move the part of setting precharge current  to set_bias_level()
>
>> +	dev_dbg(codec->dev, "rk3036_codec power on\n");
>> +	/* set a big current for capacitor discharging. */
>> +	snd_soc_write(codec, INNO_REG_10, INNO_REG_10_MAX_CUR);
>> +	mdelay(10);
>> +	/* start precharge */
>> +	snd_soc_write(codec, INNO_REG_06, INNO_REG_06_DAC_PRECHARGE);
>> +	mdelay(100);
>> +
>> +	for (i = 0; i < ARRAY_SIZE(inno_codec_open_path); i++) {
>> +		reg_val = &inno_codec_open_path[i];
>> +		snd_soc_write(codec, reg_val->reg, reg_val->val);
>> +		mdelay(5);
>> +	}
> This looks suspicious...  why isn't the power up sequence managed via
> DAPM?
Use DAPM to manage the power up path.
>
>> +static struct regmap *rk3036_codec_get_regmap(struct device *dev)
>> +{
>> +	struct rk3036_codec_priv *priv = dev_get_drvdata(dev);
>> +
>> +	dev_dbg(dev, "rk3036_codec get regmap\n");
>> +	return priv->regmap;
>> +}
> There's already dev_get_regmap().
Delete this functions.
>
>> +static int codec_reg_read(void *context, unsigned int reg, unsigned int *val)
>> +{
>> +	struct rk3036_codec_priv *priv = context;
>> +	void __iomem *base = priv->base;
>> +
>> +	*val = readl(base + reg);
>> +	return 0;
>> +}
>> +static struct regmap_bus codec_regmap_bus = {
>> +	.reg_read = codec_reg_read,
>> +	.reg_write = codec_reg_write,
> This looks like it's just regmap_mmio, why not just use that?
Use the devm_regmap_init_mmio().
>
>> +	ret = regmap_write(grf, 0x00140, BIT(16 + 10) | BIT(10));
>> +	if (ret != 0) {
> Can we have some defines for this rather than all the magic numbers?
Define some macros for grf select.
>
>> +static void rk3036_codec_platform_shutdown(struct platform_device *pdev)
>> +{
>> +	/*TODO:*/
>> +}
> If you use DAPM you shouldn't need to do anything here.
Delete it.

Thank you very much,
Shunqian

^ permalink raw reply	[flat|nested] 28+ messages in thread

end of thread, other threads:[~2015-11-05  9:52 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-13  1:01 [PATCH v1 0/4] Audio Codec Driver of RK3036 SoC Shunqian Zheng
2015-10-13  1:01 ` Shunqian Zheng
2015-10-13  1:01 ` [PATCH v1 1/4] ASoC: codec: Inno codec driver for " Shunqian Zheng
2015-10-13  1:01   ` Shunqian Zheng
2015-10-19  6:56   ` [alsa-devel] " Ricard Wanderlof
2015-10-19  6:56     ` Ricard Wanderlof
2015-10-19  6:56     ` Ricard Wanderlof
2015-10-19 18:54     ` Mark Brown
2015-10-19 18:54       ` Mark Brown
2015-10-19 18:54       ` Mark Brown
2015-10-19 19:09   ` Mark Brown
2015-10-19 19:09     ` Mark Brown
2015-11-05  9:52     ` Shunqian Zheng
2015-11-05  9:52       ` Shunqian Zheng
2015-10-13  1:01 ` [PATCH v1 2/4] ASoC: RK3036: Add binding doc of inno-rk3036 codec driver Shunqian Zheng
2015-10-13  1:01   ` Shunqian Zheng
2015-10-13  1:01 ` [PATCH v1 3/4] ASoC: Add codec machine driver for RK3036 Shunqian Zheng
2015-10-13  1:01   ` Shunqian Zheng
2015-10-13  1:01   ` Shunqian Zheng
2015-10-19 12:12   ` Sjoerd Simons
2015-10-19 12:12     ` Sjoerd Simons
2015-10-19 19:13   ` Mark Brown
2015-10-19 19:13     ` Mark Brown
2015-10-24  3:18     ` Shunqian Zheng
2015-10-24  3:18       ` Shunqian Zheng
2015-10-24  3:18       ` Shunqian Zheng
2015-10-13  1:01 ` [PATCH v1 4/4] ASoC: RK3036: Add binding doc for audio machine driver Shunqian Zheng
2015-10-13  1:01   ` Shunqian Zheng

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.