Merge git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging-2.6
[sfrench/cifs-2.6.git] / drivers / usb / host / isp1362-hcd.c
index 5c774ab9825272ead015fe3420f00a71dba81616..42971657fde2953f2d7798e5b45d4d14796fb16d 100644 (file)
@@ -80,7 +80,7 @@
 #include <linux/platform_device.h>
 #include <linux/pm.h>
 #include <linux/io.h>
-#include <linux/bitops.h>
+#include <linux/bitmap.h>
 
 #include <asm/irq.h>
 #include <asm/system.h>
@@ -190,10 +190,8 @@ static int claim_ptd_buffers(struct isp1362_ep_queue *epq,
                             struct isp1362_ep *ep, u16 len)
 {
        int ptd_offset = -EINVAL;
-       int index;
        int num_ptds = ((len + PTD_HEADER_SIZE - 1) / epq->blk_size) + 1;
-       int found = -1;
-       int last = -1;
+       int found;
 
        BUG_ON(len > epq->buf_size);
 
@@ -205,20 +203,9 @@ static int claim_ptd_buffers(struct isp1362_ep_queue *epq,
                    epq->name, len, epq->blk_size, num_ptds, epq->buf_map, epq->skip_map);
        BUG_ON(ep->num_ptds != 0);
 
-       for (index = 0; index <= epq->buf_count - num_ptds; index++) {
-               if (test_bit(index, &epq->buf_map))
-                       continue;
-               found = index;
-               for (last = index + 1; last < index + num_ptds; last++) {
-                       if (test_bit(last, &epq->buf_map)) {
-                               found = -1;
-                               break;
-                       }
-               }
-               if (found >= 0)
-                       break;
-       }
-       if (found < 0)
+       found = bitmap_find_next_zero_area(&epq->buf_map, epq->buf_count, 0,
+                                               num_ptds, 0);
+       if (found >= epq->buf_count)
                return -EOVERFLOW;
 
        DBG(1, "%s: Found %d PTDs[%d] for %d/%d byte\n", __func__,
@@ -230,8 +217,7 @@ static int claim_ptd_buffers(struct isp1362_ep_queue *epq,
        epq->buf_avail -= num_ptds;
        BUG_ON(epq->buf_avail > epq->buf_count);
        ep->ptd_index = found;
-       for (index = found; index < last; index++)
-               __set_bit(index, &epq->buf_map);
+       bitmap_set(&epq->buf_map, found, num_ptds);
        DBG(1, "%s: Done %s PTD[%d] $%04x, avail %d count %d claimed %d %08lx:%08lx\n",
            __func__, epq->name, ep->ptd_index, ep->ptd_offset,
            epq->buf_avail, epq->buf_count, num_ptds, epq->buf_map, epq->skip_map);
@@ -2284,10 +2270,10 @@ static int isp1362_mem_config(struct usb_hcd *hcd)
        dev_info(hcd->self.controller, "ISP1362 Memory usage:\n");
        dev_info(hcd->self.controller, "  ISTL:    2 * %4d:     %4d @ $%04x:$%04x\n",
                 istl_size / 2, istl_size, 0, istl_size / 2);
-       dev_info(hcd->self.controller, "  INTL: %4d * (%3lu+8):  %4d @ $%04x\n",
+       dev_info(hcd->self.controller, "  INTL: %4d * (%3zu+8):  %4d @ $%04x\n",
                 ISP1362_INTL_BUFFERS, intl_blksize - PTD_HEADER_SIZE,
                 intl_size, istl_size);
-       dev_info(hcd->self.controller, "  ATL : %4d * (%3lu+8):  %4d @ $%04x\n",
+       dev_info(hcd->self.controller, "  ATL : %4d * (%3zu+8):  %4d @ $%04x\n",
                 atl_buffers, atl_blksize - PTD_HEADER_SIZE,
                 atl_size, istl_size + intl_size);
        dev_info(hcd->self.controller, "  USED/FREE:   %4d      %4d\n", total,
@@ -2711,6 +2697,8 @@ static int __init isp1362_probe(struct platform_device *pdev)
        void __iomem *data_reg;
        int irq;
        int retval = 0;
+       struct resource *irq_res;
+       unsigned int irq_flags = 0;
 
        /* basic sanity checks first.  board-specific init logic should
         * have initialized this the three resources and probably board
@@ -2724,11 +2712,12 @@ static int __init isp1362_probe(struct platform_device *pdev)
 
        data = platform_get_resource(pdev, IORESOURCE_MEM, 0);
        addr = platform_get_resource(pdev, IORESOURCE_MEM, 1);
-       irq = platform_get_irq(pdev, 0);
-       if (!addr || !data || irq < 0) {
+       irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
+       if (!addr || !data || !irq_res) {
                retval = -ENODEV;
                goto err1;
        }
+       irq = irq_res->start;
 
 #ifdef CONFIG_USB_HCD_DMA
        if (pdev->dev.dma_mask) {
@@ -2795,12 +2784,16 @@ static int __init isp1362_probe(struct platform_device *pdev)
        }
 #endif
 
-#ifdef CONFIG_ARM
-       if (isp1362_hcd->board)
-               set_irq_type(irq, isp1362_hcd->board->int_act_high ? IRQT_RISING : IRQT_FALLING);
-#endif
+       if (irq_res->flags & IORESOURCE_IRQ_HIGHEDGE)
+               irq_flags |= IRQF_TRIGGER_RISING;
+       if (irq_res->flags & IORESOURCE_IRQ_LOWEDGE)
+               irq_flags |= IRQF_TRIGGER_FALLING;
+       if (irq_res->flags & IORESOURCE_IRQ_HIGHLEVEL)
+               irq_flags |= IRQF_TRIGGER_HIGH;
+       if (irq_res->flags & IORESOURCE_IRQ_LOWLEVEL)
+               irq_flags |= IRQF_TRIGGER_LOW;
 
-       retval = usb_add_hcd(hcd, irq, IRQF_TRIGGER_LOW | IRQF_DISABLED | IRQF_SHARED);
+       retval = usb_add_hcd(hcd, irq, irq_flags | IRQF_DISABLED | IRQF_SHARED);
        if (retval != 0)
                goto err6;
        pr_info("%s, irq %d\n", hcd->product_desc, irq);