Merge branch 'for-linus' of master.kernel.org:/home/rmk/linux-2.6-arm
[sfrench/cifs-2.6.git] / drivers / usb / gadget / pxa2xx_udc.c
index 0d225369847d06258c383eb34125abfd14dc3f17..84392e835d5f12c598bec4823b9d3b352bd7b4ca 100644 (file)
@@ -33,7 +33,6 @@
 #include <linux/types.h>
 #include <linux/errno.h>
 #include <linux/delay.h>
-#include <linux/sched.h>
 #include <linux/slab.h>
 #include <linux/init.h>
 #include <linux/timer.h>
@@ -72,7 +71,7 @@
  * by the host to interact with this device, and allocates endpoints to
  * the different protocol interfaces.  The controller driver virtualizes
  * usb hardware so that the gadget drivers will be more portable.
- * 
+ *
  * This UDC hardware wants to implement a bit too much USB protocol, so
  * it constrains the sorts of USB configuration change events that work.
  * The errata for these chips are misleading; some "fixed" bugs from
@@ -142,7 +141,7 @@ MODULE_PARM_DESC (fifo_mode, "pxa2xx udc fifo mode");
 #endif
 
 /* ---------------------------------------------------------------------------
- *     endpoint related parts of the api to the usb controller hardware,
+ *     endpoint related parts of the api to the usb controller hardware,
  *     used by gadget driver; and the inner talker-to-hardware core.
  * ---------------------------------------------------------------------------
  */
@@ -156,7 +155,7 @@ static int is_vbus_present(void)
        struct pxa2xx_udc_mach_info             *mach = the_controller->mach;
 
        if (mach->gpio_vbus)
-               return pxa_gpio_get(mach->gpio_vbus);
+               return udc_gpio_get(mach->gpio_vbus);
        if (mach->udc_is_connected)
                return mach->udc_is_connected();
        return 1;
@@ -168,7 +167,7 @@ static void pullup_off(void)
        struct pxa2xx_udc_mach_info             *mach = the_controller->mach;
 
        if (mach->gpio_pullup)
-               pxa_gpio_set(mach->gpio_pullup, 0);
+               udc_gpio_set(mach->gpio_pullup, 0);
        else if (mach->udc_command)
                mach->udc_command(PXA2XX_UDC_CMD_DISCONNECT);
 }
@@ -178,7 +177,7 @@ static void pullup_on(void)
        struct pxa2xx_udc_mach_info             *mach = the_controller->mach;
 
        if (mach->gpio_pullup)
-               pxa_gpio_set(mach->gpio_pullup, 1);
+               udc_gpio_set(mach->gpio_pullup, 1);
        else if (mach->udc_command)
                mach->udc_command(PXA2XX_UDC_CMD_CONNECT);
 }
@@ -294,7 +293,7 @@ static int pxa2xx_ep_enable (struct usb_ep *_ep,
 
 #ifdef USE_DMA
        /* for (some) bulk and ISO endpoints, try to get a DMA channel and
-        * bind it to the endpoint.  otherwise use PIO. 
+        * bind it to the endpoint.  otherwise use PIO.
         */
        switch (ep->bmAttributes) {
        case USB_ENDPOINT_XFER_ISOC:
@@ -305,7 +304,7 @@ static int pxa2xx_ep_enable (struct usb_ep *_ep,
                if (!use_dma || !ep->reg_drcmr)
                        break;
                ep->dma = pxa_request_dma ((char *)_ep->name,
-                               (le16_to_cpu (desc->wMaxPacketSize) > 64)
+                               (le16_to_cpu (desc->wMaxPacketSize) > 64)
                                        ? DMA_PRIO_MEDIUM /* some iso */
                                        : DMA_PRIO_LOW,
                                dma_nodesc_handler, ep);
@@ -362,7 +361,7 @@ static int pxa2xx_ep_disable (struct usb_ep *_ep)
  */
 
 /*
- *     pxa2xx_ep_alloc_request - allocate a request data structure
+ *     pxa2xx_ep_alloc_request - allocate a request data structure
  */
 static struct usb_request *
 pxa2xx_ep_alloc_request (struct usb_ep *_ep, gfp_t gfp_flags)
@@ -379,7 +378,7 @@ pxa2xx_ep_alloc_request (struct usb_ep *_ep, gfp_t gfp_flags)
 
 
 /*
- *     pxa2xx_ep_free_request - deallocate a request data structure
+ *     pxa2xx_ep_free_request - deallocate a request data structure
  */
 static void
 pxa2xx_ep_free_request (struct usb_ep *_ep, struct usb_request *_req)
@@ -1032,7 +1031,7 @@ pxa2xx_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
 
 
 /*
- *     nuke - dequeue ALL requests
+ *     nuke - dequeue ALL requests
  */
 static void nuke(struct pxa2xx_ep *ep, int status)
 {
@@ -1137,16 +1136,16 @@ static int pxa2xx_ep_set_halt(struct usb_ep *_ep, int value)
                ep->dev->req_pending = 0;
                ep->dev->ep0state = EP0_STALL;
 
-       /* and bulk/intr endpoints like dropping stalls too */
-       } else {
-               unsigned i;
-               for (i = 0; i < 1000; i += 20) {
-                       if (*ep->reg_udccs & UDCCS_BI_SST)
-                               break;
-                       udelay(20);
-               }
-       }
-       local_irq_restore(flags);
+       /* and bulk/intr endpoints like dropping stalls too */
+       } else {
+               unsigned i;
+               for (i = 0; i < 1000; i += 20) {
+                       if (*ep->reg_udccs & UDCCS_BI_SST)
+                               break;
+                       udelay(20);
+               }
+       }
+       local_irq_restore(flags);
 
        DBG(DBG_VERBOSE, "%s halt\n", _ep->name);
        return 0;
@@ -1217,7 +1216,7 @@ static struct usb_ep_ops pxa2xx_ep_ops = {
 
 
 /* ---------------------------------------------------------------------------
- *     device-scoped parts of the api to the usb controller hardware
+ *     device-scoped parts of the api to the usb controller hardware
  * ---------------------------------------------------------------------------
  */
 
@@ -1240,7 +1239,7 @@ static void udc_enable (struct pxa2xx_udc *);
 static void udc_disable(struct pxa2xx_udc *);
 
 /* We disable the UDC -- and its 48 MHz clock -- whenever it's not
- * in active use.  
+ * in active use.
  */
 static int pullup(struct pxa2xx_udc *udc, int is_active)
 {
@@ -1465,24 +1464,10 @@ done:
 
 #endif /* CONFIG_USB_GADGET_DEBUG_FILES */
 
-/* "function" sysfs attribute */
-static ssize_t
-show_function (struct device *_dev, struct device_attribute *attr, char *buf)
-{
-       struct pxa2xx_udc       *dev = dev_get_drvdata (_dev);
-
-       if (!dev->driver
-                       || !dev->driver->function
-                       || strlen (dev->driver->function) > PAGE_SIZE)
-               return 0;
-       return scnprintf (buf, PAGE_SIZE, "%s\n", dev->driver->function);
-}
-static DEVICE_ATTR (function, S_IRUGO, show_function, NULL);
-
 /*-------------------------------------------------------------------------*/
 
 /*
- *     udc_disable - disable USB device controller
+ *     udc_disable - disable USB device controller
  */
 static void udc_disable(struct pxa2xx_udc *dev)
 {
@@ -1498,7 +1483,7 @@ static void udc_disable(struct pxa2xx_udc *dev)
 
 #ifdef CONFIG_ARCH_PXA
         /* Disable clock for USB device */
-       pxa_set_cken(CKEN11_USB, 0);
+       pxa_set_cken(CKEN_USB, 0);
 #endif
 
        ep0_idle (dev);
@@ -1508,7 +1493,7 @@ static void udc_disable(struct pxa2xx_udc *dev)
 
 
 /*
- *     udc_reinit - initialize software state
+ *     udc_reinit - initialize software state
  */
 static void udc_reinit(struct pxa2xx_udc *dev)
 {
@@ -1544,7 +1529,7 @@ static void udc_enable (struct pxa2xx_udc *dev)
 
 #ifdef CONFIG_ARCH_PXA
         /* Enable clock for USB device */
-       pxa_set_cken(CKEN11_USB, 1);
+       pxa_set_cken(CKEN_USB, 1);
        udelay(5);
 #endif
 
@@ -1636,18 +1621,20 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
        dev->gadget.dev.driver = &driver->driver;
        dev->pullup = 1;
 
-       device_add (&dev->gadget.dev);
+       retval = device_add (&dev->gadget.dev);
+       if (retval) {
+fail:
+               dev->driver = NULL;
+               dev->gadget.dev.driver = NULL;
+               return retval;
+       }
        retval = driver->bind(&dev->gadget);
        if (retval) {
                DMSG("bind to driver %s --> error %d\n",
                                driver->driver.name, retval);
                device_del (&dev->gadget.dev);
-
-               dev->driver = NULL;
-               dev->gadget.dev.driver = NULL;
-               return retval;
+               goto fail;
        }
-       device_create_file(dev->dev, &dev_attr_function);
 
        /* ... then enable host detection and ep0; and we're ready
         * for set_configuration as well as eventual disconnect.
@@ -1705,7 +1692,6 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
        dev->driver = NULL;
 
        device_del (&dev->gadget.dev);
-       device_remove_file(dev->dev, &dev_attr_function);
 
        DMSG("unregistered gadget driver '%s'\n", driver->driver.name);
        dump_state(dev);
@@ -1756,7 +1742,7 @@ lubbock_vbus_irq(int irq, void *_dev)
 static irqreturn_t udc_vbus_irq(int irq, void *_dev)
 {
        struct pxa2xx_udc       *dev = _dev;
-       int                     vbus = pxa_gpio_get(dev->mach->gpio_vbus);
+       int                     vbus = udc_gpio_get(dev->mach->gpio_vbus);
 
        pxa2xx_udc_vbus_session(&dev->gadget, vbus);
        return IRQ_HANDLED;
@@ -2475,12 +2461,12 @@ static struct pxa2xx_udc memory = {
 #define IXP465_AD              0x00000200
 
 /*
- *     probe - binds to the platform device
+ *     probe - binds to the platform device
  */
 static int __init pxa2xx_udc_probe(struct platform_device *pdev)
 {
        struct pxa2xx_udc *dev = &memory;
-       int retval, out_dma = 1, vbus_irq;
+       int retval, out_dma = 1, vbus_irq, irq;
        u32 chiprev;
 
        /* insist on Intel/ARM/XScale */
@@ -2523,7 +2509,11 @@ static int __init pxa2xx_udc_probe(struct platform_device *pdev)
                return -ENODEV;
        }
 
-       pr_debug("%s: IRQ %d%s%s%s\n", driver_name, IRQ_USB,
+       irq = platform_get_irq(pdev, 0);
+       if (irq < 0)
+               return -ENODEV;
+
+       pr_debug("%s: IRQ %d%s%s%s\n", driver_name, irq,
                dev->has_cfr ? "" : " (!cfr)",
                out_dma ? "" : " (broken dma-out)",
                SIZE_STR DMASTR
@@ -2546,15 +2536,13 @@ static int __init pxa2xx_udc_probe(struct platform_device *pdev)
        dev->dev = &pdev->dev;
        dev->mach = pdev->dev.platform_data;
        if (dev->mach->gpio_vbus) {
-               vbus_irq = IRQ_GPIO(dev->mach->gpio_vbus & GPIO_MD_MASK_NR);
-               pxa_gpio_mode((dev->mach->gpio_vbus & GPIO_MD_MASK_NR)
-                               | GPIO_IN);
+               udc_gpio_init_vbus(dev->mach->gpio_vbus);
+               vbus_irq = udc_gpio_to_irq(dev->mach->gpio_vbus);
                set_irq_type(vbus_irq, IRQT_BOTHEDGE);
        } else
                vbus_irq = 0;
        if (dev->mach->gpio_pullup)
-               pxa_gpio_mode((dev->mach->gpio_pullup & GPIO_MD_MASK_NR)
-                               | GPIO_OUT | GPIO_DFLT_LOW);
+               udc_gpio_init_pullup(dev->mach->gpio_pullup);
 
        init_timer(&dev->timer);
        dev->timer.function = udc_watchdog;
@@ -2573,11 +2561,11 @@ static int __init pxa2xx_udc_probe(struct platform_device *pdev)
        dev->vbus = is_vbus_present();
 
        /* irq setup after old hardware state is cleaned up */
-       retval = request_irq(IRQ_USB, pxa2xx_udc_irq,
+       retval = request_irq(irq, pxa2xx_udc_irq,
                        IRQF_DISABLED, driver_name, dev);
        if (retval != 0) {
-               printk(KERN_ERR "%s: can't get irq %i, err %d\n",
-                       driver_name, IRQ_USB, retval);
+               printk(KERN_ERR "%s: can't get irq %d, err %d\n",
+                       driver_name, irq, retval);
                return -EBUSY;
        }
        dev->got_irq = 1;
@@ -2592,7 +2580,7 @@ static int __init pxa2xx_udc_probe(struct platform_device *pdev)
                        printk(KERN_ERR "%s: can't get irq %i, err %d\n",
                                driver_name, LUBBOCK_USB_DISC_IRQ, retval);
 lubbock_fail0:
-                       free_irq(IRQ_USB, dev);
+                       free_irq(irq, dev);
                        return -EBUSY;
                }
                retval = request_irq(LUBBOCK_USB_IRQ,
@@ -2614,12 +2602,12 @@ lubbock_fail0:
 #endif
        if (vbus_irq) {
                retval = request_irq(vbus_irq, udc_vbus_irq,
-                               SA_INTERRUPT | SA_SAMPLE_RANDOM,
+                               IRQF_DISABLED | IRQF_SAMPLE_RANDOM,
                                driver_name, dev);
                if (retval != 0) {
                        printk(KERN_ERR "%s: can't get irq %i, err %d\n",
                                driver_name, vbus_irq, retval);
-                       free_irq(IRQ_USB, dev);
+                       free_irq(irq, dev);
                        return -EBUSY;
                }
        }
@@ -2644,7 +2632,7 @@ static int __exit pxa2xx_udc_remove(struct platform_device *pdev)
        remove_proc_files();
 
        if (dev->got_irq) {
-               free_irq(IRQ_USB, dev);
+               free_irq(platform_get_irq(pdev, 0), dev);
                dev->got_irq = 0;
        }
 #ifdef CONFIG_ARCH_LUBBOCK
@@ -2671,7 +2659,7 @@ static int __exit pxa2xx_udc_remove(struct platform_device *pdev)
  *
  * For now, we punt and forcibly disconnect from the USB host when PXA
  * enters any suspend state.  While we're disconnected, we always disable
- * the 48MHz USB clock ... allowing PXA sleep and/or 33 MHz idle states. 
+ * the 48MHz USB clock ... allowing PXA sleep and/or 33 MHz idle states.
  * Boards without software pullup control shouldn't use those states.
  * VBUS IRQs should probably be ignored so that the PXA device just acts
  * "dead" to USB hosts until system resume.
@@ -2704,7 +2692,6 @@ static int pxa2xx_udc_resume(struct platform_device *dev)
 /*-------------------------------------------------------------------------*/
 
 static struct platform_driver udc_driver = {
-       .probe          = pxa2xx_udc_probe,
        .shutdown       = pxa2xx_udc_shutdown,
        .remove         = __exit_p(pxa2xx_udc_remove),
        .suspend        = pxa2xx_udc_suspend,
@@ -2718,7 +2705,7 @@ static struct platform_driver udc_driver = {
 static int __init udc_init(void)
 {
        printk(KERN_INFO "%s: version %s\n", driver_name, DRIVER_VERSION);
-       return platform_driver_register(&udc_driver);
+       return platform_driver_probe(&udc_driver, pxa2xx_udc_probe);
 }
 module_init(udc_init);