linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Mans Rullgard <mans@mansr.com>, Tejun Heo <tj@kernel.org>,
	linux-ide@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/3] ata: sata_dwc_460ex: use "dmas" DT property to find dma channel
Date: Thu, 17 Dec 2015 16:58:14 +0200	[thread overview]
Message-ID: <1450364294.30729.134.camel@linux.intel.com> (raw)
In-Reply-To: <1450221935-6034-1-git-send-email-mans@mansr.com>

On Tue, 2015-12-15 at 23:25 +0000, Mans Rullgard wrote:
> Currently this driver only works with a DesignWare DMA engine which
> it
> registers manually using the second "reg" address range and interrupt
> number from the DT node.
> 
> This patch makes the driver instead use the "dmas" property if
> present,
> otherwise optionally falling back on the old way so existing device
> trees can continue to work.
> 
> With this change, there is no longer any reason to depend on the
> 460EX
> machine type so drop that from Kconfig.

Looks good for me (from dw_dmac usage prospective).

> 
> Signed-off-by: Mans Rullgard <mans@mansr.com>
> ---
>  drivers/ata/Kconfig          |  10 ++-
>  drivers/ata/sata_dwc_460ex.c | 192 +++++++++++++++++++++++++++----
> ------------
>  2 files changed, 131 insertions(+), 71 deletions(-)
> 
> diff --git a/drivers/ata/Kconfig b/drivers/ata/Kconfig
> index 3fc2a56..193c673 100644
> --- a/drivers/ata/Kconfig
> +++ b/drivers/ata/Kconfig
> @@ -296,14 +296,20 @@ config ATA_PIIX
>  
>  config SATA_DWC
>  	tristate "DesignWare Cores SATA support"
> -	depends on 460EX
> -	select DW_DMAC
>  	help
>  	  This option enables support for the on-chip SATA
> controller of the
>  	  AppliedMicro processor 460EX.
>  
>  	  If unsure, say N.
>  
> +config SATA_DWC_OLD_DMA
> +	bool "Support old device trees"
> +	depends on SATA_DWC && 460EX
> +	select DW_DMAC
> +	help
> +	  This option enables support for old device trees without
> the
> +	  "dmas" property.
> +
>  config SATA_DWC_DEBUG
>  	bool "Debugging driver version"
>  	depends on SATA_DWC
> diff --git a/drivers/ata/sata_dwc_460ex.c
> b/drivers/ata/sata_dwc_460ex.c
> index 9020349..9985749 100644
> --- a/drivers/ata/sata_dwc_460ex.c
> +++ b/drivers/ata/sata_dwc_460ex.c
> @@ -30,6 +30,7 @@
>  #include <linux/kernel.h>
>  #include <linux/module.h>
>  #include <linux/device.h>
> +#include <linux/dmaengine.h>
>  #include <linux/of_address.h>
>  #include <linux/of_irq.h>
>  #include <linux/of_platform.h>
> @@ -42,10 +43,6 @@
>  #include <scsi/scsi_host.h>
>  #include <scsi/scsi_cmnd.h>
>  
> -/* Supported DMA engine drivers */
> -#include <linux/platform_data/dma-dw.h>
> -#include <linux/dma/dw.h>
> -
>  /* These two are defined in "libata.h" */
>  #undef	DRV_NAME
>  #undef	DRV_VERSION
> @@ -148,7 +145,9 @@ struct sata_dwc_device {
>  	struct ata_host		*host;
>  	u8 __iomem		*reg_base;
>  	struct sata_dwc_regs	*sata_dwc_regs;	/* DW
> Synopsys SATA specific */
> +#ifdef CONFIG_SATA_DWC_OLD_DMA
>  	struct dw_dma_chip	*dma;
> +#endif
>  };
>  
>  #define SATA_DWC_QCMD_MAX	32
> @@ -159,7 +158,6 @@ struct sata_dwc_device_port {
>  	int			dma_pending[SATA_DWC_QCMD_MAX];
>  
>  	/* DMA info */
> -	struct dw_dma_slave		*dws;
>  	struct dma_chan			*chan;
>  	struct dma_async_tx_descriptor	*desc[SATA_DWC_QCMD_MA
> X];
>  	u32				dma_interrupt_count;
> @@ -198,13 +196,6 @@ struct sata_dwc_host_priv {
>  
>  static struct sata_dwc_host_priv host_pvt;
>  
> -static struct dw_dma_slave sata_dwc_dma_dws = {
> -	.src_id = 0,
> -	.dst_id = 0,
> -	.src_master = 0,
> -	.dst_master = 1,
> -};
> -
>  /*
>   * Prototypes
>   */
> @@ -215,6 +206,90 @@ static void sata_dwc_dma_xfer_complete(struct
> ata_port *ap, u32 check_status);
>  static void sata_dwc_port_stop(struct ata_port *ap);
>  static void sata_dwc_clear_dmacr(struct sata_dwc_device_port
> *hsdevp, u8 tag);
>  
> +#ifdef CONFIG_SATA_DWC_OLD_DMA
> +
> +#include <linux/platform_data/dma-dw.h>
> +#include <linux/dma/dw.h>
> +
> +static struct dw_dma_slave sata_dwc_dma_dws = {
> +	.src_id = 0,
> +	.dst_id = 0,
> +	.src_master = 0,
> +	.dst_master = 1,
> +};
> +
> +static bool sata_dwc_dma_filter(struct dma_chan *chan, void *param)
> +{
> +	struct dw_dma_slave *dws = &sata_dwc_dma_dws;
> +
> +	if (dws->dma_dev != chan->device->dev)
> +		return false;
> +
> +	chan->private = dws;
> +	return true;
> +}
> +
> +static int sata_dwc_dma_get_channel_old(struct sata_dwc_device_port
> *hsdevp)
> +{
> +	struct sata_dwc_device *hsdev = hsdevp->hsdev;
> +	struct dw_dma_slave *dws = &sata_dwc_dma_dws;
> +	dma_cap_mask_t mask;
> +
> +	dws->dma_dev = hsdev->dev;
> +
> +	dma_cap_zero(mask);
> +	dma_cap_set(DMA_SLAVE, mask);
> +
> +	/* Acquire DMA channel */
> +	hsdevp->chan = dma_request_channel(mask,
> sata_dwc_dma_filter, hsdevp);
> +	if (!hsdevp->chan) {
> +		dev_err(hsdev->dev, "%s: dma channel unavailable\n",
> +			 __func__);
> +		return -EAGAIN;
> +	}
> +
> +	return 0;
> +}
> +
> +static int sata_dwc_dma_init_old(struct platform_device *pdev,
> +				 struct sata_dwc_device *hsdev)
> +{
> +	struct device_node *np = pdev->dev.of_node;
> +	int err;
> +
> +	hsdev->dma = devm_kzalloc(&pdev->dev, sizeof(*hsdev->dma),
> GFP_KERNEL);
> +	if (!hsdev->dma)
> +		return -ENOMEM;
> +
> +	hsdev->dma->dev = &pdev->dev;
> +
> +	/* Get SATA DMA interrupt number */
> +	hsdev->dma->irq = irq_of_parse_and_map(np, 1);
> +	if (hsdev->dma->irq == NO_IRQ) {
> +		dev_err(&pdev->dev, "no SATA DMA irq\n");
> +		return -ENODEV;
> +	}
> +
> +	/* Get physical SATA DMA register base address */
> +	hsdev->dma->regs = of_iomap(np, 1);
> +	if (!hsdev->dma->regs) {
> +		dev_err(&pdev->dev,
> +			"ioremap failed for AHBDMA register
> address\n");
> +		return -ENODEV;
> +	}
> +
> +	/* Initialize AHB DMAC */
> +	err = dw_dma_probe(hsdev->dma, NULL);
> +	if (err) {
> +		iounmap(hsdev->dma->regs);
> +		return err;
> +	}
> +
> +	return 0;
> +}
> +
> +#endif
> +
>  static const char *get_prot_descript(u8 protocol)
>  {
>  	switch ((enum ata_tf_protocols)protocol) {
> @@ -783,18 +858,6 @@ static void sata_dwc_enable_interrupts(struct
> sata_dwc_device *hsdev)
>  		in_le32(&hsdev->sata_dwc_regs->errmr));
>  }
>  
> -static bool sata_dwc_dma_filter(struct dma_chan *chan, void *param)
> -{
> -	struct sata_dwc_device_port *hsdevp = param;
> -	struct dw_dma_slave *dws = hsdevp->dws;
> -
> -	if (dws->dma_dev != chan->device->dev)
> -		return false;
> -
> -	chan->private = dws;
> -	return true;
> -}
> -
>  static void sata_dwc_setup_port(struct ata_ioports *port, unsigned
> long base)
>  {
>  	port->cmd_addr = (void __iomem *)base + 0x00;
> @@ -817,6 +880,26 @@ static void sata_dwc_setup_port(struct
> ata_ioports *port, unsigned long base)
>  	port->ctl_addr = (void __iomem *)base + 0x20;
>  }
>  
> +static int sata_dwc_dma_get_channel(struct sata_dwc_device_port
> *hsdevp)
> +{
> +	struct sata_dwc_device *hsdev = hsdevp->hsdev;
> +	struct device *dev = hsdev->dev;
> +
> +#ifdef CONFIG_SATA_DWC_OLD_DMA
> +	if (!of_find_property(dev->of_node, "dmas", NULL))
> +		return sata_dwc_dma_get_channel_old(hsdevp);
> +#endif
> +
> +	hsdevp->chan = dma_request_slave_channel(dev, "sata-dma");
> +	if (IS_ERR(hsdevp->chan)) {
> +		dev_err(dev, "failed to allocate dma channel:
> %ld\n",
> +			PTR_ERR(hsdevp->chan));
> +		return PTR_ERR(hsdevp->chan);
> +	}
> +
> +	return 0;
> +}
> +
>  /*
>   * Function : sata_dwc_port_start
>   * arguments : struct ata_ioports *port
> @@ -829,7 +912,6 @@ static int sata_dwc_port_start(struct ata_port
> *ap)
>  	struct sata_dwc_device *hsdev;
>  	struct sata_dwc_device_port *hsdevp = NULL;
>  	struct device *pdev;
> -	dma_cap_mask_t mask;
>  	int i;
>  
>  	hsdev = HSDEV_FROM_AP(ap);
> @@ -853,20 +935,9 @@ static int sata_dwc_port_start(struct ata_port
> *ap)
>  	}
>  	hsdevp->hsdev = hsdev;
>  
> -	hsdevp->dws = &sata_dwc_dma_dws;
> -	hsdevp->dws->dma_dev = hsdev->dev;
> -
> -	dma_cap_zero(mask);
> -	dma_cap_set(DMA_SLAVE, mask);
> -
> -	/* Acquire DMA channel */
> -	hsdevp->chan = dma_request_channel(mask,
> sata_dwc_dma_filter, hsdevp);
> -	if (!hsdevp->chan) {
> -		dev_err(hsdev->dev, "%s: dma channel unavailable\n",
> -			 __func__);
> -		err = -EAGAIN;
> +	err = sata_dwc_dma_get_channel(hsdevp);
> +	if (err)
>  		goto CLEANUP_ALLOC;
> -	}
>  
>  	for (i = 0; i < SATA_DWC_QCMD_MAX; i++)
>  		hsdevp->cmd_issued[i] = SATA_DWC_CMD_ISSUED_NOT;
> @@ -1225,33 +1296,9 @@ static int sata_dwc_probe(struct
> platform_device *ofdev)
>  	dev_notice(&ofdev->dev, "id %d, controller version
> %c.%c%c\n",
>  		   idr, ver[0], ver[1], ver[2]);
>  
> -	/* Get SATA DMA interrupt number */
> -	hsdev->dma->irq = irq_of_parse_and_map(np, 1);
> -	if (hsdev->dma->irq == NO_IRQ) {
> -		dev_err(&ofdev->dev, "no SATA DMA irq\n");
> -		err = -ENODEV;
> -		goto error_iomap;
> -	}
> -
> -	/* Get physical SATA DMA register base address */
> -	hsdev->dma->regs = of_iomap(np, 1);
> -	if (!hsdev->dma->regs) {
> -		dev_err(&ofdev->dev,
> -			"ioremap failed for AHBDMA register
> address\n");
> -		err = -ENODEV;
> -		goto error_iomap;
> -	}
> -
>  	/* Save dev for later use in dev_xxx() routines */
>  	hsdev->dev = &ofdev->dev;
>  
> -	hsdev->dma->dev = &ofdev->dev;
> -
> -	/* Initialize AHB DMAC */
> -	err = dw_dma_probe(hsdev->dma, NULL);
> -	if (err)
> -		goto error_dma_iomap;
> -
>  	/* Enable SATA Interrupts */
>  	sata_dwc_enable_interrupts(hsdev);
>  
> @@ -1263,6 +1310,14 @@ static int sata_dwc_probe(struct
> platform_device *ofdev)
>  		goto error_out;
>  	}
>  
> +#ifdef CONFIG_SATA_DWC_OLD_DMA
> +	if (!of_find_property(np, "dmas", NULL)) {
> +		err = sata_dwc_dma_init_old(ofdev, hsdev);
> +		if (err)
> +			goto error_out;
> +	}
> +#endif
> +
>  	/*
>  	 * Now, register with libATA core, this will also initiate
> the
>  	 * device discovery process, invoking our port_start()
> handler &
> @@ -1276,11 +1331,6 @@ static int sata_dwc_probe(struct
> platform_device *ofdev)
>  	return 0;
>  
>  error_out:
> -	/* Free SATA DMA resources */
> -	dw_dma_remove(hsdev->dma);
> -error_dma_iomap:
> -	iounmap(hsdev->dma->regs);
> -error_iomap:
>  	iounmap(base);
>  	return err;
>  }
> @@ -1293,10 +1343,14 @@ static int sata_dwc_remove(struct
> platform_device *ofdev)
>  
>  	ata_host_detach(host);
>  
> +#ifdef CONFIG_SATA_DWC_OLD_DMA
>  	/* Free SATA DMA resources */
> -	dw_dma_remove(hsdev->dma);
> +	if (hsdev->dma) {
> +		dw_dma_remove(hsdev->dma);
> +		iounmap(hsdev->dma->regs);
> +	}
> +#endif
>  
> -	iounmap(hsdev->dma->regs);
>  	iounmap(hsdev->reg_base);
>  	dev_dbg(&ofdev->dev, "done\n");
>  	return 0;

-- 
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Intel Finland Oy


      parent reply	other threads:[~2015-12-17 14:58 UTC|newest]

Thread overview: 118+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-15 23:25 [PATCH 1/3] ata: sata_dwc_460ex: use "dmas" DT property to find dma channel Mans Rullgard
2015-12-15 23:25 ` [PATCH 2/3] ata: sata_dwc_460ex: add phy support Mans Rullgard
2015-12-16 11:14   ` Sergei Shtylyov
2015-12-16 11:24     ` Måns Rullgård
2015-12-15 23:25 ` [PATCH 3/3] ata: sata_dwc_460ex: get rid of global data Mans Rullgard
2015-12-17 15:06   ` Andy Shevchenko
2015-12-17 15:19     ` Måns Rullgård
2015-12-17 15:37       ` Andy Shevchenko
2015-12-17 15:57         ` Måns Rullgård
2015-12-15 23:34 ` [PATCH 1/3] ata: sata_dwc_460ex: use "dmas" DT property to find dma channel Måns Rullgård
2015-12-17 14:59   ` Andy Shevchenko
2015-12-17 15:13     ` Måns Rullgård
2015-12-17 15:55       ` Andy Shevchenko
2015-12-17 16:04         ` Måns Rullgård
2015-12-17 16:53           ` Andy Shevchenko
2015-12-17 17:57             ` Julian Margetson
2015-12-17 17:59               ` Måns Rullgård
     [not found]                 ` <567302E8.5050303@candw.ms>
2015-12-17 18:51                   ` Måns Rullgård
     [not found]                     ` <5673061A.4070700@candw.ms>
2015-12-17 19:53                       ` Måns Rullgård
     [not found]                         ` <56732C04.9040100@candw.ms>
2015-12-18  0:06                           ` Måns Rullgård
2015-12-18  0:59                             ` Julian Margetson
2015-12-18  1:38                               ` Måns Rullgård
2015-12-18 11:48                             ` Julian Margetson
2015-12-18 12:04                               ` Måns Rullgård
2015-12-18 12:23                                 ` Andy Shevchenko
2015-12-18 12:49                                   ` Måns Rullgård
     [not found]                                     ` <5674271B.9090308@candw.ms>
2015-12-18 17:18                                       ` Måns Rullgård
2015-12-18 18:48                                         ` Andy Shevchenko
     [not found]                                         ` <56745BA4.1090607@candw.ms>
2015-12-18 22:33                                           ` Måns Rullgård
2015-12-18 22:49                                             ` Julian Margetson
2015-12-18 23:16                                               ` Måns Rullgård
2015-12-19  2:34                                                 ` Andy Shevchenko
2015-12-19 11:39                                                   ` Julian Margetson
2015-12-19 15:40                                                     ` Måns Rullgård
     [not found]                                                       ` <567585CD.9080105@candw.ms>
2015-12-19 16:39                                                         ` Måns Rullgård
2015-12-19 16:56                                                       ` Andy Shevchenko
2015-12-19 17:05                                                         ` Måns Rullgård
2015-12-19 17:09                                                           ` Julian Margetson
2015-12-19 17:11                                                             ` Andy Shevchenko
2015-12-19 17:19                                                             ` Måns Rullgård
2015-12-19 18:56                                                               ` Julian Margetson
2015-12-19 19:07                                                                 ` Måns Rullgård
2015-12-19 20:16                                                                   ` Julian Margetson
2015-12-19 20:39                                                                     ` Andy Shevchenko
2015-12-19 20:41                                                                       ` Måns Rullgård
2015-12-19 20:48                                                                         ` Julian Margetson
2015-12-19 20:55                                                                         ` Julian Margetson
2015-12-20 17:11                                                                           ` Måns Rullgård
2015-12-20 17:41                                                                             ` Andy Shevchenko
2015-12-20 17:54                                                                               ` Måns Rullgård
2015-12-20 17:44                                                                             ` Julian Margetson
2015-12-20 18:49                                                                               ` Måns Rullgård
2015-12-20 20:17                                                                                 ` Andy Shevchenko
2015-12-20 20:55                                                                                   ` Andy Shevchenko
2015-12-21  1:19                                                                                     ` Måns Rullgård
2015-12-21 19:08                                                                                       ` Andy Shevchenko
2015-12-21 19:27                                                                                         ` Måns Rullgård
2015-12-21 20:54                                                                                           ` Andy Shevchenko
2015-12-21 21:06                                                                                             ` Måns Rullgård
2015-12-22  0:08                                                                                             ` Måns Rullgård
2015-12-22 10:58                                                                                               ` Andy Shevchenko
2016-01-06 16:26                                                                                                 ` Måns Rullgård
2016-01-06 17:36                                                                                                   ` Andy Shevchenko
2016-01-07  9:34                                                                                                     ` Andy Shevchenko
2016-01-07 18:32                                                                                                       ` Måns Rullgård
2016-01-08  8:57                                                                                                         ` Andy Shevchenko
2016-01-08 10:57                                                                                                           ` Måns Rullgård
2016-01-20 18:50                                                                                                           ` Måns Rullgård
2016-01-20 19:23                                                                                                             ` Andy Shevchenko
2016-01-20 19:24                                                                                                               ` Måns Rullgård
2016-01-20 19:38                                                                                                                 ` Andy Shevchenko
2016-01-20 19:46                                                                                                                   ` Måns Rullgård
2016-01-20 19:51                                                                                                                     ` Andy Shevchenko
2016-01-20 20:07                                                                                                                       ` Måns Rullgård
2016-01-22 10:04                                                                                                                         ` Andy Shevchenko
2016-01-22 11:13                                                                                                                           ` Måns Rullgård
2016-01-22 11:56                                                                                                                             ` Andy Shevchenko
2016-01-22 12:05                                                                                                                               ` Måns Rullgård
2016-01-22 12:15                                                                                                                                 ` Andy Shevchenko
2015-12-21 16:48                                                                                     ` Andy Shevchenko
2015-12-21 17:20                                                                                       ` Julian Margetson
2015-12-21 17:26                                                                                       ` Julian Margetson
2015-12-21 17:55                                                                                         ` Andy Shevchenko
2015-12-21 18:23                                                                                           ` Julian Margetson
2015-12-21 18:27                                                                                             ` Måns Rullgård
2015-12-21 19:08                                                                                               ` Julian Margetson
2015-12-21 19:19                                                                                               ` Julian Margetson
2015-12-21 19:27                                                                                                 ` Måns Rullgård
2015-12-21 19:47                                                                                                   ` Julian Margetson
2015-12-21 20:25                                                                                                 ` Andy Shevchenko
2015-12-21 20:29                                                                                                   ` Julian Margetson
2016-01-22 10:07                                                                                                     ` Andy Shevchenko
2015-12-21 20:33                                                                                                   ` Måns Rullgård
2015-12-21 18:25                                                                                           ` Måns Rullgård
2015-12-21  0:47                                                                                   ` Måns Rullgård
2015-12-21  0:53                                                                                     ` Måns Rullgård
2015-12-21  0:58                                                                                   ` Måns Rullgård
2015-12-21  8:40                                                                                     ` Andy Shevchenko
2015-12-21 12:15                                                                                       ` Måns Rullgård
2015-12-21 17:24                                                                                         ` Andy Shevchenko
2015-12-21 18:16                                                                                           ` Måns Rullgård
2015-12-21 19:23                                                                                             ` Andy Shevchenko
2015-12-21 19:50                                                                                               ` Måns Rullgård
     [not found]                                                                                       ` <5677D447.40906@candw.ms>
2015-12-21 12:16                                                                                         ` Måns Rullgård
2015-12-21 13:18                                                                                           ` Julian Margetson
2015-12-21 13:24                                                                                             ` Måns Rullgård
2015-12-21 14:40                                                                                               ` Julian Margetson
2015-12-21 15:24                                                                                                 ` Måns Rullgård
2015-12-21 16:44                                                                                                   ` Andy Shevchenko
2015-12-21 18:19                                                                                                     ` Måns Rullgård
2015-12-18 12:33                                 ` Julian Margetson
2015-12-18 12:38                                   ` Andy Shevchenko
2015-12-18 12:45                                   ` Måns Rullgård
     [not found]                                     ` <56740F9F.5020500@candw.ms>
2015-12-18 14:24                                       ` Andy Shevchenko
2015-12-18 14:27                                       ` Måns Rullgård
2015-12-18 10:08                           ` Andy Shevchenko
2015-12-18 11:24                             ` Måns Rullgård
2015-12-17 14:58 ` Andy Shevchenko [this message]

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=1450364294.30729.134.camel@linux.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mans@mansr.com \
    --cc=tj@kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).