Skip to contentSkip to conversation

ASoC: rt5677: Remove the redundant definition in head file

PATCH Applied Oder Chiou 2 participants 6 messages Jul 7, 2014 – Aug 16, 2014

Subsystems (3)
lore
Share & tools
lore

Oder Chiou

author maintainer
#0 lore raw

PATCH 1/3 ASoC: rt5677: Remove the redundant definition in head file

The patch removes the redundant definition in head file

---
 sound/soc/codecs/rt5677.h | 7 -------
 1 file changed, 7 deletions(-)
sound/soc/codecs/rt5677.h +0 -7
index 08252e7..863393e 100644
@@ -1393,13 +1393,6 @@
 #define RT5677_DSP_IB_9_L			(0x1 << 1)
 #define RT5677_DSP_IB_9_L_SFT			1
 
-/* Debug String Length */
-#define RT5677_REG_DISP_LEN 23
-
-#define RT5677_NO_JACK		BIT(0)
-#define RT5677_HEADSET_DET	BIT(1)
-#define RT5677_HEADPHO_DET	BIT(2)
-
 /* System Clock Source */
 enum {
 	RT5677_SCLK_S_MCLK,
Signature · 1 line
1.8.1.1.439.g50a6b54
author maintainer
#1 lore raw

PATCH 2/3 ASoC: rt5677: Modify the voltage level in the BIAS OFF stage

The patch modifies the voltage level in the BIAS OFF stage

---
 sound/soc/codecs/rt5677.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/codecs/rt5677.c +1 -1
index 98370ae..67f1455 100644
@@ -3124,7 +3124,7 @@ static int rt5677_set_bias_level(struct snd_soc_codec *codec,
 		regmap_update_bits(rt5677->regmap, RT5677_DIG_MISC, 0x1, 0x0);
 		regmap_write(rt5677->regmap, RT5677_PWR_DIG1, 0x0000);
 		regmap_write(rt5677->regmap, RT5677_PWR_DIG2, 0x0000);
-		regmap_write(rt5677->regmap, RT5677_PWR_ANLG1, 0x0000);
+		regmap_write(rt5677->regmap, RT5677_PWR_ANLG1, 0x0022);
 		regmap_write(rt5677->regmap, RT5677_PWR_ANLG2, 0x0000);
 		regmap_update_bits(rt5677->regmap,
 			RT5677_PR_BASE + RT5677_BIAS_CUR4, 0x0f00, 0x0000);
Signature · 1 line
1.8.1.1.439.g50a6b54
maintainer Applied
#2 lore raw

Re: [PATCH 2/3] ASoC: rt5677: Modify the voltage level in the BIAS OFF stage

Quoted 1 line · Oder Chiou

The patch modifies the voltage level in the BIAS OFF stage

Applied, thanks.

author maintainer
#3 lore raw

PATCH 3/3 ASoC: rt5677: Support DSP function

In reply to Oder Chiou

The ALC5677 has a programmable DSP, and there is a SPI that is dadicated for DSP firmware loading. Therefore, the patch includes a SPI driver for writing the DSP firmware.

---
 sound/soc/codecs/Makefile     |   2 +-
 sound/soc/codecs/rt5677-spi.c | 151 ++++++++++++++++++++++++++++
 sound/soc/codecs/rt5677-spi.h |  20 ++++
 sound/soc/codecs/rt5677.c     | 227 ++++++++++++++++++++++++++++++++++++++++++
 sound/soc/codecs/rt5677.h     |   6 ++
 5 files changed, 405 insertions(+), 1 deletion(-)
 create mode 100644 sound/soc/codecs/rt5677-spi.c
 create mode 100644 sound/soc/codecs/rt5677-spi.h
sound/soc/codecs/Makefile +1 -1
index be3377b..3534706 100644
@@ -72,7 +72,7 @@ snd-soc-rt5631-objs := rt5631.o
 snd-soc-rt5640-objs := rt5640.o
 snd-soc-rt5645-objs := rt5645.o
 snd-soc-rt5651-objs := rt5651.o
-snd-soc-rt5677-objs := rt5677.o
+snd-soc-rt5677-objs := rt5677.o rt5677-spi.o
 snd-soc-sgtl5000-objs := sgtl5000.o
 snd-soc-alc5623-objs := alc5623.o
 snd-soc-alc5632-objs := alc5632.o
sound/soc/codecs/rt5677-spi.c new file +151 -0

151 lines not on this page · raw message

sound/soc/codecs/rt5677-spi.h new file +20 -0
new file mode 100644
index 0000000..0bfefae
@@ -0,0 +1,20 @@
+/*
+ * rt5677-spi.h  --  RT5677 ALSA SoC audio codec driver
+ *
+ * Copyright 2013 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 __RT5671_SPI_H__
+#define __RT5671_SPI_H__
+
+#define SPI_BUF_LEN 240
+
+int rt5677_spi_write(u8 *txbuf, size_t len);
+int rt5677_spi_burst_write(u32 addr, const struct firmware *fw);
+
+#endif /* __RT5677_SPI_H__ */
sound/soc/codecs/rt5677.c +227 -0

275 lines not on this page · raw message

sound/soc/codecs/rt5677.h +6 -0
index 863393e..32cbbf0 100644
@@ -1393,6 +1393,9 @@
 #define RT5677_DSP_IB_9_L			(0x1 << 1)
 #define RT5677_DSP_IB_9_L_SFT			1
 
+#define RT5677_FIRMWARE1	"rt5677_dsp_fw1.bin"
+#define RT5677_FIRMWARE2	"rt5677_dsp_fw2.bin"
+
 /* System Clock Source */
 enum {
 	RT5677_SCLK_S_MCLK,
@@ -1422,6 +1425,8 @@ struct rt5677_priv {
 	struct snd_soc_codec *codec;
 	struct rt5677_platform_data pdata;
 	struct regmap *regmap;
+	const struct firmware *fw1, *fw2;
+	struct mutex dsp_cmd_lock;
 
 	int sysclk;
 	int sysclk_src;
@@ -1431,6 +1436,7 @@ struct rt5677_priv {
 	int pll_src;
 	int pll_in;
 	int pll_out;
+	bool dsp_en;
 };
 
 #endif /* __RT5677_H__ */
Signature · 1 line
1.8.1.1.439.g50a6b54
maintainer
#4 lore raw

Re: [PATCH 3/3] ASoC: rt5677: Support DSP function

sound/soc/codecs/rt5677-spi.c line 53

Quoted 10 lines · Oder Chiou
sound/soc/codecs/rt5677-spi.c new file +10 -0
+int rt5677_spi_write(u8 *txbuf, size_t len)
+{
+	static DEFINE_MUTEX(lock);
+	int status;
+
+	mutex_lock(&lock);
+
+	status = spi_write(g_spi, txbuf, len);
+
+	mutex_unlock(&lock);

Since this lock is local to the function it doesn't do anything, the SPI framework has its own locking which makes it reentrant.

sound/soc/codecs/rt5677-spi.c line 76

Quoted 7 lines
sound/soc/codecs/rt5677-spi.c new file +7 -0
+int rt5677_spi_burst_write(u32 addr, const struct firmware *fw)
+{
+	u8 spi_cmd = 0x05;
+	u8 *write_buf;
+	unsigned int i, end, offset = 0;
+
+	write_buf = kmalloc(8 * 30 + 6, GFP_KERNEL);

Magic numbers! You also need to be aware that memory allocated by kmalloc() may not be contigous and while things using the SPI core DMA handling ought to be able to cope not everything will be.

sound/soc/codecs/rt5677-spi.c line 125

Quoted 10 lines
sound/soc/codecs/rt5677-spi.c new file +9 -0
+static int rt5677_spi_probe(struct spi_device *spi)
+{
+	g_spi = spi;
+	return 0;
+}
 
+static int rt5677_spi_remove(struct spi_device *spi)
+{
+	return 0;
+}

Delete empty functions.

sound/soc/codecs/rt5677-spi.c line 141

Quoted 5 lines
sound/soc/codecs/rt5677-spi.c new file +5 -0
+static int __init rt5677_spi_init(void)
+{
+	return spi_register_driver(&rt5677_spi_driver);
+}
+module_init(rt5677_spi_init);

module_spi_driver()

Quoted 6 lines
sound/soc/codecs/rt5677.c +6 -0
+static int rt5677_dsp_put(struct snd_kcontrol *kcontrol,
+		struct snd_ctl_elem_value *ucontrol)
+{
+	struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+	struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec);
+

sound/soc/codecs/rt5677.c static unsigned int bst_tlv[] = { · line 712

Quoted 10 lines
sound/soc/codecs/rt5677.c +10 -0
+	if (ucontrol->value.integer.value[0] != 0 && rt5677->dsp_en == false) {
+		rt5677->dsp_en = true;
+
+		regmap_update_bits(rt5677->regmap, RT5677_PWR_ANLG1,
+			RT5677_LDO1_SEL_MASK, 0x0);
+		regmap_update_bits(rt5677->regmap, RT5677_PWR_ANLG2,
+			RT5677_PWR_LDO1, RT5677_PWR_LDO1);
+		regmap_write(rt5677->regmap, RT5677_GLB_CLK2, 0x0080);
+		regmap_write(rt5677->regmap, RT5677_PWR_DSP2, 0x07ff);
+		regmap_write(rt5677->regmap, RT5677_PWR_DSP1, 0x07ff);

This doesn't seem joined up with the rest of the CODEC power management which suggests there's going to be problems - for example LDO1_SEL_MASK is also being managed by the existing set_bias_level(). What other devices do is manage the power for the DSP using a DAPM widget, enabling it when there's audio flowing through it.

sound/soc/codecs/rt5677.c static int rt5677_probe(struct snd_soc_codec *codec) · line 3374

Quoted 9 lines
sound/soc/codecs/rt5677.c +9 -0
+	mutex_init(&rt5677->dsp_cmd_lock);
+
+	request_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG,
+		RT5677_FIRMWARE1, codec->dev, GFP_KERNEL, codec,
+		rt5677_fw1_loaded);
+
+	request_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG,
+		RT5677_FIRMWARE2, codec->dev, GFP_KERNEL, codec,
+		rt5677_fw2_loaded);

It would be nicer to be able to only request firmware when needed rather than loading it once a boot time, that way we use a little less memory and we'll always have the latest firmware rather than what happened to be there when the system is booting.