diff options
| author | Mika Westerberg <mika.westerberg@linux.intel.com> | 2013-01-22 05:26:28 -0500 |
|---|---|---|
| committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2013-02-08 07:15:21 -0500 |
| commit | cd7bed00340475ee72a013a070e200e065085ef3 (patch) | |
| tree | 98f3cd20ecfaf090a772d0c0b185df7260a8336e | |
| parent | d560040f7d6fbe0a2990b8f6edca1815e19e72f5 (diff) | |
spi/pxa2xx: break out the private DMA API usage into a separate file
The PXA SPI driver uses PXA platform specific private DMA implementation
which does not work on non-PXA platforms. In order to use this driver on
other platforms we break out the private DMA implementation into a separate
file that gets compiled only when CONFIG_SPI_PXA2XX_PXADMA is set. The DMA
functions are stubbed out if there is no DMA implementation selected (i.e
we are building on non-PXA platform).
While we are there we can kill the dummy DMA bits in pxa2xx_spi.h as they
are not needed anymore for CE4100.
Once this is done we can add the generic DMA engine support to the driver
that allows usage of any DMA controller that implements DMA engine API.
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Tested-by: Lu Cao <lucao@marvell.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
| -rw-r--r-- | drivers/spi/Kconfig | 6 | ||||
| -rw-r--r-- | drivers/spi/Makefile | 4 | ||||
| -rw-r--r-- | drivers/spi/spi-pxa2xx-pxadma.c | 490 | ||||
| -rw-r--r-- | drivers/spi/spi-pxa2xx.c | 595 | ||||
| -rw-r--r-- | drivers/spi/spi-pxa2xx.h | 185 | ||||
| -rw-r--r-- | include/linux/spi/pxa2xx_spi.h | 80 |
6 files changed, 712 insertions, 648 deletions
diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig index a90393d7f106..f1878666e917 100644 --- a/drivers/spi/Kconfig +++ b/drivers/spi/Kconfig | |||
| @@ -297,6 +297,12 @@ config SPI_PPC4xx | |||
| 297 | help | 297 | help |
| 298 | This selects a driver for the PPC4xx SPI Controller. | 298 | This selects a driver for the PPC4xx SPI Controller. |
| 299 | 299 | ||
| 300 | config SPI_PXA2XX_PXADMA | ||
| 301 | bool "PXA2xx SSP legacy PXA DMA API support" | ||
| 302 | depends on SPI_PXA2XX && ARCH_PXA | ||
| 303 | help | ||
| 304 | Enable PXA private legacy DMA API support. | ||
| 305 | |||
| 300 | config SPI_PXA2XX | 306 | config SPI_PXA2XX |
| 301 | tristate "PXA2xx SSP SPI master" | 307 | tristate "PXA2xx SSP SPI master" |
| 302 | depends on ARCH_PXA || PCI | 308 | depends on ARCH_PXA || PCI |
diff --git a/drivers/spi/Makefile b/drivers/spi/Makefile index 64e970ba261c..2e3cdd3caba9 100644 --- a/drivers/spi/Makefile +++ b/drivers/spi/Makefile | |||
| @@ -47,7 +47,9 @@ obj-$(CONFIG_SPI_OMAP24XX) += spi-omap2-mcspi.o | |||
| 47 | obj-$(CONFIG_SPI_ORION) += spi-orion.o | 47 | obj-$(CONFIG_SPI_ORION) += spi-orion.o |
| 48 | obj-$(CONFIG_SPI_PL022) += spi-pl022.o | 48 | obj-$(CONFIG_SPI_PL022) += spi-pl022.o |
| 49 | obj-$(CONFIG_SPI_PPC4xx) += spi-ppc4xx.o | 49 | obj-$(CONFIG_SPI_PPC4xx) += spi-ppc4xx.o |
| 50 | obj-$(CONFIG_SPI_PXA2XX) += spi-pxa2xx.o | 50 | spi-pxa2xx-platform-objs := spi-pxa2xx.o |
| 51 | spi-pxa2xx-platform-$(CONFIG_SPI_PXA2XX_PXADMA) += spi-pxa2xx-pxadma.o | ||
| 52 | obj-$(CONFIG_SPI_PXA2XX) += spi-pxa2xx-platform.o | ||
| 51 | obj-$(CONFIG_SPI_PXA2XX_PCI) += spi-pxa2xx-pci.o | 53 | obj-$(CONFIG_SPI_PXA2XX_PCI) += spi-pxa2xx-pci.o |
| 52 | obj-$(CONFIG_SPI_RSPI) += spi-rspi.o | 54 | obj-$(CONFIG_SPI_RSPI) += spi-rspi.o |
| 53 | obj-$(CONFIG_SPI_S3C24XX) += spi-s3c24xx-hw.o | 55 | obj-$(CONFIG_SPI_S3C24XX) += spi-s3c24xx-hw.o |
diff --git a/drivers/spi/spi-pxa2xx-pxadma.c b/drivers/spi/spi-pxa2xx-pxadma.c new file mode 100644 index 000000000000..2916efc7cfe5 --- /dev/null +++ b/drivers/spi/spi-pxa2xx-pxadma.c | |||
| @@ -0,0 +1,490 @@ | |||
| 1 | /* | ||
| 2 | * PXA2xx SPI private DMA support. | ||
| 3 | * | ||
| 4 | * Copyright (C) 2005 Stephen Street / StreetFire Sound Labs | ||
| 5 | * | ||
| 6 | * This program is free software; you can redistribute it and/or modify | ||
| 7 | * it under the terms of the GNU General Public License as published by | ||
| 8 | * the Free Software Foundation; either version 2 of the License, or | ||
| 9 | * (at your option) any later version. | ||
| 10 | * | ||
| 11 | * This program is distributed in the hope that it will be useful, | ||
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | * GNU General Public License for more details. | ||
| 15 | * | ||
| 16 | * You should have received a copy of the GNU General Public License | ||
| 17 | * along with this program; if not, write to the Free Software | ||
| 18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
| 19 | */ | ||
| 20 | |||
| 21 | #include <linux/init.h> | ||
| 22 | #include <linux/delay.h> | ||
| 23 | #include <linux/device.h> | ||
| 24 | #include <linux/dma-mapping.h> | ||
| 25 | #include <linux/pxa2xx_ssp.h> | ||
| 26 | #include <linux/spi/spi.h> | ||
| 27 | #include <linux/spi/pxa2xx_spi.h> | ||
| 28 | |||
| 29 | #include "spi-pxa2xx.h" | ||
| 30 | |||
| 31 | #define DMA_INT_MASK (DCSR_ENDINTR | DCSR_STARTINTR | DCSR_BUSERR) | ||
| 32 | #define RESET_DMA_CHANNEL (DCSR_NODESC | DMA_INT_MASK) | ||
| 33 | |||
| 34 | bool pxa2xx_spi_dma_is_possible(size_t len) | ||
| 35 | { | ||
| 36 | /* Try to map dma buffer and do a dma transfer if successful, but | ||
| 37 | * only if the length is non-zero and less than MAX_DMA_LEN. | ||
| 38 | * | ||
| 39 | * Zero-length non-descriptor DMA is illegal on PXA2xx; force use | ||
| 40 | * of PIO instead. Care is needed above because the transfer may | ||
| 41 | * have have been passed with buffers that are already dma mapped. | ||
| 42 | * A zero-length transfer in PIO mode will not try to write/read | ||
| 43 | * to/from the buffers | ||
| 44 | * | ||
| 45 | * REVISIT large transfers are exactly where we most want to be | ||
| 46 | * using DMA. If this happens much, split those transfers into | ||
| 47 | * multiple DMA segments rather than forcing PIO. | ||
| 48 | */ | ||
| 49 | return len > 0 && len <= MAX_DMA_LEN; | ||
| 50 | } | ||
| 51 | |||
| 52 | int pxa2xx_spi_map_dma_buffers(struct driver_data *drv_data) | ||
| 53 | { | ||
| 54 | struct spi_message *msg = drv_data->cur_msg; | ||
| 55 | struct device *dev = &msg->spi->dev; | ||
| 56 | |||
| 57 | if (!drv_data->cur_chip->enable_dma) | ||
| 58 | return 0; | ||
| 59 | |||
| 60 | if (msg->is_dma_mapped) | ||
| 61 | return drv_data->rx_dma && drv_data->tx_dma; | ||
| 62 | |||
| 63 | if (!IS_DMA_ALIGNED(drv_data->rx) || !IS_DMA_ALIGNED(drv_data->tx)) | ||
| 64 | return 0; | ||
| 65 | |||
| 66 | /* Modify setup if rx buffer is null */ | ||
| 67 | if (drv_data->rx == NULL) { | ||
| 68 | *drv_data->null_dma_buf = 0; | ||
| 69 | drv_data->rx = drv_data->null_dma_buf; | ||
| 70 | drv_data->rx_map_len = 4; | ||
| 71 | } else | ||
| 72 | drv_data->rx_map_len = drv_data->len; | ||
| 73 | |||
| 74 | |||
| 75 | /* Modify setup if tx buffer is null */ | ||
| 76 | if (drv_data->tx == NULL) { | ||
| 77 | *drv_data->null_dma_buf = 0; | ||
| 78 | drv_data->tx = drv_data->null_dma_buf; | ||
| 79 | drv_data->tx_map_len = 4; | ||
| 80 | } else | ||
| 81 | drv_data->tx_map_len = drv_data->len; | ||
| 82 | |||
| 83 | /* Stream map the tx buffer. Always do DMA_TO_DEVICE first | ||
| 84 | * so we flush the cache *before* invalidating it, in case | ||
| 85 | * the tx and rx buffers overlap. | ||
| 86 | */ | ||
| 87 | drv_data->tx_dma = dma_map_single(dev, drv_data->tx, | ||
| 88 | drv_data->tx_map_len, DMA_TO_DEVICE); | ||
| 89 | if (dma_mapping_error(dev, drv_data->tx_dma)) | ||
| 90 | return 0; | ||
| 91 | |||
| 92 | /* Stream map the rx buffer */ | ||
| 93 | drv_data->rx_dma = dma_map_single(dev, drv_data->rx, | ||
| 94 | drv_data->rx_map_len, DMA_FROM_DEVICE); | ||
| 95 | if (dma_mapping_error(dev, drv_data->rx_dma)) { | ||
| 96 | dma_unmap_single(dev, drv_data->tx_dma, | ||
| 97 | drv_data->tx_map_len, DMA_TO_DEVICE); | ||
| 98 | return 0; | ||
| 99 | } | ||
| 100 | |||
| 101 | return 1; | ||
| 102 | } | ||
| 103 | |||
| 104 | static void pxa2xx_spi_unmap_dma_buffers(struct driver_data *drv_data) | ||
| 105 | { | ||
| 106 | struct device *dev; | ||
| 107 | |||
| 108 | if (!drv_data->dma_mapped) | ||
| 109 | return; | ||
| 110 | |||
| 111 | if (!drv_data->cur_msg->is_dma_mapped) { | ||
| 112 | dev = &drv_data->cur_msg->spi->dev; | ||
| 113 | dma_unmap_single(dev, drv_data->rx_dma, | ||
| 114 | drv_data->rx_map_len, DMA_FROM_DEVICE); | ||
| 115 | dma_unmap_single(dev, drv_data->tx_dma, | ||
| 116 | drv_data->tx_map_len, DMA_TO_DEVICE); | ||
| 117 | } | ||
| 118 | |||
| 119 | drv_data->dma_mapped = 0; | ||
| 120 | } | ||
| 121 | |||
| 122 | static int wait_ssp_rx_stall(void const __iomem *ioaddr) | ||
| 123 | { | ||
| 124 | unsigned long limit = loops_per_jiffy << 1; | ||
| 125 | |||
| 126 | while ((read_SSSR(ioaddr) & SSSR_BSY) && --limit) | ||
| 127 | cpu_relax(); | ||
| 128 | |||
| 129 | return limit; | ||
| 130 | } | ||
| 131 | |||
| 132 | static int wait_dma_channel_stop(int channel) | ||
| 133 | { | ||
| 134 | unsigned long limit = loops_per_jiffy << 1; | ||
| 135 | |||
| 136 | while (!(DCSR(channel) & DCSR_STOPSTATE) && --limit) | ||
| 137 | cpu_relax(); | ||
| 138 | |||
| 139 | return limit; | ||
| 140 | } | ||
| 141 | |||
| 142 | static void pxa2xx_spi_dma_error_stop(struct driver_data *drv_data, | ||
| 143 | const char *msg) | ||
| 144 | { | ||
| 145 | void __iomem *reg = drv_data->ioaddr; | ||
| 146 | |||
| 147 | /* Stop and reset */ | ||
| 148 | DCSR(drv_data->rx_channel) = RESET_DMA_CHANNEL; | ||
| 149 | DCSR(drv_data->tx_channel) = RESET_DMA_CHANNEL; | ||
| 150 | write_SSSR_CS(dr | ||
