Simon Glass | 4a56f10 | 2015-01-27 22:13:47 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015, Google, Inc |
| 3 | * |
| 4 | * SPDX-License-Identifier: GPL-2.0+ |
| 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Bin Meng | 74649a9 | 2017-06-16 06:31:46 -0700 | [diff] [blame] | 8 | #include <dm.h> |
Gabriel Huau | f70353a | 2015-05-11 23:18:25 -0700 | [diff] [blame] | 9 | #include <asm/gpio.h> |
Bin Meng | 74649a9 | 2017-06-16 06:31:46 -0700 | [diff] [blame] | 10 | #include <dm/device-internal.h> |
| 11 | #include <dm/uclass-internal.h> |
| 12 | |
| 13 | #define GPIO_BANKE_NAME "gpioe" |
Simon Glass | 4a56f10 | 2015-01-27 22:13:47 -0700 | [diff] [blame] | 14 | |
Gabriel Huau | f70353a | 2015-05-11 23:18:25 -0700 | [diff] [blame] | 15 | int arch_early_init_r(void) |
| 16 | { |
Bin Meng | 74649a9 | 2017-06-16 06:31:46 -0700 | [diff] [blame] | 17 | return 0; |
| 18 | } |
| 19 | |
| 20 | int 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 Huau | f70353a | 2015-05-11 23:18:25 -0700 | [diff] [blame] | 65 | return 0; |
| 66 | } |