com20020-isa.c
上传用户:lgb322
上传日期:2013-02-24
资源大小:30529k
文件大小:5k
源码类别:

嵌入式Linux

开发平台:

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. static void com20020isa_open_close(struct net_device *dev, bool open)
  120. {
  121. if (open)
  122. MOD_INC_USE_COUNT;
  123. else
  124. MOD_DEC_USE_COUNT;
  125. }
  126. int init_module(void)
  127. {
  128. struct net_device *dev;
  129. struct arcnet_local *lp;
  130. int err;
  131. dev = dev_alloc(device ? : "arc%d", &err);
  132. if (!dev)
  133. return err;
  134. lp = dev->priv = kmalloc(sizeof(struct arcnet_local), GFP_KERNEL);
  135. if (!lp)
  136. return -ENOMEM;
  137. memset(lp, 0, sizeof(struct arcnet_local));
  138. if (node && node != 0xff)
  139. dev->dev_addr[0] = node;
  140. lp->backplane = backplane;
  141. lp->clockp = clockp & 7;
  142. lp->clockm = clockm & 3;
  143. lp->timeout = timeout & 3;
  144. lp->hw.open_close_ll = com20020isa_open_close;
  145. dev->base_addr = io;
  146. dev->irq = irq;
  147. if (dev->irq == 2)
  148. dev->irq = 9;
  149. if (com20020isa_probe(dev))
  150. return -EIO;
  151. my_dev = dev;
  152. return 0;
  153. }
  154. void cleanup_module(void)
  155. {
  156. com20020_remove(my_dev);
  157. }
  158. #else
  159. static int __init com20020isa_setup(char *s)
  160. {
  161. struct net_device *dev;
  162. struct arcnet_local *lp;
  163. int ints[8];
  164. s = get_options(s, 8, ints);
  165. if (!ints[0])
  166. return 1;
  167. dev = alloc_bootmem(sizeof(struct net_device) + sizeof(struct arcnet_local));
  168. memset(dev, 0, sizeof(struct net_device) + sizeof(struct arcnet_local));
  169. lp = dev->priv = (struct arcnet_local *) (dev + 1);
  170. dev->init = com20020isa_probe;
  171. switch (ints[0]) {
  172. default: /* ERROR */
  173. printk("com90xx: Too many arguments.n");
  174. case 6: /* Timeout */
  175. lp->timeout = ints[6];
  176. case 5: /* CKP value */
  177. lp->clockp = ints[5];
  178. case 4: /* Backplane flag */
  179. lp->backplane = ints[4];
  180. case 3: /* Node ID */
  181. dev->dev_addr[0] = ints[3];
  182. case 2: /* IRQ */
  183. dev->irq = ints[2];
  184. case 1: /* IO address */
  185. dev->base_addr = ints[1];
  186. }
  187. if (*s)
  188. strncpy(dev->name, s, 9);
  189. else
  190. strcpy(dev->name, "arc%d");
  191. if (register_netdev(dev))
  192. printk(KERN_ERR "com20020: Cannot register arcnet devicen");
  193. return 1;
  194. }
  195. __setup("com20020=", com20020isa_setup);
  196. #endif /* MODULE */