[U-Boot] [PATCH v2 0/5] 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(-)

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.
Signed-off-by: Andre Przywara andre.przywara@arm.com --- 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(-)
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 01ff57cf1b..97504e1218 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -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 diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index e36a8abc42..5a4d7c553e 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig @@ -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 diff --git a/include/configs/sunxi-common.h b/include/configs/sunxi-common.h index fceb812448..7be94ee7d1 100644 --- a/include/configs/sunxi-common.h +++ b/include/configs/sunxi-common.h @@ -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, diff --git a/scripts/config_whitelist.txt b/scripts/config_whitelist.txt index 22de7a4b6c..b5799cbef6 100644 --- a/scripts/config_whitelist.txt +++ b/scripts/config_whitelist.txt @@ -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

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.
Signed-off-by: Andre Przywara andre.przywara@arm.com --- drivers/gpio/sunxi_gpio.c | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/drivers/gpio/sunxi_gpio.c b/drivers/gpio/sunxi_gpio.c index cbed8d42b7..719efc2cef 100644 --- a/drivers/gpio/sunxi_gpio.c +++ b/drivers/gpio/sunxi_gpio.c @@ -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), { } };

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.
Signed-off-by: Andre Przywara andre.przywara@arm.com --- drivers/clk/sunxi/clk_h6.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
diff --git a/drivers/clk/sunxi/clk_h6.c b/drivers/clk/sunxi/clk_h6.c index 0bb00f449a..105c15d869 100644 --- a/drivers/clk/sunxi/clk_h6.c +++ b/drivers/clk/sunxi/clk_h6.c @@ -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 = {

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.
Signed-off-by: Andre Przywara andre.przywara@arm.com --- drivers/phy/allwinner/phy-sun4i-usb.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
diff --git a/drivers/phy/allwinner/phy-sun4i-usb.c b/drivers/phy/allwinner/phy-sun4i-usb.c index f206fa3f5d..5e8f87717f 100644 --- a/drivers/phy/allwinner/phy-sun4i-usb.c +++ b/drivers/phy/allwinner/phy-sun4i-usb.c @@ -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}, { } };

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.
Signed-off-by: Andre Przywara andre.przywara@arm.com --- 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(+)
diff --git a/arch/arm/mach-sunxi/Kconfig b/arch/arm/mach-sunxi/Kconfig index 1669e62a6d..ad29139545 100644 --- a/arch/arm/mach-sunxi/Kconfig +++ b/arch/arm/mach-sunxi/Kconfig @@ -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
diff --git a/configs/beelink_gs1_defconfig b/configs/beelink_gs1_defconfig index f16d0fee22..8458f6b32f 100644 --- a/configs/beelink_gs1_defconfig +++ b/configs/beelink_gs1_defconfig @@ -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 diff --git a/configs/orangepi_lite2_defconfig b/configs/orangepi_lite2_defconfig index e5c2846eaa..227e1ac873 100644 --- a/configs/orangepi_lite2_defconfig +++ b/configs/orangepi_lite2_defconfig @@ -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 diff --git a/configs/orangepi_one_plus_defconfig b/configs/orangepi_one_plus_defconfig index 65537c422f..2e45909e3a 100644 --- a/configs/orangepi_one_plus_defconfig +++ b/configs/orangepi_one_plus_defconfig @@ -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 diff --git a/configs/pine_h64_defconfig b/configs/pine_h64_defconfig index 5ac89b462c..0c5e47bbf7 100644 --- a/configs/pine_h64_defconfig +++ b/configs/pine_h64_defconfig @@ -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"

On Sun, Jun 23, 2019 at 03:09:45PM +0100, Andre Przywara wrote:
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.
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@4020000: 0, mmc@4022000: 1 Loading Environment from FAT... Card did not respond to voltage select! In: serial@5000000 Out: serial@5000000 Err: serial@5000000 Net: No ethernet found. starting USB... Bus usb@5101000: USB EHCI 1.00 Bus usb@5101400: USB OHCI 1.0 Bus usb@5311000: USB EHCI 1.00 Bus usb@5311400: USB OHCI 1.0 scanning bus usb@5101000 for devices... 1 USB Device(s) found scanning bus usb@5101400 for devices... 1 USB Device(s) found scanning bus usb@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@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 Tested-by: Corentin Labbe clabbe.montjoie@gmail.com
Thanks Regards

On Sun, Jun 23, 2019 at 7:40 PM Andre Przywara andre.przywara@arm.com wrote:
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
Reviewed-by: Jagan Teki jagan@amarulasolutions.com

On Tue, Jul 16, 2019 at 5:05 PM Jagan Teki jagan@amarulasolutions.com wrote:
On Sun, Jun 23, 2019 at 7:40 PM Andre Przywara andre.przywara@arm.com wrote:
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
Reviewed-by: Jagan Teki jagan@amarulasolutions.com
Applied to u-boot-sunix/master
participants (3)
-
Andre Przywara
-
Corentin Labbe
-
Jagan Teki