orinoco_nortel.c 8.4 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. void __iomem *hermes_io, *bridge_io, *attr_io;
  132. err = pci_enable_device(pdev);
  133. if (err) {
  134. printk(KERN_ERR PFX "Cannot enable PCI device\n");
  135. return err;
  136. }
  137. err = pci_request_regions(pdev, DRIVER_NAME);
  138. if (err) {
  139. printk(KERN_ERR PFX "Cannot obtain PCI resources\n");
  140. goto fail_resources;
  141. }
  142. bridge_io = pci_iomap(pdev, 0, 0);
  143. if (!bridge_io) {
  144. printk(KERN_ERR PFX "Cannot map bridge registers\n");
  145. err = -EIO;
  146. goto fail_map_bridge;
  147. }
  148. attr_io = pci_iomap(pdev, 1, 0);
  149. if (!attr_io) {
  150. printk(KERN_ERR PFX "Cannot map PCMCIA attributes\n");
  151. err = -EIO;
  152. goto fail_map_attr;
  153. }
  154. hermes_io = pci_iomap(pdev, 2, 0);
  155. if (!hermes_io) {
  156. printk(KERN_ERR PFX "Cannot map chipset registers\n");
  157. err = -EIO;
  158. goto fail_map_hermes;
  159. }
  160. /* Allocate network device */
  161. priv = alloc_orinocodev(sizeof(*card), &pdev->dev,
  162. orinoco_nortel_cor_reset, NULL);
  163. if (!priv) {
  164. printk(KERN_ERR PFX "Cannot allocate network device\n");
  165. err = -ENOMEM;
  166. goto fail_alloc;
  167. }
  168. card = priv->card;
  169. card->bridge_io = bridge_io;
  170. card->attr_io = attr_io;
  171. hermes_struct_init(&priv->hw, hermes_io, HERMES_16BIT_REGSPACING);
  172. err = request_irq(pdev->irq, orinoco_interrupt, IRQF_SHARED,
  173. DRIVER_NAME, priv);
  174. if (err) {
  175. printk(KERN_ERR PFX "Cannot allocate IRQ %d\n", pdev->irq);
  176. err = -EBUSY;
  177. goto fail_irq;
  178. }
  179. err = orinoco_nortel_hw_init(card);
  180. if (err) {
  181. printk(KERN_ERR PFX "Hardware initialization failed\n");
  182. goto fail;
  183. }
  184. err = orinoco_nortel_cor_reset(priv);
  185. if (err) {
  186. printk(KERN_ERR PFX "Initial reset failed\n");
  187. goto fail;
  188. }
  189. err = orinoco_init(priv);
  190. if (err) {
  191. printk(KERN_ERR PFX "orinoco_init() failed\n");
  192. goto fail;
  193. }
  194. err = orinoco_if_add(priv, 0, 0, NULL);
  195. if (err) {
  196. printk(KERN_ERR PFX "orinoco_if_add() failed\n");
  197. goto fail_wiphy;
  198. }
  199. pci_set_drvdata(pdev, priv);
  200. return 0;
  201. fail_wiphy:
  202. wiphy_unregister(priv_to_wiphy(priv));
  203. fail:
  204. free_irq(pdev->irq, priv);
  205. fail_irq:
  206. free_orinocodev(priv);
  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 orinoco_nortel_remove_one(struct pci_dev *pdev)
  220. {
  221. struct orinoco_private *priv = pci_get_drvdata(pdev);
  222. struct orinoco_pci_card *card = priv->card;
  223. /* Clear LEDs */
  224. iowrite16(0, card->bridge_io + 10);
  225. orinoco_if_del(priv);
  226. wiphy_unregister(priv_to_wiphy(priv));
  227. free_irq(pdev->irq, priv);
  228. free_orinocodev(priv);
  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 const 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 = 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("Driver for wireless LAN cards using the Nortel PCI bridge");
  255. MODULE_LICENSE("Dual MPL/GPL");
  256. static int __init orinoco_nortel_init(void)
  257. {
  258. printk(KERN_DEBUG "%s\n", version);
  259. return pci_register_driver(&orinoco_nortel_driver);
  260. }
  261. static void __exit orinoco_nortel_exit(void)
  262. {
  263. pci_unregister_driver(&orinoco_nortel_driver);
  264. }
  265. module_init(orinoco_nortel_init);
  266. module_exit(orinoco_nortel_exit);
  267. /*
  268. * Local variables:
  269. * c-indent-level: 8
  270. * c-basic-offset: 8
  271. * tab-width: 8
  272. * End:
  273. */