| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* -*- mode: c; c-basic-offset: 8 -*- */ | 
 | 2 |  | 
 | 3 | /* Copyright (C) 1999,2001 | 
 | 4 |  * | 
 | 5 |  * Author: J.E.J.Bottomley@HansenPartnership.com | 
 | 6 |  * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 |  * This file contains all the logic for manipulating the CAT bus | 
 | 8 |  * in a level 5 machine. | 
 | 9 |  * | 
 | 10 |  * The CAT bus is a serial configuration and test bus.  Its primary | 
 | 11 |  * uses are to probe the initial configuration of the system and to | 
 | 12 |  * diagnose error conditions when a system interrupt occurs.  The low | 
 | 13 |  * level interface is fairly primitive, so most of this file consists | 
 | 14 |  * of bit shift manipulations to send and receive packets on the | 
 | 15 |  * serial bus */ | 
 | 16 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/types.h> | 
 | 18 | #include <linux/completion.h> | 
 | 19 | #include <linux/sched.h> | 
 | 20 | #include <asm/voyager.h> | 
 | 21 | #include <asm/vic.h> | 
 | 22 | #include <linux/ioport.h> | 
 | 23 | #include <linux/init.h> | 
 | 24 | #include <linux/slab.h> | 
 | 25 | #include <linux/delay.h> | 
 | 26 | #include <asm/io.h> | 
 | 27 |  | 
 | 28 | #ifdef VOYAGER_CAT_DEBUG | 
 | 29 | #define CDEBUG(x)	printk x | 
 | 30 | #else | 
 | 31 | #define CDEBUG(x) | 
 | 32 | #endif | 
 | 33 |  | 
 | 34 | /* the CAT command port */ | 
 | 35 | #define CAT_CMD		(sspb + 0xe) | 
 | 36 | /* the CAT data port */ | 
 | 37 | #define CAT_DATA	(sspb + 0xd) | 
 | 38 |  | 
 | 39 | /* the internal cat functions */ | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 40 | static void cat_pack(__u8 * msg, __u16 start_bit, __u8 * data, __u16 num_bits); | 
 | 41 | static void cat_unpack(__u8 * msg, __u16 start_bit, __u8 * data, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | 		       __u16 num_bits); | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 43 | static void cat_build_header(__u8 * header, const __u16 len, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | 			     const __u16 smallest_reg_bits, | 
 | 45 | 			     const __u16 longest_reg_bits); | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 46 | static int cat_sendinst(voyager_module_t * modp, voyager_asic_t * asicp, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | 			__u8 reg, __u8 op); | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 48 | static int cat_getdata(voyager_module_t * modp, voyager_asic_t * asicp, | 
 | 49 | 		       __u8 reg, __u8 * value); | 
 | 50 | static int cat_shiftout(__u8 * data, __u16 data_bytes, __u16 header_bytes, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | 			__u8 pad_bits); | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 52 | static int cat_write(voyager_module_t * modp, voyager_asic_t * asicp, __u8 reg, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | 		     __u8 value); | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 54 | static int cat_read(voyager_module_t * modp, voyager_asic_t * asicp, __u8 reg, | 
 | 55 | 		    __u8 * value); | 
 | 56 | static int cat_subread(voyager_module_t * modp, voyager_asic_t * asicp, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | 		       __u16 offset, __u16 len, void *buf); | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 58 | static int cat_senddata(voyager_module_t * modp, voyager_asic_t * asicp, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | 			__u8 reg, __u8 value); | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 60 | static int cat_disconnect(voyager_module_t * modp, voyager_asic_t * asicp); | 
 | 61 | static int cat_connect(voyager_module_t * modp, voyager_asic_t * asicp); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 |  | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 63 | static inline const char *cat_module_name(int module_id) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | { | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 65 | 	switch (module_id) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | 	case 0x10: | 
 | 67 | 		return "Processor Slot 0"; | 
 | 68 | 	case 0x11: | 
 | 69 | 		return "Processor Slot 1"; | 
 | 70 | 	case 0x12: | 
 | 71 | 		return "Processor Slot 2"; | 
 | 72 | 	case 0x13: | 
 | 73 | 		return "Processor Slot 4"; | 
 | 74 | 	case 0x14: | 
 | 75 | 		return "Memory Slot 0"; | 
 | 76 | 	case 0x15: | 
 | 77 | 		return "Memory Slot 1"; | 
 | 78 | 	case 0x18: | 
 | 79 | 		return "Primary Microchannel"; | 
 | 80 | 	case 0x19: | 
 | 81 | 		return "Secondary Microchannel"; | 
 | 82 | 	case 0x1a: | 
 | 83 | 		return "Power Supply Interface"; | 
 | 84 | 	case 0x1c: | 
 | 85 | 		return "Processor Slot 5"; | 
 | 86 | 	case 0x1d: | 
 | 87 | 		return "Processor Slot 6"; | 
 | 88 | 	case 0x1e: | 
 | 89 | 		return "Processor Slot 7"; | 
 | 90 | 	case 0x1f: | 
 | 91 | 		return "Processor Slot 8"; | 
 | 92 | 	default: | 
 | 93 | 		return "Unknown Module"; | 
 | 94 | 	} | 
 | 95 | } | 
 | 96 |  | 
 | 97 | static int sspb = 0;		/* stores the super port location */ | 
 | 98 | int voyager_8slot = 0;		/* set to true if a 51xx monster */ | 
 | 99 |  | 
 | 100 | voyager_module_t *voyager_cat_list; | 
 | 101 |  | 
 | 102 | /* the I/O port assignments for the VIC and QIC */ | 
 | 103 | static struct resource vic_res = { | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 104 | 	.name = "Voyager Interrupt Controller", | 
 | 105 | 	.start = 0xFC00, | 
 | 106 | 	.end = 0xFC6F | 
| Adrian Bunk | dd7ba3b | 2006-04-10 22:52:49 -0700 | [diff] [blame] | 107 | }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | static struct resource qic_res = { | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 109 | 	.name = "Quad Interrupt Controller", | 
 | 110 | 	.start = 0xFC70, | 
 | 111 | 	.end = 0xFCFF | 
| Adrian Bunk | dd7ba3b | 2006-04-10 22:52:49 -0700 | [diff] [blame] | 112 | }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 |  | 
 | 114 | /* This function is used to pack a data bit stream inside a message. | 
 | 115 |  * It writes num_bits of the data buffer in msg starting at start_bit. | 
 | 116 |  * Note: This function assumes that any unused bit in the data stream | 
 | 117 |  * is set to zero so that the ors will work correctly */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | static void | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 119 | cat_pack(__u8 * msg, const __u16 start_bit, __u8 * data, const __u16 num_bits) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | { | 
 | 121 | 	/* compute initial shift needed */ | 
 | 122 | 	const __u16 offset = start_bit % BITS_PER_BYTE; | 
 | 123 | 	__u16 len = num_bits / BITS_PER_BYTE; | 
 | 124 | 	__u16 byte = start_bit / BITS_PER_BYTE; | 
 | 125 | 	__u16 residue = (num_bits % BITS_PER_BYTE) + offset; | 
 | 126 | 	int i; | 
 | 127 |  | 
 | 128 | 	/* adjust if we have more than a byte of residue */ | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 129 | 	if (residue >= BITS_PER_BYTE) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | 		residue -= BITS_PER_BYTE; | 
 | 131 | 		len++; | 
 | 132 | 	} | 
 | 133 |  | 
 | 134 | 	/* clear out the bits.  We assume here that if len==0 then | 
 | 135 | 	 * residue >= offset.  This is always true for the catbus | 
 | 136 | 	 * operations */ | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 137 | 	msg[byte] &= 0xff << (BITS_PER_BYTE - offset); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | 	msg[byte++] |= data[0] >> offset; | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 139 | 	if (len == 0) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | 		return; | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 141 | 	for (i = 1; i < len; i++) | 
 | 142 | 		msg[byte++] = (data[i - 1] << (BITS_PER_BYTE - offset)) | 
 | 143 | 		    | (data[i] >> offset); | 
 | 144 | 	if (residue != 0) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | 		__u8 mask = 0xff >> residue; | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 146 | 		__u8 last_byte = data[i - 1] << (BITS_PER_BYTE - offset) | 
 | 147 | 		    | (data[i] >> offset); | 
 | 148 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | 		last_byte &= ~mask; | 
 | 150 | 		msg[byte] &= mask; | 
 | 151 | 		msg[byte] |= last_byte; | 
 | 152 | 	} | 
 | 153 | 	return; | 
 | 154 | } | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 155 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | /* unpack the data again (same arguments as cat_pack()). data buffer | 
 | 157 |  * must be zero populated. | 
 | 158 |  * | 
 | 159 |  * Function: given a message string move to start_bit and copy num_bits into | 
 | 160 |  * data (starting at bit 0 in data). | 
 | 161 |  */ | 
 | 162 | static void | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 163 | cat_unpack(__u8 * msg, const __u16 start_bit, __u8 * data, const __u16 num_bits) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | { | 
 | 165 | 	/* compute initial shift needed */ | 
 | 166 | 	const __u16 offset = start_bit % BITS_PER_BYTE; | 
 | 167 | 	__u16 len = num_bits / BITS_PER_BYTE; | 
 | 168 | 	const __u8 last_bits = num_bits % BITS_PER_BYTE; | 
 | 169 | 	__u16 byte = start_bit / BITS_PER_BYTE; | 
 | 170 | 	int i; | 
 | 171 |  | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 172 | 	if (last_bits != 0) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | 		len++; | 
 | 174 |  | 
 | 175 | 	/* special case: want < 8 bits from msg and we can get it from | 
 | 176 | 	 * a single byte of the msg */ | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 177 | 	if (len == 0 && BITS_PER_BYTE - offset >= num_bits) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | 		data[0] = msg[byte] << offset; | 
 | 179 | 		data[0] &= 0xff >> (BITS_PER_BYTE - num_bits); | 
 | 180 | 		return; | 
 | 181 | 	} | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 182 | 	for (i = 0; i < len; i++) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | 		/* this annoying if has to be done just in case a read of | 
 | 184 | 		 * msg one beyond the array causes a panic */ | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 185 | 		if (offset != 0) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | 			data[i] = msg[byte++] << offset; | 
 | 187 | 			data[i] |= msg[byte] >> (BITS_PER_BYTE - offset); | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 188 | 		} else { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | 			data[i] = msg[byte++]; | 
 | 190 | 		} | 
 | 191 | 	} | 
 | 192 | 	/* do we need to truncate the final byte */ | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 193 | 	if (last_bits != 0) { | 
 | 194 | 		data[i - 1] &= 0xff << (BITS_PER_BYTE - last_bits); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | 	} | 
 | 196 | 	return; | 
 | 197 | } | 
 | 198 |  | 
 | 199 | static void | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 200 | cat_build_header(__u8 * header, const __u16 len, const __u16 smallest_reg_bits, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | 		 const __u16 longest_reg_bits) | 
 | 202 | { | 
 | 203 | 	int i; | 
 | 204 | 	__u16 start_bit = (smallest_reg_bits - 1) % BITS_PER_BYTE; | 
 | 205 | 	__u8 *last_byte = &header[len - 1]; | 
 | 206 |  | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 207 | 	if (start_bit == 0) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | 		start_bit = 1;	/* must have at least one bit in the hdr */ | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 209 |  | 
 | 210 | 	for (i = 0; i < len; i++) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | 		header[i] = 0; | 
 | 212 |  | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 213 | 	for (i = start_bit; i > 0; i--) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | 		*last_byte = ((*last_byte) << 1) + 1; | 
 | 215 |  | 
 | 216 | } | 
 | 217 |  | 
 | 218 | static int | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 219 | cat_sendinst(voyager_module_t * modp, voyager_asic_t * asicp, __u8 reg, __u8 op) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | { | 
 | 221 | 	__u8 parity, inst, inst_buf[4] = { 0 }; | 
 | 222 | 	__u8 iseq[VOYAGER_MAX_SCAN_PATH], hseq[VOYAGER_MAX_REG_SIZE]; | 
 | 223 | 	__u16 ibytes, hbytes, padbits; | 
 | 224 | 	int i; | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 225 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | 	/*  | 
 | 227 | 	 * Parity is the parity of the register number + 1 (READ_REGISTER | 
 | 228 | 	 * and WRITE_REGISTER always add '1' to the number of bits == 1) | 
 | 229 | 	 */ | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 230 | 	parity = (__u8) (1 + (reg & 0x01) + | 
 | 231 | 			 ((__u8) (reg & 0x02) >> 1) + | 
 | 232 | 			 ((__u8) (reg & 0x04) >> 2) + | 
 | 233 | 			 ((__u8) (reg & 0x08) >> 3)) % 2; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 |  | 
 | 235 | 	inst = ((parity << 7) | (reg << 2) | op); | 
 | 236 |  | 
 | 237 | 	outb(VOYAGER_CAT_IRCYC, CAT_CMD); | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 238 | 	if (!modp->scan_path_connected) { | 
 | 239 | 		if (asicp->asic_id != VOYAGER_CAT_ID) { | 
 | 240 | 			printk | 
 | 241 | 			    ("**WARNING***: cat_sendinst has disconnected scan path not to CAT asic\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | 			return 1; | 
 | 243 | 		} | 
 | 244 | 		outb(VOYAGER_CAT_HEADER, CAT_DATA); | 
 | 245 | 		outb(inst, CAT_DATA); | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 246 | 		if (inb(CAT_DATA) != VOYAGER_CAT_HEADER) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | 			CDEBUG(("VOYAGER CAT: cat_sendinst failed to get CAT_HEADER\n")); | 
 | 248 | 			return 1; | 
 | 249 | 		} | 
 | 250 | 		return 0; | 
 | 251 | 	} | 
 | 252 | 	ibytes = modp->inst_bits / BITS_PER_BYTE; | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 253 | 	if ((padbits = modp->inst_bits % BITS_PER_BYTE) != 0) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | 		padbits = BITS_PER_BYTE - padbits; | 
 | 255 | 		ibytes++; | 
 | 256 | 	} | 
 | 257 | 	hbytes = modp->largest_reg / BITS_PER_BYTE; | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 258 | 	if (modp->largest_reg % BITS_PER_BYTE) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | 		hbytes++; | 
 | 260 | 	CDEBUG(("cat_sendinst: ibytes=%d, hbytes=%d\n", ibytes, hbytes)); | 
 | 261 | 	/* initialise the instruction sequence to 0xff */ | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 262 | 	for (i = 0; i < ibytes + hbytes; i++) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | 		iseq[i] = 0xff; | 
 | 264 | 	cat_build_header(hseq, hbytes, modp->smallest_reg, modp->largest_reg); | 
 | 265 | 	cat_pack(iseq, modp->inst_bits, hseq, hbytes * BITS_PER_BYTE); | 
 | 266 | 	inst_buf[0] = inst; | 
 | 267 | 	inst_buf[1] = 0xFF >> (modp->largest_reg % BITS_PER_BYTE); | 
 | 268 | 	cat_pack(iseq, asicp->bit_location, inst_buf, asicp->ireg_length); | 
 | 269 | #ifdef VOYAGER_CAT_DEBUG | 
 | 270 | 	printk("ins = 0x%x, iseq: ", inst); | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 271 | 	for (i = 0; i < ibytes + hbytes; i++) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | 		printk("0x%x ", iseq[i]); | 
 | 273 | 	printk("\n"); | 
 | 274 | #endif | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 275 | 	if (cat_shiftout(iseq, ibytes, hbytes, padbits)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | 		CDEBUG(("VOYAGER CAT: cat_sendinst: cat_shiftout failed\n")); | 
 | 277 | 		return 1; | 
 | 278 | 	} | 
 | 279 | 	CDEBUG(("CAT SHIFTOUT DONE\n")); | 
 | 280 | 	return 0; | 
 | 281 | } | 
 | 282 |  | 
 | 283 | static int | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 284 | cat_getdata(voyager_module_t * modp, voyager_asic_t * asicp, __u8 reg, | 
 | 285 | 	    __u8 * value) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | { | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 287 | 	if (!modp->scan_path_connected) { | 
 | 288 | 		if (asicp->asic_id != VOYAGER_CAT_ID) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | 			CDEBUG(("VOYAGER CAT: ERROR: cat_getdata to CAT asic with scan path connected\n")); | 
 | 290 | 			return 1; | 
 | 291 | 		} | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 292 | 		if (reg > VOYAGER_SUBADDRHI) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | 			outb(VOYAGER_CAT_RUN, CAT_CMD); | 
 | 294 | 		outb(VOYAGER_CAT_DRCYC, CAT_CMD); | 
 | 295 | 		outb(VOYAGER_CAT_HEADER, CAT_DATA); | 
 | 296 | 		*value = inb(CAT_DATA); | 
 | 297 | 		outb(0xAA, CAT_DATA); | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 298 | 		if (inb(CAT_DATA) != VOYAGER_CAT_HEADER) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | 			CDEBUG(("cat_getdata: failed to get VOYAGER_CAT_HEADER\n")); | 
 | 300 | 			return 1; | 
 | 301 | 		} | 
 | 302 | 		return 0; | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 303 | 	} else { | 
 | 304 | 		__u16 sbits = modp->num_asics - 1 + asicp->ireg_length; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | 		__u16 sbytes = sbits / BITS_PER_BYTE; | 
 | 306 | 		__u16 tbytes; | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 307 | 		__u8 string[VOYAGER_MAX_SCAN_PATH], | 
 | 308 | 		    trailer[VOYAGER_MAX_REG_SIZE]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | 		__u8 padbits; | 
 | 310 | 		int i; | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 311 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | 		outb(VOYAGER_CAT_DRCYC, CAT_CMD); | 
 | 313 |  | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 314 | 		if ((padbits = sbits % BITS_PER_BYTE) != 0) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | 			padbits = BITS_PER_BYTE - padbits; | 
 | 316 | 			sbytes++; | 
 | 317 | 		} | 
 | 318 | 		tbytes = asicp->ireg_length / BITS_PER_BYTE; | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 319 | 		if (asicp->ireg_length % BITS_PER_BYTE) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | 			tbytes++; | 
 | 321 | 		CDEBUG(("cat_getdata: tbytes = %d, sbytes = %d, padbits = %d\n", | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 322 | 			tbytes, sbytes, padbits)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | 		cat_build_header(trailer, tbytes, 1, asicp->ireg_length); | 
 | 324 |  | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 325 | 		for (i = tbytes - 1; i >= 0; i--) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | 			outb(trailer[i], CAT_DATA); | 
 | 327 | 			string[sbytes + i] = inb(CAT_DATA); | 
 | 328 | 		} | 
 | 329 |  | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 330 | 		for (i = sbytes - 1; i >= 0; i--) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | 			outb(0xaa, CAT_DATA); | 
 | 332 | 			string[i] = inb(CAT_DATA); | 
 | 333 | 		} | 
 | 334 | 		*value = 0; | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 335 | 		cat_unpack(string, | 
 | 336 | 			   padbits + (tbytes * BITS_PER_BYTE) + | 
 | 337 | 			   asicp->asic_location, value, asicp->ireg_length); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | #ifdef VOYAGER_CAT_DEBUG | 
 | 339 | 		printk("value=0x%x, string: ", *value); | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 340 | 		for (i = 0; i < tbytes + sbytes; i++) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | 			printk("0x%x ", string[i]); | 
 | 342 | 		printk("\n"); | 
 | 343 | #endif | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 344 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | 		/* sanity check the rest of the return */ | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 346 | 		for (i = 0; i < tbytes; i++) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | 			__u8 input = 0; | 
 | 348 |  | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 349 | 			cat_unpack(string, padbits + (i * BITS_PER_BYTE), | 
 | 350 | 				   &input, BITS_PER_BYTE); | 
 | 351 | 			if (trailer[i] != input) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | 				CDEBUG(("cat_getdata: failed to sanity check rest of ret(%d) 0x%x != 0x%x\n", i, input, trailer[i])); | 
 | 353 | 				return 1; | 
 | 354 | 			} | 
 | 355 | 		} | 
 | 356 | 		CDEBUG(("cat_getdata DONE\n")); | 
 | 357 | 		return 0; | 
 | 358 | 	} | 
 | 359 | } | 
 | 360 |  | 
 | 361 | static int | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 362 | cat_shiftout(__u8 * data, __u16 data_bytes, __u16 header_bytes, __u8 pad_bits) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | { | 
 | 364 | 	int i; | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 365 |  | 
 | 366 | 	for (i = data_bytes + header_bytes - 1; i >= header_bytes; i--) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | 		outb(data[i], CAT_DATA); | 
 | 368 |  | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 369 | 	for (i = header_bytes - 1; i >= 0; i--) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | 		__u8 header = 0; | 
 | 371 | 		__u8 input; | 
 | 372 |  | 
 | 373 | 		outb(data[i], CAT_DATA); | 
 | 374 | 		input = inb(CAT_DATA); | 
 | 375 | 		CDEBUG(("cat_shiftout: returned 0x%x\n", input)); | 
 | 376 | 		cat_unpack(data, ((data_bytes + i) * BITS_PER_BYTE) - pad_bits, | 
 | 377 | 			   &header, BITS_PER_BYTE); | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 378 | 		if (input != header) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | 			CDEBUG(("VOYAGER CAT: cat_shiftout failed to return header 0x%x != 0x%x\n", input, header)); | 
 | 380 | 			return 1; | 
 | 381 | 		} | 
 | 382 | 	} | 
 | 383 | 	return 0; | 
 | 384 | } | 
 | 385 |  | 
 | 386 | static int | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 387 | cat_senddata(voyager_module_t * modp, voyager_asic_t * asicp, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | 	     __u8 reg, __u8 value) | 
 | 389 | { | 
 | 390 | 	outb(VOYAGER_CAT_DRCYC, CAT_CMD); | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 391 | 	if (!modp->scan_path_connected) { | 
 | 392 | 		if (asicp->asic_id != VOYAGER_CAT_ID) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | 			CDEBUG(("VOYAGER CAT: ERROR: scan path disconnected when asic != CAT\n")); | 
 | 394 | 			return 1; | 
 | 395 | 		} | 
 | 396 | 		outb(VOYAGER_CAT_HEADER, CAT_DATA); | 
 | 397 | 		outb(value, CAT_DATA); | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 398 | 		if (inb(CAT_DATA) != VOYAGER_CAT_HEADER) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | 			CDEBUG(("cat_senddata: failed to get correct header response to sent data\n")); | 
 | 400 | 			return 1; | 
 | 401 | 		} | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 402 | 		if (reg > VOYAGER_SUBADDRHI) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | 			outb(VOYAGER_CAT_RUN, CAT_CMD); | 
 | 404 | 			outb(VOYAGER_CAT_END, CAT_CMD); | 
 | 405 | 			outb(VOYAGER_CAT_RUN, CAT_CMD); | 
 | 406 | 		} | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 407 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | 		return 0; | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 409 | 	} else { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | 		__u16 hbytes = asicp->ireg_length / BITS_PER_BYTE; | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 411 | 		__u16 dbytes = | 
 | 412 | 		    (modp->num_asics - 1 + asicp->ireg_length) / BITS_PER_BYTE; | 
 | 413 | 		__u8 padbits, dseq[VOYAGER_MAX_SCAN_PATH], | 
 | 414 | 		    hseq[VOYAGER_MAX_REG_SIZE]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | 		int i; | 
 | 416 |  | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 417 | 		if ((padbits = (modp->num_asics - 1 | 
 | 418 | 				+ asicp->ireg_length) % BITS_PER_BYTE) != 0) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | 			padbits = BITS_PER_BYTE - padbits; | 
 | 420 | 			dbytes++; | 
 | 421 | 		} | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 422 | 		if (asicp->ireg_length % BITS_PER_BYTE) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | 			hbytes++; | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 424 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | 		cat_build_header(hseq, hbytes, 1, asicp->ireg_length); | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 426 |  | 
 | 427 | 		for (i = 0; i < dbytes + hbytes; i++) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | 			dseq[i] = 0xff; | 
 | 429 | 		CDEBUG(("cat_senddata: dbytes=%d, hbytes=%d, padbits=%d\n", | 
 | 430 | 			dbytes, hbytes, padbits)); | 
 | 431 | 		cat_pack(dseq, modp->num_asics - 1 + asicp->ireg_length, | 
 | 432 | 			 hseq, hbytes * BITS_PER_BYTE); | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 433 | 		cat_pack(dseq, asicp->asic_location, &value, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | 			 asicp->ireg_length); | 
 | 435 | #ifdef VOYAGER_CAT_DEBUG | 
 | 436 | 		printk("dseq "); | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 437 | 		for (i = 0; i < hbytes + dbytes; i++) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | 			printk("0x%x ", dseq[i]); | 
 | 439 | 		} | 
 | 440 | 		printk("\n"); | 
 | 441 | #endif | 
 | 442 | 		return cat_shiftout(dseq, dbytes, hbytes, padbits); | 
 | 443 | 	} | 
 | 444 | } | 
 | 445 |  | 
 | 446 | static int | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 447 | cat_write(voyager_module_t * modp, voyager_asic_t * asicp, __u8 reg, __u8 value) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | { | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 449 | 	if (cat_sendinst(modp, asicp, reg, VOYAGER_WRITE_CONFIG)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | 		return 1; | 
 | 451 | 	return cat_senddata(modp, asicp, reg, value); | 
 | 452 | } | 
 | 453 |  | 
 | 454 | static int | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 455 | cat_read(voyager_module_t * modp, voyager_asic_t * asicp, __u8 reg, | 
 | 456 | 	 __u8 * value) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | { | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 458 | 	if (cat_sendinst(modp, asicp, reg, VOYAGER_READ_CONFIG)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | 		return 1; | 
 | 460 | 	return cat_getdata(modp, asicp, reg, value); | 
 | 461 | } | 
 | 462 |  | 
 | 463 | static int | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 464 | cat_subaddrsetup(voyager_module_t * modp, voyager_asic_t * asicp, __u16 offset, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | 		 __u16 len) | 
 | 466 | { | 
 | 467 | 	__u8 val; | 
 | 468 |  | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 469 | 	if (len > 1) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | 		/* set auto increment */ | 
 | 471 | 		__u8 newval; | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 472 |  | 
 | 473 | 		if (cat_read(modp, asicp, VOYAGER_AUTO_INC_REG, &val)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | 			CDEBUG(("cat_subaddrsetup: read of VOYAGER_AUTO_INC_REG failed\n")); | 
 | 475 | 			return 1; | 
 | 476 | 		} | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 477 | 		CDEBUG(("cat_subaddrsetup: VOYAGER_AUTO_INC_REG = 0x%x\n", | 
 | 478 | 			val)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | 		newval = val | VOYAGER_AUTO_INC; | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 480 | 		if (newval != val) { | 
 | 481 | 			if (cat_write(modp, asicp, VOYAGER_AUTO_INC_REG, val)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | 				CDEBUG(("cat_subaddrsetup: write to VOYAGER_AUTO_INC_REG failed\n")); | 
 | 483 | 				return 1; | 
 | 484 | 			} | 
 | 485 | 		} | 
 | 486 | 	} | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 487 | 	if (cat_write(modp, asicp, VOYAGER_SUBADDRLO, (__u8) (offset & 0xff))) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | 		CDEBUG(("cat_subaddrsetup: write to SUBADDRLO failed\n")); | 
 | 489 | 		return 1; | 
 | 490 | 	} | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 491 | 	if (asicp->subaddr > VOYAGER_SUBADDR_LO) { | 
 | 492 | 		if (cat_write | 
 | 493 | 		    (modp, asicp, VOYAGER_SUBADDRHI, (__u8) (offset >> 8))) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | 			CDEBUG(("cat_subaddrsetup: write to SUBADDRHI failed\n")); | 
 | 495 | 			return 1; | 
 | 496 | 		} | 
 | 497 | 		cat_read(modp, asicp, VOYAGER_SUBADDRHI, &val); | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 498 | 		CDEBUG(("cat_subaddrsetup: offset = %d, hi = %d\n", offset, | 
 | 499 | 			val)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | 	} | 
 | 501 | 	cat_read(modp, asicp, VOYAGER_SUBADDRLO, &val); | 
 | 502 | 	CDEBUG(("cat_subaddrsetup: offset = %d, lo = %d\n", offset, val)); | 
 | 503 | 	return 0; | 
 | 504 | } | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 505 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | static int | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 507 | cat_subwrite(voyager_module_t * modp, voyager_asic_t * asicp, __u16 offset, | 
 | 508 | 	     __u16 len, void *buf) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | { | 
 | 510 | 	int i, retval; | 
 | 511 |  | 
 | 512 | 	/* FIXME: need special actions for VOYAGER_CAT_ID here */ | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 513 | 	if (asicp->asic_id == VOYAGER_CAT_ID) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | 		CDEBUG(("cat_subwrite: ATTEMPT TO WRITE TO CAT ASIC\n")); | 
 | 515 | 		/* FIXME -- This is supposed to be handled better | 
 | 516 | 		 * There is a problem writing to the cat asic in the | 
 | 517 | 		 * PSI.  The 30us delay seems to work, though */ | 
 | 518 | 		udelay(30); | 
 | 519 | 	} | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 520 |  | 
 | 521 | 	if ((retval = cat_subaddrsetup(modp, asicp, offset, len)) != 0) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | 		printk("cat_subwrite: cat_subaddrsetup FAILED\n"); | 
 | 523 | 		return retval; | 
 | 524 | 	} | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 525 |  | 
 | 526 | 	if (cat_sendinst | 
 | 527 | 	    (modp, asicp, VOYAGER_SUBADDRDATA, VOYAGER_WRITE_CONFIG)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | 		printk("cat_subwrite: cat_sendinst FAILED\n"); | 
 | 529 | 		return 1; | 
 | 530 | 	} | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 531 | 	for (i = 0; i < len; i++) { | 
 | 532 | 		if (cat_senddata(modp, asicp, 0xFF, ((__u8 *) buf)[i])) { | 
 | 533 | 			printk | 
 | 534 | 			    ("cat_subwrite: cat_sendata element at %d FAILED\n", | 
 | 535 | 			     i); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | 			return 1; | 
 | 537 | 		} | 
 | 538 | 	} | 
 | 539 | 	return 0; | 
 | 540 | } | 
 | 541 | static int | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 542 | cat_subread(voyager_module_t * modp, voyager_asic_t * asicp, __u16 offset, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | 	    __u16 len, void *buf) | 
 | 544 | { | 
 | 545 | 	int i, retval; | 
 | 546 |  | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 547 | 	if ((retval = cat_subaddrsetup(modp, asicp, offset, len)) != 0) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | 		CDEBUG(("cat_subread: cat_subaddrsetup FAILED\n")); | 
 | 549 | 		return retval; | 
 | 550 | 	} | 
 | 551 |  | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 552 | 	if (cat_sendinst(modp, asicp, VOYAGER_SUBADDRDATA, VOYAGER_READ_CONFIG)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | 		CDEBUG(("cat_subread: cat_sendinst failed\n")); | 
 | 554 | 		return 1; | 
 | 555 | 	} | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 556 | 	for (i = 0; i < len; i++) { | 
 | 557 | 		if (cat_getdata(modp, asicp, 0xFF, &((__u8 *) buf)[i])) { | 
 | 558 | 			CDEBUG(("cat_subread: cat_getdata element %d failed\n", | 
 | 559 | 				i)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | 			return 1; | 
 | 561 | 		} | 
 | 562 | 	} | 
 | 563 | 	return 0; | 
 | 564 | } | 
 | 565 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | /* buffer for storing EPROM data read in during initialisation */ | 
 | 567 | static __initdata __u8 eprom_buf[0xFFFF]; | 
 | 568 | static voyager_module_t *voyager_initial_module; | 
 | 569 |  | 
 | 570 | /* Initialise the cat bus components.  We assume this is called by the | 
 | 571 |  * boot cpu *after* all memory initialisation has been done (so we can | 
 | 572 |  * use kmalloc) but before smp initialisation, so we can probe the SMP | 
 | 573 |  * configuration and pick up necessary information.  */ | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 574 | void __init voyager_cat_init(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | { | 
 | 576 | 	voyager_module_t **modpp = &voyager_initial_module; | 
 | 577 | 	voyager_asic_t **asicpp; | 
 | 578 | 	voyager_asic_t *qabc_asic = NULL; | 
 | 579 | 	int i, j; | 
 | 580 | 	unsigned long qic_addr = 0; | 
 | 581 | 	__u8 qabc_data[0x20]; | 
 | 582 | 	__u8 num_submodules, val; | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 583 | 	voyager_eprom_hdr_t *eprom_hdr = (voyager_eprom_hdr_t *) & eprom_buf[0]; | 
 | 584 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | 	__u8 cmos[4]; | 
 | 586 | 	unsigned long addr; | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 587 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | 	/* initiallise the SUS mailbox */ | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 589 | 	for (i = 0; i < sizeof(cmos); i++) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | 		cmos[i] = voyager_extended_cmos_read(VOYAGER_DUMP_LOCATION + i); | 
 | 591 | 	addr = *(unsigned long *)cmos; | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 592 | 	if ((addr & 0xff000000) != 0xff000000) { | 
 | 593 | 		printk(KERN_ERR | 
 | 594 | 		       "Voyager failed to get SUS mailbox (addr = 0x%lx\n", | 
 | 595 | 		       addr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | 	} else { | 
 | 597 | 		static struct resource res; | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 598 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | 		res.name = "voyager SUS"; | 
 | 600 | 		res.start = addr; | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 601 | 		res.end = addr + 0x3ff; | 
 | 602 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | 		request_resource(&iomem_resource, &res); | 
 | 604 | 		voyager_SUS = (struct voyager_SUS *) | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 605 | 		    ioremap(addr, 0x400); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | 		printk(KERN_NOTICE "Voyager SUS mailbox version 0x%x\n", | 
 | 607 | 		       voyager_SUS->SUS_version); | 
 | 608 | 		voyager_SUS->kernel_version = VOYAGER_MAILBOX_VERSION; | 
 | 609 | 		voyager_SUS->kernel_flags = VOYAGER_OS_HAS_SYSINT; | 
 | 610 | 	} | 
 | 611 |  | 
 | 612 | 	/* clear the processor counts */ | 
 | 613 | 	voyager_extended_vic_processors = 0; | 
 | 614 | 	voyager_quad_processors = 0; | 
 | 615 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | 	printk("VOYAGER: beginning CAT bus probe\n"); | 
 | 617 | 	/* set up the SuperSet Port Block which tells us where the | 
 | 618 | 	 * CAT communication port is */ | 
 | 619 | 	sspb = inb(VOYAGER_SSPB_RELOCATION_PORT) * 0x100; | 
 | 620 | 	VDEBUG(("VOYAGER DEBUG: sspb = 0x%x\n", sspb)); | 
 | 621 |  | 
 | 622 | 	/* now find out if were 8 slot or normal */ | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 623 | 	if ((inb(VIC_PROC_WHO_AM_I) & EIGHT_SLOT_IDENTIFIER) | 
 | 624 | 	    == EIGHT_SLOT_IDENTIFIER) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | 		voyager_8slot = 1; | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 626 | 		printk(KERN_NOTICE | 
 | 627 | 		       "Voyager: Eight slot 51xx configuration detected\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | 	} | 
 | 629 |  | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 630 | 	for (i = VOYAGER_MIN_MODULE; i <= VOYAGER_MAX_MODULE; i++) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | 		__u8 input; | 
 | 632 | 		int asic; | 
 | 633 | 		__u16 eprom_size; | 
 | 634 | 		__u16 sp_offset; | 
 | 635 |  | 
 | 636 | 		outb(VOYAGER_CAT_DESELECT, VOYAGER_CAT_CONFIG_PORT); | 
 | 637 | 		outb(i, VOYAGER_CAT_CONFIG_PORT); | 
 | 638 |  | 
 | 639 | 		/* check the presence of the module */ | 
 | 640 | 		outb(VOYAGER_CAT_RUN, CAT_CMD); | 
 | 641 | 		outb(VOYAGER_CAT_IRCYC, CAT_CMD); | 
 | 642 | 		outb(VOYAGER_CAT_HEADER, CAT_DATA); | 
 | 643 | 		/* stream series of alternating 1's and 0's to stimulate | 
 | 644 | 		 * response */ | 
 | 645 | 		outb(0xAA, CAT_DATA); | 
 | 646 | 		input = inb(CAT_DATA); | 
 | 647 | 		outb(VOYAGER_CAT_END, CAT_CMD); | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 648 | 		if (input != VOYAGER_CAT_HEADER) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | 			continue; | 
 | 650 | 		} | 
 | 651 | 		CDEBUG(("VOYAGER DEBUG: found module id 0x%x, %s\n", i, | 
 | 652 | 			cat_module_name(i))); | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 653 | 		*modpp = kmalloc(sizeof(voyager_module_t), GFP_KERNEL);	/*&voyager_module_storage[cat_count++]; */ | 
 | 654 | 		if (*modpp == NULL) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | 			printk("**WARNING** kmalloc failure in cat_init\n"); | 
 | 656 | 			continue; | 
 | 657 | 		} | 
 | 658 | 		memset(*modpp, 0, sizeof(voyager_module_t)); | 
 | 659 | 		/* need temporary asic for cat_subread.  It will be | 
 | 660 | 		 * filled in correctly later */ | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 661 | 		(*modpp)->asic = kmalloc(sizeof(voyager_asic_t), GFP_KERNEL);	/*&voyager_asic_storage[asic_count]; */ | 
 | 662 | 		if ((*modpp)->asic == NULL) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | 			printk("**WARNING** kmalloc failure in cat_init\n"); | 
 | 664 | 			continue; | 
 | 665 | 		} | 
 | 666 | 		memset((*modpp)->asic, 0, sizeof(voyager_asic_t)); | 
 | 667 | 		(*modpp)->asic->asic_id = VOYAGER_CAT_ID; | 
 | 668 | 		(*modpp)->asic->subaddr = VOYAGER_SUBADDR_HI; | 
 | 669 | 		(*modpp)->module_addr = i; | 
 | 670 | 		(*modpp)->scan_path_connected = 0; | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 671 | 		if (i == VOYAGER_PSI) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | 			/* Exception leg for modules with no EEPROM */ | 
 | 673 | 			printk("Module \"%s\"\n", cat_module_name(i)); | 
 | 674 | 			continue; | 
 | 675 | 		} | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 676 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | 		CDEBUG(("cat_init: Reading eeprom for module 0x%x at offset %d\n", i, VOYAGER_XSUM_END_OFFSET)); | 
 | 678 | 		outb(VOYAGER_CAT_RUN, CAT_CMD); | 
 | 679 | 		cat_disconnect(*modpp, (*modpp)->asic); | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 680 | 		if (cat_subread(*modpp, (*modpp)->asic, | 
 | 681 | 				VOYAGER_XSUM_END_OFFSET, sizeof(eprom_size), | 
 | 682 | 				&eprom_size)) { | 
 | 683 | 			printk | 
 | 684 | 			    ("**WARNING**: Voyager couldn't read EPROM size for module 0x%x\n", | 
 | 685 | 			     i); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | 			outb(VOYAGER_CAT_END, CAT_CMD); | 
 | 687 | 			continue; | 
 | 688 | 		} | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 689 | 		if (eprom_size > sizeof(eprom_buf)) { | 
 | 690 | 			printk | 
 | 691 | 			    ("**WARNING**: Voyager insufficient size to read EPROM data, module 0x%x.  Need %d\n", | 
 | 692 | 			     i, eprom_size); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | 			outb(VOYAGER_CAT_END, CAT_CMD); | 
 | 694 | 			continue; | 
 | 695 | 		} | 
 | 696 | 		outb(VOYAGER_CAT_END, CAT_CMD); | 
 | 697 | 		outb(VOYAGER_CAT_RUN, CAT_CMD); | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 698 | 		CDEBUG(("cat_init: module 0x%x, eeprom_size %d\n", i, | 
 | 699 | 			eprom_size)); | 
 | 700 | 		if (cat_subread | 
 | 701 | 		    (*modpp, (*modpp)->asic, 0, eprom_size, eprom_buf)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | 			outb(VOYAGER_CAT_END, CAT_CMD); | 
 | 703 | 			continue; | 
 | 704 | 		} | 
 | 705 | 		outb(VOYAGER_CAT_END, CAT_CMD); | 
 | 706 | 		printk("Module \"%s\", version 0x%x, tracer 0x%x, asics %d\n", | 
 | 707 | 		       cat_module_name(i), eprom_hdr->version_id, | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 708 | 		       *((__u32 *) eprom_hdr->tracer), eprom_hdr->num_asics); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | 		(*modpp)->ee_size = eprom_hdr->ee_size; | 
 | 710 | 		(*modpp)->num_asics = eprom_hdr->num_asics; | 
 | 711 | 		asicpp = &((*modpp)->asic); | 
 | 712 | 		sp_offset = eprom_hdr->scan_path_offset; | 
 | 713 | 		/* All we really care about are the Quad cards.  We | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 714 | 		 * identify them because they are in a processor slot | 
 | 715 | 		 * and have only four asics */ | 
 | 716 | 		if ((i < 0x10 || (i >= 0x14 && i < 0x1c) || i > 0x1f)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | 			modpp = &((*modpp)->next); | 
 | 718 | 			continue; | 
 | 719 | 		} | 
 | 720 | 		/* Now we know it's in a processor slot, does it have | 
 | 721 | 		 * a quad baseboard submodule */ | 
 | 722 | 		outb(VOYAGER_CAT_RUN, CAT_CMD); | 
 | 723 | 		cat_read(*modpp, (*modpp)->asic, VOYAGER_SUBMODPRESENT, | 
 | 724 | 			 &num_submodules); | 
 | 725 | 		/* lowest two bits, active low */ | 
 | 726 | 		num_submodules = ~(0xfc | num_submodules); | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 727 | 		CDEBUG(("VOYAGER CAT: %d submodules present\n", | 
 | 728 | 			num_submodules)); | 
 | 729 | 		if (num_submodules == 0) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | 			/* fill in the dyadic extended processors */ | 
 | 731 | 			__u8 cpu = i & 0x07; | 
 | 732 |  | 
 | 733 | 			printk("Module \"%s\": Dyadic Processor Card\n", | 
 | 734 | 			       cat_module_name(i)); | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 735 | 			voyager_extended_vic_processors |= (1 << cpu); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | 			cpu += 4; | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 737 | 			voyager_extended_vic_processors |= (1 << cpu); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | 			outb(VOYAGER_CAT_END, CAT_CMD); | 
 | 739 | 			continue; | 
 | 740 | 		} | 
 | 741 |  | 
 | 742 | 		/* now we want to read the asics on the first submodule, | 
 | 743 | 		 * which should be the quad base board */ | 
 | 744 |  | 
 | 745 | 		cat_read(*modpp, (*modpp)->asic, VOYAGER_SUBMODSELECT, &val); | 
 | 746 | 		CDEBUG(("cat_init: SUBMODSELECT value = 0x%x\n", val)); | 
 | 747 | 		val = (val & 0x7c) | VOYAGER_QUAD_BASEBOARD; | 
 | 748 | 		cat_write(*modpp, (*modpp)->asic, VOYAGER_SUBMODSELECT, val); | 
 | 749 |  | 
 | 750 | 		outb(VOYAGER_CAT_END, CAT_CMD); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 |  | 
 | 752 | 		CDEBUG(("cat_init: Reading eeprom for module 0x%x at offset %d\n", i, VOYAGER_XSUM_END_OFFSET)); | 
 | 753 | 		outb(VOYAGER_CAT_RUN, CAT_CMD); | 
 | 754 | 		cat_disconnect(*modpp, (*modpp)->asic); | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 755 | 		if (cat_subread(*modpp, (*modpp)->asic, | 
 | 756 | 				VOYAGER_XSUM_END_OFFSET, sizeof(eprom_size), | 
 | 757 | 				&eprom_size)) { | 
 | 758 | 			printk | 
 | 759 | 			    ("**WARNING**: Voyager couldn't read EPROM size for module 0x%x\n", | 
 | 760 | 			     i); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | 			outb(VOYAGER_CAT_END, CAT_CMD); | 
 | 762 | 			continue; | 
 | 763 | 		} | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 764 | 		if (eprom_size > sizeof(eprom_buf)) { | 
 | 765 | 			printk | 
 | 766 | 			    ("**WARNING**: Voyager insufficient size to read EPROM data, module 0x%x.  Need %d\n", | 
 | 767 | 			     i, eprom_size); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | 			outb(VOYAGER_CAT_END, CAT_CMD); | 
 | 769 | 			continue; | 
 | 770 | 		} | 
 | 771 | 		outb(VOYAGER_CAT_END, CAT_CMD); | 
 | 772 | 		outb(VOYAGER_CAT_RUN, CAT_CMD); | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 773 | 		CDEBUG(("cat_init: module 0x%x, eeprom_size %d\n", i, | 
 | 774 | 			eprom_size)); | 
 | 775 | 		if (cat_subread | 
 | 776 | 		    (*modpp, (*modpp)->asic, 0, eprom_size, eprom_buf)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | 			outb(VOYAGER_CAT_END, CAT_CMD); | 
 | 778 | 			continue; | 
 | 779 | 		} | 
 | 780 | 		outb(VOYAGER_CAT_END, CAT_CMD); | 
 | 781 | 		/* Now do everything for the QBB submodule 1 */ | 
 | 782 | 		(*modpp)->ee_size = eprom_hdr->ee_size; | 
 | 783 | 		(*modpp)->num_asics = eprom_hdr->num_asics; | 
 | 784 | 		asicpp = &((*modpp)->asic); | 
 | 785 | 		sp_offset = eprom_hdr->scan_path_offset; | 
 | 786 | 		/* get rid of the dummy CAT asic and read the real one */ | 
 | 787 | 		kfree((*modpp)->asic); | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 788 | 		for (asic = 0; asic < (*modpp)->num_asics; asic++) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | 			int j; | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 790 | 			voyager_asic_t *asicp = *asicpp = kzalloc(sizeof(voyager_asic_t), GFP_KERNEL);	/*&voyager_asic_storage[asic_count++]; */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | 			voyager_sp_table_t *sp_table; | 
 | 792 | 			voyager_at_t *asic_table; | 
 | 793 | 			voyager_jtt_t *jtag_table; | 
 | 794 |  | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 795 | 			if (asicp == NULL) { | 
 | 796 | 				printk | 
 | 797 | 				    ("**WARNING** kmalloc failure in cat_init\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | 				continue; | 
 | 799 | 			} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | 			asicpp = &(asicp->next); | 
 | 801 | 			asicp->asic_location = asic; | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 802 | 			sp_table = | 
 | 803 | 			    (voyager_sp_table_t *) (eprom_buf + sp_offset); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | 			asicp->asic_id = sp_table->asic_id; | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 805 | 			asic_table = | 
 | 806 | 			    (voyager_at_t *) (eprom_buf + | 
 | 807 | 					      sp_table->asic_data_offset); | 
 | 808 | 			for (j = 0; j < 4; j++) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | 				asicp->jtag_id[j] = asic_table->jtag_id[j]; | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 810 | 			jtag_table = | 
 | 811 | 			    (voyager_jtt_t *) (eprom_buf + | 
 | 812 | 					       asic_table->jtag_offset); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | 			asicp->ireg_length = jtag_table->ireg_len; | 
 | 814 | 			asicp->bit_location = (*modpp)->inst_bits; | 
 | 815 | 			(*modpp)->inst_bits += asicp->ireg_length; | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 816 | 			if (asicp->ireg_length > (*modpp)->largest_reg) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | 				(*modpp)->largest_reg = asicp->ireg_length; | 
 | 818 | 			if (asicp->ireg_length < (*modpp)->smallest_reg || | 
 | 819 | 			    (*modpp)->smallest_reg == 0) | 
 | 820 | 				(*modpp)->smallest_reg = asicp->ireg_length; | 
 | 821 | 			CDEBUG(("asic 0x%x, ireg_length=%d, bit_location=%d\n", | 
 | 822 | 				asicp->asic_id, asicp->ireg_length, | 
 | 823 | 				asicp->bit_location)); | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 824 | 			if (asicp->asic_id == VOYAGER_QUAD_QABC) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | 				CDEBUG(("VOYAGER CAT: QABC ASIC found\n")); | 
 | 826 | 				qabc_asic = asicp; | 
 | 827 | 			} | 
 | 828 | 			sp_offset += sizeof(voyager_sp_table_t); | 
 | 829 | 		} | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 830 | 		CDEBUG(("Module inst_bits = %d, largest_reg = %d, smallest_reg=%d\n", (*modpp)->inst_bits, (*modpp)->largest_reg, (*modpp)->smallest_reg)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | 		/* OK, now we have the QUAD ASICs set up, use them. | 
 | 832 | 		 * we need to: | 
 | 833 | 		 * | 
 | 834 | 		 * 1. Find the Memory area for the Quad CPIs. | 
 | 835 | 		 * 2. Find the Extended VIC processor | 
 | 836 | 		 * 3. Configure a second extended VIC processor (This | 
 | 837 | 		 *    cannot be done for the 51xx. | 
 | 838 | 		 * */ | 
 | 839 | 		outb(VOYAGER_CAT_RUN, CAT_CMD); | 
 | 840 | 		cat_connect(*modpp, (*modpp)->asic); | 
 | 841 | 		CDEBUG(("CAT CONNECTED!!\n")); | 
 | 842 | 		cat_subread(*modpp, qabc_asic, 0, sizeof(qabc_data), qabc_data); | 
 | 843 | 		qic_addr = qabc_data[5] << 8; | 
 | 844 | 		qic_addr = (qic_addr | qabc_data[6]) << 8; | 
 | 845 | 		qic_addr = (qic_addr | qabc_data[7]) << 8; | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 846 | 		printk | 
 | 847 | 		    ("Module \"%s\": Quad Processor Card; CPI 0x%lx, SET=0x%x\n", | 
 | 848 | 		     cat_module_name(i), qic_addr, qabc_data[8]); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | #if 0				/* plumbing fails---FIXME */ | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 850 | 		if ((qabc_data[8] & 0xf0) == 0) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 851 | 			/* FIXME: 32 way 8 CPU slot monster cannot be | 
 | 852 | 			 * plumbed this way---need to check for it */ | 
 | 853 |  | 
 | 854 | 			printk("Plumbing second Extended Quad Processor\n"); | 
 | 855 | 			/* second VIC line hardwired to Quad CPU 1 */ | 
 | 856 | 			qabc_data[8] |= 0x20; | 
 | 857 | 			cat_subwrite(*modpp, qabc_asic, 8, 1, &qabc_data[8]); | 
 | 858 | #ifdef VOYAGER_CAT_DEBUG | 
 | 859 | 			/* verify plumbing */ | 
 | 860 | 			cat_subread(*modpp, qabc_asic, 8, 1, &qabc_data[8]); | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 861 | 			if ((qabc_data[8] & 0xf0) == 0) { | 
 | 862 | 				CDEBUG(("PLUMBING FAILED: 0x%x\n", | 
 | 863 | 					qabc_data[8])); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | 			} | 
 | 865 | #endif | 
 | 866 | 		} | 
 | 867 | #endif | 
 | 868 |  | 
 | 869 | 		{ | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 870 | 			struct resource *res = | 
 | 871 | 			    kzalloc(sizeof(struct resource), GFP_KERNEL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | 			res->name = kmalloc(128, GFP_KERNEL); | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 873 | 			sprintf((char *)res->name, "Voyager %s Quad CPI", | 
 | 874 | 				cat_module_name(i)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | 			res->start = qic_addr; | 
 | 876 | 			res->end = qic_addr + 0x3ff; | 
 | 877 | 			request_resource(&iomem_resource, res); | 
 | 878 | 		} | 
 | 879 |  | 
| Ingo Molnar | ed5e233 | 2008-04-27 23:21:03 +0200 | [diff] [blame] | 880 | 		qic_addr = (unsigned long)ioremap_cache(qic_addr, 0x400); | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 881 |  | 
 | 882 | 		for (j = 0; j < 4; j++) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 883 | 			__u8 cpu; | 
 | 884 |  | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 885 | 			if (voyager_8slot) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | 				/* 8 slot has a different mapping, | 
 | 887 | 				 * each slot has only one vic line, so | 
 | 888 | 				 * 1 cpu in each slot must be < 8 */ | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 889 | 				cpu = (i & 0x07) + j * 8; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 890 | 			} else { | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 891 | 				cpu = (i & 0x03) + j * 4; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | 			} | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 893 | 			if ((qabc_data[8] & (1 << j))) { | 
 | 894 | 				voyager_extended_vic_processors |= (1 << cpu); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | 			} | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 896 | 			if (qabc_data[8] & (1 << (j + 4))) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | 				/* Second SET register plumbed: Quad | 
 | 898 | 				 * card has two VIC connected CPUs. | 
 | 899 | 				 * Secondary cannot be booted as a VIC | 
 | 900 | 				 * CPU */ | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 901 | 				voyager_extended_vic_processors |= (1 << cpu); | 
 | 902 | 				voyager_allowed_boot_processors &= | 
 | 903 | 				    (~(1 << cpu)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | 			} | 
 | 905 |  | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 906 | 			voyager_quad_processors |= (1 << cpu); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 907 | 			voyager_quad_cpi_addr[cpu] = (struct voyager_qic_cpi *) | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 908 | 			    (qic_addr + (j << 8)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 | 			CDEBUG(("CPU%d: CPI address 0x%lx\n", cpu, | 
 | 910 | 				(unsigned long)voyager_quad_cpi_addr[cpu])); | 
 | 911 | 		} | 
 | 912 | 		outb(VOYAGER_CAT_END, CAT_CMD); | 
 | 913 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | 		*asicpp = NULL; | 
 | 915 | 		modpp = &((*modpp)->next); | 
 | 916 | 	} | 
 | 917 | 	*modpp = NULL; | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 918 | 	printk | 
 | 919 | 	    ("CAT Bus Initialisation finished: extended procs 0x%x, quad procs 0x%x, allowed vic boot = 0x%x\n", | 
 | 920 | 	     voyager_extended_vic_processors, voyager_quad_processors, | 
 | 921 | 	     voyager_allowed_boot_processors); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 | 	request_resource(&ioport_resource, &vic_res); | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 923 | 	if (voyager_quad_processors) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | 		request_resource(&ioport_resource, &qic_res); | 
 | 925 | 	/* set up the front power switch */ | 
 | 926 | } | 
 | 927 |  | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 928 | int voyager_cat_readb(__u8 module, __u8 asic, int reg) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | { | 
 | 930 | 	return 0; | 
 | 931 | } | 
 | 932 |  | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 933 | static int cat_disconnect(voyager_module_t * modp, voyager_asic_t * asicp) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | { | 
 | 935 | 	__u8 val; | 
 | 936 | 	int err = 0; | 
 | 937 |  | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 938 | 	if (!modp->scan_path_connected) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 939 | 		return 0; | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 940 | 	if (asicp->asic_id != VOYAGER_CAT_ID) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | 		CDEBUG(("cat_disconnect: ASIC is not CAT\n")); | 
 | 942 | 		return 1; | 
 | 943 | 	} | 
 | 944 | 	err = cat_read(modp, asicp, VOYAGER_SCANPATH, &val); | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 945 | 	if (err) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | 		CDEBUG(("cat_disconnect: failed to read SCANPATH\n")); | 
 | 947 | 		return err; | 
 | 948 | 	} | 
 | 949 | 	val &= VOYAGER_DISCONNECT_ASIC; | 
 | 950 | 	err = cat_write(modp, asicp, VOYAGER_SCANPATH, val); | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 951 | 	if (err) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 952 | 		CDEBUG(("cat_disconnect: failed to write SCANPATH\n")); | 
 | 953 | 		return err; | 
 | 954 | 	} | 
 | 955 | 	outb(VOYAGER_CAT_END, CAT_CMD); | 
 | 956 | 	outb(VOYAGER_CAT_RUN, CAT_CMD); | 
 | 957 | 	modp->scan_path_connected = 0; | 
 | 958 |  | 
 | 959 | 	return 0; | 
 | 960 | } | 
 | 961 |  | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 962 | static int cat_connect(voyager_module_t * modp, voyager_asic_t * asicp) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 963 | { | 
 | 964 | 	__u8 val; | 
 | 965 | 	int err = 0; | 
 | 966 |  | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 967 | 	if (modp->scan_path_connected) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 968 | 		return 0; | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 969 | 	if (asicp->asic_id != VOYAGER_CAT_ID) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | 		CDEBUG(("cat_connect: ASIC is not CAT\n")); | 
 | 971 | 		return 1; | 
 | 972 | 	} | 
 | 973 |  | 
 | 974 | 	err = cat_read(modp, asicp, VOYAGER_SCANPATH, &val); | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 975 | 	if (err) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 976 | 		CDEBUG(("cat_connect: failed to read SCANPATH\n")); | 
 | 977 | 		return err; | 
 | 978 | 	} | 
 | 979 | 	val |= VOYAGER_CONNECT_ASIC; | 
 | 980 | 	err = cat_write(modp, asicp, VOYAGER_SCANPATH, val); | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 981 | 	if (err) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 982 | 		CDEBUG(("cat_connect: failed to write SCANPATH\n")); | 
 | 983 | 		return err; | 
 | 984 | 	} | 
 | 985 | 	outb(VOYAGER_CAT_END, CAT_CMD); | 
 | 986 | 	outb(VOYAGER_CAT_RUN, CAT_CMD); | 
 | 987 | 	modp->scan_path_connected = 1; | 
 | 988 |  | 
 | 989 | 	return 0; | 
 | 990 | } | 
 | 991 |  | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 992 | void voyager_cat_power_off(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 993 | { | 
 | 994 | 	/* Power the machine off by writing to the PSI over the CAT | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 995 | 	 * bus */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 996 | 	__u8 data; | 
 | 997 | 	voyager_module_t psi = { 0 }; | 
 | 998 | 	voyager_asic_t psi_asic = { 0 }; | 
 | 999 |  | 
 | 1000 | 	psi.asic = &psi_asic; | 
 | 1001 | 	psi.asic->asic_id = VOYAGER_CAT_ID; | 
 | 1002 | 	psi.asic->subaddr = VOYAGER_SUBADDR_HI; | 
 | 1003 | 	psi.module_addr = VOYAGER_PSI; | 
 | 1004 | 	psi.scan_path_connected = 0; | 
 | 1005 |  | 
 | 1006 | 	outb(VOYAGER_CAT_END, CAT_CMD); | 
 | 1007 | 	/* Connect the PSI to the CAT Bus */ | 
 | 1008 | 	outb(VOYAGER_CAT_DESELECT, VOYAGER_CAT_CONFIG_PORT); | 
 | 1009 | 	outb(VOYAGER_PSI, VOYAGER_CAT_CONFIG_PORT); | 
 | 1010 | 	outb(VOYAGER_CAT_RUN, CAT_CMD); | 
 | 1011 | 	cat_disconnect(&psi, &psi_asic); | 
 | 1012 | 	/* Read the status */ | 
 | 1013 | 	cat_subread(&psi, &psi_asic, VOYAGER_PSI_GENERAL_REG, 1, &data); | 
 | 1014 | 	outb(VOYAGER_CAT_END, CAT_CMD); | 
 | 1015 | 	CDEBUG(("PSI STATUS 0x%x\n", data)); | 
 | 1016 | 	/* These two writes are power off prep and perform */ | 
 | 1017 | 	data = PSI_CLEAR; | 
 | 1018 | 	outb(VOYAGER_CAT_RUN, CAT_CMD); | 
 | 1019 | 	cat_subwrite(&psi, &psi_asic, VOYAGER_PSI_GENERAL_REG, 1, &data); | 
 | 1020 | 	outb(VOYAGER_CAT_END, CAT_CMD); | 
 | 1021 | 	data = PSI_POWER_DOWN; | 
 | 1022 | 	outb(VOYAGER_CAT_RUN, CAT_CMD); | 
 | 1023 | 	cat_subwrite(&psi, &psi_asic, VOYAGER_PSI_GENERAL_REG, 1, &data); | 
 | 1024 | 	outb(VOYAGER_CAT_END, CAT_CMD); | 
 | 1025 | } | 
 | 1026 |  | 
 | 1027 | struct voyager_status voyager_status = { 0 }; | 
 | 1028 |  | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 1029 | void voyager_cat_psi(__u8 cmd, __u16 reg, __u8 * data) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | { | 
 | 1031 | 	voyager_module_t psi = { 0 }; | 
 | 1032 | 	voyager_asic_t psi_asic = { 0 }; | 
 | 1033 |  | 
 | 1034 | 	psi.asic = &psi_asic; | 
 | 1035 | 	psi.asic->asic_id = VOYAGER_CAT_ID; | 
 | 1036 | 	psi.asic->subaddr = VOYAGER_SUBADDR_HI; | 
 | 1037 | 	psi.module_addr = VOYAGER_PSI; | 
 | 1038 | 	psi.scan_path_connected = 0; | 
 | 1039 |  | 
 | 1040 | 	outb(VOYAGER_CAT_END, CAT_CMD); | 
 | 1041 | 	/* Connect the PSI to the CAT Bus */ | 
 | 1042 | 	outb(VOYAGER_CAT_DESELECT, VOYAGER_CAT_CONFIG_PORT); | 
 | 1043 | 	outb(VOYAGER_PSI, VOYAGER_CAT_CONFIG_PORT); | 
 | 1044 | 	outb(VOYAGER_CAT_RUN, CAT_CMD); | 
 | 1045 | 	cat_disconnect(&psi, &psi_asic); | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 1046 | 	switch (cmd) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1047 | 	case VOYAGER_PSI_READ: | 
 | 1048 | 		cat_read(&psi, &psi_asic, reg, data); | 
 | 1049 | 		break; | 
 | 1050 | 	case VOYAGER_PSI_WRITE: | 
 | 1051 | 		cat_write(&psi, &psi_asic, reg, *data); | 
 | 1052 | 		break; | 
 | 1053 | 	case VOYAGER_PSI_SUBREAD: | 
 | 1054 | 		cat_subread(&psi, &psi_asic, reg, 1, data); | 
 | 1055 | 		break; | 
 | 1056 | 	case VOYAGER_PSI_SUBWRITE: | 
 | 1057 | 		cat_subwrite(&psi, &psi_asic, reg, 1, data); | 
 | 1058 | 		break; | 
 | 1059 | 	default: | 
 | 1060 | 		printk(KERN_ERR "Voyager PSI, unrecognised command %d\n", cmd); | 
 | 1061 | 		break; | 
 | 1062 | 	} | 
 | 1063 | 	outb(VOYAGER_CAT_END, CAT_CMD); | 
 | 1064 | } | 
 | 1065 |  | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 1066 | void voyager_cat_do_common_interrupt(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1067 | { | 
 | 1068 | 	/* This is caused either by a memory parity error or something | 
 | 1069 | 	 * in the PSI */ | 
 | 1070 | 	__u8 data; | 
 | 1071 | 	voyager_module_t psi = { 0 }; | 
 | 1072 | 	voyager_asic_t psi_asic = { 0 }; | 
 | 1073 | 	struct voyager_psi psi_reg; | 
 | 1074 | 	int i; | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 1075 |       re_read: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | 	psi.asic = &psi_asic; | 
 | 1077 | 	psi.asic->asic_id = VOYAGER_CAT_ID; | 
 | 1078 | 	psi.asic->subaddr = VOYAGER_SUBADDR_HI; | 
 | 1079 | 	psi.module_addr = VOYAGER_PSI; | 
 | 1080 | 	psi.scan_path_connected = 0; | 
 | 1081 |  | 
 | 1082 | 	outb(VOYAGER_CAT_END, CAT_CMD); | 
 | 1083 | 	/* Connect the PSI to the CAT Bus */ | 
 | 1084 | 	outb(VOYAGER_CAT_DESELECT, VOYAGER_CAT_CONFIG_PORT); | 
 | 1085 | 	outb(VOYAGER_PSI, VOYAGER_CAT_CONFIG_PORT); | 
 | 1086 | 	outb(VOYAGER_CAT_RUN, CAT_CMD); | 
 | 1087 | 	cat_disconnect(&psi, &psi_asic); | 
 | 1088 | 	/* Read the status.  NOTE: Need to read *all* the PSI regs here | 
 | 1089 | 	 * otherwise the cmn int will be reasserted */ | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 1090 | 	for (i = 0; i < sizeof(psi_reg.regs); i++) { | 
 | 1091 | 		cat_read(&psi, &psi_asic, i, &((__u8 *) & psi_reg.regs)[i]); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1092 | 	} | 
 | 1093 | 	outb(VOYAGER_CAT_END, CAT_CMD); | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 1094 | 	if ((psi_reg.regs.checkbit & 0x02) == 0) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1095 | 		psi_reg.regs.checkbit |= 0x02; | 
 | 1096 | 		cat_write(&psi, &psi_asic, 5, psi_reg.regs.checkbit); | 
 | 1097 | 		printk("VOYAGER RE-READ PSI\n"); | 
 | 1098 | 		goto re_read; | 
 | 1099 | 	} | 
 | 1100 | 	outb(VOYAGER_CAT_RUN, CAT_CMD); | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 1101 | 	for (i = 0; i < sizeof(psi_reg.subregs); i++) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1102 | 		/* This looks strange, but the PSI doesn't do auto increment | 
 | 1103 | 		 * correctly */ | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 1104 | 		cat_subread(&psi, &psi_asic, VOYAGER_PSI_SUPPLY_REG + i, | 
 | 1105 | 			    1, &((__u8 *) & psi_reg.subregs)[i]); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1106 | 	} | 
 | 1107 | 	outb(VOYAGER_CAT_END, CAT_CMD); | 
 | 1108 | #ifdef VOYAGER_CAT_DEBUG | 
 | 1109 | 	printk("VOYAGER PSI: "); | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 1110 | 	for (i = 0; i < sizeof(psi_reg.regs); i++) | 
 | 1111 | 		printk("%02x ", ((__u8 *) & psi_reg.regs)[i]); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1112 | 	printk("\n           "); | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 1113 | 	for (i = 0; i < sizeof(psi_reg.subregs); i++) | 
 | 1114 | 		printk("%02x ", ((__u8 *) & psi_reg.subregs)[i]); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1115 | 	printk("\n"); | 
 | 1116 | #endif | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 1117 | 	if (psi_reg.regs.intstatus & PSI_MON) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1118 | 		/* switch off or power fail */ | 
 | 1119 |  | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 1120 | 		if (psi_reg.subregs.supply & PSI_SWITCH_OFF) { | 
 | 1121 | 			if (voyager_status.switch_off) { | 
 | 1122 | 				printk(KERN_ERR | 
 | 1123 | 				       "Voyager front panel switch turned off again---Immediate power off!\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1124 | 				voyager_cat_power_off(); | 
 | 1125 | 				/* not reached */ | 
 | 1126 | 			} else { | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 1127 | 				printk(KERN_ERR | 
 | 1128 | 				       "Voyager front panel switch turned off\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1129 | 				voyager_status.switch_off = 1; | 
 | 1130 | 				voyager_status.request_from_kernel = 1; | 
| Christoph Hellwig | f3402a4 | 2007-04-22 20:30:43 +0100 | [diff] [blame] | 1131 | 				wake_up_process(voyager_thread); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1132 | 			} | 
 | 1133 | 			/* Tell the hardware we're taking care of the | 
 | 1134 | 			 * shutdown, otherwise it will power the box off | 
 | 1135 | 			 * within 3 seconds of the switch being pressed and, | 
 | 1136 | 			 * which is much more important to us, continue to  | 
 | 1137 | 			 * assert the common interrupt */ | 
 | 1138 | 			data = PSI_CLR_SWITCH_OFF; | 
 | 1139 | 			outb(VOYAGER_CAT_RUN, CAT_CMD); | 
 | 1140 | 			cat_subwrite(&psi, &psi_asic, VOYAGER_PSI_SUPPLY_REG, | 
 | 1141 | 				     1, &data); | 
 | 1142 | 			outb(VOYAGER_CAT_END, CAT_CMD); | 
 | 1143 | 		} else { | 
 | 1144 |  | 
 | 1145 | 			VDEBUG(("Voyager ac fail reg 0x%x\n", | 
 | 1146 | 				psi_reg.subregs.ACfail)); | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 1147 | 			if ((psi_reg.subregs.ACfail & AC_FAIL_STAT_CHANGE) == 0) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1148 | 				/* No further update */ | 
 | 1149 | 				return; | 
 | 1150 | 			} | 
 | 1151 | #if 0 | 
 | 1152 | 			/* Don't bother trying to find out who failed. | 
 | 1153 | 			 * FIXME: This probably makes the code incorrect on | 
 | 1154 | 			 * anything other than a 345x */ | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 1155 | 			for (i = 0; i < 5; i++) { | 
 | 1156 | 				if (psi_reg.subregs.ACfail & (1 << i)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1157 | 					break; | 
 | 1158 | 				} | 
 | 1159 | 			} | 
 | 1160 | 			printk(KERN_NOTICE "AC FAIL IN SUPPLY %d\n", i); | 
 | 1161 | #endif | 
 | 1162 | 			/* DON'T do this: it shuts down the AC PSI  | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 1163 | 			   outb(VOYAGER_CAT_RUN, CAT_CMD); | 
 | 1164 | 			   data = PSI_MASK_MASK | i; | 
 | 1165 | 			   cat_subwrite(&psi, &psi_asic, VOYAGER_PSI_MASK, | 
 | 1166 | 			   1, &data); | 
 | 1167 | 			   outb(VOYAGER_CAT_END, CAT_CMD); | 
 | 1168 | 			 */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1169 | 			printk(KERN_ERR "Voyager AC power failure\n"); | 
 | 1170 | 			outb(VOYAGER_CAT_RUN, CAT_CMD); | 
 | 1171 | 			data = PSI_COLD_START; | 
 | 1172 | 			cat_subwrite(&psi, &psi_asic, VOYAGER_PSI_GENERAL_REG, | 
 | 1173 | 				     1, &data); | 
 | 1174 | 			outb(VOYAGER_CAT_END, CAT_CMD); | 
 | 1175 | 			voyager_status.power_fail = 1; | 
 | 1176 | 			voyager_status.request_from_kernel = 1; | 
| Christoph Hellwig | f3402a4 | 2007-04-22 20:30:43 +0100 | [diff] [blame] | 1177 | 			wake_up_process(voyager_thread); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1178 | 		} | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 1179 |  | 
 | 1180 | 	} else if (psi_reg.regs.intstatus & PSI_FAULT) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1181 | 		/* Major fault! */ | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 1182 | 		printk(KERN_ERR | 
 | 1183 | 		       "Voyager PSI Detected major fault, immediate power off!\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1184 | 		voyager_cat_power_off(); | 
 | 1185 | 		/* not reached */ | 
| Ingo Molnar | a4ec1ef | 2008-01-30 13:30:10 +0100 | [diff] [blame] | 1186 | 	} else if (psi_reg.regs.intstatus & (PSI_DC_FAIL | PSI_ALARM | 
 | 1187 | 					     | PSI_CURRENT | PSI_DVM | 
 | 1188 | 					     | PSI_PSCFAULT | PSI_STAT_CHG)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1189 | 		/* other psi fault */ | 
 | 1190 |  | 
 | 1191 | 		printk(KERN_WARNING "Voyager PSI status 0x%x\n", data); | 
 | 1192 | 		/* clear the PSI fault */ | 
 | 1193 | 		outb(VOYAGER_CAT_RUN, CAT_CMD); | 
 | 1194 | 		cat_write(&psi, &psi_asic, VOYAGER_PSI_STATUS_REG, 0); | 
 | 1195 | 		outb(VOYAGER_CAT_END, CAT_CMD); | 
 | 1196 | 	} | 
 | 1197 | } |