2 * CPSW common - libs used across TI ethernet devices.
4 * Copyright (C) 2016, Texas Instruments, Incorporated
6 * SPDX-License-Identifier: GPL-2.0+
11 #include <fdt_support.h>
15 DECLARE_GLOBAL_DATA_PTR;
17 #define CTRL_MAC_REG(offset, id) ((offset) + 0x8 * (id))
19 static int davinci_emac_3517_get_macid(struct udevice *dev, u16 offset,
20 int slave, u8 *mac_addr)
22 void *fdt = (void *)gd->fdt_blob;
23 int node = dev_of_offset(dev);
30 syscon = fdtdec_lookup_phandle(fdt, node, "syscon");
32 error("Syscon offset not found\n");
36 addr = (u32)map_physmem(fdt_translate_address(fdt, syscon, &gmii),
37 sizeof(u32), MAP_NOCACHE);
38 if (addr == FDT_ADDR_T_NONE) {
39 error("Not able to get syscon address to get mac efuse address\n");
43 addr += CTRL_MAC_REG(offset, slave);
45 /* try reading mac address from efuse */
46 macid_lsb = readl(addr);
47 macid_msb = readl(addr + 4);
49 mac_addr[0] = (macid_msb >> 16) & 0xff;
50 mac_addr[1] = (macid_msb >> 8) & 0xff;
51 mac_addr[2] = macid_msb & 0xff;
52 mac_addr[3] = (macid_lsb >> 16) & 0xff;
53 mac_addr[4] = (macid_lsb >> 8) & 0xff;
54 mac_addr[5] = macid_lsb & 0xff;
59 static int cpsw_am33xx_cm_get_macid(struct udevice *dev, u16 offset, int slave,
62 void *fdt = (void *)gd->fdt_blob;
63 int node = dev_of_offset(dev);
70 syscon = fdtdec_lookup_phandle(fdt, node, "syscon");
72 error("Syscon offset not found\n");
76 addr = (u32)map_physmem(fdt_translate_address(fdt, syscon, &gmii),
77 sizeof(u32), MAP_NOCACHE);
78 if (addr == FDT_ADDR_T_NONE) {
79 error("Not able to get syscon address to get mac efuse address\n");
83 addr += CTRL_MAC_REG(offset, slave);
85 /* try reading mac address from efuse */
86 macid_lo = readl(addr);
87 macid_hi = readl(addr + 4);
89 mac_addr[5] = (macid_lo >> 8) & 0xff;
90 mac_addr[4] = macid_lo & 0xff;
91 mac_addr[3] = (macid_hi >> 24) & 0xff;
92 mac_addr[2] = (macid_hi >> 16) & 0xff;
93 mac_addr[1] = (macid_hi >> 8) & 0xff;
94 mac_addr[0] = macid_hi & 0xff;
99 int ti_cm_get_macid(struct udevice *dev, int slave, u8 *mac_addr)
101 if (of_machine_is_compatible("ti,dm8148"))
102 return cpsw_am33xx_cm_get_macid(dev, 0x630, slave, mac_addr);
104 if (of_machine_is_compatible("ti,am33xx"))
105 return cpsw_am33xx_cm_get_macid(dev, 0x630, slave, mac_addr);
107 if (device_is_compatible(dev, "ti,am3517-emac"))
108 return davinci_emac_3517_get_macid(dev, 0x110, slave, mac_addr);
110 if (device_is_compatible(dev, "ti,dm816-emac"))
111 return cpsw_am33xx_cm_get_macid(dev, 0x30, slave, mac_addr);
113 if (of_machine_is_compatible("ti,am43"))
114 return cpsw_am33xx_cm_get_macid(dev, 0x630, slave, mac_addr);
116 if (of_machine_is_compatible("ti,dra7"))
117 return davinci_emac_3517_get_macid(dev, 0x514, slave, mac_addr);
119 dev_err(dev, "incompatible machine/device type for reading mac address\n");