183d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
2a13110a9SKlaus Goger /*
3a13110a9SKlaus Goger  * (C) Copyright 2017 Theobroma Systems Design und Consulting GmbH
4a13110a9SKlaus Goger  */
5fb740646SPhilipp Tomsich 
6a13110a9SKlaus Goger #include <common.h>
7a13110a9SKlaus Goger #include <dm.h>
89925f1dbSAlex Kiernan #include <environment.h>
9e92e5803SPhilipp Tomsich #include <misc.h>
10614539d4SPhilipp Tomsich #include <spl.h>
11aa41220fSJakob Unterwurzacher #include <syscon.h>
12614539d4SPhilipp Tomsich #include <usb.h>
13a13110a9SKlaus Goger #include <dm/pinctrl.h>
14a13110a9SKlaus Goger #include <dm/uclass-internal.h>
15aa41220fSJakob Unterwurzacher #include <asm/io.h>
16ae0d33a7SPhilipp Tomsich #include <asm/gpio.h>
179415b9a7SPhilipp Tomsich #include <asm/setup.h>
18ae0d33a7SPhilipp Tomsich #include <asm/arch/clock.h>
19ae0d33a7SPhilipp Tomsich #include <asm/arch/cru_rk3399.h>
20aa41220fSJakob Unterwurzacher #include <asm/arch/hardware.h>
21aa41220fSJakob Unterwurzacher #include <asm/arch/grf_rk3399.h>
22a13110a9SKlaus Goger #include <asm/arch/periph.h>
23a13110a9SKlaus Goger #include <power/regulator.h>
24e92e5803SPhilipp Tomsich #include <u-boot/sha256.h>
25e92e5803SPhilipp Tomsich 
board_init(void)26a13110a9SKlaus Goger int board_init(void)
27a13110a9SKlaus Goger {
28a13110a9SKlaus Goger 	int ret;
29a13110a9SKlaus Goger 
30a13110a9SKlaus Goger 	/*
310b5e7aabSPhilipp Tomsich 	 * We need to call into regulators_enable_boot_on() again, as the call
320b5e7aabSPhilipp Tomsich 	 * during SPL may have not included all regulators.
33a13110a9SKlaus Goger 	 */
340b5e7aabSPhilipp Tomsich 	ret = regulators_enable_boot_on(false);
35a13110a9SKlaus Goger 	if (ret)
360b5e7aabSPhilipp Tomsich 		debug("%s: Cannot enable boot on regulator\n", __func__);
37a13110a9SKlaus Goger 
38a13110a9SKlaus Goger 	return 0;
39a13110a9SKlaus Goger }
40a13110a9SKlaus Goger 
rk3399_force_power_on_reset(void)41ae0d33a7SPhilipp Tomsich static void rk3399_force_power_on_reset(void)
42ae0d33a7SPhilipp Tomsich {
43ae0d33a7SPhilipp Tomsich 	ofnode node;
44ae0d33a7SPhilipp Tomsich 	struct gpio_desc sysreset_gpio;
45ae0d33a7SPhilipp Tomsich 
46ae0d33a7SPhilipp Tomsich 	debug("%s: trying to force a power-on reset\n", __func__);
47ae0d33a7SPhilipp Tomsich 
48ae0d33a7SPhilipp Tomsich 	node = ofnode_path("/config");
49ae0d33a7SPhilipp Tomsich 	if (!ofnode_valid(node)) {
50ae0d33a7SPhilipp Tomsich 		debug("%s: no /config node?\n", __func__);
51ae0d33a7SPhilipp Tomsich 		return;
52ae0d33a7SPhilipp Tomsich 	}
53ae0d33a7SPhilipp Tomsich 
54ae0d33a7SPhilipp Tomsich 	if (gpio_request_by_name_nodev(node, "sysreset-gpio", 0,
55ae0d33a7SPhilipp Tomsich 				       &sysreset_gpio, GPIOD_IS_OUT)) {
56ae0d33a7SPhilipp Tomsich 		debug("%s: could not find a /config/sysreset-gpio\n", __func__);
57ae0d33a7SPhilipp Tomsich 		return;
58ae0d33a7SPhilipp Tomsich 	}
59ae0d33a7SPhilipp Tomsich 
60ae0d33a7SPhilipp Tomsich 	dm_gpio_set_value(&sysreset_gpio, 1);
61ae0d33a7SPhilipp Tomsich }
62ae0d33a7SPhilipp Tomsich 
spl_board_init(void)63fb740646SPhilipp Tomsich void spl_board_init(void)
64fb740646SPhilipp Tomsich {
65482cf223SPhilipp Tomsich 	int  ret;
66ae0d33a7SPhilipp Tomsich 	struct rk3399_cru *cru = rockchip_get_cru();
67ae0d33a7SPhilipp Tomsich 
68ae0d33a7SPhilipp Tomsich 	/*
69ae0d33a7SPhilipp Tomsich 	 * The RK3399 resets only 'almost all logic' (see also in the TRM
70ae0d33a7SPhilipp Tomsich 	 * "3.9.4 Global software reset"), when issuing a software reset.
71ae0d33a7SPhilipp Tomsich 	 * This may cause issues during boot-up for some configurations of
72ae0d33a7SPhilipp Tomsich 	 * the application software stack.
73ae0d33a7SPhilipp Tomsich 	 *
74ae0d33a7SPhilipp Tomsich 	 * To work around this, we test whether the last reset reason was
75ae0d33a7SPhilipp Tomsich 	 * a power-on reset and (if not) issue an overtemp-reset to reset
76ae0d33a7SPhilipp Tomsich 	 * the entire module.
77ae0d33a7SPhilipp Tomsich 	 *
78ae0d33a7SPhilipp Tomsich 	 * While this was previously fixed by modifying the various places
79ae0d33a7SPhilipp Tomsich 	 * that could generate a software reset (e.g. U-Boot's sysreset
80ae0d33a7SPhilipp Tomsich 	 * driver, the ATF or Linux), we now have it here to ensure that
81ae0d33a7SPhilipp Tomsich 	 * we no longer have to track this through the various components.
82ae0d33a7SPhilipp Tomsich 	 */
83ae0d33a7SPhilipp Tomsich 	if (cru->glb_rst_st != 0)
84ae0d33a7SPhilipp Tomsich 		rk3399_force_power_on_reset();
85482cf223SPhilipp Tomsich 
86482cf223SPhilipp Tomsich 	/*
87482cf223SPhilipp Tomsich 	 * Turning the eMMC and SPI back on (if disabled via the Qseven
88482cf223SPhilipp Tomsich 	 * BIOS_ENABLE) signal is done through a always-on regulator).
89482cf223SPhilipp Tomsich 	 */
90482cf223SPhilipp Tomsich 	ret = regulators_enable_boot_on(false);
91482cf223SPhilipp Tomsich 	if (ret)
92482cf223SPhilipp Tomsich 		debug("%s: Cannot enable boot on regulator\n", __func__);
93482cf223SPhilipp Tomsich 
94fb740646SPhilipp Tomsich 	preloader_console_init();
95fb740646SPhilipp Tomsich }
96fb740646SPhilipp Tomsich 
setup_macaddr(void)978adc9d18SKlaus Goger static void setup_macaddr(void)
988adc9d18SKlaus Goger {
998adc9d18SKlaus Goger #if CONFIG_IS_ENABLED(CMD_NET)
1008adc9d18SKlaus Goger 	int ret;
10100caae6dSSimon Glass 	const char *cpuid = env_get("cpuid#");
1028adc9d18SKlaus Goger 	u8 hash[SHA256_SUM_LEN];
1038adc9d18SKlaus Goger 	int size = sizeof(hash);
1048adc9d18SKlaus Goger 	u8 mac_addr[6];
1058adc9d18SKlaus Goger 
1068adc9d18SKlaus Goger 	/* Only generate a MAC address, if none is set in the environment */
10700caae6dSSimon Glass 	if (env_get("ethaddr"))
1088adc9d18SKlaus Goger 		return;
1098adc9d18SKlaus Goger 
1108adc9d18SKlaus Goger 	if (!cpuid) {
1118adc9d18SKlaus Goger 		debug("%s: could not retrieve 'cpuid#'\n", __func__);
1128adc9d18SKlaus Goger 		return;
1138adc9d18SKlaus Goger 	}
1148adc9d18SKlaus Goger 
1158adc9d18SKlaus Goger 	ret = hash_block("sha256", (void *)cpuid, strlen(cpuid), hash, &size);
1168adc9d18SKlaus Goger 	if (ret) {
1178adc9d18SKlaus Goger 		debug("%s: failed to calculate SHA256\n", __func__);
1188adc9d18SKlaus Goger 		return;
1198adc9d18SKlaus Goger 	}
1208adc9d18SKlaus Goger 
1218adc9d18SKlaus Goger 	/* Copy 6 bytes of the hash to base the MAC address on */
1228adc9d18SKlaus Goger 	memcpy(mac_addr, hash, 6);
1238adc9d18SKlaus Goger 
1248adc9d18SKlaus Goger 	/* Make this a valid MAC address and set it */
1258adc9d18SKlaus Goger 	mac_addr[0] &= 0xfe;  /* clear multicast bit */
1268adc9d18SKlaus Goger 	mac_addr[0] |= 0x02;  /* set local assignment bit (IEEE802) */
127fd1e959eSSimon Glass 	eth_env_set_enetaddr("ethaddr", mac_addr);
1288adc9d18SKlaus Goger #endif
1298adc9d18SKlaus Goger }
1308adc9d18SKlaus Goger 
setup_serial(void)1319415b9a7SPhilipp Tomsich static void setup_serial(void)
1329415b9a7SPhilipp Tomsich {
1339415b9a7SPhilipp Tomsich #if CONFIG_IS_ENABLED(ROCKCHIP_EFUSE)
13426722335SKever Yang 	const u32 cpuid_offset = 0x7;
13526722335SKever Yang 	const u32 cpuid_length = 0x10;
13626722335SKever Yang 
1379415b9a7SPhilipp Tomsich 	struct udevice *dev;
1389415b9a7SPhilipp Tomsich 	int ret, i;
13926722335SKever Yang 	u8 cpuid[cpuid_length];
14026722335SKever Yang 	u8 low[cpuid_length/2], high[cpuid_length/2];
14126722335SKever Yang 	char cpuid_str[cpuid_length * 2 + 1];
1429415b9a7SPhilipp Tomsich 	u64 serialno;
14360d7c509SKlaus Goger 	char serialno_str[17];
1449415b9a7SPhilipp Tomsich 
1458adc9d18SKlaus Goger 	/* retrieve the device */
1468adc9d18SKlaus Goger 	ret = uclass_get_device_by_driver(UCLASS_MISC,
1478adc9d18SKlaus Goger 					  DM_GET_DRIVER(rockchip_efuse), &dev);
1489415b9a7SPhilipp Tomsich 	if (ret) {
1499415b9a7SPhilipp Tomsich 		debug("%s: could not find efuse device\n", __func__);
1509415b9a7SPhilipp Tomsich 		return;
1519415b9a7SPhilipp Tomsich 	}
1529415b9a7SPhilipp Tomsich 
1539415b9a7SPhilipp Tomsich 	/* read the cpu_id range from the efuses */
15426722335SKever Yang 	ret = misc_read(dev, cpuid_offset, &cpuid, sizeof(cpuid));
1559415b9a7SPhilipp Tomsich 	if (ret) {
1569415b9a7SPhilipp Tomsich 		debug("%s: reading cpuid from the efuses failed\n",
1579415b9a7SPhilipp Tomsich 		      __func__);
1589415b9a7SPhilipp Tomsich 		return;
1599415b9a7SPhilipp Tomsich 	}
1609415b9a7SPhilipp Tomsich 
1619415b9a7SPhilipp Tomsich 	memset(cpuid_str, 0, sizeof(cpuid_str));
1629415b9a7SPhilipp Tomsich 	for (i = 0; i < 16; i++)
1639415b9a7SPhilipp Tomsich 		sprintf(&cpuid_str[i * 2], "%02x", cpuid[i]);
1649415b9a7SPhilipp Tomsich 
1659415b9a7SPhilipp Tomsich 	debug("cpuid: %s\n", cpuid_str);
1669415b9a7SPhilipp Tomsich 
1679415b9a7SPhilipp Tomsich 	/*
1689415b9a7SPhilipp Tomsich 	 * Mix the cpuid bytes using the same rules as in
1699415b9a7SPhilipp Tomsich 	 *   ${linux}/drivers/soc/rockchip/rockchip-cpuinfo.c
1709415b9a7SPhilipp Tomsich 	 */
1719415b9a7SPhilipp Tomsich 	for (i = 0; i < 8; i++) {
1729415b9a7SPhilipp Tomsich 		low[i] = cpuid[1 + (i << 1)];
1739415b9a7SPhilipp Tomsich 		high[i] = cpuid[i << 1];
1749415b9a7SPhilipp Tomsich 	}
1759415b9a7SPhilipp Tomsich 
1769415b9a7SPhilipp Tomsich 	serialno = crc32_no_comp(0, low, 8);
1779415b9a7SPhilipp Tomsich 	serialno |= (u64)crc32_no_comp(serialno, high, 8) << 32;
178b32b1bd1SJakob Unterwurzacher 	snprintf(serialno_str, sizeof(serialno_str), "%016llx", serialno);
1799415b9a7SPhilipp Tomsich 
180382bee57SSimon Glass 	env_set("cpuid#", cpuid_str);
181382bee57SSimon Glass 	env_set("serial#", serialno_str);
1829415b9a7SPhilipp Tomsich #endif
1839415b9a7SPhilipp Tomsich }
1849415b9a7SPhilipp Tomsich 
setup_iodomain(void)185aa41220fSJakob Unterwurzacher static void setup_iodomain(void)
186aa41220fSJakob Unterwurzacher {
187aa41220fSJakob Unterwurzacher 	const u32 GRF_IO_VSEL_GPIO4CD_SHIFT = 3;
188aa41220fSJakob Unterwurzacher 	struct rk3399_grf_regs *grf =
189aa41220fSJakob Unterwurzacher 	    syscon_get_first_range(ROCKCHIP_SYSCON_GRF);
190aa41220fSJakob Unterwurzacher 
191aa41220fSJakob Unterwurzacher 	/*
192aa41220fSJakob Unterwurzacher 	 * Set bit 3 in GRF_IO_VSEL so PCIE_RST# works (pin GPIO4_C6).
193aa41220fSJakob Unterwurzacher 	 * Linux assumes that PCIE_RST# works out of the box as it probes
194aa41220fSJakob Unterwurzacher 	 * PCIe before loading the iodomain driver.
195aa41220fSJakob Unterwurzacher 	 */
196aa41220fSJakob Unterwurzacher 	rk_setreg(&grf->io_vsel, 1 << GRF_IO_VSEL_GPIO4CD_SHIFT);
197aa41220fSJakob Unterwurzacher }
198aa41220fSJakob Unterwurzacher 
199*41826f6aSKlaus Goger /*
200*41826f6aSKlaus Goger  * Swap mmc0 and mmc1 in boot_targets if booted from SD-Card.
201*41826f6aSKlaus Goger  *
202*41826f6aSKlaus Goger  * If bootsource is uSD-card we can assume that we want to use the
203*41826f6aSKlaus Goger  * SD-Card instead of the eMMC as first boot_target for distroboot.
204*41826f6aSKlaus Goger  * We only want to swap the defaults and not any custom environment a
205*41826f6aSKlaus Goger  * user has set. We exit early if a changed boot_targets environment
206*41826f6aSKlaus Goger  * is detected.
207*41826f6aSKlaus Goger  */
setup_boottargets(void)208*41826f6aSKlaus Goger static int setup_boottargets(void)
209*41826f6aSKlaus Goger {
210*41826f6aSKlaus Goger 	const char *boot_device =
211*41826f6aSKlaus Goger 		ofnode_get_chosen_prop("u-boot,spl-boot-device");
212*41826f6aSKlaus Goger 	char *env_default, *env;
213*41826f6aSKlaus Goger 
214*41826f6aSKlaus Goger 	if (!boot_device) {
215*41826f6aSKlaus Goger 		debug("%s: /chosen/u-boot,spl-boot-device not set\n",
216*41826f6aSKlaus Goger 		      __func__);
217*41826f6aSKlaus Goger 		return -1;
218*41826f6aSKlaus Goger 	}
219*41826f6aSKlaus Goger 	debug("%s: booted from %s\n", __func__, boot_device);
220*41826f6aSKlaus Goger 
221*41826f6aSKlaus Goger 	env_default = env_get_default("boot_targets");
222*41826f6aSKlaus Goger 	env = env_get("boot_targets");
223*41826f6aSKlaus Goger 	if (!env) {
224*41826f6aSKlaus Goger 		debug("%s: boot_targets does not exist\n", __func__);
225*41826f6aSKlaus Goger 		return -1;
226*41826f6aSKlaus Goger 	}
227*41826f6aSKlaus Goger 	debug("%s: boot_targets current: %s - default: %s\n",
228*41826f6aSKlaus Goger 	      __func__, env, env_default);
229*41826f6aSKlaus Goger 
230*41826f6aSKlaus Goger 	if (strcmp(env_default, env) != 0) {
231*41826f6aSKlaus Goger 		debug("%s: boot_targets not default, don't change it\n",
232*41826f6aSKlaus Goger 		      __func__);
233*41826f6aSKlaus Goger 		return 0;
234*41826f6aSKlaus Goger 	}
235*41826f6aSKlaus Goger 
236*41826f6aSKlaus Goger 	/*
237*41826f6aSKlaus Goger 	 * Only run, if booting from mmc1 (i.e. /dwmmc@fe320000) and
238*41826f6aSKlaus Goger 	 * only consider cases where the default boot-order first
239*41826f6aSKlaus Goger 	 * tries to boot from mmc0 (eMMC) and then from mmc1
240*41826f6aSKlaus Goger 	 * (i.e. external SD).
241*41826f6aSKlaus Goger 	 *
242*41826f6aSKlaus Goger 	 * In other words: the SD card will be moved to earlier in the
243*41826f6aSKlaus Goger 	 * order, if U-Boot was also loaded from the SD-card.
244*41826f6aSKlaus Goger 	 */
245*41826f6aSKlaus Goger 	if (!strcmp(boot_device, "/dwmmc@fe320000")) {
246*41826f6aSKlaus Goger 		char *mmc0, *mmc1;
247*41826f6aSKlaus Goger 
248*41826f6aSKlaus Goger 		debug("%s: booted from SD-Card\n", __func__);
249*41826f6aSKlaus Goger 		mmc0 = strstr(env, "mmc0");
250*41826f6aSKlaus Goger 		mmc1 = strstr(env, "mmc1");
251*41826f6aSKlaus Goger 
252*41826f6aSKlaus Goger 		if (!mmc0 || !mmc1) {
253*41826f6aSKlaus Goger 			debug("%s: only one mmc boot_target found\n", __func__);
254*41826f6aSKlaus Goger 			return -1;
255*41826f6aSKlaus Goger 		}
256*41826f6aSKlaus Goger 
257*41826f6aSKlaus Goger 		/*
258*41826f6aSKlaus Goger 		 * If mmc0 comes first in the boot order, we need to change
259*41826f6aSKlaus Goger 		 * the strings to make mmc1 first.
260*41826f6aSKlaus Goger 		 */
261*41826f6aSKlaus Goger 		if (mmc0 < mmc1) {
262*41826f6aSKlaus Goger 			mmc0[3] = '1';
263*41826f6aSKlaus Goger 			mmc1[3] = '0';
264*41826f6aSKlaus Goger 			debug("%s: set boot_targets to: %s\n", __func__, env);
265*41826f6aSKlaus Goger 			env_set("boot_targets", env);
266*41826f6aSKlaus Goger 		}
267*41826f6aSKlaus Goger 	}
268*41826f6aSKlaus Goger 
269*41826f6aSKlaus Goger 	return 0;
270*41826f6aSKlaus Goger }
271*41826f6aSKlaus Goger 
misc_init_r(void)2729415b9a7SPhilipp Tomsich int misc_init_r(void)
2739415b9a7SPhilipp Tomsich {
2749415b9a7SPhilipp Tomsich 	setup_serial();
2758adc9d18SKlaus Goger 	setup_macaddr();
276aa41220fSJakob Unterwurzacher 	setup_iodomain();
277*41826f6aSKlaus Goger 	setup_boottargets();
2789415b9a7SPhilipp Tomsich 
2799415b9a7SPhilipp Tomsich 	return 0;
2809415b9a7SPhilipp Tomsich }
2819415b9a7SPhilipp Tomsich 
2829415b9a7SPhilipp Tomsich #ifdef CONFIG_SERIAL_TAG
get_board_serial(struct tag_serialnr * serialnr)2839415b9a7SPhilipp Tomsich void get_board_serial(struct tag_serialnr *serialnr)
2849415b9a7SPhilipp Tomsich {
2859415b9a7SPhilipp Tomsich 	char *serial_string;
2869415b9a7SPhilipp Tomsich 	u64 serial = 0;
2879415b9a7SPhilipp Tomsich 
28800caae6dSSimon Glass 	serial_string = env_get("serial#");
2899415b9a7SPhilipp Tomsich 
2909415b9a7SPhilipp Tomsich 	if (serial_string)
2919415b9a7SPhilipp Tomsich 		serial = simple_strtoull(serial_string, NULL, 16);
2929415b9a7SPhilipp Tomsich 
2939415b9a7SPhilipp Tomsich 	serialnr->high = (u32)(serial >> 32);
2949415b9a7SPhilipp Tomsich 	serialnr->low = (u32)(serial & 0xffffffff);
2959415b9a7SPhilipp Tomsich }
2969415b9a7SPhilipp Tomsich #endif
297614539d4SPhilipp Tomsich 
298614539d4SPhilipp Tomsich /**
299614539d4SPhilipp Tomsich  * Switch power at an external regulator (for our root hub).
300614539d4SPhilipp Tomsich  *
301614539d4SPhilipp Tomsich  * @param ctrl pointer to the xHCI controller
302614539d4SPhilipp Tomsich  * @param port port number as in the control message (one-based)
303614539d4SPhilipp Tomsich  * @param enable boolean indicating whether to enable or disable power
304614539d4SPhilipp Tomsich  * @return returns 0 on success, an error-code on failure
305614539d4SPhilipp Tomsich  */
board_usb_port_power_set(struct udevice * dev,int port,bool enable)306614539d4SPhilipp Tomsich static int board_usb_port_power_set(struct udevice *dev, int port,
307614539d4SPhilipp Tomsich 				    bool enable)
308614539d4SPhilipp Tomsich {
309614539d4SPhilipp Tomsich #if CONFIG_IS_ENABLED(OF_CONTROL) && CONFIG_IS_ENABLED(DM_REGULATOR)
310614539d4SPhilipp Tomsich 	/* We start counting ports at 0, while USB counts from 1. */
311614539d4SPhilipp Tomsich 	int index = port - 1;
312614539d4SPhilipp Tomsich 	const char *regname = NULL;
313614539d4SPhilipp Tomsich 	struct udevice *regulator;
314614539d4SPhilipp Tomsich 	const char *prop = "tsd,usb-port-power";
315614539d4SPhilipp Tomsich 	int ret;
316614539d4SPhilipp Tomsich 
317614539d4SPhilipp Tomsich 	debug("%s: ctrl '%s' port %d enable %s\n", __func__,
318614539d4SPhilipp Tomsich 	      dev_read_name(dev), port, enable ? "true" : "false");
319614539d4SPhilipp Tomsich 
320614539d4SPhilipp Tomsich 	ret = dev_read_string_index(dev, prop, index, &regname);
321614539d4SPhilipp Tomsich 	if (ret < 0) {
322614539d4SPhilipp Tomsich 		debug("%s: ctrl '%s' port %d: no entry in '%s'\n",
323614539d4SPhilipp Tomsich 		      __func__, dev_read_name(dev), port, prop);
324614539d4SPhilipp Tomsich 		return ret;
325614539d4SPhilipp Tomsich 	}
326614539d4SPhilipp Tomsich 
327614539d4SPhilipp Tomsich 	ret = regulator_get_by_platname(regname, &regulator);
328614539d4SPhilipp Tomsich 	if (ret) {
329614539d4SPhilipp Tomsich 		debug("%s: ctrl '%s' port %d: could not get regulator '%s'\n",
330614539d4SPhilipp Tomsich 		      __func__, dev_read_name(dev), port, regname);
331614539d4SPhilipp Tomsich 		return ret;
332614539d4SPhilipp Tomsich 	}
333614539d4SPhilipp Tomsich 
334614539d4SPhilipp Tomsich 	regulator_set_enable(regulator, enable);
335614539d4SPhilipp Tomsich 	return 0;
336614539d4SPhilipp Tomsich #else
337614539d4SPhilipp Tomsich 	return -ENOTSUPP;
338614539d4SPhilipp Tomsich #endif
339614539d4SPhilipp Tomsich }
340614539d4SPhilipp Tomsich 
usb_hub_reset_devices(struct usb_hub_device * hub,int port)341614539d4SPhilipp Tomsich void usb_hub_reset_devices(struct usb_hub_device *hub, int port)
342614539d4SPhilipp Tomsich {
343614539d4SPhilipp Tomsich 	struct udevice *dev = hub->pusb_dev->dev;
344614539d4SPhilipp Tomsich 	struct udevice *ctrl;
345614539d4SPhilipp Tomsich 
346614539d4SPhilipp Tomsich 	/* We are only interested in our root-hubs */
347614539d4SPhilipp Tomsich 	if (usb_hub_is_root_hub(dev) == false)
348614539d4SPhilipp Tomsich 		return;
349614539d4SPhilipp Tomsich 
350614539d4SPhilipp Tomsich 	ctrl = usb_get_bus(dev);
351614539d4SPhilipp Tomsich 	if (!ctrl) {
352614539d4SPhilipp Tomsich 		debug("%s: could not retrieve ctrl for hub\n", __func__);
353614539d4SPhilipp Tomsich 		return;
354614539d4SPhilipp Tomsich 	}
355614539d4SPhilipp Tomsich 
356614539d4SPhilipp Tomsich 	/*
357614539d4SPhilipp Tomsich 	 * To work around an incompatibility between the single-threaded
358614539d4SPhilipp Tomsich 	 * USB stack in U-Boot and (a strange low-power mode of) the USB
359614539d4SPhilipp Tomsich 	 * hub we have on-module, we need to delay powering on the hub
360614539d4SPhilipp Tomsich 	 * until the first time the port is probed.
361614539d4SPhilipp Tomsich 	 */
362614539d4SPhilipp Tomsich 	board_usb_port_power_set(ctrl, port, true);
363614539d4SPhilipp Tomsich }
364