aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char/stallion.c
diff options
context:
space:
mode:
authorJiri Slaby <jirislaby@gmail.com>2006-12-08 05:39:09 -0500
committerLinus Torvalds <torvalds@woody.osdl.org>2006-12-08 11:28:59 -0500
commitb1b84fe0d76b89534da706372ef719bbaa9fef0a (patch)
tree3a97b2874daa4b0e93c9f8f6f907f82e77d33732 /drivers/char/stallion.c
parent30f4218ffc5500e6a622a680f01133f9af65f07d (diff)
[PATCH] Char: stallion, convert to pci probing
Convert stallion driver to pci probing instead of pci_dev_get iteration. Signed-off-by: Jiri Slaby <jirislaby@gmail.com> Cc: Alan Cox <alan@lxorguk.ukuu.org.uk> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'drivers/char/stallion.c')
-rw-r--r--drivers/char/stallion.c165
1 files changed, 83 insertions, 82 deletions
diff --git a/drivers/char/stallion.c b/drivers/char/stallion.c
index 71bfdccfb42e..6a9feb69632d 100644
--- a/drivers/char/stallion.c
+++ b/drivers/char/stallion.c
@@ -381,8 +381,6 @@ static spinlock_t stallion_lock; /* Guard the tty driver */
381 381
382/*****************************************************************************/ 382/*****************************************************************************/
383 383
384#ifdef CONFIG_PCI
385
386/* 384/*
387 * Define the Stallion PCI vendor and device IDs. 385 * Define the Stallion PCI vendor and device IDs.
388 */ 386 */
@@ -402,22 +400,19 @@ static spinlock_t stallion_lock; /* Guard the tty driver */
402/* 400/*
403 * Define structure to hold all Stallion PCI boards. 401 * Define structure to hold all Stallion PCI boards.
404 */ 402 */
405typedef struct stlpcibrd {
406 unsigned short vendid;
407 unsigned short devid;
408 int brdtype;
409} stlpcibrd_t;
410
411static stlpcibrd_t stl_pcibrds[] = {
412 { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI864, BRD_ECH64PCI },
413 { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_EIOPCI, BRD_EASYIOPCI },
414 { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI832, BRD_ECHPCI },
415 { PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_87410, BRD_ECHPCI },
416};
417 403
418static int stl_nrpcibrds = ARRAY_SIZE(stl_pcibrds); 404static struct pci_device_id stl_pcibrds[] = {
419 405 { PCI_DEVICE(PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI864),
420#endif 406 .driver_data = BRD_ECH64PCI },
407 { PCI_DEVICE(PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_EIOPCI),
408 .driver_data = BRD_EASYIOPCI },
409 { PCI_DEVICE(PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI832),
410 .driver_data = BRD_ECHPCI },
411 { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_87410),
412 .driver_data = BRD_ECHPCI },
413 { }
414};
415MODULE_DEVICE_TABLE(pci, stl_pcibrds);
421 416
422/*****************************************************************************/ 417/*****************************************************************************/
423 418
@@ -2390,24 +2385,52 @@ static int __init stl_getbrdnr(void)
2390 return(-1); 2385 return(-1);
2391} 2386}
2392 2387
2393/*****************************************************************************/ 2388static void stl_cleanup_panels(struct stlbrd *brdp)
2389{
2390 struct stlpanel *panelp;
2391 struct stlport *portp;
2392 unsigned int j, k;
2394 2393
2395#ifdef CONFIG_PCI 2394 for (j = 0; j < STL_MAXPANELS; j++) {
2395 panelp = brdp->panels[j];
2396 if (panelp == NULL)
2397 continue;
2398 for (k = 0; k < STL_PORTSPERPANEL; k++) {
2399 portp = panelp->ports[k];
2400 if (portp == NULL)
2401 continue;
2402 if (portp->tty != NULL)
2403 stl_hangup(portp->tty);
2404 kfree(portp->tx.buf);
2405 kfree(portp);
2406 }
2407 kfree(panelp);
2408 }
2409}
2396 2410
2411/*****************************************************************************/
2397/* 2412/*
2398 * We have a Stallion board. Allocate a board structure and 2413 * We have a Stallion board. Allocate a board structure and
2399 * initialize it. Read its IO and IRQ resources from PCI 2414 * initialize it. Read its IO and IRQ resources from PCI
2400 * configuration space. 2415 * configuration space.
2401 */ 2416 */
2402 2417
2403static int __init stl_initpcibrd(int brdtype, struct pci_dev *devp) 2418static int __devinit stl_pciprobe(struct pci_dev *pdev,
2419 const struct pci_device_id *ent)
2404{ 2420{
2405 struct stlbrd *brdp; 2421 struct stlbrd *brdp;
2422 unsigned int brdtype = ent->driver_data;
2406 2423
2407 pr_debug("stl_initpcibrd(brdtype=%d,busnr=%x,devnr=%x)\n", brdtype, 2424 pr_debug("stl_initpcibrd(brdtype=%d,busnr=%x,devnr=%x)\n", brdtype,
2408 devp->bus->number, devp->devfn); 2425 pdev->bus->number, pdev->devfn);
2426
2427 if ((pdev->class >> 8) == PCI_CLASS_STORAGE_IDE)
2428 return -ENODEV;
2429
2430 dev_info(&pdev->dev, "please, report this to LKML: %x/%x/%x\n",
2431 pdev->vendor, pdev->device, pdev->class);
2409 2432
2410 if (pci_enable_device(devp)) 2433 if (pci_enable_device(pdev))
2411 return(-EIO); 2434 return(-EIO);
2412 if ((brdp = stl_allocbrd()) == NULL) 2435 if ((brdp = stl_allocbrd()) == NULL)
2413 return(-ENOMEM); 2436 return(-ENOMEM);
@@ -2423,8 +2446,8 @@ static int __init stl_initpcibrd(int brdtype, struct pci_dev *devp)
2423 * so set up io addresses based on board type. 2446 * so set up io addresses based on board type.
2424 */ 2447 */
2425 pr_debug("%s(%d): BAR[]=%Lx,%Lx,%Lx,%Lx IRQ=%x\n", __FILE__, __LINE__, 2448 pr_debug("%s(%d): BAR[]=%Lx,%Lx,%Lx,%Lx IRQ=%x\n", __FILE__, __LINE__,
2426 pci_resource_start(devp, 0), pci_resource_start(devp, 1), 2449 pci_resource_start(pdev, 0), pci_resource_start(pdev, 1),
2427 pci_resource_start(devp, 2), pci_resource_start(devp, 3), devp->irq); 2450 pci_resource_start(pdev, 2), pci_resource_start(pdev, 3), pdev->irq);
2428 2451
2429/* 2452/*
2430 * We have all resources from the board, so let's setup the actual 2453 * We have all resources from the board, so let's setup the actual
@@ -2432,63 +2455,52 @@ static int __init stl_initpcibrd(int brdtype, struct pci_dev *devp)
2432 */ 2455 */
2433 switch (brdtype) { 2456 switch (brdtype) {
2434 case BRD_ECHPCI: 2457 case BRD_ECHPCI:
2435 brdp->ioaddr2 = pci_resource_start(devp, 0); 2458 brdp->ioaddr2 = pci_resource_start(pdev, 0);
2436 brdp->ioaddr1 = pci_resource_start(devp, 1); 2459 brdp->ioaddr1 = pci_resource_start(pdev, 1);
2437 break; 2460 break;
2438 case BRD_ECH64PCI: 2461 case BRD_ECH64PCI:
2439 brdp->ioaddr2 = pci_resource_start(devp, 2); 2462 brdp->ioaddr2 = pci_resource_start(pdev, 2);
2440 brdp->ioaddr1 = pci_resource_start(devp, 1); 2463 brdp->ioaddr1 = pci_resource_start(pdev, 1);
2441 break; 2464 break;
2442 case BRD_EASYIOPCI: 2465 case BRD_EASYIOPCI:
2443 brdp->ioaddr1 = pci_resource_start(devp, 2); 2466 brdp->ioaddr1 = pci_resource_start(pdev, 2);
2444 brdp->ioaddr2 = pci_resource_start(devp, 1); 2467 brdp->ioaddr2 = pci_resource_start(pdev, 1);
2445 break; 2468 break;
2446 default: 2469 default:
2447 printk("STALLION: unknown PCI board type=%d\n", brdtype); 2470 printk("STALLION: unknown PCI board type=%d\n", brdtype);
2448 break; 2471 break;
2449 } 2472 }
2450 2473
2451 brdp->irq = devp->irq; 2474 brdp->irq = pdev->irq;
2452 stl_brdinit(brdp); 2475 stl_brdinit(brdp);
2453 2476
2477 pci_set_drvdata(pdev, brdp);
2478
2454 return(0); 2479 return(0);
2455} 2480}
2456 2481
2457/*****************************************************************************/ 2482static void __devexit stl_pciremove(struct pci_dev *pdev)
2458
2459/*
2460 * Find all Stallion PCI boards that might be installed. Initialize each
2461 * one as it is found.
2462 */
2463
2464
2465static int __init stl_findpcibrds(void)
2466{ 2483{
2467 struct pci_dev *dev = NULL; 2484 struct stlbrd *brdp = pci_get_drvdata(pdev);
2468 int i, rc;
2469
2470 pr_debug("stl_findpcibrds()\n");
2471 2485
2472 for (i = 0; (i < stl_nrpcibrds); i++) 2486 free_irq(brdp->irq, brdp);
2473 while ((dev = pci_get_device(stl_pcibrds[i].vendid,
2474 stl_pcibrds[i].devid, dev))) {
2475 2487
2476/* 2488 stl_cleanup_panels(brdp);
2477 * Found a device on the PCI bus that has our vendor and
2478 * device ID. Need to check now that it is really us.
2479 */
2480 if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE)
2481 continue;
2482 2489
2483 rc = stl_initpcibrd(stl_pcibrds[i].brdtype, dev); 2490 release_region(brdp->ioaddr1, brdp->iosize1);
2484 if (rc) 2491 if (brdp->iosize2 > 0)
2485 return(rc); 2492 release_region(brdp->ioaddr2, brdp->iosize2);
2486 }
2487 2493
2488 return(0); 2494 stl_brds[brdp->brdnr] = NULL;
2495 kfree(brdp);
2489} 2496}
2490 2497
2491#endif 2498static struct pci_driver stl_pcidriver = {
2499 .name = "stallion",
2500 .id_table = stl_pcibrds,
2501 .probe = stl_pciprobe,
2502 .remove = __devexit_p(stl_pciremove)
2503};
2492 2504
2493/*****************************************************************************/ 2505/*****************************************************************************/
2494 2506
@@ -2535,9 +2547,6 @@ static int __init stl_initbrds(void)
2535 * line options or auto-detected on the PCI bus. 2547 * line options or auto-detected on the PCI bus.
2536 */ 2548 */
2537 stl_argbrds(); 2549 stl_argbrds();
2538#ifdef CONFIG_PCI
2539 stl_findpcibrds();
2540#endif
2541 2550
2542 return(0); 2551 return(0);
2543} 2552}
@@ -4776,7 +4785,7 @@ static void stl_sc26198otherisr(struct stlport *portp, unsigned int iack)
4776 */ 4785 */
4777static int __init stallion_module_init(void) 4786static int __init stallion_module_init(void)
4778{ 4787{
4779 unsigned int i; 4788 unsigned int i, retval;
4780 4789
4781 printk(KERN_INFO "%s: version %s\n", stl_drvtitle, stl_drvversion); 4790 printk(KERN_INFO "%s: version %s\n", stl_drvtitle, stl_drvversion);
4782 4791
@@ -4785,6 +4794,10 @@ static int __init stallion_module_init(void)
4785 4794
4786 stl_initbrds(); 4795 stl_initbrds();
4787 4796
4797 retval = pci_register_driver(&stl_pcidriver);
4798 if (retval)
4799 goto err;
4800
4788 stl_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS); 4801 stl_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS);
4789 if (!stl_serial) 4802 if (!stl_serial)
4790 return -1; 4803 return -1;
@@ -4820,14 +4833,14 @@ static int __init stallion_module_init(void)
4820 } 4833 }
4821 4834
4822 return 0; 4835 return 0;
4836err:
4837 return retval;
4823} 4838}
4824 4839
4825static void __exit stallion_module_exit(void) 4840static void __exit stallion_module_exit(void)
4826{ 4841{
4827 struct stlbrd *brdp; 4842 struct stlbrd *brdp;
4828 struct stlpanel *panelp; 4843 int i;
4829 struct stlport *portp;
4830 int i, j, k;
4831 4844
4832 pr_debug("cleanup_module()\n"); 4845 pr_debug("cleanup_module()\n");
4833 4846
@@ -4854,27 +4867,15 @@ static void __exit stallion_module_exit(void)
4854 "errno=%d\n", -i); 4867 "errno=%d\n", -i);
4855 class_destroy(stallion_class); 4868 class_destroy(stallion_class);
4856 4869
4870 pci_unregister_driver(&stl_pcidriver);
4871
4857 for (i = 0; (i < stl_nrbrds); i++) { 4872 for (i = 0; (i < stl_nrbrds); i++) {
4858 if ((brdp = stl_brds[i]) == NULL) 4873 if ((brdp = stl_brds[i]) == NULL)
4859 continue; 4874 continue;
4860 4875
4861 free_irq(brdp->irq, brdp); 4876 free_irq(brdp->irq, brdp);
4862 4877
4863 for (j = 0; (j < STL_MAXPANELS); j++) { 4878 stl_cleanup_panels(brdp);
4864 panelp = brdp->panels[j];
4865 if (panelp == NULL)
4866 continue;
4867 for (k = 0; (k < STL_PORTSPERPANEL); k++) {
4868 portp = panelp->ports[k];
4869 if (portp == NULL)
4870 continue;
4871 if (portp->tty != NULL)
4872 stl_hangup(portp->tty);
4873 kfree(portp->tx.buf);
4874 kfree(portp);
4875 }
4876 kfree(panelp);
4877 }
4878 4879
4879 release_region(brdp->ioaddr1, brdp->iosize1); 4880 release_region(brdp->ioaddr1, brdp->iosize1);
4880 if (brdp->iosize2 > 0) 4881 if (brdp->iosize2 > 0)