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