Skip to contentSkip to conversation

DWC3 USB support for Qualcomm platform

PATCH In review Andy Gross 5 participants 17 messages Sep 12, 2014 – Jan 22, 2015 1 message not in the archive

Subsystems (5)
lore
Share & tools
lore

Andy Gross

author
#0 lore raw

v9 cover DWC3 USB support for Qualcomm platform

These patches add basic support for USB3.0 controllers found on MSM platforms. USB3.0 core is based on Synopsys DesignWare SuperSpeed IP.

This work was started by Ivan Ivanov and went through a number of iterations. I picked these patches up and did a little rework to get them working.

Changes since v8:
* Fixed minor comments from reviewers.

Changes since v7:
* Reworked phy driver to conform to the generic phy framework.
* Collapsed HS and SS phy drivers into same source file.
* Dropped regulators from the drivers. The only platform where we can utilize this driver has regulators on all the time. Will add regulators back in when they are required.
* Added timeouts to the phy register accesses
* Put in definitions for the phy specific registers and bitfields
* Removed unnecessary workarounds.

Changes since v6:
* Renamed all MSM references to qcom, including file names
* Removed direct TCSR manipulation. This done from new TCSR driver.
* Added defines for register bits
* XO clk is optional on some platforms. Corrected logic to handle this.
* Ignore set_voltage failures. This allows us to support dummy regulators on platforms where there is no voltage control.
* Reworked devicetree binding to remove TCSR reg resources

Changes since v5:
* devicetree bindings descriptions fixes
* Fixed NULL pointer dereferences in dev_prink's
* Removed extra space in "sleep " clock name

Changes since v4:
* Substitute references to "wc3" with just "dw" in USB PHY drivers and file names. This is to indicate that the PHY's are DesignWare, but not necessarily related to DWC3 IP core.

Changes since v3:
* Remove "_clk" suffix from clock names
* Clarify required child node for qcom,dwc3
* Fix comments in functions headers
* Use dbg instead err in drivers probe functions.

Changes since v2:
* Several improvements in devicetree bindings description
* Disable regulators in glue layer if there is error during ioremap.

Changes since first version:
* Split devicetree bindings description file to separate patch
* Address comments for device bindings description
* Fix typo in 'gdsc' requlator name.

Andy Gross (1):
phy: Add Qualcomm DWC3 HS/SS PHY driver

Ivan T. Ivanov (2):
usb: dwc3: qcom: Add device tree binding
usb: dwc3: Add Qualcomm DWC3 glue layer driver

 .../devicetree/bindings/phy/qcom-dwc3-usb-phy.txt  |   39 ++
 .../devicetree/bindings/usb/qcom,dwc3.txt          |   66 +++
 drivers/phy/Kconfig                                |   11 +
 drivers/phy/Makefile                               |    1 +
 drivers/phy/phy-qcom-dwc3.c                        |  483 ++++++++++++++++++++
 drivers/usb/dwc3/Kconfig                           |    8 +
 drivers/usb/dwc3/Makefile                          |    1 +
 drivers/usb/dwc3/dwc3-qcom.c                       |  131 ++++++
 8 files changed, 740 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/qcom-dwc3-usb-phy.txt
 create mode 100644 Documentation/devicetree/bindings/usb/qcom,dwc3.txt
 create mode 100644 drivers/phy/phy-qcom-dwc3.c
 create mode 100644 drivers/usb/dwc3/dwc3-qcom.c
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
hosted by The Linux Foundation
author
#1 lore raw

PATCH v9 1/3 usb: dwc3: qcom: Add device tree binding

From: "Ivan T. Ivanov" <[email protected]>

QCOM USB3.0 core wrapper consist of USB3.0 IP from Synopsys (SNPS) and HS, SS PHY's control and configuration registers.

It could operate in device mode (SS, HS, FS) and host mode (SS, HS, FS, LS).

---
 .../devicetree/bindings/phy/qcom-dwc3-usb-phy.txt  |   39 ++++++++++++
 .../devicetree/bindings/usb/qcom,dwc3.txt          |   66 ++++++++++++++++++++
 2 files changed, 105 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/qcom-dwc3-usb-phy.txt
 create mode 100644 Documentation/devicetree/bindings/usb/qcom,dwc3.txt
Documentation/devicetree/bindings/phy/qcom-dwc3-usb-phy.txt new file +39 -0
new file mode 100644
index 0000000..86f2dbe
@@ -0,0 +1,39 @@
+Qualcomm DWC3 HS AND SS PHY CONTROLLER
+--------------------------------------
+
+DWC3 PHY nodes are defined to describe on-chip Synopsis Physical layer
+controllers.  Each DWC3 PHY controller should have its own node.
+
+Required properties:
+- compatible: should contain one of the following:
+	- "qcom,dwc3-hs-usb-phy" for High Speed Synopsis PHY controller
+	- "qcom,dwc3-ss-usb-phy" for Super Speed Synopsis PHY controller
+- reg: offset and length of the DWC3 PHY controller register set
+- #phy-cells: must be zero
+- clocks: a list of phandles and clock-specifier pairs, one for each entry in
+  clock-names.
+- clock-names: Should contain "ref" for the PHY reference clock
+
+Optional clocks:
+  "xo"		External reference clock
+
+Example:
+		phy at 100f8800 {
+			compatible = "qcom,dwc3-hs-usb-phy";
+			reg = <0x100f8800 0x30>;
+			clocks = <&gcc USB30_0_UTMI_CLK>;
+			clock-names = "ref";
+			#phy-cells = <0>;
+
+			status = "ok";
+		};
+
+		phy at 100f8830 {
+			compatible = "qcom,dwc3-ss-usb-phy";
+			reg = <0x100f8830 0x30>;
+			clocks = <&gcc USB30_0_MASTER_CLK>;
+			clock-names = "ref";
+			#phy-cells = <0>;
+
+			status = "ok";
+		};
Documentation/devicetree/bindings/usb/qcom,dwc3.txt new file +66 -0

66 lines not on this page · raw message

Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
hosted by The Linux Foundation
#2 lore raw

Re: [Patch v9 1/3] usb: dwc3: qcom: Add device tree binding

Hi Andy,

Documentation/devicetree/bindings/usb/qcom,dwc3.txt line 27

Quoted 5 lines · Andy Gross
Documentation/devicetree/bindings/usb/qcom,dwc3.txt new file +5 -0
+Example device nodes:
+
+		hs_phy: phy at 100f8800 {
+			compatible = "qcom,dwc3-hs-usb-phy";
+			reg = <0x100f8800 0x30>;

Just wanted to point out that in our downstream code, the glue device/driver, i.e. "qcom,dwc3", does claim an entire register region that encompasses the same registers used by these PHYs. I noticed you're not adding a reg resource to the glue node below in this patchset. In order to allow multiple devices to use the overlapping regions, we avoid calling devm_ioremap_resource() and instead call devm_ioremap_nocache() directly which bypasses the request_mem_region() call, which I don't think is an entirely correct thing to do.

On the other hand I'm trying to think of use cases on our other SOCs (MSM8974, APQ8084) where the glue actually would need access to the same or adjacent IO registers that couldn't just be handled directly by these PHY drivers. Should we accommodate for the potential of overlapping regions or should we just hold the line here and maybe only expose with finer granularity the registers that will actually be needed by the PHYs & glue respectively?

Quoted 29 lines
Documentation/devicetree/bindings/usb/qcom,dwc3.txt new file +29 -0
+			clocks = <&gcc USB30_0_UTMI_CLK>;
+			clock-names = "ref";
+			#phy-cells = <0>;
+
+			status = "ok";
+		};
+
+		ss_phy: phy at 100f8830 {
+			compatible = "qcom,dwc3-ss-usb-phy";
+			reg = <0x100f8830 0x30>;
+			clocks = <&gcc USB30_0_MASTER_CLK>;
+			clock-names = "ref";
+			#phy-cells = <0>;
+
+			status = "ok";
+		};
+
+		usb3_0: usb30 at 0 {
+			compatible = "qcom,dwc3";
+			#address-cells = <1>;
+			#size-cells = <1>;
+			clocks = <&gcc USB30_0_MASTER_CLK>;
+			clock-names = "core";
+
+			ranges;
+
+			status = "ok";
+
+			dwc3 at 10000000 {

Documentation/devicetree/bindings/usb/qcom,dwc3.txt line 66

Quoted 10 lines
Documentation/devicetree/bindings/usb/qcom,dwc3.txt new file +10 -0
+				compatible = "snps,dwc3";
+				reg = <0x10000000 0xcd00>;
+				interrupts = <0 205 0x4>;
+				phys = <&hs_phy>, <&ss_phy>;
+				phy-names = "usb2-phy", "usb3-phy";
+				tx-fifo-resize;
+				dr_mode = "host";
+			};
+		};
+

Thanks,
Jack

Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation
#3 lore raw

Re: [Patch v9 1/3] usb: dwc3: qcom: Add device tree binding

Hi,

Quoted 18 lines · Jack Pham

Hi Andy,

Documentation/devicetree/bindings/usb/qcom,dwc3.txt line 27

Quoted 5 lines · Andy Gross
Documentation/devicetree/bindings/usb/qcom,dwc3.txt new file +5 -0
+Example device nodes:
+
+		hs_phy: phy at 100f8800 {
+			compatible = "qcom,dwc3-hs-usb-phy";
+			reg = <0x100f8800 0x30>;

Just wanted to point out that in our downstream code, the glue device/driver, i.e. "qcom,dwc3", does claim an entire register region that encompasses the same registers used by these PHYs. I noticed you're not adding a reg resource to the glue node below in this patchset. In order to allow multiple devices to use the overlapping regions, we avoid calling devm_ioremap_resource() and instead call devm_ioremap_nocache() directly which bypasses the request_mem_region() call, which I don't think is an entirely correct thing to do.

Quoted 7 lines

On the other hand I'm trying to think of use cases on our other SOCs (MSM8974, APQ8084) where the glue actually would need access to the same or adjacent IO registers that couldn't just be handled directly by these PHY drivers. Should we accommodate for the potential of overlapping regions or should we just hold the line here and maybe only expose with finer granularity the registers that will actually be needed by the PHYs & glue respectively?

I prefer to keep things separated. Glue only needs to access whatever belongs to glue. If a register related to PHY settings, it should be in the PHY address space.

cheers

Signature · 8 lines
balbi
-------------- 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/20140916/b45ffe5a/attachment.sig>
author
#4 lore raw

PATCH v9 2/3 usb: dwc3: Add Qualcomm DWC3 glue layer driver

In reply to Andy Gross

From: "Ivan T. Ivanov" <[email protected]>

DWC3 glue layer is hardware layer around Synopsys DesignWare USB3 core. Its purpose is to supply Synopsys IP with required clocks, voltages and interface it with the rest of the SoC.

---
 drivers/usb/dwc3/Kconfig     |    8 +++
 drivers/usb/dwc3/Makefile    |    1 +
 drivers/usb/dwc3/dwc3-qcom.c |  131 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 140 insertions(+)
 create mode 100644 drivers/usb/dwc3/dwc3-qcom.c
drivers/usb/dwc3/Kconfig +8 -0
index 785510a..a816fe4 100644
@@ -80,6 +80,14 @@ config USB_DWC3_KEYSTONE
 	  Support of USB2/3 functionality in TI Keystone2 platforms.
 	  Say 'Y' or 'M' here if you have one such device
 
+config USB_DWC3_QCOM
+	tristate "Qualcomm Platforms"
+	depends on ARCH_QCOM || COMPILE_TEST
+	default USB_DWC3
+	help
+	  Recent Qualcomm SoCs ship with one DesignWare Core USB3 IP inside,
+	  say 'Y' or 'M' if you have one such device.
+
 comment "Debugging features"
 
 config USB_DWC3_DEBUG
drivers/usb/dwc3/Makefile +1 -0
index 10ac3e7..0da8e75 100644
@@ -33,3 +33,4 @@ obj-$(CONFIG_USB_DWC3_OMAP)		+= dwc3-omap.o
 obj-$(CONFIG_USB_DWC3_EXYNOS)		+= dwc3-exynos.o
 obj-$(CONFIG_USB_DWC3_PCI)		+= dwc3-pci.o
 obj-$(CONFIG_USB_DWC3_KEYSTONE)		+= dwc3-keystone.o
+obj-$(CONFIG_USB_DWC3_QCOM)		+= dwc3-qcom.o
drivers/usb/dwc3/dwc3-qcom.c new file +131 -0

131 lines not on this page · raw message

Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
hosted by The Linux Foundation

A message that is not in the archive (sent off-list or not yet received): CAMf-jSm2fPPstFD2h4-gG=MCDty34f-O0ooizDEKyQUd3+CxGQ@mail.gmail.com

#6 lore raw

Re: [Patch v9 2/3] usb: dwc3: Add Qualcomm DWC3 glue layer driver

Quoted 25 lines · Pramod Gurav

Andy,
Couple of minor comments.

Quoted 17 lines · Andy Gross

From: "Ivan T. Ivanov" <[email protected]>

DWC3 glue layer is hardware layer around Synopsys DesignWare USB3 core. Its purpose is to supply Synopsys IP with required clocks, voltages and interface it with the rest of the SoC.

---
 drivers/usb/dwc3/Kconfig     |    8 +++
 drivers/usb/dwc3/Makefile    |    1 +
 drivers/usb/dwc3/dwc3-qcom.c |  131
++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 140 insertions(+)
 create mode 100644 drivers/usb/dwc3/dwc3-qcom.c

<..>

Quoted 7 lines

drivers/usb/dwc3/dwc3-qcom.c line 23

Quoted 6 lines
drivers/usb/dwc3/dwc3-qcom.c new file +5 -0
+#include <linux/platform_device.h>
+
+struct dwc3_qcom {
+       struct device           *dev;
+

Extra new line here.

that's not an issue however.

Quoted 4 lines
Quoted 4 lines
drivers/usb/dwc3/dwc3-qcom.c new file +4 -0
+       struct clk              *core_clk;
+       struct clk              *iface_clk;
+       struct clk              *sleep_clk;
+};
Quoted 8 lines

drivers/usb/dwc3/dwc3-qcom.c line 33

Quoted 7 lines
drivers/usb/dwc3/dwc3-qcom.c new file +6 -0
+
+static int dwc3_qcom_probe(struct platform_device *pdev)
+{
+       struct device_node *node = pdev->dev.of_node;
+       struct dwc3_qcom *qdwc;
+       int ret = 0;

Initialization not required.

I'll fix this one as I'm already applying this patch.

Quoted 28 lines
Quoted 28 lines
drivers/usb/dwc3/dwc3-qcom.c new file +28 -0
+
+       qdwc = devm_kzalloc(&pdev->dev, sizeof(*qdwc), GFP_KERNEL);
+       if (!qdwc)
+               return -ENOMEM;
+
+       platform_set_drvdata(pdev, qdwc);
+
+       qdwc->dev = &pdev->dev;
+
+       qdwc->core_clk = devm_clk_get(qdwc->dev, "core");
+       if (IS_ERR(qdwc->core_clk)) {
+               dev_err(qdwc->dev, "failed to get core clock\n");
+               return PTR_ERR(qdwc->core_clk);
+       }
+
+       qdwc->iface_clk = devm_clk_get(qdwc->dev, "iface");
+       if (IS_ERR(qdwc->iface_clk)) {
+               dev_dbg(qdwc->dev, "failed to get optional iface clock\n");
+               qdwc->iface_clk = NULL;
+       }
+
+       qdwc->sleep_clk = devm_clk_get(qdwc->dev, "sleep");
+       if (IS_ERR(qdwc->sleep_clk)) {
+               dev_dbg(qdwc->dev, "failed to get optional sleep clock\n");
+               qdwc->sleep_clk = NULL;
+       }
+
+       ret = clk_prepare_enable(qdwc->core_clk);
Quoted 8 lines

drivers/usb/dwc3/dwc3-qcom.c line 67

Quoted 7 lines
drivers/usb/dwc3/dwc3-qcom.c new file +6 -0
+       if (ret) {
+               dev_err(qdwc->dev, "failed to enable core clock\n");
+               goto err_core;
+       }
+
+       ret = clk_prepare_enable(qdwc->iface_clk);

Should not we check if qdwc->iface_clk is valid?

read the sources luke.

Quoted 5 lines

Review

Quoted 3 lines
(quoted diff) +2 -0
+err_clks:
+       clk_disable_unprepare(qdwc->sleep_clk);

IS_ERR check before above statement not needed as we have continued with probe even after failure og devm_clk_get?

read more carefully, there's a detail which you're missing.

Signature · 8 lines
balbi
-------------- 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/20140912/10f96815/attachment-0001.sig>
#7 lore raw

Re: [Patch v9 2/3] usb: dwc3: Add Qualcomm DWC3 glue layer driver

Hi Felipe,

Quoted 88 lines · Felipe Balbi
Quoted 25 lines · Pramod Gurav

Andy,
Couple of minor comments.

Quoted 17 lines · Andy Gross

From: "Ivan T. Ivanov" <[email protected]>

DWC3 glue layer is hardware layer around Synopsys DesignWare USB3 core. Its purpose is to supply Synopsys IP with required clocks, voltages and interface it with the rest of the SoC.

---
 drivers/usb/dwc3/Kconfig     |    8 +++
 drivers/usb/dwc3/Makefile    |    1 +
 drivers/usb/dwc3/dwc3-qcom.c |  131
++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 140 insertions(+)
 create mode 100644 drivers/usb/dwc3/dwc3-qcom.c

<..>

Quoted 7 lines

drivers/usb/dwc3/dwc3-qcom.c line 23

Quoted 6 lines
drivers/usb/dwc3/dwc3-qcom.c new file +5 -0
+#include <linux/platform_device.h>
+
+struct dwc3_qcom {
+       struct device           *dev;
+

Extra new line here.

that's not an issue however.

Quoted 4 lines
Quoted 4 lines
drivers/usb/dwc3/dwc3-qcom.c new file +4 -0
+       struct clk              *core_clk;
+       struct clk              *iface_clk;
+       struct clk              *sleep_clk;
+};
Quoted 8 lines

drivers/usb/dwc3/dwc3-qcom.c line 33

Quoted 7 lines
drivers/usb/dwc3/dwc3-qcom.c new file +6 -0
+
+static int dwc3_qcom_probe(struct platform_device *pdev)
+{
+       struct device_node *node = pdev->dev.of_node;
+       struct dwc3_qcom *qdwc;
+       int ret = 0;

Initialization not required.

I'll fix this one as I'm already applying this patch.

Quoted 28 lines
Quoted 28 lines
drivers/usb/dwc3/dwc3-qcom.c new file +28 -0
+
+       qdwc = devm_kzalloc(&pdev->dev, sizeof(*qdwc), GFP_KERNEL);
+       if (!qdwc)
+               return -ENOMEM;
+
+       platform_set_drvdata(pdev, qdwc);
+
+       qdwc->dev = &pdev->dev;
+
+       qdwc->core_clk = devm_clk_get(qdwc->dev, "core");
+       if (IS_ERR(qdwc->core_clk)) {
+               dev_err(qdwc->dev, "failed to get core clock\n");
+               return PTR_ERR(qdwc->core_clk);
+       }
+
+       qdwc->iface_clk = devm_clk_get(qdwc->dev, "iface");
+       if (IS_ERR(qdwc->iface_clk)) {
+               dev_dbg(qdwc->dev, "failed to get optional iface clock\n");
+               qdwc->iface_clk = NULL;
+       }
+
+       qdwc->sleep_clk = devm_clk_get(qdwc->dev, "sleep");
+       if (IS_ERR(qdwc->sleep_clk)) {
+               dev_dbg(qdwc->dev, "failed to get optional sleep clock\n");
+               qdwc->sleep_clk = NULL;
+       }
+
+       ret = clk_prepare_enable(qdwc->core_clk);
Quoted 8 lines

drivers/usb/dwc3/dwc3-qcom.c line 67

Quoted 7 lines
drivers/usb/dwc3/dwc3-qcom.c new file +6 -0
+       if (ret) {
+               dev_err(qdwc->dev, "failed to enable core clock\n");
+               goto err_core;
+       }
+
+       ret = clk_prepare_enable(qdwc->iface_clk);

Should not we check if qdwc->iface_clk is valid?

Quoted 1 line

read the sources luke.

Now I read that its initialized to NULL in fail case but should we call prepare_enable at all if its NULL?

Quoted 9 lines
Quoted 6 lines

Review

Quoted 4 lines
(quoted diff) +2 -0
+err_clks:
+       clk_disable_unprepare(qdwc->sleep_clk);

IS_ERR check before above statement not needed as we have continued with probe even after failure og devm_clk_get?

read more carefully, there's a detail which you're missing.

#8 lore raw

Re: [Patch v9 2/3] usb: dwc3: Add Qualcomm DWC3 glue layer driver

Hi,

Quoted 36 lines · Pramod Gurav
Quoted 36 lines
Quoted 35 lines
Quoted 24 lines
drivers/usb/dwc3/dwc3-qcom.c new file +23 -0
+       qdwc = devm_kzalloc(&pdev->dev, sizeof(*qdwc), GFP_KERNEL);
+       if (!qdwc)
+               return -ENOMEM;
+
+       platform_set_drvdata(pdev, qdwc);
+
+       qdwc->dev = &pdev->dev;
+
+       qdwc->core_clk = devm_clk_get(qdwc->dev, "core");
+       if (IS_ERR(qdwc->core_clk)) {
+               dev_err(qdwc->dev, "failed to get core clock\n");
+               return PTR_ERR(qdwc->core_clk);
+       }
+
+       qdwc->iface_clk = devm_clk_get(qdwc->dev, "iface");
+       if (IS_ERR(qdwc->iface_clk)) {
+               dev_dbg(qdwc->dev, "failed to get optional iface clock\n");
+               qdwc->iface_clk = NULL;
+       }
+
+       qdwc->sleep_clk = devm_clk_get(qdwc->dev, "sleep");
+       if (IS_ERR(qdwc->sleep_clk)) {
+               dev_dbg(qdwc->dev, "failed to get optional sleep clock\n");

drivers/usb/dwc3/dwc3-qcom.c line 67

Quoted 10 lines
drivers/usb/dwc3/dwc3-qcom.c new file +10 -0
+               qdwc->sleep_clk = NULL;
+       }
+
+       ret = clk_prepare_enable(qdwc->core_clk);
+       if (ret) {
+               dev_err(qdwc->dev, "failed to enable core clock\n");
+               goto err_core;
+       }
+
+       ret = clk_prepare_enable(qdwc->iface_clk);

Should not we check if qdwc->iface_clk is valid?

Quoted 3 lines
Quoted 1 line

read the sources luke.

Now I read that its initialized to NULL in fail case but should we call prepare_enable at all if its NULL?

now read the source of clk_enable() and clk_prepare() ;-) NULL is a valid clock, it just returns 0. This is better than sprinkling IS_ERR() all over the place.

Signature · 8 lines
balbi
-------------- 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/20140912/c311eead/attachment.sig>
#9 lore raw

Re: [Patch v9 2/3] usb: dwc3: Add Qualcomm DWC3 glue layer driver

Quoted 39 lines · Felipe Balbi

Hi,

Quoted 36 lines · Pramod Gurav
Quoted 36 lines
Quoted 35 lines
Quoted 24 lines
drivers/usb/dwc3/dwc3-qcom.c new file +23 -0
+       qdwc = devm_kzalloc(&pdev->dev, sizeof(*qdwc), GFP_KERNEL);
+       if (!qdwc)
+               return -ENOMEM;
+
+       platform_set_drvdata(pdev, qdwc);
+
+       qdwc->dev = &pdev->dev;
+
+       qdwc->core_clk = devm_clk_get(qdwc->dev, "core");
+       if (IS_ERR(qdwc->core_clk)) {
+               dev_err(qdwc->dev, "failed to get core clock\n");
+               return PTR_ERR(qdwc->core_clk);
+       }
+
+       qdwc->iface_clk = devm_clk_get(qdwc->dev, "iface");
+       if (IS_ERR(qdwc->iface_clk)) {
+               dev_dbg(qdwc->dev, "failed to get optional iface clock\n");
+               qdwc->iface_clk = NULL;
+       }
+
+       qdwc->sleep_clk = devm_clk_get(qdwc->dev, "sleep");
+       if (IS_ERR(qdwc->sleep_clk)) {
+               dev_dbg(qdwc->dev, "failed to get optional sleep clock\n");

drivers/usb/dwc3/dwc3-qcom.c line 67

Quoted 10 lines
drivers/usb/dwc3/dwc3-qcom.c new file +10 -0
+               qdwc->sleep_clk = NULL;
+       }
+
+       ret = clk_prepare_enable(qdwc->core_clk);
+       if (ret) {
+               dev_err(qdwc->dev, "failed to enable core clock\n");
+               goto err_core;
+       }
+
+       ret = clk_prepare_enable(qdwc->iface_clk);

Should not we check if qdwc->iface_clk is valid?

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

read the sources luke.

Now I read that its initialized to NULL in fail case but should we call prepare_enable at all if its NULL?

now read the source of clk_enable() and clk_prepare() ;-) NULL is a valid clock, it just returns 0. This is better than sprinkling IS_ERR() all over the place.

Seen that. I was wrong about IS_ERR. Thanks. :)

Quoted 1 line
author
#10 lore raw

PATCH v9 3/3 phy: Add Qualcomm DWC3 HS/SS PHY driver

In reply to Andy Gross

This patch adds a new driver for the Qualcomm USB 3.0 PHY that exists on some Qualcomm platforms. This driver uses the generic PHY framework and will interact with the DWC3 controller.

---
 drivers/phy/Kconfig         |   11 +
 drivers/phy/Makefile        |    1 +
 drivers/phy/phy-qcom-dwc3.c |  483 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 495 insertions(+)
 create mode 100644 drivers/phy/phy-qcom-dwc3.c
drivers/phy/Kconfig +11 -0
index 0dd7427..5d56161 100644
@@ -230,4 +230,15 @@ config PHY_XGENE
 	help
 	  This option enables support for APM X-Gene SoC multi-purpose PHY.
 
+config PHY_QCOM_DWC3
+	tristate "QCOM DWC3 USB PHY support"
+	depends on ARCH_QCOM
+	depends on HAS_IOMEM
+	depends on OF
+	select GENERIC_PHY
+	help
+	  This option enables support for the Synopsis PHYs present inside the
+	  Qualcomm USB3.0 DWC3 controller.  This driver supports both HS and SS
+	  PHY controllers.
+
 endmenu
drivers/phy/Makefile +1 -0
index 95c69ed..aa16f30 100644
@@ -28,3 +28,4 @@ obj-$(CONFIG_PHY_QCOM_IPQ806X_SATA)	+= phy-qcom-ipq806x-sata.o
 obj-$(CONFIG_PHY_ST_SPEAR1310_MIPHY)	+= phy-spear1310-miphy.o
 obj-$(CONFIG_PHY_ST_SPEAR1340_MIPHY)	+= phy-spear1340-miphy.o
 obj-$(CONFIG_PHY_XGENE)			+= phy-xgene.o
+obj-$(CONFIG_PHY_QCOM_DWC3)		+= phy-qcom-dwc3.o
drivers/phy/phy-qcom-dwc3.c new file +483 -0

483 lines not on this page · raw message

Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
hosted by The Linux Foundation
#11 lore raw

Re: [Patch v9 3/3] phy: Add Qualcomm DWC3 HS/SS PHY driver

Hi,

Quoted 3 lines · Andy Gross

This patch adds a new driver for the Qualcomm USB 3.0 PHY that exists on some Qualcomm platforms. This driver uses the generic PHY framework and will interact with the DWC3 controller.

Do you have dt documentation for this driver?

Quoted 66 lines
---
 drivers/phy/Kconfig         |   11 +
 drivers/phy/Makefile        |    1 +
 drivers/phy/phy-qcom-dwc3.c |  483 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 495 insertions(+)
 create mode 100644 drivers/phy/phy-qcom-dwc3.c
drivers/phy/Kconfig +11 -0
index 0dd7427..5d56161 100644
@@ -230,4 +230,15 @@ config PHY_XGENE
 	help
 	  This option enables support for APM X-Gene SoC multi-purpose PHY.
 
+config PHY_QCOM_DWC3
+	tristate "QCOM DWC3 USB PHY support"
+	depends on ARCH_QCOM
+	depends on HAS_IOMEM
+	depends on OF
+	select GENERIC_PHY
+	help
+	  This option enables support for the Synopsis PHYs present inside the
+	  Qualcomm USB3.0 DWC3 controller.  This driver supports both HS and SS
+	  PHY controllers.
+
 endmenu
drivers/phy/Makefile +1 -0
index 95c69ed..aa16f30 100644
@@ -28,3 +28,4 @@ obj-$(CONFIG_PHY_QCOM_IPQ806X_SATA)	+= phy-qcom-ipq806x-sata.o
 obj-$(CONFIG_PHY_ST_SPEAR1310_MIPHY)	+= phy-spear1310-miphy.o
 obj-$(CONFIG_PHY_ST_SPEAR1340_MIPHY)	+= phy-spear1340-miphy.o
 obj-$(CONFIG_PHY_XGENE)			+= phy-xgene.o
+obj-$(CONFIG_PHY_QCOM_DWC3)		+= phy-qcom-dwc3.o
drivers/phy/phy-qcom-dwc3.c new file +22 -0
new file mode 100644
index 0000000..2c7b316
@@ -0,0 +1,483 @@
+/* Copyright (c) 2013-2014, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/clk.h>
+#include <linux/err.h>
+#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/phy/phy.h>
+#include <linux/platform_device.h>
+#include <linux/delay.h>
+
+/**

drivers/phy/phy-qcom-dwc3.c line 32

Quoted 10 lines
drivers/phy/phy-qcom-dwc3.c new file +10 -0
+ *  USB QSCRATCH Hardware registers
+ */
+#define QSCRATCH_GENERAL_CFG		(0x08)
+#define HSUSB_PHY_CTRL_REG		(0x10)
+
+/* PHY_CTRL_REG */
+#define HSUSB_CTRL_DMSEHV_CLAMP			BIT(24)
+#define HSUSB_CTRL_USB2_SUSPEND			BIT(23)
+#define HSUSB_CTRL_UTMI_CLK_EN			BIT(21)
+#define	HSUSB_CTRL_UTMI_OTG_VBUS_VALID		BIT(20)
	  ^^^^

alignment went wrong here..

Quoted 49 lines
drivers/phy/phy-qcom-dwc3.c new file +49 -0
+#define HSUSB_CTRL_USE_CLKCORE			BIT(18)
+#define HSUSB_CTRL_DPSEHV_CLAMP			BIT(17)
+#define HSUSB_CTRL_COMMONONN			BIT(11)
+#define HSUSB_CTRL_ID_HV_CLAMP			BIT(9)
+#define HSUSB_CTRL_OTGSESSVLD_CLAMP		BIT(8)
+#define HSUSB_CTRL_CLAMP_EN			BIT(7)
+#define HSUSB_CTRL_RETENABLEN			BIT(1)
+#define HSUSB_CTRL_POR				BIT(0)
+
+/* QSCRATCH_GENERAL_CFG */
+#define HSUSB_GCFG_XHCI_REV		BIT(2)
+
+/**
+ *  USB QSCRATCH Hardware registers
+ */
+#define SSUSB_PHY_CTRL_REG		(0x00)
+#define SSUSB_PHY_PARAM_CTRL_1		(0x04)
+#define SSUSB_PHY_PARAM_CTRL_2		(0x08)
+#define CR_PROTOCOL_DATA_IN_REG		(0x0c)
+#define CR_PROTOCOL_DATA_OUT_REG	(0x10)
+#define CR_PROTOCOL_CAP_ADDR_REG	(0x14)
+#define CR_PROTOCOL_CAP_DATA_REG	(0x18)
+#define CR_PROTOCOL_READ_REG		(0x1c)
+#define CR_PROTOCOL_WRITE_REG		(0x20)
+
+/* PHY_CTRL_REG */
+#define SSUSB_CTRL_REF_USE_PAD		BIT(28)
+#define SSUSB_CTRL_TEST_POWERDOWN	BIT(27)
+#define SSUSB_CTRL_LANE0_PWR_PRESENT	BIT(24)
+#define SSUSB_CTRL_SS_PHY_EN		BIT(8)
+#define SSUSB_CTRL_SS_PHY_RESET		BIT(7)
+
+/* SSPHY control registers */
+#define SSPHY_CTRL_RX_OVRD_IN_HI(lane)	(0x1006 + 0x100 * lane)
+#define SSPHY_CTRL_TX_OVRD_DRV_LO(lane)	(0x1002 + 0x100 * lane)
+
+/* RX OVRD IN HI bits */
+#define RX_OVRD_IN_HI_RX_RESET_OVRD		BIT(13)
+#define RX_OVRD_IN_HI_RX_RX_RESET		BIT(12)
+#define RX_OVRD_IN_HI_RX_EQ_OVRD		BIT(11)
+#define RX_OVRD_IN_HI_RX_EQ_MASK		0x0700
+#define RX_OVRD_IN_HI_RX_EQ_SHIFT		8
+#define RX_OVRD_IN_HI_RX_EQ_EN_OVRD		BIT(7)
+#define RX_OVRD_IN_HI_RX_EQ_EN			BIT(6)
+#define RX_OVRD_IN_HI_RX_LOS_FILTER_OVRD	BIT(5)
+#define RX_OVRD_IN_HI_RX_LOS_FILTER_MASK	0x0018
+#define RX_OVRD_IN_HI_RX_RATE_OVRD		BIT(2)
+#define RX_OVRD_IN_HI_RX_RATE_MASK		0x0003
+

drivers/phy/phy-qcom-dwc3.c line 91

Quoted 10 lines
drivers/phy/phy-qcom-dwc3.c new file +10 -0
+/* TX OVRD DRV LO register bits */
+#define TX_OVRD_DRV_LO_AMPLITUDE_MASK	0x007F
+#define TX_OVRD_DRV_LO_PREEMPH_MASK	0x3F80
+#define TX_OVRD_DRV_LO_PREEMPH_SHIFT	7
+#define TX_OVRD_DRV_LO_EN		BIT(14)
+
+struct qcom_dwc3_usb_phy {
+	void __iomem		*base;
+	struct device		*dev;
+	struct phy *phy;
		  ^^

Pls keep the alignment same for all the members..

Quoted 18 lines
drivers/phy/phy-qcom-dwc3.c new file +18 -0
+
+	int (*phy_init)(struct qcom_dwc3_usb_phy *phy_dwc3);
+	int (*phy_exit)(struct qcom_dwc3_usb_phy *phy_dwc3);
+
+	struct clk		*xo_clk;
+	struct clk		*ref_clk;
+};
+
+/**
+ * Write register and read back masked value to confirm it is written
+ *
+ * @base - QCOM DWC3 PHY base virtual address.
+ * @offset - register offset.
+ * @mask - register bitmask specifying what should be updated
+ * @val - value to write.
+ */
+static inline void qcom_dwc3_phy_write_readback(
+	struct qcom_dwc3_usb_phy *phy_dwc3, u32 offset,

drivers/phy/phy-qcom-dwc3.c line 119

Quoted 10 lines
drivers/phy/phy-qcom-dwc3.c new file +10 -0
+	const u32 mask, u32 val)
+{
+	u32 write_val, tmp = readl(phy_dwc3->base + offset);
+
+	tmp &= ~mask;		/* retain other bits */
+	write_val = tmp | val;
+
+	writel(write_val, phy_dwc3->base + offset);
+
+	/* Read back to see if val was written */

Does it fail sometime? I'm not sure if this should be present in the driver since this looks more of a debug code.

Quoted 28 lines
drivers/phy/phy-qcom-dwc3.c new file +28 -0
+	tmp = readl(phy_dwc3->base + offset);
+	tmp &= mask;		/* clear other bits */
+
+	if (tmp != val)
+		dev_err(phy_dwc3->dev, "write: %x to QSCRATCH: %x FAILED\n",
+			val, offset);
+}
+
+static int wait_for_latch(void __iomem *addr)
+{
+	u32 retry = 10;
+
+	while (true) {
+		if (!readl(addr))
+			break;
+
+		if (--retry == 0)
+			return -ETIMEDOUT;
+
+		usleep_range(10, 20);
+	}
+
+	return 0;
+}
+
+/**
+ * Write SSPHY register
+ *

drivers/phy/phy-qcom-dwc3.c line 157

Quoted 10 lines
drivers/phy/phy-qcom-dwc3.c new file +10 -0
+ * @base - QCOM DWC3 PHY base virtual address.
+ * @addr - SSPHY address to write.
+ * @val - value to write.
+ */
+static int qcom_dwc3_ss_write_phycreg(void __iomem *base, u32 addr, u32 val)
+{
+	int ret;
+
+	writel(addr, base + CR_PROTOCOL_DATA_IN_REG);
+	writel(0x1, base + CR_PROTOCOL_CAP_ADDR_REG);

use macros here and below..

drivers/phy/phy-qcom-dwc3.c line 161

Quoted 4 lines
drivers/phy/phy-qcom-dwc3.c new file +4 -0
+
+	ret = wait_for_latch(base + CR_PROTOCOL_CAP_ADDR_REG);
+	if (ret)
+		goto err_wait;

a timed out error message here?

Quoted 36 lines
drivers/phy/phy-qcom-dwc3.c new file +36 -0
+
+	writel(val, base + CR_PROTOCOL_DATA_IN_REG);
+	writel(0x1, base + CR_PROTOCOL_CAP_DATA_REG);
+
+	ret = wait_for_latch(base + CR_PROTOCOL_CAP_DATA_REG);
+	if (ret)
+		goto err_wait;
+
+	writel(0x1, base + CR_PROTOCOL_WRITE_REG);
+
+	ret = wait_for_latch(base + CR_PROTOCOL_WRITE_REG);
+
+err_wait:
+	return ret;
+}
+
+/**
+ * Read SSPHY register.
+ *
+ * @base - QCOM DWC3 PHY base virtual address.
+ * @addr - SSPHY address to read.
+ */
+static int qcom_dwc3_ss_read_phycreg(void __iomem *base, u32 addr, u32 *val)
+{
+	int ret;
+	bool first_read = true;
+
+	writel(addr, base + CR_PROTOCOL_DATA_IN_REG);
+	writel(0x1, base + CR_PROTOCOL_CAP_ADDR_REG);
+
+	ret = wait_for_latch(base + CR_PROTOCOL_CAP_ADDR_REG);
+	if (ret)
+		goto err_wait;
+
+	/*
+	 * Due to hardware bug, first read of SSPHY register might be

drivers/phy/phy-qcom-dwc3.c line 207

Quoted 10 lines
drivers/phy/phy-qcom-dwc3.c new file +10 -0
+	 * incorrect. Hence as workaround, SW should perform SSPHY register
+	 * read twice, but use only second read and ignore first read.
+	 */
+retry:
+	writel(0x1, base + CR_PROTOCOL_READ_REG);
+
+	ret = wait_for_latch(base + CR_PROTOCOL_READ_REG);
+	if (ret)
+		goto err_wait;
+

_retry_ should be here? since only the read fails..

Quoted 62 lines
drivers/phy/phy-qcom-dwc3.c new file +62 -0
+	if (first_read) {
+		readl(base + CR_PROTOCOL_DATA_OUT_REG);
+		first_read = false;
+		goto retry;
+	}
+
+	*val = readl(base + CR_PROTOCOL_DATA_OUT_REG);
+
+err_wait:
+	return ret;
+}
+
+static int qcom_dwc3_phy_power_on(struct phy *phy)
+{
+	int ret;
+	struct qcom_dwc3_usb_phy *phy_dwc3 = phy_get_drvdata(phy);
+
+	ret = clk_prepare_enable(phy_dwc3->xo_clk);
+	if (ret)
+		return ret;
+
+	ret = clk_prepare_enable(phy_dwc3->ref_clk);
+	if (ret)
+		clk_disable_unprepare(phy_dwc3->xo_clk);
+
+	return ret;
+}
+
+static int qcom_dwc3_phy_power_off(struct phy *phy)
+{
+	struct qcom_dwc3_usb_phy *phy_dwc3 = phy_get_drvdata(phy);
+
+	clk_disable_unprepare(phy_dwc3->ref_clk);
+	clk_disable_unprepare(phy_dwc3->xo_clk);
+
+	return 0;
+}
+
+static int qcom_dwc3_hs_phy_init(struct qcom_dwc3_usb_phy *phy_dwc3)
+{
+	u32 val;
+
+	/*
+	 * HSPHY Initialization: Enable UTMI clock, select 19.2MHz fsel
+	 * enable clamping, and disable RETENTION (power-on default is ENABLED)
+	 */
+	val = HSUSB_CTRL_DPSEHV_CLAMP | HSUSB_CTRL_DMSEHV_CLAMP |
+		HSUSB_CTRL_RETENABLEN  | HSUSB_CTRL_COMMONONN |
+		HSUSB_CTRL_OTGSESSVLD_CLAMP | HSUSB_CTRL_ID_HV_CLAMP |
+		HSUSB_CTRL_DPSEHV_CLAMP | HSUSB_CTRL_UTMI_OTG_VBUS_VALID |
+		HSUSB_CTRL_UTMI_CLK_EN | HSUSB_CTRL_CLAMP_EN | 0x70;
+
+	/* use core clock if external reference is not present */
+	if (!phy_dwc3->xo_clk)
+		val |= HSUSB_CTRL_USE_CLKCORE;
+
+	writel(val, phy_dwc3->base + HSUSB_PHY_CTRL_REG);
+	usleep_range(2000, 2200);
+
+	/* Disable (bypass) VBUS and ID filters */
+	writel(HSUSB_GCFG_XHCI_REV, phy_dwc3->base + QSCRATCH_GENERAL_CFG);
+

drivers/phy/phy-qcom-dwc3.c line 279

Quoted 10 lines
drivers/phy/phy-qcom-dwc3.c new file +10 -0
+	return 0;
+}
+
+static int qcom_dwc3_ss_phy_init(struct qcom_dwc3_usb_phy *phy_dwc3)
+{
+	int ret;
+	u32 data = 0;
+
+	/* reset phy */
+	data = readl_relaxed(phy_dwc3->base + SSUSB_PHY_CTRL_REG);

Why readl_relaxed here?

drivers/phy/phy-qcom-dwc3.c line 282

Quoted 3 lines
drivers/phy/phy-qcom-dwc3.c new file +3 -0
+	writel_relaxed(data | SSUSB_CTRL_SS_PHY_RESET,
+		phy_dwc3->base + SSUSB_PHY_CTRL_REG);
+	usleep_range(2000, 2200);

use msleep here..

drivers/phy/phy-qcom-dwc3.c line 292

Quoted 10 lines
drivers/phy/phy-qcom-dwc3.c new file +10 -0
+	writel_relaxed(data, phy_dwc3->base + SSUSB_PHY_CTRL_REG);
+
+	/* clear REF_PAD if we don't have XO clk */
+	if (!phy_dwc3->xo_clk)
+		data &= ~SSUSB_CTRL_REF_USE_PAD;
+	else
+		data |= SSUSB_CTRL_REF_USE_PAD;
+
+	writel_relaxed(data, phy_dwc3->base + SSUSB_PHY_CTRL_REG);
+	msleep(30);

add a comment on why this delay is required. If the hw spec gives this delay, note it here.

Quoted 57 lines
drivers/phy/phy-qcom-dwc3.c new file +57 -0
+
+	data |= SSUSB_CTRL_SS_PHY_EN | SSUSB_CTRL_LANE0_PWR_PRESENT;
+	writel_relaxed(data, phy_dwc3->base + SSUSB_PHY_CTRL_REG);
+
+	/*
+	 * Fix RX Equalization setting as follows
+	 * LANE0.RX_OVRD_IN_HI. RX_EQ_EN set to 0
+	 * LANE0.RX_OVRD_IN_HI.RX_EQ_EN_OVRD set to 1
+	 * LANE0.RX_OVRD_IN_HI.RX_EQ set to 3
+	 * LANE0.RX_OVRD_IN_HI.RX_EQ_OVRD set to 1
+	 */
+	ret = qcom_dwc3_ss_read_phycreg(phy_dwc3->base,
+			SSPHY_CTRL_RX_OVRD_IN_HI(0), &data);
+	if (ret)
+		goto err_phy_trans;
+
+	data &= ~RX_OVRD_IN_HI_RX_EQ_EN;
+	data |= RX_OVRD_IN_HI_RX_EQ_EN_OVRD;
+	data &= ~RX_OVRD_IN_HI_RX_EQ_MASK;
+	data |= 0x3 << RX_OVRD_IN_HI_RX_EQ_SHIFT;
+	data |= RX_OVRD_IN_HI_RX_EQ_OVRD;
+	ret = qcom_dwc3_ss_write_phycreg(phy_dwc3->base,
+		SSPHY_CTRL_RX_OVRD_IN_HI(0), data);
+	if (ret)
+		goto err_phy_trans;
+
+	/*
+	 * Set EQ and TX launch amplitudes as follows
+	 * LANE0.TX_OVRD_DRV_LO.PREEMPH set to 22
+	 * LANE0.TX_OVRD_DRV_LO.AMPLITUDE set to 127
+	 * LANE0.TX_OVRD_DRV_LO.EN set to 1.
+	 */
+	ret = qcom_dwc3_ss_read_phycreg(phy_dwc3->base,
+		SSPHY_CTRL_TX_OVRD_DRV_LO(0), &data);
+	if (ret)
+		goto err_phy_trans;
+
+	data &= ~TX_OVRD_DRV_LO_PREEMPH_MASK;
+	data |= 0x16 << TX_OVRD_DRV_LO_PREEMPH_SHIFT;
+	data &= ~TX_OVRD_DRV_LO_AMPLITUDE_MASK;
+	data |= 0x7f;
+	data |= TX_OVRD_DRV_LO_EN;
+	ret = qcom_dwc3_ss_write_phycreg(phy_dwc3->base,
+		SSPHY_CTRL_TX_OVRD_DRV_LO(0), data);
+	if (ret)
+		goto err_phy_trans;
+
+	/*
+	 * Set the QSCRATCH PHY_PARAM_CTRL1 parameters as follows
+	 * TX_FULL_SWING [26:20] amplitude to 127
+	 * TX_DEEMPH_3_5DB [13:8] to 22
+	 * LOS_BIAS [2:0] to 0x5
+	 */
+	qcom_dwc3_phy_write_readback(phy_dwc3, SSUSB_PHY_PARAM_CTRL_1,
+				   0x07f03f07, 0x07f01605);
+
+err_phy_trans:

drivers/phy/phy-qcom-dwc3.c line 359

Quoted 10 lines
drivers/phy/phy-qcom-dwc3.c new file +10 -0
+	return ret;
+}
+
+static int qcom_dwc3_ss_phy_exit(struct qcom_dwc3_usb_phy *phy_dwc3)
+{
+	/* Sequence to put SSPHY in low power state:
+	 * 1. Clear REF_PHY_EN in PHY_CTRL_REG
+	 * 2. Clear REF_USE_PAD in PHY_CTRL_REG
+	 * 3. Set TEST_POWERED_DOWN in PHY_CTRL_REG to enable PHY retention
+	 * 4. Disable SSPHY ref clk

The last step is missing below..

Quoted 7 lines
drivers/phy/phy-qcom-dwc3.c new file +7 -0
+	 */
+	qcom_dwc3_phy_write_readback(phy_dwc3, SSUSB_PHY_CTRL_REG,
+		SSUSB_CTRL_SS_PHY_EN, 0x0);
+	qcom_dwc3_phy_write_readback(phy_dwc3, SSUSB_PHY_CTRL_REG,
+		SSUSB_CTRL_REF_USE_PAD, 0x0);
+	qcom_dwc3_phy_write_readback(phy_dwc3, SSUSB_PHY_CTRL_REG,
+		0x0, SSUSB_CTRL_TEST_POWERDOWN);

drivers/phy/phy-qcom-dwc3.c line 376

Quoted 10 lines
drivers/phy/phy-qcom-dwc3.c new file +10 -0
+
+	return 0;
+}
+
+static int qcom_dwc3_phy_init(struct phy *phy)
+{
+	struct qcom_dwc3_usb_phy *phy_dwc3 = phy_get_drvdata(phy);
+
+	if (phy_dwc3->phy_init)
+		return phy_dwc3->phy_init(phy_dwc3);

This indirection is not needed at all. qcom_dwc3_ss_phy_init can be directly populated in probe depending on the PHY.

drivers/phy/phy-qcom-dwc3.c line 386

Quoted 10 lines
drivers/phy/phy-qcom-dwc3.c new file +10 -0
+
+	return 0;
+}
+
+static int qcom_dwc3_phy_exit(struct phy *phy)
+{
+	struct qcom_dwc3_usb_phy *phy_dwc3 = phy_get_drvdata(phy);
+
+	if (phy_dwc3->phy_exit)
+		return qcom_dwc3_ss_phy_exit(phy_dwc3);

you meant return phy_dwc3->phy_exit(phy_dwc3) here?

Thanks
Kishon

#12 lore raw

Re: [Patch v9 3/3] phy: Add Qualcomm DWC3 HS/SS PHY driver

Hi,

Quoted 6 lines · Kishon Vijay Abraham I
Quoted 3 lines · Andy Gross

This patch adds a new driver for the Qualcomm USB 3.0 PHY that exists on some Qualcomm platforms. This driver uses the generic PHY framework and will interact with the DWC3 controller.

Do you have dt documentation for this driver?

see patch 1

Quoted 7 lines
Quoted 7 lines
drivers/phy/phy-qcom-dwc3.c new file +7 -0
+static inline void qcom_dwc3_phy_write_readback(
+	struct qcom_dwc3_usb_phy *phy_dwc3, u32 offset,
+	const u32 mask, u32 val)
+{
+	u32 write_val, tmp = readl(phy_dwc3->base + offset);
+
+	tmp &= ~mask;		/* retain other bits */
Quoted 8 lines

drivers/phy/phy-qcom-dwc3.c line 119

Quoted 5 lines
drivers/phy/phy-qcom-dwc3.c new file +5 -0
+	write_val = tmp | val;
+
+	writel(write_val, phy_dwc3->base + offset);
+
+	/* Read back to see if val was written */

Does it fail sometime? I'm not sure if this should be present in the driver since this looks more of a debug code.

this was mentioned before. Silicon bug.

Quoted 5 lines

drivers/phy/phy-qcom-dwc3.c line 282

Quoted 3 lines
drivers/phy/phy-qcom-dwc3.c new file +3 -0
+	writel_relaxed(data | SSUSB_CTRL_SS_PHY_RESET,
+		phy_dwc3->base + SSUSB_PHY_CTRL_REG);
+	usleep_range(2000, 2200);

use msleep here..

why ? usleep_range() gives the scheduler oportunity to group timers.

Signature · 8 lines
balbi
-------------- 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/20140913/c5a41db9/attachment.sig>
#13 lore raw

Re: [Patch v9 3/3] phy: Add Qualcomm DWC3 HS/SS PHY driver

Hi,

Quoted 11 lines · Felipe Balbi

Hi,

Quoted 6 lines · Kishon Vijay Abraham I
Quoted 3 lines · Andy Gross

This patch adds a new driver for the Qualcomm USB 3.0 PHY that exists on some Qualcomm platforms. This driver uses the generic PHY framework and will interact with the DWC3 controller.

Do you have dt documentation for this driver?

see patch 1

hmm.. missed that.

Quoted 17 lines
Quoted 16 lines

drivers/phy/phy-qcom-dwc3.c line 119

Quoted 13 lines
drivers/phy/phy-qcom-dwc3.c new file +12 -0
+static inline void qcom_dwc3_phy_write_readback(
+	struct qcom_dwc3_usb_phy *phy_dwc3, u32 offset,
+	const u32 mask, u32 val)
+{
+	u32 write_val, tmp = readl(phy_dwc3->base + offset);
+
+	tmp &= ~mask;		/* retain other bits */
+	write_val = tmp | val;
+
+	writel(write_val, phy_dwc3->base + offset);
+
+	/* Read back to see if val was written */

Does it fail sometime? I'm not sure if this should be present in the driver since this looks more of a debug code.

Quoted 1 line

this was mentioned before. Silicon bug.

okay.

Quoted 8 lines
Quoted 6 lines

drivers/phy/phy-qcom-dwc3.c line 282

Quoted 4 lines
drivers/phy/phy-qcom-dwc3.c new file +3 -0
+	writel_relaxed(data | SSUSB_CTRL_SS_PHY_RESET,
+		phy_dwc3->base + SSUSB_PHY_CTRL_REG);
+	usleep_range(2000, 2200);

use msleep here..

why ? usleep_range() gives the scheduler oportunity to group timers.

Was of the opinion that for larger delays msleep should be used. But looks like it is only for 10+ ms (Documentation/timers/timers-howto.txt).

Thanks
Kishon

#14 lore raw

Re: [Patch v9 3/3] phy: Add Qualcomm DWC3 HS/SS PHY driver

In reply to Andy Gross

Hi Andy,

Quoted 13 lines · Andy Gross
drivers/phy/phy-qcom-dwc3.c new file +13 -0
+static int qcom_dwc3_hs_phy_init(struct qcom_dwc3_usb_phy *phy_dwc3)
+{
+	u32 val;
+
+	/*
+	 * HSPHY Initialization: Enable UTMI clock, select 19.2MHz fsel
+	 * enable clamping, and disable RETENTION (power-on default is ENABLED)
+	 */
+	val = HSUSB_CTRL_DPSEHV_CLAMP | HSUSB_CTRL_DMSEHV_CLAMP |
+		HSUSB_CTRL_RETENABLEN  | HSUSB_CTRL_COMMONONN |
+		HSUSB_CTRL_OTGSESSVLD_CLAMP | HSUSB_CTRL_ID_HV_CLAMP |
+		HSUSB_CTRL_DPSEHV_CLAMP | HSUSB_CTRL_UTMI_OTG_VBUS_VALID |
+		HSUSB_CTRL_UTMI_CLK_EN | HSUSB_CTRL_CLAMP_EN | 0x70;

drivers/phy/phy-qcom-dwc3.c line 268

Quoted 10 lines
drivers/phy/phy-qcom-dwc3.c new file +10 -0
+
+	/* use core clock if external reference is not present */
+	if (!phy_dwc3->xo_clk)
+		val |= HSUSB_CTRL_USE_CLKCORE;
+
+	writel(val, phy_dwc3->base + HSUSB_PHY_CTRL_REG);
+	usleep_range(2000, 2200);
+
+	/* Disable (bypass) VBUS and ID filters */
+	writel(HSUSB_GCFG_XHCI_REV, phy_dwc3->base + QSCRATCH_GENERAL_CFG);

Is this comment accurate? I believe this bit forces the IP to behave in XHCI rev 1.0. In which case, shouldn't it be done in the glue driver?

Jack

Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation
author
#15 lore raw

Re: [Patch v9 3/3] phy: Add Qualcomm DWC3 HS/SS PHY driver

Quoted 21 lines · Jack Pham

Hi Andy,

Quoted 18 lines · Andy Gross
drivers/phy/phy-qcom-dwc3.c new file +18 -0
+static int qcom_dwc3_hs_phy_init(struct qcom_dwc3_usb_phy *phy_dwc3)
+{
+	u32 val;
+
+	/*
+	 * HSPHY Initialization: Enable UTMI clock, select 19.2MHz fsel
+	 * enable clamping, and disable RETENTION (power-on default is ENABLED)
+	 */
+	val = HSUSB_CTRL_DPSEHV_CLAMP | HSUSB_CTRL_DMSEHV_CLAMP |
+		HSUSB_CTRL_RETENABLEN  | HSUSB_CTRL_COMMONONN |
+		HSUSB_CTRL_OTGSESSVLD_CLAMP | HSUSB_CTRL_ID_HV_CLAMP |
+		HSUSB_CTRL_DPSEHV_CLAMP | HSUSB_CTRL_UTMI_OTG_VBUS_VALID |
+		HSUSB_CTRL_UTMI_CLK_EN | HSUSB_CTRL_CLAMP_EN | 0x70;
+
+	/* use core clock if external reference is not present */
+	if (!phy_dwc3->xo_clk)
+		val |= HSUSB_CTRL_USE_CLKCORE;
+
Quoted 8 lines

drivers/phy/phy-qcom-dwc3.c line 268

Quoted 5 lines
drivers/phy/phy-qcom-dwc3.c new file +5 -0
+	writel(val, phy_dwc3->base + HSUSB_PHY_CTRL_REG);
+	usleep_range(2000, 2200);
+
+	/* Disable (bypass) VBUS and ID filters */
+	writel(HSUSB_GCFG_XHCI_REV, phy_dwc3->base + QSCRATCH_GENERAL_CFG);

Is this comment accurate? I believe this bit forces the IP to behave in XHCI rev 1.0. In which case, shouldn't it be done in the glue driver?

I'll double check. I was taking the bit values and converting them to names. If this is doing that, then I'll move it to the glue.

Signature · 3 lines
sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
hosted by The Linux Foundation
#16 lore raw

Re: [Patch v9 3/3] phy: Add Qualcomm DWC3 HS/SS PHY driver

In reply to Andy Gross

Hi Andy,

Quoted 11 lines · Andy Gross

This patch adds a new driver for the Qualcomm USB 3.0 PHY that exists on some Qualcomm platforms. This driver uses the generic PHY framework and will interact with the DWC3 controller.

---
 drivers/phy/Kconfig         |   11 +
 drivers/phy/Makefile        |    1 +
 drivers/phy/phy-qcom-dwc3.c |  483 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 495 insertions(+)
 create mode 100644 drivers/phy/phy-qcom-dwc3.c

What happened to this patch? Looks like [1/3] & [2/3] made it in during the 3.18 merge, but did this one not get picked up by Kishon?

Thanks,
Jack

Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
author
#17 lore raw

Re: [Patch v9 3/3] phy: Add Qualcomm DWC3 HS/SS PHY driver

Quoted 15 lines · Jack Pham

Hi Andy,

Quoted 11 lines · Andy Gross

This patch adds a new driver for the Qualcomm USB 3.0 PHY that exists on some Qualcomm platforms. This driver uses the generic PHY framework and will interact with the DWC3 controller.

---
 drivers/phy/Kconfig         |   11 +
 drivers/phy/Makefile        |    1 +
 drivers/phy/phy-qcom-dwc3.c |  483 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 495 insertions(+)
 create mode 100644 drivers/phy/phy-qcom-dwc3.c
Quoted 2 lines

What happened to this patch? Looks like [1/3] & [2/3] made it in during the 3.18 merge, but did this one not get picked up by Kishon?

Got sidetracked. I'll rework and resend in. It'll be a couple days.

Signature · 3 lines
Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project