First Support on Ginger and OMAP TI
[linux-ginger.git] / arch / mips / bcm63xx / boards / board_bcm963xx.c
blob78e155d21be61cdc8c59c4cf84395d6f54183805
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.
6 * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
7 * Copyright (C) 2008 Florian Fainelli <florian@openwrt.org>
8 */
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_dev_pci.h>
24 #include <bcm63xx_dev_enet.h>
25 #include <bcm63xx_dev_dsp.h>
26 #include <bcm63xx_dev_pcmcia.h>
27 #include <bcm63xx_dev_uart.h>
28 #include <board_bcm963xx.h>
30 #define PFX "board_bcm963xx: "
32 static struct bcm963xx_nvram nvram;
33 static unsigned int mac_addr_used;
34 static struct board_info board;
37 * known 6338 boards
39 #ifdef CONFIG_BCM63XX_CPU_6338
40 static struct board_info __initdata board_96338gw = {
41 .name = "96338GW",
42 .expected_cpu_id = 0x6338,
44 .has_enet0 = 1,
45 .enet0 = {
46 .force_speed_100 = 1,
47 .force_duplex_full = 1,
50 .has_ohci0 = 1,
52 .leds = {
54 .name = "adsl",
55 .gpio = 3,
56 .active_low = 1,
59 .name = "ses",
60 .gpio = 5,
61 .active_low = 1,
64 .name = "ppp-fail",
65 .gpio = 4,
66 .active_low = 1,
69 .name = "power",
70 .gpio = 0,
71 .active_low = 1,
72 .default_trigger = "default-on",
75 .name = "stop",
76 .gpio = 1,
77 .active_low = 1,
82 static struct board_info __initdata board_96338w = {
83 .name = "96338W",
84 .expected_cpu_id = 0x6338,
86 .has_enet0 = 1,
87 .enet0 = {
88 .force_speed_100 = 1,
89 .force_duplex_full = 1,
92 .leds = {
94 .name = "adsl",
95 .gpio = 3,
96 .active_low = 1,
99 .name = "ses",
100 .gpio = 5,
101 .active_low = 1,
104 .name = "ppp-fail",
105 .gpio = 4,
106 .active_low = 1,
109 .name = "power",
110 .gpio = 0,
111 .active_low = 1,
112 .default_trigger = "default-on",
115 .name = "stop",
116 .gpio = 1,
117 .active_low = 1,
121 #endif
124 * known 6345 boards
126 #ifdef CONFIG_BCM63XX_CPU_6345
127 static struct board_info __initdata board_96345gw2 = {
128 .name = "96345GW2",
129 .expected_cpu_id = 0x6345,
131 #endif
134 * known 6348 boards
136 #ifdef CONFIG_BCM63XX_CPU_6348
137 static struct board_info __initdata board_96348r = {
138 .name = "96348R",
139 .expected_cpu_id = 0x6348,
141 .has_enet0 = 1,
142 .has_pci = 1,
144 .enet0 = {
145 .has_phy = 1,
146 .use_internal_phy = 1,
149 .leds = {
151 .name = "adsl-fail",
152 .gpio = 2,
153 .active_low = 1,
156 .name = "ppp",
157 .gpio = 3,
158 .active_low = 1,
161 .name = "ppp-fail",
162 .gpio = 4,
163 .active_low = 1,
166 .name = "power",
167 .gpio = 0,
168 .active_low = 1,
169 .default_trigger = "default-on",
173 .name = "stop",
174 .gpio = 1,
175 .active_low = 1,
180 static struct board_info __initdata board_96348gw_10 = {
181 .name = "96348GW-10",
182 .expected_cpu_id = 0x6348,
184 .has_enet0 = 1,
185 .has_enet1 = 1,
186 .has_pci = 1,
188 .enet0 = {
189 .has_phy = 1,
190 .use_internal_phy = 1,
192 .enet1 = {
193 .force_speed_100 = 1,
194 .force_duplex_full = 1,
197 .has_ohci0 = 1,
198 .has_pccard = 1,
199 .has_ehci0 = 1,
201 .has_dsp = 1,
202 .dsp = {
203 .gpio_rst = 6,
204 .gpio_int = 34,
205 .cs = 2,
206 .ext_irq = 2,
209 .leds = {
211 .name = "adsl-fail",
212 .gpio = 2,
213 .active_low = 1,
216 .name = "ppp",
217 .gpio = 3,
218 .active_low = 1,
221 .name = "ppp-fail",
222 .gpio = 4,
223 .active_low = 1,
226 .name = "power",
227 .gpio = 0,
228 .active_low = 1,
229 .default_trigger = "default-on",
232 .name = "stop",
233 .gpio = 1,
234 .active_low = 1,
239 static struct board_info __initdata board_96348gw_11 = {
240 .name = "96348GW-11",
241 .expected_cpu_id = 0x6348,
243 .has_enet0 = 1,
244 .has_enet1 = 1,
245 .has_pci = 1,
247 .enet0 = {
248 .has_phy = 1,
249 .use_internal_phy = 1,
252 .enet1 = {
253 .force_speed_100 = 1,
254 .force_duplex_full = 1,
258 .has_ohci0 = 1,
259 .has_pccard = 1,
260 .has_ehci0 = 1,
262 .leds = {
264 .name = "adsl-fail",
265 .gpio = 2,
266 .active_low = 1,
269 .name = "ppp",
270 .gpio = 3,
271 .active_low = 1,
274 .name = "ppp-fail",
275 .gpio = 4,
276 .active_low = 1,
279 .name = "power",
280 .gpio = 0,
281 .active_low = 1,
282 .default_trigger = "default-on",
285 .name = "stop",
286 .gpio = 1,
287 .active_low = 1,
292 static struct board_info __initdata board_96348gw = {
293 .name = "96348GW",
294 .expected_cpu_id = 0x6348,
296 .has_enet0 = 1,
297 .has_enet1 = 1,
298 .has_pci = 1,
300 .enet0 = {
301 .has_phy = 1,
302 .use_internal_phy = 1,
304 .enet1 = {
305 .force_speed_100 = 1,
306 .force_duplex_full = 1,
309 .has_ohci0 = 1,
311 .has_dsp = 1,
312 .dsp = {
313 .gpio_rst = 6,
314 .gpio_int = 34,
315 .ext_irq = 2,
316 .cs = 2,
319 .leds = {
321 .name = "adsl-fail",
322 .gpio = 2,
323 .active_low = 1,
326 .name = "ppp",
327 .gpio = 3,
328 .active_low = 1,
331 .name = "ppp-fail",
332 .gpio = 4,
333 .active_low = 1,
336 .name = "power",
337 .gpio = 0,
338 .active_low = 1,
339 .default_trigger = "default-on",
342 .name = "stop",
343 .gpio = 1,
344 .active_low = 1,
349 static struct board_info __initdata board_FAST2404 = {
350 .name = "F@ST2404",
351 .expected_cpu_id = 0x6348,
353 .has_enet0 = 1,
354 .has_enet1 = 1,
355 .has_pci = 1,
357 .enet0 = {
358 .has_phy = 1,
359 .use_internal_phy = 1,
362 .enet1 = {
363 .force_speed_100 = 1,
364 .force_duplex_full = 1,
368 .has_ohci0 = 1,
369 .has_pccard = 1,
370 .has_ehci0 = 1,
373 static struct board_info __initdata board_DV201AMR = {
374 .name = "DV201AMR",
375 .expected_cpu_id = 0x6348,
377 .has_pci = 1,
378 .has_ohci0 = 1,
380 .has_enet0 = 1,
381 .has_enet1 = 1,
382 .enet0 = {
383 .has_phy = 1,
384 .use_internal_phy = 1,
386 .enet1 = {
387 .force_speed_100 = 1,
388 .force_duplex_full = 1,
392 static struct board_info __initdata board_96348gw_a = {
393 .name = "96348GW-A",
394 .expected_cpu_id = 0x6348,
396 .has_enet0 = 1,
397 .has_enet1 = 1,
398 .has_pci = 1,
400 .enet0 = {
401 .has_phy = 1,
402 .use_internal_phy = 1,
404 .enet1 = {
405 .force_speed_100 = 1,
406 .force_duplex_full = 1,
409 .has_ohci0 = 1,
411 #endif
414 * known 6358 boards
416 #ifdef CONFIG_BCM63XX_CPU_6358
417 static struct board_info __initdata board_96358vw = {
418 .name = "96358VW",
419 .expected_cpu_id = 0x6358,
421 .has_enet0 = 1,
422 .has_enet1 = 1,
423 .has_pci = 1,
425 .enet0 = {
426 .has_phy = 1,
427 .use_internal_phy = 1,
430 .enet1 = {
431 .force_speed_100 = 1,
432 .force_duplex_full = 1,
436 .has_ohci0 = 1,
437 .has_pccard = 1,
438 .has_ehci0 = 1,
440 .leds = {
442 .name = "adsl-fail",
443 .gpio = 15,
444 .active_low = 1,
447 .name = "ppp",
448 .gpio = 22,
449 .active_low = 1,
452 .name = "ppp-fail",
453 .gpio = 23,
454 .active_low = 1,
457 .name = "power",
458 .gpio = 4,
459 .default_trigger = "default-on",
462 .name = "stop",
463 .gpio = 5,
468 static struct board_info __initdata board_96358vw2 = {
469 .name = "96358VW2",
470 .expected_cpu_id = 0x6358,
472 .has_enet0 = 1,
473 .has_enet1 = 1,
474 .has_pci = 1,
476 .enet0 = {
477 .has_phy = 1,
478 .use_internal_phy = 1,
481 .enet1 = {
482 .force_speed_100 = 1,
483 .force_duplex_full = 1,
487 .has_ohci0 = 1,
488 .has_pccard = 1,
489 .has_ehci0 = 1,
491 .leds = {
493 .name = "adsl",
494 .gpio = 22,
495 .active_low = 1,
498 .name = "ppp-fail",
499 .gpio = 23,
502 .name = "power",
503 .gpio = 5,
504 .active_low = 1,
505 .default_trigger = "default-on",
508 .name = "stop",
509 .gpio = 4,
510 .active_low = 1,
515 static struct board_info __initdata board_AGPFS0 = {
516 .name = "AGPF-S0",
517 .expected_cpu_id = 0x6358,
519 .has_enet0 = 1,
520 .has_enet1 = 1,
521 .has_pci = 1,
523 .enet0 = {
524 .has_phy = 1,
525 .use_internal_phy = 1,
528 .enet1 = {
529 .force_speed_100 = 1,
530 .force_duplex_full = 1,
533 .has_ohci0 = 1,
534 .has_ehci0 = 1,
536 #endif
539 * all boards
541 static const struct board_info __initdata *bcm963xx_boards[] = {
542 #ifdef CONFIG_BCM63XX_CPU_6338
543 &board_96338gw,
544 &board_96338w,
545 #endif
546 #ifdef CONFIG_BCM63XX_CPU_6345
547 &board_96345gw2,
548 #endif
549 #ifdef CONFIG_BCM63XX_CPU_6348
550 &board_96348r,
551 &board_96348gw,
552 &board_96348gw_10,
553 &board_96348gw_11,
554 &board_FAST2404,
555 &board_DV201AMR,
556 &board_96348gw_a,
557 #endif
559 #ifdef CONFIG_BCM63XX_CPU_6358
560 &board_96358vw,
561 &board_96358vw2,
562 &board_AGPFS0,
563 #endif
567 * early init callback, read nvram data from flash and checksum it
569 void __init board_prom_init(void)
571 unsigned int check_len, i;
572 u8 *boot_addr, *cfe, *p;
573 char cfe_version[32];
574 u32 val;
576 /* read base address of boot chip select (0)
577 * 6345 does not have MPI but boots from standard
578 * MIPS Flash address */
579 if (BCMCPU_IS_6345())
580 val = 0x1fc00000;
581 else {
582 val = bcm_mpi_readl(MPI_CSBASE_REG(0));
583 val &= MPI_CSBASE_BASE_MASK;
585 boot_addr = (u8 *)KSEG1ADDR(val);
587 /* dump cfe version */
588 cfe = boot_addr + BCM963XX_CFE_VERSION_OFFSET;
589 if (!memcmp(cfe, "cfe-v", 5))
590 snprintf(cfe_version, sizeof(cfe_version), "%u.%u.%u-%u.%u",
591 cfe[5], cfe[6], cfe[7], cfe[8], cfe[9]);
592 else
593 strcpy(cfe_version, "unknown");
594 printk(KERN_INFO PFX "CFE version: %s\n", cfe_version);
596 /* extract nvram data */
597 memcpy(&nvram, boot_addr + BCM963XX_NVRAM_OFFSET, sizeof(nvram));
599 /* check checksum before using data */
600 if (nvram.version <= 4)
601 check_len = offsetof(struct bcm963xx_nvram, checksum_old);
602 else
603 check_len = sizeof(nvram);
604 val = 0;
605 p = (u8 *)&nvram;
606 while (check_len--)
607 val += *p;
608 if (val) {
609 printk(KERN_ERR PFX "invalid nvram checksum\n");
610 return;
613 /* find board by name */
614 for (i = 0; i < ARRAY_SIZE(bcm963xx_boards); i++) {
615 if (strncmp(nvram.name, bcm963xx_boards[i]->name,
616 sizeof(nvram.name)))
617 continue;
618 /* copy, board desc array is marked initdata */
619 memcpy(&board, bcm963xx_boards[i], sizeof(board));
620 break;
623 /* bail out if board is not found, will complain later */
624 if (!board.name[0]) {
625 char name[17];
626 memcpy(name, nvram.name, 16);
627 name[16] = 0;
628 printk(KERN_ERR PFX "unknown bcm963xx board: %s\n",
629 name);
630 return;
633 /* setup pin multiplexing depending on board enabled device,
634 * this has to be done this early since PCI init is done
635 * inside arch_initcall */
636 val = 0;
638 #ifdef CONFIG_PCI
639 if (board.has_pci) {
640 bcm63xx_pci_enabled = 1;
641 if (BCMCPU_IS_6348())
642 val |= GPIO_MODE_6348_G2_PCI;
644 #endif
646 if (board.has_pccard) {
647 if (BCMCPU_IS_6348())
648 val |= GPIO_MODE_6348_G1_MII_PCCARD;
651 if (board.has_enet0 && !board.enet0.use_internal_phy) {
652 if (BCMCPU_IS_6348())
653 val |= GPIO_MODE_6348_G3_EXT_MII |
654 GPIO_MODE_6348_G0_EXT_MII;
657 if (board.has_enet1 && !board.enet1.use_internal_phy) {
658 if (BCMCPU_IS_6348())
659 val |= GPIO_MODE_6348_G3_EXT_MII |
660 GPIO_MODE_6348_G0_EXT_MII;
663 bcm_gpio_writel(val, GPIO_MODE_REG);
667 * second stage init callback, good time to panic if we couldn't
668 * identify on which board we're running since early printk is working
670 void __init board_setup(void)
672 if (!board.name[0])
673 panic("unable to detect bcm963xx board");
674 printk(KERN_INFO PFX "board name: %s\n", board.name);
676 /* make sure we're running on expected cpu */
677 if (bcm63xx_get_cpu_id() != board.expected_cpu_id)
678 panic("unexpected CPU for bcm963xx board");
682 * return board name for /proc/cpuinfo
684 const char *board_get_name(void)
686 return board.name;
690 * register & return a new board mac address
692 static int board_get_mac_address(u8 *mac)
694 u8 *p;
695 int count;
697 if (mac_addr_used >= nvram.mac_addr_count) {
698 printk(KERN_ERR PFX "not enough mac address\n");
699 return -ENODEV;
702 memcpy(mac, nvram.mac_addr_base, ETH_ALEN);
703 p = mac + ETH_ALEN - 1;
704 count = mac_addr_used;
706 while (count--) {
707 do {
708 (*p)++;
709 if (*p != 0)
710 break;
711 p--;
712 } while (p != mac);
715 if (p == mac) {
716 printk(KERN_ERR PFX "unable to fetch mac address\n");
717 return -ENODEV;
720 mac_addr_used++;
721 return 0;
724 static struct mtd_partition mtd_partitions[] = {
726 .name = "cfe",
727 .offset = 0x0,
728 .size = 0x40000,
732 static struct physmap_flash_data flash_data = {
733 .width = 2,
734 .nr_parts = ARRAY_SIZE(mtd_partitions),
735 .parts = mtd_partitions,
738 static struct resource mtd_resources[] = {
740 .start = 0, /* filled at runtime */
741 .end = 0, /* filled at runtime */
742 .flags = IORESOURCE_MEM,
746 static struct platform_device mtd_dev = {
747 .name = "physmap-flash",
748 .resource = mtd_resources,
749 .num_resources = ARRAY_SIZE(mtd_resources),
750 .dev = {
751 .platform_data = &flash_data,
756 * Register a sane SPROMv2 to make the on-board
757 * bcm4318 WLAN work
759 #ifdef CONFIG_SSB_PCIHOST
760 static struct ssb_sprom bcm63xx_sprom = {
761 .revision = 0x02,
762 .board_rev = 0x17,
763 .country_code = 0x0,
764 .ant_available_bg = 0x3,
765 .pa0b0 = 0x15ae,
766 .pa0b1 = 0xfa85,
767 .pa0b2 = 0xfe8d,
768 .pa1b0 = 0xffff,
769 .pa1b1 = 0xffff,
770 .pa1b2 = 0xffff,
771 .gpio0 = 0xff,
772 .gpio1 = 0xff,
773 .gpio2 = 0xff,
774 .gpio3 = 0xff,
775 .maxpwr_bg = 0x004c,
776 .itssi_bg = 0x00,
777 .boardflags_lo = 0x2848,
778 .boardflags_hi = 0x0000,
780 #endif
782 static struct gpio_led_platform_data bcm63xx_led_data;
784 static struct platform_device bcm63xx_gpio_leds = {
785 .name = "leds-gpio",
786 .id = 0,
787 .dev.platform_data = &bcm63xx_led_data,
791 * third stage init callback, register all board devices.
793 int __init board_register_devices(void)
795 u32 val;
797 bcm63xx_uart_register();
799 if (board.has_pccard)
800 bcm63xx_pcmcia_register();
802 if (board.has_enet0 &&
803 !board_get_mac_address(board.enet0.mac_addr))
804 bcm63xx_enet_register(0, &board.enet0);
806 if (board.has_enet1 &&
807 !board_get_mac_address(board.enet1.mac_addr))
808 bcm63xx_enet_register(1, &board.enet1);
810 if (board.has_dsp)
811 bcm63xx_dsp_register(&board.dsp);
813 /* Generate MAC address for WLAN and
814 * register our SPROM */
815 #ifdef CONFIG_SSB_PCIHOST
816 if (!board_get_mac_address(bcm63xx_sprom.il0mac)) {
817 memcpy(bcm63xx_sprom.et0mac, bcm63xx_sprom.il0mac, ETH_ALEN);
818 memcpy(bcm63xx_sprom.et1mac, bcm63xx_sprom.il0mac, ETH_ALEN);
819 if (ssb_arch_set_fallback_sprom(&bcm63xx_sprom) < 0)
820 printk(KERN_ERR "failed to register fallback SPROM\n");
822 #endif
824 /* read base address of boot chip select (0) */
825 if (BCMCPU_IS_6345())
826 val = 0x1fc00000;
827 else {
828 val = bcm_mpi_readl(MPI_CSBASE_REG(0));
829 val &= MPI_CSBASE_BASE_MASK;
831 mtd_resources[0].start = val;
832 mtd_resources[0].end = 0x1FFFFFFF;
834 platform_device_register(&mtd_dev);
836 bcm63xx_led_data.num_leds = ARRAY_SIZE(board.leds);
837 bcm63xx_led_data.leds = board.leds;
839 platform_device_register(&bcm63xx_gpio_leds);
841 return 0;