phycore-rk3288.c 2.3 KB

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