blob: 221352027779f75c5ceb0e605b15297e53b70c2f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* orinoco_plx.c
2 *
3 * Driver for Prism II devices which would usually be driven by orinoco_cs,
4 * but are connected to the PCI bus by a PLX9052.
5 *
Pavel Roskindc3437d2006-04-07 04:11:00 -04006 * Current maintainers are:
Pavel Roskin933d5942011-07-13 11:19:57 -04007 * Pavel Roskin <proski AT gnu.org>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 * and David Gibson <hermes AT gibson.dropbear.id.au>
9 *
10 * (C) Copyright David Gibson, IBM Corp. 2001-2003.
11 * Copyright (C) 2001 Daniel Barlow
12 *
13 * The contents of this file are subject to the Mozilla Public License
14 * Version 1.1 (the "License"); you may not use this file except in
15 * compliance with the License. You may obtain a copy of the License
16 * at http://www.mozilla.org/MPL/
17 *
18 * Software distributed under the License is distributed on an "AS IS"
19 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
20 * the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * Alternatively, the contents of this file may be used under the
24 * terms of the GNU General Public License version 2 (the "GPL"), in
25 * which case the provisions of the GPL are applicable instead of the
26 * above. If you wish to allow the use of your version of this file
27 * only under the terms of the GPL and not to allow others to use your
28 * version of this file under the MPL, indicate your decision by
29 * deleting the provisions above and replace them with the notice and
30 * other provisions required by the GPL. If you do not delete the
31 * provisions above, a recipient may use your version of this file
32 * under either the MPL or the GPL.
Linus Torvalds1da177e2005-04-16 15:20:36 -070033 *
Pavel Roskindc3437d2006-04-07 04:11:00 -040034 * Here's the general details on how the PLX9052 adapter works:
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 *
36 * - Two PCI I/O address spaces, one 0x80 long which contains the
37 * PLX9052 registers, and one that's 0x40 long mapped to the PCMCIA
38 * slot I/O address space.
39 *
Pavel Roskindc3437d2006-04-07 04:11:00 -040040 * - One PCI memory address space, mapped to the PCMCIA attribute space
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 * (containing the CIS).
42 *
Pavel Roskindc3437d2006-04-07 04:11:00 -040043 * Using the later, you can read through the CIS data to make sure the
44 * card is compatible with the driver. Keep in mind that the PCMCIA
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 * spec specifies the CIS as the lower 8 bits of each word read from
46 * the CIS, so to read the bytes of the CIS, read every other byte
47 * (0,2,4,...). Passing that test, you need to enable the I/O address
48 * space on the PCMCIA card via the PCMCIA COR register. This is the
49 * first byte following the CIS. In my case (which may not have any
50 * relation to what's on the PRISM2 cards), COR was at offset 0x800
51 * within the PCI memory space. Write 0x41 to the COR register to
52 * enable I/O mode and to select level triggered interrupts. To
53 * confirm you actually succeeded, read the COR register back and make
Pavel Roskindc3437d2006-04-07 04:11:00 -040054 * sure it actually got set to 0x41, in case you have an unexpected
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 * card inserted.
56 *
57 * Following that, you can treat the second PCI I/O address space (the
58 * one that's not 0x80 in length) as the PCMCIA I/O space.
59 *
60 * Note that in the Eumitcom's source for their drivers, they register
61 * the interrupt as edge triggered when registering it with the
62 * Windows kernel. I don't recall how to register edge triggered on
63 * Linux (if it can be done at all). But in some experimentation, I
64 * don't see much operational difference between using either
65 * interrupt mode. Don't mess with the interrupt mode in the COR
66 * register though, as the PLX9052 wants level triggers with the way
67 * the serial EEPROM configures it on the WL11000.
68 *
69 * There's some other little quirks related to timing that I bumped
70 * into, but I don't recall right now. Also, there's two variants of
71 * the WL11000 I've seen, revision A1 and T2. These seem to differ
72 * slightly in the timings configured in the wait-state generator in
73 * the PLX9052. There have also been some comments from Eumitcom that
74 * cards shouldn't be hot swapped, apparently due to risk of cooking
75 * the PLX9052. I'm unsure why they believe this, as I can't see
76 * anything in the design that would really cause a problem, except
77 * for crashing drivers not written to expect it. And having developed
78 * drivers for the WL11000, I'd say it's quite tricky to write code
79 * that will successfully deal with a hot unplug. Very odd things
80 * happen on the I/O side of things. But anyway, be warned. Despite
81 * that, I've hot-swapped a number of times during debugging and
82 * driver development for various reasons (stuck WAIT# line after the
83 * radio card's firmware locks up).
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 */
85
86#define DRIVER_NAME "orinoco_plx"
87#define PFX DRIVER_NAME ": "
88
Linus Torvalds1da177e2005-04-16 15:20:36 -070089#include <linux/module.h>
90#include <linux/kernel.h>
91#include <linux/init.h>
Pavel Roskinef846bf2005-09-23 04:18:07 -040092#include <linux/delay.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070093#include <linux/pci.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070094#include <pcmcia/cisreg.h>
95
Linus Torvalds1da177e2005-04-16 15:20:36 -070096#include "orinoco.h"
Pavel Roskinb884c872006-04-07 04:10:57 -040097#include "orinoco_pci.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
99#define COR_OFFSET (0x3e0) /* COR attribute offset of Prism2 PC card */
100#define COR_VALUE (COR_LEVEL_REQ | COR_FUNC_ENA) /* Enable PC card with interrupt in level trigger */
101#define COR_RESET (0x80) /* reset bit in the COR register */
102#define PLX_RESET_TIME (500) /* milliseconds */
103
104#define PLX_INTCSR 0x4c /* Interrupt Control & Status Register */
Pavel Roskin933d5942011-07-13 11:19:57 -0400105#define PLX_INTCSR_INTEN (1 << 6) /* Interrupt Enable bit */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107/*
108 * Do a soft reset of the card using the Configuration Option Register
109 */
110static int orinoco_plx_cor_reset(struct orinoco_private *priv)
111{
Pavel Roskin933d5942011-07-13 11:19:57 -0400112 struct hermes *hw = &priv->hw;
Pavel Roskinb884c872006-04-07 04:10:57 -0400113 struct orinoco_pci_card *card = priv->card;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 unsigned long timeout;
115 u16 reg;
116
Pavel Roskinb884c872006-04-07 04:10:57 -0400117 iowrite8(COR_VALUE | COR_RESET, card->attr_io + COR_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 mdelay(1);
119
Pavel Roskinb884c872006-04-07 04:10:57 -0400120 iowrite8(COR_VALUE, card->attr_io + COR_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 mdelay(1);
122
123 /* Just in case, wait more until the card is no longer busy */
Nicholas Mc Guireab458cc2015-02-04 03:07:39 -0500124 timeout = jiffies + msecs_to_jiffies(PLX_RESET_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 reg = hermes_read_regn(hw, CMD);
126 while (time_before(jiffies, timeout) && (reg & HERMES_CMD_BUSY)) {
127 mdelay(1);
128 reg = hermes_read_regn(hw, CMD);
129 }
130
Pavel Roskinb884c872006-04-07 04:10:57 -0400131 /* Still busy? */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 if (reg & HERMES_CMD_BUSY) {
133 printk(KERN_ERR PFX "Busy timeout\n");
134 return -ETIMEDOUT;
135 }
136
137 return 0;
138}
139
Pavel Roskinb884c872006-04-07 04:10:57 -0400140static int orinoco_plx_hw_init(struct orinoco_pci_card *card)
141{
142 int i;
143 u32 csr_reg;
144 static const u8 cis_magic[] = {
145 0x01, 0x03, 0x00, 0x00, 0xff, 0x17, 0x04, 0x67
146 };
147
148 printk(KERN_DEBUG PFX "CIS: ");
Andrey Borzenkovd14c7c12009-01-25 23:08:43 +0300149 for (i = 0; i < 16; i++)
Pavel Roskinb884c872006-04-07 04:10:57 -0400150 printk("%02X:", ioread8(card->attr_io + (i << 1)));
Pavel Roskinb884c872006-04-07 04:10:57 -0400151 printk("\n");
152
153 /* Verify whether a supported PC card is present */
154 /* FIXME: we probably need to be smarted about this */
155 for (i = 0; i < sizeof(cis_magic); i++) {
156 if (cis_magic[i] != ioread8(card->attr_io + (i << 1))) {
157 printk(KERN_ERR PFX "The CIS value of Prism2 PC "
158 "card is unexpected\n");
159 return -ENODEV;
160 }
161 }
162
163 /* bjoern: We need to tell the card to enable interrupts, in
164 case the serial eprom didn't do this already. See the
165 PLX9052 data book, p8-1 and 8-24 for reference. */
166 csr_reg = ioread32(card->bridge_io + PLX_INTCSR);
167 if (!(csr_reg & PLX_INTCSR_INTEN)) {
168 csr_reg |= PLX_INTCSR_INTEN;
169 iowrite32(csr_reg, card->bridge_io + PLX_INTCSR);
170 csr_reg = ioread32(card->bridge_io + PLX_INTCSR);
171 if (!(csr_reg & PLX_INTCSR_INTEN)) {
172 printk(KERN_ERR PFX "Cannot enable interrupts\n");
173 return -EIO;
174 }
175 }
176
177 return 0;
178}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
180static int orinoco_plx_init_one(struct pci_dev *pdev,
181 const struct pci_device_id *ent)
182{
Pavel Roskinb884c872006-04-07 04:10:57 -0400183 int err;
184 struct orinoco_private *priv;
185 struct orinoco_pci_card *card;
Pavel Roskinb884c872006-04-07 04:10:57 -0400186 void __iomem *hermes_io, *attr_io, *bridge_io;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187
188 err = pci_enable_device(pdev);
189 if (err) {
190 printk(KERN_ERR PFX "Cannot enable PCI device\n");
191 return err;
192 }
193
194 err = pci_request_regions(pdev, DRIVER_NAME);
Pavel Roskinb884c872006-04-07 04:10:57 -0400195 if (err) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 printk(KERN_ERR PFX "Cannot obtain PCI resources\n");
197 goto fail_resources;
198 }
199
Pavel Roskinb884c872006-04-07 04:10:57 -0400200 bridge_io = pci_iomap(pdev, 1, 0);
201 if (!bridge_io) {
202 printk(KERN_ERR PFX "Cannot map bridge registers\n");
203 err = -EIO;
204 goto fail_map_bridge;
205 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206
Pavel Roskinb884c872006-04-07 04:10:57 -0400207 attr_io = pci_iomap(pdev, 2, 0);
208 if (!attr_io) {
209 printk(KERN_ERR PFX "Cannot map PCMCIA attributes\n");
210 err = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 goto fail_map_attr;
212 }
213
Pavel Roskinb884c872006-04-07 04:10:57 -0400214 hermes_io = pci_iomap(pdev, 3, 0);
215 if (!hermes_io) {
216 printk(KERN_ERR PFX "Cannot map chipset registers\n");
217 err = -EIO;
218 goto fail_map_hermes;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 }
220
221 /* Allocate network device */
David Kilroya2608362009-06-18 23:21:23 +0100222 priv = alloc_orinocodev(sizeof(*card), &pdev->dev,
223 orinoco_plx_cor_reset, NULL);
224 if (!priv) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 printk(KERN_ERR PFX "Cannot allocate network device\n");
226 err = -ENOMEM;
227 goto fail_alloc;
228 }
229
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 card = priv->card;
Pavel Roskinb884c872006-04-07 04:10:57 -0400231 card->bridge_io = bridge_io;
232 card->attr_io = attr_io;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233
Pavel Roskinb884c872006-04-07 04:10:57 -0400234 hermes_struct_init(&priv->hw, hermes_io, HERMES_16BIT_REGSPACING);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235
Thomas Gleixner1fb9df52006-07-01 19:29:39 -0700236 err = request_irq(pdev->irq, orinoco_interrupt, IRQF_SHARED,
David Kilroy53819562009-06-18 23:21:28 +0100237 DRIVER_NAME, priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 if (err) {
239 printk(KERN_ERR PFX "Cannot allocate IRQ %d\n", pdev->irq);
240 err = -EBUSY;
241 goto fail_irq;
242 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243
Pavel Roskinb884c872006-04-07 04:10:57 -0400244 err = orinoco_plx_hw_init(card);
245 if (err) {
246 printk(KERN_ERR PFX "Hardware initialization failed\n");
247 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 }
249
250 err = orinoco_plx_cor_reset(priv);
251 if (err) {
252 printk(KERN_ERR PFX "Initial reset failed\n");
253 goto fail;
254 }
255
David Kilroy8e638262009-06-18 23:21:24 +0100256 err = orinoco_init(priv);
257 if (err) {
258 printk(KERN_ERR PFX "orinoco_init() failed\n");
259 goto fail;
260 }
261
David Kilroy593ef092010-05-01 14:05:39 +0100262 err = orinoco_if_add(priv, 0, 0, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 if (err) {
David Kilroy53819562009-06-18 23:21:28 +0100264 printk(KERN_ERR PFX "orinoco_if_add() failed\n");
Jes Sorensen94fdc2e2015-08-06 12:46:31 -0400265 goto fail_wiphy;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 }
267
David Kilroya2608362009-06-18 23:21:23 +0100268 pci_set_drvdata(pdev, priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
270 return 0;
271
Jes Sorensen94fdc2e2015-08-06 12:46:31 -0400272 fail_wiphy:
273 wiphy_unregister(priv_to_wiphy(priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 fail:
David Kilroya2608362009-06-18 23:21:23 +0100275 free_irq(pdev->irq, priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276
277 fail_irq:
David Kilroya2608362009-06-18 23:21:23 +0100278 free_orinocodev(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279
280 fail_alloc:
Pavel Roskinb884c872006-04-07 04:10:57 -0400281 pci_iounmap(pdev, hermes_io);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282
Pavel Roskinb884c872006-04-07 04:10:57 -0400283 fail_map_hermes:
284 pci_iounmap(pdev, attr_io);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285
286 fail_map_attr:
Pavel Roskinb884c872006-04-07 04:10:57 -0400287 pci_iounmap(pdev, bridge_io);
288
289 fail_map_bridge:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 pci_release_regions(pdev);
291
292 fail_resources:
293 pci_disable_device(pdev);
294
295 return err;
296}
297
Bill Pembertonbaa366c2012-12-03 09:56:37 -0500298static void orinoco_plx_remove_one(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299{
David Kilroya2608362009-06-18 23:21:23 +0100300 struct orinoco_private *priv = pci_get_drvdata(pdev);
Pavel Roskinb884c872006-04-07 04:10:57 -0400301 struct orinoco_pci_card *card = priv->card;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302
David Kilroy53819562009-06-18 23:21:28 +0100303 orinoco_if_del(priv);
Jes Sorensen94fdc2e2015-08-06 12:46:31 -0400304 wiphy_unregister(priv_to_wiphy(priv));
David Kilroya2608362009-06-18 23:21:23 +0100305 free_irq(pdev->irq, priv);
David Kilroya2608362009-06-18 23:21:23 +0100306 free_orinocodev(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 pci_iounmap(pdev, priv->hw.iobase);
Pavel Roskinb884c872006-04-07 04:10:57 -0400308 pci_iounmap(pdev, card->attr_io);
309 pci_iounmap(pdev, card->bridge_io);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 pci_release_regions(pdev);
311 pci_disable_device(pdev);
312}
313
Benoit Taine9baa3c32014-08-08 15:56:03 +0200314static const struct pci_device_id orinoco_plx_id_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 {0x111a, 0x1023, PCI_ANY_ID, PCI_ANY_ID,}, /* Siemens SpeedStream SS1023 */
316 {0x1385, 0x4100, PCI_ANY_ID, PCI_ANY_ID,}, /* Netgear MA301 */
317 {0x15e8, 0x0130, PCI_ANY_ID, PCI_ANY_ID,}, /* Correga - does this work? */
318 {0x1638, 0x1100, PCI_ANY_ID, PCI_ANY_ID,}, /* SMC EZConnect SMC2602W,
319 Eumitcom PCI WL11000,
320 Addtron AWA-100 */
321 {0x16ab, 0x1100, PCI_ANY_ID, PCI_ANY_ID,}, /* Global Sun Tech GL24110P */
322 {0x16ab, 0x1101, PCI_ANY_ID, PCI_ANY_ID,}, /* Reported working, but unknown */
323 {0x16ab, 0x1102, PCI_ANY_ID, PCI_ANY_ID,}, /* Linksys WDT11 */
324 {0x16ec, 0x3685, PCI_ANY_ID, PCI_ANY_ID,}, /* USR 2415 */
325 {0xec80, 0xec00, PCI_ANY_ID, PCI_ANY_ID,}, /* Belkin F5D6000 tested by
326 Brendan W. McAdams <rit AT jacked-in.org> */
327 {0x10b7, 0x7770, PCI_ANY_ID, PCI_ANY_ID,}, /* 3Com AirConnect PCI tested by
328 Damien Persohn <damien AT persohn.net> */
329 {0,},
330};
331
Pavel Roskinb884c872006-04-07 04:10:57 -0400332MODULE_DEVICE_TABLE(pci, orinoco_plx_id_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333
334static struct pci_driver orinoco_plx_driver = {
335 .name = DRIVER_NAME,
Pavel Roskinb884c872006-04-07 04:10:57 -0400336 .id_table = orinoco_plx_id_table,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 .probe = orinoco_plx_init_one,
Bill Pembertonbaa366c2012-12-03 09:56:37 -0500338 .remove = orinoco_plx_remove_one,
Pavel Roskinb884c872006-04-07 04:10:57 -0400339 .suspend = orinoco_pci_suspend,
340 .resume = orinoco_pci_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341};
342
343static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
344 " (Pavel Roskin <proski@gnu.org>,"
345 " David Gibson <hermes@gibson.dropbear.id.au>,"
346 " Daniel Barlow <dan@telent.net>)";
347MODULE_AUTHOR("Daniel Barlow <dan@telent.net>");
348MODULE_DESCRIPTION("Driver for wireless LAN cards using the PLX9052 PCI bridge");
349MODULE_LICENSE("Dual MPL/GPL");
350
351static int __init orinoco_plx_init(void)
352{
353 printk(KERN_DEBUG "%s\n", version);
Jeff Garzik29917622006-08-19 17:48:59 -0400354 return pci_register_driver(&orinoco_plx_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355}
356
357static void __exit orinoco_plx_exit(void)
358{
359 pci_unregister_driver(&orinoco_plx_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360}
361
362module_init(orinoco_plx_init);
363module_exit(orinoco_plx_exit);
364
365/*
366 * Local variables:
367 * c-indent-level: 8
368 * c-basic-offset: 8
369 * tab-width: 8
370 * End:
371 */