xref: /OK3568_Linux_fs/kernel/drivers/scsi/pcmcia/aha152x_stub.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*======================================================================
2*4882a593Smuzhiyun 
3*4882a593Smuzhiyun     A driver for Adaptec AHA152X-compatible PCMCIA SCSI cards.
4*4882a593Smuzhiyun 
5*4882a593Smuzhiyun     This driver supports the Adaptec AHA-1460, the New Media Bus
6*4882a593Smuzhiyun     Toaster, and the New Media Toast & Jam.
7*4882a593Smuzhiyun 
8*4882a593Smuzhiyun     aha152x_cs.c 1.54 2000/06/12 21:27:25
9*4882a593Smuzhiyun 
10*4882a593Smuzhiyun     The contents of this file are subject to the Mozilla Public
11*4882a593Smuzhiyun     License Version 1.1 (the "License"); you may not use this file
12*4882a593Smuzhiyun     except in compliance with the License. You may obtain a copy of
13*4882a593Smuzhiyun     the License at http://www.mozilla.org/MPL/
14*4882a593Smuzhiyun 
15*4882a593Smuzhiyun     Software distributed under the License is distributed on an "AS
16*4882a593Smuzhiyun     IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
17*4882a593Smuzhiyun     implied. See the License for the specific language governing
18*4882a593Smuzhiyun     rights and limitations under the License.
19*4882a593Smuzhiyun 
20*4882a593Smuzhiyun     The initial developer of the original code is David A. Hinds
21*4882a593Smuzhiyun     <dahinds@users.sourceforge.net>.  Portions created by David A. Hinds
22*4882a593Smuzhiyun     are Copyright (C) 1999 David A. Hinds.  All Rights Reserved.
23*4882a593Smuzhiyun 
24*4882a593Smuzhiyun     Alternatively, the contents of this file may be used under the
25*4882a593Smuzhiyun     terms of the GNU General Public License version 2 (the "GPL"), in which
26*4882a593Smuzhiyun     case the provisions of the GPL are applicable instead of the
27*4882a593Smuzhiyun     above.  If you wish to allow the use of your version of this file
28*4882a593Smuzhiyun     only under the terms of the GPL and not to allow others to use
29*4882a593Smuzhiyun     your version of this file under the MPL, indicate your decision
30*4882a593Smuzhiyun     by deleting the provisions above and replace them with the notice
31*4882a593Smuzhiyun     and other provisions required by the GPL.  If you do not delete
32*4882a593Smuzhiyun     the provisions above, a recipient may use your version of this
33*4882a593Smuzhiyun     file under either the MPL or the GPL.
34*4882a593Smuzhiyun 
35*4882a593Smuzhiyun ======================================================================*/
36*4882a593Smuzhiyun 
37*4882a593Smuzhiyun #include <linux/module.h>
38*4882a593Smuzhiyun #include <linux/init.h>
39*4882a593Smuzhiyun #include <linux/kernel.h>
40*4882a593Smuzhiyun #include <linux/slab.h>
41*4882a593Smuzhiyun #include <linux/string.h>
42*4882a593Smuzhiyun #include <linux/ioport.h>
43*4882a593Smuzhiyun #include <scsi/scsi.h>
44*4882a593Smuzhiyun #include <linux/major.h>
45*4882a593Smuzhiyun #include <linux/blkdev.h>
46*4882a593Smuzhiyun #include <scsi/scsi_ioctl.h>
47*4882a593Smuzhiyun 
48*4882a593Smuzhiyun #include "scsi.h"
49*4882a593Smuzhiyun #include <scsi/scsi_host.h>
50*4882a593Smuzhiyun #include "aha152x.h"
51*4882a593Smuzhiyun 
52*4882a593Smuzhiyun #include <pcmcia/cistpl.h>
53*4882a593Smuzhiyun #include <pcmcia/ds.h>
54*4882a593Smuzhiyun 
55*4882a593Smuzhiyun 
56*4882a593Smuzhiyun /*====================================================================*/
57*4882a593Smuzhiyun 
58*4882a593Smuzhiyun /* Parameters that can be set with 'insmod' */
59*4882a593Smuzhiyun 
60*4882a593Smuzhiyun /* SCSI bus setup options */
61*4882a593Smuzhiyun static int host_id = 7;
62*4882a593Smuzhiyun static int reconnect = 1;
63*4882a593Smuzhiyun static int parity = 1;
64*4882a593Smuzhiyun static int synchronous = 1;
65*4882a593Smuzhiyun static int reset_delay = 100;
66*4882a593Smuzhiyun static int ext_trans = 0;
67*4882a593Smuzhiyun 
68*4882a593Smuzhiyun module_param(host_id, int, 0);
69*4882a593Smuzhiyun module_param(reconnect, int, 0);
70*4882a593Smuzhiyun module_param(parity, int, 0);
71*4882a593Smuzhiyun module_param(synchronous, int, 0);
72*4882a593Smuzhiyun module_param(reset_delay, int, 0);
73*4882a593Smuzhiyun module_param(ext_trans, int, 0);
74*4882a593Smuzhiyun 
75*4882a593Smuzhiyun MODULE_LICENSE("Dual MPL/GPL");
76*4882a593Smuzhiyun 
77*4882a593Smuzhiyun /*====================================================================*/
78*4882a593Smuzhiyun 
79*4882a593Smuzhiyun typedef struct scsi_info_t {
80*4882a593Smuzhiyun 	struct pcmcia_device	*p_dev;
81*4882a593Smuzhiyun     struct Scsi_Host	*host;
82*4882a593Smuzhiyun } scsi_info_t;
83*4882a593Smuzhiyun 
84*4882a593Smuzhiyun static void aha152x_release_cs(struct pcmcia_device *link);
85*4882a593Smuzhiyun static void aha152x_detach(struct pcmcia_device *p_dev);
86*4882a593Smuzhiyun static int aha152x_config_cs(struct pcmcia_device *link);
87*4882a593Smuzhiyun 
aha152x_probe(struct pcmcia_device * link)88*4882a593Smuzhiyun static int aha152x_probe(struct pcmcia_device *link)
89*4882a593Smuzhiyun {
90*4882a593Smuzhiyun     scsi_info_t *info;
91*4882a593Smuzhiyun 
92*4882a593Smuzhiyun     dev_dbg(&link->dev, "aha152x_attach()\n");
93*4882a593Smuzhiyun 
94*4882a593Smuzhiyun     /* Create new SCSI device */
95*4882a593Smuzhiyun     info = kzalloc(sizeof(*info), GFP_KERNEL);
96*4882a593Smuzhiyun     if (!info) return -ENOMEM;
97*4882a593Smuzhiyun     info->p_dev = link;
98*4882a593Smuzhiyun     link->priv = info;
99*4882a593Smuzhiyun 
100*4882a593Smuzhiyun     link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
101*4882a593Smuzhiyun     link->config_regs = PRESENT_OPTION;
102*4882a593Smuzhiyun 
103*4882a593Smuzhiyun     return aha152x_config_cs(link);
104*4882a593Smuzhiyun } /* aha152x_attach */
105*4882a593Smuzhiyun 
106*4882a593Smuzhiyun /*====================================================================*/
107*4882a593Smuzhiyun 
aha152x_detach(struct pcmcia_device * link)108*4882a593Smuzhiyun static void aha152x_detach(struct pcmcia_device *link)
109*4882a593Smuzhiyun {
110*4882a593Smuzhiyun     dev_dbg(&link->dev, "aha152x_detach\n");
111*4882a593Smuzhiyun 
112*4882a593Smuzhiyun     aha152x_release_cs(link);
113*4882a593Smuzhiyun 
114*4882a593Smuzhiyun     /* Unlink device structure, free bits */
115*4882a593Smuzhiyun     kfree(link->priv);
116*4882a593Smuzhiyun } /* aha152x_detach */
117*4882a593Smuzhiyun 
118*4882a593Smuzhiyun /*====================================================================*/
119*4882a593Smuzhiyun 
aha152x_config_check(struct pcmcia_device * p_dev,void * priv_data)120*4882a593Smuzhiyun static int aha152x_config_check(struct pcmcia_device *p_dev, void *priv_data)
121*4882a593Smuzhiyun {
122*4882a593Smuzhiyun 	p_dev->io_lines = 10;
123*4882a593Smuzhiyun 
124*4882a593Smuzhiyun 	/* For New Media T&J, look for a SCSI window */
125*4882a593Smuzhiyun 	if ((p_dev->resource[0]->end < 0x20) &&
126*4882a593Smuzhiyun 		(p_dev->resource[1]->end >= 0x20))
127*4882a593Smuzhiyun 		p_dev->resource[0]->start = p_dev->resource[1]->start;
128*4882a593Smuzhiyun 
129*4882a593Smuzhiyun 	if (p_dev->resource[0]->start >= 0xffff)
130*4882a593Smuzhiyun 		return -EINVAL;
131*4882a593Smuzhiyun 
132*4882a593Smuzhiyun 	p_dev->resource[1]->start = p_dev->resource[1]->end = 0;
133*4882a593Smuzhiyun 	p_dev->resource[0]->end = 0x20;
134*4882a593Smuzhiyun 	p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
135*4882a593Smuzhiyun 	p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO;
136*4882a593Smuzhiyun 
137*4882a593Smuzhiyun 	return pcmcia_request_io(p_dev);
138*4882a593Smuzhiyun }
139*4882a593Smuzhiyun 
aha152x_config_cs(struct pcmcia_device * link)140*4882a593Smuzhiyun static int aha152x_config_cs(struct pcmcia_device *link)
141*4882a593Smuzhiyun {
142*4882a593Smuzhiyun     scsi_info_t *info = link->priv;
143*4882a593Smuzhiyun     struct aha152x_setup s;
144*4882a593Smuzhiyun     int ret;
145*4882a593Smuzhiyun     struct Scsi_Host *host;
146*4882a593Smuzhiyun 
147*4882a593Smuzhiyun     dev_dbg(&link->dev, "aha152x_config\n");
148*4882a593Smuzhiyun 
149*4882a593Smuzhiyun     ret = pcmcia_loop_config(link, aha152x_config_check, NULL);
150*4882a593Smuzhiyun     if (ret)
151*4882a593Smuzhiyun 	    goto failed;
152*4882a593Smuzhiyun 
153*4882a593Smuzhiyun     if (!link->irq)
154*4882a593Smuzhiyun 	    goto failed;
155*4882a593Smuzhiyun 
156*4882a593Smuzhiyun     ret = pcmcia_enable_device(link);
157*4882a593Smuzhiyun     if (ret)
158*4882a593Smuzhiyun 	    goto failed;
159*4882a593Smuzhiyun 
160*4882a593Smuzhiyun     /* Set configuration options for the aha152x driver */
161*4882a593Smuzhiyun     memset(&s, 0, sizeof(s));
162*4882a593Smuzhiyun     s.conf        = "PCMCIA setup";
163*4882a593Smuzhiyun     s.io_port     = link->resource[0]->start;
164*4882a593Smuzhiyun     s.irq         = link->irq;
165*4882a593Smuzhiyun     s.scsiid      = host_id;
166*4882a593Smuzhiyun     s.reconnect   = reconnect;
167*4882a593Smuzhiyun     s.parity      = parity;
168*4882a593Smuzhiyun     s.synchronous = synchronous;
169*4882a593Smuzhiyun     s.delay       = reset_delay;
170*4882a593Smuzhiyun     if (ext_trans)
171*4882a593Smuzhiyun         s.ext_trans = ext_trans;
172*4882a593Smuzhiyun 
173*4882a593Smuzhiyun     host = aha152x_probe_one(&s);
174*4882a593Smuzhiyun     if (host == NULL) {
175*4882a593Smuzhiyun 	printk(KERN_INFO "aha152x_cs: no SCSI devices found\n");
176*4882a593Smuzhiyun 	goto failed;
177*4882a593Smuzhiyun     }
178*4882a593Smuzhiyun 
179*4882a593Smuzhiyun     info->host = host;
180*4882a593Smuzhiyun 
181*4882a593Smuzhiyun     return 0;
182*4882a593Smuzhiyun 
183*4882a593Smuzhiyun failed:
184*4882a593Smuzhiyun     aha152x_release_cs(link);
185*4882a593Smuzhiyun     return -ENODEV;
186*4882a593Smuzhiyun }
187*4882a593Smuzhiyun 
aha152x_release_cs(struct pcmcia_device * link)188*4882a593Smuzhiyun static void aha152x_release_cs(struct pcmcia_device *link)
189*4882a593Smuzhiyun {
190*4882a593Smuzhiyun 	scsi_info_t *info = link->priv;
191*4882a593Smuzhiyun 
192*4882a593Smuzhiyun 	aha152x_release(info->host);
193*4882a593Smuzhiyun 	pcmcia_disable_device(link);
194*4882a593Smuzhiyun }
195*4882a593Smuzhiyun 
aha152x_resume(struct pcmcia_device * link)196*4882a593Smuzhiyun static int aha152x_resume(struct pcmcia_device *link)
197*4882a593Smuzhiyun {
198*4882a593Smuzhiyun 	scsi_info_t *info = link->priv;
199*4882a593Smuzhiyun 
200*4882a593Smuzhiyun 	aha152x_host_reset_host(info->host);
201*4882a593Smuzhiyun 
202*4882a593Smuzhiyun 	return 0;
203*4882a593Smuzhiyun }
204*4882a593Smuzhiyun 
205*4882a593Smuzhiyun static const struct pcmcia_device_id aha152x_ids[] = {
206*4882a593Smuzhiyun 	PCMCIA_DEVICE_PROD_ID123("New Media", "SCSI", "Bus Toaster", 0xcdf7e4cc, 0x35f26476, 0xa8851d6e),
207*4882a593Smuzhiyun 	PCMCIA_DEVICE_PROD_ID123("NOTEWORTHY", "SCSI", "Bus Toaster", 0xad89c6e8, 0x35f26476, 0xa8851d6e),
208*4882a593Smuzhiyun 	PCMCIA_DEVICE_PROD_ID12("Adaptec, Inc.", "APA-1460 SCSI Host Adapter", 0x24ba9738, 0x3a3c3d20),
209*4882a593Smuzhiyun 	PCMCIA_DEVICE_PROD_ID12("New Media Corporation", "Multimedia Sound/SCSI", 0x085a850b, 0x80a6535c),
210*4882a593Smuzhiyun 	PCMCIA_DEVICE_PROD_ID12("NOTEWORTHY", "NWCOMB02 SCSI/AUDIO COMBO CARD", 0xad89c6e8, 0x5f9a615b),
211*4882a593Smuzhiyun 	PCMCIA_DEVICE_NULL,
212*4882a593Smuzhiyun };
213*4882a593Smuzhiyun MODULE_DEVICE_TABLE(pcmcia, aha152x_ids);
214*4882a593Smuzhiyun 
215*4882a593Smuzhiyun static struct pcmcia_driver aha152x_cs_driver = {
216*4882a593Smuzhiyun 	.owner		= THIS_MODULE,
217*4882a593Smuzhiyun 	.name		= "aha152x_cs",
218*4882a593Smuzhiyun 	.probe		= aha152x_probe,
219*4882a593Smuzhiyun 	.remove		= aha152x_detach,
220*4882a593Smuzhiyun 	.id_table       = aha152x_ids,
221*4882a593Smuzhiyun 	.resume		= aha152x_resume,
222*4882a593Smuzhiyun };
223*4882a593Smuzhiyun module_pcmcia_driver(aha152x_cs_driver);
224