orinoco_nortel.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. /* orinoco_nortel.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 PCI-to-PCMCIA adapter used in
  5. * Nortel emobility, Symbol LA-4113 and Symbol LA-4123.
  6. *
  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. #define DRIVER_NAME "orinoco_nortel"
  40. #define PFX DRIVER_NAME ": "
  41. #include <linux/module.h>
  42. #include <linux/kernel.h>
  43. #include <linux/init.h>
  44. #include <linux/delay.h>
  45. #include <linux/pci.h>
  46. #include <pcmcia/cisreg.h>
  47. #include "orinoco.h"
  48. #include "orinoco_pci.h"
  49. #define COR_OFFSET (0xe0) /* COR attribute offset of Prism2 PC card */
  50. #define COR_VALUE (COR_LEVEL_REQ | COR_FUNC_ENA) /* Enable PC card with interrupt in level trigger */
  51. /*
  52. * Do a soft reset of the card using the Configuration Option Register
  53. * We need this to get going...
  54. * This is the part of the code that is strongly inspired from wlan-ng
  55. *
  56. * Note bis : Don't try to access HERMES_CMD during the reset phase.
  57. * It just won't work !
  58. */
  59. static int orinoco_nortel_cor_reset(struct orinoco_private *priv)
  60. {
  61. struct orinoco_pci_card *card = priv->card;
  62. /* Assert the reset until the card notices */
  63. iowrite16(8, card->bridge_io + 2);
  64. ioread16(card->attr_io + COR_OFFSET);
  65. iowrite16(0x80, card->attr_io + COR_OFFSET);
  66. mdelay(1);
  67. /* Give time for the card to recover from this hard effort */
  68. iowrite16(0, card->attr_io + COR_OFFSET);
  69. iowrite16(0, card->attr_io + COR_OFFSET);
  70. mdelay(1);
  71. /* Set COR as usual */
  72. iowrite16(COR_VALUE, card->attr_io + COR_OFFSET);
  73. iowrite16(COR_VALUE, card->attr_io + COR_OFFSET);
  74. mdelay(1);
  75. iowrite16(0x228, card->bridge_io + 2);
  76. return 0;
  77. }
  78. static int orinoco_nortel_hw_init(struct orinoco_pci_card *card)
  79. {
  80. int i;
  81. u32 reg;
  82. /* Setup bridge */
  83. if (ioread16(card->bridge_io) & 1) {
  84. printk(KERN_ERR PFX "brg1 answer1 wrong\n");
  85. return -EBUSY;
  86. }
  87. iowrite16(0x118, card->bridge_io + 2);
  88. iowrite16(0x108, card->bridge_io + 2);
  89. mdelay(30);
  90. iowrite16(0x8, card->bridge_io + 2);
  91. for (i = 0; i < 30; i++) {
  92. mdelay(30);
  93. if (ioread16(card->bridge_io) & 0x10) {
  94. break;
  95. }
  96. }
  97. if (i == 30) {
  98. printk(KERN_ERR PFX "brg1 timed out\n");
  99. return -EBUSY;
  100. }
  101. if (ioread16(card->attr_io + COR_OFFSET) & 1) {
  102. printk(KERN_ERR PFX "brg2 answer1 wrong\n");
  103. return -EBUSY;
  104. }
  105. if (ioread16(card->attr_io + COR_OFFSET + 2) & 1) {
  106. printk(KERN_ERR PFX "brg2 answer2 wrong\n");
  107. return -EBUSY;
  108. }
  109. if (ioread16(card->attr_io + COR_OFFSET + 4) & 1) {
  110. printk(KERN_ERR PFX "brg2 answer3 wrong\n");
  111. return -EBUSY;
  112. }
  113. /* Set the PCMCIA COR register */
  114. iowrite16(COR_VALUE, card->attr_io + COR_OFFSET);
  115. mdelay(1);
  116. reg = ioread16(card->attr_io + COR_OFFSET);
  117. if (reg != COR_VALUE) {
  118. printk(KERN_ERR PFX "Error setting COR value (reg=%x)\n",
  119. reg);
  120. return -EBUSY;
  121. }
  122. /* Set LEDs */
  123. iowrite16(1, card->bridge_io + 10);
  124. return 0;
  125. }
  126. static int orinoco_nortel_init_one(struct pci_dev *pdev,
  127. const struct pci_device_id *ent)
  128. {
  129. int err;
  130. struct orinoco_private *priv;
  131. struct orinoco_pci_card *card;
  132. struct net_device *dev;
  133. void __iomem *hermes_io, *bridge_io, *attr_io;
  134. err = pci_enable_device(pdev);
  135. if (err) {
  136. printk(KERN_ERR PFX "Cannot enable PCI device\n");
  137. return err;
  138. }
  139. err = pci_request_regions(pdev, DRIVER_NAME);
  140. if (err) {
  141. printk(KERN_ERR PFX "Cannot obtain PCI resources\n");
  142. goto fail_resources;
  143. }
  144. bridge_io = pci_iomap(pdev, 0, 0);
  145. if (!bridge_io) {
  146. printk(KERN_ERR PFX "Cannot map bridge registers\n");
  147. err = -EIO;
  148. goto fail_map_bridge;
  149. }
  150. attr_io = pci_iomap(pdev, 1, 0);
  151. if (!attr_io) {
  152. printk(KERN_ERR PFX "Cannot map PCMCIA attributes\n");
  153. err = -EIO;
  154. goto fail_map_attr;
  155. }
  156. hermes_io = pci_iomap(pdev, 2, 0);
  157. if (!hermes_io) {
  158. printk(KERN_ERR PFX "Cannot map chipset registers\n");
  159. err = -EIO;
  160. goto fail_map_hermes;
  161. }
  162. /* Allocate network device */
  163. dev = alloc_orinocodev(sizeof(*card), orinoco_nortel_cor_reset);
  164. if (!dev) {
  165. printk(KERN_ERR PFX "Cannot allocate network device\n");
  166. err = -ENOMEM;
  167. goto fail_alloc;
  168. }
  169. priv = netdev_priv(dev);
  170. card = priv->card;
  171. card->bridge_io = bridge_io;
  172. card->attr_io = attr_io;
  173. SET_MODULE_OWNER(dev);
  174. SET_NETDEV_DEV(dev, &pdev->dev);
  175. hermes_struct_init(&priv->hw, hermes_io, HERMES_16BIT_REGSPACING);
  176. err = request_irq(pdev->irq, orinoco_interrupt, IRQF_SHARED,
  177. dev->name, dev);
  178. if (err) {
  179. printk(KERN_ERR PFX "Cannot allocate IRQ %d\n", pdev->irq);
  180. err = -EBUSY;
  181. goto fail_irq;
  182. }
  183. err = orinoco_nortel_hw_init(card);
  184. if (err) {
  185. printk(KERN_ERR PFX "Hardware initialization failed\n");
  186. goto fail;
  187. }
  188. err = orinoco_nortel_cor_reset(priv);
  189. if (err) {
  190. printk(KERN_ERR PFX "Initial reset failed\n");
  191. goto fail;
  192. }
  193. err = register_netdev(dev);
  194. if (err) {
  195. printk(KERN_ERR PFX "Cannot register network device\n");
  196. goto fail;
  197. }
  198. pci_set_drvdata(pdev, dev);
  199. printk(KERN_DEBUG "%s: " DRIVER_NAME " at %s\n", dev->name,
  200. pci_name(pdev));
  201. return 0;
  202. fail:
  203. free_irq(pdev->irq, dev);
  204. fail_irq:
  205. pci_set_drvdata(pdev, NULL);
  206. free_orinocodev(dev);
  207. fail_alloc:
  208. pci_iounmap(pdev, hermes_io);
  209. fail_map_hermes:
  210. pci_iounmap(pdev, attr_io);
  211. fail_map_attr:
  212. pci_iounmap(pdev, bridge_io);
  213. fail_map_bridge:
  214. pci_release_regions(pdev);
  215. fail_resources:
  216. pci_disable_device(pdev);
  217. return err;
  218. }
  219. static void __devexit orinoco_nortel_remove_one(struct pci_dev *pdev)
  220. {
  221. struct net_device *dev = pci_get_drvdata(pdev);
  222. struct orinoco_private *priv = netdev_priv(dev);
  223. struct orinoco_pci_card *card = priv->card;
  224. /* Clear LEDs */
  225. iowrite16(0, card->bridge_io + 10);
  226. unregister_netdev(dev);
  227. free_irq(pdev->irq, dev);
  228. pci_set_drvdata(pdev, NULL);
  229. free_orinocodev(dev);
  230. pci_iounmap(pdev, priv->hw.iobase);
  231. pci_iounmap(pdev, card->attr_io);
  232. pci_iounmap(pdev, card->bridge_io);
  233. pci_release_regions(pdev);
  234. pci_disable_device(pdev);
  235. }
  236. static struct pci_device_id orinoco_nortel_id_table[] = {
  237. /* Nortel emobility PCI */
  238. {0x126c, 0x8030, PCI_ANY_ID, PCI_ANY_ID,},
  239. /* Symbol LA-4123 PCI */
  240. {0x1562, 0x0001, PCI_ANY_ID, PCI_ANY_ID,},
  241. {0,},
  242. };
  243. MODULE_DEVICE_TABLE(pci, orinoco_nortel_id_table);
  244. static struct pci_driver orinoco_nortel_driver = {
  245. .name = DRIVER_NAME,
  246. .id_table = orinoco_nortel_id_table,
  247. .probe = orinoco_nortel_init_one,
  248. .remove = __devexit_p(orinoco_nortel_remove_one),
  249. .suspend = orinoco_pci_suspend,
  250. .resume = orinoco_pci_resume,
  251. };
  252. static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
  253. " (Tobias Hoffmann & Christoph Jungegger <disdos@traum404.de>)";
  254. MODULE_AUTHOR("Christoph Jungegger <disdos@traum404.de>");
  255. MODULE_DESCRIPTION
  256. ("Driver for wireless LAN cards using the Nortel PCI bridge");
  257. MODULE_LICENSE("Dual MPL/GPL");
  258. static int __init orinoco_nortel_init(void)
  259. {
  260. printk(KERN_DEBUG "%s\n", version);
  261. return pci_register_driver(&orinoco_nortel_driver);
  262. }
  263. static void __exit orinoco_nortel_exit(void)
  264. {
  265. pci_unregister_driver(&orinoco_nortel_driver);
  266. }
  267. module_init(orinoco_nortel_init);
  268. module_exit(orinoco_nortel_exit);
  269. /*
  270. * Local variables:
  271. * c-indent-level: 8
  272. * c-basic-offset: 8
  273. * tab-width: 8
  274. * End:
  275. */