aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux/brcm63xx/patches-3.3/419-SPI-MIPS-BCM63XX-Add-HS-SPI-driver.patch
blob: 94c9eee6035946fd9db8a95c943614b7cda23680 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
From 2982127b8a0127667cb5354e03987cd3baa84b8c Mon Sep 17 00:00:00 2001
From: Jonas Gorski <jonas.gorski@gmail.com>
Date: Sat, 12 Nov 2011 12:19:55 +0100
Subject: [PATCH 54/79] SPI: MIPS: BCM63XX: Add HS SPI driver

Add a driver for the High Speed SPI controller found on newer BCM63XX SoCs.

Signed-off-by: Jonas Gorski <jonas.gorski@gmail.com>
---
 arch/mips/include/asm/mach-bcm63xx/bcm63xx_cpu.h   |   18 +
 .../include/asm/mach-bcm63xx/bcm63xx_dev_hsspi.h   |    3 +
 arch/mips/include/asm/mach-bcm63xx/bcm63xx_regs.h  |   47 ++
 drivers/spi/Kconfig                                |    7 +
 drivers/spi/Makefile                               |    1 +
 drivers/spi/spi-bcm63xx-hsspi.c                    |  502 ++++++++++++++++++++
 6 files changed, 578 insertions(+)
 create mode 100644 drivers/spi/spi-bcm63xx-hsspi.c

--- a/arch/mips/include/asm/mach-bcm63xx/bcm63xx_cpu.h
+++ b/arch/mips/include/asm/mach-bcm63xx/bcm63xx_cpu.h
@@ -116,6 +116,7 @@ enum bcm63xx_regs_set {
 	RSET_UART1,
 	RSET_GPIO,
 	RSET_SPI,
+	RSET_HSSPI,
 	RSET_UDC0,
 	RSET_OHCI0,
 	RSET_OHCI_PRIV,
@@ -161,6 +162,7 @@ enum bcm63xx_regs_set {
 #define RSET_ENETDMAS_SIZE(chans)	(16 * (chans))
 #define RSET_ENETSW_SIZE		65536
 #define RSET_UART_SIZE			24
+#define RSET_HSSPI_SIZE			2048
 #define RSET_UDC_SIZE			256
 #define RSET_OHCI_SIZE			256
 #define RSET_EHCI_SIZE			256
@@ -184,6 +186,7 @@ enum bcm63xx_regs_set {
 #define BCM_6328_UART1_BASE		(0xb0000120)
 #define BCM_6328_GPIO_BASE		(0xb0000080)
 #define BCM_6328_SPI_BASE		(0xdeadbeef)
+#define BCM_6328_HSSPI_BASE		(0xb0001000)
 #define BCM_6328_UDC0_BASE		(0xdeadbeef)
 #define BCM_6328_USBDMA_BASE		(0xdeadbeef)
 #define BCM_6328_OHCI0_BASE		(0xdeadbeef)
@@ -229,6 +232,7 @@ enum bcm63xx_regs_set {
 #define BCM_6338_UART1_BASE		(0xdeadbeef)
 #define BCM_6338_GPIO_BASE		(0xfffe0400)
 #define BCM_6338_SPI_BASE		(0xfffe0c00)
+#define BCM_6338_HSSPI_BASE		(0xdeadbeef)
 #define BCM_6338_UDC0_BASE		(0xdeadbeef)
 #define BCM_6338_USBDMA_BASE		(0xfffe2400)
 #define BCM_6338_OHCI0_BASE		(0xdeadbeef)
@@ -275,6 +279,7 @@ enum bcm63xx_regs_set {
 #define BCM_6345_UART1_BASE		(0xdeadbeef)
 #define BCM_6345_GPIO_BASE		(0xfffe0400)
 #define BCM_6345_SPI_BASE		(0xdeadbeef)
+#define BCM_6345_HSSPI_BASE		(0xdeadbeef)
 #define BCM_6345_UDC0_BASE		(0xdeadbeef)
 #define BCM_6345_USBDMA_BASE		(0xfffe2800)
 #define BCM_6345_ENET0_BASE		(0xfffe1800)
@@ -320,6 +325,7 @@ enum bcm63xx_regs_set {
 #define BCM_6348_UART1_BASE		(0xdeadbeef)
 #define BCM_6348_GPIO_BASE		(0xfffe0400)
 #define BCM_6348_SPI_BASE		(0xfffe0c00)
+#define BCM_6348_HSSPI_BASE		(0xdeadbeef)
 #define BCM_6348_UDC0_BASE		(0xfffe1000)
 #define BCM_6348_OHCI0_BASE		(0xfffe1b00)
 #define BCM_6348_OHCI_PRIV_BASE		(0xfffe1c00)
@@ -363,6 +369,7 @@ enum bcm63xx_regs_set {
 #define BCM_6358_UART1_BASE		(0xfffe0120)
 #define BCM_6358_GPIO_BASE		(0xfffe0080)
 #define BCM_6358_SPI_BASE		(0xfffe0800)
+#define BCM_6358_HSSPI_BASE		(0xdeadbeef)
 #define BCM_6358_UDC0_BASE		(0xfffe0800)
 #define BCM_6358_OHCI0_BASE		(0xfffe1400)
 #define BCM_6358_OHCI_PRIV_BASE		(0xdeadbeef)
@@ -407,6 +414,7 @@ enum bcm63xx_regs_set {
 #define BCM_6368_UART1_BASE		(0xb0000120)
 #define BCM_6368_GPIO_BASE		(0xb0000080)
 #define BCM_6368_SPI_BASE		(0xb0000800)
+#define BCM_6368_HSSPI_BASE		(0xdeadbeef)
 #define BCM_6368_UDC0_BASE		(0xdeadbeef)
 #define BCM_6368_OHCI0_BASE		(0xb0001600)
 #define BCM_6368_OHCI_PRIV_BASE		(0xdeadbeef)
@@ -456,6 +464,7 @@ extern const unsigned long *bcm63xx_regs
 	__GEN_RSET_BASE(__cpu, UART1)					\
 	__GEN_RSET_BASE(__cpu, GPIO)					\
 	__GEN_RSET_BASE(__cpu, SPI)					\
+	__GEN_RSET_BASE(__cpu, HSSPI)					\
 	__GEN_RSET_BASE(__cpu, UDC0)					\
 	__GEN_RSET_BASE(__cpu, OHCI0)					\
 	__GEN_RSET_BASE(__cpu, OHCI_PRIV)				\
@@ -497,6 +506,7 @@ extern const unsigned long *bcm63xx_regs
 	[RSET_UART1]		= BCM_## __cpu ##_UART1_BASE,		\
 	[RSET_GPIO]		= BCM_## __cpu ##_GPIO_BASE,		\
 	[RSET_SPI]		= BCM_## __cpu ##_SPI_BASE,		\
+	[RSET_HSSPI]		= BCM_## __cpu ##_HSSPI_BASE,		\
 	[RSET_UDC0]		= BCM_## __cpu ##_UDC0_BASE,		\
 	[RSET_OHCI0]		= BCM_## __cpu ##_OHCI0_BASE,		\
 	[RSET_OHCI_PRIV]	= BCM_## __cpu ##_OHCI_PRIV_BASE,	\
@@ -569,6 +579,7 @@ enum bcm63xx_irq {
 	IRQ_ENET0,
 	IRQ_ENET1,
 	IRQ_ENET_PHY,
+	IRQ_HSSPI,
 	IRQ_OHCI0,
 	IRQ_EHCI0,
 	IRQ_ENET0_RXDMA,
@@ -604,6 +615,7 @@ enum bcm63xx_irq {
 #define BCM_6328_ENET0_IRQ		0
 #define BCM_6328_ENET1_IRQ		0
 #define BCM_6328_ENET_PHY_IRQ		(IRQ_INTERNAL_BASE + 12)
+#define BCM_6328_HSSPI_IRQ		(IRQ_INTERNAL_BASE + 29)
 #define BCM_6328_OHCI0_IRQ		(IRQ_INTERNAL_BASE + 9)
 #define BCM_6328_EHCI0_IRQ		(IRQ_INTERNAL_BASE + 10)
 #define BCM_6328_PCMCIA_IRQ		0
@@ -642,6 +654,7 @@ enum bcm63xx_irq {
 #define BCM_6338_ENET0_IRQ		(IRQ_INTERNAL_BASE + 8)
 #define BCM_6338_ENET1_IRQ		0
 #define BCM_6338_ENET_PHY_IRQ		(IRQ_INTERNAL_BASE + 9)
+#define BCM_6338_HSSPI_IRQ		0
 #define BCM_6338_OHCI0_IRQ		0
 #define BCM_6338_EHCI0_IRQ		0
 #define BCM_6338_ENET0_RXDMA_IRQ	(IRQ_INTERNAL_BASE + 15)
@@ -673,6 +686,7 @@ enum bcm63xx_irq {
 #define BCM_6345_ENET0_IRQ		(IRQ_INTERNAL_BASE + 8)
 #define BCM_6345_ENET1_IRQ		0
 #define BCM_6345_ENET_PHY_IRQ		(IRQ_INTERNAL_BASE + 12)
+#define BCM_6345_HSSPI_IRQ		0
 #define BCM_6345_OHCI0_IRQ		0
 #define BCM_6345_EHCI0_IRQ		0
 #define BCM_6345_ENET0_RXDMA_IRQ	(IRQ_INTERNAL_BASE + 13 + 1)
@@ -704,6 +718,7 @@ enum bcm63xx_irq {
 #define BCM_6348_ENET0_IRQ		(IRQ_INTERNAL_BASE + 8)
 #define BCM_6348_ENET1_IRQ		(IRQ_INTERNAL_BASE + 7)
 #define BCM_6348_ENET_PHY_IRQ		(IRQ_INTERNAL_BASE + 9)
+#define BCM_6348_HSSPI_IRQ		0
 #define BCM_6348_OHCI0_IRQ		(IRQ_INTERNAL_BASE + 12)
 #define BCM_6348_EHCI0_IRQ		0
 #define BCM_6348_ENET0_RXDMA_IRQ	(IRQ_INTERNAL_BASE + 20)
@@ -735,6 +750,7 @@ enum bcm63xx_irq {
 #define BCM_6358_ENET0_IRQ		(IRQ_INTERNAL_BASE + 8)
 #define BCM_6358_ENET1_IRQ		(IRQ_INTERNAL_BASE + 6)
 #define BCM_6358_ENET_PHY_IRQ		(IRQ_INTERNAL_BASE + 9)
+#define BCM_6358_HSSPI_IRQ		0
 #define BCM_6358_OHCI0_IRQ		(IRQ_INTERNAL_BASE + 5)
 #define BCM_6358_EHCI0_IRQ		(IRQ_INTERNAL_BASE + 10)
 #define BCM_6358_ENET0_RXDMA_IRQ	(IRQ_INTERNAL_BASE + 15)
@@ -775,6 +791,7 @@ enum bcm63xx_irq {
 #define BCM_6368_ENET0_IRQ		0
 #define BCM_6368_ENET1_IRQ		0
 #define BCM_6368_ENET_PHY_IRQ		(IRQ_INTERNAL_BASE + 15)
+#define BCM_6368_HSSPI_IRQ		0
 #define BCM_6368_OHCI0_IRQ		(IRQ_INTERNAL_BASE + 5)
 #define BCM_6368_EHCI0_IRQ		(IRQ_INTERNAL_BASE + 7)
 #define BCM_6368_PCMCIA_IRQ		0
@@ -815,6 +832,7 @@ extern const int *bcm63xx_irqs;
 	[IRQ_ENET0]		= BCM_## __cpu ##_ENET0_IRQ,		\
 	[IRQ_ENET1]		= BCM_## __cpu ##_ENET1_IRQ,		\
 	[IRQ_ENET_PHY]		= BCM_## __cpu ##_ENET_PHY_IRQ,		\
+	[IRQ_HSSPI]		= BCM_## __cpu ##_HSSPI_IRQ,		\
 	[IRQ_OHCI0]		= BCM_## __cpu ##_OHCI0_IRQ,		\
 	[IRQ_EHCI0]		= BCM_## __cpu ##_EHCI0_IRQ,		\
 	[IRQ_ENET0_RXDMA]	= BCM_## __cpu ##_ENET0_RXDMA_IRQ,	\
--- a/arch/mips/include/asm/mach-bcm63xx/bcm63xx_dev_hsspi.h
+++ b/arch/mips/include/asm/mach-bcm63xx/bcm63xx_dev_hsspi.h
@@ -23,4 +23,7 @@ struct bcm63xx_hsspi_pdata {
 #define HSSPI_OP_WRITE		(2 << HSSPI_OP_CODE_SHIFT)
 #define HSSPI_OP_READ		(3 << HSSPI_OP_CODE_SHIFT)
 
+#define HS_SPI_CLOCK_DEF    40000000
+#define HS_SPI_BUFFER_LEN   512
+
 #endif /* BCM63XX_DEV_HSSPI_H */
--- a/arch/mips/include/asm/mach-bcm63xx/bcm63xx_regs.h
+++ b/arch/mips/include/asm/mach-bcm63xx/bcm63xx_regs.h
@@ -1276,4 +1276,51 @@
 
 #define PCIE_DEVICE_OFFSET		0x8000
 
+/*************************************************************************
+ * _REG relative to RSET_HSSPI
+ *************************************************************************/
+
+#define HSSPI_GLOBAL_CTRL_REG			0x0
+#define GLOBAL_CTRL_CLK_POLARITY		BIT(17)
+#define GLOBAL_CTRL_CLK_GATE_SSOFF		BIT(16)
+
+#define HSSPI_GLOBAL_EXT_TRIGGER_REG		0x4
+
+#define HSSPI_INT_STATUS_REG			0x8
+#define HSSPI_INT_STATUS_MASKED_REG		0xc
+#define HSSPI_INT_MASK_REG			0x10
+
+#define HSSPI_PING0_CMD_DONE			BIT(0)
+
+#define HSSPI_INT_CLEAR_ALL			0xff001f1f
+
+#define HSSPI_PINGPONG_COMMAND_REG(x)		(0x80 + (x) * 0x40)
+#define PINGPONG_CMD_COMMAND_MASK		0xf
+#define PINGPONG_COMMAND_NOOP			0
+#define PINGPONG_COMMAND_START_NOW		1
+#define PINGPONG_COMMAND_START_TRIGGER		2
+#define PINGPONG_COMMAND_HALT			3
+#define PINGPONG_COMMAND_FLUSH			4
+#define PINGPONG_CMD_PROFILE_SHIFT		8
+#define PINGPONG_CMD_SS_SHIFT			12
+
+#define HSSPI_PINGPONG_STATUS_REG(x)		(0x84 + (x) * 0x40)
+
+#define HSSPI_PROFILE_CLK_CTRL_REG(x)		(0x100 + (x) * 0x20)
+#define CLK_CTRL_ACCUM_RST_ON_LOOP		BIT(15)
+
+#define HSSPI_PROFILE_SIGNAL_CTRL_REG(x)	(0x104 + (x) * 0x20)
+#define SIGNAL_CTRL_LATCH_RISING		BIT(12)
+#define SIGNAL_CTRL_LAUNCH_RISING		BIT(13)
+#define SIGNAL_CTRL_ASYNC_INPUT_PATH		BIT(16)
+
+#define HSSPI_PROFILE_MODE_CTRL_REG(x)		(0x108 + (x) * 0x20)
+#define MODE_CTRL_MULTIDATA_RD_STRT_SHIFT	8
+#define MODE_CTRL_MULTIDATA_WR_STRT_SHIFT	12
+#define MODE_CTRL_MULTIDATA_RD_SIZE_SHIFT	16
+#define MODE_CTRL_MULTIDATA_WR_SIZE_SHIFT	18
+#define MODE_CTRL_PREPENDBYTE_CNT_SHIFT		24
+
+#define HSSPI_FIFO_REG(x)			(0x200 + (x) * 0x200)
+
 #endif /* BCM63XX_REGS_H_ */
--- a/drivers/spi/Kconfig
+++ b/drivers/spi/Kconfig
@@ -100,6 +100,13 @@ config SPI_BCM63XX
 	help
           Enable support for the SPI controller on the Broadcom BCM63xx SoCs.
 
+config SPI_BCM63XX_HSSPI
+	tristate "Broadcom BCM63XX HS SPI controller driver"
+	depends on BCM63XX
+	help
+	  This enables support for the High Speed SPI controller present on
+	  newer Broadcom BCM63XX SoCs.
+
 config SPI_BITBANG
 	tristate "Utilities for Bitbanging SPI masters"
 	help
--- a/drivers/spi/Makefile
+++ b/drivers/spi/Makefile
@@ -15,6 +15,7 @@ obj-$(CONFIG_SPI_ATMEL)			+= spi-atmel.o
 obj-$(CONFIG_SPI_ATH79)			+= spi-ath79.o
 obj-$(CONFIG_SPI_AU1550)		+= spi-au1550.o
 obj-$(CONFIG_SPI_BCM63XX)		+= spi-bcm63xx.o
+obj-$(CONFIG_SPI_BCM63XX_HSSPI)		+= spi-bcm63xx-hsspi.o
 obj-$(CONFIG_SPI_BFIN)			+= spi-bfin5xx.o
 obj-$(CONFIG_SPI_BFIN_SPORT)		+= spi-bfin-sport.o
 obj-$(CONFIG_SPI_BITBANG)		+= spi-bitbang.o
--- /dev/null
+++ b/drivers/spi/spi-bcm63xx-hsspi.c
@@ -0,0 +1,502 @@
+/*
+ * Broadcom BCM63XX High Speed SPI Controller driver
+ *
+ * Copyright 2000-2010 Broadcom Corporation
+ * Copyright 2011 Jonas Gorski <jonas.gorski@gmail.com>
+ *
+ * Licensed under the GNU/GPL. See COPYING for details.
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/clk.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/delay.h>
+#include <linux/dma-mapping.h>
+#include <linux/err.h>
+#include <linux/interrupt.h>
+#include <linux/spi/spi.h>
+#include <linux/workqueue.h>
+
+#include <bcm63xx_regs.h>
+#include <bcm63xx_dev_hsspi.h>
+
+
+#define PFX		KBUILD_MODNAME
+
+struct bcm63xx_hsspi {
+	spinlock_t		lock;
+	int			irq;
+	u8			stopping;
+
+	struct list_head	queue;
+	struct workqueue_struct	*workqueue;
+	struct work_struct	ws;
+	struct completion	done;
+
+	struct spi_transfer	*curr_trans;
+
+	struct platform_device  *pdev;
+	void __iomem		*regs;
+	struct clk		*clk;
+
+	/* Platform data */
+	u32			speed_hz;
+
+	/* data iomem */
+	u8 __iomem		*fifo;
+
+
+};
+
+static void bcm63xx_hsspi_set_clk(struct bcm63xx_hsspi *bs, int hz,
+				  int profile)
+{
+	int clock;
+
+	clock = bs->speed_hz / hz;
+	if (bs->speed_hz % HS_SPI_CLOCK_DEF)
+		clock++;
+
+	clock = 2048 / clock;
+	if (2048 % clock)
+		clock++;
+
+	bcm_hsspi_writel(CLK_CTRL_ACCUM_RST_ON_LOOP | clock,
+			 HSSPI_PROFILE_CLK_CTRL_REG(profile));
+}
+
+static int bcm63xx_hsspi_do_txrx(struct spi_device *spi,
+				 struct spi_transfer *t1,
+				 struct spi_transfer *t2)
+{
+	struct bcm63xx_hsspi *bs = spi_master_get_devdata(spi->master);
+	u8 chip_select = spi->chip_select;
+	u16 opcode = 0;
+	int prepend_size = 0;
+
+	init_completion(&bs->done);
+	bs->curr_trans = t2 ? t2 : t1;
+	bcm63xx_hsspi_set_clk(bs, bs->curr_trans->speed_hz, chip_select);
+
+	BUG_ON(t2 && !t1->tx_buf && t1->rx_buf && t2->tx_buf && !t2->rx_buf);
+
+	if (t2 && !t2->tx_buf)
+		prepend_size = t1->len;
+
+	bcm_hsspi_writel(prepend_size<<MODE_CTRL_PREPENDBYTE_CNT_SHIFT |
+			 2<<MODE_CTRL_MULTIDATA_WR_STRT_SHIFT |
+			 2<<MODE_CTRL_MULTIDATA_RD_STRT_SHIFT | 0xff,
+			 HSSPI_PROFILE_MODE_CTRL_REG(chip_select));
+
+	if (t1->rx_buf && t1->tx_buf)
+		opcode = HSSPI_OP_READ_WRITE;
+	else if (t1->rx_buf || (t2 && t2->rx_buf))
+		opcode = HSSPI_OP_READ;
+	else if (t1->tx_buf)
+		opcode = HSSPI_OP_WRITE;
+
+	BUG_ON(opcode == 0);
+
+	if (opcode == HSSPI_OP_READ && t2)
+		opcode |= t2->len;
+	else
+		opcode |= t1->len;
+
+	if (t1->tx_buf) {
+		memcpy_toio(bs->fifo + 2, t1->tx_buf, t1->len);
+		if (t2 && t2->tx_buf) {
+			memcpy_toio(bs->fifo + 2 + t1->len,
+				    t2->tx_buf, t2->len);
+			opcode += t2->len;
+		}
+	}
+
+	memcpy_toio(bs->fifo, &opcode, sizeof(opcode));
+
+	/* enable interrupt */
+	bcm_hsspi_writel(HSSPI_PING0_CMD_DONE, HSSPI_INT_MASK_REG);
+
+	/* start the transfer */
+	bcm_hsspi_writel(chip_select << PINGPONG_CMD_SS_SHIFT |
+			 chip_select << PINGPONG_CMD_PROFILE_SHIFT |
+			 PINGPONG_COMMAND_START_NOW,
+			 HSSPI_PINGPONG_COMMAND_REG(0));
+
+	wait_for_completion(&bs->done);
+	return t1->len + (t2 ? t2->len : 0);
+}
+static int bcm63xx_hsspi_setup(struct spi_device *spi)
+{
+	struct bcm63xx_hsspi *bs;
+	u32 reg;
+	bs = spi_master_get_devdata(spi->master);
+
+	if (bs->stopping)
+		return -ESHUTDOWN;
+
+	if (!spi->bits_per_word)
+		spi->bits_per_word = 8;
+
+	if (spi->bits_per_word != 8)
+		return -EINVAL;
+
+	if (spi->max_speed_hz == 0)
+		return -EINVAL;
+
+	reg = bcm_hsspi_readl(HSSPI_PROFILE_SIGNAL_CTRL_REG(spi->chip_select));
+	reg &= ~(SIGNAL_CTRL_LAUNCH_RISING | SIGNAL_CTRL_LATCH_RISING);
+
+	if (spi->mode & SPI_CPHA)
+		reg |= SIGNAL_CTRL_LAUNCH_RISING;
+	else
+		reg |= SIGNAL_CTRL_LATCH_RISING;
+
+	bcm_hsspi_writel(reg, HSSPI_PROFILE_SIGNAL_CTRL_REG(spi->chip_select));
+
+	return 0;
+}
+
+
+static int bcm63xx_hsspi_transfer(struct spi_device *spi,
+				  struct spi_message *msg)
+{
+	struct bcm63xx_hsspi *bs = spi_master_get_devdata(spi->master);
+	struct spi_transfer *t, *prev = NULL;
+
+	if (unlikely(list_empty(&msg->transfers)))
+		return -EINVAL;
+
+	if (bs->stopping)
+		return -ESHUTDOWN;
+
+	list_for_each_entry(t, &msg->transfers, transfer_list)	{
+		/* check transfer parameters */
+		if (!t->tx_buf && !t->rx_buf)
+			return -EINVAL;
+
+		if (t->speed_hz == 0)
+			t->speed_hz = spi->max_speed_hz;
+
+		if (t->speed_hz > spi->max_speed_hz)
+			return -EINVAL;
+
+		if (t->len > HS_SPI_BUFFER_LEN)
+			return -EINVAL;
+
+		/* reject if we have to combine two tx transfers and their
+		 * combined length is bigger than the buffer
+		 */
+		if (prev && !prev->cs_change && !t->cs_change && prev->tx_buf &&
+		    t->tx_buf && (prev->len + t->len) > HS_SPI_BUFFER_LEN)
+			return -EINVAL;
+
+		prev = t;
+	}
+
+
+	msg->actual_length = 0;
+
+#if 0
+	/* disable interrupts for the SPI controller
+	   using spin_lock_irqsave would disable all interrupts */
+	bcm_hsspi_writel(0, HSSPI_INT_MASK_REG);
+#endif
+	spin_lock(&bs->lock);
+	list_add_tail(&msg->queue, &bs->queue);
+	queue_work(bs->workqueue, &bs->ws);
+	spin_unlock(&bs->lock);
+
+#if 0
+	bcm_hsspi_writel(HSSPI_PING0_CMD_DONE, HSSPI_INT_MASK_REG);
+#endif
+	return 0;
+}
+
+static void bcm63xx_hsspi_do_work(struct work_struct *work)
+{
+	struct bcm63xx_hsspi *bs = container_of(work, struct bcm63xx_hsspi,
+						ws);
+	struct spi_message *msg;
+	struct spi_transfer *prev = NULL;
+	struct spi_transfer *t;
+	u32 reg;
+
+	int len = 0;
+
+	spin_lock(&bs->lock);
+	msg = list_entry(bs->queue.next, struct spi_message, queue);
+	list_del(&msg->queue);
+	spin_unlock(&bs->lock);
+
+	if (bs->stopping) {
+		msg->status = -ESHUTDOWN;
+		goto out;
+	}
+
+	/* setup clock polarity */
+	reg = bcm_hsspi_readl(HSSPI_GLOBAL_CTRL_REG);
+	reg &= ~GLOBAL_CTRL_CLK_POLARITY;
+
+	if (msg->spi->mode & SPI_CPOL)
+		reg |= GLOBAL_CTRL_CLK_POLARITY;
+
+	bcm_hsspi_writel(reg, HSSPI_GLOBAL_CTRL_REG);
+
+	list_for_each_entry(t, &msg->transfers, transfer_list) {
+		/*
+		 * This controller does not support keeping the chip select
+		 * active between transfers.
+		 * This logic currently supports combining:
+		 *  write then read with no cs_change (e.g. m25p80 RDSR)
+		 *  write then write with no cs_change (e.g. m25p80 PP)
+		 */
+		if (prev && prev->tx_buf && !prev->cs_change && !t->cs_change) {
+			/* combine write with following transfer */
+			len += bcm63xx_hsspi_do_txrx(msg->spi, prev, t);
+			prev = NULL;
+			continue;
+		}
+
+		/* write the previous pending transfer */
+		if (prev != NULL)
+			len += bcm63xx_hsspi_do_txrx(msg->spi, prev, NULL);
+
+		prev = t;
+	}
+
+	/* do last pending transfer */
+	if (prev != NULL)
+		len += bcm63xx_hsspi_do_txrx(msg->spi, prev, NULL);
+
+	msg->status = 0;
+	msg->actual_length = len;
+out:
+	msg->complete(msg->context);
+}
+
+static irqreturn_t bcm63xx_hsspi_interrupt(int irq, void *dev_id)
+{
+	struct spi_master *master = (struct spi_master *)dev_id;
+	struct bcm63xx_hsspi *bs = spi_master_get_devdata(master);
+
+	if (bcm_hsspi_readl(HSSPI_INT_STATUS_MASKED_REG) == 0)
+		return IRQ_NONE;
+
+	bcm_hsspi_writel(HSSPI_INT_CLEAR_ALL, HSSPI_INT_STATUS_REG);
+	bcm_hsspi_writel(0, HSSPI_INT_MASK_REG);
+
+	spin_lock(&bs->lock);
+
+	if (bs->curr_trans && bs->curr_trans->rx_buf)
+		memcpy_fromio(bs->curr_trans->rx_buf,  bs->fifo,
+			      bs->curr_trans->len);
+
+	complete(&bs->done);
+	spin_unlock(&bs->lock);
+
+	return IRQ_HANDLED;
+}
+
+
+static void bcm63xx_hsspi_cleanup(struct spi_device *spi)
+{
+	/* would free spi_controller memory here if any was allocated */
+}
+
+static int __devinit bcm63xx_hsspi_probe(struct platform_device *pdev)
+{
+
+	struct spi_master *master;
+	struct bcm63xx_hsspi *bs;
+	struct resource *res_mem;
+	struct device *dev = &pdev->dev;
+	struct bcm63xx_hsspi_pdata *pdata = pdev->dev.platform_data;
+	struct clk *clk;
+	int irq;
+	int ret;
+
+	res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res_mem) {
+		dev_err(dev, "no iomem\n");
+		return -ENXIO;
+	}
+
+	irq = platform_get_irq(pdev, 0);
+	if (irq < 0) {
+		dev_err(dev, "no irq\n");
+		return -ENXIO;
+	}
+
+	clk = clk_get(dev, "hsspi");
+
+	if (IS_ERR(clk)) {
+		ret = PTR_ERR(clk);
+		goto out_release;
+	}
+	clk_enable(clk);
+
+	master = spi_alloc_master(&pdev->dev, sizeof(*bs));
+	if (!master) {
+		ret = -ENOMEM;
+		goto out_disable_clk;
+	}
+
+	bs = spi_master_get_devdata(master);
+	init_completion(&bs->done);
+	bs->pdev = pdev;
+	bs->clk = clk;
+
+	bs->regs = devm_request_and_ioremap(dev, res_mem);
+	if (!bs->regs) {
+		dev_err(dev, "unable to ioremap regs\n");
+		ret = -ENOMEM;
+		goto out_put_master;
+	}
+
+	master->bus_num        = pdata->bus_num;
+	master->num_chipselect = 8;
+	master->setup          = bcm63xx_hsspi_setup;
+	master->transfer       = bcm63xx_hsspi_transfer;
+	master->cleanup        = bcm63xx_hsspi_cleanup;
+	master->mode_bits      = SPI_CPOL | SPI_CPHA;
+
+	bs->speed_hz = pdata->speed_hz;
+	bs->fifo = (u8 *)(bs->regs + HSSPI_FIFO_REG(0));
+
+	platform_set_drvdata(pdev, master);
+
+	spin_lock_init(&bs->lock);
+	INIT_LIST_HEAD(&bs->queue);
+	INIT_WORK(&bs->ws, bcm63xx_hsspi_do_work);
+	bs->workqueue = create_singlethread_workqueue(pdev->name);
+	bs->curr_trans = NULL;
+
+	/* Initialize the hardware */
+	bcm_hsspi_writel(0, HSSPI_INT_MASK_REG);
+
+	bcm_hsspi_writel(bcm_hsspi_readl(HSSPI_GLOBAL_CTRL_REG) |
+			 GLOBAL_CTRL_CLK_GATE_SSOFF,
+			 HSSPI_GLOBAL_CTRL_REG);
+
+	ret = request_irq(irq, bcm63xx_hsspi_interrupt, IRQF_SHARED, pdev->name,
+			  master);
+
+	if (ret)
+		goto out_destroy_workqueue;
+
+	spin_lock(&bs->lock);
+	bs->irq = irq;
+	spin_unlock(&bs->lock);
+
+	/* register and we are done */
+	ret = spi_register_master(master);
+	if (ret)
+		goto out_free_irq;
+
+	return 0;
+
+out_free_irq:
+	free_irq(bs->irq, master);
+out_destroy_workqueue:
+	flush_workqueue(bs->workqueue);
+	destroy_workqueue(bs->workqueue);
+	iounmap(bs->regs);
+out_put_master:
+	spi_master_put(master);
+out_disable_clk:
+	clk_disable(clk);
+	clk_put(clk);
+out_release:
+	release_mem_region(res_mem->start, resource_size(res_mem));
+
+	return ret;
+}
+
+
+static int __exit bcm63xx_hsspi_remove(struct platform_device *pdev)
+{
+	struct spi_master *master = platform_get_drvdata(pdev);
+	struct bcm63xx_hsspi *bs = spi_master_get_devdata(master);
+	struct spi_message *msg;
+
+	cancel_work_sync(&bs->ws);
+
+	/* reset the hardware and block queue progress */
+	bcm_hsspi_writel(0, HSSPI_INT_MASK_REG);
+
+	spin_lock(&bs->lock);
+	/* HW shutdown */
+	bs->stopping = 1;
+	spin_unlock(&bs->lock);
+
+
+	/* Terminate remaining queued transfers */
+	list_for_each_entry(msg, &bs->queue, queue) {
+		msg->status = -ESHUTDOWN;
+		msg->complete(msg->context);
+	}
+
+
+	free_irq(bs->irq, master);
+	flush_workqueue(bs->workqueue);
+	destroy_workqueue(bs->workqueue);
+
+	clk_disable(bs->clk);
+	clk_put(bs->clk);
+
+	spi_unregister_master(master);
+	return 0;
+}
+
+#ifdef CONFIG_PM
+static int bcm63xx_hsspi_suspend(struct platform_device *pdev,
+				 pm_message_t mesg)
+{
+	struct spi_master	*master = platform_get_drvdata(pdev);
+	struct bcm63xx_hsspi	*bs = spi_master_get_devdata(master);
+
+	clk_disable(bs->clk);
+
+	return 0;
+}
+
+static int bcm63xx_hsspi_resume(struct platform_device *pdev)
+{
+	struct spi_master	*master = platform_get_drvdata(pdev);
+	struct bcm63xx_hsspi	*bs = spi_master_get_devdata(master);
+
+	clk_enable(bs->clk);
+
+	return 0;
+}
+
+static const struct dev_pm_ops bcm63xx_hsspi_pm_ops = {
+	.suspend	= bcm63xx_hsspi_suspend,
+	.resume		= bcm63xx_hsspi_resume,
+};
+
+#define BCM63XX_HSSPI_PM_OPS	(&bcm63xx_hsspi_pm_ops)
+#else
+#define BCM63XX_HSSPI_PM_OPS	NULL
+#endif
+
+
+
+static struct platform_driver bcm63xx_hsspi_driver = {
+	.driver = {
+		.name	= "bcm63xx-hsspi",
+		.owner	= THIS_MODULE,
+		.pm	= BCM63XX_HSSPI_PM_OPS,
+	},
+	.probe		= bcm63xx_hsspi_probe,
+	.remove		= __exit_p(bcm63xx_hsspi_remove),
+};
+
+module_platform_driver(bcm63xx_hsspi_driver);
+
+MODULE_ALIAS("platform:bcm63xx_hsspi");
+MODULE_DESCRIPTION("Broadcom BCM63xx HS SPI Controller driver");
+MODULE_AUTHOR("Jonas Gorski <jonas.gorski@gmail.com>");
+MODULE_LICENSE("GPL");