aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/spi
diff options
context:
space:
mode:
authorDan Williams <dan.j.williams@intel.com>2009-09-08 20:55:21 -0400
committerDan Williams <dan.j.williams@intel.com>2009-09-08 20:55:21 -0400
commitbbb20089a3275a19e475dbc21320c3742e3ca423 (patch)
tree216fdc1cbef450ca688135c5b8969169482d9a48 /drivers/spi
parent3e48e656903e9fd8bc805c6a2c4264d7808d315b (diff)
parent657a77fa7284d8ae28dfa48f1dc5d919bf5b2843 (diff)
Merge branch 'dmaengine' into async-tx-next
Conflicts: crypto/async_tx/async_xor.c drivers/dma/ioat/dma_v2.h drivers/dma/ioat/pci.c drivers/md/raid5.c
Diffstat (limited to 'drivers/spi')
-rw-r--r--drivers/spi/Kconfig29
-rw-r--r--drivers/spi/Makefile3
-rw-r--r--drivers/spi/amba-pl022.c1866
-rw-r--r--drivers/spi/atmel_spi.c14
-rw-r--r--drivers/spi/au1550_spi.c14
-rw-r--r--drivers/spi/mpc52xx_psc_spi.c34
-rw-r--r--drivers/spi/omap2_mcspi.c16
-rw-r--r--drivers/spi/omap_uwire.c14
-rw-r--r--drivers/spi/orion_spi.c12
-rw-r--r--drivers/spi/pxa2xx_spi.c23
-rw-r--r--drivers/spi/spi.c70
-rw-r--r--drivers/spi/spi_bfin5xx.c19
-rw-r--r--drivers/spi/spi_bitbang.c16
-rw-r--r--drivers/spi/spi_imx.c17
-rw-r--r--drivers/spi/spi_mpc8xxx.c (renamed from drivers/spi/spi_mpc83xx.c)535
-rw-r--r--drivers/spi/spi_s3c24xx.c19
-rw-r--r--drivers/spi/spi_s3c24xx_gpio.c1
-rw-r--r--drivers/spi/spi_txx9.c11
-rw-r--r--drivers/spi/xilinx_spi.c18
19 files changed, 2268 insertions, 463 deletions
diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
index 83a185d52961..2c733c27db2f 100644
--- a/drivers/spi/Kconfig
+++ b/drivers/spi/Kconfig
@@ -118,7 +118,7 @@ config SPI_GPIO
118 118
119config SPI_IMX 119config SPI_IMX
120 tristate "Freescale iMX SPI controller" 120 tristate "Freescale iMX SPI controller"
121 depends on ARCH_IMX && EXPERIMENTAL 121 depends on ARCH_MX1 && EXPERIMENTAL
122 help 122 help
123 This enables using the Freescale iMX SPI controller in master 123 This enables using the Freescale iMX SPI controller in master
124 mode. 124 mode.
@@ -139,17 +139,15 @@ config SPI_MPC52xx_PSC
139 This enables using the Freescale MPC52xx Programmable Serial 139 This enables using the Freescale MPC52xx Programmable Serial
140 Controller in master SPI mode. 140 Controller in master SPI mode.
141 141
142config SPI_MPC83xx 142config SPI_MPC8xxx
143 tristate "Freescale MPC83xx/QUICC Engine SPI controller" 143 tristate "Freescale MPC8xxx SPI controller"
144 depends on (PPC_83xx || QUICC_ENGINE) && EXPERIMENTAL 144 depends on FSL_SOC
145 help 145 help
146 This enables using the Freescale MPC83xx and QUICC Engine SPI 146 This enables using the Freescale MPC8xxx SPI controllers in master
147 controllers in master mode. 147 mode.
148 148
149 Note, this driver uniquely supports the SPI controller on the MPC83xx 149 This driver uses a simple set of shift registers for data (opposed
150 family of PowerPC processors, plus processors with QUICC Engine 150 to the CPM based descriptor model).
151 technology. This driver uses a simple set of shift registers for data
152 (opposed to the CPM based descriptor model).
153 151
154config SPI_OMAP_UWIRE 152config SPI_OMAP_UWIRE
155 tristate "OMAP1 MicroWire" 153 tristate "OMAP1 MicroWire"
@@ -171,6 +169,15 @@ config SPI_ORION
171 help 169 help
172 This enables using the SPI master controller on the Orion chips. 170 This enables using the SPI master controller on the Orion chips.
173 171
172config SPI_PL022
173 tristate "ARM AMBA PL022 SSP controller (EXPERIMENTAL)"
174 depends on ARM_AMBA && EXPERIMENTAL
175 default y if MACH_U300
176 help
177 This selects the ARM(R) AMBA(R) PrimeCell PL022 SSP
178 controller. If you have an embedded system with an AMBA(R)
179 bus and a PL022 controller, say Y or M here.
180
174config SPI_PXA2XX 181config SPI_PXA2XX
175 tristate "PXA2xx SSP SPI master" 182 tristate "PXA2xx SSP SPI master"
176 depends on ARCH_PXA && EXPERIMENTAL 183 depends on ARCH_PXA && EXPERIMENTAL
@@ -212,7 +219,7 @@ config SPI_TXX9
212 219
213config SPI_XILINX 220config SPI_XILINX
214 tristate "Xilinx SPI controller" 221 tristate "Xilinx SPI controller"
215 depends on XILINX_VIRTEX && EXPERIMENTAL 222 depends on (XILINX_VIRTEX || MICROBLAZE) && EXPERIMENTAL
216 select SPI_BITBANG 223 select SPI_BITBANG
217 help 224 help
218 This exposes the SPI controller IP from the Xilinx EDK. 225 This exposes the SPI controller IP from the Xilinx EDK.
diff --git a/drivers/spi/Makefile b/drivers/spi/Makefile
index 5d0451936d86..3de408d294ba 100644
--- a/drivers/spi/Makefile
+++ b/drivers/spi/Makefile
@@ -23,8 +23,9 @@ obj-$(CONFIG_SPI_PXA2XX) += pxa2xx_spi.o
23obj-$(CONFIG_SPI_OMAP_UWIRE) += omap_uwire.o 23obj-$(CONFIG_SPI_OMAP_UWIRE) += omap_uwire.o
24obj-$(CONFIG_SPI_OMAP24XX) += omap2_mcspi.o 24obj-$(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_MPC52xx_PSC) += mpc52xx_psc_spi.o 27obj-$(CONFIG_SPI_MPC52xx_PSC) += mpc52xx_psc_spi.o
27obj-$(CONFIG_SPI_MPC83xx) += spi_mpc83xx.o 28obj-$(CONFIG_SPI_MPC8xxx) += spi_mpc8xxx.o
28obj-$(CONFIG_SPI_S3C24XX_GPIO) += spi_s3c24xx_gpio.o 29obj-$(CONFIG_SPI_S3C24XX_GPIO) += spi_s3c24xx_gpio.o
29obj-$(CONFIG_SPI_S3C24XX) += spi_s3c24xx.o 30obj-$(CONFIG_SPI_S3C24XX) += spi_s3c24xx.o
30obj-$(CONFIG_SPI_TXX9) += spi_txx9.o 31obj-$(CONFIG_SPI_TXX9) += spi_txx9.o
diff --git a/drivers/spi/amba-pl022.c b/drivers/spi/amba-pl022.c
new file mode 100644
index 000000000000..da76797ce8b9
--- /dev/null
+++ b/drivers/spi/amba-pl022.c
@@ -0,0 +1,1866 @@
1/*
2 * drivers/spi/amba-pl022.c
3 *
4 * A driver for the ARM PL022 PrimeCell SSP/SPI bus master.
5 *
6 * Copyright (C) 2008-2009 ST-Ericsson AB
7 * Copyright (C) 2006 STMicroelectronics Pvt. Ltd.
8 *
9 * Author: Linus Walleij <linus.walleij@stericsson.com>
10 *
11 * Initial version inspired by:
12 * linux-2.6.17-rc3-mm1/drivers/spi/pxa2xx_spi.c
13 * Initial adoption to PL022 by:
14 * Sachin Verma <sachin.verma@st.com>
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 */
26
27/*
28 * TODO:
29 * - add timeout on polled transfers
30 * - add generic DMA framework support
31 */
32
33#include <linux/init.h>
34#include <linux/module.h>
35#include <linux/device.h>
36#include <linux/ioport.h>
37#include <linux/errno.h>
38#include <linux/interrupt.h>
39#include <linux/spi/spi.h>
40#include <linux/workqueue.h>
41#include <linux/errno.h>
42#include <linux/delay.h>
43#include <linux/clk.h>
44#include <linux/err.h>
45#include <linux/amba/bus.h>
46#include <linux/amba/pl022.h>
47#include <linux/io.h>
48#include <linux/delay.h>
49
50/*
51 * This macro is used to define some register default values.
52 * reg is masked with mask, the OR:ed with an (again masked)
53 * val shifted sb steps to the left.
54 */
55#define SSP_WRITE_BITS(reg, val, mask, sb) \
56 ((reg) = (((reg) & ~(mask)) | (((val)<<(sb)) & (mask))))
57
58/*
59 * This macro is also used to define some default values.
60 * It will just shift val by sb steps to the left and mask
61 * the result with mask.
62 */
63#define GEN_MASK_BITS(val, mask, sb) \
64 (((val)<<(sb)) & (mask))
65
66#define DRIVE_TX 0
67#define DO_NOT_DRIVE_TX 1
68
69#define DO_NOT_QUEUE_DMA 0
70#define QUEUE_DMA 1
71
72#define RX_TRANSFER 1
73#define TX_TRANSFER 2
74
75/*
76 * Macros to access SSP Registers with their offsets
77 */
78#define SSP_CR0(r) (r + 0x000)
79#define SSP_CR1(r) (r + 0x004)
80#define SSP_DR(r) (r + 0x008)
81#define SSP_SR(r) (r + 0x00C)
82#define SSP_CPSR(r) (r + 0x010)
83#define SSP_IMSC(r) (r + 0x014)
84#define SSP_RIS(r) (r + 0x018)
85#define SSP_MIS(r) (r + 0x01C)
86#define SSP_ICR(r) (r + 0x020)
87#define SSP_DMACR(r) (r + 0x024)
88#define SSP_ITCR(r) (r + 0x080)
89#define SSP_ITIP(r) (r + 0x084)
90#define SSP_ITOP(r) (r + 0x088)
91#define SSP_TDR(r) (r + 0x08C)
92
93#define SSP_PID0(r) (r + 0xFE0)
94#define SSP_PID1(r) (r + 0xFE4)
95#define SSP_PID2(r) (r + 0xFE8)
96#define SSP_PID3(r) (r + 0xFEC)
97
98#define SSP_CID0(r) (r + 0xFF0)
99#define SSP_CID1(r) (r + 0xFF4)
100#define SSP_CID2(r) (r + 0xFF8)
101#define SSP_CID3(r) (r + 0xFFC)
102
103/*
104 * SSP Control Register 0 - SSP_CR0
105 */
106#define SSP_CR0_MASK_DSS (0x1FUL << 0)
107#define SSP_CR0_MASK_HALFDUP (0x1UL << 5)
108#define SSP_CR0_MASK_SPO (0x1UL << 6)
109#define SSP_CR0_MASK_SPH (0x1UL << 7)
110#define SSP_CR0_MASK_SCR (0xFFUL << 8)
111#define SSP_CR0_MASK_CSS (0x1FUL << 16)
112#define SSP_CR0_MASK_FRF (0x3UL << 21)
113
114/*
115 * SSP Control Register 0 - SSP_CR1
116 */
117#define SSP_CR1_MASK_LBM (0x1UL << 0)
118#define SSP_CR1_MASK_SSE (0x1UL << 1)
119#define SSP_CR1_MASK_MS (0x1UL << 2)
120#define SSP_CR1_MASK_SOD (0x1UL << 3)
121#define SSP_CR1_MASK_RENDN (0x1UL << 4)
122#define SSP_CR1_MASK_TENDN (0x1UL << 5)
123#define SSP_CR1_MASK_MWAIT (0x1UL << 6)
124#define SSP_CR1_MASK_RXIFLSEL (0x7UL << 7)
125#define SSP_CR1_MASK_TXIFLSEL (0x7UL << 10)
126
127/*
128 * SSP Data Register - SSP_DR
129 */
130#define SSP_DR_MASK_DATA 0xFFFFFFFF
131
132/*
133 * SSP Status Register - SSP_SR
134 */
135#define SSP_SR_MASK_TFE (0x1UL << 0) /* Transmit FIFO empty */
136#define SSP_SR_MASK_TNF (0x1UL << 1) /* Transmit FIFO not full */
137#define SSP_SR_MASK_RNE (0x1UL << 2) /* Receive FIFO not empty */
138#define SSP_SR_MASK_RFF (0x1UL << 3) /* Receive FIFO full */
139#define SSP_SR_MASK_BSY (0x1UL << 4) /* Busy Flag */
140
141/*
142 * SSP Clock Prescale Register - SSP_CPSR
143 */
144#define SSP_CPSR_MASK_CPSDVSR (0xFFUL << 0)
145
146/*
147 * SSP Interrupt Mask Set/Clear Register - SSP_IMSC
148 */
149#define SSP_IMSC_MASK_RORIM (0x1UL << 0) /* Receive Overrun Interrupt mask */
150#define SSP_IMSC_MASK_RTIM (0x1UL << 1) /* Receive timeout Interrupt mask */
151#define SSP_IMSC_MASK_RXIM (0x1UL << 2) /* Receive FIFO Interrupt mask */
152#define SSP_IMSC_MASK_TXIM (0x1UL << 3) /* Transmit FIFO Interrupt mask */
153
154/*
155 * SSP Raw Interrupt Status Register - SSP_RIS
156 */
157/* Receive Overrun Raw Interrupt status */
158#define SSP_RIS_MASK_RORRIS (0x1UL << 0)
159/* Receive Timeout Raw Interrupt status */
160#define SSP_RIS_MASK_RTRIS (0x1UL << 1)
161/* Receive FIFO Raw Interrupt status */
162#define SSP_RIS_MASK_RXRIS (0x1UL << 2)
163/* Transmit FIFO Raw Interrupt status */
164#define SSP_RIS_MASK_TXRIS (0x1UL << 3)
165
166/*
167 * SSP Masked Interrupt Status Register - SSP_MIS
168 */
169/* Receive Overrun Masked Interrupt status */
170#define SSP_MIS_MASK_RORMIS (0x1UL << 0)
171/* Receive Timeout Masked Interrupt status */
172#define SSP_MIS_MASK_RTMIS (0x1UL << 1)
173/* Receive FIFO Masked Interrupt status */
174#define SSP_MIS_MASK_RXMIS (0x1UL << 2)
175/* Transmit FIFO Masked Interrupt status */
176#define SSP_MIS_MASK_TXMIS (0x1UL << 3)
177
178/*
179 * SSP Interrupt Clear Register - SSP_ICR
180 */
181/* Receive Overrun Raw Clear Interrupt bit */
182#define SSP_ICR_MASK_RORIC (0x1UL << 0)
183/* Receive Timeout Clear Interrupt bit */
184#define SSP_ICR_MASK_RTIC (0x1UL << 1)
185
186/*
187 * SSP DMA Control Register - SSP_DMACR
188 */
189/* Receive DMA Enable bit */
190#define SSP_DMACR_MASK_RXDMAE (0x1UL << 0)
191/* Transmit DMA Enable bit */
192#define SSP_DMACR_MASK_TXDMAE (0x1UL << 1)
193
194/*
195 * SSP Integration Test control Register - SSP_ITCR
196 */
197#define SSP_ITCR_MASK_ITEN (0x1UL << 0)
198#define SSP_ITCR_MASK_TESTFIFO (0x1UL << 1)
199
200/*
201 * SSP Integration Test Input Register - SSP_ITIP
202 */
203#define ITIP_MASK_SSPRXD (0x1UL << 0)
204#define ITIP_MASK_SSPFSSIN (0x1UL << 1)
205#define ITIP_MASK_SSPCLKIN (0x1UL << 2)
206#define ITIP_MASK_RXDMAC (0x1UL << 3)
207#define ITIP_MASK_TXDMAC (0x1UL << 4)
208#define ITIP_MASK_SSPTXDIN (0x1UL << 5)
209
210/*
211 * SSP Integration Test output Register - SSP_ITOP
212 */
213#define ITOP_MASK_SSPTXD (0x1UL << 0)
214#define ITOP_MASK_SSPFSSOUT (0x1UL << 1)
215#define ITOP_MASK_SSPCLKOUT (0x1UL << 2)
216#define ITOP_MASK_SSPOEn (0x1UL << 3)
217#define ITOP_MASK_SSPCTLOEn (0x1UL << 4)
218#define ITOP_MASK_RORINTR (0x1UL << 5)
219#define ITOP_MASK_RTINTR (0x1UL << 6)
220#define ITOP_MASK_RXINTR (0x1UL << 7)
221#define ITOP_MASK_TXINTR (0x1UL << 8)
222#define ITOP_MASK_INTR (0x1UL << 9)
223#define ITOP_MASK_RXDMABREQ (0x1UL << 10)
224#define ITOP_MASK_RXDMASREQ (0x1UL << 11)
225#define ITOP_MASK_TXDMABREQ (0x1UL << 12)
226#define ITOP_MASK_TXDMASREQ (0x1UL << 13)
227
228/*
229 * SSP Test Data Register - SSP_TDR
230 */
231#define TDR_MASK_TESTDATA (0xFFFFFFFF)
232
233/*
234 * Message State
235 * we use the spi_message.state (void *) pointer to
236 * hold a single state value, that's why all this
237 * (void *) casting is done here.
238 */
239#define STATE_START ((void *) 0)
240#define STATE_RUNNING ((void *) 1)
241#define STATE_DONE ((void *) 2)
242#define STATE_ERROR ((void *) -1)
243
244/*
245 * Queue State
246 */
247#define QUEUE_RUNNING (0)
248#define QUEUE_STOPPED (1)
249/*
250 * SSP State - Whether Enabled or Disabled
251 */
252#define SSP_DISABLED (0)
253#define SSP_ENABLED (1)
254
255/*
256 * SSP DMA State - Whether DMA Enabled or Disabled
257 */
258#define SSP_DMA_DISABLED (0)
259#define SSP_DMA_ENABLED (1)
260
261/*
262 * SSP Clock Defaults
263 */
264#define NMDK_SSP_DEFAULT_CLKRATE 0x2
265#define NMDK_SSP_DEFAULT_PRESCALE 0x40
266
267/*
268 * SSP Clock Parameter ranges
269 */
270#define CPSDVR_MIN 0x02
271#define CPSDVR_MAX 0xFE
272#define SCR_MIN 0x00
273#define SCR_MAX 0xFF
274
275/*
276 * SSP Interrupt related Macros
277 */
278#define DEFAULT_SSP_REG_IMSC 0x0UL
279#define DISABLE_ALL_INTERRUPTS DEFAULT_SSP_REG_IMSC
280#define ENABLE_ALL_INTERRUPTS (~DEFAULT_SSP_REG_IMSC)
281
282#define CLEAR_ALL_INTERRUPTS 0x3
283
284
285/*
286 * The type of reading going on on this chip
287 */
288enum ssp_reading {
289 READING_NULL,
290 READING_U8,
291 READING_U16,
292 READING_U32
293};
294
295/**
296 * The type of writing going on on this chip
297 */
298enum ssp_writing {
299 WRITING_NULL,
300 WRITING_U8,
301 WRITING_U16,
302 WRITING_U32
303};
304
305/**
306 * struct vendor_data - vendor-specific config parameters
307 * for PL022 derivates
308 * @fifodepth: depth of FIFOs (both)
309 * @max_bpw: maximum number of bits per word
310 * @unidir: supports unidirection transfers
311 */
312struct vendor_data {
313 int fifodepth;
314 int max_bpw;
315 bool unidir;
316};
317
318/**
319 * struct pl022 - This is the private SSP driver data structure
320 * @adev: AMBA device model hookup
321 * @phybase: The physical memory where the SSP device resides
322 * @virtbase: The virtual memory where the SSP is mapped
323 * @master: SPI framework hookup
324 * @master_info: controller-specific data from machine setup
325 * @regs: SSP controller register's virtual address
326 * @pump_messages: Work struct for scheduling work to the workqueue
327 * @lock: spinlock to syncronise access to driver data
328 * @workqueue: a workqueue on which any spi_message request is queued
329 * @busy: workqueue is busy
330 * @run: workqueue is running
331 * @pump_transfers: Tasklet used in Interrupt Transfer mode
332 * @cur_msg: Pointer to current spi_message being processed
333 * @cur_transfer: Pointer to current spi_transfer
334 * @cur_chip: pointer to current clients chip(assigned from controller_state)
335 * @tx: current position in TX buffer to be read
336 * @tx_end: end position in TX buffer to be read
337 * @rx: current position in RX buffer to be written
338 * @rx_end: end position in RX buffer to be written
339 * @readingtype: the type of read currently going on
340 * @writingtype: the type or write currently going on
341 */
342struct pl022 {
343 struct amba_device *adev;
344 struct vendor_data *vendor;
345 resource_size_t phybase;
346 void __iomem *virtbase;
347 struct clk *clk;
348 struct spi_master *master;
349 struct pl022_ssp_controller *master_info;
350 /* Driver message queue */
351 struct workqueue_struct *workqueue;
352 struct work_struct pump_messages;
353 spinlock_t queue_lock;
354 struct list_head queue;
355 int busy;
356 int run;
357 /* Message transfer pump */
358 struct tasklet_struct pump_transfers;
359 struct spi_message *cur_msg;
360 struct spi_transfer *cur_transfer;
361 struct chip_data *cur_chip;
362 void *tx;
363 void *tx_end;
364 void *rx;
365 void *rx_end;
366 enum ssp_reading read;
367 enum ssp_writing write;
368};
369
370/**
371 * struct chip_data - To maintain runtime state of SSP for each client chip
372 * @cr0: Value of control register CR0 of SSP
373 * @cr1: Value of control register CR1 of SSP
374 * @dmacr: Value of DMA control Register of SSP
375 * @cpsr: Value of Clock prescale register
376 * @n_bytes: how many bytes(power of 2) reqd for a given data width of client
377 * @enable_dma: Whether to enable DMA or not
378 * @write: function ptr to be used to write when doing xfer for this chip
379 * @read: function ptr to be used to read when doing xfer for this chip
380 * @cs_control: chip select callback provided by chip
381 * @xfer_type: polling/interrupt/DMA
382 *
383 * Runtime state of the SSP controller, maintained per chip,
384 * This would be set according to the current message that would be served
385 */
386struct chip_data {
387 u16 cr0;
388 u16 cr1;
389 u16 dmacr;
390 u16 cpsr;
391 u8 n_bytes;
392 u8 enable_dma:1;
393 enum ssp_reading read;
394 enum ssp_writing write;
395 void (*cs_control) (u32 command);
396 int xfer_type;
397};
398
399/**
400 * null_cs_control - Dummy chip select function
401 * @command: select/delect the chip
402 *
403 * If no chip select function is provided by client this is used as dummy
404 * chip select
405 */
406static void null_cs_control(u32 command)
407{
408 pr_debug("pl022: dummy chip select control, CS=0x%x\n", command);
409}
410
411/**
412 * giveback - current spi_message is over, schedule next message and call
413 * callback of this message. Assumes that caller already
414 * set message->status; dma and pio irqs are blocked
415 * @pl022: SSP driver private data structure
416 */
417static void giveback(struct pl022 *pl022)
418{
419 struct spi_transfer *last_transfer;
420 unsigned long flags;
421 struct spi_message *msg;
422 void (*curr_cs_control) (u32 command);
423
424 /*
425 * This local reference to the chip select function
426 * is needed because we set curr_chip to NULL
427 * as a step toward termininating the message.
428 */
429 curr_cs_control = pl022->cur_chip->cs_control;
430 spin_lock_irqsave(&pl022->queue_lock, flags);
431 msg = pl022->cur_msg;
432 pl022->cur_msg = NULL;
433 pl022->cur_transfer = NULL;
434 pl022->cur_chip = NULL;
435 queue_work(pl022->workqueue, &pl022->pump_messages);
436 spin_unlock_irqrestore(&pl022->queue_lock, flags);
437
438 last_transfer = list_entry(msg->transfers.prev,
439 struct spi_transfer,
440 transfer_list);
441
442 /* Delay if requested before any change in chip select */
443 if (last_transfer->delay_usecs)
444 /*
445 * FIXME: This runs in interrupt context.
446 * Is this really smart?
447 */
448 udelay(last_transfer->delay_usecs);
449
450 /*
451 * Drop chip select UNLESS cs_change is true or we are returning
452 * a message with an error, or next message is for another chip
453 */
454 if (!last_transfer->cs_change)
455 curr_cs_control(SSP_CHIP_DESELECT);
456 else {
457 struct spi_message *next_msg;
458
459 /* Holding of cs was hinted, but we need to make sure
460 * the next message is for the same chip. Don't waste
461 * time with the following tests unless this was hinted.
462 *
463 * We cannot postpone this until pump_messages, because
464 * after calling msg->complete (below) the driver that
465 * sent the current message could be unloaded, which
466 * could invalidate the cs_control() callback...
467 */
468
469 /* get a pointer to the next message, if any */
470 spin_lock_irqsave(&pl022->queue_lock, flags);
471 if (list_empty(&pl022->queue))
472 next_msg = NULL;
473 else
474 next_msg = list_entry(pl022->queue.next,
475 struct spi_message, queue);
476 spin_unlock_irqrestore(&pl022->queue_lock, flags);
477
478 /* see if the next and current messages point
479 * to the same chip
480 */
481 if (next_msg && next_msg->spi != msg->spi)
482 next_msg = NULL;
483 if (!next_msg || msg->state == STATE_ERROR)
484 curr_cs_control(SSP_CHIP_DESELECT);
485 }
486 msg->state = NULL;
487 if (msg->complete)
488 msg->complete(msg->context);
489 /* This message is completed, so let's turn off the clock! */
490 clk_disable(pl022->clk);
491}
492
493/**
494 * flush - flush the FIFO to reach a clean state
495 * @pl022: SSP driver private data structure
496 */
497static int flush(struct pl022 *pl022)
498{
499 unsigned long limit = loops_per_jiffy << 1;
500
501 dev_dbg(&pl022->adev->dev, "flush\n");
502 do {
503 while (readw(SSP_SR(pl022->virtbase)) & SSP_SR_MASK_RNE)
504 readw(SSP_DR(pl022->virtbase));
505 } while ((readw(SSP_SR(pl022->virtbase)) & SSP_SR_MASK_BSY) && limit--);
506 return limit;
507}
508
509/**
510 * restore_state - Load configuration of current chip
511 * @pl022: SSP driver private data structure
512 */
513static void restore_state(struct pl022 *pl022)
514{
515 struct chip_data *chip = pl022->cur_chip;
516
517 writew(chip->cr0, SSP_CR0(pl022->virtbase));
518 writew(chip->cr1, SSP_CR1(pl022->virtbase));
519 writew(chip->dmacr, SSP_DMACR(pl022->virtbase));
520 writew(chip->cpsr, SSP_CPSR(pl022->virtbase));
521 writew(DISABLE_ALL_INTERRUPTS, SSP_IMSC(pl022->virtbase));
522 writew(CLEAR_ALL_INTERRUPTS, SSP_ICR(pl022->virtbase));
523}
524
525/**
526 * load_ssp_default_config - Load default configuration for SSP
527 * @pl022: SSP driver private data structure
528 */
529
530/*
531 * Default SSP Register Values
532 */
533#define DEFAULT_SSP_REG_CR0 ( \
534 GEN_MASK_BITS(SSP_DATA_BITS_12, SSP_CR0_MASK_DSS, 0) | \
535 GEN_MASK_BITS(SSP_MICROWIRE_CHANNEL_FULL_DUPLEX, SSP_CR0_MASK_HALFDUP, 5) | \
536 GEN_MASK_BITS(SSP_CLK_POL_IDLE_LOW, SSP_CR0_MASK_SPO, 6) | \
537 GEN_MASK_BITS(SSP_CLK_FALLING_EDGE, SSP_CR0_MASK_SPH, 7) | \
538 GEN_MASK_BITS(NMDK_SSP_DEFAULT_CLKRATE, SSP_CR0_MASK_SCR, 8) | \
539 GEN_MASK_BITS(SSP_BITS_8, SSP_CR0_MASK_CSS, 16) | \
540 GEN_MASK_BITS(SSP_INTERFACE_MOTOROLA_SPI, SSP_CR0_MASK_FRF, 21) \
541)
542
543#define DEFAULT_SSP_REG_CR1 ( \
544 GEN_MASK_BITS(LOOPBACK_DISABLED, SSP_CR1_MASK_LBM, 0) | \
545 GEN_MASK_BITS(SSP_DISABLED, SSP_CR1_MASK_SSE, 1) | \
546 GEN_MASK_BITS(SSP_MASTER, SSP_CR1_MASK_MS, 2) | \
547 GEN_MASK_BITS(DO_NOT_DRIVE_TX, SSP_CR1_MASK_SOD, 3) | \
548 GEN_MASK_BITS(SSP_RX_MSB, SSP_CR1_MASK_RENDN, 4) | \
549 GEN_MASK_BITS(SSP_TX_MSB, SSP_CR1_MASK_TENDN, 5) | \
550 GEN_MASK_BITS(SSP_MWIRE_WAIT_ZERO, SSP_CR1_MASK_MWAIT, 6) |\
551 GEN_MASK_BITS(SSP_RX_1_OR_MORE_ELEM, SSP_CR1_MASK_RXIFLSEL, 7) | \
552 GEN_MASK_BITS(SSP_TX_1_OR_MORE_EMPTY_LOC, SSP_CR1_MASK_TXIFLSEL, 10) \
553)
554
555#define DEFAULT_SSP_REG_CPSR ( \
556 GEN_MASK_BITS(NMDK_SSP_DEFAULT_PRESCALE, SSP_CPSR_MASK_CPSDVSR, 0) \
557)
558
559#define DEFAULT_SSP_REG_DMACR (\
560 GEN_MASK_BITS(SSP_DMA_DISABLED, SSP_DMACR_MASK_RXDMAE, 0) | \
561 GEN_MASK_BITS(SSP_DMA_DISABLED, SSP_DMACR_MASK_TXDMAE, 1) \
562)
563
564
565static void load_ssp_default_config(struct pl022 *pl022)
566{
567 writew(DEFAULT_SSP_REG_CR0, SSP_CR0(pl022->virtbase));
568 writew(DEFAULT_SSP_REG_CR1, SSP_CR1(pl022->virtbase));
569 writew(DEFAULT_SSP_REG_DMACR, SSP_DMACR(pl022->virtbase));
570 writew(DEFAULT_SSP_REG_CPSR, SSP_CPSR(pl022->virtbase));
571 writew(DISABLE_ALL_INTERRUPTS, SSP_IMSC(pl022->virtbase));
572 writew(CLEAR_ALL_INTERRUPTS, SSP_ICR(pl022->virtbase));
573}
574
575/**
576 * This will write to TX and read from RX according to the parameters
577 * set in pl022.
578 */
579static void readwriter(struct pl022 *pl022)
580{
581
582 /*
583 * The FIFO depth is different inbetween primecell variants.
584 * I believe filling in too much in the FIFO might cause
585 * errons in 8bit wide transfers on ARM variants (just 8 words
586 * FIFO, means only 8x8 = 64 bits in FIFO) at least.
587 *
588 * FIXME: currently we have no logic to account for this.
589 * perhaps there is even something broken in HW regarding
590 * 8bit transfers (it doesn't fail on 16bit) so this needs
591 * more investigation...
592 */
593 dev_dbg(&pl022->adev->dev,
594 "%s, rx: %p, rxend: %p, tx: %p, txend: %p\n",
595 __func__, pl022->rx, pl022->rx_end, pl022->tx, pl022->tx_end);
596
597 /* Read as much as you can */
598 while ((readw(SSP_SR(pl022->virtbase)) & SSP_SR_MASK_RNE)
599 && (pl022->rx < pl022->rx_end)) {
600 switch (pl022->read) {
601 case READING_NULL:
602 readw(SSP_DR(pl022->virtbase));
603 break;
604 case READING_U8:
605 *(u8 *) (pl022->rx) =
606 readw(SSP_DR(pl022->virtbase)) & 0xFFU;
607 break;
608 case READING_U16:
609 *(u16 *) (pl022->rx) =
610 (u16) readw(SSP_DR(pl022->virtbase));
611 break;
612 case READING_U32:
613 *(u32 *) (pl022->rx) =
614 readl(SSP_DR(pl022->virtbase));
615 break;
616 }
617 pl022->rx += (pl022->cur_chip->n_bytes);
618 }
619 /*
620 * Write as much as you can, while keeping an eye on the RX FIFO!
621 */
622 while ((readw(SSP_SR(pl022->virtbase)) & SSP_SR_MASK_TNF)
623 && (pl022->tx < pl022->tx_end)) {
624 switch (pl022->write) {
625 case WRITING_NULL:
626 writew(0x0, SSP_DR(pl022->virtbase));
627 break;
628 case WRITING_U8:
629 writew(*(u8 *) (pl022->tx), SSP_DR(pl022->virtbase));
630 break;
631 case WRITING_U16:
632 writew((*(u16 *) (pl022->tx)), SSP_DR(pl022->virtbase));
633 break;
634 case WRITING_U32:
635 writel(*(u32 *) (pl022->tx), SSP_DR(pl022->virtbase));
636 break;
637 }
638 pl022->tx += (pl022->cur_chip->n_bytes);
639 /*
640 * This inner reader takes care of things appearing in the RX
641 * FIFO as we're transmitting. This will happen a lot since the
642 * clock starts running when you put things into the TX FIFO,
643 * and then things are continously clocked into the RX FIFO.
644 */
645 while ((readw(SSP_SR(pl022->virtbase)) & SSP_SR_MASK_RNE)
646 && (pl022->rx < pl022->rx_end)) {
647 switch (pl022->read) {
648 case READING_NULL:
649 readw(SSP_DR(pl022->virtbase));
650 break;
651 case READING_U8:
652 *(u8 *) (pl022->rx) =
653 readw(SSP_DR(pl022->virtbase)) & 0xFFU;
654 break;
655 case READING_U16:
656 *(u16 *) (pl022->rx) =
657 (u16) readw(SSP_DR(pl022->virtbase));
658 break;
659 case READING_U32:
660 *(u32 *) (pl022->rx) =
661 readl(SSP_DR(pl022->virtbase));
662 break;
663 }
664 pl022->rx += (pl022->cur_chip->n_bytes);
665 }
666 }
667 /*
668 * When we exit here the TX FIFO should be full and the RX FIFO
669 * should be empty
670 */
671}
672
673
674/**
675 * next_transfer - Move to the Next transfer in the current spi message
676 * @pl022: SSP driver private data structure
677 *
678 * This function moves though the linked list of spi transfers in the
679 * current spi message and returns with the state of current spi
680 * message i.e whether its last transfer is done(STATE_DONE) or
681 * Next transfer is ready(STATE_RUNNING)
682 */
683static void *next_transfer(struct pl022 *pl022)
684{
685 struct spi_message *msg = pl022->cur_msg;
686 struct spi_transfer *trans = pl022->cur_transfer;
687
688 /* Move to next transfer */
689 if (trans->transfer_list.next != &msg->transfers) {
690 pl022->cur_transfer =
691 list_entry(trans->transfer_list.next,
692 struct spi_transfer, transfer_list);
693 return STATE_RUNNING;
694 }
695 return STATE_DONE;
696}
697/**
698 * pl022_interrupt_handler - Interrupt handler for SSP controller
699 *
700 * This function handles interrupts generated for an interrupt based transfer.
701 * If a receive overrun (ROR) interrupt is there then we disable SSP, flag the
702 * current message's state as STATE_ERROR and schedule the tasklet
703 * pump_transfers which will do the postprocessing of the current message by
704 * calling giveback(). Otherwise it reads data from RX FIFO till there is no
705 * more data, and writes data in TX FIFO till it is not full. If we complete
706 * the transfer we move to the next transfer and schedule the tasklet.
707 */
708static irqreturn_t pl022_interrupt_handler(int irq, void *dev_id)
709{
710 struct pl022 *pl022 = dev_id;
711 struct spi_message *msg = pl022->cur_msg;
712 u16 irq_status = 0;
713 u16 flag = 0;
714
715 if (unlikely(!msg)) {
716 dev_err(&pl022->adev->dev,
717 "bad message state in interrupt handler");
718 /* Never fail */
719 return IRQ_HANDLED;
720 }
721
722 /* Read the Interrupt Status Register */
723 irq_status = readw(SSP_MIS(pl022->virtbase));
724
725 if (unlikely(!irq_status))
726 return IRQ_NONE;
727
728 /* This handles the error code interrupts */
729 if (unlikely(irq_status & SSP_MIS_MASK_RORMIS)) {
730 /*
731 * Overrun interrupt - bail out since our Data has been
732 * corrupted
733 */
734 dev_err(&pl022->adev->dev,
735 "FIFO overrun\n");
736 if (readw(SSP_SR(pl022->virtbase)) & SSP_SR_MASK_RFF)
737 dev_err(&pl022->adev->dev,
738 "RXFIFO is full\n");
739 if (readw(SSP_SR(pl022->virtbase)) & SSP_SR_MASK_TNF)
740 dev_err(&pl022->adev->dev,
741 "TXFIFO is full\n");
742
743 /*
744 * Disable and clear interrupts, disable SSP,
745 * mark message with bad status so it can be
746 * retried.
747 */
748 writew(DISABLE_ALL_INTERRUPTS,
749 SSP_IMSC(pl022->virtbase));
750 writew(CLEAR_ALL_INTERRUPTS, SSP_ICR(pl022->virtbase));
751 writew((readw(SSP_CR1(pl022->virtbase)) &
752 (~SSP_CR1_MASK_SSE)), SSP_CR1(pl022->virtbase));
753 msg->state = STATE_ERROR;
754
755 /* Schedule message queue handler */
756 tasklet_schedule(&pl022->pump_transfers);
757 return IRQ_HANDLED;
758 }
759
760 readwriter(pl022);
761
762 if ((pl022->tx == pl022->tx_end) && (flag == 0)) {
763 flag = 1;
764 /* Disable Transmit interrupt */
765 writew(readw(SSP_IMSC(pl022->virtbase)) &
766 (~SSP_IMSC_MASK_TXIM),
767 SSP_IMSC(pl022->virtbase));
768 }
769
770 /*
771 * Since all transactions must write as much as shall be read,
772 * we can conclude the entire transaction once RX is complete.
773 * At this point, all TX will always be finished.
774 */
775 if (pl022->rx >= pl022->rx_end) {
776 writew(DISABLE_ALL_INTERRUPTS,
777 SSP_IMSC(pl022->virtbase));
778 writew(CLEAR_ALL_INTERRUPTS, SSP_ICR(pl022->virtbase));
779 if (unlikely(pl022->rx > pl022->rx_end)) {
780 dev_warn(&pl022->adev->dev, "read %u surplus "
781 "bytes (did you request an odd "
782 "number of bytes on a 16bit bus?)\n",
783 (u32) (pl022->rx - pl022->rx_end));
784 }
785 /* Update total bytes transfered */
786 msg->actual_length += pl022->cur_transfer->len;
787 if (pl022->cur_transfer->cs_change)
788 pl022->cur_chip->
789 cs_control(SSP_CHIP_DESELECT);
790 /* Move to next transfer */
791 msg->state = next_transfer(pl022);
792 tasklet_schedule(&pl022->pump_transfers);
793 return IRQ_HANDLED;
794 }
795
796 return IRQ_HANDLED;
797}
798
799/**
800 * This sets up the pointers to memory for the next message to
801 * send out on the SPI bus.
802 */
803static int set_up_next_transfer(struct pl022 *pl022,
804 struct spi_transfer *transfer)
805{
806 int residue;
807
808 /* Sanity check the message for this bus width */
809 residue = pl022->cur_transfer->len % pl022->cur_chip->n_bytes;
810 if (unlikely(residue != 0)) {
811 dev_err(&pl022->adev->dev,
812 "message of %u bytes to transmit but the current "
813 "chip bus has a data width of %u bytes!\n",
814 pl022->cur_transfer->len,
815 pl022->cur_chip->n_bytes);
816 dev_err(&pl022->adev->dev, "skipping this message\n");
817 return -EIO;
818 }
819 pl022->tx = (void *)transfer->tx_buf;
820 pl022->tx_end = pl022->tx + pl022->cur_transfer->len;
821 pl022->rx = (void *)transfer->rx_buf;
822 pl022->rx_end = pl022->rx + pl022->cur_transfer->len;
823 pl022->write =
824 pl022->tx ? pl022->cur_chip->write : WRITING_NULL;
825 pl022->read = pl022->rx ? pl022->cur_chip->read : READING_NULL;
826 return 0;
827}
828
829/**
830 * pump_transfers - Tasklet function which schedules next interrupt transfer
831 * when running in interrupt transfer mode.
832 * @data: SSP driver private data structure
833 *
834 */
835static void pump_transfers(unsigned long data)
836{
837 struct pl022 *pl022 = (struct pl022 *) data;
838 struct spi_message *message = NULL;
839 struct spi_transfer *transfer = NULL;
840 struct spi_transfer *previous = NULL;
841
842 /* Get current state information */
843 message = pl022->cur_msg;
844 transfer = pl022->cur_transfer;
845
846 /* Handle for abort */
847 if (message->state == STATE_ERROR) {
848 message->status = -EIO;
849 giveback(pl022);
850 return;
851 }
852
853 /* Handle end of message */
854 if (message->state == STATE_DONE) {
855 message->status = 0;
856 giveback(pl022);
857 return;
858 }
859
860 /* Delay if requested at end of transfer before CS change */
861 if (message->state == STATE_RUNNING) {
862 previous = list_entry(transfer->transfer_list.prev,
863 struct spi_transfer,
864 transfer_list);
865 if (previous->delay_usecs)
866 /*
867 * FIXME: This runs in interrupt context.
868 * Is this really smart?
869 */
870 udelay(previous->delay_usecs);
871
872 /* Drop chip select only if cs_change is requested */
873 if (previous->cs_change)
874 pl022->cur_chip->cs_control(SSP_CHIP_SELECT);
875 } else {
876 /* STATE_START */
877 message->state = STATE_RUNNING;
878 }
879
880 if (set_up_next_transfer(pl022, transfer)) {
881 message->state = STATE_ERROR;
882 message->status = -EIO;
883 giveback(pl022);
884 return;
885 }
886 /* Flush the FIFOs and let's go! */
887 flush(pl022);
888 writew(ENABLE_ALL_INTERRUPTS, SSP_IMSC(pl022->virtbase));
889}
890
891/**
892 * NOT IMPLEMENTED
893 * configure_dma - It configures the DMA pipes for DMA transfers
894 * @data: SSP driver's private data structure
895 *
896 */
897static int configure_dma(void *data)
898{
899 struct pl022 *pl022 = data;
900 dev_dbg(&pl022->adev->dev, "configure DMA\n");
901 return -ENOTSUPP;
902}
903
904/**
905 * do_dma_transfer - It handles transfers of the current message
906 * if it is DMA xfer.
907 * NOT FULLY IMPLEMENTED
908 * @data: SSP driver's private data structure
909 */
910static void do_dma_transfer(void *data)
911{
912 struct pl022 *pl022 = data;
913
914 if (configure_dma(data)) {
915 dev_dbg(&pl022->adev->dev, "configuration of DMA Failed!\n");
916 goto err_config_dma;
917 }
918
919 /* TODO: Implememt DMA setup of pipes here */
920
921 /* Enable target chip, set up transfer */
922 pl022->cur_chip->cs_control(SSP_CHIP_SELECT);
923 if (set_up_next_transfer(pl022, pl022->cur_transfer)) {
924 /* Error path */
925 pl022->cur_msg->state = STATE_ERROR;
926 pl022->cur_msg->status = -EIO;
927 giveback(pl022);
928 return;
929 }
930 /* Enable SSP */
931 writew((readw(SSP_CR1(pl022->virtbase)) | SSP_CR1_MASK_SSE),
932 SSP_CR1(pl022->virtbase));
933
934 /* TODO: Enable the DMA transfer here */
935 return;
936
937 err_config_dma:
938 pl022->cur_msg->state = STATE_ERROR;
939 pl022->cur_msg->status = -EIO;
940 giveback(pl022);
941 return;
942}
943
944static void do_interrupt_transfer(void *data)
945{
946 struct pl022 *pl022 = data;
947
948 /* Enable target chip */
949 pl022->cur_chip->cs_control(SSP_CHIP_SELECT);
950 if (set_up_next_transfer(pl022, pl022->cur_transfer)) {
951 /* Error path */
952 pl022->cur_msg->state = STATE_ERROR;
953 pl022->cur_msg->status = -EIO;
954 giveback(pl022);
955 return;
956 }
957 /* Enable SSP, turn on interrupts */
958 writew((readw(SSP_CR1(pl022->virtbase)) | SSP_CR1_MASK_SSE),
959 SSP_CR1(pl022->virtbase));
960 writew(ENABLE_ALL_INTERRUPTS, SSP_IMSC(pl022->virtbase));
961}
962
963static void do_polling_transfer(void *data)
964{
965 struct pl022 *pl022 = data;
966 struct spi_message *message = NULL;
967 struct spi_transfer *transfer = NULL;
968 struct spi_transfer *previous = NULL;
969 struct chip_data *chip;
970
971 chip = pl022->cur_chip;
972 message = pl022->cur_msg;
973
974 while (message->state != STATE_DONE) {
975 /* Handle for abort */
976 if (message->state == STATE_ERROR)
977 break;
978 transfer = pl022->cur_transfer;
979
980 /* Delay if requested at end of transfer */
981 if (message->state == STATE_RUNNING) {
982 previous =
983 list_entry(transfer->transfer_list.prev,
984 struct spi_transfer, transfer_list);
985 if (previous->delay_usecs)
986 udelay(previous->delay_usecs);
987 if (previous->cs_change)
988 pl022->cur_chip->cs_control(SSP_CHIP_SELECT);
989 } else {
990 /* STATE_START */
991 message->state = STATE_RUNNING;
992 pl022->cur_chip->cs_control(SSP_CHIP_SELECT);
993 }
994
995 /* Configuration Changing Per Transfer */
996 if (set_up_next_transfer(pl022, transfer)) {
997 /* Error path */
998 message->state = STATE_ERROR;
999 break;
1000 }
1001 /* Flush FIFOs and enable SSP */
1002 flush(pl022);
1003 writew((readw(SSP_CR1(pl022->virtbase)) | SSP_CR1_MASK_SSE),
1004 SSP_CR1(pl022->virtbase));
1005
1006 dev_dbg(&pl022->adev->dev, "POLLING TRANSFER ONGOING ... \n");
1007 /* FIXME: insert a timeout so we don't hang here indefinately */
1008 while (pl022->tx < pl022->tx_end || pl022->rx < pl022->rx_end)
1009 readwriter(pl022);
1010
1011 /* Update total byte transfered */
1012 message->actual_length += pl022->cur_transfer->len;
1013 if (pl022->cur_transfer->cs_change)
1014 pl022->cur_chip->cs_control(SSP_CHIP_DESELECT);
1015 /* Move to next transfer */
1016 message->state = next_transfer(pl022);
1017 }
1018
1019 /* Handle end of message */
1020 if (message->state == STATE_DONE)
1021 message->status = 0;
1022 else
1023 message->status = -EIO;
1024
1025 giveback(pl022);
1026 return;
1027}
1028
1029/**
1030 * pump_messages - Workqueue function which processes spi message queue
1031 * @data: pointer to private data of SSP driver
1032 *
1033 * This function checks if there is any spi message in the queue that
1034 * needs processing and delegate control to appropriate function
1035 * do_polling_transfer()/do_interrupt_transfer()/do_dma_transfer()
1036 * based on the kind of the transfer
1037 *
1038 */
1039static void pump_messages(struct work_struct *work)
1040{
1041 struct pl022 *pl022 =
1042 container_of(work, struct pl022, pump_messages);
1043 unsigned long flags;
1044
1045 /* Lock queue and check for queue work */
1046 spin_lock_irqsave(&pl022->queue_lock, flags);
1047 if (list_empty(&pl022->queue) || pl022->run == QUEUE_STOPPED) {
1048 pl022->busy = 0;
1049 spin_unlock_irqrestore(&pl022->queue_lock, flags);
1050 return;
1051 }
1052 /* Make sure we are not already running a message */
1053 if (pl022->cur_msg) {
1054 spin_unlock_irqrestore(&pl022->queue_lock, flags);
1055 return;
1056 }
1057 /* Extract head of queue */
1058 pl022->cur_msg =
1059 list_entry(pl022->queue.next, struct spi_message, queue);
1060
1061 list_del_init(&pl022->cur_msg->queue);
1062 pl022->busy = 1;
1063 spin_unlock_irqrestore(&pl022->queue_lock, flags);
1064
1065 /* Initial message state */
1066 pl022->cur_msg->state = STATE_START;
1067 pl022->cur_transfer = list_entry(pl022->cur_msg->transfers.next,
1068 struct spi_transfer,
1069 transfer_list);
1070
1071 /* Setup the SPI using the per chip configuration */
1072 pl022->cur_chip = spi_get_ctldata(pl022->cur_msg->spi);
1073 /*
1074 * We enable the clock here, then the clock will be disabled when
1075 * giveback() is called in each method (poll/interrupt/DMA)
1076 */
1077 clk_enable(pl022->clk);
1078 restore_state(pl022);
1079 flush(pl022);
1080
1081 if (pl022->cur_chip->xfer_type == POLLING_TRANSFER)
1082 do_polling_transfer(pl022);
1083 else if (pl022->cur_chip->xfer_type == INTERRUPT_TRANSFER)
1084 do_interrupt_transfer(pl022);
1085 else
1086 do_dma_transfer(pl022);
1087}
1088
1089
1090static int __init init_queue(struct pl022 *pl022)
1091{
1092 INIT_LIST_HEAD(&pl022->queue);
1093 spin_lock_init(&pl022->queue_lock);
1094
1095 pl022->run = QUEUE_STOPPED;
1096 pl022->busy = 0;
1097
1098 tasklet_init(&pl022->pump_transfers,
1099 pump_transfers, (unsigned long)pl022);
1100
1101 INIT_WORK(&pl022->pump_messages, pump_messages);
1102 pl022->workqueue = create_singlethread_workqueue(
1103 dev_name(pl022->master->dev.parent));
1104 if (pl022->workqueue == NULL)
1105 return -EBUSY;
1106
1107 return 0;
1108}
1109
1110
1111static int start_queue(struct pl022 *pl022)
1112{
1113 unsigned long flags;
1114
1115 spin_lock_irqsave(&pl022->queue_lock, flags);
1116
1117 if (pl022->run == QUEUE_RUNNING || pl022->busy) {
1118 spin_unlock_irqrestore(&pl022->queue_lock, flags);
1119 return -EBUSY;
1120 }
1121
1122 pl022->run = QUEUE_RUNNING;
1123 pl022->cur_msg = NULL;
1124 pl022->cur_transfer = NULL;
1125 pl022->cur_chip = NULL;
1126 spin_unlock_irqrestore(&pl022->queue_lock, flags);
1127
1128 queue_work(pl022->workqueue, &pl022->pump_messages);
1129
1130 return 0;
1131}
1132
1133
1134static int stop_queue(struct pl022 *pl022)
1135{
1136 unsigned long flags;
1137 unsigned limit = 500;
1138 int status = 0;
1139
1140 spin_lock_irqsave(&pl022->queue_lock, flags);
1141
1142 /* This is a bit lame, but is optimized for the common execution path.
1143 * A wait_queue on the pl022->busy could be used, but then the common
1144 * execution path (pump_messages) would be required to call wake_up or
1145 * friends on every SPI message. Do this instead */
1146 pl022->run = QUEUE_STOPPED;
1147 while (!list_empty(&pl022->queue) && pl022->busy && limit--) {
1148 spin_unlock_irqrestore(&pl022->queue_lock, flags);
1149 msleep(10);
1150 spin_lock_irqsave(&pl022->queue_lock, flags);
1151 }
1152
1153 if (!list_empty(&pl022->queue) || pl022->busy)
1154 status = -EBUSY;
1155
1156 spin_unlock_irqrestore(&pl022->queue_lock, flags);
1157
1158 return status;
1159}
1160
1161static int destroy_queue(struct pl022 *pl022)
1162{
1163 int status;
1164
1165 status = stop_queue(pl022);
1166 /* we are unloading the module or failing to load (only two calls
1167 * to this routine), and neither call can handle a return value.
1168 * However, destroy_workqueue calls flush_workqueue, and that will
1169 * block until all work is done. If the reason that stop_queue
1170 * timed out is that the work will never finish, then it does no
1171 * good to call destroy_workqueue, so return anyway. */
1172 if (status != 0)
1173 return status;
1174
1175 destroy_workqueue(pl022->workqueue);
1176
1177 return 0;
1178}
1179
1180static int verify_controller_parameters(struct pl022 *pl022,
1181 struct pl022_config_chip *chip_info)
1182{
1183 if ((chip_info->lbm != LOOPBACK_ENABLED)
1184 && (chip_info->lbm != LOOPBACK_DISABLED)) {
1185 dev_err(chip_info->dev,
1186 "loopback Mode is configured incorrectly\n");
1187 return -EINVAL;
1188 }
1189 if ((chip_info->iface < SSP_INTERFACE_MOTOROLA_SPI)
1190 || (chip_info->iface > SSP_INTERFACE_UNIDIRECTIONAL)) {
1191 dev_err(chip_info->dev,
1192 "interface is configured incorrectly\n");
1193 return -EINVAL;
1194 }
1195 if ((chip_info->iface == SSP_INTERFACE_UNIDIRECTIONAL) &&
1196 (!pl022->vendor->unidir)) {
1197 dev_err(chip_info->dev,
1198 "unidirectional mode not supported in this "
1199 "hardware version\n");
1200 return -EINVAL;
1201 }
1202 if ((chip_info->hierarchy != SSP_MASTER)
1203 && (chip_info->hierarchy != SSP_SLAVE)) {
1204 dev_err(chip_info->dev,
1205 "hierarchy is configured incorrectly\n");
1206 return -EINVAL;
1207 }
1208 if (((chip_info->clk_freq).cpsdvsr < CPSDVR_MIN)
1209 || ((chip_info->clk_freq).cpsdvsr > CPSDVR_MAX)) {
1210 dev_err(chip_info->dev,
1211 "cpsdvsr is configured incorrectly\n");
1212 return -EINVAL;
1213 }
1214 if ((chip_info->endian_rx != SSP_RX_MSB)
1215 && (chip_info->endian_rx != SSP_RX_LSB)) {
1216 dev_err(chip_info->dev,
1217 "RX FIFO endianess is configured incorrectly\n");
1218 return -EINVAL;
1219 }
1220 if ((chip_info->endian_tx != SSP_TX_MSB)
1221 && (chip_info->endian_tx != SSP_TX_LSB)) {
1222 dev_err(chip_info->dev,
1223 "TX FIFO endianess is configured incorrectly\n");
1224 return -EINVAL;
1225 }
1226 if ((chip_info->data_size < SSP_DATA_BITS_4)
1227 || (chip_info->data_size > SSP_DATA_BITS_32)) {
1228 dev_err(chip_info->dev,
1229 "DATA Size is configured incorrectly\n");
1230 return -EINVAL;
1231 }
1232 if ((chip_info->com_mode != INTERRUPT_TRANSFER)
1233 && (chip_info->com_mode != DMA_TRANSFER)
1234 && (chip_info->com_mode != POLLING_TRANSFER)) {
1235 dev_err(chip_info->dev,
1236 "Communication mode is configured incorrectly\n");
1237 return -EINVAL;
1238 }
1239 if ((chip_info->rx_lev_trig < SSP_RX_1_OR_MORE_ELEM)
1240 || (chip_info->rx_lev_trig > SSP_RX_32_OR_MORE_ELEM)) {
1241 dev_err(chip_info->dev,
1242 "RX FIFO Trigger Level is configured incorrectly\n");
1243 return -EINVAL;
1244 }
1245 if ((chip_info->tx_lev_trig < SSP_TX_1_OR_MORE_EMPTY_LOC)
1246 || (chip_info->tx_lev_trig > SSP_TX_32_OR_MORE_EMPTY_LOC)) {
1247 dev_err(chip_info->dev,
1248 "TX FIFO Trigger Level is configured incorrectly\n");
1249 return -EINVAL;
1250 }
1251 if (chip_info->iface == SSP_INTERFACE_MOTOROLA_SPI) {
1252 if ((chip_info->clk_phase != SSP_CLK_RISING_EDGE)
1253 && (chip_info->clk_phase != SSP_CLK_FALLING_EDGE)) {
1254 dev_err(chip_info->dev,
1255 "Clock Phase is configured incorrectly\n");
1256 return -EINVAL;
1257 }
1258 if ((chip_info->clk_pol != SSP_CLK_POL_IDLE_LOW)
1259 && (chip_info->clk_pol != SSP_CLK_POL_IDLE_HIGH)) {
1260 dev_err(chip_info->dev,
1261 "Clock Polarity is configured incorrectly\n");
1262 return -EINVAL;
1263 }
1264 }
1265 if (chip_info->iface == SSP_INTERFACE_NATIONAL_MICROWIRE) {
1266 if ((chip_info->ctrl_len < SSP_BITS_4)
1267 || (chip_info->ctrl_len > SSP_BITS_32)) {
1268 dev_err(chip_info->dev,
1269 "CTRL LEN is configured incorrectly\n");
1270 return -EINVAL;
1271 }
1272 if ((chip_info->wait_state != SSP_MWIRE_WAIT_ZERO)
1273 && (chip_info->wait_state != SSP_MWIRE_WAIT_ONE)) {
1274 dev_err(chip_info->dev,
1275 "Wait State is configured incorrectly\n");
1276 return -EINVAL;
1277 }
1278 if ((chip_info->duplex != SSP_MICROWIRE_CHANNEL_FULL_DUPLEX)
1279 && (chip_info->duplex !=
1280 SSP_MICROWIRE_CHANNEL_HALF_DUPLEX)) {
1281 dev_err(chip_info->dev,
1282 "DUPLEX is configured incorrectly\n");
1283 return -EINVAL;
1284 }
1285 }
1286 if (chip_info->cs_control == NULL) {
1287 dev_warn(chip_info->dev,
1288 "Chip Select Function is NULL for this chip\n");
1289 chip_info->cs_control = null_cs_control;
1290 }
1291 return 0;
1292}
1293
1294/**
1295 * pl022_transfer - transfer function registered to SPI master framework
1296 * @spi: spi device which is requesting transfer
1297 * @msg: spi message which is to handled is queued to driver queue
1298 *
1299 * This function is registered to the SPI framework for this SPI master
1300 * controller. It will queue the spi_message in the queue of driver if
1301 * the queue is not stopped and return.
1302 */
1303static int pl022_transfer(struct spi_device *spi, struct spi_message *msg)
1304{
1305 struct pl022 *pl022 = spi_master_get_devdata(spi->master);
1306 unsigned long flags;
1307
1308 spin_lock_irqsave(&pl022->queue_lock, flags);
1309
1310 if (pl022->run == QUEUE_STOPPED) {
1311 spin_unlock_irqrestore(&pl022->queue_lock, flags);
1312 return -ESHUTDOWN;
1313 }
1314 msg->actual_length = 0;
1315 msg->status = -EINPROGRESS;
1316 msg->state = STATE_START;
1317
1318 list_add_tail(&msg->queue, &pl022->queue);
1319 if (pl022->run == QUEUE_RUNNING && !pl022->busy)
1320 queue_work(pl022->workqueue, &pl022->pump_messages);
1321
1322 spin_unlock_irqrestore(&pl022->queue_lock, flags);
1323 return 0;
1324}
1325
1326static int calculate_effective_freq(struct pl022 *pl022,
1327 int freq,
1328 struct ssp_clock_params *clk_freq)
1329{
1330 /* Lets calculate the frequency parameters */
1331 u16 cpsdvsr = 2;
1332 u16 scr = 0;
1333 bool freq_found = false;
1334 u32 rate;
1335 u32 max_tclk;
1336 u32 min_tclk;
1337
1338 rate = clk_get_rate(pl022->clk);
1339 /* cpsdvscr = 2 & scr 0 */
1340 max_tclk = (rate / (CPSDVR_MIN * (1 + SCR_MIN)));
1341 /* cpsdvsr = 254 & scr = 255 */
1342 min_tclk = (rate / (CPSDVR_MAX * (1 + SCR_MAX)));
1343
1344 if ((freq <= max_tclk) && (freq >= min_tclk)) {
1345 while (cpsdvsr <= CPSDVR_MAX && !freq_found) {
1346 while (scr <= SCR_MAX && !freq_found) {
1347 if ((rate /
1348 (cpsdvsr * (1 + scr))) > freq)
1349 scr += 1;
1350 else {
1351 /*
1352 * This bool is made true when
1353 * effective frequency >=
1354 * target frequency is found
1355 */
1356 freq_found = true;
1357 if ((rate /
1358 (cpsdvsr * (1 + scr))) != freq) {
1359 if (scr == SCR_MIN) {
1360 cpsdvsr -= 2;
1361 scr = SCR_MAX;
1362 } else
1363 scr -= 1;
1364 }
1365 }
1366 }
1367 if (!freq_found) {
1368 cpsdvsr += 2;
1369 scr = SCR_MIN;
1370 }
1371 }
1372 if (cpsdvsr != 0) {
1373 dev_dbg(&pl022->adev->dev,
1374 "SSP Effective Frequency is %u\n",
1375 (rate / (cpsdvsr * (1 + scr))));
1376 clk_freq->cpsdvsr = (u8) (cpsdvsr & 0xFF);
1377 clk_freq->scr = (u8) (scr & 0xFF);
1378 dev_dbg(&pl022->adev->dev,
1379 "SSP cpsdvsr = %d, scr = %d\n",
1380 clk_freq->cpsdvsr, clk_freq->scr);
1381 }
1382 } else {
1383 dev_err(&pl022->adev->dev,
1384 "controller data is incorrect: out of range frequency");
1385 return -EINVAL;
1386 }
1387 return 0;
1388}
1389
1390/**
1391 * NOT IMPLEMENTED
1392 * process_dma_info - Processes the DMA info provided by client drivers
1393 * @chip_info: chip info provided by client device
1394 * @chip: Runtime state maintained by the SSP controller for each spi device
1395 *
1396 * This function processes and stores DMA config provided by client driver
1397 * into the runtime state maintained by the SSP controller driver
1398 */
1399static int process_dma_info(struct pl022_config_chip *chip_info,
1400 struct chip_data *chip)
1401{
1402 dev_err(chip_info->dev,
1403 "cannot process DMA info, DMA not implemented!\n");
1404 return -ENOTSUPP;
1405}
1406
1407/**
1408 * pl022_setup - setup function registered to SPI master framework
1409 * @spi: spi device which is requesting setup
1410 *
1411 * This function is registered to the SPI framework for this SPI master
1412 * controller. If it is the first time when setup is called by this device,
1413 * this function will initialize the runtime state for this chip and save
1414 * the same in the device structure. Else it will update the runtime info
1415 * with the updated chip info. Nothing is really being written to the
1416 * controller hardware here, that is not done until the actual transfer
1417 * commence.
1418 */
1419
1420/* FIXME: JUST GUESSING the spi->mode bits understood by this driver */
1421#define MODEBITS (SPI_CPOL | SPI_CPHA | SPI_CS_HIGH \
1422 | SPI_LSB_FIRST | SPI_LOOP)
1423
1424static int pl022_setup(struct spi_device *spi)
1425{
1426 struct pl022_config_chip *chip_info;
1427 struct chip_data *chip;
1428 int status = 0;
1429 struct pl022 *pl022 = spi_master_get_devdata(spi->master);
1430
1431 if (spi->mode & ~MODEBITS) {
1432 dev_dbg(&spi->dev, "unsupported mode bits %x\n",
1433 spi->mode & ~MODEBITS);
1434 return -EINVAL;
1435 }
1436
1437 if (!spi->max_speed_hz)
1438 return -EINVAL;
1439
1440 /* Get controller_state if one is supplied */
1441 chip = spi_get_ctldata(spi);
1442
1443 if (chip == NULL) {
1444 chip = kzalloc(sizeof(struct chip_data), GFP_KERNEL);
1445 if (!chip) {
1446 dev_err(&spi->dev,
1447 "cannot allocate controller state\n");
1448 return -ENOMEM;
1449 }
1450 dev_dbg(&spi->dev,
1451 "allocated memory for controller's runtime state\n");
1452 }
1453
1454 /* Get controller data if one is supplied */
1455 chip_info = spi->controller_data;
1456
1457 if (chip_info == NULL) {
1458 /* spi_board_info.controller_data not is supplied */
1459 dev_dbg(&spi->dev,
1460 "using default controller_data settings\n");
1461
1462 chip_info =
1463 kzalloc(sizeof(struct pl022_config_chip), GFP_KERNEL);
1464
1465 if (!chip_info) {
1466 dev_err(&spi->dev,
1467 "cannot allocate controller data\n");
1468 status = -ENOMEM;
1469 goto err_first_setup;
1470 }
1471
1472 dev_dbg(&spi->dev, "allocated memory for controller data\n");
1473
1474 /* Pointer back to the SPI device */
1475 chip_info->dev = &spi->dev;
1476 /*
1477 * Set controller data default values:
1478 * Polling is supported by default
1479 */
1480 chip_info->lbm = LOOPBACK_DISABLED;
1481 chip_info->com_mode = POLLING_TRANSFER;
1482 chip_info->iface = SSP_INTERFACE_MOTOROLA_SPI;
1483 chip_info->hierarchy = SSP_SLAVE;
1484 chip_info->slave_tx_disable = DO_NOT_DRIVE_TX;
1485 chip_info->endian_tx = SSP_TX_LSB;
1486 chip_info->endian_rx = SSP_RX_LSB;
1487 chip_info->data_size = SSP_DATA_BITS_12;
1488 chip_info->rx_lev_trig = SSP_RX_1_OR_MORE_ELEM;
1489 chip_info->tx_lev_trig = SSP_TX_1_OR_MORE_EMPTY_LOC;
1490 chip_info->clk_phase = SSP_CLK_FALLING_EDGE;
1491 chip_info->clk_pol = SSP_CLK_POL_IDLE_LOW;
1492 chip_info->ctrl_len = SSP_BITS_8;
1493 chip_info->wait_state = SSP_MWIRE_WAIT_ZERO;
1494 chip_info->duplex = SSP_MICROWIRE_CHANNEL_FULL_DUPLEX;
1495 chip_info->cs_control = null_cs_control;
1496 } else {
1497 dev_dbg(&spi->dev,
1498 "using user supplied controller_data settings\n");
1499 }
1500
1501 /*
1502 * We can override with custom divisors, else we use the board
1503 * frequency setting
1504 */
1505 if ((0 == chip_info->clk_freq.cpsdvsr)
1506 && (0 == chip_info->clk_freq.scr)) {
1507 status = calculate_effective_freq(pl022,
1508 spi->max_speed_hz,
1509 &chip_info->clk_freq);
1510 if (status < 0)
1511 goto err_config_params;
1512 } else {
1513 if ((chip_info->clk_freq.cpsdvsr % 2) != 0)
1514 chip_info->clk_freq.cpsdvsr =
1515 chip_info->clk_freq.cpsdvsr - 1;
1516 }
1517 status = verify_controller_parameters(pl022, chip_info);
1518 if (status) {
1519 dev_err(&spi->dev, "controller data is incorrect");
1520 goto err_config_params;
1521 }
1522 /* Now set controller state based on controller data */
1523 chip->xfer_type = chip_info->com_mode;
1524 chip->cs_control = chip_info->cs_control;
1525
1526 if (chip_info->data_size <= 8) {
1527 dev_dbg(&spi->dev, "1 <= n <=8 bits per word\n");
1528 chip->n_bytes = 1;
1529 chip->read = READING_U8;
1530 chip->write = WRITING_U8;
1531 } else if (chip_info->data_size <= 16) {
1532 dev_dbg(&spi->dev, "9 <= n <= 16 bits per word\n");
1533 chip->n_bytes = 2;
1534 chip->read = READING_U16;
1535 chip->write = WRITING_U16;
1536 } else {
1537 if (pl022->vendor->max_bpw >= 32) {
1538 dev_dbg(&spi->dev, "17 <= n <= 32 bits per word\n");
1539 chip->n_bytes = 4;
1540 chip->read = READING_U32;
1541 chip->write = WRITING_U32;
1542 } else {
1543 dev_err(&spi->dev,
1544 "illegal data size for this controller!\n");
1545 dev_err(&spi->dev,
1546 "a standard pl022 can only handle "
1547 "1 <= n <= 16 bit words\n");
1548 goto err_config_params;
1549 }
1550 }
1551
1552 /* Now Initialize all register settings required for this chip */
1553 chip->cr0 = 0;
1554 chip->cr1 = 0;
1555 chip->dmacr = 0;
1556 chip->cpsr = 0;
1557 if ((chip_info->com_mode == DMA_TRANSFER)
1558 && ((pl022->master_info)->enable_dma)) {
1559 chip->enable_dma = 1;
1560 dev_dbg(&spi->dev, "DMA mode set in controller state\n");
1561 status = process_dma_info(chip_info, chip);
1562 if (status < 0)
1563 goto err_config_params;
1564 SSP_WRITE_BITS(chip->dmacr, SSP_DMA_ENABLED,
1565 SSP_DMACR_MASK_RXDMAE, 0);
1566 SSP_WRITE_BITS(chip->dmacr, SSP_DMA_ENABLED,
1567 SSP_DMACR_MASK_TXDMAE, 1);
1568 } else {
1569 chip->enable_dma = 0;
1570 dev_dbg(&spi->dev, "DMA mode NOT set in controller state\n");
1571 SSP_WRITE_BITS(chip->dmacr, SSP_DMA_DISABLED,
1572 SSP_DMACR_MASK_RXDMAE, 0);
1573 SSP_WRITE_BITS(chip->dmacr, SSP_DMA_DISABLED,
1574 SSP_DMACR_MASK_TXDMAE, 1);
1575 }
1576
1577 chip->cpsr = chip_info->clk_freq.cpsdvsr;
1578
1579 SSP_WRITE_BITS(chip->cr0, chip_info->data_size, SSP_CR0_MASK_DSS, 0);
1580 SSP_WRITE_BITS(chip->cr0, chip_info->duplex, SSP_CR0_MASK_HALFDUP, 5);
1581 SSP_WRITE_BITS(chip->cr0, chip_info->clk_pol, SSP_CR0_MASK_SPO, 6);
1582 SSP_WRITE_BITS(chip->cr0, chip_info->clk_phase, SSP_CR0_MASK_SPH, 7);
1583 SSP_WRITE_BITS(chip->cr0, chip_info->clk_freq.scr, SSP_CR0_MASK_SCR, 8);
1584 SSP_WRITE_BITS(chip->cr0, chip_info->ctrl_len, SSP_CR0_MASK_CSS, 16);
1585 SSP_WRITE_BITS(chip->cr0, chip_info->iface, SSP_CR0_MASK_FRF, 21);
1586 SSP_WRITE_BITS(chip->cr1, chip_info->lbm, SSP_CR1_MASK_LBM, 0);
1587 SSP_WRITE_BITS(chip->cr1, SSP_DISABLED, SSP_CR1_MASK_SSE, 1);
1588 SSP_WRITE_BITS(chip->cr1, chip_info->hierarchy, SSP_CR1_MASK_MS, 2);
1589 SSP_WRITE_BITS(chip->cr1, chip_info->slave_tx_disable, SSP_CR1_MASK_SOD, 3);
1590 SSP_WRITE_BITS(chip->cr1, chip_info->endian_rx, SSP_CR1_MASK_RENDN, 4);
1591 SSP_WRITE_BITS(chip->cr1, chip_info->endian_tx, SSP_CR1_MASK_TENDN, 5);
1592 SSP_WRITE_BITS(chip->cr1, chip_info->wait_state, SSP_CR1_MASK_MWAIT, 6);
1593 SSP_WRITE_BITS(chip->cr1, chip_info->rx_lev_trig, SSP_CR1_MASK_RXIFLSEL, 7);
1594 SSP_WRITE_BITS(chip->cr1, chip_info->tx_lev_trig, SSP_CR1_MASK_TXIFLSEL, 10);
1595
1596 /* Save controller_state */
1597 spi_set_ctldata(spi, chip);
1598 return status;
1599 err_config_params:
1600 err_first_setup:
1601 kfree(chip);
1602 return status;
1603}
1604
1605/**
1606 * pl022_cleanup - cleanup function registered to SPI master framework
1607 * @spi: spi device which is requesting cleanup
1608 *
1609 * This function is registered to the SPI framework for this SPI master
1610 * controller. It will free the runtime state of chip.
1611 */
1612static void pl022_cleanup(struct spi_device *spi)
1613{
1614 struct chip_data *chip = spi_get_ctldata(spi);
1615
1616 spi_set_ctldata(spi, NULL);
1617 kfree(chip);
1618}
1619
1620
1621static int __init
1622pl022_probe(struct amba_device *adev, struct amba_id *id)
1623{
1624 struct device *dev = &adev->dev;
1625 struct pl022_ssp_controller *platform_info = adev->dev.platform_data;
1626 struct spi_master *master;
1627 struct pl022 *pl022 = NULL; /*Data for this driver */
1628 int status = 0;
1629
1630 dev_info(&adev->dev,
1631 "ARM PL022 driver, device ID: 0x%08x\n", adev->periphid);
1632 if (platform_info == NULL) {
1633 dev_err(&adev->dev, "probe - no platform data supplied\n");
1634 status = -ENODEV;
1635 goto err_no_pdata;
1636 }
1637
1638 /* Allocate master with space for data */
1639 master = spi_alloc_master(dev, sizeof(struct pl022));
1640 if (master == NULL) {
1641 dev_err(&adev->dev, "probe - cannot alloc SPI master\n");
1642 status = -ENOMEM;
1643 goto err_no_master;
1644 }
1645
1646 pl022 = spi_master_get_devdata(master);
1647 pl022->master = master;
1648 pl022->master_info = platform_info;
1649 pl022->adev = adev;
1650 pl022->vendor = id->data;
1651
1652 /*
1653 * Bus Number Which has been Assigned to this SSP controller
1654 * on this board
1655 */
1656 master->bus_num = platform_info->bus_id;
1657 master->num_chipselect = platform_info->num_chipselect;
1658 master->cleanup = pl022_cleanup;
1659 master->setup = pl022_setup;
1660 master->transfer = pl022_transfer;
1661
1662 dev_dbg(&adev->dev, "BUSNO: %d\n", master->bus_num);
1663
1664 status = amba_request_regions(adev, NULL);
1665 if (status)
1666 goto err_no_ioregion;
1667
1668 pl022->virtbase = ioremap(adev->res.start, resource_size(&adev->res));
1669 if (pl022->virtbase == NULL) {
1670 status = -ENOMEM;
1671 goto err_no_ioremap;
1672 }
1673 printk(KERN_INFO "pl022: mapped registers from 0x%08x to %p\n",
1674 adev->res.start, pl022->virtbase);
1675
1676 pl022->clk = clk_get(&adev->dev, NULL);
1677 if (IS_ERR(pl022->clk)) {
1678 status = PTR_ERR(pl022->clk);
1679 dev_err(&adev->dev, "could not retrieve SSP/SPI bus clock\n");
1680 goto err_no_clk;
1681 }
1682
1683 /* Disable SSP */
1684 clk_enable(pl022->clk);
1685 writew((readw(SSP_CR1(pl022->virtbase)) & (~SSP_CR1_MASK_SSE)),
1686 SSP_CR1(pl022->virtbase));
1687 load_ssp_default_config(pl022);
1688 clk_disable(pl022->clk);
1689
1690 status = request_irq(adev->irq[0], pl022_interrupt_handler, 0, "pl022",
1691 pl022);
1692 if (status < 0) {
1693 dev_err(&adev->dev, "probe - cannot get IRQ (%d)\n", status);
1694 goto err_no_irq;
1695 }
1696 /* Initialize and start queue */
1697 status = init_queue(pl022);
1698 if (status != 0) {
1699 dev_err(&adev->dev, "probe - problem initializing queue\n");
1700 goto err_init_queue;
1701 }
1702 status = start_queue(pl022);
1703 if (status != 0) {
1704 dev_err(&adev->dev, "probe - problem starting queue\n");
1705 goto err_start_queue;
1706 }
1707 /* Register with the SPI framework */
1708 amba_set_drvdata(adev, pl022);
1709 status = spi_register_master(master);
1710 if (status != 0) {
1711 dev_err(&adev->dev,
1712 "probe - problem registering spi master\n");
1713 goto err_spi_register;
1714 }
1715 dev_dbg(dev, "probe succeded\n");
1716 return 0;
1717
1718 err_spi_register:
1719 err_start_queue:
1720 err_init_queue:
1721 destroy_queue(pl022);
1722 free_irq(adev->irq[0], pl022);
1723 err_no_irq:
1724 clk_put(pl022->clk);
1725 err_no_clk:
1726 iounmap(pl022->virtbase);
1727 err_no_ioremap:
1728 amba_release_regions(adev);
1729 err_no_ioregion:
1730 spi_master_put(master);
1731 err_no_master:
1732 err_no_pdata:
1733 return status;
1734}
1735
1736static int __exit
1737pl022_remove(struct amba_device *adev)
1738{
1739 struct pl022 *pl022 = amba_get_drvdata(adev);
1740 int status = 0;
1741 if (!pl022)
1742 return 0;
1743
1744 /* Remove the queue */
1745 status = destroy_queue(pl022);
1746 if (status != 0) {
1747 dev_err(&adev->dev,
1748 "queue remove failed (%d)\n", status);
1749 return status;
1750 }
1751 load_ssp_default_config(pl022);
1752 free_irq(adev->irq[0], pl022);
1753 clk_disable(pl022->clk);
1754 clk_put(pl022->clk);
1755 iounmap(pl022->virtbase);
1756 amba_release_regions(adev);
1757 tasklet_disable(&pl022->pump_transfers);
1758 spi_unregister_master(pl022->master);
1759 spi_master_put(pl022->master);
1760 amba_set_drvdata(adev, NULL);
1761 dev_dbg(&adev->dev, "remove succeded\n");
1762 return 0;
1763}
1764
1765#ifdef CONFIG_PM
1766static int pl022_suspend(struct amba_device *adev, pm_message_t state)
1767{
1768 struct pl022 *pl022 = amba_get_drvdata(adev);
1769 int status = 0;
1770
1771 status = stop_queue(pl022);
1772 if (status) {
1773 dev_warn(&adev->dev, "suspend cannot stop queue\n");
1774 return status;
1775 }
1776
1777 clk_enable(pl022->clk);
1778 load_ssp_default_config(pl022);
1779 clk_disable(pl022->clk);
1780 dev_dbg(&adev->dev, "suspended\n");
1781 return 0;
1782}
1783
1784static int pl022_resume(struct amba_device *adev)
1785{
1786 struct pl022 *pl022 = amba_get_drvdata(adev);
1787 int status = 0;
1788
1789 /* Start the queue running */
1790 status = start_queue(pl022);
1791 if (status)
1792 dev_err(&adev->dev, "problem starting queue (%d)\n", status);
1793 else
1794 dev_dbg(&adev->dev, "resumed\n");
1795
1796 return status;
1797}
1798#else
1799#define pl022_suspend NULL
1800#define pl022_resume NULL
1801#endif /* CONFIG_PM */
1802
1803static struct vendor_data vendor_arm = {
1804 .fifodepth = 8,
1805 .max_bpw = 16,
1806 .unidir = false,
1807};
1808
1809
1810static struct vendor_data vendor_st = {
1811 .fifodepth = 32,
1812 .max_bpw = 32,
1813 .unidir = false,
1814};
1815
1816static struct amba_id pl022_ids[] = {
1817 {
1818 /*
1819 * ARM PL022 variant, this has a 16bit wide
1820 * and 8 locations deep TX/RX FIFO
1821 */
1822 .id = 0x00041022,
1823 .mask = 0x000fffff,
1824 .data = &vendor_arm,
1825 },
1826 {
1827 /*
1828 * ST Micro derivative, this has 32bit wide
1829 * and 32 locations deep TX/RX FIFO
1830 */
1831 .id = 0x00108022,
1832 .mask = 0xffffffff,
1833 .data = &vendor_st,
1834 },
1835 { 0, 0 },
1836};
1837
1838static struct amba_driver pl022_driver = {
1839 .drv = {
1840 .name = "ssp-pl022",
1841 },
1842 .id_table = pl022_ids,
1843 .probe = pl022_probe,
1844 .remove = __exit_p(pl022_remove),
1845 .suspend = pl022_suspend,
1846 .resume = pl022_resume,
1847};
1848
1849
1850static int __init pl022_init(void)
1851{
1852 return amba_driver_register(&pl022_driver);
1853}
1854
1855module_init(pl022_init);
1856
1857static void __exit pl022_exit(void)
1858{
1859 amba_driver_unregister(&pl022_driver);
1860}
1861
1862module_exit(pl022_exit);
1863
1864MODULE_AUTHOR("Linus Walleij <linus.walleij@stericsson.com>");
1865MODULE_DESCRIPTION("PL022 SSP Controller Driver");
1866MODULE_LICENSE("GPL");
diff --git a/drivers/spi/atmel_spi.c b/drivers/spi/atmel_spi.c
index 12e443cc4ac9..f5b3fdbb1e27 100644
--- a/drivers/spi/atmel_spi.c
+++ b/drivers/spi/atmel_spi.c
@@ -530,9 +530,6 @@ atmel_spi_interrupt(int irq, void *dev_id)
530 return ret; 530 return ret;
531} 531}
532 532
533/* the spi->mode bits understood by this driver: */
534#define MODEBITS (SPI_CPOL | SPI_CPHA | SPI_CS_HIGH)
535
536static int atmel_spi_setup(struct spi_device *spi) 533static int atmel_spi_setup(struct spi_device *spi)
537{ 534{
538 struct atmel_spi *as; 535 struct atmel_spi *as;
@@ -555,8 +552,6 @@ static int atmel_spi_setup(struct spi_device *spi)
555 return -EINVAL; 552 return -EINVAL;
556 } 553 }
557 554
558 if (bits == 0)
559 bits = 8;
560 if (bits < 8 || bits > 16) { 555 if (bits < 8 || bits > 16) {
561 dev_dbg(&spi->dev, 556 dev_dbg(&spi->dev,
562 "setup: invalid bits_per_word %u (8 to 16)\n", 557 "setup: invalid bits_per_word %u (8 to 16)\n",
@@ -564,12 +559,6 @@ static int atmel_spi_setup(struct spi_device *spi)
564 return -EINVAL; 559 return -EINVAL;
565 } 560 }
566 561
567 if (spi->mode & ~MODEBITS) {
568 dev_dbg(&spi->dev, "setup: unsupported mode bits %x\n",
569 spi->mode & ~MODEBITS);
570 return -EINVAL;
571 }
572
573 /* see notes above re chipselect */ 562 /* see notes above re chipselect */
574 if (!atmel_spi_is_v2() 563 if (!atmel_spi_is_v2()
575 && spi->chip_select == 0 564 && spi->chip_select == 0
@@ -775,6 +764,9 @@ static int __init atmel_spi_probe(struct platform_device *pdev)
775 if (!master) 764 if (!master)
776 goto out_free; 765 goto out_free;
777 766
767 /* the spi->mode bits understood by this driver: */
768 master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH;
769
778 master->bus_num = pdev->id; 770 master->bus_num = pdev->id;
779 master->num_chipselect = 4; 771 master->num_chipselect = 4;
780 master->setup = atmel_spi_setup; 772 master->setup = atmel_spi_setup;
diff --git a/drivers/spi/au1550_spi.c b/drivers/spi/au1550_spi.c
index b02f25c702fd..76cbc1a66598 100644
--- a/drivers/spi/au1550_spi.c
+++ b/drivers/spi/au1550_spi.c
@@ -284,27 +284,16 @@ static int au1550_spi_setupxfer(struct spi_device *spi, struct spi_transfer *t)
284 return 0; 284 return 0;
285} 285}
286 286
287/* the spi->mode bits understood by this driver: */
288#define MODEBITS (SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_LSB_FIRST)
289
290static int au1550_spi_setup(struct spi_device *spi) 287static int au1550_spi_setup(struct spi_device *spi)
291{ 288{
292 struct au1550_spi *hw = spi_master_get_devdata(spi->master); 289 struct au1550_spi *hw = spi_master_get_devdata(spi->master);
293 290
294 if (spi->bits_per_word == 0)
295 spi->bits_per_word = 8;
296 if (spi->bits_per_word < 4 || spi->bits_per_word > 24) { 291 if (spi->bits_per_word < 4 || spi->bits_per_word > 24) {
297 dev_err(&spi->dev, "setup: invalid bits_per_word=%d\n", 292 dev_err(&spi->dev, "setup: invalid bits_per_word=%d\n",
298 spi->bits_per_word); 293 spi->bits_per_word);
299 return -EINVAL; 294 return -EINVAL;
300 } 295 }
301 296
302 if (spi->mode & ~MODEBITS) {
303 dev_dbg(&spi->dev, "setup: unsupported mode bits %x\n",
304 spi->mode & ~MODEBITS);
305 return -EINVAL;
306 }
307
308 if (spi->max_speed_hz == 0) 297 if (spi->max_speed_hz == 0)
309 spi->max_speed_hz = hw->freq_max; 298 spi->max_speed_hz = hw->freq_max;
310 if (spi->max_speed_hz > hw->freq_max 299 if (spi->max_speed_hz > hw->freq_max
@@ -781,6 +770,9 @@ static int __init au1550_spi_probe(struct platform_device *pdev)
781 goto err_nomem; 770 goto err_nomem;
782 } 771 }
783 772
773 /* the spi->mode bits understood by this driver: */
774 master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_LSB_FIRST;
775
784 hw = spi_master_get_devdata(master); 776 hw = spi_master_get_devdata(master);
785 777
786 hw->master = spi_master_get(master); 778 hw->master = spi_master_get(master);
diff --git a/drivers/spi/mpc52xx_psc_spi.c b/drivers/spi/mpc52xx_psc_spi.c
index 68c77a911595..1b74d5ca03f3 100644
--- a/drivers/spi/mpc52xx_psc_spi.c
+++ b/drivers/spi/mpc52xx_psc_spi.c
@@ -13,6 +13,7 @@
13 13
14#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/init.h> 15#include <linux/init.h>
16#include <linux/types.h>
16#include <linux/errno.h> 17#include <linux/errno.h>
17#include <linux/interrupt.h> 18#include <linux/interrupt.h>
18#include <linux/of_platform.h> 19#include <linux/of_platform.h>
@@ -30,8 +31,7 @@
30 31
31struct mpc52xx_psc_spi { 32struct mpc52xx_psc_spi {
32 /* fsl_spi_platform data */ 33 /* fsl_spi_platform data */
33 void (*activate_cs)(u8, u8); 34 void (*cs_control)(struct spi_device *spi, bool on);
34 void (*deactivate_cs)(u8, u8);
35 u32 sysclk; 35 u32 sysclk;
36 36
37 /* driver internal data */ 37 /* driver internal data */
@@ -111,18 +111,16 @@ static void mpc52xx_psc_spi_activate_cs(struct spi_device *spi)
111 out_be16((u16 __iomem *)&psc->ccr, ccr); 111 out_be16((u16 __iomem *)&psc->ccr, ccr);
112 mps->bits_per_word = cs->bits_per_word; 112 mps->bits_per_word = cs->bits_per_word;
113 113
114 if (mps->activate_cs) 114 if (mps->cs_control)
115 mps->activate_cs(spi->chip_select, 115 mps->cs_control(spi, (spi->mode & SPI_CS_HIGH) ? 1 : 0);
116 (spi->mode & SPI_CS_HIGH) ? 1 : 0);
117} 116}
118 117
119static void mpc52xx_psc_spi_deactivate_cs(struct spi_device *spi) 118static void mpc52xx_psc_spi_deactivate_cs(struct spi_device *spi)
120{ 119{
121 struct mpc52xx_psc_spi *mps = spi_master_get_devdata(spi->master); 120 struct mpc52xx_psc_spi *mps = spi_master_get_devdata(spi->master);
122 121
123 if (mps->deactivate_cs) 122 if (mps->cs_control)
124 mps->deactivate_cs(spi->chip_select, 123 mps->cs_control(spi, (spi->mode & SPI_CS_HIGH) ? 0 : 1);
125 (spi->mode & SPI_CS_HIGH) ? 1 : 0);
126} 124}
127 125
128#define MPC52xx_PSC_BUFSIZE (MPC52xx_PSC_RFNUM_MASK + 1) 126#define MPC52xx_PSC_BUFSIZE (MPC52xx_PSC_RFNUM_MASK + 1)
@@ -261,9 +259,6 @@ static void mpc52xx_psc_spi_work(struct work_struct *work)
261 spin_unlock_irq(&mps->lock); 259 spin_unlock_irq(&mps->lock);
262} 260}
263 261
264/* the spi->mode bits understood by this driver: */
265#define MODEBITS (SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_LSB_FIRST)
266
267static int mpc52xx_psc_spi_setup(struct spi_device *spi) 262static int mpc52xx_psc_spi_setup(struct spi_device *spi)
268{ 263{
269 struct mpc52xx_psc_spi *mps = spi_master_get_devdata(spi->master); 264 struct mpc52xx_psc_spi *mps = spi_master_get_devdata(spi->master);
@@ -273,12 +268,6 @@ static int mpc52xx_psc_spi_setup(struct spi_device *spi)
273 if (spi->bits_per_word%8) 268 if (spi->bits_per_word%8)
274 return -EINVAL; 269 return -EINVAL;
275 270
276 if (spi->mode & ~MODEBITS) {
277 dev_dbg(&spi->dev, "setup: unsupported mode bits %x\n",
278 spi->mode & ~MODEBITS);
279 return -EINVAL;
280 }
281
282 if (!cs) { 271 if (!cs) {
283 cs = kzalloc(sizeof *cs, GFP_KERNEL); 272 cs = kzalloc(sizeof *cs, GFP_KERNEL);
284 if (!cs) 273 if (!cs)
@@ -385,18 +374,19 @@ static int __init mpc52xx_psc_spi_do_probe(struct device *dev, u32 regaddr,
385 dev_set_drvdata(dev, master); 374 dev_set_drvdata(dev, master);
386 mps = spi_master_get_devdata(master); 375 mps = spi_master_get_devdata(master);
387 376
377 /* the spi->mode bits understood by this driver: */
378 master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_LSB_FIRST;
379
388 mps->irq = irq; 380 mps->irq = irq;
389 if (pdata == NULL) { 381 if (pdata == NULL) {
390 dev_warn(dev, "probe called without platform data, no " 382 dev_warn(dev, "probe called without platform data, no "
391 "(de)activate_cs function will be called\n"); 383 "cs_control function will be called\n");
392 mps->activate_cs = NULL; 384 mps->cs_control = NULL;
393 mps->deactivate_cs = NULL;
394 mps->sysclk = 0; 385 mps->sysclk = 0;
395 master->bus_num = bus_num; 386 master->bus_num = bus_num;
396 master->num_chipselect = 255; 387 master->num_chipselect = 255;
397 } else { 388 } else {
398 mps->activate_cs = pdata->activate_cs; 389 mps->cs_control = pdata->cs_control;
399 mps->deactivate_cs = pdata->deactivate_cs;
400 mps->sysclk = pdata->sysclk; 390 mps->sysclk = pdata->sysclk;
401 master->bus_num = pdata->bus_num; 391 master->bus_num = pdata->bus_num;
402 master->num_chipselect = pdata->max_chipselect; 392 master->num_chipselect = pdata->max_chipselect;
diff --git a/drivers/spi/omap2_mcspi.c b/drivers/spi/omap2_mcspi.c
index d6d0c5d241ce..eee4b6e0af2c 100644
--- a/drivers/spi/omap2_mcspi.c
+++ b/drivers/spi/omap2_mcspi.c
@@ -603,9 +603,6 @@ static int omap2_mcspi_request_dma(struct spi_device *spi)
603 return 0; 603 return 0;
604} 604}
605 605
606/* the spi->mode bits understood by this driver: */
607#define MODEBITS (SPI_CPOL | SPI_CPHA | SPI_CS_HIGH)
608
609static int omap2_mcspi_setup(struct spi_device *spi) 606static int omap2_mcspi_setup(struct spi_device *spi)
610{ 607{
611 int ret; 608 int ret;
@@ -613,15 +610,7 @@ static int omap2_mcspi_setup(struct spi_device *spi)
613 struct omap2_mcspi_dma *mcspi_dma; 610 struct omap2_mcspi_dma *mcspi_dma;
614 struct omap2_mcspi_cs *cs = spi->controller_state; 611 struct omap2_mcspi_cs *cs = spi->controller_state;
615 612
616 if (spi->mode & ~MODEBITS) { 613 if (spi->bits_per_word < 4 || spi->bits_per_word > 32) {
617 dev_dbg(&spi->dev, "setup: unsupported mode bits %x\n",
618 spi->mode & ~MODEBITS);
619 return -EINVAL;
620 }
621
622 if (spi->bits_per_word == 0)
623 spi->bits_per_word = 8;
624 else if (spi->bits_per_word < 4 || spi->bits_per_word > 32) {
625 dev_dbg(&spi->dev, "setup: unsupported %d bit words\n", 614 dev_dbg(&spi->dev, "setup: unsupported %d bit words\n",
626 spi->bits_per_word); 615 spi->bits_per_word);
627 return -EINVAL; 616 return -EINVAL;
@@ -984,6 +973,9 @@ static int __init omap2_mcspi_probe(struct platform_device *pdev)
984 return -ENOMEM; 973 return -ENOMEM;
985 } 974 }
986 975
976 /* the spi->mode bits understood by this driver: */
977 master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH;
978
987 if (pdev->id != -1) 979 if (pdev->id != -1)
988 master->bus_num = pdev->id; 980 master->bus_num = pdev->id;
989 981
diff --git a/drivers/spi/omap_uwire.c b/drivers/spi/omap_uwire.c
index fe8b9ac0ccef..aa90ddb37066 100644
--- a/drivers/spi/omap_uwire.c
+++ b/drivers/spi/omap_uwire.c
@@ -339,8 +339,6 @@ static int uwire_setup_transfer(struct spi_device *spi, struct spi_transfer *t)
339 bits = spi->bits_per_word; 339 bits = spi->bits_per_word;
340 if (t != NULL && t->bits_per_word) 340 if (t != NULL && t->bits_per_word)
341 bits = t->bits_per_word; 341 bits = t->bits_per_word;
342 if (!bits)
343 bits = 8;
344 342
345 if (bits > 16) { 343 if (bits > 16) {
346 pr_debug("%s: wordsize %d?\n", dev_name(&spi->dev), bits); 344 pr_debug("%s: wordsize %d?\n", dev_name(&spi->dev), bits);
@@ -449,19 +447,10 @@ done:
449 return status; 447 return status;
450} 448}
451 449
452/* the spi->mode bits understood by this driver: */
453#define MODEBITS (SPI_CPOL | SPI_CPHA | SPI_CS_HIGH)
454
455static int uwire_setup(struct spi_device *spi) 450static int uwire_setup(struct spi_device *spi)
456{ 451{
457 struct uwire_state *ust = spi->controller_state; 452 struct uwire_state *ust = spi->controller_state;
458 453
459 if (spi->mode & ~MODEBITS) {
460 dev_dbg(&spi->dev, "setup: unsupported mode bits %x\n",
461 spi->mode & ~MODEBITS);
462 return -EINVAL;
463 }
464
465 if (ust == NULL) { 454 if (ust == NULL) {
466 ust = kzalloc(sizeof(*ust), GFP_KERNEL); 455 ust = kzalloc(sizeof(*ust), GFP_KERNEL);
467 if (ust == NULL) 456 if (ust == NULL)
@@ -522,6 +511,9 @@ static int __init uwire_probe(struct platform_device *pdev)
522 511
523 uwire_write_reg(UWIRE_SR3, 1); 512 uwire_write_reg(UWIRE_SR3, 1);
524 513
514 /* the spi->mode bits understood by this driver: */
515 master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH;
516
525 master->bus_num = 2; /* "official" */ 517 master->bus_num = 2; /* "official" */
526 master->num_chipselect = 4; 518 master->num_chipselect = 4;
527 master->setup = uwire_setup; 519 master->setup = uwire_setup;
diff --git a/drivers/spi/orion_spi.c b/drivers/spi/orion_spi.c
index c8b0babdc2a6..3aea50da7b29 100644
--- a/drivers/spi/orion_spi.c
+++ b/drivers/spi/orion_spi.c
@@ -358,20 +358,11 @@ static int orion_spi_setup(struct spi_device *spi)
358 358
359 orion_spi = spi_master_get_devdata(spi->master); 359 orion_spi = spi_master_get_devdata(spi->master);
360 360
361 if (spi->mode) {
362 dev_err(&spi->dev, "setup: unsupported mode bits %x\n",
363 spi->mode);
364 return -EINVAL;
365 }
366
367 /* Fix ac timing if required. */ 361 /* Fix ac timing if required. */
368 if (orion_spi->spi_info->enable_clock_fix) 362 if (orion_spi->spi_info->enable_clock_fix)
369 orion_spi_setbits(orion_spi, ORION_SPI_IF_CONFIG_REG, 363 orion_spi_setbits(orion_spi, ORION_SPI_IF_CONFIG_REG,
370 (1 << 14)); 364 (1 << 14));
371 365
372 if (spi->bits_per_word == 0)
373 spi->bits_per_word = 8;
374
375 if ((spi->max_speed_hz == 0) 366 if ((spi->max_speed_hz == 0)
376 || (spi->max_speed_hz > orion_spi->max_speed)) 367 || (spi->max_speed_hz > orion_spi->max_speed))
377 spi->max_speed_hz = orion_spi->max_speed; 368 spi->max_speed_hz = orion_spi->max_speed;
@@ -476,6 +467,9 @@ static int __init orion_spi_probe(struct platform_device *pdev)
476 if (pdev->id != -1) 467 if (pdev->id != -1)
477 master->bus_num = pdev->id; 468 master->bus_num = pdev->id;
478 469
470 /* we support only mode 0, and no options */
471 master->mode_bits = 0;
472
479 master->setup = orion_spi_setup; 473 master->setup = orion_spi_setup;
480 master->transfer = orion_spi_transfer; 474 master->transfer = orion_spi_transfer;
481 master->num_chipselect = ORION_NUM_CHIPSELECTS; 475 master->num_chipselect = ORION_NUM_CHIPSELECTS;
diff --git a/drivers/spi/pxa2xx_spi.c b/drivers/spi/pxa2xx_spi.c
index 3f3c08c6ba4e..d949dbf1141f 100644
--- a/drivers/spi/pxa2xx_spi.c
+++ b/drivers/spi/pxa2xx_spi.c
@@ -1185,9 +1185,6 @@ static int transfer(struct spi_device *spi, struct spi_message *msg)
1185 return 0; 1185 return 0;
1186} 1186}
1187 1187
1188/* the spi->mode bits understood by this driver: */
1189#define MODEBITS (SPI_CPOL | SPI_CPHA)
1190
1191static int setup_cs(struct spi_device *spi, struct chip_data *chip, 1188static int setup_cs(struct spi_device *spi, struct chip_data *chip,
1192 struct pxa2xx_spi_chip *chip_info) 1189 struct pxa2xx_spi_chip *chip_info)
1193{ 1190{
@@ -1236,9 +1233,6 @@ static int setup(struct spi_device *spi)
1236 uint tx_thres = TX_THRESH_DFLT; 1233 uint tx_thres = TX_THRESH_DFLT;
1237 uint rx_thres = RX_THRESH_DFLT; 1234 uint rx_thres = RX_THRESH_DFLT;
1238 1235
1239 if (!spi->bits_per_word)
1240 spi->bits_per_word = 8;
1241
1242 if (drv_data->ssp_type != PXA25x_SSP 1236 if (drv_data->ssp_type != PXA25x_SSP
1243 && (spi->bits_per_word < 4 || spi->bits_per_word > 32)) { 1237 && (spi->bits_per_word < 4 || spi->bits_per_word > 32)) {
1244 dev_err(&spi->dev, "failed setup: ssp_type=%d, bits/wrd=%d " 1238 dev_err(&spi->dev, "failed setup: ssp_type=%d, bits/wrd=%d "
@@ -1255,12 +1249,6 @@ static int setup(struct spi_device *spi)
1255 return -EINVAL; 1249 return -EINVAL;
1256 } 1250 }
1257 1251
1258 if (spi->mode & ~MODEBITS) {
1259 dev_dbg(&spi->dev, "setup: unsupported mode bits %x\n",
1260 spi->mode & ~MODEBITS);
1261 return -EINVAL;
1262 }
1263
1264 /* Only alloc on first setup */ 1252 /* Only alloc on first setup */
1265 chip = spi_get_ctldata(spi); 1253 chip = spi_get_ctldata(spi);
1266 if (!chip) { 1254 if (!chip) {
@@ -1328,18 +1316,14 @@ static int setup(struct spi_device *spi)
1328 1316
1329 /* NOTE: PXA25x_SSP _could_ use external clocking ... */ 1317 /* NOTE: PXA25x_SSP _could_ use external clocking ... */
1330 if (drv_data->ssp_type != PXA25x_SSP) 1318 if (drv_data->ssp_type != PXA25x_SSP)
1331 dev_dbg(&spi->dev, "%d bits/word, %ld Hz, mode %d, %s\n", 1319 dev_dbg(&spi->dev, "%ld Hz actual, %s\n",
1332 spi->bits_per_word,
1333 clk_get_rate(ssp->clk) 1320 clk_get_rate(ssp->clk)
1334 / (1 + ((chip->cr0 & SSCR0_SCR) >> 8)), 1321 / (1 + ((chip->cr0 & SSCR0_SCR) >> 8)),
1335 spi->mode & 0x3,
1336 chip->enable_dma ? "DMA" : "PIO"); 1322 chip->enable_dma ? "DMA" : "PIO");
1337 else 1323 else
1338 dev_dbg(&spi->dev, "%d bits/word, %ld Hz, mode %d, %s\n", 1324 dev_dbg(&spi->dev, "%ld Hz actual, %s\n",
1339 spi->bits_per_word,
1340 clk_get_rate(ssp->clk) / 2 1325 clk_get_rate(ssp->clk) / 2
1341 / (1 + ((chip->cr0 & SSCR0_SCR) >> 8)), 1326 / (1 + ((chip->cr0 & SSCR0_SCR) >> 8)),
1342 spi->mode & 0x3,
1343 chip->enable_dma ? "DMA" : "PIO"); 1327 chip->enable_dma ? "DMA" : "PIO");
1344 1328
1345 if (spi->bits_per_word <= 8) { 1329 if (spi->bits_per_word <= 8) {
@@ -1500,6 +1484,9 @@ static int __init pxa2xx_spi_probe(struct platform_device *pdev)
1500 drv_data->pdev = pdev; 1484 drv_data->pdev = pdev;
1501 drv_data->ssp = ssp; 1485 drv_data->ssp = ssp;
1502 1486
1487 /* the spi->mode bits understood by this driver: */
1488 master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH;
1489
1503 master->bus_num = pdev->id; 1490 master->bus_num = pdev->id;
1504 master->num_chipselect = platform_info->num_chipselect; 1491 master->num_chipselect = platform_info->num_chipselect;
1505 master->dma_alignment = DMA_ALIGNMENT; 1492 master->dma_alignment = DMA_ALIGNMENT;
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 8eba98c8ed1e..70845ccd85c3 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -265,7 +265,7 @@ int spi_add_device(struct spi_device *spi)
265 * normally rely on the device being setup. Devices 265 * normally rely on the device being setup. Devices
266 * using SPI_CS_HIGH can't coexist well otherwise... 266 * using SPI_CS_HIGH can't coexist well otherwise...
267 */ 267 */
268 status = spi->master->setup(spi); 268 status = spi_setup(spi);
269 if (status < 0) { 269 if (status < 0) {
270 dev_err(dev, "can't %s %s, status %d\n", 270 dev_err(dev, "can't %s %s, status %d\n",
271 "setup", dev_name(&spi->dev), status); 271 "setup", dev_name(&spi->dev), status);
@@ -583,6 +583,70 @@ EXPORT_SYMBOL_GPL(spi_busnum_to_master);
583 583
584/*-------------------------------------------------------------------------*/ 584/*-------------------------------------------------------------------------*/
585 585
586/* Core methods for SPI master protocol drivers. Some of the
587 * other core methods are currently defined as inline functions.
588 */
589
590/**
591 * spi_setup - setup SPI mode and clock rate
592 * @spi: the device whose settings are being modified
593 * Context: can sleep, and no requests are queued to the device
594 *
595 * SPI protocol drivers may need to update the transfer mode if the
596 * device doesn't work with its default. They may likewise need
597 * to update clock rates or word sizes from initial values. This function
598 * changes those settings, and must be called from a context that can sleep.
599 * Except for SPI_CS_HIGH, which takes effect immediately, the changes take
600 * effect the next time the device is selected and data is transferred to
601 * or from it. When this function returns, the spi device is deselected.
602 *
603 * Note that this call will fail if the protocol driver specifies an option
604 * that the underlying controller or its driver does not support. For
605 * example, not all hardware supports wire transfers using nine bit words,
606 * LSB-first wire encoding, or active-high chipselects.
607 */
608int spi_setup(struct spi_device *spi)
609{
610 unsigned bad_bits;
611 int status;
612
613 /* help drivers fail *cleanly* when they need options
614 * that aren't supported with their current master
615 */
616 bad_bits = spi->mode & ~spi->master->mode_bits;
617 if (bad_bits) {
618 dev_dbg(&spi->dev, "setup: unsupported mode bits %x\n",
619 bad_bits);
620 return -EINVAL;
621 }
622
623 if (!spi->bits_per_word)
624 spi->bits_per_word = 8;
625
626 status = spi->master->setup(spi);
627
628 dev_dbg(&spi->dev, "setup mode %d, %s%s%s%s"
629 "%u bits/w, %u Hz max --> %d\n",
630 (int) (spi->mode & (SPI_CPOL | SPI_CPHA)),
631 (spi->mode & SPI_CS_HIGH) ? "cs_high, " : "",
632 (spi->mode & SPI_LSB_FIRST) ? "lsb, " : "",
633 (spi->mode & SPI_3WIRE) ? "3wire, " : "",
634 (spi->mode & SPI_LOOP) ? "loopback, " : "",
635 spi->bits_per_word, spi->max_speed_hz,
636 status);
637
638 return status;
639}
640EXPORT_SYMBOL_GPL(spi_setup);
641
642
643/*-------------------------------------------------------------------------*/
644
645/* Utility methods for SPI master protocol drivers, layered on
646 * top of the core. Some other utility methods are defined as
647 * inline functions.
648 */
649
586static void spi_complete(void *arg) 650static void spi_complete(void *arg)
587{ 651{
588 complete(arg); 652 complete(arg);
@@ -636,8 +700,8 @@ static u8 *buf;
636 * @spi: device with which data will be exchanged 700 * @spi: device with which data will be exchanged
637 * @txbuf: data to be written (need not be dma-safe) 701 * @txbuf: data to be written (need not be dma-safe)
638 * @n_tx: size of txbuf, in bytes 702 * @n_tx: size of txbuf, in bytes
639 * @rxbuf: buffer into which data will be read 703 * @rxbuf: buffer into which data will be read (need not be dma-safe)
640 * @n_rx: size of rxbuf, in bytes (need not be dma-safe) 704 * @n_rx: size of rxbuf, in bytes
641 * Context: can sleep 705 * Context: can sleep
642 * 706 *
643 * This performs a half duplex MicroWire style transaction with the 707 * This performs a half duplex MicroWire style transaction with the
diff --git a/drivers/spi/spi_bfin5xx.c b/drivers/spi/spi_bfin5xx.c
index f014cc21e813..73e24ef5a2f9 100644
--- a/drivers/spi/spi_bfin5xx.c
+++ b/drivers/spi/spi_bfin5xx.c
@@ -169,7 +169,7 @@ static int bfin_spi_flush(struct driver_data *drv_data)
169 unsigned long limit = loops_per_jiffy << 1; 169 unsigned long limit = loops_per_jiffy << 1;
170 170
171 /* wait for stop and clear stat */ 171 /* wait for stop and clear stat */
172 while (!(read_STAT(drv_data) & BIT_STAT_SPIF) && limit--) 172 while (!(read_STAT(drv_data) & BIT_STAT_SPIF) && --limit)
173 cpu_relax(); 173 cpu_relax();
174 174
175 write_STAT(drv_data, BIT_STAT_CLR); 175 write_STAT(drv_data, BIT_STAT_CLR);
@@ -803,7 +803,7 @@ static void bfin_spi_pump_transfers(unsigned long data)
803 drv_data->rx, drv_data->len_in_bytes); 803 drv_data->rx, drv_data->len_in_bytes);
804 804
805 /* invalidate caches, if needed */ 805 /* invalidate caches, if needed */
806 if (bfin_addr_dcachable((unsigned long) drv_data->rx)) 806 if (bfin_addr_dcacheable((unsigned long) drv_data->rx))
807 invalidate_dcache_range((unsigned long) drv_data->rx, 807 invalidate_dcache_range((unsigned long) drv_data->rx,
808 (unsigned long) (drv_data->rx + 808 (unsigned long) (drv_data->rx +
809 drv_data->len_in_bytes)); 809 drv_data->len_in_bytes));
@@ -816,7 +816,7 @@ static void bfin_spi_pump_transfers(unsigned long data)
816 dev_dbg(&drv_data->pdev->dev, "doing DMA out.\n"); 816 dev_dbg(&drv_data->pdev->dev, "doing DMA out.\n");
817 817
818 /* flush caches, if needed */ 818 /* flush caches, if needed */
819 if (bfin_addr_dcachable((unsigned long) drv_data->tx)) 819 if (bfin_addr_dcacheable((unsigned long) drv_data->tx))
820 flush_dcache_range((unsigned long) drv_data->tx, 820 flush_dcache_range((unsigned long) drv_data->tx,
821 (unsigned long) (drv_data->tx + 821 (unsigned long) (drv_data->tx +
822 drv_data->len_in_bytes)); 822 drv_data->len_in_bytes));
@@ -1010,16 +1010,6 @@ static int bfin_spi_setup(struct spi_device *spi)
1010 struct driver_data *drv_data = spi_master_get_devdata(spi->master); 1010 struct driver_data *drv_data = spi_master_get_devdata(spi->master);
1011 int ret; 1011 int ret;
1012 1012
1013 /* Abort device setup if requested features are not supported */
1014 if (spi->mode & ~(SPI_CPOL | SPI_CPHA | SPI_LSB_FIRST)) {
1015 dev_err(&spi->dev, "requested mode not fully supported\n");
1016 return -EINVAL;
1017 }
1018
1019 /* Zero (the default) here means 8 bits */
1020 if (!spi->bits_per_word)
1021 spi->bits_per_word = 8;
1022
1023 if (spi->bits_per_word != 8 && spi->bits_per_word != 16) 1013 if (spi->bits_per_word != 8 && spi->bits_per_word != 16)
1024 return -EINVAL; 1014 return -EINVAL;
1025 1015
@@ -1287,6 +1277,9 @@ static int __init bfin_spi_probe(struct platform_device *pdev)
1287 drv_data->pdev = pdev; 1277 drv_data->pdev = pdev;
1288 drv_data->pin_req = platform_info->pin_req; 1278 drv_data->pin_req = platform_info->pin_req;
1289 1279
1280 /* the spi->mode bits supported by this driver: */
1281 master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_LSB_FIRST;
1282
1290 master->bus_num = pdev->id; 1283 master->bus_num = pdev->id;
1291 master->num_chipselect = platform_info->num_chipselect; 1284 master->num_chipselect = platform_info->num_chipselect;
1292 master->cleanup = bfin_spi_cleanup; 1285 master->cleanup = bfin_spi_cleanup;
diff --git a/drivers/spi/spi_bitbang.c b/drivers/spi/spi_bitbang.c
index 85e61f451218..2a5abc08e857 100644
--- a/drivers/spi/spi_bitbang.c
+++ b/drivers/spi/spi_bitbang.c
@@ -188,12 +188,6 @@ int spi_bitbang_setup(struct spi_device *spi)
188 188
189 bitbang = spi_master_get_devdata(spi->master); 189 bitbang = spi_master_get_devdata(spi->master);
190 190
191 /* Bitbangers can support SPI_CS_HIGH, SPI_3WIRE, and so on;
192 * add those to master->flags, and provide the other support.
193 */
194 if ((spi->mode & ~(SPI_CPOL|SPI_CPHA|bitbang->flags)) != 0)
195 return -EINVAL;
196
197 if (!cs) { 191 if (!cs) {
198 cs = kzalloc(sizeof *cs, GFP_KERNEL); 192 cs = kzalloc(sizeof *cs, GFP_KERNEL);
199 if (!cs) 193 if (!cs)
@@ -201,9 +195,6 @@ int spi_bitbang_setup(struct spi_device *spi)
201 spi->controller_state = cs; 195 spi->controller_state = cs;
202 } 196 }
203 197
204 if (!spi->bits_per_word)
205 spi->bits_per_word = 8;
206
207 /* per-word shift register access, in hardware or bitbanging */ 198 /* per-word shift register access, in hardware or bitbanging */
208 cs->txrx_word = bitbang->txrx_word[spi->mode & (SPI_CPOL|SPI_CPHA)]; 199 cs->txrx_word = bitbang->txrx_word[spi->mode & (SPI_CPOL|SPI_CPHA)];
209 if (!cs->txrx_word) 200 if (!cs->txrx_word)
@@ -213,9 +204,7 @@ int spi_bitbang_setup(struct spi_device *spi)
213 if (retval < 0) 204 if (retval < 0)
214 return retval; 205 return retval;
215 206
216 dev_dbg(&spi->dev, "%s, mode %d, %u bits/w, %u nsec/bit\n", 207 dev_dbg(&spi->dev, "%s, %u nsec/bit\n", __func__, 2 * cs->nsecs);
217 __func__, spi->mode & (SPI_CPOL | SPI_CPHA),
218 spi->bits_per_word, 2 * cs->nsecs);
219 208
220 /* NOTE we _need_ to call chipselect() early, ideally with adapter 209 /* NOTE we _need_ to call chipselect() early, ideally with adapter
221 * setup, unless the hardware defaults cooperate to avoid confusion 210 * setup, unless the hardware defaults cooperate to avoid confusion
@@ -457,6 +446,9 @@ int spi_bitbang_start(struct spi_bitbang *bitbang)
457 spin_lock_init(&bitbang->lock); 446 spin_lock_init(&bitbang->lock);
458 INIT_LIST_HEAD(&bitbang->queue); 447 INIT_LIST_HEAD(&bitbang->queue);
459 448
449 if (!bitbang->master->mode_bits)
450 bitbang->master->mode_bits = SPI_CPOL | SPI_CPHA | bitbang->flags;
451
460 if (!bitbang->master->transfer) 452 if (!bitbang->master->transfer)
461 bitbang->master->transfer = spi_bitbang_transfer; 453 bitbang->master->transfer = spi_bitbang_transfer;
462 if (!bitbang->txrx_bufs) { 454 if (!bitbang->txrx_bufs) {
diff --git a/drivers/spi/spi_imx.c b/drivers/spi/spi_imx.c
index 0671aeef5792..c195e45f7f35 100644
--- a/drivers/spi/spi_imx.c
+++ b/drivers/spi/spi_imx.c
@@ -1171,9 +1171,6 @@ msg_rejected:
1171 return -EINVAL; 1171 return -EINVAL;
1172} 1172}
1173 1173
1174/* the spi->mode bits understood by this driver: */
1175#define MODEBITS (SPI_CPOL | SPI_CPHA | SPI_CS_HIGH)
1176
1177/* On first setup bad values must free chip_data memory since will cause 1174/* On first setup bad values must free chip_data memory since will cause
1178 spi_new_device to fail. Bad value setup from protocol driver are simply not 1175 spi_new_device to fail. Bad value setup from protocol driver are simply not
1179 applied and notified to the calling driver. */ 1176 applied and notified to the calling driver. */
@@ -1186,12 +1183,6 @@ static int setup(struct spi_device *spi)
1186 u32 tmp; 1183 u32 tmp;
1187 int status = 0; 1184 int status = 0;
1188 1185
1189 if (spi->mode & ~MODEBITS) {
1190 dev_dbg(&spi->dev, "setup: unsupported mode bits %x\n",
1191 spi->mode & ~MODEBITS);
1192 return -EINVAL;
1193 }
1194
1195 /* Get controller data */ 1186 /* Get controller data */
1196 chip_info = spi->controller_data; 1187 chip_info = spi->controller_data;
1197 1188
@@ -1286,10 +1277,7 @@ static int setup(struct spi_device *spi)
1286 1277
1287 /* SPI word width */ 1278 /* SPI word width */
1288 tmp = spi->bits_per_word; 1279 tmp = spi->bits_per_word;
1289 if (tmp == 0) { 1280 if (tmp > 16) {
1290 tmp = 8;
1291 spi->bits_per_word = 8;
1292 } else if (tmp > 16) {
1293 status = -EINVAL; 1281 status = -EINVAL;
1294 dev_err(&spi->dev, 1282 dev_err(&spi->dev,
1295 "setup - " 1283 "setup - "
@@ -1481,6 +1469,9 @@ static int __init spi_imx_probe(struct platform_device *pdev)
1481 drv_data->master_info = platform_info; 1469 drv_data->master_info = platform_info;
1482 drv_data->pdev = pdev; 1470 drv_data->pdev = pdev;
1483 1471
1472 /* the spi->mode bits understood by this driver: */
1473 master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH;
1474
1484 master->bus_num = pdev->id; 1475 master->bus_num = pdev->id;
1485 master->num_chipselect = platform_info->num_chipselect; 1476 master->num_chipselect = platform_info->num_chipselect;
1486 master->dma_alignment = DMA_ALIGNMENT; 1477 master->dma_alignment = DMA_ALIGNMENT;
diff --git a/drivers/spi/spi_mpc83xx.c b/drivers/spi/spi_mpc8xxx.c
index f4573a96af24..0fd0ec4d3a7d 100644
--- a/drivers/spi/spi_mpc83xx.c
+++ b/drivers/spi/spi_mpc8xxx.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * MPC83xx SPI controller driver. 2 * MPC8xxx SPI controller driver.
3 * 3 *
4 * Maintainer: Kumar Gala 4 * Maintainer: Kumar Gala
5 * 5 *
@@ -14,8 +14,10 @@
14#include <linux/init.h> 14#include <linux/init.h>
15#include <linux/types.h> 15#include <linux/types.h>
16#include <linux/kernel.h> 16#include <linux/kernel.h>
17#include <linux/bug.h>
17#include <linux/errno.h> 18#include <linux/errno.h>
18#include <linux/err.h> 19#include <linux/err.h>
20#include <linux/io.h>
19#include <linux/completion.h> 21#include <linux/completion.h>
20#include <linux/interrupt.h> 22#include <linux/interrupt.h>
21#include <linux/delay.h> 23#include <linux/delay.h>
@@ -33,10 +35,9 @@
33 35
34#include <sysdev/fsl_soc.h> 36#include <sysdev/fsl_soc.h>
35#include <asm/irq.h> 37#include <asm/irq.h>
36#include <asm/io.h>
37 38
38/* SPI Controller registers */ 39/* SPI Controller registers */
39struct mpc83xx_spi_reg { 40struct mpc8xxx_spi_reg {
40 u8 res1[0x20]; 41 u8 res1[0x20];
41 __be32 mode; 42 __be32 mode;
42 __be32 event; 43 __be32 event;
@@ -75,16 +76,16 @@ struct mpc83xx_spi_reg {
75#define SPIM_NF 0x00000100 /* Not full */ 76#define SPIM_NF 0x00000100 /* Not full */
76 77
77/* SPI Controller driver's private data. */ 78/* SPI Controller driver's private data. */
78struct mpc83xx_spi { 79struct mpc8xxx_spi {
79 struct mpc83xx_spi_reg __iomem *base; 80 struct mpc8xxx_spi_reg __iomem *base;
80 81
81 /* rx & tx bufs from the spi_transfer */ 82 /* rx & tx bufs from the spi_transfer */
82 const void *tx; 83 const void *tx;
83 void *rx; 84 void *rx;
84 85
85 /* functions to deal with different sized buffers */ 86 /* functions to deal with different sized buffers */
86 void (*get_rx) (u32 rx_data, struct mpc83xx_spi *); 87 void (*get_rx) (u32 rx_data, struct mpc8xxx_spi *);
87 u32(*get_tx) (struct mpc83xx_spi *); 88 u32(*get_tx) (struct mpc8xxx_spi *);
88 89
89 unsigned int count; 90 unsigned int count;
90 unsigned int irq; 91 unsigned int irq;
@@ -97,8 +98,6 @@ struct mpc83xx_spi {
97 98
98 bool qe_mode; 99 bool qe_mode;
99 100
100 u8 busy;
101
102 struct workqueue_struct *workqueue; 101 struct workqueue_struct *workqueue;
103 struct work_struct work; 102 struct work_struct work;
104 103
@@ -108,44 +107,44 @@ struct mpc83xx_spi {
108 struct completion done; 107 struct completion done;
109}; 108};
110 109
111struct spi_mpc83xx_cs { 110struct spi_mpc8xxx_cs {
112 /* functions to deal with different sized buffers */ 111 /* functions to deal with different sized buffers */
113 void (*get_rx) (u32 rx_data, struct mpc83xx_spi *); 112 void (*get_rx) (u32 rx_data, struct mpc8xxx_spi *);
114 u32 (*get_tx) (struct mpc83xx_spi *); 113 u32 (*get_tx) (struct mpc8xxx_spi *);
115 u32 rx_shift; /* RX data reg shift when in qe mode */ 114 u32 rx_shift; /* RX data reg shift when in qe mode */
116 u32 tx_shift; /* TX data reg shift when in qe mode */ 115 u32 tx_shift; /* TX data reg shift when in qe mode */
117 u32 hw_mode; /* Holds HW mode register settings */ 116 u32 hw_mode; /* Holds HW mode register settings */
118}; 117};
119 118
120static inline void mpc83xx_spi_write_reg(__be32 __iomem * reg, u32 val) 119static inline void mpc8xxx_spi_write_reg(__be32 __iomem *reg, u32 val)
121{ 120{
122 out_be32(reg, val); 121 out_be32(reg, val);
123} 122}
124 123
125static inline u32 mpc83xx_spi_read_reg(__be32 __iomem * reg) 124static inline u32 mpc8xxx_spi_read_reg(__be32 __iomem *reg)
126{ 125{
127 return in_be32(reg); 126 return in_be32(reg);
128} 127}
129 128
130#define MPC83XX_SPI_RX_BUF(type) \ 129#define MPC83XX_SPI_RX_BUF(type) \
131static \ 130static \
132void mpc83xx_spi_rx_buf_##type(u32 data, struct mpc83xx_spi *mpc83xx_spi) \ 131void mpc8xxx_spi_rx_buf_##type(u32 data, struct mpc8xxx_spi *mpc8xxx_spi) \
133{ \ 132{ \
134 type * rx = mpc83xx_spi->rx; \ 133 type *rx = mpc8xxx_spi->rx; \
135 *rx++ = (type)(data >> mpc83xx_spi->rx_shift); \ 134 *rx++ = (type)(data >> mpc8xxx_spi->rx_shift); \
136 mpc83xx_spi->rx = rx; \ 135 mpc8xxx_spi->rx = rx; \
137} 136}
138 137
139#define MPC83XX_SPI_TX_BUF(type) \ 138#define MPC83XX_SPI_TX_BUF(type) \
140static \ 139static \
141u32 mpc83xx_spi_tx_buf_##type(struct mpc83xx_spi *mpc83xx_spi) \ 140u32 mpc8xxx_spi_tx_buf_##type(struct mpc8xxx_spi *mpc8xxx_spi) \
142{ \ 141{ \
143 u32 data; \ 142 u32 data; \
144 const type * tx = mpc83xx_spi->tx; \ 143 const type *tx = mpc8xxx_spi->tx; \
145 if (!tx) \ 144 if (!tx) \
146 return 0; \ 145 return 0; \
147 data = *tx++ << mpc83xx_spi->tx_shift; \ 146 data = *tx++ << mpc8xxx_spi->tx_shift; \
148 mpc83xx_spi->tx = tx; \ 147 mpc8xxx_spi->tx = tx; \
149 return data; \ 148 return data; \
150} 149}
151 150
@@ -156,12 +155,12 @@ MPC83XX_SPI_TX_BUF(u8)
156MPC83XX_SPI_TX_BUF(u16) 155MPC83XX_SPI_TX_BUF(u16)
157MPC83XX_SPI_TX_BUF(u32) 156MPC83XX_SPI_TX_BUF(u32)
158 157
159static void mpc83xx_spi_chipselect(struct spi_device *spi, int value) 158static void mpc8xxx_spi_chipselect(struct spi_device *spi, int value)
160{ 159{
161 struct mpc83xx_spi *mpc83xx_spi = spi_master_get_devdata(spi->master); 160 struct mpc8xxx_spi *mpc8xxx_spi = spi_master_get_devdata(spi->master);
162 struct fsl_spi_platform_data *pdata = spi->dev.parent->platform_data; 161 struct fsl_spi_platform_data *pdata = spi->dev.parent->platform_data;
163 bool pol = spi->mode & SPI_CS_HIGH; 162 bool pol = spi->mode & SPI_CS_HIGH;
164 struct spi_mpc83xx_cs *cs = spi->controller_state; 163 struct spi_mpc8xxx_cs *cs = spi->controller_state;
165 164
166 if (value == BITBANG_CS_INACTIVE) { 165 if (value == BITBANG_CS_INACTIVE) {
167 if (pdata->cs_control) 166 if (pdata->cs_control)
@@ -169,16 +168,16 @@ static void mpc83xx_spi_chipselect(struct spi_device *spi, int value)
169 } 168 }
170 169
171 if (value == BITBANG_CS_ACTIVE) { 170 if (value == BITBANG_CS_ACTIVE) {
172 u32 regval = mpc83xx_spi_read_reg(&mpc83xx_spi->base->mode); 171 u32 regval = mpc8xxx_spi_read_reg(&mpc8xxx_spi->base->mode);
173 172
174 mpc83xx_spi->rx_shift = cs->rx_shift; 173 mpc8xxx_spi->rx_shift = cs->rx_shift;
175 mpc83xx_spi->tx_shift = cs->tx_shift; 174 mpc8xxx_spi->tx_shift = cs->tx_shift;
176 mpc83xx_spi->get_rx = cs->get_rx; 175 mpc8xxx_spi->get_rx = cs->get_rx;
177 mpc83xx_spi->get_tx = cs->get_tx; 176 mpc8xxx_spi->get_tx = cs->get_tx;
178 177
179 if (cs->hw_mode != regval) { 178 if (cs->hw_mode != regval) {
180 unsigned long flags; 179 unsigned long flags;
181 __be32 __iomem *mode = &mpc83xx_spi->base->mode; 180 __be32 __iomem *mode = &mpc8xxx_spi->base->mode;
182 181
183 regval = cs->hw_mode; 182 regval = cs->hw_mode;
184 /* Turn off IRQs locally to minimize time that 183 /* Turn off IRQs locally to minimize time that
@@ -186,8 +185,8 @@ static void mpc83xx_spi_chipselect(struct spi_device *spi, int value)
186 */ 185 */
187 local_irq_save(flags); 186 local_irq_save(flags);
188 /* Turn off SPI unit prior changing mode */ 187 /* Turn off SPI unit prior changing mode */
189 mpc83xx_spi_write_reg(mode, regval & ~SPMODE_ENABLE); 188 mpc8xxx_spi_write_reg(mode, regval & ~SPMODE_ENABLE);
190 mpc83xx_spi_write_reg(mode, regval); 189 mpc8xxx_spi_write_reg(mode, regval);
191 local_irq_restore(flags); 190 local_irq_restore(flags);
192 } 191 }
193 if (pdata->cs_control) 192 if (pdata->cs_control)
@@ -196,15 +195,15 @@ static void mpc83xx_spi_chipselect(struct spi_device *spi, int value)
196} 195}
197 196
198static 197static
199int mpc83xx_spi_setup_transfer(struct spi_device *spi, struct spi_transfer *t) 198int mpc8xxx_spi_setup_transfer(struct spi_device *spi, struct spi_transfer *t)
200{ 199{
201 struct mpc83xx_spi *mpc83xx_spi; 200 struct mpc8xxx_spi *mpc8xxx_spi;
202 u32 regval; 201 u32 regval;
203 u8 bits_per_word, pm; 202 u8 bits_per_word, pm;
204 u32 hz; 203 u32 hz;
205 struct spi_mpc83xx_cs *cs = spi->controller_state; 204 struct spi_mpc8xxx_cs *cs = spi->controller_state;
206 205
207 mpc83xx_spi = spi_master_get_devdata(spi->master); 206 mpc8xxx_spi = spi_master_get_devdata(spi->master);
208 207
209 if (t) { 208 if (t) {
210 bits_per_word = t->bits_per_word; 209 bits_per_word = t->bits_per_word;
@@ -229,26 +228,26 @@ int mpc83xx_spi_setup_transfer(struct spi_device *spi, struct spi_transfer *t)
229 cs->rx_shift = 0; 228 cs->rx_shift = 0;
230 cs->tx_shift = 0; 229 cs->tx_shift = 0;
231 if (bits_per_word <= 8) { 230 if (bits_per_word <= 8) {
232 cs->get_rx = mpc83xx_spi_rx_buf_u8; 231 cs->get_rx = mpc8xxx_spi_rx_buf_u8;
233 cs->get_tx = mpc83xx_spi_tx_buf_u8; 232 cs->get_tx = mpc8xxx_spi_tx_buf_u8;
234 if (mpc83xx_spi->qe_mode) { 233 if (mpc8xxx_spi->qe_mode) {
235 cs->rx_shift = 16; 234 cs->rx_shift = 16;
236 cs->tx_shift = 24; 235 cs->tx_shift = 24;
237 } 236 }
238 } else if (bits_per_word <= 16) { 237 } else if (bits_per_word <= 16) {
239 cs->get_rx = mpc83xx_spi_rx_buf_u16; 238 cs->get_rx = mpc8xxx_spi_rx_buf_u16;
240 cs->get_tx = mpc83xx_spi_tx_buf_u16; 239 cs->get_tx = mpc8xxx_spi_tx_buf_u16;
241 if (mpc83xx_spi->qe_mode) { 240 if (mpc8xxx_spi->qe_mode) {
242 cs->rx_shift = 16; 241 cs->rx_shift = 16;
243 cs->tx_shift = 16; 242 cs->tx_shift = 16;
244 } 243 }
245 } else if (bits_per_word <= 32) { 244 } else if (bits_per_word <= 32) {
246 cs->get_rx = mpc83xx_spi_rx_buf_u32; 245 cs->get_rx = mpc8xxx_spi_rx_buf_u32;
247 cs->get_tx = mpc83xx_spi_tx_buf_u32; 246 cs->get_tx = mpc8xxx_spi_tx_buf_u32;
248 } else 247 } else
249 return -EINVAL; 248 return -EINVAL;
250 249
251 if (mpc83xx_spi->qe_mode && spi->mode & SPI_LSB_FIRST) { 250 if (mpc8xxx_spi->qe_mode && spi->mode & SPI_LSB_FIRST) {
252 cs->tx_shift = 0; 251 cs->tx_shift = 0;
253 if (bits_per_word <= 8) 252 if (bits_per_word <= 8)
254 cs->rx_shift = 8; 253 cs->rx_shift = 8;
@@ -256,10 +255,10 @@ int mpc83xx_spi_setup_transfer(struct spi_device *spi, struct spi_transfer *t)
256 cs->rx_shift = 0; 255 cs->rx_shift = 0;
257 } 256 }
258 257
259 mpc83xx_spi->rx_shift = cs->rx_shift; 258 mpc8xxx_spi->rx_shift = cs->rx_shift;
260 mpc83xx_spi->tx_shift = cs->tx_shift; 259 mpc8xxx_spi->tx_shift = cs->tx_shift;
261 mpc83xx_spi->get_rx = cs->get_rx; 260 mpc8xxx_spi->get_rx = cs->get_rx;
262 mpc83xx_spi->get_tx = cs->get_tx; 261 mpc8xxx_spi->get_tx = cs->get_tx;
263 262
264 if (bits_per_word == 32) 263 if (bits_per_word == 32)
265 bits_per_word = 0; 264 bits_per_word = 0;
@@ -272,25 +271,25 @@ int mpc83xx_spi_setup_transfer(struct spi_device *spi, struct spi_transfer *t)
272 271
273 cs->hw_mode |= SPMODE_LEN(bits_per_word); 272 cs->hw_mode |= SPMODE_LEN(bits_per_word);
274 273
275 if ((mpc83xx_spi->spibrg / hz) > 64) { 274 if ((mpc8xxx_spi->spibrg / hz) > 64) {
276 cs->hw_mode |= SPMODE_DIV16; 275 cs->hw_mode |= SPMODE_DIV16;
277 pm = mpc83xx_spi->spibrg / (hz * 64); 276 pm = mpc8xxx_spi->spibrg / (hz * 64);
278 if (pm > 16) { 277
279 dev_err(&spi->dev, "Requested speed is too " 278 WARN_ONCE(pm > 16, "%s: Requested speed is too low: %d Hz. "
280 "low: %d Hz. Will use %d Hz instead.\n", 279 "Will use %d Hz instead.\n", dev_name(&spi->dev),
281 hz, mpc83xx_spi->spibrg / 1024); 280 hz, mpc8xxx_spi->spibrg / 1024);
281 if (pm > 16)
282 pm = 16; 282 pm = 16;
283 }
284 } else 283 } else
285 pm = mpc83xx_spi->spibrg / (hz * 4); 284 pm = mpc8xxx_spi->spibrg / (hz * 4);
286 if (pm) 285 if (pm)
287 pm--; 286 pm--;
288 287
289 cs->hw_mode |= SPMODE_PM(pm); 288 cs->hw_mode |= SPMODE_PM(pm);
290 regval = mpc83xx_spi_read_reg(&mpc83xx_spi->base->mode); 289 regval = mpc8xxx_spi_read_reg(&mpc8xxx_spi->base->mode);
291 if (cs->hw_mode != regval) { 290 if (cs->hw_mode != regval) {
292 unsigned long flags; 291 unsigned long flags;
293 __be32 __iomem *mode = &mpc83xx_spi->base->mode; 292 __be32 __iomem *mode = &mpc8xxx_spi->base->mode;
294 293
295 regval = cs->hw_mode; 294 regval = cs->hw_mode;
296 /* Turn off IRQs locally to minimize time 295 /* Turn off IRQs locally to minimize time
@@ -298,22 +297,22 @@ int mpc83xx_spi_setup_transfer(struct spi_device *spi, struct spi_transfer *t)
298 */ 297 */
299 local_irq_save(flags); 298 local_irq_save(flags);
300 /* Turn off SPI unit prior changing mode */ 299 /* Turn off SPI unit prior changing mode */
301 mpc83xx_spi_write_reg(mode, regval & ~SPMODE_ENABLE); 300 mpc8xxx_spi_write_reg(mode, regval & ~SPMODE_ENABLE);
302 mpc83xx_spi_write_reg(mode, regval); 301 mpc8xxx_spi_write_reg(mode, regval);
303 local_irq_restore(flags); 302 local_irq_restore(flags);
304 } 303 }
305 return 0; 304 return 0;
306} 305}
307 306
308static int mpc83xx_spi_bufs(struct spi_device *spi, struct spi_transfer *t) 307static int mpc8xxx_spi_bufs(struct spi_device *spi, struct spi_transfer *t)
309{ 308{
310 struct mpc83xx_spi *mpc83xx_spi; 309 struct mpc8xxx_spi *mpc8xxx_spi;
311 u32 word, len, bits_per_word; 310 u32 word, len, bits_per_word;
312 311
313 mpc83xx_spi = spi_master_get_devdata(spi->master); 312 mpc8xxx_spi = spi_master_get_devdata(spi->master);
314 313
315 mpc83xx_spi->tx = t->tx_buf; 314 mpc8xxx_spi->tx = t->tx_buf;
316 mpc83xx_spi->rx = t->rx_buf; 315 mpc8xxx_spi->rx = t->rx_buf;
317 bits_per_word = spi->bits_per_word; 316 bits_per_word = spi->bits_per_word;
318 if (t->bits_per_word) 317 if (t->bits_per_word)
319 bits_per_word = t->bits_per_word; 318 bits_per_word = t->bits_per_word;
@@ -330,111 +329,106 @@ static int mpc83xx_spi_bufs(struct spi_device *spi, struct spi_transfer *t)
330 return -EINVAL; 329 return -EINVAL;
331 len /= 2; 330 len /= 2;
332 } 331 }
333 mpc83xx_spi->count = len; 332 mpc8xxx_spi->count = len;
334 333
335 INIT_COMPLETION(mpc83xx_spi->done); 334 INIT_COMPLETION(mpc8xxx_spi->done);
336 335
337 /* enable rx ints */ 336 /* enable rx ints */
338 mpc83xx_spi_write_reg(&mpc83xx_spi->base->mask, SPIM_NE); 337 mpc8xxx_spi_write_reg(&mpc8xxx_spi->base->mask, SPIM_NE);
339 338
340 /* transmit word */ 339 /* transmit word */
341 word = mpc83xx_spi->get_tx(mpc83xx_spi); 340 word = mpc8xxx_spi->get_tx(mpc8xxx_spi);
342 mpc83xx_spi_write_reg(&mpc83xx_spi->base->transmit, word); 341 mpc8xxx_spi_write_reg(&mpc8xxx_spi->base->transmit, word);
343 342
344 wait_for_completion(&mpc83xx_spi->done); 343 wait_for_completion(&mpc8xxx_spi->done);
345 344
346 /* disable rx ints */ 345 /* disable rx ints */
347 mpc83xx_spi_write_reg(&mpc83xx_spi->base->mask, 0); 346 mpc8xxx_spi_write_reg(&mpc8xxx_spi->base->mask, 0);
348 347
349 return mpc83xx_spi->count; 348 return mpc8xxx_spi->count;
350} 349}
351 350
352static void mpc83xx_spi_work(struct work_struct *work) 351static void mpc8xxx_spi_do_one_msg(struct spi_message *m)
353{ 352{
354 struct mpc83xx_spi *mpc83xx_spi = 353 struct spi_device *spi = m->spi;
355 container_of(work, struct mpc83xx_spi, work); 354 struct spi_transfer *t;
356 355 unsigned int cs_change;
357 spin_lock_irq(&mpc83xx_spi->lock); 356 const int nsecs = 50;
358 mpc83xx_spi->busy = 1; 357 int status;
359 while (!list_empty(&mpc83xx_spi->queue)) { 358
360 struct spi_message *m; 359 cs_change = 1;
361 struct spi_device *spi; 360 status = 0;
362 struct spi_transfer *t = NULL; 361 list_for_each_entry(t, &m->transfers, transfer_list) {
363 unsigned cs_change; 362 if (t->bits_per_word || t->speed_hz) {
364 int status, nsecs = 50; 363 /* Don't allow changes if CS is active */
365 364 status = -EINVAL;
366 m = container_of(mpc83xx_spi->queue.next,
367 struct spi_message, queue);
368 list_del_init(&m->queue);
369 spin_unlock_irq(&mpc83xx_spi->lock);
370
371 spi = m->spi;
372 cs_change = 1;
373 status = 0;
374 list_for_each_entry(t, &m->transfers, transfer_list) {
375 if (t->bits_per_word || t->speed_hz) {
376 /* Don't allow changes if CS is active */
377 status = -EINVAL;
378
379 if (cs_change)
380 status = mpc83xx_spi_setup_transfer(spi, t);
381 if (status < 0)
382 break;
383 }
384 365
385 if (cs_change) 366 if (cs_change)
386 mpc83xx_spi_chipselect(spi, BITBANG_CS_ACTIVE); 367 status = mpc8xxx_spi_setup_transfer(spi, t);
387 cs_change = t->cs_change; 368 if (status < 0)
388 if (t->len)
389 status = mpc83xx_spi_bufs(spi, t);
390 if (status) {
391 status = -EMSGSIZE;
392 break; 369 break;
393 } 370 }
394 m->actual_length += t->len;
395
396 if (t->delay_usecs)
397 udelay(t->delay_usecs);
398 371
399 if (cs_change) { 372 if (cs_change) {
400 ndelay(nsecs); 373 mpc8xxx_spi_chipselect(spi, BITBANG_CS_ACTIVE);
401 mpc83xx_spi_chipselect(spi, BITBANG_CS_INACTIVE); 374 ndelay(nsecs);
402 ndelay(nsecs); 375 }
403 } 376 cs_change = t->cs_change;
377 if (t->len)
378 status = mpc8xxx_spi_bufs(spi, t);
379 if (status) {
380 status = -EMSGSIZE;
381 break;
404 } 382 }
383 m->actual_length += t->len;
405 384
406 m->status = status; 385 if (t->delay_usecs)
407 m->complete(m->context); 386 udelay(t->delay_usecs);
408 387
409 if (status || !cs_change) { 388 if (cs_change) {
389 ndelay(nsecs);
390 mpc8xxx_spi_chipselect(spi, BITBANG_CS_INACTIVE);
410 ndelay(nsecs); 391 ndelay(nsecs);
411 mpc83xx_spi_chipselect(spi, BITBANG_CS_INACTIVE);
412 } 392 }
393 }
413 394
414 mpc83xx_spi_setup_transfer(spi, NULL); 395 m->status = status;
396 m->complete(m->context);
415 397
416 spin_lock_irq(&mpc83xx_spi->lock); 398 if (status || !cs_change) {
399 ndelay(nsecs);
400 mpc8xxx_spi_chipselect(spi, BITBANG_CS_INACTIVE);
417 } 401 }
418 mpc83xx_spi->busy = 0; 402
419 spin_unlock_irq(&mpc83xx_spi->lock); 403 mpc8xxx_spi_setup_transfer(spi, NULL);
420} 404}
421 405
422/* the spi->mode bits understood by this driver: */ 406static void mpc8xxx_spi_work(struct work_struct *work)
423#define MODEBITS (SPI_CPOL | SPI_CPHA | SPI_CS_HIGH \ 407{
424 | SPI_LSB_FIRST | SPI_LOOP) 408 struct mpc8xxx_spi *mpc8xxx_spi = container_of(work, struct mpc8xxx_spi,
409 work);
410
411 spin_lock_irq(&mpc8xxx_spi->lock);
412 while (!list_empty(&mpc8xxx_spi->queue)) {
413 struct spi_message *m = container_of(mpc8xxx_spi->queue.next,
414 struct spi_message, queue);
415
416 list_del_init(&m->queue);
417 spin_unlock_irq(&mpc8xxx_spi->lock);
418
419 mpc8xxx_spi_do_one_msg(m);
420
421 spin_lock_irq(&mpc8xxx_spi->lock);
422 }
423 spin_unlock_irq(&mpc8xxx_spi->lock);
424}
425 425
426static int mpc83xx_spi_setup(struct spi_device *spi) 426static int mpc8xxx_spi_setup(struct spi_device *spi)
427{ 427{
428 struct mpc83xx_spi *mpc83xx_spi; 428 struct mpc8xxx_spi *mpc8xxx_spi;
429 int retval; 429 int retval;
430 u32 hw_mode; 430 u32 hw_mode;
431 struct spi_mpc83xx_cs *cs = spi->controller_state; 431 struct spi_mpc8xxx_cs *cs = spi->controller_state;
432
433 if (spi->mode & ~MODEBITS) {
434 dev_dbg(&spi->dev, "setup: unsupported mode bits %x\n",
435 spi->mode & ~MODEBITS);
436 return -EINVAL;
437 }
438 432
439 if (!spi->max_speed_hz) 433 if (!spi->max_speed_hz)
440 return -EINVAL; 434 return -EINVAL;
@@ -445,13 +439,10 @@ static int mpc83xx_spi_setup(struct spi_device *spi)
445 return -ENOMEM; 439 return -ENOMEM;
446 spi->controller_state = cs; 440 spi->controller_state = cs;
447 } 441 }
448 mpc83xx_spi = spi_master_get_devdata(spi->master); 442 mpc8xxx_spi = spi_master_get_devdata(spi->master);
449
450 if (!spi->bits_per_word)
451 spi->bits_per_word = 8;
452 443
453 hw_mode = cs->hw_mode; /* Save orginal settings */ 444 hw_mode = cs->hw_mode; /* Save orginal settings */
454 cs->hw_mode = mpc83xx_spi_read_reg(&mpc83xx_spi->base->mode); 445 cs->hw_mode = mpc8xxx_spi_read_reg(&mpc8xxx_spi->base->mode);
455 /* mask out bits we are going to set */ 446 /* mask out bits we are going to set */
456 cs->hw_mode &= ~(SPMODE_CP_BEGIN_EDGECLK | SPMODE_CI_INACTIVEHIGH 447 cs->hw_mode &= ~(SPMODE_CP_BEGIN_EDGECLK | SPMODE_CI_INACTIVEHIGH
457 | SPMODE_REV | SPMODE_LOOP); 448 | SPMODE_REV | SPMODE_LOOP);
@@ -465,45 +456,29 @@ static int mpc83xx_spi_setup(struct spi_device *spi)
465 if (spi->mode & SPI_LOOP) 456 if (spi->mode & SPI_LOOP)
466 cs->hw_mode |= SPMODE_LOOP; 457 cs->hw_mode |= SPMODE_LOOP;
467 458
468 retval = mpc83xx_spi_setup_transfer(spi, NULL); 459 retval = mpc8xxx_spi_setup_transfer(spi, NULL);
469 if (retval < 0) { 460 if (retval < 0) {
470 cs->hw_mode = hw_mode; /* Restore settings */ 461 cs->hw_mode = hw_mode; /* Restore settings */
471 return retval; 462 return retval;
472 } 463 }
473
474 dev_dbg(&spi->dev, "%s, mode %d, %u bits/w, %u Hz\n",
475 __func__, spi->mode & (SPI_CPOL | SPI_CPHA),
476 spi->bits_per_word, spi->max_speed_hz);
477#if 0 /* Don't think this is needed */
478 /* NOTE we _need_ to call chipselect() early, ideally with adapter
479 * setup, unless the hardware defaults cooperate to avoid confusion
480 * between normal (active low) and inverted chipselects.
481 */
482
483 /* deselect chip (low or high) */
484 spin_lock(&mpc83xx_spi->lock);
485 if (!mpc83xx_spi->busy)
486 mpc83xx_spi_chipselect(spi, BITBANG_CS_INACTIVE);
487 spin_unlock(&mpc83xx_spi->lock);
488#endif
489 return 0; 464 return 0;
490} 465}
491 466
492static irqreturn_t mpc83xx_spi_irq(s32 irq, void *context_data) 467static irqreturn_t mpc8xxx_spi_irq(s32 irq, void *context_data)
493{ 468{
494 struct mpc83xx_spi *mpc83xx_spi = context_data; 469 struct mpc8xxx_spi *mpc8xxx_spi = context_data;
495 u32 event; 470 u32 event;
496 irqreturn_t ret = IRQ_NONE; 471 irqreturn_t ret = IRQ_NONE;
497 472
498 /* Get interrupt events(tx/rx) */ 473 /* Get interrupt events(tx/rx) */
499 event = mpc83xx_spi_read_reg(&mpc83xx_spi->base->event); 474 event = mpc8xxx_spi_read_reg(&mpc8xxx_spi->base->event);
500 475
501 /* We need handle RX first */ 476 /* We need handle RX first */
502 if (event & SPIE_NE) { 477 if (event & SPIE_NE) {
503 u32 rx_data = mpc83xx_spi_read_reg(&mpc83xx_spi->base->receive); 478 u32 rx_data = mpc8xxx_spi_read_reg(&mpc8xxx_spi->base->receive);
504 479
505 if (mpc83xx_spi->rx) 480 if (mpc8xxx_spi->rx)
506 mpc83xx_spi->get_rx(rx_data, mpc83xx_spi); 481 mpc8xxx_spi->get_rx(rx_data, mpc8xxx_spi);
507 482
508 ret = IRQ_HANDLED; 483 ret = IRQ_HANDLED;
509 } 484 }
@@ -511,56 +486,56 @@ static irqreturn_t mpc83xx_spi_irq(s32 irq, void *context_data)
511 if ((event & SPIE_NF) == 0) 486 if ((event & SPIE_NF) == 0)
512 /* spin until TX is done */ 487 /* spin until TX is done */
513 while (((event = 488 while (((event =
514 mpc83xx_spi_read_reg(&mpc83xx_spi->base->event)) & 489 mpc8xxx_spi_read_reg(&mpc8xxx_spi->base->event)) &
515 SPIE_NF) == 0) 490 SPIE_NF) == 0)
516 cpu_relax(); 491 cpu_relax();
517 492
518 mpc83xx_spi->count -= 1; 493 mpc8xxx_spi->count -= 1;
519 if (mpc83xx_spi->count) { 494 if (mpc8xxx_spi->count) {
520 u32 word = mpc83xx_spi->get_tx(mpc83xx_spi); 495 u32 word = mpc8xxx_spi->get_tx(mpc8xxx_spi);
521 mpc83xx_spi_write_reg(&mpc83xx_spi->base->transmit, word); 496 mpc8xxx_spi_write_reg(&mpc8xxx_spi->base->transmit, word);
522 } else { 497 } else {
523 complete(&mpc83xx_spi->done); 498 complete(&mpc8xxx_spi->done);
524 } 499 }
525 500
526 /* Clear the events */ 501 /* Clear the events */
527 mpc83xx_spi_write_reg(&mpc83xx_spi->base->event, event); 502 mpc8xxx_spi_write_reg(&mpc8xxx_spi->base->event, event);
528 503
529 return ret; 504 return ret;
530} 505}
531static int mpc83xx_spi_transfer(struct spi_device *spi, 506static int mpc8xxx_spi_transfer(struct spi_device *spi,
532 struct spi_message *m) 507 struct spi_message *m)
533{ 508{
534 struct mpc83xx_spi *mpc83xx_spi = spi_master_get_devdata(spi->master); 509 struct mpc8xxx_spi *mpc8xxx_spi = spi_master_get_devdata(spi->master);
535 unsigned long flags; 510 unsigned long flags;
536 511
537 m->actual_length = 0; 512 m->actual_length = 0;
538 m->status = -EINPROGRESS; 513 m->status = -EINPROGRESS;
539 514
540 spin_lock_irqsave(&mpc83xx_spi->lock, flags); 515 spin_lock_irqsave(&mpc8xxx_spi->lock, flags);
541 list_add_tail(&m->queue, &mpc83xx_spi->queue); 516 list_add_tail(&m->queue, &mpc8xxx_spi->queue);
542 queue_work(mpc83xx_spi->workqueue, &mpc83xx_spi->work); 517 queue_work(mpc8xxx_spi->workqueue, &mpc8xxx_spi->work);
543 spin_unlock_irqrestore(&mpc83xx_spi->lock, flags); 518 spin_unlock_irqrestore(&mpc8xxx_spi->lock, flags);
544 519
545 return 0; 520 return 0;
546} 521}
547 522
548 523
549static void mpc83xx_spi_cleanup(struct spi_device *spi) 524static void mpc8xxx_spi_cleanup(struct spi_device *spi)
550{ 525{
551 kfree(spi->controller_state); 526 kfree(spi->controller_state);
552} 527}
553 528
554static struct spi_master * __devinit 529static struct spi_master * __devinit
555mpc83xx_spi_probe(struct device *dev, struct resource *mem, unsigned int irq) 530mpc8xxx_spi_probe(struct device *dev, struct resource *mem, unsigned int irq)
556{ 531{
557 struct fsl_spi_platform_data *pdata = dev->platform_data; 532 struct fsl_spi_platform_data *pdata = dev->platform_data;
558 struct spi_master *master; 533 struct spi_master *master;
559 struct mpc83xx_spi *mpc83xx_spi; 534 struct mpc8xxx_spi *mpc8xxx_spi;
560 u32 regval; 535 u32 regval;
561 int ret = 0; 536 int ret = 0;
562 537
563 master = spi_alloc_master(dev, sizeof(struct mpc83xx_spi)); 538 master = spi_alloc_master(dev, sizeof(struct mpc8xxx_spi));
564 if (master == NULL) { 539 if (master == NULL) {
565 ret = -ENOMEM; 540 ret = -ENOMEM;
566 goto err; 541 goto err;
@@ -568,36 +543,40 @@ mpc83xx_spi_probe(struct device *dev, struct resource *mem, unsigned int irq)
568 543
569 dev_set_drvdata(dev, master); 544 dev_set_drvdata(dev, master);
570 545
571 master->setup = mpc83xx_spi_setup; 546 /* the spi->mode bits understood by this driver: */
572 master->transfer = mpc83xx_spi_transfer; 547 master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH
573 master->cleanup = mpc83xx_spi_cleanup; 548 | SPI_LSB_FIRST | SPI_LOOP;
574 549
575 mpc83xx_spi = spi_master_get_devdata(master); 550 master->setup = mpc8xxx_spi_setup;
576 mpc83xx_spi->qe_mode = pdata->qe_mode; 551 master->transfer = mpc8xxx_spi_transfer;
577 mpc83xx_spi->get_rx = mpc83xx_spi_rx_buf_u8; 552 master->cleanup = mpc8xxx_spi_cleanup;
578 mpc83xx_spi->get_tx = mpc83xx_spi_tx_buf_u8; 553
579 mpc83xx_spi->spibrg = pdata->sysclk; 554 mpc8xxx_spi = spi_master_get_devdata(master);
580 555 mpc8xxx_spi->qe_mode = pdata->qe_mode;
581 mpc83xx_spi->rx_shift = 0; 556 mpc8xxx_spi->get_rx = mpc8xxx_spi_rx_buf_u8;
582 mpc83xx_spi->tx_shift = 0; 557 mpc8xxx_spi->get_tx = mpc8xxx_spi_tx_buf_u8;
583 if (mpc83xx_spi->qe_mode) { 558 mpc8xxx_spi->spibrg = pdata->sysclk;
584 mpc83xx_spi->rx_shift = 16; 559
585 mpc83xx_spi->tx_shift = 24; 560 mpc8xxx_spi->rx_shift = 0;
561 mpc8xxx_spi->tx_shift = 0;
562 if (mpc8xxx_spi->qe_mode) {
563 mpc8xxx_spi->rx_shift = 16;
564 mpc8xxx_spi->tx_shift = 24;
586 } 565 }
587 566
588 init_completion(&mpc83xx_spi->done); 567 init_completion(&mpc8xxx_spi->done);
589 568
590 mpc83xx_spi->base = ioremap(mem->start, mem->end - mem->start + 1); 569 mpc8xxx_spi->base = ioremap(mem->start, mem->end - mem->start + 1);
591 if (mpc83xx_spi->base == NULL) { 570 if (mpc8xxx_spi->base == NULL) {
592 ret = -ENOMEM; 571 ret = -ENOMEM;
593 goto put_master; 572 goto put_master;
594 } 573 }
595 574
596 mpc83xx_spi->irq = irq; 575 mpc8xxx_spi->irq = irq;
597 576
598 /* Register for SPI Interrupt */ 577 /* Register for SPI Interrupt */
599 ret = request_irq(mpc83xx_spi->irq, mpc83xx_spi_irq, 578 ret = request_irq(mpc8xxx_spi->irq, mpc8xxx_spi_irq,
600 0, "mpc83xx_spi", mpc83xx_spi); 579 0, "mpc8xxx_spi", mpc8xxx_spi);
601 580
602 if (ret != 0) 581 if (ret != 0)
603 goto unmap_io; 582 goto unmap_io;
@@ -606,25 +585,25 @@ mpc83xx_spi_probe(struct device *dev, struct resource *mem, unsigned int irq)
606 master->num_chipselect = pdata->max_chipselect; 585 master->num_chipselect = pdata->max_chipselect;
607 586
608 /* SPI controller initializations */ 587 /* SPI controller initializations */
609 mpc83xx_spi_write_reg(&mpc83xx_spi->base->mode, 0); 588 mpc8xxx_spi_write_reg(&mpc8xxx_spi->base->mode, 0);
610 mpc83xx_spi_write_reg(&mpc83xx_spi->base->mask, 0); 589 mpc8xxx_spi_write_reg(&mpc8xxx_spi->base->mask, 0);
611 mpc83xx_spi_write_reg(&mpc83xx_spi->base->command, 0); 590 mpc8xxx_spi_write_reg(&mpc8xxx_spi->base->command, 0);
612 mpc83xx_spi_write_reg(&mpc83xx_spi->base->event, 0xffffffff); 591 mpc8xxx_spi_write_reg(&mpc8xxx_spi->base->event, 0xffffffff);
613 592
614 /* Enable SPI interface */ 593 /* Enable SPI interface */
615 regval = pdata->initial_spmode | SPMODE_INIT_VAL | SPMODE_ENABLE; 594 regval = pdata->initial_spmode | SPMODE_INIT_VAL | SPMODE_ENABLE;
616 if (pdata->qe_mode) 595 if (pdata->qe_mode)
617 regval |= SPMODE_OP; 596 regval |= SPMODE_OP;
618 597
619 mpc83xx_spi_write_reg(&mpc83xx_spi->base->mode, regval); 598 mpc8xxx_spi_write_reg(&mpc8xxx_spi->base->mode, regval);
620 spin_lock_init(&mpc83xx_spi->lock); 599 spin_lock_init(&mpc8xxx_spi->lock);
621 init_completion(&mpc83xx_spi->done); 600 init_completion(&mpc8xxx_spi->done);
622 INIT_WORK(&mpc83xx_spi->work, mpc83xx_spi_work); 601 INIT_WORK(&mpc8xxx_spi->work, mpc8xxx_spi_work);
623 INIT_LIST_HEAD(&mpc83xx_spi->queue); 602 INIT_LIST_HEAD(&mpc8xxx_spi->queue);
624 603
625 mpc83xx_spi->workqueue = create_singlethread_workqueue( 604 mpc8xxx_spi->workqueue = create_singlethread_workqueue(
626 dev_name(master->dev.parent)); 605 dev_name(master->dev.parent));
627 if (mpc83xx_spi->workqueue == NULL) { 606 if (mpc8xxx_spi->workqueue == NULL) {
628 ret = -EBUSY; 607 ret = -EBUSY;
629 goto free_irq; 608 goto free_irq;
630 } 609 }
@@ -634,57 +613,57 @@ mpc83xx_spi_probe(struct device *dev, struct resource *mem, unsigned int irq)
634 goto unreg_master; 613 goto unreg_master;
635 614
636 printk(KERN_INFO 615 printk(KERN_INFO
637 "%s: MPC83xx SPI Controller driver at 0x%p (irq = %d)\n", 616 "%s: MPC8xxx SPI Controller driver at 0x%p (irq = %d)\n",
638 dev_name(dev), mpc83xx_spi->base, mpc83xx_spi->irq); 617 dev_name(dev), mpc8xxx_spi->base, mpc8xxx_spi->irq);
639 618
640 return master; 619 return master;
641 620
642unreg_master: 621unreg_master:
643 destroy_workqueue(mpc83xx_spi->workqueue); 622 destroy_workqueue(mpc8xxx_spi->workqueue);
644free_irq: 623free_irq:
645 free_irq(mpc83xx_spi->irq, mpc83xx_spi); 624 free_irq(mpc8xxx_spi->irq, mpc8xxx_spi);
646unmap_io: 625unmap_io:
647 iounmap(mpc83xx_spi->base); 626 iounmap(mpc8xxx_spi->base);
648put_master: 627put_master:
649 spi_master_put(master); 628 spi_master_put(master);
650err: 629err:
651 return ERR_PTR(ret); 630 return ERR_PTR(ret);
652} 631}
653 632
654static int __devexit mpc83xx_spi_remove(struct device *dev) 633static int __devexit mpc8xxx_spi_remove(struct device *dev)
655{ 634{
656 struct mpc83xx_spi *mpc83xx_spi; 635 struct mpc8xxx_spi *mpc8xxx_spi;
657 struct spi_master *master; 636 struct spi_master *master;
658 637
659 master = dev_get_drvdata(dev); 638 master = dev_get_drvdata(dev);
660 mpc83xx_spi = spi_master_get_devdata(master); 639 mpc8xxx_spi = spi_master_get_devdata(master);
661 640
662 flush_workqueue(mpc83xx_spi->workqueue); 641 flush_workqueue(mpc8xxx_spi->workqueue);
663 destroy_workqueue(mpc83xx_spi->workqueue); 642 destroy_workqueue(mpc8xxx_spi->workqueue);
664 spi_unregister_master(master); 643 spi_unregister_master(master);
665 644
666 free_irq(mpc83xx_spi->irq, mpc83xx_spi); 645 free_irq(mpc8xxx_spi->irq, mpc8xxx_spi);
667 iounmap(mpc83xx_spi->base); 646 iounmap(mpc8xxx_spi->base);
668 647
669 return 0; 648 return 0;
670} 649}
671 650
672struct mpc83xx_spi_probe_info { 651struct mpc8xxx_spi_probe_info {
673 struct fsl_spi_platform_data pdata; 652 struct fsl_spi_platform_data pdata;
674 int *gpios; 653 int *gpios;
675 bool *alow_flags; 654 bool *alow_flags;
676}; 655};
677 656
678static struct mpc83xx_spi_probe_info * 657static struct mpc8xxx_spi_probe_info *
679to_of_pinfo(struct fsl_spi_platform_data *pdata) 658to_of_pinfo(struct fsl_spi_platform_data *pdata)
680{ 659{
681 return container_of(pdata, struct mpc83xx_spi_probe_info, pdata); 660 return container_of(pdata, struct mpc8xxx_spi_probe_info, pdata);
682} 661}
683 662
684static void mpc83xx_spi_cs_control(struct spi_device *spi, bool on) 663static void mpc8xxx_spi_cs_control(struct spi_device *spi, bool on)
685{ 664{
686 struct device *dev = spi->dev.parent; 665 struct device *dev = spi->dev.parent;
687 struct mpc83xx_spi_probe_info *pinfo = to_of_pinfo(dev->platform_data); 666 struct mpc8xxx_spi_probe_info *pinfo = to_of_pinfo(dev->platform_data);
688 u16 cs = spi->chip_select; 667 u16 cs = spi->chip_select;
689 int gpio = pinfo->gpios[cs]; 668 int gpio = pinfo->gpios[cs];
690 bool alow = pinfo->alow_flags[cs]; 669 bool alow = pinfo->alow_flags[cs];
@@ -692,11 +671,11 @@ static void mpc83xx_spi_cs_control(struct spi_device *spi, bool on)
692 gpio_set_value(gpio, on ^ alow); 671 gpio_set_value(gpio, on ^ alow);
693} 672}
694 673
695static int of_mpc83xx_spi_get_chipselects(struct device *dev) 674static int of_mpc8xxx_spi_get_chipselects(struct device *dev)
696{ 675{
697 struct device_node *np = dev_archdata_get_node(&dev->archdata); 676 struct device_node *np = dev_archdata_get_node(&dev->archdata);
698 struct fsl_spi_platform_data *pdata = dev->platform_data; 677 struct fsl_spi_platform_data *pdata = dev->platform_data;
699 struct mpc83xx_spi_probe_info *pinfo = to_of_pinfo(pdata); 678 struct mpc8xxx_spi_probe_info *pinfo = to_of_pinfo(pdata);
700 unsigned int ngpios; 679 unsigned int ngpios;
701 int i = 0; 680 int i = 0;
702 int ret; 681 int ret;
@@ -711,12 +690,12 @@ static int of_mpc83xx_spi_get_chipselects(struct device *dev)
711 return 0; 690 return 0;
712 } 691 }
713 692
714 pinfo->gpios = kmalloc(ngpios * sizeof(pinfo->gpios), GFP_KERNEL); 693 pinfo->gpios = kmalloc(ngpios * sizeof(*pinfo->gpios), GFP_KERNEL);
715 if (!pinfo->gpios) 694 if (!pinfo->gpios)
716 return -ENOMEM; 695 return -ENOMEM;
717 memset(pinfo->gpios, -1, ngpios * sizeof(pinfo->gpios)); 696 memset(pinfo->gpios, -1, ngpios * sizeof(*pinfo->gpios));
718 697
719 pinfo->alow_flags = kzalloc(ngpios * sizeof(pinfo->alow_flags), 698 pinfo->alow_flags = kzalloc(ngpios * sizeof(*pinfo->alow_flags),
720 GFP_KERNEL); 699 GFP_KERNEL);
721 if (!pinfo->alow_flags) { 700 if (!pinfo->alow_flags) {
722 ret = -ENOMEM; 701 ret = -ENOMEM;
@@ -752,7 +731,7 @@ static int of_mpc83xx_spi_get_chipselects(struct device *dev)
752 } 731 }
753 732
754 pdata->max_chipselect = ngpios; 733 pdata->max_chipselect = ngpios;
755 pdata->cs_control = mpc83xx_spi_cs_control; 734 pdata->cs_control = mpc8xxx_spi_cs_control;
756 735
757 return 0; 736 return 0;
758 737
@@ -771,10 +750,10 @@ err_alloc_flags:
771 return ret; 750 return ret;
772} 751}
773 752
774static int of_mpc83xx_spi_free_chipselects(struct device *dev) 753static int of_mpc8xxx_spi_free_chipselects(struct device *dev)
775{ 754{
776 struct fsl_spi_platform_data *pdata = dev->platform_data; 755 struct fsl_spi_platform_data *pdata = dev->platform_data;
777 struct mpc83xx_spi_probe_info *pinfo = to_of_pinfo(pdata); 756 struct mpc8xxx_spi_probe_info *pinfo = to_of_pinfo(pdata);
778 int i; 757 int i;
779 758
780 if (!pinfo->gpios) 759 if (!pinfo->gpios)
@@ -790,12 +769,12 @@ static int of_mpc83xx_spi_free_chipselects(struct device *dev)
790 return 0; 769 return 0;
791} 770}
792 771
793static int __devinit of_mpc83xx_spi_probe(struct of_device *ofdev, 772static int __devinit of_mpc8xxx_spi_probe(struct of_device *ofdev,
794 const struct of_device_id *ofid) 773 const struct of_device_id *ofid)
795{ 774{
796 struct device *dev = &ofdev->dev; 775 struct device *dev = &ofdev->dev;
797 struct device_node *np = ofdev->node; 776 struct device_node *np = ofdev->node;
798 struct mpc83xx_spi_probe_info *pinfo; 777 struct mpc8xxx_spi_probe_info *pinfo;
799 struct fsl_spi_platform_data *pdata; 778 struct fsl_spi_platform_data *pdata;
800 struct spi_master *master; 779 struct spi_master *master;
801 struct resource mem; 780 struct resource mem;
@@ -827,7 +806,7 @@ static int __devinit of_mpc83xx_spi_probe(struct of_device *ofdev,
827 if (prop && !strcmp(prop, "cpu-qe")) 806 if (prop && !strcmp(prop, "cpu-qe"))
828 pdata->qe_mode = 1; 807 pdata->qe_mode = 1;
829 808
830 ret = of_mpc83xx_spi_get_chipselects(dev); 809 ret = of_mpc8xxx_spi_get_chipselects(dev);
831 if (ret) 810 if (ret)
832 goto err; 811 goto err;
833 812
@@ -841,7 +820,7 @@ static int __devinit of_mpc83xx_spi_probe(struct of_device *ofdev,
841 goto err; 820 goto err;
842 } 821 }
843 822
844 master = mpc83xx_spi_probe(dev, &mem, irq.start); 823 master = mpc8xxx_spi_probe(dev, &mem, irq.start);
845 if (IS_ERR(master)) { 824 if (IS_ERR(master)) {
846 ret = PTR_ERR(master); 825 ret = PTR_ERR(master);
847 goto err; 826 goto err;
@@ -852,34 +831,34 @@ static int __devinit of_mpc83xx_spi_probe(struct of_device *ofdev,
852 return 0; 831 return 0;
853 832
854err: 833err:
855 of_mpc83xx_spi_free_chipselects(dev); 834 of_mpc8xxx_spi_free_chipselects(dev);
856err_clk: 835err_clk:
857 kfree(pinfo); 836 kfree(pinfo);
858 return ret; 837 return ret;
859} 838}
860 839
861static int __devexit of_mpc83xx_spi_remove(struct of_device *ofdev) 840static int __devexit of_mpc8xxx_spi_remove(struct of_device *ofdev)
862{ 841{
863 int ret; 842 int ret;
864 843
865 ret = mpc83xx_spi_remove(&ofdev->dev); 844 ret = mpc8xxx_spi_remove(&ofdev->dev);
866 if (ret) 845 if (ret)
867 return ret; 846 return ret;
868 of_mpc83xx_spi_free_chipselects(&ofdev->dev); 847 of_mpc8xxx_spi_free_chipselects(&ofdev->dev);
869 return 0; 848 return 0;
870} 849}
871 850
872static const struct of_device_id of_mpc83xx_spi_match[] = { 851static const struct of_device_id of_mpc8xxx_spi_match[] = {
873 { .compatible = "fsl,spi" }, 852 { .compatible = "fsl,spi" },
874 {}, 853 {},
875}; 854};
876MODULE_DEVICE_TABLE(of, of_mpc83xx_spi_match); 855MODULE_DEVICE_TABLE(of, of_mpc8xxx_spi_match);
877 856
878static struct of_platform_driver of_mpc83xx_spi_driver = { 857static struct of_platform_driver of_mpc8xxx_spi_driver = {
879 .name = "mpc83xx_spi", 858 .name = "mpc8xxx_spi",
880 .match_table = of_mpc83xx_spi_match, 859 .match_table = of_mpc8xxx_spi_match,
881 .probe = of_mpc83xx_spi_probe, 860 .probe = of_mpc8xxx_spi_probe,
882 .remove = __devexit_p(of_mpc83xx_spi_remove), 861 .remove = __devexit_p(of_mpc8xxx_spi_remove),
883}; 862};
884 863
885#ifdef CONFIG_MPC832x_RDB 864#ifdef CONFIG_MPC832x_RDB
@@ -890,7 +869,7 @@ static struct of_platform_driver of_mpc83xx_spi_driver = {
890 * tree can work with OpenFirmware driver. But for now we support old trees 869 * tree can work with OpenFirmware driver. But for now we support old trees
891 * as well. 870 * as well.
892 */ 871 */
893static int __devinit plat_mpc83xx_spi_probe(struct platform_device *pdev) 872static int __devinit plat_mpc8xxx_spi_probe(struct platform_device *pdev)
894{ 873{
895 struct resource *mem; 874 struct resource *mem;
896 unsigned int irq; 875 unsigned int irq;
@@ -907,23 +886,23 @@ static int __devinit plat_mpc83xx_spi_probe(struct platform_device *pdev)
907 if (!irq) 886 if (!irq)
908 return -EINVAL; 887 return -EINVAL;
909 888
910 master = mpc83xx_spi_probe(&pdev->dev, mem, irq); 889 master = mpc8xxx_spi_probe(&pdev->dev, mem, irq);
911 if (IS_ERR(master)) 890 if (IS_ERR(master))
912 return PTR_ERR(master); 891 return PTR_ERR(master);
913 return 0; 892 return 0;
914} 893}
915 894
916static int __devexit plat_mpc83xx_spi_remove(struct platform_device *pdev) 895static int __devexit plat_mpc8xxx_spi_remove(struct platform_device *pdev)
917{ 896{
918 return mpc83xx_spi_remove(&pdev->dev); 897 return mpc8xxx_spi_remove(&pdev->dev);
919} 898}
920 899
921MODULE_ALIAS("platform:mpc83xx_spi"); 900MODULE_ALIAS("platform:mpc8xxx_spi");
922static struct platform_driver mpc83xx_spi_driver = { 901static struct platform_driver mpc8xxx_spi_driver = {
923 .probe = plat_mpc83xx_spi_probe, 902 .probe = plat_mpc8xxx_spi_probe,
924 .remove = __exit_p(plat_mpc83xx_spi_remove), 903 .remove = __exit_p(plat_mpc8xxx_spi_remove),
925 .driver = { 904 .driver = {
926 .name = "mpc83xx_spi", 905 .name = "mpc8xxx_spi",
927 .owner = THIS_MODULE, 906 .owner = THIS_MODULE,
928 }, 907 },
929}; 908};
@@ -932,35 +911,35 @@ static bool legacy_driver_failed;
932 911
933static void __init legacy_driver_register(void) 912static void __init legacy_driver_register(void)
934{ 913{
935 legacy_driver_failed = platform_driver_register(&mpc83xx_spi_driver); 914 legacy_driver_failed = platform_driver_register(&mpc8xxx_spi_driver);
936} 915}
937 916
938static void __exit legacy_driver_unregister(void) 917static void __exit legacy_driver_unregister(void)
939{ 918{
940 if (legacy_driver_failed) 919 if (legacy_driver_failed)
941 return; 920 return;
942 platform_driver_unregister(&mpc83xx_spi_driver); 921 platform_driver_unregister(&mpc8xxx_spi_driver);
943} 922}
944#else 923#else
945static void __init legacy_driver_register(void) {} 924static void __init legacy_driver_register(void) {}
946static void __exit legacy_driver_unregister(void) {} 925static void __exit legacy_driver_unregister(void) {}
947#endif /* CONFIG_MPC832x_RDB */ 926#endif /* CONFIG_MPC832x_RDB */
948 927
949static int __init mpc83xx_spi_init(void) 928static int __init mpc8xxx_spi_init(void)
950{ 929{
951 legacy_driver_register(); 930 legacy_driver_register();
952 return of_register_platform_driver(&of_mpc83xx_spi_driver); 931 return of_register_platform_driver(&of_mpc8xxx_spi_driver);
953} 932}
954 933
955static void __exit mpc83xx_spi_exit(void) 934static void __exit mpc8xxx_spi_exit(void)
956{ 935{
957 of_unregister_platform_driver(&of_mpc83xx_spi_driver); 936 of_unregister_platform_driver(&of_mpc8xxx_spi_driver);
958 legacy_driver_unregister(); 937 legacy_driver_unregister();
959} 938}
960 939
961module_init(mpc83xx_spi_init); 940module_init(mpc8xxx_spi_init);
962module_exit(mpc83xx_spi_exit); 941module_exit(mpc8xxx_spi_exit);
963 942
964MODULE_AUTHOR("Kumar Gala"); 943MODULE_AUTHOR("Kumar Gala");
965MODULE_DESCRIPTION("Simple MPC83xx SPI Driver"); 944MODULE_DESCRIPTION("Simple MPC8xxx SPI Driver");
966MODULE_LICENSE("GPL"); 945MODULE_LICENSE("GPL");
diff --git a/drivers/spi/spi_s3c24xx.c b/drivers/spi/spi_s3c24xx.c
index b3ebc1d0f85f..e0d44af4745a 100644
--- a/drivers/spi/spi_s3c24xx.c
+++ b/drivers/spi/spi_s3c24xx.c
@@ -146,32 +146,16 @@ static int s3c24xx_spi_setupxfer(struct spi_device *spi,
146 return 0; 146 return 0;
147} 147}
148 148
149/* the spi->mode bits understood by this driver: */
150#define MODEBITS (SPI_CPOL | SPI_CPHA | SPI_CS_HIGH)
151
152static int s3c24xx_spi_setup(struct spi_device *spi) 149static int s3c24xx_spi_setup(struct spi_device *spi)
153{ 150{
154 int ret; 151 int ret;
155 152
156 if (!spi->bits_per_word)
157 spi->bits_per_word = 8;
158
159 if (spi->mode & ~MODEBITS) {
160 dev_dbg(&spi->dev, "setup: unsupported mode bits %x\n",
161 spi->mode & ~MODEBITS);
162 return -EINVAL;
163 }
164
165 ret = s3c24xx_spi_setupxfer(spi, NULL); 153 ret = s3c24xx_spi_setupxfer(spi, NULL);
166 if (ret < 0) { 154 if (ret < 0) {
167 dev_err(&spi->dev, "setupxfer returned %d\n", ret); 155 dev_err(&spi->dev, "setupxfer returned %d\n", ret);
168 return ret; 156 return ret;
169 } 157 }
170 158
171 dev_dbg(&spi->dev, "%s: mode %d, %u bpw, %d hz\n",
172 __func__, spi->mode, spi->bits_per_word,
173 spi->max_speed_hz);
174
175 return 0; 159 return 0;
176} 160}
177 161
@@ -290,6 +274,9 @@ static int __init s3c24xx_spi_probe(struct platform_device *pdev)
290 274
291 /* setup the master state. */ 275 /* setup the master state. */
292 276
277 /* the spi->mode bits understood by this driver: */
278 master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH;
279
293 master->num_chipselect = hw->pdata->num_cs; 280 master->num_chipselect = hw->pdata->num_cs;
294 master->bus_num = pdata->bus_num; 281 master->bus_num = pdata->bus_num;
295 282
diff --git a/drivers/spi/spi_s3c24xx_gpio.c b/drivers/spi/spi_s3c24xx_gpio.c
index f2447a5476bb..bbf9371cd284 100644
--- a/drivers/spi/spi_s3c24xx_gpio.c
+++ b/drivers/spi/spi_s3c24xx_gpio.c
@@ -17,6 +17,7 @@
17#include <linux/spinlock.h> 17#include <linux/spinlock.h>
18#include <linux/workqueue.h> 18#include <linux/workqueue.h>
19#include <linux/platform_device.h> 19#include <linux/platform_device.h>
20#include <linux/gpio.h>
20 21
21#include <linux/spi/spi.h> 22#include <linux/spi/spi.h>
22#include <linux/spi/spi_bitbang.h> 23#include <linux/spi/spi_bitbang.h>
diff --git a/drivers/spi/spi_txx9.c b/drivers/spi/spi_txx9.c
index 29cbb065618a..96057de133ad 100644
--- a/drivers/spi/spi_txx9.c
+++ b/drivers/spi/spi_txx9.c
@@ -110,23 +110,17 @@ static void txx9spi_cs_func(struct spi_device *spi, struct txx9spi *c,
110 ndelay(cs_delay); /* CS Setup Time / CS Recovery Time */ 110 ndelay(cs_delay); /* CS Setup Time / CS Recovery Time */
111} 111}
112 112
113/* the spi->mode bits understood by this driver: */
114#define MODEBITS (SPI_CS_HIGH|SPI_CPOL|SPI_CPHA)
115
116static int txx9spi_setup(struct spi_device *spi) 113static int txx9spi_setup(struct spi_device *spi)
117{ 114{
118 struct txx9spi *c = spi_master_get_devdata(spi->master); 115 struct txx9spi *c = spi_master_get_devdata(spi->master);
119 u8 bits_per_word; 116 u8 bits_per_word;
120 117
121 if (spi->mode & ~MODEBITS)
122 return -EINVAL;
123
124 if (!spi->max_speed_hz 118 if (!spi->max_speed_hz
125 || spi->max_speed_hz > c->max_speed_hz 119 || spi->max_speed_hz > c->max_speed_hz
126 || spi->max_speed_hz < c->min_speed_hz) 120 || spi->max_speed_hz < c->min_speed_hz)
127 return -EINVAL; 121 return -EINVAL;
128 122
129 bits_per_word = spi->bits_per_word ? : 8; 123 bits_per_word = spi->bits_per_word;
130 if (bits_per_word != 8 && bits_per_word != 16) 124 if (bits_per_word != 8 && bits_per_word != 16)
131 return -EINVAL; 125 return -EINVAL;
132 126
@@ -414,6 +408,9 @@ static int __init txx9spi_probe(struct platform_device *dev)
414 (unsigned long long)res->start, irq, 408 (unsigned long long)res->start, irq,
415 (c->baseclk + 500000) / 1000000); 409 (c->baseclk + 500000) / 1000000);
416 410
411 /* the spi->mode bits understood by this driver: */
412 master->mode_bits = SPI_CS_HIGH | SPI_CPOL | SPI_CPHA;
413
417 master->bus_num = dev->id; 414 master->bus_num = dev->id;
418 master->setup = txx9spi_setup; 415 master->setup = txx9spi_setup;
419 master->transfer = txx9spi_transfer; 416 master->transfer = txx9spi_transfer;
diff --git a/drivers/spi/xilinx_spi.c b/drivers/spi/xilinx_spi.c
index 494d3f756e29..46b8c5c2f45e 100644
--- a/drivers/spi/xilinx_spi.c
+++ b/drivers/spi/xilinx_spi.c
@@ -158,9 +158,6 @@ static int xilinx_spi_setup_transfer(struct spi_device *spi,
158 return 0; 158 return 0;
159} 159}
160 160
161/* the spi->mode bits understood by this driver: */
162#define MODEBITS (SPI_CPOL | SPI_CPHA)
163
164static int xilinx_spi_setup(struct spi_device *spi) 161static int xilinx_spi_setup(struct spi_device *spi)
165{ 162{
166 struct spi_bitbang *bitbang; 163 struct spi_bitbang *bitbang;
@@ -170,22 +167,10 @@ static int xilinx_spi_setup(struct spi_device *spi)
170 xspi = spi_master_get_devdata(spi->master); 167 xspi = spi_master_get_devdata(spi->master);
171 bitbang = &xspi->bitbang; 168 bitbang = &xspi->bitbang;
172 169
173 if (!spi->bits_per_word)
174 spi->bits_per_word = 8;
175
176 if (spi->mode & ~MODEBITS) {
177 dev_err(&spi->dev, "%s, unsupported mode bits %x\n",
178 __func__, spi->mode & ~MODEBITS);
179 return -EINVAL;
180 }
181
182 retval = xilinx_spi_setup_transfer(spi, NULL); 170 retval = xilinx_spi_setup_transfer(spi, NULL);
183 if (retval < 0) 171 if (retval < 0)
184 return retval; 172 return retval;
185 173
186 dev_dbg(&spi->dev, "%s, mode %d, %u bits/w, %u nsec/bit\n",
187 __func__, spi->mode & MODEBITS, spi->bits_per_word, 0);
188
189 return 0; 174 return 0;
190} 175}
191 176
@@ -333,6 +318,9 @@ static int __init xilinx_spi_of_probe(struct of_device *ofdev,
333 goto put_master; 318 goto put_master;
334 } 319 }
335 320
321 /* the spi->mode bits understood by this driver: */
322 master->mode_bits = SPI_CPOL | SPI_CPHA;
323
336 xspi = spi_master_get_devdata(master); 324 xspi = spi_master_get_devdata(master);
337 xspi->bitbang.master = spi_master_get(master); 325 xspi->bitbang.master = spi_master_get(master);
338 xspi->bitbang.chipselect = xilinx_spi_chipselect; 326 xspi->bitbang.chipselect = xilinx_spi_chipselect;