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>
18 #define priv(host) ((struct NCR5380_hostdata *)(host)->hostdata)
19 #define NCR5380_read(reg) cumanascsi_read(instance, reg)
20 #define NCR5380_write(reg, value) cumanascsi_write(instance, reg, value)
22 #define NCR5380_dma_xfer_len(instance, cmd, phase) (cmd->transfersize)
24 #define NCR5380_intr cumanascsi_intr
25 #define NCR5380_queue_command cumanascsi_queue_command
26 #define NCR5380_info cumanascsi_info
28 #define NCR5380_implementation_fields \
33 #include "../NCR5380.h"
35 void cumanascsi_setup(char *str
, int *ints
)
41 #define L(v) (((v)<<16)|((v) & 0x0000ffff))
42 #define H(v) (((v)>>16)|((v) & 0xffff0000))
45 NCR5380_pwrite(struct Scsi_Host
*host
, unsigned char *addr
, int len
)
48 void __iomem
*dma
= priv(host
)->dma
+ 0x2000;
52 writeb(0x02, priv(host
)->base
+ CTRL
);
53 laddr
= (unsigned long *)addr
;
58 status
= readb(priv(host
)->base
+ STAT
);
63 v
=*laddr
++; writew(L(v
), dma
); writew(H(v
), dma
);
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
);
76 addr
= (unsigned char *)laddr
;
77 writeb(0x12, priv(host
)->base
+ CTRL
);
82 status
= readb(priv(host
)->base
+ STAT
);
92 status
= readb(priv(host
)->base
+ STAT
);
103 writeb(priv(host
)->ctrl
| 0x40, priv(host
)->base
+ CTRL
);
108 NCR5380_pread(struct Scsi_Host
*host
, unsigned char *addr
, int len
)
110 unsigned long *laddr
;
111 void __iomem
*dma
= priv(host
)->dma
+ 0x2000;
115 writeb(0x00, priv(host
)->base
+ CTRL
);
116 laddr
= (unsigned long *)addr
;
120 status
= readb(priv(host
)->base
+ STAT
);
125 *laddr
++ = readw(dma
) | (readw(dma
) << 16);
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);
138 addr
= (unsigned char *)laddr
;
139 writeb(0x10, priv(host
)->base
+ CTRL
);
144 status
= readb(priv(host
)->base
+ STAT
);
149 *addr
++ = readb(dma
);
154 status
= readb(priv(host
)->base
+ STAT
);
159 *addr
++ = readb(dma
);
165 writeb(priv(host
)->ctrl
| 0x40, priv(host
)->base
+ CTRL
);
169 static unsigned char cumanascsi_read(struct Scsi_Host
*host
, unsigned int reg
)
171 void __iomem
*base
= priv(host
)->base
;
174 writeb(0, base
+ CTRL
);
176 val
= readb(base
+ 0x2100 + (reg
<< 2));
178 priv(host
)->ctrl
= 0x40;
179 writeb(0x40, base
+ CTRL
);
184 static void cumanascsi_write(struct Scsi_Host
*host
, unsigned int reg
, unsigned int value
)
186 void __iomem
*base
= priv(host
)->base
;
188 writeb(0, base
+ CTRL
);
190 writeb(value
, base
+ 0x2100 + (reg
<< 2));
192 priv(host
)->ctrl
= 0x40;
193 writeb(0x40, base
+ CTRL
);
196 #include "../NCR5380.c"
198 static struct scsi_host_template cumanascsi_template
= {
199 .module
= THIS_MODULE
,
200 .name
= "Cumana 16-bit SCSI",
201 .info
= cumanascsi_info
,
202 .queuecommand
= cumanascsi_queue_command
,
203 .eh_abort_handler
= NCR5380_abort
,
204 .eh_bus_reset_handler
= NCR5380_bus_reset
,
207 .sg_tablesize
= SG_ALL
,
209 .use_clustering
= DISABLE_CLUSTERING
,
210 .proc_name
= "CumanaSCSI-1",
211 .cmd_size
= NCR5380_CMD_SIZE
,
215 static int cumanascsi1_probe(struct expansion_card
*ec
,
216 const struct ecard_id
*id
)
218 struct Scsi_Host
*host
;
221 ret
= ecard_request_resources(ec
);
225 host
= scsi_host_alloc(&cumanascsi_template
, sizeof(struct NCR5380_hostdata
));
231 priv(host
)->base
= ioremap(ecard_resource_start(ec
, ECARD_RES_IOCSLOW
),
232 ecard_resource_len(ec
, ECARD_RES_IOCSLOW
));
233 priv(host
)->dma
= ioremap(ecard_resource_start(ec
, ECARD_RES_MEMC
),
234 ecard_resource_len(ec
, ECARD_RES_MEMC
));
235 if (!priv(host
)->base
|| !priv(host
)->dma
) {
242 ret
= NCR5380_init(host
, 0);
246 NCR5380_maybe_reset_bus(host
);
248 priv(host
)->ctrl
= 0;
249 writeb(0, priv(host
)->base
+ CTRL
);
251 ret
= request_irq(host
->irq
, cumanascsi_intr
, 0,
252 "CumanaSCSI-1", host
);
254 printk("scsi%d: IRQ%d not free: %d\n",
255 host
->host_no
, host
->irq
, ret
);
259 ret
= scsi_add_host(host
, &ec
->dev
);
263 scsi_scan_host(host
);
267 free_irq(host
->irq
, host
);
271 iounmap(priv(host
)->base
);
272 iounmap(priv(host
)->dma
);
275 ecard_release_resources(ec
);
280 static void cumanascsi1_remove(struct expansion_card
*ec
)
282 struct Scsi_Host
*host
= ecard_get_drvdata(ec
);
284 ecard_set_drvdata(ec
, NULL
);
286 scsi_remove_host(host
);
287 free_irq(host
->irq
, host
);
289 iounmap(priv(host
)->base
);
290 iounmap(priv(host
)->dma
);
292 ecard_release_resources(ec
);
295 static const struct ecard_id cumanascsi1_cids
[] = {
296 { MANU_CUMANA
, PROD_CUMANA_SCSI_1
},
300 static struct ecard_driver cumanascsi1_driver
= {
301 .probe
= cumanascsi1_probe
,
302 .remove
= cumanascsi1_remove
,
303 .id_table
= cumanascsi1_cids
,
305 .name
= "cumanascsi1",
309 static int __init
cumanascsi_init(void)
311 return ecard_register_driver(&cumanascsi1_driver
);
314 static void __exit
cumanascsi_exit(void)
316 ecard_remove_driver(&cumanascsi1_driver
);
319 module_init(cumanascsi_init
);
320 module_exit(cumanascsi_exit
);
322 MODULE_DESCRIPTION("Cumana SCSI-1 driver for Acorn machines");
323 MODULE_LICENSE("GPL");