[brcm63xx] fix typo for the flash start address on bcm6345
[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 * Copyright (C) 2009 Florian Fainelli <florian@openwrt.org>
8 */
9
10 #include <linux/init.h>
11 #include <linux/kernel.h>
12 #include <linux/string.h>
13 #include <linux/platform_device.h>
14 #include <linux/mtd/mtd.h>
15 #include <linux/mtd/partitions.h>
16 #include <linux/mtd/physmap.h>
17 #include <linux/ssb/ssb.h>
18 #include <asm/addrspace.h>
19 #include <bcm63xx_board.h>
20 #include <bcm63xx_cpu.h>
21 #include <bcm63xx_regs.h>
22 #include <bcm63xx_io.h>
23 #include <bcm63xx_board.h>
24 #include <bcm63xx_dev_pci.h>
25 #include <bcm63xx_dev_uart.h>
26 #include <bcm63xx_dev_wdt.h>
27 #include <bcm63xx_dev_enet.h>
28 #include <bcm63xx_dev_dsp.h>
29 #include <bcm63xx_dev_pcmcia.h>
30 #include <bcm63xx_dev_usb_ohci.h>
31 #include <bcm63xx_dev_usb_ehci.h>
32 #include <bcm63xx_dev_usb_udc.h>
33 #include <bcm63xx_dev_spi.h>
34 #include <board_bcm963xx.h>
35
36 #define PFX "board_bcm963xx: "
37
38 static struct bcm963xx_nvram nvram;
39 static unsigned int mac_addr_used = 0;
40 static struct board_info board;
41
42 /*
43 * known 6338 boards
44 */
45
46 #ifdef CONFIG_BCM63XX_CPU_6338
47 static struct board_info __initdata board_96338gw = {
48 .name = "96338GW",
49 .expected_cpu_id = 0x6338,
50
51 .has_enet0 = 1,
52 .enet0 = {
53 .force_speed_100 = 1,
54 .force_duplex_full = 1,
55 },
56
57 .has_ohci0 = 1,
58
59 .leds = {
60 {
61 .name = "adsl",
62 .gpio = 3,
63 .active_low = 1,
64 },
65 {
66 .name = "ses",
67 .gpio = 5,
68 .active_low = 1,
69 },
70 {
71 .name = "ppp-fail",
72 .gpio = 4,
73 .active_low = 1,
74 },
75 {
76 .name = "power",
77 .gpio = 0,
78 .active_low = 1,
79 .default_trigger = "default-on",
80 },
81 {
82 .name = "stop",
83 .gpio = 1,
84 .active_low = 1,
85 }
86 },
87 };
88
89 static struct board_info __initdata board_96338w = {
90 .name = "96338W",
91 .expected_cpu_id = 0x6338,
92
93 .has_enet0 = 1,
94 .enet0 = {
95 .force_speed_100 = 1,
96 .force_duplex_full = 1,
97 },
98
99 .leds = {
100 {
101 .name = "adsl",
102 .gpio = 3,
103 .active_low = 1,
104 },
105 {
106 .name = "ses",
107 .gpio = 5,
108 .active_low = 1,
109 },
110 {
111 .name = "ppp-fail",
112 .gpio = 4,
113 .active_low = 1,
114 },
115 {
116 .name = "power",
117 .gpio = 0,
118 .active_low = 1,
119 .default_trigger = "default-on",
120 },
121 {
122 .name = "stop",
123 .gpio = 1,
124 .active_low = 1,
125 },
126 },
127 };
128 #endif
129
130 /*
131 * known 6345 boards
132 */
133 #ifdef CONFIG_BCM63XX_CPU_6345
134 static struct board_info __initdata board_96345gw2 = {
135 .name = "96345GW2",
136 .expected_cpu_id = 0x6345,
137 };
138 #endif
139
140 /*
141 * known 6348 boards
142 */
143 #ifdef CONFIG_BCM63XX_CPU_6348
144 static struct board_info __initdata board_96348r = {
145 .name = "96348R",
146 .expected_cpu_id = 0x6348,
147
148 .has_enet0 = 1,
149 .has_pci = 1,
150
151 .enet0 = {
152 .has_phy = 1,
153 .use_internal_phy = 1,
154 },
155
156 .leds = {
157 {
158 .name = "adsl-fail",
159 .gpio = 2,
160 .active_low = 1,
161 },
162 {
163 .name = "ppp",
164 .gpio = 3,
165 .active_low = 1,
166 },
167 {
168 .name = "ppp-fail",
169 .gpio = 4,
170 .active_low = 1,
171 },
172 {
173 .name = "power",
174 .gpio = 0,
175 .active_low = 1,
176 .default_trigger = "default-on",
177
178 },
179 {
180 .name = "stop",
181 .gpio = 1,
182 .active_low = 1,
183 },
184 },
185 };
186
187 static struct board_info __initdata board_96348gw_10 = {
188 .name = "96348GW-10",
189 .expected_cpu_id = 0x6348,
190
191 .has_enet0 = 1,
192 .has_enet1 = 1,
193 .has_pci = 1,
194
195 .enet0 = {
196 .has_phy = 1,
197 .use_internal_phy = 1,
198 },
199 .enet1 = {
200 .force_speed_100 = 1,
201 .force_duplex_full = 1,
202 },
203
204 .has_ohci0 = 1,
205 .has_pccard = 1,
206 .has_ehci0 = 1,
207
208 .has_dsp = 1,
209 .dsp = {
210 .gpio_rst = 6,
211 .gpio_int = 34,
212 .cs = 2,
213 .ext_irq = 2,
214 },
215
216 .leds = {
217 {
218 .name = "adsl-fail",
219 .gpio = 2,
220 .active_low = 1,
221 },
222 {
223 .name = "ppp",
224 .gpio = 3,
225 .active_low = 1,
226 },
227 {
228 .name = "ppp-fail",
229 .gpio = 4,
230 .active_low = 1,
231 },
232 {
233 .name = "power",
234 .gpio = 0,
235 .active_low = 1,
236 .default_trigger = "default-on",
237 },
238 {
239 .name = "stop",
240 .gpio = 1,
241 .active_low = 1,
242 },
243 },
244 };
245
246 static struct board_info __initdata board_96348gw_11 = {
247 .name = "96348GW-11",
248 .expected_cpu_id = 0x6348,
249
250 .has_enet0 = 1,
251 .has_enet1 = 1,
252 .has_pci = 1,
253
254 .enet0 = {
255 .has_phy = 1,
256 .use_internal_phy = 1,
257 },
258
259 .enet1 = {
260 .force_speed_100 = 1,
261 .force_duplex_full = 1,
262 },
263
264
265 .has_ohci0 = 1,
266 .has_pccard = 1,
267 .has_ehci0 = 1,
268
269 .leds = {
270 {
271 .name = "adsl-fail",
272 .gpio = 2,
273 .active_low = 1,
274 },
275 {
276 .name = "ppp",
277 .gpio = 3,
278 .active_low = 1,
279 },
280 {
281 .name = "ppp-fail",
282 .gpio = 4,
283 .active_low = 1,
284 },
285 {
286 .name = "power",
287 .gpio = 0,
288 .active_low = 1,
289 .default_trigger = "default-on",
290 },
291 {
292 .name = "stop",
293 .gpio = 1,
294 .active_low = 1,
295 },
296 },
297 };
298
299 static struct board_info __initdata board_96348gw = {
300 .name = "96348GW",
301 .expected_cpu_id = 0x6348,
302
303 .has_enet0 = 1,
304 .has_enet1 = 1,
305 .has_pci = 1,
306
307 .enet0 = {
308 .has_phy = 1,
309 .use_internal_phy = 1,
310 },
311 .enet1 = {
312 .force_speed_100 = 1,
313 .force_duplex_full = 1,
314 },
315
316 .has_ohci0 = 1,
317 .has_dsp = 1,
318
319 .dsp = {
320 .gpio_rst = 6,
321 .gpio_int = 34,
322 .ext_irq = 2,
323 .cs = 2,
324 },
325
326 .leds = {
327 {
328 .name = "adsl-fail",
329 .gpio = 2,
330 .active_low = 1,
331 },
332 {
333 .name = "ppp",
334 .gpio = 3,
335 .active_low = 1,
336 },
337 {
338 .name = "ppp-fail",
339 .gpio = 4,
340 .active_low = 1,
341 },
342 {
343 .name = "power",
344 .gpio = 0,
345 .active_low = 1,
346 .default_trigger = "default-on",
347 },
348 {
349 .name = "stop",
350 .gpio = 1,
351 .active_low = 1,
352 },
353 },
354 };
355
356 static struct board_info __initdata board_FAST2404 = {
357 .name = "F@ST2404",
358 .expected_cpu_id = 0x6348,
359
360 .has_enet0 = 1,
361 .has_enet1 = 1,
362 .has_pci = 1,
363
364 .enet0 = {
365 .has_phy = 1,
366 .use_internal_phy = 1,
367 },
368
369 .enet1 = {
370 .force_speed_100 = 1,
371 .force_duplex_full = 1,
372 },
373
374
375 .has_ohci0 = 1,
376 .has_pccard = 1,
377 .has_ehci0 = 1,
378 };
379
380 static struct board_info __initdata board_DV201AMR = {
381 .name = "DV201AMR",
382 .expected_cpu_id = 0x6348,
383
384 .has_pci = 1,
385 .has_ohci0 = 1,
386 .has_udc0 = 1,
387
388 .has_enet0 = 1,
389 .has_enet1 = 1,
390 .enet0 = {
391 .has_phy = 1,
392 .use_internal_phy = 1,
393 },
394 .enet1 = {
395 .force_speed_100 = 1,
396 .force_duplex_full = 1,
397 },
398 };
399
400 static struct board_info __initdata board_96348gw_a = {
401 .name = "96348GW-A",
402 .expected_cpu_id = 0x6348,
403
404 .has_enet0 = 1,
405 .has_enet1 = 1,
406 .has_pci = 1,
407
408 .enet0 = {
409 .has_phy = 1,
410 .use_internal_phy = 1,
411 },
412 .enet1 = {
413 .force_speed_100 = 1,
414 .force_duplex_full = 1,
415 },
416
417 .has_ohci0 = 1,
418 };
419
420
421 #endif
422
423 /*
424 * known 6358 boards
425 */
426 #ifdef CONFIG_BCM63XX_CPU_6358
427 static struct board_info __initdata board_96358vw = {
428 .name = "96358VW",
429 .expected_cpu_id = 0x6358,
430
431 .has_enet0 = 1,
432 .has_enet1 = 1,
433 .has_pci = 1,
434
435 .enet0 = {
436 .has_phy = 1,
437 .use_internal_phy = 1,
438 },
439
440 .enet1 = {
441 .force_speed_100 = 1,
442 .force_duplex_full = 1,
443 },
444
445
446 .has_ohci0 = 1,
447 .has_pccard = 1,
448 .has_ehci0 = 1,
449
450 .leds = {
451 {
452 .name = "adsl-fail",
453 .gpio = 15,
454 .active_low = 1,
455 },
456 {
457 .name = "ppp",
458 .gpio = 22,
459 .active_low = 1,
460 },
461 {
462 .name = "ppp-fail",
463 .gpio = 23,
464 .active_low = 1,
465 },
466 {
467 .name = "power",
468 .gpio = 4,
469 .default_trigger = "default-on",
470 },
471 {
472 .name = "stop",
473 .gpio = 5,
474 },
475 },
476 };
477
478 static struct board_info __initdata board_96358vw2 = {
479 .name = "96358VW2",
480 .expected_cpu_id = 0x6358,
481
482 .has_enet0 = 1,
483 .has_enet1 = 1,
484 .has_pci = 1,
485
486 .enet0 = {
487 .has_phy = 1,
488 .use_internal_phy = 1,
489 },
490
491 .enet1 = {
492 .force_speed_100 = 1,
493 .force_duplex_full = 1,
494 },
495
496
497 .has_ohci0 = 1,
498 .has_pccard = 1,
499 .has_ehci0 = 1,
500
501 .leds = {
502 {
503 .name = "adsl",
504 .gpio = 22,
505 .active_low = 1,
506 },
507 {
508 .name = "ppp-fail",
509 .gpio = 23,
510 },
511 {
512 .name = "power",
513 .gpio = 5,
514 .active_low = 1,
515 .default_trigger = "default-on",
516 },
517 {
518 .name = "stop",
519 .gpio = 4,
520 .active_low = 1,
521 },
522 },
523 };
524
525 static struct board_info __initdata board_AGPFS0 = {
526 .name = "AGPF-S0",
527 .expected_cpu_id = 0x6358,
528
529 .has_enet0 = 1,
530 .has_enet1 = 1,
531 .has_pci = 1,
532
533 .enet0 = {
534 .has_phy = 1,
535 .use_internal_phy = 1,
536 },
537
538 .enet1 = {
539 .force_speed_100 = 1,
540 .force_duplex_full = 1,
541 },
542
543 .has_ohci0 = 1,
544 .has_ehci0 = 1,
545 };
546 #endif
547
548 /*
549 * all boards
550 */
551 static const struct board_info __initdata *bcm963xx_boards[] = {
552 #ifdef CONFIG_BCM63XX_CPU_6338
553 &board_96338gw,
554 &board_96338w,
555 #endif
556 #ifdef CONFIG_BCM63XX_CPU_6345
557 &board_96345gw2,
558 #endif
559 #ifdef CONFIG_BCM63XX_CPU_6348
560 &board_96348r,
561 &board_96348gw,
562 &board_96348gw_10,
563 &board_96348gw_11,
564 &board_FAST2404,
565 &board_DV201AMR,
566 &board_96348gw_a,
567 #endif
568
569 #ifdef CONFIG_BCM63XX_CPU_6358
570 &board_96358vw,
571 &board_96358vw2,
572 &board_AGPFS0,
573 #endif
574 };
575
576 /*
577 * early init callback, read nvram data from flash and checksum it
578 */
579 void __init board_prom_init(void)
580 {
581 unsigned int check_len, i;
582 u8 *boot_addr, *cfe, *p;
583 char cfe_version[32];
584 u32 val;
585
586 /* read base address of boot chip select (0)
587 * 6345 does not have MPI but boots from standard
588 * MIPS Flash address */
589 if (BCMCPU_IS_6345())
590 val = 0x1fc00000;
591 else {
592 val = bcm_mpi_readl(MPI_CSBASE_REG(0));
593 val &= MPI_CSBASE_BASE_MASK;
594 }
595 boot_addr = (u8 *)KSEG1ADDR(val);
596
597 /* dump cfe version */
598 cfe = boot_addr + BCM963XX_CFE_VERSION_OFFSET;
599 if (!memcmp(cfe, "cfe-v", 5))
600 snprintf(cfe_version, sizeof(cfe_version), "%u.%u.%u-%u.%u",
601 cfe[5], cfe[6], cfe[7], cfe[8], cfe[9]);
602 else
603 strcpy(cfe_version, "unknown");
604 printk(KERN_INFO PFX "CFE version: %s\n", cfe_version);
605
606 /* extract nvram data */
607 memcpy(&nvram, boot_addr + BCM963XX_NVRAM_OFFSET, sizeof(nvram));
608
609 /* check checksum before using data */
610 if (nvram.version <= 4)
611 check_len = offsetof(struct bcm963xx_nvram, checksum_old);
612 else
613 check_len = sizeof(nvram);
614 val = 0;
615 p = (u8 *)&nvram;
616 while (check_len--)
617 val += *p;
618 if (val) {
619 printk(KERN_ERR PFX "invalid nvram checksum\n");
620 return;
621 }
622
623 /* find board by name */
624 for (i = 0; i < ARRAY_SIZE(bcm963xx_boards); i++) {
625 if (strncmp(nvram.name, bcm963xx_boards[i]->name,
626 sizeof(nvram.name)))
627 continue;
628 /* copy, board desc array is marked initdata */
629 memcpy(&board, bcm963xx_boards[i], sizeof(board));
630 break;
631 }
632
633 /* bail out if board is not found, will complain later */
634 if (!board.name[0]) {
635 char name[17];
636 memcpy(name, nvram.name, 16);
637 name[16] = 0;
638 printk(KERN_ERR PFX "unknown bcm963xx board: %s\n",
639 name);
640 return;
641 }
642
643 /* setup pin multiplexing depending on board enabled device,
644 * this has to be done this early since PCI init is done
645 * inside arch_initcall */
646 val = 0;
647 #ifdef CONFIG_PCI
648 if (board.has_pci) {
649 bcm63xx_pci_enabled = 1;
650 if (BCMCPU_IS_6348())
651 val |= GPIO_MODE_6348_G2_PCI;
652 }
653 #endif
654 if (board.has_pccard) {
655 if (BCMCPU_IS_6348())
656 val |= GPIO_MODE_6348_G1_MII_PCCARD;
657 }
658
659 if (board.has_enet0 && !board.enet0.use_internal_phy) {
660 if (BCMCPU_IS_6348())
661 val |= GPIO_MODE_6348_G3_EXT_MII |
662 GPIO_MODE_6348_G0_EXT_MII;
663 }
664
665 if (board.has_enet1 && !board.enet1.use_internal_phy) {
666 if (BCMCPU_IS_6348())
667 val |= GPIO_MODE_6348_G3_EXT_MII |
668 GPIO_MODE_6348_G0_EXT_MII;
669 }
670
671 bcm_gpio_writel(val, GPIO_MODE_REG);
672 }
673
674 /*
675 * second stage init callback, good time to panic if we couldn't
676 * identify on which board we're running since early printk is working
677 */
678 void __init board_setup(void)
679 {
680 if (!board.name[0])
681 panic("unable to detect bcm963xx board");
682 printk(KERN_INFO PFX "board name: %s\n", board.name);
683
684 /* make sure we're running on expected cpu */
685 if (bcm63xx_get_cpu_id() != board.expected_cpu_id)
686 panic("unexpected CPU for bcm963xx board");
687 }
688
689 /*
690 * return board name for /proc/cpuinfo
691 */
692 const char *board_get_name(void)
693 {
694 return board.name;
695 }
696
697 /*
698 * register & return a new board mac address
699 */
700 static int board_get_mac_address(u8 *mac)
701 {
702 u8 *p;
703 int count;
704
705 if (mac_addr_used >= nvram.mac_addr_count) {
706 printk(KERN_ERR PFX "not enough mac address\n");
707 return -ENODEV;
708 }
709
710 memcpy(mac, nvram.mac_addr_base, ETH_ALEN);
711 p = mac + ETH_ALEN - 1;
712 count = mac_addr_used;
713
714 while (count--) {
715 do {
716 (*p)++;
717 if (*p != 0)
718 break;
719 p--;
720 } while (p != mac);
721 }
722
723 if (p == mac) {
724 printk(KERN_ERR PFX "unable to fetch mac address\n");
725 return -ENODEV;
726 }
727
728 mac_addr_used++;
729 return 0;
730 }
731
732 static struct resource mtd_resources[] = {
733 {
734 .start = 0, /* filled at runtime */
735 .end = 0, /* filled at runtime */
736 .flags = IORESOURCE_MEM,
737 }
738 };
739
740 static struct platform_device mtd_dev = {
741 .name = "bcm963xx-flash",
742 .resource = mtd_resources,
743 .num_resources = ARRAY_SIZE(mtd_resources),
744 };
745
746 /*
747 * Register a sane SPROMv2 to make the on-board
748 * bcm4318 WLAN work
749 */
750 static struct ssb_sprom bcm63xx_sprom = {
751 .revision = 0x02,
752 .board_rev = 0x17,
753 .country_code = 0x0,
754 .ant_available_bg = 0x3,
755 .pa0b0 = 0x15ae,
756 .pa0b1 = 0xfa85,
757 .pa0b2 = 0xfe8d,
758 .pa1b0 = 0xffff,
759 .pa1b1 = 0xffff,
760 .pa1b2 = 0xffff,
761 .gpio0 = 0xff,
762 .gpio1 = 0xff,
763 .gpio2 = 0xff,
764 .gpio3 = 0xff,
765 .maxpwr_bg = 0x004c,
766 .itssi_bg = 0x00,
767 .boardflags_lo = 0x2848,
768 .boardflags_hi = 0x0000,
769 };
770
771 static struct resource gpiodev_resource = {
772 .start = 0xFFFFFFFF,
773 };
774
775 static struct gpio_led_platform_data bcm63xx_led_data;
776
777 static struct platform_device bcm63xx_gpio_leds = {
778 .name = "leds-gpio",
779 .id = 0,
780 .dev.platform_data = &bcm63xx_led_data,
781 };
782
783 /*
784 * third stage init callback, register all board devices.
785 */
786 int __init board_register_devices(void)
787 {
788 u32 val;
789
790 bcm63xx_uart_register();
791 bcm63xx_wdt_register();
792 bcm63xx_spi_register();
793
794 if (board.has_pccard)
795 bcm63xx_pcmcia_register();
796
797 if (board.has_enet0 &&
798 !board_get_mac_address(board.enet0.mac_addr))
799 bcm63xx_enet_register(0, &board.enet0);
800
801 if (board.has_enet1 &&
802 !board_get_mac_address(board.enet1.mac_addr))
803 bcm63xx_enet_register(1, &board.enet1);
804
805 if (board.has_ohci0)
806 bcm63xx_ohci_register();
807
808 if (board.has_ehci0)
809 bcm63xx_ehci_register();
810
811 if (board.has_udc0)
812 bcm63xx_udc_register();
813
814 if (board.has_dsp)
815 bcm63xx_dsp_register(&board.dsp);
816
817 /* Generate MAC address for WLAN and
818 * register our SPROM */
819 #ifdef CONFIG_PCI
820 if (!board_get_mac_address(bcm63xx_sprom.il0mac)) {
821 memcpy(bcm63xx_sprom.et0mac, bcm63xx_sprom.il0mac, ETH_ALEN);
822 memcpy(bcm63xx_sprom.et1mac, bcm63xx_sprom.il0mac, ETH_ALEN);
823 if (ssb_arch_set_fallback_sprom(&bcm63xx_sprom) < 0)
824 printk(KERN_ERR "failed to register fallback SPROM\n");
825 }
826 #endif
827
828 /* read base address of boot chip select (0) */
829 if (BCMCPU_IS_6345())
830 val = 0x1fc00000;
831 else {
832 val = bcm_mpi_readl(MPI_CSBASE_REG(0));
833 val &= MPI_CSBASE_BASE_MASK;
834 }
835 mtd_resources[0].start = val;
836 mtd_resources[0].end = 0x1FFFFFFF;
837
838 platform_device_register(&mtd_dev);
839
840 /* Register GPIODEV */
841 platform_device_register_simple("GPIODEV", 0, &gpiodev_resource, 1);
842
843 bcm63xx_led_data.num_leds = ARRAY_SIZE(board.leds);
844 bcm63xx_led_data.leds = board.leds;
845
846 platform_device_register(&bcm63xx_gpio_leds);
847
848 return 0;
849 }
850