phycore-rk3288.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2017 PHYTEC Messtechnik GmbH
  4. * Author: Wadim Egorov <w.egorov@phytec.de>
  5. */
  6. #include <asm/io.h>
  7. #include <common.h>
  8. #include <dm.h>
  9. #include <environment.h>
  10. #include <i2c.h>
  11. #include <i2c_eeprom.h>
  12. #include <netdev.h>
  13. #include "som.h"
  14. static int valid_rk3288_som(struct rk3288_som *som)
  15. {
  16. unsigned char *p = (unsigned char *)som;
  17. unsigned char *e = p + sizeof(struct rk3288_som) - 1;
  18. int hw = 0;
  19. while (p < e) {
  20. hw += hweight8(*p);
  21. p++;
  22. }
  23. return hw == som->bs;
  24. }
  25. int rk_board_late_init(void)
  26. {
  27. int ret;
  28. struct udevice *dev;
  29. struct rk3288_som opt;
  30. int off;
  31. /* Get the identificatioin page of M24C32-D EEPROM */
  32. off = fdt_path_offset(gd->fdt_blob, "eeprom0");
  33. if (off < 0) {
  34. printf("%s: No eeprom0 path offset\n", __func__);
  35. return off;
  36. }
  37. ret = uclass_get_device_by_of_offset(UCLASS_I2C_EEPROM, off, &dev);
  38. if (ret) {
  39. printf("%s: Could not find EEPROM\n", __func__);
  40. return ret;
  41. }
  42. ret = i2c_set_chip_offset_len(dev, 2);
  43. if (ret)
  44. return ret;
  45. ret = i2c_eeprom_read(dev, 0, (uint8_t *)&opt,
  46. sizeof(struct rk3288_som));
  47. if (ret) {
  48. printf("%s: Could not read EEPROM\n", __func__);
  49. return ret;
  50. }
  51. if (opt.api_version != 0 || !valid_rk3288_som(&opt)) {
  52. printf("Invalid data or wrong EEPROM layout version.\n");
  53. /* Proceed anyway, since there is no fallback option */
  54. }
  55. if (is_valid_ethaddr(opt.mac))
  56. eth_env_set_enetaddr("ethaddr", opt.mac);
  57. return 0;
  58. }