aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn Guo <shawn.guo@linaro.org>2013-02-25 22:07:32 -0500
committerShawn Guo <shawn.guo@linaro.org>2013-04-04 09:22:44 -0400
commit26aafa77df61c4190eae80646211ee6f07c88eaf (patch)
tree5ae896947ebde38999bd5271a8a13ad09a2b117d
parent0e91e434c86c84e84c46cf8bff2b5e53daee85d5 (diff)
spi: mxs-spi: move to use generic DMA helper
With the generic DMA device tree helper supported by mxs-dma driver, client devices only need to call dma_request_slave_channel() for requesting a DMA channel from dmaengine. Since mxs is a DT only platform now, along with the changes, the non-DT case handling in probe function also gets removed. Signed-off-by: Shawn Guo <shawn.guo@linaro.org> Acked-by: Grant Likely <grant.likely@secretlab.ca> Reviewed-by: Arnd Bergmann <arnd@arndb.de>
-rw-r--r--Documentation/devicetree/bindings/spi/mxs-spi.txt12
-rw-r--r--drivers/spi/spi-mxs.c60
-rw-r--r--include/linux/spi/mxs-spi.h4
3 files changed, 18 insertions, 58 deletions
diff --git a/Documentation/devicetree/bindings/spi/mxs-spi.txt b/Documentation/devicetree/bindings/spi/mxs-spi.txt
index e2e13957c2a4..3499b73293c2 100644
--- a/Documentation/devicetree/bindings/spi/mxs-spi.txt
+++ b/Documentation/devicetree/bindings/spi/mxs-spi.txt
@@ -3,8 +3,11 @@
3Required properties: 3Required properties:
4- compatible: Should be "fsl,<soc>-spi", where soc is "imx23" or "imx28" 4- compatible: Should be "fsl,<soc>-spi", where soc is "imx23" or "imx28"
5- reg: Offset and length of the register set for the device 5- reg: Offset and length of the register set for the device
6- interrupts: Should contain SSP interrupts (error irq first, dma irq second) 6- interrupts: Should contain SSP ERROR interrupt
7- fsl,ssp-dma-channel: APBX DMA channel for the SSP 7- dmas: DMA specifier, consisting of a phandle to DMA controller node
8 and SSP DMA channel ID.
9 Refer to dma.txt and fsl-mxs-dma.txt for details.
10- dma-names: Must be "rx-tx".
8 11
9Optional properties: 12Optional properties:
10- clock-frequency : Input clock frequency to the SPI block in Hz. 13- clock-frequency : Input clock frequency to the SPI block in Hz.
@@ -17,6 +20,7 @@ ssp0: ssp@80010000 {
17 #size-cells = <0>; 20 #size-cells = <0>;
18 compatible = "fsl,imx28-spi"; 21 compatible = "fsl,imx28-spi";
19 reg = <0x80010000 0x2000>; 22 reg = <0x80010000 0x2000>;
20 interrupts = <96 82>; 23 interrupts = <96>;
21 fsl,ssp-dma-channel = <0>; 24 dmas = <&dma_apbh 0>;
25 dma-names = "rx-tx";
22}; 26};
diff --git a/drivers/spi/spi-mxs.c b/drivers/spi/spi-mxs.c
index 22a0af0147fb..7b1c014b0740 100644
--- a/drivers/spi/spi-mxs.c
+++ b/drivers/spi/spi-mxs.c
@@ -490,21 +490,6 @@ static int mxs_spi_transfer_one(struct spi_master *master,
490 return status; 490 return status;
491} 491}
492 492
493static bool mxs_ssp_dma_filter(struct dma_chan *chan, void *param)
494{
495 struct mxs_ssp *ssp = param;
496
497 if (!mxs_dma_is_apbh(chan))
498 return false;
499
500 if (chan->chan_id != ssp->dma_channel)
501 return false;
502
503 chan->private = &ssp->dma_data;
504
505 return true;
506}
507
508static const struct of_device_id mxs_spi_dt_ids[] = { 493static const struct of_device_id mxs_spi_dt_ids[] = {
509 { .compatible = "fsl,imx23-spi", .data = (void *) IMX23_SSP, }, 494 { .compatible = "fsl,imx23-spi", .data = (void *) IMX23_SSP, },
510 { .compatible = "fsl,imx28-spi", .data = (void *) IMX28_SSP, }, 495 { .compatible = "fsl,imx28-spi", .data = (void *) IMX28_SSP, },
@@ -520,13 +505,12 @@ static int mxs_spi_probe(struct platform_device *pdev)
520 struct spi_master *master; 505 struct spi_master *master;
521 struct mxs_spi *spi; 506 struct mxs_spi *spi;
522 struct mxs_ssp *ssp; 507 struct mxs_ssp *ssp;
523 struct resource *iores, *dmares; 508 struct resource *iores;
524 struct pinctrl *pinctrl; 509 struct pinctrl *pinctrl;
525 struct clk *clk; 510 struct clk *clk;
526 void __iomem *base; 511 void __iomem *base;
527 int devid, dma_channel, clk_freq; 512 int devid, clk_freq;
528 int ret = 0, irq_err, irq_dma; 513 int ret = 0, irq_err;
529 dma_cap_mask_t mask;
530 514
531 /* 515 /*
532 * Default clock speed for the SPI core. 160MHz seems to 516 * Default clock speed for the SPI core. 160MHz seems to
@@ -537,8 +521,7 @@ static int mxs_spi_probe(struct platform_device *pdev)
537 521
538 iores = platform_get_resource(pdev, IORESOURCE_MEM, 0); 522 iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
539 irq_err = platform_get_irq(pdev, 0); 523 irq_err = platform_get_irq(pdev, 0);
540 irq_dma = platform_get_irq(pdev, 1); 524 if (!iores || irq_err < 0)
541 if (!iores || irq_err < 0 || irq_dma < 0)
542 return -EINVAL; 525 return -EINVAL;
543 526
544 base = devm_ioremap_resource(&pdev->dev, iores); 527 base = devm_ioremap_resource(&pdev->dev, iores);
@@ -553,32 +536,11 @@ static int mxs_spi_probe(struct platform_device *pdev)
553 if (IS_ERR(clk)) 536 if (IS_ERR(clk))
554 return PTR_ERR(clk); 537 return PTR_ERR(clk);
555 538
556 if (np) { 539 devid = (enum mxs_ssp_id) of_id->data;
557 devid = (enum mxs_ssp_id) of_id->data; 540 ret = of_property_read_u32(np, "clock-frequency",
558 /* 541 &clk_freq);
559 * TODO: This is a temporary solution and should be changed 542 if (ret)
560 * to use generic DMA binding later when the helpers get in.
561 */
562 ret = of_property_read_u32(np, "fsl,ssp-dma-channel",
563 &dma_channel);
564 if (ret) {
565 dev_err(&pdev->dev,
566 "Failed to get DMA channel\n");
567 return -EINVAL;
568 }
569
570 ret = of_property_read_u32(np, "clock-frequency",
571 &clk_freq);
572 if (ret)
573 clk_freq = clk_freq_default;
574 } else {
575 dmares = platform_get_resource(pdev, IORESOURCE_DMA, 0);
576 if (!dmares)
577 return -EINVAL;
578 devid = pdev->id_entry->driver_data;
579 dma_channel = dmares->start;
580 clk_freq = clk_freq_default; 543 clk_freq = clk_freq_default;
581 }
582 544
583 master = spi_alloc_master(&pdev->dev, sizeof(*spi)); 545 master = spi_alloc_master(&pdev->dev, sizeof(*spi));
584 if (!master) 546 if (!master)
@@ -597,7 +559,6 @@ static int mxs_spi_probe(struct platform_device *pdev)
597 ssp->clk = clk; 559 ssp->clk = clk;
598 ssp->base = base; 560 ssp->base = base;
599 ssp->devid = devid; 561 ssp->devid = devid;
600 ssp->dma_channel = dma_channel;
601 562
602 init_completion(&spi->c); 563 init_completion(&spi->c);
603 564
@@ -606,10 +567,7 @@ static int mxs_spi_probe(struct platform_device *pdev)
606 if (ret) 567 if (ret)
607 goto out_master_free; 568 goto out_master_free;
608 569
609 dma_cap_zero(mask); 570 ssp->dmach = dma_request_slave_channel(&pdev->dev, "rx-tx");
610 dma_cap_set(DMA_SLAVE, mask);
611 ssp->dma_data.chan_irq = irq_dma;
612 ssp->dmach = dma_request_channel(mask, mxs_ssp_dma_filter, ssp);
613 if (!ssp->dmach) { 571 if (!ssp->dmach) {
614 dev_err(ssp->dev, "Failed to request DMA\n"); 572 dev_err(ssp->dev, "Failed to request DMA\n");
615 goto out_master_free; 573 goto out_master_free;
diff --git a/include/linux/spi/mxs-spi.h b/include/linux/spi/mxs-spi.h
index 61ae1306db23..4835486f58e5 100644
--- a/include/linux/spi/mxs-spi.h
+++ b/include/linux/spi/mxs-spi.h
@@ -24,7 +24,7 @@
24#ifndef __LINUX_SPI_MXS_SPI_H__ 24#ifndef __LINUX_SPI_MXS_SPI_H__
25#define __LINUX_SPI_MXS_SPI_H__ 25#define __LINUX_SPI_MXS_SPI_H__
26 26
27#include <linux/fsl/mxs-dma.h> 27#include <linux/dmaengine.h>
28 28
29#define ssp_is_old(host) ((host)->devid == IMX23_SSP) 29#define ssp_is_old(host) ((host)->devid == IMX23_SSP)
30 30
@@ -137,9 +137,7 @@ struct mxs_ssp {
137 unsigned int clk_rate; 137 unsigned int clk_rate;
138 enum mxs_ssp_id devid; 138 enum mxs_ssp_id devid;
139 139
140 int dma_channel;
141 struct dma_chan *dmach; 140 struct dma_chan *dmach;
142 struct mxs_dma_data dma_data;
143 unsigned int dma_dir; 141 unsigned int dma_dir;
144 enum dma_transfer_direction slave_dirn; 142 enum dma_transfer_direction slave_dirn;
145 u32 ssp_pio_words[SSP_PIO_NUM]; 143 u32 ssp_pio_words[SSP_PIO_NUM];