Skip to content

Commit 115200c

Browse files
committed
sunxi: ehci: Add proper Kconfig options to select the usb Vbus gpio-s
Add proper Kconfig options to select the usb Vbus gpio-s, besides moving to Kconfig being the right thing to do, an added advantage of this is that it allows for boards without Vbus gpio-s. Signed-off-by: Hans de Goede <[email protected]> Acked-by: Ian Campbell <[email protected]>
1 parent 505ecee commit 115200c

10 files changed

+51
-30
lines changed

board/sunxi/Kconfig

+14
Original file line numberDiff line numberDiff line change
@@ -197,4 +197,18 @@ config MMC_SUNXI_SLOT_EXTRA
197197
slot or emmc on mmc1 - mmc3. Setting this to 1, 2 or 3 will enable
198198
support for this.
199199

200+
config USB1_VBUS_PIN
201+
string "Vbus enable pin for usb1 (ehci0)"
202+
default "PH6" if MACH_SUN4I || MACH_SUN7I
203+
---help---
204+
Set the Vbus enable pin for usb1 (ehci0, usb0 is the otg). This takes
205+
a string in the format understood by sunxi_name_to_gpio, e.g.
206+
PH1 for pin 1 of port H.
207+
208+
config USB2_VBUS_PIN
209+
string "Vbus enable pin for usb2 (ehci1)"
210+
default "PH3" if MACH_SUN4I || MACH_SUN7I
211+
---help---
212+
See USB1_VBUS_PIN help text.
213+
200214
endif

configs/A10s-OLinuXino-M_defconfig

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
CONFIG_SPL=y
2-
CONFIG_SYS_EXTRA_OPTIONS="AXP152_POWER,SUNXI_EMAC,USB_EHCI,SUNXI_USB_VBUS0_GPIO=SUNXI_GPB(10)"
2+
CONFIG_SYS_EXTRA_OPTIONS="AXP152_POWER,SUNXI_EMAC,USB_EHCI"
33
CONFIG_FDTFILE="sun5i-a10s-olinuxino-micro.dtb"
44
CONFIG_MMC_SUNXI_SLOT_EXTRA=1
5+
CONFIG_USB1_VBUS_PIN="PB10"
56
+S:CONFIG_MMC0_CD_PIN="PG1"
67
+S:CONFIG_MMC1_CD_PIN="PG13"
78
+S:CONFIG_ARM=y

configs/A13-OLinuXinoM_defconfig

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
CONFIG_SPL=y
2-
CONFIG_SYS_EXTRA_OPTIONS="CONS_INDEX=2,USB_EHCI,SUNXI_USB_VBUS0_GPIO=SUNXI_GPG(11)"
2+
CONFIG_SYS_EXTRA_OPTIONS="CONS_INDEX=2,USB_EHCI"
33
CONFIG_FDTFILE="sun5i-a13-olinuxino-micro.dtb"
4+
CONFIG_USB1_VBUS_PIN="PG11"
45
+S:CONFIG_ARM=y
56
+S:CONFIG_ARCH_SUNXI=y
67
+S:CONFIG_MACH_SUN5I=y

configs/A13-OLinuXino_defconfig

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
CONFIG_SPL=y
2-
CONFIG_SYS_EXTRA_OPTIONS="CONS_INDEX=2,AXP209_POWER,USB_EHCI,SUNXI_USB_VBUS0_GPIO=SUNXI_GPG(11)"
2+
CONFIG_SYS_EXTRA_OPTIONS="CONS_INDEX=2,AXP209_POWER,USB_EHCI"
33
CONFIG_FDTFILE="sun5i-a13-olinuxino.dtb"
4+
CONFIG_USB1_VBUS_PIN="PG11"
45
+S:CONFIG_ARM=y
56
+S:CONFIG_ARCH_SUNXI=y
67
+S:CONFIG_MACH_SUN5I=y

configs/Auxtek-T004_defconfig

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
CONFIG_SPL=y
2-
CONFIG_SYS_EXTRA_OPTIONS="AXP152_POWER,USB_EHCI,SUNXI_USB_VBUS0_GPIO=SUNXI_GPG(13)"
2+
CONFIG_SYS_EXTRA_OPTIONS="AXP152_POWER,USB_EHCI"
33
CONFIG_FDTFILE="sun5i-a10s-auxtek-t004.dtb"
4+
CONFIG_USB1_VBUS_PIN="PG13"
45
+S:CONFIG_ARM=y
56
+S:CONFIG_ARCH_SUNXI=y
67
+S:CONFIG_MACH_SUN5I=y

configs/ba10_tv_box_defconfig

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
CONFIG_SPL=y
2-
CONFIG_SYS_EXTRA_OPTIONS="AXP209_POWER,SUNXI_EMAC,USB_EHCI,SUNXI_USB_VBUS1_GPIO=SUNXI_GPH(12)"
2+
CONFIG_SYS_EXTRA_OPTIONS="AXP209_POWER,SUNXI_EMAC,USB_EHCI"
33
CONFIG_FDTFILE="sun4i-a10-ba10-tvbox.dtb"
4+
CONFIG_USB1_VBUS_PIN="PH12"
45
+S:CONFIG_ARM=y
56
+S:CONFIG_ARCH_SUNXI=y
67
+S:CONFIG_MACH_SUN4I=y

configs/r7-tv-dongle_defconfig

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
CONFIG_SPL=y
2-
CONFIG_SYS_EXTRA_OPTIONS="AXP152_POWER,USB_EHCI,SUNXI_USB_VBUS0_GPIO=SUNXI_GPG(13)"
2+
CONFIG_SYS_EXTRA_OPTIONS="AXP152_POWER,USB_EHCI"
33
CONFIG_FDTFILE="sun5i-a10s-r7-tv-dongle.dtb"
4+
CONFIG_USB1_VBUS_PIN="PG13"
45
+S:CONFIG_ARM=y
56
+S:CONFIG_ARCH_SUNXI=y
67
+S:CONFIG_MACH_SUN5I=y

drivers/usb/host/ehci-sunxi.c

+25-10
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ static struct sunxi_ehci_hcd {
3939
{
4040
.usb_rst_mask = CCM_USB_CTRL_PHY1_RST,
4141
.ahb_clk_mask = 1 << AHB_GATE_OFFSET_USB_EHCI0,
42-
.gpio_vbus = CONFIG_SUNXI_USB_VBUS0_GPIO,
4342
.csr = (void *)SUNXI_USB_CSR,
4443
.irq = 39,
4544
.id = 1,
@@ -48,7 +47,6 @@ static struct sunxi_ehci_hcd {
4847
{
4948
.usb_rst_mask = CCM_USB_CTRL_PHY2_RST,
5049
.ahb_clk_mask = 1 << AHB_GATE_OFFSET_USB_EHCI1,
51-
.gpio_vbus = CONFIG_SUNXI_USB_VBUS1_GPIO,
5250
.csr = (void *)SUNXI_USB_CSR,
5351
.irq = 40,
5452
.id = 2,
@@ -68,6 +66,15 @@ static void *get_io_base(int hcd_id)
6866
return NULL;
6967
}
7068

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+
7178
static void usb_phy_write(struct sunxi_ehci_hcd *sunxi_ehci, int addr,
7279
int data, int len)
7380
{
@@ -143,14 +150,16 @@ static void sunxi_ehci_enable(struct sunxi_ehci_hcd *sunxi_ehci)
143150

144151
sunxi_usb_passby(sunxi_ehci, SUNXI_USB_PASSBY_EN);
145152

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);
147155
}
148156

149157
static void sunxi_ehci_disable(struct sunxi_ehci_hcd *sunxi_ehci)
150158
{
151159
struct sunxi_ccm_reg *ccm = (struct sunxi_ccm_reg *)SUNXI_CCM_BASE;
152160

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);
154163

155164
sunxi_usb_passby(sunxi_ehci, !SUNXI_USB_PASSBY_EN);
156165

@@ -165,13 +174,17 @@ int ehci_hcd_init(int index, enum usb_init_type init, struct ehci_hccr **hccr,
165174
struct sunxi_ehci_hcd *sunxi_ehci = &sunxi_echi_hcd[index];
166175
int err;
167176

177+
sunxi_ehci->gpio_vbus = get_vbus_gpio(sunxi_ehci->id);
178+
168179
/* enable common PHY only once */
169180
if (index == 0)
170181
setbits_le32(&ccm->usb_clk_cfg, CCM_USB_CTRL_PHYGATE);
171182

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+
}
175188

176189
sunxi_ehci_enable(sunxi_ehci);
177190

@@ -197,9 +210,11 @@ int ehci_hcd_stop(int index)
197210

198211
sunxi_ehci_disable(sunxi_ehci);
199212

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+
}
203218

204219
/* disable common PHY only once, for the last enabled hcd */
205220
if (enabled_hcd_count == 1)

include/configs/sun4i.h

-7
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,7 @@
1818

1919
#ifdef CONFIG_USB_EHCI
2020
#define CONFIG_USB_EHCI_SUNXI
21-
2221
#define CONFIG_USB_MAX_CONTROLLER_COUNT 2
23-
#ifndef CONFIG_SUNXI_USB_VBUS0_GPIO
24-
#define CONFIG_SUNXI_USB_VBUS0_GPIO SUNXI_GPH(6)
25-
#endif
26-
#ifndef CONFIG_SUNXI_USB_VBUS1_GPIO
27-
#define CONFIG_SUNXI_USB_VBUS1_GPIO SUNXI_GPH(3)
28-
#endif
2922
#endif
3023

3124
/*

include/configs/sun7i.h

-7
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,7 @@
1919

2020
#ifdef CONFIG_USB_EHCI
2121
#define CONFIG_USB_EHCI_SUNXI
22-
2322
#define CONFIG_USB_MAX_CONTROLLER_COUNT 2
24-
#ifndef CONFIG_SUNXI_USB_VBUS0_GPIO
25-
#define CONFIG_SUNXI_USB_VBUS0_GPIO SUNXI_GPH(6)
26-
#endif
27-
#ifndef CONFIG_SUNXI_USB_VBUS1_GPIO
28-
#define CONFIG_SUNXI_USB_VBUS1_GPIO SUNXI_GPH(3)
29-
#endif
3023
#endif
3124

3225
#define CONFIG_ARMV7_VIRT 1

0 commit comments

Comments
 (0)