summaryrefslogtreecommitdiff
path: root/target/linux/lantiq/patches-3.7/0302-wifi-eep.patch
blob: 54a8acd1edf9c53af408fe23cd5098c1a415e7ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
Index: linux-3.7-rc8/arch/mips/lantiq/xway/Makefile
===================================================================
--- linux-3.7-rc8.orig/arch/mips/lantiq/xway/Makefile	2012-12-13 10:59:54.176314899 +0100
+++ linux-3.7-rc8/arch/mips/lantiq/xway/Makefile	2012-12-13 13:58:51.696584083 +0100
@@ -1,3 +1,6 @@
 obj-y := prom.o sysctrl.o clk.o reset.o dma.o timer.o dcdc.o
 
+obj-y += eth_mac.o
+obj-$(CONFIG_PCI) += ath_eep.o rt_eep.o
+
 obj-$(CONFIG_XRX200_PHY_FW) += xrx200_phy_fw.o
Index: linux-3.7-rc8/arch/mips/lantiq/xway/ath_eep.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ linux-3.7-rc8/arch/mips/lantiq/xway/ath_eep.c	2012-12-13 13:49:12.472569552 +0100
@@ -0,0 +1,120 @@
+/*
+ *  Copyright (C) 2011 John Crispin <blogic@openwrt.org>
+ *  Copyright (C) 2011 Andrej Vlašić <andrej.vlasic0@gmail.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify it
+ *  under the terms of the GNU General Public License version 2 as published
+ *  by the Free Software Foundation.
+ */
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/etherdevice.h>
+#include <linux/ath5k_platform.h>
+#include <linux/ath9k_platform.h>
+#include <linux/pci.h>
+
+extern int (*ltq_pci_plat_dev_init)(struct pci_dev *dev);
+struct ath5k_platform_data ath5k_pdata;
+/*struct ath9k_platform_data ath9k_pdata = {
+	.led_pin = -1,
+	.endian_check = true,
+};*/
+static u16 ath5k_eeprom_data[ATH5K_PLAT_EEP_MAX_WORDS];
+//static u16 ath9k_eeprom_data[ATH9K_PLAT_EEP_MAX_WORDS];
+static u8 athxk_eeprom_mac[6];
+
+/*static int
+ath9k_pci_plat_dev_init(struct pci_dev *dev)
+{
+	dev->dev.platform_data = &ath9k_pdata;
+	return 0;
+}
+
+void __init
+ltq_register_ath9k(u16 *eeprom_data, u8 *macaddr)
+{
+	memcpy(ath9k_pdata.eeprom_data, eeprom_data, sizeof(ath9k_pdata.eeprom_data));
+	ath9k_pdata.macaddr = macaddr;
+	ltq_pci_plat_dev_init = ath9k_pci_plat_dev_init;
+}
+*/
+static int ath5k_pci_plat_dev_init(struct pci_dev *dev)
+{
+	dev->dev.platform_data = &ath5k_pdata;
+	return 0;
+}
+
+int __init of_ath5k_eeprom_probe(struct platform_device *pdev)
+{
+	struct device_node *np = pdev->dev.of_node;
+	struct resource *eep_res, *mac_res;
+	void __iomem *eep, *mac;
+	int mac_offset;
+	u32 mac_inc = 0;
+	int i;
+
+	eep_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	mac_res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
+
+	if (!eep_res) {
+		dev_err(&pdev->dev, "failed to load eeprom address\n");
+		return -ENODEV;
+	}
+	if (resource_size(eep_res) != ATH5K_PLAT_EEP_MAX_WORDS) {
+		dev_err(&pdev->dev, "eeprom has an invalid size\n");
+		return -EINVAL;
+	}
+
+	eep = ioremap(eep_res->start, resource_size(eep_res));
+	memcpy_fromio(ath5k_eeprom_data, eep, ATH5K_PLAT_EEP_MAX_WORDS);
+
+	if (of_find_property(np, "ath,eep-swap", NULL))
+		for (i = 0; i < (ATH5K_PLAT_EEP_MAX_WORDS >> 1); i++)
+				ath5k_eeprom_data[i] = swab16(ath5k_eeprom_data[i]);
+
+	if (!of_property_read_u32(np, "ath,mac-offset", &mac_offset)) {
+		memcpy_fromio(athxk_eeprom_mac, (void*) ath5k_eeprom_data, 6);
+	} else if (mac_res) {
+		if (resource_size(mac_res) != 6) {
+			dev_err(&pdev->dev, "mac has an invalid size\n");
+			return -EINVAL;
+		}
+		mac = ioremap(mac_res->start, resource_size(mac_res));
+		memcpy_fromio(athxk_eeprom_mac, mac, 6);
+	} else {
+		dev_warn(&pdev->dev, "using random mac\n");
+		random_ether_addr(athxk_eeprom_mac);
+	}
+
+	if (!of_property_read_u32(np, "ath,mac-increment", &mac_inc))
+		athxk_eeprom_mac[5] += mac_inc;
+
+	ath5k_pdata.eeprom_data = ath5k_eeprom_data;
+	ath5k_pdata.macaddr = athxk_eeprom_mac;
+	ltq_pci_plat_dev_init = ath5k_pci_plat_dev_init;
+
+	dev_info(&pdev->dev, "loaded ath5k eeprom\n");
+
+	return 0;
+}
+
+static struct of_device_id ath5k_eeprom_ids[] = {
+	{ .compatible = "ath5k,eeprom" },
+	{ }
+};
+
+static struct platform_driver ath5k_eeprom_driver = {
+	.driver		= {
+		.name		= "ath5k,eeprom",
+		.owner	= THIS_MODULE,
+		.of_match_table	= of_match_ptr(ath5k_eeprom_ids),
+	},
+};
+
+static int __init of_ath5k_eeprom_init(void)
+{
+	return platform_driver_probe(&ath5k_eeprom_driver, of_ath5k_eeprom_probe);
+}
+device_initcall(of_ath5k_eeprom_init);
Index: linux-3.7-rc8/arch/mips/include/asm/mach-lantiq/xway/lantiq_soc.h
===================================================================
--- linux-3.7-rc8.orig/arch/mips/include/asm/mach-lantiq/xway/lantiq_soc.h	2012-12-13 10:59:57.300314976 +0100
+++ linux-3.7-rc8/arch/mips/include/asm/mach-lantiq/xway/lantiq_soc.h	2012-12-13 10:59:57.308314977 +0100
@@ -93,5 +93,8 @@
 /* allow tapi driver to read the gptu value */
 long gptu_get_count(struct clk *clk);
 
+/* allow the ethernet driver to load a flash mapped mac addr */
+const u8* ltq_get_eth_mac(void);
+
 #endif /* CONFIG_SOC_TYPE_XWAY */
 #endif /* _LTQ_XWAY_H__ */
Index: linux-3.7-rc8/arch/mips/lantiq/xway/eth_mac.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ linux-3.7-rc8/arch/mips/lantiq/xway/eth_mac.c	2012-12-13 10:59:57.308314977 +0100
@@ -0,0 +1,76 @@
+/*
+ *  Copyright (C) 2012 John Crispin <blogic@openwrt.org>
+ *
+ *  This program is free software; you can redistribute it and/or modify it
+ *  under the terms of the GNU General Public License version 2 as published
+ *  by the Free Software Foundation.
+ */
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/of_platform.h>
+#include <linux/if_ether.h>
+
+static u8 eth_mac[6];
+static int eth_mac_set;
+
+const u8* ltq_get_eth_mac(void)
+{
+	return eth_mac;
+}
+
+static int __init setup_ethaddr(char *str)
+{
+	eth_mac_set = mac_pton(str, eth_mac);
+	return !eth_mac_set;
+}
+__setup("ethaddr=", setup_ethaddr);
+
+int __init of_eth_mac_probe(struct platform_device *pdev)
+{
+	struct device_node *np = pdev->dev.of_node;
+	struct resource *mac_res;
+	void __iomem *mac;
+	u32 mac_inc = 0;
+
+	if (eth_mac_set) {
+		dev_err(&pdev->dev, "mac was already set by bootloader\n");
+		return -EINVAL;
+	}
+	mac_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+
+	if (!mac_res) {
+		dev_err(&pdev->dev, "failed to load mac\n");
+		return -EINVAL;
+	}
+	if (resource_size(mac_res) != 6) {
+		dev_err(&pdev->dev, "mac has an invalid size\n");
+		return -EINVAL;
+	}
+	mac = ioremap(mac_res->start, resource_size(mac_res));
+	memcpy_fromio(eth_mac, mac, 6);
+
+	if (!of_property_read_u32(np, "mac-increment", &mac_inc))
+		eth_mac[5] += mac_inc;
+
+	return 0;
+}
+
+static struct of_device_id eth_mac_ids[] = {
+	{ .compatible = "lantiq,eth-mac" },
+	{ /* sentinel */ }
+};
+
+static struct platform_driver eth_mac_driver = {
+	.driver		= {
+		.name		= "lantiq,eth-mac",
+		.owner	= THIS_MODULE,
+		.of_match_table	= of_match_ptr(eth_mac_ids),
+	},
+};
+
+static int __init of_eth_mac_init(void)
+{
+	return platform_driver_probe(&eth_mac_driver, of_eth_mac_probe);
+}
+device_initcall(of_eth_mac_init);
Index: linux-3.7-rc8/drivers/net/ethernet/lantiq_etop.c
===================================================================
--- linux-3.7-rc8.orig/drivers/net/ethernet/lantiq_etop.c	2012-12-13 10:59:54.176314899 +0100
+++ linux-3.7-rc8/drivers/net/ethernet/lantiq_etop.c	2012-12-13 10:59:57.308314977 +0100
@@ -816,7 +816,8 @@
 
 	ltq_etop_change_mtu(dev, 1500);
 
-	memcpy(&mac.sa_data, priv->mac, ETH_ALEN);
+	if (priv->mac)
+		memcpy(&mac.sa_data, priv->mac, ETH_ALEN);
 	if (!is_valid_ether_addr(mac.sa_data)) {
 		pr_warn("etop: invalid MAC, using random\n");
 		random_ether_addr(mac.sa_data);
@@ -940,7 +941,9 @@
 	priv->tx_irq = irqres[0].start;
 	priv->rx_irq = irqres[1].start;
 	priv->mii_mode = of_get_phy_mode(pdev->dev.of_node);
-	priv->mac = of_get_mac_address(pdev->dev.of_node);
+	priv->mac = ltq_get_eth_mac();
+	if (!priv->mac)
+		priv->mac = of_get_mac_address(pdev->dev.of_node);
 
 	priv->clk_ppe = clk_get(&pdev->dev, NULL);
 	if (IS_ERR(priv->clk_ppe))
Index: linux-3.7-rc8/arch/mips/lantiq/xway/rt_eep.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ linux-3.7-rc8/arch/mips/lantiq/xway/rt_eep.c	2012-12-13 13:55:43.132579350 +0100
@@ -0,0 +1,60 @@
+/*
+ *  Copyright (C) 2011 John Crispin <blogic@openwrt.org>
+ *
+ *  This program is free software; you can redistribute it and/or modify it
+ *  under the terms of the GNU General Public License version 2 as published
+ *  by the Free Software Foundation.
+ */
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/pci.h>
+#include <linux/platform_device.h>
+#include <linux/rt2x00_platform.h>
+
+extern int (*ltq_pci_plat_dev_init)(struct pci_dev *dev);
+static struct rt2x00_platform_data rt2x00_pdata;
+
+static int rt2x00_pci_plat_dev_init(struct pci_dev *dev)
+{
+	dev->dev.platform_data = &rt2x00_pdata;
+	return 0;
+}
+
+int __init of_ralink_eeprom_probe(struct platform_device *pdev)
+{
+	struct device_node *np = pdev->dev.of_node;
+	const char *eeprom;
+
+	if (of_property_read_string(np, "ralink,eeprom", &eeprom)) {
+		dev_err(&pdev->dev, "failed to load eeprom filename\n");
+		return 0;
+	}
+
+	rt2x00_pdata.eeprom_file_name = kstrdup(eeprom, GFP_KERNEL);
+//	rt2x00_pdata.mac_address = mac;
+	ltq_pci_plat_dev_init = rt2x00_pci_plat_dev_init;
+
+	dev_info(&pdev->dev, "using %s as eeprom\n", eeprom);
+
+	return 0;
+}
+
+static struct of_device_id ralink_eeprom_ids[] = {
+	{ .compatible = "ralink,eeprom" },
+	{ }
+};
+
+static struct platform_driver ralink_eeprom_driver = {
+	.driver		= {
+		.name		= "ralink,eeprom",
+		.owner	= THIS_MODULE,
+		.of_match_table	= of_match_ptr(ralink_eeprom_ids),
+	},
+};
+
+static int __init of_ralink_eeprom_init(void)
+{
+	return platform_driver_probe(&ralink_eeprom_driver, of_ralink_eeprom_probe);
+}
+device_initcall(of_ralink_eeprom_init);