blob: 9bb63d25b48833cd7a7716d9c871d4c518ee2e35 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Peng Fanbbb20942018-01-10 13:20:31 +08002/*
3 * Copyright 2017 NXP
4 *
5 * Peng Fan <peng.fan@nxp.com>
Peng Fanbbb20942018-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);
Ye Li0cdfbfb2021-08-16 18:44:26 +080034 has_second_mac = is_mx7() || is_mx6sx() || is_mx6ul() || is_mx6ull() || is_imx8mp();
Peng Fanbbb20942018-01-10 13:20:31 +080035
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}