Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* orinoco_pci.c |
| 2 | * |
Pavel Roskin | dc3437d | 2006-04-07 04:11:00 -0400 | [diff] [blame] | 3 | * Driver for Prism 2.5/3 devices that have a direct PCI interface |
| 4 | * (i.e. these are not PCMCIA cards in a PCMCIA-to-PCI bridge). |
| 5 | * The card contains only one PCI region, which contains all the usual |
| 6 | * hermes registers, as well as the COR register. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * |
Pavel Roskin | dc3437d | 2006-04-07 04:11:00 -0400 | [diff] [blame] | 8 | * Current maintainers are: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * Pavel Roskin <proski AT gnu.org> |
| 10 | * and David Gibson <hermes AT gibson.dropbear.id.au> |
| 11 | * |
| 12 | * Some of this code is borrowed from orinoco_plx.c |
| 13 | * Copyright (C) 2001 Daniel Barlow <dan AT telent.net> |
| 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 | * This file originally written by: |
| 18 | * Copyright (C) 2001 Jean Tourrilhes <jt AT hpl.hp.com> |
| 19 | * And is now maintained by: |
| 20 | * (C) Copyright David Gibson, IBM Corp. 2002-2003. |
| 21 | * |
| 22 | * The contents of this file are subject to the Mozilla Public License |
| 23 | * Version 1.1 (the "License"); you may not use this file except in |
| 24 | * compliance with the License. You may obtain a copy of the License |
| 25 | * at http://www.mozilla.org/MPL/ |
| 26 | * |
| 27 | * Software distributed under the License is distributed on an "AS IS" |
| 28 | * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See |
| 29 | * the License for the specific language governing rights and |
| 30 | * limitations under the License. |
| 31 | * |
| 32 | * Alternatively, the contents of this file may be used under the |
| 33 | * terms of the GNU General Public License version 2 (the "GPL"), in |
| 34 | * which case the provisions of the GPL are applicable instead of the |
| 35 | * above. If you wish to allow the use of your version of this file |
| 36 | * only under the terms of the GPL and not to allow others to use your |
| 37 | * version of this file under the MPL, indicate your decision by |
| 38 | * deleting the provisions above and replace them with the notice and |
| 39 | * other provisions required by the GPL. If you do not delete the |
| 40 | * provisions above, a recipient may use your version of this file |
| 41 | * under either the MPL or the GPL. |
| 42 | */ |
| 43 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #define DRIVER_NAME "orinoco_pci" |
| 45 | #define PFX DRIVER_NAME ": " |
| 46 | |
| 47 | #include <linux/config.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | #include <linux/module.h> |
| 49 | #include <linux/kernel.h> |
| 50 | #include <linux/init.h> |
Pavel Roskin | ef846bf | 2005-09-23 04:18:07 -0400 | [diff] [blame] | 51 | #include <linux/delay.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | #include <linux/pci.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | #include "orinoco.h" |
Pavel Roskin | b884c87 | 2006-04-07 04:10:57 -0400 | [diff] [blame] | 55 | #include "orinoco_pci.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | |
Pavel Roskin | dc3437d | 2006-04-07 04:11:00 -0400 | [diff] [blame] | 57 | /* Offset of the COR register of the PCI card */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | #define HERMES_PCI_COR (0x26) |
Pavel Roskin | dc3437d | 2006-04-07 04:11:00 -0400 | [diff] [blame] | 59 | |
| 60 | /* Bitmask to reset the card */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | #define HERMES_PCI_COR_MASK (0x0080) |
Pavel Roskin | dc3437d | 2006-04-07 04:11:00 -0400 | [diff] [blame] | 62 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | /* Magic timeouts for doing the reset. |
| 64 | * Those times are straight from wlan-ng, and it is claimed that they |
| 65 | * are necessary. Alan will kill me. Take your time and grab a coffee. */ |
| 66 | #define HERMES_PCI_COR_ONT (250) /* ms */ |
| 67 | #define HERMES_PCI_COR_OFFT (500) /* ms */ |
| 68 | #define HERMES_PCI_COR_BUSYT (500) /* ms */ |
| 69 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | /* |
Pavel Roskin | dc3437d | 2006-04-07 04:11:00 -0400 | [diff] [blame] | 71 | * Do a soft reset of the card using the Configuration Option Register |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | * We need this to get going... |
| 73 | * This is the part of the code that is strongly inspired from wlan-ng |
| 74 | * |
| 75 | * Note : This code is done with irq enabled. This mean that many |
| 76 | * interrupts will occur while we are there. This is why we use the |
| 77 | * jiffies to regulate time instead of a straight mdelay(). Usually we |
| 78 | * need only around 245 iteration of the loop to do 250 ms delay. |
| 79 | * |
| 80 | * Note bis : Don't try to access HERMES_CMD during the reset phase. |
| 81 | * It just won't work ! |
| 82 | */ |
Pavel Roskin | b884c87 | 2006-04-07 04:10:57 -0400 | [diff] [blame] | 83 | static int orinoco_pci_cor_reset(struct orinoco_private *priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | { |
| 85 | hermes_t *hw = &priv->hw; |
Pavel Roskin | b884c87 | 2006-04-07 04:10:57 -0400 | [diff] [blame] | 86 | unsigned long timeout; |
| 87 | u16 reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
Pavel Roskin | dc3437d | 2006-04-07 04:11:00 -0400 | [diff] [blame] | 89 | /* Assert the reset until the card notices */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | hermes_write_regn(hw, PCI_COR, HERMES_PCI_COR_MASK); |
| 91 | mdelay(HERMES_PCI_COR_ONT); |
| 92 | |
| 93 | /* Give time for the card to recover from this hard effort */ |
| 94 | hermes_write_regn(hw, PCI_COR, 0x0000); |
| 95 | mdelay(HERMES_PCI_COR_OFFT); |
| 96 | |
| 97 | /* The card is ready when it's no longer busy */ |
| 98 | timeout = jiffies + (HERMES_PCI_COR_BUSYT * HZ / 1000); |
| 99 | reg = hermes_read_regn(hw, CMD); |
| 100 | while (time_before(jiffies, timeout) && (reg & HERMES_CMD_BUSY)) { |
| 101 | mdelay(1); |
| 102 | reg = hermes_read_regn(hw, CMD); |
| 103 | } |
| 104 | |
| 105 | /* Still busy? */ |
| 106 | if (reg & HERMES_CMD_BUSY) { |
| 107 | printk(KERN_ERR PFX "Busy timeout\n"); |
| 108 | return -ETIMEDOUT; |
| 109 | } |
| 110 | |
| 111 | return 0; |
| 112 | } |
| 113 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | static int orinoco_pci_init_one(struct pci_dev *pdev, |
| 115 | const struct pci_device_id *ent) |
| 116 | { |
Pavel Roskin | b884c87 | 2006-04-07 04:10:57 -0400 | [diff] [blame] | 117 | int err; |
| 118 | struct orinoco_private *priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | struct orinoco_pci_card *card; |
Pavel Roskin | b884c87 | 2006-04-07 04:10:57 -0400 | [diff] [blame] | 120 | struct net_device *dev; |
| 121 | void __iomem *hermes_io; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | |
| 123 | err = pci_enable_device(pdev); |
| 124 | if (err) { |
| 125 | printk(KERN_ERR PFX "Cannot enable PCI device\n"); |
| 126 | return err; |
| 127 | } |
| 128 | |
| 129 | err = pci_request_regions(pdev, DRIVER_NAME); |
Pavel Roskin | b884c87 | 2006-04-07 04:10:57 -0400 | [diff] [blame] | 130 | if (err) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | printk(KERN_ERR PFX "Cannot obtain PCI resources\n"); |
| 132 | goto fail_resources; |
| 133 | } |
| 134 | |
Pavel Roskin | b884c87 | 2006-04-07 04:10:57 -0400 | [diff] [blame] | 135 | hermes_io = pci_iomap(pdev, 0, 0); |
| 136 | if (!hermes_io) { |
| 137 | printk(KERN_ERR PFX "Cannot remap chipset registers\n"); |
Pavel Roskin | 3d52996 | 2006-04-07 04:10:53 -0400 | [diff] [blame] | 138 | err = -EIO; |
Pavel Roskin | b884c87 | 2006-04-07 04:10:57 -0400 | [diff] [blame] | 139 | goto fail_map_hermes; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | /* Allocate network device */ |
| 143 | dev = alloc_orinocodev(sizeof(*card), orinoco_pci_cor_reset); |
Pavel Roskin | b884c87 | 2006-04-07 04:10:57 -0400 | [diff] [blame] | 144 | if (!dev) { |
| 145 | printk(KERN_ERR PFX "Cannot allocate network device\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | err = -ENOMEM; |
| 147 | goto fail_alloc; |
| 148 | } |
| 149 | |
| 150 | priv = netdev_priv(dev); |
| 151 | card = priv->card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | SET_MODULE_OWNER(dev); |
| 153 | SET_NETDEV_DEV(dev, &pdev->dev); |
| 154 | |
Pavel Roskin | b884c87 | 2006-04-07 04:10:57 -0400 | [diff] [blame] | 155 | hermes_struct_init(&priv->hw, hermes_io, HERMES_32BIT_REGSPACING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | |
| 157 | err = request_irq(pdev->irq, orinoco_interrupt, SA_SHIRQ, |
| 158 | dev->name, dev); |
| 159 | if (err) { |
| 160 | printk(KERN_ERR PFX "Cannot allocate IRQ %d\n", pdev->irq); |
| 161 | err = -EBUSY; |
| 162 | goto fail_irq; |
| 163 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | err = orinoco_pci_cor_reset(priv); |
| 166 | if (err) { |
| 167 | printk(KERN_ERR PFX "Initial reset failed\n"); |
| 168 | goto fail; |
| 169 | } |
| 170 | |
| 171 | err = register_netdev(dev); |
| 172 | if (err) { |
Pavel Roskin | b884c87 | 2006-04-07 04:10:57 -0400 | [diff] [blame] | 173 | printk(KERN_ERR PFX "Cannot register network device\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | goto fail; |
| 175 | } |
| 176 | |
| 177 | pci_set_drvdata(pdev, dev); |
Pavel Roskin | 461c078 | 2006-05-01 02:13:33 -0400 | [diff] [blame^] | 178 | printk(KERN_DEBUG "%s: " DRIVER_NAME " at %s\n", dev->name, |
| 179 | pci_name(pdev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | |
| 181 | return 0; |
| 182 | |
| 183 | fail: |
| 184 | free_irq(pdev->irq, dev); |
| 185 | |
| 186 | fail_irq: |
| 187 | pci_set_drvdata(pdev, NULL); |
| 188 | free_orinocodev(dev); |
| 189 | |
| 190 | fail_alloc: |
Pavel Roskin | b884c87 | 2006-04-07 04:10:57 -0400 | [diff] [blame] | 191 | pci_iounmap(pdev, hermes_io); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | |
Pavel Roskin | b884c87 | 2006-04-07 04:10:57 -0400 | [diff] [blame] | 193 | fail_map_hermes: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | pci_release_regions(pdev); |
| 195 | |
| 196 | fail_resources: |
| 197 | pci_disable_device(pdev); |
| 198 | |
| 199 | return err; |
| 200 | } |
| 201 | |
| 202 | static void __devexit orinoco_pci_remove_one(struct pci_dev *pdev) |
| 203 | { |
| 204 | struct net_device *dev = pci_get_drvdata(pdev); |
| 205 | struct orinoco_private *priv = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | |
| 207 | unregister_netdev(dev); |
Pavel Roskin | 461c078 | 2006-05-01 02:13:33 -0400 | [diff] [blame^] | 208 | free_irq(pdev->irq, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | pci_set_drvdata(pdev, NULL); |
| 210 | free_orinocodev(dev); |
Pavel Roskin | b884c87 | 2006-04-07 04:10:57 -0400 | [diff] [blame] | 211 | pci_iounmap(pdev, priv->hw.iobase); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | pci_release_regions(pdev); |
| 213 | pci_disable_device(pdev); |
| 214 | } |
| 215 | |
Pavel Roskin | b884c87 | 2006-04-07 04:10:57 -0400 | [diff] [blame] | 216 | static struct pci_device_id orinoco_pci_id_table[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | /* Intersil Prism 3 */ |
| 218 | {0x1260, 0x3872, PCI_ANY_ID, PCI_ANY_ID,}, |
| 219 | /* Intersil Prism 2.5 */ |
| 220 | {0x1260, 0x3873, PCI_ANY_ID, PCI_ANY_ID,}, |
| 221 | /* Samsung MagicLAN SWL-2210P */ |
| 222 | {0x167d, 0xa000, PCI_ANY_ID, PCI_ANY_ID,}, |
| 223 | {0,}, |
| 224 | }; |
| 225 | |
Pavel Roskin | b884c87 | 2006-04-07 04:10:57 -0400 | [diff] [blame] | 226 | MODULE_DEVICE_TABLE(pci, orinoco_pci_id_table); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | |
| 228 | static struct pci_driver orinoco_pci_driver = { |
| 229 | .name = DRIVER_NAME, |
Pavel Roskin | b884c87 | 2006-04-07 04:10:57 -0400 | [diff] [blame] | 230 | .id_table = orinoco_pci_id_table, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | .probe = orinoco_pci_init_one, |
| 232 | .remove = __devexit_p(orinoco_pci_remove_one), |
| 233 | .suspend = orinoco_pci_suspend, |
| 234 | .resume = orinoco_pci_resume, |
| 235 | }; |
| 236 | |
| 237 | static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION |
| 238 | " (Pavel Roskin <proski@gnu.org>," |
| 239 | " David Gibson <hermes@gibson.dropbear.id.au> &" |
| 240 | " Jean Tourrilhes <jt@hpl.hp.com>)"; |
| 241 | MODULE_AUTHOR("Pavel Roskin <proski@gnu.org> & David Gibson <hermes@gibson.dropbear.id.au>"); |
| 242 | MODULE_DESCRIPTION("Driver for wireless LAN cards using direct PCI interface"); |
| 243 | MODULE_LICENSE("Dual MPL/GPL"); |
| 244 | |
| 245 | static int __init orinoco_pci_init(void) |
| 246 | { |
| 247 | printk(KERN_DEBUG "%s\n", version); |
| 248 | return pci_module_init(&orinoco_pci_driver); |
| 249 | } |
| 250 | |
| 251 | static void __exit orinoco_pci_exit(void) |
| 252 | { |
| 253 | pci_unregister_driver(&orinoco_pci_driver); |
| 254 | } |
| 255 | |
| 256 | module_init(orinoco_pci_init); |
| 257 | module_exit(orinoco_pci_exit); |
| 258 | |
| 259 | /* |
| 260 | * Local variables: |
| 261 | * c-indent-level: 8 |
| 262 | * c-basic-offset: 8 |
| 263 | * tab-width: 8 |
| 264 | * End: |
| 265 | */ |