@@ -39,7 +39,6 @@ static struct sunxi_ehci_hcd {
39
39
{
40
40
.usb_rst_mask = CCM_USB_CTRL_PHY1_RST ,
41
41
.ahb_clk_mask = 1 << AHB_GATE_OFFSET_USB_EHCI0 ,
42
- .gpio_vbus = CONFIG_SUNXI_USB_VBUS0_GPIO ,
43
42
.csr = (void * )SUNXI_USB_CSR ,
44
43
.irq = 39 ,
45
44
.id = 1 ,
@@ -48,7 +47,6 @@ static struct sunxi_ehci_hcd {
48
47
{
49
48
.usb_rst_mask = CCM_USB_CTRL_PHY2_RST ,
50
49
.ahb_clk_mask = 1 << AHB_GATE_OFFSET_USB_EHCI1 ,
51
- .gpio_vbus = CONFIG_SUNXI_USB_VBUS1_GPIO ,
52
50
.csr = (void * )SUNXI_USB_CSR ,
53
51
.irq = 40 ,
54
52
.id = 2 ,
@@ -68,6 +66,15 @@ static void *get_io_base(int hcd_id)
68
66
return NULL ;
69
67
}
70
68
69
+ static int get_vbus_gpio (int hcd_id )
70
+ {
71
+ switch (hcd_id ) {
72
+ case 1 : return sunxi_name_to_gpio (CONFIG_USB1_VBUS_PIN );
73
+ case 2 : return sunxi_name_to_gpio (CONFIG_USB2_VBUS_PIN );
74
+ }
75
+ return -1 ;
76
+ }
77
+
71
78
static void usb_phy_write (struct sunxi_ehci_hcd * sunxi_ehci , int addr ,
72
79
int data , int len )
73
80
{
@@ -143,14 +150,16 @@ static void sunxi_ehci_enable(struct sunxi_ehci_hcd *sunxi_ehci)
143
150
144
151
sunxi_usb_passby (sunxi_ehci , SUNXI_USB_PASSBY_EN );
145
152
146
- gpio_direction_output (sunxi_ehci -> gpio_vbus , 1 );
153
+ if (sunxi_ehci -> gpio_vbus != -1 )
154
+ gpio_direction_output (sunxi_ehci -> gpio_vbus , 1 );
147
155
}
148
156
149
157
static void sunxi_ehci_disable (struct sunxi_ehci_hcd * sunxi_ehci )
150
158
{
151
159
struct sunxi_ccm_reg * ccm = (struct sunxi_ccm_reg * )SUNXI_CCM_BASE ;
152
160
153
- gpio_direction_output (sunxi_ehci -> gpio_vbus , 0 );
161
+ if (sunxi_ehci -> gpio_vbus != -1 )
162
+ gpio_direction_output (sunxi_ehci -> gpio_vbus , 0 );
154
163
155
164
sunxi_usb_passby (sunxi_ehci , !SUNXI_USB_PASSBY_EN );
156
165
@@ -165,13 +174,17 @@ int ehci_hcd_init(int index, enum usb_init_type init, struct ehci_hccr **hccr,
165
174
struct sunxi_ehci_hcd * sunxi_ehci = & sunxi_echi_hcd [index ];
166
175
int err ;
167
176
177
+ sunxi_ehci -> gpio_vbus = get_vbus_gpio (sunxi_ehci -> id );
178
+
168
179
/* enable common PHY only once */
169
180
if (index == 0 )
170
181
setbits_le32 (& ccm -> usb_clk_cfg , CCM_USB_CTRL_PHYGATE );
171
182
172
- err = gpio_request (sunxi_ehci -> gpio_vbus , "ehci_vbus" );
173
- if (err )
174
- return err ;
183
+ if (sunxi_ehci -> gpio_vbus != -1 ) {
184
+ err = gpio_request (sunxi_ehci -> gpio_vbus , "ehci_vbus" );
185
+ if (err )
186
+ return err ;
187
+ }
175
188
176
189
sunxi_ehci_enable (sunxi_ehci );
177
190
@@ -197,9 +210,11 @@ int ehci_hcd_stop(int index)
197
210
198
211
sunxi_ehci_disable (sunxi_ehci );
199
212
200
- err = gpio_free (sunxi_ehci -> gpio_vbus );
201
- if (err )
202
- return err ;
213
+ if (sunxi_ehci -> gpio_vbus != -1 ) {
214
+ err = gpio_free (sunxi_ehci -> gpio_vbus );
215
+ if (err )
216
+ return err ;
217
+ }
203
218
204
219
/* disable common PHY only once, for the last enabled hcd */
205
220
if (enabled_hcd_count == 1 )
0 commit comments