Enable ohci on bcm96348gw
[openwrt/svn-archive/archive.git] / target / linux / brcm63xx / files / arch / mips / bcm63xx / boards / board_bcm963xx.c
1 /*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
5 *
6 * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
7 */
8
9 #include <linux/init.h>
10 #include <linux/kernel.h>
11 #include <linux/string.h>
12 #include <linux/platform_device.h>
13 #include <linux/mtd/mtd.h>
14 #include <linux/mtd/partitions.h>
15 #include <linux/mtd/physmap.h>
16 #include <asm/addrspace.h>
17 #include <bcm63xx_board.h>
18 #include <bcm63xx_cpu.h>
19 #include <bcm63xx_regs.h>
20 #include <bcm63xx_io.h>
21 #include <bcm63xx_board.h>
22 #include <bcm63xx_dev_pci.h>
23 #include <bcm63xx_dev_uart.h>
24 #include <bcm63xx_dev_enet.h>
25 #include <bcm63xx_dev_pcmcia.h>
26 #include <bcm63xx_dev_usb_ohci.h>
27 #include <bcm63xx_dev_usb_ehci.h>
28 #include <board_bcm963xx.h>
29
30 #define PFX "board_bcm963xx: "
31
32 static struct bcm963xx_nvram nvram;
33 static unsigned int mac_addr_used = 0;
34 static struct board_info board;
35
36 /*
37 * known 6348 boards
38 */
39 #ifdef CONFIG_BCM63XX_CPU_6348
40 static struct board_info __initdata board_96348r = {
41 .name = "96348R",
42 .expected_cpu_id = 0x6348,
43
44 .has_enet0 = 1,
45 .has_pci = 1,
46
47 .enet0 = {
48 .has_phy = 1,
49 .use_internal_phy = 1,
50 },
51 };
52
53 static struct board_info __initdata board_96348gw_10 = {
54 .name = "96348GW-10",
55 .expected_cpu_id = 0x6348,
56
57 .has_enet0 = 1,
58 .has_enet1 = 1,
59 .has_pci = 1,
60
61 .enet0 = {
62 .has_phy = 1,
63 .use_internal_phy = 1,
64 },
65 .enet1 = {
66 .force_speed_100 = 1,
67 .force_duplex_full = 1,
68 },
69
70 .has_ohci0 = 1,
71 .has_pccard = 1,
72 .has_ehci0 = 1,
73 };
74
75 static struct board_info __initdata board_96348gw_11 = {
76 .name = "96348GW-11",
77 .expected_cpu_id = 0x6348,
78
79 .has_enet0 = 1,
80 .has_enet1 = 1,
81 .has_pci = 1,
82
83 .enet0 = {
84 .has_phy = 1,
85 .use_internal_phy = 1,
86 },
87
88 .enet1 = {
89 .force_speed_100 = 1,
90 .force_duplex_full = 1,
91 },
92
93
94 .has_ohci0 = 1,
95 .has_pccard = 1,
96 .has_ehci0 = 1,
97 };
98
99 static struct board_info __initdata board_96348gw = {
100 .name = "96348GW",
101 .expected_cpu_id = 0x6348,
102
103 .has_enet0 = 1,
104 .has_enet1 = 1,
105 .has_pci = 1,
106
107 .enet0 = {
108 .has_phy = 1,
109 .use_internal_phy = 1,
110 },
111 .enet1 = {
112 .force_speed_100 = 1,
113 .force_duplex_full = 1,
114 },
115
116 .has_ohci0 = 1,
117 };
118 #endif
119
120 /*
121 * known 6358 boards
122 */
123 #ifdef CONFIG_BCM63XX_CPU_6358
124 static struct board_info __initdata board_96358vw = {
125 .name = "96358VW",
126 .expected_cpu_id = 0x6358,
127
128 .has_enet0 = 1,
129 .has_enet1 = 1,
130 .has_pci = 1,
131
132 .enet0 = {
133 .has_phy = 1,
134 .use_internal_phy = 1,
135 },
136
137 .enet1 = {
138 .force_speed_100 = 1,
139 .force_duplex_full = 1,
140 },
141
142
143 .has_ohci0 = 1,
144 .has_pccard = 1,
145 .has_ehci0 = 1,
146 };
147
148 static struct board_info __initdata board_96358vw2 = {
149 .name = "96358VW2",
150 .expected_cpu_id = 0x6358,
151
152 .has_enet0 = 1,
153 .has_enet1 = 1,
154 .has_pci = 1,
155
156 .enet0 = {
157 .has_phy = 1,
158 .use_internal_phy = 1,
159 },
160
161 .enet1 = {
162 .force_speed_100 = 1,
163 .force_duplex_full = 1,
164 },
165
166
167 .has_ohci0 = 1,
168 .has_pccard = 1,
169 .has_ehci0 = 1,
170 };
171 #endif
172
173 /*
174 * all boards
175 */
176 static const struct board_info __initdata *bcm963xx_boards[] = {
177 #ifdef CONFIG_BCM63XX_CPU_6348
178 &board_96348r,
179 &board_96348gw,
180 &board_96348gw_10,
181 &board_96348gw_11,
182 #endif
183
184 #ifdef CONFIG_BCM63XX_CPU_6358
185 &board_96358vw,
186 &board_96358vw2,
187 #endif
188 };
189
190 /*
191 * early init callback, read nvram data from flash and checksum it
192 */
193 void __init board_prom_init(void)
194 {
195 unsigned int check_len, i;
196 u8 *boot_addr, *cfe, *p;
197 char cfe_version[32];
198 u32 val;
199
200 /* read base address of boot chip select (0) */
201 val = bcm_mpi_readl(MPI_CSBASE_REG(0));
202 val &= MPI_CSBASE_BASE_MASK;
203 boot_addr = (u8 *)KSEG1ADDR(val);
204
205 /* dump cfe version */
206 cfe = boot_addr + BCM963XX_CFE_VERSION_OFFSET;
207 if (!memcmp(cfe, "cfe-v", 5))
208 snprintf(cfe_version, sizeof(cfe_version), "%u.%u.%u-%u.%u",
209 cfe[5], cfe[6], cfe[7], cfe[8], cfe[9]);
210 else
211 strcpy(cfe_version, "unknown");
212 printk(KERN_INFO PFX "CFE version: %s\n", cfe_version);
213
214 /* extract nvram data */
215 memcpy(&nvram, boot_addr + BCM963XX_NVRAM_OFFSET, sizeof(nvram));
216
217 /* check checksum before using data */
218 if (nvram.version <= 4)
219 check_len = offsetof(struct bcm963xx_nvram, checksum_old);
220 else
221 check_len = sizeof(nvram);
222 val = 0;
223 p = (u8 *)&nvram;
224 while (check_len--)
225 val += *p;
226 if (val) {
227 printk(KERN_ERR PFX "invalid nvram checksum\n");
228 return;
229 }
230
231 /* find board by name */
232 for (i = 0; i < ARRAY_SIZE(bcm963xx_boards); i++) {
233 if (strncmp(nvram.name, bcm963xx_boards[i]->name,
234 sizeof(nvram.name)))
235 continue;
236 /* copy, board desc array is marked initdata */
237 memcpy(&board, bcm963xx_boards[i], sizeof(board));
238 break;
239 }
240
241 /* bail out if board is not found, will complain later */
242 if (!board.name[0]) {
243 char name[17];
244 memcpy(name, nvram.name, 16);
245 name[16] = 0;
246 printk(KERN_ERR PFX "unknown bcm963xx board: %s\n",
247 name);
248 return;
249 }
250
251 /* setup pin multiplexing depending on board enabled device,
252 * this has to be done this early since PCI init is done
253 * inside arch_initcall */
254 val = 0;
255
256 if (board.has_pci) {
257 bcm63xx_pci_enabled = 1;
258 if (BCMCPU_IS_6348())
259 val |= GPIO_MODE_6348_G2_PCI;
260 }
261
262 if (board.has_pccard) {
263 if (BCMCPU_IS_6348())
264 val |= GPIO_MODE_6348_G1_MII_PCCARD;
265 }
266
267 if (board.has_enet0 && !board.enet0.use_internal_phy) {
268 if (BCMCPU_IS_6348())
269 val |= GPIO_MODE_6348_G3_EXT_MII |
270 GPIO_MODE_6348_G0_EXT_MII;
271 }
272
273 if (board.has_enet1 && !board.enet1.use_internal_phy) {
274 if (BCMCPU_IS_6348())
275 val |= GPIO_MODE_6348_G3_EXT_MII |
276 GPIO_MODE_6348_G0_EXT_MII;
277 }
278
279 bcm_gpio_writel(val, GPIO_MODE_REG);
280 }
281
282 /*
283 * second stage init callback, good time to panic if we couldn't
284 * identify on which board we're running since early printk is working
285 */
286 void __init board_setup(void)
287 {
288 if (!board.name[0])
289 panic("unable to detect bcm963xx board");
290 printk(KERN_INFO PFX "board name: %s\n", board.name);
291
292 /* make sure we're running on expected cpu */
293 if (bcm63xx_get_cpu_id() != board.expected_cpu_id)
294 panic("unexpected CPU for bcm963xx board");
295 }
296
297 /*
298 * return board name for /proc/cpuinfo
299 */
300 const char *board_get_name(void)
301 {
302 return board.name;
303 }
304
305 /*
306 * register & return a new board mac address
307 */
308 static int board_get_mac_address(u8 *mac)
309 {
310 u8 *p;
311 int count;
312
313 if (mac_addr_used >= nvram.mac_addr_count) {
314 printk(KERN_ERR PFX "not enough mac address\n");
315 return -ENODEV;
316 }
317
318 memcpy(mac, nvram.mac_addr_base, ETH_ALEN);
319 p = mac + ETH_ALEN - 1;
320 count = mac_addr_used;
321
322 while (count--) {
323 do {
324 (*p)++;
325 if (*p != 0)
326 break;
327 p--;
328 } while (p != mac);
329 }
330
331 if (p == mac) {
332 printk(KERN_ERR PFX "unable to fetch mac address\n");
333 return -ENODEV;
334 }
335
336 mac_addr_used++;
337 return 0;
338 }
339
340 static struct resource mtd_resources[] = {
341 {
342 .start = 0, /* filled at runtime */
343 .end = 0, /* filled at runtime */
344 .flags = IORESOURCE_MEM,
345 }
346 };
347
348 static struct platform_device mtd_dev = {
349 .name = "bcm963xx-flash",
350 .resource = mtd_resources,
351 .num_resources = ARRAY_SIZE(mtd_resources),
352 };
353
354 /*
355 * third stage init callback, register all board devices.
356 */
357 int __init board_register_devices(void)
358 {
359 u32 val;
360
361 bcm63xx_uart_register();
362
363 if (board.has_pccard)
364 bcm63xx_pcmcia_register();
365
366 if (board.has_enet0 &&
367 !board_get_mac_address(board.enet0.mac_addr))
368 bcm63xx_enet_register(0, &board.enet0);
369
370 if (board.has_enet1 &&
371 !board_get_mac_address(board.enet1.mac_addr))
372 bcm63xx_enet_register(1, &board.enet1);
373
374 if (board.has_ohci0)
375 bcm63xx_ohci_register();
376
377 if (board.has_ehci0)
378 bcm63xx_ehci_register();
379
380
381 /* read base address of boot chip select (0) */
382 val = bcm_mpi_readl(MPI_CSBASE_REG(0));
383 val &= MPI_CSBASE_BASE_MASK;
384 mtd_resources[0].start = val;
385 mtd_resources[0].end = 0x1FFFFFFF;
386
387 platform_device_register(&mtd_dev);
388
389 return 0;
390 }
391