Make the resynced core build with the U-Boot APIs. Most of it is renames, like struct udevice and generic_phy_*().
The old U-Boot functions need three changes. dwc3_init() counts the ports and inits the locks, like dwc3_core_probe() in Linux. dwc3_uboot_init() uses do_fifo_resize, the new name for needs_fifo_resize. dwc3_remove() no longer frees dwc->mem, since it is always NULL there. phy_set_mode_ext() is a static stub. The old core.c did not set the PHY mode either. Co-developed-by: Jerome Forissier <[email protected]> Signed-off-by: Jerome Forissier <[email protected]> Co-developed-by: Jens Wiklander <[email protected]> Signed-off-by: Jens Wiklander <[email protected]> Signed-off-by: Anders Roxell <[email protected]> --- drivers/usb/dwc3/core.c | 126 ++++++++++++++++++++++------------------ drivers/usb/dwc3/core.h | 27 +++------ 2 files changed, 76 insertions(+), 77 deletions(-) diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index 8db1dd2c29a1..e15c8254b016 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -8,41 +8,38 @@ * Sebastian Andrzej Siewior <[email protected]> */ -#include <linux/clk.h> -#include <linux/version.h> -#include <linux/module.h> -#include <linux/kernel.h> -#include <linux/slab.h> -#include <linux/spinlock.h> -#include <linux/platform_device.h> -#include <linux/pm_runtime.h> -#include <linux/interrupt.h> -#include <linux/ioport.h> -#include <linux/io.h> -#include <linux/list.h> +#include <clk.h> +#include <cpu_func.h> +#include <malloc.h> +#include <dwc3-uboot.h> +#include <dm/device_compat.h> +#include <dm/devres.h> +#include <linux/bug.h> #include <linux/delay.h> #include <linux/dma-mapping.h> -#include <linux/of.h> -#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> - +#include <linux/err.h> +#include <linux/iopoll.h> +#include <linux/ioport.h> +#include <dm.h> +#include <generic-phy.h> +#include <reset.h> #include <linux/usb/ch9.h> #include <linux/usb/gadget.h> -#include <linux/usb/of.h> -#include <linux/usb/otg.h> +#include <linux/bitfield.h> +#include <linux/math64.h> +#include <linux/time.h> + +#include <version.h> #include "core.h" #include "gadget.h" #include "glue.h" #include "io.h" -#include "debug.h" #include "../host/xhci-ext-caps.h" +#define msleep(a) udelay(a * 1000) + #define DWC3_DEFAULT_AUTOSUSPEND_DELAY 5000 /* ms */ static LIST_HEAD(dwc3_list); @@ -274,7 +271,7 @@ static void dwc3_ref_clk_period(struct dwc3 *dwc) static void dwc3_free_one_event_buffer(struct dwc3 *dwc, struct dwc3_event_buffer *evt) { - dma_free_coherent(dwc->sysdev, evt->length, evt->buf, evt->dma); + dma_free_coherent(evt->buf); } /** @@ -290,18 +287,19 @@ static struct dwc3_event_buffer *dwc3_alloc_one_event_buffer(struct dwc3 *dwc, { struct dwc3_event_buffer *evt; - evt = devm_kzalloc(dwc->dev, sizeof(*evt), GFP_KERNEL); + evt = devm_kzalloc((struct udevice *)dwc->dev, sizeof(*evt), GFP_KERNEL); if (!evt) return ERR_PTR(-ENOMEM); evt->dwc = dwc; evt->length = length; - evt->cache = devm_kzalloc(dwc->dev, length, GFP_KERNEL); + evt->cache = devm_kzalloc((struct udevice *)dwc->dev, length, + GFP_KERNEL); if (!evt->cache) return ERR_PTR(-ENOMEM); - evt->buf = dma_alloc_coherent(dwc->sysdev, length, - &evt->dma, GFP_KERNEL); + evt->buf = dma_alloc_coherent(length, + (unsigned long *)&evt->dma); if (!evt->buf) return ERR_PTR(-ENOMEM); @@ -617,13 +615,13 @@ static int dwc3_phy_init(struct dwc3 *dwc) usb_phy_init(dwc->usb3_phy); for (i = 0; i < dwc->num_usb2_ports; i++) { - ret = phy_init(dwc->usb2_generic_phy[i]); + ret = generic_phy_init(dwc->usb2_generic_phy[i]); 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]); + ret = generic_phy_init(dwc->usb3_generic_phy[j]); if (ret < 0) goto err_exit_usb3_phy; } @@ -651,11 +649,11 @@ static int dwc3_phy_init(struct dwc3 *dwc) err_exit_usb3_phy: while (--j >= 0) - phy_exit(dwc->usb3_generic_phy[j]); + generic_phy_exit(dwc->usb3_generic_phy[j]); err_exit_usb2_phy: while (--i >= 0) - phy_exit(dwc->usb2_generic_phy[i]); + generic_phy_exit(dwc->usb2_generic_phy[i]); usb_phy_shutdown(dwc->usb3_phy); usb_phy_shutdown(dwc->usb2_phy); @@ -668,10 +666,10 @@ static void dwc3_phy_exit(struct dwc3 *dwc) int i; for (i = 0; i < dwc->num_usb3_ports; i++) - phy_exit(dwc->usb3_generic_phy[i]); + generic_phy_exit(dwc->usb3_generic_phy[i]); for (i = 0; i < dwc->num_usb2_ports; i++) - phy_exit(dwc->usb2_generic_phy[i]); + generic_phy_exit(dwc->usb2_generic_phy[i]); usb_phy_shutdown(dwc->usb3_phy); usb_phy_shutdown(dwc->usb2_phy); @@ -687,13 +685,13 @@ static int dwc3_phy_power_on(struct dwc3 *dwc) usb_phy_set_suspend(dwc->usb3_phy, 0); for (i = 0; i < dwc->num_usb2_ports; i++) { - ret = phy_power_on(dwc->usb2_generic_phy[i]); + ret = generic_phy_power_on(dwc->usb2_generic_phy[i]); 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]); + ret = generic_phy_power_on(dwc->usb3_generic_phy[j]); if (ret < 0) goto err_power_off_usb3_phy; } @@ -702,11 +700,11 @@ static int dwc3_phy_power_on(struct dwc3 *dwc) err_power_off_usb3_phy: while (--j >= 0) - phy_power_off(dwc->usb3_generic_phy[j]); + generic_phy_power_off(dwc->usb3_generic_phy[j]); err_power_off_usb2_phy: while (--i >= 0) - phy_power_off(dwc->usb2_generic_phy[i]); + generic_phy_power_off(dwc->usb2_generic_phy[i]); usb_phy_set_suspend(dwc->usb3_phy, 1); usb_phy_set_suspend(dwc->usb2_phy, 1); @@ -719,10 +717,10 @@ static void dwc3_phy_power_off(struct dwc3 *dwc) int i; for (i = 0; i < dwc->num_usb3_ports; i++) - phy_power_off(dwc->usb3_generic_phy[i]); + generic_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]); + generic_phy_power_off(dwc->usb2_generic_phy[i]); usb_phy_set_suspend(dwc->usb3_phy, 1); usb_phy_set_suspend(dwc->usb2_phy, 1); @@ -838,7 +836,7 @@ static int dwc3_core_ulpi_init(struct dwc3 *dwc); /* set global incr burst type configuration registers */ static void dwc3_set_incr_burst_type(struct dwc3 *dwc) { - struct device *dev = dwc->dev; + struct udevice *dev = dwc->dev; /* incrx_mode : for INCR burst type. */ bool incrx_mode; /* incrx_size : for size of INCRX burst. */ @@ -1079,9 +1077,9 @@ static int dwc3_core_init(struct dwc3 *dwc) /* * Write Linux Version Code to our GUID register so it's easy to figure - * out which kernel version a bug was found. + * out which U-Boot version a bug was found. */ - dwc3_writel(dwc->regs, DWC3_GUID, LINUX_VERSION_CODE); + dwc3_writel(dwc->regs, DWC3_GUID, U_BOOT_VERSION_NUM); ret = dwc3_phy_setup(dwc); if (ret) @@ -1099,13 +1097,6 @@ static int dwc3_core_init(struct dwc3 *dwc) dwc->ulpi_ready = true; } - if (!dwc->phys_ready) { - ret = dwc3_core_get_phy(dwc); - if (ret) - goto err_exit_ulpi; - dwc->phys_ready = true; - } - ret = dwc3_phy_init(dwc); if (ret) goto err_exit_ulpi; @@ -1270,9 +1261,17 @@ err_exit_ulpi: return ret; } +static int phy_set_mode_ext(struct phy *phy, enum phy_mode mode, int submode) +{ + /* TODO */ + return -ENOSYS; +} +#define phy_set_mode(phy, mode) \ + phy_set_mode_ext(phy, mode, 0) + static int dwc3_core_init_mode(struct dwc3 *dwc) { - struct device *dev = dwc->dev; + struct udevice *dev = dwc->dev; int ret; int i; @@ -1280,8 +1279,6 @@ static int dwc3_core_init_mode(struct dwc3 *dwc) case USB_DR_MODE_PERIPHERAL: dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_DEVICE, false); - if (dwc->usb2_phy) - otg_set_vbus(dwc->usb2_phy->otg, false); phy_set_mode(dwc->usb2_generic_phy[0], PHY_MODE_USB_DEVICE); phy_set_mode(dwc->usb3_generic_phy[0], PHY_MODE_USB_DEVICE); @@ -1292,8 +1289,6 @@ static int dwc3_core_init_mode(struct dwc3 *dwc) case USB_DR_MODE_HOST: dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_HOST, false); - if (dwc->usb2_phy) - otg_set_vbus(dwc->usb2_phy->otg, true); 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++) @@ -1535,11 +1530,29 @@ void dwc3_of_parse(struct dwc3 *dwc) int dwc3_init(struct dwc3 *dwc) { + unsigned int hw_mode; int ret; u32 reg; dwc3_cache_hwparams(dwc); + /* + * 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) + return ret; + } else { + dwc->num_usb2_ports = 1; + dwc->num_usb3_ports = 1; + } + + spin_lock_init(&dwc->lock); + mutex_init(&dwc->mutex); + ret = dwc3_alloc_event_buffers(dwc, DWC3_EVENT_BUFFERS_SIZE); if (ret) { dev_err(dwc->dev, "failed to allocate event buffers\n"); @@ -1608,7 +1621,6 @@ void dwc3_remove(struct dwc3 *dwc) dwc3_free_event_buffers(dwc); dwc3_core_stop(dwc); dwc3_core_exit(dwc); - kfree(dwc->mem); } #endif @@ -1666,7 +1678,7 @@ int dwc3_uboot_init(struct dwc3_device *dwc3_dev) if (dwc3_dev->hird_threshold) hird_threshold = dwc3_dev->hird_threshold; - dwc->needs_fifo_resize = dwc3_dev->tx_fifo_resize; + dwc->do_fifo_resize = dwc3_dev->tx_fifo_resize; dwc->dr_mode = dwc3_dev->dr_mode; dwc->disable_scramble_quirk = dwc3_dev->disable_scramble_quirk; diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index 4c4d7bae2e5f..a9473e9d34b9 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -11,27 +11,13 @@ #ifndef __DRIVERS_USB_DWC3_CORE_H #define __DRIVERS_USB_DWC3_CORE_H -#include <linux/device.h> -#include <linux/spinlock.h> -#include <linux/mutex.h> #include <linux/ioport.h> -#include <linux/list.h> #include <linux/bitops.h> -#include <linux/dma-mapping.h> -#include <linux/mm.h> -#include <linux/debugfs.h> -#include <linux/wait.h> -#include <linux/workqueue.h> #include <linux/usb/ch9.h> #include <linux/usb/gadget.h> #include <linux/usb/otg.h> -#include <linux/usb/role.h> -#include <linux/ulpi/interface.h> - -#include <linux/phy/phy.h> - -#include <linux/power_supply.h> +#include <linux/usb/phy.h> /* * DWC3 Multiport controllers support up to 15 High-Speed PHYs @@ -745,7 +731,6 @@ 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; @@ -1178,7 +1163,6 @@ struct dwc3 { dma_addr_t ep0_trb_addr; dma_addr_t bounce_addr; struct dwc3_request ep0_usb_req; - struct completion ep0_in_setup; /* device lock */ spinlock_t lock; @@ -1186,8 +1170,11 @@ struct dwc3 { /* mode switching lock */ struct mutex mutex; +#if defined(__UBOOT__) && CONFIG_IS_ENABLED(DM_USB) + struct udevice *dev; +#else struct device *dev; - struct device *sysdev; +#endif struct platform_device *xhci; struct resource xhci_resources[DWC3_XHCI_RESOURCES_NUM]; @@ -1195,7 +1182,7 @@ struct dwc3 { struct dwc3_event_buffer *ev_buf; struct dwc3_ep *eps[DWC3_ENDPOINTS_NUM]; - struct usb_gadget *gadget; + struct usb_gadget gadget; struct usb_gadget_driver *gadget_driver; struct clk *bus_clk; @@ -1204,7 +1191,7 @@ struct dwc3 { struct clk *utmi_clk; struct clk *pipe_clk; - struct reset_control *reset; + struct reset_ctl *reset; struct usb_phy *usb2_phy; struct usb_phy *usb3_phy; -- 2.53.0
