1 --- a/arch/mips/bcm63xx/cpu.c
2 +++ b/arch/mips/bcm63xx/cpu.c
3 @@ -55,6 +55,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 @@ -127,6 +128,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 @@ -169,6 +171,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_DSL] = BCM_6358_DSL_IRQ,
26 [IRQ_ENET0] = BCM_6358_ENET0_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 +static struct resource spi_resources[] = {
48 + .start = -1, /* filled at runtime */
49 + .end = -1, /* filled at runtime */
50 + .flags = IORESOURCE_MEM,
53 + .start = -1, /* filled at runtime */
54 + .flags = IORESOURCE_IRQ,
58 +static struct bcm63xx_spi_pdata spi_pdata = {
60 + .num_chipselect = 4,
61 + .speed_hz = 50000000, /* Fclk */
64 +static struct platform_device bcm63xx_spi_device = {
65 + .name = "bcm63xx-spi",
67 + .num_resources = ARRAY_SIZE(spi_resources),
68 + .resource = spi_resources,
70 + .platform_data = &spi_pdata,
74 +int __init bcm63xx_spi_register(void)
76 + spi_resources[0].start = bcm63xx_regset_address(RSET_SPI);
77 + spi_resources[0].end = spi_resources[0].start;
78 + spi_resources[0].end += RSET_SPI_SIZE - 1;
79 + spi_resources[1].start = bcm63xx_get_irq_number(IRQ_SPI);
81 + /* Fill in platform data */
82 + if (BCMCPU_IS_6338() || BCMCPU_IS_6348())
83 + spi_pdata.fifo_size = SPI_BCM_6338_SPI_MSG_DATA_SIZE;
85 + if (BCMCPU_IS_6358())
86 + spi_pdata.fifo_size = SPI_BCM_6358_SPI_MSG_DATA_SIZE;
88 + return platform_device_register(&bcm63xx_spi_device);
90 --- a/arch/mips/include/asm/mach-bcm63xx/bcm63xx_cpu.h
91 +++ b/arch/mips/include/asm/mach-bcm63xx/bcm63xx_cpu.h
92 @@ -108,6 +108,7 @@ enum bcm63xx_regs_set {
93 #define RSET_WDT_SIZE 12
94 #define RSET_ENET_SIZE 2048
95 #define RSET_ENETDMA_SIZE 2048
96 +#define RSET_SPI_SIZE 256
97 #define RSET_UART_SIZE 24
98 #define RSET_UDC_SIZE 256
99 #define RSET_OHCI_SIZE 256
100 @@ -209,7 +210,7 @@ enum bcm63xx_regs_set {
101 #define BCM_6358_WDT_BASE (0xfffe005c)
102 #define BCM_6358_UART0_BASE (0xfffe0100)
103 #define BCM_6358_GPIO_BASE (0xfffe0080)
104 -#define BCM_6358_SPI_BASE (0xdeadbeef)
105 +#define BCM_6358_SPI_BASE (0xfffe0800)
106 #define BCM_6358_UDC0_BASE (0xfffe0400)
107 #define BCM_6358_OHCI0_BASE (0xfffe1400)
108 #define BCM_6358_OHCI_PRIV_BASE (0xdeadbeef)
109 @@ -428,6 +429,7 @@ static inline unsigned long bcm63xx_regs
117 @@ -493,6 +495,7 @@ enum bcm63xx_irq {
120 #define BCM_6348_TIMER_IRQ (IRQ_INTERNAL_BASE + 0)
121 +#define BCM_6348_SPI_IRQ (IRQ_INTERNAL_BASE + 1)
122 #define BCM_6348_UART0_IRQ (IRQ_INTERNAL_BASE + 2)
123 #define BCM_6348_DSL_IRQ (IRQ_INTERNAL_BASE + 4)
124 #define BCM_6348_UDC0_IRQ (IRQ_INTERNAL_BASE + 6)
125 @@ -517,6 +520,7 @@ enum bcm63xx_irq {
128 #define BCM_6358_TIMER_IRQ (IRQ_INTERNAL_BASE + 0)
129 +#define BCM_6358_SPI_IRQ (IRQ_INTERNAL_BASE + 1)
130 #define BCM_6358_UART0_IRQ (IRQ_INTERNAL_BASE + 2)
131 #define BCM_6358_OHCI0_IRQ (IRQ_INTERNAL_BASE + 5)
132 #define BCM_6358_ENET1_IRQ (IRQ_INTERNAL_BASE + 6)
133 --- a/arch/mips/include/asm/mach-bcm63xx/bcm63xx_regs.h
134 +++ b/arch/mips/include/asm/mach-bcm63xx/bcm63xx_regs.h
135 @@ -769,5 +769,117 @@
136 #define DMIPSPLLCFG_N2_SHIFT 29
137 #define DMIPSPLLCFG_N2_MASK (0x7 << DMIPSPLLCFG_N2_SHIFT)
139 +/*************************************************************************
140 + * _REG relative to RSET_SPI
141 + *************************************************************************/
143 +/* BCM 6338 SPI core */
144 +#define SPI_BCM_6338_SPI_CMD 0x00 /* 16-bits register */
145 +#define SPI_BCM_6338_SPI_INT_STATUS 0x02
146 +#define SPI_BCM_6338_SPI_MASK_INT_ST 0x03
147 +#define SPI_BCM_6338_SPI_INT_MASK 0x04
148 +#define SPI_BCM_6338_SPI_ST 0x05
149 +#define SPI_BCM_6338_SPI_CLK_CFG 0x06
150 +#define SPI_BCM_6338_SPI_FILL_BYTE 0x07
151 +#define SPI_BCM_6338_SPI_MSG_TAIL 0x09
152 +#define SPI_BCM_6338_SPI_RX_TAIL 0x0b
153 +#define SPI_BCM_6338_SPI_MSG_CTL 0x40
154 +#define SPI_BCM_6338_SPI_MSG_DATA 0x41
155 +#define SPI_BCM_6338_SPI_MSG_DATA_SIZE 0x3f
156 +#define SPI_BCM_6338_SPI_RX_DATA 0x80
157 +#define SPI_BCM_6338_SPI_RX_DATA_SIZE 0x3f
159 +/* BCM 6348 SPI core */
160 +#define SPI_BCM_6348_SPI_MASK_INT_ST 0x00
161 +#define SPI_BCM_6348_SPI_INT_STATUS 0x01
162 +#define SPI_BCM_6348_SPI_CMD 0x02 /* 16-bits register */
163 +#define SPI_BCM_6348_SPI_FILL_BYTE 0x04
164 +#define SPI_BCM_6348_SPI_CLK_CFG 0x05
165 +#define SPI_BCM_6348_SPI_ST 0x06
166 +#define SPI_BCM_6348_SPI_INT_MASK 0x07
167 +#define SPI_BCM_6348_SPI_RX_TAIL 0x08
168 +#define SPI_BCM_6348_SPI_MSG_TAIL 0x10
169 +#define SPI_BCM_6348_SPI_MSG_DATA 0x40
170 +#define SPI_BCM_6348_SPI_MSG_CTL 0x42
171 +#define SPI_BCM_6348_SPI_MSG_DATA_SIZE 0x3f
172 +#define SPI_BCM_6348_SPI_RX_DATA 0x80
173 +#define SPI_BCM_6348_SPI_RX_DATA_SIZE 0x3f
175 +/* BCM 6358 SPI core */
176 +#define SPI_BCM_6358_MSG_CTL 0x00 /* 16-bits register */
178 +#define SPI_BCM_6358_SPI_MSG_DATA 0x02
179 +#define SPI_BCM_6358_SPI_MSG_DATA_SIZE 0x21e
181 +#define SPI_BCM_6358_SPI_RX_DATA 0x400
182 +#define SPI_BCM_6358_SPI_RX_DATA_SIZE 0x220
184 +#define SPI_BCM_6358_SPI_CMD 0x700 /* 16-bits register */
186 +#define SPI_BCM_6358_SPI_INT_STATUS 0x702
187 +#define SPI_BCM_6358_SPI_MASK_INT_ST 0x703
189 +#define SPI_BCM_6358_SPI_INT_MASK 0x704
191 +#define SPI_BCM_6358_SPI_STATUS 0x705
193 +#define SPI_BCM_6358_SPI_CLK_CFG 0x706
195 +#define SPI_BCM_6358_SPI_FILL_BYTE 0x707
196 +#define SPI_BCM_6358_SPI_MSG_TAIL 0x709
197 +#define SPI_BCM_6358_SPI_RX_TAIL 0x70B
199 +/* Shared SPI definitions */
201 +/* Message configuration */
202 +#define SPI_FD_RW 0x00
203 +#define SPI_HD_W 0x01
204 +#define SPI_HD_R 0x02
205 +#define SPI_BYTE_CNT_SHIFT 0
206 +#define SPI_MSG_TYPE_SHIFT 14
209 +#define SPI_CMD_NOOP 0x01
210 +#define SPI_CMD_SOFT_RESET 0x02
211 +#define SPI_CMD_HARD_RESET 0x04
212 +#define SPI_CMD_START_IMMEDIATE 0x08
213 +#define SPI_CMD_COMMAND_SHIFT 0
214 +#define SPI_CMD_COMMAND_MASK 0x000f
215 +#define SPI_CMD_DEVICE_ID_SHIFT 4
216 +#define SPI_CMD_PREPEND_BYTE_CNT_SHIFT 8
217 +#define SPI_CMD_ONE_BYTE_SHIFT 11
218 +#define SPI_CMD_ONE_WIRE_SHIFT 12
219 +#define SPI_DEV_ID_0 0
220 +#define SPI_DEV_ID_1 1
221 +#define SPI_DEV_ID_2 2
222 +#define SPI_DEV_ID_3 3
224 +/* Interrupt mask */
225 +#define SPI_INTR_CMD_DONE 0x01
226 +#define SPI_INTR_RX_OVERFLOW 0x02
227 +#define SPI_INTR_TX_UNDERFLOW 0x04
228 +#define SPI_INTR_TX_OVERFLOW 0x08
229 +#define SPI_INTR_RX_UNDERFLOW 0x10
230 +#define SPI_INTR_CLEAR_ALL 0x1f
233 +#define SPI_RX_EMPTY 0x02
234 +#define SPI_CMD_BUSY 0x04
235 +#define SPI_SERIAL_BUSY 0x08
237 +/* Clock configuration */
238 +#define SPI_CLK_20MHZ 0x00
239 +#define SPI_CLK_0_391MHZ 0x01
240 +#define SPI_CLK_0_781MHZ 0x02 /* default */
241 +#define SPI_CLK_1_563MHZ 0x03
242 +#define SPI_CLK_3_125MHZ 0x04
243 +#define SPI_CLK_6_250MHZ 0x05
244 +#define SPI_CLK_12_50MHZ 0x06
245 +#define SPI_CLK_25MHZ 0x07
246 +#define SPI_CLK_MASK 0x07
247 +#define SPI_SSOFFTIME_MASK 0x38
248 +#define SPI_SSOFFTIME_SHIFT 3
249 +#define SPI_BYTE_SWAP 0x80
251 #endif /* BCM63XX_REGS_H_ */
254 +++ b/drivers/spi/bcm63xx_spi.c
257 + * Broadcom BCM63xx SPI controller support
259 + * Copyright (C) 2009 Florian Fainelli <florian@openwrt.org>
261 + * This program is free software; you can redistribute it and/or
262 + * modify it under the terms of the GNU General Public License
263 + * as published by the Free Software Foundation; either version 2
264 + * of the License, or (at your option) any later version.
266 + * This program is distributed in the hope that it will be useful,
267 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
268 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
269 + * GNU General Public License for more details.
271 + * You should have received a copy of the GNU General Public License
272 + * along with this program; if not, write to the
273 + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
276 +#include <linux/kernel.h>
277 +#include <linux/init.h>
278 +#include <linux/clk.h>
279 +#include <linux/module.h>
280 +#include <linux/platform_device.h>
281 +#include <linux/delay.h>
282 +#include <linux/interrupt.h>
283 +#include <linux/spi/spi.h>
284 +#include <linux/spi/spi_bitbang.h>
285 +#include <linux/gpio.h>
286 +#include <linux/completion.h>
287 +#include <linux/err.h>
289 +#include <bcm63xx_io.h>
290 +#include <bcm63xx_regs.h>
291 +#include <bcm63xx_dev_spi.h>
293 +#define PFX KBUILD_MODNAME
294 +#define DRV_VER "0.1.2"
296 +enum bcm63xx_regs_spi {
314 +static const unsigned long bcm96338_regs_spi[] = {
315 + [SPI_CMD] = SPI_BCM_6338_SPI_CMD,
316 + [SPI_INT_STATUS] = SPI_BCM_6338_SPI_INT_STATUS,
317 + [SPI_INT_MASK_ST] = SPI_BCM_6338_SPI_MASK_INT_ST,
318 + [SPI_INT_MASK] = SPI_BCM_6338_SPI_INT_MASK,
319 + [SPI_ST] = SPI_BCM_6338_SPI_ST,
320 + [SPI_CLK_CFG] = SPI_BCM_6338_SPI_CLK_CFG,
321 + [SPI_FILL_BYTE] = SPI_BCM_6338_SPI_FILL_BYTE,
322 + [SPI_MSG_TAIL] = SPI_BCM_6338_SPI_MSG_TAIL,
323 + [SPI_RX_TAIL] = SPI_BCM_6338_SPI_RX_TAIL,
324 + [SPI_MSG_CTL] = SPI_BCM_6338_SPI_MSG_CTL,
325 + [SPI_MSG_DATA] = SPI_BCM_6338_SPI_MSG_DATA,
326 + [SPI_RX_DATA] = SPI_BCM_6338_SPI_RX_DATA,
329 +static const unsigned long bcm96348_regs_spi[] = {
330 + [SPI_CMD] = SPI_BCM_6348_SPI_CMD,
331 + [SPI_INT_STATUS] = SPI_BCM_6348_SPI_INT_STATUS,
332 + [SPI_INT_MASK_ST] = SPI_BCM_6348_SPI_MASK_INT_ST,
333 + [SPI_INT_MASK] = SPI_BCM_6348_SPI_INT_MASK,
334 + [SPI_ST] = SPI_BCM_6348_SPI_ST,
335 + [SPI_CLK_CFG] = SPI_BCM_6348_SPI_CLK_CFG,
336 + [SPI_FILL_BYTE] = SPI_BCM_6348_SPI_FILL_BYTE,
337 + [SPI_MSG_TAIL] = SPI_BCM_6348_SPI_MSG_TAIL,
338 + [SPI_RX_TAIL] = SPI_BCM_6348_SPI_RX_TAIL,
339 + [SPI_MSG_CTL] = SPI_BCM_6348_SPI_MSG_CTL,
340 + [SPI_MSG_DATA] = SPI_BCM_6348_SPI_MSG_DATA,
341 + [SPI_RX_DATA] = SPI_BCM_6348_SPI_RX_DATA,
344 +static const unsigned long bcm96358_regs_spi[] = {
345 + [SPI_CMD] = SPI_BCM_6358_SPI_CMD,
346 + [SPI_INT_STATUS] = SPI_BCM_6358_SPI_INT_STATUS,
347 + [SPI_INT_MASK_ST] = SPI_BCM_6358_SPI_MASK_INT_ST,
348 + [SPI_INT_MASK] = SPI_BCM_6358_SPI_INT_MASK,
349 + [SPI_ST] = SPI_BCM_6358_SPI_STATUS,
350 + [SPI_CLK_CFG] = SPI_BCM_6358_SPI_CLK_CFG,
351 + [SPI_FILL_BYTE] = SPI_BCM_6358_SPI_FILL_BYTE,
352 + [SPI_MSG_TAIL] = SPI_BCM_6358_SPI_MSG_TAIL,
353 + [SPI_RX_TAIL] = SPI_BCM_6358_SPI_RX_TAIL,
354 + [SPI_MSG_CTL] = SPI_BCM_6358_MSG_CTL,
355 + [SPI_MSG_DATA] = SPI_BCM_6358_SPI_MSG_DATA,
356 + [SPI_RX_DATA] = SPI_BCM_6358_SPI_RX_DATA,
360 +#ifdef BCMCPU_RUNTIME_DETECT
361 +static const unsigned long *bcm63xx_regs_spi;
363 +static __init void bcm63xx_spi_regs_init(void)
365 + if (BCMCPU_IS_6338())
366 + bcm63xx_regs_spi = bcm96338_regs_spi;
367 + if (BCMCPU_IS_6348())
368 + bcm63xx_regs_spi = bcm96348_regs_spi;
369 + if (BCMCPU_IS_6358())
370 + bcm63xx_regs_spi = bcm96358_regs_spi;
373 +static __init void bcm63xx_spi_regs_init(void) { }
376 +static inline unsigned long bcm63xx_spireg(enum bcm63xx_regs_spi reg)
378 +#ifdef BCMCPU_RUNTIME_DETECT
379 + return bcm63xx_regs_spi[reg];
381 +#ifdef CONFIG_BCM63XX_CPU_6338
384 + return SPI_BCM_6338_SPI_CMD;
385 + case SPI_INT_STATUS:
386 + return SPI_BCM_6338_SPI_INT_STATUS;
387 + case SPI_INT_MASK_ST:
388 + return SPI_BCM_6338_SPI_MASK_INT_ST;
390 + return SPI_BCM_6338_SPI_INT_MASK;
392 + return SPI_BCM_6338_SPI_ST;
394 + return SPI_BCM_6338_SPI_CLK_CFG;
395 + case SPI_FILL_BYTE:
396 + return SPI_BCM_6338_SPI_FILL_BYTE;
398 + return SPI_BCM_6338_SPI_MSG_TAIL;
400 + return SPI_BCM_6338_SPI_RX_TAIL;
402 + return SPI_BCM_6338_SPI_MSG_CTL;
404 + return SPI_BCM_6338_SPI_MSG_DATA;
406 + return SPI_BCM_6338_SPI_RX_DATA;
409 +#ifdef CONFIG_BCM63XX_CPU_6348
412 + return SPI_BCM_6348_SPI_CMD;
413 + case SPI_INT_MASK_ST:
414 + return SPI_BCM_6348_SPI_MASK_INT_ST;
416 + return SPI_BCM_6348_SPI_INT_MASK;
417 + case SPI_INT_STATUS:
418 + return SPI_BCM_6348_SPI_INT_STATUS;
420 + return SPI_BCM_6348_SPI_ST;
422 + return SPI_BCM_6348_SPI_CLK_CFG;
423 + case SPI_FILL_BYTE:
424 + return SPI_BCM_6348_SPI_FILL_BYTE;
426 + return SPI_BCM_6348_SPI_MSG_TAIL;
428 + return SPI_BCM_6348_SPI_RX_TAIL;
430 + return SPI_BCM_6348_SPI_MSG_CTL;
432 + return SPI_BCM_6348_SPI_MSG_DATA;
434 + return SPI_BCM_6348_SPI_RX_DATA;
437 +#ifdef CONFIG_BCM63XX_CPU_6358
440 + return SPI_BCM_6358_SPI_CMD;
441 + case SPI_INT_STATUS:
442 + return SPI_BCM_6358_SPI_INT_STATUS;
443 + case SPI_INT_MASK_ST:
444 + return SPI_BCM_6358_SPI_MASK_INT_ST;
446 + return SPI_BCM_6358_SPI_INT_MASK;
448 + return SPI_BCM_6358_SPI_STATUS;
450 + return SPI_BCM_6358_SPI_CLK_CFG;
451 + case SPI_FILL_BYTE:
452 + return SPI_BCM_6358_SPI_FILL_BYTE;
454 + return SPI_BCM_6358_SPI_MSG_TAIL;
456 + return SPI_BCM_6358_SPI_RX_TAIL;
458 + return SPI_BCM_6358_MSG_CTL;
460 + return SPI_BCM_6358_SPI_MSG_DATA;
462 + return SPI_BCM_6358_SPI_RX_DATA;
470 + * helpers for the SPI register sets
472 +#define bcm_spi_readb(b,o) bcm_readb((b) + bcm63xx_spireg(o))
473 +#define bcm_spi_readw(b,o) bcm_readw((b) + bcm63xx_spireg(o))
474 +#define bcm_spi_writeb(v,b,o) bcm_writeb((v), (b) + bcm63xx_spireg(o))
475 +#define bcm_spi_writew(v,b,o) bcm_writew((v), (b) + bcm63xx_spireg(o))
477 +struct bcm63xx_spi {
478 + /* bitbang has to be first */
479 + struct spi_bitbang bitbang;
480 + struct completion done;
482 + void __iomem *regs;
485 + /* Platform data */
487 + unsigned fifo_size;
490 + const unsigned char *tx_ptr;
491 + unsigned char *rx_ptr;
492 + int remaining_bytes;
495 + struct resource *ioarea;
496 + struct platform_device *pdev;
499 +static void bcm63xx_spi_chipselect(struct spi_device *spi, int is_on)
501 + struct bcm63xx_spi *bs = spi_master_get_devdata(spi->master);
504 + val = bcm_spi_readw(bs->regs, SPI_CMD);
505 + if (is_on == BITBANG_CS_INACTIVE)
506 + val |= SPI_CMD_NOOP;
507 + else if (is_on == BITBANG_CS_ACTIVE)
508 + val |= (spi->chip_select << SPI_CMD_DEVICE_ID_SHIFT);
510 + bcm_spi_writew(val, bs->regs, SPI_CMD);
513 +static int bcm63xx_spi_setup_transfer(struct spi_device *spi,
514 + struct spi_transfer *t)
521 + struct bcm63xx_spi *bs = spi_master_get_devdata(spi->master);
523 + bits_per_word = (t) ? t->bits_per_word : spi->bits_per_word;
524 + hz = (t) ? t->speed_hz : spi->max_speed_hz;
525 + if (bits_per_word != 8) {
526 + dev_err(&spi->dev, "%s, unsupported bits_per_word=%d\n",
527 + __func__, bits_per_word);
531 + if (spi->chip_select > spi->master->num_chipselect) {
532 + dev_err(&spi->dev, "%s, unsupported slave %d\n",
533 + __func__, spi->chip_select);
537 + /* Check clock setting */
538 + div = (bs->speed_hz / hz);
541 + clk_cfg = SPI_CLK_25MHZ;
544 + clk_cfg = SPI_CLK_12_50MHZ;
547 + clk_cfg = SPI_CLK_6_250MHZ;
550 + clk_cfg = SPI_CLK_3_125MHZ;
553 + clk_cfg = SPI_CLK_1_563MHZ;
556 + clk_cfg = SPI_CLK_0_781MHZ;
560 + /* Set to slowest mode for compatibility */
561 + clk_cfg = SPI_CLK_0_781MHZ;
565 + bcm_spi_writeb(clk_cfg, bs->regs, SPI_CLK_CFG);
566 + dev_dbg(&spi->dev, "Setting clock register to %d (hz %d, cmd %02x)\n",
572 +/* the spi->mode bits understood by this driver: */
573 +#define MODEBITS (SPI_CPOL | SPI_CPHA)
575 +static int bcm63xx_spi_setup(struct spi_device *spi)
577 + struct spi_bitbang *bitbang;
578 + struct bcm63xx_spi *bs;
581 + bs = spi_master_get_devdata(spi->master);
582 + bitbang = &bs->bitbang;
584 + if (!spi->bits_per_word)
585 + spi->bits_per_word = 8;
587 + if (spi->mode & ~MODEBITS) {
588 + dev_err(&spi->dev, "%s, unsupported mode bits %x\n",
589 + __func__, spi->mode & ~MODEBITS);
593 + retval = bcm63xx_spi_setup_transfer(spi, NULL);
595 + dev_err(&spi->dev, "setup: unsupported mode bits %x\n",
596 + spi->mode & ~MODEBITS);
600 + dev_dbg(&spi->dev, "%s, mode %d, %u bits/w, %u nsec/bit\n",
601 + __func__, spi->mode & MODEBITS, spi->bits_per_word, 0);
606 +/* Fill the TX FIFO with as many bytes as possible */
607 +static void bcm63xx_spi_fill_tx_fifo(struct bcm63xx_spi *bs)
611 + /* Fill the Tx FIFO with as many bytes as possible */
612 + tail = bcm_spi_readb(bs->regs, SPI_MSG_TAIL);
613 + while ((tail < bs->fifo_size) && (bs->remaining_bytes > 0)) {
615 + bcm_spi_writeb(*bs->tx_ptr++, bs->regs, SPI_MSG_DATA);
617 + bcm_spi_writeb(0, bs->regs, SPI_MSG_DATA);
618 + bs->remaining_bytes--;
619 + tail = bcm_spi_readb(bs->regs, SPI_MSG_TAIL);
623 +static int bcm63xx_txrx_bufs(struct spi_device *spi, struct spi_transfer *t)
625 + struct bcm63xx_spi *bs = spi_master_get_devdata(spi->master);
629 + dev_dbg(&spi->dev, "txrx: tx %p, rx %p, len %d\n",
630 + t->tx_buf, t->rx_buf, t->len);
632 + /* Transmitter is inhibited */
633 + bs->tx_ptr = t->tx_buf;
634 + bs->rx_ptr = t->rx_buf;
635 + bs->remaining_bytes = t->len;
636 + init_completion(&bs->done);
638 + bcm63xx_spi_fill_tx_fifo(bs);
640 + /* Enable the command done interrupt which
641 + * we use to determine completion of a command */
642 + bcm_spi_writeb(SPI_INTR_CMD_DONE, bs->regs, SPI_INT_MASK);
644 + /* Fill in the Message control register */
645 + msg_ctl = bcm_spi_readb(bs->regs, SPI_MSG_CTL);
646 + msg_ctl |= (t->len << SPI_BYTE_CNT_SHIFT);
647 + msg_ctl |= (SPI_FD_RW << SPI_MSG_TYPE_SHIFT);
648 + bcm_spi_writeb(msg_ctl, bs->regs, SPI_MSG_CTL);
650 + /* Issue the transfer */
651 + cmd = bcm_spi_readw(bs->regs, SPI_CMD);
652 + cmd |= SPI_CMD_START_IMMEDIATE;
653 + cmd |= (0 << SPI_CMD_PREPEND_BYTE_CNT_SHIFT);
654 + bcm_spi_writew(cmd, bs->regs, SPI_CMD);
656 + wait_for_completion(&bs->done);
658 + /* Disable the CMD_DONE interrupt */
659 + bcm_spi_writeb(~(SPI_INTR_CMD_DONE), bs->regs, SPI_INT_MASK);
661 + return t->len - bs->remaining_bytes;
664 +/* This driver supports single master mode only. Hence
665 + * CMD_DONE is the only interrupt we care about
667 +static irqreturn_t bcm63xx_spi_interrupt(int irq, void *dev_id)
669 + struct spi_master *master = (struct spi_master *)dev_id;
670 + struct bcm63xx_spi *bs = spi_master_get_devdata(master);
674 + /* Read interupts and clear them immediately */
675 + intr = bcm_spi_readb(bs->regs, SPI_INT_STATUS);
676 + bcm_spi_writeb(SPI_INTR_CLEAR_ALL, bs->regs, SPI_INT_MASK);
678 + /* A tansfer completed */
679 + if (intr & SPI_INTR_CMD_DONE) {
682 + rx_empty = bcm_spi_readb(bs->regs, SPI_ST);
683 + /* Read out all the data */
684 + while ((rx_empty & SPI_RX_EMPTY) == 0) {
687 + data = bcm_spi_readb(bs->regs, SPI_RX_DATA);
689 + *bs->rx_ptr++ = data;
691 + rx_empty = bcm_spi_readb(bs->regs, SPI_RX_EMPTY);
694 + /* See if there is more data to send */
695 + if (bs->remaining_bytes > 0) {
696 + bcm63xx_spi_fill_tx_fifo(bs);
698 + /* Start the transfer */
699 + cmd = bcm_spi_readw(bs->regs, SPI_CMD);
700 + cmd |= SPI_CMD_START_IMMEDIATE;
701 + cmd |= (0 << SPI_CMD_PREPEND_BYTE_CNT_SHIFT);
702 + bcm_spi_writew(cmd, bs->regs, SPI_CMD);
704 + complete(&bs->done);
707 + return IRQ_HANDLED;
711 +static int __init bcm63xx_spi_probe(struct platform_device *pdev)
713 + struct resource *r;
714 + struct bcm63xx_spi_pdata *pdata = pdev->dev.platform_data;
716 + struct spi_master *master;
718 + struct bcm63xx_spi *bs;
721 + r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
727 + irq = platform_get_irq(pdev, 0);
733 + bcm63xx_spi_regs_init();
735 + clk = clk_get(&pdev->dev, "spi");
737 + dev_err(&pdev->dev, "No clock for device\n");
742 + master = spi_alloc_master(&pdev->dev, sizeof(struct bcm63xx_spi));
748 + bs = spi_master_get_devdata(master);
749 + bs->bitbang.master = spi_master_get(master);
750 + bs->bitbang.chipselect = bcm63xx_spi_chipselect;
751 + bs->bitbang.setup_transfer = bcm63xx_spi_setup_transfer;
752 + bs->bitbang.txrx_bufs = bcm63xx_txrx_bufs;
753 + bs->bitbang.master->setup = bcm63xx_spi_setup;
754 + init_completion(&bs->done);
756 + platform_set_drvdata(pdev, master);
759 + if (!request_mem_region(r->start,
760 + r->end - r->start, PFX)) {
765 + bs->regs = ioremap_nocache(r->start, r->end - r->start);
767 + printk(KERN_ERR PFX " unable to ioremap regs\n");
773 + bs->fifo_size = pdata->fifo_size;
775 + ret = request_irq(irq, bcm63xx_spi_interrupt, 0,
776 + pdev->name, master);
778 + printk(KERN_ERR PFX " unable to request irq\n");
782 + master->bus_num = pdata->bus_num;
783 + master->num_chipselect = pdata->num_chipselect;
784 + bs->speed_hz = pdata->speed_hz;
786 + /* Initialize hardware */
787 + clk_enable(bs->clk);
788 + bcm_spi_writeb(SPI_INTR_CLEAR_ALL, bs->regs, SPI_INT_MASK);
790 + dev_info(&pdev->dev, " at 0x%08x (irq %d, FIFOs size %d) v%s\n",
791 + r->start, irq, bs->fifo_size, DRV_VER);
793 + ret = spi_bitbang_start(&bs->bitbang);
795 + dev_err(&pdev->dev, "spi_bitbang_start FAILED\n");
803 + free_irq(irq, master);
808 + spi_master_put(master);
813 +static int __exit bcm63xx_spi_remove(struct platform_device *pdev)
815 + struct spi_master *master = platform_get_drvdata(pdev);
816 + struct bcm63xx_spi *bs = spi_master_get_devdata(master);
818 + spi_bitbang_stop(&bs->bitbang);
819 + clk_disable(bs->clk);
821 + free_irq(bs->irq, master);
823 + platform_set_drvdata(pdev, 0);
824 + spi_master_put(bs->bitbang.master);
830 +static int bcm63xx_spi_suspend(struct platform_device *pdev, pm_message_t mesg)
832 + struct spi_master *master = platform_get_drvdata(pdev);
833 + struct bcm63xx_spi *bs = spi_master_get_devdata(master);
835 + clk_disable(bs->clk);
840 +static int bcm63xx_spi_resume(struct platform_device *pdev)
842 + struct bcm63xx_spi *bs = spi_master_get_devdata(master);
843 + struct bcm63xx_spi *bs = spi_master_get_devdata(master);
845 + clk_enable(bs->clk);
850 +#define bcm63xx_spi_suspend NULL
851 +#define bcm63xx_spi_resume NULL
854 +static struct platform_driver bcm63xx_spi_driver = {
856 + .name = "bcm63xx-spi",
857 + .owner = THIS_MODULE,
859 + .probe = bcm63xx_spi_probe,
860 + .remove = bcm63xx_spi_remove,
861 + .suspend = bcm63xx_spi_suspend,
862 + .resume = bcm63xx_spi_resume,
866 +static int __init bcm63xx_spi_init(void)
868 + return platform_driver_register(&bcm63xx_spi_driver);
871 +static void __exit bcm63xx_spi_exit(void)
873 + platform_driver_unregister(&bcm63xx_spi_driver);
876 +module_init(bcm63xx_spi_init);
877 +module_exit(bcm63xx_spi_exit);
879 +MODULE_ALIAS("platform:bcm63xx_spi");
880 +MODULE_AUTHOR("Florian Fainelli <florian@openwrt.org>");
881 +MODULE_DESCRIPTION("Broadcom BCM63xx SPI Controller driver");
882 +MODULE_LICENSE("GPL");
883 +MODULE_VERSION(DRV_VER);
884 --- a/drivers/spi/Kconfig
885 +++ b/drivers/spi/Kconfig
886 @@ -60,6 +60,13 @@ config SPI_ATMEL
887 This selects a driver for the Atmel SPI Controller, present on
888 many AT32 (AVR32) and AT91 (ARM) chips.
891 + tristate "Broadcom BCM63xx SPI controller"
895 + This is the SPI controller master driver for Broadcom BCM63xx SoC.
898 tristate "SPI controller driver for ADI Blackfin5xx"
900 --- a/drivers/spi/Makefile
901 +++ b/drivers/spi/Makefile
902 @@ -43,6 +43,7 @@ obj-$(CONFIG_SPI_SH_SCI) += spi_sh_sci.
903 obj-$(CONFIG_SPI_SH_MSIOF) += spi_sh_msiof.o
904 obj-$(CONFIG_SPI_STMP3XXX) += spi_stmp.o
905 obj-$(CONFIG_SPI_NUC900) += spi_nuc900.o
906 +obj-$(CONFIG_SPI_BCM63XX) += bcm63xx_spi.o
908 # special build for s3c24xx spi driver with fiq support
909 spi_s3c24xx_hw-y := spi_s3c24xx.o
911 +++ b/arch/mips/include/asm/mach-bcm63xx/bcm63xx_dev_spi.h
913 +#ifndef BCM63XX_DEV_SPI_H
914 +#define BCM63XX_DEV_SPI_H
916 +#include <linux/types.h>
918 +int __init bcm63xx_spi_register(void);
920 +struct bcm63xx_spi_pdata {
921 + unsigned int fifo_size;
923 + int num_chipselect;
927 +#endif /* BCM63XX_DEV_SPI_H */
928 --- a/arch/mips/bcm63xx/Makefile
929 +++ b/arch/mips/bcm63xx/Makefile
931 obj-y += clk.o cpu.o cs.o gpio.o irq.o prom.o setup.o timer.o \
932 dev-dsp.o dev-enet.o dev-pcmcia.o dev-uart.o dev-wdt.o \
933 - dev-usb-ohci.o dev-usb-ehci.o dev-usb-udc.o
934 + dev-usb-ohci.o dev-usb-ehci.o dev-usb-udc.o dev-spi.o
935 obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
938 --- a/arch/mips/bcm63xx/boards/board_bcm963xx.c
939 +++ b/arch/mips/bcm63xx/boards/board_bcm963xx.c
941 #include <bcm63xx_dev_usb_ohci.h>
942 #include <bcm63xx_dev_usb_ehci.h>
943 #include <bcm63xx_dev_usb_udc.h>
944 +#include <bcm63xx_dev_spi.h>
945 #include <board_bcm963xx.h>
947 #define PFX "board_bcm963xx: "
948 @@ -998,6 +999,9 @@ int __init board_register_devices(void)
950 bcm63xx_udc_register();
952 + if (!BCMCPU_IS_6345())
953 + bcm63xx_spi_register();
955 /* Generate MAC address for WLAN and
956 * register our SPROM */
957 #ifdef CONFIG_SSB_PCIHOST