blob: 048693b6c6c24f06e701a2fa5856484c228065a6 [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
Andrey Borzenkovd14c7c12009-01-25 23:08:43 +030012 * Some of this code is borrowed from orinoco_pci.c
Pavel Roskinec829052005-09-01 20:08:56 -040013 * 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.
Andrey Borzenkovd14c7c12009-01-25 23:08:43 +030017 *
Pavel Roskinec829052005-09-01 20:08:56 -040018 * 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
Pavel Roskinec829052005-09-01 20:08:56 -040043#include <linux/module.h>
44#include <linux/kernel.h>
45#include <linux/init.h>
Pavel Roskinef846bf2005-09-23 04:18:07 -040046#include <linux/delay.h>
Pavel Roskinec829052005-09-01 20:08:56 -040047#include <linux/pci.h>
Pavel Roskinec829052005-09-01 20:08:56 -040048#include <pcmcia/cisreg.h>
49
Pavel Roskinec829052005-09-01 20:08:56 -040050#include "orinoco.h"
Pavel Roskinb884c872006-04-07 04:10:57 -040051#include "orinoco_pci.h"
Pavel Roskinec829052005-09-01 20:08:56 -040052
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
Pavel Roskinec829052005-09-01 20:08:56 -040057/*
Pavel Roskindc3437d2006-04-07 04:11:00 -040058 * Do a soft reset of the card using the Configuration Option Register
Pavel Roskinec829052005-09-01 20:08:56 -040059 * 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 */
Pavel Roskinb884c872006-04-07 04:10:57 -040065static int orinoco_nortel_cor_reset(struct orinoco_private *priv)
Pavel Roskinec829052005-09-01 20:08:56 -040066{
Pavel Roskinb884c872006-04-07 04:10:57 -040067 struct orinoco_pci_card *card = priv->card;
Pavel Roskinec829052005-09-01 20:08:56 -040068
Pavel Roskindc3437d2006-04-07 04:11:00 -040069 /* Assert the reset until the card notices */
Pavel Roskinb884c872006-04-07 04:10:57 -040070 iowrite16(8, card->bridge_io + 2);
71 ioread16(card->attr_io + COR_OFFSET);
72 iowrite16(0x80, card->attr_io + COR_OFFSET);
Pavel Roskinec829052005-09-01 20:08:56 -040073 mdelay(1);
74
75 /* Give time for the card to recover from this hard effort */
Pavel Roskinb884c872006-04-07 04:10:57 -040076 iowrite16(0, card->attr_io + COR_OFFSET);
77 iowrite16(0, card->attr_io + COR_OFFSET);
Pavel Roskinec829052005-09-01 20:08:56 -040078 mdelay(1);
79
Pavel Roskinb884c872006-04-07 04:10:57 -040080 /* Set COR as usual */
81 iowrite16(COR_VALUE, card->attr_io + COR_OFFSET);
82 iowrite16(COR_VALUE, card->attr_io + COR_OFFSET);
Pavel Roskinec829052005-09-01 20:08:56 -040083 mdelay(1);
84
Pavel Roskinb884c872006-04-07 04:10:57 -040085 iowrite16(0x228, card->bridge_io + 2);
Pavel Roskinec829052005-09-01 20:08:56 -040086
87 return 0;
88}
89
Pavel Roskinb884c872006-04-07 04:10:57 -040090static int orinoco_nortel_hw_init(struct orinoco_pci_card *card)
Pavel Roskinec829052005-09-01 20:08:56 -040091{
92 int i;
93 u32 reg;
94
Pavel Roskinb884c872006-04-07 04:10:57 -040095 /* Setup bridge */
96 if (ioread16(card->bridge_io) & 1) {
Pavel Roskinec829052005-09-01 20:08:56 -040097 printk(KERN_ERR PFX "brg1 answer1 wrong\n");
98 return -EBUSY;
99 }
Pavel Roskinb884c872006-04-07 04:10:57 -0400100 iowrite16(0x118, card->bridge_io + 2);
101 iowrite16(0x108, card->bridge_io + 2);
Pavel Roskinec829052005-09-01 20:08:56 -0400102 mdelay(30);
Pavel Roskinb884c872006-04-07 04:10:57 -0400103 iowrite16(0x8, card->bridge_io + 2);
Pavel Roskinec829052005-09-01 20:08:56 -0400104 for (i = 0; i < 30; i++) {
105 mdelay(30);
Andrey Borzenkovd14c7c12009-01-25 23:08:43 +0300106 if (ioread16(card->bridge_io) & 0x10)
Pavel Roskinec829052005-09-01 20:08:56 -0400107 break;
Pavel Roskinec829052005-09-01 20:08:56 -0400108 }
109 if (i == 30) {
110 printk(KERN_ERR PFX "brg1 timed out\n");
111 return -EBUSY;
112 }
Pavel Roskinb884c872006-04-07 04:10:57 -0400113 if (ioread16(card->attr_io + COR_OFFSET) & 1) {
Pavel Roskinec829052005-09-01 20:08:56 -0400114 printk(KERN_ERR PFX "brg2 answer1 wrong\n");
115 return -EBUSY;
116 }
Pavel Roskinb884c872006-04-07 04:10:57 -0400117 if (ioread16(card->attr_io + COR_OFFSET + 2) & 1) {
Pavel Roskinec829052005-09-01 20:08:56 -0400118 printk(KERN_ERR PFX "brg2 answer2 wrong\n");
119 return -EBUSY;
120 }
Pavel Roskinb884c872006-04-07 04:10:57 -0400121 if (ioread16(card->attr_io + COR_OFFSET + 4) & 1) {
Pavel Roskinec829052005-09-01 20:08:56 -0400122 printk(KERN_ERR PFX "brg2 answer3 wrong\n");
123 return -EBUSY;
124 }
125
Pavel Roskindc3437d2006-04-07 04:11:00 -0400126 /* Set the PCMCIA COR register */
Pavel Roskinb884c872006-04-07 04:10:57 -0400127 iowrite16(COR_VALUE, card->attr_io + COR_OFFSET);
Pavel Roskinec829052005-09-01 20:08:56 -0400128 mdelay(1);
Pavel Roskinb884c872006-04-07 04:10:57 -0400129 reg = ioread16(card->attr_io + COR_OFFSET);
Pavel Roskinec829052005-09-01 20:08:56 -0400130 if (reg != COR_VALUE) {
131 printk(KERN_ERR PFX "Error setting COR value (reg=%x)\n",
132 reg);
133 return -EBUSY;
134 }
135
Pavel Roskinb884c872006-04-07 04:10:57 -0400136 /* Set LEDs */
137 iowrite16(1, card->bridge_io + 10);
Pavel Roskinec829052005-09-01 20:08:56 -0400138 return 0;
139}
140
Pavel Roskinb884c872006-04-07 04:10:57 -0400141static int orinoco_nortel_init_one(struct pci_dev *pdev,
142 const struct pci_device_id *ent)
Pavel Roskinec829052005-09-01 20:08:56 -0400143{
144 int err;
145 struct orinoco_private *priv;
Pavel Roskinb884c872006-04-07 04:10:57 -0400146 struct orinoco_pci_card *card;
Pavel Roskinb884c872006-04-07 04:10:57 -0400147 void __iomem *hermes_io, *bridge_io, *attr_io;
Pavel Roskinec829052005-09-01 20:08:56 -0400148
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);
Pavel Roskinb884c872006-04-07 04:10:57 -0400156 if (err) {
Pavel Roskinec829052005-09-01 20:08:56 -0400157 printk(KERN_ERR PFX "Cannot obtain PCI resources\n");
158 goto fail_resources;
159 }
160
Pavel Roskinb884c872006-04-07 04:10:57 -0400161 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;
Pavel Roskinec829052005-09-01 20:08:56 -0400180 }
181
182 /* Allocate network device */
David Kilroya2608362009-06-18 23:21:23 +0100183 priv = alloc_orinocodev(sizeof(*card), &pdev->dev,
184 orinoco_nortel_cor_reset, NULL);
185 if (!priv) {
Pavel Roskinec829052005-09-01 20:08:56 -0400186 printk(KERN_ERR PFX "Cannot allocate network device\n");
187 err = -ENOMEM;
188 goto fail_alloc;
189 }
190
Pavel Roskinec829052005-09-01 20:08:56 -0400191 card = priv->card;
Pavel Roskinb884c872006-04-07 04:10:57 -0400192 card->bridge_io = bridge_io;
193 card->attr_io = attr_io;
Pavel Roskinec829052005-09-01 20:08:56 -0400194
Pavel Roskinb884c872006-04-07 04:10:57 -0400195 hermes_struct_init(&priv->hw, hermes_io, HERMES_16BIT_REGSPACING);
Pavel Roskinec829052005-09-01 20:08:56 -0400196
Thomas Gleixner1fb9df52006-07-01 19:29:39 -0700197 err = request_irq(pdev->irq, orinoco_interrupt, IRQF_SHARED,
David Kilroy53819562009-06-18 23:21:28 +0100198 DRIVER_NAME, priv);
Pavel Roskinec829052005-09-01 20:08:56 -0400199 if (err) {
200 printk(KERN_ERR PFX "Cannot allocate IRQ %d\n", pdev->irq);
201 err = -EBUSY;
202 goto fail_irq;
203 }
Pavel Roskinec829052005-09-01 20:08:56 -0400204
Pavel Roskinb884c872006-04-07 04:10:57 -0400205 err = orinoco_nortel_hw_init(card);
Pavel Roskinec829052005-09-01 20:08:56 -0400206 if (err) {
207 printk(KERN_ERR PFX "Hardware initialization failed\n");
208 goto fail;
209 }
210
Pavel Roskinb884c872006-04-07 04:10:57 -0400211 err = orinoco_nortel_cor_reset(priv);
Pavel Roskinec829052005-09-01 20:08:56 -0400212 if (err) {
213 printk(KERN_ERR PFX "Initial reset failed\n");
214 goto fail;
215 }
216
David Kilroy8e638262009-06-18 23:21:24 +0100217 err = orinoco_init(priv);
218 if (err) {
219 printk(KERN_ERR PFX "orinoco_init() failed\n");
220 goto fail;
221 }
222
David Kilroy593ef092010-05-01 14:05:39 +0100223 err = orinoco_if_add(priv, 0, 0, NULL);
Pavel Roskinec829052005-09-01 20:08:56 -0400224 if (err) {
David Kilroy53819562009-06-18 23:21:28 +0100225 printk(KERN_ERR PFX "orinoco_if_add() failed\n");
Jes Sorensen94fdc2e2015-08-06 12:46:31 -0400226 goto fail_wiphy;
Pavel Roskinec829052005-09-01 20:08:56 -0400227 }
228
David Kilroya2608362009-06-18 23:21:23 +0100229 pci_set_drvdata(pdev, priv);
Pavel Roskinec829052005-09-01 20:08:56 -0400230
231 return 0;
232
Jes Sorensen94fdc2e2015-08-06 12:46:31 -0400233 fail_wiphy:
234 wiphy_unregister(priv_to_wiphy(priv));
Pavel Roskinec829052005-09-01 20:08:56 -0400235 fail:
David Kilroya2608362009-06-18 23:21:23 +0100236 free_irq(pdev->irq, priv);
Pavel Roskinec829052005-09-01 20:08:56 -0400237
238 fail_irq:
David Kilroya2608362009-06-18 23:21:23 +0100239 free_orinocodev(priv);
Pavel Roskinec829052005-09-01 20:08:56 -0400240
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
Bill Pembertonbaa366c2012-12-03 09:56:37 -0500259static void orinoco_nortel_remove_one(struct pci_dev *pdev)
Pavel Roskinec829052005-09-01 20:08:56 -0400260{
David Kilroya2608362009-06-18 23:21:23 +0100261 struct orinoco_private *priv = pci_get_drvdata(pdev);
Pavel Roskinb884c872006-04-07 04:10:57 -0400262 struct orinoco_pci_card *card = priv->card;
Pavel Roskinec829052005-09-01 20:08:56 -0400263
Pavel Roskinb884c872006-04-07 04:10:57 -0400264 /* Clear LEDs */
265 iowrite16(0, card->bridge_io + 10);
Pavel Roskinec829052005-09-01 20:08:56 -0400266
David Kilroy53819562009-06-18 23:21:28 +0100267 orinoco_if_del(priv);
Jes Sorensen94fdc2e2015-08-06 12:46:31 -0400268 wiphy_unregister(priv_to_wiphy(priv));
David Kilroya2608362009-06-18 23:21:23 +0100269 free_irq(pdev->irq, priv);
David Kilroya2608362009-06-18 23:21:23 +0100270 free_orinocodev(priv);
Pavel Roskinec829052005-09-01 20:08:56 -0400271 pci_iounmap(pdev, priv->hw.iobase);
Pavel Roskinb884c872006-04-07 04:10:57 -0400272 pci_iounmap(pdev, card->attr_io);
273 pci_iounmap(pdev, card->bridge_io);
Pavel Roskinec829052005-09-01 20:08:56 -0400274 pci_release_regions(pdev);
275 pci_disable_device(pdev);
276}
277
Benoit Taine9baa3c32014-08-08 15:56:03 +0200278static const struct pci_device_id orinoco_nortel_id_table[] = {
Pavel Roskinec829052005-09-01 20:08:56 -0400279 /* Nortel emobility PCI */
280 {0x126c, 0x8030, PCI_ANY_ID, PCI_ANY_ID,},
Pavel Roskind4956572005-12-16 18:57:10 -0500281 /* Symbol LA-4123 PCI */
282 {0x1562, 0x0001, PCI_ANY_ID, PCI_ANY_ID,},
Pavel Roskinec829052005-09-01 20:08:56 -0400283 {0,},
284};
285
Pavel Roskinb884c872006-04-07 04:10:57 -0400286MODULE_DEVICE_TABLE(pci, orinoco_nortel_id_table);
Pavel Roskinec829052005-09-01 20:08:56 -0400287
Pavel Roskinb884c872006-04-07 04:10:57 -0400288static struct pci_driver orinoco_nortel_driver = {
Pavel Roskinc6fb2e92006-04-07 04:10:55 -0400289 .name = DRIVER_NAME,
Pavel Roskinb884c872006-04-07 04:10:57 -0400290 .id_table = orinoco_nortel_id_table,
291 .probe = orinoco_nortel_init_one,
Bill Pembertonbaa366c2012-12-03 09:56:37 -0500292 .remove = orinoco_nortel_remove_one,
Pavel Roskinb884c872006-04-07 04:10:57 -0400293 .suspend = orinoco_pci_suspend,
294 .resume = orinoco_pci_resume,
Pavel Roskinec829052005-09-01 20:08:56 -0400295};
296
297static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
298 " (Tobias Hoffmann & Christoph Jungegger <disdos@traum404.de>)";
299MODULE_AUTHOR("Christoph Jungegger <disdos@traum404.de>");
Pavel Roskin933d5942011-07-13 11:19:57 -0400300MODULE_DESCRIPTION("Driver for wireless LAN cards using the Nortel PCI bridge");
Pavel Roskinec829052005-09-01 20:08:56 -0400301MODULE_LICENSE("Dual MPL/GPL");
302
Pavel Roskinb884c872006-04-07 04:10:57 -0400303static int __init orinoco_nortel_init(void)
Pavel Roskinec829052005-09-01 20:08:56 -0400304{
305 printk(KERN_DEBUG "%s\n", version);
Jeff Garzik29917622006-08-19 17:48:59 -0400306 return pci_register_driver(&orinoco_nortel_driver);
Pavel Roskinec829052005-09-01 20:08:56 -0400307}
308
Pavel Roskinb884c872006-04-07 04:10:57 -0400309static void __exit orinoco_nortel_exit(void)
Pavel Roskinec829052005-09-01 20:08:56 -0400310{
Pavel Roskinb884c872006-04-07 04:10:57 -0400311 pci_unregister_driver(&orinoco_nortel_driver);
Pavel Roskinec829052005-09-01 20:08:56 -0400312}
313
Pavel Roskinb884c872006-04-07 04:10:57 -0400314module_init(orinoco_nortel_init);
315module_exit(orinoco_nortel_exit);
Pavel Roskinec829052005-09-01 20:08:56 -0400316
317/*
318 * Local variables:
319 * c-indent-level: 8
320 * c-basic-offset: 8
321 * tab-width: 8
322 * End:
323 */