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