beelink-s922x.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2020 BayLibre, SAS
  4. * Author: Neil Armstrong <narmstrong@baylibre.com>
  5. */
  6. #include <common.h>
  7. #include <dm.h>
  8. #include <env.h>
  9. #include <init.h>
  10. #include <net.h>
  11. #include <asm/io.h>
  12. #include <asm/arch/sm.h>
  13. #include <asm/arch/eth.h>
  14. #include <asm/arch/boot.h>
  15. #define EFUSE_MAC_OFFSET 20
  16. #define EFUSE_MAC_SIZE 12
  17. #define MAC_ADDR_LEN 6
  18. int misc_init_r(void)
  19. {
  20. u8 mac_addr[MAC_ADDR_LEN];
  21. char efuse_mac_addr[EFUSE_MAC_SIZE], tmp[3];
  22. ssize_t len;
  23. if (IS_ENABLED(CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG) &&
  24. meson_get_soc_rev(tmp, sizeof(tmp)) > 0)
  25. env_set("soc_rev", tmp);
  26. if (!eth_env_get_enetaddr("ethaddr", mac_addr)) {
  27. len = meson_sm_read_efuse(EFUSE_MAC_OFFSET,
  28. efuse_mac_addr, EFUSE_MAC_SIZE);
  29. if (len != EFUSE_MAC_SIZE)
  30. return 0;
  31. /* MAC is stored in ASCII format, 1bytes = 2characters */
  32. for (int i = 0; i < 6; i++) {
  33. tmp[0] = efuse_mac_addr[i * 2];
  34. tmp[1] = efuse_mac_addr[i * 2 + 1];
  35. tmp[2] = '\0';
  36. mac_addr[i] = hextoul(tmp, NULL);
  37. }
  38. if (is_valid_ethaddr(mac_addr))
  39. eth_env_set_enetaddr("ethaddr", mac_addr);
  40. else
  41. meson_generate_serial_ethaddr();
  42. }
  43. return 0;
  44. }