ip22-eisa.c 6.5 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
/*
 * Basic EISA bus support for the SGI Indigo-2.
 *
 * (C) 2002 Pascal Dameme <netinet@freesurf.fr>
 *      and Marc Zyngier <mzyngier@freesurf.fr>
 *
 * This code is released under both the GPL version 2 and BSD
 * licenses.  Either license may be used.
 *
 * This code offers a very basic support for this EISA bus present in
 * the SGI Indigo-2. It currently only supports PIO (forget about DMA
 * for the time being). This is enough for a low-end ethernet card,
 * but forget about your favorite SCSI card...
 *
 * TODO :
 * - Fix bugs...
 * - Add ISA support
 * - Add DMA (yeah, right...).
 * - Fix more bugs.
 */

#include <linux/eisa.h>
#include <linux/types.h>
#include <linux/init.h>
#include <linux/irq.h>
#include <linux/kernel_stat.h>
#include <linux/signal.h>
#include <linux/sched.h>
#include <linux/interrupt.h>
#include <linux/delay.h>
T
Thiemo Seufer 已提交
31
#include <asm/io.h>
L
Linus Torvalds 已提交
32 33 34 35 36 37 38 39
#include <asm/irq.h>
#include <asm/mipsregs.h>
#include <asm/addrspace.h>
#include <asm/processor.h>
#include <asm/sgi/ioc.h>
#include <asm/sgi/mc.h>
#include <asm/sgi/ip22.h>

T
Thiemo Seufer 已提交
40 41
/* I2 has four EISA slots. */
#define IP22_EISA_MAX_SLOTS	  4
L
Linus Torvalds 已提交
42 43
#define EISA_MAX_IRQ             16

T
Thiemo Seufer 已提交
44 45 46 47 48 49 50
#define EIU_MODE_REG     0x0001ffc0
#define EIU_STAT_REG     0x0001ffc4
#define EIU_PREMPT_REG   0x0001ffc8
#define EIU_QUIET_REG    0x0001ffcc
#define EIU_INTRPT_ACK   0x00010004

static char __init *decode_eisa_sig(unsigned long addr)
L
Linus Torvalds 已提交
51
{
T
Thiemo Seufer 已提交
52 53 54 55 56 57 58
        static char sig_str[EISA_SIG_LEN];
	u8 sig[4];
        u16 rev;
	int i;

	for (i = 0; i < 4; i++) {
		sig[i] = inb (addr + i);
L
Linus Torvalds 已提交
59

T
Thiemo Seufer 已提交
60 61 62
		if (!i && (sig[0] & 0x80))
			return NULL;
	}
L
Linus Torvalds 已提交
63 64 65 66 67 68 69 70 71 72

	sig_str[0] = ((sig[0] >> 2) & 0x1f) + ('A' - 1);
	sig_str[1] = (((sig[0] & 3) << 3) | (sig[1] >> 5)) + ('A' - 1);
	sig_str[2] = (sig[1] & 0x1f) + ('A' - 1);
	rev = (sig[2] << 8) | sig[3];
	sprintf(sig_str + 3, "%04X", rev);

	return sig_str;
}

T
Thiemo Seufer 已提交
73
static irqreturn_t ip22_eisa_intr(int irq, void *dev_id, struct pt_regs *regs)
L
Linus Torvalds 已提交
74 75 76 77
{
	u8 eisa_irq;
	u8 dma1, dma2;

T
Thiemo Seufer 已提交
78 79 80
	eisa_irq = inb(EIU_INTRPT_ACK);
	dma1 = inb(EISA_DMA1_STATUS);
	dma2 = inb(EISA_DMA2_STATUS);
L
Linus Torvalds 已提交
81

T
Thiemo Seufer 已提交
82
	if (eisa_irq < EISA_MAX_IRQ) {
L
Linus Torvalds 已提交
83
		do_IRQ(eisa_irq, regs);
T
Thiemo Seufer 已提交
84 85 86 87 88 89 90 91 92
		return IRQ_HANDLED;
	}

	/* Oops, Bad Stuff Happened... */
	printk(KERN_ERR "eisa_irq %d out of bound\n", eisa_irq);

	outb(0x20, EISA_INT2_CTRL);
	outb(0x20, EISA_INT1_CTRL);
	return IRQ_NONE;
L
Linus Torvalds 已提交
93 94 95 96 97 98 99 100 101
}

static void enable_eisa1_irq(unsigned int irq)
{
	unsigned long flags;
	u8 mask;

	local_irq_save(flags);

T
Thiemo Seufer 已提交
102
	mask = inb(EISA_INT1_MASK);
L
Linus Torvalds 已提交
103
	mask &= ~((u8) (1 << irq));
T
Thiemo Seufer 已提交
104
	outb(mask, EISA_INT1_MASK);
L
Linus Torvalds 已提交
105 106 107 108 109 110 111 112 113 114

	local_irq_restore(flags);
}

static unsigned int startup_eisa1_irq(unsigned int irq)
{
	u8 edge;

	/* Only use edge interrupts for EISA */

T
Thiemo Seufer 已提交
115
	edge = inb(EISA_INT1_EDGE_LEVEL);
L
Linus Torvalds 已提交
116
	edge &= ~((u8) (1 << irq));
T
Thiemo Seufer 已提交
117
	outb(edge, EISA_INT1_EDGE_LEVEL);
L
Linus Torvalds 已提交
118 119 120 121 122 123 124 125 126

	enable_eisa1_irq(irq);
	return 0;
}

static void disable_eisa1_irq(unsigned int irq)
{
	u8 mask;

T
Thiemo Seufer 已提交
127
	mask = inb(EISA_INT1_MASK);
L
Linus Torvalds 已提交
128
	mask |= ((u8) (1 << irq));
T
Thiemo Seufer 已提交
129
	outb(mask, EISA_INT1_MASK);
L
Linus Torvalds 已提交
130 131 132 133 134 135 136 137
}

#define shutdown_eisa1_irq	disable_eisa1_irq

static void mask_and_ack_eisa1_irq(unsigned int irq)
{
	disable_eisa1_irq(irq);

T
Thiemo Seufer 已提交
138
	outb(0x20, EISA_INT1_CTRL);
L
Linus Torvalds 已提交
139 140 141 142 143 144 145 146
}

static void end_eisa1_irq(unsigned int irq)
{
	if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS)))
		enable_eisa1_irq(irq);
}

147
static struct irq_chip ip22_eisa1_irq_type = {
L
Linus Torvalds 已提交
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
	.typename	= "IP22 EISA",
	.startup	= startup_eisa1_irq,
	.shutdown	= shutdown_eisa1_irq,
	.enable		= enable_eisa1_irq,
	.disable	= disable_eisa1_irq,
	.ack		= mask_and_ack_eisa1_irq,
	.end		= end_eisa1_irq,
};

static void enable_eisa2_irq(unsigned int irq)
{
	unsigned long flags;
	u8 mask;

	local_irq_save(flags);

T
Thiemo Seufer 已提交
164
	mask = inb(EISA_INT2_MASK);
L
Linus Torvalds 已提交
165
	mask &= ~((u8) (1 << (irq - 8)));
T
Thiemo Seufer 已提交
166
	outb(mask, EISA_INT2_MASK);
L
Linus Torvalds 已提交
167 168 169 170 171 172 173 174 175 176

	local_irq_restore(flags);
}

static unsigned int startup_eisa2_irq(unsigned int irq)
{
	u8 edge;

	/* Only use edge interrupts for EISA */

T
Thiemo Seufer 已提交
177
	edge = inb(EISA_INT2_EDGE_LEVEL);
L
Linus Torvalds 已提交
178
	edge &= ~((u8) (1 << (irq - 8)));
T
Thiemo Seufer 已提交
179
	outb(edge, EISA_INT2_EDGE_LEVEL);
L
Linus Torvalds 已提交
180 181 182 183 184 185 186 187 188

	enable_eisa2_irq(irq);
	return 0;
}

static void disable_eisa2_irq(unsigned int irq)
{
	u8 mask;

T
Thiemo Seufer 已提交
189
	mask = inb(EISA_INT2_MASK);
L
Linus Torvalds 已提交
190
	mask |= ((u8) (1 << (irq - 8)));
T
Thiemo Seufer 已提交
191
	outb(mask, EISA_INT2_MASK);
L
Linus Torvalds 已提交
192 193 194 195 196 197 198 199
}

#define shutdown_eisa2_irq	disable_eisa2_irq

static void mask_and_ack_eisa2_irq(unsigned int irq)
{
	disable_eisa2_irq(irq);

T
Thiemo Seufer 已提交
200
	outb(0x20, EISA_INT2_CTRL);
L
Linus Torvalds 已提交
201 202 203 204 205 206 207 208
}

static void end_eisa2_irq(unsigned int irq)
{
	if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS)))
		enable_eisa2_irq(irq);
}

209
static struct irq_chip ip22_eisa2_irq_type = {
L
Linus Torvalds 已提交
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
	.typename	= "IP22 EISA",
	.startup	= startup_eisa2_irq,
	.shutdown	= shutdown_eisa2_irq,
	.enable		= enable_eisa2_irq,
	.disable	= disable_eisa2_irq,
	.ack		= mask_and_ack_eisa2_irq,
	.end		= end_eisa2_irq,
};

static struct irqaction eisa_action = {
	.handler	= ip22_eisa_intr,
	.name		= "EISA",
};

static struct irqaction cascade_action = {
	.handler	= no_action,
	.name		= "EISA cascade",
};

int __init ip22_eisa_init(void)
{
	int i, c;
	char *str;
233

L
Linus Torvalds 已提交
234 235 236 237 238 239
	if (!(sgimc->systemid & SGIMC_SYSID_EPRESENT)) {
		printk(KERN_INFO "EISA: bus not present.\n");
		return 1;
	}

	printk(KERN_INFO "EISA: Probing bus...\n");
T
Thiemo Seufer 已提交
240 241
	for (c = 0, i = 1; i <= IP22_EISA_MAX_SLOTS; i++) {
		if ((str = decode_eisa_sig(0x1000 * i + EISA_VENDOR_ID_OFFSET))) {
L
Linus Torvalds 已提交
242 243 244 245 246 247 248 249 250 251 252 253 254 255
			printk(KERN_INFO "EISA: slot %d : %s detected.\n",
			       i, str);
			c++;
		}
	}
	printk(KERN_INFO "EISA: Detected %d card%s.\n", c, c < 2 ? "" : "s");
#ifdef CONFIG_ISA
	printk(KERN_INFO "ISA support compiled in.\n");
#endif

	/* Warning : BlackMagicAhead(tm).
	   Please wave your favorite dead chicken over the busses */

	/* First say hello to the EIU */
T
Thiemo Seufer 已提交
256 257 258
	outl(0x0000FFFF, EIU_PREMPT_REG);
	outl(1, EIU_QUIET_REG);
	outl(0x40f3c07F, EIU_MODE_REG);
L
Linus Torvalds 已提交
259 260

	/* Now be nice to the EISA chipset */
T
Thiemo Seufer 已提交
261 262 263 264 265 266 267 268 269 270 271 272 273 274
	outb(1, EISA_EXT_NMI_RESET_CTRL);
	udelay(50);	/* Wait long enough for the dust to settle */
	outb(0, EISA_EXT_NMI_RESET_CTRL);
	outb(0x11, EISA_INT1_CTRL);
	outb(0x11, EISA_INT2_CTRL);
	outb(0, EISA_INT1_MASK);
	outb(8, EISA_INT2_MASK);
	outb(4, EISA_INT1_MASK);
	outb(2, EISA_INT2_MASK);
	outb(1, EISA_INT1_MASK);
	outb(1, EISA_INT2_MASK);
	outb(0xfb, EISA_INT1_MASK);
	outb(0xff, EISA_INT2_MASK);
	outb(0, EISA_DMA2_WRITE_SINGLE);
L
Linus Torvalds 已提交
275 276 277 278 279 280

	for (i = SGINT_EISA; i < (SGINT_EISA + EISA_MAX_IRQ); i++) {
		irq_desc[i].status = IRQ_DISABLED;
		irq_desc[i].action = 0;
		irq_desc[i].depth = 1;
		if (i < (SGINT_EISA + 8))
281
			irq_desc[i].chip = &ip22_eisa1_irq_type;
L
Linus Torvalds 已提交
282
		else
283
			irq_desc[i].chip = &ip22_eisa2_irq_type;
L
Linus Torvalds 已提交
284 285 286 287 288 289 290 291 292 293
	}

	/* Cannot use request_irq because of kmalloc not being ready at such
	 * an early stage. Yes, I've been bitten... */
	setup_irq(SGI_EISA_IRQ, &eisa_action);
	setup_irq(SGINT_EISA + 2, &cascade_action);

	EISA_bus = 1;
	return 0;
}