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>
25 #include <asm/pgtable.h>
28 #include <scsi/scsi_host.h>
32 #include <scsi/scsicam.h>
34 #define POWERTEC_FAS216_OFFSET 0x3000
35 #define POWERTEC_FAS216_SHIFT 6
37 #define POWERTEC_INTR_STATUS 0x2000
38 #define POWERTEC_INTR_BIT 0x80
40 #define POWERTEC_RESET_CONTROL 0x1018
41 #define POWERTEC_RESET_BIT 1
43 #define POWERTEC_TERM_CONTROL 0x2018
44 #define POWERTEC_TERM_ENABLE 1
46 #define POWERTEC_INTR_CONTROL 0x101c
47 #define POWERTEC_INTR_ENABLE 1
48 #define POWERTEC_INTR_DISABLE 0
50 #define VERSION "1.10 (19/01/2003 2.5.59)"
53 * Use term=0,1,0,0,0 to turn terminators on/off.
56 static int term[MAX_ECARDS] = { 1, 1, 1, 1, 1, 1, 1, 1 };
60 struct powertec_info {
62 struct expansion_card *ec;
64 unsigned int term_ctl;
65 struct scatterlist sg[NR_SG];
68 /* Prototype: void powertecscsi_irqenable(ec, irqnr)
69 * Purpose : Enable interrupts on Powertec SCSI card
70 * Params : ec - expansion card structure
71 * : irqnr - interrupt number
74 powertecscsi_irqenable(struct expansion_card *ec, int irqnr)
76 struct powertec_info *info = ec->irq_data;
77 writeb(POWERTEC_INTR_ENABLE, info->base + POWERTEC_INTR_CONTROL);
80 /* Prototype: void powertecscsi_irqdisable(ec, irqnr)
81 * Purpose : Disable interrupts on Powertec SCSI card
82 * Params : ec - expansion card structure
83 * : irqnr - interrupt number
86 powertecscsi_irqdisable(struct expansion_card *ec, int irqnr)
88 struct powertec_info *info = ec->irq_data;
89 writeb(POWERTEC_INTR_DISABLE, info->base + POWERTEC_INTR_CONTROL);
92 static const expansioncard_ops_t powertecscsi_ops = {
93 .irqenable = powertecscsi_irqenable,
94 .irqdisable = powertecscsi_irqdisable,
97 /* Prototype: void powertecscsi_terminator_ctl(host, on_off)
98 * Purpose : Turn the Powertec SCSI terminators on or off
99 * Params : host - card to turn on/off
100 * : on_off - !0 to turn on, 0 to turn off
103 powertecscsi_terminator_ctl(struct Scsi_Host *host, int on_off)
105 struct powertec_info *info = (struct powertec_info *)host->hostdata;
107 info->term_ctl = on_off ? POWERTEC_TERM_ENABLE : 0;
108 writeb(info->term_ctl, info->base + POWERTEC_TERM_CONTROL);
111 /* Prototype: void powertecscsi_intr(irq, *dev_id, *regs)
112 * Purpose : handle interrupts from Powertec SCSI card
113 * Params : irq - interrupt number
114 * dev_id - user-defined (Scsi_Host structure)
116 static irqreturn_t powertecscsi_intr(int irq, void *dev_id)
118 struct powertec_info *info = dev_id;
120 return fas216_intr(&info->info);
123 /* Prototype: fasdmatype_t powertecscsi_dma_setup(host, SCpnt, direction, min_type)
124 * Purpose : initialises DMA/PIO
125 * Params : host - host
127 * direction - DMA on to/off of card
128 * min_type - minimum DMA support that we must have for this transfer
129 * Returns : type of transfer to be performed
132 powertecscsi_dma_setup(struct Scsi_Host *host, struct scsi_pointer *SCp,
133 fasdmadir_t direction, fasdmatype_t min_type)
135 struct powertec_info *info = (struct powertec_info *)host->hostdata;
136 struct device *dev = scsi_get_device(host);
137 int dmach = info->info.scsi.dma;
139 if (info->info.ifcfg.capabilities & FASCAP_DMA &&
140 min_type == fasdma_real_all) {
141 int bufs, map_dir, dma_dir;
143 bufs = copy_SCp_to_sg(&info->sg[0], SCp, NR_SG);
145 if (direction == DMA_OUT)
146 map_dir = DMA_TO_DEVICE,
147 dma_dir = DMA_MODE_WRITE;
149 map_dir = DMA_FROM_DEVICE,
150 dma_dir = DMA_MODE_READ;
152 dma_map_sg(dev, info->sg, bufs + 1, map_dir);
155 set_dma_sg(dmach, info->sg, bufs + 1);
156 set_dma_mode(dmach, dma_dir);
158 return fasdma_real_all;
162 * If we're not doing DMA,
168 /* Prototype: int powertecscsi_dma_stop(host, SCpnt)
169 * Purpose : stops DMA/PIO
170 * Params : host - host
174 powertecscsi_dma_stop(struct Scsi_Host *host, struct scsi_pointer *SCp)
176 struct powertec_info *info = (struct powertec_info *)host->hostdata;
177 if (info->info.scsi.dma != NO_DMA)
178 disable_dma(info->info.scsi.dma);
181 /* Prototype: const char *powertecscsi_info(struct Scsi_Host * host)
182 * Purpose : returns a descriptive string about this interface,
183 * Params : host - driver host structure to return info for.
184 * Returns : pointer to a static buffer containing null terminated string.
186 const char *powertecscsi_info(struct Scsi_Host *host)
188 struct powertec_info *info = (struct powertec_info *)host->hostdata;
189 static char string[150];
191 sprintf(string, "%s (%s) in slot %d v%s terminators o%s",
192 host->hostt->name, info->info.scsi.type, info->ec->slot_no,
193 VERSION, info->term_ctl ? "n" : "ff");
198 /* Prototype: int powertecscsi_set_proc_info(struct Scsi_Host *host, char *buffer, int length)
199 * Purpose : Set a driver specific function
200 * Params : host - host to setup
201 * : buffer - buffer containing string describing operation
202 * : length - length of string
203 * Returns : -EINVAL, or 0
206 powertecscsi_set_proc_info(struct Scsi_Host *host, char *buffer, int length)
210 if (length >= 12 && strncmp(buffer, "POWERTECSCSI", 12) == 0) {
214 if (length >= 5 && strncmp(buffer, "term=", 5) == 0) {
215 if (buffer[5] == '1')
216 powertecscsi_terminator_ctl(host, 1);
217 else if (buffer[5] == '0')
218 powertecscsi_terminator_ctl(host, 0);
229 /* Prototype: int powertecscsi_proc_info(char *buffer, char **start, off_t offset,
230 * int length, int host_no, int inout)
231 * Purpose : Return information about the driver to a user process accessing
232 * the /proc filesystem.
233 * Params : buffer - a buffer to write information to
234 * start - a pointer into this buffer set by this routine to the start
235 * of the required information.
236 * offset - offset into information that we have read upto.
237 * length - length of buffer
238 * inout - 0 for reading, 1 for writing.
239 * Returns : length of data written to buffer.
241 int powertecscsi_proc_info(struct Scsi_Host *host, char *buffer, char **start, off_t offset,
242 int length, int inout)
244 struct powertec_info *info;
249 return powertecscsi_set_proc_info(host, buffer, length);
251 info = (struct powertec_info *)host->hostdata;
253 p += sprintf(p, "PowerTec SCSI driver v%s\n", VERSION);
254 p += fas216_print_host(&info->info, p);
255 p += sprintf(p, "Term : o%s\n",
256 info->term_ctl ? "n" : "ff");
258 p += fas216_print_stats(&info->info, p);
259 p += fas216_print_devices(&info->info, p);
261 *start = buffer + offset;
262 pos = p - buffer - offset;
269 static ssize_t powertecscsi_show_term(struct device *dev, struct device_attribute *attr, char *buf)
271 struct expansion_card *ec = ECARD_DEV(dev);
272 struct Scsi_Host *host = ecard_get_drvdata(ec);
273 struct powertec_info *info = (struct powertec_info *)host->hostdata;
275 return sprintf(buf, "%d\n", info->term_ctl ? 1 : 0);
279 powertecscsi_store_term(struct device *dev, struct device_attribute *attr, const char *buf, size_t len)
281 struct expansion_card *ec = ECARD_DEV(dev);
282 struct Scsi_Host *host = ecard_get_drvdata(ec);
285 powertecscsi_terminator_ctl(host, buf[0] != '0');
290 static DEVICE_ATTR(bus_term, S_IRUGO | S_IWUSR,
291 powertecscsi_show_term, powertecscsi_store_term);
293 static struct scsi_host_template powertecscsi_template = {
294 .module = THIS_MODULE,
295 .proc_info = powertecscsi_proc_info,
296 .name = "PowerTec SCSI",
297 .info = powertecscsi_info,
298 .queuecommand = fas216_queue_command,
299 .eh_host_reset_handler = fas216_eh_host_reset,
300 .eh_bus_reset_handler = fas216_eh_bus_reset,
301 .eh_device_reset_handler = fas216_eh_device_reset,
302 .eh_abort_handler = fas216_eh_abort,
306 .sg_tablesize = SG_ALL,
308 .use_clustering = ENABLE_CLUSTERING,
309 .proc_name = "powertec",
313 powertecscsi_probe(struct expansion_card *ec, const struct ecard_id *id)
315 struct Scsi_Host *host;
316 struct powertec_info *info;
317 unsigned long resbase, reslen;
321 ret = ecard_request_resources(ec);
325 resbase = ecard_resource_start(ec, ECARD_RES_IOCFAST);
326 reslen = ecard_resource_len(ec, ECARD_RES_IOCFAST);
327 base = ioremap(resbase, reslen);
333 host = scsi_host_alloc(&powertecscsi_template,
334 sizeof (struct powertec_info));
340 ecard_set_drvdata(ec, host);
342 info = (struct powertec_info *)host->hostdata;
344 powertecscsi_terminator_ctl(host, term[ec->slot_no]);
346 info->info.scsi.io_base = base + POWERTEC_FAS216_OFFSET;
347 info->info.scsi.io_shift = POWERTEC_FAS216_SHIFT;
348 info->info.scsi.irq = ec->irq;
349 info->info.scsi.dma = ec->dma;
350 info->info.ifcfg.clockrate = 40; /* MHz */
351 info->info.ifcfg.select_timeout = 255;
352 info->info.ifcfg.asyncperiod = 200; /* ns */
353 info->info.ifcfg.sync_max_depth = 7;
354 info->info.ifcfg.cntl3 = CNTL3_BS8 | CNTL3_FASTSCSI | CNTL3_FASTCLK;
355 info->info.ifcfg.disconnect_ok = 1;
356 info->info.ifcfg.wide_max_size = 0;
357 info->info.ifcfg.capabilities = 0;
358 info->info.dma.setup = powertecscsi_dma_setup;
359 info->info.dma.pseudo = NULL;
360 info->info.dma.stop = powertecscsi_dma_stop;
362 ec->irqaddr = base + POWERTEC_INTR_STATUS;
363 ec->irqmask = POWERTEC_INTR_BIT;
365 ec->ops = &powertecscsi_ops;
367 device_create_file(&ec->dev, &dev_attr_bus_term);
369 ret = fas216_init(host);
373 ret = request_irq(ec->irq, powertecscsi_intr,
374 IRQF_DISABLED, "powertec", info);
376 printk("scsi%d: IRQ%d not free: %d\n",
377 host->host_no, ec->irq, ret);
381 if (info->info.scsi.dma != NO_DMA) {
382 if (request_dma(info->info.scsi.dma, "powertec")) {
383 printk("scsi%d: DMA%d not free, using PIO\n",
384 host->host_no, info->info.scsi.dma);
385 info->info.scsi.dma = NO_DMA;
387 set_dma_speed(info->info.scsi.dma, 180);
388 info->info.ifcfg.capabilities |= FASCAP_DMA;
392 ret = fas216_add(host, &ec->dev);
396 if (info->info.scsi.dma != NO_DMA)
397 free_dma(info->info.scsi.dma);
398 free_irq(ec->irq, host);
401 fas216_release(host);
404 device_remove_file(&ec->dev, &dev_attr_bus_term);
411 ecard_release_resources(ec);
417 static void __devexit powertecscsi_remove(struct expansion_card *ec)
419 struct Scsi_Host *host = ecard_get_drvdata(ec);
420 struct powertec_info *info = (struct powertec_info *)host->hostdata;
422 ecard_set_drvdata(ec, NULL);
425 device_remove_file(&ec->dev, &dev_attr_bus_term);
427 if (info->info.scsi.dma != NO_DMA)
428 free_dma(info->info.scsi.dma);
429 free_irq(ec->irq, info);
433 fas216_release(host);
435 ecard_release_resources(ec);
438 static const struct ecard_id powertecscsi_cids[] = {
439 { MANU_ALSYSTEMS, PROD_ALSYS_SCSIATAPI },
443 static struct ecard_driver powertecscsi_driver = {
444 .probe = powertecscsi_probe,
445 .remove = __devexit_p(powertecscsi_remove),
446 .id_table = powertecscsi_cids,
448 .name = "powertecscsi",
452 static int __init powertecscsi_init(void)
454 return ecard_register_driver(&powertecscsi_driver);
457 static void __exit powertecscsi_exit(void)
459 ecard_remove_driver(&powertecscsi_driver);
462 module_init(powertecscsi_init);
463 module_exit(powertecscsi_exit);
465 MODULE_AUTHOR("Russell King");
466 MODULE_DESCRIPTION("Powertec SCSI driver");
467 module_param_array(term, int, NULL, 0);
468 MODULE_PARM_DESC(term, "SCSI bus termination");
469 MODULE_LICENSE("GPL");