All of lore.kernel.org
 help / color / mirror / Atom feed
From: biju.das@bp.renesas.com (Biju Das)
To: cip-dev@lists.cip-project.org
Subject: [cip-dev] [PATCH 4.19.y-cip 40/57] ASoC: rsnd: update BSDSR/BSDISR handling
Date: Thu, 17 Oct 2019 08:05:12 +0100	[thread overview]
Message-ID: <1571295929-47286-41-git-send-email-biju.das@bp.renesas.com> (raw)
In-Reply-To: <1571295929-47286-1-git-send-email-biju.das@bp.renesas.com>

From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>

commit 7674bec4fc09e85803a8f2bd26a013d0076a80a9 upstream.

Current BSDSR/BSDISR are using temporary/generic settings, but it can't
handle all SRCx/SoC. It needs to handle correctry.
Otherwise, sampling rate converted sound channel will be broken if it
was TDM. One note is that it needs to overwrite settings on E3 case.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Tested-by: chaoliang qin <chaoliang.qin.jg@renesas.com>
Tested-by: Yusuke Goda <yusuke.goda.sx@renesas.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Biju Das <biju.das@bp.renesas.com>
---
 sound/soc/sh/rcar/src.c | 125 ++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 115 insertions(+), 10 deletions(-)

diff --git a/sound/soc/sh/rcar/src.c b/sound/soc/sh/rcar/src.c
index 50348a2..db81e06 100644
--- a/sound/soc/sh/rcar/src.c
+++ b/sound/soc/sh/rcar/src.c
@@ -14,6 +14,7 @@
  */
 
 #include "rsnd.h"
+#include <linux/sys_soc.h>
 
 #define SRC_NAME "src"
 
@@ -134,20 +135,83 @@ unsigned int rsnd_src_get_rate(struct rsnd_priv *priv,
 	return rate;
 }
 
+const static u32 bsdsr_table_pattern1[] = {
+	0x01800000, /* 6 - 1/6 */
+	0x01000000, /* 6 - 1/4 */
+	0x00c00000, /* 6 - 1/3 */
+	0x00800000, /* 6 - 1/2 */
+	0x00600000, /* 6 - 2/3 */
+	0x00400000, /* 6 - 1   */
+};
+
+const static u32 bsdsr_table_pattern2[] = {
+	0x02400000, /* 6 - 1/6 */
+	0x01800000, /* 6 - 1/4 */
+	0x01200000, /* 6 - 1/3 */
+	0x00c00000, /* 6 - 1/2 */
+	0x00900000, /* 6 - 2/3 */
+	0x00600000, /* 6 - 1   */
+};
+
+const static u32 bsisr_table[] = {
+	0x00100060, /* 6 - 1/6 */
+	0x00100040, /* 6 - 1/4 */
+	0x00100030, /* 6 - 1/3 */
+	0x00100020, /* 6 - 1/2 */
+	0x00100020, /* 6 - 2/3 */
+	0x00100020, /* 6 - 1   */
+};
+
+const static u32 chan288888[] = {
+	0x00000006, /* 1 to 2 */
+	0x000001fe, /* 1 to 8 */
+	0x000001fe, /* 1 to 8 */
+	0x000001fe, /* 1 to 8 */
+	0x000001fe, /* 1 to 8 */
+	0x000001fe, /* 1 to 8 */
+};
+
+const static u32 chan244888[] = {
+	0x00000006, /* 1 to 2 */
+	0x0000001e, /* 1 to 4 */
+	0x0000001e, /* 1 to 4 */
+	0x000001fe, /* 1 to 8 */
+	0x000001fe, /* 1 to 8 */
+	0x000001fe, /* 1 to 8 */
+};
+
+const static u32 chan222222[] = {
+	0x00000006, /* 1 to 2 */
+	0x00000006, /* 1 to 2 */
+	0x00000006, /* 1 to 2 */
+	0x00000006, /* 1 to 2 */
+	0x00000006, /* 1 to 2 */
+	0x00000006, /* 1 to 2 */
+};
+
+static const struct soc_device_attribute ov_soc[] = {
+	{ .soc_id = "r8a77990" }, /* E3 */
+	{ /* sentinel */ }
+};
+
 static void rsnd_src_set_convert_rate(struct rsnd_dai_stream *io,
 				      struct rsnd_mod *mod)
 {
 	struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
 	struct device *dev = rsnd_priv_to_dev(priv);
 	struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
+	const struct soc_device_attribute *soc = soc_device_match(ov_soc);
 	int is_play = rsnd_io_is_play(io);
 	int use_src = 0;
 	u32 fin, fout;
 	u32 ifscr, fsrate, adinr;
 	u32 cr, route;
-	u32 bsdsr, bsisr;
 	u32 i_busif, o_busif, tmp;
+	const u32 *bsdsr_table;
+	const u32 *chptn;
 	uint ratio;
+	int chan;
+	int idx;
 
 	if (!runtime)
 		return;
@@ -155,6 +219,8 @@ static void rsnd_src_set_convert_rate(struct rsnd_dai_stream *io,
 	fin  = rsnd_src_get_in_rate(priv, io);
 	fout = rsnd_src_get_out_rate(priv, io);
 
+	chan = rsnd_runtime_channel_original(io);
+
 	/* 6 - 1/6 are very enough ratio for SRC_BSDSR */
 	if (fin == fout)
 		ratio = 0;
@@ -173,8 +239,7 @@ static void rsnd_src_set_convert_rate(struct rsnd_dai_stream *io,
 	/*
 	 * SRC_ADINR
 	 */
-	adinr = rsnd_get_adinr_bit(mod, io) |
-		rsnd_runtime_channel_original(io);
+	adinr = rsnd_get_adinr_bit(mod, io) | chan;
 
 	/*
 	 * SRC_IFSCR / SRC_IFSVR
@@ -207,21 +272,56 @@ static void rsnd_src_set_convert_rate(struct rsnd_dai_stream *io,
 
 	/*
 	 * SRC_BSDSR / SRC_BSISR
+	 *
+	 * see
+	 *	Combination of Register Setting Related to
+	 *	FSO/FSI Ratio and Channel, Latency
 	 */
 	switch (rsnd_mod_id(mod)) {
+	case 0:
+		chptn		= chan288888;
+		bsdsr_table	= bsdsr_table_pattern1;
+		break;
+	case 1:
+	case 3:
+	case 4:
+		chptn		= chan244888;
+		bsdsr_table	= bsdsr_table_pattern1;
+		break;
+	case 2:
+	case 9:
+		chptn		= chan222222;
+		bsdsr_table	= bsdsr_table_pattern1;
+		break;
 	case 5:
 	case 6:
 	case 7:
 	case 8:
-		bsdsr = 0x02400000; /* 6 - 1/6 */
-		bsisr = 0x00100060; /* 6 - 1/6 */
+		chptn		= chan222222;
+		bsdsr_table	= bsdsr_table_pattern2;
 		break;
 	default:
-		bsdsr = 0x01800000; /* 6 - 1/6 */
-		bsisr = 0x00100060 ;/* 6 - 1/6 */
-		break;
+		goto convert_rate_err;
 	}
 
+	/*
+	 * E3 need to overwrite
+	 */
+	if (soc)
+		switch (rsnd_mod_id(mod)) {
+		case 0:
+		case 4:
+			chptn	= chan222222;
+		}
+
+	for (idx = 0; idx < ARRAY_SIZE(chan222222); idx++)
+		if (chptn[idx] & (1 << chan))
+			break;
+
+	if (chan > 8 ||
+	    idx >= ARRAY_SIZE(chan222222))
+		goto convert_rate_err;
+
 	/* BUSIF_MODE */
 	tmp = rsnd_get_busif_shift(io, mod);
 	i_busif = ( is_play ? tmp : 0) | 1;
@@ -234,8 +334,8 @@ static void rsnd_src_set_convert_rate(struct rsnd_dai_stream *io,
 	rsnd_mod_write(mod, SRC_IFSCR, ifscr);
 	rsnd_mod_write(mod, SRC_IFSVR, fsrate);
 	rsnd_mod_write(mod, SRC_SRCCR, cr);
-	rsnd_mod_write(mod, SRC_BSDSR, bsdsr);
-	rsnd_mod_write(mod, SRC_BSISR, bsisr);
+	rsnd_mod_write(mod, SRC_BSDSR, bsdsr_table[idx]);
+	rsnd_mod_write(mod, SRC_BSISR, bsisr_table[idx]);
 	rsnd_mod_write(mod, SRC_SRCIR, 0);	/* cancel initialize */
 
 	rsnd_mod_write(mod, SRC_I_BUSIF_MODE, i_busif);
@@ -244,6 +344,11 @@ static void rsnd_src_set_convert_rate(struct rsnd_dai_stream *io,
 	rsnd_mod_write(mod, SRC_BUSIF_DALIGN, rsnd_get_dalign(mod, io));
 
 	rsnd_adg_set_src_timesel_gen2(mod, io, fin, fout);
+
+	return;
+
+convert_rate_err:
+	dev_err(dev, "unknown BSDSR/BSDIR settings\n");
 }
 
 static int rsnd_src_irq(struct rsnd_mod *mod,
-- 
2.7.4

  parent reply	other threads:[~2019-10-17  7:05 UTC|newest]

Thread overview: 106+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-17  7:04 [cip-dev] [PATCH 4.19.y-cip 00/57] Audio improvements/SSIU BUSIF/ Biju Das
2019-10-17  7:04 ` [cip-dev] [PATCH 4.19.y-cip 01/57] ASoC: rsnd: add warning message to rsnd_kctrl_accept_runtime() Biju Das
2019-10-17  7:04 ` [cip-dev] [PATCH 4.19.y-cip 02/57] ASoC: rsnd: add support for 16/24 bit slot widths Biju Das
2019-10-17  7:04 ` [cip-dev] [PATCH 4.19.y-cip 03/57] ASoC: rsnd: add support for 8 bit S8 format Biju Das
2019-10-17  7:04 ` [cip-dev] [PATCH 4.19.y-cip 04/57] ASoC: rsnd: remove is_play parameter from hw_rule function Biju Das
2019-10-17  7:04 ` [cip-dev] [PATCH 4.19.y-cip 05/57] ASoC: rsnd: ssi: Fix issue in dma data address assignment Biju Das
2019-10-17  7:04 ` [cip-dev] [PATCH 4.19.y-cip 06/57] ASoC: rsnd: ssi: Check runtime channel number rather than hw_params Biju Das
2019-10-20  9:12   ` Pavel Machek
2019-10-21 12:10     ` Biju Das
2019-10-17  7:04 ` [cip-dev] [PATCH 4.19.y-cip 07/57] ASoc: rsnd: dma: Calculate dma address with consider of BUSIF Biju Das
2019-10-17  7:04 ` [cip-dev] [PATCH 4.19.y-cip 08/57] ASoc: rsnd: dma: Calculate PDMACHCRE " Biju Das
2019-10-17  7:04 ` [cip-dev] [PATCH 4.19.y-cip 09/57] ASoC: rsnd: ssiu: Support BUSIF other than BUSIF0 Biju Das
2019-10-17  7:04 ` [cip-dev] [PATCH 4.19.y-cip 10/57] ASoC: rsnd: ssiu: Support to init different BUSIF instance Biju Das
2019-10-17  7:04 ` [cip-dev] [PATCH 4.19.y-cip 11/57] ASoC: rsnd: merge .nolock_start and .prepare Biju Das
2019-10-17  7:04 ` [cip-dev] [PATCH 4.19.y-cip 12/57] ASoC: rsnd: gen: use tab instead of white-space Biju Das
2019-10-20  9:22   ` Pavel Machek
2019-10-21 12:12     ` Biju Das
2019-10-17  7:04 ` [cip-dev] [PATCH 4.19.y-cip 13/57] ASoC: rsnd: don't use %p for dev_dbg() Biju Das
2019-10-20  9:27   ` Pavel Machek
2019-10-21 12:17     ` Biju Das
2019-10-17  7:04 ` [cip-dev] [PATCH 4.19.y-cip 14/57] ASoC: add for_each_rtd_codec_dai() macro Biju Das
2019-10-20  9:36   ` Pavel Machek
2019-10-21 12:18     ` Biju Das
2019-10-17  7:04 ` [cip-dev] [PATCH 4.19.y-cip 15/57] ASoC: convert for_each_rtd_codec_dai() for missing part Biju Das
2019-10-20  9:41   ` Pavel Machek
2019-10-21 12:22     ` Biju Das
2019-10-23  1:20       ` Kuninori Morimoto
2019-10-23  6:47         ` Biju Das
2019-10-17  7:04 ` [cip-dev] [PATCH 4.19.y-cip 16/57] ASoC: add for_each_dpcm_fe() macro Biju Das
2019-10-20  9:48   ` Pavel Machek
2019-10-21 12:26     ` Biju Das
2019-10-23  1:28       ` Kuninori Morimoto
2019-11-18 15:30         ` Pavel Machek
2019-11-19  1:24           ` Kuninori Morimoto
2019-10-17  7:04 ` [cip-dev] [PATCH 4.19.y-cip 17/57] ASoC: add for_each_dpcm_be() macro Biju Das
2019-10-17  7:04 ` [cip-dev] [PATCH 4.19.y-cip 18/57] ASoC: rsnd: fixup SSI clock during suspend/resume modes Biju Das
2019-10-17  7:04 ` [cip-dev] [PATCH 4.19.y-cip 19/57] ASoC: rsnd: use 32bit TDM width as default Biju Das
2019-10-20  9:49   ` Pavel Machek
2019-10-21 13:54     ` Biju Das
2019-10-23  1:45       ` Kuninori Morimoto
2019-11-18 15:32         ` Pavel Machek
2019-11-19  0:53           ` Kuninori Morimoto
2019-10-17  7:04 ` [cip-dev] [PATCH 4.19.y-cip 20/57] ASoC: rsnd: enable TDM settings for SSI parent Biju Das
2019-10-17  7:04 ` [cip-dev] [PATCH 4.19.y-cip 21/57] ASoC: rsnd: tidyup SSICR::SWSP for TDM Biju Das
2019-10-17  7:04 ` [cip-dev] [PATCH 4.19.y-cip 22/57] ASoC: rsnd: move .get_status under rsnd_mod_ops Biju Das
2019-10-17  7:04 ` [cip-dev] [PATCH 4.19.y-cip 23/57] ASoC: rsnd: add .get_id/.get_id_sub Biju Das
2019-10-17  7:04 ` [cip-dev] [PATCH 4.19.y-cip 24/57] ASoC: rsnd: rsnd_mod_name() handles both name and ID Biju Das
2019-10-20 10:34   ` Pavel Machek
2019-10-21 13:26     ` Biju Das
2019-11-18 15:34       ` Pavel Machek
2019-11-18 15:41         ` Biju Das
2019-11-19  1:03           ` Kuninori Morimoto
2019-10-17  7:04 ` [cip-dev] [PATCH 4.19.y-cip 25/57] ASoC: rsnd: remove endpoint bidirectional check Biju Das
2019-10-20 10:38   ` Pavel Machek
2019-10-21 13:40     ` Biju Das
2019-10-23  1:38       ` Kuninori Morimoto
2019-10-17  7:04 ` [cip-dev] [PATCH 4.19.y-cip 26/57] ASoC: rsnd: rename rsnd_runtime_is_ssi_xxx() Biju Das
2019-10-17  7:04 ` [cip-dev] [PATCH 4.19.y-cip 27/57] ASoC: rsnd: use defined io_playback/io_capture Biju Das
2019-10-17  7:05 ` [cip-dev] [PATCH 4.19.y-cip 28/57] ASoC: rsnd: move HDMI information from ssi.c to core.c Biju Das
2019-10-20 10:40   ` Pavel Machek
2019-10-21 13:48     ` Biju Das
2019-10-17  7:05 ` [cip-dev] [PATCH 4.19.y-cip 29/57] ASoC: rsnd: handle DPCM converted rate/chan under core Biju Das
2019-10-17  7:05 ` [cip-dev] [PATCH 4.19.y-cip 30/57] ASoC: rsnd: add SSIU BUSIF support Biju Das
2019-10-20 10:50   ` Pavel Machek
2019-10-21 13:46     ` Biju Das
2019-10-17  7:05 ` [cip-dev] [PATCH 4.19.y-cip 31/57] ASoC: rsnd: add TDM Split mode support Biju Das
2019-10-17  7:05 ` [cip-dev] [PATCH 4.19.y-cip 32/57] ASoC: rsnd: use ring buffer for rsnd_mod_name() Biju Das
2019-10-20 10:54   ` Pavel Machek
2019-10-21 13:50     ` Biju Das
2019-10-17  7:05 ` [cip-dev] [PATCH 4.19.y-cip 33/57] ASoC: rsnd: tidyup rsnd_parse_connect_ssiu_compatible() Biju Das
2019-10-17  7:05 ` [cip-dev] [PATCH 4.19.y-cip 34/57] ASoC: rsnd: makes rsnd_ssi_is_dma_mode() static Biju Das
2019-10-17  7:05 ` [cip-dev] [PATCH 4.19.y-cip 35/57] ASoC: rsnd: tidyup registering method for rsnd_kctrl_new() Biju Das
2019-10-17  7:05 ` [cip-dev] [PATCH 4.19.y-cip 36/57] ASoC: rsnd: indicates Channel and Mode for debug Biju Das
2019-10-17  7:05 ` [cip-dev] [PATCH 4.19.y-cip 37/57] ASoC: rsnd: fixup mod ID for CTU regmap read/write Biju Das
2019-10-17  7:05 ` [cip-dev] [PATCH 4.19.y-cip 38/57] ASoC: rsnd: add missing TDM Split mode support for simple-card Biju Das
2019-10-17  7:05 ` [cip-dev] [PATCH 4.19.y-cip 39/57] ASoC: rsnd: remove RSND_REG_ from rsnd_reg Biju Das
2019-10-25 12:03   ` Pavel Machek
2019-10-28  0:36     ` Kuninori Morimoto
2019-10-17  7:05 ` Biju Das [this message]
2019-10-27  7:33   ` [cip-dev] [PATCH 4.19.y-cip 40/57] ASoC: rsnd: update BSDSR/BSDISR handling Pavel Machek
2019-10-17  7:05 ` [cip-dev] [PATCH 4.19.y-cip 41/57] ASoC: rsnd: fixup MIX kctrl registration Biju Das
2019-10-17  7:05 ` [cip-dev] [PATCH 4.19.y-cip 42/57] ASoC: rsnd: synchronize connection check for simple-card/audio-graph Biju Das
2019-10-17  7:05 ` [cip-dev] [PATCH 4.19.y-cip 43/57] ASoC: rsnd: fixup TDM Split mode check for CTU Biju Das
2019-10-17  7:05 ` [cip-dev] [PATCH 4.19.y-cip 44/57] ASoC: sh: Avoid passing NULL to memory allocators Biju Das
2019-10-17  7:05 ` [cip-dev] [PATCH 4.19.y-cip 45/57] ASoC: sh: Drop superfluous PCM preallocation error checks Biju Das
2019-10-17  7:05 ` [cip-dev] [PATCH 4.19.y-cip 46/57] ASoC: rsnd: ssiu: correct shift bit for ssiu9 Biju Das
2019-10-17  7:05 ` [cip-dev] [PATCH 4.19.y-cip 47/57] ASoC: rsnd: gen: fix SSI9 4/5/6/7 busif related register address Biju Das
2019-10-17  7:05 ` [cip-dev] [PATCH 4.19.y-cip 48/57] ASoC: rsnd: src: Avoid a potential deadlock Biju Das
2019-10-27  7:45   ` Pavel Machek
2019-10-17  7:05 ` [cip-dev] [PATCH 4.19.y-cip 49/57] ASoC: rsnd: src: fix compiler warnings Biju Das
2019-10-27  7:47   ` Pavel Machek
2019-10-17  7:05 ` [cip-dev] [PATCH 4.19.y-cip 50/57] ASoC: rsnd: fixup 6ch settings to 8ch Biju Das
2019-10-27  7:51   ` Pavel Machek
2019-10-28  0:43     ` Kuninori Morimoto
2019-10-17  7:05 ` [cip-dev] [PATCH 4.19.y-cip 51/57] ASoC: rsnd: move pcm_new from snd_soc_component_driver to snd_soc_dai_driver Biju Das
2019-10-17  7:05 ` [cip-dev] [PATCH 4.19.y-cip 52/57] ASoC: rsnd: fixup mod ID calculation in rsnd_ctu_probe_ Biju Das
2019-10-27  7:56   ` Pavel Machek
2019-10-17  7:05 ` [cip-dev] [PATCH 4.19.y-cip 53/57] ASoC: rsnd: ssiu: tidyup SSI_MODE1/2 settings Biju Das
2019-10-17  7:05 ` [cip-dev] [PATCH 4.19.y-cip 54/57] ASoC: rsnd: add missing pin sharing with SSI9 Biju Das
2019-10-17  7:05 ` [cip-dev] [PATCH 4.19.y-cip 55/57] ASoC: rsnd: Support hw_free() callback at DAI level Biju Das
2019-10-17  7:05 ` [cip-dev] [PATCH 4.19.y-cip 56/57] ASoC: rsnd: do error check after rsnd_channel_normalization() Biju Das
2019-10-17  7:05 ` [cip-dev] [PATCH 4.19.y-cip 57/57] arm64: dts: renesas: r8a774a1: Add SSIU support for sound Biju Das
2019-10-18 21:49 ` [cip-dev] [PATCH 4.19.y-cip 00/57] Audio improvements/SSIU BUSIF/ Pavel Machek
2019-11-14 16:20 ` Biju Das
2019-11-15 21:46   ` Pavel Machek
2019-11-18  7:43     ` Biju Das

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1571295929-47286-41-git-send-email-biju.das@bp.renesas.com \
    --to=biju.das@bp.renesas.com \
    --cc=cip-dev@lists.cip-project.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.