[lantiq] dgn3500 support with eeprom loading from sysfs
[openwrt.git] / target / linux / lantiq / files-3.2 / arch / mips / lantiq / xway / mach-gigasx76x.c
1 /*
2  *  This program is free software; you can redistribute it and/or modify it
3  *  under the terms of the GNU General Public License version 2 as published
4  *  by the Free Software Foundation.
5  *
6  *  Copyright (C) 2011 Andrej Vlašić
7  *  Copyright (C) 2011 Luka Perkov
8  *
9  */
10
11 #include <linux/kernel.h>
12 #include <linux/init.h>
13 #include <linux/platform_device.h>
14 #include <linux/leds.h>
15 #include <linux/gpio.h>
16 #include <linux/mtd/mtd.h>
17 #include <linux/mtd/partitions.h>
18 #include <linux/mtd/physmap.h>
19 #include <linux/input.h>
20 #include <linux/ath5k_platform.h>
21 #include <linux/pci.h>
22 #include <linux/phy.h>
23 #include <linux/io.h>
24 #include <linux/if_ether.h>
25 #include <linux/etherdevice.h>
26 #include <linux/string.h>
27
28 #include <irq.h>
29 #include <lantiq_soc.h>
30 #include <lantiq_platform.h>
31 #include <dev-gpio-leds.h>
32 #include <dev-gpio-buttons.h>
33
34 #include "../machtypes.h"
35 #include "dev-wifi-athxk.h"
36 #include "devices.h"
37 #include "dev-dwc_otg.h"
38
39 #include "mach-gigasx76x.h"
40
41 static u8 ltq_ethaddr[6] = { 0 };
42
43 static int __init setup_ethaddr(char *str)
44 {
45         if (!mac_pton(str, ltq_ethaddr))
46                 memset(ltq_ethaddr, 0, 6);
47         return 0;
48 }
49 __setup("ethaddr=", setup_ethaddr);
50
51
52 enum {
53         UNKNOWN = 0,
54         SX761,
55         SX762,
56         SX763,
57 };
58 static u8 board = SX763;
59
60 static int __init setup_board(char *str)
61 {
62         if (!strcmp(str, "sx761"))
63                 board = SX761;
64         else if (!strcmp(str, "sx762"))
65                 board = SX762;
66         else if (!strcmp(str, "sx763"))
67                 board = SX763;
68         else
69                 board = UNKNOWN;
70         return 0;
71 }
72 __setup("board=", setup_board);
73
74 static struct mtd_partition gigasx76x_partitions[] =
75 {
76         {
77                 .name   = "uboot",
78                 .offset = 0x0,
79                 .size   = 0x10000,
80         },
81         {
82                 .name   = "uboot_env",
83                 .offset = 0x10000,
84                 .size   = 0x10000,
85         },
86         {
87                 .name   = "linux",
88                 .offset = 0x20000,
89                 .size   = 0x7e0000,
90         },
91 };
92
93 static struct gpio_led
94 gigasx76x_gpio_leds[] __initdata = {
95         { .name = "soc:green:voip", .gpio = 216, },
96         { .name = "soc:green:adsl", .gpio = 217, },
97         { .name = "soc:green:usb", .gpio = 218, },
98         { .name = "soc:green:wifi", .gpio = 219, },
99         { .name = "soc:green:phone2", .gpio = 220, },
100         { .name = "soc:green:phone1", .gpio = 221, },
101         { .name = "soc:green:line", .gpio = 222, },
102         { .name = "soc:green:online", .gpio = 223, },
103 };
104
105 static struct gpio_keys_button
106 gigasx76x_gpio_keys[] __initdata = {
107         {
108                 .desc           = "wps",
109                 .type           = EV_KEY,
110                 .code           = KEY_WPS_BUTTON,
111                 .debounce_interval = LTQ_KEYS_DEBOUNCE_INTERVAL,
112                 .gpio           = 22,
113                 .active_low     = 1,
114         },
115         {
116                 .desc           = "reset",
117                 .type           = EV_KEY,
118                 .code           = BTN_0,
119                 .debounce_interval = LTQ_KEYS_DEBOUNCE_INTERVAL,
120                 .gpio           = 14,
121                 .active_low     = 0,
122         },
123 };
124
125 static struct physmap_flash_data gigasx76x_flash_data = {
126         .nr_parts       = ARRAY_SIZE(gigasx76x_partitions),
127         .parts          = gigasx76x_partitions,
128 };
129
130 static struct ltq_pci_data ltq_pci_data = {
131         .clock  = PCI_CLOCK_INT,
132         .gpio   = PCI_GNT1 | PCI_REQ1,
133         .irq    = { [14] = INT_NUM_IM0_IRL0 + 22, },
134 };
135
136 static struct ltq_eth_data ltq_eth_data = {
137         .mii_mode       = PHY_INTERFACE_MODE_MII,
138 };
139
140 static void __init gigasx76x_init(void)
141 {
142 #define GIGASX76X_USB           29
143
144         ltq_register_gpio_stp();
145         ltq_register_nor(&gigasx76x_flash_data);
146         ltq_register_pci(&ltq_pci_data);
147         ltq_register_tapi();
148         ltq_add_device_gpio_leds(-1, ARRAY_SIZE(gigasx76x_gpio_leds), gigasx76x_gpio_leds);
149         ltq_register_gpio_keys_polled(-1, LTQ_KEYS_POLL_INTERVAL, ARRAY_SIZE(gigasx76x_gpio_keys), gigasx76x_gpio_keys);
150         xway_register_dwc(GIGASX76X_USB);
151
152         if (!is_valid_ether_addr(ltq_ethaddr))
153                 random_ether_addr(ltq_ethaddr);
154
155         memcpy(&ltq_eth_data.mac.sa_data, ltq_ethaddr, 6);
156         ltq_register_etop(&ltq_eth_data);
157         if (board == SX762) 
158                 ltq_register_ath5k(sx762_eeprom_data, ltq_ethaddr);
159         else
160                 ltq_register_ath5k(sx763_eeprom_data, ltq_ethaddr);
161 }
162
163 MIPS_MACHINE(LANTIQ_MACH_GIGASX76X,
164                         "GIGASX76X",
165                         "GIGASX76X - Gigaset SX761,SX762,SX763",
166                         gigasx76x_init);