[PATCH 05/13] usb: cdns3-ti: add suspend/resume procedures for J72=

From: =3D?UTF-8?q?Th=3DC3=3DA9o=3D20Lebrun?=3D
Date: Mon Nov 20 2023 - 10:47:29 EST


Hardware initialisation is only done at probe. The J7200 USB controller
is reset at resume because of power-domains toggling off & on. We
therefore reconfigure the hardware at resume.

Reuse the newly extracted cdns_ti_init_hw() function that contains the
register write sequence.

Only focus J7200 as other SoC are untested. If the controller does not
reset we do not want to redo reg writes.

Signed-off-by: Th=C3=A9o Lebrun <theo.lebrun@xxxxxxxxxxx>
---
drivers/usb/cdns3/cdns3-ti.c | 32 +++++++++++++++++++++++++++++++-
1 file changed, 31 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/cdns3/cdns3-ti.c b/drivers/usb/cdns3/cdns3-ti.c
index d4232b440e4e..7530b6b5159d 100644
--- a/drivers/usb/cdns3/cdns3-ti.c
+++ b/drivers/usb/cdns3/cdns3-ti.c
@@ -58,6 +58,11 @@ struct cdns_ti {
struct clk *usb2_refclk;
struct clk *lpm_clk;
int usb2_refclk_rate_code;
+ const struct cdns_ti_match_data *match_data;
+};
+
+struct cdns_ti_match_data {
+ bool reset_on_resume;
};

static const int cdns_ti_rate_table[] =3D { /* in KHZ */
@@ -138,6 +143,7 @@ static int cdns_ti_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, data);

data->dev =3D dev;
+ data->match_data =3D of_device_get_match_data(dev);

data->usbss =3D devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(data->usbss)) {
@@ -202,7 +208,30 @@ static void cdns_ti_remove(struct platform_device *pde=
v)
platform_set_drvdata(pdev, NULL);
}

+#ifdef CONFIG_PM
+
+static int cdns_ti_resume(struct device *dev)
+{
+ struct cdns_ti *data =3D dev_get_drvdata(dev);
+
+ if (data->match_data && data->match_data->reset_on_resume)
+ cdns_ti_init_hw(data);
+
+ return 0;
+}
+
+static const struct dev_pm_ops cdns_ti_pm_ops =3D {
+ SET_SYSTEM_SLEEP_PM_OPS(NULL, cdns_ti_resume)
+};
+
+#endif /* CONFIG_PM */
+
+static const struct cdns_ti_match_data cdns_ti_j7200_match_data =3D {
+ .reset_on_resume =3D true,
+};
+
static const struct of_device_id cdns_ti_of_match[] =3D {
+ { .compatible =3D "ti,j7200-usb", .data =3D &cdns_ti_j7200_match_data, }=
,
{ .compatible =3D "ti,j721e-usb", },
{ .compatible =3D "ti,am64-usb", },
{},
@@ -213,8 +242,9 @@ static struct platform_driver cdns_ti_driver =3D {
.probe =3D cdns_ti_probe,
.remove_new =3D cdns_ti_remove,
.driver =3D {
- .name =3D "cdns3-ti",
+ .name =3D "cdns3-ti",
.of_match_table =3D cdns_ti_of_match,
+ .pm =3D pm_ptr(&cdns_ti_pm_ops),
},
};

--
2.42.0


------------------------------------------------------------------------