blob: d25f944b59c27a42e1c034a3e85b75a68326f5e9 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Oak Generic NCR5380 driver
3 *
4 * Copyright 1995-2002, Russell King
5 */
6
7#include <linux/module.h>
8#include <linux/signal.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
17#include "../scsi.h"
18#include <scsi/scsi_host.h>
19
20#define AUTOSENSE
21/*#define PSEUDO_DMA*/
22
23#define OAKSCSI_PUBLIC_RELEASE 1
24
Russell King8b801ea2007-07-20 10:38:54 +010025#define priv(host) ((struct NCR5380_hostdata *)(host)->hostdata)
26#define NCR5380_local_declare() void __iomem *_base
27#define NCR5380_setup(host) _base = priv(host)->base
28
29#define NCR5380_read(reg) readb(_base + ((reg) << 2))
30#define NCR5380_write(reg, value) writeb(value, _base + ((reg) << 2))
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#define NCR5380_intr oakscsi_intr
32#define NCR5380_queue_command oakscsi_queue_command
33#define NCR5380_proc_info oakscsi_proc_info
34
Russell King8b801ea2007-07-20 10:38:54 +010035#define NCR5380_implementation_fields \
36 void __iomem *base
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
38#define BOARD_NORMAL 0
39#define BOARD_NCR53C400 1
40
41#include "../NCR5380.h"
42
43#undef START_DMA_INITIATOR_RECEIVE_REG
Russell King8b801ea2007-07-20 10:38:54 +010044#define START_DMA_INITIATOR_RECEIVE_REG (128 + 7)
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
46const char * oakscsi_info (struct Scsi_Host *spnt)
47{
48 return "";
49}
50
Russell King8b801ea2007-07-20 10:38:54 +010051#define STAT ((128 + 16) << 2)
52#define DATA ((128 + 8) << 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
54static inline int NCR5380_pwrite(struct Scsi_Host *instance, unsigned char *addr,
55 int len)
56{
Russell King8b801ea2007-07-20 10:38:54 +010057 void __iomem *base = priv(instance)->base;
58
Linus Torvalds1da177e2005-04-16 15:20:36 -070059printk("writing %p len %d\n",addr, len);
60 if(!len) return -1;
61
62 while(1)
63 {
64 int status;
Russell King8b801ea2007-07-20 10:38:54 +010065 while (((status = readw(base + STAT)) & 0x100)==0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 }
67}
68
69static inline int NCR5380_pread(struct Scsi_Host *instance, unsigned char *addr,
70 int len)
71{
Russell King8b801ea2007-07-20 10:38:54 +010072 void __iomem *base = priv(instance)->base;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073printk("reading %p len %d\n", addr, len);
74 while(len > 0)
75 {
Russell King8b801ea2007-07-20 10:38:54 +010076 unsigned int status, timeout;
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 unsigned long b;
78
79 timeout = 0x01FFFFFF;
80
Russell King8b801ea2007-07-20 10:38:54 +010081 while (((status = readw(base + STAT)) & 0x100)==0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 {
83 timeout--;
84 if(status & 0x200 || !timeout)
85 {
Russell King8b801ea2007-07-20 10:38:54 +010086 printk("status = %08X\n", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 return 1;
88 }
89 }
Russell King8b801ea2007-07-20 10:38:54 +010090
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 if(len >= 128)
92 {
Russell King8b801ea2007-07-20 10:38:54 +010093 readsw(base + DATA, addr, 128);
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 addr += 128;
95 len -= 128;
96 }
97 else
98 {
Russell King8b801ea2007-07-20 10:38:54 +010099 b = (unsigned long) readw(base + DATA);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 *addr ++ = b;
101 len -= 1;
102 if(len)
103 *addr ++ = b>>8;
104 len -= 1;
105 }
106 }
107 return 0;
108}
109
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110#undef STAT
Russell King8b801ea2007-07-20 10:38:54 +0100111#undef DATA
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
113#include "../NCR5380.c"
114
Christoph Hellwigd0be4a7d2005-10-31 18:31:40 +0100115static struct scsi_host_template oakscsi_template = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 .module = THIS_MODULE,
117 .proc_info = oakscsi_proc_info,
118 .name = "Oak 16-bit SCSI",
119 .info = oakscsi_info,
120 .queuecommand = oakscsi_queue_command,
121 .eh_abort_handler = NCR5380_abort,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 .eh_bus_reset_handler = NCR5380_bus_reset,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 .can_queue = 16,
124 .this_id = 7,
125 .sg_tablesize = SG_ALL,
126 .cmd_per_lun = 2,
127 .use_clustering = DISABLE_CLUSTERING,
128 .proc_name = "oakscsi",
129};
130
131static int __devinit
132oakscsi_probe(struct expansion_card *ec, const struct ecard_id *id)
133{
134 struct Scsi_Host *host;
135 int ret = -ENOMEM;
136
Russell King8b801ea2007-07-20 10:38:54 +0100137 ret = ecard_request_resources(ec);
138 if (ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 goto out;
140
Russell King8b801ea2007-07-20 10:38:54 +0100141 host = scsi_host_alloc(&oakscsi_template, sizeof(struct NCR5380_hostdata));
142 if (!host) {
143 ret = -ENOMEM;
144 goto release;
145 }
146
147 priv(host)->base = ioremap(ecard_resource_start(ec, ECARD_RES_MEMC),
148 ecard_resource_len(ec, ECARD_RES_MEMC));
149 if (!priv(host)->base) {
150 ret = -ENOMEM;
151 goto unreg;
152 }
153
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 host->irq = IRQ_NONE;
155 host->n_io_port = 255;
156
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 NCR5380_init(host, 0);
158
159 printk("scsi%d: at port 0x%08lx irqs disabled",
160 host->host_no, host->io_port);
161 printk(" options CAN_QUEUE=%d CMD_PER_LUN=%d release=%d",
162 host->can_queue, host->cmd_per_lun, OAKSCSI_PUBLIC_RELEASE);
163 printk("\nscsi%d:", host->host_no);
164 NCR5380_print_options(host);
165 printk("\n");
166
167 ret = scsi_add_host(host, &ec->dev);
168 if (ret)
Russell King8b801ea2007-07-20 10:38:54 +0100169 goto out_unmap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170
171 scsi_scan_host(host);
172 goto out;
173
Russell King8b801ea2007-07-20 10:38:54 +0100174 out_unmap:
175 iounmap(priv(host)->base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 unreg:
177 scsi_host_put(host);
Russell King8b801ea2007-07-20 10:38:54 +0100178 release:
179 ecard_release_resources(ec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 out:
181 return ret;
182}
183
184static void __devexit oakscsi_remove(struct expansion_card *ec)
185{
186 struct Scsi_Host *host = ecard_get_drvdata(ec);
187
188 ecard_set_drvdata(ec, NULL);
189 scsi_remove_host(host);
190
191 NCR5380_exit(host);
Russell King8b801ea2007-07-20 10:38:54 +0100192 iounmap(priv(host)->base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 scsi_host_put(host);
Russell King8b801ea2007-07-20 10:38:54 +0100194 ecard_release_resources(ec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195}
196
197static const struct ecard_id oakscsi_cids[] = {
198 { MANU_OAK, PROD_OAK_SCSI },
199 { 0xffff, 0xffff }
200};
201
202static struct ecard_driver oakscsi_driver = {
203 .probe = oakscsi_probe,
204 .remove = __devexit_p(oakscsi_remove),
205 .id_table = oakscsi_cids,
206 .drv = {
207 .name = "oakscsi",
208 },
209};
210
211static int __init oakscsi_init(void)
212{
213 return ecard_register_driver(&oakscsi_driver);
214}
215
216static void __exit oakscsi_exit(void)
217{
218 ecard_remove_driver(&oakscsi_driver);
219}
220
221module_init(oakscsi_init);
222module_exit(oakscsi_exit);
223
224MODULE_AUTHOR("Russell King");
225MODULE_DESCRIPTION("Oak SCSI driver");
226MODULE_LICENSE("GPL");
227