2 * Generic Generic NCR5380 driver
4 * Copyright 1995-2002, Russell King
6 #include <linux/module.h>
7 #include <linux/signal.h>
8 #include <linux/ioport.h>
9 #include <linux/delay.h>
10 #include <linux/blkdev.h>
11 #include <linux/init.h>
13 #include <asm/ecard.h>
15 #include <asm/system.h>
18 #include <scsi/scsi_host.h>
20 #include <scsi/scsicam.h>
25 #define CUMANASCSI_PUBLIC_RELEASE 1
27 #define NCR5380_implementation_fields int port, ctrl
28 #define NCR5380_local_declare() struct Scsi_Host *_instance
29 #define NCR5380_setup(instance) _instance = instance
30 #define NCR5380_read(reg) cumanascsi_read(_instance, reg)
31 #define NCR5380_write(reg, value) cumanascsi_write(_instance, reg, value)
32 #define NCR5380_intr cumanascsi_intr
33 #define NCR5380_queue_command cumanascsi_queue_command
34 #define NCR5380_proc_info cumanascsi_proc_info
36 #define BOARD_NORMAL 0
37 #define BOARD_NCR53C400 1
39 #include "../NCR5380.h"
41 void cumanascsi_setup(char *str, int *ints)
45 const char *cumanascsi_info(struct Scsi_Host *spnt)
51 #define CTRL(p,v) outb(*ctrl = (v), (p) - 577)
52 #define STAT(p) inb((p)+1)
53 #define IN(p) inb((p))
54 #define OUT(v,p) outb((v), (p))
56 #define CTRL(p,v) (p[-2308] = (*ctrl = (v)))
57 #define STAT(p) (p[4])
59 #define IN2(p) ((unsigned short)(*(volatile unsigned long *)(p)))
60 #define OUT(v,p) (*(p) = (v))
61 #define OUT2(v,p) (*((volatile unsigned long *)(p)) = (v))
63 #define L(v) (((v)<<16)|((v) & 0x0000ffff))
64 #define H(v) (((v)>>16)|((v) & 0xffff0000))
67 NCR5380_pwrite(struct Scsi_Host *instance, unsigned char *addr, int len)
69 int *ctrl = &((struct NCR5380_hostdata *)instance->hostdata)->ctrl;
73 int iobase = instance->io_port;
74 int dma_io = iobase & ~(0x3C0000>>2);
76 volatile unsigned char *iobase = (unsigned char *)ioaddr(instance->io_port);
77 volatile unsigned char *dma_io = (unsigned char *)((int)iobase & ~0x3C0000);
83 laddr = (unsigned long *)addr;
88 status = STAT(iobase);
93 v=*laddr++; OUT2(L(v),dma_io); OUT2(H(v),dma_io);
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);
106 addr = (unsigned char *)laddr;
111 status = STAT(iobase);
116 OUT(*addr++, dma_io);
121 status = STAT(iobase);
126 OUT(*addr++, dma_io);
132 CTRL(iobase, oldctrl|0x40);
137 NCR5380_pread(struct Scsi_Host *instance, unsigned char *addr, int len)
139 int *ctrl = &((struct NCR5380_hostdata *)instance->hostdata)->ctrl;
141 unsigned long *laddr;
143 int iobase = instance->io_port;
144 int dma_io = iobase & ~(0x3C0000>>2);
146 volatile unsigned char *iobase = (unsigned char *)ioaddr(instance->io_port);
147 volatile unsigned char *dma_io = (unsigned char *)((int)iobase & ~0x3C0000);
153 laddr = (unsigned long *)addr;
157 status = STAT(iobase);
162 *laddr++ = IN2(dma_io)|(IN2(dma_io)<<16);
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);
175 addr = (unsigned char *)laddr;
180 status = STAT(iobase);
185 *addr++ = IN(dma_io);
190 status = STAT(iobase);
195 *addr++ = IN(dma_io);
201 CTRL(iobase, oldctrl|0x40);
210 #define CTRL(p,v) outb(*ctrl = (v), (p) - 577)
212 static char cumanascsi_read(struct Scsi_Host *instance, int reg)
214 unsigned int iobase = instance->io_port;
216 int *ctrl = &((struct NCR5380_hostdata *)instance->hostdata)->ctrl;
219 i = inb(iobase + 64 + reg);
225 static void cumanascsi_write(struct Scsi_Host *instance, int reg, int value)
227 int iobase = instance->io_port;
228 int *ctrl = &((struct NCR5380_hostdata *)instance->hostdata)->ctrl;
231 outb(value, iobase + 64 + reg);
237 #include "../NCR5380.c"
239 static struct scsi_host_template cumanascsi_template = {
240 .module = THIS_MODULE,
241 .name = "Cumana 16-bit SCSI",
242 .info = cumanascsi_info,
243 .queuecommand = cumanascsi_queue_command,
244 .eh_abort_handler = NCR5380_abort,
245 .eh_bus_reset_handler = NCR5380_bus_reset,
248 .sg_tablesize = SG_ALL,
250 .unchecked_isa_dma = 0,
251 .use_clustering = DISABLE_CLUSTERING,
252 .proc_name = "CumanaSCSI-1",
256 cumanascsi1_probe(struct expansion_card *ec, const struct ecard_id *id)
258 struct Scsi_Host *host;
261 host = scsi_host_alloc(&cumanascsi_template, sizeof(struct NCR5380_hostdata));
265 host->io_port = ecard_address(ec, ECARD_IOC, ECARD_SLOW) + 0x800;
268 NCR5380_init(host, 0);
270 host->n_io_port = 255;
271 if (!(request_region(host->io_port, host->n_io_port, "CumanaSCSI-1"))) {
276 ((struct NCR5380_hostdata *)host->hostdata)->ctrl = 0;
277 outb(0x00, host->io_port - 577);
279 ret = request_irq(host->irq, cumanascsi_intr, IRQF_DISABLED,
280 "CumanaSCSI-1", host);
282 printk("scsi%d: IRQ%d not free: %d\n",
283 host->host_no, host->irq, ret);
287 printk("scsi%d: at port 0x%08lx irq %d",
288 host->host_no, host->io_port, host->irq);
289 printk(" options CAN_QUEUE=%d CMD_PER_LUN=%d release=%d",
290 host->can_queue, host->cmd_per_lun, CUMANASCSI_PUBLIC_RELEASE);
291 printk("\nscsi%d:", host->host_no);
292 NCR5380_print_options(host);
295 ret = scsi_add_host(host, &ec->dev);
299 scsi_scan_host(host);
303 free_irq(host->irq, host);
305 release_region(host->io_port, host->n_io_port);
312 static void __devexit cumanascsi1_remove(struct expansion_card *ec)
314 struct Scsi_Host *host = ecard_get_drvdata(ec);
316 ecard_set_drvdata(ec, NULL);
318 scsi_remove_host(host);
319 free_irq(host->irq, host);
321 release_region(host->io_port, host->n_io_port);
325 static const struct ecard_id cumanascsi1_cids[] = {
326 { MANU_CUMANA, PROD_CUMANA_SCSI_1 },
330 static struct ecard_driver cumanascsi1_driver = {
331 .probe = cumanascsi1_probe,
332 .remove = __devexit_p(cumanascsi1_remove),
333 .id_table = cumanascsi1_cids,
335 .name = "cumanascsi1",
339 static int __init cumanascsi_init(void)
341 return ecard_register_driver(&cumanascsi1_driver);
344 static void __exit cumanascsi_exit(void)
346 ecard_remove_driver(&cumanascsi1_driver);
349 module_init(cumanascsi_init);
350 module_exit(cumanascsi_exit);
352 MODULE_DESCRIPTION("Cumana SCSI-1 driver for Acorn machines");
353 MODULE_LICENSE("GPL");