Commit 2e651baf authored by Kuninori Morimoto's avatar Kuninori Morimoto Committed by Mark Brown

ASoC: sh: fsi: tidyup unclear variable naming

Some variables on this driver were a unclear naming,
and were different unit (byte, frame, sample).
And some functions had wrong name
(ex. it returned "sample width" but name was "fsi_get_frame_width").
This patch tidy-up this issue, and the minimum unit become "sample".
Special thanks to Takashi YOSHII.
Signed-off-by: default avatarKuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Acked-by: default avatarLiam Girdwood <lrg@ti.com>
Signed-off-by: default avatarMark Brown <broonie@opensource.wolfsonmicro.com>
parent 1ddddd36
...@@ -118,10 +118,38 @@ typedef int (*set_rate_func)(struct device *dev, int is_porta, int rate, int ena ...@@ -118,10 +118,38 @@ typedef int (*set_rate_func)(struct device *dev, int is_porta, int rate, int ena
/* /*
* FSI driver use below type name for variable * 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 * xxx_num : number of data
* xxx_pos : position of data
* xxx_capa : capacity of data
*/
/*
* period/frame/sample image
*
* ex) PCM (2ch)
*
* period pos period pos
* [n] [n + 1]
* |<-------------------- period--------------------->|
* ==|============================================ ... =|==
* | |
* ||<----- frame ----->|<------ frame ----->| ... |
* |+--------------------+--------------------+- ... |
* ||[ sample ][ sample ]|[ sample ][ sample ]| ... |
* |+--------------------+--------------------+- ... |
* ==|============================================ ... =|==
*/
/*
* FSI FIFO image
*
* | |
* | |
* | [ sample ] |
* | [ sample ] |
* | [ sample ] |
* | [ sample ] |
* --> go to codecs
*/ */
/* /*
...@@ -131,12 +159,11 @@ typedef int (*set_rate_func)(struct device *dev, int is_porta, int rate, int ena ...@@ -131,12 +159,11 @@ typedef int (*set_rate_func)(struct device *dev, int is_porta, int rate, int ena
struct fsi_stream { struct fsi_stream {
struct snd_pcm_substream *substream; struct snd_pcm_substream *substream;
int fifo_max_num; int fifo_sample_capa; /* sample capacity of FSI FIFO */
int buff_sample_capa; /* sample capacity of ALSA buffer */
int buff_offset; int buff_sample_pos; /* sample position of ALSA buffer */
int buff_len; int period_samples; /* sample number / 1 period */
int period_len; int period_pos; /* current period position */
int period_num;
int uerr_num; int uerr_num;
int oerr_num; int oerr_num;
...@@ -342,6 +369,16 @@ static u32 fsi_get_port_shift(struct fsi_priv *fsi, int is_play) ...@@ -342,6 +369,16 @@ static u32 fsi_get_port_shift(struct fsi_priv *fsi, int is_play)
return shift; return shift;
} }
static int fsi_frame2sample(struct fsi_priv *fsi, int frames)
{
return frames * fsi->chan_num;
}
static int fsi_sample2frame(struct fsi_priv *fsi, int samples)
{
return samples / fsi->chan_num;
}
static void fsi_stream_push(struct fsi_priv *fsi, static void fsi_stream_push(struct fsi_priv *fsi,
int is_play, int is_play,
struct snd_pcm_substream *substream) struct snd_pcm_substream *substream)
...@@ -350,10 +387,10 @@ static void fsi_stream_push(struct fsi_priv *fsi, ...@@ -350,10 +387,10 @@ static void fsi_stream_push(struct fsi_priv *fsi,
struct snd_pcm_runtime *runtime = substream->runtime; struct snd_pcm_runtime *runtime = substream->runtime;
io->substream = substream; io->substream = substream;
io->buff_len = frames_to_bytes(runtime, runtime->buffer_size); io->buff_sample_capa = fsi_frame2sample(fsi, runtime->buffer_size);
io->buff_offset = 0; io->buff_sample_pos = 0;
io->period_len = frames_to_bytes(runtime, runtime->period_size); io->period_samples = fsi_frame2sample(fsi, runtime->period_size);
io->period_num = 0; io->period_pos = 0;
io->oerr_num = -1; /* ignore 1st err */ io->oerr_num = -1; /* ignore 1st err */
io->uerr_num = -1; /* ignore 1st err */ io->uerr_num = -1; /* ignore 1st err */
} }
...@@ -371,47 +408,26 @@ static void fsi_stream_pop(struct fsi_priv *fsi, int is_play) ...@@ -371,47 +408,26 @@ static void fsi_stream_pop(struct fsi_priv *fsi, int is_play)
dev_err(dai->dev, "under_run = %d\n", io->uerr_num); dev_err(dai->dev, "under_run = %d\n", io->uerr_num);
io->substream = NULL; io->substream = NULL;
io->buff_len = 0; io->buff_sample_capa = 0;
io->buff_offset = 0; io->buff_sample_pos = 0;
io->period_len = 0; io->period_samples = 0;
io->period_num = 0; io->period_pos = 0;
io->oerr_num = 0; io->oerr_num = 0;
io->uerr_num = 0; io->uerr_num = 0;
} }
static int fsi_get_fifo_data_num(struct fsi_priv *fsi, int is_play) static int fsi_get_current_fifo_samples(struct fsi_priv *fsi, int is_play)
{ {
u32 status; u32 status;
int data_num; int frames;
status = is_play ? status = is_play ?
fsi_reg_read(fsi, DOFF_ST) : fsi_reg_read(fsi, DOFF_ST) :
fsi_reg_read(fsi, DIFF_ST); fsi_reg_read(fsi, DIFF_ST);
data_num = 0x1ff & (status >> 8); frames = 0x1ff & (status >> 8);
data_num *= fsi->chan_num;
return data_num;
}
static int fsi_len2num(int len, int width)
{
return len / width;
}
#define fsi_num2offset(a, b) fsi_num2len(a, b) return fsi_frame2sample(fsi, frames);
static int fsi_num2len(int num, int width)
{
return num * width;
}
static int fsi_get_frame_width(struct fsi_priv *fsi, int is_play)
{
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;
} }
static void fsi_count_fifo_err(struct fsi_priv *fsi) static void fsi_count_fifo_err(struct fsi_priv *fsi)
...@@ -443,8 +459,10 @@ static u8 *fsi_dma_get_area(struct fsi_priv *fsi, int stream) ...@@ -443,8 +459,10 @@ static u8 *fsi_dma_get_area(struct fsi_priv *fsi, int stream)
{ {
int is_play = fsi_stream_is_play(stream); int is_play = fsi_stream_is_play(stream);
struct fsi_stream *io = fsi_get_stream(fsi, is_play); struct fsi_stream *io = fsi_get_stream(fsi, is_play);
struct snd_pcm_runtime *runtime = io->substream->runtime;
return io->substream->runtime->dma_area + io->buff_offset; return runtime->dma_area +
samples_to_bytes(runtime, io->buff_sample_pos);
} }
static void fsi_dma_soft_push16(struct fsi_priv *fsi, int num) static void fsi_dma_soft_push16(struct fsi_priv *fsi, int num)
...@@ -683,13 +701,14 @@ static void fsi_fifo_init(struct fsi_priv *fsi, ...@@ -683,13 +701,14 @@ static void fsi_fifo_init(struct fsi_priv *fsi,
struct fsi_master *master = fsi_get_master(fsi); struct fsi_master *master = fsi_get_master(fsi);
struct fsi_stream *io = fsi_get_stream(fsi, is_play); struct fsi_stream *io = fsi_get_stream(fsi, is_play);
u32 shift, i; u32 shift, i;
int frame_capa;
/* get on-chip RAM capacity */ /* get on-chip RAM capacity */
shift = fsi_master_read(master, FIFO_SZ); shift = fsi_master_read(master, FIFO_SZ);
shift >>= fsi_get_port_shift(fsi, is_play); shift >>= fsi_get_port_shift(fsi, is_play);
shift &= FIFO_SZ_MASK; shift &= FIFO_SZ_MASK;
io->fifo_max_num = 256 << shift; frame_capa = 256 << shift;
dev_dbg(dai->dev, "fifo = %d words\n", io->fifo_max_num); dev_dbg(dai->dev, "fifo = %d words\n", frame_capa);
/* /*
* The maximum number of sample data varies depending * The maximum number of sample data varies depending
...@@ -711,9 +730,11 @@ static void fsi_fifo_init(struct fsi_priv *fsi, ...@@ -711,9 +730,11 @@ static void fsi_fifo_init(struct fsi_priv *fsi,
* 8 channels: 32 ( 32 x 8 = 256) * 8 channels: 32 ( 32 x 8 = 256)
*/ */
for (i = 1; i < fsi->chan_num; i <<= 1) for (i = 1; i < fsi->chan_num; i <<= 1)
io->fifo_max_num >>= 1; frame_capa >>= 1;
dev_dbg(dai->dev, "%d channel %d store\n", dev_dbg(dai->dev, "%d channel %d store\n",
fsi->chan_num, io->fifo_max_num); fsi->chan_num, frame_capa);
io->fifo_sample_capa = fsi_frame2sample(fsi, frame_capa);
/* /*
* set interrupt generation factor * set interrupt generation factor
...@@ -734,10 +755,10 @@ static int fsi_fifo_data_ctrl(struct fsi_priv *fsi, int stream) ...@@ -734,10 +755,10 @@ static int fsi_fifo_data_ctrl(struct fsi_priv *fsi, int stream)
struct snd_pcm_substream *substream = NULL; struct snd_pcm_substream *substream = NULL;
int is_play = fsi_stream_is_play(stream); int is_play = fsi_stream_is_play(stream);
struct fsi_stream *io = fsi_get_stream(fsi, is_play); struct fsi_stream *io = fsi_get_stream(fsi, is_play);
int data_residue_num; int sample_residues;
int data_num; int sample_width;
int data_num_max; int samples;
int ch_width; int samples_max;
int over_period; int over_period;
void (*fn)(struct fsi_priv *fsi, int size); void (*fn)(struct fsi_priv *fsi, int size);
...@@ -753,36 +774,35 @@ static int fsi_fifo_data_ctrl(struct fsi_priv *fsi, int stream) ...@@ -753,36 +774,35 @@ static int fsi_fifo_data_ctrl(struct fsi_priv *fsi, int stream)
/* 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 (io->buff_offset >= if (io->buff_sample_pos >=
fsi_num2offset(io->period_num + 1, io->period_len)) { io->period_samples * (io->period_pos + 1)) {
over_period = 1; over_period = 1;
io->period_num = (io->period_num + 1) % runtime->periods; io->period_pos = (io->period_pos + 1) % runtime->periods;
if (0 == io->period_num) if (0 == io->period_pos)
io->buff_offset = 0; io->buff_sample_pos = 0;
} }
/* get 1 channel data width */ /* get 1 sample data width */
ch_width = fsi_get_frame_width(fsi, is_play); sample_width = samples_to_bytes(runtime, 1);
/* get residue data number of alsa */ /* get number of residue samples */
data_residue_num = fsi_len2num(io->buff_len - io->buff_offset, sample_residues = io->buff_sample_capa - io->buff_sample_pos;
ch_width);
if (is_play) { if (is_play) {
/* /*
* for play-back * for play-back
* *
* data_num_max : number of FSI fifo free space * samples_max : number of FSI fifo free samples space
* data_num : number of ALSA residue data * samples : number of ALSA residue samples
*/ */
data_num_max = io->fifo_max_num * fsi->chan_num; samples_max = io->fifo_sample_capa;
data_num_max -= fsi_get_fifo_data_num(fsi, is_play); samples_max -= fsi_get_current_fifo_samples(fsi, is_play);
data_num = data_residue_num; samples = sample_residues;
switch (ch_width) { switch (sample_width) {
case 2: case 2:
fn = fsi_dma_soft_push16; fn = fsi_dma_soft_push16;
break; break;
...@@ -796,13 +816,13 @@ static int fsi_fifo_data_ctrl(struct fsi_priv *fsi, int stream) ...@@ -796,13 +816,13 @@ static int fsi_fifo_data_ctrl(struct fsi_priv *fsi, int stream)
/* /*
* for capture * for capture
* *
* data_num_max : number of ALSA free space * samples_max : number of ALSA free samples space
* data_num : number of data in FSI fifo * samples : number of samples in FSI fifo
*/ */
data_num_max = data_residue_num; samples_max = sample_residues;
data_num = fsi_get_fifo_data_num(fsi, is_play); samples = fsi_get_current_fifo_samples(fsi, is_play);
switch (ch_width) { switch (sample_width) {
case 2: case 2:
fn = fsi_dma_soft_pop16; fn = fsi_dma_soft_pop16;
break; break;
...@@ -814,12 +834,12 @@ static int fsi_fifo_data_ctrl(struct fsi_priv *fsi, int stream) ...@@ -814,12 +834,12 @@ static int fsi_fifo_data_ctrl(struct fsi_priv *fsi, int stream)
} }
} }
data_num = min(data_num, data_num_max); samples = min(samples, samples_max);
fn(fsi, data_num); fn(fsi, samples);
/* update buff_offset */ /* update buff_sample_pos */
io->buff_offset += fsi_num2offset(data_num, ch_width); io->buff_sample_pos += samples;
if (over_period) if (over_period)
snd_pcm_period_elapsed(substream); snd_pcm_period_elapsed(substream);
...@@ -1107,16 +1127,14 @@ static int fsi_hw_free(struct snd_pcm_substream *substream) ...@@ -1107,16 +1127,14 @@ static int fsi_hw_free(struct snd_pcm_substream *substream)
static snd_pcm_uframes_t fsi_pointer(struct snd_pcm_substream *substream) 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_priv *fsi = fsi_get_priv(substream);
struct fsi_stream *io = fsi_get_stream(fsi, fsi_is_play(substream)); struct fsi_stream *io = fsi_get_stream(fsi, fsi_is_play(substream));
long location; int samples_pos = io->buff_sample_pos - 1;
location = (io->buff_offset - 1); if (samples_pos < 0)
if (location < 0) samples_pos = 0;
location = 0;
return bytes_to_frames(runtime, location); return fsi_sample2frame(fsi, samples_pos);
} }
static struct snd_pcm_ops fsi_pcm_ops = { static struct snd_pcm_ops fsi_pcm_ops = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment