ARM Sunxi Platform Development
 help / color / mirror / Atom feed
* [PATCH 0/3] phy: sun4i: Allwinner F1C100s support and cleanup
@ 2023-06-09 10:56 Andre Przywara
  2023-06-09 10:56 ` [PATCH 1/3] phy: sun4i-usb: Fix of_xlate() argument check Andre Przywara
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Andre Przywara @ 2023-06-09 10:56 UTC (permalink / raw)
  To: Jagan Teki
  Cc: Marek Vasut, Sam Edwards, Samuel Holland, Icenowy Zheng, u-boot,
	linux-sunxi

This mini series adds support for the Allwinner F1C100s USB PHY. There
is really not much to it, we just need to connect the compatible string
to a description that says we have one "old-style" PHY (patch 2/3).
Doing this revealed a bug, which is fixed in patch 1/3.

Also use the opportunity to fix a long-standing annoyance: we were
"select"ing the USB PHY driver from each SoC's Kconfig stanza, which does
not only look questionable, but also prevents USB support from being
deliberately disabled, for boards without USB sockets or to save
memory and boot time.

The fix in patch 1/3 is not urgent, since we were not hitting this
condition before, so this would all be 2023.10 material.

Cheers,
Andre

Andre Przywara (3):
  phy: sun4i-usb: Fix of_xlate() argument check
  phy: sun4i-usb: add Allwinner F1C100s support
  sunxi: Kconfig: rework PHY_USB_SUN4I selection

 arch/arm/mach-sunxi/Kconfig           | 11 -----------
 drivers/phy/allwinner/Kconfig         |  6 +++++-
 drivers/phy/allwinner/phy-sun4i-usb.c | 14 +++++++++++++-
 3 files changed, 18 insertions(+), 13 deletions(-)

-- 
2.25.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/3] phy: sun4i-usb: Fix of_xlate() argument check
  2023-06-09 10:56 [PATCH 0/3] phy: sun4i: Allwinner F1C100s support and cleanup Andre Przywara
@ 2023-06-09 10:56 ` Andre Przywara
  2023-06-09 20:40   ` Jernej Škrabec
  2023-06-09 10:56 ` [PATCH 2/3] phy: sun4i-usb: add Allwinner F1C100s support Andre Przywara
  2023-06-09 10:56 ` [PATCH 3/3] sunxi: Kconfig: rework PHY_USB_SUN4I selection Andre Przywara
  2 siblings, 1 reply; 7+ messages in thread
From: Andre Przywara @ 2023-06-09 10:56 UTC (permalink / raw)
  To: Jagan Teki
  Cc: Marek Vasut, Sam Edwards, Samuel Holland, Icenowy Zheng, u-boot,
	linux-sunxi

In its of_xlate() function, the Allwinner USB PHY driver compares the
args_count variable against the number of implemented USB PHYs, although
this is the *number of arguments* to the DT phandle property. Per the DT
binding for this PHY device, this number is always one, so this check
will always fail if the particular SoC implements exactly one USB PHY.
So far this affected only the V3s (which has USB support disabled), but
the F1C100s also sports one PHY only.

Fix that check to compare args_count against exactly 1, and the args[0]
content (requested PHY number) against the number of implemented PHYs.

This fixes USB operation on the Allwinner V3s and allows to enable USB
on the Allwinner F1C100s SoC.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
---
 drivers/phy/allwinner/phy-sun4i-usb.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/phy/allwinner/phy-sun4i-usb.c b/drivers/phy/allwinner/phy-sun4i-usb.c
index 6428163c188..dbea70f9a5e 100644
--- a/drivers/phy/allwinner/phy-sun4i-usb.c
+++ b/drivers/phy/allwinner/phy-sun4i-usb.c
@@ -372,7 +372,10 @@ static int sun4i_usb_phy_xlate(struct phy *phy,
 {
 	struct sun4i_usb_phy_data *data = dev_get_priv(phy->dev);
 
-	if (args->args_count >= data->cfg->num_phys)
+	if (args->args_count != 1)
+		return -EINVAL;
+
+	if (args->args[0] >= data->cfg->num_phys)
 		return -EINVAL;
 
 	if (data->cfg->missing_phys & BIT(args->args[0]))
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/3] phy: sun4i-usb: add Allwinner F1C100s support
  2023-06-09 10:56 [PATCH 0/3] phy: sun4i: Allwinner F1C100s support and cleanup Andre Przywara
  2023-06-09 10:56 ` [PATCH 1/3] phy: sun4i-usb: Fix of_xlate() argument check Andre Przywara
@ 2023-06-09 10:56 ` Andre Przywara
  2023-06-09 20:40   ` Jernej Škrabec
  2023-06-09 10:56 ` [PATCH 3/3] sunxi: Kconfig: rework PHY_USB_SUN4I selection Andre Przywara
  2 siblings, 1 reply; 7+ messages in thread
From: Andre Przywara @ 2023-06-09 10:56 UTC (permalink / raw)
  To: Jagan Teki
  Cc: Marek Vasut, Sam Edwards, Samuel Holland, Icenowy Zheng, u-boot,
	linux-sunxi

The Allwinner F1C100s implements a single USB PHY, connected to its MUSB
OTG controller. The USB PHY is of the simpler, older type (like the A10),
the only real difference is that it's indeed only one PHY.

Add a struct describing those F1C100s USB PHY properties, and connect it
to the new compatible string.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
---
 drivers/phy/allwinner/phy-sun4i-usb.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/drivers/phy/allwinner/phy-sun4i-usb.c b/drivers/phy/allwinner/phy-sun4i-usb.c
index dbea70f9a5e..2bf47fc36a7 100644
--- a/drivers/phy/allwinner/phy-sun4i-usb.c
+++ b/drivers/phy/allwinner/phy-sun4i-usb.c
@@ -648,6 +648,14 @@ static const struct sun4i_usb_phy_cfg sun50i_h6_cfg = {
 	.missing_phys = BIT(1) | BIT(2),
 };
 
+static const struct sun4i_usb_phy_cfg suniv_f1c100s_cfg = {
+	.num_phys = 1,
+	.type = sun4i_a10_phy,
+	.disc_thresh = 3,
+	.phyctl_offset = REG_PHYCTL_A10,
+	.dedicated_clocks = true,
+};
+
 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 },
@@ -662,6 +670,7 @@ static const struct udevice_id sun4i_usb_phy_ids[] = {
 	{ .compatible = "allwinner,sun20i-d1-usb-phy", .data = (ulong)&sun20i_d1_cfg },
 	{ .compatible = "allwinner,sun50i-a64-usb-phy", .data = (ulong)&sun50i_a64_cfg},
 	{ .compatible = "allwinner,sun50i-h6-usb-phy", .data = (ulong)&sun50i_h6_cfg},
+	{ .compatible = "allwinner,suniv-f1c100s-usb-phy", .data = (ulong)&suniv_f1c100s_cfg },
 	{ }
 };
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/3] sunxi: Kconfig: rework PHY_USB_SUN4I selection
  2023-06-09 10:56 [PATCH 0/3] phy: sun4i: Allwinner F1C100s support and cleanup Andre Przywara
  2023-06-09 10:56 ` [PATCH 1/3] phy: sun4i-usb: Fix of_xlate() argument check Andre Przywara
  2023-06-09 10:56 ` [PATCH 2/3] phy: sun4i-usb: add Allwinner F1C100s support Andre Przywara
@ 2023-06-09 10:56 ` Andre Przywara
  2023-06-09 20:42   ` Jernej Škrabec
  2 siblings, 1 reply; 7+ messages in thread
From: Andre Przywara @ 2023-06-09 10:56 UTC (permalink / raw)
  To: Jagan Teki
  Cc: Marek Vasut, Sam Edwards, Samuel Holland, Icenowy Zheng, u-boot,
	linux-sunxi

At the moment we use "select" in each Allwinner SoC's Kconfig section to
include the USB PHY driver in the build. This means it cannot be disabled
via Kconfig, although USB is not really a strictly required core
functionality, and a particular board might not even include USB ports.

Rework the Kconfig part by removing the "select" lines for each SoC's
section, and instead letting it default to "y" in the PHY driver section
itself. We use "depends on !" to exclude the few SoCs we don't support
(yet). The Allwinner V3s does not enable USB (PHY) support at the moment,
even though it should work: let the PHY default to "n" to keep the
current behaviour.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
---
 arch/arm/mach-sunxi/Kconfig   | 11 -----------
 drivers/phy/allwinner/Kconfig |  6 +++++-
 2 files changed, 5 insertions(+), 12 deletions(-)

diff --git a/arch/arm/mach-sunxi/Kconfig b/arch/arm/mach-sunxi/Kconfig
index 6dcbb096f74..e0b1bde35a9 100644
--- a/arch/arm/mach-sunxi/Kconfig
+++ b/arch/arm/mach-sunxi/Kconfig
@@ -207,7 +207,6 @@ endif
 
 config MACH_SUNXI_H3_H5
 	bool
-	select PHY_SUN4I_USB
 	select SUNXI_DE2
 	select SUNXI_DRAM_DW
 	select SUNXI_DRAM_DW_32BIT
@@ -236,7 +235,6 @@ config MACH_SUNIV
 config MACH_SUN4I
 	bool "sun4i (Allwinner A10)"
 	select CPU_V7A
-	select PHY_SUN4I_USB
 	select DRAM_SUN4I
 	select SUNXI_GEN_SUN4I
 	select SUPPORT_SPL
@@ -247,7 +245,6 @@ config MACH_SUN5I
 	bool "sun5i (Allwinner A13)"
 	select CPU_V7A
 	select DRAM_SUN4I
-	select PHY_SUN4I_USB
 	select SUNXI_GEN_SUN4I
 	select SUPPORT_SPL
 	imply SPL_SYS_I2C_LEGACY
@@ -261,7 +258,6 @@ config MACH_SUN6I
 	select ARCH_SUPPORT_PSCI
 	select SPL_ARMV7_SET_CORTEX_SMPEN
 	select DRAM_SUN6I
-	select PHY_SUN4I_USB
 	select SPL_I2C
 	select SUN6I_PRCM
 	select SUNXI_GEN_SUN6I
@@ -277,7 +273,6 @@ config MACH_SUN7I
 	select ARCH_SUPPORT_PSCI
 	select SPL_ARMV7_SET_CORTEX_SMPEN
 	select DRAM_SUN4I
-	select PHY_SUN4I_USB
 	select SUNXI_GEN_SUN4I
 	select SUPPORT_SPL
 	select ARMV7_BOOT_SEC_DEFAULT if OLD_SUNXI_KERNEL_COMPAT
@@ -291,7 +286,6 @@ config MACH_SUN8I_A23
 	select CPU_V7_HAS_VIRT
 	select ARCH_SUPPORT_PSCI
 	select DRAM_SUN8I_A23
-	select PHY_SUN4I_USB
 	select SPL_I2C
 	select SUNXI_GEN_SUN6I
 	select SUPPORT_SPL
@@ -305,7 +299,6 @@ config MACH_SUN8I_A33
 	select CPU_V7_HAS_VIRT
 	select ARCH_SUPPORT_PSCI
 	select DRAM_SUN8I_A33
-	select PHY_SUN4I_USB
 	select SPL_I2C
 	select SUNXI_GEN_SUN6I
 	select SUPPORT_SPL
@@ -316,7 +309,6 @@ config MACH_SUN8I_A83T
 	bool "sun8i (Allwinner A83T)"
 	select CPU_V7A
 	select DRAM_SUN8I_A83T
-	select PHY_SUN4I_USB
 	select SPL_I2C
 	select SUNXI_GEN_SUN6I
 	select MMC_SUNXI_HAS_NEW_MODE
@@ -344,7 +336,6 @@ config MACH_SUN8I_R40
 	select SUPPORT_SPL
 	select SUNXI_DRAM_DW
 	select SUNXI_DRAM_DW_32BIT
-	select PHY_SUN4I_USB
 	imply SPL_SYS_I2C_LEGACY
 
 config MACH_SUN8I_V3S
@@ -372,7 +363,6 @@ config MACH_SUN9I
 config MACH_SUN50I
 	bool "sun50i (Allwinner A64)"
 	select ARM64
-	select PHY_SUN4I_USB
 	select SUN6I_PRCM
 	select SUNXI_DE2
 	select SUNXI_GEN_SUN6I
@@ -395,7 +385,6 @@ config MACH_SUN50I_H5
 config MACH_SUN50I_H6
 	bool "sun50i (Allwinner H6)"
 	select ARM64
-	select PHY_SUN4I_USB
 	select DRAM_SUN50I_H6
 	select SUN50I_GEN_H6
 
diff --git a/drivers/phy/allwinner/Kconfig b/drivers/phy/allwinner/Kconfig
index f8f1e99c4f5..565b4617b01 100644
--- a/drivers/phy/allwinner/Kconfig
+++ b/drivers/phy/allwinner/Kconfig
@@ -4,6 +4,10 @@
 config PHY_SUN4I_USB
 	bool "Allwinner Sun4I USB PHY driver"
 	depends on ARCH_SUNXI
+	depends on !MACH_SUN9I
+	depends on !MACH_SUN50I_H616
+	default n if MACH_SUN8I_V3S
+	default y
 	select DM_REGULATOR
 	select PHY
 	help
@@ -11,7 +15,7 @@ config PHY_SUN4I_USB
 	  sunxi SoCs.
 
 	  This driver controls the entire USB PHY block, both the USB OTG
-	  parts, as well as the 2 regular USB 2 host PHYs.
+	  parts, as well as the regular USB HCI host PHYs.
 
 config INITIAL_USB_SCAN_DELAY
 	int "Delay initial USB scan by x ms to allow builtin devices to init"
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/3] phy: sun4i-usb: Fix of_xlate() argument check
  2023-06-09 10:56 ` [PATCH 1/3] phy: sun4i-usb: Fix of_xlate() argument check Andre Przywara
@ 2023-06-09 20:40   ` Jernej Škrabec
  0 siblings, 0 replies; 7+ messages in thread
From: Jernej Škrabec @ 2023-06-09 20:40 UTC (permalink / raw)
  To: Jagan Teki, Andre Przywara
  Cc: Marek Vasut, Sam Edwards, Samuel Holland, Icenowy Zheng, u-boot,
	linux-sunxi

Dne petek, 09. junij 2023 ob 12:56:19 CEST je Andre Przywara napisal(a):
> In its of_xlate() function, the Allwinner USB PHY driver compares the
> args_count variable against the number of implemented USB PHYs, although
> this is the *number of arguments* to the DT phandle property. Per the DT
> binding for this PHY device, this number is always one, so this check
> will always fail if the particular SoC implements exactly one USB PHY.
> So far this affected only the V3s (which has USB support disabled), but
> the F1C100s also sports one PHY only.
> 
> Fix that check to compare args_count against exactly 1, and the args[0]
> content (requested PHY number) against the number of implemented PHYs.
> 
> This fixes USB operation on the Allwinner V3s and allows to enable USB
> on the Allwinner F1C100s SoC.
> 
> Signed-off-by: Andre Przywara <andre.przywara@arm.com>

Nice catch!

Reviewed-by: Jernej Skrabec <jernej.skrabec@gmail.com>

Best regards,
Jernej



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/3] phy: sun4i-usb: add Allwinner F1C100s support
  2023-06-09 10:56 ` [PATCH 2/3] phy: sun4i-usb: add Allwinner F1C100s support Andre Przywara
@ 2023-06-09 20:40   ` Jernej Škrabec
  0 siblings, 0 replies; 7+ messages in thread
From: Jernej Škrabec @ 2023-06-09 20:40 UTC (permalink / raw)
  To: Jagan Teki, Andre Przywara
  Cc: Marek Vasut, Sam Edwards, Samuel Holland, Icenowy Zheng, u-boot,
	linux-sunxi

Dne petek, 09. junij 2023 ob 12:56:20 CEST je Andre Przywara napisal(a):
> The Allwinner F1C100s implements a single USB PHY, connected to its MUSB
> OTG controller. The USB PHY is of the simpler, older type (like the A10),
> the only real difference is that it's indeed only one PHY.
> 
> Add a struct describing those F1C100s USB PHY properties, and connect it
> to the new compatible string.
> 
> Signed-off-by: Andre Przywara <andre.przywara@arm.com>

Reviewed-by: Jernej Skrabec <jernej.skrabec@gmail.com>

Best regards,
Jernej



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 3/3] sunxi: Kconfig: rework PHY_USB_SUN4I selection
  2023-06-09 10:56 ` [PATCH 3/3] sunxi: Kconfig: rework PHY_USB_SUN4I selection Andre Przywara
@ 2023-06-09 20:42   ` Jernej Škrabec
  0 siblings, 0 replies; 7+ messages in thread
From: Jernej Škrabec @ 2023-06-09 20:42 UTC (permalink / raw)
  To: Jagan Teki, Andre Przywara
  Cc: Marek Vasut, Sam Edwards, Samuel Holland, Icenowy Zheng, u-boot,
	linux-sunxi

Dne petek, 09. junij 2023 ob 12:56:21 CEST je Andre Przywara napisal(a):
> At the moment we use "select" in each Allwinner SoC's Kconfig section to
> include the USB PHY driver in the build. This means it cannot be disabled
> via Kconfig, although USB is not really a strictly required core
> functionality, and a particular board might not even include USB ports.
> 
> Rework the Kconfig part by removing the "select" lines for each SoC's
> section, and instead letting it default to "y" in the PHY driver section
> itself. We use "depends on !" to exclude the few SoCs we don't support
> (yet). The Allwinner V3s does not enable USB (PHY) support at the moment,
> even though it should work: let the PHY default to "n" to keep the
> current behaviour.
> 
> Signed-off-by: Andre Przywara <andre.przywara@arm.com>

I stumbled on this issue before, but it didn't bother me enough to actually
do something about that. Thanks!

Reviewed-by: Jernej Skrabec <jernej.skrabec@gmail.com>

Best regards,
Jernej



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-06-09 20:42 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-09 10:56 [PATCH 0/3] phy: sun4i: Allwinner F1C100s support and cleanup Andre Przywara
2023-06-09 10:56 ` [PATCH 1/3] phy: sun4i-usb: Fix of_xlate() argument check Andre Przywara
2023-06-09 20:40   ` Jernej Škrabec
2023-06-09 10:56 ` [PATCH 2/3] phy: sun4i-usb: add Allwinner F1C100s support Andre Przywara
2023-06-09 20:40   ` Jernej Škrabec
2023-06-09 10:56 ` [PATCH 3/3] sunxi: Kconfig: rework PHY_USB_SUN4I selection Andre Przywara
2023-06-09 20:42   ` Jernej Škrabec

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox