]>
Commit | Line | Data |
---|---|---|
ec829051 | 1 | /* orinoco_nortel.c |
b884c872 | 2 | * |
ec829051 | 3 | * Driver for Prism II devices which would usually be driven by orinoco_cs, |
d4956572 PR |
4 | * but are connected to the PCI bus by a PCI-to-PCMCIA adapter used in |
5 | * Nortel emobility, Symbol LA-4113 and Symbol LA-4123. | |
ec829051 PR |
6 | * |
7 | * Copyright (C) 2002 Tobias Hoffmann | |
8 | * (C) 2003 Christoph Jungegger <disdos@traum404.de> | |
9 | * | |
10 | * Some of this code is borrowed from orinoco_plx.c | |
11 | * Copyright (C) 2001 Daniel Barlow | |
d14c7c1d | 12 | * Some of this code is borrowed from orinoco_pci.c |
ec829051 PR |
13 | * Copyright (C) 2001 Jean Tourrilhes |
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. | |
d14c7c1d | 17 | * |
ec829051 PR |
18 | * The contents of this file are subject to the Mozilla Public License |
19 | * Version 1.1 (the "License"); you may not use this file except in | |
20 | * compliance with the License. You may obtain a copy of the License | |
21 | * at http://www.mozilla.org/MPL/ | |
22 | * | |
23 | * Software distributed under the License is distributed on an "AS IS" | |
24 | * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See | |
25 | * the License for the specific language governing rights and | |
26 | * limitations under the License. | |
27 | * | |
28 | * Alternatively, the contents of this file may be used under the | |
29 | * terms of the GNU General Public License version 2 (the "GPL"), in | |
30 | * which case the provisions of the GPL are applicable instead of the | |
31 | * above. If you wish to allow the use of your version of this file | |
32 | * only under the terms of the GPL and not to allow others to use your | |
33 | * version of this file under the MPL, indicate your decision by | |
34 | * deleting the provisions above and replace them with the notice and | |
35 | * other provisions required by the GPL. If you do not delete the | |
36 | * provisions above, a recipient may use your version of this file | |
37 | * under either the MPL or the GPL. | |
38 | */ | |
39 | ||
40 | #define DRIVER_NAME "orinoco_nortel" | |
41 | #define PFX DRIVER_NAME ": " | |
42 | ||
ec829051 PR |
43 | #include <linux/module.h> |
44 | #include <linux/kernel.h> | |
45 | #include <linux/init.h> | |
ef846bf0 | 46 | #include <linux/delay.h> |
ec829051 | 47 | #include <linux/pci.h> |
ec829051 PR |
48 | #include <pcmcia/cisreg.h> |
49 | ||
ec829051 | 50 | #include "orinoco.h" |
b884c872 | 51 | #include "orinoco_pci.h" |
ec829051 PR |
52 | |
53 | #define COR_OFFSET (0xe0) /* COR attribute offset of Prism2 PC card */ | |
54 | #define COR_VALUE (COR_LEVEL_REQ | COR_FUNC_ENA) /* Enable PC card with interrupt in level trigger */ | |
55 | ||
56 | ||
ec829051 | 57 | /* |
dc3437d2 | 58 | * Do a soft reset of the card using the Configuration Option Register |
ec829051 PR |
59 | * We need this to get going... |
60 | * This is the part of the code that is strongly inspired from wlan-ng | |
61 | * | |
62 | * Note bis : Don't try to access HERMES_CMD during the reset phase. | |
63 | * It just won't work ! | |
64 | */ | |
b884c872 | 65 | static int orinoco_nortel_cor_reset(struct orinoco_private *priv) |
ec829051 | 66 | { |
b884c872 | 67 | struct orinoco_pci_card *card = priv->card; |
ec829051 | 68 | |
dc3437d2 | 69 | /* Assert the reset until the card notices */ |
b884c872 PR |
70 | iowrite16(8, card->bridge_io + 2); |
71 | ioread16(card->attr_io + COR_OFFSET); | |
72 | iowrite16(0x80, card->attr_io + COR_OFFSET); | |
ec829051 PR |
73 | mdelay(1); |
74 | ||
75 | /* Give time for the card to recover from this hard effort */ | |
b884c872 PR |
76 | iowrite16(0, card->attr_io + COR_OFFSET); |
77 | iowrite16(0, card->attr_io + COR_OFFSET); | |
ec829051 PR |
78 | mdelay(1); |
79 | ||
b884c872 PR |
80 | /* Set COR as usual */ |
81 | iowrite16(COR_VALUE, card->attr_io + COR_OFFSET); | |
82 | iowrite16(COR_VALUE, card->attr_io + COR_OFFSET); | |
ec829051 PR |
83 | mdelay(1); |
84 | ||
b884c872 | 85 | iowrite16(0x228, card->bridge_io + 2); |
ec829051 PR |
86 | |
87 | return 0; | |
88 | } | |
89 | ||
b884c872 | 90 | static int orinoco_nortel_hw_init(struct orinoco_pci_card *card) |
ec829051 PR |
91 | { |
92 | int i; | |
93 | u32 reg; | |
94 | ||
b884c872 PR |
95 | /* Setup bridge */ |
96 | if (ioread16(card->bridge_io) & 1) { | |
ec829051 PR |
97 | printk(KERN_ERR PFX "brg1 answer1 wrong\n"); |
98 | return -EBUSY; | |
99 | } | |
b884c872 PR |
100 | iowrite16(0x118, card->bridge_io + 2); |
101 | iowrite16(0x108, card->bridge_io + 2); | |
ec829051 | 102 | mdelay(30); |
b884c872 | 103 | iowrite16(0x8, card->bridge_io + 2); |
ec829051 PR |
104 | for (i = 0; i < 30; i++) { |
105 | mdelay(30); | |
d14c7c1d | 106 | if (ioread16(card->bridge_io) & 0x10) |
ec829051 | 107 | break; |
ec829051 PR |
108 | } |
109 | if (i == 30) { | |
110 | printk(KERN_ERR PFX "brg1 timed out\n"); | |
111 | return -EBUSY; | |
112 | } | |
b884c872 | 113 | if (ioread16(card->attr_io + COR_OFFSET) & 1) { |
ec829051 PR |
114 | printk(KERN_ERR PFX "brg2 answer1 wrong\n"); |
115 | return -EBUSY; | |
116 | } | |
b884c872 | 117 | if (ioread16(card->attr_io + COR_OFFSET + 2) & 1) { |
ec829051 PR |
118 | printk(KERN_ERR PFX "brg2 answer2 wrong\n"); |
119 | return -EBUSY; | |
120 | } | |
b884c872 | 121 | if (ioread16(card->attr_io + COR_OFFSET + 4) & 1) { |
ec829051 PR |
122 | printk(KERN_ERR PFX "brg2 answer3 wrong\n"); |
123 | return -EBUSY; | |
124 | } | |
125 | ||
dc3437d2 | 126 | /* Set the PCMCIA COR register */ |
b884c872 | 127 | iowrite16(COR_VALUE, card->attr_io + COR_OFFSET); |
ec829051 | 128 | mdelay(1); |
b884c872 | 129 | reg = ioread16(card->attr_io + COR_OFFSET); |
ec829051 PR |
130 | if (reg != COR_VALUE) { |
131 | printk(KERN_ERR PFX "Error setting COR value (reg=%x)\n", | |
132 | reg); | |
133 | return -EBUSY; | |
134 | } | |
135 | ||
b884c872 PR |
136 | /* Set LEDs */ |
137 | iowrite16(1, card->bridge_io + 10); | |
ec829051 PR |
138 | return 0; |
139 | } | |
140 | ||
b884c872 PR |
141 | static int orinoco_nortel_init_one(struct pci_dev *pdev, |
142 | const struct pci_device_id *ent) | |
ec829051 PR |
143 | { |
144 | int err; | |
145 | struct orinoco_private *priv; | |
b884c872 | 146 | struct orinoco_pci_card *card; |
b884c872 | 147 | void __iomem *hermes_io, *bridge_io, *attr_io; |
ec829051 PR |
148 | |
149 | err = pci_enable_device(pdev); | |
150 | if (err) { | |
151 | printk(KERN_ERR PFX "Cannot enable PCI device\n"); | |
152 | return err; | |
153 | } | |
154 | ||
155 | err = pci_request_regions(pdev, DRIVER_NAME); | |
b884c872 | 156 | if (err) { |
ec829051 PR |
157 | printk(KERN_ERR PFX "Cannot obtain PCI resources\n"); |
158 | goto fail_resources; | |
159 | } | |
160 | ||
b884c872 PR |
161 | bridge_io = pci_iomap(pdev, 0, 0); |
162 | if (!bridge_io) { | |
163 | printk(KERN_ERR PFX "Cannot map bridge registers\n"); | |
164 | err = -EIO; | |
165 | goto fail_map_bridge; | |
166 | } | |
167 | ||
168 | attr_io = pci_iomap(pdev, 1, 0); | |
169 | if (!attr_io) { | |
170 | printk(KERN_ERR PFX "Cannot map PCMCIA attributes\n"); | |
171 | err = -EIO; | |
172 | goto fail_map_attr; | |
173 | } | |
174 | ||
175 | hermes_io = pci_iomap(pdev, 2, 0); | |
176 | if (!hermes_io) { | |
177 | printk(KERN_ERR PFX "Cannot map chipset registers\n"); | |
178 | err = -EIO; | |
179 | goto fail_map_hermes; | |
ec829051 PR |
180 | } |
181 | ||
182 | /* Allocate network device */ | |
a2608362 DK |
183 | priv = alloc_orinocodev(sizeof(*card), &pdev->dev, |
184 | orinoco_nortel_cor_reset, NULL); | |
185 | if (!priv) { | |
ec829051 PR |
186 | printk(KERN_ERR PFX "Cannot allocate network device\n"); |
187 | err = -ENOMEM; | |
188 | goto fail_alloc; | |
189 | } | |
190 | ||
ec829051 | 191 | card = priv->card; |
b884c872 PR |
192 | card->bridge_io = bridge_io; |
193 | card->attr_io = attr_io; | |
ec829051 | 194 | |
b884c872 | 195 | hermes_struct_init(&priv->hw, hermes_io, HERMES_16BIT_REGSPACING); |
ec829051 | 196 | |
1fb9df5d | 197 | err = request_irq(pdev->irq, orinoco_interrupt, IRQF_SHARED, |
5381956b | 198 | DRIVER_NAME, priv); |
ec829051 PR |
199 | if (err) { |
200 | printk(KERN_ERR PFX "Cannot allocate IRQ %d\n", pdev->irq); | |
201 | err = -EBUSY; | |
202 | goto fail_irq; | |
203 | } | |
ec829051 | 204 | |
b884c872 | 205 | err = orinoco_nortel_hw_init(card); |
ec829051 PR |
206 | if (err) { |
207 | printk(KERN_ERR PFX "Hardware initialization failed\n"); | |
208 | goto fail; | |
209 | } | |
210 | ||
b884c872 | 211 | err = orinoco_nortel_cor_reset(priv); |
ec829051 PR |
212 | if (err) { |
213 | printk(KERN_ERR PFX "Initial reset failed\n"); | |
214 | goto fail; | |
215 | } | |
216 | ||
8e638267 DK |
217 | err = orinoco_init(priv); |
218 | if (err) { | |
219 | printk(KERN_ERR PFX "orinoco_init() failed\n"); | |
220 | goto fail; | |
221 | } | |
222 | ||
5381956b | 223 | err = orinoco_if_add(priv, 0, 0); |
ec829051 | 224 | if (err) { |
5381956b | 225 | printk(KERN_ERR PFX "orinoco_if_add() failed\n"); |
ec829051 PR |
226 | goto fail; |
227 | } | |
228 | ||
a2608362 | 229 | pci_set_drvdata(pdev, priv); |
ec829051 PR |
230 | |
231 | return 0; | |
232 | ||
233 | fail: | |
a2608362 | 234 | free_irq(pdev->irq, priv); |
ec829051 PR |
235 | |
236 | fail_irq: | |
237 | pci_set_drvdata(pdev, NULL); | |
a2608362 | 238 | free_orinocodev(priv); |
ec829051 PR |
239 | |
240 | fail_alloc: | |
b884c872 PR |
241 | pci_iounmap(pdev, hermes_io); |
242 | ||
243 | fail_map_hermes: | |
244 | pci_iounmap(pdev, attr_io); | |
245 | ||
246 | fail_map_attr: | |
247 | pci_iounmap(pdev, bridge_io); | |
ec829051 | 248 | |
b884c872 | 249 | fail_map_bridge: |
ec829051 PR |
250 | pci_release_regions(pdev); |
251 | ||
252 | fail_resources: | |
253 | pci_disable_device(pdev); | |
254 | ||
255 | return err; | |
256 | } | |
257 | ||
b884c872 | 258 | static void __devexit orinoco_nortel_remove_one(struct pci_dev *pdev) |
ec829051 | 259 | { |
a2608362 | 260 | struct orinoco_private *priv = pci_get_drvdata(pdev); |
b884c872 | 261 | struct orinoco_pci_card *card = priv->card; |
ec829051 | 262 | |
b884c872 PR |
263 | /* Clear LEDs */ |
264 | iowrite16(0, card->bridge_io + 10); | |
ec829051 | 265 | |
5381956b | 266 | orinoco_if_del(priv); |
a2608362 | 267 | free_irq(pdev->irq, priv); |
ec829051 | 268 | pci_set_drvdata(pdev, NULL); |
a2608362 | 269 | free_orinocodev(priv); |
ec829051 | 270 | pci_iounmap(pdev, priv->hw.iobase); |
b884c872 PR |
271 | pci_iounmap(pdev, card->attr_io); |
272 | pci_iounmap(pdev, card->bridge_io); | |
ec829051 PR |
273 | pci_release_regions(pdev); |
274 | pci_disable_device(pdev); | |
275 | } | |
276 | ||
a3aa1884 | 277 | static DEFINE_PCI_DEVICE_TABLE(orinoco_nortel_id_table) = { |
ec829051 PR |
278 | /* Nortel emobility PCI */ |
279 | {0x126c, 0x8030, PCI_ANY_ID, PCI_ANY_ID,}, | |
d4956572 PR |
280 | /* Symbol LA-4123 PCI */ |
281 | {0x1562, 0x0001, PCI_ANY_ID, PCI_ANY_ID,}, | |
ec829051 PR |
282 | {0,}, |
283 | }; | |
284 | ||
b884c872 | 285 | MODULE_DEVICE_TABLE(pci, orinoco_nortel_id_table); |
ec829051 | 286 | |
b884c872 | 287 | static struct pci_driver orinoco_nortel_driver = { |
c6fb2e9a | 288 | .name = DRIVER_NAME, |
b884c872 PR |
289 | .id_table = orinoco_nortel_id_table, |
290 | .probe = orinoco_nortel_init_one, | |
291 | .remove = __devexit_p(orinoco_nortel_remove_one), | |
292 | .suspend = orinoco_pci_suspend, | |
293 | .resume = orinoco_pci_resume, | |
ec829051 PR |
294 | }; |
295 | ||
296 | static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION | |
297 | " (Tobias Hoffmann & Christoph Jungegger <disdos@traum404.de>)"; | |
298 | MODULE_AUTHOR("Christoph Jungegger <disdos@traum404.de>"); | |
299 | MODULE_DESCRIPTION | |
300 | ("Driver for wireless LAN cards using the Nortel PCI bridge"); | |
301 | MODULE_LICENSE("Dual MPL/GPL"); | |
302 | ||
b884c872 | 303 | static int __init orinoco_nortel_init(void) |
ec829051 PR |
304 | { |
305 | printk(KERN_DEBUG "%s\n", version); | |
29917620 | 306 | return pci_register_driver(&orinoco_nortel_driver); |
ec829051 PR |
307 | } |
308 | ||
b884c872 | 309 | static void __exit orinoco_nortel_exit(void) |
ec829051 | 310 | { |
b884c872 | 311 | pci_unregister_driver(&orinoco_nortel_driver); |
ec829051 PR |
312 | } |
313 | ||
b884c872 PR |
314 | module_init(orinoco_nortel_init); |
315 | module_exit(orinoco_nortel_exit); | |
ec829051 PR |
316 | |
317 | /* | |
318 | * Local variables: | |
319 | * c-indent-level: 8 | |
320 | * c-basic-offset: 8 | |
321 | * tab-width: 8 | |
322 | * End: | |
323 | */ |