Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5bfb9ad0 authored by Kuninori Morimoto's avatar Kuninori Morimoto Committed by Mark Brown
Browse files

ASoC: fsi: modify variable name to easy to understand



Current FSI driver is using
data-length / width / number / offset for variables.
But it was a very confusing name.

This patch rename them to easy to understand,
and add new functions for it.

Signed-off-by: default avatarKuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Acked-by: default avatarLiam Girdwood <lrg@slimlogic.co.uk>
Signed-off-by: default avatarMark Brown <broonie@opensource.wolfsonmicro.com>
parent 5250a503
Loading
Loading
Loading
Loading
+96 −77
Original line number Original line Diff line number Diff line
@@ -101,6 +101,15 @@


#define FSI_FMTS (SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S16_LE)
#define FSI_FMTS (SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S16_LE)


/*
 * FSI driver use below type name for variable
 *
 * xxx_len	: data length
 * xxx_width	: data width
 * xxx_offset	: data offset
 * xxx_num	: number of data
 */

/*
/*
 *		struct
 *		struct
 */
 */
@@ -110,13 +119,13 @@ struct fsi_priv {
	struct snd_pcm_substream *substream;
	struct snd_pcm_substream *substream;
	struct fsi_master *master;
	struct fsi_master *master;


	int fifo_max;
	int fifo_max_num;
	int chan;
	int chan_num;


	int byte_offset;
	int buff_offset;
	int buff_len;
	int period_len;
	int period_len;
	int buffer_len;
	int period_num;
	int periods;


	u32 mst_ctrl;
	u32 mst_ctrl;
};
};
@@ -320,32 +329,43 @@ static void fsi_stream_push(struct fsi_priv *fsi,
			    u32 period_len)
			    u32 period_len)
{
{
	fsi->substream		= substream;
	fsi->substream		= substream;
	fsi->buffer_len		= buffer_len;
	fsi->buff_len		= buffer_len;
	fsi->buff_offset	= 0;
	fsi->period_len		= period_len;
	fsi->period_len		= period_len;
	fsi->byte_offset	= 0;
	fsi->period_num		= 0;
	fsi->periods		= 0;
}
}


static void fsi_stream_pop(struct fsi_priv *fsi)
static void fsi_stream_pop(struct fsi_priv *fsi)
{
{
	fsi->substream		= NULL;
	fsi->substream		= NULL;
	fsi->buffer_len		= 0;
	fsi->buff_len		= 0;
	fsi->buff_offset	= 0;
	fsi->period_len		= 0;
	fsi->period_len		= 0;
	fsi->byte_offset	= 0;
	fsi->period_num		= 0;
	fsi->periods		= 0;
}
}


static int fsi_get_fifo_residue(struct fsi_priv *fsi, int is_play)
static int fsi_get_fifo_data_num(struct fsi_priv *fsi, int is_play)
{
{
	u32 status;
	u32 status;
	u32 reg = is_play ? DOFF_ST : DIFF_ST;
	u32 reg = is_play ? DOFF_ST : DIFF_ST;
	int residue;
	int data_num;


	status = fsi_reg_read(fsi, reg);
	status = fsi_reg_read(fsi, reg);
	residue = 0x1ff & (status >> 8);
	data_num = 0x1ff & (status >> 8);
	residue *= fsi->chan;
	data_num *= fsi->chan_num;

	return data_num;
}


	return residue;
static int fsi_len2num(int len, int width)
{
	return len / width;
}

#define fsi_num2offset(a, b) fsi_num2len(a, b)
static int fsi_num2len(int num, int width)
{
	return num * width;
}
}


/*
/*
@@ -354,50 +374,50 @@ static int fsi_get_fifo_residue(struct fsi_priv *fsi, int is_play)


static u8 *fsi_dma_get_area(struct fsi_priv *fsi)
static u8 *fsi_dma_get_area(struct fsi_priv *fsi)
{
{
	return fsi->substream->runtime->dma_area + fsi->byte_offset;
	return fsi->substream->runtime->dma_area + fsi->buff_offset;
}
}


static void fsi_dma_soft_push16(struct fsi_priv *fsi, int size)
static void fsi_dma_soft_push16(struct fsi_priv *fsi, int num)
{
{
	u16 *start;
	u16 *start;
	int i;
	int i;


	start  = (u16 *)fsi_dma_get_area(fsi);
	start  = (u16 *)fsi_dma_get_area(fsi);


	for (i = 0; i < size; i++)
	for (i = 0; i < num; i++)
		fsi_reg_write(fsi, DODT, ((u32)*(start + i) << 8));
		fsi_reg_write(fsi, DODT, ((u32)*(start + i) << 8));
}
}


static void fsi_dma_soft_pop16(struct fsi_priv *fsi, int size)
static void fsi_dma_soft_pop16(struct fsi_priv *fsi, int num)
{
{
	u16 *start;
	u16 *start;
	int i;
	int i;


	start  = (u16 *)fsi_dma_get_area(fsi);
	start  = (u16 *)fsi_dma_get_area(fsi);


	for (i = 0; i < size; i++)
	for (i = 0; i < num; i++)
		*(start + i) = (u16)(fsi_reg_read(fsi, DIDT) >> 8);
		*(start + i) = (u16)(fsi_reg_read(fsi, DIDT) >> 8);
}
}


static void fsi_dma_soft_push32(struct fsi_priv *fsi, int size)
static void fsi_dma_soft_push32(struct fsi_priv *fsi, int num)
{
{
	u32 *start;
	u32 *start;
	int i;
	int i;


	start  = (u32 *)fsi_dma_get_area(fsi);
	start  = (u32 *)fsi_dma_get_area(fsi);


	for (i = 0; i < size; i++)
	for (i = 0; i < num; i++)
		fsi_reg_write(fsi, DODT, *(start + i));
		fsi_reg_write(fsi, DODT, *(start + i));
}
}


static void fsi_dma_soft_pop32(struct fsi_priv *fsi, int size)
static void fsi_dma_soft_pop32(struct fsi_priv *fsi, int num)
{
{
	u32 *start;
	u32 *start;
	int i;
	int i;


	start  = (u32 *)fsi_dma_get_area(fsi);
	start  = (u32 *)fsi_dma_get_area(fsi);


	for (i = 0; i < size; i++)
	for (i = 0; i < num; i++)
		*(start + i) = fsi_reg_read(fsi, DIDT);
		*(start + i) = fsi_reg_read(fsi, DIDT);
}
}


@@ -492,8 +512,8 @@ static void fsi_fifo_init(struct fsi_priv *fsi,
	shift = fsi_master_read(master, FIFO_SZ);
	shift = fsi_master_read(master, FIFO_SZ);
	shift >>= fsi_is_port_a(fsi) ? AO_SZ_SHIFT : BO_SZ_SHIFT;
	shift >>= fsi_is_port_a(fsi) ? AO_SZ_SHIFT : BO_SZ_SHIFT;
	shift &= OUT_SZ_MASK;
	shift &= OUT_SZ_MASK;
	fsi->fifo_max = 256 << shift;
	fsi->fifo_max_num = 256 << shift;
	dev_dbg(dai->dev, "fifo = %d words\n", fsi->fifo_max);
	dev_dbg(dai->dev, "fifo = %d words\n", fsi->fifo_max_num);


	/*
	/*
	 * The maximum number of sample data varies depending
	 * The maximum number of sample data varies depending
@@ -514,9 +534,10 @@ static void fsi_fifo_init(struct fsi_priv *fsi,
	 * 7 channels:  32 ( 32 x 7 = 224)
	 * 7 channels:  32 ( 32 x 7 = 224)
	 * 8 channels:  32 ( 32 x 8 = 256)
	 * 8 channels:  32 ( 32 x 8 = 256)
	 */
	 */
	for (i = 1; i < fsi->chan; i <<= 1)
	for (i = 1; i < fsi->chan_num; i <<= 1)
		fsi->fifo_max >>= 1;
		fsi->fifo_max_num >>= 1;
	dev_dbg(dai->dev, "%d channel %d store\n", fsi->chan, fsi->fifo_max);
	dev_dbg(dai->dev, "%d channel %d store\n",
		fsi->chan_num, fsi->fifo_max_num);


	ctrl = is_play ? DOFF_CTL : DIFF_CTL;
	ctrl = is_play ? DOFF_CTL : DIFF_CTL;


@@ -545,9 +566,9 @@ static int fsi_data_push(struct fsi_priv *fsi, int startup)
	struct snd_pcm_runtime *runtime;
	struct snd_pcm_runtime *runtime;
	struct snd_pcm_substream *substream = NULL;
	struct snd_pcm_substream *substream = NULL;
	u32 status;
	u32 status;
	int send;
	int push_num;
	int fifo_free;
	int push_num_max;
	int width;
	int ch_width;
	int over_period;
	int over_period;


	if (!fsi			||
	if (!fsi			||
@@ -562,41 +583,40 @@ static int fsi_data_push(struct fsi_priv *fsi, int startup)
	/* FSI FIFO has limit.
	/* FSI FIFO has limit.
	 * So, this driver can not send periods data at a time
	 * So, this driver can not send periods data at a time
	 */
	 */
	if (fsi->byte_offset >=
	if (fsi->buff_offset >=
	    fsi->period_len * (fsi->periods + 1)) {
	    fsi_num2offset(fsi->period_num + 1, fsi->period_len)) {


		over_period = 1;
		over_period = 1;
		fsi->periods = (fsi->periods + 1) % runtime->periods;
		fsi->period_num = (fsi->period_num + 1) % runtime->periods;


		if (0 == fsi->periods)
		if (0 == fsi->period_num)
			fsi->byte_offset = 0;
			fsi->buff_offset = 0;
	}
	}


	/* get 1 channel data width */
	/* get 1 channel data width */
	width = frames_to_bytes(runtime, 1) / fsi->chan;
	ch_width = frames_to_bytes(runtime, 1) / fsi->chan_num;


	/* get send size for alsa */
	/* number of push data */
	send = (fsi->buffer_len - fsi->byte_offset) / width;
	push_num = fsi_len2num(fsi->buff_len - fsi->buff_offset, ch_width);


	/*  get FIFO free size */
	/* max number of push data */
	fifo_free = (fsi->fifo_max * fsi->chan) - fsi_get_fifo_residue(fsi, 1);
	push_num_max = (fsi->fifo_max_num * fsi->chan_num) -
			fsi_get_fifo_data_num(fsi, 1);


	/* size check */
	push_num = min(push_num, push_num_max);
	if (fifo_free < send)
		send = fifo_free;


	switch (width) {
	switch (ch_width) {
	case 2:
	case 2:
		fsi_dma_soft_push16(fsi, send);
		fsi_dma_soft_push16(fsi, push_num);
		break;
		break;
	case 4:
	case 4:
		fsi_dma_soft_push32(fsi, send);
		fsi_dma_soft_push32(fsi, push_num);
		break;
		break;
	default:
	default:
		return -EINVAL;
		return -EINVAL;
	}
	}


	fsi->byte_offset += send * width;
	fsi->buff_offset += fsi_num2offset(push_num, ch_width);


	status = fsi_reg_read(fsi, DOFF_ST);
	status = fsi_reg_read(fsi, DOFF_ST);
	if (!startup) {
	if (!startup) {
@@ -622,9 +642,9 @@ static int fsi_data_pop(struct fsi_priv *fsi, int startup)
	struct snd_pcm_runtime *runtime;
	struct snd_pcm_runtime *runtime;
	struct snd_pcm_substream *substream = NULL;
	struct snd_pcm_substream *substream = NULL;
	u32 status;
	u32 status;
	int free;
	int pop_num;
	int fifo_fill;
	int pop_num_max;
	int width;
	int ch_width;
	int over_period;
	int over_period;


	if (!fsi			||
	if (!fsi			||
@@ -639,40 +659,39 @@ static int fsi_data_pop(struct fsi_priv *fsi, int startup)
	/* FSI FIFO has limit.
	/* FSI FIFO has limit.
	 * So, this driver can not send periods data at a time
	 * So, this driver can not send periods data at a time
	 */
	 */
	if (fsi->byte_offset >=
	if (fsi->buff_offset >=
	    fsi->period_len * (fsi->periods + 1)) {
	    fsi_num2offset(fsi->period_num + 1, fsi->period_len)) {


		over_period = 1;
		over_period = 1;
		fsi->periods = (fsi->periods + 1) % runtime->periods;
		fsi->period_num = (fsi->period_num + 1) % runtime->periods;


		if (0 == fsi->periods)
		if (0 == fsi->period_num)
			fsi->byte_offset = 0;
			fsi->buff_offset = 0;
	}
	}


	/* get 1 channel data width */
	/* get 1 channel data width */
	width = frames_to_bytes(runtime, 1) / fsi->chan;
	ch_width = frames_to_bytes(runtime, 1) / fsi->chan_num;


	/* get free space for alsa */
	/* get free space for alsa */
	free = (fsi->buffer_len - fsi->byte_offset) / width;
	pop_num_max = fsi_len2num(fsi->buff_len - fsi->buff_offset, ch_width);


	/* get recv size */
	/* get recv size */
	fifo_fill = fsi_get_fifo_residue(fsi, 0);
	pop_num = fsi_get_fifo_data_num(fsi, 0);


	if (free < fifo_fill)
	pop_num = min(pop_num_max, pop_num);
		fifo_fill = free;


	switch (width) {
	switch (ch_width) {
	case 2:
	case 2:
		fsi_dma_soft_pop16(fsi, fifo_fill);
		fsi_dma_soft_pop16(fsi, pop_num);
		break;
		break;
	case 4:
	case 4:
		fsi_dma_soft_pop32(fsi, fifo_fill);
		fsi_dma_soft_pop32(fsi, pop_num);
		break;
		break;
	default:
	default:
		return -EINVAL;
		return -EINVAL;
	}
	}


	fsi->byte_offset += fifo_fill * width;
	fsi->buff_offset += fsi_num2offset(pop_num, ch_width);


	status = fsi_reg_read(fsi, DIFF_ST);
	status = fsi_reg_read(fsi, DIFF_ST);
	if (!startup) {
	if (!startup) {
@@ -763,29 +782,29 @@ static int fsi_dai_startup(struct snd_pcm_substream *substream,
	switch (fmt) {
	switch (fmt) {
	case SH_FSI_FMT_MONO:
	case SH_FSI_FMT_MONO:
		data = CR_MONO;
		data = CR_MONO;
		fsi->chan = 1;
		fsi->chan_num = 1;
		break;
		break;
	case SH_FSI_FMT_MONO_DELAY:
	case SH_FSI_FMT_MONO_DELAY:
		data = CR_MONO_D;
		data = CR_MONO_D;
		fsi->chan = 1;
		fsi->chan_num = 1;
		break;
		break;
	case SH_FSI_FMT_PCM:
	case SH_FSI_FMT_PCM:
		data = CR_PCM;
		data = CR_PCM;
		fsi->chan = 2;
		fsi->chan_num = 2;
		break;
		break;
	case SH_FSI_FMT_I2S:
	case SH_FSI_FMT_I2S:
		data = CR_I2S;
		data = CR_I2S;
		fsi->chan = 2;
		fsi->chan_num = 2;
		break;
		break;
	case SH_FSI_FMT_TDM:
	case SH_FSI_FMT_TDM:
		fsi->chan = is_play ?
		fsi->chan_num = is_play ?
			SH_FSI_GET_CH_O(flags) : SH_FSI_GET_CH_I(flags);
			SH_FSI_GET_CH_O(flags) : SH_FSI_GET_CH_I(flags);
		data = CR_TDM | (fsi->chan - 1);
		data = CR_TDM | (fsi->chan_num - 1);
		break;
		break;
	case SH_FSI_FMT_TDM_DELAY:
	case SH_FSI_FMT_TDM_DELAY:
		fsi->chan = is_play ?
		fsi->chan_num = is_play ?
			SH_FSI_GET_CH_O(flags) : SH_FSI_GET_CH_I(flags);
			SH_FSI_GET_CH_O(flags) : SH_FSI_GET_CH_I(flags);
		data = CR_TDM_D | (fsi->chan - 1);
		data = CR_TDM_D | (fsi->chan_num - 1);
		break;
		break;
	case SH_FSI_FMT_SPDIF:
	case SH_FSI_FMT_SPDIF:
		if (master->core->ver < 2) {
		if (master->core->ver < 2) {
@@ -793,7 +812,7 @@ static int fsi_dai_startup(struct snd_pcm_substream *substream,
			return -EINVAL;
			return -EINVAL;
		}
		}
		data = CR_SPDIF;
		data = CR_SPDIF;
		fsi->chan = 2;
		fsi->chan_num = 2;
		fsi_spdif_clk_ctrl(fsi, 1);
		fsi_spdif_clk_ctrl(fsi, 1);
		fsi_reg_mask_set(fsi, OUT_SEL, 0x0010, 0x0010);
		fsi_reg_mask_set(fsi, OUT_SEL, 0x0010, 0x0010);
		break;
		break;
@@ -992,7 +1011,7 @@ static snd_pcm_uframes_t fsi_pointer(struct snd_pcm_substream *substream)
	struct fsi_priv *fsi = fsi_get_priv(substream);
	struct fsi_priv *fsi = fsi_get_priv(substream);
	long location;
	long location;


	location = (fsi->byte_offset - 1);
	location = (fsi->buff_offset - 1);
	if (location < 0)
	if (location < 0)
		location = 0;
		location = 0;