[alsa-devel] [PATCH 0/10] 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
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
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.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- sound/soc/sh/rcar/adg.c | 58 ++++++++++++++++++++--------------------------- 1 file changed, 24 insertions(+), 34 deletions(-)
diff --git a/sound/soc/sh/rcar/adg.c b/sound/soc/sh/rcar/adg.c index 9430097..55d0394 100644 --- a/sound/soc/sh/rcar/adg.c +++ b/sound/soc/sh/rcar/adg.c @@ -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; }
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
we can check rsnd_ssi_init(), not, rsnd_ssi_start()
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- sound/soc/sh/rcar/ssi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/sound/soc/sh/rcar/ssi.c b/sound/soc/sh/rcar/ssi.c index 85936ae..6b1f501 100644 --- a/sound/soc/sh/rcar/ssi.c +++ b/sound/soc/sh/rcar/ssi.c @@ -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];
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
Use correct register name which appears in the datasheet
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- 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(-)
diff --git a/sound/soc/sh/rcar/gen.c b/sound/soc/sh/rcar/gen.c index d0ab203..862758d 100644 --- a/sound/soc/sh/rcar/gen.c +++ b/sound/soc/sh/rcar/gen.c @@ -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), diff --git a/sound/soc/sh/rcar/rsnd.h b/sound/soc/sh/rcar/rsnd.h index bff7b9e..d5c0182 100644 --- a/sound/soc/sh/rcar/rsnd.h +++ b/sound/soc/sh/rcar/rsnd.h @@ -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, diff --git a/sound/soc/sh/rcar/scu.c b/sound/soc/sh/rcar/scu.c index fa8fa15..f18f45e 100644 --- a/sound/soc/sh/rcar/scu.c +++ b/sound/soc/sh/rcar/scu.c @@ -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; }
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
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.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- sound/soc/sh/rcar/adg.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/sound/soc/sh/rcar/adg.c b/sound/soc/sh/rcar/adg.c index 55d0394..2e71a7b 100644 --- a/sound/soc/sh/rcar/adg.c +++ b/sound/soc/sh/rcar/adg.c @@ -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; } }
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
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.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- sound/soc/sh/rcar/rsnd.h | 10 +++++----- sound/soc/sh/rcar/scu.c | 6 ++++-- 2 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/sound/soc/sh/rcar/rsnd.h b/sound/soc/sh/rcar/rsnd.h index d5c0182..a14bc92 100644 --- a/sound/soc/sh/rcar/rsnd.h +++ b/sound/soc/sh/rcar/rsnd.h @@ -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, diff --git a/sound/soc/sh/rcar/scu.c b/sound/soc/sh/rcar/scu.c index f18f45e..206e4cb 100644 --- a/sound/soc/sh/rcar/scu.c +++ b/sound/soc/sh/rcar/scu.c @@ -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;
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
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
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- sound/soc/sh/rcar/scu.c | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-)
diff --git a/sound/soc/sh/rcar/scu.c b/sound/soc/sh/rcar/scu.c index 206e4cb..4ac20f2 100644 --- a/sound/soc/sh/rcar/scu.c +++ b/sound/soc/sh/rcar/scu.c @@ -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;
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
INT_ENABLE is needed only Gen2. rsnd_mod_write() do nothing on Gen1, but it is confusable.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- sound/soc/sh/rcar/rsnd.h | 2 +- sound/soc/sh/rcar/ssi.c | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/sound/soc/sh/rcar/rsnd.h b/sound/soc/sh/rcar/rsnd.h index a14bc92..3774dfc 100644 --- a/sound/soc/sh/rcar/rsnd.h +++ b/sound/soc/sh/rcar/rsnd.h @@ -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 */ diff --git a/sound/soc/sh/rcar/ssi.c b/sound/soc/sh/rcar/ssi.c index 6b1f501..98a3de0 100644 --- a/sound/soc/sh/rcar/ssi.c +++ b/sound/soc/sh/rcar/ssi.c @@ -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);
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
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.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- sound/soc/sh/rcar/scu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/sound/soc/sh/rcar/scu.c b/sound/soc/sh/rcar/scu.c index 4ac20f2..fcc0a66 100644 --- a/sound/soc/sh/rcar/scu.c +++ b/sound/soc/sh/rcar/scu.c @@ -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;
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
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
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- sound/soc/sh/rcar/ssi.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/sound/soc/sh/rcar/ssi.c b/sound/soc/sh/rcar/ssi.c index 98a3de0..846bb5e 100644 --- a/sound/soc/sh/rcar/ssi.c +++ b/sound/soc/sh/rcar/ssi.c @@ -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); } }
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
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.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- 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(-)
diff --git a/include/sound/rcar_snd.h b/include/sound/rcar_snd.h index 8f639e0..6add6cc 100644 --- a/include/sound/rcar_snd.h +++ b/include/sound/rcar_snd.h @@ -57,6 +57,7 @@ struct rsnd_ssi_platform_info {
struct rsnd_scu_platform_info { u32 flags; + u32 convert_rate; /* sampling rate convert */ };
/* diff --git a/sound/soc/sh/rcar/adg.c b/sound/soc/sh/rcar/adg.c index 2e71a7b..a53235c 100644 --- a/sound/soc/sh/rcar/adg.c +++ b/sound/soc/sh/rcar/adg.c @@ -30,6 +30,79 @@ struct rsnd_adg { i++, (pos) = adg->clk[i]) #define rsnd_priv_to_adg(priv) ((struct rsnd_adg *)(priv)->adg)
+static int rsnd_adg_set_convert_clk_gen1(struct rsnd_priv *priv, + struct rsnd_mod *mod, + unsigned int src_rate, + unsigned int dst_rate) +{ + struct rsnd_adg *adg = rsnd_priv_to_adg(priv); + struct device *dev = rsnd_priv_to_dev(priv); + int idx, sel, div, shift; + u32 mask, val; + int id = rsnd_mod_id(mod); + unsigned int sel_rate [] = { + clk_get_rate(adg->clk[CLKA]), /* 000: CLKA */ + clk_get_rate(adg->clk[CLKB]), /* 001: CLKB */ + clk_get_rate(adg->clk[CLKC]), /* 010: CLKC */ + 0, /* 011: MLBCLK (not used) */ + adg->rbga_rate_for_441khz_div_6,/* 100: RBGA */ + adg->rbgb_rate_for_48khz_div_6, /* 101: RBGB */ + }; + + /* find div (= 1/128, 1/256, 1/512, 1/1024, 1/2048 */ + for (sel = 0; sel < ARRAY_SIZE(sel_rate); sel++) { + for (div = 128, idx = 0; + div <= 2048; + div *= 2, idx++) { + if (src_rate == sel_rate[sel] / div) { + val = (idx << 4) | sel; + goto find_rate; + } + } + } + dev_err(dev, "can't find convert src clk\n"); + return -EINVAL; + +find_rate: + shift = (id % 4) * 8; + mask = 0xFF << shift; + val = val << shift; + + dev_dbg(dev, "adg convert src clk = %02x\n", val); + + switch (id / 4) { + case 0: + rsnd_mod_bset(mod, AUDIO_CLK_SEL3, mask, val); + break; + case 1: + rsnd_mod_bset(mod, AUDIO_CLK_SEL4, mask, val); + break; + case 2: + rsnd_mod_bset(mod, AUDIO_CLK_SEL5, mask, val); + break; + } + + /* + * Gen1 doesn't need dst_rate settings, + * since it uses SSI WS pin. + * see also rsnd_src_set_route_if_gen1() + */ + + return 0; +} + +int rsnd_adg_set_convert_clk(struct rsnd_priv *priv, + struct rsnd_mod *mod, + unsigned int src_rate, + unsigned int dst_rate) +{ + if (rsnd_is_gen1(priv)) + return rsnd_adg_set_convert_clk_gen1(priv, mod, + src_rate, dst_rate); + + return -EINVAL; +} + static void rsnd_adg_set_ssi_clk(struct rsnd_mod *mod, u32 val) { int id = rsnd_mod_id(mod); diff --git a/sound/soc/sh/rcar/gen.c b/sound/soc/sh/rcar/gen.c index 862758d..add088b 100644 --- a/sound/soc/sh/rcar/gen.c +++ b/sound/soc/sh/rcar/gen.c @@ -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), diff --git a/sound/soc/sh/rcar/rsnd.h b/sound/soc/sh/rcar/rsnd.h index 3774dfc..4ca66cd 100644 --- a/sound/soc/sh/rcar/rsnd.h +++ b/sound/soc/sh/rcar/rsnd.h @@ -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)
/* diff --git a/sound/soc/sh/rcar/scu.c b/sound/soc/sh/rcar/scu.c index fcc0a66..9bb08bb 100644 --- a/sound/soc/sh/rcar/scu.c +++ b/sound/soc/sh/rcar/scu.c @@ -13,9 +13,13 @@ struct rsnd_scu { struct rsnd_scu_platform_info *info; /* rcar_snd.h */ struct rsnd_mod mod; + struct clk *clk; };
#define rsnd_scu_mode_flags(p) ((p)->info->flags) +#define rsnd_scu_convert_rate(p) ((p)->info->convert_rate) + +#define RSND_SCU_NAME_SIZE 16
/* * ADINR @@ -26,6 +30,15 @@ struct rsnd_scu { #define OTBL_18 (6 << 16) #define OTBL_16 (8 << 16)
+/* + * image of SRC (Sampling Rate Converter) + * + * 96kHz <-> +-----+ 48kHz +-----+ 48kHz +-------+ + * 48kHz <-> | SRC | <------> | SSI | <-----> | codec | + * 44.1kHz <-> +-----+ +-----+ +-------+ + * ... + * + */
#define rsnd_mod_to_scu(_mod) \ container_of((_mod), struct rsnd_scu, mod) @@ -56,7 +69,7 @@ static int rsnd_src_set_route_if_gen1(struct rsnd_priv *priv, { 0x3, 28, }, /* 7 */ { 0x3, 30, }, /* 8 */ }; - + struct rsnd_scu *scu = rsnd_mod_to_scu(mod); u32 mask; u32 val; int shift; @@ -86,9 +99,18 @@ static int rsnd_src_set_route_if_gen1(struct rsnd_priv *priv, */ shift = (id % 4) * 8; mask = 0x1F << shift; - if (8 == id) /* SRU8 is very special */ + + /* + * ADG is used as source clock if SRC was used, + * then, SSI WS is used as destination clock. + * SSI WS is used as source clock if SRC is not used + * (when playback, source/destination become reverse when capture) + */ + if (rsnd_scu_convert_rate(scu)) /* use ADG */ + val = 0; + else if (8 == id) /* use SSI WS, but SRU8 is special */ val = id << shift; - else + else /* use SSI WS */ val = (id + 1) << shift;
switch (id / 4) { @@ -106,14 +128,45 @@ static int rsnd_src_set_route_if_gen1(struct rsnd_priv *priv, return 0; }
-static int rsnd_scu_rate_ctrl(struct rsnd_priv *priv, +unsigned int rsnd_scu_get_ssi_rate(struct rsnd_priv *priv, + struct rsnd_mod *ssi_mod, + struct snd_pcm_runtime *runtime) +{ + struct rsnd_scu *scu; + unsigned int rate; + + /* this function is assuming SSI id = SCU id here */ + scu = rsnd_mod_to_scu(rsnd_scu_mod_get(priv, rsnd_mod_id(ssi_mod))); + + /* + * return convert rate if SRC is used, + * otherwise, return runtime->rate as usual + */ + rate = rsnd_scu_convert_rate(scu); + if (!rate) + rate = runtime->rate; + + return rate; +} + +static int rsnd_scu_convert_rate_ctrl(struct rsnd_priv *priv, struct rsnd_mod *mod, struct rsnd_dai *rdai, struct rsnd_dai_stream *io) { struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); + struct rsnd_scu *scu = rsnd_mod_to_scu(mod); + u32 convert_rate = rsnd_scu_convert_rate(scu); u32 adinr = runtime->channels;
+ /* set/clear soft reset */ + rsnd_mod_write(mod, SRC_SWRSR, 0); + rsnd_mod_write(mod, SRC_SWRSR, 1); + + /* Initialize the operation of the SRC internal circuits */ + rsnd_mod_write(mod, SRC_SRCIR, 1); + + /* Set channel number and output bit length */ switch (runtime->sample_bits) { case 16: adinr |= OTBL_16; @@ -124,9 +177,42 @@ static int rsnd_scu_rate_ctrl(struct rsnd_priv *priv, default: return -EIO; } - rsnd_mod_write(mod, SRC_ADINR, adinr);
+ if (convert_rate) { + u32 fsrate = 0x0400000 / convert_rate * runtime->rate; + int ret; + + /* Enable the initial value of IFS */ + rsnd_mod_write(mod, SRC_IFSCR, 1); + + /* Set initial value of IFS */ + rsnd_mod_write(mod, SRC_IFSVR, fsrate); + + /* Select SRC mode (fixed value) */ + rsnd_mod_write(mod, SRC_SRCCR, 0x00010110); + + /* Set the restriction value of the FS ratio (98%) */ + rsnd_mod_write(mod, SRC_MNFSR, fsrate / 100 * 98); + + if (rsnd_is_gen1(priv)) { + /* no SRC_BFSSR settings, since SRC_SRCCR::BUFMD is 0 */ + } + + /* set convert clock */ + ret = rsnd_adg_set_convert_clk(priv, mod, + runtime->rate, + convert_rate); + if (ret < 0) + return ret; + } + + /* Cancel the initialization and operate the SRC function */ + rsnd_mod_write(mod, SRC_SRCIR, 0); + + /* use DMA transfer */ + rsnd_mod_write(mod, BUSIF_MODE, 1); + return 0; }
@@ -135,6 +221,7 @@ static int rsnd_scu_transfer_start(struct rsnd_priv *priv, struct rsnd_dai *rdai, struct rsnd_dai_stream *io) { + struct rsnd_scu *scu = rsnd_mod_to_scu(mod); int id = rsnd_mod_id(mod); u32 val;
@@ -143,7 +230,28 @@ static int rsnd_scu_transfer_start(struct rsnd_priv *priv, rsnd_mod_bset(mod, SRC_ROUTE_CTRL, val, val); }
- rsnd_mod_write(mod, BUSIF_MODE, 1); + if (rsnd_scu_convert_rate(scu)) + rsnd_mod_write(mod, SRC_ROUTE_MODE0, 1); + + return 0; +} + +static int rsnd_scu_transfer_stop(struct rsnd_priv *priv, + struct rsnd_mod *mod, + struct rsnd_dai *rdai, + struct rsnd_dai_stream *io) +{ + struct rsnd_scu *scu = rsnd_mod_to_scu(mod); + int id = rsnd_mod_id(mod); + u32 mask; + + if (rsnd_is_gen1(priv)) { + mask = (1 << id); + rsnd_mod_bset(mod, SRC_ROUTE_CTRL, mask, 0); + } + + if (rsnd_scu_convert_rate(scu)) + rsnd_mod_write(mod, SRC_ROUTE_MODE0, 0);
return 0; } @@ -161,6 +269,7 @@ static int rsnd_scu_start(struct rsnd_mod *mod, struct rsnd_dai_stream *io) { struct rsnd_priv *priv = rsnd_mod_to_priv(mod); + struct rsnd_scu *scu = rsnd_mod_to_scu(mod); struct device *dev = rsnd_priv_to_dev(priv); int ret;
@@ -175,13 +284,15 @@ static int rsnd_scu_start(struct rsnd_mod *mod, return 0; }
+ clk_enable(scu->clk); + /* it use DMA transter */
ret = rsnd_src_set_route_if_gen1(priv, mod, rdai, io); if (ret < 0) return ret;
- ret = rsnd_scu_rate_ctrl(priv, mod, rdai, io); + ret = rsnd_scu_convert_rate_ctrl(priv, mod, rdai, io); if (ret < 0) return ret;
@@ -194,9 +305,27 @@ static int rsnd_scu_start(struct rsnd_mod *mod, return 0; }
+static int rsnd_scu_stop(struct rsnd_mod *mod, + struct rsnd_dai *rdai, + struct rsnd_dai_stream *io) +{ + struct rsnd_priv *priv = rsnd_mod_to_priv(mod); + struct rsnd_scu *scu = rsnd_mod_to_scu(mod); + + if (!rsnd_scu_hpbif_is_enable(mod)) + return 0; + + rsnd_scu_transfer_stop(priv, mod, rdai, io); + + clk_disable(scu->clk); + + return 0; +} + static struct rsnd_mod_ops rsnd_scu_ops = { .name = "scu", .start = rsnd_scu_start, + .stop = rsnd_scu_stop, };
struct rsnd_mod *rsnd_scu_mod_get(struct rsnd_priv *priv, int id) @@ -213,6 +342,8 @@ int rsnd_scu_probe(struct platform_device *pdev, { struct device *dev = rsnd_priv_to_dev(priv); struct rsnd_scu *scu; + struct clk *clk; + char name[RSND_SCU_NAME_SIZE]; int i, nr;
/* @@ -229,9 +360,16 @@ int rsnd_scu_probe(struct platform_device *pdev, priv->scu = scu;
for_each_rsnd_scu(scu, priv, i) { + snprintf(name, RSND_SCU_NAME_SIZE, "scu.%d", i); + + clk = devm_clk_get(dev, name); + if (IS_ERR(clk)) + return PTR_ERR(clk); + rsnd_mod_init(priv, &scu->mod, &rsnd_scu_ops, i); scu->info = &info->scu_info[i]; + scu->clk = clk;
dev_dbg(dev, "SCU%d probed\n", i); } diff --git a/sound/soc/sh/rcar/ssi.c b/sound/soc/sh/rcar/ssi.c index 846bb5e..4b8cf7c 100644 --- a/sound/soc/sh/rcar/ssi.c +++ b/sound/soc/sh/rcar/ssi.c @@ -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
On Thu, Dec 19, 2013 at 07:25:41PM -0800, Kuninori Morimoto wrote:
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.
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.
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
On Sun, Jan 05, 2014 at 09:29:27PM -0800, Kuninori Morimoto wrote:
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).
Hi Mark
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
On Mon, 06 Jan 2014 16:21:01 -0800 (PST) Kuninori Morimoto kuninori.morimoto.gx@gmail.com wrote:
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 ?
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.ht...
and also:
http://mailman.alsa-project.org/pipermail/alsa-devel/2014-January/070634.htm...
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.htm...
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.ht...
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).
On Mon, Jan 06, 2014 at 04:21:01PM -0800, Kuninori Morimoto wrote:
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.
If I could get sample code, and I finished my current task, I will start DPCM support. is it OK ?
Sure.
participants (3)
-
Jean-Francois Moine
-
Kuninori Morimoto
-
Mark Brown