usb: dwc3: part 1, reset and import from Linux v6.16
Subsystems (3)
PATCH v10 49/63 usb: dwc3: import from kernel v6.4
In reply to Anders RoxellFrom: Jens Wiklander <[email protected]>
Sync Linux kernel dwc3 changes from v6.3 to v6.4.
The following files are preserved across the import:Makefile Kconfig dwc3-meson-g12a.c dwc3-meson-gxl.c dwc3-omap.c dwc3-uniphier.c dwc3-generic.h dwc3-generic.c dwc3-generic-sti.c dwc3-layerscape.c ti_usb_phy.c
Skipping unused files:debugfs.c drd.c dwc3-exynos.c dwc3-haps.c dwc3-imx8mp.c dwc3-keystone.c dwc3-octeon.c dwc3-of-simple.c dwc3-pci.c dwc3-qcom.c dwc3-qcom-legacy.c dwc3-rtk.c dwc3-st.c dwc3-xilinx.c host.c trace.c trace.h ulpi.c
Note that this is a raw import and doesn't build. A fixup commit at the end of the series fixes that.
List of commits: git log --oneline v6.3..v6.4
Commits imported:e3dbb6575715 USB: dwc3: fix use-after-free on core driver unbind 00f8205ffcf1 usb: dwc3: gadget: Reset num TRBs before giving back the request 8018018d9c56 usb: dwc3: fix a test for error in dwc3_core_init() 4e8ef34e36f2 usb: dwc3: fix gadget mode suspend interrupt handler issue c8540870af4c usb: dwc3: gadget: Improve dwc3_gadget_suspend() and dwc3_gadget_resume() 8f40fc080813 usb: dwc3: gadget: Refactor EP0 forced stall/restart into a separate API 39674be56fba usb: dwc3: gadget: Execute gadget stop after halting the controller 02435a739b81 usb: dwc3: gadget: Stall and restart EP0 if host is unresponsive d21a797a3eeb usb: dwc3: core: add support for disabling High-speed park mode 9a4d7dd19903 USB: dwc3: clean up probe declarationsbd82857424d3 USB: dwc3: refactor clock lookups1d72fab47656 USB: dwc3: refactor phy handlingd2f197822d58 USB: dwc3: clean up core init error handlingc8e9eccf6ed2 USB: dwc3: clean up phy init error handlingfe296046c721 USB: dwc3: clean up probe error labelsf56d0d29b018 USB: dwc3: drop dead hibernation codebdb19d01026a USB: dwc3: gadget: drop dead hibernation code6b3b2402ca5b USB: dwc3: disable autosuspend on unbind44d257e9012e USB: dwc3: fix runtime pm imbalance on unbind9a8ad10c9f2e USB: dwc3: fix runtime pm imbalance on probe errors 091b813d3d10 usb: Add explicit of.h of_platform.h include92c08a84b53e usb: dwc3: Add function suspend and function wakeup support 047161686b81 usb: dwc3: Add remote wakeup handling2926c5275028 usb: dwc3-am62: Fix up wake-up configuration and spurious wake up 4e3972b589da usb: dwc3-am62: Enable as a wakeup source by default 84364a00b264 usb: dwc3-am62: Add support for system wakeup based on USB events 4fa1387261e7 usb: remove dead code in dwc3_gadget_get_irq4decf4060ecf usb: dwc3: gadget: Change condition for processing suspend event b84ba26c922a usb: dwc3: core: add external vBus supply support for ulpi phy
--- drivers/usb/dwc3/core.c | 448 ++++++++++++++++------------------- drivers/usb/dwc3/core.h | 23 +- drivers/usb/dwc3/debug.h | 2 + drivers/usb/dwc3/dwc3-am62.c | 52 +++- drivers/usb/dwc3/ep0.c | 19 +- drivers/usb/dwc3/gadget.c | 353 ++++++++++++++++----------- 6 files changed, 497 insertions(+), 400 deletions(-)
drivers/usb/dwc3/core.c +198 -250
@@ -534,90 +534,6 @@ void dwc3_event_buffers_cleanup(struct dwc3 *dwc)dwc3_writel (dwc->regs,DWC3_GEVNTCOUNT (0 ),0 ); } -static int dwc3_alloc_scratch_buffers (struct dwc3 *dwc) -{ -if (!dwc->has_hibernation) -return 0 ; - -if (!dwc->nr_scratch) -return 0 ; - - dwc->scratchbuf =kmalloc_array (dwc->nr_scratch, -DWC3_SCRATCHBUF_SIZE ,GFP_KERNEL ); -if (!dwc->scratchbuf) -return -ENOMEM ; - -return 0 ; -} - -static int dwc3_setup_scratch_buffers (struct dwc3 *dwc) -{ -dma_addr_t scratch_addr; -u32 param; -int ret; - -if (!dwc->has_hibernation) -return 0 ; - -if (!dwc->nr_scratch) -return 0 ; - -/* should never fall here */ -if (!WARN_ON (dwc->scratchbuf)) -return 0 ; - - scratch_addr =dma_map_single (dwc->sysdev, dwc->scratchbuf, - dwc->nr_scratch *DWC3_SCRATCHBUF_SIZE , -DMA_BIDIRECTIONAL ); -if (dma_mapping_error (dwc->sysdev, scratch_addr)) { -dev_err (dwc->sysdev,"failed to map scratch buffer\n" ); - ret = -EFAULT ; - goto err0; - } - - dwc->scratch_addr = scratch_addr; - - param =lower_32_bits (scratch_addr); - - ret =dwc3_send_gadget_generic_command (dwc, -DWC3_DGCMD_SET_SCRATCHPAD_ADDR_LO , param); -if (ret <0 ) - goto err1; - - param =upper_32_bits (scratch_addr); - - ret =dwc3_send_gadget_generic_command (dwc, -DWC3_DGCMD_SET_SCRATCHPAD_ADDR_HI , param); -if (ret <0 ) - goto err1; - -return 0 ; - -err1: -dma_unmap_single (dwc->sysdev, dwc->scratch_addr, dwc->nr_scratch * -DWC3_SCRATCHBUF_SIZE ,DMA_BIDIRECTIONAL ); - -err0: -return ret; -} - -static void dwc3_free_scratch_buffers (struct dwc3 *dwc) -{ -if (!dwc->has_hibernation) -return ; - -if (!dwc->nr_scratch) -return ; - -/* should never fall here */ -if (!WARN_ON (dwc->scratchbuf)) -return ; - -dma_unmap_single (dwc->sysdev, dwc->scratch_addr, dwc->nr_scratch * -DWC3_SCRATCHBUF_SIZE ,DMA_BIDIRECTIONAL ); -kfree (dwc->scratchbuf); -} -static void dwc3_core_num_eps (struct dwc3 *dwc) {struct dwc3_hwparams *parms = &dwc->hwparams;
@@ -800,11 +716,91 @@ static int dwc3_phy_setup(struct dwc3 *dwc)if (dwc->dis_u2_freeclk_exists_quirk || dwc->gfladj_refclk_lpm_sel) reg &= ~DWC3_GUSB2PHYCFG_U2_FREECLK_EXISTS ; +/* +* Some ULPI USB PHY does not support internal VBUS supply, to drive +* the CPEN pin requires the configuration of the ULPI DRVVBUSEXTERNAL +* bit of OTG_CTRL register. Controller configures the USB2 PHY +* ULPIEXTVBUSDRV bit[17] of the GUSB2PHYCFG register to drive vBus +* with an external supply. +*/ +if (dwc->ulpi_ext_vbus_drv) + reg |=DWC3_GUSB2PHYCFG_ULPIEXTVBUSDRV ; +dwc3_writel (dwc->regs,DWC3_GUSB2PHYCFG (0 ), reg);return 0 ; } +static int dwc3_phy_init (struct dwc3 *dwc) +{ +int ret; + +usb_phy_init (dwc->usb2_phy); +usb_phy_init (dwc->usb3_phy); + + ret =phy_init (dwc->usb2_generic_phy); +if (ret <0 ) + goto err_shutdown_usb3_phy; + + ret =phy_init (dwc->usb3_generic_phy); +if (ret <0 ) + goto err_exit_usb2_phy; + +return 0 ; + +err_exit_usb2_phy: +phy_exit (dwc->usb2_generic_phy); +err_shutdown_usb3_phy: +usb_phy_shutdown (dwc->usb3_phy); +usb_phy_shutdown (dwc->usb2_phy); + +return ret; +} + +static void dwc3_phy_exit (struct dwc3 *dwc) +{ +phy_exit (dwc->usb3_generic_phy); +phy_exit (dwc->usb2_generic_phy); + +usb_phy_shutdown (dwc->usb3_phy); +usb_phy_shutdown (dwc->usb2_phy); +} + +static int dwc3_phy_power_on (struct dwc3 *dwc) +{ +int ret; + +usb_phy_set_suspend (dwc->usb2_phy,0 ); +usb_phy_set_suspend (dwc->usb3_phy,0 ); + + ret =phy_power_on (dwc->usb2_generic_phy); +if (ret <0 ) + goto err_suspend_usb3_phy; + + ret =phy_power_on (dwc->usb3_generic_phy); +if (ret <0 ) + goto err_power_off_usb2_phy; + +return 0 ; + +err_power_off_usb2_phy: +phy_power_off (dwc->usb2_generic_phy); +err_suspend_usb3_phy: +usb_phy_set_suspend (dwc->usb3_phy,1 ); +usb_phy_set_suspend (dwc->usb2_phy,1 ); + +return ret; +} + +static void dwc3_phy_power_off (struct dwc3 *dwc) +{ +phy_power_off (dwc->usb3_generic_phy); +phy_power_off (dwc->usb2_generic_phy); + +usb_phy_set_suspend (dwc->usb3_phy,1 ); +usb_phy_set_suspend (dwc->usb2_phy,1 ); +} +static int dwc3_clk_enable (struct dwc3 *dwc) {int ret;
@@ -840,17 +836,8 @@ static void dwc3_clk_disable(struct dwc3 *dwc)static void dwc3_core_exit (struct dwc3 *dwc) {dwc3_event_buffers_cleanup (dwc); - -usb_phy_set_suspend (dwc->usb2_phy,1 ); -usb_phy_set_suspend (dwc->usb3_phy,1 ); -phy_power_off (dwc->usb2_generic_phy); -phy_power_off (dwc->usb3_generic_phy); - -usb_phy_shutdown (dwc->usb2_phy); -usb_phy_shutdown (dwc->usb3_phy); -phy_exit (dwc->usb2_generic_phy); -phy_exit (dwc->usb3_generic_phy); - +dwc3_phy_power_off (dwc); +dwc3_phy_exit (dwc);dwc3_clk_disable (dwc);reset_control_assert (dwc->reset); }
@@ -877,7 +864,6 @@ static bool dwc3_core_is_valid(struct dwc3 *dwc)static void dwc3_core_setup_global_control (struct dwc3 *dwc) { -u32 hwparams4 = dwc->hwparams.hwparams4;u32 reg; reg =dwc3_readl (dwc->regs,DWC3_GCTL );
@@ -905,9 +891,6 @@ static void dwc3_core_setup_global_control(struct dwc3 *dwc) reg &= ~DWC3_GCTL_DSBLCLKGTNG ;break ;case DWC3_GHWPARAMS1_EN_PWROPT_HIB : -/* enable hibernation here */ - dwc->nr_scratch =DWC3_GHWPARAMS4_HIBER_SCRATCHBUFS (hwparams4); -/* * REVISIT Enabling this bit so that host-mode hibernation * will work. Device-mode hibernation is not yet implemented.
@@ -1096,7 +1079,7 @@ static int dwc3_core_init(struct dwc3 *dwc) ret =dwc3_phy_setup (dwc);if (ret) - goto err0; +return ret;if (!dwc->ulpi_ready) { ret =dwc3_core_ulpi_init (dwc);
@@ -1105,7 +1088,7 @@ static int dwc3_core_init(struct dwc3 *dwc)dwc3_core_soft_reset (dwc); ret = -EPROBE_DEFER ; } - goto err0; +return ret; } dwc->ulpi_ready = true; }
@@ -1113,25 +1096,17 @@ static int dwc3_core_init(struct dwc3 *dwc)if (!dwc->phys_ready) { ret =dwc3_core_get_phy (dwc);if (ret) - goto err0a; + goto err_exit_ulpi; dwc->phys_ready = true; } -usb_phy_init (dwc->usb2_phy); -usb_phy_init (dwc->usb3_phy); - ret =phy_init (dwc->usb2_generic_phy); -if (ret <0 ) - goto err0a; - - ret =phy_init (dwc->usb3_generic_phy); -if (ret <0 ) { -phy_exit (dwc->usb2_generic_phy); - goto err0a; - } + ret =dwc3_phy_init (dwc); +if (ret) + goto err_exit_ulpi; ret =dwc3_core_soft_reset (dwc);if (ret) - goto err1; + goto err_exit_phy;if (hw_mode ==DWC3_GHWPARAMS0_MODE_DRD && !DWC3_VER_IS_WITHIN(DWC3, ANY, 194A)) {
@@ -1151,10 +1126,6 @@ static int dwc3_core_init(struct dwc3 *dwc)dwc3_core_setup_global_control (dwc);dwc3_core_num_eps (dwc); - ret =dwc3_setup_scratch_buffers (dwc); -if (ret) - goto err1; -/* Set power down scale of suspend_clk */ dwc3_set_power_down_clk_scale (dwc);
@@ -1166,20 +1137,14 @@ static int dwc3_core_init(struct dwc3 *dwc)dwc3_set_incr_burst_type (dwc); -usb_phy_set_suspend (dwc->usb2_phy,0 ); -usb_phy_set_suspend (dwc->usb3_phy,0 ); - ret =phy_power_on (dwc->usb2_generic_phy); -if (ret <0 ) - goto err2; - - ret =phy_power_on (dwc->usb3_generic_phy); -if (ret <0 ) - goto err3; + ret =dwc3_phy_power_on (dwc); +if (ret) + goto err_exit_phy; ret =dwc3_event_buffers_setup (dwc);if (ret) {dev_err (dwc->dev,"failed to setup event buffers\n" ); - goto err4; + goto err_power_off_phy; }/*
@@ -1233,6 +1198,9 @@ static int dwc3_core_init(struct dwc3 *dwc)if (dwc->parkmode_disable_ss_quirk) reg |=DWC3_GUCTL1_PARKMODE_DISABLE_SS ; +if (dwc->parkmode_disable_hs_quirk) + reg |=DWC3_GUCTL1_PARKMODE_DISABLE_HS ; + if (DWC3_VER_IS_WITHIN(DWC3, 290A, ANY) && (dwc->maximum_speed ==USB_SPEED_HIGH || dwc->maximum_speed ==USB_SPEED_FULL ))
@@ -1296,26 +1264,13 @@ static int dwc3_core_init(struct dwc3 *dwc)return 0 ; -err4: -phy_power_off (dwc->usb3_generic_phy); - -err3: -phy_power_off (dwc->usb2_generic_phy); - -err2: -usb_phy_set_suspend (dwc->usb2_phy,1 ); -usb_phy_set_suspend (dwc->usb3_phy,1 ); - -err1: -usb_phy_shutdown (dwc->usb2_phy); -usb_phy_shutdown (dwc->usb3_phy); -phy_exit (dwc->usb2_generic_phy); -phy_exit (dwc->usb3_generic_phy); - -err0a: +err_power_off_phy: +dwc3_phy_power_off (dwc); +err_exit_phy: +dwc3_phy_exit (dwc); +err_exit_ulpi:dwc3_ulpi_exit (dwc); -err0:return ret; }
@@ -1553,8 +1508,12 @@ static void dwc3_get_properties(struct dwc3 *dwc) "snps,dis-tx-ipgap-linecheck-quirk"); dwc->resume_hs_terminations =device_property_read_bool (dev,"snps,resume-hs-terminations" ); + dwc->ulpi_ext_vbus_drv =device_property_read_bool (dev, +"snps,ulpi-ext-vbus-drv" ); dwc->parkmode_disable_ss_quirk =device_property_read_bool (dev,"snps,parkmode-disable-ss-quirk" ); + dwc->parkmode_disable_hs_quirk =device_property_read_bool (dev, +"snps,parkmode-disable-hs-quirk" ); dwc->gfladj_refclk_lpm_sel =device_property_read_bool (dev,"snps,gfladj-refclk-lpm-sel-quirk" );
@@ -1750,16 +1709,72 @@ static struct extcon_dev *dwc3_get_extcon(struct dwc3 *dwc)return edev; } +static int dwc3_get_clocks (struct dwc3 *dwc) +{ +struct device *dev = dwc->dev; + +if (!dev->of_node) +return 0 ; + +/* +* Clocks are optional, but new DT platforms should support all clocks +* as required by the DT-binding. +* Some devices have different clock names in legacy device trees, +* check for them to retain backwards compatibility. +*/ + dwc->bus_clk =devm_clk_get_optional (dev,"bus_early" ); +if (IS_ERR (dwc->bus_clk)) { +return dev_err_probe (dev,PTR_ERR (dwc->bus_clk), +"could not get bus clock\n" ); + } + +if (dwc->bus_clk ==NULL ) { + dwc->bus_clk =devm_clk_get_optional (dev,"bus_clk" ); +if (IS_ERR (dwc->bus_clk)) { +return dev_err_probe (dev,PTR_ERR (dwc->bus_clk), +"could not get bus clock\n" ); + } + } + + dwc->ref_clk =devm_clk_get_optional (dev,"ref" ); +if (IS_ERR (dwc->ref_clk)) { +return dev_err_probe (dev,PTR_ERR (dwc->ref_clk), +"could not get ref clock\n" ); + } + +if (dwc->ref_clk ==NULL ) { + dwc->ref_clk =devm_clk_get_optional (dev,"ref_clk" ); +if (IS_ERR (dwc->ref_clk)) { +return dev_err_probe (dev,PTR_ERR (dwc->ref_clk), +"could not get ref clock\n" ); + } + } + + dwc->susp_clk =devm_clk_get_optional (dev,"suspend" ); +if (IS_ERR (dwc->susp_clk)) { +return dev_err_probe (dev,PTR_ERR (dwc->susp_clk), +"could not get suspend clock\n" ); + } + +if (dwc->susp_clk ==NULL ) { + dwc->susp_clk =devm_clk_get_optional (dev,"suspend_clk" ); +if (IS_ERR (dwc->susp_clk)) { +return dev_err_probe (dev,PTR_ERR (dwc->susp_clk), +"could not get suspend clock\n" ); + } + } + +return 0 ; +} +static int dwc3_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev;struct resource *res, dwc_res; +void __iomem *regs;struct dwc3 *dwc; -int ret; -void __iomem *regs; - dwc =devm_kzalloc (dev,sizeof (*dwc),GFP_KERNEL );if (!dwc)return -ENOMEM ;
@@ -1797,77 +1812,25 @@ static int dwc3_probe(struct platform_device *pdev) dwc->reset =devm_reset_control_array_get_optional_shared (dev);if (IS_ERR (dwc->reset)) { ret =PTR_ERR (dwc->reset); - goto put_usb_psy; + goto err_put_psy; } -if (dev->of_node) { -/* -* Clocks are optional, but new DT platforms should support all -* clocks as required by the DT-binding. -* Some devices have different clock names in legacy device trees, -* check for them to retain backwards compatibility. -*/ - dwc->bus_clk =devm_clk_get_optional (dev,"bus_early" ); -if (IS_ERR (dwc->bus_clk)) { - ret =dev_err_probe (dev,PTR_ERR (dwc->bus_clk), -"could not get bus clock\n" ); - goto put_usb_psy; - } - -if (dwc->bus_clk ==NULL ) { - dwc->bus_clk =devm_clk_get_optional (dev,"bus_clk" ); -if (IS_ERR (dwc->bus_clk)) { - ret =dev_err_probe (dev,PTR_ERR (dwc->bus_clk), -"could not get bus clock\n" ); - goto put_usb_psy; - } - } - - dwc->ref_clk =devm_clk_get_optional (dev,"ref" ); -if (IS_ERR (dwc->ref_clk)) { - ret =dev_err_probe (dev,PTR_ERR (dwc->ref_clk), -"could not get ref clock\n" ); - goto put_usb_psy; - } - -if (dwc->ref_clk ==NULL ) { - dwc->ref_clk =devm_clk_get_optional (dev,"ref_clk" ); -if (IS_ERR (dwc->ref_clk)) { - ret =dev_err_probe (dev,PTR_ERR (dwc->ref_clk), -"could not get ref clock\n" ); - goto put_usb_psy; - } - } - - dwc->susp_clk =devm_clk_get_optional (dev,"suspend" ); -if (IS_ERR (dwc->susp_clk)) { - ret =dev_err_probe (dev,PTR_ERR (dwc->susp_clk), -"could not get suspend clock\n" ); - goto put_usb_psy; - } - -if (dwc->susp_clk ==NULL ) { - dwc->susp_clk =devm_clk_get_optional (dev,"suspend_clk" ); -if (IS_ERR (dwc->susp_clk)) { - ret =dev_err_probe (dev,PTR_ERR (dwc->susp_clk), -"could not get suspend clock\n" ); - goto put_usb_psy; - } - } - } + ret =dwc3_get_clocks (dwc); +if (ret) + goto err_put_psy; ret =reset_control_deassert (dwc->reset);if (ret) - goto put_usb_psy; + goto err_put_psy; ret =dwc3_clk_enable (dwc);if (ret) - goto assert_reset; + goto err_assert_reset;if (!dwc3_core_is_valid (dwc)) {dev_err (dwc->dev,"this is not a DesignWare USB3 DRD Core\n" ); ret = -ENODEV ; - goto disable_clks; + goto err_disable_clks; }platform_set_drvdata (pdev, dwc);
@@ -1877,19 +1840,17 @@ static int dwc3_probe(struct platform_device *pdev) DWC3_GHWPARAMS0_AWIDTH(dwc->hwparams.hwparams0) == 64) { ret =dma_set_mask_and_coherent (dwc->sysdev,DMA_BIT_MASK (64 ));if (ret) - goto disable_clks; + goto err_disable_clks; }spin_lock_init (&dwc->lock);mutex_init (&dwc->mutex); +pm_runtime_get_noresume (dev);pm_runtime_set_active (dev);pm_runtime_use_autosuspend (dev);pm_runtime_set_autosuspend_delay (dev,DWC3_DEFAULT_AUTOSUSPEND_DELAY );pm_runtime_enable (dev); - ret =pm_runtime_get_sync (dev); -if (ret <0 ) - goto err1;pm_runtime_forbid (dev);
@@ -1897,27 +1858,23 @@ static int dwc3_probe(struct platform_device *pdev)if (ret) {dev_err (dwc->dev,"failed to allocate event buffers\n" ); ret = -ENOMEM ; - goto err2; + goto err_allow_rpm; } dwc->edev =dwc3_get_extcon (dwc);if (IS_ERR (dwc->edev)) { ret =dev_err_probe (dwc->dev,PTR_ERR (dwc->edev),"failed to get extcon\n" ); - goto err3; + goto err_free_event_buffers; } ret =dwc3_get_dr_mode (dwc);if (ret) - goto err3; - - ret =dwc3_alloc_scratch_buffers (dwc); -if (ret) - goto err3; + goto err_free_event_buffers; ret =dwc3_core_init (dwc);if (ret) {dev_err_probe (dev, ret,"failed to initialize core\n" ); - goto err4; + goto err_free_event_buffers; }dwc3_check_params (dwc);
@@ -1925,46 +1882,31 @@ static int dwc3_probe(struct platform_device *pdev) ret =dwc3_core_init_mode (dwc);if (ret) - goto err5; + goto err_exit_debugfs;pm_runtime_put (dev);return 0 ; -err5: +err_exit_debugfs:dwc3_debugfs_exit (dwc);dwc3_event_buffers_cleanup (dwc); - -usb_phy_set_suspend (dwc->usb2_phy,1 ); -usb_phy_set_suspend (dwc->usb3_phy,1 ); -phy_power_off (dwc->usb2_generic_phy); -phy_power_off (dwc->usb3_generic_phy); - -usb_phy_shutdown (dwc->usb2_phy); -usb_phy_shutdown (dwc->usb3_phy); -phy_exit (dwc->usb2_generic_phy); -phy_exit (dwc->usb3_generic_phy); - +dwc3_phy_power_off (dwc); +dwc3_phy_exit (dwc);dwc3_ulpi_exit (dwc); - -err4: -dwc3_free_scratch_buffers (dwc); - -err3: +err_free_event_buffers:dwc3_free_event_buffers (dwc); - -err2: -pm_runtime_allow (&pdev->dev); - -err1: -pm_runtime_put_sync (&pdev->dev); -pm_runtime_disable (&pdev->dev); - -disable_clks: +err_allow_rpm: +pm_runtime_allow (dev); +pm_runtime_disable (dev); +pm_runtime_dont_use_autosuspend (dev); +pm_runtime_set_suspended (dev); +pm_runtime_put_noidle (dev); +err_disable_clks:dwc3_clk_disable (dwc); -assert_reset: +err_assert_reset:reset_control_assert (dwc->reset); -put_usb_psy: +err_put_psy:if (dwc->usb_psy)power_supply_put (dwc->usb_psy);
@@ -1983,12 +1925,18 @@ static int dwc3_remove(struct platform_device *pdev)dwc3_core_exit (dwc);dwc3_ulpi_exit (dwc); +pm_runtime_allow (&pdev->dev);pm_runtime_disable (&pdev->dev); +pm_runtime_dont_use_autosuspend (&pdev->dev);pm_runtime_put_noidle (&pdev->dev); +/* +* HACK: Clear the driver data, which is currently accessed by parent +* glue drivers, before allowing the parent to suspend. +*/ +platform_set_drvdata (pdev,NULL );pm_runtime_set_suspended (&pdev->dev);dwc3_free_event_buffers (dwc); -dwc3_free_scratch_buffers (dwc);if (dwc->usb_psy)power_supply_put (dwc->usb_psy);
drivers/usb/dwc3/core.h +15 -8
@@ -263,6 +263,7 @@#define DWC3_GUCTL1_DEV_FORCE_20_CLK_FOR_30_CLK BIT(26)#define DWC3_GUCTL1_DEV_L1_EXIT_BY_HW BIT(24)#define DWC3_GUCTL1_PARKMODE_DISABLE_SS BIT(17) +#define DWC3_GUCTL1_PARKMODE_DISABLE_HS BIT(16)#define DWC3_GUCTL1_RESUME_OPMODE_HS_HOST BIT(10)/* Global Status Register */
@@ -280,6 +281,7 @@/* Global USB2 PHY Configuration Register */ #define DWC3_GUSB2PHYCFG_PHYSOFTRST BIT(31)#define DWC3_GUSB2PHYCFG_U2_FREECLK_EXISTS BIT(30) +#define DWC3_GUSB2PHYCFG_ULPIEXTVBUSDRV BIT(17)#define DWC3_GUSB2PHYCFG_SUSPHY BIT(6)#define DWC3_GUSB2PHYCFG_ULPI_UTMI BIT(4)#define DWC3_GUSB2PHYCFG_ENBLSLPM BIT(8)
@@ -526,6 +528,7 @@#define DWC3_DGCMD_SET_ENDPOINT_NRDY 0x0c#define DWC3_DGCMD_SET_ENDPOINT_PRIME 0x0d#define DWC3_DGCMD_RUN_SOC_BUS_LOOPBACK 0x10 +#define DWC3_DGCMD_DEV_NOTIFICATION 0x07#define DWC3_DGCMD_STATUS (n) (((n) >> 12) & 0x0F)#define DWC3_DGCMD_CMDACT BIT(10)
@@ -538,6 +541,8 @@#define DWC3_DGCMDPAR_TX_FIFO BIT(5)#define DWC3_DGCMDPAR_LOOPBACK_DIS (0 << 0)#define DWC3_DGCMDPAR_LOOPBACK_ENA BIT(0) +#define DWC3_DGCMDPAR_DN_FUNC_WAKE BIT(0) +#define DWC3_DGCMDPAR_INTF_SEL (n) ((n) << 4)/* Device Endpoint Command Register */ #define DWC3_DEPCMD_PARAM_SHIFT 16
@@ -969,12 +974,10 @@ struct dwc3_scratchpad_array {* @drd_work: workqueue used for role swapping * @ep0_trb: trb which is used for the ctrl_req * @bounce: address of bounce buffer -* @scratchbuf: address of scratch buffer * @setup_buf: used while precessing STD USB requests * @ep0_trb_addr: dma address of @ep0_trb * @bounce_addr: dma address of @bounce * @ep0_usb_req: dummy req used while handling STD USB requests -* @scratch_addr: dma address of scratchbuf * @ep0_in_setup: one control transfer is completed and enter setup phase * @lock: for synchronizing * @mutex: for mode switching
@@ -999,7 +1002,6 @@ struct dwc3_scratchpad_array {* @current_otg_role: current role of operation while using the OTG block * @desired_otg_role: desired role of operation while using the OTG block * @otg_restart_host: flag that OTG controller needs to restart host -* @nr_scratch: number of scratch buffers * @u1u2: only used on revisions <1.83a for workaround * @maximum_speed: maximum speed requested (mainly for testing purposes) * @max_ssp_rate: SuperSpeed Plus maximum signaling rate and lane count
@@ -1056,7 +1058,6 @@ struct dwc3_scratchpad_array {* @delayed_status: true when gadget driver asks for delayed status * @ep0_bounced: true when we used bounce buffer * @ep0_expect_in: true when we expect a DATA IN transfer -* @has_hibernation: true when dwc3 was configured with Hibernation * @sysdev_is_parent: true when dwc3 device has a parent driver * @has_lpm_erratum: true when core was configured with LPM Erratum. Note that * there's now way for software to detect this in runtime.
@@ -1100,8 +1101,12 @@ struct dwc3_scratchpad_array {* check during HS transmit. * @resume_hs_terminations: Set if we enable quirk for fixing improper crc * generation after resume from suspend. +* @ulpi_ext_vbus_drv: Set to confiure the upli chip to drives CPEN pin +* VBUS with an external supply. * @parkmode_disable_ss_quirk: set if we need to disable all SuperSpeed * instances in park mode. +* @parkmode_disable_hs_quirk: set if we need to disable all HishSpeed +* instances in park mode. * @tx_de_emphasis_quirk: set if we enable Tx de-emphasis quirk * @tx_de_emphasis: Tx de-emphasis value * 0 - -6dB de-emphasis
@@ -1110,6 +1115,8 @@ struct dwc3_scratchpad_array {* 3 - Reserved * @dis_metastability_quirk: set to disable metastability quirk. * @dis_split_quirk: set to disable split boundary. +* @wakeup_configured: set if the device is configured for remote wakeup. +* @suspended: set to track suspend event due to U3/L2. * @imod_interval: set the interrupt moderation interval in 250ns * increments or 0 to disable. * @max_cfg_eps: current max number of IN eps used across all USB configs.
@@ -1123,11 +1130,9 @@ struct dwc3 {struct work_struct drd_work;struct dwc3_trb *ep0_trb;void *bounce; -void *scratchbuf;u8 *setup_buf;dma_addr_t ep0_trb_addr;dma_addr_t bounce_addr; -dma_addr_t scratch_addr;struct dwc3_request ep0_usb_req;struct completion ep0_in_setup;
@@ -1187,7 +1192,6 @@ struct dwc3 {u32 current_otg_role;u32 desired_otg_role;bool otg_restart_host; -u32 nr_scratch;u32 u1u2;u32 maximum_speed;u32 gadget_max_speed;
@@ -1284,7 +1288,6 @@ struct dwc3 { unsigned delayed_status:1; unsigned ep0_bounced:1; unsigned ep0_expect_in:1; - unsigned has_hibernation:1; unsigned sysdev_is_parent:1; unsigned has_lpm_erratum:1; unsigned is_utmi_l1_suspend:1;
@@ -1317,7 +1320,9 @@ struct dwc3 { unsigned dis_del_phy_power_chg_quirk:1; unsigned dis_tx_ipgap_linecheck_quirk:1; unsigned resume_hs_terminations:1; + unsigned ulpi_ext_vbus_drv:1; unsigned parkmode_disable_ss_quirk:1; + unsigned parkmode_disable_hs_quirk:1; unsigned gfladj_refclk_lpm_sel:1; unsigned tx_de_emphasis_quirk:1;
@@ -1327,6 +1332,8 @@ struct dwc3 { unsigned dis_split_quirk:1; unsigned async_callbacks:1; + unsigned wakeup_configured:1; + unsigned suspended:1;u16 imod_interval;
drivers/usb/dwc3/debug.h +2 -0
@@ -72,6 +72,8 @@ dwc3_gadget_generic_cmd_string(u8 cmd)return "Set Endpoint Prime" ;case DWC3_DGCMD_RUN_SOC_BUS_LOOPBACK :return "Run SoC Bus Loopback Test" ; +case DWC3_DGCMD_DEV_NOTIFICATION : +return "Device Notification" ;default :return "UNKNOWN" ; }
drivers/usb/dwc3/dwc3-am62.c +51 -1
102 lines not on this page · raw message
drivers/usb/dwc3/ep0.c +11 -8
@@ -30,6 +30,8 @@static void __dwc3_ep0_do_control_status (struct dwc3 *dwc,struct dwc3_ep *dep);static void __dwc3_ep0_do_control_data (struct dwc3 *dwc,struct dwc3_ep *dep,struct dwc3_request *req); +static int dwc3_ep0_delegate_req (struct dwc3 *dwc, +struct usb_ctrlrequest *ctrl);static void dwc3_ep0_prepare_one_trb (struct dwc3_ep *dep,dma_addr_t buf_dma,u32 len,u32 type,bool chain)
@@ -356,6 +358,9 @@ static int dwc3_ep0_handle_status(struct dwc3 *dwc, usb_status |=1 <<USB_DEV_STAT_U1_ENABLED ;if (reg &DWC3_DCTL_INITU2ENA ) usb_status |=1 <<USB_DEV_STAT_U2_ENABLED ; + }else { + usb_status |= dwc->gadget->wakeup_armed << +USB_DEVICE_REMOTE_WAKEUP ; }break ;
@@ -365,7 +370,7 @@ static int dwc3_ep0_handle_status(struct dwc3 *dwc,* Function Remote Wake Capable D0 * Function Remote Wakeup D1 */ -break ; +return dwc3_ep0_delegate_req (dwc, ctrl);case USB_RECIP_ENDPOINT : dep =dwc3_wIndex_to_dep (dwc, ctrl->wIndex);
@@ -476,6 +481,10 @@ static int dwc3_ep0_handle_device(struct dwc3 *dwc,switch (wValue) {case USB_DEVICE_REMOTE_WAKEUP : +if (dwc->wakeup_configured) + dwc->gadget->wakeup_armed = set; +else + ret = -EINVAL ;break ;/* * 9.4.1 says only for SS, in AddressState only for
@@ -510,13 +519,7 @@ static int dwc3_ep0_handle_intf(struct dwc3 *dwc,switch (wValue) {case USB_INTRF_FUNC_SUSPEND : -/* -* REVISIT: Ideally we would enable some low power mode here, -* however it's unclear what we should be doing here. -* -* For now, we're not doing anything, just making sure we return -* 0 so USB Command Verifier tests pass without any errors. -*/ + ret =dwc3_ep0_delegate_req (dwc, ctrl);break ;default : ret = -EINVAL ;
drivers/usb/dwc3/gadget.c +220 -133
583 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH v10 50/63 usb: dwc3: import from kernel v6.5
In reply to Anders RoxellFrom: Jens Wiklander <[email protected]>
Sync Linux kernel dwc3 changes from v6.4 to v6.5.
The following files are preserved across the import:Makefile Kconfig dwc3-meson-g12a.c dwc3-meson-gxl.c dwc3-omap.c dwc3-uniphier.c dwc3-generic.h dwc3-generic.c dwc3-generic-sti.c dwc3-layerscape.c ti_usb_phy.c
Skipping unused files:debugfs.c drd.c dwc3-exynos.c dwc3-haps.c dwc3-imx8mp.c dwc3-keystone.c dwc3-octeon.c dwc3-of-simple.c dwc3-pci.c dwc3-qcom.c dwc3-qcom-legacy.c dwc3-rtk.c dwc3-st.c dwc3-xilinx.c host.c trace.c trace.h ulpi.c
Note that this is a raw import and doesn't build. A fixup commit at the end of the series fixes that.
List of commits: git log --oneline v6.4..v6.5
Commits imported:3ddaa6a27457 usb: dwc3: Properly handle processing of pending events734ae15ab95a Revert "usb: dwc3: core: Enable AutoRetry feature in the controller" e835c0a4e23c usb: dwc3: don't reset device side if dwc3 was configured as host-only c0aabed9cabe usb: dwc3: gadget: Propagate core init errors to UDC during pullup b4a4be847184 USB: fix up merge of 6.4-rc4 into usb-next890258e22117 usb: dwc3-am62: Convert to platform remove callback returning void 0176568702a5 usb: core: Convert to platform remove callback returning void 813f44d57e19 usb: dwc3: gadget: Bail out in pullup if soft reset timeout happens 2f28c3c9c347 usb: dwc3: Add error logs for unknown endpoint eventsec5eb43813a4 usb: dwc3: core: add support for realtek SoCs custom's global register start address
--- drivers/usb/dwc3/core.c | 37 +++++++++++++++--------------------- drivers/usb/dwc3/core.h | 5 ++--- drivers/usb/dwc3/dwc3-am62.c | 5 ++--- drivers/usb/dwc3/ep0.c | 3 +++ drivers/usb/dwc3/gadget.c | 22 ++++++++++++++++++--- 5 files changed, 41 insertions(+), 31 deletions(-)
drivers/usb/dwc3/core.c +15 -22
@@ -277,9 +277,9 @@ int dwc3_core_soft_reset(struct dwc3 *dwc)/* * We're resetting only the device side because, if we're in host mode, * XHCI driver will reset the host block. If dwc3 was configured for -* host-only mode, then we can return early. +* host-only mode or current role is host, then we can return early. */ -if (dwc->current_dr_role ==DWC3_GCTL_PRTCAP_HOST ) +if (dwc->dr_mode ==USB_DR_MODE_HOST || dwc->current_dr_role ==DWC3_GCTL_PRTCAP_HOST )return 0 ; reg =dwc3_readl (dwc->regs,DWC3_DCTL );
@@ -1209,22 +1209,6 @@ static int dwc3_core_init(struct dwc3 *dwc)dwc3_writel (dwc->regs,DWC3_GUCTL1 , reg); } -if (dwc->dr_mode ==USB_DR_MODE_HOST || - dwc->dr_mode ==USB_DR_MODE_OTG ) { - reg =dwc3_readl (dwc->regs,DWC3_GUCTL ); - -/* -* Enable Auto retry Feature to make the controller operating in -* Host mode on seeing transaction errors(CRC errors or internal -* overrun scenerios) on IN transfers to reply to the device -* with a non-terminating retry ACK (i.e, an ACK transcation -* packet with Retry=1 & Nump != 0) -*/ - reg |=DWC3_GUCTL_HSTINAUTORETRY ; - -dwc3_writel (dwc->regs,DWC3_GUCTL , reg); - } -/* * Must config both number of packets and max burst settings to enable * RX and/or TX threshold.
@@ -1800,6 +1784,17 @@ static int dwc3_probe(struct platform_device *pdev) dwc_res = *res; dwc_res.start +=DWC3_GLOBALS_REGS_START ; +if (dev->of_node) { +struct device_node *parent =of_get_parent (dev->of_node); + +if (of_device_is_compatible (parent,"realtek,rtd-dwc3" )) { + dwc_res.start -=DWC3_GLOBALS_REGS_START ; + dwc_res.start +=DWC3_RTK_RTD_GLOBALS_REGS_START ; + } + +of_node_put (parent); + } + regs =devm_ioremap_resource (dev, &dwc_res);if (IS_ERR (regs))return PTR_ERR (regs);
@@ -1913,7 +1908,7 @@ err_put_psy:return ret; } -static int dwc3_remove (struct platform_device *pdev) +static void dwc3_remove (struct platform_device *pdev) {struct dwc3 *dwc =platform_get_drvdata (pdev);
@@ -1940,8 +1935,6 @@ static int dwc3_remove(struct platform_device *pdev)if (dwc->usb_psy)power_supply_put (dwc->usb_psy); - -return 0 ; }#ifdef CONFIG_PM
@@ -2252,7 +2245,7 @@ MODULE_DEVICE_TABLE(acpi, dwc3_acpi_match);static struct platform_driver dwc3_driver = { .probe = dwc3_probe, - .remove = dwc3_remove, + .remove_new = dwc3_remove, .driver = { .name ="dwc3" , .of_match_table =of_match_ptr (of_dwc3_match),
drivers/usb/dwc3/core.h +2 -3
@@ -84,6 +84,8 @@#define DWC3_OTG_REGS_START 0xcc00#define DWC3_OTG_REGS_END 0xccff +#define DWC3_RTK_RTD_GLOBALS_REGS_START 0x8100 +/* Global Registers */ #define DWC3_GSBUSCFG0 0xc100#define DWC3_GSBUSCFG1 0xc104
@@ -254,9 +256,6 @@#define DWC3_GCTL_GBLHIBERNATIONEN BIT(1)#define DWC3_GCTL_DSBLCLKGTNG BIT(0) -/* Global User Control Register */ -#define DWC3_GUCTL_HSTINAUTORETRY BIT(14) -/* Global User Control 1 Register */ #define DWC3_GUCTL1_DEV_DECOUPLE_L1L2_EVT BIT(31)#define DWC3_GUCTL1_TX_IPGAP_LINECHECK_DIS BIT(28)
drivers/usb/dwc3/dwc3-am62.c +2 -3
@@ -275,7 +275,7 @@ static int dwc3_ti_remove_core(struct device *dev, void *c)return 0 ; } -static int dwc3_ti_remove (struct platform_device *pdev) +static void dwc3_ti_remove (struct platform_device *pdev) {struct device *dev = &pdev->dev;struct dwc3_data *data =platform_get_drvdata (pdev);
@@ -294,7 +294,6 @@ static int dwc3_ti_remove(struct platform_device *pdev)pm_runtime_set_suspended (dev);platform_set_drvdata (pdev,NULL ); -return 0 ; }#ifdef CONFIG_PM
@@ -362,7 +361,7 @@ MODULE_DEVICE_TABLE(of, dwc3_ti_of_match);static struct platform_driver dwc3_ti_driver = { .probe = dwc3_ti_probe, - .remove = dwc3_ti_remove, + .remove_new = dwc3_ti_remove, .driver = { .name ="dwc3-am62" , .pm =DEV_PM_OPS ,
drivers/usb/dwc3/ep0.c +3 -0
@@ -1207,5 +1207,8 @@ void dwc3_ep0_interrupt(struct dwc3 *dwc, dep->flags &= ~DWC3_EP_TRANSFER_STARTED ; }break ; +default : +dev_err (dwc->dev,"unknown endpoint event %d\n" , event->endpoint_event); +break ; } }
drivers/usb/dwc3/gadget.c +19 -3
@@ -2703,13 +2703,17 @@ static int dwc3_gadget_soft_disconnect(struct dwc3 *dwc)static int dwc3_gadget_soft_connect (struct dwc3 *dwc) { +int ret; +/* * In the Synopsys DWC_usb31 1.90a programming guide section * 4.1.9, it specifies that for a reconnect after a * device-initiated disconnect requires a core soft reset * (DCTL.CSftRst) before enabling the run/stop bit. */ -dwc3_core_soft_reset (dwc); + ret =dwc3_core_soft_reset (dwc); +if (ret) +return ret;dwc3_event_buffers_setup (dwc);__dwc3_gadget_start (dwc);
@@ -2744,7 +2748,9 @@ static int dwc3_gadget_pullup(struct usb_gadget *g, int is_on) ret =pm_runtime_get_sync (dwc->dev);if (!ret || ret <0 ) {pm_runtime_put (dwc->dev); -return 0 ; +if (ret <0 ) +pm_runtime_set_suspended (dwc->dev); +return ret; }if (dwc->pullups_connected == is_on) {
@@ -3809,6 +3815,9 @@ static void dwc3_endpoint_interrupt(struct dwc3 *dwc,break ;case DWC3_DEPEVT_RXTXFIFOEVT :break ; +default : +dev_err (dwc->dev,"unknown endpoint event %d\n" , event->endpoint_event); +break ; } }
@@ -4446,9 +4455,14 @@ static irqreturn_t dwc3_check_event_buf(struct dwc3_event_buffer *evt)u32 count;if (pm_runtime_suspended (dwc->dev)) { + dwc->pending_events = true; +/* +* Trigger runtime resume. The get() function will be balanced +* after processing the pending events in dwc3_process_pending +* events(). +*/ pm_runtime_get (dwc->dev);disable_irq_nosync (dwc->irq_gadget); - dwc->pending_events = true;return IRQ_HANDLED ; }
@@ -4709,6 +4723,8 @@ void dwc3_gadget_process_pending_events(struct dwc3 *dwc) {if (dwc->pending_events) {dwc3_interrupt (dwc->irq_gadget, dwc->ev_buf); +dwc3_thread_interrupt (dwc->irq_gadget, dwc->ev_buf); +pm_runtime_put (dwc->dev); dwc->pending_events = false;enable_irq (dwc->irq_gadget); }
Signature · 1 line
2.53.0
PATCH v10 51/63 usb: dwc3: import from kernel v6.6
In reply to Anders RoxellFrom: Jens Wiklander <[email protected]>
Sync Linux kernel dwc3 changes from v6.5 to v6.6.
The following files are preserved across the import:Makefile Kconfig dwc3-meson-g12a.c dwc3-meson-gxl.c dwc3-omap.c dwc3-uniphier.c dwc3-generic.h dwc3-generic.c dwc3-generic-sti.c dwc3-layerscape.c ti_usb_phy.c
Skipping unused files:debugfs.c drd.c dwc3-exynos.c dwc3-haps.c dwc3-imx8mp.c dwc3-keystone.c dwc3-octeon.c dwc3-of-simple.c dwc3-pci.c dwc3-qcom.c dwc3-qcom-legacy.c dwc3-rtk.c dwc3-st.c dwc3-xilinx.c host.c trace.c trace.h ulpi.c
Note that this is a raw import and doesn't build. A fixup commit at the end of the series fixes that.
List of commits: git log --oneline v6.5..v6.6
Commits imported:8bea147dfdf8 usb: dwc3: Soft reset phy on probe for host 8d1de0ebce71 usb: dwc3: remove unnecessary platform_set_drvdata() 3609699c32aa usb: dwc3-am62: Rename private data
--- drivers/usb/dwc3/core.c | 39 ++++++++++++++- drivers/usb/dwc3/dwc3-am62.c | 96 ++++++++++++++++++------------------ 2 files changed, 85 insertions(+), 50 deletions(-)
drivers/usb/dwc3/core.c +38 -1
@@ -279,9 +279,46 @@ int dwc3_core_soft_reset(struct dwc3 *dwc)* XHCI driver will reset the host block. If dwc3 was configured for * host-only mode or current role is host, then we can return early. */ -if (dwc->dr_mode ==USB_DR_MODE_HOST || dwc->current_dr_role ==DWC3_GCTL_PRTCAP_HOST ) +if (dwc->current_dr_role ==DWC3_GCTL_PRTCAP_HOST )return 0 ; +/* +* If the dr_mode is host and the dwc->current_dr_role is not the +* corresponding DWC3_GCTL_PRTCAP_HOST, then the dwc3_core_init_mode +* isn't executed yet. Ensure the phy is ready before the controller +* updates the GCTL.PRTCAPDIR or other settings by soft-resetting +* the phy. +* +* Note: GUSB3PIPECTL[n] and GUSB2PHYCFG[n] are port settings where n +* is port index. If this is a multiport host, then we need to reset +* all active ports. +*/ +if (dwc->dr_mode ==USB_DR_MODE_HOST ) { +u32 usb3_port; +u32 usb2_port; + + usb3_port =dwc3_readl (dwc->regs,DWC3_GUSB3PIPECTL (0 )); + usb3_port |=DWC3_GUSB3PIPECTL_PHYSOFTRST ; +dwc3_writel (dwc->regs,DWC3_GUSB3PIPECTL (0 ), usb3_port); + + usb2_port =dwc3_readl (dwc->regs,DWC3_GUSB2PHYCFG (0 )); + usb2_port |=DWC3_GUSB2PHYCFG_PHYSOFTRST ; +dwc3_writel (dwc->regs,DWC3_GUSB2PHYCFG (0 ), usb2_port); + +/* Small delay for phy reset assertion */ +usleep_range (1000 ,2000 ); + + usb3_port &= ~DWC3_GUSB3PIPECTL_PHYSOFTRST ; +dwc3_writel (dwc->regs,DWC3_GUSB3PIPECTL (0 ), usb3_port); + + usb2_port &= ~DWC3_GUSB2PHYCFG_PHYSOFTRST ; +dwc3_writel (dwc->regs,DWC3_GUSB2PHYCFG (0 ), usb2_port); + +/* Wait for clock synchronization */ +msleep (50 ); +return 0 ; + } + reg =dwc3_readl (dwc->regs,DWC3_DCTL ); reg |=DWC3_DCTL_CSFTRST ; reg &= ~DWC3_DCTL_RUN_STOP ;
drivers/usb/dwc3/dwc3-am62.c +47 -49
230 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH v10 52/63 usb: dwc3: import from kernel v6.7
In reply to Anders RoxellFrom: Jens Wiklander <[email protected]>
Sync Linux kernel dwc3 changes from v6.6 to v6.7.
The following files are preserved across the import:Makefile Kconfig dwc3-meson-g12a.c dwc3-meson-gxl.c dwc3-omap.c dwc3-uniphier.c dwc3-generic.h dwc3-generic.c dwc3-generic-sti.c dwc3-layerscape.c ti_usb_phy.c
Skipping unused files:debugfs.c drd.c dwc3-exynos.c dwc3-haps.c dwc3-imx8mp.c dwc3-keystone.c dwc3-octeon.c dwc3-of-simple.c dwc3-pci.c dwc3-qcom.c dwc3-qcom-legacy.c dwc3-rtk.c dwc3-st.c dwc3-xilinx.c host.c trace.c trace.h ulpi.c
Note that this is a raw import and doesn't build. A fixup commit at the end of the series fixes that.
List of commits: git log --oneline v6.6..v6.7
Commits imported:8bbae288a85a usb: dwc3: set the dma max_seg_size 97789b93b792 usb: dwc3: add optional PHY interface clocks e24bc293a6a6 usb: dwc3: document gfladj_refclk_lpm_sel field e72fc8d6a12a usb: dwc3: core: configure TX/RX threshold for DWC3_IP
--- drivers/usb/dwc3/core.c | 190 ++++++++++++++++++++++++++++++++-------- drivers/usb/dwc3/core.h | 19 ++++ 2 files changed, 173 insertions(+), 36 deletions(-)
drivers/usb/dwc3/core.c +154 -36
@@ -854,8 +854,20 @@ static int dwc3_clk_enable(struct dwc3 *dwc)if (ret) goto disable_ref_clk; + ret =clk_prepare_enable (dwc->utmi_clk); +if (ret) + goto disable_susp_clk; + + ret =clk_prepare_enable (dwc->pipe_clk); +if (ret) + goto disable_utmi_clk; +return 0 ; +disable_utmi_clk: +clk_disable_unprepare (dwc->utmi_clk); +disable_susp_clk: +clk_disable_unprepare (dwc->susp_clk); disable_ref_clk:clk_disable_unprepare (dwc->ref_clk); disable_bus_clk:
@@ -865,6 +877,8 @@ disable_bus_clk:static void dwc3_clk_disable (struct dwc3 *dwc) { +clk_disable_unprepare (dwc->pipe_clk); +clk_disable_unprepare (dwc->utmi_clk);clk_disable_unprepare (dwc->susp_clk);clk_disable_unprepare (dwc->ref_clk);clk_disable_unprepare (dwc->bus_clk);
@@ -1094,6 +1108,111 @@ static void dwc3_set_power_down_clk_scale(struct dwc3 *dwc) } } +static void dwc3_config_threshold (struct dwc3 *dwc) +{ +u32 reg; +u8 rx_thr_num; +u8 rx_maxburst; +u8 tx_thr_num; +u8 tx_maxburst; + +/* +* Must config both number of packets and max burst settings to enable +* RX and/or TX threshold. +*/ +if (!DWC3_IP_IS (DWC3 ) && dwc->dr_mode ==USB_DR_MODE_HOST ) { + rx_thr_num = dwc->rx_thr_num_pkt_prd; + rx_maxburst = dwc->rx_max_burst_prd; + tx_thr_num = dwc->tx_thr_num_pkt_prd; + tx_maxburst = dwc->tx_max_burst_prd; + +if (rx_thr_num && rx_maxburst) { + reg =dwc3_readl (dwc->regs,DWC3_GRXTHRCFG ); + reg |=DWC31_RXTHRNUMPKTSEL_PRD ; + + reg &= ~DWC31_RXTHRNUMPKT_PRD (~0 ); + reg |=DWC31_RXTHRNUMPKT_PRD (rx_thr_num); + + reg &= ~DWC31_MAXRXBURSTSIZE_PRD (~0 ); + reg |=DWC31_MAXRXBURSTSIZE_PRD (rx_maxburst); + +dwc3_writel (dwc->regs,DWC3_GRXTHRCFG , reg); + } + +if (tx_thr_num && tx_maxburst) { + reg =dwc3_readl (dwc->regs,DWC3_GTXTHRCFG ); + reg |=DWC31_TXTHRNUMPKTSEL_PRD ; + + reg &= ~DWC31_TXTHRNUMPKT_PRD (~0 ); + reg |=DWC31_TXTHRNUMPKT_PRD (tx_thr_num); + + reg &= ~DWC31_MAXTXBURSTSIZE_PRD (~0 ); + reg |=DWC31_MAXTXBURSTSIZE_PRD (tx_maxburst); + +dwc3_writel (dwc->regs,DWC3_GTXTHRCFG , reg); + } + } + + rx_thr_num = dwc->rx_thr_num_pkt; + rx_maxburst = dwc->rx_max_burst; + tx_thr_num = dwc->tx_thr_num_pkt; + tx_maxburst = dwc->tx_max_burst; + +if (DWC3_IP_IS (DWC3 )) { +if (rx_thr_num && rx_maxburst) { + reg =dwc3_readl (dwc->regs,DWC3_GRXTHRCFG ); + reg |=DWC3_GRXTHRCFG_PKTCNTSEL ; + + reg &= ~DWC3_GRXTHRCFG_RXPKTCNT (~0 ); + reg |=DWC3_GRXTHRCFG_RXPKTCNT (rx_thr_num); + + reg &= ~DWC3_GRXTHRCFG_MAXRXBURSTSIZE (~0 ); + reg |=DWC3_GRXTHRCFG_MAXRXBURSTSIZE (rx_maxburst); + +dwc3_writel (dwc->regs,DWC3_GRXTHRCFG , reg); + } + +if (tx_thr_num && tx_maxburst) { + reg =dwc3_readl (dwc->regs,DWC3_GTXTHRCFG ); + reg |=DWC3_GTXTHRCFG_PKTCNTSEL ; + + reg &= ~DWC3_GTXTHRCFG_TXPKTCNT (~0 ); + reg |=DWC3_GTXTHRCFG_TXPKTCNT (tx_thr_num); + + reg &= ~DWC3_GTXTHRCFG_MAXTXBURSTSIZE (~0 ); + reg |=DWC3_GTXTHRCFG_MAXTXBURSTSIZE (tx_maxburst); + +dwc3_writel (dwc->regs,DWC3_GTXTHRCFG , reg); + } + }else { +if (rx_thr_num && rx_maxburst) { + reg =dwc3_readl (dwc->regs,DWC3_GRXTHRCFG ); + reg |=DWC31_GRXTHRCFG_PKTCNTSEL ; + + reg &= ~DWC31_GRXTHRCFG_RXPKTCNT (~0 ); + reg |=DWC31_GRXTHRCFG_RXPKTCNT (rx_thr_num); + + reg &= ~DWC31_GRXTHRCFG_MAXRXBURSTSIZE (~0 ); + reg |=DWC31_GRXTHRCFG_MAXRXBURSTSIZE (rx_maxburst); + +dwc3_writel (dwc->regs,DWC3_GRXTHRCFG , reg); + } + +if (tx_thr_num && tx_maxburst) { + reg =dwc3_readl (dwc->regs,DWC3_GTXTHRCFG ); + reg |=DWC31_GTXTHRCFG_PKTCNTSEL ; + + reg &= ~DWC31_GTXTHRCFG_TXPKTCNT (~0 ); + reg |=DWC31_GTXTHRCFG_TXPKTCNT (tx_thr_num); + + reg &= ~DWC31_GTXTHRCFG_MAXTXBURSTSIZE (~0 ); + reg |=DWC31_GTXTHRCFG_MAXTXBURSTSIZE (tx_maxburst); + +dwc3_writel (dwc->regs,DWC3_GTXTHRCFG , reg); + } + } +} +/** * dwc3_core_init - Low-level initialization of DWC3 Core * @dwc: Pointer to our controller context structure
@@ -1246,42 +1365,7 @@ static int dwc3_core_init(struct dwc3 *dwc)dwc3_writel (dwc->regs,DWC3_GUCTL1 , reg); } -/* -* Must config both number of packets and max burst settings to enable -* RX and/or TX threshold. -*/ -if (!DWC3_IP_IS (DWC3 ) && dwc->dr_mode ==USB_DR_MODE_HOST ) { -u8 rx_thr_num = dwc->rx_thr_num_pkt_prd; -u8 rx_maxburst = dwc->rx_max_burst_prd; -u8 tx_thr_num = dwc->tx_thr_num_pkt_prd; -u8 tx_maxburst = dwc->tx_max_burst_prd; - -if (rx_thr_num && rx_maxburst) { - reg =dwc3_readl (dwc->regs,DWC3_GRXTHRCFG ); - reg |=DWC31_RXTHRNUMPKTSEL_PRD ; - - reg &= ~DWC31_RXTHRNUMPKT_PRD (~0 ); - reg |=DWC31_RXTHRNUMPKT_PRD (rx_thr_num); - - reg &= ~DWC31_MAXRXBURSTSIZE_PRD (~0 ); - reg |=DWC31_MAXRXBURSTSIZE_PRD (rx_maxburst); - -dwc3_writel (dwc->regs,DWC3_GRXTHRCFG , reg); - } - -if (tx_thr_num && tx_maxburst) { - reg =dwc3_readl (dwc->regs,DWC3_GTXTHRCFG ); - reg |=DWC31_TXTHRNUMPKTSEL_PRD ; - - reg &= ~DWC31_TXTHRNUMPKT_PRD (~0 ); - reg |=DWC31_TXTHRNUMPKT_PRD (tx_thr_num); - - reg &= ~DWC31_MAXTXBURSTSIZE_PRD (~0 ); - reg |=DWC31_MAXTXBURSTSIZE_PRD (tx_maxburst); - -dwc3_writel (dwc->regs,DWC3_GTXTHRCFG , reg); - } - } +dwc3_config_threshold (dwc);return 0 ;
@@ -1417,6 +1501,10 @@ static void dwc3_get_properties(struct dwc3 *dwc)u8 lpm_nyet_threshold;u8 tx_de_emphasis;u8 hird_threshold; +u8 rx_thr_num_pkt =0 ; +u8 rx_max_burst =0 ; +u8 tx_thr_num_pkt =0 ; +u8 tx_max_burst =0 ;u8 rx_thr_num_pkt_prd =0 ;u8 rx_max_burst_prd =0 ;u8 tx_thr_num_pkt_prd =0 ;
@@ -1479,6 +1567,14 @@ static void dwc3_get_properties(struct dwc3 *dwc) "snps,usb2-lpm-disable"); dwc->usb2_gadget_lpm_disable =device_property_read_bool (dev,"snps,usb2-gadget-lpm-disable" ); +device_property_read_u8 (dev,"snps,rx-thr-num-pkt" , + &rx_thr_num_pkt); +device_property_read_u8 (dev,"snps,rx-max-burst" , + &rx_max_burst); +device_property_read_u8 (dev,"snps,tx-thr-num-pkt" , + &tx_thr_num_pkt); +device_property_read_u8 (dev,"snps,tx-max-burst" , + &tx_max_burst);device_property_read_u8 (dev,"snps,rx-thr-num-pkt-prd" , &rx_thr_num_pkt_prd); device_property_read_u8(dev, "snps,rx-max-burst-prd",
@@ -1560,6 +1656,12 @@ static void dwc3_get_properties(struct dwc3 *dwc) dwc->hird_threshold = hird_threshold; + dwc->rx_thr_num_pkt = rx_thr_num_pkt; + dwc->rx_max_burst = rx_max_burst; + + dwc->tx_thr_num_pkt = tx_thr_num_pkt; + dwc->tx_max_burst = tx_max_burst; + dwc->rx_thr_num_pkt_prd = rx_thr_num_pkt_prd; dwc->rx_max_burst_prd = rx_max_burst_prd;
@@ -1785,6 +1887,20 @@ static int dwc3_get_clocks(struct dwc3 *dwc) } } +/* specific to Rockchip RK3588 */ + dwc->utmi_clk =devm_clk_get_optional (dev,"utmi" ); +if (IS_ERR (dwc->utmi_clk)) { +return dev_err_probe (dev,PTR_ERR (dwc->utmi_clk), +"could not get utmi clock\n" ); + } + +/* specific to Rockchip RK3588 */ + dwc->pipe_clk =devm_clk_get_optional (dev,"pipe" ); +if (IS_ERR (dwc->pipe_clk)) { +return dev_err_probe (dev,PTR_ERR (dwc->pipe_clk), +"could not get pipe clock\n" ); + } +return 0 ; }
@@ -1918,6 +2034,8 @@ static int dwc3_probe(struct platform_device *pdev)pm_runtime_put (dev); +dma_set_max_seg_size (dev,UINT_MAX ); +return 0 ; err_exit_debugfs:
drivers/usb/dwc3/core.h +19 -0
@@ -211,6 +211,11 @@#define DWC3_GRXTHRCFG_RXPKTCNT (n) (((n) & 0xf) << 24)#define DWC3_GRXTHRCFG_PKTCNTSEL BIT(29) +/* Global TX Threshold Configuration Register */ +#define DWC3_GTXTHRCFG_MAXTXBURSTSIZE (n) (((n) & 0xff) << 16) +#define DWC3_GTXTHRCFG_TXPKTCNT (n) (((n) & 0xf) << 24) +#define DWC3_GTXTHRCFG_PKTCNTSEL BIT(29) +/* Global RX Threshold Configuration Register for DWC_usb31 only */ #define DWC31_GRXTHRCFG_MAXRXBURSTSIZE (n) (((n) & 0x1f) << 16)#define DWC31_GRXTHRCFG_RXPKTCNT (n) (((n) & 0x1f) << 21)
@@ -991,6 +996,8 @@ struct dwc3_scratchpad_array {* @bus_clk: clock for accessing the registers * @ref_clk: reference clock * @susp_clk: clock used when the SS phy is in low power (S3) state +* @utmi_clk: clock used for USB2 PHY communication +* @pipe_clk: clock used for USB3 PHY communication * @reset: reset control * @regs: base address for our registers * @regs_size: address space size
@@ -1045,6 +1052,10 @@ struct dwc3_scratchpad_array {* @test_mode_nr: test feature selector * @lpm_nyet_threshold: LPM NYET response threshold * @hird_threshold: HIRD threshold +* @rx_thr_num_pkt: USB receive packet count +* @rx_max_burst: max USB receive burst size +* @tx_thr_num_pkt: USB transmit packet count +* @tx_max_burst: max USB transmit burst size * @rx_thr_num_pkt_prd: periodic ESS receive packet count * @rx_max_burst_prd: max periodic ESS receive burst size * @tx_thr_num_pkt_prd: periodic ESS transmit packet count
@@ -1106,6 +1117,8 @@ struct dwc3_scratchpad_array {* instances in park mode. * @parkmode_disable_hs_quirk: set if we need to disable all HishSpeed * instances in park mode. +* @gfladj_refclk_lpm_sel: set if we need to enable SOF/ITP counter +* running based on ref_clk * @tx_de_emphasis_quirk: set if we enable Tx de-emphasis quirk * @tx_de_emphasis: Tx de-emphasis value * 0 - -6dB de-emphasis
@@ -1156,6 +1169,8 @@ struct dwc3 {struct clk *bus_clk;struct clk *ref_clk;struct clk *susp_clk; +struct clk *utmi_clk; +struct clk *pipe_clk;struct reset_control *reset;
@@ -1273,6 +1288,10 @@ struct dwc3 {u8 test_mode_nr;u8 lpm_nyet_threshold;u8 hird_threshold; +u8 rx_thr_num_pkt; +u8 rx_max_burst; +u8 tx_thr_num_pkt; +u8 tx_max_burst;u8 rx_thr_num_pkt_prd;u8 rx_max_burst_prd;u8 tx_thr_num_pkt_prd;
Signature · 1 line
2.53.0
PATCH v10 53/63 usb: dwc3: import from kernel v6.8
In reply to Anders RoxellFrom: Jens Wiklander <[email protected]>
Sync Linux kernel dwc3 changes from v6.7 to v6.8.
The following files are preserved across the import:Makefile Kconfig dwc3-meson-g12a.c dwc3-meson-gxl.c dwc3-omap.c dwc3-uniphier.c dwc3-generic.h dwc3-generic.c dwc3-generic-sti.c dwc3-layerscape.c ti_usb_phy.c
Skipping unused files:debugfs.c drd.c dwc3-exynos.c dwc3-haps.c dwc3-imx8mp.c dwc3-keystone.c dwc3-octeon.c dwc3-of-simple.c dwc3-pci.c dwc3-qcom.c dwc3-qcom-legacy.c dwc3-rtk.c dwc3-st.c dwc3-xilinx.c host.c trace.c trace.h ulpi.c
Note that this is a raw import and doesn't build. A fixup commit at the end of the series fixes that.
List of commits: git log --oneline v6.7..v6.8
Commits imported:b191a18cb5c4 usb: dwc3: gadget: Don't disconnect if not started7d708c145b26 Revert "usb: dwc3: Support EBC feature of DWC_usb31" 61a348857e86 usb: dwc3: gadget: Fix NULL pointer dereference in dwc3_gadget_suspend 3c7af52c7616 usb: dwc3: gadget: Queue PM runtime idle on disconnect event 68c26fe58182 usb: dwc3: set pm runtime active before resume common 398aa9a7e77c usb: dwc3: Support EBC feature of DWC_usb3191736d0619eb usb: dwc3: core: set force_gen1 bit in USB31 devices if max speed is SS e9d40b215e38 usb: dwc: ep0: Update request status in dwc3_ep0_stall_restart 730e12fbec53 usb: dwc3: gadget: Handle EP0 request dequeuing properly afe28cd686ae Revert "usb: dwc3: don't reset device side if dwc3 was configured as host-only" 7059fbebcb00 Revert "usb: dwc3: Soft reset phy on probe for host"
--- drivers/usb/dwc3/core.c | 60 +++++++++++++-------------------------- drivers/usb/dwc3/core.h | 5 ++++ drivers/usb/dwc3/ep0.c | 5 +++- drivers/usb/dwc3/gadget.c | 30 ++++++++++++++++---- 4 files changed, 53 insertions(+), 47 deletions(-)
drivers/usb/dwc3/core.c +19 -41
@@ -277,48 +277,11 @@ int dwc3_core_soft_reset(struct dwc3 *dwc)/* * We're resetting only the device side because, if we're in host mode, * XHCI driver will reset the host block. If dwc3 was configured for -* host-only mode or current role is host, then we can return early. +* host-only mode, then we can return early. */ if (dwc->current_dr_role ==DWC3_GCTL_PRTCAP_HOST )return 0 ; -/* -* If the dr_mode is host and the dwc->current_dr_role is not the -* corresponding DWC3_GCTL_PRTCAP_HOST, then the dwc3_core_init_mode -* isn't executed yet. Ensure the phy is ready before the controller -* updates the GCTL.PRTCAPDIR or other settings by soft-resetting -* the phy. -* -* Note: GUSB3PIPECTL[n] and GUSB2PHYCFG[n] are port settings where n -* is port index. If this is a multiport host, then we need to reset -* all active ports. -*/ -if (dwc->dr_mode ==USB_DR_MODE_HOST ) { -u32 usb3_port; -u32 usb2_port; - - usb3_port =dwc3_readl (dwc->regs,DWC3_GUSB3PIPECTL (0 )); - usb3_port |=DWC3_GUSB3PIPECTL_PHYSOFTRST ; -dwc3_writel (dwc->regs,DWC3_GUSB3PIPECTL (0 ), usb3_port); - - usb2_port =dwc3_readl (dwc->regs,DWC3_GUSB2PHYCFG (0 )); - usb2_port |=DWC3_GUSB2PHYCFG_PHYSOFTRST ; -dwc3_writel (dwc->regs,DWC3_GUSB2PHYCFG (0 ), usb2_port); - -/* Small delay for phy reset assertion */ -usleep_range (1000 ,2000 ); - - usb3_port &= ~DWC3_GUSB3PIPECTL_PHYSOFTRST ; -dwc3_writel (dwc->regs,DWC3_GUSB3PIPECTL (0 ), usb3_port); - - usb2_port &= ~DWC3_GUSB2PHYCFG_PHYSOFTRST ; -dwc3_writel (dwc->regs,DWC3_GUSB2PHYCFG (0 ), usb2_port); - -/* Wait for clock synchronization */ -msleep (50 ); -return 0 ; - } - reg =dwc3_readl (dwc->regs,DWC3_DCTL ); reg |=DWC3_DCTL_CSFTRST ; reg &= ~DWC3_DCTL_RUN_STOP ;
@@ -1367,6 +1330,18 @@ static int dwc3_core_init(struct dwc3 *dwc)dwc3_config_threshold (dwc); +/* +* Modify this for all supported Super Speed ports when +* multiport support is added. +*/ +if (hw_mode !=DWC3_GHWPARAMS0_MODE_GADGET && + (DWC3_IP_IS (DWC31 )) && + dwc->maximum_speed ==USB_SPEED_SUPER ) { + reg =dwc3_readl (dwc->regs,DWC3_LLUCTL ); + reg |=DWC3_LLUCTL_FORCE_GEN1 ; +dwc3_writel (dwc->regs,DWC3_LLUCTL , reg); + } +return 0 ; err_power_off_phy:
@@ -2340,12 +2315,15 @@ static int dwc3_resume(struct device *dev)pinctrl_pm_select_default_state (dev); +pm_runtime_disable (dev); +pm_runtime_set_active (dev); + ret =dwc3_resume_common (dwc,PMSG_RESUME ); -if (ret) +if (ret) { +pm_runtime_set_suspended (dev);return ret; + } -pm_runtime_disable (dev); -pm_runtime_set_active (dev);pm_runtime_enable (dev);return 0 ;
drivers/usb/dwc3/core.h +5 -0
@@ -172,6 +172,8 @@#define DWC3_OEVTEN 0xcc0C#define DWC3_OSTS 0xcc10 +#define DWC3_LLUCTL 0xd024 +/* Bit fields */ /* Global SoC Bus Configuration INCRx Register 0 */
@@ -657,6 +659,9 @@#define DWC3_OSTS_VBUSVLD BIT(1)#define DWC3_OSTS_CONIDSTS BIT(0) +/* Force Gen1 speed on Gen2 link */ +#define DWC3_LLUCTL_FORCE_GEN1 BIT(10) +/* Structures */ struct dwc3_trb ;
drivers/usb/dwc3/ep0.c +4 -1
@@ -238,7 +238,10 @@ void dwc3_ep0_stall_and_restart(struct dwc3 *dwc)struct dwc3_request *req; req =next_request (&dep->pending_list); -dwc3_gadget_giveback (dep, req, -ECONNRESET ); +if (!dwc->connected) +dwc3_gadget_giveback (dep, req, -ESHUTDOWN ); +else +dwc3_gadget_giveback (dep, req, -ECONNRESET ); } dwc->eps[0 ]->trb_enqueue =0 ;
drivers/usb/dwc3/gadget.c +25 -5
@@ -2103,7 +2103,17 @@ static int dwc3_gadget_ep_dequeue(struct usb_ep *ep,list_for_each_entry (r, &dep->pending_list, list) {if (r == req) { -dwc3_gadget_giveback (dep, req, -ECONNRESET ); +/* +* Explicitly check for EP0/1 as dequeue for those +* EPs need to be handled differently. Control EP +* only deals with one USB req, and giveback will +* occur during dwc3_ep0_stall_and_restart(). EP0 +* requests are never added to started_list. +*/ +if (dep->number >1 ) +dwc3_gadget_giveback (dep, req, -ECONNRESET ); +else +dwc3_ep0_reset_state (dwc); goto out; } }
@@ -2640,6 +2650,11 @@ static int dwc3_gadget_soft_disconnect(struct dwc3 *dwc)int ret;spin_lock_irqsave (&dwc->lock, flags); +if (!dwc->pullups_connected) { +spin_unlock_irqrestore (&dwc->lock, flags); +return 0 ; + } + dwc->connected = false;/*
@@ -3973,6 +3988,13 @@ static void dwc3_gadget_disconnect_interrupt(struct dwc3 *dwc)usb_gadget_set_state (dwc->gadget,USB_STATE_NOTATTACHED );dwc3_ep0_reset_state (dwc); + +/* +* Request PM idle to address condition where usage count is +* already decremented to zero, but waiting for the disconnect +* interrupt to set dwc->connected to FALSE. +*/ +pm_request_idle (dwc->dev); }static void dwc3_gadget_reset_interrupt (struct dwc3 *dwc)
@@ -4686,15 +4708,13 @@ int dwc3_gadget_suspend(struct dwc3 *dwc)unsigned long flags;int ret; -if (!dwc->gadget_driver) -return 0 ; - ret =dwc3_gadget_soft_disconnect (dwc);if (ret) goto err;spin_lock_irqsave (&dwc->lock, flags); -dwc3_disconnect_gadget (dwc); +if (dwc->gadget_driver) +dwc3_disconnect_gadget (dwc);spin_unlock_irqrestore (&dwc->lock, flags);return 0 ;
Signature · 1 line
2.53.0
PATCH v10 54/63 usb: dwc3: import from kernel v6.9
In reply to Anders RoxellFrom: Jens Wiklander <[email protected]>
Sync Linux kernel dwc3 changes from v6.8 to v6.9.
The following files are preserved across the import:Makefile Kconfig dwc3-meson-g12a.c dwc3-meson-gxl.c dwc3-omap.c dwc3-uniphier.c dwc3-generic.h dwc3-generic.c dwc3-generic-sti.c dwc3-layerscape.c ti_usb_phy.c
Skipping unused files:debugfs.c drd.c dwc3-exynos.c dwc3-haps.c dwc3-imx8mp.c dwc3-keystone.c dwc3-octeon.c dwc3-of-simple.c dwc3-pci.c dwc3-qcom.c dwc3-qcom-legacy.c dwc3-rtk.c dwc3-st.c dwc3-xilinx.c host.c trace.c trace.h ulpi.c
Note that this is a raw import and doesn't build. A fixup commit at the end of the series fixes that.
List of commits: git log --oneline v6.8..v6.9
Commits imported:6d735722063a usb: dwc3: core: Prevent phy suspend during init f2e0eee47038 usb: dwc3: ep0: Don't reset resource alloc flag f9aa41130ac6 usb: dwc3: Properly set system wakeup1e43c86d84fb usb: dwc3: core: Add DWC31 version 2.00a controller f0b9c578408e usb: dwc3-am62: add workaround for Errata i2409 d78ff37567c9 usb: dwc3-am62: Fix PHY core voltage selection 4ead695e6b3c usb: dwc3-am62: Disable wakeup at remove6661befe4100 usb: dwc3-am62: fix module unload/reload behavior a6ba1e453174 usb: dwc3: apply snps,host-vbus-glitches workaround unconditionally 50c72a46eb41 usb: dwc3: gadget: Remove redundant assignment to pointer trb b311048c174d usb: dwc3: gadget: Rewrite endpoint allocation flow 2d2a3349521d usb: dwc3: Add workaround for host mode VBUS glitch when boot
--- drivers/usb/dwc3/core.c | 92 ++++++++++++++----------------- drivers/usb/dwc3/core.h | 5 ++ drivers/usb/dwc3/dwc3-am62.c | 42 ++++++++++---- drivers/usb/dwc3/ep0.c | 4 +- drivers/usb/dwc3/gadget.c | 103 +++++++++++++++++------------------ drivers/usb/dwc3/gadget.h | 1 + 6 files changed, 130 insertions(+), 117 deletions(-)
drivers/usb/dwc3/core.c +40 -52
@@ -104,6 +104,27 @@ static int dwc3_get_dr_mode(struct dwc3 *dwc)return 0 ; } +void dwc3_enable_susphy (struct dwc3 *dwc,bool enable) +{ +u32 reg; + + reg =dwc3_readl (dwc->regs,DWC3_GUSB3PIPECTL (0 )); +if (enable && !dwc->dis_u3_susphy_quirk) + reg |=DWC3_GUSB3PIPECTL_SUSPHY ; +else + reg &= ~DWC3_GUSB3PIPECTL_SUSPHY ; + +dwc3_writel (dwc->regs,DWC3_GUSB3PIPECTL (0 ), reg); + + reg =dwc3_readl (dwc->regs,DWC3_GUSB2PHYCFG (0 )); +if (enable && !dwc->dis_u2_susphy_quirk) + reg |=DWC3_GUSB2PHYCFG_SUSPHY ; +else + reg &= ~DWC3_GUSB2PHYCFG_SUSPHY ; + +dwc3_writel (dwc->regs,DWC3_GUSB2PHYCFG (0 ), reg); +} +void dwc3_set_prtcap (struct dwc3 *dwc,u32 mode) {u32 reg;
@@ -585,11 +606,8 @@ static int dwc3_core_ulpi_init(struct dwc3 *dwc)*/ static int dwc3_phy_setup (struct dwc3 *dwc) { -unsigned int hw_mode;u32 reg; - hw_mode =DWC3_GHWPARAMS0_MODE (dwc->hwparams.hwparams0); - reg =dwc3_readl (dwc->regs,DWC3_GUSB3PIPECTL (0 ));/*
@@ -599,21 +617,16 @@ static int dwc3_phy_setup(struct dwc3 *dwc) reg &= ~DWC3_GUSB3PIPECTL_UX_EXIT_PX ;/* -* Above 1.94a, it is recommended to set DWC3_GUSB3PIPECTL_SUSPHY -* to '0' during coreConsultant configuration. So default value -* will be '0' when the core is reset. Application needs to set it -* to '1' after the core initialization is completed. -*/ - if (!DWC3_VER_IS_WITHIN(DWC3, ANY, 194A)) - reg |=DWC3_GUSB3PIPECTL_SUSPHY ; - -/* -* For DRD controllers, GUSB3PIPECTL.SUSPENDENABLE must be cleared after -* power-on reset, and it can be set after core initialization, which is -* after device soft-reset during initialization. +* Above DWC_usb3.0 1.94a, it is recommended to set +* DWC3_GUSB3PIPECTL_SUSPHY to '0' during coreConsultant configuration. +* So default value will be '0' when the core is reset. Application +* needs to set it to '1' after the core initialization is completed. +* +* Similarly for DRD controllers, GUSB3PIPECTL.SUSPENDENABLE must be +* cleared after power-on reset, and it can be set after core +* initialization. */ -if (hw_mode ==DWC3_GHWPARAMS0_MODE_DRD ) - reg &= ~DWC3_GUSB3PIPECTL_SUSPHY ; + reg &= ~DWC3_GUSB3PIPECTL_SUSPHY ;if (dwc->u2ss_inp3_quirk) reg |=DWC3_GUSB3PIPECTL_U2SSINP3OK ;
@@ -639,9 +652,6 @@ static int dwc3_phy_setup(struct dwc3 *dwc)if (dwc->tx_de_emphasis_quirk) reg |=DWC3_GUSB3PIPECTL_TX_DEEPH (dwc->tx_de_emphasis); -if (dwc->dis_u3_susphy_quirk) - reg &= ~DWC3_GUSB3PIPECTL_SUSPHY ; -if (dwc->dis_del_phy_power_chg_quirk) reg &= ~DWC3_GUSB3PIPECTL_DEPOCHANGE ;
@@ -689,24 +699,15 @@ static int dwc3_phy_setup(struct dwc3 *dwc) }/* -* Above 1.94a, it is recommended to set DWC3_GUSB2PHYCFG_SUSPHY to -* '0' during coreConsultant configuration. So default value will -* be '0' when the core is reset. Application needs to set it to -* '1' after the core initialization is completed. -*/ - if (!DWC3_VER_IS_WITHIN(DWC3, ANY, 194A)) - reg |=DWC3_GUSB2PHYCFG_SUSPHY ; - -/* -* For DRD controllers, GUSB2PHYCFG.SUSPHY must be cleared after -* power-on reset, and it can be set after core initialization, which is -* after device soft-reset during initialization. +* Above DWC_usb3.0 1.94a, it is recommended to set +* DWC3_GUSB2PHYCFG_SUSPHY to '0' during coreConsultant configuration. +* So default value will be '0' when the core is reset. Application +* needs to set it to '1' after the core initialization is completed. +* +* Similarly for DRD controllers, GUSB2PHYCFG.SUSPHY must be cleared +* after power-on reset, and it can be set after core initialization. */ -if (hw_mode ==DWC3_GHWPARAMS0_MODE_DRD ) - reg &= ~DWC3_GUSB2PHYCFG_SUSPHY ; - -if (dwc->dis_u2_susphy_quirk) - reg &= ~DWC3_GUSB2PHYCFG_SUSPHY ; + reg &= ~DWC3_GUSB2PHYCFG_SUSPHY ;if (dwc->dis_enblslpm_quirk) reg &= ~DWC3_GUSB2PHYCFG_ENBLSLPM ;
@@ -1227,21 +1228,6 @@ static int dwc3_core_init(struct dwc3 *dwc)if (ret) goto err_exit_phy; -if (hw_mode ==DWC3_GHWPARAMS0_MODE_DRD && - !DWC3_VER_IS_WITHIN(DWC3, ANY, 194A)) { -if (!dwc->dis_u3_susphy_quirk) { - reg =dwc3_readl (dwc->regs,DWC3_GUSB3PIPECTL (0 )); - reg |=DWC3_GUSB3PIPECTL_SUSPHY ; -dwc3_writel (dwc->regs,DWC3_GUSB3PIPECTL (0 ), reg); - } - -if (!dwc->dis_u2_susphy_quirk) { - reg =dwc3_readl (dwc->regs,DWC3_GUSB2PHYCFG (0 )); - reg |=DWC3_GUSB2PHYCFG_SUSPHY ; -dwc3_writel (dwc->regs,DWC3_GUSB2PHYCFG (0 ), reg); - } - } -dwc3_core_setup_global_control (dwc);dwc3_core_num_eps (dwc);
@@ -1519,6 +1505,8 @@ static void dwc3_get_properties(struct dwc3 *dwc)else dwc->sysdev = dwc->dev; + dwc->sys_wakeup =device_may_wakeup (dwc->sysdev); + ret =device_property_read_string (dev,"usb-psy-name" , &usb_psy_name);if (ret >=0 ) { dwc->usb_psy =power_supply_get_by_name (usb_psy_name);
drivers/usb/dwc3/core.h +5 -0
@@ -755,6 +755,7 @@ struct dwc3_ep {#define DWC3_EP_PENDING_CLEAR_STALL BIT(11)#define DWC3_EP_TXFIFO_RESIZED BIT(12)#define DWC3_EP_DELAY_STOP BIT(13) +#define DWC3_EP_RESOURCE_ALLOCATED BIT(14)/* This last one is specific to EP0 */ #define DWC3_EP0_DIR_IN BIT(31)
@@ -1132,6 +1133,7 @@ struct dwc3_scratchpad_array {* 3 - Reserved * @dis_metastability_quirk: set to disable metastability quirk. * @dis_split_quirk: set to disable split boundary. +* @sys_wakeup: set if the device may do system wakeup. * @wakeup_configured: set if the device is configured for remote wakeup. * @suspended: set to track suspend event due to U3/L2. * @imod_interval: set the interrupt moderation interval in 250ns
@@ -1257,6 +1259,7 @@ struct dwc3 {#define DWC31_REVISION_170A 0x3137302a#define DWC31_REVISION_180A 0x3138302a#define DWC31_REVISION_190A 0x3139302a +#define DWC31_REVISION_200A 0x3230302a#define DWC32_REVISION_ANY 0x0#define DWC32_REVISION_100A 0x3130302a
@@ -1355,6 +1358,7 @@ struct dwc3 { unsigned dis_split_quirk:1; unsigned async_callbacks:1; + unsigned sys_wakeup:1; unsigned wakeup_configured:1; unsigned suspended:1;
@@ -1576,6 +1580,7 @@ int dwc3_event_buffers_setup(struct dwc3 *dwc);void dwc3_event_buffers_cleanup (struct dwc3 *dwc);int dwc3_core_soft_reset (struct dwc3 *dwc); +void dwc3_enable_susphy (struct dwc3 *dwc,bool enable);#if IS_ENABLED (CONFIG_USB_DWC3_HOST ) ||IS_ENABLED (CONFIG_USB_DWC3_DUAL_ROLE )int dwc3_host_init (struct dwc3 *dwc);
drivers/usb/dwc3/dwc3-am62.c +30 -12
87 lines not on this page · raw message
drivers/usb/dwc3/ep0.c +3 -1
@@ -226,7 +226,8 @@ void dwc3_ep0_stall_and_restart(struct dwc3 *dwc)/* reinitialize physical ep1 */ dep = dwc->eps[1 ]; - dep->flags =DWC3_EP_ENABLED ; + dep->flags &=DWC3_EP_RESOURCE_ALLOCATED ; + dep->flags |=DWC3_EP_ENABLED ;/* stall is always issued on EP0 */ dep = dwc->eps[0 ];
@@ -646,6 +647,7 @@ static int dwc3_ep0_set_config(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)return -EINVAL ;case USB_STATE_ADDRESS : +dwc3_gadget_start_config (dwc,2 );dwc3_gadget_clear_tx_fifos (dwc); ret =dwc3_ep0_delegate_req (dwc, ctrl);
drivers/usb/dwc3/gadget.c +51 -52
194 lines not on this page · raw message
drivers/usb/dwc3/gadget.h +1 -0
@@ -119,6 +119,7 @@ int dwc3_gadget_ep0_queue(struct usb_ep *ep, struct usb_request *request,int __dwc3_gadget_ep_set_halt (struct dwc3_ep *dep,int value,int protocol);void dwc3_ep0_send_delayed_status (struct dwc3 *dwc);void dwc3_stop_active_transfer (struct dwc3_ep *dep,bool force,bool interrupt); +int dwc3_gadget_start_config (struct dwc3 *dwc,unsigned int resource_index);/** * dwc3_gadget_ep_get_transfer_index - Gets transfer index from HW
Signature · 1 line
2.53.0
PATCH v10 55/63 usb: dwc3: import from kernel v6.10
In reply to Anders RoxellFrom: Jens Wiklander <[email protected]>
Sync Linux kernel dwc3 changes from v6.9 to v6.10.
The following files are preserved across the import:Makefile Kconfig dwc3-meson-g12a.c dwc3-meson-gxl.c dwc3-omap.c dwc3-uniphier.c dwc3-generic.h dwc3-generic.c dwc3-generic-sti.c dwc3-layerscape.c ti_usb_phy.c
Skipping unused files:debugfs.c drd.c dwc3-exynos.c dwc3-haps.c dwc3-imx8mp.c dwc3-keystone.c dwc3-octeon.c dwc3-of-simple.c dwc3-pci.c dwc3-qcom.c dwc3-qcom-legacy.c dwc3-rtk.c dwc3-st.c dwc3-xilinx.c host.c trace.c trace.h ulpi.c
Note that this is a raw import and doesn't build. A fixup commit at the end of the series fixes that.
List of commits: git log --oneline v6.9..v6.10
Commits imported:fc1d1a712b51 usb: dwc3: core: Workaround for CSR read timeout7838de15bb70 usb: dwc3: core: remove lock of otg mode during gadget suspend/resume to avoid deadlock 01be965ce5ab usb: dwc3: core: Fix unused variable warning in core driver 1d26ba0944d3 usb: dwc3: Wait unconditionally after issuing EndXfer command 3f12222a4beb usb: dwc3: core: Fix compile warning on s390 gcc in dwc3_get_phy call 30a46746ca5a usb: dwc3: core: Refactor PHY logic to support Multiport Controller 89d7f9629946 usb: dwc3: core: Skip setting event buffers for host only controllers 921e109c6200 usb: dwc3: core: Access XHCI address space temporarily to read port info 606c096adc79 usb: dwc3: Select 2.0 or 3.0 clk base on maximum_speed
--- drivers/usb/dwc3/core.c | 346 +++++++++++++++++++++++++++++--------- drivers/usb/dwc3/core.h | 20 ++- drivers/usb/dwc3/gadget.c | 4 +- 3 files changed, 284 insertions(+), 86 deletions(-)
drivers/usb/dwc3/core.c +267 -79
@@ -39,6 +39,7 @@#include "io.h" #include "debug.h" +#include "../host/xhci-ext-caps.h" #define DWC3_DEFAULT_AUTOSUSPEND_DELAY 5000/* ms */
@@ -144,6 +145,7 @@ static void __dwc3_set_mode(struct work_struct *work)int ret;u32 reg;u32 desired_dr_role; +int i;mutex_lock (&dwc->mutex);spin_lock_irqsave (&dwc->lock, flags);
@@ -221,8 +223,12 @@ static void __dwc3_set_mode(struct work_struct *work) }else {if (dwc->usb2_phy)otg_set_vbus (dwc->usb2_phy->otg, true); -phy_set_mode (dwc->usb2_generic_phy,PHY_MODE_USB_HOST ); -phy_set_mode (dwc->usb3_generic_phy,PHY_MODE_USB_HOST ); + +for (i =0 ; i < dwc->num_usb2_ports; i++) +phy_set_mode (dwc->usb2_generic_phy[i],PHY_MODE_USB_HOST ); +for (i =0 ; i < dwc->num_usb3_ports; i++) +phy_set_mode (dwc->usb3_generic_phy[i],PHY_MODE_USB_HOST ); +if (dwc->dis_split_quirk) { reg =dwc3_readl (dwc->regs,DWC3_GUCTL3 ); reg |=DWC3_GUCTL3_SPLITDISABLE ;
@@ -237,8 +243,8 @@ static void __dwc3_set_mode(struct work_struct *work)if (dwc->usb2_phy)otg_set_vbus (dwc->usb2_phy->otg, false); -phy_set_mode (dwc->usb2_generic_phy,PHY_MODE_USB_DEVICE ); -phy_set_mode (dwc->usb3_generic_phy,PHY_MODE_USB_DEVICE ); +phy_set_mode (dwc->usb2_generic_phy[0 ],PHY_MODE_USB_DEVICE ); +phy_set_mode (dwc->usb3_generic_phy[0 ],PHY_MODE_USB_DEVICE ); ret =dwc3_gadget_init (dwc);if (ret)
@@ -506,6 +512,13 @@ static void dwc3_free_event_buffers(struct dwc3 *dwc)static int dwc3_alloc_event_buffers (struct dwc3 *dwc,unsigned int length) {struct dwc3_event_buffer *evt; +unsigned int hw_mode; + + hw_mode =DWC3_GHWPARAMS0_MODE (dwc->hwparams.hwparams0); +if (hw_mode ==DWC3_GHWPARAMS0_MODE_HOST ) { + dwc->ev_buf =NULL ; +return 0 ; + } evt =dwc3_alloc_one_event_buffer (dwc, length);if (IS_ERR (evt)) {
@@ -527,6 +540,9 @@ int dwc3_event_buffers_setup(struct dwc3 *dwc) {struct dwc3_event_buffer *evt; +if (!dwc->ev_buf) +return 0 ; + evt = dwc->ev_buf; evt->lpos =0 ; dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(0),
@@ -544,6 +560,9 @@ void dwc3_event_buffers_cleanup(struct dwc3 *dwc) {struct dwc3_event_buffer *evt; +if (!dwc->ev_buf) +return ; + evt = dwc->ev_buf; evt->lpos =0 ;
@@ -596,19 +615,11 @@ static int dwc3_core_ulpi_init(struct dwc3 *dwc)return ret; } -/** -* dwc3_phy_setup - Configure USB PHY Interface of DWC3 Core -* @dwc: Pointer to our controller context structure -* -* Returns 0 on success. The USB PHY interfaces are configured but not -* initialized. The PHY interfaces and the PHYs get initialized together with -* the core in dwc3_core_init. -*/ -static int dwc3_phy_setup (struct dwc3 *dwc) +static int dwc3_ss_phy_setup (struct dwc3 *dwc,int index) {u32 reg; - reg =dwc3_readl (dwc->regs,DWC3_GUSB3PIPECTL (0 )); + reg =dwc3_readl (dwc->regs,DWC3_GUSB3PIPECTL (index));/* * Make sure UX_EXIT_PX is cleared as that causes issues with some
@@ -655,9 +666,16 @@ static int dwc3_phy_setup(struct dwc3 *dwc)if (dwc->dis_del_phy_power_chg_quirk) reg &= ~DWC3_GUSB3PIPECTL_DEPOCHANGE ; -dwc3_writel (dwc->regs,DWC3_GUSB3PIPECTL (0 ), reg); +dwc3_writel (dwc->regs,DWC3_GUSB3PIPECTL (index), reg); - reg =dwc3_readl (dwc->regs,DWC3_GUSB2PHYCFG (0 )); +return 0 ; +} + +static int dwc3_hs_phy_setup (struct dwc3 *dwc,int index) +{ +u32 reg; + + reg =dwc3_readl (dwc->regs,DWC3_GUSB2PHYCFG (index));/* Select the HS PHY interface */ switch (DWC3_GHWPARAMS3_HSPHY_IFC (dwc->hwparams.hwparams3)) {
@@ -669,7 +687,7 @@ static int dwc3_phy_setup(struct dwc3 *dwc) }else if (dwc->hsphy_interface && !strncmp (dwc->hsphy_interface,"ulpi" ,4 )) { reg |=DWC3_GUSB2PHYCFG_ULPI_UTMI ; -dwc3_writel (dwc->regs,DWC3_GUSB2PHYCFG (0 ), reg); +dwc3_writel (dwc->regs,DWC3_GUSB2PHYCFG (index), reg); }else {/* Relying on default value. */ if (!(reg &DWC3_GUSB2PHYCFG_ULPI_UTMI ))
@@ -727,7 +745,35 @@ static int dwc3_phy_setup(struct dwc3 *dwc)if (dwc->ulpi_ext_vbus_drv) reg |=DWC3_GUSB2PHYCFG_ULPIEXTVBUSDRV ; -dwc3_writel (dwc->regs,DWC3_GUSB2PHYCFG (0 ), reg); +dwc3_writel (dwc->regs,DWC3_GUSB2PHYCFG (index), reg); + +return 0 ; +} + +/** +* dwc3_phy_setup - Configure USB PHY Interface of DWC3 Core +* @dwc: Pointer to our controller context structure +* +* Returns 0 on success. The USB PHY interfaces are configured but not +* initialized. The PHY interfaces and the PHYs get initialized together with +* the core in dwc3_core_init. +*/ +static int dwc3_phy_setup (struct dwc3 *dwc) +{ +int i; +int ret; + +for (i =0 ; i < dwc->num_usb3_ports; i++) { + ret =dwc3_ss_phy_setup (dwc, i); +if (ret) +return ret; + } + +for (i =0 ; i < dwc->num_usb2_ports; i++) { + ret =dwc3_hs_phy_setup (dwc, i); +if (ret) +return ret; + }return 0 ; }
@@ -735,23 +781,34 @@ static int dwc3_phy_setup(struct dwc3 *dwc)static int dwc3_phy_init (struct dwc3 *dwc) {int ret; +int i; +int j;usb_phy_init (dwc->usb2_phy);usb_phy_init (dwc->usb3_phy); - ret =phy_init (dwc->usb2_generic_phy); -if (ret <0 ) - goto err_shutdown_usb3_phy; +for (i =0 ; i < dwc->num_usb2_ports; i++) { + ret =phy_init (dwc->usb2_generic_phy[i]); +if (ret <0 ) + goto err_exit_usb2_phy; + } - ret =phy_init (dwc->usb3_generic_phy); -if (ret <0 ) - goto err_exit_usb2_phy; +for (j =0 ; j < dwc->num_usb3_ports; j++) { + ret =phy_init (dwc->usb3_generic_phy[j]); +if (ret <0 ) + goto err_exit_usb3_phy; + }return 0 ; +err_exit_usb3_phy: +while (--j >=0 ) +phy_exit (dwc->usb3_generic_phy[j]); + err_exit_usb2_phy: -phy_exit (dwc->usb2_generic_phy); -err_shutdown_usb3_phy: +while (--i >=0 ) +phy_exit (dwc->usb2_generic_phy[i]); +usb_phy_shutdown (dwc->usb3_phy);usb_phy_shutdown (dwc->usb2_phy);
@@ -760,8 +817,13 @@ err_shutdown_usb3_phy:static void dwc3_phy_exit (struct dwc3 *dwc) { -phy_exit (dwc->usb3_generic_phy); -phy_exit (dwc->usb2_generic_phy); +int i; + +for (i =0 ; i < dwc->num_usb3_ports; i++) +phy_exit (dwc->usb3_generic_phy[i]); + +for (i =0 ; i < dwc->num_usb2_ports; i++) +phy_exit (dwc->usb2_generic_phy[i]);usb_phy_shutdown (dwc->usb3_phy);usb_phy_shutdown (dwc->usb2_phy);
@@ -770,23 +832,34 @@ static void dwc3_phy_exit(struct dwc3 *dwc)static int dwc3_phy_power_on (struct dwc3 *dwc) {int ret; +int i; +int j;usb_phy_set_suspend (dwc->usb2_phy,0 );usb_phy_set_suspend (dwc->usb3_phy,0 ); - ret =phy_power_on (dwc->usb2_generic_phy); -if (ret <0 ) - goto err_suspend_usb3_phy; +for (i =0 ; i < dwc->num_usb2_ports; i++) { + ret =phy_power_on (dwc->usb2_generic_phy[i]); +if (ret <0 ) + goto err_power_off_usb2_phy; + } - ret =phy_power_on (dwc->usb3_generic_phy); -if (ret <0 ) - goto err_power_off_usb2_phy; +for (j =0 ; j < dwc->num_usb3_ports; j++) { + ret =phy_power_on (dwc->usb3_generic_phy[j]); +if (ret <0 ) + goto err_power_off_usb3_phy; + }return 0 ; +err_power_off_usb3_phy: +while (--j >=0 ) +phy_power_off (dwc->usb3_generic_phy[j]); + err_power_off_usb2_phy: -phy_power_off (dwc->usb2_generic_phy); -err_suspend_usb3_phy: +while (--i >=0 ) +phy_power_off (dwc->usb2_generic_phy[i]); +usb_phy_set_suspend (dwc->usb3_phy,1 );usb_phy_set_suspend (dwc->usb2_phy,1 );
@@ -795,8 +868,13 @@ err_suspend_usb3_phy:static void dwc3_phy_power_off (struct dwc3 *dwc) { -phy_power_off (dwc->usb3_generic_phy); -phy_power_off (dwc->usb2_generic_phy); +int i; + +for (i =0 ; i < dwc->num_usb3_ports; i++) +phy_power_off (dwc->usb3_generic_phy[i]); + +for (i =0 ; i < dwc->num_usb2_ports; i++) +phy_power_off (dwc->usb2_generic_phy[i]);usb_phy_set_suspend (dwc->usb3_phy,1 );usb_phy_set_suspend (dwc->usb2_phy,1 );
@@ -879,12 +957,16 @@ static bool dwc3_core_is_valid(struct dwc3 *dwc)static void dwc3_core_setup_global_control (struct dwc3 *dwc) { +unsigned int power_opt; +unsigned int hw_mode;u32 reg; reg =dwc3_readl (dwc->regs,DWC3_GCTL ); reg &= ~DWC3_GCTL_SCALEDOWN_MASK ; + hw_mode =DWC3_GHWPARAMS0_MODE (dwc->hwparams.hwparams0); + power_opt =DWC3_GHWPARAMS1_EN_PWROPT (dwc->hwparams.hwparams1); -switch (DWC3_GHWPARAMS1_EN_PWROPT (dwc->hwparams.hwparams1)) { +switch (power_opt) {case DWC3_GHWPARAMS1_EN_PWROPT_CLK :/** * WORKAROUND: DWC3 revisions between 2.10a and 2.50a have an
@@ -917,6 +999,20 @@ static void dwc3_core_setup_global_control(struct dwc3 *dwc)break ; } +/* +* This is a workaround for STAR#4846132, which only affects +* DWC_usb31 version2.00a operating in host mode. +* +* There is a problem in DWC_usb31 version 2.00a operating +* in host mode that would cause a CSR read timeout When CSR +* read coincides with RAM Clock Gating Entry. By disable +* Clock Gating, sacrificing power consumption for normal +* operation. +*/ +if (power_opt !=DWC3_GHWPARAMS1_EN_PWROPT_NO && + hw_mode != DWC3_GHWPARAMS0_MODE_GADGET && DWC3_VER_IS(DWC31, 200A)) + reg |=DWC3_GCTL_DSBLCLKGTNG ; +/* check if current dwc3 is on simulation board */ if (dwc->hwparams.hwparams6 &DWC3_GHWPARAMS6_EN_FPGA ) {dev_info (dwc->dev,"Running with FPGA optimizations\n" );
@@ -1306,10 +1402,13 @@ static int dwc3_core_init(struct dwc3 *dwc)if (dwc->parkmode_disable_hs_quirk) reg |=DWC3_GUCTL1_PARKMODE_DISABLE_HS ; - if (DWC3_VER_IS_WITHIN(DWC3, 290A, ANY) && - (dwc->maximum_speed ==USB_SPEED_HIGH || - dwc->maximum_speed ==USB_SPEED_FULL )) - reg |=DWC3_GUCTL1_DEV_FORCE_20_CLK_FOR_30_CLK ; + if (DWC3_VER_IS_WITHIN(DWC3, 290A, ANY)) { +if (dwc->maximum_speed ==USB_SPEED_FULL || + dwc->maximum_speed ==USB_SPEED_HIGH ) + reg |=DWC3_GUCTL1_DEV_FORCE_20_CLK_FOR_30_CLK ; +else + reg &= ~DWC3_GUCTL1_DEV_FORCE_20_CLK_FOR_30_CLK ; + }dwc3_writel (dwc->regs,DWC3_GUCTL1 , reg); }
@@ -1344,7 +1443,9 @@ static int dwc3_core_get_phy(struct dwc3 *dwc) {struct device *dev = dwc->dev;struct device_node *node = dev->of_node; +char phy_name[9 ];int ret; +u8 i;if (node) { dwc->usb2_phy =devm_usb_get_phy_by_phandle (dev,"usb-phy" ,0 );
@@ -1370,22 +1471,38 @@ static int dwc3_core_get_phy(struct dwc3 *dwc)return dev_err_probe (dev, ret,"no usb3 phy configured\n" ); } - dwc->usb2_generic_phy =devm_phy_get (dev,"usb2-phy" ); -if (IS_ERR (dwc->usb2_generic_phy)) { - ret =PTR_ERR (dwc->usb2_generic_phy); -if (ret == -ENOSYS || ret == -ENODEV ) - dwc->usb2_generic_phy =NULL ; +for (i =0 ; i < dwc->num_usb2_ports; i++) { +if (dwc->num_usb2_ports ==1 ) +snprintf (phy_name,sizeof (phy_name),"usb2-phy" );else -return dev_err_probe (dev, ret,"no usb2 phy configured\n" ); +snprintf (phy_name,sizeof (phy_name),"usb2-%u" , i); + + dwc->usb2_generic_phy[i] =devm_phy_get (dev, phy_name); +if (IS_ERR (dwc->usb2_generic_phy[i])) { + ret =PTR_ERR (dwc->usb2_generic_phy[i]); +if (ret == -ENOSYS || ret == -ENODEV ) + dwc->usb2_generic_phy[i] =NULL ; +else +return dev_err_probe (dev, ret,"failed to lookup phy %s\n" , + phy_name); + } } - dwc->usb3_generic_phy =devm_phy_get (dev,"usb3-phy" ); -if (IS_ERR (dwc->usb3_generic_phy)) { - ret =PTR_ERR (dwc->usb3_generic_phy); -if (ret == -ENOSYS || ret == -ENODEV ) - dwc->usb3_generic_phy =NULL ; +for (i =0 ; i < dwc->num_usb3_ports; i++) { +if (dwc->num_usb3_ports ==1 ) +snprintf (phy_name,sizeof (phy_name),"usb3-phy" );else -return dev_err_probe (dev, ret,"no usb3 phy configured\n" ); +snprintf (phy_name,sizeof (phy_name),"usb3-%u" , i); + + dwc->usb3_generic_phy[i] =devm_phy_get (dev, phy_name); +if (IS_ERR (dwc->usb3_generic_phy[i])) { + ret =PTR_ERR (dwc->usb3_generic_phy[i]); +if (ret == -ENOSYS || ret == -ENODEV ) + dwc->usb3_generic_phy[i] =NULL ; +else +return dev_err_probe (dev, ret,"failed to lookup phy %s\n" , + phy_name); + } }return 0 ;
@@ -1395,6 +1512,7 @@ static int dwc3_core_init_mode(struct dwc3 *dwc) {struct device *dev = dwc->dev;int ret; +int i;switch (dwc->dr_mode) {case USB_DR_MODE_PERIPHERAL :
@@ -1402,8 +1520,8 @@ static int dwc3_core_init_mode(struct dwc3 *dwc)if (dwc->usb2_phy)otg_set_vbus (dwc->usb2_phy->otg, false); -phy_set_mode (dwc->usb2_generic_phy,PHY_MODE_USB_DEVICE ); -phy_set_mode (dwc->usb3_generic_phy,PHY_MODE_USB_DEVICE ); +phy_set_mode (dwc->usb2_generic_phy[0 ],PHY_MODE_USB_DEVICE ); +phy_set_mode (dwc->usb3_generic_phy[0 ],PHY_MODE_USB_DEVICE ); ret =dwc3_gadget_init (dwc);if (ret)
@@ -1414,8 +1532,10 @@ static int dwc3_core_init_mode(struct dwc3 *dwc)if (dwc->usb2_phy)otg_set_vbus (dwc->usb2_phy->otg, true); -phy_set_mode (dwc->usb2_generic_phy,PHY_MODE_USB_HOST ); -phy_set_mode (dwc->usb3_generic_phy,PHY_MODE_USB_HOST ); +for (i =0 ; i < dwc->num_usb2_ports; i++) +phy_set_mode (dwc->usb2_generic_phy[i],PHY_MODE_USB_HOST ); +for (i =0 ; i < dwc->num_usb3_ports; i++) +phy_set_mode (dwc->usb3_generic_phy[i],PHY_MODE_USB_HOST ); ret =dwc3_host_init (dwc);if (ret)
@@ -1867,10 +1987,60 @@ static int dwc3_get_clocks(struct dwc3 *dwc)return 0 ; } +static int dwc3_get_num_ports (struct dwc3 *dwc) +{ +void __iomem *base; +u8 major_revision; +u32 offset; +u32 val; + +/* +* Remap xHCI address space to access XHCI ext cap regs since it is +* needed to get information on number of ports present. +*/ + base =ioremap (dwc->xhci_resources[0 ].start, +resource_size (&dwc->xhci_resources[0 ])); +if (!base) +return -ENOMEM ; + + offset =0 ; +do { + offset =xhci_find_next_ext_cap (base, offset, +XHCI_EXT_CAPS_PROTOCOL ); +if (!offset) +break ; + + val =readl (base + offset); + major_revision =XHCI_EXT_PORT_MAJOR (val); + + val =readl (base + offset +0x08 ); +if (major_revision ==0x03 ) { + dwc->num_usb3_ports +=XHCI_EXT_PORT_COUNT (val); + }else if (major_revision <=0x02 ) { + dwc->num_usb2_ports +=XHCI_EXT_PORT_COUNT (val); + }else { +dev_warn (dwc->dev,"unrecognized port major revision %d\n" , + major_revision); + } + }while (1 ); + +dev_dbg (dwc->dev,"hs-ports: %u ss-ports: %u\n" , + dwc->num_usb2_ports, dwc->num_usb3_ports); + +iounmap (base); + +if (dwc->num_usb2_ports >DWC3_USB2_MAX_PORTS || + dwc->num_usb3_ports >DWC3_USB3_MAX_PORTS ) +return -EINVAL ; + +return 0 ; +} +static int dwc3_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev;struct resource *res, dwc_res; +unsigned int hw_mode;void __iomem *regs;struct dwc3 *dwc;int ret;
@@ -1954,6 +2124,20 @@ static int dwc3_probe(struct platform_device *pdev) goto err_disable_clks; } +/* +* Currently only DWC3 controllers that are host-only capable +* can have more than one port. +*/ + hw_mode =DWC3_GHWPARAMS0_MODE (dwc->hwparams.hwparams0); +if (hw_mode ==DWC3_GHWPARAMS0_MODE_HOST ) { + ret =dwc3_get_num_ports (dwc); +if (ret) + goto err_disable_clks; + }else { + dwc->num_usb2_ports =1 ; + dwc->num_usb3_ports =1 ; + } +spin_lock_init (&dwc->lock);mutex_init (&dwc->mutex);
@@ -2084,8 +2268,8 @@ assert_reset:static int dwc3_suspend_common (struct dwc3 *dwc,pm_message_t msg) { -unsigned long flags;u32 reg; +int i;switch (dwc->current_dr_role) {case DWC3_GCTL_PRTCAP_DEVICE :
@@ -2104,17 +2288,21 @@ static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg)/* Let controller to suspend HSPHY before PHY driver suspends */ if (dwc->dis_u2_susphy_quirk || dwc->dis_enblslpm_quirk) { - reg =dwc3_readl (dwc->regs,DWC3_GUSB2PHYCFG (0 )); - reg |=DWC3_GUSB2PHYCFG_ENBLSLPM | -DWC3_GUSB2PHYCFG_SUSPHY ; -dwc3_writel (dwc->regs,DWC3_GUSB2PHYCFG (0 ), reg); +for (i =0 ; i < dwc->num_usb2_ports; i++) { + reg =dwc3_readl (dwc->regs,DWC3_GUSB2PHYCFG (i)); + reg |=DWC3_GUSB2PHYCFG_ENBLSLPM | +DWC3_GUSB2PHYCFG_SUSPHY ; +dwc3_writel (dwc->regs,DWC3_GUSB2PHYCFG (i), reg); + }/* Give some time for USB2 PHY to suspend */ usleep_range (5000 ,6000 ); } -phy_pm_runtime_put_sync (dwc->usb2_generic_phy); -phy_pm_runtime_put_sync (dwc->usb3_generic_phy); +for (i =0 ; i < dwc->num_usb2_ports; i++) +phy_pm_runtime_put_sync (dwc->usb2_generic_phy[i]); +for (i =0 ; i < dwc->num_usb3_ports; i++) +phy_pm_runtime_put_sync (dwc->usb3_generic_phy[i]);break ;case DWC3_GCTL_PRTCAP_OTG :/* do nothing during runtime_suspend */
@@ -2122,9 +2310,7 @@ static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg)break ;if (dwc->current_otg_role ==DWC3_OTG_ROLE_DEVICE ) { -spin_lock_irqsave (&dwc->lock, flags);dwc3_gadget_suspend (dwc); -spin_unlock_irqrestore (&dwc->lock, flags);synchronize_irq (dwc->irq_gadget); }
@@ -2141,9 +2327,9 @@ static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg)static int dwc3_resume_common (struct dwc3 *dwc,pm_message_t msg) { -unsigned long flags;int ret;u32 reg; +int i;switch (dwc->current_dr_role) {case DWC3_GCTL_PRTCAP_DEVICE :
@@ -2163,17 +2349,21 @@ static int dwc3_resume_common(struct dwc3 *dwc, pm_message_t msg)break ; }/* Restore GUSB2PHYCFG bits that were modified in suspend */ - reg =dwc3_readl (dwc->regs,DWC3_GUSB2PHYCFG (0 )); -if (dwc->dis_u2_susphy_quirk) - reg &= ~DWC3_GUSB2PHYCFG_SUSPHY ; +for (i =0 ; i < dwc->num_usb2_ports; i++) { + reg =dwc3_readl (dwc->regs,DWC3_GUSB2PHYCFG (i)); +if (dwc->dis_u2_susphy_quirk) + reg &= ~DWC3_GUSB2PHYCFG_SUSPHY ; -if (dwc->dis_enblslpm_quirk) - reg &= ~DWC3_GUSB2PHYCFG_ENBLSLPM ; +if (dwc->dis_enblslpm_quirk) + reg &= ~DWC3_GUSB2PHYCFG_ENBLSLPM ; -dwc3_writel (dwc->regs,DWC3_GUSB2PHYCFG (0 ), reg); +dwc3_writel (dwc->regs,DWC3_GUSB2PHYCFG (i), reg); + } -phy_pm_runtime_get_sync (dwc->usb2_generic_phy); -phy_pm_runtime_get_sync (dwc->usb3_generic_phy); +for (i =0 ; i < dwc->num_usb2_ports; i++) +phy_pm_runtime_get_sync (dwc->usb2_generic_phy[i]); +for (i =0 ; i < dwc->num_usb3_ports; i++) +phy_pm_runtime_get_sync (dwc->usb3_generic_phy[i]);break ;case DWC3_GCTL_PRTCAP_OTG :/* nothing to do on runtime_resume */
@@ -2190,9 +2380,7 @@ static int dwc3_resume_common(struct dwc3 *dwc, pm_message_t msg)if (dwc->current_otg_role ==DWC3_OTG_ROLE_HOST ) {dwc3_otg_host_init (dwc); }else if (dwc->current_otg_role ==DWC3_OTG_ROLE_DEVICE ) { -spin_lock_irqsave (&dwc->lock, flags);dwc3_gadget_resume (dwc); -spin_unlock_irqrestore (&dwc->lock, flags); }break ;
drivers/usb/dwc3/core.h +16 -4
@@ -33,6 +33,13 @@#include <linux/power_supply.h> +/* +* DWC3 Multiport controllers support up to 15 High-Speed PHYs +* and 4 SuperSpeed PHYs. +*/ +#define DWC3_USB2_MAX_PORTS 15 +#define DWC3_USB3_MAX_PORTS 4 +#define DWC3_MSG_MAX 500/* Global constants */
@@ -1037,8 +1044,10 @@ struct dwc3_scratchpad_array {* @usb_psy: pointer to power supply interface. * @usb2_phy: pointer to USB2 PHY * @usb3_phy: pointer to USB3 PHY -* @usb2_generic_phy: pointer to USB2 PHY -* @usb3_generic_phy: pointer to USB3 PHY +* @usb2_generic_phy: pointer to array of USB2 PHYs +* @usb3_generic_phy: pointer to array of USB3 PHYs +* @num_usb2_ports: number of USB2 ports +* @num_usb3_ports: number of USB3 ports * @phys_ready: flag to indicate that PHYs are ready * @ulpi: pointer to ulpi interface * @ulpi_ready: flag to indicate that ULPI is initialized
@@ -1184,8 +1193,11 @@ struct dwc3 {struct usb_phy *usb2_phy;struct usb_phy *usb3_phy; -struct phy *usb2_generic_phy; -struct phy *usb3_generic_phy; +struct phy *usb2_generic_phy[DWC3_USB2_MAX_PORTS ]; +struct phy *usb3_generic_phy[DWC3_USB3_MAX_PORTS ]; + +u8 num_usb2_ports; +u8 num_usb3_ports;bool phys_ready;
drivers/usb/dwc3/gadget.c +1 -3
@@ -1699,7 +1699,6 @@ static int __dwc3_gadget_get_frame(struct dwc3 *dwc)*/ static int __dwc3_stop_active_transfer (struct dwc3_ep *dep,bool force,bool interrupt) { -struct dwc3 *dwc = dep->dwc;struct dwc3_gadget_ep_cmd_params params;u32 cmd;int ret;
@@ -1724,8 +1723,7 @@ static int __dwc3_stop_active_transfer(struct dwc3_ep *dep, bool force, bool int dep->resource_index =0 ;if (!interrupt) { - if (!DWC3_IP_IS(DWC3) || DWC3_VER_IS_PRIOR(DWC3, 310A)) -mdelay (1 ); +mdelay (1 ); dep->flags &= ~DWC3_EP_TRANSFER_STARTED ; }else if (!ret) { dep->flags |=DWC3_EP_END_TRANSFER_PENDING ;
Signature · 1 line
2.53.0
PATCH v10 56/63 usb: dwc3: import from kernel v6.11
In reply to Anders RoxellFrom: Jens Wiklander <[email protected]>
Sync Linux kernel dwc3 changes from v6.10 to v6.11.
The following files are preserved across the import:Makefile Kconfig dwc3-meson-g12a.c dwc3-meson-gxl.c dwc3-omap.c dwc3-uniphier.c dwc3-generic.h dwc3-generic.c dwc3-generic-sti.c dwc3-layerscape.c ti_usb_phy.c
Skipping unused files:debugfs.c drd.c dwc3-exynos.c dwc3-haps.c dwc3-imx8mp.c dwc3-keystone.c dwc3-octeon.c dwc3-of-simple.c dwc3-pci.c dwc3-qcom.c dwc3-qcom-legacy.c dwc3-rtk.c dwc3-st.c dwc3-xilinx.c host.c trace.c trace.h ulpi.c
Note that this is a raw import and doesn't build. A fixup commit at the end of the series fixes that.
List of commits: git log --oneline v6.10..v6.11
Commits imported:9149c9b0c7e0 usb: dwc3: core: update LC timer as per USB Spec V3.2 00dcf2fa449f usb: dwc3: Avoid waking up gadget during startxfer 72fca8371f20 usb: dwc3: ep0: Don't reset resource alloc flag (including ep0) 14e497183df2 usb: dwc3: core: Prevent USB core invalid event buffer address access d504bfa6cfd1 usb: dwc3: enable CCI support for AMD-xilinx DWC3 controller 179264157bba usb: dwc3: core: Check all ports when set phy suspend
--- drivers/usb/dwc3/core.c | 89 +++++++++++++++++++++++++++++++++------ drivers/usb/dwc3/core.h | 10 +++++ drivers/usb/dwc3/ep0.c | 3 +- drivers/usb/dwc3/gadget.c | 41 ++++++++---------- 4 files changed, 106 insertions(+), 37 deletions(-)
drivers/usb/dwc3/core.c +77 -12
@@ -108,22 +108,27 @@ static int dwc3_get_dr_mode(struct dwc3 *dwc)void dwc3_enable_susphy (struct dwc3 *dwc,bool enable) {u32 reg; +int i; - reg =dwc3_readl (dwc->regs,DWC3_GUSB3PIPECTL (0 )); -if (enable && !dwc->dis_u3_susphy_quirk) - reg |=DWC3_GUSB3PIPECTL_SUSPHY ; -else - reg &= ~DWC3_GUSB3PIPECTL_SUSPHY ; +for (i =0 ; i < dwc->num_usb3_ports; i++) { + reg =dwc3_readl (dwc->regs,DWC3_GUSB3PIPECTL (i)); +if (enable && !dwc->dis_u3_susphy_quirk) + reg |=DWC3_GUSB3PIPECTL_SUSPHY ; +else + reg &= ~DWC3_GUSB3PIPECTL_SUSPHY ; -dwc3_writel (dwc->regs,DWC3_GUSB3PIPECTL (0 ), reg); +dwc3_writel (dwc->regs,DWC3_GUSB3PIPECTL (i), reg); + } - reg =dwc3_readl (dwc->regs,DWC3_GUSB2PHYCFG (0 )); -if (enable && !dwc->dis_u2_susphy_quirk) - reg |=DWC3_GUSB2PHYCFG_SUSPHY ; -else - reg &= ~DWC3_GUSB2PHYCFG_SUSPHY ; +for (i =0 ; i < dwc->num_usb2_ports; i++) { + reg =dwc3_readl (dwc->regs,DWC3_GUSB2PHYCFG (i)); +if (enable && !dwc->dis_u2_susphy_quirk) + reg |=DWC3_GUSB2PHYCFG_SUSPHY ; +else + reg &= ~DWC3_GUSB2PHYCFG_SUSPHY ; -dwc3_writel (dwc->regs,DWC3_GUSB2PHYCFG (0 ), reg); +dwc3_writel (dwc->regs,DWC3_GUSB2PHYCFG (i), reg); + } }void dwc3_set_prtcap (struct dwc3 *dwc,u32 mode)
@@ -559,9 +564,17 @@ int dwc3_event_buffers_setup(struct dwc3 *dwc)void dwc3_event_buffers_cleanup (struct dwc3 *dwc) {struct dwc3_event_buffer *evt; +u32 reg;if (!dwc->ev_buf)return ; +/* +* Exynos platforms may not be able to access event buffer if the +* controller failed to halt on dwc3_core_exit(). +*/ + reg =dwc3_readl (dwc->regs,DWC3_DSTS ); +if (!(reg &DWC3_DSTS_DEVCTRLHLT )) +return ; evt = dwc->ev_buf;
@@ -599,6 +612,18 @@ static void dwc3_cache_hwparams(struct dwc3 *dwc) parms->hwparams9 =dwc3_readl (dwc->regs,DWC3_GHWPARAMS9 ); } +static void dwc3_config_soc_bus (struct dwc3 *dwc) +{ +if (dwc->gsbuscfg0_reqinfo !=DWC3_GSBUSCFG0_REQINFO_UNSPECIFIED ) { +u32 reg; + + reg =dwc3_readl (dwc->regs,DWC3_GSBUSCFG0 ); + reg &= ~DWC3_GSBUSCFG0_REQINFO (~0 ); + reg |=DWC3_GSBUSCFG0_REQINFO (dwc->gsbuscfg0_reqinfo); +dwc3_writel (dwc->regs,DWC3_GSBUSCFG0 , reg); + } +} +static int dwc3_core_ulpi_init (struct dwc3 *dwc) {int intf;
@@ -1338,6 +1363,8 @@ static int dwc3_core_init(struct dwc3 *dwc)dwc3_set_incr_burst_type (dwc); +dwc3_config_soc_bus (dwc); + ret =dwc3_phy_power_on (dwc);if (ret) goto err_exit_phy;
@@ -1359,6 +1386,21 @@ static int dwc3_core_init(struct dwc3 *dwc)dwc3_writel (dwc->regs,DWC3_GUCTL2 , reg); } +/* +* STAR 9001285599: This issue affects DWC_usb3 version 3.20a +* only. If the PM TIMER ECM is enabled through GUCTL2[19], the +* link compliance test (TD7.21) may fail. If the ECN is not +* enabled (GUCTL2[19] = 0), the controller will use the old timer +* value (5us), which is still acceptable for the link compliance +* test. Therefore, do not enable PM TIMER ECM in 3.20a by +* setting GUCTL2[19] by default; instead, use GUCTL2[19] = 0. +*/ + if (DWC3_VER_IS(DWC3, 320A)) { + reg =dwc3_readl (dwc->regs,DWC3_GUCTL2 ); + reg &= ~DWC3_GUCTL2_LC_TIMER ; +dwc3_writel (dwc->regs,DWC3_GUCTL2 , reg); + } +/* * When configured in HOST mode, after issuing U3/L2 exit controller * fails to send proper CRC checksum in CRC5 feild. Because of this
@@ -1576,6 +1618,27 @@ static void dwc3_core_exit_mode(struct dwc3 *dwc)dwc3_set_prtcap (dwc,DWC3_GCTL_PRTCAP_DEVICE ); } +static void dwc3_get_software_properties (struct dwc3 *dwc) +{ +struct device *tmpdev; +u16 gsbuscfg0_reqinfo; +int ret; + + dwc->gsbuscfg0_reqinfo =DWC3_GSBUSCFG0_REQINFO_UNSPECIFIED ; + +/* +* Iterate over all parent nodes for finding swnode properties +* and non-DT (non-ABI) properties. +*/ +for (tmpdev = dwc->dev; tmpdev; tmpdev = tmpdev->parent) { + ret =device_property_read_u16 (tmpdev, +"snps,gsbuscfg0-reqinfo" , + &gsbuscfg0_reqinfo); +if (!ret) + dwc->gsbuscfg0_reqinfo = gsbuscfg0_reqinfo; + } +} +static void dwc3_get_properties (struct dwc3 *dwc) {struct device *dev = dwc->dev;
@@ -2090,6 +2153,8 @@ static int dwc3_probe(struct platform_device *pdev)dwc3_get_properties (dwc); +dwc3_get_software_properties (dwc); + dwc->reset =devm_reset_control_array_get_optional_shared (dev);if (IS_ERR (dwc->reset)) { ret =PTR_ERR (dwc->reset);
drivers/usb/dwc3/core.h +10 -0
@@ -194,6 +194,10 @@#define DWC3_GSBUSCFG0_INCRBRSTENA (1 << 0)/* undefined length enable */ #define DWC3_GSBUSCFG0_INCRBRST_MASK 0xff +/* Global SoC Bus Configuration Register: AHB-prot/AXI-cache/OCP-ReqInfo */ +#define DWC3_GSBUSCFG0_REQINFO (n) (((n) & 0xffff) << 16) +#define DWC3_GSBUSCFG0_REQINFO_UNSPECIFIED 0xffffffff +/* Global Debug LSP MUX Select */ #define DWC3_GDBGLSPMUX_ENDBC BIT(15)/* Host only */ #define DWC3_GDBGLSPMUX_HOSTSELECT (n) ((n) & 0x3fff)
@@ -417,6 +421,7 @@/* Global User Control Register 2 */ #define DWC3_GUCTL2_RST_ACTBITLATER BIT(14) +#define DWC3_GUCTL2_LC_TIMER BIT(19)/* Global User Control Register 3 */ #define DWC3_GUCTL3_SPLITDISABLE BIT(14)
@@ -1153,6 +1158,9 @@ struct dwc3_scratchpad_array {* @num_ep_resized: carries the current number endpoints which have had its tx * fifo resized. * @debug_root: root debugfs directory for this device to put its files in. +* @gsbuscfg0_reqinfo: store GSBUSCFG0.DATRDREQINFO, DESRDREQINFO, +* DATWRREQINFO, and DESWRREQINFO value passed from +* glue driver. */ struct dwc3 {struct work_struct drd_work;
@@ -1262,6 +1270,7 @@ struct dwc3 {#define DWC3_REVISION_290A 0x5533290a#define DWC3_REVISION_300A 0x5533300a#define DWC3_REVISION_310A 0x5533310a +#define DWC3_REVISION_320A 0x5533320a#define DWC3_REVISION_330A 0x5533330a#define DWC31_REVISION_ANY 0x0
@@ -1380,6 +1389,7 @@ struct dwc3 {int last_fifo_depth;int num_ep_resized;struct dentry *debug_root; +u32 gsbuscfg0_reqinfo; };#define INCRX_BURST_MODE 0
drivers/usb/dwc3/ep0.c +2 -1
@@ -232,7 +232,8 @@ void dwc3_ep0_stall_and_restart(struct dwc3 *dwc)/* stall is always issued on EP0 */ dep = dwc->eps[0 ];__dwc3_gadget_ep_set_halt (dep,1 , false); - dep->flags =DWC3_EP_ENABLED ; + dep->flags &=DWC3_EP_RESOURCE_ALLOCATED ; + dep->flags |=DWC3_EP_ENABLED ; dwc->delayed_status = false;if (!list_empty (&dep->pending_list)) {
drivers/usb/dwc3/gadget.c +17 -24
53 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH v10 57/63 usb: dwc3: import from kernel v6.12
In reply to Anders RoxellFrom: Jens Wiklander <[email protected]>
Sync Linux kernel dwc3 changes from v6.11 to v6.12.
The following files are preserved across the import:Makefile Kconfig dwc3-meson-g12a.c dwc3-meson-gxl.c dwc3-omap.c dwc3-uniphier.c dwc3-generic.h dwc3-generic.c dwc3-generic-sti.c dwc3-layerscape.c ti_usb_phy.c
Skipping unused files:debugfs.c drd.c dwc3-exynos.c dwc3-haps.c dwc3-imx8mp.c dwc3-keystone.c dwc3-octeon.c dwc3-of-simple.c dwc3-pci.c dwc3-qcom.c dwc3-qcom-legacy.c dwc3-rtk.c dwc3-st.c dwc3-xilinx.c host.c trace.c trace.h ulpi.c
Note that this is a raw import and doesn't build. A fixup commit at the end of the series fixes that.
List of commits: git log --oneline v6.11..v6.12
Commits imported:9cfb31e4c89d usb: dwc3: fix fault at system suspend if device was already runtime suspended 705e3ce37bcc usb: dwc3: core: Fix system suspend on TI AM62 platforms c96e31252110 usb: dwc3: Wait for EndXfer completion before restoring GUSB2PHYCFG 0d410e8913f5 usb: dwc3: core: Stop processing of pending events if controller is halted 897e13a8f9a2 usb: dwc3: re-enable runtime PM after failed resume
--- drivers/usb/dwc3/core.c | 48 ++++++++++++++++++++++++++++++++------- drivers/usb/dwc3/core.h | 7 +++--- drivers/usb/dwc3/gadget.c | 21 +++++------------ 3 files changed, 49 insertions(+), 27 deletions(-)
drivers/usb/dwc3/core.c +40 -8
@@ -544,6 +544,7 @@ static int dwc3_alloc_event_buffers(struct dwc3 *dwc, unsigned int length)int dwc3_event_buffers_setup (struct dwc3 *dwc) {struct dwc3_event_buffer *evt; +u32 reg;if (!dwc->ev_buf)return 0 ;
@@ -556,8 +557,10 @@ int dwc3_event_buffers_setup(struct dwc3 *dwc) upper_32_bits(evt->dma));dwc3_writel (dwc->regs,DWC3_GEVNTSIZ (0 ),DWC3_GEVNTSIZ_SIZE (evt->length)); -dwc3_writel (dwc->regs,DWC3_GEVNTCOUNT (0 ),0 ); +/* Clear any stale event */ + reg =dwc3_readl (dwc->regs,DWC3_GEVNTCOUNT (0 )); +dwc3_writel (dwc->regs,DWC3_GEVNTCOUNT (0 ), reg);return 0 ; }
@@ -584,7 +587,10 @@ void dwc3_event_buffers_cleanup(struct dwc3 *dwc)dwc3_writel (dwc->regs,DWC3_GEVNTADRHI (0 ),0 );dwc3_writel (dwc->regs,DWC3_GEVNTSIZ (0 ),DWC3_GEVNTSIZ_INTMASK |DWC3_GEVNTSIZ_SIZE (0 )); -dwc3_writel (dwc->regs,DWC3_GEVNTCOUNT (0 ),0 ); + +/* Clear any stale event */ + reg =dwc3_readl (dwc->regs,DWC3_GEVNTCOUNT (0 )); +dwc3_writel (dwc->regs,DWC3_GEVNTCOUNT (0 ), reg); }static void dwc3_core_num_eps (struct dwc3 *dwc)
@@ -2336,6 +2342,19 @@ static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg)u32 reg;int i; +if (!pm_runtime_suspended (dwc->dev) && !PMSG_IS_AUTO (msg)) { + dwc->susphy_state = (dwc3_readl (dwc->regs,DWC3_GUSB2PHYCFG (0 )) & +DWC3_GUSB2PHYCFG_SUSPHY ) || + (dwc3_readl (dwc->regs,DWC3_GUSB3PIPECTL (0 )) & +DWC3_GUSB3PIPECTL_SUSPHY ); +/* +* TI AM62 platform requires SUSPHY to be +* enabled for system suspend to work. +*/ +if (!dwc->susphy_state) +dwc3_enable_susphy (dwc, true); + } +switch (dwc->current_dr_role) {case DWC3_GCTL_PRTCAP_DEVICE :if (pm_runtime_suspended (dwc->dev))
@@ -2454,6 +2473,11 @@ static int dwc3_resume_common(struct dwc3 *dwc, pm_message_t msg)break ; } +if (!PMSG_IS_AUTO (msg)) { +/* restore SUSPHY state to that before system suspend. */ +dwc3_enable_susphy (dwc, dwc->susphy_state); + } +return 0 ; }
@@ -2499,7 +2523,11 @@ static int dwc3_runtime_resume(struct device *dev)switch (dwc->current_dr_role) {case DWC3_GCTL_PRTCAP_DEVICE : -dwc3_gadget_process_pending_events (dwc); +if (dwc->pending_events) { +pm_runtime_put (dwc->dev); + dwc->pending_events = false; +enable_irq (dwc->irq_gadget); + }break ;case DWC3_GCTL_PRTCAP_HOST :default :
@@ -2552,7 +2580,7 @@ static int dwc3_suspend(struct device *dev)static int dwc3_resume (struct device *dev) {struct dwc3 *dwc =dev_get_drvdata (dev); -int ret; +int ret =0 ;pinctrl_pm_select_default_state (dev);
@@ -2560,14 +2588,12 @@ static int dwc3_resume(struct device *dev)pm_runtime_set_active (dev); ret =dwc3_resume_common (dwc,PMSG_RESUME ); -if (ret) { +if (ret)pm_runtime_set_suspended (dev); -return ret; - }pm_runtime_enable (dev); -return 0 ; +return ret; }static void dwc3_complete (struct device *dev)
@@ -2589,6 +2615,12 @@ static void dwc3_complete(struct device *dev)static const struct dev_pm_ops dwc3_dev_pm_ops = {SET_SYSTEM_SLEEP_PM_OPS (dwc3_suspend, dwc3_resume) .complete = dwc3_complete, + +/* +* Runtime suspend halts the controller on disconnection. It relies on +* platforms with custom connection notification to start the controller +* again. +*/ SET_RUNTIME_PM_OPS (dwc3_runtime_suspend, dwc3_runtime_resume, dwc3_runtime_idle) };
drivers/usb/dwc3/core.h +3 -4
@@ -1150,6 +1150,8 @@ struct dwc3_scratchpad_array {* @sys_wakeup: set if the device may do system wakeup. * @wakeup_configured: set if the device is configured for remote wakeup. * @suspended: set to track suspend event due to U3/L2. +* @susphy_state: state of DWC3_GUSB2PHYCFG_SUSPHY + DWC3_GUSB3PIPECTL_SUSPHY +* before PM suspend. * @imod_interval: set the interrupt moderation interval in 250ns * increments or 0 to disable. * @max_cfg_eps: current max number of IN eps used across all USB configs.
@@ -1382,6 +1384,7 @@ struct dwc3 { unsigned sys_wakeup:1; unsigned wakeup_configured:1; unsigned suspended:1; + unsigned susphy_state:1;u16 imod_interval;
@@ -1675,7 +1678,6 @@ static inline void dwc3_otg_host_init(struct dwc3 *dwc)#if !IS_ENABLED (CONFIG_USB_DWC3_HOST )int dwc3_gadget_suspend (struct dwc3 *dwc);int dwc3_gadget_resume (struct dwc3 *dwc); -void dwc3_gadget_process_pending_events (struct dwc3 *dwc);#else static inline int dwc3_gadget_suspend (struct dwc3 *dwc) {
@@ -1687,9 +1689,6 @@ static inline int dwc3_gadget_resume(struct dwc3 *dwc) return 0; } -static inline void dwc3_gadget_process_pending_events (struct dwc3 *dwc) -{ -}#endif /* !IS_ENABLED(CONFIG_USB_DWC3_HOST) */ #if IS_ENABLED (CONFIG_USB_DWC3_ULPI )
drivers/usb/dwc3/gadget.c +6 -15
@@ -438,6 +438,10 @@ skip_status:dwc3_gadget_ep_get_transfer_index (dep); } +if (DWC3_DEPCMD_CMD (cmd) ==DWC3_DEPCMD_ENDTRANSFER && + !(cmd &DWC3_DEPCMD_CMDIOC )) +mdelay (1 ); +if (saved_config) { reg =dwc3_readl (dwc->regs,DWC3_GUSB2PHYCFG (0 )); reg |= saved_config;
@@ -1715,12 +1719,10 @@ static int __dwc3_stop_active_transfer(struct dwc3_ep *dep, bool force, bool intWARN_ON_ONCE (ret); dep->resource_index =0 ; -if (!interrupt) { -mdelay (1 ); +if (!interrupt) dep->flags &= ~DWC3_EP_TRANSFER_STARTED ; - }else if (!ret) { +else if (!ret) dep->flags |=DWC3_EP_END_TRANSFER_PENDING ; - } dep->flags &= ~DWC3_EP_DELAY_STOP ;return ret;
@@ -4728,14 +4730,3 @@ int dwc3_gadget_resume(struct dwc3 *dwc)return dwc3_gadget_soft_connect (dwc); } - -void dwc3_gadget_process_pending_events (struct dwc3 *dwc) -{ -if (dwc->pending_events) { -dwc3_interrupt (dwc->irq_gadget, dwc->ev_buf); -dwc3_thread_interrupt (dwc->irq_gadget, dwc->ev_buf); -pm_runtime_put (dwc->dev); - dwc->pending_events = false; -enable_irq (dwc->irq_gadget); - } -}
Signature · 1 line
2.53.0
PATCH v10 58/63 usb: dwc3: import from kernel v6.13
In reply to Anders RoxellFrom: Jens Wiklander <[email protected]>
Sync Linux kernel dwc3 changes from v6.12 to v6.13.
The following files are preserved across the import:Makefile Kconfig dwc3-meson-g12a.c dwc3-meson-gxl.c dwc3-omap.c dwc3-uniphier.c dwc3-generic.h dwc3-generic.c dwc3-generic-sti.c dwc3-layerscape.c ti_usb_phy.c
Skipping unused files:debugfs.c drd.c dwc3-exynos.c dwc3-haps.c dwc3-imx8mp.c dwc3-keystone.c dwc3-octeon.c dwc3-of-simple.c dwc3-pci.c dwc3-qcom.c dwc3-qcom-legacy.c dwc3-rtk.c dwc3-st.c dwc3-xilinx.c host.c trace.c trace.h ulpi.c
Note that this is a raw import and doesn't build. A fixup commit at the end of the series fixes that.
List of commits: git log --oneline v6.12..v6.13
Commits imported:625e70ccb7bb usb: dwc3-am62: Disable autosuspend during remove01ea6bf5cb58 usb: dwc3: gadget: fix writing NYET thresholdf5313c8b418c usb: dwc3: gadget: Remove dwc3_request->needs_extra_trb 61440628a4ff usb: dwc3: gadget: Cleanup SG handlingb7fc65f5141c usb: dwc3: gadget: Fix looping of queued SG entries02a6982b0ccf usb: dwc3: gadget: Fix checking for number of TRBs left 5d2fb074dea2 usb: dwc3: ep0: Don't clear ep0 DWC3_EP_TRANSFER_STARTED ce25e2a8d82d usb: dwc3: core: Set force_gen1 bit for all applicable SuperSpeed ports 61eb055cd304 usb: dwc3: gadget: Add missing check for single port RAM in TxFIFO resizing logic 6ff78df5b3d0 usb: Use (of|device)_property_present() for non-boolean properties fad16c823e66 usb: dwc3: gadget: Refine the logic for resizing Tx FIFOs 9a0749d61a9a usb: Switch back to struct platform_driver::remove()57d7a6b93822 usb: dwc3: Correct some typos in comments
--- drivers/usb/dwc3/core.c | 16 ++-- drivers/usb/dwc3/core.h | 15 ++-- drivers/usb/dwc3/dwc3-am62.c | 3 +- drivers/usb/dwc3/ep0.c | 4 +- drivers/usb/dwc3/gadget.c | 156 +++++++++++++++++++++-------------- 5 files changed, 114 insertions(+), 80 deletions(-)
drivers/usb/dwc3/core.c +10 -6
@@ -1409,7 +1409,7 @@ static int dwc3_core_init(struct dwc3 *dwc)/* * When configured in HOST mode, after issuing U3/L2 exit controller -* fails to send proper CRC checksum in CRC5 feild. Because of this +* fails to send proper CRC checksum in CRC5 field. Because of this * behaviour Transaction Error is generated, resulting in reset and * re-enumeration of usb device attached. All the termsel, xcvrsel, * opmode becomes 0 during end of resume. Enabling bit 10 of GUCTL1
@@ -1470,9 +1470,13 @@ static int dwc3_core_init(struct dwc3 *dwc)if (hw_mode !=DWC3_GHWPARAMS0_MODE_GADGET && (DWC3_IP_IS (DWC31 )) && dwc->maximum_speed ==USB_SPEED_SUPER ) { - reg =dwc3_readl (dwc->regs,DWC3_LLUCTL ); - reg |=DWC3_LLUCTL_FORCE_GEN1 ; -dwc3_writel (dwc->regs,DWC3_LLUCTL , reg); +int i; + +for (i =0 ; i < dwc->num_usb3_ports; i++) { + reg =dwc3_readl (dwc->regs,DWC3_LLUCTL (i)); + reg |=DWC3_LLUCTL_FORCE_GEN1 ; +dwc3_writel (dwc->regs,DWC3_LLUCTL (i), reg); + } }return 0 ;
@@ -1941,7 +1945,7 @@ static struct extcon_dev *dwc3_get_extcon(struct dwc3 *dwc)struct extcon_dev *edev =NULL ;const char *name; -if (device_property_read_bool (dev,"extcon" )) +if (device_property_present (dev,"extcon" ))return extcon_get_edev_by_phandle (dev,0 );/*
@@ -2651,7 +2655,7 @@ MODULE_DEVICE_TABLE(acpi, dwc3_acpi_match);static struct platform_driver dwc3_driver = { .probe = dwc3_probe, - .remove_new = dwc3_remove, + .remove = dwc3_remove, .driver = { .name ="dwc3" , .of_match_table =of_match_ptr (of_dwc3_match),
drivers/usb/dwc3/core.h +7 -8
@@ -81,7 +81,7 @@#define DWC3_GSNPSREV_MASK 0xffff#define DWC3_GSNPS_ID (p) (((p) & DWC3_GSNPSID_MASK) >> 16) -/* DWC3 registers memory space boundries */ +/* DWC3 registers memory space boundaries */ #define DWC3_XHCI_REGS_START 0x0#define DWC3_XHCI_REGS_END 0x7fff#define DWC3_GLOBALS_REGS_START 0xc100
@@ -179,7 +179,7 @@#define DWC3_OEVTEN 0xcc0C#define DWC3_OSTS 0xcc10 -#define DWC3_LLUCTL 0xd024 +#define DWC3_LLUCTL (n) (0xd024 + ((n) * 0x80))/* Bit fields */
@@ -464,6 +464,7 @@#define DWC3_DCTL_TRGTULST_SS_INACT (DWC3_DCTL_TRGTULST(6))/* These apply for core versions 1.94a and later */ +#define DWC3_DCTL_NYET_THRES_MASK (0xf << 20)#define DWC3_DCTL_NYET_THRES (n) (((n) & 0xf) << 20)#define DWC3_DCTL_KEEP_CONNECT BIT(19)
@@ -915,6 +916,7 @@ struct dwc3_hwparams {#define DWC3_MODE (n) ((n) & 0x7)/* HWPARAMS1 */ +#define DWC3_SPRAM_TYPE (n) (((n) >> 23) & 1)#define DWC3_NUM_INT (n) (((n) & (0x3f << 15)) >> 15)/* HWPARAMS3 */
@@ -925,6 +927,9 @@ struct dwc3_hwparams {#define DWC3_NUM_IN_EPS (p) (((p)->hwparams3 & \ (DWC3_NUM_IN_EPS_MASK)) >> 18) +/* HWPARAMS6 */ +#define DWC3_RAM0_DEPTH (n) (((n) & (0xffff0000)) >> 16) +/* HWPARAMS7 */ #define DWC3_RAM1_DEPTH (n) ((n) & 0xffff)
@@ -937,18 +942,14 @@ struct dwc3_hwparams {* @request: struct usb_request to be transferred * @list: a list_head used for request queueing * @dep: struct dwc3_ep owning this request -* @sg: pointer to first incomplete sg * @start_sg: pointer to the sg which should be queued next * @num_pending_sgs: counter to pending sgs -* @num_queued_sgs: counter to the number of sgs which already got queued * @remaining: amount of data remaining * @status: internal dwc3 request status tracking * @epnum: endpoint number to which this request refers * @trb: pointer to struct dwc3_trb * @trb_dma: DMA address of @trb * @num_trbs: number of TRBs used by this request -* @needs_extra_trb: true when request needs one extra TRB (either due to ZLP -* or unaligned OUT) * @direction: IN or OUT direction flag * @mapped: true when request has been dma-mapped */
@@ -960,7 +961,6 @@ struct dwc3_request {struct scatterlist *start_sg;unsigned int num_pending_sgs; -unsigned int num_queued_sgs;unsigned int remaining;unsigned int status;
@@ -978,7 +978,6 @@ struct dwc3_request {unsigned int num_trbs; - unsigned int needs_extra_trb:1; unsigned int direction:1; unsigned int mapped:1; };
drivers/usb/dwc3/dwc3-am62.c +2 -1
@@ -309,6 +309,7 @@ static void dwc3_ti_remove(struct platform_device *pdev)pm_runtime_put_sync (dev);pm_runtime_disable (dev); +pm_runtime_dont_use_autosuspend (dev);pm_runtime_set_suspended (dev); }
@@ -377,7 +378,7 @@ MODULE_DEVICE_TABLE(of, dwc3_ti_of_match);static struct platform_driver dwc3_ti_driver = { .probe = dwc3_ti_probe, - .remove_new = dwc3_ti_remove, + .remove = dwc3_ti_remove, .driver = { .name ="dwc3-am62" , .pm =DEV_PM_OPS ,
drivers/usb/dwc3/ep0.c +2 -2
@@ -145,7 +145,7 @@ static int __dwc3_gadget_ep0_queue(struct dwc3_ep *dep,* Unfortunately we have uncovered a limitation wrt the Data Phase. * * Section 9.4 says we can wait for the XferNotReady(DATA) event to -* come before issueing Start Transfer command, but if we do, we will +* come before issuing Start Transfer command, but if we do, we will * miss situations where the host starts another SETUP phase instead of * the DATA phase. Such cases happen at least on TD.7.6 of the Link * Layer Compliance Suite.
@@ -232,7 +232,7 @@ void dwc3_ep0_stall_and_restart(struct dwc3 *dwc)/* stall is always issued on EP0 */ dep = dwc->eps[0 ];__dwc3_gadget_ep_set_halt (dep,1 , false); - dep->flags &=DWC3_EP_RESOURCE_ALLOCATED ; + dep->flags &=DWC3_EP_RESOURCE_ALLOCATED |DWC3_EP_TRANSFER_STARTED ; dep->flags |=DWC3_EP_ENABLED ; dwc->delayed_status = false;
drivers/usb/dwc3/gadget.c +93 -63
295 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH v10 59/63 usb: dwc3: import from kernel v6.14
In reply to Anders RoxellFrom: Jens Wiklander <[email protected]>
Sync Linux kernel dwc3 changes from v6.13 to v6.14.
The following files are preserved across the import:Makefile Kconfig dwc3-meson-g12a.c dwc3-meson-gxl.c dwc3-omap.c dwc3-uniphier.c dwc3-generic.h dwc3-generic.c dwc3-generic-sti.c dwc3-layerscape.c ti_usb_phy.c
Skipping unused files:debugfs.c drd.c dwc3-exynos.c dwc3-haps.c dwc3-imx8mp.c dwc3-keystone.c dwc3-octeon.c dwc3-of-simple.c dwc3-pci.c dwc3-qcom.c dwc3-qcom-legacy.c dwc3-rtk.c dwc3-st.c dwc3-xilinx.c host.c trace.c trace.h ulpi.c
Note that this is a raw import and doesn't build. A fixup commit at the end of the series fixes that.
List of commits: git log --oneline v6.13..v6.14
Commits imported:cc5bfc4e16fc usb: dwc3: Set SUSPENDENABLE soon after phy init 69c58deec196 usb: dwc3: gadget: Prevent irq storm when TH re-executes d3a8c28426fc usb: dwc3: Fix timeout issue during controller enter/exit from halt state 1ed3af5a2aae usb: dwc3: Document nostream_work66e0ea341a2a usb: dwc3: core: Defer the probe until USB power supply ready dcfe437492e2 usb: dwc3: gadget: Reinitiate stream for all host NoStream behavior a266462b937b usb: dwc3-am62: Fix an OF node leak in phy_syscon_pll_refclk() e3a9bd247cdd usb: dwc3: Skip resume if pm_runtime_set_active() fails 1ff24d40b3c3 usb: dwc3: gadget: Fix incorrect UDC state after manual deconfiguration 31d500c2d0d4 usb: dwc3: dwc3-am62: Re-initialize controller if lost power in PM suspend 04d5b4c23f3b usb: dwc3: core: Disable USB2 retry for DWC_usb31 1.80a and prior 686d4a2c26b4 usb: dwc3: remove unused sg struct member
--- drivers/usb/dwc3/core.c | 140 ++++++++++++++++++++----------- drivers/usb/dwc3/core.h | 8 +- drivers/usb/dwc3/dwc3-am62.c | 83 +++++++++++++------ drivers/usb/dwc3/gadget.c | 155 ++++++++++++++++++++++------------- 4 files changed, 254 insertions(+), 132 deletions(-)
drivers/usb/dwc3/core.c +93 -47
@@ -131,11 +131,24 @@ void dwc3_enable_susphy(struct dwc3 *dwc, bool enable) } } -void dwc3_set_prtcap (struct dwc3 *dwc,u32 mode) +void dwc3_set_prtcap (struct dwc3 *dwc,u32 mode,bool ignore_susphy) { +unsigned int hw_mode;u32 reg; reg =dwc3_readl (dwc->regs,DWC3_GCTL ); + +/* +* For DRD controllers, GUSB3PIPECTL.SUSPENDENABLE and +* GUSB2PHYCFG.SUSPHY should be cleared during mode switching, +* and they can be set after core initialization. +*/ + hw_mode =DWC3_GHWPARAMS0_MODE (dwc->hwparams.hwparams0); +if (hw_mode ==DWC3_GHWPARAMS0_MODE_DRD && !ignore_susphy) { +if (DWC3_GCTL_PRTCAP (reg) != mode) +dwc3_enable_susphy (dwc, false); + } + reg &= ~(DWC3_GCTL_PRTCAPDIR (DWC3_GCTL_PRTCAP_OTG )); reg |=DWC3_GCTL_PRTCAPDIR (mode);dwc3_writel (dwc->regs,DWC3_GCTL , reg);
@@ -216,7 +229,7 @@ static void __dwc3_set_mode(struct work_struct *work)spin_lock_irqsave (&dwc->lock, flags); -dwc3_set_prtcap (dwc, desired_dr_role); +dwc3_set_prtcap (dwc, desired_dr_role, false);spin_unlock_irqrestore (&dwc->lock, flags);
@@ -658,16 +671,7 @@ static int dwc3_ss_phy_setup(struct dwc3 *dwc, int index)*/ reg &= ~DWC3_GUSB3PIPECTL_UX_EXIT_PX ; -/* -* Above DWC_usb3.0 1.94a, it is recommended to set -* DWC3_GUSB3PIPECTL_SUSPHY to '0' during coreConsultant configuration. -* So default value will be '0' when the core is reset. Application -* needs to set it to '1' after the core initialization is completed. -* -* Similarly for DRD controllers, GUSB3PIPECTL.SUSPENDENABLE must be -* cleared after power-on reset, and it can be set after core -* initialization. -*/ +/* Ensure the GUSB3PIPECTL.SUSPENDENABLE is cleared prior to phy init. */ reg &= ~DWC3_GUSB3PIPECTL_SUSPHY ;if (dwc->u2ss_inp3_quirk)
@@ -747,15 +751,7 @@ static int dwc3_hs_phy_setup(struct dwc3 *dwc, int index)break ; } -/* -* Above DWC_usb3.0 1.94a, it is recommended to set -* DWC3_GUSB2PHYCFG_SUSPHY to '0' during coreConsultant configuration. -* So default value will be '0' when the core is reset. Application -* needs to set it to '1' after the core initialization is completed. -* -* Similarly for DRD controllers, GUSB2PHYCFG.SUSPHY must be cleared -* after power-on reset, and it can be set after core initialization. -*/ +/* Ensure the GUSB2PHYCFG.SUSPHY is cleared prior to phy init. */ reg &= ~DWC3_GUSB2PHYCFG_SUSPHY ;if (dwc->dis_enblslpm_quirk)
@@ -830,6 +826,25 @@ static int dwc3_phy_init(struct dwc3 *dwc) goto err_exit_usb3_phy; } +/* +* Above DWC_usb3.0 1.94a, it is recommended to set +* DWC3_GUSB3PIPECTL_SUSPHY and DWC3_GUSB2PHYCFG_SUSPHY to '0' during +* coreConsultant configuration. So default value will be '0' when the +* core is reset. Application needs to set it to '1' after the core +* initialization is completed. +* +* Certain phy requires to be in P0 power state during initialization. +* Make sure GUSB3PIPECTL.SUSPENDENABLE and GUSB2PHYCFG.SUSPHY are clear +* prior to phy init to maintain in the P0 state. +* +* After phy initialization, some phy operations can only be executed +* while in lower P states. Ensure GUSB3PIPECTL.SUSPENDENABLE and +* GUSB2PHYCFG.SUSPHY are set soon after initialization to avoid +* blocking phy ops. +*/ + if (!DWC3_VER_IS_WITHIN(DWC3, ANY, 194A)) +dwc3_enable_susphy (dwc, true); +return 0 ; err_exit_usb3_phy:
@@ -1479,6 +1494,26 @@ static int dwc3_core_init(struct dwc3 *dwc) } } +/* +* STAR 9001346572: This issue affects DWC_usb31 versions 1.80a and +* prior. When an active endpoint not currently cached in the host +* controller is chosen to be cached to the same index as an endpoint +* receiving NAKs, the endpoint receiving NAKs enters continuous +* retry mode. This prevents it from being evicted from the host +* controller cache, blocking the new endpoint from being cached and +* serviced. +* +* To resolve this, for controller versions 1.70a and 1.80a, set the +* GUCTL3 bit[16] (USB2.0 Internal Retry Disable) to 1. This bit +* disables the USB2.0 internal retry feature. The GUCTL3[16] register +* function is available only from version 1.70a. +*/ + if (DWC3_VER_IS_WITHIN(DWC31, 170A, 180A)) { + reg =dwc3_readl (dwc->regs,DWC3_GUCTL3 ); + reg |=DWC3_GUCTL3_USB20_RETRY_DISABLE ; +dwc3_writel (dwc->regs,DWC3_GUCTL3 , reg); + } +return 0 ; err_power_off_phy:
@@ -1568,7 +1603,7 @@ static int dwc3_core_init_mode(struct dwc3 *dwc)switch (dwc->dr_mode) {case USB_DR_MODE_PERIPHERAL : -dwc3_set_prtcap (dwc,DWC3_GCTL_PRTCAP_DEVICE ); +dwc3_set_prtcap (dwc,DWC3_GCTL_PRTCAP_DEVICE , false);if (dwc->usb2_phy)otg_set_vbus (dwc->usb2_phy->otg, false);
@@ -1580,7 +1615,7 @@ static int dwc3_core_init_mode(struct dwc3 *dwc)return dev_err_probe (dev, ret,"failed to initialize gadget\n" );break ;case USB_DR_MODE_HOST : -dwc3_set_prtcap (dwc,DWC3_GCTL_PRTCAP_HOST ); +dwc3_set_prtcap (dwc,DWC3_GCTL_PRTCAP_HOST , false);if (dwc->usb2_phy)otg_set_vbus (dwc->usb2_phy->otg, true);
@@ -1625,7 +1660,7 @@ static void dwc3_core_exit_mode(struct dwc3 *dwc) }/* de-assert DRVVBUS for HOST and OTG mode */ -dwc3_set_prtcap (dwc,DWC3_GCTL_PRTCAP_DEVICE ); +dwc3_set_prtcap (dwc,DWC3_GCTL_PRTCAP_DEVICE , true); }static void dwc3_get_software_properties (struct dwc3 *dwc)
@@ -1664,8 +1699,6 @@ static void dwc3_get_properties(struct dwc3 *dwc)u8 tx_thr_num_pkt_prd =0 ;u8 tx_max_burst_prd =0 ;u8 tx_fifo_resize_max_num; -const char *usb_psy_name; -int ret;/* default to highest possible threshold */ lpm_nyet_threshold =0xf ;
@@ -1700,13 +1733,6 @@ static void dwc3_get_properties(struct dwc3 *dwc) dwc->sys_wakeup =device_may_wakeup (dwc->sysdev); - ret =device_property_read_string (dev,"usb-psy-name" , &usb_psy_name); -if (ret >=0 ) { - dwc->usb_psy =power_supply_get_by_name (usb_psy_name); -if (!dwc->usb_psy) -dev_err (dev,"couldn't get usb power supply\n" ); - } - dwc->has_lpm_erratum =device_property_read_bool (dev,"snps,has-lpm-erratum" ); device_property_read_u8(dev, "snps,lpm-nyet-threshold",
@@ -1824,8 +1850,6 @@ static void dwc3_get_properties(struct dwc3 *dwc) dwc->tx_thr_num_pkt_prd = tx_thr_num_pkt_prd; dwc->tx_max_burst_prd = tx_max_burst_prd; - dwc->imod_interval =0 ; - dwc->tx_fifo_resize_max_num = tx_fifo_resize_max_num; }
@@ -1843,21 +1867,19 @@ static void dwc3_check_params(struct dwc3 *dwc)unsigned int hwparam_gen =DWC3_GHWPARAMS3_SSPHY_IFC (dwc->hwparams.hwparams3); -/* Check for proper value of imod_interval */ -if (dwc->imod_interval && !dwc3_has_imod (dwc)) { -dev_warn (dwc->dev,"Interrupt moderation not supported\n" ); - dwc->imod_interval =0 ; - } -/* +* Enable IMOD for all supporting controllers. +* +* Particularly, DWC_usb3 v3.00a must enable this feature for +* the following reason: +* * Workaround for STAR 9000961433 which affects only version * 3.00a of the DWC_usb3 core. This prevents the controller * interrupt from being masked while handling events. IMOD * allows us to work around this issue. Enable it for the * affected version. */ -if (!dwc->imod_interval && - DWC3_VER_IS(DWC3, 300A)) +if (dwc3_has_imod ((dwc))) dwc->imod_interval =1 ;/* Check the maximum_speed parameter */
@@ -2109,6 +2131,23 @@ static int dwc3_get_num_ports(struct dwc3 *dwc)return 0 ; } +static struct power_supply *dwc3_get_usb_power_supply (struct dwc3 *dwc) +{ +struct power_supply *usb_psy; +const char *usb_psy_name; +int ret; + + ret =device_property_read_string (dwc->dev,"usb-psy-name" , &usb_psy_name); +if (ret <0 ) +return NULL ; + + usb_psy =power_supply_get_by_name (usb_psy_name); +if (!usb_psy) +return ERR_PTR (-EPROBE_DEFER ); + +return usb_psy; +} +static int dwc3_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev;
@@ -2165,6 +2204,10 @@ static int dwc3_probe(struct platform_device *pdev)dwc3_get_software_properties (dwc); + dwc->usb_psy =dwc3_get_usb_power_supply (dwc); +if (IS_ERR (dwc->usb_psy)) +return dev_err_probe (dev,PTR_ERR (dwc->usb_psy),"couldn't get usb power supply\n" ); + dwc->reset =devm_reset_control_array_get_optional_shared (dev);if (IS_ERR (dwc->reset)) { ret =PTR_ERR (dwc->reset);
@@ -2425,7 +2468,7 @@ static int dwc3_resume_common(struct dwc3 *dwc, pm_message_t msg)if (ret)return ret; -dwc3_set_prtcap (dwc,DWC3_GCTL_PRTCAP_DEVICE ); +dwc3_set_prtcap (dwc,DWC3_GCTL_PRTCAP_DEVICE , true);dwc3_gadget_resume (dwc);break ;case DWC3_GCTL_PRTCAP_HOST :
@@ -2433,7 +2476,7 @@ static int dwc3_resume_common(struct dwc3 *dwc, pm_message_t msg) ret =dwc3_core_init_for_resume (dwc);if (ret)return ret; -dwc3_set_prtcap (dwc,DWC3_GCTL_PRTCAP_HOST ); +dwc3_set_prtcap (dwc,DWC3_GCTL_PRTCAP_HOST , true);break ; }/* Restore GUSB2PHYCFG bits that were modified in suspend */
@@ -2462,7 +2505,7 @@ static int dwc3_resume_common(struct dwc3 *dwc, pm_message_t msg)if (ret)return ret; -dwc3_set_prtcap (dwc, dwc->current_dr_role); +dwc3_set_prtcap (dwc, dwc->current_dr_role, true);dwc3_otg_init (dwc);if (dwc->current_otg_role ==DWC3_OTG_ROLE_HOST ) {
@@ -2589,12 +2632,15 @@ static int dwc3_resume(struct device *dev)pinctrl_pm_select_default_state (dev);pm_runtime_disable (dev); -pm_runtime_set_active (dev); + ret =pm_runtime_set_active (dev); +if (ret) + goto out; ret =dwc3_resume_common (dwc,PMSG_RESUME );if (ret)pm_runtime_set_suspended (dev); +out:pm_runtime_enable (dev);return ret;
drivers/usb/dwc3/core.h +5 -3
@@ -425,6 +425,7 @@/* Global User Control Register 3 */ #define DWC3_GUCTL3_SPLITDISABLE BIT(14) +#define DWC3_GUCTL3_USB20_RETRY_DISABLE BIT(16)/* Device Configuration Register */ #define DWC3_DCFG_NUMLANES (n) (((n) & 0x3) << 30)/* DWC_usb32 only */
@@ -716,6 +717,7 @@ struct dwc3_event_buffer {/** * struct dwc3_ep - device side endpoint representation * @endpoint: usb endpoint +* @nostream_work: work for handling bulk NoStream * @cancelled_list: list of cancelled requests for this endpoint * @pending_list: list of pending requests for this endpoint * @started_list: list of started requests on this endpoint
@@ -742,6 +744,7 @@ struct dwc3_event_buffer {*/ struct dwc3_ep {struct usb_ep endpoint; +struct delayed_work nostream_work;struct list_head cancelled_list;struct list_head pending_list;struct list_head started_list;
@@ -764,7 +767,7 @@ struct dwc3_ep {#define DWC3_EP_WAIT_TRANSFER_COMPLETE BIT(7)#define DWC3_EP_IGNORE_NEXT_NOSTREAM BIT(8)#define DWC3_EP_FORCE_RESTART_STREAM BIT(9) -#define DWC3_EP_FIRST_STREAM_PRIMED BIT(10) +#define DWC3_EP_STREAM_PRIMED BIT(10)#define DWC3_EP_PENDING_CLEAR_STALL BIT(11)#define DWC3_EP_TXFIFO_RESIZED BIT(12)#define DWC3_EP_DELAY_STOP BIT(13)
@@ -957,7 +960,6 @@ struct dwc3_request {struct usb_request request;struct list_head list;struct dwc3_ep *dep; -struct scatterlist *sg;struct scatterlist *start_sg;unsigned int num_pending_sgs;
@@ -1556,7 +1558,7 @@ struct dwc3_gadget_ep_cmd_params {#define DWC3_HAS_OTG BIT(3)/* prototypes */ -void dwc3_set_prtcap (struct dwc3 *dwc,u32 mode); +void dwc3_set_prtcap (struct dwc3 *dwc,u32 mode,bool ignore_susphy);void dwc3_set_mode (struct dwc3 *dwc,u32 mode);u32 dwc3_core_fifo_space (struct dwc3_ep *dep,u8 type);
drivers/usb/dwc3/dwc3-am62.c +56 -27
149 lines not on this page · raw message
drivers/usb/dwc3/gadget.c +100 -55
222 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH v10 60/63 usb: dwc3: import from kernel v6.15
In reply to Anders RoxellFrom: Jens Wiklander <[email protected]>
Sync Linux kernel dwc3 changes from v6.14 to v6.15.
The following files are preserved across the import:Makefile Kconfig dwc3-meson-g12a.c dwc3-meson-gxl.c dwc3-omap.c dwc3-uniphier.c dwc3-generic.h dwc3-generic.c dwc3-generic-sti.c dwc3-layerscape.c ti_usb_phy.c
Skipping unused files:debugfs.c drd.c dwc3-exynos.c dwc3-haps.c dwc3-imx8mp.c dwc3-keystone.c dwc3-octeon.c dwc3-of-simple.c dwc3-pci.c dwc3-qcom.c dwc3-qcom-legacy.c dwc3-rtk.c dwc3-st.c dwc3-xilinx.c host.c trace.c trace.h ulpi.c
Note that this is a raw import and doesn't build. A fixup commit at the end of the series fixes that.
List of commits: git log --oneline v6.14..v6.15
Commits imported:2372f1caeca4 usb: dwc3: gadget: Make gadget_wakeup asynchronous 63ccd26cd1f6 usb: dwc3: gadget: check that event count does not exceed event buffer length 042c3dd1f2d3 usb: dwc3: Don't use %pK through printk07959ad5775f USB: dwc3: Use syscon_regmap_lookup_by_phandle_args 5425191f85fe usb: dwc3: gadget: Add support for snps,reserved-endpoints property eafba0205426 usb: dwc3: gadget: Refactor loop to avoid NULL endpoints
--- drivers/usb/dwc3/core.h | 4 ++ drivers/usb/dwc3/dwc3-am62.c | 12 +--- drivers/usb/dwc3/gadget.c | 135 +++++++++++++++++++++++------------ 3 files changed, 96 insertions(+), 55 deletions(-)
drivers/usb/dwc3/core.h +4 -0
@@ -1164,6 +1164,9 @@ struct dwc3_scratchpad_array {* @gsbuscfg0_reqinfo: store GSBUSCFG0.DATRDREQINFO, DESRDREQINFO, * DATWRREQINFO, and DESWRREQINFO value passed from * glue driver. +* @wakeup_pending_funcs: Indicates whether any interface has requested for +* function wakeup in bitmap format where bit position +* represents interface_id. */ struct dwc3 {struct work_struct drd_work;
@@ -1394,6 +1397,7 @@ struct dwc3 {int num_ep_resized;struct dentry *debug_root;u32 gsbuscfg0_reqinfo; +u32 wakeup_pending_funcs; };#define INCRX_BURST_MODE 0
drivers/usb/dwc3/dwc3-am62.c +2 -10
@@ -153,11 +153,11 @@ static int phy_syscon_pll_refclk(struct dwc3_am62 *am62) {struct device *dev = am62->dev;struct device_node *node = dev->of_node; -struct of_phandle_args args;struct regmap *syscon;int ret; - syscon =syscon_regmap_lookup_by_phandle (node,"ti,syscon-phy-pll-refclk" ); + syscon =syscon_regmap_lookup_by_phandle_args (node,"ti,syscon-phy-pll-refclk" , +1 , &am62->offset);if (IS_ERR (syscon)) {dev_err (dev,"unable to get ti,syscon-phy-pll-refclk regmap\n" );return PTR_ERR (syscon);
@@ -165,14 +165,6 @@ static int phy_syscon_pll_refclk(struct dwc3_am62 *am62) am62->syscon = syscon; - ret =of_parse_phandle_with_fixed_args (node,"ti,syscon-phy-pll-refclk" ,1 , -0 , &args); -if (ret) -return ret; - -of_node_put (args.np); - 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) {
drivers/usb/dwc3/gadget.c +90 -45
257 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH v10 61/63 usb: dwc3: import from kernel v6.16
In reply to Anders RoxellFrom: Jens Wiklander <[email protected]>
Sync Linux kernel dwc3 changes from v6.15 to v6.16.
The following files are preserved across the import:Makefile Kconfig dwc3-meson-g12a.c dwc3-meson-gxl.c dwc3-omap.c dwc3-uniphier.c dwc3-generic.h dwc3-generic.c dwc3-generic-sti.c dwc3-layerscape.c ti_usb_phy.c
Skipping unused files:debugfs.c drd.c dwc3-exynos.c dwc3-haps.c dwc3-imx8mp.c dwc3-keystone.c dwc3-octeon.c dwc3-of-simple.c dwc3-pci.c dwc3-qcom.c dwc3-qcom-legacy.c dwc3-rtk.c dwc3-st.c dwc3-xilinx.c host.c trace.c trace.h ulpi.c
Note that this is a raw import and doesn't build. A fixup commit at the end of the series fixes that.
List of commits: git log --oneline v6.15..v6.16
Commits imported:80e083943775 usb: dwc3: gadget: Fix TRB reclaim logic for short transfers and ZLPs 630a1dec3b0e usb: dwc3: Abort suspend on soft disconnect failure 170940f7e685 usb: dwc3: core: Don't touch resets and clocks 613a2e655d4d usb: dwc3: core: Expose core driver as library 850e634006f4 usb: dwc3: core: Avoid redundant system suspend/resume callbacks 8da7644493b4 usb: dwc3: Specify maximum number of XHCI interrupters
--- drivers/usb/dwc3/core.c | 206 ++++++++++++++++++++++++++++---------- drivers/usb/dwc3/core.h | 2 + drivers/usb/dwc3/gadget.c | 24 ++--- drivers/usb/dwc3/glue.h | 36 +++++++ 4 files changed, 199 insertions(+), 69 deletions(-) create mode 100644 drivers/usb/dwc3/glue.h
drivers/usb/dwc3/core.c +151 -55
@@ -26,6 +26,7 @@#include <linux/of_graph.h> #include <linux/acpi.h> #include <linux/pinctrl/consumer.h> +#include <linux/pinctrl/devinfo.h> #include <linux/reset.h> #include <linux/bitfield.h>
@@ -36,6 +37,7 @@#include "core.h" #include "gadget.h" +#include "glue.h" #include "io.h" #include "debug.h"
@@ -1699,6 +1701,7 @@ static void dwc3_get_properties(struct dwc3 *dwc)u8 tx_thr_num_pkt_prd =0 ;u8 tx_max_burst_prd =0 ;u8 tx_fifo_resize_max_num; +u16 num_hc_interrupters;/* default to highest possible threshold */ lpm_nyet_threshold =0xf ;
@@ -1719,6 +1722,9 @@ static void dwc3_get_properties(struct dwc3 *dwc)*/ tx_fifo_resize_max_num =6 ; +/* default to a single XHCI interrupter */ + num_hc_interrupters =1 ; + dwc->maximum_speed =usb_get_maximum_speed (dev); dwc->max_ssp_rate =usb_get_maximum_ssp_rate (dev); dwc->dr_mode =usb_get_dr_mode (dev);
@@ -1765,6 +1771,12 @@ static void dwc3_get_properties(struct dwc3 *dwc) &tx_thr_num_pkt_prd);device_property_read_u8 (dev,"snps,tx-max-burst-prd" , &tx_max_burst_prd); +device_property_read_u16 (dev,"num-hc-interrupters" , + &num_hc_interrupters); +/* DWC3 core allowed to have a max of 8 interrupters */ +if (num_hc_interrupters >8 ) + num_hc_interrupters =8 ; + dwc->do_fifo_resize =device_property_read_bool (dev,"tx-fifo-resize" );if (dwc->do_fifo_resize)
@@ -1851,6 +1863,8 @@ static void dwc3_get_properties(struct dwc3 *dwc) dwc->tx_max_burst_prd = tx_max_burst_prd; dwc->tx_fifo_resize_max_num = tx_fifo_resize_max_num; + + dwc->num_hc_interrupters = num_hc_interrupters; }/* check whether the core supports IMOD */
@@ -2148,27 +2162,16 @@ static struct power_supply *dwc3_get_usb_power_supply(struct dwc3 *dwc)return usb_psy; } -static int dwc3_probe (struct platform_device *pdev) +int dwc3_core_probe (const struct dwc3_probe_data *data) { -struct device *dev = &pdev->dev; -struct resource *res, dwc_res; +struct dwc3 *dwc = data->dwc; +struct device *dev = dwc->dev; +struct resource dwc_res;unsigned int hw_mode;void __iomem *regs; -struct dwc3 *dwc; +struct resource *res = data->res;int ret; - dwc =devm_kzalloc (dev,sizeof (*dwc),GFP_KERNEL ); -if (!dwc) -return -ENOMEM ; - - dwc->dev = dev; - - res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); -if (!res) { -dev_err (dev,"missing memory resource\n" ); -return -ENODEV ; - } - dwc->xhci_resources[0 ].start = res->start; dwc->xhci_resources[0 ].end = dwc->xhci_resources[0 ].start +DWC3_XHCI_REGS_END ;
@@ -2208,15 +2211,17 @@ static int dwc3_probe(struct platform_device *pdev)if (IS_ERR (dwc->usb_psy))return dev_err_probe (dev,PTR_ERR (dwc->usb_psy),"couldn't get usb power supply\n" ); - dwc->reset =devm_reset_control_array_get_optional_shared (dev); -if (IS_ERR (dwc->reset)) { - ret =PTR_ERR (dwc->reset); - goto err_put_psy; - } +if (!data->ignore_clocks_and_resets) { + dwc->reset =devm_reset_control_array_get_optional_shared (dev); +if (IS_ERR (dwc->reset)) { + ret =PTR_ERR (dwc->reset); + goto err_put_psy; + } - ret =dwc3_get_clocks (dwc); -if (ret) - goto err_put_psy; + ret =dwc3_get_clocks (dwc); +if (ret) + goto err_put_psy; + } ret =reset_control_deassert (dwc->reset);if (ret)
@@ -2232,7 +2237,7 @@ static int dwc3_probe(struct platform_device *pdev) goto err_disable_clks; } -platform_set_drvdata (pdev, dwc); +dev_set_drvdata (dev, dwc);dwc3_cache_hwparams (dwc); if (!dwc->sysdev_is_parent &&
@@ -2327,12 +2332,35 @@ err_put_psy:return ret; } +EXPORT_SYMBOL_GPL (dwc3_core_probe); -static void dwc3_remove (struct platform_device *pdev) +static int dwc3_probe (struct platform_device *pdev) { -struct dwc3 *dwc =platform_get_drvdata (pdev); +struct dwc3_probe_data probe_data = {}; +struct resource *res; +struct dwc3 *dwc; + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (!res) { +dev_err (&pdev->dev,"missing memory resource\n" ); +return -ENODEV ; + } + + dwc =devm_kzalloc (&pdev->dev,sizeof (*dwc),GFP_KERNEL ); +if (!dwc) +return -ENOMEM ; -pm_runtime_get_sync (&pdev->dev); + dwc->dev = &pdev->dev; + + probe_data.dwc = dwc; + probe_data.res = res; + +return dwc3_core_probe (&probe_data); +} + +void dwc3_core_remove (struct dwc3 *dwc) +{ +pm_runtime_get_sync (dwc->dev);dwc3_core_exit_mode (dwc);dwc3_debugfs_exit (dwc);
@@ -2340,22 +2368,28 @@ static void dwc3_remove(struct platform_device *pdev)dwc3_core_exit (dwc);dwc3_ulpi_exit (dwc); -pm_runtime_allow (&pdev->dev); -pm_runtime_disable (&pdev->dev); -pm_runtime_dont_use_autosuspend (&pdev->dev); -pm_runtime_put_noidle (&pdev->dev); +pm_runtime_allow (dwc->dev); +pm_runtime_disable (dwc->dev); +pm_runtime_dont_use_autosuspend (dwc->dev); +pm_runtime_put_noidle (dwc->dev);/* * HACK: Clear the driver data, which is currently accessed by parent * glue drivers, before allowing the parent to suspend. */ -platform_set_drvdata (pdev,NULL ); -pm_runtime_set_suspended (&pdev->dev); +dev_set_drvdata (dwc->dev,NULL ); +pm_runtime_set_suspended (dwc->dev);dwc3_free_event_buffers (dwc);if (dwc->usb_psy)power_supply_put (dwc->usb_psy); } +EXPORT_SYMBOL_GPL (dwc3_core_remove); + +static void dwc3_remove (struct platform_device *pdev) +{ +dwc3_core_remove (platform_get_drvdata (pdev)); +}#ifdef CONFIG_PM static int dwc3_core_init_for_resume (struct dwc3 *dwc)
@@ -2388,6 +2422,7 @@ static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg) {u32 reg;int i; +int ret;if (!pm_runtime_suspended (dwc->dev) && !PMSG_IS_AUTO (msg)) { dwc->susphy_state = (dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)) &
@@ -2406,7 +2441,9 @@ static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg)case DWC3_GCTL_PRTCAP_DEVICE :if (pm_runtime_suspended (dwc->dev))break ; -dwc3_gadget_suspend (dwc); + ret =dwc3_gadget_suspend (dwc); +if (ret) +return ret;synchronize_irq (dwc->irq_gadget);dwc3_core_exit (dwc);break ;
@@ -2441,7 +2478,9 @@ static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg)break ;if (dwc->current_otg_role ==DWC3_OTG_ROLE_DEVICE ) { -dwc3_gadget_suspend (dwc); + ret =dwc3_gadget_suspend (dwc); +if (ret) +return ret;synchronize_irq (dwc->irq_gadget); }
@@ -2544,9 +2583,8 @@ static int dwc3_runtime_checks(struct dwc3 *dwc)return 0 ; } -static int dwc3_runtime_suspend (struct device *dev) +int dwc3_runtime_suspend (struct dwc3 *dwc) { -struct dwc3 *dwc =dev_get_drvdata (dev);int ret;if (dwc3_runtime_checks (dwc))
@@ -2558,10 +2596,11 @@ static int dwc3_runtime_suspend(struct device *dev)return 0 ; } +EXPORT_SYMBOL_GPL (dwc3_runtime_suspend); -static int dwc3_runtime_resume (struct device *dev) +int dwc3_runtime_resume (struct dwc3 *dwc) { -struct dwc3 *dwc =dev_get_drvdata (dev); +struct device *dev = dwc->dev;int ret; ret =dwc3_resume_common (dwc,PMSG_AUTO_RESUME );
@@ -2571,7 +2610,7 @@ static int dwc3_runtime_resume(struct device *dev)switch (dwc->current_dr_role) {case DWC3_GCTL_PRTCAP_DEVICE :if (dwc->pending_events) { -pm_runtime_put (dwc->dev); +pm_runtime_put (dev); dwc->pending_events = false;enable_irq (dwc->irq_gadget); }
@@ -2586,10 +2625,11 @@ static int dwc3_runtime_resume(struct device *dev)return 0 ; } +EXPORT_SYMBOL_GPL (dwc3_runtime_resume); -static int dwc3_runtime_idle (struct device *dev) +int dwc3_runtime_idle (struct dwc3 *dwc) { -struct dwc3 *dwc =dev_get_drvdata (dev); +struct device *dev = dwc->dev;switch (dwc->current_dr_role) {case DWC3_GCTL_PRTCAP_DEVICE :
@@ -2607,12 +2647,28 @@ static int dwc3_runtime_idle(struct device *dev)return 0 ; } +EXPORT_SYMBOL_GPL (dwc3_runtime_idle); + +static int dwc3_plat_runtime_suspend (struct device *dev) +{ +return dwc3_runtime_suspend (dev_get_drvdata (dev)); +} + +static int dwc3_plat_runtime_resume (struct device *dev) +{ +return dwc3_runtime_resume (dev_get_drvdata (dev)); +} + +static int dwc3_plat_runtime_idle (struct device *dev) +{ +return dwc3_runtime_idle (dev_get_drvdata (dev)); +}#endif /* CONFIG_PM */ #ifdef CONFIG_PM_SLEEP -static int dwc3_suspend (struct device *dev) +int dwc3_pm_suspend (struct dwc3 *dwc) { -struct dwc3 *dwc =dev_get_drvdata (dev); +struct device *dev = dwc->dev;int ret; ret =dwc3_suspend_common (dwc,PMSG_SUSPEND );
@@ -2623,10 +2679,11 @@ static int dwc3_suspend(struct device *dev)return 0 ; } +EXPORT_SYMBOL_GPL (dwc3_pm_suspend); -static int dwc3_resume (struct device *dev) +int dwc3_pm_resume (struct dwc3 *dwc) { -struct dwc3 *dwc =dev_get_drvdata (dev); +struct device *dev = dwc->dev;int ret =0 ;pinctrl_pm_select_default_state (dev);
@@ -2645,10 +2702,10 @@ out:return ret; } +EXPORT_SYMBOL_GPL (dwc3_pm_resume); -static void dwc3_complete (struct device *dev) +void dwc3_pm_complete (struct dwc3 *dwc) { -struct dwc3 *dwc =dev_get_drvdata (dev);u32 reg; if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_HOST &&
@@ -2658,21 +2715,60 @@ static void dwc3_complete(struct device *dev) dwc3_writel(dwc->regs, DWC3_GUCTL3, reg); } } +EXPORT_SYMBOL_GPL (dwc3_pm_complete); + +int dwc3_pm_prepare (struct dwc3 *dwc) +{ +struct device *dev = dwc->dev; + +/* +* Indicate to the PM core that it may safely leave the device in +* runtime suspend if runtime-suspended already in device mode. +*/ +if (dwc->current_dr_role ==DWC3_GCTL_PRTCAP_DEVICE && +pm_runtime_suspended (dev) && + !dev_pinctrl (dev)) +return 1 ; + +return 0 ; +} +EXPORT_SYMBOL_GPL (dwc3_pm_prepare); + +static int dwc3_plat_suspend (struct device *dev) +{ +return dwc3_pm_suspend (dev_get_drvdata (dev)); +} + +static int dwc3_plat_resume (struct device *dev) +{ +return dwc3_pm_resume (dev_get_drvdata (dev)); +} + +static void dwc3_plat_complete (struct device *dev) +{ +dwc3_pm_complete (dev_get_drvdata (dev)); +} + +static int dwc3_plat_prepare (struct device *dev) +{ +return dwc3_pm_prepare (dev_get_drvdata (dev)); +}#else -#define dwc3_complete NULL +#define dwc3_plat_complete NULL +#define dwc3_plat_prepare NULL#endif /* CONFIG_PM_SLEEP */ static const struct dev_pm_ops dwc3_dev_pm_ops = { -SET_SYSTEM_SLEEP_PM_OPS (dwc3_suspend, dwc3_resume) - .complete = dwc3_complete, - +SET_SYSTEM_SLEEP_PM_OPS (dwc3_plat_suspend, dwc3_plat_resume) + .complete = dwc3_plat_complete, + .prepare = dwc3_plat_prepare,/* * Runtime suspend halts the controller on disconnection. It relies on * platforms with custom connection notification to start the controller * again. */ -SET_RUNTIME_PM_OPS (dwc3_runtime_suspend, dwc3_runtime_resume, - dwc3_runtime_idle) +SET_RUNTIME_PM_OPS (dwc3_plat_runtime_suspend, dwc3_plat_runtime_resume, + dwc3_plat_runtime_idle) };#ifdef CONFIG_OF
drivers/usb/dwc3/core.h +2 -0
@@ -1083,6 +1083,7 @@ struct dwc3_scratchpad_array {* @tx_max_burst_prd: max periodic ESS transmit burst size * @tx_fifo_resize_max_num: max number of fifos allocated during txfifo resize * @clear_stall_protocol: endpoint number that requires a delayed status phase +* @num_hc_interrupters: number of host controller interrupters * @hsphy_interface: "utmi" or "ulpi" * @connected: true when we're connected to a host, false otherwise * @softconnect: true when gadget connect is called, false when disconnect runs
@@ -1333,6 +1334,7 @@ struct dwc3 {u8 tx_max_burst_prd;u8 tx_fifo_resize_max_num;u8 clear_stall_protocol; +u16 num_hc_interrupters;const char *hsphy_interface;
drivers/usb/dwc3/gadget.c +10 -14
@@ -3516,7 +3516,7 @@ static int dwc3_gadget_ep_reclaim_completed_trb(struct dwc3_ep *dep,* We're going to do that here to avoid problems of HW trying * to use bogus TRBs for transfers. */ -if (chain && (trb->ctrl &DWC3_TRB_CTRL_HWO )) +if (trb->ctrl &DWC3_TRB_CTRL_HWO ) trb->ctrl &= ~DWC3_TRB_CTRL_HWO ;/*
@@ -4821,26 +4821,22 @@ int dwc3_gadget_suspend(struct dwc3 *dwc)int ret; ret =dwc3_gadget_soft_disconnect (dwc); -if (ret) - goto err; - -spin_lock_irqsave (&dwc->lock, flags); -if (dwc->gadget_driver) -dwc3_disconnect_gadget (dwc); -spin_unlock_irqrestore (&dwc->lock, flags); - -return 0 ; - -err:/* * Attempt to reset the controller's state. Likely no * communication can be established until the host * performs a port reset. */ -if (dwc->softconnect) +if (ret && dwc->softconnect) {dwc3_gadget_soft_connect (dwc); +return -EAGAIN ; + } -return ret; +spin_lock_irqsave (&dwc->lock, flags); +if (dwc->gadget_driver) +dwc3_disconnect_gadget (dwc); +spin_unlock_irqrestore (&dwc->lock, flags); + +return 0 ; }int dwc3_gadget_resume (struct dwc3 *dwc)
drivers/usb/dwc3/glue.h new file +36 -0
@@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* glue.h - DesignWare USB3 DRD glue header +*/ + +#ifndef __DRIVERS_USB_DWC3_GLUE_H +#define __DRIVERS_USB_DWC3_GLUE_H + +#include <linux/types.h> +#include "core.h" + +/** +* dwc3_probe_data: Initialization parameters passed to dwc3_core_probe() +* @dwc: Reference to dwc3 context structure +* @res: resource for the DWC3 core mmio region +* @ignore_clocks_and_resets: clocks and resets defined for the device should +* be ignored by the DWC3 core, as they are managed by the glue +*/ +struct dwc3_probe_data { +struct dwc3 *dwc; +struct resource *res; +bool ignore_clocks_and_resets; +}; + +int dwc3_core_probe (const struct dwc3_probe_data *data); +void dwc3_core_remove (struct dwc3 *dwc); + +int dwc3_runtime_suspend (struct dwc3 *dwc); +int dwc3_runtime_resume (struct dwc3 *dwc); +int dwc3_runtime_idle (struct dwc3 *dwc); +int dwc3_pm_suspend (struct dwc3 *dwc); +int dwc3_pm_resume (struct dwc3 *dwc); +void dwc3_pm_complete (struct dwc3 *dwc); +int dwc3_pm_prepare (struct dwc3 *dwc); + +#endif
Signature · 1 line
2.53.0
PATCH v10 62/63 usb: gadget: re-import epautoconf.c from kernel v6.16
In reply to Anders RoxellFrom: Jerome Forissier <[email protected]>
Replace drivers/usb/gadget/epautoconf.c with the one from the Linux kernel. Fixes will come later.
--- drivers/usb/gadget/epautoconf.c | 292 +++++++++++++++----------------- 1 file changed, 133 insertions(+), 159 deletions(-)
drivers/usb/gadget/epautoconf.c +133 -159
@@ -1,172 +1,123 @@// SPDX-License-Identifier: GPL-2.0+ +/* Imported from Linux v6.16 */ /* * epautoconf.c -- endpoint autoconfiguration for usb gadget drivers * * Copyright (C) 2004 David Brownell -* -* Ported to U-Boot by: Thomas Smits <[email protected]> and -* Remy Bohmer <[email protected]> */ -#include <linux/usb/ch9.h> -#include <linux/errno.h> -#include <linux/usb/gadget.h> -#include <asm/unaligned.h> - -#define isdigit (c) ('0' <= (c) && (c) <= '9') +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/types.h> +#include <linux/device.h> -/* we must assign addresses for configurable endpoints (like net2280) */ -static unsigned epnum; +#include <linux/ctype.h> +#include <linux/string.h> -/* #define MANY_ENDPOINTS */ -#ifdef MANY_ENDPOINTS -/* more than 15 configurable endpoints */ -static unsigned in_epnum; -#endif +#include <linux/usb/ch9.h> +#include <linux/usb/gadget.h> -/* -* This should work with endpoints from controller drivers sharing the -* same endpoint naming convention. By example: +/** +* usb_ep_autoconfig_ss() - choose an endpoint matching the ep +* descriptor and ep companion descriptor +* @gadget: The device to which the endpoint must belong. +* @desc: Endpoint descriptor, with endpoint direction and transfer mode +* initialized. For periodic transfers, the maximum packet +* size must also be initialized. This is modified on +* success. +* @ep_comp: Endpoint companion descriptor, with the required +* number of streams. Will be modified when the chosen EP +* supports a different number of streams. +* +* This routine replaces the usb_ep_autoconfig when needed +* superspeed enhancments. If such enhancemnets are required, +* the FD should call usb_ep_autoconfig_ss directly and provide +* the additional ep_comp parameter. +* +* By choosing an endpoint to use with the specified descriptor, +* this routine simplifies writing gadget drivers that work with +* multiple USB device controllers. The endpoint would be +* passed later to usb_ep_enable(), along with some descriptor. +* +* That second descriptor won't always be the same as the first one. +* For example, isochronous endpoints can be autoconfigured for high +* bandwidth, and then used in several lower bandwidth altsettings. +* Also, high and full speed descriptors will be different. * -* - ep1, ep2, ... address is fixed, not direction or type -* - ep1in, ep2out, ... address and direction are fixed, not type -* - ep1-bulk, ep2-bulk, ... address and type are fixed, not direction -* - ep1in-bulk, ep2out-iso, ... all three are fixed -* - ep-* ... no functionality restrictions +* Be sure to examine and test the results of autoconfiguration +* on your hardware. This code may not make the best choices +* about how to use the USB controller, and it can't know all +* the restrictions that may apply. Some combinations of driver +* and hardware won't be able to autoconfigure. * -* Type suffixes are "-bulk", "-iso", or "-int". Numbers are decimal. -* Less common restrictions are implied by gadget_is_*(). +* On success, this returns an claimed usb_ep, and modifies the endpoint +* descriptor bEndpointAddress. For bulk endpoints, the wMaxPacket value +* is initialized as if the endpoint were used at full speed and +* the bmAttribute field in the ep companion descriptor is +* updated with the assigned number of streams if it is +* different from the original value. To prevent the endpoint +* from being returned by a later autoconfig call, claims it by +* assigning ep->claimed to true. * -* NOTE: each endpoint is unidirectional, as specified by its USB -* descriptor; and isn't specific to a configuration or altsetting. +* On failure, this returns a null endpoint descriptor. */ -static int ep_matches ( +struct usb_ep *usb_ep_autoconfig_ss (struct usb_gadget *gadget, -struct usb_ep *ep, -struct usb_endpoint_descriptor *desc +struct usb_endpoint_descriptor *desc, +struct usb_ss_ep_comp_descriptor *ep_comp ) { -u8 type; -const char *tmp; -u16 max; - -/* endpoint already claimed? */ -if (NULL != ep->driver_data) -return 0 ; - -/* only support ep0 for portable CONTROL traffic */ - type = desc->bmAttributes &USB_ENDPOINT_XFERTYPE_MASK ; -if (USB_ENDPOINT_XFER_CONTROL == type) -return 0 ; - -/* some other naming convention */ -if ('e' != ep->name[0 ]) -return 0 ; +struct usb_ep *ep; -/* type-restriction: "-iso", "-bulk", or "-int". -* direction-restriction: "in", "out". -*/ -if ('-' != ep->name[2 ]) { - tmp =strrchr (ep->name,'-' ); -if (tmp) { -switch (type) { -case USB_ENDPOINT_XFER_INT : -/* bulk endpoints handle interrupt transfers, -* except the toggle-quirky iso-synch kind -*/ -if ('s' == tmp[2 ])/* == "-iso" */ -return 0 ; -break ; -case USB_ENDPOINT_XFER_BULK : -if ('b' != tmp[1 ])/* != "-bulk" */ -return 0 ; -break ; -case USB_ENDPOINT_XFER_ISOC : -if ('s' != tmp[2 ])/* != "-iso" */ -return 0 ; - } - }else { - tmp = ep->name +strlen (ep->name); - } - -/* direction-restriction: "..in-..", "out-.." */ - tmp--; -if (!isdigit (*tmp)) { -if (desc->bEndpointAddress &USB_DIR_IN ) { -if ('n' != *tmp) -return 0 ; - }else { -if ('t' != *tmp) -return 0 ; - } - } +if (gadget->ops->match_ep) { + ep = gadget->ops->match_ep (gadget, desc, ep_comp); +if (ep) + goto found_ep; } -/* endpoint maxpacket size is an input parameter, except for bulk -* where it's an output parameter representing the full speed limit. -* the usb spec fixes high speed bulk maxpacket at 512 bytes. -*/ - max =0x7ff &le16_to_cpu (get_unaligned (&desc->wMaxPacketSize)); -switch (type) { -case USB_ENDPOINT_XFER_INT : -/* INT: limit 64 bytes full speed, 1024 high speed */ -if (!gadget->is_dualspeed && max >64 ) -return 0 ; -/* FALLTHROUGH */ - -case USB_ENDPOINT_XFER_ISOC : -/* ISO: limit 1023 bytes full speed, 1024 high speed */ -if (ep->maxpacket < max) -return 0 ; -if (!gadget->is_dualspeed && max >1023 ) -return 0 ; - -/* BOTH: "high bandwidth" works only at high speed */ -if ((get_unaligned (&desc->wMaxPacketSize) & -__constant_cpu_to_le16 (3 <<11 ))) { -if (!gadget->is_dualspeed) -return 0 ; -/* configure your hardware with enough buffering!! */ - } -break ; +/* Second, look at endpoints until an unclaimed one looks usable */ + list_for_each_entry (ep, &gadget->ep_list, ep_list) { +if (usb_gadget_ep_match_desc (gadget, ep, desc, ep_comp)) + goto found_ep; } -/* MATCH!! */ +/* Fail */ +return NULL ; +found_ep: + +/* +* If the protocol driver hasn't yet decided on wMaxPacketSize +* and wants to know the maximum possible, provide the info. +*/ +if (desc->wMaxPacketSize ==0 ) + desc->wMaxPacketSize =cpu_to_le16 (ep->maxpacket_limit);/* report address */ + desc->bEndpointAddress &=USB_DIR_IN ;if (isdigit (ep->name[2 ])) { -u8 num =dectoul (&ep->name[2 ],NULL ); +u8 num =simple_strtoul (&ep->name[2 ],NULL ,10 ); desc->bEndpointAddress |= num; -#ifdef MANY_ENDPOINTS }else if (desc->bEndpointAddress &USB_DIR_IN ) { -if (++in_epnum >15 ) -return 0 ; - desc->bEndpointAddress =USB_DIR_IN | in_epnum; -#endif +if (++gadget->in_epnum >15 ) +return NULL ; + desc->bEndpointAddress =USB_DIR_IN | gadget->in_epnum; }else { -if (++epnum >15 ) -return 0 ; - desc->bEndpointAddress |= epnum; +if (++gadget->out_epnum >15 ) +return NULL ; + desc->bEndpointAddress |= gadget->out_epnum; } -/* report (variable) full speed bulk maxpacket */ -if (USB_ENDPOINT_XFER_BULK == type) { -int size = ep->maxpacket; - -/* min() doesn't work on bitfields with gcc-3.5 */ -if (size >64 ) - size =64 ; -put_unaligned (cpu_to_le16 (size), &desc->wMaxPacketSize); - } - -if (gadget->ops->ep_conf) -return gadget->ops->ep_conf (gadget, ep, desc); - -return 1 ; + ep->address = desc->bEndpointAddress; + ep->desc =NULL ; + ep->comp_desc =NULL ; + ep->claimed = true; +return ep; } +EXPORT_SYMBOL_GPL (usb_ep_autoconfig_ss);/** -* usb_ep_autoconfig - choose an endpoint matching the descriptor +* usb_ep_autoconfig() - choose an endpoint matching the +* descriptor * @gadget: The device to which the endpoint must belong. * @desc: Endpoint descriptor, with endpoint direction and transfer mode * initialized. For periodic transfers, the maximum packet
@@ -187,11 +138,12 @@ static int ep_matches(* USB controller, and it can't know all the restrictions that may apply. * Some combinations of driver and hardware won't be able to autoconfigure. * -* On success, this returns an un-claimed usb_ep, and modifies the endpoint +* On success, this returns an claimed usb_ep, and modifies the endpoint * descriptor bEndpointAddress. For bulk endpoints, the wMaxPacket value -* is initialized as if the endpoint were used at full speed. To prevent -* the endpoint from being returned by a later autoconfig call, claim it -* by assigning ep->driver_data to some non-null value. +* is initialized as if the endpoint were used at full speed. Because of +* that the users must consider adjusting the autoconfigured descriptor. +* To prevent the endpoint from being returned by a later autoconfig call, +* claims it by assigning ep->claimed to true. * * On failure, this returns a null endpoint descriptor. */
@@ -200,23 +152,45 @@ struct usb_ep *usb_ep_autoconfig(struct usb_endpoint_descriptor *desc ) { -struct usb_ep *ep; +struct usb_ep *ep; +u8 type; -if (gadget->ops->match_ep) { - ep = gadget->ops->match_ep (gadget, desc,NULL ); -if (ep &&ep_matches (gadget, ep, desc)) -return ep; - } + ep =usb_ep_autoconfig_ss (gadget, desc,NULL ); +if (!ep) +return NULL ; -/* Second, look at endpoints until an unclaimed one looks usable */ -list_for_each_entry (ep, &gadget->ep_list, ep_list) { -if (ep_matches (gadget, ep, desc)) -return ep; + type =usb_endpoint_type (desc); + +/* report (variable) full speed bulk maxpacket */ +if (type ==USB_ENDPOINT_XFER_BULK ) { +int size = ep->maxpacket_limit; + +/* min() doesn't work on bitfields with gcc-3.5 */ +if (size >64 ) + size =64 ; + desc->wMaxPacketSize =cpu_to_le16 (size); } -/* Fail */ -return NULL ; +return ep; +} +EXPORT_SYMBOL_GPL (usb_ep_autoconfig); + +/** +* usb_ep_autoconfig_release - releases endpoint and set it to initial state +* @ep: endpoint which should be released +* +* This function can be used during function bind for endpoints obtained +* from usb_ep_autoconfig(). It unclaims endpoint claimed by +* usb_ep_autoconfig() to make it available for other functions. Endpoint +* which was released is no longer valid and shouldn't be used in +* context of function which released it. +*/ +void usb_ep_autoconfig_release (struct usb_ep *ep) +{ + ep->claimed = false; + ep->driver_data =NULL ; } +EXPORT_SYMBOL_GPL (usb_ep_autoconfig_release);/** * usb_ep_autoconfig_reset - reset endpoint autoconfig state
@@ -224,18 +198,18 @@ struct usb_ep *usb_ep_autoconfig(* * Use this for devices where one configuration may need to assign * endpoint resources very differently from the next one. It clears -* state such as ep->driver_data and the record of assigned endpoints +* state such as ep->claimed and the record of assigned endpoints * used by usb_ep_autoconfig(). */ -void usb_ep_autoconfig_reset (struct usb_gadget *gadget) +void usb_ep_autoconfig_reset (struct usb_gadget *gadget) {struct usb_ep *ep; -list_for_each_entry (ep, &gadget->ep_list, ep_list) { + list_for_each_entry (ep, &gadget->ep_list, ep_list) { + ep->claimed = false; ep->driver_data =NULL ; } -#ifdef MANY_ENDPOINTS - in_epnum =0 ; -#endif - epnum =0 ; + gadget->in_epnum =0 ; + gadget->out_epnum =0 ; } +EXPORT_SYMBOL_GPL (usb_ep_autoconfig_reset);
Signature · 1 line
2.53.0
PATCH v10 63/63 usb: udc: re-import udc-core.c from kernel v6.16
In reply to Anders RoxellFrom: Jerome Forissier <[email protected]>
Delete drivers/usb/gadget/udc/udc-core.c which was imported from kernel v3.19-rc1 and replace it with drivers/usb/gadget/udc/core.c from kernel v6.16. Keep the name udc-core.c for now.
--- drivers/usb/gadget/udc/udc-core.c | 1890 ++++++++++++++++++++++++++--- 1 file changed, 1716 insertions(+), 174 deletions(-)
drivers/usb/gadget/udc/udc-core.c +1716 -174
@@ -1,35 +1,52 @@// SPDX-License-Identifier: GPL-2.0 -/** -* udc-core.c - Core UDC Framework -* -* Copyright (C) 2015 Texas Instruments Incorporated - https://www.ti.com +/* Imported from Linux v6.16 */ +/* +* udc.c - Core UDC Framework * +* Copyright (C) 2010 Texas Instruments * Author: Felipe Balbi <[email protected]> -* -* Taken from Linux Kernel v3.19-rc1 (drivers/usb/gadget/udc-core.c) and ported -* to uboot. -* -* commit 02e8c96627 : usb: gadget: udc: core: prepend udc_attach_driver with -* usb_ */ -#include <dm/device_compat.h> -#include <dm/devres.h> -#include <linux/compat.h> -#include <malloc.h> -#include <asm/cache.h> +#define pr_fmt (fmt) "UDC core: " fmt + +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/device.h> +#include <linux/list.h> +#include <linux/idr.h> +#include <linux/err.h> #include <linux/dma-mapping.h> -#include <dm.h> -#include <dm/device-internal.h> +#include <linux/sched/task_stack.h> +#include <linux/workqueue.h> +#include <linux/usb/ch9.h> #include <linux/usb/gadget.h> +#include <linux/usb.h> + +#include "trace.h" + +static DEFINE_IDA (gadget_id_numbers); + +static const struct bus_type gadget_bus_type;/** * struct usb_udc - describes one usb device controller -* @driver - the gadget driver pointer. For use by the class code -* @dev - the child device to the actual controller -* @gadget - the gadget. For use by the class code -* @list - for use by the udc class driver +* @driver: the gadget driver pointer. For use by the class code +* @dev: the child device to the actual controller +* @gadget: the gadget. For use by the class code +* @list: for use by the udc class driver +* @vbus: for udcs who care about vbus status, this value is real vbus status; +* for udcs who do not care about vbus status, this value is always true +* @started: the UDC's started state. True if the UDC had started. +* @allow_connect: Indicates whether UDC is allowed to be pulled up. +* Set/cleared by gadget_(un)bind_driver() after gadget driver is bound or +* unbound. +* @vbus_work: work routine to handle VBUS status change notifications. +* @connect_lock: protects udc->started, gadget->connect, +* gadget->allow_connect and gadget->deactivate. The routines +* usb_gadget_connect_locked(), usb_gadget_disconnect_locked(), +* usb_udc_connect_control_locked(), usb_gadget_udc_start_locked() and +* usb_gadget_udc_stop_locked() are called with this lock held. * * This represents the internal data structure which is used by the UDC-class * to hold information about udc driver and gadget together.
@@ -39,43 +56,935 @@ struct usb_udc {struct usb_gadget *gadget;struct device dev;struct list_head list; +bool vbus; +bool started; +bool allow_connect; +struct work_struct vbus_work; +struct mutex connect_lock; }; -static struct class *udc_class; +static const struct class udc_class;static LIST_HEAD (udc_list); -DEFINE_MUTEX (udc_lock); + +/* Protects udc_list, udc->driver, driver->is_bound, and related calls */ +static DEFINE_MUTEX (udc_lock);/* ------------------------------------------------------------------------- */ -int usb_gadget_map_request (struct usb_gadget *gadget, +/** +* usb_ep_set_maxpacket_limit - set maximum packet size limit for endpoint +* @ep:the endpoint being configured +* @maxpacket_limit:value of maximum packet size limit +* +* This function should be used only in UDC drivers to initialize endpoint +* (usually in probe function). +*/ +void usb_ep_set_maxpacket_limit (struct usb_ep *ep, +unsigned maxpacket_limit) +{ + ep->maxpacket_limit = maxpacket_limit; + ep->maxpacket = maxpacket_limit; + +trace_usb_ep_set_maxpacket_limit (ep,0 ); +} +EXPORT_SYMBOL_GPL (usb_ep_set_maxpacket_limit); + +/** +* usb_ep_enable - configure endpoint, making it usable +* @ep:the endpoint being configured. may not be the endpoint named "ep0". +* drivers discover endpoints through the ep_list of a usb_gadget. +* +* When configurations are set, or when interface settings change, the driver +* will enable or disable the relevant endpoints. while it is enabled, an +* endpoint may be used for i/o until the driver receives a disconnect() from +* the host or until the endpoint is disabled. +* +* the ep0 implementation (which calls this routine) must ensure that the +* hardware capabilities of each endpoint match the descriptor provided +* for it. for example, an endpoint named "ep2in-bulk" would be usable +* for interrupt transfers as well as bulk, but it likely couldn't be used +* for iso transfers or for endpoint 14. some endpoints are fully +* configurable, with more generic names like "ep-a". (remember that for +* USB, "in" means "towards the USB host".) +* +* This routine may be called in an atomic (interrupt) context. +* +* returns zero, or a negative error code. +*/ +int usb_ep_enable (struct usb_ep *ep) +{ +int ret =0 ; + +if (ep->enabled) + goto out; + +/* UDC drivers can't handle endpoints with maxpacket size 0 */ +if (!ep->desc ||usb_endpoint_maxp (ep->desc) ==0 ) { +WARN_ONCE (1 ,"%s: ep%d (%s) has %s\n" , __func__, ep->address, ep->name, + (!ep->desc) ?"NULL descriptor" :"maxpacket 0" ); + + ret = -EINVAL ; + goto out; + } + + ret = ep->ops->enable (ep, ep->desc); +if (ret) + goto out; + + ep->enabled = true; + +out: +trace_usb_ep_enable (ep, ret); + +return ret; +} +EXPORT_SYMBOL_GPL (usb_ep_enable); + +/** +* usb_ep_disable - endpoint is no longer usable +* @ep:the endpoint being unconfigured. may not be the endpoint named "ep0". +* +* no other task may be using this endpoint when this is called. +* any pending and uncompleted requests will complete with status +* indicating disconnect (-ESHUTDOWN) before this call returns. +* gadget drivers must call usb_ep_enable() again before queueing +* requests to the endpoint. +* +* This routine may be called in an atomic (interrupt) context. +* +* returns zero, or a negative error code. +*/ +int usb_ep_disable (struct usb_ep *ep) +{ +int ret =0 ; + +if (!ep->enabled) + goto out; + + ret = ep->ops->disable (ep); +if (ret) + goto out; + + ep->enabled = false; + +out: +trace_usb_ep_disable (ep, ret); + +return ret; +} +EXPORT_SYMBOL_GPL (usb_ep_disable); + +/** +* usb_ep_alloc_request - allocate a request object to use with this endpoint +* @ep:the endpoint to be used with with the request +* @gfp_flags:GFP_* flags to use +* +* Request objects must be allocated with this call, since they normally +* need controller-specific setup and may even need endpoint-specific +* resources such as allocation of DMA descriptors. +* Requests may be submitted with usb_ep_queue(), and receive a single +* completion callback. Free requests with usb_ep_free_request(), when +* they are no longer needed. +* +* Returns the request, or null if one could not be allocated. +*/ +struct usb_request *usb_ep_alloc_request (struct usb_ep *ep, +gfp_t gfp_flags) +{ +struct usb_request *req =NULL ; + + req = ep->ops->alloc_request (ep, gfp_flags); + +trace_usb_ep_alloc_request (ep, req, req ?0 : -ENOMEM ); + +return req; +} +EXPORT_SYMBOL_GPL (usb_ep_alloc_request); + +/** +* usb_ep_free_request - frees a request object +* @ep:the endpoint associated with the request +* @req:the request being freed +* +* Reverses the effect of usb_ep_alloc_request(). +* Caller guarantees the request is not queued, and that it will +* no longer be requeued (or otherwise used). +*/ +void usb_ep_free_request (struct usb_ep *ep, +struct usb_request *req) +{ +trace_usb_ep_free_request (ep, req,0 ); + ep->ops->free_request (ep, req); +} +EXPORT_SYMBOL_GPL (usb_ep_free_request); + +/** +* usb_ep_queue - queues (submits) an I/O request to an endpoint. +* @ep:the endpoint associated with the request +* @req:the request being submitted +* @gfp_flags: GFP_* flags to use in case the lower level driver couldn't +* pre-allocate all necessary memory with the request. +* +* This tells the device controller to perform the specified request through +* that endpoint (reading or writing a buffer). When the request completes, +* including being canceled by usb_ep_dequeue(), the request's completion +* routine is called to return the request to the driver. Any endpoint +* (except control endpoints like ep0) may have more than one transfer +* request queued; they complete in FIFO order. Once a gadget driver +* submits a request, that request may not be examined or modified until it +* is given back to that driver through the completion callback. +* +* Each request is turned into one or more packets. The controller driver +* never merges adjacent requests into the same packet. OUT transfers +* will sometimes use data that's already buffered in the hardware. +* Drivers can rely on the fact that the first byte of the request's buffer +* always corresponds to the first byte of some USB packet, for both +* IN and OUT transfers. +* +* Bulk endpoints can queue any amount of data; the transfer is packetized +* automatically. The last packet will be short if the request doesn't fill it +* out completely. Zero length packets (ZLPs) should be avoided in portable +* protocols since not all usb hardware can successfully handle zero length +* packets. (ZLPs may be explicitly written, and may be implicitly written if +* the request 'zero' flag is set.) Bulk endpoints may also be used +* for interrupt transfers; but the reverse is not true, and some endpoints +* won't support every interrupt transfer. (Such as 768 byte packets.) +* +* Interrupt-only endpoints are less functional than bulk endpoints, for +* example by not supporting queueing or not handling buffers that are +* larger than the endpoint's maxpacket size. They may also treat data +* toggle differently. +* +* Control endpoints ... after getting a setup() callback, the driver queues +* one response (even if it would be zero length). That enables the +* status ack, after transferring data as specified in the response. Setup +* functions may return negative error codes to generate protocol stalls. +* (Note that some USB device controllers disallow protocol stall responses +* in some cases.) When control responses are deferred (the response is +* written after the setup callback returns), then usb_ep_set_halt() may be +* used on ep0 to trigger protocol stalls. Depending on the controller, +* it may not be possible to trigger a status-stage protocol stall when the +* data stage is over, that is, from within the response's completion +* routine. +* +* For periodic endpoints, like interrupt or isochronous ones, the usb host +* arranges to poll once per interval, and the gadget driver usually will +* have queued some data to transfer at that time. +* +* Note that @req's ->complete() callback must never be called from +* within usb_ep_queue() as that can create deadlock situations. +* +* This routine may be called in interrupt context. +* +* Returns zero, or a negative error code. Endpoints that are not enabled +* report errors; errors will also be +* reported when the usb peripheral is disconnected. +* +* If and only if @req is successfully queued (the return value is zero), +* @req->complete() will be called exactly once, when the Gadget core and +* UDC are finished with the request. When the completion function is called, +* control of the request is returned to the device driver which submitted it. +* The completion handler may then immediately free or reuse @req. +*/ +int usb_ep_queue (struct usb_ep *ep, +struct usb_request *req,gfp_t gfp_flags) +{ +int ret =0 ; + +if (!ep->enabled && ep->address) { +pr_debug ("USB gadget: queue request to disabled ep 0x%x (%s)\n" , + ep->address, ep->name); + ret = -ESHUTDOWN ; + goto out; + } + + ret = ep->ops->queue (ep, req, gfp_flags); + +out: +trace_usb_ep_queue (ep, req, ret); + +return ret; +} +EXPORT_SYMBOL_GPL (usb_ep_queue); + +/** +* usb_ep_dequeue - dequeues (cancels, unlinks) an I/O request from an endpoint +* @ep:the endpoint associated with the request +* @req:the request being canceled +* +* If the request is still active on the endpoint, it is dequeued and +* eventually its completion routine is called (with status -ECONNRESET); +* else a negative error code is returned. This routine is asynchronous, +* that is, it may return before the completion routine runs. +* +* Note that some hardware can't clear out write fifos (to unlink the request +* at the head of the queue) except as part of disconnecting from usb. Such +* restrictions prevent drivers from supporting configuration changes, +* even to configuration zero (a "chapter 9" requirement). +* +* This routine may be called in interrupt context. +*/ +int usb_ep_dequeue (struct usb_ep *ep,struct usb_request *req) +{ +int ret; + + ret = ep->ops->dequeue (ep, req); +trace_usb_ep_dequeue (ep, req, ret); + +return ret; +} +EXPORT_SYMBOL_GPL (usb_ep_dequeue); + +/** +* usb_ep_set_halt - sets the endpoint halt feature. +* @ep: the non-isochronous endpoint being stalled +* +* Use this to stall an endpoint, perhaps as an error report. +* Except for control endpoints, +* the endpoint stays halted (will not stream any data) until the host +* clears this feature; drivers may need to empty the endpoint's request +* queue first, to make sure no inappropriate transfers happen. +* +* Note that while an endpoint CLEAR_FEATURE will be invisible to the +* gadget driver, a SET_INTERFACE will not be. To reset endpoints for the +* current altsetting, see usb_ep_clear_halt(). When switching altsettings, +* it's simplest to use usb_ep_enable() or usb_ep_disable() for the endpoints. +* +* This routine may be called in interrupt context. +* +* Returns zero, or a negative error code. On success, this call sets +* underlying hardware state that blocks data transfers. +* Attempts to halt IN endpoints will fail (returning -EAGAIN) if any +* transfer requests are still queued, or if the controller hardware +* (usually a FIFO) still holds bytes that the host hasn't collected. +*/ +int usb_ep_set_halt (struct usb_ep *ep) +{ +int ret; + + ret = ep->ops->set_halt (ep,1 ); +trace_usb_ep_set_halt (ep, ret); + +return ret; +} +EXPORT_SYMBOL_GPL (usb_ep_set_halt); + +/** +* usb_ep_clear_halt - clears endpoint halt, and resets toggle +* @ep:the bulk or interrupt endpoint being reset +* +* Use this when responding to the standard usb "set interface" request, +* for endpoints that aren't reconfigured, after clearing any other state +* in the endpoint's i/o queue. +* +* This routine may be called in interrupt context. +* +* Returns zero, or a negative error code. On success, this call clears +* the underlying hardware state reflecting endpoint halt and data toggle. +* Note that some hardware can't support this request (like pxa2xx_udc), +* and accordingly can't correctly implement interface altsettings. +*/ +int usb_ep_clear_halt (struct usb_ep *ep) +{ +int ret; + + ret = ep->ops->set_halt (ep,0 ); +trace_usb_ep_clear_halt (ep, ret); + +return ret; +} +EXPORT_SYMBOL_GPL (usb_ep_clear_halt); + +/** +* usb_ep_set_wedge - sets the halt feature and ignores clear requests +* @ep: the endpoint being wedged +* +* Use this to stall an endpoint and ignore CLEAR_FEATURE(HALT_ENDPOINT) +* requests. If the gadget driver clears the halt status, it will +* automatically unwedge the endpoint. +* +* This routine may be called in interrupt context. +* +* Returns zero on success, else negative errno. +*/ +int usb_ep_set_wedge (struct usb_ep *ep) +{ +int ret; + +if (ep->ops->set_wedge) + ret = ep->ops->set_wedge (ep); +else + ret = ep->ops->set_halt (ep,1 ); + +trace_usb_ep_set_wedge (ep, ret); + +return ret; +} +EXPORT_SYMBOL_GPL (usb_ep_set_wedge); + +/** +* usb_ep_fifo_status - returns number of bytes in fifo, or error +* @ep: the endpoint whose fifo status is being checked. +* +* FIFO endpoints may have "unclaimed data" in them in certain cases, +* such as after aborted transfers. Hosts may not have collected all +* the IN data written by the gadget driver (and reported by a request +* completion). The gadget driver may not have collected all the data +* written OUT to it by the host. Drivers that need precise handling for +* fault reporting or recovery may need to use this call. +* +* This routine may be called in interrupt context. +* +* This returns the number of such bytes in the fifo, or a negative +* errno if the endpoint doesn't use a FIFO or doesn't support such +* precise handling. +*/ +int usb_ep_fifo_status (struct usb_ep *ep) +{ +int ret; + +if (ep->ops->fifo_status) + ret = ep->ops->fifo_status (ep); +else + ret = -EOPNOTSUPP ; + +trace_usb_ep_fifo_status (ep, ret); + +return ret; +} +EXPORT_SYMBOL_GPL (usb_ep_fifo_status); + +/** +* usb_ep_fifo_flush - flushes contents of a fifo +* @ep: the endpoint whose fifo is being flushed. +* +* This call may be used to flush the "unclaimed data" that may exist in +* an endpoint fifo after abnormal transaction terminations. The call +* must never be used except when endpoint is not being used for any +* protocol translation. +* +* This routine may be called in interrupt context. +*/ +void usb_ep_fifo_flush (struct usb_ep *ep) +{ +if (ep->ops->fifo_flush) + ep->ops->fifo_flush (ep); + +trace_usb_ep_fifo_flush (ep,0 ); +} +EXPORT_SYMBOL_GPL (usb_ep_fifo_flush); + +/* ------------------------------------------------------------------------- */ + +/** +* usb_gadget_frame_number - returns the current frame number +* @gadget: controller that reports the frame number +* +* Returns the usb frame number, normally eleven bits from a SOF packet, +* or negative errno if this device doesn't support this capability. +*/ +int usb_gadget_frame_number (struct usb_gadget *gadget) +{ +int ret; + + ret = gadget->ops->get_frame (gadget); + +trace_usb_gadget_frame_number (gadget, ret); + +return ret; +} +EXPORT_SYMBOL_GPL (usb_gadget_frame_number); + +/** +* usb_gadget_wakeup - tries to wake up the host connected to this gadget +* @gadget: controller used to wake up the host +* +* Returns zero on success, else negative error code if the hardware +* doesn't support such attempts, or its support has not been enabled +* by the usb host. Drivers must return device descriptors that report +* their ability to support this, or hosts won't enable it. +* +* This may also try to use SRP to wake the host and start enumeration, +* even if OTG isn't otherwise in use. OTG devices may also start +* remote wakeup even when hosts don't explicitly enable it. +*/ +int usb_gadget_wakeup (struct usb_gadget *gadget) +{ +int ret =0 ; + +if (!gadget->ops->wakeup) { + ret = -EOPNOTSUPP ; + goto out; + } + + ret = gadget->ops->wakeup (gadget); + +out: +trace_usb_gadget_wakeup (gadget, ret); + +return ret; +} +EXPORT_SYMBOL_GPL (usb_gadget_wakeup); + +/** +* usb_gadget_set_remote_wakeup - configures the device remote wakeup feature. +* @gadget:the device being configured for remote wakeup +* @set:value to be configured. +* +* set to one to enable remote wakeup feature and zero to disable it. +* +* returns zero on success, else negative errno. +*/ +int usb_gadget_set_remote_wakeup (struct usb_gadget *gadget,int set) +{ +int ret =0 ; + +if (!gadget->ops->set_remote_wakeup) { + ret = -EOPNOTSUPP ; + goto out; + } + + ret = gadget->ops->set_remote_wakeup (gadget, set); + +out: +trace_usb_gadget_set_remote_wakeup (gadget, ret); + +return ret; +} +EXPORT_SYMBOL_GPL (usb_gadget_set_remote_wakeup); + +/** +* usb_gadget_set_selfpowered - sets the device selfpowered feature. +* @gadget:the device being declared as self-powered +* +* this affects the device status reported by the hardware driver +* to reflect that it now has a local power supply. +* +* returns zero on success, else negative errno. +*/ +int usb_gadget_set_selfpowered (struct usb_gadget *gadget) +{ +int ret =0 ; + +if (!gadget->ops->set_selfpowered) { + ret = -EOPNOTSUPP ; + goto out; + } + + ret = gadget->ops->set_selfpowered (gadget,1 ); + +out: +trace_usb_gadget_set_selfpowered (gadget, ret); + +return ret; +} +EXPORT_SYMBOL_GPL (usb_gadget_set_selfpowered); + +/** +* usb_gadget_clear_selfpowered - clear the device selfpowered feature. +* @gadget:the device being declared as bus-powered +* +* this affects the device status reported by the hardware driver. +* some hardware may not support bus-powered operation, in which +* case this feature's value can never change. +* +* returns zero on success, else negative errno. +*/ +int usb_gadget_clear_selfpowered (struct usb_gadget *gadget) +{ +int ret =0 ; + +if (!gadget->ops->set_selfpowered) { + ret = -EOPNOTSUPP ; + goto out; + } + + ret = gadget->ops->set_selfpowered (gadget,0 ); + +out: +trace_usb_gadget_clear_selfpowered (gadget, ret); + +return ret; +} +EXPORT_SYMBOL_GPL (usb_gadget_clear_selfpowered); + +/** +* usb_gadget_vbus_connect - Notify controller that VBUS is powered +* @gadget:The device which now has VBUS power. +* Context: can sleep +* +* This call is used by a driver for an external transceiver (or GPIO) +* that detects a VBUS power session starting. Common responses include +* resuming the controller, activating the D+ (or D-) pullup to let the +* host detect that a USB device is attached, and starting to draw power +* (8mA or possibly more, especially after SET_CONFIGURATION). +* +* Returns zero on success, else negative errno. +*/ +int usb_gadget_vbus_connect (struct usb_gadget *gadget) +{ +int ret =0 ; + +if (!gadget->ops->vbus_session) { + ret = -EOPNOTSUPP ; + goto out; + } + + ret = gadget->ops->vbus_session (gadget,1 ); + +out: +trace_usb_gadget_vbus_connect (gadget, ret); + +return ret; +} +EXPORT_SYMBOL_GPL (usb_gadget_vbus_connect); + +/** +* usb_gadget_vbus_draw - constrain controller's VBUS power usage +* @gadget:The device whose VBUS usage is being described +* @mA:How much current to draw, in milliAmperes. This should be twice +* the value listed in the configuration descriptor bMaxPower field. +* +* This call is used by gadget drivers during SET_CONFIGURATION calls, +* reporting how much power the device may consume. For example, this +* could affect how quickly batteries are recharged. +* +* Returns zero on success, else negative errno. +*/ +int usb_gadget_vbus_draw (struct usb_gadget *gadget,unsigned mA) +{ +int ret =0 ; + +if (!gadget->ops->vbus_draw) { + ret = -EOPNOTSUPP ; + goto out; + } + + ret = gadget->ops->vbus_draw (gadget, mA); +if (!ret) + gadget->mA = mA; + +out: +trace_usb_gadget_vbus_draw (gadget, ret); + +return ret; +} +EXPORT_SYMBOL_GPL (usb_gadget_vbus_draw); + +/** +* usb_gadget_vbus_disconnect - notify controller about VBUS session end +* @gadget:the device whose VBUS supply is being described +* Context: can sleep +* +* This call is used by a driver for an external transceiver (or GPIO) +* that detects a VBUS power session ending. Common responses include +* reversing everything done in usb_gadget_vbus_connect(). +* +* Returns zero on success, else negative errno. +*/ +int usb_gadget_vbus_disconnect (struct usb_gadget *gadget) +{ +int ret =0 ; + +if (!gadget->ops->vbus_session) { + ret = -EOPNOTSUPP ; + goto out; + } + + ret = gadget->ops->vbus_session (gadget,0 ); + +out: +trace_usb_gadget_vbus_disconnect (gadget, ret); + +return ret; +} +EXPORT_SYMBOL_GPL (usb_gadget_vbus_disconnect); + +static int usb_gadget_connect_locked (struct usb_gadget *gadget) + __must_hold(&gadget->udc->connect_lock) +{ +int ret =0 ; + +if (!gadget->ops->pullup) { + ret = -EOPNOTSUPP ; + goto out; + } + +if (gadget->deactivated || !gadget->udc->allow_connect || !gadget->udc->started) { +/* +* If the gadget isn't usable (because it is deactivated, +* unbound, or not yet started), we only save the new state. +* The gadget will be connected automatically when it is +* activated/bound/started. +*/ + gadget->connected = true; + goto out; + } + + ret = gadget->ops->pullup (gadget,1 ); +if (!ret) + gadget->connected =1 ; + +out: +trace_usb_gadget_connect (gadget, ret); + +return ret; +} + +/** +* usb_gadget_connect - software-controlled connect to USB host +* @gadget:the peripheral being connected +* +* Enables the D+ (or potentially D-) pullup. The host will start +* enumerating this gadget when the pullup is active and a VBUS session +* is active (the link is powered). +* +* Returns zero on success, else negative errno. +*/ +int usb_gadget_connect (struct usb_gadget *gadget) +{ +int ret; + +mutex_lock (&gadget->udc->connect_lock); + ret =usb_gadget_connect_locked (gadget); +mutex_unlock (&gadget->udc->connect_lock); + +return ret; +} +EXPORT_SYMBOL_GPL (usb_gadget_connect); + +static int usb_gadget_disconnect_locked (struct usb_gadget *gadget) + __must_hold(&gadget->udc->connect_lock) +{ +int ret =0 ; + +if (!gadget->ops->pullup) { + ret = -EOPNOTSUPP ; + goto out; + } + +if (!gadget->connected) + goto out; + +if (gadget->deactivated || !gadget->udc->started) { +/* +* If gadget is deactivated we only save new state. +* Gadget will stay disconnected after activation. +*/ + gadget->connected = false; + goto out; + } + + ret = gadget->ops->pullup (gadget,0 ); +if (!ret) + gadget->connected =0 ; + +mutex_lock (&udc_lock); +if (gadget->udc->driver) + gadget->udc->driver->disconnect (gadget); +mutex_unlock (&udc_lock); + +out: +trace_usb_gadget_disconnect (gadget, ret); + +return ret; +} + +/** +* usb_gadget_disconnect - software-controlled disconnect from USB host +* @gadget:the peripheral being disconnected +* +* Disables the D+ (or potentially D-) pullup, which the host may see +* as a disconnect (when a VBUS session is active). Not all systems +* support software pullup controls. +* +* Following a successful disconnect, invoke the ->disconnect() callback +* for the current gadget driver so that UDC drivers don't need to. +* +* Returns zero on success, else negative errno. +*/ +int usb_gadget_disconnect (struct usb_gadget *gadget) +{ +int ret; + +mutex_lock (&gadget->udc->connect_lock); + ret =usb_gadget_disconnect_locked (gadget); +mutex_unlock (&gadget->udc->connect_lock); + +return ret; +} +EXPORT_SYMBOL_GPL (usb_gadget_disconnect); + +/** +* usb_gadget_deactivate - deactivate function which is not ready to work +* @gadget: the peripheral being deactivated +* +* This routine may be used during the gadget driver bind() call to prevent +* the peripheral from ever being visible to the USB host, unless later +* usb_gadget_activate() is called. For example, user mode components may +* need to be activated before the system can talk to hosts. +* +* This routine may sleep; it must not be called in interrupt context +* (such as from within a gadget driver's disconnect() callback). +* +* Returns zero on success, else negative errno. +*/ +int usb_gadget_deactivate (struct usb_gadget *gadget) +{ +int ret =0 ; + +mutex_lock (&gadget->udc->connect_lock); +if (gadget->deactivated) + goto unlock; + +if (gadget->connected) { + ret =usb_gadget_disconnect_locked (gadget); +if (ret) + goto unlock; + +/* +* If gadget was being connected before deactivation, we want +* to reconnect it in usb_gadget_activate(). +*/ + gadget->connected = true; + } + gadget->deactivated = true; + +unlock: +mutex_unlock (&gadget->udc->connect_lock); +trace_usb_gadget_deactivate (gadget, ret); + +return ret; +} +EXPORT_SYMBOL_GPL (usb_gadget_deactivate); + +/** +* usb_gadget_activate - activate function which is not ready to work +* @gadget: the peripheral being activated +* +* This routine activates gadget which was previously deactivated with +* usb_gadget_deactivate() call. It calls usb_gadget_connect() if needed. +* +* This routine may sleep; it must not be called in interrupt context. +* +* Returns zero on success, else negative errno. +*/ +int usb_gadget_activate (struct usb_gadget *gadget) +{ +int ret =0 ; + +mutex_lock (&gadget->udc->connect_lock); +if (!gadget->deactivated) + goto unlock; + + gadget->deactivated = false; + +/* +* If gadget has been connected before deactivation, or became connected +* while it was being deactivated, we call usb_gadget_connect(). +*/ +if (gadget->connected) + ret =usb_gadget_connect_locked (gadget); + +unlock: +mutex_unlock (&gadget->udc->connect_lock); +trace_usb_gadget_activate (gadget, ret); + +return ret; +} +EXPORT_SYMBOL_GPL (usb_gadget_activate); + +/* ------------------------------------------------------------------------- */ + +#ifdef CONFIG_HAS_DMA + +int usb_gadget_map_request_by_dev (struct device *dev,struct usb_request *req,int is_in) {if (req->length ==0 )return 0 ; - req->dma =dma_map_single (req->buf, req->length, - is_in ?DMA_TO_DEVICE :DMA_FROM_DEVICE ); +if (req->sg_was_mapped) { + req->num_mapped_sgs = req->num_sgs; +return 0 ; + } + +if (req->num_sgs) { +int mapped; + + mapped =dma_map_sg (dev, req->sg, req->num_sgs, + is_in ?DMA_TO_DEVICE :DMA_FROM_DEVICE ); +if (mapped ==0 ) { +dev_err (dev,"failed to map SGs\n" ); +return -EFAULT ; + } + + req->num_mapped_sgs = mapped; + }else { +if (is_vmalloc_addr (req->buf)) { +dev_err (dev,"buffer is not dma capable\n" ); +return -EFAULT ; + }else if (object_is_on_stack (req->buf)) { +dev_err (dev,"buffer is on stack\n" ); +return -EFAULT ; + } + + req->dma =dma_map_single (dev, req->buf, req->length, + is_in ?DMA_TO_DEVICE :DMA_FROM_DEVICE ); + +if (dma_mapping_error (dev, req->dma)) { +dev_err (dev,"failed to map buffer\n" ); +return -EFAULT ; + } + + req->dma_mapped =1 ; + }return 0 ; } +EXPORT_SYMBOL_GPL (usb_gadget_map_request_by_dev); + +int usb_gadget_map_request (struct usb_gadget *gadget, +struct usb_request *req,int is_in) +{ +return usb_gadget_map_request_by_dev (gadget->dev.parent, req, is_in); +}EXPORT_SYMBOL_GPL (usb_gadget_map_request); -void usb_gadget_unmap_request (struct usb_gadget *gadget, +void usb_gadget_unmap_request_by_dev (struct device *dev,struct usb_request *req,int is_in) { -if (req->length ==0 ) +if (req->length ==0 || req->sg_was_mapped)return ; -dma_unmap_single (req->dma, req->length, - is_in ?DMA_TO_DEVICE :DMA_FROM_DEVICE ); +if (req->num_mapped_sgs) { +dma_unmap_sg (dev, req->sg, req->num_sgs, + is_in ?DMA_TO_DEVICE :DMA_FROM_DEVICE ); + + req->num_mapped_sgs =0 ; + }else if (req->dma_mapped) { +dma_unmap_single (dev, req->dma, req->length, + is_in ?DMA_TO_DEVICE :DMA_FROM_DEVICE ); + req->dma_mapped =0 ; + } +} +EXPORT_SYMBOL_GPL (usb_gadget_unmap_request_by_dev); + +void usb_gadget_unmap_request (struct usb_gadget *gadget, +struct usb_request *req,int is_in) +{ +usb_gadget_unmap_request_by_dev (gadget->dev.parent, req, is_in); }EXPORT_SYMBOL_GPL (usb_gadget_unmap_request); +#endif /* CONFIG_HAS_DMA */ +/* ------------------------------------------------------------------------- */ /** * usb_gadget_giveback_request - give the request back to the gadget layer -* Context: in_interrupt() +* @ep: the endpoint to be used with with the request +* @req: the request being given back * * This is called by device controller drivers in order to return the * completed request back to the gadget layer.
@@ -83,21 +992,191 @@ EXPORT_SYMBOL_GPL(usb_gadget_unmap_request);void usb_gadget_giveback_request (struct usb_ep *ep,struct usb_request *req) { +if (likely (req->status ==0 )) +usb_led_activity (USB_LED_EVENT_GADGET ); + +trace_usb_gadget_giveback_request (ep, req,0 ); + req->complete (ep, req); }EXPORT_SYMBOL_GPL (usb_gadget_giveback_request);/* ------------------------------------------------------------------------- */ +/** +* gadget_find_ep_by_name - returns ep whose name is the same as sting passed +* in second parameter or NULL if searched endpoint not found +* @g: controller to check for quirk +* @name: name of searched endpoint +*/ +struct usb_ep *gadget_find_ep_by_name (struct usb_gadget *g,const char *name) +{ +struct usb_ep *ep; + +gadget_for_each_ep (ep, g) { +if (!strcmp (ep->name, name)) +return ep; + } + +return NULL ; +} +EXPORT_SYMBOL_GPL (gadget_find_ep_by_name); + +/* ------------------------------------------------------------------------- */ + +int usb_gadget_ep_match_desc (struct usb_gadget *gadget, +struct usb_ep *ep,struct usb_endpoint_descriptor *desc, +struct usb_ss_ep_comp_descriptor *ep_comp) +{ +u8 type; +u16 max; +int num_req_streams =0 ; + +/* endpoint already claimed? */ +if (ep->claimed) +return 0 ; + + type =usb_endpoint_type (desc); + max =usb_endpoint_maxp (desc); + +if (usb_endpoint_dir_in (desc) && !ep->caps.dir_in) +return 0 ; +if (usb_endpoint_dir_out (desc) && !ep->caps.dir_out) +return 0 ; + +if (max > ep->maxpacket_limit) +return 0 ; + +/* "high bandwidth" works only at high speed */ +if (!gadget_is_dualspeed (gadget) &&usb_endpoint_maxp_mult (desc) >1 ) +return 0 ; + +switch (type) { +case USB_ENDPOINT_XFER_CONTROL : +/* only support ep0 for portable CONTROL traffic */ +return 0 ; +case USB_ENDPOINT_XFER_ISOC : +if (!ep->caps.type_iso) +return 0 ; +/* ISO: limit 1023 bytes full speed, 1024 high/super speed */ +if (!gadget_is_dualspeed (gadget) && max >1023 ) +return 0 ; +break ; +case USB_ENDPOINT_XFER_BULK : +if (!ep->caps.type_bulk) +return 0 ; +if (ep_comp &&gadget_is_superspeed (gadget)) { +/* Get the number of required streams from the +* EP companion descriptor and see if the EP +* matches it +*/ + num_req_streams = ep_comp->bmAttributes &0x1f ; +if (num_req_streams > ep->max_streams) +return 0 ; + } +break ; +case USB_ENDPOINT_XFER_INT : +/* Bulk endpoints handle interrupt transfers, +* except the toggle-quirky iso-synch kind +*/ +if (!ep->caps.type_int && !ep->caps.type_bulk) +return 0 ; +/* INT: limit 64 bytes full speed, 1024 high/super speed */ +if (!gadget_is_dualspeed (gadget) && max >64 ) +return 0 ; +break ; + } + +return 1 ; +} +EXPORT_SYMBOL_GPL (usb_gadget_ep_match_desc); + +/** +* usb_gadget_check_config - checks if the UDC can support the binded +* configuration +* @gadget: controller to check the USB configuration +* +* Ensure that a UDC is able to support the requested resources by a +* configuration, and that there are no resource limitations, such as +* internal memory allocated to all requested endpoints. +* +* Returns zero on success, else a negative errno. +*/ +int usb_gadget_check_config (struct usb_gadget *gadget) +{ +if (gadget->ops->check_config) +return gadget->ops->check_config (gadget); +return 0 ; +} +EXPORT_SYMBOL_GPL (usb_gadget_check_config); + +/* ------------------------------------------------------------------------- */ + +static void usb_gadget_state_work (struct work_struct *work) +{ +struct usb_gadget *gadget =work_to_gadget (work); +struct usb_udc *udc = gadget->udc; + +if (udc) +sysfs_notify (&udc->dev.kobj,NULL ,"state" ); +} +void usb_gadget_set_state (struct usb_gadget *gadget,enum usb_device_state state) { gadget->state = state; +schedule_work (&gadget->work); }EXPORT_SYMBOL_GPL (usb_gadget_set_state);/* ------------------------------------------------------------------------- */ +/* Acquire connect_lock before calling this function. */ +static int usb_udc_connect_control_locked(struct usb_udc *udc) __must_hold(&udc->connect_lock) +{ +if (udc->vbus) +return usb_gadget_connect_locked (udc->gadget); +else +return usb_gadget_disconnect_locked (udc->gadget); +} + +static void vbus_event_work (struct work_struct *work) +{ + struct usb_udc *udc = container_of(work, struct usb_udc, vbus_work); + +mutex_lock (&udc->connect_lock); +usb_udc_connect_control_locked (udc); +mutex_unlock (&udc->connect_lock); +} + +/** +* usb_udc_vbus_handler - updates the udc core vbus status, and try to +* connect or disconnect gadget +* @gadget: The gadget which vbus change occurs +* @status: The vbus status +* +* The udc driver calls it when it wants to connect or disconnect gadget +* according to vbus status. +* +* This function can be invoked from interrupt context by irq handlers of +* the gadget drivers, however, usb_udc_connect_control() has to run in +* non-atomic context due to the following: +* a. Some of the gadget driver implementations expect the ->pullup +* callback to be invoked in non-atomic context. +* b. usb_gadget_disconnect() acquires udc_lock which is a mutex. +* Hence offload invocation of usb_udc_connect_control() to workqueue. +*/ +void usb_udc_vbus_handler (struct usb_gadget *gadget,bool status) +{ +struct usb_udc *udc = gadget->udc; + +if (udc) { + udc->vbus = status; +schedule_work (&udc->vbus_work); + } +} +EXPORT_SYMBOL_GPL (usb_udc_vbus_handler); +/** * usb_gadget_udc_reset - notifies the udc core that bus reset occurs * @gadget: The gadget which bus reset occurs
@@ -107,47 +1186,143 @@ EXPORT_SYMBOL_GPL(usb_gadget_set_state);* reset occurs, it notifies the gadget driver that the bus reset occurs as * well as updates gadget state. */ -void usb_gadget_udc_reset (struct usb_gadget *gadget, -struct usb_gadget_driver *driver) +void usb_gadget_udc_reset (struct usb_gadget *gadget, +struct usb_gadget_driver *driver) +{ + driver->reset (gadget); +usb_gadget_set_state (gadget,USB_STATE_DEFAULT ); +} +EXPORT_SYMBOL_GPL (usb_gadget_udc_reset); + +/** +* usb_gadget_udc_start_locked - tells usb device controller to start up +* @udc: The UDC to be started +* +* This call is issued by the UDC Class driver when it's about +* to register a gadget driver to the device controller, before +* calling gadget driver's bind() method. +* +* It allows the controller to be powered off until strictly +* necessary to have it powered on. +* +* Returns zero on success, else negative errno. +* +* Caller should acquire connect_lock before invoking this function. +*/ +static inline int usb_gadget_udc_start_locked (struct usb_udc *udc) + __must_hold(&udc->connect_lock) +{ +int ret; + +if (udc->started) { +dev_err (&udc->dev,"UDC had already started\n" ); +return -EBUSY ; + } + + ret = udc->gadget->ops->udc_start (udc->gadget, udc->driver); +if (!ret) + udc->started = true; + +return ret; +} + +/** +* usb_gadget_udc_stop_locked - tells usb device controller we don't need it anymore +* @udc: The UDC to be stopped +* +* This call is issued by the UDC Class driver after calling +* gadget driver's unbind() method. +* +* The details are implementation specific, but it can go as +* far as powering off UDC completely and disable its data +* line pullups. +* +* Caller should acquire connect lock before invoking this function. +*/ +static inline void usb_gadget_udc_stop_locked (struct usb_udc *udc) + __must_hold(&udc->connect_lock) +{ +if (!udc->started) { +dev_err (&udc->dev,"UDC had already stopped\n" ); +return ; + } + + udc->gadget->ops->udc_stop (udc->gadget); + udc->started = false; +} + +/** +* usb_gadget_udc_set_speed - tells usb device controller speed supported by +* current driver +* @udc: The device we want to set maximum speed +* @speed: The maximum speed to allowed to run +* +* This call is issued by the UDC Class driver before calling +* usb_gadget_udc_start() in order to make sure that we don't try to +* connect on speeds the gadget driver doesn't support. +*/ +static inline void usb_gadget_udc_set_speed (struct usb_udc *udc, +enum usb_device_speed speed) { - driver->reset (gadget); -usb_gadget_set_state (gadget,USB_STATE_DEFAULT ); +struct usb_gadget *gadget = udc->gadget; +enum usb_device_speed s; + +if (speed ==USB_SPEED_UNKNOWN ) + s = gadget->max_speed; +else + s =min (speed, gadget->max_speed); + +if (s ==USB_SPEED_SUPER_PLUS && gadget->ops->udc_set_ssp_rate) + gadget->ops->udc_set_ssp_rate (gadget, gadget->max_ssp_rate); +else if (gadget->ops->udc_set_speed) + gadget->ops->udc_set_speed (gadget, s); } -EXPORT_SYMBOL_GPL (usb_gadget_udc_reset);/** -* usb_gadget_udc_start - tells usb device controller to start up -* @udc: The UDC to be started -* -* This call is issued by the UDC Class driver when it's about -* to register a gadget driver to the device controller, before -* calling gadget driver's bind() method. +* usb_gadget_enable_async_callbacks - tell usb device controller to enable asynchronous callbacks +* @udc: The UDC which should enable async callbacks * -* It allows the controller to be powered off until strictly -* necessary to have it powered on. +* This routine is used when binding gadget drivers. It undoes the effect +* of usb_gadget_disable_async_callbacks(); the UDC driver should enable IRQs +* (if necessary) and resume issuing callbacks. * -* Returns zero on success, else negative errno. +* This routine will always be called in process context. */ -static inline int usb_gadget_udc_start (struct usb_udc *udc) +static inline void usb_gadget_enable_async_callbacks (struct usb_udc *udc) { -return udc->gadget->ops->udc_start (udc->gadget, udc->driver); +struct usb_gadget *gadget = udc->gadget; + +if (gadget->ops->udc_async_callbacks) + gadget->ops->udc_async_callbacks (gadget, true); }/** -* usb_gadget_udc_stop - tells usb device controller we don't need it anymore -* @gadget: The device we want to stop activity -* @driver: The driver to unbind from @gadget +* usb_gadget_disable_async_callbacks - tell usb device controller to disable asynchronous callbacks +* @udc: The UDC which should disable async callbacks * -* This call is issued by the UDC Class driver after calling -* gadget driver's unbind() method. +* This routine is used when unbinding gadget drivers. It prevents a race: +* The UDC driver doesn't know when the gadget driver's ->unbind callback +* runs, so unless it is told to disable asynchronous callbacks, it might +* issue a callback (such as ->disconnect) after the unbind has completed. * -* The details are implementation specific, but it can go as -* far as powering off UDC completely and disable its data -* line pullups. +* After this function runs, the UDC driver must suppress all ->suspend, +* ->resume, ->disconnect, ->reset, and ->setup callbacks to the gadget driver +* until async callbacks are again enabled. A simple-minded but effective +* way to accomplish this is to tell the UDC hardware not to generate any +* more IRQs. +* +* Request completion callbacks must still be issued. However, it's okay +* to defer them until the request is cancelled, since the pull-up will be +* turned off during the time period when async callbacks are disabled. +* +* This routine will always be called in process context. */ -static inline void usb_gadget_udc_stop (struct usb_udc *udc) +static inline void usb_gadget_disable_async_callbacks (struct usb_udc *udc) { - udc->gadget->ops->udc_stop (udc->gadget); +struct usb_gadget *gadget = udc->gadget; + +if (gadget->ops->udc_async_callbacks) + gadget->ops->udc_async_callbacks (gadget, false); }/**
@@ -162,51 +1337,177 @@ static void usb_udc_release(struct device *dev)struct usb_udc *udc; udc = container_of(dev, struct usb_udc, dev); +dev_dbg (dev,"releasing '%s'\n" ,dev_name (dev));kfree (udc); } +static const struct attribute_group *usb_udc_attr_groups[]; + +static void usb_udc_nop_release (struct device *dev) +{ +dev_vdbg (dev,"%s\n" , __func__); +} +/** -* usb_add_gadget_udc_release - adds a new gadget to the udc class driver list +* usb_initialize_gadget - initialize a gadget and its embedded struct device * @parent: the parent device to this udc. Usually the controller driver's * device. -* @gadget: the gadget to be added to the list. +* @gadget: the gadget to be initialized. * @release: a gadget release function. +*/ +void usb_initialize_gadget (struct device *parent,struct usb_gadget *gadget, +void (*release)(struct device *dev)) +{ +INIT_WORK (&gadget->work, usb_gadget_state_work); + gadget->dev.parent = parent; + +if (release) + gadget->dev.release = release; +else + gadget->dev.release = usb_udc_nop_release; + +device_initialize (&gadget->dev); + gadget->dev.bus = &gadget_bus_type; +} +EXPORT_SYMBOL_GPL (usb_initialize_gadget); + +/** +* usb_add_gadget - adds a new gadget to the udc class driver list +* @gadget: the gadget to be added to the list. * * Returns zero on success, negative errno otherwise. +* Does not do a final usb_put_gadget() if an error occurs. */ -int usb_add_gadget_udc_release (struct device *parent,struct usb_gadget *gadget, -void (*release)(struct device *dev)) +int usb_add_gadget (struct usb_gadget *gadget) {struct usb_udc *udc;int ret = -ENOMEM ; udc =kzalloc (sizeof (*udc),GFP_KERNEL );if (!udc) - goto err1; - -dev_set_name (&gadget->dev,"gadget" ); - gadget->dev.parent = parent; + goto error; +device_initialize (&udc->dev); udc->dev.release = usb_udc_release; - udc->dev.class = udc_class; - udc->dev.parent = parent; + udc->dev.class = &udc_class; + udc->dev.groups = usb_udc_attr_groups; + udc->dev.parent = gadget->dev.parent; + ret =dev_set_name (&udc->dev,"%s" , +kobject_name (&gadget->dev.parent->kobj)); +if (ret) + goto err_put_udc; udc->gadget = gadget; + gadget->udc = udc; +mutex_init (&udc->connect_lock); + + udc->started = false;mutex_lock (&udc_lock);list_add_tail (&udc->list, &udc_list); +mutex_unlock (&udc_lock); +INIT_WORK (&udc->vbus_work, vbus_event_work); + + ret =device_add (&udc->dev); +if (ret) + goto err_unlist_udc;usb_gadget_set_state (gadget,USB_STATE_NOTATTACHED ); + udc->vbus = true; -mutex_unlock (&udc_lock); + ret =ida_alloc (&gadget_id_numbers,GFP_KERNEL ); +if (ret <0 ) + goto err_del_udc; + gadget->id_number = ret; +dev_set_name (&gadget->dev,"gadget.%d" , ret); + + ret =device_add (&gadget->dev); +if (ret) + goto err_free_id; + + ret =sysfs_create_link (&udc->dev.kobj, + &gadget->dev.kobj,"gadget" ); +if (ret) + goto err_del_gadget;return 0 ; -err1: + err_del_gadget: +device_del (&gadget->dev); + + err_free_id: +ida_free (&gadget_id_numbers, gadget->id_number); + + err_del_udc: +flush_work (&gadget->work); +device_del (&udc->dev); + + err_unlist_udc: +mutex_lock (&udc_lock); +list_del (&udc->list); +mutex_unlock (&udc_lock); + + err_put_udc: +put_device (&udc->dev); + + error: +return ret; +} +EXPORT_SYMBOL_GPL (usb_add_gadget); + +/** +* usb_add_gadget_udc_release - adds a new gadget to the udc class driver list +* @parent: the parent device to this udc. Usually the controller driver's +* device. +* @gadget: the gadget to be added to the list. +* @release: a gadget release function. +* +* Returns zero on success, negative errno otherwise. +* Calls the gadget release function in the latter case. +*/ +int usb_add_gadget_udc_release (struct device *parent,struct usb_gadget *gadget, +void (*release)(struct device *dev)) +{ +int ret; + +usb_initialize_gadget (parent, gadget, release); + ret =usb_add_gadget (gadget); +if (ret) +usb_put_gadget (gadget);return ret; }EXPORT_SYMBOL_GPL (usb_add_gadget_udc_release); +/** +* usb_get_gadget_udc_name - get the name of the first UDC controller +* This functions returns the name of the first UDC controller in the system. +* Please note that this interface is usefull only for legacy drivers which +* assume that there is only one UDC controller in the system and they need to +* get its name before initialization. There is no guarantee that the UDC +* of the returned name will be still available, when gadget driver registers +* itself. +* +* Returns pointer to string with UDC controller name on success, NULL +* otherwise. Caller should kfree() returned string. +*/ +char *usb_get_gadget_udc_name (void ) +{ +struct usb_udc *udc; +char *name =NULL ; + +/* For now we take the first available UDC */ +mutex_lock (&udc_lock); +list_for_each_entry (udc, &udc_list, list) { +if (!udc->driver) { + name =kstrdup (udc->gadget->name,GFP_KERNEL ); +break ; + } + } +mutex_unlock (&udc_lock); +return name; +} +EXPORT_SYMBOL_GPL (usb_get_gadget_udc_name); +/** * usb_add_gadget_udc - adds a new gadget to the udc class driver list * @parent: the parent device to this udc. Usually the controller
@@ -221,168 +1522,409 @@ int usb_add_gadget_udc(struct device *parent, struct usb_gadget *gadget) }EXPORT_SYMBOL_GPL (usb_add_gadget_udc); -static void usb_gadget_remove_driver (struct usb_udc *udc) -{ -dev_dbg (&udc->dev,"unregistering UDC driver [%s]\n" , - udc->driver->function); - -usb_gadget_disconnect (udc->gadget); - udc->driver->disconnect (udc->gadget); - udc->driver->unbind (udc->gadget); -usb_gadget_udc_stop (udc); - - udc->driver =NULL ; -} -/** -* usb_del_gadget_udc - deletes @udc from udc_list -* @gadget: the gadget to be removed. +* usb_del_gadget - deletes a gadget and unregisters its udc +* @gadget: the gadget to be deleted. * -* This, will call usb_gadget_unregister_driver() if -* the @udc is still busy. +* This will unbind @gadget, if it is bound. +* It will not do a final usb_put_gadget(). */ -void usb_del_gadget_udc (struct usb_gadget *gadget) +void usb_del_gadget (struct usb_gadget *gadget) { -struct usb_udc *udc =NULL ; - -mutex_lock (&udc_lock); -list_for_each_entry (udc, &udc_list, list) -if (udc->gadget == gadget) - goto found; - -dev_err (gadget->dev.parent,"gadget not registered.\n" ); -mutex_unlock (&udc_lock); +struct usb_udc *udc = gadget->udc; -return ; +if (!udc) +return ; -found:dev_vdbg (gadget->dev.parent,"unregistering gadget\n" ); +mutex_lock (&udc_lock);list_del (&udc->list);mutex_unlock (&udc_lock); -if (udc->driver) -usb_gadget_remove_driver (udc); +kobject_uevent (&udc->dev.kobj,KOBJ_REMOVE ); +sysfs_remove_link (&udc->dev.kobj,"gadget" ); +device_del (&gadget->dev); +flush_work (&gadget->work); +ida_free (&gadget_id_numbers, gadget->id_number); +cancel_work_sync (&udc->vbus_work); +device_unregister (&udc->dev); } -EXPORT_SYMBOL_GPL (usb_del_gadget_udc); - -/* ------------------------------------------------------------------------- */ +EXPORT_SYMBOL_GPL (usb_del_gadget);/** -* usb_gadget_udc_set_speed - tells usb device controller speed supported by -* current driver -* @udc: The device we want to set maximum speed -* @speed: The maximum speed to allowed to run +* usb_del_gadget_udc - unregisters a gadget +* @gadget: the gadget to be unregistered. * -* This call is issued by the UDC Class driver before calling -* usb_gadget_udc_start() in order to make sure that we don't try to -* connect on speeds the gadget driver doesn't support. +* Calls usb_del_gadget() and does a final usb_put_gadget(). */ -static inline void usb_gadget_udc_set_speed (struct usb_udc *udc, -enum usb_device_speed speed) +void usb_del_gadget_udc (struct usb_gadget *gadget) { -if (udc->gadget->ops->udc_set_speed) { -enum usb_device_speed s; - - s =min (speed, udc->gadget->max_speed); - udc->gadget->ops->udc_set_speed (udc->gadget, s); - } +usb_del_gadget (gadget); +usb_put_gadget (gadget); } +EXPORT_SYMBOL_GPL (usb_del_gadget_udc); + +/* ------------------------------------------------------------------------- */ -static int udc_bind_to_driver (struct usb_udc *udc,struct usb_gadget_driver *driver) +static int gadget_match_driver (struct device *dev,const struct device_driver *drv) { -int ret; +struct usb_gadget *gadget =dev_to_usb_gadget (dev); +struct usb_udc *udc = gadget->udc; +const struct usb_gadget_driver *driver =container_of (drv, + struct usb_gadget_driver, driver); -dev_dbg (&udc->dev,"registering UDC driver [%s]\n" , - driver->function); +/* If the driver specifies a udc_name, it must match the UDC's name */ +if (driver->udc_name && +strcmp (driver->udc_name,dev_name (&udc->dev)) !=0 ) +return 0 ; + +/* If the driver is already bound to a gadget, it doesn't match */ +if (driver->is_bound) +return 0 ; + +/* Otherwise any gadget driver matches any UDC */ +return 1 ; +} + +static int gadget_bind_driver (struct device *dev) +{ +struct usb_gadget *gadget =dev_to_usb_gadget (dev); +struct usb_udc *udc = gadget->udc; +struct usb_gadget_driver *driver =container_of (dev->driver, + struct usb_gadget_driver, driver); +int ret =0 ; +mutex_lock (&udc_lock); +if (driver->is_bound) { +mutex_unlock (&udc_lock); +return -ENXIO ;/* Driver binds to only one gadget */ + } + driver->is_bound = true; udc->driver = driver; +mutex_unlock (&udc_lock); -usb_gadget_udc_set_speed (udc, driver->speed); +dev_dbg (&udc->dev,"binding gadget driver [%s]\n" , driver->function); - ret = driver->bind (udc->gadget); +usb_gadget_udc_set_speed (udc, driver->max_speed); + + ret = driver->bind (udc->gadget, driver);if (ret) - goto err1; - ret =usb_gadget_udc_start (udc); + goto err_bind; + +mutex_lock (&udc->connect_lock); + ret =usb_gadget_udc_start_locked (udc);if (ret) { - driver->unbind (udc->gadget); - goto err1; +mutex_unlock (&udc->connect_lock); + goto err_start; } -usb_gadget_connect (udc->gadget); +usb_gadget_enable_async_callbacks (udc); + udc->allow_connect = true; + ret =usb_udc_connect_control_locked (udc); +if (ret) + goto err_connect_control; + +mutex_unlock (&udc->connect_lock); +kobject_uevent (&udc->dev.kobj,KOBJ_CHANGE );return 0 ; -err1: + + err_connect_control: + udc->allow_connect = false; +usb_gadget_disable_async_callbacks (udc); +if (gadget->irq) +synchronize_irq (gadget->irq); +usb_gadget_udc_stop_locked (udc); +mutex_unlock (&udc->connect_lock); + + err_start: + driver->unbind (udc->gadget); + + err_bind:if (ret != -EISNAM )dev_err (&udc->dev,"failed to start %s: %d\n" , - udc->driver->function, ret); + driver->function, ret); + +mutex_lock (&udc_lock); udc->driver =NULL ; + driver->is_bound = false; +mutex_unlock (&udc_lock); +return ret; } -int usb_gadget_probe_driver (struct usb_gadget_driver *driver) +static void gadget_unbind_driver (struct device *dev) { -struct usb_udc *udc =NULL ; -unsigned int udc_count =0 ; -int ret; +struct usb_gadget *gadget =dev_to_usb_gadget (dev); +struct usb_udc *udc = gadget->udc; +struct usb_gadget_driver *driver = udc->driver; -if (!driver || !driver->bind || !driver->setup) -return -EINVAL ; +dev_dbg (&udc->dev,"unbinding gadget driver [%s]\n" , driver->function); + + udc->allow_connect = false; +cancel_work_sync (&udc->vbus_work); +mutex_lock (&udc->connect_lock); +usb_gadget_disconnect_locked (gadget); +usb_gadget_disable_async_callbacks (udc); +if (gadget->irq) +synchronize_irq (gadget->irq); +mutex_unlock (&udc->connect_lock); + + udc->driver->unbind (gadget); + +mutex_lock (&udc->connect_lock); +usb_gadget_udc_stop_locked (udc); +mutex_unlock (&udc->connect_lock);mutex_lock (&udc_lock); -list_for_each_entry (udc, &udc_list, list) { - udc_count++; + driver->is_bound = false; + udc->driver =NULL ; +mutex_unlock (&udc_lock); + +kobject_uevent (&udc->dev.kobj,KOBJ_CHANGE ); +} + +/* ------------------------------------------------------------------------- */ + +int usb_gadget_register_driver_owner (struct usb_gadget_driver *driver, +struct module *owner,const char *mod_name) +{ +int ret; + +if (!driver || !driver->bind || !driver->setup) +return -EINVAL ; -/* For now we take the first one */ -if (!udc->driver) - goto found; + driver->driver.bus = &gadget_bus_type; + driver->driver.owner = owner; + driver->driver.mod_name = mod_name; + driver->driver.probe_type =PROBE_FORCE_SYNCHRONOUS ; + ret =driver_register (&driver->driver); +if (ret) { +pr_warn ("%s: driver registration failed: %d\n" , + driver->function, ret); +return ret; } -if (!udc_count) -printf ("No UDC available in the system\n" ); -else -/* When this happens, users should 'unbind <class> <index>' -* using the output of 'dm tree' and looking at the line right -* after the USB peripheral/device controller. -*/ -printf ("All UDCs in use (%d available), use the unbind command\n" , - udc_count); -mutex_unlock (&udc_lock); -return -ENODEV ; -found: - ret =udc_bind_to_driver (udc, driver); +mutex_lock (&udc_lock); +if (!driver->is_bound) { +if (driver->match_existing_only) { +pr_warn ("%s: couldn't find an available UDC or it's busy\n" , + driver->function); + ret = -EBUSY ; + }else { +pr_info ("%s: couldn't find an available UDC\n" , + driver->function); + ret =0 ; + } + }mutex_unlock (&udc_lock); + +if (ret) +driver_unregister (&driver->driver);return ret; } -EXPORT_SYMBOL_GPL (usb_gadget_probe_driver); +EXPORT_SYMBOL_GPL (usb_gadget_register_driver_owner); + +int usb_gadget_unregister_driver (struct usb_gadget_driver *driver) +{ +if (!driver || !driver->unbind) +return -EINVAL ; + +driver_unregister (&driver->driver); +return 0 ; +} +EXPORT_SYMBOL_GPL (usb_gadget_unregister_driver); + +/* ------------------------------------------------------------------------- */ -int usb_gadget_register_driver (struct usb_gadget_driver *driver) +static ssize_t srp_store (struct device *dev, +struct device_attribute *attr,const char *buf,size_t n) { -return usb_gadget_probe_driver (driver); + struct usb_udc *udc = container_of(dev, struct usb_udc, dev); + +if (sysfs_streq (buf,"1" )) +usb_gadget_wakeup (udc->gadget); + +return n; } -EXPORT_SYMBOL_GPL (usb_gadget_register_driver); +static DEVICE_ATTR_WO (srp); -int usb_gadget_unregister_driver (struct usb_gadget_driver *driver) +static ssize_t soft_connect_store (struct device *dev, +struct device_attribute *attr,const char *buf,size_t n) { -struct usb_udc *udc =NULL ; -int ret = -ENODEV ; + struct usb_udc *udc = container_of(dev, struct usb_udc, dev); +ssize_t ret; -if (!driver || !driver->unbind) -return -EINVAL ; +device_lock (&udc->gadget->dev); +if (!udc->driver) { +dev_err (dev,"soft-connect without a gadget driver\n" ); + ret = -EOPNOTSUPP ; + goto out; + } + +if (sysfs_streq (buf,"connect" )) { +mutex_lock (&udc->connect_lock); +usb_gadget_udc_start_locked (udc); +usb_gadget_connect_locked (udc->gadget); +mutex_unlock (&udc->connect_lock); + }else if (sysfs_streq (buf,"disconnect" )) { +mutex_lock (&udc->connect_lock); +usb_gadget_disconnect_locked (udc->gadget); +usb_gadget_udc_stop_locked (udc); +mutex_unlock (&udc->connect_lock); + }else { +dev_err (dev,"unsupported command '%s'\n" , buf); + ret = -EINVAL ; + goto out; + } + + ret = n; +out: +device_unlock (&udc->gadget->dev); +return ret; +} +static DEVICE_ATTR_WO (soft_connect); + +static ssize_t state_show (struct device *dev,struct device_attribute *attr, +char *buf) +{ + struct usb_udc *udc = container_of(dev, struct usb_udc, dev); +struct usb_gadget *gadget = udc->gadget; + +return sprintf (buf,"%s\n" ,usb_state_string (gadget->state)); +} +static DEVICE_ATTR_RO (state); + +static ssize_t function_show (struct device *dev,struct device_attribute *attr, +char *buf) +{ + struct usb_udc *udc = container_of(dev, struct usb_udc, dev); +struct usb_gadget_driver *drv; +int rc =0 ;mutex_lock (&udc_lock); -list_for_each_entry (udc, &udc_list, list) -if (udc->driver == driver) { -usb_gadget_remove_driver (udc); -usb_gadget_set_state (udc->gadget, -USB_STATE_NOTATTACHED ); - ret =0 ; -break ; - } + drv = udc->driver; +if (drv && drv->function) + rc =scnprintf (buf,PAGE_SIZE ,"%s\n" , drv->function); +mutex_unlock (&udc_lock); +return rc; +} +static DEVICE_ATTR_RO (function); + +#define USB_UDC_SPEED_ATTR (name, param) \ +ssize_t name##_show(struct device *dev, \ + struct device_attribute *attr, char *buf) \ +{ \ + struct usb_udc *udc = container_of(dev, struct usb_udc, dev); \ + return scnprintf(buf, PAGE_SIZE, "%s\n", \ + usb_speed_string(udc->gadget->param)); \ +} \ +static DEVICE_ATTR_RO(name) + +static USB_UDC_SPEED_ATTR(current_speed, speed); +static USB_UDC_SPEED_ATTR(maximum_speed, max_speed); + +#define USB_UDC_ATTR (name) \ +ssize_t name##_show(struct device *dev, \ + struct device_attribute *attr, char *buf) \ +{ \ + struct usb_udc *udc = container_of(dev, struct usb_udc, dev); \ + struct usb_gadget *gadget = udc->gadget; \ + \ + return scnprintf(buf, PAGE_SIZE, "%d\n", gadget->name); \ +} \ +static DEVICE_ATTR_RO(name) + +static USB_UDC_ATTR (is_otg); +static USB_UDC_ATTR (is_a_peripheral); +static USB_UDC_ATTR (b_hnp_enable); +static USB_UDC_ATTR (a_hnp_support); +static USB_UDC_ATTR (a_alt_hnp_support); +static USB_UDC_ATTR (is_selfpowered); + +static struct attribute *usb_udc_attrs[] = { + &dev_attr_srp.attr, + &dev_attr_soft_connect.attr, + &dev_attr_state.attr, + &dev_attr_function.attr, + &dev_attr_current_speed.attr, + &dev_attr_maximum_speed.attr, + &dev_attr_is_otg.attr, + &dev_attr_is_a_peripheral.attr, + &dev_attr_b_hnp_enable.attr, + &dev_attr_a_hnp_support.attr, + &dev_attr_a_alt_hnp_support.attr, + &dev_attr_is_selfpowered.attr, +NULL , +}; + +static const struct attribute_group usb_udc_attr_group = { + .attrs = usb_udc_attrs, +}; + +static const struct attribute_group *usb_udc_attr_groups[] = { + &usb_udc_attr_group, +NULL , +}; + +static int usb_udc_uevent (const struct device *dev,struct kobj_uevent_env *env) +{ + const struct usb_udc *udc = container_of(dev, struct usb_udc, dev); +int ret; + + ret =add_uevent_var (env,"USB_UDC_NAME=%s" , udc->gadget->name); +if (ret) { +dev_err (dev,"failed to add uevent USB_UDC_NAME\n" ); +return ret; + } + +mutex_lock (&udc_lock); +if (udc->driver) + ret =add_uevent_var (env,"USB_UDC_DRIVER=%s" , + udc->driver->function);mutex_unlock (&udc_lock); -return ret; +if (ret) { +dev_err (dev,"failed to add uevent USB_UDC_DRIVER\n" ); +return ret; + } + +return 0 ; } -EXPORT_SYMBOL_GPL (usb_gadget_unregister_driver); + +static const struct class udc_class = { + .name ="udc" , + .dev_uevent = usb_udc_uevent, +}; + +static const struct bus_type gadget_bus_type = { + .name ="gadget" , + .probe = gadget_bind_driver, + .remove = gadget_unbind_driver, + .match = gadget_match_driver, +}; + +static int __init usb_udc_init (void ) +{ +int rc; + + rc =class_register (&udc_class); +if (rc) +return rc; + + rc =bus_register (&gadget_bus_type); +if (rc) +class_unregister (&udc_class); +return rc; +} +subsys_initcall (usb_udc_init); + +static void __exit usb_udc_exit(void) +{ +bus_unregister (&gadget_bus_type); +class_unregister (&udc_class); +} +module_exit (usb_udc_exit);MODULE_DESCRIPTION ("UDC Framework" );MODULE_AUTHOR ("Felipe Balbi <[email protected]>" );
Signature · 1 line
2.53.0
Hi,
Quoted 140 lines · Anders Roxell
Hi,
This is part one of two. It resets the DWC3 driver and imports it up to Linux v6.16. Part two [2] follows right after this one and makes the tree build and work again.
Part one on its own breaks the build for every board that enables DWC3, and USB gadget stops working. That is expected. The two parts have to go in together.
Part two lists the boards that were tested on hardware, with both parts applied.
The driver was forked from the kernel v3.19-rc1 eleven years ago, in commit
85d5e7075f33("usb: dwc3: add dwc3 folder from linux kernel to u-boot"). After that almost no kernel changes came back to U-Boot.Part one is three steps:
1. Re-import
xhci-ext-caps.hfrom v6.16. Marek asked for this one to come first, since the dwc3 imports build on it.2. Restore
drivers/usb/dwc3to the v3.19-rc1 import. U-Boot only files likedwc3-generic.candsamsung_usb_phy.cstay.3. Import the dwc3 directory once per major kernel version, from v3.19 up to v6.16. Each commit is a raw snapshot from that kernel. The last two patches re-import
epautoconf.candudc-core.cthe same way.The import commits are raw kernel snapshots. This is on purpose. It makes it easy to see what comes from which kernel version, and to compare each import with the matching kernel release. The commit messages say this too.
The branch has both parts [1].
[1] https://github.com/roxell/u-boot/tree/usb_dwc3_sync_v10
[2] part two, subject: [PATCH v10 00/30] usb: dwc3: part 2, make the
resynced code work
[3] v7 part one: https://lore.kernel.org/u-boot/[email protected]/
[4] Marek on v9 part two: https://lore.kernel.org/u-boot/[email protected]/v7 -> v10:
- Skipped v8 and v9, so both parts have the same version.
- Rebased on8649a54d301a, since v7 did not apply anymore. The restore commit conflicted ondwc3-am62.cafter commit83abf9120071("usb:
dwc3-am62: checkdev_remap_addr_index()for NULL"). It still deletes the file, and part two brings the fix back.
- The restore commit keepssamsung_usb_phy.cnow, instead of a patch in part two that brought it back. It is U-Boot code and was never part of the kernel import. Marek asked for this [4]. I kept Mattijs' Reviewed-by, since the commit only deletes one file less.
- The other 62 patches are unchanged.Older changes are listed in v7 [3].
Cheers,
AndersJens Wiklander (60):
usb: dwc3: restore to original v3.19-rc1 kernel import
usb: dwc3: import from kernel v3.19
usb: dwc3: import from kernel v4.0
usb: dwc3: import from kernel v4.1
usb: dwc3: import from kernel v4.2
usb: dwc3: import from kernel v4.3
usb: dwc3: import from kernel v4.4
usb: dwc3: import from kernel v4.5
usb: dwc3: import from kernel v4.6
usb: dwc3: import from kernel v4.7
usb: dwc3: import from kernel v4.8
usb: dwc3: import from kernel v4.9
usb: dwc3: import from kernel v4.10
usb: dwc3: import from kernel v4.11
usb: dwc3: import from kernel v4.12
usb: dwc3: import from kernel v4.13
usb: dwc3: import from kernel v4.14
usb: dwc3: import from kernel v4.15
usb: dwc3: import from kernel v4.16
usb: dwc3: import from kernel v4.17
usb: dwc3: import from kernel v4.18
usb: dwc3: import from kernel v4.19
usb: dwc3: import from kernel v4.20
usb: dwc3: import from kernel v5.0
usb: dwc3: import from kernel v5.1
usb: dwc3: import from kernel v5.2
usb: dwc3: import from kernel v5.3
usb: dwc3: import from kernel v5.4
usb: dwc3: import from kernel v5.5
usb: dwc3: import from kernel v5.6
usb: dwc3: import from kernel v5.7
usb: dwc3: import from kernel v5.8
usb: dwc3: import from kernel v5.9
usb: dwc3: import from kernel v5.10
usb: dwc3: import from kernel v5.11
usb: dwc3: import from kernel v5.12
usb: dwc3: import from kernel v5.13
usb: dwc3: import from kernel v5.14
usb: dwc3: import from kernel v5.15
usb: dwc3: import from kernel v5.16
usb: dwc3: import from kernel v5.17
usb: dwc3: import from kernel v5.18
usb: dwc3: import from kernel v5.19
usb: dwc3: import from kernel v6.0
usb: dwc3: import from kernel v6.1
usb: dwc3: import from kernel v6.2
usb: dwc3: import from kernel v6.3
usb: dwc3: import from kernel v6.4
usb: dwc3: import from kernel v6.5
usb: dwc3: import from kernel v6.6
usb: dwc3: import from kernel v6.7
usb: dwc3: import from kernel v6.8
usb: dwc3: import from kernel v6.9
usb: dwc3: import from kernel v6.10
usb: dwc3: import from kernel v6.11
usb: dwc3: import from kernel v6.12
usb: dwc3: import from kernel v6.13
usb: dwc3: import from kernel v6.14
usb: dwc3: import from kernel v6.15
usb: dwc3: import from kernel v6.16Jerome Forissier (3):
usb: host: re-importxhci-ext-caps.hfrom kernel v6.16
usb: gadget: re-importepautoconf.cfrom kernel v6.16
usb: udc: re-importudc-core.cfrom kernel v6.16drivers/usb/dwc3/core.c | 2961 +++++++++++++----- drivers/usb/dwc3/core.h | 1087 +++++-- drivers/usb/dwc3/debug.h | 432 +++ drivers/usb/dwc3/dwc3-am62.c | 424 ++- drivers/usb/dwc3/ep0.c | 763 +++-- drivers/usb/dwc3/gadget.c | 4776 +++++++++++++++++++++-------- drivers/usb/dwc3/gadget.h | 114 +- drivers/usb/dwc3/glue.h | 36 + drivers/usb/dwc3/io.h | 51 +- drivers/usb/dwc3/linux-compat.h | 16 - drivers/usb/gadget/epautoconf.c | 292 +- drivers/usb/gadget/udc/udc-core.c | 1890 ++++++++++-- drivers/usb/host/xhci-ext-caps.h | 158 + 13 files changed, 9864 insertions(+), 3136 deletions(-)
Quoted 5 lines
create mode 100644
drivers/usb/dwc3/debug.hcreate mode 100644drivers/usb/dwc3/glue.hdelete mode 100644drivers/usb/dwc3/linux-compat.hcreate mode 100644drivers/usb/host/xhci-ext-caps.h
Tested on AMD/Xilinx ZynqMP, Versal, Versal-Net, and Versal Gen 2 boards. No issues observed.
Regards,
Love Kumar