Skip to contentSkip to conversation

ASoC: rt5514: add rt5514 SPI driver

PATCH Superseded Oder Chiou 2 participants 4 messages May 9, 2016 – Jun 3, 2016

Subsystems (3)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Oder Chiou

author maintainer
#0 lore raw

PATCH v3 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 | 457 ++++++++++++++++++++++++++++++++++++++++++
 sound/soc/codecs/rt5514-spi.h |  38 ++++
 sound/soc/codecs/rt5514.c     | 134 ++++++++++++-
 sound/soc/codecs/rt5514.h     |   4 +
 6 files changed, 637 insertions(+), 1 deletion(-)
 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 c6f86ef..90749d2 100644
@@ -639,6 +639,9 @@ config SND_SOC_RT298
 config SND_SOC_RT5514
 	tristate
 
+config SND_SOC_RT5514_SPI
+	tristate
+
 config SND_SOC_RT5616
 	tristate "Realtek RT5616 CODEC"
 	depends on I2C
sound/soc/codecs/Makefile +2 -0
index 94873ee..9ab7016 100644
@@ -99,6 +99,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
@@ -312,6 +313,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 +457 -0

457 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 +133 -1

176 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

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

Quoted 6 lines · Oder Chiou
sound/soc/codecs/rt5514-spi.c new file +6 -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;

I can't see anything that cancels this work when the PCM stream to userspace is stopped or if things power off otherwise?

author maintainer
#2 lore raw
Quoted 10 lines

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

Quoted 6 lines
sound/soc/codecs/rt5514-spi.c new file +6 -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;

I can't see anything that cancels this work when the PCM stream to userspace is stopped or if things power off otherwise?

In the beginning of the function "rt5514_spi_copy_work", there is a if condition to check the variable "rt5514_dsp->substream", and the function "rt5514_spi_hw_free" will set the variable "rt5514_dsp->substream" to NULL. It also will make the delayed work stop and won't schedule again.

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

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

Quoted 6 lines
sound/soc/codecs/rt5514-spi.c new file +6 -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;

I can't see anything that cancels this work when the PCM stream to userspace is stopped or if things power off otherwise?

Quoted 4 lines

In the beginning of the function "rt5514_spi_copy_work", there is a if condition to check the variable "rt5514_dsp->substream", and the function "rt5514_spi_hw_free" will set the variable "rt5514_dsp->substream" to NULL. It also will make the delayed work stop and won't schedule again.

No, that won't stop the currently running work which means that on driver removal we could for example try to free the driver data while the work is still running. The driver needs to explicitly ensure that there is no work running when it shouldn't be, not just stop any new work being added.