Skip to contentSkip to conversation

Enable IPQ5332 USB2

PATCH Superseded Varadarajan Narayanan 6 participants 39 messages Jun 7, 2023 – Jun 21, 2023

Subsystems (7)

v1 of 12 Superseded Latest is v12 →

lore
Share & tools
lore
#4 lore raw

PATCH 2/9 dt-bindings: phy: qcom,m31: Document qcom,m31 USB phy

In reply to Varadarajan Narayanan

Document the M31 USB2 phy present in IPQ5332

---
 .../devicetree/bindings/phy/qcom,m31.yaml          | 69 ++++++++++++++++++++++
 1 file changed, 69 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/qcom,m31.yaml
Documentation/devicetree/bindings/phy/qcom,m31.yaml new file +69 -0
new file mode 100644
index 0000000..8ad4ba4
@@ -0,0 +1,69 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/phy/qcom,m31.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Qualcomm M31 USB PHY
+
+maintainers:
+  - Sricharan Ramabadhran <[email protected]>
+  - Varadarajan Narayanan <[email protected]>
+
+description:
+  This file contains documentation for the USB M31 PHY found in Qualcomm
+  IPQ5018, IPQ5332 SoCs.
+
+properties:
+  compatible:
+    oneOf:
+      - items:
+          - enum:
+              - qcom,m31-usb-hsphy
+              - qcom,ipq5332-m31-usb-hsphy
+
+  reg:
+    description:
+      Offset and length of the M31 PHY register set
+    maxItems: 2
+
+  reg-names:
+    items:
+      - const: m31usb_phy_base
+      - const: qscratch_base
+
+  phy_type:
+    oneOf:
+      - items:
+          - enum:
+              - utmi
+              - ulpi
+
+  resets:
+    maxItems: 1
+    description:
+      List of phandles and reset pairs, one for each entry in reset-names.
+
+  reset-names:
+    items:
+      - const:
+          usb2_phy_reset
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/clock/qcom,ipq5332-gcc.h>
+    hs_m31phy_0: hs_m31phy@5b00 {
+        compatible = "qcom,m31-usb-hsphy";
+        reg = <0x5b000 0x3000>,
+            <0x08af8800 0x400>;
+        reg-names = "m31usb_phy_base",
+                "qscratch_base";
+        phy_type = "utmi";
+        resets = <&gcc GCC_QUSB2_0_PHY_BCR>;
+        reset-names = "usb2_phy_reset";
+
+        status = "ok";
+    };
Signature · 7 lines
2.7.4


-- 
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#12 lore raw

PATCH 3/9 phy: qcom-m31: Introduce qcom,m31 USB phy driver

In reply to Varadarajan Narayanan

Add the M31 USB2 phy driver

---
 drivers/phy/qualcomm/phy-qcom-m31.c | 360 ++++++++++++++++++++++++++++++++++++
 1 file changed, 360 insertions(+)
 create mode 100644 drivers/phy/qualcomm/phy-qcom-m31.c
drivers/phy/qualcomm/phy-qcom-m31.c new file +360 -0
new file mode 100644
index 0000000..d29a91e
@@ -0,0 +1,360 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2014-2016, 2020, The Linux Foundation. All rights reserved.
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/err.h>
+#include <linux/slab.h>
+#include <linux/clk.h>
+#include <linux/delay.h>
+#include <linux/io.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/usb/phy.h>
+#include <linux/reset.h>
+#include <linux/of_device.h>
+
+enum clk_reset_action {
+	CLK_RESET_DEASSERT	= 0,
+	CLK_RESET_ASSERT	= 1
+};
+
+#define USB2PHY_PORT_POWERDOWN		0xA4
+#define POWER_UP			BIT(0)
+#define POWER_DOWN			0
+
+#define USB2PHY_PORT_UTMI_CTRL1	0x40
+
+#define USB2PHY_PORT_UTMI_CTRL2	0x44
+#define UTMI_ULPI_SEL			BIT(7)
+#define UTMI_TEST_MUX_SEL		BIT(6)
+
+#define HS_PHY_CTRL_REG			0x10
+#define UTMI_OTG_VBUS_VALID             BIT(20)
+#define SW_SESSVLD_SEL                  BIT(28)
+
+#define USB_PHY_CFG0			0x94
+#define USB_PHY_UTMI_CTRL5		0x50
+#define USB_PHY_FSEL_SEL		0xB8
+#define USB_PHY_HS_PHY_CTRL_COMMON0	0x54
+#define USB_PHY_REFCLK_CTRL		0xA0
+#define USB_PHY_HS_PHY_CTRL2		0x64
+#define USB_PHY_UTMI_CTRL0		0x3c
+#define USB2PHY_USB_PHY_M31_XCFGI_1	0xBC
+#define USB2PHY_USB_PHY_M31_XCFGI_4	0xC8
+#define USB2PHY_USB_PHY_M31_XCFGI_5	0xCC
+#define USB2PHY_USB_PHY_M31_XCFGI_11	0xE4
+
+#define USB2_0_TX_ENABLE		BIT(2)
+#define HSTX_SLEW_RATE_565PS		3
+#define PLL_CHARGING_PUMP_CURRENT_35UA	(3 << 3)
+#define ODT_VALUE_38_02_OHM		(3 << 6)
+#define ODT_VALUE_45_02_OHM		BIT(2)
+#define HSTX_PRE_EMPHASIS_LEVEL_0_55MA	(1)
+
+#define UTMI_PHY_OVERRIDE_EN		BIT(1)
+#define POR_EN				BIT(1)
+#define FREQ_SEL			BIT(0)
+#define COMMONONN			BIT(7)
+#define FSEL				BIT(4)
+#define RETENABLEN			BIT(3)
+#define USB2_SUSPEND_N_SEL		BIT(3)
+#define USB2_SUSPEND_N			BIT(2)
+#define USB2_UTMI_CLK_EN		BIT(1)
+#define CLKCORE				BIT(1)
+#define ATERESET			~BIT(0)
+#define FREQ_24MHZ			(5 << 4)
+#define XCFG_COARSE_TUNE_NUM		(2 << 0)
+#define XCFG_FINE_TUNE_NUM		(1 << 3)
+
+static void m31usb_write_readback(void *base, u32 offset,
+					const u32 mask, u32 val);
+
+struct m31usb_phy {
+	struct usb_phy		phy;
+	void __iomem		*base;
+	void __iomem		*qscratch_base;
+
+	struct reset_control	*phy_reset;
+
+	bool			cable_connected;
+	bool			suspended;
+	bool			ulpi_mode;
+};
+
+static void m31usb_reset(struct m31usb_phy *qphy, u32 action)
+{
+	if (action == CLK_RESET_ASSERT)
+		reset_control_assert(qphy->phy_reset);
+	else
+		reset_control_deassert(qphy->phy_reset);
+	wmb(); /* ensure data is written to hw register */
+}
+
+static void m31usb_phy_enable_clock(struct m31usb_phy *qphy)
+{
+	/* Enable override ctrl */
+	writel(UTMI_PHY_OVERRIDE_EN, qphy->base + USB_PHY_CFG0);
+	/* Enable POR*/
+	writel(POR_EN, qphy->base + USB_PHY_UTMI_CTRL5);
+	udelay(15);
+	/* Configure frequency select value*/
+	writel(FREQ_SEL, qphy->base + USB_PHY_FSEL_SEL);
+	/* Configure refclk frequency */
+	writel(COMMONONN | FSEL | RETENABLEN,
+		qphy->base + USB_PHY_HS_PHY_CTRL_COMMON0);
+	/* select refclk source */
+	writel(CLKCORE, qphy->base + USB_PHY_REFCLK_CTRL);
+	/* select ATERESET*/
+	writel(POR_EN & ATERESET, qphy->base + USB_PHY_UTMI_CTRL5);
+	writel(USB2_SUSPEND_N_SEL | USB2_SUSPEND_N | USB2_UTMI_CLK_EN,
+		qphy->base + USB_PHY_HS_PHY_CTRL2);
+	writel(0x0, qphy->base + USB_PHY_UTMI_CTRL5);
+	writel(USB2_SUSPEND_N | USB2_UTMI_CLK_EN,
+		qphy->base + USB_PHY_HS_PHY_CTRL2);
+	/* Disable override ctrl */
+	writel(0x0, qphy->base + USB_PHY_CFG0);
+}
+
+static void ipq5332_m31usb_phy_enable_clock(struct m31usb_phy *qphy)
+{
+	/* Enable override ctrl */
+	writel(UTMI_PHY_OVERRIDE_EN, qphy->base + USB_PHY_CFG0);
+	/* Enable POR*/
+	writel(POR_EN, qphy->base + USB_PHY_UTMI_CTRL5);
+	udelay(15);
+	/* Configure frequency select value*/
+	writel(FREQ_SEL, qphy->base + USB_PHY_FSEL_SEL);
+	/* Configure refclk frequency */
+	writel(COMMONONN | FREQ_24MHZ | RETENABLEN,
+		qphy->base + USB_PHY_HS_PHY_CTRL_COMMON0);
+	/* select ATERESET*/
+	writel(POR_EN & ATERESET, qphy->base + USB_PHY_UTMI_CTRL5);
+	writel(USB2_SUSPEND_N_SEL | USB2_SUSPEND_N | USB2_UTMI_CLK_EN,
+		qphy->base + USB_PHY_HS_PHY_CTRL2);
+	writel(XCFG_COARSE_TUNE_NUM  | XCFG_FINE_TUNE_NUM,
+				qphy->base + USB2PHY_USB_PHY_M31_XCFGI_11);
+	/* Adjust HSTX slew rate to 565 ps*/
+	/* Adjust PLL lock Time counter for release clock to 35uA */
+	/* Adjust Manual control ODT value to 38.02 Ohm */
+	writel(HSTX_SLEW_RATE_565PS | PLL_CHARGING_PUMP_CURRENT_35UA |
+		ODT_VALUE_38_02_OHM, qphy->base + USB2PHY_USB_PHY_M31_XCFGI_4);
+	/*
+	 * Enable to always turn on USB 2.0 TX driver
+	 * when system is in USB 2.0 HS mode
+	 */
+	writel(USB2_0_TX_ENABLE, qphy->base + USB2PHY_USB_PHY_M31_XCFGI_1);
+	/* Adjust Manual control ODT value to 45.02 Ohm */
+	/* Adjust HSTX Pre-emphasis level to 0.55mA */
+	writel(ODT_VALUE_45_02_OHM | HSTX_PRE_EMPHASIS_LEVEL_0_55MA,
+		qphy->base + USB2PHY_USB_PHY_M31_XCFGI_5);
+	udelay(4);
+	writel(0x0, qphy->base + USB_PHY_UTMI_CTRL5);
+	writel(USB2_SUSPEND_N | USB2_UTMI_CLK_EN,
+		qphy->base + USB_PHY_HS_PHY_CTRL2);
+}
+
+static int m31usb_phy_init(struct usb_phy *phy)
+{
+	struct m31usb_phy *qphy = container_of(phy, struct m31usb_phy, phy);
+
+	/* Perform phy reset */
+	m31usb_reset(qphy, CLK_RESET_ASSERT);
+	usleep_range(1, 5);
+	m31usb_reset(qphy, CLK_RESET_DEASSERT);
+
+	/* configure for ULPI mode if requested */
+	if (qphy->ulpi_mode)
+		writel_relaxed(0x0, qphy->base + USB2PHY_PORT_UTMI_CTRL2);
+
+	/* Enable the PHY */
+	writel_relaxed(POWER_UP, qphy->base + USB2PHY_PORT_POWERDOWN);
+
+	/* Make sure above write completed */
+	wmb();
+
+	/* Turn on phy ref clock*/
+	if (of_device_is_compatible(phy->dev->of_node,
+					"qcom,ipq5332-m31-usb-hsphy"))
+		ipq5332_m31usb_phy_enable_clock(qphy);
+	else
+		m31usb_phy_enable_clock(qphy);
+
+	/* Set OTG VBUS Valid from HSPHY to controller */
+	m31usb_write_readback(qphy->qscratch_base, HS_PHY_CTRL_REG,
+				UTMI_OTG_VBUS_VALID, UTMI_OTG_VBUS_VALID);
+	/* Indicate value is driven by UTMI_OTG_VBUS_VALID bit */
+	m31usb_write_readback(qphy->qscratch_base, HS_PHY_CTRL_REG,
+				SW_SESSVLD_SEL, SW_SESSVLD_SEL);
+
+	return 0;
+}
+
+static void m31usb_phy_shutdown(struct usb_phy *phy)
+{
+	struct m31usb_phy *qphy = container_of(phy, struct m31usb_phy, phy);
+
+	/* Disable the PHY */
+	writel_relaxed(POWER_DOWN, qphy->base + USB2PHY_PORT_POWERDOWN);
+	/* Make sure above write completed */
+	wmb();
+}
+
+static void m31usb_write_readback(void *base, u32 offset,
+					const u32 mask, u32 val)
+{
+	u32 write_val, tmp = readl_relaxed(base + offset);
+
+	tmp &= ~mask; /* retain other bits */
+	write_val = tmp | val;
+
+	writel_relaxed(write_val, base + offset);
+	/* Make sure above write completed */
+	wmb();
+
+	/* Read back to see if val was written */
+	tmp = readl_relaxed(base + offset);
+	tmp &= mask; /* clear other bits */
+
+	if (tmp != val)
+		pr_err("%s: write: %x to QSCRATCH: %x FAILED\n",
+			__func__, val, offset);
+}
+
+static int m31usb_phy_notify_connect(struct usb_phy *phy,
+					enum usb_device_speed speed)
+{
+	struct m31usb_phy *qphy = container_of(phy, struct m31usb_phy, phy);
+
+	qphy->cable_connected = true;
+
+	dev_dbg(phy->dev, " cable_connected=%d\n", qphy->cable_connected);
+
+	/* Set OTG VBUS Valid from HSPHY to controller */
+	m31usb_write_readback(qphy->qscratch_base, HS_PHY_CTRL_REG,
+				UTMI_OTG_VBUS_VALID,
+				UTMI_OTG_VBUS_VALID);
+
+	/* Indicate value is driven by UTMI_OTG_VBUS_VALID bit */
+	m31usb_write_readback(qphy->qscratch_base, HS_PHY_CTRL_REG,
+				SW_SESSVLD_SEL, SW_SESSVLD_SEL);
+
+	dev_dbg(phy->dev, "M31USB2 phy connect notification\n");
+	return 0;
+}
+
+static int m31usb_phy_notify_disconnect(struct usb_phy *phy,
+					enum usb_device_speed speed)
+{
+	struct m31usb_phy *qphy = container_of(phy, struct m31usb_phy, phy);
+
+	qphy->cable_connected = false;
+
+	dev_dbg(phy->dev, " cable_connected=%d\n", qphy->cable_connected);
+
+	/* Set OTG VBUS Valid from HSPHY to controller */
+	m31usb_write_readback(qphy->qscratch_base, HS_PHY_CTRL_REG,
+				UTMI_OTG_VBUS_VALID, 0);
+
+	/* Indicate value is driven by UTMI_OTG_VBUS_VALID bit */
+	m31usb_write_readback(qphy->qscratch_base, HS_PHY_CTRL_REG,
+				SW_SESSVLD_SEL, 0);
+
+	dev_dbg(phy->dev, "M31USB2 phy disconnect notification\n");
+	return 0;
+}
+
+static int m31usb_phy_probe(struct platform_device *pdev)
+{
+	struct m31usb_phy *qphy;
+	struct device *dev = &pdev->dev;
+	struct resource *res;
+	int ret;
+	const char *phy_type;
+
+	qphy = devm_kzalloc(dev, sizeof(*qphy), GFP_KERNEL);
+	if (!qphy)
+		return -ENOMEM;
+
+	qphy->phy.dev = dev;
+
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
+							"m31usb_phy_base");
+	qphy->base = devm_ioremap_resource(dev, res);
+	if (IS_ERR(qphy->base))
+		return PTR_ERR(qphy->base);
+
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
+							"qscratch_base");
+	if (res) {
+		qphy->qscratch_base = devm_ioremap(dev, res->start,
+							resource_size(res));
+		if (IS_ERR(qphy->qscratch_base)) {
+			dev_dbg(dev, "couldn't ioremap qscratch_base\n");
+			qphy->qscratch_base = NULL;
+		}
+	}
+
+	qphy->phy_reset = devm_reset_control_get(dev, "usb2_phy_reset");
+	if (IS_ERR(qphy->phy_reset))
+		return PTR_ERR(qphy->phy_reset);
+
+	qphy->ulpi_mode = false;
+	ret = of_property_read_string(dev->of_node, "phy_type", &phy_type);
+
+	if (!ret) {
+		if (!strcasecmp(phy_type, "ulpi"))
+			qphy->ulpi_mode = true;
+	} else {
+		dev_err(dev, "error reading phy_type property\n");
+		return ret;
+	}
+
+	platform_set_drvdata(pdev, qphy);
+
+	qphy->phy.label			= "qcom-m31usb-phy";
+	qphy->phy.init			= m31usb_phy_init;
+	qphy->phy.shutdown		= m31usb_phy_shutdown;
+	qphy->phy.type			= USB_PHY_TYPE_USB2;
+
+	if (qphy->qscratch_base) {
+		qphy->phy.notify_connect        = m31usb_phy_notify_connect;
+		qphy->phy.notify_disconnect     = m31usb_phy_notify_disconnect;
+	}
+
+	ret = usb_add_phy_dev(&qphy->phy);
+
+	return ret;
+}
+
+static int m31usb_phy_remove(struct platform_device *pdev)
+{
+	struct m31usb_phy *qphy = platform_get_drvdata(pdev);
+
+	usb_remove_phy(&qphy->phy);
+
+	return 0;
+}
+
+static const struct of_device_id m31usb_phy_id_table[] = {
+	{ .compatible = "qcom,m31-usb-hsphy",},
+	{ .compatible = "qcom,ipq5332-m31-usb-hsphy",},
+	{ },
+};
+MODULE_DEVICE_TABLE(of, m31usb_phy_id_table);
+
+static struct platform_driver m31usb_phy_driver = {
+	.probe		= m31usb_phy_probe,
+	.remove		= m31usb_phy_remove,
+	.driver = {
+		.name	= "qcom-m31usb-phy",
+		.of_match_table = of_match_ptr(m31usb_phy_id_table),
+	},
+};
+
+module_platform_driver(m31usb_phy_driver);
+
+MODULE_DESCRIPTION("USB2 Qualcomm M31 HSPHY driver");
+MODULE_LICENSE("GPL");
Signature · 7 lines
2.7.4


-- 
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#18 lore raw

PATCH 4/9 clk: qcom: ipq5332: Fix USB related clock defines

In reply to Varadarajan Narayanan

Fix the USB related clock defines and add details
referenced by them

---
 drivers/clk/qcom/gcc-ipq5332.c | 34 +++++++++++++++++++++++-----------
 1 file changed, 23 insertions(+), 11 deletions(-)
drivers/clk/qcom/gcc-ipq5332.c +23 -11
index a75ab88..2b58558 100644
@@ -351,6 +351,16 @@ static const struct freq_tbl ftbl_gcc_adss_pwm_clk_src[] = {
 	{ }
 };
 
+static const struct clk_parent_data gcc_usb3phy_0_cc_pipe_clk_xo[] = {
+	{ .fw_name = "usb3phy_0_cc_pipe_clk" },
+	{ .fw_name = "xo" },
+};
+
+static const struct parent_map gcc_usb3phy_0_cc_pipe_clk_xo_map[] = {
+	{ P_USB3PHY_0_PIPE, 0 },
+	{ P_XO, 2 },
+};
+
 static struct clk_rcg2 gcc_adss_pwm_clk_src = {
 	.cmd_rcgr = 0x1c004,
 	.mnd_width = 0,
@@ -1101,16 +1111,18 @@ static struct clk_rcg2 gcc_usb0_mock_utmi_clk_src = {
 	},
 };
 
-static struct clk_regmap_phy_mux gcc_usb0_pipe_clk_src = {
+static struct clk_regmap_mux usb0_pipe_clk_src = {
 	.reg = 0x2c074,
+	.shift = 8,
+	.width = 2,
+	.parent_map = gcc_usb3phy_0_cc_pipe_clk_xo_map,
 	.clkr = {
-		.hw.init = &(struct clk_init_data) {
-			.name = "gcc_usb0_pipe_clk_src",
-			.parent_data = &(const struct clk_parent_data) {
-				.index = DT_USB_PCIE_WRAPPER_PIPE_CLK,
-			},
-			.num_parents = 1,
-			.ops = &clk_regmap_phy_mux_ops,
+		.hw.init = &(const struct clk_init_data){
+			.name = "usb0phy_0_cc_pipe_clk_src",
+			.parent_data = gcc_usb3phy_0_cc_pipe_clk_xo,
+			.num_parents = 2,
+			.ops = &clk_regmap_mux_closest_ops,
+			.flags = CLK_SET_RATE_PARENT,
 		},
 	},
 };
@@ -3041,8 +3053,8 @@ static struct clk_branch gcc_usb0_pipe_clk = {
 		.enable_mask = BIT(0),
 		.hw.init = &(const struct clk_init_data) {
 			.name = "gcc_usb0_pipe_clk",
-			.parent_hws = (const struct clk_hw*[]) {
-				&gcc_usb0_pipe_clk_src.clkr.hw,
+			.parent_names = (const char *[]){
+				"usb0_pipe_clk_src"
 			},
 			.num_parents = 1,
 			.flags = CLK_SET_RATE_PARENT,
@@ -3580,7 +3592,7 @@ static struct clk_regmap *gcc_ipq5332_clocks[] = {
 	[GCC_PCIE3X2_PIPE_CLK_SRC] = &gcc_pcie3x2_pipe_clk_src.clkr,
 	[GCC_PCIE3X1_0_PIPE_CLK_SRC] = &gcc_pcie3x1_0_pipe_clk_src.clkr,
 	[GCC_PCIE3X1_1_PIPE_CLK_SRC] = &gcc_pcie3x1_1_pipe_clk_src.clkr,
-	[GCC_USB0_PIPE_CLK_SRC] = &gcc_usb0_pipe_clk_src.clkr,
+	[GCC_USB0_PIPE_CLK_SRC] = &usb0_pipe_clk_src.clkr,
 };
 
 static const struct qcom_reset_map gcc_ipq5332_resets[] = {
Signature · 7 lines
2.7.4


-- 
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#21 lore raw

PATCH 5/9 phy: qcom-m31: Introduce qcom,m31 USB phy

In reply to Varadarajan Narayanan

Introduce CONFIG_PHY_QCOM_M31_USB for including the M31 phy driver

---
 drivers/phy/qualcomm/Kconfig | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/phy/qualcomm/Kconfig +11 -0
index 67a45d9..8a363dd 100644
@@ -188,3 +188,14 @@ config PHY_QCOM_IPQ806X_USB
 	  This option enables support for the Synopsis PHYs present inside the
 	  Qualcomm USB3.0 DWC3 controller on ipq806x SoC. This driver supports
 	  both HS and SS PHY controllers.
+
+config PHY_QCOM_M31_USB
+	tristate "Qualcomm M31 HS PHY driver support"
+	depends on (USB || USB_GADGET) && ARCH_QCOM
+	select USB_PHY
+	help
+	  Enable this to support M31 HS PHY transceivers on Qualcomm chips
+	  with DWC3 USB core. It handles PHY initialization, clock
+	  management required after resetting the hardware and power
+	  management. This driver is required even for peripheral only or
+	  host only mode configurations.
Signature · 7 lines
2.7.4


-- 
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#25 lore raw

PATCH 6/9 phy: qcom: Add qcom,m31 USB phy driver

In reply to Varadarajan Narayanan

Include M31 phy driver if CONFIG_PHY_QCOM_M31_USB is enabled

---
 drivers/phy/qualcomm/Makefile | 1 +
 1 file changed, 1 insertion(+)
drivers/phy/qualcomm/Makefile +1 -0
index de3dc9c..79a6e75 100644
@@ -21,3 +21,4 @@ obj-$(CONFIG_PHY_QCOM_USB_HS_28NM)	+= phy-qcom-usb-hs-28nm.o
 obj-$(CONFIG_PHY_QCOM_USB_SS)		+= phy-qcom-usb-ss.o
 obj-$(CONFIG_PHY_QCOM_USB_SNPS_FEMTO_V2)+= phy-qcom-snps-femto-v2.o
 obj-$(CONFIG_PHY_QCOM_IPQ806X_USB)		+= phy-qcom-ipq806x-usb.o
+obj-$(CONFIG_PHY_QCOM_M31_USB)		+= phy-qcom-m31.o
Signature · 7 lines
2.7.4


-- 
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#28 lore raw

PATCH 7/9 arm64: dts: qcom: ipq5332: Add USB related nodes

In reply to Varadarajan Narayanan

Add USB phy and controller nodes

---
 arch/arm64/boot/dts/qcom/ipq5332.dtsi | 55 +++++++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)
arch/arm64/boot/dts/qcom/ipq5332.dtsi +55 -0
index c2d6cc65..3183357 100644
@@ -383,6 +383,61 @@
 				status = "disabled";
 			};
 		};
+
+		usb_0_m31phy: hs_m31phy@7b000 {
+			compatible = "qcom,ipq5332-m31-usb-hsphy";
+			reg = <0x0007b000 0x12C>,
+			      <0x08af8800 0x400>;
+			reg-names = "m31usb_phy_base",
+				    "qscratch_base";
+			phy_type= "utmi";
+
+			resets = <&gcc GCC_QUSB2_0_PHY_BCR>;
+			reset-names = "usb2_phy_reset";
+
+			status = "okay";
+		};
+
+		usb2: usb2@8a00000 {
+			compatible = "qcom,ipq5332-dwc3", "qcom,dwc3";
+			#address-cells = <1>;
+			#size-cells = <1>;
+			ranges;
+
+			reg = <0x08af8800 0x100>;
+
+			clocks = <&gcc GCC_USB0_MASTER_CLK>,
+				<&gcc GCC_SNOC_USB_CLK>,
+				<&gcc GCC_USB0_SLEEP_CLK>,
+				<&gcc GCC_USB0_MOCK_UTMI_CLK>;
+
+			clock-names = "core",
+				"iface",
+				"sleep",
+				"mock_utmi";
+
+			interrupts-extended = <&intc GIC_SPI 134 IRQ_TYPE_LEVEL_HIGH>;
+			interrupt-names = "pwr_event";
+
+			resets = <&gcc GCC_USB_BCR>;
+
+			qcom,select-utmi-as-pipe-clk;
+
+			usb2_0_dwc: usb@8a00000 {
+				compatible = "snps,dwc3";
+				reg = <0x08a00000 0xe000>;
+				clocks = <&gcc GCC_USB0_MOCK_UTMI_CLK>;
+				clock-names = "ref";
+				interrupts = <GIC_SPI 64 IRQ_TYPE_LEVEL_HIGH>;
+				usb-phy = <&usb_0_m31phy>;
+				tx-fifo-resize;
+				snps,is-utmi-l1-suspend;
+				snps,hird-threshold = /bits/ 8 <0x0>;
+				snps,dis_u2_susphy_quirk;
+				snps,dis_u3_susphy_quirk;
+				snps,ref-clock-period-ns = <21>;
+			};
+		};
 	};
 
 	timer {
Signature · 7 lines
2.7.4


-- 
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#35 lore raw

PATCH 8/9 arm64: dts: qcom: ipq5332: Enable USB

In reply to Varadarajan Narayanan

Enable USB2 in host mode

---
 arch/arm64/boot/dts/qcom/ipq5332-rdp468.dts | 8 ++++++++
 1 file changed, 8 insertions(+)
arch/arm64/boot/dts/qcom/ipq5332-rdp468.dts +8 -0
index 3b6a5cb..303e796 100644
@@ -101,3 +101,11 @@
 		bias-pull-up;
 	};
 };
+
+&usb2 {
+	status = "okay";
+};
+
+&usb2_0_dwc {
+	dr_mode = "host";
+};
Signature · 7 lines
2.7.4


-- 
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#36 lore raw

PATCH 9/9 arm64: defconfig: Enable QCOM M31 USB phy driver

In reply to Varadarajan Narayanan

Enable QCOM M31 USB phy driver present in IPQ5332

---
 arch/arm64/configs/defconfig | 1 +
 1 file changed, 1 insertion(+)
arch/arm64/configs/defconfig +1 -0
index afb63e3..f1e8669 100644
@@ -1362,6 +1362,7 @@ CONFIG_PHY_QCOM_USB_HS=m
 CONFIG_PHY_QCOM_USB_SNPS_FEMTO_V2=m
 CONFIG_PHY_QCOM_USB_HS_28NM=m
 CONFIG_PHY_QCOM_USB_SS=m
+CONFIG_PHY_QCOM_M31_USB=m
 CONFIG_PHY_R8A779F0_ETHERNET_SERDES=y
 CONFIG_PHY_RCAR_GEN3_PCIE=y
 CONFIG_PHY_RCAR_GEN3_USB2=y
Signature · 7 lines
2.7.4


-- 
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#1 lore raw

PATCH 1/9 dt-bindings: usb: dwc3: Add IPQ5332 compatible

In reply to Varadarajan Narayanan

Document the IPQ5332 dwc3 compatible

---
 Documentation/devicetree/bindings/usb/qcom,dwc3.yaml | 2 ++
 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/usb/qcom,dwc3.yaml +2 -0
index ae24dac..9c3d6f4 100644
@@ -14,6 +14,7 @@ properties:
     items:
       - enum:
           - qcom,ipq4019-dwc3
+          - qcom,ipq5332-dwc3
           - qcom,ipq6018-dwc3
           - qcom,ipq8064-dwc3
           - qcom,ipq8074-dwc3
@@ -246,6 +247,7 @@ allOf:
         compatible:
           contains:
             enum:
+              - qcom,ipq5332-dwc3
               - qcom,msm8994-dwc3
               - qcom,qcs404-dwc3
     then:
Signature · 1 line
2.7.4
#0 lore raw

cover Enable IPQ5332 USB2

This patch series adds the relevant phy and controller configurations for enabling USB2 on IPQ5332

Depends On: https://lore.kernel.org/linux-arm-msm/[email protected]/

Varadarajan Narayanan (9):
dt-bindings: usb: dwc3: Add IPQ5332 compatible
dt-bindings: phy: qcom,m31: Document qcom,m31 USB phy
phy: qcom-m31: Introduce qcom,m31 USB phy driver
clk: qcom: ipq5332: Fix USB related clock defines
phy: qcom-m31: Introduce qcom,m31 USB phy
phy: qcom: Add qcom,m31 USB phy driver
arm64: dts: qcom: ipq5332: Add USB related nodes
arm64: dts: qcom: ipq5332: Enable USB
arm64: defconfig: Enable QCOM M31 USB phy driver

 .../devicetree/bindings/phy/qcom,m31.yaml          |  69 ++++
 .../devicetree/bindings/usb/qcom,dwc3.yaml         |   2 +
 arch/arm64/boot/dts/qcom/ipq5332-rdp468.dts        |   8 +
 arch/arm64/boot/dts/qcom/ipq5332.dtsi              |  55 ++++
 arch/arm64/configs/defconfig                       |   1 +
 drivers/clk/qcom/gcc-ipq5332.c                     |  34 +-
 drivers/phy/qualcomm/Kconfig                       |  11 +
 drivers/phy/qualcomm/Makefile                      |   1 +
 drivers/phy/qualcomm/phy-qcom-m31.c                | 360 +++++++++++++++++++++
 9 files changed, 530 insertions(+), 11 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/phy/qcom,m31.yaml
 create mode 100644 drivers/phy/qualcomm/phy-qcom-m31.c
Signature · 1 line
2.7.4
#19 lore raw

Re: [PATCH 4/9] clk: qcom: ipq5332: Fix USB related clock defines

In reply to Varadarajan Narayanan
Quoted 13 lines · Varadarajan Narayanan

Fix the USB related clock defines and add details
referenced by them

---
  drivers/clk/qcom/gcc-ipq5332.c | 34 +++++++++++++++++++++++-----------
  1 file changed, 23 insertions(+), 11 deletions(-)
drivers/clk/qcom/gcc-ipq5332.c +0 -0
index a75ab88..2b58558 100644

drivers/clk/qcom/gcc-ipq5332.c static const struct freq_tbl ftbl_gcc_adss_pwm_clk_src[] = { · line 356

Quoted 6 lines
drivers/clk/qcom/gcc-ipq5332.c +3 -0
@@ -351,6 +351,16 @@ static const struct freq_tbl ftbl_gcc_adss_pwm_clk_src[] = {
  	{ }
  };
 
+static const struct clk_parent_data gcc_usb3phy_0_cc_pipe_clk_xo[] = {
+	{ .fw_name = "usb3phy_0_cc_pipe_clk" },
+	{ .fw_name = "xo" },

gcc-ipq5332 uses DT indices, please don't mix that with .fw_name.

Quoted 25 lines
drivers/clk/qcom/gcc-ipq5332.c +11 -5
+};
+
+static const struct parent_map gcc_usb3phy_0_cc_pipe_clk_xo_map[] = {
+	{ P_USB3PHY_0_PIPE, 0 },
+	{ P_XO, 2 },
+};
+
  static struct clk_rcg2 gcc_adss_pwm_clk_src = {
  	.cmd_rcgr = 0x1c004,
  	.mnd_width = 0,
@@ -1101,16 +1111,18 @@ static struct clk_rcg2 gcc_usb0_mock_utmi_clk_src = {
  	},
  };
 
-static struct clk_regmap_phy_mux gcc_usb0_pipe_clk_src = {
+static struct clk_regmap_mux usb0_pipe_clk_src = {
  	.reg = 0x2c074,
+	.shift = 8,
+	.width = 2,
+	.parent_map = gcc_usb3phy_0_cc_pipe_clk_xo_map,
  	.clkr = {
-		.hw.init = &(struct clk_init_data) {
-			.name = "gcc_usb0_pipe_clk_src",
-			.parent_data = &(const struct clk_parent_data) {
-				.index = DT_USB_PCIE_WRAPPER_PIPE_CLK,

drivers/clk/qcom/gcc-ipq5332.c static struct clk_rcg2 gcc_usb0_mock_utmi_clk_src = { · line 1126

Quoted 10 lines
drivers/clk/qcom/gcc-ipq5332.c +6 -3
-			},
-			.num_parents = 1,
-			.ops = &clk_regmap_phy_mux_ops,
+		.hw.init = &(const struct clk_init_data){
+			.name = "usb0phy_0_cc_pipe_clk_src",
+			.parent_data = gcc_usb3phy_0_cc_pipe_clk_xo,
+			.num_parents = 2,
+			.ops = &clk_regmap_mux_closest_ops,
+			.flags = CLK_SET_RATE_PARENT,
  		},

Soo... As you are reverting this. Is USB0 PIPE clock required to be parked to the XO? I was going to write 'before turning USB0_GDSC' off, but then I noticed that gcc-ipq5332 doesn't declare GDSCs. Does this platform have GDSCs?

drivers/clk/qcom/gcc-ipq5332.c static struct clk_branch gcc_usb0_pipe_clk = { · line 3057

Quoted 10 lines
drivers/clk/qcom/gcc-ipq5332.c +2 -2
  	},
  };
@@ -3041,8 +3053,8 @@ static struct clk_branch gcc_usb0_pipe_clk = {
  		.enable_mask = BIT(0),
  		.hw.init = &(const struct clk_init_data) {
  			.name = "gcc_usb0_pipe_clk",
-			.parent_hws = (const struct clk_hw*[]) {
-				&gcc_usb0_pipe_clk_src.clkr.hw,
+			.parent_names = (const char *[]){
+				"usb0_pipe_clk_src"

complete and definitive NAK. Do not use parent_names, we have just stopped migrating from them.

Quoted 12 lines
drivers/clk/qcom/gcc-ipq5332.c +1 -1
  			},
  			.num_parents = 1,
  			.flags = CLK_SET_RATE_PARENT,
@@ -3580,7 +3592,7 @@ static struct clk_regmap *gcc_ipq5332_clocks[] = {
  	[GCC_PCIE3X2_PIPE_CLK_SRC] = &gcc_pcie3x2_pipe_clk_src.clkr,
  	[GCC_PCIE3X1_0_PIPE_CLK_SRC] = &gcc_pcie3x1_0_pipe_clk_src.clkr,
  	[GCC_PCIE3X1_1_PIPE_CLK_SRC] = &gcc_pcie3x1_1_pipe_clk_src.clkr,
-	[GCC_USB0_PIPE_CLK_SRC] = &gcc_usb0_pipe_clk_src.clkr,
+	[GCC_USB0_PIPE_CLK_SRC] = &usb0_pipe_clk_src.clkr,
  };
 
  static const struct qcom_reset_map gcc_ipq5332_resets[] = {
Signature · 8 lines
With best wishes
Dmitry


-- 
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#22 lore raw

Re: [PATCH 5/9] phy: qcom-m31: Introduce qcom,m31 USB phy

In reply to Varadarajan Narayanan
Quoted 3 lines · Varadarajan Narayanan

Introduce CONFIG_PHY_QCOM_M31_USB for including the M31 phy driver

Is there any reason to keep Kconfig, Makefile and driver in different commits?

Quoted 23 lines
---
  drivers/phy/qualcomm/Kconfig | 11 +++++++++++
  1 file changed, 11 insertions(+)
drivers/phy/qualcomm/Kconfig +11 -0
index 67a45d9..8a363dd 100644
@@ -188,3 +188,14 @@ config PHY_QCOM_IPQ806X_USB
  	  This option enables support for the Synopsis PHYs present inside the
  	  Qualcomm USB3.0 DWC3 controller on ipq806x SoC. This driver supports
  	  both HS and SS PHY controllers.
+
+config PHY_QCOM_M31_USB
+	tristate "Qualcomm M31 HS PHY driver support"
+	depends on (USB || USB_GADGET) && ARCH_QCOM
+	select USB_PHY
+	help
+	  Enable this to support M31 HS PHY transceivers on Qualcomm chips
+	  with DWC3 USB core. It handles PHY initialization, clock
+	  management required after resetting the hardware and power
+	  management. This driver is required even for peripheral only or
+	  host only mode configurations.
Signature · 8 lines
With best wishes
Dmitry


-- 
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#29 lore raw

Re: [PATCH 7/9] arm64: dts: qcom: ipq5332: Add USB related nodes

In reply to Varadarajan Narayanan
Quoted 32 lines · Varadarajan Narayanan

Add USB phy and controller nodes

---
  arch/arm64/boot/dts/qcom/ipq5332.dtsi | 55 +++++++++++++++++++++++++++++++++++
  1 file changed, 55 insertions(+)
arch/arm64/boot/dts/qcom/ipq5332.dtsi +17 -0
index c2d6cc65..3183357 100644
@@ -383,6 +383,61 @@
  				status = "disabled";
  			};
  		};
+
+		usb_0_m31phy: hs_m31phy@7b000 {
+			compatible = "qcom,ipq5332-m31-usb-hsphy";
+			reg = <0x0007b000 0x12C>,
+			      <0x08af8800 0x400>;
+			reg-names = "m31usb_phy_base",
+				    "qscratch_base";
+			phy_type= "utmi";
+
+			resets = <&gcc GCC_QUSB2_0_PHY_BCR>;
+			reset-names = "usb2_phy_reset";
+
+			status = "okay";
+		};
+
+		usb2: usb2@8a00000 {
+			compatible = "qcom,ipq5332-dwc3", "qcom,dwc3";

arch/arm64/boot/dts/qcom/ipq5332.dtsi line 412

Quoted 10 lines
arch/arm64/boot/dts/qcom/ipq5332.dtsi +10 -0
+			#address-cells = <1>;
+			#size-cells = <1>;
+			ranges;
+
+			reg = <0x08af8800 0x100>;
+
+			clocks = <&gcc GCC_USB0_MASTER_CLK>,
+				<&gcc GCC_SNOC_USB_CLK>,
+				<&gcc GCC_USB0_SLEEP_CLK>,
+				<&gcc GCC_USB0_MOCK_UTMI_CLK>;

Please indent these values.

arch/arm64/boot/dts/qcom/ipq5332.dtsi line 417

Quoted 5 lines
arch/arm64/boot/dts/qcom/ipq5332.dtsi +5 -0
+
+			clock-names = "core",
+				"iface",
+				"sleep",
+				"mock_utmi";

Please indent these values.

arch/arm64/boot/dts/qcom/ipq5332.dtsi line 419

Quoted 2 lines
arch/arm64/boot/dts/qcom/ipq5332.dtsi +2 -0
+
+			interrupts-extended = <&intc GIC_SPI 134 IRQ_TYPE_LEVEL_HIGH>;

No PHY IRQs?

Quoted 24 lines
arch/arm64/boot/dts/qcom/ipq5332.dtsi +21 -0
+			interrupt-names = "pwr_event";
+
+			resets = <&gcc GCC_USB_BCR>;
+
+			qcom,select-utmi-as-pipe-clk;
+
+			usb2_0_dwc: usb@8a00000 {
+				compatible = "snps,dwc3";
+				reg = <0x08a00000 0xe000>;
+				clocks = <&gcc GCC_USB0_MOCK_UTMI_CLK>;
+				clock-names = "ref";
+				interrupts = <GIC_SPI 64 IRQ_TYPE_LEVEL_HIGH>;
+				usb-phy = <&usb_0_m31phy>;
+				tx-fifo-resize;
+				snps,is-utmi-l1-suspend;
+				snps,hird-threshold = /bits/ 8 <0x0>;
+				snps,dis_u2_susphy_quirk;
+				snps,dis_u3_susphy_quirk;
+				snps,ref-clock-period-ns = <21>;
+			};
+		};
  	};
 
  	timer {
Signature · 2 lines
With best wishes
Dmitry
maintainer
#5 lore raw

Re: [PATCH 2/9] dt-bindings: phy: qcom,m31: Document qcom,m31 USB phy

In reply to Varadarajan Narayanan
Quoted 9 lines · Varadarajan Narayanan

Document the M31 USB2 phy present in IPQ5332

---
 .../devicetree/bindings/phy/qcom,m31.yaml          | 69 ++++++++++++++++++++++
 1 file changed, 69 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/qcom,m31.yaml

My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check' on your patch (DT_CHECKER_FLAGS is new in v5.13):

yamllint warnings/errors:

dtschema/dtc warnings/errors:
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/phy/qcom,m31.example.dtb: hs_m31phy@5b00: status:0: 'ok' is not one of ['okay', 'disabled', 'reserved']
From schema: /usr/local/lib/python3.10/dist-packages/dtschema/schemas/dt-core.yaml

doc reference errors (make refcheckdocs):

See https://patchwork.ozlabs.org/project/devicetree-bindings/patch/14f60578e2935c0844537eab162af3afa52ffe39.1686126439.git.quic_varada@quicinc.com

The base for the series is generally the latest rc1. A different dependency should be noted in *this* patch.

If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:

pip3 install dtschema --upgrade

Please check and re-submit after running the above command yourself. Note that DT_SCHEMA_FILES can be set to your schema file to speed up checking your schema. However, it must be unset to test all examples with your schema.

#13 lore raw

Re: [PATCH 3/9] phy: qcom-m31: Introduce qcom,m31 USB phy driver

In reply to Varadarajan Narayanan
Quoted 21 lines · Varadarajan Narayanan

Add the M31 USB2 phy driver

---
 drivers/phy/qualcomm/phy-qcom-m31.c | 360 ++++++++++++++++++++++++++++++++++++
 1 file changed, 360 insertions(+)
 create mode 100644 drivers/phy/qualcomm/phy-qcom-m31.c
drivers/phy/qualcomm/phy-qcom-m31.c new file +7 -0
new file mode 100644
index 0000000..d29a91e
@@ -0,0 +1,360 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2014-2016, 2020, The Linux Foundation. All rights reserved.
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>

drivers/phy/qualcomm/phy-qcom-m31.c line 17

Quoted 10 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +10 -0
+#include <linux/err.h>
+#include <linux/slab.h>
+#include <linux/clk.h>
+#include <linux/delay.h>
+#include <linux/io.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/usb/phy.h>
+#include <linux/reset.h>
+#include <linux/of_device.h>

Please sort these

Quoted 21 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +21 -0
+
+enum clk_reset_action {
+	CLK_RESET_DEASSERT	= 0,
+	CLK_RESET_ASSERT	= 1
+};
+
+#define USB2PHY_PORT_POWERDOWN		0xA4
+#define POWER_UP			BIT(0)
+#define POWER_DOWN			0
+
+#define USB2PHY_PORT_UTMI_CTRL1	0x40
+
+#define USB2PHY_PORT_UTMI_CTRL2	0x44
+#define UTMI_ULPI_SEL			BIT(7)
+#define UTMI_TEST_MUX_SEL		BIT(6)
+
+#define HS_PHY_CTRL_REG			0x10
+#define UTMI_OTG_VBUS_VALID             BIT(20)
+#define SW_SESSVLD_SEL                  BIT(28)
+
+#define USB_PHY_CFG0			0x94

drivers/phy/qualcomm/phy-qcom-m31.c line 48

Quoted 10 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +10 -0
+#define USB_PHY_UTMI_CTRL5		0x50
+#define USB_PHY_FSEL_SEL		0xB8
+#define USB_PHY_HS_PHY_CTRL_COMMON0	0x54
+#define USB_PHY_REFCLK_CTRL		0xA0
+#define USB_PHY_HS_PHY_CTRL2		0x64
+#define USB_PHY_UTMI_CTRL0		0x3c
+#define USB2PHY_USB_PHY_M31_XCFGI_1	0xBC
+#define USB2PHY_USB_PHY_M31_XCFGI_4	0xC8
+#define USB2PHY_USB_PHY_M31_XCFGI_5	0xCC
+#define USB2PHY_USB_PHY_M31_XCFGI_11	0xE4

Could you sort them address-wise?

drivers/phy/qualcomm/phy-qcom-m31.c line 55

Quoted 7 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +7 -0
+
+#define USB2_0_TX_ENABLE		BIT(2)
+#define HSTX_SLEW_RATE_565PS		3
+#define PLL_CHARGING_PUMP_CURRENT_35UA	(3 << 3)
+#define ODT_VALUE_38_02_OHM		(3 << 6)
+#define ODT_VALUE_45_02_OHM		BIT(2)
+#define HSTX_PRE_EMPHASIS_LEVEL_0_55MA	(1)

Weird mix of values, bits, bitfields.. perhaps BIT(n) and GENMASK() (+ FIELD_PREP) would be more suitable?

drivers/phy/qualcomm/phy-qcom-m31.c line 58

Quoted 3 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +3 -0
+
+#define UTMI_PHY_OVERRIDE_EN		BIT(1)
+#define POR_EN				BIT(1)

Please associate these with their registers, like

#define FOO_REG 0xf00
#define POR_EN BIT(1)

drivers/phy/qualcomm/phy-qcom-m31.c line 70

Quoted 12 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +12 -0
+#define FREQ_SEL			BIT(0)
+#define COMMONONN			BIT(7)
+#define FSEL				BIT(4)
+#define RETENABLEN			BIT(3)
+#define USB2_SUSPEND_N_SEL		BIT(3)
+#define USB2_SUSPEND_N			BIT(2)
+#define USB2_UTMI_CLK_EN		BIT(1)
+#define CLKCORE				BIT(1)
+#define ATERESET			~BIT(0)
+#define FREQ_24MHZ			(5 << 4)
+#define XCFG_COARSE_TUNE_NUM		(2 << 0)
+#define XCFG_FINE_TUNE_NUM		(1 << 3)

same comment

drivers/phy/qualcomm/phy-qcom-m31.c line 73

Quoted 3 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +3 -0
+
+static void m31usb_write_readback(void *base, u32 offset,
+					const u32 mask, u32 val);

We don't need this forward-definition, just move the function up.

Quoted 10 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +10 -0
+
+struct m31usb_phy {
+	struct usb_phy		phy;
+	void __iomem		*base;
+	void __iomem		*qscratch_base;
+
+	struct reset_control	*phy_reset;
+
+	bool			cable_connected;
+	bool			suspended;

drivers/phy/qualcomm/phy-qcom-m31.c line 93

Quoted 10 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +10 -0
+	bool			ulpi_mode;
+};
+
+static void m31usb_reset(struct m31usb_phy *qphy, u32 action)
+{
+	if (action == CLK_RESET_ASSERT)
+		reset_control_assert(qphy->phy_reset);
+	else
+		reset_control_deassert(qphy->phy_reset);
+	wmb(); /* ensure data is written to hw register */

Please move the comment above the call.

drivers/phy/qualcomm/phy-qcom-m31.c line 99

Quoted 6 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +6 -0
+}
+
+static void m31usb_phy_enable_clock(struct m31usb_phy *qphy)
+{
+	/* Enable override ctrl */
+	writel(UTMI_PHY_OVERRIDE_EN, qphy->base + USB_PHY_CFG0);

Some of the comments are missing a space before '*/'

Also, please consider adding some newlines to logically split the actions.

Quoted 16 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +16 -0
+	/* Enable POR*/
+	writel(POR_EN, qphy->base + USB_PHY_UTMI_CTRL5);
+	udelay(15);
+	/* Configure frequency select value*/
+	writel(FREQ_SEL, qphy->base + USB_PHY_FSEL_SEL);
+	/* Configure refclk frequency */
+	writel(COMMONONN | FSEL | RETENABLEN,
+		qphy->base + USB_PHY_HS_PHY_CTRL_COMMON0);
+	/* select refclk source */
+	writel(CLKCORE, qphy->base + USB_PHY_REFCLK_CTRL);
+	/* select ATERESET*/
+	writel(POR_EN & ATERESET, qphy->base + USB_PHY_UTMI_CTRL5);
+	writel(USB2_SUSPEND_N_SEL | USB2_SUSPEND_N | USB2_UTMI_CLK_EN,
+		qphy->base + USB_PHY_HS_PHY_CTRL2);
+	writel(0x0, qphy->base + USB_PHY_UTMI_CTRL5);
+	writel(USB2_SUSPEND_N | USB2_UTMI_CLK_EN,

drivers/phy/qualcomm/phy-qcom-m31.c line 125

Quoted 10 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +10 -0
+		qphy->base + USB_PHY_HS_PHY_CTRL2);
+	/* Disable override ctrl */
+	writel(0x0, qphy->base + USB_PHY_CFG0);
+}
+
+static void ipq5332_m31usb_phy_enable_clock(struct m31usb_phy *qphy)
+{
+	/* Enable override ctrl */
+	writel(UTMI_PHY_OVERRIDE_EN, qphy->base + USB_PHY_CFG0);
+	/* Enable POR*/

ditto

Quoted 8 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +8 -0
+	writel(POR_EN, qphy->base + USB_PHY_UTMI_CTRL5);
+	udelay(15);
+	/* Configure frequency select value*/
+	writel(FREQ_SEL, qphy->base + USB_PHY_FSEL_SEL);
+	/* Configure refclk frequency */
+	writel(COMMONONN | FREQ_24MHZ | RETENABLEN,
+		qphy->base + USB_PHY_HS_PHY_CTRL_COMMON0);
+	/* select ATERESET*/

drivers/phy/qualcomm/phy-qcom-m31.c line 143

Quoted 10 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +10 -0
+	writel(POR_EN & ATERESET, qphy->base + USB_PHY_UTMI_CTRL5);
+	writel(USB2_SUSPEND_N_SEL | USB2_SUSPEND_N | USB2_UTMI_CLK_EN,
+		qphy->base + USB_PHY_HS_PHY_CTRL2);
+	writel(XCFG_COARSE_TUNE_NUM  | XCFG_FINE_TUNE_NUM,
+				qphy->base + USB2PHY_USB_PHY_M31_XCFGI_11);
+	/* Adjust HSTX slew rate to 565 ps*/
+	/* Adjust PLL lock Time counter for release clock to 35uA */
+	/* Adjust Manual control ODT value to 38.02 Ohm */
+	writel(HSTX_SLEW_RATE_565PS | PLL_CHARGING_PUMP_CURRENT_35UA |
+		ODT_VALUE_38_02_OHM, qphy->base + USB2PHY_USB_PHY_M31_XCFGI_4);

These functions seem very similar, with the main difference being that IPQ5332 adds some more writes at the end. Perhaps some commonizing could be done?

Quoted 12 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +12 -0
+	/*
+	 * Enable to always turn on USB 2.0 TX driver
+	 * when system is in USB 2.0 HS mode
+	 */
+	writel(USB2_0_TX_ENABLE, qphy->base + USB2PHY_USB_PHY_M31_XCFGI_1);
+	/* Adjust Manual control ODT value to 45.02 Ohm */
+	/* Adjust HSTX Pre-emphasis level to 0.55mA */
+	writel(ODT_VALUE_45_02_OHM | HSTX_PRE_EMPHASIS_LEVEL_0_55MA,
+		qphy->base + USB2PHY_USB_PHY_M31_XCFGI_5);
+	udelay(4);
+	writel(0x0, qphy->base + USB_PHY_UTMI_CTRL5);
+	writel(USB2_SUSPEND_N | USB2_UTMI_CLK_EN,

drivers/phy/qualcomm/phy-qcom-m31.c line 165

Quoted 10 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +10 -0
+		qphy->base + USB_PHY_HS_PHY_CTRL2);
+}
+
+static int m31usb_phy_init(struct usb_phy *phy)
+{
+	struct m31usb_phy *qphy = container_of(phy, struct m31usb_phy, phy);
+
+	/* Perform phy reset */
+	m31usb_reset(qphy, CLK_RESET_ASSERT);
+	usleep_range(1, 5);

https://www.kernel.org/doc/Documentation/timers/timers-howto.txt

this may not work as intended

drivers/phy/qualcomm/phy-qcom-m31.c line 176

Quoted 11 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +11 -0
+	m31usb_reset(qphy, CLK_RESET_DEASSERT);
+
+	/* configure for ULPI mode if requested */
+	if (qphy->ulpi_mode)
+		writel_relaxed(0x0, qphy->base + USB2PHY_PORT_UTMI_CTRL2);
+
+	/* Enable the PHY */
+	writel_relaxed(POWER_UP, qphy->base + USB2PHY_PORT_POWERDOWN);
+
+	/* Make sure above write completed */
+	wmb();

As you're calling wmb in the reset func, dropping _relaxed from the ULPI and PORT_POWERDOWN writes should work the same

drivers/phy/qualcomm/phy-qcom-m31.c line 183

Quoted 7 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +7 -0
+
+	/* Turn on phy ref clock*/
+	if (of_device_is_compatible(phy->dev->of_node,
+					"qcom,ipq5332-m31-usb-hsphy"))
+		ipq5332_m31usb_phy_enable_clock(qphy);
+	else
+		m31usb_phy_enable_clock(qphy);

This should be done using OF match data.

Quoted 13 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +13 -0
+
+	/* Set OTG VBUS Valid from HSPHY to controller */
+	m31usb_write_readback(qphy->qscratch_base, HS_PHY_CTRL_REG,
+				UTMI_OTG_VBUS_VALID, UTMI_OTG_VBUS_VALID);
+	/* Indicate value is driven by UTMI_OTG_VBUS_VALID bit */
+	m31usb_write_readback(qphy->qscratch_base, HS_PHY_CTRL_REG,
+				SW_SESSVLD_SEL, SW_SESSVLD_SEL);
+
+	return 0;
+}
+
+static void m31usb_phy_shutdown(struct usb_phy *phy)
+{

drivers/phy/qualcomm/phy-qcom-m31.c line 206

Quoted 10 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +10 -0
+	struct m31usb_phy *qphy = container_of(phy, struct m31usb_phy, phy);
+
+	/* Disable the PHY */
+	writel_relaxed(POWER_DOWN, qphy->base + USB2PHY_PORT_POWERDOWN);
+	/* Make sure above write completed */
+	wmb();
+}
+
+static void m31usb_write_readback(void *base, u32 offset,
+					const u32 mask, u32 val)

The indentation here makes const u32.. misaligned.

Quoted 17 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +17 -0
+{
+	u32 write_val, tmp = readl_relaxed(base + offset);
+
+	tmp &= ~mask; /* retain other bits */
+	write_val = tmp | val;
+
+	writel_relaxed(write_val, base + offset);
+	/* Make sure above write completed */
+	wmb();
+
+	/* Read back to see if val was written */
+	tmp = readl_relaxed(base + offset);
+	tmp &= mask; /* clear other bits */
+
+	if (tmp != val)
+		pr_err("%s: write: %x to QSCRATCH: %x FAILED\n",
+			__func__, val, offset);

drivers/phy/qualcomm/phy-qcom-m31.c line 233

Quoted 10 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +10 -0
+}
+
+static int m31usb_phy_notify_connect(struct usb_phy *phy,
+					enum usb_device_speed speed)
+{
+	struct m31usb_phy *qphy = container_of(phy, struct m31usb_phy, phy);
+
+	qphy->cable_connected = true;
+
+	dev_dbg(phy->dev, " cable_connected=%d\n", qphy->cable_connected);

spurious space at the beginning of the string

drivers/phy/qualcomm/phy-qcom-m31.c line 238

Quoted 5 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +5 -0
+
+	/* Set OTG VBUS Valid from HSPHY to controller */
+	m31usb_write_readback(qphy->qscratch_base, HS_PHY_CTRL_REG,
+				UTMI_OTG_VBUS_VALID,
+				UTMI_OTG_VBUS_VALID);

Please align the lines with the previous opening bracket

Quoted 27 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +27 -0
+
+	/* Indicate value is driven by UTMI_OTG_VBUS_VALID bit */
+	m31usb_write_readback(qphy->qscratch_base, HS_PHY_CTRL_REG,
+				SW_SESSVLD_SEL, SW_SESSVLD_SEL);
+
+	dev_dbg(phy->dev, "M31USB2 phy connect notification\n");
+	return 0;
+}
+
+static int m31usb_phy_notify_disconnect(struct usb_phy *phy,
+					enum usb_device_speed speed)
+{
+	struct m31usb_phy *qphy = container_of(phy, struct m31usb_phy, phy);
+
+	qphy->cable_connected = false;
+
+	dev_dbg(phy->dev, " cable_connected=%d\n", qphy->cable_connected);
+
+	/* Set OTG VBUS Valid from HSPHY to controller */
+	m31usb_write_readback(qphy->qscratch_base, HS_PHY_CTRL_REG,
+				UTMI_OTG_VBUS_VALID, 0);
+
+	/* Indicate value is driven by UTMI_OTG_VBUS_VALID bit */
+	m31usb_write_readback(qphy->qscratch_base, HS_PHY_CTRL_REG,
+				SW_SESSVLD_SEL, 0);
+
+	dev_dbg(phy->dev, "M31USB2 phy disconnect notification\n");

drivers/phy/qualcomm/phy-qcom-m31.c line 275

Quoted 10 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +10 -0
+	return 0;
+}
+
+static int m31usb_phy_probe(struct platform_device *pdev)
+{
+	struct m31usb_phy *qphy;
+	struct device *dev = &pdev->dev;
+	struct resource *res;
+	int ret;
+	const char *phy_type;

Please sort these in a reverse-Christmas-tree order.

drivers/phy/qualcomm/phy-qcom-m31.c line 285

Quoted 10 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +10 -0
+
+	qphy = devm_kzalloc(dev, sizeof(*qphy), GFP_KERNEL);
+	if (!qphy)
+		return -ENOMEM;
+
+	qphy->phy.dev = dev;
+
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
+							"m31usb_phy_base");
+	qphy->base = devm_ioremap_resource(dev, res);

devm_platform_get_and_ioremap_resource?

drivers/phy/qualcomm/phy-qcom-m31.c line 291

Quoted 6 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +6 -0
+	if (IS_ERR(qphy->base))
+		return PTR_ERR(qphy->base);
+
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
+							"qscratch_base");
+	if (res) {

Do we expect platforms without this register space?

drivers/phy/qualcomm/phy-qcom-m31.c line 300

Quoted 9 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +9 -0
+		qphy->qscratch_base = devm_ioremap(dev, res->start,
+							resource_size(res));
+		if (IS_ERR(qphy->qscratch_base)) {
+			dev_dbg(dev, "couldn't ioremap qscratch_base\n");
+			qphy->qscratch_base = NULL;
+		}
+	}
+
+	qphy->phy_reset = devm_reset_control_get(dev, "usb2_phy_reset");

not _exclusive?

drivers/phy/qualcomm/phy-qcom-m31.c line 305

Quoted 5 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +5 -0
+	if (IS_ERR(qphy->phy_reset))
+		return PTR_ERR(qphy->phy_reset);
+
+	qphy->ulpi_mode = false;
+	ret = of_property_read_string(dev->of_node, "phy_type", &phy_type);

of_usb_get_phy_mode?

Quoted 17 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +17 -0
+
+	if (!ret) {
+		if (!strcasecmp(phy_type, "ulpi"))
+			qphy->ulpi_mode = true;
+	} else {
+		dev_err(dev, "error reading phy_type property\n");
+		return ret;
+	}
+
+	platform_set_drvdata(pdev, qphy);
+
+	qphy->phy.label			= "qcom-m31usb-phy";
+	qphy->phy.init			= m31usb_phy_init;
+	qphy->phy.shutdown		= m31usb_phy_shutdown;
+	qphy->phy.type			= USB_PHY_TYPE_USB2;
+
+	if (qphy->qscratch_base) {

drivers/phy/qualcomm/phy-qcom-m31.c line 332

Quoted 10 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +10 -0
+		qphy->phy.notify_connect        = m31usb_phy_notify_connect;
+		qphy->phy.notify_disconnect     = m31usb_phy_notify_disconnect;
+	}
+
+	ret = usb_add_phy_dev(&qphy->phy);
+
+	return ret;
+}
+
+static int m31usb_phy_remove(struct platform_device *pdev)

Please make this return void and pass it to .remove_new

Quoted 11 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +11 -0
+{
+	struct m31usb_phy *qphy = platform_get_drvdata(pdev);
+
+	usb_remove_phy(&qphy->phy);
+
+	return 0;
+}
+
+static const struct of_device_id m31usb_phy_id_table[] = {
+	{ .compatible = "qcom,m31-usb-hsphy",},
+	{ .compatible = "qcom,ipq5332-m31-usb-hsphy",},

drivers/phy/qualcomm/phy-qcom-m31.c line 353

Quoted 10 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +10 -0
+	{ },
+};
+MODULE_DEVICE_TABLE(of, m31usb_phy_id_table);
+
+static struct platform_driver m31usb_phy_driver = {
+	.probe		= m31usb_phy_probe,
+	.remove		= m31usb_phy_remove,
+	.driver = {
+		.name	= "qcom-m31usb-phy",
+		.of_match_table = of_match_ptr(m31usb_phy_id_table),

of_match_ptr is unnecessary, this driver depends on OF.

Konrad

Quoted 7 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +7 -0
+	},
+};
+
+module_platform_driver(m31usb_phy_driver);
+
+MODULE_DESCRIPTION("USB2 Qualcomm M31 HSPHY driver");
+MODULE_LICENSE("GPL");
#14 lore raw

Re: [PATCH 3/9] phy: qcom-m31: Introduce qcom,m31 USB phy driver

Two minor nits on top of the review:

Quoted 58 lines · Konrad Dybcio
Quoted 21 lines · Varadarajan Narayanan

Add the M31 USB2 phy driver

---
  drivers/phy/qualcomm/phy-qcom-m31.c | 360 ++++++++++++++++++++++++++++++++++++
  1 file changed, 360 insertions(+)

create mode 100644 drivers/phy/qualcomm/phy-qcom-m31.c

drivers/phy/qualcomm/phy-qcom-m31.c new file +7 -0
new file mode 100644
index 0000000..d29a91e
@@ -0,0 +1,360 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2014-2016, 2020, The Linux Foundation. All rights reserved.
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>

drivers/phy/qualcomm/phy-qcom-m31.c line 17

Quoted 10 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +10 -0
+#include <linux/err.h>
+#include <linux/slab.h>
+#include <linux/clk.h>
+#include <linux/delay.h>
+#include <linux/io.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/usb/phy.h>
+#include <linux/reset.h>
+#include <linux/of_device.h>

Please sort these

Quoted 24 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +24 -0
+
+enum clk_reset_action {
+	CLK_RESET_DEASSERT	= 0,
+	CLK_RESET_ASSERT	= 1
+};
+
+#define USB2PHY_PORT_POWERDOWN		0xA4
+#define POWER_UP			BIT(0)
+#define POWER_DOWN			0
+
+#define USB2PHY_PORT_UTMI_CTRL1	0x40
+
+#define USB2PHY_PORT_UTMI_CTRL2	0x44
+#define UTMI_ULPI_SEL			BIT(7)
+#define UTMI_TEST_MUX_SEL		BIT(6)
+
+#define HS_PHY_CTRL_REG			0x10
+#define UTMI_OTG_VBUS_VALID             BIT(20)
+#define SW_SESSVLD_SEL                  BIT(28)
+
+#define USB_PHY_CFG0			0x94
+#define USB_PHY_UTMI_CTRL5		0x50
+#define USB_PHY_FSEL_SEL		0xB8
+#define USB_PHY_HS_PHY_CTRL_COMMON0	0x54
Quoted 8 lines

drivers/phy/qualcomm/phy-qcom-m31.c line 48

Quoted 7 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +7 -0
+#define USB_PHY_REFCLK_CTRL		0xA0
+#define USB_PHY_HS_PHY_CTRL2		0x64
+#define USB_PHY_UTMI_CTRL0		0x3c
+#define USB2PHY_USB_PHY_M31_XCFGI_1	0xBC
+#define USB2PHY_USB_PHY_M31_XCFGI_4	0xC8
+#define USB2PHY_USB_PHY_M31_XCFGI_5	0xCC
+#define USB2PHY_USB_PHY_M31_XCFGI_11	0xE4

Could you sort them address-wise?

... and lowercase the hex values, please.

Quoted 51 lines

drivers/phy/qualcomm/phy-qcom-m31.c line 55

Quoted 8 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +7 -0
+
+#define USB2_0_TX_ENABLE		BIT(2)
+#define HSTX_SLEW_RATE_565PS		3
+#define PLL_CHARGING_PUMP_CURRENT_35UA	(3 << 3)
+#define ODT_VALUE_38_02_OHM		(3 << 6)
+#define ODT_VALUE_45_02_OHM		BIT(2)
+#define HSTX_PRE_EMPHASIS_LEVEL_0_55MA	(1)

Weird mix of values, bits, bitfields.. perhaps BIT(n) and GENMASK() (+ FIELD_PREP) would be more suitable?

drivers/phy/qualcomm/phy-qcom-m31.c line 58

Quoted 3 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +3 -0
+
+#define UTMI_PHY_OVERRIDE_EN		BIT(1)
+#define POR_EN				BIT(1)

Please associate these with their registers, like

#define FOO_REG 0xf00
#define POR_EN BIT(1)

drivers/phy/qualcomm/phy-qcom-m31.c line 70

Quoted 12 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +12 -0
+#define FREQ_SEL			BIT(0)
+#define COMMONONN			BIT(7)
+#define FSEL				BIT(4)
+#define RETENABLEN			BIT(3)
+#define USB2_SUSPEND_N_SEL		BIT(3)
+#define USB2_SUSPEND_N			BIT(2)
+#define USB2_UTMI_CLK_EN		BIT(1)
+#define CLKCORE				BIT(1)
+#define ATERESET			~BIT(0)
+#define FREQ_24MHZ			(5 << 4)
+#define XCFG_COARSE_TUNE_NUM		(2 << 0)
+#define XCFG_FINE_TUNE_NUM		(1 << 3)

same comment

drivers/phy/qualcomm/phy-qcom-m31.c line 73

Quoted 3 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +3 -0
+
+static void m31usb_write_readback(void *base, u32 offset,
+					const u32 mask, u32 val);

We don't need this forward-definition, just move the function up.

Quoted 13 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +13 -0
+
+struct m31usb_phy {
+	struct usb_phy		phy;
+	void __iomem		*base;
+	void __iomem		*qscratch_base;
+
+	struct reset_control	*phy_reset;
+
+	bool			cable_connected;
+	bool			suspended;
+	bool			ulpi_mode;
+};
+
Quoted 10 lines

drivers/phy/qualcomm/phy-qcom-m31.c line 93

Quoted 7 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +7 -0
+static void m31usb_reset(struct m31usb_phy *qphy, u32 action)
+{
+	if (action == CLK_RESET_ASSERT)
+		reset_control_assert(qphy->phy_reset);
+	else
+		reset_control_deassert(qphy->phy_reset);
+	wmb(); /* ensure data is written to hw register */

Please move the comment above the call.

Quoted 1 line
drivers/phy/qualcomm/phy-qcom-m31.c new file +1 -0
+}

Or even better just inline the function. I was never a fan of such multiplexers.

Also does wmb() make sense here? Doesn't regmap (which is used by reset controller) remove the need for it?

Quoted 9 lines

drivers/phy/qualcomm/phy-qcom-m31.c line 99

Quoted 5 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +5 -0
+
+static void m31usb_phy_enable_clock(struct m31usb_phy *qphy)
+{
+	/* Enable override ctrl */
+	writel(UTMI_PHY_OVERRIDE_EN, qphy->base + USB_PHY_CFG0);

Some of the comments are missing a space before '*/'

Also, please consider adding some newlines to logically split the actions.

Signature · 8 lines
With best wishes
Dmitry


-- 
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#31 lore raw

Re: [PATCH 7/9] arm64: dts: qcom: ipq5332: Add USB related nodes

In reply to Varadarajan Narayanan
Quoted 12 lines · Varadarajan Narayanan

Add USB phy and controller nodes

---
 arch/arm64/boot/dts/qcom/ipq5332.dtsi | 55 +++++++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)
arch/arm64/boot/dts/qcom/ipq5332.dtsi +0 -0
index c2d6cc65..3183357 100644

arch/arm64/boot/dts/qcom/ipq5332.dtsi line 389

Quoted 7 lines
arch/arm64/boot/dts/qcom/ipq5332.dtsi +4 -0
@@ -383,6 +383,61 @@
 				status = "disabled";
 			};
 		};
+
+		usb_0_m31phy: hs_m31phy@7b000 {
+			compatible = "qcom,ipq5332-m31-usb-hsphy";
+			reg = <0x0007b000 0x12C>,

random uppercase hex

arch/arm64/boot/dts/qcom/ipq5332.dtsi line 393

Quoted 4 lines
arch/arm64/boot/dts/qcom/ipq5332.dtsi +4 -0
+			      <0x08af8800 0x400>;
+			reg-names = "m31usb_phy_base",
+				    "qscratch_base";
+			phy_type= "utmi";

Missing space before '='

arch/arm64/boot/dts/qcom/ipq5332.dtsi line 398

Quoted 5 lines
arch/arm64/boot/dts/qcom/ipq5332.dtsi +5 -0
+
+			resets = <&gcc GCC_QUSB2_0_PHY_BCR>;
+			reset-names = "usb2_phy_reset";
+
+			status = "okay";

If you're only defining the node, it's enabled by default

In this case, you'd probably want to disable it by default.

arch/arm64/boot/dts/qcom/ipq5332.dtsi line 405

Quoted 7 lines
arch/arm64/boot/dts/qcom/ipq5332.dtsi +7 -0
+		};
+
+		usb2: usb2@8a00000 {
+			compatible = "qcom,ipq5332-dwc3", "qcom,dwc3";
+			#address-cells = <1>;
+			#size-cells = <1>;
+			ranges;

Please push these 3 properties to the end

And add status = "disabled" below them.

arch/arm64/boot/dts/qcom/ipq5332.dtsi line 413

Quoted 8 lines
arch/arm64/boot/dts/qcom/ipq5332.dtsi +8 -0
+
+			reg = <0x08af8800 0x100>;
+
+			clocks = <&gcc GCC_USB0_MASTER_CLK>,
+				<&gcc GCC_SNOC_USB_CLK>,
+				<&gcc GCC_USB0_SLEEP_CLK>,
+				<&gcc GCC_USB0_MOCK_UTMI_CLK>;
+

Please remove this newline.

arch/arm64/boot/dts/qcom/ipq5332.dtsi line 417

Quoted 4 lines
arch/arm64/boot/dts/qcom/ipq5332.dtsi +4 -0
+			clock-names = "core",
+				"iface",
+				"sleep",
+				"mock_utmi";

Please align this, and all other similar lists.

arch/arm64/boot/dts/qcom/ipq5332.dtsi line 419

Quoted 2 lines
arch/arm64/boot/dts/qcom/ipq5332.dtsi +2 -0
+
+			interrupts-extended = <&intc GIC_SPI 134 IRQ_TYPE_LEVEL_HIGH>;

interrupts-extended is unnecessary with just a single interrupt source.. you can make it interrupts and drop the GIC reference.

It would also be nice to push the interrupt properties below 'reg'. We're working on documenting and automating checking the preferred property order.

Quoted 9 lines
arch/arm64/boot/dts/qcom/ipq5332.dtsi +9 -0
+			interrupt-names = "pwr_event";
+
+			resets = <&gcc GCC_USB_BCR>;
+
+			qcom,select-utmi-as-pipe-clk;
+
+			usb2_0_dwc: usb@8a00000 {
+				compatible = "snps,dwc3";
+				reg = <0x08a00000 0xe000>;

arch/arm64/boot/dts/qcom/ipq5332.dtsi line 438

Quoted 10 lines
arch/arm64/boot/dts/qcom/ipq5332.dtsi +10 -0
+				clocks = <&gcc GCC_USB0_MOCK_UTMI_CLK>;
+				clock-names = "ref";
+				interrupts = <GIC_SPI 64 IRQ_TYPE_LEVEL_HIGH>;
+				usb-phy = <&usb_0_m31phy>;
+				tx-fifo-resize;
+				snps,is-utmi-l1-suspend;
+				snps,hird-threshold = /bits/ 8 <0x0>;
+				snps,dis_u2_susphy_quirk;
+				snps,dis_u3_susphy_quirk;
+				snps,ref-clock-period-ns = <21>;

1/21 is 0.0476.. that doesn't seem to correspond to the ref clk frequency?

Konrad

Quoted 5 lines
arch/arm64/boot/dts/qcom/ipq5332.dtsi +2 -0
+			};
+		};
 	};
 
 	timer {
Signature · 3 lines
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#6 lore raw

Re: [PATCH 2/9] dt-bindings: phy: qcom,m31: Document qcom,m31 USB phy

In reply to Varadarajan Narayanan
Quoted 1 line · Varadarajan Narayanan

Document the M31 USB2 phy present in IPQ5332

Full stop.

Quoted 14 lines
---
 .../devicetree/bindings/phy/qcom,m31.yaml          | 69 ++++++++++++++++++++++
 1 file changed, 69 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/qcom,m31.yaml
Documentation/devicetree/bindings/phy/qcom,m31.yaml new file +0 -0
new file mode 100644
index 0000000..8ad4ba4

Documentation/devicetree/bindings/phy/qcom,m31.yaml line 2

Quoted 2 lines
Documentation/devicetree/bindings/phy/qcom,m31.yaml new file +2 -0
@@ -0,0 +1,69 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+

Drop stray blank lines.

Documentation/devicetree/bindings/phy/qcom,m31.yaml line 8

Quoted 6 lines
Documentation/devicetree/bindings/phy/qcom,m31.yaml new file +6 -0
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/phy/qcom,m31.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Qualcomm M31 USB PHY

What is M31?

Documentation/devicetree/bindings/phy/qcom,m31.yaml line 15

Quoted 7 lines
Documentation/devicetree/bindings/phy/qcom,m31.yaml new file +7 -0
+
+maintainers:
+  - Sricharan Ramabadhran <[email protected]>
+  - Varadarajan Narayanan <[email protected]>
+
+description:
+  This file contains documentation for the USB M31 PHY found in Qualcomm

Drop redundant parts ("This file contains documentation for the").

Documentation/devicetree/bindings/phy/qcom,m31.yaml line 20

Quoted 5 lines
Documentation/devicetree/bindings/phy/qcom,m31.yaml new file +5 -0
+  IPQ5018, IPQ5332 SoCs.
+
+properties:
+  compatible:
+    oneOf:

That's not oneOf.

Documentation/devicetree/bindings/phy/qcom,m31.yaml line 21

Quoted 1 line
Documentation/devicetree/bindings/phy/qcom,m31.yaml new file +1 -0
+      - items:

No items.

Documentation/devicetree/bindings/phy/qcom,m31.yaml line 23

Quoted 2 lines
Documentation/devicetree/bindings/phy/qcom,m31.yaml new file +2 -0
+          - enum:
+              - qcom,m31-usb-hsphy

I am confused what's this. If m31 is coming from some IP block provider, then you are using wrong vendor prefix.
https://www.m31tech.com/download_file/M31_USB.pdf

Documentation/devicetree/bindings/phy/qcom,m31.yaml line 24

Quoted 1 line
Documentation/devicetree/bindings/phy/qcom,m31.yaml new file +1 -0
+              - qcom,ipq5332-m31-usb-hsphy

This confuses me even more. IPQ m31?

Documentation/devicetree/bindings/phy/qcom,m31.yaml line 28

Quoted 4 lines
Documentation/devicetree/bindings/phy/qcom,m31.yaml new file +4 -0
+
+  reg:
+    description:
+      Offset and length of the M31 PHY register set

Drop description, obvious.

Documentation/devicetree/bindings/phy/qcom,m31.yaml line 34

Quoted 6 lines
Documentation/devicetree/bindings/phy/qcom,m31.yaml new file +6 -0
+    maxItems: 2
+
+  reg-names:
+    items:
+      - const: m31usb_phy_base
+      - const: qscratch_base

Drop "_base" from both.

Documentation/devicetree/bindings/phy/qcom,m31.yaml line 41

Quoted 7 lines
Documentation/devicetree/bindings/phy/qcom,m31.yaml new file +7 -0
+
+  phy_type:
+    oneOf:
+      - items:
+          - enum:
+              - utmi
+              - ulpi

This does not belong to phy, but to USB node.

Documentation/devicetree/bindings/phy/qcom,m31.yaml line 46

Quoted 5 lines
Documentation/devicetree/bindings/phy/qcom,m31.yaml new file +5 -0
+
+  resets:
+    maxItems: 1
+    description:
+      List of phandles and reset pairs, one for each entry in reset-names.

Drop useless description.

Documentation/devicetree/bindings/phy/qcom,m31.yaml line 51

Quoted 5 lines
Documentation/devicetree/bindings/phy/qcom,m31.yaml new file +5 -0
+
+  reset-names:
+    items:
+      - const:
+          usb2_phy_reset

Drop entire reset-names.

Documentation/devicetree/bindings/phy/qcom,m31.yaml line 58

Quoted 7 lines
Documentation/devicetree/bindings/phy/qcom,m31.yaml new file +7 -0
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/clock/qcom,ipq5332-gcc.h>
+    hs_m31phy_0: hs_m31phy@5b00 {

Node names should be generic. See also explanation and list of examples in DT specification:
https://devicetree-specification.readthedocs.io/en/latest/chapter2-devicetree-basics.html#generic-names-recommendation

Also, no underscores in node names.

Documentation/devicetree/bindings/phy/qcom,m31.yaml line 60

Quoted 2 lines
Documentation/devicetree/bindings/phy/qcom,m31.yaml new file +2 -0
+        compatible = "qcom,m31-usb-hsphy";
+        reg = <0x5b000 0x3000>,

This is not what your unit address is saying.

Documentation/devicetree/bindings/phy/qcom,m31.yaml line 61

Quoted 1 line
Documentation/devicetree/bindings/phy/qcom,m31.yaml new file +1 -0
+            <0x08af8800 0x400>;

Align it.

Documentation/devicetree/bindings/phy/qcom,m31.yaml line 63

Quoted 2 lines
Documentation/devicetree/bindings/phy/qcom,m31.yaml new file +2 -0
+        reg-names = "m31usb_phy_base",
+                "qscratch_base";

Align it.

Documentation/devicetree/bindings/phy/qcom,m31.yaml line 68

Quoted 5 lines
Documentation/devicetree/bindings/phy/qcom,m31.yaml new file +5 -0
+        phy_type = "utmi";
+        resets = <&gcc GCC_QUSB2_0_PHY_BCR>;
+        reset-names = "usb2_phy_reset";
+
+        status = "ok";

Drop.

Documentation/devicetree/bindings/phy/qcom,m31.yaml line 69

Quoted 1 line
Documentation/devicetree/bindings/phy/qcom,m31.yaml new file +1 -0
+    };

Best regards,
Krzysztof

#2 lore raw

Re: [PATCH 1/9] dt-bindings: usb: dwc3: Add IPQ5332 compatible

In reply to Varadarajan Narayanan
Quoted 1 line · Varadarajan Narayanan

Document the IPQ5332 dwc3 compatible

Full stop.

Quoted 19 lines
---
 Documentation/devicetree/bindings/usb/qcom,dwc3.yaml | 2 ++
 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/usb/qcom,dwc3.yaml +1 -0
index ae24dac..9c3d6f4 100644
@@ -14,6 +14,7 @@ properties:
     items:
       - enum:
           - qcom,ipq4019-dwc3
+          - qcom,ipq5332-dwc3
           - qcom,ipq6018-dwc3
           - qcom,ipq8064-dwc3
           - qcom,ipq8074-dwc3

Documentation/devicetree/bindings/usb/qcom,dwc3.yaml allOf: · line 252

Quoted 6 lines
Documentation/devicetree/bindings/usb/qcom,dwc3.yaml +1 -0
@@ -246,6 +247,7 @@ allOf:
         compatible:
           contains:
             enum:
+              - qcom,ipq5332-dwc3
               - qcom,msm8994-dwc3
               - qcom,qcs404-dwc3

What about interrupts?

Best regards,
Krzysztof

Signature · 3 lines
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#33 lore raw

Re: [PATCH 7/9] arm64: dts: qcom: ipq5332: Add USB related nodes

In reply to Varadarajan Narayanan
Quoted 12 lines · Varadarajan Narayanan

Add USB phy and controller nodes

---
 arch/arm64/boot/dts/qcom/ipq5332.dtsi | 55 +++++++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)
arch/arm64/boot/dts/qcom/ipq5332.dtsi +0 -0
index c2d6cc65..3183357 100644

arch/arm64/boot/dts/qcom/ipq5332.dtsi line 387

Quoted 5 lines
arch/arm64/boot/dts/qcom/ipq5332.dtsi +2 -0
@@ -383,6 +383,61 @@
 				status = "disabled";
 			};
 		};
+
+		usb_0_m31phy: hs_m31phy@7b000 {

Node names should be generic. See also explanation and list of examples in DT specification:
https://devicetree-specification.readthedocs.io/en/latest/chapter2-devicetree-basics.html#generic-names-recommendation

arch/arm64/boot/dts/qcom/ipq5332.dtsi line 390

Quoted 3 lines
arch/arm64/boot/dts/qcom/ipq5332.dtsi +3 -0
+			compatible = "qcom,ipq5332-m31-usb-hsphy";
+			reg = <0x0007b000 0x12C>,
+			      <0x08af8800 0x400>;

Lowercase hex only.

arch/arm64/boot/dts/qcom/ipq5332.dtsi line 398

Quoted 8 lines
arch/arm64/boot/dts/qcom/ipq5332.dtsi +8 -0
+			reg-names = "m31usb_phy_base",
+				    "qscratch_base";
+			phy_type= "utmi";
+
+			resets = <&gcc GCC_QUSB2_0_PHY_BCR>;
+			reset-names = "usb2_phy_reset";
+
+			status = "okay";

It's by default. Drop.

arch/arm64/boot/dts/qcom/ipq5332.dtsi line 401

Quoted 3 lines
arch/arm64/boot/dts/qcom/ipq5332.dtsi +3 -0
+		};
+
+		usb2: usb2@8a00000 {

It does not look like you tested the DTS against bindings. Please run make dtbs_check (see Documentation/devicetree/bindings/writing-schema.rst for instructions).

Node names should be generic. See also explanation and list of examples in DT specification:
https://devicetree-specification.readthedocs.io/en/latest/chapter2-devicetree-basics.html#generic-names-recommendation

arch/arm64/boot/dts/qcom/ipq5332.dtsi line 407

Quoted 6 lines
arch/arm64/boot/dts/qcom/ipq5332.dtsi +6 -0
+			compatible = "qcom,ipq5332-dwc3", "qcom,dwc3";
+			#address-cells = <1>;
+			#size-cells = <1>;
+			ranges;
+
+			reg = <0x08af8800 0x100>;

reg is always after compatible. Ranges is third. Then you will spot that address is wrong.

arch/arm64/boot/dts/qcom/ipq5332.dtsi line 412

Quoted 5 lines
arch/arm64/boot/dts/qcom/ipq5332.dtsi +5 -0
+
+			clocks = <&gcc GCC_USB0_MASTER_CLK>,
+				<&gcc GCC_SNOC_USB_CLK>,
+				<&gcc GCC_USB0_SLEEP_CLK>,
+				<&gcc GCC_USB0_MOCK_UTMI_CLK>;

Fix alignment.

arch/arm64/boot/dts/qcom/ipq5332.dtsi line 417

Quoted 5 lines
arch/arm64/boot/dts/qcom/ipq5332.dtsi +5 -0
+
+			clock-names = "core",
+				"iface",
+				"sleep",
+				"mock_utmi";

Fix alignment.

arch/arm64/boot/dts/qcom/ipq5332.dtsi line 421

Quoted 4 lines
arch/arm64/boot/dts/qcom/ipq5332.dtsi +4 -0
+
+			interrupts-extended = <&intc GIC_SPI 134 IRQ_TYPE_LEVEL_HIGH>;
+			interrupt-names = "pwr_event";
+

Best regards,
Krzysztof

Signature · 3 lines
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#37 lore raw

Re: [PATCH 9/9] arm64: defconfig: Enable QCOM M31 USB phy driver

In reply to Varadarajan Narayanan
Quoted 1 line · Varadarajan Narayanan

Enable QCOM M31 USB phy driver present in IPQ5332

What is "QCOM"? If acronym, extend. IPQ5332 - provide full name, so "Qualcomm IPQ....".

Best regards,
Krzysztof

Signature · 3 lines
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#23 lore raw

Re: [PATCH 5/9] phy: qcom-m31: Introduce qcom,m31 USB phy

In reply to Dmitry Baryshkov
Quoted 7 lines · Dmitry Baryshkov
Quoted 3 lines · Varadarajan Narayanan

Introduce CONFIG_PHY_QCOM_M31_USB for including the M31 phy driver

Is there any reason to keep Kconfig, Makefile and driver in different commits?

KPI? Yearly objectives/goals?

Best regards,
Krzysztof

Signature · 3 lines
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#3 lore raw

Re: [PATCH 1/9] dt-bindings: usb: dwc3: Add IPQ5332 compatible

In reply to Krzysztof Kozlowski
Quoted 4 lines · Krzysztof Kozlowski
Quoted 1 line · Varadarajan Narayanan

Document the IPQ5332 dwc3 compatible

Full stop.

Ok.

Quoted 18 lines
Quoted 18 lines
---
 Documentation/devicetree/bindings/usb/qcom,dwc3.yaml | 2 ++
 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/usb/qcom,dwc3.yaml +1 -0
index ae24dac..9c3d6f4 100644
@@ -14,6 +14,7 @@ properties:
     items:
       - enum:
           - qcom,ipq4019-dwc3
+          - qcom,ipq5332-dwc3
           - qcom,ipq6018-dwc3
           - qcom,ipq8064-dwc3
           - qcom,ipq8074-dwc3
@@ -246,6 +247,7 @@ allOf:
Quoted 8 lines

Documentation/devicetree/bindings/usb/qcom,dwc3.yaml allOf: · line 252

Quoted 6 lines
Documentation/devicetree/bindings/usb/qcom,dwc3.yaml +1 -0
         compatible:
           contains:
             enum:
+              - qcom,ipq5332-dwc3
               - qcom,msm8994-dwc3
               - qcom,qcs404-dwc3

What about interrupts?

Will fix and post next version.

Thanks
Varada

Signature · 3 lines
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#7 lore raw

Re: [PATCH 2/9] dt-bindings: phy: qcom,m31: Document qcom,m31 USB phy

In reply to Krzysztof Kozlowski
Quoted 4 lines · Krzysztof Kozlowski
Quoted 1 line · Varadarajan Narayanan

Document the M31 USB2 phy present in IPQ5332

Full stop.

Ok.

Quoted 7 lines
Quoted 7 lines
---
 .../devicetree/bindings/phy/qcom,m31.yaml          | 69 ++++++++++++++++++++++
 1 file changed, 69 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/qcom,m31.yaml
Quoted 10 lines

Documentation/devicetree/bindings/phy/qcom,m31.yaml line 2

Quoted 8 lines
Documentation/devicetree/bindings/phy/qcom,m31.yaml new file +2 -0
new file mode 100644
index 0000000..8ad4ba4
@@ -0,0 +1,69 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+

Drop stray blank lines.

Ok.

Quoted 8 lines

Documentation/devicetree/bindings/phy/qcom,m31.yaml line 8

Quoted 6 lines
Documentation/devicetree/bindings/phy/qcom,m31.yaml new file +6 -0
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/phy/qcom,m31.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Qualcomm M31 USB PHY

What is M31?

M31 is an external IP integrated into IPQ5332 SoC.

Quoted 9 lines

Documentation/devicetree/bindings/phy/qcom,m31.yaml line 15

Quoted 7 lines
Documentation/devicetree/bindings/phy/qcom,m31.yaml new file +7 -0
+
+maintainers:
+  - Sricharan Ramabadhran <[email protected]>
+  - Varadarajan Narayanan <[email protected]>
+
+description:
+  This file contains documentation for the USB M31 PHY found in Qualcomm

Drop redundant parts ("This file contains documentation for the").

Ok.

Quoted 7 lines

Documentation/devicetree/bindings/phy/qcom,m31.yaml line 20

Quoted 5 lines
Documentation/devicetree/bindings/phy/qcom,m31.yaml new file +5 -0
+  IPQ5018, IPQ5332 SoCs.
+
+properties:
+  compatible:
+    oneOf:

That's not oneOf.

Ok.

Quoted 3 lines

Documentation/devicetree/bindings/phy/qcom,m31.yaml line 21

Quoted 1 line
Documentation/devicetree/bindings/phy/qcom,m31.yaml new file +1 -0
+      - items:

No items.

Ok.

Quoted 11 lines

Documentation/devicetree/bindings/phy/qcom,m31.yaml line 23

Quoted 2 lines
Documentation/devicetree/bindings/phy/qcom,m31.yaml new file +2 -0
+          - enum:
+              - qcom,m31-usb-hsphy

I am confused what's this. If m31 is coming from some IP block provider, then you are using wrong vendor prefix.
https://www.m31tech.com/download_file/M31_USB.pdf

Documentation/devicetree/bindings/phy/qcom,m31.yaml line 24

Quoted 1 line
Documentation/devicetree/bindings/phy/qcom,m31.yaml new file +1 -0
+              - qcom,ipq5332-m31-usb-hsphy

This confuses me even more. IPQ m31?

Will change this to m31,usb-hsphy and m31,ipq5332-usb-hsphy respectively. Will that be acceptable?

Quoted 6 lines

Documentation/devicetree/bindings/phy/qcom,m31.yaml line 28

Quoted 4 lines
Documentation/devicetree/bindings/phy/qcom,m31.yaml new file +4 -0
+
+  reg:
+    description:
+      Offset and length of the M31 PHY register set

Drop description, obvious.

Ok.

Quoted 8 lines

Documentation/devicetree/bindings/phy/qcom,m31.yaml line 34

Quoted 6 lines
Documentation/devicetree/bindings/phy/qcom,m31.yaml new file +6 -0
+    maxItems: 2
+
+  reg-names:
+    items:
+      - const: m31usb_phy_base
+      - const: qscratch_base

Drop "_base" from both.

Ok. Will drop qscratch_base. This is in the controller space. Should not come here.

Quoted 9 lines

Documentation/devicetree/bindings/phy/qcom,m31.yaml line 41

Quoted 7 lines
Documentation/devicetree/bindings/phy/qcom,m31.yaml new file +7 -0
+
+  phy_type:
+    oneOf:
+      - items:
+          - enum:
+              - utmi
+              - ulpi

This does not belong to phy, but to USB node.

This is used by the driver to set a bit during phy init. Hence have it as a replication of the USB node's entry. If this is not permissible, is there some way to get this from the USB node, or any other alternative mechanism?

Quoted 7 lines

Documentation/devicetree/bindings/phy/qcom,m31.yaml line 46

Quoted 5 lines
Documentation/devicetree/bindings/phy/qcom,m31.yaml new file +5 -0
+
+  resets:
+    maxItems: 1
+    description:
+      List of phandles and reset pairs, one for each entry in reset-names.

Drop useless description.

Ok.

Quoted 7 lines

Documentation/devicetree/bindings/phy/qcom,m31.yaml line 51

Quoted 5 lines
Documentation/devicetree/bindings/phy/qcom,m31.yaml new file +5 -0
+
+  reset-names:
+    items:
+      - const:
+          usb2_phy_reset

Drop entire reset-names.

Ok.

Quoted 12 lines

Documentation/devicetree/bindings/phy/qcom,m31.yaml line 58

Quoted 7 lines
Documentation/devicetree/bindings/phy/qcom,m31.yaml new file +7 -0
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/clock/qcom,ipq5332-gcc.h>
+    hs_m31phy_0: hs_m31phy@5b00 {

Node names should be generic. See also explanation and list of examples in DT specification:
https://devicetree-specification.readthedocs.io/en/latest/chapter2-devicetree-basics.html#generic-names-recommendation

Quoted 1 line

Also, no underscores in node names.

Will change this as usbphy0:hs_m31phy@7b000

Quoted 4 lines

Documentation/devicetree/bindings/phy/qcom,m31.yaml line 60

Quoted 2 lines
Documentation/devicetree/bindings/phy/qcom,m31.yaml new file +2 -0
+        compatible = "qcom,m31-usb-hsphy";
+        reg = <0x5b000 0x3000>,

This is not what your unit address is saying.

Will change to 0x0007b000.

Quoted 3 lines

Documentation/devicetree/bindings/phy/qcom,m31.yaml line 61

Quoted 1 line
Documentation/devicetree/bindings/phy/qcom,m31.yaml new file +1 -0
+            <0x08af8800 0x400>;

Align it.

Will drop this. This is in the controller space.

Quoted 4 lines

Documentation/devicetree/bindings/phy/qcom,m31.yaml line 63

Quoted 2 lines
Documentation/devicetree/bindings/phy/qcom,m31.yaml new file +2 -0
+        reg-names = "m31usb_phy_base",
+                "qscratch_base";

Align it.

Ok.

Quoted 7 lines

Documentation/devicetree/bindings/phy/qcom,m31.yaml line 68

Quoted 5 lines
Documentation/devicetree/bindings/phy/qcom,m31.yaml new file +5 -0
+        phy_type = "utmi";
+        resets = <&gcc GCC_QUSB2_0_PHY_BCR>;
+        reset-names = "usb2_phy_reset";
+
+        status = "ok";

Drop.

Ok. Hopefully will get an alternative for the phy_type.

Thanks
Varada

Quoted 5 lines

Documentation/devicetree/bindings/phy/qcom,m31.yaml line 69

Quoted 1 line
Documentation/devicetree/bindings/phy/qcom,m31.yaml new file +1 -0
+    };

Best regards,
Krzysztof

Signature · 3 lines
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#16 lore raw

Re: [PATCH 3/9] phy: qcom-m31: Introduce qcom,m31 USB phy driver

In reply to Konrad Dybcio
Quoted 27 lines · Konrad Dybcio
Quoted 24 lines · Varadarajan Narayanan

Add the M31 USB2 phy driver

---
 drivers/phy/qualcomm/phy-qcom-m31.c | 360 ++++++++++++++++++++++++++++++++++++
 1 file changed, 360 insertions(+)
 create mode 100644 drivers/phy/qualcomm/phy-qcom-m31.c
drivers/phy/qualcomm/phy-qcom-m31.c new file +10 -0
new file mode 100644
index 0000000..d29a91e
@@ -0,0 +1,360 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2014-2016, 2020, The Linux Foundation. All rights reserved.
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/err.h>
+#include <linux/slab.h>
+#include <linux/clk.h>
Quoted 8 lines

drivers/phy/qualcomm/phy-qcom-m31.c line 17

Quoted 7 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +7 -0
+#include <linux/delay.h>
+#include <linux/io.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/usb/phy.h>
+#include <linux/reset.h>
+#include <linux/of_device.h>

Please sort these

Ok.

Quoted 24 lines
Quoted 24 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +24 -0
+
+enum clk_reset_action {
+	CLK_RESET_DEASSERT	= 0,
+	CLK_RESET_ASSERT	= 1
+};
+
+#define USB2PHY_PORT_POWERDOWN		0xA4
+#define POWER_UP			BIT(0)
+#define POWER_DOWN			0
+
+#define USB2PHY_PORT_UTMI_CTRL1	0x40
+
+#define USB2PHY_PORT_UTMI_CTRL2	0x44
+#define UTMI_ULPI_SEL			BIT(7)
+#define UTMI_TEST_MUX_SEL		BIT(6)
+
+#define HS_PHY_CTRL_REG			0x10
+#define UTMI_OTG_VBUS_VALID             BIT(20)
+#define SW_SESSVLD_SEL                  BIT(28)
+
+#define USB_PHY_CFG0			0x94
+#define USB_PHY_UTMI_CTRL5		0x50
+#define USB_PHY_FSEL_SEL		0xB8
+#define USB_PHY_HS_PHY_CTRL_COMMON0	0x54
Quoted 8 lines

drivers/phy/qualcomm/phy-qcom-m31.c line 48

Quoted 7 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +7 -0
+#define USB_PHY_REFCLK_CTRL		0xA0
+#define USB_PHY_HS_PHY_CTRL2		0x64
+#define USB_PHY_UTMI_CTRL0		0x3c
+#define USB2PHY_USB_PHY_M31_XCFGI_1	0xBC
+#define USB2PHY_USB_PHY_M31_XCFGI_4	0xC8
+#define USB2PHY_USB_PHY_M31_XCFGI_5	0xCC
+#define USB2PHY_USB_PHY_M31_XCFGI_11	0xE4

Could you sort them address-wise?

Ok.

Quoted 9 lines

drivers/phy/qualcomm/phy-qcom-m31.c line 55

Quoted 7 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +7 -0
+
+#define USB2_0_TX_ENABLE		BIT(2)
+#define HSTX_SLEW_RATE_565PS		3
+#define PLL_CHARGING_PUMP_CURRENT_35UA	(3 << 3)
+#define ODT_VALUE_38_02_OHM		(3 << 6)
+#define ODT_VALUE_45_02_OHM		BIT(2)
+#define HSTX_PRE_EMPHASIS_LEVEL_0_55MA	(1)

Weird mix of values, bits, bitfields.. perhaps BIT(n) and GENMASK() (+ FIELD_PREP) would be more suitable?

Ok.

Quoted 4 lines

drivers/phy/qualcomm/phy-qcom-m31.c line 58

Quoted 3 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +3 -0
+
+#define UTMI_PHY_OVERRIDE_EN		BIT(1)
+#define POR_EN				BIT(1)

Please associate these with their registers, like

Ok.

Quoted 16 lines

#define FOO_REG 0xf00
#define POR_EN BIT(1)

drivers/phy/qualcomm/phy-qcom-m31.c line 70

Quoted 12 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +12 -0
+#define FREQ_SEL			BIT(0)
+#define COMMONONN			BIT(7)
+#define FSEL				BIT(4)
+#define RETENABLEN			BIT(3)
+#define USB2_SUSPEND_N_SEL		BIT(3)
+#define USB2_SUSPEND_N			BIT(2)
+#define USB2_UTMI_CLK_EN		BIT(1)
+#define CLKCORE				BIT(1)
+#define ATERESET			~BIT(0)
+#define FREQ_24MHZ			(5 << 4)
+#define XCFG_COARSE_TUNE_NUM		(2 << 0)
+#define XCFG_FINE_TUNE_NUM		(1 << 3)

same comment

Ok.

Quoted 18 lines

drivers/phy/qualcomm/phy-qcom-m31.c line 73

Quoted 3 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +3 -0
+
+static void m31usb_write_readback(void *base, u32 offset,
+					const u32 mask, u32 val);

We don't need this forward-definition, just move the function up.

Quoted 13 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +13 -0
+
+struct m31usb_phy {
+	struct usb_phy		phy;
+	void __iomem		*base;
+	void __iomem		*qscratch_base;
+
+	struct reset_control	*phy_reset;
+
+	bool			cable_connected;
+	bool			suspended;
+	bool			ulpi_mode;
+};
+
Quoted 8 lines

drivers/phy/qualcomm/phy-qcom-m31.c line 93

Quoted 7 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +7 -0
+static void m31usb_reset(struct m31usb_phy *qphy, u32 action)
+{
+	if (action == CLK_RESET_ASSERT)
+		reset_control_assert(qphy->phy_reset);
+	else
+		reset_control_deassert(qphy->phy_reset);
+	wmb(); /* ensure data is written to hw register */

Please move the comment above the call.

This is used only once. Hence, will move it to the calling location itself.

Quoted 61 lines

drivers/phy/qualcomm/phy-qcom-m31.c line 99

Quoted 6 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +6 -0
+}
+
+static void m31usb_phy_enable_clock(struct m31usb_phy *qphy)
+{
+	/* Enable override ctrl */
+	writel(UTMI_PHY_OVERRIDE_EN, qphy->base + USB_PHY_CFG0);

Some of the comments are missing a space before '*/'

Also, please consider adding some newlines to logically split the actions.

Quoted 16 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +16 -0
+	/* Enable POR*/
+	writel(POR_EN, qphy->base + USB_PHY_UTMI_CTRL5);
+	udelay(15);
+	/* Configure frequency select value*/
+	writel(FREQ_SEL, qphy->base + USB_PHY_FSEL_SEL);
+	/* Configure refclk frequency */
+	writel(COMMONONN | FSEL | RETENABLEN,
+		qphy->base + USB_PHY_HS_PHY_CTRL_COMMON0);
+	/* select refclk source */
+	writel(CLKCORE, qphy->base + USB_PHY_REFCLK_CTRL);
+	/* select ATERESET*/
+	writel(POR_EN & ATERESET, qphy->base + USB_PHY_UTMI_CTRL5);
+	writel(USB2_SUSPEND_N_SEL | USB2_SUSPEND_N | USB2_UTMI_CLK_EN,
+		qphy->base + USB_PHY_HS_PHY_CTRL2);
+	writel(0x0, qphy->base + USB_PHY_UTMI_CTRL5);
+	writel(USB2_SUSPEND_N | USB2_UTMI_CLK_EN,

drivers/phy/qualcomm/phy-qcom-m31.c line 125

Quoted 10 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +10 -0
+		qphy->base + USB_PHY_HS_PHY_CTRL2);
+	/* Disable override ctrl */
+	writel(0x0, qphy->base + USB_PHY_CFG0);
+}
+
+static void ipq5332_m31usb_phy_enable_clock(struct m31usb_phy *qphy)
+{
+	/* Enable override ctrl */
+	writel(UTMI_PHY_OVERRIDE_EN, qphy->base + USB_PHY_CFG0);
+	/* Enable POR*/

ditto

Quoted 8 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +8 -0
+	writel(POR_EN, qphy->base + USB_PHY_UTMI_CTRL5);
+	udelay(15);
+	/* Configure frequency select value*/
+	writel(FREQ_SEL, qphy->base + USB_PHY_FSEL_SEL);
+	/* Configure refclk frequency */
+	writel(COMMONONN | FREQ_24MHZ | RETENABLEN,
+		qphy->base + USB_PHY_HS_PHY_CTRL_COMMON0);
+	/* select ATERESET*/

drivers/phy/qualcomm/phy-qcom-m31.c line 143

Quoted 10 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +10 -0
+	writel(POR_EN & ATERESET, qphy->base + USB_PHY_UTMI_CTRL5);
+	writel(USB2_SUSPEND_N_SEL | USB2_SUSPEND_N | USB2_UTMI_CLK_EN,
+		qphy->base + USB_PHY_HS_PHY_CTRL2);
+	writel(XCFG_COARSE_TUNE_NUM  | XCFG_FINE_TUNE_NUM,
+				qphy->base + USB2PHY_USB_PHY_M31_XCFGI_11);
+	/* Adjust HSTX slew rate to 565 ps*/
+	/* Adjust PLL lock Time counter for release clock to 35uA */
+	/* Adjust Manual control ODT value to 38.02 Ohm */
+	writel(HSTX_SLEW_RATE_565PS | PLL_CHARGING_PUMP_CURRENT_35UA |
+		ODT_VALUE_38_02_OHM, qphy->base + USB2PHY_USB_PHY_M31_XCFGI_4);

These functions seem very similar, with the main difference being that IPQ5332 adds some more writes at the end. Perhaps some commonizing could be done?

Quoted 14 lines
Quoted 4 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +4 -0
+	/*
+	 * Enable to always turn on USB 2.0 TX driver
+	 * when system is in USB 2.0 HS mode
+	 */

drivers/phy/qualcomm/phy-qcom-m31.c line 157

Quoted 10 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +10 -0
+	writel(USB2_0_TX_ENABLE, qphy->base + USB2PHY_USB_PHY_M31_XCFGI_1);
+	/* Adjust Manual control ODT value to 45.02 Ohm */
+	/* Adjust HSTX Pre-emphasis level to 0.55mA */
+	writel(ODT_VALUE_45_02_OHM | HSTX_PRE_EMPHASIS_LEVEL_0_55MA,
+		qphy->base + USB2PHY_USB_PHY_M31_XCFGI_5);
+	udelay(4);
+	writel(0x0, qphy->base + USB_PHY_UTMI_CTRL5);
+	writel(USB2_SUSPEND_N | USB2_UTMI_CLK_EN,
+		qphy->base + USB_PHY_HS_PHY_CTRL2);
+}

Will change the above to table based register init, based on compatible/data.

Quoted 11 lines

drivers/phy/qualcomm/phy-qcom-m31.c line 165

Quoted 8 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +8 -0
+
+static int m31usb_phy_init(struct usb_phy *phy)
+{
+	struct m31usb_phy *qphy = container_of(phy, struct m31usb_phy, phy);
+
+	/* Perform phy reset */
+	m31usb_reset(qphy, CLK_RESET_ASSERT);
+	usleep_range(1, 5);

https://www.kernel.org/doc/Documentation/timers/timers-howto.txt

this may not work as intended

Will change it to udelay(5).

Quoted 5 lines
Quoted 5 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +5 -0
+	m31usb_reset(qphy, CLK_RESET_DEASSERT);
+
+	/* configure for ULPI mode if requested */
+	if (qphy->ulpi_mode)
+		writel_relaxed(0x0, qphy->base + USB2PHY_PORT_UTMI_CTRL2);
Quoted 8 lines

drivers/phy/qualcomm/phy-qcom-m31.c line 176

Quoted 6 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +6 -0
+
+	/* Enable the PHY */
+	writel_relaxed(POWER_UP, qphy->base + USB2PHY_PORT_POWERDOWN);
+
+	/* Make sure above write completed */
+	wmb();

As you're calling wmb in the reset func, dropping _relaxed from the ULPI and PORT_POWERDOWN writes should work the same

Ok.

Quoted 8 lines

drivers/phy/qualcomm/phy-qcom-m31.c line 183

Quoted 7 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +7 -0
+
+	/* Turn on phy ref clock*/
+	if (of_device_is_compatible(phy->dev->of_node,
+					"qcom,ipq5332-m31-usb-hsphy"))
+		ipq5332_m31usb_phy_enable_clock(qphy);
+	else
+		m31usb_phy_enable_clock(qphy);

This should be done using OF match data.

Ok.

Quoted 82 lines
Quoted 13 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +13 -0
+
+	/* Set OTG VBUS Valid from HSPHY to controller */
+	m31usb_write_readback(qphy->qscratch_base, HS_PHY_CTRL_REG,
+				UTMI_OTG_VBUS_VALID, UTMI_OTG_VBUS_VALID);
+	/* Indicate value is driven by UTMI_OTG_VBUS_VALID bit */
+	m31usb_write_readback(qphy->qscratch_base, HS_PHY_CTRL_REG,
+				SW_SESSVLD_SEL, SW_SESSVLD_SEL);
+
+	return 0;
+}
+
+static void m31usb_phy_shutdown(struct usb_phy *phy)
+{

drivers/phy/qualcomm/phy-qcom-m31.c line 206

Quoted 10 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +10 -0
+	struct m31usb_phy *qphy = container_of(phy, struct m31usb_phy, phy);
+
+	/* Disable the PHY */
+	writel_relaxed(POWER_DOWN, qphy->base + USB2PHY_PORT_POWERDOWN);
+	/* Make sure above write completed */
+	wmb();
+}
+
+static void m31usb_write_readback(void *base, u32 offset,
+					const u32 mask, u32 val)

The indentation here makes const u32.. misaligned.

Quoted 17 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +17 -0
+{
+	u32 write_val, tmp = readl_relaxed(base + offset);
+
+	tmp &= ~mask; /* retain other bits */
+	write_val = tmp | val;
+
+	writel_relaxed(write_val, base + offset);
+	/* Make sure above write completed */
+	wmb();
+
+	/* Read back to see if val was written */
+	tmp = readl_relaxed(base + offset);
+	tmp &= mask; /* clear other bits */
+
+	if (tmp != val)
+		pr_err("%s: write: %x to QSCRATCH: %x FAILED\n",
+			__func__, val, offset);

drivers/phy/qualcomm/phy-qcom-m31.c line 233

Quoted 10 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +10 -0
+}
+
+static int m31usb_phy_notify_connect(struct usb_phy *phy,
+					enum usb_device_speed speed)
+{
+	struct m31usb_phy *qphy = container_of(phy, struct m31usb_phy, phy);
+
+	qphy->cable_connected = true;
+
+	dev_dbg(phy->dev, " cable_connected=%d\n", qphy->cable_connected);

spurious space at the beginning of the string

drivers/phy/qualcomm/phy-qcom-m31.c line 238

Quoted 5 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +5 -0
+
+	/* Set OTG VBUS Valid from HSPHY to controller */
+	m31usb_write_readback(qphy->qscratch_base, HS_PHY_CTRL_REG,
+				UTMI_OTG_VBUS_VALID,
+				UTMI_OTG_VBUS_VALID);

Please align the lines with the previous opening bracket

Quoted 21 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +21 -0
+
+	/* Indicate value is driven by UTMI_OTG_VBUS_VALID bit */
+	m31usb_write_readback(qphy->qscratch_base, HS_PHY_CTRL_REG,
+				SW_SESSVLD_SEL, SW_SESSVLD_SEL);
+
+	dev_dbg(phy->dev, "M31USB2 phy connect notification\n");
+	return 0;
+}
+
+static int m31usb_phy_notify_disconnect(struct usb_phy *phy,
+					enum usb_device_speed speed)
+{
+	struct m31usb_phy *qphy = container_of(phy, struct m31usb_phy, phy);
+
+	qphy->cable_connected = false;
+
+	dev_dbg(phy->dev, " cable_connected=%d\n", qphy->cable_connected);
+
+	/* Set OTG VBUS Valid from HSPHY to controller */
+	m31usb_write_readback(qphy->qscratch_base, HS_PHY_CTRL_REG,
+				UTMI_OTG_VBUS_VALID, 0);
Quoted 8 lines

drivers/phy/qualcomm/phy-qcom-m31.c line 267

Quoted 8 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +8 -0
+
+	/* Indicate value is driven by UTMI_OTG_VBUS_VALID bit */
+	m31usb_write_readback(qphy->qscratch_base, HS_PHY_CTRL_REG,
+				SW_SESSVLD_SEL, 0);
+
+	dev_dbg(phy->dev, "M31USB2 phy disconnect notification\n");
+	return 0;
+}

Will remove these functions. They are accessing 'qscratch' area that is part of the controller space. It doesn't belong in this driver.

Quoted 8 lines

drivers/phy/qualcomm/phy-qcom-m31.c line 275

Quoted 7 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +7 -0
+static int m31usb_phy_probe(struct platform_device *pdev)
+{
+	struct m31usb_phy *qphy;
+	struct device *dev = &pdev->dev;
+	struct resource *res;
+	int ret;
+	const char *phy_type;

Please sort these in a reverse-Christmas-tree order.

ok.

Quoted 11 lines

drivers/phy/qualcomm/phy-qcom-m31.c line 285

Quoted 10 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +10 -0
+
+	qphy = devm_kzalloc(dev, sizeof(*qphy), GFP_KERNEL);
+	if (!qphy)
+		return -ENOMEM;
+
+	qphy->phy.dev = dev;
+
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
+							"m31usb_phy_base");
+	qphy->base = devm_ioremap_resource(dev, res);

devm_platform_get_and_ioremap_resource?

ok.

Quoted 8 lines

drivers/phy/qualcomm/phy-qcom-m31.c line 291

Quoted 6 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +6 -0
+	if (IS_ERR(qphy->base))
+		return PTR_ERR(qphy->base);
+
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
+							"qscratch_base");
+	if (res) {

Do we expect platforms without this register space?

Quoted 7 lines

drivers/phy/qualcomm/phy-qcom-m31.c line 298

Quoted 7 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +7 -0
+		qphy->qscratch_base = devm_ioremap(dev, res->start,
+							resource_size(res));
+		if (IS_ERR(qphy->qscratch_base)) {
+			dev_dbg(dev, "couldn't ioremap qscratch_base\n");
+			qphy->qscratch_base = NULL;
+		}
+	}

Will remove this qscratch code.

Quoted 2 lines

drivers/phy/qualcomm/phy-qcom-m31.c line 300

Quoted 1 line
drivers/phy/qualcomm/phy-qcom-m31.c new file +1 -0
+	qphy->phy_reset = devm_reset_control_get(dev, "usb2_phy_reset");

not _exclusive?

Ok.

Quoted 6 lines

drivers/phy/qualcomm/phy-qcom-m31.c line 305

Quoted 5 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +5 -0
+	if (IS_ERR(qphy->phy_reset))
+		return PTR_ERR(qphy->phy_reset);
+
+	qphy->ulpi_mode = false;
+	ret = of_property_read_string(dev->of_node, "phy_type", &phy_type);

of_usb_get_phy_mode?

Ok.

Quoted 20 lines
Quoted 20 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +20 -0
+
+	if (!ret) {
+		if (!strcasecmp(phy_type, "ulpi"))
+			qphy->ulpi_mode = true;
+	} else {
+		dev_err(dev, "error reading phy_type property\n");
+		return ret;
+	}
+
+	platform_set_drvdata(pdev, qphy);
+
+	qphy->phy.label			= "qcom-m31usb-phy";
+	qphy->phy.init			= m31usb_phy_init;
+	qphy->phy.shutdown		= m31usb_phy_shutdown;
+	qphy->phy.type			= USB_PHY_TYPE_USB2;
+
+	if (qphy->qscratch_base) {
+		qphy->phy.notify_connect        = m31usb_phy_notify_connect;
+		qphy->phy.notify_disconnect     = m31usb_phy_notify_disconnect;
+	}
Quoted 8 lines

drivers/phy/qualcomm/phy-qcom-m31.c line 332

Quoted 7 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +7 -0
+
+	ret = usb_add_phy_dev(&qphy->phy);
+
+	return ret;
+}
+
+static int m31usb_phy_remove(struct platform_device *pdev)

Please make this return void and pass it to .remove_new

Ok.

Quoted 14 lines
Quoted 14 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +14 -0
+{
+	struct m31usb_phy *qphy = platform_get_drvdata(pdev);
+
+	usb_remove_phy(&qphy->phy);
+
+	return 0;
+}
+
+static const struct of_device_id m31usb_phy_id_table[] = {
+	{ .compatible = "qcom,m31-usb-hsphy",},
+	{ .compatible = "qcom,ipq5332-m31-usb-hsphy",},
+	{ },
+};
+MODULE_DEVICE_TABLE(of, m31usb_phy_id_table);
Quoted 8 lines

drivers/phy/qualcomm/phy-qcom-m31.c line 353

Quoted 7 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +7 -0
+
+static struct platform_driver m31usb_phy_driver = {
+	.probe		= m31usb_phy_probe,
+	.remove		= m31usb_phy_remove,
+	.driver = {
+		.name	= "qcom-m31usb-phy",
+		.of_match_table = of_match_ptr(m31usb_phy_id_table),

of_match_ptr is unnecessary, this driver depends on OF.

Ok.

Thanks
Varada

Quoted 8 lines

Konrad

Quoted 7 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +7 -0
+	},
+};
+
+module_platform_driver(m31usb_phy_driver);
+
+MODULE_DESCRIPTION("USB2 Qualcomm M31 HSPHY driver");
+MODULE_LICENSE("GPL");
Signature · 3 lines
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#15 lore raw

Re: [PATCH 3/9] phy: qcom-m31: Introduce qcom,m31 USB phy driver

In reply to Dmitry Baryshkov
Quoted 70 lines · Dmitry Baryshkov

Two minor nits on top of the review:

Quoted 58 lines · Konrad Dybcio
Quoted 21 lines · Varadarajan Narayanan

Add the M31 USB2 phy driver

---
 drivers/phy/qualcomm/phy-qcom-m31.c | 360 ++++++++++++++++++++++++++++++++++++
 1 file changed, 360 insertions(+)
 create mode 100644 drivers/phy/qualcomm/phy-qcom-m31.c
drivers/phy/qualcomm/phy-qcom-m31.c new file +7 -0
new file mode 100644
index 0000000..d29a91e
@@ -0,0 +1,360 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2014-2016, 2020, The Linux Foundation. All rights reserved.
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>

drivers/phy/qualcomm/phy-qcom-m31.c line 17

Quoted 10 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +10 -0
+#include <linux/err.h>
+#include <linux/slab.h>
+#include <linux/clk.h>
+#include <linux/delay.h>
+#include <linux/io.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/usb/phy.h>
+#include <linux/reset.h>
+#include <linux/of_device.h>

Please sort these

Quoted 24 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +24 -0
+
+enum clk_reset_action {
+	CLK_RESET_DEASSERT	= 0,
+	CLK_RESET_ASSERT	= 1
+};
+
+#define USB2PHY_PORT_POWERDOWN		0xA4
+#define POWER_UP			BIT(0)
+#define POWER_DOWN			0
+
+#define USB2PHY_PORT_UTMI_CTRL1	0x40
+
+#define USB2PHY_PORT_UTMI_CTRL2	0x44
+#define UTMI_ULPI_SEL			BIT(7)
+#define UTMI_TEST_MUX_SEL		BIT(6)
+
+#define HS_PHY_CTRL_REG			0x10
+#define UTMI_OTG_VBUS_VALID             BIT(20)
+#define SW_SESSVLD_SEL                  BIT(28)
+
+#define USB_PHY_CFG0			0x94
+#define USB_PHY_UTMI_CTRL5		0x50
+#define USB_PHY_FSEL_SEL		0xB8
+#define USB_PHY_HS_PHY_CTRL_COMMON0	0x54
Quoted 8 lines

drivers/phy/qualcomm/phy-qcom-m31.c line 48

Quoted 7 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +7 -0
+#define USB_PHY_REFCLK_CTRL		0xA0
+#define USB_PHY_HS_PHY_CTRL2		0x64
+#define USB_PHY_UTMI_CTRL0		0x3c
+#define USB2PHY_USB_PHY_M31_XCFGI_1	0xBC
+#define USB2PHY_USB_PHY_M31_XCFGI_4	0xC8
+#define USB2PHY_USB_PHY_M31_XCFGI_5	0xCC
+#define USB2PHY_USB_PHY_M31_XCFGI_11	0xE4

Could you sort them address-wise?

Quoted 1 line

... and lowercase the hex values, please.

Ok.

Quoted 59 lines
Quoted 59 lines

drivers/phy/qualcomm/phy-qcom-m31.c line 55

Quoted 7 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +7 -0
+
+#define USB2_0_TX_ENABLE		BIT(2)
+#define HSTX_SLEW_RATE_565PS		3
+#define PLL_CHARGING_PUMP_CURRENT_35UA	(3 << 3)
+#define ODT_VALUE_38_02_OHM		(3 << 6)
+#define ODT_VALUE_45_02_OHM		BIT(2)
+#define HSTX_PRE_EMPHASIS_LEVEL_0_55MA	(1)

Weird mix of values, bits, bitfields.. perhaps BIT(n) and GENMASK() (+ FIELD_PREP) would be more suitable?

drivers/phy/qualcomm/phy-qcom-m31.c line 58

Quoted 3 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +3 -0
+
+#define UTMI_PHY_OVERRIDE_EN		BIT(1)
+#define POR_EN				BIT(1)

Please associate these with their registers, like

#define FOO_REG 0xf00
#define POR_EN BIT(1)

drivers/phy/qualcomm/phy-qcom-m31.c line 70

Quoted 12 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +12 -0
+#define FREQ_SEL			BIT(0)
+#define COMMONONN			BIT(7)
+#define FSEL				BIT(4)
+#define RETENABLEN			BIT(3)
+#define USB2_SUSPEND_N_SEL		BIT(3)
+#define USB2_SUSPEND_N			BIT(2)
+#define USB2_UTMI_CLK_EN		BIT(1)
+#define CLKCORE				BIT(1)
+#define ATERESET			~BIT(0)
+#define FREQ_24MHZ			(5 << 4)
+#define XCFG_COARSE_TUNE_NUM		(2 << 0)
+#define XCFG_FINE_TUNE_NUM		(1 << 3)

same comment

drivers/phy/qualcomm/phy-qcom-m31.c line 73

Quoted 3 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +3 -0
+
+static void m31usb_write_readback(void *base, u32 offset,
+					const u32 mask, u32 val);

We don't need this forward-definition, just move the function up.

Quoted 10 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +10 -0
+
+struct m31usb_phy {
+	struct usb_phy		phy;
+	void __iomem		*base;
+	void __iomem		*qscratch_base;
+
+	struct reset_control	*phy_reset;
+
+	bool			cable_connected;
+	bool			suspended;

drivers/phy/qualcomm/phy-qcom-m31.c line 93

Quoted 10 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +10 -0
+	bool			ulpi_mode;
+};
+
+static void m31usb_reset(struct m31usb_phy *qphy, u32 action)
+{
+	if (action == CLK_RESET_ASSERT)
+		reset_control_assert(qphy->phy_reset);
+	else
+		reset_control_deassert(qphy->phy_reset);
+	wmb(); /* ensure data is written to hw register */

Please move the comment above the call.

Quoted 7 lines
Quoted 1 line

drivers/phy/qualcomm/phy-qcom-m31.c line 94

Quoted 1 line
drivers/phy/qualcomm/phy-qcom-m31.c new file +1 -0
+}

Or even better just inline the function. I was never a fan of such multiplexers.

Also does wmb() make sense here? Doesn't regmap (which is used by reset controller) remove the need for it?

Will inline and remove the wmb.

Thanks
Varada

Quoted 15 lines
Quoted 9 lines

drivers/phy/qualcomm/phy-qcom-m31.c line 99

Quoted 5 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +5 -0
+
+static void m31usb_phy_enable_clock(struct m31usb_phy *qphy)
+{
+	/* Enable override ctrl */
+	writel(UTMI_PHY_OVERRIDE_EN, qphy->base + USB_PHY_CFG0);

Some of the comments are missing a space before '*/'

Also, please consider adding some newlines to logically split the actions.

--
With best wishes
Dmitry

Signature · 3 lines
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#20 lore raw

Re: [PATCH 4/9] clk: qcom: ipq5332: Fix USB related clock defines

In reply to Dmitry Baryshkov
Quoted 62 lines · Dmitry Baryshkov
Quoted 13 lines · Varadarajan Narayanan

Fix the USB related clock defines and add details
referenced by them

---
 drivers/clk/qcom/gcc-ipq5332.c | 34 +++++++++++++++++++++++-----------
 1 file changed, 23 insertions(+), 11 deletions(-)
drivers/clk/qcom/gcc-ipq5332.c +0 -0
index a75ab88..2b58558 100644

drivers/clk/qcom/gcc-ipq5332.c static const struct freq_tbl ftbl_gcc_adss_pwm_clk_src[] = { · line 355

Quoted 5 lines
drivers/clk/qcom/gcc-ipq5332.c +3 -0
@@ -351,6 +351,16 @@ static const struct freq_tbl ftbl_gcc_adss_pwm_clk_src[] = {
 	{ }
 };
+static const struct clk_parent_data gcc_usb3phy_0_cc_pipe_clk_xo[] = {
+	{ .fw_name = "usb3phy_0_cc_pipe_clk" },
+	{ .fw_name = "xo" },

gcc-ipq5332 uses DT indices, please don't mix that with .fw_name.

Quoted 24 lines
drivers/clk/qcom/gcc-ipq5332.c +11 -5
+};
+
+static const struct parent_map gcc_usb3phy_0_cc_pipe_clk_xo_map[] = {
+	{ P_USB3PHY_0_PIPE, 0 },
+	{ P_XO, 2 },
+};
+
 static struct clk_rcg2 gcc_adss_pwm_clk_src = {
 	.cmd_rcgr = 0x1c004,
 	.mnd_width = 0,
@@ -1101,16 +1111,18 @@ static struct clk_rcg2 gcc_usb0_mock_utmi_clk_src = {
 	},
 };
-static struct clk_regmap_phy_mux gcc_usb0_pipe_clk_src = {
+static struct clk_regmap_mux usb0_pipe_clk_src = {
 	.reg = 0x2c074,
+	.shift = 8,
+	.width = 2,
+	.parent_map = gcc_usb3phy_0_cc_pipe_clk_xo_map,
 	.clkr = {
-		.hw.init = &(struct clk_init_data) {
-			.name = "gcc_usb0_pipe_clk_src",
-			.parent_data = &(const struct clk_parent_data) {
-				.index = DT_USB_PCIE_WRAPPER_PIPE_CLK,

drivers/clk/qcom/gcc-ipq5332.c static struct clk_rcg2 gcc_usb0_mock_utmi_clk_src = { · line 1125

Quoted 10 lines
drivers/clk/qcom/gcc-ipq5332.c +6 -3
-			},
-			.num_parents = 1,
-			.ops = &clk_regmap_phy_mux_ops,
+		.hw.init = &(const struct clk_init_data){
+			.name = "usb0phy_0_cc_pipe_clk_src",
+			.parent_data = gcc_usb3phy_0_cc_pipe_clk_xo,
+			.num_parents = 2,
+			.ops = &clk_regmap_mux_closest_ops,
+			.flags = CLK_SET_RATE_PARENT,
 		},

Soo... As you are reverting this. Is USB0 PIPE clock required to be parked to the XO? I was going to write 'before turning USB0_GDSC' off, but then I noticed that gcc-ipq5332 doesn't declare GDSCs. Does this platform have GDSCs?

Quoted 13 lines

drivers/clk/qcom/gcc-ipq5332.c static struct clk_branch gcc_usb0_pipe_clk = { · line 3057

Quoted 10 lines
drivers/clk/qcom/gcc-ipq5332.c +2 -2
 	},
 };
@@ -3041,8 +3053,8 @@ static struct clk_branch gcc_usb0_pipe_clk = {
 		.enable_mask = BIT(0),
 		.hw.init = &(const struct clk_init_data) {
 			.name = "gcc_usb0_pipe_clk",
-			.parent_hws = (const struct clk_hw*[]) {
-				&gcc_usb0_pipe_clk_src.clkr.hw,
+			.parent_names = (const char *[]){
+				"usb0_pipe_clk_src"

complete and definitive NAK. Do not use parent_names, we have just stopped migrating from them.

Will drop changes to this file and post a new patch.

Thanks
Varada

Quoted 16 lines

drivers/clk/qcom/gcc-ipq5332.c static struct clk_regmap *gcc_ipq5332_clocks[] = { · line 3597

Quoted 11 lines
drivers/clk/qcom/gcc-ipq5332.c +1 -1
 			},
 			.num_parents = 1,
 			.flags = CLK_SET_RATE_PARENT,
@@ -3580,7 +3592,7 @@ static struct clk_regmap *gcc_ipq5332_clocks[] = {
 	[GCC_PCIE3X2_PIPE_CLK_SRC] = &gcc_pcie3x2_pipe_clk_src.clkr,
 	[GCC_PCIE3X1_0_PIPE_CLK_SRC] = &gcc_pcie3x1_0_pipe_clk_src.clkr,
 	[GCC_PCIE3X1_1_PIPE_CLK_SRC] = &gcc_pcie3x1_1_pipe_clk_src.clkr,
-	[GCC_USB0_PIPE_CLK_SRC] = &gcc_usb0_pipe_clk_src.clkr,
+	[GCC_USB0_PIPE_CLK_SRC] = &usb0_pipe_clk_src.clkr,
 };
 static const struct qcom_reset_map gcc_ipq5332_resets[] = {

--
With best wishes
Dmitry

Signature · 3 lines
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#24 lore raw

Re: [PATCH 5/9] phy: qcom-m31: Introduce qcom,m31 USB phy

In reply to Krzysztof Kozlowski
Quoted 10 lines · Krzysztof Kozlowski
Quoted 7 lines · Dmitry Baryshkov
Quoted 3 lines · Varadarajan Narayanan

Introduce CONFIG_PHY_QCOM_M31_USB for including the M31 phy driver

Is there any reason to keep Kconfig, Makefile and driver in different commits?

KPI? Yearly objectives/goals?

No :-). Was not sure, hence split them.
Will combine in the next version.

Thanks
Varada

Signature · 3 lines
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#27 lore raw

Re: [PATCH 6/9] phy: qcom: Add qcom,m31 USB phy driver

In reply to Krzysztof Kozlowski
Quoted 6 lines · Krzysztof Kozlowski
Quoted 3 lines · Varadarajan Narayanan

Include M31 phy driver if CONFIG_PHY_QCOM_M31_USB is enabled

That's not a separate commit.

Will combine with the driver and post new version.

Thanks
Varada

Quoted 3 lines

Best regards,
Krzysztof

Signature · 3 lines
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#30 lore raw

Re: [PATCH 7/9] arm64: dts: qcom: ipq5332: Add USB related nodes

In reply to Dmitry Baryshkov
Quoted 37 lines · Dmitry Baryshkov
Quoted 36 lines · Varadarajan Narayanan

Add USB phy and controller nodes

---
 arch/arm64/boot/dts/qcom/ipq5332.dtsi | 55 +++++++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)
arch/arm64/boot/dts/qcom/ipq5332.dtsi +21 -0
index c2d6cc65..3183357 100644
@@ -383,6 +383,61 @@
 				status = "disabled";
 			};
 		};
+
+		usb_0_m31phy: hs_m31phy@7b000 {
+			compatible = "qcom,ipq5332-m31-usb-hsphy";
+			reg = <0x0007b000 0x12C>,
+			      <0x08af8800 0x400>;
+			reg-names = "m31usb_phy_base",
+				    "qscratch_base";
+			phy_type= "utmi";
+
+			resets = <&gcc GCC_QUSB2_0_PHY_BCR>;
+			reset-names = "usb2_phy_reset";
+
+			status = "okay";
+		};
+
+		usb2: usb2@8a00000 {
+			compatible = "qcom,ipq5332-dwc3", "qcom,dwc3";
+			#address-cells = <1>;
+			#size-cells = <1>;
+			ranges;
+
Quoted 8 lines

arch/arm64/boot/dts/qcom/ipq5332.dtsi line 412

Quoted 6 lines
arch/arm64/boot/dts/qcom/ipq5332.dtsi +6 -0
+			reg = <0x08af8800 0x100>;
+
+			clocks = <&gcc GCC_USB0_MASTER_CLK>,
+				<&gcc GCC_SNOC_USB_CLK>,
+				<&gcc GCC_USB0_SLEEP_CLK>,
+				<&gcc GCC_USB0_MOCK_UTMI_CLK>;

Please indent these values.

Ok.

Quoted 7 lines

arch/arm64/boot/dts/qcom/ipq5332.dtsi line 417

Quoted 5 lines
arch/arm64/boot/dts/qcom/ipq5332.dtsi +5 -0
+
+			clock-names = "core",
+				"iface",
+				"sleep",
+				"mock_utmi";

Please indent these values.

Ok.

Quoted 4 lines

arch/arm64/boot/dts/qcom/ipq5332.dtsi line 419

Quoted 2 lines
arch/arm64/boot/dts/qcom/ipq5332.dtsi +2 -0
+
+			interrupts-extended = <&intc GIC_SPI 134 IRQ_TYPE_LEVEL_HIGH>;

No PHY IRQs?

Will add.

Thanks
Varada

Quoted 28 lines
Quoted 13 lines
arch/arm64/boot/dts/qcom/ipq5332.dtsi +13 -0
+			interrupt-names = "pwr_event";
+
+			resets = <&gcc GCC_USB_BCR>;
+
+			qcom,select-utmi-as-pipe-clk;
+
+			usb2_0_dwc: usb@8a00000 {
+				compatible = "snps,dwc3";
+				reg = <0x08a00000 0xe000>;
+				clocks = <&gcc GCC_USB0_MOCK_UTMI_CLK>;
+				clock-names = "ref";
+				interrupts = <GIC_SPI 64 IRQ_TYPE_LEVEL_HIGH>;
+				usb-phy = <&usb_0_m31phy>;

arch/arm64/boot/dts/qcom/ipq5332.dtsi line 443

Quoted 10 lines
arch/arm64/boot/dts/qcom/ipq5332.dtsi +8 -0
+				tx-fifo-resize;
+				snps,is-utmi-l1-suspend;
+				snps,hird-threshold = /bits/ 8 <0x0>;
+				snps,dis_u2_susphy_quirk;
+				snps,dis_u3_susphy_quirk;
+				snps,ref-clock-period-ns = <21>;
+			};
+		};
 	};
 	timer {

--
With best wishes
Dmitry

Signature · 3 lines
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#32 lore raw

Re: [PATCH 7/9] arm64: dts: qcom: ipq5332: Add USB related nodes

In reply to Konrad Dybcio
Quoted 10 lines · Konrad Dybcio
Quoted 7 lines · Varadarajan Narayanan

Add USB phy and controller nodes

---
 arch/arm64/boot/dts/qcom/ipq5332.dtsi | 55 +++++++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)
Quoted 13 lines

arch/arm64/boot/dts/qcom/ipq5332.dtsi line 389

Quoted 12 lines
arch/arm64/boot/dts/qcom/ipq5332.dtsi +4 -0
index c2d6cc65..3183357 100644
@@ -383,6 +383,61 @@
 				status = "disabled";
 			};
 		};
+
+		usb_0_m31phy: hs_m31phy@7b000 {
+			compatible = "qcom,ipq5332-m31-usb-hsphy";
+			reg = <0x0007b000 0x12C>,

random uppercase hex

Ok.

Quoted 5 lines

arch/arm64/boot/dts/qcom/ipq5332.dtsi line 393

Quoted 4 lines
arch/arm64/boot/dts/qcom/ipq5332.dtsi +4 -0
+			      <0x08af8800 0x400>;
+			reg-names = "m31usb_phy_base",
+				    "qscratch_base";
+			phy_type= "utmi";

Missing space before '='

Ok.

Quoted 8 lines

arch/arm64/boot/dts/qcom/ipq5332.dtsi line 398

Quoted 5 lines
arch/arm64/boot/dts/qcom/ipq5332.dtsi +5 -0
+
+			resets = <&gcc GCC_QUSB2_0_PHY_BCR>;
+			reset-names = "usb2_phy_reset";
+
+			status = "okay";

If you're only defining the node, it's enabled by default

In this case, you'd probably want to disable it by default.

Ok.

Quoted 10 lines

arch/arm64/boot/dts/qcom/ipq5332.dtsi line 405

Quoted 7 lines
arch/arm64/boot/dts/qcom/ipq5332.dtsi +7 -0
+		};
+
+		usb2: usb2@8a00000 {
+			compatible = "qcom,ipq5332-dwc3", "qcom,dwc3";
+			#address-cells = <1>;
+			#size-cells = <1>;
+			ranges;

Please push these 3 properties to the end

And add status = "disabled" below them.

Ok.

Quoted 10 lines

arch/arm64/boot/dts/qcom/ipq5332.dtsi line 413

Quoted 8 lines
arch/arm64/boot/dts/qcom/ipq5332.dtsi +8 -0
+
+			reg = <0x08af8800 0x100>;
+
+			clocks = <&gcc GCC_USB0_MASTER_CLK>,
+				<&gcc GCC_SNOC_USB_CLK>,
+				<&gcc GCC_USB0_SLEEP_CLK>,
+				<&gcc GCC_USB0_MOCK_UTMI_CLK>;
+

Please remove this newline.

Quoted 5 lines

arch/arm64/boot/dts/qcom/ipq5332.dtsi line 417

Quoted 4 lines
arch/arm64/boot/dts/qcom/ipq5332.dtsi +4 -0
+			clock-names = "core",
+				"iface",
+				"sleep",
+				"mock_utmi";

Please align this, and all other similar lists.

Ok.

Quoted 8 lines

arch/arm64/boot/dts/qcom/ipq5332.dtsi line 419

Quoted 2 lines
arch/arm64/boot/dts/qcom/ipq5332.dtsi +2 -0
+
+			interrupts-extended = <&intc GIC_SPI 134 IRQ_TYPE_LEVEL_HIGH>;

interrupts-extended is unnecessary with just a single interrupt source.. you can make it interrupts and drop the GIC reference.

It would also be nice to push the interrupt properties below 'reg'. We're working on documenting and automating checking the preferred property order.

Ok.

Quoted 13 lines
Quoted 13 lines
arch/arm64/boot/dts/qcom/ipq5332.dtsi +13 -0
+			interrupt-names = "pwr_event";
+
+			resets = <&gcc GCC_USB_BCR>;
+
+			qcom,select-utmi-as-pipe-clk;
+
+			usb2_0_dwc: usb@8a00000 {
+				compatible = "snps,dwc3";
+				reg = <0x08a00000 0xe000>;
+				clocks = <&gcc GCC_USB0_MOCK_UTMI_CLK>;
+				clock-names = "ref";
+				interrupts = <GIC_SPI 64 IRQ_TYPE_LEVEL_HIGH>;
+				usb-phy = <&usb_0_m31phy>;
Quoted 8 lines

arch/arm64/boot/dts/qcom/ipq5332.dtsi line 438

Quoted 6 lines
arch/arm64/boot/dts/qcom/ipq5332.dtsi +6 -0
+				tx-fifo-resize;
+				snps,is-utmi-l1-suspend;
+				snps,hird-threshold = /bits/ 8 <0x0>;
+				snps,dis_u2_susphy_quirk;
+				snps,dis_u3_susphy_quirk;
+				snps,ref-clock-period-ns = <21>;

1/21 is 0.0476.. that doesn't seem to correspond to the ref clk frequency?

dwc3_ref_clk_period() prefers ref clock's rate over ref-clock-period-ns. Since ref clock is available this is not used. Will remove this.

Thanks
Varada

Quoted 6 lines

Konrad

Quoted 5 lines
arch/arm64/boot/dts/qcom/ipq5332.dtsi +2 -0
+			};
+		};
 	};
 
 	timer {
Signature · 3 lines
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#34 lore raw

Re: [PATCH 7/9] arm64: dts: qcom: ipq5332: Add USB related nodes

In reply to Krzysztof Kozlowski
Quoted 8 lines · Krzysztof Kozlowski
Quoted 7 lines · Varadarajan Narayanan

Add USB phy and controller nodes

---
 arch/arm64/boot/dts/qcom/ipq5332.dtsi | 55 +++++++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)
Quoted 14 lines

arch/arm64/boot/dts/qcom/ipq5332.dtsi line 387

Quoted 10 lines
arch/arm64/boot/dts/qcom/ipq5332.dtsi +2 -0
index c2d6cc65..3183357 100644
@@ -383,6 +383,61 @@
 				status = "disabled";
 			};
 		};
+
+		usb_0_m31phy: hs_m31phy@7b000 {

Node names should be generic. See also explanation and list of examples in DT specification:
https://devicetree-specification.readthedocs.io/en/latest/chapter2-devicetree-basics.html#generic-names-recommendation

Ok.

Quoted 5 lines

arch/arm64/boot/dts/qcom/ipq5332.dtsi line 390

Quoted 3 lines
arch/arm64/boot/dts/qcom/ipq5332.dtsi +3 -0
+			compatible = "qcom,ipq5332-m31-usb-hsphy";
+			reg = <0x0007b000 0x12C>,
+			      <0x08af8800 0x400>;

Lowercase hex only.

Ok.

Quoted 10 lines

arch/arm64/boot/dts/qcom/ipq5332.dtsi line 398

Quoted 8 lines
arch/arm64/boot/dts/qcom/ipq5332.dtsi +8 -0
+			reg-names = "m31usb_phy_base",
+				    "qscratch_base";
+			phy_type= "utmi";
+
+			resets = <&gcc GCC_QUSB2_0_PHY_BCR>;
+			reset-names = "usb2_phy_reset";
+
+			status = "okay";

It's by default. Drop.

Ok.

Quoted 11 lines

arch/arm64/boot/dts/qcom/ipq5332.dtsi line 401

Quoted 3 lines
arch/arm64/boot/dts/qcom/ipq5332.dtsi +3 -0
+		};
+
+		usb2: usb2@8a00000 {

It does not look like you tested the DTS against bindings. Please run make dtbs_check (see Documentation/devicetree/bindings/writing-schema.rst for instructions).

Node names should be generic. See also explanation and list of examples in DT specification:
https://devicetree-specification.readthedocs.io/en/latest/chapter2-devicetree-basics.html#generic-names-recommendation

Ok.

Quoted 9 lines

arch/arm64/boot/dts/qcom/ipq5332.dtsi line 407

Quoted 6 lines
arch/arm64/boot/dts/qcom/ipq5332.dtsi +6 -0
+			compatible = "qcom,ipq5332-dwc3", "qcom,dwc3";
+			#address-cells = <1>;
+			#size-cells = <1>;
+			ranges;
+
+			reg = <0x08af8800 0x100>;

reg is always after compatible. Ranges is third. Then you will spot that address is wrong.

Ok.

Quoted 7 lines

arch/arm64/boot/dts/qcom/ipq5332.dtsi line 412

Quoted 5 lines
arch/arm64/boot/dts/qcom/ipq5332.dtsi +5 -0
+
+			clocks = <&gcc GCC_USB0_MASTER_CLK>,
+				<&gcc GCC_SNOC_USB_CLK>,
+				<&gcc GCC_USB0_SLEEP_CLK>,
+				<&gcc GCC_USB0_MOCK_UTMI_CLK>;

Fix alignment.

Ok.

Quoted 7 lines

arch/arm64/boot/dts/qcom/ipq5332.dtsi line 417

Quoted 5 lines
arch/arm64/boot/dts/qcom/ipq5332.dtsi +5 -0
+
+			clock-names = "core",
+				"iface",
+				"sleep",
+				"mock_utmi";

Fix alignment.

Ok.

Quoted 4 lines

arch/arm64/boot/dts/qcom/ipq5332.dtsi line 421

Quoted 4 lines
arch/arm64/boot/dts/qcom/ipq5332.dtsi +4 -0
+
+			interrupts-extended = <&intc GIC_SPI 134 IRQ_TYPE_LEVEL_HIGH>;
+			interrupt-names = "pwr_event";
+

Thanks
Varada

Quoted 3 lines

Best regards,
Krzysztof

Signature · 3 lines
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#38 lore raw

Re: [PATCH 9/9] arm64: defconfig: Enable QCOM M31 USB phy driver

In reply to Krzysztof Kozlowski
Quoted 5 lines · Krzysztof Kozlowski
Quoted 1 line · Varadarajan Narayanan

Enable QCOM M31 USB phy driver present in IPQ5332

What is "QCOM"? If acronym, extend. IPQ5332 - provide full name, so "Qualcomm IPQ....".

Will remove 'QCOM'.

Thanks
Varada

Quoted 3 lines

Best regards,
Krzysztof

Signature · 3 lines
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#8 lore raw

Re: [PATCH 2/9] dt-bindings: phy: qcom,m31: Document qcom,m31 USB phy

In reply to Varadarajan Narayanan
Quoted 8 lines · Varadarajan Narayanan
Quoted 8 lines

Documentation/devicetree/bindings/phy/qcom,m31.yaml line 23

Quoted 2 lines
Documentation/devicetree/bindings/phy/qcom,m31.yaml new file +2 -0
+          - enum:
+              - qcom,m31-usb-hsphy

I am confused what's this. If m31 is coming from some IP block provider, then you are using wrong vendor prefix.
https://www.m31tech.com/download_file/M31_USB.pdf

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

+ - qcom,ipq5332-m31-usb-hsphy

This confuses me even more. IPQ m31?

Will change this to m31,usb-hsphy and m31,ipq5332-usb-hsphy respectively. Will that be acceptable?

m31,ipq5332 seems wrong, as m31 did not create ipq5332. Does the m31 device have some name/version/model? If it is not really known, then I would just propose to go with qcom,ipq5332-usb-hsphy.

Skip generic compatible ("usb-hsphy") entirely.

And then we have... existing bindings qcom,usb-hs-phy.yaml. Don't create something similar with difference in the hyphen. Just use device specific compatible thus device specific filename.

Quoted 17 lines
Quoted 7 lines

Documentation/devicetree/bindings/phy/qcom,m31.yaml line 28

Quoted 5 lines
Documentation/devicetree/bindings/phy/qcom,m31.yaml new file +4 -0
+
+  reg:
+    description:
+      Offset and length of the M31 PHY register set

Drop description, obvious.

Ok.

Quoted 7 lines
Quoted 6 lines
Documentation/devicetree/bindings/phy/qcom,m31.yaml new file +6 -0
+    maxItems: 2
+
+  reg-names:
+    items:
+      - const: m31usb_phy_base
+      - const: qscratch_base
Quoted 4 lines
Quoted 1 line

Drop "_base" from both.

Ok. Will drop qscratch_base. This is in the controller space. Should not come here.

Then drop reg-names entirely.

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Documentation/devicetree/bindings/phy/qcom,m31.yaml new file +7 -0
+
+  phy_type:
+    oneOf:
+      - items:
+          - enum:
+              - utmi
+              - ulpi
Quoted 6 lines
Quoted 1 line

This does not belong to phy, but to USB node.

This is used by the driver to set a bit during phy init. Hence have it as a replication of the USB node's entry. If this is not permissible, is there some way to get this from the USB node, or any other alternative mechanism?

Shouldn't USB controller choose what type of PHY type it wants?

Quoted 13 lines
Quoted 13 lines

Documentation/devicetree/bindings/phy/qcom,m31.yaml line 58

Quoted 8 lines
Documentation/devicetree/bindings/phy/qcom,m31.yaml new file +7 -0
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/clock/qcom,ipq5332-gcc.h>
+    hs_m31phy_0: hs_m31phy@5b00 {

Node names should be generic. See also explanation and list of examples in DT specification:
https://devicetree-specification.readthedocs.io/en/latest/chapter2-devicetree-basics.html#generic-names-recommendation

Quoted 3 lines
Quoted 1 line

Also, no underscores in node names.

Will change this as usbphy0:hs_m31phy@7b000

This does not solve my comments. I did not write "label" but "node name".

Best regards,
Krzysztof

#9 lore raw

Re: [PATCH 2/9] dt-bindings: phy: qcom,m31: Document qcom,m31 USB phy

Quoted 13 lines · Krzysztof Kozlowski
Quoted 12 lines · Varadarajan Narayanan
Quoted 11 lines

Documentation/devicetree/bindings/phy/qcom,m31.yaml line 23

Quoted 2 lines
Documentation/devicetree/bindings/phy/qcom,m31.yaml new file +2 -0
+          - enum:
+              - qcom,m31-usb-hsphy

I am confused what's this. If m31 is coming from some IP block provider, then you are using wrong vendor prefix.
https://www.m31tech.com/download_file/M31_USB.pdf

Quoted 1 line

+ - qcom,ipq5332-m31-usb-hsphy

This confuses me even more. IPQ m31?

Quoted 8 lines
Quoted 2 lines

Will change this to m31,usb-hsphy and m31,ipq5332-usb-hsphy respectively. Will that be acceptable?

m31,ipq5332 seems wrong, as m31 did not create ipq5332. Does the m31 device have some name/version/model? If it is not really known, then I would just propose to go with qcom,ipq5332-usb-hsphy.

Skip generic compatible ("usb-hsphy") entirely.

Ok.

Quoted 3 lines

And then we have... existing bindings qcom,usb-hs-phy.yaml. Don't create something similar with difference in the hyphen. Just use device specific compatible thus device specific filename.

qcom,usb-hs-phy.yaml seems to be for ULPI mode phy and the driver we are introducing is for UTMI. We would have to modify phy-qcom-usb-hs.c to accomodate M31. Will that be acceptable to phy-qcom-usb-hs.c owners/maintainers?

Quoted 16 lines
Quoted 16 lines
Quoted 6 lines

Documentation/devicetree/bindings/phy/qcom,m31.yaml line 28

Quoted 4 lines
Documentation/devicetree/bindings/phy/qcom,m31.yaml new file +4 -0
+
+  reg:
+    description:
+      Offset and length of the M31 PHY register set

Drop description, obvious.

Ok.

Quoted 7 lines
Quoted 6 lines
Documentation/devicetree/bindings/phy/qcom,m31.yaml new file +6 -0
+    maxItems: 2
+
+  reg-names:
+    items:
+      - const: m31usb_phy_base
+      - const: qscratch_base
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Drop "_base" from both.

Ok. Will drop qscratch_base. This is in the controller space. Should not come here.

Then drop reg-names entirely.

Ok.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Documentation/devicetree/bindings/phy/qcom,m31.yaml new file +7 -0
+
+  phy_type:
+    oneOf:
+      - items:
+          - enum:
+              - utmi
+              - ulpi
Quoted 8 lines
Quoted 6 lines
Quoted 1 line

This does not belong to phy, but to USB node.

This is used by the driver to set a bit during phy init. Hence have it as a replication of the USB node's entry. If this is not permissible, is there some way to get this from the USB node, or any other alternative mechanism?

Shouldn't USB controller choose what type of PHY type it wants?

Will remove this. IPQ5332 uses it in UTMI mode only.

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

Documentation/devicetree/bindings/phy/qcom,m31.yaml line 58

Quoted 7 lines
Documentation/devicetree/bindings/phy/qcom,m31.yaml new file +7 -0
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/clock/qcom,ipq5332-gcc.h>
+    hs_m31phy_0: hs_m31phy@5b00 {

Node names should be generic. See also explanation and list of examples in DT specification:
https://devicetree-specification.readthedocs.io/en/latest/chapter2-devicetree-basics.html#generic-names-recommendation

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Also, no underscores in node names.

Will change this as usbphy0:hs_m31phy@7b000

This does not solve my comments. I did not write "label" but "node name".

Sorry. will fix it.

Thanks
Varada

Signature · 3 lines
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#10 lore raw

Re: [PATCH 2/9] dt-bindings: phy: qcom,m31: Document qcom,m31 USB phy

Quoted 9 lines · Varadarajan Narayanan
Quoted 4 lines

And then we have... existing bindings qcom,usb-hs-phy.yaml. Don't create something similar with difference in the hyphen. Just use device specific compatible thus device specific filename.

qcom,usb-hs-phy.yaml seems to be for ULPI mode phy and the driver we are introducing is for UTMI. We would have to modify phy-qcom-usb-hs.c to accomodate M31. Will that be acceptable to phy-qcom-usb-hs.c owners/maintainers?

We don't talk about drivers here but bindings. Why would you need to modify the driver when introducing new binding for different device?

Best regards,
Krzysztof

#11 lore raw

Re: [PATCH 2/9] dt-bindings: phy: qcom,m31: Document qcom,m31 USB phy

Quoted 7 lines · Krzysztof Kozlowski
Quoted 5 lines · Varadarajan Narayanan
Quoted 4 lines

And then we have... existing bindings qcom,usb-hs-phy.yaml. Don't create something similar with difference in the hyphen. Just use device specific compatible thus device specific filename.

Quoted 7 lines
Quoted 4 lines

qcom,usb-hs-phy.yaml seems to be for ULPI mode phy and the driver we are introducing is for UTMI. We would have to modify phy-qcom-usb-hs.c to accomodate M31. Will that be acceptable to phy-qcom-usb-hs.c owners/maintainers?

We don't talk about drivers here but bindings. Why would you need to modify the driver when introducing new binding for different device?

Sorry. I misunderstood your feedback as "use the existing bindings".

Will name the bindings file as qcom,ipq5332-usb-hsphy.yaml and post the next version.

Thanks
Varada

Signature · 3 lines
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
maintainer
#17 lore raw

Re: [PATCH 3/9] phy: qcom-m31: Introduce qcom,m31 USB phy driver

In reply to Konrad Dybcio
Quoted 60 lines · Konrad Dybcio
Quoted 21 lines · Varadarajan Narayanan

Add the M31 USB2 phy driver

---
 drivers/phy/qualcomm/phy-qcom-m31.c | 360 ++++++++++++++++++++++++++++++++++++
 1 file changed, 360 insertions(+)
 create mode 100644 drivers/phy/qualcomm/phy-qcom-m31.c
drivers/phy/qualcomm/phy-qcom-m31.c new file +7 -0
new file mode 100644
index 0000000..d29a91e
@@ -0,0 +1,360 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2014-2016, 2020, The Linux Foundation. All rights reserved.
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>

drivers/phy/qualcomm/phy-qcom-m31.c line 17

Quoted 10 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +10 -0
+#include <linux/err.h>
+#include <linux/slab.h>
+#include <linux/clk.h>
+#include <linux/delay.h>
+#include <linux/io.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/usb/phy.h>
+#include <linux/reset.h>
+#include <linux/of_device.h>

Please sort these

Quoted 24 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +24 -0
+
+enum clk_reset_action {
+	CLK_RESET_DEASSERT	= 0,
+	CLK_RESET_ASSERT	= 1
+};
+
+#define USB2PHY_PORT_POWERDOWN		0xA4
+#define POWER_UP			BIT(0)
+#define POWER_DOWN			0
+
+#define USB2PHY_PORT_UTMI_CTRL1	0x40
+
+#define USB2PHY_PORT_UTMI_CTRL2	0x44
+#define UTMI_ULPI_SEL			BIT(7)
+#define UTMI_TEST_MUX_SEL		BIT(6)
+
+#define HS_PHY_CTRL_REG			0x10
+#define UTMI_OTG_VBUS_VALID             BIT(20)
+#define SW_SESSVLD_SEL                  BIT(28)
+
+#define USB_PHY_CFG0			0x94
+#define USB_PHY_UTMI_CTRL5		0x50
+#define USB_PHY_FSEL_SEL		0xB8
+#define USB_PHY_HS_PHY_CTRL_COMMON0	0x54
Quoted 8 lines

drivers/phy/qualcomm/phy-qcom-m31.c line 48

Quoted 7 lines
drivers/phy/qualcomm/phy-qcom-m31.c new file +7 -0
+#define USB_PHY_REFCLK_CTRL		0xA0
+#define USB_PHY_HS_PHY_CTRL2		0x64
+#define USB_PHY_UTMI_CTRL0		0x3c
+#define USB2PHY_USB_PHY_M31_XCFGI_1	0xBC
+#define USB2PHY_USB_PHY_M31_XCFGI_4	0xC8
+#define USB2PHY_USB_PHY_M31_XCFGI_5	0xCC
+#define USB2PHY_USB_PHY_M31_XCFGI_11	0xE4

Could you sort them address-wise?

and lower case hex values as well please

Signature · 6 lines
~Vinod

-- 
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy