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