blob: a033b2affad25bb34b786c1db975c9a9d922ebae (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
/*
* board/hardkernel/odroid-common/usb.c
*
* (C) Copyright 2019 Hardkernel Co., Ltd
*
* SPDX-License-Identifier: GPL-2.0+
*/
#include <common.h>
#include <errno.h>
#include <asm/arch/secure_apb.h>
#include <asm-generic/gpio.h>
#include <asm/arch/gpio.h>
#include <odroid-common.h>
static bool usbhost_init = 0;
static int __usbhost_early_power = 0;
int board_usbhost_early_power(void)
{
return __usbhost_early_power;
}
int usbhost_early_poweron(void)
{
__usbhost_early_power = 1;
run_command("usb start", 0);
/* TODO: do something here */
run_command("usb stop", 0);
__usbhost_early_power = 0;
return 0;
}
static bool usbhost_requested(void)
{
return usbhost_init;
}
static int usbhost_gpio_request(void)
{
int ret;
/* Already GPIO for USB Host power is allocated */
if (usbhost_requested())
return 0;
/* usb host hub reset */
ret = gpio_request(CONFIG_USB_HUB_RST_N, CONFIG_USB_HUB_RST_N_NAME);
if (ret && ret != -EBUSY) {
debug("gpio: requesting pin %u failed\n", CONFIG_USB_HUB_RST_N);
return ret;
}
#if defined(CONFIG_ODROID_N2)
/* usb host hub chip enable */
ret = gpio_request(CONFIG_USB_HUB_CHIP_EN, CONFIG_USB_HUB_CHIP_EN_NAME);
if (ret && ret != -EBUSY) {
debug("gpio: requesting pin %u failed\n", CONFIG_USB_HUB_CHIP_EN);
gpio_free(CONFIG_USB_HUB_RST_N);
return ret;
}
#endif
usbhost_init = true;
return 0;
}
static int usbhost_gpio_free(void)
{
#if defined(CONFIG_ODROID_N2)
gpio_free(CONFIG_USB_HUB_CHIP_EN);
#endif
gpio_free(CONFIG_USB_HUB_RST_N);
return 0;
}
int usbhost_set_power(int on)
{
if (on) {
if (usbhost_gpio_request() == 0) {
#if defined(CONFIG_ODROID_N2)
gpio_direction_output(CONFIG_USB_HUB_CHIP_EN, 1);
udelay(100);
#endif
gpio_direction_output(CONFIG_USB_HUB_RST_N, 1);
}
} else {
if (usbhost_requested()) {
gpio_direction_output(CONFIG_USB_HUB_RST_N, 0);
#if defined(CONFIG_ODROID_N2)
gpio_direction_output(CONFIG_USB_HUB_CHIP_EN, 0);
#endif
}
usbhost_gpio_free();
}
return 0;
}
|