blob: 74b9d5b2ba9ee00005586938f832cf4c1f36911e [file] [log] [blame]
Pavel Roskinec829052005-09-01 20:08:56 -04001/* orinoco_nortel.c
Pavel Roskinb884c872006-04-07 04:10:57 -04002 *
Pavel Roskinec829052005-09-01 20:08:56 -04003 * Driver for Prism II devices which would usually be driven by orinoco_cs,
Pavel Roskind4956572005-12-16 18:57:10 -05004 * 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.
Pavel Roskinec829052005-09-01 20:08:56 -04006 *
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
12 * Some of this code is borrowed from orinoco_pci.c
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.
17 *
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
43#include <linux/config.h>
Pavel Roskinec829052005-09-01 20:08:56 -040044#include <linux/module.h>
45#include <linux/kernel.h>
46#include <linux/init.h>
Pavel Roskinef846bf2005-09-23 04:18:07 -040047#include <linux/delay.h>
Pavel Roskinec829052005-09-01 20:08:56 -040048#include <linux/pci.h>
Pavel Roskinec829052005-09-01 20:08:56 -040049#include <pcmcia/cisreg.h>
50
Pavel Roskinec829052005-09-01 20:08:56 -040051#include "orinoco.h"
Pavel Roskinb884c872006-04-07 04:10:57 -040052#include "orinoco_pci.h"
Pavel Roskinec829052005-09-01 20:08:56 -040053
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
Pavel Roskinec829052005-09-01 20:08:56 -040058/*
Pavel Roskindc3437d2006-04-07 04:11:00 -040059 * Do a soft reset of the card using the Configuration Option Register
Pavel Roskinec829052005-09-01 20:08:56 -040060 * We need this to get going...
61 * This is the part of the code that is strongly inspired from wlan-ng
62 *
63 * Note bis : Don't try to access HERMES_CMD during the reset phase.
64 * It just won't work !
65 */
Pavel Roskinb884c872006-04-07 04:10:57 -040066static int orinoco_nortel_cor_reset(struct orinoco_private *priv)
Pavel Roskinec829052005-09-01 20:08:56 -040067{
Pavel Roskinb884c872006-04-07 04:10:57 -040068 struct orinoco_pci_card *card = priv->card;
Pavel Roskinec829052005-09-01 20:08:56 -040069
Pavel Roskindc3437d2006-04-07 04:11:00 -040070 /* Assert the reset until the card notices */
Pavel Roskinb884c872006-04-07 04:10:57 -040071 iowrite16(8, card->bridge_io + 2);
72 ioread16(card->attr_io + COR_OFFSET);
73 iowrite16(0x80, card->attr_io + COR_OFFSET);
Pavel Roskinec829052005-09-01 20:08:56 -040074 mdelay(1);
75
76 /* Give time for the card to recover from this hard effort */
Pavel Roskinb884c872006-04-07 04:10:57 -040077 iowrite16(0, card->attr_io + COR_OFFSET);
78 iowrite16(0, card->attr_io + COR_OFFSET);
Pavel Roskinec829052005-09-01 20:08:56 -040079 mdelay(1);
80
Pavel Roskinb884c872006-04-07 04:10:57 -040081 /* Set COR as usual */
82 iowrite16(COR_VALUE, card->attr_io + COR_OFFSET);
83 iowrite16(COR_VALUE, card->attr_io + COR_OFFSET);
Pavel Roskinec829052005-09-01 20:08:56 -040084 mdelay(1);
85
Pavel Roskinb884c872006-04-07 04:10:57 -040086 iowrite16(0x228, card->bridge_io + 2);
Pavel Roskinec829052005-09-01 20:08:56 -040087
88 return 0;
89}
90
Pavel Roskinb884c872006-04-07 04:10:57 -040091static int orinoco_nortel_hw_init(struct orinoco_pci_card *card)
Pavel Roskinec829052005-09-01 20:08:56 -040092{
93 int i;
94 u32 reg;
95
Pavel Roskinb884c872006-04-07 04:10:57 -040096 /* Setup bridge */
97 if (ioread16(card->bridge_io) & 1) {
Pavel Roskinec829052005-09-01 20:08:56 -040098 printk(KERN_ERR PFX "brg1 answer1 wrong\n");
99 return -EBUSY;
100 }
Pavel Roskinb884c872006-04-07 04:10:57 -0400101 iowrite16(0x118, card->bridge_io + 2);
102 iowrite16(0x108, card->bridge_io + 2);
Pavel Roskinec829052005-09-01 20:08:56 -0400103 mdelay(30);
Pavel Roskinb884c872006-04-07 04:10:57 -0400104 iowrite16(0x8, card->bridge_io + 2);
Pavel Roskinec829052005-09-01 20:08:56 -0400105 for (i = 0; i < 30; i++) {
106 mdelay(30);
Pavel Roskinb884c872006-04-07 04:10:57 -0400107 if (ioread16(card->bridge_io) & 0x10) {
Pavel Roskinec829052005-09-01 20:08:56 -0400108 break;
109 }
110 }
111 if (i == 30) {
112 printk(KERN_ERR PFX "brg1 timed out\n");
113 return -EBUSY;
114 }
Pavel Roskinb884c872006-04-07 04:10:57 -0400115 if (ioread16(card->attr_io + COR_OFFSET) & 1) {
Pavel Roskinec829052005-09-01 20:08:56 -0400116 printk(KERN_ERR PFX "brg2 answer1 wrong\n");
117 return -EBUSY;
118 }
Pavel Roskinb884c872006-04-07 04:10:57 -0400119 if (ioread16(card->attr_io + COR_OFFSET + 2) & 1) {
Pavel Roskinec829052005-09-01 20:08:56 -0400120 printk(KERN_ERR PFX "brg2 answer2 wrong\n");
121 return -EBUSY;
122 }
Pavel Roskinb884c872006-04-07 04:10:57 -0400123 if (ioread16(card->attr_io + COR_OFFSET + 4) & 1) {
Pavel Roskinec829052005-09-01 20:08:56 -0400124 printk(KERN_ERR PFX "brg2 answer3 wrong\n");
125 return -EBUSY;
126 }
127
Pavel Roskindc3437d2006-04-07 04:11:00 -0400128 /* Set the PCMCIA COR register */
Pavel Roskinb884c872006-04-07 04:10:57 -0400129 iowrite16(COR_VALUE, card->attr_io + COR_OFFSET);
Pavel Roskinec829052005-09-01 20:08:56 -0400130 mdelay(1);
Pavel Roskinb884c872006-04-07 04:10:57 -0400131 reg = ioread16(card->attr_io + COR_OFFSET);
Pavel Roskinec829052005-09-01 20:08:56 -0400132 if (reg != COR_VALUE) {
133 printk(KERN_ERR PFX "Error setting COR value (reg=%x)\n",
134 reg);
135 return -EBUSY;
136 }
137
Pavel Roskinb884c872006-04-07 04:10:57 -0400138 /* Set LEDs */
139 iowrite16(1, card->bridge_io + 10);
Pavel Roskinec829052005-09-01 20:08:56 -0400140 return 0;
141}
142
Pavel Roskinb884c872006-04-07 04:10:57 -0400143static int orinoco_nortel_init_one(struct pci_dev *pdev,
144 const struct pci_device_id *ent)
Pavel Roskinec829052005-09-01 20:08:56 -0400145{
146 int err;
147 struct orinoco_private *priv;
Pavel Roskinb884c872006-04-07 04:10:57 -0400148 struct orinoco_pci_card *card;
Pavel Roskinec829052005-09-01 20:08:56 -0400149 struct net_device *dev;
Pavel Roskinb884c872006-04-07 04:10:57 -0400150 void __iomem *hermes_io, *bridge_io, *attr_io;
Pavel Roskinec829052005-09-01 20:08:56 -0400151
152 err = pci_enable_device(pdev);
153 if (err) {
154 printk(KERN_ERR PFX "Cannot enable PCI device\n");
155 return err;
156 }
157
158 err = pci_request_regions(pdev, DRIVER_NAME);
Pavel Roskinb884c872006-04-07 04:10:57 -0400159 if (err) {
Pavel Roskinec829052005-09-01 20:08:56 -0400160 printk(KERN_ERR PFX "Cannot obtain PCI resources\n");
161 goto fail_resources;
162 }
163
Pavel Roskinb884c872006-04-07 04:10:57 -0400164 bridge_io = pci_iomap(pdev, 0, 0);
165 if (!bridge_io) {
166 printk(KERN_ERR PFX "Cannot map bridge registers\n");
167 err = -EIO;
168 goto fail_map_bridge;
169 }
170
171 attr_io = pci_iomap(pdev, 1, 0);
172 if (!attr_io) {
173 printk(KERN_ERR PFX "Cannot map PCMCIA attributes\n");
174 err = -EIO;
175 goto fail_map_attr;
176 }
177
178 hermes_io = pci_iomap(pdev, 2, 0);
179 if (!hermes_io) {
180 printk(KERN_ERR PFX "Cannot map chipset registers\n");
181 err = -EIO;
182 goto fail_map_hermes;
Pavel Roskinec829052005-09-01 20:08:56 -0400183 }
184
185 /* Allocate network device */
Pavel Roskinb884c872006-04-07 04:10:57 -0400186 dev = alloc_orinocodev(sizeof(*card), orinoco_nortel_cor_reset);
Pavel Roskinec829052005-09-01 20:08:56 -0400187 if (!dev) {
188 printk(KERN_ERR PFX "Cannot allocate network device\n");
189 err = -ENOMEM;
190 goto fail_alloc;
191 }
192
193 priv = netdev_priv(dev);
194 card = priv->card;
Pavel Roskinb884c872006-04-07 04:10:57 -0400195 card->bridge_io = bridge_io;
196 card->attr_io = attr_io;
Pavel Roskinec829052005-09-01 20:08:56 -0400197 SET_MODULE_OWNER(dev);
198 SET_NETDEV_DEV(dev, &pdev->dev);
199
Pavel Roskinb884c872006-04-07 04:10:57 -0400200 hermes_struct_init(&priv->hw, hermes_io, HERMES_16BIT_REGSPACING);
Pavel Roskinec829052005-09-01 20:08:56 -0400201
202 err = request_irq(pdev->irq, orinoco_interrupt, SA_SHIRQ,
203 dev->name, dev);
204 if (err) {
205 printk(KERN_ERR PFX "Cannot allocate IRQ %d\n", pdev->irq);
206 err = -EBUSY;
207 goto fail_irq;
208 }
Pavel Roskinec829052005-09-01 20:08:56 -0400209
Pavel Roskinb884c872006-04-07 04:10:57 -0400210 err = orinoco_nortel_hw_init(card);
Pavel Roskinec829052005-09-01 20:08:56 -0400211 if (err) {
212 printk(KERN_ERR PFX "Hardware initialization failed\n");
213 goto fail;
214 }
215
Pavel Roskinb884c872006-04-07 04:10:57 -0400216 err = orinoco_nortel_cor_reset(priv);
Pavel Roskinec829052005-09-01 20:08:56 -0400217 if (err) {
218 printk(KERN_ERR PFX "Initial reset failed\n");
219 goto fail;
220 }
221
Pavel Roskinec829052005-09-01 20:08:56 -0400222 err = register_netdev(dev);
223 if (err) {
224 printk(KERN_ERR PFX "Cannot register network device\n");
225 goto fail;
226 }
227
228 pci_set_drvdata(pdev, dev);
Pavel Roskin461c0782006-05-01 02:13:33 -0400229 printk(KERN_DEBUG "%s: " DRIVER_NAME " at %s\n", dev->name,
230 pci_name(pdev));
Pavel Roskinec829052005-09-01 20:08:56 -0400231
232 return 0;
233
234 fail:
235 free_irq(pdev->irq, dev);
236
237 fail_irq:
238 pci_set_drvdata(pdev, NULL);
239 free_orinocodev(dev);
240
241 fail_alloc:
Pavel Roskinb884c872006-04-07 04:10:57 -0400242 pci_iounmap(pdev, hermes_io);
Pavel Roskinec829052005-09-01 20:08:56 -0400243
Pavel Roskinb884c872006-04-07 04:10:57 -0400244 fail_map_hermes:
245 pci_iounmap(pdev, attr_io);
246
247 fail_map_attr:
248 pci_iounmap(pdev, bridge_io);
249
250 fail_map_bridge:
Pavel Roskinec829052005-09-01 20:08:56 -0400251 pci_release_regions(pdev);
252
253 fail_resources:
254 pci_disable_device(pdev);
255
256 return err;
257}
258
Pavel Roskinb884c872006-04-07 04:10:57 -0400259static void __devexit orinoco_nortel_remove_one(struct pci_dev *pdev)
Pavel Roskinec829052005-09-01 20:08:56 -0400260{
261 struct net_device *dev = pci_get_drvdata(pdev);
262 struct orinoco_private *priv = netdev_priv(dev);
Pavel Roskinb884c872006-04-07 04:10:57 -0400263 struct orinoco_pci_card *card = priv->card;
Pavel Roskinec829052005-09-01 20:08:56 -0400264
Pavel Roskinb884c872006-04-07 04:10:57 -0400265 /* Clear LEDs */
266 iowrite16(0, card->bridge_io + 10);
Pavel Roskinec829052005-09-01 20:08:56 -0400267
268 unregister_netdev(dev);
Pavel Roskin461c0782006-05-01 02:13:33 -0400269 free_irq(pdev->irq, dev);
Pavel Roskinec829052005-09-01 20:08:56 -0400270 pci_set_drvdata(pdev, NULL);
271 free_orinocodev(dev);
272 pci_iounmap(pdev, priv->hw.iobase);
Pavel Roskinb884c872006-04-07 04:10:57 -0400273 pci_iounmap(pdev, card->attr_io);
274 pci_iounmap(pdev, card->bridge_io);
Pavel Roskinec829052005-09-01 20:08:56 -0400275 pci_release_regions(pdev);
276 pci_disable_device(pdev);
277}
278
Pavel Roskinb884c872006-04-07 04:10:57 -0400279static struct pci_device_id orinoco_nortel_id_table[] = {
Pavel Roskinec829052005-09-01 20:08:56 -0400280 /* Nortel emobility PCI */
281 {0x126c, 0x8030, PCI_ANY_ID, PCI_ANY_ID,},
Pavel Roskind4956572005-12-16 18:57:10 -0500282 /* Symbol LA-4123 PCI */
283 {0x1562, 0x0001, PCI_ANY_ID, PCI_ANY_ID,},
Pavel Roskinec829052005-09-01 20:08:56 -0400284 {0,},
285};
286
Pavel Roskinb884c872006-04-07 04:10:57 -0400287MODULE_DEVICE_TABLE(pci, orinoco_nortel_id_table);
Pavel Roskinec829052005-09-01 20:08:56 -0400288
Pavel Roskinb884c872006-04-07 04:10:57 -0400289static struct pci_driver orinoco_nortel_driver = {
Pavel Roskinc6fb2e92006-04-07 04:10:55 -0400290 .name = DRIVER_NAME,
Pavel Roskinb884c872006-04-07 04:10:57 -0400291 .id_table = orinoco_nortel_id_table,
292 .probe = orinoco_nortel_init_one,
293 .remove = __devexit_p(orinoco_nortel_remove_one),
294 .suspend = orinoco_pci_suspend,
295 .resume = orinoco_pci_resume,
Pavel Roskinec829052005-09-01 20:08:56 -0400296};
297
298static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
299 " (Tobias Hoffmann & Christoph Jungegger <disdos@traum404.de>)";
300MODULE_AUTHOR("Christoph Jungegger <disdos@traum404.de>");
301MODULE_DESCRIPTION
302 ("Driver for wireless LAN cards using the Nortel PCI bridge");
303MODULE_LICENSE("Dual MPL/GPL");
304
Pavel Roskinb884c872006-04-07 04:10:57 -0400305static int __init orinoco_nortel_init(void)
Pavel Roskinec829052005-09-01 20:08:56 -0400306{
307 printk(KERN_DEBUG "%s\n", version);
Pavel Roskinb884c872006-04-07 04:10:57 -0400308 return pci_module_init(&orinoco_nortel_driver);
Pavel Roskinec829052005-09-01 20:08:56 -0400309}
310
Pavel Roskinb884c872006-04-07 04:10:57 -0400311static void __exit orinoco_nortel_exit(void)
Pavel Roskinec829052005-09-01 20:08:56 -0400312{
Pavel Roskinb884c872006-04-07 04:10:57 -0400313 pci_unregister_driver(&orinoco_nortel_driver);
Pavel Roskinec829052005-09-01 20:08:56 -0400314}
315
Pavel Roskinb884c872006-04-07 04:10:57 -0400316module_init(orinoco_nortel_init);
317module_exit(orinoco_nortel_exit);
Pavel Roskinec829052005-09-01 20:08:56 -0400318
319/*
320 * Local variables:
321 * c-indent-level: 8
322 * c-basic-offset: 8
323 * tab-width: 8
324 * End:
325 */