diff options
-rw-r--r-- | Documentation/devicetree/bindings/spi/fsl-spi.txt | 1 | ||||
-rw-r--r-- | drivers/spi/Kconfig | 7 | ||||
-rw-r--r-- | drivers/spi/Makefile | 1 | ||||
-rw-r--r-- | drivers/spi/spi-fsl-cpm.c | 387 | ||||
-rw-r--r-- | drivers/spi/spi-fsl-cpm.h | 43 | ||||
-rw-r--r-- | drivers/spi/spi-fsl-lib.c | 8 | ||||
-rw-r--r-- | drivers/spi/spi-fsl-lib.h | 6 | ||||
-rw-r--r-- | drivers/spi/spi-fsl-spi.c | 411 | ||||
-rw-r--r-- | drivers/spi/spi-fsl-spi.h | 61 |
9 files changed, 520 insertions, 405 deletions
diff --git a/Documentation/devicetree/bindings/spi/fsl-spi.txt b/Documentation/devicetree/bindings/spi/fsl-spi.txt index 777abd7399d5..4f2ea9461797 100644 --- a/Documentation/devicetree/bindings/spi/fsl-spi.txt +++ b/Documentation/devicetree/bindings/spi/fsl-spi.txt | |||
@@ -14,6 +14,7 @@ Required properties: | |||
14 | controller you have. | 14 | controller you have. |
15 | - interrupt-parent : the phandle for the interrupt controller that | 15 | - interrupt-parent : the phandle for the interrupt controller that |
16 | services interrupts for this device. | 16 | services interrupts for this device. |
17 | - clock-frequency : input clock frequency to non FSL_SOC cores | ||
17 | 18 | ||
18 | Optional properties: | 19 | Optional properties: |
19 | - gpios : specifies the gpio pins to be used for chipselects. | 20 | - gpios : specifies the gpio pins to be used for chipselects. |
diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig index 32b85d43bbe2..3524bec5ae5b 100644 --- a/drivers/spi/Kconfig +++ b/drivers/spi/Kconfig | |||
@@ -229,12 +229,17 @@ config SPI_MPC512x_PSC | |||
229 | 229 | ||
230 | config SPI_FSL_LIB | 230 | config SPI_FSL_LIB |
231 | tristate | 231 | tristate |
232 | depends on OF | ||
233 | |||
234 | config SPI_FSL_CPM | ||
235 | tristate | ||
232 | depends on FSL_SOC | 236 | depends on FSL_SOC |
233 | 237 | ||
234 | config SPI_FSL_SPI | 238 | config SPI_FSL_SPI |
235 | bool "Freescale SPI controller" | 239 | bool "Freescale SPI controller" |
236 | depends on FSL_SOC | 240 | depends on OF |
237 | select SPI_FSL_LIB | 241 | select SPI_FSL_LIB |
242 | select SPI_FSL_CPM if FSL_SOC | ||
238 | help | 243 | help |
239 | This enables using the Freescale SPI controllers in master mode. | 244 | This enables using the Freescale SPI controllers in master mode. |
240 | MPC83xx platform uses the controller in cpu mode or CPM/QE mode. | 245 | MPC83xx platform uses the controller in cpu mode or CPM/QE mode. |
diff --git a/drivers/spi/Makefile b/drivers/spi/Makefile index 3ce1d082ce79..604460dddbb6 100644 --- a/drivers/spi/Makefile +++ b/drivers/spi/Makefile | |||
@@ -29,6 +29,7 @@ obj-$(CONFIG_SPI_DW_PCI) += spi-dw-midpci.o | |||
29 | spi-dw-midpci-objs := spi-dw-pci.o spi-dw-mid.o | 29 | spi-dw-midpci-objs := spi-dw-pci.o spi-dw-mid.o |
30 | obj-$(CONFIG_SPI_EP93XX) += spi-ep93xx.o | 30 | obj-$(CONFIG_SPI_EP93XX) += spi-ep93xx.o |
31 | obj-$(CONFIG_SPI_FALCON) += spi-falcon.o | 31 | obj-$(CONFIG_SPI_FALCON) += spi-falcon.o |
32 | obj-$(CONFIG_SPI_FSL_CPM) += spi-fsl-cpm.o | ||
32 | obj-$(CONFIG_SPI_FSL_LIB) += spi-fsl-lib.o | 33 | obj-$(CONFIG_SPI_FSL_LIB) += spi-fsl-lib.o |
33 | obj-$(CONFIG_SPI_FSL_ESPI) += spi-fsl-espi.o | 34 | obj-$(CONFIG_SPI_FSL_ESPI) += spi-fsl-espi.o |
34 | obj-$(CONFIG_SPI_FSL_SPI) += spi-fsl-spi.o | 35 | obj-$(CONFIG_SPI_FSL_SPI) += spi-fsl-spi.o |
diff --git a/drivers/spi/spi-fsl-cpm.c b/drivers/spi/spi-fsl-cpm.c new file mode 100644 index 000000000000..07971e3fe58b --- /dev/null +++ b/drivers/spi/spi-fsl-cpm.c | |||
@@ -0,0 +1,387 @@ | |||
1 | /* | ||
2 | * Freescale SPI controller driver cpm functions. | ||
3 | * | ||
4 | * Maintainer: Kumar Gala | ||
5 | * | ||
6 | * Copyright (C) 2006 Polycom, Inc. | ||
7 | * Copyright 2010 Freescale Semiconductor, Inc. | ||
8 | * | ||
9 | * CPM SPI and QE buffer descriptors mode support: | ||
10 | * Copyright (c) 2009 MontaVista Software, Inc. | ||
11 | * Author: Anton Vorontsov <avorontsov@ru.mvista.com> | ||
12 | * | ||
13 | * This program is free software; you can redistribute it and/or modify it | ||
14 | * under the terms of the GNU General Public License as published by the | ||
15 | * Free Software Foundation; either version 2 of the License, or (at your | ||
16 | * option) any later version. | ||
17 | */ | ||
18 | #include <linux/types.h> | ||
19 | #include <linux/kernel.h> | ||
20 | #include <linux/spi/spi.h> | ||
21 | #include <linux/fsl_devices.h> | ||
22 | #include <linux/dma-mapping.h> | ||
23 | #include <asm/cpm.h> | ||
24 | #include <asm/qe.h> | ||
25 | |||
26 | #include "spi-fsl-lib.h" | ||
27 | #include "spi-fsl-cpm.h" | ||
28 | #include "spi-fsl-spi.h" | ||
29 | |||
30 | /* CPM1 and CPM2 are mutually exclusive. */ | ||
31 | #ifdef CONFIG_CPM1 | ||
32 | #include <asm/cpm1.h> | ||
33 | #define CPM_SPI_CMD mk_cr_cmd(CPM_CR_CH_SPI, 0) | ||
34 | #else | ||
35 | #include <asm/cpm2.h> | ||
36 | #define CPM_SPI_CMD mk_cr_cmd(CPM_CR_SPI_PAGE, CPM_CR_SPI_SBLOCK, 0, 0) | ||
37 | #endif | ||
38 | |||
39 | #define SPIE_TXB 0x00000200 /* Last char is written to tx fifo */ | ||
40 | #define SPIE_RXB 0x00000100 /* Last char is written to rx buf */ | ||
41 | |||
42 | /* SPCOM register values */ | ||
43 | #define SPCOM_STR (1 << 23) /* Start transmit */ | ||
44 | |||
45 | #define SPI_PRAM_SIZE 0x100 | ||
46 | #define SPI_MRBLR ((unsigned int)PAGE_SIZE) | ||
47 | |||
48 | static void *fsl_dummy_rx; | ||
49 | static DEFINE_MUTEX(fsl_dummy_rx_lock); | ||
50 | static int fsl_dummy_rx_refcnt; | ||
51 | |||
52 | void fsl_spi_cpm_reinit_txrx(struct mpc8xxx_spi *mspi) | ||
53 | { | ||
54 | if (mspi->flags & SPI_QE) { | ||
55 | qe_issue_cmd(QE_INIT_TX_RX, mspi->subblock, | ||
56 | QE_CR_PROTOCOL_UNSPECIFIED, 0); | ||
57 | } else { | ||
58 | cpm_command(CPM_SPI_CMD, CPM_CR_INIT_TRX); | ||
59 | if (mspi->flags & SPI_CPM1) { | ||
60 | out_be16(&mspi->pram->rbptr, | ||
61 | in_be16(&mspi->pram->rbase)); | ||
62 | out_be16(&mspi->pram->tbptr, | ||
63 | in_be16(&mspi->pram->tbase)); | ||
64 | } | ||
65 | } | ||
66 | } | ||
67 | |||
68 | static void fsl_spi_cpm_bufs_start(struct mpc8xxx_spi *mspi) | ||
69 | { | ||
70 | struct cpm_buf_desc __iomem *tx_bd = mspi->tx_bd; | ||
71 | struct cpm_buf_desc __iomem *rx_bd = mspi->rx_bd; | ||
72 | unsigned int xfer_len = min(mspi->count, SPI_MRBLR); | ||
73 | unsigned int xfer_ofs; | ||
74 | struct fsl_spi_reg *reg_base = mspi->reg_base; | ||
75 | |||
76 | xfer_ofs = mspi->xfer_in_progress->len - mspi->count; | ||
77 | |||
78 | if (mspi->rx_dma == mspi->dma_dummy_rx) | ||
79 | out_be32(&rx_bd->cbd_bufaddr, mspi->rx_dma); | ||
80 | else | ||
81 | out_be32(&rx_bd->cbd_bufaddr, mspi->rx_dma + xfer_ofs); | ||
82 | out_be16(&rx_bd->cbd_datlen, 0); | ||
83 | out_be16(&rx_bd->cbd_sc, BD_SC_EMPTY | BD_SC_INTRPT | BD_SC_WRAP); | ||
84 | |||
85 | if (mspi->tx_dma == mspi->dma_dummy_tx) | ||
86 | out_be32(&tx_bd->cbd_bufaddr, mspi->tx_dma); | ||
87 | else | ||
88 | out_be32(&tx_bd->cbd_bufaddr, mspi->tx_dma + xfer_ofs); | ||
89 | out_be16(&tx_bd->cbd_datlen, xfer_len); | ||
90 | out_be16(&tx_bd->cbd_sc, BD_SC_READY | BD_SC_INTRPT | BD_SC_WRAP | | ||
91 | BD_SC_LAST); | ||
92 | |||
93 | /* start transfer */ | ||
94 | mpc8xxx_spi_write_reg(®_base->command, SPCOM_STR); | ||
95 | } | ||
96 | |||
97 | int fsl_spi_cpm_bufs(struct mpc8xxx_spi *mspi, | ||
98 | struct spi_transfer *t, bool is_dma_mapped) | ||
99 | { | ||
100 | struct device *dev = mspi->dev; | ||
101 | struct fsl_spi_reg *reg_base = mspi->reg_base; | ||
102 | |||
103 | if (is_dma_mapped) { | ||
104 | mspi->map_tx_dma = 0; | ||
105 | mspi->map_rx_dma = 0; | ||
106 | } else { | ||
107 | mspi->map_tx_dma = 1; | ||
108 | mspi->map_rx_dma = 1; | ||
109 | } | ||
110 | |||
111 | if (!t->tx_buf) { | ||
112 | mspi->tx_dma = mspi->dma_dummy_tx; | ||
113 | mspi->map_tx_dma = 0; | ||
114 | } | ||
115 | |||
116 | if (!t->rx_buf) { | ||
117 | mspi->rx_dma = mspi->dma_dummy_rx; | ||
118 | mspi->map_rx_dma = 0; | ||
119 | } | ||
120 | |||
121 | if (mspi->map_tx_dma) { | ||
122 | void *nonconst_tx = (void *)mspi->tx; /* shut up gcc */ | ||
123 | |||
124 | mspi->tx_dma = dma_map_single(dev, nonconst_tx, t->len, | ||
125 | DMA_TO_DEVICE); | ||
126 | if (dma_mapping_error(dev, mspi->tx_dma)) { | ||
127 | dev_err(dev, "unable to map tx dma\n"); | ||
128 | return -ENOMEM; | ||
129 | } | ||
130 | } else if (t->tx_buf) { | ||
131 | mspi->tx_dma = t->tx_dma; | ||
132 | } | ||
133 | |||
134 | if (mspi->map_rx_dma) { | ||
135 | mspi->rx_dma = dma_map_single(dev, mspi->rx, t->len, | ||
136 | DMA_FROM_DEVICE); | ||
137 | if (dma_mapping_error(dev, mspi->rx_dma)) { | ||
138 | dev_err(dev, "unable to map rx dma\n"); | ||
139 | goto err_rx_dma; | ||
140 | } | ||
141 | } else if (t->rx_buf) { | ||
142 | mspi->rx_dma = t->rx_dma; | ||
143 | } | ||
144 | |||
145 | /* enable rx ints */ | ||
146 | mpc8xxx_spi_write_reg(®_base->mask, SPIE_RXB); | ||
147 | |||
148 | mspi->xfer_in_progress = t; | ||
149 | mspi->count = t->len; | ||
150 | |||
151 | /* start CPM transfers */ | ||
152 | fsl_spi_cpm_bufs_start(mspi); | ||
153 | |||
154 | return 0; | ||
155 | |||
156 | err_rx_dma: | ||
157 | if (mspi->map_tx_dma) | ||
158 | dma_unmap_single(dev, mspi->tx_dma, t->len, DMA_TO_DEVICE); | ||
159 | return -ENOMEM; | ||
160 | } | ||
161 | |||
162 | void fsl_spi_cpm_bufs_complete(struct mpc8xxx_spi *mspi) | ||
163 | { | ||
164 | struct device *dev = mspi->dev; | ||
165 | struct spi_transfer *t = mspi->xfer_in_progress; | ||
166 | |||
167 | if (mspi->map_tx_dma) | ||
168 | dma_unmap_single(dev, mspi->tx_dma, t->len, DMA_TO_DEVICE); | ||
169 | if (mspi->map_rx_dma) | ||
170 | dma_unmap_single(dev, mspi->rx_dma, t->len, DMA_FROM_DEVICE); | ||
171 | mspi->xfer_in_progress = NULL; | ||
172 | } | ||
173 | |||
174 | void fsl_spi_cpm_irq(struct mpc8xxx_spi *mspi, u32 events) | ||
175 | { | ||
176 | u16 len; | ||
177 | struct fsl_spi_reg *reg_base = mspi->reg_base; | ||
178 | |||
179 | dev_dbg(mspi->dev, "%s: bd datlen %d, count %d\n", __func__, | ||
180 | in_be16(&mspi->rx_bd->cbd_datlen), mspi->count); | ||
181 | |||
182 | len = in_be16(&mspi->rx_bd->cbd_datlen); | ||
183 | if (len > mspi->count) { | ||
184 | WARN_ON(1); | ||
185 | len = mspi->count; | ||
186 | } | ||
187 | |||
188 | /* Clear the events */ | ||
189 | mpc8xxx_spi_write_reg(®_base->event, events); | ||
190 | |||
191 | mspi->count -= len; | ||
192 | if (mspi->count) | ||
193 | fsl_spi_cpm_bufs_start(mspi); | ||
194 | else | ||
195 | complete(&mspi->done); | ||
196 | } | ||
197 | |||
198 | static void *fsl_spi_alloc_dummy_rx(void) | ||
199 | { | ||
200 | mutex_lock(&fsl_dummy_rx_lock); | ||
201 | |||
202 | if (!fsl_dummy_rx) | ||
203 | fsl_dummy_rx = kmalloc(SPI_MRBLR, GFP_KERNEL); | ||
204 | if (fsl_dummy_rx) | ||
205 | fsl_dummy_rx_refcnt++; | ||
206 | |||
207 | mutex_unlock(&fsl_dummy_rx_lock); | ||
208 | |||
209 | return fsl_dummy_rx; | ||
210 | } | ||
211 | |||
212 | static void fsl_spi_free_dummy_rx(void) | ||
213 | { | ||
214 | mutex_lock(&fsl_dummy_rx_lock); | ||
215 | |||
216 | switch (fsl_dummy_rx_refcnt) { | ||
217 | case 0: | ||
218 | WARN_ON(1); | ||
219 | break; | ||
220 | case 1: | ||
221 | kfree(fsl_dummy_rx); | ||
222 | fsl_dummy_rx = NULL; | ||
223 | /* fall through */ | ||
224 | default: | ||
225 | fsl_dummy_rx_refcnt--; | ||
226 | break; | ||
227 | } | ||
228 | |||
229 | mutex_unlock(&fsl_dummy_rx_lock); | ||
230 | } | ||
231 | |||
232 | static unsigned long fsl_spi_cpm_get_pram(struct mpc8xxx_spi *mspi) | ||
233 | { | ||
234 | struct device *dev = mspi->dev; | ||
235 | struct device_node *np = dev->of_node; | ||
236 | const u32 *iprop; | ||
237 | int size; | ||
238 | void __iomem *spi_base; | ||
239 | unsigned long pram_ofs = -ENOMEM; | ||
240 | |||
241 | /* Can't use of_address_to_resource(), QE muram isn't at 0. */ | ||
242 | iprop = of_get_property(np, "reg", &size); | ||
243 | |||
244 | /* QE with a fixed pram location? */ | ||
245 | if (mspi->flags & SPI_QE && iprop && size == sizeof(*iprop) * 4) | ||
246 | return cpm_muram_alloc_fixed(iprop[2], SPI_PRAM_SIZE); | ||
247 | |||
248 | /* QE but with a dynamic pram location? */ | ||
249 | if (mspi->flags & SPI_QE) { | ||
250 | pram_ofs = cpm_muram_alloc(SPI_PRAM_SIZE, 64); | ||
251 | qe_issue_cmd(QE_ASSIGN_PAGE_TO_DEVICE, mspi->subblock, | ||
252 | QE_CR_PROTOCOL_UNSPECIFIED, pram_ofs); | ||
253 | return pram_ofs; | ||
254 | } | ||
255 | |||
256 | spi_base = of_iomap(np, 1); | ||
257 | if (spi_base == NULL) | ||
258 | return -EINVAL; | ||
259 | |||
260 | if (mspi->flags & SPI_CPM2) { | ||
261 | pram_ofs = cpm_muram_alloc(SPI_PRAM_SIZE, 64); | ||
262 | out_be16(spi_base, pram_ofs); | ||
263 | } else { | ||
264 | struct spi_pram __iomem *pram = spi_base; | ||
265 | u16 rpbase = in_be16(&pram->rpbase); | ||
266 | |||
267 | /* Microcode relocation patch applied? */ | ||
268 | if (rpbase) { | ||
269 | pram_ofs = rpbase; | ||
270 | } else { | ||
271 | pram_ofs = cpm_muram_alloc(SPI_PRAM_SIZE, 64); | ||
272 | out_be16(spi_base, pram_ofs); | ||
273 | } | ||
274 | } | ||
275 | |||
276 | iounmap(spi_base); | ||
277 | return pram_ofs; | ||
278 | } | ||
279 | |||
280 | int fsl_spi_cpm_init(struct mpc8xxx_spi *mspi) | ||
281 | { | ||
282 | struct device *dev = mspi->dev; | ||
283 | struct device_node *np = dev->of_node; | ||
284 | const u32 *iprop; | ||
285 | int size; | ||
286 | unsigned long pram_ofs; | ||
287 | unsigned long bds_ofs; | ||
288 | |||
289 | if (!(mspi->flags & SPI_CPM_MODE)) | ||
290 | return 0; | ||
291 | |||
292 | if (!fsl_spi_alloc_dummy_rx()) | ||
293 | return -ENOMEM; | ||
294 | |||
295 | if (mspi->flags & SPI_QE) { | ||
296 | iprop = of_get_property(np, "cell-index", &size); | ||
297 | if (iprop && size == sizeof(*iprop)) | ||
298 | mspi->subblock = *iprop; | ||
299 | |||
300 | switch (mspi->subblock) { | ||
301 | default: | ||
302 | dev_warn(dev, "cell-index unspecified, assuming SPI1"); | ||
303 | /* fall through */ | ||
304 | case 0: | ||
305 | mspi->subblock = QE_CR_SUBBLOCK_SPI1; | ||
306 | break; | ||
307 | case 1: | ||
308 | mspi->subblock = QE_CR_SUBBLOCK_SPI2; | ||
309 | break; | ||
310 | } | ||
311 | } | ||
312 | |||
313 | pram_ofs = fsl_spi_cpm_get_pram(mspi); | ||
314 | if (IS_ERR_VALUE(pram_ofs)) { | ||
315 | dev_err(dev, "can't allocate spi parameter ram\n"); | ||
316 | goto err_pram; | ||
317 | } | ||
318 | |||
319 | bds_ofs = cpm_muram_alloc(sizeof(*mspi->tx_bd) + | ||
320 | sizeof(*mspi->rx_bd), 8); | ||
321 | if (IS_ERR_VALUE(bds_ofs)) { | ||
322 | dev_err(dev, "can't allocate bds\n"); | ||
323 | goto err_bds; | ||
324 | } | ||
325 | |||
326 | mspi->dma_dummy_tx = dma_map_single(dev, empty_zero_page, PAGE_SIZE, | ||
327 | DMA_TO_DEVICE); | ||
328 | if (dma_mapping_error(dev, mspi->dma_dummy_tx)) { | ||
329 | dev_err(dev, "unable to map dummy tx buffer\n"); | ||
330 | goto err_dummy_tx; | ||
331 | } | ||
332 | |||
333 | mspi->dma_dummy_rx = dma_map_single(dev, fsl_dummy_rx, SPI_MRBLR, | ||
334 | DMA_FROM_DEVICE); | ||
335 | if (dma_mapping_error(dev, mspi->dma_dummy_rx)) { | ||
336 | dev_err(dev, "unable to map dummy rx buffer\n"); | ||
337 | goto err_dummy_rx; | ||
338 | } | ||
339 | |||
340 | mspi->pram = cpm_muram_addr(pram_ofs); | ||
341 | |||
342 | mspi->tx_bd = cpm_muram_addr(bds_ofs); | ||
343 | mspi->rx_bd = cpm_muram_addr(bds_ofs + sizeof(*mspi->tx_bd)); | ||
344 | |||
345 | /* Initialize parameter ram. */ | ||
346 | out_be16(&mspi->pram->tbase, cpm_muram_offset(mspi->tx_bd)); | ||
347 | out_be16(&mspi->pram->rbase, cpm_muram_offset(mspi->rx_bd)); | ||
348 | out_8(&mspi->pram->tfcr, CPMFCR_EB | CPMFCR_GBL); | ||
349 | out_8(&mspi->pram->rfcr, CPMFCR_EB | CPMFCR_GBL); | ||
350 | out_be16(&mspi->pram->mrblr, SPI_MRBLR); | ||
351 | out_be32(&mspi->pram->rstate, 0); | ||
352 | out_be32(&mspi->pram->rdp, 0); | ||
353 | out_be16(&mspi->pram->rbptr, 0); | ||
354 | out_be16(&mspi->pram->rbc, 0); | ||
355 | out_be32(&mspi->pram->rxtmp, 0); | ||
356 | out_be32(&mspi->pram->tstate, 0); | ||
357 | out_be32(&mspi->pram->tdp, 0); | ||
358 | out_be16(&mspi->pram->tbptr, 0); | ||
359 | out_be16(&mspi->pram->tbc, 0); | ||
360 | out_be32(&mspi->pram->txtmp, 0); | ||
361 | |||
362 | return 0; | ||
363 | |||
364 | err_dummy_rx: | ||
365 | dma_unmap_single(dev, mspi->dma_dummy_tx, PAGE_SIZE, DMA_TO_DEVICE); | ||
366 | err_dummy_tx: | ||
367 | cpm_muram_free(bds_ofs); | ||
368 | err_bds: | ||
369 | cpm_muram_free(pram_ofs); | ||
370 | err_pram: | ||
371 | fsl_spi_free_dummy_rx(); | ||
372 | return -ENOMEM; | ||
373 | } | ||
374 | |||
375 | void fsl_spi_cpm_free(struct mpc8xxx_spi *mspi) | ||
376 | { | ||
377 | struct device *dev = mspi->dev; | ||
378 | |||
379 | if (!(mspi->flags & SPI_CPM_MODE)) | ||
380 | return; | ||
381 | |||
382 | dma_unmap_single(dev, mspi->dma_dummy_rx, SPI_MRBLR, DMA_FROM_DEVICE); | ||
383 | dma_unmap_single(dev, mspi->dma_dummy_tx, PAGE_SIZE, DMA_TO_DEVICE); | ||
384 | cpm_muram_free(cpm_muram_offset(mspi->tx_bd)); | ||
385 | cpm_muram_free(cpm_muram_offset(mspi->pram)); | ||
386 | fsl_spi_free_dummy_rx(); | ||
387 | } | ||
diff --git a/drivers/spi/spi-fsl-cpm.h b/drivers/spi/spi-fsl-cpm.h new file mode 100644 index 000000000000..c71115805485 --- /dev/null +++ b/drivers/spi/spi-fsl-cpm.h | |||
@@ -0,0 +1,43 @@ | |||
1 | /* | ||
2 | * Freescale SPI controller driver cpm functions. | ||
3 | * | ||
4 | * Maintainer: Kumar Gala | ||
5 | * | ||
6 | * Copyright (C) 2006 Polycom, Inc. | ||
7 | * Copyright 2010 Freescale Semiconductor, Inc. | ||
8 | * | ||
9 | * CPM SPI and QE buffer descriptors mode support: | ||
10 | * Copyright (c) 2009 MontaVista Software, Inc. | ||
11 | * Author: Anton Vorontsov <avorontsov@ru.mvista.com> | ||
12 | * | ||
13 | * This program is free software; you can redistribute it and/or modify it | ||
14 | * under the terms of the GNU General Public License as published by the | ||
15 | * Free Software Foundation; either version 2 of the License, or (at your | ||
16 | * option) any later version. | ||
17 | */ | ||
18 | |||
19 | #ifndef __SPI_FSL_CPM_H__ | ||
20 | #define __SPI_FSL_CPM_H__ | ||
21 | |||
22 | #include "spi-fsl-lib.h" | ||
23 | |||
24 | #ifdef CONFIG_FSL_SOC | ||
25 | extern void fsl_spi_cpm_reinit_txrx(struct mpc8xxx_spi *mspi); | ||
26 | extern int fsl_spi_cpm_bufs(struct mpc8xxx_spi *mspi, | ||
27 | struct spi_transfer *t, bool is_dma_mapped); | ||
28 | extern void fsl_spi_cpm_bufs_complete(struct mpc8xxx_spi *mspi); | ||
29 | extern void fsl_spi_cpm_irq(struct mpc8xxx_spi *mspi, u32 events); | ||
30 | extern int fsl_spi_cpm_init(struct mpc8xxx_spi *mspi); | ||
31 | extern void fsl_spi_cpm_free(struct mpc8xxx_spi *mspi); | ||
32 | #else | ||
33 | static inline void fsl_spi_cpm_reinit_txrx(struct mpc8xxx_spi *mspi) { } | ||
34 | static inline int fsl_spi_cpm_bufs(struct mpc8xxx_spi *mspi, | ||
35 | struct spi_transfer *t, | ||
36 | bool is_dma_mapped) { return 0; } | ||
37 | static inline void fsl_spi_cpm_bufs_complete(struct mpc8xxx_spi *mspi) { } | ||
38 | static inline void fsl_spi_cpm_irq(struct mpc8xxx_spi *mspi, u32 events) { } | ||
39 | static inline int fsl_spi_cpm_init(struct mpc8xxx_spi *mspi) { return 0; } | ||
40 | static inline void fsl_spi_cpm_free(struct mpc8xxx_spi *mspi) { } | ||
41 | #endif | ||
42 | |||
43 | #endif /* __SPI_FSL_CPM_H__ */ | ||
diff --git a/drivers/spi/spi-fsl-lib.c b/drivers/spi/spi-fsl-lib.c index 8ade675a04f1..a91db0e57b23 100644 --- a/drivers/spi/spi-fsl-lib.c +++ b/drivers/spi/spi-fsl-lib.c | |||
@@ -23,7 +23,9 @@ | |||
23 | #include <linux/mm.h> | 23 | #include <linux/mm.h> |
24 | #include <linux/of_platform.h> | 24 | #include <linux/of_platform.h> |
25 | #include <linux/spi/spi.h> | 25 | #include <linux/spi/spi.h> |
26 | #ifdef CONFIG_FSL_SOC | ||
26 | #include <sysdev/fsl_soc.h> | 27 | #include <sysdev/fsl_soc.h> |
28 | #endif | ||
27 | 29 | ||
28 | #include "spi-fsl-lib.h" | 30 | #include "spi-fsl-lib.h" |
29 | 31 | ||
@@ -208,6 +210,7 @@ int of_mpc8xxx_spi_probe(struct platform_device *ofdev) | |||
208 | /* Allocate bus num dynamically. */ | 210 | /* Allocate bus num dynamically. */ |
209 | pdata->bus_num = -1; | 211 | pdata->bus_num = -1; |
210 | 212 | ||
213 | #ifdef CONFIG_FSL_SOC | ||
211 | /* SPI controller is either clocked from QE or SoC clock. */ | 214 | /* SPI controller is either clocked from QE or SoC clock. */ |
212 | pdata->sysclk = get_brgfreq(); | 215 | pdata->sysclk = get_brgfreq(); |
213 | if (pdata->sysclk == -1) { | 216 | if (pdata->sysclk == -1) { |
@@ -217,6 +220,11 @@ int of_mpc8xxx_spi_probe(struct platform_device *ofdev) | |||
217 | goto err; | 220 | goto err; |
218 | } | 221 | } |
219 | } | 222 | } |
223 | #else | ||
224 | ret = of_property_read_u32(np, "clock-frequency", &pdata->sysclk); | ||
225 | if (ret) | ||
226 | goto err; | ||
227 | #endif | ||
220 | 228 | ||
221 | prop = of_get_property(np, "mode", NULL); | 229 | prop = of_get_property(np, "mode", NULL); |
222 | if (prop && !strcmp(prop, "cpu-qe")) | 230 | if (prop && !strcmp(prop, "cpu-qe")) |
diff --git a/drivers/spi/spi-fsl-lib.h b/drivers/spi/spi-fsl-lib.h index cbe881b9ea76..d785595c206e 100644 --- a/drivers/spi/spi-fsl-lib.h +++ b/drivers/spi/spi-fsl-lib.h | |||
@@ -34,8 +34,10 @@ struct mpc8xxx_spi { | |||
34 | 34 | ||
35 | int subblock; | 35 | int subblock; |
36 | struct spi_pram __iomem *pram; | 36 | struct spi_pram __iomem *pram; |
37 | #ifdef CONFIG_FSL_SOC | ||
37 | struct cpm_buf_desc __iomem *tx_bd; | 38 | struct cpm_buf_desc __iomem *tx_bd; |
38 | struct cpm_buf_desc __iomem *rx_bd; | 39 | struct cpm_buf_desc __iomem *rx_bd; |
40 | #endif | ||
39 | 41 | ||
40 | struct spi_transfer *xfer_in_progress; | 42 | struct spi_transfer *xfer_in_progress; |
41 | 43 | ||
@@ -87,12 +89,12 @@ struct spi_mpc8xxx_cs { | |||
87 | 89 | ||
88 | static inline void mpc8xxx_spi_write_reg(__be32 __iomem *reg, u32 val) | 90 | static inline void mpc8xxx_spi_write_reg(__be32 __iomem *reg, u32 val) |
89 | { | 91 | { |
90 | out_be32(reg, val); | 92 | iowrite32be(val, reg); |
91 | } | 93 | } |
92 | 94 | ||
93 | static inline u32 mpc8xxx_spi_read_reg(__be32 __iomem *reg) | 95 | static inline u32 mpc8xxx_spi_read_reg(__be32 __iomem *reg) |
94 | { | 96 | { |
95 | return in_be32(reg); | 97 | return ioread32be(reg); |
96 | } | 98 | } |
97 | 99 | ||
98 | struct mpc8xxx_spi_probe_info { | 100 | struct mpc8xxx_spi_probe_info { |
diff --git a/drivers/spi/spi-fsl-spi.c b/drivers/spi/spi-fsl-spi.c index 1985ba38032e..9878911ee6af 100644 --- a/drivers/spi/spi-fsl-spi.c +++ b/drivers/spi/spi-fsl-spi.c | |||
@@ -30,75 +30,14 @@ | |||
30 | #include <linux/mutex.h> | 30 | #include <linux/mutex.h> |
31 | #include <linux/of.h> | 31 | #include <linux/of.h> |
32 | #include <linux/of_platform.h> | 32 | #include <linux/of_platform.h> |
33 | #include <linux/of_address.h> | ||
34 | #include <linux/of_irq.h> | ||
33 | #include <linux/gpio.h> | 35 | #include <linux/gpio.h> |
34 | #include <linux/of_gpio.h> | 36 | #include <linux/of_gpio.h> |
35 | 37 | ||
36 | #include <sysdev/fsl_soc.h> | ||
37 | #include <asm/cpm.h> | ||
38 | #include <asm/qe.h> | ||
39 | |||
40 | #include "spi-fsl-lib.h" | 38 | #include "spi-fsl-lib.h" |
41 | 39 | #include "spi-fsl-cpm.h" | |
42 | /* CPM1 and CPM2 are mutually exclusive. */ | 40 | #include "spi-fsl-spi.h" |
43 | #ifdef CONFIG_CPM1 | ||
44 | #include <asm/cpm1.h> | ||
45 | #define CPM_SPI_CMD mk_cr_cmd(CPM_CR_CH_SPI, 0) | ||
46 | #else | ||
47 | #include <asm/cpm2.h> | ||
48 | #define CPM_SPI_CMD mk_cr_cmd(CPM_CR_SPI_PAGE, CPM_CR_SPI_SBLOCK, 0, 0) | ||
49 | #endif | ||
50 | |||
51 | /* SPI Controller registers */ | ||
52 | struct fsl_spi_reg { | ||
53 | u8 res1[0x20]; | ||
54 | __be32 mode; | ||
55 | __be32 event; | ||
56 | __be32 mask; | ||
57 | __be32 command; | ||
58 | __be32 transmit; | ||
59 | __be32 receive; | ||
60 | }; | ||
61 | |||
62 | /* SPI Controller mode register definitions */ | ||
63 | #define SPMODE_LOOP (1 << 30) | ||
64 | #define SPMODE_CI_INACTIVEHIGH (1 << 29) | ||
65 | #define SPMODE_CP_BEGIN_EDGECLK (1 << 28) | ||
66 | #define SPMODE_DIV16 (1 << 27) | ||
67 | #define SPMODE_REV (1 << 26) | ||
68 | #define SPMODE_MS (1 << 25) | ||
69 | #define SPMODE_ENABLE (1 << 24) | ||
70 | #define SPMODE_LEN(x) ((x) << 20) | ||
71 | #define SPMODE_PM(x) ((x) << 16) | ||
72 | #define SPMODE_OP (1 << 14) | ||
73 | #define SPMODE_CG(x) ((x) << 7) | ||
74 | |||
75 | /* | ||
76 | * Default for SPI Mode: | ||
77 | * SPI MODE 0 (inactive low, phase middle, MSB, 8-bit length, slow clk | ||
78 | */ | ||
79 | #define SPMODE_INIT_VAL (SPMODE_CI_INACTIVEHIGH | SPMODE_DIV16 | SPMODE_REV | \ | ||
80 | SPMODE_MS | SPMODE_LEN(7) | SPMODE_PM(0xf)) | ||
81 | |||
82 | /* SPIE register values */ | ||
83 | #define SPIE_NE 0x00000200 /* Not empty */ | ||
84 | #define SPIE_NF 0x00000100 /* Not full */ | ||
85 | |||
86 | /* SPIM register values */ | ||
87 | #define SPIM_NE 0x00000200 /* Not empty */ | ||
88 | #define SPIM_NF 0x00000100 /* Not full */ | ||
89 | |||
90 | #define SPIE_TXB 0x00000200 /* Last char is written to tx fifo */ | ||
91 | #define SPIE_RXB 0x00000100 /* Last char is written to rx buf */ | ||
92 | |||
93 | /* SPCOM register values */ | ||
94 | #define SPCOM_STR (1 << 23) /* Start transmit */ | ||
95 | |||
96 | #define SPI_PRAM_SIZE 0x100 | ||
97 | #define SPI_MRBLR ((unsigned int)PAGE_SIZE) | ||
98 | |||
99 | static void *fsl_dummy_rx; | ||
100 | static DEFINE_MUTEX(fsl_dummy_rx_lock); | ||
101 | static int fsl_dummy_rx_refcnt; | ||
102 | 41 | ||
103 | static void fsl_spi_change_mode(struct spi_device *spi) | 42 | static void fsl_spi_change_mode(struct spi_device *spi) |
104 | { | 43 | { |
@@ -119,18 +58,7 @@ static void fsl_spi_change_mode(struct spi_device *spi) | |||
119 | 58 | ||
120 | /* When in CPM mode, we need to reinit tx and rx. */ | 59 | /* When in CPM mode, we need to reinit tx and rx. */ |
121 | if (mspi->flags & SPI_CPM_MODE) { | 60 | if (mspi->flags & SPI_CPM_MODE) { |
122 | if (mspi->flags & SPI_QE) { | 61 | fsl_spi_cpm_reinit_txrx(mspi); |
123 | qe_issue_cmd(QE_INIT_TX_RX, mspi->subblock, | ||
124 | QE_CR_PROTOCOL_UNSPECIFIED, 0); | ||
125 | } else { | ||
126 | cpm_command(CPM_SPI_CMD, CPM_CR_INIT_TRX); | ||
127 | if (mspi->flags & SPI_CPM1) { | ||
128 | out_be16(&mspi->pram->rbptr, | ||
129 | in_be16(&mspi->pram->rbase)); | ||
130 | out_be16(&mspi->pram->tbptr, | ||
131 | in_be16(&mspi->pram->tbase)); | ||
132 | } | ||
133 | } | ||
134 | } | 62 | } |
135 | mpc8xxx_spi_write_reg(mode, cs->hw_mode); | 63 | mpc8xxx_spi_write_reg(mode, cs->hw_mode); |
136 | local_irq_restore(flags); | 64 | local_irq_restore(flags); |
@@ -295,112 +223,6 @@ static int fsl_spi_setup_transfer(struct spi_device *spi, | |||
295 | return 0; | 223 | return 0; |
296 | } | 224 | } |
297 | 225 | ||
298 | static void fsl_spi_cpm_bufs_start(struct mpc8xxx_spi *mspi) | ||
299 | { | ||
300 | struct cpm_buf_desc __iomem *tx_bd = mspi->tx_bd; | ||
301 | struct cpm_buf_desc __iomem *rx_bd = mspi->rx_bd; | ||
302 | unsigned int xfer_len = min(mspi->count, SPI_MRBLR); | ||
303 | unsigned int xfer_ofs; | ||
304 | struct fsl_spi_reg *reg_base = mspi->reg_base; | ||
305 | |||
306 | xfer_ofs = mspi->xfer_in_progress->len - mspi->count; | ||
307 | |||
308 | if (mspi->rx_dma == mspi->dma_dummy_rx) | ||
309 | out_be32(&rx_bd->cbd_bufaddr, mspi->rx_dma); | ||
310 | else | ||
311 | out_be32(&rx_bd->cbd_bufaddr, mspi->rx_dma + xfer_ofs); | ||
312 | out_be16(&rx_bd->cbd_datlen, 0); | ||
313 | out_be16(&rx_bd->cbd_sc, BD_SC_EMPTY | BD_SC_INTRPT | BD_SC_WRAP); | ||
314 | |||
315 | if (mspi->tx_dma == mspi->dma_dummy_tx) | ||
316 | out_be32(&tx_bd->cbd_bufaddr, mspi->tx_dma); | ||
317 | else | ||
318 | out_be32(&tx_bd->cbd_bufaddr, mspi->tx_dma + xfer_ofs); | ||
319 | out_be16(&tx_bd->cbd_datlen, xfer_len); | ||
320 | out_be16(&tx_bd->cbd_sc, BD_SC_READY | BD_SC_INTRPT | BD_SC_WRAP | | ||
321 | BD_SC_LAST); | ||
322 | |||
323 | /* start transfer */ | ||
324 | mpc8xxx_spi_write_reg(®_base->command, SPCOM_STR); | ||
325 | } | ||
326 | |||
327 | static int fsl_spi_cpm_bufs(struct mpc8xxx_spi *mspi, | ||
328 | struct spi_transfer *t, bool is_dma_mapped) | ||
329 | { | ||
330 | struct device *dev = mspi->dev; | ||
331 | struct fsl_spi_reg *reg_base = mspi->reg_base; | ||
332 | |||
333 | if (is_dma_mapped) { | ||
334 | mspi->map_tx_dma = 0; | ||
335 | mspi->map_rx_dma = 0; | ||
336 | } else { | ||
337 | mspi->map_tx_dma = 1; | ||
338 | mspi->map_rx_dma = 1; | ||
339 | } | ||
340 | |||
341 | if (!t->tx_buf) { | ||
342 | mspi->tx_dma = mspi->dma_dummy_tx; | ||
343 | mspi->map_tx_dma = 0; | ||
344 | } | ||
345 | |||
346 | if (!t->rx_buf) { | ||
347 | mspi->rx_dma = mspi->dma_dummy_rx; | ||
348 | mspi->map_rx_dma = 0; | ||
349 | } | ||
350 | |||
351 | if (mspi->map_tx_dma) { | ||
352 | void *nonconst_tx = (void *)mspi->tx; /* shut up gcc */ | ||
353 | |||
354 | mspi->tx_dma = dma_map_single(dev, nonconst_tx, t->len, | ||
355 | DMA_TO_DEVICE); | ||
356 | if (dma_mapping_error(dev, mspi->tx_dma)) { | ||
357 | dev_err(dev, "unable to map tx dma\n"); | ||
358 | return -ENOMEM; | ||
359 | } | ||
360 | } else if (t->tx_buf) { | ||
361 | mspi->tx_dma = t->tx_dma; | ||
362 | } | ||
363 | |||
364 | if (mspi->map_rx_dma) { | ||
365 | mspi->rx_dma = dma_map_single(dev, mspi->rx, t->len, | ||
366 | DMA_FROM_DEVICE); | ||
367 | if (dma_mapping_error(dev, mspi->rx_dma)) { | ||
368 | dev_err(dev, "unable to map rx dma\n"); | ||
369 | goto err_rx_dma; | ||
370 | } | ||
371 | } else if (t->rx_buf) { | ||
372 | mspi->rx_dma = t->rx_dma; | ||
373 | } | ||
374 | |||
375 | /* enable rx ints */ | ||
376 | mpc8xxx_spi_write_reg(®_base->mask, SPIE_RXB); | ||
377 | |||
378 | mspi->xfer_in_progress = t; | ||
379 | mspi->count = t->len; | ||
380 | |||
381 | /* start CPM transfers */ | ||
382 | fsl_spi_cpm_bufs_start(mspi); | ||
383 | |||
384 | return 0; | ||
385 | |||
386 | err_rx_dma: | ||
387 | if (mspi->map_tx_dma) | ||
388 | dma_unmap_single(dev, mspi->tx_dma, t->len, DMA_TO_DEVICE); | ||
389 | return -ENOMEM; | ||
390 | } | ||
391 | |||
392 | static void fsl_spi_cpm_bufs_complete(struct mpc8xxx_spi *mspi) | ||
393 | { | ||
394 | struct device *dev = mspi->dev; | ||
395 | struct spi_transfer *t = mspi->xfer_in_progress; | ||
396 | |||
397 | if (mspi->map_tx_dma) | ||
398 | dma_unmap_single(dev, mspi->tx_dma, t->len, DMA_TO_DEVICE); | ||
399 | if (mspi->map_rx_dma) | ||
400 | dma_unmap_single(dev, mspi->rx_dma, t->len, DMA_FROM_DEVICE); | ||
401 | mspi->xfer_in_progress = NULL; | ||
402 | } | ||
403 | |||
404 | static int fsl_spi_cpu_bufs(struct mpc8xxx_spi *mspi, | 226 | static int fsl_spi_cpu_bufs(struct mpc8xxx_spi *mspi, |
405 | struct spi_transfer *t, unsigned int len) | 227 | struct spi_transfer *t, unsigned int len) |
406 | { | 228 | { |
@@ -568,30 +390,6 @@ static int fsl_spi_setup(struct spi_device *spi) | |||
568 | return 0; | 390 | return 0; |
569 | } | 391 | } |
570 | 392 | ||
571 | static void fsl_spi_cpm_irq(struct mpc8xxx_spi *mspi, u32 events) | ||
572 | { | ||
573 | u16 len; | ||
574 | struct fsl_spi_reg *reg_base = mspi->reg_base; | ||
575 | |||
576 | dev_dbg(mspi->dev, "%s: bd datlen %d, count %d\n", __func__, | ||
577 | in_be16(&mspi->rx_bd->cbd_datlen), mspi->count); | ||
578 | |||
579 | len = in_be16(&mspi->rx_bd->cbd_datlen); | ||
580 | if (len > mspi->count) { | ||
581 | WARN_ON(1); | ||
582 | len = mspi->count; | ||
583 | } | ||
584 | |||
585 | /* Clear the events */ | ||
586 | mpc8xxx_spi_write_reg(®_base->event, events); | ||
587 | |||
588 | mspi->count -= len; | ||
589 | if (mspi->count) | ||
590 | fsl_spi_cpm_bufs_start(mspi); | ||
591 | else | ||
592 | complete(&mspi->done); | ||
593 | } | ||
594 | |||
595 | static void fsl_spi_cpu_irq(struct mpc8xxx_spi *mspi, u32 events) | 393 | static void fsl_spi_cpu_irq(struct mpc8xxx_spi *mspi, u32 events) |
596 | { | 394 | { |
597 | struct fsl_spi_reg *reg_base = mspi->reg_base; | 395 | struct fsl_spi_reg *reg_base = mspi->reg_base; |
@@ -646,197 +444,6 @@ static irqreturn_t fsl_spi_irq(s32 irq, void *context_data) | |||
646 | return ret; | 444 | return ret; |
647 | } | 445 | } |
648 | 446 | ||
649 | static void *fsl_spi_alloc_dummy_rx(void) | ||
650 | { | ||
651 | mutex_lock(&fsl_dummy_rx_lock); | ||
652 | |||
653 | if (!fsl_dummy_rx) | ||
654 | fsl_dummy_rx = kmalloc(SPI_MRBLR, GFP_KERNEL); | ||
655 | if (fsl_dummy_rx) | ||
656 | fsl_dummy_rx_refcnt++; | ||
657 | |||
658 | mutex_unlock(&fsl_dummy_rx_lock); | ||
659 | |||
660 | return fsl_dummy_rx; | ||
661 | } | ||
662 | |||
663 | static void fsl_spi_free_dummy_rx(void) | ||
664 | { | ||
665 | mutex_lock(&fsl_dummy_rx_lock); | ||
666 | |||
667 | switch (fsl_dummy_rx_refcnt) { | ||
668 | case 0: | ||
669 | WARN_ON(1); | ||
670 | break; | ||
671 | case 1: | ||
672 | kfree(fsl_dummy_rx); | ||
673 | fsl_dummy_rx = NULL; | ||
674 | /* fall through */ | ||
675 | default: | ||
676 | fsl_dummy_rx_refcnt--; | ||
677 | break; | ||
678 | } | ||
679 | |||
680 | mutex_unlock(&fsl_dummy_rx_lock); | ||
681 | } | ||
682 | |||
683 | static unsigned long fsl_spi_cpm_get_pram(struct mpc8xxx_spi *mspi) | ||
684 | { | ||
685 | struct device *dev = mspi->dev; | ||
686 | struct device_node *np = dev->of_node; | ||
687 | const u32 *iprop; | ||
688 | int size; | ||
689 | void __iomem *spi_base; | ||
690 | unsigned long pram_ofs = -ENOMEM; | ||
691 | |||
692 | /* Can't use of_address_to_resource(), QE muram isn't at 0. */ | ||
693 | iprop = of_get_property(np, "reg", &size); | ||
694 | |||
695 | /* QE with a fixed pram location? */ | ||
696 | if (mspi->flags & SPI_QE && iprop && size == sizeof(*iprop) * 4) | ||
697 | return cpm_muram_alloc_fixed(iprop[2], SPI_PRAM_SIZE); | ||
698 | |||
699 | /* QE but with a dynamic pram location? */ | ||
700 | if (mspi->flags & SPI_QE) { | ||
701 | pram_ofs = cpm_muram_alloc(SPI_PRAM_SIZE, 64); | ||
702 | qe_issue_cmd(QE_ASSIGN_PAGE_TO_DEVICE, mspi->subblock, | ||
703 | QE_CR_PROTOCOL_UNSPECIFIED, pram_ofs); | ||
704 | return pram_ofs; | ||
705 | } | ||
706 | |||
707 | spi_base = of_iomap(np, 1); | ||
708 | if (spi_base == NULL) | ||
709 | return -EINVAL; | ||
710 | |||
711 | if (mspi->flags & SPI_CPM2) { | ||
712 | pram_ofs = cpm_muram_alloc(SPI_PRAM_SIZE, 64); | ||
713 | out_be16(spi_base, pram_ofs); | ||
714 | } else { | ||
715 | struct spi_pram __iomem *pram = spi_base; | ||
716 | u16 rpbase = in_be16(&pram->rpbase); | ||
717 | |||
718 | /* Microcode relocation patch applied? */ | ||
719 | if (rpbase) | ||
720 | pram_ofs = rpbase; | ||
721 | else { | ||
722 | pram_ofs = cpm_muram_alloc(SPI_PRAM_SIZE, 64); | ||
723 | out_be16(spi_base, pram_ofs); | ||
724 | } | ||
725 | } | ||
726 | |||
727 | iounmap(spi_base); | ||
728 | return pram_ofs; | ||
729 | } | ||
730 | |||
731 | static int fsl_spi_cpm_init(struct mpc8xxx_spi *mspi) | ||
732 | { | ||
733 | struct device *dev = mspi->dev; | ||
734 | struct device_node *np = dev->of_node; | ||
735 | const u32 *iprop; | ||
736 | int size; | ||
737 | unsigned long pram_ofs; | ||
738 | unsigned long bds_ofs; | ||
739 | |||
740 | if (!(mspi->flags & SPI_CPM_MODE)) | ||
741 | return 0; | ||
742 | |||
743 | if (!fsl_spi_alloc_dummy_rx()) | ||
744 | return -ENOMEM; | ||
745 | |||
746 | if (mspi->flags & SPI_QE) { | ||
747 | iprop = of_get_property(np, "cell-index", &size); | ||
748 | if (iprop && size == sizeof(*iprop)) | ||
749 | mspi->subblock = *iprop; | ||
750 | |||
751 | switch (mspi->subblock) { | ||
752 | default: | ||
753 | dev_warn(dev, "cell-index unspecified, assuming SPI1"); | ||
754 | /* fall through */ | ||
755 | case 0: | ||
756 | mspi->subblock = QE_CR_SUBBLOCK_SPI1; | ||
757 | break; | ||
758 | case 1: | ||
759 | mspi->subblock = QE_CR_SUBBLOCK_SPI2; | ||
760 | break; | ||
761 | } | ||
762 | } | ||
763 | |||
764 | pram_ofs = fsl_spi_cpm_get_pram(mspi); | ||
765 | if (IS_ERR_VALUE(pram_ofs)) { | ||
766 | dev_err(dev, "can't allocate spi parameter ram\n"); | ||
767 | goto err_pram; | ||
768 | } | ||
769 | |||
770 | bds_ofs = cpm_muram_alloc(sizeof(*mspi->tx_bd) + | ||
771 | sizeof(*mspi->rx_bd), 8); | ||
772 | if (IS_ERR_VALUE(bds_ofs)) { | ||
773 | dev_err(dev, "can't allocate bds\n"); | ||
774 | goto err_bds; | ||
775 | } | ||
776 | |||
777 | mspi->dma_dummy_tx = dma_map_single(dev, empty_zero_page, PAGE_SIZE, | ||
778 | DMA_TO_DEVICE); | ||
779 | if (dma_mapping_error(dev, mspi->dma_dummy_tx)) { | ||
780 | dev_err(dev, "unable to map dummy tx buffer\n"); | ||
781 | goto err_dummy_tx; | ||
782 | } | ||
783 | |||
784 | mspi->dma_dummy_rx = dma_map_single(dev, fsl_dummy_rx, SPI_MRBLR, | ||
785 | DMA_FROM_DEVICE); | ||
786 | if (dma_mapping_error(dev, mspi->dma_dummy_rx)) { | ||
787 | dev_err(dev, "unable to map dummy rx buffer\n"); | ||
788 | goto err_dummy_rx; | ||
789 | } | ||
790 | |||
791 | mspi->pram = cpm_muram_addr(pram_ofs); | ||
792 | |||
793 | mspi->tx_bd = cpm_muram_addr(bds_ofs); | ||
794 | mspi->rx_bd = cpm_muram_addr(bds_ofs + sizeof(*mspi->tx_bd)); | ||
795 | |||
796 | /* Initialize parameter ram. */ | ||
797 | out_be16(&mspi->pram->tbase, cpm_muram_offset(mspi->tx_bd)); | ||
798 | out_be16(&mspi->pram->rbase, cpm_muram_offset(mspi->rx_bd)); | ||
799 | out_8(&mspi->pram->tfcr, CPMFCR_EB | CPMFCR_GBL); | ||
800 | out_8(&mspi->pram->rfcr, CPMFCR_EB | CPMFCR_GBL); | ||
801 | out_be16(&mspi->pram->mrblr, SPI_MRBLR); | ||
802 | out_be32(&mspi->pram->rstate, 0); | ||
803 | out_be32(&mspi->pram->rdp, 0); | ||
804 | out_be16(&mspi->pram->rbptr, 0); | ||
805 | out_be16(&mspi->pram->rbc, 0); | ||
806 | out_be32(&mspi->pram->rxtmp, 0); | ||
807 | out_be32(&mspi->pram->tstate, 0); | ||
808 | out_be32(&mspi->pram->tdp, 0); | ||
809 | out_be16(&mspi->pram->tbptr, 0); | ||
810 | out_be16(&mspi->pram->tbc, 0); | ||
811 | out_be32(&mspi->pram->txtmp, 0); | ||
812 | |||
813 | return 0; | ||
814 | |||
815 | err_dummy_rx: | ||
816 | dma_unmap_single(dev, mspi->dma_dummy_tx, PAGE_SIZE, DMA_TO_DEVICE); | ||
817 | err_dummy_tx: | ||
818 | cpm_muram_free(bds_ofs); | ||
819 | err_bds: | ||
820 | cpm_muram_free(pram_ofs); | ||
821 | err_pram: | ||
822 | fsl_spi_free_dummy_rx(); | ||
823 | return -ENOMEM; | ||
824 | } | ||
825 | |||
826 | static void fsl_spi_cpm_free(struct mpc8xxx_spi *mspi) | ||
827 | { | ||
828 | struct device *dev = mspi->dev; | ||
829 | |||
830 | if (!(mspi->flags & SPI_CPM_MODE)) | ||
831 | return; | ||
832 | |||
833 | dma_unmap_single(dev, mspi->dma_dummy_rx, SPI_MRBLR, DMA_FROM_DEVICE); | ||
834 | dma_unmap_single(dev, mspi->dma_dummy_tx, PAGE_SIZE, DMA_TO_DEVICE); | ||
835 | cpm_muram_free(cpm_muram_offset(mspi->tx_bd)); | ||
836 | cpm_muram_free(cpm_muram_offset(mspi->pram)); | ||
837 | fsl_spi_free_dummy_rx(); | ||
838 | } | ||
839 | |||
840 | static void fsl_spi_remove(struct mpc8xxx_spi *mspi) | 447 | static void fsl_spi_remove(struct mpc8xxx_spi *mspi) |
841 | { | 448 | { |
842 | iounmap(mspi->reg_base); | 449 | iounmap(mspi->reg_base); |
@@ -1047,7 +654,7 @@ static int of_fsl_spi_probe(struct platform_device *ofdev) | |||
1047 | struct device_node *np = ofdev->dev.of_node; | 654 | struct device_node *np = ofdev->dev.of_node; |
1048 | struct spi_master *master; | 655 | struct spi_master *master; |
1049 | struct resource mem; | 656 | struct resource mem; |
1050 | struct resource irq; | 657 | int irq; |
1051 | int ret = -ENOMEM; | 658 | int ret = -ENOMEM; |
1052 | 659 | ||
1053 | ret = of_mpc8xxx_spi_probe(ofdev); | 660 | ret = of_mpc8xxx_spi_probe(ofdev); |
@@ -1062,13 +669,13 @@ static int of_fsl_spi_probe(struct platform_device *ofdev) | |||
1062 | if (ret) | 669 | if (ret) |
1063 | goto err; | 670 | goto err; |
1064 | 671 | ||
1065 | ret = of_irq_to_resource(np, 0, &irq); | 672 | irq = irq_of_parse_and_map(np, 0); |
1066 | if (!ret) { | 673 | if (!irq) { |
1067 | ret = -EINVAL; | 674 | ret = -EINVAL; |
1068 | goto err; | 675 | goto err; |
1069 | } | 676 | } |
1070 | 677 | ||
1071 | master = fsl_spi_probe(dev, &mem, irq.start); | 678 | master = fsl_spi_probe(dev, &mem, irq); |
1072 | if (IS_ERR(master)) { | 679 | if (IS_ERR(master)) { |
1073 | ret = PTR_ERR(master); | 680 | ret = PTR_ERR(master); |
1074 | goto err; | 681 | goto err; |
diff --git a/drivers/spi/spi-fsl-spi.h b/drivers/spi/spi-fsl-spi.h new file mode 100644 index 000000000000..8bd73a4318ef --- /dev/null +++ b/drivers/spi/spi-fsl-spi.h | |||
@@ -0,0 +1,61 @@ | |||
1 | /* | ||
2 | * Freescale SPI controller driver. | ||
3 | * | ||
4 | * Maintainer: Kumar Gala | ||
5 | * | ||
6 | * Copyright (C) 2006 Polycom, Inc. | ||
7 | * Copyright 2010 Freescale Semiconductor, Inc. | ||
8 | * | ||
9 | * CPM SPI and QE buffer descriptors mode support: | ||
10 | * Copyright (c) 2009 MontaVista Software, Inc. | ||
11 | * Author: Anton Vorontsov <avorontsov@ru.mvista.com> | ||
12 | * | ||
13 | * This program is free software; you can redistribute it and/or modify it | ||
14 | * under the terms of the GNU General Public License as published by the | ||
15 | * Free Software Foundation; either version 2 of the License, or (at your | ||
16 | * option) any later version. | ||
17 | */ | ||
18 | |||
19 | #ifndef __SPI_FSL_SPI_H__ | ||
20 | #define __SPI_FSL_SPI_H__ | ||
21 | |||
22 | /* SPI Controller registers */ | ||
23 | struct fsl_spi_reg { | ||
24 | u8 res1[0x20]; | ||
25 | __be32 mode; | ||
26 | __be32 event; | ||
27 | __be32 mask; | ||
28 | __be32 command; | ||
29 | __be32 transmit; | ||
30 | __be32 receive; | ||
31 | }; | ||
32 | |||
33 | /* SPI Controller mode register definitions */ | ||
34 | #define SPMODE_LOOP (1 << 30) | ||
35 | #define SPMODE_CI_INACTIVEHIGH (1 << 29) | ||
36 | #define SPMODE_CP_BEGIN_EDGECLK (1 << 28) | ||
37 | #define SPMODE_DIV16 (1 << 27) | ||
38 | #define SPMODE_REV (1 << 26) | ||
39 | #define SPMODE_MS (1 << 25) | ||
40 | #define SPMODE_ENABLE (1 << 24) | ||
41 | #define SPMODE_LEN(x) ((x) << 20) | ||
42 | #define SPMODE_PM(x) ((x) << 16) | ||
43 | #define SPMODE_OP (1 << 14) | ||
44 | #define SPMODE_CG(x) ((x) << 7) | ||
45 | |||
46 | /* | ||
47 | * Default for SPI Mode: | ||
48 | * SPI MODE 0 (inactive low, phase middle, MSB, 8-bit length, slow clk | ||
49 | */ | ||
50 | #define SPMODE_INIT_VAL (SPMODE_CI_INACTIVEHIGH | SPMODE_DIV16 | SPMODE_REV | \ | ||
51 | SPMODE_MS | SPMODE_LEN(7) | SPMODE_PM(0xf)) | ||
52 | |||
53 | /* SPIE register values */ | ||
54 | #define SPIE_NE 0x00000200 /* Not empty */ | ||
55 | #define SPIE_NF 0x00000100 /* Not full */ | ||
56 | |||
57 | /* SPIM register values */ | ||
58 | #define SPIM_NE 0x00000200 /* Not empty */ | ||
59 | #define SPIM_NF 0x00000100 /* Not full */ | ||
60 | |||
61 | #endif /* __SPI_FSL_SPI_H__ */ | ||