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>
16 #include <asm/system.h>
19 #include <scsi/scsi_host.h>
21 #include <scsi/scsicam.h>
26 #define CUMANASCSI_PUBLIC_RELEASE 1
28 #define NCR5380_implementation_fields int port, ctrl
29 #define NCR5380_local_declare() struct Scsi_Host *_instance
30 #define NCR5380_setup(instance) _instance = instance
31 #define NCR5380_read(reg) cumanascsi_read(_instance, reg)
32 #define NCR5380_write(reg, value) cumanascsi_write(_instance, reg, value)
33 #define NCR5380_intr cumanascsi_intr
34 #define NCR5380_queue_command cumanascsi_queue_command
35 #define NCR5380_proc_info cumanascsi_proc_info
37 #define BOARD_NORMAL 0
38 #define BOARD_NCR53C400 1
40 #include "../NCR5380.h"
42 void cumanascsi_setup(char *str
, int *ints
)
46 const char *cumanascsi_info(struct Scsi_Host
*spnt
)
52 #define CTRL(p,v) outb(*ctrl = (v), (p) - 577)
53 #define STAT(p) inb((p)+1)
54 #define IN(p) inb((p))
55 #define OUT(v,p) outb((v), (p))
57 #define CTRL(p,v) (p[-2308] = (*ctrl = (v)))
58 #define STAT(p) (p[4])
60 #define IN2(p) ((unsigned short)(*(volatile unsigned long *)(p)))
61 #define OUT(v,p) (*(p) = (v))
62 #define OUT2(v,p) (*((volatile unsigned long *)(p)) = (v))
64 #define L(v) (((v)<<16)|((v) & 0x0000ffff))
65 #define H(v) (((v)>>16)|((v) & 0xffff0000))
68 NCR5380_pwrite(struct Scsi_Host
*instance
, unsigned char *addr
, int len
)
70 int *ctrl
= &((struct NCR5380_hostdata
*)instance
->hostdata
)->ctrl
;
74 int iobase
= instance
->io_port
;
75 int dma_io
= iobase
& ~(0x3C0000>>2);
77 volatile unsigned char *iobase
= (unsigned char *)ioaddr(instance
->io_port
);
78 volatile unsigned char *dma_io
= (unsigned char *)((int)iobase
& ~0x3C0000);
84 laddr
= (unsigned long *)addr
;
89 status
= STAT(iobase
);
94 v
=*laddr
++; OUT2(L(v
),dma_io
); OUT2(H(v
),dma_io
);
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
);
107 addr
= (unsigned char *)laddr
;
112 status
= STAT(iobase
);
117 OUT(*addr
++, dma_io
);
122 status
= STAT(iobase
);
127 OUT(*addr
++, dma_io
);
133 CTRL(iobase
, oldctrl
|0x40);
138 NCR5380_pread(struct Scsi_Host
*instance
, unsigned char *addr
, int len
)
140 int *ctrl
= &((struct NCR5380_hostdata
*)instance
->hostdata
)->ctrl
;
142 unsigned long *laddr
;
144 int iobase
= instance
->io_port
;
145 int dma_io
= iobase
& ~(0x3C0000>>2);
147 volatile unsigned char *iobase
= (unsigned char *)ioaddr(instance
->io_port
);
148 volatile unsigned char *dma_io
= (unsigned char *)((int)iobase
& ~0x3C0000);
154 laddr
= (unsigned long *)addr
;
158 status
= STAT(iobase
);
163 *laddr
++ = IN2(dma_io
)|(IN2(dma_io
)<<16);
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);
176 addr
= (unsigned char *)laddr
;
181 status
= STAT(iobase
);
186 *addr
++ = IN(dma_io
);
191 status
= STAT(iobase
);
196 *addr
++ = IN(dma_io
);
202 CTRL(iobase
, oldctrl
|0x40);
211 #define CTRL(p,v) outb(*ctrl = (v), (p) - 577)
213 static char cumanascsi_read(struct Scsi_Host
*instance
, int reg
)
215 unsigned int iobase
= instance
->io_port
;
217 int *ctrl
= &((struct NCR5380_hostdata
*)instance
->hostdata
)->ctrl
;
220 i
= inb(iobase
+ 64 + reg
);
226 static void cumanascsi_write(struct Scsi_Host
*instance
, int reg
, int value
)
228 int iobase
= instance
->io_port
;
229 int *ctrl
= &((struct NCR5380_hostdata
*)instance
->hostdata
)->ctrl
;
232 outb(value
, iobase
+ 64 + reg
);
238 #include "../NCR5380.c"
240 static struct scsi_host_template cumanascsi_template
= {
241 .module
= THIS_MODULE
,
242 .name
= "Cumana 16-bit SCSI",
243 .info
= cumanascsi_info
,
244 .queuecommand
= cumanascsi_queue_command
,
245 .eh_abort_handler
= NCR5380_abort
,
246 .eh_bus_reset_handler
= NCR5380_bus_reset
,
249 .sg_tablesize
= SG_ALL
,
251 .unchecked_isa_dma
= 0,
252 .use_clustering
= DISABLE_CLUSTERING
,
253 .proc_name
= "CumanaSCSI-1",
257 cumanascsi1_probe(struct expansion_card
*ec
, const struct ecard_id
*id
)
259 struct Scsi_Host
*host
;
262 host
= scsi_host_alloc(&cumanascsi_template
, sizeof(struct NCR5380_hostdata
));
266 host
->io_port
= ecard_address(ec
, ECARD_IOC
, ECARD_SLOW
) + 0x800;
269 NCR5380_init(host
, 0);
271 host
->n_io_port
= 255;
272 if (!(request_region(host
->io_port
, host
->n_io_port
, "CumanaSCSI-1"))) {
277 ((struct NCR5380_hostdata
*)host
->hostdata
)->ctrl
= 0;
278 outb(0x00, host
->io_port
- 577);
280 ret
= request_irq(host
->irq
, cumanascsi_intr
, SA_INTERRUPT
,
281 "CumanaSCSI-1", host
);
283 printk("scsi%d: IRQ%d not free: %d\n",
284 host
->host_no
, host
->irq
, ret
);
288 printk("scsi%d: at port 0x%08lx irq %d",
289 host
->host_no
, host
->io_port
, host
->irq
);
290 printk(" options CAN_QUEUE=%d CMD_PER_LUN=%d release=%d",
291 host
->can_queue
, host
->cmd_per_lun
, CUMANASCSI_PUBLIC_RELEASE
);
292 printk("\nscsi%d:", host
->host_no
);
293 NCR5380_print_options(host
);
296 ret
= scsi_add_host(host
, &ec
->dev
);
300 scsi_scan_host(host
);
304 free_irq(host
->irq
, host
);
306 release_region(host
->io_port
, host
->n_io_port
);
313 static void __devexit
cumanascsi1_remove(struct expansion_card
*ec
)
315 struct Scsi_Host
*host
= ecard_get_drvdata(ec
);
317 ecard_set_drvdata(ec
, NULL
);
319 scsi_remove_host(host
);
320 free_irq(host
->irq
, host
);
322 release_region(host
->io_port
, host
->n_io_port
);
326 static const struct ecard_id cumanascsi1_cids
[] = {
327 { MANU_CUMANA
, PROD_CUMANA_SCSI_1
},
331 static struct ecard_driver cumanascsi1_driver
= {
332 .probe
= cumanascsi1_probe
,
333 .remove
= __devexit_p(cumanascsi1_remove
),
334 .id_table
= cumanascsi1_cids
,
336 .name
= "cumanascsi1",
340 static int __init
cumanascsi_init(void)
342 return ecard_register_driver(&cumanascsi1_driver
);
345 static void __exit
cumanascsi_exit(void)
347 ecard_remove_driver(&cumanascsi1_driver
);
350 module_init(cumanascsi_init
);
351 module_exit(cumanascsi_exit
);
353 MODULE_DESCRIPTION("Cumana SCSI-1 driver for Acorn machines");
354 MODULE_LICENSE("GPL");