com20020-isa.c 5.36 KB
Newer Older
Linus Torvalds's avatar
Linus Torvalds committed
1 2
/*
 * Linux ARCnet driver - COM20020 chipset support
3
 *
Linus Torvalds's avatar
Linus Torvalds committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
 * Written 1997 by David Woodhouse.
 * Written 1994-1999 by Avery Pennarun.
 * Written 1999-2000 by Martin Mares <mj@ucw.cz>.
 * Derived from skeleton.c by Donald Becker.
 *
 * Special thanks to Contemporary Controls, Inc. (www.ccontrols.com)
 *  for sponsoring the further development of this driver.
 *
 * **********************
 *
 * The original copyright of skeleton.c was as follows:
 *
 * skeleton.c Written 1993 by Donald Becker.
 * Copyright 1993 United States Government as represented by the
 * Director, National Security Agency.  This software may only be used
 * and distributed according to the terms of the GNU General Public License as
 * modified by SRC, incorporated herein by reference.
 *
 * **********************
 *
 * For more details, see drivers/net/arcnet.c
 *
 * **********************
 */
28 29 30

#define pr_fmt(fmt) "arcnet:" KBUILD_MODNAME ": " fmt

Linus Torvalds's avatar
Linus Torvalds committed
31 32 33 34 35 36 37 38 39
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/kernel.h>
#include <linux/types.h>
#include <linux/ioport.h>
#include <linux/errno.h>
#include <linux/delay.h>
#include <linux/netdevice.h>
#include <linux/init.h>
40
#include <linux/interrupt.h>
Linus Torvalds's avatar
Linus Torvalds committed
41
#include <linux/bootmem.h>
42
#include <linux/io.h>
Linus Torvalds's avatar
Linus Torvalds committed
43

44 45 46
#include "arcdevice.h"
#include "com20020.h"

47
/* We cannot (yet) probe for an IO mapped card, although we can check that
Linus Torvalds's avatar
Linus Torvalds committed
48 49 50 51 52 53
 * it's where we were told it was, and even do autoirq.
 */
static int __init com20020isa_probe(struct net_device *dev)
{
	int ioaddr;
	unsigned long airqmask;
54
	struct arcnet_local *lp = netdev_priv(dev);
Linus Torvalds's avatar
Linus Torvalds committed
55 56
	int err;

57
	if (BUGLVL(D_NORMAL))
58
		pr_info("%s\n", "COM20020 ISA support (by David Woodhouse et al.)");
Linus Torvalds's avatar
Linus Torvalds committed
59 60 61

	ioaddr = dev->base_addr;
	if (!ioaddr) {
62
		arc_printk(D_NORMAL, dev, "No autoprobe (yet) for IO mapped cards; you must specify the base address!\n");
Linus Torvalds's avatar
Linus Torvalds committed
63 64 65
		return -ENODEV;
	}
	if (!request_region(ioaddr, ARCNET_TOTAL_SIZE, "arcnet (COM20020)")) {
66 67
		arc_printk(D_NORMAL, dev, "IO region %xh-%xh already allocated.\n",
			   ioaddr, ioaddr + ARCNET_TOTAL_SIZE - 1);
Linus Torvalds's avatar
Linus Torvalds committed
68 69
		return -ENXIO;
	}
70
	if (arcnet_inb(ioaddr, COM20020_REG_R_STATUS) == 0xFF) {
71
		arc_printk(D_NORMAL, dev, "IO address %x empty\n", ioaddr);
Linus Torvalds's avatar
Linus Torvalds committed
72 73 74 75 76 77 78 79 80 81 82 83 84
		err = -ENODEV;
		goto out;
	}
	if (com20020_check(dev)) {
		err = -ENODEV;
		goto out;
	}

	if (!dev->irq) {
		/* if we do this, we're sure to get an IRQ since the
		 * card has just reset and the NORXflag is on until
		 * we tell it to start receiving.
		 */
85
		arc_printk(D_INIT_REASONS, dev, "intmask was %02Xh\n",
86 87
			   arcnet_inb(ioaddr, COM20020_REG_R_STATUS));
		arcnet_outb(0, ioaddr, COM20020_REG_W_INTMASK);
Linus Torvalds's avatar
Linus Torvalds committed
88
		airqmask = probe_irq_on();
89
		arcnet_outb(NORXflag, ioaddr, COM20020_REG_W_INTMASK);
Linus Torvalds's avatar
Linus Torvalds committed
90
		udelay(1);
91
		arcnet_outb(0, ioaddr, COM20020_REG_W_INTMASK);
Linus Torvalds's avatar
Linus Torvalds committed
92 93
		dev->irq = probe_irq_off(airqmask);

94
		if ((int)dev->irq <= 0) {
95
			arc_printk(D_INIT_REASONS, dev, "Autoprobe IRQ failed first time\n");
Linus Torvalds's avatar
Linus Torvalds committed
96
			airqmask = probe_irq_on();
97
			arcnet_outb(NORXflag, ioaddr, COM20020_REG_W_INTMASK);
Linus Torvalds's avatar
Linus Torvalds committed
98
			udelay(5);
99
			arcnet_outb(0, ioaddr, COM20020_REG_W_INTMASK);
Linus Torvalds's avatar
Linus Torvalds committed
100
			dev->irq = probe_irq_off(airqmask);
101
			if ((int)dev->irq <= 0) {
102
				arc_printk(D_NORMAL, dev, "Autoprobe IRQ failed.\n");
Linus Torvalds's avatar
Linus Torvalds committed
103 104 105 106 107 108 109
				err = -ENODEV;
				goto out;
			}
		}
	}

	lp->card_name = "ISA COM20020";
110 111 112

	err = com20020_found(dev, 0);
	if (err != 0)
Linus Torvalds's avatar
Linus Torvalds committed
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
		goto out;

	return 0;

out:
	release_region(ioaddr, ARCNET_TOTAL_SIZE);
	return err;
}

static int node = 0;
static int io = 0x0;		/* <--- EDIT THESE LINES FOR YOUR CONFIGURATION */
static int irq = 0;		/* or use the insmod io= irq= shmem= options */
static char device[9];		/* use eg. device="arc1" to change name */
static int timeout = 3;
static int backplane = 0;
static int clockp = 0;
static int clockm = 0;

module_param(node, int, 0);
132 133
module_param_hw(io, int, ioport, 0);
module_param_hw(irq, int, irq, 0);
Linus Torvalds's avatar
Linus Torvalds committed
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
module_param_string(device, device, sizeof(device), 0);
module_param(timeout, int, 0);
module_param(backplane, int, 0);
module_param(clockp, int, 0);
module_param(clockm, int, 0);

MODULE_LICENSE("GPL");

static struct net_device *my_dev;

static int __init com20020_init(void)
{
	struct net_device *dev;
	struct arcnet_local *lp;

	dev = alloc_arcdev(device);
	if (!dev)
		return -ENOMEM;

	if (node && node != 0xff)
		dev->dev_addr[0] = node;

156 157
	dev->netdev_ops = &com20020_netdev_ops;

158
	lp = netdev_priv(dev);
Linus Torvalds's avatar
Linus Torvalds committed
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
	lp->backplane = backplane;
	lp->clockp = clockp & 7;
	lp->clockm = clockm & 3;
	lp->timeout = timeout & 3;
	lp->hw.owner = THIS_MODULE;

	dev->base_addr = io;
	dev->irq = irq;

	if (dev->irq == 2)
		dev->irq = 9;

	if (com20020isa_probe(dev)) {
		free_netdev(dev);
		return -EIO;
	}

	my_dev = dev;
	return 0;
}

static void __exit com20020_exit(void)
{
	unregister_netdev(my_dev);
	free_irq(my_dev->irq, my_dev);
	release_region(my_dev->base_addr, ARCNET_TOTAL_SIZE);
	free_netdev(my_dev);
}

#ifndef MODULE
static int __init com20020isa_setup(char *s)
{
	int ints[8];

	s = get_options(s, 8, ints);
	if (!ints[0])
		return 1;

	switch (ints[0]) {
	default:		/* ERROR */
199
		pr_info("Too many arguments\n");
Linus Torvalds's avatar
Linus Torvalds committed
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
	case 6:		/* Timeout */
		timeout = ints[6];
	case 5:		/* CKP value */
		clockp = ints[5];
	case 4:		/* Backplane flag */
		backplane = ints[4];
	case 3:		/* Node ID */
		node = ints[3];
	case 2:		/* IRQ */
		irq = ints[2];
	case 1:		/* IO address */
		io = ints[1];
	}
	if (*s)
		snprintf(device, sizeof(device), "%s", s);
	return 1;
}

__setup("com20020=", com20020isa_setup);

#endif				/* MODULE */

module_init(com20020_init)
module_exit(com20020_exit)