1 // SPDX-License-Identifier: GPL-2.0-only
3 * linux/drivers/acorn/scsi/powertec.c
5 * Copyright (C) 1997-2005 Russell King
7 #include <linux/module.h>
8 #include <linux/blkdev.h>
9 #include <linux/kernel.h>
10 #include <linux/string.h>
11 #include <linux/ioport.h>
12 #include <linux/proc_fs.h>
13 #include <linux/delay.h>
14 #include <linux/interrupt.h>
15 #include <linux/init.h>
16 #include <linux/dma-mapping.h>
19 #include <asm/ecard.h>
21 #include <asm/pgtable.h>
24 #include <scsi/scsi_host.h>
28 #include <scsi/scsicam.h>
30 #define POWERTEC_FAS216_OFFSET 0x3000
31 #define POWERTEC_FAS216_SHIFT 6
33 #define POWERTEC_INTR_STATUS 0x2000
34 #define POWERTEC_INTR_BIT 0x80
36 #define POWERTEC_RESET_CONTROL 0x1018
37 #define POWERTEC_RESET_BIT 1
39 #define POWERTEC_TERM_CONTROL 0x2018
40 #define POWERTEC_TERM_ENABLE 1
42 #define POWERTEC_INTR_CONTROL 0x101c
43 #define POWERTEC_INTR_ENABLE 1
44 #define POWERTEC_INTR_DISABLE 0
46 #define VERSION "1.10 (19/01/2003 2.5.59)"
49 * Use term=0,1,0,0,0 to turn terminators on/off.
52 static int term
[MAX_ECARDS
] = { 1, 1, 1, 1, 1, 1, 1, 1 };
56 struct powertec_info
{
58 struct expansion_card
*ec
;
60 unsigned int term_ctl
;
61 struct scatterlist sg
[NR_SG
];
64 /* Prototype: void powertecscsi_irqenable(ec, irqnr)
65 * Purpose : Enable interrupts on Powertec SCSI card
66 * Params : ec - expansion card structure
67 * : irqnr - interrupt number
70 powertecscsi_irqenable(struct expansion_card
*ec
, int irqnr
)
72 struct powertec_info
*info
= ec
->irq_data
;
73 writeb(POWERTEC_INTR_ENABLE
, info
->base
+ POWERTEC_INTR_CONTROL
);
76 /* Prototype: void powertecscsi_irqdisable(ec, irqnr)
77 * Purpose : Disable interrupts on Powertec SCSI card
78 * Params : ec - expansion card structure
79 * : irqnr - interrupt number
82 powertecscsi_irqdisable(struct expansion_card
*ec
, int irqnr
)
84 struct powertec_info
*info
= ec
->irq_data
;
85 writeb(POWERTEC_INTR_DISABLE
, info
->base
+ POWERTEC_INTR_CONTROL
);
88 static const expansioncard_ops_t powertecscsi_ops
= {
89 .irqenable
= powertecscsi_irqenable
,
90 .irqdisable
= powertecscsi_irqdisable
,
93 /* Prototype: void powertecscsi_terminator_ctl(host, on_off)
94 * Purpose : Turn the Powertec SCSI terminators on or off
95 * Params : host - card to turn on/off
96 * : on_off - !0 to turn on, 0 to turn off
99 powertecscsi_terminator_ctl(struct Scsi_Host
*host
, int on_off
)
101 struct powertec_info
*info
= (struct powertec_info
*)host
->hostdata
;
103 info
->term_ctl
= on_off
? POWERTEC_TERM_ENABLE
: 0;
104 writeb(info
->term_ctl
, info
->base
+ POWERTEC_TERM_CONTROL
);
107 /* Prototype: void powertecscsi_intr(irq, *dev_id, *regs)
108 * Purpose : handle interrupts from Powertec SCSI card
109 * Params : irq - interrupt number
110 * dev_id - user-defined (Scsi_Host structure)
112 static irqreturn_t
powertecscsi_intr(int irq
, void *dev_id
)
114 struct powertec_info
*info
= dev_id
;
116 return fas216_intr(&info
->info
);
119 /* Prototype: fasdmatype_t powertecscsi_dma_setup(host, SCpnt, direction, min_type)
120 * Purpose : initialises DMA/PIO
121 * Params : host - host
123 * direction - DMA on to/off of card
124 * min_type - minimum DMA support that we must have for this transfer
125 * Returns : type of transfer to be performed
128 powertecscsi_dma_setup(struct Scsi_Host
*host
, struct scsi_pointer
*SCp
,
129 fasdmadir_t direction
, fasdmatype_t min_type
)
131 struct powertec_info
*info
= (struct powertec_info
*)host
->hostdata
;
132 struct device
*dev
= scsi_get_device(host
);
133 int dmach
= info
->info
.scsi
.dma
;
135 if (info
->info
.ifcfg
.capabilities
& FASCAP_DMA
&&
136 min_type
== fasdma_real_all
) {
137 int bufs
, map_dir
, dma_dir
;
139 bufs
= copy_SCp_to_sg(&info
->sg
[0], SCp
, NR_SG
);
141 if (direction
== DMA_OUT
)
142 map_dir
= DMA_TO_DEVICE
,
143 dma_dir
= DMA_MODE_WRITE
;
145 map_dir
= DMA_FROM_DEVICE
,
146 dma_dir
= DMA_MODE_READ
;
148 dma_map_sg(dev
, info
->sg
, bufs
, map_dir
);
151 set_dma_sg(dmach
, info
->sg
, bufs
);
152 set_dma_mode(dmach
, dma_dir
);
154 return fasdma_real_all
;
158 * If we're not doing DMA,
164 /* Prototype: int powertecscsi_dma_stop(host, SCpnt)
165 * Purpose : stops DMA/PIO
166 * Params : host - host
170 powertecscsi_dma_stop(struct Scsi_Host
*host
, struct scsi_pointer
*SCp
)
172 struct powertec_info
*info
= (struct powertec_info
*)host
->hostdata
;
173 if (info
->info
.scsi
.dma
!= NO_DMA
)
174 disable_dma(info
->info
.scsi
.dma
);
177 /* Prototype: const char *powertecscsi_info(struct Scsi_Host * host)
178 * Purpose : returns a descriptive string about this interface,
179 * Params : host - driver host structure to return info for.
180 * Returns : pointer to a static buffer containing null terminated string.
182 const char *powertecscsi_info(struct Scsi_Host
*host
)
184 struct powertec_info
*info
= (struct powertec_info
*)host
->hostdata
;
185 static char string
[150];
187 sprintf(string
, "%s (%s) in slot %d v%s terminators o%s",
188 host
->hostt
->name
, info
->info
.scsi
.type
, info
->ec
->slot_no
,
189 VERSION
, info
->term_ctl
? "n" : "ff");
194 /* Prototype: int powertecscsi_set_proc_info(struct Scsi_Host *host, char *buffer, int length)
195 * Purpose : Set a driver specific function
196 * Params : host - host to setup
197 * : buffer - buffer containing string describing operation
198 * : length - length of string
199 * Returns : -EINVAL, or 0
202 powertecscsi_set_proc_info(struct Scsi_Host
*host
, char *buffer
, int length
)
206 if (length
>= 12 && strncmp(buffer
, "POWERTECSCSI", 12) == 0) {
210 if (length
>= 5 && strncmp(buffer
, "term=", 5) == 0) {
211 if (buffer
[5] == '1')
212 powertecscsi_terminator_ctl(host
, 1);
213 else if (buffer
[5] == '0')
214 powertecscsi_terminator_ctl(host
, 0);
225 /* Prototype: int powertecscsi_proc_info(char *buffer, char **start, off_t offset,
226 * int length, int host_no, int inout)
227 * Purpose : Return information about the driver to a user process accessing
228 * the /proc filesystem.
229 * Params : buffer - a buffer to write information to
230 * start - a pointer into this buffer set by this routine to the start
231 * of the required information.
232 * offset - offset into information that we have read up to.
233 * length - length of buffer
234 * inout - 0 for reading, 1 for writing.
235 * Returns : length of data written to buffer.
237 static int powertecscsi_show_info(struct seq_file
*m
, struct Scsi_Host
*host
)
239 struct powertec_info
*info
;
241 info
= (struct powertec_info
*)host
->hostdata
;
243 seq_printf(m
, "PowerTec SCSI driver v%s\n", VERSION
);
244 fas216_print_host(&info
->info
, m
);
245 seq_printf(m
, "Term : o%s\n",
246 info
->term_ctl
? "n" : "ff");
248 fas216_print_stats(&info
->info
, m
);
249 fas216_print_devices(&info
->info
, m
);
253 static ssize_t
powertecscsi_show_term(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
255 struct expansion_card
*ec
= ECARD_DEV(dev
);
256 struct Scsi_Host
*host
= ecard_get_drvdata(ec
);
257 struct powertec_info
*info
= (struct powertec_info
*)host
->hostdata
;
259 return sprintf(buf
, "%d\n", info
->term_ctl
? 1 : 0);
263 powertecscsi_store_term(struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t len
)
265 struct expansion_card
*ec
= ECARD_DEV(dev
);
266 struct Scsi_Host
*host
= ecard_get_drvdata(ec
);
269 powertecscsi_terminator_ctl(host
, buf
[0] != '0');
274 static DEVICE_ATTR(bus_term
, S_IRUGO
| S_IWUSR
,
275 powertecscsi_show_term
, powertecscsi_store_term
);
277 static struct scsi_host_template powertecscsi_template
= {
278 .module
= THIS_MODULE
,
279 .show_info
= powertecscsi_show_info
,
280 .write_info
= powertecscsi_set_proc_info
,
281 .name
= "PowerTec SCSI",
282 .info
= powertecscsi_info
,
283 .queuecommand
= fas216_queue_command
,
284 .eh_host_reset_handler
= fas216_eh_host_reset
,
285 .eh_bus_reset_handler
= fas216_eh_bus_reset
,
286 .eh_device_reset_handler
= fas216_eh_device_reset
,
287 .eh_abort_handler
= fas216_eh_abort
,
291 .sg_tablesize
= SG_MAX_SEGMENTS
,
292 .dma_boundary
= IOMD_DMA_BOUNDARY
,
294 .proc_name
= "powertec",
297 static int powertecscsi_probe(struct expansion_card
*ec
,
298 const struct ecard_id
*id
)
300 struct Scsi_Host
*host
;
301 struct powertec_info
*info
;
305 ret
= ecard_request_resources(ec
);
309 base
= ecardm_iomap(ec
, ECARD_RES_IOCFAST
, 0, 0);
315 host
= scsi_host_alloc(&powertecscsi_template
,
316 sizeof (struct powertec_info
));
322 ecard_set_drvdata(ec
, host
);
324 info
= (struct powertec_info
*)host
->hostdata
;
326 powertecscsi_terminator_ctl(host
, term
[ec
->slot_no
]);
329 info
->info
.scsi
.io_base
= base
+ POWERTEC_FAS216_OFFSET
;
330 info
->info
.scsi
.io_shift
= POWERTEC_FAS216_SHIFT
;
331 info
->info
.scsi
.irq
= ec
->irq
;
332 info
->info
.scsi
.dma
= ec
->dma
;
333 info
->info
.ifcfg
.clockrate
= 40; /* MHz */
334 info
->info
.ifcfg
.select_timeout
= 255;
335 info
->info
.ifcfg
.asyncperiod
= 200; /* ns */
336 info
->info
.ifcfg
.sync_max_depth
= 7;
337 info
->info
.ifcfg
.cntl3
= CNTL3_BS8
| CNTL3_FASTSCSI
| CNTL3_FASTCLK
;
338 info
->info
.ifcfg
.disconnect_ok
= 1;
339 info
->info
.ifcfg
.wide_max_size
= 0;
340 info
->info
.ifcfg
.capabilities
= 0;
341 info
->info
.dma
.setup
= powertecscsi_dma_setup
;
342 info
->info
.dma
.pseudo
= NULL
;
343 info
->info
.dma
.stop
= powertecscsi_dma_stop
;
345 ec
->irqaddr
= base
+ POWERTEC_INTR_STATUS
;
346 ec
->irqmask
= POWERTEC_INTR_BIT
;
348 ecard_setirq(ec
, &powertecscsi_ops
, info
);
350 device_create_file(&ec
->dev
, &dev_attr_bus_term
);
352 ret
= fas216_init(host
);
356 ret
= request_irq(ec
->irq
, powertecscsi_intr
,
357 0, "powertec", info
);
359 printk("scsi%d: IRQ%d not free: %d\n",
360 host
->host_no
, ec
->irq
, ret
);
364 if (info
->info
.scsi
.dma
!= NO_DMA
) {
365 if (request_dma(info
->info
.scsi
.dma
, "powertec")) {
366 printk("scsi%d: DMA%d not free, using PIO\n",
367 host
->host_no
, info
->info
.scsi
.dma
);
368 info
->info
.scsi
.dma
= NO_DMA
;
370 set_dma_speed(info
->info
.scsi
.dma
, 180);
371 info
->info
.ifcfg
.capabilities
|= FASCAP_DMA
;
375 ret
= fas216_add(host
, &ec
->dev
);
379 if (info
->info
.scsi
.dma
!= NO_DMA
)
380 free_dma(info
->info
.scsi
.dma
);
381 free_irq(ec
->irq
, host
);
384 fas216_release(host
);
387 device_remove_file(&ec
->dev
, &dev_attr_bus_term
);
391 ecard_release_resources(ec
);
397 static void powertecscsi_remove(struct expansion_card
*ec
)
399 struct Scsi_Host
*host
= ecard_get_drvdata(ec
);
400 struct powertec_info
*info
= (struct powertec_info
*)host
->hostdata
;
402 ecard_set_drvdata(ec
, NULL
);
405 device_remove_file(&ec
->dev
, &dev_attr_bus_term
);
407 if (info
->info
.scsi
.dma
!= NO_DMA
)
408 free_dma(info
->info
.scsi
.dma
);
409 free_irq(ec
->irq
, info
);
411 fas216_release(host
);
413 ecard_release_resources(ec
);
416 static const struct ecard_id powertecscsi_cids
[] = {
417 { MANU_ALSYSTEMS
, PROD_ALSYS_SCSIATAPI
},
421 static struct ecard_driver powertecscsi_driver
= {
422 .probe
= powertecscsi_probe
,
423 .remove
= powertecscsi_remove
,
424 .id_table
= powertecscsi_cids
,
426 .name
= "powertecscsi",
430 static int __init
powertecscsi_init(void)
432 return ecard_register_driver(&powertecscsi_driver
);
435 static void __exit
powertecscsi_exit(void)
437 ecard_remove_driver(&powertecscsi_driver
);
440 module_init(powertecscsi_init
);
441 module_exit(powertecscsi_exit
);
443 MODULE_AUTHOR("Russell King");
444 MODULE_DESCRIPTION("Powertec SCSI driver");
445 module_param_array(term
, int, NULL
, 0);
446 MODULE_PARM_DESC(term
, "SCSI bus termination");
447 MODULE_LICENSE("GPL");