diff options
author | Peter Ujfalusi <peter.ujfalusi@ti.com> | 2016-04-29 09:10:22 -0400 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2016-04-29 13:15:15 -0400 |
commit | fe5fd2540947a6c584e70f1249007dd636e62d78 (patch) | |
tree | 9f41d0ed04470586ad88ddc0cbed8764e33dfa55 /drivers/spi | |
parent | f55532a0c0b8bb6148f4e07853b876ef73bc69ca (diff) |
spi: davinci: Use dma_request_chan() for requesting DMA channel
With the new dma_request_chan() the client driver does not need to look for
the DMA resource and it does not need to pass filter_fn anymore.
By switching to the new API the driver can now support deferred probing
against DMA.
Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
Diffstat (limited to 'drivers/spi')
-rw-r--r-- | drivers/spi/spi-davinci.c | 76 |
1 files changed, 24 insertions, 52 deletions
diff --git a/drivers/spi/spi-davinci.c b/drivers/spi/spi-davinci.c index fddb7a3be322..d36c11b73a35 100644 --- a/drivers/spi/spi-davinci.c +++ b/drivers/spi/spi-davinci.c | |||
@@ -23,7 +23,6 @@ | |||
23 | #include <linux/clk.h> | 23 | #include <linux/clk.h> |
24 | #include <linux/dmaengine.h> | 24 | #include <linux/dmaengine.h> |
25 | #include <linux/dma-mapping.h> | 25 | #include <linux/dma-mapping.h> |
26 | #include <linux/edma.h> | ||
27 | #include <linux/of.h> | 26 | #include <linux/of.h> |
28 | #include <linux/of_device.h> | 27 | #include <linux/of_device.h> |
29 | #include <linux/of_gpio.h> | 28 | #include <linux/of_gpio.h> |
@@ -33,8 +32,6 @@ | |||
33 | 32 | ||
34 | #include <linux/platform_data/spi-davinci.h> | 33 | #include <linux/platform_data/spi-davinci.h> |
35 | 34 | ||
36 | #define SPI_NO_RESOURCE ((resource_size_t)-1) | ||
37 | |||
38 | #define CS_DEFAULT 0xFF | 35 | #define CS_DEFAULT 0xFF |
39 | 36 | ||
40 | #define SPIFMT_PHASE_MASK BIT(16) | 37 | #define SPIFMT_PHASE_MASK BIT(16) |
@@ -130,8 +127,6 @@ struct davinci_spi { | |||
130 | 127 | ||
131 | struct dma_chan *dma_rx; | 128 | struct dma_chan *dma_rx; |
132 | struct dma_chan *dma_tx; | 129 | struct dma_chan *dma_tx; |
133 | int dma_rx_chnum; | ||
134 | int dma_tx_chnum; | ||
135 | 130 | ||
136 | struct davinci_spi_platform_data pdata; | 131 | struct davinci_spi_platform_data pdata; |
137 | 132 | ||
@@ -797,35 +792,19 @@ static irqreturn_t davinci_spi_irq(s32 irq, void *data) | |||
797 | 792 | ||
798 | static int davinci_spi_request_dma(struct davinci_spi *dspi) | 793 | static int davinci_spi_request_dma(struct davinci_spi *dspi) |
799 | { | 794 | { |
800 | dma_cap_mask_t mask; | ||
801 | struct device *sdev = dspi->bitbang.master->dev.parent; | 795 | struct device *sdev = dspi->bitbang.master->dev.parent; |
802 | int r; | ||
803 | |||
804 | dma_cap_zero(mask); | ||
805 | dma_cap_set(DMA_SLAVE, mask); | ||
806 | 796 | ||
807 | dspi->dma_rx = dma_request_channel(mask, edma_filter_fn, | 797 | dspi->dma_rx = dma_request_chan(sdev, "rx"); |
808 | &dspi->dma_rx_chnum); | 798 | if (IS_ERR(dspi->dma_rx)) |
809 | if (!dspi->dma_rx) { | 799 | return PTR_ERR(dspi->dma_rx); |
810 | dev_err(sdev, "request RX DMA channel failed\n"); | ||
811 | r = -ENODEV; | ||
812 | goto rx_dma_failed; | ||
813 | } | ||
814 | 800 | ||
815 | dspi->dma_tx = dma_request_channel(mask, edma_filter_fn, | 801 | dspi->dma_tx = dma_request_chan(sdev, "tx"); |
816 | &dspi->dma_tx_chnum); | 802 | if (IS_ERR(dspi->dma_tx)) { |
817 | if (!dspi->dma_tx) { | 803 | dma_release_channel(dspi->dma_rx); |
818 | dev_err(sdev, "request TX DMA channel failed\n"); | 804 | return PTR_ERR(dspi->dma_tx); |
819 | r = -ENODEV; | ||
820 | goto tx_dma_failed; | ||
821 | } | 805 | } |
822 | 806 | ||
823 | return 0; | 807 | return 0; |
824 | |||
825 | tx_dma_failed: | ||
826 | dma_release_channel(dspi->dma_rx); | ||
827 | rx_dma_failed: | ||
828 | return r; | ||
829 | } | 808 | } |
830 | 809 | ||
831 | #if defined(CONFIG_OF) | 810 | #if defined(CONFIG_OF) |
@@ -936,8 +915,6 @@ static int davinci_spi_probe(struct platform_device *pdev) | |||
936 | struct davinci_spi *dspi; | 915 | struct davinci_spi *dspi; |
937 | struct davinci_spi_platform_data *pdata; | 916 | struct davinci_spi_platform_data *pdata; |
938 | struct resource *r; | 917 | struct resource *r; |
939 | resource_size_t dma_rx_chan = SPI_NO_RESOURCE; | ||
940 | resource_size_t dma_tx_chan = SPI_NO_RESOURCE; | ||
941 | int ret = 0; | 918 | int ret = 0; |
942 | u32 spipc0; | 919 | u32 spipc0; |
943 | 920 | ||
@@ -1044,27 +1021,15 @@ static int davinci_spi_probe(struct platform_device *pdev) | |||
1044 | } | 1021 | } |
1045 | } | 1022 | } |
1046 | 1023 | ||
1047 | r = platform_get_resource(pdev, IORESOURCE_DMA, 0); | ||
1048 | if (r) | ||
1049 | dma_rx_chan = r->start; | ||
1050 | r = platform_get_resource(pdev, IORESOURCE_DMA, 1); | ||
1051 | if (r) | ||
1052 | dma_tx_chan = r->start; | ||
1053 | |||
1054 | dspi->bitbang.txrx_bufs = davinci_spi_bufs; | 1024 | dspi->bitbang.txrx_bufs = davinci_spi_bufs; |
1055 | if (dma_rx_chan != SPI_NO_RESOURCE && | 1025 | |
1056 | dma_tx_chan != SPI_NO_RESOURCE) { | 1026 | ret = davinci_spi_request_dma(dspi); |
1057 | dspi->dma_rx_chnum = dma_rx_chan; | 1027 | if (ret == -EPROBE_DEFER) { |
1058 | dspi->dma_tx_chnum = dma_tx_chan; | 1028 | goto free_clk; |
1059 | 1029 | } else if (ret) { | |
1060 | ret = davinci_spi_request_dma(dspi); | 1030 | dev_info(&pdev->dev, "DMA is not supported (%d)\n", ret); |
1061 | if (ret) | 1031 | dspi->dma_rx = NULL; |
1062 | goto free_clk; | 1032 | dspi->dma_tx = NULL; |
1063 | |||
1064 | dev_info(&pdev->dev, "DMA: supported\n"); | ||
1065 | dev_info(&pdev->dev, "DMA: RX channel: %pa, TX channel: %pa, event queue: %d\n", | ||
1066 | &dma_rx_chan, &dma_tx_chan, | ||
1067 | pdata->dma_event_q); | ||
1068 | } | 1033 | } |
1069 | 1034 | ||
1070 | dspi->get_rx = davinci_spi_rx_buf_u8; | 1035 | dspi->get_rx = davinci_spi_rx_buf_u8; |
@@ -1102,8 +1067,10 @@ static int davinci_spi_probe(struct platform_device *pdev) | |||
1102 | return ret; | 1067 | return ret; |
1103 | 1068 | ||
1104 | free_dma: | 1069 | free_dma: |
1105 | dma_release_channel(dspi->dma_rx); | 1070 | if (dspi->dma_rx) { |
1106 | dma_release_channel(dspi->dma_tx); | 1071 | dma_release_channel(dspi->dma_rx); |
1072 | dma_release_channel(dspi->dma_tx); | ||
1073 | } | ||
1107 | free_clk: | 1074 | free_clk: |
1108 | clk_disable_unprepare(dspi->clk); | 1075 | clk_disable_unprepare(dspi->clk); |
1109 | free_master: | 1076 | free_master: |
@@ -1134,6 +1101,11 @@ static int davinci_spi_remove(struct platform_device *pdev) | |||
1134 | clk_disable_unprepare(dspi->clk); | 1101 | clk_disable_unprepare(dspi->clk); |
1135 | spi_master_put(master); | 1102 | spi_master_put(master); |
1136 | 1103 | ||
1104 | if (dspi->dma_rx) { | ||
1105 | dma_release_channel(dspi->dma_rx); | ||
1106 | dma_release_channel(dspi->dma_tx); | ||
1107 | } | ||
1108 | |||
1137 | return 0; | 1109 | return 0; |
1138 | } | 1110 | } |
1139 | 1111 | ||