Commit 940e9479 authored by Kuninori Morimoto's avatar Kuninori Morimoto Committed by Mark Brown

ASoC: rsnd: use mod base common method on DMA phase1

Renesas sound needs many devices
(SSI/SSIU/SRC/CTU/MIX/DVC/CMD/AudioDMAC/AudioDMACpp).
SSI/SRC/CTU/MIX/DVC are implemented as module.
SSI parent, SSIU are implemented as part of SSI
CMD is implemented as part of CTU/MIX/DVC
AudioDMAC/AudioDMACpp are implemented as part of SSI/SRC
It is nice sense that these all devices are implemented as mod.

DMA will be implemented as module. Then rsnd_dma will be mod base.
This patch makes rsnd_dma mod base, but still not yet completely
finished. This mod is not yet installed to system at this point.
Signed-off-by: default avatarKuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent e10369d8
...@@ -34,7 +34,8 @@ struct rsnd_dmapp { ...@@ -34,7 +34,8 @@ struct rsnd_dmapp {
struct rsnd_dma { struct rsnd_dma {
struct rsnd_dma_ops *ops; struct rsnd_dma_ops *ops;
struct rsnd_mod *mod; struct rsnd_mod mod;
struct rsnd_mod *user_mod;
dma_addr_t src_addr; dma_addr_t src_addr;
dma_addr_t dst_addr; dma_addr_t dst_addr;
union { union {
...@@ -45,6 +46,7 @@ struct rsnd_dma { ...@@ -45,6 +46,7 @@ struct rsnd_dma {
struct rsnd_dma_ctrl { struct rsnd_dma_ctrl {
void __iomem *base; void __iomem *base;
int dmaen_num;
int dmapp_num; int dmapp_num;
}; };
...@@ -56,9 +58,9 @@ struct rsnd_dma_ops { ...@@ -56,9 +58,9 @@ struct rsnd_dma_ops {
}; };
#define rsnd_priv_to_dmac(p) ((struct rsnd_dma_ctrl *)(p)->dma) #define rsnd_priv_to_dmac(p) ((struct rsnd_dma_ctrl *)(p)->dma)
#define rsnd_mod_to_dma(_mod) container_of((_mod), struct rsnd_dma, mod)
#define rsnd_dma_to_dmaen(dma) (&(dma)->dma.en) #define rsnd_dma_to_dmaen(dma) (&(dma)->dma.en)
#define rsnd_dma_to_dmapp(dma) (&(dma)->dma.pp) #define rsnd_dma_to_dmapp(dma) (&(dma)->dma.pp)
#define rsnd_dma_to_mod(_dma) ((dma)->mod)
/* /*
* Audio DMAC * Audio DMAC
...@@ -109,8 +111,8 @@ static void rsnd_dmaen_stop(struct rsnd_dai_stream *io, struct rsnd_dma *dma) ...@@ -109,8 +111,8 @@ static void rsnd_dmaen_stop(struct rsnd_dai_stream *io, struct rsnd_dma *dma)
static void rsnd_dmaen_start(struct rsnd_dai_stream *io, 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_dmaen *dmaen = rsnd_dma_to_dmaen(dma);
struct rsnd_mod *mod = rsnd_dma_to_mod(dma); struct rsnd_mod *user_mod = dma->user_mod;
struct rsnd_priv *priv = rsnd_mod_to_priv(mod); struct rsnd_priv *priv = rsnd_io_to_priv(io);
struct snd_pcm_substream *substream = io->substream; struct snd_pcm_substream *substream = io->substream;
struct device *dev = rsnd_priv_to_dev(priv); struct device *dev = rsnd_priv_to_dev(priv);
struct dma_async_tx_descriptor *desc; struct dma_async_tx_descriptor *desc;
...@@ -129,7 +131,7 @@ static void rsnd_dmaen_start(struct rsnd_dai_stream *io, struct rsnd_dma *dma) ...@@ -129,7 +131,7 @@ static void rsnd_dmaen_start(struct rsnd_dai_stream *io, struct rsnd_dma *dma)
} }
desc->callback = rsnd_dmaen_complete; desc->callback = rsnd_dmaen_complete;
desc->callback_param = mod; desc->callback_param = user_mod;
if (dmaengine_submit(desc) < 0) { if (dmaengine_submit(desc) < 0) {
dev_err(dev, "dmaengine_submit() fail\n"); dev_err(dev, "dmaengine_submit() fail\n");
...@@ -180,6 +182,7 @@ static int rsnd_dmaen_attach(struct rsnd_dai_stream *io, ...@@ -180,6 +182,7 @@ static int rsnd_dmaen_attach(struct rsnd_dai_stream *io,
{ {
struct rsnd_dmaen *dmaen = rsnd_dma_to_dmaen(dma); struct rsnd_dmaen *dmaen = rsnd_dma_to_dmaen(dma);
struct rsnd_priv *priv = rsnd_io_to_priv(io); 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); struct device *dev = rsnd_priv_to_dev(priv);
struct dma_slave_config cfg = {}; struct dma_slave_config cfg = {};
int is_play = rsnd_io_is_play(io); int is_play = rsnd_io_is_play(io);
...@@ -221,10 +224,12 @@ static int rsnd_dmaen_attach(struct rsnd_dai_stream *io, ...@@ -221,10 +224,12 @@ static int rsnd_dmaen_attach(struct rsnd_dai_stream *io,
if (ret < 0) if (ret < 0)
goto rsnd_dma_attach_err; goto rsnd_dma_attach_err;
dmac->dmaen_num++;
return 0; return 0;
rsnd_dma_attach_err: rsnd_dma_attach_err:
rsnd_dma_quit(io, dma); rsnd_dma_quit(io, rsnd_mod_get(dma));
rsnd_dma_channel_err: rsnd_dma_channel_err:
/* /*
...@@ -328,7 +333,7 @@ static u32 rsnd_dmapp_get_chcr(struct rsnd_dai_stream *io, ...@@ -328,7 +333,7 @@ static u32 rsnd_dmapp_get_chcr(struct rsnd_dai_stream *io,
(0x10 * rsnd_dma_to_dmapp(dma)->dmapp_id)) (0x10 * rsnd_dma_to_dmapp(dma)->dmapp_id))
static void rsnd_dmapp_write(struct rsnd_dma *dma, u32 data, u32 reg) static void rsnd_dmapp_write(struct rsnd_dma *dma, u32 data, u32 reg)
{ {
struct rsnd_mod *mod = rsnd_dma_to_mod(dma); struct rsnd_mod *mod = rsnd_mod_get(dma);
struct rsnd_priv *priv = rsnd_mod_to_priv(mod); struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
struct rsnd_dma_ctrl *dmac = rsnd_priv_to_dmac(priv); struct rsnd_dma_ctrl *dmac = rsnd_priv_to_dmac(priv);
struct device *dev = rsnd_priv_to_dev(priv); struct device *dev = rsnd_priv_to_dev(priv);
...@@ -340,7 +345,7 @@ static void rsnd_dmapp_write(struct rsnd_dma *dma, u32 data, u32 reg) ...@@ -340,7 +345,7 @@ static void rsnd_dmapp_write(struct rsnd_dma *dma, u32 data, u32 reg)
static u32 rsnd_dmapp_read(struct rsnd_dma *dma, u32 reg) static u32 rsnd_dmapp_read(struct rsnd_dma *dma, u32 reg)
{ {
struct rsnd_mod *mod = rsnd_dma_to_mod(dma); struct rsnd_mod *mod = rsnd_mod_get(dma);
struct rsnd_priv *priv = rsnd_mod_to_priv(mod); struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
struct rsnd_dma_ctrl *dmac = rsnd_priv_to_dmac(priv); struct rsnd_dma_ctrl *dmac = rsnd_priv_to_dmac(priv);
...@@ -517,13 +522,12 @@ static dma_addr_t rsnd_dma_addr(struct rsnd_dai_stream *io, ...@@ -517,13 +522,12 @@ static dma_addr_t rsnd_dma_addr(struct rsnd_dai_stream *io,
} }
#define MOD_MAX (RSND_MOD_MAX + 1) /* +Memory */ #define MOD_MAX (RSND_MOD_MAX + 1) /* +Memory */
static void rsnd_dma_of_path(struct rsnd_dma *dma, static void rsnd_dma_of_path(struct rsnd_mod *this,
struct rsnd_dai_stream *io, struct rsnd_dai_stream *io,
int is_play, int is_play,
struct rsnd_mod **mod_from, struct rsnd_mod **mod_from,
struct rsnd_mod **mod_to) struct rsnd_mod **mod_to)
{ {
struct rsnd_mod *this = rsnd_dma_to_mod(dma);
struct rsnd_mod *ssi = rsnd_io_to_mod_ssi(io); struct rsnd_mod *ssi = rsnd_io_to_mod_ssi(io);
struct rsnd_mod *src = rsnd_io_to_mod_src(io); struct rsnd_mod *src = rsnd_io_to_mod_src(io);
struct rsnd_mod *ctu = rsnd_io_to_mod_ctu(io); struct rsnd_mod *ctu = rsnd_io_to_mod_ctu(io);
...@@ -605,19 +609,23 @@ static void rsnd_dma_of_path(struct rsnd_dma *dma, ...@@ -605,19 +609,23 @@ static void rsnd_dma_of_path(struct rsnd_dma *dma,
} }
} }
void rsnd_dma_stop(struct rsnd_dai_stream *io, struct rsnd_dma *dma) void rsnd_dma_stop(struct rsnd_dai_stream *io, struct rsnd_mod *mod)
{ {
struct rsnd_dma *dma = rsnd_mod_to_dma(mod);
dma->ops->stop(io, dma); dma->ops->stop(io, dma);
} }
void rsnd_dma_start(struct rsnd_dai_stream *io, struct rsnd_dma *dma) void rsnd_dma_start(struct rsnd_dai_stream *io, struct rsnd_mod *mod)
{ {
struct rsnd_dma *dma = rsnd_mod_to_dma(mod);
dma->ops->start(io, dma); dma->ops->start(io, dma);
} }
void rsnd_dma_quit(struct rsnd_dai_stream *io, struct rsnd_dma *dma) void rsnd_dma_quit(struct rsnd_dai_stream *io, struct rsnd_mod *mod)
{ {
struct rsnd_mod *mod = rsnd_dma_to_mod(dma); struct rsnd_dma *dma = rsnd_mod_to_dma(mod);
struct rsnd_priv *priv = rsnd_mod_to_priv(mod); struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
struct rsnd_dma_ctrl *dmac = rsnd_priv_to_dmac(priv); struct rsnd_dma_ctrl *dmac = rsnd_priv_to_dmac(priv);
...@@ -627,9 +635,13 @@ void rsnd_dma_quit(struct rsnd_dai_stream *io, struct rsnd_dma *dma) ...@@ -627,9 +635,13 @@ void rsnd_dma_quit(struct rsnd_dai_stream *io, struct rsnd_dma *dma)
dma->ops->quit(io, dma); dma->ops->quit(io, dma);
} }
struct rsnd_dma *rsnd_dma_attach(struct rsnd_dai_stream *io, static struct rsnd_mod_ops rsnd_dma_ops = {
};
struct rsnd_mod *rsnd_dma_attach(struct rsnd_dai_stream *io,
struct rsnd_mod *mod, int id) struct rsnd_mod *mod, int id)
{ {
struct rsnd_mod *dma_mod;
struct rsnd_mod *mod_from = NULL; struct rsnd_mod *mod_from = NULL;
struct rsnd_mod *mod_to = NULL; struct rsnd_mod *mod_to = NULL;
struct rsnd_priv *priv = rsnd_io_to_priv(io); struct rsnd_priv *priv = rsnd_io_to_priv(io);
...@@ -639,7 +651,7 @@ struct rsnd_dma *rsnd_dma_attach(struct rsnd_dai_stream *io, ...@@ -639,7 +651,7 @@ struct rsnd_dma *rsnd_dma_attach(struct rsnd_dai_stream *io,
int (*attach)(struct rsnd_dai_stream *io, struct rsnd_dma *dma, int id, int (*attach)(struct rsnd_dai_stream *io, struct rsnd_dma *dma, int id,
struct rsnd_mod *mod_from, struct rsnd_mod *mod_to); struct rsnd_mod *mod_from, struct rsnd_mod *mod_to);
int is_play = rsnd_io_is_play(io); int is_play = rsnd_io_is_play(io);
int ret; int ret, dma_id;
/* /*
* DMA failed. try to PIO mode * DMA failed. try to PIO mode
...@@ -654,10 +666,9 @@ struct rsnd_dma *rsnd_dma_attach(struct rsnd_dai_stream *io, ...@@ -654,10 +666,9 @@ struct rsnd_dma *rsnd_dma_attach(struct rsnd_dai_stream *io,
if (!dma) if (!dma)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
dma->mod = mod; rsnd_dma_of_path(mod, io, is_play, &mod_from, &mod_to);
rsnd_dma_of_path(dma, io, is_play, &mod_from, &mod_to);
dma->user_mod = mod;
dma->src_addr = rsnd_dma_addr(io, mod_from, is_play, 1); dma->src_addr = rsnd_dma_addr(io, mod_from, is_play, 1);
dma->dst_addr = rsnd_dma_addr(io, mod_to, is_play, 0); dma->dst_addr = rsnd_dma_addr(io, mod_to, is_play, 0);
...@@ -665,27 +676,37 @@ struct rsnd_dma *rsnd_dma_attach(struct rsnd_dai_stream *io, ...@@ -665,27 +676,37 @@ struct rsnd_dma *rsnd_dma_attach(struct rsnd_dai_stream *io,
if (mod_from && mod_to) { if (mod_from && mod_to) {
dma->ops = &rsnd_dmapp_ops; dma->ops = &rsnd_dmapp_ops;
attach = rsnd_dmapp_attach; attach = rsnd_dmapp_attach;
dma_id = dmac->dmapp_num;
} else { } else {
dma->ops = &rsnd_dmaen_ops; dma->ops = &rsnd_dmaen_ops;
attach = rsnd_dmaen_attach; attach = rsnd_dmaen_attach;
dma_id = dmac->dmaen_num;
} }
/* for Gen1, overwrite */ /* for Gen1, overwrite */
if (rsnd_is_gen1(priv)) { if (rsnd_is_gen1(priv)) {
dma->ops = &rsnd_dmaen_ops; dma->ops = &rsnd_dmaen_ops;
attach = rsnd_dmaen_attach; attach = rsnd_dmaen_attach;
dma_id = dmac->dmaen_num;
} }
dma_mod = rsnd_mod_get(dma);
dev_dbg(dev, "%s %s[%d] -> %s[%d]\n", dev_dbg(dev, "%s %s[%d] -> %s[%d]\n",
dma->ops->name, dma->ops->name,
rsnd_mod_name(mod_from), rsnd_mod_id(mod_from), rsnd_mod_name(mod_from), rsnd_mod_id(mod_from),
rsnd_mod_name(mod_to), rsnd_mod_id(mod_to)); rsnd_mod_name(mod_to), rsnd_mod_id(mod_to));
ret = rsnd_mod_init(priv, dma_mod,
&rsnd_dma_ops, NULL, 0, dma_id);
if (ret < 0)
return ERR_PTR(ret);
ret = attach(io, dma, id, mod_from, mod_to); ret = attach(io, dma, id, mod_from, mod_to);
if (ret < 0) if (ret < 0)
return ERR_PTR(ret); return ERR_PTR(ret);
return dma; return rsnd_mod_get(dma);
} }
int rsnd_dma_probe(struct platform_device *pdev, int rsnd_dma_probe(struct platform_device *pdev,
......
...@@ -193,13 +193,11 @@ void rsnd_path_parse(struct rsnd_priv *priv, ...@@ -193,13 +193,11 @@ void rsnd_path_parse(struct rsnd_priv *priv,
/* /*
* R-Car DMA * R-Car DMA
*/ */
struct rsnd_dma; void rsnd_dma_start(struct rsnd_dai_stream *io, struct rsnd_mod *mod);
void rsnd_dma_stop(struct rsnd_dai_stream *io, struct rsnd_mod *mod);
void rsnd_dma_start(struct rsnd_dai_stream *io, struct rsnd_dma *dma); struct rsnd_mod *rsnd_dma_attach(struct rsnd_dai_stream *io,
void rsnd_dma_stop(struct rsnd_dai_stream *io, struct rsnd_dma *dma);
struct rsnd_dma *rsnd_dma_attach(struct rsnd_dai_stream *io,
struct rsnd_mod *mod, int id); struct rsnd_mod *mod, int id);
void rsnd_dma_quit(struct rsnd_dai_stream *io, struct rsnd_dma *dma); void rsnd_dma_quit(struct rsnd_dai_stream *io, struct rsnd_mod *mod);
int rsnd_dma_probe(struct platform_device *pdev, int rsnd_dma_probe(struct platform_device *pdev,
const struct rsnd_of_data *of_data, const struct rsnd_of_data *of_data,
struct rsnd_priv *priv); struct rsnd_priv *priv);
...@@ -210,7 +208,9 @@ struct dma_chan *rsnd_dma_request_channel(struct device_node *of_node, ...@@ -210,7 +208,9 @@ struct dma_chan *rsnd_dma_request_channel(struct device_node *of_node,
* R-Car sound mod * R-Car sound mod
*/ */
enum rsnd_mod_type { enum rsnd_mod_type {
RSND_MOD_DVC = 0, RSND_MOD_AUDMAPP,
RSND_MOD_AUDMA,
RSND_MOD_DVC,
RSND_MOD_MIX, RSND_MOD_MIX,
RSND_MOD_CTU, RSND_MOD_CTU,
RSND_MOD_SRC, RSND_MOD_SRC,
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
struct rsnd_src { struct rsnd_src {
struct rsnd_src_platform_info *info; /* rcar_snd.h */ struct rsnd_src_platform_info *info; /* rcar_snd.h */
struct rsnd_mod mod; struct rsnd_mod mod;
struct rsnd_dma *dma; struct rsnd_mod *dma;
struct rsnd_kctrl_cfg_s sen; /* sync convert enable */ struct rsnd_kctrl_cfg_s sen; /* sync convert enable */
struct rsnd_kctrl_cfg_s sync; /* sync convert */ struct rsnd_kctrl_cfg_s sync; /* sync convert */
u32 convert_rate; /* sampling rate convert */ u32 convert_rate; /* sampling rate convert */
......
...@@ -63,7 +63,7 @@ struct rsnd_ssi { ...@@ -63,7 +63,7 @@ struct rsnd_ssi {
struct rsnd_ssi_platform_info *info; /* rcar_snd.h */ struct rsnd_ssi_platform_info *info; /* rcar_snd.h */
struct rsnd_ssi *parent; struct rsnd_ssi *parent;
struct rsnd_mod mod; struct rsnd_mod mod;
struct rsnd_dma *dma; struct rsnd_mod *dma;
u32 cr_own; u32 cr_own;
u32 cr_clk; u32 cr_clk;
...@@ -630,7 +630,7 @@ static int rsnd_ssi_dma_start(struct rsnd_mod *mod, ...@@ -630,7 +630,7 @@ static int rsnd_ssi_dma_start(struct rsnd_mod *mod,
struct rsnd_priv *priv) struct rsnd_priv *priv)
{ {
struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
struct rsnd_dma *dma = rsnd_ssi_to_dma(ssi); struct rsnd_mod *dma = rsnd_ssi_to_dma(ssi);
rsnd_dma_start(io, dma); rsnd_dma_start(io, dma);
...@@ -644,7 +644,7 @@ static int rsnd_ssi_dma_stop(struct rsnd_mod *mod, ...@@ -644,7 +644,7 @@ static int rsnd_ssi_dma_stop(struct rsnd_mod *mod,
struct rsnd_priv *priv) struct rsnd_priv *priv)
{ {
struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
struct rsnd_dma *dma = rsnd_ssi_to_dma(ssi); struct rsnd_mod *dma = rsnd_ssi_to_dma(ssi);
rsnd_ssi_stop(mod, io, priv); rsnd_ssi_stop(mod, io, priv);
......
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