com20020-pci.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:5k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

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