2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2011-10-27 08:36:46 +00:00
|
|
|
/*
|
2015-12-04 01:34:46 +00:00
|
|
|
* drivers/usb/gadget/dwc2_udc_otg.c
|
2015-12-04 01:55:37 +00:00
|
|
|
* Designware DWC2 on-chip full/high speed USB OTG 2.0 device controllers
|
2011-10-27 08:36:46 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2008 for Samsung Electronics
|
|
|
|
*
|
|
|
|
* BSP Support for Samsung's UDC driver
|
|
|
|
* available at:
|
|
|
|
* git://git.kernel.org/pub/scm/linux/kernel/git/kki_ap/linux-2.6-samsung.git
|
|
|
|
*
|
|
|
|
* State machine bugfixes:
|
|
|
|
* Marek Szyprowski <m.szyprowski@samsung.com>
|
|
|
|
*
|
|
|
|
* Ported to u-boot:
|
|
|
|
* Marek Szyprowski <m.szyprowski@samsung.com>
|
|
|
|
* Lukasz Majewski <l.majewski@samsumg.com>
|
|
|
|
*/
|
2012-05-02 11:11:38 +00:00
|
|
|
#undef DEBUG
|
2011-10-27 08:36:46 +00:00
|
|
|
#include <common.h>
|
2019-03-29 14:42:15 +00:00
|
|
|
#include <clk.h>
|
|
|
|
#include <dm.h>
|
|
|
|
#include <generic-phy.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2019-03-29 14:42:15 +00:00
|
|
|
#include <malloc.h>
|
|
|
|
#include <reset.h>
|
2020-02-03 14:36:16 +00:00
|
|
|
#include <dm/device_compat.h>
|
2020-02-03 14:36:15 +00:00
|
|
|
#include <dm/devres.h>
|
2020-05-10 17:40:08 +00:00
|
|
|
#include <linux/bug.h>
|
2020-05-10 17:40:11 +00:00
|
|
|
#include <linux/delay.h>
|
2019-03-29 14:42:15 +00:00
|
|
|
|
2016-09-21 02:28:55 +00:00
|
|
|
#include <linux/errno.h>
|
2011-10-27 08:36:46 +00:00
|
|
|
#include <linux/list.h>
|
|
|
|
|
|
|
|
#include <linux/usb/ch9.h>
|
2019-03-29 14:42:15 +00:00
|
|
|
#include <linux/usb/otg.h>
|
2011-10-27 08:36:46 +00:00
|
|
|
#include <linux/usb/gadget.h>
|
|
|
|
|
2019-12-02 11:11:17 +00:00
|
|
|
#include <phys2bus.h>
|
2011-10-27 08:36:46 +00:00
|
|
|
#include <asm/byteorder.h>
|
2011-12-15 15:40:51 +00:00
|
|
|
#include <asm/unaligned.h>
|
2011-10-27 08:36:46 +00:00
|
|
|
#include <asm/io.h>
|
|
|
|
|
|
|
|
#include <asm/mach-types.h>
|
|
|
|
|
2019-03-29 14:42:15 +00:00
|
|
|
#include <power/regulator.h>
|
|
|
|
|
2015-12-04 01:32:22 +00:00
|
|
|
#include "dwc2_udc_otg_regs.h"
|
|
|
|
#include "dwc2_udc_otg_priv.h"
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
/***********************************************************/
|
|
|
|
|
|
|
|
#define OTG_DMA_MODE 1
|
|
|
|
|
2012-05-02 11:11:35 +00:00
|
|
|
#define DEBUG_SETUP 0
|
|
|
|
#define DEBUG_EP0 0
|
|
|
|
#define DEBUG_ISR 0
|
|
|
|
#define DEBUG_OUT_EP 0
|
|
|
|
#define DEBUG_IN_EP 0
|
2011-10-27 08:36:46 +00:00
|
|
|
|
2015-12-04 01:51:20 +00:00
|
|
|
#include <usb/dwc2_udc.h>
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
#define EP0_CON 0
|
|
|
|
#define EP_MASK 0xF
|
|
|
|
|
|
|
|
static char *state_names[] = {
|
|
|
|
"WAIT_FOR_SETUP",
|
|
|
|
"DATA_STATE_XMIT",
|
|
|
|
"DATA_STATE_NEED_ZLP",
|
|
|
|
"WAIT_FOR_OUT_STATUS",
|
|
|
|
"DATA_STATE_RECV",
|
|
|
|
"WAIT_FOR_COMPLETE",
|
|
|
|
"WAIT_FOR_OUT_COMPLETE",
|
|
|
|
"WAIT_FOR_IN_COMPLETE",
|
|
|
|
"WAIT_FOR_NULL_COMPLETE",
|
|
|
|
};
|
|
|
|
|
|
|
|
#define DRIVER_VERSION "15 March 2009"
|
|
|
|
|
2015-12-03 23:57:58 +00:00
|
|
|
struct dwc2_udc *the_controller;
|
2011-10-27 08:36:46 +00:00
|
|
|
|
2015-12-04 01:28:40 +00:00
|
|
|
static const char driver_name[] = "dwc2-udc";
|
2011-10-27 08:36:46 +00:00
|
|
|
static const char ep0name[] = "ep0-control";
|
|
|
|
|
|
|
|
/* Max packet size*/
|
|
|
|
static unsigned int ep0_fifo_size = 64;
|
|
|
|
static unsigned int ep_fifo_size = 512;
|
|
|
|
static unsigned int ep_fifo_size2 = 1024;
|
|
|
|
static int reset_available = 1;
|
|
|
|
|
|
|
|
static struct usb_ctrlrequest *usb_ctrl;
|
|
|
|
static dma_addr_t usb_ctrl_dma_addr;
|
|
|
|
|
|
|
|
/*
|
|
|
|
Local declarations.
|
|
|
|
*/
|
2015-12-04 01:13:42 +00:00
|
|
|
static int dwc2_ep_enable(struct usb_ep *ep,
|
2011-10-27 08:36:46 +00:00
|
|
|
const struct usb_endpoint_descriptor *);
|
2015-12-04 01:13:42 +00:00
|
|
|
static int dwc2_ep_disable(struct usb_ep *ep);
|
2015-12-04 01:17:40 +00:00
|
|
|
static struct usb_request *dwc2_alloc_request(struct usb_ep *ep,
|
2011-10-27 08:36:46 +00:00
|
|
|
gfp_t gfp_flags);
|
2015-12-04 01:17:40 +00:00
|
|
|
static void dwc2_free_request(struct usb_ep *ep, struct usb_request *);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
2015-12-04 01:17:40 +00:00
|
|
|
static int dwc2_queue(struct usb_ep *ep, struct usb_request *, gfp_t gfp_flags);
|
|
|
|
static int dwc2_dequeue(struct usb_ep *ep, struct usb_request *);
|
|
|
|
static int dwc2_fifo_status(struct usb_ep *ep);
|
|
|
|
static void dwc2_fifo_flush(struct usb_ep *ep);
|
2015-12-04 00:59:12 +00:00
|
|
|
static void dwc2_ep0_read(struct dwc2_udc *dev);
|
|
|
|
static void dwc2_ep0_kick(struct dwc2_udc *dev, struct dwc2_ep *ep);
|
2015-12-04 01:17:40 +00:00
|
|
|
static void dwc2_handle_ep0(struct dwc2_udc *dev);
|
2015-12-04 00:59:12 +00:00
|
|
|
static int dwc2_ep0_write(struct dwc2_udc *dev);
|
2015-12-04 00:51:07 +00:00
|
|
|
static int write_fifo_ep0(struct dwc2_ep *ep, struct dwc2_request *req);
|
|
|
|
static void done(struct dwc2_ep *ep, struct dwc2_request *req, int status);
|
2015-12-03 23:57:58 +00:00
|
|
|
static void stop_activity(struct dwc2_udc *dev,
|
2011-10-27 08:36:46 +00:00
|
|
|
struct usb_gadget_driver *driver);
|
2015-12-03 23:57:58 +00:00
|
|
|
static int udc_enable(struct dwc2_udc *dev);
|
|
|
|
static void udc_set_address(struct dwc2_udc *dev, unsigned char address);
|
|
|
|
static void reconfig_usbd(struct dwc2_udc *dev);
|
|
|
|
static void set_max_pktsize(struct dwc2_udc *dev, enum usb_device_speed speed);
|
2015-12-04 00:48:57 +00:00
|
|
|
static void nuke(struct dwc2_ep *ep, int status);
|
2015-12-04 01:03:45 +00:00
|
|
|
static int dwc2_udc_set_halt(struct usb_ep *_ep, int value);
|
|
|
|
static void dwc2_udc_set_nak(struct dwc2_ep *ep);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
2012-05-02 11:11:38 +00:00
|
|
|
void set_udc_gadget_private_data(void *p)
|
|
|
|
{
|
|
|
|
debug_cond(DEBUG_SETUP != 0,
|
|
|
|
"%s: the_controller: 0x%p, p: 0x%p\n", __func__,
|
|
|
|
the_controller, p);
|
|
|
|
the_controller->gadget.dev.device_data = p;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *get_udc_gadget_private_data(struct usb_gadget *gadget)
|
|
|
|
{
|
|
|
|
return gadget->dev.device_data;
|
|
|
|
}
|
|
|
|
|
2015-12-04 01:13:42 +00:00
|
|
|
static struct usb_ep_ops dwc2_ep_ops = {
|
|
|
|
.enable = dwc2_ep_enable,
|
|
|
|
.disable = dwc2_ep_disable,
|
2011-10-27 08:36:46 +00:00
|
|
|
|
2015-12-04 01:17:40 +00:00
|
|
|
.alloc_request = dwc2_alloc_request,
|
|
|
|
.free_request = dwc2_free_request,
|
2011-10-27 08:36:46 +00:00
|
|
|
|
2015-12-04 01:17:40 +00:00
|
|
|
.queue = dwc2_queue,
|
|
|
|
.dequeue = dwc2_dequeue,
|
2011-10-27 08:36:46 +00:00
|
|
|
|
2015-12-04 01:03:45 +00:00
|
|
|
.set_halt = dwc2_udc_set_halt,
|
2015-12-04 01:17:40 +00:00
|
|
|
.fifo_status = dwc2_fifo_status,
|
|
|
|
.fifo_flush = dwc2_fifo_flush,
|
2011-10-27 08:36:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define create_proc_files() do {} while (0)
|
|
|
|
#define remove_proc_files() do {} while (0)
|
|
|
|
|
|
|
|
/***********************************************************/
|
|
|
|
|
2015-12-04 00:11:45 +00:00
|
|
|
struct dwc2_usbotg_reg *reg;
|
2011-10-27 08:36:46 +00:00
|
|
|
|
2014-08-25 09:07:29 +00:00
|
|
|
bool dfu_usb_get_reset(void)
|
|
|
|
{
|
|
|
|
return !!(readl(®->gintsts) & INT_RESET);
|
|
|
|
}
|
|
|
|
|
2015-12-03 23:57:58 +00:00
|
|
|
__weak void otg_phy_init(struct dwc2_udc *dev) {}
|
|
|
|
__weak void otg_phy_off(struct dwc2_udc *dev) {}
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
/***********************************************************/
|
|
|
|
|
2015-12-04 01:34:46 +00:00
|
|
|
#include "dwc2_udc_otg_xfer_dma.c"
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* udc_disable - disable USB device controller
|
|
|
|
*/
|
2015-12-03 23:57:58 +00:00
|
|
|
static void udc_disable(struct dwc2_udc *dev)
|
2011-10-27 08:36:46 +00:00
|
|
|
{
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_SETUP != 0, "%s: %p\n", __func__, dev);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
udc_set_address(dev, 0);
|
|
|
|
|
|
|
|
dev->ep0state = WAIT_FOR_SETUP;
|
|
|
|
dev->gadget.speed = USB_SPEED_UNKNOWN;
|
|
|
|
dev->usb_address = 0;
|
|
|
|
|
|
|
|
otg_phy_off(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* udc_reinit - initialize software state
|
|
|
|
*/
|
2015-12-03 23:57:58 +00:00
|
|
|
static void udc_reinit(struct dwc2_udc *dev)
|
2011-10-27 08:36:46 +00:00
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_SETUP != 0, "%s: %p\n", __func__, dev);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
/* device/ep0 records init */
|
|
|
|
INIT_LIST_HEAD(&dev->gadget.ep_list);
|
|
|
|
INIT_LIST_HEAD(&dev->gadget.ep0->ep_list);
|
|
|
|
dev->ep0state = WAIT_FOR_SETUP;
|
|
|
|
|
|
|
|
/* basic endpoint records init */
|
2015-12-04 01:44:33 +00:00
|
|
|
for (i = 0; i < DWC2_MAX_ENDPOINTS; i++) {
|
2015-12-04 00:48:57 +00:00
|
|
|
struct dwc2_ep *ep = &dev->ep[i];
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
if (i != 0)
|
|
|
|
list_add_tail(&ep->ep.ep_list, &dev->gadget.ep_list);
|
|
|
|
|
|
|
|
ep->desc = 0;
|
|
|
|
ep->stopped = 0;
|
|
|
|
INIT_LIST_HEAD(&ep->queue);
|
|
|
|
ep->pio_irqs = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* the rest was statically initialized, and is read-only */
|
|
|
|
}
|
|
|
|
|
|
|
|
#define BYTES2MAXP(x) (x / 8)
|
|
|
|
#define MAXP2BYTES(x) (x * 8)
|
|
|
|
|
|
|
|
/* until it's enabled, this UDC should be completely invisible
|
|
|
|
* to any USB host.
|
|
|
|
*/
|
2015-12-03 23:57:58 +00:00
|
|
|
static int udc_enable(struct dwc2_udc *dev)
|
2011-10-27 08:36:46 +00:00
|
|
|
{
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_SETUP != 0, "%s: %p\n", __func__, dev);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
otg_phy_init(dev);
|
2014-11-04 03:23:25 +00:00
|
|
|
reconfig_usbd(dev);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_SETUP != 0,
|
2015-12-04 01:28:40 +00:00
|
|
|
"DWC2 USB 2.0 OTG Controller Core Initialized : 0x%x\n",
|
2011-10-27 08:36:46 +00:00
|
|
|
readl(®->gintmsk));
|
|
|
|
|
|
|
|
dev->gadget.speed = USB_SPEED_UNKNOWN;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-03-29 14:42:15 +00:00
|
|
|
#if !CONFIG_IS_ENABLED(DM_USB_GADGET)
|
2011-10-27 08:36:46 +00:00
|
|
|
/*
|
|
|
|
Register entry point for the peripheral controller driver.
|
|
|
|
*/
|
|
|
|
int usb_gadget_register_driver(struct usb_gadget_driver *driver)
|
|
|
|
{
|
2015-12-03 23:57:58 +00:00
|
|
|
struct dwc2_udc *dev = the_controller;
|
2011-10-27 08:36:46 +00:00
|
|
|
int retval = 0;
|
2014-08-27 09:28:18 +00:00
|
|
|
unsigned long flags = 0;
|
2011-10-27 08:36:46 +00:00
|
|
|
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_SETUP != 0, "%s: %s\n", __func__, "no name");
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
if (!driver
|
|
|
|
|| (driver->speed != USB_SPEED_FULL
|
|
|
|
&& driver->speed != USB_SPEED_HIGH)
|
|
|
|
|| !driver->bind || !driver->disconnect || !driver->setup)
|
|
|
|
return -EINVAL;
|
|
|
|
if (!dev)
|
|
|
|
return -ENODEV;
|
|
|
|
if (dev->driver)
|
|
|
|
return -EBUSY;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&dev->lock, flags);
|
|
|
|
/* first hook up the driver ... */
|
|
|
|
dev->driver = driver;
|
|
|
|
spin_unlock_irqrestore(&dev->lock, flags);
|
|
|
|
|
|
|
|
if (retval) { /* TODO */
|
|
|
|
printf("target device_add failed, error %d\n", retval);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
retval = driver->bind(&dev->gadget);
|
|
|
|
if (retval) {
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_SETUP != 0,
|
|
|
|
"%s: bind to driver --> error %d\n",
|
2011-10-27 08:36:46 +00:00
|
|
|
dev->gadget.name, retval);
|
|
|
|
dev->driver = 0;
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
enable_irq(IRQ_OTG);
|
|
|
|
|
2012-05-02 11:11:35 +00:00
|
|
|
debug_cond(DEBUG_SETUP != 0,
|
|
|
|
"Registered gadget driver %s\n", dev->gadget.name);
|
2011-10-27 08:36:46 +00:00
|
|
|
udc_enable(dev);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unregister entry point for the peripheral controller driver.
|
|
|
|
*/
|
|
|
|
int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
|
|
|
|
{
|
2015-12-03 23:57:58 +00:00
|
|
|
struct dwc2_udc *dev = the_controller;
|
2014-08-27 09:28:18 +00:00
|
|
|
unsigned long flags = 0;
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
if (!dev)
|
|
|
|
return -ENODEV;
|
|
|
|
if (!driver || driver != dev->driver)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&dev->lock, flags);
|
|
|
|
dev->driver = 0;
|
|
|
|
stop_activity(dev, driver);
|
|
|
|
spin_unlock_irqrestore(&dev->lock, flags);
|
|
|
|
|
|
|
|
driver->unbind(&dev->gadget);
|
|
|
|
|
|
|
|
disable_irq(IRQ_OTG);
|
|
|
|
|
|
|
|
udc_disable(dev);
|
|
|
|
return 0;
|
|
|
|
}
|
2019-03-29 14:42:15 +00:00
|
|
|
#else /* !CONFIG_IS_ENABLED(DM_USB_GADGET) */
|
|
|
|
|
|
|
|
static int dwc2_gadget_start(struct usb_gadget *g,
|
|
|
|
struct usb_gadget_driver *driver)
|
|
|
|
{
|
|
|
|
struct dwc2_udc *dev = the_controller;
|
|
|
|
|
|
|
|
debug_cond(DEBUG_SETUP != 0, "%s: %s\n", __func__, "no name");
|
|
|
|
|
|
|
|
if (!driver ||
|
|
|
|
(driver->speed != USB_SPEED_FULL &&
|
|
|
|
driver->speed != USB_SPEED_HIGH) ||
|
|
|
|
!driver->bind || !driver->disconnect || !driver->setup)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (!dev)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
if (dev->driver)
|
|
|
|
return -EBUSY;
|
|
|
|
|
|
|
|
/* first hook up the driver ... */
|
|
|
|
dev->driver = driver;
|
|
|
|
|
|
|
|
debug_cond(DEBUG_SETUP != 0,
|
|
|
|
"Registered gadget driver %s\n", dev->gadget.name);
|
|
|
|
return udc_enable(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dwc2_gadget_stop(struct usb_gadget *g)
|
|
|
|
{
|
|
|
|
struct dwc2_udc *dev = the_controller;
|
|
|
|
|
|
|
|
if (!dev)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
if (!dev->driver)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
dev->driver = 0;
|
|
|
|
stop_activity(dev, dev->driver);
|
|
|
|
|
|
|
|
udc_disable(dev);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* !CONFIG_IS_ENABLED(DM_USB_GADGET) */
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* done - retire a request; caller blocked irqs
|
|
|
|
*/
|
2015-12-04 00:51:07 +00:00
|
|
|
static void done(struct dwc2_ep *ep, struct dwc2_request *req, int status)
|
2011-10-27 08:36:46 +00:00
|
|
|
{
|
|
|
|
unsigned int stopped = ep->stopped;
|
|
|
|
|
2011-12-19 04:20:35 +00:00
|
|
|
debug("%s: %s %p, req = %p, stopped = %d\n",
|
2011-10-27 08:36:46 +00:00
|
|
|
__func__, ep->ep.name, ep, &req->req, stopped);
|
|
|
|
|
|
|
|
list_del_init(&req->queue);
|
|
|
|
|
|
|
|
if (likely(req->req.status == -EINPROGRESS))
|
|
|
|
req->req.status = status;
|
|
|
|
else
|
|
|
|
status = req->req.status;
|
|
|
|
|
|
|
|
if (status && status != -ESHUTDOWN) {
|
2011-12-19 04:20:35 +00:00
|
|
|
debug("complete %s req %p stat %d len %u/%u\n",
|
2011-10-27 08:36:46 +00:00
|
|
|
ep->ep.name, &req->req, status,
|
|
|
|
req->req.actual, req->req.length);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* don't modify queue heads during completion callback */
|
|
|
|
ep->stopped = 1;
|
|
|
|
|
2012-05-02 11:11:35 +00:00
|
|
|
#ifdef DEBUG
|
2011-10-27 08:36:46 +00:00
|
|
|
printf("calling complete callback\n");
|
|
|
|
{
|
|
|
|
int i, len = req->req.length;
|
|
|
|
|
|
|
|
printf("pkt[%d] = ", req->req.length);
|
|
|
|
if (len > 64)
|
|
|
|
len = 64;
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
printf("%02x", ((u8 *)req->req.buf)[i]);
|
|
|
|
if ((i & 7) == 7)
|
|
|
|
printf(" ");
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
spin_unlock(&ep->dev->lock);
|
|
|
|
req->req.complete(&ep->ep, &req->req);
|
|
|
|
spin_lock(&ep->dev->lock);
|
|
|
|
|
2011-12-19 04:20:35 +00:00
|
|
|
debug("callback completed\n");
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
ep->stopped = stopped;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* nuke - dequeue ALL requests
|
|
|
|
*/
|
2015-12-04 00:48:57 +00:00
|
|
|
static void nuke(struct dwc2_ep *ep, int status)
|
2011-10-27 08:36:46 +00:00
|
|
|
{
|
2015-12-04 00:51:07 +00:00
|
|
|
struct dwc2_request *req;
|
2011-10-27 08:36:46 +00:00
|
|
|
|
2011-12-19 04:20:35 +00:00
|
|
|
debug("%s: %s %p\n", __func__, ep->ep.name, ep);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
/* called with irqs blocked */
|
|
|
|
while (!list_empty(&ep->queue)) {
|
2015-12-04 00:51:07 +00:00
|
|
|
req = list_entry(ep->queue.next, struct dwc2_request, queue);
|
2011-10-27 08:36:46 +00:00
|
|
|
done(ep, req, status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-03 23:57:58 +00:00
|
|
|
static void stop_activity(struct dwc2_udc *dev,
|
2011-10-27 08:36:46 +00:00
|
|
|
struct usb_gadget_driver *driver)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* don't disconnect drivers more than once */
|
|
|
|
if (dev->gadget.speed == USB_SPEED_UNKNOWN)
|
|
|
|
driver = 0;
|
|
|
|
dev->gadget.speed = USB_SPEED_UNKNOWN;
|
|
|
|
|
|
|
|
/* prevent new request submissions, kill any outstanding requests */
|
2015-12-04 01:44:33 +00:00
|
|
|
for (i = 0; i < DWC2_MAX_ENDPOINTS; i++) {
|
2015-12-04 00:48:57 +00:00
|
|
|
struct dwc2_ep *ep = &dev->ep[i];
|
2011-10-27 08:36:46 +00:00
|
|
|
ep->stopped = 1;
|
|
|
|
nuke(ep, -ESHUTDOWN);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* report disconnect; the driver is already quiesced */
|
|
|
|
if (driver) {
|
|
|
|
spin_unlock(&dev->lock);
|
|
|
|
driver->disconnect(&dev->gadget);
|
|
|
|
spin_lock(&dev->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* re-init driver-visible data structures */
|
|
|
|
udc_reinit(dev);
|
|
|
|
}
|
|
|
|
|
2015-12-03 23:57:58 +00:00
|
|
|
static void reconfig_usbd(struct dwc2_udc *dev)
|
2011-10-27 08:36:46 +00:00
|
|
|
{
|
|
|
|
/* 2. Soft-reset OTG Core and then unreset again. */
|
|
|
|
int i;
|
|
|
|
unsigned int uTemp = writel(CORE_SOFT_RESET, ®->grstctl);
|
2014-11-04 03:23:25 +00:00
|
|
|
uint32_t dflt_gusbcfg;
|
2016-07-14 06:52:33 +00:00
|
|
|
uint32_t rx_fifo_sz, tx_fifo_sz, np_tx_fifo_sz;
|
2019-03-29 14:42:19 +00:00
|
|
|
u32 max_hw_ep;
|
2019-03-29 14:42:20 +00:00
|
|
|
int pdata_hw_ep;
|
2011-10-27 08:36:46 +00:00
|
|
|
|
2011-12-19 04:20:35 +00:00
|
|
|
debug("Reseting OTG controller\n");
|
2011-10-27 08:36:46 +00:00
|
|
|
|
2014-11-04 03:23:25 +00:00
|
|
|
dflt_gusbcfg =
|
|
|
|
0<<15 /* PHY Low Power Clock sel*/
|
2011-10-27 08:36:46 +00:00
|
|
|
|1<<14 /* Non-Periodic TxFIFO Rewind Enable*/
|
|
|
|
|0x5<<10 /* Turnaround time*/
|
|
|
|
|0<<9 | 0<<8 /* [0:HNP disable,1:HNP enable][ 0:SRP disable*/
|
|
|
|
/* 1:SRP enable] H1= 1,1*/
|
|
|
|
|0<<7 /* Ulpi DDR sel*/
|
|
|
|
|0<<6 /* 0: high speed utmi+, 1: full speed serial*/
|
|
|
|
|0<<4 /* 0: utmi+, 1:ulpi*/
|
2016-06-07 22:35:21 +00:00
|
|
|
#ifdef CONFIG_USB_GADGET_DWC2_OTG_PHY_BUS_WIDTH_8
|
|
|
|
|0<<3 /* phy i/f 0:8bit, 1:16bit*/
|
|
|
|
#else
|
2011-10-27 08:36:46 +00:00
|
|
|
|1<<3 /* phy i/f 0:8bit, 1:16bit*/
|
2016-06-07 22:35:21 +00:00
|
|
|
#endif
|
2014-11-04 03:23:25 +00:00
|
|
|
|0x7<<0; /* HS/FS Timeout**/
|
|
|
|
|
|
|
|
if (dev->pdata->usb_gusbcfg)
|
|
|
|
dflt_gusbcfg = dev->pdata->usb_gusbcfg;
|
|
|
|
|
|
|
|
writel(dflt_gusbcfg, ®->gusbcfg);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
/* 3. Put the OTG device core in the disconnected state.*/
|
|
|
|
uTemp = readl(®->dctl);
|
|
|
|
uTemp |= SOFT_DISCONNECT;
|
|
|
|
writel(uTemp, ®->dctl);
|
|
|
|
|
|
|
|
udelay(20);
|
|
|
|
|
|
|
|
/* 4. Make the OTG device core exit from the disconnected state.*/
|
|
|
|
uTemp = readl(®->dctl);
|
|
|
|
uTemp = uTemp & ~SOFT_DISCONNECT;
|
|
|
|
writel(uTemp, ®->dctl);
|
|
|
|
|
|
|
|
/* 5. Configure OTG Core to initial settings of device mode.*/
|
|
|
|
/* [][1: full speed(30Mhz) 0:high speed]*/
|
|
|
|
writel(EP_MISS_CNT(1) | DEV_SPEED_HIGH_SPEED_20, ®->dcfg);
|
|
|
|
|
|
|
|
mdelay(1);
|
|
|
|
|
|
|
|
/* 6. Unmask the core interrupts*/
|
|
|
|
writel(GINTMSK_INIT, ®->gintmsk);
|
|
|
|
|
|
|
|
/* 7. Set NAK bit of EP0, EP1, EP2*/
|
|
|
|
writel(DEPCTL_EPDIS|DEPCTL_SNAK, ®->out_endp[EP0_CON].doepctl);
|
|
|
|
writel(DEPCTL_EPDIS|DEPCTL_SNAK, ®->in_endp[EP0_CON].diepctl);
|
|
|
|
|
2015-12-04 01:44:33 +00:00
|
|
|
for (i = 1; i < DWC2_MAX_ENDPOINTS; i++) {
|
2011-10-27 08:36:46 +00:00
|
|
|
writel(DEPCTL_EPDIS|DEPCTL_SNAK, ®->out_endp[i].doepctl);
|
|
|
|
writel(DEPCTL_EPDIS|DEPCTL_SNAK, ®->in_endp[i].diepctl);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 8. Unmask EPO interrupts*/
|
|
|
|
writel(((1 << EP0_CON) << DAINT_OUT_BIT)
|
|
|
|
| (1 << EP0_CON), ®->daintmsk);
|
|
|
|
|
|
|
|
/* 9. Unmask device OUT EP common interrupts*/
|
|
|
|
writel(DOEPMSK_INIT, ®->doepmsk);
|
|
|
|
|
|
|
|
/* 10. Unmask device IN EP common interrupts*/
|
|
|
|
writel(DIEPMSK_INIT, ®->diepmsk);
|
|
|
|
|
2016-07-14 06:52:33 +00:00
|
|
|
rx_fifo_sz = RX_FIFO_SIZE;
|
|
|
|
np_tx_fifo_sz = NPTX_FIFO_SIZE;
|
|
|
|
tx_fifo_sz = PTX_FIFO_SIZE;
|
|
|
|
|
|
|
|
if (dev->pdata->rx_fifo_sz)
|
|
|
|
rx_fifo_sz = dev->pdata->rx_fifo_sz;
|
|
|
|
if (dev->pdata->np_tx_fifo_sz)
|
|
|
|
np_tx_fifo_sz = dev->pdata->np_tx_fifo_sz;
|
|
|
|
if (dev->pdata->tx_fifo_sz)
|
|
|
|
tx_fifo_sz = dev->pdata->tx_fifo_sz;
|
|
|
|
|
2011-10-27 08:36:46 +00:00
|
|
|
/* 11. Set Rx FIFO Size (in 32-bit words) */
|
2016-07-14 06:52:33 +00:00
|
|
|
writel(rx_fifo_sz, ®->grxfsiz);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
/* 12. Set Non Periodic Tx FIFO Size */
|
2016-07-14 06:52:33 +00:00
|
|
|
writel((np_tx_fifo_sz << 16) | rx_fifo_sz,
|
2011-10-27 08:36:46 +00:00
|
|
|
®->gnptxfsiz);
|
|
|
|
|
2019-03-29 14:42:19 +00:00
|
|
|
/* retrieve the number of IN Endpoints (excluding ep0) */
|
|
|
|
max_hw_ep = (readl(®->ghwcfg4) & GHWCFG4_NUM_IN_EPS_MASK) >>
|
|
|
|
GHWCFG4_NUM_IN_EPS_SHIFT;
|
2019-03-29 14:42:20 +00:00
|
|
|
pdata_hw_ep = dev->pdata->tx_fifo_sz_nb;
|
|
|
|
|
|
|
|
/* tx_fifo_sz_nb should equal to number of IN Endpoint */
|
|
|
|
if (pdata_hw_ep && max_hw_ep != pdata_hw_ep)
|
|
|
|
pr_warn("Got %d hw endpoint but %d tx-fifo-size in array !!\n",
|
|
|
|
max_hw_ep, pdata_hw_ep);
|
|
|
|
|
|
|
|
for (i = 0; i < max_hw_ep; i++) {
|
|
|
|
if (pdata_hw_ep)
|
|
|
|
tx_fifo_sz = dev->pdata->tx_fifo_sz_array[i];
|
2019-03-29 14:42:19 +00:00
|
|
|
|
|
|
|
writel((rx_fifo_sz + np_tx_fifo_sz + (tx_fifo_sz * i)) |
|
|
|
|
tx_fifo_sz << 16, ®->dieptxf[i]);
|
2019-03-29 14:42:20 +00:00
|
|
|
}
|
2011-10-27 08:36:46 +00:00
|
|
|
/* Flush the RX FIFO */
|
|
|
|
writel(RX_FIFO_FLUSH, ®->grstctl);
|
|
|
|
while (readl(®->grstctl) & RX_FIFO_FLUSH)
|
2015-12-04 01:44:33 +00:00
|
|
|
debug("%s: waiting for DWC2_UDC_OTG_GRSTCTL\n", __func__);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
/* Flush all the Tx FIFO's */
|
|
|
|
writel(TX_FIFO_FLUSH_ALL, ®->grstctl);
|
|
|
|
writel(TX_FIFO_FLUSH_ALL | TX_FIFO_FLUSH, ®->grstctl);
|
|
|
|
while (readl(®->grstctl) & TX_FIFO_FLUSH)
|
2015-12-04 01:44:33 +00:00
|
|
|
debug("%s: waiting for DWC2_UDC_OTG_GRSTCTL\n", __func__);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
/* 13. Clear NAK bit of EP0, EP1, EP2*/
|
|
|
|
/* For Slave mode*/
|
|
|
|
/* EP0: Control OUT */
|
|
|
|
writel(DEPCTL_EPDIS | DEPCTL_CNAK,
|
|
|
|
®->out_endp[EP0_CON].doepctl);
|
|
|
|
|
|
|
|
/* 14. Initialize OTG Link Core.*/
|
|
|
|
writel(GAHBCFG_INIT, ®->gahbcfg);
|
|
|
|
}
|
|
|
|
|
2015-12-03 23:57:58 +00:00
|
|
|
static void set_max_pktsize(struct dwc2_udc *dev, enum usb_device_speed speed)
|
2011-10-27 08:36:46 +00:00
|
|
|
{
|
|
|
|
unsigned int ep_ctrl;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (speed == USB_SPEED_HIGH) {
|
|
|
|
ep0_fifo_size = 64;
|
|
|
|
ep_fifo_size = 512;
|
|
|
|
ep_fifo_size2 = 1024;
|
|
|
|
dev->gadget.speed = USB_SPEED_HIGH;
|
|
|
|
} else {
|
|
|
|
ep0_fifo_size = 64;
|
|
|
|
ep_fifo_size = 64;
|
|
|
|
ep_fifo_size2 = 64;
|
|
|
|
dev->gadget.speed = USB_SPEED_FULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
dev->ep[0].ep.maxpacket = ep0_fifo_size;
|
2015-12-04 01:44:33 +00:00
|
|
|
for (i = 1; i < DWC2_MAX_ENDPOINTS; i++)
|
2011-10-27 08:36:46 +00:00
|
|
|
dev->ep[i].ep.maxpacket = ep_fifo_size;
|
|
|
|
|
|
|
|
/* EP0 - Control IN (64 bytes)*/
|
|
|
|
ep_ctrl = readl(®->in_endp[EP0_CON].diepctl);
|
|
|
|
writel(ep_ctrl|(0<<0), ®->in_endp[EP0_CON].diepctl);
|
|
|
|
|
|
|
|
/* EP0 - Control OUT (64 bytes)*/
|
|
|
|
ep_ctrl = readl(®->out_endp[EP0_CON].doepctl);
|
|
|
|
writel(ep_ctrl|(0<<0), ®->out_endp[EP0_CON].doepctl);
|
|
|
|
}
|
|
|
|
|
2015-12-04 01:13:42 +00:00
|
|
|
static int dwc2_ep_enable(struct usb_ep *_ep,
|
2011-10-27 08:36:46 +00:00
|
|
|
const struct usb_endpoint_descriptor *desc)
|
|
|
|
{
|
2015-12-04 00:48:57 +00:00
|
|
|
struct dwc2_ep *ep;
|
2015-12-03 23:57:58 +00:00
|
|
|
struct dwc2_udc *dev;
|
2014-08-27 09:28:18 +00:00
|
|
|
unsigned long flags = 0;
|
2011-10-27 08:36:46 +00:00
|
|
|
|
2011-12-19 04:20:35 +00:00
|
|
|
debug("%s: %p\n", __func__, _ep);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
2015-12-04 00:48:57 +00:00
|
|
|
ep = container_of(_ep, struct dwc2_ep, ep);
|
2011-10-27 08:36:46 +00:00
|
|
|
if (!_ep || !desc || ep->desc || _ep->name == ep0name
|
|
|
|
|| desc->bDescriptorType != USB_DT_ENDPOINT
|
|
|
|
|| ep->bEndpointAddress != desc->bEndpointAddress
|
2011-12-15 15:40:51 +00:00
|
|
|
|| ep_maxpacket(ep) <
|
|
|
|
le16_to_cpu(get_unaligned(&desc->wMaxPacketSize))) {
|
2011-10-27 08:36:46 +00:00
|
|
|
|
2011-12-19 04:20:35 +00:00
|
|
|
debug("%s: bad ep or descriptor\n", __func__);
|
2011-10-27 08:36:46 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* xfer types must match, except that interrupt ~= bulk */
|
|
|
|
if (ep->bmAttributes != desc->bmAttributes
|
|
|
|
&& ep->bmAttributes != USB_ENDPOINT_XFER_BULK
|
|
|
|
&& desc->bmAttributes != USB_ENDPOINT_XFER_INT) {
|
|
|
|
|
2011-12-19 04:20:35 +00:00
|
|
|
debug("%s: %s type mismatch\n", __func__, _ep->name);
|
2011-10-27 08:36:46 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* hardware _could_ do smaller, but driver doesn't */
|
2016-01-27 20:39:40 +00:00
|
|
|
if ((desc->bmAttributes == USB_ENDPOINT_XFER_BULK &&
|
|
|
|
le16_to_cpu(get_unaligned(&desc->wMaxPacketSize)) >
|
2011-12-15 15:40:51 +00:00
|
|
|
ep_maxpacket(ep)) || !get_unaligned(&desc->wMaxPacketSize)) {
|
2011-10-27 08:36:46 +00:00
|
|
|
|
2011-12-19 04:20:35 +00:00
|
|
|
debug("%s: bad %s maxpacket\n", __func__, _ep->name);
|
2011-10-27 08:36:46 +00:00
|
|
|
return -ERANGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
dev = ep->dev;
|
|
|
|
if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) {
|
|
|
|
|
2011-12-19 04:20:35 +00:00
|
|
|
debug("%s: bogus device state\n", __func__);
|
2011-10-27 08:36:46 +00:00
|
|
|
return -ESHUTDOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
ep->stopped = 0;
|
|
|
|
ep->desc = desc;
|
|
|
|
ep->pio_irqs = 0;
|
2011-12-15 15:40:51 +00:00
|
|
|
ep->ep.maxpacket = le16_to_cpu(get_unaligned(&desc->wMaxPacketSize));
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
/* Reset halt state */
|
2015-12-04 01:03:45 +00:00
|
|
|
dwc2_udc_set_nak(ep);
|
|
|
|
dwc2_udc_set_halt(_ep, 0);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
spin_lock_irqsave(&ep->dev->lock, flags);
|
2015-12-04 01:03:45 +00:00
|
|
|
dwc2_udc_ep_activate(ep);
|
2011-10-27 08:36:46 +00:00
|
|
|
spin_unlock_irqrestore(&ep->dev->lock, flags);
|
|
|
|
|
2011-12-19 04:20:35 +00:00
|
|
|
debug("%s: enabled %s, stopped = %d, maxpacket = %d\n",
|
2011-10-27 08:36:46 +00:00
|
|
|
__func__, _ep->name, ep->stopped, ep->ep.maxpacket);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Disable EP
|
|
|
|
*/
|
2015-12-04 01:13:42 +00:00
|
|
|
static int dwc2_ep_disable(struct usb_ep *_ep)
|
2011-10-27 08:36:46 +00:00
|
|
|
{
|
2015-12-04 00:48:57 +00:00
|
|
|
struct dwc2_ep *ep;
|
2014-08-27 09:28:18 +00:00
|
|
|
unsigned long flags = 0;
|
2011-10-27 08:36:46 +00:00
|
|
|
|
2011-12-19 04:20:35 +00:00
|
|
|
debug("%s: %p\n", __func__, _ep);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
2015-12-04 00:48:57 +00:00
|
|
|
ep = container_of(_ep, struct dwc2_ep, ep);
|
2011-10-27 08:36:46 +00:00
|
|
|
if (!_ep || !ep->desc) {
|
2011-12-19 04:20:35 +00:00
|
|
|
debug("%s: %s not enabled\n", __func__,
|
2011-10-27 08:36:46 +00:00
|
|
|
_ep ? ep->ep.name : NULL);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_lock_irqsave(&ep->dev->lock, flags);
|
|
|
|
|
|
|
|
/* Nuke all pending requests */
|
|
|
|
nuke(ep, -ESHUTDOWN);
|
|
|
|
|
|
|
|
ep->desc = 0;
|
|
|
|
ep->stopped = 1;
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&ep->dev->lock, flags);
|
|
|
|
|
2011-12-19 04:20:35 +00:00
|
|
|
debug("%s: disabled %s\n", __func__, _ep->name);
|
2011-10-27 08:36:46 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-12-04 01:17:40 +00:00
|
|
|
static struct usb_request *dwc2_alloc_request(struct usb_ep *ep,
|
2011-10-27 08:36:46 +00:00
|
|
|
gfp_t gfp_flags)
|
|
|
|
{
|
2015-12-04 00:51:07 +00:00
|
|
|
struct dwc2_request *req;
|
2011-10-27 08:36:46 +00:00
|
|
|
|
2011-12-19 04:20:35 +00:00
|
|
|
debug("%s: %s %p\n", __func__, ep->name, ep);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
2012-04-26 02:34:44 +00:00
|
|
|
req = memalign(CONFIG_SYS_CACHELINE_SIZE, sizeof(*req));
|
2011-10-27 08:36:46 +00:00
|
|
|
if (!req)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
memset(req, 0, sizeof *req);
|
|
|
|
INIT_LIST_HEAD(&req->queue);
|
|
|
|
|
|
|
|
return &req->req;
|
|
|
|
}
|
|
|
|
|
2015-12-04 01:17:40 +00:00
|
|
|
static void dwc2_free_request(struct usb_ep *ep, struct usb_request *_req)
|
2011-10-27 08:36:46 +00:00
|
|
|
{
|
2015-12-04 00:51:07 +00:00
|
|
|
struct dwc2_request *req;
|
2011-10-27 08:36:46 +00:00
|
|
|
|
2011-12-19 04:20:35 +00:00
|
|
|
debug("%s: %p\n", __func__, ep);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
2015-12-04 00:51:07 +00:00
|
|
|
req = container_of(_req, struct dwc2_request, req);
|
2011-10-27 08:36:46 +00:00
|
|
|
WARN_ON(!list_empty(&req->queue));
|
|
|
|
kfree(req);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* dequeue JUST ONE request */
|
2015-12-04 01:17:40 +00:00
|
|
|
static int dwc2_dequeue(struct usb_ep *_ep, struct usb_request *_req)
|
2011-10-27 08:36:46 +00:00
|
|
|
{
|
2015-12-04 00:48:57 +00:00
|
|
|
struct dwc2_ep *ep;
|
2015-12-04 00:51:07 +00:00
|
|
|
struct dwc2_request *req;
|
2014-08-27 09:28:18 +00:00
|
|
|
unsigned long flags = 0;
|
2011-10-27 08:36:46 +00:00
|
|
|
|
2011-12-19 04:20:35 +00:00
|
|
|
debug("%s: %p\n", __func__, _ep);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
2015-12-04 00:48:57 +00:00
|
|
|
ep = container_of(_ep, struct dwc2_ep, ep);
|
2011-10-27 08:36:46 +00:00
|
|
|
if (!_ep || ep->ep.name == ep0name)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&ep->dev->lock, flags);
|
|
|
|
|
|
|
|
/* make sure it's actually queued on this endpoint */
|
|
|
|
list_for_each_entry(req, &ep->queue, queue) {
|
|
|
|
if (&req->req == _req)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (&req->req != _req) {
|
|
|
|
spin_unlock_irqrestore(&ep->dev->lock, flags);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
done(ep, req, -ECONNRESET);
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&ep->dev->lock, flags);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return bytes in EP FIFO
|
|
|
|
*/
|
2015-12-04 01:17:40 +00:00
|
|
|
static int dwc2_fifo_status(struct usb_ep *_ep)
|
2011-10-27 08:36:46 +00:00
|
|
|
{
|
|
|
|
int count = 0;
|
2015-12-04 00:48:57 +00:00
|
|
|
struct dwc2_ep *ep;
|
2011-10-27 08:36:46 +00:00
|
|
|
|
2015-12-04 00:48:57 +00:00
|
|
|
ep = container_of(_ep, struct dwc2_ep, ep);
|
2011-10-27 08:36:46 +00:00
|
|
|
if (!_ep) {
|
2011-12-19 04:20:35 +00:00
|
|
|
debug("%s: bad ep\n", __func__);
|
2011-10-27 08:36:46 +00:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2011-12-19 04:20:35 +00:00
|
|
|
debug("%s: %d\n", __func__, ep_index(ep));
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
/* LPD can't report unclaimed bytes from IN fifos */
|
|
|
|
if (ep_is_in(ep))
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Flush EP FIFO
|
|
|
|
*/
|
2015-12-04 01:17:40 +00:00
|
|
|
static void dwc2_fifo_flush(struct usb_ep *_ep)
|
2011-10-27 08:36:46 +00:00
|
|
|
{
|
2015-12-04 00:48:57 +00:00
|
|
|
struct dwc2_ep *ep;
|
2011-10-27 08:36:46 +00:00
|
|
|
|
2015-12-04 00:48:57 +00:00
|
|
|
ep = container_of(_ep, struct dwc2_ep, ep);
|
2011-10-27 08:36:46 +00:00
|
|
|
if (unlikely(!_ep || (!ep->desc && ep->ep.name != ep0name))) {
|
2011-12-19 04:20:35 +00:00
|
|
|
debug("%s: bad ep\n", __func__);
|
2011-10-27 08:36:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-12-19 04:20:35 +00:00
|
|
|
debug("%s: %d\n", __func__, ep_index(ep));
|
2011-10-27 08:36:46 +00:00
|
|
|
}
|
|
|
|
|
2015-12-04 01:03:45 +00:00
|
|
|
static const struct usb_gadget_ops dwc2_udc_ops = {
|
2011-10-27 08:36:46 +00:00
|
|
|
/* current versions must always be self-powered */
|
2019-03-29 14:42:15 +00:00
|
|
|
#if CONFIG_IS_ENABLED(DM_USB_GADGET)
|
|
|
|
.udc_start = dwc2_gadget_start,
|
|
|
|
.udc_stop = dwc2_gadget_stop,
|
|
|
|
#endif
|
2011-10-27 08:36:46 +00:00
|
|
|
};
|
|
|
|
|
2015-12-03 23:57:58 +00:00
|
|
|
static struct dwc2_udc memory = {
|
2011-10-27 08:36:46 +00:00
|
|
|
.usb_address = 0,
|
|
|
|
.gadget = {
|
2015-12-04 01:03:45 +00:00
|
|
|
.ops = &dwc2_udc_ops,
|
2011-10-27 08:36:46 +00:00
|
|
|
.ep0 = &memory.ep[0].ep,
|
|
|
|
.name = driver_name,
|
|
|
|
},
|
|
|
|
|
|
|
|
/* control endpoint */
|
|
|
|
.ep[0] = {
|
|
|
|
.ep = {
|
|
|
|
.name = ep0name,
|
2015-12-04 01:13:42 +00:00
|
|
|
.ops = &dwc2_ep_ops,
|
2011-10-27 08:36:46 +00:00
|
|
|
.maxpacket = EP0_FIFO_SIZE,
|
|
|
|
},
|
|
|
|
.dev = &memory,
|
|
|
|
|
|
|
|
.bEndpointAddress = 0,
|
|
|
|
.bmAttributes = 0,
|
|
|
|
|
|
|
|
.ep_type = ep_control,
|
|
|
|
},
|
|
|
|
|
|
|
|
/* first group of endpoints */
|
|
|
|
.ep[1] = {
|
|
|
|
.ep = {
|
|
|
|
.name = "ep1in-bulk",
|
2015-12-04 01:13:42 +00:00
|
|
|
.ops = &dwc2_ep_ops,
|
2011-10-27 08:36:46 +00:00
|
|
|
.maxpacket = EP_FIFO_SIZE,
|
|
|
|
},
|
|
|
|
.dev = &memory,
|
|
|
|
|
|
|
|
.bEndpointAddress = USB_DIR_IN | 1,
|
|
|
|
.bmAttributes = USB_ENDPOINT_XFER_BULK,
|
|
|
|
|
|
|
|
.ep_type = ep_bulk_out,
|
|
|
|
.fifo_num = 1,
|
|
|
|
},
|
|
|
|
|
|
|
|
.ep[2] = {
|
|
|
|
.ep = {
|
|
|
|
.name = "ep2out-bulk",
|
2015-12-04 01:13:42 +00:00
|
|
|
.ops = &dwc2_ep_ops,
|
2011-10-27 08:36:46 +00:00
|
|
|
.maxpacket = EP_FIFO_SIZE,
|
|
|
|
},
|
|
|
|
.dev = &memory,
|
|
|
|
|
|
|
|
.bEndpointAddress = USB_DIR_OUT | 2,
|
|
|
|
.bmAttributes = USB_ENDPOINT_XFER_BULK,
|
|
|
|
|
|
|
|
.ep_type = ep_bulk_in,
|
|
|
|
.fifo_num = 2,
|
|
|
|
},
|
|
|
|
|
|
|
|
.ep[3] = {
|
|
|
|
.ep = {
|
|
|
|
.name = "ep3in-int",
|
2015-12-04 01:13:42 +00:00
|
|
|
.ops = &dwc2_ep_ops,
|
2011-10-27 08:36:46 +00:00
|
|
|
.maxpacket = EP_FIFO_SIZE,
|
|
|
|
},
|
|
|
|
.dev = &memory,
|
|
|
|
|
|
|
|
.bEndpointAddress = USB_DIR_IN | 3,
|
|
|
|
.bmAttributes = USB_ENDPOINT_XFER_INT,
|
|
|
|
|
|
|
|
.ep_type = ep_interrupt,
|
|
|
|
.fifo_num = 3,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* probe - binds to the platform device
|
|
|
|
*/
|
|
|
|
|
2015-12-04 01:26:33 +00:00
|
|
|
int dwc2_udc_probe(struct dwc2_plat_otg_data *pdata)
|
2011-10-27 08:36:46 +00:00
|
|
|
{
|
2015-12-03 23:57:58 +00:00
|
|
|
struct dwc2_udc *dev = &memory;
|
2014-02-05 09:10:44 +00:00
|
|
|
int retval = 0;
|
2011-10-27 08:36:46 +00:00
|
|
|
|
2011-12-19 04:20:35 +00:00
|
|
|
debug("%s: %p\n", __func__, pdata);
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
dev->pdata = pdata;
|
|
|
|
|
2015-12-04 00:11:45 +00:00
|
|
|
reg = (struct dwc2_usbotg_reg *)pdata->regs_otg;
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
dev->gadget.is_dualspeed = 1; /* Hack only*/
|
|
|
|
dev->gadget.is_otg = 0;
|
|
|
|
dev->gadget.is_a_peripheral = 0;
|
|
|
|
dev->gadget.b_hnp_enable = 0;
|
|
|
|
dev->gadget.a_hnp_support = 0;
|
|
|
|
dev->gadget.a_alt_hnp_support = 0;
|
|
|
|
|
|
|
|
the_controller = dev;
|
|
|
|
|
2014-02-05 09:10:44 +00:00
|
|
|
usb_ctrl = memalign(CONFIG_SYS_CACHELINE_SIZE,
|
|
|
|
ROUND(sizeof(struct usb_ctrlrequest),
|
|
|
|
CONFIG_SYS_CACHELINE_SIZE));
|
|
|
|
if (!usb_ctrl) {
|
2017-09-16 05:10:41 +00:00
|
|
|
pr_err("No memory available for UDC!\n");
|
2014-02-05 09:10:44 +00:00
|
|
|
return -ENOMEM;
|
2011-10-27 08:36:46 +00:00
|
|
|
}
|
2014-02-05 09:10:44 +00:00
|
|
|
|
|
|
|
usb_ctrl_dma_addr = (dma_addr_t) usb_ctrl;
|
2011-10-27 08:36:46 +00:00
|
|
|
|
|
|
|
udc_reinit(dev);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2019-03-29 14:42:15 +00:00
|
|
|
int dwc2_udc_handle_interrupt(void)
|
2011-10-27 08:36:46 +00:00
|
|
|
{
|
|
|
|
u32 intr_status = readl(®->gintsts);
|
|
|
|
u32 gintmsk = readl(®->gintmsk);
|
|
|
|
|
|
|
|
if (intr_status & gintmsk)
|
2015-12-04 01:03:45 +00:00
|
|
|
return dwc2_udc_irq(1, (void *)the_controller);
|
2019-03-29 14:42:15 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if !CONFIG_IS_ENABLED(DM_USB_GADGET)
|
|
|
|
|
|
|
|
int usb_gadget_handle_interrupts(int index)
|
|
|
|
{
|
|
|
|
return dwc2_udc_handle_interrupt();
|
|
|
|
}
|
|
|
|
|
|
|
|
#else /* CONFIG_IS_ENABLED(DM_USB_GADGET) */
|
|
|
|
|
|
|
|
struct dwc2_priv_data {
|
|
|
|
struct clk_bulk clks;
|
|
|
|
struct reset_ctl_bulk resets;
|
2020-05-02 09:35:14 +00:00
|
|
|
struct phy_bulk phys;
|
2019-03-29 14:42:21 +00:00
|
|
|
struct udevice *usb33d_supply;
|
2019-03-29 14:42:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
int dm_usb_gadget_handle_interrupts(struct udevice *dev)
|
|
|
|
{
|
|
|
|
return dwc2_udc_handle_interrupt();
|
|
|
|
}
|
|
|
|
|
2020-05-02 09:35:14 +00:00
|
|
|
static int dwc2_phy_setup(struct udevice *dev, struct phy_bulk *phys)
|
2019-03-29 14:42:15 +00:00
|
|
|
{
|
2020-05-02 09:35:14 +00:00
|
|
|
int ret;
|
2019-03-29 14:42:15 +00:00
|
|
|
|
2020-05-02 09:35:14 +00:00
|
|
|
ret = generic_phy_get_bulk(dev, phys);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2019-03-29 14:42:15 +00:00
|
|
|
|
2020-05-02 09:35:14 +00:00
|
|
|
ret = generic_phy_init_bulk(phys);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2019-03-29 14:42:15 +00:00
|
|
|
|
2020-05-02 09:35:14 +00:00
|
|
|
ret = generic_phy_power_on_bulk(phys);
|
|
|
|
if (ret)
|
|
|
|
generic_phy_exit_bulk(phys);
|
2019-03-29 14:42:15 +00:00
|
|
|
|
|
|
|
return ret;
|
2011-10-27 08:36:46 +00:00
|
|
|
}
|
2019-03-29 14:42:15 +00:00
|
|
|
|
2020-05-02 09:35:14 +00:00
|
|
|
static void dwc2_phy_shutdown(struct udevice *dev, struct phy_bulk *phys)
|
2019-03-29 14:42:15 +00:00
|
|
|
{
|
2020-05-02 09:35:14 +00:00
|
|
|
generic_phy_power_off_bulk(phys);
|
|
|
|
generic_phy_exit_bulk(phys);
|
2019-03-29 14:42:15 +00:00
|
|
|
}
|
|
|
|
|
2020-12-03 23:55:21 +00:00
|
|
|
static int dwc2_udc_otg_of_to_plat(struct udevice *dev)
|
2019-03-29 14:42:15 +00:00
|
|
|
{
|
2020-12-03 23:55:20 +00:00
|
|
|
struct dwc2_plat_otg_data *plat = dev_get_plat(dev);
|
2019-03-29 14:42:21 +00:00
|
|
|
ulong drvdata;
|
|
|
|
void (*set_params)(struct dwc2_plat_otg_data *data);
|
2019-06-18 14:57:16 +00:00
|
|
|
int ret;
|
2019-03-29 14:42:15 +00:00
|
|
|
|
2020-12-19 17:40:14 +00:00
|
|
|
if (usb_get_dr_mode(dev_ofnode(dev)) != USB_DR_MODE_PERIPHERAL &&
|
|
|
|
usb_get_dr_mode(dev_ofnode(dev)) != USB_DR_MODE_OTG) {
|
2019-03-29 14:42:15 +00:00
|
|
|
dev_dbg(dev, "Invalid mode\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2020-12-03 23:55:18 +00:00
|
|
|
plat->regs_otg = dev_read_addr(dev);
|
2019-03-29 14:42:15 +00:00
|
|
|
|
2020-12-03 23:55:18 +00:00
|
|
|
plat->rx_fifo_sz = dev_read_u32_default(dev, "g-rx-fifo-size", 0);
|
|
|
|
plat->np_tx_fifo_sz = dev_read_u32_default(dev, "g-np-tx-fifo-size", 0);
|
2019-06-18 14:57:16 +00:00
|
|
|
|
2020-12-03 23:55:18 +00:00
|
|
|
plat->tx_fifo_sz_nb =
|
2019-06-18 14:57:16 +00:00
|
|
|
dev_read_size(dev, "g-tx-fifo-size") / sizeof(u32);
|
2020-12-03 23:55:18 +00:00
|
|
|
if (plat->tx_fifo_sz_nb > DWC2_MAX_HW_ENDPOINTS)
|
|
|
|
plat->tx_fifo_sz_nb = DWC2_MAX_HW_ENDPOINTS;
|
|
|
|
if (plat->tx_fifo_sz_nb) {
|
2019-06-18 14:57:16 +00:00
|
|
|
ret = dev_read_u32_array(dev, "g-tx-fifo-size",
|
2020-12-03 23:55:18 +00:00
|
|
|
plat->tx_fifo_sz_array,
|
|
|
|
plat->tx_fifo_sz_nb);
|
2019-06-18 14:57:16 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
2019-03-29 14:42:15 +00:00
|
|
|
|
2020-12-03 23:55:18 +00:00
|
|
|
plat->force_b_session_valid =
|
2019-03-29 14:42:24 +00:00
|
|
|
dev_read_bool(dev, "u-boot,force-b-session-valid");
|
2019-03-29 14:42:17 +00:00
|
|
|
|
2020-12-03 23:55:18 +00:00
|
|
|
plat->force_vbus_detection =
|
2020-10-15 12:49:37 +00:00
|
|
|
dev_read_bool(dev, "u-boot,force-vbus-detection");
|
|
|
|
|
2020-12-03 23:55:18 +00:00
|
|
|
/* force plat according compatible */
|
2019-03-29 14:42:21 +00:00
|
|
|
drvdata = dev_get_driver_data(dev);
|
|
|
|
if (drvdata) {
|
|
|
|
set_params = (void *)drvdata;
|
2020-12-03 23:55:18 +00:00
|
|
|
set_params(plat);
|
2019-03-29 14:42:21 +00:00
|
|
|
}
|
|
|
|
|
2019-03-29 14:42:15 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-03-29 14:42:21 +00:00
|
|
|
static void dwc2_set_stm32mp1_hsotg_params(struct dwc2_plat_otg_data *p)
|
|
|
|
{
|
|
|
|
p->activate_stm_id_vb_detection = true;
|
|
|
|
p->usb_gusbcfg =
|
|
|
|
0 << 15 /* PHY Low Power Clock sel*/
|
|
|
|
| 0x9 << 10 /* USB Turnaround time (0x9 for HS phy) */
|
|
|
|
| 0 << 9 /* [0:HNP disable,1:HNP enable]*/
|
|
|
|
| 0 << 8 /* [0:SRP disable 1:SRP enable]*/
|
|
|
|
| 0 << 6 /* 0: high speed utmi+, 1: full speed serial*/
|
|
|
|
| 0x7 << 0; /* FS timeout calibration**/
|
2019-03-29 14:42:24 +00:00
|
|
|
|
|
|
|
if (p->force_b_session_valid)
|
|
|
|
p->usb_gusbcfg |= 1 << 30; /* FDMOD: Force device mode */
|
2019-03-29 14:42:21 +00:00
|
|
|
}
|
|
|
|
|
2019-03-29 14:42:15 +00:00
|
|
|
static int dwc2_udc_otg_reset_init(struct udevice *dev,
|
|
|
|
struct reset_ctl_bulk *resets)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = reset_get_bulk(dev, resets);
|
2020-10-21 12:28:41 +00:00
|
|
|
if (ret == -ENOTSUPP || ret == -ENOENT)
|
2019-03-29 14:42:15 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2019-03-29 14:42:16 +00:00
|
|
|
ret = reset_assert_bulk(resets);
|
|
|
|
|
|
|
|
if (!ret) {
|
|
|
|
udelay(2);
|
|
|
|
ret = reset_deassert_bulk(resets);
|
|
|
|
}
|
2019-03-29 14:42:15 +00:00
|
|
|
if (ret) {
|
|
|
|
reset_release_bulk(resets);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dwc2_udc_otg_clk_init(struct udevice *dev,
|
|
|
|
struct clk_bulk *clks)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = clk_get_bulk(dev, clks);
|
|
|
|
if (ret == -ENOSYS)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = clk_enable_bulk(clks);
|
|
|
|
if (ret) {
|
|
|
|
clk_release_bulk(clks);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dwc2_udc_otg_probe(struct udevice *dev)
|
|
|
|
{
|
2020-12-03 23:55:20 +00:00
|
|
|
struct dwc2_plat_otg_data *plat = dev_get_plat(dev);
|
2019-03-29 14:42:15 +00:00
|
|
|
struct dwc2_priv_data *priv = dev_get_priv(dev);
|
2019-03-29 14:42:17 +00:00
|
|
|
struct dwc2_usbotg_reg *usbotg_reg =
|
2020-12-03 23:55:18 +00:00
|
|
|
(struct dwc2_usbotg_reg *)plat->regs_otg;
|
2019-03-29 14:42:15 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = dwc2_udc_otg_clk_init(dev, &priv->clks);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = dwc2_udc_otg_reset_init(dev, &priv->resets);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2020-05-02 09:35:14 +00:00
|
|
|
ret = dwc2_phy_setup(dev, &priv->phys);
|
2019-03-29 14:42:15 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2020-12-03 23:55:18 +00:00
|
|
|
if (plat->activate_stm_id_vb_detection) {
|
2020-10-15 12:49:37 +00:00
|
|
|
if (CONFIG_IS_ENABLED(DM_REGULATOR) &&
|
2020-12-03 23:55:18 +00:00
|
|
|
(!plat->force_b_session_valid ||
|
|
|
|
plat->force_vbus_detection)) {
|
2020-10-15 12:49:37 +00:00
|
|
|
ret = device_get_supply_regulator(dev, "usb33d-supply",
|
|
|
|
&priv->usb33d_supply);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(dev, "can't get voltage level detector supply\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
ret = regulator_set_enable(priv->usb33d_supply, true);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(dev, "can't enable voltage level detector supply\n");
|
|
|
|
return ret;
|
|
|
|
}
|
2019-03-29 14:42:21 +00:00
|
|
|
}
|
2020-10-15 12:49:37 +00:00
|
|
|
|
2020-12-03 23:55:18 +00:00
|
|
|
if (plat->force_b_session_valid &&
|
|
|
|
!plat->force_vbus_detection) {
|
2020-10-15 12:49:37 +00:00
|
|
|
/* Override VBUS detection: enable then value*/
|
|
|
|
setbits_le32(&usbotg_reg->gotgctl, VB_VALOEN);
|
|
|
|
setbits_le32(&usbotg_reg->gotgctl, VB_VALOVAL);
|
|
|
|
} else {
|
|
|
|
/* Enable VBUS sensing */
|
|
|
|
setbits_le32(&usbotg_reg->ggpio,
|
|
|
|
GGPIO_STM32_OTG_GCCFG_VBDEN);
|
|
|
|
}
|
2020-12-03 23:55:18 +00:00
|
|
|
if (plat->force_b_session_valid) {
|
2020-10-15 12:49:37 +00:00
|
|
|
/* Override B session bits: enable then value */
|
|
|
|
setbits_le32(&usbotg_reg->gotgctl, A_VALOEN | B_VALOEN);
|
|
|
|
setbits_le32(&usbotg_reg->gotgctl,
|
|
|
|
A_VALOVAL | B_VALOVAL);
|
|
|
|
} else {
|
|
|
|
/* Enable ID detection */
|
|
|
|
setbits_le32(&usbotg_reg->ggpio,
|
|
|
|
GGPIO_STM32_OTG_GCCFG_IDEN);
|
2019-03-29 14:42:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-03 23:55:18 +00:00
|
|
|
ret = dwc2_udc_probe(plat);
|
2019-03-29 14:42:15 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
the_controller->driver = 0;
|
|
|
|
|
|
|
|
ret = usb_add_gadget_udc((struct device *)dev, &the_controller->gadget);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dwc2_udc_otg_remove(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct dwc2_priv_data *priv = dev_get_priv(dev);
|
|
|
|
|
|
|
|
usb_del_gadget_udc(&the_controller->gadget);
|
|
|
|
|
|
|
|
reset_release_bulk(&priv->resets);
|
|
|
|
|
|
|
|
clk_release_bulk(&priv->clks);
|
|
|
|
|
2020-05-02 09:35:14 +00:00
|
|
|
dwc2_phy_shutdown(dev, &priv->phys);
|
2019-03-29 14:42:15 +00:00
|
|
|
|
|
|
|
return dm_scan_fdt_dev(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct udevice_id dwc2_udc_otg_ids[] = {
|
|
|
|
{ .compatible = "snps,dwc2" },
|
2019-12-02 11:11:17 +00:00
|
|
|
{ .compatible = "brcm,bcm2835-usb" },
|
2019-03-29 14:42:21 +00:00
|
|
|
{ .compatible = "st,stm32mp1-hsotg",
|
|
|
|
.data = (ulong)dwc2_set_stm32mp1_hsotg_params },
|
|
|
|
{},
|
2019-03-29 14:42:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(dwc2_udc_otg) = {
|
|
|
|
.name = "dwc2-udc-otg",
|
|
|
|
.id = UCLASS_USB_GADGET_GENERIC,
|
|
|
|
.of_match = dwc2_udc_otg_ids,
|
2020-12-03 23:55:21 +00:00
|
|
|
.of_to_plat = dwc2_udc_otg_of_to_plat,
|
2019-03-29 14:42:15 +00:00
|
|
|
.probe = dwc2_udc_otg_probe,
|
|
|
|
.remove = dwc2_udc_otg_remove,
|
2020-12-03 23:55:18 +00:00
|
|
|
.plat_auto = sizeof(struct dwc2_plat_otg_data),
|
2020-12-03 23:55:17 +00:00
|
|
|
.priv_auto = sizeof(struct dwc2_priv_data),
|
2019-03-29 14:42:15 +00:00
|
|
|
};
|
2019-03-29 14:42:18 +00:00
|
|
|
|
|
|
|
int dwc2_udc_B_session_valid(struct udevice *dev)
|
|
|
|
{
|
2020-12-03 23:55:20 +00:00
|
|
|
struct dwc2_plat_otg_data *plat = dev_get_plat(dev);
|
2019-03-29 14:42:18 +00:00
|
|
|
struct dwc2_usbotg_reg *usbotg_reg =
|
2020-12-03 23:55:18 +00:00
|
|
|
(struct dwc2_usbotg_reg *)plat->regs_otg;
|
2019-03-29 14:42:18 +00:00
|
|
|
|
|
|
|
return readl(&usbotg_reg->gotgctl) & B_SESSION_VALID;
|
|
|
|
}
|
2019-03-29 14:42:15 +00:00
|
|
|
#endif /* CONFIG_IS_ENABLED(DM_USB_GADGET) */
|