Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Mugunthan V N | e431056 | 2016-04-28 15:36:07 +0530 | [diff] [blame] | 2 | /* |
| 3 | * CPSW common - libs used across TI ethernet devices. |
| 4 | * |
| 5 | * Copyright (C) 2016, Texas Instruments, Incorporated |
Mugunthan V N | e431056 | 2016-04-28 15:36:07 +0530 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <dm.h> |
| 10 | #include <fdt_support.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 11 | #include <asm/global_data.h> |
Mugunthan V N | e431056 | 2016-04-28 15:36:07 +0530 | [diff] [blame] | 12 | #include <asm/io.h> |
| 13 | #include <cpsw.h> |
Simon Glass | 336d461 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 14 | #include <dm/device_compat.h> |
Mugunthan V N | e431056 | 2016-04-28 15:36:07 +0530 | [diff] [blame] | 15 | |
| 16 | DECLARE_GLOBAL_DATA_PTR; |
| 17 | |
| 18 | #define CTRL_MAC_REG(offset, id) ((offset) + 0x8 * (id)) |
| 19 | |
Faiz Abbas | a58d222 | 2019-03-18 13:54:34 +0530 | [diff] [blame] | 20 | static void davinci_emac_3517_get_macid(u32 addr, u8 *mac_addr) |
Mugunthan V N | e431056 | 2016-04-28 15:36:07 +0530 | [diff] [blame] | 21 | { |
Mugunthan V N | e431056 | 2016-04-28 15:36:07 +0530 | [diff] [blame] | 22 | /* try reading mac address from efuse */ |
Faiz Abbas | a58d222 | 2019-03-18 13:54:34 +0530 | [diff] [blame] | 23 | u32 macid_lsb = readl(addr); |
| 24 | u32 macid_msb = readl(addr + 4); |
Mugunthan V N | e431056 | 2016-04-28 15:36:07 +0530 | [diff] [blame] | 25 | |
| 26 | mac_addr[0] = (macid_msb >> 16) & 0xff; |
| 27 | mac_addr[1] = (macid_msb >> 8) & 0xff; |
| 28 | mac_addr[2] = macid_msb & 0xff; |
| 29 | mac_addr[3] = (macid_lsb >> 16) & 0xff; |
| 30 | mac_addr[4] = (macid_lsb >> 8) & 0xff; |
| 31 | mac_addr[5] = macid_lsb & 0xff; |
Mugunthan V N | e431056 | 2016-04-28 15:36:07 +0530 | [diff] [blame] | 32 | } |
| 33 | |
Faiz Abbas | a58d222 | 2019-03-18 13:54:34 +0530 | [diff] [blame] | 34 | static void cpsw_am33xx_cm_get_macid(u32 addr, u8 *mac_addr) |
Mugunthan V N | e431056 | 2016-04-28 15:36:07 +0530 | [diff] [blame] | 35 | { |
Mugunthan V N | e431056 | 2016-04-28 15:36:07 +0530 | [diff] [blame] | 36 | /* try reading mac address from efuse */ |
Faiz Abbas | a58d222 | 2019-03-18 13:54:34 +0530 | [diff] [blame] | 37 | u32 macid_lo = readl(addr); |
| 38 | u32 macid_hi = readl(addr + 4); |
Mugunthan V N | e431056 | 2016-04-28 15:36:07 +0530 | [diff] [blame] | 39 | |
| 40 | mac_addr[5] = (macid_lo >> 8) & 0xff; |
| 41 | mac_addr[4] = macid_lo & 0xff; |
| 42 | mac_addr[3] = (macid_hi >> 24) & 0xff; |
| 43 | mac_addr[2] = (macid_hi >> 16) & 0xff; |
| 44 | mac_addr[1] = (macid_hi >> 8) & 0xff; |
| 45 | mac_addr[0] = macid_hi & 0xff; |
Mugunthan V N | e431056 | 2016-04-28 15:36:07 +0530 | [diff] [blame] | 46 | } |
| 47 | |
Faiz Abbas | a58d222 | 2019-03-18 13:54:34 +0530 | [diff] [blame] | 48 | void ti_cm_get_macid(struct udevice *dev, struct cpsw_platform_data *data, |
| 49 | u8 *mac_addr) |
Mugunthan V N | e431056 | 2016-04-28 15:36:07 +0530 | [diff] [blame] | 50 | { |
Faiz Abbas | a58d222 | 2019-03-18 13:54:34 +0530 | [diff] [blame] | 51 | if (!strcmp(data->macid_sel_compat, "cpsw,am33xx")) |
| 52 | cpsw_am33xx_cm_get_macid(data->syscon_addr, mac_addr); |
| 53 | else if (!strcmp(data->macid_sel_compat, "davinci,emac")) |
| 54 | davinci_emac_3517_get_macid(data->syscon_addr, mac_addr); |
| 55 | } |
Mugunthan V N | e431056 | 2016-04-28 15:36:07 +0530 | [diff] [blame] | 56 | |
Faiz Abbas | a58d222 | 2019-03-18 13:54:34 +0530 | [diff] [blame] | 57 | int ti_cm_get_macid_addr(struct udevice *dev, int slave, |
| 58 | struct cpsw_platform_data *data) |
| 59 | { |
| 60 | void *fdt = (void *)gd->fdt_blob; |
| 61 | int node = dev_of_offset(dev); |
| 62 | fdt32_t gmii = 0; |
| 63 | int syscon; |
| 64 | u16 offset; |
Mugunthan V N | e431056 | 2016-04-28 15:36:07 +0530 | [diff] [blame] | 65 | |
Faiz Abbas | a58d222 | 2019-03-18 13:54:34 +0530 | [diff] [blame] | 66 | if (of_machine_is_compatible("ti,dm8148")) { |
| 67 | offset = 0x630; |
| 68 | data->macid_sel_compat = "cpsw,am33xx"; |
| 69 | } else if (of_machine_is_compatible("ti,am33xx")) { |
| 70 | offset = 0x630; |
| 71 | data->macid_sel_compat = "cpsw,am33xx"; |
| 72 | } else if (device_is_compatible(dev, "ti,am3517-emac")) { |
| 73 | offset = 0x110; |
| 74 | data->macid_sel_compat = "davinci,emac"; |
| 75 | } else if (device_is_compatible(dev, "ti,dm816-emac")) { |
| 76 | offset = 0x30; |
| 77 | data->macid_sel_compat = "cpsw,am33xx"; |
| 78 | } else if (of_machine_is_compatible("ti,am43")) { |
| 79 | offset = 0x630; |
| 80 | data->macid_sel_compat = "cpsw,am33xx"; |
| 81 | } else if (of_machine_is_compatible("ti,dra7")) { |
| 82 | offset = 0x514; |
| 83 | data->macid_sel_compat = "davinci,emac"; |
| 84 | } else { |
| 85 | dev_err(dev, "incompatible machine/device type for reading mac address\n"); |
| 86 | return -ENOENT; |
| 87 | } |
Mugunthan V N | e431056 | 2016-04-28 15:36:07 +0530 | [diff] [blame] | 88 | |
Faiz Abbas | a58d222 | 2019-03-18 13:54:34 +0530 | [diff] [blame] | 89 | syscon = fdtdec_lookup_phandle(fdt, node, "syscon"); |
| 90 | if (syscon < 0) { |
| 91 | pr_err("Syscon offset not found\n"); |
| 92 | return -ENOENT; |
| 93 | } |
Mugunthan V N | e431056 | 2016-04-28 15:36:07 +0530 | [diff] [blame] | 94 | |
Faiz Abbas | a58d222 | 2019-03-18 13:54:34 +0530 | [diff] [blame] | 95 | data->syscon_addr = (u32)map_physmem(fdt_translate_address(fdt, syscon, |
| 96 | &gmii), |
| 97 | sizeof(u32), MAP_NOCACHE); |
| 98 | if (data->syscon_addr == FDT_ADDR_T_NONE) { |
| 99 | pr_err("Not able to get syscon address to get mac efuse address\n"); |
| 100 | return -ENOENT; |
| 101 | } |
Mugunthan V N | e431056 | 2016-04-28 15:36:07 +0530 | [diff] [blame] | 102 | |
Faiz Abbas | a58d222 | 2019-03-18 13:54:34 +0530 | [diff] [blame] | 103 | data->syscon_addr += CTRL_MAC_REG(offset, slave); |
Mugunthan V N | e431056 | 2016-04-28 15:36:07 +0530 | [diff] [blame] | 104 | |
Faiz Abbas | a58d222 | 2019-03-18 13:54:34 +0530 | [diff] [blame] | 105 | return 0; |
| 106 | |
Mugunthan V N | e431056 | 2016-04-28 15:36:07 +0530 | [diff] [blame] | 107 | } |