c62c147c5af34afa0fa4c7b65e69d18dd2ac438a
[openwrt.git] / target / linux / adm5120 / files / arch / mips / adm5120 / generic / eb-214a.c
1 /*
2  *  EB-214A board support
3  *
4  *  Copyright (C) 2007-2008 Gabor Juhos <juhosg@openwrt.org>
5  *  Copyright (C) 2010 Cezary Jackiewicz <cezary@eko.one.pl>
6  *
7  *  This program is free software; you can redistribute it and/or modify it
8  *  under the terms of the GNU General Public License version 2 as published
9  *  by the Free Software Foundation.
10  *
11  */
12
13 #include <asm/addrspace.h>
14 #include <asm/byteorder.h>
15 #include <linux/kernel.h>
16 #include <linux/init.h>
17 #include <linux/gpio.h>
18 #include <linux/irq.h>
19 #include <linux/etherdevice.h>
20
21 #include <asm/mips_machine.h>
22
23 #include <asm/mach-adm5120/adm5120_info.h>
24 #include <asm/mach-adm5120/adm5120_platform.h>
25 #include <asm/mach-adm5120/adm5120_defs.h>
26
27
28 #define EB214A_GPIO_DEV_MASK    0
29 #define EB214A_CONFIG_OFFSET    0x4000
30
31 #define EB214A_KEYS_POLL_INTERVAL       20
32 #define EB214A_KEYS_DEBOUNCE_INTERVAL   (3 * EB214A_KEYS_POLL_INTERVAL)
33
34 static struct mtd_partition eb214a_partitions[] = {
35         {
36                 .name   = "bootloader",
37                 .offset = 0,
38                 .size   = 32*1024,
39                 .mask_flags = MTD_WRITEABLE,
40         } , {
41                 .name   = "config",
42                 .offset = MTDPART_OFS_APPEND,
43                 .size   = 32*1024,
44         } , {
45                 .name   = "firmware",
46                 .offset = MTDPART_OFS_APPEND,
47                 .size   = MTDPART_SIZ_FULL,
48         }
49 };
50
51 static struct adm5120_pci_irq eb214a_pci_irqs[] __initdata = {
52         PCIIRQ(4, 0, 1, ADM5120_IRQ_PCI0),
53         PCIIRQ(4, 1, 2, ADM5120_IRQ_PCI0),
54         PCIIRQ(4, 2, 3, ADM5120_IRQ_PCI0),
55 };
56
57 static struct gpio_led eb214a_gpio_leds[] __initdata = {
58         GPIO_LED_INV(ADM5120_GPIO_PIN7, "power",        NULL),
59         GPIO_LED_INV(ADM5120_GPIO_P0L0, "lan",          NULL),
60         GPIO_LED_INV(ADM5120_GPIO_P4L0, "usb1",         NULL),
61         GPIO_LED_INV(ADM5120_GPIO_P4L1, "usb2",         NULL),
62         GPIO_LED_INV(ADM5120_GPIO_P4L2, "usb3",         NULL),
63         GPIO_LED_INV(ADM5120_GPIO_P3L0, "usb4",         NULL),
64 };
65
66 static struct gpio_keys_button eb214a_gpio_buttons[] __initdata = {
67         {
68                 .desc           = "reset",
69                 .type           = EV_KEY,
70                 .code           = KEY_RESTART,
71                 .debounce_interval = EB214A_KEYS_DEBOUNCE_INTERVAL,
72                 .gpio           = ADM5120_GPIO_PIN1,
73         }
74 };
75
76 static u8 eb214a_vlans[6] __initdata = {
77         0x41, 0x42, 0x44, 0x48, 0x50, 0x00
78 };
79
80 static void __init eb214a_mac_setup(void)
81 {
82         u8 mac_base[6];
83         u8 *cfg;
84         int i;
85
86         cfg = (u8 *) KSEG1ADDR(ADM5120_SRAM0_BASE + EB214A_CONFIG_OFFSET);
87         for (i = 0; i < 6; i++)
88                 mac_base[i] = cfg[i];
89
90         if (!is_valid_ether_addr(mac_base))
91                 random_ether_addr(mac_base);
92
93         adm5120_setup_eth_macs(mac_base);
94 }
95
96 static void __init eb214a_setup(void)
97 {
98         adm5120_flash0_data.nr_parts = ARRAY_SIZE(eb214a_partitions);
99         adm5120_flash0_data.parts = eb214a_partitions;
100         adm5120_add_device_flash(0);
101
102         adm5120_add_device_gpio(EB214A_GPIO_DEV_MASK);
103
104         adm5120_add_device_uart(0);
105         /* adm5120_add_device_uart(1); */
106
107         adm5120_add_device_switch(5, eb214a_vlans);
108
109         eb214a_mac_setup();
110
111         adm5120_register_gpio_buttons(-1, EB214A_KEYS_POLL_INTERVAL,
112                                       ARRAY_SIZE(eb214a_gpio_buttons),
113                                       eb214a_gpio_buttons);
114
115         adm5120_add_device_gpio_leds(ARRAY_SIZE(eb214a_gpio_leds),
116                                         eb214a_gpio_leds);
117
118         adm5120_pci_set_irq_map(ARRAY_SIZE(eb214a_pci_irqs),
119                                         eb214a_pci_irqs);
120         /* adm5120_add_device_usb(); */
121 }
122
123 MIPS_MACHINE(MACH_ADM5120_EB_214A, "EB-214A", "Generic EB-214A", eb214a_setup);