Linux-mtd Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Ladislav Michl <ladis@linux-mips.org>
To: Roger Quadros <rogerq@ti.com>
Cc: linux-mtd@lists.infradead.org, linux-omap@vger.kernel.org,
	Tony Lindgren <tony@atomide.com>,
	Peter Ujfalusi <peter.ujfalusi@ti.com>,
	Boris Brezillon <boris.brezillon@free-electrons.com>,
	Kyungmin Park <kyungmin.park@samsung.com>
Subject: Re: [PATCH v4 10/16] mtd: onenand: omap2: Convert to use dmaengine for memcpy
Date: Wed, 15 Nov 2017 10:32:30 +0100	[thread overview]
Message-ID: <20171115093230.p7pyskaqtg5fu74y@lenoch> (raw)
In-Reply-To: <758b3751-cd22-a53b-f323-90067108bd53@ti.com>

On Wed, Nov 15, 2017 at 10:57:20AM +0200, Roger Quadros wrote:
> On 11/11/17 23:23, Ladislav Michl wrote:
> > From: Peter Ujfalusi <peter.ujfalusi@ti.com>
> > 
> > Do not use the legacy and deprecated omap-dma interface for setting up the
> > memcpy.
> > 
> > Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
> > Signed-off-by: Ladislav Michl <ladis@linux-mips.org>
> 
> Acked-by: Roger Quadros <rogerq@ti.com>
> 
> Please see one comment below.
> 
> > ---
> >  Changes:
> >  -v4: new patch
> > 
> >  drivers/mtd/onenand/omap2.c | 80 +++++++++++++++++++++------------------------
> >  1 file changed, 38 insertions(+), 42 deletions(-)
> > 
> > diff --git a/drivers/mtd/onenand/omap2.c b/drivers/mtd/onenand/omap2.c
> > index 36314124488d..c9ff67100ef4 100644
> > --- a/drivers/mtd/onenand/omap2.c
> > +++ b/drivers/mtd/onenand/omap2.c
> > @@ -32,6 +32,7 @@
> >  #include <linux/interrupt.h>
> >  #include <linux/delay.h>
> >  #include <linux/dma-mapping.h>
> > +#include <linux/dmaengine.h>
> >  #include <linux/io.h>
> >  #include <linux/slab.h>
> >  #include <linux/gpio.h>
> > @@ -39,8 +40,6 @@
> >  #include <asm/mach/flash.h>
> >  #include <linux/platform_data/mtd-onenand-omap2.h>
> >  
> > -#include <linux/omap-dma.h>
> > -
> >  #define DRIVER_NAME "omap2-onenand"
> >  
> >  #define ONENAND_BUFRAM_SIZE	(1024 * 5)
> > @@ -55,17 +54,15 @@ struct omap2_onenand {
> >  	struct onenand_chip onenand;
> >  	struct completion irq_done;
> >  	struct completion dma_done;
> > -	int dma_channel;
> > +	struct dma_chan *dma_chan;
> >  	int freq;
> >  	int (*setup)(void __iomem *base, int *freq_ptr);
> >  	u8 flags;
> >  };
> >  
> > -static void omap2_onenand_dma_cb(int lch, u16 ch_status, void *data)
> > +static void omap2_onenand_dma_complete_func(void *completion)
> >  {
> > -	struct omap2_onenand *c = data;
> > -
> > -	complete(&c->dma_done);
> > +	complete(completion);
> >  }
> >  
> >  static irqreturn_t omap2_onenand_interrupt(int irq, void *dev_id)
> > @@ -292,23 +289,31 @@ static inline int omap2_onenand_dma_transfer(struct omap2_onenand *c,
> >  					     dma_addr_t src, dma_addr_t dst,
> >  					     size_t count)
> >  {
> > -	int data_type = __ffs((src | dst | count));
> > +	struct dma_async_tx_descriptor *tx;
> > +	dma_cookie_t cookie;
> >  
> > -	if (data_type > OMAP_DMA_DATA_TYPE_S32)
> > -		data_type = OMAP_DMA_DATA_TYPE_S32;
> > -
> > -	omap_set_dma_transfer_params(c->dma_channel, data_type,
> > -				     count / BIT(data_type), 1, 0, 0, 0);
> > -	omap_set_dma_src_params(c->dma_channel, 0, OMAP_DMA_AMODE_POST_INC,
> > -				src, 0, 0);
> > -	omap_set_dma_dest_params(c->dma_channel, 0, OMAP_DMA_AMODE_POST_INC,
> > -				 dst, 0, 0);
> > +	tx = dmaengine_prep_dma_memcpy(c->dma_chan, dst, src, count, 0);
> > +	if (!tx) {
> > +		dev_err(&c->pdev->dev, "Failed to prepare DMA memcpy\n");
> > +		return -EIO;
> > +	}
> >  
> >  	reinit_completion(&c->dma_done);
> > -	omap_start_dma(c->dma_channel);
> > +
> > +	tx->callback = omap2_onenand_dma_complete_func;
> > +	tx->callback_param = &c->dma_done;
> > +
> > +	cookie = tx->tx_submit(tx);
> > +	if (dma_submit_error(cookie)) {
> > +		dev_err(&c->pdev->dev, "Failed to do DMA tx_submit\n");
> > +		return -EIO;
> > +	}
> > +
> > +	dma_async_issue_pending(c->dma_chan);
> > +
> >  	if (!wait_for_completion_io_timeout(&c->dma_done,
> >  					    msecs_to_jiffies(20))) {
> > -		omap_stop_dma(c->dma_channel);
> > +		dmaengine_terminate_sync(c->dma_chan);
> >  		return -ETIMEDOUT;
> >  	}
> >  
> > @@ -468,8 +473,7 @@ static int omap2_onenand_probe(struct platform_device *pdev)
> >  	c->flags = pdata->flags;
> >  	c->gpmc_cs = pdata->cs;
> >  	c->gpio_irq = pdata->gpio_irq;
> > -	c->dma_channel = pdata->dma_channel;
> > -	if (c->dma_channel < 0) {
> > +	if (pdata->dma_channel < 0) {
> >  		/* if -1, don't use DMA */
> >  		c->gpio_irq = 0;
> 
> Why are we ignoring gpio_irq if DMA channel is not available?
> The wait mechanism could still benefit from the Interrupt even with no DMA right?

That's what original driver does and logic is preserved here.

> We could fix this in a separate patch of course.

And indeed we did. See "mtd: onenand: omap2: Enable DMA by default" (*) and
"mtd: onenand: omap2: Configure driver from DT".

(*) Now looking at that patch is should be renamed, as enabling DMA still depends
on pdata->dma_chan. It is enabled unconditionally in later patch. Will fix.

> >  	}
> > @@ -521,25 +525,17 @@ static int omap2_onenand_probe(struct platform_device *pdev)
> >  		goto err_release_gpio;
> >  	}
> >  
> > -	if (c->dma_channel >= 0) {
> > -		r = omap_request_dma(0, pdev->dev.driver->name,
> > -				     omap2_onenand_dma_cb, (void *) c,
> > -				     &c->dma_channel);
> > -		if (r == 0) {
> > -			omap_set_dma_write_mode(c->dma_channel,
> > -						OMAP_DMA_WRITE_NON_POSTED);
> > -			omap_set_dma_src_data_pack(c->dma_channel, 1);
> > -			omap_set_dma_src_burst_mode(c->dma_channel,
> > -						    OMAP_DMA_DATA_BURST_8);
> > -			omap_set_dma_dest_data_pack(c->dma_channel, 1);
> > -			omap_set_dma_dest_burst_mode(c->dma_channel,
> > -						     OMAP_DMA_DATA_BURST_8);
> > -		} else {
> > +	if (pdata->dma_channel >= 0) {
> > +		dma_cap_mask_t mask;
> > +
> > +		dma_cap_zero(mask);
> > +		dma_cap_set(DMA_MEMCPY, mask);
> > +
> > +		c->dma_chan = dma_request_channel(mask, NULL, NULL);
> > +		if (!c->dma_chan)
> >  			dev_info(&pdev->dev,
> >  				 "failed to allocate DMA for OneNAND, "
> >  				 "using PIO instead\n");
> > -			c->dma_channel = -1;
> > -		}
> >  	}
> >  
> >  	dev_info(&pdev->dev, "initializing on CS%d, phys base 0x%08lx, virtual "
> > @@ -553,7 +549,7 @@ static int omap2_onenand_probe(struct platform_device *pdev)
> >  	mtd_set_of_node(&c->mtd, pdata->of_node);
> >  
> >  	this = &c->onenand;
> > -	if (c->dma_channel >= 0) {
> > +	if (c->dma_chan) {
> >  		this->wait = omap2_onenand_wait;
> >  		this->read_bufferram = omap2_onenand_read_bufferram;
> >  		this->write_bufferram = omap2_onenand_write_bufferram;
> > @@ -573,8 +569,8 @@ static int omap2_onenand_probe(struct platform_device *pdev)
> >  err_release_onenand:
> >  	onenand_release(&c->mtd);
> >  err_release_dma:
> > -	if (c->dma_channel != -1)
> > -		omap_free_dma(c->dma_channel);
> > +	if (c->dma_chan)
> > +		dma_release_channel(c->dma_chan);
> >  	if (c->gpio_irq)
> >  		free_irq(gpio_to_irq(c->gpio_irq), c);
> >  err_release_gpio:
> > @@ -595,8 +591,8 @@ static int omap2_onenand_remove(struct platform_device *pdev)
> >  	struct omap2_onenand *c = dev_get_drvdata(&pdev->dev);
> >  
> >  	onenand_release(&c->mtd);
> > -	if (c->dma_channel != -1)
> > -		omap_free_dma(c->dma_channel);
> > +	if (c->dma_chan)
> > +		dma_release_channel(c->dma_chan);
> >  	omap2_onenand_shutdown(pdev);
> >  	if (c->gpio_irq) {
> >  		free_irq(gpio_to_irq(c->gpio_irq), c);
> > 
> 
> -- 
> cheers,
> -roger
> 
> Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki

  reply	other threads:[~2017-11-15  9:33 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-11 21:12 [PATCH v4 00/16] OMAP2+ OneNAND driver update Ladislav Michl
2017-11-11 21:17 ` [PATCH v4 02/16] ARM: dts: OMAP2+: Add compatible property to onenand node Ladislav Michl
2017-11-14 15:11   ` Roger Quadros
2017-11-14 23:01     ` Ladislav Michl
2017-11-14 21:39   ` Tony Lindgren
2017-11-11 21:18 ` [PATCH v4 03/16] ARM: dts: omap3-igep: Update onenand node timings Ladislav Michl
2017-11-14 15:12   ` Roger Quadros
2017-11-14 21:39   ` Tony Lindgren
2017-11-11 21:19 ` [PATCH v4 04/16] mtd: onenand: omap2: Remove regulator support Ladislav Michl
2017-11-14 15:13   ` Roger Quadros
2017-11-15 14:15   ` Sebastian Reichel
2017-11-11 21:19 ` [PATCH v4 05/16] mtd: onenand: omap2: Remove skip initial unlocking support Ladislav Michl
2017-11-14 15:14   ` Roger Quadros
2017-11-15 14:16   ` Sebastian Reichel
2017-11-11 21:20 ` [PATCH v4 06/16] mtd: onenand: omap2: Remove partitioning support from platform data Ladislav Michl
2017-11-14 15:14   ` Roger Quadros
2017-11-15 14:57   ` Sebastian Reichel
2017-11-11 21:20 ` [PATCH v4 07/16] mtd: onenand: omap2: Account waiting time as waiting on IO Ladislav Michl
2017-11-14 15:18   ` Roger Quadros
2017-11-15 15:00   ` Sebastian Reichel
2017-11-11 21:21 ` [PATCH v4 08/16] mtd: onenand: omap2: Simplify the DMA setup for various paths Ladislav Michl
2017-11-15  8:35   ` Roger Quadros
2017-11-15 15:05   ` Sebastian Reichel
2017-11-11 21:22 ` [PATCH v4 09/16] mtd: onenand: omap2: Unify OMAP2 and OMAP3 DMA implementation Ladislav Michl
2017-11-15  8:38   ` Roger Quadros
2017-11-15 15:07   ` Sebastian Reichel
2017-11-11 21:23 ` [PATCH v4 10/16] mtd: onenand: omap2: Convert to use dmaengine for memcpy Ladislav Michl
2017-11-15  8:57   ` Roger Quadros
2017-11-15  9:32     ` Ladislav Michl [this message]
2017-11-15 15:19   ` Sebastian Reichel
2017-11-11 21:24 ` [PATCH v4 11/16] mtd: onenand: omap2: Do not make delay for GPIO OMAP3 specific Ladislav Michl
2017-11-15  9:31   ` Roger Quadros
2017-11-15 15:20   ` Sebastian Reichel
2017-11-11 21:24 ` [PATCH v4 12/16] mtd: onenand: omap2: Enable DMA by default Ladislav Michl
2017-11-15 10:08   ` Roger Quadros
2017-11-15 10:32     ` Ladislav Michl
2017-11-15 10:43       ` Roger Quadros
2017-11-27 18:21         ` Ladislav Michl
2017-11-15 10:44       ` Roger Quadros
2017-11-11 21:26 ` [PATCH v4 13/16] memory: omap-gpmc: Refactor OneNAND support Ladislav Michl
2017-11-15 10:13   ` Roger Quadros
2017-11-15 10:37     ` Ladislav Michl
2017-11-11 21:27 ` [PATCH v4 14/16] mtd: onenand: omap2: Configure driver from DT Ladislav Michl
2017-11-15 10:40   ` Roger Quadros
2017-11-15 10:53     ` Ladislav Michl
2017-11-15 11:04       ` Roger Quadros
2017-11-15 11:20         ` Ladislav Michl
2017-11-15 14:41           ` Roger Quadros
2017-11-11 21:29 ` [PATCH v4 15/16] ARM: OMAP2+: Remove gpmc-onenand Ladislav Michl
2017-11-14 21:41   ` Tony Lindgren
2017-11-15 10:46   ` Roger Quadros
2017-11-11 21:29 ` [PATCH v4 16/16] ARM: dts: Nokia: Use R/B pin Ladislav Michl
2017-11-14 21:42   ` Tony Lindgren
2017-11-14 22:46     ` Ladislav Michl
2017-11-14 21:48 ` [PATCH v4 00/16] OMAP2+ OneNAND driver update Tony Lindgren
2017-11-14 22:53   ` Ladislav Michl
2017-11-15  8:10 ` Peter Ujfalusi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171115093230.p7pyskaqtg5fu74y@lenoch \
    --to=ladis@linux-mips.org \
    --cc=boris.brezillon@free-electrons.com \
    --cc=kyungmin.park@samsung.com \
    --cc=linux-mtd@lists.infradead.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=peter.ujfalusi@ti.com \
    --cc=rogerq@ti.com \
    --cc=tony@atomide.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox