adm5120: add experimental 3.14 kernel support
[openwrt/svn-archive/archive.git] / target / linux / adm5120 / files-3.14 / arch / mips / adm5120 / prom / admboot.c
1 /*
2 * ADMBoot specific prom routines
3 *
4 * Copyright (C) 2008 Gabor Juhos <juhosg@openwrt.org>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation.
9 *
10 */
11
12 #include <linux/types.h>
13 #include <linux/init.h>
14 #include <linux/errno.h>
15
16 #include <asm/addrspace.h>
17 #include <asm/byteorder.h>
18
19 #include <asm/mach-adm5120/adm5120_defs.h>
20 #include <prom/admboot.h>
21 #include "prom_read.h"
22
23 #define ADMBOOT_MAGIC_MAC_BASE 0x636D676D /* 'mgmc' */
24 #define ADMBOOT_MAGIC_MAC_BASE_BR6104XX 0x31305348 /* 'HS01' */
25
26 int __init admboot_get_mac_base(u32 offset, u32 len, u8 *mac)
27 {
28 u8 *cfg;
29 int i;
30
31 cfg = (u8 *) KSEG1ADDR(ADM5120_SRAM0_BASE + offset);
32 for (i = 0; i < len; i += 4) {
33 u32 magic;
34
35 magic = prom_read_le32(cfg + i);
36 if (magic == ADMBOOT_MAGIC_MAC_BASE) {
37 int j;
38
39 for (j = 0; j < 6; j++)
40 mac[j] = cfg[i + 4 + j];
41
42 return 0;
43 }
44 if (magic == ADMBOOT_MAGIC_MAC_BASE_BR6104XX) {
45 int j;
46
47 for (j = 0; j < 6; j++)
48 mac[j] = cfg[i + 7 + j];
49
50 return 0;
51 }
52 }
53
54 return -ENXIO;
55 }