aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/arm/cumana_1.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/scsi/arm/cumana_1.c
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'drivers/scsi/arm/cumana_1.c')
-rw-r--r--drivers/scsi/arm/cumana_1.c357
1 files changed, 357 insertions, 0 deletions
diff --git a/drivers/scsi/arm/cumana_1.c b/drivers/scsi/arm/cumana_1.c
new file mode 100644
index 000000000000..27271bfc01d7
--- /dev/null
+++ b/drivers/scsi/arm/cumana_1.c
@@ -0,0 +1,357 @@
1/*
2 * Generic Generic NCR5380 driver
3 *
4 * Copyright 1995-2002, Russell King
5 */
6#include <linux/module.h>
7#include <linux/signal.h>
8#include <linux/sched.h>
9#include <linux/ioport.h>
10#include <linux/delay.h>
11#include <linux/blkdev.h>
12#include <linux/init.h>
13
14#include <asm/ecard.h>
15#include <asm/io.h>
16#include <asm/irq.h>
17#include <asm/system.h>
18
19#include "../scsi.h"
20#include <scsi/scsi_host.h>
21
22#include <scsi/scsicam.h>
23
24#define AUTOSENSE
25#define PSEUDO_DMA
26
27#define CUMANASCSI_PUBLIC_RELEASE 1
28
29#define NCR5380_implementation_fields int port, ctrl
30#define NCR5380_local_declare() struct Scsi_Host *_instance
31#define NCR5380_setup(instance) _instance = instance
32#define NCR5380_read(reg) cumanascsi_read(_instance, reg)
33#define NCR5380_write(reg, value) cumanascsi_write(_instance, reg, value)
34#define NCR5380_intr cumanascsi_intr
35#define NCR5380_queue_command cumanascsi_queue_command
36#define NCR5380_proc_info cumanascsi_proc_info
37
38#define BOARD_NORMAL 0
39#define BOARD_NCR53C400 1
40
41#include "../NCR5380.h"
42
43void cumanascsi_setup(char *str, int *ints)
44{
45}
46
47const char *cumanascsi_info(struct Scsi_Host *spnt)
48{
49 return "";
50}
51
52#ifdef NOT_EFFICIENT
53#define CTRL(p,v) outb(*ctrl = (v), (p) - 577)
54#define STAT(p) inb((p)+1)
55#define IN(p) inb((p))
56#define OUT(v,p) outb((v), (p))
57#else
58#define CTRL(p,v) (p[-2308] = (*ctrl = (v)))
59#define STAT(p) (p[4])
60#define IN(p) (*(p))
61#define IN2(p) ((unsigned short)(*(volatile unsigned long *)(p)))
62#define OUT(v,p) (*(p) = (v))
63#define OUT2(v,p) (*((volatile unsigned long *)(p)) = (v))
64#endif
65#define L(v) (((v)<<16)|((v) & 0x0000ffff))
66#define H(v) (((v)>>16)|((v) & 0xffff0000))
67
68static inline int
69NCR5380_pwrite(struct Scsi_Host *instance, unsigned char *addr, int len)
70{
71 int *ctrl = &((struct NCR5380_hostdata *)instance->hostdata)->ctrl;
72 int oldctrl = *ctrl;
73 unsigned long *laddr;
74#ifdef NOT_EFFICIENT
75 int iobase = instance->io_port;
76 int dma_io = iobase & ~(0x3C0000>>2);
77#else
78 volatile unsigned char *iobase = (unsigned char *)ioaddr(instance->io_port);
79 volatile unsigned char *dma_io = (unsigned char *)((int)iobase & ~0x3C0000);
80#endif
81
82 if(!len) return 0;
83
84 CTRL(iobase, 0x02);
85 laddr = (unsigned long *)addr;
86 while(len >= 32)
87 {
88 int status;
89 unsigned long v;
90 status = STAT(iobase);
91 if(status & 0x80)
92 goto end;
93 if(!(status & 0x40))
94 continue;
95 v=*laddr++; OUT2(L(v),dma_io); OUT2(H(v),dma_io);
96 v=*laddr++; OUT2(L(v),dma_io); OUT2(H(v),dma_io);
97 v=*laddr++; OUT2(L(v),dma_io); OUT2(H(v),dma_io);
98 v=*laddr++; OUT2(L(v),dma_io); OUT2(H(v),dma_io);
99 v=*laddr++; OUT2(L(v),dma_io); OUT2(H(v),dma_io);
100 v=*laddr++; OUT2(L(v),dma_io); OUT2(H(v),dma_io);
101 v=*laddr++; OUT2(L(v),dma_io); OUT2(H(v),dma_io);
102 v=*laddr++; OUT2(L(v),dma_io); OUT2(H(v),dma_io);
103 len -= 32;
104 if(len == 0)
105 break;
106 }
107
108 addr = (unsigned char *)laddr;
109 CTRL(iobase, 0x12);
110 while(len > 0)
111 {
112 int status;
113 status = STAT(iobase);
114 if(status & 0x80)
115 goto end;
116 if(status & 0x40)
117 {
118 OUT(*addr++, dma_io);
119 if(--len == 0)
120 break;
121 }
122
123 status = STAT(iobase);
124 if(status & 0x80)
125 goto end;
126 if(status & 0x40)
127 {
128 OUT(*addr++, dma_io);
129 if(--len == 0)
130 break;
131 }
132 }
133end:
134 CTRL(iobase, oldctrl|0x40);
135 return len;
136}
137
138static inline int
139NCR5380_pread(struct Scsi_Host *instance, unsigned char *addr, int len)
140{
141 int *ctrl = &((struct NCR5380_hostdata *)instance->hostdata)->ctrl;
142 int oldctrl = *ctrl;
143 unsigned long *laddr;
144#ifdef NOT_EFFICIENT
145 int iobase = instance->io_port;
146 int dma_io = iobase & ~(0x3C0000>>2);
147#else
148 volatile unsigned char *iobase = (unsigned char *)ioaddr(instance->io_port);
149 volatile unsigned char *dma_io = (unsigned char *)((int)iobase & ~0x3C0000);
150#endif
151
152 if(!len) return 0;
153
154 CTRL(iobase, 0x00);
155 laddr = (unsigned long *)addr;
156 while(len >= 32)
157 {
158 int status;
159 status = STAT(iobase);
160 if(status & 0x80)
161 goto end;
162 if(!(status & 0x40))
163 continue;
164 *laddr++ = IN2(dma_io)|(IN2(dma_io)<<16);
165 *laddr++ = IN2(dma_io)|(IN2(dma_io)<<16);
166 *laddr++ = IN2(dma_io)|(IN2(dma_io)<<16);
167 *laddr++ = IN2(dma_io)|(IN2(dma_io)<<16);
168 *laddr++ = IN2(dma_io)|(IN2(dma_io)<<16);
169 *laddr++ = IN2(dma_io)|(IN2(dma_io)<<16);
170 *laddr++ = IN2(dma_io)|(IN2(dma_io)<<16);
171 *laddr++ = IN2(dma_io)|(IN2(dma_io)<<16);
172 len -= 32;
173 if(len == 0)
174 break;
175 }
176
177 addr = (unsigned char *)laddr;
178 CTRL(iobase, 0x10);
179 while(len > 0)
180 {
181 int status;
182 status = STAT(iobase);
183 if(status & 0x80)
184 goto end;
185 if(status & 0x40)
186 {
187 *addr++ = IN(dma_io);
188 if(--len == 0)
189 break;
190 }
191
192 status = STAT(iobase);
193 if(status & 0x80)
194 goto end;
195 if(status & 0x40)
196 {
197 *addr++ = IN(dma_io);
198 if(--len == 0)
199 break;
200 }
201 }
202end:
203 CTRL(iobase, oldctrl|0x40);
204 return len;
205}
206
207#undef STAT
208#undef CTRL
209#undef IN
210#undef OUT
211
212#define CTRL(p,v) outb(*ctrl = (v), (p) - 577)
213
214static char cumanascsi_read(struct Scsi_Host *instance, int reg)
215{
216 unsigned int iobase = instance->io_port;
217 int i;
218 int *ctrl = &((struct NCR5380_hostdata *)instance->hostdata)->ctrl;
219
220 CTRL(iobase, 0);
221 i = inb(iobase + 64 + reg);
222 CTRL(iobase, 0x40);
223
224 return i;
225}
226
227static void cumanascsi_write(struct Scsi_Host *instance, int reg, int value)
228{
229 int iobase = instance->io_port;
230 int *ctrl = &((struct NCR5380_hostdata *)instance->hostdata)->ctrl;
231
232 CTRL(iobase, 0);
233 outb(value, iobase + 64 + reg);
234 CTRL(iobase, 0x40);
235}
236
237#undef CTRL
238
239#include "../NCR5380.c"
240
241static Scsi_Host_Template cumanascsi_template = {
242 .module = THIS_MODULE,
243 .name = "Cumana 16-bit SCSI",
244 .info = cumanascsi_info,
245 .queuecommand = cumanascsi_queue_command,
246 .eh_abort_handler = NCR5380_abort,
247 .eh_device_reset_handler= NCR5380_device_reset,
248 .eh_bus_reset_handler = NCR5380_bus_reset,
249 .eh_host_reset_handler = NCR5380_host_reset,
250 .can_queue = 16,
251 .this_id = 7,
252 .sg_tablesize = SG_ALL,
253 .cmd_per_lun = 2,
254 .unchecked_isa_dma = 0,
255 .use_clustering = DISABLE_CLUSTERING,
256 .proc_name = "CumanaSCSI-1",
257};
258
259static int __devinit
260cumanascsi1_probe(struct expansion_card *ec, const struct ecard_id *id)
261{
262 struct Scsi_Host *host;
263 int ret = -ENOMEM;
264
265 host = scsi_host_alloc(&cumanascsi_template, sizeof(struct NCR5380_hostdata));
266 if (!host)
267 goto out;
268
269 host->io_port = ecard_address(ec, ECARD_IOC, ECARD_SLOW) + 0x800;
270 host->irq = ec->irq;
271
272 NCR5380_init(host, 0);
273
274 host->n_io_port = 255;
275 if (!(request_region(host->io_port, host->n_io_port, "CumanaSCSI-1"))) {
276 ret = -EBUSY;
277 goto out_free;
278 }
279
280 ((struct NCR5380_hostdata *)host->hostdata)->ctrl = 0;
281 outb(0x00, host->io_port - 577);
282
283 ret = request_irq(host->irq, cumanascsi_intr, SA_INTERRUPT,
284 "CumanaSCSI-1", host);
285 if (ret) {
286 printk("scsi%d: IRQ%d not free: %d\n",
287 host->host_no, host->irq, ret);
288 goto out_release;
289 }
290
291 printk("scsi%d: at port 0x%08lx irq %d",
292 host->host_no, host->io_port, host->irq);
293 printk(" options CAN_QUEUE=%d CMD_PER_LUN=%d release=%d",
294 host->can_queue, host->cmd_per_lun, CUMANASCSI_PUBLIC_RELEASE);
295 printk("\nscsi%d:", host->host_no);
296 NCR5380_print_options(host);
297 printk("\n");
298
299 ret = scsi_add_host(host, &ec->dev);
300 if (ret)
301 goto out_free_irq;
302
303 scsi_scan_host(host);
304 goto out;
305
306 out_free_irq:
307 free_irq(host->irq, host);
308 out_release:
309 release_region(host->io_port, host->n_io_port);
310 out_free:
311 scsi_host_put(host);
312 out:
313 return ret;
314}
315
316static void __devexit cumanascsi1_remove(struct expansion_card *ec)
317{
318 struct Scsi_Host *host = ecard_get_drvdata(ec);
319
320 ecard_set_drvdata(ec, NULL);
321
322 scsi_remove_host(host);
323 free_irq(host->irq, host);
324 NCR5380_exit(host);
325 release_region(host->io_port, host->n_io_port);
326 scsi_host_put(host);
327}
328
329static const struct ecard_id cumanascsi1_cids[] = {
330 { MANU_CUMANA, PROD_CUMANA_SCSI_1 },
331 { 0xffff, 0xffff }
332};
333
334static struct ecard_driver cumanascsi1_driver = {
335 .probe = cumanascsi1_probe,
336 .remove = __devexit_p(cumanascsi1_remove),
337 .id_table = cumanascsi1_cids,
338 .drv = {
339 .name = "cumanascsi1",
340 },
341};
342
343static int __init cumanascsi_init(void)
344{
345 return ecard_register_driver(&cumanascsi1_driver);
346}
347
348static void __exit cumanascsi_exit(void)
349{
350 ecard_remove_driver(&cumanascsi1_driver);
351}
352
353module_init(cumanascsi_init);
354module_exit(cumanascsi_exit);
355
356MODULE_DESCRIPTION("Cumana SCSI-1 driver for Acorn machines");
357MODULE_LICENSE("GPL");