Commit | Line | Data |
---|---|---|
ec829051 PR |
1 | /* orinoco_nortel.c |
2 | * | |
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 | * but are connected to the PCI bus by a Nortel PCI-PCMCIA-Adapter. |
7 | * | |
8 | * Copyright (C) 2002 Tobias Hoffmann | |
9 | * (C) 2003 Christoph Jungegger <disdos@traum404.de> | |
10 | * | |
11 | * Some of this code is borrowed from orinoco_plx.c | |
12 | * Copyright (C) 2001 Daniel Barlow | |
13 | * Some of this code is borrowed from orinoco_pci.c | |
14 | * Copyright (C) 2001 Jean Tourrilhes | |
15 | * Some of this code is "inspired" by linux-wlan-ng-0.1.10, but nothing | |
16 | * has been copied from it. linux-wlan-ng-0.1.10 is originally : | |
17 | * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved. | |
18 | * | |
19 | * The contents of this file are subject to the Mozilla Public License | |
20 | * Version 1.1 (the "License"); you may not use this file except in | |
21 | * compliance with the License. You may obtain a copy of the License | |
22 | * at http://www.mozilla.org/MPL/ | |
23 | * | |
24 | * Software distributed under the License is distributed on an "AS IS" | |
25 | * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See | |
26 | * the License for the specific language governing rights and | |
27 | * limitations under the License. | |
28 | * | |
29 | * Alternatively, the contents of this file may be used under the | |
30 | * terms of the GNU General Public License version 2 (the "GPL"), in | |
31 | * which case the provisions of the GPL are applicable instead of the | |
32 | * above. If you wish to allow the use of your version of this file | |
33 | * only under the terms of the GPL and not to allow others to use your | |
34 | * version of this file under the MPL, indicate your decision by | |
35 | * deleting the provisions above and replace them with the notice and | |
36 | * other provisions required by the GPL. If you do not delete the | |
37 | * provisions above, a recipient may use your version of this file | |
38 | * under either the MPL or the GPL. | |
39 | */ | |
40 | ||
41 | #define DRIVER_NAME "orinoco_nortel" | |
42 | #define PFX DRIVER_NAME ": " | |
43 | ||
44 | #include <linux/config.h> | |
ec829051 PR |
45 | #include <linux/module.h> |
46 | #include <linux/kernel.h> | |
47 | #include <linux/init.h> | |
ef846bf0 | 48 | #include <linux/delay.h> |
ec829051 | 49 | #include <linux/pci.h> |
ec829051 PR |
50 | #include <pcmcia/cisreg.h> |
51 | ||
ec829051 PR |
52 | #include "orinoco.h" |
53 | ||
54 | #define COR_OFFSET (0xe0) /* COR attribute offset of Prism2 PC card */ | |
55 | #define COR_VALUE (COR_LEVEL_REQ | COR_FUNC_ENA) /* Enable PC card with interrupt in level trigger */ | |
56 | ||
57 | ||
58 | /* Nortel specific data */ | |
59 | struct nortel_pci_card { | |
60 | unsigned long iobase1; | |
61 | unsigned long iobase2; | |
62 | }; | |
63 | ||
64 | /* | |
65 | * Do a soft reset of the PCI card using the Configuration Option Register | |
66 | * We need this to get going... | |
67 | * This is the part of the code that is strongly inspired from wlan-ng | |
68 | * | |
69 | * Note bis : Don't try to access HERMES_CMD during the reset phase. | |
70 | * It just won't work ! | |
71 | */ | |
72 | static int nortel_pci_cor_reset(struct orinoco_private *priv) | |
73 | { | |
74 | struct nortel_pci_card *card = priv->card; | |
75 | ||
76 | /* Assert the reset until the card notice */ | |
77 | outw_p(8, card->iobase1 + 2); | |
78 | inw(card->iobase2 + COR_OFFSET); | |
79 | outw_p(0x80, card->iobase2 + COR_OFFSET); | |
80 | mdelay(1); | |
81 | ||
82 | /* Give time for the card to recover from this hard effort */ | |
83 | outw_p(0, card->iobase2 + COR_OFFSET); | |
84 | outw_p(0, card->iobase2 + COR_OFFSET); | |
85 | mdelay(1); | |
86 | ||
87 | /* set COR as usual */ | |
88 | outw_p(COR_VALUE, card->iobase2 + COR_OFFSET); | |
89 | outw_p(COR_VALUE, card->iobase2 + COR_OFFSET); | |
90 | mdelay(1); | |
91 | ||
92 | outw_p(0x228, card->iobase1 + 2); | |
93 | ||
94 | return 0; | |
95 | } | |
96 | ||
4c082025 | 97 | static int nortel_pci_hw_init(struct nortel_pci_card *card) |
ec829051 PR |
98 | { |
99 | int i; | |
100 | u32 reg; | |
101 | ||
102 | /* setup bridge */ | |
103 | if (inw(card->iobase1) & 1) { | |
104 | printk(KERN_ERR PFX "brg1 answer1 wrong\n"); | |
105 | return -EBUSY; | |
106 | } | |
107 | outw_p(0x118, card->iobase1 + 2); | |
108 | outw_p(0x108, card->iobase1 + 2); | |
109 | mdelay(30); | |
110 | outw_p(0x8, card->iobase1 + 2); | |
111 | for (i = 0; i < 30; i++) { | |
112 | mdelay(30); | |
113 | if (inw(card->iobase1) & 0x10) { | |
114 | break; | |
115 | } | |
116 | } | |
117 | if (i == 30) { | |
118 | printk(KERN_ERR PFX "brg1 timed out\n"); | |
119 | return -EBUSY; | |
120 | } | |
121 | if (inw(card->iobase2 + 0xe0) & 1) { | |
122 | printk(KERN_ERR PFX "brg2 answer1 wrong\n"); | |
123 | return -EBUSY; | |
124 | } | |
125 | if (inw(card->iobase2 + 0xe2) & 1) { | |
126 | printk(KERN_ERR PFX "brg2 answer2 wrong\n"); | |
127 | return -EBUSY; | |
128 | } | |
129 | if (inw(card->iobase2 + 0xe4) & 1) { | |
130 | printk(KERN_ERR PFX "brg2 answer3 wrong\n"); | |
131 | return -EBUSY; | |
132 | } | |
133 | ||
134 | /* set the PCMCIA COR-Register */ | |
135 | outw_p(COR_VALUE, card->iobase2 + COR_OFFSET); | |
136 | mdelay(1); | |
137 | reg = inw(card->iobase2 + COR_OFFSET); | |
138 | if (reg != COR_VALUE) { | |
139 | printk(KERN_ERR PFX "Error setting COR value (reg=%x)\n", | |
140 | reg); | |
141 | return -EBUSY; | |
142 | } | |
143 | ||
144 | /* set leds */ | |
145 | outw_p(1, card->iobase1 + 10); | |
146 | return 0; | |
147 | } | |
148 | ||
149 | static int nortel_pci_init_one(struct pci_dev *pdev, | |
150 | const struct pci_device_id *ent) | |
151 | { | |
152 | int err; | |
153 | struct orinoco_private *priv; | |
154 | struct nortel_pci_card *card; | |
155 | struct net_device *dev; | |
156 | void __iomem *iomem; | |
157 | ||
158 | err = pci_enable_device(pdev); | |
159 | if (err) { | |
160 | printk(KERN_ERR PFX "Cannot enable PCI device\n"); | |
161 | return err; | |
162 | } | |
163 | ||
164 | err = pci_request_regions(pdev, DRIVER_NAME); | |
165 | if (err != 0) { | |
166 | printk(KERN_ERR PFX "Cannot obtain PCI resources\n"); | |
167 | goto fail_resources; | |
168 | } | |
169 | ||
c8cb00f6 | 170 | iomem = pci_iomap(pdev, 2, 0); |
ec829051 PR |
171 | if (!iomem) { |
172 | err = -ENOMEM; | |
173 | goto fail_map_io; | |
174 | } | |
175 | ||
176 | /* Allocate network device */ | |
177 | dev = alloc_orinocodev(sizeof(*card), nortel_pci_cor_reset); | |
178 | if (!dev) { | |
179 | printk(KERN_ERR PFX "Cannot allocate network device\n"); | |
180 | err = -ENOMEM; | |
181 | goto fail_alloc; | |
182 | } | |
183 | ||
184 | priv = netdev_priv(dev); | |
185 | card = priv->card; | |
186 | card->iobase1 = pci_resource_start(pdev, 0); | |
187 | card->iobase2 = pci_resource_start(pdev, 1); | |
188 | dev->base_addr = pci_resource_start(pdev, 2); | |
189 | SET_MODULE_OWNER(dev); | |
190 | SET_NETDEV_DEV(dev, &pdev->dev); | |
191 | ||
192 | hermes_struct_init(&priv->hw, iomem, HERMES_16BIT_REGSPACING); | |
193 | ||
194 | printk(KERN_DEBUG PFX "Detected Nortel PCI device at %s irq:%d, " | |
195 | "io addr:0x%lx\n", pci_name(pdev), pdev->irq, dev->base_addr); | |
196 | ||
197 | err = request_irq(pdev->irq, orinoco_interrupt, SA_SHIRQ, | |
198 | dev->name, dev); | |
199 | if (err) { | |
200 | printk(KERN_ERR PFX "Cannot allocate IRQ %d\n", pdev->irq); | |
201 | err = -EBUSY; | |
202 | goto fail_irq; | |
203 | } | |
204 | dev->irq = pdev->irq; | |
205 | ||
206 | err = nortel_pci_hw_init(card); | |
207 | if (err) { | |
208 | printk(KERN_ERR PFX "Hardware initialization failed\n"); | |
209 | goto fail; | |
210 | } | |
211 | ||
212 | err = nortel_pci_cor_reset(priv); | |
213 | if (err) { | |
214 | printk(KERN_ERR PFX "Initial reset failed\n"); | |
215 | goto fail; | |
216 | } | |
217 | ||
218 | ||
219 | err = register_netdev(dev); | |
220 | if (err) { | |
221 | printk(KERN_ERR PFX "Cannot register network device\n"); | |
222 | goto fail; | |
223 | } | |
224 | ||
225 | pci_set_drvdata(pdev, dev); | |
226 | ||
227 | return 0; | |
228 | ||
229 | fail: | |
230 | free_irq(pdev->irq, dev); | |
231 | ||
232 | fail_irq: | |
233 | pci_set_drvdata(pdev, NULL); | |
234 | free_orinocodev(dev); | |
235 | ||
236 | fail_alloc: | |
237 | pci_iounmap(pdev, iomem); | |
238 | ||
239 | fail_map_io: | |
240 | pci_release_regions(pdev); | |
241 | ||
242 | fail_resources: | |
243 | pci_disable_device(pdev); | |
244 | ||
245 | return err; | |
246 | } | |
247 | ||
248 | static void __devexit nortel_pci_remove_one(struct pci_dev *pdev) | |
249 | { | |
250 | struct net_device *dev = pci_get_drvdata(pdev); | |
251 | struct orinoco_private *priv = netdev_priv(dev); | |
252 | struct nortel_pci_card *card = priv->card; | |
253 | ||
254 | /* clear leds */ | |
255 | outw_p(0, card->iobase1 + 10); | |
256 | ||
257 | unregister_netdev(dev); | |
258 | free_irq(dev->irq, dev); | |
259 | pci_set_drvdata(pdev, NULL); | |
260 | free_orinocodev(dev); | |
261 | pci_iounmap(pdev, priv->hw.iobase); | |
262 | pci_release_regions(pdev); | |
263 | pci_disable_device(pdev); | |
264 | } | |
265 | ||
c6fb2e9a PR |
266 | static int orinoco_nortel_suspend(struct pci_dev *pdev, pm_message_t state) |
267 | { | |
268 | struct net_device *dev = pci_get_drvdata(pdev); | |
269 | struct orinoco_private *priv = netdev_priv(dev); | |
270 | unsigned long flags; | |
271 | int err; | |
272 | ||
273 | err = orinoco_lock(priv, &flags); | |
274 | if (err) { | |
275 | printk(KERN_ERR "%s: cannot lock hardware for suspend\n", | |
276 | dev->name); | |
277 | return err; | |
278 | } | |
279 | ||
280 | err = __orinoco_down(dev); | |
281 | if (err) | |
282 | printk(KERN_WARNING "%s: error %d bringing interface down " | |
283 | "for suspend\n", dev->name, err); | |
284 | ||
285 | netif_device_detach(dev); | |
286 | ||
287 | priv->hw_unavailable++; | |
288 | ||
289 | orinoco_unlock(priv, &flags); | |
290 | ||
291 | free_irq(pdev->irq, dev); | |
292 | pci_save_state(pdev); | |
293 | pci_disable_device(pdev); | |
294 | pci_set_power_state(pdev, PCI_D3hot); | |
295 | ||
296 | return 0; | |
297 | } | |
298 | ||
299 | static int orinoco_nortel_resume(struct pci_dev *pdev) | |
300 | { | |
301 | struct net_device *dev = pci_get_drvdata(pdev); | |
302 | struct orinoco_private *priv = netdev_priv(dev); | |
303 | unsigned long flags; | |
304 | int err; | |
305 | ||
306 | pci_set_power_state(pdev, 0); | |
307 | pci_enable_device(pdev); | |
308 | pci_restore_state(pdev); | |
309 | ||
310 | err = request_irq(pdev->irq, orinoco_interrupt, SA_SHIRQ, | |
311 | dev->name, dev); | |
312 | if (err) { | |
313 | printk(KERN_ERR "%s: cannot re-allocate IRQ on resume\n", | |
314 | dev->name); | |
315 | pci_disable_device(pdev); | |
316 | return -EBUSY; | |
317 | } | |
318 | ||
319 | err = orinoco_reinit_firmware(dev); | |
320 | if (err) { | |
321 | printk(KERN_ERR "%s: error %d re-initializing firmware " | |
322 | "on resume\n", dev->name, err); | |
323 | return err; | |
324 | } | |
325 | ||
326 | spin_lock_irqsave(&priv->lock, flags); | |
327 | ||
328 | netif_device_attach(dev); | |
329 | ||
330 | priv->hw_unavailable--; | |
331 | ||
332 | if (priv->open && (! priv->hw_unavailable)) { | |
333 | err = __orinoco_up(dev); | |
334 | if (err) | |
335 | printk(KERN_ERR "%s: Error %d restarting card on resume\n", | |
336 | dev->name, err); | |
337 | } | |
338 | ||
339 | spin_unlock_irqrestore(&priv->lock, flags); | |
340 | ||
341 | return 0; | |
342 | } | |
ec829051 PR |
343 | |
344 | static struct pci_device_id nortel_pci_id_table[] = { | |
345 | /* Nortel emobility PCI */ | |
346 | {0x126c, 0x8030, PCI_ANY_ID, PCI_ANY_ID,}, | |
d4956572 PR |
347 | /* Symbol LA-4123 PCI */ |
348 | {0x1562, 0x0001, PCI_ANY_ID, PCI_ANY_ID,}, | |
ec829051 PR |
349 | {0,}, |
350 | }; | |
351 | ||
352 | MODULE_DEVICE_TABLE(pci, nortel_pci_id_table); | |
353 | ||
354 | static struct pci_driver nortel_pci_driver = { | |
c6fb2e9a PR |
355 | .name = DRIVER_NAME, |
356 | .id_table = nortel_pci_id_table, | |
357 | .probe = nortel_pci_init_one, | |
358 | .remove = __devexit_p(nortel_pci_remove_one), | |
359 | .suspend = orinoco_nortel_suspend, | |
360 | .resume = orinoco_nortel_resume, | |
ec829051 PR |
361 | }; |
362 | ||
363 | static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION | |
364 | " (Tobias Hoffmann & Christoph Jungegger <disdos@traum404.de>)"; | |
365 | MODULE_AUTHOR("Christoph Jungegger <disdos@traum404.de>"); | |
366 | MODULE_DESCRIPTION | |
367 | ("Driver for wireless LAN cards using the Nortel PCI bridge"); | |
368 | MODULE_LICENSE("Dual MPL/GPL"); | |
369 | ||
370 | static int __init nortel_pci_init(void) | |
371 | { | |
372 | printk(KERN_DEBUG "%s\n", version); | |
373 | return pci_module_init(&nortel_pci_driver); | |
374 | } | |
375 | ||
376 | static void __exit nortel_pci_exit(void) | |
377 | { | |
378 | pci_unregister_driver(&nortel_pci_driver); | |
379 | ssleep(1); | |
380 | } | |
381 | ||
382 | module_init(nortel_pci_init); | |
383 | module_exit(nortel_pci_exit); | |
384 | ||
385 | /* | |
386 | * Local variables: | |
387 | * c-indent-level: 8 | |
388 | * c-basic-offset: 8 | |
389 | * tab-width: 8 | |
390 | * End: | |
391 | */ |