blob: 3b1496b20383c389f509a26788dcb4ba67bad3cc [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Peng Fan6ce8b102018-01-10 13:20:31 +08002/*
3 * Copyright 2017 NXP
4 *
5 * Peng Fan <peng.fan@nxp.com>
Peng Fan6ce8b102018-01-10 13:20:31 +08006 */
7
8#include <common.h>
9#include <asm/arch/imx-regs.h>
10#include <asm/io.h>
11#include <asm/arch/sys_proto.h>
12#include <errno.h>
13
14struct imx_mac_fuse {
15 u32 mac_addr0;
16 u32 rsvd0[3];
17 u32 mac_addr1;
18 u32 rsvd1[3];
19 u32 mac_addr2;
20 u32 rsvd2[7];
21};
22
23#define MAC_FUSE_MX6_OFFSET 0x620
24#define MAC_FUSE_MX7_OFFSET 0x640
25
26void imx_get_mac_from_fuse(int dev_id, unsigned char *mac)
27{
28 struct imx_mac_fuse *fuse;
29 u32 offset;
30 bool has_second_mac;
31
32 offset = is_mx6() ? MAC_FUSE_MX6_OFFSET : MAC_FUSE_MX7_OFFSET;
33 fuse = (struct imx_mac_fuse *)(ulong)(OCOTP_BASE_ADDR + offset);
34 has_second_mac = is_mx7() || is_mx6sx() || is_mx6ul() || is_mx6ull();
35
36 if (has_second_mac && dev_id == 1) {
37 u32 value = readl(&fuse->mac_addr2);
38
39 mac[0] = value >> 24;
40 mac[1] = value >> 16;
41 mac[2] = value >> 8;
42 mac[3] = value;
43
44 value = readl(&fuse->mac_addr1);
45 mac[4] = value >> 24;
46 mac[5] = value >> 16;
47
48 } else {
49 u32 value = readl(&fuse->mac_addr1);
50
51 mac[0] = value >> 8;
52 mac[1] = value;
53
54 value = readl(&fuse->mac_addr0);
55 mac[2] = value >> 24;
56 mac[3] = value >> 16;
57 mac[4] = value >> 8;
58 mac[5] = value;
59 }
60}