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