Skip to contentSkip to conversation

ASoC: fsi: Add FIFO size calculate

PATCH In review Kuninori Morimoto 3 participants 6 messages Mar 25, 2010 – Mar 29, 2010

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

PATCH v2 2/4 ASoC: fsi: Add FIFO size calculate

---
v1 -> v2

o move calculate area to fsi_fifo_init
o modify fifo calculation way
o Add tiny document for fifo calculation

 sound/soc/sh/fsi.c |   70 ++++++++++++++++++++++++++++++++--------------------
 1 files changed, 43 insertions(+), 27 deletions(-)
sound/soc/sh/fsi.c +43 -27
index 7c295df..ae88865 100644
@@ -46,8 +46,9 @@
 #define MUTE		0x020C
 #define CLK_RST		0x0210
 #define SOFT_RST	0x0214
+#define FIFO_SZ		0x0218
 #define MREG_START	INT_ST
-#define MREG_END	SOFT_RST
+#define MREG_END	FIFO_SZ
 
 /* DO_FMT */
 /* DI_FMT */
@@ -85,6 +86,11 @@
 #define IR		(1 <<  4) /* Interrupt Reset */
 #define FSISR		(1 <<  0) /* Software Reset */
 
+/* FIFO_SZ */
+#define OUT_SZ_MASK	0x7
+#define BO_SZ_SHIFT	8
+#define AO_SZ_SHIFT	0
+
 #define FSI_RATES SNDRV_PCM_RATE_8000_96000
 
 #define FSI_FMTS (SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S16_LE)
@@ -384,9 +390,42 @@ static void fsi_clk_ctrl(struct fsi_priv *fsi, int enable)
 		fsi_master_mask_set(master, CLK_RST, val, 0);
 }
 
-static void fsi_fifo_init(struct fsi_priv *fsi, int is_play)
+static void fsi_fifo_init(struct fsi_priv *fsi,
+			  int is_play,
+			  struct snd_soc_dai *dai)
 {
-	u32 ctrl;
+	struct fsi_master *master = fsi_get_master(fsi);
+	u32 ctrl, shift, i;
+
+	/* get on-chip RAM capacity */
+	shift = fsi_master_read(master, FIFO_SZ);
+	shift >>= fsi_is_port_a(fsi) ? AO_SZ_SHIFT : BO_SZ_SHIFT;
+	shift &= OUT_SZ_MASK;
+	fsi->fifo_max = 256 << shift;
+	dev_dbg(dai->dev, "fifo = %d words\n", fsi->fifo_max);
+
+	/*
+	 * The maximum number of sample data varies depending
+	 * on the number of channels selected for the format.
+	 *
+	 * FIFOs are used in 4-channel units in 3-channel mode
+	 * and in 8-channel units in 5- to 7-channel mode
+	 * meaning that more FIFOs than the required size of DPRAM
+	 * are used.
+	 *
+	 * ex) if 256 words of DP-RAM is connected
+	 * 1 channel:  256 (256 x 1 = 256)
+	 * 2 channels: 128 (128 x 2 = 256)
+	 * 3 channels:  64 ( 64 x 3 = 192)
+	 * 4 channels:  64 ( 64 x 4 = 256)
+	 * 5 channels:  32 ( 32 x 5 = 160)
+	 * 6 channels:  32 ( 32 x 6 = 192)
+	 * 7 channels:  32 ( 32 x 7 = 224)
+	 * 8 channels:  32 ( 32 x 8 = 256)
+	 */
+	for (i = 1; i < fsi->chan; i <<= 1)
+		fsi->fifo_max >>= 1;
+	dev_dbg(dai->dev, "%d channel %d store\n", fsi->chan, fsi->fifo_max);
 
 	ctrl = is_play ? DOFF_CTL : DIFF_CTL;
 
@@ -689,29 +728,6 @@ static int fsi_dai_startup(struct snd_pcm_substream *substream,
 		dev_err(dai->dev, "unknown format.\n");
 		return -EINVAL;
 	}
-
-	switch (fsi->chan) {
-	case 1:
-		fsi->fifo_max = 256;
-		break;
-	case 2:
-		fsi->fifo_max = 128;
-		break;
-	case 3:
-	case 4:
-		fsi->fifo_max = 64;
-		break;
-	case 5:
-	case 6:
-	case 7:
-	case 8:
-		fsi->fifo_max = 32;
-		break;
-	default:
-		dev_err(dai->dev, "channel size error.\n");
-		return -EINVAL;
-	}
-
 	fsi_reg_write(fsi, reg, data);
 
 	/*
@@ -725,7 +741,7 @@ static int fsi_dai_startup(struct snd_pcm_substream *substream,
 	fsi_irq_clear_status(fsi);
 
 	/* fifo init */
-	fsi_fifo_init(fsi, is_play);
+	fsi_fifo_init(fsi, is_play, dai);
 
 	return ret;
 }
Signature · 1 line
1.6.3.3
Acked-by on v2 2/4
#1 lore raw
Quoted 10 lines · Kuninori Morimoto

---
v1 -> v2

o move calculate area to fsi_fifo_init
o modify fifo calculation way
o Add tiny document for fifo calculation

 sound/soc/sh/fsi.c |   70 ++++++++++++++++++++++++++++++++--------------------
 1 files changed, 43 insertions(+), 27 deletions(-)

Both 2/4 and 4/4

Signature · 3 lines
Freelance Developer, SlimLogic Ltd
ASoC and Voltage Regulator Maintainer.
http://www.slimlogic.co.uk
#2 lore raw
In reply to Kuninori Morimoto
Quoted 7 lines · Kuninori Morimoto

---
v1 -> v2

o move calculate area to fsi_fifo_init
o modify fifo calculation way
o Add tiny document for fifo calculation

This patch is fine but it doesn't apply against for-2.6.35. Could you please check and resubmit? I suspect a collision with the previously applied patches.

#3 lore raw

Dear Mark

Thank you for comment.

Quoted 5 lines · Kuninori Morimoto
Quoted 4 lines

---
v1 -> v2

Quoted 7 lines
Quoted 3 lines

o move calculate area to fsi_fifo_init
o modify fifo calculation way
o Add tiny document for fifo calculation

This patch is fine but it doesn't apply against for-2.6.35. Could you please check and resubmit? I suspect a collision with the previously applied patches.

Hmm strange...
I created it on "for-2.6.35"
and it works well in my environment on it

-----------
[morimoto] git checkout asoc/for-2.6.35
Previous HEAD position was afa9f82... ASoC: fsi: Add FSI2 device support HEAD is now at 10ea76c... ASoC: fsi: IRQ related process had be united

[morimoto] git am -3 /tmp/${[PATCH 2/4 v2]}
Applying: ASoC: fsi: Add FIFO size calculate

[morimoto] git am -3 /tmp/${[PATCH 4/4 v2]}
Applying: ASoC: fsi: Add FSI2 device support
-----------

Ahhh...
Sorry. my mail server seems little strange.
I guess you got my mail [4/4] -> [2/4] order ?

correct order is [2/4] -> [4/4]

Below is your issue ?
it is [4/4] -> [2/4] order.
If so, please change [2/4] -> [4/4] order.
So sorry.
---------------
[morimoto] git checkout asoc/for-2.6.35
Previous HEAD position was afa9f82... ASoC: fsi: Add FSI2 device support HEAD is now at 10ea76c... ASoC: fsi: IRQ related process had be united

[morimoto] git am -3 /tmp/${[PATCH 4/4 v2]}
Applying: ASoC: fsi: Add FSI2 device support
error: patch failed: sound/soc/sh/fsi.c:47
error: sound/soc/sh/fsi.c: patch does not apply
Using index info to reconstruct a base tree...
Falling back to patching base and 3-way merge...
Auto-merging sound/soc/sh/fsi.c
CONFLICT (content): Merge conflict in sound/soc/sh/fsi.c Failed to merge in the changes.
Patch failed at 0001 ASoC: fsi: Add FSI2 device support
When you have resolved this problem run "git am -3 --resolved". If you would prefer to skip this patch, instead run "git am -3 --skip". To restore the original branch and stop patching run "git am -3 --abort".

[morimoto] git diff

sound/soc/sh/fsi.c +0 -0
diff --cc sound/soc/sh/fsi.c
index 7c295df,f14bbb0..0000000
@@@ -46,8 -50,9 +50,14 @@@
  #define MUTE          0x020C
  #define CLK_RST               0x0210
  #define SOFT_RST      0x0214
++<<<<<<< HEAD:sound/soc/sh/fsi.c
 +#define MREG_START    INT_ST
 +#define MREG_END      SOFT_RST
++=======
+ #define FIFO_SZ               0x0218
+ #define MREG_START    CPU_INT_ST
+ #define MREG_END      FIFO_SZ
++>>>>>>> ASoC: fsi: Add FSI2 device support:sound/soc/sh/fsi.c
  
  /* DO_FMT */
  /* DI_FMT */
---------------

Best regards
--
Kuninori Morimoto

#4 lore raw
Quoted 3 lines · Kuninori Morimoto

it is [4/4] -> [2/4] order.
If so, please change [2/4] -> [4/4] order.
So sorry.

Ah, no - I'd not deleted the earlier version of the patch from my local tree from when I checked why patch 4 was failing. Sorry about that, my mistake - I've applied both patches now.

#5 lore raw

Dear Mark

Quoted 7 lines
Quoted 3 lines

it is [4/4] -> [2/4] order.
If so, please change [2/4] -> [4/4] order.
So sorry.

Ah, no - I'd not deleted the earlier version of the patch from my local tree from when I checked why patch 4 was failing. Sorry about that, my mistake - I've applied both patches now.

Hahahaha... =)
No worry. It is always happen on my desk =)

Best regards
--
Kuninori Morimoto