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