[brcm63xx] add support for the Pirelli AG226G board (#5337)
[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 * 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
547 static struct board_info __initdata board_DWVS0 = {
548 .name = "DWV-S0",
549 .expected_cpu_id = 0x6358,
550
551 .has_enet0 = 1,
552 .has_enet1 = 1,
553 .has_pci = 1,
554
555 .enet0 = {
556 .has_phy = 1,
557 .use_internal_phy = 1,
558 },
559
560 .enet1 = {
561 .force_speed_100 = 1,
562 .force_duplex_full = 1,
563 },
564
565 .has_ohci0 = 1,
566 };
567 #endif
568
569 /*
570 * all boards
571 */
572 static const struct board_info __initdata *bcm963xx_boards[] = {
573 #ifdef CONFIG_BCM63XX_CPU_6338
574 &board_96338gw,
575 &board_96338w,
576 #endif
577 #ifdef CONFIG_BCM63XX_CPU_6345
578 &board_96345gw2,
579 #endif
580 #ifdef CONFIG_BCM63XX_CPU_6348
581 &board_96348r,
582 &board_96348gw,
583 &board_96348gw_10,
584 &board_96348gw_11,
585 &board_FAST2404,
586 &board_DV201AMR,
587 &board_96348gw_a,
588 #endif
589
590 #ifdef CONFIG_BCM63XX_CPU_6358
591 &board_96358vw,
592 &board_96358vw2,
593 &board_AGPFS0,
594 &board_DWVS0,
595 #endif
596 };
597
598 /*
599 * early init callback, read nvram data from flash and checksum it
600 */
601 void __init board_prom_init(void)
602 {
603 unsigned int check_len, i;
604 u8 *boot_addr, *cfe, *p;
605 char cfe_version[32];
606 u32 val;
607
608 /* read base address of boot chip select (0)
609 * 6345 does not have MPI but boots from standard
610 * MIPS Flash address */
611 if (BCMCPU_IS_6345())
612 val = 0x1fc00000;
613 else {
614 val = bcm_mpi_readl(MPI_CSBASE_REG(0));
615 val &= MPI_CSBASE_BASE_MASK;
616 }
617 boot_addr = (u8 *)KSEG1ADDR(val);
618
619 /* dump cfe version */
620 cfe = boot_addr + BCM963XX_CFE_VERSION_OFFSET;
621 if (!memcmp(cfe, "cfe-v", 5))
622 snprintf(cfe_version, sizeof(cfe_version), "%u.%u.%u-%u.%u",
623 cfe[5], cfe[6], cfe[7], cfe[8], cfe[9]);
624 else
625 strcpy(cfe_version, "unknown");
626 printk(KERN_INFO PFX "CFE version: %s\n", cfe_version);
627
628 /* extract nvram data */
629 memcpy(&nvram, boot_addr + BCM963XX_NVRAM_OFFSET, sizeof(nvram));
630
631 /* check checksum before using data */
632 if (nvram.version <= 4)
633 check_len = offsetof(struct bcm963xx_nvram, checksum_old);
634 else
635 check_len = sizeof(nvram);
636 val = 0;
637 p = (u8 *)&nvram;
638 while (check_len--)
639 val += *p;
640 if (val) {
641 printk(KERN_ERR PFX "invalid nvram checksum\n");
642 return;
643 }
644
645 /* find board by name */
646 for (i = 0; i < ARRAY_SIZE(bcm963xx_boards); i++) {
647 if (strncmp(nvram.name, bcm963xx_boards[i]->name,
648 sizeof(nvram.name)))
649 continue;
650 /* copy, board desc array is marked initdata */
651 memcpy(&board, bcm963xx_boards[i], sizeof(board));
652 break;
653 }
654
655 /* bail out if board is not found, will complain later */
656 if (!board.name[0]) {
657 char name[17];
658 memcpy(name, nvram.name, 16);
659 name[16] = 0;
660 printk(KERN_ERR PFX "unknown bcm963xx board: %s\n",
661 name);
662 return;
663 }
664
665 /* setup pin multiplexing depending on board enabled device,
666 * this has to be done this early since PCI init is done
667 * inside arch_initcall */
668 val = 0;
669 #ifdef CONFIG_PCI
670 if (board.has_pci) {
671 bcm63xx_pci_enabled = 1;
672 if (BCMCPU_IS_6348())
673 val |= GPIO_MODE_6348_G2_PCI;
674 }
675 #endif
676 if (board.has_pccard) {
677 if (BCMCPU_IS_6348())
678 val |= GPIO_MODE_6348_G1_MII_PCCARD;
679 }
680
681 if (board.has_enet0 && !board.enet0.use_internal_phy) {
682 if (BCMCPU_IS_6348())
683 val |= GPIO_MODE_6348_G3_EXT_MII |
684 GPIO_MODE_6348_G0_EXT_MII;
685 }
686
687 if (board.has_enet1 && !board.enet1.use_internal_phy) {
688 if (BCMCPU_IS_6348())
689 val |= GPIO_MODE_6348_G3_EXT_MII |
690 GPIO_MODE_6348_G0_EXT_MII;
691 }
692
693 bcm_gpio_writel(val, GPIO_MODE_REG);
694 }
695
696 /*
697 * second stage init callback, good time to panic if we couldn't
698 * identify on which board we're running since early printk is working
699 */
700 void __init board_setup(void)
701 {
702 if (!board.name[0])
703 panic("unable to detect bcm963xx board");
704 printk(KERN_INFO PFX "board name: %s\n", board.name);
705
706 /* make sure we're running on expected cpu */
707 if (bcm63xx_get_cpu_id() != board.expected_cpu_id)
708 panic("unexpected CPU for bcm963xx board");
709 }
710
711 /*
712 * return board name for /proc/cpuinfo
713 */
714 const char *board_get_name(void)
715 {
716 return board.name;
717 }
718
719 /*
720 * register & return a new board mac address
721 */
722 static int board_get_mac_address(u8 *mac)
723 {
724 u8 *p;
725 int count;
726
727 if (mac_addr_used >= nvram.mac_addr_count) {
728 printk(KERN_ERR PFX "not enough mac address\n");
729 return -ENODEV;
730 }
731
732 memcpy(mac, nvram.mac_addr_base, ETH_ALEN);
733 p = mac + ETH_ALEN - 1;
734 count = mac_addr_used;
735
736 while (count--) {
737 do {
738 (*p)++;
739 if (*p != 0)
740 break;
741 p--;
742 } while (p != mac);
743 }
744
745 if (p == mac) {
746 printk(KERN_ERR PFX "unable to fetch mac address\n");
747 return -ENODEV;
748 }
749
750 mac_addr_used++;
751 return 0;
752 }
753
754 static struct resource mtd_resources[] = {
755 {
756 .start = 0, /* filled at runtime */
757 .end = 0, /* filled at runtime */
758 .flags = IORESOURCE_MEM,
759 }
760 };
761
762 static struct platform_device mtd_dev = {
763 .name = "bcm963xx-flash",
764 .resource = mtd_resources,
765 .num_resources = ARRAY_SIZE(mtd_resources),
766 };
767
768 /*
769 * Register a sane SPROMv2 to make the on-board
770 * bcm4318 WLAN work
771 */
772 static struct ssb_sprom bcm63xx_sprom = {
773 .revision = 0x02,
774 .board_rev = 0x17,
775 .country_code = 0x0,
776 .ant_available_bg = 0x3,
777 .pa0b0 = 0x15ae,
778 .pa0b1 = 0xfa85,
779 .pa0b2 = 0xfe8d,
780 .pa1b0 = 0xffff,
781 .pa1b1 = 0xffff,
782 .pa1b2 = 0xffff,
783 .gpio0 = 0xff,
784 .gpio1 = 0xff,
785 .gpio2 = 0xff,
786 .gpio3 = 0xff,
787 .maxpwr_bg = 0x004c,
788 .itssi_bg = 0x00,
789 .boardflags_lo = 0x2848,
790 .boardflags_hi = 0x0000,
791 };
792
793 static struct resource gpiodev_resource = {
794 .start = 0xFFFFFFFF,
795 };
796
797 static struct gpio_led_platform_data bcm63xx_led_data;
798
799 static struct platform_device bcm63xx_gpio_leds = {
800 .name = "leds-gpio",
801 .id = 0,
802 .dev.platform_data = &bcm63xx_led_data,
803 };
804
805 /*
806 * third stage init callback, register all board devices.
807 */
808 int __init board_register_devices(void)
809 {
810 u32 val;
811
812 bcm63xx_uart_register();
813 bcm63xx_wdt_register();
814
815 if (!BCMCPU_IS_6345())
816 bcm63xx_spi_register();
817
818 if (board.has_pccard)
819 bcm63xx_pcmcia_register();
820
821 if (board.has_enet0 &&
822 !board_get_mac_address(board.enet0.mac_addr))
823 bcm63xx_enet_register(0, &board.enet0);
824
825 if (board.has_enet1 &&
826 !board_get_mac_address(board.enet1.mac_addr))
827 bcm63xx_enet_register(1, &board.enet1);
828
829 if (board.has_ohci0)
830 bcm63xx_ohci_register();
831
832 if (board.has_ehci0)
833 bcm63xx_ehci_register();
834
835 if (board.has_udc0)
836 bcm63xx_udc_register();
837
838 if (board.has_dsp)
839 bcm63xx_dsp_register(&board.dsp);
840
841 /* Generate MAC address for WLAN and
842 * register our SPROM */
843 #ifdef CONFIG_PCI
844 if (!board_get_mac_address(bcm63xx_sprom.il0mac)) {
845 memcpy(bcm63xx_sprom.et0mac, bcm63xx_sprom.il0mac, ETH_ALEN);
846 memcpy(bcm63xx_sprom.et1mac, bcm63xx_sprom.il0mac, ETH_ALEN);
847 if (ssb_arch_set_fallback_sprom(&bcm63xx_sprom) < 0)
848 printk(KERN_ERR "failed to register fallback SPROM\n");
849 }
850 #endif
851
852 /* read base address of boot chip select (0) */
853 if (BCMCPU_IS_6345())
854 val = 0x1fc00000;
855 else {
856 val = bcm_mpi_readl(MPI_CSBASE_REG(0));
857 val &= MPI_CSBASE_BASE_MASK;
858 }
859 mtd_resources[0].start = val;
860 mtd_resources[0].end = 0x1FFFFFFF;
861
862 platform_device_register(&mtd_dev);
863
864 /* Register GPIODEV */
865 platform_device_register_simple("GPIODEV", 0, &gpiodev_resource, 1);
866
867 bcm63xx_led_data.num_leds = ARRAY_SIZE(board.leds);
868 bcm63xx_led_data.leds = board.leds;
869
870 platform_device_register(&bcm63xx_gpio_leds);
871
872 return 0;
873 }
874
This page took 0.090737 seconds and 5 git commands to generate.