phycore-rk3288.c 2.4 KB

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