2 * Generic Generic NCR5380 driver
4 * Copyright 1995-2002, Russell King
6 #include <linux/module.h>
7 #include <linux/ioport.h>
8 #include <linux/blkdev.h>
9 #include <linux/init.h>
11 #include <asm/ecard.h>
14 #include <scsi/scsi_host.h>
16 #define priv(host) ((struct NCR5380_hostdata *)(host)->hostdata)
17 #define NCR5380_read(reg) cumanascsi_read(instance, reg)
18 #define NCR5380_write(reg, value) cumanascsi_write(instance, reg, value)
20 #define NCR5380_dma_xfer_len(instance, cmd, phase) (cmd->transfersize)
21 #define NCR5380_dma_recv_setup cumanascsi_pread
22 #define NCR5380_dma_send_setup cumanascsi_pwrite
23 #define NCR5380_dma_residual(instance) (0)
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))
45 static inline int cumanascsi_pwrite(struct Scsi_Host *host,
46 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);
111 static inline int cumanascsi_pread(struct Scsi_Host *host,
112 unsigned char *addr, int len)
114 unsigned long *laddr;
115 void __iomem *dma = priv(host)->dma + 0x2000;
119 writeb(0x00, priv(host)->base + CTRL);
120 laddr = (unsigned long *)addr;
124 status = readb(priv(host)->base + STAT);
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);
134 *laddr++ = readw(dma) | (readw(dma) << 16);
135 *laddr++ = readw(dma) | (readw(dma) << 16);
136 *laddr++ = readw(dma) | (readw(dma) << 16);
142 addr = (unsigned char *)laddr;
143 writeb(0x10, priv(host)->base + CTRL);
148 status = readb(priv(host)->base + STAT);
153 *addr++ = readb(dma);
158 status = readb(priv(host)->base + STAT);
163 *addr++ = readb(dma);
169 writeb(priv(host)->ctrl | 0x40, priv(host)->base + CTRL);
176 static unsigned char cumanascsi_read(struct Scsi_Host *host, unsigned int reg)
178 void __iomem *base = priv(host)->base;
181 writeb(0, base + CTRL);
183 val = readb(base + 0x2100 + (reg << 2));
185 priv(host)->ctrl = 0x40;
186 writeb(0x40, base + CTRL);
191 static void cumanascsi_write(struct Scsi_Host *host, unsigned int reg, unsigned int value)
193 void __iomem *base = priv(host)->base;
195 writeb(0, base + CTRL);
197 writeb(value, base + 0x2100 + (reg << 2));
199 priv(host)->ctrl = 0x40;
200 writeb(0x40, base + CTRL);
203 #include "../NCR5380.c"
205 static struct scsi_host_template cumanascsi_template = {
206 .module = THIS_MODULE,
207 .name = "Cumana 16-bit SCSI",
208 .info = cumanascsi_info,
209 .queuecommand = cumanascsi_queue_command,
210 .eh_abort_handler = NCR5380_abort,
211 .eh_bus_reset_handler = NCR5380_bus_reset,
214 .sg_tablesize = SG_ALL,
216 .use_clustering = DISABLE_CLUSTERING,
217 .proc_name = "CumanaSCSI-1",
218 .cmd_size = NCR5380_CMD_SIZE,
222 static int cumanascsi1_probe(struct expansion_card *ec,
223 const struct ecard_id *id)
225 struct Scsi_Host *host;
228 ret = ecard_request_resources(ec);
232 host = scsi_host_alloc(&cumanascsi_template, sizeof(struct NCR5380_hostdata));
238 priv(host)->base = ioremap(ecard_resource_start(ec, ECARD_RES_IOCSLOW),
239 ecard_resource_len(ec, ECARD_RES_IOCSLOW));
240 priv(host)->dma = ioremap(ecard_resource_start(ec, ECARD_RES_MEMC),
241 ecard_resource_len(ec, ECARD_RES_MEMC));
242 if (!priv(host)->base || !priv(host)->dma) {
249 ret = NCR5380_init(host, FLAG_DMA_FIXUP | FLAG_LATE_DMA_SETUP);
253 NCR5380_maybe_reset_bus(host);
255 priv(host)->ctrl = 0;
256 writeb(0, priv(host)->base + CTRL);
258 ret = request_irq(host->irq, cumanascsi_intr, 0,
259 "CumanaSCSI-1", host);
261 printk("scsi%d: IRQ%d not free: %d\n",
262 host->host_no, host->irq, ret);
266 ret = scsi_add_host(host, &ec->dev);
270 scsi_scan_host(host);
274 free_irq(host->irq, host);
278 iounmap(priv(host)->base);
279 iounmap(priv(host)->dma);
282 ecard_release_resources(ec);
287 static void cumanascsi1_remove(struct expansion_card *ec)
289 struct Scsi_Host *host = ecard_get_drvdata(ec);
291 ecard_set_drvdata(ec, NULL);
293 scsi_remove_host(host);
294 free_irq(host->irq, host);
296 iounmap(priv(host)->base);
297 iounmap(priv(host)->dma);
299 ecard_release_resources(ec);
302 static const struct ecard_id cumanascsi1_cids[] = {
303 { MANU_CUMANA, PROD_CUMANA_SCSI_1 },
307 static struct ecard_driver cumanascsi1_driver = {
308 .probe = cumanascsi1_probe,
309 .remove = cumanascsi1_remove,
310 .id_table = cumanascsi1_cids,
312 .name = "cumanascsi1",
316 static int __init cumanascsi_init(void)
318 return ecard_register_driver(&cumanascsi1_driver);
321 static void __exit cumanascsi_exit(void)
323 ecard_remove_driver(&cumanascsi1_driver);
326 module_init(cumanascsi_init);
327 module_exit(cumanascsi_exit);
329 MODULE_DESCRIPTION("Cumana SCSI-1 driver for Acorn machines");
330 MODULE_LICENSE("GPL");