/drivers/net/wireless/orinoco_tmd.c

https://bitbucket.org/evzijst/gittest · C · 276 lines · 166 code · 46 blank · 64 comment · 11 complexity · 499e9da6b5f2d3d7e798b74fe7f1dd05 MD5 · raw file

  1. /* orinoco_tmd.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 TMD7160.
  5. *
  6. * Copyright (C) 2003 Joerg Dorchain <joerg AT dorchain.net>
  7. * based heavily upon orinoco_plx.c Copyright (C) 2001 Daniel Barlow
  8. *
  9. * The contents of this file are subject to the Mozilla Public License
  10. * Version 1.1 (the "License"); you may not use this file except in
  11. * compliance with the License. You may obtain a copy of the License
  12. * at http://www.mozilla.org/MPL/
  13. *
  14. * Software distributed under the License is distributed on an "AS IS"
  15. * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
  16. * the License for the specific language governing rights and
  17. * limitations under the License.
  18. *
  19. * Alternatively, the contents of this file may be used under the
  20. * terms of the GNU General Public License version 2 (the "GPL"), in
  21. * which case the provisions of the GPL are applicable instead of the
  22. * above. If you wish to allow the use of your version of this file
  23. * only under the terms of the GPL and not to allow others to use your
  24. * version of this file under the MPL, indicate your decision by
  25. * deleting the provisions above and replace them with the notice and
  26. * other provisions required by the GPL. If you do not delete the
  27. * provisions above, a recipient may use your version of this file
  28. * under either the MPL or the GPL.
  29. * Caution: this is experimental and probably buggy. For success and
  30. * failure reports for different cards and adaptors, see
  31. * orinoco_tmd_pci_id_table near the end of the file. If you have a
  32. * card we don't have the PCI id for, and looks like it should work,
  33. * drop me mail with the id and "it works"/"it doesn't work".
  34. *
  35. * Note: if everything gets detected fine but it doesn't actually send
  36. * or receive packets, your first port of call should probably be to
  37. * try newer firmware in the card. Especially if you're doing Ad-Hoc
  38. * modes
  39. *
  40. * The actual driving is done by orinoco.c, this is just resource
  41. * allocation stuff.
  42. *
  43. * This driver is modeled after the orinoco_plx driver. The main
  44. * difference is that the TMD chip has only IO port ranges and no
  45. * memory space, i.e. no access to the CIS. Compared to the PLX chip,
  46. * the io range functionalities are exchanged.
  47. *
  48. * Pheecom sells cards with the TMD chip as "ASIC version"
  49. */
  50. #define DRIVER_NAME "orinoco_tmd"
  51. #define PFX DRIVER_NAME ": "
  52. #include <linux/config.h>
  53. #include <linux/module.h>
  54. #include <linux/kernel.h>
  55. #include <linux/init.h>
  56. #include <linux/sched.h>
  57. #include <linux/ptrace.h>
  58. #include <linux/slab.h>
  59. #include <linux/string.h>
  60. #include <linux/timer.h>
  61. #include <linux/ioport.h>
  62. #include <asm/uaccess.h>
  63. #include <asm/io.h>
  64. #include <asm/system.h>
  65. #include <linux/netdevice.h>
  66. #include <linux/if_arp.h>
  67. #include <linux/etherdevice.h>
  68. #include <linux/list.h>
  69. #include <linux/pci.h>
  70. #include <linux/fcntl.h>
  71. #include <pcmcia/cisreg.h>
  72. #include "hermes.h"
  73. #include "orinoco.h"
  74. #define COR_VALUE (COR_LEVEL_REQ | COR_FUNC_ENA) /* Enable PC card with interrupt in level trigger */
  75. #define COR_RESET (0x80) /* reset bit in the COR register */
  76. #define TMD_RESET_TIME (500) /* milliseconds */
  77. /* Orinoco TMD specific data */
  78. struct orinoco_tmd_card {
  79. u32 tmd_io;
  80. };
  81. /*
  82. * Do a soft reset of the card using the Configuration Option Register
  83. */
  84. static int orinoco_tmd_cor_reset(struct orinoco_private *priv)
  85. {
  86. hermes_t *hw = &priv->hw;
  87. struct orinoco_tmd_card *card = priv->card;
  88. u32 addr = card->tmd_io;
  89. unsigned long timeout;
  90. u16 reg;
  91. outb(COR_VALUE | COR_RESET, addr);
  92. mdelay(1);
  93. outb(COR_VALUE, addr);
  94. mdelay(1);
  95. /* Just in case, wait more until the card is no longer busy */
  96. timeout = jiffies + (TMD_RESET_TIME * HZ / 1000);
  97. reg = hermes_read_regn(hw, CMD);
  98. while (time_before(jiffies, timeout) && (reg & HERMES_CMD_BUSY)) {
  99. mdelay(1);
  100. reg = hermes_read_regn(hw, CMD);
  101. }
  102. /* Did we timeout ? */
  103. if (reg & HERMES_CMD_BUSY) {
  104. printk(KERN_ERR PFX "Busy timeout\n");
  105. return -ETIMEDOUT;
  106. }
  107. return 0;
  108. }
  109. static int orinoco_tmd_init_one(struct pci_dev *pdev,
  110. const struct pci_device_id *ent)
  111. {
  112. int err = 0;
  113. struct orinoco_private *priv = NULL;
  114. struct orinoco_tmd_card *card;
  115. struct net_device *dev = NULL;
  116. void __iomem *mem;
  117. err = pci_enable_device(pdev);
  118. if (err) {
  119. printk(KERN_ERR PFX "Cannot enable PCI device\n");
  120. return err;
  121. }
  122. err = pci_request_regions(pdev, DRIVER_NAME);
  123. if (err != 0) {
  124. printk(KERN_ERR PFX "Cannot obtain PCI resources\n");
  125. goto fail_resources;
  126. }
  127. mem = pci_iomap(pdev, 2, 0);
  128. if (! mem) {
  129. err = -ENOMEM;
  130. goto fail_iomap;
  131. }
  132. /* Allocate network device */
  133. dev = alloc_orinocodev(sizeof(*card), orinoco_tmd_cor_reset);
  134. if (! dev) {
  135. printk(KERN_ERR PFX "Cannot allocate network device\n");
  136. err = -ENOMEM;
  137. goto fail_alloc;
  138. }
  139. priv = netdev_priv(dev);
  140. card = priv->card;
  141. card->tmd_io = pci_resource_start(pdev, 1);
  142. dev->base_addr = pci_resource_start(pdev, 2);
  143. SET_MODULE_OWNER(dev);
  144. SET_NETDEV_DEV(dev, &pdev->dev);
  145. hermes_struct_init(&priv->hw, mem, HERMES_16BIT_REGSPACING);
  146. printk(KERN_DEBUG PFX "Detected Orinoco/Prism2 TMD device "
  147. "at %s irq:%d, io addr:0x%lx\n", pci_name(pdev), pdev->irq,
  148. dev->base_addr);
  149. err = request_irq(pdev->irq, orinoco_interrupt, SA_SHIRQ,
  150. dev->name, dev);
  151. if (err) {
  152. printk(KERN_ERR PFX "Cannot allocate IRQ %d\n", pdev->irq);
  153. err = -EBUSY;
  154. goto fail_irq;
  155. }
  156. dev->irq = pdev->irq;
  157. err = orinoco_tmd_cor_reset(priv);
  158. if (err) {
  159. printk(KERN_ERR PFX "Initial reset failed\n");
  160. goto fail;
  161. }
  162. err = register_netdev(dev);
  163. if (err) {
  164. printk(KERN_ERR PFX "Cannot register network device\n");
  165. goto fail;
  166. }
  167. pci_set_drvdata(pdev, dev);
  168. return 0;
  169. fail:
  170. free_irq(pdev->irq, dev);
  171. fail_irq:
  172. pci_set_drvdata(pdev, NULL);
  173. free_orinocodev(dev);
  174. fail_alloc:
  175. pci_iounmap(pdev, mem);
  176. fail_iomap:
  177. pci_release_regions(pdev);
  178. fail_resources:
  179. pci_disable_device(pdev);
  180. return err;
  181. }
  182. static void __devexit orinoco_tmd_remove_one(struct pci_dev *pdev)
  183. {
  184. struct net_device *dev = pci_get_drvdata(pdev);
  185. struct orinoco_private *priv = dev->priv;
  186. BUG_ON(! dev);
  187. unregister_netdev(dev);
  188. free_irq(dev->irq, dev);
  189. pci_set_drvdata(pdev, NULL);
  190. free_orinocodev(dev);
  191. pci_iounmap(pdev, priv->hw.iobase);
  192. pci_release_regions(pdev);
  193. pci_disable_device(pdev);
  194. }
  195. static struct pci_device_id orinoco_tmd_pci_id_table[] = {
  196. {0x15e8, 0x0131, PCI_ANY_ID, PCI_ANY_ID,}, /* NDC and OEMs, e.g. pheecom */
  197. {0,},
  198. };
  199. MODULE_DEVICE_TABLE(pci, orinoco_tmd_pci_id_table);
  200. static struct pci_driver orinoco_tmd_driver = {
  201. .name = DRIVER_NAME,
  202. .id_table = orinoco_tmd_pci_id_table,
  203. .probe = orinoco_tmd_init_one,
  204. .remove = __devexit_p(orinoco_tmd_remove_one),
  205. };
  206. static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
  207. " (Joerg Dorchain <joerg@dorchain.net>)";
  208. MODULE_AUTHOR("Joerg Dorchain <joerg@dorchain.net>");
  209. MODULE_DESCRIPTION("Driver for wireless LAN cards using the TMD7160 PCI bridge");
  210. MODULE_LICENSE("Dual MPL/GPL");
  211. static int __init orinoco_tmd_init(void)
  212. {
  213. printk(KERN_DEBUG "%s\n", version);
  214. return pci_module_init(&orinoco_tmd_driver);
  215. }
  216. static void __exit orinoco_tmd_exit(void)
  217. {
  218. pci_unregister_driver(&orinoco_tmd_driver);
  219. ssleep(1);
  220. }
  221. module_init(orinoco_tmd_init);
  222. module_exit(orinoco_tmd_exit);
  223. /*
  224. * Local variables:
  225. * c-indent-level: 8
  226. * c-basic-offset: 8
  227. * tab-width: 8
  228. * End:
  229. */