1 Index: linux-2.6.32.13/arch/mips/bcm63xx/cpu.c
2 ===================================================================
3 --- linux-2.6.32.13.orig/arch/mips/bcm63xx/cpu.c 2010-05-27 21:34:54.000000000 -0400
4 +++ linux-2.6.32.13/arch/mips/bcm63xx/cpu.c 2010-05-27 21:48:23.000000000 -0400
7 static const int bcm96338_irqs[] = {
8 [IRQ_TIMER] = BCM_6338_TIMER_IRQ,
9 + [IRQ_SPI] = BCM_6338_SPI_IRQ,
10 [IRQ_UART0] = BCM_6338_UART0_IRQ,
11 [IRQ_DSL] = BCM_6338_DSL_IRQ,
12 [IRQ_ENET0] = BCM_6338_ENET0_IRQ,
15 static const int bcm96348_irqs[] = {
16 [IRQ_TIMER] = BCM_6348_TIMER_IRQ,
17 + [IRQ_SPI] = BCM_6348_SPI_IRQ,
18 [IRQ_UART0] = BCM_6348_UART0_IRQ,
19 [IRQ_DSL] = BCM_6348_DSL_IRQ,
20 [IRQ_ENET0] = BCM_6348_ENET0_IRQ,
23 static const int bcm96358_irqs[] = {
24 [IRQ_TIMER] = BCM_6358_TIMER_IRQ,
25 + [IRQ_SPI] = BCM_6358_SPI_IRQ,
26 [IRQ_UART0] = BCM_6358_UART0_IRQ,
27 [IRQ_DSL] = BCM_6358_DSL_IRQ,
28 [IRQ_ENET0] = BCM_6358_ENET0_IRQ,
29 Index: linux-2.6.32.13/arch/mips/bcm63xx/dev-spi.c
30 ===================================================================
31 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
32 +++ linux-2.6.32.13/arch/mips/bcm63xx/dev-spi.c 2010-05-27 21:48:23.000000000 -0400
35 + * This file is subject to the terms and conditions of the GNU General Public
36 + * License. See the file "COPYING" in the main directory of this archive
39 + * Copyright (C) 2009 Florian Fainelli <florian@openwrt.org>
42 +#include <linux/init.h>
43 +#include <linux/kernel.h>
44 +#include <linux/platform_device.h>
46 +#include <bcm63xx_cpu.h>
47 +#include <bcm63xx_dev_spi.h>
48 +#include <bcm63xx_regs.h>
50 +static struct resource spi_resources[] = {
52 + .start = -1, /* filled at runtime */
53 + .end = -1, /* filled at runtime */
54 + .flags = IORESOURCE_MEM,
57 + .start = -1, /* filled at runtime */
58 + .flags = IORESOURCE_IRQ,
62 +static struct bcm63xx_spi_pdata spi_pdata = {
64 + .num_chipselect = 4,
65 + .speed_hz = 50000000, /* Fclk */
68 +static struct platform_device bcm63xx_spi_device = {
69 + .name = "bcm63xx-spi",
71 + .num_resources = ARRAY_SIZE(spi_resources),
72 + .resource = spi_resources,
74 + .platform_data = &spi_pdata,
78 +int __init bcm63xx_spi_register(void)
80 + spi_resources[0].start = bcm63xx_regset_address(RSET_SPI);
81 + spi_resources[0].end = spi_resources[0].start;
82 + spi_resources[0].end += RSET_SPI_SIZE - 1;
83 + spi_resources[1].start = bcm63xx_get_irq_number(IRQ_SPI);
85 + /* Fill in platform data */
86 + if (BCMCPU_IS_6338() || BCMCPU_IS_6348())
87 + spi_pdata.fifo_size = SPI_BCM_6338_SPI_MSG_DATA_SIZE;
89 + if (BCMCPU_IS_6358())
90 + spi_pdata.fifo_size = SPI_BCM_6358_SPI_MSG_DATA_SIZE;
92 + return platform_device_register(&bcm63xx_spi_device);
94 Index: linux-2.6.32.13/arch/mips/include/asm/mach-bcm63xx/bcm63xx_cpu.h
95 ===================================================================
96 --- linux-2.6.32.13.orig/arch/mips/include/asm/mach-bcm63xx/bcm63xx_cpu.h 2010-05-27 21:44:19.000000000 -0400
97 +++ linux-2.6.32.13/arch/mips/include/asm/mach-bcm63xx/bcm63xx_cpu.h 2010-05-27 21:48:23.000000000 -0400
99 #define RSET_WDT_SIZE 12
100 #define RSET_ENET_SIZE 2048
101 #define RSET_ENETDMA_SIZE 2048
102 +#define RSET_SPI_SIZE 256
103 #define RSET_UART_SIZE 24
104 #define RSET_UDC_SIZE 256
105 #define RSET_OHCI_SIZE 256
107 #define BCM_6358_WDT_BASE (0xfffe005c)
108 #define BCM_6358_UART0_BASE (0xfffe0100)
109 #define BCM_6358_GPIO_BASE (0xfffe0080)
110 -#define BCM_6358_SPI_BASE (0xdeadbeef)
111 +#define BCM_6358_SPI_BASE (0xfffe0800)
112 #define BCM_6358_UDC0_BASE (0xfffe0400)
113 #define BCM_6358_OHCI0_BASE (0xfffe1400)
114 #define BCM_6358_OHCI_PRIV_BASE (0xdeadbeef)
126 #define BCM_6348_TIMER_IRQ (IRQ_INTERNAL_BASE + 0)
127 +#define BCM_6348_SPI_IRQ (IRQ_INTERNAL_BASE + 1)
128 #define BCM_6348_UART0_IRQ (IRQ_INTERNAL_BASE + 2)
129 #define BCM_6348_DSL_IRQ (IRQ_INTERNAL_BASE + 4)
130 #define BCM_6348_UDC0_IRQ (IRQ_INTERNAL_BASE + 6)
134 #define BCM_6358_TIMER_IRQ (IRQ_INTERNAL_BASE + 0)
135 +#define BCM_6358_SPI_IRQ (IRQ_INTERNAL_BASE + 1)
136 #define BCM_6358_UART0_IRQ (IRQ_INTERNAL_BASE + 2)
137 #define BCM_6358_OHCI0_IRQ (IRQ_INTERNAL_BASE + 5)
138 #define BCM_6358_ENET1_IRQ (IRQ_INTERNAL_BASE + 6)
139 Index: linux-2.6.32.13/arch/mips/include/asm/mach-bcm63xx/bcm63xx_regs.h
140 ===================================================================
141 --- linux-2.6.32.13.orig/arch/mips/include/asm/mach-bcm63xx/bcm63xx_regs.h 2010-05-27 21:34:54.000000000 -0400
142 +++ linux-2.6.32.13/arch/mips/include/asm/mach-bcm63xx/bcm63xx_regs.h 2010-05-27 21:48:23.000000000 -0400
143 @@ -769,5 +769,117 @@
144 #define DMIPSPLLCFG_N2_SHIFT 29
145 #define DMIPSPLLCFG_N2_MASK (0x7 << DMIPSPLLCFG_N2_SHIFT)
147 +/*************************************************************************
148 + * _REG relative to RSET_SPI
149 + *************************************************************************/
151 +/* BCM 6338 SPI core */
152 +#define SPI_BCM_6338_SPI_CMD 0x00 /* 16-bits register */
153 +#define SPI_BCM_6338_SPI_INT_STATUS 0x02
154 +#define SPI_BCM_6338_SPI_MASK_INT_ST 0x03
155 +#define SPI_BCM_6338_SPI_INT_MASK 0x04
156 +#define SPI_BCM_6338_SPI_ST 0x05
157 +#define SPI_BCM_6338_SPI_CLK_CFG 0x06
158 +#define SPI_BCM_6338_SPI_FILL_BYTE 0x07
159 +#define SPI_BCM_6338_SPI_MSG_TAIL 0x09
160 +#define SPI_BCM_6338_SPI_RX_TAIL 0x0b
161 +#define SPI_BCM_6338_SPI_MSG_CTL 0x40
162 +#define SPI_BCM_6338_SPI_MSG_DATA 0x41
163 +#define SPI_BCM_6338_SPI_MSG_DATA_SIZE 0x3f
164 +#define SPI_BCM_6338_SPI_RX_DATA 0x80
165 +#define SPI_BCM_6338_SPI_RX_DATA_SIZE 0x3f
167 +/* BCM 6348 SPI core */
168 +#define SPI_BCM_6348_SPI_MASK_INT_ST 0x00
169 +#define SPI_BCM_6348_SPI_INT_STATUS 0x01
170 +#define SPI_BCM_6348_SPI_CMD 0x02 /* 16-bits register */
171 +#define SPI_BCM_6348_SPI_FILL_BYTE 0x04
172 +#define SPI_BCM_6348_SPI_CLK_CFG 0x05
173 +#define SPI_BCM_6348_SPI_ST 0x06
174 +#define SPI_BCM_6348_SPI_INT_MASK 0x07
175 +#define SPI_BCM_6348_SPI_RX_TAIL 0x08
176 +#define SPI_BCM_6348_SPI_MSG_TAIL 0x10
177 +#define SPI_BCM_6348_SPI_MSG_DATA 0x40
178 +#define SPI_BCM_6348_SPI_MSG_CTL 0x42
179 +#define SPI_BCM_6348_SPI_MSG_DATA_SIZE 0x3f
180 +#define SPI_BCM_6348_SPI_RX_DATA 0x80
181 +#define SPI_BCM_6348_SPI_RX_DATA_SIZE 0x3f
183 +/* BCM 6358 SPI core */
184 +#define SPI_BCM_6358_MSG_CTL 0x00 /* 16-bits register */
186 +#define SPI_BCM_6358_SPI_MSG_DATA 0x02
187 +#define SPI_BCM_6358_SPI_MSG_DATA_SIZE 0x21e
189 +#define SPI_BCM_6358_SPI_RX_DATA 0x400
190 +#define SPI_BCM_6358_SPI_RX_DATA_SIZE 0x220
192 +#define SPI_BCM_6358_SPI_CMD 0x700 /* 16-bits register */
194 +#define SPI_BCM_6358_SPI_INT_STATUS 0x702
195 +#define SPI_BCM_6358_SPI_MASK_INT_ST 0x703
197 +#define SPI_BCM_6358_SPI_INT_MASK 0x704
199 +#define SPI_BCM_6358_SPI_STATUS 0x705
201 +#define SPI_BCM_6358_SPI_CLK_CFG 0x706
203 +#define SPI_BCM_6358_SPI_FILL_BYTE 0x707
204 +#define SPI_BCM_6358_SPI_MSG_TAIL 0x709
205 +#define SPI_BCM_6358_SPI_RX_TAIL 0x70B
207 +/* Shared SPI definitions */
209 +/* Message configuration */
210 +#define SPI_FD_RW 0x00
211 +#define SPI_HD_W 0x01
212 +#define SPI_HD_R 0x02
213 +#define SPI_BYTE_CNT_SHIFT 0
214 +#define SPI_MSG_TYPE_SHIFT 14
217 +#define SPI_CMD_NOOP 0x01
218 +#define SPI_CMD_SOFT_RESET 0x02
219 +#define SPI_CMD_HARD_RESET 0x04
220 +#define SPI_CMD_START_IMMEDIATE 0x08
221 +#define SPI_CMD_COMMAND_SHIFT 0
222 +#define SPI_CMD_COMMAND_MASK 0x000f
223 +#define SPI_CMD_DEVICE_ID_SHIFT 4
224 +#define SPI_CMD_PREPEND_BYTE_CNT_SHIFT 8
225 +#define SPI_CMD_ONE_BYTE_SHIFT 11
226 +#define SPI_CMD_ONE_WIRE_SHIFT 12
227 +#define SPI_DEV_ID_0 0
228 +#define SPI_DEV_ID_1 1
229 +#define SPI_DEV_ID_2 2
230 +#define SPI_DEV_ID_3 3
232 +/* Interrupt mask */
233 +#define SPI_INTR_CMD_DONE 0x01
234 +#define SPI_INTR_RX_OVERFLOW 0x02
235 +#define SPI_INTR_TX_UNDERFLOW 0x04
236 +#define SPI_INTR_TX_OVERFLOW 0x08
237 +#define SPI_INTR_RX_UNDERFLOW 0x10
238 +#define SPI_INTR_CLEAR_ALL 0x1f
241 +#define SPI_RX_EMPTY 0x02
242 +#define SPI_CMD_BUSY 0x04
243 +#define SPI_SERIAL_BUSY 0x08
245 +/* Clock configuration */
246 +#define SPI_CLK_20MHZ 0x00
247 +#define SPI_CLK_0_391MHZ 0x01
248 +#define SPI_CLK_0_781MHZ 0x02 /* default */
249 +#define SPI_CLK_1_563MHZ 0x03
250 +#define SPI_CLK_3_125MHZ 0x04
251 +#define SPI_CLK_6_250MHZ 0x05
252 +#define SPI_CLK_12_50MHZ 0x06
253 +#define SPI_CLK_25MHZ 0x07
254 +#define SPI_CLK_MASK 0x07
255 +#define SPI_SSOFFTIME_MASK 0x38
256 +#define SPI_SSOFFTIME_SHIFT 3
257 +#define SPI_BYTE_SWAP 0x80
259 #endif /* BCM63XX_REGS_H_ */
261 Index: linux-2.6.32.13/drivers/spi/bcm63xx_spi.c
262 ===================================================================
263 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
264 +++ linux-2.6.32.13/drivers/spi/bcm63xx_spi.c 2010-05-27 21:48:23.000000000 -0400
267 + * Broadcom BCM63xx SPI controller support
269 + * Copyright (C) 2009 Florian Fainelli <florian@openwrt.org>
271 + * This program is free software; you can redistribute it and/or
272 + * modify it under the terms of the GNU General Public License
273 + * as published by the Free Software Foundation; either version 2
274 + * of the License, or (at your option) any later version.
276 + * This program is distributed in the hope that it will be useful,
277 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
278 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
279 + * GNU General Public License for more details.
281 + * You should have received a copy of the GNU General Public License
282 + * along with this program; if not, write to the
283 + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
286 +#include <linux/kernel.h>
287 +#include <linux/init.h>
288 +#include <linux/clk.h>
289 +#include <linux/module.h>
290 +#include <linux/platform_device.h>
291 +#include <linux/delay.h>
292 +#include <linux/interrupt.h>
293 +#include <linux/spi/spi.h>
294 +#include <linux/spi/spi_bitbang.h>
295 +#include <linux/gpio.h>
296 +#include <linux/completion.h>
297 +#include <linux/err.h>
299 +#include <bcm63xx_io.h>
300 +#include <bcm63xx_regs.h>
301 +#include <bcm63xx_dev_spi.h>
303 +#define PFX KBUILD_MODNAME
304 +#define DRV_VER "0.1.2"
306 +enum bcm63xx_regs_spi {
324 +static const unsigned long bcm96338_regs_spi[] = {
325 + [SPI_CMD] = SPI_BCM_6338_SPI_CMD,
326 + [SPI_INT_STATUS] = SPI_BCM_6338_SPI_INT_STATUS,
327 + [SPI_INT_MASK_ST] = SPI_BCM_6338_SPI_MASK_INT_ST,
328 + [SPI_INT_MASK] = SPI_BCM_6338_SPI_INT_MASK,
329 + [SPI_ST] = SPI_BCM_6338_SPI_ST,
330 + [SPI_CLK_CFG] = SPI_BCM_6338_SPI_CLK_CFG,
331 + [SPI_FILL_BYTE] = SPI_BCM_6338_SPI_FILL_BYTE,
332 + [SPI_MSG_TAIL] = SPI_BCM_6338_SPI_MSG_TAIL,
333 + [SPI_RX_TAIL] = SPI_BCM_6338_SPI_RX_TAIL,
334 + [SPI_MSG_CTL] = SPI_BCM_6338_SPI_MSG_CTL,
335 + [SPI_MSG_DATA] = SPI_BCM_6338_SPI_MSG_DATA,
336 + [SPI_RX_DATA] = SPI_BCM_6338_SPI_RX_DATA,
339 +static const unsigned long bcm96348_regs_spi[] = {
340 + [SPI_CMD] = SPI_BCM_6348_SPI_CMD,
341 + [SPI_INT_STATUS] = SPI_BCM_6348_SPI_INT_STATUS,
342 + [SPI_INT_MASK_ST] = SPI_BCM_6348_SPI_MASK_INT_ST,
343 + [SPI_INT_MASK] = SPI_BCM_6348_SPI_INT_MASK,
344 + [SPI_ST] = SPI_BCM_6348_SPI_ST,
345 + [SPI_CLK_CFG] = SPI_BCM_6348_SPI_CLK_CFG,
346 + [SPI_FILL_BYTE] = SPI_BCM_6348_SPI_FILL_BYTE,
347 + [SPI_MSG_TAIL] = SPI_BCM_6348_SPI_MSG_TAIL,
348 + [SPI_RX_TAIL] = SPI_BCM_6348_SPI_RX_TAIL,
349 + [SPI_MSG_CTL] = SPI_BCM_6348_SPI_MSG_CTL,
350 + [SPI_MSG_DATA] = SPI_BCM_6348_SPI_MSG_DATA,
351 + [SPI_RX_DATA] = SPI_BCM_6348_SPI_RX_DATA,
354 +static const unsigned long bcm96358_regs_spi[] = {
355 + [SPI_CMD] = SPI_BCM_6358_SPI_CMD,
356 + [SPI_INT_STATUS] = SPI_BCM_6358_SPI_INT_STATUS,
357 + [SPI_INT_MASK_ST] = SPI_BCM_6358_SPI_MASK_INT_ST,
358 + [SPI_INT_MASK] = SPI_BCM_6358_SPI_INT_MASK,
359 + [SPI_ST] = SPI_BCM_6358_SPI_STATUS,
360 + [SPI_CLK_CFG] = SPI_BCM_6358_SPI_CLK_CFG,
361 + [SPI_FILL_BYTE] = SPI_BCM_6358_SPI_FILL_BYTE,
362 + [SPI_MSG_TAIL] = SPI_BCM_6358_SPI_MSG_TAIL,
363 + [SPI_RX_TAIL] = SPI_BCM_6358_SPI_RX_TAIL,
364 + [SPI_MSG_CTL] = SPI_BCM_6358_MSG_CTL,
365 + [SPI_MSG_DATA] = SPI_BCM_6358_SPI_MSG_DATA,
366 + [SPI_RX_DATA] = SPI_BCM_6358_SPI_RX_DATA,
370 +#ifdef BCMCPU_RUNTIME_DETECT
371 +static const unsigned long *bcm63xx_regs_spi;
373 +static __init void bcm63xx_spi_regs_init(void)
375 + if (BCMCPU_IS_6338())
376 + bcm63xx_regs_spi = bcm96338_regs_spi;
377 + if (BCMCPU_IS_6348())
378 + bcm63xx_regs_spi = bcm96348_regs_spi;
379 + if (BCMCPU_IS_6358())
380 + bcm63xx_regs_spi = bcm96358_regs_spi;
383 +static __init void bcm63xx_spi_regs_init(void) { }
386 +static inline unsigned long bcm63xx_spireg(enum bcm63xx_regs_spi reg)
388 +#ifdef BCMCPU_RUNTIME_DETECT
389 + return bcm63xx_regs_spi[reg];
391 +#ifdef CONFIG_BCM63XX_CPU_6338
394 + return SPI_BCM_6338_SPI_CMD;
395 + case SPI_INT_STATUS:
396 + return SPI_BCM_6338_SPI_INT_STATUS;
397 + case SPI_INT_MASK_ST:
398 + return SPI_BCM_6338_SPI_MASK_INT_ST;
400 + return SPI_BCM_6338_SPI_INT_MASK;
402 + return SPI_BCM_6338_SPI_ST;
404 + return SPI_BCM_6338_SPI_CLK_CFG;
405 + case SPI_FILL_BYTE:
406 + return SPI_BCM_6338_SPI_FILL_BYTE;
408 + return SPI_BCM_6338_SPI_MSG_TAIL;
410 + return SPI_BCM_6338_SPI_RX_TAIL;
412 + return SPI_BCM_6338_SPI_MSG_CTL;
414 + return SPI_BCM_6338_SPI_MSG_DATA;
416 + return SPI_BCM_6338_SPI_RX_DATA;
419 +#ifdef CONFIG_BCM63XX_CPU_6348
422 + return SPI_BCM_6348_SPI_CMD;
423 + case SPI_INT_MASK_ST:
424 + return SPI_BCM_6348_SPI_MASK_INT_ST;
426 + return SPI_BCM_6348_SPI_INT_MASK;
427 + case SPI_INT_STATUS:
428 + return SPI_BCM_6348_SPI_INT_STATUS;
430 + return SPI_BCM_6348_SPI_ST;
432 + return SPI_BCM_6348_SPI_CLK_CFG;
433 + case SPI_FILL_BYTE:
434 + return SPI_BCM_6348_SPI_FILL_BYTE;
436 + return SPI_BCM_6348_SPI_MSG_TAIL;
438 + return SPI_BCM_6348_SPI_RX_TAIL;
440 + return SPI_BCM_6348_SPI_MSG_CTL;
442 + return SPI_BCM_6348_SPI_MSG_DATA;
444 + return SPI_BCM_6348_SPI_RX_DATA;
447 +#ifdef CONFIG_BCM63XX_CPU_6358
450 + return SPI_BCM_6358_SPI_CMD;
451 + case SPI_INT_STATUS:
452 + return SPI_BCM_6358_SPI_INT_STATUS;
453 + case SPI_INT_MASK_ST:
454 + return SPI_BCM_6358_SPI_MASK_INT_ST;
456 + return SPI_BCM_6358_SPI_INT_MASK;
458 + return SPI_BCM_6358_SPI_STATUS;
460 + return SPI_BCM_6358_SPI_CLK_CFG;
461 + case SPI_FILL_BYTE:
462 + return SPI_BCM_6358_SPI_FILL_BYTE;
464 + return SPI_BCM_6358_SPI_MSG_TAIL;
466 + return SPI_BCM_6358_SPI_RX_TAIL;
468 + return SPI_BCM_6358_MSG_CTL;
470 + return SPI_BCM_6358_SPI_MSG_DATA;
472 + return SPI_BCM_6358_SPI_RX_DATA;
480 + * helpers for the SPI register sets
482 +#define bcm_spi_readb(b,o) bcm_readb((b) + bcm63xx_spireg(o))
483 +#define bcm_spi_readw(b,o) bcm_readw((b) + bcm63xx_spireg(o))
484 +#define bcm_spi_writeb(v,b,o) bcm_writeb((v), (b) + bcm63xx_spireg(o))
485 +#define bcm_spi_writew(v,b,o) bcm_writew((v), (b) + bcm63xx_spireg(o))
487 +struct bcm63xx_spi {
488 + /* bitbang has to be first */
489 + struct spi_bitbang bitbang;
490 + struct completion done;
492 + void __iomem *regs;
495 + /* Platform data */
497 + unsigned fifo_size;
500 + const unsigned char *tx_ptr;
501 + unsigned char *rx_ptr;
502 + int remaining_bytes;
505 + struct resource *ioarea;
506 + struct platform_device *pdev;
509 +static void bcm63xx_spi_chipselect(struct spi_device *spi, int is_on)
511 + struct bcm63xx_spi *bs = spi_master_get_devdata(spi->master);
514 + val = bcm_spi_readw(bs->regs, SPI_CMD);
515 + if (is_on == BITBANG_CS_INACTIVE)
516 + val |= SPI_CMD_NOOP;
517 + else if (is_on == BITBANG_CS_ACTIVE)
518 + val |= (spi->chip_select << SPI_CMD_DEVICE_ID_SHIFT);
520 + bcm_spi_writew(val, bs->regs, SPI_CMD);
523 +static int bcm63xx_spi_setup_transfer(struct spi_device *spi,
524 + struct spi_transfer *t)
531 + struct bcm63xx_spi *bs = spi_master_get_devdata(spi->master);
533 + bits_per_word = (t) ? t->bits_per_word : spi->bits_per_word;
534 + hz = (t) ? t->speed_hz : spi->max_speed_hz;
535 + if (bits_per_word != 8) {
536 + dev_err(&spi->dev, "%s, unsupported bits_per_word=%d\n",
537 + __func__, bits_per_word);
541 + if (spi->chip_select > spi->master->num_chipselect) {
542 + dev_err(&spi->dev, "%s, unsupported slave %d\n",
543 + __func__, spi->chip_select);
547 + /* Check clock setting */
548 + div = (bs->speed_hz / hz);
551 + clk_cfg = SPI_CLK_25MHZ;
554 + clk_cfg = SPI_CLK_12_50MHZ;
557 + clk_cfg = SPI_CLK_6_250MHZ;
560 + clk_cfg = SPI_CLK_3_125MHZ;
563 + clk_cfg = SPI_CLK_1_563MHZ;
566 + clk_cfg = SPI_CLK_0_781MHZ;
570 + /* Set to slowest mode for compatibility */
571 + clk_cfg = SPI_CLK_0_781MHZ;
575 + bcm_spi_writeb(clk_cfg, bs->regs, SPI_CLK_CFG);
576 + dev_dbg(&spi->dev, "Setting clock register to %d (hz %d, cmd %02x)\n",
582 +/* the spi->mode bits understood by this driver: */
583 +#define MODEBITS (SPI_CPOL | SPI_CPHA)
585 +static int bcm63xx_spi_setup(struct spi_device *spi)
587 + struct spi_bitbang *bitbang;
588 + struct bcm63xx_spi *bs;
591 + bs = spi_master_get_devdata(spi->master);
592 + bitbang = &bs->bitbang;
594 + if (!spi->bits_per_word)
595 + spi->bits_per_word = 8;
597 + if (spi->mode & ~MODEBITS) {
598 + dev_err(&spi->dev, "%s, unsupported mode bits %x\n",
599 + __func__, spi->mode & ~MODEBITS);
603 + retval = bcm63xx_spi_setup_transfer(spi, NULL);
605 + dev_err(&spi->dev, "setup: unsupported mode bits %x\n",
606 + spi->mode & ~MODEBITS);
610 + dev_dbg(&spi->dev, "%s, mode %d, %u bits/w, %u nsec/bit\n",
611 + __func__, spi->mode & MODEBITS, spi->bits_per_word, 0);
616 +/* Fill the TX FIFO with as many bytes as possible */
617 +static void bcm63xx_spi_fill_tx_fifo(struct bcm63xx_spi *bs)
621 + /* Fill the Tx FIFO with as many bytes as possible */
622 + tail = bcm_spi_readb(bs->regs, SPI_MSG_TAIL);
623 + while ((tail < bs->fifo_size) && (bs->remaining_bytes > 0)) {
625 + bcm_spi_writeb(*bs->tx_ptr++, bs->regs, SPI_MSG_DATA);
627 + bcm_spi_writeb(0, bs->regs, SPI_MSG_DATA);
628 + bs->remaining_bytes--;
629 + tail = bcm_spi_readb(bs->regs, SPI_MSG_TAIL);
633 +static int bcm63xx_txrx_bufs(struct spi_device *spi, struct spi_transfer *t)
635 + struct bcm63xx_spi *bs = spi_master_get_devdata(spi->master);
639 + dev_dbg(&spi->dev, "txrx: tx %p, rx %p, len %d\n",
640 + t->tx_buf, t->rx_buf, t->len);
642 + /* Transmitter is inhibited */
643 + bs->tx_ptr = t->tx_buf;
644 + bs->rx_ptr = t->rx_buf;
645 + bs->remaining_bytes = t->len;
646 + init_completion(&bs->done);
648 + bcm63xx_spi_fill_tx_fifo(bs);
650 + /* Enable the command done interrupt which
651 + * we use to determine completion of a command */
652 + bcm_spi_writeb(SPI_INTR_CMD_DONE, bs->regs, SPI_INT_MASK);
654 + /* Fill in the Message control register */
655 + msg_ctl = bcm_spi_readb(bs->regs, SPI_MSG_CTL);
656 + msg_ctl |= (t->len << SPI_BYTE_CNT_SHIFT);
657 + msg_ctl |= (SPI_FD_RW << SPI_MSG_TYPE_SHIFT);
658 + bcm_spi_writeb(msg_ctl, bs->regs, SPI_MSG_CTL);
660 + /* Issue the transfer */
661 + cmd = bcm_spi_readw(bs->regs, SPI_CMD);
662 + cmd |= SPI_CMD_START_IMMEDIATE;
663 + cmd |= (0 << SPI_CMD_PREPEND_BYTE_CNT_SHIFT);
664 + bcm_spi_writew(cmd, bs->regs, SPI_CMD);
666 + wait_for_completion(&bs->done);
668 + /* Disable the CMD_DONE interrupt */
669 + bcm_spi_writeb(~(SPI_INTR_CMD_DONE), bs->regs, SPI_INT_MASK);
671 + return t->len - bs->remaining_bytes;
674 +/* This driver supports single master mode only. Hence
675 + * CMD_DONE is the only interrupt we care about
677 +static irqreturn_t bcm63xx_spi_interrupt(int irq, void *dev_id)
679 + struct spi_master *master = (struct spi_master *)dev_id;
680 + struct bcm63xx_spi *bs = spi_master_get_devdata(master);
684 + /* Read interupts and clear them immediately */
685 + intr = bcm_spi_readb(bs->regs, SPI_INT_STATUS);
686 + bcm_spi_writeb(SPI_INTR_CLEAR_ALL, bs->regs, SPI_INT_MASK);
688 + /* A tansfer completed */
689 + if (intr & SPI_INTR_CMD_DONE) {
692 + rx_empty = bcm_spi_readb(bs->regs, SPI_ST);
693 + /* Read out all the data */
694 + while ((rx_empty & SPI_RX_EMPTY) == 0) {
697 + data = bcm_spi_readb(bs->regs, SPI_RX_DATA);
699 + *bs->rx_ptr++ = data;
701 + rx_empty = bcm_spi_readb(bs->regs, SPI_RX_EMPTY);
704 + /* See if there is more data to send */
705 + if (bs->remaining_bytes > 0) {
706 + bcm63xx_spi_fill_tx_fifo(bs);
708 + /* Start the transfer */
709 + cmd = bcm_spi_readw(bs->regs, SPI_CMD);
710 + cmd |= SPI_CMD_START_IMMEDIATE;
711 + cmd |= (0 << SPI_CMD_PREPEND_BYTE_CNT_SHIFT);
712 + bcm_spi_writew(cmd, bs->regs, SPI_CMD);
714 + complete(&bs->done);
717 + return IRQ_HANDLED;
721 +static int __init bcm63xx_spi_probe(struct platform_device *pdev)
723 + struct resource *r;
724 + struct bcm63xx_spi_pdata *pdata = pdev->dev.platform_data;
726 + struct spi_master *master;
728 + struct bcm63xx_spi *bs;
731 + r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
737 + irq = platform_get_irq(pdev, 0);
743 + bcm63xx_spi_regs_init();
745 + clk = clk_get(&pdev->dev, "spi");
747 + dev_err(&pdev->dev, "No clock for device\n");
752 + master = spi_alloc_master(&pdev->dev, sizeof(struct bcm63xx_spi));
758 + bs = spi_master_get_devdata(master);
759 + bs->bitbang.master = spi_master_get(master);
760 + bs->bitbang.chipselect = bcm63xx_spi_chipselect;
761 + bs->bitbang.setup_transfer = bcm63xx_spi_setup_transfer;
762 + bs->bitbang.txrx_bufs = bcm63xx_txrx_bufs;
763 + bs->bitbang.master->setup = bcm63xx_spi_setup;
764 + init_completion(&bs->done);
766 + platform_set_drvdata(pdev, master);
769 + if (!request_mem_region(r->start,
770 + r->end - r->start, PFX)) {
775 + bs->regs = ioremap_nocache(r->start, r->end - r->start);
777 + printk(KERN_ERR PFX " unable to ioremap regs\n");
783 + bs->fifo_size = pdata->fifo_size;
785 + ret = request_irq(irq, bcm63xx_spi_interrupt, 0,
786 + pdev->name, master);
788 + printk(KERN_ERR PFX " unable to request irq\n");
792 + master->bus_num = pdata->bus_num;
793 + master->num_chipselect = pdata->num_chipselect;
794 + bs->speed_hz = pdata->speed_hz;
796 + /* Initialize hardware */
797 + clk_enable(bs->clk);
798 + bcm_spi_writeb(SPI_INTR_CLEAR_ALL, bs->regs, SPI_INT_MASK);
800 + dev_info(&pdev->dev, " at 0x%08x (irq %d, FIFOs size %d) v%s\n",
801 + r->start, irq, bs->fifo_size, DRV_VER);
803 + ret = spi_bitbang_start(&bs->bitbang);
805 + dev_err(&pdev->dev, "spi_bitbang_start FAILED\n");
813 + free_irq(irq, master);
818 + spi_master_put(master);
823 +static int __exit bcm63xx_spi_remove(struct platform_device *pdev)
825 + struct spi_master *master = platform_get_drvdata(pdev);
826 + struct bcm63xx_spi *bs = spi_master_get_devdata(master);
828 + spi_bitbang_stop(&bs->bitbang);
829 + clk_disable(bs->clk);
831 + free_irq(bs->irq, master);
833 + platform_set_drvdata(pdev, 0);
834 + spi_master_put(bs->bitbang.master);
840 +static int bcm63xx_spi_suspend(struct platform_device *pdev, pm_message_t mesg)
842 + struct spi_master *master = platform_get_drvdata(pdev);
843 + struct bcm63xx_spi *bs = spi_master_get_devdata(master);
845 + clk_disable(bs->clk);
850 +static int bcm63xx_spi_resume(struct platform_device *pdev)
852 + struct bcm63xx_spi *bs = spi_master_get_devdata(master);
853 + struct bcm63xx_spi *bs = spi_master_get_devdata(master);
855 + clk_enable(bs->clk);
860 +#define bcm63xx_spi_suspend NULL
861 +#define bcm63xx_spi_resume NULL
864 +static struct platform_driver bcm63xx_spi_driver = {
866 + .name = "bcm63xx-spi",
867 + .owner = THIS_MODULE,
869 + .probe = bcm63xx_spi_probe,
870 + .remove = bcm63xx_spi_remove,
871 + .suspend = bcm63xx_spi_suspend,
872 + .resume = bcm63xx_spi_resume,
876 +static int __init bcm63xx_spi_init(void)
878 + return platform_driver_register(&bcm63xx_spi_driver);
881 +static void __exit bcm63xx_spi_exit(void)
883 + platform_driver_unregister(&bcm63xx_spi_driver);
886 +module_init(bcm63xx_spi_init);
887 +module_exit(bcm63xx_spi_exit);
889 +MODULE_ALIAS("platform:bcm63xx_spi");
890 +MODULE_AUTHOR("Florian Fainelli <florian@openwrt.org>");
891 +MODULE_DESCRIPTION("Broadcom BCM63xx SPI Controller driver");
892 +MODULE_LICENSE("GPL");
893 +MODULE_VERSION(DRV_VER);
894 Index: linux-2.6.32.13/drivers/spi/Kconfig
895 ===================================================================
896 --- linux-2.6.32.13.orig/drivers/spi/Kconfig 2010-05-27 21:34:54.000000000 -0400
897 +++ linux-2.6.32.13/drivers/spi/Kconfig 2010-05-27 21:48:23.000000000 -0400
899 This selects a driver for the Atmel SPI Controller, present on
900 many AT32 (AVR32) and AT91 (ARM) chips.
903 + tristate "Broadcom BCM63xx SPI controller"
907 + This is the SPI controller master driver for Broadcom BCM63xx SoC.
910 tristate "SPI controller driver for ADI Blackfin5xx"
912 Index: linux-2.6.32.13/drivers/spi/Makefile
913 ===================================================================
914 --- linux-2.6.32.13.orig/drivers/spi/Makefile 2010-05-27 21:34:54.000000000 -0400
915 +++ linux-2.6.32.13/drivers/spi/Makefile 2010-05-27 21:48:23.000000000 -0400
917 obj-$(CONFIG_SPI_XILINX) += xilinx_spi.o
918 obj-$(CONFIG_SPI_SH_SCI) += spi_sh_sci.o
919 obj-$(CONFIG_SPI_STMP3XXX) += spi_stmp.o
920 +obj-$(CONFIG_SPI_BCM63XX) += bcm63xx_spi.o
921 # ... add above this line ...
923 # SPI protocol drivers (device/link on bus)
924 Index: linux-2.6.32.13/arch/mips/include/asm/mach-bcm63xx/bcm63xx_dev_spi.h
925 ===================================================================
926 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
927 +++ linux-2.6.32.13/arch/mips/include/asm/mach-bcm63xx/bcm63xx_dev_spi.h 2010-05-27 21:48:23.000000000 -0400
929 +#ifndef BCM63XX_DEV_SPI_H
930 +#define BCM63XX_DEV_SPI_H
932 +#include <linux/types.h>
934 +int __init bcm63xx_spi_register(void);
936 +struct bcm63xx_spi_pdata {
937 + unsigned int fifo_size;
939 + int num_chipselect;
943 +#endif /* BCM63XX_DEV_SPI_H */
944 Index: linux-2.6.32.13/arch/mips/bcm63xx/Makefile
945 ===================================================================
946 --- linux-2.6.32.13.orig/arch/mips/bcm63xx/Makefile 2010-05-27 21:44:19.000000000 -0400
947 +++ linux-2.6.32.13/arch/mips/bcm63xx/Makefile 2010-05-27 21:48:23.000000000 -0400
949 obj-y += clk.o cpu.o cs.o gpio.o irq.o prom.o setup.o timer.o \
950 dev-dsp.o dev-enet.o dev-pcmcia.o dev-uart.o dev-wdt.o \
951 - dev-usb-ohci.o dev-usb-ehci.o dev-usb-udc.o
952 + dev-usb-ohci.o dev-usb-ehci.o dev-usb-udc.o dev-spi.o
953 obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
956 Index: linux-2.6.32.13/arch/mips/bcm63xx/boards/board_bcm963xx.c
957 ===================================================================
958 --- linux-2.6.32.13.orig/arch/mips/bcm63xx/boards/board_bcm963xx.c 2010-05-27 21:46:39.000000000 -0400
959 +++ linux-2.6.32.13/arch/mips/bcm63xx/boards/board_bcm963xx.c 2010-05-27 21:48:23.000000000 -0400
961 #include <bcm63xx_dev_usb_ohci.h>
962 #include <bcm63xx_dev_usb_ehci.h>
963 #include <bcm63xx_dev_usb_udc.h>
964 +#include <bcm63xx_dev_spi.h>
965 #include <board_bcm963xx.h>
967 #define PFX "board_bcm963xx: "
968 @@ -1479,6 +1480,9 @@
970 bcm63xx_udc_register();
972 + if (!BCMCPU_IS_6345())
973 + bcm63xx_spi_register();
975 /* Generate MAC address for WLAN and
976 * register our SPROM */
977 #ifdef CONFIG_SSB_PCIHOST