aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/devicetree/bindings/spi/fsl-imx-cspi.txt1
-rw-r--r--drivers/spi/spi-imx.c218
-rw-r--r--drivers/spi/spi-loopback-test.c34
-rw-r--r--drivers/spi/spi-omap2-mcspi.c4
-rw-r--r--drivers/spi/spi-pic32.c4
-rw-r--r--drivers/spi/spi-pl022.c2
6 files changed, 228 insertions, 35 deletions
diff --git a/Documentation/devicetree/bindings/spi/fsl-imx-cspi.txt b/Documentation/devicetree/bindings/spi/fsl-imx-cspi.txt
index 31b5b21598ff..5bf13960f7f4 100644
--- a/Documentation/devicetree/bindings/spi/fsl-imx-cspi.txt
+++ b/Documentation/devicetree/bindings/spi/fsl-imx-cspi.txt
@@ -9,6 +9,7 @@ Required properties:
9 - "fsl,imx31-cspi" for SPI compatible with the one integrated on i.MX31 9 - "fsl,imx31-cspi" for SPI compatible with the one integrated on i.MX31
10 - "fsl,imx35-cspi" for SPI compatible with the one integrated on i.MX35 10 - "fsl,imx35-cspi" for SPI compatible with the one integrated on i.MX35
11 - "fsl,imx51-ecspi" for SPI compatible with the one integrated on i.MX51 11 - "fsl,imx51-ecspi" for SPI compatible with the one integrated on i.MX51
12 - "fsl,imx53-ecspi" for SPI compatible with the one integrated on i.MX53 and later Soc
12- reg : Offset and length of the register set for the device 13- reg : Offset and length of the register set for the device
13- interrupts : Should contain CSPI/eCSPI interrupt 14- interrupts : Should contain CSPI/eCSPI interrupt
14- cs-gpios : Specifies the gpio pins to be used for chipselects. 15- cs-gpios : Specifies the gpio pins to be used for chipselects.
diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c
index f9698b7aeb3b..babb15f07995 100644
--- a/drivers/spi/spi-imx.c
+++ b/drivers/spi/spi-imx.c
@@ -56,6 +56,7 @@
56 56
57/* The maximum bytes that a sdma BD can transfer.*/ 57/* The maximum bytes that a sdma BD can transfer.*/
58#define MAX_SDMA_BD_BYTES (1 << 15) 58#define MAX_SDMA_BD_BYTES (1 << 15)
59#define MX51_ECSPI_CTRL_MAX_BURST 512
59 60
60enum spi_imx_devtype { 61enum spi_imx_devtype {
61 IMX1_CSPI, 62 IMX1_CSPI,
@@ -63,7 +64,8 @@ enum spi_imx_devtype {
63 IMX27_CSPI, 64 IMX27_CSPI,
64 IMX31_CSPI, 65 IMX31_CSPI,
65 IMX35_CSPI, /* CSPI on all i.mx except above */ 66 IMX35_CSPI, /* CSPI on all i.mx except above */
66 IMX51_ECSPI, /* ECSPI on i.mx51 and later */ 67 IMX51_ECSPI, /* ECSPI on i.mx51 */
68 IMX53_ECSPI, /* ECSPI on i.mx53 and later */
67}; 69};
68 70
69struct spi_imx_data; 71struct spi_imx_data;
@@ -74,6 +76,9 @@ struct spi_imx_devtype_data {
74 void (*trigger)(struct spi_imx_data *); 76 void (*trigger)(struct spi_imx_data *);
75 int (*rx_available)(struct spi_imx_data *); 77 int (*rx_available)(struct spi_imx_data *);
76 void (*reset)(struct spi_imx_data *); 78 void (*reset)(struct spi_imx_data *);
79 bool has_dmamode;
80 unsigned int fifo_size;
81 bool dynamic_burst;
77 enum spi_imx_devtype devtype; 82 enum spi_imx_devtype devtype;
78}; 83};
79 84
@@ -94,12 +99,14 @@ struct spi_imx_data {
94 unsigned int bits_per_word; 99 unsigned int bits_per_word;
95 unsigned int spi_drctl; 100 unsigned int spi_drctl;
96 101
97 unsigned int count; 102 unsigned int count, remainder;
98 void (*tx)(struct spi_imx_data *); 103 void (*tx)(struct spi_imx_data *);
99 void (*rx)(struct spi_imx_data *); 104 void (*rx)(struct spi_imx_data *);
100 void *rx_buf; 105 void *rx_buf;
101 const void *tx_buf; 106 const void *tx_buf;
102 unsigned int txfifo; /* number of words pushed in tx FIFO */ 107 unsigned int txfifo; /* number of words pushed in tx FIFO */
108 unsigned int dynamic_burst, read_u32;
109 unsigned int word_mask;
103 110
104 /* DMA */ 111 /* DMA */
105 bool usedma; 112 bool usedma;
@@ -125,9 +132,9 @@ static inline int is_imx51_ecspi(struct spi_imx_data *d)
125 return d->devtype_data->devtype == IMX51_ECSPI; 132 return d->devtype_data->devtype == IMX51_ECSPI;
126} 133}
127 134
128static inline unsigned spi_imx_get_fifosize(struct spi_imx_data *d) 135static inline int is_imx53_ecspi(struct spi_imx_data *d)
129{ 136{
130 return is_imx51_ecspi(d) ? 64 : 8; 137 return d->devtype_data->devtype == IMX53_ECSPI;
131} 138}
132 139
133#define MXC_SPI_BUF_RX(type) \ 140#define MXC_SPI_BUF_RX(type) \
@@ -219,7 +226,7 @@ static bool spi_imx_can_dma(struct spi_master *master, struct spi_device *spi,
219 if (bytes_per_word != 1 && bytes_per_word != 2 && bytes_per_word != 4) 226 if (bytes_per_word != 1 && bytes_per_word != 2 && bytes_per_word != 4)
220 return false; 227 return false;
221 228
222 for (i = spi_imx_get_fifosize(spi_imx) / 2; i > 0; i--) { 229 for (i = spi_imx->devtype_data->fifo_size / 2; i > 0; i--) {
223 if (!(transfer->len % (i * bytes_per_word))) 230 if (!(transfer->len % (i * bytes_per_word)))
224 break; 231 break;
225 } 232 }
@@ -228,6 +235,7 @@ static bool spi_imx_can_dma(struct spi_master *master, struct spi_device *spi,
228 return false; 235 return false;
229 236
230 spi_imx->wml = i; 237 spi_imx->wml = i;
238 spi_imx->dynamic_burst = 0;
231 239
232 return true; 240 return true;
233} 241}
@@ -242,6 +250,7 @@ static bool spi_imx_can_dma(struct spi_master *master, struct spi_device *spi,
242#define MX51_ECSPI_CTRL_PREDIV_OFFSET 12 250#define MX51_ECSPI_CTRL_PREDIV_OFFSET 12
243#define MX51_ECSPI_CTRL_CS(cs) ((cs) << 18) 251#define MX51_ECSPI_CTRL_CS(cs) ((cs) << 18)
244#define MX51_ECSPI_CTRL_BL_OFFSET 20 252#define MX51_ECSPI_CTRL_BL_OFFSET 20
253#define MX51_ECSPI_CTRL_BL_MASK (0xfff << 20)
245 254
246#define MX51_ECSPI_CONFIG 0x0c 255#define MX51_ECSPI_CONFIG 0x0c
247#define MX51_ECSPI_CONFIG_SCLKPHA(cs) (1 << ((cs) + 0)) 256#define MX51_ECSPI_CONFIG_SCLKPHA(cs) (1 << ((cs) + 0))
@@ -269,6 +278,106 @@ static bool spi_imx_can_dma(struct spi_master *master, struct spi_device *spi,
269#define MX51_ECSPI_TESTREG 0x20 278#define MX51_ECSPI_TESTREG 0x20
270#define MX51_ECSPI_TESTREG_LBC BIT(31) 279#define MX51_ECSPI_TESTREG_LBC BIT(31)
271 280
281static void spi_imx_buf_rx_swap_u32(struct spi_imx_data *spi_imx)
282{
283 unsigned int val = readl(spi_imx->base + MXC_CSPIRXDATA);
284#ifdef __LITTLE_ENDIAN
285 unsigned int bytes_per_word;
286#endif
287
288 if (spi_imx->rx_buf) {
289#ifdef __LITTLE_ENDIAN
290 bytes_per_word = spi_imx_bytes_per_word(spi_imx->bits_per_word);
291 if (bytes_per_word == 1)
292 val = cpu_to_be32(val);
293 else if (bytes_per_word == 2)
294 val = (val << 16) | (val >> 16);
295#endif
296 val &= spi_imx->word_mask;
297 *(u32 *)spi_imx->rx_buf = val;
298 spi_imx->rx_buf += sizeof(u32);
299 }
300}
301
302static void spi_imx_buf_rx_swap(struct spi_imx_data *spi_imx)
303{
304 unsigned int bytes_per_word;
305
306 bytes_per_word = spi_imx_bytes_per_word(spi_imx->bits_per_word);
307 if (spi_imx->read_u32) {
308 spi_imx_buf_rx_swap_u32(spi_imx);
309 return;
310 }
311
312 if (bytes_per_word == 1)
313 spi_imx_buf_rx_u8(spi_imx);
314 else if (bytes_per_word == 2)
315 spi_imx_buf_rx_u16(spi_imx);
316}
317
318static void spi_imx_buf_tx_swap_u32(struct spi_imx_data *spi_imx)
319{
320 u32 val = 0;
321#ifdef __LITTLE_ENDIAN
322 unsigned int bytes_per_word;
323#endif
324
325 if (spi_imx->tx_buf) {
326 val = *(u32 *)spi_imx->tx_buf;
327 val &= spi_imx->word_mask;
328 spi_imx->tx_buf += sizeof(u32);
329 }
330
331 spi_imx->count -= sizeof(u32);
332#ifdef __LITTLE_ENDIAN
333 bytes_per_word = spi_imx_bytes_per_word(spi_imx->bits_per_word);
334
335 if (bytes_per_word == 1)
336 val = cpu_to_be32(val);
337 else if (bytes_per_word == 2)
338 val = (val << 16) | (val >> 16);
339#endif
340 writel(val, spi_imx->base + MXC_CSPITXDATA);
341}
342
343static void spi_imx_buf_tx_swap(struct spi_imx_data *spi_imx)
344{
345 u32 ctrl, val;
346 unsigned int bytes_per_word;
347
348 if (spi_imx->count == spi_imx->remainder) {
349 ctrl = readl(spi_imx->base + MX51_ECSPI_CTRL);
350 ctrl &= ~MX51_ECSPI_CTRL_BL_MASK;
351 if (spi_imx->count > MX51_ECSPI_CTRL_MAX_BURST) {
352 spi_imx->remainder = spi_imx->count %
353 MX51_ECSPI_CTRL_MAX_BURST;
354 val = MX51_ECSPI_CTRL_MAX_BURST * 8 - 1;
355 } else if (spi_imx->count >= sizeof(u32)) {
356 spi_imx->remainder = spi_imx->count % sizeof(u32);
357 val = (spi_imx->count - spi_imx->remainder) * 8 - 1;
358 } else {
359 spi_imx->remainder = 0;
360 val = spi_imx->bits_per_word - 1;
361 spi_imx->read_u32 = 0;
362 }
363
364