Skip to contentSkip to conversation

DWC3 USB support for Qualcomm platform

PATCH Superseded Andy Gross 4 participants 10 messages Sep 12, 2014

Subsystems (5)

v8 of 9 Superseded Latest is v9 →

lore
Share & tools
lore

Andy Gross

author
#0 lore raw

v8 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 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                        |  500 ++++++++++++++++++++
 drivers/usb/dwc3/Kconfig                           |    9 +
 drivers/usb/dwc3/Makefile                          |    1 +
 drivers/usb/dwc3/dwc3-qcom.c                       |  133 ++++++
 8 files changed, 760 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 v8 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
author
#2 lore raw

PATCH v8 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     |    9 +++
 drivers/usb/dwc3/Makefile    |    1 +
 drivers/usb/dwc3/dwc3-qcom.c |  133 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 143 insertions(+)
 create mode 100644 drivers/usb/dwc3/dwc3-qcom.c
drivers/usb/dwc3/Kconfig +9 -0
index 785510a..e9f258e 100644
@@ -80,6 +80,15 @@ 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
+	select PHY_QCOM_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 +133 -0

133 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
#3 lore raw

Re: [PATCH v8 2/3] usb: dwc3: Add Qualcomm DWC3 glue layer driver

Hi,

Quoted 20 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     |    9 +++
 drivers/usb/dwc3/Makefile    |    1 +
 drivers/usb/dwc3/dwc3-qcom.c |  133 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 143 insertions(+)
 create mode 100644 drivers/usb/dwc3/dwc3-qcom.c
drivers/usb/dwc3/Kconfig +0 -0
index 785510a..e9f258e 100644

drivers/usb/dwc3/Kconfig config USB_DWC3_KEYSTONE · line 87

Quoted 8 lines
drivers/usb/dwc3/Kconfig +5 -0
@@ -80,6 +80,15 @@ 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
+	select PHY_QCOM_DWC3

I would rather steer away from selecting the PHY as it prevents having PHYs as modules. Also, this will add a Kconfig warning for selecting a symbol that doesn't exist (yet).

If it's all the same with you, I can clean this up when applying.

Quoted 17 lines
drivers/usb/dwc3/dwc3-qcom.c new file +11 -0
new file mode 100644
index 0000000..2067c04
@@ -0,0 +1,133 @@
+/* Copyright (c) 2013-2014, The Linux Foundation. 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.
+ */

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

Quoted 10 lines
drivers/usb/dwc3/dwc3-qcom.c new file +10 -0
+
+#include <linux/clk.h>
+#include <linux/err.h>
+#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_platform.h>
+#include <linux/platform_device.h>
+#include <linux/regulator/consumer.h>
+#include <linux/usb/phy.h>

doesn't look like you need regulator/consumer.h and usb/phy.h. I can clean it up when applying.

Quoted 15 lines
drivers/usb/dwc3/dwc3-qcom.c new file +15 -0
+struct dwc3_qcom {
+	struct device		*dev;
+
+	struct clk		*core_clk;
+	struct clk		*iface_clk;
+	struct clk		*sleep_clk;
+};
+
+static int dwc3_qcom_probe(struct platform_device *pdev)
+{
+	struct device_node *node = pdev->dev.of_node;
+	struct dwc3_qcom *qdwc;
+	int ret = 0;
+
+	qdwc = devm_kzalloc(&pdev->dev, sizeof(*qdwc), GFP_KERNEL);

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

Quoted 10 lines
drivers/usb/dwc3/dwc3-qcom.c new file +10 -0
+	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_dbg(qdwc->dev, "failed to get core clock\n");

this one would be a dev_err() since core can't work without its clock. I can fix when applying.

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/360a34a9/attachment.sig>
author
#4 lore raw

Re: [PATCH v8 2/3] usb: dwc3: Add Qualcomm DWC3 glue layer driver

Quoted 26 lines · Felipe Balbi

Hi,

Quoted 23 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     |    9 +++
 drivers/usb/dwc3/Makefile    |    1 +
 drivers/usb/dwc3/dwc3-qcom.c |  133 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 143 insertions(+)
 create mode 100644 drivers/usb/dwc3/dwc3-qcom.c
drivers/usb/dwc3/Kconfig +0 -0
index 785510a..e9f258e 100644
@@ -80,6 +80,15 @@ config USB_DWC3_KEYSTONE
 	  Support of USB2/3 functionality in TI Keystone2 platforms.
 	  Say 'Y' or 'M' here if you have one such device
 
Quoted 9 lines

drivers/usb/dwc3/Kconfig config USB_DWC3_KEYSTONE · line 87

Quoted 5 lines
drivers/usb/dwc3/Kconfig +5 -0
+config USB_DWC3_QCOM
+	tristate "Qualcomm Platforms"
+	depends on ARCH_QCOM || COMPILE_TEST
+	default USB_DWC3
+	select PHY_QCOM_DWC3

I would rather steer away from selecting the PHY as it prevents having PHYs as modules. Also, this will add a Kconfig warning for selecting a symbol that doesn't exist (yet).

True. The one downside is people having to fish around to find the phy config option.

Quoted 3 lines

If it's all the same with you, I can clean this up when applying.

Thats fine.

Quoted 22 lines
Quoted 22 lines
drivers/usb/dwc3/dwc3-qcom.c new file +16 -0
new file mode 100644
index 0000000..2067c04
@@ -0,0 +1,133 @@
+/* Copyright (c) 2013-2014, The Linux Foundation. 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>
Quoted 8 lines

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

Quoted 5 lines
drivers/usb/dwc3/dwc3-qcom.c new file +5 -0
+#include <linux/of.h>
+#include <linux/of_platform.h>
+#include <linux/platform_device.h>
+#include <linux/regulator/consumer.h>
+#include <linux/usb/phy.h>

doesn't look like you need regulator/consumer.h and usb/phy.h. I can clean it up when applying.

Ack, interim changes that should have been removed. you can do that or I can respin.... no big deal.

Quoted 21 lines
Quoted 21 lines
drivers/usb/dwc3/dwc3-qcom.c new file +20 -0
+struct dwc3_qcom {
+	struct device		*dev;
+
+	struct clk		*core_clk;
+	struct clk		*iface_clk;
+	struct clk		*sleep_clk;
+};
+
+static int dwc3_qcom_probe(struct platform_device *pdev)
+{
+	struct device_node *node = pdev->dev.of_node;
+	struct dwc3_qcom *qdwc;
+	int ret = 0;
+
+	qdwc = devm_kzalloc(&pdev->dev, sizeof(*qdwc), GFP_KERNEL);
+	if (!qdwc)
+		return -ENOMEM;
+
+	platform_set_drvdata(pdev, qdwc);
+
Quoted 8 lines

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

Quoted 5 lines
drivers/usb/dwc3/dwc3-qcom.c new file +5 -0
+	qdwc->dev = &pdev->dev;
+
+	qdwc->core_clk = devm_clk_get(qdwc->dev, "core");
+	if (IS_ERR(qdwc->core_clk)) {
+		dev_dbg(qdwc->dev, "failed to get core clock\n");

this one would be a dev_err() since core can't work without its clock. I can fix when applying.

Right. That's fine.

Quoted 3 lines
Signature · 2 lines
-- 
balbi
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
author
#5 lore raw

PATCH v8 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 |  500 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 512 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 +500 -0

500 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
#6 lore raw

Re: [PATCH v8 3/3] phy: Add Qualcomm DWC3 HS/SS PHY driver

Hey Andy-

Mostly cosmetic things below:

Quoted 46 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 |  500 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 512 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 +0 -0
new file mode 100644
index 0000000..05b8e1d

[..]

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

Quoted 7 lines
drivers/phy/phy-qcom-dwc3.c new file +7 -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;

Do you need this?

Quoted 66 lines
drivers/phy/phy-qcom-dwc3.c new file +66 -0
+
+enum qcom_dwc3_phy_id {
+	QCOM_DWC3_PHY_UTMI = 0,
+	QCOM_DWC3_PHY_PIPE,
+	QCOM_DWC3_PHYS_NUM,
+};
+
+struct qcom_dwc3_usb_phy {
+	void __iomem		*base;
+	struct device		*dev;
+	struct phy *phy;
+	enum qcom_dwc3_phy_id	index;
+
+	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,
+	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 */
+	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
+ *
+ * @base - QCOM DWC3 PHY base virtual address.

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

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

I'm not too familiar with the GENERIC_PHY infrastructure, does it understand that '1' is an error case? I'm wondering if you should instead propogate the -ETIMEDOUT up.

Quoted 15 lines
drivers/phy/phy-qcom-dwc3.c new file +15 -0
+
+	writel(val, base + CR_PROTOCOL_DATA_IN_REG);
+	writel(0x1, base + CR_PROTOCOL_CAP_DATA_REG);
+
+	if (wait_for_latch(base + CR_PROTOCOL_CAP_DATA_REG))
+		return 1;
+
+	writel(0x1, base + CR_PROTOCOL_WRITE_REG);
+
+	if (wait_for_latch(base + CR_PROTOCOL_WRITE_REG))
+		return 1;
+
+	return 0;
+}
+

[..]

Quoted 11 lines
drivers/phy/phy-qcom-dwc3.c new file +11 -0
+
+static struct phy_ops qcom_dwc3_phy_ops = {
+	.init		= qcom_dwc3_phy_init,
+	.exit		= qcom_dwc3_phy_exit,
+	.power_on	= qcom_dwc3_phy_power_on,
+	.power_off	= qcom_dwc3_phy_power_off,
+	.owner		= THIS_MODULE,
+};
+
+static const struct of_device_id qcom_dwc3_phy_table[] = {
+	{

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

Quoted 10 lines
drivers/phy/phy-qcom-dwc3.c new file +10 -0
+		.compatible = "qcom,dwc3-hs-usb-phy",
+		.data = (void *)QCOM_DWC3_PHY_UTMI,
+	},
+	{
+		.compatible = "qcom,dwc3-ss-usb-phy",
+		.data = (void *)QCOM_DWC3_PHY_PIPE,
+	},
+	{ /* Sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, qcom_dwc3_phy_table);

I'd suggest just creating a separate ops table, and have '.data' point to it. Might cleanup all of the switch() statements above. You could also probably drop the 'index' member of 'struct qcom_dwc3_usb_phy', and maybe even 'enum qcom_dwc3_phy_id' altogether.

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

Re: [PATCH v8 3/3] phy: Add Qualcomm DWC3 HS/SS PHY driver

Quoted 52 lines · Josh Cartwright

Hey Andy-

Mostly cosmetic things below:

Quoted 46 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 |  500 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 512 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 +0 -0
new file mode 100644
index 0000000..05b8e1d

[..]

Quoted 9 lines

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

Quoted 7 lines
drivers/phy/phy-qcom-dwc3.c new file +7 -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;

Do you need this?

No, this was a set of interim changes that should have been squashed. Incidently, this was used when I had a separate ops table for the phys.

Quoted 72 lines
Quoted 72 lines
drivers/phy/phy-qcom-dwc3.c new file +72 -0
+
+enum qcom_dwc3_phy_id {
+	QCOM_DWC3_PHY_UTMI = 0,
+	QCOM_DWC3_PHY_PIPE,
+	QCOM_DWC3_PHYS_NUM,
+};
+
+struct qcom_dwc3_usb_phy {
+	void __iomem		*base;
+	struct device		*dev;
+	struct phy *phy;
+	enum qcom_dwc3_phy_id	index;
+
+	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,
+	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 */
+	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
+ *
+ * @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)
+{
+	writel(addr, base + CR_PROTOCOL_DATA_IN_REG);
Quoted 8 lines

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

Quoted 4 lines
drivers/phy/phy-qcom-dwc3.c new file +4 -0
+	writel(0x1, base + CR_PROTOCOL_CAP_ADDR_REG);
+
+	if (wait_for_latch(base + CR_PROTOCOL_CAP_ADDR_REG))
+		return 1;

I'm not too familiar with the GENERIC_PHY infrastructure, does it understand that '1' is an error case? I'm wondering if you should instead propogate the -ETIMEDOUT up.

Actually, yeah I need to return something < 0. Let me respin to fix that.

Quoted 34 lines
Quoted 15 lines
drivers/phy/phy-qcom-dwc3.c new file +15 -0
+
+	writel(val, base + CR_PROTOCOL_DATA_IN_REG);
+	writel(0x1, base + CR_PROTOCOL_CAP_DATA_REG);
+
+	if (wait_for_latch(base + CR_PROTOCOL_CAP_DATA_REG))
+		return 1;
+
+	writel(0x1, base + CR_PROTOCOL_WRITE_REG);
+
+	if (wait_for_latch(base + CR_PROTOCOL_WRITE_REG))
+		return 1;
+
+	return 0;
+}
+

[..]

Quoted 18 lines
drivers/phy/phy-qcom-dwc3.c new file +18 -0
+
+static struct phy_ops qcom_dwc3_phy_ops = {
+	.init		= qcom_dwc3_phy_init,
+	.exit		= qcom_dwc3_phy_exit,
+	.power_on	= qcom_dwc3_phy_power_on,
+	.power_off	= qcom_dwc3_phy_power_off,
+	.owner		= THIS_MODULE,
+};
+
+static const struct of_device_id qcom_dwc3_phy_table[] = {
+	{
+		.compatible = "qcom,dwc3-hs-usb-phy",
+		.data = (void *)QCOM_DWC3_PHY_UTMI,
+	},
+	{
+		.compatible = "qcom,dwc3-ss-usb-phy",
+		.data = (void *)QCOM_DWC3_PHY_PIPE,
+	},
Quoted 8 lines

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

Quoted 3 lines
drivers/phy/phy-qcom-dwc3.c new file +3 -0
+	{ /* Sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, qcom_dwc3_phy_table);

I'd suggest just creating a separate ops table, and have '.data' point to it. Might cleanup all of the switch() statements above. You could also probably drop the 'index' member of 'struct qcom_dwc3_usb_phy', and maybe even 'enum qcom_dwc3_phy_id' altogether.

Or just put in two function handlers that I point to in the probe and key off of the compat.

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
Reviewed-by Acked-by on v8 3/3
#8 lore raw

Re: [PATCH v8 3/3] phy: Add Qualcomm DWC3 HS/SS PHY driver

In reply to Andy Gross

Hi,

Quoted 5 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.

Kishon, this looks good to my eyes. It has no direct dependency with dwc3 glue layer. Can you still grab this for v3.18 merge window ?

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/20140912/4ebff467/attachment.sig>
#9 lore raw

Re: [PATCH v8 3/3] phy: Add Qualcomm DWC3 HS/SS PHY driver

In reply to Andy Gross

Yay nitpicks!

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

Quoted 5 lines · Andy Gross
drivers/phy/phy-qcom-dwc3.c new file +5 -0
+
+struct qcom_dwc3_usb_phy {
+	void __iomem		*base;
+	struct device		*dev;
+	struct phy *phy;

Align with other members?

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

Quoted 5 lines
drivers/phy/phy-qcom-dwc3.c new file +4 -0
+
+static int wait_for_latch(void __iomem *addr)
+{
+	u32 retry = 10;

Why not just int?

Quoted 13 lines
drivers/phy/phy-qcom-dwc3.c new file +13 -0
+
+	while (true) {
+		if (!readl(addr))
+			break;
+
+		if (--retry == 0)
+			return -ETIMEDOUT;
+
+		usleep_range(10, 20);
+	}
+
+	return 0;
+}

[...]

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

Quoted 5 lines
drivers/phy/phy-qcom-dwc3.c new file +5 -0
+
+static int qcom_dwc3_ss_phy_init(struct qcom_dwc3_usb_phy *phy_dwc3)
+{
+	u32 data = 0;
+

Unnecessary initialization.

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

Quoted 4 lines
drivers/phy/phy-qcom-dwc3.c new file +2 -0
+
+static struct phy_ops qcom_dwc3_phy_ops = {

Can this be const?

Quoted 7 lines
drivers/phy/phy-qcom-dwc3.c new file +7 -0
+	.init		= qcom_dwc3_phy_init,
+	.exit		= qcom_dwc3_phy_exit,
+	.power_on	= qcom_dwc3_phy_power_on,
+	.power_off	= qcom_dwc3_phy_power_off,
+	.owner		= THIS_MODULE,
+};
+

[...]

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

Quoted 9 lines
drivers/phy/phy-qcom-dwc3.c new file +9 -0
+
+static int qcom_dwc3_phy_probe(struct platform_device *pdev)
+{
+	struct qcom_dwc3_usb_phy	*phy_dwc3;
+	struct phy_provider		*phy_provider;
+	struct resource			*res;
+	const struct of_device_id	*match;
+
+

Weird two newlines here.

Quoted 5 lines
drivers/phy/phy-qcom-dwc3.c new file +4 -0
+	phy_dwc3 = devm_kzalloc(&pdev->dev, sizeof(*phy_dwc3), GFP_KERNEL);
+	if (!phy_dwc3)
+		return -ENOMEM;
+
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation