[adm5120] experimental support for 2.6.27
[15.05/openwrt.git] / target / linux / adm5120 / files / arch / mips / adm5120 / motorola / pmugw.c
1 /*
2  *  Motorola Powerline MU Gateway board
3  *
4  *  Copyright (C) 2008 Gabor Juhos <juhosg@openwrt.org>
5  *
6  *  This program is free software; you can redistribute it and/or modify it
7  *  under the terms of the GNU General Public License version 2 as published
8  *  by the Free Software Foundation.
9  *
10  */
11
12 #include <linux/kernel.h>
13 #include <linux/init.h>
14 #include <linux/gpio.h>
15 #include <linux/irq.h>
16 #include <linux/etherdevice.h>
17
18 #include <asm/bootinfo.h>
19
20 #include <asm/mach-adm5120/adm5120_defs.h>
21 #include <asm/mach-adm5120/adm5120_board.h>
22 #include <asm/mach-adm5120/adm5120_platform.h>
23 #include <asm/mach-adm5120/adm5120_info.h>
24
25 #include <prom/admboot.h>
26
27 #define PMUGW_CONFIG_OFFSET     0x10000
28 #define PMUGW_CONFIG_SIZE       0x1000
29
30 #ifdef CONFIG_MTD_PARTITIONS
31 static struct mtd_partition pmugw_partitions[] = {
32         {
33                 .name   = "admboot",
34                 .offset = 0,
35                 .size   = 64*1024,
36                 .mask_flags = MTD_WRITEABLE,
37         } , {
38                 .name   = "boardcfg",
39                 .offset = MTDPART_OFS_APPEND,
40                 .size   = 64*1024,
41         } , {
42                 .name   = "firmware",
43                 .offset = MTDPART_OFS_APPEND,
44                 .size   = MTDPART_SIZ_FULL,
45         }
46 };
47 #endif /* CONFIG_MTD_PARTITIONS */
48
49 static u8 pmugw_vlans[6] __initdata = {
50         0x41, 0x42, 0x44, 0x48, 0x50, 0x00
51 };
52
53 static __init void pmugw_setup_mac(void)
54 {
55         u8 mac_base[6];
56         int err;
57
58         err = admboot_get_mac_base(PMUGW_CONFIG_OFFSET,
59                                    PMUGW_CONFIG_SIZE, mac_base);
60
61         if ((err) || !is_valid_ether_addr(mac_base))
62                 random_ether_addr(mac_base);
63
64         adm5120_setup_eth_macs(mac_base);
65 }
66
67 static void switch_bank_gpio5(unsigned bank)
68 {
69         switch (bank) {
70         case 0:
71                 gpio_set_value(ADM5120_GPIO_PIN5, 0);
72                 break;
73         case 1:
74                 gpio_set_value(ADM5120_GPIO_PIN5, 1);
75                 break;
76         }
77 }
78
79 void __init pmugw_setup(void)
80 {
81         /* setup flash A20 line */
82         gpio_request(ADM5120_GPIO_PIN5, NULL);
83         gpio_direction_output(ADM5120_GPIO_PIN5, 0);
84         adm5120_flash0_data.switch_bank = switch_bank_gpio5;
85
86 #ifdef CONFIG_MTD_PARTITIONS
87         adm5120_flash0_data.nr_parts = ARRAY_SIZE(pmugw_partitions);
88         adm5120_flash0_data.parts = pmugw_partitions;
89 #endif /* CONFIG_MTD_PARTITIONS */
90
91         adm5120_add_device_uart(1); /* ttyS0 */
92         adm5120_add_device_uart(0); /* ttyS1 */
93
94         adm5120_add_device_flash(0);
95
96         pmugw_setup_mac();
97         adm5120_add_device_switch(5, pmugw_vlans);
98 }
99
100 ADM5120_BOARD(MACH_ADM5120_PMUGW,
101                 "Motorola Powerline MU Gateway",
102                 pmugw_setup);