xref: /OK3568_Linux_fs/kernel/drivers/net/wireless/cisco/airo_cs.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*======================================================================
2*4882a593Smuzhiyun 
3*4882a593Smuzhiyun     Aironet driver for 4500 and 4800 series cards
4*4882a593Smuzhiyun 
5*4882a593Smuzhiyun     This code is released under both the GPL version 2 and BSD licenses.
6*4882a593Smuzhiyun     Either license may be used.  The respective licenses are found at
7*4882a593Smuzhiyun     the end of this file.
8*4882a593Smuzhiyun 
9*4882a593Smuzhiyun     This code was developed by Benjamin Reed <breed@users.sourceforge.net>
10*4882a593Smuzhiyun     including portions of which come from the Aironet PC4500
11*4882a593Smuzhiyun     Developer's Reference Manual and used with permission.  Copyright
12*4882a593Smuzhiyun     (C) 1999 Benjamin Reed.  All Rights Reserved.  Permission to use
13*4882a593Smuzhiyun     code in the Developer's manual was granted for this driver by
14*4882a593Smuzhiyun     Aironet.
15*4882a593Smuzhiyun 
16*4882a593Smuzhiyun     In addition this module was derived from dummy_cs.
17*4882a593Smuzhiyun     The initial developer of dummy_cs is David A. Hinds
18*4882a593Smuzhiyun     <dahinds@users.sourceforge.net>.  Portions created by David A. Hinds
19*4882a593Smuzhiyun     are Copyright (C) 1999 David A. Hinds.  All Rights Reserved.
20*4882a593Smuzhiyun 
21*4882a593Smuzhiyun ======================================================================*/
22*4882a593Smuzhiyun 
23*4882a593Smuzhiyun #ifdef __IN_PCMCIA_PACKAGE__
24*4882a593Smuzhiyun #include <pcmcia/k_compat.h>
25*4882a593Smuzhiyun #endif
26*4882a593Smuzhiyun #include <linux/kernel.h>
27*4882a593Smuzhiyun #include <linux/module.h>
28*4882a593Smuzhiyun #include <linux/ptrace.h>
29*4882a593Smuzhiyun #include <linux/slab.h>
30*4882a593Smuzhiyun #include <linux/string.h>
31*4882a593Smuzhiyun #include <linux/timer.h>
32*4882a593Smuzhiyun #include <linux/netdevice.h>
33*4882a593Smuzhiyun 
34*4882a593Smuzhiyun #include <pcmcia/cistpl.h>
35*4882a593Smuzhiyun #include <pcmcia/cisreg.h>
36*4882a593Smuzhiyun #include <pcmcia/ds.h>
37*4882a593Smuzhiyun 
38*4882a593Smuzhiyun #include <linux/io.h>
39*4882a593Smuzhiyun 
40*4882a593Smuzhiyun #include "airo.h"
41*4882a593Smuzhiyun 
42*4882a593Smuzhiyun 
43*4882a593Smuzhiyun /*====================================================================*/
44*4882a593Smuzhiyun 
45*4882a593Smuzhiyun MODULE_AUTHOR("Benjamin Reed");
46*4882a593Smuzhiyun MODULE_DESCRIPTION("Support for Cisco/Aironet 802.11 wireless ethernet "
47*4882a593Smuzhiyun 		   "cards.  This is the module that links the PCMCIA card "
48*4882a593Smuzhiyun 		   "with the airo module.");
49*4882a593Smuzhiyun MODULE_LICENSE("Dual BSD/GPL");
50*4882a593Smuzhiyun MODULE_SUPPORTED_DEVICE("Aironet 4500, 4800 and Cisco 340 PCMCIA cards");
51*4882a593Smuzhiyun 
52*4882a593Smuzhiyun /*====================================================================*/
53*4882a593Smuzhiyun 
54*4882a593Smuzhiyun static int airo_config(struct pcmcia_device *link);
55*4882a593Smuzhiyun static void airo_release(struct pcmcia_device *link);
56*4882a593Smuzhiyun 
57*4882a593Smuzhiyun static void airo_detach(struct pcmcia_device *p_dev);
58*4882a593Smuzhiyun 
59*4882a593Smuzhiyun struct local_info {
60*4882a593Smuzhiyun 	struct net_device *eth_dev;
61*4882a593Smuzhiyun };
62*4882a593Smuzhiyun 
airo_probe(struct pcmcia_device * p_dev)63*4882a593Smuzhiyun static int airo_probe(struct pcmcia_device *p_dev)
64*4882a593Smuzhiyun {
65*4882a593Smuzhiyun 	struct local_info *local;
66*4882a593Smuzhiyun 
67*4882a593Smuzhiyun 	dev_dbg(&p_dev->dev, "airo_attach()\n");
68*4882a593Smuzhiyun 
69*4882a593Smuzhiyun 	/* Allocate space for private device-specific data */
70*4882a593Smuzhiyun 	local = kzalloc(sizeof(*local), GFP_KERNEL);
71*4882a593Smuzhiyun 	if (!local)
72*4882a593Smuzhiyun 		return -ENOMEM;
73*4882a593Smuzhiyun 
74*4882a593Smuzhiyun 	p_dev->priv = local;
75*4882a593Smuzhiyun 
76*4882a593Smuzhiyun 	return airo_config(p_dev);
77*4882a593Smuzhiyun } /* airo_attach */
78*4882a593Smuzhiyun 
airo_detach(struct pcmcia_device * link)79*4882a593Smuzhiyun static void airo_detach(struct pcmcia_device *link)
80*4882a593Smuzhiyun {
81*4882a593Smuzhiyun 	dev_dbg(&link->dev, "airo_detach\n");
82*4882a593Smuzhiyun 
83*4882a593Smuzhiyun 	airo_release(link);
84*4882a593Smuzhiyun 
85*4882a593Smuzhiyun 	if (((struct local_info *)link->priv)->eth_dev) {
86*4882a593Smuzhiyun 		stop_airo_card(((struct local_info *)link->priv)->eth_dev,
87*4882a593Smuzhiyun 			       0);
88*4882a593Smuzhiyun 	}
89*4882a593Smuzhiyun 	((struct local_info *)link->priv)->eth_dev = NULL;
90*4882a593Smuzhiyun 
91*4882a593Smuzhiyun 	kfree(link->priv);
92*4882a593Smuzhiyun } /* airo_detach */
93*4882a593Smuzhiyun 
airo_cs_config_check(struct pcmcia_device * p_dev,void * priv_data)94*4882a593Smuzhiyun static int airo_cs_config_check(struct pcmcia_device *p_dev, void *priv_data)
95*4882a593Smuzhiyun {
96*4882a593Smuzhiyun 	if (p_dev->config_index == 0)
97*4882a593Smuzhiyun 		return -EINVAL;
98*4882a593Smuzhiyun 
99*4882a593Smuzhiyun 	return pcmcia_request_io(p_dev);
100*4882a593Smuzhiyun }
101*4882a593Smuzhiyun 
102*4882a593Smuzhiyun 
airo_config(struct pcmcia_device * link)103*4882a593Smuzhiyun static int airo_config(struct pcmcia_device *link)
104*4882a593Smuzhiyun {
105*4882a593Smuzhiyun 	int ret;
106*4882a593Smuzhiyun 
107*4882a593Smuzhiyun 	dev_dbg(&link->dev, "airo_config\n");
108*4882a593Smuzhiyun 
109*4882a593Smuzhiyun 	link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_VPP |
110*4882a593Smuzhiyun 		CONF_AUTO_AUDIO | CONF_AUTO_SET_IO;
111*4882a593Smuzhiyun 
112*4882a593Smuzhiyun 	ret = pcmcia_loop_config(link, airo_cs_config_check, NULL);
113*4882a593Smuzhiyun 	if (ret)
114*4882a593Smuzhiyun 		goto failed;
115*4882a593Smuzhiyun 
116*4882a593Smuzhiyun 	if (!link->irq)
117*4882a593Smuzhiyun 		goto failed;
118*4882a593Smuzhiyun 
119*4882a593Smuzhiyun 	ret = pcmcia_enable_device(link);
120*4882a593Smuzhiyun 	if (ret)
121*4882a593Smuzhiyun 		goto failed;
122*4882a593Smuzhiyun 	((struct local_info *)link->priv)->eth_dev =
123*4882a593Smuzhiyun 		init_airo_card(link->irq,
124*4882a593Smuzhiyun 			       link->resource[0]->start, 1, &link->dev);
125*4882a593Smuzhiyun 	if (!((struct local_info *)link->priv)->eth_dev)
126*4882a593Smuzhiyun 		goto failed;
127*4882a593Smuzhiyun 
128*4882a593Smuzhiyun 	return 0;
129*4882a593Smuzhiyun 
130*4882a593Smuzhiyun  failed:
131*4882a593Smuzhiyun 	airo_release(link);
132*4882a593Smuzhiyun 	return -ENODEV;
133*4882a593Smuzhiyun } /* airo_config */
134*4882a593Smuzhiyun 
airo_release(struct pcmcia_device * link)135*4882a593Smuzhiyun static void airo_release(struct pcmcia_device *link)
136*4882a593Smuzhiyun {
137*4882a593Smuzhiyun 	dev_dbg(&link->dev, "airo_release\n");
138*4882a593Smuzhiyun 	pcmcia_disable_device(link);
139*4882a593Smuzhiyun }
140*4882a593Smuzhiyun 
airo_suspend(struct pcmcia_device * link)141*4882a593Smuzhiyun static int airo_suspend(struct pcmcia_device *link)
142*4882a593Smuzhiyun {
143*4882a593Smuzhiyun 	struct local_info *local = link->priv;
144*4882a593Smuzhiyun 
145*4882a593Smuzhiyun 	netif_device_detach(local->eth_dev);
146*4882a593Smuzhiyun 
147*4882a593Smuzhiyun 	return 0;
148*4882a593Smuzhiyun }
149*4882a593Smuzhiyun 
airo_resume(struct pcmcia_device * link)150*4882a593Smuzhiyun static int airo_resume(struct pcmcia_device *link)
151*4882a593Smuzhiyun {
152*4882a593Smuzhiyun 	struct local_info *local = link->priv;
153*4882a593Smuzhiyun 
154*4882a593Smuzhiyun 	if (link->open) {
155*4882a593Smuzhiyun 		reset_airo_card(local->eth_dev);
156*4882a593Smuzhiyun 		netif_device_attach(local->eth_dev);
157*4882a593Smuzhiyun 	}
158*4882a593Smuzhiyun 
159*4882a593Smuzhiyun 	return 0;
160*4882a593Smuzhiyun }
161*4882a593Smuzhiyun 
162*4882a593Smuzhiyun static const struct pcmcia_device_id airo_ids[] = {
163*4882a593Smuzhiyun 	PCMCIA_DEVICE_MANF_CARD(0x015f, 0x000a),
164*4882a593Smuzhiyun 	PCMCIA_DEVICE_MANF_CARD(0x015f, 0x0005),
165*4882a593Smuzhiyun 	PCMCIA_DEVICE_MANF_CARD(0x015f, 0x0007),
166*4882a593Smuzhiyun 	PCMCIA_DEVICE_MANF_CARD(0x0105, 0x0007),
167*4882a593Smuzhiyun 	PCMCIA_DEVICE_NULL,
168*4882a593Smuzhiyun };
169*4882a593Smuzhiyun MODULE_DEVICE_TABLE(pcmcia, airo_ids);
170*4882a593Smuzhiyun 
171*4882a593Smuzhiyun static struct pcmcia_driver airo_driver = {
172*4882a593Smuzhiyun 	.owner		= THIS_MODULE,
173*4882a593Smuzhiyun 	.name		= "airo_cs",
174*4882a593Smuzhiyun 	.probe		= airo_probe,
175*4882a593Smuzhiyun 	.remove		= airo_detach,
176*4882a593Smuzhiyun 	.id_table       = airo_ids,
177*4882a593Smuzhiyun 	.suspend	= airo_suspend,
178*4882a593Smuzhiyun 	.resume		= airo_resume,
179*4882a593Smuzhiyun };
180*4882a593Smuzhiyun module_pcmcia_driver(airo_driver);
181*4882a593Smuzhiyun 
182*4882a593Smuzhiyun /*
183*4882a593Smuzhiyun     This program is free software; you can redistribute it and/or
184*4882a593Smuzhiyun     modify it under the terms of the GNU General Public License
185*4882a593Smuzhiyun     as published by the Free Software Foundation; either version 2
186*4882a593Smuzhiyun     of the License, or (at your option) any later version.
187*4882a593Smuzhiyun 
188*4882a593Smuzhiyun     This program is distributed in the hope that it will be useful,
189*4882a593Smuzhiyun     but WITHOUT ANY WARRANTY; without even the implied warranty of
190*4882a593Smuzhiyun     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
191*4882a593Smuzhiyun     GNU General Public License for more details.
192*4882a593Smuzhiyun 
193*4882a593Smuzhiyun     In addition:
194*4882a593Smuzhiyun 
195*4882a593Smuzhiyun     Redistribution and use in source and binary forms, with or without
196*4882a593Smuzhiyun     modification, are permitted provided that the following conditions
197*4882a593Smuzhiyun     are met:
198*4882a593Smuzhiyun 
199*4882a593Smuzhiyun     1. Redistributions of source code must retain the above copyright
200*4882a593Smuzhiyun        notice, this list of conditions and the following disclaimer.
201*4882a593Smuzhiyun     2. Redistributions in binary form must reproduce the above copyright
202*4882a593Smuzhiyun        notice, this list of conditions and the following disclaimer in the
203*4882a593Smuzhiyun        documentation and/or other materials provided with the distribution.
204*4882a593Smuzhiyun     3. The name of the author may not be used to endorse or promote
205*4882a593Smuzhiyun        products derived from this software without specific prior written
206*4882a593Smuzhiyun        permission.
207*4882a593Smuzhiyun 
208*4882a593Smuzhiyun     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
209*4882a593Smuzhiyun     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
210*4882a593Smuzhiyun     WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
211*4882a593Smuzhiyun     ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
212*4882a593Smuzhiyun     INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
213*4882a593Smuzhiyun     (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
214*4882a593Smuzhiyun     SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
215*4882a593Smuzhiyun     HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
216*4882a593Smuzhiyun     STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
217*4882a593Smuzhiyun     IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
218*4882a593Smuzhiyun     POSSIBILITY OF SUCH DAMAGE.
219*4882a593Smuzhiyun */
220