All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] phy: sun4i-usb: support automatically switch PHY0 route to MUSB/HCI
@ 2017-02-28 15:27 ` Icenowy Zheng
  0 siblings, 0 replies; 24+ messages in thread
From: Icenowy Zheng @ 2017-02-28 15:27 UTC (permalink / raw)
  To: Maxime Ripard, Chen-Yu Tsai, Kishon Vijay Abraham I, Hans de Goede
  Cc: devicetree-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-sunxi-/JYPxA39Uh5TLH3MbocFFw, Icenowy Zheng

On newer Allwinner SoCs (H3 and after), the PHY0 node is routed to both
MUSB controller for peripheral and host support (the host support is
slightly broken), and a pair of EHCI/OHCI controllers, which provide a
better support for host mode.

Add support for automatically switch the route of PHY0 according to the
status of dr_mode and id det pin.

Only H3 have this function enabled in this patch, as further SoCs will
be tested later and then have it enabled.

Signed-off-by: Icenowy Zheng <icenowy-ymACFijhrKM@public.gmane.org>
---
 drivers/phy/phy-sun4i-usb.c | 55 +++++++++++++++++++++++++++++++--------------
 1 file changed, 38 insertions(+), 17 deletions(-)

diff --git a/drivers/phy/phy-sun4i-usb.c b/drivers/phy/phy-sun4i-usb.c
index a21b5f24a340..8b91afe8f42d 100644
--- a/drivers/phy/phy-sun4i-usb.c
+++ b/drivers/phy/phy-sun4i-usb.c
@@ -49,12 +49,14 @@
 #define REG_PHYBIST			0x08
 #define REG_PHYTUNE			0x0c
 #define REG_PHYCTL_A33			0x10
-#define REG_PHY_UNK_H3			0x20
+#define REG_PHY_OTGCTL			0x20
 
 #define REG_PMU_UNK1			0x10
 
 #define PHYCTL_DATA			BIT(7)
 
+#define OTGCTL_ROUTE_MUSB		BIT(0)
+
 #define SUNXI_AHB_ICHR8_EN		BIT(10)
 #define SUNXI_AHB_INCR4_BURST_EN	BIT(9)
 #define SUNXI_AHB_INCRX_ALIGN_EN	BIT(8)
@@ -110,6 +112,7 @@ struct sun4i_usb_phy_cfg {
 	u8 phyctl_offset;
 	bool dedicated_clocks;
 	bool enable_pmu_unk1;
+	bool phy0_dual_route;
 };
 
 struct sun4i_usb_phy_data {
@@ -271,23 +274,16 @@ static int sun4i_usb_phy_init(struct phy *_phy)
 		writel(val & ~2, phy->pmu + REG_PMU_UNK1);
 	}
 
-	if (data->cfg->type == sun8i_h3_phy) {
-		if (phy->index == 0) {
-			val = readl(data->base + REG_PHY_UNK_H3);
-			writel(val & ~1, data->base + REG_PHY_UNK_H3);
-		}
-	} else {
-		/* Enable USB 45 Ohm resistor calibration */
-		if (phy->index == 0)
-			sun4i_usb_phy_write(phy, PHY_RES45_CAL_EN, 0x01, 1);
+	/* Enable USB 45 Ohm resistor calibration */
+	if (phy->index == 0)
+		sun4i_usb_phy_write(phy, PHY_RES45_CAL_EN, 0x01, 1);
 
-		/* Adjust PHY's magnitude and rate */
-		sun4i_usb_phy_write(phy, PHY_TX_AMPLITUDE_TUNE, 0x14, 5);
+	/* Adjust PHY's magnitude and rate */
+	sun4i_usb_phy_write(phy, PHY_TX_AMPLITUDE_TUNE, 0x14, 5);
 
-		/* Disconnect threshold adjustment */
-		sun4i_usb_phy_write(phy, PHY_DISCON_TH_SEL,
-				    data->cfg->disc_thresh, 2);
-	}
+	/* Disconnect threshold adjustment */
+	sun4i_usb_phy_write(phy, PHY_DISCON_TH_SEL,
+			    data->cfg->disc_thresh, 2);
 
 	sun4i_usb_phy_passby(phy, 1);
 
@@ -486,6 +482,26 @@ static const struct phy_ops sun4i_usb_phy_ops = {
 	.owner		= THIS_MODULE,
 };
 
+static void sun4i_usb_phy0_reroute(struct sun4i_usb_phy_data *data, int id_det)
+{
+	u32 regval;
+
+	if (data->dr_mode == USB_DR_MODE_HOST)
+		id_det = 0; /* Force host */
+	if (data->dr_mode == USB_DR_MODE_PERIPHERAL)
+		id_det = 1; /* Force peripheral*/
+
+	regval = readl(data->base + REG_PHY_OTGCTL);
+	if (id_det == 0) {
+		/* Host mode. Route phy0 to EHCI/OHCI */
+		regval &= ~OTGCTL_ROUTE_MUSB;
+	} else {
+		/* Peripheral mode. Route phy0 to MUSB */
+		regval |= OTGCTL_ROUTE_MUSB;
+	}
+	writel(regval, data->base + REG_PHY_OTGCTL);
+}
+
 static void sun4i_usb_phy0_id_vbus_det_scan(struct work_struct *work)
 {
 	struct sun4i_usb_phy_data *data =
@@ -511,6 +527,10 @@ static void sun4i_usb_phy0_id_vbus_det_scan(struct work_struct *work)
 	data->force_session_end = false;
 
 	if (id_det != data->id_det) {
+		/* Re-route PHY0 if necessary */
+		if (data->cfg->phy0_dual_route)
+			sun4i_usb_phy0_reroute(data, id_det);
+
 		/* id-change, force session end if we've no vbus detection */
 		if (data->dr_mode == USB_DR_MODE_OTG &&
 		    !sun4i_usb_phy0_have_vbus_det(data))
@@ -700,7 +720,7 @@ static int sun4i_usb_phy_probe(struct platform_device *pdev)
 			return PTR_ERR(phy->reset);
 		}
 
-		if (i) { /* No pmu for usbc0 */
+		if (i || data->cfg->phy0_dual_route) { /* No pmu for musb */
 			snprintf(name, sizeof(name), "pmu%d", i);
 			res = platform_get_resource_byname(pdev,
 							IORESOURCE_MEM, name);
@@ -825,6 +845,7 @@ static const struct sun4i_usb_phy_cfg sun8i_h3_cfg = {
 	.disc_thresh = 3,
 	.dedicated_clocks = true,
 	.enable_pmu_unk1 = true,
+	.phy0_dual_route = true,
 };
 
 static const struct sun4i_usb_phy_cfg sun8i_v3s_cfg = {
-- 
2.11.1

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

* [PATCH 1/3] phy: sun4i-usb: support automatically switch PHY0 route to MUSB/HCI
@ 2017-02-28 15:27 ` Icenowy Zheng
  0 siblings, 0 replies; 24+ messages in thread
From: Icenowy Zheng @ 2017-02-28 15:27 UTC (permalink / raw)
  To: linux-arm-kernel

On newer Allwinner SoCs (H3 and after), the PHY0 node is routed to both
MUSB controller for peripheral and host support (the host support is
slightly broken), and a pair of EHCI/OHCI controllers, which provide a
better support for host mode.

Add support for automatically switch the route of PHY0 according to the
status of dr_mode and id det pin.

Only H3 have this function enabled in this patch, as further SoCs will
be tested later and then have it enabled.

Signed-off-by: Icenowy Zheng <icenowy@aosc.xyz>
---
 drivers/phy/phy-sun4i-usb.c | 55 +++++++++++++++++++++++++++++++--------------
 1 file changed, 38 insertions(+), 17 deletions(-)

diff --git a/drivers/phy/phy-sun4i-usb.c b/drivers/phy/phy-sun4i-usb.c
index a21b5f24a340..8b91afe8f42d 100644
--- a/drivers/phy/phy-sun4i-usb.c
+++ b/drivers/phy/phy-sun4i-usb.c
@@ -49,12 +49,14 @@
 #define REG_PHYBIST			0x08
 #define REG_PHYTUNE			0x0c
 #define REG_PHYCTL_A33			0x10
-#define REG_PHY_UNK_H3			0x20
+#define REG_PHY_OTGCTL			0x20
 
 #define REG_PMU_UNK1			0x10
 
 #define PHYCTL_DATA			BIT(7)
 
+#define OTGCTL_ROUTE_MUSB		BIT(0)
+
 #define SUNXI_AHB_ICHR8_EN		BIT(10)
 #define SUNXI_AHB_INCR4_BURST_EN	BIT(9)
 #define SUNXI_AHB_INCRX_ALIGN_EN	BIT(8)
@@ -110,6 +112,7 @@ struct sun4i_usb_phy_cfg {
 	u8 phyctl_offset;
 	bool dedicated_clocks;
 	bool enable_pmu_unk1;
+	bool phy0_dual_route;
 };
 
 struct sun4i_usb_phy_data {
@@ -271,23 +274,16 @@ static int sun4i_usb_phy_init(struct phy *_phy)
 		writel(val & ~2, phy->pmu + REG_PMU_UNK1);
 	}
 
-	if (data->cfg->type == sun8i_h3_phy) {
-		if (phy->index == 0) {
-			val = readl(data->base + REG_PHY_UNK_H3);
-			writel(val & ~1, data->base + REG_PHY_UNK_H3);
-		}
-	} else {
-		/* Enable USB 45 Ohm resistor calibration */
-		if (phy->index == 0)
-			sun4i_usb_phy_write(phy, PHY_RES45_CAL_EN, 0x01, 1);
+	/* Enable USB 45 Ohm resistor calibration */
+	if (phy->index == 0)
+		sun4i_usb_phy_write(phy, PHY_RES45_CAL_EN, 0x01, 1);
 
-		/* Adjust PHY's magnitude and rate */
-		sun4i_usb_phy_write(phy, PHY_TX_AMPLITUDE_TUNE, 0x14, 5);
+	/* Adjust PHY's magnitude and rate */
+	sun4i_usb_phy_write(phy, PHY_TX_AMPLITUDE_TUNE, 0x14, 5);
 
-		/* Disconnect threshold adjustment */
-		sun4i_usb_phy_write(phy, PHY_DISCON_TH_SEL,
-				    data->cfg->disc_thresh, 2);
-	}
+	/* Disconnect threshold adjustment */
+	sun4i_usb_phy_write(phy, PHY_DISCON_TH_SEL,
+			    data->cfg->disc_thresh, 2);
 
 	sun4i_usb_phy_passby(phy, 1);
 
@@ -486,6 +482,26 @@ static const struct phy_ops sun4i_usb_phy_ops = {
 	.owner		= THIS_MODULE,
 };
 
+static void sun4i_usb_phy0_reroute(struct sun4i_usb_phy_data *data, int id_det)
+{
+	u32 regval;
+
+	if (data->dr_mode == USB_DR_MODE_HOST)
+		id_det = 0; /* Force host */
+	if (data->dr_mode == USB_DR_MODE_PERIPHERAL)
+		id_det = 1; /* Force peripheral*/
+
+	regval = readl(data->base + REG_PHY_OTGCTL);
+	if (id_det == 0) {
+		/* Host mode. Route phy0 to EHCI/OHCI */
+		regval &= ~OTGCTL_ROUTE_MUSB;
+	} else {
+		/* Peripheral mode. Route phy0 to MUSB */
+		regval |= OTGCTL_ROUTE_MUSB;
+	}
+	writel(regval, data->base + REG_PHY_OTGCTL);
+}
+
 static void sun4i_usb_phy0_id_vbus_det_scan(struct work_struct *work)
 {
 	struct sun4i_usb_phy_data *data =
@@ -511,6 +527,10 @@ static void sun4i_usb_phy0_id_vbus_det_scan(struct work_struct *work)
 	data->force_session_end = false;
 
 	if (id_det != data->id_det) {
+		/* Re-route PHY0 if necessary */
+		if (data->cfg->phy0_dual_route)
+			sun4i_usb_phy0_reroute(data, id_det);
+
 		/* id-change, force session end if we've no vbus detection */
 		if (data->dr_mode == USB_DR_MODE_OTG &&
 		    !sun4i_usb_phy0_have_vbus_det(data))
@@ -700,7 +720,7 @@ static int sun4i_usb_phy_probe(struct platform_device *pdev)
 			return PTR_ERR(phy->reset);
 		}
 
-		if (i) { /* No pmu for usbc0 */
+		if (i || data->cfg->phy0_dual_route) { /* No pmu for musb */
 			snprintf(name, sizeof(name), "pmu%d", i);
 			res = platform_get_resource_byname(pdev,
 							IORESOURCE_MEM, name);
@@ -825,6 +845,7 @@ static const struct sun4i_usb_phy_cfg sun8i_h3_cfg = {
 	.disc_thresh = 3,
 	.dedicated_clocks = true,
 	.enable_pmu_unk1 = true,
+	.phy0_dual_route = true,
 };
 
 static const struct sun4i_usb_phy_cfg sun8i_v3s_cfg = {
-- 
2.11.1

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

* [PATCH 2/3] ARM: dts: sun8i: add usb_otg and OHCI/EHCI for usbc0 on H3
  2017-02-28 15:27 ` Icenowy Zheng
@ 2017-02-28 15:27     ` Icenowy Zheng
  -1 siblings, 0 replies; 24+ messages in thread
From: Icenowy Zheng @ 2017-02-28 15:27 UTC (permalink / raw)
  To: Maxime Ripard, Chen-Yu Tsai, Kishon Vijay Abraham I, Hans de Goede
  Cc: devicetree-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-sunxi-/JYPxA39Uh5TLH3MbocFFw, Icenowy Zheng

Allwinner H3 have a dual-routed USB PHY0 -- routed to either OHCI/EHCI
or MUSB controller.

Add device nodes for these controllers.

Signed-off-by: Icenowy Zheng <icenowy-ymACFijhrKM@public.gmane.org>
---
 arch/arm/boot/dts/sun8i-h3.dtsi | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/arch/arm/boot/dts/sun8i-h3.dtsi b/arch/arm/boot/dts/sun8i-h3.dtsi
index 27780b97c863..bc9a53edf371 100644
--- a/arch/arm/boot/dts/sun8i-h3.dtsi
+++ b/arch/arm/boot/dts/sun8i-h3.dtsi
@@ -206,6 +206,19 @@
 			#size-cells = <0>;
 		};
 
+		usb_otg: usb@01c19000 {
+			compatible = "allwinner,sun8i-h3-musb";
+			reg = <0x01c19000 0x0400>;
+			clocks = <&ccu CLK_BUS_OTG>;
+			resets = <&ccu RST_BUS_OTG>;
+			interrupts = <GIC_SPI 71 IRQ_TYPE_LEVEL_HIGH>;
+			interrupt-names = "mc";
+			phys = <&usbphy 0>;
+			phy-names = "usb";
+			extcon = <&usbphy 0>;
+			status = "disabled";
+		};
+
 		usbphy: phy@01c19400 {
 			compatible = "allwinner,sun8i-h3-usb-phy";
 			reg = <0x01c19400 0x2c>,
@@ -238,6 +251,29 @@
 			#phy-cells = <1>;
 		};
 
+		ehci0: usb@01c1a000 {
+			compatible = "allwinner,sun8i-h3-ehci", "generic-ehci";
+			reg = <0x01c1a000 0x100>;
+			interrupts = <GIC_SPI 72 IRQ_TYPE_LEVEL_HIGH>;
+			clocks = <&ccu CLK_BUS_EHCI0>, <&ccu CLK_BUS_OHCI0>;
+			resets = <&ccu RST_BUS_EHCI0>, <&ccu RST_BUS_OHCI0>;
+			phys = <&usbphy 0>;
+			phy-names = "usb";
+			status = "disabled";
+		};
+
+		ohci0: usb@01c1a400 {
+			compatible = "allwinner,sun8i-h3-ohci", "generic-ohci";
+			reg = <0x01c1a400 0x100>;
+			interrupts = <GIC_SPI 73 IRQ_TYPE_LEVEL_HIGH>;
+			clocks = <&ccu CLK_BUS_EHCI0>, <&ccu CLK_BUS_OHCI0>,
+				 <&ccu CLK_USB_OHCI0>;
+			resets = <&ccu RST_BUS_EHCI0>, <&ccu RST_BUS_OHCI0>;
+			phys = <&usbphy 0>;
+			phy-names = "usb";
+			status = "disabled";
+		};
+
 		ehci1: usb@01c1b000 {
 			compatible = "allwinner,sun8i-h3-ehci", "generic-ehci";
 			reg = <0x01c1b000 0x100>;
-- 
2.11.1

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

* [PATCH 2/3] ARM: dts: sun8i: add usb_otg and OHCI/EHCI for usbc0 on H3
@ 2017-02-28 15:27     ` Icenowy Zheng
  0 siblings, 0 replies; 24+ messages in thread
From: Icenowy Zheng @ 2017-02-28 15:27 UTC (permalink / raw)
  To: linux-arm-kernel

Allwinner H3 have a dual-routed USB PHY0 -- routed to either OHCI/EHCI
or MUSB controller.

Add device nodes for these controllers.

Signed-off-by: Icenowy Zheng <icenowy@aosc.xyz>
---
 arch/arm/boot/dts/sun8i-h3.dtsi | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/arch/arm/boot/dts/sun8i-h3.dtsi b/arch/arm/boot/dts/sun8i-h3.dtsi
index 27780b97c863..bc9a53edf371 100644
--- a/arch/arm/boot/dts/sun8i-h3.dtsi
+++ b/arch/arm/boot/dts/sun8i-h3.dtsi
@@ -206,6 +206,19 @@
 			#size-cells = <0>;
 		};
 
+		usb_otg: usb at 01c19000 {
+			compatible = "allwinner,sun8i-h3-musb";
+			reg = <0x01c19000 0x0400>;
+			clocks = <&ccu CLK_BUS_OTG>;
+			resets = <&ccu RST_BUS_OTG>;
+			interrupts = <GIC_SPI 71 IRQ_TYPE_LEVEL_HIGH>;
+			interrupt-names = "mc";
+			phys = <&usbphy 0>;
+			phy-names = "usb";
+			extcon = <&usbphy 0>;
+			status = "disabled";
+		};
+
 		usbphy: phy at 01c19400 {
 			compatible = "allwinner,sun8i-h3-usb-phy";
 			reg = <0x01c19400 0x2c>,
@@ -238,6 +251,29 @@
 			#phy-cells = <1>;
 		};
 
+		ehci0: usb at 01c1a000 {
+			compatible = "allwinner,sun8i-h3-ehci", "generic-ehci";
+			reg = <0x01c1a000 0x100>;
+			interrupts = <GIC_SPI 72 IRQ_TYPE_LEVEL_HIGH>;
+			clocks = <&ccu CLK_BUS_EHCI0>, <&ccu CLK_BUS_OHCI0>;
+			resets = <&ccu RST_BUS_EHCI0>, <&ccu RST_BUS_OHCI0>;
+			phys = <&usbphy 0>;
+			phy-names = "usb";
+			status = "disabled";
+		};
+
+		ohci0: usb at 01c1a400 {
+			compatible = "allwinner,sun8i-h3-ohci", "generic-ohci";
+			reg = <0x01c1a400 0x100>;
+			interrupts = <GIC_SPI 73 IRQ_TYPE_LEVEL_HIGH>;
+			clocks = <&ccu CLK_BUS_EHCI0>, <&ccu CLK_BUS_OHCI0>,
+				 <&ccu CLK_USB_OHCI0>;
+			resets = <&ccu RST_BUS_EHCI0>, <&ccu RST_BUS_OHCI0>;
+			phys = <&usbphy 0>;
+			phy-names = "usb";
+			status = "disabled";
+		};
+
 		ehci1: usb at 01c1b000 {
 			compatible = "allwinner,sun8i-h3-ehci", "generic-ehci";
 			reg = <0x01c1b000 0x100>;
-- 
2.11.1

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

* [PATCH 3/3] ARM: dts: sun8i: enable USB OTG on Orange Pi One
  2017-02-28 15:27 ` Icenowy Zheng
@ 2017-02-28 15:27     ` Icenowy Zheng
  -1 siblings, 0 replies; 24+ messages in thread
From: Icenowy Zheng @ 2017-02-28 15:27 UTC (permalink / raw)
  To: Maxime Ripard, Chen-Yu Tsai, Kishon Vijay Abraham I, Hans de Goede
  Cc: devicetree-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-sunxi-/JYPxA39Uh5TLH3MbocFFw, Icenowy Zheng

Orange Pi One features a MicroUSB port that can work in both host mode
and peripheral mode.

When in host mode, its VBUS is controlled via a GPIO; when in peripheral
mode, its VBUS cannot be used to power up the board.

Add support for this port.

Signed-off-by: Icenowy Zheng <icenowy-ymACFijhrKM@public.gmane.org>
---
 arch/arm/boot/dts/sun8i-h3-orangepi-one.dts | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/arch/arm/boot/dts/sun8i-h3-orangepi-one.dts b/arch/arm/boot/dts/sun8i-h3-orangepi-one.dts
index 34da853ee037..b87778d74239 100644
--- a/arch/arm/boot/dts/sun8i-h3-orangepi-one.dts
+++ b/arch/arm/boot/dts/sun8i-h3-orangepi-one.dts
@@ -90,6 +90,10 @@
 	};
 };
 
+&ehci0 {
+	status = "okay";
+};
+
 &ehci1 {
 	status = "okay";
 };
@@ -104,6 +108,10 @@
 	status = "okay";
 };
 
+&ohci0 {
+	status = "okay";
+};
+
 &ohci1 {
 	status = "okay";
 };
@@ -127,6 +135,11 @@
 	};
 };
 
+&reg_usb0_vbus {
+	gpio = <&r_pio 0 2 GPIO_ACTIVE_HIGH>; /* PL2 */
+	status = "okay";
+};
+
 &uart0 {
 	pinctrl-names = "default";
 	pinctrl-0 = <&uart0_pins_a>;
@@ -151,7 +164,14 @@
 	status = "disabled";
 };
 
+&usb_otg {
+	dr_mode = "otg";
+	status = "okay";
+};
+
 &usbphy {
-	/* USB VBUS is always on */
+	/* USB Type-A port's VBUS is always on */
+	usb0_id_det-gpios = <&pio 6 12 GPIO_ACTIVE_HIGH>; /* PG12 */
+	usb0_vbus-supply = <&reg_usb0_vbus>;
 	status = "okay";
 };
-- 
2.11.1

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

* [PATCH 3/3] ARM: dts: sun8i: enable USB OTG on Orange Pi One
@ 2017-02-28 15:27     ` Icenowy Zheng
  0 siblings, 0 replies; 24+ messages in thread
From: Icenowy Zheng @ 2017-02-28 15:27 UTC (permalink / raw)
  To: linux-arm-kernel

Orange Pi One features a MicroUSB port that can work in both host mode
and peripheral mode.

When in host mode, its VBUS is controlled via a GPIO; when in peripheral
mode, its VBUS cannot be used to power up the board.

Add support for this port.

Signed-off-by: Icenowy Zheng <icenowy@aosc.xyz>
---
 arch/arm/boot/dts/sun8i-h3-orangepi-one.dts | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/arch/arm/boot/dts/sun8i-h3-orangepi-one.dts b/arch/arm/boot/dts/sun8i-h3-orangepi-one.dts
index 34da853ee037..b87778d74239 100644
--- a/arch/arm/boot/dts/sun8i-h3-orangepi-one.dts
+++ b/arch/arm/boot/dts/sun8i-h3-orangepi-one.dts
@@ -90,6 +90,10 @@
 	};
 };
 
+&ehci0 {
+	status = "okay";
+};
+
 &ehci1 {
 	status = "okay";
 };
@@ -104,6 +108,10 @@
 	status = "okay";
 };
 
+&ohci0 {
+	status = "okay";
+};
+
 &ohci1 {
 	status = "okay";
 };
@@ -127,6 +135,11 @@
 	};
 };
 
+&reg_usb0_vbus {
+	gpio = <&r_pio 0 2 GPIO_ACTIVE_HIGH>; /* PL2 */
+	status = "okay";
+};
+
 &uart0 {
 	pinctrl-names = "default";
 	pinctrl-0 = <&uart0_pins_a>;
@@ -151,7 +164,14 @@
 	status = "disabled";
 };
 
+&usb_otg {
+	dr_mode = "otg";
+	status = "okay";
+};
+
 &usbphy {
-	/* USB VBUS is always on */
+	/* USB Type-A port's VBUS is always on */
+	usb0_id_det-gpios = <&pio 6 12 GPIO_ACTIVE_HIGH>; /* PG12 */
+	usb0_vbus-supply = <&reg_usb0_vbus>;
 	status = "okay";
 };
-- 
2.11.1

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

* Re: [linux-sunxi] [PATCH 1/3] phy: sun4i-usb: support automatically switch PHY0 route to MUSB/HCI
       [not found] ` <20170228152702.42602-1-icenowy-ymACFijhrKM@public.gmane.org>
  2017-02-28 15:27     ` Icenowy Zheng
@ 2017-02-28 15:42   ` Chen-Yu Tsai
  1 sibling, 0 replies; 24+ messages in thread
From: Chen-Yu Tsai @ 2017-02-28 15:42 UTC (permalink / raw)
  To: Icenowy Zheng
  Cc: Maxime Ripard, Chen-Yu Tsai, Kishon Vijay Abraham I,
	Hans de Goede, devicetree, linux-arm-kernel, linux-kernel,
	linux-sunxi

On Tue, Feb 28, 2017 at 11:27 PM, Icenowy Zheng <icenowy@aosc.xyz> wrote:
> On newer Allwinner SoCs (H3 and after), the PHY0 node is routed to both
> MUSB controller for peripheral and host support (the host support is
> slightly broken), and a pair of EHCI/OHCI controllers, which provide a
> better support for host mode.
>
> Add support for automatically switch the route of PHY0 according to the
> status of dr_mode and id det pin.
>
> Only H3 have this function enabled in this patch, as further SoCs will
> be tested later and then have it enabled.
>
> Signed-off-by: Icenowy Zheng <icenowy@aosc.xyz>
> ---
>  drivers/phy/phy-sun4i-usb.c | 55 +++++++++++++++++++++++++++++++--------------
>  1 file changed, 38 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/phy/phy-sun4i-usb.c b/drivers/phy/phy-sun4i-usb.c
> index a21b5f24a340..8b91afe8f42d 100644
> --- a/drivers/phy/phy-sun4i-usb.c
> +++ b/drivers/phy/phy-sun4i-usb.c
> @@ -49,12 +49,14 @@
>  #define REG_PHYBIST                    0x08
>  #define REG_PHYTUNE                    0x0c
>  #define REG_PHYCTL_A33                 0x10
> -#define REG_PHY_UNK_H3                 0x20
> +#define REG_PHY_OTGCTL                 0x20
>
>  #define REG_PMU_UNK1                   0x10
>
>  #define PHYCTL_DATA                    BIT(7)
>
> +#define OTGCTL_ROUTE_MUSB              BIT(0)
> +
>  #define SUNXI_AHB_ICHR8_EN             BIT(10)
>  #define SUNXI_AHB_INCR4_BURST_EN       BIT(9)
>  #define SUNXI_AHB_INCRX_ALIGN_EN       BIT(8)
> @@ -110,6 +112,7 @@ struct sun4i_usb_phy_cfg {
>         u8 phyctl_offset;
>         bool dedicated_clocks;
>         bool enable_pmu_unk1;
> +       bool phy0_dual_route;
>  };
>
>  struct sun4i_usb_phy_data {
> @@ -271,23 +274,16 @@ static int sun4i_usb_phy_init(struct phy *_phy)
>                 writel(val & ~2, phy->pmu + REG_PMU_UNK1);
>         }
>
> -       if (data->cfg->type == sun8i_h3_phy) {
> -               if (phy->index == 0) {
> -                       val = readl(data->base + REG_PHY_UNK_H3);
> -                       writel(val & ~1, data->base + REG_PHY_UNK_H3);
> -               }
> -       } else {
> -               /* Enable USB 45 Ohm resistor calibration */
> -               if (phy->index == 0)
> -                       sun4i_usb_phy_write(phy, PHY_RES45_CAL_EN, 0x01, 1);
> +       /* Enable USB 45 Ohm resistor calibration */
> +       if (phy->index == 0)
> +               sun4i_usb_phy_write(phy, PHY_RES45_CAL_EN, 0x01, 1);
>
> -               /* Adjust PHY's magnitude and rate */
> -               sun4i_usb_phy_write(phy, PHY_TX_AMPLITUDE_TUNE, 0x14, 5);
> +       /* Adjust PHY's magnitude and rate */
> +       sun4i_usb_phy_write(phy, PHY_TX_AMPLITUDE_TUNE, 0x14, 5);
>
> -               /* Disconnect threshold adjustment */
> -               sun4i_usb_phy_write(phy, PHY_DISCON_TH_SEL,
> -                                   data->cfg->disc_thresh, 2);
> -       }
> +       /* Disconnect threshold adjustment */
> +       sun4i_usb_phy_write(phy, PHY_DISCON_TH_SEL,
> +                           data->cfg->disc_thresh, 2);
>
>         sun4i_usb_phy_passby(phy, 1);
>
> @@ -486,6 +482,26 @@ static const struct phy_ops sun4i_usb_phy_ops = {
>         .owner          = THIS_MODULE,
>  };
>
> +static void sun4i_usb_phy0_reroute(struct sun4i_usb_phy_data *data, int id_det)
> +{
> +       u32 regval;
> +
> +       if (data->dr_mode == USB_DR_MODE_HOST)
> +               id_det = 0; /* Force host */
> +       if (data->dr_mode == USB_DR_MODE_PERIPHERAL)
> +               id_det = 1; /* Force peripheral*/
> +
> +       regval = readl(data->base + REG_PHY_OTGCTL);
> +       if (id_det == 0) {
> +               /* Host mode. Route phy0 to EHCI/OHCI */
> +               regval &= ~OTGCTL_ROUTE_MUSB;
> +       } else {
> +               /* Peripheral mode. Route phy0 to MUSB */
> +               regval |= OTGCTL_ROUTE_MUSB;
> +       }
> +       writel(regval, data->base + REG_PHY_OTGCTL);
> +}
> +
>  static void sun4i_usb_phy0_id_vbus_det_scan(struct work_struct *work)
>  {
>         struct sun4i_usb_phy_data *data =
> @@ -511,6 +527,10 @@ static void sun4i_usb_phy0_id_vbus_det_scan(struct work_struct *work)
>         data->force_session_end = false;
>
>         if (id_det != data->id_det) {
> +               /* Re-route PHY0 if necessary */
> +               if (data->cfg->phy0_dual_route)
> +                       sun4i_usb_phy0_reroute(data, id_det);
> +

Would it make sense to do this after force session end?

ChenYu

>                 /* id-change, force session end if we've no vbus detection */
>                 if (data->dr_mode == USB_DR_MODE_OTG &&
>                     !sun4i_usb_phy0_have_vbus_det(data))
> @@ -700,7 +720,7 @@ static int sun4i_usb_phy_probe(struct platform_device *pdev)
>                         return PTR_ERR(phy->reset);
>                 }
>
> -               if (i) { /* No pmu for usbc0 */
> +               if (i || data->cfg->phy0_dual_route) { /* No pmu for musb */
>                         snprintf(name, sizeof(name), "pmu%d", i);
>                         res = platform_get_resource_byname(pdev,
>                                                         IORESOURCE_MEM, name);
> @@ -825,6 +845,7 @@ static const struct sun4i_usb_phy_cfg sun8i_h3_cfg = {
>         .disc_thresh = 3,
>         .dedicated_clocks = true,
>         .enable_pmu_unk1 = true,
> +       .phy0_dual_route = true,
>  };
>
>  static const struct sun4i_usb_phy_cfg sun8i_v3s_cfg = {
> --
> 2.11.1
>
> --
> You received this message because you are subscribed to the Google Groups "linux-sunxi" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+unsubscribe@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

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

* Re: [PATCH 1/3] phy: sun4i-usb: support automatically switch PHY0 route to MUSB/HCI
@ 2017-02-28 15:42   ` Chen-Yu Tsai
  0 siblings, 0 replies; 24+ messages in thread
From: Chen-Yu Tsai @ 2017-02-28 15:42 UTC (permalink / raw)
  To: Icenowy Zheng
  Cc: Maxime Ripard, Chen-Yu Tsai, Kishon Vijay Abraham I,
	Hans de Goede, devicetree, linux-arm-kernel, linux-kernel,
	linux-sunxi

On Tue, Feb 28, 2017 at 11:27 PM, Icenowy Zheng <icenowy-ymACFijhrKM@public.gmane.org> wrote:
> On newer Allwinner SoCs (H3 and after), the PHY0 node is routed to both
> MUSB controller for peripheral and host support (the host support is
> slightly broken), and a pair of EHCI/OHCI controllers, which provide a
> better support for host mode.
>
> Add support for automatically switch the route of PHY0 according to the
> status of dr_mode and id det pin.
>
> Only H3 have this function enabled in this patch, as further SoCs will
> be tested later and then have it enabled.
>
> Signed-off-by: Icenowy Zheng <icenowy-ymACFijhrKM@public.gmane.org>
> ---
>  drivers/phy/phy-sun4i-usb.c | 55 +++++++++++++++++++++++++++++++--------------
>  1 file changed, 38 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/phy/phy-sun4i-usb.c b/drivers/phy/phy-sun4i-usb.c
> index a21b5f24a340..8b91afe8f42d 100644
> --- a/drivers/phy/phy-sun4i-usb.c
> +++ b/drivers/phy/phy-sun4i-usb.c
> @@ -49,12 +49,14 @@
>  #define REG_PHYBIST                    0x08
>  #define REG_PHYTUNE                    0x0c
>  #define REG_PHYCTL_A33                 0x10
> -#define REG_PHY_UNK_H3                 0x20
> +#define REG_PHY_OTGCTL                 0x20
>
>  #define REG_PMU_UNK1                   0x10
>
>  #define PHYCTL_DATA                    BIT(7)
>
> +#define OTGCTL_ROUTE_MUSB              BIT(0)
> +
>  #define SUNXI_AHB_ICHR8_EN             BIT(10)
>  #define SUNXI_AHB_INCR4_BURST_EN       BIT(9)
>  #define SUNXI_AHB_INCRX_ALIGN_EN       BIT(8)
> @@ -110,6 +112,7 @@ struct sun4i_usb_phy_cfg {
>         u8 phyctl_offset;
>         bool dedicated_clocks;
>         bool enable_pmu_unk1;
> +       bool phy0_dual_route;
>  };
>
>  struct sun4i_usb_phy_data {
> @@ -271,23 +274,16 @@ static int sun4i_usb_phy_init(struct phy *_phy)
>                 writel(val & ~2, phy->pmu + REG_PMU_UNK1);
>         }
>
> -       if (data->cfg->type == sun8i_h3_phy) {
> -               if (phy->index == 0) {
> -                       val = readl(data->base + REG_PHY_UNK_H3);
> -                       writel(val & ~1, data->base + REG_PHY_UNK_H3);
> -               }
> -       } else {
> -               /* Enable USB 45 Ohm resistor calibration */
> -               if (phy->index == 0)
> -                       sun4i_usb_phy_write(phy, PHY_RES45_CAL_EN, 0x01, 1);
> +       /* Enable USB 45 Ohm resistor calibration */
> +       if (phy->index == 0)
> +               sun4i_usb_phy_write(phy, PHY_RES45_CAL_EN, 0x01, 1);
>
> -               /* Adjust PHY's magnitude and rate */
> -               sun4i_usb_phy_write(phy, PHY_TX_AMPLITUDE_TUNE, 0x14, 5);
> +       /* Adjust PHY's magnitude and rate */
> +       sun4i_usb_phy_write(phy, PHY_TX_AMPLITUDE_TUNE, 0x14, 5);
>
> -               /* Disconnect threshold adjustment */
> -               sun4i_usb_phy_write(phy, PHY_DISCON_TH_SEL,
> -                                   data->cfg->disc_thresh, 2);
> -       }
> +       /* Disconnect threshold adjustment */
> +       sun4i_usb_phy_write(phy, PHY_DISCON_TH_SEL,
> +                           data->cfg->disc_thresh, 2);
>
>         sun4i_usb_phy_passby(phy, 1);
>
> @@ -486,6 +482,26 @@ static const struct phy_ops sun4i_usb_phy_ops = {
>         .owner          = THIS_MODULE,
>  };
>
> +static void sun4i_usb_phy0_reroute(struct sun4i_usb_phy_data *data, int id_det)
> +{
> +       u32 regval;
> +
> +       if (data->dr_mode == USB_DR_MODE_HOST)
> +               id_det = 0; /* Force host */
> +       if (data->dr_mode == USB_DR_MODE_PERIPHERAL)
> +               id_det = 1; /* Force peripheral*/
> +
> +       regval = readl(data->base + REG_PHY_OTGCTL);
> +       if (id_det == 0) {
> +               /* Host mode. Route phy0 to EHCI/OHCI */
> +               regval &= ~OTGCTL_ROUTE_MUSB;
> +       } else {
> +               /* Peripheral mode. Route phy0 to MUSB */
> +               regval |= OTGCTL_ROUTE_MUSB;
> +       }
> +       writel(regval, data->base + REG_PHY_OTGCTL);
> +}
> +
>  static void sun4i_usb_phy0_id_vbus_det_scan(struct work_struct *work)
>  {
>         struct sun4i_usb_phy_data *data =
> @@ -511,6 +527,10 @@ static void sun4i_usb_phy0_id_vbus_det_scan(struct work_struct *work)
>         data->force_session_end = false;
>
>         if (id_det != data->id_det) {
> +               /* Re-route PHY0 if necessary */
> +               if (data->cfg->phy0_dual_route)
> +                       sun4i_usb_phy0_reroute(data, id_det);
> +

Would it make sense to do this after force session end?

ChenYu

>                 /* id-change, force session end if we've no vbus detection */
>                 if (data->dr_mode == USB_DR_MODE_OTG &&
>                     !sun4i_usb_phy0_have_vbus_det(data))
> @@ -700,7 +720,7 @@ static int sun4i_usb_phy_probe(struct platform_device *pdev)
>                         return PTR_ERR(phy->reset);
>                 }
>
> -               if (i) { /* No pmu for usbc0 */
> +               if (i || data->cfg->phy0_dual_route) { /* No pmu for musb */
>                         snprintf(name, sizeof(name), "pmu%d", i);
>                         res = platform_get_resource_byname(pdev,
>                                                         IORESOURCE_MEM, name);
> @@ -825,6 +845,7 @@ static const struct sun4i_usb_phy_cfg sun8i_h3_cfg = {
>         .disc_thresh = 3,
>         .dedicated_clocks = true,
>         .enable_pmu_unk1 = true,
> +       .phy0_dual_route = true,
>  };
>
>  static const struct sun4i_usb_phy_cfg sun8i_v3s_cfg = {
> --
> 2.11.1
>
> --
> You received this message because you are subscribed to the Google Groups "linux-sunxi" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> For more options, visit https://groups.google.com/d/optout.

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

* [linux-sunxi] [PATCH 1/3] phy: sun4i-usb: support automatically switch PHY0 route to MUSB/HCI
@ 2017-02-28 15:42   ` Chen-Yu Tsai
  0 siblings, 0 replies; 24+ messages in thread
From: Chen-Yu Tsai @ 2017-02-28 15:42 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, Feb 28, 2017 at 11:27 PM, Icenowy Zheng <icenowy@aosc.xyz> wrote:
> On newer Allwinner SoCs (H3 and after), the PHY0 node is routed to both
> MUSB controller for peripheral and host support (the host support is
> slightly broken), and a pair of EHCI/OHCI controllers, which provide a
> better support for host mode.
>
> Add support for automatically switch the route of PHY0 according to the
> status of dr_mode and id det pin.
>
> Only H3 have this function enabled in this patch, as further SoCs will
> be tested later and then have it enabled.
>
> Signed-off-by: Icenowy Zheng <icenowy@aosc.xyz>
> ---
>  drivers/phy/phy-sun4i-usb.c | 55 +++++++++++++++++++++++++++++++--------------
>  1 file changed, 38 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/phy/phy-sun4i-usb.c b/drivers/phy/phy-sun4i-usb.c
> index a21b5f24a340..8b91afe8f42d 100644
> --- a/drivers/phy/phy-sun4i-usb.c
> +++ b/drivers/phy/phy-sun4i-usb.c
> @@ -49,12 +49,14 @@
>  #define REG_PHYBIST                    0x08
>  #define REG_PHYTUNE                    0x0c
>  #define REG_PHYCTL_A33                 0x10
> -#define REG_PHY_UNK_H3                 0x20
> +#define REG_PHY_OTGCTL                 0x20
>
>  #define REG_PMU_UNK1                   0x10
>
>  #define PHYCTL_DATA                    BIT(7)
>
> +#define OTGCTL_ROUTE_MUSB              BIT(0)
> +
>  #define SUNXI_AHB_ICHR8_EN             BIT(10)
>  #define SUNXI_AHB_INCR4_BURST_EN       BIT(9)
>  #define SUNXI_AHB_INCRX_ALIGN_EN       BIT(8)
> @@ -110,6 +112,7 @@ struct sun4i_usb_phy_cfg {
>         u8 phyctl_offset;
>         bool dedicated_clocks;
>         bool enable_pmu_unk1;
> +       bool phy0_dual_route;
>  };
>
>  struct sun4i_usb_phy_data {
> @@ -271,23 +274,16 @@ static int sun4i_usb_phy_init(struct phy *_phy)
>                 writel(val & ~2, phy->pmu + REG_PMU_UNK1);
>         }
>
> -       if (data->cfg->type == sun8i_h3_phy) {
> -               if (phy->index == 0) {
> -                       val = readl(data->base + REG_PHY_UNK_H3);
> -                       writel(val & ~1, data->base + REG_PHY_UNK_H3);
> -               }
> -       } else {
> -               /* Enable USB 45 Ohm resistor calibration */
> -               if (phy->index == 0)
> -                       sun4i_usb_phy_write(phy, PHY_RES45_CAL_EN, 0x01, 1);
> +       /* Enable USB 45 Ohm resistor calibration */
> +       if (phy->index == 0)
> +               sun4i_usb_phy_write(phy, PHY_RES45_CAL_EN, 0x01, 1);
>
> -               /* Adjust PHY's magnitude and rate */
> -               sun4i_usb_phy_write(phy, PHY_TX_AMPLITUDE_TUNE, 0x14, 5);
> +       /* Adjust PHY's magnitude and rate */
> +       sun4i_usb_phy_write(phy, PHY_TX_AMPLITUDE_TUNE, 0x14, 5);
>
> -               /* Disconnect threshold adjustment */
> -               sun4i_usb_phy_write(phy, PHY_DISCON_TH_SEL,
> -                                   data->cfg->disc_thresh, 2);
> -       }
> +       /* Disconnect threshold adjustment */
> +       sun4i_usb_phy_write(phy, PHY_DISCON_TH_SEL,
> +                           data->cfg->disc_thresh, 2);
>
>         sun4i_usb_phy_passby(phy, 1);
>
> @@ -486,6 +482,26 @@ static const struct phy_ops sun4i_usb_phy_ops = {
>         .owner          = THIS_MODULE,
>  };
>
> +static void sun4i_usb_phy0_reroute(struct sun4i_usb_phy_data *data, int id_det)
> +{
> +       u32 regval;
> +
> +       if (data->dr_mode == USB_DR_MODE_HOST)
> +               id_det = 0; /* Force host */
> +       if (data->dr_mode == USB_DR_MODE_PERIPHERAL)
> +               id_det = 1; /* Force peripheral*/
> +
> +       regval = readl(data->base + REG_PHY_OTGCTL);
> +       if (id_det == 0) {
> +               /* Host mode. Route phy0 to EHCI/OHCI */
> +               regval &= ~OTGCTL_ROUTE_MUSB;
> +       } else {
> +               /* Peripheral mode. Route phy0 to MUSB */
> +               regval |= OTGCTL_ROUTE_MUSB;
> +       }
> +       writel(regval, data->base + REG_PHY_OTGCTL);
> +}
> +
>  static void sun4i_usb_phy0_id_vbus_det_scan(struct work_struct *work)
>  {
>         struct sun4i_usb_phy_data *data =
> @@ -511,6 +527,10 @@ static void sun4i_usb_phy0_id_vbus_det_scan(struct work_struct *work)
>         data->force_session_end = false;
>
>         if (id_det != data->id_det) {
> +               /* Re-route PHY0 if necessary */
> +               if (data->cfg->phy0_dual_route)
> +                       sun4i_usb_phy0_reroute(data, id_det);
> +

Would it make sense to do this after force session end?

ChenYu

>                 /* id-change, force session end if we've no vbus detection */
>                 if (data->dr_mode == USB_DR_MODE_OTG &&
>                     !sun4i_usb_phy0_have_vbus_det(data))
> @@ -700,7 +720,7 @@ static int sun4i_usb_phy_probe(struct platform_device *pdev)
>                         return PTR_ERR(phy->reset);
>                 }
>
> -               if (i) { /* No pmu for usbc0 */
> +               if (i || data->cfg->phy0_dual_route) { /* No pmu for musb */
>                         snprintf(name, sizeof(name), "pmu%d", i);
>                         res = platform_get_resource_byname(pdev,
>                                                         IORESOURCE_MEM, name);
> @@ -825,6 +845,7 @@ static const struct sun4i_usb_phy_cfg sun8i_h3_cfg = {
>         .disc_thresh = 3,
>         .dedicated_clocks = true,
>         .enable_pmu_unk1 = true,
> +       .phy0_dual_route = true,
>  };
>
>  static const struct sun4i_usb_phy_cfg sun8i_v3s_cfg = {
> --
> 2.11.1
>
> --
> You received this message because you are subscribed to the Google Groups "linux-sunxi" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+unsubscribe at googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

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

* Re: [linux-sunxi] [PATCH 2/3] ARM: dts: sun8i: add usb_otg and OHCI/EHCI for usbc0 on H3
@ 2017-02-28 15:46       ` Chen-Yu Tsai
  0 siblings, 0 replies; 24+ messages in thread
From: Chen-Yu Tsai @ 2017-02-28 15:46 UTC (permalink / raw)
  To: Icenowy Zheng
  Cc: Maxime Ripard, Chen-Yu Tsai, Kishon Vijay Abraham I,
	Hans de Goede, devicetree, linux-arm-kernel, linux-kernel,
	linux-sunxi

On Tue, Feb 28, 2017 at 11:27 PM, Icenowy Zheng <icenowy@aosc.xyz> wrote:
> Allwinner H3 have a dual-routed USB PHY0 -- routed to either OHCI/EHCI
> or MUSB controller.
>
> Add device nodes for these controllers.
>
> Signed-off-by: Icenowy Zheng <icenowy@aosc.xyz>
> ---
>  arch/arm/boot/dts/sun8i-h3.dtsi | 36 ++++++++++++++++++++++++++++++++++++
>  1 file changed, 36 insertions(+)
>
> diff --git a/arch/arm/boot/dts/sun8i-h3.dtsi b/arch/arm/boot/dts/sun8i-h3.dtsi
> index 27780b97c863..bc9a53edf371 100644
> --- a/arch/arm/boot/dts/sun8i-h3.dtsi
> +++ b/arch/arm/boot/dts/sun8i-h3.dtsi
> @@ -206,6 +206,19 @@
>                         #size-cells = <0>;
>                 };
>
> +               usb_otg: usb@01c19000 {
> +                       compatible = "allwinner,sun8i-h3-musb";
> +                       reg = <0x01c19000 0x0400>;
> +                       clocks = <&ccu CLK_BUS_OTG>;
> +                       resets = <&ccu RST_BUS_OTG>;
> +                       interrupts = <GIC_SPI 71 IRQ_TYPE_LEVEL_HIGH>;
> +                       interrupt-names = "mc";
> +                       phys = <&usbphy 0>;
> +                       phy-names = "usb";
> +                       extcon = <&usbphy 0>;
> +                       status = "disabled";
> +               };
> +
>                 usbphy: phy@01c19400 {
>                         compatible = "allwinner,sun8i-h3-usb-phy";
>                         reg = <0x01c19400 0x2c>,
> @@ -238,6 +251,29 @@
>                         #phy-cells = <1>;
>                 };
>
> +               ehci0: usb@01c1a000 {
> +                       compatible = "allwinner,sun8i-h3-ehci", "generic-ehci";
> +                       reg = <0x01c1a000 0x100>;
> +                       interrupts = <GIC_SPI 72 IRQ_TYPE_LEVEL_HIGH>;
> +                       clocks = <&ccu CLK_BUS_EHCI0>, <&ccu CLK_BUS_OHCI0>;
> +                       resets = <&ccu RST_BUS_EHCI0>, <&ccu RST_BUS_OHCI0>;
> +                       phys = <&usbphy 0>;
> +                       phy-names = "usb";

So this bit is slightly concerning. IIRC the xHCI drivers power on the phy when
probed, which means VBUS is _always_ going to be powered on, even when it's
supposed to be in peripheral mode. You're probably going to need to rework
either the phy or the musb driver to cope with this.

Or maybe just dropping the phy handle here and letting the musb driver handle
it would work, but that requires the musb driver be loaded.

ChenYu

> +                       status = "disabled";
> +               };
> +
> +               ohci0: usb@01c1a400 {
> +                       compatible = "allwinner,sun8i-h3-ohci", "generic-ohci";
> +                       reg = <0x01c1a400 0x100>;
> +                       interrupts = <GIC_SPI 73 IRQ_TYPE_LEVEL_HIGH>;
> +                       clocks = <&ccu CLK_BUS_EHCI0>, <&ccu CLK_BUS_OHCI0>,
> +                                <&ccu CLK_USB_OHCI0>;
> +                       resets = <&ccu RST_BUS_EHCI0>, <&ccu RST_BUS_OHCI0>;
> +                       phys = <&usbphy 0>;
> +                       phy-names = "usb";
> +                       status = "disabled";
> +               };
> +
>                 ehci1: usb@01c1b000 {
>                         compatible = "allwinner,sun8i-h3-ehci", "generic-ehci";
>                         reg = <0x01c1b000 0x100>;
> --
> 2.11.1
>
> --
> You received this message because you are subscribed to the Google Groups "linux-sunxi" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+unsubscribe@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

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

* Re: [PATCH 2/3] ARM: dts: sun8i: add usb_otg and OHCI/EHCI for usbc0 on H3
@ 2017-02-28 15:46       ` Chen-Yu Tsai
  0 siblings, 0 replies; 24+ messages in thread
From: Chen-Yu Tsai @ 2017-02-28 15:46 UTC (permalink / raw)
  To: Icenowy Zheng
  Cc: Maxime Ripard, Chen-Yu Tsai, Kishon Vijay Abraham I,
	Hans de Goede, devicetree, linux-arm-kernel, linux-kernel,
	linux-sunxi

On Tue, Feb 28, 2017 at 11:27 PM, Icenowy Zheng <icenowy-ymACFijhrKM@public.gmane.org> wrote:
> Allwinner H3 have a dual-routed USB PHY0 -- routed to either OHCI/EHCI
> or MUSB controller.
>
> Add device nodes for these controllers.
>
> Signed-off-by: Icenowy Zheng <icenowy-ymACFijhrKM@public.gmane.org>
> ---
>  arch/arm/boot/dts/sun8i-h3.dtsi | 36 ++++++++++++++++++++++++++++++++++++
>  1 file changed, 36 insertions(+)
>
> diff --git a/arch/arm/boot/dts/sun8i-h3.dtsi b/arch/arm/boot/dts/sun8i-h3.dtsi
> index 27780b97c863..bc9a53edf371 100644
> --- a/arch/arm/boot/dts/sun8i-h3.dtsi
> +++ b/arch/arm/boot/dts/sun8i-h3.dtsi
> @@ -206,6 +206,19 @@
>                         #size-cells = <0>;
>                 };
>
> +               usb_otg: usb@01c19000 {
> +                       compatible = "allwinner,sun8i-h3-musb";
> +                       reg = <0x01c19000 0x0400>;
> +                       clocks = <&ccu CLK_BUS_OTG>;
> +                       resets = <&ccu RST_BUS_OTG>;
> +                       interrupts = <GIC_SPI 71 IRQ_TYPE_LEVEL_HIGH>;
> +                       interrupt-names = "mc";
> +                       phys = <&usbphy 0>;
> +                       phy-names = "usb";
> +                       extcon = <&usbphy 0>;
> +                       status = "disabled";
> +               };
> +
>                 usbphy: phy@01c19400 {
>                         compatible = "allwinner,sun8i-h3-usb-phy";
>                         reg = <0x01c19400 0x2c>,
> @@ -238,6 +251,29 @@
>                         #phy-cells = <1>;
>                 };
>
> +               ehci0: usb@01c1a000 {
> +                       compatible = "allwinner,sun8i-h3-ehci", "generic-ehci";
> +                       reg = <0x01c1a000 0x100>;
> +                       interrupts = <GIC_SPI 72 IRQ_TYPE_LEVEL_HIGH>;
> +                       clocks = <&ccu CLK_BUS_EHCI0>, <&ccu CLK_BUS_OHCI0>;
> +                       resets = <&ccu RST_BUS_EHCI0>, <&ccu RST_BUS_OHCI0>;
> +                       phys = <&usbphy 0>;
> +                       phy-names = "usb";

So this bit is slightly concerning. IIRC the xHCI drivers power on the phy when
probed, which means VBUS is _always_ going to be powered on, even when it's
supposed to be in peripheral mode. You're probably going to need to rework
either the phy or the musb driver to cope with this.

Or maybe just dropping the phy handle here and letting the musb driver handle
it would work, but that requires the musb driver be loaded.

ChenYu

> +                       status = "disabled";
> +               };
> +
> +               ohci0: usb@01c1a400 {
> +                       compatible = "allwinner,sun8i-h3-ohci", "generic-ohci";
> +                       reg = <0x01c1a400 0x100>;
> +                       interrupts = <GIC_SPI 73 IRQ_TYPE_LEVEL_HIGH>;
> +                       clocks = <&ccu CLK_BUS_EHCI0>, <&ccu CLK_BUS_OHCI0>,
> +                                <&ccu CLK_USB_OHCI0>;
> +                       resets = <&ccu RST_BUS_EHCI0>, <&ccu RST_BUS_OHCI0>;
> +                       phys = <&usbphy 0>;
> +                       phy-names = "usb";
> +                       status = "disabled";
> +               };
> +
>                 ehci1: usb@01c1b000 {
>                         compatible = "allwinner,sun8i-h3-ehci", "generic-ehci";
>                         reg = <0x01c1b000 0x100>;
> --
> 2.11.1
>
> --
> You received this message because you are subscribed to the Google Groups "linux-sunxi" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> For more options, visit https://groups.google.com/d/optout.

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

* [linux-sunxi] [PATCH 2/3] ARM: dts: sun8i: add usb_otg and OHCI/EHCI for usbc0 on H3
@ 2017-02-28 15:46       ` Chen-Yu Tsai
  0 siblings, 0 replies; 24+ messages in thread
From: Chen-Yu Tsai @ 2017-02-28 15:46 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, Feb 28, 2017 at 11:27 PM, Icenowy Zheng <icenowy@aosc.xyz> wrote:
> Allwinner H3 have a dual-routed USB PHY0 -- routed to either OHCI/EHCI
> or MUSB controller.
>
> Add device nodes for these controllers.
>
> Signed-off-by: Icenowy Zheng <icenowy@aosc.xyz>
> ---
>  arch/arm/boot/dts/sun8i-h3.dtsi | 36 ++++++++++++++++++++++++++++++++++++
>  1 file changed, 36 insertions(+)
>
> diff --git a/arch/arm/boot/dts/sun8i-h3.dtsi b/arch/arm/boot/dts/sun8i-h3.dtsi
> index 27780b97c863..bc9a53edf371 100644
> --- a/arch/arm/boot/dts/sun8i-h3.dtsi
> +++ b/arch/arm/boot/dts/sun8i-h3.dtsi
> @@ -206,6 +206,19 @@
>                         #size-cells = <0>;
>                 };
>
> +               usb_otg: usb at 01c19000 {
> +                       compatible = "allwinner,sun8i-h3-musb";
> +                       reg = <0x01c19000 0x0400>;
> +                       clocks = <&ccu CLK_BUS_OTG>;
> +                       resets = <&ccu RST_BUS_OTG>;
> +                       interrupts = <GIC_SPI 71 IRQ_TYPE_LEVEL_HIGH>;
> +                       interrupt-names = "mc";
> +                       phys = <&usbphy 0>;
> +                       phy-names = "usb";
> +                       extcon = <&usbphy 0>;
> +                       status = "disabled";
> +               };
> +
>                 usbphy: phy at 01c19400 {
>                         compatible = "allwinner,sun8i-h3-usb-phy";
>                         reg = <0x01c19400 0x2c>,
> @@ -238,6 +251,29 @@
>                         #phy-cells = <1>;
>                 };
>
> +               ehci0: usb at 01c1a000 {
> +                       compatible = "allwinner,sun8i-h3-ehci", "generic-ehci";
> +                       reg = <0x01c1a000 0x100>;
> +                       interrupts = <GIC_SPI 72 IRQ_TYPE_LEVEL_HIGH>;
> +                       clocks = <&ccu CLK_BUS_EHCI0>, <&ccu CLK_BUS_OHCI0>;
> +                       resets = <&ccu RST_BUS_EHCI0>, <&ccu RST_BUS_OHCI0>;
> +                       phys = <&usbphy 0>;
> +                       phy-names = "usb";

So this bit is slightly concerning. IIRC the xHCI drivers power on the phy when
probed, which means VBUS is _always_ going to be powered on, even when it's
supposed to be in peripheral mode. You're probably going to need to rework
either the phy or the musb driver to cope with this.

Or maybe just dropping the phy handle here and letting the musb driver handle
it would work, but that requires the musb driver be loaded.

ChenYu

> +                       status = "disabled";
> +               };
> +
> +               ohci0: usb at 01c1a400 {
> +                       compatible = "allwinner,sun8i-h3-ohci", "generic-ohci";
> +                       reg = <0x01c1a400 0x100>;
> +                       interrupts = <GIC_SPI 73 IRQ_TYPE_LEVEL_HIGH>;
> +                       clocks = <&ccu CLK_BUS_EHCI0>, <&ccu CLK_BUS_OHCI0>,
> +                                <&ccu CLK_USB_OHCI0>;
> +                       resets = <&ccu RST_BUS_EHCI0>, <&ccu RST_BUS_OHCI0>;
> +                       phys = <&usbphy 0>;
> +                       phy-names = "usb";
> +                       status = "disabled";
> +               };
> +
>                 ehci1: usb at 01c1b000 {
>                         compatible = "allwinner,sun8i-h3-ehci", "generic-ehci";
>                         reg = <0x01c1b000 0x100>;
> --
> 2.11.1
>
> --
> You received this message because you are subscribed to the Google Groups "linux-sunxi" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+unsubscribe at googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

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

* Re: [PATCH 2/3] ARM: dts: sun8i: add usb_otg and OHCI/EHCI for usbc0 on H3
  2017-02-28 15:46       ` Chen-Yu Tsai
@ 2017-02-28 15:57           ` Icenowy Zheng
  -1 siblings, 0 replies; 24+ messages in thread
From: Icenowy Zheng @ 2017-02-28 15:57 UTC (permalink / raw)
  To: wens-jdAy2FN1RRM
  Cc: Maxime Ripard, Kishon Vijay Abraham I, Hans de Goede, devicetree,
	linux-arm-kernel, linux-kernel, linux-sunxi



28.02.2017, 23:46, "Chen-Yu Tsai" <wens-jdAy2FN1RRM@public.gmane.org>:
> On Tue, Feb 28, 2017 at 11:27 PM, Icenowy Zheng <icenowy-ymACFijhrKM@public.gmane.org> wrote:
>>  Allwinner H3 have a dual-routed USB PHY0 -- routed to either OHCI/EHCI
>>  or MUSB controller.
>>
>>  Add device nodes for these controllers.
>>
>>  Signed-off-by: Icenowy Zheng <icenowy-ymACFijhrKM@public.gmane.org>
>>  ---
>>   arch/arm/boot/dts/sun8i-h3.dtsi | 36 ++++++++++++++++++++++++++++++++++++
>>   1 file changed, 36 insertions(+)
>>
>>  diff --git a/arch/arm/boot/dts/sun8i-h3.dtsi b/arch/arm/boot/dts/sun8i-h3.dtsi
>>  index 27780b97c863..bc9a53edf371 100644
>>  --- a/arch/arm/boot/dts/sun8i-h3.dtsi
>>  +++ b/arch/arm/boot/dts/sun8i-h3.dtsi
>>  @@ -206,6 +206,19 @@
>>                          #size-cells = <0>;
>>                  };
>>
>>  + usb_otg: usb@01c19000 {
>>  + compatible = "allwinner,sun8i-h3-musb";
>>  + reg = <0x01c19000 0x0400>;
>>  + clocks = <&ccu CLK_BUS_OTG>;
>>  + resets = <&ccu RST_BUS_OTG>;
>>  + interrupts = <GIC_SPI 71 IRQ_TYPE_LEVEL_HIGH>;
>>  + interrupt-names = "mc";
>>  + phys = <&usbphy 0>;
>>  + phy-names = "usb";
>>  + extcon = <&usbphy 0>;
>>  + status = "disabled";
>>  + };
>>  +
>>                  usbphy: phy@01c19400 {
>>                          compatible = "allwinner,sun8i-h3-usb-phy";
>>                          reg = <0x01c19400 0x2c>,
>>  @@ -238,6 +251,29 @@
>>                          #phy-cells = <1>;
>>                  };
>>
>>  + ehci0: usb@01c1a000 {
>>  + compatible = "allwinner,sun8i-h3-ehci", "generic-ehci";
>>  + reg = <0x01c1a000 0x100>;
>>  + interrupts = <GIC_SPI 72 IRQ_TYPE_LEVEL_HIGH>;
>>  + clocks = <&ccu CLK_BUS_EHCI0>, <&ccu CLK_BUS_OHCI0>;
>>  + resets = <&ccu RST_BUS_EHCI0>, <&ccu RST_BUS_OHCI0>;
>>  + phys = <&usbphy 0>;
>>  + phy-names = "usb";
>
> So this bit is slightly concerning. IIRC the xHCI drivers power on the phy when
> probed, which means VBUS is _always_ going to be powered on, even when it's
> supposed to be in peripheral mode. You're probably going to need to rework
> either the phy or the musb driver to cope with this.
>
> Or maybe just dropping the phy handle here and letting the musb driver handle
> it would work, but that requires the musb driver be loaded.

In fact the MUSB driver is always needed -- to set the dr_mode.

And currently MUSB driver can take over the USB bus even if it's host-only by forcing
its mode in sysfs. 

>
> ChenYu
>
>>  + status = "disabled";
>>  + };
>>  +
>>  + ohci0: usb@01c1a400 {
>>  + compatible = "allwinner,sun8i-h3-ohci", "generic-ohci";
>>  + reg = <0x01c1a400 0x100>;
>>  + interrupts = <GIC_SPI 73 IRQ_TYPE_LEVEL_HIGH>;
>>  + clocks = <&ccu CLK_BUS_EHCI0>, <&ccu CLK_BUS_OHCI0>,
>>  + <&ccu CLK_USB_OHCI0>;
>>  + resets = <&ccu RST_BUS_EHCI0>, <&ccu RST_BUS_OHCI0>;
>>  + phys = <&usbphy 0>;
>>  + phy-names = "usb";
>>  + status = "disabled";
>>  + };
>>  +
>>                  ehci1: usb@01c1b000 {
>>                          compatible = "allwinner,sun8i-h3-ehci", "generic-ehci";
>>                          reg = <0x01c1b000 0x100>;
>>  --
>>  2.11.1
>>
>>  --
>>  You received this message because you are subscribed to the Google Groups "linux-sunxi" group.
>>  To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
>>  For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups "linux-sunxi" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups "linux-sunxi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit https://groups.google.com/d/optout.

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

* [linux-sunxi] [PATCH 2/3] ARM: dts: sun8i: add usb_otg and OHCI/EHCI for usbc0 on H3
@ 2017-02-28 15:57           ` Icenowy Zheng
  0 siblings, 0 replies; 24+ messages in thread
From: Icenowy Zheng @ 2017-02-28 15:57 UTC (permalink / raw)
  To: linux-arm-kernel



28.02.2017, 23:46, "Chen-Yu Tsai" <wens@csie.org>:
> On Tue, Feb 28, 2017 at 11:27 PM, Icenowy Zheng <icenowy@aosc.xyz> wrote:
>> ?Allwinner H3 have a dual-routed USB PHY0 -- routed to either OHCI/EHCI
>> ?or MUSB controller.
>>
>> ?Add device nodes for these controllers.
>>
>> ?Signed-off-by: Icenowy Zheng <icenowy@aosc.xyz>
>> ?---
>> ??arch/arm/boot/dts/sun8i-h3.dtsi | 36 ++++++++++++++++++++++++++++++++++++
>> ??1 file changed, 36 insertions(+)
>>
>> ?diff --git a/arch/arm/boot/dts/sun8i-h3.dtsi b/arch/arm/boot/dts/sun8i-h3.dtsi
>> ?index 27780b97c863..bc9a53edf371 100644
>> ?--- a/arch/arm/boot/dts/sun8i-h3.dtsi
>> ?+++ b/arch/arm/boot/dts/sun8i-h3.dtsi
>> ?@@ -206,6 +206,19 @@
>> ?????????????????????????#size-cells = <0>;
>> ?????????????????};
>>
>> ?+ usb_otg: usb at 01c19000 {
>> ?+ compatible = "allwinner,sun8i-h3-musb";
>> ?+ reg = <0x01c19000 0x0400>;
>> ?+ clocks = <&ccu CLK_BUS_OTG>;
>> ?+ resets = <&ccu RST_BUS_OTG>;
>> ?+ interrupts = <GIC_SPI 71 IRQ_TYPE_LEVEL_HIGH>;
>> ?+ interrupt-names = "mc";
>> ?+ phys = <&usbphy 0>;
>> ?+ phy-names = "usb";
>> ?+ extcon = <&usbphy 0>;
>> ?+ status = "disabled";
>> ?+ };
>> ?+
>> ?????????????????usbphy: phy at 01c19400 {
>> ?????????????????????????compatible = "allwinner,sun8i-h3-usb-phy";
>> ?????????????????????????reg = <0x01c19400 0x2c>,
>> ?@@ -238,6 +251,29 @@
>> ?????????????????????????#phy-cells = <1>;
>> ?????????????????};
>>
>> ?+ ehci0: usb at 01c1a000 {
>> ?+ compatible = "allwinner,sun8i-h3-ehci", "generic-ehci";
>> ?+ reg = <0x01c1a000 0x100>;
>> ?+ interrupts = <GIC_SPI 72 IRQ_TYPE_LEVEL_HIGH>;
>> ?+ clocks = <&ccu CLK_BUS_EHCI0>, <&ccu CLK_BUS_OHCI0>;
>> ?+ resets = <&ccu RST_BUS_EHCI0>, <&ccu RST_BUS_OHCI0>;
>> ?+ phys = <&usbphy 0>;
>> ?+ phy-names = "usb";
>
> So this bit is slightly concerning. IIRC the xHCI drivers power on the phy when
> probed, which means VBUS is _always_ going to be powered on, even when it's
> supposed to be in peripheral mode. You're probably going to need to rework
> either the phy or the musb driver to cope with this.
>
> Or maybe just dropping the phy handle here and letting the musb driver handle
> it would work, but that requires the musb driver be loaded.

In fact the MUSB driver is always needed -- to set the dr_mode.

And currently MUSB driver can take over the USB bus even if it's host-only by forcing
its mode in sysfs. 

>
> ChenYu
>
>> ?+ status = "disabled";
>> ?+ };
>> ?+
>> ?+ ohci0: usb at 01c1a400 {
>> ?+ compatible = "allwinner,sun8i-h3-ohci", "generic-ohci";
>> ?+ reg = <0x01c1a400 0x100>;
>> ?+ interrupts = <GIC_SPI 73 IRQ_TYPE_LEVEL_HIGH>;
>> ?+ clocks = <&ccu CLK_BUS_EHCI0>, <&ccu CLK_BUS_OHCI0>,
>> ?+ <&ccu CLK_USB_OHCI0>;
>> ?+ resets = <&ccu RST_BUS_EHCI0>, <&ccu RST_BUS_OHCI0>;
>> ?+ phys = <&usbphy 0>;
>> ?+ phy-names = "usb";
>> ?+ status = "disabled";
>> ?+ };
>> ?+
>> ?????????????????ehci1: usb at 01c1b000 {
>> ?????????????????????????compatible = "allwinner,sun8i-h3-ehci", "generic-ehci";
>> ?????????????????????????reg = <0x01c1b000 0x100>;
>> ?--
>> ?2.11.1
>>
>> ?--
>> ?You received this message because you are subscribed to the Google Groups "linux-sunxi" group.
>> ?To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+unsubscribe at googlegroups.com.
>> ?For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups "linux-sunxi" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+unsubscribe at googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

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

* Re: [PATCH 2/3] ARM: dts: sun8i: add usb_otg and OHCI/EHCI for usbc0 on H3
  2017-02-28 15:46       ` Chen-Yu Tsai
@ 2017-02-28 16:07           ` Icenowy Zheng
  -1 siblings, 0 replies; 24+ messages in thread
From: Icenowy Zheng @ 2017-02-28 16:07 UTC (permalink / raw)
  To: wens-jdAy2FN1RRM
  Cc: Maxime Ripard, Kishon Vijay Abraham I, Hans de Goede, devicetree,
	linux-arm-kernel, linux-kernel, linux-sunxi



28.02.2017, 23:46, "Chen-Yu Tsai" <wens-jdAy2FN1RRM@public.gmane.org>:
> On Tue, Feb 28, 2017 at 11:27 PM, Icenowy Zheng <icenowy-ymACFijhrKM@public.gmane.org> wrote:
>>  Allwinner H3 have a dual-routed USB PHY0 -- routed to either OHCI/EHCI
>>  or MUSB controller.
>>
>>  Add device nodes for these controllers.
>>
>>  Signed-off-by: Icenowy Zheng <icenowy-ymACFijhrKM@public.gmane.org>
>>  ---
>>   arch/arm/boot/dts/sun8i-h3.dtsi | 36 ++++++++++++++++++++++++++++++++++++
>>   1 file changed, 36 insertions(+)
>>
>>  diff --git a/arch/arm/boot/dts/sun8i-h3.dtsi b/arch/arm/boot/dts/sun8i-h3.dtsi
>>  index 27780b97c863..bc9a53edf371 100644
>>  --- a/arch/arm/boot/dts/sun8i-h3.dtsi
>>  +++ b/arch/arm/boot/dts/sun8i-h3.dtsi
>>  @@ -206,6 +206,19 @@
>>                          #size-cells = <0>;
>>                  };
>>
>>  + usb_otg: usb@01c19000 {
>>  + compatible = "allwinner,sun8i-h3-musb";
>>  + reg = <0x01c19000 0x0400>;
>>  + clocks = <&ccu CLK_BUS_OTG>;
>>  + resets = <&ccu RST_BUS_OTG>;
>>  + interrupts = <GIC_SPI 71 IRQ_TYPE_LEVEL_HIGH>;
>>  + interrupt-names = "mc";
>>  + phys = <&usbphy 0>;
>>  + phy-names = "usb";
>>  + extcon = <&usbphy 0>;
>>  + status = "disabled";
>>  + };
>>  +
>>                  usbphy: phy@01c19400 {
>>                          compatible = "allwinner,sun8i-h3-usb-phy";
>>                          reg = <0x01c19400 0x2c>,
>>  @@ -238,6 +251,29 @@
>>                          #phy-cells = <1>;
>>                  };
>>
>>  + ehci0: usb@01c1a000 {
>>  + compatible = "allwinner,sun8i-h3-ehci", "generic-ehci";
>>  + reg = <0x01c1a000 0x100>;
>>  + interrupts = <GIC_SPI 72 IRQ_TYPE_LEVEL_HIGH>;
>>  + clocks = <&ccu CLK_BUS_EHCI0>, <&ccu CLK_BUS_OHCI0>;
>>  + resets = <&ccu RST_BUS_EHCI0>, <&ccu RST_BUS_OHCI0>;
>>  + phys = <&usbphy 0>;
>>  + phy-names = "usb";
>
> So this bit is slightly concerning. IIRC the xHCI drivers power on the phy when
> probed, which means VBUS is _always_ going to be powered on, even when it's
> supposed to be in peripheral mode. You're probably going to need to rework
> either the phy or the musb driver to cope with this.
>
> Or maybe just dropping the phy handle here and letting the musb driver handle
> it would work, but that requires the musb driver be loaded.

Tested this solution.

I may choose it in the next version.

Hans, how do you think of this solution?

>
> ChenYu
>
>>  + status = "disabled";
>>  + };
>>  +
>>  + ohci0: usb@01c1a400 {
>>  + compatible = "allwinner,sun8i-h3-ohci", "generic-ohci";
>>  + reg = <0x01c1a400 0x100>;
>>  + interrupts = <GIC_SPI 73 IRQ_TYPE_LEVEL_HIGH>;
>>  + clocks = <&ccu CLK_BUS_EHCI0>, <&ccu CLK_BUS_OHCI0>,
>>  + <&ccu CLK_USB_OHCI0>;
>>  + resets = <&ccu RST_BUS_EHCI0>, <&ccu RST_BUS_OHCI0>;
>>  + phys = <&usbphy 0>;
>>  + phy-names = "usb";
>>  + status = "disabled";
>>  + };
>>  +
>>                  ehci1: usb@01c1b000 {
>>                          compatible = "allwinner,sun8i-h3-ehci", "generic-ehci";
>>                          reg = <0x01c1b000 0x100>;
>>  --
>>  2.11.1
>>
>>  --
>>  You received this message because you are subscribed to the Google Groups "linux-sunxi" group.
>>  To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
>>  For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups "linux-sunxi" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups "linux-sunxi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit https://groups.google.com/d/optout.

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

* [linux-sunxi] [PATCH 2/3] ARM: dts: sun8i: add usb_otg and OHCI/EHCI for usbc0 on H3
@ 2017-02-28 16:07           ` Icenowy Zheng
  0 siblings, 0 replies; 24+ messages in thread
From: Icenowy Zheng @ 2017-02-28 16:07 UTC (permalink / raw)
  To: linux-arm-kernel



28.02.2017, 23:46, "Chen-Yu Tsai" <wens@csie.org>:
> On Tue, Feb 28, 2017 at 11:27 PM, Icenowy Zheng <icenowy@aosc.xyz> wrote:
>> ?Allwinner H3 have a dual-routed USB PHY0 -- routed to either OHCI/EHCI
>> ?or MUSB controller.
>>
>> ?Add device nodes for these controllers.
>>
>> ?Signed-off-by: Icenowy Zheng <icenowy@aosc.xyz>
>> ?---
>> ??arch/arm/boot/dts/sun8i-h3.dtsi | 36 ++++++++++++++++++++++++++++++++++++
>> ??1 file changed, 36 insertions(+)
>>
>> ?diff --git a/arch/arm/boot/dts/sun8i-h3.dtsi b/arch/arm/boot/dts/sun8i-h3.dtsi
>> ?index 27780b97c863..bc9a53edf371 100644
>> ?--- a/arch/arm/boot/dts/sun8i-h3.dtsi
>> ?+++ b/arch/arm/boot/dts/sun8i-h3.dtsi
>> ?@@ -206,6 +206,19 @@
>> ?????????????????????????#size-cells = <0>;
>> ?????????????????};
>>
>> ?+ usb_otg: usb at 01c19000 {
>> ?+ compatible = "allwinner,sun8i-h3-musb";
>> ?+ reg = <0x01c19000 0x0400>;
>> ?+ clocks = <&ccu CLK_BUS_OTG>;
>> ?+ resets = <&ccu RST_BUS_OTG>;
>> ?+ interrupts = <GIC_SPI 71 IRQ_TYPE_LEVEL_HIGH>;
>> ?+ interrupt-names = "mc";
>> ?+ phys = <&usbphy 0>;
>> ?+ phy-names = "usb";
>> ?+ extcon = <&usbphy 0>;
>> ?+ status = "disabled";
>> ?+ };
>> ?+
>> ?????????????????usbphy: phy at 01c19400 {
>> ?????????????????????????compatible = "allwinner,sun8i-h3-usb-phy";
>> ?????????????????????????reg = <0x01c19400 0x2c>,
>> ?@@ -238,6 +251,29 @@
>> ?????????????????????????#phy-cells = <1>;
>> ?????????????????};
>>
>> ?+ ehci0: usb at 01c1a000 {
>> ?+ compatible = "allwinner,sun8i-h3-ehci", "generic-ehci";
>> ?+ reg = <0x01c1a000 0x100>;
>> ?+ interrupts = <GIC_SPI 72 IRQ_TYPE_LEVEL_HIGH>;
>> ?+ clocks = <&ccu CLK_BUS_EHCI0>, <&ccu CLK_BUS_OHCI0>;
>> ?+ resets = <&ccu RST_BUS_EHCI0>, <&ccu RST_BUS_OHCI0>;
>> ?+ phys = <&usbphy 0>;
>> ?+ phy-names = "usb";
>
> So this bit is slightly concerning. IIRC the xHCI drivers power on the phy when
> probed, which means VBUS is _always_ going to be powered on, even when it's
> supposed to be in peripheral mode. You're probably going to need to rework
> either the phy or the musb driver to cope with this.
>
> Or maybe just dropping the phy handle here and letting the musb driver handle
> it would work, but that requires the musb driver be loaded.

Tested this solution.

I may choose it in the next version.

Hans, how do you think of this solution?

>
> ChenYu
>
>> ?+ status = "disabled";
>> ?+ };
>> ?+
>> ?+ ohci0: usb at 01c1a400 {
>> ?+ compatible = "allwinner,sun8i-h3-ohci", "generic-ohci";
>> ?+ reg = <0x01c1a400 0x100>;
>> ?+ interrupts = <GIC_SPI 73 IRQ_TYPE_LEVEL_HIGH>;
>> ?+ clocks = <&ccu CLK_BUS_EHCI0>, <&ccu CLK_BUS_OHCI0>,
>> ?+ <&ccu CLK_USB_OHCI0>;
>> ?+ resets = <&ccu RST_BUS_EHCI0>, <&ccu RST_BUS_OHCI0>;
>> ?+ phys = <&usbphy 0>;
>> ?+ phy-names = "usb";
>> ?+ status = "disabled";
>> ?+ };
>> ?+
>> ?????????????????ehci1: usb at 01c1b000 {
>> ?????????????????????????compatible = "allwinner,sun8i-h3-ehci", "generic-ehci";
>> ?????????????????????????reg = <0x01c1b000 0x100>;
>> ?--
>> ?2.11.1
>>
>> ?--
>> ?You received this message because you are subscribed to the Google Groups "linux-sunxi" group.
>> ?To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+unsubscribe at googlegroups.com.
>> ?For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups "linux-sunxi" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+unsubscribe at googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

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

* Re: [linux-sunxi] [PATCH 2/3] ARM: dts: sun8i: add usb_otg and OHCI/EHCI for usbc0 on H3
@ 2017-02-28 16:10             ` Chen-Yu Tsai
  0 siblings, 0 replies; 24+ messages in thread
From: Chen-Yu Tsai @ 2017-02-28 16:10 UTC (permalink / raw)
  To: Icenowy Zheng
  Cc: wens, Maxime Ripard, Kishon Vijay Abraham I, Hans de Goede,
	devicetree, linux-arm-kernel, linux-kernel, linux-sunxi

On Tue, Feb 28, 2017 at 11:57 PM, Icenowy Zheng <icenowy@aosc.xyz> wrote:
>
>
> 28.02.2017, 23:46, "Chen-Yu Tsai" <wens@csie.org>:
>> On Tue, Feb 28, 2017 at 11:27 PM, Icenowy Zheng <icenowy@aosc.xyz> wrote:
>>>  Allwinner H3 have a dual-routed USB PHY0 -- routed to either OHCI/EHCI
>>>  or MUSB controller.
>>>
>>>  Add device nodes for these controllers.
>>>
>>>  Signed-off-by: Icenowy Zheng <icenowy@aosc.xyz>
>>>  ---
>>>   arch/arm/boot/dts/sun8i-h3.dtsi | 36 ++++++++++++++++++++++++++++++++++++
>>>   1 file changed, 36 insertions(+)
>>>
>>>  diff --git a/arch/arm/boot/dts/sun8i-h3.dtsi b/arch/arm/boot/dts/sun8i-h3.dtsi
>>>  index 27780b97c863..bc9a53edf371 100644
>>>  --- a/arch/arm/boot/dts/sun8i-h3.dtsi
>>>  +++ b/arch/arm/boot/dts/sun8i-h3.dtsi
>>>  @@ -206,6 +206,19 @@
>>>                          #size-cells = <0>;
>>>                  };
>>>
>>>  + usb_otg: usb@01c19000 {
>>>  + compatible = "allwinner,sun8i-h3-musb";
>>>  + reg = <0x01c19000 0x0400>;
>>>  + clocks = <&ccu CLK_BUS_OTG>;
>>>  + resets = <&ccu RST_BUS_OTG>;
>>>  + interrupts = <GIC_SPI 71 IRQ_TYPE_LEVEL_HIGH>;
>>>  + interrupt-names = "mc";
>>>  + phys = <&usbphy 0>;
>>>  + phy-names = "usb";
>>>  + extcon = <&usbphy 0>;
>>>  + status = "disabled";
>>>  + };
>>>  +
>>>                  usbphy: phy@01c19400 {
>>>                          compatible = "allwinner,sun8i-h3-usb-phy";
>>>                          reg = <0x01c19400 0x2c>,
>>>  @@ -238,6 +251,29 @@
>>>                          #phy-cells = <1>;
>>>                  };
>>>
>>>  + ehci0: usb@01c1a000 {
>>>  + compatible = "allwinner,sun8i-h3-ehci", "generic-ehci";
>>>  + reg = <0x01c1a000 0x100>;
>>>  + interrupts = <GIC_SPI 72 IRQ_TYPE_LEVEL_HIGH>;
>>>  + clocks = <&ccu CLK_BUS_EHCI0>, <&ccu CLK_BUS_OHCI0>;
>>>  + resets = <&ccu RST_BUS_EHCI0>, <&ccu RST_BUS_OHCI0>;
>>>  + phys = <&usbphy 0>;
>>>  + phy-names = "usb";
>>
>> So this bit is slightly concerning. IIRC the xHCI drivers power on the phy when
>> probed, which means VBUS is _always_ going to be powered on, even when it's
>> supposed to be in peripheral mode. You're probably going to need to rework
>> either the phy or the musb driver to cope with this.
>>
>> Or maybe just dropping the phy handle here and letting the musb driver handle
>> it would work, but that requires the musb driver be loaded.
>
> In fact the MUSB driver is always needed -- to set the dr_mode.

I guess it's the same with DWC2/3 that have host controller pairs.

> And currently MUSB driver can take over the USB bus even if it's host-only by forcing
> its mode in sysfs.

IIUC that would also switch the phy muxing over to the HCI pairs.

ChenYu

>>
>> ChenYu
>>
>>>  + status = "disabled";
>>>  + };
>>>  +
>>>  + ohci0: usb@01c1a400 {
>>>  + compatible = "allwinner,sun8i-h3-ohci", "generic-ohci";
>>>  + reg = <0x01c1a400 0x100>;
>>>  + interrupts = <GIC_SPI 73 IRQ_TYPE_LEVEL_HIGH>;
>>>  + clocks = <&ccu CLK_BUS_EHCI0>, <&ccu CLK_BUS_OHCI0>,
>>>  + <&ccu CLK_USB_OHCI0>;
>>>  + resets = <&ccu RST_BUS_EHCI0>, <&ccu RST_BUS_OHCI0>;
>>>  + phys = <&usbphy 0>;
>>>  + phy-names = "usb";
>>>  + status = "disabled";
>>>  + };
>>>  +
>>>                  ehci1: usb@01c1b000 {
>>>                          compatible = "allwinner,sun8i-h3-ehci", "generic-ehci";
>>>                          reg = <0x01c1b000 0x100>;
>>>  --
>>>  2.11.1
>>>
>>>  --
>>>  You received this message because you are subscribed to the Google Groups "linux-sunxi" group.
>>>  To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+unsubscribe@googlegroups.com.
>>>  For more options, visit https://groups.google.com/d/optout.
>>
>> --
>> You received this message because you are subscribed to the Google Groups "linux-sunxi" group.
>> To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+unsubscribe@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups "linux-sunxi" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+unsubscribe@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

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

* Re: [PATCH 2/3] ARM: dts: sun8i: add usb_otg and OHCI/EHCI for usbc0 on H3
@ 2017-02-28 16:10             ` Chen-Yu Tsai
  0 siblings, 0 replies; 24+ messages in thread
From: Chen-Yu Tsai @ 2017-02-28 16:10 UTC (permalink / raw)
  To: Icenowy Zheng
  Cc: wens-jdAy2FN1RRM, Maxime Ripard, Kishon Vijay Abraham I,
	Hans de Goede, devicetree, linux-arm-kernel, linux-kernel,
	linux-sunxi

On Tue, Feb 28, 2017 at 11:57 PM, Icenowy Zheng <icenowy-ymACFijhrKM@public.gmane.org> wrote:
>
>
> 28.02.2017, 23:46, "Chen-Yu Tsai" <wens-jdAy2FN1RRM@public.gmane.org>:
>> On Tue, Feb 28, 2017 at 11:27 PM, Icenowy Zheng <icenowy-ymACFijhrKM@public.gmane.org> wrote:
>>>  Allwinner H3 have a dual-routed USB PHY0 -- routed to either OHCI/EHCI
>>>  or MUSB controller.
>>>
>>>  Add device nodes for these controllers.
>>>
>>>  Signed-off-by: Icenowy Zheng <icenowy-ymACFijhrKM@public.gmane.org>
>>>  ---
>>>   arch/arm/boot/dts/sun8i-h3.dtsi | 36 ++++++++++++++++++++++++++++++++++++
>>>   1 file changed, 36 insertions(+)
>>>
>>>  diff --git a/arch/arm/boot/dts/sun8i-h3.dtsi b/arch/arm/boot/dts/sun8i-h3.dtsi
>>>  index 27780b97c863..bc9a53edf371 100644
>>>  --- a/arch/arm/boot/dts/sun8i-h3.dtsi
>>>  +++ b/arch/arm/boot/dts/sun8i-h3.dtsi
>>>  @@ -206,6 +206,19 @@
>>>                          #size-cells = <0>;
>>>                  };
>>>
>>>  + usb_otg: usb@01c19000 {
>>>  + compatible = "allwinner,sun8i-h3-musb";
>>>  + reg = <0x01c19000 0x0400>;
>>>  + clocks = <&ccu CLK_BUS_OTG>;
>>>  + resets = <&ccu RST_BUS_OTG>;
>>>  + interrupts = <GIC_SPI 71 IRQ_TYPE_LEVEL_HIGH>;
>>>  + interrupt-names = "mc";
>>>  + phys = <&usbphy 0>;
>>>  + phy-names = "usb";
>>>  + extcon = <&usbphy 0>;
>>>  + status = "disabled";
>>>  + };
>>>  +
>>>                  usbphy: phy@01c19400 {
>>>                          compatible = "allwinner,sun8i-h3-usb-phy";
>>>                          reg = <0x01c19400 0x2c>,
>>>  @@ -238,6 +251,29 @@
>>>                          #phy-cells = <1>;
>>>                  };
>>>
>>>  + ehci0: usb@01c1a000 {
>>>  + compatible = "allwinner,sun8i-h3-ehci", "generic-ehci";
>>>  + reg = <0x01c1a000 0x100>;
>>>  + interrupts = <GIC_SPI 72 IRQ_TYPE_LEVEL_HIGH>;
>>>  + clocks = <&ccu CLK_BUS_EHCI0>, <&ccu CLK_BUS_OHCI0>;
>>>  + resets = <&ccu RST_BUS_EHCI0>, <&ccu RST_BUS_OHCI0>;
>>>  + phys = <&usbphy 0>;
>>>  + phy-names = "usb";
>>
>> So this bit is slightly concerning. IIRC the xHCI drivers power on the phy when
>> probed, which means VBUS is _always_ going to be powered on, even when it's
>> supposed to be in peripheral mode. You're probably going to need to rework
>> either the phy or the musb driver to cope with this.
>>
>> Or maybe just dropping the phy handle here and letting the musb driver handle
>> it would work, but that requires the musb driver be loaded.
>
> In fact the MUSB driver is always needed -- to set the dr_mode.

I guess it's the same with DWC2/3 that have host controller pairs.

> And currently MUSB driver can take over the USB bus even if it's host-only by forcing
> its mode in sysfs.

IIUC that would also switch the phy muxing over to the HCI pairs.

ChenYu

>>
>> ChenYu
>>
>>>  + status = "disabled";
>>>  + };
>>>  +
>>>  + ohci0: usb@01c1a400 {
>>>  + compatible = "allwinner,sun8i-h3-ohci", "generic-ohci";
>>>  + reg = <0x01c1a400 0x100>;
>>>  + interrupts = <GIC_SPI 73 IRQ_TYPE_LEVEL_HIGH>;
>>>  + clocks = <&ccu CLK_BUS_EHCI0>, <&ccu CLK_BUS_OHCI0>,
>>>  + <&ccu CLK_USB_OHCI0>;
>>>  + resets = <&ccu RST_BUS_EHCI0>, <&ccu RST_BUS_OHCI0>;
>>>  + phys = <&usbphy 0>;
>>>  + phy-names = "usb";
>>>  + status = "disabled";
>>>  + };
>>>  +
>>>                  ehci1: usb@01c1b000 {
>>>                          compatible = "allwinner,sun8i-h3-ehci", "generic-ehci";
>>>                          reg = <0x01c1b000 0x100>;
>>>  --
>>>  2.11.1
>>>
>>>  --
>>>  You received this message because you are subscribed to the Google Groups "linux-sunxi" group.
>>>  To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
>>>  For more options, visit https://groups.google.com/d/optout.
>>
>> --
>> You received this message because you are subscribed to the Google Groups "linux-sunxi" group.
>> To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
>> For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups "linux-sunxi" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> For more options, visit https://groups.google.com/d/optout.

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

* [linux-sunxi] [PATCH 2/3] ARM: dts: sun8i: add usb_otg and OHCI/EHCI for usbc0 on H3
@ 2017-02-28 16:10             ` Chen-Yu Tsai
  0 siblings, 0 replies; 24+ messages in thread
From: Chen-Yu Tsai @ 2017-02-28 16:10 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, Feb 28, 2017 at 11:57 PM, Icenowy Zheng <icenowy@aosc.xyz> wrote:
>
>
> 28.02.2017, 23:46, "Chen-Yu Tsai" <wens@csie.org>:
>> On Tue, Feb 28, 2017 at 11:27 PM, Icenowy Zheng <icenowy@aosc.xyz> wrote:
>>>  Allwinner H3 have a dual-routed USB PHY0 -- routed to either OHCI/EHCI
>>>  or MUSB controller.
>>>
>>>  Add device nodes for these controllers.
>>>
>>>  Signed-off-by: Icenowy Zheng <icenowy@aosc.xyz>
>>>  ---
>>>   arch/arm/boot/dts/sun8i-h3.dtsi | 36 ++++++++++++++++++++++++++++++++++++
>>>   1 file changed, 36 insertions(+)
>>>
>>>  diff --git a/arch/arm/boot/dts/sun8i-h3.dtsi b/arch/arm/boot/dts/sun8i-h3.dtsi
>>>  index 27780b97c863..bc9a53edf371 100644
>>>  --- a/arch/arm/boot/dts/sun8i-h3.dtsi
>>>  +++ b/arch/arm/boot/dts/sun8i-h3.dtsi
>>>  @@ -206,6 +206,19 @@
>>>                          #size-cells = <0>;
>>>                  };
>>>
>>>  + usb_otg: usb at 01c19000 {
>>>  + compatible = "allwinner,sun8i-h3-musb";
>>>  + reg = <0x01c19000 0x0400>;
>>>  + clocks = <&ccu CLK_BUS_OTG>;
>>>  + resets = <&ccu RST_BUS_OTG>;
>>>  + interrupts = <GIC_SPI 71 IRQ_TYPE_LEVEL_HIGH>;
>>>  + interrupt-names = "mc";
>>>  + phys = <&usbphy 0>;
>>>  + phy-names = "usb";
>>>  + extcon = <&usbphy 0>;
>>>  + status = "disabled";
>>>  + };
>>>  +
>>>                  usbphy: phy at 01c19400 {
>>>                          compatible = "allwinner,sun8i-h3-usb-phy";
>>>                          reg = <0x01c19400 0x2c>,
>>>  @@ -238,6 +251,29 @@
>>>                          #phy-cells = <1>;
>>>                  };
>>>
>>>  + ehci0: usb at 01c1a000 {
>>>  + compatible = "allwinner,sun8i-h3-ehci", "generic-ehci";
>>>  + reg = <0x01c1a000 0x100>;
>>>  + interrupts = <GIC_SPI 72 IRQ_TYPE_LEVEL_HIGH>;
>>>  + clocks = <&ccu CLK_BUS_EHCI0>, <&ccu CLK_BUS_OHCI0>;
>>>  + resets = <&ccu RST_BUS_EHCI0>, <&ccu RST_BUS_OHCI0>;
>>>  + phys = <&usbphy 0>;
>>>  + phy-names = "usb";
>>
>> So this bit is slightly concerning. IIRC the xHCI drivers power on the phy when
>> probed, which means VBUS is _always_ going to be powered on, even when it's
>> supposed to be in peripheral mode. You're probably going to need to rework
>> either the phy or the musb driver to cope with this.
>>
>> Or maybe just dropping the phy handle here and letting the musb driver handle
>> it would work, but that requires the musb driver be loaded.
>
> In fact the MUSB driver is always needed -- to set the dr_mode.

I guess it's the same with DWC2/3 that have host controller pairs.

> And currently MUSB driver can take over the USB bus even if it's host-only by forcing
> its mode in sysfs.

IIUC that would also switch the phy muxing over to the HCI pairs.

ChenYu

>>
>> ChenYu
>>
>>>  + status = "disabled";
>>>  + };
>>>  +
>>>  + ohci0: usb at 01c1a400 {
>>>  + compatible = "allwinner,sun8i-h3-ohci", "generic-ohci";
>>>  + reg = <0x01c1a400 0x100>;
>>>  + interrupts = <GIC_SPI 73 IRQ_TYPE_LEVEL_HIGH>;
>>>  + clocks = <&ccu CLK_BUS_EHCI0>, <&ccu CLK_BUS_OHCI0>,
>>>  + <&ccu CLK_USB_OHCI0>;
>>>  + resets = <&ccu RST_BUS_EHCI0>, <&ccu RST_BUS_OHCI0>;
>>>  + phys = <&usbphy 0>;
>>>  + phy-names = "usb";
>>>  + status = "disabled";
>>>  + };
>>>  +
>>>                  ehci1: usb at 01c1b000 {
>>>                          compatible = "allwinner,sun8i-h3-ehci", "generic-ehci";
>>>                          reg = <0x01c1b000 0x100>;
>>>  --
>>>  2.11.1
>>>
>>>  --
>>>  You received this message because you are subscribed to the Google Groups "linux-sunxi" group.
>>>  To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+unsubscribe at googlegroups.com.
>>>  For more options, visit https://groups.google.com/d/optout.
>>
>> --
>> You received this message because you are subscribed to the Google Groups "linux-sunxi" group.
>> To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+unsubscribe at googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups "linux-sunxi" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+unsubscribe at googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

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

* Re: [PATCH 2/3] ARM: dts: sun8i: add usb_otg and OHCI/EHCI for usbc0 on H3
  2017-02-28 16:10             ` Chen-Yu Tsai
@ 2017-02-28 16:23                 ` Icenowy Zheng
  -1 siblings, 0 replies; 24+ messages in thread
From: Icenowy Zheng @ 2017-02-28 16:23 UTC (permalink / raw)
  To: wens-jdAy2FN1RRM
  Cc: Maxime Ripard, Kishon Vijay Abraham I, Hans de Goede, devicetree,
	linux-arm-kernel, linux-kernel, linux-sunxi



01.03.2017, 00:10, "Chen-Yu Tsai" <wens-jdAy2FN1RRM@public.gmane.org>:
> On Tue, Feb 28, 2017 at 11:57 PM, Icenowy Zheng <icenowy-ymACFijhrKM@public.gmane.org> wrote:
>>  28.02.2017, 23:46, "Chen-Yu Tsai" <wens-jdAy2FN1RRM@public.gmane.org>:
>>>  On Tue, Feb 28, 2017 at 11:27 PM, Icenowy Zheng <icenowy-ymACFijhrKM@public.gmane.org> wrote:
>>>>   Allwinner H3 have a dual-routed USB PHY0 -- routed to either OHCI/EHCI
>>>>   or MUSB controller.
>>>>
>>>>   Add device nodes for these controllers.
>>>>
>>>>   Signed-off-by: Icenowy Zheng <icenowy-ymACFijhrKM@public.gmane.org>
>>>>   ---
>>>>    arch/arm/boot/dts/sun8i-h3.dtsi | 36 ++++++++++++++++++++++++++++++++++++
>>>>    1 file changed, 36 insertions(+)
>>>>
>>>>   diff --git a/arch/arm/boot/dts/sun8i-h3.dtsi b/arch/arm/boot/dts/sun8i-h3.dtsi
>>>>   index 27780b97c863..bc9a53edf371 100644
>>>>   --- a/arch/arm/boot/dts/sun8i-h3.dtsi
>>>>   +++ b/arch/arm/boot/dts/sun8i-h3.dtsi
>>>>   @@ -206,6 +206,19 @@
>>>>                           #size-cells = <0>;
>>>>                   };
>>>>
>>>>   + usb_otg: usb@01c19000 {
>>>>   + compatible = "allwinner,sun8i-h3-musb";
>>>>   + reg = <0x01c19000 0x0400>;
>>>>   + clocks = <&ccu CLK_BUS_OTG>;
>>>>   + resets = <&ccu RST_BUS_OTG>;
>>>>   + interrupts = <GIC_SPI 71 IRQ_TYPE_LEVEL_HIGH>;
>>>>   + interrupt-names = "mc";
>>>>   + phys = <&usbphy 0>;
>>>>   + phy-names = "usb";
>>>>   + extcon = <&usbphy 0>;
>>>>   + status = "disabled";
>>>>   + };
>>>>   +
>>>>                   usbphy: phy@01c19400 {
>>>>                           compatible = "allwinner,sun8i-h3-usb-phy";
>>>>                           reg = <0x01c19400 0x2c>,
>>>>   @@ -238,6 +251,29 @@
>>>>                           #phy-cells = <1>;
>>>>                   };
>>>>
>>>>   + ehci0: usb@01c1a000 {
>>>>   + compatible = "allwinner,sun8i-h3-ehci", "generic-ehci";
>>>>   + reg = <0x01c1a000 0x100>;
>>>>   + interrupts = <GIC_SPI 72 IRQ_TYPE_LEVEL_HIGH>;
>>>>   + clocks = <&ccu CLK_BUS_EHCI0>, <&ccu CLK_BUS_OHCI0>;
>>>>   + resets = <&ccu RST_BUS_EHCI0>, <&ccu RST_BUS_OHCI0>;
>>>>   + phys = <&usbphy 0>;
>>>>   + phy-names = "usb";
>>>
>>>  So this bit is slightly concerning. IIRC the xHCI drivers power on the phy when
>>>  probed, which means VBUS is _always_ going to be powered on, even when it's
>>>  supposed to be in peripheral mode. You're probably going to need to rework
>>>  either the phy or the musb driver to cope with this.
>>>
>>>  Or maybe just dropping the phy handle here and letting the musb driver handle
>>>  it would work, but that requires the musb driver be loaded.
>>
>>  In fact the MUSB driver is always needed -- to set the dr_mode.
>
> I guess it's the same with DWC2/3 that have host controller pairs.
>
>>  And currently MUSB driver can take over the USB bus even if it's host-only by forcing
>>  its mode in sysfs.
>
> IIUC that would also switch the phy muxing over to the HCI pairs.

The MUSB mode setting code in fact sets the mode of PHY.

So then the PHY will return a id_det value based on its mode set
(Always 0 for host, Always 1 for peripheral, real GPIO value for otg),
then the id_det change code will be run and then re-route the PHY.

>
> ChenYu
>
>>>  ChenYu
>>>
>>>>   + status = "disabled";
>>>>   + };
>>>>   +
>>>>   + ohci0: usb@01c1a400 {
>>>>   + compatible = "allwinner,sun8i-h3-ohci", "generic-ohci";
>>>>   + reg = <0x01c1a400 0x100>;
>>>>   + interrupts = <GIC_SPI 73 IRQ_TYPE_LEVEL_HIGH>;
>>>>   + clocks = <&ccu CLK_BUS_EHCI0>, <&ccu CLK_BUS_OHCI0>,
>>>>   + <&ccu CLK_USB_OHCI0>;
>>>>   + resets = <&ccu RST_BUS_EHCI0>, <&ccu RST_BUS_OHCI0>;
>>>>   + phys = <&usbphy 0>;
>>>>   + phy-names = "usb";
>>>>   + status = "disabled";
>>>>   + };
>>>>   +
>>>>                   ehci1: usb@01c1b000 {
>>>>                           compatible = "allwinner,sun8i-h3-ehci", "generic-ehci";
>>>>                           reg = <0x01c1b000 0x100>;
>>>>   --
>>>>   2.11.1
>>>>
>>>>   --
>>>>   You received this message because you are subscribed to the Google Groups "linux-sunxi" group.
>>>>   To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
>>>>   For more options, visit https://groups.google.com/d/optout.
>>>
>>>  --
>>>  You received this message because you are subscribed to the Google Groups "linux-sunxi" group.
>>>  To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
>>>  For more options, visit https://groups.google.com/d/optout.
>>
>>  --
>>  You received this message because you are subscribed to the Google Groups "linux-sunxi" group.
>>  To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
>>  For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups "linux-sunxi" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups "linux-sunxi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit https://groups.google.com/d/optout.

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

* [linux-sunxi] [PATCH 2/3] ARM: dts: sun8i: add usb_otg and OHCI/EHCI for usbc0 on H3
@ 2017-02-28 16:23                 ` Icenowy Zheng
  0 siblings, 0 replies; 24+ messages in thread
From: Icenowy Zheng @ 2017-02-28 16:23 UTC (permalink / raw)
  To: linux-arm-kernel



01.03.2017, 00:10, "Chen-Yu Tsai" <wens@csie.org>:
> On Tue, Feb 28, 2017 at 11:57 PM, Icenowy Zheng <icenowy@aosc.xyz> wrote:
>> ?28.02.2017, 23:46, "Chen-Yu Tsai" <wens@csie.org>:
>>> ?On Tue, Feb 28, 2017 at 11:27 PM, Icenowy Zheng <icenowy@aosc.xyz> wrote:
>>>> ??Allwinner H3 have a dual-routed USB PHY0 -- routed to either OHCI/EHCI
>>>> ??or MUSB controller.
>>>>
>>>> ??Add device nodes for these controllers.
>>>>
>>>> ??Signed-off-by: Icenowy Zheng <icenowy@aosc.xyz>
>>>> ??---
>>>> ???arch/arm/boot/dts/sun8i-h3.dtsi | 36 ++++++++++++++++++++++++++++++++++++
>>>> ???1 file changed, 36 insertions(+)
>>>>
>>>> ??diff --git a/arch/arm/boot/dts/sun8i-h3.dtsi b/arch/arm/boot/dts/sun8i-h3.dtsi
>>>> ??index 27780b97c863..bc9a53edf371 100644
>>>> ??--- a/arch/arm/boot/dts/sun8i-h3.dtsi
>>>> ??+++ b/arch/arm/boot/dts/sun8i-h3.dtsi
>>>> ??@@ -206,6 +206,19 @@
>>>> ??????????????????????????#size-cells = <0>;
>>>> ??????????????????};
>>>>
>>>> ??+ usb_otg: usb at 01c19000 {
>>>> ??+ compatible = "allwinner,sun8i-h3-musb";
>>>> ??+ reg = <0x01c19000 0x0400>;
>>>> ??+ clocks = <&ccu CLK_BUS_OTG>;
>>>> ??+ resets = <&ccu RST_BUS_OTG>;
>>>> ??+ interrupts = <GIC_SPI 71 IRQ_TYPE_LEVEL_HIGH>;
>>>> ??+ interrupt-names = "mc";
>>>> ??+ phys = <&usbphy 0>;
>>>> ??+ phy-names = "usb";
>>>> ??+ extcon = <&usbphy 0>;
>>>> ??+ status = "disabled";
>>>> ??+ };
>>>> ??+
>>>> ??????????????????usbphy: phy at 01c19400 {
>>>> ??????????????????????????compatible = "allwinner,sun8i-h3-usb-phy";
>>>> ??????????????????????????reg = <0x01c19400 0x2c>,
>>>> ??@@ -238,6 +251,29 @@
>>>> ??????????????????????????#phy-cells = <1>;
>>>> ??????????????????};
>>>>
>>>> ??+ ehci0: usb at 01c1a000 {
>>>> ??+ compatible = "allwinner,sun8i-h3-ehci", "generic-ehci";
>>>> ??+ reg = <0x01c1a000 0x100>;
>>>> ??+ interrupts = <GIC_SPI 72 IRQ_TYPE_LEVEL_HIGH>;
>>>> ??+ clocks = <&ccu CLK_BUS_EHCI0>, <&ccu CLK_BUS_OHCI0>;
>>>> ??+ resets = <&ccu RST_BUS_EHCI0>, <&ccu RST_BUS_OHCI0>;
>>>> ??+ phys = <&usbphy 0>;
>>>> ??+ phy-names = "usb";
>>>
>>> ?So this bit is slightly concerning. IIRC the xHCI drivers power on the phy when
>>> ?probed, which means VBUS is _always_ going to be powered on, even when it's
>>> ?supposed to be in peripheral mode. You're probably going to need to rework
>>> ?either the phy or the musb driver to cope with this.
>>>
>>> ?Or maybe just dropping the phy handle here and letting the musb driver handle
>>> ?it would work, but that requires the musb driver be loaded.
>>
>> ?In fact the MUSB driver is always needed -- to set the dr_mode.
>
> I guess it's the same with DWC2/3 that have host controller pairs.
>
>> ?And currently MUSB driver can take over the USB bus even if it's host-only by forcing
>> ?its mode in sysfs.
>
> IIUC that would also switch the phy muxing over to the HCI pairs.

The MUSB mode setting code in fact sets the mode of PHY.

So then the PHY will return a id_det value based on its mode set
(Always 0 for host, Always 1 for peripheral, real GPIO value for otg),
then the id_det change code will be run and then re-route the PHY.

>
> ChenYu
>
>>> ?ChenYu
>>>
>>>> ??+ status = "disabled";
>>>> ??+ };
>>>> ??+
>>>> ??+ ohci0: usb at 01c1a400 {
>>>> ??+ compatible = "allwinner,sun8i-h3-ohci", "generic-ohci";
>>>> ??+ reg = <0x01c1a400 0x100>;
>>>> ??+ interrupts = <GIC_SPI 73 IRQ_TYPE_LEVEL_HIGH>;
>>>> ??+ clocks = <&ccu CLK_BUS_EHCI0>, <&ccu CLK_BUS_OHCI0>,
>>>> ??+ <&ccu CLK_USB_OHCI0>;
>>>> ??+ resets = <&ccu RST_BUS_EHCI0>, <&ccu RST_BUS_OHCI0>;
>>>> ??+ phys = <&usbphy 0>;
>>>> ??+ phy-names = "usb";
>>>> ??+ status = "disabled";
>>>> ??+ };
>>>> ??+
>>>> ??????????????????ehci1: usb at 01c1b000 {
>>>> ??????????????????????????compatible = "allwinner,sun8i-h3-ehci", "generic-ehci";
>>>> ??????????????????????????reg = <0x01c1b000 0x100>;
>>>> ??--
>>>> ??2.11.1
>>>>
>>>> ??--
>>>> ??You received this message because you are subscribed to the Google Groups "linux-sunxi" group.
>>>> ??To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+unsubscribe at googlegroups.com.
>>>> ??For more options, visit https://groups.google.com/d/optout.
>>>
>>> ?--
>>> ?You received this message because you are subscribed to the Google Groups "linux-sunxi" group.
>>> ?To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+unsubscribe at googlegroups.com.
>>> ?For more options, visit https://groups.google.com/d/optout.
>>
>> ?--
>> ?You received this message because you are subscribed to the Google Groups "linux-sunxi" group.
>> ?To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+unsubscribe at googlegroups.com.
>> ?For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups "linux-sunxi" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+unsubscribe at googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

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

* Re: [PATCH 1/3] phy: sun4i-usb: support automatically switch PHY0 route to MUSB/HCI
       [not found] ` <20170228152702.42602-1-icenowy-ymACFijhrKM@public.gmane.org>
  2017-02-28 15:27     ` Icenowy Zheng
@ 2017-02-28 23:46   ` Hans de Goede
  1 sibling, 0 replies; 24+ messages in thread
From: Hans de Goede @ 2017-02-28 23:46 UTC (permalink / raw)
  To: Icenowy Zheng, Maxime Ripard, Chen-Yu Tsai, Kishon Vijay Abraham I
  Cc: devicetree, linux-arm-kernel, linux-kernel, linux-sunxi

Hi,

On 28-02-17 16:27, Icenowy Zheng wrote:
> On newer Allwinner SoCs (H3 and after), the PHY0 node is routed to both
> MUSB controller for peripheral and host support (the host support is
> slightly broken), and a pair of EHCI/OHCI controllers, which provide a
> better support for host mode.
>
> Add support for automatically switch the route of PHY0 according to the
> status of dr_mode and id det pin.
>
> Only H3 have this function enabled in this patch, as further SoCs will
> be tested later and then have it enabled.
>
> Signed-off-by: Icenowy Zheng <icenowy@aosc.xyz>
> ---
>  drivers/phy/phy-sun4i-usb.c | 55 +++++++++++++++++++++++++++++++--------------
>  1 file changed, 38 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/phy/phy-sun4i-usb.c b/drivers/phy/phy-sun4i-usb.c
> index a21b5f24a340..8b91afe8f42d 100644
> --- a/drivers/phy/phy-sun4i-usb.c
> +++ b/drivers/phy/phy-sun4i-usb.c
> @@ -49,12 +49,14 @@
>  #define REG_PHYBIST			0x08
>  #define REG_PHYTUNE			0x0c
>  #define REG_PHYCTL_A33			0x10
> -#define REG_PHY_UNK_H3			0x20
> +#define REG_PHY_OTGCTL			0x20
>
>  #define REG_PMU_UNK1			0x10
>
>  #define PHYCTL_DATA			BIT(7)
>
> +#define OTGCTL_ROUTE_MUSB		BIT(0)
> +
>  #define SUNXI_AHB_ICHR8_EN		BIT(10)
>  #define SUNXI_AHB_INCR4_BURST_EN	BIT(9)
>  #define SUNXI_AHB_INCRX_ALIGN_EN	BIT(8)
> @@ -110,6 +112,7 @@ struct sun4i_usb_phy_cfg {
>  	u8 phyctl_offset;
>  	bool dedicated_clocks;
>  	bool enable_pmu_unk1;
> +	bool phy0_dual_route;
>  };
>
>  struct sun4i_usb_phy_data {
> @@ -271,23 +274,16 @@ static int sun4i_usb_phy_init(struct phy *_phy)
>  		writel(val & ~2, phy->pmu + REG_PMU_UNK1);
>  	}
>
> -	if (data->cfg->type == sun8i_h3_phy) {
> -		if (phy->index == 0) {
> -			val = readl(data->base + REG_PHY_UNK_H3);
> -			writel(val & ~1, data->base + REG_PHY_UNK_H3);
> -		}
> -	} else {
> -		/* Enable USB 45 Ohm resistor calibration */
> -		if (phy->index == 0)
> -			sun4i_usb_phy_write(phy, PHY_RES45_CAL_EN, 0x01, 1);
> +	/* Enable USB 45 Ohm resistor calibration */
> +	if (phy->index == 0)
> +		sun4i_usb_phy_write(phy, PHY_RES45_CAL_EN, 0x01, 1);
>
> -		/* Adjust PHY's magnitude and rate */
> -		sun4i_usb_phy_write(phy, PHY_TX_AMPLITUDE_TUNE, 0x14, 5);
> +	/* Adjust PHY's magnitude and rate */
> +	sun4i_usb_phy_write(phy, PHY_TX_AMPLITUDE_TUNE, 0x14, 5);
>
> -		/* Disconnect threshold adjustment */
> -		sun4i_usb_phy_write(phy, PHY_DISCON_TH_SEL,
> -				    data->cfg->disc_thresh, 2);
> -	}
> +	/* Disconnect threshold adjustment */
> +	sun4i_usb_phy_write(phy, PHY_DISCON_TH_SEL,
> +			    data->cfg->disc_thresh, 2);
>
>  	sun4i_usb_phy_passby(phy, 1);
>
> @@ -486,6 +482,26 @@ static const struct phy_ops sun4i_usb_phy_ops = {
>  	.owner		= THIS_MODULE,
>  };
>
> +static void sun4i_usb_phy0_reroute(struct sun4i_usb_phy_data *data, int id_det)
> +{
> +	u32 regval;
> +
> +	if (data->dr_mode == USB_DR_MODE_HOST)
> +		id_det = 0; /* Force host */
> +	if (data->dr_mode == USB_DR_MODE_PERIPHERAL)
> +		id_det = 1; /* Force peripheral*/

The passed in id_det comes from sun4i_usb_phy0_get_id_det() which already
does:

         switch (data->dr_mode) {
         case USB_DR_MODE_OTG:
                 if (data->id_det_gpio)
                         return gpiod_get_value_cansleep(data->id_det_gpio);
                 else
                         return 1; /* Fallback to peripheral mode */
         case USB_DR_MODE_HOST:
                 return 0;
         case USB_DR_MODE_PERIPHERAL:
         default:
                 return 1;
         }

So the above 4 lines are unnecessary and should be removed.

Otherwise looks good, thank you for doing this.

Regards,

Hans



> +
> +	regval = readl(data->base + REG_PHY_OTGCTL);
> +	if (id_det == 0) {
> +		/* Host mode. Route phy0 to EHCI/OHCI */
> +		regval &= ~OTGCTL_ROUTE_MUSB;
> +	} else {
> +		/* Peripheral mode. Route phy0 to MUSB */
> +		regval |= OTGCTL_ROUTE_MUSB;
> +	}
> +	writel(regval, data->base + REG_PHY_OTGCTL);
> +}
> +
>  static void sun4i_usb_phy0_id_vbus_det_scan(struct work_struct *work)
>  {
>  	struct sun4i_usb_phy_data *data =
> @@ -511,6 +527,10 @@ static void sun4i_usb_phy0_id_vbus_det_scan(struct work_struct *work)
>  	data->force_session_end = false;
>
>  	if (id_det != data->id_det) {
> +		/* Re-route PHY0 if necessary */
> +		if (data->cfg->phy0_dual_route)
> +			sun4i_usb_phy0_reroute(data, id_det);
> +
>  		/* id-change, force session end if we've no vbus detection */
>  		if (data->dr_mode == USB_DR_MODE_OTG &&
>  		    !sun4i_usb_phy0_have_vbus_det(data))
> @@ -700,7 +720,7 @@ static int sun4i_usb_phy_probe(struct platform_device *pdev)
>  			return PTR_ERR(phy->reset);
>  		}
>
> -		if (i) { /* No pmu for usbc0 */
> +		if (i || data->cfg->phy0_dual_route) { /* No pmu for musb */
>  			snprintf(name, sizeof(name), "pmu%d", i);
>  			res = platform_get_resource_byname(pdev,
>  							IORESOURCE_MEM, name);
> @@ -825,6 +845,7 @@ static const struct sun4i_usb_phy_cfg sun8i_h3_cfg = {
>  	.disc_thresh = 3,
>  	.dedicated_clocks = true,
>  	.enable_pmu_unk1 = true,
> +	.phy0_dual_route = true,
>  };
>
>  static const struct sun4i_usb_phy_cfg sun8i_v3s_cfg = {
>

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

* Re: [PATCH 1/3] phy: sun4i-usb: support automatically switch PHY0 route to MUSB/HCI
@ 2017-02-28 23:46   ` Hans de Goede
  0 siblings, 0 replies; 24+ messages in thread
From: Hans de Goede @ 2017-02-28 23:46 UTC (permalink / raw)
  To: Icenowy Zheng, Maxime Ripard, Chen-Yu Tsai, Kishon Vijay Abraham I
  Cc: devicetree-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-sunxi-/JYPxA39Uh5TLH3MbocFFw

Hi,

On 28-02-17 16:27, Icenowy Zheng wrote:
> On newer Allwinner SoCs (H3 and after), the PHY0 node is routed to both
> MUSB controller for peripheral and host support (the host support is
> slightly broken), and a pair of EHCI/OHCI controllers, which provide a
> better support for host mode.
>
> Add support for automatically switch the route of PHY0 according to the
> status of dr_mode and id det pin.
>
> Only H3 have this function enabled in this patch, as further SoCs will
> be tested later and then have it enabled.
>
> Signed-off-by: Icenowy Zheng <icenowy-ymACFijhrKM@public.gmane.org>
> ---
>  drivers/phy/phy-sun4i-usb.c | 55 +++++++++++++++++++++++++++++++--------------
>  1 file changed, 38 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/phy/phy-sun4i-usb.c b/drivers/phy/phy-sun4i-usb.c
> index a21b5f24a340..8b91afe8f42d 100644
> --- a/drivers/phy/phy-sun4i-usb.c
> +++ b/drivers/phy/phy-sun4i-usb.c
> @@ -49,12 +49,14 @@
>  #define REG_PHYBIST			0x08
>  #define REG_PHYTUNE			0x0c
>  #define REG_PHYCTL_A33			0x10
> -#define REG_PHY_UNK_H3			0x20
> +#define REG_PHY_OTGCTL			0x20
>
>  #define REG_PMU_UNK1			0x10
>
>  #define PHYCTL_DATA			BIT(7)
>
> +#define OTGCTL_ROUTE_MUSB		BIT(0)
> +
>  #define SUNXI_AHB_ICHR8_EN		BIT(10)
>  #define SUNXI_AHB_INCR4_BURST_EN	BIT(9)
>  #define SUNXI_AHB_INCRX_ALIGN_EN	BIT(8)
> @@ -110,6 +112,7 @@ struct sun4i_usb_phy_cfg {
>  	u8 phyctl_offset;
>  	bool dedicated_clocks;
>  	bool enable_pmu_unk1;
> +	bool phy0_dual_route;
>  };
>
>  struct sun4i_usb_phy_data {
> @@ -271,23 +274,16 @@ static int sun4i_usb_phy_init(struct phy *_phy)
>  		writel(val & ~2, phy->pmu + REG_PMU_UNK1);
>  	}
>
> -	if (data->cfg->type == sun8i_h3_phy) {
> -		if (phy->index == 0) {
> -			val = readl(data->base + REG_PHY_UNK_H3);
> -			writel(val & ~1, data->base + REG_PHY_UNK_H3);
> -		}
> -	} else {
> -		/* Enable USB 45 Ohm resistor calibration */
> -		if (phy->index == 0)
> -			sun4i_usb_phy_write(phy, PHY_RES45_CAL_EN, 0x01, 1);
> +	/* Enable USB 45 Ohm resistor calibration */
> +	if (phy->index == 0)
> +		sun4i_usb_phy_write(phy, PHY_RES45_CAL_EN, 0x01, 1);
>
> -		/* Adjust PHY's magnitude and rate */
> -		sun4i_usb_phy_write(phy, PHY_TX_AMPLITUDE_TUNE, 0x14, 5);
> +	/* Adjust PHY's magnitude and rate */
> +	sun4i_usb_phy_write(phy, PHY_TX_AMPLITUDE_TUNE, 0x14, 5);
>
> -		/* Disconnect threshold adjustment */
> -		sun4i_usb_phy_write(phy, PHY_DISCON_TH_SEL,
> -				    data->cfg->disc_thresh, 2);
> -	}
> +	/* Disconnect threshold adjustment */
> +	sun4i_usb_phy_write(phy, PHY_DISCON_TH_SEL,
> +			    data->cfg->disc_thresh, 2);
>
>  	sun4i_usb_phy_passby(phy, 1);
>
> @@ -486,6 +482,26 @@ static const struct phy_ops sun4i_usb_phy_ops = {
>  	.owner		= THIS_MODULE,
>  };
>
> +static void sun4i_usb_phy0_reroute(struct sun4i_usb_phy_data *data, int id_det)
> +{
> +	u32 regval;
> +
> +	if (data->dr_mode == USB_DR_MODE_HOST)
> +		id_det = 0; /* Force host */
> +	if (data->dr_mode == USB_DR_MODE_PERIPHERAL)
> +		id_det = 1; /* Force peripheral*/

The passed in id_det comes from sun4i_usb_phy0_get_id_det() which already
does:

         switch (data->dr_mode) {
         case USB_DR_MODE_OTG:
                 if (data->id_det_gpio)
                         return gpiod_get_value_cansleep(data->id_det_gpio);
                 else
                         return 1; /* Fallback to peripheral mode */
         case USB_DR_MODE_HOST:
                 return 0;
         case USB_DR_MODE_PERIPHERAL:
         default:
                 return 1;
         }

So the above 4 lines are unnecessary and should be removed.

Otherwise looks good, thank you for doing this.

Regards,

Hans



> +
> +	regval = readl(data->base + REG_PHY_OTGCTL);
> +	if (id_det == 0) {
> +		/* Host mode. Route phy0 to EHCI/OHCI */
> +		regval &= ~OTGCTL_ROUTE_MUSB;
> +	} else {
> +		/* Peripheral mode. Route phy0 to MUSB */
> +		regval |= OTGCTL_ROUTE_MUSB;
> +	}
> +	writel(regval, data->base + REG_PHY_OTGCTL);
> +}
> +
>  static void sun4i_usb_phy0_id_vbus_det_scan(struct work_struct *work)
>  {
>  	struct sun4i_usb_phy_data *data =
> @@ -511,6 +527,10 @@ static void sun4i_usb_phy0_id_vbus_det_scan(struct work_struct *work)
>  	data->force_session_end = false;
>
>  	if (id_det != data->id_det) {
> +		/* Re-route PHY0 if necessary */
> +		if (data->cfg->phy0_dual_route)
> +			sun4i_usb_phy0_reroute(data, id_det);
> +
>  		/* id-change, force session end if we've no vbus detection */
>  		if (data->dr_mode == USB_DR_MODE_OTG &&
>  		    !sun4i_usb_phy0_have_vbus_det(data))
> @@ -700,7 +720,7 @@ static int sun4i_usb_phy_probe(struct platform_device *pdev)
>  			return PTR_ERR(phy->reset);
>  		}
>
> -		if (i) { /* No pmu for usbc0 */
> +		if (i || data->cfg->phy0_dual_route) { /* No pmu for musb */
>  			snprintf(name, sizeof(name), "pmu%d", i);
>  			res = platform_get_resource_byname(pdev,
>  							IORESOURCE_MEM, name);
> @@ -825,6 +845,7 @@ static const struct sun4i_usb_phy_cfg sun8i_h3_cfg = {
>  	.disc_thresh = 3,
>  	.dedicated_clocks = true,
>  	.enable_pmu_unk1 = true,
> +	.phy0_dual_route = true,
>  };
>
>  static const struct sun4i_usb_phy_cfg sun8i_v3s_cfg = {
>

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

* [PATCH 1/3] phy: sun4i-usb: support automatically switch PHY0 route to MUSB/HCI
@ 2017-02-28 23:46   ` Hans de Goede
  0 siblings, 0 replies; 24+ messages in thread
From: Hans de Goede @ 2017-02-28 23:46 UTC (permalink / raw)
  To: linux-arm-kernel

Hi,

On 28-02-17 16:27, Icenowy Zheng wrote:
> On newer Allwinner SoCs (H3 and after), the PHY0 node is routed to both
> MUSB controller for peripheral and host support (the host support is
> slightly broken), and a pair of EHCI/OHCI controllers, which provide a
> better support for host mode.
>
> Add support for automatically switch the route of PHY0 according to the
> status of dr_mode and id det pin.
>
> Only H3 have this function enabled in this patch, as further SoCs will
> be tested later and then have it enabled.
>
> Signed-off-by: Icenowy Zheng <icenowy@aosc.xyz>
> ---
>  drivers/phy/phy-sun4i-usb.c | 55 +++++++++++++++++++++++++++++++--------------
>  1 file changed, 38 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/phy/phy-sun4i-usb.c b/drivers/phy/phy-sun4i-usb.c
> index a21b5f24a340..8b91afe8f42d 100644
> --- a/drivers/phy/phy-sun4i-usb.c
> +++ b/drivers/phy/phy-sun4i-usb.c
> @@ -49,12 +49,14 @@
>  #define REG_PHYBIST			0x08
>  #define REG_PHYTUNE			0x0c
>  #define REG_PHYCTL_A33			0x10
> -#define REG_PHY_UNK_H3			0x20
> +#define REG_PHY_OTGCTL			0x20
>
>  #define REG_PMU_UNK1			0x10
>
>  #define PHYCTL_DATA			BIT(7)
>
> +#define OTGCTL_ROUTE_MUSB		BIT(0)
> +
>  #define SUNXI_AHB_ICHR8_EN		BIT(10)
>  #define SUNXI_AHB_INCR4_BURST_EN	BIT(9)
>  #define SUNXI_AHB_INCRX_ALIGN_EN	BIT(8)
> @@ -110,6 +112,7 @@ struct sun4i_usb_phy_cfg {
>  	u8 phyctl_offset;
>  	bool dedicated_clocks;
>  	bool enable_pmu_unk1;
> +	bool phy0_dual_route;
>  };
>
>  struct sun4i_usb_phy_data {
> @@ -271,23 +274,16 @@ static int sun4i_usb_phy_init(struct phy *_phy)
>  		writel(val & ~2, phy->pmu + REG_PMU_UNK1);
>  	}
>
> -	if (data->cfg->type == sun8i_h3_phy) {
> -		if (phy->index == 0) {
> -			val = readl(data->base + REG_PHY_UNK_H3);
> -			writel(val & ~1, data->base + REG_PHY_UNK_H3);
> -		}
> -	} else {
> -		/* Enable USB 45 Ohm resistor calibration */
> -		if (phy->index == 0)
> -			sun4i_usb_phy_write(phy, PHY_RES45_CAL_EN, 0x01, 1);
> +	/* Enable USB 45 Ohm resistor calibration */
> +	if (phy->index == 0)
> +		sun4i_usb_phy_write(phy, PHY_RES45_CAL_EN, 0x01, 1);
>
> -		/* Adjust PHY's magnitude and rate */
> -		sun4i_usb_phy_write(phy, PHY_TX_AMPLITUDE_TUNE, 0x14, 5);
> +	/* Adjust PHY's magnitude and rate */
> +	sun4i_usb_phy_write(phy, PHY_TX_AMPLITUDE_TUNE, 0x14, 5);
>
> -		/* Disconnect threshold adjustment */
> -		sun4i_usb_phy_write(phy, PHY_DISCON_TH_SEL,
> -				    data->cfg->disc_thresh, 2);
> -	}
> +	/* Disconnect threshold adjustment */
> +	sun4i_usb_phy_write(phy, PHY_DISCON_TH_SEL,
> +			    data->cfg->disc_thresh, 2);
>
>  	sun4i_usb_phy_passby(phy, 1);
>
> @@ -486,6 +482,26 @@ static const struct phy_ops sun4i_usb_phy_ops = {
>  	.owner		= THIS_MODULE,
>  };
>
> +static void sun4i_usb_phy0_reroute(struct sun4i_usb_phy_data *data, int id_det)
> +{
> +	u32 regval;
> +
> +	if (data->dr_mode == USB_DR_MODE_HOST)
> +		id_det = 0; /* Force host */
> +	if (data->dr_mode == USB_DR_MODE_PERIPHERAL)
> +		id_det = 1; /* Force peripheral*/

The passed in id_det comes from sun4i_usb_phy0_get_id_det() which already
does:

         switch (data->dr_mode) {
         case USB_DR_MODE_OTG:
                 if (data->id_det_gpio)
                         return gpiod_get_value_cansleep(data->id_det_gpio);
                 else
                         return 1; /* Fallback to peripheral mode */
         case USB_DR_MODE_HOST:
                 return 0;
         case USB_DR_MODE_PERIPHERAL:
         default:
                 return 1;
         }

So the above 4 lines are unnecessary and should be removed.

Otherwise looks good, thank you for doing this.

Regards,

Hans



> +
> +	regval = readl(data->base + REG_PHY_OTGCTL);
> +	if (id_det == 0) {
> +		/* Host mode. Route phy0 to EHCI/OHCI */
> +		regval &= ~OTGCTL_ROUTE_MUSB;
> +	} else {
> +		/* Peripheral mode. Route phy0 to MUSB */
> +		regval |= OTGCTL_ROUTE_MUSB;
> +	}
> +	writel(regval, data->base + REG_PHY_OTGCTL);
> +}
> +
>  static void sun4i_usb_phy0_id_vbus_det_scan(struct work_struct *work)
>  {
>  	struct sun4i_usb_phy_data *data =
> @@ -511,6 +527,10 @@ static void sun4i_usb_phy0_id_vbus_det_scan(struct work_struct *work)
>  	data->force_session_end = false;
>
>  	if (id_det != data->id_det) {
> +		/* Re-route PHY0 if necessary */
> +		if (data->cfg->phy0_dual_route)
> +			sun4i_usb_phy0_reroute(data, id_det);
> +
>  		/* id-change, force session end if we've no vbus detection */
>  		if (data->dr_mode == USB_DR_MODE_OTG &&
>  		    !sun4i_usb_phy0_have_vbus_det(data))
> @@ -700,7 +720,7 @@ static int sun4i_usb_phy_probe(struct platform_device *pdev)
>  			return PTR_ERR(phy->reset);
>  		}
>
> -		if (i) { /* No pmu for usbc0 */
> +		if (i || data->cfg->phy0_dual_route) { /* No pmu for musb */
>  			snprintf(name, sizeof(name), "pmu%d", i);
>  			res = platform_get_resource_byname(pdev,
>  							IORESOURCE_MEM, name);
> @@ -825,6 +845,7 @@ static const struct sun4i_usb_phy_cfg sun8i_h3_cfg = {
>  	.disc_thresh = 3,
>  	.dedicated_clocks = true,
>  	.enable_pmu_unk1 = true,
> +	.phy0_dual_route = true,
>  };
>
>  static const struct sun4i_usb_phy_cfg sun8i_v3s_cfg = {
>

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

end of thread, other threads:[~2017-03-01  0:12 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-28 15:27 [PATCH 1/3] phy: sun4i-usb: support automatically switch PHY0 route to MUSB/HCI Icenowy Zheng
2017-02-28 15:27 ` Icenowy Zheng
     [not found] ` <20170228152702.42602-1-icenowy-ymACFijhrKM@public.gmane.org>
2017-02-28 15:27   ` [PATCH 2/3] ARM: dts: sun8i: add usb_otg and OHCI/EHCI for usbc0 on H3 Icenowy Zheng
2017-02-28 15:27     ` Icenowy Zheng
2017-02-28 15:46     ` [linux-sunxi] " Chen-Yu Tsai
2017-02-28 15:46       ` Chen-Yu Tsai
2017-02-28 15:46       ` Chen-Yu Tsai
     [not found]       ` <CAGb2v67fsuhRnGp7X8PDkH_t_gb+gPb6VrY-pVu0B4HhD6d8qA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-02-28 15:57         ` Icenowy Zheng
2017-02-28 15:57           ` [linux-sunxi] " Icenowy Zheng
2017-02-28 16:10           ` Chen-Yu Tsai
2017-02-28 16:10             ` Chen-Yu Tsai
2017-02-28 16:10             ` Chen-Yu Tsai
     [not found]             ` <CAGb2v64cu8Jz6PZ7mZ7Atw9jS7xaaG+8MSv+NX_6nKNmyyXotQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-02-28 16:23               ` Icenowy Zheng
2017-02-28 16:23                 ` [linux-sunxi] " Icenowy Zheng
2017-02-28 16:07         ` Icenowy Zheng
2017-02-28 16:07           ` [linux-sunxi] " Icenowy Zheng
2017-02-28 15:27   ` [PATCH 3/3] ARM: dts: sun8i: enable USB OTG on Orange Pi One Icenowy Zheng
2017-02-28 15:27     ` Icenowy Zheng
2017-02-28 15:42 ` [linux-sunxi] [PATCH 1/3] phy: sun4i-usb: support automatically switch PHY0 route to MUSB/HCI Chen-Yu Tsai
2017-02-28 15:42   ` Chen-Yu Tsai
2017-02-28 15:42   ` Chen-Yu Tsai
2017-02-28 23:46 ` Hans de Goede
2017-02-28 23:46   ` Hans de Goede
2017-02-28 23:46   ` Hans de Goede

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.