Skip to contentSkip to conversation

ASoC: rt5514: add rt5514 SPI driver

PATCH Superseded Oder Chiou 2 participants 8 messages Mar 14, 2016 – Apr 6, 2016

Subsystems (3)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Oder Chiou

author maintainer
#0 lore raw

PATCH v2 1/1 ASoC: rt5514: add rt5514 SPI driver

The device has multiple control interfaces, I2C and SPI. The I2C interface mainly controls the register settings of codec. The SPI interface is in order to provide the high speed transmission of data. For example, high bandwidth memory read/write of DSP. The patch adds the rt5514 SPI driver for loading the firmware of DSP and retrieving the voice data from DSP after the system is waked up by specific voice.

---
 sound/soc/codecs/Kconfig      |   3 +
 sound/soc/codecs/Makefile     |   2 +
 sound/soc/codecs/rt5514-spi.c | 458 ++++++++++++++++++++++++++++++++++++++++++
 sound/soc/codecs/rt5514-spi.h |  38 ++++
 sound/soc/codecs/rt5514.c     | 249 +++++++++++++++++++++++
 sound/soc/codecs/rt5514.h     |   4 +
 6 files changed, 754 insertions(+)
 create mode 100644 sound/soc/codecs/rt5514-spi.c
 create mode 100644 sound/soc/codecs/rt5514-spi.h
sound/soc/codecs/Kconfig +3 -0
index 2f99b11..306c4e3 100644
@@ -627,6 +627,9 @@ config SND_SOC_RT298
 config SND_SOC_RT5514
 	tristate
 
+config SND_SOC_RT5514_SPI
+	tristate
+
 config SND_SOC_RT5616
 	tristate
 
sound/soc/codecs/Makefile +2 -0
index 185a712..501bf43 100644
@@ -97,6 +97,7 @@ snd-soc-rl6347a-objs := rl6347a.o
 snd-soc-rt286-objs := rt286.o
 snd-soc-rt298-objs := rt298.o
 snd-soc-rt5514-objs := rt5514.o
+snd-soc-rt5514-spi-objs := rt5514-spi.o
 snd-soc-rt5616-objs := rt5616.o
 snd-soc-rt5631-objs := rt5631.o
 snd-soc-rt5640-objs := rt5640.o
@@ -306,6 +307,7 @@ obj-$(CONFIG_SND_SOC_RL6347A)	+= snd-soc-rl6347a.o
 obj-$(CONFIG_SND_SOC_RT286)	+= snd-soc-rt286.o
 obj-$(CONFIG_SND_SOC_RT298)	+= snd-soc-rt298.o
 obj-$(CONFIG_SND_SOC_RT5514)	+= snd-soc-rt5514.o
+obj-$(CONFIG_SND_SOC_RT5514_SPI)	+= snd-soc-rt5514-spi.o
 obj-$(CONFIG_SND_SOC_RT5616)	+= snd-soc-rt5616.o
 obj-$(CONFIG_SND_SOC_RT5631)	+= snd-soc-rt5631.o
 obj-$(CONFIG_SND_SOC_RT5640)	+= snd-soc-rt5640.o
sound/soc/codecs/rt5514-spi.c new file +458 -0

458 lines not on this page · raw message

sound/soc/codecs/rt5514-spi.h new file +38 -0
new file mode 100644
index 0000000..f69b1cd
@@ -0,0 +1,38 @@
+/*
+ * rt5514-spi.h  --  RT5514 driver
+ *
+ * Copyright 2015 Realtek Semiconductor Corp.
+ * Author: Oder Chiou <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef __RT5514_SPI_H__
+#define __RT5514_SPI_H__
+
+/**
+ * RT5514_SPI_BUF_LEN is the buffer size of SPI master controller.
+*/
+#define RT5514_SPI_BUF_LEN		240
+
+#define RT5514_BUFFER_VOICE_BASE	0x18001034
+#define RT5514_BUFFER_VOICE_LIMIT	0x18001038
+#define RT5514_BUFFER_VOICE_RP		0x1800103c
+#define RT5514_BUFFER_VOICE_SIZE	0x18001040
+
+/* SPI Command */
+enum {
+	RT5514_SPI_CMD_16_READ = 0,
+	RT5514_SPI_CMD_16_WRITE,
+	RT5514_SPI_CMD_32_READ,
+	RT5514_SPI_CMD_32_WRITE,
+	RT5514_SPI_CMD_BURST_READ,
+	RT5514_SPI_CMD_BURST_WRITE,
+};
+
+int rt5514_spi_burst_read(unsigned int addr, u8 *rxbuf, size_t len);
+int rt5514_spi_burst_write(u32 addr, const u8 *txbuf, size_t len);
+
+#endif /* __RT5514_SPI_H__ */
sound/soc/codecs/rt5514.c +249 -0

285 lines not on this page · raw message

sound/soc/codecs/rt5514.h +4 -0
index 6ad8a61..6e89e7d 100644
@@ -225,6 +225,9 @@
 #define RT5514_PLL_INP_MAX			40000000
 #define RT5514_PLL_INP_MIN			256000
 
+#define RT5514_FIRMWARE1	"rt5514_dsp_fw1.bin"
+#define RT5514_FIRMWARE2	"rt5514_dsp_fw2.bin"
+
 /* System Clock Source */
 enum {
 	RT5514_SCLK_S_MCLK,
@@ -247,6 +250,7 @@ struct rt5514_priv {
 	int pll_src;
 	int pll_in;
 	int pll_out;
+	int dsp_enabled;
 };
 
 #endif /* __RT5514_H__ */
Signature · 1 line
1.8.1.1.439.g50a6b54
maintainer
#1 lore raw

On Mon, Mar 14, 2016 at 06:58:21PM +0800, Oder Chiou wrote:

This looks mostly good, a few relatively small things here that should be simple to fix:

sound/soc/codecs/rt5514-spi.c line 86

Quoted 8 lines
sound/soc/codecs/rt5514-spi.c new file +8 -0
+static void rt5514_spi_copy_work(struct work_struct *work)
+{
+	struct rt5514_dsp *rt5514_dsp =
+		container_of(work, struct rt5514_dsp, copy_work.work);
+	struct snd_pcm_runtime *runtime = rt5514_dsp->substream->runtime;
+	size_t period_bytes, truncated_bytes = 0;
+
+	mutex_lock(&rt5514_dsp->dma_lock);

_copy_work() holds dma_lock for the entire time it runs...

sound/soc/codecs/rt5514-spi.c line 168

Quoted 10 lines
sound/soc/codecs/rt5514-spi.c new file +10 -0
+static int rt5514_spi_hw_free(struct snd_pcm_substream *substream)
+{
+	struct snd_soc_pcm_runtime *rtd = substream->private_data;
+	struct rt5514_dsp *rt5514_dsp =
+			snd_soc_platform_get_drvdata(rtd->platform);
+
+	mutex_lock(&rt5514_dsp->dma_lock);
+	cancel_delayed_work_sync(&rt5514_dsp->copy_work);
+	rt5514_dsp->substream = NULL;
+	mutex_unlock(&rt5514_dsp->dma_lock);

...but _hw_free() tries to cancel the work while holding dma_lock. This means we've got a deadlock, if the work starts running after the mutex is acquired in _hw_free() then it will block trying to get the mutex which will never get released because we're waiting for the work to complete.

Looks like the cancel needs to be after the unlock.

sound/soc/codecs/rt5514-spi.c line 449

Quoted 4 lines
sound/soc/codecs/rt5514-spi.c new file +4 -0
+static struct spi_driver rt5514_spi_driver = {
+	.driver = {
+			.name = "rt5514",
+			.of_match_table = of_match_ptr(rt5514_of_match),

Weird indentation here.

sound/soc/codecs/rt5514.c static const struct reg_default rt5514_reg[] = { · line 119

Quoted 4 lines
sound/soc/codecs/rt5514.c +4 -0
+static void rt5514_enable_dsp_prepare(struct rt5514_priv *rt5514)
+{
+	/* Reset */
+	regmap_write(rt5514->i2c_regmap, 0x18002000, 0x000010ec);

This is a *very* big table of magic numbers with what look like system specific settings in there (there seem to be some things routing to and from the ADC, and some clocking setup...). Are you sure none of this depends on the runtime configuration?

sound/soc/codecs/rt5514.c static const DECLARE_TLV_DB_RANGE(bst_tlv, · line 439

Quoted 9 lines
sound/soc/codecs/rt5514.c +9 -0
+	if (rt5514->dsp_enabled) {
+		rt5514_enable_dsp_prepare(rt5514);
+
+		request_firmware(&fw, RT5514_FIRMWARE1, codec->dev);
+		if (fw) {
+#if defined(CONFIG_SND_SOC_RT5514_SPI)
+			rt5514_spi_burst_write(0x4ff60000, fw->data,
+				((fw->size/8)+1)*8);
+#endif

This will silently report success if SPI support is disabled, I'd expect either the control would be entirely absent or we'd report an error.

Quoted 5 lines
sound/soc/codecs/rt5514.c +5 -0
+		if (snd_soc_codec_get_bias_level(codec) ==
+			SND_SOC_BIAS_STANDBY) {
+			/**
+			 * If the DSP is enabled in start of recording, the
+			 * DSP should be disabled, and sync back to normal

sound/soc/codecs/rt5514.c static int rt5514_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask, · line 1039

Quoted 10 lines
sound/soc/codecs/rt5514.c +10 -0
+			 * recording settings to make sure recording
+			 * properly.
+			*/
+			if (rt5514->dsp_enabled) {
+				rt5514->dsp_enabled = 0;
+				regcache_mark_dirty(rt5514->i2c_regmap);
+				regcache_mark_dirty(rt5514->regmap);
+				regcache_sync(rt5514->i2c_regmap);
+				regcache_sync(rt5514->regmap);
+			}

This talks specifically about recording but this is in set_bias_level(). I'd expect something to do with the start/stop of recording to be attached to something like a DAPM event for an ADC or DAI widget.

author maintainer
#2 lore raw
Quoted 10 lines

sound/soc/codecs/rt5514.c static const struct reg_default rt5514_reg[] = { · line 119

Quoted 4 lines
sound/soc/codecs/rt5514.c +4 -0
+static void rt5514_enable_dsp_prepare(struct rt5514_priv *rt5514)
+{
+	/* Reset */
+	regmap_write(rt5514->i2c_regmap, 0x18002000, 0x000010ec);

This is a *very* big table of magic numbers with what look like system specific settings in there (there seem to be some things routing to and from the ADC, and some clocking setup...). Are you sure none of this depends on the runtime configuration?

Yes, it is independent of the ASoC runtime configuration. The table of magic numbers is the settings for the voice wake up, so it is not required to be run on ASoC framework.

maintainer
#3 lore raw
Quoted 10 lines · Oder Chiou
Quoted 9 lines

sound/soc/codecs/rt5514.c static const struct reg_default rt5514_reg[] = { · line 119

Quoted 4 lines
sound/soc/codecs/rt5514.c +4 -0
+static void rt5514_enable_dsp_prepare(struct rt5514_priv *rt5514)
+{
+	/* Reset */
+	regmap_write(rt5514->i2c_regmap, 0x18002000, 0x000010ec);

This is a *very* big table of magic numbers with what look like system specific settings in there (there seem to be some things routing to and from the ADC, and some clocking setup...). Are you sure none of this depends on the runtime configuration?

Quoted 3 lines

Yes, it is independent of the ASoC runtime configuration. The table of magic numbers is the settings for the voice wake up, so it is not required to be run on ASoC framework.

Are you *positive* about that? There look to be routing things going on for example which might be system dependant.

author maintainer
#4 lore raw
Quoted 11 lines · Oder Chiou
Quoted 9 lines
Quoted 9 lines

sound/soc/codecs/rt5514.c static const struct reg_default rt5514_reg[] = { · line 119

Quoted 4 lines
sound/soc/codecs/rt5514.c +4 -0
+static void rt5514_enable_dsp_prepare(struct rt5514_priv *rt5514)
+{
+	/* Reset */
+	regmap_write(rt5514->i2c_regmap, 0x18002000, 0x000010ec);

This is a *very* big table of magic numbers with what look like system specific settings in there (there seem to be some things routing to and from the ADC, and some clocking setup...). Are you sure none of this depends on the runtime configuration?

Quoted 7 lines
Quoted 3 lines

Yes, it is independent of the ASoC runtime configuration. The table of magic numbers is the settings for the voice wake up, so it is not required to be run on ASoC framework.

Are you *positive* about that? There look to be routing things going on for example which might be system dependant.

They are the default settings for the our common hardware planning. If the developer wants to modify the settings to match the different hardware planning, they can consider to change the settings in the DSP firmware.

maintainer
#5 lore raw
Quoted 6 lines · Oder Chiou
Quoted 2 lines

Are you *positive* about that? There look to be routing things going on for example which might be system dependant.

They are the default settings for the our common hardware planning. If the developer wants to modify the settings to match the different hardware planning, they can consider to change the settings in the DSP firmware.

So if they do that the driver will not be compatible with their reconfigured firmware... this needs to work on all systems, including end user ones with different system integrations.

author maintainer
#6 lore raw
Quoted 11 lines
Quoted 6 lines
Quoted 2 lines

Are you *positive* about that? There look to be routing things going on for example which might be system dependant.

They are the default settings for the our common hardware planning. If the developer wants to modify the settings to match the different hardware planning, they can consider to change the settings in the DSP firmware.

So if they do that the driver will not be compatible with their reconfigured firmware... this needs to work on all systems, including end user ones with different system integrations.

The DSP of ALC5514 is a programmable DSP, and it also can control the all setting domain including routing path. So they can modify the different setting on the same register address in DSP firmware. The default settings also can be reference for the development of user's DSP firmware.

maintainer
#7 lore raw
Quoted 8 lines · Oder Chiou
Quoted 3 lines

So if they do that the driver will not be compatible with their reconfigured firmware... this needs to work on all systems, including end user ones with different system integrations.

The DSP of ALC5514 is a programmable DSP, and it also can control the all setting domain including routing path. So they can modify the different setting on the same register address in DSP firmware. The default settings also can be reference for the development of user's DSP firmware.

That doesn't address the issue at all. You've got a large set of register writes in the driver which will be the same for all users.