2 * linux/arch/arm/drivers/scsi/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/sched.h>
27 #include <linux/proc_fs.h>
28 #include <linux/unistd.h>
29 #include <linux/stat.h>
30 #include <linux/delay.h>
31 #include <linux/init.h>
32 #include <linux/interrupt.h>
37 #include <asm/ecard.h>
40 #include <scsi/scsi_host.h>
43 struct arxescsi_info {
45 struct expansion_card *ec;
49 #define DMADATA_OFFSET (0x200)
51 #define DMASTAT_OFFSET (0x600)
52 #define DMASTAT_DRQ (1 << 0)
54 #define CSTATUS_IRQ (1 << 0)
56 #define VERSION "1.10 (23/01/2003 2.5.57)"
59 * Function: int arxescsi_dma_setup(host, SCpnt, direction, min_type)
60 * Purpose : initialises DMA/PIO
61 * Params : host - host
63 * direction - DMA on to/off of card
64 * min_type - minimum DMA support that we must have for this transfer
65 * Returns : 0 if we should not set CMD_WITHDMA for transfer info command
68 arxescsi_dma_setup(struct Scsi_Host *host, struct scsi_pointer *SCp,
69 fasdmadir_t direction, fasdmatype_t min_type)
72 * We don't do real DMA
77 static void arxescsi_pseudo_dma_write(unsigned char *addr, void __iomem *base)
80 " stmdb sp!, {r0-r12}\n"
85 ".loop_1: ldmia r3!, {r6, r8, r10, r12}\n"
86 " mov r5, r6, lsl #16\n"
87 " mov r7, r8, lsl #16\n"
88 ".loop_2: ldrb r0, [r1, #1536]\n"
91 " stmia r2, {r5-r8}\n\t"
92 " mov r9, r10, lsl #16\n"
93 " mov r11, r12, lsl #16\n"
94 ".loop_3: ldrb r0, [r1, #1536]\n"
97 " stmia r2, {r9-r12}\n"
100 " ldmia sp!, {r0-r12}\n"
102 : "r" (addr), "r" (base));
106 * Function: int arxescsi_dma_pseudo(host, SCpnt, direction, transfer)
107 * Purpose : handles pseudo DMA
108 * Params : host - host
110 * direction - DMA on to/off of card
111 * transfer - minimum number of bytes we expect to transfer
114 arxescsi_dma_pseudo(struct Scsi_Host *host, struct scsi_pointer *SCp,
115 fasdmadir_t direction, int transfer)
117 struct arxescsi_info *info = (struct arxescsi_info *)host->hostdata;
118 unsigned int length, error = 0;
119 void __iomem *base = info->info.scsi.io_base;
122 length = SCp->this_residual;
125 if (direction == DMA_OUT) {
127 while (length > 256) {
128 if (readb(base + 0x80) & STAT_INT) {
132 arxescsi_pseudo_dma_write(addr, base);
139 if (readb(base + 0x80) & STAT_INT)
142 if (!(readb(base + DMASTAT_OFFSET) & DMASTAT_DRQ))
145 word = *addr | *(addr + 1) << 8;
147 writew(word, base + DMADATA_OFFSET);
158 if (transfer && (transfer & 255)) {
159 while (length >= 256) {
160 if (readb(base + 0x80) & STAT_INT) {
165 if (!(readb(base + DMASTAT_OFFSET) & DMASTAT_DRQ))
168 readsw(base + DMADATA_OFFSET, addr, 256 >> 1);
178 if (readb(base + 0x80) & STAT_INT)
181 if (!(readb(base + DMASTAT_OFFSET) & DMASTAT_DRQ))
184 word = readw(base + DMADATA_OFFSET);
195 * Function: int arxescsi_dma_stop(host, SCpnt)
196 * Purpose : stops DMA/PIO
197 * Params : host - host
200 static void arxescsi_dma_stop(struct Scsi_Host *host, struct scsi_pointer *SCp)
208 * Function: const char *arxescsi_info(struct Scsi_Host * host)
209 * Purpose : returns a descriptive string about this interface,
210 * Params : host - driver host structure to return info for.
211 * Returns : pointer to a static buffer containing null terminated string.
213 static const char *arxescsi_info(struct Scsi_Host *host)
215 struct arxescsi_info *info = (struct arxescsi_info *)host->hostdata;
216 static char string[150];
218 sprintf(string, "%s (%s) in slot %d v%s",
219 host->hostt->name, info->info.scsi.type, info->ec->slot_no,
226 * Function: int arxescsi_proc_info(char *buffer, char **start, off_t offset,
227 * int length, int host_no, int inout)
228 * Purpose : Return information about the driver to a user process accessing
229 * the /proc filesystem.
230 * Params : buffer - a buffer to write information to
231 * start - a pointer into this buffer set by this routine to the start
232 * of the required information.
233 * offset - offset into information that we have read upto.
234 * length - length of buffer
235 * host_no - host number to return information for
236 * inout - 0 for reading, 1 for writing.
237 * Returns : length of data written to buffer.
240 arxescsi_proc_info(struct Scsi_Host *host, char *buffer, char **start, off_t offset, int length,
243 struct arxescsi_info *info;
247 info = (struct arxescsi_info *)host->hostdata;
251 p += sprintf(p, "ARXE 16-bit SCSI driver v%s\n", VERSION);
252 p += fas216_print_host(&info->info, p);
253 p += fas216_print_stats(&info->info, p);
254 p += fas216_print_devices(&info->info, p);
256 *start = buffer + offset;
257 pos = p - buffer - offset;
264 static struct scsi_host_template arxescsi_template = {
265 .proc_info = arxescsi_proc_info,
266 .name = "ARXE SCSI card",
267 .info = arxescsi_info,
268 .queuecommand = fas216_noqueue_command,
269 .eh_host_reset_handler = fas216_eh_host_reset,
270 .eh_bus_reset_handler = fas216_eh_bus_reset,
271 .eh_device_reset_handler = fas216_eh_device_reset,
272 .eh_abort_handler = fas216_eh_abort,
275 .sg_tablesize = SG_ALL,
277 .use_clustering = DISABLE_CLUSTERING,
278 .proc_name = "arxescsi",
282 arxescsi_probe(struct expansion_card *ec, const struct ecard_id *id)
284 struct Scsi_Host *host;
285 struct arxescsi_info *info;
286 unsigned long resbase, reslen;
290 ret = ecard_request_resources(ec);
294 resbase = ecard_resource_start(ec, ECARD_RES_MEMC);
295 reslen = ecard_resource_len(ec, ECARD_RES_MEMC);
296 base = ioremap(resbase, reslen);
302 host = scsi_host_alloc(&arxescsi_template, sizeof(struct arxescsi_info));
308 info = (struct arxescsi_info *)host->hostdata;
312 info->info.scsi.io_base = base + 0x2000;
313 info->info.scsi.irq = NO_IRQ;
314 info->info.scsi.dma = NO_DMA;
315 info->info.scsi.io_shift = 5;
316 info->info.ifcfg.clockrate = 24; /* MHz */
317 info->info.ifcfg.select_timeout = 255;
318 info->info.ifcfg.asyncperiod = 200; /* ns */
319 info->info.ifcfg.sync_max_depth = 0;
320 info->info.ifcfg.cntl3 = CNTL3_FASTSCSI | CNTL3_FASTCLK;
321 info->info.ifcfg.disconnect_ok = 0;
322 info->info.ifcfg.wide_max_size = 0;
323 info->info.ifcfg.capabilities = FASCAP_PSEUDODMA;
324 info->info.dma.setup = arxescsi_dma_setup;
325 info->info.dma.pseudo = arxescsi_dma_pseudo;
326 info->info.dma.stop = arxescsi_dma_stop;
329 ec->irqmask = CSTATUS_IRQ;
331 ret = fas216_init(host);
335 ret = fas216_add(host, &ec->dev);
339 fas216_release(host);
345 ecard_release_resources(ec);
350 static void __devexit arxescsi_remove(struct expansion_card *ec)
352 struct Scsi_Host *host = ecard_get_drvdata(ec);
353 struct arxescsi_info *info = (struct arxescsi_info *)host->hostdata;
355 ecard_set_drvdata(ec, NULL);
360 fas216_release(host);
362 ecard_release_resources(ec);
365 static const struct ecard_id arxescsi_cids[] = {
366 { MANU_ARXE, PROD_ARXE_SCSI },
370 static struct ecard_driver arxescsi_driver = {
371 .probe = arxescsi_probe,
372 .remove = __devexit_p(arxescsi_remove),
373 .id_table = arxescsi_cids,
379 static int __init init_arxe_scsi_driver(void)
381 return ecard_register_driver(&arxescsi_driver);
384 static void __exit exit_arxe_scsi_driver(void)
386 ecard_remove_driver(&arxescsi_driver);
389 module_init(init_arxe_scsi_driver);
390 module_exit(exit_arxe_scsi_driver);
392 MODULE_AUTHOR("Stefan Hanske");
393 MODULE_DESCRIPTION("ARXESCSI driver for Acorn machines");
394 MODULE_LICENSE("GPL");