upgrade to linux 2.6.10-1.12_FC2
[linux-2.6.git] / drivers / scsi / lasi700.c
1 /* -*- mode: c; c-basic-offset: 8 -*- */
2
3 /* PARISC LASI driver for the 53c700 chip
4  *
5  * Copyright (C) 2001 by James.Bottomley@HansenPartnership.com
6 **-----------------------------------------------------------------------------
7 **  
8 **  This program is free software; you can redistribute it and/or modify
9 **  it under the terms of the GNU General Public License as published by
10 **  the Free Software Foundation; either version 2 of the License, or
11 **  (at your option) any later version.
12 **
13 **  This program is distributed in the hope that it will be useful,
14 **  but WITHOUT ANY WARRANTY; without even the implied warranty of
15 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 **  GNU General Public License for more details.
17 **
18 **  You should have received a copy of the GNU General Public License
19 **  along with this program; if not, write to the Free Software
20 **  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 **
22 **-----------------------------------------------------------------------------
23  */
24
25 /*
26  * Many thanks to Richard Hirst <rhirst@linuxcare.com> for patiently
27  * debugging this driver on the parisc architecture and suggesting
28  * many improvements and bug fixes.
29  *
30  * Thanks also go to Linuxcare Inc. for providing several PARISC
31  * machines for me to debug the driver on.
32  */
33
34 #include <linux/kernel.h>
35 #include <linux/module.h>
36 #include <linux/init.h>
37 #include <linux/types.h>
38 #include <linux/stat.h>
39 #include <linux/mm.h>
40 #include <linux/blkdev.h>
41 #include <linux/sched.h>
42 #include <linux/ioport.h>
43 #include <linux/dma-mapping.h>
44
45 #include <asm/page.h>
46 #include <asm/pgtable.h>
47 #include <asm/irq.h>
48 #include <asm/hardware.h>
49 #include <asm/parisc-device.h>
50 #include <asm/delay.h>
51
52 #include <scsi/scsi_host.h>
53 #include <scsi/scsi_device.h>
54 #include <scsi/scsi_transport.h>
55 #include <scsi/scsi_transport_spi.h>
56
57 #include "lasi700.h"
58 #include "53c700.h"
59
60 MODULE_AUTHOR("James Bottomley");
61 MODULE_DESCRIPTION("lasi700 SCSI Driver");
62 MODULE_LICENSE("GPL");
63
64 static struct parisc_device_id lasi700_ids[] = {
65         LASI700_ID_TABLE,
66         LASI710_ID_TABLE,
67         { 0 }
68 };
69
70 static struct scsi_host_template lasi700_template = {
71         .name           = "LASI SCSI 53c700",
72         .proc_name      = "lasi700",
73         .this_id        = 7,
74         .module         = THIS_MODULE,
75 };
76 MODULE_DEVICE_TABLE(parisc, lasi700_ids);
77
78 static int __init
79 lasi700_probe(struct parisc_device *dev)
80 {
81         unsigned long base = dev->hpa + LASI_SCSI_CORE_OFFSET;
82         struct NCR_700_Host_Parameters *hostdata;
83         struct Scsi_Host *host;
84
85         hostdata = kmalloc(sizeof(*hostdata), GFP_KERNEL);
86         if (!hostdata) {
87                 printk(KERN_ERR "%s: Failed to allocate host data\n",
88                        dev->dev.bus_id);
89                 return -ENOMEM;
90         }
91         memset(hostdata, 0, sizeof(struct NCR_700_Host_Parameters));
92
93         hostdata->dev = &dev->dev;
94         dma_set_mask(&dev->dev, 0xffffffffUL);
95         hostdata->base = base;
96         hostdata->differential = 0;
97
98         if (dev->id.sversion == LASI_700_SVERSION) {
99                 hostdata->clock = LASI700_CLOCK;
100                 hostdata->force_le_on_be = 1;
101         } else {
102                 hostdata->clock = LASI710_CLOCK;
103                 hostdata->force_le_on_be = 0;
104                 hostdata->chip710 = 1;
105                 hostdata->dmode_extra = DMODE_FC2;
106         }
107
108         NCR_700_set_mem_mapped(hostdata);
109
110         host = NCR_700_detect(&lasi700_template, hostdata, &dev->dev,
111                               dev->irq, 7);
112         if (!host)
113                 goto out_kfree;
114
115         dev_set_drvdata(&dev->dev, host);
116         scsi_scan_host(host);
117
118         return 0;
119
120  out_kfree:
121         kfree(hostdata);
122         return -ENODEV;
123 }
124
125 static int __exit
126 lasi700_driver_remove(struct parisc_device *dev)
127 {
128         struct Scsi_Host *host = dev_get_drvdata(&dev->dev);
129         struct NCR_700_Host_Parameters *hostdata = 
130                 (struct NCR_700_Host_Parameters *)host->hostdata[0];
131
132         scsi_remove_host(host);
133         NCR_700_release(host);
134         free_irq(host->irq, host);
135         kfree(hostdata);
136
137         return 0;
138 }
139
140 static struct parisc_driver lasi700_driver = {
141         .name =         "Lasi SCSI",
142         .id_table =     lasi700_ids,
143         .probe =        lasi700_probe,
144         .remove =       __devexit_p(lasi700_driver_remove),
145 };
146
147 static int __init
148 lasi700_init(void)
149 {
150         return register_parisc_driver(&lasi700_driver);
151 }
152
153 static void __exit
154 lasi700_exit(void)
155 {
156         unregister_parisc_driver(&lasi700_driver);
157 }
158
159 module_init(lasi700_init);
160 module_exit(lasi700_exit);