[tools] cleanup imagetag
[openwrt.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 <linux/ssb/ssb.h>
17 #include <asm/addrspace.h>
18 #include <bcm63xx_board.h>
19 #include <bcm63xx_cpu.h>
20 #include <bcm63xx_regs.h>
21 #include <bcm63xx_io.h>
22 #include <bcm63xx_board.h>
23 #include <bcm63xx_dev_pci.h>
24 #include <bcm63xx_dev_uart.h>
25 #include <bcm63xx_dev_wdt.h>
26 #include <bcm63xx_dev_enet.h>
27 #include <bcm63xx_dev_pcmcia.h>
28 #include <bcm63xx_dev_usb_ohci.h>
29 #include <bcm63xx_dev_usb_ehci.h>
30 #include <bcm63xx_dev_usb_udc.h>
31 #include <bcm63xx_dev_spi.h>
32 #include <board_bcm963xx.h>
33
34 #define PFX "board_bcm963xx: "
35
36 static struct bcm963xx_nvram nvram;
37 static unsigned int mac_addr_used = 0;
38 static struct board_info board;
39
40 /*
41 * known 6338 boards
42 */
43
44 #ifdef CONFIG_BCM63XX_CPU_6338
45 static struct board_info __initdata board_96338gw = {
46 .name = "96338GW",
47 .expected_cpu_id = 0x6338,
48
49 .has_enet0 = 1,
50 .enet0 = {
51 .has_phy = 1,
52 .use_internal_phy = 1,
53 },
54
55 .has_ohci0 = 1,
56 };
57 #endif
58
59 /*
60 * known 6348 boards
61 */
62 #ifdef CONFIG_BCM63XX_CPU_6348
63 static struct board_info __initdata board_96348r = {
64 .name = "96348R",
65 .expected_cpu_id = 0x6348,
66
67 .has_enet0 = 1,
68 .has_pci = 1,
69
70 .enet0 = {
71 .has_phy = 1,
72 .use_internal_phy = 1,
73 },
74 };
75
76 static struct board_info __initdata board_96348gw_10 = {
77 .name = "96348GW-10",
78 .expected_cpu_id = 0x6348,
79
80 .has_enet0 = 1,
81 .has_enet1 = 1,
82 .has_pci = 1,
83
84 .enet0 = {
85 .has_phy = 1,
86 .use_internal_phy = 1,
87 },
88 .enet1 = {
89 .force_speed_100 = 1,
90 .force_duplex_full = 1,
91 },
92
93 .has_ohci0 = 1,
94 .has_pccard = 1,
95 .has_ehci0 = 1,
96 };
97
98 static struct board_info __initdata board_96348gw_11 = {
99 .name = "96348GW-11",
100 .expected_cpu_id = 0x6348,
101
102 .has_enet0 = 1,
103 .has_enet1 = 1,
104 .has_pci = 1,
105
106 .enet0 = {
107 .has_phy = 1,
108 .use_internal_phy = 1,
109 },
110
111 .enet1 = {
112 .force_speed_100 = 1,
113 .force_duplex_full = 1,
114 },
115
116
117 .has_ohci0 = 1,
118 .has_pccard = 1,
119 .has_ehci0 = 1,
120 };
121
122 static struct board_info __initdata board_96348gw = {
123 .name = "96348GW",
124 .expected_cpu_id = 0x6348,
125
126 .has_enet0 = 1,
127 .has_enet1 = 1,
128 .has_pci = 1,
129
130 .enet0 = {
131 .has_phy = 1,
132 .use_internal_phy = 1,
133 },
134 .enet1 = {
135 .force_speed_100 = 1,
136 .force_duplex_full = 1,
137 },
138
139 .has_ohci0 = 1,
140 };
141
142 static struct board_info __initdata board_FAST2404 = {
143 .name = "F@ST2404",
144 .expected_cpu_id = 0x6348,
145
146 .has_enet0 = 1,
147 .has_enet1 = 1,
148 .has_pci = 1,
149
150 .enet0 = {
151 .has_phy = 1,
152 .use_internal_phy = 1,
153 },
154
155 .enet1 = {
156 .force_speed_100 = 1,
157 .force_duplex_full = 1,
158 },
159
160
161 .has_ohci0 = 1,
162 .has_pccard = 1,
163 .has_ehci0 = 1,
164 };
165
166 static struct board_info __initdata board_DV201AMR = {
167 .name = "DV201AMR",
168 .expected_cpu_id = 0x6348,
169
170 .has_pci = 1,
171 .has_ohci0 = 1,
172 .has_udc0 = 1,
173
174 .has_enet0 = 1,
175 .has_enet1 = 1,
176 .enet0 = {
177 .has_phy = 1,
178 .use_internal_phy = 1,
179 },
180 .enet1 = {
181 .force_speed_100 = 1,
182 .force_duplex_full = 1,
183 },
184 };
185
186 static struct board_info __initdata board_96348gw_a = {
187 .name = "96348GW-A",
188 .expected_cpu_id = 0x6348,
189
190 .has_enet0 = 1,
191 .has_enet1 = 1,
192 .has_pci = 1,
193
194 .enet0 = {
195 .has_phy = 1,
196 .use_internal_phy = 1,
197 },
198 .enet1 = {
199 .force_speed_100 = 1,
200 .force_duplex_full = 1,
201 },
202
203 .has_ohci0 = 1,
204 };
205
206
207 #endif
208
209 /*
210 * known 6358 boards
211 */
212 #ifdef CONFIG_BCM63XX_CPU_6358
213 static struct board_info __initdata board_96358vw = {
214 .name = "96358VW",
215 .expected_cpu_id = 0x6358,
216
217 .has_enet0 = 1,
218 .has_enet1 = 1,
219 .has_pci = 1,
220
221 .enet0 = {
222 .has_phy = 1,
223 .use_internal_phy = 1,
224 },
225
226 .enet1 = {
227 .force_speed_100 = 1,
228 .force_duplex_full = 1,
229 },
230
231
232 .has_ohci0 = 1,
233 .has_pccard = 1,
234 .has_ehci0 = 1,
235 };
236
237 static struct board_info __initdata board_96358vw2 = {
238 .name = "96358VW2",
239 .expected_cpu_id = 0x6358,
240
241 .has_enet0 = 1,
242 .has_enet1 = 1,
243 .has_pci = 1,
244
245 .enet0 = {
246 .has_phy = 1,
247 .use_internal_phy = 1,
248 },
249
250 .enet1 = {
251 .force_speed_100 = 1,
252 .force_duplex_full = 1,
253 },
254
255
256 .has_ohci0 = 1,
257 .has_pccard = 1,
258 .has_ehci0 = 1,
259 };
260
261 static struct board_info __initdata board_AGPFS0 = {
262 .name = "AGPF-S0",
263 .expected_cpu_id = 0x6358,
264
265 .has_enet0 = 1,
266 .has_enet1 = 1,
267 .has_pci = 1,
268
269 .enet0 = {
270 .has_phy = 1,
271 .use_internal_phy = 1,
272 },
273
274 .enet1 = {
275 .force_speed_100 = 1,
276 .force_duplex_full = 1,
277 },
278
279 .has_ohci0 = 1,
280 .has_ehci0 = 1,
281 };
282 #endif
283
284 /*
285 * all boards
286 */
287 static const struct board_info __initdata *bcm963xx_boards[] = {
288 #ifdef CONFIG_BCM63XX_CPU_6338
289 &board_96338gw,
290 #endif
291 #ifdef CONFIG_BCM63XX_CPU_6348
292 &board_96348r,
293 &board_96348gw,
294 &board_96348gw_10,
295 &board_96348gw_11,
296 &board_FAST2404,
297 &board_DV201AMR,
298 &board_96348gw_a,
299 #endif
300
301 #ifdef CONFIG_BCM63XX_CPU_6358
302 &board_96358vw,
303 &board_96358vw2,
304 &board_AGPFS0,
305 #endif
306 };
307
308 /*
309 * early init callback, read nvram data from flash and checksum it
310 */
311 void __init board_prom_init(void)
312 {
313 unsigned int check_len, i;
314 u8 *boot_addr, *cfe, *p;
315 char cfe_version[32];
316 u32 val;
317
318 /* read base address of boot chip select (0) */
319 val = bcm_mpi_readl(MPI_CSBASE_REG(0));
320 val &= MPI_CSBASE_BASE_MASK;
321 boot_addr = (u8 *)KSEG1ADDR(val);
322
323 /* dump cfe version */
324 cfe = boot_addr + BCM963XX_CFE_VERSION_OFFSET;
325 if (!memcmp(cfe, "cfe-v", 5))
326 snprintf(cfe_version, sizeof(cfe_version), "%u.%u.%u-%u.%u",
327 cfe[5], cfe[6], cfe[7], cfe[8], cfe[9]);
328 else
329 strcpy(cfe_version, "unknown");
330 printk(KERN_INFO PFX "CFE version: %s\n", cfe_version);
331
332 /* extract nvram data */
333 memcpy(&nvram, boot_addr + BCM963XX_NVRAM_OFFSET, sizeof(nvram));
334
335 /* check checksum before using data */
336 if (nvram.version <= 4)
337 check_len = offsetof(struct bcm963xx_nvram, checksum_old);
338 else
339 check_len = sizeof(nvram);
340 val = 0;
341 p = (u8 *)&nvram;
342 while (check_len--)
343 val += *p;
344 if (val) {
345 printk(KERN_ERR PFX "invalid nvram checksum\n");
346 return;
347 }
348
349 /* find board by name */
350 for (i = 0; i < ARRAY_SIZE(bcm963xx_boards); i++) {
351 if (strncmp(nvram.name, bcm963xx_boards[i]->name,
352 sizeof(nvram.name)))
353 continue;
354 /* copy, board desc array is marked initdata */
355 memcpy(&board, bcm963xx_boards[i], sizeof(board));
356 break;
357 }
358
359 /* bail out if board is not found, will complain later */
360 if (!board.name[0]) {
361 char name[17];
362 memcpy(name, nvram.name, 16);
363 name[16] = 0;
364 printk(KERN_ERR PFX "unknown bcm963xx board: %s\n",
365 name);
366 return;
367 }
368
369 /* setup pin multiplexing depending on board enabled device,
370 * this has to be done this early since PCI init is done
371 * inside arch_initcall */
372 val = 0;
373
374 if (board.has_pci) {
375 bcm63xx_pci_enabled = 1;
376 if (BCMCPU_IS_6348())
377 val |= GPIO_MODE_6348_G2_PCI;
378 }
379
380 if (board.has_pccard) {
381 if (BCMCPU_IS_6348())
382 val |= GPIO_MODE_6348_G1_MII_PCCARD;
383 }
384
385 if (board.has_enet0 && !board.enet0.use_internal_phy) {
386 if (BCMCPU_IS_6348())
387 val |= GPIO_MODE_6348_G3_EXT_MII |
388 GPIO_MODE_6348_G0_EXT_MII;
389 }
390
391 if (board.has_enet1 && !board.enet1.use_internal_phy) {
392 if (BCMCPU_IS_6348())
393 val |= GPIO_MODE_6348_G3_EXT_MII |
394 GPIO_MODE_6348_G0_EXT_MII;
395 }
396
397 bcm_gpio_writel(val, GPIO_MODE_REG);
398 }
399
400 /*
401 * second stage init callback, good time to panic if we couldn't
402 * identify on which board we're running since early printk is working
403 */
404 void __init board_setup(void)
405 {
406 if (!board.name[0])
407 panic("unable to detect bcm963xx board");
408 printk(KERN_INFO PFX "board name: %s\n", board.name);
409
410 /* make sure we're running on expected cpu */
411 if (bcm63xx_get_cpu_id() != board.expected_cpu_id)
412 panic("unexpected CPU for bcm963xx board");
413 }
414
415 /*
416 * return board name for /proc/cpuinfo
417 */
418 const char *board_get_name(void)
419 {
420 return board.name;
421 }
422
423 /*
424 * register & return a new board mac address
425 */
426 static int board_get_mac_address(u8 *mac)
427 {
428 u8 *p;
429 int count;
430
431 if (mac_addr_used >= nvram.mac_addr_count) {
432 printk(KERN_ERR PFX "not enough mac address\n");
433 return -ENODEV;
434 }
435
436 memcpy(mac, nvram.mac_addr_base, ETH_ALEN);
437 p = mac + ETH_ALEN - 1;
438 count = mac_addr_used;
439
440 while (count--) {
441 do {
442 (*p)++;
443 if (*p != 0)
444 break;
445 p--;
446 } while (p != mac);
447 }
448
449 if (p == mac) {
450 printk(KERN_ERR PFX "unable to fetch mac address\n");
451 return -ENODEV;
452 }
453
454 mac_addr_used++;
455 return 0;
456 }
457
458 static struct resource mtd_resources[] = {
459 {
460 .start = 0, /* filled at runtime */
461 .end = 0, /* filled at runtime */
462 .flags = IORESOURCE_MEM,
463 }
464 };
465
466 static struct platform_device mtd_dev = {
467 .name = "bcm963xx-flash",
468 .resource = mtd_resources,
469 .num_resources = ARRAY_SIZE(mtd_resources),
470 };
471
472 /*
473 * Register a sane SPROMv2 to make the on-board
474 * bcm4318 WLAN work
475 */
476 static struct ssb_sprom bcm63xx_sprom = {
477 .revision = 0x02,
478 .board_rev = 0x17,
479 .country_code = 0x0,
480 .ant_available_bg = 0x3,
481 .pa0b0 = 0x15ae,
482 .pa0b1 = 0xfa85,
483 .pa0b2 = 0xfe8d,
484 .pa1b0 = 0xffff,
485 .pa1b1 = 0xffff,
486 .pa1b2 = 0xffff,
487 .gpio0 = 0xff,
488 .gpio1 = 0xff,
489 .gpio2 = 0xff,
490 .gpio3 = 0xff,
491 .maxpwr_bg = 0x004c,
492 .itssi_bg = 0x00,
493 .boardflags_lo = 0x2848,
494 .boardflags_hi = 0x0000,
495 };
496
497 /*
498 * third stage init callback, register all board devices.
499 */
500 int __init board_register_devices(void)
501 {
502 u32 val;
503
504 bcm63xx_uart_register();
505 bcm63xx_wdt_register();
506 bcm63xx_spi_register();
507
508 if (board.has_pccard)
509 bcm63xx_pcmcia_register();
510
511 if (board.has_enet0 &&
512 !board_get_mac_address(board.enet0.mac_addr))
513 bcm63xx_enet_register(0, &board.enet0);
514
515 if (board.has_enet1 &&
516 !board_get_mac_address(board.enet1.mac_addr))
517 bcm63xx_enet_register(1, &board.enet1);
518
519 if (board.has_ohci0)
520 bcm63xx_ohci_register();
521
522 if (board.has_ehci0)
523 bcm63xx_ehci_register();
524
525 if (board.has_udc0)
526 bcm63xx_udc_register();
527 /* Generate MAC address for WLAN and
528 * register our SPROM */
529 if (!board_get_mac_address(bcm63xx_sprom.il0mac)) {
530 memcpy(bcm63xx_sprom.et0mac, bcm63xx_sprom.il0mac, ETH_ALEN);
531 memcpy(bcm63xx_sprom.et1mac, bcm63xx_sprom.il0mac, ETH_ALEN);
532 if (ssb_arch_set_fallback_sprom(&bcm63xx_sprom) < 0)
533 printk(KERN_ERR "failed to register fallback SPROM\n");
534 }
535
536 /* read base address of boot chip select (0) */
537 val = bcm_mpi_readl(MPI_CSBASE_REG(0));
538 val &= MPI_CSBASE_BASE_MASK;
539 mtd_resources[0].start = val;
540 mtd_resources[0].end = 0x1FFFFFFF;
541
542 platform_device_register(&mtd_dev);
543
544 return 0;
545 }
546
This page took 0.069854 seconds and 5 git commands to generate.