[lantiq]
[openwrt/svn-archive/archive.git] / target / linux / lantiq / patches-2.6.39 / 601-mach-gigasx76x.patch
1 --- a/arch/mips/lantiq/xway/Kconfig
2 +++ b/arch/mips/lantiq/xway/Kconfig
3 @@ -14,6 +14,11 @@ config LANTIQ_MACH_NETGEAR
4 bool "Netgear"
5 default y
6
7 +config LANTIQ_MACH_GIGASX76X
8 + bool "GIGASX76X"
9 + select LTQ_DEV_GPIO_BUTTONS
10 + default y
11 +
12 endmenu
13
14 endif
15 --- a/arch/mips/lantiq/xway/Makefile
16 +++ b/arch/mips/lantiq/xway/Makefile
17 @@ -7,4 +7,5 @@ obj-$(CONFIG_LANTIQ_MACH_EASY50712) += m
18 obj-$(CONFIG_LANTIQ_MACH_EASY50601) += mach-easy50601.o
19 obj-$(CONFIG_LANTIQ_MACH_ARV45XX) += mach-arv45xx.o
20 obj-$(CONFIG_LANTIQ_MACH_NETGEAR) += mach-netgear.o
21 +obj-$(CONFIG_LANTIQ_MACH_GIGASX76X) += mach-gigasx76x.o
22 obj-y += dev-dwc_otg.o
23 --- /dev/null
24 +++ b/arch/mips/lantiq/xway/mach-gigasx76x.c
25 @@ -0,0 +1,209 @@
26 +/*
27 + * This program is free software; you can redistribute it and/or modify it
28 + * under the terms of the GNU General Public License version 2 as published
29 + * by the Free Software Foundation.
30 + *
31 + * Copyright (C) 2011 Andrej Vlašić
32 + * Copyright (C) 2011 Luka Perkov
33 + *
34 + */
35 +
36 +#include <linux/kernel.h>
37 +#include <linux/init.h>
38 +#include <linux/platform_device.h>
39 +#include <linux/leds.h>
40 +#include <linux/gpio.h>
41 +#include <linux/mtd/mtd.h>
42 +#include <linux/mtd/partitions.h>
43 +#include <linux/mtd/physmap.h>
44 +#include <linux/input.h>
45 +#include <linux/ath5k_platform.h>
46 +#include <linux/pci.h>
47 +#include <linux/phy.h>
48 +#include <linux/io.h>
49 +#include <linux/string.h>
50 +
51 +#include <irq.h>
52 +
53 +#include <lantiq_soc.h>
54 +#include <lantiq_platform.h>
55 +
56 +#include "devices.h"
57 +#include "dev-dwc_otg.h"
58 +#include "../machtypes.h"
59 +#include "../dev-leds-gpio.h"
60 +#include "../dev-gpio-buttons.h"
61 +
62 +#define UBOOT_ENV_OFFSET 0x010000
63 +#define UBOOT_ENV_SIZE 0x010000
64 +
65 +#ifdef CONFIG_MTD_PARTITIONS
66 +static struct mtd_partition gigasx76x_partitions[] =
67 +{
68 + {
69 + .name = "uboot",
70 + .offset = 0x000000,
71 + .size = 0x010000,
72 + },
73 + {
74 + .name = "uboot_env",
75 + .offset = UBOOT_ENV_OFFSET,
76 + .size = UBOOT_ENV_SIZE,
77 + },
78 + {
79 + .name = "linux",
80 + .offset = 0x020000,
81 + .size = 0x7d0000,
82 + },
83 + {
84 + .name = "board_config",
85 + .offset = 0x7f0000,
86 + .size = 0x010000,
87 + },
88 +};
89 +#endif
90 +
91 +static struct gpio_led
92 +gigasx76x_gpio_leds[] __initdata = {
93 + { .name = "soc:green:usb", .gpio = 50, },
94 + { .name = "soc:green:wlan", .gpio = 51, },
95 + { .name = "soc:green:phone2", .gpio = 52, },
96 + { .name = "soc:green:phone1", .gpio = 53, },
97 + { .name = "soc:green:line", .gpio = 54, },
98 + { .name = "soc:green:online", .gpio = 55, },
99 + { .name = "soc:green:voip", .gpio = 56, },
100 +};
101 +
102 +static struct gpio_keys_button
103 +gigasx76x_gpio_keys[] __initdata = {
104 + {
105 + .desc = "reset",
106 + .type = EV_KEY,
107 + .code = KEY_RESTART,
108 + .debounce_interval = LTQ_KEYS_DEBOUNCE_INTERVAL,
109 + .gpio = 14,
110 + .active_low = 1,
111 + },
112 +};
113 +
114 +static struct physmap_flash_data gigasx76x_flash_data = {
115 +#ifdef CONFIG_MTD_PARTITIONS
116 + .nr_parts = ARRAY_SIZE(gigasx76x_partitions),
117 + .parts = gigasx76x_partitions,
118 +#endif
119 +};
120 +
121 +static struct ltq_pci_data ltq_pci_data = {
122 + .clock = PCI_CLOCK_INT,
123 + .gpio = PCI_GNT1 | PCI_REQ1,
124 + .irq = { [14] = INT_NUM_IM0_IRL0 + 22, },
125 +};
126 +
127 +static struct ltq_eth_data ltq_eth_data = {
128 + .mii_mode = PHY_INTERFACE_MODE_MII,
129 +};
130 +
131 +static char __init *get_uboot_env_var(char *haystack, int haystack_len, char *needle, int needle_len) {
132 + int i;
133 + for (i = 0; i <= haystack_len - needle_len; i++) {
134 + if (memcmp(haystack + i, needle, needle_len) == 0) {
135 + return haystack + i + needle_len;
136 + }
137 + }
138 + return NULL;
139 +}
140 +
141 +/*
142 + * gigasx76x_parse_hex_* are not uniq. in arm/orion there are also duplicates:
143 + * dns323_parse_hex_*
144 + * TODO: one day write a patch for this :)
145 + */
146 +static int __init gigasx76x_parse_hex_nibble(char n) {
147 + if (n >= '0' && n <= '9')
148 + return n - '0';
149 +
150 + if (n >= 'A' && n <= 'F')
151 + return n - 'A' + 10;
152 +
153 + if (n >= 'a' && n <= 'f')
154 + return n - 'a' + 10;
155 +
156 + return -1;
157 +}
158 +
159 +static int __init gigasx76x_parse_hex_byte(const char *b) {
160 + int hi;
161 + int lo;
162 +
163 + hi = gigasx76x_parse_hex_nibble(b[0]);
164 + lo = gigasx76x_parse_hex_nibble(b[1]);
165 +
166 + if (hi < 0 || lo < 0)
167 + return -1;
168 +
169 + return (hi << 4) | lo;
170 +}
171 +
172 +static int __init gigasx76x_register_ethernet(void) {
173 + u_int8_t addr[6];
174 + int i;
175 + char *uboot_env_page;
176 + char *mac;
177 +
178 + uboot_env_page = ioremap(LTQ_FLASH_START + UBOOT_ENV_OFFSET, UBOOT_ENV_SIZE);
179 + if (!uboot_env_page)
180 + return -ENOMEM;
181 +
182 + mac = get_uboot_env_var(uboot_env_page, UBOOT_ENV_SIZE, "\0ethaddr=", 9);
183 +
184 + if (!mac) {
185 + goto error_fail;
186 + }
187 +
188 + /* Sanity check the string we're looking at */
189 + for (i = 0; i < 5; i++) {
190 + if (*(mac + (i * 3) + 2) != ':') {
191 + goto error_fail;
192 + }
193 + }
194 +
195 + for (i = 0; i < 6; i++) {
196 + int byte;
197 + byte = gigasx76x_parse_hex_byte(mac + (i * 3));
198 + if (byte < 0) {
199 + goto error_fail;
200 + }
201 + addr[i] = byte;
202 + }
203 +
204 + iounmap(uboot_env_page);
205 + printk("GIGASX76X: Found ethernet MAC address: ");
206 + for (i = 0; i < 6; i++)
207 + printk("%.2x%s", addr[i], (i < 5) ? ":" : ".\n");
208 +
209 + memcpy(&ltq_eth_data.mac.sa_data, addr, 6);
210 + ltq_register_etop(&ltq_eth_data);
211 +
212 + return 0;
213 +
214 + error_fail:
215 + iounmap(uboot_env_page);
216 + return -EINVAL;
217 +}
218 +
219 +static void __init gigasx76x_init(void) {
220 +#define GIGASX76X_USB 29
221 +#define GIGASX76X_MADWIFI_ADDR 0xb07f0000
222 +
223 + ltq_register_gpio_stp();
224 + ltq_register_nor(&gigasx76x_flash_data);
225 + ltq_register_pci(&ltq_pci_data);
226 + gigasx76x_register_ethernet();
227 + xway_register_dwc(GIGASX76X_USB);
228 + ltq_register_tapi();
229 + ltq_register_madwifi_eep(GIGASX76X_MADWIFI_ADDR);
230 + ltq_add_device_leds_gpio(-1, ARRAY_SIZE(gigasx76x_gpio_leds), gigasx76x_gpio_leds);
231 + ltq_register_gpio_keys_polled(-1, LTQ_KEYS_POLL_INTERVAL, ARRAY_SIZE(gigasx76x_gpio_keys), gigasx76x_gpio_keys);
232 +}
233 +
234 +MIPS_MACHINE(LANTIQ_MACH_GIGASX76X, "GIGASX76X", "GIGASX76X - Gigaset SX761,SX762,SX763", gigasx76x_init);
235 --- a/arch/mips/lantiq/machtypes.h
236 +++ b/arch/mips/lantiq/machtypes.h
237 @@ -37,6 +37,9 @@ enum lantiq_mach_type {
238
239 /* Netgear */
240 LANTIQ_MACH_DGN3500B, /* Netgear DGN3500 */
241 +
242 + /* Gigaset */
243 + LANTIQ_MACH_GIGASX76X, /* Gigaset SX76x */
244 };
245
246 #endif