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

Commit 497debaa authored by Kuninori Morimoto's avatar Kuninori Morimoto Committed by Mark Brown
Browse files

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



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.

This patch makes DMA mod bse common method

Signed-off-by: default avatarKuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent 76c80b5b
Loading
Loading
Loading
Loading
+61 −93
Original line number Diff line number Diff line
@@ -33,9 +33,7 @@ struct rsnd_dmapp {
};

struct rsnd_dma {
	struct rsnd_dma_ops	*ops;
	struct rsnd_mod		mod;
	struct rsnd_mod		*user_mod;
	dma_addr_t		src_addr;
	dma_addr_t		dst_addr;
	union {
@@ -50,19 +48,6 @@ struct rsnd_dma_ctrl {
	int dmapp_num;
};

struct rsnd_dma_ops {
	char *name;
	void (*start)(struct rsnd_mod *mod,
		      struct rsnd_dai_stream *io,
		      struct rsnd_priv *priv);
	void (*stop)(struct rsnd_mod *mod,
		     struct rsnd_dai_stream *io,
		     struct rsnd_priv *priv);
	void (*quit)(struct rsnd_mod *mod,
		     struct rsnd_dai_stream *io,
		     struct rsnd_priv *priv);
};

#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)
@@ -107,7 +92,7 @@ static void rsnd_dmaen_complete(void *data)
	rsnd_mod_interrupt(mod, __rsnd_dmaen_complete);
}

static void rsnd_dmaen_stop(struct rsnd_mod *mod,
static int rsnd_dmaen_stop(struct rsnd_mod *mod,
			   struct rsnd_dai_stream *io,
			   struct rsnd_priv *priv)
{
@@ -115,15 +100,16 @@ static void rsnd_dmaen_stop(struct rsnd_mod *mod,
	struct rsnd_dmaen *dmaen = rsnd_dma_to_dmaen(dma);

	dmaengine_terminate_all(dmaen->chan);

	return 0;
}

static void rsnd_dmaen_start(struct rsnd_mod *mod,
static int rsnd_dmaen_start(struct rsnd_mod *mod,
			    struct rsnd_dai_stream *io,
			    struct rsnd_priv *priv)
{
	struct rsnd_dma *dma = rsnd_mod_to_dma(mod);
	struct rsnd_dmaen *dmaen = rsnd_dma_to_dmaen(dma);
	struct rsnd_mod *user_mod = dma->user_mod;
	struct snd_pcm_substream *substream = io->substream;
	struct device *dev = rsnd_priv_to_dev(priv);
	struct dma_async_tx_descriptor *desc;
@@ -138,18 +124,20 @@ static void rsnd_dmaen_start(struct rsnd_mod *mod,

	if (!desc) {
		dev_err(dev, "dmaengine_prep_slave_sg() fail\n");
		return;
		return -EIO;
	}

	desc->callback		= rsnd_dmaen_complete;
	desc->callback_param	= user_mod;
	desc->callback_param	= rsnd_mod_get(dma);

	if (dmaengine_submit(desc) < 0) {
		dev_err(dev, "dmaengine_submit() fail\n");
		return;
		return -EIO;
	}

	dma_async_issue_pending(dmaen->chan);

	return 0;
}

struct dma_chan *rsnd_dma_request_channel(struct device_node *of_node,
@@ -187,10 +175,26 @@ static struct dma_chan *rsnd_dmaen_request_channel(struct rsnd_dai_stream *io,
		return rsnd_mod_dma_req(io, mod_to);
}

static int rsnd_dmaen_remove(struct rsnd_mod *mod,
			      struct rsnd_dai_stream *io,
			      struct rsnd_priv *priv)
{
	struct rsnd_dma *dma = rsnd_mod_to_dma(mod);
	struct rsnd_dmaen *dmaen = rsnd_dma_to_dmaen(dma);

	if (dmaen->chan)
		dma_release_channel(dmaen->chan);

	dmaen->chan = NULL;

	return 0;
}

static int rsnd_dmaen_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 = rsnd_mod_get(dma);
	struct rsnd_dmaen *dmaen = rsnd_dma_to_dmaen(dma);
	struct rsnd_priv *priv = rsnd_io_to_priv(io);
	struct rsnd_dma_ctrl *dmac = rsnd_priv_to_dmac(priv);
@@ -227,8 +231,8 @@ static int rsnd_dmaen_attach(struct rsnd_dai_stream *io,
	cfg.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
	cfg.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;

	dev_dbg(dev, "%s %pad -> %pad\n",
		dma->ops->name,
	dev_dbg(dev, "%s[%d] %pad -> %pad\n",
		rsnd_mod_name(mod), rsnd_mod_id(mod),
		&cfg.src_addr, &cfg.dst_addr);

	ret = dmaengine_slave_config(dmaen->chan, &cfg);
@@ -240,7 +244,7 @@ static int rsnd_dmaen_attach(struct rsnd_dai_stream *io,
	return 0;

rsnd_dma_attach_err:
	rsnd_dma_quit(rsnd_mod_get(dma), io, priv);
	rsnd_dmaen_remove(mod, io, priv);
rsnd_dma_channel_err:

	/*
@@ -252,24 +256,11 @@ static int rsnd_dmaen_attach(struct rsnd_dai_stream *io,
	return -EAGAIN;
}

static void rsnd_dmaen_quit(struct rsnd_mod *mod,
			    struct rsnd_dai_stream *io,
			    struct rsnd_priv *priv)
{
	struct rsnd_dma *dma = rsnd_mod_to_dma(mod);
	struct rsnd_dmaen *dmaen = rsnd_dma_to_dmaen(dma);

	if (dmaen->chan)
		dma_release_channel(dmaen->chan);

	dmaen->chan = NULL;
}

static struct rsnd_dma_ops rsnd_dmaen_ops = {
static struct rsnd_mod_ops rsnd_dmaen_ops = {
	.name	= "audmac",
	.start	= rsnd_dmaen_start,
	.stop	= rsnd_dmaen_stop,
	.quit	= rsnd_dmaen_quit,
	.remove	= rsnd_dmaen_remove,
};

/*
@@ -366,7 +357,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_mod *mod,
static int rsnd_dmapp_stop(struct rsnd_mod *mod,
			   struct rsnd_dai_stream *io,
			   struct rsnd_priv *priv)
{
@@ -377,12 +368,14 @@ static void rsnd_dmapp_stop(struct rsnd_mod *mod,

	for (i = 0; i < 1024; i++) {
		if (0 == rsnd_dmapp_read(dma, PDMACHCR))
			return;
			return -EIO;
		udelay(1);
	}

	return 0;
}

static void rsnd_dmapp_start(struct rsnd_mod *mod,
static int rsnd_dmapp_start(struct rsnd_mod *mod,
			    struct rsnd_dai_stream *io,
			    struct rsnd_priv *priv)
{
@@ -392,6 +385,8 @@ static void rsnd_dmapp_start(struct rsnd_mod *mod,
	rsnd_dmapp_write(dma, dma->src_addr,	PDMASAR);
	rsnd_dmapp_write(dma, dma->dst_addr,	PDMADAR);
	rsnd_dmapp_write(dma, dmapp->chcr,	PDMACHCR);

	return 0;
}

static int rsnd_dmapp_attach(struct rsnd_dai_stream *io,
@@ -414,7 +409,7 @@ static int rsnd_dmapp_attach(struct rsnd_dai_stream *io,
	return 0;
}

static struct rsnd_dma_ops rsnd_dmapp_ops = {
static struct rsnd_mod_ops rsnd_dmapp_ops = {
	.name	= "audmac-pp",
	.start	= rsnd_dmapp_start,
	.stop	= rsnd_dmapp_stop,
@@ -627,41 +622,6 @@ static void rsnd_dma_of_path(struct rsnd_mod *this,
	}
}

void rsnd_dma_stop(struct rsnd_mod *mod,
		   struct rsnd_dai_stream *io,
		   struct rsnd_priv *priv)

{
	struct rsnd_dma *dma = rsnd_mod_to_dma(mod);

	dma->ops->stop(mod, io, priv);
}

void rsnd_dma_start(struct rsnd_mod *mod,
		    struct rsnd_dai_stream *io,
		    struct rsnd_priv *priv)
{
	struct rsnd_dma *dma = rsnd_mod_to_dma(mod);

	dma->ops->start(mod, io, priv);
}

void rsnd_dma_quit(struct rsnd_mod *mod,
		   struct rsnd_dai_stream *io,
		   struct rsnd_priv *priv)
{
	struct rsnd_dma *dma = rsnd_mod_to_dma(mod);
	struct rsnd_dma_ctrl *dmac = rsnd_priv_to_dmac(priv);

	if (!dmac)
		return;

	dma->ops->quit(mod, io, priv);
}

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)
{
@@ -672,6 +632,8 @@ struct rsnd_mod *rsnd_dma_attach(struct rsnd_dai_stream *io,
	struct rsnd_dma_ctrl *dmac = rsnd_priv_to_dmac(priv);
	struct rsnd_dma *dma;
	struct device *dev = rsnd_priv_to_dev(priv);
	struct rsnd_mod_ops *ops;
	enum rsnd_mod_type type;
	int (*attach)(struct rsnd_dai_stream *io, struct rsnd_dma *dma, int id,
		      struct rsnd_mod *mod_from, struct rsnd_mod *mod_to);
	int is_play = rsnd_io_is_play(io);
@@ -692,37 +654,39 @@ struct rsnd_mod *rsnd_dma_attach(struct rsnd_dai_stream *io,

	rsnd_dma_of_path(mod, io, is_play, &mod_from, &mod_to);

	dma->user_mod = mod;
	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) {
		dma->ops = &rsnd_dmapp_ops;
		ops	= &rsnd_dmapp_ops;
		attach	= rsnd_dmapp_attach;
		dma_id	= dmac->dmapp_num;
		type	= RSND_MOD_AUDMAPP;
	} else {
		dma->ops = &rsnd_dmaen_ops;
		ops	= &rsnd_dmaen_ops;
		attach	= rsnd_dmaen_attach;
		dma_id	= dmac->dmaen_num;
		type	= RSND_MOD_AUDMA;
	}

	/* for Gen1, overwrite */
	if (rsnd_is_gen1(priv)) {
		dma->ops = &rsnd_dmaen_ops;
		ops	= &rsnd_dmaen_ops;
		attach	= rsnd_dmaen_attach;
		dma_id	= dmac->dmaen_num;
		type	= RSND_MOD_AUDMA;
	}

	dma_mod = rsnd_mod_get(dma);

	dev_dbg(dev, "%s %s[%d] -> %s[%d]\n",
		dma->ops->name,
	dev_dbg(dev, "%s[%d] %s[%d] -> %s[%d]\n",
		rsnd_mod_name(dma_mod), rsnd_mod_id(dma_mod),
		rsnd_mod_name(mod_from), rsnd_mod_id(mod_from),
		rsnd_mod_name(mod_to),   rsnd_mod_id(mod_to));

	ret = rsnd_mod_init(priv, dma_mod,
			    &rsnd_dma_ops, NULL, 0, dma_id);
			    ops, NULL, type, dma_id);
	if (ret < 0)
		return ERR_PTR(ret);

@@ -730,6 +694,10 @@ struct rsnd_mod *rsnd_dma_attach(struct rsnd_dai_stream *io,
	if (ret < 0)
		return ERR_PTR(ret);

	ret = rsnd_dai_connect(dma_mod, io, type);
	if (ret < 0)
		return ERR_PTR(ret);

	return rsnd_mod_get(dma);
}

+0 −9
Original line number Diff line number Diff line
@@ -193,15 +193,6 @@ void rsnd_path_parse(struct rsnd_priv *priv,
/*
 *	R-Car DMA
 */
void rsnd_dma_start(struct rsnd_mod *mod,
		    struct rsnd_dai_stream *io,
		    struct rsnd_priv *priv);
void rsnd_dma_stop(struct rsnd_mod *mod,
		   struct rsnd_dai_stream *io,
		   struct rsnd_priv *priv);
void rsnd_dma_quit(struct rsnd_mod *mod,
		   struct rsnd_dai_stream *io,
		   struct rsnd_priv *priv);
struct rsnd_mod *rsnd_dma_attach(struct rsnd_dai_stream *io,
			       struct rsnd_mod *mod, int id);
int rsnd_dma_probe(struct platform_device *pdev,
+8 −42
Original line number Diff line number Diff line
@@ -632,8 +632,9 @@ static bool rsnd_src_error_record_gen2(struct rsnd_mod *mod)
	return ret;
}

static int _rsnd_src_start_gen2(struct rsnd_mod *mod,
				struct rsnd_dai_stream *io)
static int rsnd_src_start_gen2(struct rsnd_mod *mod,
			       struct rsnd_dai_stream *io,
			       struct rsnd_priv *priv)
{
	struct rsnd_src *src = rsnd_mod_to_src(mod);
	u32 val;
@@ -661,7 +662,9 @@ static int _rsnd_src_start_gen2(struct rsnd_mod *mod,
	return 0;
}

static int _rsnd_src_stop_gen2(struct rsnd_mod *mod)
static int rsnd_src_stop_gen2(struct rsnd_mod *mod,
			      struct rsnd_dai_stream *io,
			      struct rsnd_priv *priv)
{
	rsnd_src_irq_disable_gen2(mod);

@@ -704,8 +707,8 @@ static void __rsnd_src_interrupt_gen2(struct rsnd_mod *mod,
		dev_dbg(dev, "%s[%d] restart\n",
			rsnd_mod_name(mod), rsnd_mod_id(mod));

		_rsnd_src_stop_gen2(mod);
		_rsnd_src_start_gen2(mod, io);
		rsnd_src_stop_gen2(mod, io, priv);
		rsnd_src_start_gen2(mod, io, priv);
	}

	if (src->err > 1024) {
@@ -837,17 +840,6 @@ static int rsnd_src_probe_gen2(struct rsnd_mod *mod,
	return ret;
}

static int rsnd_src_remove_gen2(struct rsnd_mod *mod,
				struct rsnd_dai_stream *io,
				struct rsnd_priv *priv)
{
	struct rsnd_src *src = rsnd_mod_to_src(mod);

	rsnd_dma_quit(rsnd_src_to_dma(src), io, priv);

	return 0;
}

static int rsnd_src_init_gen2(struct rsnd_mod *mod,
			      struct rsnd_dai_stream *io,
			      struct rsnd_priv *priv)
@@ -869,31 +861,6 @@ static int rsnd_src_init_gen2(struct rsnd_mod *mod,
	return 0;
}

static int rsnd_src_start_gen2(struct rsnd_mod *mod,
			       struct rsnd_dai_stream *io,
			       struct rsnd_priv *priv)
{
	struct rsnd_src *src = rsnd_mod_to_src(mod);

	rsnd_dma_start(rsnd_src_to_dma(src), io, priv);

	return _rsnd_src_start_gen2(mod, io);
}

static int rsnd_src_stop_gen2(struct rsnd_mod *mod,
			      struct rsnd_dai_stream *io,
			      struct rsnd_priv *priv)
{
	struct rsnd_src *src = rsnd_mod_to_src(mod);
	int ret;

	ret = _rsnd_src_stop_gen2(mod);

	rsnd_dma_stop(rsnd_src_to_dma(src), io, priv);

	return ret;
}

static void rsnd_src_reconvert_update(struct rsnd_dai_stream *io,
				      struct rsnd_mod *mod)
{
@@ -958,7 +925,6 @@ static struct rsnd_mod_ops rsnd_src_gen2_ops = {
	.name	= SRC_NAME,
	.dma_req = rsnd_src_dma_req,
	.probe	= rsnd_src_probe_gen2,
	.remove	= rsnd_src_remove_gen2,
	.init	= rsnd_src_init_gen2,
	.quit	= rsnd_src_quit_gen2,
	.start	= rsnd_src_start_gen2,
+2 −32
Original line number Diff line number Diff line
@@ -596,8 +596,6 @@ 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_ssi_to_dma(ssi), io, priv);

	/* PIO will request IRQ again */
	devm_free_irq(dev, irq, mod);

@@ -625,34 +623,6 @@ static int rsnd_ssi_fallback(struct rsnd_mod *mod,
	return 0;
}

static int rsnd_ssi_dma_start(struct rsnd_mod *mod,
			      struct rsnd_dai_stream *io,
			      struct rsnd_priv *priv)
{
	struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
	struct rsnd_mod *dma = rsnd_ssi_to_dma(ssi);

	rsnd_dma_start(dma, io, priv);

	rsnd_ssi_start(mod, io, priv);

	return 0;
}

static int rsnd_ssi_dma_stop(struct rsnd_mod *mod,
			     struct rsnd_dai_stream *io,
			     struct rsnd_priv *priv)
{
	struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
	struct rsnd_mod *dma = rsnd_ssi_to_dma(ssi);

	rsnd_ssi_stop(mod, io, priv);

	rsnd_dma_stop(dma, io, priv);

	return 0;
}

static struct dma_chan *rsnd_ssi_dma_req(struct rsnd_dai_stream *io,
					 struct rsnd_mod *mod)
{
@@ -676,8 +646,8 @@ static struct rsnd_mod_ops rsnd_ssi_dma_ops = {
	.remove	= rsnd_ssi_dma_remove,
	.init	= rsnd_ssi_init,
	.quit	= rsnd_ssi_quit,
	.start	= rsnd_ssi_dma_start,
	.stop	= rsnd_ssi_dma_stop,
	.start	= rsnd_ssi_start,
	.stop	= rsnd_ssi_stop,
	.fallback = rsnd_ssi_fallback,
	.hw_params = rsnd_ssi_hw_params,
};