blob: 5bdb2fdbc7cb4282f9720860fb6bf51776ce26c0 [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
Bin Meng74649a92017-06-16 06:31:46 -070015int 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
Gabriel Huauf70353a2015-05-11 23:18:25 -070060 return 0;
61}