RT-AC66 3.0.0.4.374.130 core
[tomato.git] / release / src-rt-6.x / linux / linux-2.6 / drivers / scsi / arm / cumana_1.c
blobcf9a21cea6d9309b88aa4cb69b2d2addc53aa7a1
1 /*
2 * Generic Generic NCR5380 driver
4 * Copyright 1995-2002, Russell King
5 */
6 #include <linux/module.h>
7 #include <linux/signal.h>
8 #include <linux/ioport.h>
9 #include <linux/delay.h>
10 #include <linux/blkdev.h>
11 #include <linux/init.h>
13 #include <asm/ecard.h>
14 #include <asm/io.h>
15 #include <asm/system.h>
17 #include "../scsi.h"
18 #include <scsi/scsi_host.h>
20 #include <scsi/scsicam.h>
22 #define AUTOSENSE
23 #define PSEUDO_DMA
25 #define CUMANASCSI_PUBLIC_RELEASE 1
27 #define NCR5380_implementation_fields int port, ctrl
28 #define NCR5380_local_declare() struct Scsi_Host *_instance
29 #define NCR5380_setup(instance) _instance = instance
30 #define NCR5380_read(reg) cumanascsi_read(_instance, reg)
31 #define NCR5380_write(reg, value) cumanascsi_write(_instance, reg, value)
32 #define NCR5380_intr cumanascsi_intr
33 #define NCR5380_queue_command cumanascsi_queue_command
34 #define NCR5380_proc_info cumanascsi_proc_info
36 #define BOARD_NORMAL 0
37 #define BOARD_NCR53C400 1
39 #include "../NCR5380.h"
41 void cumanascsi_setup(char *str, int *ints)
45 const char *cumanascsi_info(struct Scsi_Host *spnt)
47 return "";
50 #ifdef NOT_EFFICIENT
51 #define CTRL(p,v) outb(*ctrl = (v), (p) - 577)
52 #define STAT(p) inb((p)+1)
53 #define IN(p) inb((p))
54 #define OUT(v,p) outb((v), (p))
55 #else
56 #define CTRL(p,v) (p[-2308] = (*ctrl = (v)))
57 #define STAT(p) (p[4])
58 #define IN(p) (*(p))
59 #define IN2(p) ((unsigned short)(*(volatile unsigned long *)(p)))
60 #define OUT(v,p) (*(p) = (v))
61 #define OUT2(v,p) (*((volatile unsigned long *)(p)) = (v))
62 #endif
63 #define L(v) (((v)<<16)|((v) & 0x0000ffff))
64 #define H(v) (((v)>>16)|((v) & 0xffff0000))
66 static inline int
67 NCR5380_pwrite(struct Scsi_Host *instance, unsigned char *addr, int len)
69 int *ctrl = &((struct NCR5380_hostdata *)instance->hostdata)->ctrl;
70 int oldctrl = *ctrl;
71 unsigned long *laddr;
72 #ifdef NOT_EFFICIENT
73 int iobase = instance->io_port;
74 int dma_io = iobase & ~(0x3C0000>>2);
75 #else
76 volatile unsigned char *iobase = (unsigned char *)ioaddr(instance->io_port);
77 volatile unsigned char *dma_io = (unsigned char *)((int)iobase & ~0x3C0000);
78 #endif
80 if(!len) return 0;
82 CTRL(iobase, 0x02);
83 laddr = (unsigned long *)addr;
84 while(len >= 32)
86 int status;
87 unsigned long v;
88 status = STAT(iobase);
89 if(status & 0x80)
90 goto end;
91 if(!(status & 0x40))
92 continue;
93 v=*laddr++; OUT2(L(v),dma_io); OUT2(H(v),dma_io);
94 v=*laddr++; OUT2(L(v),dma_io); OUT2(H(v),dma_io);
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 len -= 32;
102 if(len == 0)
103 break;
106 addr = (unsigned char *)laddr;
107 CTRL(iobase, 0x12);
108 while(len > 0)
110 int status;
111 status = STAT(iobase);
112 if(status & 0x80)
113 goto end;
114 if(status & 0x40)
116 OUT(*addr++, dma_io);
117 if(--len == 0)
118 break;
121 status = STAT(iobase);
122 if(status & 0x80)
123 goto end;
124 if(status & 0x40)
126 OUT(*addr++, dma_io);
127 if(--len == 0)
128 break;
131 end:
132 CTRL(iobase, oldctrl|0x40);
133 return len;
136 static inline int
137 NCR5380_pread(struct Scsi_Host *instance, unsigned char *addr, int len)
139 int *ctrl = &((struct NCR5380_hostdata *)instance->hostdata)->ctrl;
140 int oldctrl = *ctrl;
141 unsigned long *laddr;
142 #ifdef NOT_EFFICIENT
143 int iobase = instance->io_port;
144 int dma_io = iobase & ~(0x3C0000>>2);
145 #else
146 volatile unsigned char *iobase = (unsigned char *)ioaddr(instance->io_port);
147 volatile unsigned char *dma_io = (unsigned char *)((int)iobase & ~0x3C0000);
148 #endif
150 if(!len) return 0;
152 CTRL(iobase, 0x00);
153 laddr = (unsigned long *)addr;
154 while(len >= 32)
156 int status;
157 status = STAT(iobase);
158 if(status & 0x80)
159 goto end;
160 if(!(status & 0x40))
161 continue;
162 *laddr++ = IN2(dma_io)|(IN2(dma_io)<<16);
163 *laddr++ = IN2(dma_io)|(IN2(dma_io)<<16);
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 len -= 32;
171 if(len == 0)
172 break;
175 addr = (unsigned char *)laddr;
176 CTRL(iobase, 0x10);
177 while(len > 0)
179 int status;
180 status = STAT(iobase);
181 if(status & 0x80)
182 goto end;
183 if(status & 0x40)
185 *addr++ = IN(dma_io);
186 if(--len == 0)
187 break;
190 status = STAT(iobase);
191 if(status & 0x80)
192 goto end;
193 if(status & 0x40)
195 *addr++ = IN(dma_io);
196 if(--len == 0)
197 break;
200 end:
201 CTRL(iobase, oldctrl|0x40);
202 return len;
205 #undef STAT
206 #undef CTRL
207 #undef IN
208 #undef OUT
210 #define CTRL(p,v) outb(*ctrl = (v), (p) - 577)
212 static char cumanascsi_read(struct Scsi_Host *instance, int reg)
214 unsigned int iobase = instance->io_port;
215 int i;
216 int *ctrl = &((struct NCR5380_hostdata *)instance->hostdata)->ctrl;
218 CTRL(iobase, 0);
219 i = inb(iobase + 64 + reg);
220 CTRL(iobase, 0x40);
222 return i;
225 static void cumanascsi_write(struct Scsi_Host *instance, int reg, int value)
227 int iobase = instance->io_port;
228 int *ctrl = &((struct NCR5380_hostdata *)instance->hostdata)->ctrl;
230 CTRL(iobase, 0);
231 outb(value, iobase + 64 + reg);
232 CTRL(iobase, 0x40);
235 #undef CTRL
237 #include "../NCR5380.c"
239 static struct scsi_host_template cumanascsi_template = {
240 .module = THIS_MODULE,
241 .name = "Cumana 16-bit SCSI",
242 .info = cumanascsi_info,
243 .queuecommand = cumanascsi_queue_command,
244 .eh_abort_handler = NCR5380_abort,
245 .eh_bus_reset_handler = NCR5380_bus_reset,
246 .can_queue = 16,
247 .this_id = 7,
248 .sg_tablesize = SG_ALL,
249 .cmd_per_lun = 2,
250 .unchecked_isa_dma = 0,
251 .use_clustering = DISABLE_CLUSTERING,
252 .proc_name = "CumanaSCSI-1",
255 static int __devinit
256 cumanascsi1_probe(struct expansion_card *ec, const struct ecard_id *id)
258 struct Scsi_Host *host;
259 int ret = -ENOMEM;
261 host = scsi_host_alloc(&cumanascsi_template, sizeof(struct NCR5380_hostdata));
262 if (!host)
263 goto out;
265 host->io_port = ecard_address(ec, ECARD_IOC, ECARD_SLOW) + 0x800;
266 host->irq = ec->irq;
268 NCR5380_init(host, 0);
270 host->n_io_port = 255;
271 if (!(request_region(host->io_port, host->n_io_port, "CumanaSCSI-1"))) {
272 ret = -EBUSY;
273 goto out_free;
276 ((struct NCR5380_hostdata *)host->hostdata)->ctrl = 0;
277 outb(0x00, host->io_port - 577);
279 ret = request_irq(host->irq, cumanascsi_intr, IRQF_DISABLED,
280 "CumanaSCSI-1", host);
281 if (ret) {
282 printk("scsi%d: IRQ%d not free: %d\n",
283 host->host_no, host->irq, ret);
284 goto out_release;
287 printk("scsi%d: at port 0x%08lx irq %d",
288 host->host_no, host->io_port, host->irq);
289 printk(" options CAN_QUEUE=%d CMD_PER_LUN=%d release=%d",
290 host->can_queue, host->cmd_per_lun, CUMANASCSI_PUBLIC_RELEASE);
291 printk("\nscsi%d:", host->host_no);
292 NCR5380_print_options(host);
293 printk("\n");
295 ret = scsi_add_host(host, &ec->dev);
296 if (ret)
297 goto out_free_irq;
299 scsi_scan_host(host);
300 goto out;
302 out_free_irq:
303 free_irq(host->irq, host);
304 out_release:
305 release_region(host->io_port, host->n_io_port);
306 out_free:
307 scsi_host_put(host);
308 out:
309 return ret;
312 static void __devexit cumanascsi1_remove(struct expansion_card *ec)
314 struct Scsi_Host *host = ecard_get_drvdata(ec);
316 ecard_set_drvdata(ec, NULL);
318 scsi_remove_host(host);
319 free_irq(host->irq, host);
320 NCR5380_exit(host);
321 release_region(host->io_port, host->n_io_port);
322 scsi_host_put(host);
325 static const struct ecard_id cumanascsi1_cids[] = {
326 { MANU_CUMANA, PROD_CUMANA_SCSI_1 },
327 { 0xffff, 0xffff }
330 static struct ecard_driver cumanascsi1_driver = {
331 .probe = cumanascsi1_probe,
332 .remove = __devexit_p(cumanascsi1_remove),
333 .id_table = cumanascsi1_cids,
334 .drv = {
335 .name = "cumanascsi1",
339 static int __init cumanascsi_init(void)
341 return ecard_register_driver(&cumanascsi1_driver);
344 static void __exit cumanascsi_exit(void)
346 ecard_remove_driver(&cumanascsi1_driver);
349 module_init(cumanascsi_init);
350 module_exit(cumanascsi_exit);
352 MODULE_DESCRIPTION("Cumana SCSI-1 driver for Acorn machines");
353 MODULE_LICENSE("GPL");