drivers/net/: use DEFINE_PCI_DEVICE_TABLE()
[deliverable/linux.git] / drivers / net / wireless / orinoco / orinoco_pci.c
CommitLineData
1da177e4 1/* orinoco_pci.c
d14c7c1d 2 *
dc3437d2
PR
3 * 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.
1da177e4 7 *
dc3437d2 8 * Current maintainers are:
1da177e4
LT
9 * 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
1da177e4
LT
44#define DRIVER_NAME "orinoco_pci"
45#define PFX DRIVER_NAME ": "
46
1da177e4
LT
47#include <linux/module.h>
48#include <linux/kernel.h>
49#include <linux/init.h>
ef846bf0 50#include <linux/delay.h>
1da177e4 51#include <linux/pci.h>
1da177e4 52
1da177e4 53#include "orinoco.h"
b884c872 54#include "orinoco_pci.h"
1da177e4 55
dc3437d2 56/* Offset of the COR register of the PCI card */
1da177e4 57#define HERMES_PCI_COR (0x26)
dc3437d2
PR
58
59/* Bitmask to reset the card */
1da177e4 60#define HERMES_PCI_COR_MASK (0x0080)
dc3437d2 61
1da177e4
LT
62/* 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
1da177e4 69/*
dc3437d2 70 * Do a soft reset of the card using the Configuration Option Register
1da177e4
LT
71 * 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 */
b884c872 82static int orinoco_pci_cor_reset(struct orinoco_private *priv)
1da177e4
LT
83{
84 hermes_t *hw = &priv->hw;
b884c872
PR
85 unsigned long timeout;
86 u16 reg;
1da177e4 87
dc3437d2 88 /* Assert the reset until the card notices */
1da177e4
LT
89 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
1da177e4
LT
113static int orinoco_pci_init_one(struct pci_dev *pdev,
114 const struct pci_device_id *ent)
115{
b884c872
PR
116 int err;
117 struct orinoco_private *priv;
1da177e4 118 struct orinoco_pci_card *card;
b884c872 119 void __iomem *hermes_io;
1da177e4
LT
120
121 err = pci_enable_device(pdev);
122 if (err) {
123 printk(KERN_ERR PFX "Cannot enable PCI device\n");
124 return err;
125 }
126
127 err = pci_request_regions(pdev, DRIVER_NAME);
b884c872 128 if (err) {
1da177e4
LT
129 printk(KERN_ERR PFX "Cannot obtain PCI resources\n");
130 goto fail_resources;
131 }
132
b884c872
PR
133 hermes_io = pci_iomap(pdev, 0, 0);
134 if (!hermes_io) {
135 printk(KERN_ERR PFX "Cannot remap chipset registers\n");
3d529962 136 err = -EIO;
b884c872 137 goto fail_map_hermes;
1da177e4
LT
138 }
139
140 /* Allocate network device */
a2608362
DK
141 priv = alloc_orinocodev(sizeof(*card), &pdev->dev,
142 orinoco_pci_cor_reset, NULL);
143 if (!priv) {
b884c872 144 printk(KERN_ERR PFX "Cannot allocate network device\n");
1da177e4
LT
145 err = -ENOMEM;
146 goto fail_alloc;
147 }
148
1da177e4 149 card = priv->card;
1da177e4 150
b884c872 151 hermes_struct_init(&priv->hw, hermes_io, HERMES_32BIT_REGSPACING);
1da177e4 152
1fb9df5d 153 err = request_irq(pdev->irq, orinoco_interrupt, IRQF_SHARED,
5381956b 154 DRIVER_NAME, priv);
1da177e4
LT
155 if (err) {
156 printk(KERN_ERR PFX "Cannot allocate IRQ %d\n", pdev->irq);
157 err = -EBUSY;
158 goto fail_irq;
159 }
1da177e4 160
1da177e4
LT
161 err = orinoco_pci_cor_reset(priv);
162 if (err) {
163 printk(KERN_ERR PFX "Initial reset failed\n");
164 goto fail;
165 }
166
8e638267
DK
167 err = orinoco_init(priv);
168 if (err) {
169 printk(KERN_ERR PFX "orinoco_init() failed\n");
170 goto fail;
171 }
172
5381956b 173 err = orinoco_if_add(priv, 0, 0);
1da177e4 174 if (err) {
5381956b 175 printk(KERN_ERR PFX "orinoco_if_add() failed\n");
1da177e4
LT
176 goto fail;
177 }
178
a2608362 179 pci_set_drvdata(pdev, priv);
1da177e4
LT
180
181 return 0;
182
183 fail:
a2608362 184 free_irq(pdev->irq, priv);
1da177e4
LT
185
186 fail_irq:
187 pci_set_drvdata(pdev, NULL);
a2608362 188 free_orinocodev(priv);
1da177e4
LT
189
190 fail_alloc:
b884c872 191 pci_iounmap(pdev, hermes_io);
1da177e4 192
b884c872 193 fail_map_hermes:
1da177e4
LT
194 pci_release_regions(pdev);
195
196 fail_resources:
197 pci_disable_device(pdev);
198
199 return err;
200}
201
202static void __devexit orinoco_pci_remove_one(struct pci_dev *pdev)
203{
a2608362 204 struct orinoco_private *priv = pci_get_drvdata(pdev);
1da177e4 205
5381956b 206 orinoco_if_del(priv);
a2608362 207 free_irq(pdev->irq, priv);
1da177e4 208 pci_set_drvdata(pdev, NULL);
a2608362 209 free_orinocodev(priv);
b884c872 210 pci_iounmap(pdev, priv->hw.iobase);
1da177e4
LT
211 pci_release_regions(pdev);
212 pci_disable_device(pdev);
213}
214
a3aa1884 215static DEFINE_PCI_DEVICE_TABLE(orinoco_pci_id_table) = {
1da177e4
LT
216 /* Intersil Prism 3 */
217 {0x1260, 0x3872, PCI_ANY_ID, PCI_ANY_ID,},
218 /* Intersil Prism 2.5 */
219 {0x1260, 0x3873, PCI_ANY_ID, PCI_ANY_ID,},
220 /* Samsung MagicLAN SWL-2210P */
221 {0x167d, 0xa000, PCI_ANY_ID, PCI_ANY_ID,},
222 {0,},
223};
224
b884c872 225MODULE_DEVICE_TABLE(pci, orinoco_pci_id_table);
1da177e4
LT
226
227static struct pci_driver orinoco_pci_driver = {
228 .name = DRIVER_NAME,
b884c872 229 .id_table = orinoco_pci_id_table,
1da177e4
LT
230 .probe = orinoco_pci_init_one,
231 .remove = __devexit_p(orinoco_pci_remove_one),
232 .suspend = orinoco_pci_suspend,
233 .resume = orinoco_pci_resume,
234};
235
236static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
237 " (Pavel Roskin <proski@gnu.org>,"
238 " David Gibson <hermes@gibson.dropbear.id.au> &"
239 " Jean Tourrilhes <jt@hpl.hp.com>)";
d14c7c1d
AB
240MODULE_AUTHOR("Pavel Roskin <proski@gnu.org> &"
241 " David Gibson <hermes@gibson.dropbear.id.au>");
1da177e4
LT
242MODULE_DESCRIPTION("Driver for wireless LAN cards using direct PCI interface");
243MODULE_LICENSE("Dual MPL/GPL");
244
245static int __init orinoco_pci_init(void)
246{
247 printk(KERN_DEBUG "%s\n", version);
29917620 248 return pci_register_driver(&orinoco_pci_driver);
1da177e4
LT
249}
250
251static void __exit orinoco_pci_exit(void)
252{
253 pci_unregister_driver(&orinoco_pci_driver);
254}
255
256module_init(orinoco_pci_init);
257module_exit(orinoco_pci_exit);
258
259/*
260 * Local variables:
261 * c-indent-level: 8
262 * c-basic-offset: 8
263 * tab-width: 8
264 * End:
265 */
This page took 0.590151 seconds and 5 git commands to generate.