Merge tag 'drm-intel-fixes-2014-08-08' of git://anongit.freedesktop.org/drm-intel
[linux-2.6-block.git] / drivers / scsi / arm / cumana_1.c
CommitLineData
1da177e4
LT
1/*
2 * Generic Generic NCR5380 driver
3 *
4 * Copyright 1995-2002, Russell King
5 */
6#include <linux/module.h>
7#include <linux/signal.h>
1da177e4
LT
8#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>
1da177e4
LT
15
16#include "../scsi.h"
17#include <scsi/scsi_host.h>
18
19#include <scsi/scsicam.h>
20
21#define AUTOSENSE
22#define PSEUDO_DMA
23
24#define CUMANASCSI_PUBLIC_RELEASE 1
25
8b801ead 26#define priv(host) ((struct NCR5380_hostdata *)(host)->hostdata)
1da177e4
LT
27#define NCR5380_local_declare() struct Scsi_Host *_instance
28#define NCR5380_setup(instance) _instance = instance
29#define NCR5380_read(reg) cumanascsi_read(_instance, reg)
30#define NCR5380_write(reg, value) cumanascsi_write(_instance, reg, value)
31#define NCR5380_intr cumanascsi_intr
32#define NCR5380_queue_command cumanascsi_queue_command
1da177e4 33
8b801ead
RK
34#define NCR5380_implementation_fields \
35 unsigned ctrl; \
36 void __iomem *base; \
37 void __iomem *dma
38
1da177e4
LT
39#include "../NCR5380.h"
40
41void cumanascsi_setup(char *str, int *ints)
42{
43}
44
45const char *cumanascsi_info(struct Scsi_Host *spnt)
46{
47 return "";
48}
49
8b801ead
RK
50#define CTRL 0x16fc
51#define STAT 0x2004
52#define L(v) (((v)<<16)|((v) & 0x0000ffff))
53#define H(v) (((v)>>16)|((v) & 0xffff0000))
1da177e4
LT
54
55static inline int
8b801ead 56NCR5380_pwrite(struct Scsi_Host *host, unsigned char *addr, int len)
1da177e4 57{
1da177e4 58 unsigned long *laddr;
8b801ead 59 void __iomem *dma = priv(host)->dma + 0x2000;
1da177e4
LT
60
61 if(!len) return 0;
62
8b801ead 63 writeb(0x02, priv(host)->base + CTRL);
1da177e4
LT
64 laddr = (unsigned long *)addr;
65 while(len >= 32)
66 {
8b801ead 67 unsigned int status;
1da177e4 68 unsigned long v;
8b801ead 69 status = readb(priv(host)->base + STAT);
1da177e4
LT
70 if(status & 0x80)
71 goto end;
72 if(!(status & 0x40))
73 continue;
8b801ead
RK
74 v=*laddr++; writew(L(v), dma); writew(H(v), dma);
75 v=*laddr++; writew(L(v), dma); writew(H(v), dma);
76 v=*laddr++; writew(L(v), dma); writew(H(v), dma);
77 v=*laddr++; writew(L(v), dma); writew(H(v), dma);
78 v=*laddr++; writew(L(v), dma); writew(H(v), dma);
79 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);
1da177e4
LT
82 len -= 32;
83 if(len == 0)
84 break;
85 }
86
87 addr = (unsigned char *)laddr;
8b801ead
RK
88 writeb(0x12, priv(host)->base + CTRL);
89
1da177e4
LT
90 while(len > 0)
91 {
8b801ead
RK
92 unsigned int status;
93 status = readb(priv(host)->base + STAT);
1da177e4
LT
94 if(status & 0x80)
95 goto end;
96 if(status & 0x40)
97 {
8b801ead 98 writeb(*addr++, dma);
1da177e4
LT
99 if(--len == 0)
100 break;
101 }
102
8b801ead 103 status = readb(priv(host)->base + STAT);
1da177e4
LT
104 if(status & 0x80)
105 goto end;
106 if(status & 0x40)
107 {
8b801ead 108 writeb(*addr++, dma);
1da177e4
LT
109 if(--len == 0)
110 break;
111 }
112 }
113end:
8b801ead 114 writeb(priv(host)->ctrl | 0x40, priv(host)->base + CTRL);
1da177e4
LT
115 return len;
116}
117
118static inline int
8b801ead 119NCR5380_pread(struct Scsi_Host *host, unsigned char *addr, int len)
1da177e4 120{
1da177e4 121 unsigned long *laddr;
8b801ead 122 void __iomem *dma = priv(host)->dma + 0x2000;
1da177e4
LT
123
124 if(!len) return 0;
125
8b801ead 126 writeb(0x00, priv(host)->base + CTRL);
1da177e4
LT
127 laddr = (unsigned long *)addr;
128 while(len >= 32)
129 {
8b801ead
RK
130 unsigned int status;
131 status = readb(priv(host)->base + STAT);
1da177e4
LT
132 if(status & 0x80)
133 goto end;
134 if(!(status & 0x40))
135 continue;
8b801ead
RK
136 *laddr++ = readw(dma) | (readw(dma) << 16);
137 *laddr++ = readw(dma) | (readw(dma) << 16);
138 *laddr++ = readw(dma) | (readw(dma) << 16);
139 *laddr++ = readw(dma) | (readw(dma) << 16);
140 *laddr++ = readw(dma) | (readw(dma) << 16);
141 *laddr++ = readw(dma) | (readw(dma) << 16);
142 *laddr++ = readw(dma) | (readw(dma) << 16);
143 *laddr++ = readw(dma) | (readw(dma) << 16);
1da177e4
LT
144 len -= 32;
145 if(len == 0)
146 break;
147 }
148
149 addr = (unsigned char *)laddr;
8b801ead
RK
150 writeb(0x10, priv(host)->base + CTRL);
151
1da177e4
LT
152 while(len > 0)
153 {
8b801ead
RK
154 unsigned int status;
155 status = readb(priv(host)->base + STAT);
1da177e4
LT
156 if(status & 0x80)
157 goto end;
158 if(status & 0x40)
159 {
8b801ead 160 *addr++ = readb(dma);
1da177e4
LT
161 if(--len == 0)
162 break;
163 }
164
8b801ead 165 status = readb(priv(host)->base + STAT);
1da177e4
LT
166 if(status & 0x80)
167 goto end;
168 if(status & 0x40)
169 {
8b801ead 170 *addr++ = readb(dma);
1da177e4
LT
171 if(--len == 0)
172 break;
173 }
174 }
175end:
8b801ead 176 writeb(priv(host)->ctrl | 0x40, priv(host)->base + CTRL);
1da177e4
LT
177 return len;
178}
179
8b801ead
RK
180static unsigned char cumanascsi_read(struct Scsi_Host *host, unsigned int reg)
181{
182 void __iomem *base = priv(host)->base;
183 unsigned char val;
1da177e4 184
8b801ead 185 writeb(0, base + CTRL);
1da177e4 186
8b801ead 187 val = readb(base + 0x2100 + (reg << 2));
1da177e4 188
8b801ead
RK
189 priv(host)->ctrl = 0x40;
190 writeb(0x40, base + CTRL);
1da177e4 191
8b801ead 192 return val;
1da177e4
LT
193}
194
8b801ead 195static void cumanascsi_write(struct Scsi_Host *host, unsigned int reg, unsigned int value)
1da177e4 196{
8b801ead 197 void __iomem *base = priv(host)->base;
1da177e4 198
8b801ead 199 writeb(0, base + CTRL);
1da177e4 200
8b801ead
RK
201 writeb(value, base + 0x2100 + (reg << 2));
202
203 priv(host)->ctrl = 0x40;
204 writeb(0x40, base + CTRL);
205}
1da177e4
LT
206
207#include "../NCR5380.c"
208
d0be4a7d 209static struct scsi_host_template cumanascsi_template = {
1da177e4
LT
210 .module = THIS_MODULE,
211 .name = "Cumana 16-bit SCSI",
212 .info = cumanascsi_info,
213 .queuecommand = cumanascsi_queue_command,
214 .eh_abort_handler = NCR5380_abort,
1da177e4 215 .eh_bus_reset_handler = NCR5380_bus_reset,
1da177e4
LT
216 .can_queue = 16,
217 .this_id = 7,
218 .sg_tablesize = SG_ALL,
219 .cmd_per_lun = 2,
1da177e4
LT
220 .use_clustering = DISABLE_CLUSTERING,
221 .proc_name = "CumanaSCSI-1",
222};
223
6f039790
GKH
224static int cumanascsi1_probe(struct expansion_card *ec,
225 const struct ecard_id *id)
1da177e4
LT
226{
227 struct Scsi_Host *host;
8b801ead 228 int ret;
1da177e4 229
8b801ead
RK
230 ret = ecard_request_resources(ec);
231 if (ret)
1da177e4
LT
232 goto out;
233
8b801ead
RK
234 host = scsi_host_alloc(&cumanascsi_template, sizeof(struct NCR5380_hostdata));
235 if (!host) {
236 ret = -ENOMEM;
237 goto out_release;
238 }
239
240 priv(host)->base = ioremap(ecard_resource_start(ec, ECARD_RES_IOCSLOW),
241 ecard_resource_len(ec, ECARD_RES_IOCSLOW));
242 priv(host)->dma = ioremap(ecard_resource_start(ec, ECARD_RES_MEMC),
243 ecard_resource_len(ec, ECARD_RES_MEMC));
244 if (!priv(host)->base || !priv(host)->dma) {
245 ret = -ENOMEM;
246 goto out_unmap;
247 }
248
1da177e4
LT
249 host->irq = ec->irq;
250
251 NCR5380_init(host, 0);
252
8b801ead
RK
253 priv(host)->ctrl = 0;
254 writeb(0, priv(host)->base + CTRL);
255
1da177e4
LT
256 host->n_io_port = 255;
257 if (!(request_region(host->io_port, host->n_io_port, "CumanaSCSI-1"))) {
258 ret = -EBUSY;
8b801ead 259 goto out_unmap;
1da177e4
LT
260 }
261
4909cc2b 262 ret = request_irq(host->irq, cumanascsi_intr, 0,
1da177e4
LT
263 "CumanaSCSI-1", host);
264 if (ret) {
265 printk("scsi%d: IRQ%d not free: %d\n",
266 host->host_no, host->irq, ret);
8b801ead 267 goto out_unmap;
1da177e4
LT
268 }
269
270 printk("scsi%d: at port 0x%08lx irq %d",
271 host->host_no, host->io_port, host->irq);
272 printk(" options CAN_QUEUE=%d CMD_PER_LUN=%d release=%d",
273 host->can_queue, host->cmd_per_lun, CUMANASCSI_PUBLIC_RELEASE);
274 printk("\nscsi%d:", host->host_no);
275 NCR5380_print_options(host);
276 printk("\n");
277
278 ret = scsi_add_host(host, &ec->dev);
279 if (ret)
280 goto out_free_irq;
281
282 scsi_scan_host(host);
283 goto out;
284
285 out_free_irq:
286 free_irq(host->irq, host);
8b801ead
RK
287 out_unmap:
288 iounmap(priv(host)->base);
289 iounmap(priv(host)->dma);
1da177e4 290 scsi_host_put(host);
8b801ead
RK
291 out_release:
292 ecard_release_resources(ec);
1da177e4
LT
293 out:
294 return ret;
295}
296
6f039790 297static void cumanascsi1_remove(struct expansion_card *ec)
1da177e4
LT
298{
299 struct Scsi_Host *host = ecard_get_drvdata(ec);
300
301 ecard_set_drvdata(ec, NULL);
302
303 scsi_remove_host(host);
304 free_irq(host->irq, host);
305 NCR5380_exit(host);
8b801ead
RK
306 iounmap(priv(host)->base);
307 iounmap(priv(host)->dma);
1da177e4 308 scsi_host_put(host);
8b801ead 309 ecard_release_resources(ec);
1da177e4
LT
310}
311
312static const struct ecard_id cumanascsi1_cids[] = {
313 { MANU_CUMANA, PROD_CUMANA_SCSI_1 },
314 { 0xffff, 0xffff }
315};
316
317static struct ecard_driver cumanascsi1_driver = {
318 .probe = cumanascsi1_probe,
6f039790 319 .remove = cumanascsi1_remove,
1da177e4
LT
320 .id_table = cumanascsi1_cids,
321 .drv = {
322 .name = "cumanascsi1",
323 },
324};
325
326static int __init cumanascsi_init(void)
327{
328 return ecard_register_driver(&cumanascsi1_driver);
329}
330
331static void __exit cumanascsi_exit(void)
332{
333 ecard_remove_driver(&cumanascsi1_driver);
334}
335
336module_init(cumanascsi_init);
337module_exit(cumanascsi_exit);
338
339MODULE_DESCRIPTION("Cumana SCSI-1 driver for Acorn machines");
340MODULE_LICENSE("GPL");