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