Skip to contentSkip to conversation

usb: dwc3-am62: module removal and errata fixes

PATCH Superseded Roger Quadros 2 participants 7 messages Feb 1, 2024 – Feb 2, 2024

Subsystems (2)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover usb: dwc3-am62: module removal and errata fixes

Hi,

This series fixes errors during module removal. It also implements PHY core voltage selection as per TI recommendation and workaround for Errata i2409 [1].

The workaround needs PHY2 region to be present in device node. This is sent as a separate series [2].

[1] - https://www.ti.com/lit/er/sprz487d/sprz487d.pdf
[2] - https://lore.kernel.org/all/[email protected]/

cheers,
-roger

Roger Quadros (4):
usb: dwc3-am62: call of_platform_depopulate in .remove()
usb: dwc3-am62: fix error on module removal
usb: dwc3-am62: Fix PHY core voltage selection
usb: dwc3-am62: add workaround for Errata i2409

 drivers/usb/dwc3/dwc3-am62.c | 55 ++++++++++++++++++++++++++++--------
 1 file changed, 44 insertions(+), 11 deletions(-)

base-commit: 6613476e225e090cc9aad49be7fa504e290dd33d

Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/4 usb: dwc3-am62: call of_platform_depopulate in .remove()

We called of_platform_populate() in .probe() so call the cleanup function of_platform_depopulate() in .remove().

Get rid of the now unnnecessary dwc3_ti_remove_core().

---
 drivers/usb/dwc3/dwc3-am62.c | 10 +---------
 1 file changed, 1 insertion(+), 9 deletions(-)
drivers/usb/dwc3/dwc3-am62.c +1 -9
index 90a587bc29b7..1bfc9e67614f 100644
@@ -267,21 +267,13 @@ static int dwc3_ti_probe(struct platform_device *pdev)
 	return ret;
 }
 
-static int dwc3_ti_remove_core(struct device *dev, void *c)
-{
-	struct platform_device *pdev = to_platform_device(dev);
-
-	platform_device_unregister(pdev);
-	return 0;
-}
-
 static void dwc3_ti_remove(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
 	struct dwc3_am62 *am62 = platform_get_drvdata(pdev);
 	u32 reg;
 
-	device_for_each_child(dev, NULL, dwc3_ti_remove_core);
+	of_platform_depopulate(dev);
 
 	/* Clear mode valid bit */
 	reg = dwc3_ti_readl(am62, USBSS_MODE_CONTROL);
Signature · 1 line
2.34.1
#2 lore raw

PATCH 2/4 usb: dwc3-am62: fix error on module removal

In reply to Roger Quadros

As runtime PM is enabled, the module can be runtime suspended when .remove() is called.

Do a pm_runtime_get_sync() to make sure module is active before doing any register operations.

Doing a pm_runtime_put_sync() should disable the refclk so no need to disable it again.

Fixes the below warning at module removel.

[   39.705310] ------------[ cut here ]------------
[   39.710004] clk:162:3 already disabled
[   39.713941] WARNING: CPU: 0 PID: 921 at drivers/clk/clk.c:1090 clk_core_disable+0xb0/0xb8
---
 drivers/usb/dwc3/dwc3-am62.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/usb/dwc3/dwc3-am62.c +5 -1
index 1bfc9e67614f..600ba9cfefea 100644
@@ -273,6 +273,11 @@ static void dwc3_ti_remove(struct platform_device *pdev)
 	struct dwc3_am62 *am62 = platform_get_drvdata(pdev);
 	u32 reg;
 
+	pm_runtime_get_sync(dev);
+
+	device_wakeup_disable(dev);
+	device_set_wakeup_capable(dev, false);
+
 	of_platform_depopulate(dev);
 
 	/* Clear mode valid bit */
@@ -281,7 +286,6 @@ static void dwc3_ti_remove(struct platform_device *pdev)
 	dwc3_ti_writel(am62, USBSS_MODE_CONTROL, reg);
 
 	pm_runtime_put_sync(dev);
-	clk_disable_unprepare(am62->usb2_refclk);
 	pm_runtime_disable(dev);
 	pm_runtime_set_suspended(dev);
 }
Signature · 1 line
2.34.1
#3 lore raw

PATCH 3/4 usb: dwc3-am62: Fix PHY core voltage selection

In reply to Roger Quadros

TRM information is outdated and design team has confirmed that PHY_CORE_VOLTAGE should be 0 irrespective of VDD_CORE voltage.

---
 drivers/usb/dwc3/dwc3-am62.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/usb/dwc3/dwc3-am62.c +9 -1
index 600ba9cfefea..af1ce934e7fb 100644
@@ -97,7 +97,8 @@
 #define USBSS_VBUS_STAT_SESSVALID	BIT(2)
 #define USBSS_VBUS_STAT_VBUSVALID	BIT(0)
 
-/* Mask for PHY PLL REFCLK */
+/* USB_PHY_CTRL register bits in CTRL_MMR */
+#define PHY_CORE_VOLTAGE_MASK	BIT(31)
 #define PHY_PLL_REFCLK_MASK	GENMASK(3, 0)
 
 #define DWC3_AM62_AUTOSUSPEND_DELAY	100
@@ -162,6 +163,13 @@ static int phy_syscon_pll_refclk(struct dwc3_am62 *am62)
 
 	am62->offset = args.args[0];
 
+	/* Core voltage. PHY_CORE_VOLTAGE bit Recommended to be 0 always */
+	ret = regmap_update_bits(am62->syscon, am62->offset, PHY_CORE_VOLTAGE_MASK, 0);
+	if (ret) {
+		dev_err(dev, "failed to set phy core voltage\n");
+		return ret;
+	}
+
 	ret = regmap_update_bits(am62->syscon, am62->offset, PHY_PLL_REFCLK_MASK, am62->rate_code);
 	if (ret) {
 		dev_err(dev, "failed to set phy pll reference clock rate\n");
Signature · 1 line
2.34.1
#4 lore raw

PATCH 4/4 usb: dwc3-am62: add workaround for Errata i2409

In reply to Roger Quadros

All AM62 devices have Errata i2409 [1] due to which USB2 PHY may lock up due to short suspend.

Workaround involves setting bit 5 and 4 PLL_REG12 in PHY2 register space after USB controller is brought out of LPSC reset but before controller initialization.

Handle this workaround.

[1] - https://www.ti.com/lit/er/sprz487d/sprz487d.pdf

---
 drivers/usb/dwc3/dwc3-am62.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
drivers/usb/dwc3/dwc3-am62.c +29 -0
index af1ce934e7fb..35d7a2fb128e 100644
@@ -101,11 +101,17 @@
 #define PHY_CORE_VOLTAGE_MASK	BIT(31)
 #define PHY_PLL_REFCLK_MASK	GENMASK(3, 0)
 
+/* USB PHY2 register offsets */
+#define	USB_PHY_PLL_REG12		0x130
+#define	USB_PHY_PLL_LDO_REF_EN		BIT(5)
+#define	USB_PHY_PLL_LDO_REF_EN_EN	BIT(4)
+
 #define DWC3_AM62_AUTOSUSPEND_DELAY	100
 
 struct dwc3_am62 {
 	struct device *dev;
 	void __iomem *usbss;
+	void __iomem *phy;
 	struct clk *usb2_refclk;
 	int rate_code;
 	struct regmap *syscon;
@@ -140,6 +146,16 @@ static inline void dwc3_ti_writel(struct dwc3_am62 *am62, u32 offset, u32 value)
 	writel(value, (am62->usbss) + offset);
 }
 
+static inline u32 dwc3_ti_phy_readl(struct dwc3_am62 *am62, u32 offset)
+{
+	return readl((am62->phy) + offset);
+}
+
+static inline void dwc3_ti_phy_writel(struct dwc3_am62 *am62, u32 offset, u32 value)
+{
+	writel(value, (am62->phy) + offset);
+}
+
 static int phy_syscon_pll_refclk(struct dwc3_am62 *am62)
 {
 	struct device *dev = am62->dev;
@@ -201,6 +217,12 @@ static int dwc3_ti_probe(struct platform_device *pdev)
 		return PTR_ERR(am62->usbss);
 	}
 
+	am62->phy = devm_platform_ioremap_resource(pdev, 1);
+	if (IS_ERR(am62->phy)) {
+		dev_err(dev, "can't map PHY IOMEM resource. Won't apply i2409 fix.\n");
+		am62->phy = NULL;
+	}
+
 	am62->usb2_refclk = devm_clk_get(dev, "ref");
 	if (IS_ERR(am62->usb2_refclk)) {
 		dev_err(dev, "can't get usb2_refclk\n");
@@ -227,6 +249,13 @@ static int dwc3_ti_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
+	/* Workaround Errata i2409 */
+	if (am62->phy) {
+		reg = dwc3_ti_phy_readl(am62, USB_PHY_PLL_REG12);
+		reg |= USB_PHY_PLL_LDO_REF_EN | USB_PHY_PLL_LDO_REF_EN_EN;
+		dwc3_ti_phy_writel(am62, USB_PHY_PLL_REG12, reg);
+	}
+
 	/* VBUS divider select */
 	am62->vbus_divider = device_property_read_bool(dev, "ti,vbus-divider");
 	reg = dwc3_ti_readl(am62, USBSS_PHY_CONFIG);
Signature · 1 line
2.34.1
#5 lore raw

Re: [PATCH 4/4] usb: dwc3-am62: add workaround for Errata i2409

Quoted 25 lines · Roger Quadros

All AM62 devices have Errata i2409 [1] due to which USB2 PHY may lock up due to short suspend.

Workaround involves setting bit 5 and 4 PLL_REG12 in PHY2 register space after USB controller is brought out of LPSC reset but before controller initialization.

Handle this workaround.

[1] - https://www.ti.com/lit/er/sprz487d/sprz487d.pdf

---
  drivers/usb/dwc3/dwc3-am62.c | 29 +++++++++++++++++++++++++++++
  1 file changed, 29 insertions(+)
drivers/usb/dwc3/dwc3-am62.c +1 -0
index af1ce934e7fb..35d7a2fb128e 100644
@@ -101,11 +101,17 @@
  #define PHY_CORE_VOLTAGE_MASK	BIT(31)
  #define PHY_PLL_REFCLK_MASK	GENMASK(3, 0)
 
+/* USB PHY2 register offsets */

drivers/usb/dwc3/dwc3-am62.c line 114

Quoted 10 lines
drivers/usb/dwc3/dwc3-am62.c +5 -0
+#define	USB_PHY_PLL_REG12		0x130
+#define	USB_PHY_PLL_LDO_REF_EN		BIT(5)
+#define	USB_PHY_PLL_LDO_REF_EN_EN	BIT(4)
+
  #define DWC3_AM62_AUTOSUSPEND_DELAY	100
 
  struct dwc3_am62 {
  	struct device *dev;
  	void __iomem *usbss;
+	void __iomem *phy;

Why do you need this in the driver data? You only use it in probe(), just have it be a local variable.

drivers/usb/dwc3/dwc3-am62.c static inline void dwc3_ti_writel(struct dwc3_am62 *am62, u32 offset, u32 value) · line 150

Quoted 9 lines
drivers/usb/dwc3/dwc3-am62.c +2 -0
  	struct clk *usb2_refclk;
  	int rate_code;
  	struct regmap *syscon;
@@ -140,6 +146,16 @@ static inline void dwc3_ti_writel(struct dwc3_am62 *am62, u32 offset, u32 value)
  	writel(value, (am62->usbss) + offset);
  }
 
+static inline u32 dwc3_ti_phy_readl(struct dwc3_am62 *am62, u32 offset)
+{

Do you really need these one line functions? They add more code than they save and just hide a single deference? Just do that directly.

Andrew

Quoted 38 lines
drivers/usb/dwc3/dwc3-am62.c +21 -0
+	return readl((am62->phy) + offset);
+}
+
+static inline void dwc3_ti_phy_writel(struct dwc3_am62 *am62, u32 offset, u32 value)
+{
+	writel(value, (am62->phy) + offset);
+}
+
  static int phy_syscon_pll_refclk(struct dwc3_am62 *am62)
  {
  	struct device *dev = am62->dev;
@@ -201,6 +217,12 @@ static int dwc3_ti_probe(struct platform_device *pdev)
  		return PTR_ERR(am62->usbss);
  	}
 
+	am62->phy = devm_platform_ioremap_resource(pdev, 1);
+	if (IS_ERR(am62->phy)) {
+		dev_err(dev, "can't map PHY IOMEM resource. Won't apply i2409 fix.\n");
+		am62->phy = NULL;
+	}
+
  	am62->usb2_refclk = devm_clk_get(dev, "ref");
  	if (IS_ERR(am62->usb2_refclk)) {
  		dev_err(dev, "can't get usb2_refclk\n");
@@ -227,6 +249,13 @@ static int dwc3_ti_probe(struct platform_device *pdev)
  	if (ret)
  		return ret;
 
+	/* Workaround Errata i2409 */
+	if (am62->phy) {
+		reg = dwc3_ti_phy_readl(am62, USB_PHY_PLL_REG12);
+		reg |= USB_PHY_PLL_LDO_REF_EN | USB_PHY_PLL_LDO_REF_EN_EN;
+		dwc3_ti_phy_writel(am62, USB_PHY_PLL_REG12, reg);
+	}
+
  	/* VBUS divider select */
  	am62->vbus_divider = device_property_read_bool(dev, "ti,vbus-divider");
  	reg = dwc3_ti_readl(am62, USBSS_PHY_CONFIG);
#6 lore raw

Re: [PATCH 4/4] usb: dwc3-am62: add workaround for Errata i2409

Quoted 29 lines · Andrew Davis
Quoted 28 lines · Roger Quadros

All AM62 devices have Errata i2409 [1] due to which USB2 PHY may lock up due to short suspend.

Workaround involves setting bit 5 and 4 PLL_REG12 in PHY2 register space after USB controller is brought out of LPSC reset but before controller initialization.

Handle this workaround.

[1] - https://www.ti.com/lit/er/sprz487d/sprz487d.pdf

---
  drivers/usb/dwc3/dwc3-am62.c | 29 +++++++++++++++++++++++++++++

  1 file changed, 29 insertions(+)
drivers/usb/dwc3/dwc3-am62.c +0 -0
index af1ce934e7fb..35d7a2fb128e 100644
@@ -101,11 +101,17 @@
   #define PHY_CORE_VOLTAGE_MASK    BIT(31)
   #define PHY_PLL_REFCLK_MASK    GENMASK(3, 0)

  +/* USB PHY2 register offsets */

drivers/usb/dwc3/dwc3-am62.c +4 -0
+#define    USB_PHY_PLL_REG12        0x130
+#define    USB_PHY_PLL_LDO_REF_EN        BIT(5)
+#define    USB_PHY_PLL_LDO_REF_EN_EN    BIT(4)
+
Quoted 8 lines
Quoted 5 lines

  #define DWC3_AM62_AUTOSUSPEND_DELAY    100 struct dwc3_am62 {
      struct device *dev;
      void __iomem *usbss;
+    void __iomem *phy;

Why do you need this in the driver data? You only use it in probe(), just have it be a local variable.

OK.

Quoted 12 lines

drivers/usb/dwc3/dwc3-am62.c static inline void dwc3_ti_writel(struct dwc3_am62 *am62, u32 offset, u32 value) · line 149

Quoted 9 lines

      struct clk *usb2_refclk;
      int rate_code;
      struct regmap *syscon;

drivers/usb/dwc3/dwc3-am62.c +1 -0
@@ -140,6 +146,16 @@ static inline void dwc3_ti_writel(struct dwc3_am62 *am62, u32 offset, u32 value)
       writel(value, (am62->usbss) + offset);
   }
   +static inline u32 dwc3_ti_phy_readl(struct dwc3_am62 *am62, u32 offset)
+{

Do you really need these one line functions? They add more code than they save and just hide a single deference? Just do that directly.

Sure. Thanks.

Quoted 39 lines

Andrew

Quoted 36 lines
drivers/usb/dwc3/dwc3-am62.c +13 -0
+    return readl((am62->phy) + offset);
+}
+
+static inline void dwc3_ti_phy_writel(struct dwc3_am62 *am62, u32 offset, u32 value)
+{
+    writel(value, (am62->phy) + offset);
+}
+
   static int phy_syscon_pll_refclk(struct dwc3_am62 *am62)
   {
       struct device *dev = am62->dev;
@@ -201,6 +217,12 @@ static int dwc3_ti_probe(struct platform_device *pdev)
           return PTR_ERR(am62->usbss);
       }
   +    am62->phy = devm_platform_ioremap_resource(pdev, 1);
+    if (IS_ERR(am62->phy)) {
+        dev_err(dev, "can't map PHY IOMEM resource. Won't apply i2409 fix.\n");
+        am62->phy = NULL;
+    }
+
       am62->usb2_refclk = devm_clk_get(dev, "ref");
       if (IS_ERR(am62->usb2_refclk)) {
           dev_err(dev, "can't get usb2_refclk\n");
@@ -227,6 +249,13 @@ static int dwc3_ti_probe(struct platform_device *pdev)
       if (ret)
           return ret;

  +    /* Workaround Errata i2409 */
+    if (am62->phy) {
+        reg = dwc3_ti_phy_readl(am62, USB_PHY_PLL_REG12);
+        reg |= USB_PHY_PLL_LDO_REF_EN | USB_PHY_PLL_LDO_REF_EN_EN; +        dwc3_ti_phy_writel(am62, USB_PHY_PLL_REG12, reg);
+    }
+
      /* VBUS divider select */
      am62->vbus_divider = device_property_read_bool(dev, "ti,vbus-divider"); reg = dwc3_ti_readl(am62, USBSS_PHY_CONFIG);

Signature · 2 lines
cheers,
-roger