update atp870u driver to 0.78 from D-Link source
[linux-2.4.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 #ifndef __hppa__
35 #error "lasi700 only compiles on hppa architecture"
36 #endif
37
38 #include <linux/kernel.h>
39 #include <linux/init.h>
40 #include <linux/types.h>
41 #include <linux/stat.h>
42 #include <linux/mm.h>
43 #include <linux/blk.h>
44 #include <linux/sched.h>
45 #include <linux/version.h>
46 #include <linux/config.h>
47 #include <linux/ioport.h>
48
49 #include <asm/page.h>
50 #include <asm/pgtable.h>
51 #include <asm/irq.h>
52 #include <asm/hardware.h>
53 #include <asm/delay.h>
54 #include <asm/gsc.h>
55
56 #include <linux/module.h>
57
58 #include "scsi.h"
59 #include "hosts.h"
60 #include "constants.h"
61
62 #include "lasi700.h"
63 #include "53c700.h"
64
65 #ifdef MODULE
66
67 char *lasi700;                  /* command line from insmod */
68
69 MODULE_AUTHOR("James Bottomley");
70 MODULE_DESCRIPTION("lasi700 SCSI Driver");
71 MODULE_LICENSE("GPL");
72 MODULE_PARM(lasi700, "s");
73
74 #endif
75
76 #ifdef MODULE
77 #define ARG_SEP ' '
78 #else
79 #define ARG_SEP ','
80 #endif
81
82 static unsigned long __initdata opt_base;
83 static int __initdata opt_irq;
84
85 static int __init
86 param_setup(char *string)
87 {
88         char *pos = string, *next;
89
90         while(pos != NULL && (next = strchr(pos, ':')) != NULL) {
91                 int val = (int)simple_strtoul(++next, NULL, 0);
92                 
93                 if(!strncmp(pos, "addr:", 5))
94                         opt_base = val;
95                 else if(!strncmp(pos, "irq:", 4))
96                         opt_irq = val;
97
98                 if((pos = strchr(pos, ARG_SEP)) != NULL)
99                         pos++;
100         }
101         return 1;
102 }
103
104 #ifndef MODULE
105 __setup("lasi700=", param_setup);
106 #endif
107
108 static Scsi_Host_Template __initdata *host_tpnt = NULL;
109 static int __initdata host_count = 0;
110 static struct parisc_device_id lasi700_scsi_tbl[] = {
111         LASI700_ID_TABLE,
112         LASI710_ID_TABLE,
113         { 0 }
114 };
115
116 MODULE_DEVICE_TABLE(parisc, lasi700_scsi_tbl);
117
118 static struct parisc_driver lasi700_driver = LASI700_DRIVER;
119
120 static int __init
121 lasi700_detect(Scsi_Host_Template *tpnt)
122 {
123         host_tpnt = tpnt;
124
125 #ifdef MODULE
126         if(lasi700)
127                 param_setup(lasi700);
128 #endif
129
130         register_parisc_driver(&lasi700_driver);
131
132         return (host_count != 0);
133 }
134
135 static int __init
136 lasi700_driver_callback(struct parisc_device *dev)
137 {
138         unsigned long base = dev->hpa + LASI_SCSI_CORE_OFFSET;
139         char *driver_name;
140         struct Scsi_Host *host;
141         struct NCR_700_Host_Parameters *hostdata =
142                 kmalloc(sizeof(struct NCR_700_Host_Parameters),
143                         GFP_KERNEL);
144         if(dev->id.sversion == LASI_700_SVERSION) {
145                 driver_name = "lasi700";
146         } else {
147                 driver_name = "lasi710";
148         }
149         if(hostdata == NULL) {
150                 printk(KERN_ERR "%s: Failed to allocate host data\n",
151                        driver_name);
152                 return 1;
153         }
154         memset(hostdata, 0, sizeof(struct NCR_700_Host_Parameters));
155         hostdata->base = base;
156         hostdata->differential = 0;
157         if(dev->id.sversion == LASI_700_SVERSION) {
158                 hostdata->clock = LASI700_CLOCK;
159                 hostdata->force_le_on_be = 1;
160         } else {
161                 hostdata->clock = LASI710_CLOCK;
162                 hostdata->force_le_on_be = 0;
163                 hostdata->chip710 = 1;
164                 hostdata->dmode_extra = DMODE_FC2;
165         }
166         hostdata->pci_dev = ccio_get_fake(dev);
167         if((host = NCR_700_detect(host_tpnt, hostdata)) == NULL) {
168                 kfree(hostdata);
169                 return 1;
170         }
171         host->irq = dev->irq;
172         if(request_irq(dev->irq, NCR_700_intr, SA_SHIRQ, driver_name, host)) {
173                 printk(KERN_ERR "%s: irq problem, detaching\n",
174                        driver_name);
175                 scsi_unregister(host);
176                 NCR_700_release(host);
177                 return 1;
178         }
179         host_count++;
180         return 0;
181 }
182
183 static int
184 lasi700_release(struct Scsi_Host *host)
185 {
186         struct D700_Host_Parameters *hostdata = 
187                 (struct D700_Host_Parameters *)host->hostdata[0];
188
189         NCR_700_release(host);
190         kfree(hostdata);
191         free_irq(host->irq, host);
192         unregister_parisc_driver(&lasi700_driver);
193         return 1;
194 }
195
196 static Scsi_Host_Template driver_template = LASI700_SCSI;
197
198 #include "scsi_module.c"