com20020-pci.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /*
  2. * Linux ARCnet driver - COM20020 PCI support
  3. * Contemporary Controls PCI20 and SOHARD SH-ARC PCI
  4. *
  5. * Written 1994-1999 by Avery Pennarun,
  6. * based on an ISA version by David Woodhouse.
  7. * Written 1999-2000 by Martin Mares <mj@ucw.cz>.
  8. * Derived from skeleton.c by Donald Becker.
  9. *
  10. * Special thanks to Contemporary Controls, Inc. (www.ccontrols.com)
  11. * for sponsoring the further development of this driver.
  12. *
  13. * **********************
  14. *
  15. * The original copyright of skeleton.c was as follows:
  16. *
  17. * skeleton.c Written 1993 by Donald Becker.
  18. * Copyright 1993 United States Government as represented by the
  19. * Director, National Security Agency. This software may only be used
  20. * and distributed according to the terms of the GNU General Public License as
  21. * modified by SRC, incorporated herein by reference.
  22. *
  23. * **********************
  24. *
  25. * For more details, see drivers/net/arcnet.c
  26. *
  27. * **********************
  28. */
  29. #include <linux/module.h>
  30. #include <linux/moduleparam.h>
  31. #include <linux/kernel.h>
  32. #include <linux/types.h>
  33. #include <linux/ioport.h>
  34. #include <linux/errno.h>
  35. #include <linux/netdevice.h>
  36. #include <linux/init.h>
  37. #include <linux/pci.h>
  38. #include <linux/arcdevice.h>
  39. #include <linux/com20020.h>
  40. #include <asm/io.h>
  41. #define VERSION "arcnet: COM20020 PCI support\n"
  42. /* Module parameters */
  43. static int node;
  44. static char device[9]; /* use eg. device="arc1" to change name */
  45. static int timeout = 3;
  46. static int backplane;
  47. static int clockp;
  48. static int clockm;
  49. module_param(node, int, 0);
  50. module_param_string(device, device, sizeof(device), 0);
  51. module_param(timeout, int, 0);
  52. module_param(backplane, int, 0);
  53. module_param(clockp, int, 0);
  54. module_param(clockm, int, 0);
  55. MODULE_LICENSE("GPL");
  56. static int __devinit com20020pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  57. {
  58. struct net_device *dev;
  59. struct arcnet_local *lp;
  60. int ioaddr, err;
  61. if (pci_enable_device(pdev))
  62. return -EIO;
  63. dev = alloc_arcdev(device);
  64. if (!dev)
  65. return -ENOMEM;
  66. dev->netdev_ops = &com20020_netdev_ops;
  67. lp = netdev_priv(dev);
  68. pci_set_drvdata(pdev, dev);
  69. // SOHARD needs PCI base addr 4
  70. if (pdev->vendor==0x10B5) {
  71. BUGMSG(D_NORMAL, "SOHARD\n");
  72. ioaddr = pci_resource_start(pdev, 4);
  73. }
  74. else {
  75. BUGMSG(D_NORMAL, "Contemporary Controls\n");
  76. ioaddr = pci_resource_start(pdev, 2);
  77. }
  78. if (!request_region(ioaddr, ARCNET_TOTAL_SIZE, "com20020-pci")) {
  79. BUGMSG(D_INIT, "IO region %xh-%xh already allocated.\n",
  80. ioaddr, ioaddr + ARCNET_TOTAL_SIZE - 1);
  81. err = -EBUSY;
  82. goto out_dev;
  83. }
  84. // Dummy access after Reset
  85. // ARCNET controller needs this access to detect bustype
  86. outb(0x00,ioaddr+1);
  87. inb(ioaddr+1);
  88. dev->base_addr = ioaddr;
  89. dev->irq = pdev->irq;
  90. dev->dev_addr[0] = node;
  91. lp->card_name = "PCI COM20020";
  92. lp->card_flags = id->driver_data;
  93. lp->backplane = backplane;
  94. lp->clockp = clockp & 7;
  95. lp->clockm = clockm & 3;
  96. lp->timeout = timeout;
  97. lp->hw.owner = THIS_MODULE;
  98. if (ASTATUS() == 0xFF) {
  99. BUGMSG(D_NORMAL, "IO address %Xh was reported by PCI BIOS, "
  100. "but seems empty!\n", ioaddr);
  101. err = -EIO;
  102. goto out_port;
  103. }
  104. if (com20020_check(dev)) {
  105. err = -EIO;
  106. goto out_port;
  107. }
  108. if ((err = com20020_found(dev, IRQF_SHARED)) != 0)
  109. goto out_port;
  110. return 0;
  111. out_port:
  112. release_region(ioaddr, ARCNET_TOTAL_SIZE);
  113. out_dev:
  114. free_netdev(dev);
  115. return err;
  116. }
  117. static void __devexit com20020pci_remove(struct pci_dev *pdev)
  118. {
  119. struct net_device *dev = pci_get_drvdata(pdev);
  120. unregister_netdev(dev);
  121. free_irq(dev->irq, dev);
  122. release_region(dev->base_addr, ARCNET_TOTAL_SIZE);
  123. free_netdev(dev);
  124. }
  125. static DEFINE_PCI_DEVICE_TABLE(com20020pci_id_table) = {
  126. { 0x1571, 0xa001, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  127. { 0x1571, 0xa002, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  128. { 0x1571, 0xa003, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  129. { 0x1571, 0xa004, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  130. { 0x1571, 0xa005, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  131. { 0x1571, 0xa006, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  132. { 0x1571, 0xa007, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  133. { 0x1571, 0xa008, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  134. { 0x1571, 0xa009, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_IS_5MBIT },
  135. { 0x1571, 0xa00a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_IS_5MBIT },
  136. { 0x1571, 0xa00b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_IS_5MBIT },
  137. { 0x1571, 0xa00c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_IS_5MBIT },
  138. { 0x1571, 0xa00d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_IS_5MBIT },
  139. { 0x1571, 0xa00e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_IS_5MBIT },
  140. { 0x1571, 0xa201, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_CAN_10MBIT },
  141. { 0x1571, 0xa202, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_CAN_10MBIT },
  142. { 0x1571, 0xa203, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_CAN_10MBIT },
  143. { 0x1571, 0xa204, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_CAN_10MBIT },
  144. { 0x1571, 0xa205, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_CAN_10MBIT },
  145. { 0x1571, 0xa206, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_CAN_10MBIT },
  146. { 0x10B5, 0x9030, 0x10B5, 0x2978, 0, 0, ARC_CAN_10MBIT },
  147. { 0x10B5, 0x9050, 0x10B5, 0x2273, 0, 0, ARC_CAN_10MBIT },
  148. { 0x14BA, 0x6000, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_CAN_10MBIT },
  149. { 0x10B5, 0x2200, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_CAN_10MBIT },
  150. {0,}
  151. };
  152. MODULE_DEVICE_TABLE(pci, com20020pci_id_table);
  153. static struct pci_driver com20020pci_driver = {
  154. .name = "com20020",
  155. .id_table = com20020pci_id_table,
  156. .probe = com20020pci_probe,
  157. .remove = __devexit_p(com20020pci_remove),
  158. };
  159. static int __init com20020pci_init(void)
  160. {
  161. BUGLVL(D_NORMAL) printk(VERSION);
  162. return pci_register_driver(&com20020pci_driver);
  163. }
  164. static void __exit com20020pci_cleanup(void)
  165. {
  166. pci_unregister_driver(&com20020pci_driver);
  167. }
  168. module_init(com20020pci_init)
  169. module_exit(com20020pci_cleanup)