summaryrefslogtreecommitdiff
path: root/sound/soc/sh/fsi.c
diff options
context:
space:
mode:
Diffstat (limited to 'sound/soc/sh/fsi.c')
-rw-r--r--sound/soc/sh/fsi.c152
1 files changed, 94 insertions, 58 deletions
diff --git a/sound/soc/sh/fsi.c b/sound/soc/sh/fsi.c
index dfc04bc2809e..507e709f2807 100644
--- a/sound/soc/sh/fsi.c
+++ b/sound/soc/sh/fsi.c
@@ -113,10 +113,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 +123,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,9 +300,20 @@ static u32 fsi_get_info_flags(struct fsi_priv *fsi)
master->info->portb_flags;
}
+static inline int fsi_stream_is_play(int stream)
+{
+ return stream == SNDRV_PCM_STREAM_PLAYBACK;
+}
+
static inline int fsi_is_play(struct snd_pcm_substream *substream)
{
- return substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
+ return fsi_stream_is_play(substream->stream);
+}
+
+static inline struct fsi_stream *fsi_get_stream(struct fsi_priv *fsi,
+ int is_play)
+{
+ return is_play ? &fsi->playback : &fsi->capture;
}
static int fsi_is_master_mode(struct fsi_priv *fsi, int is_play)
@@ -328,35 +345,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 +395,25 @@ 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 stream)
{
- return fsi->substream->runtime->dma_area + fsi->buff_offset;
+ int is_play = fsi_stream_is_play(stream);
+ 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 +421,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, SNDRV_PCM_STREAM_PLAYBACK);
for (i = 0; i < num; i++)
fsi_reg_write(fsi, DODT, ((u32)*(start + i) << 8));
@@ -405,7 +432,8 @@ 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, SNDRV_PCM_STREAM_CAPTURE);
+
for (i = 0; i < num; i++)
*(start + i) = (u16)(fsi_reg_read(fsi, DIDT) >> 8);
@@ -416,7 +444,8 @@ 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, SNDRV_PCM_STREAM_PLAYBACK);
+
for (i = 0; i < num; i++)
fsi_reg_write(fsi, DODT, *(start + i));
@@ -427,7 +456,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, SNDRV_PCM_STREAM_CAPTURE);
for (i = 0; i < num; i++)
*(start + i) = fsi_reg_read(fsi, DIDT);
@@ -518,14 +547,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 +576,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;
@@ -572,10 +602,12 @@ static void fsi_soft_all_reset(struct fsi_master *master)
mdelay(10);
}
-static int fsi_fifo_data_ctrl(struct fsi_priv *fsi, int startup, int is_play)
+static int fsi_fifo_data_ctrl(struct fsi_priv *fsi, int startup, int stream)
{
struct snd_pcm_runtime *runtime;
struct snd_pcm_substream *substream = NULL;
+ int is_play = fsi_stream_is_play(stream);
+ 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 +617,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 +652,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 +694,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 +719,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, SNDRV_PCM_STREAM_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, SNDRV_PCM_STREAM_PLAYBACK);
}
static irqreturn_t fsi_interrupt(int irq, void *data)
@@ -726,14 +758,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 +799,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 +829,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 +871,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 +1026,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;