USB: option: add pid for ZTE
[safe/jmp/linux-2.6] / drivers / usb / gadget / lh7a40x_udc.c
index 0def9f7..6cd3d54 100644 (file)
@@ -21,6 +21,8 @@
  *
  */
 
+#include <linux/platform_device.h>
+
 #include "lh7a40x_udc.h"
 
 //#define DEBUG printk
@@ -71,17 +73,12 @@ static char *state_names[] = {
 static int lh7a40x_ep_enable(struct usb_ep *ep,
                             const struct usb_endpoint_descriptor *);
 static int lh7a40x_ep_disable(struct usb_ep *ep);
-static struct usb_request *lh7a40x_alloc_request(struct usb_ep *ep, int);
+static struct usb_request *lh7a40x_alloc_request(struct usb_ep *ep, gfp_t);
 static void lh7a40x_free_request(struct usb_ep *ep, struct usb_request *);
-static void *lh7a40x_alloc_buffer(struct usb_ep *ep, unsigned, dma_addr_t *,
-                                 int);
-static void lh7a40x_free_buffer(struct usb_ep *ep, void *, dma_addr_t,
-                               unsigned);
-static int lh7a40x_queue(struct usb_ep *ep, struct usb_request *, int);
+static int lh7a40x_queue(struct usb_ep *ep, struct usb_request *, gfp_t);
 static int lh7a40x_dequeue(struct usb_ep *ep, struct usb_request *);
 static int lh7a40x_set_halt(struct usb_ep *ep, int);
 static int lh7a40x_fifo_status(struct usb_ep *ep);
-static int lh7a40x_fifo_status(struct usb_ep *ep);
 static void lh7a40x_fifo_flush(struct usb_ep *ep);
 static void lh7a40x_ep0_kick(struct lh7a40x_udc *dev, struct lh7a40x_ep *ep);
 static void lh7a40x_handle_ep0(struct lh7a40x_udc *dev, u32 intr);
@@ -103,9 +100,6 @@ static struct usb_ep_ops lh7a40x_ep_ops = {
        .alloc_request = lh7a40x_alloc_request,
        .free_request = lh7a40x_free_request,
 
-       .alloc_buffer = lh7a40x_alloc_buffer,
-       .free_buffer = lh7a40x_free_buffer,
-
        .queue = lh7a40x_queue,
        .dequeue = lh7a40x_dequeue,
 
@@ -259,7 +253,7 @@ udc_proc_read(char *page, char **start, off_t off, int count,
  */
 static void udc_disable(struct lh7a40x_udc *dev)
 {
-       DEBUG("%s, %p\n", __FUNCTION__, dev);
+       DEBUG("%s, %p\n", __func__, dev);
 
        udc_set_address(dev, 0);
 
@@ -291,7 +285,7 @@ static void udc_reinit(struct lh7a40x_udc *dev)
 {
        u32 i;
 
-       DEBUG("%s, %p\n", __FUNCTION__, dev);
+       DEBUG("%s, %p\n", __func__, dev);
 
        /* device/ep0 records init */
        INIT_LIST_HEAD(&dev->gadget.ep_list);
@@ -324,7 +318,7 @@ static void udc_enable(struct lh7a40x_udc *dev)
 {
        int ep;
 
-       DEBUG("%s, %p\n", __FUNCTION__, dev);
+       DEBUG("%s, %p\n", __func__, dev);
 
        dev->gadget.speed = USB_SPEED_UNKNOWN;
 
@@ -418,12 +412,13 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
        struct lh7a40x_udc *dev = the_controller;
        int retval;
 
-       DEBUG("%s: %s\n", __FUNCTION__, driver->driver.name);
+       DEBUG("%s: %s\n", __func__, driver->driver.name);
 
        if (!driver
-           || driver->speed != USB_SPEED_FULL
-           || !driver->bind
-           || !driver->unbind || !driver->disconnect || !driver->setup)
+                       || driver->speed != USB_SPEED_FULL
+                       || !driver->bind
+                       || !driver->disconnect
+                       || !driver->setup)
                return -EINVAL;
        if (!dev)
                return -ENODEV;
@@ -437,8 +432,8 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
        device_add(&dev->gadget.dev);
        retval = driver->bind(&dev->gadget);
        if (retval) {
-               printk("%s: bind to driver %s --> error %d\n", dev->gadget.name,
-                      driver->driver.name, retval);
+               printk(KERN_WARNING "%s: bind to driver %s --> error %d\n",
+                      dev->gadget.name, driver->driver.name, retval);
                device_del(&dev->gadget.dev);
 
                dev->driver = 0;
@@ -450,8 +445,8 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
         * for set_configuration as well as eventual disconnect.
         * NOTE:  this shouldn't power up until later.
         */
-       printk("%s: registered gadget driver '%s'\n", dev->gadget.name,
-              driver->driver.name);
+       printk(KERN_WARNING "%s: registered gadget driver '%s'\n",
+              dev->gadget.name, driver->driver.name);
 
        udc_enable(dev);
 
@@ -470,7 +465,7 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
 
        if (!dev)
                return -ENODEV;
-       if (!driver || driver != dev->driver)
+       if (!driver || driver != dev->driver || !driver->unbind)
                return -EINVAL;
 
        spin_lock_irqsave(&dev->lock, flags);
@@ -479,6 +474,7 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
        spin_unlock_irqrestore(&dev->lock, flags);
 
        driver->unbind(&dev->gadget);
+       dev->gadget.dev.driver = NULL;
        device_del(&dev->gadget.dev);
 
        udc_disable(dev);
@@ -525,7 +521,7 @@ static int write_fifo(struct lh7a40x_ep *ep, struct lh7a40x_request *req)
                        is_short = unlikely(max < ep_maxpacket(ep));
                }
 
-               DEBUG("%s: wrote %s %d bytes%s%s %d left %p\n", __FUNCTION__,
+               DEBUG("%s: wrote %s %d bytes%s%s %d left %p\n", __func__,
                      ep->ep.name, count,
                      is_last ? "/L" : "", is_short ? "/S" : "",
                      req->req.length - req->req.actual, req);
@@ -559,7 +555,7 @@ static int read_fifo(struct lh7a40x_ep *ep, struct lh7a40x_request *req)
        /* make sure there's a packet in the FIFO. */
        csr = usb_read(ep->csr1);
        if (!(csr & USB_OUT_CSR1_OUT_PKT_RDY)) {
-               DEBUG("%s: Packet NOT ready!\n", __FUNCTION__);
+               DEBUG("%s: Packet NOT ready!\n", __func__);
                return -EINVAL;
        }
 
@@ -585,7 +581,8 @@ static int read_fifo(struct lh7a40x_ep *ep, struct lh7a40x_request *req)
                         * discard the extra data.
                         */
                        if (req->req.status != -EOVERFLOW)
-                               printk("%s overflow %d\n", ep->ep.name, count);
+                               printk(KERN_WARNING "%s overflow %d\n",
+                                      ep->ep.name, count);
                        req->req.status = -EOVERFLOW;
                } else {
                        *buf++ = byte;
@@ -618,7 +615,7 @@ static void done(struct lh7a40x_ep *ep, struct lh7a40x_request *req, int status)
        unsigned int stopped = ep->stopped;
        u32 index;
 
-       DEBUG("%s, %p\n", __FUNCTION__, ep);
+       DEBUG("%s, %p\n", __func__, ep);
        list_del_init(&req->queue);
 
        if (likely(req->req.status == -EINPROGRESS))
@@ -648,7 +645,7 @@ static void done(struct lh7a40x_ep *ep, struct lh7a40x_request *req, int status)
 /** Enable EP interrupt */
 static void pio_irq_enable(int ep)
 {
-       DEBUG("%s: %d\n", __FUNCTION__, ep);
+       DEBUG("%s: %d\n", __func__, ep);
 
        switch (ep) {
        case 1:
@@ -669,7 +666,7 @@ static void pio_irq_enable(int ep)
 /** Disable EP interrupt */
 static void pio_irq_disable(int ep)
 {
-       DEBUG("%s: %d\n", __FUNCTION__, ep);
+       DEBUG("%s: %d\n", __func__, ep);
 
        switch (ep) {
        case 1:
@@ -694,7 +691,7 @@ void nuke(struct lh7a40x_ep *ep, int status)
 {
        struct lh7a40x_request *req;
 
-       DEBUG("%s, %p\n", __FUNCTION__, ep);
+       DEBUG("%s, %p\n", __func__, ep);
 
        /* Flush FIFO */
        flush(ep);
@@ -705,7 +702,7 @@ void nuke(struct lh7a40x_ep *ep, int status)
                done(ep, req, status);
        }
 
-       /* Disable IRQ if EP is enabled (has decriptor) */
+       /* Disable IRQ if EP is enabled (has descriptor) */
        if (ep->desc)
                pio_irq_disable(ep_index(ep));
 }
@@ -738,7 +735,7 @@ static void flush_all(struct lh7a40x_udc *dev)
  */
 static void flush(struct lh7a40x_ep *ep)
 {
-       DEBUG("%s, %p\n", __FUNCTION__, ep);
+       DEBUG("%s, %p\n", __func__, ep);
 
        switch (ep->ep_type) {
        case ep_control:
@@ -770,7 +767,7 @@ static void lh7a40x_in_epn(struct lh7a40x_udc *dev, u32 ep_idx, u32 intr)
        usb_set_index(ep_idx);
 
        csr = usb_read(ep->csr1);
-       DEBUG("%s: %d, csr %x\n", __FUNCTION__, ep_idx, csr);
+       DEBUG("%s: %d, csr %x\n", __func__, ep_idx, csr);
 
        if (csr & USB_IN_CSR1_SENT_STALL) {
                DEBUG("USB_IN_CSR1_SENT_STALL\n");
@@ -780,7 +777,7 @@ static void lh7a40x_in_epn(struct lh7a40x_udc *dev, u32 ep_idx, u32 intr)
        }
 
        if (!ep->desc) {
-               DEBUG("%s: NO EP DESC\n", __FUNCTION__);
+               DEBUG("%s: NO EP DESC\n", __func__);
                return;
        }
 
@@ -806,7 +803,7 @@ static void lh7a40x_out_epn(struct lh7a40x_udc *dev, u32 ep_idx, u32 intr)
        struct lh7a40x_ep *ep = &dev->ep[ep_idx];
        struct lh7a40x_request *req;
 
-       DEBUG("%s: %d\n", __FUNCTION__, ep_idx);
+       DEBUG("%s: %d\n", __func__, ep_idx);
 
        usb_set_index(ep_idx);
 
@@ -818,11 +815,11 @@ static void lh7a40x_out_epn(struct lh7a40x_udc *dev, u32 ep_idx, u32 intr)
                        usb_read(ep->
                                 csr1)) & (USB_OUT_CSR1_OUT_PKT_RDY |
                                           USB_OUT_CSR1_SENT_STALL)) {
-                       DEBUG("%s: %x\n", __FUNCTION__, csr);
+                       DEBUG("%s: %x\n", __func__, csr);
 
                        if (csr & USB_OUT_CSR1_SENT_STALL) {
                                DEBUG("%s: stall sent, flush fifo\n",
-                                     __FUNCTION__);
+                                     __func__);
                                /* usb_set(USB_OUT_CSR1_FIFO_FLUSH, ep->csr1); */
                                flush(ep);
                        } else if (csr & USB_OUT_CSR1_OUT_PKT_RDY) {
@@ -835,8 +832,9 @@ static void lh7a40x_out_epn(struct lh7a40x_udc *dev, u32 ep_idx, u32 intr)
                                                       queue);
 
                                if (!req) {
-                                       printk("%s: NULL REQ %d\n",
-                                              __FUNCTION__, ep_idx);
+                                       printk(KERN_WARNING
+                                              "%s: NULL REQ %d\n",
+                                              __func__, ep_idx);
                                        flush(ep);
                                        break;
                                } else {
@@ -848,7 +846,7 @@ static void lh7a40x_out_epn(struct lh7a40x_udc *dev, u32 ep_idx, u32 intr)
 
        } else {
                /* Throw packet away.. */
-               printk("%s: No descriptor?!?\n", __FUNCTION__);
+               printk(KERN_WARNING "%s: No descriptor?!?\n", __func__);
                flush(ep);
        }
 }
@@ -890,7 +888,7 @@ static void lh7a40x_reset_intr(struct lh7a40x_udc *dev)
 #if 0                          /* def CONFIG_ARCH_LH7A404 */
        /* Does not work always... */
 
-       DEBUG("%s: %d\n", __FUNCTION__, dev->usb_address);
+       DEBUG("%s: %d\n", __func__, dev->usb_address);
 
        if (!dev->usb_address) {
                /*usb_set(USB_RESET_IO, USB_RESET);
@@ -920,7 +918,7 @@ static void lh7a40x_reset_intr(struct lh7a40x_udc *dev)
 /*
  *     lh7a40x usb client interrupt handler.
  */
-static irqreturn_t lh7a40x_udc_irq(int irq, void *_dev, struct pt_regs *r)
+static irqreturn_t lh7a40x_udc_irq(int irq, void *_dev)
 {
        struct lh7a40x_udc *dev = _dev;
 
@@ -940,7 +938,7 @@ static irqreturn_t lh7a40x_udc_irq(int irq, void *_dev, struct pt_regs *r)
                if (!intr_out && !intr_in && !intr_int)
                        break;
 
-               DEBUG("%s (on state %s)\n", __FUNCTION__,
+               DEBUG("%s (on state %s)\n", __func__,
                      state_names[dev->ep0state]);
                DEBUG("intr_out = %x\n", intr_out);
                DEBUG("intr_in  = %x\n", intr_in);
@@ -1020,14 +1018,14 @@ static int lh7a40x_ep_enable(struct usb_ep *_ep,
        struct lh7a40x_udc *dev;
        unsigned long flags;
 
-       DEBUG("%s, %p\n", __FUNCTION__, _ep);
+       DEBUG("%s, %p\n", __func__, _ep);
 
        ep = container_of(_ep, struct lh7a40x_ep, ep);
        if (!_ep || !desc || ep->desc || _ep->name == ep0name
            || desc->bDescriptorType != USB_DT_ENDPOINT
            || ep->bEndpointAddress != desc->bEndpointAddress
            || ep_maxpacket(ep) < le16_to_cpu(desc->wMaxPacketSize)) {
-               DEBUG("%s, bad ep or descriptor\n", __FUNCTION__);
+               DEBUG("%s, bad ep or descriptor\n", __func__);
                return -EINVAL;
        }
 
@@ -1035,7 +1033,7 @@ static int lh7a40x_ep_enable(struct usb_ep *_ep,
        if (ep->bmAttributes != desc->bmAttributes
            && ep->bmAttributes != USB_ENDPOINT_XFER_BULK
            && desc->bmAttributes != USB_ENDPOINT_XFER_INT) {
-               DEBUG("%s, %s type mismatch\n", __FUNCTION__, _ep->name);
+               DEBUG("%s, %s type mismatch\n", __func__, _ep->name);
                return -EINVAL;
        }
 
@@ -1043,13 +1041,13 @@ static int lh7a40x_ep_enable(struct usb_ep *_ep,
        if ((desc->bmAttributes == USB_ENDPOINT_XFER_BULK
             && le16_to_cpu(desc->wMaxPacketSize) != ep_maxpacket(ep))
            || !desc->wMaxPacketSize) {
-               DEBUG("%s, bad %s maxpacket\n", __FUNCTION__, _ep->name);
+               DEBUG("%s, bad %s maxpacket\n", __func__, _ep->name);
                return -ERANGE;
        }
 
        dev = ep->dev;
        if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) {
-               DEBUG("%s, bogus device state\n", __FUNCTION__);
+               DEBUG("%s, bogus device state\n", __func__);
                return -ESHUTDOWN;
        }
 
@@ -1060,12 +1058,12 @@ static int lh7a40x_ep_enable(struct usb_ep *_ep,
        ep->pio_irqs = 0;
        ep->ep.maxpacket = le16_to_cpu(desc->wMaxPacketSize);
 
+       spin_unlock_irqrestore(&ep->dev->lock, flags);
+
        /* Reset halt state (does flush) */
        lh7a40x_set_halt(_ep, 0);
 
-       spin_unlock_irqrestore(&ep->dev->lock, flags);
-
-       DEBUG("%s: enabled %s\n", __FUNCTION__, _ep->name);
+       DEBUG("%s: enabled %s\n", __func__, _ep->name);
        return 0;
 }
 
@@ -1077,11 +1075,11 @@ static int lh7a40x_ep_disable(struct usb_ep *_ep)
        struct lh7a40x_ep *ep;
        unsigned long flags;
 
-       DEBUG("%s, %p\n", __FUNCTION__, _ep);
+       DEBUG("%s, %p\n", __func__, _ep);
 
        ep = container_of(_ep, struct lh7a40x_ep, ep);
        if (!_ep || !ep->desc) {
-               DEBUG("%s, %s not enabled\n", __FUNCTION__,
+               DEBUG("%s, %s not enabled\n", __func__,
                      _ep ? ep->ep.name : NULL);
                return -EINVAL;
        }
@@ -1101,22 +1099,21 @@ static int lh7a40x_ep_disable(struct usb_ep *_ep)
 
        spin_unlock_irqrestore(&ep->dev->lock, flags);
 
-       DEBUG("%s: disabled %s\n", __FUNCTION__, _ep->name);
+       DEBUG("%s: disabled %s\n", __func__, _ep->name);
        return 0;
 }
 
 static struct usb_request *lh7a40x_alloc_request(struct usb_ep *ep,
-                                                int gfp_flags)
+                                                gfp_t gfp_flags)
 {
        struct lh7a40x_request *req;
 
-       DEBUG("%s, %p\n", __FUNCTION__, ep);
+       DEBUG("%s, %p\n", __func__, ep);
 
-       req = kmalloc(sizeof *req, gfp_flags);
+       req = kzalloc(sizeof(*req), gfp_flags);
        if (!req)
                return 0;
 
-       memset(req, 0, sizeof *req);
        INIT_LIST_HEAD(&req->queue);
 
        return &req->req;
@@ -1126,64 +1123,44 @@ static void lh7a40x_free_request(struct usb_ep *ep, struct usb_request *_req)
 {
        struct lh7a40x_request *req;
 
-       DEBUG("%s, %p\n", __FUNCTION__, ep);
+       DEBUG("%s, %p\n", __func__, ep);
 
        req = container_of(_req, struct lh7a40x_request, req);
        WARN_ON(!list_empty(&req->queue));
        kfree(req);
 }
 
-static void *lh7a40x_alloc_buffer(struct usb_ep *ep, unsigned bytes,
-                                 dma_addr_t * dma, int gfp_flags)
-{
-       char *retval;
-
-       DEBUG("%s (%p, %d, %d)\n", __FUNCTION__, ep, bytes, gfp_flags);
-
-       retval = kmalloc(bytes, gfp_flags & ~(__GFP_DMA | __GFP_HIGHMEM));
-       if (retval)
-               *dma = virt_to_bus(retval);
-       return retval;
-}
-
-static void lh7a40x_free_buffer(struct usb_ep *ep, void *buf, dma_addr_t dma,
-                               unsigned bytes)
-{
-       DEBUG("%s, %p\n", __FUNCTION__, ep);
-       kfree(buf);
-}
-
 /** Queue one request
  *  Kickstart transfer if needed
  *  NOTE: Sets INDEX register
  */
 static int lh7a40x_queue(struct usb_ep *_ep, struct usb_request *_req,
-                        int gfp_flags)
+                        gfp_t gfp_flags)
 {
        struct lh7a40x_request *req;
        struct lh7a40x_ep *ep;
        struct lh7a40x_udc *dev;
        unsigned long flags;
 
-       DEBUG("\n\n\n%s, %p\n", __FUNCTION__, _ep);
+       DEBUG("\n\n\n%s, %p\n", __func__, _ep);
 
        req = container_of(_req, struct lh7a40x_request, req);
        if (unlikely
            (!_req || !_req->complete || !_req->buf
             || !list_empty(&req->queue))) {
-               DEBUG("%s, bad params\n", __FUNCTION__);
+               DEBUG("%s, bad params\n", __func__);
                return -EINVAL;
        }
 
        ep = container_of(_ep, struct lh7a40x_ep, ep);
        if (unlikely(!_ep || (!ep->desc && ep->ep.name != ep0name))) {
-               DEBUG("%s, bad ep\n", __FUNCTION__);
+               DEBUG("%s, bad ep\n", __func__);
                return -EINVAL;
        }
 
        dev = ep->dev;
        if (unlikely(!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN)) {
-               DEBUG("%s, bogus device state %p\n", __FUNCTION__, dev->driver);
+               DEBUG("%s, bogus device state %p\n", __func__, dev->driver);
                return -ESHUTDOWN;
        }
 
@@ -1243,7 +1220,7 @@ static int lh7a40x_dequeue(struct usb_ep *_ep, struct usb_request *_req)
        struct lh7a40x_request *req;
        unsigned long flags;
 
-       DEBUG("%s, %p\n", __FUNCTION__, _ep);
+       DEBUG("%s, %p\n", __func__, _ep);
 
        ep = container_of(_ep, struct lh7a40x_ep, ep);
        if (!_ep || ep->ep.name == ep0name)
@@ -1278,13 +1255,13 @@ static int lh7a40x_set_halt(struct usb_ep *_ep, int value)
 
        ep = container_of(_ep, struct lh7a40x_ep, ep);
        if (unlikely(!_ep || (!ep->desc && ep->ep.name != ep0name))) {
-               DEBUG("%s, bad ep\n", __FUNCTION__);
+               DEBUG("%s, bad ep\n", __func__);
                return -EINVAL;
        }
 
        usb_set_index(ep_index(ep));
 
-       DEBUG("%s, ep %d, val %d\n", __FUNCTION__, ep_index(ep), value);
+       DEBUG("%s, ep %d, val %d\n", __func__, ep_index(ep), value);
 
        spin_lock_irqsave(&ep->dev->lock, flags);
 
@@ -1298,7 +1275,7 @@ static int lh7a40x_set_halt(struct usb_ep *_ep, int value)
                        /*
                         * Attempts to halt IN endpoints will fail (returning -EAGAIN)
                         * if any transfer requests are still queued, or if the controller
-                        * FIFO still holds bytes that the host hasn\92t collected.
+                        * FIFO still holds bytes that the host hasn't collected.
                         */
                        spin_unlock_irqrestore(&ep->dev->lock, flags);
                        DEBUG
@@ -1350,11 +1327,11 @@ static int lh7a40x_fifo_status(struct usb_ep *_ep)
 
        ep = container_of(_ep, struct lh7a40x_ep, ep);
        if (!_ep) {
-               DEBUG("%s, bad ep\n", __FUNCTION__);
+               DEBUG("%s, bad ep\n", __func__);
                return -ENODEV;
        }
 
-       DEBUG("%s, %d\n", __FUNCTION__, ep_index(ep));
+       DEBUG("%s, %d\n", __func__, ep_index(ep));
 
        /* LPD can't report unclaimed bytes from IN fifos */
        if (ep_is_in(ep))
@@ -1380,7 +1357,7 @@ static void lh7a40x_fifo_flush(struct usb_ep *_ep)
 
        ep = container_of(_ep, struct lh7a40x_ep, ep);
        if (unlikely(!_ep || (!ep->desc && ep->ep.name != ep0name))) {
-               DEBUG("%s, bad ep\n", __FUNCTION__);
+               DEBUG("%s, bad ep\n", __func__);
                return;
        }
 
@@ -1401,7 +1378,7 @@ static int write_fifo_ep0(struct lh7a40x_ep *ep, struct lh7a40x_request *req)
 
        max = ep_maxpacket(ep);
 
-       DEBUG_EP0("%s\n", __FUNCTION__);
+       DEBUG_EP0("%s\n", __func__);
 
        count = write_packet(ep, req, max);
 
@@ -1415,7 +1392,7 @@ static int write_fifo_ep0(struct lh7a40x_ep *ep, struct lh7a40x_request *req)
                        is_last = 1;
        }
 
-       DEBUG_EP0("%s: wrote %s %d bytes%s %d left %p\n", __FUNCTION__,
+       DEBUG_EP0("%s: wrote %s %d bytes%s %d left %p\n", __func__,
                  ep->ep.name, count,
                  is_last ? "/L" : "", req->req.length - req->req.actual, req);
 
@@ -1459,7 +1436,7 @@ static int read_fifo_ep0(struct lh7a40x_ep *ep, struct lh7a40x_request *req)
        unsigned bufferspace, count, is_short;
        volatile u32 *fifo = (volatile u32 *)ep->fifo;
 
-       DEBUG_EP0("%s\n", __FUNCTION__);
+       DEBUG_EP0("%s\n", __func__);
 
        csr = usb_read(USB_EP0_CSR);
        if (!(csr & USB_OUT_CSR1_OUT_PKT_RDY))
@@ -1517,7 +1494,7 @@ static int read_fifo_ep0(struct lh7a40x_ep *ep, struct lh7a40x_request *req)
  */
 static void udc_set_address(struct lh7a40x_udc *dev, unsigned char address)
 {
-       DEBUG_EP0("%s: %d\n", __FUNCTION__, address);
+       DEBUG_EP0("%s: %d\n", __func__, address);
        /* c.f. 15.1.2.2 Table 15-4 address will be used after DATA_END is set */
        dev->usb_address = address;
        usb_set((address & USB_FA_FUNCTION_ADDR), USB_FA);
@@ -1539,7 +1516,7 @@ static void lh7a40x_ep0_out(struct lh7a40x_udc *dev, u32 csr)
        struct lh7a40x_ep *ep = &dev->ep[0];
        int ret;
 
-       DEBUG_EP0("%s: %x\n", __FUNCTION__, csr);
+       DEBUG_EP0("%s: %x\n", __func__, csr);
 
        if (list_empty(&ep->queue))
                req = 0;
@@ -1558,13 +1535,13 @@ static void lh7a40x_ep0_out(struct lh7a40x_udc *dev, u32 csr)
                if (ret) {
                        /* Done! */
                        DEBUG_EP0("%s: finished, waiting for status\n",
-                                 __FUNCTION__);
+                                 __func__);
 
                        usb_set((EP0_CLR_OUT | EP0_DATA_END), USB_EP0_CSR);
                        dev->ep0state = WAIT_FOR_SETUP;
                } else {
                        /* Not done yet.. */
-                       DEBUG_EP0("%s: not finished\n", __FUNCTION__);
+                       DEBUG_EP0("%s: not finished\n", __func__);
                        usb_set(EP0_CLR_OUT, USB_EP0_CSR);
                }
        } else {
@@ -1581,7 +1558,7 @@ static int lh7a40x_ep0_in(struct lh7a40x_udc *dev, u32 csr)
        struct lh7a40x_ep *ep = &dev->ep[0];
        int ret, need_zlp = 0;
 
-       DEBUG_EP0("%s: %x\n", __FUNCTION__, csr);
+       DEBUG_EP0("%s: %x\n", __func__, csr);
 
        if (list_empty(&ep->queue))
                req = 0;
@@ -1589,7 +1566,7 @@ static int lh7a40x_ep0_in(struct lh7a40x_udc *dev, u32 csr)
                req = list_entry(ep->queue.next, struct lh7a40x_request, queue);
 
        if (!req) {
-               DEBUG_EP0("%s: NULL REQ\n", __FUNCTION__);
+               DEBUG_EP0("%s: NULL REQ\n", __func__);
                return 0;
        }
 
@@ -1610,17 +1587,17 @@ static int lh7a40x_ep0_in(struct lh7a40x_udc *dev, u32 csr)
 
        if (ret == 1 && !need_zlp) {
                /* Last packet */
-               DEBUG_EP0("%s: finished, waiting for status\n", __FUNCTION__);
+               DEBUG_EP0("%s: finished, waiting for status\n", __func__);
 
                usb_set((EP0_IN_PKT_RDY | EP0_DATA_END), USB_EP0_CSR);
                dev->ep0state = WAIT_FOR_SETUP;
        } else {
-               DEBUG_EP0("%s: not finished\n", __FUNCTION__);
+               DEBUG_EP0("%s: not finished\n", __func__);
                usb_set(EP0_IN_PKT_RDY, USB_EP0_CSR);
        }
 
        if (need_zlp) {
-               DEBUG_EP0("%s: Need ZLP!\n", __FUNCTION__);
+               DEBUG_EP0("%s: Need ZLP!\n", __func__);
                usb_set(EP0_IN_PKT_RDY, USB_EP0_CSR);
                dev->ep0state = DATA_STATE_NEED_ZLP;
        }
@@ -1719,7 +1696,7 @@ static void lh7a40x_ep0_setup(struct lh7a40x_udc *dev, u32 csr)
        struct usb_ctrlrequest ctrl;
        int i, bytes, is_in;
 
-       DEBUG_SETUP("%s: %x\n", __FUNCTION__, csr);
+       DEBUG_SETUP("%s: %x\n", __func__, csr);
 
        /* Nuke all previous transfers */
        nuke(ep, -EPROTO);
@@ -1773,6 +1750,7 @@ static void lh7a40x_ep0_setup(struct lh7a40x_udc *dev, u32 csr)
                                        break;
 
                                qep = &dev->ep[ep_num];
+                               spin_unlock(&dev->lock);
                                if (ctrl.bRequest == USB_REQ_SET_FEATURE) {
                                        DEBUG_SETUP("SET_FEATURE (%d)\n",
                                                    ep_num);
@@ -1782,6 +1760,7 @@ static void lh7a40x_ep0_setup(struct lh7a40x_udc *dev, u32 csr)
                                                    ep_num);
                                        lh7a40x_set_halt(&qep->ep, 0);
                                }
+                               spin_lock(&dev->lock);
                                usb_set_index(0);
 
                                /* Reply with a ZLP on next IN token */
@@ -1822,7 +1801,7 @@ static void lh7a40x_ep0_setup(struct lh7a40x_udc *dev, u32 csr)
  */
 static void lh7a40x_ep0_in_zlp(struct lh7a40x_udc *dev, u32 csr)
 {
-       DEBUG_EP0("%s: %x\n", __FUNCTION__, csr);
+       DEBUG_EP0("%s: %x\n", __func__, csr);
 
        /* c.f. Table 15-14 */
        usb_set((EP0_IN_PKT_RDY | EP0_DATA_END), USB_EP0_CSR);
@@ -1841,7 +1820,7 @@ static void lh7a40x_handle_ep0(struct lh7a40x_udc *dev, u32 intr)
        usb_set_index(0);
        csr = usb_read(USB_EP0_CSR);
 
-       DEBUG_EP0("%s: csr = %x\n", __FUNCTION__, csr);
+       DEBUG_EP0("%s: csr = %x\n", __func__, csr);
 
        /*
         * For overview of what we should be doing see c.f. Chapter 18.1.2.4
@@ -1855,7 +1834,7 @@ static void lh7a40x_handle_ep0(struct lh7a40x_udc *dev, u32 intr)
         *      - clear the SENT_STALL bit
         */
        if (csr & EP0_SENT_STALL) {
-               DEBUG_EP0("%s: EP0_SENT_STALL is set: %x\n", __FUNCTION__, csr);
+               DEBUG_EP0("%s: EP0_SENT_STALL is set: %x\n", __func__, csr);
                usb_clear((EP0_SENT_STALL | EP0_SEND_STALL), USB_EP0_CSR);
                nuke(ep, -ECONNABORTED);
                dev->ep0state = WAIT_FOR_SETUP;
@@ -1872,7 +1851,7 @@ static void lh7a40x_handle_ep0(struct lh7a40x_udc *dev, u32 intr)
         */
        if (!(csr & (EP0_IN_PKT_RDY | EP0_OUT_PKT_RDY))) {
                DEBUG_EP0("%s: IN_PKT_RDY and OUT_PKT_RDY are clear\n",
-                         __FUNCTION__);
+                         __func__);
 
                switch (dev->ep0state) {
                case DATA_STATE_XMIT:
@@ -1900,7 +1879,7 @@ static void lh7a40x_handle_ep0(struct lh7a40x_udc *dev, u32 intr)
         *      - set SERVICED_SETUP_END_BIT
         */
        if (csr & EP0_SETUP_END) {
-               DEBUG_EP0("%s: EP0_SETUP_END is set: %x\n", __FUNCTION__, csr);
+               DEBUG_EP0("%s: EP0_SETUP_END is set: %x\n", __func__, csr);
 
                usb_set(EP0_CLR_SETUP_END, USB_EP0_CSR);
 
@@ -1919,7 +1898,7 @@ static void lh7a40x_handle_ep0(struct lh7a40x_udc *dev, u32 intr)
         */
        if (csr & EP0_OUT_PKT_RDY) {
 
-               DEBUG_EP0("%s: EP0_OUT_PKT_RDY is set: %x\n", __FUNCTION__,
+               DEBUG_EP0("%s: EP0_OUT_PKT_RDY is set: %x\n", __func__,
                          csr);
 
                switch (dev->ep0state) {
@@ -1949,7 +1928,7 @@ static void lh7a40x_ep0_kick(struct lh7a40x_udc *dev, struct lh7a40x_ep *ep)
        usb_set_index(0);
        csr = usb_read(USB_EP0_CSR);
 
-       DEBUG_EP0("%s: %x\n", __FUNCTION__, csr);
+       DEBUG_EP0("%s: %x\n", __func__, csr);
 
        /* Clear "out packet ready" */
        usb_set(EP0_CLR_OUT, USB_EP0_CSR);
@@ -1972,7 +1951,7 @@ static int lh7a40x_udc_get_frame(struct usb_gadget *_gadget)
 {
        u32 frame1 = usb_read(USB_FRM_NUM1);    /* Least significant 8 bits */
        u32 frame2 = usb_read(USB_FRM_NUM2);    /* Most significant 3 bits */
-       DEBUG("%s, %p\n", __FUNCTION__, _gadget);
+       DEBUG("%s, %p\n", __func__, _gadget);
        return ((frame2 & 0x07) << 8) | (frame1 & 0xff);
 }
 
@@ -1993,7 +1972,7 @@ static const struct usb_gadget_ops lh7a40x_udc_ops = {
 
 static void nop_release(struct device *dev)
 {
-       DEBUG("%s %s\n", __FUNCTION__, dev->bus_id);
+       DEBUG("%s %s\n", __func__, dev_name(dev));
 }
 
 static struct lh7a40x_udc memory = {
@@ -2004,7 +1983,7 @@ static struct lh7a40x_udc memory = {
                   .ep0 = &memory.ep[0].ep,
                   .name = driver_name,
                   .dev = {
-                          .bus_id = "gadget",
+                          .init_name = "gadget",
                           .release = nop_release,
                           },
                   },
@@ -2083,28 +2062,28 @@ static struct lh7a40x_udc memory = {
 /*
  *     probe - binds to the platform device
  */
-static int lh7a40x_udc_probe(struct device *_dev)
+static int lh7a40x_udc_probe(struct platform_device *pdev)
 {
        struct lh7a40x_udc *dev = &memory;
        int retval;
 
-       DEBUG("%s: %p\n", __FUNCTION__, _dev);
+       DEBUG("%s: %p\n", __func__, pdev);
 
        spin_lock_init(&dev->lock);
-       dev->dev = _dev;
+       dev->dev = &pdev->dev;
 
        device_initialize(&dev->gadget.dev);
-       dev->gadget.dev.parent = _dev;
+       dev->gadget.dev.parent = &pdev->dev;
 
        the_controller = dev;
-       dev_set_drvdata(_dev, dev);
+       platform_set_drvdata(pdev, dev);
 
        udc_disable(dev);
        udc_reinit(dev);
 
        /* irq setup after old hardware state is cleaned up */
        retval =
-           request_irq(IRQ_USBINTR, lh7a40x_udc_irq, SA_INTERRUPT, driver_name,
+           request_irq(IRQ_USBINTR, lh7a40x_udc_irq, IRQF_DISABLED, driver_name,
                        dev);
        if (retval != 0) {
                DEBUG(KERN_ERR "%s: can't get irq %i, err %d\n", driver_name,
@@ -2117,19 +2096,21 @@ static int lh7a40x_udc_probe(struct device *_dev)
        return retval;
 }
 
-static int lh7a40x_udc_remove(struct device *_dev)
+static int lh7a40x_udc_remove(struct platform_device *pdev)
 {
-       struct lh7a40x_udc *dev = _dev->driver_data;
+       struct lh7a40x_udc *dev = platform_get_drvdata(pdev);
+
+       DEBUG("%s: %p\n", __func__, pdev);
 
-       DEBUG("%s: %p\n", __FUNCTION__, dev);
+       if (dev->driver)
+               return -EBUSY;
 
        udc_disable(dev);
        remove_proc_files();
-       usb_gadget_unregister_driver(dev->driver);
 
        free_irq(IRQ_USBINTR, dev);
 
-       dev_set_drvdata(_dev, 0);
+       platform_set_drvdata(pdev, 0);
 
        the_controller = 0;
 
@@ -2138,25 +2119,27 @@ static int lh7a40x_udc_remove(struct device *_dev)
 
 /*-------------------------------------------------------------------------*/
 
-static struct device_driver udc_driver = {
-       .name = (char *)driver_name,
-       .bus = &platform_bus_type,
+static struct platform_driver udc_driver = {
        .probe = lh7a40x_udc_probe,
-       .remove = lh7a40x_udc_remove
+       .remove = lh7a40x_udc_remove,
            /* FIXME power management support */
            /* .suspend = ... disable UDC */
            /* .resume = ... re-enable UDC */
+       .driver = {
+               .name = (char *)driver_name,
+               .owner = THIS_MODULE,
+       },
 };
 
 static int __init udc_init(void)
 {
-       DEBUG("%s: %s version %s\n", __FUNCTION__, driver_name, DRIVER_VERSION);
-       return driver_register(&udc_driver);
+       DEBUG("%s: %s version %s\n", __func__, driver_name, DRIVER_VERSION);
+       return platform_driver_register(&udc_driver);
 }
 
 static void __exit udc_exit(void)
 {
-       driver_unregister(&udc_driver);
+       platform_driver_unregister(&udc_driver);
 }
 
 module_init(udc_init);
@@ -2165,3 +2148,4 @@ module_exit(udc_exit);
 MODULE_DESCRIPTION(DRIVER_DESC);
 MODULE_AUTHOR("Mikko Lahteenmaki, Bo Henriksen");
 MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:lh7a40x_udc");