phycore-rk3288.c 2.4 KB

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