1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2017 PHYTEC Messtechnik GmbH
4 * Author: Wadim Egorov <w.egorov@phytec.de>
10 #include <environment.h>
13 #include <i2c_eeprom.h>
16 #include <power/regulator.h>
17 #include <power/rk8xx_pmic.h>
19 static int valid_rk3288_som(struct rk3288_som *som)
21 unsigned char *p = (unsigned char *)som;
22 unsigned char *e = p + sizeof(struct rk3288_som) - 1;
33 int rk3288_board_late_init(void)
37 struct rk3288_som opt;
40 /* Get the identificatioin page of M24C32-D EEPROM */
41 off = fdt_path_offset(gd->fdt_blob, "eeprom0");
43 printf("%s: No eeprom0 path offset\n", __func__);
47 ret = uclass_get_device_by_of_offset(UCLASS_I2C_EEPROM, off, &dev);
49 printf("%s: Could not find EEPROM\n", __func__);
53 ret = i2c_set_chip_offset_len(dev, 2);
57 ret = i2c_eeprom_read(dev, 0, (uint8_t *)&opt,
58 sizeof(struct rk3288_som));
60 printf("%s: Could not read EEPROM\n", __func__);
64 if (opt.api_version != 0 || !valid_rk3288_som(&opt)) {
65 printf("Invalid data or wrong EEPROM layout version.\n");
66 /* Proceed anyway, since there is no fallback option */
69 if (is_valid_ethaddr(opt.mac))
70 eth_env_set_enetaddr("ethaddr", opt.mac);
75 #ifdef CONFIG_SPL_BUILD
76 #if !defined(CONFIG_SPL_OF_PLATDATA)
77 static int phycore_init(void)
82 ret = uclass_first_device_err(UCLASS_PMIC, &pmic);
86 #if defined(CONFIG_SPL_POWER_SUPPORT)
87 /* Increase USB input current to 2A */
88 ret = rk818_spl_configure_usb_input_current(pmic, 2000);
92 /* Close charger when USB lower then 3.26V */
93 ret = rk818_spl_configure_usb_chrg_shutdown(pmic, 3260000);
102 void spl_board_init(void)
104 #if !defined(CONFIG_SPL_OF_PLATDATA)
107 if (of_machine_is_compatible("phytec,rk3288-phycore-som")) {
108 ret = phycore_init();
110 debug("Failed to set up phycore power settings: %d\n",