diff options
Diffstat (limited to 'drivers/usb/gadget/pxa27x_udc.c')
-rw-r--r-- | drivers/usb/gadget/pxa27x_udc.c | 272 |
1 files changed, 231 insertions, 41 deletions
diff --git a/drivers/usb/gadget/pxa27x_udc.c b/drivers/usb/gadget/pxa27x_udc.c index 990f40f988d4..8cc676ecbb23 100644 --- a/drivers/usb/gadget/pxa27x_udc.c +++ b/drivers/usb/gadget/pxa27x_udc.c | |||
@@ -30,6 +30,7 @@ | |||
30 | #include <linux/proc_fs.h> | 30 | #include <linux/proc_fs.h> |
31 | #include <linux/clk.h> | 31 | #include <linux/clk.h> |
32 | #include <linux/irq.h> | 32 | #include <linux/irq.h> |
33 | #include <linux/gpio.h> | ||
33 | 34 | ||
34 | #include <asm/byteorder.h> | 35 | #include <asm/byteorder.h> |
35 | #include <mach/hardware.h> | 36 | #include <mach/hardware.h> |
@@ -278,7 +279,7 @@ static void pxa_init_debugfs(struct pxa_udc *udc) | |||
278 | goto err_queues; | 279 | goto err_queues; |
279 | eps = debugfs_create_file("epstate", 0400, root, udc, | 280 | eps = debugfs_create_file("epstate", 0400, root, udc, |
280 | &eps_dbg_fops); | 281 | &eps_dbg_fops); |
281 | if (!queues) | 282 | if (!eps) |
282 | goto err_eps; | 283 | goto err_eps; |
283 | 284 | ||
284 | udc->debugfs_root = root; | 285 | udc->debugfs_root = root; |
@@ -747,13 +748,13 @@ static void req_done(struct pxa_ep *ep, struct pxa27x_request *req, int status) | |||
747 | } | 748 | } |
748 | 749 | ||
749 | /** | 750 | /** |
750 | * ep_end_out_req - Ends control endpoint in request | 751 | * ep_end_out_req - Ends endpoint OUT request |
751 | * @ep: physical endpoint | 752 | * @ep: physical endpoint |
752 | * @req: pxa request | 753 | * @req: pxa request |
753 | * | 754 | * |
754 | * Context: ep->lock held | 755 | * Context: ep->lock held |
755 | * | 756 | * |
756 | * Ends endpoint in request (completes usb request). | 757 | * Ends endpoint OUT request (completes usb request). |
757 | */ | 758 | */ |
758 | static void ep_end_out_req(struct pxa_ep *ep, struct pxa27x_request *req) | 759 | static void ep_end_out_req(struct pxa_ep *ep, struct pxa27x_request *req) |
759 | { | 760 | { |
@@ -762,13 +763,13 @@ static void ep_end_out_req(struct pxa_ep *ep, struct pxa27x_request *req) | |||
762 | } | 763 | } |
763 | 764 | ||
764 | /** | 765 | /** |
765 | * ep0_end_out_req - Ends control endpoint in request (ends data stage) | 766 | * ep0_end_out_req - Ends control endpoint OUT request (ends data stage) |
766 | * @ep: physical endpoint | 767 | * @ep: physical endpoint |
767 | * @req: pxa request | 768 | * @req: pxa request |
768 | * | 769 | * |
769 | * Context: ep->lock held | 770 | * Context: ep->lock held |
770 | * | 771 | * |
771 | * Ends control endpoint in request (completes usb request), and puts | 772 | * Ends control endpoint OUT request (completes usb request), and puts |
772 | * control endpoint into idle state | 773 | * control endpoint into idle state |
773 | */ | 774 | */ |
774 | static void ep0_end_out_req(struct pxa_ep *ep, struct pxa27x_request *req) | 775 | static void ep0_end_out_req(struct pxa_ep *ep, struct pxa27x_request *req) |
@@ -779,13 +780,13 @@ static void ep0_end_out_req(struct pxa_ep *ep, struct pxa27x_request *req) | |||
779 | } | 780 | } |
780 | 781 | ||
781 | /** | 782 | /** |
782 | * ep_end_in_req - Ends endpoint out request | 783 | * ep_end_in_req - Ends endpoint IN request |
783 | * @ep: physical endpoint | 784 | * @ep: physical endpoint |
784 | * @req: pxa request | 785 | * @req: pxa request |
785 | * | 786 | * |
786 | * Context: ep->lock held | 787 | * Context: ep->lock held |
787 | * | 788 | * |
788 | * Ends endpoint out request (completes usb request). | 789 | * Ends endpoint IN request (completes usb request). |
789 | */ | 790 | */ |
790 | static void ep_end_in_req(struct pxa_ep *ep, struct pxa27x_request *req) | 791 | static void ep_end_in_req(struct pxa_ep *ep, struct pxa27x_request *req) |
791 | { | 792 | { |
@@ -794,20 +795,18 @@ static void ep_end_in_req(struct pxa_ep *ep, struct pxa27x_request *req) | |||
794 | } | 795 | } |
795 | 796 | ||
796 | /** | 797 | /** |
797 | * ep0_end_in_req - Ends control endpoint out request (ends data stage) | 798 | * ep0_end_in_req - Ends control endpoint IN request (ends data stage) |
798 | * @ep: physical endpoint | 799 | * @ep: physical endpoint |
799 | * @req: pxa request | 800 | * @req: pxa request |
800 | * | 801 | * |
801 | * Context: ep->lock held | 802 | * Context: ep->lock held |
802 | * | 803 | * |
803 | * Ends control endpoint out request (completes usb request), and puts | 804 | * Ends control endpoint IN request (completes usb request), and puts |
804 | * control endpoint into status state | 805 | * control endpoint into status state |
805 | */ | 806 | */ |
806 | static void ep0_end_in_req(struct pxa_ep *ep, struct pxa27x_request *req) | 807 | static void ep0_end_in_req(struct pxa_ep *ep, struct pxa27x_request *req) |
807 | { | 808 | { |
808 | struct pxa_udc *udc = ep->dev; | 809 | set_ep0state(ep->dev, IN_STATUS_STAGE); |
809 | |||
810 | set_ep0state(udc, IN_STATUS_STAGE); | ||
811 | ep_end_in_req(ep, req); | 810 | ep_end_in_req(ep, req); |
812 | } | 811 | } |
813 | 812 | ||
@@ -1167,7 +1166,7 @@ static int pxa_ep_queue(struct usb_ep *_ep, struct usb_request *_req, | |||
1167 | ep_end_in_req(ep, req); | 1166 | ep_end_in_req(ep, req); |
1168 | } else { | 1167 | } else { |
1169 | ep_err(ep, "got a request of %d bytes while" | 1168 | ep_err(ep, "got a request of %d bytes while" |
1170 | "in state WATI_ACK_SET_CONF_INTERF\n", | 1169 | "in state WAIT_ACK_SET_CONF_INTERF\n", |
1171 | length); | 1170 | length); |
1172 | ep_del_request(ep, req); | 1171 | ep_del_request(ep, req); |
1173 | rc = -EL2HLT; | 1172 | rc = -EL2HLT; |
@@ -1213,30 +1212,26 @@ static int pxa_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) | |||
1213 | struct udc_usb_ep *udc_usb_ep; | 1212 | struct udc_usb_ep *udc_usb_ep; |
1214 | struct pxa27x_request *req; | 1213 | struct pxa27x_request *req; |
1215 | unsigned long flags; | 1214 | unsigned long flags; |
1216 | int rc; | 1215 | int rc = -EINVAL; |
1217 | 1216 | ||
1218 | if (!_ep) | 1217 | if (!_ep) |
1219 | return -EINVAL; | 1218 | return rc; |
1220 | udc_usb_ep = container_of(_ep, struct udc_usb_ep, usb_ep); | 1219 | udc_usb_ep = container_of(_ep, struct udc_usb_ep, usb_ep); |
1221 | ep = udc_usb_ep->pxa_ep; | 1220 | ep = udc_usb_ep->pxa_ep; |
1222 | if (!ep || is_ep0(ep)) | 1221 | if (!ep || is_ep0(ep)) |
1223 | return -EINVAL; | 1222 | return rc; |
1224 | 1223 | ||
1225 | spin_lock_irqsave(&ep->lock, flags); | 1224 | spin_lock_irqsave(&ep->lock, flags); |
1226 | 1225 | ||
1227 | /* make sure it's actually queued on this endpoint */ | 1226 | /* make sure it's actually queued on this endpoint */ |
1228 | list_for_each_entry(req, &ep->queue, queue) { | 1227 | list_for_each_entry(req, &ep->queue, queue) { |
1229 | if (&req->req == _req) | 1228 | if (&req->req == _req) { |
1229 | req_done(ep, req, -ECONNRESET); | ||
1230 | rc = 0; | ||
1230 | break; | 1231 | break; |
1232 | } | ||
1231 | } | 1233 | } |
1232 | 1234 | ||
1233 | rc = -EINVAL; | ||
1234 | if (&req->req != _req) | ||
1235 | goto out; | ||
1236 | |||
1237 | rc = 0; | ||
1238 | req_done(ep, req, -ECONNRESET); | ||
1239 | out: | ||
1240 | spin_unlock_irqrestore(&ep->lock, flags); | 1235 | spin_unlock_irqrestore(&ep->lock, flags); |
1241 | return rc; | 1236 | return rc; |
1242 | } | 1237 | } |
@@ -1471,6 +1466,32 @@ static struct usb_ep_ops pxa_ep_ops = { | |||
1471 | .fifo_flush = pxa_ep_fifo_flush, | 1466 | .fifo_flush = pxa_ep_fifo_flush, |
1472 | }; | 1467 | }; |
1473 | 1468 | ||
1469 | /** | ||
1470 | * dplus_pullup - Connect or disconnect pullup resistor to D+ pin | ||
1471 | * @udc: udc device | ||
1472 | * @on: 0 if disconnect pullup resistor, 1 otherwise | ||
1473 | * Context: any | ||
1474 | * | ||
1475 | * Handle D+ pullup resistor, make the device visible to the usb bus, and | ||
1476 | * declare it as a full speed usb device | ||
1477 | */ | ||
1478 | static void dplus_pullup(struct pxa_udc *udc, int on) | ||
1479 | { | ||
1480 | if (on) { | ||
1481 | if (gpio_is_valid(udc->mach->gpio_pullup)) | ||
1482 | gpio_set_value(udc->mach->gpio_pullup, | ||
1483 | !udc->mach->gpio_pullup_inverted); | ||
1484 | if (udc->mach->udc_command) | ||
1485 | udc->mach->udc_command(PXA2XX_UDC_CMD_CONNECT); | ||
1486 | } else { | ||
1487 | if (gpio_is_valid(udc->mach->gpio_pullup)) | ||
1488 | gpio_set_value(udc->mach->gpio_pullup, | ||
1489 | udc->mach->gpio_pullup_inverted); | ||
1490 | if (udc->mach->udc_command) | ||
1491 | udc->mach->udc_command(PXA2XX_UDC_CMD_DISCONNECT); | ||
1492 | } | ||
1493 | udc->pullup_on = on; | ||
1494 | } | ||
1474 | 1495 | ||
1475 | /** | 1496 | /** |
1476 | * pxa_udc_get_frame - Returns usb frame number | 1497 | * pxa_udc_get_frame - Returns usb frame number |
@@ -1500,21 +1521,145 @@ static int pxa_udc_wakeup(struct usb_gadget *_gadget) | |||
1500 | return 0; | 1521 | return 0; |
1501 | } | 1522 | } |
1502 | 1523 | ||
1524 | static void udc_enable(struct pxa_udc *udc); | ||
1525 | static void udc_disable(struct pxa_udc *udc); | ||
1526 | |||
1527 | /** | ||
1528 | * should_enable_udc - Tells if UDC should be enabled | ||
1529 | * @udc: udc device | ||
1530 | * Context: any | ||
1531 | * | ||
1532 | * The UDC should be enabled if : | ||
1533 | |||
1534 | * - the pullup resistor is connected | ||
1535 | * - and a gadget driver is bound | ||
1536 | * - and vbus is sensed (or no vbus sense is available) | ||
1537 | * | ||
1538 | * Returns 1 if UDC should be enabled, 0 otherwise | ||
1539 | */ | ||
1540 | static int should_enable_udc(struct pxa_udc *udc) | ||
1541 | { | ||
1542 | int put_on; | ||
1543 | |||
1544 | put_on = ((udc->pullup_on) && (udc->driver)); | ||
1545 | put_on &= ((udc->vbus_sensed) || (!udc->transceiver)); | ||
1546 | return put_on; | ||
1547 | } | ||
1548 | |||
1549 | /** | ||
1550 | * should_disable_udc - Tells if UDC should be disabled | ||
1551 | * @udc: udc device | ||
1552 | * Context: any | ||
1553 | * | ||
1554 | * The UDC should be disabled if : | ||
1555 | * - the pullup resistor is not connected | ||
1556 | * - or no gadget driver is bound | ||
1557 | * - or no vbus is sensed (when vbus sesing is available) | ||
1558 | * | ||
1559 | * Returns 1 if UDC should be disabled | ||
1560 | */ | ||
1561 | static int should_disable_udc(struct pxa_udc *udc) | ||
1562 | { | ||
1563 | int put_off; | ||
1564 | |||
1565 | put_off = ((!udc->pullup_on) || (!udc->driver)); | ||
1566 | put_off |= ((!udc->vbus_sensed) && (udc->transceiver)); | ||
1567 | return put_off; | ||
1568 | } | ||
1569 | |||
1570 | /** | ||
1571 | * pxa_udc_pullup - Offer manual D+ pullup control | ||
1572 | * @_gadget: usb gadget using the control | ||
1573 | * @is_active: 0 if disconnect, else connect D+ pullup resistor | ||
1574 | * Context: !in_interrupt() | ||
1575 | * | ||
1576 | * Returns 0 if OK, -EOPNOTSUPP if udc driver doesn't handle D+ pullup | ||
1577 | */ | ||
1578 | static int pxa_udc_pullup(struct usb_gadget *_gadget, int is_active) | ||
1579 | { | ||
1580 | struct pxa_udc *udc = to_gadget_udc(_gadget); | ||
1581 | |||
1582 | if (!gpio_is_valid(udc->mach->gpio_pullup) && !udc->mach->udc_command) | ||
1583 | return -EOPNOTSUPP; | ||
1584 | |||
1585 | dplus_pullup(udc, is_active); | ||
1586 | |||
1587 | if (should_enable_udc(udc)) | ||
1588 | udc_enable(udc); | ||
1589 | if (should_disable_udc(udc)) | ||
1590 | udc_disable(udc); | ||
1591 | return 0; | ||
1592 | } | ||
1593 | |||
1594 | static void udc_enable(struct pxa_udc *udc); | ||
1595 | static void udc_disable(struct pxa_udc *udc); | ||
1596 | |||
1597 | /** | ||
1598 | * pxa_udc_vbus_session - Called by external transceiver to enable/disable udc | ||
1599 | * @_gadget: usb gadget | ||
1600 | * @is_active: 0 if should disable the udc, 1 if should enable | ||
1601 | * | ||
1602 | * Enables the udc, and optionnaly activates D+ pullup resistor. Or disables the | ||
1603 | * udc, and deactivates D+ pullup resistor. | ||
1604 | * | ||
1605 | * Returns 0 | ||
1606 | */ | ||
1607 | static int pxa_udc_vbus_session(struct usb_gadget *_gadget, int is_active) | ||
1608 | { | ||
1609 | struct pxa_udc *udc = to_gadget_udc(_gadget); | ||
1610 | |||
1611 | udc->vbus_sensed = is_active; | ||
1612 | if (should_enable_udc(udc)) | ||
1613 | udc_enable(udc); | ||
1614 | if (should_disable_udc(udc)) | ||
1615 | udc_disable(udc); | ||
1616 | |||
1617 | return 0; | ||
1618 | } | ||
1619 | |||
1620 | /** | ||
1621 | * pxa_udc_vbus_draw - Called by gadget driver after SET_CONFIGURATION completed | ||
1622 | * @_gadget: usb gadget | ||
1623 | * @mA: current drawn | ||
1624 | * | ||
1625 | * Context: !in_interrupt() | ||
1626 | * | ||
1627 | * Called after a configuration was chosen by a USB host, to inform how much | ||
1628 | * current can be drawn by the device from VBus line. | ||
1629 | * | ||
1630 | * Returns 0 or -EOPNOTSUPP if no transceiver is handling the udc | ||
1631 | */ | ||
1632 | static int pxa_udc_vbus_draw(struct usb_gadget *_gadget, unsigned mA) | ||
1633 | { | ||
1634 | struct pxa_udc *udc; | ||
1635 | |||
1636 | udc = to_gadget_udc(_gadget); | ||
1637 | if (udc->transceiver) | ||
1638 | return otg_set_power(udc->transceiver, mA); | ||
1639 | return -EOPNOTSUPP; | ||
1640 | } | ||
1641 | |||
1503 | static const struct usb_gadget_ops pxa_udc_ops = { | 1642 | static const struct usb_gadget_ops pxa_udc_ops = { |
1504 | .get_frame = pxa_udc_get_frame, | 1643 | .get_frame = pxa_udc_get_frame, |
1505 | .wakeup = pxa_udc_wakeup, | 1644 | .wakeup = pxa_udc_wakeup, |
1506 | /* current versions must always be self-powered */ | 1645 | .pullup = pxa_udc_pullup, |
1646 | .vbus_session = pxa_udc_vbus_session, | ||
1647 | .vbus_draw = pxa_udc_vbus_draw, | ||
1507 | }; | 1648 | }; |
1508 | 1649 | ||
1509 | /** | 1650 | /** |
1510 | * udc_disable - disable udc device controller | 1651 | * udc_disable - disable udc device controller |
1511 | * @udc: udc device | 1652 | * @udc: udc device |
1653 | * Context: any | ||
1512 | * | 1654 | * |
1513 | * Disables the udc device : disables clocks, udc interrupts, control endpoint | 1655 | * Disables the udc device : disables clocks, udc interrupts, control endpoint |
1514 | * interrupts. | 1656 | * interrupts. |
1515 | */ | 1657 | */ |
1516 | static void udc_disable(struct pxa_udc *udc) | 1658 | static void udc_disable(struct pxa_udc *udc) |
1517 | { | 1659 | { |
1660 | if (!udc->enabled) | ||
1661 | return; | ||
1662 | |||
1518 | udc_writel(udc, UDCICR0, 0); | 1663 | udc_writel(udc, UDCICR0, 0); |
1519 | udc_writel(udc, UDCICR1, 0); | 1664 | udc_writel(udc, UDCICR1, 0); |
1520 | 1665 | ||
@@ -1523,8 +1668,8 @@ static void udc_disable(struct pxa_udc *udc) | |||
1523 | 1668 | ||
1524 | ep0_idle(udc); | 1669 | ep0_idle(udc); |
1525 | udc->gadget.speed = USB_SPEED_UNKNOWN; | 1670 | udc->gadget.speed = USB_SPEED_UNKNOWN; |
1526 | if (udc->mach->udc_command) | 1671 | |
1527 | udc->mach->udc_command(PXA2XX_UDC_CMD_DISCONNECT); | 1672 | udc->enabled = 0; |
1528 | } | 1673 | } |
1529 | 1674 | ||
1530 | /** | 1675 | /** |
@@ -1555,10 +1700,9 @@ static __init void udc_init_data(struct pxa_udc *dev) | |||
1555 | } | 1700 | } |
1556 | 1701 | ||
1557 | /* USB endpoints init */ | 1702 | /* USB endpoints init */ |
1558 | for (i = 0; i < NR_USB_ENDPOINTS; i++) | 1703 | for (i = 1; i < NR_USB_ENDPOINTS; i++) |
1559 | if (i != 0) | 1704 | list_add_tail(&dev->udc_usb_ep[i].usb_ep.ep_list, |
1560 | list_add_tail(&dev->udc_usb_ep[i].usb_ep.ep_list, | 1705 | &dev->gadget.ep_list); |
1561 | &dev->gadget.ep_list); | ||
1562 | } | 1706 | } |
1563 | 1707 | ||
1564 | /** | 1708 | /** |
@@ -1570,6 +1714,9 @@ static __init void udc_init_data(struct pxa_udc *dev) | |||
1570 | */ | 1714 | */ |
1571 | static void udc_enable(struct pxa_udc *udc) | 1715 | static void udc_enable(struct pxa_udc *udc) |
1572 | { | 1716 | { |
1717 | if (udc->enabled) | ||
1718 | return; | ||
1719 | |||
1573 | udc_writel(udc, UDCICR0, 0); | 1720 | udc_writel(udc, UDCICR0, 0); |
1574 | udc_writel(udc, UDCICR1, 0); | 1721 | udc_writel(udc, UDCICR1, 0); |
1575 | udc_clear_mask_UDCCR(udc, UDCCR_UDE); | 1722 | udc_clear_mask_UDCCR(udc, UDCCR_UDE); |
@@ -1598,9 +1745,7 @@ static void udc_enable(struct pxa_udc *udc) | |||
1598 | /* enable ep0 irqs */ | 1745 | /* enable ep0 irqs */ |
1599 | pio_irq_enable(&udc->pxa_ep[0]); | 1746 | pio_irq_enable(&udc->pxa_ep[0]); |
1600 | 1747 | ||
1601 | dev_info(udc->dev, "UDC connecting\n"); | 1748 | udc->enabled = 1; |
1602 | if (udc->mach->udc_command) | ||
1603 | udc->mach->udc_command(PXA2XX_UDC_CMD_CONNECT); | ||
1604 | } | 1749 | } |
1605 | 1750 | ||
1606 | /** | 1751 | /** |
@@ -1612,6 +1757,9 @@ static void udc_enable(struct pxa_udc *udc) | |||
1612 | * usb traffic follows until a disconnect is reported. Then a host may connect | 1757 | * usb traffic follows until a disconnect is reported. Then a host may connect |
1613 | * again, or the driver might get unbound. | 1758 | * again, or the driver might get unbound. |
1614 | * | 1759 | * |
1760 | * Note that the udc is not automatically enabled. Check function | ||
1761 | * should_enable_udc(). | ||
1762 | * | ||
1615 | * Returns 0 if no error, -EINVAL, -ENODEV, -EBUSY otherwise | 1763 | * Returns 0 if no error, -EINVAL, -ENODEV, -EBUSY otherwise |
1616 | */ | 1764 | */ |
1617 | int usb_gadget_register_driver(struct usb_gadget_driver *driver) | 1765 | int usb_gadget_register_driver(struct usb_gadget_driver *driver) |
@@ -1630,6 +1778,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver) | |||
1630 | /* first hook up the driver ... */ | 1778 | /* first hook up the driver ... */ |
1631 | udc->driver = driver; | 1779 | udc->driver = driver; |
1632 | udc->gadget.dev.driver = &driver->driver; | 1780 | udc->gadget.dev.driver = &driver->driver; |
1781 | dplus_pullup(udc, 1); | ||
1633 | 1782 | ||
1634 | retval = device_add(&udc->gadget.dev); | 1783 | retval = device_add(&udc->gadget.dev); |
1635 | if (retval) { | 1784 | if (retval) { |
@@ -1645,9 +1794,21 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver) | |||
1645 | dev_dbg(udc->dev, "registered gadget driver '%s'\n", | 1794 | dev_dbg(udc->dev, "registered gadget driver '%s'\n", |
1646 | driver->driver.name); | 1795 | driver->driver.name); |
1647 | 1796 | ||
1648 | udc_enable(udc); | 1797 | if (udc->transceiver) { |
1798 | retval = otg_set_peripheral(udc->transceiver, &udc->gadget); | ||
1799 | if (retval) { | ||
1800 | dev_err(udc->dev, "can't bind to transceiver\n"); | ||
1801 | goto transceiver_fail; | ||
1802 | } | ||
1803 | } | ||
1804 | |||
1805 | if (should_enable_udc(udc)) | ||
1806 | udc_enable(udc); | ||
1649 | return 0; | 1807 | return 0; |
1650 | 1808 | ||
1809 | transceiver_fail: | ||
1810 | if (driver->unbind) | ||
1811 | driver->unbind(&udc->gadget); | ||
1651 | bind_fail: | 1812 | bind_fail: |
1652 | device_del(&udc->gadget.dev); | 1813 | device_del(&udc->gadget.dev); |
1653 | add_fail: | 1814 | add_fail: |
@@ -1699,14 +1860,17 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) | |||
1699 | 1860 | ||
1700 | stop_activity(udc, driver); | 1861 | stop_activity(udc, driver); |
1701 | udc_disable(udc); | 1862 | udc_disable(udc); |
1863 | dplus_pullup(udc, 0); | ||
1702 | 1864 | ||
1703 | driver->unbind(&udc->gadget); | 1865 | driver->unbind(&udc->gadget); |
1704 | udc->driver = NULL; | 1866 | udc->driver = NULL; |
1705 | 1867 | ||
1706 | device_del(&udc->gadget.dev); | 1868 | device_del(&udc->gadget.dev); |
1707 | |||
1708 | dev_info(udc->dev, "unregistered gadget driver '%s'\n", | 1869 | dev_info(udc->dev, "unregistered gadget driver '%s'\n", |
1709 | driver->driver.name); | 1870 | driver->driver.name); |
1871 | |||
1872 | if (udc->transceiver) | ||
1873 | return otg_set_peripheral(udc->transceiver, NULL); | ||
1710 | return 0; | 1874 | return 0; |
1711 | } | 1875 | } |
1712 | EXPORT_SYMBOL(usb_gadget_unregister_driver); | 1876 | EXPORT_SYMBOL(usb_gadget_unregister_driver); |
@@ -1823,14 +1987,14 @@ static void handle_ep0(struct pxa_udc *udc, int fifo_irq, int opc_irq) | |||
1823 | struct pxa27x_request *req = NULL; | 1987 | struct pxa27x_request *req = NULL; |
1824 | int completed = 0; | 1988 | int completed = 0; |
1825 | 1989 | ||
1990 | if (!list_empty(&ep->queue)) | ||
1991 | req = list_entry(ep->queue.next, struct pxa27x_request, queue); | ||
1992 | |||
1826 | udccsr0 = udc_ep_readl(ep, UDCCSR); | 1993 | udccsr0 = udc_ep_readl(ep, UDCCSR); |
1827 | ep_dbg(ep, "state=%s, req=%p, udccsr0=0x%03x, udcbcr=%d, irq_msk=%x\n", | 1994 | ep_dbg(ep, "state=%s, req=%p, udccsr0=0x%03x, udcbcr=%d, irq_msk=%x\n", |
1828 | EP0_STNAME(udc), req, udccsr0, udc_ep_readl(ep, UDCBCR), | 1995 | EP0_STNAME(udc), req, udccsr0, udc_ep_readl(ep, UDCBCR), |
1829 | (fifo_irq << 1 | opc_irq)); | 1996 | (fifo_irq << 1 | opc_irq)); |
1830 | 1997 | ||
1831 | if (!list_empty(&ep->queue)) | ||
1832 | req = list_entry(ep->queue.next, struct pxa27x_request, queue); | ||
1833 | |||
1834 | if (udccsr0 & UDCCSR0_SST) { | 1998 | if (udccsr0 & UDCCSR0_SST) { |
1835 | ep_dbg(ep, "clearing stall status\n"); | 1999 | ep_dbg(ep, "clearing stall status\n"); |
1836 | nuke(ep, -EPIPE); | 2000 | nuke(ep, -EPIPE); |
@@ -2212,7 +2376,7 @@ static int __init pxa_udc_probe(struct platform_device *pdev) | |||
2212 | { | 2376 | { |
2213 | struct resource *regs; | 2377 | struct resource *regs; |
2214 | struct pxa_udc *udc = &memory; | 2378 | struct pxa_udc *udc = &memory; |
2215 | int retval; | 2379 | int retval = 0, gpio; |
2216 | 2380 | ||
2217 | regs = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 2381 | regs = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
2218 | if (!regs) | 2382 | if (!regs) |
@@ -2223,6 +2387,20 @@ static int __init pxa_udc_probe(struct platform_device *pdev) | |||
2223 | 2387 | ||
2224 | udc->dev = &pdev->dev; | 2388 | udc->dev = &pdev->dev; |
2225 | udc->mach = pdev->dev.platform_data; | 2389 | udc->mach = pdev->dev.platform_data; |
2390 | udc->transceiver = otg_get_transceiver(); | ||
2391 | |||
2392 | gpio = udc->mach->gpio_pullup; | ||
2393 | if (gpio_is_valid(gpio)) { | ||
2394 | retval = gpio_request(gpio, "USB D+ pullup"); | ||
2395 | if (retval == 0) | ||
2396 | gpio_direction_output(gpio, | ||
2397 | udc->mach->gpio_pullup_inverted); | ||
2398 | } | ||
2399 | if (retval) { | ||
2400 | dev_err(&pdev->dev, "Couldn't request gpio %d : %d\n", | ||
2401 | gpio, retval); | ||
2402 | return retval; | ||
2403 | } | ||
2226 | 2404 | ||
2227 | udc->clk = clk_get(&pdev->dev, NULL); | 2405 | udc->clk = clk_get(&pdev->dev, NULL); |
2228 | if (IS_ERR(udc->clk)) { | 2406 | if (IS_ERR(udc->clk)) { |
@@ -2240,6 +2418,7 @@ static int __init pxa_udc_probe(struct platform_device *pdev) | |||
2240 | device_initialize(&udc->gadget.dev); | 2418 | device_initialize(&udc->gadget.dev); |
2241 | udc->gadget.dev.parent = &pdev->dev; | 2419 | udc->gadget.dev.parent = &pdev->dev; |
2242 | udc->gadget.dev.dma_mask = NULL; | 2420 | udc->gadget.dev.dma_mask = NULL; |
2421 | udc->vbus_sensed = 0; | ||
2243 | 2422 | ||
2244 | the_controller = udc; | 2423 | the_controller = udc; |
2245 | platform_set_drvdata(pdev, udc); | 2424 | platform_set_drvdata(pdev, udc); |
@@ -2273,14 +2452,21 @@ err_clk: | |||
2273 | static int __exit pxa_udc_remove(struct platform_device *_dev) | 2452 | static int __exit pxa_udc_remove(struct platform_device *_dev) |
2274 | { | 2453 | { |
2275 | struct pxa_udc *udc = platform_get_drvdata(_dev); | 2454 | struct pxa_udc *udc = platform_get_drvdata(_dev); |
2455 | int gpio = udc->mach->gpio_pullup; | ||
2276 | 2456 | ||
2277 | usb_gadget_unregister_driver(udc->driver); | 2457 | usb_gadget_unregister_driver(udc->driver); |
2278 | free_irq(udc->irq, udc); | 2458 | free_irq(udc->irq, udc); |
2279 | pxa_cleanup_debugfs(udc); | 2459 | pxa_cleanup_debugfs(udc); |
2460 | if (gpio_is_valid(gpio)) | ||
2461 | gpio_free(gpio); | ||
2462 | |||
2463 | otg_put_transceiver(udc->transceiver); | ||
2280 | 2464 | ||
2465 | udc->transceiver = NULL; | ||
2281 | platform_set_drvdata(_dev, NULL); | 2466 | platform_set_drvdata(_dev, NULL); |
2282 | the_controller = NULL; | 2467 | the_controller = NULL; |
2283 | clk_put(udc->clk); | 2468 | clk_put(udc->clk); |
2469 | iounmap(udc->regs); | ||
2284 | 2470 | ||
2285 | return 0; | 2471 | return 0; |
2286 | } | 2472 | } |
@@ -2319,6 +2505,8 @@ static int pxa_udc_suspend(struct platform_device *_dev, pm_message_t state) | |||
2319 | } | 2505 | } |
2320 | 2506 | ||
2321 | udc_disable(udc); | 2507 | udc_disable(udc); |
2508 | udc->pullup_resume = udc->pullup_on; | ||
2509 | dplus_pullup(udc, 0); | ||
2322 | 2510 | ||
2323 | return 0; | 2511 | return 0; |
2324 | } | 2512 | } |
@@ -2346,7 +2534,9 @@ static int pxa_udc_resume(struct platform_device *_dev) | |||
2346 | ep->udccsr_value, ep->udccr_value); | 2534 | ep->udccsr_value, ep->udccr_value); |
2347 | } | 2535 | } |
2348 | 2536 | ||
2349 | udc_enable(udc); | 2537 | dplus_pullup(udc, udc->pullup_resume); |
2538 | if (should_enable_udc(udc)) | ||
2539 | udc_enable(udc); | ||
2350 | /* | 2540 | /* |
2351 | * We do not handle OTG yet. | 2541 | * We do not handle OTG yet. |
2352 | * | 2542 | * |