phycore-rk3288.c 2.3 KB

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