orinoco_nortel.c 8.4 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/config.h>
  42. #include <linux/module.h>
  43. #include <linux/kernel.h>
  44. #include <linux/init.h>
  45. #include <linux/delay.h>
  46. #include <linux/pci.h>
  47. #include <pcmcia/cisreg.h>
  48. #include "orinoco.h"
  49. #include "orinoco_pci.h"
  50. #define COR_OFFSET (0xe0) /* COR attribute offset of Prism2 PC card */
  51. #define COR_VALUE (COR_LEVEL_REQ | COR_FUNC_ENA) /* Enable PC card with interrupt in level trigger */
  52. /*
  53. * Do a soft reset of the card using the Configuration Option Register
  54. * We need this to get going...
  55. * This is the part of the code that is strongly inspired from wlan-ng
  56. *
  57. * Note bis : Don't try to access HERMES_CMD during the reset phase.
  58. * It just won't work !
  59. */
  60. static int orinoco_nortel_cor_reset(struct orinoco_private *priv)
  61. {
  62. struct orinoco_pci_card *card = priv->card;
  63. /* Assert the reset until the card notices */
  64. iowrite16(8, card->bridge_io + 2);
  65. ioread16(card->attr_io + COR_OFFSET);
  66. iowrite16(0x80, card->attr_io + COR_OFFSET);
  67. mdelay(1);
  68. /* Give time for the card to recover from this hard effort */
  69. iowrite16(0, card->attr_io + COR_OFFSET);
  70. iowrite16(0, card->attr_io + COR_OFFSET);
  71. mdelay(1);
  72. /* Set COR as usual */
  73. iowrite16(COR_VALUE, card->attr_io + COR_OFFSET);
  74. iowrite16(COR_VALUE, card->attr_io + COR_OFFSET);
  75. mdelay(1);
  76. iowrite16(0x228, card->bridge_io + 2);
  77. return 0;
  78. }
  79. static int orinoco_nortel_hw_init(struct orinoco_pci_card *card)
  80. {
  81. int i;
  82. u32 reg;
  83. /* Setup bridge */
  84. if (ioread16(card->bridge_io) & 1) {
  85. printk(KERN_ERR PFX "brg1 answer1 wrong\n");
  86. return -EBUSY;
  87. }
  88. iowrite16(0x118, card->bridge_io + 2);
  89. iowrite16(0x108, card->bridge_io + 2);
  90. mdelay(30);
  91. iowrite16(0x8, card->bridge_io + 2);
  92. for (i = 0; i < 30; i++) {
  93. mdelay(30);
  94. if (ioread16(card->bridge_io) & 0x10) {
  95. break;
  96. }
  97. }
  98. if (i == 30) {
  99. printk(KERN_ERR PFX "brg1 timed out\n");
  100. return -EBUSY;
  101. }
  102. if (ioread16(card->attr_io + COR_OFFSET) & 1) {
  103. printk(KERN_ERR PFX "brg2 answer1 wrong\n");
  104. return -EBUSY;
  105. }
  106. if (ioread16(card->attr_io + COR_OFFSET + 2) & 1) {
  107. printk(KERN_ERR PFX "brg2 answer2 wrong\n");
  108. return -EBUSY;
  109. }
  110. if (ioread16(card->attr_io + COR_OFFSET + 4) & 1) {
  111. printk(KERN_ERR PFX "brg2 answer3 wrong\n");
  112. return -EBUSY;
  113. }
  114. /* Set the PCMCIA COR register */
  115. iowrite16(COR_VALUE, card->attr_io + COR_OFFSET);
  116. mdelay(1);
  117. reg = ioread16(card->attr_io + COR_OFFSET);
  118. if (reg != COR_VALUE) {
  119. printk(KERN_ERR PFX "Error setting COR value (reg=%x)\n",
  120. reg);
  121. return -EBUSY;
  122. }
  123. /* Set LEDs */
  124. iowrite16(1, card->bridge_io + 10);
  125. return 0;
  126. }
  127. static int orinoco_nortel_init_one(struct pci_dev *pdev,
  128. const struct pci_device_id *ent)
  129. {
  130. int err;
  131. struct orinoco_private *priv;
  132. struct orinoco_pci_card *card;
  133. struct net_device *dev;
  134. void __iomem *hermes_io, *bridge_io, *attr_io;
  135. err = pci_enable_device(pdev);
  136. if (err) {
  137. printk(KERN_ERR PFX "Cannot enable PCI device\n");
  138. return err;
  139. }
  140. err = pci_request_regions(pdev, DRIVER_NAME);
  141. if (err) {
  142. printk(KERN_ERR PFX "Cannot obtain PCI resources\n");
  143. goto fail_resources;
  144. }
  145. bridge_io = pci_iomap(pdev, 0, 0);
  146. if (!bridge_io) {
  147. printk(KERN_ERR PFX "Cannot map bridge registers\n");
  148. err = -EIO;
  149. goto fail_map_bridge;
  150. }
  151. attr_io = pci_iomap(pdev, 1, 0);
  152. if (!attr_io) {
  153. printk(KERN_ERR PFX "Cannot map PCMCIA attributes\n");
  154. err = -EIO;
  155. goto fail_map_attr;
  156. }
  157. hermes_io = pci_iomap(pdev, 2, 0);
  158. if (!hermes_io) {
  159. printk(KERN_ERR PFX "Cannot map chipset registers\n");
  160. err = -EIO;
  161. goto fail_map_hermes;
  162. }
  163. /* Allocate network device */
  164. dev = alloc_orinocodev(sizeof(*card), orinoco_nortel_cor_reset);
  165. if (!dev) {
  166. printk(KERN_ERR PFX "Cannot allocate network device\n");
  167. err = -ENOMEM;
  168. goto fail_alloc;
  169. }
  170. priv = netdev_priv(dev);
  171. card = priv->card;
  172. card->bridge_io = bridge_io;
  173. card->attr_io = attr_io;
  174. SET_MODULE_OWNER(dev);
  175. SET_NETDEV_DEV(dev, &pdev->dev);
  176. hermes_struct_init(&priv->hw, hermes_io, HERMES_16BIT_REGSPACING);
  177. err = request_irq(pdev->irq, orinoco_interrupt, SA_SHIRQ,
  178. dev->name, dev);
  179. if (err) {
  180. printk(KERN_ERR PFX "Cannot allocate IRQ %d\n", pdev->irq);
  181. err = -EBUSY;
  182. goto fail_irq;
  183. }
  184. orinoco_pci_setup_netdev(dev, pdev, 2);
  185. err = orinoco_nortel_hw_init(card);
  186. if (err) {
  187. printk(KERN_ERR PFX "Hardware initialization failed\n");
  188. goto fail;
  189. }
  190. err = orinoco_nortel_cor_reset(priv);
  191. if (err) {
  192. printk(KERN_ERR PFX "Initial reset failed\n");
  193. goto fail;
  194. }
  195. err = register_netdev(dev);
  196. if (err) {
  197. printk(KERN_ERR PFX "Cannot register network device\n");
  198. goto fail;
  199. }
  200. pci_set_drvdata(pdev, dev);
  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(dev->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_module_init(&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. */