Merge to Fedora kernel-2.6.18-1.2224_FC5 patched with stable patch-2.6.18.1-vs2.0...
[linux-2.6.git] / drivers / usb / gadget / lh7a40x_udc.c
index 772627e..36db725 100644 (file)
@@ -21,6 +21,8 @@
  *
  */
 
+#include <linux/platform_device.h>
+
 #include "lh7a40x_udc.h"
 
 //#define DEBUG printk
@@ -54,7 +56,6 @@ static const char ep0name[] = "ep0-control";
 /*
   Local definintions.
 */
-#define UDC_PROC_FILE
 
 #ifndef NO_STATES
 static char *state_names[] = {
@@ -72,13 +73,13 @@ 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);
+                                 gfp_t);
 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);
@@ -192,7 +193,7 @@ static __inline__ void usb_clear(u32 val, u32 port)
  */
 #define is_usb_connected()             get_portc_pdr(2)
 
-#ifdef UDC_PROC_FILE
+#ifdef CONFIG_USB_GADGET_DEBUG_FILES
 
 static const char proc_node_name[] = "driver/udc";
 
@@ -248,12 +249,12 @@ udc_proc_read(char *page, char **start, off_t off, int count,
 #define create_proc_files()    create_proc_read_entry(proc_node_name, 0, NULL, udc_proc_read, dev)
 #define remove_proc_files()    remove_proc_entry(proc_node_name, NULL)
 
-#else                          /* !UDC_PROC_FILE */
+#else  /* !CONFIG_USB_GADGET_DEBUG_FILES */
 
 #define create_proc_files() do {} while (0)
 #define remove_proc_files() do {} while (0)
 
-#endif                         /* UDC_PROC_FILE */
+#endif /* CONFIG_USB_GADGET_DEBUG_FILES */
 
 /*
  *     udc_disable - disable USB device controller
@@ -706,7 +707,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));
 }
@@ -1061,11 +1062,11 @@ 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);
        return 0;
 }
@@ -1107,17 +1108,16 @@ static int lh7a40x_ep_disable(struct usb_ep *_ep)
 }
 
 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);
 
-       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;
@@ -1135,7 +1135,7 @@ static void lh7a40x_free_request(struct usb_ep *ep, struct usb_request *_req)
 }
 
 static void *lh7a40x_alloc_buffer(struct usb_ep *ep, unsigned bytes,
-                                 dma_addr_t * dma, int gfp_flags)
+                                 dma_addr_t * dma, gfp_t gfp_flags)
 {
        char *retval;
 
@@ -1159,7 +1159,7 @@ static void lh7a40x_free_buffer(struct usb_ep *ep, void *buf, dma_addr_t dma,
  *  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;
@@ -1774,6 +1774,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);
@@ -1783,6 +1784,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 */
@@ -2084,28 +2086,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", __FUNCTION__, 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,
@@ -2118,11 +2120,11 @@ 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", __FUNCTION__, dev);
+       DEBUG("%s: %p\n", __FUNCTION__, pdev);
 
        udc_disable(dev);
        remove_proc_files();
@@ -2130,7 +2132,7 @@ static int lh7a40x_udc_remove(struct device *_dev)
 
        free_irq(IRQ_USBINTR, dev);
 
-       dev_set_drvdata(_dev, 0);
+       platform_set_drvdata(pdev, 0);
 
        the_controller = 0;
 
@@ -2139,25 +2141,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);
+       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);