2 * linux/drivers/acorn/scsi/powertec.c
4 * Copyright (C) 1997-2005 Russell King
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 #include <linux/module.h>
11 #include <linux/blkdev.h>
12 #include <linux/kernel.h>
13 #include <linux/string.h>
14 #include <linux/ioport.h>
15 #include <linux/sched.h>
16 #include <linux/proc_fs.h>
17 #include <linux/delay.h>
18 #include <linux/interrupt.h>
19 #include <linux/init.h>
20 #include <linux/dma-mapping.h>
23 #include <asm/ecard.h>
26 #include <asm/pgtable.h>
29 #include <scsi/scsi_host.h>
33 #include <scsi/scsicam.h>
35 #define POWERTEC_FAS216_OFFSET 0x3000
36 #define POWERTEC_FAS216_SHIFT 6
38 #define POWERTEC_INTR_STATUS 0x2000
39 #define POWERTEC_INTR_BIT 0x80
41 #define POWERTEC_RESET_CONTROL 0x1018
42 #define POWERTEC_RESET_BIT 1
44 #define POWERTEC_TERM_CONTROL 0x2018
45 #define POWERTEC_TERM_ENABLE 1
47 #define POWERTEC_INTR_CONTROL 0x101c
48 #define POWERTEC_INTR_ENABLE 1
49 #define POWERTEC_INTR_DISABLE 0
51 #define VERSION "1.10 (19/01/2003 2.5.59)"
54 * Use term=0,1,0,0,0 to turn terminators on/off.
57 static int term[MAX_ECARDS] = { 1, 1, 1, 1, 1, 1, 1, 1 };
61 struct powertec_info {
63 struct expansion_card *ec;
65 unsigned int term_ctl;
66 struct scatterlist sg[NR_SG];
69 /* Prototype: void powertecscsi_irqenable(ec, irqnr)
70 * Purpose : Enable interrupts on Powertec SCSI card
71 * Params : ec - expansion card structure
72 * : irqnr - interrupt number
75 powertecscsi_irqenable(struct expansion_card *ec, int irqnr)
77 struct powertec_info *info = ec->irq_data;
78 writeb(POWERTEC_INTR_ENABLE, info->base + POWERTEC_INTR_CONTROL);
81 /* Prototype: void powertecscsi_irqdisable(ec, irqnr)
82 * Purpose : Disable interrupts on Powertec SCSI card
83 * Params : ec - expansion card structure
84 * : irqnr - interrupt number
87 powertecscsi_irqdisable(struct expansion_card *ec, int irqnr)
89 struct powertec_info *info = ec->irq_data;
90 writeb(POWERTEC_INTR_DISABLE, info->base + POWERTEC_INTR_CONTROL);
93 static const expansioncard_ops_t powertecscsi_ops = {
94 .irqenable = powertecscsi_irqenable,
95 .irqdisable = powertecscsi_irqdisable,
98 /* Prototype: void powertecscsi_terminator_ctl(host, on_off)
99 * Purpose : Turn the Powertec SCSI terminators on or off
100 * Params : host - card to turn on/off
101 * : on_off - !0 to turn on, 0 to turn off
104 powertecscsi_terminator_ctl(struct Scsi_Host *host, int on_off)
106 struct powertec_info *info = (struct powertec_info *)host->hostdata;
108 info->term_ctl = on_off ? POWERTEC_TERM_ENABLE : 0;
109 writeb(info->term_ctl, info->base + POWERTEC_TERM_CONTROL);
112 /* Prototype: void powertecscsi_intr(irq, *dev_id, *regs)
113 * Purpose : handle interrupts from Powertec SCSI card
114 * Params : irq - interrupt number
115 * dev_id - user-defined (Scsi_Host structure)
116 * regs - processor registers at interrupt
119 powertecscsi_intr(int irq, void *dev_id, struct pt_regs *regs)
121 struct powertec_info *info = dev_id;
123 return fas216_intr(&info->info);
126 /* Prototype: fasdmatype_t powertecscsi_dma_setup(host, SCpnt, direction, min_type)
127 * Purpose : initialises DMA/PIO
128 * Params : host - host
130 * direction - DMA on to/off of card
131 * min_type - minimum DMA support that we must have for this transfer
132 * Returns : type of transfer to be performed
135 powertecscsi_dma_setup(struct Scsi_Host *host, struct scsi_pointer *SCp,
136 fasdmadir_t direction, fasdmatype_t min_type)
138 struct powertec_info *info = (struct powertec_info *)host->hostdata;
139 struct device *dev = scsi_get_device(host);
140 int dmach = info->info.scsi.dma;
142 if (info->info.ifcfg.capabilities & FASCAP_DMA &&
143 min_type == fasdma_real_all) {
144 int bufs, map_dir, dma_dir;
146 bufs = copy_SCp_to_sg(&info->sg[0], SCp, NR_SG);
148 if (direction == DMA_OUT)
149 map_dir = DMA_TO_DEVICE,
150 dma_dir = DMA_MODE_WRITE;
152 map_dir = DMA_FROM_DEVICE,
153 dma_dir = DMA_MODE_READ;
155 dma_map_sg(dev, info->sg, bufs + 1, map_dir);
158 set_dma_sg(dmach, info->sg, bufs + 1);
159 set_dma_mode(dmach, dma_dir);
161 return fasdma_real_all;
165 * If we're not doing DMA,
171 /* Prototype: int powertecscsi_dma_stop(host, SCpnt)
172 * Purpose : stops DMA/PIO
173 * Params : host - host
177 powertecscsi_dma_stop(struct Scsi_Host *host, struct scsi_pointer *SCp)
179 struct powertec_info *info = (struct powertec_info *)host->hostdata;
180 if (info->info.scsi.dma != NO_DMA)
181 disable_dma(info->info.scsi.dma);
184 /* Prototype: const char *powertecscsi_info(struct Scsi_Host * host)
185 * Purpose : returns a descriptive string about this interface,
186 * Params : host - driver host structure to return info for.
187 * Returns : pointer to a static buffer containing null terminated string.
189 const char *powertecscsi_info(struct Scsi_Host *host)
191 struct powertec_info *info = (struct powertec_info *)host->hostdata;
192 static char string[150];
194 sprintf(string, "%s (%s) in slot %d v%s terminators o%s",
195 host->hostt->name, info->info.scsi.type, info->ec->slot_no,
196 VERSION, info->term_ctl ? "n" : "ff");
201 /* Prototype: int powertecscsi_set_proc_info(struct Scsi_Host *host, char *buffer, int length)
202 * Purpose : Set a driver specific function
203 * Params : host - host to setup
204 * : buffer - buffer containing string describing operation
205 * : length - length of string
206 * Returns : -EINVAL, or 0
209 powertecscsi_set_proc_info(struct Scsi_Host *host, char *buffer, int length)
213 if (length >= 12 && strncmp(buffer, "POWERTECSCSI", 12) == 0) {
217 if (length >= 5 && strncmp(buffer, "term=", 5) == 0) {
218 if (buffer[5] == '1')
219 powertecscsi_terminator_ctl(host, 1);
220 else if (buffer[5] == '0')
221 powertecscsi_terminator_ctl(host, 0);
232 /* Prototype: int powertecscsi_proc_info(char *buffer, char **start, off_t offset,
233 * int length, int host_no, int inout)
234 * Purpose : Return information about the driver to a user process accessing
235 * the /proc filesystem.
236 * Params : buffer - a buffer to write information to
237 * start - a pointer into this buffer set by this routine to the start
238 * of the required information.
239 * offset - offset into information that we have read upto.
240 * length - length of buffer
241 * inout - 0 for reading, 1 for writing.
242 * Returns : length of data written to buffer.
244 int powertecscsi_proc_info(struct Scsi_Host *host, char *buffer, char **start, off_t offset,
245 int length, int inout)
247 struct powertec_info *info;
252 return powertecscsi_set_proc_info(host, buffer, length);
254 info = (struct powertec_info *)host->hostdata;
256 p += sprintf(p, "PowerTec SCSI driver v%s\n", VERSION);
257 p += fas216_print_host(&info->info, p);
258 p += sprintf(p, "Term : o%s\n",
259 info->term_ctl ? "n" : "ff");
261 p += fas216_print_stats(&info->info, p);
262 p += fas216_print_devices(&info->info, p);
264 *start = buffer + offset;
265 pos = p - buffer - offset;
272 static ssize_t powertecscsi_show_term(struct device *dev, struct device_attribute *attr, char *buf)
274 struct expansion_card *ec = ECARD_DEV(dev);
275 struct Scsi_Host *host = ecard_get_drvdata(ec);
276 struct powertec_info *info = (struct powertec_info *)host->hostdata;
278 return sprintf(buf, "%d\n", info->term_ctl ? 1 : 0);
282 powertecscsi_store_term(struct device *dev, struct device_attribute *attr, const char *buf, size_t len)
284 struct expansion_card *ec = ECARD_DEV(dev);
285 struct Scsi_Host *host = ecard_get_drvdata(ec);
288 powertecscsi_terminator_ctl(host, buf[0] != '0');
293 static DEVICE_ATTR(bus_term, S_IRUGO | S_IWUSR,
294 powertecscsi_show_term, powertecscsi_store_term);
296 static struct scsi_host_template powertecscsi_template = {
297 .module = THIS_MODULE,
298 .proc_info = powertecscsi_proc_info,
299 .name = "PowerTec SCSI",
300 .info = powertecscsi_info,
301 .queuecommand = fas216_queue_command,
302 .eh_host_reset_handler = fas216_eh_host_reset,
303 .eh_bus_reset_handler = fas216_eh_bus_reset,
304 .eh_device_reset_handler = fas216_eh_device_reset,
305 .eh_abort_handler = fas216_eh_abort,
309 .sg_tablesize = SG_ALL,
311 .use_clustering = ENABLE_CLUSTERING,
312 .proc_name = "powertec",
316 powertecscsi_probe(struct expansion_card *ec, const struct ecard_id *id)
318 struct Scsi_Host *host;
319 struct powertec_info *info;
320 unsigned long resbase, reslen;
324 ret = ecard_request_resources(ec);
328 resbase = ecard_resource_start(ec, ECARD_RES_IOCFAST);
329 reslen = ecard_resource_len(ec, ECARD_RES_IOCFAST);
330 base = ioremap(resbase, reslen);
336 host = scsi_host_alloc(&powertecscsi_template,
337 sizeof (struct powertec_info));
343 ecard_set_drvdata(ec, host);
345 info = (struct powertec_info *)host->hostdata;
347 powertecscsi_terminator_ctl(host, term[ec->slot_no]);
349 info->info.scsi.io_base = base + POWERTEC_FAS216_OFFSET;
350 info->info.scsi.io_shift = POWERTEC_FAS216_SHIFT;
351 info->info.scsi.irq = ec->irq;
352 info->info.scsi.dma = ec->dma;
353 info->info.ifcfg.clockrate = 40; /* MHz */
354 info->info.ifcfg.select_timeout = 255;
355 info->info.ifcfg.asyncperiod = 200; /* ns */
356 info->info.ifcfg.sync_max_depth = 7;
357 info->info.ifcfg.cntl3 = CNTL3_BS8 | CNTL3_FASTSCSI | CNTL3_FASTCLK;
358 info->info.ifcfg.disconnect_ok = 1;
359 info->info.ifcfg.wide_max_size = 0;
360 info->info.ifcfg.capabilities = 0;
361 info->info.dma.setup = powertecscsi_dma_setup;
362 info->info.dma.pseudo = NULL;
363 info->info.dma.stop = powertecscsi_dma_stop;
365 ec->irqaddr = base + POWERTEC_INTR_STATUS;
366 ec->irqmask = POWERTEC_INTR_BIT;
368 ec->ops = &powertecscsi_ops;
370 device_create_file(&ec->dev, &dev_attr_bus_term);
372 ret = fas216_init(host);
376 ret = request_irq(ec->irq, powertecscsi_intr,
377 SA_INTERRUPT, "powertec", info);
379 printk("scsi%d: IRQ%d not free: %d\n",
380 host->host_no, ec->irq, ret);
384 if (info->info.scsi.dma != NO_DMA) {
385 if (request_dma(info->info.scsi.dma, "powertec")) {
386 printk("scsi%d: DMA%d not free, using PIO\n",
387 host->host_no, info->info.scsi.dma);
388 info->info.scsi.dma = NO_DMA;
390 set_dma_speed(info->info.scsi.dma, 180);
391 info->info.ifcfg.capabilities |= FASCAP_DMA;
395 ret = fas216_add(host, &ec->dev);
399 if (info->info.scsi.dma != NO_DMA)
400 free_dma(info->info.scsi.dma);
401 free_irq(ec->irq, host);
404 fas216_release(host);
407 device_remove_file(&ec->dev, &dev_attr_bus_term);
414 ecard_release_resources(ec);
420 static void __devexit powertecscsi_remove(struct expansion_card *ec)
422 struct Scsi_Host *host = ecard_get_drvdata(ec);
423 struct powertec_info *info = (struct powertec_info *)host->hostdata;
425 ecard_set_drvdata(ec, NULL);
428 device_remove_file(&ec->dev, &dev_attr_bus_term);
430 if (info->info.scsi.dma != NO_DMA)
431 free_dma(info->info.scsi.dma);
432 free_irq(ec->irq, info);
436 fas216_release(host);
438 ecard_release_resources(ec);
441 static const struct ecard_id powertecscsi_cids[] = {
442 { MANU_ALSYSTEMS, PROD_ALSYS_SCSIATAPI },
446 static struct ecard_driver powertecscsi_driver = {
447 .probe = powertecscsi_probe,
448 .remove = __devexit_p(powertecscsi_remove),
449 .id_table = powertecscsi_cids,
451 .name = "powertecscsi",
455 static int __init powertecscsi_init(void)
457 return ecard_register_driver(&powertecscsi_driver);
460 static void __exit powertecscsi_exit(void)
462 ecard_remove_driver(&powertecscsi_driver);
465 module_init(powertecscsi_init);
466 module_exit(powertecscsi_exit);
468 MODULE_AUTHOR("Russell King");
469 MODULE_DESCRIPTION("Powertec SCSI driver");
470 MODULE_PARM(term, "1-8i");
471 MODULE_PARM_DESC(term, "SCSI bus termination");
472 MODULE_LICENSE("GPL");