Merge branch 'iommu/largepages' into amd-iommu/2.6.35
[pandora-kernel.git] / drivers / scsi / zorro7xx.c
1 /*
2  * Detection routine for the NCR53c710 based Amiga SCSI Controllers for Linux.
3  *              Amiga MacroSystemUS WarpEngine SCSI controller.
4  *              Amiga Technologies/DKB A4091 SCSI controller.
5  *
6  * Written 1997 by Alan Hourihane <alanh@fairlite.demon.co.uk>
7  * plus modifications of the 53c7xx.c driver to support the Amiga.
8  *
9  * Rewritten to use 53c700.c by Kars de Jong <jongk@linux-m68k.org>
10  */
11
12 #include <linux/module.h>
13 #include <linux/init.h>
14 #include <linux/interrupt.h>
15 #include <linux/zorro.h>
16 #include <linux/slab.h>
17
18 #include <asm/amigahw.h>
19 #include <asm/amigaints.h>
20
21 #include <scsi/scsi_host.h>
22 #include <scsi/scsi_transport_spi.h>
23
24 #include "53c700.h"
25
26 MODULE_AUTHOR("Alan Hourihane <alanh@fairlite.demon.co.uk> / Kars de Jong <jongk@linux-m68k.org>");
27 MODULE_DESCRIPTION("Amiga Zorro NCR53C710 driver");
28 MODULE_LICENSE("GPL");
29
30
31 static struct scsi_host_template zorro7xx_scsi_driver_template = {
32         .proc_name      = "zorro7xx",
33         .this_id        = 7,
34         .module         = THIS_MODULE,
35 };
36
37 static struct zorro_driver_data {
38         const char *name;
39         unsigned long offset;
40         int absolute;   /* offset is absolute address */
41 } zorro7xx_driver_data[] __devinitdata = {
42         { .name = "PowerUP 603e+", .offset = 0xf40000, .absolute = 1 },
43         { .name = "WarpEngine 40xx", .offset = 0x40000 },
44         { .name = "A4091", .offset = 0x800000 },
45         { .name = "GForce 040/060", .offset = 0x40000 },
46         { 0 }
47 };
48
49 static struct zorro_device_id zorro7xx_zorro_tbl[] __devinitdata = {
50         {
51                 .id = ZORRO_PROD_PHASE5_BLIZZARD_603E_PLUS,
52                 .driver_data = (unsigned long)&zorro7xx_driver_data[0],
53         },
54         {
55                 .id = ZORRO_PROD_MACROSYSTEMS_WARP_ENGINE_40xx,
56                 .driver_data = (unsigned long)&zorro7xx_driver_data[1],
57         },
58         {
59                 .id = ZORRO_PROD_CBM_A4091_1,
60                 .driver_data = (unsigned long)&zorro7xx_driver_data[2],
61         },
62         {
63                 .id = ZORRO_PROD_CBM_A4091_2,
64                 .driver_data = (unsigned long)&zorro7xx_driver_data[2],
65         },
66         {
67                 .id = ZORRO_PROD_GVP_GFORCE_040_060,
68                 .driver_data = (unsigned long)&zorro7xx_driver_data[3],
69         },
70         { 0 }
71 };
72
73 static int __devinit zorro7xx_init_one(struct zorro_dev *z,
74                                        const struct zorro_device_id *ent)
75 {
76         struct Scsi_Host *host;
77         struct NCR_700_Host_Parameters *hostdata;
78         struct zorro_driver_data *zdd;
79         unsigned long board, ioaddr;
80
81         board = zorro_resource_start(z);
82         zdd = (struct zorro_driver_data *)ent->driver_data;
83
84         if (zdd->absolute) {
85                 ioaddr = zdd->offset;
86         } else {
87                 ioaddr = board + zdd->offset;
88         }
89
90         if (!zorro_request_device(z, zdd->name)) {
91                 printk(KERN_ERR "zorro7xx: cannot reserve region 0x%lx, abort\n",
92                        board);
93                 return -EBUSY;
94         }
95
96         hostdata = kzalloc(sizeof(struct NCR_700_Host_Parameters), GFP_KERNEL);
97         if (!hostdata) {
98                 printk(KERN_ERR "zorro7xx: Failed to allocate host data\n");
99                 goto out_release;
100         }
101
102         /* Fill in the required pieces of hostdata */
103         if (ioaddr > 0x01000000)
104                 hostdata->base = ioremap(ioaddr, zorro_resource_len(z));
105         else
106                 hostdata->base = (void __iomem *)ZTWO_VADDR(ioaddr);
107
108         hostdata->clock = 50;
109         hostdata->chip710 = 1;
110
111         /* Settings for at least WarpEngine 40xx */
112         hostdata->ctest7_extra = CTEST7_TT1;
113
114         zorro7xx_scsi_driver_template.name = zdd->name;
115
116         /* and register the chip */
117         host = NCR_700_detect(&zorro7xx_scsi_driver_template, hostdata,
118                               &z->dev);
119         if (!host) {
120                 printk(KERN_ERR "zorro7xx: No host detected; "
121                                 "board configuration problem?\n");
122                 goto out_free;
123         }
124
125         host->this_id = 7;
126         host->base = ioaddr;
127         host->irq = IRQ_AMIGA_PORTS;
128
129         if (request_irq(host->irq, NCR_700_intr, IRQF_SHARED, "zorro7xx-scsi",
130                         host)) {
131                 printk(KERN_ERR "zorro7xx: request_irq failed\n");
132                 goto out_put_host;
133         }
134
135         zorro_set_drvdata(z, host);
136         scsi_scan_host(host);
137
138         return 0;
139
140  out_put_host:
141         scsi_host_put(host);
142  out_free:
143         if (ioaddr > 0x01000000)
144                 iounmap(hostdata->base);
145         kfree(hostdata);
146  out_release:
147         zorro_release_device(z);
148
149         return -ENODEV;
150 }
151
152 static __devexit void zorro7xx_remove_one(struct zorro_dev *z)
153 {
154         struct Scsi_Host *host = zorro_get_drvdata(z);
155         struct NCR_700_Host_Parameters *hostdata = shost_priv(host);
156
157         scsi_remove_host(host);
158
159         NCR_700_release(host);
160         kfree(hostdata);
161         free_irq(host->irq, host);
162         zorro_release_device(z);
163 }
164
165 static struct zorro_driver zorro7xx_driver = {
166         .name     = "zorro7xx-scsi",
167         .id_table = zorro7xx_zorro_tbl,
168         .probe    = zorro7xx_init_one,
169         .remove   = __devexit_p(zorro7xx_remove_one),
170 };
171
172 static int __init zorro7xx_scsi_init(void)
173 {
174         return zorro_register_driver(&zorro7xx_driver);
175 }
176
177 static void __exit zorro7xx_scsi_exit(void)
178 {
179         zorro_unregister_driver(&zorro7xx_driver);
180 }
181
182 module_init(zorro7xx_scsi_init);
183 module_exit(zorro7xx_scsi_exit);