1 --- a/arch/mips/bcm63xx/cpu.c
2 +++ b/arch/mips/bcm63xx/cpu.c
3 @@ -56,6 +56,7 @@ static const unsigned long bcm96338_regs
5 static const int bcm96338_irqs[] = {
6 [IRQ_TIMER] = BCM_6338_TIMER_IRQ,
7 + [IRQ_SPI] = BCM_6338_SPI_IRQ,
8 [IRQ_UART0] = BCM_6338_UART0_IRQ,
9 [IRQ_DSL] = BCM_6338_DSL_IRQ,
10 [IRQ_ENET0] = BCM_6338_ENET0_IRQ,
11 @@ -130,6 +131,7 @@ static const unsigned long bcm96348_regs
13 static const int bcm96348_irqs[] = {
14 [IRQ_TIMER] = BCM_6348_TIMER_IRQ,
15 + [IRQ_SPI] = BCM_6348_SPI_IRQ,
16 [IRQ_UART0] = BCM_6348_UART0_IRQ,
17 [IRQ_DSL] = BCM_6348_DSL_IRQ,
18 [IRQ_ENET0] = BCM_6348_ENET0_IRQ,
19 @@ -173,6 +175,7 @@ static const unsigned long bcm96358_regs
21 static const int bcm96358_irqs[] = {
22 [IRQ_TIMER] = BCM_6358_TIMER_IRQ,
23 + [IRQ_SPI] = BCM_6358_SPI_IRQ,
24 [IRQ_UART0] = BCM_6358_UART0_IRQ,
25 [IRQ_UART1] = BCM_6358_UART1_IRQ,
26 [IRQ_DSL] = BCM_6358_DSL_IRQ,
28 +++ b/arch/mips/bcm63xx/dev-spi.c
31 + * This file is subject to the terms and conditions of the GNU General Public
32 + * License. See the file "COPYING" in the main directory of this archive
35 + * Copyright (C) 2009 Florian Fainelli <florian@openwrt.org>
38 +#include <linux/init.h>
39 +#include <linux/kernel.h>
40 +#include <linux/platform_device.h>
42 +#include <bcm63xx_cpu.h>
43 +#include <bcm63xx_dev_spi.h>
44 +#include <bcm63xx_regs.h>
46 +#ifdef BCMCPU_RUNTIME_DETECT
50 +static const unsigned long bcm96338_regs_spi[] = {
51 + [SPI_CMD] = SPI_BCM_6338_SPI_CMD,
52 + [SPI_INT_STATUS] = SPI_BCM_6338_SPI_INT_STATUS,
53 + [SPI_INT_MASK_ST] = SPI_BCM_6338_SPI_MASK_INT_ST,
54 + [SPI_INT_MASK] = SPI_BCM_6338_SPI_INT_MASK,
55 + [SPI_ST] = SPI_BCM_6338_SPI_ST,
56 + [SPI_CLK_CFG] = SPI_BCM_6338_SPI_CLK_CFG,
57 + [SPI_FILL_BYTE] = SPI_BCM_6338_SPI_FILL_BYTE,
58 + [SPI_MSG_TAIL] = SPI_BCM_6338_SPI_MSG_TAIL,
59 + [SPI_RX_TAIL] = SPI_BCM_6338_SPI_RX_TAIL,
60 + [SPI_MSG_CTL] = SPI_BCM_6338_SPI_MSG_CTL,
61 + [SPI_MSG_DATA] = SPI_BCM_6338_SPI_MSG_DATA,
62 + [SPI_RX_DATA] = SPI_BCM_6338_SPI_RX_DATA,
65 +static const unsigned long bcm96348_regs_spi[] = {
66 + [SPI_CMD] = SPI_BCM_6348_SPI_CMD,
67 + [SPI_INT_STATUS] = SPI_BCM_6348_SPI_INT_STATUS,
68 + [SPI_INT_MASK_ST] = SPI_BCM_6348_SPI_MASK_INT_ST,
69 + [SPI_INT_MASK] = SPI_BCM_6348_SPI_INT_MASK,
70 + [SPI_ST] = SPI_BCM_6348_SPI_ST,
71 + [SPI_CLK_CFG] = SPI_BCM_6348_SPI_CLK_CFG,
72 + [SPI_FILL_BYTE] = SPI_BCM_6348_SPI_FILL_BYTE,
73 + [SPI_MSG_TAIL] = SPI_BCM_6348_SPI_MSG_TAIL,
74 + [SPI_RX_TAIL] = SPI_BCM_6348_SPI_RX_TAIL,
75 + [SPI_MSG_CTL] = SPI_BCM_6348_SPI_MSG_CTL,
76 + [SPI_MSG_DATA] = SPI_BCM_6348_SPI_MSG_DATA,
77 + [SPI_RX_DATA] = SPI_BCM_6348_SPI_RX_DATA,
80 +static const unsigned long bcm96358_regs_spi[] = {
81 + [SPI_CMD] = SPI_BCM_6358_SPI_CMD,
82 + [SPI_INT_STATUS] = SPI_BCM_6358_SPI_INT_STATUS,
83 + [SPI_INT_MASK_ST] = SPI_BCM_6358_SPI_MASK_INT_ST,
84 + [SPI_INT_MASK] = SPI_BCM_6358_SPI_INT_MASK,
85 + [SPI_ST] = SPI_BCM_6358_SPI_STATUS,
86 + [SPI_CLK_CFG] = SPI_BCM_6358_SPI_CLK_CFG,
87 + [SPI_FILL_BYTE] = SPI_BCM_6358_SPI_FILL_BYTE,
88 + [SPI_MSG_TAIL] = SPI_BCM_6358_SPI_MSG_TAIL,
89 + [SPI_RX_TAIL] = SPI_BCM_6358_SPI_RX_TAIL,
90 + [SPI_MSG_CTL] = SPI_BCM_6358_MSG_CTL,
91 + [SPI_MSG_DATA] = SPI_BCM_6358_SPI_MSG_DATA,
92 + [SPI_RX_DATA] = SPI_BCM_6358_SPI_RX_DATA,
95 +const unsigned long *bcm63xx_regs_spi;
96 +EXPORT_SYMBOL(bcm63xx_regs_spi);
98 +static __init void bcm63xx_spi_regs_init(void)
100 + if (BCMCPU_IS_6338())
101 + bcm63xx_regs_spi = bcm96338_regs_spi;
102 + if (BCMCPU_IS_6348())
103 + bcm63xx_regs_spi = bcm96348_regs_spi;
104 + if (BCMCPU_IS_6358())
105 + bcm63xx_regs_spi = bcm96358_regs_spi;
108 +static __init void bcm63xx_spi_regs_init(void) { }
111 +static struct resource spi_resources[] = {
113 + .start = -1, /* filled at runtime */
114 + .end = -1, /* filled at runtime */
115 + .flags = IORESOURCE_MEM,
118 + .start = -1, /* filled at runtime */
119 + .flags = IORESOURCE_IRQ,
123 +static struct bcm63xx_spi_pdata spi_pdata = {
125 + .num_chipselect = 8,
126 + .speed_hz = 50000000, /* Fclk */
129 +static struct platform_device bcm63xx_spi_device = {
130 + .name = "bcm63xx-spi",
132 + .num_resources = ARRAY_SIZE(spi_resources),
133 + .resource = spi_resources,
135 + .platform_data = &spi_pdata,
139 +int __init bcm63xx_spi_register(void)
141 + spi_resources[0].start = bcm63xx_regset_address(RSET_SPI);
142 + spi_resources[0].end = spi_resources[0].start;
143 + spi_resources[0].end += RSET_SPI_SIZE - 1;
144 + spi_resources[1].start = bcm63xx_get_irq_number(IRQ_SPI);
146 + /* Fill in platform data */
147 + if (BCMCPU_IS_6338() || BCMCPU_IS_6348())
148 + spi_pdata.fifo_size = SPI_BCM_6338_SPI_MSG_DATA_SIZE;
150 + if (BCMCPU_IS_6358())
151 + spi_pdata.fifo_size = SPI_BCM_6358_SPI_MSG_DATA_SIZE;
153 + bcm63xx_spi_regs_init();
155 + return platform_device_register(&bcm63xx_spi_device);
157 --- a/arch/mips/include/asm/mach-bcm63xx/bcm63xx_cpu.h
158 +++ b/arch/mips/include/asm/mach-bcm63xx/bcm63xx_cpu.h
159 @@ -109,6 +109,7 @@ enum bcm63xx_regs_set {
160 #define RSET_WDT_SIZE 12
161 #define RSET_ENET_SIZE 2048
162 #define RSET_ENETDMA_SIZE 2048
163 +#define RSET_SPI_SIZE 256
164 #define RSET_UART_SIZE 24
165 #define RSET_UDC_SIZE 256
166 #define RSET_OHCI_SIZE 256
167 @@ -214,7 +215,7 @@ enum bcm63xx_regs_set {
168 #define BCM_6358_UART0_BASE (0xfffe0100)
169 #define BCM_6358_UART1_BASE (0xfffe0120)
170 #define BCM_6358_GPIO_BASE (0xfffe0080)
171 -#define BCM_6358_SPI_BASE (0xdeadbeef)
172 +#define BCM_6358_SPI_BASE (0xfffe0800)
173 #define BCM_6358_UDC0_BASE (0xfffe0400)
174 #define BCM_6358_OHCI0_BASE (0xfffe1400)
175 #define BCM_6358_OHCI_PRIV_BASE (0xdeadbeef)
176 @@ -441,6 +442,7 @@ static inline unsigned long bcm63xx_regs
184 @@ -507,6 +509,7 @@ enum bcm63xx_irq {
187 #define BCM_6348_TIMER_IRQ (IRQ_INTERNAL_BASE + 0)
188 +#define BCM_6348_SPI_IRQ (IRQ_INTERNAL_BASE + 1)
189 #define BCM_6348_UART0_IRQ (IRQ_INTERNAL_BASE + 2)
190 #define BCM_6348_DSL_IRQ (IRQ_INTERNAL_BASE + 4)
191 #define BCM_6348_UDC0_IRQ (IRQ_INTERNAL_BASE + 6)
192 @@ -531,6 +534,7 @@ enum bcm63xx_irq {
195 #define BCM_6358_TIMER_IRQ (IRQ_INTERNAL_BASE + 0)
196 +#define BCM_6358_SPI_IRQ (IRQ_INTERNAL_BASE + 1)
197 #define BCM_6358_UART0_IRQ (IRQ_INTERNAL_BASE + 2)
198 #define BCM_6358_UART1_IRQ (IRQ_INTERNAL_BASE + 3)
199 #define BCM_6358_OHCI0_IRQ (IRQ_INTERNAL_BASE + 5)
200 --- a/arch/mips/include/asm/mach-bcm63xx/bcm63xx_regs.h
201 +++ b/arch/mips/include/asm/mach-bcm63xx/bcm63xx_regs.h
202 @@ -769,4 +769,116 @@
203 #define DMIPSPLLCFG_N2_SHIFT 29
204 #define DMIPSPLLCFG_N2_MASK (0x7 << DMIPSPLLCFG_N2_SHIFT)
206 +/*************************************************************************
207 + * _REG relative to RSET_SPI
208 + *************************************************************************/
210 +/* BCM 6338 SPI core */
211 +#define SPI_BCM_6338_SPI_CMD 0x00 /* 16-bits register */
212 +#define SPI_BCM_6338_SPI_INT_STATUS 0x02
213 +#define SPI_BCM_6338_SPI_MASK_INT_ST 0x03
214 +#define SPI_BCM_6338_SPI_INT_MASK 0x04
215 +#define SPI_BCM_6338_SPI_ST 0x05
216 +#define SPI_BCM_6338_SPI_CLK_CFG 0x06
217 +#define SPI_BCM_6338_SPI_FILL_BYTE 0x07
218 +#define SPI_BCM_6338_SPI_MSG_TAIL 0x09
219 +#define SPI_BCM_6338_SPI_RX_TAIL 0x0b
220 +#define SPI_BCM_6338_SPI_MSG_CTL 0x40
221 +#define SPI_BCM_6338_SPI_MSG_DATA 0x41
222 +#define SPI_BCM_6338_SPI_MSG_DATA_SIZE 0x3f
223 +#define SPI_BCM_6338_SPI_RX_DATA 0x80
224 +#define SPI_BCM_6338_SPI_RX_DATA_SIZE 0x3f
226 +/* BCM 6348 SPI core */
227 +#define SPI_BCM_6348_SPI_MASK_INT_ST 0x00
228 +#define SPI_BCM_6348_SPI_INT_STATUS 0x01
229 +#define SPI_BCM_6348_SPI_CMD 0x02 /* 16-bits register */
230 +#define SPI_BCM_6348_SPI_FILL_BYTE 0x04
231 +#define SPI_BCM_6348_SPI_CLK_CFG 0x05
232 +#define SPI_BCM_6348_SPI_ST 0x06
233 +#define SPI_BCM_6348_SPI_INT_MASK 0x07
234 +#define SPI_BCM_6348_SPI_RX_TAIL 0x08
235 +#define SPI_BCM_6348_SPI_MSG_TAIL 0x10
236 +#define SPI_BCM_6348_SPI_MSG_DATA 0x40
237 +#define SPI_BCM_6348_SPI_MSG_CTL 0x42
238 +#define SPI_BCM_6348_SPI_MSG_DATA_SIZE 0x3f
239 +#define SPI_BCM_6348_SPI_RX_DATA 0x80
240 +#define SPI_BCM_6348_SPI_RX_DATA_SIZE 0x3f
242 +/* BCM 6358 SPI core */
243 +#define SPI_BCM_6358_MSG_CTL 0x00 /* 16-bits register */
245 +#define SPI_BCM_6358_SPI_MSG_DATA 0x02
246 +#define SPI_BCM_6358_SPI_MSG_DATA_SIZE 0x21e
248 +#define SPI_BCM_6358_SPI_RX_DATA 0x400
249 +#define SPI_BCM_6358_SPI_RX_DATA_SIZE 0x220
251 +#define SPI_BCM_6358_SPI_CMD 0x700 /* 16-bits register */
253 +#define SPI_BCM_6358_SPI_INT_STATUS 0x702
254 +#define SPI_BCM_6358_SPI_MASK_INT_ST 0x703
256 +#define SPI_BCM_6358_SPI_INT_MASK 0x704
258 +#define SPI_BCM_6358_SPI_STATUS 0x705
260 +#define SPI_BCM_6358_SPI_CLK_CFG 0x706
262 +#define SPI_BCM_6358_SPI_FILL_BYTE 0x707
263 +#define SPI_BCM_6358_SPI_MSG_TAIL 0x709
264 +#define SPI_BCM_6358_SPI_RX_TAIL 0x70B
266 +/* Shared SPI definitions */
268 +/* Message configuration */
269 +#define SPI_FD_RW 0x00
270 +#define SPI_HD_W 0x01
271 +#define SPI_HD_R 0x02
272 +#define SPI_BYTE_CNT_SHIFT 0
273 +#define SPI_MSG_TYPE_SHIFT 14
276 +#define SPI_CMD_NOOP 0x01
277 +#define SPI_CMD_SOFT_RESET 0x02
278 +#define SPI_CMD_HARD_RESET 0x04
279 +#define SPI_CMD_START_IMMEDIATE 0x08
280 +#define SPI_CMD_COMMAND_SHIFT 0
281 +#define SPI_CMD_COMMAND_MASK 0x000f
282 +#define SPI_CMD_DEVICE_ID_SHIFT 4
283 +#define SPI_CMD_PREPEND_BYTE_CNT_SHIFT 8
284 +#define SPI_CMD_ONE_BYTE_SHIFT 11
285 +#define SPI_CMD_ONE_WIRE_SHIFT 12
286 +#define SPI_DEV_ID_0 0
287 +#define SPI_DEV_ID_1 1
288 +#define SPI_DEV_ID_2 2
289 +#define SPI_DEV_ID_3 3
291 +/* Interrupt mask */
292 +#define SPI_INTR_CMD_DONE 0x01
293 +#define SPI_INTR_RX_OVERFLOW 0x02
294 +#define SPI_INTR_TX_UNDERFLOW 0x04
295 +#define SPI_INTR_TX_OVERFLOW 0x08
296 +#define SPI_INTR_RX_UNDERFLOW 0x10
297 +#define SPI_INTR_CLEAR_ALL 0x1f
300 +#define SPI_RX_EMPTY 0x02
301 +#define SPI_CMD_BUSY 0x04
302 +#define SPI_SERIAL_BUSY 0x08
304 +/* Clock configuration */
305 +#define SPI_CLK_20MHZ 0x00
306 +#define SPI_CLK_0_391MHZ 0x01
307 +#define SPI_CLK_0_781MHZ 0x02 /* default */
308 +#define SPI_CLK_1_563MHZ 0x03
309 +#define SPI_CLK_3_125MHZ 0x04
310 +#define SPI_CLK_6_250MHZ 0x05
311 +#define SPI_CLK_12_50MHZ 0x06
312 +#define SPI_CLK_25MHZ 0x07
313 +#define SPI_CLK_MASK 0x07
314 +#define SPI_SSOFFTIME_MASK 0x38
315 +#define SPI_SSOFFTIME_SHIFT 3
316 +#define SPI_BYTE_SWAP 0x80
318 #endif /* BCM63XX_REGS_H_ */
320 +++ b/drivers/spi/bcm63xx_spi.c
323 + * Broadcom BCM63xx SPI controller support
325 + * Copyright (C) 2009 Florian Fainelli <florian@openwrt.org>
327 + * This program is free software; you can redistribute it and/or
328 + * modify it under the terms of the GNU General Public License
329 + * as published by the Free Software Foundation; either version 2
330 + * of the License, or (at your option) any later version.
332 + * This program is distributed in the hope that it will be useful,
333 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
334 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
335 + * GNU General Public License for more details.
337 + * You should have received a copy of the GNU General Public License
338 + * along with this program; if not, write to the
339 + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
342 +#include <linux/kernel.h>
343 +#include <linux/init.h>
344 +#include <linux/clk.h>
345 +#include <linux/module.h>
346 +#include <linux/platform_device.h>
347 +#include <linux/delay.h>
348 +#include <linux/interrupt.h>
349 +#include <linux/spi/spi.h>
350 +#include <linux/completion.h>
351 +#include <linux/err.h>
353 +#include <bcm63xx_dev_spi.h>
355 +#define PFX KBUILD_MODNAME
356 +#define DRV_VER "0.1.2"
358 +struct bcm63xx_spi {
361 + struct completion done;
363 + void __iomem *regs;
366 + /* Platform data */
368 + unsigned fifo_size;
371 + const unsigned char *tx_ptr;
372 + unsigned char *rx_ptr;
373 + int remaining_bytes;
376 + struct platform_device *pdev;
379 +static int bcm63xx_spi_setup_transfer(struct spi_device *spi,
380 + struct spi_transfer *t)
387 + struct bcm63xx_spi *bs = spi_master_get_devdata(spi->master);
389 + bits_per_word = (t) ? t->bits_per_word : spi->bits_per_word;
390 + hz = (t) ? t->speed_hz : spi->max_speed_hz;
391 + if (bits_per_word != 8) {
392 + dev_err(&spi->dev, "%s, unsupported bits_per_word=%d\n",
393 + __func__, bits_per_word);
397 + if (spi->chip_select > spi->master->num_chipselect) {
398 + dev_err(&spi->dev, "%s, unsupported slave %d\n",
399 + __func__, spi->chip_select);
403 + /* Check clock setting */
404 + div = (bs->speed_hz / hz);
407 + clk_cfg = SPI_CLK_25MHZ;
410 + clk_cfg = SPI_CLK_12_50MHZ;
413 + clk_cfg = SPI_CLK_6_250MHZ;
416 + clk_cfg = SPI_CLK_3_125MHZ;
419 + clk_cfg = SPI_CLK_1_563MHZ;
422 + clk_cfg = SPI_CLK_0_781MHZ;
426 + /* Set to slowest mode for compatibility */
427 + clk_cfg = SPI_CLK_0_781MHZ;
431 + bcm_spi_writeb(clk_cfg, SPI_CLK_CFG);
432 + dev_dbg(&spi->dev, "Setting clock register to %d (hz %d, cmd %02x)\n",
438 +/* the spi->mode bits understood by this driver: */
439 +#define MODEBITS (SPI_CPOL | SPI_CPHA)
441 +static int bcm63xx_spi_setup(struct spi_device *spi)
443 + struct bcm63xx_spi *bs;
446 + bs = spi_master_get_devdata(spi->master);
451 + if (!spi->bits_per_word)
452 + spi->bits_per_word = 8;
454 + if (spi->mode & ~MODEBITS) {
455 + dev_err(&spi->dev, "%s, unsupported mode bits %x\n",
456 + __func__, spi->mode & ~MODEBITS);
460 + retval = bcm63xx_spi_setup_transfer(spi, NULL);
462 + dev_err(&spi->dev, "setup: unsupported mode bits %x\n",
463 + spi->mode & ~MODEBITS);
467 + dev_dbg(&spi->dev, "%s, mode %d, %u bits/w, %u nsec/bit\n",
468 + __func__, spi->mode & MODEBITS, spi->bits_per_word, 0);
473 +/* Fill the TX FIFO with as many bytes as possible */
474 +static void bcm63xx_spi_fill_tx_fifo(struct bcm63xx_spi *bs)
478 + /* Fill the Tx FIFO with as many bytes as possible */
479 + tail = bcm_spi_readb(SPI_MSG_TAIL);
481 + while ((tail < bs->fifo_size) && (bs->remaining_bytes > 0)) {
483 + bcm_spi_writeb(*bs->tx_ptr++, SPI_MSG_DATA);
485 + bcm_spi_writeb(0, SPI_MSG_DATA);
487 + bs->remaining_bytes--;
488 + tail = bcm_spi_readb(SPI_MSG_TAIL);
492 +static int bcm63xx_txrx_bufs(struct spi_device *spi, struct spi_transfer *t)
494 + struct bcm63xx_spi *bs = spi_master_get_devdata(spi->master);
498 + dev_dbg(&spi->dev, "txrx: tx %p, rx %p, len %d\n",
499 + t->tx_buf, t->rx_buf, t->len);
501 + /* Transmitter is inhibited */
502 + bs->tx_ptr = t->tx_buf;
503 + bs->rx_ptr = t->rx_buf;
504 + init_completion(&bs->done);
507 + bs->remaining_bytes = t->len;
508 + bcm63xx_spi_fill_tx_fifo(bs);
511 + /* Enable the command done interrupt which
512 + * we use to determine completion of a command */
513 + bcm_spi_writeb(SPI_INTR_CMD_DONE, SPI_INT_MASK);
515 + /* Fill in the Message control register */
516 + msg_ctl = (t->len << SPI_BYTE_CNT_SHIFT);
518 + if (t->rx_buf && t->tx_buf)
519 + msg_ctl |= (SPI_FD_RW << SPI_MSG_TYPE_SHIFT);
520 + else if (t->rx_buf)
521 + msg_ctl |= (SPI_HD_R << SPI_MSG_TYPE_SHIFT);
522 + else if (t->tx_buf)
523 + msg_ctl |= (SPI_HD_W << SPI_MSG_TYPE_SHIFT);
525 + bcm_spi_writew(msg_ctl, SPI_MSG_CTL);
527 + /* Issue the transfer */
528 + cmd = SPI_CMD_START_IMMEDIATE;
529 + cmd |= (0 << SPI_CMD_PREPEND_BYTE_CNT_SHIFT);
530 + bcm_spi_writew(cmd, SPI_CMD);
531 + wait_for_completion(&bs->done);
533 + /* Disable the CMD_DONE interrupt */
534 + bcm_spi_writeb(0, SPI_INT_MASK);
536 + return t->len - bs->remaining_bytes;
539 +static int bcm63xx_transfer(struct spi_device *spi, struct spi_message *msg)
541 + struct bcm63xx_spi *bs = spi_master_get_devdata(spi->master);
542 + struct spi_transfer *xfer;
545 + if (unlikely(list_empty(&msg->transfers)))
551 + list_for_each_entry(xfer, &msg->transfers, transfer_list) {
552 + ret += bcm63xx_txrx_bufs(spi, xfer);
555 + msg->complete(msg->context);
560 +/* This driver supports single master mode only. Hence
561 + * CMD_DONE is the only interrupt we care about
563 +static irqreturn_t bcm63xx_spi_interrupt(int irq, void *dev_id)
565 + struct spi_master *master = (struct spi_master *)dev_id;
566 + struct bcm63xx_spi *bs = spi_master_get_devdata(master);
570 + /* Read interupts and clear them immediately */
571 + intr = bcm_spi_readb(SPI_INT_STATUS);
572 + bcm_spi_writeb(SPI_INTR_CLEAR_ALL, SPI_INT_STATUS);
573 + bcm_spi_writeb(0, SPI_INT_MASK);
575 + /* A tansfer completed */
576 + if (intr & SPI_INTR_CMD_DONE) {
579 + rx_tail = bcm_spi_readb(SPI_RX_TAIL);
581 + /* Read out all the data */
586 + for(i = 0; i < rx_tail; i++) {
587 + data = bcm_spi_readb(SPI_RX_DATA);
589 + *bs->rx_ptr++ = data;
593 + /* See if there is more data to send */
594 + if (bs->remaining_bytes > 0) {
595 + bcm63xx_spi_fill_tx_fifo(bs);
597 + /* Start the transfer */
598 + bcm_spi_writew(SPI_HD_W << SPI_MSG_TYPE_SHIFT,
600 + cmd = bcm_spi_readw(SPI_CMD);
601 + cmd |= SPI_CMD_START_IMMEDIATE;
602 + cmd |= (0 << SPI_CMD_PREPEND_BYTE_CNT_SHIFT);
603 + bcm_spi_writeb(SPI_INTR_CMD_DONE, SPI_INT_MASK);
604 + bcm_spi_writew(cmd, SPI_CMD);
606 + complete(&bs->done);
610 + return IRQ_HANDLED;
614 +static int __init bcm63xx_spi_probe(struct platform_device *pdev)
616 + struct resource *r;
617 + struct device *dev = &pdev->dev;
618 + struct bcm63xx_spi_pdata *pdata = pdev->dev.platform_data;
620 + struct spi_master *master;
622 + struct bcm63xx_spi *bs;
625 + r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
627 + dev_err(dev, "no iomem\n");
632 + irq = platform_get_irq(pdev, 0);
634 + dev_err(dev, "no irq\n");
639 + clk = clk_get(&pdev->dev, "spi");
641 + dev_err(dev, "no clock for device\n");
646 + master = spi_alloc_master(&pdev->dev, sizeof(struct bcm63xx_spi));
648 + dev_err(dev, "out of memory\n");
653 + bs = spi_master_get_devdata(master);
654 + init_completion(&bs->done);
656 + platform_set_drvdata(pdev, master);
659 + if (!request_mem_region(r->start,
660 + r->end - r->start, PFX)) {
661 + dev_err(dev, "iomem request failed\n");
663 + goto out_put_master;
666 + bs->regs = ioremap_nocache(r->start, r->end - r->start);
668 + dev_err(dev, "unable to ioremap regs\n");
670 + goto out_put_master;
674 + bs->fifo_size = pdata->fifo_size;
676 + ret = request_irq(irq, bcm63xx_spi_interrupt, 0,
677 + pdev->name, master);
679 + dev_err(dev, "unable to request irq\n");
683 + master->bus_num = pdata->bus_num;
684 + master->num_chipselect = pdata->num_chipselect;
685 + master->setup = bcm63xx_spi_setup;
686 + master->transfer = bcm63xx_transfer;
687 + bs->speed_hz = pdata->speed_hz;
689 + spin_lock_init(&bs->lock);
691 + /* Initialize hardware */
692 + clk_enable(bs->clk);
693 + bcm_spi_writeb(SPI_INTR_CLEAR_ALL, SPI_INT_STATUS);
695 + /* register and we are done */
696 + ret = spi_register_master(master);
698 + dev_err(dev, "spi register failed\n");
702 + dev_info(dev, "at 0x%08x (irq %d, FIFOs size %d) v%s\n",
703 + r->start, irq, bs->fifo_size, DRV_VER);
709 + free_irq(irq, master);
713 + spi_master_put(master);
720 +static int __exit bcm63xx_spi_remove(struct platform_device *pdev)
722 + struct spi_master *master = platform_get_drvdata(pdev);
723 + struct bcm63xx_spi *bs = spi_master_get_devdata(master);
724 + struct resource *r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
726 + /* reset spi block */
727 + bcm_spi_writeb(0, SPI_INT_MASK);
728 + spin_lock(&bs->lock);
732 + clk_disable(bs->clk);
735 + spin_unlock(&bs->lock);
737 + free_irq(bs->irq, master);
739 + release_mem_region(r->start, r->end - r->start);
740 + platform_set_drvdata(pdev, 0);
741 + spi_unregister_master(master);
747 +static int bcm63xx_spi_suspend(struct platform_device *pdev, pm_message_t mesg)
749 + struct spi_master *master = platform_get_drvdata(pdev);
750 + struct bcm63xx_spi *bs = spi_master_get_devdata(master);
752 + clk_disable(bs->clk);
757 +static int bcm63xx_spi_resume(struct platform_device *pdev)
759 + struct spi_master *master = platform_get_drvdata(pdev);
760 + struct bcm63xx_spi *bs = spi_master_get_devdata(master);
762 + clk_enable(bs->clk);
767 +#define bcm63xx_spi_suspend NULL
768 +#define bcm63xx_spi_resume NULL
771 +static struct platform_driver bcm63xx_spi_driver = {
773 + .name = "bcm63xx-spi",
774 + .owner = THIS_MODULE,
776 + .probe = bcm63xx_spi_probe,
777 + .remove = bcm63xx_spi_remove,
778 + .suspend = bcm63xx_spi_suspend,
779 + .resume = bcm63xx_spi_resume,
783 +static int __init bcm63xx_spi_init(void)
785 + return platform_driver_register(&bcm63xx_spi_driver);
788 +static void __exit bcm63xx_spi_exit(void)
790 + platform_driver_unregister(&bcm63xx_spi_driver);
793 +module_init(bcm63xx_spi_init);
794 +module_exit(bcm63xx_spi_exit);
796 +MODULE_ALIAS("platform:bcm63xx_spi");
797 +MODULE_AUTHOR("Florian Fainelli <florian@openwrt.org>");
798 +MODULE_DESCRIPTION("Broadcom BCM63xx SPI Controller driver");
799 +MODULE_LICENSE("GPL");
800 +MODULE_VERSION(DRV_VER);
801 --- a/drivers/spi/Kconfig
802 +++ b/drivers/spi/Kconfig
803 @@ -60,6 +60,12 @@ config SPI_ATMEL
804 This selects a driver for the Atmel SPI Controller, present on
805 many AT32 (AVR32) and AT91 (ARM) chips.
808 + tristate "Broadcom BCM63xx SPI controller"
811 + This is the SPI controller master driver for Broadcom BCM63xx SoC.
814 tristate "SPI controller driver for ADI Blackfin5xx"
816 --- a/drivers/spi/Makefile
817 +++ b/drivers/spi/Makefile
818 @@ -48,6 +48,7 @@ obj-$(CONFIG_SPI_SH_SCI) += spi_sh_sci.
819 obj-$(CONFIG_SPI_SH_MSIOF) += spi_sh_msiof.o
820 obj-$(CONFIG_SPI_STMP3XXX) += spi_stmp.o
821 obj-$(CONFIG_SPI_NUC900) += spi_nuc900.o
822 +obj-$(CONFIG_SPI_BCM63XX) += bcm63xx_spi.o
824 # special build for s3c24xx spi driver with fiq support
825 spi_s3c24xx_hw-y := spi_s3c24xx.o
827 +++ b/arch/mips/include/asm/mach-bcm63xx/bcm63xx_dev_spi.h
829 +#ifndef BCM63XX_DEV_SPI_H
830 +#define BCM63XX_DEV_SPI_H
832 +#include <linux/types.h>
833 +#include <bcm63xx_io.h>
834 +#include <bcm63xx_regs.h>
836 +int __init bcm63xx_spi_register(void);
838 +struct bcm63xx_spi_pdata {
839 + unsigned int fifo_size;
841 + int num_chipselect;
845 +enum bcm63xx_regs_spi {
860 +static inline unsigned long bcm63xx_spireg(enum bcm63xx_regs_spi reg)
862 +#ifdef BCMCPU_RUNTIME_DETECT
863 + extern const unsigned long *bcm63xx_regs_spi;
864 + return bcm63xx_regs_spi[reg];
866 +#ifdef CONFIG_BCM63XX_CPU_6338
869 + return SPI_BCM_6338_SPI_CMD;
870 + case SPI_INT_STATUS:
871 + return SPI_BCM_6338_SPI_INT_STATUS;
872 + case SPI_INT_MASK_ST:
873 + return SPI_BCM_6338_SPI_MASK_INT_ST;
875 + return SPI_BCM_6338_SPI_INT_MASK;
877 + return SPI_BCM_6338_SPI_ST;
879 + return SPI_BCM_6338_SPI_CLK_CFG;
880 + case SPI_FILL_BYTE:
881 + return SPI_BCM_6338_SPI_FILL_BYTE;
883 + return SPI_BCM_6338_SPI_MSG_TAIL;
885 + return SPI_BCM_6338_SPI_RX_TAIL;
887 + return SPI_BCM_6338_SPI_MSG_CTL;
889 + return SPI_BCM_6338_SPI_MSG_DATA;
891 + return SPI_BCM_6338_SPI_RX_DATA;
894 +#ifdef CONFIG_BCM63XX_CPU_6348
897 + return SPI_BCM_6348_SPI_CMD;
898 + case SPI_INT_MASK_ST:
899 + return SPI_BCM_6348_SPI_MASK_INT_ST;
901 + return SPI_BCM_6348_SPI_INT_MASK;
902 + case SPI_INT_STATUS:
903 + return SPI_BCM_6348_SPI_INT_STATUS;
905 + return SPI_BCM_6348_SPI_ST;
907 + return SPI_BCM_6348_SPI_CLK_CFG;
908 + case SPI_FILL_BYTE:
909 + return SPI_BCM_6348_SPI_FILL_BYTE;
911 + return SPI_BCM_6348_SPI_MSG_TAIL;
913 + return SPI_BCM_6348_SPI_RX_TAIL;
915 + return SPI_BCM_6348_SPI_MSG_CTL;
917 + return SPI_BCM_6348_SPI_MSG_DATA;
919 + return SPI_BCM_6348_SPI_RX_DATA;
922 +#ifdef CONFIG_BCM63XX_CPU_6358
925 + return SPI_BCM_6358_SPI_CMD;
926 + case SPI_INT_STATUS:
927 + return SPI_BCM_6358_SPI_INT_STATUS;
928 + case SPI_INT_MASK_ST:
929 + return SPI_BCM_6358_SPI_MASK_INT_ST;
931 + return SPI_BCM_6358_SPI_INT_MASK;
933 + return SPI_BCM_6358_SPI_STATUS;
935 + return SPI_BCM_6358_SPI_CLK_CFG;
936 + case SPI_FILL_BYTE:
937 + return SPI_BCM_6358_SPI_FILL_BYTE;
939 + return SPI_BCM_6358_SPI_MSG_TAIL;
941 + return SPI_BCM_6358_SPI_RX_TAIL;
943 + return SPI_BCM_6358_MSG_CTL;
945 + return SPI_BCM_6358_SPI_MSG_DATA;
947 + return SPI_BCM_6358_SPI_RX_DATA;
955 + * helpers for the SPI register sets
957 +#define bcm_spi_readb(o) bcm_rset_readb(RSET_SPI, bcm63xx_spireg(o))
958 +#define bcm_spi_readw(o) bcm_rset_readw(RSET_SPI, bcm63xx_spireg(o))
959 +#define bcm_spi_readl(o) bcm_rset_readl(RSET_SPI, bcm63xx_spireg(o))
960 +#define bcm_spi_writeb(v,o) bcm_rset_writeb(RSET_SPI, (v), bcm63xx_spireg(o))
961 +#define bcm_spi_writew(v,o) bcm_rset_writew(RSET_SPI, (v), bcm63xx_spireg(o))
962 +#define bcm_spi_writel(v,o) bcm_rset_writel(RSET_SPI, (v), bcm63xx_spireg(o))
964 +#endif /* BCM63XX_DEV_SPI_H */
965 --- a/arch/mips/bcm63xx/Makefile
966 +++ b/arch/mips/bcm63xx/Makefile
968 obj-y += clk.o cpu.o cs.o gpio.o irq.o prom.o setup.o timer.o \
969 dev-dsp.o dev-enet.o dev-pcmcia.o dev-uart.o dev-wdt.o \
970 - dev-usb-ohci.o dev-usb-ehci.o dev-usb-udc.o
971 + dev-usb-ohci.o dev-usb-ehci.o dev-usb-udc.o dev-spi.o
972 obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
975 --- a/arch/mips/bcm63xx/boards/board_bcm963xx.c
976 +++ b/arch/mips/bcm63xx/boards/board_bcm963xx.c
978 #include <bcm63xx_dev_usb_ohci.h>
979 #include <bcm63xx_dev_usb_ehci.h>
980 #include <bcm63xx_dev_usb_udc.h>
981 +#include <bcm63xx_dev_spi.h>
982 #include <board_bcm963xx.h>
984 #define PFX "board_bcm963xx: "
985 @@ -1596,6 +1597,9 @@ int __init board_register_devices(void)
987 spi_register_board_info(board.spis, board.num_spis);
989 + if (!BCMCPU_IS_6345())
990 + bcm63xx_spi_register();
992 /* read base address of boot chip select (0) */
993 if (BCMCPU_IS_6345())