Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 3a1a18f | 2015-01-27 22:13:47 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2015, Google, Inc |
Simon Glass | 3a1a18f | 2015-01-27 22:13:47 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Bin Meng | 70b95de | 2017-06-16 06:31:46 -0700 | [diff] [blame] | 7 | #include <dm.h> |
Simon Glass | 691d719 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 8 | #include <init.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 9 | #include <log.h> |
Gabriel Huau | 5d3c2c5 | 2015-05-11 23:18:25 -0700 | [diff] [blame] | 10 | #include <asm/gpio.h> |
Bin Meng | 70b95de | 2017-06-16 06:31:46 -0700 | [diff] [blame] | 11 | #include <dm/device-internal.h> |
| 12 | #include <dm/uclass-internal.h> |
| 13 | |
| 14 | #define GPIO_BANKE_NAME "gpioe" |
Simon Glass | 3a1a18f | 2015-01-27 22:13:47 -0700 | [diff] [blame] | 15 | |
Bin Meng | 70b95de | 2017-06-16 06:31:46 -0700 | [diff] [blame] | 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 | } |