orinoco_pci.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /* orinoco_pci.c
  2. *
  3. * Driver for Prism 2.5/3 devices that have a direct PCI interface
  4. * (i.e. these are not PCMCIA cards in a PCMCIA-to-PCI bridge).
  5. * The card contains only one PCI region, which contains all the usual
  6. * hermes registers, as well as the COR register.
  7. *
  8. * Current maintainers are:
  9. * Pavel Roskin <proski AT gnu.org>
  10. * and David Gibson <hermes AT gibson.dropbear.id.au>
  11. *
  12. * Some of this code is borrowed from orinoco_plx.c
  13. * Copyright (C) 2001 Daniel Barlow <dan AT telent.net>
  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. * This file originally written by:
  18. * Copyright (C) 2001 Jean Tourrilhes <jt AT hpl.hp.com>
  19. * And is now maintained by:
  20. * (C) Copyright David Gibson, IBM Corp. 2002-2003.
  21. *
  22. * The contents of this file are subject to the Mozilla Public License
  23. * Version 1.1 (the "License"); you may not use this file except in
  24. * compliance with the License. You may obtain a copy of the License
  25. * at http://www.mozilla.org/MPL/
  26. *
  27. * Software distributed under the License is distributed on an "AS IS"
  28. * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
  29. * the License for the specific language governing rights and
  30. * limitations under the License.
  31. *
  32. * Alternatively, the contents of this file may be used under the
  33. * terms of the GNU General Public License version 2 (the "GPL"), in
  34. * which case the provisions of the GPL are applicable instead of the
  35. * above. If you wish to allow the use of your version of this file
  36. * only under the terms of the GPL and not to allow others to use your
  37. * version of this file under the MPL, indicate your decision by
  38. * deleting the provisions above and replace them with the notice and
  39. * other provisions required by the GPL. If you do not delete the
  40. * provisions above, a recipient may use your version of this file
  41. * under either the MPL or the GPL.
  42. */
  43. #define DRIVER_NAME "orinoco_pci"
  44. #define PFX DRIVER_NAME ": "
  45. #include <linux/module.h>
  46. #include <linux/kernel.h>
  47. #include <linux/init.h>
  48. #include <linux/delay.h>
  49. #include <linux/pci.h>
  50. #include "orinoco.h"
  51. #include "orinoco_pci.h"
  52. /* Offset of the COR register of the PCI card */
  53. #define HERMES_PCI_COR (0x26)
  54. /* Bitmask to reset the card */
  55. #define HERMES_PCI_COR_MASK (0x0080)
  56. /* Magic timeouts for doing the reset.
  57. * Those times are straight from wlan-ng, and it is claimed that they
  58. * are necessary. Alan will kill me. Take your time and grab a coffee. */
  59. #define HERMES_PCI_COR_ONT (250) /* ms */
  60. #define HERMES_PCI_COR_OFFT (500) /* ms */
  61. #define HERMES_PCI_COR_BUSYT (500) /* ms */
  62. /*
  63. * Do a soft reset of the card using the Configuration Option Register
  64. * We need this to get going...
  65. * This is the part of the code that is strongly inspired from wlan-ng
  66. *
  67. * Note : This code is done with irq enabled. This mean that many
  68. * interrupts will occur while we are there. This is why we use the
  69. * jiffies to regulate time instead of a straight mdelay(). Usually we
  70. * need only around 245 iteration of the loop to do 250 ms delay.
  71. *
  72. * Note bis : Don't try to access HERMES_CMD during the reset phase.
  73. * It just won't work !
  74. */
  75. static int orinoco_pci_cor_reset(struct orinoco_private *priv)
  76. {
  77. struct hermes *hw = &priv->hw;
  78. unsigned long timeout;
  79. u16 reg;
  80. /* Assert the reset until the card notices */
  81. hermes_write_regn(hw, PCI_COR, HERMES_PCI_COR_MASK);
  82. mdelay(HERMES_PCI_COR_ONT);
  83. /* Give time for the card to recover from this hard effort */
  84. hermes_write_regn(hw, PCI_COR, 0x0000);
  85. mdelay(HERMES_PCI_COR_OFFT);
  86. /* The card is ready when it's no longer busy */
  87. timeout = jiffies + msecs_to_jiffies(HERMES_PCI_COR_BUSYT);
  88. reg = hermes_read_regn(hw, CMD);
  89. while (time_before(jiffies, timeout) && (reg & HERMES_CMD_BUSY)) {
  90. mdelay(1);
  91. reg = hermes_read_regn(hw, CMD);
  92. }
  93. /* Still busy? */
  94. if (reg & HERMES_CMD_BUSY) {
  95. printk(KERN_ERR PFX "Busy timeout\n");
  96. return -ETIMEDOUT;
  97. }
  98. return 0;
  99. }
  100. static int orinoco_pci_init_one(struct pci_dev *pdev,
  101. const struct pci_device_id *ent)
  102. {
  103. int err;
  104. struct orinoco_private *priv;
  105. struct orinoco_pci_card *card;
  106. void __iomem *hermes_io;
  107. err = pci_enable_device(pdev);
  108. if (err) {
  109. printk(KERN_ERR PFX "Cannot enable PCI device\n");
  110. return err;
  111. }
  112. err = pci_request_regions(pdev, DRIVER_NAME);
  113. if (err) {
  114. printk(KERN_ERR PFX "Cannot obtain PCI resources\n");
  115. goto fail_resources;
  116. }
  117. hermes_io = pci_iomap(pdev, 0, 0);
  118. if (!hermes_io) {
  119. printk(KERN_ERR PFX "Cannot remap chipset registers\n");
  120. err = -EIO;
  121. goto fail_map_hermes;
  122. }
  123. /* Allocate network device */
  124. priv = alloc_orinocodev(sizeof(*card), &pdev->dev,
  125. orinoco_pci_cor_reset, NULL);
  126. if (!priv) {
  127. printk(KERN_ERR PFX "Cannot allocate network device\n");
  128. err = -ENOMEM;
  129. goto fail_alloc;
  130. }
  131. card = priv->card;
  132. hermes_struct_init(&priv->hw, hermes_io, HERMES_32BIT_REGSPACING);
  133. err = request_irq(pdev->irq, orinoco_interrupt, IRQF_SHARED,
  134. DRIVER_NAME, priv);
  135. if (err) {
  136. printk(KERN_ERR PFX "Cannot allocate IRQ %d\n", pdev->irq);
  137. err = -EBUSY;
  138. goto fail_irq;
  139. }
  140. err = orinoco_pci_cor_reset(priv);
  141. if (err) {
  142. printk(KERN_ERR PFX "Initial reset failed\n");
  143. goto fail;
  144. }
  145. err = orinoco_init(priv);
  146. if (err) {
  147. printk(KERN_ERR PFX "orinoco_init() failed\n");
  148. goto fail;
  149. }
  150. err = orinoco_if_add(priv, 0, 0, NULL);
  151. if (err) {
  152. printk(KERN_ERR PFX "orinoco_if_add() failed\n");
  153. goto fail_wiphy;
  154. }
  155. pci_set_drvdata(pdev, priv);
  156. return 0;
  157. fail_wiphy:
  158. wiphy_unregister(priv_to_wiphy(priv));
  159. fail:
  160. free_irq(pdev->irq, priv);
  161. fail_irq:
  162. free_orinocodev(priv);
  163. fail_alloc:
  164. pci_iounmap(pdev, hermes_io);
  165. fail_map_hermes:
  166. pci_release_regions(pdev);
  167. fail_resources:
  168. pci_disable_device(pdev);
  169. return err;
  170. }
  171. static void orinoco_pci_remove_one(struct pci_dev *pdev)
  172. {
  173. struct orinoco_private *priv = pci_get_drvdata(pdev);
  174. orinoco_if_del(priv);
  175. wiphy_unregister(priv_to_wiphy(priv));
  176. free_irq(pdev->irq, priv);
  177. free_orinocodev(priv);
  178. pci_iounmap(pdev, priv->hw.iobase);
  179. pci_release_regions(pdev);
  180. pci_disable_device(pdev);
  181. }
  182. static const struct pci_device_id orinoco_pci_id_table[] = {
  183. /* Intersil Prism 3 */
  184. {0x1260, 0x3872, PCI_ANY_ID, PCI_ANY_ID,},
  185. /* Intersil Prism 2.5 */
  186. {0x1260, 0x3873, PCI_ANY_ID, PCI_ANY_ID,},
  187. /* Samsung MagicLAN SWL-2210P */
  188. {0x167d, 0xa000, PCI_ANY_ID, PCI_ANY_ID,},
  189. {0,},
  190. };
  191. MODULE_DEVICE_TABLE(pci, orinoco_pci_id_table);
  192. static struct pci_driver orinoco_pci_driver = {
  193. .name = DRIVER_NAME,
  194. .id_table = orinoco_pci_id_table,
  195. .probe = orinoco_pci_init_one,
  196. .remove = orinoco_pci_remove_one,
  197. .suspend = orinoco_pci_suspend,
  198. .resume = orinoco_pci_resume,
  199. };
  200. static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
  201. " (Pavel Roskin <proski@gnu.org>,"
  202. " David Gibson <hermes@gibson.dropbear.id.au> &"
  203. " Jean Tourrilhes <jt@hpl.hp.com>)";
  204. MODULE_AUTHOR("Pavel Roskin <proski@gnu.org> &"
  205. " David Gibson <hermes@gibson.dropbear.id.au>");
  206. MODULE_DESCRIPTION("Driver for wireless LAN cards using direct PCI interface");
  207. MODULE_LICENSE("Dual MPL/GPL");
  208. static int __init orinoco_pci_init(void)
  209. {
  210. printk(KERN_DEBUG "%s\n", version);
  211. return pci_register_driver(&orinoco_pci_driver);
  212. }
  213. static void __exit orinoco_pci_exit(void)
  214. {
  215. pci_unregister_driver(&orinoco_pci_driver);
  216. }
  217. module_init(orinoco_pci_init);
  218. module_exit(orinoco_pci_exit);
  219. /*
  220. * Local variables:
  221. * c-indent-level: 8
  222. * c-basic-offset: 8
  223. * tab-width: 8
  224. * End:
  225. */