Skip to contentSkip to conversation

ARM: sunxi: Add support for USB OTG PHY

PATCH In review Roman Byshko 5 participants 11 messages Nov 10, 2014 – Dec 2, 2014

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

v2 cover ARM: sunxi: Add support for USB OTG PHY

Hi,

There is already support for two USB phys, which are used for USB host controllers on Allwinner SoC aka sunxi.

This patch series add support for the USB OTG phy (aka phy0).

The code has been tested on Allwinner A20 aka sun7i (Cubietruck).

Best regards,
Roman Byshko

Changes since v1:
* Improved comment about 45 Ohm resistor calibration
* Added Signed-off-by to all patches

Roman Byshko (5):
phy: sun4i: add support for USB phy0
ARM: dtsi: sunxi: add common VBUS regulator
ARM: sun7i: dtsi: add support for usbphy0
ARM: dts: sun7i: Cubietruck: override regulator pin
ARM: dts: sun7i: Cubietruck: add power supply regulator for USB OTG
VBUS

 arch/arm/boot/dts/sun7i-a20-cubietruck.dts     | 14 ++++++++++++++
 arch/arm/boot/dts/sun7i-a20.dtsi               |  4 ++--
 arch/arm/boot/dts/sunxi-common-regulators.dtsi | 19 +++++++++++++++++++
 drivers/phy/phy-sun4i-usb.c                    |  9 ++++++---
 4 files changed, 41 insertions(+), 5 deletions(-)
Signature · 1 line
2.1.2
#1 lore raw

PATCH v2 1/5 phy: sun4i: add support for USB phy0

The driver for sun4i USB phys currently supports only phy1 and phy2 which are used for USB host controllers. This patch adds support for USB phy0, which is used by the musb hdrc USB controller.

---
 drivers/phy/phy-sun4i-usb.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/phy/phy-sun4i-usb.c +6 -3
index 0baf5ef..6bd2b0c 100644
@@ -157,6 +157,10 @@ static int sun4i_usb_phy_init(struct phy *_phy)
 		return ret;
 	}
 
+	/* 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);
 
@@ -213,7 +217,7 @@ static struct phy *sun4i_usb_phy_xlate(struct device *dev,
 {
 	struct sun4i_usb_phy_data *data = dev_get_drvdata(dev);
 
-	if (WARN_ON(args->args[0] == 0 || args->args[0] >= data->num_phys))
+	if (args->args[0] >= data->num_phys)
 		return ERR_PTR(-ENODEV);
 
 	return data->phys[args->args[0]].phy;
@@ -255,8 +259,7 @@ static int sun4i_usb_phy_probe(struct platform_device *pdev)
 	if (IS_ERR(data->base))
 		return PTR_ERR(data->base);
 
-	/* Skip 0, 0 is the phy for otg which is not yet supported. */
-	for (i = 1; i < data->num_phys; i++) {
+	for (i = 0; i < data->num_phys; i++) {
 		struct sun4i_usb_phy *phy = data->phys + i;
 		char name[16];
 
Signature · 1 line
2.1.2
Acked-by on v2 1/5
#2 lore raw

Re: [PATCH v2 1/5] phy: sun4i: add support for USB phy0

Quoted 6 lines · Roman Byshko

The driver for sun4i USB phys currently supports only phy1 and phy2 which are used for USB host controllers. This patch adds support for USB phy0, which is used by the musb hdrc USB controller.

Thanks!
Maxime

Signature · 10 lines
Maxime Ripard, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20141112/00769842/attachment.sig>
#3 lore raw

PATCH v2 2/5 ARM: dtsi: sunxi: add common VBUS regulator

In reply to Roman Byshko

Until now the regulator nodes for powering USB VBUS existed only for the two host controllers. Now the regulator is added for USB OTG too.

---
 arch/arm/boot/dts/sunxi-common-regulators.dtsi | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
arch/arm/boot/dts/sunxi-common-regulators.dtsi +19 -0
index c9c5b10..f521672 100644
@@ -21,6 +21,13 @@
 				allwinner,pull = <0>;
 			};
 
+			usb0_vbus_pin_a: usb0_vbus_pin at 0 {
+				allwinner,pins = "PB9";
+				allwinner,function = "gpio_out";
+				allwinner,drive = <0>;
+				allwinner,pull = <0>;
+			};
+
 			usb1_vbus_pin_a: usb1_vbus_pin at 0 {
 				allwinner,pins = "PH6";
 				allwinner,function = "gpio_out";
@@ -49,6 +56,18 @@
 		status = "disabled";
 	};
 
+	reg_usb0_vbus: usb0-vbus {
+		compatible = "regulator-fixed";
+		pinctrl-names = "default";
+		pinctrl-0 = <&usb0_vbus_pin_a>;
+		regulator-name = "usb0-vbus";
+		regulator-min-microvolt = <5000000>;
+		regulator-max-microvolt = <5000000>;
+		enable-active-high;
+		gpio = <&pio 1 9 0>;
+		status = "disabled";
+	};
+
 	reg_usb1_vbus: usb1-vbus {
 		compatible = "regulator-fixed";
 		pinctrl-names = "default";
Signature · 1 line
2.1.2
#4 lore raw

PATCH v2 3/5 ARM: sun7i: dtsi: add support for usbphy0

In reply to Roman Byshko
---
 arch/arm/boot/dts/sun7i-a20.dtsi | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm/boot/dts/sun7i-a20.dtsi +2 -2
index 82097c9..f787ccb 100644
@@ -552,8 +552,8 @@
 			reg-names = "phy_ctrl", "pmu1", "pmu2";
 			clocks = <&usb_clk 8>;
 			clock-names = "usb_phy";
-			resets = <&usb_clk 1>, <&usb_clk 2>;
-			reset-names = "usb1_reset", "usb2_reset";
+			resets = <&usb_clk 0>, <&usb_clk 1>, <&usb_clk 2>;
+			reset-names = "usb0_reset", "usb1_reset", "usb2_reset";
 			status = "disabled";
 		};
 
Signature · 1 line
2.1.2
#5 lore raw

PATCH v2 4/5 ARM: dts: sun7i: Cubietruck: override regulator pin

In reply to Roman Byshko

Cubietruck uses different pin for the USB OTG VBUS that is why we override the one defined in sunxi-common-regulators.dtsi

---
 arch/arm/boot/dts/sun7i-a20-cubietruck.dts | 13 +++++++++++++
 1 file changed, 13 insertions(+)
arch/arm/boot/dts/sun7i-a20-cubietruck.dts +13 -0
index a6c1a3c..1682307 100644
@@ -92,6 +92,13 @@
 				allwinner,drive = <0>;
 				allwinner,pull = <0>;
 			};
+
+			usb0_vbus_pin_a: usb0_vbus_pin at 0 {
+				allwinner,pins = "PH17";
+				allwinner,function = "gpio_out";
+				allwinner,drive = <0>;
+				allwinner,pull = <0>;
+			};
 		};
 
 		pwm: pwm at 01c20e00 {
@@ -185,6 +192,12 @@
 		status = "okay";
 	};
 
+	reg_usb0_vbus: usb0-vbus {
+		pinctrl-0 = <&usb0_vbus_pin_a>;
+		gpio = <&pio 7 17 0>;
+		status = "okay";
+	};
+
 	reg_usb1_vbus: usb1-vbus {
 		status = "okay";
 	};
Signature · 1 line
2.1.2
#6 lore raw

PATCH v2 5/5 ARM: dts: sun7i: Cubietruck: add power supply regulator for USB OTG VBUS

In reply to Roman Byshko
---
 arch/arm/boot/dts/sun7i-a20-cubietruck.dts | 1 +
 1 file changed, 1 insertion(+)
arch/arm/boot/dts/sun7i-a20-cubietruck.dts +1 -0
index 1682307..a281d25 100644
@@ -40,6 +40,7 @@
 		};
 
 		usbphy: phy at 01c13400 {
+			usb0_vbus-supply = <&reg_usb0_vbus>;
 			usb1_vbus-supply = <&reg_usb1_vbus>;
 			usb2_vbus-supply = <&reg_usb2_vbus>;
 			status = "okay";
Signature · 1 line
2.1.2
#7 lore raw
In reply to Roman Byshko

Hi,

Quoted 11 lines · Roman Byshko

Hi,

There is already support for two USB phys, which are used for USB host controllers on Allwinner SoC aka sunxi.

This patch series add support for the USB OTG phy (aka phy0).

The code has been tested on Allwinner A20 aka sun7i (Cubietruck).

Best regards,
Roman Byshko

First of all very cool that you're working on this, I somehow missed v1, but I'm very happy to see this.

Second some questions, this series seems to only add support for initializing the phy, without adding the necessary magic for switching from app to host mode, and without actually hooking up musb, I assume you've a follow up series adding musb support, which actually uses the phy ?

Also have you coordinated your work with ChenYu? ATM ChenYu is mostly working on other stuff, but AFAIk he has been working on musb support in the past.

Regards,

Hans

#8 lore raw
Quoted 24 lines · Hans de Goede

Hi,

Quoted 11 lines · Roman Byshko

Hi,

There is already support for two USB phys, which are used for USB host controllers on Allwinner SoC aka sunxi.

This patch series add support for the USB OTG phy (aka phy0).

The code has been tested on Allwinner A20 aka sun7i (Cubietruck).

Best regards,
Roman Byshko

First of all very cool that you're working on this, I somehow missed v1, but I'm very happy to see this.

Second some questions, this series seems to only add support for initializing the phy, without adding the necessary magic for switching from app to host mode, and without actually hooking up musb, I assume you've a follow up series adding musb support, which actually uses the phy ?

Quoted 3 lines

Also have you coordinated your work with ChenYu? ATM ChenYu is mostly working on other stuff, but AFAIk he has been working on musb support in the past.

I'm happy that someone has taken over. I was mostly just exploring what OTG is, not much code actually made it into my working branch, which is available on github.

ChenYu

#9 lore raw
In reply to Hans de Goede
Quoted 15 lines · Hans de Goede

Hi,

Quoted 11 lines · Roman Byshko

Hi,

There is already support for two USB phys, which are used for USB host controllers on Allwinner SoC aka sunxi.

This patch series add support for the USB OTG phy (aka phy0).

The code has been tested on Allwinner A20 aka sun7i (Cubietruck).

Best regards,
Roman Byshko

Quoted 8 lines

First of all very cool that you're working on this, I somehow missed v1, but I'm very happy to see this.

Second some questions, this series seems to only add support for initializing the phy, without adding the necessary magic for switching from app to host mode, and without actually hooking up musb, I assume you've a follow up series adding musb support, which actually uses the phy ?

Yes, there will be follow ups.

Quoted 3 lines

Also have you coordinated your work with ChenYu? ATM ChenYu is mostly working on other stuff, but AFAIk he has been working on musb support in the past.

Yes.

Best,
Roman

Quoted 9 lines

Regards,

Hans

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#10 lore raw
In reply to Roman Byshko
Quoted 11 lines · Roman Byshko

Hi,

There is already support for two USB phys, which are used for USB host controllers on Allwinner SoC aka sunxi.

This patch series add support for the USB OTG phy (aka phy0).

The code has been tested on Allwinner A20 aka sun7i (Cubietruck).

Best regards,
Roman Byshko

Merged patches 2-5. Thanks!
Maxime

Signature · 10 lines
Maxime Ripard, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20141112/c989884e/attachment.sig>