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 priv(host) ((struct NCR5380_hostdata *)(host)->hostdata)
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 NCR5380_implementation_fields \
41 #define BOARD_NORMAL 0
42 #define BOARD_NCR53C400 1
44 #include "../NCR5380.h"
46 void cumanascsi_setup(char *str
, int *ints
)
50 const char *cumanascsi_info(struct Scsi_Host
*spnt
)
57 #define L(v) (((v)<<16)|((v) & 0x0000ffff))
58 #define H(v) (((v)>>16)|((v) & 0xffff0000))
61 NCR5380_pwrite(struct Scsi_Host
*host
, unsigned char *addr
, int len
)
64 void __iomem
*dma
= priv(host
)->dma
+ 0x2000;
68 writeb(0x02, priv(host
)->base
+ CTRL
);
69 laddr
= (unsigned long *)addr
;
74 status
= readb(priv(host
)->base
+ STAT
);
79 v
=*laddr
++; writew(L(v
), dma
); writew(H(v
), dma
);
80 v
=*laddr
++; writew(L(v
), dma
); writew(H(v
), dma
);
81 v
=*laddr
++; writew(L(v
), dma
); writew(H(v
), dma
);
82 v
=*laddr
++; writew(L(v
), dma
); writew(H(v
), dma
);
83 v
=*laddr
++; writew(L(v
), dma
); writew(H(v
), dma
);
84 v
=*laddr
++; writew(L(v
), dma
); writew(H(v
), dma
);
85 v
=*laddr
++; writew(L(v
), dma
); writew(H(v
), dma
);
86 v
=*laddr
++; writew(L(v
), dma
); writew(H(v
), dma
);
92 addr
= (unsigned char *)laddr
;
93 writeb(0x12, priv(host
)->base
+ CTRL
);
98 status
= readb(priv(host
)->base
+ STAT
);
103 writeb(*addr
++, dma
);
108 status
= readb(priv(host
)->base
+ STAT
);
113 writeb(*addr
++, dma
);
119 writeb(priv(host
)->ctrl
| 0x40, priv(host
)->base
+ CTRL
);
124 NCR5380_pread(struct Scsi_Host
*host
, unsigned char *addr
, int len
)
126 unsigned long *laddr
;
127 void __iomem
*dma
= priv(host
)->dma
+ 0x2000;
131 writeb(0x00, priv(host
)->base
+ CTRL
);
132 laddr
= (unsigned long *)addr
;
136 status
= readb(priv(host
)->base
+ STAT
);
141 *laddr
++ = readw(dma
) | (readw(dma
) << 16);
142 *laddr
++ = readw(dma
) | (readw(dma
) << 16);
143 *laddr
++ = readw(dma
) | (readw(dma
) << 16);
144 *laddr
++ = readw(dma
) | (readw(dma
) << 16);
145 *laddr
++ = readw(dma
) | (readw(dma
) << 16);
146 *laddr
++ = readw(dma
) | (readw(dma
) << 16);
147 *laddr
++ = readw(dma
) | (readw(dma
) << 16);
148 *laddr
++ = readw(dma
) | (readw(dma
) << 16);
154 addr
= (unsigned char *)laddr
;
155 writeb(0x10, priv(host
)->base
+ CTRL
);
160 status
= readb(priv(host
)->base
+ STAT
);
165 *addr
++ = readb(dma
);
170 status
= readb(priv(host
)->base
+ STAT
);
175 *addr
++ = readb(dma
);
181 writeb(priv(host
)->ctrl
| 0x40, priv(host
)->base
+ CTRL
);
185 static unsigned char cumanascsi_read(struct Scsi_Host
*host
, unsigned int reg
)
187 void __iomem
*base
= priv(host
)->base
;
190 writeb(0, base
+ CTRL
);
192 val
= readb(base
+ 0x2100 + (reg
<< 2));
194 priv(host
)->ctrl
= 0x40;
195 writeb(0x40, base
+ CTRL
);
200 static void cumanascsi_write(struct Scsi_Host
*host
, unsigned int reg
, unsigned int value
)
202 void __iomem
*base
= priv(host
)->base
;
204 writeb(0, base
+ CTRL
);
206 writeb(value
, base
+ 0x2100 + (reg
<< 2));
208 priv(host
)->ctrl
= 0x40;
209 writeb(0x40, base
+ CTRL
);
212 #include "../NCR5380.c"
214 static struct scsi_host_template cumanascsi_template
= {
215 .module
= THIS_MODULE
,
216 .name
= "Cumana 16-bit SCSI",
217 .info
= cumanascsi_info
,
218 .queuecommand
= cumanascsi_queue_command
,
219 .eh_abort_handler
= NCR5380_abort
,
220 .eh_bus_reset_handler
= NCR5380_bus_reset
,
223 .sg_tablesize
= SG_ALL
,
225 .unchecked_isa_dma
= 0,
226 .use_clustering
= DISABLE_CLUSTERING
,
227 .proc_name
= "CumanaSCSI-1",
231 cumanascsi1_probe(struct expansion_card
*ec
, const struct ecard_id
*id
)
233 struct Scsi_Host
*host
;
236 ret
= ecard_request_resources(ec
);
240 host
= scsi_host_alloc(&cumanascsi_template
, sizeof(struct NCR5380_hostdata
));
246 priv(host
)->base
= ioremap(ecard_resource_start(ec
, ECARD_RES_IOCSLOW
),
247 ecard_resource_len(ec
, ECARD_RES_IOCSLOW
));
248 priv(host
)->dma
= ioremap(ecard_resource_start(ec
, ECARD_RES_MEMC
),
249 ecard_resource_len(ec
, ECARD_RES_MEMC
));
250 if (!priv(host
)->base
|| !priv(host
)->dma
) {
257 NCR5380_init(host
, 0);
259 priv(host
)->ctrl
= 0;
260 writeb(0, priv(host
)->base
+ CTRL
);
262 host
->n_io_port
= 255;
263 if (!(request_region(host
->io_port
, host
->n_io_port
, "CumanaSCSI-1"))) {
268 ret
= request_irq(host
->irq
, cumanascsi_intr
, IRQF_DISABLED
,
269 "CumanaSCSI-1", host
);
271 printk("scsi%d: IRQ%d not free: %d\n",
272 host
->host_no
, host
->irq
, ret
);
276 printk("scsi%d: at port 0x%08lx irq %d",
277 host
->host_no
, host
->io_port
, host
->irq
);
278 printk(" options CAN_QUEUE=%d CMD_PER_LUN=%d release=%d",
279 host
->can_queue
, host
->cmd_per_lun
, CUMANASCSI_PUBLIC_RELEASE
);
280 printk("\nscsi%d:", host
->host_no
);
281 NCR5380_print_options(host
);
284 ret
= scsi_add_host(host
, &ec
->dev
);
288 scsi_scan_host(host
);
292 free_irq(host
->irq
, host
);
294 iounmap(priv(host
)->base
);
295 iounmap(priv(host
)->dma
);
298 ecard_release_resources(ec
);
303 static void __devexit
cumanascsi1_remove(struct expansion_card
*ec
)
305 struct Scsi_Host
*host
= ecard_get_drvdata(ec
);
307 ecard_set_drvdata(ec
, NULL
);
309 scsi_remove_host(host
);
310 free_irq(host
->irq
, host
);
312 iounmap(priv(host
)->base
);
313 iounmap(priv(host
)->dma
);
315 ecard_release_resources(ec
);
318 static const struct ecard_id cumanascsi1_cids
[] = {
319 { MANU_CUMANA
, PROD_CUMANA_SCSI_1
},
323 static struct ecard_driver cumanascsi1_driver
= {
324 .probe
= cumanascsi1_probe
,
325 .remove
= __devexit_p(cumanascsi1_remove
),
326 .id_table
= cumanascsi1_cids
,
328 .name
= "cumanascsi1",
332 static int __init
cumanascsi_init(void)
334 return ecard_register_driver(&cumanascsi1_driver
);
337 static void __exit
cumanascsi_exit(void)
339 ecard_remove_driver(&cumanascsi1_driver
);
342 module_init(cumanascsi_init
);
343 module_exit(cumanascsi_exit
);
345 MODULE_DESCRIPTION("Cumana SCSI-1 driver for Acorn machines");
346 MODULE_LICENSE("GPL");