1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2017 PHYTEC Messtechnik GmbH
4 * Author: Wadim Egorov <w.egorov@phytec.de>
12 #include <env_internal.h>
14 #include <i2c_eeprom.h>
17 #include <power/regulator.h>
18 #include <power/rk8xx_pmic.h>
20 static int valid_rk3288_som(struct rk3288_som *som)
22 unsigned char *p = (unsigned char *)som;
23 unsigned char *e = p + sizeof(struct rk3288_som) - 1;
34 int rk3288_board_late_init(void)
38 struct rk3288_som opt;
41 /* Get the identificatioin page of M24C32-D EEPROM */
42 off = fdt_path_offset(gd->fdt_blob, "eeprom0");
44 printf("%s: No eeprom0 path offset\n", __func__);
48 ret = uclass_get_device_by_of_offset(UCLASS_I2C_EEPROM, off, &dev);
50 printf("%s: Could not find EEPROM\n", __func__);
54 ret = i2c_set_chip_offset_len(dev, 2);
58 ret = i2c_eeprom_read(dev, 0, (uint8_t *)&opt,
59 sizeof(struct rk3288_som));
61 printf("%s: Could not read EEPROM\n", __func__);
65 if (opt.api_version != 0 || !valid_rk3288_som(&opt)) {
66 printf("Invalid data or wrong EEPROM layout version.\n");
67 /* Proceed anyway, since there is no fallback option */
70 if (is_valid_ethaddr(opt.mac))
71 eth_env_set_enetaddr("ethaddr", opt.mac);
76 #ifdef CONFIG_SPL_BUILD
77 #if !defined(CONFIG_SPL_OF_PLATDATA)
78 static int phycore_init(void)
83 ret = uclass_first_device_err(UCLASS_PMIC, &pmic);
87 #if defined(CONFIG_SPL_POWER_SUPPORT)
88 /* Increase USB input current to 2A */
89 ret = rk818_spl_configure_usb_input_current(pmic, 2000);
93 /* Close charger when USB lower then 3.26V */
94 ret = rk818_spl_configure_usb_chrg_shutdown(pmic, 3260000);
103 void spl_board_init(void)
105 #if !defined(CONFIG_SPL_OF_PLATDATA)
108 if (of_machine_is_compatible("phytec,rk3288-phycore-som")) {
109 ret = phycore_init();
111 debug("Failed to set up phycore power settings: %d\n",