blob: 21b8bbda3d5b61cd900642c5c9cf0fc109c8a347 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Mugunthan V N9e556352016-04-28 15:36:07 +05302/*
3 * CPSW common - libs used across TI ethernet devices.
4 *
5 * Copyright (C) 2016, Texas Instruments, Incorporated
Mugunthan V N9e556352016-04-28 15:36:07 +05306 */
7
8#include <common.h>
9#include <dm.h>
10#include <fdt_support.h>
11#include <asm/io.h>
12#include <cpsw.h>
13
14DECLARE_GLOBAL_DATA_PTR;
15
16#define CTRL_MAC_REG(offset, id) ((offset) + 0x8 * (id))
17
Faiz Abbas8ecdffe2019-03-18 13:54:34 +053018static void davinci_emac_3517_get_macid(u32 addr, u8 *mac_addr)
Mugunthan V N9e556352016-04-28 15:36:07 +053019{
Mugunthan V N9e556352016-04-28 15:36:07 +053020 /* try reading mac address from efuse */
Faiz Abbas8ecdffe2019-03-18 13:54:34 +053021 u32 macid_lsb = readl(addr);
22 u32 macid_msb = readl(addr + 4);
Mugunthan V N9e556352016-04-28 15:36:07 +053023
24 mac_addr[0] = (macid_msb >> 16) & 0xff;
25 mac_addr[1] = (macid_msb >> 8) & 0xff;
26 mac_addr[2] = macid_msb & 0xff;
27 mac_addr[3] = (macid_lsb >> 16) & 0xff;
28 mac_addr[4] = (macid_lsb >> 8) & 0xff;
29 mac_addr[5] = macid_lsb & 0xff;
Faiz Abbas8ecdffe2019-03-18 13:54:34 +053030}
Mugunthan V N9e556352016-04-28 15:36:07 +053031
Faiz Abbas8ecdffe2019-03-18 13:54:34 +053032static void cpsw_am33xx_cm_get_macid(u32 addr, u8 *mac_addr)
33{
34 /* try reading mac address from efuse */
35 u32 macid_lo = readl(addr);
36 u32 macid_hi = readl(addr + 4);
37
38 mac_addr[5] = (macid_lo >> 8) & 0xff;
39 mac_addr[4] = macid_lo & 0xff;
40 mac_addr[3] = (macid_hi >> 24) & 0xff;
41 mac_addr[2] = (macid_hi >> 16) & 0xff;
42 mac_addr[1] = (macid_hi >> 8) & 0xff;
43 mac_addr[0] = macid_hi & 0xff;
Mugunthan V N9e556352016-04-28 15:36:07 +053044}
45
Faiz Abbas8ecdffe2019-03-18 13:54:34 +053046void ti_cm_get_macid(struct udevice *dev, struct cpsw_platform_data *data,
47 u8 *mac_addr)
48{
49 if (!strcmp(data->macid_sel_compat, "cpsw,am33xx"))
50 cpsw_am33xx_cm_get_macid(data->syscon_addr, mac_addr);
51 else if (!strcmp(data->macid_sel_compat, "davinci,emac"))
52 davinci_emac_3517_get_macid(data->syscon_addr, mac_addr);
53}
54
55int ti_cm_get_macid_addr(struct udevice *dev, int slave,
56 struct cpsw_platform_data *data)
Mugunthan V N9e556352016-04-28 15:36:07 +053057{
58 void *fdt = (void *)gd->fdt_blob;
Simon Glassdd79d6e2017-01-17 16:52:55 -070059 int node = dev_of_offset(dev);
Mugunthan V N9e556352016-04-28 15:36:07 +053060 fdt32_t gmii = 0;
61 int syscon;
Faiz Abbas8ecdffe2019-03-18 13:54:34 +053062 u16 offset;
63
64 if (of_machine_is_compatible("ti,dm8148")) {
65 offset = 0x630;
66 data->macid_sel_compat = "cpsw,am33xx";
67 } else if (of_machine_is_compatible("ti,am33xx")) {
68 offset = 0x630;
69 data->macid_sel_compat = "cpsw,am33xx";
70 } else if (device_is_compatible(dev, "ti,am3517-emac")) {
71 offset = 0x110;
72 data->macid_sel_compat = "davinci,emac";
73 } else if (device_is_compatible(dev, "ti,dm816-emac")) {
74 offset = 0x30;
75 data->macid_sel_compat = "cpsw,am33xx";
76 } else if (of_machine_is_compatible("ti,am43")) {
77 offset = 0x630;
78 data->macid_sel_compat = "cpsw,am33xx";
79 } else if (of_machine_is_compatible("ti,dra7")) {
80 offset = 0x514;
81 data->macid_sel_compat = "davinci,emac";
82 } else {
83 dev_err(dev, "incompatible machine/device type for reading mac address\n");
84 return -ENOENT;
85 }
Mugunthan V N9e556352016-04-28 15:36:07 +053086
87 syscon = fdtdec_lookup_phandle(fdt, node, "syscon");
88 if (syscon < 0) {
Masahiro Yamada81e10422017-09-16 14:10:41 +090089 pr_err("Syscon offset not found\n");
Mugunthan V N9e556352016-04-28 15:36:07 +053090 return -ENOENT;
91 }
92
Faiz Abbas8ecdffe2019-03-18 13:54:34 +053093 data->syscon_addr = (u32)map_physmem(fdt_translate_address(fdt, syscon,
94 &gmii),
95 sizeof(u32), MAP_NOCACHE);
96 if (data->syscon_addr == FDT_ADDR_T_NONE) {
Masahiro Yamada81e10422017-09-16 14:10:41 +090097 pr_err("Not able to get syscon address to get mac efuse address\n");
Mugunthan V N9e556352016-04-28 15:36:07 +053098 return -ENOENT;
99 }
100
Faiz Abbas8ecdffe2019-03-18 13:54:34 +0530101 data->syscon_addr += CTRL_MAC_REG(offset, slave);
Mugunthan V N9e556352016-04-28 15:36:07 +0530102
103 return 0;
Mugunthan V N9e556352016-04-28 15:36:07 +0530104
Mugunthan V N9e556352016-04-28 15:36:07 +0530105}