blob: a3398fe70a9c5f8d0214869f7bf8f921d30b07cd [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Generic Generic NCR5380 driver
3 *
4 * Copyright 1995-2002, Russell King
5 */
6#include <linux/module.h>
7#include <linux/signal.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008#include <linux/ioport.h>
9#include <linux/delay.h>
10#include <linux/blkdev.h>
11#include <linux/init.h>
12
13#include <asm/ecard.h>
14#include <asm/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <asm/system.h>
16
17#include "../scsi.h"
18#include <scsi/scsi_host.h>
19
20#include <scsi/scsicam.h>
21
22#define AUTOSENSE
23#define PSEUDO_DMA
24
25#define CUMANASCSI_PUBLIC_RELEASE 1
26
Russell King8b801ea2007-07-20 10:38:54 +010027#define priv(host) ((struct NCR5380_hostdata *)(host)->hostdata)
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#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
35
Russell King8b801ea2007-07-20 10:38:54 +010036#define NCR5380_implementation_fields \
37 unsigned ctrl; \
38 void __iomem *base; \
39 void __iomem *dma
40
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#define BOARD_NORMAL 0
42#define BOARD_NCR53C400 1
43
44#include "../NCR5380.h"
45
46void cumanascsi_setup(char *str, int *ints)
47{
48}
49
50const char *cumanascsi_info(struct Scsi_Host *spnt)
51{
52 return "";
53}
54
Russell King8b801ea2007-07-20 10:38:54 +010055#define CTRL 0x16fc
56#define STAT 0x2004
57#define L(v) (((v)<<16)|((v) & 0x0000ffff))
58#define H(v) (((v)>>16)|((v) & 0xffff0000))
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
60static inline int
Russell King8b801ea2007-07-20 10:38:54 +010061NCR5380_pwrite(struct Scsi_Host *host, unsigned char *addr, int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -070062{
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 unsigned long *laddr;
Russell King8b801ea2007-07-20 10:38:54 +010064 void __iomem *dma = priv(host)->dma + 0x2000;
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
66 if(!len) return 0;
67
Russell King8b801ea2007-07-20 10:38:54 +010068 writeb(0x02, priv(host)->base + CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 laddr = (unsigned long *)addr;
70 while(len >= 32)
71 {
Russell King8b801ea2007-07-20 10:38:54 +010072 unsigned int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 unsigned long v;
Russell King8b801ea2007-07-20 10:38:54 +010074 status = readb(priv(host)->base + STAT);
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 if(status & 0x80)
76 goto end;
77 if(!(status & 0x40))
78 continue;
Russell King8b801ea2007-07-20 10:38:54 +010079 v=*laddr++; writew(L(v), dma); writew(H(v), dma);
80 v=*laddr++; writew(L(v), dma); writew(H(v), dma);
81 v=*laddr++; writew(L(v), dma); writew(H(v), dma);
82 v=*laddr++; writew(L(v), dma); writew(H(v), dma);
83 v=*laddr++; writew(L(v), dma); writew(H(v), dma);
84 v=*laddr++; writew(L(v), dma); writew(H(v), dma);
85 v=*laddr++; writew(L(v), dma); writew(H(v), dma);
86 v=*laddr++; writew(L(v), dma); writew(H(v), dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 len -= 32;
88 if(len == 0)
89 break;
90 }
91
92 addr = (unsigned char *)laddr;
Russell King8b801ea2007-07-20 10:38:54 +010093 writeb(0x12, priv(host)->base + CTRL);
94
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 while(len > 0)
96 {
Russell King8b801ea2007-07-20 10:38:54 +010097 unsigned int status;
98 status = readb(priv(host)->base + STAT);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 if(status & 0x80)
100 goto end;
101 if(status & 0x40)
102 {
Russell King8b801ea2007-07-20 10:38:54 +0100103 writeb(*addr++, dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 if(--len == 0)
105 break;
106 }
107
Russell King8b801ea2007-07-20 10:38:54 +0100108 status = readb(priv(host)->base + STAT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 if(status & 0x80)
110 goto end;
111 if(status & 0x40)
112 {
Russell King8b801ea2007-07-20 10:38:54 +0100113 writeb(*addr++, dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 if(--len == 0)
115 break;
116 }
117 }
118end:
Russell King8b801ea2007-07-20 10:38:54 +0100119 writeb(priv(host)->ctrl | 0x40, priv(host)->base + CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 return len;
121}
122
123static inline int
Russell King8b801ea2007-07-20 10:38:54 +0100124NCR5380_pread(struct Scsi_Host *host, unsigned char *addr, int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 unsigned long *laddr;
Russell King8b801ea2007-07-20 10:38:54 +0100127 void __iomem *dma = priv(host)->dma + 0x2000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128
129 if(!len) return 0;
130
Russell King8b801ea2007-07-20 10:38:54 +0100131 writeb(0x00, priv(host)->base + CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 laddr = (unsigned long *)addr;
133 while(len >= 32)
134 {
Russell King8b801ea2007-07-20 10:38:54 +0100135 unsigned int status;
136 status = readb(priv(host)->base + STAT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 if(status & 0x80)
138 goto end;
139 if(!(status & 0x40))
140 continue;
Russell King8b801ea2007-07-20 10:38:54 +0100141 *laddr++ = readw(dma) | (readw(dma) << 16);
142 *laddr++ = readw(dma) | (readw(dma) << 16);
143 *laddr++ = readw(dma) | (readw(dma) << 16);
144 *laddr++ = readw(dma) | (readw(dma) << 16);
145 *laddr++ = readw(dma) | (readw(dma) << 16);
146 *laddr++ = readw(dma) | (readw(dma) << 16);
147 *laddr++ = readw(dma) | (readw(dma) << 16);
148 *laddr++ = readw(dma) | (readw(dma) << 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 len -= 32;
150 if(len == 0)
151 break;
152 }
153
154 addr = (unsigned char *)laddr;
Russell King8b801ea2007-07-20 10:38:54 +0100155 writeb(0x10, priv(host)->base + CTRL);
156
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 while(len > 0)
158 {
Russell King8b801ea2007-07-20 10:38:54 +0100159 unsigned int status;
160 status = readb(priv(host)->base + STAT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 if(status & 0x80)
162 goto end;
163 if(status & 0x40)
164 {
Russell King8b801ea2007-07-20 10:38:54 +0100165 *addr++ = readb(dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 if(--len == 0)
167 break;
168 }
169
Russell King8b801ea2007-07-20 10:38:54 +0100170 status = readb(priv(host)->base + STAT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 if(status & 0x80)
172 goto end;
173 if(status & 0x40)
174 {
Russell King8b801ea2007-07-20 10:38:54 +0100175 *addr++ = readb(dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 if(--len == 0)
177 break;
178 }
179 }
180end:
Russell King8b801ea2007-07-20 10:38:54 +0100181 writeb(priv(host)->ctrl | 0x40, priv(host)->base + CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 return len;
183}
184
Russell King8b801ea2007-07-20 10:38:54 +0100185static unsigned char cumanascsi_read(struct Scsi_Host *host, unsigned int reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186{
Russell King8b801ea2007-07-20 10:38:54 +0100187 void __iomem *base = priv(host)->base;
188 unsigned char val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189
Russell King8b801ea2007-07-20 10:38:54 +0100190 writeb(0, base + CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
Russell King8b801ea2007-07-20 10:38:54 +0100192 val = readb(base + 0x2100 + (reg << 2));
193
194 priv(host)->ctrl = 0x40;
195 writeb(0x40, base + CTRL);
196
197 return val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198}
199
Russell King8b801ea2007-07-20 10:38:54 +0100200static void cumanascsi_write(struct Scsi_Host *host, unsigned int reg, unsigned int value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201{
Russell King8b801ea2007-07-20 10:38:54 +0100202 void __iomem *base = priv(host)->base;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203
Russell King8b801ea2007-07-20 10:38:54 +0100204 writeb(0, base + CTRL);
205
206 writeb(value, base + 0x2100 + (reg << 2));
207
208 priv(host)->ctrl = 0x40;
209 writeb(0x40, base + CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210}
211
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212#include "../NCR5380.c"
213
Christoph Hellwigd0be4a7d2005-10-31 18:31:40 +0100214static struct scsi_host_template cumanascsi_template = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 .module = THIS_MODULE,
216 .name = "Cumana 16-bit SCSI",
217 .info = cumanascsi_info,
218 .queuecommand = cumanascsi_queue_command,
219 .eh_abort_handler = NCR5380_abort,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 .eh_bus_reset_handler = NCR5380_bus_reset,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 .can_queue = 16,
222 .this_id = 7,
223 .sg_tablesize = SG_ALL,
224 .cmd_per_lun = 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 .use_clustering = DISABLE_CLUSTERING,
226 .proc_name = "CumanaSCSI-1",
227};
228
229static int __devinit
230cumanascsi1_probe(struct expansion_card *ec, const struct ecard_id *id)
231{
232 struct Scsi_Host *host;
Russell King8b801ea2007-07-20 10:38:54 +0100233 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234
Russell King8b801ea2007-07-20 10:38:54 +0100235 ret = ecard_request_resources(ec);
236 if (ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 goto out;
238
Russell King8b801ea2007-07-20 10:38:54 +0100239 host = scsi_host_alloc(&cumanascsi_template, sizeof(struct NCR5380_hostdata));
240 if (!host) {
241 ret = -ENOMEM;
242 goto out_release;
243 }
244
245 priv(host)->base = ioremap(ecard_resource_start(ec, ECARD_RES_IOCSLOW),
246 ecard_resource_len(ec, ECARD_RES_IOCSLOW));
247 priv(host)->dma = ioremap(ecard_resource_start(ec, ECARD_RES_MEMC),
248 ecard_resource_len(ec, ECARD_RES_MEMC));
249 if (!priv(host)->base || !priv(host)->dma) {
250 ret = -ENOMEM;
251 goto out_unmap;
252 }
253
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 host->irq = ec->irq;
255
256 NCR5380_init(host, 0);
257
Russell King8b801ea2007-07-20 10:38:54 +0100258 priv(host)->ctrl = 0;
259 writeb(0, priv(host)->base + CTRL);
260
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 host->n_io_port = 255;
262 if (!(request_region(host->io_port, host->n_io_port, "CumanaSCSI-1"))) {
263 ret = -EBUSY;
Russell King8b801ea2007-07-20 10:38:54 +0100264 goto out_unmap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 }
266
Thomas Gleixner1d6f3592006-07-01 19:29:42 -0700267 ret = request_irq(host->irq, cumanascsi_intr, IRQF_DISABLED,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 "CumanaSCSI-1", host);
269 if (ret) {
270 printk("scsi%d: IRQ%d not free: %d\n",
271 host->host_no, host->irq, ret);
Russell King8b801ea2007-07-20 10:38:54 +0100272 goto out_unmap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 }
274
275 printk("scsi%d: at port 0x%08lx irq %d",
276 host->host_no, host->io_port, host->irq);
277 printk(" options CAN_QUEUE=%d CMD_PER_LUN=%d release=%d",
278 host->can_queue, host->cmd_per_lun, CUMANASCSI_PUBLIC_RELEASE);
279 printk("\nscsi%d:", host->host_no);
280 NCR5380_print_options(host);
281 printk("\n");
282
283 ret = scsi_add_host(host, &ec->dev);
284 if (ret)
285 goto out_free_irq;
286
287 scsi_scan_host(host);
288 goto out;
289
290 out_free_irq:
291 free_irq(host->irq, host);
Russell King8b801ea2007-07-20 10:38:54 +0100292 out_unmap:
293 iounmap(priv(host)->base);
294 iounmap(priv(host)->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 scsi_host_put(host);
Russell King8b801ea2007-07-20 10:38:54 +0100296 out_release:
297 ecard_release_resources(ec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 out:
299 return ret;
300}
301
302static void __devexit cumanascsi1_remove(struct expansion_card *ec)
303{
304 struct Scsi_Host *host = ecard_get_drvdata(ec);
305
306 ecard_set_drvdata(ec, NULL);
307
308 scsi_remove_host(host);
309 free_irq(host->irq, host);
310 NCR5380_exit(host);
Russell King8b801ea2007-07-20 10:38:54 +0100311 iounmap(priv(host)->base);
312 iounmap(priv(host)->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 scsi_host_put(host);
Russell King8b801ea2007-07-20 10:38:54 +0100314 ecard_release_resources(ec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315}
316
317static const struct ecard_id cumanascsi1_cids[] = {
318 { MANU_CUMANA, PROD_CUMANA_SCSI_1 },
319 { 0xffff, 0xffff }
320};
321
322static struct ecard_driver cumanascsi1_driver = {
323 .probe = cumanascsi1_probe,
324 .remove = __devexit_p(cumanascsi1_remove),
325 .id_table = cumanascsi1_cids,
326 .drv = {
327 .name = "cumanascsi1",
328 },
329};
330
331static int __init cumanascsi_init(void)
332{
333 return ecard_register_driver(&cumanascsi1_driver);
334}
335
336static void __exit cumanascsi_exit(void)
337{
338 ecard_remove_driver(&cumanascsi1_driver);
339}
340
341module_init(cumanascsi_init);
342module_exit(cumanascsi_exit);
343
344MODULE_DESCRIPTION("Cumana SCSI-1 driver for Acorn machines");
345MODULE_LICENSE("GPL");