Message ID | 20240307-j7200-usb-suspend-v4-0-5ec7615431f3@bootlin.com |
---|---|
Headers | show |
Series | usb: cdns: fix suspend on J7200 by assuming reset-on-resume | expand |
Hi, On 07/03/2024 11:55, Théo Lebrun wrote: > The hardware initialisation register write sequence is only used at > probe. Move it from being done at explicitely at probe to being done > implicitely by pm_runtime_get_sync() that calls ->runtime_resume(). explicitly / implicitly > > Keep devicetree parsing in probe and add a new field in the private > struct to remember the USB2 refclk rate code computation result. > > This opens the door to having the init sequence being executed later > down the road, at system-wide resume for example. This is NOT currently > happening because runtime PM is disabled at suspend without the > refcount being affected. > > Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com> > --- > drivers/usb/cdns3/cdns3-ti.c | 90 +++++++++++++++++++++++++------------------- > 1 file changed, 52 insertions(+), 38 deletions(-) > > diff --git a/drivers/usb/cdns3/cdns3-ti.c b/drivers/usb/cdns3/cdns3-ti.c > index 5945c4b1e11f..4c8a557e6a6f 100644 > --- a/drivers/usb/cdns3/cdns3-ti.c > +++ b/drivers/usb/cdns3/cdns3-ti.c > @@ -57,6 +57,7 @@ struct cdns_ti { > unsigned vbus_divider:1; > struct clk *usb2_refclk; > struct clk *lpm_clk; > + int usb2_refclk_rate_code; > }; > > static const int cdns_ti_rate_table[] = { /* in KHZ */ > @@ -90,10 +91,8 @@ static int cdns_ti_probe(struct platform_device *pdev) > struct device *dev = &pdev->dev; > struct device_node *node = pdev->dev.of_node; > struct cdns_ti *data; > - int error; > - u32 reg; > - int rate_code, i; > unsigned long rate; > + int error, i; > > data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); > if (!data) > @@ -133,7 +132,9 @@ static int cdns_ti_probe(struct platform_device *pdev) > return -EINVAL; > } > > - rate_code = i; > + data->usb2_refclk_rate_code = i; > + data->vbus_divider = device_property_read_bool(dev, "ti,vbus-divider"); > + data->usb2_only = device_property_read_bool(dev, "ti,usb2-only"); > > pm_runtime_enable(dev); > error = pm_runtime_get_sync(dev); > @@ -142,40 +143,6 @@ static int cdns_ti_probe(struct platform_device *pdev) > goto err; > } > > - /* assert RESET */ > - reg = cdns_ti_readl(data, USBSS_W1); > - reg &= ~USBSS_W1_PWRUP_RST; > - cdns_ti_writel(data, USBSS_W1, reg); > - > - /* set static config */ > - reg = cdns_ti_readl(data, USBSS_STATIC_CONFIG); > - reg &= ~USBSS1_STATIC_PLL_REF_SEL_MASK; > - reg |= rate_code << USBSS1_STATIC_PLL_REF_SEL_SHIFT; > - > - reg &= ~USBSS1_STATIC_VBUS_SEL_MASK; > - data->vbus_divider = device_property_read_bool(dev, "ti,vbus-divider"); > - if (data->vbus_divider) > - reg |= 1 << USBSS1_STATIC_VBUS_SEL_SHIFT; > - > - cdns_ti_writel(data, USBSS_STATIC_CONFIG, reg); > - reg = cdns_ti_readl(data, USBSS_STATIC_CONFIG); > - > - /* set USB2_ONLY mode if requested */ > - reg = cdns_ti_readl(data, USBSS_W1); > - data->usb2_only = device_property_read_bool(dev, "ti,usb2-only"); > - if (data->usb2_only) > - reg |= USBSS_W1_USB2_ONLY; > - > - /* set default modestrap */ > - reg |= USBSS_W1_MODESTRAP_SEL; > - reg &= ~USBSS_W1_MODESTRAP_MASK; > - reg |= USBSS_MODESTRAP_MODE_NONE << USBSS_W1_MODESTRAP_SHIFT; > - cdns_ti_writel(data, USBSS_W1, reg); > - > - /* de-assert RESET */ > - reg |= USBSS_W1_PWRUP_RST; > - cdns_ti_writel(data, USBSS_W1, reg); > - > error = of_platform_populate(node, NULL, NULL, dev); > if (error) { > dev_err(dev, "failed to create children: %d\n", error); > @@ -211,6 +178,52 @@ static void cdns_ti_remove(struct platform_device *pdev) > platform_set_drvdata(pdev, NULL); > } > > +static int cdns_ti_runtime_resume(struct device *dev) > +{ > + struct cdns_ti *data = dev_get_drvdata(dev); > + u32 reg; > + > + /* assert RESET */ > + reg = cdns_ti_readl(data, USBSS_W1); > + reg &= ~USBSS_W1_PWRUP_RST; > + cdns_ti_writel(data, USBSS_W1, reg); > + > + /* set static config */ > + reg = cdns_ti_readl(data, USBSS_STATIC_CONFIG); > + reg &= ~USBSS1_STATIC_PLL_REF_SEL_MASK; > + reg |= data->usb2_refclk_rate_code << USBSS1_STATIC_PLL_REF_SEL_SHIFT; > + > + reg &= ~USBSS1_STATIC_VBUS_SEL_MASK; > + > + if (data->vbus_divider) > + reg |= 1 << USBSS1_STATIC_VBUS_SEL_SHIFT; > + > + cdns_ti_writel(data, USBSS_STATIC_CONFIG, reg); > + reg = cdns_ti_readl(data, USBSS_STATIC_CONFIG); > + > + /* set USB2_ONLY mode if requested */ > + reg = cdns_ti_readl(data, USBSS_W1); > + > + if (data->usb2_only) > + reg |= USBSS_W1_USB2_ONLY; > + > + /* set default modestrap */ > + reg |= USBSS_W1_MODESTRAP_SEL; > + reg &= ~USBSS_W1_MODESTRAP_MASK; > + reg |= USBSS_MODESTRAP_MODE_NONE << USBSS_W1_MODESTRAP_SHIFT; > + cdns_ti_writel(data, USBSS_W1, reg); > + > + /* de-assert RESET */ > + reg |= USBSS_W1_PWRUP_RST; > + cdns_ti_writel(data, USBSS_W1, reg); I don't think USB controller requires a reset and re-init between runtime suspend/resume. What you need is reset/re-init during system Resume on certain platforms. So you should move this part of code into a helper function and call it from .probe() and .system_resume() > + > + return 0; > +} > + > +static const struct dev_pm_ops cdns_ti_pm_ops = { > + RUNTIME_PM_OPS(NULL, cdns_ti_runtime_resume, NULL) > +}; > + > static const struct of_device_id cdns_ti_of_match[] = { > { .compatible = "ti,j721e-usb", }, > { .compatible = "ti,am64-usb", }, > @@ -224,6 +237,7 @@ static struct platform_driver cdns_ti_driver = { > .driver = { > .name = "cdns3-ti", > .of_match_table = cdns_ti_of_match, > + .pm = pm_ptr(&cdns_ti_pm_ops), > }, > }; > >
On 07/03/2024 11:55, Théo Lebrun wrote: > Add match data support, with one boolean to indicate whether the > hardware resets after a system-wide suspend. If hardware resets, we > force execute ->runtime_resume() at system-wide resume to run the > hardware init sequence. > > No compatible exploits this functionality, just yet. > > Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com> > --- > drivers/usb/cdns3/cdns3-ti.c | 27 +++++++++++++++++++++++++++ > 1 file changed, 27 insertions(+) > > diff --git a/drivers/usb/cdns3/cdns3-ti.c b/drivers/usb/cdns3/cdns3-ti.c > index 4c8a557e6a6f..f76327566798 100644 > --- a/drivers/usb/cdns3/cdns3-ti.c > +++ b/drivers/usb/cdns3/cdns3-ti.c > @@ -57,9 +57,14 @@ struct cdns_ti { > unsigned vbus_divider:1; > struct clk *usb2_refclk; > struct clk *lpm_clk; > + const struct cdns_ti_match_data *match_data; > int usb2_refclk_rate_code; > }; > > +struct cdns_ti_match_data { > + bool reset_on_resume; > +}; > + > static const int cdns_ti_rate_table[] = { /* in KHZ */ > 9600, > 10000, > @@ -101,6 +106,7 @@ static int cdns_ti_probe(struct platform_device *pdev) > platform_set_drvdata(pdev, data); > > data->dev = dev; > + data->match_data = device_get_match_data(dev); > > data->usbss = devm_platform_ioremap_resource(pdev, 0); > if (IS_ERR(data->usbss)) { > @@ -220,8 +226,29 @@ static int cdns_ti_runtime_resume(struct device *dev) > return 0; > } > > +static int cdns_ti_suspend(struct device *dev) > +{ > + struct cdns_ti *data = dev_get_drvdata(dev); > + > + if (data->match_data && data->match_data->reset_on_resume) > + return pm_runtime_force_suspend(dev); > + else > + return 0; > +} > + > +static int cdns_ti_resume(struct device *dev) > +{ > + struct cdns_ti *data = dev_get_drvdata(dev); > + Instead of this just do Reset and re-init here on affected platforms. This is after you remove reset/re-init code from .runtime_resume(). > + if (data->match_data && data->match_data->reset_on_resume) > + return pm_runtime_force_resume(dev); > + else > + return 0; > +} > + > static const struct dev_pm_ops cdns_ti_pm_ops = { > RUNTIME_PM_OPS(NULL, cdns_ti_runtime_resume, NULL) > + SYSTEM_SLEEP_PM_OPS(cdns_ti_suspend, cdns_ti_resume) > }; > > static const struct of_device_id cdns_ti_of_match[] = { >
On 07/03/2024 11:55, Théo Lebrun wrote: > Allow compatible to pick auxdata given to child platform devices. > > No compatible exploits this functionality, just yet. > This patch could be merged with Patch 7 so we know exactly how auxdata is used? > Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com> > --- > drivers/usb/cdns3/cdns3-ti.c | 8 ++++++-- > 1 file changed, 6 insertions(+), 2 deletions(-) > > diff --git a/drivers/usb/cdns3/cdns3-ti.c b/drivers/usb/cdns3/cdns3-ti.c > index f76327566798..29fb24c811b3 100644 > --- a/drivers/usb/cdns3/cdns3-ti.c > +++ b/drivers/usb/cdns3/cdns3-ti.c > @@ -62,7 +62,8 @@ struct cdns_ti { > }; > > struct cdns_ti_match_data { > - bool reset_on_resume; > + bool reset_on_resume; > + const struct of_dev_auxdata *auxdata; > }; > > static const int cdns_ti_rate_table[] = { /* in KHZ */ > @@ -95,6 +96,7 @@ static int cdns_ti_probe(struct platform_device *pdev) > { > struct device *dev = &pdev->dev; > struct device_node *node = pdev->dev.of_node; > + const struct of_dev_auxdata *auxdata = NULL; > struct cdns_ti *data; > unsigned long rate; > int error, i; > @@ -149,7 +151,9 @@ static int cdns_ti_probe(struct platform_device *pdev) > goto err; > } > > - error = of_platform_populate(node, NULL, NULL, dev); > + if (data->match_data) > + auxdata = data->match_data->auxdata; > + error = of_platform_populate(node, NULL, auxdata, dev); > if (error) { > dev_err(dev, "failed to create children: %d\n", error); > goto err; >
Hello Roger, On Thu Mar 7, 2024 at 1:31 PM CET, Roger Quadros wrote: > Hi, > > On 07/03/2024 11:55, Théo Lebrun wrote: > > The hardware initialisation register write sequence is only used at > > probe. Move it from being done at explicitely at probe to being done > > implicitely by pm_runtime_get_sync() that calls ->runtime_resume(). > > explicitly / implicitly > > > > > Keep devicetree parsing in probe and add a new field in the private > > struct to remember the USB2 refclk rate code computation result. > > > > This opens the door to having the init sequence being executed later > > down the road, at system-wide resume for example. This is NOT currently > > happening because runtime PM is disabled at suspend without the > > refcount being affected. > > > > Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com> > > --- > > drivers/usb/cdns3/cdns3-ti.c | 90 +++++++++++++++++++++++++------------------- > > 1 file changed, 52 insertions(+), 38 deletions(-) > > > > diff --git a/drivers/usb/cdns3/cdns3-ti.c b/drivers/usb/cdns3/cdns3-ti.c > > index 5945c4b1e11f..4c8a557e6a6f 100644 > > --- a/drivers/usb/cdns3/cdns3-ti.c > > +++ b/drivers/usb/cdns3/cdns3-ti.c > > @@ -57,6 +57,7 @@ struct cdns_ti { > > unsigned vbus_divider:1; > > struct clk *usb2_refclk; > > struct clk *lpm_clk; > > + int usb2_refclk_rate_code; > > }; > > > > static const int cdns_ti_rate_table[] = { /* in KHZ */ > > @@ -90,10 +91,8 @@ static int cdns_ti_probe(struct platform_device *pdev) > > struct device *dev = &pdev->dev; > > struct device_node *node = pdev->dev.of_node; > > struct cdns_ti *data; > > - int error; > > - u32 reg; > > - int rate_code, i; > > unsigned long rate; > > + int error, i; > > > > data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); > > if (!data) > > @@ -133,7 +132,9 @@ static int cdns_ti_probe(struct platform_device *pdev) > > return -EINVAL; > > } > > > > - rate_code = i; > > + data->usb2_refclk_rate_code = i; > > + data->vbus_divider = device_property_read_bool(dev, "ti,vbus-divider"); > > + data->usb2_only = device_property_read_bool(dev, "ti,usb2-only"); > > > > pm_runtime_enable(dev); > > error = pm_runtime_get_sync(dev); > > @@ -142,40 +143,6 @@ static int cdns_ti_probe(struct platform_device *pdev) > > goto err; > > } > > > > - /* assert RESET */ > > - reg = cdns_ti_readl(data, USBSS_W1); > > - reg &= ~USBSS_W1_PWRUP_RST; > > - cdns_ti_writel(data, USBSS_W1, reg); > > - > > - /* set static config */ > > - reg = cdns_ti_readl(data, USBSS_STATIC_CONFIG); > > - reg &= ~USBSS1_STATIC_PLL_REF_SEL_MASK; > > - reg |= rate_code << USBSS1_STATIC_PLL_REF_SEL_SHIFT; > > - > > - reg &= ~USBSS1_STATIC_VBUS_SEL_MASK; > > - data->vbus_divider = device_property_read_bool(dev, "ti,vbus-divider"); > > - if (data->vbus_divider) > > - reg |= 1 << USBSS1_STATIC_VBUS_SEL_SHIFT; > > - > > - cdns_ti_writel(data, USBSS_STATIC_CONFIG, reg); > > - reg = cdns_ti_readl(data, USBSS_STATIC_CONFIG); > > - > > - /* set USB2_ONLY mode if requested */ > > - reg = cdns_ti_readl(data, USBSS_W1); > > - data->usb2_only = device_property_read_bool(dev, "ti,usb2-only"); > > - if (data->usb2_only) > > - reg |= USBSS_W1_USB2_ONLY; > > - > > - /* set default modestrap */ > > - reg |= USBSS_W1_MODESTRAP_SEL; > > - reg &= ~USBSS_W1_MODESTRAP_MASK; > > - reg |= USBSS_MODESTRAP_MODE_NONE << USBSS_W1_MODESTRAP_SHIFT; > > - cdns_ti_writel(data, USBSS_W1, reg); > > - > > - /* de-assert RESET */ > > - reg |= USBSS_W1_PWRUP_RST; > > - cdns_ti_writel(data, USBSS_W1, reg); > > - > > error = of_platform_populate(node, NULL, NULL, dev); > > if (error) { > > dev_err(dev, "failed to create children: %d\n", error); > > @@ -211,6 +178,52 @@ static void cdns_ti_remove(struct platform_device *pdev) > > platform_set_drvdata(pdev, NULL); > > } > > > > +static int cdns_ti_runtime_resume(struct device *dev) > > +{ > > + struct cdns_ti *data = dev_get_drvdata(dev); > > + u32 reg; > > + > > + /* assert RESET */ > > + reg = cdns_ti_readl(data, USBSS_W1); > > + reg &= ~USBSS_W1_PWRUP_RST; > > + cdns_ti_writel(data, USBSS_W1, reg); > > + > > + /* set static config */ > > + reg = cdns_ti_readl(data, USBSS_STATIC_CONFIG); > > + reg &= ~USBSS1_STATIC_PLL_REF_SEL_MASK; > > + reg |= data->usb2_refclk_rate_code << USBSS1_STATIC_PLL_REF_SEL_SHIFT; > > + > > + reg &= ~USBSS1_STATIC_VBUS_SEL_MASK; > > + > > + if (data->vbus_divider) > > + reg |= 1 << USBSS1_STATIC_VBUS_SEL_SHIFT; > > + > > + cdns_ti_writel(data, USBSS_STATIC_CONFIG, reg); > > + reg = cdns_ti_readl(data, USBSS_STATIC_CONFIG); > > + > > + /* set USB2_ONLY mode if requested */ > > + reg = cdns_ti_readl(data, USBSS_W1); > > + > > + if (data->usb2_only) > > + reg |= USBSS_W1_USB2_ONLY; > > + > > + /* set default modestrap */ > > + reg |= USBSS_W1_MODESTRAP_SEL; > > + reg &= ~USBSS_W1_MODESTRAP_MASK; > > + reg |= USBSS_MODESTRAP_MODE_NONE << USBSS_W1_MODESTRAP_SHIFT; > > + cdns_ti_writel(data, USBSS_W1, reg); > > + > > + /* de-assert RESET */ > > + reg |= USBSS_W1_PWRUP_RST; > > + cdns_ti_writel(data, USBSS_W1, reg); > > I don't think USB controller requires a reset and re-init between > runtime suspend/resume. > > What you need is reset/re-init during system Resume on certain platforms. > So you should move this part of code into a helper function and call it > from .probe() and .system_resume() Runtime resume is being called at probe() and system-wide resume. See our runtime_resume() implementation as that helper function you are describing. A previous revision did what you are recommending. We leaned towards the current version. See: https://lore.kernel.org/lkml/7h34wxfmwn.fsf@baylibre.com/ Also, assuming we enable runtime PM, a reset and re-init after runtime suspend would be the right thing to do anyways. My reading of drivers/pmdomain/core.c tells me that if our device goes to runtime suspend, domains will be shut down. Our controller will be reset and we'll need to re-init it. The GENPD_FLAG_RPM_ALWAYS_ON flag is of interest to avoid the PD to be shut down during runtime PM. Regards, -- Théo Lebrun, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Hello, On Thu Mar 7, 2024 at 1:38 PM CET, Roger Quadros wrote: > > > On 07/03/2024 11:55, Théo Lebrun wrote: > > Allow compatible to pick auxdata given to child platform devices. > > > > No compatible exploits this functionality, just yet. > > > > This patch could be merged with Patch 7 so we know exactly how auxdata > is used? Indeed. I liked splitting. Previous revision had it as a single patch. I can revert. Regards, -- Théo Lebrun, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Théo Lebrun <theo.lebrun@bootlin.com> writes: > Add match data support, with one boolean to indicate whether the > hardware resets after a system-wide suspend. If hardware resets, we > force execute ->runtime_resume() at system-wide resume to run the > hardware init sequence. Is "whether the hardware resets after a system-wide suspend" really a function of the IP itself, or rather whether the IP is in a power domain that might power down? > No compatible exploits this functionality, just yet. > > Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com> > --- > drivers/usb/cdns3/cdns3-ti.c | 27 +++++++++++++++++++++++++++ > 1 file changed, 27 insertions(+) > > diff --git a/drivers/usb/cdns3/cdns3-ti.c b/drivers/usb/cdns3/cdns3-ti.c > index 4c8a557e6a6f..f76327566798 100644 > --- a/drivers/usb/cdns3/cdns3-ti.c > +++ b/drivers/usb/cdns3/cdns3-ti.c > @@ -57,9 +57,14 @@ struct cdns_ti { > unsigned vbus_divider:1; > struct clk *usb2_refclk; > struct clk *lpm_clk; > + const struct cdns_ti_match_data *match_data; > int usb2_refclk_rate_code; > }; > > +struct cdns_ti_match_data { > + bool reset_on_resume; > +}; > + > static const int cdns_ti_rate_table[] = { /* in KHZ */ > 9600, > 10000, > @@ -101,6 +106,7 @@ static int cdns_ti_probe(struct platform_device *pdev) > platform_set_drvdata(pdev, data); > > data->dev = dev; > + data->match_data = device_get_match_data(dev); > > data->usbss = devm_platform_ioremap_resource(pdev, 0); > if (IS_ERR(data->usbss)) { > @@ -220,8 +226,29 @@ static int cdns_ti_runtime_resume(struct device *dev) > return 0; > } > > +static int cdns_ti_suspend(struct device *dev) > +{ > + struct cdns_ti *data = dev_get_drvdata(dev); > + > + if (data->match_data && data->match_data->reset_on_resume) > + return pm_runtime_force_suspend(dev); > + else > + return 0; > +} > + > +static int cdns_ti_resume(struct device *dev) > +{ > + struct cdns_ti *data = dev_get_drvdata(dev); > + > + if (data->match_data && data->match_data->reset_on_resume) > + return pm_runtime_force_resume(dev); > + else > + return 0; > +} Conditionally forcing runtime suspend/resume based on a property of the IP doesn't feel right to me. IMO, the device should always runtime suspend/resume, and in the runtime PM hooks is where the conditional logic should be. And speaking of the conditional logic... let's go back to whether "resets_on_resume" is a property of the IP or the enclosing power domain. Instead of having an IP-specific flag, another way of approaching this when ->runtime_resume() is called every time is simply for that hook to check if a reset has happend. Sometimes you can tell this simply by reading a register that has been previously programmed by the driver but has a known reset. Simply check that regisister and you can tell whether context has been lost. Doing it this way makes the driver "smart" and then you don't have to rely on bool flag based on the IP and dependent on the DT compatible. Kevin
Hello, On Fri Mar 8, 2024 at 10:58 PM CET, Kevin Hilman wrote: > Théo Lebrun <theo.lebrun@bootlin.com> writes: > > Add match data support, with one boolean to indicate whether the > > hardware resets after a system-wide suspend. If hardware resets, we > > force execute ->runtime_resume() at system-wide resume to run the > > hardware init sequence. > > Is "whether the hardware resets after a system-wide suspend" really a > function of the IP itself, or rather whether the IP is in a power domain > that might power down? Is a compatible defining (1) the IP block involved or (2) the IP block involved and its integration? This is a rethorical question, I've asked it internally at Bootlin and we had some interesting discussions. :-) Whether compatible or some other mechanism indicate expected suspend behavior, we agreed that suspend types where not modeled properly by the kernel currently. > > No compatible exploits this functionality, just yet. > > > > Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com> > > --- > > drivers/usb/cdns3/cdns3-ti.c | 27 +++++++++++++++++++++++++++ > > 1 file changed, 27 insertions(+) > > > > diff --git a/drivers/usb/cdns3/cdns3-ti.c b/drivers/usb/cdns3/cdns3-ti.c > > index 4c8a557e6a6f..f76327566798 100644 > > --- a/drivers/usb/cdns3/cdns3-ti.c > > +++ b/drivers/usb/cdns3/cdns3-ti.c > > @@ -57,9 +57,14 @@ struct cdns_ti { > > unsigned vbus_divider:1; > > struct clk *usb2_refclk; > > struct clk *lpm_clk; > > + const struct cdns_ti_match_data *match_data; > > int usb2_refclk_rate_code; > > }; > > > > +struct cdns_ti_match_data { > > + bool reset_on_resume; > > +}; > > + > > static const int cdns_ti_rate_table[] = { /* in KHZ */ > > 9600, > > 10000, > > @@ -101,6 +106,7 @@ static int cdns_ti_probe(struct platform_device *pdev) > > platform_set_drvdata(pdev, data); > > > > data->dev = dev; > > + data->match_data = device_get_match_data(dev); > > > > data->usbss = devm_platform_ioremap_resource(pdev, 0); > > if (IS_ERR(data->usbss)) { > > @@ -220,8 +226,29 @@ static int cdns_ti_runtime_resume(struct device *dev) > > return 0; > > } > > > > +static int cdns_ti_suspend(struct device *dev) > > +{ > > + struct cdns_ti *data = dev_get_drvdata(dev); > > + > > + if (data->match_data && data->match_data->reset_on_resume) > > + return pm_runtime_force_suspend(dev); > > + else > > + return 0; > > +} > > + > > +static int cdns_ti_resume(struct device *dev) > > +{ > > + struct cdns_ti *data = dev_get_drvdata(dev); > > + > > + if (data->match_data && data->match_data->reset_on_resume) > > + return pm_runtime_force_resume(dev); > > + else > > + return 0; > > +} > > Conditionally forcing runtime suspend/resume based on a property of the > IP doesn't feel right to me. > > IMO, the device should always runtime suspend/resume, and in the > runtime PM hooks is where the conditional logic should be. > > And speaking of the conditional logic... let's go back to whether > "resets_on_resume" is a property of the IP or the enclosing power > domain. > > Instead of having an IP-specific flag, another way of approaching this > when ->runtime_resume() is called every time is simply for that hook to > check if a reset has happend. Sometimes you can tell this simply by > reading a register that has been previously programmed by the driver but > has a known reset. Simply check that regisister and you can tell > whether context has been lost. > > Doing it this way makes the driver "smart" and then you don't have to > rely on bool flag based on the IP and dependent on the DT compatible. I agree! I never digged into this for a reason: the HXCI subsystem takes a quirk flag that tells it whether it resets on resume (XHCI_RESET_ON_RESUME). My plans weren't grandiose enough to think about touching this aspect. That means we need to know this bool value at probe. About a smart ->runtime_resume() implementation: it is doable. I've experimented with that following your message. The condition is rather simple, looking like: static int cdns_ti_runtime_resume(struct device *dev) { struct cdns_ti *data = dev_get_drvdata(dev); u32 w1, mask; w1 = cdns_ti_readl(data, USBSS_W1); mask = USBSS_W1_PWRUP_RST | USBSS_W1_MODESTRAP_SEL; if ((w1 & mask) != mask) cdns_ti_reset_and_init_hw(dev, data); return 0; } Tested on J7200-EVM, works as expected. Both bits reset to zero. First is software reset; second is described as "this bit has to be always set to 1". cdns_ti_reset_and_init_hw() would also be call at probe before enabling runtime PM to ensure we always reset the IP at probe. Then ->runtime_resume() would get called once during probe without any impact as the conditional would return false. It would trigger at resume. System-wide suspend/resume hooks would become: SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, pm_runtime_force_resume) Do you have any ideas related to the handling of XHCI_RESET_ON_RESUME? See xhci_resume(). Some notes: - XHCI is capable of detect what it calls reinit (reset after resume). The flags only shortcut the restore attempt (which is useless when the controller reset) and disables warning because of reinit. Logs contain this when we do not pass the flag: [ 18.518138] xhci-hcd xhci-hcd.11.auto: xHC error in resume, USBSTS 0x401, Reinit [ 18.525522] usb usb1: root hub lost power or was reset [ 18.530647] usb usb2: root hub lost power or was reset - Ways forward I can imagine: - A quick and dirty solution would be to grab a reference to the xhci_hcd struct pointer from TI wrapper and update quirks on the go. - Another one would be to keep as-is and let xhci-hcd warn on each resume. Mentioning this for exhaustiveness. - Introduce a new mechanism to communicate through the stack: from the TI wrapper, to cdns3 core, to the xhci-hcd device. Or use an existing mechanism if one is present. - Remove the assumption xHCI does that a suspend is broken if the controller was reset during it. That doesn't sound right to me, can you confirm? Thanks! -- Théo Lebrun, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Hi, Here is a new revision of the J7200 USB suspend fix. It is currently broken on the platform, leading to a kernel panic at resume. Patches are tested on a J7200 evaluation board, both s2idle and suspend-to-RAM. This revision only changes dt-bindings and DTS stuff. We fix the current situation (as discussed previously [0]) and add our J7200 compatible. Have a nice day, Théo [0]: https://lore.kernel.org/lkml/20240223-j7200-usb-suspend-v3-1-b41c9893a130@bootlin.com/ -- Théo Lebrun, Bootlin Embedded Linux and Kernel engineering https://bootlin.com Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com> --- Changes in v4: - dt-bindings: usb: ti,j721e-usb: - Remove ti,am64-usb single compatible entry. - Reverse ordering of compatible pair j721e + am64 (becoming am64 + j721e). - Add j7200 + j721e compatible pair (versus only j7200). It is the same thing as am64: only the integration differs with base j721e compatible. - NOT taking trailers from Conor as patches changed substantially. - arm64: dts: ti: j3-j7200: - Use j7200 + j721e compatible pair (versus only j7200 previously). - arm64: dts: ti: j3-am64: - Fix to use am64 + j721e compatible pair (versus only am64). This is a new patch. - Link to v3: https://lore.kernel.org/r/20240223-j7200-usb-suspend-v3-0-b41c9893a130@bootlin.com Changes in v3: - dt-bindings: use an enum to list compatibles instead of the previous odd construct. This is done in a separate patch from the one adding J7200 compatible. - dt-bindings: dropped Acked-by Conor as the changes were modified a lot. - Add runtime PM back. Put the init sequence in ->runtime_resume(). It gets called at probe for all compatibles and at resume for J7200. - Introduce a cdns_ti_match_data struct rather than rely on compatible from code. - Reorder code changes. Add infrastructure based on match data THEN add compatible and its match data. - DTSI: use only J7200 compatible rather than both J7200 then J721E. - Link to v2: https://lore.kernel.org/r/20231120-j7200-usb-suspend-v2-0-038c7e4a3df4@bootlin.com Changes in v2: - Remove runtime PM from cdns3-ti; it brings nothing. That means our cdns3-ti suspend/resume patch is simpler; there is no need to handle runtime PM at suspend/resume. - Do not add cdns3 host role suspend/resume callbacks; they are not needed as core detects reset on resume & calls cdns_drd_host_on when needed. - cdns3-ti: Move usb2_refclk_rate_code assignment closer to the value computation. - cdns3/host.c: do not pass XHCI_SUSPEND_RESUME_CLKS quirk to xHCI; it is unneeded on our platform. - Link to v1: https://lore.kernel.org/r/20231113-j7200-usb-suspend-v1-0-ad1ee714835c@bootlin.com --- Théo Lebrun (9): dt-bindings: usb: ti,j721e-usb: fix compatible list dt-bindings: usb: ti,j721e-usb: add ti,j7200-usb compatible usb: cdns3-ti: move reg writes from probe into ->runtime_resume() usb: cdns3-ti: support reset-on-resume behavior usb: cdns3-ti: pass auxdata from match data to of_platform_populate() usb: cdns3: add quirk to platform data for reset-on-resume usb: cdns3-ti: add J7200 support with reset-on-resume behavior arm64: dts: ti: k3-j7200: use J7200-specific USB compatible arm64: dts: ti: k3-am64: add USB fallback compatible to J721E .../devicetree/bindings/usb/ti,j721e-usb.yaml | 6 +- arch/arm64/boot/dts/ti/k3-am64-main.dtsi | 2 +- arch/arm64/boot/dts/ti/k3-j7200-main.dtsi | 2 +- drivers/usb/cdns3/cdns3-ti.c | 125 ++++++++++++++++----- drivers/usb/cdns3/core.h | 1 + drivers/usb/cdns3/host.c | 3 + 6 files changed, 105 insertions(+), 34 deletions(-) --- base-commit: 1871c27e3539e5b812d50ec6ccad7567ec5414f2 change-id: 20231113-j7200-usb-suspend-2a47f2281e04 Best regards,