Skip to contentSkip to conversation

sunxi: H6: Enable USB (2.0) support

PATCH New Andre Przywara 3 participants 9 messages Jun 23, 2019 – Jul 16, 2019

Subsystems (7)
lore
Share & tools
lore
#0 lore raw

v2 cover sunxi: H6: Enable USB (2.0) support

Hi,

a minor update to v1, adding PortM support as per Icenowy's comment and dropping the DT change. We still need the latter for support the USB0 port on some boards, but this takes another route now (syncing back from Linux).
---------------

This series enables USB support on the H6 boards. This is mostly just adding some missing pieces here and there, the actual controller and PHY are very similar to the previous ones, if not identical. This is for the 2.0 ports only at the moment, USB 3.0 requires some more work to make U-Boot's driver compliant to the kernel's DT bindings.

The Pine H64 shares a similar problem as the Pine64+ boards regarding the upper USB port. To enable this port, we need a patch from Paul [1] and changes to the DT [2]. But this is orthogonal to this series.

Patch 1 is a drive-by patch to bring SUNXI_GPIO to Kconfig, as this was lingering in one of my branches for a while.
Patch 2 enables GPIO support for the H6, as this is needed for the Pine H64 to enable the VBUS regulator.
Patch 3 adds the clock and reset gates mappings for the USB controller and the PHY, the values are taken from the manual and verified against Linux.
Patch 4 adds some code to the PHY driver to skip over not implemented PHYs, as the H6 uses a PHY0/PHY3 combination in the DT.
Patch 5 then eventually enables USB in the existing defconfigs.

Cheers,
Andre.

[1] https://lists.denx.de/pipermail/u-boot/2019-March/361828.html
[2] http://lists.infradead.org/pipermail/linux-arm-kernel/2019-June/661580.html

Andre Przywara (5):
sunxi: move SUNXI_GPIO to Kconfig
sunxi: gpio: Enable support for H6 pin controller
sunxi: clocks: Add H6 USB clock gates and resets
sunxi: phy: Add USB PHY support for Allwinner H6
sunxi: H6: Enable USB for existing boards

 arch/arm/Kconfig                      |  1 +
 arch/arm/mach-sunxi/Kconfig           |  1 +
 configs/beelink_gs1_defconfig         |  2 ++
 configs/orangepi_lite2_defconfig      |  2 ++
 configs/orangepi_one_plus_defconfig   |  2 ++
 configs/pine_h64_defconfig            |  3 +++
 drivers/clk/sunxi/clk_h6.c            | 29 +++++++++++++++++++++++++++++
 drivers/gpio/Kconfig                  |  6 ++++++
 drivers/gpio/sunxi_gpio.c             |  2 ++
 drivers/phy/allwinner/phy-sun4i-usb.c | 20 ++++++++++++++++++++
 include/configs/sunxi-common.h        |  3 ---
 scripts/config_whitelist.txt          |  1 -
 12 files changed, 68 insertions(+), 4 deletions(-)
Signature · 1 line
2.14.5
#1 lore raw

PATCH v2 1/5 sunxi: move SUNXI_GPIO to Kconfig

Probably for no particular reason SUNXI_GPIO was still defined the "old way", in header files only.

Introduce SUNXI_GPIO to the Kconfig file in drivers/gpio to remove another line from our dreadful config_whitelist.txt.

---
 arch/arm/Kconfig               | 1 +
 drivers/gpio/Kconfig           | 6 ++++++
 include/configs/sunxi-common.h | 3 ---
 scripts/config_whitelist.txt   | 1 -
 4 files changed, 7 insertions(+), 4 deletions(-)
arch/arm/Kconfig +1 -0
index 01ff57cf1b..97504e1218 100644
@@ -926,6 +926,7 @@ config ARCH_SUNXI
 	select SPL_STACK_R if SPL
 	select SPL_SYS_MALLOC_SIMPLE if SPL
 	select SPL_SYS_THUMB_BUILD if !ARM64
+	select SUNXI_GPIO
 	select SYS_NS16550
 	select SYS_THUMB_BUILD if !ARM64
 	select USB if DISTRO_DEFAULTS
drivers/gpio/Kconfig +6 -0
index e36a8abc42..5a4d7c553e 100644
@@ -205,6 +205,12 @@ config SANDBOX_GPIO_COUNT
 	  of 'anonymous' GPIOs that do not belong to any device or bank.
 	  Select a suitable value depending on your needs.
 
+config SUNXI_GPIO
+	bool "Allwinner GPIO driver"
+	depends on ARCH_SUNXI
+	help
+	  Support the GPIO device in Allwinner SoCs.
+
 config XILINX_GPIO
 	bool "Xilinx GPIO driver"
 	depends on DM_GPIO
include/configs/sunxi-common.h +0 -3
index fceb812448..7be94ee7d1 100644
@@ -257,9 +257,6 @@ extern int soft_i2c_gpio_scl;
 #endif
 #endif /* ifdef CONFIG_REQUIRE_SERIAL_CONSOLE */
 
-/* GPIO */
-#define CONFIG_SUNXI_GPIO
-
 #ifdef CONFIG_VIDEO_SUNXI
 /*
  * The amount of RAM to keep free at the top of RAM when relocating u-boot,
scripts/config_whitelist.txt +0 -1
index 22de7a4b6c..b5799cbef6 100644
@@ -1863,7 +1863,6 @@ CONFIG_STV0991
 CONFIG_STV0991_HZ
 CONFIG_STV0991_HZ_CLOCK
 CONFIG_ST_SMI
-CONFIG_SUNXI_GPIO
 CONFIG_SUNXI_MAX_FB_SIZE
 CONFIG_SUVD3
 CONFIG_SXNI855T
Signature · 1 line
2.14.5
#2 lore raw

PATCH v2 2/5 sunxi: gpio: Enable support for H6 pin controller

In reply to Andre Przywara

The Allwinner H6 pin controller is not really special, at least not when it comes to normal GPIO operation.

Add the H6 compatible strings to the list of recognised strings, to make GPIOs work for H6 boards.

---
 drivers/gpio/sunxi_gpio.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpio/sunxi_gpio.c +2 -0
index cbed8d42b7..719efc2cef 100644
@@ -354,12 +354,14 @@ static const struct udevice_id sunxi_gpio_ids[] = {
 	ID("allwinner,sun8i-v3s-pinctrl",	a_all),
 	ID("allwinner,sun9i-a80-pinctrl",	a_all),
 	ID("allwinner,sun50i-a64-pinctrl",	a_all),
+	ID("allwinner,sun50i-h6-pinctrl",	a_all),
 	ID("allwinner,sun6i-a31-r-pinctrl",	l_2),
 	ID("allwinner,sun8i-a23-r-pinctrl",	l_1),
 	ID("allwinner,sun8i-a83t-r-pinctrl",	l_1),
 	ID("allwinner,sun8i-h3-r-pinctrl",	l_1),
 	ID("allwinner,sun9i-a80-r-pinctrl",	l_3),
 	ID("allwinner,sun50i-a64-r-pinctrl",	l_1),
+	ID("allwinner,sun50i-h6-r-pinctrl",	l_2),
 	{ }
 };
 
Signature · 1 line
2.14.5
#3 lore raw

PATCH v2 3/5 sunxi: clocks: Add H6 USB clock gates and resets

In reply to Andre Przywara

To enable USB support in U-Boot, add the required clock and reset gates to the H6 clock driver. Once enabled, the generic EHCI/OCHI drivers will pick them up from there automatically.

---
 drivers/clk/sunxi/clk_h6.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
drivers/clk/sunxi/clk_h6.c +29 -0
index 0bb00f449a..105c15d869 100644
@@ -28,6 +28,22 @@ static struct ccu_clk_gate h6_gates[] = {
 	[CLK_BUS_SPI1]		= GATE(0x96c, BIT(1)),
 
 	[CLK_BUS_EMAC]		= GATE(0x97c, BIT(0)),
+
+	[CLK_USB_PHY0]		= GATE(0xa70, BIT(29)),
+	[CLK_USB_OHCI0]		= GATE(0xa70, BIT(31)),
+
+	[CLK_USB_PHY1]		= GATE(0xa74, BIT(29)),
+
+	[CLK_USB_HSIC]		= GATE(0xa7c, BIT(26)),
+	[CLK_USB_HSIC_12M]	= GATE(0xa7c, BIT(27)),
+	[CLK_USB_PHY3]		= GATE(0xa7c, BIT(29)),
+	[CLK_USB_OHCI3]		= GATE(0xa7c, BIT(31)),
+
+	[CLK_BUS_OHCI0]		= GATE(0xa8c, BIT(0)),
+	[CLK_BUS_OHCI3]		= GATE(0xa8c, BIT(3)),
+	[CLK_BUS_EHCI0]		= GATE(0xa8c, BIT(4)),
+	[CLK_BUS_EHCI3]		= GATE(0xa8c, BIT(7)),
+	[CLK_BUS_OTG]		= GATE(0xa8c, BIT(8)),
 };
 
 static struct ccu_reset h6_resets[] = {
@@ -43,6 +59,19 @@ static struct ccu_reset h6_resets[] = {
 	[RST_BUS_SPI1]		= RESET(0x96c, BIT(17)),
 
 	[RST_BUS_EMAC]		= RESET(0x97c, BIT(16)),
+
+	[RST_USB_PHY0]		= RESET(0xa70, BIT(30)),
+
+	[RST_USB_PHY1]		= RESET(0xa74, BIT(30)),
+
+	[RST_USB_HSIC]		= RESET(0xa7c, BIT(28)),
+	[RST_USB_PHY3]		= RESET(0xa7c, BIT(30)),
+
+	[RST_BUS_OHCI0]		= RESET(0xa8c, BIT(16)),
+	[RST_BUS_OHCI3]		= RESET(0xa8c, BIT(19)),
+	[RST_BUS_EHCI0]		= RESET(0xa8c, BIT(20)),
+	[RST_BUS_EHCI3]		= RESET(0xa8c, BIT(23)),
+	[RST_BUS_OTG]		= RESET(0xa8c, BIT(24)),
 };
 
 static const struct ccu_desc h6_ccu_desc = {
Signature · 1 line
2.14.5
#4 lore raw

PATCH v2 4/5 sunxi: phy: Add USB PHY support for Allwinner H6

In reply to Andre Przywara

The USB PHY used in the Allwinner H6 SoC has some pecularities (as usual), which require a small addition to the USB PHY driver:
In this case the second PHY is PHY3, not PHY1, so we need to skip number 1 and 2 in the code. Just use the respective code from Linux for that.

---
 drivers/phy/allwinner/phy-sun4i-usb.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
drivers/phy/allwinner/phy-sun4i-usb.c +20 -0
index f206fa3f5d..5e8f87717f 100644
@@ -75,6 +75,7 @@ enum sun4i_usb_phy_type {
 	sun8i_h3_phy,
 	sun8i_v3s_phy,
 	sun50i_a64_phy,
+	sun50i_h6_phy,
 };
 
 struct sun4i_usb_phy_cfg {
@@ -85,6 +86,7 @@ struct sun4i_usb_phy_cfg {
 	bool dedicated_clocks;
 	bool enable_pmu_unk1;
 	bool phy0_dual_route;
+	int missing_phys;
 };
 
 struct sun4i_usb_phy_info {
@@ -349,6 +351,9 @@ static int sun4i_usb_phy_xlate(struct phy *phy,
 	if (args->args_count >= data->cfg->num_phys)
 		return -EINVAL;
 
+	if (data->cfg->missing_phys & BIT(args->args[0]))
+		return -ENODEV;
+
 	if (args->args_count)
 		phy->id = args->args[0];
 	else
@@ -429,6 +434,9 @@ static int sun4i_usb_phy_probe(struct udevice *dev)
 		struct sun4i_usb_phy_info *info = &phy_info[i];
 		char name[16];
 
+		if (data->cfg->missing_phys & BIT(i))
+			continue;
+
 		phy->gpio_vbus = sunxi_name_to_gpio(info->gpio_vbus);
 		if (phy->gpio_vbus >= 0) {
 			ret = gpio_request(phy->gpio_vbus, "usb_vbus");
@@ -583,6 +591,17 @@ static const struct sun4i_usb_phy_cfg sun50i_a64_cfg = {
 	.phy0_dual_route = true,
 };
 
+static const struct sun4i_usb_phy_cfg sun50i_h6_cfg = {
+	.num_phys = 4,
+	.type = sun50i_h6_phy,
+	.disc_thresh = 3,
+	.phyctl_offset = REG_PHYCTL_A33,
+	.dedicated_clocks = true,
+	.enable_pmu_unk1 = true,
+	.phy0_dual_route = true,
+	.missing_phys = BIT(1) | BIT(2),
+};
+
 static const struct udevice_id sun4i_usb_phy_ids[] = {
 	{ .compatible = "allwinner,sun4i-a10-usb-phy", .data = (ulong)&sun4i_a10_cfg },
 	{ .compatible = "allwinner,sun5i-a13-usb-phy", .data = (ulong)&sun5i_a13_cfg },
@@ -594,6 +613,7 @@ static const struct udevice_id sun4i_usb_phy_ids[] = {
 	{ .compatible = "allwinner,sun8i-h3-usb-phy", .data = (ulong)&sun8i_h3_cfg },
 	{ .compatible = "allwinner,sun8i-v3s-usb-phy", .data = (ulong)&sun8i_v3s_cfg },
 	{ .compatible = "allwinner,sun50i-a64-usb-phy", .data = (ulong)&sun50i_a64_cfg},
+	{ .compatible = "allwinner,sun50i-h6-usb-phy", .data = (ulong)&sun50i_h6_cfg},
 	{ }
 };
 
Signature · 1 line
2.14.5
#5 lore raw

PATCH v2 5/5 sunxi: H6: Enable USB for existing boards

In reply to Andre Przywara

So far USB was not enabled for the Allwinner H6 boards, as the PHY driver was not ready and the clock gates were missing. Since this is now fixed, let's add the PHY and the OHCI/EHCI drivers to the build, for all existing H6 boards.

---
 arch/arm/mach-sunxi/Kconfig         | 1 +
 configs/beelink_gs1_defconfig       | 2 ++
 configs/orangepi_lite2_defconfig    | 2 ++
 configs/orangepi_one_plus_defconfig | 2 ++
 configs/pine_h64_defconfig          | 3 +++
 5 files changed, 10 insertions(+)
arch/arm/mach-sunxi/Kconfig +1 -0
index 1669e62a6d..ad29139545 100644
@@ -300,6 +300,7 @@ config MACH_SUN50I_H6
 	select ARM64
 	select SUPPORT_SPL
 	select FIT
+	select PHY_SUN4I_USB
 	select SPL_LOAD_FIT
 	select DRAM_SUN50I_H6
 
configs/beelink_gs1_defconfig +2 -0
index f16d0fee22..8458f6b32f 100644
@@ -14,3 +14,5 @@ CONFIG_SPL_TEXT_BASE=0x20060
 CONFIG_DEFAULT_DEVICE_TREE="sun50i-h6-beelink-gs1"
 CONFIG_LED=y
 CONFIG_LED_GPIO=y
+CONFIG_USB_EHCI_HCD=y
+CONFIG_USB_OHCI_HCD=y
configs/orangepi_lite2_defconfig +2 -0
index e5c2846eaa..227e1ac873 100644
@@ -11,3 +11,5 @@ CONFIG_SPL_TEXT_BASE=0x20060
 # CONFIG_SPL_DOS_PARTITION is not set
 # CONFIG_SPL_EFI_PARTITION is not set
 CONFIG_DEFAULT_DEVICE_TREE="sun50i-h6-orangepi-lite2"
+CONFIG_USB_EHCI_HCD=y
+CONFIG_USB_OHCI_HCD=y
configs/orangepi_one_plus_defconfig +2 -0
index 65537c422f..2e45909e3a 100644
@@ -11,3 +11,5 @@ CONFIG_SPL_TEXT_BASE=0x20060
 # CONFIG_SPL_DOS_PARTITION is not set
 # CONFIG_SPL_EFI_PARTITION is not set
 CONFIG_DEFAULT_DEVICE_TREE="sun50i-h6-orangepi-one-plus"
+CONFIG_USB_EHCI_HCD=y
+CONFIG_USB_OHCI_HCD=y
configs/pine_h64_defconfig +3 -0
index 5ac89b462c..0c5e47bbf7 100644
@@ -12,3 +12,6 @@ CONFIG_SPL_TEXT_BASE=0x20060
 # CONFIG_SPL_DOS_PARTITION is not set
 # CONFIG_SPL_EFI_PARTITION is not set
 CONFIG_DEFAULT_DEVICE_TREE="sun50i-h6-pine-h64"
+CONFIG_USB_EHCI_HCD=y
+CONFIG_USB_OHCI_HCD=y
+CONFIG_USB3_VBUS_PIN="PL5"
Signature · 1 line
2.14.5
#6 lore raw

v2 cover sunxi: H6: Enable USB (2.0) support

In reply to Andre Przywara
Quoted 29 lines · Andre Przywara

Hi,

a minor update to v1, adding PortM support as per Icenowy's comment and dropping the DT change. We still need the latter for support the USB0 port on some boards, but this takes another route now (syncing back from Linux).
---------------

This series enables USB support on the H6 boards. This is mostly just adding some missing pieces here and there, the actual controller and PHY are very similar to the previous ones, if not identical. This is for the 2.0 ports only at the moment, USB 3.0 requires some more work to make U-Boot's driver compliant to the kernel's DT bindings.

The Pine H64 shares a similar problem as the Pine64+ boards regarding the upper USB port. To enable this port, we need a patch from Paul [1] and changes to the DT [2]. But this is orthogonal to this series.

Patch 1 is a drive-by patch to bring SUNXI_GPIO to Kconfig, as this was lingering in one of my branches for a while.
Patch 2 enables GPIO support for the H6, as this is needed for the Pine H64 to enable the VBUS regulator.
Patch 3 adds the clock and reset gates mappings for the USB controller and the PHY, the values are taken from the manual and verified against Linux.
Patch 4 adds some code to the PHY driver to skip over not implemented PHYs, as the H6 uses a PHY0/PHY3 combination in the DT.
Patch 5 then eventually enables USB in the existing defconfigs.

Quoted 3 lines

Cheers,
Andre.

Hello

I have tested your serie on a orangepi1+ and it works!

But on a pineH64 with an asix USb dongle I got:
U-Boot SPL 2019.07-rc4-00183-g6b5b853fd8-dirty (Jun 24 2019 - 10:44:19 +0200)
DRAM: 2048 MiB
Trying to boot from MMC1

NOTICE:  BL31: v2.1(release):v2.1-72-g4b9d01d5
NOTICE:  BL31: Built : 11:47:12, Apr 16 2019
NOTICE:  BL31: Detected Allwinner H6 SoC (1728)
NOTICE:  BL31: Found U-Boot DTB at 0xc07fa00, model: Pine H64
NOTICE:  PMIC: Probing AXP805
NOTICE:  PMIC: AXP805 detected

U-Boot 2019.07-rc4-00183-g6b5b853fd8-dirty (Jun 24 2019 - 10:44:19 +0200) Allwinner Technology

CPU:   Allwinner H6 (SUN50I)
Model: Pine H64
DRAM:  2 GiB
MMC:   mmc at 4020000: 0, mmc at 4022000: 1
Loading Environment from FAT... Card did not respond to voltage select!
In:    serial at 5000000
Out:   serial at 5000000
Err:   serial at 5000000
Net:   No ethernet found.

starting USB...
Bus usb at 5101000: USB EHCI 1.00
Bus usb at 5101400: USB OHCI 1.0
Bus usb at 5311000: USB EHCI 1.00
Bus usb at 5311400: USB OHCI 1.0
scanning bus usb at 5101000 for devices... 1 USB Device(s) found scanning bus usb at 5101400 for devices... 1 USB Device(s) found scanning bus usb at 5311000 for devices...
Warning: ax88179_eth MAC addresses don't match:
Address in ROM is 00:0e:c6:ac:f3:d0
Address in environment is 02:01:1b:e5:f7:26
2 USB Device(s) found
scanning bus usb at 5311400 for devices... 1 USB Device(s) found
scanning usb for storage devices... 0 Storage Device(s) found
Hit any key to stop autoboot: 0
=> dhcp
Waiting for Ethernet connection... unable to connect. Reset Ethernet Device
Waiting for Ethernet connection... done.
BOOTP broadcast 1
EHCI timed out on TD - token=0x14008d80
Rx: failed to receive: -5
BOOTP broadcast 2
DHCP client bound to address 192.168.66.143 (6010 ms)
*** ERROR: `serverip' not set
Cannot autoload with TFTPGET

But the network is working (download kernel via tftp with success) But I fear the EHCI timed out and co...
Could it be related to yours patchs ?

Anyway you could add

Thanks
Regards

#7 lore raw

v2 cover sunxi: H6: Enable USB (2.0) support

In reply to Andre Przywara
Quoted 36 lines · Andre Przywara

Hi,

a minor update to v1, adding PortM support as per Icenowy's comment and dropping the DT change. We still need the latter for support the USB0 port on some boards, but this takes another route now (syncing back from Linux).
---------------

This series enables USB support on the H6 boards. This is mostly just adding some missing pieces here and there, the actual controller and PHY are very similar to the previous ones, if not identical. This is for the 2.0 ports only at the moment, USB 3.0 requires some more work to make U-Boot's driver compliant to the kernel's DT bindings.

The Pine H64 shares a similar problem as the Pine64+ boards regarding the upper USB port. To enable this port, we need a patch from Paul [1] and changes to the DT [2]. But this is orthogonal to this series.

Patch 1 is a drive-by patch to bring SUNXI_GPIO to Kconfig, as this was lingering in one of my branches for a while.
Patch 2 enables GPIO support for the H6, as this is needed for the Pine H64 to enable the VBUS regulator.
Patch 3 adds the clock and reset gates mappings for the USB controller and the PHY, the values are taken from the manual and verified against Linux.
Patch 4 adds some code to the PHY driver to skip over not implemented PHYs, as the H6 uses a PHY0/PHY3 combination in the DT.
Patch 5 then eventually enables USB in the existing defconfigs.

Cheers,
Andre.

[1] https://lists.denx.de/pipermail/u-boot/2019-March/361828.html
[2] http://lists.infradead.org/pipermail/linux-arm-kernel/2019-June/661580.html

Quoted 6 lines

Andre Przywara (5):
sunxi: move SUNXI_GPIO to Kconfig
sunxi: gpio: Enable support for H6 pin controller
sunxi: clocks: Add H6 USB clock gates and resets
sunxi: phy: Add USB PHY support for Allwinner H6
sunxi: H6: Enable USB for existing boards

#8 lore raw

v2 cover sunxi: H6: Enable USB (2.0) support

Quoted 38 lines · Jagan Teki
Quoted 36 lines · Andre Przywara

Hi,

a minor update to v1, adding PortM support as per Icenowy's comment and dropping the DT change. We still need the latter for support the USB0 port on some boards, but this takes another route now (syncing back from Linux).
---------------

This series enables USB support on the H6 boards. This is mostly just adding some missing pieces here and there, the actual controller and PHY are very similar to the previous ones, if not identical. This is for the 2.0 ports only at the moment, USB 3.0 requires some more work to make U-Boot's driver compliant to the kernel's DT bindings.

The Pine H64 shares a similar problem as the Pine64+ boards regarding the upper USB port. To enable this port, we need a patch from Paul [1] and changes to the DT [2]. But this is orthogonal to this series.

Patch 1 is a drive-by patch to bring SUNXI_GPIO to Kconfig, as this was lingering in one of my branches for a while.
Patch 2 enables GPIO support for the H6, as this is needed for the Pine H64 to enable the VBUS regulator.
Patch 3 adds the clock and reset gates mappings for the USB controller and the PHY, the values are taken from the manual and verified against Linux.
Patch 4 adds some code to the PHY driver to skip over not implemented PHYs, as the H6 uses a PHY0/PHY3 combination in the DT.
Patch 5 then eventually enables USB in the existing defconfigs.

Cheers,
Andre.

[1] https://lists.denx.de/pipermail/u-boot/2019-March/361828.html
[2] http://lists.infradead.org/pipermail/linux-arm-kernel/2019-June/661580.html

Quoted 8 lines
Quoted 6 lines

Andre Przywara (5):
sunxi: move SUNXI_GPIO to Kconfig
sunxi: gpio: Enable support for H6 pin controller
sunxi: clocks: Add H6 USB clock gates and resets
sunxi: phy: Add USB PHY support for Allwinner H6
sunxi: H6: Enable USB for existing boards

Applied to u-boot-sunix/master