summaryrefslogtreecommitdiff
path: root/drivers/usb/gadget/langwell_udc.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/gadget/langwell_udc.c')
-rw-r--r--drivers/usb/gadget/langwell_udc.c1058
1 files changed, 632 insertions, 426 deletions
diff --git a/drivers/usb/gadget/langwell_udc.c b/drivers/usb/gadget/langwell_udc.c
index c2d2a201f84b..b8ec954c0692 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 = INTR_ULPIE /* ULPI */
@@ -1485,8 +1500,7 @@ static void langwell_udc_start(struct langwell_udc *dev)
usbcmd |= CMD_RUNSTOP;
writel(usbcmd, &dev->op_regs->usbcmd);
- DBG(dev, "<--- %s()\n", __func__);
- return;
+ dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__);
}
@@ -1495,7 +1509,7 @@ static void langwell_udc_stop(struct langwell_udc *dev)
{
u32 usbcmd;
- DBG(dev, "---> %s()\n", __func__);
+ dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__);
/* disable all interrupts */
writel(0, &dev->op_regs->usbintr);
@@ -1508,8 +1522,7 @@ static void langwell_udc_stop(struct langwell_udc *dev)
usbcmd &= ~CMD_RUNSTOP;
writel(usbcmd, &dev->op_regs->usbcmd);
- DBG(dev, "<--- %s()\n", __func__);
- return;
+ dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__);
}
@@ -1518,7 +1531,7 @@ static void stop_activity(struct langwell_udc *dev,
struct usb_gadget_driver *driver)
{
struct langwell_ep *ep;
- DBG(dev, "---> %s()\n", __func__);
+ dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__);
nuke(&dev->ep[0], -ESHUTDOWN);
@@ -1533,7 +1546,7 @@ static void stop_activity(struct langwell_udc *dev,
spin_lock(&dev->lock);
}
- DBG(dev, "<--- %s()\n", __func__);
+ dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__);
}
@@ -1659,13 +1672,15 @@ static ssize_t show_langwell_udc(struct device *_dev,
"Over-current Change: %s\n"
"Port Enable/Disable Change: %s\n"
"Port Enabled/Disabled: %s\n"
- "Current Connect Status: %s\n\n",
+ "Current Connect Status: %s\n"
+ "LPM Suspend Status: %s\n\n",
(tmp_reg & PORTS_PR) ? "Reset" : "Not Reset",
(tmp_reg & PORTS_SUSP) ? "Suspend " : "Not Suspend",
(tmp_reg & PORTS_OCC) ? "Detected" : "No",
(tmp_reg & PORTS_PEC) ? "Changed" : "Not Changed",
(tmp_reg & PORTS_PE) ? "Enable" : "Not Correct",
- (tmp_reg & PORTS_CCS) ? "Attached" : "Not Attached");
+ (tmp_reg & PORTS_CCS) ? "Attached" : "Not Attached",
+ (tmp_reg & PORTS_SLP) ? "LPM L1" : "LPM L0");
size -= t;
next += t;
@@ -1676,7 +1691,7 @@ static ssize_t show_langwell_udc(struct device *_dev,
"Serial Transceiver : %d\n"
"Port Speed: %s\n"
"Port Force Full Speed Connenct: %s\n"
- "PHY Low Power Suspend Clock Disable: %s\n"
+ "PHY Low Power Suspend Clock: %s\n"
"BmAttributes: %d\n\n",
LPM_PTS(tmp_reg),
(tmp_reg & LPM_STS) ? 1 : 0,
@@ -1797,6 +1812,36 @@ static ssize_t show_langwell_udc(struct device *_dev,
static DEVICE_ATTR(langwell_udc, S_IRUGO, show_langwell_udc, NULL);
+/* device "remote_wakeup" sysfs attribute file */
+static ssize_t store_remote_wakeup(struct device *_dev,
+ struct device_attribute *attr, const char *buf, size_t count)
+{
+ struct langwell_udc *dev = the_controller;
+ unsigned long flags;
+ ssize_t rc = count;
+
+ if (count > 2)
+ return -EINVAL;
+
+ if (count > 0 && buf[count-1] == '\n')
+ ((char *) buf)[count-1] = 0;
+
+ if (buf[0] != '1')
+ return -EINVAL;
+
+ /* force remote wakeup enabled in case gadget driver doesn't support */
+ spin_lock_irqsave(&dev->lock, flags);
+ dev->remote_wakeup = 1;
+ dev->dev_status |= (1 << USB_DEVICE_REMOTE_WAKEUP);
+ spin_unlock_irqrestore(&dev->lock, flags);
+
+ langwell_wakeup(&dev->gadget);
+
+ return rc;
+}
+static DEVICE_ATTR(remote_wakeup, S_IWUSR, NULL, store_remote_wakeup);
+
+
/*-------------------------------------------------------------------------*/
/*
@@ -1807,7 +1852,8 @@ static DEVICE_ATTR(langwell_udc, S_IRUGO, show_langwell_udc, NULL);
* the driver might get unbound.
*/
-int usb_gadget_register_driver(struct usb_gadget_driver *driver)
+int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
+ int (*bind)(struct usb_gadget *))
{
struct langwell_udc *dev = the_controller;
unsigned long flags;
@@ -1816,7 +1862,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
if (!dev)
return -ENODEV;
- DBG(dev, "---> %s()\n", __func__);
+ dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__);
if (dev->driver)
return -EBUSY;
@@ -1830,9 +1876,9 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
spin_unlock_irqrestore(&dev->lock, flags);
- retval = driver->bind(&dev->gadget);
+ retval = bind(&dev->gadget);
if (retval) {
- DBG(dev, "bind to driver %s --> %d\n",
+ dev_dbg(&dev->pdev->dev, "bind to driver %s --> %d\n",
driver->driver.name, retval);
dev->driver = NULL;
dev->gadget.dev.driver = NULL;
@@ -1851,13 +1897,13 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
if (dev->got_irq)
langwell_udc_start(dev);
- VDBG(dev, "After langwell_udc_start(), print all registers:\n");
-#ifdef VERBOSE
+ dev_vdbg(&dev->pdev->dev,
+ "After langwell_udc_start(), print all registers:\n");
print_all_registers(dev);
-#endif
- INFO(dev, "register driver: %s\n", driver->driver.name);
- VDBG(dev, "<--- %s()\n", __func__);
+ dev_info(&dev->pdev->dev, "register driver: %s\n",
+ driver->driver.name);
+ dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__);
return 0;
err_unbind:
@@ -1865,10 +1911,10 @@ err_unbind:
dev->gadget.dev.driver = NULL;
dev->driver = NULL;
- DBG(dev, "<--- %s()\n", __func__);
+ dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__);
return retval;
}
-EXPORT_SYMBOL(usb_gadget_register_driver);
+EXPORT_SYMBOL(usb_gadget_probe_driver);
/* unregister gadget driver */
@@ -1880,11 +1926,15 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
if (!dev)
return -ENODEV;
- DBG(dev, "---> %s()\n", __func__);
+ dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__);
- if (unlikely(!driver || !driver->bind || !driver->unbind))
+ if (unlikely(!driver || !driver->unbind))
return -EINVAL;
+ /* exit PHY low power suspend */
+ if (dev->pdev->device != 0x0829)
+ langwell_phy_low_power(dev, 0);
+
/* unbind OTG transceiver */
if (dev->transceiver)
(void)otg_set_peripheral(dev->transceiver, 0);
@@ -1910,8 +1960,9 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
device_remove_file(&dev->pdev->dev, &dev_attr_function);
- INFO(dev, "unregistered driver '%s'\n", driver->driver.name);
- DBG(dev, "<--- %s()\n", __func__);
+ dev_info(&dev->pdev->dev, "unregistered driver '%s'\n",
+ driver->driver.name);
+ dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__);
return 0;
}
EXPORT_SYMBOL(usb_gadget_unregister_driver);
@@ -1930,7 +1981,7 @@ static void setup_tripwire(struct langwell_udc *dev)
unsigned long timeout;
struct langwell_dqh *dqh;
- VDBG(dev, "---> %s()\n", __func__);
+ dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
/* ep0 OUT dQH */
dqh = &dev->ep_dqh[EP_DIR_OUT];
@@ -1943,7 +1994,7 @@ static void setup_tripwire(struct langwell_udc *dev)
timeout = jiffies + SETUPSTAT_TIMEOUT;
while (readl(&dev->op_regs->endptsetupstat)) {
if (time_after(jiffies, timeout)) {
- ERROR(dev, "setup_tripwire timeout\n");
+ dev_err(&dev->pdev->dev, "setup_tripwire timeout\n");
break;
}
cpu_relax();
@@ -1963,7 +2014,7 @@ static void setup_tripwire(struct langwell_udc *dev)
usbcmd = readl(&dev->op_regs->usbcmd);
writel(usbcmd & ~CMD_SUTW, &dev->op_regs->usbcmd);
- VDBG(dev, "<--- %s()\n", __func__);
+ dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
}
@@ -1972,7 +2023,7 @@ static void ep0_stall(struct langwell_udc *dev)
{
u32 endptctrl;
- VDBG(dev, "---> %s()\n", __func__);
+ dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
/* set TX and RX to stall */
endptctrl = readl(&dev->op_regs->endptctrl[0]);
@@ -1983,7 +2034,7 @@ static void ep0_stall(struct langwell_udc *dev)
dev->ep0_state = WAIT_FOR_SETUP;
dev->ep0_dir = USB_DIR_OUT;
- VDBG(dev, "<--- %s()\n", __func__);
+ dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
}
@@ -1994,7 +2045,7 @@ static int prime_status_phase(struct langwell_udc *dev, int dir)
struct langwell_ep *ep;
int status = 0;
- VDBG(dev, "---> %s()\n", __func__);
+ dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
if (dir == EP_DIR_IN)
dev->ep0_dir = USB_DIR_IN;
@@ -2019,11 +2070,11 @@ static int prime_status_phase(struct langwell_udc *dev, int dir)
return -ENOMEM;
if (status)
- ERROR(dev, "can't queue ep0 status request\n");
+ dev_err(&dev->pdev->dev, "can't queue ep0 status request\n");
list_add_tail(&req->queue, &ep->queue);
- VDBG(dev, "<--- %s()\n", __func__);
+ dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
return status;
}
@@ -2032,11 +2083,11 @@ static int prime_status_phase(struct langwell_udc *dev, int dir)
static void set_address(struct langwell_udc *dev, u16 value,
u16 index, u16 length)
{
- VDBG(dev, "---> %s()\n", __func__);
+ dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
/* save the new address to device struct */
dev->dev_addr = (u8) value;
- VDBG(dev, "dev->dev_addr = %d\n", dev->dev_addr);
+ dev_vdbg(&dev->pdev->dev, "dev->dev_addr = %d\n", dev->dev_addr);
/* update usb state */
dev->usb_state = USB_STATE_ADDRESS;
@@ -2045,7 +2096,7 @@ static void set_address(struct langwell_udc *dev, u16 value,
if (prime_status_phase(dev, EP_DIR_IN))
ep0_stall(dev);
- VDBG(dev, "<--- %s()\n", __func__);
+ dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
}
@@ -2054,7 +2105,7 @@ static struct langwell_ep *get_ep_by_windex(struct langwell_udc *dev,
u16 wIndex)
{
struct langwell_ep *ep;
- VDBG(dev, "---> %s()\n", __func__);
+ dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
if ((wIndex & USB_ENDPOINT_NUMBER_MASK) == 0)
return &dev->ep[0];
@@ -2073,7 +2124,7 @@ static struct langwell_ep *get_ep_by_windex(struct langwell_udc *dev,
return ep;
}
- VDBG(dev, "<--- %s()\n", __func__);
+ dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
return NULL;
}
@@ -2085,7 +2136,7 @@ static int ep_is_stall(struct langwell_ep *ep)
u32 endptctrl;
int retval;
- VDBG(dev, "---> %s()\n", __func__);
+ dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
endptctrl = readl(&dev->op_regs->endptctrl[ep->ep_num]);
if (is_in(ep))
@@ -2093,7 +2144,7 @@ static int ep_is_stall(struct langwell_ep *ep)
else
retval = endptctrl & EPCTRL_RXS ? 1 : 0;
- VDBG(dev, "<--- %s()\n", __func__);
+ dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
return retval;
}
@@ -2107,14 +2158,13 @@ static void get_status(struct langwell_udc *dev, u8 request_type, u16 value,
u16 status_data = 0; /* 16 bits cpu view status data */
int status = 0;
- VDBG(dev, "---> %s()\n", __func__);
+ dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
ep = &dev->ep[0];
if ((request_type & USB_RECIP_MASK) == USB_RECIP_DEVICE) {
/* get device status */
- status_data = 1 << USB_DEVICE_SELF_POWERED;
- status_data |= dev->remote_wakeup << USB_DEVICE_REMOTE_WAKEUP;
+ status_data = dev->dev_status;
} else if ((request_type & USB_RECIP_MASK) == USB_RECIP_INTERFACE) {
/* get interface status */
status_data = 0;
@@ -2129,6 +2179,8 @@ static void get_status(struct langwell_udc *dev, u8 request_type, u16 value,
status_data = ep_is_stall(epn) << USB_ENDPOINT_HALT;
}
+ dev_dbg(&dev->pdev->dev, "get status data: 0x%04x\n", status_data);
+
dev->ep0_dir = USB_DIR_IN;
/* borrow the per device status_req */
@@ -2150,18 +2202,19 @@ static void get_status(struct langwell_udc *dev, u8 request_type, u16 value,
goto stall;
if (status) {
- ERROR(dev, "response error on GET_STATUS request\n");
+ dev_err(&dev->pdev->dev,
+ "response error on GET_STATUS request\n");
goto stall;
}
list_add_tail(&req->queue, &ep->queue);
dev->ep0_state = DATA_STATE_XMIT;
- VDBG(dev, "<--- %s()\n", __func__);
+ dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
return;
stall:
ep0_stall(dev);
- VDBG(dev, "<--- %s()\n", __func__);
+ dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
}
@@ -2173,12 +2226,12 @@ static void handle_setup_packet(struct langwell_udc *dev,
u16 wIndex = le16_to_cpu(setup->wIndex);
u16 wLength = le16_to_cpu(setup->wLength);
- VDBG(dev, "---> %s()\n", __func__);
+ dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
/* ep0 fifo flush */
nuke(&dev->ep[0], -ESHUTDOWN);
- DBG(dev, "SETUP %02x.%02x v%04x i%04x l%04x\n",
+ dev_dbg(&dev->pdev->dev, "SETUP %02x.%02x v%04x i%04x l%04x\n",
setup->bRequestType, setup->bRequest,
wValue, wIndex, wLength);
@@ -2197,7 +2250,7 @@ static void handle_setup_packet(struct langwell_udc *dev,
/* We process some stardard setup requests here */
switch (setup->bRequest) {
case USB_REQ_GET_STATUS:
- DBG(dev, "SETUP: USB_REQ_GET_STATUS\n");
+ dev_dbg(&dev->pdev->dev, "SETUP: USB_REQ_GET_STATUS\n");
/* get status, DATA and STATUS phase */
if ((setup->bRequestType & (USB_DIR_IN | USB_TYPE_MASK))
!= (USB_DIR_IN | USB_TYPE_STANDARD))
@@ -2206,7 +2259,7 @@ static void handle_setup_packet(struct langwell_udc *dev,
goto end;
case USB_REQ_SET_ADDRESS:
- DBG(dev, "SETUP: USB_REQ_SET_ADDRESS\n");
+ dev_dbg(&dev->pdev->dev, "SETUP: USB_REQ_SET_ADDRESS\n");
/* STATUS phase */
if (setup->bRequestType != (USB_DIR_OUT | USB_TYPE_STANDARD
| USB_RECIP_DEVICE))
@@ -2220,9 +2273,11 @@ static void handle_setup_packet(struct langwell_udc *dev,
{
int rc = -EOPNOTSUPP;
if (setup->bRequest == USB_REQ_SET_FEATURE)
- DBG(dev, "SETUP: USB_REQ_SET_FEATURE\n");
+ dev_dbg(&dev->pdev->dev,
+ "SETUP: USB_REQ_SET_FEATURE\n");
else if (setup->bRequest == USB_REQ_CLEAR_FEATURE)
- DBG(dev, "SETUP: USB_REQ_CLEAR_FEATURE\n");
+ dev_dbg(&dev->pdev->dev,
+ "SETUP: USB_REQ_CLEAR_FEATURE\n");
if ((setup->bRequestType & (USB_RECIP_MASK | USB_TYPE_MASK))
== (USB_RECIP_ENDPOINT | USB_TYPE_STANDARD)) {
@@ -2240,13 +2295,29 @@ static void handle_setup_packet(struct langwell_udc *dev,
spin_unlock(&dev->lock);
rc = langwell_ep_set_halt(&epn->ep,
- (setup->bRequest == USB_REQ_SET_FEATURE)
- ? 1 : 0);
+ (setup->bRequest == USB_REQ_SET_FEATURE)
+ ? 1 : 0);
spin_lock(&dev->lock);
} else if ((setup->bRequestType & (USB_RECIP_MASK
| USB_TYPE_MASK)) == (USB_RECIP_DEVICE
| USB_TYPE_STANDARD)) {
+ rc = 0;
+ switch (wValue) {
+ case USB_DEVICE_REMOTE_WAKEUP:
+ if (setup->bRequest == USB_REQ_SET_FEATURE) {
+ dev->remote_wakeup = 1;
+ dev->dev_status |= (1 << wValue);
+ } else {
+ dev->remote_wakeup = 0;
+ dev->dev_status &= ~(1 << wValue);
+ }
+ break;
+ default:
+ rc = -EOPNOTSUPP;
+ break;
+ }
+
if (!gadget_is_otg(&dev->gadget))
break;
else if (setup->bRequest == USB_DEVICE_B_HNP_ENABLE) {
@@ -2262,7 +2333,6 @@ static void handle_setup_packet(struct langwell_udc *dev,
dev->gadget.a_alt_hnp_support = 1;
else
break;
- rc = 0;
} else
break;
@@ -2274,31 +2344,38 @@ static void handle_setup_packet(struct langwell_udc *dev,
}
case USB_REQ_GET_DESCRIPTOR:
- DBG(dev, "SETUP: USB_REQ_GET_DESCRIPTOR\n");
+ dev_dbg(&dev->pdev->dev,
+ "SETUP: USB_REQ_GET_DESCRIPTOR\n");
goto delegate;
case USB_REQ_SET_DESCRIPTOR:
- DBG(dev, "SETUP: USB_REQ_SET_DESCRIPTOR unsupported\n");
+ dev_dbg(&dev->pdev->dev,
+ "SETUP: USB_REQ_SET_DESCRIPTOR unsupported\n");
goto delegate;
case USB_REQ_GET_CONFIGURATION:
- DBG(dev, "SETUP: USB_REQ_GET_CONFIGURATION\n");
+ dev_dbg(&dev->pdev->dev,
+ "SETUP: USB_REQ_GET_CONFIGURATION\n");
goto delegate;
case USB_REQ_SET_CONFIGURATION:
- DBG(dev, "SETUP: USB_REQ_SET_CONFIGURATION\n");
+ dev_dbg(&dev->pdev->dev,
+ "SETUP: USB_REQ_SET_CONFIGURATION\n");
goto delegate;
case USB_REQ_GET_INTERFACE:
- DBG(dev, "SETUP: USB_REQ_GET_INTERFACE\n");
+ dev_dbg(&dev->pdev->dev,
+ "SETUP: USB_REQ_GET_INTERFACE\n");
goto delegate;
case USB_REQ_SET_INTERFACE:
- DBG(dev, "SETUP: USB_REQ_SET_INTERFACE\n");
+ dev_dbg(&dev->pdev->dev,
+ "SETUP: USB_REQ_SET_INTERFACE\n");
goto delegate;
case USB_REQ_SYNCH_FRAME:
- DBG(dev, "SETUP: USB_REQ_SYNCH_FRAME unsupported\n");
+ dev_dbg(&dev->pdev->dev,
+ "SETUP: USB_REQ_SYNCH_FRAME unsupported\n");
goto delegate;
default:
@@ -2310,7 +2387,8 @@ delegate:
/* DATA phase from gadget, STATUS phase from udc */
dev->ep0_dir = (setup->bRequestType & USB_DIR_IN)
? USB_DIR_IN : USB_DIR_OUT;
- VDBG(dev, "dev->ep0_dir = 0x%x, wLength = %d\n",
+ dev_vdbg(&dev->pdev->dev,
+ "dev->ep0_dir = 0x%x, wLength = %d\n",
dev->ep0_dir, wLength);
spin_unlock(&dev->lock);
if (dev->driver->setup(&dev->gadget,
@@ -2322,7 +2400,8 @@ delegate:
} else {
/* no DATA phase, IN STATUS phase from gadget */
dev->ep0_dir = USB_DIR_IN;
- VDBG(dev, "dev->ep0_dir = 0x%x, wLength = %d\n",
+ dev_vdbg(&dev->pdev->dev,
+ "dev->ep0_dir = 0x%x, wLength = %d\n",
dev->ep0_dir, wLength);
spin_unlock(&dev->lock);
if (dev->driver->setup(&dev->gadget,
@@ -2334,8 +2413,7 @@ delegate:
break;
}
end:
- VDBG(dev, "<--- %s()\n", __func__);
- return;
+ dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
}
@@ -2359,23 +2437,27 @@ static int process_ep_req(struct langwell_udc *dev, int index,
td_complete = 0;
actual = curr_req->req.length;
- VDBG(dev, "---> %s()\n", __func__);
+ dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
for (i = 0; i < curr_req->dtd_count; i++) {
- remaining_length = le16_to_cpu(curr_dtd->dtd_total);
- actual -= remaining_length;
/* command execution states by dTD */
dtd_status = curr_dtd->dtd_status;
+ barrier();
+ remaining_length = le16_to_cpu(curr_dtd->dtd_total);
+ actual -= remaining_length;
+
if (!dtd_status) {
/* transfers completed successfully */
if (!remaining_length) {
td_complete++;
- VDBG(dev, "dTD transmitted successfully\n");
+ dev_vdbg(&dev->pdev->dev,
+ "dTD transmitted successfully\n");
} else {
if (dir) {
- VDBG(dev, "TX dTD remains data\n");
+ dev_vdbg(&dev->pdev->dev,
+ "TX dTD remains data\n");
retval = -EPROTO;
break;
@@ -2387,27 +2469,32 @@ static int process_ep_req(struct langwell_udc *dev, int index,
} else {
/* transfers completed with errors */
if (dtd_status & DTD_STS_ACTIVE) {
- DBG(dev, "request not completed\n");
+ dev_dbg(&dev->pdev->dev,
+ "dTD status ACTIVE dQH[%d]\n", index);
retval = 1;
return retval;
} else if (dtd_status & DTD_STS_HALTED) {
- ERROR(dev, "dTD error %08x dQH[%d]\n",
- dtd_status, index);
+ dev_err(&dev->pdev->dev,
+ "dTD error %08x dQH[%d]\n",
+ dtd_status, index);
/* clear the errors and halt condition */
curr_dqh->dtd_status = 0;
retval = -EPIPE;
break;
} else if (dtd_status & DTD_STS_DBE) {
- DBG(dev, "data buffer (overflow) error\n");
+ dev_dbg(&dev->pdev->dev,
+ "data buffer (overflow) error\n");
retval = -EPROTO;
break;
} else if (dtd_status & DTD_STS_TRE) {
- DBG(dev, "transaction(ISO) error\n");
+ dev_dbg(&dev->pdev->dev,
+ "transaction(ISO) error\n");
retval = -EILSEQ;
break;
} else
- ERROR(dev, "unknown error (0x%x)!\n",
- dtd_status);
+ dev_err(&dev->pdev->dev,
+ "unknown error (0x%x)!\n",
+ dtd_status);
}
if (i != curr_req->dtd_count - 1)
@@ -2420,7 +2507,7 @@ static int process_ep_req(struct langwell_udc *dev, int index,
curr_req->req.actual = actual;
- VDBG(dev, "<--- %s()\n", __func__);
+ dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
return 0;
}
@@ -2430,7 +2517,7 @@ static void ep0_req_complete(struct langwell_udc *dev,
struct langwell_ep *ep0, struct langwell_request *req)
{
u32 new_addr;
- VDBG(dev, "---> %s()\n", __func__);
+ dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
if (dev->usb_state == USB_STATE_ADDRESS) {
/* set the new address */
@@ -2438,7 +2525,7 @@ static void ep0_req_complete(struct langwell_udc *dev,
writel(new_addr << USBADR_SHIFT, &dev->op_regs->deviceaddr);
new_addr = USBADR(readl(&dev->op_regs->deviceaddr));
- VDBG(dev, "new_addr = %d\n", new_addr);
+ dev_vdbg(&dev->pdev->dev, "new_addr = %d\n", new_addr);
}
done(ep0, req, 0);
@@ -2458,14 +2545,14 @@ static void ep0_req_complete(struct langwell_udc *dev,
dev->ep0_state = WAIT_FOR_SETUP;
break;
case WAIT_FOR_SETUP:
- ERROR(dev, "unexpect ep0 packets\n");
+ dev_err(&dev->pdev->dev, "unexpect ep0 packets\n");
break;
default:
ep0_stall(dev);
break;
}
- VDBG(dev, "<--- %s()\n", __func__);
+ dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
}
@@ -2477,16 +2564,17 @@ static void handle_trans_complete(struct langwell_udc *dev)
struct langwell_ep *epn;
struct langwell_request *curr_req, *temp_req;
- VDBG(dev, "---> %s()\n", __func__);
+ dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
complete_bits = readl(&dev->op_regs->endptcomplete);
- VDBG(dev, "endptcomplete register: 0x%08x\n", complete_bits);
+ dev_vdbg(&dev->pdev->dev, "endptcomplete register: 0x%08x\n",
+ complete_bits);
/* Write-Clear the bits in endptcomplete register */
writel(complete_bits, &dev->op_regs->endptcomplete);
if (!complete_bits) {
- DBG(dev, "complete_bits = 0\n");
+ dev_dbg(&dev->pdev->dev, "complete_bits = 0\n");
goto done;
}
@@ -2506,23 +2594,25 @@ static void handle_trans_complete(struct langwell_udc *dev)
epn = &dev->ep[i];
if (epn->name == NULL) {
- WARNING(dev, "invalid endpoint\n");
+ dev_warn(&dev->pdev->dev, "invalid endpoint\n");
continue;
}
if (i < 2)
/* ep0 in and out */
- DBG(dev, "%s-%s transfer completed\n",
+ dev_dbg(&dev->pdev->dev, "%s-%s transfer completed\n",
epn->name,
is_in(epn) ? "in" : "out");
else
- DBG(dev, "%s transfer completed\n", epn->name);
+ dev_dbg(&dev->pdev->dev, "%s transfer completed\n",
+ epn->name);
/* process the req queue until an uncomplete request */
list_for_each_entry_safe(curr_req, temp_req,
&epn->queue, queue) {
status = process_ep_req(dev, i, curr_req);
- VDBG(dev, "%s req status: %d\n", epn->name, status);
+ dev_vdbg(&dev->pdev->dev, "%s req status: %d\n",
+ epn->name, status);
if (status)
break;
@@ -2540,8 +2630,7 @@ static void handle_trans_complete(struct langwell_udc *dev)
}
}
done:
- VDBG(dev, "<--- %s()\n", __func__);
- return;
+ dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
}
@@ -2551,14 +2640,14 @@ static void handle_port_change(struct langwell_udc *dev)
u32 portsc1, devlc;
u32 speed;
- VDBG(dev, "---> %s()\n", __func__);
+ dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
if (dev->bus_reset)
dev->bus_reset = 0;
portsc1 = readl(&dev->op_regs->portsc1);
devlc = readl(&dev->op_regs->devlc);
- VDBG(dev, "portsc1 = 0x%08x, devlc = 0x%08x\n",
+ dev_vdbg(&dev->pdev->dev, "portsc1 = 0x%08x, devlc = 0x%08x\n",
portsc1, devlc);
/* bus reset is finished */
@@ -2579,25 +2668,22 @@ static void handle_port_change(struct langwell_udc *dev)
dev->gadget.speed = USB_SPEED_UNKNOWN;
break;
}
- VDBG(dev, "speed = %d, dev->gadget.speed = %d\n",
+ dev_vdbg(&dev->pdev->dev,
+ "speed = %d, dev->gadget.speed = %d\n",
speed, dev->gadget.speed);
}
/* LPM L0 to L1 */
if (dev->lpm && dev->lpm_state == LPM_L0)
if (portsc1 & PORTS_SUSP && portsc1 & PORTS_SLP) {
- INFO(dev, "LPM L0 to L1\n");
- dev->lpm_state = LPM_L1;
+ dev_info(&dev->pdev->dev, "LPM L0 to L1\n");
+ dev->lpm_state = LPM_L1;
}
/* LPM L1 to L0, force resume or remote wakeup finished */
if (dev->lpm && dev->lpm_state == LPM_L1)
if (!(portsc1 & PORTS_SUSP)) {
- if (portsc1 & PORTS_SLP)
- INFO(dev, "LPM L1 to L0, force resume\n");
- else
- INFO(dev, "LPM L1 to L0, remote wakeup\n");
-
+ dev_info(&dev->pdev->dev, "LPM L1 to L0\n");
dev->lpm_state = LPM_L0;
}
@@ -2605,7 +2691,7 @@ static void handle_port_change(struct langwell_udc *dev)
if (!dev->resume_state)
dev->usb_state = USB_STATE_DEFAULT;
- VDBG(dev, "<--- %s()\n", __func__);
+ dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
}
@@ -2617,7 +2703,7 @@ static void handle_usb_reset(struct langwell_udc *dev)
endptcomplete;
unsigned long timeout;
- VDBG(dev, "---> %s()\n", __func__);
+ dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
/* Write-Clear the device address */
deviceaddr = readl(&dev->op_regs->deviceaddr);
@@ -2634,7 +2720,10 @@ static void handle_usb_reset(struct langwell_udc *dev)
dev->ep0_dir = USB_DIR_OUT;
dev->ep0_state = WAIT_FOR_SETUP;
- dev->remote_wakeup = 0; /* default to 0 on reset */
+
+ /* remote wakeup reset to 0 when the device is reset */
+ dev->remote_wakeup = 0;
+ dev->dev_status = 1 << USB_DEVICE_SELF_POWERED;
dev->gadget.b_hnp_enable = 0;
dev->gadget.a_hnp_support = 0;
dev->gadget.a_alt_hnp_support = 0;
@@ -2651,7 +2740,7 @@ static void handle_usb_reset(struct langwell_udc *dev)
timeout = jiffies + PRIME_TIMEOUT;
while (readl(&dev->op_regs->endptprime)) {
if (time_after(jiffies, timeout)) {
- ERROR(dev, "USB reset timeout\n");
+ dev_err(&dev->pdev->dev, "USB reset timeout\n");
break;
}
cpu_relax();
@@ -2661,7 +2750,7 @@ static void handle_usb_reset(struct langwell_udc *dev)
writel((u32) ~0, &dev->op_regs->endptflush);
if (readl(&dev->op_regs->portsc1) & PORTS_PR) {
- VDBG(dev, "USB bus reset\n");
+ dev_vdbg(&dev->pdev->dev, "USB bus reset\n");
/* bus is reseting */
dev->bus_reset = 1;
@@ -2669,7 +2758,7 @@ static void handle_usb_reset(struct langwell_udc *dev)
stop_activity(dev, dev->driver);
dev->usb_state = USB_STATE_DEFAULT;
} else {
- VDBG(dev, "device controller reset\n");
+ dev_vdbg(&dev->pdev->dev, "device controller reset\n");
/* controller reset */
langwell_udc_reset(dev);
@@ -2691,15 +2780,14 @@ static void handle_usb_reset(struct langwell_udc *dev)
dev->lotg->hsm.b_hnp_enable = 0;
#endif
- VDBG(dev, "<--- %s()\n", __func__);
+ dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
}
/* USB bus suspend/resume interrupt */
static void handle_bus_suspend(struct langwell_udc *dev)
{
- u32 devlc;
- DBG(dev, "---> %s()\n", __func__);
+ dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__);
dev->resume_state = dev->usb_state;
dev->usb_state = USB_STATE_SUSPENDED;
@@ -2733,33 +2821,29 @@ static void handle_bus_suspend(struct langwell_udc *dev)
spin_unlock(&dev->lock);
dev->driver->suspend(&dev->gadget);
spin_lock(&dev->lock);
- DBG(dev, "suspend %s\n", dev->driver->driver.name);
+ dev_dbg(&dev->pdev->dev, "suspend %s\n",
+ dev->driver->driver.name);
}
}
/* enter 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);
- DBG(dev, "<--- %s()\n", __func__);
+ dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__);
}
static void handle_bus_resume(struct langwell_udc *dev)
{
- u32 devlc;
- DBG(dev, "---> %s()\n", __func__);
+ dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__);
dev->usb_state = dev->resume_state;
dev->resume_state = 0;
/* 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);
#ifdef OTG_TRANSCEIVER
if (dev->lotg->otg.default_a == 0)
@@ -2772,11 +2856,12 @@ static void handle_bus_resume(struct langwell_udc *dev)
spin_unlock(&dev->lock);
dev->driver->resume(&dev->gadget);
spin_lock(&dev->lock);
- DBG(dev, "resume %s\n", dev->driver->driver.name);
+ dev_dbg(&dev->pdev->dev, "resume %s\n",
+ dev->driver->driver.name);
}
}
- DBG(dev, "<--- %s()\n", __func__);
+ dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__);
}
@@ -2789,11 +2874,11 @@ static irqreturn_t langwell_irq(int irq, void *_dev)
irq_sts,
portsc1;
- VDBG(dev, "---> %s()\n", __func__);
+ dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
if (dev->stopped) {
- VDBG(dev, "handle IRQ_NONE\n");
- VDBG(dev, "<--- %s()\n", __func__);
+ dev_vdbg(&dev->pdev->dev, "handle IRQ_NONE\n");
+ dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
return IRQ_NONE;
}
@@ -2806,12 +2891,13 @@ static irqreturn_t langwell_irq(int irq, void *_dev)
usbintr = readl(&dev->op_regs->usbintr);
irq_sts = usbsts & usbintr;
- VDBG(dev, "usbsts = 0x%08x, usbintr = 0x%08x, irq_sts = 0x%08x\n",
+ dev_vdbg(&dev->pdev->dev,
+ "usbsts = 0x%08x, usbintr = 0x%08x, irq_sts = 0x%08x\n",
usbsts, usbintr, irq_sts);
if (!irq_sts) {
- VDBG(dev, "handle IRQ_NONE\n");
- VDBG(dev, "<--- %s()\n", __func__);
+ dev_vdbg(&dev->pdev->dev, "handle IRQ_NONE\n");
+ dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
spin_unlock(&dev->lock);
return IRQ_NONE;
}
@@ -2827,12 +2913,13 @@ static irqreturn_t langwell_irq(int irq, void *_dev)
/* USB interrupt */
if (irq_sts & STS_UI) {
- VDBG(dev, "USB interrupt\n");
+ dev_vdbg(&dev->pdev->dev, "USB interrupt\n");
/* setup packet received from ep0 */
if (readl(&dev->op_regs->endptsetupstat)
& EP0SETUPSTAT_MASK) {
- VDBG(dev, "USB SETUP packet received interrupt\n");
+ dev_vdbg(&dev->pdev->dev,
+ "USB SETUP packet received interrupt\n");
/* setup tripwire semaphone */
setup_tripwire(dev);
handle_setup_packet(dev, &dev->local_setup_buff);
@@ -2840,7 +2927,8 @@ static irqreturn_t langwell_irq(int irq, void *_dev)
/* USB transfer completion */
if (readl(&dev->op_regs->endptcomplete)) {
- VDBG(dev, "USB transfer completion interrupt\n");
+ dev_vdbg(&dev->pdev->dev,
+ "USB transfer completion interrupt\n");
handle_trans_complete(dev);
}
}
@@ -2848,36 +2936,36 @@ static irqreturn_t langwell_irq(int irq, void *_dev)
/* SOF received interrupt (for ISO transfer) */
if (irq_sts & STS_SRI) {
/* FIXME */
- /* VDBG(dev, "SOF received interrupt\n"); */
+ /* dev_vdbg(&dev->pdev->dev, "SOF received interrupt\n"); */
}
/* port change detect interrupt */
if (irq_sts & STS_PCI) {
- VDBG(dev, "port change detect interrupt\n");
+ dev_vdbg(&dev->pdev->dev, "port change detect interrupt\n");
handle_port_change(dev);
}
/* suspend interrrupt */
if (irq_sts & STS_SLI) {
- VDBG(dev, "suspend interrupt\n");
+ dev_vdbg(&dev->pdev->dev, "suspend interrupt\n");
handle_bus_suspend(dev);
}
/* USB reset interrupt */
if (irq_sts & STS_URI) {
- VDBG(dev, "USB reset interrupt\n");
+ dev_vdbg(&dev->pdev->dev, "USB reset interrupt\n");
handle_usb_reset(dev);
}
/* USB error or system error interrupt */
if (irq_sts & (STS_UEI | STS_SEI)) {
/* FIXME */
- WARNING(dev, "error IRQ, irq_sts: %x\n", irq_sts);
+ dev_warn(&dev->pdev->dev, "error IRQ, irq_sts: %x\n", irq_sts);
}
spin_unlock(&dev->lock);
- VDBG(dev, "<--- %s()\n", __func__);
+ dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
return IRQ_HANDLED;
}
@@ -2889,15 +2977,59 @@ static void gadget_release(struct device *_dev)
{
struct langwell_udc *dev = the_controller;
- DBG(dev, "---> %s()\n", __func__);
+ dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__);
complete(dev->done);
- DBG(dev, "<--- %s()\n", __func__);
+ dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__);
kfree(dev);
}
+/* enable SRAM caching if SRAM detected */
+static void sram_init(struct langwell_udc *dev)
+{
+ struct pci_dev *pdev = dev->pdev;
+
+ dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__);
+
+ dev->sram_addr = pci_resource_start(pdev, 1);
+ dev->sram_size = pci_resource_len(pdev, 1);
+ dev_info(&dev->pdev->dev, "Found private SRAM at %x size:%x\n",
+ dev->sram_addr, dev->sram_size);
+ dev->got_sram = 1;
+
+ if (pci_request_region(pdev, 1, kobject_name(&pdev->dev.kobj))) {
+ dev_warn(&dev->pdev->dev, "SRAM request failed\n");
+ dev->got_sram = 0;
+ } else if (!dma_declare_coherent_memory(&pdev->dev, dev->sram_addr,
+ dev->sram_addr, dev->sram_size, DMA_MEMORY_MAP)) {
+ dev_warn(&dev->pdev->dev, "SRAM DMA declare failed\n");
+ pci_release_region(pdev, 1);
+ dev->got_sram = 0;
+ }
+
+ dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__);
+}
+
+
+/* release SRAM caching */
+static void sram_deinit(struct langwell_udc *dev)
+{
+ struct pci_dev *pdev = dev->pdev;
+
+ dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__);
+
+ dma_release_declared_memory(&pdev->dev);
+ pci_release_region(pdev, 1);
+
+ dev->got_sram = 0;
+
+ dev_info(&dev->pdev->dev, "release SRAM caching\n");
+ dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__);
+}
+
+
/* tear down the binding between this driver and the pci device */
static void langwell_udc_remove(struct pci_dev *pdev)
{
@@ -2906,23 +3038,29 @@ static void langwell_udc_remove(struct pci_dev *pdev)
DECLARE_COMPLETION(done);
BUG_ON(dev->driver);
- DBG(dev, "---> %s()\n", __func__);
+ dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__);
dev->done = &done;
- /* free memory allocated in probe */
+#ifndef OTG_TRANSCEIVER
+ /* free dTD dma_pool and dQH */
if (dev->dtd_pool)
dma_pool_destroy(dev->dtd_pool);
+ if (dev->ep_dqh)
+ dma_free_coherent(&pdev->dev, dev->ep_dqh_size,
+ dev->ep_dqh, dev->ep_dqh_dma);
+
+ /* release SRAM caching */
+ if (dev->has_sram && dev->got_sram)
+ sram_deinit(dev);
+#endif
+
if (dev->status_req) {
kfree(dev->status_req->req.buf);
kfree(dev->status_req);
}
- if (dev->ep_dqh)
- dma_free_coherent(&pdev->dev, dev->ep_dqh_size,
- dev->ep_dqh, dev->ep_dqh_dma);
-
kfree(dev->ep);
/* diable IRQ handler */
@@ -2949,11 +3087,12 @@ static void langwell_udc_remove(struct pci_dev *pdev)
dev->cap_regs = NULL;
- INFO(dev, "unbind\n");
- DBG(dev, "<--- %s()\n", __func__);
+ dev_info(&dev->pdev->dev, "unbind\n");
+ dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__);
device_unregister(&dev->gadget.dev);
device_remove_file(&pdev->dev, &dev_attr_langwell_udc);
+ device_remove_file(&pdev->dev, &dev_attr_remote_wakeup);
#ifndef OTG_TRANSCEIVER
pci_set_drvdata(pdev, NULL);
@@ -2997,7 +3136,7 @@ static int langwell_udc_probe(struct pci_dev *pdev,
spin_lock_init(&dev->lock);
dev->pdev = pdev;
- DBG(dev, "---> %s()\n", __func__);
+ dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__);
#ifdef OTG_TRANSCEIVER
/* PCI device is already enabled by otg_transceiver driver */
@@ -3022,7 +3161,7 @@ static int langwell_udc_probe(struct pci_dev *pdev,
resource = pci_resource_start(pdev, 0);
len = pci_resource_len(pdev, 0);
if (!request_mem_region(resource, len, driver_name)) {
- ERROR(dev, "controller already in use\n");
+ dev_err(&dev->pdev->dev, "controller already in use\n");
retval = -EBUSY;
goto error;
}
@@ -3031,33 +3170,43 @@ static int langwell_udc_probe(struct pci_dev *pdev,
base = ioremap_nocache(resource, len);
#endif
if (base == NULL) {
- ERROR(dev, "can't map memory\n");
+ dev_err(&dev->pdev->dev, "can't map memory\n");
retval = -EFAULT;
goto error;
}
dev->cap_regs = (struct langwell_cap_regs __iomem *) base;
- VDBG(dev, "dev->cap_regs: %p\n", dev->cap_regs);
+ dev_vdbg(&dev->pdev->dev, "dev->cap_regs: %p\n", dev->cap_regs);
dev->op_regs = (struct langwell_op_regs __iomem *)
(base + OP_REG_OFFSET);
- VDBG(dev, "dev->op_regs: %p\n", dev->op_regs);
+ dev_vdbg(&dev->pdev->dev, "dev->op_regs: %p\n", dev->op_regs);
/* irq setup after old hardware is cleaned up */
if (!pdev->irq) {
- ERROR(dev, "No IRQ. Check PCI setup!\n");
+ dev_err(&dev->pdev->dev, "No IRQ. Check PCI setup!\n");
retval = -ENODEV;
goto error;
}
+ dev->has_sram = 1;
+ dev->got_sram = 0;
+ dev_vdbg(&dev->pdev->dev, "dev->has_sram: %d\n", dev->has_sram);
+
#ifndef OTG_TRANSCEIVER
- INFO(dev, "irq %d, io mem: 0x%08lx, len: 0x%08lx, pci mem 0x%p\n",
+ /* enable SRAM caching if detected */
+ if (dev->has_sram && !dev->got_sram)
+ sram_init(dev);
+
+ dev_info(&dev->pdev->dev,
+ "irq %d, io mem: 0x%08lx, len: 0x%08lx, pci mem 0x%p\n",
pdev->irq, resource, len, base);
/* enables bus-mastering for device dev */
pci_set_master(pdev);
if (request_irq(pdev->irq, langwell_irq, IRQF_SHARED,
driver_name, dev) != 0) {
- ERROR(dev, "request interrupt %d failed\n", pdev->irq);
+ dev_err(&dev->pdev->dev,
+ "request interrupt %d failed\n", pdev->irq);
retval = -EBUSY;
goto error;
}
@@ -3071,32 +3220,34 @@ static int langwell_udc_probe(struct pci_dev *pdev,
dev->lpm = (readl(&dev->cap_regs->hccparams) & HCC_LEN) ? 1 : 0;
dev->dciversion = readw(&dev->cap_regs->dciversion);
dev->devcap = (readl(&dev->cap_regs->dccparams) & DEVCAP) ? 1 : 0;
- VDBG(dev, "dev->lpm: %d\n", dev->lpm);
- VDBG(dev, "dev->dciversion: 0x%04x\n", dev->dciversion);
- VDBG(dev, "dccparams: 0x%08x\n", readl(&dev->cap_regs->dccparams));
- VDBG(dev, "dev->devcap: %d\n", dev->devcap);
+ dev_vdbg(&dev->pdev->dev, "dev->lpm: %d\n", dev->lpm);
+ dev_vdbg(&dev->pdev->dev, "dev->dciversion: 0x%04x\n",
+ dev->dciversion);
+ dev_vdbg(&dev->pdev->dev, "dccparams: 0x%08x\n",
+ readl(&dev->cap_regs->dccparams));
+ dev_vdbg(&dev->pdev->dev, "dev->devcap: %d\n", dev->devcap);
if (!dev->devcap) {
- ERROR(dev, "can't support device mode\n");
+ dev_err(&dev->pdev->dev, "can't support device mode\n");
retval = -ENODEV;
goto error;
}
/* a pair of endpoints (out/in) for each address */
dev->ep_max = DEN(readl(&dev->cap_regs->dccparams)) * 2;
- VDBG(dev, "dev->ep_max: %d\n", dev->ep_max);
+ dev_vdbg(&dev->pdev->dev, "dev->ep_max: %d\n", dev->ep_max);
/* allocate endpoints memory */
dev->ep = kzalloc(sizeof(struct langwell_ep) * dev->ep_max,
GFP_KERNEL);
if (!dev->ep) {
- ERROR(dev, "allocate endpoints memory failed\n");
+ dev_err(&dev->pdev->dev, "allocate endpoints memory failed\n");
retval = -ENOMEM;
goto error;
}
/* allocate device dQH memory */
size = dev->ep_max * sizeof(struct langwell_dqh);
- VDBG(dev, "orig size = %d\n", size);
+ dev_vdbg(&dev->pdev->dev, "orig size = %d\n", size);
if (size < DQH_ALIGNMENT)
size = DQH_ALIGNMENT;
else if ((size % DQH_ALIGNMENT) != 0) {
@@ -3106,17 +3257,18 @@ static int langwell_udc_probe(struct pci_dev *pdev,
dev->ep_dqh = dma_alloc_coherent(&pdev->dev, size,
&dev->ep_dqh_dma, GFP_KERNEL);
if (!dev->ep_dqh) {
- ERROR(dev, "allocate dQH memory failed\n");
+ dev_err(&dev->pdev->dev, "allocate dQH memory failed\n");
retval = -ENOMEM;
goto error;
}
dev->ep_dqh_size = size;
- VDBG(dev, "ep_dqh_size = %d\n", dev->ep_dqh_size);
+ dev_vdbg(&dev->pdev->dev, "ep_dqh_size = %d\n", dev->ep_dqh_size);
/* initialize ep0 status request structure */
dev->status_req = kzalloc(sizeof(struct langwell_request), GFP_KERNEL);
if (!dev->status_req) {
- ERROR(dev, "allocate status_req memory failed\n");
+ dev_err(&dev->pdev->dev,
+ "allocate status_req memory failed\n");
retval = -ENOMEM;
goto error;
}
@@ -3129,7 +3281,10 @@ static int langwell_udc_probe(struct pci_dev *pdev,
dev->resume_state = USB_STATE_NOTATTACHED;
dev->usb_state = USB_STATE_POWERED;
dev->ep0_dir = USB_DIR_OUT;
- dev->remote_wakeup = 0; /* default to 0 on reset */
+
+ /* remote wakeup reset to 0 when the device is reset */
+ dev->remote_wakeup = 0;
+ dev->dev_status = 1 << USB_DEVICE_SELF_POWERED;
#ifndef OTG_TRANSCEIVER
/* reset device controller */
@@ -3174,18 +3329,20 @@ static int langwell_udc_probe(struct pci_dev *pdev,
}
/* done */
- INFO(dev, "%s\n", driver_desc);
- INFO(dev, "irq %d, pci mem %p\n", pdev->irq, base);
- INFO(dev, "Driver version: " DRIVER_VERSION "\n");
- INFO(dev, "Support (max) %d endpoints\n", dev->ep_max);
- INFO(dev, "Device interface version: 0x%04x\n", dev->dciversion);
- INFO(dev, "Controller mode: %s\n", dev->devcap ? "Device" : "Host");
- INFO(dev, "Support USB LPM: %s\n", dev->lpm ? "Yes" : "No");
-
- VDBG(dev, "After langwell_udc_probe(), print all registers:\n");
-#ifdef VERBOSE
+ dev_info(&dev->pdev->dev, "%s\n", driver_desc);
+ dev_info(&dev->pdev->dev, "irq %d, pci mem %p\n", pdev->irq, base);
+ dev_info(&dev->pdev->dev, "Driver version: " DRIVER_VERSION "\n");
+ dev_info(&dev->pdev->dev, "Support (max) %d endpoints\n", dev->ep_max);
+ dev_info(&dev->pdev->dev, "Device interface version: 0x%04x\n",
+ dev->dciversion);
+ dev_info(&dev->pdev->dev, "Controller mode: %s\n",
+ dev->devcap ? "Device" : "Host");
+ dev_info(&dev->pdev->dev, "Support USB LPM: %s\n",
+ dev->lpm ? "Yes" : "No");
+
+ dev_vdbg(&dev->pdev->dev,
+ "After langwell_udc_probe(), print all registers:\n");
print_all_registers(dev);
-#endif
the_controller = dev;
@@ -3197,12 +3354,18 @@ static int langwell_udc_probe(struct pci_dev *pdev,
if (retval)
goto error;
- VDBG(dev, "<--- %s()\n", __func__);
+ retval = device_create_file(&pdev->dev, &dev_attr_remote_wakeup);
+ if (retval)
+ goto error_attr1;
+
+ dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
return 0;
+error_attr1:
+ device_remove_file(&pdev->dev, &dev_attr_langwell_udc);
error:
if (dev) {
- DBG(dev, "<--- %s()\n", __func__);
+ dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__);
langwell_udc_remove(pdev);
}
@@ -3214,9 +3377,8 @@ error:
static int langwell_udc_suspend(struct pci_dev *pdev, pm_message_t state)
{
struct langwell_udc *dev = the_controller;
- u32 devlc;
- DBG(dev, "---> %s()\n", __func__);
+ dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__);
/* disable interrupt and set controller to stop state */
langwell_udc_stop(dev);
@@ -3226,20 +3388,34 @@ static int langwell_udc_suspend(struct pci_dev *pdev, pm_message_t state)
free_irq(pdev->irq, dev);
dev->got_irq = 0;
-
/* save PCI state */
pci_save_state(pdev);
+ spin_lock_irq(&dev->lock);
+ /* stop all usb activities */
+ stop_activity(dev, dev->driver);
+ spin_unlock_irq(&dev->lock);
+
+ /* free dTD dma_pool and dQH */
+ if (dev->dtd_pool)
+ dma_pool_destroy(dev->dtd_pool);
+
+ if (dev->ep_dqh)
+ dma_free_coherent(&pdev->dev, dev->ep_dqh_size,
+ dev->ep_dqh, dev->ep_dqh_dma);
+
+ /* release SRAM caching */
+ if (dev->has_sram && dev->got_sram)
+ sram_deinit(dev);
+
/* set device power state */
pci_set_power_state(pdev, PCI_D3hot);
/* enter 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, 1);
- DBG(dev, "<--- %s()\n", __func__);
+ dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__);
return 0;
}
@@ -3248,27 +3424,58 @@ static int langwell_udc_suspend(struct pci_dev *pdev, pm_message_t state)
static int langwell_udc_resume(struct pci_dev *pdev)
{
struct langwell_udc *dev = the_controller;
- u32 devlc;
+ size_t size;
- DBG(dev, "---> %s()\n", __func__);
+ dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__);
/* 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);
/* set device D0 power state */
pci_set_power_state(pdev, PCI_D0);
+ /* enable SRAM caching if detected */
+ if (dev->has_sram && !dev->got_sram)
+ sram_init(dev);
+
+ /* allocate device dQH memory */
+ size = dev->ep_max * sizeof(struct langwell_dqh);
+ dev_vdbg(&dev->pdev->dev, "orig size = %d\n", size);
+ if (size < DQH_ALIGNMENT)
+ size = DQH_ALIGNMENT;
+ else if ((size % DQH_ALIGNMENT) != 0) {
+ size += DQH_ALIGNMENT + 1;
+ size &= ~(DQH_ALIGNMENT - 1);
+ }
+ dev->ep_dqh = dma_alloc_coherent(&pdev->dev, size,
+ &dev->ep_dqh_dma, GFP_KERNEL);
+ if (!dev->ep_dqh) {
+ dev_err(&dev->pdev->dev, "allocate dQH memory failed\n");
+ return -ENOMEM;
+ }
+ dev->ep_dqh_size = size;
+ dev_vdbg(&dev->pdev->dev, "ep_dqh_size = %d\n", dev->ep_dqh_size);
+
+ /* create dTD dma_pool resource */
+ dev->dtd_pool = dma_pool_create("langwell_dtd",
+ &dev->pdev->dev,
+ sizeof(struct langwell_dtd),
+ DTD_ALIGNMENT,
+ DMA_BOUNDARY);
+
+ if (!dev->dtd_pool)
+ return -ENOMEM;
+
/* restore PCI state */
pci_restore_state(pdev);
/* enable IRQ handler */
- if (request_irq(pdev->irq, langwell_irq, IRQF_SHARED, driver_name, dev)
- != 0) {
- ERROR(dev, "request interrupt %d failed\n", pdev->irq);
- return -1;
+ if (request_irq(pdev->irq, langwell_irq, IRQF_SHARED,
+ driver_name, dev) != 0) {
+ dev_err(&dev->pdev->dev, "request interrupt %d failed\n",
+ pdev->irq);
+ return -EBUSY;
}
dev->got_irq = 1;
@@ -3290,7 +3497,7 @@ static int langwell_udc_resume(struct pci_dev *pdev)
dev->ep0_state = WAIT_FOR_SETUP;
dev->ep0_dir = USB_DIR_OUT;
- DBG(dev, "<--- %s()\n", __func__);
+ dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__);
return 0;
}
@@ -3301,15 +3508,15 @@ static void langwell_udc_shutdown(struct pci_dev *pdev)
struct langwell_udc *dev = the_controller;
u32 usbmode;
- DBG(dev, "---> %s()\n", __func__);
+ dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__);
/* reset controller mode to IDLE */
usbmode = readl(&dev->op_regs->usbmode);
- DBG(dev, "usbmode = 0x%08x\n", usbmode);
+ dev_dbg(&dev->pdev->dev, "usbmode = 0x%08x\n", usbmode);
usbmode &= (~3 | MODE_IDLE);
writel(usbmode, &dev->op_regs->usbmode);
- DBG(dev, "<--- %s()\n", __func__);
+ dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__);
}
/*-------------------------------------------------------------------------*/
@@ -3324,7 +3531,6 @@ static const struct pci_device_id pci_ids[] = { {
}, { /* end: all zeroes */ }
};
-
MODULE_DEVICE_TABLE(pci, pci_ids);
@@ -3343,12 +3549,6 @@ static struct pci_driver langwell_pci_driver = {
};
-MODULE_DESCRIPTION(DRIVER_DESC);
-MODULE_AUTHOR("Xiaochen Shen <xiaochen.shen@intel.com>");
-MODULE_VERSION(DRIVER_VERSION);
-MODULE_LICENSE("GPL");
-
-
static int __init init(void)
{
#ifdef OTG_TRANSCEIVER
@@ -3370,3 +3570,9 @@ static void __exit cleanup(void)
}
module_exit(cleanup);
+
+MODULE_DESCRIPTION(DRIVER_DESC);
+MODULE_AUTHOR("Xiaochen Shen <xiaochen.shen@intel.com>");
+MODULE_VERSION(DRIVER_VERSION);
+MODULE_LICENSE("GPL");
+