Fixes two DMA bugs in the pxa2xx_spi driver. The first bug is in allversions of this driver; the second was introduced in the 2.6.20 kernel,and prevents using the driver with chips like m25p16 flash (which canissue large DMA reads).

1. Zero length transfers are permitted for use to insert timing, but pxa2xx_spi.c will fail if this is requested in DMA mode. Fixed by using programmed I/O (PIO) mode for such transfers.

2. Transfers larger than 8191 are not permitted in DMA mode. A test for length rejects all large transfers regardless of DMA or PIO mode. Worked around by rejecting only large transfers with DMA mapped buffers, and forcing all other transfers larger than 8191 to use PIO mode. A rate limited warning is issued for DMA transfers forced to PIO mode.

This patch should apply to all kernels back to and including 2.6.20;it was test patched against 2.6.20. An additional patch would berequired for older kernels, but those versions are very buggy anyway.

- /* Try to map dma buffer and do a dma transfer if successful */- if ((drv_data->dma_mapped = map_dma_buffers(drv_data))) {+ /* Try to map dma buffer and do a dma transfer if successful, but+ * only if the length is non-zero and less than MAX_DMA_LEN.+ *+ * Zero-length non-descriptor DMA is illegal on PXA2xx; force use+ * of PIO instead. Care is needed above because the transfer may+ * have have been passed with buffers that are already dma mapped.+ * A zero-length transfer in PIO mode will not try to write/read+ * to/from the buffers+ *+ * REVISIT large transfers are exactly where we most want to be+ * using DMA. If this happens much, split those transfers into+ * multiple DMA segments rather than forcing PIO.+ */+ drv_data->dma_mapped = 0;+ if (drv_data->len > 0 && drv_data->len <= MAX_DMA_LEN)+ drv_data->dma_mapped = map_dma_buffers(drv_data);+ if (drv_data->dma_mapped) {