phycore-rk3288.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 <eeprom.h>
  7. #include <init.h>
  8. #include <asm/io.h>
  9. #include <common.h>
  10. #include <dm.h>
  11. #include <env.h>
  12. #include <env_internal.h>
  13. #include <i2c.h>
  14. #include <i2c_eeprom.h>
  15. #include <netdev.h>
  16. #include "som.h"
  17. #include <power/regulator.h>
  18. #include <power/rk8xx_pmic.h>
  19. static int valid_rk3288_som(struct rk3288_som *som)
  20. {
  21. unsigned char *p = (unsigned char *)som;
  22. unsigned char *e = p + sizeof(struct rk3288_som) - 1;
  23. int hw = 0;
  24. while (p < e) {
  25. hw += hweight8(*p);
  26. p++;
  27. }
  28. return hw == som->bs;
  29. }
  30. int rk3288_board_late_init(void)
  31. {
  32. int ret;
  33. struct udevice *dev;
  34. struct rk3288_som opt;
  35. int off;
  36. /* Get the identificatioin page of M24C32-D EEPROM */
  37. off = fdt_path_offset(gd->fdt_blob, "eeprom0");
  38. if (off < 0) {
  39. printf("%s: No eeprom0 path offset\n", __func__);
  40. return off;
  41. }
  42. ret = uclass_get_device_by_of_offset(UCLASS_I2C_EEPROM, off, &dev);
  43. if (ret) {
  44. printf("%s: Could not find EEPROM\n", __func__);
  45. return ret;
  46. }
  47. ret = i2c_set_chip_offset_len(dev, 2);
  48. if (ret)
  49. return ret;
  50. ret = i2c_eeprom_read(dev, 0, (uint8_t *)&opt,
  51. sizeof(struct rk3288_som));
  52. if (ret) {
  53. printf("%s: Could not read EEPROM\n", __func__);
  54. return ret;
  55. }
  56. if (opt.api_version != 0 || !valid_rk3288_som(&opt)) {
  57. printf("Invalid data or wrong EEPROM layout version.\n");
  58. /* Proceed anyway, since there is no fallback option */
  59. }
  60. if (is_valid_ethaddr(opt.mac))
  61. eth_env_set_enetaddr("ethaddr", opt.mac);
  62. return 0;
  63. }
  64. #ifdef CONFIG_SPL_BUILD
  65. #if !defined(CONFIG_SPL_OF_PLATDATA)
  66. static int phycore_init(void)
  67. {
  68. struct udevice *pmic;
  69. int ret;
  70. ret = uclass_first_device_err(UCLASS_PMIC, &pmic);
  71. if (ret)
  72. return ret;
  73. #if defined(CONFIG_SPL_POWER_SUPPORT)
  74. /* Increase USB input current to 2A */
  75. ret = rk818_spl_configure_usb_input_current(pmic, 2000);
  76. if (ret)
  77. return ret;
  78. /* Close charger when USB lower then 3.26V */
  79. ret = rk818_spl_configure_usb_chrg_shutdown(pmic, 3260000);
  80. if (ret)
  81. return ret;
  82. #endif
  83. return 0;
  84. }
  85. #endif
  86. void spl_board_init(void)
  87. {
  88. #if !defined(CONFIG_SPL_OF_PLATDATA)
  89. int ret;
  90. if (of_machine_is_compatible("phytec,rk3288-phycore-som")) {
  91. ret = phycore_init();
  92. if (ret) {
  93. debug("Failed to set up phycore power settings: %d\n",
  94. ret);
  95. return;
  96. }
  97. }
  98. #endif
  99. }
  100. #endif