diff options
Diffstat (limited to 'drivers/usb/gadget/at91_udc.c')
-rw-r--r-- | drivers/usb/gadget/at91_udc.c | 176 |
1 files changed, 112 insertions, 64 deletions
diff --git a/drivers/usb/gadget/at91_udc.c b/drivers/usb/gadget/at91_udc.c index 1c459ff037ce..cfebca05ead5 100644 --- a/drivers/usb/gadget/at91_udc.c +++ b/drivers/usb/gadget/at91_udc.c | |||
@@ -57,19 +57,23 @@ | |||
57 | 57 | ||
58 | /* | 58 | /* |
59 | * This controller is simple and PIO-only. It's used in many AT91-series | 59 | * This controller is simple and PIO-only. It's used in many AT91-series |
60 | * ARMv4T controllers, including the at91rm9200 (arm920T, with MMU), | 60 | * full speed USB controllers, including the at91rm9200 (arm920T, with MMU), |
61 | * at91sam9261 (arm926ejs, with MMU), and several no-mmu versions. | 61 | * at91sam926x (arm926ejs, with MMU), and several no-mmu versions. |
62 | * | 62 | * |
63 | * This driver expects the board has been wired with two GPIOs suppporting | 63 | * This driver expects the board has been wired with two GPIOs suppporting |
64 | * a VBUS sensing IRQ, and a D+ pullup. (They may be omitted, but the | 64 | * a VBUS sensing IRQ, and a D+ pullup. (They may be omitted, but the |
65 | * testing hasn't covered such cases.) The pullup is most important; it | 65 | * testing hasn't covered such cases.) |
66 | * | ||
67 | * The pullup is most important (so it's integrated on sam926x parts). It | ||
66 | * provides software control over whether the host enumerates the device. | 68 | * provides software control over whether the host enumerates the device. |
69 | * | ||
67 | * The VBUS sensing helps during enumeration, and allows both USB clocks | 70 | * The VBUS sensing helps during enumeration, and allows both USB clocks |
68 | * (and the transceiver) to stay gated off until they're necessary, saving | 71 | * (and the transceiver) to stay gated off until they're necessary, saving |
69 | * power. During USB suspend, the 48 MHz clock is gated off. | 72 | * power. During USB suspend, the 48 MHz clock is gated off in hardware; |
73 | * it may also be gated off by software during some Linux sleep states. | ||
70 | */ | 74 | */ |
71 | 75 | ||
72 | #define DRIVER_VERSION "8 March 2005" | 76 | #define DRIVER_VERSION "3 May 2006" |
73 | 77 | ||
74 | static const char driver_name [] = "at91_udc"; | 78 | static const char driver_name [] = "at91_udc"; |
75 | static const char ep0name[] = "ep0"; | 79 | static const char ep0name[] = "ep0"; |
@@ -316,9 +320,15 @@ static void done(struct at91_ep *ep, struct at91_request *req, int status) | |||
316 | * | 320 | * |
317 | * There are also state bits like FORCESTALL, EPEDS, DIR, and EPTYPE | 321 | * There are also state bits like FORCESTALL, EPEDS, DIR, and EPTYPE |
318 | * that shouldn't normally be changed. | 322 | * that shouldn't normally be changed. |
323 | * | ||
324 | * NOTE at91sam9260 docs mention synch between UDPCK and MCK clock domains, | ||
325 | * implying a need to wait for one write to complete (test relevant bits) | ||
326 | * before starting the next write. This shouldn't be an issue given how | ||
327 | * infrequently we write, except maybe for write-then-read idioms. | ||
319 | */ | 328 | */ |
320 | #define SET_FX (AT91_UDP_TXPKTRDY) | 329 | #define SET_FX (AT91_UDP_TXPKTRDY) |
321 | #define CLR_FX (RX_DATA_READY | AT91_UDP_RXSETUP | AT91_UDP_STALLSENT | AT91_UDP_TXCOMP) | 330 | #define CLR_FX (RX_DATA_READY | AT91_UDP_RXSETUP \ |
331 | | AT91_UDP_STALLSENT | AT91_UDP_TXCOMP) | ||
322 | 332 | ||
323 | /* pull OUT packet data from the endpoint's fifo */ | 333 | /* pull OUT packet data from the endpoint's fifo */ |
324 | static int read_fifo (struct at91_ep *ep, struct at91_request *req) | 334 | static int read_fifo (struct at91_ep *ep, struct at91_request *req) |
@@ -472,7 +482,8 @@ static void nuke(struct at91_ep *ep, int status) | |||
472 | 482 | ||
473 | /*-------------------------------------------------------------------------*/ | 483 | /*-------------------------------------------------------------------------*/ |
474 | 484 | ||
475 | static int at91_ep_enable(struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc) | 485 | static int at91_ep_enable(struct usb_ep *_ep, |
486 | const struct usb_endpoint_descriptor *desc) | ||
476 | { | 487 | { |
477 | struct at91_ep *ep = container_of(_ep, struct at91_ep, ep); | 488 | struct at91_ep *ep = container_of(_ep, struct at91_ep, ep); |
478 | struct at91_udc *dev = ep->udc; | 489 | struct at91_udc *dev = ep->udc; |
@@ -582,11 +593,12 @@ static int at91_ep_disable (struct usb_ep * _ep) | |||
582 | * interesting for request or buffer allocation. | 593 | * interesting for request or buffer allocation. |
583 | */ | 594 | */ |
584 | 595 | ||
585 | static struct usb_request *at91_ep_alloc_request (struct usb_ep *_ep, unsigned int gfp_flags) | 596 | static struct usb_request * |
597 | at91_ep_alloc_request(struct usb_ep *_ep, unsigned int gfp_flags) | ||
586 | { | 598 | { |
587 | struct at91_request *req; | 599 | struct at91_request *req; |
588 | 600 | ||
589 | req = kcalloc(1, sizeof (struct at91_request), SLAB_KERNEL); | 601 | req = kcalloc(1, sizeof (struct at91_request), gfp_flags); |
590 | if (!req) | 602 | if (!req) |
591 | return NULL; | 603 | return NULL; |
592 | 604 | ||
@@ -862,6 +874,7 @@ static void stop_activity(struct at91_udc *udc) | |||
862 | if (udc->gadget.speed == USB_SPEED_UNKNOWN) | 874 | if (udc->gadget.speed == USB_SPEED_UNKNOWN) |
863 | driver = NULL; | 875 | driver = NULL; |
864 | udc->gadget.speed = USB_SPEED_UNKNOWN; | 876 | udc->gadget.speed = USB_SPEED_UNKNOWN; |
877 | udc->suspended = 0; | ||
865 | 878 | ||
866 | for (i = 0; i < NUM_ENDPOINTS; i++) { | 879 | for (i = 0; i < NUM_ENDPOINTS; i++) { |
867 | struct at91_ep *ep = &udc->ep[i]; | 880 | struct at91_ep *ep = &udc->ep[i]; |
@@ -889,8 +902,8 @@ static void clk_off(struct at91_udc *udc) | |||
889 | return; | 902 | return; |
890 | udc->clocked = 0; | 903 | udc->clocked = 0; |
891 | udc->gadget.speed = USB_SPEED_UNKNOWN; | 904 | udc->gadget.speed = USB_SPEED_UNKNOWN; |
892 | clk_disable(udc->iclk); | ||
893 | clk_disable(udc->fclk); | 905 | clk_disable(udc->fclk); |
906 | clk_disable(udc->iclk); | ||
894 | } | 907 | } |
895 | 908 | ||
896 | /* | 909 | /* |
@@ -911,9 +924,6 @@ static void pullup(struct at91_udc *udc, int is_on) | |||
911 | at91_udp_write(AT91_UDP_TXVC, AT91_UDP_TXVC_TXVDIS); | 924 | at91_udp_write(AT91_UDP_TXVC, AT91_UDP_TXVC_TXVDIS); |
912 | at91_set_gpio_value(udc->board.pullup_pin, 0); | 925 | at91_set_gpio_value(udc->board.pullup_pin, 0); |
913 | clk_off(udc); | 926 | clk_off(udc); |
914 | |||
915 | // REVISIT: with transceiver disabled, will D- float | ||
916 | // so that a host would falsely detect a device? | ||
917 | } | 927 | } |
918 | } | 928 | } |
919 | 929 | ||
@@ -1290,7 +1300,8 @@ static void handle_ep0(struct at91_udc *udc) | |||
1290 | if (udc->wait_for_addr_ack) { | 1300 | if (udc->wait_for_addr_ack) { |
1291 | u32 tmp; | 1301 | u32 tmp; |
1292 | 1302 | ||
1293 | at91_udp_write(AT91_UDP_FADDR, AT91_UDP_FEN | udc->addr); | 1303 | at91_udp_write(AT91_UDP_FADDR, |
1304 | AT91_UDP_FEN | udc->addr); | ||
1294 | tmp = at91_udp_read(AT91_UDP_GLB_STAT); | 1305 | tmp = at91_udp_read(AT91_UDP_GLB_STAT); |
1295 | tmp &= ~AT91_UDP_FADDEN; | 1306 | tmp &= ~AT91_UDP_FADDEN; |
1296 | if (udc->addr) | 1307 | if (udc->addr) |
@@ -1361,9 +1372,10 @@ static irqreturn_t at91_udc_irq (int irq, void *_udc, struct pt_regs *r) | |||
1361 | u32 rescans = 5; | 1372 | u32 rescans = 5; |
1362 | 1373 | ||
1363 | while (rescans--) { | 1374 | while (rescans--) { |
1364 | u32 status = at91_udp_read(AT91_UDP_ISR); | 1375 | u32 status; |
1365 | 1376 | ||
1366 | status &= at91_udp_read(AT91_UDP_IMR); | 1377 | status = at91_udp_read(AT91_UDP_ISR) |
1378 | & at91_udp_read(AT91_UDP_IMR); | ||
1367 | if (!status) | 1379 | if (!status) |
1368 | break; | 1380 | break; |
1369 | 1381 | ||
@@ -1379,18 +1391,17 @@ static irqreturn_t at91_udc_irq (int irq, void *_udc, struct pt_regs *r) | |||
1379 | stop_activity(udc); | 1391 | stop_activity(udc); |
1380 | 1392 | ||
1381 | /* enable ep0 */ | 1393 | /* enable ep0 */ |
1382 | at91_udp_write(AT91_UDP_CSR(0), AT91_UDP_EPEDS | AT91_UDP_EPTYPE_CTRL); | 1394 | at91_udp_write(AT91_UDP_CSR(0), |
1395 | AT91_UDP_EPEDS | AT91_UDP_EPTYPE_CTRL); | ||
1383 | udc->gadget.speed = USB_SPEED_FULL; | 1396 | udc->gadget.speed = USB_SPEED_FULL; |
1384 | udc->suspended = 0; | 1397 | udc->suspended = 0; |
1385 | at91_udp_write(AT91_UDP_IER, AT91_UDP_EP(0)); | 1398 | at91_udp_write(AT91_UDP_IER, AT91_UDP_EP(0)); |
1386 | 1399 | ||
1387 | /* | 1400 | /* |
1388 | * NOTE: this driver keeps clocks off unless the | 1401 | * NOTE: this driver keeps clocks off unless the |
1389 | * USB host is present. That saves power, and also | 1402 | * USB host is present. That saves power, but for |
1390 | * eliminates IRQs (reset, resume, suspend) that can | 1403 | * boards that don't support VBUS detection, both |
1391 | * otherwise flood from the controller. If your | 1404 | * clocks need to be active most of the time. |
1392 | * board doesn't support VBUS detection, suspend and | ||
1393 | * resume irq logic may need more attention... | ||
1394 | */ | 1405 | */ |
1395 | 1406 | ||
1396 | /* host initiated suspend (3+ms bus idle) */ | 1407 | /* host initiated suspend (3+ms bus idle) */ |
@@ -1452,13 +1463,19 @@ static irqreturn_t at91_udc_irq (int irq, void *_udc, struct pt_regs *r) | |||
1452 | 1463 | ||
1453 | /*-------------------------------------------------------------------------*/ | 1464 | /*-------------------------------------------------------------------------*/ |
1454 | 1465 | ||
1466 | static void nop_release(struct device *dev) | ||
1467 | { | ||
1468 | /* nothing to free */ | ||
1469 | } | ||
1470 | |||
1455 | static struct at91_udc controller = { | 1471 | static struct at91_udc controller = { |
1456 | .gadget = { | 1472 | .gadget = { |
1457 | .ops = &at91_udc_ops, | 1473 | .ops = &at91_udc_ops, |
1458 | .ep0 = &controller.ep[0].ep, | 1474 | .ep0 = &controller.ep[0].ep, |
1459 | .name = driver_name, | 1475 | .name = driver_name, |
1460 | .dev = { | 1476 | .dev = { |
1461 | .bus_id = "gadget" | 1477 | .bus_id = "gadget", |
1478 | .release = nop_release, | ||
1462 | } | 1479 | } |
1463 | }, | 1480 | }, |
1464 | .ep[0] = { | 1481 | .ep[0] = { |
@@ -1468,7 +1485,8 @@ static struct at91_udc controller = { | |||
1468 | }, | 1485 | }, |
1469 | .udc = &controller, | 1486 | .udc = &controller, |
1470 | .maxpacket = 8, | 1487 | .maxpacket = 8, |
1471 | .creg = (void __iomem *)(AT91_VA_BASE_UDP + AT91_UDP_CSR(0)), | 1488 | .creg = (void __iomem *)(AT91_VA_BASE_UDP |
1489 | + AT91_UDP_CSR(0)), | ||
1472 | .int_mask = 1 << 0, | 1490 | .int_mask = 1 << 0, |
1473 | }, | 1491 | }, |
1474 | .ep[1] = { | 1492 | .ep[1] = { |
@@ -1479,7 +1497,8 @@ static struct at91_udc controller = { | |||
1479 | .udc = &controller, | 1497 | .udc = &controller, |
1480 | .is_pingpong = 1, | 1498 | .is_pingpong = 1, |
1481 | .maxpacket = 64, | 1499 | .maxpacket = 64, |
1482 | .creg = (void __iomem *)(AT91_VA_BASE_UDP + AT91_UDP_CSR(1)), | 1500 | .creg = (void __iomem *)(AT91_VA_BASE_UDP |
1501 | + AT91_UDP_CSR(1)), | ||
1483 | .int_mask = 1 << 1, | 1502 | .int_mask = 1 << 1, |
1484 | }, | 1503 | }, |
1485 | .ep[2] = { | 1504 | .ep[2] = { |
@@ -1490,7 +1509,8 @@ static struct at91_udc controller = { | |||
1490 | .udc = &controller, | 1509 | .udc = &controller, |
1491 | .is_pingpong = 1, | 1510 | .is_pingpong = 1, |
1492 | .maxpacket = 64, | 1511 | .maxpacket = 64, |
1493 | .creg = (void __iomem *)(AT91_VA_BASE_UDP + AT91_UDP_CSR(2)), | 1512 | .creg = (void __iomem *)(AT91_VA_BASE_UDP |
1513 | + AT91_UDP_CSR(2)), | ||
1494 | .int_mask = 1 << 2, | 1514 | .int_mask = 1 << 2, |
1495 | }, | 1515 | }, |
1496 | .ep[3] = { | 1516 | .ep[3] = { |
@@ -1501,7 +1521,8 @@ static struct at91_udc controller = { | |||
1501 | }, | 1521 | }, |
1502 | .udc = &controller, | 1522 | .udc = &controller, |
1503 | .maxpacket = 8, | 1523 | .maxpacket = 8, |
1504 | .creg = (void __iomem *)(AT91_VA_BASE_UDP + AT91_UDP_CSR(3)), | 1524 | .creg = (void __iomem *)(AT91_VA_BASE_UDP |
1525 | + AT91_UDP_CSR(3)), | ||
1505 | .int_mask = 1 << 3, | 1526 | .int_mask = 1 << 3, |
1506 | }, | 1527 | }, |
1507 | .ep[4] = { | 1528 | .ep[4] = { |
@@ -1512,7 +1533,8 @@ static struct at91_udc controller = { | |||
1512 | .udc = &controller, | 1533 | .udc = &controller, |
1513 | .is_pingpong = 1, | 1534 | .is_pingpong = 1, |
1514 | .maxpacket = 256, | 1535 | .maxpacket = 256, |
1515 | .creg = (void __iomem *)(AT91_VA_BASE_UDP + AT91_UDP_CSR(4)), | 1536 | .creg = (void __iomem *)(AT91_VA_BASE_UDP |
1537 | + AT91_UDP_CSR(4)), | ||
1516 | .int_mask = 1 << 4, | 1538 | .int_mask = 1 << 4, |
1517 | }, | 1539 | }, |
1518 | .ep[5] = { | 1540 | .ep[5] = { |
@@ -1523,10 +1545,11 @@ static struct at91_udc controller = { | |||
1523 | .udc = &controller, | 1545 | .udc = &controller, |
1524 | .is_pingpong = 1, | 1546 | .is_pingpong = 1, |
1525 | .maxpacket = 256, | 1547 | .maxpacket = 256, |
1526 | .creg = (void __iomem *)(AT91_VA_BASE_UDP + AT91_UDP_CSR(5)), | 1548 | .creg = (void __iomem *)(AT91_VA_BASE_UDP |
1549 | + AT91_UDP_CSR(5)), | ||
1527 | .int_mask = 1 << 5, | 1550 | .int_mask = 1 << 5, |
1528 | }, | 1551 | }, |
1529 | /* ep6 and ep7 are also reserved */ | 1552 | /* ep6 and ep7 are also reserved (custom silicon might use them) */ |
1530 | }; | 1553 | }; |
1531 | 1554 | ||
1532 | static irqreturn_t at91_vbus_irq(int irq, void *_udc, struct pt_regs *r) | 1555 | static irqreturn_t at91_vbus_irq(int irq, void *_udc, struct pt_regs *r) |
@@ -1593,6 +1616,7 @@ int usb_gadget_unregister_driver (struct usb_gadget_driver *driver) | |||
1593 | 1616 | ||
1594 | local_irq_disable(); | 1617 | local_irq_disable(); |
1595 | udc->enabled = 0; | 1618 | udc->enabled = 0; |
1619 | at91_udp_write(AT91_UDP_IDR, ~0); | ||
1596 | pullup(udc, 0); | 1620 | pullup(udc, 0); |
1597 | local_irq_enable(); | 1621 | local_irq_enable(); |
1598 | 1622 | ||
@@ -1624,6 +1648,16 @@ static int __devinit at91udc_probe(struct platform_device *pdev) | |||
1624 | return -ENODEV; | 1648 | return -ENODEV; |
1625 | } | 1649 | } |
1626 | 1650 | ||
1651 | if (pdev->num_resources != 2) { | ||
1652 | DBG("invalid num_resources"); | ||
1653 | return -ENODEV; | ||
1654 | } | ||
1655 | if ((pdev->resource[0].flags != IORESOURCE_MEM) | ||
1656 | || (pdev->resource[1].flags != IORESOURCE_IRQ)) { | ||
1657 | DBG("invalid resource type"); | ||
1658 | return -ENODEV; | ||
1659 | } | ||
1660 | |||
1627 | if (!request_mem_region(AT91_BASE_UDP, SZ_16K, driver_name)) { | 1661 | if (!request_mem_region(AT91_BASE_UDP, SZ_16K, driver_name)) { |
1628 | DBG("someone's using UDC memory\n"); | 1662 | DBG("someone's using UDC memory\n"); |
1629 | return -EBUSY; | 1663 | return -EBUSY; |
@@ -1649,19 +1683,26 @@ static int __devinit at91udc_probe(struct platform_device *pdev) | |||
1649 | if (retval < 0) | 1683 | if (retval < 0) |
1650 | goto fail0; | 1684 | goto fail0; |
1651 | 1685 | ||
1652 | /* disable everything until there's a gadget driver and vbus */ | 1686 | /* don't do anything until we have both gadget driver and VBUS */ |
1653 | pullup(udc, 0); | 1687 | clk_enable(udc->iclk); |
1688 | at91_udp_write(AT91_UDP_TXVC, AT91_UDP_TXVC_TXVDIS); | ||
1689 | at91_udp_write(AT91_UDP_IDR, 0xffffffff); | ||
1690 | clk_disable(udc->iclk); | ||
1654 | 1691 | ||
1655 | /* request UDC and maybe VBUS irqs */ | 1692 | /* request UDC and maybe VBUS irqs */ |
1656 | if (request_irq(AT91_ID_UDP, at91_udc_irq, IRQF_DISABLED, driver_name, udc)) { | 1693 | udc->udp_irq = platform_get_irq(pdev, 0); |
1657 | DBG("request irq %d failed\n", AT91_ID_UDP); | 1694 | if (request_irq(udc->udp_irq, at91_udc_irq, |
1695 | IRQF_DISABLED, driver_name, udc)) { | ||
1696 | DBG("request irq %d failed\n", udc->udp_irq); | ||
1658 | retval = -EBUSY; | 1697 | retval = -EBUSY; |
1659 | goto fail1; | 1698 | goto fail1; |
1660 | } | 1699 | } |
1661 | if (udc->board.vbus_pin > 0) { | 1700 | if (udc->board.vbus_pin > 0) { |
1662 | if (request_irq(udc->board.vbus_pin, at91_vbus_irq, IRQF_DISABLED, driver_name, udc)) { | 1701 | if (request_irq(udc->board.vbus_pin, at91_vbus_irq, |
1663 | DBG("request vbus irq %d failed\n", udc->board.vbus_pin); | 1702 | IRQF_DISABLED, driver_name, udc)) { |
1664 | free_irq(AT91_ID_UDP, udc); | 1703 | DBG("request vbus irq %d failed\n", |
1704 | udc->board.vbus_pin); | ||
1705 | free_irq(udc->udp_irq, udc); | ||
1665 | retval = -EBUSY; | 1706 | retval = -EBUSY; |
1666 | goto fail1; | 1707 | goto fail1; |
1667 | } | 1708 | } |
@@ -1670,6 +1711,7 @@ static int __devinit at91udc_probe(struct platform_device *pdev) | |||
1670 | udc->vbus = 1; | 1711 | udc->vbus = 1; |
1671 | } | 1712 | } |
1672 | dev_set_drvdata(dev, udc); | 1713 | dev_set_drvdata(dev, udc); |
1714 | device_init_wakeup(dev, 1); | ||
1673 | create_debug_file(udc); | 1715 | create_debug_file(udc); |
1674 | 1716 | ||
1675 | INFO("%s version %s\n", driver_name, DRIVER_VERSION); | 1717 | INFO("%s version %s\n", driver_name, DRIVER_VERSION); |
@@ -1678,14 +1720,14 @@ static int __devinit at91udc_probe(struct platform_device *pdev) | |||
1678 | fail1: | 1720 | fail1: |
1679 | device_unregister(&udc->gadget.dev); | 1721 | device_unregister(&udc->gadget.dev); |
1680 | fail0: | 1722 | fail0: |
1681 | release_mem_region(AT91_VA_BASE_UDP, SZ_16K); | 1723 | release_mem_region(AT91_BASE_UDP, SZ_16K); |
1682 | DBG("%s probe failed, %d\n", driver_name, retval); | 1724 | DBG("%s probe failed, %d\n", driver_name, retval); |
1683 | return retval; | 1725 | return retval; |
1684 | } | 1726 | } |
1685 | 1727 | ||
1686 | static int __devexit at91udc_remove(struct platform_device *dev) | 1728 | static int __devexit at91udc_remove(struct platform_device *pdev) |
1687 | { | 1729 | { |
1688 | struct at91_udc *udc = platform_get_drvdata(dev); | 1730 | struct at91_udc *udc = platform_get_drvdata(pdev); |
1689 | 1731 | ||
1690 | DBG("remove\n"); | 1732 | DBG("remove\n"); |
1691 | 1733 | ||
@@ -1694,10 +1736,11 @@ static int __devexit at91udc_remove(struct platform_device *dev) | |||
1694 | if (udc->driver != 0) | 1736 | if (udc->driver != 0) |
1695 | usb_gadget_unregister_driver(udc->driver); | 1737 | usb_gadget_unregister_driver(udc->driver); |
1696 | 1738 | ||
1739 | device_init_wakeup(&pdev->dev, 0); | ||
1697 | remove_debug_file(udc); | 1740 | remove_debug_file(udc); |
1698 | if (udc->board.vbus_pin > 0) | 1741 | if (udc->board.vbus_pin > 0) |
1699 | free_irq(udc->board.vbus_pin, udc); | 1742 | free_irq(udc->board.vbus_pin, udc); |
1700 | free_irq(AT91_ID_UDP, udc); | 1743 | free_irq(udc->udp_irq, udc); |
1701 | device_unregister(&udc->gadget.dev); | 1744 | device_unregister(&udc->gadget.dev); |
1702 | release_mem_region(AT91_BASE_UDP, SZ_16K); | 1745 | release_mem_region(AT91_BASE_UDP, SZ_16K); |
1703 | 1746 | ||
@@ -1708,31 +1751,36 @@ static int __devexit at91udc_remove(struct platform_device *dev) | |||
1708 | } | 1751 | } |
1709 | 1752 | ||
1710 | #ifdef CONFIG_PM | 1753 | #ifdef CONFIG_PM |
1711 | static int at91udc_suspend(struct platform_device *dev, pm_message_t mesg) | 1754 | static int at91udc_suspend(struct platform_device *pdev, pm_message_t mesg) |
1712 | { | 1755 | { |
1713 | struct at91_udc *udc = platform_get_drvdata(dev); | 1756 | struct at91_udc *udc = platform_get_drvdata(pdev); |
1757 | int wake = udc->driver && device_may_wakeup(&pdev->dev); | ||
1714 | 1758 | ||
1715 | /* | 1759 | /* Unless we can act normally to the host (letting it wake us up |
1716 | * The "safe" suspend transitions are opportunistic ... e.g. when | 1760 | * whenever it has work for us) force disconnect. Wakeup requires |
1717 | * the USB link is suspended (48MHz clock autogated off), or when | 1761 | * PLLB for USB events (signaling for reset, wakeup, or incoming |
1718 | * it's disconnected (programmatically gated off, elsewhere). | 1762 | * tokens) and VBUS irqs (on systems which support them). |
1719 | * Then we can suspend, and the chip can enter slow clock mode. | ||
1720 | * | ||
1721 | * The problem case is some component (user mode?) suspending this | ||
1722 | * device while it's active, with the 48 MHz clock in use. There | ||
1723 | * are two basic approaches: (a) veto suspend levels involving slow | ||
1724 | * clock mode, (b) disconnect, so 48 MHz will no longer be in use | ||
1725 | * and we can enter slow clock mode. This uses (b) for now, since | ||
1726 | * it's simplest until AT91 PM exists and supports the other option. | ||
1727 | */ | 1763 | */ |
1728 | if (udc->vbus && !udc->suspended) | 1764 | if ((!udc->suspended && udc->addr) |
1765 | || !wake | ||
1766 | || at91_suspend_entering_slow_clock()) { | ||
1729 | pullup(udc, 0); | 1767 | pullup(udc, 0); |
1768 | disable_irq_wake(udc->udp_irq); | ||
1769 | } else | ||
1770 | enable_irq_wake(udc->udp_irq); | ||
1771 | |||
1772 | if (udc->board.vbus_pin > 0) { | ||
1773 | if (wake) | ||
1774 | enable_irq_wake(udc->board.vbus_pin); | ||
1775 | else | ||
1776 | disable_irq_wake(udc->board.vbus_pin); | ||
1777 | } | ||
1730 | return 0; | 1778 | return 0; |
1731 | } | 1779 | } |
1732 | 1780 | ||
1733 | static int at91udc_resume(struct platform_device *dev) | 1781 | static int at91udc_resume(struct platform_device *pdev) |
1734 | { | 1782 | { |
1735 | struct at91_udc *udc = platform_get_drvdata(dev); | 1783 | struct at91_udc *udc = platform_get_drvdata(pdev); |
1736 | 1784 | ||
1737 | /* maybe reconnect to host; if so, clocks on */ | 1785 | /* maybe reconnect to host; if so, clocks on */ |
1738 | pullup(udc, 1); | 1786 | pullup(udc, 1); |
@@ -1748,7 +1796,7 @@ static struct platform_driver at91_udc = { | |||
1748 | .remove = __devexit_p(at91udc_remove), | 1796 | .remove = __devexit_p(at91udc_remove), |
1749 | .shutdown = at91udc_shutdown, | 1797 | .shutdown = at91udc_shutdown, |
1750 | .suspend = at91udc_suspend, | 1798 | .suspend = at91udc_suspend, |
1751 | .resume = at91udc_resume, | 1799 | .resume = at91udc_resume, |
1752 | .driver = { | 1800 | .driver = { |
1753 | .name = (char *) driver_name, | 1801 | .name = (char *) driver_name, |
1754 | .owner = THIS_MODULE, | 1802 | .owner = THIS_MODULE, |
@@ -1767,6 +1815,6 @@ static void __devexit udc_exit_module(void) | |||
1767 | } | 1815 | } |
1768 | module_exit(udc_exit_module); | 1816 | module_exit(udc_exit_module); |
1769 | 1817 | ||
1770 | MODULE_DESCRIPTION("AT91RM9200 udc driver"); | 1818 | MODULE_DESCRIPTION("AT91 udc driver"); |
1771 | MODULE_AUTHOR("Thomas Rathbone, David Brownell"); | 1819 | MODULE_AUTHOR("Thomas Rathbone, David Brownell"); |
1772 | MODULE_LICENSE("GPL"); | 1820 | MODULE_LICENSE("GPL"); |