diff options
author | Tom Rini <trini@konsulko.com> | 2019-08-12 18:47:53 -0400 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2019-08-12 18:47:53 -0400 |
commit | 9c6115822e894ead72fa4c094bf718eaabb9e103 (patch) | |
tree | 4f8843a5cfbe2895a168d96dee111dd31e443b2a /board/siemens | |
parent | 5939afc9611e8ba4a86b96e67670b765ee27668e (diff) | |
parent | 0805fe151d8c47cfbcfddf71c0891ed4f3c10b56 (diff) | |
download | u-boot-9c6115822e894ead72fa4c094bf718eaabb9e103.tar.gz |
Merge branch '2019-08-11-ti-imports'
- More DaVinci updates and fixes
- PCIe support on am65x
- Watchdog converted to DM
- Assorted other bugfixes
Diffstat (limited to 'board/siemens')
-rw-r--r-- | board/siemens/common/factoryset.c | 124 | ||||
-rw-r--r-- | board/siemens/common/factoryset.h | 3 |
2 files changed, 110 insertions, 17 deletions
diff --git a/board/siemens/common/factoryset.c b/board/siemens/common/factoryset.c index 049a65ff77..7715ddf307 100644 --- a/board/siemens/common/factoryset.c +++ b/board/siemens/common/factoryset.c @@ -9,6 +9,8 @@ #include <common.h> #include <env.h> +#include <dm.h> +#include <env_internal.h> #include <i2c.h> #include <asm/io.h> #include <asm/arch/cpu.h> @@ -143,16 +145,39 @@ int factoryset_read_eeprom(int i2c_addr) int i, pages = 0, size = 0; unsigned char eeprom_buf[0x3c00], hdr[4], buf[MAX_STRING_LENGTH]; unsigned char *cp, *cp1; +#if CONFIG_IS_ENABLED(DM_I2C) + struct udevice *bus, *dev; + int ret; +#endif #if defined(CONFIG_DFU_OVER_USB) factory_dat.usb_vendor_id = CONFIG_USB_GADGET_VENDOR_NUM; factory_dat.usb_product_id = CONFIG_USB_GADGET_PRODUCT_NUM; #endif + +#if CONFIG_IS_ENABLED(DM_I2C) + ret = uclass_get_device_by_seq(UCLASS_I2C, EEPROM_I2C_BUS, &bus); + if (ret) + goto err; + + ret = dm_i2c_probe(bus, i2c_addr, 0, &dev); + if (ret) + goto err; + + ret = i2c_set_chip_offset_len(dev, 2); + if (ret) + goto err; + + ret = dm_i2c_read(dev, EEPROM_FATORYSET_OFFSET, hdr, sizeof(hdr)); + if (ret) + goto err; +#else if (i2c_probe(i2c_addr)) goto err; if (i2c_read(i2c_addr, EEPROM_FATORYSET_OFFSET, 2, hdr, sizeof(hdr))) goto err; +#endif if ((hdr[0] != 0x99) || (hdr[1] != 0x80)) { printf("FactorySet is not right in eeprom.\n"); @@ -173,16 +198,33 @@ int factoryset_read_eeprom(int i2c_addr) * data after every time we got a record from eeprom */ debug("Read eeprom page :\n"); - for (i = 0; i < pages; i++) + for (i = 0; i < pages; i++) { +#if CONFIG_IS_ENABLED(DM_I2C) + ret = dm_i2c_read(dev, (OFF_PG + i) * EEPR_PG_SZ, + eeprom_buf + (i * EEPR_PG_SZ), EEPR_PG_SZ); + if (ret) + goto err; +#else if (i2c_read(i2c_addr, (OFF_PG + i) * EEPR_PG_SZ, 2, eeprom_buf + (i * EEPR_PG_SZ), EEPR_PG_SZ)) goto err; +#endif + } - if (size % EEPR_PG_SZ) + if (size % EEPR_PG_SZ) { +#if CONFIG_IS_ENABLED(DM_I2C) + ret = dm_i2c_read(dev, (OFF_PG + pages) * EEPR_PG_SZ, + eeprom_buf + (pages * EEPR_PG_SZ), + size % EEPR_PG_SZ); + if (ret) + goto err; +#else if (i2c_read(i2c_addr, (OFF_PG + pages) * EEPR_PG_SZ, 2, eeprom_buf + (pages * EEPR_PG_SZ), (size % EEPR_PG_SZ))) goto err; +#endif + } /* we do below just for eeprom align */ for (i = 0; i < size; i++) @@ -202,6 +244,20 @@ int factoryset_read_eeprom(int i2c_addr) cp1 += 3; } +#if CONFIG_IS_ENABLED(TARGET_GIEDI) || CONFIG_IS_ENABLED(TARGET_DENEB) + /* get mac address for WLAN */ + ret = get_factory_record_val(cp, size, (uchar *)"WLAN1", (uchar *)"mac", + buf, MAX_STRING_LENGTH); + if (ret > 0) { + cp1 = buf; + for (i = 0; i < 6; i++) { + factory_dat.mac_wlan[i] = simple_strtoul((char *)cp1, + NULL, 16); + cp1 += 3; + } + } +#endif + #if defined(CONFIG_DFU_OVER_USB) /* read vid and pid for dfu mode */ if (0 <= get_factory_record_val(cp, size, (uchar *)"USBD1", @@ -264,42 +320,76 @@ err: return 1; } -static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE; +static int get_mac_from_efuse(uint8_t mac[6]) +{ +#ifdef CONFIG_AM33XX + struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE; + uint32_t mac_hi, mac_lo; + + mac_lo = readl(&cdev->macid0l); + mac_hi = readl(&cdev->macid0h); + + mac[0] = mac_hi & 0xFF; + mac[1] = (mac_hi & 0xFF00) >> 8; + mac[2] = (mac_hi & 0xFF0000) >> 16; + mac[3] = (mac_hi & 0xFF000000) >> 24; + mac[4] = mac_lo & 0xFF; + mac[5] = (mac_lo & 0xFF00) >> 8; +#else + /* unhandled */ + memset(mac, 0, 6); +#endif + if (!is_valid_ethaddr(mac)) { + puts("Warning: ethaddr not set by FactorySet or E-fuse. "); + puts("Set <ethaddr> variable to overcome this.\n"); + return -1; + } + return 0; +} static int factoryset_mac_env_set(void) { uint8_t mac_addr[6]; + /* Set mac from factoryset or try reading E-fuse */ debug("FactorySet: Set mac address\n"); if (is_valid_ethaddr(factory_dat.mac)) { memcpy(mac_addr, factory_dat.mac, 6); } else { - uint32_t mac_hi, mac_lo; - debug("Warning: FactorySet: <ethaddr> not set. Fallback to E-fuse\n"); - mac_lo = readl(&cdev->macid0l); - mac_hi = readl(&cdev->macid0h); - - mac_addr[0] = mac_hi & 0xFF; - mac_addr[1] = (mac_hi & 0xFF00) >> 8; - mac_addr[2] = (mac_hi & 0xFF0000) >> 16; - mac_addr[3] = (mac_hi & 0xFF000000) >> 24; - mac_addr[4] = mac_lo & 0xFF; - mac_addr[5] = (mac_lo & 0xFF00) >> 8; - if (!is_valid_ethaddr(mac_addr)) { - printf("Warning: ethaddr not set by FactorySet or E-fuse. Set <ethaddr> variable to overcome this.\n"); + if (get_mac_from_efuse(mac_addr) < 0) return -1; - } } eth_env_set_enetaddr("ethaddr", mac_addr); + +#if CONFIG_IS_ENABLED(TARGET_GIEDI) || CONFIG_IS_ENABLED(TARGET_DENEB) + eth_env_set_enetaddr("eth1addr", mac_addr); + + /* wlan mac */ + if (is_valid_ethaddr(factory_dat.mac_wlan)) + eth_env_set_enetaddr("eth2addr", factory_dat.mac_wlan); +#endif return 0; } +static void factoryset_dtb_env_set(void) +{ + /* Set ASN in environment*/ + if (factory_dat.asn[0] != 0) { + env_set("dtb_name", (char *)factory_dat.asn); + } else { + /* dtb suffix gets added in load script */ + env_set("dtb_name", "default"); + } +} + int factoryset_env_set(void) { int ret = 0; + factoryset_dtb_env_set(); + if (factoryset_mac_env_set() < 0) ret = -1; diff --git a/board/siemens/common/factoryset.h b/board/siemens/common/factoryset.h index d4e8353249..261a217687 100644 --- a/board/siemens/common/factoryset.h +++ b/board/siemens/common/factoryset.h @@ -11,6 +11,9 @@ struct factorysetcontainer { uchar mac[6]; +#if CONFIG_IS_ENABLED(TARGET_GIEDI) || CONFIG_IS_ENABLED(TARGET_DENEB) + uchar mac_wlan[6]; +#endif int usb_vendor_id; int usb_product_id; int pxm50; |