]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/scsi/arm/oak.c
ncr5380: Remove NCR5380_local_declare and NCR5380_setup macros
[karo-tx-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/signal.h>
9 #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>
16
17 #include <scsi/scsi_host.h>
18
19 /*#define PSEUDO_DMA*/
20 #define DONT_USE_INTR
21
22 #define priv(host)                      ((struct NCR5380_hostdata *)(host)->hostdata)
23
24 #define NCR5380_read(reg) \
25         readb(priv(instance)->base + ((reg) << 2))
26 #define NCR5380_write(reg, value) \
27         writeb(value, priv(instance)->base + ((reg) << 2))
28
29 #define NCR5380_queue_command           oakscsi_queue_command
30 #define NCR5380_info                    oakscsi_info
31 #define NCR5380_show_info               oakscsi_show_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 NCR5380_pwrite(struct Scsi_Host *instance, unsigned char *addr,
45               int len)
46 {
47   void __iomem *base = priv(instance)->base;
48
49 printk("writing %p len %d\n",addr, len);
50   if(!len) return -1;
51
52   while(1)
53   {
54     int status;
55     while (((status = readw(base + STAT)) & 0x100)==0);
56   }
57 }
58
59 static inline int NCR5380_pread(struct Scsi_Host *instance, unsigned char *addr,
60               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         .show_info              = oakscsi_show_info,
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 };
120
121 static int oakscsi_probe(struct expansion_card *ec, const struct ecard_id *id)
122 {
123         struct Scsi_Host *host;
124         int ret = -ENOMEM;
125
126         ret = ecard_request_resources(ec);
127         if (ret)
128                 goto out;
129
130         host = scsi_host_alloc(&oakscsi_template, sizeof(struct NCR5380_hostdata));
131         if (!host) {
132                 ret = -ENOMEM;
133                 goto release;
134         }
135
136         priv(host)->base = ioremap(ecard_resource_start(ec, ECARD_RES_MEMC),
137                                    ecard_resource_len(ec, ECARD_RES_MEMC));
138         if (!priv(host)->base) {
139                 ret = -ENOMEM;
140                 goto unreg;
141         }
142
143         host->irq = NO_IRQ;
144         host->n_io_port = 255;
145
146         NCR5380_init(host, 0);
147
148         ret = scsi_add_host(host, &ec->dev);
149         if (ret)
150                 goto out_unmap;
151
152         scsi_scan_host(host);
153         goto out;
154
155  out_unmap:
156         iounmap(priv(host)->base);
157  unreg:
158         scsi_host_put(host);
159  release:
160         ecard_release_resources(ec);
161  out:
162         return ret;
163 }
164
165 static void oakscsi_remove(struct expansion_card *ec)
166 {
167         struct Scsi_Host *host = ecard_get_drvdata(ec);
168
169         ecard_set_drvdata(ec, NULL);
170         scsi_remove_host(host);
171
172         NCR5380_exit(host);
173         iounmap(priv(host)->base);
174         scsi_host_put(host);
175         ecard_release_resources(ec);
176 }
177
178 static const struct ecard_id oakscsi_cids[] = {
179         { MANU_OAK, PROD_OAK_SCSI },
180         { 0xffff, 0xffff }
181 };
182
183 static struct ecard_driver oakscsi_driver = {
184         .probe          = oakscsi_probe,
185         .remove         = oakscsi_remove,
186         .id_table       = oakscsi_cids,
187         .drv = {
188                 .name           = "oakscsi",
189         },
190 };
191
192 static int __init oakscsi_init(void)
193 {
194         return ecard_register_driver(&oakscsi_driver);
195 }
196
197 static void __exit oakscsi_exit(void)
198 {
199         ecard_remove_driver(&oakscsi_driver);
200 }
201
202 module_init(oakscsi_init);
203 module_exit(oakscsi_exit);
204
205 MODULE_AUTHOR("Russell King");
206 MODULE_DESCRIPTION("Oak SCSI driver");
207 MODULE_LICENSE("GPL");
208