OpenWrt – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | From f8c5db89e793a4bc6c1e87bd7b3a5cec16b75bc3 Mon Sep 17 00:00:00 2001 |
2 | From: John Crispin <blogic@openwrt.org> |
||
3 | Date: Wed, 10 Sep 2014 22:42:14 +0200 |
||
4 | Subject: [PATCH 35/36] owrt: lantiq: wifi and ethernet eeprom handling |
||
5 | |||
6 | Signed-off-by: John Crispin <blogic@openwrt.org> |
||
7 | --- |
||
8 | .../mips/include/asm/mach-lantiq/xway/lantiq_soc.h | 3 + |
||
9 | arch/mips/lantiq/xway/Makefile | 3 + |
||
10 | arch/mips/lantiq/xway/ath5k_eep.c | 136 +++++++++++++++++++++ |
||
11 | arch/mips/lantiq/xway/eth_mac.c | 25 ++++ |
||
12 | drivers/net/ethernet/lantiq_etop.c | 6 +- |
||
13 | 5 files changed, 172 insertions(+), 1 deletion(-) |
||
14 | create mode 100644 arch/mips/lantiq/xway/ath5k_eep.c |
||
15 | create mode 100644 arch/mips/lantiq/xway/eth_mac.c |
||
16 | |||
17 | --- a/arch/mips/include/asm/mach-lantiq/xway/lantiq_soc.h |
||
18 | +++ b/arch/mips/include/asm/mach-lantiq/xway/lantiq_soc.h |
||
19 | @@ -104,5 +104,8 @@ int xrx200_gphy_boot(struct device *dev, |
||
20 | extern void ltq_pmu_enable(unsigned int module); |
||
21 | extern void ltq_pmu_disable(unsigned int module); |
||
22 | |||
23 | +/* allow the ethernet driver to load a flash mapped mac addr */ |
||
24 | +const u8* ltq_get_eth_mac(void); |
||
25 | + |
||
26 | #endif /* CONFIG_SOC_TYPE_XWAY */ |
||
27 | #endif /* _LTQ_XWAY_H__ */ |
||
28 | --- a/arch/mips/lantiq/xway/Makefile |
||
29 | +++ b/arch/mips/lantiq/xway/Makefile |
||
30 | @@ -7,3 +7,6 @@ obj-y += timer.o |
||
31 | endif |
||
32 | |||
33 | obj-y += vmmc.o |
||
34 | + |
||
35 | +obj-y += eth_mac.o |
||
36 | +obj-$(CONFIG_PCI) += ath5k_eep.o |
||
37 | --- /dev/null |
||
38 | +++ b/arch/mips/lantiq/xway/ath5k_eep.c |
||
39 | @@ -0,0 +1,136 @@ |
||
40 | +/* |
||
41 | + * Copyright (C) 2011 Luca Olivetti <luca@ventoso.org> |
||
42 | + * Copyright (C) 2011 John Crispin <blogic@openwrt.org> |
||
43 | + * Copyright (C) 2011 Andrej Vlašić <andrej.vlasic0@gmail.com> |
||
44 | + * Copyright (C) 2013 Álvaro Fernández Rojas <noltari@gmail.com> |
||
45 | + * Copyright (C) 2013 Daniel Gimpelevich <daniel@gimpelevich.san-francisco.ca.us> |
||
46 | + * Copyright (C) 2015 Vittorio Gambaletta <openwrt@vittgam.net> |
||
47 | + * |
||
48 | + * This program is free software; you can redistribute it and/or modify it |
||
49 | + * under the terms of the GNU General Public License version 2 as published |
||
50 | + * by the Free Software Foundation. |
||
51 | + */ |
||
52 | + |
||
53 | +#include <linux/init.h> |
||
54 | +#include <linux/platform_device.h> |
||
55 | +#include <linux/etherdevice.h> |
||
56 | +#include <linux/ath5k_platform.h> |
||
57 | +#include <linux/pci.h> |
||
58 | +#include <linux/err.h> |
||
59 | +#include <linux/mtd/mtd.h> |
||
60 | +#include <lantiq_soc.h> |
||
61 | + |
||
62 | +extern int (*ltq_pci_plat_dev_init)(struct pci_dev *dev); |
||
63 | +struct ath5k_platform_data ath5k_pdata; |
||
64 | +static u8 athxk_eeprom_mac[6]; |
||
65 | + |
||
66 | +static int ath5k_pci_plat_dev_init(struct pci_dev *dev) |
||
67 | +{ |
||
68 | + dev->dev.platform_data = &ath5k_pdata; |
||
69 | + return 0; |
||
70 | +} |
||
71 | + |
||
72 | +static int ath5k_eep_load; |
||
73 | +int __init of_ath5k_eeprom_probe(struct platform_device *pdev) |
||
74 | +{ |
||
75 | + struct device_node *np = pdev->dev.of_node, *mtd_np = NULL; |
||
76 | + int mac_offset; |
||
77 | + u32 mac_inc = 0; |
||
78 | + int i; |
||
79 | + struct mtd_info *the_mtd; |
||
80 | + size_t flash_readlen; |
||
81 | + const __be32 *list; |
||
82 | + const char *part; |
||
83 | + phandle phandle; |
||
84 | + |
||
85 | + list = of_get_property(np, "ath,eep-flash", &i); |
||
86 | + if (!list || (i != (2 * sizeof(*list)))) |
||
87 | + return -ENODEV; |
||
88 | + |
||
89 | + phandle = be32_to_cpup(list++); |
||
90 | + if (phandle) |
||
91 | + mtd_np = of_find_node_by_phandle(phandle); |
||
92 | + |
||
93 | + if (!mtd_np) |
||
94 | + return -ENODEV; |
||
95 | + |
||
96 | + part = of_get_property(mtd_np, "label", NULL); |
||
97 | + if (!part) |
||
98 | + part = mtd_np->name; |
||
99 | + |
||
100 | + the_mtd = get_mtd_device_nm(part); |
||
101 | + if (IS_ERR(the_mtd)) |
||
102 | + return -ENODEV; |
||
103 | + |
||
104 | + ath5k_pdata.eeprom_data = kmalloc(ATH5K_PLAT_EEP_MAX_WORDS<<1, GFP_KERNEL); |
||
105 | + |
||
106 | + i = mtd_read(the_mtd, be32_to_cpup(list), ATH5K_PLAT_EEP_MAX_WORDS << 1, |
||
107 | + &flash_readlen, (void *) ath5k_pdata.eeprom_data); |
||
108 | + |
||
109 | + if (!of_property_read_u32(np, "ath,mac-offset", &mac_offset)) { |
||
110 | + size_t mac_readlen; |
||
111 | + mtd_read(the_mtd, mac_offset, 6, &mac_readlen, |
||
112 | + (void *) athxk_eeprom_mac); |
||
113 | + } |
||
114 | + put_mtd_device(the_mtd); |
||
115 | + |
||
116 | + if (((ATH5K_PLAT_EEP_MAX_WORDS<<1) != flash_readlen) || i) { |
||
117 | + dev_err(&pdev->dev, "failed to load eeprom from mtd\n"); |
||
118 | + return -ENODEV; |
||
119 | + } |
||
120 | + |
||
121 | + if (of_find_property(np, "ath,eep-swap", NULL)) |
||
122 | + for (i = 0; i < ATH5K_PLAT_EEP_MAX_WORDS; i++) |
||
123 | + ath5k_pdata.eeprom_data[i] = swab16(ath5k_pdata.eeprom_data[i]); |
||
124 | + |
||
125 | + if (!is_valid_ether_addr(athxk_eeprom_mac) && ltq_get_eth_mac()) |
||
126 | + ether_addr_copy(athxk_eeprom_mac, ltq_get_eth_mac()); |
||
127 | + |
||
128 | + if (!is_valid_ether_addr(athxk_eeprom_mac)) { |
||
129 | + dev_warn(&pdev->dev, "using random mac\n"); |
||
130 | + random_ether_addr(athxk_eeprom_mac); |
||
131 | + } |
||
132 | + |
||
133 | + if (!of_property_read_u32(np, "ath,mac-increment", &mac_inc)) |
||
134 | + athxk_eeprom_mac[5] += mac_inc; |
||
135 | + |
||
136 | + ath5k_pdata.macaddr = athxk_eeprom_mac; |
||
137 | + ltq_pci_plat_dev_init = ath5k_pci_plat_dev_init; |
||
138 | + |
||
139 | + dev_info(&pdev->dev, "loaded ath5k eeprom\n"); |
||
140 | + |
||
141 | + return 0; |
||
142 | +} |
||
143 | + |
||
144 | +static struct of_device_id ath5k_eeprom_ids[] = { |
||
145 | + { .compatible = "ath5k,eeprom" }, |
||
146 | + { } |
||
147 | +}; |
||
148 | + |
||
149 | +static struct platform_driver ath5k_eeprom_driver = { |
||
150 | + .driver = { |
||
151 | + .name = "ath5k,eeprom", |
||
152 | + .owner = THIS_MODULE, |
||
153 | + .of_match_table = of_match_ptr(ath5k_eeprom_ids), |
||
154 | + }, |
||
155 | +}; |
||
156 | + |
||
157 | +static int __init of_ath5k_eeprom_init(void) |
||
158 | +{ |
||
159 | + int ret = platform_driver_probe(&ath5k_eeprom_driver, of_ath5k_eeprom_probe); |
||
160 | + |
||
161 | + if (ret) |
||
162 | + ath5k_eep_load = 1; |
||
163 | + |
||
164 | + return ret; |
||
165 | +} |
||
166 | + |
||
167 | +static int __init of_ath5k_eeprom_init_late(void) |
||
168 | +{ |
||
169 | + if (!ath5k_eep_load) |
||
170 | + return 0; |
||
171 | + |
||
172 | + return platform_driver_probe(&ath5k_eeprom_driver, of_ath5k_eeprom_probe); |
||
173 | +} |
||
174 | +late_initcall(of_ath5k_eeprom_init_late); |
||
175 | +subsys_initcall(of_ath5k_eeprom_init); |
||
176 | --- /dev/null |
||
177 | +++ b/arch/mips/lantiq/xway/eth_mac.c |
||
178 | @@ -0,0 +1,25 @@ |
||
179 | +/* |
||
180 | + * Copyright (C) 2012 John Crispin <blogic@openwrt.org> |
||
181 | + * |
||
182 | + * This program is free software; you can redistribute it and/or modify it |
||
183 | + * under the terms of the GNU General Public License version 2 as published |
||
184 | + * by the Free Software Foundation. |
||
185 | + */ |
||
186 | + |
||
187 | +#include <linux/init.h> |
||
188 | +#include <linux/if_ether.h> |
||
189 | + |
||
190 | +static u8 eth_mac[6]; |
||
191 | +static int eth_mac_set; |
||
192 | + |
||
193 | +const u8* ltq_get_eth_mac(void) |
||
194 | +{ |
||
195 | + return eth_mac; |
||
196 | +} |
||
197 | + |
||
198 | +static int __init setup_ethaddr(char *str) |
||
199 | +{ |
||
200 | + eth_mac_set = mac_pton(str, eth_mac); |
||
201 | + return !eth_mac_set; |
||
202 | +} |
||
203 | +early_param("ethaddr", setup_ethaddr); |
||
204 | --- a/drivers/net/ethernet/lantiq_etop.c |
||
205 | +++ b/drivers/net/ethernet/lantiq_etop.c |
||
206 | @@ -783,7 +783,11 @@ ltq_etop_init(struct net_device *dev) |
||
207 | if (err) |
||
208 | goto err_hw; |
||
209 | |||
210 | - memcpy(&mac, &priv->pldata->mac, sizeof(struct sockaddr)); |
||
211 | + memcpy(&mac.sa_data, ltq_get_eth_mac(), ETH_ALEN); |
||
212 | + |
||
213 | + if (priv->mac && !is_valid_ether_addr(mac.sa_data)) |
||
214 | + memcpy(&mac.sa_data, priv->mac, ETH_ALEN); |
||
215 | + |
||
216 | if (!is_valid_ether_addr(mac.sa_data)) { |
||
217 | pr_warn("etop: invalid MAC, using random\n"); |
||
218 | eth_random_addr(mac.sa_data); |