PageRenderTime 62ms CodeModel.GetById 34ms RepoModel.GetById 0ms app.codeStats 0ms

/drivers/net/wireless/orinoco/orinoco_nortel.c

https://github.com/mstsirkin/linux
C | 322 lines | 209 code | 50 blank | 63 comment | 21 complexity | c6658878adffb24dcc1e259acdb2b17f MD5 | raw file
  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;
  198. }
  199. pci_set_drvdata(pdev, priv);
  200. return 0;
  201. fail:
  202. free_irq(pdev->irq, priv);
  203. fail_irq:
  204. pci_set_drvdata(pdev, NULL);
  205. free_orinocodev(priv);
  206. fail_alloc:
  207. pci_iounmap(pdev, hermes_io);
  208. fail_map_hermes:
  209. pci_iounmap(pdev, attr_io);
  210. fail_map_attr:
  211. pci_iounmap(pdev, bridge_io);
  212. fail_map_bridge:
  213. pci_release_regions(pdev);
  214. fail_resources:
  215. pci_disable_device(pdev);
  216. return err;
  217. }
  218. static void __devexit orinoco_nortel_remove_one(struct pci_dev *pdev)
  219. {
  220. struct orinoco_private *priv = pci_get_drvdata(pdev);
  221. struct orinoco_pci_card *card = priv->card;
  222. /* Clear LEDs */
  223. iowrite16(0, card->bridge_io + 10);
  224. orinoco_if_del(priv);
  225. free_irq(pdev->irq, priv);
  226. pci_set_drvdata(pdev, NULL);
  227. free_orinocodev(priv);
  228. pci_iounmap(pdev, priv->hw.iobase);
  229. pci_iounmap(pdev, card->attr_io);
  230. pci_iounmap(pdev, card->bridge_io);
  231. pci_release_regions(pdev);
  232. pci_disable_device(pdev);
  233. }
  234. static DEFINE_PCI_DEVICE_TABLE(orinoco_nortel_id_table) = {
  235. /* Nortel emobility PCI */
  236. {0x126c, 0x8030, PCI_ANY_ID, PCI_ANY_ID,},
  237. /* Symbol LA-4123 PCI */
  238. {0x1562, 0x0001, PCI_ANY_ID, PCI_ANY_ID,},
  239. {0,},
  240. };
  241. MODULE_DEVICE_TABLE(pci, orinoco_nortel_id_table);
  242. static struct pci_driver orinoco_nortel_driver = {
  243. .name = DRIVER_NAME,
  244. .id_table = orinoco_nortel_id_table,
  245. .probe = orinoco_nortel_init_one,
  246. .remove = __devexit_p(orinoco_nortel_remove_one),
  247. .suspend = orinoco_pci_suspend,
  248. .resume = orinoco_pci_resume,
  249. };
  250. static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
  251. " (Tobias Hoffmann & Christoph Jungegger <disdos@traum404.de>)";
  252. MODULE_AUTHOR("Christoph Jungegger <disdos@traum404.de>");
  253. MODULE_DESCRIPTION("Driver for wireless LAN cards using the Nortel PCI bridge");
  254. MODULE_LICENSE("Dual MPL/GPL");
  255. static int __init orinoco_nortel_init(void)
  256. {
  257. printk(KERN_DEBUG "%s\n", version);
  258. return pci_register_driver(&orinoco_nortel_driver);
  259. }
  260. static void __exit orinoco_nortel_exit(void)
  261. {
  262. pci_unregister_driver(&orinoco_nortel_driver);
  263. }
  264. module_init(orinoco_nortel_init);
  265. module_exit(orinoco_nortel_exit);
  266. /*
  267. * Local variables:
  268. * c-indent-level: 8
  269. * c-basic-offset: 8
  270. * tab-width: 8
  271. * End:
  272. */