orinoco_nortel.c 7.8 KB

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