Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Peng Fan | bbb2094 | 2018-01-10 13:20:31 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2017 NXP |
| 4 | * |
| 5 | * Peng Fan <peng.fan@nxp.com> |
Peng Fan | bbb2094 | 2018-01-10 13:20:31 +0800 | [diff] [blame] | 6 | */ |
| 7 | |
Peng Fan | bbb2094 | 2018-01-10 13:20:31 +0800 | [diff] [blame] | 8 | #include <asm/arch/imx-regs.h> |
| 9 | #include <asm/io.h> |
| 10 | #include <asm/arch/sys_proto.h> |
| 11 | #include <errno.h> |
| 12 | |
| 13 | struct 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 | |
| 25 | void 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 Li | 0cdfbfb | 2021-08-16 18:44:26 +0800 | [diff] [blame] | 33 | has_second_mac = is_mx7() || is_mx6sx() || is_mx6ul() || is_mx6ull() || is_imx8mp(); |
Peng Fan | bbb2094 | 2018-01-10 13:20:31 +0800 | [diff] [blame] | 34 | |
| 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 | } |