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