blob: e739fd14c89820fee8a4641b50e607fccd3a37e9 [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
Peng Fanbbb20942018-01-10 13:20:31 +08008#include <asm/arch/imx-regs.h>
9#include <asm/io.h>
10#include <asm/arch/sys_proto.h>
11#include <errno.h>
12
13struct imx_mac_fuse {
14 u32 mac_addr0;
15 u32 rsvd0[3];
16 u32 mac_addr1;
17 u32 rsvd1[3];
18 u32 mac_addr2;
19 u32 rsvd2[7];
20};
21
22#define MAC_FUSE_MX6_OFFSET 0x620
23#define MAC_FUSE_MX7_OFFSET 0x640
24
25void imx_get_mac_from_fuse(int dev_id, unsigned char *mac)
26{
27 struct imx_mac_fuse *fuse;
28 u32 offset;
29 bool has_second_mac;
30
31 offset = is_mx6() ? MAC_FUSE_MX6_OFFSET : MAC_FUSE_MX7_OFFSET;
32 fuse = (struct imx_mac_fuse *)(ulong)(OCOTP_BASE_ADDR + offset);
Ye Li0cdfbfb2021-08-16 18:44:26 +080033 has_second_mac = is_mx7() || is_mx6sx() || is_mx6ul() || is_mx6ull() || is_imx8mp();
Peng Fanbbb20942018-01-10 13:20:31 +080034
35 if (has_second_mac && dev_id == 1) {
36 u32 value = readl(&fuse->mac_addr2);
37
38 mac[0] = value >> 24;
39 mac[1] = value >> 16;
40 mac[2] = value >> 8;
41 mac[3] = value;
42
43 value = readl(&fuse->mac_addr1);
44 mac[4] = value >> 24;
45 mac[5] = value >> 16;
46
47 } else {
48 u32 value = readl(&fuse->mac_addr1);
49
50 mac[0] = value >> 8;
51 mac[1] = value;
52
53 value = readl(&fuse->mac_addr0);
54 mac[2] = value >> 24;
55 mac[3] = value >> 16;
56 mac[4] = value >> 8;
57 mac[5] = value;
58 }
59}