Merge ../linus
[linux-drm-fsl-dcu.git] / drivers / char / sx.c
index f506ee3243d15cf2de435c4df25d223a4334b4bd..a3008ce13015496c5eb409429379e769f93f904c 100644 (file)
@@ -2485,7 +2485,8 @@ static void __exit sx_release_drivers(void)
        func_exit();
 }
 
-static void __devexit sx_remove_card(struct sx_board *board)
+static void __devexit sx_remove_card(struct sx_board *board,
+               struct pci_dev *pdev)
 {
        if (board->flags & SX_BOARD_INITIALIZED) {
                /* The board should stop messing with us. (actually I mean the
@@ -2496,7 +2497,13 @@ static void __devexit sx_remove_card(struct sx_board *board)
 
                /* It is safe/allowed to del_timer a non-active timer */
                del_timer(&board->timer);
-               iounmap(board->base);
+               if (pdev) {
+                       pci_iounmap(pdev, board->base);
+                       pci_release_region(pdev, IS_CF_BOARD(board) ? 3 : 2);
+               } else {
+                       iounmap(board->base);
+                       release_region(board->hw_base, board->hw_len);
+               }
 
                board->flags &= ~(SX_BOARD_INITIALIZED | SX_BOARD_PRESENT);
        }
@@ -2534,8 +2541,17 @@ static int __devinit sx_eisa_probe(struct device *dev)
 
        board->hw_base = ((inb(eisa_slot + 0xc01) << 8) +
                          inb(eisa_slot + 0xc00)) << 16;
+       board->hw_len = SI2_EISA_WINDOW_LEN;
+       if (!request_region(board->hw_base, board->hw_len, "sx")) {
+               dev_err(dev, "can't request region\n");
+               goto err_flag;
+       }
        board->base2 =
        board->base = ioremap(board->hw_base, SI2_EISA_WINDOW_LEN);
+       if (!board->base) {
+               dev_err(dev, "can't remap memory\n");
+               goto err_reg;
+       }
 
        sx_dprintk(SX_DEBUG_PROBE, "IO hw_base address: %lx\n", board->hw_base);
        sx_dprintk(SX_DEBUG_PROBE, "base: %p\n", board->base);
@@ -2550,6 +2566,9 @@ static int __devinit sx_eisa_probe(struct device *dev)
        return 0;
 err_unmap:
        iounmap(board->base);
+err_reg:
+       release_region(board->hw_base, board->hw_len);
+err_flag:
        board->flags &= ~SX_BOARD_PRESENT;
 err:
        return retval;
@@ -2559,7 +2578,7 @@ static int __devexit sx_eisa_remove(struct device *dev)
 {
        struct sx_board *board = dev_get_drvdata(dev);
 
-       sx_remove_card(board);
+       sx_remove_card(board, NULL);
 
        return 0;
 }
@@ -2618,7 +2637,7 @@ static int __devinit sx_pci_probe(struct pci_dev *pdev,
                                  const struct pci_device_id *ent)
 {
        struct sx_board *board;
-       unsigned int i;
+       unsigned int i, reg;
        int retval = -EIO;
 
        mutex_lock(&sx_boards_lock);
@@ -2640,15 +2659,18 @@ static int __devinit sx_pci_probe(struct pci_dev *pdev,
                SX_CFPCI_BOARD;
 
        /* CF boards use base address 3.... */
-       if (IS_CF_BOARD(board))
-               board->hw_base = pci_resource_start(pdev, 3);
-       else
-               board->hw_base = pci_resource_start(pdev, 2);
+       reg = IS_CF_BOARD(board) ? 3 : 2;
+       retval = pci_request_region(pdev, reg, "sx");
+       if (retval) {
+               dev_err(&pdev->dev, "can't request region\n");
+               goto err_flag;
+       }
+       board->hw_base = pci_resource_start(pdev, reg);
        board->base2 =
-       board->base = ioremap(board->hw_base, WINDOW_LEN(board));
+       board->base = pci_iomap(pdev, reg, WINDOW_LEN(board));
        if (!board->base) {
                dev_err(&pdev->dev, "ioremap failed\n");
-               goto err_flag;
+               goto err_reg;
        }
 
        /* Most of the stuff on the CF board is offset by 0x18000 ....  */
@@ -2671,7 +2693,9 @@ static int __devinit sx_pci_probe(struct pci_dev *pdev,
 
        return 0;
 err_unmap:
-       iounmap(board->base2);
+       pci_iounmap(pdev, board->base);
+err_reg:
+       pci_release_region(pdev, reg);
 err_flag:
        board->flags &= ~SX_BOARD_PRESENT;
 err:
@@ -2682,7 +2706,7 @@ static void __devexit sx_pci_remove(struct pci_dev *pdev)
 {
        struct sx_board *board = pci_get_drvdata(pdev);
 
-       sx_remove_card(board);
+       sx_remove_card(board, pdev);
 }
 
 /* Specialix has a whole bunch of cards with 0x2000 as the device ID. They say
@@ -2734,8 +2758,13 @@ static int __init sx_init(void)
        for (i = 0; i < NR_SX_ADDRS; i++) {
                board = &boards[found];
                board->hw_base = sx_probe_addrs[i];
+               board->hw_len = SX_WINDOW_LEN;
+               if (!request_region(board->hw_base, board->hw_len, "sx"))
+                       continue;
                board->base2 =
-               board->base = ioremap(board->hw_base, SX_WINDOW_LEN);
+               board->base = ioremap(board->hw_base, board->hw_len);
+               if (!board->base)
+                       goto err_sx_reg;
                board->flags &= ~SX_BOARD_TYPE;
                board->flags |= SX_ISA_BOARD;
                board->irq = sx_irqmask ? -1 : 0;
@@ -2745,14 +2774,21 @@ static int __init sx_init(void)
                        found++;
                } else {
                        iounmap(board->base);
+err_sx_reg:
+                       release_region(board->hw_base, board->hw_len);
                }
        }
 
        for (i = 0; i < NR_SI_ADDRS; i++) {
                board = &boards[found];
                board->hw_base = si_probe_addrs[i];
+               board->hw_len = SI2_ISA_WINDOW_LEN;
+               if (!request_region(board->hw_base, board->hw_len, "sx"))
+                       continue;
                board->base2 =
-               board->base = ioremap(board->hw_base, SI2_ISA_WINDOW_LEN);
+               board->base = ioremap(board->hw_base, board->hw_len);
+               if (!board->base)
+                       goto err_si_reg;
                board->flags &= ~SX_BOARD_TYPE;
                board->flags |= SI_ISA_BOARD;
                board->irq = sx_irqmask ? -1 : 0;
@@ -2762,13 +2798,20 @@ static int __init sx_init(void)
                        found++;
                } else {
                        iounmap(board->base);
+err_si_reg:
+                       release_region(board->hw_base, board->hw_len);
                }
        }
        for (i = 0; i < NR_SI1_ADDRS; i++) {
                board = &boards[found];
                board->hw_base = si1_probe_addrs[i];
+               board->hw_len = SI1_ISA_WINDOW_LEN;
+               if (!request_region(board->hw_base, board->hw_len, "sx"))
+                       continue;
                board->base2 =
-               board->base = ioremap(board->hw_base, SI1_ISA_WINDOW_LEN);
+               board->base = ioremap(board->hw_base, board->hw_len);
+               if (!board->base)
+                       goto err_si1_reg;
                board->flags &= ~SX_BOARD_TYPE;
                board->flags |= SI1_ISA_BOARD;
                board->irq = sx_irqmask ? -1 : 0;
@@ -2778,6 +2821,8 @@ static int __init sx_init(void)
                        found++;
                } else {
                        iounmap(board->base);
+err_si1_reg:
+                       release_region(board->hw_base, board->hw_len);
                }
        }
 #endif
@@ -2812,7 +2857,7 @@ static void __exit sx_exit(void)
        pci_unregister_driver(&sx_pcidriver);
 
        for (i = 0; i < SX_NBOARDS; i++)
-               sx_remove_card(&boards[i]);
+               sx_remove_card(&boards[i], NULL);
 
        if (misc_deregister(&sx_fw_device) < 0) {
                printk(KERN_INFO "sx: couldn't deregister firmware loader "