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 +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 @@ -109,6 +109,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 @@ -214,7 +215,7 @@ enum bcm63xx_regs_set {
101 #define BCM_6358_UART0_BASE (0xfffe0100)
102 #define BCM_6358_UART1_BASE (0xfffe0120)
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 @@ -441,6 +442,7 @@ static inline unsigned long bcm63xx_regs
117 @@ -507,6 +509,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 @@ -531,6 +534,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_UART1_IRQ (IRQ_INTERNAL_BASE + 3)
132 #define BCM_6358_OHCI0_IRQ (IRQ_INTERNAL_BASE + 5)
133 --- a/arch/mips/include/asm/mach-bcm63xx/bcm63xx_regs.h
134 +++ b/arch/mips/include/asm/mach-bcm63xx/bcm63xx_regs.h
135 @@ -769,4 +769,116 @@
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_ */
253 +++ b/drivers/spi/bcm63xx_spi.c
256 + * Broadcom BCM63xx SPI controller support
258 + * Copyright (C) 2009 Florian Fainelli <florian@openwrt.org>
260 + * This program is free software; you can redistribute it and/or
261 + * modify it under the terms of the GNU General Public License
262 + * as published by the Free Software Foundation; either version 2
263 + * of the License, or (at your option) any later version.
265 + * This program is distributed in the hope that it will be useful,
266 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
267 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
268 + * GNU General Public License for more details.
270 + * You should have received a copy of the GNU General Public License
271 + * along with this program; if not, write to the
272 + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
275 +#include <linux/kernel.h>
276 +#include <linux/init.h>
277 +#include <linux/clk.h>
278 +#include <linux/module.h>
279 +#include <linux/platform_device.h>
280 +#include <linux/delay.h>
281 +#include <linux/interrupt.h>
282 +#include <linux/spi/spi.h>
283 +#include <linux/spi/spi_bitbang.h>
284 +#include <linux/gpio.h>
285 +#include <linux/completion.h>
286 +#include <linux/err.h>
288 +#include <bcm63xx_io.h>
289 +#include <bcm63xx_regs.h>
290 +#include <bcm63xx_dev_spi.h>
292 +#define PFX KBUILD_MODNAME
293 +#define DRV_VER "0.1.2"
295 +enum bcm63xx_regs_spi {
313 +static const unsigned long bcm96338_regs_spi[] = {
314 + [SPI_CMD] = SPI_BCM_6338_SPI_CMD,
315 + [SPI_INT_STATUS] = SPI_BCM_6338_SPI_INT_STATUS,
316 + [SPI_INT_MASK_ST] = SPI_BCM_6338_SPI_MASK_INT_ST,
317 + [SPI_INT_MASK] = SPI_BCM_6338_SPI_INT_MASK,
318 + [SPI_ST] = SPI_BCM_6338_SPI_ST,
319 + [SPI_CLK_CFG] = SPI_BCM_6338_SPI_CLK_CFG,
320 + [SPI_FILL_BYTE] = SPI_BCM_6338_SPI_FILL_BYTE,
321 + [SPI_MSG_TAIL] = SPI_BCM_6338_SPI_MSG_TAIL,
322 + [SPI_RX_TAIL] = SPI_BCM_6338_SPI_RX_TAIL,
323 + [SPI_MSG_CTL] = SPI_BCM_6338_SPI_MSG_CTL,
324 + [SPI_MSG_DATA] = SPI_BCM_6338_SPI_MSG_DATA,
325 + [SPI_RX_DATA] = SPI_BCM_6338_SPI_RX_DATA,
328 +static const unsigned long bcm96348_regs_spi[] = {
329 + [SPI_CMD] = SPI_BCM_6348_SPI_CMD,
330 + [SPI_INT_STATUS] = SPI_BCM_6348_SPI_INT_STATUS,
331 + [SPI_INT_MASK_ST] = SPI_BCM_6348_SPI_MASK_INT_ST,
332 + [SPI_INT_MASK] = SPI_BCM_6348_SPI_INT_MASK,
333 + [SPI_ST] = SPI_BCM_6348_SPI_ST,
334 + [SPI_CLK_CFG] = SPI_BCM_6348_SPI_CLK_CFG,
335 + [SPI_FILL_BYTE] = SPI_BCM_6348_SPI_FILL_BYTE,
336 + [SPI_MSG_TAIL] = SPI_BCM_6348_SPI_MSG_TAIL,
337 + [SPI_RX_TAIL] = SPI_BCM_6348_SPI_RX_TAIL,
338 + [SPI_MSG_CTL] = SPI_BCM_6348_SPI_MSG_CTL,
339 + [SPI_MSG_DATA] = SPI_BCM_6348_SPI_MSG_DATA,
340 + [SPI_RX_DATA] = SPI_BCM_6348_SPI_RX_DATA,
343 +static const unsigned long bcm96358_regs_spi[] = {
344 + [SPI_CMD] = SPI_BCM_6358_SPI_CMD,
345 + [SPI_INT_STATUS] = SPI_BCM_6358_SPI_INT_STATUS,
346 + [SPI_INT_MASK_ST] = SPI_BCM_6358_SPI_MASK_INT_ST,
347 + [SPI_INT_MASK] = SPI_BCM_6358_SPI_INT_MASK,
348 + [SPI_ST] = SPI_BCM_6358_SPI_STATUS,
349 + [SPI_CLK_CFG] = SPI_BCM_6358_SPI_CLK_CFG,
350 + [SPI_FILL_BYTE] = SPI_BCM_6358_SPI_FILL_BYTE,
351 + [SPI_MSG_TAIL] = SPI_BCM_6358_SPI_MSG_TAIL,
352 + [SPI_RX_TAIL] = SPI_BCM_6358_SPI_RX_TAIL,
353 + [SPI_MSG_CTL] = SPI_BCM_6358_MSG_CTL,
354 + [SPI_MSG_DATA] = SPI_BCM_6358_SPI_MSG_DATA,
355 + [SPI_RX_DATA] = SPI_BCM_6358_SPI_RX_DATA,
359 +#ifdef BCMCPU_RUNTIME_DETECT
360 +static const unsigned long *bcm63xx_regs_spi;
362 +static __init void bcm63xx_spi_regs_init(void)
364 + if (BCMCPU_IS_6338())
365 + bcm63xx_regs_spi = bcm96338_regs_spi;
366 + if (BCMCPU_IS_6348())
367 + bcm63xx_regs_spi = bcm96348_regs_spi;
368 + if (BCMCPU_IS_6358())
369 + bcm63xx_regs_spi = bcm96358_regs_spi;
372 +static __init void bcm63xx_spi_regs_init(void) { }
375 +static inline unsigned long bcm63xx_spireg(enum bcm63xx_regs_spi reg)
377 +#ifdef BCMCPU_RUNTIME_DETECT
378 + return bcm63xx_regs_spi[reg];
380 +#ifdef CONFIG_BCM63XX_CPU_6338
383 + return SPI_BCM_6338_SPI_CMD;
384 + case SPI_INT_STATUS:
385 + return SPI_BCM_6338_SPI_INT_STATUS;
386 + case SPI_INT_MASK_ST:
387 + return SPI_BCM_6338_SPI_MASK_INT_ST;
389 + return SPI_BCM_6338_SPI_INT_MASK;
391 + return SPI_BCM_6338_SPI_ST;
393 + return SPI_BCM_6338_SPI_CLK_CFG;
394 + case SPI_FILL_BYTE:
395 + return SPI_BCM_6338_SPI_FILL_BYTE;
397 + return SPI_BCM_6338_SPI_MSG_TAIL;
399 + return SPI_BCM_6338_SPI_RX_TAIL;
401 + return SPI_BCM_6338_SPI_MSG_CTL;
403 + return SPI_BCM_6338_SPI_MSG_DATA;
405 + return SPI_BCM_6338_SPI_RX_DATA;
408 +#ifdef CONFIG_BCM63XX_CPU_6348
411 + return SPI_BCM_6348_SPI_CMD;
412 + case SPI_INT_MASK_ST:
413 + return SPI_BCM_6348_SPI_MASK_INT_ST;
415 + return SPI_BCM_6348_SPI_INT_MASK;
416 + case SPI_INT_STATUS:
417 + return SPI_BCM_6348_SPI_INT_STATUS;
419 + return SPI_BCM_6348_SPI_ST;
421 + return SPI_BCM_6348_SPI_CLK_CFG;
422 + case SPI_FILL_BYTE:
423 + return SPI_BCM_6348_SPI_FILL_BYTE;
425 + return SPI_BCM_6348_SPI_MSG_TAIL;
427 + return SPI_BCM_6348_SPI_RX_TAIL;
429 + return SPI_BCM_6348_SPI_MSG_CTL;
431 + return SPI_BCM_6348_SPI_MSG_DATA;
433 + return SPI_BCM_6348_SPI_RX_DATA;
436 +#ifdef CONFIG_BCM63XX_CPU_6358
439 + return SPI_BCM_6358_SPI_CMD;
440 + case SPI_INT_STATUS:
441 + return SPI_BCM_6358_SPI_INT_STATUS;
442 + case SPI_INT_MASK_ST:
443 + return SPI_BCM_6358_SPI_MASK_INT_ST;
445 + return SPI_BCM_6358_SPI_INT_MASK;
447 + return SPI_BCM_6358_SPI_STATUS;
449 + return SPI_BCM_6358_SPI_CLK_CFG;
450 + case SPI_FILL_BYTE:
451 + return SPI_BCM_6358_SPI_FILL_BYTE;
453 + return SPI_BCM_6358_SPI_MSG_TAIL;
455 + return SPI_BCM_6358_SPI_RX_TAIL;
457 + return SPI_BCM_6358_MSG_CTL;
459 + return SPI_BCM_6358_SPI_MSG_DATA;
461 + return SPI_BCM_6358_SPI_RX_DATA;
469 + * helpers for the SPI register sets
471 +#define bcm_spi_readb(b,o) bcm_readb((b) + bcm63xx_spireg(o))
472 +#define bcm_spi_readw(b,o) bcm_readw((b) + bcm63xx_spireg(o))
473 +#define bcm_spi_writeb(v,b,o) bcm_writeb((v), (b) + bcm63xx_spireg(o))
474 +#define bcm_spi_writew(v,b,o) bcm_writew((v), (b) + bcm63xx_spireg(o))
476 +struct bcm63xx_spi {
477 + /* bitbang has to be first */
478 + struct spi_bitbang bitbang;
479 + struct completion done;
481 + void __iomem *regs;
484 + /* Platform data */
486 + unsigned fifo_size;
489 + const unsigned char *tx_ptr;
490 + unsigned char *rx_ptr;
491 + int remaining_bytes;
494 + struct resource *ioarea;
495 + struct platform_device *pdev;
498 +static void bcm63xx_spi_chipselect(struct spi_device *spi, int is_on)
500 + struct bcm63xx_spi *bs = spi_master_get_devdata(spi->master);
503 + val = bcm_spi_readw(bs->regs, SPI_CMD);
504 + if (is_on == BITBANG_CS_INACTIVE)
505 + val |= SPI_CMD_NOOP;
506 + else if (is_on == BITBANG_CS_ACTIVE)
507 + val |= (spi->chip_select << SPI_CMD_DEVICE_ID_SHIFT);
509 + bcm_spi_writew(val, bs->regs, SPI_CMD);
512 +static int bcm63xx_spi_setup_transfer(struct spi_device *spi,
513 + struct spi_transfer *t)
520 + struct bcm63xx_spi *bs = spi_master_get_devdata(spi->master);
522 + bits_per_word = (t) ? t->bits_per_word : spi->bits_per_word;
523 + hz = (t) ? t->speed_hz : spi->max_speed_hz;
524 + if (bits_per_word != 8) {
525 + dev_err(&spi->dev, "%s, unsupported bits_per_word=%d\n",
526 + __func__, bits_per_word);
530 + if (spi->chip_select > spi->master->num_chipselect) {
531 + dev_err(&spi->dev, "%s, unsupported slave %d\n",
532 + __func__, spi->chip_select);
536 + /* Check clock setting */
537 + div = (bs->speed_hz / hz);
540 + clk_cfg = SPI_CLK_25MHZ;
543 + clk_cfg = SPI_CLK_12_50MHZ;
546 + clk_cfg = SPI_CLK_6_250MHZ;
549 + clk_cfg = SPI_CLK_3_125MHZ;
552 + clk_cfg = SPI_CLK_1_563MHZ;
555 + clk_cfg = SPI_CLK_0_781MHZ;
559 + /* Set to slowest mode for compatibility */
560 + clk_cfg = SPI_CLK_0_781MHZ;
564 + bcm_spi_writeb(clk_cfg, bs->regs, SPI_CLK_CFG);
565 + dev_dbg(&spi->dev, "Setting clock register to %d (hz %d, cmd %02x)\n",
571 +/* the spi->mode bits understood by this driver: */
572 +#define MODEBITS (SPI_CPOL | SPI_CPHA)
574 +static int bcm63xx_spi_setup(struct spi_device *spi)
576 + struct spi_bitbang *bitbang;
577 + struct bcm63xx_spi *bs;
580 + bs = spi_master_get_devdata(spi->master);
581 + bitbang = &bs->bitbang;
583 + if (!spi->bits_per_word)
584 + spi->bits_per_word = 8;
586 + if (spi->mode & ~MODEBITS) {
587 + dev_err(&spi->dev, "%s, unsupported mode bits %x\n",
588 + __func__, spi->mode & ~MODEBITS);
592 + retval = bcm63xx_spi_setup_transfer(spi, NULL);
594 + dev_err(&spi->dev, "setup: unsupported mode bits %x\n",
595 + spi->mode & ~MODEBITS);
599 + dev_dbg(&spi->dev, "%s, mode %d, %u bits/w, %u nsec/bit\n",
600 + __func__, spi->mode & MODEBITS, spi->bits_per_word, 0);
605 +/* Fill the TX FIFO with as many bytes as possible */
606 +static void bcm63xx_spi_fill_tx_fifo(struct bcm63xx_spi *bs)
610 + /* Fill the Tx FIFO with as many bytes as possible */
611 + tail = bcm_spi_readb(bs->regs, SPI_MSG_TAIL);
612 + while ((tail < bs->fifo_size) && (bs->remaining_bytes > 0)) {
614 + bcm_spi_writeb(*bs->tx_ptr++, bs->regs, SPI_MSG_DATA);
616 + bcm_spi_writeb(0, bs->regs, SPI_MSG_DATA);
617 + bs->remaining_bytes--;
618 + tail = bcm_spi_readb(bs->regs, SPI_MSG_TAIL);
622 +static int bcm63xx_txrx_bufs(struct spi_device *spi, struct spi_transfer *t)
624 + struct bcm63xx_spi *bs = spi_master_get_devdata(spi->master);
628 + dev_dbg(&spi->dev, "txrx: tx %p, rx %p, len %d\n",
629 + t->tx_buf, t->rx_buf, t->len);
631 + /* Transmitter is inhibited */
632 + bs->tx_ptr = t->tx_buf;
633 + bs->rx_ptr = t->rx_buf;
634 + bs->remaining_bytes = t->len;
635 + init_completion(&bs->done);
637 + bcm63xx_spi_fill_tx_fifo(bs);
639 + /* Enable the command done interrupt which
640 + * we use to determine completion of a command */
641 + bcm_spi_writeb(SPI_INTR_CMD_DONE, bs->regs, SPI_INT_MASK);
643 + /* Fill in the Message control register */
644 + msg_ctl = bcm_spi_readb(bs->regs, SPI_MSG_CTL);
645 + msg_ctl |= (t->len << SPI_BYTE_CNT_SHIFT);
646 + msg_ctl |= (SPI_FD_RW << SPI_MSG_TYPE_SHIFT);
647 + bcm_spi_writeb(msg_ctl, bs->regs, SPI_MSG_CTL);
649 + /* Issue the transfer */
650 + cmd = bcm_spi_readw(bs->regs, SPI_CMD);
651 + cmd |= SPI_CMD_START_IMMEDIATE;
652 + cmd |= (0 << SPI_CMD_PREPEND_BYTE_CNT_SHIFT);
653 + bcm_spi_writew(cmd, bs->regs, SPI_CMD);
655 + wait_for_completion(&bs->done);
657 + /* Disable the CMD_DONE interrupt */
658 + bcm_spi_writeb(~(SPI_INTR_CMD_DONE), bs->regs, SPI_INT_MASK);
660 + return t->len - bs->remaining_bytes;
663 +/* This driver supports single master mode only. Hence
664 + * CMD_DONE is the only interrupt we care about
666 +static irqreturn_t bcm63xx_spi_interrupt(int irq, void *dev_id)
668 + struct spi_master *master = (struct spi_master *)dev_id;
669 + struct bcm63xx_spi *bs = spi_master_get_devdata(master);
673 + /* Read interupts and clear them immediately */
674 + intr = bcm_spi_readb(bs->regs, SPI_INT_STATUS);
675 + bcm_spi_writeb(SPI_INTR_CLEAR_ALL, bs->regs, SPI_INT_MASK);
677 + /* A tansfer completed */
678 + if (intr & SPI_INTR_CMD_DONE) {
681 + rx_empty = bcm_spi_readb(bs->regs, SPI_ST);
682 + /* Read out all the data */
683 + while ((rx_empty & SPI_RX_EMPTY) == 0) {
686 + data = bcm_spi_readb(bs->regs, SPI_RX_DATA);
688 + *bs->rx_ptr++ = data;
690 + rx_empty = bcm_spi_readb(bs->regs, SPI_RX_EMPTY);
693 + /* See if there is more data to send */
694 + if (bs->remaining_bytes > 0) {
695 + bcm63xx_spi_fill_tx_fifo(bs);
697 + /* Start the transfer */
698 + cmd = bcm_spi_readw(bs->regs, SPI_CMD);
699 + cmd |= SPI_CMD_START_IMMEDIATE;
700 + cmd |= (0 << SPI_CMD_PREPEND_BYTE_CNT_SHIFT);
701 + bcm_spi_writew(cmd, bs->regs, SPI_CMD);
703 + complete(&bs->done);
706 + return IRQ_HANDLED;
710 +static int __init bcm63xx_spi_probe(struct platform_device *pdev)
712 + struct resource *r;
713 + struct bcm63xx_spi_pdata *pdata = pdev->dev.platform_data;
715 + struct spi_master *master;
717 + struct bcm63xx_spi *bs;
720 + r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
726 + irq = platform_get_irq(pdev, 0);
732 + bcm63xx_spi_regs_init();
734 + clk = clk_get(&pdev->dev, "spi");
736 + dev_err(&pdev->dev, "No clock for device\n");
741 + master = spi_alloc_master(&pdev->dev, sizeof(struct bcm63xx_spi));
747 + bs = spi_master_get_devdata(master);
748 + bs->bitbang.master = spi_master_get(master);
749 + bs->bitbang.chipselect = bcm63xx_spi_chipselect;
750 + bs->bitbang.setup_transfer = bcm63xx_spi_setup_transfer;
751 + bs->bitbang.txrx_bufs = bcm63xx_txrx_bufs;
752 + bs->bitbang.master->setup = bcm63xx_spi_setup;
753 + init_completion(&bs->done);
755 + platform_set_drvdata(pdev, master);
758 + if (!request_mem_region(r->start,
759 + r->end - r->start, PFX)) {
764 + bs->regs = ioremap_nocache(r->start, r->end - r->start);
766 + printk(KERN_ERR PFX " unable to ioremap regs\n");
772 + bs->fifo_size = pdata->fifo_size;
774 + ret = request_irq(irq, bcm63xx_spi_interrupt, 0,
775 + pdev->name, master);
777 + printk(KERN_ERR PFX " unable to request irq\n");
781 + master->bus_num = pdata->bus_num;
782 + master->num_chipselect = pdata->num_chipselect;
783 + bs->speed_hz = pdata->speed_hz;
785 + /* Initialize hardware */
786 + clk_enable(bs->clk);
787 + bcm_spi_writeb(SPI_INTR_CLEAR_ALL, bs->regs, SPI_INT_MASK);
789 + dev_info(&pdev->dev, " at 0x%08x (irq %d, FIFOs size %d) v%s\n",
790 + r->start, irq, bs->fifo_size, DRV_VER);
792 + ret = spi_bitbang_start(&bs->bitbang);
794 + dev_err(&pdev->dev, "spi_bitbang_start FAILED\n");
802 + free_irq(irq, master);
807 + spi_master_put(master);
812 +static int __exit bcm63xx_spi_remove(struct platform_device *pdev)
814 + struct spi_master *master = platform_get_drvdata(pdev);
815 + struct bcm63xx_spi *bs = spi_master_get_devdata(master);
817 + spi_bitbang_stop(&bs->bitbang);
818 + clk_disable(bs->clk);
820 + free_irq(bs->irq, master);
822 + platform_set_drvdata(pdev, 0);
823 + spi_master_put(bs->bitbang.master);
829 +static int bcm63xx_spi_suspend(struct platform_device *pdev, pm_message_t mesg)
831 + struct spi_master *master = platform_get_drvdata(pdev);
832 + struct bcm63xx_spi *bs = spi_master_get_devdata(master);
834 + clk_disable(bs->clk);
839 +static int bcm63xx_spi_resume(struct platform_device *pdev)
841 + struct bcm63xx_spi *bs = spi_master_get_devdata(master);
842 + struct bcm63xx_spi *bs = spi_master_get_devdata(master);
844 + clk_enable(bs->clk);
849 +#define bcm63xx_spi_suspend NULL
850 +#define bcm63xx_spi_resume NULL
853 +static struct platform_driver bcm63xx_spi_driver = {
855 + .name = "bcm63xx-spi",
856 + .owner = THIS_MODULE,
858 + .probe = bcm63xx_spi_probe,
859 + .remove = bcm63xx_spi_remove,
860 + .suspend = bcm63xx_spi_suspend,
861 + .resume = bcm63xx_spi_resume,
865 +static int __init bcm63xx_spi_init(void)
867 + return platform_driver_register(&bcm63xx_spi_driver);
870 +static void __exit bcm63xx_spi_exit(void)
872 + platform_driver_unregister(&bcm63xx_spi_driver);
875 +module_init(bcm63xx_spi_init);
876 +module_exit(bcm63xx_spi_exit);
878 +MODULE_ALIAS("platform:bcm63xx_spi");
879 +MODULE_AUTHOR("Florian Fainelli <florian@openwrt.org>");
880 +MODULE_DESCRIPTION("Broadcom BCM63xx SPI Controller driver");
881 +MODULE_LICENSE("GPL");
882 +MODULE_VERSION(DRV_VER);
883 --- a/drivers/spi/Kconfig
884 +++ b/drivers/spi/Kconfig
885 @@ -60,6 +60,13 @@ config SPI_ATMEL
886 This selects a driver for the Atmel SPI Controller, present on
887 many AT32 (AVR32) and AT91 (ARM) chips.
890 + tristate "Broadcom BCM63xx SPI controller"
894 + This is the SPI controller master driver for Broadcom BCM63xx SoC.
897 tristate "SPI controller driver for ADI Blackfin5xx"
899 --- a/drivers/spi/Makefile
900 +++ b/drivers/spi/Makefile
901 @@ -48,6 +48,7 @@ obj-$(CONFIG_SPI_SH_SCI) += spi_sh_sci.
902 obj-$(CONFIG_SPI_SH_MSIOF) += spi_sh_msiof.o
903 obj-$(CONFIG_SPI_STMP3XXX) += spi_stmp.o
904 obj-$(CONFIG_SPI_NUC900) += spi_nuc900.o
905 +obj-$(CONFIG_SPI_BCM63XX) += bcm63xx_spi.o
907 # special build for s3c24xx spi driver with fiq support
908 spi_s3c24xx_hw-y := spi_s3c24xx.o
910 +++ b/arch/mips/include/asm/mach-bcm63xx/bcm63xx_dev_spi.h
912 +#ifndef BCM63XX_DEV_SPI_H
913 +#define BCM63XX_DEV_SPI_H
915 +#include <linux/types.h>
917 +int __init bcm63xx_spi_register(void);
919 +struct bcm63xx_spi_pdata {
920 + unsigned int fifo_size;
922 + int num_chipselect;
926 +#endif /* BCM63XX_DEV_SPI_H */
927 --- a/arch/mips/bcm63xx/Makefile
928 +++ b/arch/mips/bcm63xx/Makefile
930 obj-y += clk.o cpu.o cs.o gpio.o irq.o prom.o setup.o timer.o \
931 dev-dsp.o dev-enet.o dev-pcmcia.o dev-uart.o dev-wdt.o \
932 - dev-usb-ohci.o dev-usb-ehci.o dev-usb-udc.o
933 + dev-usb-ohci.o dev-usb-ehci.o dev-usb-udc.o dev-spi.o
934 obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
937 --- a/arch/mips/bcm63xx/boards/board_bcm963xx.c
938 +++ b/arch/mips/bcm63xx/boards/board_bcm963xx.c
940 #include <bcm63xx_dev_usb_ohci.h>
941 #include <bcm63xx_dev_usb_ehci.h>
942 #include <bcm63xx_dev_usb_udc.h>
943 +#include <bcm63xx_dev_spi.h>
944 #include <board_bcm963xx.h>
946 #define PFX "board_bcm963xx: "
947 @@ -1459,6 +1460,9 @@ void __init board_prom_init(void)
949 bcm63xx_udc_register();
951 + if (!BCMCPU_IS_6345())
952 + bcm63xx_spi_register();
954 /* Generate MAC address for WLAN and
955 * register our SPROM */
956 #ifdef CONFIG_SSB_PCIHOST