blob: 4266eef8aca12256b469b0983e39c652ac43f7c0 [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
Arnd Bergmannea065f12012-04-30 16:26:31 +000024#define DONT_USE_INTR
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
Russell King8b801ea2007-07-20 10:38:54 +010026#define priv(host) ((struct NCR5380_hostdata *)(host)->hostdata)
27#define NCR5380_local_declare() void __iomem *_base
28#define NCR5380_setup(host) _base = priv(host)->base
29
30#define NCR5380_read(reg) readb(_base + ((reg) << 2))
31#define NCR5380_write(reg, value) writeb(value, _base + ((reg) << 2))
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#define NCR5380_intr oakscsi_intr
33#define NCR5380_queue_command oakscsi_queue_command
Al Virodd7ab712013-03-31 01:15:54 -040034#define NCR5380_show_info oakscsi_show_info
35#define NCR5380_write_info oakscsi_write_info
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
Russell King8b801ea2007-07-20 10:38:54 +010037#define NCR5380_implementation_fields \
38 void __iomem *base
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
40#define BOARD_NORMAL 0
41#define BOARD_NCR53C400 1
42
43#include "../NCR5380.h"
44
45#undef START_DMA_INITIATOR_RECEIVE_REG
Russell King8b801ea2007-07-20 10:38:54 +010046#define START_DMA_INITIATOR_RECEIVE_REG (128 + 7)
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
48const char * oakscsi_info (struct Scsi_Host *spnt)
49{
50 return "";
51}
52
Russell King8b801ea2007-07-20 10:38:54 +010053#define STAT ((128 + 16) << 2)
54#define DATA ((128 + 8) << 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
56static inline int NCR5380_pwrite(struct Scsi_Host *instance, unsigned char *addr,
57 int len)
58{
Russell King8b801ea2007-07-20 10:38:54 +010059 void __iomem *base = priv(instance)->base;
60
Linus Torvalds1da177e2005-04-16 15:20:36 -070061printk("writing %p len %d\n",addr, len);
62 if(!len) return -1;
63
64 while(1)
65 {
66 int status;
Russell King8b801ea2007-07-20 10:38:54 +010067 while (((status = readw(base + STAT)) & 0x100)==0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 }
69}
70
71static inline int NCR5380_pread(struct Scsi_Host *instance, unsigned char *addr,
72 int len)
73{
Russell King8b801ea2007-07-20 10:38:54 +010074 void __iomem *base = priv(instance)->base;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075printk("reading %p len %d\n", addr, len);
76 while(len > 0)
77 {
Russell King8b801ea2007-07-20 10:38:54 +010078 unsigned int status, timeout;
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 unsigned long b;
80
81 timeout = 0x01FFFFFF;
82
Russell King8b801ea2007-07-20 10:38:54 +010083 while (((status = readw(base + STAT)) & 0x100)==0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 {
85 timeout--;
86 if(status & 0x200 || !timeout)
87 {
Russell King8b801ea2007-07-20 10:38:54 +010088 printk("status = %08X\n", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 return 1;
90 }
91 }
Russell King8b801ea2007-07-20 10:38:54 +010092
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 if(len >= 128)
94 {
Russell King8b801ea2007-07-20 10:38:54 +010095 readsw(base + DATA, addr, 128);
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 addr += 128;
97 len -= 128;
98 }
99 else
100 {
Russell King8b801ea2007-07-20 10:38:54 +0100101 b = (unsigned long) readw(base + DATA);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 *addr ++ = b;
103 len -= 1;
104 if(len)
105 *addr ++ = b>>8;
106 len -= 1;
107 }
108 }
109 return 0;
110}
111
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112#undef STAT
Russell King8b801ea2007-07-20 10:38:54 +0100113#undef DATA
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
115#include "../NCR5380.c"
116
Christoph Hellwigd0be4a7d2005-10-31 18:31:40 +0100117static struct scsi_host_template oakscsi_template = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 .module = THIS_MODULE,
Al Virodd7ab712013-03-31 01:15:54 -0400119 .show_info = oakscsi_show_info,
120 .write_info = oakscsi_write_info,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 .name = "Oak 16-bit SCSI",
122 .info = oakscsi_info,
123 .queuecommand = oakscsi_queue_command,
124 .eh_abort_handler = NCR5380_abort,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 .eh_bus_reset_handler = NCR5380_bus_reset,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 .can_queue = 16,
127 .this_id = 7,
128 .sg_tablesize = SG_ALL,
129 .cmd_per_lun = 2,
130 .use_clustering = DISABLE_CLUSTERING,
131 .proc_name = "oakscsi",
132};
133
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -0800134static int oakscsi_probe(struct expansion_card *ec, const struct ecard_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135{
136 struct Scsi_Host *host;
137 int ret = -ENOMEM;
138
Russell King8b801ea2007-07-20 10:38:54 +0100139 ret = ecard_request_resources(ec);
140 if (ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 goto out;
142
Russell King8b801ea2007-07-20 10:38:54 +0100143 host = scsi_host_alloc(&oakscsi_template, sizeof(struct NCR5380_hostdata));
144 if (!host) {
145 ret = -ENOMEM;
146 goto release;
147 }
148
149 priv(host)->base = ioremap(ecard_resource_start(ec, ECARD_RES_MEMC),
150 ecard_resource_len(ec, ECARD_RES_MEMC));
151 if (!priv(host)->base) {
152 ret = -ENOMEM;
153 goto unreg;
154 }
155
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 host->irq = IRQ_NONE;
157 host->n_io_port = 255;
158
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 NCR5380_init(host, 0);
160
161 printk("scsi%d: at port 0x%08lx irqs disabled",
162 host->host_no, host->io_port);
163 printk(" options CAN_QUEUE=%d CMD_PER_LUN=%d release=%d",
164 host->can_queue, host->cmd_per_lun, OAKSCSI_PUBLIC_RELEASE);
165 printk("\nscsi%d:", host->host_no);
166 NCR5380_print_options(host);
167 printk("\n");
168
169 ret = scsi_add_host(host, &ec->dev);
170 if (ret)
Russell King8b801ea2007-07-20 10:38:54 +0100171 goto out_unmap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172
173 scsi_scan_host(host);
174 goto out;
175
Russell King8b801ea2007-07-20 10:38:54 +0100176 out_unmap:
177 iounmap(priv(host)->base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 unreg:
179 scsi_host_put(host);
Russell King8b801ea2007-07-20 10:38:54 +0100180 release:
181 ecard_release_resources(ec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 out:
183 return ret;
184}
185
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -0800186static void oakscsi_remove(struct expansion_card *ec)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187{
188 struct Scsi_Host *host = ecard_get_drvdata(ec);
189
190 ecard_set_drvdata(ec, NULL);
191 scsi_remove_host(host);
192
193 NCR5380_exit(host);
Russell King8b801ea2007-07-20 10:38:54 +0100194 iounmap(priv(host)->base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 scsi_host_put(host);
Russell King8b801ea2007-07-20 10:38:54 +0100196 ecard_release_resources(ec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197}
198
199static const struct ecard_id oakscsi_cids[] = {
200 { MANU_OAK, PROD_OAK_SCSI },
201 { 0xffff, 0xffff }
202};
203
204static struct ecard_driver oakscsi_driver = {
205 .probe = oakscsi_probe,
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -0800206 .remove = oakscsi_remove,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 .id_table = oakscsi_cids,
208 .drv = {
209 .name = "oakscsi",
210 },
211};
212
213static int __init oakscsi_init(void)
214{
215 return ecard_register_driver(&oakscsi_driver);
216}
217
218static void __exit oakscsi_exit(void)
219{
220 ecard_remove_driver(&oakscsi_driver);
221}
222
223module_init(oakscsi_init);
224module_exit(oakscsi_exit);
225
226MODULE_AUTHOR("Russell King");
227MODULE_DESCRIPTION("Oak SCSI driver");
228MODULE_LICENSE("GPL");
229