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(hostdata, reg)
18 #define NCR5380_write(reg, value) cumanascsi_write(hostdata, reg, value)
20 #define NCR5380_dma_xfer_len cumanascsi_dma_xfer_len
21 #define NCR5380_dma_recv_setup cumanascsi_pread
22 #define NCR5380_dma_send_setup cumanascsi_pwrite
23 #define NCR5380_dma_residual NCR5380_dma_residual_none
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 \
32 struct NCR5380_hostdata
;
33 static u8
cumanascsi_read(struct NCR5380_hostdata
*, unsigned int);
34 static void cumanascsi_write(struct NCR5380_hostdata
*, unsigned int, u8
);
36 #include "../NCR5380.h"
40 #define L(v) (((v)<<16)|((v) & 0x0000ffff))
41 #define H(v) (((v)>>16)|((v) & 0xffff0000))
43 static inline int cumanascsi_pwrite(struct NCR5380_hostdata
*hostdata
,
44 unsigned char *addr
, int len
)
47 u8 __iomem
*base
= hostdata
->io
;
48 u8 __iomem
*dma
= hostdata
->pdma_io
+ 0x2000;
52 writeb(0x02, base
+ CTRL
);
53 laddr
= (unsigned long *)addr
;
58 status
= readb(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, base
+ CTRL
);
82 status
= readb(base
+ STAT
);
92 status
= readb(base
+ STAT
);
103 writeb(hostdata
->ctrl
| 0x40, base
+ CTRL
);
110 static inline int cumanascsi_pread(struct NCR5380_hostdata
*hostdata
,
111 unsigned char *addr
, int len
)
113 unsigned long *laddr
;
114 u8 __iomem
*base
= hostdata
->io
;
115 u8 __iomem
*dma
= hostdata
->pdma_io
+ 0x2000;
119 writeb(0x00, base
+ CTRL
);
120 laddr
= (unsigned long *)addr
;
124 status
= readb(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, base
+ CTRL
);
148 status
= readb(base
+ STAT
);
153 *addr
++ = readb(dma
);
158 status
= readb(base
+ STAT
);
163 *addr
++ = readb(dma
);
169 writeb(hostdata
->ctrl
| 0x40, base
+ CTRL
);
176 static int cumanascsi_dma_xfer_len(struct NCR5380_hostdata
*hostdata
,
177 struct scsi_cmnd
*cmd
)
179 return cmd
->transfersize
;
182 static u8
cumanascsi_read(struct NCR5380_hostdata
*hostdata
,
185 u8 __iomem
*base
= hostdata
->io
;
188 writeb(0, base
+ CTRL
);
190 val
= readb(base
+ 0x2100 + (reg
<< 2));
192 hostdata
->ctrl
= 0x40;
193 writeb(0x40, base
+ CTRL
);
198 static void cumanascsi_write(struct NCR5380_hostdata
*hostdata
,
199 unsigned int reg
, u8 value
)
201 u8 __iomem
*base
= hostdata
->io
;
203 writeb(0, base
+ CTRL
);
205 writeb(value
, base
+ 0x2100 + (reg
<< 2));
207 hostdata
->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_host_reset_handler
= NCR5380_host_reset
,
222 .sg_tablesize
= SG_ALL
,
224 .use_clustering
= DISABLE_CLUSTERING
,
225 .proc_name
= "CumanaSCSI-1",
226 .cmd_size
= NCR5380_CMD_SIZE
,
230 static int cumanascsi1_probe(struct expansion_card
*ec
,
231 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
)->io
= ioremap(ecard_resource_start(ec
, ECARD_RES_IOCSLOW
),
247 ecard_resource_len(ec
, ECARD_RES_IOCSLOW
));
248 priv(host
)->pdma_io
= ioremap(ecard_resource_start(ec
, ECARD_RES_MEMC
),
249 ecard_resource_len(ec
, ECARD_RES_MEMC
));
250 if (!priv(host
)->io
|| !priv(host
)->pdma_io
) {
257 ret
= NCR5380_init(host
, FLAG_DMA_FIXUP
| FLAG_LATE_DMA_SETUP
);
261 NCR5380_maybe_reset_bus(host
);
263 priv(host
)->ctrl
= 0;
264 writeb(0, priv(host
)->io
+ CTRL
);
266 ret
= request_irq(host
->irq
, cumanascsi_intr
, 0,
267 "CumanaSCSI-1", host
);
269 printk("scsi%d: IRQ%d not free: %d\n",
270 host
->host_no
, host
->irq
, ret
);
274 ret
= scsi_add_host(host
, &ec
->dev
);
278 scsi_scan_host(host
);
282 free_irq(host
->irq
, host
);
286 iounmap(priv(host
)->io
);
287 iounmap(priv(host
)->pdma_io
);
290 ecard_release_resources(ec
);
295 static void cumanascsi1_remove(struct expansion_card
*ec
)
297 struct Scsi_Host
*host
= ecard_get_drvdata(ec
);
298 void __iomem
*base
= priv(host
)->io
;
299 void __iomem
*dma
= priv(host
)->pdma_io
;
301 ecard_set_drvdata(ec
, NULL
);
303 scsi_remove_host(host
);
304 free_irq(host
->irq
, host
);
309 ecard_release_resources(ec
);
312 static const struct ecard_id cumanascsi1_cids
[] = {
313 { MANU_CUMANA
, PROD_CUMANA_SCSI_1
},
317 static struct ecard_driver cumanascsi1_driver
= {
318 .probe
= cumanascsi1_probe
,
319 .remove
= cumanascsi1_remove
,
320 .id_table
= cumanascsi1_cids
,
322 .name
= "cumanascsi1",
326 static int __init
cumanascsi_init(void)
328 return ecard_register_driver(&cumanascsi1_driver
);
331 static void __exit
cumanascsi_exit(void)
333 ecard_remove_driver(&cumanascsi1_driver
);
336 module_init(cumanascsi_init
);
337 module_exit(cumanascsi_exit
);
339 MODULE_DESCRIPTION("Cumana SCSI-1 driver for Acorn machines");
340 MODULE_LICENSE("GPL");