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