2 * linux/drivers/scsi/arm/arxescsi.c
4 * Copyright (C) 1997-2000 Russell King, Stefan Hanske
6 * This driver is based on experimentation. Hence, it may have made
7 * assumptions about the particular card that I have available, and
11 * 30-08-1997 RMK 0.0.0 Created, READONLY version as cumana_2.c
12 * 22-01-1998 RMK 0.0.1 Updated to 2.1.80
13 * 15-04-1998 RMK 0.0.1 Only do PIO if FAS216 will allow it.
14 * 11-06-1998 SH 0.0.2 Changed to support ARXE 16-bit SCSI card
16 * 01-01-2000 SH 0.1.0 Added *real* pseudo dma writing
17 * (arxescsi_pseudo_dma_write)
18 * 02-04-2000 RMK 0.1.1 Updated for new error handling code.
19 * 22-10-2000 SH Updated for new registering scheme.
21 #include <linux/module.h>
22 #include <linux/blkdev.h>
23 #include <linux/kernel.h>
24 #include <linux/string.h>
25 #include <linux/ioport.h>
26 #include <linux/proc_fs.h>
27 #include <linux/unistd.h>
28 #include <linux/stat.h>
29 #include <linux/delay.h>
30 #include <linux/init.h>
31 #include <linux/interrupt.h>
35 #include <asm/ecard.h>
38 #include <scsi/scsi_host.h>
41 struct arxescsi_info
{
43 struct expansion_card
*ec
;
47 #define DMADATA_OFFSET (0x200)
49 #define DMASTAT_OFFSET (0x600)
50 #define DMASTAT_DRQ (1 << 0)
52 #define CSTATUS_IRQ (1 << 0)
54 #define VERSION "1.10 (23/01/2003 2.5.57)"
57 * Function: int arxescsi_dma_setup(host, SCpnt, direction, min_type)
58 * Purpose : initialises DMA/PIO
59 * Params : host - host
61 * direction - DMA on to/off of card
62 * min_type - minimum DMA support that we must have for this transfer
63 * Returns : 0 if we should not set CMD_WITHDMA for transfer info command
66 arxescsi_dma_setup(struct Scsi_Host
*host
, struct scsi_pointer
*SCp
,
67 fasdmadir_t direction
, fasdmatype_t min_type
)
70 * We don't do real DMA
75 static void arxescsi_pseudo_dma_write(unsigned char *addr
, void __iomem
*base
)
78 " stmdb sp!, {r0-r12}\n"
83 ".loop_1: ldmia r3!, {r6, r8, r10, r12}\n"
84 " mov r5, r6, lsl #16\n"
85 " mov r7, r8, lsl #16\n"
86 ".loop_2: ldrb r0, [r1, #1536]\n"
89 " stmia r2, {r5-r8}\n\t"
90 " mov r9, r10, lsl #16\n"
91 " mov r11, r12, lsl #16\n"
92 ".loop_3: ldrb r0, [r1, #1536]\n"
95 " stmia r2, {r9-r12}\n"
98 " ldmia sp!, {r0-r12}\n"
100 : "r" (addr
), "r" (base
));
104 * Function: int arxescsi_dma_pseudo(host, SCpnt, direction, transfer)
105 * Purpose : handles pseudo DMA
106 * Params : host - host
108 * direction - DMA on to/off of card
109 * transfer - minimum number of bytes we expect to transfer
112 arxescsi_dma_pseudo(struct Scsi_Host
*host
, struct scsi_pointer
*SCp
,
113 fasdmadir_t direction
, int transfer
)
115 struct arxescsi_info
*info
= (struct arxescsi_info
*)host
->hostdata
;
116 unsigned int length
, error
= 0;
117 void __iomem
*base
= info
->info
.scsi
.io_base
;
120 length
= SCp
->this_residual
;
123 if (direction
== DMA_OUT
) {
125 while (length
> 256) {
126 if (readb(base
+ 0x80) & STAT_INT
) {
130 arxescsi_pseudo_dma_write(addr
, base
);
137 if (readb(base
+ 0x80) & STAT_INT
)
140 if (!(readb(base
+ DMASTAT_OFFSET
) & DMASTAT_DRQ
))
143 word
= *addr
| *(addr
+ 1) << 8;
145 writew(word
, base
+ DMADATA_OFFSET
);
156 if (transfer
&& (transfer
& 255)) {
157 while (length
>= 256) {
158 if (readb(base
+ 0x80) & STAT_INT
) {
163 if (!(readb(base
+ DMASTAT_OFFSET
) & DMASTAT_DRQ
))
166 readsw(base
+ DMADATA_OFFSET
, addr
, 256 >> 1);
176 if (readb(base
+ 0x80) & STAT_INT
)
179 if (!(readb(base
+ DMASTAT_OFFSET
) & DMASTAT_DRQ
))
182 word
= readw(base
+ DMADATA_OFFSET
);
193 * Function: int arxescsi_dma_stop(host, SCpnt)
194 * Purpose : stops DMA/PIO
195 * Params : host - host
198 static void arxescsi_dma_stop(struct Scsi_Host
*host
, struct scsi_pointer
*SCp
)
206 * Function: const char *arxescsi_info(struct Scsi_Host * host)
207 * Purpose : returns a descriptive string about this interface,
208 * Params : host - driver host structure to return info for.
209 * Returns : pointer to a static buffer containing null terminated string.
211 static const char *arxescsi_info(struct Scsi_Host
*host
)
213 struct arxescsi_info
*info
= (struct arxescsi_info
*)host
->hostdata
;
214 static char string
[150];
216 sprintf(string
, "%s (%s) in slot %d v%s",
217 host
->hostt
->name
, info
->info
.scsi
.type
, info
->ec
->slot_no
,
224 arxescsi_show_info(struct seq_file
*m
, struct Scsi_Host
*host
)
226 struct arxescsi_info
*info
;
227 info
= (struct arxescsi_info
*)host
->hostdata
;
229 seq_printf(m
, "ARXE 16-bit SCSI driver v%s\n", VERSION
);
230 fas216_print_host(&info
->info
, m
);
231 fas216_print_stats(&info
->info
, m
);
232 fas216_print_devices(&info
->info
, m
);
236 static struct scsi_host_template arxescsi_template
= {
237 .show_info
= arxescsi_show_info
,
238 .name
= "ARXE SCSI card",
239 .info
= arxescsi_info
,
240 .queuecommand
= fas216_noqueue_command
,
241 .eh_host_reset_handler
= fas216_eh_host_reset
,
242 .eh_bus_reset_handler
= fas216_eh_bus_reset
,
243 .eh_device_reset_handler
= fas216_eh_device_reset
,
244 .eh_abort_handler
= fas216_eh_abort
,
247 .sg_tablesize
= SG_ALL
,
248 .use_clustering
= DISABLE_CLUSTERING
,
249 .proc_name
= "arxescsi",
252 static int arxescsi_probe(struct expansion_card
*ec
, const struct ecard_id
*id
)
254 struct Scsi_Host
*host
;
255 struct arxescsi_info
*info
;
259 ret
= ecard_request_resources(ec
);
263 base
= ecardm_iomap(ec
, ECARD_RES_MEMC
, 0, 0);
269 host
= scsi_host_alloc(&arxescsi_template
, sizeof(struct arxescsi_info
));
275 info
= (struct arxescsi_info
*)host
->hostdata
;
279 info
->info
.scsi
.io_base
= base
+ 0x2000;
280 info
->info
.scsi
.irq
= 0;
281 info
->info
.scsi
.dma
= NO_DMA
;
282 info
->info
.scsi
.io_shift
= 5;
283 info
->info
.ifcfg
.clockrate
= 24; /* MHz */
284 info
->info
.ifcfg
.select_timeout
= 255;
285 info
->info
.ifcfg
.asyncperiod
= 200; /* ns */
286 info
->info
.ifcfg
.sync_max_depth
= 0;
287 info
->info
.ifcfg
.cntl3
= CNTL3_FASTSCSI
| CNTL3_FASTCLK
;
288 info
->info
.ifcfg
.disconnect_ok
= 0;
289 info
->info
.ifcfg
.wide_max_size
= 0;
290 info
->info
.ifcfg
.capabilities
= FASCAP_PSEUDODMA
;
291 info
->info
.dma
.setup
= arxescsi_dma_setup
;
292 info
->info
.dma
.pseudo
= arxescsi_dma_pseudo
;
293 info
->info
.dma
.stop
= arxescsi_dma_stop
;
296 ec
->irqmask
= CSTATUS_IRQ
;
298 ret
= fas216_init(host
);
302 ret
= fas216_add(host
, &ec
->dev
);
306 fas216_release(host
);
310 ecard_release_resources(ec
);
315 static void arxescsi_remove(struct expansion_card
*ec
)
317 struct Scsi_Host
*host
= ecard_get_drvdata(ec
);
319 ecard_set_drvdata(ec
, NULL
);
322 fas216_release(host
);
324 ecard_release_resources(ec
);
327 static const struct ecard_id arxescsi_cids
[] = {
328 { MANU_ARXE
, PROD_ARXE_SCSI
},
332 static struct ecard_driver arxescsi_driver
= {
333 .probe
= arxescsi_probe
,
334 .remove
= arxescsi_remove
,
335 .id_table
= arxescsi_cids
,
341 static int __init
init_arxe_scsi_driver(void)
343 return ecard_register_driver(&arxescsi_driver
);
346 static void __exit
exit_arxe_scsi_driver(void)
348 ecard_remove_driver(&arxescsi_driver
);
351 module_init(init_arxe_scsi_driver
);
352 module_exit(exit_arxe_scsi_driver
);
354 MODULE_AUTHOR("Stefan Hanske");
355 MODULE_DESCRIPTION("ARXESCSI driver for Acorn machines");
356 MODULE_LICENSE("GPL");