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