Skip to contentSkip to conversation

ASoC: rt5514: add rt5514 SPI driver

PATCH Superseded Oder Chiou 2 participants 2 messages Feb 5, 2016 – Feb 8, 2016

Subsystems (3)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Oder Chiou

author maintainer
#0 lore raw

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

The patch adds the rt5514 SPI driver for loading the firmware of DSP and retrieving the voice data after the system is waked up by voice.

---
 sound/soc/codecs/Kconfig      |   6 +
 sound/soc/codecs/Makefile     |   2 +
 sound/soc/codecs/rt5514-spi.c | 494 ++++++++++++++++++++++++++++++++++++++++++
 sound/soc/codecs/rt5514-spi.h |  36 +++
 sound/soc/codecs/rt5514.c     | 243 +++++++++++++++++++++
 sound/soc/codecs/rt5514.h     |   1 +
 6 files changed, 782 insertions(+)
 create mode 100644 sound/soc/codecs/rt5514-spi.c
 create mode 100644 sound/soc/codecs/rt5514-spi.h
sound/soc/codecs/Kconfig +6 -0
index 4383966..6a36c3a 100644
@@ -621,6 +621,12 @@ config SND_SOC_RT298
 
 config SND_SOC_RT5514
 	tristate
+	default y if SND_SOC_RT5514_SPI=y
+	default m if SND_SOC_RT5514_SPI=m
+
+config SND_SOC_RT5514_SPI
+	tristate
+	depends on SPI_MASTER
 
 config SND_SOC_RT5616
 	tristate
sound/soc/codecs/Makefile +2 -0
index cd05e70..c04d5b6 100644
@@ -96,6 +96,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
@@ -304,6 +305,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 +494 -0

494 lines not on this page · raw message

sound/soc/codecs/rt5514-spi.h new file +36 -0
new file mode 100644
index 0000000..68b73f4
@@ -0,0 +1,36 @@
+/*
+ * 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__
+
+#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_read_addr(unsigned int addr, unsigned int *val);
+int rt5514_spi_write_addr(unsigned int addr, unsigned int val);
+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 +243 -0

279 lines not on this page · raw message

sound/soc/codecs/rt5514.h +1 -0
index 6ad8a61..80a5492 100644
@@ -247,6 +247,7 @@ struct rt5514_priv {
 	int pll_src;
 	int pll_in;
 	int pll_out;
+	int dsp_mode;
 };
 
 #endif /* __RT5514_H__ */
Signature · 1 line
1.8.1.1.439.g50a6b54
maintainer
#1 lore raw
Quoted 2 lines · Oder Chiou

The patch adds the rt5514 SPI driver for loading the firmware of DSP and retrieving the voice data after the system is waked up by voice.

Please have words with your hardware designers about having devices with multiple control interfaces :/

sound/soc/codecs/Kconfig config SND_SOC_RT298 · line 629

Quoted 8 lines

config SND_SOC_RT5514

sound/soc/codecs/Kconfig +6 -0
 	tristate
+	default y if SND_SOC_RT5514_SPI=y
+	default m if SND_SOC_RT5514_SPI=m
+
+config SND_SOC_RT5514_SPI
+	tristate
+	depends on SPI_MASTER

This is really confused and probably broken. I'm surprised that having a default for a hidden symbol like SND_SOC_RT5514 would do anything and there's nothing here that ensures that the dependencies are correct with respect to I2C.

Quoted 6 lines
sound/soc/codecs/rt5514-spi.c new file +6 -0
+static int rt5514_spi_prepare(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);
+

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

Quoted 10 lines
sound/soc/codecs/rt5514-spi.c new file +10 -0
+	rt5514_dsp->dma_offset = 0;
+	rt5514_dsp->dsp_offset = 0;
+	rt5514_spi_read_addr(RT5514_BUFFER_VOICE_BASE, &rt5514_dsp->buf_base);
+	rt5514_spi_read_addr(RT5514_BUFFER_VOICE_LIMIT, &rt5514_dsp->buf_limit);
+	rt5514_spi_read_addr(RT5514_BUFFER_VOICE_RP, &rt5514_dsp->buf_rp);
+	rt5514_spi_read_addr(RT5514_BUFFER_VOICE_SIZE, &rt5514_dsp->buf_size);
+
+	if (rt5514_dsp->buf_base && rt5514_dsp->buf_limit &&
+		rt5514_dsp->buf_rp && rt5514_dsp->buf_size)
+		schedule_delayed_work(&rt5514_dsp->copy_work, 0);

Scheduling this work in prepare() seems wrong - it's going to start doing things before we trigger anything. I'd expect this to be done on trigger (which is fine).

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

Quoted 11 lines
sound/soc/codecs/rt5514-spi.c new file +11 -0
+		x[0].len = 5;
+		x[0].tx_buf = write_buf;
+		spi_message_add_tail(&x[0], &message);
+
+		x[1].len = 4;
+		x[1].tx_buf = write_buf;
+		spi_message_add_tail(&x[1], &message);
+
+		x[2].len = end;
+		x[2].rx_buf = rxbuf + offset;
+		spi_message_add_tail(&x[2], &message);

This all looks a lot like a regmap... only funny thing is the command byte on the front of everything which we could add support for, AFAICT we could just use burst I/O for everything.

Review

Quoted 1 line
(quoted diff) +1 -0
+		offset += RT5514_SPI_BUF_LEN;

Is this a limitation of the device?

Quoted 1 line

+EXPORT_SYMBOL_GPL(rt5514_spi_burst_read);

Why are all these symbols exported?

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

Quoted 8 lines
sound/soc/codecs/rt5514.c +8 -0
+static void rt5514_enable_dsp_clock(struct rt5514_priv *rt5514)
+{
+	/* Reset */
+	regmap_write(rt5514->i2c_regmap, 0x18002000, 0x000010ec);
+	/* LDO_I_limit */
+	regmap_write(rt5514->i2c_regmap, 0x18002200, 0x00028604);
+	/* (for reset DSP) mini-core reset */
+	regmap_write(rt5514->i2c_regmap, 0x18002f00, 0x0005514b);

This looks like it's doing rather more than enabling the clock, there looks to be quite a bit of use case specific stuff in here...

Review

Quoted 2 lines
(quoted diff) +2 -0
+		request_firmware(&fw, "0x4ff60000.dat", codec->dev);
+		if (fw) {

That needs a *much* more sensible filename, at least put the firmware in a directory for the CODEC.

sound/soc/codecs/rt5514.c static const struct snd_kcontrol_new rt5514_snd_controls[] = { · line 475

Quoted 2 lines
sound/soc/codecs/rt5514.c +2 -0
+	SOC_SINGLE_EXT("DSP Control", SND_SOC_NOPM, 0, 1, 0,
+		rt5514_dsp_mode_get, rt5514_dsp_mode_put),

It's not clear what this is intended to mean to userspace... looks like it might be intended to be an on/off switch but that's more a DAPM thing.

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

Quoted 4 lines
sound/soc/codecs/rt5514.c +4 -0
+		if (snd_soc_codec_get_bias_level(codec) ==
+			SND_SOC_BIAS_STANDBY) {
+			if (rt5514->dsp_mode) {
+				rt5514->dsp_mode = 0;

So we reset the value for dsp_mode when powering up... that's confusing?