fix the wan phy on the GW2355 - thanks, Chris ;)
[openwrt.git] / target / linux / ixp4xx / patches-2.6.24 / 300-avila_fetch_mac.patch
1 Index: linux-2.6.24.2/arch/arm/mach-ixp4xx/avila-setup.c
2 ===================================================================
3 --- linux-2.6.24.2.orig/arch/arm/mach-ixp4xx/avila-setup.c
4 +++ linux-2.6.24.2/arch/arm/mach-ixp4xx/avila-setup.c
5 @@ -14,10 +14,18 @@
6 #include <linux/kernel.h>
7 #include <linux/init.h>
8 #include <linux/device.h>
9 +#include <linux/if_ether.h>
10 +#include <linux/socket.h>
11 +#include <linux/netdevice.h>
12 #include <linux/serial.h>
13 #include <linux/tty.h>
14 #include <linux/serial_8250.h>
15 #include <linux/slab.h>
16 +#ifdef CONFIG_SENSORS_EEPROM
17 +# include <linux/i2c.h>
18 +# include <linux/eeprom.h>
19 +#endif
20 +
21 #include <linux/i2c-gpio.h>
22
23 #include <asm/types.h>
24 @@ -29,6 +37,13 @@
25 #include <asm/mach/arch.h>
26 #include <asm/mach/flash.h>
27
28 +struct avila_board_info {
29 + unsigned char *model;
30 + void (* setup)(void);
31 +};
32 +
33 +static struct avila_board_info *avila_info __initdata;
34 +
35 static struct flash_platform_data avila_flash_data = {
36 .map_name = "cfi_probe",
37 .width = 2,
38 @@ -192,10 +207,160 @@ static void __init avila_fixup(struct ma
39 t->hdr.size = 0;
40 }
41
42 +static void __init avila_gw23xx_setup(void)
43 +{
44 + platform_device_register(&avila_npeb_device);
45 + platform_device_register(&avila_npec_device);
46 +}
47 +
48 +#ifdef CONFIG_SENSORS_EEPROM
49 +static void __init avila_gw2342_setup(void)
50 +{
51 + platform_device_register(&avila_npeb_device);
52 + platform_device_register(&avila_npec_device);
53 +}
54 +
55 +static void __init avila_gw2345_setup(void)
56 +{
57 + avila_npeb_data.phy = IXP4XX_ETH_PHY_MAX_ADDR;
58 + avila_npeb_data.phy_mask = 0x1e; /* ports 1-4 of the KS8995 switch */
59 + platform_device_register(&avila_npeb_device);
60 +
61 + avila_npec_data.phy = 5; /* port 5 of the KS8995 switch */
62 + platform_device_register(&avila_npec_device);
63 +}
64 +
65 +static void __init avila_gw2347_setup(void)
66 +{
67 + platform_device_register(&avila_npeb_device);
68 +}
69 +
70 +static void __init avila_gw2348_setup(void)
71 +{
72 + platform_device_register(&avila_npeb_device);
73 + platform_device_register(&avila_npec_device);
74 +}
75 +
76 +static void __init avila_gw2353_setup(void)
77 +{
78 + platform_device_register(&avila_npeb_device);
79 +}
80 +
81 +static void __init avila_gw2355_setup(void)
82 +{
83 + avila_npeb_data.phy = IXP4XX_ETH_PHY_MAX_ADDR;
84 + avila_npeb_data.phy_mask = 0x1e; /* ports 1-4 of the KS8995 switch */
85 + platform_device_register(&avila_npeb_device);
86 +
87 + avila_npec_data.phy = 16;
88 + platform_device_register(&avila_npec_device);
89 +}
90 +
91 +static void __init avila_gw2357_setup(void)
92 +{
93 + platform_device_register(&avila_npeb_device);
94 +}
95 +
96 +static struct avila_board_info avila_boards[] __initdata = {
97 + {
98 + .model = "GW2342",
99 + .setup = avila_gw2342_setup,
100 + }, {
101 + .model = "GW2345",
102 + .setup = avila_gw2345_setup,
103 + }, {
104 + .model = "GW2347",
105 + .setup = avila_gw2347_setup,
106 + }, {
107 + .model = "GW2348",
108 + .setup = avila_gw2348_setup,
109 + }, {
110 + .model = "GW2353",
111 + .setup = avila_gw2353_setup,
112 + }, {
113 + .model = "GW2355",
114 + .setup = avila_gw2355_setup,
115 + }, {
116 + .model = "GW2357",
117 + .setup = avila_gw2357_setup,
118 + }
119 +};
120 +
121 +static struct avila_board_info * __init avila_find_board_info(char *model)
122 +{
123 + int i;
124 +
125 + for (i = 0; i < ARRAY_SIZE(avila_boards); i++) {
126 + struct avila_board_info *info = &avila_boards[i];
127 + if (strncmp(info->model, model, strlen(info->model)) == 0)
128 + return info;
129 + }
130 +
131 + return NULL;
132 +}
133 +
134 +struct avila_eeprom_header {
135 + unsigned char mac0[ETH_ALEN];
136 + unsigned char mac1[ETH_ALEN];
137 + unsigned char res0[4];
138 + unsigned char magic[2];
139 + unsigned char config[14];
140 + unsigned char model[16];
141 +};
142 +
143 +static int __init avila_eeprom_notify(struct notifier_block *self,
144 + unsigned long event, void *t)
145 +{
146 + struct eeprom_data *ee = t;
147 + struct avila_eeprom_header hdr;
148 +
149 + if (avila_info)
150 + return NOTIFY_DONE;
151 +
152 + /* The eeprom is at address 0x51 */
153 + if (event != EEPROM_REGISTER || ee->client.addr != 0x51)
154 + return NOTIFY_DONE;
155 +
156 + ee->attr->read(&ee->client.dev.kobj, ee->attr, (char *)&hdr,
157 + 0, sizeof(hdr));
158 +
159 + if (hdr.magic[0] != 'G' || hdr.magic[1] != 'W')
160 + return NOTIFY_DONE;
161 +
162 + memcpy(&avila_npeb_data.hwaddr, hdr.mac0, ETH_ALEN);
163 + memcpy(&avila_npec_data.hwaddr, hdr.mac1, ETH_ALEN);
164 +
165 + avila_info = avila_find_board_info(hdr.model);
166 +
167 + return NOTIFY_OK;
168 +}
169 +
170 +static struct notifier_block avila_eeprom_notifier __initdata = {
171 + .notifier_call = avila_eeprom_notify
172 +};
173 +
174 +static void __init avila_register_eeprom_notifier(void)
175 +{
176 + register_eeprom_notifier(&avila_eeprom_notifier);
177 +}
178 +
179 +static void __init avila_unregister_eeprom_notifier(void)
180 +{
181 + unregister_eeprom_notifier(&avila_eeprom_notifier);
182 +}
183 +#else /* CONFIG_SENSORS_EEPROM */
184 +static inline void avila_register_eeprom_notifier(void) {};
185 +static inline void avila_unregister_eeprom_notifier(void) {};
186 +#endif /* CONFIG_SENSORS_EEPROM */
187 +
188 static void __init avila_init(void)
189 {
190 ixp4xx_sys_init();
191
192 + /*
193 + * These devices are present on all Avila models and don't need any
194 + * model specific setup.
195 + */
196 avila_flash_resource.start = IXP4XX_EXP_BUS_BASE(0);
197 avila_flash_resource.end =
198 IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1;
199 @@ -213,9 +378,28 @@ static void __init avila_init(void)
200
201 platform_device_register(&avila_pata);
202
203 - platform_device_register(avila_npeb_device);
204 - platform_device_register(avila_npec_device);
205 + avila_register_eeprom_notifier();
206 +}
207 +
208 +static int __init avila_model_setup(void)
209 +{
210 + if (!machine_is_avila())
211 + return 0;
212 +
213 + if (avila_info) {
214 + printk(KERN_DEBUG "Running on Gateworks Avila %s\n",
215 + avila_info->model);
216 + avila_info->setup();
217 + } else {
218 + printk(KERN_INFO "Unknown/missing Avila model number"
219 + " -- defaults will be used\n");
220 + avila_gw23xx_setup();
221 + }
222 +
223 + avila_unregister_eeprom_notifier();
224 + return 0;
225 }
226 +late_initcall(avila_model_setup);
227
228 MACHINE_START(AVILA, "Gateworks Avila Network Platform")
229 /* Maintainer: Deepak Saxena <dsaxena@plexity.net> */
This page took 0.050609 seconds and 5 git commands to generate.