1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2017 PHYTEC Messtechnik GmbH
4 * Author: Wadim Egorov <w.egorov@phytec.de>
11 #include <asm/global_data.h>
16 #include <env_internal.h>
18 #include <i2c_eeprom.h>
20 #include <linux/bitops.h>
22 #include <power/regulator.h>
23 #include <power/rk8xx_pmic.h>
25 static int valid_rk3288_som(struct rk3288_som *som)
27 unsigned char *p = (unsigned char *)som;
28 unsigned char *e = p + sizeof(struct rk3288_som) - 1;
39 int rk3288_board_late_init(void)
43 struct rk3288_som opt;
46 /* Get the identificatioin page of M24C32-D EEPROM */
47 off = fdt_path_offset(gd->fdt_blob, "eeprom0");
49 printf("%s: No eeprom0 path offset\n", __func__);
53 ret = uclass_get_device_by_of_offset(UCLASS_I2C_EEPROM, off, &dev);
55 printf("%s: Could not find EEPROM\n", __func__);
59 ret = i2c_set_chip_offset_len(dev, 2);
63 ret = i2c_eeprom_read(dev, 0, (uint8_t *)&opt,
64 sizeof(struct rk3288_som));
66 printf("%s: Could not read EEPROM\n", __func__);
70 if (opt.api_version != 0 || !valid_rk3288_som(&opt)) {
71 printf("Invalid data or wrong EEPROM layout version.\n");
72 /* Proceed anyway, since there is no fallback option */
75 if (is_valid_ethaddr(opt.mac))
76 eth_env_set_enetaddr("ethaddr", opt.mac);
81 #ifdef CONFIG_SPL_BUILD
82 #if !defined(CONFIG_SPL_OF_PLATDATA)
83 static int phycore_init(void)
88 ret = uclass_first_device_err(UCLASS_PMIC, &pmic);
92 #if defined(CONFIG_SPL_POWER)
93 /* Increase USB input current to 2A */
94 ret = rk818_spl_configure_usb_input_current(pmic, 2000);
98 /* Close charger when USB lower then 3.26V */
99 ret = rk818_spl_configure_usb_chrg_shutdown(pmic, 3260000);
108 void spl_board_init(void)
110 #if !defined(CONFIG_SPL_OF_PLATDATA)
113 if (of_machine_is_compatible("phytec,rk3288-phycore-som")) {
114 ret = phycore_init();
116 debug("Failed to set up phycore power settings: %d\n",