bcm63xx: add support for the HSSPI controller
[openwrt/openwrt.git] / target / linux / brcm63xx / patches-3.3 / 418-MIPS-BCM63XX-add-HS-SPI-platform-device-and-register.patch
1 From a2b75f344cdc0f9e12c7909511d95b27be72c6b9 Mon Sep 17 00:00:00 2001
2 From: Jonas Gorski <jonas.gorski@gmail.com>
3 Date: Sat, 12 Nov 2011 12:18:26 +0100
4 Subject: [PATCH 52/79] MIPS: BCM63XX: add HS SPI platform device and register
5 it
6
7 Signed-off-by: Jonas Gorski <jonas.gorski@gmail.com>
8 ---
9 arch/mips/bcm63xx/Makefile | 5 +-
10 arch/mips/bcm63xx/boards/board_bcm963xx.c | 2 +
11 arch/mips/bcm63xx/dev-hsspi.c | 58 ++++++++++++++++++++
12 .../include/asm/mach-bcm63xx/bcm63xx_dev_hsspi.h | 26 +++++++++
13 4 files changed, 89 insertions(+), 2 deletions(-)
14 create mode 100644 arch/mips/bcm63xx/dev-hsspi.c
15 create mode 100644 arch/mips/include/asm/mach-bcm63xx/bcm63xx_dev_hsspi.h
16
17 --- a/arch/mips/bcm63xx/Makefile
18 +++ b/arch/mips/bcm63xx/Makefile
19 @@ -1,6 +1,7 @@
20 obj-y += clk.o cpu.o cs.o gpio.o irq.o prom.o setup.o timer.o \
21 - dev-dsp.o dev-enet.o dev-flash.o dev-pcmcia.o dev-spi.o \
22 - dev-trng.o dev-uart.o dev-usb-ehci.o dev-usb-ohci.o dev-wdt.o
23 + dev-dsp.o dev-enet.o dev-flash.o dev-hsspi.o dev-pcmcia.o \
24 + dev-spi.o dev-trng.o dev-uart.o dev-usb-ehci.o \
25 + dev-usb-ohci.o dev-wdt.o
26 obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
27
28 obj-y += boards/
29 --- a/arch/mips/bcm63xx/boards/board_bcm963xx.c
30 +++ b/arch/mips/bcm63xx/boards/board_bcm963xx.c
31 @@ -24,6 +24,7 @@
32 #include <bcm63xx_dev_enet.h>
33 #include <bcm63xx_dev_dsp.h>
34 #include <bcm63xx_dev_flash.h>
35 +#include <bcm63xx_dev_hsspi.h>
36 #include <bcm63xx_dev_pcmcia.h>
37 #include <bcm63xx_dev_spi.h>
38 #include <bcm63xx_dev_usb_ohci.h>
39 @@ -940,6 +941,7 @@ int __init board_register_devices(void)
40 pr_err(PFX "failed to register fallback SPROM\n");
41 }
42 #endif
43 + bcm63xx_hsspi_register();
44
45 bcm63xx_spi_register();
46
47 --- /dev/null
48 +++ b/arch/mips/bcm63xx/dev-hsspi.c
49 @@ -0,0 +1,58 @@
50 +/*
51 + * This file is subject to the terms and conditions of the GNU General Public
52 + * License. See the file "COPYING" in the main directory of this archive
53 + * for more details.
54 + *
55 + * Copyright (C) 2009 Florian Fainelli <florian@openwrt.org>
56 + * Copyright (C) 2010 Tanguy Bouzeloc <tanguy.bouzeloc@efixo.com>
57 + */
58 +
59 +#include <linux/init.h>
60 +#include <linux/kernel.h>
61 +#include <linux/platform_device.h>
62 +
63 +#include <bcm63xx_cpu.h>
64 +#include <bcm63xx_dev_hsspi.h>
65 +#include <bcm63xx_regs.h>
66 +
67 +static struct resource spi_resources[] = {
68 + {
69 + .start = -1, /* filled at runtime */
70 + .end = -1, /* filled at runtime */
71 + .flags = IORESOURCE_MEM,
72 + },
73 + {
74 + .start = -1, /* filled at runtime */
75 + .flags = IORESOURCE_IRQ,
76 + },
77 +};
78 +
79 +static struct bcm63xx_hsspi_pdata spi_pdata = {
80 + .bus_num = 0,
81 +};
82 +
83 +static struct platform_device bcm63xx_hsspi_device = {
84 + .name = "bcm63xx-hsspi",
85 + .id = 0,
86 + .num_resources = ARRAY_SIZE(spi_resources),
87 + .resource = spi_resources,
88 + .dev = {
89 + .platform_data = &spi_pdata,
90 + },
91 +};
92 +
93 +int __init bcm63xx_hsspi_register(void)
94 +{
95 +
96 + if (!BCMCPU_IS_6328())
97 + return -ENODEV;
98 +
99 + spi_resources[0].start = bcm63xx_regset_address(RSET_HSSPI);
100 + spi_resources[0].end = spi_resources[0].start;
101 + spi_resources[0].end += RSET_HSSPI_SIZE - 1;
102 + spi_resources[1].start = bcm63xx_get_irq_number(IRQ_HSSPI);
103 +
104 + spi_pdata.speed_hz = HSSPI_PLL_HZ_6328;
105 +
106 + return platform_device_register(&bcm63xx_hsspi_device);
107 +}
108 --- /dev/null
109 +++ b/arch/mips/include/asm/mach-bcm63xx/bcm63xx_dev_hsspi.h
110 @@ -0,0 +1,26 @@
111 +#ifndef BCM63XX_DEV_HSSPI_H
112 +#define BCM63XX_DEV_HSSPI_H
113 +
114 +#include <linux/types.h>
115 +#include <bcm63xx_io.h>
116 +#include <bcm63xx_regs.h>
117 +
118 +int __init bcm63xx_hsspi_register(void);
119 +
120 +struct bcm63xx_hsspi_pdata {
121 + int bus_num;
122 + u32 speed_hz;
123 +};
124 +
125 +#define bcm_hsspi_readl(o) bcm_rset_readl(RSET_HSSPI, (o))
126 +#define bcm_hsspi_writel(v, o) bcm_rset_writel(RSET_HSSPI, (v), (o))
127 +
128 +#define HSSPI_PLL_HZ_6328 133333333
129 +
130 +#define HSSPI_OP_CODE_SHIFT 13
131 +#define HSSPI_OP_SLEEP (0 << HSSPI_OP_CODE_SHIFT)
132 +#define HSSPI_OP_READ_WRITE (1 << HSSPI_OP_CODE_SHIFT)
133 +#define HSSPI_OP_WRITE (2 << HSSPI_OP_CODE_SHIFT)
134 +#define HSSPI_OP_READ (3 << HSSPI_OP_CODE_SHIFT)
135 +
136 +#endif /* BCM63XX_DEV_HSSPI_H */