ASoC: rsnd: don't use rsnd_mod_to_io() on rsnd_dma_xxx()

Each Renesas sound mod (= SSI/SRC/DVC) might be called from many paths
if it supports MIXer. In such case, mod <-> io is no longer 1:1
relationship. This patch removes rsnd_mod_to_io() from rsnd_dma_xxx()
and related function

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Tested-by: Keita Kobayashi <keita.kobayashi.ym@renesas.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
Kuninori Morimoto 2015-06-15 06:26:25 +00:00 committed by Mark Brown
parent 4e2639ff38
commit 9b99e9a7c5
6 changed files with 85 additions and 71 deletions

View File

@ -137,12 +137,13 @@ char *rsnd_mod_name(struct rsnd_mod *mod)
return mod->ops->name;
}
struct dma_chan *rsnd_mod_dma_req(struct rsnd_mod *mod)
struct dma_chan *rsnd_mod_dma_req(struct rsnd_dai_stream *io,
struct rsnd_mod *mod)
{
if (!mod || !mod->ops || !mod->ops->dma_req)
return NULL;
return mod->ops->dma_req(mod);
return mod->ops->dma_req(io, mod);
}
int rsnd_mod_init(struct rsnd_priv *priv,

View File

@ -32,12 +32,10 @@ struct rsnd_dma_ctrl {
/*
* Audio DMAC
*/
static void rsnd_dmaen_complete(void *data)
static void __rsnd_dmaen_complete(struct rsnd_mod *mod,
struct rsnd_dai_stream *io)
{
struct rsnd_dma *dma = (struct rsnd_dma *)data;
struct rsnd_mod *mod = rsnd_dma_to_mod(dma);
struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
bool elapsed = false;
unsigned long flags;
@ -54,7 +52,8 @@ static void rsnd_dmaen_complete(void *data)
*/
spin_lock_irqsave(&priv->lock, flags);
elapsed = rsnd_dai_pointer_update(io, io->byte_per_period);
if (rsnd_mod_is_working(mod))
elapsed = rsnd_dai_pointer_update(io, io->byte_per_period);
spin_unlock_irqrestore(&priv->lock, flags);
@ -62,19 +61,25 @@ static void rsnd_dmaen_complete(void *data)
rsnd_dai_period_elapsed(io);
}
static void rsnd_dmaen_stop(struct rsnd_dma *dma)
static void rsnd_dmaen_complete(void *data)
{
struct rsnd_mod *mod = data;
rsnd_mod_interrupt(mod, __rsnd_dmaen_complete);
}
static void rsnd_dmaen_stop(struct rsnd_dai_stream *io, struct rsnd_dma *dma)
{
struct rsnd_dmaen *dmaen = rsnd_dma_to_dmaen(dma);
dmaengine_terminate_all(dmaen->chan);
}
static void rsnd_dmaen_start(struct rsnd_dma *dma)
static void rsnd_dmaen_start(struct rsnd_dai_stream *io, struct rsnd_dma *dma)
{
struct rsnd_dmaen *dmaen = rsnd_dma_to_dmaen(dma);
struct rsnd_mod *mod = rsnd_dma_to_mod(dma);
struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
struct snd_pcm_substream *substream = io->substream;
struct device *dev = rsnd_priv_to_dev(priv);
struct dma_async_tx_descriptor *desc;
@ -93,7 +98,7 @@ static void rsnd_dmaen_start(struct rsnd_dma *dma)
}
desc->callback = rsnd_dmaen_complete;
desc->callback_param = dma;
desc->callback_param = mod;
if (dmaengine_submit(desc) < 0) {
dev_err(dev, "dmaengine_submit() fail\n");
@ -124,7 +129,8 @@ struct dma_chan *rsnd_dma_request_channel(struct device_node *of_node,
return chan;
}
static struct dma_chan *rsnd_dmaen_request_channel(struct rsnd_mod *mod_from,
static struct dma_chan *rsnd_dmaen_request_channel(struct rsnd_dai_stream *io,
struct rsnd_mod *mod_from,
struct rsnd_mod *mod_to)
{
if ((!mod_from && !mod_to) ||
@ -132,19 +138,19 @@ static struct dma_chan *rsnd_dmaen_request_channel(struct rsnd_mod *mod_from,
return NULL;
if (mod_from)
return rsnd_mod_dma_req(mod_from);
return rsnd_mod_dma_req(io, mod_from);
else
return rsnd_mod_dma_req(mod_to);
return rsnd_mod_dma_req(io, mod_to);
}
static int rsnd_dmaen_init(struct rsnd_priv *priv, struct rsnd_dma *dma, int id,
static int rsnd_dmaen_init(struct rsnd_dai_stream *io,
struct rsnd_dma *dma, int id,
struct rsnd_mod *mod_from, struct rsnd_mod *mod_to)
{
struct rsnd_dmaen *dmaen = rsnd_dma_to_dmaen(dma);
struct rsnd_priv *priv = rsnd_io_to_priv(io);
struct device *dev = rsnd_priv_to_dev(priv);
struct dma_slave_config cfg = {};
struct rsnd_mod *mod = rsnd_dma_to_mod(dma);
struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
int is_play = rsnd_io_is_play(io);
int ret;
@ -154,7 +160,7 @@ static int rsnd_dmaen_init(struct rsnd_priv *priv, struct rsnd_dma *dma, int id,
}
if (dev->of_node) {
dmaen->chan = rsnd_dmaen_request_channel(mod_from, mod_to);
dmaen->chan = rsnd_dmaen_request_channel(io, mod_from, mod_to);
} else {
dma_cap_mask_t mask;
@ -185,7 +191,7 @@ static int rsnd_dmaen_init(struct rsnd_priv *priv, struct rsnd_dma *dma, int id,
return 0;
rsnd_dma_init_err:
rsnd_dma_quit(dma);
rsnd_dma_quit(io, dma);
rsnd_dma_channel_err:
/*
@ -197,7 +203,7 @@ rsnd_dma_channel_err:
return -EAGAIN;
}
static void rsnd_dmaen_quit(struct rsnd_dma *dma)
static void rsnd_dmaen_quit(struct rsnd_dai_stream *io, struct rsnd_dma *dma)
{
struct rsnd_dmaen *dmaen = rsnd_dma_to_dmaen(dma);
@ -246,9 +252,9 @@ static const u8 gen2_id_table_cmd[] = {
0x38, /* SCU_CMD1 */
};
static u32 rsnd_dmapp_get_id(struct rsnd_mod *mod)
static u32 rsnd_dmapp_get_id(struct rsnd_dai_stream *io,
struct rsnd_mod *mod)
{
struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
struct rsnd_mod *ssi = rsnd_io_to_mod_ssi(io);
struct rsnd_mod *src = rsnd_io_to_mod_src(io);
struct rsnd_mod *dvc = rsnd_io_to_mod_dvc(io);
@ -276,11 +282,12 @@ static u32 rsnd_dmapp_get_id(struct rsnd_mod *mod)
return entry[id];
}
static u32 rsnd_dmapp_get_chcr(struct rsnd_mod *mod_from,
static u32 rsnd_dmapp_get_chcr(struct rsnd_dai_stream *io,
struct rsnd_mod *mod_from,
struct rsnd_mod *mod_to)
{
return (rsnd_dmapp_get_id(mod_from) << 24) +
(rsnd_dmapp_get_id(mod_to) << 16);
return (rsnd_dmapp_get_id(io, mod_from) << 24) +
(rsnd_dmapp_get_id(io, mod_to) << 16);
}
#define rsnd_dmapp_addr(dmac, dma, reg) \
@ -307,7 +314,7 @@ static u32 rsnd_dmapp_read(struct rsnd_dma *dma, u32 reg)
return ioread32(rsnd_dmapp_addr(dmac, dma, reg));
}
static void rsnd_dmapp_stop(struct rsnd_dma *dma)
static void rsnd_dmapp_stop(struct rsnd_dai_stream *io, struct rsnd_dma *dma)
{
int i;
@ -320,7 +327,7 @@ static void rsnd_dmapp_stop(struct rsnd_dma *dma)
}
}
static void rsnd_dmapp_start(struct rsnd_dma *dma)
static void rsnd_dmapp_start(struct rsnd_dai_stream *io, struct rsnd_dma *dma)
{
struct rsnd_dmapp *dmapp = rsnd_dma_to_dmapp(dma);
@ -329,19 +336,21 @@ static void rsnd_dmapp_start(struct rsnd_dma *dma)
rsnd_dmapp_write(dma, dmapp->chcr, PDMACHCR);
}
static int rsnd_dmapp_init(struct rsnd_priv *priv, struct rsnd_dma *dma, int id,
static int rsnd_dmapp_init(struct rsnd_dai_stream *io,
struct rsnd_dma *dma, int id,
struct rsnd_mod *mod_from, struct rsnd_mod *mod_to)
{
struct rsnd_dmapp *dmapp = rsnd_dma_to_dmapp(dma);
struct rsnd_priv *priv = rsnd_io_to_priv(io);
struct rsnd_dma_ctrl *dmac = rsnd_priv_to_dmac(priv);
struct device *dev = rsnd_priv_to_dev(priv);
dmapp->dmapp_id = dmac->dmapp_num;
dmapp->chcr = rsnd_dmapp_get_chcr(mod_from, mod_to) | PDMACHCR_DE;
dmapp->chcr = rsnd_dmapp_get_chcr(io, mod_from, mod_to) | PDMACHCR_DE;
dmac->dmapp_num++;
rsnd_dmapp_stop(dma);
rsnd_dmapp_stop(io, dma);
dev_dbg(dev, "id/src/dst/chcr = %d/%pad/%pad/%08x\n",
dmapp->dmapp_id, &dma->src_addr, &dma->dst_addr, dmapp->chcr);
@ -394,12 +403,12 @@ static struct rsnd_dma_ops rsnd_dmapp_ops = {
#define RDMA_CMD_O_P(addr, i) (addr ##_reg - 0x001f8000 + (0x400 * i))
static dma_addr_t
rsnd_gen2_dma_addr(struct rsnd_priv *priv,
rsnd_gen2_dma_addr(struct rsnd_dai_stream *io,
struct rsnd_mod *mod,
int is_play, int is_from)
{
struct rsnd_priv *priv = rsnd_io_to_priv(io);
struct device *dev = rsnd_priv_to_dev(priv);
struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
phys_addr_t ssi_reg = rsnd_gen_get_phy_addr(priv, RSND_GEN2_SSI);
phys_addr_t src_reg = rsnd_gen_get_phy_addr(priv, RSND_GEN2_SCU);
int is_ssi = !!(rsnd_io_to_mod_ssi(io) == mod);
@ -454,10 +463,12 @@ rsnd_gen2_dma_addr(struct rsnd_priv *priv,
dma_addrs[is_ssi][is_play][use_src + use_dvc].in_addr;
}
static dma_addr_t rsnd_dma_addr(struct rsnd_priv *priv,
static dma_addr_t rsnd_dma_addr(struct rsnd_dai_stream *io,
struct rsnd_mod *mod,
int is_play, int is_from)
{
struct rsnd_priv *priv = rsnd_io_to_priv(io);
/*
* gen1 uses default DMA addr
*/
@ -467,17 +478,17 @@ static dma_addr_t rsnd_dma_addr(struct rsnd_priv *priv,
if (!mod)
return 0;
return rsnd_gen2_dma_addr(priv, mod, is_play, is_from);
return rsnd_gen2_dma_addr(io, mod, is_play, is_from);
}
#define MOD_MAX 4 /* MEM/SSI/SRC/DVC */
static void rsnd_dma_of_path(struct rsnd_dma *dma,
struct rsnd_dai_stream *io,
int is_play,
struct rsnd_mod **mod_from,
struct rsnd_mod **mod_to)
{
struct rsnd_mod *this = rsnd_dma_to_mod(dma);
struct rsnd_dai_stream *io = rsnd_mod_to_io(this);
struct rsnd_mod *ssi = rsnd_io_to_mod_ssi(io);
struct rsnd_mod *src = rsnd_io_to_mod_src(io);
struct rsnd_mod *dvc = rsnd_io_to_mod_dvc(io);
@ -532,17 +543,17 @@ static void rsnd_dma_of_path(struct rsnd_dma *dma,
}
}
void rsnd_dma_stop(struct rsnd_dma *dma)
void rsnd_dma_stop(struct rsnd_dai_stream *io, struct rsnd_dma *dma)
{
dma->ops->stop(dma);
dma->ops->stop(io, dma);
}
void rsnd_dma_start(struct rsnd_dma *dma)
void rsnd_dma_start(struct rsnd_dai_stream *io, struct rsnd_dma *dma)
{
dma->ops->start(dma);
dma->ops->start(io, dma);
}
void rsnd_dma_quit(struct rsnd_dma *dma)
void rsnd_dma_quit(struct rsnd_dai_stream *io, struct rsnd_dma *dma)
{
struct rsnd_mod *mod = rsnd_dma_to_mod(dma);
struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
@ -551,15 +562,14 @@ void rsnd_dma_quit(struct rsnd_dma *dma)
if (!dmac)
return;
dma->ops->quit(dma);
dma->ops->quit(io, dma);
}
int rsnd_dma_init(struct rsnd_priv *priv, struct rsnd_dma *dma, int id)
int rsnd_dma_init(struct rsnd_dai_stream *io, struct rsnd_dma *dma, int id)
{
struct rsnd_mod *mod = rsnd_dma_to_mod(dma);
struct rsnd_mod *mod_from;
struct rsnd_mod *mod_to;
struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
struct rsnd_priv *priv = rsnd_io_to_priv(io);
struct rsnd_dma_ctrl *dmac = rsnd_priv_to_dmac(priv);
int is_play = rsnd_io_is_play(io);
@ -572,10 +582,10 @@ int rsnd_dma_init(struct rsnd_priv *priv, struct rsnd_dma *dma, int id)
if (!dmac)
return -EAGAIN;
rsnd_dma_of_path(dma, is_play, &mod_from, &mod_to);
rsnd_dma_of_path(dma, io, is_play, &mod_from, &mod_to);
dma->src_addr = rsnd_dma_addr(priv, mod_from, is_play, 1);
dma->dst_addr = rsnd_dma_addr(priv, mod_to, is_play, 0);
dma->src_addr = rsnd_dma_addr(io, mod_from, is_play, 1);
dma->dst_addr = rsnd_dma_addr(io, mod_to, is_play, 0);
/* for Gen2 */
if (mod_from && mod_to)
@ -587,7 +597,7 @@ int rsnd_dma_init(struct rsnd_priv *priv, struct rsnd_dma *dma, int id)
if (rsnd_is_gen1(priv))
dma->ops = &rsnd_dmaen_ops;
return dma->ops->init(priv, dma, id, mod_from, mod_to);
return dma->ops->init(io, dma, id, mod_from, mod_to);
}
int rsnd_dma_probe(struct platform_device *pdev,

View File

@ -265,7 +265,8 @@ static int rsnd_dvc_pcm_new(struct rsnd_mod *mod,
return 0;
}
static struct dma_chan *rsnd_dvc_dma_req(struct rsnd_mod *mod)
static struct dma_chan *rsnd_dvc_dma_req(struct rsnd_dai_stream *io,
struct rsnd_mod *mod)
{
struct rsnd_priv *priv = rsnd_mod_to_priv(mod);

View File

@ -172,11 +172,11 @@ u32 rsnd_get_adinr(struct rsnd_mod *mod, struct rsnd_dai_stream *io);
*/
struct rsnd_dma;
struct rsnd_dma_ops {
void (*start)(struct rsnd_dma *dma);
void (*stop)(struct rsnd_dma *dma);
int (*init)(struct rsnd_priv *priv, struct rsnd_dma *dma, int id,
void (*start)(struct rsnd_dai_stream *io, struct rsnd_dma *dma);
void (*stop)(struct rsnd_dai_stream *io, struct rsnd_dma *dma);
int (*init)(struct rsnd_dai_stream *io, struct rsnd_dma *dma, int id,
struct rsnd_mod *mod_from, struct rsnd_mod *mod_to);
void (*quit)(struct rsnd_dma *dma);
void (*quit)(struct rsnd_dai_stream *io, struct rsnd_dma *dma);
};
struct rsnd_dmaen {
@ -200,10 +200,10 @@ struct rsnd_dma {
#define rsnd_dma_to_dmaen(dma) (&(dma)->dma.en)
#define rsnd_dma_to_dmapp(dma) (&(dma)->dma.pp)
void rsnd_dma_start(struct rsnd_dma *dma);
void rsnd_dma_stop(struct rsnd_dma *dma);
int rsnd_dma_init(struct rsnd_priv *priv, struct rsnd_dma *dma, int id);
void rsnd_dma_quit(struct rsnd_dma *dma);
void rsnd_dma_start(struct rsnd_dai_stream *io, struct rsnd_dma *dma);
void rsnd_dma_stop(struct rsnd_dai_stream *io, struct rsnd_dma *dma);
int rsnd_dma_init(struct rsnd_dai_stream *io, struct rsnd_dma *dma, int id);
void rsnd_dma_quit(struct rsnd_dai_stream *io, struct rsnd_dma *dma);
int rsnd_dma_probe(struct platform_device *pdev,
const struct rsnd_of_data *of_data,
struct rsnd_priv *priv);
@ -224,7 +224,8 @@ enum rsnd_mod_type {
struct rsnd_mod_ops {
char *name;
struct dma_chan* (*dma_req)(struct rsnd_mod *mod);
struct dma_chan* (*dma_req)(struct rsnd_dai_stream *io,
struct rsnd_mod *mod);
int (*probe)(struct rsnd_mod *mod,
struct rsnd_dai_stream *io,
struct rsnd_priv *priv);
@ -326,7 +327,8 @@ int rsnd_mod_init(struct rsnd_priv *priv,
void rsnd_mod_quit(struct rsnd_mod *mod);
char *rsnd_mod_name(struct rsnd_mod *mod);
int rsnd_mod_is_working(struct rsnd_mod *mod);
struct dma_chan *rsnd_mod_dma_req(struct rsnd_mod *mod);
struct dma_chan *rsnd_mod_dma_req(struct rsnd_dai_stream *io,
struct rsnd_mod *mod);
void rsnd_mod_interrupt(struct rsnd_mod *mod,
void (*callback)(struct rsnd_mod *mod,
struct rsnd_dai_stream *io));

View File

@ -117,10 +117,10 @@ struct rsnd_src {
/*
* Gen1/Gen2 common functions
*/
static struct dma_chan *rsnd_src_dma_req(struct rsnd_mod *mod)
static struct dma_chan *rsnd_src_dma_req(struct rsnd_dai_stream *io,
struct rsnd_mod *mod)
{
struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
int is_play = rsnd_io_is_play(io);
return rsnd_dma_request_channel(rsnd_src_of_node(priv),
@ -810,7 +810,7 @@ static int rsnd_src_probe_gen2(struct rsnd_mod *mod,
return ret;
}
ret = rsnd_dma_init(priv,
ret = rsnd_dma_init(io,
rsnd_mod_to_dma(mod),
src->info->dma_id);
@ -821,7 +821,7 @@ static int rsnd_src_remove_gen2(struct rsnd_mod *mod,
struct rsnd_dai_stream *io,
struct rsnd_priv *priv)
{
rsnd_dma_quit(rsnd_mod_to_dma(mod));
rsnd_dma_quit(io, rsnd_mod_to_dma(mod));
return 0;
}
@ -851,7 +851,7 @@ static int rsnd_src_start_gen2(struct rsnd_mod *mod,
struct rsnd_dai_stream *io,
struct rsnd_priv *priv)
{
rsnd_dma_start(rsnd_mod_to_dma(mod));
rsnd_dma_start(io, rsnd_mod_to_dma(mod));
return _rsnd_src_start_gen2(mod);
}
@ -864,7 +864,7 @@ static int rsnd_src_stop_gen2(struct rsnd_mod *mod,
ret = _rsnd_src_stop_gen2(mod);
rsnd_dma_stop(rsnd_mod_to_dma(mod));
rsnd_dma_stop(io, rsnd_mod_to_dma(mod));
return ret;
}

View File

@ -533,7 +533,7 @@ static int rsnd_ssi_dma_probe(struct rsnd_mod *mod,
return ret;
ret = rsnd_dma_init(
priv, rsnd_mod_to_dma(mod),
io, rsnd_mod_to_dma(mod),
dma_id);
return ret;
@ -547,7 +547,7 @@ static int rsnd_ssi_dma_remove(struct rsnd_mod *mod,
struct device *dev = rsnd_priv_to_dev(priv);
int irq = ssi->info->irq;
rsnd_dma_quit(rsnd_mod_to_dma(mod));
rsnd_dma_quit(io, rsnd_mod_to_dma(mod));
/* PIO will request IRQ again */
devm_free_irq(dev, irq, ssi);
@ -582,7 +582,7 @@ static int rsnd_ssi_dma_start(struct rsnd_mod *mod,
{
struct rsnd_dma *dma = rsnd_mod_to_dma(mod);
rsnd_dma_start(dma);
rsnd_dma_start(io, dma);
rsnd_ssi_start(mod, io, priv);
@ -597,15 +597,15 @@ static int rsnd_ssi_dma_stop(struct rsnd_mod *mod,
rsnd_ssi_stop(mod, io, priv);
rsnd_dma_stop(dma);
rsnd_dma_stop(io, dma);
return 0;
}
static struct dma_chan *rsnd_ssi_dma_req(struct rsnd_mod *mod)
static struct dma_chan *rsnd_ssi_dma_req(struct rsnd_dai_stream *io,
struct rsnd_mod *mod)
{
struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
int is_play = rsnd_io_is_play(io);
char *name;