1 /*
2  * Copyright (C) 2015, Google, Inc
3  *
4  * SPDX-License-Identifier:	GPL-2.0+
5  */
6 
7 #include <common.h>
8 #include <dm.h>
9 #include <asm/gpio.h>
10 #include <dm/device-internal.h>
11 #include <dm/uclass-internal.h>
12 
13 #define GPIO_BANKE_NAME		"gpioe"
14 
15 int misc_init_r(void)
16 {
17 	struct udevice *dev;
18 	struct gpio_desc desc;
19 	int ret;
20 
21 	/*
22 	 * Turn on USB VBUS for the two USB ports on the board.
23 	 * Each port's VBUS is controlled by a GPIO pin.
24 	 */
25 
26 	ret = uclass_find_device_by_name(UCLASS_GPIO, GPIO_BANKE_NAME, &dev);
27 	if (ret) {
28 		debug("%s: GPIO %s device cannot be not found (ret=%d)\n",
29 		      __func__, GPIO_BANKE_NAME, ret);
30 		return ret;
31 	}
32 
33 	ret = device_probe(dev);
34 	if (ret) {
35 		debug("%s: GPIO %s device probe failed (ret=%d)\n",
36 		      __func__, GPIO_BANKE_NAME, ret);
37 		return ret;
38 	}
39 
40 	desc.dev = dev;
41 	desc.flags = GPIOD_IS_OUT;
42 
43 	/* GPIO E8 controls the bottom port */
44 	desc.offset = 8;
45 
46 	ret = dm_gpio_request(&desc, "usb_host_en0");
47 	if (ret)
48 		return ret;
49 	dm_gpio_set_value(&desc, 1);
50 
51 	/* GPIO E9 controls the upper port */
52 	desc.offset = 9;
53 
54 	ret = dm_gpio_request(&desc, "usb_host_en1");
55 	if (ret)
56 		return ret;
57 
58 	dm_gpio_set_value(&desc, 1);
59 
60 	return 0;
61 }
62