aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/spi
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2009-12-12 17:27:24 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2009-12-12 17:27:24 -0500
commit09cea96caa59fabab3030c53bd698b9b568d959a (patch)
treea991cdc0c887fdcda37f4b751ee98d3db9559f4e /drivers/spi
parent6eb7365db6f3a4a9d8d9922bb0b800f9cbaad641 (diff)
parente090aa80321b64c3b793f3b047e31ecf1af9538d (diff)
Merge branch 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/benh/powerpc
* 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/benh/powerpc: (151 commits) powerpc: Fix usage of 64-bit instruction in 32-bit altivec code MAINTAINERS: Add PowerPC patterns powerpc/pseries: Track previous CPPR values to correctly EOI interrupts powerpc/pseries: Correct pseries/dlpar.c build break without CONFIG_SMP powerpc: Make "intspec" pointers in irq_host->xlate() const powerpc/8xx: DTLB Miss cleanup powerpc/8xx: Remove DIRTY pte handling in DTLB Error. powerpc/8xx: Start using dcbX instructions in various copy routines powerpc/8xx: Restore _PAGE_WRITETHRU powerpc/8xx: Add missing Guarded setting in DTLB Error. powerpc/8xx: Fixup DAR from buggy dcbX instructions. powerpc/8xx: Tag DAR with 0x00f0 to catch buggy instructions. powerpc/8xx: Update TLB asm so it behaves as linux mm expects. powerpc/8xx: Invalidate non present TLBs powerpc/pseries: Serialize cpu hotplug operations during deactivate Vs deallocate pseries/pseries: Add code to online/offline CPUs of a DLPAR node powerpc: stop_this_cpu: remove the cpu from the online map. powerpc/pseries: Add kernel based CPU DLPAR handling sysfs/cpu: Add probe/release files powerpc/pseries: Kernel DLPAR Infrastructure ...
Diffstat (limited to 'drivers/spi')
-rw-r--r--drivers/spi/Kconfig11
-rw-r--r--drivers/spi/Makefile1
-rw-r--r--drivers/spi/mpc52xx_psc_spi.c25
-rw-r--r--drivers/spi/mpc52xx_spi.c520
-rw-r--r--drivers/spi/spi_mpc8xxx.c618
-rw-r--r--drivers/spi/xilinx_spi.c3
6 files changed, 1085 insertions, 93 deletions
diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
index 4b6f7cba3b3d..28fce65b8594 100644
--- a/drivers/spi/Kconfig
+++ b/drivers/spi/Kconfig
@@ -133,6 +133,14 @@ config SPI_LM70_LLP
133 which interfaces to an LM70 temperature sensor using 133 which interfaces to an LM70 temperature sensor using
134 a parallel port. 134 a parallel port.
135 135
136config SPI_MPC52xx
137 tristate "Freescale MPC52xx SPI (non-PSC) controller support"
138 depends on PPC_MPC52xx && SPI
139 select SPI_MASTER_OF
140 help
141 This drivers supports the MPC52xx SPI controller in master SPI
142 mode.
143
136config SPI_MPC52xx_PSC 144config SPI_MPC52xx_PSC
137 tristate "Freescale MPC52xx PSC SPI controller" 145 tristate "Freescale MPC52xx PSC SPI controller"
138 depends on PPC_MPC52xx && EXPERIMENTAL 146 depends on PPC_MPC52xx && EXPERIMENTAL
@@ -147,9 +155,6 @@ config SPI_MPC8xxx
147 This enables using the Freescale MPC8xxx SPI controllers in master 155 This enables using the Freescale MPC8xxx SPI controllers in master
148 mode. 156 mode.
149 157
150 This driver uses a simple set of shift registers for data (opposed
151 to the CPM based descriptor model).
152
153config SPI_OMAP_UWIRE 158config SPI_OMAP_UWIRE
154 tristate "OMAP1 MicroWire" 159 tristate "OMAP1 MicroWire"
155 depends on ARCH_OMAP1 160 depends on ARCH_OMAP1
diff --git a/drivers/spi/Makefile b/drivers/spi/Makefile
index 21a118269cac..e3f092a9afa5 100644
--- a/drivers/spi/Makefile
+++ b/drivers/spi/Makefile
@@ -25,6 +25,7 @@ obj-$(CONFIG_SPI_OMAP24XX) += omap2_mcspi.o
25obj-$(CONFIG_SPI_ORION) += orion_spi.o 25obj-$(CONFIG_SPI_ORION) += orion_spi.o
26obj-$(CONFIG_SPI_PL022) += amba-pl022.o 26obj-$(CONFIG_SPI_PL022) += amba-pl022.o
27obj-$(CONFIG_SPI_MPC52xx_PSC) += mpc52xx_psc_spi.o 27obj-$(CONFIG_SPI_MPC52xx_PSC) += mpc52xx_psc_spi.o
28obj-$(CONFIG_SPI_MPC52xx) += mpc52xx_spi.o
28obj-$(CONFIG_SPI_MPC8xxx) += spi_mpc8xxx.o 29obj-$(CONFIG_SPI_MPC8xxx) += spi_mpc8xxx.o
29obj-$(CONFIG_SPI_PPC4xx) += spi_ppc4xx.o 30obj-$(CONFIG_SPI_PPC4xx) += spi_ppc4xx.o
30obj-$(CONFIG_SPI_S3C24XX_GPIO) += spi_s3c24xx_gpio.o 31obj-$(CONFIG_SPI_S3C24XX_GPIO) += spi_s3c24xx_gpio.o
diff --git a/drivers/spi/mpc52xx_psc_spi.c b/drivers/spi/mpc52xx_psc_spi.c
index 1b74d5ca03f3..f50c81df336a 100644
--- a/drivers/spi/mpc52xx_psc_spi.c
+++ b/drivers/spi/mpc52xx_psc_spi.c
@@ -17,6 +17,7 @@
17#include <linux/errno.h> 17#include <linux/errno.h>
18#include <linux/interrupt.h> 18#include <linux/interrupt.h>
19#include <linux/of_platform.h> 19#include <linux/of_platform.h>
20#include <linux/of_spi.h>
20#include <linux/workqueue.h> 21#include <linux/workqueue.h>
21#include <linux/completion.h> 22#include <linux/completion.h>
22#include <linux/io.h> 23#include <linux/io.h>
@@ -313,11 +314,13 @@ static int mpc52xx_psc_spi_port_config(int psc_id, struct mpc52xx_psc_spi *mps)
313 struct mpc52xx_psc __iomem *psc = mps->psc; 314 struct mpc52xx_psc __iomem *psc = mps->psc;
314 struct mpc52xx_psc_fifo __iomem *fifo = mps->fifo; 315 struct mpc52xx_psc_fifo __iomem *fifo = mps->fifo;
315 u32 mclken_div; 316 u32 mclken_div;
316 int ret = 0; 317 int ret;
317 318
318 /* default sysclk is 512MHz */ 319 /* default sysclk is 512MHz */
319 mclken_div = (mps->sysclk ? mps->sysclk : 512000000) / MCLK; 320 mclken_div = (mps->sysclk ? mps->sysclk : 512000000) / MCLK;
320 mpc52xx_set_psc_clkdiv(psc_id, mclken_div); 321 ret = mpc52xx_set_psc_clkdiv(psc_id, mclken_div);
322 if (ret)
323 return ret;
321 324
322 /* Reset the PSC into a known state */ 325 /* Reset the PSC into a known state */
323 out_8(&psc->command, MPC52xx_PSC_RST_RX); 326 out_8(&psc->command, MPC52xx_PSC_RST_RX);
@@ -341,7 +344,7 @@ static int mpc52xx_psc_spi_port_config(int psc_id, struct mpc52xx_psc_spi *mps)
341 344
342 mps->bits_per_word = 8; 345 mps->bits_per_word = 8;
343 346
344 return ret; 347 return 0;
345} 348}
346 349
347static irqreturn_t mpc52xx_psc_spi_isr(int irq, void *dev_id) 350static irqreturn_t mpc52xx_psc_spi_isr(int irq, void *dev_id)
@@ -410,8 +413,10 @@ static int __init mpc52xx_psc_spi_do_probe(struct device *dev, u32 regaddr,
410 goto free_master; 413 goto free_master;
411 414
412 ret = mpc52xx_psc_spi_port_config(master->bus_num, mps); 415 ret = mpc52xx_psc_spi_port_config(master->bus_num, mps);
413 if (ret < 0) 416 if (ret < 0) {
417 dev_err(dev, "can't configure PSC! Is it capable of SPI?\n");
414 goto free_irq; 418 goto free_irq;
419 }
415 420
416 spin_lock_init(&mps->lock); 421 spin_lock_init(&mps->lock);
417 init_completion(&mps->done); 422 init_completion(&mps->done);
@@ -464,10 +469,11 @@ static int __init mpc52xx_psc_spi_of_probe(struct of_device *op,
464 const u32 *regaddr_p; 469 const u32 *regaddr_p;
465 u64 regaddr64, size64; 470 u64 regaddr64, size64;
466 s16 id = -1; 471 s16 id = -1;
472 int rc;
467 473
468 regaddr_p = of_get_address(op->node, 0, &size64, NULL); 474 regaddr_p = of_get_address(op->node, 0, &size64, NULL);
469 if (!regaddr_p) { 475 if (!regaddr_p) {
470 printk(KERN_ERR "Invalid PSC address\n"); 476 dev_err(&op->dev, "Invalid PSC address\n");
471 return -EINVAL; 477 return -EINVAL;
472 } 478 }
473 regaddr64 = of_translate_address(op->node, regaddr_p); 479 regaddr64 = of_translate_address(op->node, regaddr_p);
@@ -478,15 +484,18 @@ static int __init mpc52xx_psc_spi_of_probe(struct of_device *op,
478 484
479 psc_nump = of_get_property(op->node, "cell-index", NULL); 485 psc_nump = of_get_property(op->node, "cell-index", NULL);
480 if (!psc_nump || *psc_nump > 5) { 486 if (!psc_nump || *psc_nump > 5) {
481 printk(KERN_ERR "mpc52xx_psc_spi: Device node %s has invalid " 487 dev_err(&op->dev, "Invalid cell-index property\n");
482 "cell-index property\n", op->node->full_name);
483 return -EINVAL; 488 return -EINVAL;
484 } 489 }
485 id = *psc_nump + 1; 490 id = *psc_nump + 1;
486 } 491 }
487 492
488 return mpc52xx_psc_spi_do_probe(&op->dev, (u32)regaddr64, (u32)size64, 493 rc = mpc52xx_psc_spi_do_probe(&op->dev, (u32)regaddr64, (u32)size64,
489 irq_of_parse_and_map(op->node, 0), id); 494 irq_of_parse_and_map(op->node, 0), id);
495 if (rc == 0)
496 of_register_spi_devices(dev_get_drvdata(&op->dev), op->node);
497
498 return rc;
490} 499}
491 500
492static int __exit mpc52xx_psc_spi_of_remove(struct of_device *op) 501static int __exit mpc52xx_psc_spi_of_remove(struct of_device *op)
diff --git a/drivers/spi/mpc52xx_spi.c b/drivers/spi/mpc52xx_spi.c
new file mode 100644
index 000000000000..ef8379b2c172
--- /dev/null
+++ b/drivers/spi/mpc52xx_spi.c
@@ -0,0 +1,520 @@
1/*
2 * MPC52xx SPI bus driver.
3 *
4 * Copyright (C) 2008 Secret Lab Technologies Ltd.
5 *
6 * This file is released under the GPLv2
7 *
8 * This is the driver for the MPC5200's dedicated SPI controller.
9 *
10 * Note: this driver does not support the MPC5200 PSC in SPI mode. For
11 * that driver see drivers/spi/mpc52xx_psc_spi.c
12 */
13
14#include <linux/module.h>
15#include <linux/init.h>
16#include <linux/errno.h>
17#include <linux/of_platform.h>
18#include <linux/interrupt.h>
19#include <linux/delay.h>
20#include <linux/spi/spi.h>
21#include <linux/spi/mpc52xx_spi.h>
22#include <linux/of_spi.h>
23#include <linux/io.h>
24#include <asm/time.h>
25#include <asm/mpc52xx.h>
26
27MODULE_AUTHOR("Grant Likely <grant.likely@secretlab.ca>");
28MODULE_DESCRIPTION("MPC52xx SPI (non-PSC) Driver");
29MODULE_LICENSE("GPL");
30
31/* Register offsets */
32#define SPI_CTRL1 0x00
33#define SPI_CTRL1_SPIE (1 << 7)
34#define SPI_CTRL1_SPE (1 << 6)
35#define SPI_CTRL1_MSTR (1 << 4)
36#define SPI_CTRL1_CPOL (1 << 3)
37#define SPI_CTRL1_CPHA (1 << 2)
38#define SPI_CTRL1_SSOE (1 << 1)
39#define SPI_CTRL1_LSBFE (1 << 0)
40
41#define SPI_CTRL2 0x01
42#define SPI_BRR 0x04
43
44#define SPI_STATUS 0x05
45#define SPI_STATUS_SPIF (1 << 7)
46#define SPI_STATUS_WCOL (1 << 6)
47#define SPI_STATUS_MODF (1 << 4)
48
49#define SPI_DATA 0x09
50#define SPI_PORTDATA 0x0d
51#define SPI_DATADIR 0x10
52
53/* FSM state return values */
54#define FSM_STOP 0 /* Nothing more for the state machine to */
55 /* do. If something interesting happens */
56 /* then and IRQ will be received */
57#define FSM_POLL 1 /* need to poll for completion, an IRQ is */
58 /* not expected */
59#define FSM_CONTINUE 2 /* Keep iterating the state machine */
60
61/* Driver internal data */
62struct mpc52xx_spi {
63 struct spi_master *master;
64 u32 sysclk;
65 void __iomem *regs;
66 int irq0; /* MODF irq */
67 int irq1; /* SPIF irq */
68 int ipb_freq;
69
70 /* Statistics */
71 int msg_count;
72 int wcol_count;
73 int wcol_ticks;
74 u32 wcol_tx_timestamp;
75 int modf_count;
76 int byte_count;
77
78 struct list_head queue; /* queue of pending messages */
79 spinlock_t lock;
80 struct work_struct work;
81
82
83 /* Details of current transfer (length, and buffer pointers) */
84 struct spi_message *message; /* current message */
85 struct spi_transfer *transfer; /* current transfer */
86 int (*state)(int irq, struct mpc52xx_spi *ms, u8 status, u8 data);
87 int len;
88 int timestamp;
89 u8 *rx_buf;
90 const u8 *tx_buf;
91 int cs_change;
92};
93
94/*
95 * CS control function
96 */
97static void mpc52xx_spi_chipsel(struct mpc52xx_spi *ms, int value)
98{
99 out_8(ms->regs + SPI_PORTDATA, value ? 0 : 0x08);
100}
101
102/*
103 * Start a new transfer. This is called both by the idle state
104 * for the first transfer in a message, and by the wait state when the
105 * previous transfer in a message is complete.
106 */
107static void mpc52xx_spi_start_transfer(struct mpc52xx_spi *ms)
108{
109 ms->rx_buf = ms->transfer->rx_buf;
110 ms->tx_buf = ms->transfer->tx_buf;
111 ms->len = ms->transfer->len;
112
113 /* Activate the chip select */
114 if (ms->cs_change)
115 mpc52xx_spi_chipsel(ms, 1);
116 ms->cs_change = ms->transfer->cs_change;
117
118 /* Write out the first byte */
119 ms->wcol_tx_timestamp = get_tbl();
120 if (ms->tx_buf)
121 out_8(ms->regs + SPI_DATA, *ms->tx_buf++);
122 else
123 out_8(ms->regs + SPI_DATA, 0);
124}
125
126/* Forward declaration of state handlers */
127static int mpc52xx_spi_fsmstate_transfer(int irq, struct mpc52xx_spi *ms,
128 u8 status, u8 data);
129static int mpc52xx_spi_fsmstate_wait(int irq, struct mpc52xx_spi *ms,
130 u8 status, u8 data);
131
132/*
133 * IDLE state
134 *
135 * No transfers are in progress; if another transfer is pending then retrieve
136 * it and kick it off. Otherwise, stop processing the state machine
137 */
138static int
139mpc52xx_spi_fsmstate_idle(int irq, struct mpc52xx_spi *ms, u8 status, u8 data)
140{
141 struct spi_device *spi;
142 int spr, sppr;
143 u8 ctrl1;
144
145 if (status && (irq != NO_IRQ))
146 dev_err(&ms->master->dev, "spurious irq, status=0x%.2x\n",
147 status);
148
149 /* Check if there is another transfer waiting. */
150 if (list_empty(&ms->queue))
151 return FSM_STOP;
152
153 /* get the head of the queue */
154 ms->message = list_first_entry(&ms->queue, struct spi_message, queue);
155 list_del_init(&ms->message->queue);
156
157 /* Setup the controller parameters */
158 ctrl1 = SPI_CTRL1_SPIE | SPI_CTRL1_SPE | SPI_CTRL1_MSTR;
159 spi = ms->message->spi;
160 if (spi->mode & SPI_CPHA)
161 ctrl1 |= SPI_CTRL1_CPHA;
162 if (spi->mode & SPI_CPOL)
163 ctrl1 |= SPI_CTRL1_CPOL;
164 if (spi->mode & SPI_LSB_FIRST)
165 ctrl1 |= SPI_CTRL1_LSBFE;
166 out_8(ms->regs + SPI_CTRL1, ctrl1);
167
168 /* Setup the controller speed */
169 /* minimum divider is '2'. Also, add '1' to force rounding the
170 * divider up. */
171 sppr = ((ms->ipb_freq / ms->message->spi->max_speed_hz) + 1) >> 1;
172 spr = 0;
173 if (sppr < 1)
174 sppr = 1;
175 while (((sppr - 1) & ~0x7) != 0) {
176 sppr = (sppr + 1) >> 1; /* add '1' to force rounding up */
177 spr++;
178 }
179 sppr--; /* sppr quantity in register is offset by 1 */
180 if (spr > 7) {
181 /* Don't overrun limits of SPI baudrate register */
182 spr = 7;
183 sppr = 7;
184 }
185 out_8(ms->regs + SPI_BRR, sppr << 4 | spr); /* Set speed */
186
187 ms->cs_change = 1;
188 ms->transfer = container_of(ms->message->transfers.next,
189 struct spi_transfer, transfer_list);
190
191 mpc52xx_spi_start_transfer(ms);
192 ms->state = mpc52xx_spi_fsmstate_transfer;
193
194 return FSM_CONTINUE;
195}
196
197/*
198 * TRANSFER state
199 *
200 * In the middle of a transfer. If the SPI core has completed processing
201 * a byte, then read out the received data and write out the next byte
202 * (unless this transfer is finished; in which case go on to the wait
203 * state)
204 */
205static int mpc52xx_spi_fsmstate_transfer(int irq, struct mpc52xx_spi *ms,
206 u8 status, u8 data)
207{
208 if (!status)
209 return ms->irq0 ? FSM_STOP : FSM_POLL;
210
211 if (status & SPI_STATUS_WCOL) {
212 /* The SPI controller is stoopid. At slower speeds, it may
213 * raise the SPIF flag before the state machine is actually
214 * finished, which causes a collision (internal to the state
215 * machine only). The manual recommends inserting a delay
216 * between receiving the interrupt and sending the next byte,
217 * but it can also be worked around simply by retrying the
218 * transfer which is what we do here. */
219 ms->wcol_count++;
220 ms->wcol_ticks += get_tbl() - ms->wcol_tx_timestamp;
221 ms->wcol_tx_timestamp = get_tbl();
222 data = 0;
223 if (ms->tx_buf)
224 data = *(ms->tx_buf-1);
225 out_8(ms->regs + SPI_DATA, data); /* try again */
226 return FSM_CONTINUE;
227 } else if (status & SPI_STATUS_MODF) {
228 ms->modf_count++;
229 dev_err(&ms->master->dev, "mode fault\n");
230 mpc52xx_spi_chipsel(ms, 0);
231 ms->message->status = -EIO;
232 ms->message->complete(ms->message->context);
233 ms->state = mpc52xx_spi_fsmstate_idle;
234 return FSM_CONTINUE;
235 }
236
237 /* Read data out of the spi device */
238 ms->byte_count++;
239 if (ms->rx_buf)
240 *ms->rx_buf++ = data;
241
242 /* Is the transfer complete? */
243 ms->len--;
244 if (ms->len == 0) {
245 ms->timestamp = get_tbl();
246 ms->timestamp += ms->transfer->delay_usecs * tb_ticks_per_usec;
247 ms->state = mpc52xx_spi_fsmstate_wait;
248 return FSM_CONTINUE;
249 }
250
251 /* Write out the next byte */
252 ms->wcol_tx_timestamp = get_tbl();
253 if (ms->tx_buf)
254 out_8(ms->regs + SPI_DATA, *ms->tx_buf++);
255 else
256 out_8(ms->regs + SPI_DATA, 0);
257
258 return FSM_CONTINUE;
259}
260
261/*
262 * WAIT state
263 *
264 * A transfer has completed; need to wait for the delay period to complete
265 * before starting the next transfer
266 */
267static int
268mpc52xx_spi_fsmstate_wait(int irq, struct mpc52xx_spi *ms, u8 status, u8 data)
269{
270 if (status && irq)
271 dev_err(&ms->master->dev, "spurious irq, status=0x%.2x\n",
272 status);
273
274 if (((int)get_tbl()) - ms->timestamp < 0)
275 return FSM_POLL;
276
277 ms->message->actual_length += ms->transfer->len;
278
279 /* Check if there is another transfer in this message. If there
280 * aren't then deactivate CS, notify sender, and drop back to idle
281 * to start the next message. */
282 if (ms->transfer->transfer_list.next == &ms->message->transfers) {
283 ms->msg_count++;
284 mpc52xx_spi_chipsel(ms, 0);
285 ms->message->status = 0;
286 ms->message->complete(ms->message->context);
287 ms->state = mpc52xx_spi_fsmstate_idle;
288 return FSM_CONTINUE;
289 }
290
291 /* There is another transfer; kick it off */
292
293 if (ms->cs_change)
294 mpc52xx_spi_chipsel(ms, 0);
295
296 ms->transfer = container_of(ms->transfer->transfer_list.next,
297 struct spi_transfer, transfer_list);
298 mpc52xx_spi_start_transfer(ms);
299 ms->state = mpc52xx_spi_fsmstate_transfer;
300 return FSM_CONTINUE;
301}
302
303/**
304 * mpc52xx_spi_fsm_process - Finite State Machine iteration function
305 * @irq: irq number that triggered the FSM or 0 for polling
306 * @ms: pointer to mpc52xx_spi driver data
307 */
308static void mpc52xx_spi_fsm_process(int irq, struct mpc52xx_spi *ms)
309{
310 int rc = FSM_CONTINUE;
311 u8 status, data;
312
313 while (rc == FSM_CONTINUE) {
314 /* Interrupt cleared by read of STATUS followed by
315 * read of DATA registers */
316 status = in_8(ms->regs + SPI_STATUS);
317 data = in_8(ms->regs + SPI_DATA);
318 rc = ms->state(irq, ms, status, data);
319 }
320
321 if (rc == FSM_POLL)
322 schedule_work(&ms->work);
323}
324
325/**
326 * mpc52xx_spi_irq - IRQ handler
327 */
328static irqreturn_t mpc52xx_spi_irq(int irq, void *_ms)
329{
330 struct mpc52xx_spi *ms = _ms;
331 spin_lock(&ms->lock);
332 mpc52xx_spi_fsm_process(irq, ms);
333 spin_unlock(&ms->lock);
334 return IRQ_HANDLED;
335}
336
337/**
338 * mpc52xx_spi_wq - Workqueue function for polling the state machine
339 */
340static void mpc52xx_spi_wq(struct work_struct *work)
341{
342 struct mpc52xx_spi *ms = container_of(work, struct mpc52xx_spi, work);
343 unsigned long flags;
344
345 spin_lock_irqsave(&ms->lock, flags);
346 mpc52xx_spi_fsm_process(0, ms);
347 spin_unlock_irqrestore(&ms->lock, flags);
348}
349
350/*
351 * spi_master ops
352 */
353
354static int mpc52xx_spi_setup(struct spi_device *spi)
355{
356 if (spi->bits_per_word % 8)
357 return -EINVAL;
358
359 if (spi->mode & ~(SPI_CPOL | SPI_CPHA | SPI_LSB_FIRST))
360 return -EINVAL;
361
362 if (spi->chip_select >= spi->master->num_chipselect)
363 return -EINVAL;
364
365 return 0;
366}
367
368static int mpc52xx_spi_transfer(struct spi_device *spi, struct spi_message *m)
369{
370 struct mpc52xx_spi *ms = spi_master_get_devdata(spi->master);
371 unsigned long flags;
372
373 m->actual_length = 0;
374 m->status = -EINPROGRESS;
375
376 spin_lock_irqsave(&ms->lock, flags);
377 list_add_tail(&m->queue, &ms->queue);
378 spin_unlock_irqrestore(&ms->lock, flags);
379 schedule_work(&ms->work);
380
381 return 0;
382}
383
384/*
385 * OF Platform Bus Binding
386 */
387static int __devinit mpc52xx_spi_probe(struct of_device *op,
388 const struct of_device_id *match)
389{
390 struct spi_master *master;
391 struct mpc52xx_spi *ms;
392 void __iomem *regs;
393 int rc;
394
395 /* MMIO registers */
396 dev_dbg(&op->dev, "probing mpc5200 SPI device\n");
397 regs = of_iomap(op->node, 0);
398 if (!regs)
399 return -ENODEV;
400
401 /* initialize the device */
402 out_8(regs+SPI_CTRL1, SPI_CTRL1_SPIE | SPI_CTRL1_SPE | SPI_CTRL1_MSTR);
403 out_8(regs + SPI_CTRL2, 0x0);
404 out_8(regs + SPI_DATADIR, 0xe); /* Set output pins */
405 out_8(regs + SPI_PORTDATA, 0x8); /* Deassert /SS signal */
406
407 /* Clear the status register and re-read it to check for a MODF
408 * failure. This driver cannot currently handle multiple masters
409 * on the SPI bus. This fault will also occur if the SPI signals
410 * are not connected to any pins (port_config setting) */
411 in_8(regs + SPI_STATUS);
412 in_8(regs + SPI_DATA);
413 if (in_8(regs + SPI_STATUS) & SPI_STATUS_MODF) {
414 dev_err(&op->dev, "mode fault; is port_config correct?\n");
415 rc = -EIO;
416 goto err_init;
417 }
418
419 dev_dbg(&op->dev, "allocating spi_master struct\n");
420 master = spi_alloc_master(&op->dev, sizeof *ms);
421 if (!master) {
422 rc = -ENOMEM;
423 goto err_alloc;
424 }
425 master->bus_num = -1;
426 master->num_chipselect = 1;
427 master->setup = mpc52xx_spi_setup;
428 master->transfer = mpc52xx_spi_transfer;
429 dev_set_drvdata(&op->dev, master);
430
431 ms = spi_master_get_devdata(master);
432 ms->master = master;
433 ms->regs = regs;
434 ms->irq0 = irq_of_parse_and_map(op->node, 0);
435 ms->irq1 = irq_of_parse_and_map(op->node, 1);
436 ms->state = mpc52xx_spi_fsmstate_idle;
437 ms->ipb_freq = mpc5xxx_get_bus_frequency(op->node);
438 spin_lock_init(&ms->lock);
439 INIT_LIST_HEAD(&ms->queue);
440 INIT_WORK(&ms->work, mpc52xx_spi_wq);
441
442 /* Decide if interrupts can be used */
443 if (ms->irq0 && ms->irq1) {
444 rc = request_irq(ms->irq0, mpc52xx_spi_irq, IRQF_SAMPLE_RANDOM,
445 "mpc5200-spi-modf", ms);
446 rc |= request_irq(ms->irq1, mpc52xx_spi_irq, IRQF_SAMPLE_RANDOM,
447 "mpc5200-spi-spiF", ms);
448 if (rc) {
449 free_irq(ms->irq0, ms);
450 free_irq(ms->irq1, ms);
451 ms->irq0 = ms->irq1 = 0;
452 }
453 } else {
454 /* operate in polled mode */
455 ms->irq0 = ms->irq1 = 0;
456 }
457
458 if (!ms->irq0)
459 dev_info(&op->dev, "using polled mode\n");
460
461 dev_dbg(&op->dev, "registering spi_master struct\n");
462 rc = spi_register_master(master);
463 if (rc)
464 goto err_register;
465
466 of_register_spi_devices(master, op->node);
467 dev_info(&ms->master->dev, "registered MPC5200 SPI bus\n");
468
469 return rc;
470
471 err_register:
472 dev_err(&ms->master->dev, "initialization failed\n");
473 spi_master_put(master);
474 err_alloc:
475 err_init:
476 iounmap(regs);
477 return rc;
478}
479
480static int __devexit mpc52xx_spi_remove(struct of_device *op)
481{
482 struct spi_master *master = dev_get_drvdata(&op->dev);
483 struct mpc52xx_spi *ms = spi_master_get_devdata(master);
484
485 free_irq(ms->irq0, ms);
486 free_irq(ms->irq1, ms);
487
488 spi_unregister_master(master);
489 spi_master_put(master);
490 iounmap(ms->regs);
491
492 return 0;
493}
494
495static struct of_device_id mpc52xx_spi_match[] __devinitdata = {
496 { .compatible = "fsl,mpc5200-spi", },
497 {}
498};
499MODULE_DEVICE_TABLE(of, mpc52xx_spi_match);
500
501static struct of_platform_driver mpc52xx_spi_of_driver = {
502 .owner = THIS_MODULE,
503 .name = "mpc52xx-spi",
504 .match_table = mpc52xx_spi_match,
505 .probe = mpc52xx_spi_probe,
506 .remove = __exit_p(mpc52xx_spi_remove),
507};
508
509static int __init mpc52xx_spi_init(void)
510{
511 return of_register_platform_driver(&mpc52xx_spi_of_driver);
512}
513module_init(mpc52xx_spi_init);
514
515static void __exit mpc52xx_spi_exit(void)
516{
517 of_unregister_platform_driver(&mpc52xx_spi_of_driver);
518}
519module_exit(mpc52xx_spi_exit);
520
diff --git a/drivers/spi/spi_mpc8xxx.c b/drivers/spi/spi_mpc8xxx.c
index 0fd0ec4d3a7d..930135dc73ba 100644
--- a/drivers/spi/spi_mpc8xxx.c
+++ b/drivers/spi/spi_mpc8xxx.c
@@ -5,6 +5,10 @@
5 * 5 *
6 * Copyright (C) 2006 Polycom, Inc. 6 * Copyright (C) 2006 Polycom, Inc.
7 * 7 *
8 * CPM SPI and QE buffer descriptors mode support:
9 * Copyright (c) 2009 MontaVista Software, Inc.
10 * Author: Anton Vorontsov <avorontsov@ru.mvista.com>
11 *
8 * This program is free software; you can redistribute it and/or modify it 12 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the 13 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your 14 * Free Software Foundation; either version 2 of the License, or (at your
@@ -27,6 +31,9 @@
27#include <linux/spi/spi_bitbang.h> 31#include <linux/spi/spi_bitbang.h>
28#include <linux/platform_device.h> 32#include <linux/platform_device.h>
29#include <linux/fsl_devices.h> 33#include <linux/fsl_devices.h>
34#include <linux/dma-mapping.h>
35#include <linux/mm.h>
36#include <linux/mutex.h>
30#include <linux/of.h> 37#include <linux/of.h>
31#include <linux/of_platform.h> 38#include <linux/of_platform.h>
32#include <linux/gpio.h> 39#include <linux/gpio.h>
@@ -34,8 +41,19 @@
34#include <linux/of_spi.h> 41#include <linux/of_spi.h>
35 42
36#include <sysdev/fsl_soc.h> 43#include <sysdev/fsl_soc.h>
44#include <asm/cpm.h>
45#include <asm/qe.h>
37#include <asm/irq.h> 46#include <asm/irq.h>
38 47
48/* CPM1 and CPM2 are mutually exclusive. */
49#ifdef CONFIG_CPM1
50#include <asm/cpm1.h>
51#define CPM_SPI_CMD mk_cr_cmd(CPM_CR_CH_SPI, 0)
52#else
53#include <asm/cpm2.h>
54#define CPM_SPI_CMD mk_cr_cmd(CPM_CR_SPI_PAGE, CPM_CR_SPI_SBLOCK, 0, 0)
55#endif
56
39/* SPI Controller registers */ 57/* SPI Controller registers */
40struct mpc8xxx_spi_reg { 58struct mpc8xxx_spi_reg {
41 u8 res1[0x20]; 59 u8 res1[0x20];
@@ -47,6 +65,28 @@ struct mpc8xxx_spi_reg {
47 __be32 receive; 65 __be32 receive;
48}; 66};
49 67
68/* SPI Parameter RAM */
69struct spi_pram {
70 __be16 rbase; /* Rx Buffer descriptor base address */
71 __be16 tbase; /* Tx Buffer descriptor base address */
72 u8 rfcr; /* Rx function code */
73 u8 tfcr; /* Tx function code */
74 __be16 mrblr; /* Max receive buffer length */
75 __be32 rstate; /* Internal */
76 __be32 rdp; /* Internal */
77 __be16 rbptr; /* Internal */
78 __be16 rbc; /* Internal */
79 __be32 rxtmp; /* Internal */
80 __be32 tstate; /* Internal */
81 __be32 tdp; /* Internal */
82 __be16 tbptr; /* Internal */
83 __be16 tbc; /* Internal */
84 __be32 txtmp; /* Internal */
85 __be32 res; /* Tx temp. */
86 __be16 rpbase; /* Relocation pointer (CPM1 only) */
87 __be16 res1; /* Reserved */
88};
89
50/* SPI Controller mode register definitions */ 90/* SPI Controller mode register definitions */
51#define SPMODE_LOOP (1 << 30) 91#define SPMODE_LOOP (1 << 30)
52#define SPMODE_CI_INACTIVEHIGH (1 << 29) 92#define SPMODE_CI_INACTIVEHIGH (1 << 29)
@@ -75,14 +115,40 @@ struct mpc8xxx_spi_reg {
75#define SPIM_NE 0x00000200 /* Not empty */ 115#define SPIM_NE 0x00000200 /* Not empty */
76#define SPIM_NF 0x00000100 /* Not full */ 116#define SPIM_NF 0x00000100 /* Not full */
77 117
118#define SPIE_TXB 0x00000200 /* Last char is written to tx fifo */
119#define SPIE_RXB 0x00000100 /* Last char is written to rx buf */
120
121/* SPCOM register values */
122#define SPCOM_STR (1 << 23) /* Start transmit */
123
124#define SPI_PRAM_SIZE 0x100
125#define SPI_MRBLR ((unsigned int)PAGE_SIZE)
126
78/* SPI Controller driver's private data. */ 127/* SPI Controller driver's private data. */
79struct mpc8xxx_spi { 128struct mpc8xxx_spi {
129 struct device *dev;
80 struct mpc8xxx_spi_reg __iomem *base; 130 struct mpc8xxx_spi_reg __iomem *base;
81 131
82 /* rx & tx bufs from the spi_transfer */ 132 /* rx & tx bufs from the spi_transfer */
83 const void *tx; 133 const void *tx;
84 void *rx; 134 void *rx;
85 135
136 int subblock;
137 struct spi_pram __iomem *pram;
138 struct cpm_buf_desc __iomem *tx_bd;
139 struct cpm_buf_desc __iomem *rx_bd;
140
141 struct spi_transfer *xfer_in_progress;
142
143 /* dma addresses for CPM transfers */
144 dma_addr_t tx_dma;
145 dma_addr_t rx_dma;
146 bool map_tx_dma;
147 bool map_rx_dma;
148
149 dma_addr_t dma_dummy_tx;
150 dma_addr_t dma_dummy_rx;
151
86 /* functions to deal with different sized buffers */ 152 /* functions to deal with different sized buffers */
87 void (*get_rx) (u32 rx_data, struct mpc8xxx_spi *); 153 void (*get_rx) (u32 rx_data, struct mpc8xxx_spi *);
88 u32(*get_tx) (struct mpc8xxx_spi *); 154 u32(*get_tx) (struct mpc8xxx_spi *);
@@ -96,7 +162,7 @@ struct mpc8xxx_spi {
96 u32 rx_shift; /* RX data reg shift when in qe mode */ 162 u32 rx_shift; /* RX data reg shift when in qe mode */
97 u32 tx_shift; /* TX data reg shift when in qe mode */ 163 u32 tx_shift; /* TX data reg shift when in qe mode */
98 164
99 bool qe_mode; 165 unsigned int flags;
100 166
101 struct workqueue_struct *workqueue; 167 struct workqueue_struct *workqueue;
102 struct work_struct work; 168 struct work_struct work;
@@ -107,6 +173,10 @@ struct mpc8xxx_spi {
107 struct completion done; 173 struct completion done;
108}; 174};
109 175
176static void *mpc8xxx_dummy_rx;
177static DEFINE_MUTEX(mpc8xxx_dummy_rx_lock);
178static int mpc8xxx_dummy_rx_refcnt;
179
110struct spi_mpc8xxx_cs { 180struct spi_mpc8xxx_cs {
111 /* functions to deal with different sized buffers */ 181 /* functions to deal with different sized buffers */
112 void (*get_rx) (u32 rx_data, struct mpc8xxx_spi *); 182 void (*get_rx) (u32 rx_data, struct mpc8xxx_spi *);
@@ -155,6 +225,42 @@ MPC83XX_SPI_TX_BUF(u8)
155MPC83XX_SPI_TX_BUF(u16) 225MPC83XX_SPI_TX_BUF(u16)
156MPC83XX_SPI_TX_BUF(u32) 226MPC83XX_SPI_TX_BUF(u32)
157 227
228static void mpc8xxx_spi_change_mode(struct spi_device *spi)
229{
230 struct mpc8xxx_spi *mspi = spi_master_get_devdata(spi->master);
231 struct spi_mpc8xxx_cs *cs = spi->controller_state;
232 __be32 __iomem *mode = &mspi->base->mode;
233 unsigned long flags;
234
235 if (cs->hw_mode == mpc8xxx_spi_read_reg(mode))
236 return;
237
238 /* Turn off IRQs locally to minimize time that SPI is disabled. */
239 local_irq_save(flags);
240
241 /* Turn off SPI unit prior changing mode */
242 mpc8xxx_spi_write_reg(mode, cs->hw_mode & ~SPMODE_ENABLE);
243 mpc8xxx_spi_write_reg(mode, cs->hw_mode);
244
245 /* When in CPM mode, we need to reinit tx and rx. */
246 if (mspi->flags & SPI_CPM_MODE) {
247 if (mspi->flags & SPI_QE) {
248 qe_issue_cmd(QE_INIT_TX_RX, mspi->subblock,
249 QE_CR_PROTOCOL_UNSPECIFIED, 0);
250 } else {
251 cpm_command(CPM_SPI_CMD, CPM_CR_INIT_TRX);
252 if (mspi->flags & SPI_CPM1) {
253 out_be16(&mspi->pram->rbptr,
254 in_be16(&mspi->pram->rbase));
255 out_be16(&mspi->pram->tbptr,
256 in_be16(&mspi->pram->tbase));
257 }
258 }
259 }
260
261 local_irq_restore(flags);
262}
263
158static void mpc8xxx_spi_chipselect(struct spi_device *spi, int value) 264static void mpc8xxx_spi_chipselect(struct spi_device *spi, int value)
159{ 265{
160 struct mpc8xxx_spi *mpc8xxx_spi = spi_master_get_devdata(spi->master); 266 struct mpc8xxx_spi *mpc8xxx_spi = spi_master_get_devdata(spi->master);
@@ -168,27 +274,13 @@ static void mpc8xxx_spi_chipselect(struct spi_device *spi, int value)
168 } 274 }
169 275
170 if (value == BITBANG_CS_ACTIVE) { 276 if (value == BITBANG_CS_ACTIVE) {
171 u32 regval = mpc8xxx_spi_read_reg(&mpc8xxx_spi->base->mode);
172
173 mpc8xxx_spi->rx_shift = cs->rx_shift; 277 mpc8xxx_spi->rx_shift = cs->rx_shift;
174 mpc8xxx_spi->tx_shift = cs->tx_shift; 278 mpc8xxx_spi->tx_shift = cs->tx_shift;
175 mpc8xxx_spi->get_rx = cs->get_rx; 279 mpc8xxx_spi->get_rx = cs->get_rx;
176 mpc8xxx_spi->get_tx = cs->get_tx; 280 mpc8xxx_spi->get_tx = cs->get_tx;
177 281
178 if (cs->hw_mode != regval) { 282 mpc8xxx_spi_change_mode(spi);
179 unsigned long flags; 283
180 __be32 __iomem *mode = &mpc8xxx_spi->base->mode;
181
182 regval = cs->hw_mode;
183 /* Turn off IRQs locally to minimize time that
184 * SPI is disabled
185 */
186 local_irq_save(flags);
187 /* Turn off SPI unit prior changing mode */
188 mpc8xxx_spi_write_reg(mode, regval & ~SPMODE_ENABLE);
189 mpc8xxx_spi_write_reg(mode, regval);
190 local_irq_restore(flags);
191 }
192 if (pdata->cs_control) 284 if (pdata->cs_control)
193 pdata->cs_control(spi, pol); 285 pdata->cs_control(spi, pol);
194 } 286 }
@@ -198,7 +290,6 @@ static
198int mpc8xxx_spi_setup_transfer(struct spi_device *spi, struct spi_transfer *t) 290int mpc8xxx_spi_setup_transfer(struct spi_device *spi, struct spi_transfer *t)
199{ 291{
200 struct mpc8xxx_spi *mpc8xxx_spi; 292 struct mpc8xxx_spi *mpc8xxx_spi;
201 u32 regval;
202 u8 bits_per_word, pm; 293 u8 bits_per_word, pm;
203 u32 hz; 294 u32 hz;
204 struct spi_mpc8xxx_cs *cs = spi->controller_state; 295 struct spi_mpc8xxx_cs *cs = spi->controller_state;
@@ -230,14 +321,14 @@ int mpc8xxx_spi_setup_transfer(struct spi_device *spi, struct spi_transfer *t)
230 if (bits_per_word <= 8) { 321 if (bits_per_word <= 8) {
231 cs->get_rx = mpc8xxx_spi_rx_buf_u8; 322 cs->get_rx = mpc8xxx_spi_rx_buf_u8;
232 cs->get_tx = mpc8xxx_spi_tx_buf_u8; 323 cs->get_tx = mpc8xxx_spi_tx_buf_u8;
233 if (mpc8xxx_spi->qe_mode) { 324 if (mpc8xxx_spi->flags & SPI_QE_CPU_MODE) {
234 cs->rx_shift = 16; 325 cs->rx_shift = 16;
235 cs->tx_shift = 24; 326 cs->tx_shift = 24;
236 } 327 }
237 } else if (bits_per_word <= 16) { 328 } else if (bits_per_word <= 16) {
238 cs->get_rx = mpc8xxx_spi_rx_buf_u16; 329 cs->get_rx = mpc8xxx_spi_rx_buf_u16;
239 cs->get_tx = mpc8xxx_spi_tx_buf_u16; 330 cs->get_tx = mpc8xxx_spi_tx_buf_u16;
240 if (mpc8xxx_spi->qe_mode) { 331 if (mpc8xxx_spi->flags & SPI_QE_CPU_MODE) {
241 cs->rx_shift = 16; 332 cs->rx_shift = 16;
242 cs->tx_shift = 16; 333 cs->tx_shift = 16;
243 } 334 }
@@ -247,7 +338,8 @@ int mpc8xxx_spi_setup_transfer(struct spi_device *spi, struct spi_transfer *t)
247 } else 338 } else
248 return -EINVAL; 339 return -EINVAL;
249 340
250 if (mpc8xxx_spi->qe_mode && spi->mode & SPI_LSB_FIRST) { 341 if (mpc8xxx_spi->flags & SPI_QE_CPU_MODE &&
342 spi->mode & SPI_LSB_FIRST) {
251 cs->tx_shift = 0; 343 cs->tx_shift = 0;
252 if (bits_per_word <= 8) 344 if (bits_per_word <= 8)
253 cs->rx_shift = 8; 345 cs->rx_shift = 8;
@@ -286,37 +378,138 @@ int mpc8xxx_spi_setup_transfer(struct spi_device *spi, struct spi_transfer *t)
286 pm--; 378 pm--;
287 379
288 cs->hw_mode |= SPMODE_PM(pm); 380 cs->hw_mode |= SPMODE_PM(pm);
289 regval = mpc8xxx_spi_read_reg(&mpc8xxx_spi->base->mode); 381
290 if (cs->hw_mode != regval) { 382 mpc8xxx_spi_change_mode(spi);
291 unsigned long flags; 383 return 0;
292 __be32 __iomem *mode = &mpc8xxx_spi->base->mode; 384}
293 385
294 regval = cs->hw_mode; 386static void mpc8xxx_spi_cpm_bufs_start(struct mpc8xxx_spi *mspi)
295 /* Turn off IRQs locally to minimize time 387{
296 * that SPI is disabled 388 struct cpm_buf_desc __iomem *tx_bd = mspi->tx_bd;
297 */ 389 struct cpm_buf_desc __iomem *rx_bd = mspi->rx_bd;
298 local_irq_save(flags); 390 unsigned int xfer_len = min(mspi->count, SPI_MRBLR);
299 /* Turn off SPI unit prior changing mode */ 391 unsigned int xfer_ofs;
300 mpc8xxx_spi_write_reg(mode, regval & ~SPMODE_ENABLE); 392
301 mpc8xxx_spi_write_reg(mode, regval); 393 xfer_ofs = mspi->xfer_in_progress->len - mspi->count;
302 local_irq_restore(flags); 394
395 out_be32(&rx_bd->cbd_bufaddr, mspi->rx_dma + xfer_ofs);
396 out_be16(&rx_bd->cbd_datlen, 0);
397 out_be16(&rx_bd->cbd_sc, BD_SC_EMPTY | BD_SC_INTRPT | BD_SC_WRAP);
398
399 out_be32(&tx_bd->cbd_bufaddr, mspi->tx_dma + xfer_ofs);
400 out_be16(&tx_bd->cbd_datlen, xfer_len);
401 out_be16(&tx_bd->cbd_sc, BD_SC_READY | BD_SC_INTRPT | BD_SC_WRAP |
402 BD_SC_LAST);
403
404 /* start transfer */
405 mpc8xxx_spi_write_reg(&mspi->base->command, SPCOM_STR);
406}
407
408static int mpc8xxx_spi_cpm_bufs(struct mpc8xxx_spi *mspi,
409 struct spi_transfer *t, bool is_dma_mapped)
410{
411 struct device *dev = mspi->dev;
412
413 if (is_dma_mapped) {
414 mspi->map_tx_dma = 0;
415 mspi->map_rx_dma = 0;
416 } else {
417 mspi->map_tx_dma = 1;
418 mspi->map_rx_dma = 1;
419 }
420
421 if (!t->tx_buf) {
422 mspi->tx_dma = mspi->dma_dummy_tx;
423 mspi->map_tx_dma = 0;
424 }
425
426 if (!t->rx_buf) {
427 mspi->rx_dma = mspi->dma_dummy_rx;
428 mspi->map_rx_dma = 0;
303 } 429 }
430
431 if (mspi->map_tx_dma) {
432 void *nonconst_tx = (void *)mspi->tx; /* shut up gcc */
433
434 mspi->tx_dma = dma_map_single(dev, nonconst_tx, t->len,
435 DMA_TO_DEVICE);
436 if (dma_mapping_error(dev, mspi->tx_dma)) {
437 dev_err(dev, "unable to map tx dma\n");
438 return -ENOMEM;
439 }
440 } else {
441 mspi->tx_dma = t->tx_dma;
442 }
443
444 if (mspi->map_rx_dma) {
445 mspi->rx_dma = dma_map_single(dev, mspi->rx, t->len,
446 DMA_FROM_DEVICE);
447 if (dma_mapping_error(dev, mspi->rx_dma)) {
448 dev_err(dev, "unable to map rx dma\n");
449 goto err_rx_dma;
450 }
451 } else {
452 mspi->rx_dma = t->rx_dma;
453 }
454
455 /* enable rx ints */
456 mpc8xxx_spi_write_reg(&mspi->base->mask, SPIE_RXB);
457
458 mspi->xfer_in_progress = t;
459 mspi->count = t->len;
460
461 /* start CPM transfers */
462 mpc8xxx_spi_cpm_bufs_start(mspi);
463
304 return 0; 464 return 0;
465
466err_rx_dma:
467 if (mspi->map_tx_dma)
468 dma_unmap_single(dev, mspi->tx_dma, t->len, DMA_TO_DEVICE);
469 return -ENOMEM;
305} 470}
306 471
307static int mpc8xxx_spi_bufs(struct spi_device *spi, struct spi_transfer *t) 472static void mpc8xxx_spi_cpm_bufs_complete(struct mpc8xxx_spi *mspi)
308{ 473{
309 struct mpc8xxx_spi *mpc8xxx_spi; 474 struct device *dev = mspi->dev;
310 u32 word, len, bits_per_word; 475 struct spi_transfer *t = mspi->xfer_in_progress;
476
477 if (mspi->map_tx_dma)
478 dma_unmap_single(dev, mspi->tx_dma, t->len, DMA_TO_DEVICE);
479 if (mspi->map_tx_dma)
480 dma_unmap_single(dev, mspi->rx_dma, t->len, DMA_FROM_DEVICE);
481 mspi->xfer_in_progress = NULL;
482}
311 483
312 mpc8xxx_spi = spi_master_get_devdata(spi->master); 484static int mpc8xxx_spi_cpu_bufs(struct mpc8xxx_spi *mspi,
485 struct spi_transfer *t, unsigned int len)
486{
487 u32 word;
488
489 mspi->count = len;
490
491 /* enable rx ints */
492 mpc8xxx_spi_write_reg(&mspi->base->mask, SPIM_NE);
493
494 /* transmit word */
495 word = mspi->get_tx(mspi);
496 mpc8xxx_spi_write_reg(&mspi->base->transmit, word);
497
498 return 0;
499}
500
501static int mpc8xxx_spi_bufs(struct spi_device *spi, struct spi_transfer *t,
502 bool is_dma_mapped)
503{
504 struct mpc8xxx_spi *mpc8xxx_spi = spi_master_get_devdata(spi->master);
505 unsigned int len = t->len;
506 u8 bits_per_word;
507 int ret;
313 508
314 mpc8xxx_spi->tx = t->tx_buf;
315 mpc8xxx_spi->rx = t->rx_buf;
316 bits_per_word = spi->bits_per_word; 509 bits_per_word = spi->bits_per_word;
317 if (t->bits_per_word) 510 if (t->bits_per_word)
318 bits_per_word = t->bits_per_word; 511 bits_per_word = t->bits_per_word;
319 len = t->len; 512
320 if (bits_per_word > 8) { 513 if (bits_per_word > 8) {
321 /* invalid length? */ 514 /* invalid length? */
322 if (len & 1) 515 if (len & 1)
@@ -329,22 +522,27 @@ static int mpc8xxx_spi_bufs(struct spi_device *spi, struct spi_transfer *t)
329 return -EINVAL; 522 return -EINVAL;
330 len /= 2; 523 len /= 2;
331 } 524 }
332 mpc8xxx_spi->count = len;
333 525
334 INIT_COMPLETION(mpc8xxx_spi->done); 526 mpc8xxx_spi->tx = t->tx_buf;
527 mpc8xxx_spi->rx = t->rx_buf;
335 528
336 /* enable rx ints */ 529 INIT_COMPLETION(mpc8xxx_spi->done);
337 mpc8xxx_spi_write_reg(&mpc8xxx_spi->base->mask, SPIM_NE);
338 530
339 /* transmit word */ 531 if (mpc8xxx_spi->flags & SPI_CPM_MODE)
340 word = mpc8xxx_spi->get_tx(mpc8xxx_spi); 532 ret = mpc8xxx_spi_cpm_bufs(mpc8xxx_spi, t, is_dma_mapped);
341 mpc8xxx_spi_write_reg(&mpc8xxx_spi->base->transmit, word); 533 else
534 ret = mpc8xxx_spi_cpu_bufs(mpc8xxx_spi, t, len);
535 if (ret)
536 return ret;
342 537
343 wait_for_completion(&mpc8xxx_spi->done); 538 wait_for_completion(&mpc8xxx_spi->done);
344 539
345 /* disable rx ints */ 540 /* disable rx ints */
346 mpc8xxx_spi_write_reg(&mpc8xxx_spi->base->mask, 0); 541 mpc8xxx_spi_write_reg(&mpc8xxx_spi->base->mask, 0);
347 542
543 if (mpc8xxx_spi->flags & SPI_CPM_MODE)
544 mpc8xxx_spi_cpm_bufs_complete(mpc8xxx_spi);
545
348 return mpc8xxx_spi->count; 546 return mpc8xxx_spi->count;
349} 547}
350 548
@@ -375,7 +573,7 @@ static void mpc8xxx_spi_do_one_msg(struct spi_message *m)
375 } 573 }
376 cs_change = t->cs_change; 574 cs_change = t->cs_change;
377 if (t->len) 575 if (t->len)
378 status = mpc8xxx_spi_bufs(spi, t); 576 status = mpc8xxx_spi_bufs(spi, t, m->is_dma_mapped);
379 if (status) { 577 if (status) {
380 status = -EMSGSIZE; 578 status = -EMSGSIZE;
381 break; 579 break;
@@ -464,45 +662,80 @@ static int mpc8xxx_spi_setup(struct spi_device *spi)
464 return 0; 662 return 0;
465} 663}
466 664
467static irqreturn_t mpc8xxx_spi_irq(s32 irq, void *context_data) 665static void mpc8xxx_spi_cpm_irq(struct mpc8xxx_spi *mspi, u32 events)
468{ 666{
469 struct mpc8xxx_spi *mpc8xxx_spi = context_data; 667 u16 len;
470 u32 event;
471 irqreturn_t ret = IRQ_NONE;
472 668
473 /* Get interrupt events(tx/rx) */ 669 dev_dbg(mspi->dev, "%s: bd datlen %d, count %d\n", __func__,
474 event = mpc8xxx_spi_read_reg(&mpc8xxx_spi->base->event); 670 in_be16(&mspi->rx_bd->cbd_datlen), mspi->count);
475 671
476 /* We need handle RX first */ 672 len = in_be16(&mspi->rx_bd->cbd_datlen);
477 if (event & SPIE_NE) { 673 if (len > mspi->count) {
478 u32 rx_data = mpc8xxx_spi_read_reg(&mpc8xxx_spi->base->receive); 674 WARN_ON(1);
675 len = mspi->count;
676 }
479 677
480 if (mpc8xxx_spi->rx) 678 /* Clear the events */
481 mpc8xxx_spi->get_rx(rx_data, mpc8xxx_spi); 679 mpc8xxx_spi_write_reg(&mspi->base->event, events);
482 680
483 ret = IRQ_HANDLED; 681 mspi->count -= len;
682 if (mspi->count)
683 mpc8xxx_spi_cpm_bufs_start(mspi);
684 else
685 complete(&mspi->done);
686}
687
688static void mpc8xxx_spi_cpu_irq(struct mpc8xxx_spi *mspi, u32 events)
689{
690 /* We need handle RX first */
691 if (events & SPIE_NE) {
692 u32 rx_data = mpc8xxx_spi_read_reg(&mspi->base->receive);
693
694 if (mspi->rx)
695 mspi->get_rx(rx_data, mspi);
484 } 696 }
485 697
486 if ((event & SPIE_NF) == 0) 698 if ((events & SPIE_NF) == 0)
487 /* spin until TX is done */ 699 /* spin until TX is done */
488 while (((event = 700 while (((events =
489 mpc8xxx_spi_read_reg(&mpc8xxx_spi->base->event)) & 701 mpc8xxx_spi_read_reg(&mspi->base->event)) &
490 SPIE_NF) == 0) 702 SPIE_NF) == 0)
491 cpu_relax(); 703 cpu_relax();
492 704
493 mpc8xxx_spi->count -= 1; 705 /* Clear the events */
494 if (mpc8xxx_spi->count) { 706 mpc8xxx_spi_write_reg(&mspi->base->event, events);
495 u32 word = mpc8xxx_spi->get_tx(mpc8xxx_spi); 707
496 mpc8xxx_spi_write_reg(&mpc8xxx_spi->base->transmit, word); 708 mspi->count -= 1;
709 if (mspi->count) {
710 u32 word = mspi->get_tx(mspi);
711
712 mpc8xxx_spi_write_reg(&mspi->base->transmit, word);
497 } else { 713 } else {
498 complete(&mpc8xxx_spi->done); 714 complete(&mspi->done);
499 } 715 }
716}
500 717
501 /* Clear the events */ 718static irqreturn_t mpc8xxx_spi_irq(s32 irq, void *context_data)
502 mpc8xxx_spi_write_reg(&mpc8xxx_spi->base->event, event); 719{
720 struct mpc8xxx_spi *mspi = context_data;
721 irqreturn_t ret = IRQ_NONE;
722 u32 events;
723
724 /* Get interrupt events(tx/rx) */
725 events = mpc8xxx_spi_read_reg(&mspi->base->event);
726 if (events)
727 ret = IRQ_HANDLED;
728
729 dev_dbg(mspi->dev, "%s: events %x\n", __func__, events);
730
731 if (mspi->flags & SPI_CPM_MODE)
732 mpc8xxx_spi_cpm_irq(mspi, events);
733 else
734 mpc8xxx_spi_cpu_irq(mspi, events);
503 735
504 return ret; 736 return ret;
505} 737}
738
506static int mpc8xxx_spi_transfer(struct spi_device *spi, 739static int mpc8xxx_spi_transfer(struct spi_device *spi,
507 struct spi_message *m) 740 struct spi_message *m)
508{ 741{
@@ -526,6 +759,215 @@ static void mpc8xxx_spi_cleanup(struct spi_device *spi)
526 kfree(spi->controller_state); 759 kfree(spi->controller_state);
527} 760}
528 761
762static void *mpc8xxx_spi_alloc_dummy_rx(void)
763{
764 mutex_lock(&mpc8xxx_dummy_rx_lock);
765
766 if (!mpc8xxx_dummy_rx)
767 mpc8xxx_dummy_rx = kmalloc(SPI_MRBLR, GFP_KERNEL);
768 if (mpc8xxx_dummy_rx)
769 mpc8xxx_dummy_rx_refcnt++;
770
771 mutex_unlock(&mpc8xxx_dummy_rx_lock);
772
773 return mpc8xxx_dummy_rx;
774}
775
776static void mpc8xxx_spi_free_dummy_rx(void)
777{
778 mutex_lock(&mpc8xxx_dummy_rx_lock);
779
780 switch (mpc8xxx_dummy_rx_refcnt) {
781 case 0:
782 WARN_ON(1);
783 break;
784 case 1:
785 kfree(mpc8xxx_dummy_rx);
786 mpc8xxx_dummy_rx = NULL;
787 /* fall through */
788 default:
789 mpc8xxx_dummy_rx_refcnt--;
790 break;
791 }
792
793 mutex_unlock(&mpc8xxx_dummy_rx_lock);
794}
795
796static unsigned long mpc8xxx_spi_cpm_get_pram(struct mpc8xxx_spi *mspi)
797{
798 struct device *dev = mspi->dev;
799 struct device_node *np = dev_archdata_get_node(&dev->archdata);
800 const u32 *iprop;
801 int size;
802 unsigned long spi_base_ofs;
803 unsigned long pram_ofs = -ENOMEM;
804
805 /* Can't use of_address_to_resource(), QE muram isn't at 0. */
806 iprop = of_get_property(np, "reg", &size);
807
808 /* QE with a fixed pram location? */
809 if (mspi->flags & SPI_QE && iprop && size == sizeof(*iprop) * 4)
810 return cpm_muram_alloc_fixed(iprop[2], SPI_PRAM_SIZE);
811
812 /* QE but with a dynamic pram location? */
813 if (mspi->flags & SPI_QE) {
814 pram_ofs = cpm_muram_alloc(SPI_PRAM_SIZE, 64);
815 qe_issue_cmd(QE_ASSIGN_PAGE_TO_DEVICE, mspi->subblock,
816 QE_CR_PROTOCOL_UNSPECIFIED, pram_ofs);
817 return pram_ofs;
818 }
819
820 /* CPM1 and CPM2 pram must be at a fixed addr. */
821 if (!iprop || size != sizeof(*iprop) * 4)
822 return -ENOMEM;
823
824 spi_base_ofs = cpm_muram_alloc_fixed(iprop[2], 2);
825 if (IS_ERR_VALUE(spi_base_ofs))
826 return -ENOMEM;
827
828 if (mspi->flags & SPI_CPM2) {
829 pram_ofs = cpm_muram_alloc(SPI_PRAM_SIZE, 64);
830 if (!IS_ERR_VALUE(pram_ofs)) {
831 u16 __iomem *spi_base = cpm_muram_addr(spi_base_ofs);
832
833 out_be16(spi_base, pram_ofs);
834 }
835 } else {
836 struct spi_pram __iomem *pram = cpm_muram_addr(spi_base_ofs);
837 u16 rpbase = in_be16(&pram->rpbase);
838
839 /* Microcode relocation patch applied? */
840 if (rpbase)
841 pram_ofs = rpbase;
842 else
843 return spi_base_ofs;
844 }
845
846 cpm_muram_free(spi_base_ofs);
847 return pram_ofs;
848}
849
850static int mpc8xxx_spi_cpm_init(struct mpc8xxx_spi *mspi)
851{
852 struct device *dev = mspi->dev;
853 struct device_node *np = dev_archdata_get_node(&dev->archdata);
854 const u32 *iprop;
855 int size;
856 unsigned long pram_ofs;
857 unsigned long bds_ofs;
858
859 if (!(mspi->flags & SPI_CPM_MODE))
860 return 0;
861
862 if (!mpc8xxx_spi_alloc_dummy_rx())
863 return -ENOMEM;
864
865 if (mspi->flags & SPI_QE) {
866 iprop = of_get_property(np, "cell-index", &size);
867 if (iprop && size == sizeof(*iprop))
868 mspi->subblock = *iprop;
869
870 switch (mspi->subblock) {
871 default:
872 dev_warn(dev, "cell-index unspecified, assuming SPI1");
873 /* fall through */
874 case 0:
875 mspi->subblock = QE_CR_SUBBLOCK_SPI1;
876 break;
877 case 1:
878 mspi->subblock = QE_CR_SUBBLOCK_SPI2;
879 break;
880 }
881 }
882
883 pram_ofs = mpc8xxx_spi_cpm_get_pram(mspi);
884 if (IS_ERR_VALUE(pram_ofs)) {
885 dev_err(dev, "can't allocate spi parameter ram\n");
886 goto err_pram;
887 }
888
889 bds_ofs = cpm_muram_alloc(sizeof(*mspi->tx_bd) +
890 sizeof(*mspi->rx_bd), 8);
891 if (IS_ERR_VALUE(bds_ofs)) {
892 dev_err(dev, "can't allocate bds\n");
893 goto err_bds;
894 }
895
896 mspi->dma_dummy_tx = dma_map_single(dev, empty_zero_page, PAGE_SIZE,
897 DMA_TO_DEVICE);
898 if (dma_mapping_error(dev, mspi->dma_dummy_tx)) {
899 dev_err(dev, "unable to map dummy tx buffer\n");
900 goto err_dummy_tx;
901 }
902
903 mspi->dma_dummy_rx = dma_map_single(dev, mpc8xxx_dummy_rx, SPI_MRBLR,
904 DMA_FROM_DEVICE);
905 if (dma_mapping_error(dev, mspi->dma_dummy_rx)) {
906 dev_err(dev, "unable to map dummy rx buffer\n");
907 goto err_dummy_rx;
908 }
909
910 mspi->pram = cpm_muram_addr(pram_ofs);
911
912 mspi->tx_bd = cpm_muram_addr(bds_ofs);
913 mspi->rx_bd = cpm_muram_addr(bds_ofs + sizeof(*mspi->tx_bd));
914
915 /* Initialize parameter ram. */
916 out_be16(&mspi->pram->tbase, cpm_muram_offset(mspi->tx_bd));
917 out_be16(&mspi->pram->rbase, cpm_muram_offset(mspi->rx_bd));
918 out_8(&mspi->pram->tfcr, CPMFCR_EB | CPMFCR_GBL);
919 out_8(&mspi->pram->rfcr, CPMFCR_EB | CPMFCR_GBL);
920 out_be16(&mspi->pram->mrblr, SPI_MRBLR);
921 out_be32(&mspi->pram->rstate, 0);
922 out_be32(&mspi->pram->rdp, 0);
923 out_be16(&mspi->pram->rbptr, 0);
924 out_be16(&mspi->pram->rbc, 0);
925 out_be32(&mspi->pram->rxtmp, 0);
926 out_be32(&mspi->pram->tstate, 0);
927 out_be32(&mspi->pram->tdp, 0);
928 out_be16(&mspi->pram->tbptr, 0);
929 out_be16(&mspi->pram->tbc, 0);
930 out_be32(&mspi->pram->txtmp, 0);
931
932 return 0;
933
934err_dummy_rx:
935 dma_unmap_single(dev, mspi->dma_dummy_tx, PAGE_SIZE, DMA_TO_DEVICE);
936err_dummy_tx:
937 cpm_muram_free(bds_ofs);
938err_bds:
939 cpm_muram_free(pram_ofs);
940err_pram:
941 mpc8xxx_spi_free_dummy_rx();
942 return -ENOMEM;
943}
944
945static void mpc8xxx_spi_cpm_free(struct mpc8xxx_spi *mspi)
946{
947 struct device *dev = mspi->dev;
948
949 dma_unmap_single(dev, mspi->dma_dummy_rx, SPI_MRBLR, DMA_FROM_DEVICE);
950 dma_unmap_single(dev, mspi->dma_dummy_tx, PAGE_SIZE, DMA_TO_DEVICE);
951 cpm_muram_free(cpm_muram_offset(mspi->tx_bd));
952 cpm_muram_free(cpm_muram_offset(mspi->pram));
953 mpc8xxx_spi_free_dummy_rx();
954}
955
956static const char *mpc8xxx_spi_strmode(unsigned int flags)
957{
958 if (flags & SPI_QE_CPU_MODE) {
959 return "QE CPU";
960 } else if (flags & SPI_CPM_MODE) {
961 if (flags & SPI_QE)
962 return "QE";
963 else if (flags & SPI_CPM2)
964 return "CPM2";
965 else
966 return "CPM1";
967 }
968 return "CPU";
969}
970
529static struct spi_master * __devinit 971static struct spi_master * __devinit
530mpc8xxx_spi_probe(struct device *dev, struct resource *mem, unsigned int irq) 972mpc8xxx_spi_probe(struct device *dev, struct resource *mem, unsigned int irq)
531{ 973{
@@ -552,14 +994,19 @@ mpc8xxx_spi_probe(struct device *dev, struct resource *mem, unsigned int irq)
552 master->cleanup = mpc8xxx_spi_cleanup; 994 master->cleanup = mpc8xxx_spi_cleanup;
553 995
554 mpc8xxx_spi = spi_master_get_devdata(master); 996 mpc8xxx_spi = spi_master_get_devdata(master);
555 mpc8xxx_spi->qe_mode = pdata->qe_mode; 997 mpc8xxx_spi->dev = dev;
556 mpc8xxx_spi->get_rx = mpc8xxx_spi_rx_buf_u8; 998 mpc8xxx_spi->get_rx = mpc8xxx_spi_rx_buf_u8;
557 mpc8xxx_spi->get_tx = mpc8xxx_spi_tx_buf_u8; 999 mpc8xxx_spi->get_tx = mpc8xxx_spi_tx_buf_u8;
1000 mpc8xxx_spi->flags = pdata->flags;
558 mpc8xxx_spi->spibrg = pdata->sysclk; 1001 mpc8xxx_spi->spibrg = pdata->sysclk;
559 1002
1003 ret = mpc8xxx_spi_cpm_init(mpc8xxx_spi);
1004 if (ret)
1005 goto err_cpm_init;
1006
560 mpc8xxx_spi->rx_shift = 0; 1007 mpc8xxx_spi->rx_shift = 0;
561 mpc8xxx_spi->tx_shift = 0; 1008 mpc8xxx_spi->tx_shift = 0;
562 if (mpc8xxx_spi->qe_mode) { 1009 if (mpc8xxx_spi->flags & SPI_QE_CPU_MODE) {
563 mpc8xxx_spi->rx_shift = 16; 1010 mpc8xxx_spi->rx_shift = 16;
564 mpc8xxx_spi->tx_shift = 24; 1011 mpc8xxx_spi->tx_shift = 24;
565 } 1012 }
@@ -569,7 +1016,7 @@ mpc8xxx_spi_probe(struct device *dev, struct resource *mem, unsigned int irq)
569 mpc8xxx_spi->base = ioremap(mem->start, mem->end - mem->start + 1); 1016 mpc8xxx_spi->base = ioremap(mem->start, mem->end - mem->start + 1);
570 if (mpc8xxx_spi->base == NULL) { 1017 if (mpc8xxx_spi->base == NULL) {
571 ret = -ENOMEM; 1018 ret = -ENOMEM;
572 goto put_master; 1019 goto err_ioremap;
573 } 1020 }
574 1021
575 mpc8xxx_spi->irq = irq; 1022 mpc8xxx_spi->irq = irq;
@@ -592,7 +1039,7 @@ mpc8xxx_spi_probe(struct device *dev, struct resource *mem, unsigned int irq)
592 1039
593 /* Enable SPI interface */ 1040 /* Enable SPI interface */
594 regval = pdata->initial_spmode | SPMODE_INIT_VAL | SPMODE_ENABLE; 1041 regval = pdata->initial_spmode | SPMODE_INIT_VAL | SPMODE_ENABLE;
595 if (pdata->qe_mode) 1042 if (mpc8xxx_spi->flags & SPI_QE_CPU_MODE)
596 regval |= SPMODE_OP; 1043 regval |= SPMODE_OP;
597 1044
598 mpc8xxx_spi_write_reg(&mpc8xxx_spi->base->mode, regval); 1045 mpc8xxx_spi_write_reg(&mpc8xxx_spi->base->mode, regval);
@@ -612,9 +1059,8 @@ mpc8xxx_spi_probe(struct device *dev, struct resource *mem, unsigned int irq)
612 if (ret < 0) 1059 if (ret < 0)
613 goto unreg_master; 1060 goto unreg_master;
614 1061
615 printk(KERN_INFO 1062 dev_info(dev, "at 0x%p (irq = %d), %s mode\n", mpc8xxx_spi->base,
616 "%s: MPC8xxx SPI Controller driver at 0x%p (irq = %d)\n", 1063 mpc8xxx_spi->irq, mpc8xxx_spi_strmode(mpc8xxx_spi->flags));
617 dev_name(dev), mpc8xxx_spi->base, mpc8xxx_spi->irq);
618 1064
619 return master; 1065 return master;
620 1066
@@ -624,7 +1070,9 @@ free_irq:
624 free_irq(mpc8xxx_spi->irq, mpc8xxx_spi); 1070 free_irq(mpc8xxx_spi->irq, mpc8xxx_spi);
625unmap_io: 1071unmap_io:
626 iounmap(mpc8xxx_spi->base); 1072 iounmap(mpc8xxx_spi->base);
627put_master: 1073err_ioremap:
1074 mpc8xxx_spi_cpm_free(mpc8xxx_spi);
1075err_cpm_init:
628 spi_master_put(master); 1076 spi_master_put(master);
629err: 1077err:
630 return ERR_PTR(ret); 1078 return ERR_PTR(ret);
@@ -644,6 +1092,7 @@ static int __devexit mpc8xxx_spi_remove(struct device *dev)
644 1092
645 free_irq(mpc8xxx_spi->irq, mpc8xxx_spi); 1093 free_irq(mpc8xxx_spi->irq, mpc8xxx_spi);
646 iounmap(mpc8xxx_spi->base); 1094 iounmap(mpc8xxx_spi->base);
1095 mpc8xxx_spi_cpm_free(mpc8xxx_spi);
647 1096
648 return 0; 1097 return 0;
649} 1098}
@@ -709,6 +1158,7 @@ static int of_mpc8xxx_spi_get_chipselects(struct device *dev)
709 gpio = of_get_gpio_flags(np, i, &flags); 1158 gpio = of_get_gpio_flags(np, i, &flags);
710 if (!gpio_is_valid(gpio)) { 1159 if (!gpio_is_valid(gpio)) {
711 dev_err(dev, "invalid gpio #%d: %d\n", i, gpio); 1160 dev_err(dev, "invalid gpio #%d: %d\n", i, gpio);
1161 ret = gpio;
712 goto err_loop; 1162 goto err_loop;
713 } 1163 }
714 1164
@@ -804,7 +1254,13 @@ static int __devinit of_mpc8xxx_spi_probe(struct of_device *ofdev,
804 1254
805 prop = of_get_property(np, "mode", NULL); 1255 prop = of_get_property(np, "mode", NULL);
806 if (prop && !strcmp(prop, "cpu-qe")) 1256 if (prop && !strcmp(prop, "cpu-qe"))
807 pdata->qe_mode = 1; 1257 pdata->flags = SPI_QE_CPU_MODE;
1258 else if (prop && !strcmp(prop, "qe"))
1259 pdata->flags = SPI_CPM_MODE | SPI_QE;
1260 else if (of_device_is_compatible(np, "fsl,cpm2-spi"))
1261 pdata->flags = SPI_CPM_MODE | SPI_CPM2;
1262 else if (of_device_is_compatible(np, "fsl,cpm1-spi"))
1263 pdata->flags = SPI_CPM_MODE | SPI_CPM1;
808 1264
809 ret = of_mpc8xxx_spi_get_chipselects(dev); 1265 ret = of_mpc8xxx_spi_get_chipselects(dev);
810 if (ret) 1266 if (ret)
diff --git a/drivers/spi/xilinx_spi.c b/drivers/spi/xilinx_spi.c
index 46b8c5c2f45e..5a143b9f6361 100644
--- a/drivers/spi/xilinx_spi.c
+++ b/drivers/spi/xilinx_spi.c
@@ -148,7 +148,8 @@ static int xilinx_spi_setup_transfer(struct spi_device *spi,
148{ 148{
149 u8 bits_per_word; 149 u8 bits_per_word;
150 150
151 bits_per_word = (t) ? t->bits_per_word : spi->bits_per_word; 151 bits_per_word = (t && t->bits_per_word)
152 ? t->bits_per_word : spi->bits_per_word;
152 if (bits_per_word != 8) { 153 if (bits_per_word != 8) {
153 dev_err(&spi->dev, "%s, unsupported bits_per_word=%d\n", 154 dev_err(&spi->dev, "%s, unsupported bits_per_word=%d\n",
154 __func__, bits_per_word); 155 __func__, bits_per_word);