diff options
Diffstat (limited to 'drivers/usb/gadget/langwell_udc.c')
-rw-r--r-- | drivers/usb/gadget/langwell_udc.c | 1058 |
1 files changed, 632 insertions, 426 deletions
diff --git a/drivers/usb/gadget/langwell_udc.c b/drivers/usb/gadget/langwell_udc.c index c2d2a201f84..b8ec954c069 100644 --- a/drivers/usb/gadget/langwell_udc.c +++ b/drivers/usb/gadget/langwell_udc.c @@ -19,7 +19,7 @@ /* #undef DEBUG */ -/* #undef VERBOSE */ +/* #undef VERBOSE_DEBUG */ #if defined(CONFIG_USB_LANGWELL_OTG) #define OTG_TRANSCEIVER @@ -77,141 +77,110 @@ langwell_ep0_desc = { /*-------------------------------------------------------------------------*/ /* debugging */ -#ifdef DEBUG -#define DBG(dev, fmt, args...) \ - pr_debug("%s %s: " fmt , driver_name, \ - pci_name(dev->pdev), ## args) -#else -#define DBG(dev, fmt, args...) \ - do { } while (0) -#endif /* DEBUG */ - - -#ifdef VERBOSE -#define VDBG DBG -#else -#define VDBG(dev, fmt, args...) \ - do { } while (0) -#endif /* VERBOSE */ - - -#define ERROR(dev, fmt, args...) \ - pr_err("%s %s: " fmt , driver_name, \ - pci_name(dev->pdev), ## args) - -#define WARNING(dev, fmt, args...) \ - pr_warning("%s %s: " fmt , driver_name, \ - pci_name(dev->pdev), ## args) - -#define INFO(dev, fmt, args...) \ - pr_info("%s %s: " fmt , driver_name, \ - pci_name(dev->pdev), ## args) - - -#ifdef VERBOSE +#ifdef VERBOSE_DEBUG static inline void print_all_registers(struct langwell_udc *dev) { int i; /* Capability Registers */ - printk(KERN_DEBUG "Capability Registers (offset: " - "0x%04x, length: 0x%08x)\n", - CAP_REG_OFFSET, - (u32)sizeof(struct langwell_cap_regs)); - printk(KERN_DEBUG "caplength=0x%02x\n", + dev_dbg(&dev->pdev->dev, + "Capability Registers (offset: 0x%04x, length: 0x%08x)\n", + CAP_REG_OFFSET, (u32)sizeof(struct langwell_cap_regs)); + dev_dbg(&dev->pdev->dev, "caplength=0x%02x\n", readb(&dev->cap_regs->caplength)); - printk(KERN_DEBUG "hciversion=0x%04x\n", + dev_dbg(&dev->pdev->dev, "hciversion=0x%04x\n", readw(&dev->cap_regs->hciversion)); - printk(KERN_DEBUG "hcsparams=0x%08x\n", + dev_dbg(&dev->pdev->dev, "hcsparams=0x%08x\n", readl(&dev->cap_regs->hcsparams)); - printk(KERN_DEBUG "hccparams=0x%08x\n", + dev_dbg(&dev->pdev->dev, "hccparams=0x%08x\n", readl(&dev->cap_regs->hccparams)); - printk(KERN_DEBUG "dciversion=0x%04x\n", + dev_dbg(&dev->pdev->dev, "dciversion=0x%04x\n", readw(&dev->cap_regs->dciversion)); - printk(KERN_DEBUG "dccparams=0x%08x\n", + dev_dbg(&dev->pdev->dev, "dccparams=0x%08x\n", readl(&dev->cap_regs->dccparams)); /* Operational Registers */ - printk(KERN_DEBUG "Operational Registers (offset: " - "0x%04x, length: 0x%08x)\n", - OP_REG_OFFSET, - (u32)sizeof(struct langwell_op_regs)); - printk(KERN_DEBUG "extsts=0x%08x\n", + dev_dbg(&dev->pdev->dev, + "Operational Registers (offset: 0x%04x, length: 0x%08x)\n", + OP_REG_OFFSET, (u32)sizeof(struct langwell_op_regs)); + dev_dbg(&dev->pdev->dev, "extsts=0x%08x\n", readl(&dev->op_regs->extsts)); - printk(KERN_DEBUG "extintr=0x%08x\n", + dev_dbg(&dev->pdev->dev, "extintr=0x%08x\n", readl(&dev->op_regs->extintr)); - printk(KERN_DEBUG "usbcmd=0x%08x\n", + dev_dbg(&dev->pdev->dev, "usbcmd=0x%08x\n", readl(&dev->op_regs->usbcmd)); - printk(KERN_DEBUG "usbsts=0x%08x\n", + dev_dbg(&dev->pdev->dev, "usbsts=0x%08x\n", readl(&dev->op_regs->usbsts)); - printk(KERN_DEBUG "usbintr=0x%08x\n", + dev_dbg(&dev->pdev->dev, "usbintr=0x%08x\n", readl(&dev->op_regs->usbintr)); - printk(KERN_DEBUG "frindex=0x%08x\n", + dev_dbg(&dev->pdev->dev, "frindex=0x%08x\n", readl(&dev->op_regs->frindex)); - printk(KERN_DEBUG "ctrldssegment=0x%08x\n", + dev_dbg(&dev->pdev->dev, "ctrldssegment=0x%08x\n", readl(&dev->op_regs->ctrldssegment)); - printk(KERN_DEBUG "deviceaddr=0x%08x\n", + dev_dbg(&dev->pdev->dev, "deviceaddr=0x%08x\n", readl(&dev->op_regs->deviceaddr)); - printk(KERN_DEBUG "endpointlistaddr=0x%08x\n", + dev_dbg(&dev->pdev->dev, "endpointlistaddr=0x%08x\n", readl(&dev->op_regs->endpointlistaddr)); - printk(KERN_DEBUG "ttctrl=0x%08x\n", + dev_dbg(&dev->pdev->dev, "ttctrl=0x%08x\n", readl(&dev->op_regs->ttctrl)); - printk(KERN_DEBUG "burstsize=0x%08x\n", + dev_dbg(&dev->pdev->dev, "burstsize=0x%08x\n", readl(&dev->op_regs->burstsize)); - printk(KERN_DEBUG "txfilltuning=0x%08x\n", + dev_dbg(&dev->pdev->dev, "txfilltuning=0x%08x\n", readl(&dev->op_regs->txfilltuning)); - printk(KERN_DEBUG "txttfilltuning=0x%08x\n", + dev_dbg(&dev->pdev->dev, "txttfilltuning=0x%08x\n", readl(&dev->op_regs->txttfilltuning)); - printk(KERN_DEBUG "ic_usb=0x%08x\n", + dev_dbg(&dev->pdev->dev, "ic_usb=0x%08x\n", readl(&dev->op_regs->ic_usb)); - printk(KERN_DEBUG "ulpi_viewport=0x%08x\n", + dev_dbg(&dev->pdev->dev, "ulpi_viewport=0x%08x\n", readl(&dev->op_regs->ulpi_viewport)); - printk(KERN_DEBUG "configflag=0x%08x\n", + dev_dbg(&dev->pdev->dev, "configflag=0x%08x\n", readl(&dev->op_regs->configflag)); - printk(KERN_DEBUG "portsc1=0x%08x\n", + dev_dbg(&dev->pdev->dev, "portsc1=0x%08x\n", readl(&dev->op_regs->portsc1)); - printk(KERN_DEBUG "devlc=0x%08x\n", + dev_dbg(&dev->pdev->dev, "devlc=0x%08x\n", readl(&dev->op_regs->devlc)); - printk(KERN_DEBUG "otgsc=0x%08x\n", + dev_dbg(&dev->pdev->dev, "otgsc=0x%08x\n", readl(&dev->op_regs->otgsc)); - printk(KERN_DEBUG "usbmode=0x%08x\n", + dev_dbg(&dev->pdev->dev, "usbmode=0x%08x\n", readl(&dev->op_regs->usbmode)); - printk(KERN_DEBUG "endptnak=0x%08x\n", + dev_dbg(&dev->pdev->dev, "endptnak=0x%08x\n", readl(&dev->op_regs->endptnak)); - printk(KERN_DEBUG "endptnaken=0x%08x\n", + dev_dbg(&dev->pdev->dev, "endptnaken=0x%08x\n", readl(&dev->op_regs->endptnaken)); - printk(KERN_DEBUG "endptsetupstat=0x%08x\n", + dev_dbg(&dev->pdev->dev, "endptsetupstat=0x%08x\n", readl(&dev->op_regs->endptsetupstat)); - printk(KERN_DEBUG "endptprime=0x%08x\n", + dev_dbg(&dev->pdev->dev, "endptprime=0x%08x\n", readl(&dev->op_regs->endptprime)); - printk(KERN_DEBUG "endptflush=0x%08x\n", + dev_dbg(&dev->pdev->dev, "endptflush=0x%08x\n", readl(&dev->op_regs->endptflush)); - printk(KERN_DEBUG "endptstat=0x%08x\n", + dev_dbg(&dev->pdev->dev, "endptstat=0x%08x\n", readl(&dev->op_regs->endptstat)); - printk(KERN_DEBUG "endptcomplete=0x%08x\n", + dev_dbg(&dev->pdev->dev, "endptcomplete=0x%08x\n", readl(&dev->op_regs->endptcomplete)); for (i = 0; i < dev->ep_max / 2; i++) { - printk(KERN_DEBUG "endptctrl[%d]=0x%08x\n", + dev_dbg(&dev->pdev->dev, "endptctrl[%d]=0x%08x\n", i, readl(&dev->op_regs->endptctrl[i])); } } -#endif /* VERBOSE */ +#else + +#define print_all_registers(dev) do { } while (0) + +#endif /* VERBOSE_DEBUG */ /*-------------------------------------------------------------------------*/ -#define DIR_STRING(bAddress) (((bAddress) & USB_DIR_IN) ? "in" : "out") +#define is_in(ep) (((ep)->ep_num == 0) ? ((ep)->dev->ep0_dir == \ + USB_DIR_IN) : (usb_endpoint_dir_in((ep)->desc))) -#define is_in(ep) (((ep)->ep_num == 0) ? ((ep)->dev->ep0_dir == \ - USB_DIR_IN) : ((ep)->desc->bEndpointAddress \ - & USB_DIR_IN) == USB_DIR_IN) +#define DIR_STRING(ep) (is_in(ep) ? "in" : "out") -#ifdef DEBUG -static char *type_string(u8 bmAttributes) +static char *type_string(const struct usb_endpoint_descriptor *desc) { - switch ((bmAttributes) & USB_ENDPOINT_XFERTYPE_MASK) { + switch (usb_endpoint_type(desc)) { case USB_ENDPOINT_XFER_BULK: return "bulk"; case USB_ENDPOINT_XFER_ISOC: @@ -222,7 +191,6 @@ static char *type_string(u8 bmAttributes) return "control"; } -#endif /* configure endpoint control registers */ @@ -233,7 +201,7 @@ static void ep_reset(struct langwell_ep *ep, unsigned char ep_num, u32 endptctrl; dev = ep->dev; - VDBG(dev, "---> %s()\n", __func__); + dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__); endptctrl = readl(&dev->op_regs->endptctrl[ep_num]); if (is_in) { /* TX */ @@ -250,7 +218,7 @@ static void ep_reset(struct langwell_ep *ep, unsigned char ep_num, writel(endptctrl, &dev->op_regs->endptctrl[ep_num]); - VDBG(dev, "<--- %s()\n", __func__); + dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); } @@ -260,7 +228,7 @@ static void ep0_reset(struct langwell_udc *dev) struct langwell_ep *ep; int i; - VDBG(dev, "---> %s()\n", __func__); + dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__); /* ep0 in and out */ for (i = 0; i < 2; i++) { @@ -274,17 +242,18 @@ static void ep0_reset(struct langwell_udc *dev) ep->dqh->dqh_ios = 1; ep->dqh->dqh_mpl = EP0_MAX_PKT_SIZE; - /* FIXME: enable ep0-in HW zero length termination select */ + /* enable ep0-in HW zero length termination select */ if (is_in(ep)) ep->dqh->dqh_zlt = 0; ep->dqh->dqh_mult = 0; + ep->dqh->dtd_next = DTD_TERM; + /* configure ep0 control registers */ ep_reset(&dev->ep[0], 0, i, USB_ENDPOINT_XFER_CONTROL); } - VDBG(dev, "<--- %s()\n", __func__); - return; + dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); } @@ -300,12 +269,12 @@ static int langwell_ep_enable(struct usb_ep *_ep, struct langwell_ep *ep; u16 max = 0; unsigned long flags; - int retval = 0; + int i, retval = 0; unsigned char zlt, ios = 0, mult = 0; ep = container_of(_ep, struct langwell_ep, ep); dev = ep->dev; - VDBG(dev, "---> %s()\n", __func__); + dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__); if (!_ep || !desc || ep->desc || desc->bDescriptorType != USB_DT_ENDPOINT) @@ -326,7 +295,7 @@ static int langwell_ep_enable(struct usb_ep *_ep, * sanity check type, direction, address, and then * initialize the endpoint capabilities fields in dQH */ - switch (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) { + switch (usb_endpoint_type(desc)) { case USB_ENDPOINT_XFER_CONTROL: ios = 1; break; @@ -386,33 +355,36 @@ static int langwell_ep_enable(struct usb_ep *_ep, spin_lock_irqsave(&dev->lock, flags); - /* configure endpoint capabilities in dQH */ - ep->dqh->dqh_ios = ios; - ep->dqh->dqh_mpl = cpu_to_le16(max); - ep->dqh->dqh_zlt = zlt; - ep->dqh->dqh_mult = mult; - ep->ep.maxpacket = max; ep->desc = desc; ep->stopped = 0; - ep->ep_num = desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK; + ep->ep_num = usb_endpoint_num(desc); /* ep_type */ - ep->ep_type = desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK; + ep->ep_type = usb_endpoint_type(desc); /* configure endpoint control registers */ ep_reset(ep, ep->ep_num, is_in(ep), ep->ep_type); - DBG(dev, "enabled %s (ep%d%s-%s), max %04x\n", + /* configure endpoint capabilities in dQH */ + i = ep->ep_num * 2 + is_in(ep); + ep->dqh = &dev->ep_dqh[i]; + ep->dqh->dqh_ios = ios; + ep->dqh->dqh_mpl = cpu_to_le16(max); + ep->dqh->dqh_zlt = zlt; + ep->dqh->dqh_mult = mult; + ep->dqh->dtd_next = DTD_TERM; + + dev_dbg(&dev->pdev->dev, "enabled %s (ep%d%s-%s), max %04x\n", _ep->name, ep->ep_num, - DIR_STRING(desc->bEndpointAddress), - type_string(desc->bmAttributes), + DIR_STRING(ep), + type_string(desc), max); spin_unlock_irqrestore(&dev->lock, flags); done: - VDBG(dev, "<--- %s()\n", __func__); + dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); return retval; } @@ -428,7 +400,7 @@ static void done(struct langwell_ep *ep, struct langwell_request *req, struct langwell_dtd *curr_dtd, *next_dtd; int i; - VDBG(dev, "---> %s()\n", __func__); + dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__); /* remove the req from ep->queue */ list_del_init(&req->queue); @@ -448,7 +420,8 @@ static void done(struct langwell_ep *ep, struct langwell_request *req, } if (req->mapped) { - dma_unmap_single(&dev->pdev->dev, req->req.dma, req->req.length, + dma_unmap_single(&dev->pdev->dev, + req->req.dma, req->req.length, is_in(ep) ? PCI_DMA_TODEVICE : PCI_DMA_FROMDEVICE); req->req.dma = DMA_ADDR_INVALID; req->mapped = 0; @@ -458,9 +431,10 @@ static void done(struct langwell_ep *ep, struct langwell_request *req, is_in(ep) ? DMA_TO_DEVICE : DMA_FROM_DEVICE); if (status != -ESHUTDOWN) - DBG(dev, "complete %s, req %p, stat %d, len %u/%u\n", - ep->ep.name, &req->req, status, - req->req.actual, req->req.length); + dev_dbg(&dev->pdev->dev, + "complete %s, req %p, stat %d, len %u/%u\n", + ep->ep.name, &req->req, status, + req->req.actual, req->req.length); /* don't modify queue heads during completion callback */ ep->stopped = 1; @@ -473,7 +447,7 @@ static void done(struct langwell_ep *ep, struct langwell_request *req, spin_lock(&dev->lock); ep->stopped = stopped; - VDBG(dev, "<--- %s()\n", __func__); + dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); } @@ -511,7 +485,7 @@ static int langwell_ep_disable(struct usb_ep *_ep) ep = container_of(_ep, struct langwell_ep, ep); dev = ep->dev; - VDBG(dev, "---> %s()\n", __func__); + dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__); if (!_ep || !ep->desc) return -EINVAL; @@ -535,8 +509,8 @@ static int langwell_ep_disable(struct usb_ep *_ep) spin_unlock_irqrestore(&dev->lock, flags); - DBG(dev, "disabled %s\n", _ep->name); - VDBG(dev, "<--- %s()\n", __func__); + dev_dbg(&dev->pdev->dev, "disabled %s\n", _ep->name); + dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); return 0; } @@ -555,7 +529,7 @@ static struct usb_request *langwell_alloc_request(struct usb_ep *_ep, ep = container_of(_ep, struct langwell_ep, ep); dev = ep->dev; - VDBG(dev, "---> %s()\n", __func__); + dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__); req = kzalloc(sizeof(*req), gfp_flags); if (!req) @@ -564,8 +538,8 @@ static struct usb_request *langwell_alloc_request(struct usb_ep *_ep, req->req.dma = DMA_ADDR_INVALID; INIT_LIST_HEAD(&req->queue); - VDBG(dev, "alloc request for %s\n", _ep->name); - VDBG(dev, "<--- %s()\n", __func__); + dev_vdbg(&dev->pdev->dev, "alloc request for %s\n", _ep->name); + dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); return &req->req; } @@ -580,7 +554,7 @@ static void langwell_free_request(struct usb_ep *_ep, ep = container_of(_ep, struct langwell_ep, ep); dev = ep->dev; - VDBG(dev, "---> %s()\n", __func__); + dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__); if (!_ep || !_req) return; @@ -591,8 +565,8 @@ static void langwell_free_request(struct usb_ep *_ep, if (_req) kfree(req); - VDBG(dev, "free request for %s\n", _ep->name); - VDBG(dev, "<--- %s()\n", __func__); + dev_vdbg(&dev->pdev->dev, "free request for %s\n", _ep->name); + dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); } @@ -608,23 +582,24 @@ static int queue_dtd(struct langwell_ep *ep, struct langwell_request *req) struct langwell_udc *dev; dev = ep->dev; - VDBG(dev, "---> %s()\n", __func__); + dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__); i = ep->ep_num * 2 + is_in(ep); dqh = &dev->ep_dqh[i]; if (ep->ep_num) - VDBG(dev, "%s\n", ep->name); + dev_vdbg(&dev->pdev->dev, "%s\n", ep->name); else /* ep0 */ - VDBG(dev, "%s-%s\n", ep->name, is_in(ep) ? "in" : "out"); + dev_vdbg(&dev->pdev->dev, "%s-%s\n", ep->name, DIR_STRING(ep)); - VDBG(dev, "ep_dqh[%d] addr: 0x%08x\n", i, (u32)&(dev->ep_dqh[i])); + dev_vdbg(&dev->pdev->dev, "ep_dqh[%d] addr: 0x%08x\n", + i, (u32)&(dev->ep_dqh[i])); bit_mask = is_in(ep) ? (1 << (ep->ep_num + 16)) : (1 << (ep->ep_num)); - VDBG(dev, "bit_mask = 0x%08x\n", bit_mask); + dev_vdbg(&dev->pdev->dev, "bit_mask = 0x%08x\n", bit_mask); /* check if the pipe is empty */ if (!(list_empty(&ep->queue))) { @@ -665,14 +640,17 @@ static int queue_dtd(struct langwell_ep *ep, struct langwell_request *req) /* clear active and halt bit */ dtd_status = (u8) ~(DTD_STS_ACTIVE | DTD_STS_HALTED); dqh->dtd_status &= dtd_status; - VDBG(dev, "dqh->dtd_status = 0x%x\n", dqh->dtd_status); + dev_vdbg(&dev->pdev->dev, "dqh->dtd_status = 0x%x\n", dqh->dtd_status); + + /* ensure that updates to the dQH will occure before priming */ + wmb(); /* write 1 to endptprime register to PRIME endpoint */ bit_mask = is_in(ep) ? (1 << (ep->ep_num + 16)) : (1 << ep->ep_num); - VDBG(dev, "endprime bit_mask = 0x%08x\n", bit_mask); + dev_vdbg(&dev->pdev->dev, "endprime bit_mask = 0x%08x\n", bit_mask); writel(bit_mask, &dev->op_regs->endptprime); out: - VDBG(dev, "<--- %s()\n", __func__); + dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); return 0; } @@ -687,7 +665,7 @@ static struct langwell_dtd *build_dtd(struct langwell_request *req, int i; dev = req->ep->dev; - VDBG(dev, "---> %s()\n", __func__); + dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__); /* the maximum transfer length, up to 16k bytes */ *length = min(req->req.length - req->req.actual, @@ -708,7 +686,7 @@ static struct langwell_dtd *build_dtd(struct langwell_request *req, /* fill in total bytes with transfer size */ dtd->dtd_total = cpu_to_le16(*length); - VDBG(dev, "dtd->dtd_total = %d\n", dtd->dtd_total); + dev_vdbg(&dev->pdev->dev, "dtd->dtd_total = %d\n", dtd->dtd_total); /* set is_last flag if req->req.zero is set or not */ if (req->req.zero) { @@ -722,7 +700,7 @@ static struct langwell_dtd *build_dtd(struct langwell_request *req, *is_last = 0; if (*is_last == 0) - VDBG(dev, "multi-dtd request!\n"); + dev_vdbg(&dev->pdev->dev, "multi-dtd request!\n"); /* set interrupt on complete bit for the last dTD */ if (*is_last && !req->req.no_interrupt) @@ -733,10 +711,12 @@ static struct langwell_dtd *build_dtd(struct langwell_request *req, /* set the active bit of status field to 1 */ dtd->dtd_status = DTD_STS_ACTIVE; - VDBG(dev, "dtd->dtd_status = 0x%02x\n", dtd->dtd_status); + dev_vdbg(&dev->pdev->dev, "dtd->dtd_status = 0x%02x\n", + dtd->dtd_status); - VDBG(dev, "length = %d, dma addr= 0x%08x\n", *length, (int)*dma); - VDBG(dev, "<--- %s()\n", __func__); + dev_vdbg(&dev->pdev->dev, "length = %d, dma addr= 0x%08x\n", + *length, (int)*dma); + dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); return dtd; } @@ -751,7 +731,7 @@ static int req_to_dtd(struct langwell_request *req) dma_addr_t dma; dev = req->ep->dev; - VDBG(dev, "---> %s()\n", __func__); + dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__); do { dtd = build_dtd(req, &count, &dma, &is_last); if (dtd == NULL) @@ -773,7 +753,7 @@ static int req_to_dtd(struct langwell_request *req) req->tail = dtd; - VDBG(dev, "<--- %s()\n", __func__); + dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); return 0; } @@ -803,9 +783,9 @@ static int langwell_ep_queue(struct usb_ep *_ep, struct usb_request *_req, dev = ep->dev; req->ep = ep; - VDBG(dev, "---> %s()\n", __func__); + dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__); - if (ep->desc->bmAttributes == USB_ENDPOINT_XFER_ISOC) { + if (usb_endpoint_xfer_isoc(ep->desc)) { if (req->req.length > ep->ep.maxpacket) return -EMSGSIZE; is_iso = 1; @@ -818,7 +798,7 @@ static int langwell_ep_queue(struct usb_ep *_ep, struct usb_request *_req, if (_req->dma == DMA_ADDR_INVALID) { /* WORKAROUND: WARN_ON(size == 0) */ if (_req->length == 0) { - VDBG(dev, "req->length: 0->1\n"); + dev_vdbg(&dev->pdev->dev, "req->length: 0->1\n"); zlflag = 1; _req->length++; } @@ -827,24 +807,25 @@ static int langwell_ep_queue(struct usb_ep *_ep, struct usb_request *_req, _req->buf, _req->length, is_in(ep) ? DMA_TO_DEVICE : DMA_FROM_DEVICE); if (zlflag && (_req->length == 1)) { - VDBG(dev, "req->length: 1->0\n"); + dev_vdbg(&dev->pdev->dev, "req->length: 1->0\n"); zlflag = 0; _req->length = 0; } req->mapped = 1; - VDBG(dev, "req->mapped = 1\n"); + dev_vdbg(&dev->pdev->dev, "req->mapped = 1\n"); } else { dma_sync_single_for_device(&dev->pdev->dev, _req->dma, _req->length, is_in(ep) ? DMA_TO_DEVICE : DMA_FROM_DEVICE); req->mapped = 0; - VDBG(dev, "req->mapped = 0\n"); + dev_vdbg(&dev->pdev->dev, "req->mapped = 0\n"); } - DBG(dev, "%s queue req %p, len %u, buf %p, dma 0x%08llx\n", - _ep->name, - _req, _req->length, _req->buf, (unsigned long long)_req->dma); + dev_dbg(&dev->pdev->dev, + "%s queue req %p, len %u, buf %p, dma 0x%08x\n", + _ep->name, + _req, _req->length, _req->buf, (int)_req->dma); _req->status = -EINPROGRESS; _req->actual = 0; @@ -866,12 +847,12 @@ static int langwell_ep_queue(struct usb_ep *_ep, struct usb_request *_req, if (likely(req != NULL)) { list_add_tail(&req->queue, &ep->queue); - VDBG(dev, "list_add_tail() \n"); + dev_vdbg(&dev->pdev->dev, "list_add_tail()\n"); } spin_unlock_irqrestore(&dev->lock, flags); - VDBG(dev, "<--- %s()\n", __func__); + dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); return 0; } @@ -888,7 +869,7 @@ static int langwell_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) ep = container_of(_ep, struct langwell_ep, ep); dev = ep->dev; - VDBG(dev, "---> %s()\n", __func__); + dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__); if (!_ep || !ep->desc || !_req) return -EINVAL; @@ -924,7 +905,7 @@ static int langwell_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) /* queue head may be partially complete. */ if (ep->queue.next == &req->queue) { - DBG(dev, "unlink (%s) dma\n", _ep->name); + dev_dbg(&dev->pdev->dev, "unlink (%s) dma\n", _ep->name); _req->status = -ECONNRESET; langwell_ep_fifo_flush(&ep->ep); @@ -963,7 +944,7 @@ done: ep->stopped = stopped; spin_unlock_irqrestore(&dev->lock, flags); - VDBG(dev, "<--- %s()\n", __func__); + dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); return retval; } @@ -976,7 +957,7 @@ static void ep_set_halt(struct langwell_ep *ep, int value) u32 endptctrl = 0; int ep_num; struct langwell_udc *dev = ep->dev; - VDBG(dev, "---> %s()\n", __func__); + dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__); ep_num = ep->ep_num; endptctrl = readl(&dev->op_regs->endptctrl[ep_num]); @@ -1001,7 +982,7 @@ static void ep_set_halt(struct langwell_ep *ep, int value) writel(endptctrl, &dev->op_regs->endptctrl[ep_num]); - VDBG(dev, "<--- %s()\n", __func__); + dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); } @@ -1016,7 +997,7 @@ static int langwell_ep_set_halt(struct usb_ep *_ep, int value) ep = container_of(_ep, struct langwell_ep, ep); dev = ep->dev; - VDBG(dev, "---> %s()\n", __func__); + dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__); if (!_ep || !ep->desc) return -EINVAL; @@ -1024,8 +1005,7 @@ static int langwell_ep_set_halt(struct usb_ep *_ep, int value) if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) return -ESHUTDOWN; - if (ep->desc && (ep->desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) - == USB_ENDPOINT_XFER_ISOC) + if (usb_endpoint_xfer_isoc(ep->desc)) return -EOPNOTSUPP; spin_lock_irqsave(&dev->lock, flags); @@ -1036,7 +1016,7 @@ static int langwell_ep_set_halt(struct usb_ep *_ep, int value) */ if (!list_empty(&ep->queue) && is_in(ep) && value) { /* IN endpoint FIFO holds bytes */ - DBG(dev, "%s FIFO holds bytes\n", _ep->name); + dev_dbg(&dev->pdev->dev, "%s FIFO holds bytes\n", _ep->name); retval = -EAGAIN; goto done; } @@ -1050,8 +1030,9 @@ static int langwell_ep_set_halt(struct usb_ep *_ep, int value) } done: spin_unlock_irqrestore(&dev->lock, flags); - DBG(dev, "%s %s halt\n", _ep->name, value ? "set" : "clear"); - VDBG(dev, "<--- %s()\n", __func__); + dev_dbg(&dev->pdev->dev, "%s %s halt\n", + _ep->name, value ? "set" : "clear"); + dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); return retval; } @@ -1065,12 +1046,12 @@ static int langwell_ep_set_wedge(struct usb_ep *_ep) ep = container_of(_ep, struct langwell_ep, ep); dev = ep->dev; - VDBG(dev, "---> %s()\n", __func__); + dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__); if (!_ep || !ep->desc) return -EINVAL; - VDBG(dev, "<--- %s()\n", __func__); + dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); return usb_ep_set_halt(_ep); } @@ -1086,15 +1067,16 @@ static void langwell_ep_fifo_flush(struct usb_ep *_ep) ep = container_of(_ep, struct langwell_ep, ep); dev = ep->dev; - VDBG(dev, "---> %s()\n", __func__); + dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__); if (!_ep || !ep->desc) { - VDBG(dev, "ep or ep->desc is NULL\n"); - VDBG(dev, "<--- %s()\n", __func__); + dev_vdbg(&dev->pdev->dev, "ep or ep->desc is NULL\n"); + dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); return; } - VDBG(dev, "%s-%s fifo flush\n", _ep->name, is_in(ep) ? "in" : "out"); + dev_vdbg(&dev->pdev->dev, "%s-%s fifo flush\n", + _ep->name, DIR_STRING(ep)); /* flush endpoint buffer */ if (ep->ep_num == 0) @@ -1110,14 +1092,14 @@ static void langwell_ep_fifo_flush(struct usb_ep *_ep) writel(flush_bit, &dev->op_regs->endptflush); while (readl(&dev->op_regs->endptflush)) { if (time_after(jiffies, timeout)) { - ERROR(dev, "ep flush timeout\n"); + dev_err(&dev->pdev->dev, "ep flush timeout\n"); goto done; } cpu_relax(); } } while (readl(&dev->op_regs->endptstat) & flush_bit); done: - VDBG(dev, "<--- %s()\n", __func__); + dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); } @@ -1167,31 +1149,59 @@ static int langwell_get_frame(struct usb_gadget *_gadget) return -ENODEV; dev = container_of(_gadget, struct langwell_udc, gadget); - VDBG(dev, "---> %s()\n", __func__); + dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__); retval = readl(&dev->op_regs->frindex) & FRINDEX_MASK; - VDBG(dev, "<--- %s()\n", __func__); + dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); return retval; } +/* enter or exit PHY low power state */ +static void langwell_phy_low_power(struct langwell_udc *dev, bool flag) +{ + u32 devlc; + u8 devlc_byte2; + dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__); + + devlc = readl(&dev->op_regs->devlc); + dev_vdbg(&dev->pdev->dev, "devlc = 0x%08x\n", devlc); + + if (flag) + devlc |= LPM_PHCD; + else + devlc &= ~LPM_PHCD; + + /* FIXME: workaround for Langwell A1/A2/A3 sighting */ + devlc_byte2 = (devlc >> 16) & 0xff; + writeb(devlc_byte2, (u8 *)&dev->op_regs->devlc + 2); + + devlc = readl(&dev->op_regs->devlc); + dev_vdbg(&dev->pdev->dev, + "%s PHY low power suspend, devlc = 0x%08x\n", + flag ? "enter" : "exit", devlc); +} + + /* tries to wake up the host connected to this gadget */ static int langwell_wakeup(struct usb_gadget *_gadget) { struct langwell_udc *dev; - u32 portsc1, devlc; - unsigned long flags; + u32 portsc1; + unsigned long flags; if (!_gadget) return 0; dev = container_of(_gadget, struct langwell_udc, gadget); - VDBG(dev, "---> %s()\n", __func__); + dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__); - /* Remote Wakeup feature not enabled by host */ - if (!dev->remote_wakeup) + /* remote wakeup feature not enabled by host */ + if (!dev->remote_wakeup) { + dev_info(&dev->pdev->dev, "remote wakeup is disabled\n"); return -ENOTSUPP; + } spin_lock_irqsave(&dev->lock, flags); @@ -1201,27 +1211,23 @@ static int langwell_wakeup(struct usb_gadget *_gadget) return 0; } - /* LPM L1 to L0, remote wakeup */ - if (dev->lpm && dev->lpm_state == LPM_L1) { - portsc1 |= PORTS_SLP; - writel(portsc1, &dev->op_regs->portsc1); - } - - /* force port resume */ - if (dev->usb_state == USB_STATE_SUSPENDED) { - portsc1 |= PORTS_FPR; - writel(portsc1, &dev->op_regs->portsc1); - } + /* LPM L1 to L0 or legacy remote wakeup */ + if (dev->lpm && dev->lpm_state == LPM_L1) + dev_info(&dev->pdev->dev, "LPM L1 to L0 remote wakeup\n"); + else + dev_info(&dev->pdev->dev, "device remote wakeup\n"); /* exit PHY low power suspend */ - devlc = readl(&dev->op_regs->devlc); - VDBG(dev, "devlc = 0x%08x\n", devlc); - devlc &= ~LPM_PHCD; - writel(devlc, &dev->op_regs->devlc); + if (dev->pdev->device != 0x0829) + langwell_phy_low_power(dev, 0); + + /* force port resume */ + portsc1 |= PORTS_FPR; + writel(portsc1, &dev->op_regs->portsc1); spin_unlock_irqrestore(&dev->lock, flags); - VDBG(dev, "<--- %s()\n", __func__); + dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); return 0; } @@ -1231,16 +1237,17 @@ static int langwell_vbus_session(struct usb_gadget *_gadget, int is_active) { struct langwell_udc *dev; unsigned long flags; - u32 usbcmd; + u32 usbcmd; if (!_gadget) return -ENODEV; dev = container_of(_gadget, struct langwell_udc, gadget); - VDBG(dev, "---> %s()\n", __func__); + dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__); spin_lock_irqsave(&dev->lock, flags); - VDBG(dev, "VBUS status: %s\n", is_active ? "on" : "off"); + dev_vdbg(&dev->pdev->dev, "VBUS status: %s\n", + is_active ? "on" : "off"); dev->vbus_active = (is_active != 0); if (dev->driver && dev->softconnected && dev->vbus_active) { @@ -1255,7 +1262,7 @@ static int langwell_vbus_session(struct usb_gadget *_gadget, int is_active) spin_unlock_irqrestore(&dev->lock, flags); - VDBG(dev, "<--- %s()\n", __func__); + dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); return 0; } @@ -1269,15 +1276,15 @@ static int langwell_vbus_draw(struct usb_gadget *_gadget, unsigned mA) return -ENODEV; dev = container_of(_gadget, struct langwell_udc, gadget); - VDBG(dev, "---> %s()\n", __func__); + dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__); if (dev->transceiver) { - VDBG(dev, "otg_set_power\n"); - VDBG(dev, "<--- %s()\n", __func__); + dev_vdbg(&dev->pdev->dev, "otg_set_power\n"); + dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); return otg_set_power(dev->transceiver, mA); } - VDBG(dev, "<--- %s()\n", __func__); + dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); return -ENOTSUPP; } @@ -1286,15 +1293,15 @@ static int langwell_vbus_draw(struct usb_gadget *_gadget, unsigned mA) static int langwell_pullup(struct usb_gadget *_gadget, int is_on) { struct langwell_udc *dev; - u32 usbcmd; - unsigned long flags; + u32 usbcmd; + unsigned long flags; if (!_gadget) return -ENODEV; dev = container_of(_gadget, struct langwell_udc, gadget); - VDBG(dev, "---> %s()\n", __func__); + dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__); spin_lock_irqsave(&dev->lock, flags); dev->softconnected = (is_on != 0); @@ -1310,7 +1317,7 @@ static int langwell_pullup(struct usb_gadget *_gadget, int is_on) } spin_unlock_irqrestore(&dev->lock, flags); - VDBG(dev, "<--- %s()\n", __func__); + dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); return 0; } @@ -1346,12 +1353,13 @@ static const struct usb_gadget_ops langwell_ops = { static int langwell_udc_reset(struct langwell_udc *dev) { u32 usbcmd, usbmode, devlc, endpointlistaddr; + u8 devlc_byte0, devlc_byte2; unsigned long timeout; if (!dev) return -EINVAL; - DBG(dev, "---> %s()\n", __func__); + dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__); /* set controller to stop state */ usbcmd = readl(&dev->op_regs->usbcmd); @@ -1367,7 +1375,7 @@ static int langwell_udc_reset(struct langwell_udc *dev) timeout = jiffies + RESET_TIMEOUT; while (readl(&dev->op_regs->usbcmd) & CMD_RST) { if (time_after(jiffies, timeout)) { - ERROR(dev, "device reset timeout\n"); + dev_err(&dev->pdev->dev, "device reset timeout\n"); return -ETIMEDOUT; } cpu_relax(); @@ -1382,7 +1390,7 @@ static int langwell_udc_reset(struct langwell_udc *dev) writel(usbmode, &dev->op_regs->usbmode); usbmode = readl(&dev->op_regs->usbmode); - VDBG(dev, "usbmode=0x%08x\n", usbmode); + dev_vdbg(&dev->pdev->dev, "usbmode=0x%08x\n", usbmode); /* Write-Clear setup status */ writel(0, &dev->op_regs->usbsts); @@ -1390,9 +1398,17 @@ static int langwell_udc_reset(struct langwell_udc *dev) /* if support USB LPM, ACK all LPM token */ if (dev->lpm) { devlc = readl(&dev->op_regs->devlc); + dev_vdbg(&dev->pdev->dev, "devlc = 0x%08x\n", devlc); + /* FIXME: workaround for Langwell A1/A2/A3 sighting */ devlc &= ~LPM_STL; /* don't STALL LPM token */ devlc &= ~LPM_NYT_ACK; /* ACK LPM token */ - writel(devlc, &dev->op_regs->devlc); + devlc_byte0 = devlc & 0xff; + devlc_byte2 = (devlc >> 16) & 0xff; + writeb(devlc_byte0, (u8 *)&dev->op_regs->devlc); + writeb(devlc_byte2, (u8 *)&dev->op_regs->devlc + 2); + devlc = readl(&dev->op_regs->devlc); + dev_vdbg(&dev->pdev->dev, + "ACK LPM token, devlc = 0x%08x\n", devlc); } /* fill endpointlistaddr register */ @@ -1400,10 +1416,11 @@ static int langwell_udc_reset(struct langwell_udc *dev) endpointlistaddr &= ENDPOINTLISTADDR_MASK; writel(endpointlistaddr, &dev->op_regs->endpointlistaddr); - VDBG(dev, "dQH base (vir: %p, phy: 0x%08x), endpointlistaddr=0x%08x\n", - dev->ep_dqh, endpointlistaddr, - readl(&dev->op_regs->endpointlistaddr)); - DBG(dev, "<--- %s()\n", __func__); + dev_vdbg(&dev->pdev->dev, + "dQH base (vir: %p, phy: 0x%08x), endpointlistaddr=0x%08x\n", + dev->ep_dqh, endpointlistaddr, + readl(&dev->op_regs->endpointlistaddr)); + dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__); return 0; } @@ -1415,7 +1432,7 @@ static int eps_reinit(struct langwell_udc *dev) char name[14]; int i; - VDBG(dev, "---> %s()\n", __func__); + dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__); /* initialize ep0 */ ep = &dev->ep[0]; @@ -1449,11 +1466,9 @@ static int eps_reinit(struct langwell_udc *dev) INIT_LIST_HEAD(&ep->queue); list_add_tail(&ep->ep.ep_list, &dev->gadget.ep_list); - - ep->dqh = &dev->ep_dqh[i]; } - VDBG(dev, "<--- %s()\n", __func__); + dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); return 0; } @@ -1462,7 +1477,7 @@ static int eps_reinit(struct langwell_udc *dev) static void langwell_udc_start(struct langwell_udc *dev) { u32 usbintr, usbcmd; - DBG(dev, "---> %s()\n", __func__); + dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__); /* enable interrupts */ usbintr = |