V4L/DVB (3306): Fixed i2c return value, conversion mdelay to msleep
[powerpc.git] / drivers / usb / gadget / omap_udc.c
index ff5533e..a8972d7 100644 (file)
@@ -38,7 +38,7 @@
 #include <linux/proc_fs.h>
 #include <linux/mm.h>
 #include <linux/moduleparam.h>
-#include <linux/device.h>
+#include <linux/platform_device.h>
 #include <linux/usb_ch9.h>
 #include <linux/usb_gadget.h>
 #include <linux/usb_otg.h>
@@ -269,7 +269,7 @@ static int omap_ep_disable(struct usb_ep *_ep)
 /*-------------------------------------------------------------------------*/
 
 static struct usb_request *
-omap_alloc_request(struct usb_ep *ep, unsigned gfp_flags)
+omap_alloc_request(struct usb_ep *ep, gfp_t gfp_flags)
 {
        struct omap_req *req;
 
@@ -298,7 +298,7 @@ omap_alloc_buffer(
        struct usb_ep   *_ep,
        unsigned        bytes,
        dma_addr_t      *dma,
-       unsigned        gfp_flags
+       gfp_t           gfp_flags
 )
 {
        void            *retval;
@@ -691,7 +691,7 @@ static void next_out_dma(struct omap_ep *ep, struct omap_req *req)
 }
 
 static void
-finish_out_dma(struct omap_ep *ep, struct omap_req *req, int status)
+finish_out_dma(struct omap_ep *ep, struct omap_req *req, int status, int one)
 {
        u16     count;
 
@@ -699,6 +699,8 @@ finish_out_dma(struct omap_ep *ep, struct omap_req *req, int status)
                ep->dma_counter = (u16) (req->req.dma + req->req.actual);
        count = dma_dest_len(ep, req->req.dma + req->req.actual);
        count += req->req.actual;
+       if (one)
+               count--;
        if (count <= req->req.length)
                req->req.actual = count;
 
@@ -747,7 +749,7 @@ static void dma_irq(struct omap_udc *udc, u16 irq_src)
                if (!list_empty(&ep->queue)) {
                        req = container_of(ep->queue.next,
                                        struct omap_req, queue);
-                       finish_out_dma(ep, req, 0);
+                       finish_out_dma(ep, req, 0, dman_stat & UDC_DMA_RX_SB);
                }
                UDC_IRQ_SRC_REG = UDC_RXN_EOT;
 
@@ -925,7 +927,7 @@ static void dma_channel_release(struct omap_ep *ep)
                while (UDC_RXDMA_CFG_REG & mask)
                        udelay(10);
                if (req)
-                       finish_out_dma(ep, req, -ECONNRESET);
+                       finish_out_dma(ep, req, -ECONNRESET, 0);
        }
        omap_free_dma(ep->lch);
        ep->dma_channel = 0;
@@ -937,7 +939,7 @@ static void dma_channel_release(struct omap_ep *ep)
 /*-------------------------------------------------------------------------*/
 
 static int
-omap_ep_queue(struct usb_ep *_ep, struct usb_request *_req, unsigned gfp_flags)
+omap_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
 {
        struct omap_ep  *ep = container_of(_ep, struct omap_ep, ep);
        struct omap_req *req = container_of(_req, struct omap_req, req);
@@ -1786,8 +1788,12 @@ static void devstate_irq(struct omap_udc *udc, u16 irq_src)
                                        udc->driver->suspend(&udc->gadget);
                                        spin_lock(&udc->lock);
                                }
+                               if (udc->transceiver)
+                                       otg_set_suspend(udc->transceiver, 1);
                        } else {
                                VDBG("resume\n");
+                               if (udc->transceiver)
+                                       otg_set_suspend(udc->transceiver, 0);
                                if (udc->gadget.speed == USB_SPEED_FULL
                                                && udc->driver->resume) {
                                        spin_unlock(&udc->lock);
@@ -2701,18 +2707,17 @@ omap_udc_setup(struct platform_device *odev, struct otg_transceiver *xceiv)
        return 0;
 }
 
-static int __init omap_udc_probe(struct device *dev)
+static int __init omap_udc_probe(struct platform_device *pdev)
 {
-       struct platform_device  *odev = to_platform_device(dev);
        int                     status = -ENODEV;
        int                     hmc;
        struct otg_transceiver  *xceiv = NULL;
        const char              *type = NULL;
-       struct omap_usb_config  *config = dev->platform_data;
+       struct omap_usb_config  *config = pdev->dev.platform_data;
 
        /* NOTE:  "knows" the order of the resources! */
-       if (!request_mem_region(odev->resource[0].start, 
-                       odev->resource[0].end - odev->resource[0].start + 1,
+       if (!request_mem_region(pdev->resource[0].start, 
+                       pdev->resource[0].end - pdev->resource[0].start + 1,
                        driver_name)) {
                DBG("request_mem_region failed\n");
                return -EBUSY;
@@ -2797,7 +2802,7 @@ bad_on_1710:
        INFO("hmc mode %d, %s transceiver\n", hmc, type);
 
        /* a "gadget" abstracts/virtualizes the controller */
-       status = omap_udc_setup(odev, xceiv);
+       status = omap_udc_setup(pdev, xceiv);
        if (status) {
                goto cleanup0;
        }
@@ -2815,28 +2820,28 @@ bad_on_1710:
                udc->clr_halt = UDC_RESET_EP;
 
        /* USB general purpose IRQ:  ep0, state changes, dma, etc */
-       status = request_irq(odev->resource[1].start, omap_udc_irq,
+       status = request_irq(pdev->resource[1].start, omap_udc_irq,
                        SA_SAMPLE_RANDOM, driver_name, udc);
        if (status != 0) {
                ERR( "can't get irq %ld, err %d\n",
-                       odev->resource[1].start, status);
+                       pdev->resource[1].start, status);
                goto cleanup1;
        }
 
        /* USB "non-iso" IRQ (PIO for all but ep0) */
-       status = request_irq(odev->resource[2].start, omap_udc_pio_irq,
+       status = request_irq(pdev->resource[2].start, omap_udc_pio_irq,
                        SA_SAMPLE_RANDOM, "omap_udc pio", udc);
        if (status != 0) {
                ERR( "can't get irq %ld, err %d\n",
-                       odev->resource[2].start, status);
+                       pdev->resource[2].start, status);
                goto cleanup2;
        }
 #ifdef USE_ISO
-       status = request_irq(odev->resource[3].start, omap_udc_iso_irq,
+       status = request_irq(pdev->resource[3].start, omap_udc_iso_irq,
                        SA_INTERRUPT, "omap_udc iso", udc);
        if (status != 0) {
                ERR("can't get irq %ld, err %d\n",
-                       odev->resource[3].start, status);
+                       pdev->resource[3].start, status);
                goto cleanup3;
        }
 #endif
@@ -2847,11 +2852,11 @@ bad_on_1710:
 
 #ifdef USE_ISO
 cleanup3:
-       free_irq(odev->resource[2].start, udc);
+       free_irq(pdev->resource[2].start, udc);
 #endif
 
 cleanup2:
-       free_irq(odev->resource[1].start, udc);
+       free_irq(pdev->resource[1].start, udc);
 
 cleanup1:
        kfree (udc);
@@ -2860,14 +2865,13 @@ cleanup1:
 cleanup0:
        if (xceiv)
                put_device(xceiv->dev);
-       release_mem_region(odev->resource[0].start,
-                       odev->resource[0].end - odev->resource[0].start + 1);
+       release_mem_region(pdev->resource[0].start,
+                       pdev->resource[0].end - pdev->resource[0].start + 1);
        return status;
 }
 
-static int __exit omap_udc_remove(struct device *dev)
+static int __exit omap_udc_remove(struct platform_device *pdev)
 {
-       struct platform_device  *odev = to_platform_device(dev);
        DECLARE_COMPLETION(done);
 
        if (!udc)
@@ -2885,13 +2889,13 @@ static int __exit omap_udc_remove(struct device *dev)
        remove_proc_file();
 
 #ifdef USE_ISO
-       free_irq(odev->resource[3].start, udc);
+       free_irq(pdev->resource[3].start, udc);
 #endif
-       free_irq(odev->resource[2].start, udc);
-       free_irq(odev->resource[1].start, udc);
+       free_irq(pdev->resource[2].start, udc);
+       free_irq(pdev->resource[1].start, udc);
 
-       release_mem_region(odev->resource[0].start,
-                       odev->resource[0].end - odev->resource[0].start + 1);
+       release_mem_region(pdev->resource[0].start,
+                       pdev->resource[0].end - pdev->resource[0].start + 1);
 
        device_unregister(&udc->gadget.dev);
        wait_for_completion(&done);
@@ -2909,12 +2913,10 @@ static int __exit omap_udc_remove(struct device *dev)
  * may involve talking to an external transceiver (e.g. isp1301).
  */
 
-static int omap_udc_suspend(struct device *dev, pm_message_t message, u32 level)
+static int omap_udc_suspend(struct platform_device *dev, pm_message_t message)
 {
        u32     devstat;
 
-       if (level != SUSPEND_POWER_DOWN)
-               return 0;
        devstat = UDC_DEVSTAT_REG;
 
        /* we're requesting 48 MHz clock if the pullup is enabled
@@ -2931,11 +2933,8 @@ static int omap_udc_suspend(struct device *dev, pm_message_t message, u32 level)
        return 0;
 }
 
-static int omap_udc_resume(struct device *dev, u32 level)
+static int omap_udc_resume(struct platform_device *dev)
 {
-       if (level != RESUME_POWER_ON)
-               return 0;
-
        DBG("resume + wakeup/SRP\n");
        omap_pullup(&udc->gadget, 1);
 
@@ -2946,13 +2945,15 @@ static int omap_udc_resume(struct device *dev, u32 level)
 
 /*-------------------------------------------------------------------------*/
 
-static struct device_driver udc_driver = {
-       .name           = (char *) driver_name,
-       .bus            = &platform_bus_type,
+static struct platform_driver udc_driver = {
        .probe          = omap_udc_probe,
        .remove         = __exit_p(omap_udc_remove),
        .suspend        = omap_udc_suspend,
        .resume         = omap_udc_resume,
+       .driver         = {
+               .owner  = THIS_MODULE,
+               .name   = (char *) driver_name,
+       },
 };
 
 static int __init udc_init(void)
@@ -2963,13 +2964,13 @@ static int __init udc_init(void)
 #endif
                "%s\n", driver_desc,
                use_dma ?  " (dma)" : "");
-       return driver_register(&udc_driver);
+       return platform_driver_register(&udc_driver);
 }
 module_init(udc_init);
 
 static void __exit udc_exit(void)
 {
-       driver_unregister(&udc_driver);
+       platform_driver_unregister(&udc_driver);
 }
 module_exit(udc_exit);