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

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  * Linux ARCnet driver - COM20020 chipset support
  3.  * 
  4.  * Written 1997 by David Woodhouse.
  5.  * Written 1994-1999 by Avery Pennarun.
  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/delay.h>
  35. #include <linux/netdevice.h>
  36. #include <linux/init.h>
  37. #include <linux/bootmem.h>
  38. #include <linux/arcdevice.h>
  39. #include <linux/com20020.h>
  40. #include <asm/io.h>
  41. #define VERSION "arcnet: COM20020 ISA support (by David Woodhouse et al.)n"
  42. /*
  43.  * We cannot (yet) probe for an IO mapped card, although we can check that
  44.  * it's where we were told it was, and even do autoirq.
  45.  */
  46. static int __init com20020isa_probe(struct net_device *dev)
  47. {
  48. int ioaddr;
  49. unsigned long airqmask;
  50. struct arcnet_local *lp = dev->priv;
  51. #ifndef MODULE
  52. arcnet_init();
  53. #endif
  54. BUGLVL(D_NORMAL) printk(VERSION);
  55. ioaddr = dev->base_addr;
  56. if (!ioaddr) {
  57. BUGMSG(D_NORMAL, "No autoprobe (yet) for IO mapped cards; you "
  58.        "must specify the base address!n");
  59. return -ENODEV;
  60. }
  61. if (check_region(ioaddr, ARCNET_TOTAL_SIZE)) {
  62. BUGMSG(D_NORMAL, "IO region %xh-%xh already allocated.n",
  63.        ioaddr, ioaddr + ARCNET_TOTAL_SIZE - 1);
  64. return -ENXIO;
  65. }
  66. if (ASTATUS() == 0xFF) {
  67. BUGMSG(D_NORMAL, "IO address %x emptyn", ioaddr);
  68. return -ENODEV;
  69. }
  70. if (com20020_check(dev))
  71. return -ENODEV;
  72. if (!dev->irq) {
  73. /* if we do this, we're sure to get an IRQ since the
  74.  * card has just reset and the NORXflag is on until
  75.  * we tell it to start receiving.
  76.  */
  77. BUGMSG(D_INIT_REASONS, "intmask was %02Xhn", inb(_INTMASK));
  78. outb(0, _INTMASK);
  79. airqmask = probe_irq_on();
  80. outb(NORXflag, _INTMASK);
  81. udelay(1);
  82. outb(0, _INTMASK);
  83. dev->irq = probe_irq_off(airqmask);
  84. if (dev->irq <= 0) {
  85. BUGMSG(D_INIT_REASONS, "Autoprobe IRQ failed first timen");
  86. airqmask = probe_irq_on();
  87. outb(NORXflag, _INTMASK);
  88. udelay(5);
  89. outb(0, _INTMASK);
  90. dev->irq = probe_irq_off(airqmask);
  91. if (dev->irq <= 0) {
  92. BUGMSG(D_NORMAL, "Autoprobe IRQ failed.n");
  93. return -ENODEV;
  94. }
  95. }
  96. }
  97. lp->card_name = "ISA COM20020";
  98. return com20020_found(dev, 0);
  99. }
  100. #ifdef MODULE
  101. static struct net_device *my_dev;
  102. /* Module parameters */
  103. static int node = 0;
  104. static int io = 0x0; /* <--- EDIT THESE LINES FOR YOUR CONFIGURATION */
  105. static int irq = 0; /* or use the insmod io= irq= shmem= options */
  106. static char *device; /* use eg. device="arc1" to change name */
  107. static int timeout = 3;
  108. static int backplane = 0;
  109. static int clockp = 0;
  110. static int clockm = 0;
  111. MODULE_PARM(node, "i");
  112. MODULE_PARM(io, "i");
  113. MODULE_PARM(irq, "i");
  114. MODULE_PARM(device, "s");
  115. MODULE_PARM(timeout, "i");
  116. MODULE_PARM(backplane, "i");
  117. MODULE_PARM(clockp, "i");
  118. MODULE_PARM(clockm, "i");
  119. MODULE_LICENSE("GPL");
  120. static void com20020isa_open_close(struct net_device *dev, bool open)
  121. {
  122. if (open)
  123. MOD_INC_USE_COUNT;
  124. else
  125. MOD_DEC_USE_COUNT;
  126. }
  127. int init_module(void)
  128. {
  129. struct net_device *dev;
  130. struct arcnet_local *lp;
  131. int err;
  132. dev = dev_alloc(device ? : "arc%d", &err);
  133. if (!dev)
  134. return err;
  135. lp = dev->priv = kmalloc(sizeof(struct arcnet_local), GFP_KERNEL);
  136. if (!lp)
  137. return -ENOMEM;
  138. memset(lp, 0, sizeof(struct arcnet_local));
  139. if (node && node != 0xff)
  140. dev->dev_addr[0] = node;
  141. lp->backplane = backplane;
  142. lp->clockp = clockp & 7;
  143. lp->clockm = clockm & 3;
  144. lp->timeout = timeout & 3;
  145. lp->hw.open_close_ll = com20020isa_open_close;
  146. dev->base_addr = io;
  147. dev->irq = irq;
  148. if (dev->irq == 2)
  149. dev->irq = 9;
  150. if (com20020isa_probe(dev))
  151. return -EIO;
  152. my_dev = dev;
  153. return 0;
  154. }
  155. void cleanup_module(void)
  156. {
  157. com20020_remove(my_dev);
  158. }
  159. #else
  160. static int __init com20020isa_setup(char *s)
  161. {
  162. struct net_device *dev;
  163. struct arcnet_local *lp;
  164. int ints[8];
  165. s = get_options(s, 8, ints);
  166. if (!ints[0])
  167. return 1;
  168. dev = alloc_bootmem(sizeof(struct net_device) + sizeof(struct arcnet_local));
  169. memset(dev, 0, sizeof(struct net_device) + sizeof(struct arcnet_local));
  170. lp = dev->priv = (struct arcnet_local *) (dev + 1);
  171. dev->init = com20020isa_probe;
  172. switch (ints[0]) {
  173. default: /* ERROR */
  174. printk("com90xx: Too many arguments.n");
  175. case 6: /* Timeout */
  176. lp->timeout = ints[6];
  177. case 5: /* CKP value */
  178. lp->clockp = ints[5];
  179. case 4: /* Backplane flag */
  180. lp->backplane = ints[4];
  181. case 3: /* Node ID */
  182. dev->dev_addr[0] = ints[3];
  183. case 2: /* IRQ */
  184. dev->irq = ints[2];
  185. case 1: /* IO address */
  186. dev->base_addr = ints[1];
  187. }
  188. if (*s)
  189. strncpy(dev->name, s, 9);
  190. else
  191. strcpy(dev->name, "arc%d");
  192. if (register_netdev(dev))
  193. printk(KERN_ERR "com20020: Cannot register arcnet devicen");
  194. return 1;
  195. }
  196. __setup("com20020=", com20020isa_setup);
  197. #endif /* MODULE */