ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / drivers / net / wireless / orinoco_tmd.c
1 /* orinoco_tmd.c 0.01
2  * 
3  * Driver for Prism II devices which would usually be driven by orinoco_cs,
4  * but are connected to the PCI bus by a TMD7160. 
5  *
6  * Copyright (C) 2003 Joerg Dorchain <joerg@dorchain.net>
7  * based heavily upon orinoco_plx.c Copyright (C) 2001 Daniel Barlow <dan@telent.net>
8  *
9  * The contents of this file are subject to the Mozilla Public License
10  * Version 1.1 (the "License"); you may not use this file except in
11  * compliance with the License. You may obtain a copy of the License
12  * at http://www.mozilla.org/MPL/
13  *
14  * Software distributed under the License is distributed on an "AS IS"
15  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
16  * the License for the specific language governing rights and
17  * limitations under the License.
18  *
19  * Alternatively, the contents of this file may be used under the
20  * terms of the GNU General Public License version 2 (the "GPL"), in
21  * which case the provisions of the GPL are applicable instead of the
22  * above.  If you wish to allow the use of your version of this file
23  * only under the terms of the GPL and not to allow others to use your
24  * version of this file under the MPL, indicate your decision by
25  * deleting the provisions above and replace them with the notice and
26  * other provisions required by the GPL.  If you do not delete the
27  * provisions above, a recipient may use your version of this file
28  * under either the MPL or the GPL.
29
30  * Caution: this is experimental and probably buggy.  For success and
31  * failure reports for different cards and adaptors, see
32  * orinoco_tmd_pci_id_table near the end of the file.  If you have a
33  * card we don't have the PCI id for, and looks like it should work,
34  * drop me mail with the id and "it works"/"it doesn't work".
35  *
36  * Note: if everything gets detected fine but it doesn't actually send
37  * or receive packets, your first port of call should probably be to   
38  * try newer firmware in the card.  Especially if you're doing Ad-Hoc
39  * modes
40  *
41  * The actual driving is done by orinoco.c, this is just resource
42  * allocation stuff.
43  *
44  * This driver is modeled after the orinoco_plx driver. The main
45  * difference is that the TMD chip has only IO port ranges and no
46  * memory space, i.e.  no access to the CIS. Compared to the PLX chip,
47  * the io range functionalities are exchanged.
48  *
49  * Pheecom sells cards with the TMD chip as "ASIC version"
50  */
51
52 #include <linux/config.h>
53
54 #include <linux/module.h>
55 #include <linux/kernel.h>
56 #include <linux/init.h>
57 #include <linux/sched.h>
58 #include <linux/ptrace.h>
59 #include <linux/slab.h>
60 #include <linux/string.h>
61 #include <linux/timer.h>
62 #include <linux/ioport.h>
63 #include <asm/uaccess.h>
64 #include <asm/io.h>
65 #include <asm/system.h>
66 #include <linux/netdevice.h>
67 #include <linux/if_arp.h>
68 #include <linux/etherdevice.h>
69 #include <linux/wireless.h>
70 #include <linux/list.h>
71 #include <linux/pci.h>
72 #include <linux/wireless.h>
73 #include <linux/fcntl.h>
74
75 #include <pcmcia/cisreg.h>
76
77 #include "hermes.h"
78 #include "orinoco.h"
79
80 static char dev_info[] = "orinoco_tmd";
81
82 #define COR_VALUE     (COR_LEVEL_REQ | COR_FUNC_ENA | COR_FUNC_ENA) /* Enable PC card with level triggered irqs and irq requests */
83
84
85 static int orinoco_tmd_init_one(struct pci_dev *pdev,
86                                 const struct pci_device_id *ent)
87 {
88         int err = 0;
89         u32 reg, addr;
90         struct orinoco_private *priv = NULL;
91         unsigned long pccard_ioaddr = 0;
92         unsigned long pccard_iolen = 0;
93         struct net_device *dev = NULL;
94
95         err = pci_enable_device(pdev);
96         if (err)
97                 return -EIO;
98
99         printk(KERN_DEBUG "TMD setup\n");
100         pccard_ioaddr = pci_resource_start(pdev, 2);
101         pccard_iolen = pci_resource_len(pdev, 2);
102         if (! request_region(pccard_ioaddr, pccard_iolen, dev_info)) {
103                 printk(KERN_ERR "orinoco_tmd: I/O resource at 0x%lx len 0x%lx busy\n",
104                         pccard_ioaddr, pccard_iolen);
105                 pccard_ioaddr = 0;
106                 err = -EBUSY;
107                 goto fail;
108         }
109         addr = pci_resource_start(pdev, 1);
110         outb(COR_VALUE, addr);
111         mdelay(1);
112         reg = inb(addr);
113         if (reg != COR_VALUE) {
114                 printk(KERN_ERR "orinoco_tmd: Error setting TMD COR values %x should be %x\n", reg, COR_VALUE);
115                 err = -EIO;
116                 goto fail;
117         }
118
119         dev = alloc_orinocodev(0, NULL);
120         if (! dev) {
121                 err = -ENOMEM;
122                 goto fail;
123         }
124
125         priv = dev->priv;
126         dev->base_addr = pccard_ioaddr;
127         SET_MODULE_OWNER(dev);
128         SET_NETDEV_DEV(dev, &pdev->dev);
129
130         printk(KERN_DEBUG
131                "Detected Orinoco/Prism2 TMD device at %s irq:%d, io addr:0x%lx\n",
132                pci_name(pdev), pdev->irq, pccard_ioaddr);
133
134         hermes_struct_init(&(priv->hw), dev->base_addr,
135                         HERMES_IO, HERMES_16BIT_REGSPACING);
136         pci_set_drvdata(pdev, dev);
137
138         err = request_irq(pdev->irq, orinoco_interrupt, SA_SHIRQ, dev->name,
139                           dev);
140         if (err) {
141                 printk(KERN_ERR "orinoco_tmd: Error allocating IRQ %d.\n",
142                        pdev->irq);
143                 err = -EBUSY;
144                 goto fail;
145         }
146         dev->irq = pdev->irq;
147
148         err = register_netdev(dev);
149         if (err)
150                 goto fail;
151
152         return 0;               /* succeeded */
153
154  fail:  
155         printk(KERN_DEBUG "orinoco_tmd: init_one(), FAIL!\n");
156
157         if (dev) {
158                 if (dev->irq)
159                         free_irq(dev->irq, dev);
160                 
161                 free_netdev(dev);
162         }
163
164         if (pccard_ioaddr)
165                 release_region(pccard_ioaddr, pccard_iolen);
166
167         pci_disable_device(pdev);
168
169         return err;
170 }
171
172 static void __devexit orinoco_tmd_remove_one(struct pci_dev *pdev)
173 {
174         struct net_device *dev = pci_get_drvdata(pdev);
175
176         if (! dev)
177                 BUG();
178
179         unregister_netdev(dev);
180                 
181         if (dev->irq)
182                 free_irq(dev->irq, dev);
183                 
184         pci_set_drvdata(pdev, NULL);
185
186         free_netdev(dev);
187
188         release_region(pci_resource_start(pdev, 2), pci_resource_len(pdev, 2));
189
190         pci_disable_device(pdev);
191 }
192
193
194 static struct pci_device_id orinoco_tmd_pci_id_table[] = {
195         {0x15e8, 0x0131, PCI_ANY_ID, PCI_ANY_ID,},      /* NDC and OEMs, e.g. pheecom */
196         {0,},
197 };
198
199 MODULE_DEVICE_TABLE(pci, orinoco_tmd_pci_id_table);
200
201 static struct pci_driver orinoco_tmd_driver = {
202         .name           = "orinoco_tmd",
203         .id_table       = orinoco_tmd_pci_id_table,
204         .probe          = orinoco_tmd_init_one,
205         .remove         = __devexit_p(orinoco_tmd_remove_one),
206         .suspend        = 0,
207         .resume         = 0,
208 };
209
210 static char version[] __initdata = "orinoco_tmd.c 0.01 (Joerg Dorchain <joerg@dorchain.net>)";
211 MODULE_AUTHOR("Joerg Dorchain <joerg@dorchain.net>");
212 MODULE_DESCRIPTION("Driver for wireless LAN cards using the TMD7160 PCI bridge");
213 #ifdef MODULE_LICENSE
214 MODULE_LICENSE("Dual MPL/GPL");
215 #endif
216
217 static int __init orinoco_tmd_init(void)
218 {
219         printk(KERN_DEBUG "%s\n", version);
220         return pci_module_init(&orinoco_tmd_driver);
221 }
222
223 extern void __exit orinoco_tmd_exit(void)
224 {
225         pci_unregister_driver(&orinoco_tmd_driver);
226         current->state = TASK_UNINTERRUPTIBLE;
227         schedule_timeout(HZ);
228 }
229
230 module_init(orinoco_tmd_init);
231 module_exit(orinoco_tmd_exit);
232
233 /*
234  * Local variables:
235  *  c-indent-level: 8
236  *  c-basic-offset: 8
237  *  tab-width: 8
238  * End:
239  */