orinoco_nortel.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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. if (i == 30) {
  97. printk(KERN_ERR PFX "brg1 timed out\n");
  98. return -EBUSY;
  99. }
  100. if (ioread16(card->attr_io + COR_OFFSET) & 1) {
  101. printk(KERN_ERR PFX "brg2 answer1 wrong\n");
  102. return -EBUSY;
  103. }
  104. if (ioread16(card->attr_io + COR_OFFSET + 2) & 1) {
  105. printk(KERN_ERR PFX "brg2 answer2 wrong\n");
  106. return -EBUSY;
  107. }
  108. if (ioread16(card->attr_io + COR_OFFSET + 4) & 1) {
  109. printk(KERN_ERR PFX "brg2 answer3 wrong\n");
  110. return -EBUSY;
  111. }
  112. /* Set the PCMCIA COR register */
  113. iowrite16(COR_VALUE, card->attr_io + COR_OFFSET);
  114. mdelay(1);
  115. reg = ioread16(card->attr_io + COR_OFFSET);
  116. if (reg != COR_VALUE) {
  117. printk(KERN_ERR PFX "Error setting COR value (reg=%x)\n",
  118. reg);
  119. return -EBUSY;
  120. }
  121. /* Set LEDs */
  122. iowrite16(1, card->bridge_io + 10);
  123. return 0;
  124. }
  125. static int orinoco_nortel_init_one(struct pci_dev *pdev,
  126. const struct pci_device_id *ent)
  127. {
  128. int err;
  129. struct orinoco_private *priv;
  130. struct orinoco_pci_card *card;
  131. struct net_device *dev;
  132. void __iomem *hermes_io, *bridge_io, *attr_io;
  133. err = pci_enable_device(pdev);
  134. if (err) {
  135. printk(KERN_ERR PFX "Cannot enable PCI device\n");
  136. return err;
  137. }
  138. err = pci_request_regions(pdev, DRIVER_NAME);
  139. if (err) {
  140. printk(KERN_ERR PFX "Cannot obtain PCI resources\n");
  141. goto fail_resources;
  142. }
  143. bridge_io = pci_iomap(pdev, 0, 0);
  144. if (!bridge_io) {
  145. printk(KERN_ERR PFX "Cannot map bridge registers\n");
  146. err = -EIO;
  147. goto fail_map_bridge;
  148. }
  149. attr_io = pci_iomap(pdev, 1, 0);
  150. if (!attr_io) {
  151. printk(KERN_ERR PFX "Cannot map PCMCIA attributes\n");
  152. err = -EIO;
  153. goto fail_map_attr;
  154. }
  155. hermes_io = pci_iomap(pdev, 2, 0);
  156. if (!hermes_io) {
  157. printk(KERN_ERR PFX "Cannot map chipset registers\n");
  158. err = -EIO;
  159. goto fail_map_hermes;
  160. }
  161. /* Allocate network device */
  162. dev = alloc_orinocodev(sizeof(*card), &pdev->dev,
  163. orinoco_nortel_cor_reset, NULL);
  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_NETDEV_DEV(dev, &pdev->dev);
  174. hermes_struct_init(&priv->hw, hermes_io, HERMES_16BIT_REGSPACING);
  175. err = request_irq(pdev->irq, orinoco_interrupt, IRQF_SHARED,
  176. dev->name, dev);
  177. if (err) {
  178. printk(KERN_ERR PFX "Cannot allocate IRQ %d\n", pdev->irq);
  179. err = -EBUSY;
  180. goto fail_irq;
  181. }
  182. err = orinoco_nortel_hw_init(card);
  183. if (err) {
  184. printk(KERN_ERR PFX "Hardware initialization failed\n");
  185. goto fail;
  186. }
  187. err = orinoco_nortel_cor_reset(priv);
  188. if (err) {
  189. printk(KERN_ERR PFX "Initial reset failed\n");
  190. goto fail;
  191. }
  192. err = register_netdev(dev);
  193. if (err) {
  194. printk(KERN_ERR PFX "Cannot register network device\n");
  195. goto fail;
  196. }
  197. pci_set_drvdata(pdev, dev);
  198. printk(KERN_DEBUG "%s: " DRIVER_NAME " at %s\n", dev->name,
  199. pci_name(pdev));
  200. return 0;
  201. fail:
  202. free_irq(pdev->irq, dev);
  203. fail_irq:
  204. pci_set_drvdata(pdev, NULL);
  205. free_orinocodev(dev);
  206. fail_alloc:
  207. pci_iounmap(pdev, hermes_io);
  208. fail_map_hermes:
  209. pci_iounmap(pdev, attr_io);
  210. fail_map_attr:
  211. pci_iounmap(pdev, bridge_io);
  212. fail_map_bridge:
  213. pci_release_regions(pdev);
  214. fail_resources:
  215. pci_disable_device(pdev);
  216. return err;
  217. }
  218. static void __devexit orinoco_nortel_remove_one(struct pci_dev *pdev)
  219. {
  220. struct net_device *dev = pci_get_drvdata(pdev);
  221. struct orinoco_private *priv = netdev_priv(dev);
  222. struct orinoco_pci_card *card = priv->card;
  223. /* Clear LEDs */
  224. iowrite16(0, card->bridge_io + 10);
  225. unregister_netdev(dev);
  226. free_irq(pdev->irq, dev);
  227. pci_set_drvdata(pdev, NULL);
  228. free_orinocodev(dev);
  229. pci_iounmap(pdev, priv->hw.iobase);
  230. pci_iounmap(pdev, card->attr_io);
  231. pci_iounmap(pdev, card->bridge_io);
  232. pci_release_regions(pdev);
  233. pci_disable_device(pdev);
  234. }
  235. static struct pci_device_id orinoco_nortel_id_table[] = {
  236. /* Nortel emobility PCI */
  237. {0x126c, 0x8030, PCI_ANY_ID, PCI_ANY_ID,},
  238. /* Symbol LA-4123 PCI */
  239. {0x1562, 0x0001, PCI_ANY_ID, PCI_ANY_ID,},
  240. {0,},
  241. };
  242. MODULE_DEVICE_TABLE(pci, orinoco_nortel_id_table);
  243. static struct pci_driver orinoco_nortel_driver = {
  244. .name = DRIVER_NAME,
  245. .id_table = orinoco_nortel_id_table,
  246. .probe = orinoco_nortel_init_one,
  247. .remove = __devexit_p(orinoco_nortel_remove_one),
  248. .suspend = orinoco_pci_suspend,
  249. .resume = orinoco_pci_resume,
  250. };
  251. static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
  252. " (Tobias Hoffmann & Christoph Jungegger <disdos@traum404.de>)";
  253. MODULE_AUTHOR("Christoph Jungegger <disdos@traum404.de>");
  254. MODULE_DESCRIPTION
  255. ("Driver for wireless LAN cards using the Nortel PCI bridge");
  256. MODULE_LICENSE("Dual MPL/GPL");
  257. static int __init orinoco_nortel_init(void)
  258. {
  259. printk(KERN_DEBUG "%s\n", version);
  260. return pci_register_driver(&orinoco_nortel_driver);
  261. }
  262. static void __exit orinoco_nortel_exit(void)
  263. {
  264. pci_unregister_driver(&orinoco_nortel_driver);
  265. }
  266. module_init(orinoco_nortel_init);
  267. module_exit(orinoco_nortel_exit);
  268. /*
  269. * Local variables:
  270. * c-indent-level: 8
  271. * c-basic-offset: 8
  272. * tab-width: 8
  273. * End:
  274. */