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 struct 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_bus_reset_handler = NCR5380_bus_reset,
250 .sg_tablesize = SG_ALL,
252 .unchecked_isa_dma = 0,
253 .use_clustering = DISABLE_CLUSTERING,
254 .proc_name = "CumanaSCSI-1",
258 cumanascsi1_probe(struct expansion_card *ec, const struct ecard_id *id)
260 struct Scsi_Host *host;
263 host = scsi_host_alloc(&cumanascsi_template, sizeof(struct NCR5380_hostdata));
267 host->io_port = ecard_address(ec, ECARD_IOC, ECARD_SLOW) + 0x800;
270 NCR5380_init(host, 0);
272 host->n_io_port = 255;
273 if (!(request_region(host->io_port, host->n_io_port, "CumanaSCSI-1"))) {
278 ((struct NCR5380_hostdata *)host->hostdata)->ctrl = 0;
279 outb(0x00, host->io_port - 577);
281 ret = request_irq(host->irq, cumanascsi_intr, SA_INTERRUPT,
282 "CumanaSCSI-1", host);
284 printk("scsi%d: IRQ%d not free: %d\n",
285 host->host_no, host->irq, ret);
289 printk("scsi%d: at port 0x%08lx irq %d",
290 host->host_no, host->io_port, host->irq);
291 printk(" options CAN_QUEUE=%d CMD_PER_LUN=%d release=%d",
292 host->can_queue, host->cmd_per_lun, CUMANASCSI_PUBLIC_RELEASE);
293 printk("\nscsi%d:", host->host_no);
294 NCR5380_print_options(host);
297 ret = scsi_add_host(host, &ec->dev);
301 scsi_scan_host(host);
305 free_irq(host->irq, host);
307 release_region(host->io_port, host->n_io_port);
314 static void __devexit cumanascsi1_remove(struct expansion_card *ec)
316 struct Scsi_Host *host = ecard_get_drvdata(ec);
318 ecard_set_drvdata(ec, NULL);
320 scsi_remove_host(host);
321 free_irq(host->irq, host);
323 release_region(host->io_port, host->n_io_port);
327 static const struct ecard_id cumanascsi1_cids[] = {
328 { MANU_CUMANA, PROD_CUMANA_SCSI_1 },
332 static struct ecard_driver cumanascsi1_driver = {
333 .probe = cumanascsi1_probe,
334 .remove = __devexit_p(cumanascsi1_remove),
335 .id_table = cumanascsi1_cids,
337 .name = "cumanascsi1",
341 static int __init cumanascsi_init(void)
343 return ecard_register_driver(&cumanascsi1_driver);
346 static void __exit cumanascsi_exit(void)
348 ecard_remove_driver(&cumanascsi1_driver);
351 module_init(cumanascsi_init);
352 module_exit(cumanascsi_exit);
354 MODULE_DESCRIPTION("Cumana SCSI-1 driver for Acorn machines");
355 MODULE_LICENSE("GPL");