Skip to contentSkip to conversation

ASoC: rsnd: add SRC support

PATCH Applied Kuninori Morimoto 3 participants 17 messages Dec 20, 2013 – Jan 7, 2014

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover ASoC: rsnd: add SRC support

Hi Mark

These are cleanup and SRC support patches
for Renesas sound driver

#1 - #4 are cleanup
#5 - #9 are prepare for SRC support
#a is SRC support

Kuninori Morimoto (10):
1) ASoC: rsnd: add rsnd_adg_set_ssi_clk() and cleanup adg
2) ASoC: rsnd: tidyup ssi comment
3) ASoC: rsnd: tidyup register naming
4) ASoC: rsnd: make sure variable name for 44.1kHz/48kHz
5) ASoC: rsnd: route setting is needed only Gen1
6) ASoC: rsnd: make sure Gen2 only method on ssi
7) ASoC: rsnd: add rsnd_scu_transfer_start()
8) ASoC: rsnd: scu cleanup: add rsnd_scu_rate_ctrl()
9) ASoC: rsnd: tidyup rsnd_ssi_master_clk_start() parameter
a) ASoC: rsnd: add SRC (Sampling Rate Converter) support

 include/sound/rcar_snd.h |    1 +
 sound/soc/sh/rcar/adg.c  |  151 +++++++++++++++++++++++++++-----------
 sound/soc/sh/rcar/gen.c  |   14 +++-
 sound/soc/sh/rcar/rsnd.h |   32 ++++++--
 sound/soc/sh/rcar/scu.c  |  181 +++++++++++++++++++++++++++++++++++++++++-----
 sound/soc/sh/rcar/ssi.c  |   17 ++---
 6 files changed, 314 insertions(+), 82 deletions(-)

Best regards
---
Kuninori Morimoto

#1 lore raw

PATCH 1/10 ASoC: rsnd: add rsnd_adg_set_ssi_clk() and cleanup adg

From: Kuninori Morimoto <[email protected]>

This patch adds rsnd_adg_set_ssi_clk() to access to AUDIO_CLK_SEL0/1/2, and removes last user of rsnd_write/read/bset which is very low level function.

---
 sound/soc/sh/rcar/adg.c |   58 ++++++++++++++++++++---------------------------
 1 file changed, 24 insertions(+), 34 deletions(-)
sound/soc/sh/rcar/adg.c +24 -34
index 9430097..55d0394 100644
@@ -30,41 +30,41 @@ struct rsnd_adg {
 	     i++, (pos) = adg->clk[i])
 #define rsnd_priv_to_adg(priv) ((struct rsnd_adg *)(priv)->adg)
 
-static enum rsnd_reg rsnd_adg_ssi_reg_get(int id)
+static void rsnd_adg_set_ssi_clk(struct rsnd_mod *mod, u32 val)
 {
-	enum rsnd_reg reg;
+	int id = rsnd_mod_id(mod);
+	int shift = (id % 4) * 8;
+	u32 mask = 0xFF << shift;
+
+	val = val << shift;
 
 	/*
 	 * SSI 8 is not connected to ADG.
 	 * it works with SSI 7
 	 */
 	if (id == 8)
-		return RSND_REG_MAX;
-
-	if (0 <= id && id <= 3)
-		reg = RSND_REG_AUDIO_CLK_SEL0;
-	else if (4 <= id && id <= 7)
-		reg = RSND_REG_AUDIO_CLK_SEL1;
-	else
-		reg = RSND_REG_AUDIO_CLK_SEL2;
-
-	return reg;
+		return;
+
+	switch (id / 4) {
+	case 0:
+		rsnd_mod_bset(mod, AUDIO_CLK_SEL0, mask, val);
+		break;
+	case 1:
+		rsnd_mod_bset(mod, AUDIO_CLK_SEL1, mask, val);
+		break;
+	case 2:
+		rsnd_mod_bset(mod, AUDIO_CLK_SEL2, mask, val);
+		break;
+	}
 }
 
 int rsnd_adg_ssi_clk_stop(struct rsnd_mod *mod)
 {
-	struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
-	enum rsnd_reg reg;
-	int id;
-
 	/*
 	 * "mod" = "ssi" here.
 	 * we can get "ssi id" from mod
 	 */
-	id  = rsnd_mod_id(mod);
-	reg = rsnd_adg_ssi_reg_get(id);
-
-	rsnd_write(priv, mod, reg, 0);
+	rsnd_adg_set_ssi_clk(mod, 0);
 
 	return 0;
 }
@@ -75,8 +75,7 @@ int rsnd_adg_ssi_clk_try_start(struct rsnd_mod *mod, unsigned int rate)
 	struct rsnd_adg *adg = rsnd_priv_to_adg(priv);
 	struct device *dev = rsnd_priv_to_dev(priv);
 	struct clk *clk;
-	enum rsnd_reg reg;
-	int id, shift, i;
+	int i;
 	u32 data;
 	int sel_table[] = {
 		[CLKA] = 0x1,
@@ -125,19 +124,10 @@ found_clock:
 	 * This "mod" = "ssi" here.
 	 * we can get "ssi id" from mod
 	 */
-	id  = rsnd_mod_id(mod);
-	reg = rsnd_adg_ssi_reg_get(id);
-
-	dev_dbg(dev, "ADG: ssi%d selects clk%d = %d", id, i, rate);
-
-	/*
-	 * Enable SSIx clock
-	 */
-	shift = (id % 4) * 8;
+	rsnd_adg_set_ssi_clk(mod, data);
 
-	rsnd_bset(priv, mod, reg,
-		   0xFF << shift,
-		   data << shift);
+	dev_dbg(dev, "ADG: ssi%d selects clk%d = %d",
+		rsnd_mod_id(mod), i, rate);
 
 	return 0;
 }
Signature · 1 line
1.7.9.5
#2 lore raw

PATCH 2/10 ASoC: rsnd: tidyup ssi comment

In reply to Kuninori Morimoto

From: Kuninori Morimoto <[email protected]>

we can check rsnd_ssi_init(), not, rsnd_ssi_start()

---
 sound/soc/sh/rcar/ssi.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/sh/rcar/ssi.c +1 -1
index 85936ae..6b1f501 100644
@@ -209,7 +209,7 @@ static int rsnd_ssi_master_clk_start(struct rsnd_ssi *ssi,
 			/*
 			 * this driver is assuming that
 			 * system word is 64fs (= 2 x 32bit)
-			 * see rsnd_ssi_start()
+			 * see rsnd_ssi_init()
 			 */
 			main_rate = rate / adg_clk_div_table[i]
 				* 32 * 2 * ssi_clk_mul_table[j];
Signature · 1 line
1.7.9.5
#3 lore raw

PATCH 3/10 ASoC: rsnd: tidyup register naming

In reply to Kuninori Morimoto

From: Kuninori Morimoto <[email protected]>

Use correct register name which appears in the datasheet

---
 sound/soc/sh/rcar/gen.c  |    4 ++--
 sound/soc/sh/rcar/rsnd.h |    4 ++--
 sound/soc/sh/rcar/scu.c  |    4 ++--
 3 files changed, 6 insertions(+), 6 deletions(-)
sound/soc/sh/rcar/gen.c +2 -2
index d0ab203..862758d 100644
@@ -314,11 +314,11 @@ static int rsnd_gen1_regmap_init(struct rsnd_priv *priv, struct rsnd_gen *gen)
 		RSND_GEN1_S_REG(gen, SRU,	SRC_TMG_SEL0,	0x08),
 		RSND_GEN1_S_REG(gen, SRU,	SRC_TMG_SEL1,	0x0c),
 		RSND_GEN1_S_REG(gen, SRU,	SRC_TMG_SEL2,	0x10),
-		RSND_GEN1_S_REG(gen, SRU,	SRC_CTRL,	0xc0),
+		RSND_GEN1_S_REG(gen, SRU,	SRC_ROUTE_CTRL,	0xc0),
 		RSND_GEN1_S_REG(gen, SRU,	SSI_MODE0,	0xD0),
 		RSND_GEN1_S_REG(gen, SRU,	SSI_MODE1,	0xD4),
 		RSND_GEN1_M_REG(gen, SRU,	BUSIF_MODE,	0x20,	0x4),
-		RSND_GEN1_M_REG(gen, SRU,	BUSIF_ADINR,	0x214,	0x40),
+		RSND_GEN1_M_REG(gen, SRU,	SRC_ADINR,	0x214,	0x40),
 
 		RSND_GEN1_S_REG(gen, ADG,	BRRA,		0x00),
 		RSND_GEN1_S_REG(gen, ADG,	BRRB,		0x04),
sound/soc/sh/rcar/rsnd.h +2 -2
index bff7b9e..d5c0182 100644
@@ -36,12 +36,12 @@ enum rsnd_reg {
 	RSND_REG_SRC_TMG_SEL0,
 	RSND_REG_SRC_TMG_SEL1,
 	RSND_REG_SRC_TMG_SEL2,
-	RSND_REG_SRC_CTRL,
+	RSND_REG_SRC_ROUTE_CTRL,
 	RSND_REG_SSI_MODE0,
 	RSND_REG_SSI_MODE1,
 	RSND_REG_BUSIF_MODE,
-	RSND_REG_BUSIF_ADINR,
 	RSND_REG_INT_ENABLE,
+	RSND_REG_SRC_ADINR,
 
 	/* ADG */
 	RSND_REG_BRRA,
sound/soc/sh/rcar/scu.c +2 -2
index fa8fa15..f18f45e 100644
@@ -115,7 +115,7 @@ static int rsnd_scu_set_mode(struct rsnd_priv *priv,
 
 	if (rsnd_is_gen1(priv)) {
 		val = (1 << id);
-		rsnd_mod_bset(mod, SRC_CTRL, val, val);
+		rsnd_mod_bset(mod, SRC_ROUTE_CTRL, val, val);
 	}
 
 	return 0;
@@ -141,7 +141,7 @@ static int rsnd_scu_set_hpbif(struct rsnd_priv *priv,
 	}
 
 	rsnd_mod_write(mod, BUSIF_MODE, 1);
-	rsnd_mod_write(mod, BUSIF_ADINR, adinr);
+	rsnd_mod_write(mod, SRC_ADINR, adinr);
 
 	return 0;
 }
Signature · 1 line
1.7.9.5
#4 lore raw

PATCH 4/10 ASoC: rsnd: make sure variable name for 44.1kHz/48kHz

In reply to Kuninori Morimoto

From: Kuninori Morimoto <[email protected]>

This driver is assuming that
RBGA is used as source clock of 44.1kHz category, and RBGB is used as source clock of 48kHz category. This patch clarifies the variable name.

---
 sound/soc/sh/rcar/adg.c |   20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
sound/soc/sh/rcar/adg.c +10 -10
index 55d0394..2e71a7b 100644
@@ -19,8 +19,8 @@
 struct rsnd_adg {
 	struct clk *clk[CLKMAX];
 
-	int rate_of_441khz_div_6;
-	int rate_of_48khz_div_6;
+	int rbga_rate_for_441khz_div_6;	/* RBGA */
+	int rbgb_rate_for_48khz_div_6;	/* RBGB */
 	u32 ckr;
 };
 
@@ -101,12 +101,12 @@ int rsnd_adg_ssi_clk_try_start(struct rsnd_mod *mod, unsigned int rate)
 	/*
 	 * find 1/6 clock from BRGA/BRGB
 	 */
-	if (rate == adg->rate_of_441khz_div_6) {
+	if (rate == adg->rbga_rate_for_441khz_div_6) {
 		data = 0x10;
 		goto found_clock;
 	}
 
-	if (rate == adg->rate_of_48khz_div_6) {
+	if (rate == adg->rbgb_rate_for_48khz_div_6) {
 		data = 0x20;
 		goto found_clock;
 	}
@@ -156,8 +156,8 @@ static void rsnd_adg_ssi_clk_init(struct rsnd_priv *priv, struct rsnd_adg *adg)
 	 *	rsnd_adg_ssi_clk_try_start()
 	 */
 	ckr = 0;
-	adg->rate_of_441khz_div_6 = 0;
-	adg->rate_of_48khz_div_6  = 0;
+	adg->rbga_rate_for_441khz_div_6 = 0;
+	adg->rbgb_rate_for_48khz_div_6  = 0;
 	for_each_rsnd_clk(clk, adg, i) {
 		rate = clk_get_rate(clk);
 
@@ -165,14 +165,14 @@ static void rsnd_adg_ssi_clk_init(struct rsnd_priv *priv, struct rsnd_adg *adg)
 			continue;
 
 		/* RBGA */
-		if (!adg->rate_of_441khz_div_6 && (0 == rate % 44100)) {
-			adg->rate_of_441khz_div_6 = rate / 6;
+		if (!adg->rbga_rate_for_441khz_div_6 && (0 == rate % 44100)) {
+			adg->rbga_rate_for_441khz_div_6 = rate / 6;
 			ckr |= brg_table[i] << 20;
 		}
 
 		/* RBGB */
-		if (!adg->rate_of_48khz_div_6 && (0 == rate % 48000)) {
-			adg->rate_of_48khz_div_6 = rate / 6;
+		if (!adg->rbgb_rate_for_48khz_div_6 && (0 == rate % 48000)) {
+			adg->rbgb_rate_for_48khz_div_6 = rate / 6;
 			ckr |= brg_table[i] << 16;
 		}
 	}
Signature · 1 line
1.7.9.5
#5 lore raw

PATCH 5/10 ASoC: rsnd: route setting is needed only Gen1

In reply to Kuninori Morimoto

From: Kuninori Morimoto <[email protected]>

Renesas sound has SRC (= Sampling Rate Converter), but, the HW implementation depends on its generation. It was part of SRU on Gen1, and SCU on Gen2.
This SCU needs DMA transfer to use it.
Current rsnd driver is using it as DMA transfer buffer (= no rate convert), and Gen1 is only supported at this point.

This patch cleanup it with focusing about SRC and Gen2 part.

rsnd_scu_set_route() is needed only Gen1.

This patch renames it to rsnd_scu_set_route_if_gen1() and it adds comment to rsnd_reg member
in order to clarify it is used for Gen1.

---
 sound/soc/sh/rcar/rsnd.h |   10 +++++-----
 sound/soc/sh/rcar/scu.c  |    6 ++++--
 2 files changed, 9 insertions(+), 7 deletions(-)
sound/soc/sh/rcar/rsnd.h +5 -5
index d5c0182..a14bc92 100644
@@ -32,11 +32,11 @@
  */
 enum rsnd_reg {
 	/* SRU/SCU/SSIU */
-	RSND_REG_SRC_ROUTE_SEL,
-	RSND_REG_SRC_TMG_SEL0,
-	RSND_REG_SRC_TMG_SEL1,
-	RSND_REG_SRC_TMG_SEL2,
-	RSND_REG_SRC_ROUTE_CTRL,
+	RSND_REG_SRC_ROUTE_SEL,		/* for Gen1 */
+	RSND_REG_SRC_TMG_SEL0,		/* for Gen1 */
+	RSND_REG_SRC_TMG_SEL1,		/* for Gen1 */
+	RSND_REG_SRC_TMG_SEL2,		/* for Gen1 */
+	RSND_REG_SRC_ROUTE_CTRL,	/* for Gen1 */
 	RSND_REG_SSI_MODE0,
 	RSND_REG_SSI_MODE1,
 	RSND_REG_BUSIF_MODE,
sound/soc/sh/rcar/scu.c +4 -2
index f18f45e..206e4cb 100644
@@ -36,7 +36,8 @@ struct rsnd_scu {
 		     ((pos) = (struct rsnd_scu *)(priv)->scu + i);	\
 	     i++)
 
-static int rsnd_scu_set_route(struct rsnd_priv *priv,
+/* Gen1 only */
+static int rsnd_src_set_route_if_gen1(struct rsnd_priv *priv,
 			      struct rsnd_mod *mod,
 			      struct rsnd_dai *rdai,
 			      struct rsnd_dai_stream *io)
@@ -174,7 +175,8 @@ static int rsnd_scu_start(struct rsnd_mod *mod,
 	}
 
 	/* it use DMA transter */
-	ret = rsnd_scu_set_route(priv, mod, rdai, io);
+
+	ret = rsnd_src_set_route_if_gen1(priv, mod, rdai, io);
 	if (ret < 0)
 		return ret;
 
Signature · 1 line
1.7.9.5
#6 lore raw

PATCH 6/10 ASoC: rsnd: INT_ENABLE is needed only Gen2

In reply to Kuninori Morimoto

From: Kuninori Morimoto <[email protected]>

INT_ENABLE is needed only Gen2.
rsnd_mod_write() do nothing on Gen1, but it is confusable.

---
 sound/soc/sh/rcar/rsnd.h |    2 +-
 sound/soc/sh/rcar/ssi.c  |    5 +++--
 2 files changed, 4 insertions(+), 3 deletions(-)
sound/soc/sh/rcar/rsnd.h +1 -1
index a14bc92..3774dfc 100644
@@ -40,7 +40,7 @@ enum rsnd_reg {
 	RSND_REG_SSI_MODE0,
 	RSND_REG_SSI_MODE1,
 	RSND_REG_BUSIF_MODE,
-	RSND_REG_INT_ENABLE,
+	RSND_REG_INT_ENABLE,		/* for Gen2 */
 	RSND_REG_SRC_ADINR,
 
 	/* ADG */
sound/soc/sh/rcar/ssi.c +3 -2
index 6b1f501..98a3de0 100644
@@ -457,8 +457,9 @@ static int rsnd_ssi_pio_start(struct rsnd_mod *mod,
 	/* enable PIO IRQ */
 	ssi->cr_etc = UIEN | OIEN | DIEN;
 
-	/* enable PIO interrupt */
-	rsnd_mod_write(&ssi->mod, INT_ENABLE, 0x0f000000);
+	/* enable PIO interrupt if gen2 */
+	if (rsnd_is_gen2(priv))
+		rsnd_mod_write(&ssi->mod, INT_ENABLE, 0x0f000000);
 
 	rsnd_ssi_hw_start(ssi, rdai, io);
 
Signature · 1 line
1.7.9.5
#7 lore raw

PATCH 7/10 ASoC: rsnd: add rsnd_scu_transfer_start()

In reply to Kuninori Morimoto

From: Kuninori Morimoto <[email protected]>

Renesas sound has SRC (= Sampling Rate Converter), but, the HW implementation depends on its generation. It was part of SRU on Gen1, and SCU on Gen2.
This SCU needs DMA transfer to use it.
Current rsnd driver is using it as DMA transfer buffer (= no rate convert), and Gen1 is only supported at this point.

This patch cleanup it with focusing about SRC and Gen2 part.

SRC_CTRL/BUSIF_MODE are used for transfer start. This patch adds rsnd_scu_transfer_start() and merge these

---
 sound/soc/sh/rcar/scu.c |   39 ++++++++++++++++++++-------------------
 1 file changed, 20 insertions(+), 19 deletions(-)
sound/soc/sh/rcar/scu.c +20 -19
index 206e4cb..4ac20f2 100644
@@ -106,22 +106,6 @@ static int rsnd_src_set_route_if_gen1(struct rsnd_priv *priv,
 	return 0;
 }
 
-static int rsnd_scu_set_mode(struct rsnd_priv *priv,
-			     struct rsnd_mod *mod,
-			     struct rsnd_dai *rdai,
-			     struct rsnd_dai_stream *io)
-{
-	int id = rsnd_mod_id(mod);
-	u32 val;
-
-	if (rsnd_is_gen1(priv)) {
-		val = (1 << id);
-		rsnd_mod_bset(mod, SRC_ROUTE_CTRL, val, val);
-	}
-
-	return 0;
-}
-
 static int rsnd_scu_set_hpbif(struct rsnd_priv *priv,
 			      struct rsnd_mod *mod,
 			      struct rsnd_dai *rdai,
@@ -141,12 +125,29 @@ static int rsnd_scu_set_hpbif(struct rsnd_priv *priv,
 		return -EIO;
 	}
 
-	rsnd_mod_write(mod, BUSIF_MODE, 1);
 	rsnd_mod_write(mod, SRC_ADINR, adinr);
 
 	return 0;
 }
 
+static int rsnd_scu_transfer_start(struct rsnd_priv *priv,
+				   struct rsnd_mod *mod,
+				   struct rsnd_dai *rdai,
+				   struct rsnd_dai_stream *io)
+{
+	int id = rsnd_mod_id(mod);
+	u32 val;
+
+	if (rsnd_is_gen1(priv)) {
+		val = (1 << id);
+		rsnd_mod_bset(mod, SRC_ROUTE_CTRL, val, val);
+	}
+
+	rsnd_mod_write(mod, BUSIF_MODE, 1);
+
+	return 0;
+}
+
 bool rsnd_scu_hpbif_is_enable(struct rsnd_mod *mod)
 {
 	struct rsnd_scu *scu = rsnd_mod_to_scu(mod);
@@ -180,11 +181,11 @@ static int rsnd_scu_start(struct rsnd_mod *mod,
 	if (ret < 0)
 		return ret;
 
-	ret = rsnd_scu_set_mode(priv, mod, rdai, io);
+	ret = rsnd_scu_set_hpbif(priv, mod, rdai, io);
 	if (ret < 0)
 		return ret;
 
-	ret = rsnd_scu_set_hpbif(priv, mod, rdai, io);
+	ret = rsnd_scu_transfer_start(priv, mod, rdai, io);
 	if (ret < 0)
 		return ret;
 
Signature · 1 line
1.7.9.5
#8 lore raw

PATCH 8/10 ASoC: rsnd: scu cleanup: add rsnd_scu_rate_ctrl()

In reply to Kuninori Morimoto

From: Kuninori Morimoto <[email protected]>

Renesas sound has SRC (= Sampling Rate Converter), but, the HW implementation depends on its generation. It was part of SRU on Gen1, and SCU on Gen2.
This SCU needs DMA transfer to use it.
Current rsnd driver is using it as DMA transfer buffer (= no rate convert), and Gen1 is only supported at this point.

This patch cleanup it with focusing about SRC and Gen2 part.

rsnd_scu_set_hpbif() is renamed to rsnd_scu_rate_ctrl(), since its naming doesn't indicate the function meaning.

---
 sound/soc/sh/rcar/scu.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
sound/soc/sh/rcar/scu.c +2 -2
index 4ac20f2..fcc0a66 100644
@@ -106,7 +106,7 @@ static int rsnd_src_set_route_if_gen1(struct rsnd_priv *priv,
 	return 0;
 }
 
-static int rsnd_scu_set_hpbif(struct rsnd_priv *priv,
+static int rsnd_scu_rate_ctrl(struct rsnd_priv *priv,
 			      struct rsnd_mod *mod,
 			      struct rsnd_dai *rdai,
 			      struct rsnd_dai_stream *io)
@@ -181,7 +181,7 @@ static int rsnd_scu_start(struct rsnd_mod *mod,
 	if (ret < 0)
 		return ret;
 
-	ret = rsnd_scu_set_hpbif(priv, mod, rdai, io);
+	ret = rsnd_scu_rate_ctrl(priv, mod, rdai, io);
 	if (ret < 0)
 		return ret;
 
Signature · 1 line
1.7.9.5
#9 lore raw

PATCH 9/10 ASoC: rsnd: tidyup rsnd_ssi_master_clk_start() parameter

In reply to Kuninori Morimoto

From: Kuninori Morimoto <[email protected]>

Renesas sound has SRC (= Sampling Rate Converter), but, the HW implementation depends on its generation. It was part of SRU on Gen1, and SCU on Gen2.
This SCU needs DMA transfer to use it.
Current rsnd driver is using it as DMA transfer buffer (= no rate convert), and Gen1 is only supported at this point.

This patch cleanup it with focusing about SRC and Gen2 part.

ssi clock which is calculated from rsnd_ssi_master_clk_start() should have flexibility since Renesas sound has
SRC (= Sampling Rate Converter).
But current implementation is using runtime->rate directly. This patch tidyup rsnd_ssi_master_clk_start() parameter as preparation of future SRC support

---
 sound/soc/sh/rcar/ssi.c |   10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
sound/soc/sh/rcar/ssi.c +4 -6
index 98a3de0..846bb5e 100644
@@ -187,9 +187,10 @@ static void rsnd_ssi_status_check(struct rsnd_mod *mod,
 }
 
 static int rsnd_ssi_master_clk_start(struct rsnd_ssi *ssi,
-				     unsigned int rate)
+				     struct rsnd_dai_stream *io)
 {
 	struct rsnd_priv *priv = rsnd_mod_to_priv(&ssi->mod);
+	struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
 	struct device *dev = rsnd_priv_to_dev(priv);
 	int i, j, ret;
 	int adg_clk_div_table[] = {
@@ -199,6 +200,7 @@ static int rsnd_ssi_master_clk_start(struct rsnd_ssi *ssi,
 		1, 2, 4, 8, 16, 6, 12,
 	};
 	unsigned int main_rate;
+	unsigned int rate = runtime->rate;
 
 	/*
 	 * Find best clock, and try to start ADG
@@ -251,14 +253,10 @@ static void rsnd_ssi_hw_start(struct rsnd_ssi *ssi,
 		clk_enable(ssi->clk);
 
 		if (rsnd_rdai_is_clk_master(rdai)) {
-			struct snd_pcm_runtime *runtime;
-
-			runtime = rsnd_io_to_runtime(io);
-
 			if (rsnd_ssi_clk_from_parent(ssi))
 				rsnd_ssi_hw_start(ssi->parent, rdai, io);
 			else
-				rsnd_ssi_master_clk_start(ssi, runtime->rate);
+				rsnd_ssi_master_clk_start(ssi, io);
 		}
 	}
 
Signature · 1 line
1.7.9.5
#10 lore raw

PATCH 10/10 ASoC: rsnd: add SRC (Sampling Rate Converter) support

In reply to Kuninori Morimoto

From: Kuninori Morimoto <[email protected]>

This patch adds SRC support to Renesas sound driver. SRC converts sampling rate between codec <-> cpu. It needs special codec chip,
or very simple DA/AD converter to use it. This patch was tested via ak4554 codec,
and supports Gen1 only at this point.

---
 include/sound/rcar_snd.h |    1 +
 sound/soc/sh/rcar/adg.c  |   73 ++++++++++++++++++++++
 sound/soc/sh/rcar/gen.c  |   10 +++
 sound/soc/sh/rcar/rsnd.h |   18 ++++++
 sound/soc/sh/rcar/scu.c  |  152 +++++++++++++++++++++++++++++++++++++++++++---
 sound/soc/sh/rcar/ssi.c  |    2 +-
 6 files changed, 248 insertions(+), 8 deletions(-)
include/sound/rcar_snd.h +1 -0
index 8f639e0..6add6cc 100644
@@ -57,6 +57,7 @@ struct rsnd_ssi_platform_info {
 
 struct rsnd_scu_platform_info {
 	u32 flags;
+	u32 convert_rate; /* sampling rate convert */
 };
 
 /*
sound/soc/sh/rcar/adg.c +73 -0

79 lines not on this page · raw message

sound/soc/sh/rcar/gen.c +10 -0
index 862758d..add088b 100644
@@ -318,13 +318,23 @@ static int rsnd_gen1_regmap_init(struct rsnd_priv *priv, struct rsnd_gen *gen)
 		RSND_GEN1_S_REG(gen, SRU,	SSI_MODE0,	0xD0),
 		RSND_GEN1_S_REG(gen, SRU,	SSI_MODE1,	0xD4),
 		RSND_GEN1_M_REG(gen, SRU,	BUSIF_MODE,	0x20,	0x4),
+		RSND_GEN1_M_REG(gen, SRU,	SRC_ROUTE_MODE0,0x50,	0x8),
+		RSND_GEN1_M_REG(gen, SRU,	SRC_SWRSR,	0x200,	0x40),
+		RSND_GEN1_M_REG(gen, SRU,	SRC_SRCIR,	0x204,	0x40),
 		RSND_GEN1_M_REG(gen, SRU,	SRC_ADINR,	0x214,	0x40),
+		RSND_GEN1_M_REG(gen, SRU,	SRC_IFSCR,	0x21c,	0x40),
+		RSND_GEN1_M_REG(gen, SRU,	SRC_IFSVR,	0x220,	0x40),
+		RSND_GEN1_M_REG(gen, SRU,	SRC_SRCCR,	0x224,	0x40),
+		RSND_GEN1_M_REG(gen, SRU,	SRC_MNFSR,	0x228,	0x40),
 
 		RSND_GEN1_S_REG(gen, ADG,	BRRA,		0x00),
 		RSND_GEN1_S_REG(gen, ADG,	BRRB,		0x04),
 		RSND_GEN1_S_REG(gen, ADG,	SSICKR,		0x08),
 		RSND_GEN1_S_REG(gen, ADG,	AUDIO_CLK_SEL0,	0x0c),
 		RSND_GEN1_S_REG(gen, ADG,	AUDIO_CLK_SEL1,	0x10),
+		RSND_GEN1_S_REG(gen, ADG,	AUDIO_CLK_SEL3,	0x18),
+		RSND_GEN1_S_REG(gen, ADG,	AUDIO_CLK_SEL4,	0x1c),
+		RSND_GEN1_S_REG(gen, ADG,	AUDIO_CLK_SEL5,	0x20),
 
 		RSND_GEN1_M_REG(gen, SSI,	SSICR,		0x00,	0x40),
 		RSND_GEN1_M_REG(gen, SSI,	SSISR,		0x04,	0x40),
sound/soc/sh/rcar/rsnd.h +18 -0
index 3774dfc..4ca66cd 100644
@@ -41,7 +41,14 @@ enum rsnd_reg {
 	RSND_REG_SSI_MODE1,
 	RSND_REG_BUSIF_MODE,
 	RSND_REG_INT_ENABLE,		/* for Gen2 */
+	RSND_REG_SRC_ROUTE_MODE0,
+	RSND_REG_SRC_SWRSR,
+	RSND_REG_SRC_SRCIR,
 	RSND_REG_SRC_ADINR,
+	RSND_REG_SRC_IFSCR,
+	RSND_REG_SRC_IFSVR,
+	RSND_REG_SRC_SRCCR,
+	RSND_REG_SRC_MNFSR,
 
 	/* ADG */
 	RSND_REG_BRRA,
@@ -50,6 +57,9 @@ enum rsnd_reg {
 	RSND_REG_AUDIO_CLK_SEL0,
 	RSND_REG_AUDIO_CLK_SEL1,
 	RSND_REG_AUDIO_CLK_SEL2,
+	RSND_REG_AUDIO_CLK_SEL3,	/* for Gen1 */
+	RSND_REG_AUDIO_CLK_SEL4,	/* for Gen1 */
+	RSND_REG_AUDIO_CLK_SEL5,	/* for Gen1 */
 
 	/* SSI */
 	RSND_REG_SSICR,
@@ -227,6 +237,10 @@ int rsnd_adg_probe(struct platform_device *pdev,
 		   struct rsnd_priv *priv);
 void rsnd_adg_remove(struct platform_device *pdev,
 		   struct rsnd_priv *priv);
+int rsnd_adg_set_convert_clk(struct rsnd_priv *priv,
+			     struct rsnd_mod *mod,
+			     unsigned int src_rate,
+			     unsigned int dst_rate);
 
 /*
  *	R-Car sound priv
@@ -280,6 +294,10 @@ void rsnd_scu_remove(struct platform_device *pdev,
 		     struct rsnd_priv *priv);
 struct rsnd_mod *rsnd_scu_mod_get(struct rsnd_priv *priv, int id);
 bool rsnd_scu_hpbif_is_enable(struct rsnd_mod *mod);
+unsigned int rsnd_scu_get_ssi_rate(struct rsnd_priv *priv,
+				   struct rsnd_mod *ssi_mod,
+				   struct snd_pcm_runtime *runtime);
+
 #define rsnd_scu_nr(priv) ((priv)->scu_nr)
 
 /*
sound/soc/sh/rcar/scu.c +145 -7

255 lines not on this page · raw message

sound/soc/sh/rcar/ssi.c +1 -1
index 846bb5e..4b8cf7c 100644
@@ -200,7 +200,7 @@ static int rsnd_ssi_master_clk_start(struct rsnd_ssi *ssi,
 		1, 2, 4, 8, 16, 6, 12,
 	};
 	unsigned int main_rate;
-	unsigned int rate = runtime->rate;
+	unsigned int rate = rsnd_scu_get_ssi_rate(priv, &ssi->mod, runtime);
 
 	/*
 	 * Find best clock, and try to start ADG
Signature · 1 line
1.7.9.5
maintainer Applied
#11 lore raw
In reply to Kuninori Morimoto
Quoted 5 lines · Kuninori Morimoto

Hi Mark

These are cleanup and SRC support patches
for Renesas sound driver

I've applied all these but you really need to start moving this stuff over to use DPCM, this is getting to be very borderline.

#12 lore raw

Hi Mark

Quoted 5 lines
Quoted 2 lines

These are cleanup and SRC support patches
for Renesas sound driver

I've applied all these but you really need to start moving this stuff over to use DPCM, this is getting to be very borderline.

Thank you for your help.
I see, I will start moving it, but I need sample code for it. Who is using DPCM ?

Best regards
---
Kuninori Morimoto

maintainer
#13 lore raw
Quoted 6 lines · Kuninori Morimoto
Quoted 2 lines

I've applied all these but you really need to start moving this stuff over to use DPCM, this is getting to be very borderline.

Thank you for your help.
I see, I will start moving it, but I need sample code for it. Who is using DPCM ?

Nobody in tree unfortunately. The TI OMAP and Qualcomm production kernels use it as do some of the newer Intel Haswell chips but all of that is out of tree. There's also the work Russell has been doing for Kirkwood but I don't think he posted the finished version to the list yet (he's waiting for some fixes from Liam which will hopefully come soon).

#14 lore raw

Hi Mark

Quoted 10 lines
Quoted 3 lines

Thank you for your help.
I see, I will start moving it, but I need sample code for it. Who is using DPCM ?

Nobody in tree unfortunately. The TI OMAP and Qualcomm production kernels use it as do some of the newer Intel Haswell chips but all of that is out of tree. There's also the work Russell has been doing for Kirkwood but I don't think he posted the finished version to the list yet (he's waiting for some fixes from Liam which will hopefully come soon).

Hmm... OK I understood.
Do you think it is possible to get these out-of-tree codes from somewhere/somehow ?
I can work for DPCM support for our driver,
but it is very difficult for me without sample code...

If I could get sample code, and I finished my current task, I will start DPCM support. is it OK ?

Best regards
---
Kuninori Morimoto

#15 lore raw
Quoted 11 lines · On Mon, 06 Jan 2014 16:21:01 -0800 (PST) Kuninori Morimoto…
Quoted 10 lines
Quoted 3 lines

Thank you for your help.
I see, I will start moving it, but I need sample code for it. Who is using DPCM ?

Nobody in tree unfortunately. The TI OMAP and Qualcomm production kernels use it as do some of the newer Intel Haswell chips but all of that is out of tree. There's also the work Russell has been doing for Kirkwood but I don't think he posted the finished version to the list yet (he's waiting for some fixes from Liam which will hopefully come soon).

Quoted 8 lines

Hmm... OK I understood.
Do you think it is possible to get these out-of-tree codes from somewhere/somehow ?
I can work for DPCM support for our driver,
but it is very difficult for me without sample code...

If I could get sample code, and I finished my current task, I will start DPCM support. is it OK ?

Kuninori,

Last month I tried to use DPCM in the Cubox (kirkwood audio + nxp tda998x HDMI transmitter and S/PDIF), and, as your simple-card was not easy to extend, I proposed an other way to describe a DPCM audio system in DT:

http://mailman.alsa-project.org/pipermail/alsa-devel/2013-December/070594.html

and also:

http://mailman.alsa-project.org/pipermail/alsa-devel/2014-January/070634.html

In fact, DPCM just needs many DAI links, and a flag 'front-end' / 'back-end':

http://mailman.alsa-project.org/pipermail/alsa-devel/2014-January/070623.html

Actually, I added many DAI links to your simple-card and I am waiting for Xiubo's patches to be applied before proposing mine.

This will make the Cubox audio system work by selecting the I2S or S/PDIF PCM, but it will not be DPCM. The reason is that, with the actual DPCM, the sample rates and formats are the ones of the front-end, and not the subset of the ones of the DAIs in the sound route. I explained this problem in:

http://mailman.alsa-project.org/pipermail/alsa-devel/2013-December/070585.html

and it appears that some development is needed in the sound core to handle this Cubox case.

Coming back to a DPCM example, apart from adding the 'front-end' and 'back-end' flags in the DAI links, the changes were:

- add the global system playback DAI in the audio controller.

This DAI is the audio entry point (front-end). On audio open, the back-end DAIs are searched and started (snd_pcm_open). If there was a platform declared in the associated DAI links, the DMA open would be called many times, so

- don't set a platform pointer in the back-end DAI links.

That's all.

If you want more information, I may send you the patch I did for DPCM in the audio controller (kirkwood-i2s.c).

Signature · 6 lines
Ken ar c'hentañ	|	      ** Breizh ha Linux atav! **
Jef		|		http://moinejf.free.fr/
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
maintainer
#16 lore raw
In reply to Kuninori Morimoto
Quoted 3 lines · Kuninori Morimoto

Hmm... OK I understood.
Do you think it is possible to get these out-of-tree codes from somewhere/somehow ?

The Qualcomm stuff should be on codeaurora.org. I'm not 100% sure where the latest code is for anything else - the Galaxy Nexus code from Google should have a version of the DPCM support too.

Quoted 2 lines

If I could get sample code, and I finished my current task, I will start DPCM support. is it OK ?

Sure.