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