6cf3f718239be11a26a1f98b54ab09f352cc04f2
[openwrt/staging/florian.git] / target / linux / brcm63xx / patches-2.6.32 / 170-board_livebox.patch
1 Index: linux-2.6.32.9/arch/mips/bcm63xx/boards/Kconfig
2 ===================================================================
3 --- linux-2.6.32.9.orig/arch/mips/bcm63xx/boards/Kconfig 2010-02-28 19:03:38.000000000 +0100
4 +++ linux-2.6.32.9/arch/mips/bcm63xx/boards/Kconfig 2010-02-28 19:04:38.000000000 +0100
5 @@ -8,4 +8,10 @@
6 select SSB
7 help
8
9 +config BOARD_LIVEBOX
10 + bool "Inventel Livebox(es) boards"
11 + select SSB
12 + help
13 + Inventel Livebox boards using the RedBoot bootloader.
14 +
15 endchoice
16 Index: linux-2.6.32.9/arch/mips/bcm63xx/boards/Makefile
17 ===================================================================
18 --- linux-2.6.32.9.orig/arch/mips/bcm63xx/boards/Makefile 2010-02-28 19:03:45.000000000 +0100
19 +++ linux-2.6.32.9/arch/mips/bcm63xx/boards/Makefile 2010-02-28 19:04:54.000000000 +0100
20 @@ -1,3 +1,4 @@
21 obj-$(CONFIG_BOARD_BCM963XX) += board_bcm963xx.o
22 +obj-$(CONFIG_BOARD_LIVEBOX) += board_livebox.o
23
24 EXTRA_CFLAGS += -Werror
25 Index: linux-2.6.32.9/arch/mips/bcm63xx/boards/board_livebox.c
26 ===================================================================
27 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
28 +++ linux-2.6.32.9/arch/mips/bcm63xx/boards/board_livebox.c 2010-02-28 19:05:16.000000000 +0100
29 @@ -0,0 +1,227 @@
30 +/*
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
33 + * for more details.
34 + *
35 + * Copyright (C) 2008 Florian Fainelli <florian@openwrt.org>
36 + */
37 +
38 +#include <linux/init.h>
39 +#include <linux/kernel.h>
40 +#include <linux/string.h>
41 +#include <linux/platform_device.h>
42 +#include <linux/mtd/mtd.h>
43 +#include <linux/mtd/partitions.h>
44 +#include <linux/mtd/physmap.h>
45 +#include <asm/addrspace.h>
46 +#include <bcm63xx_board.h>
47 +#include <bcm63xx_cpu.h>
48 +#include <bcm63xx_regs.h>
49 +#include <bcm63xx_io.h>
50 +#include <bcm63xx_board.h>
51 +#include <bcm63xx_dev_pci.h>
52 +#include <bcm63xx_dev_uart.h>
53 +#include <bcm63xx_dev_wdt.h>
54 +#include <bcm63xx_dev_enet.h>
55 +#include <bcm63xx_dev_pcmcia.h>
56 +#include <bcm63xx_dev_usb_ohci.h>
57 +#include <bcm63xx_dev_usb_ehci.h>
58 +#include <board_bcm963xx.h>
59 +
60 +#define PFX "board_livebox: "
61 +
62 +static unsigned int mac_addr_used = 0;
63 +static struct board_info board;
64 +
65 +/*
66 + * known 6348 boards
67 + */
68 +#ifdef CONFIG_BCM63XX_CPU_6348
69 +static struct board_info __initdata board_livebox = {
70 + .name = "Livebox",
71 + .expected_cpu_id = 0x6348,
72 +
73 + .has_enet0 = 1,
74 + .has_enet1 = 1,
75 + .has_pci = 1,
76 +
77 + .enet0 = {
78 + .has_phy = 1,
79 + .use_internal_phy = 1,
80 + },
81 +
82 + .enet1 = {
83 + .force_speed_100 = 1,
84 + .force_duplex_full = 1,
85 + },
86 +
87 + .has_ohci0 = 1,
88 + .has_pccard = 1,
89 + .has_ehci0 = 1,
90 +};
91 +#endif
92 +
93 +/*
94 + * all boards
95 + */
96 +static const struct board_info __initdata *bcm963xx_boards[] = {
97 +#ifdef CONFIG_BCM63XX_CPU_6348
98 + &board_livebox
99 +#endif
100 +};
101 +
102 +/*
103 + * early init callback
104 + */
105 +void __init board_prom_init(void)
106 +{
107 + u32 val;
108 +
109 + /* read base address of boot chip select (0) */
110 + val = bcm_mpi_readl(MPI_CSBASE_REG(0));
111 + val &= MPI_CSBASE_BASE_MASK;
112 +
113 + /* assume board is a Livebox */
114 + memcpy(&board, bcm963xx_boards[0], sizeof(board));
115 +
116 + /* setup pin multiplexing depending on board enabled device,
117 + * this has to be done this early since PCI init is done
118 + * inside arch_initcall */
119 + val = 0;
120 +
121 + if (board.has_pci) {
122 + bcm63xx_pci_enabled = 1;
123 + if (BCMCPU_IS_6348())
124 + val |= GPIO_MODE_6348_G2_PCI;
125 + }
126 +
127 + if (board.has_pccard) {
128 + if (BCMCPU_IS_6348())
129 + val |= GPIO_MODE_6348_G1_MII_PCCARD;
130 + }
131 +
132 + if (board.has_enet0 && !board.enet0.use_internal_phy) {
133 + if (BCMCPU_IS_6348())
134 + val |= GPIO_MODE_6348_G3_EXT_MII |
135 + GPIO_MODE_6348_G0_EXT_MII;
136 + }
137 +
138 + if (board.has_enet1 && !board.enet1.use_internal_phy) {
139 + if (BCMCPU_IS_6348())
140 + val |= GPIO_MODE_6348_G3_EXT_MII |
141 + GPIO_MODE_6348_G0_EXT_MII;
142 + }
143 +
144 + bcm_gpio_writel(val, GPIO_MODE_REG);
145 +}
146 +
147 +/*
148 + * second stage init callback, good time to panic if we couldn't
149 + * identify on which board we're running since early printk is working
150 + */
151 +void __init board_setup(void)
152 +{
153 + if (!board.name[0])
154 + panic("unable to detect bcm963xx board");
155 + printk(KERN_INFO PFX "board name: %s\n", board.name);
156 +
157 + /* make sure we're running on expected cpu */
158 + if (bcm63xx_get_cpu_id() != board.expected_cpu_id)
159 + panic("unexpected CPU for bcm963xx board");
160 +}
161 +
162 +/*
163 + * return board name for /proc/cpuinfo
164 + */
165 +const char *board_get_name(void)
166 +{
167 + return board.name;
168 +}
169 +
170 +/*
171 + * register & return a new board mac address
172 + */
173 +
174 +static int board_get_mac_address(u8 *mac)
175 +{
176 + u8 default_mac[ETH_ALEN] = {0x00, 0x07, 0x3A, 0x00, 0x00, 0x00};
177 + u8 *p;
178 + int count;
179 +
180 + memcpy(mac, default_mac, ETH_ALEN);
181 +
182 + p = mac + ETH_ALEN - 1;
183 + count = mac_addr_used;
184 +
185 + while (count--) {
186 + do {
187 + (*p)++;
188 + if (*p != 0)
189 + break;
190 + p--;
191 + } while (p != mac);
192 + }
193 +
194 + if (p == mac) {
195 + printk(KERN_ERR PFX "unable to fetch mac address\n");
196 + return -ENODEV;
197 + }
198 + mac_addr_used++;
199 +
200 + return 0;
201 +}
202 +
203 +static struct resource mtd_resources[] = {
204 + {
205 + .start = 0, /* filled at runtime */
206 + .end = 0, /* filled at runtime */
207 + .flags = IORESOURCE_MEM,
208 + }
209 +};
210 +
211 +static struct platform_device mtd_dev = {
212 + .name = "bcm963xx-flash",
213 + .resource = mtd_resources,
214 + .num_resources = ARRAY_SIZE(mtd_resources),
215 +};
216 +
217 +
218 +/*
219 + * third stage init callback, register all board devices.
220 + */
221 +int __init board_register_devices(void)
222 +{
223 + u32 val;
224 +
225 + bcm63xx_uart_register();
226 + bcm63xx_wdt_register();
227 +
228 + if (board.has_pccard)
229 + bcm63xx_pcmcia_register();
230 +
231 + if (board.has_enet0 &&
232 + !board_get_mac_address(board.enet0.mac_addr))
233 + bcm63xx_enet_register(0, &board.enet0);
234 +
235 + if (board.has_enet1 &&
236 + !board_get_mac_address(board.enet1.mac_addr))
237 + bcm63xx_enet_register(1, &board.enet1);
238 +
239 + if (board.has_ohci0)
240 + bcm63xx_ohci_register();
241 +
242 + if (board.has_ehci0)
243 + bcm63xx_ehci_register();
244 +
245 +
246 + /* read base address of boot chip select (0) */
247 + val = bcm_mpi_readl(MPI_CSBASE_REG(0));
248 + val &= MPI_CSBASE_BASE_MASK;
249 + mtd_resources[0].start = val;
250 + mtd_resources[0].end = 0x1FFFFFFF;
251 +
252 + platform_device_register(&mtd_dev);
253 +
254 + return 0;
255 +}
256 +