ARM: mali400: r5p2_rel0: fix build error
[profile/mobile/platform/kernel/linux-3.10-sc7730.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.h"
18 #include <scsi/scsi_host.h>
19
20 #define AUTOSENSE
21 /*#define PSEUDO_DMA*/
22
23 #define OAKSCSI_PUBLIC_RELEASE 1
24 #define DONT_USE_INTR
25
26 #define priv(host)                      ((struct NCR5380_hostdata *)(host)->hostdata)
27 #define NCR5380_local_declare()         void __iomem *_base
28 #define NCR5380_setup(host)             _base = priv(host)->base
29
30 #define NCR5380_read(reg)               readb(_base + ((reg) << 2))
31 #define NCR5380_write(reg, value)       writeb(value, _base + ((reg) << 2))
32 #define NCR5380_intr                    oakscsi_intr
33 #define NCR5380_queue_command           oakscsi_queue_command
34 #define NCR5380_show_info               oakscsi_show_info
35 #define NCR5380_write_info              oakscsi_write_info
36
37 #define NCR5380_implementation_fields   \
38         void __iomem *base
39
40 #define BOARD_NORMAL    0
41 #define BOARD_NCR53C400 1
42
43 #include "../NCR5380.h"
44
45 #undef START_DMA_INITIATOR_RECEIVE_REG
46 #define START_DMA_INITIATOR_RECEIVE_REG (128 + 7)
47
48 const char * oakscsi_info (struct Scsi_Host *spnt)
49 {
50         return "";
51 }
52
53 #define STAT    ((128 + 16) << 2)
54 #define DATA    ((128 + 8) << 2)
55
56 static inline int NCR5380_pwrite(struct Scsi_Host *instance, unsigned char *addr,
57               int len)
58 {
59   void __iomem *base = priv(instance)->base;
60
61 printk("writing %p len %d\n",addr, len);
62   if(!len) return -1;
63
64   while(1)
65   {
66     int status;
67     while (((status = readw(base + STAT)) & 0x100)==0);
68   }
69 }
70
71 static inline int NCR5380_pread(struct Scsi_Host *instance, unsigned char *addr,
72               int len)
73 {
74   void __iomem *base = priv(instance)->base;
75 printk("reading %p len %d\n", addr, len);
76   while(len > 0)
77   {
78     unsigned int status, timeout;
79     unsigned long b;
80     
81     timeout = 0x01FFFFFF;
82     
83     while (((status = readw(base + STAT)) & 0x100)==0)
84     {
85       timeout--;
86       if(status & 0x200 || !timeout)
87       {
88         printk("status = %08X\n", status);
89         return 1;
90       }
91     }
92
93     if(len >= 128)
94     {
95       readsw(base + DATA, addr, 128);
96       addr += 128;
97       len -= 128;
98     }
99     else
100     {
101       b = (unsigned long) readw(base + DATA);
102       *addr ++ = b;
103       len -= 1;
104       if(len)
105         *addr ++ = b>>8;
106       len -= 1;
107     }
108   }
109   return 0;
110 }
111
112 #undef STAT
113 #undef DATA
114
115 #include "../NCR5380.c"
116
117 static struct scsi_host_template oakscsi_template = {
118         .module                 = THIS_MODULE,
119         .show_info              = oakscsi_show_info,
120         .write_info             = oakscsi_write_info,
121         .name                   = "Oak 16-bit SCSI",
122         .info                   = oakscsi_info,
123         .queuecommand           = oakscsi_queue_command,
124         .eh_abort_handler       = NCR5380_abort,
125         .eh_bus_reset_handler   = NCR5380_bus_reset,
126         .can_queue              = 16,
127         .this_id                = 7,
128         .sg_tablesize           = SG_ALL,
129         .cmd_per_lun            = 2,
130         .use_clustering         = DISABLE_CLUSTERING,
131         .proc_name              = "oakscsi",
132 };
133
134 static int oakscsi_probe(struct expansion_card *ec, const struct ecard_id *id)
135 {
136         struct Scsi_Host *host;
137         int ret = -ENOMEM;
138
139         ret = ecard_request_resources(ec);
140         if (ret)
141                 goto out;
142
143         host = scsi_host_alloc(&oakscsi_template, sizeof(struct NCR5380_hostdata));
144         if (!host) {
145                 ret = -ENOMEM;
146                 goto release;
147         }
148
149         priv(host)->base = ioremap(ecard_resource_start(ec, ECARD_RES_MEMC),
150                                    ecard_resource_len(ec, ECARD_RES_MEMC));
151         if (!priv(host)->base) {
152                 ret = -ENOMEM;
153                 goto unreg;
154         }
155
156         host->irq = IRQ_NONE;
157         host->n_io_port = 255;
158
159         NCR5380_init(host, 0);
160
161         printk("scsi%d: at port 0x%08lx irqs disabled",
162                 host->host_no, host->io_port);
163         printk(" options CAN_QUEUE=%d  CMD_PER_LUN=%d release=%d",
164                 host->can_queue, host->cmd_per_lun, OAKSCSI_PUBLIC_RELEASE);
165         printk("\nscsi%d:", host->host_no);
166         NCR5380_print_options(host);
167         printk("\n");
168
169         ret = scsi_add_host(host, &ec->dev);
170         if (ret)
171                 goto out_unmap;
172
173         scsi_scan_host(host);
174         goto out;
175
176  out_unmap:
177         iounmap(priv(host)->base);
178  unreg:
179         scsi_host_put(host);
180  release:
181         ecard_release_resources(ec);
182  out:
183         return ret;
184 }
185
186 static void oakscsi_remove(struct expansion_card *ec)
187 {
188         struct Scsi_Host *host = ecard_get_drvdata(ec);
189
190         ecard_set_drvdata(ec, NULL);
191         scsi_remove_host(host);
192
193         NCR5380_exit(host);
194         iounmap(priv(host)->base);
195         scsi_host_put(host);
196         ecard_release_resources(ec);
197 }
198
199 static const struct ecard_id oakscsi_cids[] = {
200         { MANU_OAK, PROD_OAK_SCSI },
201         { 0xffff, 0xffff }
202 };
203
204 static struct ecard_driver oakscsi_driver = {
205         .probe          = oakscsi_probe,
206         .remove         = oakscsi_remove,
207         .id_table       = oakscsi_cids,
208         .drv = {
209                 .name           = "oakscsi",
210         },
211 };
212
213 static int __init oakscsi_init(void)
214 {
215         return ecard_register_driver(&oakscsi_driver);
216 }
217
218 static void __exit oakscsi_exit(void)
219 {
220         ecard_remove_driver(&oakscsi_driver);
221 }
222
223 module_init(oakscsi_init);
224 module_exit(oakscsi_exit);
225
226 MODULE_AUTHOR("Russell King");
227 MODULE_DESCRIPTION("Oak SCSI driver");
228 MODULE_LICENSE("GPL");
229