orinoco_nortel.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  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. * but are connected to the PCI bus by a Nortel PCI-PCMCIA-Adapter.
  7. *
  8. * Copyright (C) 2002 Tobias Hoffmann
  9. * (C) 2003 Christoph Jungegger <disdos@traum404.de>
  10. *
  11. * Some of this code is borrowed from orinoco_plx.c
  12. * Copyright (C) 2001 Daniel Barlow
  13. * Some of this code is borrowed from orinoco_pci.c
  14. * Copyright (C) 2001 Jean Tourrilhes
  15. * Some of this code is "inspired" by linux-wlan-ng-0.1.10, but nothing
  16. * has been copied from it. linux-wlan-ng-0.1.10 is originally :
  17. * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved.
  18. *
  19. * The contents of this file are subject to the Mozilla Public License
  20. * Version 1.1 (the "License"); you may not use this file except in
  21. * compliance with the License. You may obtain a copy of the License
  22. * at http://www.mozilla.org/MPL/
  23. *
  24. * Software distributed under the License is distributed on an "AS IS"
  25. * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
  26. * the License for the specific language governing rights and
  27. * limitations under the License.
  28. *
  29. * Alternatively, the contents of this file may be used under the
  30. * terms of the GNU General Public License version 2 (the "GPL"), in
  31. * which case the provisions of the GPL are applicable instead of the
  32. * above. If you wish to allow the use of your version of this file
  33. * only under the terms of the GPL and not to allow others to use your
  34. * version of this file under the MPL, indicate your decision by
  35. * deleting the provisions above and replace them with the notice and
  36. * other provisions required by the GPL. If you do not delete the
  37. * provisions above, a recipient may use your version of this file
  38. * under either the MPL or the GPL.
  39. */
  40. #define DRIVER_NAME "orinoco_nortel"
  41. #define PFX DRIVER_NAME ": "
  42. #include <linux/config.h>
  43. #include <linux/module.h>
  44. #include <linux/kernel.h>
  45. #include <linux/init.h>
  46. #include <linux/delay.h>
  47. #include <linux/pci.h>
  48. #include <pcmcia/cisreg.h>
  49. #include "orinoco.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. /* Nortel specific data */
  53. struct nortel_pci_card {
  54. unsigned long iobase1;
  55. unsigned long iobase2;
  56. };
  57. /*
  58. * Do a soft reset of the PCI card using the Configuration Option Register
  59. * We need this to get going...
  60. * This is the part of the code that is strongly inspired from wlan-ng
  61. *
  62. * Note bis : Don't try to access HERMES_CMD during the reset phase.
  63. * It just won't work !
  64. */
  65. static int nortel_pci_cor_reset(struct orinoco_private *priv)
  66. {
  67. struct nortel_pci_card *card = priv->card;
  68. /* Assert the reset until the card notice */
  69. outw_p(8, card->iobase1 + 2);
  70. inw(card->iobase2 + COR_OFFSET);
  71. outw_p(0x80, card->iobase2 + COR_OFFSET);
  72. mdelay(1);
  73. /* Give time for the card to recover from this hard effort */
  74. outw_p(0, card->iobase2 + COR_OFFSET);
  75. outw_p(0, card->iobase2 + COR_OFFSET);
  76. mdelay(1);
  77. /* set COR as usual */
  78. outw_p(COR_VALUE, card->iobase2 + COR_OFFSET);
  79. outw_p(COR_VALUE, card->iobase2 + COR_OFFSET);
  80. mdelay(1);
  81. outw_p(0x228, card->iobase1 + 2);
  82. return 0;
  83. }
  84. static int nortel_pci_hw_init(struct nortel_pci_card *card)
  85. {
  86. int i;
  87. u32 reg;
  88. /* setup bridge */
  89. if (inw(card->iobase1) & 1) {
  90. printk(KERN_ERR PFX "brg1 answer1 wrong\n");
  91. return -EBUSY;
  92. }
  93. outw_p(0x118, card->iobase1 + 2);
  94. outw_p(0x108, card->iobase1 + 2);
  95. mdelay(30);
  96. outw_p(0x8, card->iobase1 + 2);
  97. for (i = 0; i < 30; i++) {
  98. mdelay(30);
  99. if (inw(card->iobase1) & 0x10) {
  100. break;
  101. }
  102. }
  103. if (i == 30) {
  104. printk(KERN_ERR PFX "brg1 timed out\n");
  105. return -EBUSY;
  106. }
  107. if (inw(card->iobase2 + 0xe0) & 1) {
  108. printk(KERN_ERR PFX "brg2 answer1 wrong\n");
  109. return -EBUSY;
  110. }
  111. if (inw(card->iobase2 + 0xe2) & 1) {
  112. printk(KERN_ERR PFX "brg2 answer2 wrong\n");
  113. return -EBUSY;
  114. }
  115. if (inw(card->iobase2 + 0xe4) & 1) {
  116. printk(KERN_ERR PFX "brg2 answer3 wrong\n");
  117. return -EBUSY;
  118. }
  119. /* set the PCMCIA COR-Register */
  120. outw_p(COR_VALUE, card->iobase2 + COR_OFFSET);
  121. mdelay(1);
  122. reg = inw(card->iobase2 + COR_OFFSET);
  123. if (reg != COR_VALUE) {
  124. printk(KERN_ERR PFX "Error setting COR value (reg=%x)\n",
  125. reg);
  126. return -EBUSY;
  127. }
  128. /* set leds */
  129. outw_p(1, card->iobase1 + 10);
  130. return 0;
  131. }
  132. static int nortel_pci_init_one(struct pci_dev *pdev,
  133. const struct pci_device_id *ent)
  134. {
  135. int err;
  136. struct orinoco_private *priv;
  137. struct nortel_pci_card *card;
  138. struct net_device *dev;
  139. void __iomem *iomem;
  140. err = pci_enable_device(pdev);
  141. if (err) {
  142. printk(KERN_ERR PFX "Cannot enable PCI device\n");
  143. return err;
  144. }
  145. err = pci_request_regions(pdev, DRIVER_NAME);
  146. if (err != 0) {
  147. printk(KERN_ERR PFX "Cannot obtain PCI resources\n");
  148. goto fail_resources;
  149. }
  150. iomem = pci_iomap(pdev, 2, 0);
  151. if (!iomem) {
  152. err = -ENOMEM;
  153. goto fail_map_io;
  154. }
  155. /* Allocate network device */
  156. dev = alloc_orinocodev(sizeof(*card), nortel_pci_cor_reset);
  157. if (!dev) {
  158. printk(KERN_ERR PFX "Cannot allocate network device\n");
  159. err = -ENOMEM;
  160. goto fail_alloc;
  161. }
  162. priv = netdev_priv(dev);
  163. card = priv->card;
  164. card->iobase1 = pci_resource_start(pdev, 0);
  165. card->iobase2 = pci_resource_start(pdev, 1);
  166. dev->base_addr = pci_resource_start(pdev, 2);
  167. SET_MODULE_OWNER(dev);
  168. SET_NETDEV_DEV(dev, &pdev->dev);
  169. hermes_struct_init(&priv->hw, iomem, HERMES_16BIT_REGSPACING);
  170. printk(KERN_DEBUG PFX "Detected Nortel PCI device at %s irq:%d, "
  171. "io addr:0x%lx\n", pci_name(pdev), pdev->irq, dev->base_addr);
  172. err = request_irq(pdev->irq, orinoco_interrupt, SA_SHIRQ,
  173. dev->name, dev);
  174. if (err) {
  175. printk(KERN_ERR PFX "Cannot allocate IRQ %d\n", pdev->irq);
  176. err = -EBUSY;
  177. goto fail_irq;
  178. }
  179. dev->irq = pdev->irq;
  180. err = nortel_pci_hw_init(card);
  181. if (err) {
  182. printk(KERN_ERR PFX "Hardware initialization failed\n");
  183. goto fail;
  184. }
  185. err = nortel_pci_cor_reset(priv);
  186. if (err) {
  187. printk(KERN_ERR PFX "Initial reset failed\n");
  188. goto fail;
  189. }
  190. err = register_netdev(dev);
  191. if (err) {
  192. printk(KERN_ERR PFX "Cannot register network device\n");
  193. goto fail;
  194. }
  195. pci_set_drvdata(pdev, dev);
  196. return 0;
  197. fail:
  198. free_irq(pdev->irq, dev);
  199. fail_irq:
  200. pci_set_drvdata(pdev, NULL);
  201. free_orinocodev(dev);
  202. fail_alloc:
  203. pci_iounmap(pdev, iomem);
  204. fail_map_io:
  205. pci_release_regions(pdev);
  206. fail_resources:
  207. pci_disable_device(pdev);
  208. return err;
  209. }
  210. static void __devexit nortel_pci_remove_one(struct pci_dev *pdev)
  211. {
  212. struct net_device *dev = pci_get_drvdata(pdev);
  213. struct orinoco_private *priv = netdev_priv(dev);
  214. struct nortel_pci_card *card = priv->card;
  215. /* clear leds */
  216. outw_p(0, card->iobase1 + 10);
  217. unregister_netdev(dev);
  218. free_irq(dev->irq, dev);
  219. pci_set_drvdata(pdev, NULL);
  220. free_orinocodev(dev);
  221. pci_iounmap(pdev, priv->hw.iobase);
  222. pci_release_regions(pdev);
  223. pci_disable_device(pdev);
  224. }
  225. static struct pci_device_id nortel_pci_id_table[] = {
  226. /* Nortel emobility PCI */
  227. {0x126c, 0x8030, PCI_ANY_ID, PCI_ANY_ID,},
  228. /* Symbol LA-4123 PCI */
  229. {0x1562, 0x0001, PCI_ANY_ID, PCI_ANY_ID,},
  230. {0,},
  231. };
  232. MODULE_DEVICE_TABLE(pci, nortel_pci_id_table);
  233. static struct pci_driver nortel_pci_driver = {
  234. .name = DRIVER_NAME,
  235. .id_table = nortel_pci_id_table,
  236. .probe = nortel_pci_init_one,
  237. .remove = __devexit_p(nortel_pci_remove_one),
  238. };
  239. static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
  240. " (Tobias Hoffmann & Christoph Jungegger <disdos@traum404.de>)";
  241. MODULE_AUTHOR("Christoph Jungegger <disdos@traum404.de>");
  242. MODULE_DESCRIPTION
  243. ("Driver for wireless LAN cards using the Nortel PCI bridge");
  244. MODULE_LICENSE("Dual MPL/GPL");
  245. static int __init nortel_pci_init(void)
  246. {
  247. printk(KERN_DEBUG "%s\n", version);
  248. return pci_module_init(&nortel_pci_driver);
  249. }
  250. static void __exit nortel_pci_exit(void)
  251. {
  252. pci_unregister_driver(&nortel_pci_driver);
  253. ssleep(1);
  254. }
  255. module_init(nortel_pci_init);
  256. module_exit(nortel_pci_exit);
  257. /*
  258. * Local variables:
  259. * c-indent-level: 8
  260. * c-basic-offset: 8
  261. * tab-width: 8
  262. * End:
  263. */