[alsa-devel] [PATCH 1/2] ASoC: fsi: simultaneous playback/recorde support

Kuninori Morimoto kuninori.morimoto.gx at renesas.com
Tue Oct 12 06:39:09 CEST 2010


Current FSI driver had not cared about simultaneous
playback/recorde on same port.
This patch add new fsi_stream struct to care it,

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx at renesas.com>
---
 sound/soc/sh/fsi.c |  142 +++++++++++++++++++++++++++++++--------------------
 1 files changed, 86 insertions(+), 56 deletions(-)

diff --git a/sound/soc/sh/fsi.c b/sound/soc/sh/fsi.c
index 895ce75..0c80d10 100644
--- a/sound/soc/sh/fsi.c
+++ b/sound/soc/sh/fsi.c
@@ -48,6 +48,10 @@
 #define MREG_START	A_MST_CTLR
 #define MREG_END	FIFO_SZ
 
+/* is */
+#define IS_PLAY		1
+#define IS_CAPTURE	0
+
 /* DO_FMT */
 /* DI_FMT */
 #define CR_MONO		(0x0 << 4)
@@ -113,10 +117,8 @@
  *		struct
  */
 
-struct fsi_priv {
-	void __iomem *base;
+struct fsi_stream {
 	struct snd_pcm_substream *substream;
-	struct fsi_master *master;
 
 	int fifo_max_num;
 	int chan_num;
@@ -125,6 +127,14 @@ struct fsi_priv {
 	int buff_len;
 	int period_len;
 	int period_num;
+};
+
+struct fsi_priv {
+	void __iomem *base;
+	struct fsi_master *master;
+
+	struct fsi_stream playback;
+	struct fsi_stream capture;
 
 	u32 mst_ctrl;
 };
@@ -294,6 +304,11 @@ static u32 fsi_get_info_flags(struct fsi_priv *fsi)
 		master->info->portb_flags;
 }
 
+static struct fsi_stream *fsi_get_stream(struct fsi_priv *fsi, int is_play)
+{
+	return is_play ? &fsi->playback : &fsi->capture;
+}
+
 static int fsi_is_play(struct snd_pcm_substream *substream)
 {
 	return substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
@@ -328,35 +343,41 @@ static u32 fsi_get_port_shift(struct fsi_priv *fsi, int is_play)
 }
 
 static void fsi_stream_push(struct fsi_priv *fsi,
+			    int is_play,
 			    struct snd_pcm_substream *substream,
 			    u32 buffer_len,
 			    u32 period_len)
 {
-	fsi->substream		= substream;
-	fsi->buff_len		= buffer_len;
-	fsi->buff_offset	= 0;
-	fsi->period_len		= period_len;
-	fsi->period_num		= 0;
+	struct fsi_stream *io = fsi_get_stream(fsi, is_play);
+
+	io->substream	= substream;
+	io->buff_len	= buffer_len;
+	io->buff_offset	= 0;
+	io->period_len	= period_len;
+	io->period_num	= 0;
 }
 
-static void fsi_stream_pop(struct fsi_priv *fsi)
+static void fsi_stream_pop(struct fsi_priv *fsi, int is_play)
 {
-	fsi->substream		= NULL;
-	fsi->buff_len		= 0;
-	fsi->buff_offset	= 0;
-	fsi->period_len		= 0;
-	fsi->period_num		= 0;
+	struct fsi_stream *io = fsi_get_stream(fsi, is_play);
+
+	io->substream	= NULL;
+	io->buff_len	= 0;
+	io->buff_offset	= 0;
+	io->period_len	= 0;
+	io->period_num	= 0;
 }
 
 static int fsi_get_fifo_data_num(struct fsi_priv *fsi, int is_play)
 {
 	u32 status;
 	u32 reg = is_play ? DOFF_ST : DIFF_ST;
+	struct fsi_stream *io = fsi_get_stream(fsi, is_play);
 	int data_num;
 
 	status = fsi_reg_read(fsi, reg);
 	data_num = 0x1ff & (status >> 8);
-	data_num *= fsi->chan_num;
+	data_num *= io->chan_num;
 
 	return data_num;
 }
@@ -372,21 +393,24 @@ static int fsi_num2len(int num, int width)
 	return num * width;
 }
 
-static int fsi_get_frame_width(struct fsi_priv *fsi)
+static int fsi_get_frame_width(struct fsi_priv *fsi, int is_play)
 {
-	struct snd_pcm_substream *substream = fsi->substream;
+	struct fsi_stream *io = fsi_get_stream(fsi, is_play);
+	struct snd_pcm_substream *substream = io->substream;
 	struct snd_pcm_runtime *runtime = substream->runtime;
 
-	return frames_to_bytes(runtime, 1) / fsi->chan_num;
+	return frames_to_bytes(runtime, 1) / io->chan_num;
 }
 
 /*
  *		dma function
  */
 
-static u8 *fsi_dma_get_area(struct fsi_priv *fsi)
+static u8 *fsi_dma_get_area(struct fsi_priv *fsi, int is_play)
 {
-	return fsi->substream->runtime->dma_area + fsi->buff_offset;
+	struct fsi_stream *io = fsi_get_stream(fsi, is_play);
+
+	return io->substream->runtime->dma_area + io->buff_offset;
 }
 
 static void fsi_dma_soft_push16(struct fsi_priv *fsi, int num)
@@ -394,7 +418,7 @@ static void fsi_dma_soft_push16(struct fsi_priv *fsi, int num)
 	u16 *start;
 	int i;
 
-	start  = (u16 *)fsi_dma_get_area(fsi);
+	start  = (u16 *)fsi_dma_get_area(fsi, IS_PLAY);
 
 	for (i = 0; i < num; i++)
 		fsi_reg_write(fsi, DODT, ((u32)*(start + i) << 8));
@@ -405,7 +429,7 @@ static void fsi_dma_soft_pop16(struct fsi_priv *fsi, int num)
 	u16 *start;
 	int i;
 
-	start  = (u16 *)fsi_dma_get_area(fsi);
+	start  = (u16 *)fsi_dma_get_area(fsi, IS_CAPTURE);
 
 	for (i = 0; i < num; i++)
 		*(start + i) = (u16)(fsi_reg_read(fsi, DIDT) >> 8);
@@ -416,7 +440,7 @@ static void fsi_dma_soft_push32(struct fsi_priv *fsi, int num)
 	u32 *start;
 	int i;
 
-	start  = (u32 *)fsi_dma_get_area(fsi);
+	start  = (u32 *)fsi_dma_get_area(fsi, IS_PLAY);
 
 	for (i = 0; i < num; i++)
 		fsi_reg_write(fsi, DODT, *(start + i));
@@ -427,7 +451,7 @@ static void fsi_dma_soft_pop32(struct fsi_priv *fsi, int num)
 	u32 *start;
 	int i;
 
-	start  = (u32 *)fsi_dma_get_area(fsi);
+	start  = (u32 *)fsi_dma_get_area(fsi, IS_CAPTURE);
 
 	for (i = 0; i < num; i++)
 		*(start + i) = fsi_reg_read(fsi, DIDT);
@@ -518,14 +542,15 @@ static void fsi_fifo_init(struct fsi_priv *fsi,
 			  struct snd_soc_dai *dai)
 {
 	struct fsi_master *master = fsi_get_master(fsi);
+	struct fsi_stream *io = fsi_get_stream(fsi, is_play);
 	u32 ctrl, shift, i;
 
 	/* get on-chip RAM capacity */
 	shift = fsi_master_read(master, FIFO_SZ);
 	shift >>= fsi_get_port_shift(fsi, is_play);
 	shift &= FIFO_SZ_MASK;
-	fsi->fifo_max_num = 256 << shift;
-	dev_dbg(dai->dev, "fifo = %d words\n", fsi->fifo_max_num);
+	io->fifo_max_num = 256 << shift;
+	dev_dbg(dai->dev, "fifo = %d words\n", io->fifo_max_num);
 
 	/*
 	 * The maximum number of sample data varies depending
@@ -546,10 +571,10 @@ static void fsi_fifo_init(struct fsi_priv *fsi,
 	 * 7 channels:  32 ( 32 x 7 = 224)
 	 * 8 channels:  32 ( 32 x 8 = 256)
 	 */
-	for (i = 1; i < fsi->chan_num; i <<= 1)
-		fsi->fifo_max_num >>= 1;
+	for (i = 1; i < io->chan_num; i <<= 1)
+		io->fifo_max_num >>= 1;
 	dev_dbg(dai->dev, "%d channel %d store\n",
-		fsi->chan_num, fsi->fifo_max_num);
+		io->chan_num, io->fifo_max_num);
 
 	ctrl = is_play ? DOFF_CTL : DIFF_CTL;
 
@@ -576,6 +601,7 @@ static int fsi_fifo_data_ctrl(struct fsi_priv *fsi, int startup, int is_play)
 {
 	struct snd_pcm_runtime *runtime;
 	struct snd_pcm_substream *substream = NULL;
+	struct fsi_stream *io = fsi_get_stream(fsi, is_play);
 	u32 status_reg = is_play ? DOFF_ST : DIFF_ST;
 	int data_residue_num;
 	int data_num;
@@ -585,32 +611,32 @@ static int fsi_fifo_data_ctrl(struct fsi_priv *fsi, int startup, int is_play)
 	void (*fn)(struct fsi_priv *fsi, int size);
 
 	if (!fsi			||
-	    !fsi->substream		||
-	    !fsi->substream->runtime)
+	    !io->substream		||
+	    !io->substream->runtime)
 		return -EINVAL;
 
 	over_period	= 0;
-	substream	= fsi->substream;
+	substream	= io->substream;
 	runtime		= substream->runtime;
 
 	/* FSI FIFO has limit.
 	 * So, this driver can not send periods data at a time
 	 */
-	if (fsi->buff_offset >=
-	    fsi_num2offset(fsi->period_num + 1, fsi->period_len)) {
+	if (io->buff_offset >=
+	    fsi_num2offset(io->period_num + 1, io->period_len)) {
 
 		over_period = 1;
-		fsi->period_num = (fsi->period_num + 1) % runtime->periods;
+		io->period_num = (io->period_num + 1) % runtime->periods;
 
-		if (0 == fsi->period_num)
-			fsi->buff_offset = 0;
+		if (0 == io->period_num)
+			io->buff_offset = 0;
 	}
 
 	/* get 1 channel data width */
-	ch_width = fsi_get_frame_width(fsi);
+	ch_width = fsi_get_frame_width(fsi, is_play);
 
 	/* get residue data number of alsa */
-	data_residue_num = fsi_len2num(fsi->buff_len - fsi->buff_offset,
+	data_residue_num = fsi_len2num(io->buff_len - io->buff_offset,
 				       ch_width);
 
 	if (is_play) {
@@ -620,7 +646,7 @@ static int fsi_fifo_data_ctrl(struct fsi_priv *fsi, int startup, int is_play)
 		 * data_num_max	: number of FSI fifo free space
 		 * data_num	: number of ALSA residue data
 		 */
-		data_num_max  = fsi->fifo_max_num * fsi->chan_num;
+		data_num_max  = io->fifo_max_num * io->chan_num;
 		data_num_max -= fsi_get_fifo_data_num(fsi, is_play);
 
 		data_num = data_residue_num;
@@ -662,7 +688,7 @@ static int fsi_fifo_data_ctrl(struct fsi_priv *fsi, int startup, int is_play)
 	fn(fsi, data_num);
 
 	/* update buff_offset */
-	fsi->buff_offset += fsi_num2offset(data_num, ch_width);
+	io->buff_offset += fsi_num2offset(data_num, ch_width);
 
 	/* check fifo status */
 	if (!startup) {
@@ -687,12 +713,12 @@ static int fsi_fifo_data_ctrl(struct fsi_priv *fsi, int startup, int is_play)
 
 static int fsi_data_pop(struct fsi_priv *fsi, int startup)
 {
-	return fsi_fifo_data_ctrl(fsi, startup, 0);
+	return fsi_fifo_data_ctrl(fsi, startup, IS_CAPTURE);
 }
 
 static int fsi_data_push(struct fsi_priv *fsi, int startup)
 {
-	return fsi_fifo_data_ctrl(fsi, startup, 1);
+	return fsi_fifo_data_ctrl(fsi, startup, IS_PLAY);
 }
 
 static irqreturn_t fsi_interrupt(int irq, void *data)
@@ -726,14 +752,17 @@ static int fsi_dai_startup(struct snd_pcm_substream *substream,
 			   struct snd_soc_dai *dai)
 {
 	struct fsi_priv *fsi = fsi_get_priv(substream);
-	u32 flags = fsi_get_info_flags(fsi);
 	struct fsi_master *master = fsi_get_master(fsi);
+	struct fsi_stream *io;
+	u32 flags = fsi_get_info_flags(fsi);
 	u32 fmt;
 	u32 reg;
 	u32 data;
 	int is_play = fsi_is_play(substream);
 	int is_master;
 
+	io = fsi_get_stream(fsi, is_play);
+
 	pm_runtime_get_sync(dai->dev);
 
 	/* CKG1 */
@@ -764,29 +793,29 @@ static int fsi_dai_startup(struct snd_pcm_substream *substream,
 	switch (fmt) {
 	case SH_FSI_FMT_MONO:
 		data = CR_MONO;
-		fsi->chan_num = 1;
+		io->chan_num = 1;
 		break;
 	case SH_FSI_FMT_MONO_DELAY:
 		data = CR_MONO_D;
-		fsi->chan_num = 1;
+		io->chan_num = 1;
 		break;
 	case SH_FSI_FMT_PCM:
 		data = CR_PCM;
-		fsi->chan_num = 2;
+		io->chan_num = 2;
 		break;
 	case SH_FSI_FMT_I2S:
 		data = CR_I2S;
-		fsi->chan_num = 2;
+		io->chan_num = 2;
 		break;
 	case SH_FSI_FMT_TDM:
-		fsi->chan_num = is_play ?
+		io->chan_num = is_play ?
 			SH_FSI_GET_CH_O(flags) : SH_FSI_GET_CH_I(flags);
-		data = CR_TDM | (fsi->chan_num - 1);
+		data = CR_TDM | (io->chan_num - 1);
 		break;
 	case SH_FSI_FMT_TDM_DELAY:
-		fsi->chan_num = is_play ?
+		io->chan_num = is_play ?
 			SH_FSI_GET_CH_O(flags) : SH_FSI_GET_CH_I(flags);
-		data = CR_TDM_D | (fsi->chan_num - 1);
+		data = CR_TDM_D | (io->chan_num - 1);
 		break;
 	case SH_FSI_FMT_SPDIF:
 		if (master->core->ver < 2) {
@@ -794,7 +823,7 @@ static int fsi_dai_startup(struct snd_pcm_substream *substream,
 			return -EINVAL;
 		}
 		data = CR_SPDIF;
-		fsi->chan_num = 2;
+		io->chan_num = 2;
 		fsi_spdif_clk_ctrl(fsi, 1);
 		fsi_reg_mask_set(fsi, OUT_SEL, 0x0010, 0x0010);
 		break;
@@ -836,14 +865,14 @@ static int fsi_dai_trigger(struct snd_pcm_substream *substream, int cmd,
 
 	switch (cmd) {
 	case SNDRV_PCM_TRIGGER_START:
-		fsi_stream_push(fsi, substream,
+		fsi_stream_push(fsi, is_play, substream,
 				frames_to_bytes(runtime, runtime->buffer_size),
 				frames_to_bytes(runtime, runtime->period_size));
 		ret = is_play ? fsi_data_push(fsi, 1) : fsi_data_pop(fsi, 1);
 		break;
 	case SNDRV_PCM_TRIGGER_STOP:
 		fsi_irq_disable(fsi, is_play);
-		fsi_stream_pop(fsi);
+		fsi_stream_pop(fsi, is_play);
 		break;
 	}
 
@@ -991,9 +1020,10 @@ static snd_pcm_uframes_t fsi_pointer(struct snd_pcm_substream *substream)
 {
 	struct snd_pcm_runtime *runtime = substream->runtime;
 	struct fsi_priv *fsi = fsi_get_priv(substream);
+	struct fsi_stream *io = fsi_get_stream(fsi, fsi_is_play(substream));
 	long location;
 
-	location = (fsi->buff_offset - 1);
+	location = (io->buff_offset - 1);
 	if (location < 0)
 		location = 0;
 
-- 
1.7.0.4



More information about the Alsa-devel mailing list