1#define AUTOSENSE
2#define PSEUDO_DMA
3#define FOO
4#define UNSAFE
5#define PDEBUG 0
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114#include <linux/module.h>
115
116#include <linux/signal.h>
117#include <linux/proc_fs.h>
118#include <asm/io.h>
119#include <asm/dma.h>
120#include <linux/blkdev.h>
121#include <linux/delay.h>
122#include <linux/interrupt.h>
123#include <linux/stat.h>
124#include <linux/init.h>
125
126#include "scsi.h"
127#include <scsi/scsi_host.h>
128#include "pas16.h"
129#define AUTOPROBE_IRQ
130#include "NCR5380.h"
131
132
133static int pas_maxi = 0;
134static int pas_wmaxi = 0;
135static unsigned short pas16_addr = 0;
136static int pas16_irq = 0;
137
138
139static const int scsi_irq_translate[] =
140 { 0, 0, 1, 2, 3, 4, 5, 6, 0, 0, 7, 8, 9, 0, 10, 11 };
141
142
143
144
145
146
147static int default_irqs[] __initdata =
148 { PAS16_DEFAULT_BOARD_1_IRQ,
149 PAS16_DEFAULT_BOARD_2_IRQ,
150 PAS16_DEFAULT_BOARD_3_IRQ,
151 PAS16_DEFAULT_BOARD_4_IRQ
152 };
153
154static struct override {
155 unsigned short io_port;
156 int irq;
157} overrides
158#ifdef PAS16_OVERRIDE
159 [] __initdata = PAS16_OVERRIDE;
160#else
161 [4] __initdata = {{0,IRQ_AUTO}, {0,IRQ_AUTO}, {0,IRQ_AUTO},
162 {0,IRQ_AUTO}};
163#endif
164
165#define NO_OVERRIDES ARRAY_SIZE(overrides)
166
167static struct base {
168 unsigned short io_port;
169 int noauto;
170} bases[] __initdata =
171 { {PAS16_DEFAULT_BASE_1, 0},
172 {PAS16_DEFAULT_BASE_2, 0},
173 {PAS16_DEFAULT_BASE_3, 0},
174 {PAS16_DEFAULT_BASE_4, 0}
175 };
176
177#define NO_BASES ARRAY_SIZE(bases)
178
179static const unsigned short pas16_offset[ 8 ] =
180 {
181 0x1c00,
182 0x1c01,
183 0x1c02,
184 0x1c03,
185 0x3c00,
186 0x3c01,
187 0x3c02,
188
189
190 0x3c03,
191
192
193 };
194
195
196
197
198
199
200
201
202
203
204
205#if 1
206#define rtrc(i) {inb(0x3da); outb(0x31, 0x3c0); outb((i), 0x3c0);}
207#else
208#define rtrc(i) {}
209#endif
210
211
212
213
214
215
216
217
218
219
220
221static void __init
222 enable_board( int board_num, unsigned short port )
223{
224 outb( 0xbc + board_num, MASTER_ADDRESS_PTR );
225 outb( port >> 2, MASTER_ADDRESS_PTR );
226}
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241static void __init
242 init_board( unsigned short io_port, int irq, int force_irq )
243{
244 unsigned int tmp;
245 unsigned int pas_irq_code;
246
247
248
249 outb( 0x30, io_port + P_TIMEOUT_COUNTER_REG );
250 outb( 0x01, io_port + P_TIMEOUT_STATUS_REG_OFFSET );
251 outb( 0x01, io_port + WAIT_STATE );
252
253 NCR5380_read( RESET_PARITY_INTERRUPT_REG );
254
255
256
257
258 pas_irq_code = ( irq < 16 ) ? scsi_irq_translate[irq] : 0;
259 tmp = inb( io_port + IO_CONFIG_3 );
260
261 if( (( tmp & 0x0f ) == pas_irq_code) && pas_irq_code > 0
262 && !force_irq )
263 {
264 printk( "pas16: WARNING: Can't use same irq as sound "
265 "driver -- interrupts disabled\n" );
266
267 outb( 0x4d, io_port + SYS_CONFIG_4 );
268 }
269 else
270 {
271 tmp = ( tmp & 0x0f ) | ( pas_irq_code << 4 );
272 outb( tmp, io_port + IO_CONFIG_3 );
273
274
275 outb( 0x6d, io_port + SYS_CONFIG_4 );
276 }
277}
278
279
280
281
282
283
284
285
286
287
288
289
290static int __init
291 pas16_hw_detect( unsigned short board_num )
292{
293 unsigned char board_rev, tmp;
294 unsigned short io_port = bases[ board_num ].io_port;
295
296
297
298
299
300
301
302
303 enable_board( board_num, io_port );
304
305
306 board_rev = inb( io_port + PCB_CONFIG );
307
308 if( board_rev == 0xff )
309 return 0;
310
311 tmp = board_rev ^ 0xe0;
312
313 outb( tmp, io_port + PCB_CONFIG );
314 tmp = inb( io_port + PCB_CONFIG );
315 outb( board_rev, io_port + PCB_CONFIG );
316
317 if( board_rev != tmp )
318 return 0;
319
320 if( ( inb( io_port + OPERATION_MODE_1 ) & 0x03 ) != 0x03 )
321 return 0;
322
323
324
325
326
327
328 outb( 0x01, io_port + WAIT_STATE );
329 NCR5380_write( MODE_REG, 0x20 );
330 if( NCR5380_read( MODE_REG ) != 0x20 )
331 return 0;
332 NCR5380_write( MODE_REG, 0x00 );
333 if( NCR5380_read( MODE_REG ) != 0x00 )
334 return 0;
335
336 return 1;
337}
338
339
340
341
342
343
344
345
346
347
348
349
350void __init pas16_setup(char *str, int *ints)
351{
352 static int commandline_current = 0;
353 int i;
354 if (ints[0] != 2)
355 printk("pas16_setup : usage pas16=io_port,irq\n");
356 else
357 if (commandline_current < NO_OVERRIDES) {
358 overrides[commandline_current].io_port = (unsigned short) ints[1];
359 overrides[commandline_current].irq = ints[2];
360 for (i = 0; i < NO_BASES; ++i)
361 if (bases[i].io_port == (unsigned short) ints[1]) {
362 bases[i].noauto = 1;
363 break;
364 }
365 ++commandline_current;
366 }
367}
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382int __init pas16_detect(struct scsi_host_template * tpnt)
383{
384 static int current_override = 0;
385 static unsigned short current_base = 0;
386 struct Scsi_Host *instance;
387 unsigned short io_port;
388 int count;
389
390 tpnt->proc_name = "pas16";
391 tpnt->proc_info = &pas16_proc_info;
392
393 if (pas16_addr != 0) {
394 overrides[0].io_port = pas16_addr;
395
396
397
398
399
400 for (count = 0; count < NO_BASES; ++count)
401 if (bases[count].io_port == pas16_addr) {
402 bases[count].noauto = 1;
403 break;
404 }
405 }
406 if (pas16_irq != 0)
407 overrides[0].irq = pas16_irq;
408
409 for (count = 0; current_override < NO_OVERRIDES; ++current_override) {
410 io_port = 0;
411
412 if (overrides[current_override].io_port)
413 {
414 io_port = overrides[current_override].io_port;
415 enable_board( current_override, io_port );
416 init_board( io_port, overrides[current_override].irq, 1 );
417 }
418 else
419 for (; !io_port && (current_base < NO_BASES); ++current_base) {
420#if (PDEBUG & PDEBUG_INIT)
421 printk("scsi-pas16 : probing io_port %04x\n", (unsigned int) bases[current_base].io_port);
422#endif
423 if ( !bases[current_base].noauto &&
424 pas16_hw_detect( current_base ) ){
425 io_port = bases[current_base].io_port;
426 init_board( io_port, default_irqs[ current_base ], 0 );
427#if (PDEBUG & PDEBUG_INIT)
428 printk("scsi-pas16 : detected board.\n");
429#endif
430 }
431 }
432
433
434#if defined(PDEBUG) && (PDEBUG & PDEBUG_INIT)
435 printk("scsi-pas16 : io_port = %04x\n", (unsigned int) io_port);
436#endif
437
438 if (!io_port)
439 break;
440
441 instance = scsi_register (tpnt, sizeof(struct NCR5380_hostdata));
442 if(instance == NULL)
443 break;
444
445 instance->io_port = io_port;
446
447 NCR5380_init(instance, 0);
448
449 if (overrides[current_override].irq != IRQ_AUTO)
450 instance->irq = overrides[current_override].irq;
451 else
452 instance->irq = NCR5380_probe_irq(instance, PAS16_IRQS);
453
454 if (instance->irq != SCSI_IRQ_NONE)
455 if (request_irq(instance->irq, pas16_intr, IRQF_DISABLED,
456 "pas16", instance)) {
457 printk("scsi%d : IRQ%d not free, interrupts disabled\n",
458 instance->host_no, instance->irq);
459 instance->irq = SCSI_IRQ_NONE;
460 }
461
462 if (instance->irq == SCSI_IRQ_NONE) {
463 printk("scsi%d : interrupts not enabled. for better interactive performance,\n", instance->host_no);
464 printk("scsi%d : please jumper the board for a free IRQ.\n", instance->host_no);
465
466 outb( 0x4d, io_port + SYS_CONFIG_4 );
467 outb( (inb(io_port + IO_CONFIG_3) & 0x0f), io_port + IO_CONFIG_3 );
468 }
469
470#if defined(PDEBUG) && (PDEBUG & PDEBUG_INIT)
471 printk("scsi%d : irq = %d\n", instance->host_no, instance->irq);
472#endif
473
474 printk("scsi%d : at 0x%04x", instance->host_no, (int)
475 instance->io_port);
476 if (instance->irq == SCSI_IRQ_NONE)
477 printk (" interrupts disabled");
478 else
479 printk (" irq %d", instance->irq);
480 printk(" options CAN_QUEUE=%d CMD_PER_LUN=%d release=%d",
481 CAN_QUEUE, CMD_PER_LUN, PAS16_PUBLIC_RELEASE);
482 NCR5380_print_options(instance);
483 printk("\n");
484
485 ++current_override;
486 ++count;
487 }
488 return count;
489}
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511int pas16_biosparam(struct scsi_device *sdev, struct block_device *dev,
512 sector_t capacity, int * ip)
513{
514 int size = capacity;
515 ip[0] = 64;
516 ip[1] = 32;
517 ip[2] = size >> 11;
518 if( ip[2] > 1024 ) {
519 ip[0]=255;
520 ip[1]=63;
521 ip[2]=size/(63*255);
522 if( ip[2] > 1023 )
523 ip[2] = 1023;
524 }
525
526 return 0;
527}
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542static inline int NCR5380_pread (struct Scsi_Host *instance, unsigned char *dst,
543 int len) {
544 register unsigned char *d = dst;
545 register unsigned short reg = (unsigned short) (instance->io_port +
546 P_DATA_REG_OFFSET);
547 register int i = len;
548 int ii = 0;
549
550 while ( !(inb(instance->io_port + P_STATUS_REG_OFFSET) & P_ST_RDY) )
551 ++ii;
552
553 insb( reg, d, i );
554
555 if ( inb(instance->io_port + P_TIMEOUT_STATUS_REG_OFFSET) & P_TS_TIM) {
556 outb( P_TS_CT, instance->io_port + P_TIMEOUT_STATUS_REG_OFFSET);
557 printk("scsi%d : watchdog timer fired in NCR5380_pread()\n",
558 instance->host_no);
559 return -1;
560 }
561 if (ii > pas_maxi)
562 pas_maxi = ii;
563 return 0;
564}
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579static inline int NCR5380_pwrite (struct Scsi_Host *instance, unsigned char *src,
580 int len) {
581 register unsigned char *s = src;
582 register unsigned short reg = (instance->io_port + P_DATA_REG_OFFSET);
583 register int i = len;
584 int ii = 0;
585
586 while ( !((inb(instance->io_port + P_STATUS_REG_OFFSET)) & P_ST_RDY) )
587 ++ii;
588
589 outsb( reg, s, i );
590
591 if (inb(instance->io_port + P_TIMEOUT_STATUS_REG_OFFSET) & P_TS_TIM) {
592 outb( P_TS_CT, instance->io_port + P_TIMEOUT_STATUS_REG_OFFSET);
593 printk("scsi%d : watchdog timer fired in NCR5380_pwrite()\n",
594 instance->host_no);
595 return -1;
596 }
597 if (ii > pas_maxi)
598 pas_wmaxi = ii;
599 return 0;
600}
601
602#include "NCR5380.c"
603
604static int pas16_release(struct Scsi_Host *shost)
605{
606 if (shost->irq)
607 free_irq(shost->irq, shost);
608 NCR5380_exit(shost);
609 if (shost->dma_channel != 0xff)
610 free_dma(shost->dma_channel);
611 if (shost->io_port && shost->n_io_port)
612 release_region(shost->io_port, shost->n_io_port);
613 scsi_unregister(shost);
614 return 0;
615}
616
617static struct scsi_host_template driver_template = {
618 .name = "Pro Audio Spectrum-16 SCSI",
619 .detect = pas16_detect,
620 .release = pas16_release,
621 .queuecommand = pas16_queue_command,
622 .eh_abort_handler = pas16_abort,
623 .eh_bus_reset_handler = pas16_bus_reset,
624 .bios_param = pas16_biosparam,
625 .can_queue = CAN_QUEUE,
626 .this_id = 7,
627 .sg_tablesize = SG_ALL,
628 .cmd_per_lun = CMD_PER_LUN,
629 .use_clustering = DISABLE_CLUSTERING,
630};
631#include "scsi_module.c"
632
633#ifdef MODULE
634module_param(pas16_addr, ushort, 0);
635module_param(pas16_irq, int, 0);
636#endif
637MODULE_LICENSE("GPL");
638