blob: 3597ef47b28a4763a782886e605024b76523a3f7 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * This software may be used and distributed according to the terms
3 * of the GNU General Public License, incorporated herein by reference.
4 *
5 */
6
7#include <linux/module.h>
8#include <linux/init.h>
9#include <linux/interrupt.h>
10#include <linux/delay.h>
Alexey Dobriyand43c36d2009-10-07 17:09:06 +040011#include <linux/sched.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090012#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include "includes.h"
14#include "hardware.h"
15#include "card.h"
16
17MODULE_DESCRIPTION("ISDN4Linux: Driver for Spellcaster card");
18MODULE_AUTHOR("Spellcaster Telecommunications Inc.");
19MODULE_LICENSE("GPL");
20
21board *sc_adapter[MAX_CARDS];
22int cinst;
23
24static char devname[] = "scX";
Adrian Bunke3ca5e72005-06-25 14:58:34 -070025static const char version[] = "2.0b1";
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
Adrian Bunke3ca5e72005-06-25 14:58:34 -070027static const char *boardname[] = { "DataCommute/BRI", "DataCommute/PRI", "TeleCommute/BRI" };
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
29/* insmod set parameters */
Joe Perches475be4d2012-02-19 19:52:38 -080030static unsigned int io[] = {0, 0, 0, 0};
31static unsigned char irq[] = {0, 0, 0, 0};
32static unsigned long ram[] = {0, 0, 0, 0};
Akash Shendeabee1ce2015-01-16 19:12:42 +053033static bool do_reset;
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
35module_param_array(io, int, NULL, 0);
Geert Uytterhoevenb9e48de2013-04-24 02:46:37 +000036module_param_array(irq, byte, NULL, 0);
37module_param_array(ram, long, NULL, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070038module_param(do_reset, bool, 0);
39
Adrian Bunke3ca5e72005-06-25 14:58:34 -070040static int identify_board(unsigned long, unsigned int);
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
42static int __init sc_init(void)
43{
44 int b = -1;
45 int i, j;
46 int status = -ENODEV;
47
48 unsigned long memsize = 0;
49 unsigned long features = 0;
50 isdn_if *interface;
51 unsigned char channels;
52 unsigned char pgport;
53 unsigned long magic;
54 int model;
55 int last_base = IOBASE_MIN;
56 int probe_exhasted = 0;
57
58#ifdef MODULE
59 pr_info("SpellCaster ISA ISDN Adapter Driver rev. %s Loaded\n", version);
60#else
61 pr_info("SpellCaster ISA ISDN Adapter Driver rev. %s\n", version);
62#endif
63 pr_info("Copyright (C) 1996 SpellCaster Telecommunications Inc.\n");
64
Joe Perches475be4d2012-02-19 19:52:38 -080065 while (b++ < MAX_CARDS - 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 pr_debug("Probing for adapter #%d\n", b);
67 /*
68 * Initialize reusable variables
69 */
70 model = -1;
71 magic = 0;
72 channels = 0;
73 pgport = 0;
74
Joe Perches475be4d2012-02-19 19:52:38 -080075 /*
76 * See if we should probe for IO base
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 */
78 pr_debug("I/O Base for board %d is 0x%x, %s probe\n", b, io[b],
Joe Perches475be4d2012-02-19 19:52:38 -080079 io[b] == 0 ? "will" : "won't");
80 if (io[b]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 /*
82 * No, I/O Base has been provided
83 */
Joe Perches475be4d2012-02-19 19:52:38 -080084 for (i = 0; i < MAX_IO_REGS - 1; i++) {
85 if (!request_region(io[b] + i * 0x400, 1, "sc test")) {
Peter Osterlundfb911ee2005-09-13 01:25:15 -070086 pr_debug("request_region for 0x%x failed\n", io[b] + i * 0x400);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 io[b] = 0;
88 break;
89 } else
90 release_region(io[b] + i * 0x400, 1);
91 }
92
93 /*
94 * Confirm the I/O Address with a test
95 */
Joe Perches475be4d2012-02-19 19:52:38 -080096 if (io[b] == 0) {
Jeff Garzik76fd0202006-10-11 01:22:25 -070097 pr_debug("I/O Address invalid.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 continue;
99 }
100
101 outb(0x18, io[b] + 0x400 * EXP_PAGE0);
Joe Perches475be4d2012-02-19 19:52:38 -0800102 if (inb(io[b] + 0x400 * EXP_PAGE0) != 0x18) {
Jeff Garzik76fd0202006-10-11 01:22:25 -0700103 pr_debug("I/O Base 0x%x fails test\n",
104 io[b] + 0x400 * EXP_PAGE0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 continue;
106 }
Akash Shendeabee1ce2015-01-16 19:12:42 +0530107 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 /*
109 * Yes, probe for I/O Base
110 */
Joe Perches475be4d2012-02-19 19:52:38 -0800111 if (probe_exhasted) {
Akash Shendeabee1ce2015-01-16 19:12:42 +0530112 pr_debug("All probe addresses exhausted, skipping\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 continue;
114 }
115 pr_debug("Probing for I/O...\n");
Joe Perches475be4d2012-02-19 19:52:38 -0800116 for (i = last_base; i <= IOBASE_MAX; i += IOBASE_OFFSET) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 int found_io = 1;
118 if (i == IOBASE_MAX) {
119 probe_exhasted = 1; /* No more addresses to probe */
120 pr_debug("End of Probes\n");
121 }
122 last_base = i + IOBASE_OFFSET;
123 pr_debug(" checking 0x%x...", i);
Joe Perches475be4d2012-02-19 19:52:38 -0800124 for (j = 0; j < MAX_IO_REGS - 1; j++) {
125 if (!request_region(i + j * 0x400, 1, "sc test")) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 pr_debug("Failed\n");
127 found_io = 0;
128 break;
129 } else
130 release_region(i + j * 0x400, 1);
Joe Perches475be4d2012-02-19 19:52:38 -0800131 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
Joe Perches475be4d2012-02-19 19:52:38 -0800133 if (found_io) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 io[b] = i;
135 outb(0x18, io[b] + 0x400 * EXP_PAGE0);
Joe Perches475be4d2012-02-19 19:52:38 -0800136 if (inb(io[b] + 0x400 * EXP_PAGE0) != 0x18) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 pr_debug("Failed by test\n");
138 continue;
139 }
140 pr_debug("Passed\n");
141 break;
142 }
143 }
Joe Perches475be4d2012-02-19 19:52:38 -0800144 if (probe_exhasted) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 continue;
146 }
147 }
148
149 /*
150 * See if we should probe for shared RAM
151 */
Joe Perches475be4d2012-02-19 19:52:38 -0800152 if (do_reset) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 pr_debug("Doing a SAFE probe reset\n");
154 outb(0xFF, io[b] + RESET_OFFSET);
155 msleep_interruptible(10000);
156 }
Jeff Garzik76fd0202006-10-11 01:22:25 -0700157 pr_debug("RAM Base for board %d is 0x%lx, %s probe\n", b,
Joe Perches475be4d2012-02-19 19:52:38 -0800158 ram[b], ram[b] == 0 ? "will" : "won't");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
Joe Perches475be4d2012-02-19 19:52:38 -0800160 if (ram[b]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 /*
162 * No, the RAM base has been provided
163 * Just look for a signature and ID the
164 * board model
165 */
Joe Perches475be4d2012-02-19 19:52:38 -0800166 if (request_region(ram[b], SRAM_PAGESIZE, "sc test")) {
Jeff Garzik76fd0202006-10-11 01:22:25 -0700167 pr_debug("request_region for RAM base 0x%lx succeeded\n", ram[b]);
Joe Perches475be4d2012-02-19 19:52:38 -0800168 model = identify_board(ram[b], io[b]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 release_region(ram[b], SRAM_PAGESIZE);
170 }
Akash Shendeabee1ce2015-01-16 19:12:42 +0530171 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 /*
173 * Yes, probe for free RAM and look for
174 * a signature and id the board model
175 */
Joe Perches475be4d2012-02-19 19:52:38 -0800176 for (i = SRAM_MIN; i < SRAM_MAX; i += SRAM_PAGESIZE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 pr_debug("Checking RAM address 0x%x...\n", i);
Joe Perches475be4d2012-02-19 19:52:38 -0800178 if (request_region(i, SRAM_PAGESIZE, "sc test")) {
Peter Osterlundfb911ee2005-09-13 01:25:15 -0700179 pr_debug(" request_region succeeded\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 model = identify_board(i, io[b]);
181 release_region(i, SRAM_PAGESIZE);
182 if (model >= 0) {
183 pr_debug(" Identified a %s\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800184 boardname[model]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 ram[b] = i;
186 break;
187 }
Akash Shendeabee1ce2015-01-16 19:12:42 +0530188 pr_debug(" Unidentified or inaccessible\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 continue;
190 }
191 pr_debug(" request failed\n");
192 }
193 }
194 /*
195 * See if we found free RAM and the board model
196 */
Joe Perches475be4d2012-02-19 19:52:38 -0800197 if (!ram[b] || model < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 /*
199 * Nope, there was no place in RAM for the
200 * board, or it couldn't be identified
201 */
Joe Perches475be4d2012-02-19 19:52:38 -0800202 pr_debug("Failed to find an adapter at 0x%lx\n", ram[b]);
203 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 }
205
206 /*
207 * Set the board's magic number, memory size and page register
208 */
Joe Perches475be4d2012-02-19 19:52:38 -0800209 switch (model) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 case PRI_BOARD:
211 channels = 23;
212 magic = 0x20000;
213 memsize = 0x100000;
214 features = PRI_FEATURES;
215 break;
216
217 case BRI_BOARD:
218 case POTS_BOARD:
219 channels = 2;
220 magic = 0x60000;
221 memsize = 0x10000;
222 features = BRI_FEATURES;
223 break;
224 }
Joe Perches475be4d2012-02-19 19:52:38 -0800225 switch (ram[b] >> 12 & 0x0F) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 case 0x0:
227 pr_debug("RAM Page register set to EXP_PAGE0\n");
228 pgport = EXP_PAGE0;
229 break;
230
231 case 0x4:
232 pr_debug("RAM Page register set to EXP_PAGE1\n");
233 pgport = EXP_PAGE1;
234 break;
235
236 case 0x8:
237 pr_debug("RAM Page register set to EXP_PAGE2\n");
238 pgport = EXP_PAGE2;
239 break;
240
241 case 0xC:
242 pr_debug("RAM Page register set to EXP_PAGE3\n");
243 pgport = EXP_PAGE3;
244 break;
245
246 default:
247 pr_debug("RAM base address doesn't fall on 16K boundary\n");
248 continue;
249 }
250
Joe Perches475be4d2012-02-19 19:52:38 -0800251 pr_debug("current IRQ: %d b: %d\n", irq[b], b);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252
253 /*
254 * Make sure we got an IRQ
255 */
Joe Perches475be4d2012-02-19 19:52:38 -0800256 if (!irq[b]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 /*
258 * No interrupt could be used
259 */
260 pr_debug("Failed to acquire an IRQ line\n");
261 continue;
262 }
263
264 /*
265 * Horray! We found a board, Make sure we can register
266 * it with ISDN4Linux
267 */
Burman Yan41f96932006-12-08 02:39:35 -0800268 interface = kzalloc(sizeof(isdn_if), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 if (interface == NULL) {
270 /*
271 * Oops, can't malloc isdn_if
272 */
273 continue;
274 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275
276 interface->owner = THIS_MODULE;
277 interface->hl_hdrlen = 0;
278 interface->channels = channels;
279 interface->maxbufsize = BUFFER_SIZE;
280 interface->features = features;
281 interface->writebuf_skb = sndpkt;
282 interface->writecmd = NULL;
283 interface->command = command;
284 strcpy(interface->id, devname);
285 interface->id[2] = '0' + cinst;
286
287 /*
288 * Allocate the board structure
289 */
Burman Yan41f96932006-12-08 02:39:35 -0800290 sc_adapter[cinst] = kzalloc(sizeof(board), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 if (sc_adapter[cinst] == NULL) {
292 /*
293 * Oops, can't alloc memory for the board
294 */
295 kfree(interface);
296 continue;
297 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 spin_lock_init(&sc_adapter[cinst]->lock);
299
Joe Perches475be4d2012-02-19 19:52:38 -0800300 if (!register_isdn(interface)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 /*
302 * Oops, couldn't register for some reason
303 */
304 kfree(interface);
305 kfree(sc_adapter[cinst]);
306 continue;
307 }
308
309 sc_adapter[cinst]->card = interface;
310 sc_adapter[cinst]->driverId = interface->channels;
311 strcpy(sc_adapter[cinst]->devicename, interface->id);
312 sc_adapter[cinst]->nChannels = channels;
313 sc_adapter[cinst]->ramsize = memsize;
314 sc_adapter[cinst]->shmem_magic = magic;
315 sc_adapter[cinst]->shmem_pgport = pgport;
316 sc_adapter[cinst]->StartOnReset = 1;
317
318 /*
319 * Allocate channels status structures
320 */
Burman Yan41f96932006-12-08 02:39:35 -0800321 sc_adapter[cinst]->channel = kzalloc(sizeof(bchan) * channels, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 if (sc_adapter[cinst]->channel == NULL) {
323 /*
324 * Oops, can't alloc memory for the channels
325 */
326 indicate_status(cinst, ISDN_STAT_UNLOAD, 0, NULL); /* Fix me */
327 kfree(interface);
328 kfree(sc_adapter[cinst]);
329 continue;
330 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331
332 /*
333 * Lock down the hardware resources
334 */
335 sc_adapter[cinst]->interrupt = irq[b];
336 if (request_irq(sc_adapter[cinst]->interrupt, interrupt_handler,
Michael Opdenacker33235ca2013-10-13 07:24:29 +0200337 0, interface->id,
Akash Shendeabee1ce2015-01-16 19:12:42 +0530338 (void *)(unsigned long) cinst)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 kfree(sc_adapter[cinst]->channel);
340 indicate_status(cinst, ISDN_STAT_UNLOAD, 0, NULL); /* Fix me */
341 kfree(interface);
342 kfree(sc_adapter[cinst]);
343 continue;
Joe Perches475be4d2012-02-19 19:52:38 -0800344
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 }
346 sc_adapter[cinst]->iobase = io[b];
Joe Perches475be4d2012-02-19 19:52:38 -0800347 for (i = 0; i < MAX_IO_REGS - 1; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 sc_adapter[cinst]->ioport[i] = io[b] + i * 0x400;
349 request_region(sc_adapter[cinst]->ioport[i], 1,
Joe Perches475be4d2012-02-19 19:52:38 -0800350 interface->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 pr_debug("Requesting I/O Port %#x\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800352 sc_adapter[cinst]->ioport[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 }
354 sc_adapter[cinst]->ioport[IRQ_SELECT] = io[b] + 0x2;
355 request_region(sc_adapter[cinst]->ioport[IRQ_SELECT], 1,
Joe Perches475be4d2012-02-19 19:52:38 -0800356 interface->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 pr_debug("Requesting I/O Port %#x\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800358 sc_adapter[cinst]->ioport[IRQ_SELECT]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 sc_adapter[cinst]->rambase = ram[b];
360 request_region(sc_adapter[cinst]->rambase, SRAM_PAGESIZE,
Joe Perches475be4d2012-02-19 19:52:38 -0800361 interface->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362
Joe Perches475be4d2012-02-19 19:52:38 -0800363 pr_info(" %s (%d) - %s %d channels IRQ %d, I/O Base 0x%x, RAM Base 0x%lx\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 sc_adapter[cinst]->devicename,
365 sc_adapter[cinst]->driverId,
366 boardname[model], channels, irq[b], io[b], ram[b]);
Joe Perches475be4d2012-02-19 19:52:38 -0800367
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 /*
369 * reset the adapter to put things in motion
370 */
371 reset(cinst);
372
373 cinst++;
374 status = 0;
375 }
Joe Perches475be4d2012-02-19 19:52:38 -0800376 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 pr_info("Failed to find any adapters, driver unloaded\n");
378 return status;
379}
380
381static void __exit sc_exit(void)
382{
383 int i, j;
384
Joe Perches475be4d2012-02-19 19:52:38 -0800385 for (i = 0; i < cinst; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 pr_debug("Cleaning up after adapter %d\n", i);
387 /*
388 * kill the timers
389 */
Julia Lawall0c295e42014-03-26 22:33:39 +0100390 del_timer_sync(&(sc_adapter[i]->reset_timer));
391 del_timer_sync(&(sc_adapter[i]->stat_timer));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392
393 /*
394 * Tell I4L we're toast
395 */
396 indicate_status(i, ISDN_STAT_STOP, 0, NULL);
397 indicate_status(i, ISDN_STAT_UNLOAD, 0, NULL);
398
399 /*
400 * Release shared RAM
401 */
402 release_region(sc_adapter[i]->rambase, SRAM_PAGESIZE);
403
404 /*
405 * Release the IRQ
406 */
Fernando Luis Vázquez Cao345225c2007-10-18 23:39:20 -0700407 free_irq(sc_adapter[i]->interrupt, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
409 /*
410 * Reset for a clean start
411 */
412 outb(0xFF, sc_adapter[i]->ioport[SFT_RESET]);
413
414 /*
415 * Release the I/O Port regions
416 */
Joe Perches475be4d2012-02-19 19:52:38 -0800417 for (j = 0; j < MAX_IO_REGS - 1; j++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 release_region(sc_adapter[i]->ioport[j], 1);
419 pr_debug("Releasing I/O Port %#x\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800420 sc_adapter[i]->ioport[j]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 }
422 release_region(sc_adapter[i]->ioport[IRQ_SELECT], 1);
423 pr_debug("Releasing I/O Port %#x\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800424 sc_adapter[i]->ioport[IRQ_SELECT]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425
426 /*
427 * Release any memory we alloced
428 */
429 kfree(sc_adapter[i]->channel);
430 kfree(sc_adapter[i]->card);
431 kfree(sc_adapter[i]);
432 }
433 pr_info("SpellCaster ISA ISDN Adapter Driver Unloaded.\n");
434}
435
Adrian Bunke3ca5e72005-06-25 14:58:34 -0700436static int identify_board(unsigned long rambase, unsigned int iobase)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437{
438 unsigned int pgport;
439 unsigned long sig;
440 DualPortMemory *dpm;
441 RspMessage rcvmsg;
442 ReqMessage sndmsg;
443 HWConfig_pl hwci;
444 int x;
445
Jeff Garzik76fd0202006-10-11 01:22:25 -0700446 pr_debug("Attempting to identify adapter @ 0x%lx io 0x%x\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800447 rambase, iobase);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448
449 /*
450 * Enable the base pointer
451 */
452 outb(rambase >> 12, iobase + 0x2c00);
453
Joe Perches475be4d2012-02-19 19:52:38 -0800454 switch (rambase >> 12 & 0x0F) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 case 0x0:
456 pgport = iobase + PG0_OFFSET;
457 pr_debug("Page Register offset is 0x%x\n", PG0_OFFSET);
458 break;
Joe Perches475be4d2012-02-19 19:52:38 -0800459
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 case 0x4:
461 pgport = iobase + PG1_OFFSET;
462 pr_debug("Page Register offset is 0x%x\n", PG1_OFFSET);
463 break;
464
465 case 0x8:
466 pgport = iobase + PG2_OFFSET;
467 pr_debug("Page Register offset is 0x%x\n", PG2_OFFSET);
468 break;
469
470 case 0xC:
471 pgport = iobase + PG3_OFFSET;
472 pr_debug("Page Register offset is 0x%x\n", PG3_OFFSET);
473 break;
474 default:
475 pr_debug("Invalid rambase 0x%lx\n", rambase);
476 return -1;
477 }
478
479 /*
480 * Try to identify a PRI card
481 */
482 outb(PRI_BASEPG_VAL, pgport);
483 msleep_interruptible(1000);
484 sig = readl(rambase + SIG_OFFSET);
Jeff Garzik76fd0202006-10-11 01:22:25 -0700485 pr_debug("Looking for a signature, got 0x%lx\n", sig);
Joe Perches475be4d2012-02-19 19:52:38 -0800486 if (sig == SIGNATURE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 return PRI_BOARD;
488
489 /*
490 * Try to identify a PRI card
491 */
492 outb(BRI_BASEPG_VAL, pgport);
493 msleep_interruptible(1000);
494 sig = readl(rambase + SIG_OFFSET);
Jeff Garzik76fd0202006-10-11 01:22:25 -0700495 pr_debug("Looking for a signature, got 0x%lx\n", sig);
Joe Perches475be4d2012-02-19 19:52:38 -0800496 if (sig == SIGNATURE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 return BRI_BOARD;
498
499 return -1;
500
501 /*
502 * Try to spot a card
503 */
504 sig = readl(rambase + SIG_OFFSET);
Jeff Garzik76fd0202006-10-11 01:22:25 -0700505 pr_debug("Looking for a signature, got 0x%lx\n", sig);
Joe Perches475be4d2012-02-19 19:52:38 -0800506 if (sig != SIGNATURE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 return -1;
508
509 dpm = (DualPortMemory *) rambase;
510
511 memset(&sndmsg, 0, MSG_LEN);
512 sndmsg.msg_byte_cnt = 3;
513 sndmsg.type = cmReqType1;
514 sndmsg.class = cmReqClass0;
515 sndmsg.code = cmReqHWConfig;
516 memcpy_toio(&(dpm->req_queue[dpm->req_head++]), &sndmsg, MSG_LEN);
517 outb(0, iobase + 0x400);
518 pr_debug("Sent HWConfig message\n");
519 /*
520 * Wait for the response
521 */
522 x = 0;
Joe Perches475be4d2012-02-19 19:52:38 -0800523 while ((inb(iobase + FIFOSTAT_OFFSET) & RF_HAS_DATA) && x < 100) {
Nishanth Aravamudan24763c42005-11-07 01:01:16 -0800524 schedule_timeout_interruptible(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 x++;
526 }
Joe Perches475be4d2012-02-19 19:52:38 -0800527 if (x == 100) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 pr_debug("Timeout waiting for response\n");
529 return -1;
530 }
531
532 memcpy_fromio(&rcvmsg, &(dpm->rsp_queue[dpm->rsp_tail]), MSG_LEN);
533 pr_debug("Got HWConfig response, status = 0x%x\n", rcvmsg.rsp_status);
534 memcpy(&hwci, &(rcvmsg.msg_data.HWCresponse), sizeof(HWConfig_pl));
Jeff Garzik76fd0202006-10-11 01:22:25 -0700535 pr_debug("Hardware Config: Interface: %s, RAM Size: %ld, Serial: %s\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 " Part: %s, Rev: %s\n",
537 hwci.st_u_sense ? "S/T" : "U", hwci.ram_size,
538 hwci.serial_no, hwci.part_no, hwci.rev_no);
539
Joe Perches475be4d2012-02-19 19:52:38 -0800540 if (!strncmp(PRI_PARTNO, hwci.part_no, 6))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 return PRI_BOARD;
Joe Perches475be4d2012-02-19 19:52:38 -0800542 if (!strncmp(BRI_PARTNO, hwci.part_no, 6))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 return BRI_BOARD;
Joe Perches475be4d2012-02-19 19:52:38 -0800544
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 return -1;
546}
547
548module_init(sc_init);
549module_exit(sc_exit);