0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 #define pr_fmt(fmt) "arcnet:" KBUILD_MODNAME ": " fmt
0030
0031 #include <linux/module.h>
0032 #include <linux/moduleparam.h>
0033 #include <linux/kernel.h>
0034 #include <linux/types.h>
0035 #include <linux/ioport.h>
0036 #include <linux/errno.h>
0037 #include <linux/delay.h>
0038 #include <linux/netdevice.h>
0039 #include <linux/init.h>
0040 #include <linux/interrupt.h>
0041 #include <linux/memblock.h>
0042 #include <linux/io.h>
0043
0044 #include "arcdevice.h"
0045 #include "com20020.h"
0046
0047
0048
0049
0050 static int __init com20020isa_probe(struct net_device *dev)
0051 {
0052 int ioaddr;
0053 unsigned long airqmask;
0054 struct arcnet_local *lp = netdev_priv(dev);
0055 int err;
0056
0057 if (BUGLVL(D_NORMAL))
0058 pr_info("%s\n", "COM20020 ISA support (by David Woodhouse et al.)");
0059
0060 ioaddr = dev->base_addr;
0061 if (!ioaddr) {
0062 arc_printk(D_NORMAL, dev, "No autoprobe (yet) for IO mapped cards; you must specify the base address!\n");
0063 return -ENODEV;
0064 }
0065 if (!request_region(ioaddr, ARCNET_TOTAL_SIZE, "arcnet (COM20020)")) {
0066 arc_printk(D_NORMAL, dev, "IO region %xh-%xh already allocated.\n",
0067 ioaddr, ioaddr + ARCNET_TOTAL_SIZE - 1);
0068 return -ENXIO;
0069 }
0070 if (arcnet_inb(ioaddr, COM20020_REG_R_STATUS) == 0xFF) {
0071 arc_printk(D_NORMAL, dev, "IO address %x empty\n", ioaddr);
0072 err = -ENODEV;
0073 goto out;
0074 }
0075 if (com20020_check(dev)) {
0076 err = -ENODEV;
0077 goto out;
0078 }
0079
0080 if (!dev->irq) {
0081
0082
0083
0084
0085 arc_printk(D_INIT_REASONS, dev, "intmask was %02Xh\n",
0086 arcnet_inb(ioaddr, COM20020_REG_R_STATUS));
0087 arcnet_outb(0, ioaddr, COM20020_REG_W_INTMASK);
0088 airqmask = probe_irq_on();
0089 arcnet_outb(NORXflag, ioaddr, COM20020_REG_W_INTMASK);
0090 udelay(1);
0091 arcnet_outb(0, ioaddr, COM20020_REG_W_INTMASK);
0092 dev->irq = probe_irq_off(airqmask);
0093
0094 if ((int)dev->irq <= 0) {
0095 arc_printk(D_INIT_REASONS, dev, "Autoprobe IRQ failed first time\n");
0096 airqmask = probe_irq_on();
0097 arcnet_outb(NORXflag, ioaddr, COM20020_REG_W_INTMASK);
0098 udelay(5);
0099 arcnet_outb(0, ioaddr, COM20020_REG_W_INTMASK);
0100 dev->irq = probe_irq_off(airqmask);
0101 if ((int)dev->irq <= 0) {
0102 arc_printk(D_NORMAL, dev, "Autoprobe IRQ failed.\n");
0103 err = -ENODEV;
0104 goto out;
0105 }
0106 }
0107 }
0108
0109 lp->card_name = "ISA COM20020";
0110
0111 err = com20020_found(dev, 0);
0112 if (err != 0)
0113 goto out;
0114
0115 return 0;
0116
0117 out:
0118 release_region(ioaddr, ARCNET_TOTAL_SIZE);
0119 return err;
0120 }
0121
0122 static int node = 0;
0123 static int io = 0x0;
0124 static int irq = 0;
0125 static char device[9];
0126 static int timeout = 3;
0127 static int backplane = 0;
0128 static int clockp = 0;
0129 static int clockm = 0;
0130
0131 module_param(node, int, 0);
0132 module_param_hw(io, int, ioport, 0);
0133 module_param_hw(irq, int, irq, 0);
0134 module_param_string(device, device, sizeof(device), 0);
0135 module_param(timeout, int, 0);
0136 module_param(backplane, int, 0);
0137 module_param(clockp, int, 0);
0138 module_param(clockm, int, 0);
0139
0140 MODULE_LICENSE("GPL");
0141
0142 static struct net_device *my_dev;
0143
0144 static int __init com20020_init(void)
0145 {
0146 struct net_device *dev;
0147 struct arcnet_local *lp;
0148
0149 dev = alloc_arcdev(device);
0150 if (!dev)
0151 return -ENOMEM;
0152
0153 if (node && node != 0xff)
0154 arcnet_set_addr(dev, node);
0155
0156 dev->netdev_ops = &com20020_netdev_ops;
0157
0158 lp = netdev_priv(dev);
0159 lp->backplane = backplane;
0160 lp->clockp = clockp & 7;
0161 lp->clockm = clockm & 3;
0162 lp->timeout = timeout & 3;
0163 lp->hw.owner = THIS_MODULE;
0164
0165 dev->base_addr = io;
0166 dev->irq = irq;
0167
0168 if (dev->irq == 2)
0169 dev->irq = 9;
0170
0171 if (com20020isa_probe(dev)) {
0172 free_arcdev(dev);
0173 return -EIO;
0174 }
0175
0176 my_dev = dev;
0177 return 0;
0178 }
0179
0180 static void __exit com20020_exit(void)
0181 {
0182 unregister_netdev(my_dev);
0183 free_irq(my_dev->irq, my_dev);
0184 release_region(my_dev->base_addr, ARCNET_TOTAL_SIZE);
0185 free_arcdev(my_dev);
0186 }
0187
0188 #ifndef MODULE
0189 static int __init com20020isa_setup(char *s)
0190 {
0191 int ints[8];
0192
0193 s = get_options(s, 8, ints);
0194 if (!ints[0])
0195 return 1;
0196
0197 switch (ints[0]) {
0198 default:
0199 pr_info("Too many arguments\n");
0200 fallthrough;
0201 case 6:
0202 timeout = ints[6];
0203 fallthrough;
0204 case 5:
0205 clockp = ints[5];
0206 fallthrough;
0207 case 4:
0208 backplane = ints[4];
0209 fallthrough;
0210 case 3:
0211 node = ints[3];
0212 fallthrough;
0213 case 2:
0214 irq = ints[2];
0215 fallthrough;
0216 case 1:
0217 io = ints[1];
0218 }
0219 if (*s)
0220 snprintf(device, sizeof(device), "%s", s);
0221 return 1;
0222 }
0223
0224 __setup("com20020=", com20020isa_setup);
0225
0226 #endif
0227
0228 module_init(com20020_init)
0229 module_exit(com20020_exit)