ncr5380: Merge DMA implementation from atari_NCR5380 core driver
[deliverable/linux.git] / drivers / scsi / arm / oak.c
CommitLineData
1da177e4
LT
1/*
2 * Oak Generic NCR5380 driver
3 *
4 * Copyright 1995-2002, Russell King
5 */
6
7#include <linux/module.h>
1da177e4 8#include <linux/ioport.h>
1da177e4
LT
9#include <linux/blkdev.h>
10#include <linux/init.h>
11
12#include <asm/ecard.h>
13#include <asm/io.h>
1da177e4 14
1da177e4
LT
15#include <scsi/scsi_host.h>
16
ea065f13 17#define DONT_USE_INTR
1da177e4 18
8b801ead 19#define priv(host) ((struct NCR5380_hostdata *)(host)->hostdata)
8b801ead 20
54d8fe44
FT
21#define NCR5380_read(reg) \
22 readb(priv(instance)->base + ((reg) << 2))
23#define NCR5380_write(reg, value) \
24 writeb(value, priv(instance)->base + ((reg) << 2))
25
f825e40b 26#define NCR5380_dma_xfer_len(instance, cmd, phase) (0)
6c4b88ca
FT
27#define NCR5380_dma_recv_setup oakscsi_pread
28#define NCR5380_dma_send_setup oakscsi_pwrite
8053b0ee 29#define NCR5380_dma_residual(instance) (0)
ff3d4578 30
1da177e4 31#define NCR5380_queue_command oakscsi_queue_command
8c32513b 32#define NCR5380_info oakscsi_info
1da177e4 33
8b801ead
RK
34#define NCR5380_implementation_fields \
35 void __iomem *base
1da177e4 36
1da177e4
LT
37#include "../NCR5380.h"
38
39#undef START_DMA_INITIATOR_RECEIVE_REG
8b801ead 40#define START_DMA_INITIATOR_RECEIVE_REG (128 + 7)
1da177e4 41
8b801ead
RK
42#define STAT ((128 + 16) << 2)
43#define DATA ((128 + 8) << 2)
1da177e4 44
6c4b88ca
FT
45static inline int oakscsi_pwrite(struct Scsi_Host *instance,
46 unsigned char *addr, int len)
1da177e4 47{
8b801ead
RK
48 void __iomem *base = priv(instance)->base;
49
1da177e4 50printk("writing %p len %d\n",addr, len);
1da177e4
LT
51
52 while(1)
53 {
54 int status;
8b801ead 55 while (((status = readw(base + STAT)) & 0x100)==0);
1da177e4 56 }
438af51c 57 return 0;
1da177e4
LT
58}
59
6c4b88ca
FT
60static inline int oakscsi_pread(struct Scsi_Host *instance,
61 unsigned char *addr, int len)
1da177e4 62{
8b801ead 63 void __iomem *base = priv(instance)->base;
1da177e4
LT
64printk("reading %p len %d\n", addr, len);
65 while(len > 0)
66 {
8b801ead 67 unsigned int status, timeout;
1da177e4
LT
68 unsigned long b;
69
70 timeout = 0x01FFFFFF;
71
8b801ead 72 while (((status = readw(base + STAT)) & 0x100)==0)
1da177e4
LT
73 {
74 timeout--;
75 if(status & 0x200 || !timeout)
76 {
8b801ead 77 printk("status = %08X\n", status);
438af51c 78 return -1;
1da177e4
LT
79 }
80 }
8b801ead 81
1da177e4
LT
82 if(len >= 128)
83 {
8b801ead 84 readsw(base + DATA, addr, 128);
1da177e4
LT
85 addr += 128;
86 len -= 128;
87 }
88 else
89 {
8b801ead 90 b = (unsigned long) readw(base + DATA);
1da177e4
LT
91 *addr ++ = b;
92 len -= 1;
93 if(len)
94 *addr ++ = b>>8;
95 len -= 1;
96 }
97 }
98 return 0;
99}
100
1da177e4 101#undef STAT
8b801ead 102#undef DATA
1da177e4
LT
103
104#include "../NCR5380.c"
105
d0be4a7d 106static struct scsi_host_template oakscsi_template = {
1da177e4 107 .module = THIS_MODULE,
1da177e4
LT
108 .name = "Oak 16-bit SCSI",
109 .info = oakscsi_info,
110 .queuecommand = oakscsi_queue_command,
111 .eh_abort_handler = NCR5380_abort,
1da177e4 112 .eh_bus_reset_handler = NCR5380_bus_reset,
1da177e4
LT
113 .can_queue = 16,
114 .this_id = 7,
115 .sg_tablesize = SG_ALL,
116 .cmd_per_lun = 2,
117 .use_clustering = DISABLE_CLUSTERING,
118 .proc_name = "oakscsi",
32b26a10 119 .cmd_size = NCR5380_CMD_SIZE,
0a4e3612 120 .max_sectors = 128,
1da177e4
LT
121};
122
6f039790 123static int oakscsi_probe(struct expansion_card *ec, const struct ecard_id *id)
1da177e4
LT
124{
125 struct Scsi_Host *host;
126 int ret = -ENOMEM;
127
8b801ead
RK
128 ret = ecard_request_resources(ec);
129 if (ret)
1da177e4
LT
130 goto out;
131
8b801ead
RK
132 host = scsi_host_alloc(&oakscsi_template, sizeof(struct NCR5380_hostdata));
133 if (!host) {
134 ret = -ENOMEM;
135 goto release;
136 }
137
138 priv(host)->base = ioremap(ecard_resource_start(ec, ECARD_RES_MEMC),
139 ecard_resource_len(ec, ECARD_RES_MEMC));
140 if (!priv(host)->base) {
141 ret = -ENOMEM;
142 goto unreg;
143 }
144
22f5f10d 145 host->irq = NO_IRQ;
1da177e4
LT
146 host->n_io_port = 255;
147
8053b0ee 148 ret = NCR5380_init(host, FLAG_DMA_FIXUP | FLAG_LATE_DMA_SETUP);
0ad0eff9
FT
149 if (ret)
150 goto out_unmap;
1da177e4 151
b6488f97
FT
152 NCR5380_maybe_reset_bus(host);
153
1da177e4
LT
154 ret = scsi_add_host(host, &ec->dev);
155 if (ret)
0ad0eff9 156 goto out_exit;
1da177e4
LT
157
158 scsi_scan_host(host);
159 goto out;
160
0ad0eff9
FT
161 out_exit:
162 NCR5380_exit(host);
8b801ead
RK
163 out_unmap:
164 iounmap(priv(host)->base);
1da177e4
LT
165 unreg:
166 scsi_host_put(host);
8b801ead
RK
167 release:
168 ecard_release_resources(ec);
1da177e4
LT
169 out:
170 return ret;
171}
172
6f039790 173static void oakscsi_remove(struct expansion_card *ec)
1da177e4
LT
174{
175 struct Scsi_Host *host = ecard_get_drvdata(ec);
176
177 ecard_set_drvdata(ec, NULL);
178 scsi_remove_host(host);
179
180 NCR5380_exit(host);
8b801ead 181 iounmap(priv(host)->base);
1da177e4 182 scsi_host_put(host);
8b801ead 183 ecard_release_resources(ec);
1da177e4
LT
184}
185
186static const struct ecard_id oakscsi_cids[] = {
187 { MANU_OAK, PROD_OAK_SCSI },
188 { 0xffff, 0xffff }
189};
190
191static struct ecard_driver oakscsi_driver = {
192 .probe = oakscsi_probe,
6f039790 193 .remove = oakscsi_remove,
1da177e4
LT
194 .id_table = oakscsi_cids,
195 .drv = {
196 .name = "oakscsi",
197 },
198};
199
200static int __init oakscsi_init(void)
201{
202 return ecard_register_driver(&oakscsi_driver);
203}
204
205static void __exit oakscsi_exit(void)
206{
207 ecard_remove_driver(&oakscsi_driver);
208}
209
210module_init(oakscsi_init);
211module_exit(oakscsi_exit);
212
213MODULE_AUTHOR("Russell King");
214MODULE_DESCRIPTION("Oak SCSI driver");
215MODULE_LICENSE("GPL");
216
This page took 0.920473 seconds and 5 git commands to generate.