blob: 17a7904f75b19ce55b63a562158bc82c172cf677 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* -*- mode: c; c-basic-offset: 8 -*- */
2
3/* Copyright (C) 1999,2001
4 *
5 * Author: J.E.J.Bottomley@HansenPartnership.com
6 *
7 * linux/arch/i386/kernel/voyager_cat.c
8 *
9 * This file contains all the logic for manipulating the CAT bus
10 * in a level 5 machine.
11 *
12 * The CAT bus is a serial configuration and test bus. Its primary
13 * uses are to probe the initial configuration of the system and to
14 * diagnose error conditions when a system interrupt occurs. The low
15 * level interface is fairly primitive, so most of this file consists
16 * of bit shift manipulations to send and receive packets on the
17 * serial bus */
18
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <linux/types.h>
20#include <linux/completion.h>
21#include <linux/sched.h>
22#include <asm/voyager.h>
23#include <asm/vic.h>
24#include <linux/ioport.h>
25#include <linux/init.h>
26#include <linux/slab.h>
27#include <linux/delay.h>
28#include <asm/io.h>
29
30#ifdef VOYAGER_CAT_DEBUG
31#define CDEBUG(x) printk x
32#else
33#define CDEBUG(x)
34#endif
35
36/* the CAT command port */
37#define CAT_CMD (sspb + 0xe)
38/* the CAT data port */
39#define CAT_DATA (sspb + 0xd)
40
41/* the internal cat functions */
Ingo Molnara4ec1ef2008-01-30 13:30:10 +010042static void cat_pack(__u8 * msg, __u16 start_bit, __u8 * data, __u16 num_bits);
43static void cat_unpack(__u8 * msg, __u16 start_bit, __u8 * data,
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 __u16 num_bits);
Ingo Molnara4ec1ef2008-01-30 13:30:10 +010045static void cat_build_header(__u8 * header, const __u16 len,
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 const __u16 smallest_reg_bits,
47 const __u16 longest_reg_bits);
Ingo Molnara4ec1ef2008-01-30 13:30:10 +010048static int cat_sendinst(voyager_module_t * modp, voyager_asic_t * asicp,
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 __u8 reg, __u8 op);
Ingo Molnara4ec1ef2008-01-30 13:30:10 +010050static int cat_getdata(voyager_module_t * modp, voyager_asic_t * asicp,
51 __u8 reg, __u8 * value);
52static int cat_shiftout(__u8 * data, __u16 data_bytes, __u16 header_bytes,
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 __u8 pad_bits);
Ingo Molnara4ec1ef2008-01-30 13:30:10 +010054static int cat_write(voyager_module_t * modp, voyager_asic_t * asicp, __u8 reg,
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 __u8 value);
Ingo Molnara4ec1ef2008-01-30 13:30:10 +010056static int cat_read(voyager_module_t * modp, voyager_asic_t * asicp, __u8 reg,
57 __u8 * value);
58static int cat_subread(voyager_module_t * modp, voyager_asic_t * asicp,
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 __u16 offset, __u16 len, void *buf);
Ingo Molnara4ec1ef2008-01-30 13:30:10 +010060static int cat_senddata(voyager_module_t * modp, voyager_asic_t * asicp,
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 __u8 reg, __u8 value);
Ingo Molnara4ec1ef2008-01-30 13:30:10 +010062static int cat_disconnect(voyager_module_t * modp, voyager_asic_t * asicp);
63static int cat_connect(voyager_module_t * modp, voyager_asic_t * asicp);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
Ingo Molnara4ec1ef2008-01-30 13:30:10 +010065static inline const char *cat_module_name(int module_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070066{
Ingo Molnara4ec1ef2008-01-30 13:30:10 +010067 switch (module_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 case 0x10:
69 return "Processor Slot 0";
70 case 0x11:
71 return "Processor Slot 1";
72 case 0x12:
73 return "Processor Slot 2";
74 case 0x13:
75 return "Processor Slot 4";
76 case 0x14:
77 return "Memory Slot 0";
78 case 0x15:
79 return "Memory Slot 1";
80 case 0x18:
81 return "Primary Microchannel";
82 case 0x19:
83 return "Secondary Microchannel";
84 case 0x1a:
85 return "Power Supply Interface";
86 case 0x1c:
87 return "Processor Slot 5";
88 case 0x1d:
89 return "Processor Slot 6";
90 case 0x1e:
91 return "Processor Slot 7";
92 case 0x1f:
93 return "Processor Slot 8";
94 default:
95 return "Unknown Module";
96 }
97}
98
99static int sspb = 0; /* stores the super port location */
100int voyager_8slot = 0; /* set to true if a 51xx monster */
101
102voyager_module_t *voyager_cat_list;
103
104/* the I/O port assignments for the VIC and QIC */
105static struct resource vic_res = {
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100106 .name = "Voyager Interrupt Controller",
107 .start = 0xFC00,
108 .end = 0xFC6F
Adrian Bunkdd7ba3b2006-04-10 22:52:49 -0700109};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110static struct resource qic_res = {
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100111 .name = "Quad Interrupt Controller",
112 .start = 0xFC70,
113 .end = 0xFCFF
Adrian Bunkdd7ba3b2006-04-10 22:52:49 -0700114};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
116/* This function is used to pack a data bit stream inside a message.
117 * It writes num_bits of the data buffer in msg starting at start_bit.
118 * Note: This function assumes that any unused bit in the data stream
119 * is set to zero so that the ors will work correctly */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120static void
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100121cat_pack(__u8 * msg, const __u16 start_bit, __u8 * data, const __u16 num_bits)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122{
123 /* compute initial shift needed */
124 const __u16 offset = start_bit % BITS_PER_BYTE;
125 __u16 len = num_bits / BITS_PER_BYTE;
126 __u16 byte = start_bit / BITS_PER_BYTE;
127 __u16 residue = (num_bits % BITS_PER_BYTE) + offset;
128 int i;
129
130 /* adjust if we have more than a byte of residue */
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100131 if (residue >= BITS_PER_BYTE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 residue -= BITS_PER_BYTE;
133 len++;
134 }
135
136 /* clear out the bits. We assume here that if len==0 then
137 * residue >= offset. This is always true for the catbus
138 * operations */
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100139 msg[byte] &= 0xff << (BITS_PER_BYTE - offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 msg[byte++] |= data[0] >> offset;
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100141 if (len == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 return;
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100143 for (i = 1; i < len; i++)
144 msg[byte++] = (data[i - 1] << (BITS_PER_BYTE - offset))
145 | (data[i] >> offset);
146 if (residue != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 __u8 mask = 0xff >> residue;
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100148 __u8 last_byte = data[i - 1] << (BITS_PER_BYTE - offset)
149 | (data[i] >> offset);
150
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 last_byte &= ~mask;
152 msg[byte] &= mask;
153 msg[byte] |= last_byte;
154 }
155 return;
156}
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100157
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158/* unpack the data again (same arguments as cat_pack()). data buffer
159 * must be zero populated.
160 *
161 * Function: given a message string move to start_bit and copy num_bits into
162 * data (starting at bit 0 in data).
163 */
164static void
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100165cat_unpack(__u8 * msg, const __u16 start_bit, __u8 * data, const __u16 num_bits)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166{
167 /* compute initial shift needed */
168 const __u16 offset = start_bit % BITS_PER_BYTE;
169 __u16 len = num_bits / BITS_PER_BYTE;
170 const __u8 last_bits = num_bits % BITS_PER_BYTE;
171 __u16 byte = start_bit / BITS_PER_BYTE;
172 int i;
173
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100174 if (last_bits != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 len++;
176
177 /* special case: want < 8 bits from msg and we can get it from
178 * a single byte of the msg */
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100179 if (len == 0 && BITS_PER_BYTE - offset >= num_bits) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 data[0] = msg[byte] << offset;
181 data[0] &= 0xff >> (BITS_PER_BYTE - num_bits);
182 return;
183 }
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100184 for (i = 0; i < len; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 /* this annoying if has to be done just in case a read of
186 * msg one beyond the array causes a panic */
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100187 if (offset != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 data[i] = msg[byte++] << offset;
189 data[i] |= msg[byte] >> (BITS_PER_BYTE - offset);
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100190 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 data[i] = msg[byte++];
192 }
193 }
194 /* do we need to truncate the final byte */
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100195 if (last_bits != 0) {
196 data[i - 1] &= 0xff << (BITS_PER_BYTE - last_bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 }
198 return;
199}
200
201static void
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100202cat_build_header(__u8 * header, const __u16 len, const __u16 smallest_reg_bits,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 const __u16 longest_reg_bits)
204{
205 int i;
206 __u16 start_bit = (smallest_reg_bits - 1) % BITS_PER_BYTE;
207 __u8 *last_byte = &header[len - 1];
208
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100209 if (start_bit == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 start_bit = 1; /* must have at least one bit in the hdr */
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100211
212 for (i = 0; i < len; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 header[i] = 0;
214
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100215 for (i = start_bit; i > 0; i--)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 *last_byte = ((*last_byte) << 1) + 1;
217
218}
219
220static int
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100221cat_sendinst(voyager_module_t * modp, voyager_asic_t * asicp, __u8 reg, __u8 op)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222{
223 __u8 parity, inst, inst_buf[4] = { 0 };
224 __u8 iseq[VOYAGER_MAX_SCAN_PATH], hseq[VOYAGER_MAX_REG_SIZE];
225 __u16 ibytes, hbytes, padbits;
226 int i;
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100227
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 /*
229 * Parity is the parity of the register number + 1 (READ_REGISTER
230 * and WRITE_REGISTER always add '1' to the number of bits == 1)
231 */
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100232 parity = (__u8) (1 + (reg & 0x01) +
233 ((__u8) (reg & 0x02) >> 1) +
234 ((__u8) (reg & 0x04) >> 2) +
235 ((__u8) (reg & 0x08) >> 3)) % 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236
237 inst = ((parity << 7) | (reg << 2) | op);
238
239 outb(VOYAGER_CAT_IRCYC, CAT_CMD);
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100240 if (!modp->scan_path_connected) {
241 if (asicp->asic_id != VOYAGER_CAT_ID) {
242 printk
243 ("**WARNING***: cat_sendinst has disconnected scan path not to CAT asic\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 return 1;
245 }
246 outb(VOYAGER_CAT_HEADER, CAT_DATA);
247 outb(inst, CAT_DATA);
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100248 if (inb(CAT_DATA) != VOYAGER_CAT_HEADER) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 CDEBUG(("VOYAGER CAT: cat_sendinst failed to get CAT_HEADER\n"));
250 return 1;
251 }
252 return 0;
253 }
254 ibytes = modp->inst_bits / BITS_PER_BYTE;
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100255 if ((padbits = modp->inst_bits % BITS_PER_BYTE) != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 padbits = BITS_PER_BYTE - padbits;
257 ibytes++;
258 }
259 hbytes = modp->largest_reg / BITS_PER_BYTE;
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100260 if (modp->largest_reg % BITS_PER_BYTE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 hbytes++;
262 CDEBUG(("cat_sendinst: ibytes=%d, hbytes=%d\n", ibytes, hbytes));
263 /* initialise the instruction sequence to 0xff */
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100264 for (i = 0; i < ibytes + hbytes; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 iseq[i] = 0xff;
266 cat_build_header(hseq, hbytes, modp->smallest_reg, modp->largest_reg);
267 cat_pack(iseq, modp->inst_bits, hseq, hbytes * BITS_PER_BYTE);
268 inst_buf[0] = inst;
269 inst_buf[1] = 0xFF >> (modp->largest_reg % BITS_PER_BYTE);
270 cat_pack(iseq, asicp->bit_location, inst_buf, asicp->ireg_length);
271#ifdef VOYAGER_CAT_DEBUG
272 printk("ins = 0x%x, iseq: ", inst);
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100273 for (i = 0; i < ibytes + hbytes; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 printk("0x%x ", iseq[i]);
275 printk("\n");
276#endif
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100277 if (cat_shiftout(iseq, ibytes, hbytes, padbits)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 CDEBUG(("VOYAGER CAT: cat_sendinst: cat_shiftout failed\n"));
279 return 1;
280 }
281 CDEBUG(("CAT SHIFTOUT DONE\n"));
282 return 0;
283}
284
285static int
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100286cat_getdata(voyager_module_t * modp, voyager_asic_t * asicp, __u8 reg,
287 __u8 * value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288{
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100289 if (!modp->scan_path_connected) {
290 if (asicp->asic_id != VOYAGER_CAT_ID) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 CDEBUG(("VOYAGER CAT: ERROR: cat_getdata to CAT asic with scan path connected\n"));
292 return 1;
293 }
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100294 if (reg > VOYAGER_SUBADDRHI)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 outb(VOYAGER_CAT_RUN, CAT_CMD);
296 outb(VOYAGER_CAT_DRCYC, CAT_CMD);
297 outb(VOYAGER_CAT_HEADER, CAT_DATA);
298 *value = inb(CAT_DATA);
299 outb(0xAA, CAT_DATA);
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100300 if (inb(CAT_DATA) != VOYAGER_CAT_HEADER) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 CDEBUG(("cat_getdata: failed to get VOYAGER_CAT_HEADER\n"));
302 return 1;
303 }
304 return 0;
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100305 } else {
306 __u16 sbits = modp->num_asics - 1 + asicp->ireg_length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 __u16 sbytes = sbits / BITS_PER_BYTE;
308 __u16 tbytes;
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100309 __u8 string[VOYAGER_MAX_SCAN_PATH],
310 trailer[VOYAGER_MAX_REG_SIZE];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 __u8 padbits;
312 int i;
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100313
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 outb(VOYAGER_CAT_DRCYC, CAT_CMD);
315
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100316 if ((padbits = sbits % BITS_PER_BYTE) != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 padbits = BITS_PER_BYTE - padbits;
318 sbytes++;
319 }
320 tbytes = asicp->ireg_length / BITS_PER_BYTE;
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100321 if (asicp->ireg_length % BITS_PER_BYTE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 tbytes++;
323 CDEBUG(("cat_getdata: tbytes = %d, sbytes = %d, padbits = %d\n",
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100324 tbytes, sbytes, padbits));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 cat_build_header(trailer, tbytes, 1, asicp->ireg_length);
326
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100327 for (i = tbytes - 1; i >= 0; i--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 outb(trailer[i], CAT_DATA);
329 string[sbytes + i] = inb(CAT_DATA);
330 }
331
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100332 for (i = sbytes - 1; i >= 0; i--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 outb(0xaa, CAT_DATA);
334 string[i] = inb(CAT_DATA);
335 }
336 *value = 0;
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100337 cat_unpack(string,
338 padbits + (tbytes * BITS_PER_BYTE) +
339 asicp->asic_location, value, asicp->ireg_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340#ifdef VOYAGER_CAT_DEBUG
341 printk("value=0x%x, string: ", *value);
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100342 for (i = 0; i < tbytes + sbytes; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 printk("0x%x ", string[i]);
344 printk("\n");
345#endif
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100346
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 /* sanity check the rest of the return */
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100348 for (i = 0; i < tbytes; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 __u8 input = 0;
350
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100351 cat_unpack(string, padbits + (i * BITS_PER_BYTE),
352 &input, BITS_PER_BYTE);
353 if (trailer[i] != input) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 CDEBUG(("cat_getdata: failed to sanity check rest of ret(%d) 0x%x != 0x%x\n", i, input, trailer[i]));
355 return 1;
356 }
357 }
358 CDEBUG(("cat_getdata DONE\n"));
359 return 0;
360 }
361}
362
363static int
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100364cat_shiftout(__u8 * data, __u16 data_bytes, __u16 header_bytes, __u8 pad_bits)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365{
366 int i;
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100367
368 for (i = data_bytes + header_bytes - 1; i >= header_bytes; i--)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 outb(data[i], CAT_DATA);
370
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100371 for (i = header_bytes - 1; i >= 0; i--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 __u8 header = 0;
373 __u8 input;
374
375 outb(data[i], CAT_DATA);
376 input = inb(CAT_DATA);
377 CDEBUG(("cat_shiftout: returned 0x%x\n", input));
378 cat_unpack(data, ((data_bytes + i) * BITS_PER_BYTE) - pad_bits,
379 &header, BITS_PER_BYTE);
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100380 if (input != header) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 CDEBUG(("VOYAGER CAT: cat_shiftout failed to return header 0x%x != 0x%x\n", input, header));
382 return 1;
383 }
384 }
385 return 0;
386}
387
388static int
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100389cat_senddata(voyager_module_t * modp, voyager_asic_t * asicp,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 __u8 reg, __u8 value)
391{
392 outb(VOYAGER_CAT_DRCYC, CAT_CMD);
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100393 if (!modp->scan_path_connected) {
394 if (asicp->asic_id != VOYAGER_CAT_ID) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 CDEBUG(("VOYAGER CAT: ERROR: scan path disconnected when asic != CAT\n"));
396 return 1;
397 }
398 outb(VOYAGER_CAT_HEADER, CAT_DATA);
399 outb(value, CAT_DATA);
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100400 if (inb(CAT_DATA) != VOYAGER_CAT_HEADER) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 CDEBUG(("cat_senddata: failed to get correct header response to sent data\n"));
402 return 1;
403 }
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100404 if (reg > VOYAGER_SUBADDRHI) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 outb(VOYAGER_CAT_RUN, CAT_CMD);
406 outb(VOYAGER_CAT_END, CAT_CMD);
407 outb(VOYAGER_CAT_RUN, CAT_CMD);
408 }
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100409
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 return 0;
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100411 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 __u16 hbytes = asicp->ireg_length / BITS_PER_BYTE;
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100413 __u16 dbytes =
414 (modp->num_asics - 1 + asicp->ireg_length) / BITS_PER_BYTE;
415 __u8 padbits, dseq[VOYAGER_MAX_SCAN_PATH],
416 hseq[VOYAGER_MAX_REG_SIZE];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 int i;
418
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100419 if ((padbits = (modp->num_asics - 1
420 + asicp->ireg_length) % BITS_PER_BYTE) != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 padbits = BITS_PER_BYTE - padbits;
422 dbytes++;
423 }
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100424 if (asicp->ireg_length % BITS_PER_BYTE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 hbytes++;
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100426
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 cat_build_header(hseq, hbytes, 1, asicp->ireg_length);
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100428
429 for (i = 0; i < dbytes + hbytes; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 dseq[i] = 0xff;
431 CDEBUG(("cat_senddata: dbytes=%d, hbytes=%d, padbits=%d\n",
432 dbytes, hbytes, padbits));
433 cat_pack(dseq, modp->num_asics - 1 + asicp->ireg_length,
434 hseq, hbytes * BITS_PER_BYTE);
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100435 cat_pack(dseq, asicp->asic_location, &value,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 asicp->ireg_length);
437#ifdef VOYAGER_CAT_DEBUG
438 printk("dseq ");
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100439 for (i = 0; i < hbytes + dbytes; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 printk("0x%x ", dseq[i]);
441 }
442 printk("\n");
443#endif
444 return cat_shiftout(dseq, dbytes, hbytes, padbits);
445 }
446}
447
448static int
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100449cat_write(voyager_module_t * modp, voyager_asic_t * asicp, __u8 reg, __u8 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450{
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100451 if (cat_sendinst(modp, asicp, reg, VOYAGER_WRITE_CONFIG))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 return 1;
453 return cat_senddata(modp, asicp, reg, value);
454}
455
456static int
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100457cat_read(voyager_module_t * modp, voyager_asic_t * asicp, __u8 reg,
458 __u8 * value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459{
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100460 if (cat_sendinst(modp, asicp, reg, VOYAGER_READ_CONFIG))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 return 1;
462 return cat_getdata(modp, asicp, reg, value);
463}
464
465static int
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100466cat_subaddrsetup(voyager_module_t * modp, voyager_asic_t * asicp, __u16 offset,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 __u16 len)
468{
469 __u8 val;
470
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100471 if (len > 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 /* set auto increment */
473 __u8 newval;
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100474
475 if (cat_read(modp, asicp, VOYAGER_AUTO_INC_REG, &val)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 CDEBUG(("cat_subaddrsetup: read of VOYAGER_AUTO_INC_REG failed\n"));
477 return 1;
478 }
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100479 CDEBUG(("cat_subaddrsetup: VOYAGER_AUTO_INC_REG = 0x%x\n",
480 val));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 newval = val | VOYAGER_AUTO_INC;
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100482 if (newval != val) {
483 if (cat_write(modp, asicp, VOYAGER_AUTO_INC_REG, val)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 CDEBUG(("cat_subaddrsetup: write to VOYAGER_AUTO_INC_REG failed\n"));
485 return 1;
486 }
487 }
488 }
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100489 if (cat_write(modp, asicp, VOYAGER_SUBADDRLO, (__u8) (offset & 0xff))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 CDEBUG(("cat_subaddrsetup: write to SUBADDRLO failed\n"));
491 return 1;
492 }
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100493 if (asicp->subaddr > VOYAGER_SUBADDR_LO) {
494 if (cat_write
495 (modp, asicp, VOYAGER_SUBADDRHI, (__u8) (offset >> 8))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 CDEBUG(("cat_subaddrsetup: write to SUBADDRHI failed\n"));
497 return 1;
498 }
499 cat_read(modp, asicp, VOYAGER_SUBADDRHI, &val);
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100500 CDEBUG(("cat_subaddrsetup: offset = %d, hi = %d\n", offset,
501 val));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 }
503 cat_read(modp, asicp, VOYAGER_SUBADDRLO, &val);
504 CDEBUG(("cat_subaddrsetup: offset = %d, lo = %d\n", offset, val));
505 return 0;
506}
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100507
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508static int
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100509cat_subwrite(voyager_module_t * modp, voyager_asic_t * asicp, __u16 offset,
510 __u16 len, void *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511{
512 int i, retval;
513
514 /* FIXME: need special actions for VOYAGER_CAT_ID here */
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100515 if (asicp->asic_id == VOYAGER_CAT_ID) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 CDEBUG(("cat_subwrite: ATTEMPT TO WRITE TO CAT ASIC\n"));
517 /* FIXME -- This is supposed to be handled better
518 * There is a problem writing to the cat asic in the
519 * PSI. The 30us delay seems to work, though */
520 udelay(30);
521 }
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100522
523 if ((retval = cat_subaddrsetup(modp, asicp, offset, len)) != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 printk("cat_subwrite: cat_subaddrsetup FAILED\n");
525 return retval;
526 }
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100527
528 if (cat_sendinst
529 (modp, asicp, VOYAGER_SUBADDRDATA, VOYAGER_WRITE_CONFIG)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 printk("cat_subwrite: cat_sendinst FAILED\n");
531 return 1;
532 }
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100533 for (i = 0; i < len; i++) {
534 if (cat_senddata(modp, asicp, 0xFF, ((__u8 *) buf)[i])) {
535 printk
536 ("cat_subwrite: cat_sendata element at %d FAILED\n",
537 i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 return 1;
539 }
540 }
541 return 0;
542}
543static int
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100544cat_subread(voyager_module_t * modp, voyager_asic_t * asicp, __u16 offset,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 __u16 len, void *buf)
546{
547 int i, retval;
548
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100549 if ((retval = cat_subaddrsetup(modp, asicp, offset, len)) != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 CDEBUG(("cat_subread: cat_subaddrsetup FAILED\n"));
551 return retval;
552 }
553
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100554 if (cat_sendinst(modp, asicp, VOYAGER_SUBADDRDATA, VOYAGER_READ_CONFIG)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 CDEBUG(("cat_subread: cat_sendinst failed\n"));
556 return 1;
557 }
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100558 for (i = 0; i < len; i++) {
559 if (cat_getdata(modp, asicp, 0xFF, &((__u8 *) buf)[i])) {
560 CDEBUG(("cat_subread: cat_getdata element %d failed\n",
561 i));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 return 1;
563 }
564 }
565 return 0;
566}
567
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568/* buffer for storing EPROM data read in during initialisation */
569static __initdata __u8 eprom_buf[0xFFFF];
570static voyager_module_t *voyager_initial_module;
571
572/* Initialise the cat bus components. We assume this is called by the
573 * boot cpu *after* all memory initialisation has been done (so we can
574 * use kmalloc) but before smp initialisation, so we can probe the SMP
575 * configuration and pick up necessary information. */
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100576void __init voyager_cat_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577{
578 voyager_module_t **modpp = &voyager_initial_module;
579 voyager_asic_t **asicpp;
580 voyager_asic_t *qabc_asic = NULL;
581 int i, j;
582 unsigned long qic_addr = 0;
583 __u8 qabc_data[0x20];
584 __u8 num_submodules, val;
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100585 voyager_eprom_hdr_t *eprom_hdr = (voyager_eprom_hdr_t *) & eprom_buf[0];
586
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 __u8 cmos[4];
588 unsigned long addr;
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100589
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 /* initiallise the SUS mailbox */
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100591 for (i = 0; i < sizeof(cmos); i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 cmos[i] = voyager_extended_cmos_read(VOYAGER_DUMP_LOCATION + i);
593 addr = *(unsigned long *)cmos;
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100594 if ((addr & 0xff000000) != 0xff000000) {
595 printk(KERN_ERR
596 "Voyager failed to get SUS mailbox (addr = 0x%lx\n",
597 addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 } else {
599 static struct resource res;
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100600
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 res.name = "voyager SUS";
602 res.start = addr;
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100603 res.end = addr + 0x3ff;
604
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 request_resource(&iomem_resource, &res);
606 voyager_SUS = (struct voyager_SUS *)
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100607 ioremap(addr, 0x400);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 printk(KERN_NOTICE "Voyager SUS mailbox version 0x%x\n",
609 voyager_SUS->SUS_version);
610 voyager_SUS->kernel_version = VOYAGER_MAILBOX_VERSION;
611 voyager_SUS->kernel_flags = VOYAGER_OS_HAS_SYSINT;
612 }
613
614 /* clear the processor counts */
615 voyager_extended_vic_processors = 0;
616 voyager_quad_processors = 0;
617
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 printk("VOYAGER: beginning CAT bus probe\n");
619 /* set up the SuperSet Port Block which tells us where the
620 * CAT communication port is */
621 sspb = inb(VOYAGER_SSPB_RELOCATION_PORT) * 0x100;
622 VDEBUG(("VOYAGER DEBUG: sspb = 0x%x\n", sspb));
623
624 /* now find out if were 8 slot or normal */
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100625 if ((inb(VIC_PROC_WHO_AM_I) & EIGHT_SLOT_IDENTIFIER)
626 == EIGHT_SLOT_IDENTIFIER) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 voyager_8slot = 1;
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100628 printk(KERN_NOTICE
629 "Voyager: Eight slot 51xx configuration detected\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 }
631
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100632 for (i = VOYAGER_MIN_MODULE; i <= VOYAGER_MAX_MODULE; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 __u8 input;
634 int asic;
635 __u16 eprom_size;
636 __u16 sp_offset;
637
638 outb(VOYAGER_CAT_DESELECT, VOYAGER_CAT_CONFIG_PORT);
639 outb(i, VOYAGER_CAT_CONFIG_PORT);
640
641 /* check the presence of the module */
642 outb(VOYAGER_CAT_RUN, CAT_CMD);
643 outb(VOYAGER_CAT_IRCYC, CAT_CMD);
644 outb(VOYAGER_CAT_HEADER, CAT_DATA);
645 /* stream series of alternating 1's and 0's to stimulate
646 * response */
647 outb(0xAA, CAT_DATA);
648 input = inb(CAT_DATA);
649 outb(VOYAGER_CAT_END, CAT_CMD);
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100650 if (input != VOYAGER_CAT_HEADER) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 continue;
652 }
653 CDEBUG(("VOYAGER DEBUG: found module id 0x%x, %s\n", i,
654 cat_module_name(i)));
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100655 *modpp = kmalloc(sizeof(voyager_module_t), GFP_KERNEL); /*&voyager_module_storage[cat_count++]; */
656 if (*modpp == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 printk("**WARNING** kmalloc failure in cat_init\n");
658 continue;
659 }
660 memset(*modpp, 0, sizeof(voyager_module_t));
661 /* need temporary asic for cat_subread. It will be
662 * filled in correctly later */
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100663 (*modpp)->asic = kmalloc(sizeof(voyager_asic_t), GFP_KERNEL); /*&voyager_asic_storage[asic_count]; */
664 if ((*modpp)->asic == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 printk("**WARNING** kmalloc failure in cat_init\n");
666 continue;
667 }
668 memset((*modpp)->asic, 0, sizeof(voyager_asic_t));
669 (*modpp)->asic->asic_id = VOYAGER_CAT_ID;
670 (*modpp)->asic->subaddr = VOYAGER_SUBADDR_HI;
671 (*modpp)->module_addr = i;
672 (*modpp)->scan_path_connected = 0;
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100673 if (i == VOYAGER_PSI) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 /* Exception leg for modules with no EEPROM */
675 printk("Module \"%s\"\n", cat_module_name(i));
676 continue;
677 }
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100678
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 CDEBUG(("cat_init: Reading eeprom for module 0x%x at offset %d\n", i, VOYAGER_XSUM_END_OFFSET));
680 outb(VOYAGER_CAT_RUN, CAT_CMD);
681 cat_disconnect(*modpp, (*modpp)->asic);
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100682 if (cat_subread(*modpp, (*modpp)->asic,
683 VOYAGER_XSUM_END_OFFSET, sizeof(eprom_size),
684 &eprom_size)) {
685 printk
686 ("**WARNING**: Voyager couldn't read EPROM size for module 0x%x\n",
687 i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 outb(VOYAGER_CAT_END, CAT_CMD);
689 continue;
690 }
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100691 if (eprom_size > sizeof(eprom_buf)) {
692 printk
693 ("**WARNING**: Voyager insufficient size to read EPROM data, module 0x%x. Need %d\n",
694 i, eprom_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 outb(VOYAGER_CAT_END, CAT_CMD);
696 continue;
697 }
698 outb(VOYAGER_CAT_END, CAT_CMD);
699 outb(VOYAGER_CAT_RUN, CAT_CMD);
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100700 CDEBUG(("cat_init: module 0x%x, eeprom_size %d\n", i,
701 eprom_size));
702 if (cat_subread
703 (*modpp, (*modpp)->asic, 0, eprom_size, eprom_buf)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 outb(VOYAGER_CAT_END, CAT_CMD);
705 continue;
706 }
707 outb(VOYAGER_CAT_END, CAT_CMD);
708 printk("Module \"%s\", version 0x%x, tracer 0x%x, asics %d\n",
709 cat_module_name(i), eprom_hdr->version_id,
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100710 *((__u32 *) eprom_hdr->tracer), eprom_hdr->num_asics);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 (*modpp)->ee_size = eprom_hdr->ee_size;
712 (*modpp)->num_asics = eprom_hdr->num_asics;
713 asicpp = &((*modpp)->asic);
714 sp_offset = eprom_hdr->scan_path_offset;
715 /* All we really care about are the Quad cards. We
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100716 * identify them because they are in a processor slot
717 * and have only four asics */
718 if ((i < 0x10 || (i >= 0x14 && i < 0x1c) || i > 0x1f)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 modpp = &((*modpp)->next);
720 continue;
721 }
722 /* Now we know it's in a processor slot, does it have
723 * a quad baseboard submodule */
724 outb(VOYAGER_CAT_RUN, CAT_CMD);
725 cat_read(*modpp, (*modpp)->asic, VOYAGER_SUBMODPRESENT,
726 &num_submodules);
727 /* lowest two bits, active low */
728 num_submodules = ~(0xfc | num_submodules);
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100729 CDEBUG(("VOYAGER CAT: %d submodules present\n",
730 num_submodules));
731 if (num_submodules == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 /* fill in the dyadic extended processors */
733 __u8 cpu = i & 0x07;
734
735 printk("Module \"%s\": Dyadic Processor Card\n",
736 cat_module_name(i));
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100737 voyager_extended_vic_processors |= (1 << cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 cpu += 4;
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100739 voyager_extended_vic_processors |= (1 << cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 outb(VOYAGER_CAT_END, CAT_CMD);
741 continue;
742 }
743
744 /* now we want to read the asics on the first submodule,
745 * which should be the quad base board */
746
747 cat_read(*modpp, (*modpp)->asic, VOYAGER_SUBMODSELECT, &val);
748 CDEBUG(("cat_init: SUBMODSELECT value = 0x%x\n", val));
749 val = (val & 0x7c) | VOYAGER_QUAD_BASEBOARD;
750 cat_write(*modpp, (*modpp)->asic, VOYAGER_SUBMODSELECT, val);
751
752 outb(VOYAGER_CAT_END, CAT_CMD);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753
754 CDEBUG(("cat_init: Reading eeprom for module 0x%x at offset %d\n", i, VOYAGER_XSUM_END_OFFSET));
755 outb(VOYAGER_CAT_RUN, CAT_CMD);
756 cat_disconnect(*modpp, (*modpp)->asic);
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100757 if (cat_subread(*modpp, (*modpp)->asic,
758 VOYAGER_XSUM_END_OFFSET, sizeof(eprom_size),
759 &eprom_size)) {
760 printk
761 ("**WARNING**: Voyager couldn't read EPROM size for module 0x%x\n",
762 i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 outb(VOYAGER_CAT_END, CAT_CMD);
764 continue;
765 }
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100766 if (eprom_size > sizeof(eprom_buf)) {
767 printk
768 ("**WARNING**: Voyager insufficient size to read EPROM data, module 0x%x. Need %d\n",
769 i, eprom_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 outb(VOYAGER_CAT_END, CAT_CMD);
771 continue;
772 }
773 outb(VOYAGER_CAT_END, CAT_CMD);
774 outb(VOYAGER_CAT_RUN, CAT_CMD);
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100775 CDEBUG(("cat_init: module 0x%x, eeprom_size %d\n", i,
776 eprom_size));
777 if (cat_subread
778 (*modpp, (*modpp)->asic, 0, eprom_size, eprom_buf)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 outb(VOYAGER_CAT_END, CAT_CMD);
780 continue;
781 }
782 outb(VOYAGER_CAT_END, CAT_CMD);
783 /* Now do everything for the QBB submodule 1 */
784 (*modpp)->ee_size = eprom_hdr->ee_size;
785 (*modpp)->num_asics = eprom_hdr->num_asics;
786 asicpp = &((*modpp)->asic);
787 sp_offset = eprom_hdr->scan_path_offset;
788 /* get rid of the dummy CAT asic and read the real one */
789 kfree((*modpp)->asic);
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100790 for (asic = 0; asic < (*modpp)->num_asics; asic++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 int j;
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100792 voyager_asic_t *asicp = *asicpp = kzalloc(sizeof(voyager_asic_t), GFP_KERNEL); /*&voyager_asic_storage[asic_count++]; */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793 voyager_sp_table_t *sp_table;
794 voyager_at_t *asic_table;
795 voyager_jtt_t *jtag_table;
796
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100797 if (asicp == NULL) {
798 printk
799 ("**WARNING** kmalloc failure in cat_init\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 continue;
801 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 asicpp = &(asicp->next);
803 asicp->asic_location = asic;
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100804 sp_table =
805 (voyager_sp_table_t *) (eprom_buf + sp_offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 asicp->asic_id = sp_table->asic_id;
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100807 asic_table =
808 (voyager_at_t *) (eprom_buf +
809 sp_table->asic_data_offset);
810 for (j = 0; j < 4; j++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 asicp->jtag_id[j] = asic_table->jtag_id[j];
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100812 jtag_table =
813 (voyager_jtt_t *) (eprom_buf +
814 asic_table->jtag_offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815 asicp->ireg_length = jtag_table->ireg_len;
816 asicp->bit_location = (*modpp)->inst_bits;
817 (*modpp)->inst_bits += asicp->ireg_length;
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100818 if (asicp->ireg_length > (*modpp)->largest_reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 (*modpp)->largest_reg = asicp->ireg_length;
820 if (asicp->ireg_length < (*modpp)->smallest_reg ||
821 (*modpp)->smallest_reg == 0)
822 (*modpp)->smallest_reg = asicp->ireg_length;
823 CDEBUG(("asic 0x%x, ireg_length=%d, bit_location=%d\n",
824 asicp->asic_id, asicp->ireg_length,
825 asicp->bit_location));
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100826 if (asicp->asic_id == VOYAGER_QUAD_QABC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 CDEBUG(("VOYAGER CAT: QABC ASIC found\n"));
828 qabc_asic = asicp;
829 }
830 sp_offset += sizeof(voyager_sp_table_t);
831 }
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100832 CDEBUG(("Module inst_bits = %d, largest_reg = %d, smallest_reg=%d\n", (*modpp)->inst_bits, (*modpp)->largest_reg, (*modpp)->smallest_reg));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 /* OK, now we have the QUAD ASICs set up, use them.
834 * we need to:
835 *
836 * 1. Find the Memory area for the Quad CPIs.
837 * 2. Find the Extended VIC processor
838 * 3. Configure a second extended VIC processor (This
839 * cannot be done for the 51xx.
840 * */
841 outb(VOYAGER_CAT_RUN, CAT_CMD);
842 cat_connect(*modpp, (*modpp)->asic);
843 CDEBUG(("CAT CONNECTED!!\n"));
844 cat_subread(*modpp, qabc_asic, 0, sizeof(qabc_data), qabc_data);
845 qic_addr = qabc_data[5] << 8;
846 qic_addr = (qic_addr | qabc_data[6]) << 8;
847 qic_addr = (qic_addr | qabc_data[7]) << 8;
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100848 printk
849 ("Module \"%s\": Quad Processor Card; CPI 0x%lx, SET=0x%x\n",
850 cat_module_name(i), qic_addr, qabc_data[8]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851#if 0 /* plumbing fails---FIXME */
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100852 if ((qabc_data[8] & 0xf0) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 /* FIXME: 32 way 8 CPU slot monster cannot be
854 * plumbed this way---need to check for it */
855
856 printk("Plumbing second Extended Quad Processor\n");
857 /* second VIC line hardwired to Quad CPU 1 */
858 qabc_data[8] |= 0x20;
859 cat_subwrite(*modpp, qabc_asic, 8, 1, &qabc_data[8]);
860#ifdef VOYAGER_CAT_DEBUG
861 /* verify plumbing */
862 cat_subread(*modpp, qabc_asic, 8, 1, &qabc_data[8]);
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100863 if ((qabc_data[8] & 0xf0) == 0) {
864 CDEBUG(("PLUMBING FAILED: 0x%x\n",
865 qabc_data[8]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 }
867#endif
868 }
869#endif
870
871 {
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100872 struct resource *res =
873 kzalloc(sizeof(struct resource), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 res->name = kmalloc(128, GFP_KERNEL);
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100875 sprintf((char *)res->name, "Voyager %s Quad CPI",
876 cat_module_name(i));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 res->start = qic_addr;
878 res->end = qic_addr + 0x3ff;
879 request_resource(&iomem_resource, res);
880 }
881
882 qic_addr = (unsigned long)ioremap(qic_addr, 0x400);
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100883
884 for (j = 0; j < 4; j++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 __u8 cpu;
886
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100887 if (voyager_8slot) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888 /* 8 slot has a different mapping,
889 * each slot has only one vic line, so
890 * 1 cpu in each slot must be < 8 */
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100891 cpu = (i & 0x07) + j * 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 } else {
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100893 cpu = (i & 0x03) + j * 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 }
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100895 if ((qabc_data[8] & (1 << j))) {
896 voyager_extended_vic_processors |= (1 << cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 }
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100898 if (qabc_data[8] & (1 << (j + 4))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899 /* Second SET register plumbed: Quad
900 * card has two VIC connected CPUs.
901 * Secondary cannot be booted as a VIC
902 * CPU */
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100903 voyager_extended_vic_processors |= (1 << cpu);
904 voyager_allowed_boot_processors &=
905 (~(1 << cpu));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906 }
907
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100908 voyager_quad_processors |= (1 << cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 voyager_quad_cpi_addr[cpu] = (struct voyager_qic_cpi *)
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100910 (qic_addr + (j << 8));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 CDEBUG(("CPU%d: CPI address 0x%lx\n", cpu,
912 (unsigned long)voyager_quad_cpi_addr[cpu]));
913 }
914 outb(VOYAGER_CAT_END, CAT_CMD);
915
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 *asicpp = NULL;
917 modpp = &((*modpp)->next);
918 }
919 *modpp = NULL;
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100920 printk
921 ("CAT Bus Initialisation finished: extended procs 0x%x, quad procs 0x%x, allowed vic boot = 0x%x\n",
922 voyager_extended_vic_processors, voyager_quad_processors,
923 voyager_allowed_boot_processors);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 request_resource(&ioport_resource, &vic_res);
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100925 if (voyager_quad_processors)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926 request_resource(&ioport_resource, &qic_res);
927 /* set up the front power switch */
928}
929
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100930int voyager_cat_readb(__u8 module, __u8 asic, int reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931{
932 return 0;
933}
934
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100935static int cat_disconnect(voyager_module_t * modp, voyager_asic_t * asicp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936{
937 __u8 val;
938 int err = 0;
939
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100940 if (!modp->scan_path_connected)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 return 0;
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100942 if (asicp->asic_id != VOYAGER_CAT_ID) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 CDEBUG(("cat_disconnect: ASIC is not CAT\n"));
944 return 1;
945 }
946 err = cat_read(modp, asicp, VOYAGER_SCANPATH, &val);
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100947 if (err) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948 CDEBUG(("cat_disconnect: failed to read SCANPATH\n"));
949 return err;
950 }
951 val &= VOYAGER_DISCONNECT_ASIC;
952 err = cat_write(modp, asicp, VOYAGER_SCANPATH, val);
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100953 if (err) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954 CDEBUG(("cat_disconnect: failed to write SCANPATH\n"));
955 return err;
956 }
957 outb(VOYAGER_CAT_END, CAT_CMD);
958 outb(VOYAGER_CAT_RUN, CAT_CMD);
959 modp->scan_path_connected = 0;
960
961 return 0;
962}
963
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100964static int cat_connect(voyager_module_t * modp, voyager_asic_t * asicp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965{
966 __u8 val;
967 int err = 0;
968
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100969 if (modp->scan_path_connected)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970 return 0;
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100971 if (asicp->asic_id != VOYAGER_CAT_ID) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 CDEBUG(("cat_connect: ASIC is not CAT\n"));
973 return 1;
974 }
975
976 err = cat_read(modp, asicp, VOYAGER_SCANPATH, &val);
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100977 if (err) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978 CDEBUG(("cat_connect: failed to read SCANPATH\n"));
979 return err;
980 }
981 val |= VOYAGER_CONNECT_ASIC;
982 err = cat_write(modp, asicp, VOYAGER_SCANPATH, val);
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100983 if (err) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 CDEBUG(("cat_connect: failed to write SCANPATH\n"));
985 return err;
986 }
987 outb(VOYAGER_CAT_END, CAT_CMD);
988 outb(VOYAGER_CAT_RUN, CAT_CMD);
989 modp->scan_path_connected = 1;
990
991 return 0;
992}
993
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100994void voyager_cat_power_off(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995{
996 /* Power the machine off by writing to the PSI over the CAT
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100997 * bus */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 __u8 data;
999 voyager_module_t psi = { 0 };
1000 voyager_asic_t psi_asic = { 0 };
1001
1002 psi.asic = &psi_asic;
1003 psi.asic->asic_id = VOYAGER_CAT_ID;
1004 psi.asic->subaddr = VOYAGER_SUBADDR_HI;
1005 psi.module_addr = VOYAGER_PSI;
1006 psi.scan_path_connected = 0;
1007
1008 outb(VOYAGER_CAT_END, CAT_CMD);
1009 /* Connect the PSI to the CAT Bus */
1010 outb(VOYAGER_CAT_DESELECT, VOYAGER_CAT_CONFIG_PORT);
1011 outb(VOYAGER_PSI, VOYAGER_CAT_CONFIG_PORT);
1012 outb(VOYAGER_CAT_RUN, CAT_CMD);
1013 cat_disconnect(&psi, &psi_asic);
1014 /* Read the status */
1015 cat_subread(&psi, &psi_asic, VOYAGER_PSI_GENERAL_REG, 1, &data);
1016 outb(VOYAGER_CAT_END, CAT_CMD);
1017 CDEBUG(("PSI STATUS 0x%x\n", data));
1018 /* These two writes are power off prep and perform */
1019 data = PSI_CLEAR;
1020 outb(VOYAGER_CAT_RUN, CAT_CMD);
1021 cat_subwrite(&psi, &psi_asic, VOYAGER_PSI_GENERAL_REG, 1, &data);
1022 outb(VOYAGER_CAT_END, CAT_CMD);
1023 data = PSI_POWER_DOWN;
1024 outb(VOYAGER_CAT_RUN, CAT_CMD);
1025 cat_subwrite(&psi, &psi_asic, VOYAGER_PSI_GENERAL_REG, 1, &data);
1026 outb(VOYAGER_CAT_END, CAT_CMD);
1027}
1028
1029struct voyager_status voyager_status = { 0 };
1030
Ingo Molnara4ec1ef2008-01-30 13:30:10 +01001031void voyager_cat_psi(__u8 cmd, __u16 reg, __u8 * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032{
1033 voyager_module_t psi = { 0 };
1034 voyager_asic_t psi_asic = { 0 };
1035
1036 psi.asic = &psi_asic;
1037 psi.asic->asic_id = VOYAGER_CAT_ID;
1038 psi.asic->subaddr = VOYAGER_SUBADDR_HI;
1039 psi.module_addr = VOYAGER_PSI;
1040 psi.scan_path_connected = 0;
1041
1042 outb(VOYAGER_CAT_END, CAT_CMD);
1043 /* Connect the PSI to the CAT Bus */
1044 outb(VOYAGER_CAT_DESELECT, VOYAGER_CAT_CONFIG_PORT);
1045 outb(VOYAGER_PSI, VOYAGER_CAT_CONFIG_PORT);
1046 outb(VOYAGER_CAT_RUN, CAT_CMD);
1047 cat_disconnect(&psi, &psi_asic);
Ingo Molnara4ec1ef2008-01-30 13:30:10 +01001048 switch (cmd) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 case VOYAGER_PSI_READ:
1050 cat_read(&psi, &psi_asic, reg, data);
1051 break;
1052 case VOYAGER_PSI_WRITE:
1053 cat_write(&psi, &psi_asic, reg, *data);
1054 break;
1055 case VOYAGER_PSI_SUBREAD:
1056 cat_subread(&psi, &psi_asic, reg, 1, data);
1057 break;
1058 case VOYAGER_PSI_SUBWRITE:
1059 cat_subwrite(&psi, &psi_asic, reg, 1, data);
1060 break;
1061 default:
1062 printk(KERN_ERR "Voyager PSI, unrecognised command %d\n", cmd);
1063 break;
1064 }
1065 outb(VOYAGER_CAT_END, CAT_CMD);
1066}
1067
Ingo Molnara4ec1ef2008-01-30 13:30:10 +01001068void voyager_cat_do_common_interrupt(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069{
1070 /* This is caused either by a memory parity error or something
1071 * in the PSI */
1072 __u8 data;
1073 voyager_module_t psi = { 0 };
1074 voyager_asic_t psi_asic = { 0 };
1075 struct voyager_psi psi_reg;
1076 int i;
Ingo Molnara4ec1ef2008-01-30 13:30:10 +01001077 re_read:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078 psi.asic = &psi_asic;
1079 psi.asic->asic_id = VOYAGER_CAT_ID;
1080 psi.asic->subaddr = VOYAGER_SUBADDR_HI;
1081 psi.module_addr = VOYAGER_PSI;
1082 psi.scan_path_connected = 0;
1083
1084 outb(VOYAGER_CAT_END, CAT_CMD);
1085 /* Connect the PSI to the CAT Bus */
1086 outb(VOYAGER_CAT_DESELECT, VOYAGER_CAT_CONFIG_PORT);
1087 outb(VOYAGER_PSI, VOYAGER_CAT_CONFIG_PORT);
1088 outb(VOYAGER_CAT_RUN, CAT_CMD);
1089 cat_disconnect(&psi, &psi_asic);
1090 /* Read the status. NOTE: Need to read *all* the PSI regs here
1091 * otherwise the cmn int will be reasserted */
Ingo Molnara4ec1ef2008-01-30 13:30:10 +01001092 for (i = 0; i < sizeof(psi_reg.regs); i++) {
1093 cat_read(&psi, &psi_asic, i, &((__u8 *) & psi_reg.regs)[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094 }
1095 outb(VOYAGER_CAT_END, CAT_CMD);
Ingo Molnara4ec1ef2008-01-30 13:30:10 +01001096 if ((psi_reg.regs.checkbit & 0x02) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097 psi_reg.regs.checkbit |= 0x02;
1098 cat_write(&psi, &psi_asic, 5, psi_reg.regs.checkbit);
1099 printk("VOYAGER RE-READ PSI\n");
1100 goto re_read;
1101 }
1102 outb(VOYAGER_CAT_RUN, CAT_CMD);
Ingo Molnara4ec1ef2008-01-30 13:30:10 +01001103 for (i = 0; i < sizeof(psi_reg.subregs); i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104 /* This looks strange, but the PSI doesn't do auto increment
1105 * correctly */
Ingo Molnara4ec1ef2008-01-30 13:30:10 +01001106 cat_subread(&psi, &psi_asic, VOYAGER_PSI_SUPPLY_REG + i,
1107 1, &((__u8 *) & psi_reg.subregs)[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108 }
1109 outb(VOYAGER_CAT_END, CAT_CMD);
1110#ifdef VOYAGER_CAT_DEBUG
1111 printk("VOYAGER PSI: ");
Ingo Molnara4ec1ef2008-01-30 13:30:10 +01001112 for (i = 0; i < sizeof(psi_reg.regs); i++)
1113 printk("%02x ", ((__u8 *) & psi_reg.regs)[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114 printk("\n ");
Ingo Molnara4ec1ef2008-01-30 13:30:10 +01001115 for (i = 0; i < sizeof(psi_reg.subregs); i++)
1116 printk("%02x ", ((__u8 *) & psi_reg.subregs)[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117 printk("\n");
1118#endif
Ingo Molnara4ec1ef2008-01-30 13:30:10 +01001119 if (psi_reg.regs.intstatus & PSI_MON) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120 /* switch off or power fail */
1121
Ingo Molnara4ec1ef2008-01-30 13:30:10 +01001122 if (psi_reg.subregs.supply & PSI_SWITCH_OFF) {
1123 if (voyager_status.switch_off) {
1124 printk(KERN_ERR
1125 "Voyager front panel switch turned off again---Immediate power off!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126 voyager_cat_power_off();
1127 /* not reached */
1128 } else {
Ingo Molnara4ec1ef2008-01-30 13:30:10 +01001129 printk(KERN_ERR
1130 "Voyager front panel switch turned off\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131 voyager_status.switch_off = 1;
1132 voyager_status.request_from_kernel = 1;
Christoph Hellwigf3402a42007-04-22 20:30:43 +01001133 wake_up_process(voyager_thread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134 }
1135 /* Tell the hardware we're taking care of the
1136 * shutdown, otherwise it will power the box off
1137 * within 3 seconds of the switch being pressed and,
1138 * which is much more important to us, continue to
1139 * assert the common interrupt */
1140 data = PSI_CLR_SWITCH_OFF;
1141 outb(VOYAGER_CAT_RUN, CAT_CMD);
1142 cat_subwrite(&psi, &psi_asic, VOYAGER_PSI_SUPPLY_REG,
1143 1, &data);
1144 outb(VOYAGER_CAT_END, CAT_CMD);
1145 } else {
1146
1147 VDEBUG(("Voyager ac fail reg 0x%x\n",
1148 psi_reg.subregs.ACfail));
Ingo Molnara4ec1ef2008-01-30 13:30:10 +01001149 if ((psi_reg.subregs.ACfail & AC_FAIL_STAT_CHANGE) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150 /* No further update */
1151 return;
1152 }
1153#if 0
1154 /* Don't bother trying to find out who failed.
1155 * FIXME: This probably makes the code incorrect on
1156 * anything other than a 345x */
Ingo Molnara4ec1ef2008-01-30 13:30:10 +01001157 for (i = 0; i < 5; i++) {
1158 if (psi_reg.subregs.ACfail & (1 << i)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159 break;
1160 }
1161 }
1162 printk(KERN_NOTICE "AC FAIL IN SUPPLY %d\n", i);
1163#endif
1164 /* DON'T do this: it shuts down the AC PSI
Ingo Molnara4ec1ef2008-01-30 13:30:10 +01001165 outb(VOYAGER_CAT_RUN, CAT_CMD);
1166 data = PSI_MASK_MASK | i;
1167 cat_subwrite(&psi, &psi_asic, VOYAGER_PSI_MASK,
1168 1, &data);
1169 outb(VOYAGER_CAT_END, CAT_CMD);
1170 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171 printk(KERN_ERR "Voyager AC power failure\n");
1172 outb(VOYAGER_CAT_RUN, CAT_CMD);
1173 data = PSI_COLD_START;
1174 cat_subwrite(&psi, &psi_asic, VOYAGER_PSI_GENERAL_REG,
1175 1, &data);
1176 outb(VOYAGER_CAT_END, CAT_CMD);
1177 voyager_status.power_fail = 1;
1178 voyager_status.request_from_kernel = 1;
Christoph Hellwigf3402a42007-04-22 20:30:43 +01001179 wake_up_process(voyager_thread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180 }
Ingo Molnara4ec1ef2008-01-30 13:30:10 +01001181
1182 } else if (psi_reg.regs.intstatus & PSI_FAULT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183 /* Major fault! */
Ingo Molnara4ec1ef2008-01-30 13:30:10 +01001184 printk(KERN_ERR
1185 "Voyager PSI Detected major fault, immediate power off!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186 voyager_cat_power_off();
1187 /* not reached */
Ingo Molnara4ec1ef2008-01-30 13:30:10 +01001188 } else if (psi_reg.regs.intstatus & (PSI_DC_FAIL | PSI_ALARM
1189 | PSI_CURRENT | PSI_DVM
1190 | PSI_PSCFAULT | PSI_STAT_CHG)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191 /* other psi fault */
1192
1193 printk(KERN_WARNING "Voyager PSI status 0x%x\n", data);
1194 /* clear the PSI fault */
1195 outb(VOYAGER_CAT_RUN, CAT_CMD);
1196 cat_write(&psi, &psi_asic, VOYAGER_PSI_STATUS_REG, 0);
1197 outb(VOYAGER_CAT_END, CAT_CMD);
1198 }
1199}