summaryrefslogtreecommitdiff
path: root/drivers/usb/dwc3/dwc3-xilinx.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/dwc3/dwc3-xilinx.c')
-rw-r--r--drivers/usb/dwc3/dwc3-xilinx.c123
1 files changed, 100 insertions, 23 deletions
diff --git a/drivers/usb/dwc3/dwc3-xilinx.c b/drivers/usb/dwc3/dwc3-xilinx.c
index c9fb8c259493..095bc3dde0fa 100644
--- a/drivers/usb/dwc3/dwc3-xilinx.c
+++ b/drivers/usb/dwc3/dwc3-xilinx.c
@@ -48,6 +48,9 @@ struct dwc3_xlnx {
void __iomem *regs;
int (*pltfm_init)(struct dwc3_xlnx *data);
struct phy *usb3_phy;
+ struct reset_control *usb_crst;
+ struct reset_control *usb_hibrst;
+ struct reset_control *usb_apbrst;
};
static void dwc3_xlnx_mask_phy_rst(struct dwc3_xlnx *priv_data, bool mask)
@@ -109,10 +112,42 @@ static int dwc3_xlnx_init_versal(struct dwc3_xlnx *priv_data)
return 0;
}
+static void dwc3_xlnx_zynqmp_teardown(void *data)
+{
+ struct dwc3_xlnx *priv_data = data;
+
+ phy_power_off(priv_data->usb3_phy);
+
+ /*
+ * Undo only the reset cycle init performed. As on the init error
+ * path, the unconditional deasserts are not paired with an assert
+ * here: with no usb3-phy, resetting the core could break a USB3
+ * configuration that is live but missing from the device tree.
+ */
+ if (priv_data->usb3_phy) {
+ reset_control_assert(priv_data->usb_hibrst);
+ reset_control_assert(priv_data->usb_crst);
+ reset_control_assert(priv_data->usb_apbrst);
+ }
+
+ phy_exit(priv_data->usb3_phy);
+}
+
+/*
+ * Run the platform teardown explicitly, so the resets are asserted while the
+ * clocks are still running. devm_release_action() unlinks the action before
+ * calling it, so devres will not run it a second time.
+ */
+static void dwc3_xlnx_release_teardown(struct device *dev,
+ struct dwc3_xlnx *priv_data)
+{
+ if (devm_is_action_added(dev, dwc3_xlnx_zynqmp_teardown, priv_data))
+ devm_release_action(dev, dwc3_xlnx_zynqmp_teardown, priv_data);
+}
+
static int dwc3_xlnx_init_zynqmp(struct dwc3_xlnx *priv_data)
{
struct device *dev = priv_data->dev;
- struct reset_control *crst, *hibrst, *apbrst;
struct gpio_desc *reset_gpio;
int ret = 0;
@@ -124,25 +159,25 @@ static int dwc3_xlnx_init_zynqmp(struct dwc3_xlnx *priv_data)
goto err;
}
- crst = devm_reset_control_get_exclusive(dev, "usb_crst");
- if (IS_ERR(crst)) {
- ret = PTR_ERR(crst);
+ priv_data->usb_crst = devm_reset_control_get_exclusive(dev, "usb_crst");
+ if (IS_ERR(priv_data->usb_crst)) {
+ ret = PTR_ERR(priv_data->usb_crst);
dev_err_probe(dev, ret,
"failed to get core reset signal\n");
goto err;
}
- hibrst = devm_reset_control_get_exclusive(dev, "usb_hibrst");
- if (IS_ERR(hibrst)) {
- ret = PTR_ERR(hibrst);
+ priv_data->usb_hibrst = devm_reset_control_get_exclusive(dev, "usb_hibrst");
+ if (IS_ERR(priv_data->usb_hibrst)) {
+ ret = PTR_ERR(priv_data->usb_hibrst);
dev_err_probe(dev, ret,
"failed to get hibernation reset signal\n");
goto err;
}
- apbrst = devm_reset_control_get_exclusive(dev, "usb_apbrst");
- if (IS_ERR(apbrst)) {
- ret = PTR_ERR(apbrst);
+ priv_data->usb_apbrst = devm_reset_control_get_exclusive(dev, "usb_apbrst");
+ if (IS_ERR(priv_data->usb_apbrst)) {
+ ret = PTR_ERR(priv_data->usb_apbrst);
dev_err_probe(dev, ret,
"failed to get APB reset signal\n");
goto err;
@@ -156,19 +191,19 @@ static int dwc3_xlnx_init_zynqmp(struct dwc3_xlnx *priv_data)
* absent.
*/
if (priv_data->usb3_phy) {
- ret = reset_control_assert(crst);
+ ret = reset_control_assert(priv_data->usb_crst);
if (ret < 0) {
dev_err(dev, "Failed to assert core reset\n");
goto err;
}
- ret = reset_control_assert(hibrst);
+ ret = reset_control_assert(priv_data->usb_hibrst);
if (ret < 0) {
dev_err(dev, "Failed to assert hibernation reset\n");
goto err;
}
- ret = reset_control_assert(apbrst);
+ ret = reset_control_assert(priv_data->usb_apbrst);
if (ret < 0) {
dev_err(dev, "Failed to assert APB reset\n");
goto err;
@@ -179,7 +214,7 @@ static int dwc3_xlnx_init_zynqmp(struct dwc3_xlnx *priv_data)
if (ret < 0)
goto err;
- ret = reset_control_deassert(apbrst);
+ ret = reset_control_deassert(priv_data->usb_apbrst);
if (ret < 0) {
dev_err(dev, "Failed to release APB reset\n");
goto err_phy_exit;
@@ -195,21 +230,21 @@ static int dwc3_xlnx_init_zynqmp(struct dwc3_xlnx *priv_data)
writel(PIPE_CLK_DESELECT, priv_data->regs + XLNX_USB_FPD_PIPE_CLK);
}
- ret = reset_control_deassert(crst);
+ ret = reset_control_deassert(priv_data->usb_crst);
if (ret < 0) {
dev_err(dev, "Failed to release core reset\n");
- goto err_phy_exit;
+ goto err_reset_assert;
}
- ret = reset_control_deassert(hibrst);
+ ret = reset_control_deassert(priv_data->usb_hibrst);
if (ret < 0) {
dev_err(dev, "Failed to release hibernation reset\n");
- goto err_phy_exit;
+ goto err_reset_assert;
}
ret = phy_power_on(priv_data->usb3_phy);
if (ret < 0)
- goto err_phy_exit;
+ goto err_reset_assert;
/* ulpi reset via gpio-modepin or gpio-framework driver */
reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
@@ -226,10 +261,26 @@ static int dwc3_xlnx_init_zynqmp(struct dwc3_xlnx *priv_data)
dwc3_xlnx_set_coherency(priv_data, XLNX_USB_TRAFFIC_ROUTE_CONFIG);
- return 0;
+ return devm_add_action_or_reset(dev, dwc3_xlnx_zynqmp_teardown,
+ priv_data);
err_phy_power_off:
phy_power_off(priv_data->usb3_phy);
+err_reset_assert:
+ /*
+ * Undo only the reset cycle performed above. That cycle is skipped
+ * when there is no usb3-phy. The deasserts stay unconditional so a
+ * core the bootloader left in reset still comes up, but they are
+ * deliberately not paired with an assert here: resetting a USB3
+ * configuration that is live but missing from the device tree could
+ * break it. Asserting an already asserted reset is harmless, so one
+ * block covers however far the cycle's deasserts got.
+ */
+ if (priv_data->usb3_phy) {
+ reset_control_assert(priv_data->usb_hibrst);
+ reset_control_assert(priv_data->usb_crst);
+ reset_control_assert(priv_data->usb_apbrst);
+ }
err_phy_exit:
phy_exit(priv_data->usb3_phy);
err:
@@ -338,6 +389,7 @@ err_pm_set_suspended:
pm_runtime_set_suspended(dev);
err_clk_put:
+ dwc3_xlnx_release_teardown(dev, priv_data);
clk_bulk_disable_unprepare(priv_data->num_clocks, priv_data->clks);
return ret;
@@ -350,6 +402,13 @@ static void dwc3_xlnx_remove(struct platform_device *pdev)
of_platform_depopulate(dev);
+ /*
+ * This is also what makes .shutdown behave the same as .remove:
+ * device_shutdown() does not call devres_release_all(), so a teardown
+ * left to devres would never run on the shutdown path.
+ */
+ dwc3_xlnx_release_teardown(dev, priv_data);
+
clk_bulk_disable_unprepare(priv_data->num_clocks, priv_data->clks);
priv_data->num_clocks = 0;
@@ -383,13 +442,26 @@ static int __maybe_unused dwc3_xlnx_runtime_idle(struct device *dev)
static int __maybe_unused dwc3_xlnx_suspend(struct device *dev)
{
struct dwc3_xlnx *priv_data = dev_get_drvdata(dev);
+ int ret;
- phy_exit(priv_data->usb3_phy);
+ ret = phy_power_off(priv_data->usb3_phy);
+ if (ret < 0)
+ return ret;
+
+ ret = phy_exit(priv_data->usb3_phy);
+ if (ret < 0)
+ goto err_phy_power_on;
/* Disable the clocks */
clk_bulk_disable(priv_data->num_clocks, priv_data->clks);
return 0;
+
+err_phy_power_on:
+ if (phy_power_on(priv_data->usb3_phy))
+ dev_err(dev, "failed to restore PHY power after suspend error\n");
+
+ return ret;
}
static int __maybe_unused dwc3_xlnx_resume(struct device *dev)
@@ -403,15 +475,20 @@ static int __maybe_unused dwc3_xlnx_resume(struct device *dev)
ret = phy_init(priv_data->usb3_phy);
if (ret < 0)
- return ret;
+ goto err_clk_disable;
ret = phy_power_on(priv_data->usb3_phy);
if (ret < 0) {
phy_exit(priv_data->usb3_phy);
- return ret;
+ goto err_clk_disable;
}
return 0;
+
+err_clk_disable:
+ clk_bulk_disable(priv_data->num_clocks, priv_data->clks);
+
+ return ret;
}
static const struct dev_pm_ops dwc3_xlnx_dev_pm_ops = {