aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux/adm5120/files-3.18/arch/mips/adm5120/prom/admboot.c
blob: b655390c16ff5f96b9de0caf9a7806505bff5378 (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
/*
 *  ADMBoot specific prom routines
 *
 *  Copyright (C) 2008 Gabor Juhos <juhosg@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/types.h>
#include <linux/init.h>
#include <linux/errno.h>

#include <asm/addrspace.h>
#include <asm/byteorder.h>

#include <asm/mach-adm5120/adm5120_defs.h>
#include <prom/admboot.h>
#include "prom_read.h"

#define ADMBOOT_MAGIC_MAC_BASE		0x636D676D	/* 'mgmc' */
#define ADMBOOT_MAGIC_MAC_BASE_BR6104XX 0x31305348	/* 'HS01' */

int __init admboot_get_mac_base(u32 offset, u32 len, u8 *mac)
{
	u8 *cfg;
	int i;

	cfg = (u8 *) KSEG1ADDR(ADM5120_SRAM0_BASE + offset);
	for (i = 0; i < len; i += 4) {
		u32 magic;

		magic = prom_read_le32(cfg + i);
		if (magic == ADMBOOT_MAGIC_MAC_BASE) {
			int j;

			for (j = 0; j < 6; j++)
				mac[j] = cfg[i + 4 + j];

			return 0;
		}
		if (magic == ADMBOOT_MAGIC_MAC_BASE_BR6104XX) {
			int j;

			for (j = 0; j < 6; j++)
				mac[j] = cfg[i + 7 + j];

			return 0;
		}
	}

	return -ENXIO;
}