2 * Generic Generic NCR5380 driver
4 * Copyright 1995-2002, Russell King
6 #include <linux/module.h>
7 #include <linux/signal.h>
8 #include <linux/sched.h>
9 #include <linux/ioport.h>
10 #include <linux/delay.h>
11 #include <linux/blkdev.h>
12 #include <linux/init.h>
14 #include <asm/ecard.h>
17 #include <asm/system.h>
20 #include <scsi/scsi_host.h>
22 #include <scsi/scsicam.h>
27 #define CUMANASCSI_PUBLIC_RELEASE 1
29 #define NCR5380_implementation_fields int port, ctrl
30 #define NCR5380_local_declare() struct Scsi_Host *_instance
31 #define NCR5380_setup(instance) _instance = instance
32 #define NCR5380_read(reg) cumanascsi_read(_instance, reg)
33 #define NCR5380_write(reg, value) cumanascsi_write(_instance, reg, value)
34 #define NCR5380_intr cumanascsi_intr
35 #define NCR5380_queue_command cumanascsi_queue_command
36 #define NCR5380_proc_info cumanascsi_proc_info
38 #define BOARD_NORMAL 0
39 #define BOARD_NCR53C400 1
41 #include "../NCR5380.h"
43 void cumanascsi_setup(char *str
, int *ints
)
47 const char *cumanascsi_info(struct Scsi_Host
*spnt
)
53 #define CTRL(p,v) outb(*ctrl = (v), (p) - 577)
54 #define STAT(p) inb((p)+1)
55 #define IN(p) inb((p))
56 #define OUT(v,p) outb((v), (p))
58 #define CTRL(p,v) (p[-2308] = (*ctrl = (v)))
59 #define STAT(p) (p[4])
61 #define IN2(p) ((unsigned short)(*(volatile unsigned long *)(p)))
62 #define OUT(v,p) (*(p) = (v))
63 #define OUT2(v,p) (*((volatile unsigned long *)(p)) = (v))
65 #define L(v) (((v)<<16)|((v) & 0x0000ffff))
66 #define H(v) (((v)>>16)|((v) & 0xffff0000))
69 NCR5380_pwrite(struct Scsi_Host
*instance
, unsigned char *addr
, int len
)
71 int *ctrl
= &((struct NCR5380_hostdata
*)instance
->hostdata
)->ctrl
;
75 int iobase
= instance
->io_port
;
76 int dma_io
= iobase
& ~(0x3C0000>>2);
78 volatile unsigned char *iobase
= (unsigned char *)ioaddr(instance
->io_port
);
79 volatile unsigned char *dma_io
= (unsigned char *)((int)iobase
& ~0x3C0000);
85 laddr
= (unsigned long *)addr
;
90 status
= STAT(iobase
);
95 v
=*laddr
++; OUT2(L(v
),dma_io
); OUT2(H(v
),dma_io
);
96 v
=*laddr
++; OUT2(L(v
),dma_io
); OUT2(H(v
),dma_io
);
97 v
=*laddr
++; OUT2(L(v
),dma_io
); OUT2(H(v
),dma_io
);
98 v
=*laddr
++; OUT2(L(v
),dma_io
); OUT2(H(v
),dma_io
);
99 v
=*laddr
++; OUT2(L(v
),dma_io
); OUT2(H(v
),dma_io
);
100 v
=*laddr
++; OUT2(L(v
),dma_io
); OUT2(H(v
),dma_io
);
101 v
=*laddr
++; OUT2(L(v
),dma_io
); OUT2(H(v
),dma_io
);
102 v
=*laddr
++; OUT2(L(v
),dma_io
); OUT2(H(v
),dma_io
);
108 addr
= (unsigned char *)laddr
;
113 status
= STAT(iobase
);
118 OUT(*addr
++, dma_io
);
123 status
= STAT(iobase
);
128 OUT(*addr
++, dma_io
);
134 CTRL(iobase
, oldctrl
|0x40);
139 NCR5380_pread(struct Scsi_Host
*instance
, unsigned char *addr
, int len
)
141 int *ctrl
= &((struct NCR5380_hostdata
*)instance
->hostdata
)->ctrl
;
143 unsigned long *laddr
;
145 int iobase
= instance
->io_port
;
146 int dma_io
= iobase
& ~(0x3C0000>>2);
148 volatile unsigned char *iobase
= (unsigned char *)ioaddr(instance
->io_port
);
149 volatile unsigned char *dma_io
= (unsigned char *)((int)iobase
& ~0x3C0000);
155 laddr
= (unsigned long *)addr
;
159 status
= STAT(iobase
);
164 *laddr
++ = IN2(dma_io
)|(IN2(dma_io
)<<16);
165 *laddr
++ = IN2(dma_io
)|(IN2(dma_io
)<<16);
166 *laddr
++ = IN2(dma_io
)|(IN2(dma_io
)<<16);
167 *laddr
++ = IN2(dma_io
)|(IN2(dma_io
)<<16);
168 *laddr
++ = IN2(dma_io
)|(IN2(dma_io
)<<16);
169 *laddr
++ = IN2(dma_io
)|(IN2(dma_io
)<<16);
170 *laddr
++ = IN2(dma_io
)|(IN2(dma_io
)<<16);
171 *laddr
++ = IN2(dma_io
)|(IN2(dma_io
)<<16);
177 addr
= (unsigned char *)laddr
;
182 status
= STAT(iobase
);
187 *addr
++ = IN(dma_io
);
192 status
= STAT(iobase
);
197 *addr
++ = IN(dma_io
);
203 CTRL(iobase
, oldctrl
|0x40);
212 #define CTRL(p,v) outb(*ctrl = (v), (p) - 577)
214 static char cumanascsi_read(struct Scsi_Host
*instance
, int reg
)
216 unsigned int iobase
= instance
->io_port
;
218 int *ctrl
= &((struct NCR5380_hostdata
*)instance
->hostdata
)->ctrl
;
221 i
= inb(iobase
+ 64 + reg
);
227 static void cumanascsi_write(struct Scsi_Host
*instance
, int reg
, int value
)
229 int iobase
= instance
->io_port
;
230 int *ctrl
= &((struct NCR5380_hostdata
*)instance
->hostdata
)->ctrl
;
233 outb(value
, iobase
+ 64 + reg
);
239 #include "../NCR5380.c"
241 static Scsi_Host_Template cumanascsi_template
= {
242 .module
= THIS_MODULE
,
243 .name
= "Cumana 16-bit SCSI",
244 .info
= cumanascsi_info
,
245 .queuecommand
= cumanascsi_queue_command
,
246 .eh_abort_handler
= NCR5380_abort
,
247 .eh_device_reset_handler
= NCR5380_device_reset
,
248 .eh_bus_reset_handler
= NCR5380_bus_reset
,
249 .eh_host_reset_handler
= NCR5380_host_reset
,
252 .sg_tablesize
= SG_ALL
,
254 .unchecked_isa_dma
= 0,
255 .use_clustering
= DISABLE_CLUSTERING
,
256 .proc_name
= "CumanaSCSI-1",
260 cumanascsi1_probe(struct expansion_card
*ec
, const struct ecard_id
*id
)
262 struct Scsi_Host
*host
;
265 host
= scsi_host_alloc(&cumanascsi_template
, sizeof(struct NCR5380_hostdata
));
269 host
->io_port
= ecard_address(ec
, ECARD_IOC
, ECARD_SLOW
) + 0x800;
272 NCR5380_init(host
, 0);
274 host
->n_io_port
= 255;
275 if (!(request_region(host
->io_port
, host
->n_io_port
, "CumanaSCSI-1"))) {
280 ((struct NCR5380_hostdata
*)host
->hostdata
)->ctrl
= 0;
281 outb(0x00, host
->io_port
- 577);
283 ret
= request_irq(host
->irq
, cumanascsi_intr
, SA_INTERRUPT
,
284 "CumanaSCSI-1", host
);
286 printk("scsi%d: IRQ%d not free: %d\n",
287 host
->host_no
, host
->irq
, ret
);
291 printk("scsi%d: at port 0x%08lx irq %d",
292 host
->host_no
, host
->io_port
, host
->irq
);
293 printk(" options CAN_QUEUE=%d CMD_PER_LUN=%d release=%d",
294 host
->can_queue
, host
->cmd_per_lun
, CUMANASCSI_PUBLIC_RELEASE
);
295 printk("\nscsi%d:", host
->host_no
);
296 NCR5380_print_options(host
);
299 ret
= scsi_add_host(host
, &ec
->dev
);
303 scsi_scan_host(host
);
307 free_irq(host
->irq
, host
);
309 release_region(host
->io_port
, host
->n_io_port
);
316 static void __devexit
cumanascsi1_remove(struct expansion_card
*ec
)
318 struct Scsi_Host
*host
= ecard_get_drvdata(ec
);
320 ecard_set_drvdata(ec
, NULL
);
322 scsi_remove_host(host
);
323 free_irq(host
->irq
, host
);
325 release_region(host
->io_port
, host
->n_io_port
);
329 static const struct ecard_id cumanascsi1_cids
[] = {
330 { MANU_CUMANA
, PROD_CUMANA_SCSI_1
},
334 static struct ecard_driver cumanascsi1_driver
= {
335 .probe
= cumanascsi1_probe
,
336 .remove
= __devexit_p(cumanascsi1_remove
),
337 .id_table
= cumanascsi1_cids
,
339 .name
= "cumanascsi1",
343 static int __init
cumanascsi_init(void)
345 return ecard_register_driver(&cumanascsi1_driver
);
348 static void __exit
cumanascsi_exit(void)
350 ecard_remove_driver(&cumanascsi1_driver
);
353 module_init(cumanascsi_init
);
354 module_exit(cumanascsi_exit
);
356 MODULE_DESCRIPTION("Cumana SCSI-1 driver for Acorn machines");
357 MODULE_LICENSE("GPL");