blob: 2547d5dac0d338752439e14be5db194871b5baa2 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* orinoco_pci.c
2 *
Pavel Roskindc3437d2006-04-07 04:11:00 -04003 * Driver for Prism 2.5/3 devices that have a direct PCI interface
4 * (i.e. these are not PCMCIA cards in a PCMCIA-to-PCI bridge).
5 * The card contains only one PCI region, which contains all the usual
6 * hermes registers, as well as the COR register.
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 *
Pavel Roskindc3437d2006-04-07 04:11:00 -04008 * Current maintainers are:
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * Pavel Roskin <proski AT gnu.org>
10 * and David Gibson <hermes AT gibson.dropbear.id.au>
11 *
12 * Some of this code is borrowed from orinoco_plx.c
13 * Copyright (C) 2001 Daniel Barlow <dan AT telent.net>
14 * Some of this code is "inspired" by linux-wlan-ng-0.1.10, but nothing
15 * has been copied from it. linux-wlan-ng-0.1.10 is originally :
16 * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved.
17 * This file originally written by:
18 * Copyright (C) 2001 Jean Tourrilhes <jt AT hpl.hp.com>
19 * And is now maintained by:
20 * (C) Copyright David Gibson, IBM Corp. 2002-2003.
21 *
22 * The contents of this file are subject to the Mozilla Public License
23 * Version 1.1 (the "License"); you may not use this file except in
24 * compliance with the License. You may obtain a copy of the License
25 * at http://www.mozilla.org/MPL/
26 *
27 * Software distributed under the License is distributed on an "AS IS"
28 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
29 * the License for the specific language governing rights and
30 * limitations under the License.
31 *
32 * Alternatively, the contents of this file may be used under the
33 * terms of the GNU General Public License version 2 (the "GPL"), in
34 * which case the provisions of the GPL are applicable instead of the
35 * above. If you wish to allow the use of your version of this file
36 * only under the terms of the GPL and not to allow others to use your
37 * version of this file under the MPL, indicate your decision by
38 * deleting the provisions above and replace them with the notice and
39 * other provisions required by the GPL. If you do not delete the
40 * provisions above, a recipient may use your version of this file
41 * under either the MPL or the GPL.
42 */
43
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#define DRIVER_NAME "orinoco_pci"
45#define PFX DRIVER_NAME ": "
46
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#include <linux/module.h>
48#include <linux/kernel.h>
49#include <linux/init.h>
Pavel Roskinef846bf2005-09-23 04:18:07 -040050#include <linux/delay.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#include <linux/pci.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Linus Torvalds1da177e2005-04-16 15:20:36 -070053#include "orinoco.h"
Pavel Roskinb884c872006-04-07 04:10:57 -040054#include "orinoco_pci.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
Pavel Roskindc3437d2006-04-07 04:11:00 -040056/* Offset of the COR register of the PCI card */
Linus Torvalds1da177e2005-04-16 15:20:36 -070057#define HERMES_PCI_COR (0x26)
Pavel Roskindc3437d2006-04-07 04:11:00 -040058
59/* Bitmask to reset the card */
Linus Torvalds1da177e2005-04-16 15:20:36 -070060#define HERMES_PCI_COR_MASK (0x0080)
Pavel Roskindc3437d2006-04-07 04:11:00 -040061
Linus Torvalds1da177e2005-04-16 15:20:36 -070062/* Magic timeouts for doing the reset.
63 * Those times are straight from wlan-ng, and it is claimed that they
64 * are necessary. Alan will kill me. Take your time and grab a coffee. */
65#define HERMES_PCI_COR_ONT (250) /* ms */
66#define HERMES_PCI_COR_OFFT (500) /* ms */
67#define HERMES_PCI_COR_BUSYT (500) /* ms */
68
Linus Torvalds1da177e2005-04-16 15:20:36 -070069/*
Pavel Roskindc3437d2006-04-07 04:11:00 -040070 * Do a soft reset of the card using the Configuration Option Register
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 * We need this to get going...
72 * This is the part of the code that is strongly inspired from wlan-ng
73 *
74 * Note : This code is done with irq enabled. This mean that many
75 * interrupts will occur while we are there. This is why we use the
76 * jiffies to regulate time instead of a straight mdelay(). Usually we
77 * need only around 245 iteration of the loop to do 250 ms delay.
78 *
79 * Note bis : Don't try to access HERMES_CMD during the reset phase.
80 * It just won't work !
81 */
Pavel Roskinb884c872006-04-07 04:10:57 -040082static int orinoco_pci_cor_reset(struct orinoco_private *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -070083{
84 hermes_t *hw = &priv->hw;
Pavel Roskinb884c872006-04-07 04:10:57 -040085 unsigned long timeout;
86 u16 reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
Pavel Roskindc3437d2006-04-07 04:11:00 -040088 /* Assert the reset until the card notices */
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 hermes_write_regn(hw, PCI_COR, HERMES_PCI_COR_MASK);
90 mdelay(HERMES_PCI_COR_ONT);
91
92 /* Give time for the card to recover from this hard effort */
93 hermes_write_regn(hw, PCI_COR, 0x0000);
94 mdelay(HERMES_PCI_COR_OFFT);
95
96 /* The card is ready when it's no longer busy */
97 timeout = jiffies + (HERMES_PCI_COR_BUSYT * HZ / 1000);
98 reg = hermes_read_regn(hw, CMD);
99 while (time_before(jiffies, timeout) && (reg & HERMES_CMD_BUSY)) {
100 mdelay(1);
101 reg = hermes_read_regn(hw, CMD);
102 }
103
104 /* Still busy? */
105 if (reg & HERMES_CMD_BUSY) {
106 printk(KERN_ERR PFX "Busy timeout\n");
107 return -ETIMEDOUT;
108 }
109
110 return 0;
111}
112
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113static int orinoco_pci_init_one(struct pci_dev *pdev,
114 const struct pci_device_id *ent)
115{
Pavel Roskinb884c872006-04-07 04:10:57 -0400116 int err;
117 struct orinoco_private *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 struct orinoco_pci_card *card;
Pavel Roskinb884c872006-04-07 04:10:57 -0400119 struct net_device *dev;
120 void __iomem *hermes_io;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
122 err = pci_enable_device(pdev);
123 if (err) {
124 printk(KERN_ERR PFX "Cannot enable PCI device\n");
125 return err;
126 }
127
128 err = pci_request_regions(pdev, DRIVER_NAME);
Pavel Roskinb884c872006-04-07 04:10:57 -0400129 if (err) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 printk(KERN_ERR PFX "Cannot obtain PCI resources\n");
131 goto fail_resources;
132 }
133
Pavel Roskinb884c872006-04-07 04:10:57 -0400134 hermes_io = pci_iomap(pdev, 0, 0);
135 if (!hermes_io) {
136 printk(KERN_ERR PFX "Cannot remap chipset registers\n");
Pavel Roskin3d529962006-04-07 04:10:53 -0400137 err = -EIO;
Pavel Roskinb884c872006-04-07 04:10:57 -0400138 goto fail_map_hermes;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 }
140
141 /* Allocate network device */
142 dev = alloc_orinocodev(sizeof(*card), orinoco_pci_cor_reset);
Pavel Roskinb884c872006-04-07 04:10:57 -0400143 if (!dev) {
144 printk(KERN_ERR PFX "Cannot allocate network device\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 err = -ENOMEM;
146 goto fail_alloc;
147 }
148
149 priv = netdev_priv(dev);
150 card = priv->card;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 SET_NETDEV_DEV(dev, &pdev->dev);
152
Pavel Roskinb884c872006-04-07 04:10:57 -0400153 hermes_struct_init(&priv->hw, hermes_io, HERMES_32BIT_REGSPACING);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
Thomas Gleixner1fb9df52006-07-01 19:29:39 -0700155 err = request_irq(pdev->irq, orinoco_interrupt, IRQF_SHARED,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 dev->name, dev);
157 if (err) {
158 printk(KERN_ERR PFX "Cannot allocate IRQ %d\n", pdev->irq);
159 err = -EBUSY;
160 goto fail_irq;
161 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 err = orinoco_pci_cor_reset(priv);
164 if (err) {
165 printk(KERN_ERR PFX "Initial reset failed\n");
166 goto fail;
167 }
168
169 err = register_netdev(dev);
170 if (err) {
Pavel Roskinb884c872006-04-07 04:10:57 -0400171 printk(KERN_ERR PFX "Cannot register network device\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 goto fail;
173 }
174
175 pci_set_drvdata(pdev, dev);
Pavel Roskin461c0782006-05-01 02:13:33 -0400176 printk(KERN_DEBUG "%s: " DRIVER_NAME " at %s\n", dev->name,
177 pci_name(pdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178
179 return 0;
180
181 fail:
182 free_irq(pdev->irq, dev);
183
184 fail_irq:
185 pci_set_drvdata(pdev, NULL);
186 free_orinocodev(dev);
187
188 fail_alloc:
Pavel Roskinb884c872006-04-07 04:10:57 -0400189 pci_iounmap(pdev, hermes_io);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190
Pavel Roskinb884c872006-04-07 04:10:57 -0400191 fail_map_hermes:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 pci_release_regions(pdev);
193
194 fail_resources:
195 pci_disable_device(pdev);
196
197 return err;
198}
199
200static void __devexit orinoco_pci_remove_one(struct pci_dev *pdev)
201{
202 struct net_device *dev = pci_get_drvdata(pdev);
203 struct orinoco_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204
205 unregister_netdev(dev);
Pavel Roskin461c0782006-05-01 02:13:33 -0400206 free_irq(pdev->irq, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 pci_set_drvdata(pdev, NULL);
208 free_orinocodev(dev);
Pavel Roskinb884c872006-04-07 04:10:57 -0400209 pci_iounmap(pdev, priv->hw.iobase);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 pci_release_regions(pdev);
211 pci_disable_device(pdev);
212}
213
Pavel Roskinb884c872006-04-07 04:10:57 -0400214static struct pci_device_id orinoco_pci_id_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 /* Intersil Prism 3 */
216 {0x1260, 0x3872, PCI_ANY_ID, PCI_ANY_ID,},
217 /* Intersil Prism 2.5 */
218 {0x1260, 0x3873, PCI_ANY_ID, PCI_ANY_ID,},
219 /* Samsung MagicLAN SWL-2210P */
220 {0x167d, 0xa000, PCI_ANY_ID, PCI_ANY_ID,},
221 {0,},
222};
223
Pavel Roskinb884c872006-04-07 04:10:57 -0400224MODULE_DEVICE_TABLE(pci, orinoco_pci_id_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225
226static struct pci_driver orinoco_pci_driver = {
227 .name = DRIVER_NAME,
Pavel Roskinb884c872006-04-07 04:10:57 -0400228 .id_table = orinoco_pci_id_table,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 .probe = orinoco_pci_init_one,
230 .remove = __devexit_p(orinoco_pci_remove_one),
231 .suspend = orinoco_pci_suspend,
232 .resume = orinoco_pci_resume,
233};
234
235static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
236 " (Pavel Roskin <proski@gnu.org>,"
237 " David Gibson <hermes@gibson.dropbear.id.au> &"
238 " Jean Tourrilhes <jt@hpl.hp.com>)";
239MODULE_AUTHOR("Pavel Roskin <proski@gnu.org> & David Gibson <hermes@gibson.dropbear.id.au>");
240MODULE_DESCRIPTION("Driver for wireless LAN cards using direct PCI interface");
241MODULE_LICENSE("Dual MPL/GPL");
242
243static int __init orinoco_pci_init(void)
244{
245 printk(KERN_DEBUG "%s\n", version);
Jeff Garzik29917622006-08-19 17:48:59 -0400246 return pci_register_driver(&orinoco_pci_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247}
248
249static void __exit orinoco_pci_exit(void)
250{
251 pci_unregister_driver(&orinoco_pci_driver);
252}
253
254module_init(orinoco_pci_init);
255module_exit(orinoco_pci_exit);
256
257/*
258 * Local variables:
259 * c-indent-level: 8
260 * c-basic-offset: 8
261 * tab-width: 8
262 * End:
263 */