ncr5380: Remove BOARD_REQUIRES_NO_DELAY macro
[deliverable/linux.git] / drivers / scsi / pas16.c
CommitLineData
1da177e4
LT
1/*
2 * This driver adapted from Drew Eckhardt's Trantor T128 driver
3 *
4 * Copyright 1993, Drew Eckhardt
5 * Visionary Computing
6 * (Unix and Linux consulting and custom programming)
7 * drew@colorado.edu
8 * +1 (303) 666-5836
9 *
10 * ( Based on T128 - DISTRIBUTION RELEASE 3. )
11 *
12 * Modified to work with the Pro Audio Spectrum/Studio 16
13 * by John Weidman.
14 *
15 *
16 * For more information, please consult
17 *
18 * Media Vision
19 * (510) 770-8600
20 * (800) 348-7116
1da177e4
LT
21 */
22
23/*
1da177e4
LT
24 * The card is detected and initialized in one of several ways :
25 * 1. Autoprobe (default) - There are many different models of
26 * the Pro Audio Spectrum/Studio 16, and I only have one of
27 * them, so this may require a little tweaking. An interrupt
28 * is triggered to autoprobe for the interrupt line. Note:
29 * with the newer model boards, the interrupt is set via
30 * software after reset using the default_irq for the
31 * current board number.
32 *
33 * 2. With command line overrides - pas16=port,irq may be
34 * used on the LILO command line to override the defaults.
35 *
36 * 3. With the PAS16_OVERRIDE compile time define. This is
37 * specified as an array of address, irq tuples. Ie, for
38 * one board at the default 0x388 address, IRQ10, I could say
39 * -DPAS16_OVERRIDE={{0x388, 10}}
40 * NOTE: Untested.
41 *
42 * 4. When included as a module, with arguments passed on the command line:
43 * pas16_irq=xx the interrupt
44 * pas16_addr=xx the port
45 * e.g. "modprobe pas16 pas16_addr=0x388 pas16_irq=5"
46 *
47 * Note that if the override methods are used, place holders must
48 * be specified for other boards in the system.
49 *
50 *
51 * Configuration notes :
52 * The current driver does not support interrupt sharing with the
53 * sound portion of the card. If you use the same irq for the
54 * scsi port and sound you will have problems. Either use
55 * a different irq for the scsi port or don't use interrupts
56 * for the scsi port.
57 *
58 * If you have problems with your card not being recognized, use
59 * the LILO command line override. Try to get it recognized without
60 * interrupts. Ie, for a board at the default 0x388 base port,
22f5f10d 61 * boot: linux pas16=0x388,0
1da177e4 62 *
22f5f10d 63 * NO_IRQ (0) should be specified for no interrupt,
1da177e4
LT
64 * IRQ_AUTO (254) to autoprobe for an IRQ line if overridden
65 * on the command line.
1da177e4
LT
66 */
67
68#include <linux/module.h>
69
1da177e4
LT
70#include <asm/io.h>
71#include <asm/dma.h>
72#include <linux/blkdev.h>
1da177e4 73#include <linux/interrupt.h>
1da177e4
LT
74#include <linux/init.h>
75
1da177e4
LT
76#include <scsi/scsi_host.h>
77#include "pas16.h"
78#define AUTOPROBE_IRQ
79#include "NCR5380.h"
80
81
d5f7e65d
FT
82static unsigned short pas16_addr;
83static int pas16_irq;
1da177e4
LT
84
85
408b664a 86static const int scsi_irq_translate[] =
1da177e4
LT
87 { 0, 0, 1, 2, 3, 4, 5, 6, 0, 0, 7, 8, 9, 0, 10, 11 };
88
89/* The default_irqs array contains values used to set the irq into the
90 * board via software (as must be done on newer model boards without
91 * irq jumpers on the board). The first value in the array will be
92 * assigned to logical board 0, the next to board 1, etc.
93 */
408b664a 94static int default_irqs[] __initdata =
1da177e4
LT
95 { PAS16_DEFAULT_BOARD_1_IRQ,
96 PAS16_DEFAULT_BOARD_2_IRQ,
97 PAS16_DEFAULT_BOARD_3_IRQ,
98 PAS16_DEFAULT_BOARD_4_IRQ
99 };
100
101static struct override {
102 unsigned short io_port;
103 int irq;
6391a113 104} overrides
1da177e4
LT
105#ifdef PAS16_OVERRIDE
106 [] __initdata = PAS16_OVERRIDE;
107#else
108 [4] __initdata = {{0,IRQ_AUTO}, {0,IRQ_AUTO}, {0,IRQ_AUTO},
109 {0,IRQ_AUTO}};
110#endif
111
6391a113 112#define NO_OVERRIDES ARRAY_SIZE(overrides)
1da177e4
LT
113
114static struct base {
115 unsigned short io_port;
116 int noauto;
6391a113 117} bases[] __initdata =
1da177e4
LT
118 { {PAS16_DEFAULT_BASE_1, 0},
119 {PAS16_DEFAULT_BASE_2, 0},
120 {PAS16_DEFAULT_BASE_3, 0},
121 {PAS16_DEFAULT_BASE_4, 0}
122 };
123
6391a113 124#define NO_BASES ARRAY_SIZE(bases)
1da177e4 125
408b664a 126static const unsigned short pas16_offset[ 8 ] =
1da177e4
LT
127 {
128 0x1c00, /* OUTPUT_DATA_REG */
129 0x1c01, /* INITIATOR_COMMAND_REG */
130 0x1c02, /* MODE_REG */
131 0x1c03, /* TARGET_COMMAND_REG */
132 0x3c00, /* STATUS_REG ro, SELECT_ENABLE_REG wo */
133 0x3c01, /* BUS_AND_STATUS_REG ro, START_DMA_SEND_REG wo */
134 0x3c02, /* INPUT_DATA_REGISTER ro, (N/A on PAS16 ?)
135 * START_DMA_TARGET_RECEIVE_REG wo
136 */
137 0x3c03, /* RESET_PARITY_INTERRUPT_REG ro,
138 * START_DMA_INITIATOR_RECEIVE_REG wo
139 */
140 };
1da177e4
LT
141
142
143/*
144 * Function : enable_board( int board_num, unsigned short port )
145 *
146 * Purpose : set address in new model board
147 *
148 * Inputs : board_num - logical board number 0-3, port - base address
149 *
150 */
151
152static void __init
153 enable_board( int board_num, unsigned short port )
154{
155 outb( 0xbc + board_num, MASTER_ADDRESS_PTR );
156 outb( port >> 2, MASTER_ADDRESS_PTR );
157}
158
159
160
161/*
162 * Function : init_board( unsigned short port, int irq )
163 *
164 * Purpose : Set the board up to handle the SCSI interface
165 *
166 * Inputs : port - base address of the board,
167 * irq - irq to assign to the SCSI port
168 * force_irq - set it even if it conflicts with sound driver
169 *
170 */
171
172static void __init
173 init_board( unsigned short io_port, int irq, int force_irq )
174{
175 unsigned int tmp;
176 unsigned int pas_irq_code;
177
178 /* Initialize the SCSI part of the board */
179
180 outb( 0x30, io_port + P_TIMEOUT_COUNTER_REG ); /* Timeout counter */
181 outb( 0x01, io_port + P_TIMEOUT_STATUS_REG_OFFSET ); /* Reset TC */
182 outb( 0x01, io_port + WAIT_STATE ); /* 1 Wait state */
183
54d8fe44 184 inb(io_port + pas16_offset[RESET_PARITY_INTERRUPT_REG]);
1da177e4
LT
185
186 /* Set the SCSI interrupt pointer without mucking up the sound
187 * interrupt pointer in the same byte.
188 */
189 pas_irq_code = ( irq < 16 ) ? scsi_irq_translate[irq] : 0;
190 tmp = inb( io_port + IO_CONFIG_3 );
191
192 if( (( tmp & 0x0f ) == pas_irq_code) && pas_irq_code > 0
193 && !force_irq )
194 {
195 printk( "pas16: WARNING: Can't use same irq as sound "
196 "driver -- interrupts disabled\n" );
197 /* Set up the drive parameters, disable 5380 interrupts */
198 outb( 0x4d, io_port + SYS_CONFIG_4 );
199 }
200 else
201 {
202 tmp = ( tmp & 0x0f ) | ( pas_irq_code << 4 );
203 outb( tmp, io_port + IO_CONFIG_3 );
204
205 /* Set up the drive parameters and enable 5380 interrupts */
206 outb( 0x6d, io_port + SYS_CONFIG_4 );
207 }
208}
209
210
211/*
212 * Function : pas16_hw_detect( unsigned short board_num )
213 *
214 * Purpose : determine if a pas16 board is present
215 *
216 * Inputs : board_num - logical board number ( 0 - 3 )
217 *
218 * Returns : 0 if board not found, 1 if found.
219 */
220
221static int __init
222 pas16_hw_detect( unsigned short board_num )
223{
224 unsigned char board_rev, tmp;
225 unsigned short io_port = bases[ board_num ].io_port;
226
227 /* See if we can find a PAS16 board at the address associated
228 * with this logical board number.
229 */
230
231 /* First, attempt to take a newer model board out of reset and
232 * give it a base address. This shouldn't affect older boards.
233 */
234 enable_board( board_num, io_port );
235
236 /* Now see if it looks like a PAS16 board */
237 board_rev = inb( io_port + PCB_CONFIG );
238
239 if( board_rev == 0xff )
240 return 0;
241
242 tmp = board_rev ^ 0xe0;
243
244 outb( tmp, io_port + PCB_CONFIG );
245 tmp = inb( io_port + PCB_CONFIG );
246 outb( board_rev, io_port + PCB_CONFIG );
247
248 if( board_rev != tmp ) /* Not a PAS-16 */
249 return 0;
250
251 if( ( inb( io_port + OPERATION_MODE_1 ) & 0x03 ) != 0x03 )
252 return 0; /* return if no SCSI interface found */
253
254 /* Mediavision has some new model boards that return ID bits
255 * that indicate a SCSI interface, but they're not (LMS). We'll
256 * put in an additional test to try to weed them out.
257 */
258
54d8fe44
FT
259 outb(0x01, io_port + WAIT_STATE); /* 1 Wait state */
260 outb(0x20, io_port + pas16_offset[MODE_REG]); /* Is it really SCSI? */
261 if (inb(io_port + pas16_offset[MODE_REG]) != 0x20) /* Write to a reg. */
262 return 0; /* and try to read */
263 outb(0x00, io_port + pas16_offset[MODE_REG]); /* it back. */
264 if (inb(io_port + pas16_offset[MODE_REG]) != 0x00)
265 return 0;
1da177e4
LT
266
267 return 1;
268}
269
270
925e4610 271#ifndef MODULE
1da177e4
LT
272/*
273 * Function : pas16_setup(char *str, int *ints)
274 *
275 * Purpose : LILO command line initialization of the overrides array,
276 *
277 * Inputs : str - unused, ints - array of integer parameters with ints[0]
278 * equal to the number of ints.
279 *
280 */
281
925e4610 282static int __init pas16_setup(char *str)
1da177e4 283{
d5f7e65d 284 static int commandline_current;
1da177e4 285 int i;
925e4610
FT
286 int ints[10];
287
288 get_options(str, ARRAY_SIZE(ints), ints);
1da177e4
LT
289 if (ints[0] != 2)
290 printk("pas16_setup : usage pas16=io_port,irq\n");
291 else
292 if (commandline_current < NO_OVERRIDES) {
293 overrides[commandline_current].io_port = (unsigned short) ints[1];
294 overrides[commandline_current].irq = ints[2];
295 for (i = 0; i < NO_BASES; ++i)
296 if (bases[i].io_port == (unsigned short) ints[1]) {
297 bases[i].noauto = 1;
298 break;
299 }
300 ++commandline_current;
301 }
925e4610 302 return 1;
1da177e4
LT
303}
304
925e4610
FT
305__setup("pas16=", pas16_setup);
306#endif
307
1da177e4 308/*
d0be4a7d 309 * Function : int pas16_detect(struct scsi_host_template * tpnt)
1da177e4
LT
310 *
311 * Purpose : detects and initializes PAS16 controllers
312 * that were autoprobed, overridden on the LILO command line,
313 * or specified at compile time.
314 *
315 * Inputs : tpnt - template for this SCSI adapter.
316 *
317 * Returns : 1 if a host adapter was found, 0 if not.
318 *
319 */
320
ed8b9e7f 321static int __init pas16_detect(struct scsi_host_template *tpnt)
1da177e4 322{
d5f7e65d
FT
323 static int current_override;
324 static unsigned short current_base;
1da177e4
LT
325 struct Scsi_Host *instance;
326 unsigned short io_port;
327 int count;
328
1da177e4
LT
329 if (pas16_addr != 0) {
330 overrides[0].io_port = pas16_addr;
331 /*
332 * This is how we avoid seeing more than
333 * one host adapter at the same I/O port.
334 * Cribbed shamelessly from pas16_setup().
335 */
336 for (count = 0; count < NO_BASES; ++count)
337 if (bases[count].io_port == pas16_addr) {
338 bases[count].noauto = 1;
339 break;
340 }
341 }
342 if (pas16_irq != 0)
343 overrides[0].irq = pas16_irq;
344
345 for (count = 0; current_override < NO_OVERRIDES; ++current_override) {
346 io_port = 0;
347
348 if (overrides[current_override].io_port)
349 {
350 io_port = overrides[current_override].io_port;
351 enable_board( current_override, io_port );
352 init_board( io_port, overrides[current_override].irq, 1 );
353 }
354 else
355 for (; !io_port && (current_base < NO_BASES); ++current_base) {
2f7dba9f
FT
356 dprintk(NDEBUG_INIT, "pas16: probing io_port 0x%04x\n",
357 (unsigned int)bases[current_base].io_port);
1da177e4
LT
358 if ( !bases[current_base].noauto &&
359 pas16_hw_detect( current_base ) ){
360 io_port = bases[current_base].io_port;
361 init_board( io_port, default_irqs[ current_base ], 0 );
2f7dba9f 362 dprintk(NDEBUG_INIT, "pas16: detected board\n");
1da177e4
LT
363 }
364 }
365
2f7dba9f
FT
366 dprintk(NDEBUG_INIT, "pas16: io_port = 0x%04x\n",
367 (unsigned int)io_port);
1da177e4
LT
368
369 if (!io_port)
370 break;
371
372 instance = scsi_register (tpnt, sizeof(struct NCR5380_hostdata));
373 if(instance == NULL)
0ad0eff9 374 goto out;
1da177e4
LT
375
376 instance->io_port = io_port;
377
1bb46002 378 if (NCR5380_init(instance, FLAG_DMA_FIXUP))
0ad0eff9 379 goto out_unregister;
1da177e4 380
b6488f97
FT
381 NCR5380_maybe_reset_bus(instance);
382
1da177e4
LT
383 if (overrides[current_override].irq != IRQ_AUTO)
384 instance->irq = overrides[current_override].irq;
385 else
386 instance->irq = NCR5380_probe_irq(instance, PAS16_IRQS);
387
22f5f10d
FT
388 /* Compatibility with documented NCR5380 kernel parameters */
389 if (instance->irq == 255)
390 instance->irq = NO_IRQ;
391
392 if (instance->irq != NO_IRQ)
4909cc2b 393 if (request_irq(instance->irq, pas16_intr, 0,
1e641664 394 "pas16", instance)) {
1da177e4
LT
395 printk("scsi%d : IRQ%d not free, interrupts disabled\n",
396 instance->host_no, instance->irq);
22f5f10d 397 instance->irq = NO_IRQ;
1da177e4
LT
398 }
399
22f5f10d 400 if (instance->irq == NO_IRQ) {
1da177e4
LT
401 printk("scsi%d : interrupts not enabled. for better interactive performance,\n", instance->host_no);
402 printk("scsi%d : please jumper the board for a free IRQ.\n", instance->host_no);
403 /* Disable 5380 interrupts, leave drive params the same */
404 outb( 0x4d, io_port + SYS_CONFIG_4 );
405 outb( (inb(io_port + IO_CONFIG_3) & 0x0f), io_port + IO_CONFIG_3 );
406 }
407
2f7dba9f
FT
408 dprintk(NDEBUG_INIT, "scsi%d : irq = %d\n",
409 instance->host_no, instance->irq);
1da177e4 410
1da177e4
LT
411 ++current_override;
412 ++count;
413 }
414 return count;
0ad0eff9
FT
415
416out_unregister:
417 scsi_unregister(instance);
418out:
419 return count;
1da177e4
LT
420}
421
422/*
423 * Function : int pas16_biosparam(Disk *disk, struct block_device *dev, int *ip)
424 *
425 * Purpose : Generates a BIOS / DOS compatible H-C-S mapping for
426 * the specified device / size.
427 *
428 * Inputs : size = size of device in sectors (512 bytes), dev = block device
429 * major / minor, ip[] = {heads, sectors, cylinders}
430 *
431 * Returns : always 0 (success), initializes ip
432 *
433 */
434
435/*
436 * XXX Most SCSI boards use this mapping, I could be incorrect. Some one
437 * using hard disks on a trantor should verify that this mapping corresponds
438 * to that used by the BIOS / ASPI driver by running the linux fdisk program
439 * and matching the H_C_S coordinates to what DOS uses.
440 */
441
ed8b9e7f
FT
442static int pas16_biosparam(struct scsi_device *sdev, struct block_device *dev,
443 sector_t capacity, int *ip)
1da177e4
LT
444{
445 int size = capacity;
446 ip[0] = 64;
447 ip[1] = 32;
448 ip[2] = size >> 11; /* I think I have it as /(32*64) */
449 if( ip[2] > 1024 ) { /* yes, >, not >= */
450 ip[0]=255;
451 ip[1]=63;
452 ip[2]=size/(63*255);
453 if( ip[2] > 1023 ) /* yes >1023... */
454 ip[2] = 1023;
455 }
456
457 return 0;
458}
459
460/*
461 * Function : int NCR5380_pread (struct Scsi_Host *instance,
462 * unsigned char *dst, int len)
463 *
464 * Purpose : Fast 5380 pseudo-dma read function, transfers len bytes to
465 * dst
466 *
467 * Inputs : dst = destination, len = length in bytes
468 *
469 * Returns : 0 on success, non zero on a failure such as a watchdog
470 * timeout.
471 */
472
473static inline int NCR5380_pread (struct Scsi_Host *instance, unsigned char *dst,
474 int len) {
475 register unsigned char *d = dst;
476 register unsigned short reg = (unsigned short) (instance->io_port +
477 P_DATA_REG_OFFSET);
478 register int i = len;
479 int ii = 0;
480
481 while ( !(inb(instance->io_port + P_STATUS_REG_OFFSET) & P_ST_RDY) )
482 ++ii;
483
484 insb( reg, d, i );
485
486 if ( inb(instance->io_port + P_TIMEOUT_STATUS_REG_OFFSET) & P_TS_TIM) {
487 outb( P_TS_CT, instance->io_port + P_TIMEOUT_STATUS_REG_OFFSET);
488 printk("scsi%d : watchdog timer fired in NCR5380_pread()\n",
489 instance->host_no);
490 return -1;
491 }
1da177e4
LT
492 return 0;
493}
494
495/*
496 * Function : int NCR5380_pwrite (struct Scsi_Host *instance,
497 * unsigned char *src, int len)
498 *
499 * Purpose : Fast 5380 pseudo-dma write function, transfers len bytes from
500 * src
501 *
502 * Inputs : src = source, len = length in bytes
503 *
504 * Returns : 0 on success, non zero on a failure such as a watchdog
505 * timeout.
506 */
507
508static inline int NCR5380_pwrite (struct Scsi_Host *instance, unsigned char *src,
509 int len) {
510 register unsigned char *s = src;
511 register unsigned short reg = (instance->io_port + P_DATA_REG_OFFSET);
512 register int i = len;
513 int ii = 0;
514
515 while ( !((inb(instance->io_port + P_STATUS_REG_OFFSET)) & P_ST_RDY) )
516 ++ii;
517
518 outsb( reg, s, i );
519
520 if (inb(instance->io_port + P_TIMEOUT_STATUS_REG_OFFSET) & P_TS_TIM) {
521 outb( P_TS_CT, instance->io_port + P_TIMEOUT_STATUS_REG_OFFSET);
522 printk("scsi%d : watchdog timer fired in NCR5380_pwrite()\n",
523 instance->host_no);
524 return -1;
525 }
1da177e4
LT
526 return 0;
527}
528
529#include "NCR5380.c"
530
531static int pas16_release(struct Scsi_Host *shost)
532{
22f5f10d 533 if (shost->irq != NO_IRQ)
1e641664 534 free_irq(shost->irq, shost);
1da177e4 535 NCR5380_exit(shost);
1da177e4
LT
536 scsi_unregister(shost);
537 return 0;
538}
539
d0be4a7d 540static struct scsi_host_template driver_template = {
aa2e2cb1
FT
541 .name = "Pro Audio Spectrum-16 SCSI",
542 .detect = pas16_detect,
543 .release = pas16_release,
544 .proc_name = "pas16",
aa2e2cb1
FT
545 .info = pas16_info,
546 .queuecommand = pas16_queue_command,
547 .eh_abort_handler = pas16_abort,
548 .eh_bus_reset_handler = pas16_bus_reset,
549 .bios_param = pas16_biosparam,
550 .can_queue = 32,
551 .this_id = 7,
552 .sg_tablesize = SG_ALL,
553 .cmd_per_lun = 2,
554 .use_clustering = DISABLE_CLUSTERING,
32b26a10 555 .cmd_size = NCR5380_CMD_SIZE,
0a4e3612 556 .max_sectors = 128,
1da177e4
LT
557};
558#include "scsi_module.c"
559
560#ifdef MODULE
561module_param(pas16_addr, ushort, 0);
562module_param(pas16_irq, int, 0);
563#endif
564MODULE_LICENSE("GPL");
This page took 0.99252 seconds and 5 git commands to generate.