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_local_declare() struct Scsi_Host *_instance
24 #define NCR5380_setup(instance) _instance = instance
25 #define NCR5380_read(reg) cumanascsi_read(_instance, reg)
26 #define NCR5380_write(reg, value) cumanascsi_write(_instance, reg, value)
27 #define NCR5380_intr cumanascsi_intr
28 #define NCR5380_queue_command cumanascsi_queue_command
29 #define NCR5380_info cumanascsi_info
31 #define NCR5380_implementation_fields \
36 #include "../NCR5380.h"
38 void cumanascsi_setup(char *str
, int *ints
)
44 #define L(v) (((v)<<16)|((v) & 0x0000ffff))
45 #define H(v) (((v)>>16)|((v) & 0xffff0000))
48 NCR5380_pwrite(struct Scsi_Host
*host
, unsigned char *addr
, int len
)
51 void __iomem
*dma
= priv(host
)->dma
+ 0x2000;
55 writeb(0x02, priv(host
)->base
+ CTRL
);
56 laddr
= (unsigned long *)addr
;
61 status
= readb(priv(host
)->base
+ STAT
);
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
);
72 v
=*laddr
++; writew(L(v
), dma
); writew(H(v
), dma
);
73 v
=*laddr
++; writew(L(v
), dma
); writew(H(v
), dma
);
79 addr
= (unsigned char *)laddr
;
80 writeb(0x12, priv(host
)->base
+ CTRL
);
85 status
= readb(priv(host
)->base
+ STAT
);
95 status
= readb(priv(host
)->base
+ STAT
);
100 writeb(*addr
++, dma
);
106 writeb(priv(host
)->ctrl
| 0x40, priv(host
)->base
+ CTRL
);
111 NCR5380_pread(struct Scsi_Host
*host
, unsigned char *addr
, int len
)
113 unsigned long *laddr
;
114 void __iomem
*dma
= priv(host
)->dma
+ 0x2000;
118 writeb(0x00, priv(host
)->base
+ CTRL
);
119 laddr
= (unsigned long *)addr
;
123 status
= readb(priv(host
)->base
+ STAT
);
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);
134 *laddr
++ = readw(dma
) | (readw(dma
) << 16);
135 *laddr
++ = readw(dma
) | (readw(dma
) << 16);
141 addr
= (unsigned char *)laddr
;
142 writeb(0x10, priv(host
)->base
+ CTRL
);
147 status
= readb(priv(host
)->base
+ STAT
);
152 *addr
++ = readb(dma
);
157 status
= readb(priv(host
)->base
+ STAT
);
162 *addr
++ = readb(dma
);
168 writeb(priv(host
)->ctrl
| 0x40, priv(host
)->base
+ CTRL
);
172 static unsigned char cumanascsi_read(struct Scsi_Host
*host
, unsigned int reg
)
174 void __iomem
*base
= priv(host
)->base
;
177 writeb(0, base
+ CTRL
);
179 val
= readb(base
+ 0x2100 + (reg
<< 2));
181 priv(host
)->ctrl
= 0x40;
182 writeb(0x40, base
+ CTRL
);
187 static void cumanascsi_write(struct Scsi_Host
*host
, unsigned int reg
, unsigned int value
)
189 void __iomem
*base
= priv(host
)->base
;
191 writeb(0, base
+ CTRL
);
193 writeb(value
, base
+ 0x2100 + (reg
<< 2));
195 priv(host
)->ctrl
= 0x40;
196 writeb(0x40, base
+ CTRL
);
199 #include "../NCR5380.c"
201 static struct scsi_host_template cumanascsi_template
= {
202 .module
= THIS_MODULE
,
203 .name
= "Cumana 16-bit SCSI",
204 .info
= cumanascsi_info
,
205 .queuecommand
= cumanascsi_queue_command
,
206 .eh_abort_handler
= NCR5380_abort
,
207 .eh_bus_reset_handler
= NCR5380_bus_reset
,
210 .sg_tablesize
= SG_ALL
,
212 .use_clustering
= DISABLE_CLUSTERING
,
213 .proc_name
= "CumanaSCSI-1",
216 static int cumanascsi1_probe(struct expansion_card
*ec
,
217 const struct ecard_id
*id
)
219 struct Scsi_Host
*host
;
222 ret
= ecard_request_resources(ec
);
226 host
= scsi_host_alloc(&cumanascsi_template
, sizeof(struct NCR5380_hostdata
));
232 priv(host
)->base
= ioremap(ecard_resource_start(ec
, ECARD_RES_IOCSLOW
),
233 ecard_resource_len(ec
, ECARD_RES_IOCSLOW
));
234 priv(host
)->dma
= ioremap(ecard_resource_start(ec
, ECARD_RES_MEMC
),
235 ecard_resource_len(ec
, ECARD_RES_MEMC
));
236 if (!priv(host
)->base
|| !priv(host
)->dma
) {
243 NCR5380_init(host
, 0);
245 priv(host
)->ctrl
= 0;
246 writeb(0, priv(host
)->base
+ CTRL
);
248 host
->n_io_port
= 255;
249 if (!(request_region(host
->io_port
, host
->n_io_port
, "CumanaSCSI-1"))) {
254 ret
= request_irq(host
->irq
, cumanascsi_intr
, 0,
255 "CumanaSCSI-1", host
);
257 printk("scsi%d: IRQ%d not free: %d\n",
258 host
->host_no
, host
->irq
, ret
);
262 ret
= scsi_add_host(host
, &ec
->dev
);
266 scsi_scan_host(host
);
270 free_irq(host
->irq
, host
);
272 iounmap(priv(host
)->base
);
273 iounmap(priv(host
)->dma
);
276 ecard_release_resources(ec
);
281 static void cumanascsi1_remove(struct expansion_card
*ec
)
283 struct Scsi_Host
*host
= ecard_get_drvdata(ec
);
285 ecard_set_drvdata(ec
, NULL
);
287 scsi_remove_host(host
);
288 free_irq(host
->irq
, host
);
290 iounmap(priv(host
)->base
);
291 iounmap(priv(host
)->dma
);
293 ecard_release_resources(ec
);
296 static const struct ecard_id cumanascsi1_cids
[] = {
297 { MANU_CUMANA
, PROD_CUMANA_SCSI_1
},
301 static struct ecard_driver cumanascsi1_driver
= {
302 .probe
= cumanascsi1_probe
,
303 .remove
= cumanascsi1_remove
,
304 .id_table
= cumanascsi1_cids
,
306 .name
= "cumanascsi1",
310 static int __init
cumanascsi_init(void)
312 return ecard_register_driver(&cumanascsi1_driver
);
315 static void __exit
cumanascsi_exit(void)
317 ecard_remove_driver(&cumanascsi1_driver
);
320 module_init(cumanascsi_init
);
321 module_exit(cumanascsi_exit
);
323 MODULE_DESCRIPTION("Cumana SCSI-1 driver for Acorn machines");
324 MODULE_LICENSE("GPL");