[TG3]: Set minimal hw interrupt mitigation.
[linux-2.6/verdex.git] / drivers / net / wireless / orinoco_tmd.c
blob85893f42445be7e227c7fd3627747d66e984b656
1 /* orinoco_tmd.c
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.
6 * Copyright (C) 2003 Joerg Dorchain <joerg AT dorchain.net>
7 * based heavily upon orinoco_plx.c Copyright (C) 2001 Daniel Barlow
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/
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.
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.
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".
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
41 * The actual driving is done by orinoco.c, this is just resource
42 * allocation stuff.
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.
49 * Pheecom sells cards with the TMD chip as "ASIC version"
52 #define DRIVER_NAME "orinoco_tmd"
53 #define PFX DRIVER_NAME ": "
55 #include <linux/config.h>
57 #include <linux/module.h>
58 #include <linux/kernel.h>
59 #include <linux/init.h>
60 #include <linux/sched.h>
61 #include <linux/ptrace.h>
62 #include <linux/slab.h>
63 #include <linux/string.h>
64 #include <linux/timer.h>
65 #include <linux/ioport.h>
66 #include <asm/uaccess.h>
67 #include <asm/io.h>
68 #include <asm/system.h>
69 #include <linux/netdevice.h>
70 #include <linux/if_arp.h>
71 #include <linux/etherdevice.h>
72 #include <linux/list.h>
73 #include <linux/pci.h>
74 #include <linux/fcntl.h>
76 #include <pcmcia/cisreg.h>
78 #include "hermes.h"
79 #include "orinoco.h"
81 #define COR_VALUE (COR_LEVEL_REQ | COR_FUNC_ENA) /* Enable PC card with interrupt in level trigger */
82 #define COR_RESET (0x80) /* reset bit in the COR register */
83 #define TMD_RESET_TIME (500) /* milliseconds */
85 /* Orinoco TMD specific data */
86 struct orinoco_tmd_card {
87 u32 tmd_io;
92 * Do a soft reset of the card using the Configuration Option Register
94 static int orinoco_tmd_cor_reset(struct orinoco_private *priv)
96 hermes_t *hw = &priv->hw;
97 struct orinoco_tmd_card *card = priv->card;
98 u32 addr = card->tmd_io;
99 unsigned long timeout;
100 u16 reg;
102 outb(COR_VALUE | COR_RESET, addr);
103 mdelay(1);
105 outb(COR_VALUE, addr);
106 mdelay(1);
108 /* Just in case, wait more until the card is no longer busy */
109 timeout = jiffies + (TMD_RESET_TIME * HZ / 1000);
110 reg = hermes_read_regn(hw, CMD);
111 while (time_before(jiffies, timeout) && (reg & HERMES_CMD_BUSY)) {
112 mdelay(1);
113 reg = hermes_read_regn(hw, CMD);
116 /* Did we timeout ? */
117 if (reg & HERMES_CMD_BUSY) {
118 printk(KERN_ERR PFX "Busy timeout\n");
119 return -ETIMEDOUT;
122 return 0;
126 static int orinoco_tmd_init_one(struct pci_dev *pdev,
127 const struct pci_device_id *ent)
129 int err = 0;
130 struct orinoco_private *priv = NULL;
131 struct orinoco_tmd_card *card;
132 struct net_device *dev = NULL;
133 void __iomem *mem;
135 err = pci_enable_device(pdev);
136 if (err) {
137 printk(KERN_ERR PFX "Cannot enable PCI device\n");
138 return err;
141 err = pci_request_regions(pdev, DRIVER_NAME);
142 if (err != 0) {
143 printk(KERN_ERR PFX "Cannot obtain PCI resources\n");
144 goto fail_resources;
147 mem = pci_iomap(pdev, 2, 0);
148 if (! mem) {
149 err = -ENOMEM;
150 goto fail_iomap;
153 /* Allocate network device */
154 dev = alloc_orinocodev(sizeof(*card), orinoco_tmd_cor_reset);
155 if (! dev) {
156 printk(KERN_ERR PFX "Cannot allocate network device\n");
157 err = -ENOMEM;
158 goto fail_alloc;
161 priv = netdev_priv(dev);
162 card = priv->card;
163 card->tmd_io = pci_resource_start(pdev, 1);
164 dev->base_addr = pci_resource_start(pdev, 2);
165 SET_MODULE_OWNER(dev);
166 SET_NETDEV_DEV(dev, &pdev->dev);
168 hermes_struct_init(&priv->hw, mem, HERMES_16BIT_REGSPACING);
170 printk(KERN_DEBUG PFX "Detected Orinoco/Prism2 TMD device "
171 "at %s irq:%d, io addr:0x%lx\n", pci_name(pdev), pdev->irq,
172 dev->base_addr);
174 err = request_irq(pdev->irq, orinoco_interrupt, SA_SHIRQ,
175 dev->name, dev);
176 if (err) {
177 printk(KERN_ERR PFX "Cannot allocate IRQ %d\n", pdev->irq);
178 err = -EBUSY;
179 goto fail_irq;
181 dev->irq = pdev->irq;
183 err = orinoco_tmd_cor_reset(priv);
184 if (err) {
185 printk(KERN_ERR PFX "Initial reset failed\n");
186 goto fail;
189 err = register_netdev(dev);
190 if (err) {
191 printk(KERN_ERR PFX "Cannot register network device\n");
192 goto fail;
195 pci_set_drvdata(pdev, dev);
197 return 0;
199 fail:
200 free_irq(pdev->irq, dev);
202 fail_irq:
203 pci_set_drvdata(pdev, NULL);
204 free_orinocodev(dev);
206 fail_alloc:
207 pci_iounmap(pdev, mem);
209 fail_iomap:
210 pci_release_regions(pdev);
212 fail_resources:
213 pci_disable_device(pdev);
215 return err;
218 static void __devexit orinoco_tmd_remove_one(struct pci_dev *pdev)
220 struct net_device *dev = pci_get_drvdata(pdev);
221 struct orinoco_private *priv = dev->priv;
223 BUG_ON(! dev);
225 unregister_netdev(dev);
226 free_irq(dev->irq, dev);
227 pci_set_drvdata(pdev, NULL);
228 free_orinocodev(dev);
229 pci_iounmap(pdev, priv->hw.iobase);
230 pci_release_regions(pdev);
231 pci_disable_device(pdev);
235 static struct pci_device_id orinoco_tmd_pci_id_table[] = {
236 {0x15e8, 0x0131, PCI_ANY_ID, PCI_ANY_ID,}, /* NDC and OEMs, e.g. pheecom */
237 {0,},
240 MODULE_DEVICE_TABLE(pci, orinoco_tmd_pci_id_table);
242 static struct pci_driver orinoco_tmd_driver = {
243 .name = DRIVER_NAME,
244 .id_table = orinoco_tmd_pci_id_table,
245 .probe = orinoco_tmd_init_one,
246 .remove = __devexit_p(orinoco_tmd_remove_one),
249 static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
250 " (Joerg Dorchain <joerg@dorchain.net>)";
251 MODULE_AUTHOR("Joerg Dorchain <joerg@dorchain.net>");
252 MODULE_DESCRIPTION("Driver for wireless LAN cards using the TMD7160 PCI bridge");
253 MODULE_LICENSE("Dual MPL/GPL");
255 static int __init orinoco_tmd_init(void)
257 printk(KERN_DEBUG "%s\n", version);
258 return pci_module_init(&orinoco_tmd_driver);
261 static void __exit orinoco_tmd_exit(void)
263 pci_unregister_driver(&orinoco_tmd_driver);
264 ssleep(1);
267 module_init(orinoco_tmd_init);
268 module_exit(orinoco_tmd_exit);
271 * Local variables:
272 * c-indent-level: 8
273 * c-basic-offset: 8
274 * tab-width: 8
275 * End: