blob: b02e3f0d4e5c43144255bb412915d879e92b49b1 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glass3a1a18f2015-01-27 22:13:47 -07002/*
3 * Copyright (C) 2015, Google, Inc
Simon Glass3a1a18f2015-01-27 22:13:47 -07004 */
5
6#include <common.h>
Bin Meng70b95de2017-06-16 06:31:46 -07007#include <dm.h>
Simon Glass691d7192020-05-10 11:40:02 -06008#include <init.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -06009#include <log.h>
Gabriel Huau5d3c2c52015-05-11 23:18:25 -070010#include <asm/gpio.h>
Bin Meng70b95de2017-06-16 06:31:46 -070011#include <dm/device-internal.h>
12#include <dm/uclass-internal.h>
13
14#define GPIO_BANKE_NAME "gpioe"
Simon Glass3a1a18f2015-01-27 22:13:47 -070015
Bin Meng70b95de2017-06-16 06:31:46 -070016int 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}