aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-orion5x/ts209-setup.c
diff options
context:
space:
mode:
authorLennert Buytenhek <buytenh@wantstofly.org>2008-04-01 11:21:49 -0400
committerRussell King <rmk+kernel@arm.linux.org.uk>2008-04-04 05:04:30 -0400
commitbee036b503214dd65f62af6599d2bebdf156467c (patch)
tree62884307ee3a51783c9a1573667ba288773813b1 /arch/arm/mach-orion5x/ts209-setup.c
parent9dd0b194bf6804b1998f0fe261b2606ec7b58d72 (diff)
[ARM] 4886/1: Orion: grab ts209 ethernet MAC address from flash
The bootloader on ts209 Orion boards doesn't configure the right ethernet MAC address into the GigE unit on boot. The only way to get the MAC address is by parsing it from the 'NAS Config' flash partition, which is an ext2 partition that contains a file which holds the MAC address in plain text (format "xx:xx:xx:xx:xx:xx\n") -- this patch does that. Tested-by: Martin Michlmayr <tbm@cyrius.com> Cc: Byron Bradley <byron.bbradley@gmail.com> Signed-off-by: Lennert Buytenhek <buytenh@marvell.com> Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Diffstat (limited to 'arch/arm/mach-orion5x/ts209-setup.c')
-rw-r--r--arch/arm/mach-orion5x/ts209-setup.c83
1 files changed, 83 insertions, 0 deletions
diff --git a/arch/arm/mach-orion5x/ts209-setup.c b/arch/arm/mach-orion5x/ts209-setup.c
index 71b0cffa2fe0..fd43863a86f6 100644
--- a/arch/arm/mach-orion5x/ts209-setup.c
+++ b/arch/arm/mach-orion5x/ts209-setup.c
@@ -188,6 +188,87 @@ static struct mv643xx_eth_platform_data qnap_ts209_eth_data = {
188 .force_phy_addr = 1, 188 .force_phy_addr = 1,
189}; 189};
190 190
191static int __init parse_hex_nibble(char n)
192{
193 if (n >= '0' && n <= '9')
194 return n - '0';
195
196 if (n >= 'A' && n <= 'F')
197 return n - 'A' + 10;
198
199 if (n >= 'a' && n <= 'f')
200 return n - 'a' + 10;
201
202 return -1;
203}
204
205static int __init parse_hex_byte(const char *b)
206{
207 int hi;
208 int lo;
209
210 hi = parse_hex_nibble(b[0]);
211 lo = parse_hex_nibble(b[1]);
212
213 if (hi < 0 || lo < 0)
214 return -1;
215
216 return (hi << 4) | lo;
217}
218
219static int __init check_mac_addr(const char *addr_str)
220{
221 u_int8_t addr[6];
222 int i;
223
224 for (i = 0; i < 6; i++) {
225 int byte;
226
227 /*
228 * Enforce "xx:xx:xx:xx:xx:xx\n" format.
229 */
230 if (addr_str[(i * 3) + 2] != ((i < 5) ? ':' : '\n'))
231 return -1;
232
233 byte = parse_hex_byte(addr_str + (i * 3));
234 if (byte < 0)
235 return -1;
236 addr[i] = byte;
237 }
238
239 printk(KERN_INFO "ts209: found ethernet mac address ");
240 for (i = 0; i < 6; i++)
241 printk("%.2x%s", addr[i], (i < 5) ? ":" : ".\n");
242
243 memcpy(qnap_ts209_eth_data.mac_addr, addr, 6);
244
245 return 0;
246}
247
248/*
249 * The 'NAS Config' flash partition has an ext2 filesystem which
250 * contains a file that has the ethernet MAC address in plain text
251 * (format "xx:xx:xx:xx:xx:xx\n".)
252 */
253static void __init ts209_find_mac_addr(void)
254{
255 unsigned long addr;
256
257 for (addr = 0x00700000; addr < 0x00760000; addr += 1024) {
258 char *nor_page;
259 int ret = 0;
260
261 nor_page = ioremap(QNAP_TS209_NOR_BOOT_BASE + addr, 1024);
262 if (nor_page != NULL) {
263 ret = check_mac_addr(nor_page);
264 iounmap(nor_page);
265 }
266
267 if (ret == 0)
268 break;
269 }
270}
271
191/***************************************************************************** 272/*****************************************************************************
192 * RTC S35390A on I2C bus 273 * RTC S35390A on I2C bus
193 ****************************************************************************/ 274 ****************************************************************************/
@@ -342,7 +423,9 @@ static void __init qnap_ts209_init(void)
342 pr_warning("qnap_ts209_init: failed to get RTC IRQ\n"); 423 pr_warning("qnap_ts209_init: failed to get RTC IRQ\n");
343 i2c_register_board_info(0, &qnap_ts209_i2c_rtc, 1); 424 i2c_register_board_info(0, &qnap_ts209_i2c_rtc, 1);
344 425
426 ts209_find_mac_addr();
345 orion5x_eth_init(&qnap_ts209_eth_data); 427 orion5x_eth_init(&qnap_ts209_eth_data);
428
346 orion5x_sata_init(&qnap_ts209_sata_data); 429 orion5x_sata_init(&qnap_ts209_sata_data);
347} 430}
348 431