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