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>
16 #include <scsi/scsi_host.h>
18 #include <scsi/scsicam.h>
22 #define priv(host) ((struct NCR5380_hostdata *)(host)->hostdata)
23 #define NCR5380_read(reg) cumanascsi_read(instance, reg)
24 #define NCR5380_write(reg, value) cumanascsi_write(instance, reg, value)
25 #define NCR5380_intr cumanascsi_intr
26 #define NCR5380_queue_command cumanascsi_queue_command
27 #define NCR5380_info cumanascsi_info
29 #define NCR5380_implementation_fields \
34 #include "../NCR5380.h"
36 void cumanascsi_setup(char *str, int *ints)
42 #define L(v) (((v)<<16)|((v) & 0x0000ffff))
43 #define H(v) (((v)>>16)|((v) & 0xffff0000))
46 NCR5380_pwrite(struct Scsi_Host *host, unsigned char *addr, int len)
49 void __iomem *dma = priv(host)->dma + 0x2000;
53 writeb(0x02, priv(host)->base + CTRL);
54 laddr = (unsigned long *)addr;
59 status = readb(priv(host)->base + STAT);
64 v=*laddr++; writew(L(v), dma); writew(H(v), dma);
65 v=*laddr++; writew(L(v), dma); writew(H(v), dma);
66 v=*laddr++; writew(L(v), dma); writew(H(v), dma);
67 v=*laddr++; writew(L(v), dma); writew(H(v), dma);
68 v=*laddr++; writew(L(v), dma); writew(H(v), dma);
69 v=*laddr++; writew(L(v), dma); writew(H(v), dma);
70 v=*laddr++; writew(L(v), dma); writew(H(v), dma);
71 v=*laddr++; writew(L(v), dma); writew(H(v), dma);
77 addr = (unsigned char *)laddr;
78 writeb(0x12, priv(host)->base + CTRL);
83 status = readb(priv(host)->base + STAT);
93 status = readb(priv(host)->base + STAT);
104 writeb(priv(host)->ctrl | 0x40, priv(host)->base + CTRL);
109 NCR5380_pread(struct Scsi_Host *host, unsigned char *addr, int len)
111 unsigned long *laddr;
112 void __iomem *dma = priv(host)->dma + 0x2000;
116 writeb(0x00, priv(host)->base + CTRL);
117 laddr = (unsigned long *)addr;
121 status = readb(priv(host)->base + STAT);
126 *laddr++ = readw(dma) | (readw(dma) << 16);
127 *laddr++ = readw(dma) | (readw(dma) << 16);
128 *laddr++ = readw(dma) | (readw(dma) << 16);
129 *laddr++ = readw(dma) | (readw(dma) << 16);
130 *laddr++ = readw(dma) | (readw(dma) << 16);
131 *laddr++ = readw(dma) | (readw(dma) << 16);
132 *laddr++ = readw(dma) | (readw(dma) << 16);
133 *laddr++ = readw(dma) | (readw(dma) << 16);
139 addr = (unsigned char *)laddr;
140 writeb(0x10, priv(host)->base + CTRL);
145 status = readb(priv(host)->base + STAT);
150 *addr++ = readb(dma);
155 status = readb(priv(host)->base + STAT);
160 *addr++ = readb(dma);
166 writeb(priv(host)->ctrl | 0x40, priv(host)->base + CTRL);
170 static unsigned char cumanascsi_read(struct Scsi_Host *host, unsigned int reg)
172 void __iomem *base = priv(host)->base;
175 writeb(0, base + CTRL);
177 val = readb(base + 0x2100 + (reg << 2));
179 priv(host)->ctrl = 0x40;
180 writeb(0x40, base + CTRL);
185 static void cumanascsi_write(struct Scsi_Host *host, unsigned int reg, unsigned int value)
187 void __iomem *base = priv(host)->base;
189 writeb(0, base + CTRL);
191 writeb(value, base + 0x2100 + (reg << 2));
193 priv(host)->ctrl = 0x40;
194 writeb(0x40, base + CTRL);
197 #include "../NCR5380.c"
199 static struct scsi_host_template cumanascsi_template = {
200 .module = THIS_MODULE,
201 .name = "Cumana 16-bit SCSI",
202 .info = cumanascsi_info,
203 .queuecommand = cumanascsi_queue_command,
204 .eh_abort_handler = NCR5380_abort,
205 .eh_bus_reset_handler = NCR5380_bus_reset,
208 .sg_tablesize = SG_ALL,
210 .use_clustering = DISABLE_CLUSTERING,
211 .proc_name = "CumanaSCSI-1",
214 static int cumanascsi1_probe(struct expansion_card *ec,
215 const struct ecard_id *id)
217 struct Scsi_Host *host;
220 ret = ecard_request_resources(ec);
224 host = scsi_host_alloc(&cumanascsi_template, sizeof(struct NCR5380_hostdata));
230 priv(host)->base = ioremap(ecard_resource_start(ec, ECARD_RES_IOCSLOW),
231 ecard_resource_len(ec, ECARD_RES_IOCSLOW));
232 priv(host)->dma = ioremap(ecard_resource_start(ec, ECARD_RES_MEMC),
233 ecard_resource_len(ec, ECARD_RES_MEMC));
234 if (!priv(host)->base || !priv(host)->dma) {
241 ret = NCR5380_init(host, 0);
245 NCR5380_maybe_reset_bus(host);
247 priv(host)->ctrl = 0;
248 writeb(0, priv(host)->base + CTRL);
250 ret = request_irq(host->irq, cumanascsi_intr, 0,
251 "CumanaSCSI-1", host);
253 printk("scsi%d: IRQ%d not free: %d\n",
254 host->host_no, host->irq, ret);
258 ret = scsi_add_host(host, &ec->dev);
262 scsi_scan_host(host);
266 free_irq(host->irq, host);
270 iounmap(priv(host)->base);
271 iounmap(priv(host)->dma);
274 ecard_release_resources(ec);
279 static void cumanascsi1_remove(struct expansion_card *ec)
281 struct Scsi_Host *host = ecard_get_drvdata(ec);
283 ecard_set_drvdata(ec, NULL);
285 scsi_remove_host(host);
286 free_irq(host->irq, host);
288 iounmap(priv(host)->base);
289 iounmap(priv(host)->dma);
291 ecard_release_resources(ec);
294 static const struct ecard_id cumanascsi1_cids[] = {
295 { MANU_CUMANA, PROD_CUMANA_SCSI_1 },
299 static struct ecard_driver cumanascsi1_driver = {
300 .probe = cumanascsi1_probe,
301 .remove = cumanascsi1_remove,
302 .id_table = cumanascsi1_cids,
304 .name = "cumanascsi1",
308 static int __init cumanascsi_init(void)
310 return ecard_register_driver(&cumanascsi1_driver);
313 static void __exit cumanascsi_exit(void)
315 ecard_remove_driver(&cumanascsi1_driver);
318 module_init(cumanascsi_init);
319 module_exit(cumanascsi_exit);
321 MODULE_DESCRIPTION("Cumana SCSI-1 driver for Acorn machines");
322 MODULE_LICENSE("GPL");