~ubuntu-branches/ubuntu/precise/linux-ti-omap4/precise

« back to all changes in this revision

Viewing changes to drivers/usb/gadget/ci13xxx_udc.c

  • Committer: Bazaar Package Importer
  • Author(s): Paolo Pisati
  • Date: 2011-06-29 15:23:51 UTC
  • mfrom: (26.1.1 natty-proposed)
  • Revision ID: james.westby@ubuntu.com-20110629152351-xs96tm303d95rpbk
Tags: 3.0.0-1200.2
* Rebased against 3.0.0-6.7
* BSP from TI based on 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
310
310
                udc->udc_driver->notify_event(udc,
311
311
                        CI13XXX_CONTROLLER_RESET_EVENT);
312
312
 
313
 
        if (udc->udc_driver->flags && CI13XXX_DISABLE_STREAMING)
 
313
        if (udc->udc_driver->flags & CI13XXX_DISABLE_STREAMING)
314
314
                hw_cwrite(CAP_USBMODE, USBMODE_SDIS, USBMODE_SDIS);
315
315
 
316
316
        /* USBMODE should be configured step by step */
1634
1634
        gadget_for_each_ep(ep, gadget) {
1635
1635
                usb_ep_disable(ep);
1636
1636
        }
1637
 
        usb_ep_disable(&udc->ep0out.ep);
1638
 
        usb_ep_disable(&udc->ep0in.ep);
1639
1637
 
1640
1638
        if (udc->status != NULL) {
1641
1639
                usb_ep_free_request(&udc->ep0in.ep, udc->status);
1678
1676
        if (retval)
1679
1677
                goto done;
1680
1678
 
1681
 
        retval = usb_ep_enable(&udc->ep0out.ep, &ctrl_endpt_out_desc);
1682
 
        if (retval)
1683
 
                goto done;
 
1679
        udc->status = usb_ep_alloc_request(&udc->ep0in.ep, GFP_ATOMIC);
 
1680
        if (udc->status == NULL)
 
1681
                retval = -ENOMEM;
1684
1682
 
1685
 
        retval = usb_ep_enable(&udc->ep0in.ep, &ctrl_endpt_in_desc);
1686
 
        if (!retval) {
1687
 
                udc->status = usb_ep_alloc_request(&udc->ep0in.ep, GFP_ATOMIC);
1688
 
                if (udc->status == NULL) {
1689
 
                        usb_ep_disable(&udc->ep0out.ep);
1690
 
                        retval = -ENOMEM;
1691
 
                }
1692
 
        }
1693
1683
        spin_lock(udc->lock);
1694
1684
 
1695
1685
 done:
1843
1833
__acquires(mEp->lock)
1844
1834
{
1845
1835
        struct ci13xxx_req *mReq, *mReqTemp;
1846
 
        int retval;
 
1836
        struct ci13xxx_ep *mEpTemp = mEp;
 
1837
        int uninitialized_var(retval);
1847
1838
 
1848
1839
        trace("%p", mEp);
1849
1840
 
1859
1850
                dbg_done(_usb_addr(mEp), mReq->ptr->token, retval);
1860
1851
                if (mReq->req.complete != NULL) {
1861
1852
                        spin_unlock(mEp->lock);
1862
 
                        mReq->req.complete(&mEp->ep, &mReq->req);
 
1853
                        if ((mEp->type == USB_ENDPOINT_XFER_CONTROL) &&
 
1854
                                        mReq->req.length)
 
1855
                                mEpTemp = &_udc->ep0in;
 
1856
                        mReq->req.complete(&mEpTemp->ep, &mReq->req);
1863
1857
                        spin_lock(mEp->lock);
1864
1858
                }
1865
1859
        }
1866
1860
 
1867
 
        if (retval == EBUSY)
 
1861
        if (retval == -EBUSY)
1868
1862
                retval = 0;
1869
1863
        if (retval < 0)
1870
1864
                dbg_event(_usb_addr(mEp), "DONE", retval);
1894
1888
 
1895
1889
        for (i = 0; i < hw_ep_max; i++) {
1896
1890
                struct ci13xxx_ep *mEp  = &udc->ci13xxx_ep[i];
1897
 
                int type, num, err = -EINVAL;
 
1891
                int type, num, dir, err = -EINVAL;
1898
1892
                struct usb_ctrlrequest req;
1899
1893
 
1900
1894
                if (mEp->desc == NULL)
1952
1946
                                if (req.wLength != 0)
1953
1947
                                        break;
1954
1948
                                num  = le16_to_cpu(req.wIndex);
 
1949
                                dir = num & USB_ENDPOINT_DIR_MASK;
1955
1950
                                num &= USB_ENDPOINT_NUMBER_MASK;
 
1951
                                if (dir) /* TX */
 
1952
                                        num += hw_ep_max/2;
1956
1953
                                if (!udc->ci13xxx_ep[num].wedge) {
1957
1954
                                        spin_unlock(udc->lock);
1958
1955
                                        err = usb_ep_clear_halt(
2001
1998
                                if (req.wLength != 0)
2002
1999
                                        break;
2003
2000
                                num  = le16_to_cpu(req.wIndex);
 
2001
                                dir = num & USB_ENDPOINT_DIR_MASK;
2004
2002
                                num &= USB_ENDPOINT_NUMBER_MASK;
 
2003
                                if (dir) /* TX */
 
2004
                                        num += hw_ep_max/2;
2005
2005
 
2006
2006
                                spin_unlock(udc->lock);
2007
2007
                                err = usb_ep_set_halt(&udc->ci13xxx_ep[num].ep);
2110
2110
                (mEp->ep.maxpacket << ffs_nr(QH_MAX_PKT)) & QH_MAX_PKT;
2111
2111
        mEp->qh.ptr->td.next |= TD_TERMINATE;   /* needed? */
2112
2112
 
2113
 
        retval |= hw_ep_enable(mEp->num, mEp->dir, mEp->type);
 
2113
        /*
 
2114
         * Enable endpoints in the HW other than ep0 as ep0
 
2115
         * is always enabled
 
2116
         */
 
2117
        if (mEp->num)
 
2118
                retval |= hw_ep_enable(mEp->num, mEp->dir, mEp->type);
2114
2119
 
2115
2120
        spin_unlock_irqrestore(mEp->lock, flags);
2116
2121
        return retval;
2242
2247
 
2243
2248
        spin_lock_irqsave(mEp->lock, flags);
2244
2249
 
2245
 
        if (mEp->type == USB_ENDPOINT_XFER_CONTROL &&
2246
 
            !list_empty(&mEp->qh.queue)) {
2247
 
                _ep_nuke(mEp);
2248
 
                retval = -EOVERFLOW;
2249
 
                warn("endpoint ctrl %X nuked", _usb_addr(mEp));
 
2250
        if (mEp->type == USB_ENDPOINT_XFER_CONTROL) {
 
2251
                if (req->length)
 
2252
                        mEp = (_udc->ep0_dir == RX) ?
 
2253
                                &_udc->ep0out : &_udc->ep0in;
 
2254
                if (!list_empty(&mEp->qh.queue)) {
 
2255
                        _ep_nuke(mEp);
 
2256
                        retval = -EOVERFLOW;
 
2257
                        warn("endpoint ctrl %X nuked", _usb_addr(mEp));
 
2258
                }
2250
2259
        }
2251
2260
 
2252
2261
        /* first nuke then test link, e.g. previous status has not sent */
2497
2506
        return ret;
2498
2507
}
2499
2508
 
 
2509
static int ci13xxx_vbus_draw(struct usb_gadget *_gadget, unsigned mA)
 
2510
{
 
2511
        struct ci13xxx *udc = container_of(_gadget, struct ci13xxx, gadget);
 
2512
 
 
2513
        if (udc->transceiver)
 
2514
                return otg_set_power(udc->transceiver, mA);
 
2515
        return -ENOTSUPP;
 
2516
}
 
2517
 
2500
2518
/**
2501
2519
 * Device operations part of the API to the USB controller hardware,
2502
2520
 * which don't involve endpoints (or i/o)
2505
2523
static const struct usb_gadget_ops usb_gadget_ops = {
2506
2524
        .vbus_session   = ci13xxx_vbus_session,
2507
2525
        .wakeup         = ci13xxx_wakeup,
 
2526
        .vbus_draw      = ci13xxx_vbus_draw,
2508
2527
};
2509
2528
 
2510
2529
/**
2595
2614
        }
2596
2615
        if (retval)
2597
2616
                goto done;
 
2617
        spin_unlock_irqrestore(udc->lock, flags);
 
2618
        retval = usb_ep_enable(&udc->ep0out.ep, &ctrl_endpt_out_desc);
 
2619
        if (retval)
 
2620
                return retval;
 
2621
        retval = usb_ep_enable(&udc->ep0in.ep, &ctrl_endpt_in_desc);
 
2622
        if (retval)
 
2623
                return retval;
 
2624
        spin_lock_irqsave(udc->lock, flags);
2598
2625
 
2599
2626
        udc->gadget.ep0 = &udc->ep0in.ep;
2600
2627
        /* bind gadget */