All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 1/5] dmaengine: sun6i: Simplify and fix lli setting
  2016-03-18 14:32 [PATCH v3 0/5] dmaengine: sun6i: Upgrade for audio transfers Jean-Francois Moine
@ 2016-03-18 11:50 ` Jean-Francois Moine
  2016-03-21  7:27   ` Maxime Ripard
  2016-03-18 14:12 ` [PATCH v3 2/5] dmaengine: sun6i: Add 4 as a possible burst value for the H3 Jean-Francois Moine
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 14+ messages in thread
From: Jean-Francois Moine @ 2016-03-18 11:50 UTC (permalink / raw)
  To: linux-arm-kernel

Checking the DMA config before setting the lli list avoids to do tests
inside the setting loop.
Also, in case of audio streaming, the sound PCM DMA engine sets only
the burst and bus width of the device. Set the lacking memory values
to system values while checking the config.

Signed-off-by: Jean-Francois Moine <moinejf@free.fr>
---
 drivers/dma/sun6i-dma.c | 116 +++++++++++++++++++++++++-----------------------
 1 file changed, 61 insertions(+), 55 deletions(-)

diff --git a/drivers/dma/sun6i-dma.c b/drivers/dma/sun6i-dma.c
index 3579ee7..ce1e4d6 100644
--- a/drivers/dma/sun6i-dma.c
+++ b/drivers/dma/sun6i-dma.c
@@ -276,45 +276,6 @@ static void *sun6i_dma_lli_add(struct sun6i_dma_lli *prev,
 	return next;
 }
 
-static inline int sun6i_dma_cfg_lli(struct sun6i_dma_lli *lli,
-				    dma_addr_t src,
-				    dma_addr_t dst, u32 len,
-				    struct dma_slave_config *config)
-{
-	s8 src_width, dst_width, src_burst, dst_burst;
-
-	if (!config)
-		return -EINVAL;
-
-	src_burst = convert_burst(config->src_maxburst);
-	if (src_burst < 0)
-		return src_burst;
-
-	dst_burst = convert_burst(config->dst_maxburst);
-	if (dst_burst < 0)
-		return dst_burst;
-
-	src_width = convert_buswidth(config->src_addr_width);
-	if (src_width < 0)
-		return src_width;
-
-	dst_width = convert_buswidth(config->dst_addr_width);
-	if (dst_width < 0)
-		return dst_width;
-
-	lli->cfg = DMA_CHAN_CFG_SRC_BURST(src_burst) |
-		DMA_CHAN_CFG_SRC_WIDTH(src_width) |
-		DMA_CHAN_CFG_DST_BURST(dst_burst) |
-		DMA_CHAN_CFG_DST_WIDTH(dst_width);
-
-	lli->src = src;
-	lli->dst = dst;
-	lli->len = len;
-	lli->para = NORMAL_WAIT;
-
-	return 0;
-}
-
 static inline void sun6i_dma_dump_lli(struct sun6i_vchan *vchan,
 				      struct sun6i_dma_lli *lli)
 {
@@ -502,6 +463,49 @@ static irqreturn_t sun6i_dma_interrupt(int irq, void *dev_id)
 	return ret;
 }
 
+static int set_config(struct sun6i_dma_dev *sdev,
+			struct dma_slave_config *sconfig,
+			enum dma_transfer_direction direction,
+			u32 *p_cfg)
+{
+	s8 src_width, dst_width, src_burst, dst_burst;
+
+	if (direction == DMA_MEM_TO_DEV) {
+		src_burst = convert_burst(sconfig->src_maxburst ?
+					sconfig->src_maxburst : 8);
+		src_width = convert_buswidth(sconfig->src_addr_width !=
+						DMA_SLAVE_BUSWIDTH_UNDEFINED ?
+				sconfig->src_addr_width :
+				DMA_SLAVE_BUSWIDTH_4_BYTES);
+		dst_burst = convert_burst(sconfig->dst_maxburst);
+		dst_width = convert_buswidth(sconfig->dst_addr_width);
+	} else {	/* DMA_DEV_TO_MEM */
+		src_burst = convert_burst(sconfig->src_maxburst);
+		src_width = convert_buswidth(sconfig->src_addr_width);
+		dst_burst = convert_burst(sconfig->dst_maxburst ?
+					sconfig->dst_maxburst : 8);
+		dst_width = convert_buswidth(sconfig->dst_addr_width !=
+						DMA_SLAVE_BUSWIDTH_UNDEFINED ?
+				sconfig->dst_addr_width :
+				DMA_SLAVE_BUSWIDTH_4_BYTES);
+	}
+	if (src_burst < 0)
+		return src_burst;
+	if (src_width < 0)
+		return src_width;
+	if (dst_burst < 0)
+		return dst_burst;
+	if (dst_width < 0)
+		return dst_width;
+
+	*p_cfg = DMA_CHAN_CFG_SRC_BURST(src_burst) |
+		DMA_CHAN_CFG_SRC_WIDTH(src_width) |
+		DMA_CHAN_CFG_DST_BURST(dst_burst) |
+		DMA_CHAN_CFG_DST_WIDTH(dst_width);
+
+	return 0;
+}
+
 static struct dma_async_tx_descriptor *sun6i_dma_prep_dma_memcpy(
 		struct dma_chan *chan, dma_addr_t dest, dma_addr_t src,
 		size_t len, unsigned long flags)
@@ -569,6 +573,7 @@ static struct dma_async_tx_descriptor *sun6i_dma_prep_slave_sg(
 	struct sun6i_desc *txd;
 	struct scatterlist *sg;
 	dma_addr_t p_lli;
+	u32 lli_cfg;
 	int i, ret;
 
 	if (!sgl)
@@ -579,6 +584,12 @@ static struct dma_async_tx_descriptor *sun6i_dma_prep_slave_sg(
 		return NULL;
 	}
 
+	ret = set_config(sdev, sconfig, dir, &lli_cfg);
+	if (ret) {
+		dev_err(chan2dev(chan), "Invalid DMA configuration\n");
+		return NULL;
+	}
+
 	txd = kzalloc(sizeof(*txd), GFP_NOWAIT);
 	if (!txd)
 		return NULL;
@@ -588,14 +599,14 @@ static struct dma_async_tx_descriptor *sun6i_dma_prep_slave_sg(
 		if (!v_lli)
 			goto err_lli_free;
 
-		if (dir == DMA_MEM_TO_DEV) {
-			ret = sun6i_dma_cfg_lli(v_lli, sg_dma_address(sg),
-						sconfig->dst_addr, sg_dma_len(sg),
-						sconfig);
-			if (ret)
-				goto err_cur_lli_free;
+		v_lli->len = sg_dma_len(sg);
+		v_lli->para = NORMAL_WAIT;
 
-			v_lli->cfg |= DMA_CHAN_CFG_DST_IO_MODE |
+		if (dir == DMA_MEM_TO_DEV) {
+			v_lli->src = sg_dma_address(sg);
+			v_lli->dst = sconfig->dst_addr;
+			v_lli->cfg = lli_cfg |
+				DMA_CHAN_CFG_DST_IO_MODE |
 				DMA_CHAN_CFG_SRC_LINEAR_MODE |
 				DMA_CHAN_CFG_SRC_DRQ(DRQ_SDRAM) |
 				DMA_CHAN_CFG_DST_DRQ(vchan->port);
@@ -607,13 +618,10 @@ static struct dma_async_tx_descriptor *sun6i_dma_prep_slave_sg(
 				sg_dma_len(sg), flags);
 
 		} else {
-			ret = sun6i_dma_cfg_lli(v_lli, sconfig->src_addr,
-						sg_dma_address(sg), sg_dma_len(sg),
-						sconfig);
-			if (ret)
-				goto err_cur_lli_free;
-
-			v_lli->cfg |= DMA_CHAN_CFG_DST_LINEAR_MODE |
+			v_lli->src = sconfig->src_addr;
+			v_lli->dst = sg_dma_address(sg);
+			v_lli->cfg = lli_cfg |
+				DMA_CHAN_CFG_DST_LINEAR_MODE |
 				DMA_CHAN_CFG_SRC_IO_MODE |
 				DMA_CHAN_CFG_DST_DRQ(DRQ_SDRAM) |
 				DMA_CHAN_CFG_SRC_DRQ(vchan->port);
@@ -634,8 +642,6 @@ static struct dma_async_tx_descriptor *sun6i_dma_prep_slave_sg(
 
 	return vchan_tx_prep(&vchan->vc, &txd->vd, flags);
 
-err_cur_lli_free:
-	dma_pool_free(sdev->pool, v_lli, p_lli);
 err_lli_free:
 	for (prev = txd->v_lli; prev; prev = prev->v_lli_next)
 		dma_pool_free(sdev->pool, prev, virt_to_phys(prev));
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v3 2/5] dmaengine: sun6i: Add 4 as a possible burst value for the H3
  2016-03-18 14:32 [PATCH v3 0/5] dmaengine: sun6i: Upgrade for audio transfers Jean-Francois Moine
  2016-03-18 11:50 ` [PATCH v3 1/5] dmaengine: sun6i: Simplify and fix lli setting Jean-Francois Moine
@ 2016-03-18 14:12 ` Jean-Francois Moine
  2016-03-21  7:29   ` Maxime Ripard
  2016-03-18 14:18 ` [PATCH v3 3/5] dmaengine: sun6i: Add cyclic capability Jean-Francois Moine
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 14+ messages in thread
From: Jean-Francois Moine @ 2016-03-18 14:12 UTC (permalink / raw)
  To: linux-arm-kernel

The H3 accepts 4 as a burst value.

Signed-off-by: Jean-Francois Moine <moinejf@free.fr>
---
 drivers/dma/sun6i-dma.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/drivers/dma/sun6i-dma.c b/drivers/dma/sun6i-dma.c
index ce1e4d6..9378fda 100644
--- a/drivers/dma/sun6i-dma.c
+++ b/drivers/dma/sun6i-dma.c
@@ -101,6 +101,7 @@ struct sun6i_dma_config {
 	u32 nr_max_channels;
 	u32 nr_max_requests;
 	u32 nr_max_vchans;
+	u32 burst_4;
 };
 
 /*
@@ -238,6 +239,8 @@ static inline s8 convert_burst(u32 maxburst)
 	switch (maxburst) {
 	case 1:
 		return 0;
+	case 4:
+		return 1;
 	case 8:
 		return 2;
 	default:
@@ -470,6 +473,10 @@ static int set_config(struct sun6i_dma_dev *sdev,
 {
 	s8 src_width, dst_width, src_burst, dst_burst;
 
+	if (!sdev->cfg->burst_4 &&
+	    (sconfig->src_maxburst == 4 || sconfig->dst_maxburst == 4))
+		return -EINVAL;
+
 	if (direction == DMA_MEM_TO_DEV) {
 		src_burst = convert_burst(sconfig->src_maxburst ?
 					sconfig->src_maxburst : 8);
@@ -900,12 +907,14 @@ static struct sun6i_dma_config sun8i_a23_dma_cfg = {
 /*
  * The H3 has 12 physical channels, a maximum DRQ port id of 27,
  * and a total of 34 usable source and destination endpoints.
+ * Setting the maxburst to '4' is possible.
  */
 
 static struct sun6i_dma_config sun8i_h3_dma_cfg = {
 	.nr_max_channels = 12,
 	.nr_max_requests = 27,
 	.nr_max_vchans   = 34,
+	.burst_4	 = 1,
 };
 
 static const struct of_device_id sun6i_dma_match[] = {
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v3 3/5] dmaengine: sun6i: Add cyclic capability
  2016-03-18 14:32 [PATCH v3 0/5] dmaengine: sun6i: Upgrade for audio transfers Jean-Francois Moine
  2016-03-18 11:50 ` [PATCH v3 1/5] dmaengine: sun6i: Simplify and fix lli setting Jean-Francois Moine
  2016-03-18 14:12 ` [PATCH v3 2/5] dmaengine: sun6i: Add 4 as a possible burst value for the H3 Jean-Francois Moine
@ 2016-03-18 14:18 ` Jean-Francois Moine
  2016-03-21  7:33   ` Maxime Ripard
  2016-03-18 14:21 ` [PATCH v3 4/5] dmaengine: sun6i: Simplify some macros Jean-Francois Moine
  2016-03-18 14:25 ` [PATCH v3 5/5] dmaengine: sun6i: Compact a bit some config constants Jean-Francois Moine
  4 siblings, 1 reply; 14+ messages in thread
From: Jean-Francois Moine @ 2016-03-18 14:18 UTC (permalink / raw)
  To: linux-arm-kernel

DMA cyclic transfers are required by audio streaming.

Signed-off-by: Jean-Francois Moine <moinejf@free.fr>
---
 drivers/dma/sun6i-dma.c | 129 +++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 122 insertions(+), 7 deletions(-)

diff --git a/drivers/dma/sun6i-dma.c b/drivers/dma/sun6i-dma.c
index 9378fda..3f73123 100644
--- a/drivers/dma/sun6i-dma.c
+++ b/drivers/dma/sun6i-dma.c
@@ -147,6 +147,8 @@ struct sun6i_vchan {
 	struct dma_slave_config	cfg;
 	struct sun6i_pchan	*phy;
 	u8			port;
+	u8			irq_type;
+	bool			cyclic;
 };
 
 struct sun6i_dma_dev {
@@ -257,6 +259,30 @@ static inline s8 convert_buswidth(enum dma_slave_buswidth addr_width)
 	return addr_width >> 1;
 }
 
+static size_t sun6i_get_chan_size(struct sun6i_pchan *pchan)
+{
+	struct sun6i_desc *txd = pchan->desc;
+	struct sun6i_dma_lli *lli;
+	size_t bytes;
+	dma_addr_t pos;
+
+	pos = readl(pchan->base + DMA_CHAN_LLI_ADDR);
+	bytes = readl(pchan->base + DMA_CHAN_CUR_CNT);
+
+	if (pos == LLI_LAST_ITEM)
+		return bytes;
+
+	for (lli = txd->v_lli; lli; lli = lli->v_lli_next) {
+		if (lli->p_lli_next == pos) {
+			for (lli = lli->v_lli_next; lli; lli = lli->v_lli_next)
+				bytes += lli->len;
+			break;
+		}
+	}
+
+	return bytes;
+}
+
 static void *sun6i_dma_lli_add(struct sun6i_dma_lli *prev,
 			       struct sun6i_dma_lli *next,
 			       dma_addr_t next_phy,
@@ -345,8 +371,12 @@ static int sun6i_dma_start_desc(struct sun6i_vchan *vchan)
 	irq_reg = pchan->idx / DMA_IRQ_CHAN_NR;
 	irq_offset = pchan->idx % DMA_IRQ_CHAN_NR;
 
+	vchan->irq_type = vchan->cyclic ? DMA_IRQ_PKG : DMA_IRQ_QUEUE;
+
 	irq_val = readl(sdev->base + DMA_IRQ_EN(irq_reg));
-	irq_val |= DMA_IRQ_QUEUE << (irq_offset * DMA_IRQ_CHAN_WIDTH);
+	irq_val &= ~((DMA_IRQ_HALF | DMA_IRQ_PKG | DMA_IRQ_QUEUE) <<
+			(irq_offset * DMA_IRQ_CHAN_WIDTH));
+	irq_val |= vchan->irq_type << (irq_offset * DMA_IRQ_CHAN_WIDTH);
 	writel(irq_val, sdev->base + DMA_IRQ_EN(irq_reg));
 
 	writel(pchan->desc->p_lli, pchan->base + DMA_CHAN_LLI_ADDR);
@@ -443,11 +473,12 @@ static irqreturn_t sun6i_dma_interrupt(int irq, void *dev_id)
 		writel(status, sdev->base + DMA_IRQ_STAT(i));
 
 		for (j = 0; (j < DMA_IRQ_CHAN_NR) && status; j++) {
-			if (status & DMA_IRQ_QUEUE) {
-				pchan = sdev->pchans + j;
-				vchan = pchan->vchan;
-
-				if (vchan) {
+			pchan = sdev->pchans + j;
+			vchan = pchan->vchan;
+			if (vchan && (status & vchan->irq_type)) {
+				if (vchan->cyclic) {
+					vchan_cyclic_callback(&pchan->desc->vd);
+				} else {
 					spin_lock(&vchan->vc.lock);
 					vchan_cookie_complete(&pchan->desc->vd);
 					pchan->done = pchan->desc;
@@ -656,6 +687,78 @@ err_lli_free:
 	return NULL;
 }
 
+static struct dma_async_tx_descriptor *sun6i_dma_prep_dma_cyclic(
+					struct dma_chan *chan,
+					dma_addr_t buf_addr,
+					size_t buf_len,
+					size_t period_len,
+					enum dma_transfer_direction dir,
+					unsigned long flags)
+{
+	struct sun6i_dma_dev *sdev = to_sun6i_dma_dev(chan->device);
+	struct sun6i_vchan *vchan = to_sun6i_vchan(chan);
+	struct dma_slave_config *sconfig = &vchan->cfg;
+	struct sun6i_dma_lli *v_lli, *prev = NULL;
+	struct sun6i_desc *txd;
+	dma_addr_t p_lli;
+	u32 lli_cfg;
+	unsigned int i, periods = buf_len / period_len;
+	int ret;
+
+	ret = set_config(sdev, sconfig, dir, &lli_cfg);
+	if (ret) {
+		dev_err(chan2dev(chan), "Invalid DMA configuration\n");
+		return NULL;
+	}
+
+	txd = kzalloc(sizeof(*txd), GFP_NOWAIT);
+	if (!txd)
+		return NULL;
+
+	for (i = 0; i < periods; i++){
+		v_lli = dma_pool_alloc(sdev->pool, GFP_NOWAIT, &p_lli);
+		if (!v_lli) {
+			dev_err(sdev->slave.dev, "Failed to alloc lli memory\n");
+			goto err_lli_free;
+		}
+
+		v_lli->len = period_len;
+		v_lli->para = NORMAL_WAIT;
+
+		if (dir == DMA_MEM_TO_DEV) {
+			v_lli->src = buf_addr + period_len * i;
+			v_lli->dst = sconfig->dst_addr;
+			v_lli->cfg = lli_cfg |
+				DMA_CHAN_CFG_DST_IO_MODE |
+				DMA_CHAN_CFG_SRC_LINEAR_MODE |
+				DMA_CHAN_CFG_SRC_DRQ(DRQ_SDRAM) |
+				DMA_CHAN_CFG_DST_DRQ(vchan->port);
+		} else {
+			v_lli->src = sconfig->src_addr;
+			v_lli->dst = buf_addr + period_len * i;
+			v_lli->cfg = lli_cfg |
+				DMA_CHAN_CFG_DST_LINEAR_MODE |
+				DMA_CHAN_CFG_SRC_IO_MODE |
+				DMA_CHAN_CFG_DST_DRQ(DRQ_SDRAM) |
+				DMA_CHAN_CFG_SRC_DRQ(vchan->port);
+		}
+
+		prev = sun6i_dma_lli_add(prev, v_lli, p_lli, txd);
+	}
+
+	prev->p_lli_next = txd->p_lli;		/* cyclic list */
+
+	vchan->cyclic = true;
+
+	return vchan_tx_prep(&vchan->vc, &txd->vd, flags);
+
+err_lli_free:
+	for (prev = txd->v_lli; prev; prev = prev->v_lli_next)
+		dma_pool_free(sdev->pool, prev, virt_to_phys(prev));
+	kfree(txd);
+	return NULL;
+}
+
 static int sun6i_dma_config(struct dma_chan *chan,
 			    struct dma_slave_config *config)
 {
@@ -725,6 +828,16 @@ static int sun6i_dma_terminate_all(struct dma_chan *chan)
 
 	spin_lock_irqsave(&vchan->vc.lock, flags);
 
+	if (vchan->cyclic) {
+		vchan->cyclic = false;
+		if (pchan && pchan->desc) {
+			struct virt_dma_desc *vd = &pchan->desc->vd;
+			struct virt_dma_chan *vc = &vchan->vc;
+
+			list_add_tail(&vd->node, &vc->desc_completed);
+		}
+	}
+
 	vchan_get_all_descriptors(&vchan->vc, &head);
 
 	if (pchan) {
@@ -772,7 +885,7 @@ static enum dma_status sun6i_dma_tx_status(struct dma_chan *chan,
 	} else if (!pchan || !pchan->desc) {
 		bytes = 0;
 	} else {
-		bytes = readl(pchan->base + DMA_CHAN_CUR_CNT);
+		bytes = sun6i_get_chan_size(pchan);
 	}
 
 	spin_unlock_irqrestore(&vchan->vc.lock, flags);
@@ -978,6 +1091,7 @@ static int sun6i_dma_probe(struct platform_device *pdev)
 	dma_cap_set(DMA_PRIVATE, sdc->slave.cap_mask);
 	dma_cap_set(DMA_MEMCPY, sdc->slave.cap_mask);
 	dma_cap_set(DMA_SLAVE, sdc->slave.cap_mask);
+	dma_cap_set(DMA_CYCLIC, sdc->slave.cap_mask);
 
 	INIT_LIST_HEAD(&sdc->slave.channels);
 	sdc->slave.device_free_chan_resources	= sun6i_dma_free_chan_resources;
@@ -985,6 +1099,7 @@ static int sun6i_dma_probe(struct platform_device *pdev)
 	sdc->slave.device_issue_pending		= sun6i_dma_issue_pending;
 	sdc->slave.device_prep_slave_sg		= sun6i_dma_prep_slave_sg;
 	sdc->slave.device_prep_dma_memcpy	= sun6i_dma_prep_dma_memcpy;
+	sdc->slave.device_prep_dma_cyclic	= sun6i_dma_prep_dma_cyclic;
 	sdc->slave.copy_align			= DMAENGINE_ALIGN_4_BYTES;
 	sdc->slave.device_config		= sun6i_dma_config;
 	sdc->slave.device_pause			= sun6i_dma_pause;
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v3 4/5] dmaengine: sun6i: Simplify some macros
  2016-03-18 14:32 [PATCH v3 0/5] dmaengine: sun6i: Upgrade for audio transfers Jean-Francois Moine
                   ` (2 preceding siblings ...)
  2016-03-18 14:18 ` [PATCH v3 3/5] dmaengine: sun6i: Add cyclic capability Jean-Francois Moine
@ 2016-03-18 14:21 ` Jean-Francois Moine
  2016-03-21  7:48   ` Maxime Ripard
  2016-03-18 14:25 ` [PATCH v3 5/5] dmaengine: sun6i: Compact a bit some config constants Jean-Francois Moine
  4 siblings, 1 reply; 14+ messages in thread
From: Jean-Francois Moine @ 2016-03-18 14:21 UTC (permalink / raw)
  To: linux-arm-kernel

As the max burst and bus width values are now checked, there is
no reason to check them again when setting the hardware registers.

Signed-off-by: Jean-Francois Moine <moinejf@free.fr>
---
 drivers/dma/sun6i-dma.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/dma/sun6i-dma.c b/drivers/dma/sun6i-dma.c
index 3f73123..643ba4c 100644
--- a/drivers/dma/sun6i-dma.c
+++ b/drivers/dma/sun6i-dma.c
@@ -65,8 +65,8 @@
 #define DMA_CHAN_CFG_SRC_DRQ(x)		((x) & 0x1f)
 #define DMA_CHAN_CFG_SRC_IO_MODE	BIT(5)
 #define DMA_CHAN_CFG_SRC_LINEAR_MODE	(0 << 5)
-#define DMA_CHAN_CFG_SRC_BURST(x)	(((x) & 0x3) << 7)
-#define DMA_CHAN_CFG_SRC_WIDTH(x)	(((x) & 0x3) << 9)
+#define DMA_CHAN_CFG_SRC_BURST(x)	((x) << 7)
+#define DMA_CHAN_CFG_SRC_WIDTH(x)	((x) << 9)
 
 #define DMA_CHAN_CFG_DST_DRQ(x)		(DMA_CHAN_CFG_SRC_DRQ(x) << 16)
 #define DMA_CHAN_CFG_DST_IO_MODE	(DMA_CHAN_CFG_SRC_IO_MODE << 16)
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v3 5/5] dmaengine: sun6i: Compact a bit some config constants
  2016-03-18 14:32 [PATCH v3 0/5] dmaengine: sun6i: Upgrade for audio transfers Jean-Francois Moine
                   ` (3 preceding siblings ...)
  2016-03-18 14:21 ` [PATCH v3 4/5] dmaengine: sun6i: Simplify some macros Jean-Francois Moine
@ 2016-03-18 14:25 ` Jean-Francois Moine
  4 siblings, 0 replies; 14+ messages in thread
From: Jean-Francois Moine @ 2016-03-18 14:25 UTC (permalink / raw)
  To: linux-arm-kernel

All config SoC specific values are less than 128. Store them as bytes.

Signed-off-by: Jean-Francois Moine <moinejf@free.fr>
---
 drivers/dma/sun6i-dma.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/dma/sun6i-dma.c b/drivers/dma/sun6i-dma.c
index 643ba4c..491522d 100644
--- a/drivers/dma/sun6i-dma.c
+++ b/drivers/dma/sun6i-dma.c
@@ -98,10 +98,10 @@
  * to a certain compatible string.
  */
 struct sun6i_dma_config {
-	u32 nr_max_channels;
-	u32 nr_max_requests;
-	u32 nr_max_vchans;
-	u32 burst_4;
+	u8 nr_max_channels;
+	u8 nr_max_requests;
+	u8 nr_max_vchans;
+	u8 burst_4;
 };
 
 /*
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v3 0/5] dmaengine: sun6i: Upgrade for audio transfers
@ 2016-03-18 14:32 Jean-Francois Moine
  2016-03-18 11:50 ` [PATCH v3 1/5] dmaengine: sun6i: Simplify and fix lli setting Jean-Francois Moine
                   ` (4 more replies)
  0 siblings, 5 replies; 14+ messages in thread
From: Jean-Francois Moine @ 2016-03-18 14:32 UTC (permalink / raw)
  To: linux-arm-kernel

This patch series replaces the 2nd part of the previous series
'dmaengine: sun6i: Fixes and upgrade for audio transfers'.
It contains the required changes to the sun6i DMA driver for
audio streaming.
These ones have been tested in a Allwinner H3 (Orange PI 2).

Changes since v2
- do some optimizations
- add a check about the maxburst value '4' (Maxime Ripard)
- remove the driver fixes
Changes since v1 (comments from Vinod Koul and Sergei Shtylyov - thanks)
- typo fixes
- change some comments
- better handling of burst and bus width
- remove useless code in the cyclic capability patch

Jean-Francois Moine (5):
  dmaengine: sun6i: Simplify and fix lli setting
  dmaengine: sun6i: Add 4 as a possible burst value for H3
  dmaengine: sun6i: Add cyclic capability
  dmaengine: sun6i: Simplify some macros
  dmaengine: sun6i: Compact a bit some config constants

 drivers/dma/sun6i-dma.c | 264 ++++++++++++++++++++++++++++++++++++------------
 1 file changed, 197 insertions(+), 67 deletions(-)

-- 
2.7.4

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH v3 1/5] dmaengine: sun6i: Simplify and fix lli setting
  2016-03-18 11:50 ` [PATCH v3 1/5] dmaengine: sun6i: Simplify and fix lli setting Jean-Francois Moine
@ 2016-03-21  7:27   ` Maxime Ripard
  0 siblings, 0 replies; 14+ messages in thread
From: Maxime Ripard @ 2016-03-21  7:27 UTC (permalink / raw)
  To: linux-arm-kernel

On Fri, Mar 18, 2016 at 12:50:07PM +0100, Jean-Francois Moine wrote:
> Checking the DMA config before setting the lli list avoids to do tests
> inside the setting loop.
> Also, in case of audio streaming, the sound PCM DMA engine sets only
> the burst and bus width of the device. Set the lacking memory values
> to system values while checking the config.

You're doing two separate and unrelated things here, please make two
patches.

Also, you commit title says you fix something, but you never say what
the issue actually is in the commit log.

Maxime

-- 
Maxime Ripard, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20160321/d45b98a5/attachment.sig>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH v3 2/5] dmaengine: sun6i: Add 4 as a possible burst value for the H3
  2016-03-18 14:12 ` [PATCH v3 2/5] dmaengine: sun6i: Add 4 as a possible burst value for the H3 Jean-Francois Moine
@ 2016-03-21  7:29   ` Maxime Ripard
  2016-03-21  8:35     ` Jean-Francois Moine
  0 siblings, 1 reply; 14+ messages in thread
From: Maxime Ripard @ 2016-03-21  7:29 UTC (permalink / raw)
  To: linux-arm-kernel

On Fri, Mar 18, 2016 at 03:12:26PM +0100, Jean-Francois Moine wrote:
> The H3 accepts 4 as a burst value.
> 
> Signed-off-by: Jean-Francois Moine <moinejf@free.fr>
> ---
>  drivers/dma/sun6i-dma.c | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/drivers/dma/sun6i-dma.c b/drivers/dma/sun6i-dma.c
> index ce1e4d6..9378fda 100644
> --- a/drivers/dma/sun6i-dma.c
> +++ b/drivers/dma/sun6i-dma.c
> @@ -101,6 +101,7 @@ struct sun6i_dma_config {
>  	u32 nr_max_channels;
>  	u32 nr_max_requests;
>  	u32 nr_max_vchans;
> +	u32 burst_4;
>  };
>  
>  /*
> @@ -238,6 +239,8 @@ static inline s8 convert_burst(u32 maxburst)
>  	switch (maxburst) {
>  	case 1:
>  		return 0;
> +	case 4:
> +		return 1;
>  	case 8:
>  		return 2;
>  	default:
> @@ -470,6 +473,10 @@ static int set_config(struct sun6i_dma_dev *sdev,
>  {
>  	s8 src_width, dst_width, src_burst, dst_burst;
>  
> +	if (!sdev->cfg->burst_4 &&
> +	    (sconfig->src_maxburst == 4 || sconfig->dst_maxburst == 4))
> +		return -EINVAL;
> +

I still believe this should be dealt with at the framework level.

Maxime

-- 
Maxime Ripard, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20160321/b12e55d5/attachment.sig>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH v3 3/5] dmaengine: sun6i: Add cyclic capability
  2016-03-18 14:18 ` [PATCH v3 3/5] dmaengine: sun6i: Add cyclic capability Jean-Francois Moine
@ 2016-03-21  7:33   ` Maxime Ripard
  0 siblings, 0 replies; 14+ messages in thread
From: Maxime Ripard @ 2016-03-21  7:33 UTC (permalink / raw)
  To: linux-arm-kernel

On Fri, Mar 18, 2016 at 03:18:32PM +0100, Jean-Francois Moine wrote:
> DMA cyclic transfers are required by audio streaming.
> 
> Signed-off-by: Jean-Francois Moine <moinejf@free.fr>

Acked-by: Maxime Ripard <maxime.ripard@free-electrons.com>

Thanks!
Maxime

-- 
Maxime Ripard, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20160321/0e0a1055/attachment.sig>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH v3 4/5] dmaengine: sun6i: Simplify some macros
  2016-03-18 14:21 ` [PATCH v3 4/5] dmaengine: sun6i: Simplify some macros Jean-Francois Moine
@ 2016-03-21  7:48   ` Maxime Ripard
  2016-03-21 14:40     ` Jean-Francois Moine
  0 siblings, 1 reply; 14+ messages in thread
From: Maxime Ripard @ 2016-03-21  7:48 UTC (permalink / raw)
  To: linux-arm-kernel

On Fri, Mar 18, 2016 at 03:21:11PM +0100, Jean-Francois Moine wrote:
> As the max burst and bus width values are now checked, there is
> no reason to check them again when setting the hardware registers.
> 
> Signed-off-by: Jean-Francois Moine <moinejf@free.fr>
> ---
>  drivers/dma/sun6i-dma.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/dma/sun6i-dma.c b/drivers/dma/sun6i-dma.c
> index 3f73123..643ba4c 100644
> --- a/drivers/dma/sun6i-dma.c
> +++ b/drivers/dma/sun6i-dma.c
> @@ -65,8 +65,8 @@
>  #define DMA_CHAN_CFG_SRC_DRQ(x)		((x) & 0x1f)
>  #define DMA_CHAN_CFG_SRC_IO_MODE	BIT(5)
>  #define DMA_CHAN_CFG_SRC_LINEAR_MODE	(0 << 5)
> -#define DMA_CHAN_CFG_SRC_BURST(x)	(((x) & 0x3) << 7)
> -#define DMA_CHAN_CFG_SRC_WIDTH(x)	(((x) & 0x3) << 9)
> +#define DMA_CHAN_CFG_SRC_BURST(x)	((x) << 7)
> +#define DMA_CHAN_CFG_SRC_WIDTH(x)	((x) << 9)

Well, you can easily end up with values higher than that. I still
believe that making sure you only always write what is expected is a
good thing.

Maxime

-- 
Maxime Ripard, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20160321/8f446f4c/attachment.sig>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH v3 2/5] dmaengine: sun6i: Add 4 as a possible burst value for the H3
  2016-03-21  7:29   ` Maxime Ripard
@ 2016-03-21  8:35     ` Jean-Francois Moine
  2016-03-29  6:46       ` Maxime Ripard
  0 siblings, 1 reply; 14+ messages in thread
From: Jean-Francois Moine @ 2016-03-21  8:35 UTC (permalink / raw)
  To: linux-arm-kernel

On Mon, 21 Mar 2016 08:29:18 +0100
Maxime Ripard <maxime.ripard@free-electrons.com> wrote:

> > @@ -470,6 +473,10 @@ static int set_config(struct sun6i_dma_dev *sdev,
> >  {
> >  	s8 src_width, dst_width, src_burst, dst_burst;
> >  
> > +	if (!sdev->cfg->burst_4 &&
> > +	    (sconfig->src_maxburst == 4 || sconfig->dst_maxburst == 4))
> > +		return -EINVAL;
> > +
> 
> I still believe this should be dealt with at the framework level.

What do you mean? In the DMA clients?

-- 
Ken ar c'henta?	|	      ** Breizh ha Linux atav! **
Jef		|		http://moinejf.free.fr/

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH v3 4/5] dmaengine: sun6i: Simplify some macros
  2016-03-21  7:48   ` Maxime Ripard
@ 2016-03-21 14:40     ` Jean-Francois Moine
  0 siblings, 0 replies; 14+ messages in thread
From: Jean-Francois Moine @ 2016-03-21 14:40 UTC (permalink / raw)
  To: linux-arm-kernel

On Mon, 21 Mar 2016 08:48:43 +0100
Maxime Ripard <maxime.ripard@free-electrons.com> wrote:

> On Fri, Mar 18, 2016 at 03:21:11PM +0100, Jean-Francois Moine wrote:
> > As the max burst and bus width values are now checked, there is
> > no reason to check them again when setting the hardware registers.
> > 
> > Signed-off-by: Jean-Francois Moine <moinejf@free.fr>
> > ---
> >  drivers/dma/sun6i-dma.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/dma/sun6i-dma.c b/drivers/dma/sun6i-dma.c
> > index 3f73123..643ba4c 100644
> > --- a/drivers/dma/sun6i-dma.c
> > +++ b/drivers/dma/sun6i-dma.c
> > @@ -65,8 +65,8 @@
> >  #define DMA_CHAN_CFG_SRC_DRQ(x)		((x) & 0x1f)
> >  #define DMA_CHAN_CFG_SRC_IO_MODE	BIT(5)
> >  #define DMA_CHAN_CFG_SRC_LINEAR_MODE	(0 << 5)
> > -#define DMA_CHAN_CFG_SRC_BURST(x)	(((x) & 0x3) << 7)
> > -#define DMA_CHAN_CFG_SRC_WIDTH(x)	(((x) & 0x3) << 9)
> > +#define DMA_CHAN_CFG_SRC_BURST(x)	((x) << 7)
> > +#define DMA_CHAN_CFG_SRC_WIDTH(x)	((x) << 9)
> 
> Well, you can easily end up with values higher than that. I still
> believe that making sure you only always write what is expected is a
> good thing.

How the values could be higher? They are locally generated in
convert_burst() and convert_buswidth() from checked client values.

-- 
Ken ar c'henta?	|	      ** Breizh ha Linux atav! **
Jef		|		http://moinejf.free.fr/

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH v3 2/5] dmaengine: sun6i: Add 4 as a possible burst value for the H3
  2016-03-21  8:35     ` Jean-Francois Moine
@ 2016-03-29  6:46       ` Maxime Ripard
  2016-03-29  9:03         ` Jean-Francois Moine
  0 siblings, 1 reply; 14+ messages in thread
From: Maxime Ripard @ 2016-03-29  6:46 UTC (permalink / raw)
  To: linux-arm-kernel

On Mon, Mar 21, 2016 at 09:35:33AM +0100, Jean-Francois Moine wrote:
> On Mon, 21 Mar 2016 08:29:18 +0100
> Maxime Ripard <maxime.ripard@free-electrons.com> wrote:
> 
> > > @@ -470,6 +473,10 @@ static int set_config(struct sun6i_dma_dev *sdev,
> > >  {
> > >  	s8 src_width, dst_width, src_burst, dst_burst;
> > >  
> > > +	if (!sdev->cfg->burst_4 &&
> > > +	    (sconfig->src_maxburst == 4 || sconfig->dst_maxburst == 4))
> > > +		return -EINVAL;
> > > +
> > 
> > I still believe this should be dealt with at the framework level.
> 
> What do you mean? In the DMA clients?

No, in the dmaengine framework.

A driver should register the burst size they support, and
dmaengine_slave_config would reject any invalid burst size based on
that.

Maxime

-- 
Maxime Ripard, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20160329/3d482454/attachment-0001.sig>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH v3 2/5] dmaengine: sun6i: Add 4 as a possible burst value for the H3
  2016-03-29  6:46       ` Maxime Ripard
@ 2016-03-29  9:03         ` Jean-Francois Moine
  0 siblings, 0 replies; 14+ messages in thread
From: Jean-Francois Moine @ 2016-03-29  9:03 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, 29 Mar 2016 08:46:50 +0200
Maxime Ripard <maxime.ripard@free-electrons.com> wrote:

> On Mon, Mar 21, 2016 at 09:35:33AM +0100, Jean-Francois Moine wrote:
> > On Mon, 21 Mar 2016 08:29:18 +0100
> > Maxime Ripard <maxime.ripard@free-electrons.com> wrote:
> > 
> > > > @@ -470,6 +473,10 @@ static int set_config(struct sun6i_dma_dev *sdev,
> > > >  {
> > > >  	s8 src_width, dst_width, src_burst, dst_burst;
> > > >  
> > > > +	if (!sdev->cfg->burst_4 &&
> > > > +	    (sconfig->src_maxburst == 4 || sconfig->dst_maxburst == 4))
> > > > +		return -EINVAL;
> > > > +
> > > 
> > > I still believe this should be dealt with at the framework level.
> > 
> > What do you mean? In the DMA clients?
> 
> No, in the dmaengine framework.
> 
> A driver should register the burst size they support, and
> dmaengine_slave_config would reject any invalid burst size based on
> that.

Maybe you are right, but this does not seem to be very easy: the max
burst size is on a u32 value, and, as a bit map (256Mb) is forbidden,
the DMA drivers should declare a list of (min, max) authorized values.

Well, I will not start such a development for just testing if 4 is a
good burst size when calling the sun6i DMA driver...

-- 
Ken ar c'henta?	|	      ** Breizh ha Linux atav! **
Jef		|		http://moinejf.free.fr/

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2016-03-29  9:03 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-18 14:32 [PATCH v3 0/5] dmaengine: sun6i: Upgrade for audio transfers Jean-Francois Moine
2016-03-18 11:50 ` [PATCH v3 1/5] dmaengine: sun6i: Simplify and fix lli setting Jean-Francois Moine
2016-03-21  7:27   ` Maxime Ripard
2016-03-18 14:12 ` [PATCH v3 2/5] dmaengine: sun6i: Add 4 as a possible burst value for the H3 Jean-Francois Moine
2016-03-21  7:29   ` Maxime Ripard
2016-03-21  8:35     ` Jean-Francois Moine
2016-03-29  6:46       ` Maxime Ripard
2016-03-29  9:03         ` Jean-Francois Moine
2016-03-18 14:18 ` [PATCH v3 3/5] dmaengine: sun6i: Add cyclic capability Jean-Francois Moine
2016-03-21  7:33   ` Maxime Ripard
2016-03-18 14:21 ` [PATCH v3 4/5] dmaengine: sun6i: Simplify some macros Jean-Francois Moine
2016-03-21  7:48   ` Maxime Ripard
2016-03-21 14:40     ` Jean-Francois Moine
2016-03-18 14:25 ` [PATCH v3 5/5] dmaengine: sun6i: Compact a bit some config constants Jean-Francois Moine

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.