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>
17 #include <scsi/scsi_host.h>
19 #include <scsi/scsicam.h>
24 #define CUMANASCSI_PUBLIC_RELEASE 1
26 #define priv(host) ((struct NCR5380_hostdata *)(host)->hostdata)
27 #define NCR5380_local_declare() struct Scsi_Host *_instance
28 #define NCR5380_setup(instance) _instance = instance
29 #define NCR5380_read(reg) cumanascsi_read(_instance, reg)
30 #define NCR5380_write(reg, value) cumanascsi_write(_instance, reg, value)
31 #define NCR5380_intr cumanascsi_intr
32 #define NCR5380_queue_command cumanascsi_queue_command
33 #define NCR5380_proc_info cumanascsi_proc_info
35 #define NCR5380_implementation_fields \
40 #define BOARD_NORMAL 0
41 #define BOARD_NCR53C400 1
43 #include "../NCR5380.h"
45 void cumanascsi_setup(char *str
, int *ints
)
49 const char *cumanascsi_info(struct Scsi_Host
*spnt
)
56 #define L(v) (((v)<<16)|((v) & 0x0000ffff))
57 #define H(v) (((v)>>16)|((v) & 0xffff0000))
60 NCR5380_pwrite(struct Scsi_Host
*host
, unsigned char *addr
, int len
)
63 void __iomem
*dma
= priv(host
)->dma
+ 0x2000;
67 writeb(0x02, priv(host
)->base
+ CTRL
);
68 laddr
= (unsigned long *)addr
;
73 status
= readb(priv(host
)->base
+ STAT
);
78 v
=*laddr
++; writew(L(v
), dma
); writew(H(v
), dma
);
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
);
91 addr
= (unsigned char *)laddr
;
92 writeb(0x12, priv(host
)->base
+ CTRL
);
97 status
= readb(priv(host
)->base
+ STAT
);
102 writeb(*addr
++, dma
);
107 status
= readb(priv(host
)->base
+ STAT
);
112 writeb(*addr
++, dma
);
118 writeb(priv(host
)->ctrl
| 0x40, priv(host
)->base
+ CTRL
);
123 NCR5380_pread(struct Scsi_Host
*host
, unsigned char *addr
, int len
)
125 unsigned long *laddr
;
126 void __iomem
*dma
= priv(host
)->dma
+ 0x2000;
130 writeb(0x00, priv(host
)->base
+ CTRL
);
131 laddr
= (unsigned long *)addr
;
135 status
= readb(priv(host
)->base
+ STAT
);
140 *laddr
++ = readw(dma
) | (readw(dma
) << 16);
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);
153 addr
= (unsigned char *)laddr
;
154 writeb(0x10, priv(host
)->base
+ CTRL
);
159 status
= readb(priv(host
)->base
+ STAT
);
164 *addr
++ = readb(dma
);
169 status
= readb(priv(host
)->base
+ STAT
);
174 *addr
++ = readb(dma
);
180 writeb(priv(host
)->ctrl
| 0x40, priv(host
)->base
+ CTRL
);
184 static unsigned char cumanascsi_read(struct Scsi_Host
*host
, unsigned int reg
)
186 void __iomem
*base
= priv(host
)->base
;
189 writeb(0, base
+ CTRL
);
191 val
= readb(base
+ 0x2100 + (reg
<< 2));
193 priv(host
)->ctrl
= 0x40;
194 writeb(0x40, base
+ CTRL
);
199 static void cumanascsi_write(struct Scsi_Host
*host
, unsigned int reg
, unsigned int value
)
201 void __iomem
*base
= priv(host
)->base
;
203 writeb(0, base
+ CTRL
);
205 writeb(value
, base
+ 0x2100 + (reg
<< 2));
207 priv(host
)->ctrl
= 0x40;
208 writeb(0x40, base
+ CTRL
);
211 #include "../NCR5380.c"
213 static struct scsi_host_template cumanascsi_template
= {
214 .module
= THIS_MODULE
,
215 .name
= "Cumana 16-bit SCSI",
216 .info
= cumanascsi_info
,
217 .queuecommand
= cumanascsi_queue_command
,
218 .eh_abort_handler
= NCR5380_abort
,
219 .eh_bus_reset_handler
= NCR5380_bus_reset
,
222 .sg_tablesize
= SG_ALL
,
224 .use_clustering
= DISABLE_CLUSTERING
,
225 .proc_name
= "CumanaSCSI-1",
229 cumanascsi1_probe(struct expansion_card
*ec
, const struct ecard_id
*id
)
231 struct Scsi_Host
*host
;
234 ret
= ecard_request_resources(ec
);
238 host
= scsi_host_alloc(&cumanascsi_template
, sizeof(struct NCR5380_hostdata
));
244 priv(host
)->base
= ioremap(ecard_resource_start(ec
, ECARD_RES_IOCSLOW
),
245 ecard_resource_len(ec
, ECARD_RES_IOCSLOW
));
246 priv(host
)->dma
= ioremap(ecard_resource_start(ec
, ECARD_RES_MEMC
),
247 ecard_resource_len(ec
, ECARD_RES_MEMC
));
248 if (!priv(host
)->base
|| !priv(host
)->dma
) {
255 NCR5380_init(host
, 0);
257 priv(host
)->ctrl
= 0;
258 writeb(0, priv(host
)->base
+ CTRL
);
260 host
->n_io_port
= 255;
261 if (!(request_region(host
->io_port
, host
->n_io_port
, "CumanaSCSI-1"))) {
266 ret
= request_irq(host
->irq
, cumanascsi_intr
, IRQF_DISABLED
,
267 "CumanaSCSI-1", host
);
269 printk("scsi%d: IRQ%d not free: %d\n",
270 host
->host_no
, host
->irq
, ret
);
274 printk("scsi%d: at port 0x%08lx irq %d",
275 host
->host_no
, host
->io_port
, host
->irq
);
276 printk(" options CAN_QUEUE=%d CMD_PER_LUN=%d release=%d",
277 host
->can_queue
, host
->cmd_per_lun
, CUMANASCSI_PUBLIC_RELEASE
);
278 printk("\nscsi%d:", host
->host_no
);
279 NCR5380_print_options(host
);
282 ret
= scsi_add_host(host
, &ec
->dev
);
286 scsi_scan_host(host
);
290 free_irq(host
->irq
, host
);
292 iounmap(priv(host
)->base
);
293 iounmap(priv(host
)->dma
);
296 ecard_release_resources(ec
);
301 static void __devexit
cumanascsi1_remove(struct expansion_card
*ec
)
303 struct Scsi_Host
*host
= ecard_get_drvdata(ec
);
305 ecard_set_drvdata(ec
, NULL
);
307 scsi_remove_host(host
);
308 free_irq(host
->irq
, host
);
310 iounmap(priv(host
)->base
);
311 iounmap(priv(host
)->dma
);
313 ecard_release_resources(ec
);
316 static const struct ecard_id cumanascsi1_cids
[] = {
317 { MANU_CUMANA
, PROD_CUMANA_SCSI_1
},
321 static struct ecard_driver cumanascsi1_driver
= {
322 .probe
= cumanascsi1_probe
,
323 .remove
= __devexit_p(cumanascsi1_remove
),
324 .id_table
= cumanascsi1_cids
,
326 .name
= "cumanascsi1",
330 static int __init
cumanascsi_init(void)
332 return ecard_register_driver(&cumanascsi1_driver
);
335 static void __exit
cumanascsi_exit(void)
337 ecard_remove_driver(&cumanascsi1_driver
);
340 module_init(cumanascsi_init
);
341 module_exit(cumanascsi_exit
);
343 MODULE_DESCRIPTION("Cumana SCSI-1 driver for Acorn machines");
344 MODULE_LICENSE("GPL");