2017-11-03 03:28:30 -07:00
|
|
|
// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
|
2013-04-22 14:00:19 -07:00
|
|
|
/*
|
|
|
|
* platform.c - DesignWare HS OTG Controller platform driver
|
|
|
|
*
|
|
|
|
* Copyright (C) Matthijs Kooijman <matthijs@stdin.nl>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/slab.h>
|
2015-10-13 23:52:29 -07:00
|
|
|
#include <linux/clk.h>
|
2013-04-22 14:00:19 -07:00
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/dma-mapping.h>
|
2023-07-18 07:30:23 -07:00
|
|
|
#include <linux/of.h>
|
2014-11-21 07:14:48 -07:00
|
|
|
#include <linux/mutex.h>
|
2013-04-22 14:00:19 -07:00
|
|
|
#include <linux/platform_device.h>
|
2015-10-13 23:52:29 -07:00
|
|
|
#include <linux/phy/phy.h>
|
|
|
|
#include <linux/platform_data/s3c-hsotg.h>
|
2016-08-10 06:53:34 -07:00
|
|
|
#include <linux/reset.h>
|
2013-04-22 14:00:19 -07:00
|
|
|
|
2014-08-05 18:01:50 -07:00
|
|
|
#include <linux/usb/of.h>
|
|
|
|
|
2013-04-22 14:00:19 -07:00
|
|
|
#include "core.h"
|
|
|
|
#include "hcd.h"
|
2015-04-29 13:08:59 -07:00
|
|
|
#include "debug.h"
|
2013-04-22 14:00:19 -07:00
|
|
|
|
|
|
|
static const char dwc2_driver_name[] = "dwc2";
|
|
|
|
|
2015-12-17 12:16:31 -07:00
|
|
|
/*
|
|
|
|
* Check the dr_mode against the module configuration and hardware
|
|
|
|
* capabilities.
|
|
|
|
*
|
|
|
|
* The hardware, module, and dr_mode, can each be set to host, device,
|
|
|
|
* or otg. Check that all these values are compatible and adjust the
|
|
|
|
* value of dr_mode if possible.
|
|
|
|
*
|
|
|
|
* actual
|
|
|
|
* HW MOD dr_mode dr_mode
|
|
|
|
* ------------------------------
|
|
|
|
* HST HST any : HST
|
|
|
|
* HST DEV any : ---
|
|
|
|
* HST OTG any : HST
|
|
|
|
*
|
|
|
|
* DEV HST any : ---
|
|
|
|
* DEV DEV any : DEV
|
|
|
|
* DEV OTG any : DEV
|
|
|
|
*
|
|
|
|
* OTG HST any : HST
|
|
|
|
* OTG DEV any : DEV
|
|
|
|
* OTG OTG any : dr_mode
|
|
|
|
*/
|
|
|
|
static int dwc2_get_dr_mode(struct dwc2_hsotg *hsotg)
|
|
|
|
{
|
|
|
|
enum usb_dr_mode mode;
|
|
|
|
|
|
|
|
hsotg->dr_mode = usb_get_dr_mode(hsotg->dev);
|
|
|
|
if (hsotg->dr_mode == USB_DR_MODE_UNKNOWN)
|
|
|
|
hsotg->dr_mode = USB_DR_MODE_OTG;
|
|
|
|
|
|
|
|
mode = hsotg->dr_mode;
|
|
|
|
|
|
|
|
if (dwc2_hw_is_device(hsotg)) {
|
|
|
|
if (IS_ENABLED(CONFIG_USB_DWC2_HOST)) {
|
|
|
|
dev_err(hsotg->dev,
|
|
|
|
"Controller does not support host mode.\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
mode = USB_DR_MODE_PERIPHERAL;
|
|
|
|
} else if (dwc2_hw_is_host(hsotg)) {
|
|
|
|
if (IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL)) {
|
|
|
|
dev_err(hsotg->dev,
|
|
|
|
"Controller does not support device mode.\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
mode = USB_DR_MODE_HOST;
|
|
|
|
} else {
|
|
|
|
if (IS_ENABLED(CONFIG_USB_DWC2_HOST))
|
|
|
|
mode = USB_DR_MODE_HOST;
|
|
|
|
else if (IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL))
|
|
|
|
mode = USB_DR_MODE_PERIPHERAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mode != hsotg->dr_mode) {
|
|
|
|
dev_warn(hsotg->dev,
|
2017-01-17 21:30:27 -07:00
|
|
|
"Configuration mismatch. dr_mode forced to %s\n",
|
2015-12-17 12:16:31 -07:00
|
|
|
mode == USB_DR_MODE_HOST ? "host" : "device");
|
|
|
|
|
|
|
|
hsotg->dr_mode = mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-10-13 23:52:29 -07:00
|
|
|
static int __dwc2_lowlevel_hw_enable(struct dwc2_hsotg *hsotg)
|
|
|
|
{
|
|
|
|
struct platform_device *pdev = to_platform_device(hsotg->dev);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = regulator_bulk_enable(ARRAY_SIZE(hsotg->supplies),
|
|
|
|
hsotg->supplies);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
usb: dwc2: platform: add support for utmi optional clock
Add support for the utmi clock. It's needed on STM32MP15, when using
the integrated full-speed PHY. This clock is an output of USBPHYC, but
HS USBPHYC is not attached as PHY in this case: Full-Speed PHY is directly
managed in dwc2 glue, through GGPIO register. Typical DT when using FS PHY
&usbotg_hs {
compatible = "st,stm32mp15-fsotg", "snps,dwc2";
pinctrl-names = "default";
pinctrl-0 = <&usbotg_hs_pins_a &usbotg_fs_dp_dm_pins_a>;
vbus-supply = <&vbus_otg>;
status = "okay";
};
In this configuration, USBPHYC clock output must be defined, so it can
be properly enabled as a clock provider:
clocks = <&rcc USBO_K>, <&usbphyc>;
clock-names = "otg", "utmi";
Acked-by: Minas Harutyunyan <hminas@synopsys.com>
Signed-off-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com>
Link: https://lore.kernel.org/r/20230414084137.1050487-4-fabrice.gasnier@foss.st.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2023-04-14 01:41:36 -07:00
|
|
|
if (hsotg->utmi_clk) {
|
|
|
|
ret = clk_prepare_enable(hsotg->utmi_clk);
|
|
|
|
if (ret)
|
|
|
|
goto err_dis_reg;
|
|
|
|
}
|
|
|
|
|
2015-11-13 10:02:12 -07:00
|
|
|
if (hsotg->clk) {
|
|
|
|
ret = clk_prepare_enable(hsotg->clk);
|
|
|
|
if (ret)
|
usb: dwc2: platform: add support for utmi optional clock
Add support for the utmi clock. It's needed on STM32MP15, when using
the integrated full-speed PHY. This clock is an output of USBPHYC, but
HS USBPHYC is not attached as PHY in this case: Full-Speed PHY is directly
managed in dwc2 glue, through GGPIO register. Typical DT when using FS PHY
&usbotg_hs {
compatible = "st,stm32mp15-fsotg", "snps,dwc2";
pinctrl-names = "default";
pinctrl-0 = <&usbotg_hs_pins_a &usbotg_fs_dp_dm_pins_a>;
vbus-supply = <&vbus_otg>;
status = "okay";
};
In this configuration, USBPHYC clock output must be defined, so it can
be properly enabled as a clock provider:
clocks = <&rcc USBO_K>, <&usbphyc>;
clock-names = "otg", "utmi";
Acked-by: Minas Harutyunyan <hminas@synopsys.com>
Signed-off-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com>
Link: https://lore.kernel.org/r/20230414084137.1050487-4-fabrice.gasnier@foss.st.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2023-04-14 01:41:36 -07:00
|
|
|
goto err_dis_utmi_clk;
|
2015-11-13 10:02:12 -07:00
|
|
|
}
|
2015-10-13 23:52:29 -07:00
|
|
|
|
2017-01-17 21:31:43 -07:00
|
|
|
if (hsotg->uphy) {
|
2015-10-13 23:52:29 -07:00
|
|
|
ret = usb_phy_init(hsotg->uphy);
|
2017-01-17 21:31:43 -07:00
|
|
|
} else if (hsotg->plat && hsotg->plat->phy_init) {
|
2015-10-13 23:52:29 -07:00
|
|
|
ret = hsotg->plat->phy_init(pdev, hsotg->plat->phy_type);
|
2017-01-17 21:31:43 -07:00
|
|
|
} else {
|
2022-08-23 10:58:42 -07:00
|
|
|
ret = phy_init(hsotg->phy);
|
2023-04-14 01:41:34 -07:00
|
|
|
if (ret == 0) {
|
2022-08-23 10:58:42 -07:00
|
|
|
ret = phy_power_on(hsotg->phy);
|
2023-04-14 01:41:34 -07:00
|
|
|
if (ret)
|
|
|
|
phy_exit(hsotg->phy);
|
|
|
|
}
|
2015-10-13 23:52:29 -07:00
|
|
|
}
|
|
|
|
|
2023-04-14 01:41:34 -07:00
|
|
|
if (ret)
|
|
|
|
goto err_dis_clk;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_dis_clk:
|
|
|
|
if (hsotg->clk)
|
|
|
|
clk_disable_unprepare(hsotg->clk);
|
|
|
|
|
usb: dwc2: platform: add support for utmi optional clock
Add support for the utmi clock. It's needed on STM32MP15, when using
the integrated full-speed PHY. This clock is an output of USBPHYC, but
HS USBPHYC is not attached as PHY in this case: Full-Speed PHY is directly
managed in dwc2 glue, through GGPIO register. Typical DT when using FS PHY
&usbotg_hs {
compatible = "st,stm32mp15-fsotg", "snps,dwc2";
pinctrl-names = "default";
pinctrl-0 = <&usbotg_hs_pins_a &usbotg_fs_dp_dm_pins_a>;
vbus-supply = <&vbus_otg>;
status = "okay";
};
In this configuration, USBPHYC clock output must be defined, so it can
be properly enabled as a clock provider:
clocks = <&rcc USBO_K>, <&usbphyc>;
clock-names = "otg", "utmi";
Acked-by: Minas Harutyunyan <hminas@synopsys.com>
Signed-off-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com>
Link: https://lore.kernel.org/r/20230414084137.1050487-4-fabrice.gasnier@foss.st.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2023-04-14 01:41:36 -07:00
|
|
|
err_dis_utmi_clk:
|
|
|
|
if (hsotg->utmi_clk)
|
|
|
|
clk_disable_unprepare(hsotg->utmi_clk);
|
|
|
|
|
2023-04-14 01:41:34 -07:00
|
|
|
err_dis_reg:
|
|
|
|
regulator_bulk_disable(ARRAY_SIZE(hsotg->supplies), hsotg->supplies);
|
|
|
|
|
2015-10-13 23:52:29 -07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* dwc2_lowlevel_hw_enable - enable platform lowlevel hw resources
|
|
|
|
* @hsotg: The driver state
|
|
|
|
*
|
|
|
|
* A wrapper for platform code responsible for controlling
|
|
|
|
* low-level USB platform resources (phy, clock, regulators)
|
|
|
|
*/
|
|
|
|
int dwc2_lowlevel_hw_enable(struct dwc2_hsotg *hsotg)
|
|
|
|
{
|
|
|
|
int ret = __dwc2_lowlevel_hw_enable(hsotg);
|
|
|
|
|
|
|
|
if (ret == 0)
|
|
|
|
hsotg->ll_hw_enabled = true;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __dwc2_lowlevel_hw_disable(struct dwc2_hsotg *hsotg)
|
|
|
|
{
|
|
|
|
struct platform_device *pdev = to_platform_device(hsotg->dev);
|
|
|
|
int ret = 0;
|
|
|
|
|
2017-01-17 21:31:43 -07:00
|
|
|
if (hsotg->uphy) {
|
2015-10-13 23:52:29 -07:00
|
|
|
usb_phy_shutdown(hsotg->uphy);
|
2017-01-17 21:31:43 -07:00
|
|
|
} else if (hsotg->plat && hsotg->plat->phy_exit) {
|
2015-10-13 23:52:29 -07:00
|
|
|
ret = hsotg->plat->phy_exit(pdev, hsotg->plat->phy_type);
|
2017-01-17 21:31:43 -07:00
|
|
|
} else {
|
2022-08-23 10:58:42 -07:00
|
|
|
ret = phy_power_off(hsotg->phy);
|
2015-10-13 23:52:29 -07:00
|
|
|
if (ret == 0)
|
2022-08-23 10:58:42 -07:00
|
|
|
ret = phy_exit(hsotg->phy);
|
2015-10-13 23:52:29 -07:00
|
|
|
}
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2015-11-13 10:02:12 -07:00
|
|
|
if (hsotg->clk)
|
|
|
|
clk_disable_unprepare(hsotg->clk);
|
2015-10-13 23:52:29 -07:00
|
|
|
|
usb: dwc2: platform: add support for utmi optional clock
Add support for the utmi clock. It's needed on STM32MP15, when using
the integrated full-speed PHY. This clock is an output of USBPHYC, but
HS USBPHYC is not attached as PHY in this case: Full-Speed PHY is directly
managed in dwc2 glue, through GGPIO register. Typical DT when using FS PHY
&usbotg_hs {
compatible = "st,stm32mp15-fsotg", "snps,dwc2";
pinctrl-names = "default";
pinctrl-0 = <&usbotg_hs_pins_a &usbotg_fs_dp_dm_pins_a>;
vbus-supply = <&vbus_otg>;
status = "okay";
};
In this configuration, USBPHYC clock output must be defined, so it can
be properly enabled as a clock provider:
clocks = <&rcc USBO_K>, <&usbphyc>;
clock-names = "otg", "utmi";
Acked-by: Minas Harutyunyan <hminas@synopsys.com>
Signed-off-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com>
Link: https://lore.kernel.org/r/20230414084137.1050487-4-fabrice.gasnier@foss.st.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2023-04-14 01:41:36 -07:00
|
|
|
if (hsotg->utmi_clk)
|
|
|
|
clk_disable_unprepare(hsotg->utmi_clk);
|
|
|
|
|
2023-03-16 01:41:27 -07:00
|
|
|
return regulator_bulk_disable(ARRAY_SIZE(hsotg->supplies), hsotg->supplies);
|
2015-10-13 23:52:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* dwc2_lowlevel_hw_disable - disable platform lowlevel hw resources
|
|
|
|
* @hsotg: The driver state
|
|
|
|
*
|
|
|
|
* A wrapper for platform code responsible for controlling
|
|
|
|
* low-level USB platform resources (phy, clock, regulators)
|
|
|
|
*/
|
|
|
|
int dwc2_lowlevel_hw_disable(struct dwc2_hsotg *hsotg)
|
|
|
|
{
|
|
|
|
int ret = __dwc2_lowlevel_hw_disable(hsotg);
|
|
|
|
|
|
|
|
if (ret == 0)
|
|
|
|
hsotg->ll_hw_enabled = false;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-05-05 10:15:08 -07:00
|
|
|
static void dwc2_reset_control_assert(void *data)
|
|
|
|
{
|
|
|
|
reset_control_assert(data);
|
|
|
|
}
|
|
|
|
|
2015-10-13 23:52:29 -07:00
|
|
|
static int dwc2_lowlevel_hw_init(struct dwc2_hsotg *hsotg)
|
|
|
|
{
|
|
|
|
int i, ret;
|
|
|
|
|
2016-08-10 06:53:34 -07:00
|
|
|
hsotg->reset = devm_reset_control_get_optional(hsotg->dev, "dwc2");
|
2021-12-07 05:08:29 -07:00
|
|
|
if (IS_ERR(hsotg->reset))
|
|
|
|
return dev_err_probe(hsotg->dev, PTR_ERR(hsotg->reset),
|
|
|
|
"error getting reset control\n");
|
2016-08-10 06:53:34 -07:00
|
|
|
|
2017-03-15 04:31:53 -07:00
|
|
|
reset_control_deassert(hsotg->reset);
|
2023-05-05 10:15:08 -07:00
|
|
|
ret = devm_add_action_or_reset(hsotg->dev, dwc2_reset_control_assert,
|
|
|
|
hsotg->reset);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2016-08-10 06:53:34 -07:00
|
|
|
|
2017-11-01 08:34:53 -07:00
|
|
|
hsotg->reset_ecc = devm_reset_control_get_optional(hsotg->dev, "dwc2-ecc");
|
2021-12-07 05:08:29 -07:00
|
|
|
if (IS_ERR(hsotg->reset_ecc))
|
|
|
|
return dev_err_probe(hsotg->dev, PTR_ERR(hsotg->reset_ecc),
|
|
|
|
"error getting reset control for ecc\n");
|
2017-11-01 08:34:53 -07:00
|
|
|
|
|
|
|
reset_control_deassert(hsotg->reset_ecc);
|
2023-05-05 10:15:08 -07:00
|
|
|
ret = devm_add_action_or_reset(hsotg->dev, dwc2_reset_control_assert,
|
|
|
|
hsotg->reset_ecc);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2017-11-01 08:34:53 -07:00
|
|
|
|
2015-10-13 23:52:29 -07:00
|
|
|
/*
|
|
|
|
* Attempt to find a generic PHY, then look for an old style
|
|
|
|
* USB PHY and then fall back to pdata
|
|
|
|
*/
|
|
|
|
hsotg->phy = devm_phy_get(hsotg->dev, "usb2-phy");
|
|
|
|
if (IS_ERR(hsotg->phy)) {
|
2015-11-13 10:02:11 -07:00
|
|
|
ret = PTR_ERR(hsotg->phy);
|
|
|
|
switch (ret) {
|
|
|
|
case -ENODEV:
|
|
|
|
case -ENOSYS:
|
|
|
|
hsotg->phy = NULL;
|
|
|
|
break;
|
|
|
|
default:
|
2021-12-07 05:08:29 -07:00
|
|
|
return dev_err_probe(hsotg->dev, ret, "error getting phy\n");
|
2015-11-13 10:02:11 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!hsotg->phy) {
|
2015-10-13 23:52:29 -07:00
|
|
|
hsotg->uphy = devm_usb_get_phy(hsotg->dev, USB_PHY_TYPE_USB2);
|
2015-11-13 10:02:11 -07:00
|
|
|
if (IS_ERR(hsotg->uphy)) {
|
|
|
|
ret = PTR_ERR(hsotg->uphy);
|
|
|
|
switch (ret) {
|
|
|
|
case -ENODEV:
|
|
|
|
case -ENXIO:
|
|
|
|
hsotg->uphy = NULL;
|
|
|
|
break;
|
|
|
|
default:
|
2021-12-07 05:08:29 -07:00
|
|
|
return dev_err_probe(hsotg->dev, ret, "error getting usb phy\n");
|
2015-11-13 10:02:11 -07:00
|
|
|
}
|
|
|
|
}
|
2015-10-13 23:52:29 -07:00
|
|
|
}
|
|
|
|
|
2015-11-13 10:02:11 -07:00
|
|
|
hsotg->plat = dev_get_platdata(hsotg->dev);
|
|
|
|
|
2015-10-13 23:52:29 -07:00
|
|
|
/* Clock */
|
2019-04-17 01:28:19 -07:00
|
|
|
hsotg->clk = devm_clk_get_optional(hsotg->dev, "otg");
|
2021-12-07 05:08:29 -07:00
|
|
|
if (IS_ERR(hsotg->clk))
|
|
|
|
return dev_err_probe(hsotg->dev, PTR_ERR(hsotg->clk), "cannot get otg clock\n");
|
2015-10-13 23:52:29 -07:00
|
|
|
|
usb: dwc2: platform: add support for utmi optional clock
Add support for the utmi clock. It's needed on STM32MP15, when using
the integrated full-speed PHY. This clock is an output of USBPHYC, but
HS USBPHYC is not attached as PHY in this case: Full-Speed PHY is directly
managed in dwc2 glue, through GGPIO register. Typical DT when using FS PHY
&usbotg_hs {
compatible = "st,stm32mp15-fsotg", "snps,dwc2";
pinctrl-names = "default";
pinctrl-0 = <&usbotg_hs_pins_a &usbotg_fs_dp_dm_pins_a>;
vbus-supply = <&vbus_otg>;
status = "okay";
};
In this configuration, USBPHYC clock output must be defined, so it can
be properly enabled as a clock provider:
clocks = <&rcc USBO_K>, <&usbphyc>;
clock-names = "otg", "utmi";
Acked-by: Minas Harutyunyan <hminas@synopsys.com>
Signed-off-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com>
Link: https://lore.kernel.org/r/20230414084137.1050487-4-fabrice.gasnier@foss.st.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2023-04-14 01:41:36 -07:00
|
|
|
hsotg->utmi_clk = devm_clk_get_optional(hsotg->dev, "utmi");
|
|
|
|
if (IS_ERR(hsotg->utmi_clk))
|
|
|
|
return dev_err_probe(hsotg->dev, PTR_ERR(hsotg->utmi_clk),
|
|
|
|
"cannot get utmi clock\n");
|
|
|
|
|
2015-10-13 23:52:29 -07:00
|
|
|
/* Regulators */
|
|
|
|
for (i = 0; i < ARRAY_SIZE(hsotg->supplies); i++)
|
|
|
|
hsotg->supplies[i].supply = dwc2_hsotg_supply_names[i];
|
|
|
|
|
|
|
|
ret = devm_regulator_bulk_get(hsotg->dev, ARRAY_SIZE(hsotg->supplies),
|
|
|
|
hsotg->supplies);
|
2021-12-07 05:08:29 -07:00
|
|
|
if (ret)
|
|
|
|
return dev_err_probe(hsotg->dev, ret, "failed to request supplies\n");
|
|
|
|
|
2015-10-13 23:52:29 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-04-22 14:00:19 -07:00
|
|
|
/**
|
|
|
|
* dwc2_driver_remove() - Called when the DWC_otg core is unregistered with the
|
|
|
|
* DWC_otg driver
|
|
|
|
*
|
|
|
|
* @dev: Platform device
|
|
|
|
*
|
|
|
|
* This routine is called, for example, when the rmmod command is executed. The
|
|
|
|
* device may or may not be electrically present. If it is present, the driver
|
|
|
|
* stops device processing. Any resources used on behalf of this device are
|
|
|
|
* freed.
|
|
|
|
*/
|
2023-05-30 00:19:08 -07:00
|
|
|
static void dwc2_driver_remove(struct platform_device *dev)
|
2013-04-22 14:00:19 -07:00
|
|
|
{
|
|
|
|
struct dwc2_hsotg *hsotg = platform_get_drvdata(dev);
|
2021-04-16 05:48:26 -07:00
|
|
|
struct dwc2_gregs_backup *gr;
|
2021-04-08 02:46:14 -07:00
|
|
|
int ret = 0;
|
|
|
|
|
2021-04-16 05:48:26 -07:00
|
|
|
gr = &hsotg->gr_backup;
|
|
|
|
|
|
|
|
/* Exit Hibernation when driver is removed. */
|
|
|
|
if (hsotg->hibernated) {
|
|
|
|
if (gr->gotgctl & GOTGCTL_CURMODE_HOST)
|
|
|
|
ret = dwc2_exit_hibernation(hsotg, 0, 0, 1);
|
|
|
|
else
|
|
|
|
ret = dwc2_exit_hibernation(hsotg, 0, 0, 0);
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
dev_err(hsotg->dev,
|
|
|
|
"exit hibernation failed.\n");
|
|
|
|
}
|
|
|
|
|
2021-04-08 02:46:14 -07:00
|
|
|
/* Exit Partial Power Down when driver is removed. */
|
|
|
|
if (hsotg->in_ppd) {
|
|
|
|
ret = dwc2_exit_partial_power_down(hsotg, 0, true);
|
|
|
|
if (ret)
|
|
|
|
dev_err(hsotg->dev,
|
|
|
|
"exit partial_power_down failed\n");
|
|
|
|
}
|
2013-04-22 14:00:19 -07:00
|
|
|
|
2021-04-13 00:37:30 -07:00
|
|
|
/* Exit clock gating when driver is removed. */
|
|
|
|
if (hsotg->params.power_down == DWC2_POWER_DOWN_PARAM_NONE &&
|
2024-03-13 02:22:01 -07:00
|
|
|
hsotg->bus_suspended && !hsotg->params.no_clock_gating) {
|
2021-04-13 00:37:30 -07:00
|
|
|
if (dwc2_is_device_mode(hsotg))
|
|
|
|
dwc2_gadget_exit_clock_gating(hsotg, 0);
|
|
|
|
else
|
|
|
|
dwc2_host_exit_clock_gating(hsotg, 0);
|
|
|
|
}
|
|
|
|
|
2015-04-29 13:08:59 -07:00
|
|
|
dwc2_debugfs_exit(hsotg);
|
2015-03-10 05:41:10 -07:00
|
|
|
if (hsotg->hcd_enabled)
|
|
|
|
dwc2_hcd_remove(hsotg);
|
|
|
|
if (hsotg->gadget_enabled)
|
2015-08-06 16:11:54 -07:00
|
|
|
dwc2_hsotg_remove(hsotg);
|
2013-04-22 14:00:19 -07:00
|
|
|
|
2020-09-09 02:35:10 -07:00
|
|
|
dwc2_drd_exit(hsotg);
|
|
|
|
|
2020-01-24 01:41:31 -07:00
|
|
|
if (hsotg->params.activate_stm_id_vb_detection)
|
|
|
|
regulator_disable(hsotg->usb33d);
|
|
|
|
|
2015-10-13 23:52:29 -07:00
|
|
|
if (hsotg->ll_hw_enabled)
|
|
|
|
dwc2_lowlevel_hw_disable(hsotg);
|
2013-04-22 14:00:19 -07:00
|
|
|
}
|
|
|
|
|
2015-12-18 11:30:59 -07:00
|
|
|
/**
|
|
|
|
* dwc2_driver_shutdown() - Called on device shutdown
|
|
|
|
*
|
|
|
|
* @dev: Platform device
|
|
|
|
*
|
|
|
|
* In specific conditions (involving usb hubs) dwc2 devices can create a
|
|
|
|
* lot of interrupts, even to the point of overwhelming devices running
|
|
|
|
* at low frequencies. Some devices need to do special clock handling
|
|
|
|
* at shutdown-time which may bring the system clock below the threshold
|
|
|
|
* of being able to handle the dwc2 interrupts. Disabling dwc2-irqs
|
|
|
|
* prevents reboots/poweroffs from getting stuck in such cases.
|
|
|
|
*/
|
|
|
|
static void dwc2_driver_shutdown(struct platform_device *dev)
|
|
|
|
{
|
|
|
|
struct dwc2_hsotg *hsotg = platform_get_drvdata(dev);
|
|
|
|
|
2020-05-30 00:41:50 -07:00
|
|
|
dwc2_disable_global_interrupts(hsotg);
|
|
|
|
synchronize_irq(hsotg->irq);
|
2015-12-18 11:30:59 -07:00
|
|
|
}
|
|
|
|
|
2018-07-27 01:26:29 -07:00
|
|
|
/**
|
|
|
|
* dwc2_check_core_endianness() - Returns true if core and AHB have
|
|
|
|
* opposite endianness.
|
|
|
|
* @hsotg: Programming view of the DWC_otg controller.
|
|
|
|
*/
|
|
|
|
static bool dwc2_check_core_endianness(struct dwc2_hsotg *hsotg)
|
|
|
|
{
|
|
|
|
u32 snpsid;
|
|
|
|
|
|
|
|
snpsid = ioread32(hsotg->regs + GSNPSID);
|
|
|
|
if ((snpsid & GSNPSID_ID_MASK) == DWC2_OTG_ID ||
|
|
|
|
(snpsid & GSNPSID_ID_MASK) == DWC2_FS_IOT_ID ||
|
|
|
|
(snpsid & GSNPSID_ID_MASK) == DWC2_HS_IOT_ID)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-05-20 23:05:44 -07:00
|
|
|
/**
|
2021-05-26 06:00:15 -07:00
|
|
|
* dwc2_check_core_version() - Check core version
|
2020-05-20 23:05:44 -07:00
|
|
|
*
|
|
|
|
* @hsotg: Programming view of the DWC_otg controller
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
int dwc2_check_core_version(struct dwc2_hsotg *hsotg)
|
|
|
|
{
|
|
|
|
struct dwc2_hw_params *hw = &hsotg->hw_params;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Attempt to ensure this device is really a DWC_otg Controller.
|
|
|
|
* Read and verify the GSNPSID register contents. The value should be
|
|
|
|
* 0x45f4xxxx, 0x5531xxxx or 0x5532xxxx
|
|
|
|
*/
|
|
|
|
|
|
|
|
hw->snpsid = dwc2_readl(hsotg, GSNPSID);
|
|
|
|
if ((hw->snpsid & GSNPSID_ID_MASK) != DWC2_OTG_ID &&
|
|
|
|
(hw->snpsid & GSNPSID_ID_MASK) != DWC2_FS_IOT_ID &&
|
|
|
|
(hw->snpsid & GSNPSID_ID_MASK) != DWC2_HS_IOT_ID) {
|
|
|
|
dev_err(hsotg->dev, "Bad value for GSNPSID: 0x%08x\n",
|
|
|
|
hw->snpsid);
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
dev_dbg(hsotg->dev, "Core Release: %1x.%1x%1x%1x (snpsid=%x)\n",
|
|
|
|
hw->snpsid >> 12 & 0xf, hw->snpsid >> 8 & 0xf,
|
|
|
|
hw->snpsid >> 4 & 0xf, hw->snpsid & 0xf, hw->snpsid);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-04-22 14:00:19 -07:00
|
|
|
/**
|
|
|
|
* dwc2_driver_probe() - Called when the DWC_otg core is bound to the DWC_otg
|
|
|
|
* driver
|
|
|
|
*
|
|
|
|
* @dev: Platform device
|
|
|
|
*
|
|
|
|
* This routine creates the driver components required to control the device
|
|
|
|
* (core, HCD, and PCD) and initializes the device. The driver components are
|
|
|
|
* stored in a dwc2_hsotg structure. A reference to the dwc2_hsotg is saved
|
|
|
|
* in the device private data. This allows the driver to access the dwc2_hsotg
|
|
|
|
* structure on subsequent calls to driver methods for this device.
|
|
|
|
*/
|
|
|
|
static int dwc2_driver_probe(struct platform_device *dev)
|
|
|
|
{
|
|
|
|
struct dwc2_hsotg *hsotg;
|
|
|
|
struct resource *res;
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
hsotg = devm_kzalloc(&dev->dev, sizeof(*hsotg), GFP_KERNEL);
|
|
|
|
if (!hsotg)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
hsotg->dev = &dev->dev;
|
|
|
|
|
2013-05-17 01:52:55 -07:00
|
|
|
/*
|
|
|
|
* Use reasonable defaults so platforms don't have to provide these.
|
|
|
|
*/
|
|
|
|
if (!dev->dev.dma_mask)
|
|
|
|
dev->dev.dma_mask = &dev->dev.coherent_dma_mask;
|
2013-06-10 08:56:16 -07:00
|
|
|
retval = dma_set_coherent_mask(&dev->dev, DMA_BIT_MASK(32));
|
2018-02-12 13:20:08 -07:00
|
|
|
if (retval) {
|
|
|
|
dev_err(&dev->dev, "can't set coherent DMA mask: %d\n", retval);
|
2013-06-10 08:56:16 -07:00
|
|
|
return retval;
|
2018-02-12 13:20:08 -07:00
|
|
|
}
|
2013-05-17 01:52:55 -07:00
|
|
|
|
2020-03-23 09:06:11 -07:00
|
|
|
hsotg->regs = devm_platform_get_and_ioremap_resource(dev, 0, &res);
|
2013-04-22 14:00:19 -07:00
|
|
|
if (IS_ERR(hsotg->regs))
|
|
|
|
return PTR_ERR(hsotg->regs);
|
|
|
|
|
|
|
|
dev_dbg(&dev->dev, "mapped PA %08lx to VA %p\n",
|
|
|
|
(unsigned long)res->start, hsotg->regs);
|
|
|
|
|
2015-10-13 23:52:29 -07:00
|
|
|
retval = dwc2_lowlevel_hw_init(hsotg);
|
2015-04-29 13:09:05 -07:00
|
|
|
if (retval)
|
|
|
|
return retval;
|
|
|
|
|
2015-10-13 23:52:29 -07:00
|
|
|
spin_lock_init(&hsotg->lock);
|
|
|
|
|
2018-09-05 04:40:02 -07:00
|
|
|
hsotg->vbus_supply = devm_regulator_get_optional(hsotg->dev, "vbus");
|
|
|
|
if (IS_ERR(hsotg->vbus_supply)) {
|
|
|
|
retval = PTR_ERR(hsotg->vbus_supply);
|
|
|
|
hsotg->vbus_supply = NULL;
|
|
|
|
if (retval != -ENODEV)
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2015-10-13 23:52:29 -07:00
|
|
|
retval = dwc2_lowlevel_hw_enable(hsotg);
|
|
|
|
if (retval)
|
|
|
|
return retval;
|
|
|
|
|
2018-08-27 14:36:38 -07:00
|
|
|
hsotg->needs_byte_swap = dwc2_check_core_endianness(hsotg);
|
|
|
|
|
2015-12-17 12:16:31 -07:00
|
|
|
retval = dwc2_get_dr_mode(hsotg);
|
|
|
|
if (retval)
|
2016-04-27 20:20:56 -07:00
|
|
|
goto error;
|
2015-12-17 12:16:31 -07:00
|
|
|
|
2019-05-20 10:56:04 -07:00
|
|
|
hsotg->need_phy_for_wake =
|
|
|
|
of_property_read_bool(dev->dev.of_node,
|
|
|
|
"snps,need-phy-for-wake");
|
|
|
|
|
2020-05-20 23:05:44 -07:00
|
|
|
/*
|
|
|
|
* Before performing any core related operations
|
|
|
|
* check core version.
|
|
|
|
*/
|
|
|
|
retval = dwc2_check_core_version(hsotg);
|
|
|
|
if (retval)
|
|
|
|
goto error;
|
|
|
|
|
2016-01-11 17:32:14 -07:00
|
|
|
/*
|
|
|
|
* Reset before dwc2_get_hwparams() then it could get power-on real
|
|
|
|
* reset value form registers.
|
|
|
|
*/
|
2018-02-16 01:56:03 -07:00
|
|
|
retval = dwc2_core_reset(hsotg, false);
|
|
|
|
if (retval)
|
|
|
|
goto error;
|
2016-01-11 17:32:14 -07:00
|
|
|
|
|
|
|
/* Detect config values from hardware */
|
2015-10-13 23:52:29 -07:00
|
|
|
retval = dwc2_get_hwparams(hsotg);
|
|
|
|
if (retval)
|
|
|
|
goto error;
|
|
|
|
|
usb: dwc2: Adjust the timing of USB Driver Interrupt Registration in the Crashkernel Scenario
The issue is that before entering the crash kernel, the DWC USB controller
did not perform operations such as resetting the interrupt mask bits.
After entering the crash kernel,before the USB interrupt handler
registration was completed while loading the DWC USB driver,an GINTSTS_SOF
interrupt was received.This triggered the misroute_irq process within the
GIC handling framework,ultimately leading to the misrouting of the
interrupt,causing it to be handled by the wrong interrupt handler
and resulting in the issue.
Summary:In a scenario where the kernel triggers a panic and enters
the crash kernel,it is necessary to ensure that the interrupt mask
bit is not enabled before the interrupt registration is complete.
If an interrupt reaches the CPU at this moment,it will certainly
not be handled correctly,especially in cases where this interrupt
is reported frequently.
Please refer to the Crashkernel dmesg information as follows
(the message on line 3 was added before devm_request_irq is
called by the dwc2_driver_probe function):
[ 5.866837][ T1] dwc2 JMIC0010:01: supply vusb_d not found, using dummy regulator
[ 5.874588][ T1] dwc2 JMIC0010:01: supply vusb_a not found, using dummy regulator
[ 5.882335][ T1] dwc2 JMIC0010:01: before devm_request_irq irq: [71], gintmsk[0xf300080e], gintsts[0x04200009]
[ 5.892686][ C0] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 5.10.0-jmnd1.2_RC #18
[ 5.900327][ C0] Hardware name: CMSS HyperCard4-25G/HyperCard4-25G, BIOS 1.6.4 Jul 8 2024
[ 5.908836][ C0] Call trace:
[ 5.911965][ C0] dump_backtrace+0x0/0x1f0
[ 5.916308][ C0] show_stack+0x20/0x30
[ 5.920304][ C0] dump_stack+0xd8/0x140
[ 5.924387][ C0] pcie_xxx_handler+0x3c/0x1d8
[ 5.930121][ C0] __handle_irq_event_percpu+0x64/0x1e0
[ 5.935506][ C0] handle_irq_event+0x80/0x1d0
[ 5.940109][ C0] try_one_irq+0x138/0x174
[ 5.944365][ C0] misrouted_irq+0x134/0x140
[ 5.948795][ C0] note_interrupt+0x1d0/0x30c
[ 5.953311][ C0] handle_irq_event+0x13c/0x1d0
[ 5.958001][ C0] handle_fasteoi_irq+0xd4/0x260
[ 5.962779][ C0] __handle_domain_irq+0x88/0xf0
[ 5.967555][ C0] gic_handle_irq+0x9c/0x2f0
[ 5.971985][ C0] el1_irq+0xb8/0x140
[ 5.975807][ C0] __setup_irq+0x3dc/0x7cc
[ 5.980064][ C0] request_threaded_irq+0xf4/0x1b4
[ 5.985015][ C0] devm_request_threaded_irq+0x80/0x100
[ 5.990400][ C0] dwc2_driver_probe+0x1b8/0x6b0
[ 5.995178][ C0] platform_drv_probe+0x5c/0xb0
[ 5.999868][ C0] really_probe+0xf8/0x51c
[ 6.004125][ C0] driver_probe_device+0xfc/0x170
[ 6.008989][ C0] device_driver_attach+0xc8/0xd0
[ 6.013853][ C0] __driver_attach+0xe8/0x1b0
[ 6.018369][ C0] bus_for_each_dev+0x7c/0xdc
[ 6.022886][ C0] driver_attach+0x2c/0x3c
[ 6.027143][ C0] bus_add_driver+0xdc/0x240
[ 6.031573][ C0] driver_register+0x80/0x13c
[ 6.036090][ C0] __platform_driver_register+0x50/0x5c
[ 6.041476][ C0] dwc2_platform_driver_init+0x24/0x30
[ 6.046774][ C0] do_one_initcall+0x50/0x25c
[ 6.051291][ C0] do_initcall_level+0xe4/0xfc
[ 6.055894][ C0] do_initcalls+0x80/0xa4
[ 6.060064][ C0] kernel_init_freeable+0x198/0x240
[ 6.065102][ C0] kernel_init+0x1c/0x12c
Signed-off-by: Shawn Shao <shawn.shao@jaguarmicro.com>
Link: https://lore.kernel.org/r/20240830031709.134-1-shawn.shao@jaguarmicro.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-08-29 20:17:09 -07:00
|
|
|
hsotg->irq = platform_get_irq(dev, 0);
|
|
|
|
if (hsotg->irq < 0) {
|
|
|
|
retval = hsotg->irq;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
dev_dbg(hsotg->dev, "registering common handler for irq%d\n",
|
|
|
|
hsotg->irq);
|
|
|
|
retval = devm_request_irq(hsotg->dev, hsotg->irq,
|
|
|
|
dwc2_handle_common_intr, IRQF_SHARED,
|
|
|
|
dev_name(hsotg->dev), hsotg);
|
|
|
|
if (retval)
|
|
|
|
goto error;
|
|
|
|
|
2018-02-16 01:56:03 -07:00
|
|
|
/*
|
|
|
|
* For OTG cores, set the force mode bits to reflect the value
|
|
|
|
* of dr_mode. Force mode bits should not be touched at any
|
|
|
|
* other time after this.
|
|
|
|
*/
|
2015-12-17 12:18:27 -07:00
|
|
|
dwc2_force_dr_mode(hsotg);
|
2015-12-17 12:16:58 -07:00
|
|
|
|
2016-11-03 17:55:55 -07:00
|
|
|
retval = dwc2_init_params(hsotg);
|
|
|
|
if (retval)
|
|
|
|
goto error;
|
|
|
|
|
2020-01-24 01:41:31 -07:00
|
|
|
if (hsotg->params.activate_stm_id_vb_detection) {
|
|
|
|
u32 ggpio;
|
|
|
|
|
|
|
|
hsotg->usb33d = devm_regulator_get(hsotg->dev, "usb33d");
|
|
|
|
if (IS_ERR(hsotg->usb33d)) {
|
|
|
|
retval = PTR_ERR(hsotg->usb33d);
|
2021-12-07 05:08:29 -07:00
|
|
|
dev_err_probe(hsotg->dev, retval, "failed to request usb33d supply\n");
|
2020-01-24 01:41:31 -07:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
retval = regulator_enable(hsotg->usb33d);
|
|
|
|
if (retval) {
|
2021-12-07 05:08:29 -07:00
|
|
|
dev_err_probe(hsotg->dev, retval, "failed to enable usb33d supply\n");
|
2020-01-24 01:41:31 -07:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
ggpio = dwc2_readl(hsotg, GGPIO);
|
|
|
|
ggpio |= GGPIO_STM32_OTG_GCCFG_IDEN;
|
|
|
|
ggpio |= GGPIO_STM32_OTG_GCCFG_VBDEN;
|
|
|
|
dwc2_writel(hsotg, ggpio, GGPIO);
|
2021-12-07 05:45:10 -07:00
|
|
|
|
|
|
|
/* ID/VBUS detection startup time */
|
|
|
|
usleep_range(5000, 7000);
|
2020-01-24 01:41:31 -07:00
|
|
|
}
|
|
|
|
|
2020-09-09 02:35:10 -07:00
|
|
|
retval = dwc2_drd_init(hsotg);
|
|
|
|
if (retval) {
|
2021-12-07 05:08:29 -07:00
|
|
|
dev_err_probe(hsotg->dev, retval, "failed to initialize dual-role\n");
|
2020-09-09 02:35:10 -07:00
|
|
|
goto error_init;
|
|
|
|
}
|
|
|
|
|
2015-03-10 05:41:10 -07:00
|
|
|
if (hsotg->dr_mode != USB_DR_MODE_HOST) {
|
2017-12-25 04:17:45 -07:00
|
|
|
retval = dwc2_gadget_init(hsotg);
|
2015-03-10 05:41:10 -07:00
|
|
|
if (retval)
|
2020-09-09 02:35:10 -07:00
|
|
|
goto error_drd;
|
2015-03-10 05:41:10 -07:00
|
|
|
hsotg->gadget_enabled = 1;
|
|
|
|
}
|
|
|
|
|
2019-05-20 10:56:04 -07:00
|
|
|
/*
|
|
|
|
* If we need PHY for wakeup we must be wakeup capable.
|
|
|
|
* When we have a device that can wake without the PHY we
|
|
|
|
* can adjust this condition.
|
|
|
|
*/
|
|
|
|
if (hsotg->need_phy_for_wake)
|
|
|
|
device_set_wakeup_capable(&dev->dev, true);
|
|
|
|
|
2019-04-16 14:53:49 -07:00
|
|
|
hsotg->reset_phy_on_wake =
|
|
|
|
of_property_read_bool(dev->dev.of_node,
|
|
|
|
"snps,reset-phy-on-wake");
|
|
|
|
if (hsotg->reset_phy_on_wake && !hsotg->phy) {
|
|
|
|
dev_warn(hsotg->dev,
|
|
|
|
"Quirk reset-phy-on-wake only supports generic PHYs\n");
|
|
|
|
hsotg->reset_phy_on_wake = false;
|
|
|
|
}
|
|
|
|
|
2015-03-10 05:41:10 -07:00
|
|
|
if (hsotg->dr_mode != USB_DR_MODE_PERIPHERAL) {
|
2017-01-25 15:13:37 -07:00
|
|
|
retval = dwc2_hcd_init(hsotg);
|
2015-03-10 05:41:10 -07:00
|
|
|
if (retval) {
|
|
|
|
if (hsotg->gadget_enabled)
|
2015-08-06 16:11:54 -07:00
|
|
|
dwc2_hsotg_remove(hsotg);
|
2020-09-09 02:35:10 -07:00
|
|
|
goto error_drd;
|
2015-03-10 05:41:10 -07:00
|
|
|
}
|
|
|
|
hsotg->hcd_enabled = 1;
|
|
|
|
}
|
2013-04-22 14:00:19 -07:00
|
|
|
|
|
|
|
platform_set_drvdata(dev, hsotg);
|
2018-02-16 03:08:27 -07:00
|
|
|
hsotg->hibernated = 0;
|
2013-04-22 14:00:19 -07:00
|
|
|
|
2015-04-29 13:08:59 -07:00
|
|
|
dwc2_debugfs_init(hsotg);
|
|
|
|
|
2015-10-13 23:52:29 -07:00
|
|
|
/* Gadget code manages lowlevel hw on its own */
|
usb: dwc2: fix a race, don't power off/on phy for dual-role mode
When in dual role mode (dr_mode == USB_DR_MODE_OTG), platform probe
successively basically calls:
- dwc2_gadget_init()
- dwc2_hcd_init()
- dwc2_lowlevel_hw_disable() since recent change [1]
- usb_add_gadget_udc()
The PHYs (and so the clocks it may provide) shouldn't be disabled for all
SoCs, in OTG mode, as the HCD part has been initialized.
On STM32 this creates some weird race condition upon boot, when:
- initially attached as a device, to a HOST
- and there is a gadget script invoked to setup the device part.
Below issue becomes systematic, as long as the gadget script isn't
started by userland: the hardware PHYs (and so the clocks provided by the
PHYs) remains disabled.
It ends up in having an endless interrupt storm, before the watchdog
resets the platform.
[ 16.924163] dwc2 49000000.usb-otg: EPs: 9, dedicated fifos, 952 entries in SPRAM
[ 16.962704] dwc2 49000000.usb-otg: DWC OTG Controller
[ 16.966488] dwc2 49000000.usb-otg: new USB bus registered, assigned bus number 2
[ 16.974051] dwc2 49000000.usb-otg: irq 77, io mem 0x49000000
[ 17.032170] hub 2-0:1.0: USB hub found
[ 17.042299] hub 2-0:1.0: 1 port detected
[ 17.175408] dwc2 49000000.usb-otg: Mode Mismatch Interrupt: currently in Host mode
[ 17.181741] dwc2 49000000.usb-otg: Mode Mismatch Interrupt: currently in Host mode
[ 17.189303] dwc2 49000000.usb-otg: Mode Mismatch Interrupt: currently in Host mode
...
The host part is also not functional, until the gadget part is configured.
The HW may only be disabled for peripheral mode (original init), e.g.
dr_mode == USB_DR_MODE_PERIPHERAL, until the gadget driver initializes.
But when in USB_DR_MODE_OTG, the HW should remain enabled, as the HCD part
is able to run, while the gadget part isn't necessarily configured.
I don't fully get the of purpose the original change, that claims disabling
the hardware is missing. It creates conditions on SOCs using the PHY
initialization to be completely non working in OTG mode. Original
change [1] should be reworked to be platform specific.
[1] https://lore.kernel.org/r/20221206-dwc2-gadget-dual-role-v1-2-36515e1092cd@theobroma-systems.com
Fixes: ade23d7b7ec5 ("usb: dwc2: power on/off phy for peripheral mode in dual-role mode")
Cc: stable <stable@kernel.org>
Signed-off-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com>
Reviewed-by: Quentin Schulz <quentin.schulz@theobroma-systems.com>
Tested-by: Quentin Schulz <quentin.schulz@theobroma-systems.com>
Link: https://lore.kernel.org/r/20230315144433.3095859-1-fabrice.gasnier@foss.st.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2023-03-15 07:44:33 -07:00
|
|
|
if (hsotg->dr_mode == USB_DR_MODE_PERIPHERAL)
|
2015-10-13 23:52:29 -07:00
|
|
|
dwc2_lowlevel_hw_disable(hsotg);
|
|
|
|
|
2020-06-09 01:28:11 -07:00
|
|
|
#if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || \
|
|
|
|
IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
|
|
|
|
/* Postponed adding a new gadget to the udc class driver list */
|
|
|
|
if (hsotg->gadget_enabled) {
|
|
|
|
retval = usb_add_gadget_udc(hsotg->dev, &hsotg->gadget);
|
|
|
|
if (retval) {
|
2020-07-16 05:09:48 -07:00
|
|
|
hsotg->gadget.udc = NULL;
|
2020-06-09 01:28:11 -07:00
|
|
|
dwc2_hsotg_remove(hsotg);
|
2020-07-03 15:50:43 -07:00
|
|
|
goto error_debugfs;
|
2020-06-09 01:28:11 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_USB_DWC2_PERIPHERAL || CONFIG_USB_DWC2_DUAL_ROLE */
|
2015-10-13 23:52:29 -07:00
|
|
|
return 0;
|
|
|
|
|
2020-10-17 09:50:12 -07:00
|
|
|
#if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || \
|
|
|
|
IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
|
2020-07-03 15:50:43 -07:00
|
|
|
error_debugfs:
|
|
|
|
dwc2_debugfs_exit(hsotg);
|
|
|
|
if (hsotg->hcd_enabled)
|
|
|
|
dwc2_hcd_remove(hsotg);
|
2020-10-17 09:50:12 -07:00
|
|
|
#endif
|
2020-09-09 02:35:10 -07:00
|
|
|
error_drd:
|
|
|
|
dwc2_drd_exit(hsotg);
|
|
|
|
|
2020-01-24 01:41:31 -07:00
|
|
|
error_init:
|
|
|
|
if (hsotg->params.activate_stm_id_vb_detection)
|
|
|
|
regulator_disable(hsotg->usb33d);
|
2015-10-13 23:52:29 -07:00
|
|
|
error:
|
2023-03-16 01:41:27 -07:00
|
|
|
if (hsotg->ll_hw_enabled)
|
2020-07-16 05:09:48 -07:00
|
|
|
dwc2_lowlevel_hw_disable(hsotg);
|
2013-04-22 14:00:19 -07:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2014-11-19 07:37:53 -07:00
|
|
|
static int __maybe_unused dwc2_suspend(struct device *dev)
|
2014-11-11 10:13:34 -07:00
|
|
|
{
|
2014-11-11 10:13:35 -07:00
|
|
|
struct dwc2_hsotg *dwc2 = dev_get_drvdata(dev);
|
2019-05-20 10:56:04 -07:00
|
|
|
bool is_device_mode = dwc2_is_device_mode(dwc2);
|
2014-11-11 10:13:34 -07:00
|
|
|
int ret = 0;
|
|
|
|
|
2019-05-20 10:56:04 -07:00
|
|
|
if (is_device_mode)
|
2015-10-13 23:52:29 -07:00
|
|
|
dwc2_hsotg_suspend(dwc2);
|
|
|
|
|
2020-09-09 02:35:10 -07:00
|
|
|
dwc2_drd_suspend(dwc2);
|
|
|
|
|
2020-01-24 01:41:31 -07:00
|
|
|
if (dwc2->params.activate_stm_id_vb_detection) {
|
|
|
|
unsigned long flags;
|
|
|
|
u32 ggpio, gotgctl;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Need to force the mode to the current mode to avoid Mode
|
|
|
|
* Mismatch Interrupt when ID detection will be disabled.
|
|
|
|
*/
|
|
|
|
dwc2_force_mode(dwc2, !is_device_mode);
|
|
|
|
|
|
|
|
spin_lock_irqsave(&dwc2->lock, flags);
|
|
|
|
gotgctl = dwc2_readl(dwc2, GOTGCTL);
|
|
|
|
/* bypass debounce filter, enable overrides */
|
|
|
|
gotgctl |= GOTGCTL_DBNCE_FLTR_BYPASS;
|
|
|
|
gotgctl |= GOTGCTL_BVALOEN | GOTGCTL_AVALOEN;
|
|
|
|
/* Force A / B session if needed */
|
|
|
|
if (gotgctl & GOTGCTL_ASESVLD)
|
|
|
|
gotgctl |= GOTGCTL_AVALOVAL;
|
|
|
|
if (gotgctl & GOTGCTL_BSESVLD)
|
|
|
|
gotgctl |= GOTGCTL_BVALOVAL;
|
|
|
|
dwc2_writel(dwc2, gotgctl, GOTGCTL);
|
|
|
|
spin_unlock_irqrestore(&dwc2->lock, flags);
|
|
|
|
|
|
|
|
ggpio = dwc2_readl(dwc2, GGPIO);
|
|
|
|
ggpio &= ~GGPIO_STM32_OTG_GCCFG_IDEN;
|
|
|
|
ggpio &= ~GGPIO_STM32_OTG_GCCFG_VBDEN;
|
|
|
|
dwc2_writel(dwc2, ggpio, GGPIO);
|
|
|
|
|
|
|
|
regulator_disable(dwc2->usb33d);
|
|
|
|
}
|
|
|
|
|
2019-05-20 10:56:04 -07:00
|
|
|
if (dwc2->ll_hw_enabled &&
|
|
|
|
(is_device_mode || dwc2_host_can_poweroff_phy(dwc2))) {
|
2015-10-13 23:52:29 -07:00
|
|
|
ret = __dwc2_lowlevel_hw_disable(dwc2);
|
2019-05-20 10:56:04 -07:00
|
|
|
dwc2->phy_off_for_suspend = true;
|
|
|
|
}
|
2014-12-08 02:46:26 -07:00
|
|
|
|
2014-11-11 10:13:34 -07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-11-19 07:37:53 -07:00
|
|
|
static int __maybe_unused dwc2_resume(struct device *dev)
|
2014-11-11 10:13:34 -07:00
|
|
|
{
|
2014-11-11 10:13:35 -07:00
|
|
|
struct dwc2_hsotg *dwc2 = dev_get_drvdata(dev);
|
2014-11-11 10:13:34 -07:00
|
|
|
int ret = 0;
|
|
|
|
|
2019-05-20 10:56:04 -07:00
|
|
|
if (dwc2->phy_off_for_suspend && dwc2->ll_hw_enabled) {
|
2015-10-13 23:52:29 -07:00
|
|
|
ret = __dwc2_lowlevel_hw_enable(dwc2);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
2019-05-20 10:56:04 -07:00
|
|
|
dwc2->phy_off_for_suspend = false;
|
2015-10-13 23:52:29 -07:00
|
|
|
|
2020-01-24 01:41:31 -07:00
|
|
|
if (dwc2->params.activate_stm_id_vb_detection) {
|
|
|
|
unsigned long flags;
|
|
|
|
u32 ggpio, gotgctl;
|
|
|
|
|
|
|
|
ret = regulator_enable(dwc2->usb33d);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ggpio = dwc2_readl(dwc2, GGPIO);
|
|
|
|
ggpio |= GGPIO_STM32_OTG_GCCFG_IDEN;
|
|
|
|
ggpio |= GGPIO_STM32_OTG_GCCFG_VBDEN;
|
|
|
|
dwc2_writel(dwc2, ggpio, GGPIO);
|
|
|
|
|
|
|
|
/* ID/VBUS detection startup time */
|
|
|
|
usleep_range(5000, 7000);
|
|
|
|
|
|
|
|
spin_lock_irqsave(&dwc2->lock, flags);
|
|
|
|
gotgctl = dwc2_readl(dwc2, GOTGCTL);
|
|
|
|
gotgctl &= ~GOTGCTL_DBNCE_FLTR_BYPASS;
|
|
|
|
gotgctl &= ~(GOTGCTL_BVALOEN | GOTGCTL_AVALOEN |
|
|
|
|
GOTGCTL_BVALOVAL | GOTGCTL_AVALOVAL);
|
|
|
|
dwc2_writel(dwc2, gotgctl, GOTGCTL);
|
|
|
|
spin_unlock_irqrestore(&dwc2->lock, flags);
|
|
|
|
}
|
|
|
|
|
2021-12-06 08:56:43 -07:00
|
|
|
if (!dwc2->role_sw) {
|
|
|
|
/* Need to restore FORCEDEVMODE/FORCEHOSTMODE */
|
|
|
|
dwc2_force_dr_mode(dwc2);
|
|
|
|
} else {
|
|
|
|
dwc2_drd_resume(dwc2);
|
|
|
|
}
|
2020-09-09 02:35:10 -07:00
|
|
|
|
2015-10-13 23:52:29 -07:00
|
|
|
if (dwc2_is_device_mode(dwc2))
|
2015-08-06 16:11:54 -07:00
|
|
|
ret = dwc2_hsotg_resume(dwc2);
|
2014-12-08 02:46:26 -07:00
|
|
|
|
2014-11-11 10:13:34 -07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-11-11 10:13:35 -07:00
|
|
|
static const struct dev_pm_ops dwc2_dev_pm_ops = {
|
|
|
|
SET_SYSTEM_SLEEP_PM_OPS(dwc2_suspend, dwc2_resume)
|
|
|
|
};
|
|
|
|
|
2013-04-22 14:00:19 -07:00
|
|
|
static struct platform_driver dwc2_platform_driver = {
|
|
|
|
.driver = {
|
2013-11-12 12:07:19 -07:00
|
|
|
.name = dwc2_driver_name,
|
2013-04-22 14:00:19 -07:00
|
|
|
.of_match_table = dwc2_of_match_table,
|
2021-04-13 14:58:34 -07:00
|
|
|
.acpi_match_table = ACPI_PTR(dwc2_acpi_match),
|
2014-11-11 10:13:35 -07:00
|
|
|
.pm = &dwc2_dev_pm_ops,
|
2013-04-22 14:00:19 -07:00
|
|
|
},
|
|
|
|
.probe = dwc2_driver_probe,
|
2023-05-30 00:19:08 -07:00
|
|
|
.remove_new = dwc2_driver_remove,
|
2015-12-18 11:30:59 -07:00
|
|
|
.shutdown = dwc2_driver_shutdown,
|
2013-04-22 14:00:19 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
module_platform_driver(dwc2_platform_driver);
|