orinoco_tmd.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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/delay.h>
  57. #include <linux/pci.h>
  58. #include <pcmcia/cisreg.h>
  59. #include "orinoco.h"
  60. #define COR_VALUE (COR_LEVEL_REQ | COR_FUNC_ENA) /* Enable PC card with interrupt in level trigger */
  61. #define COR_RESET (0x80) /* reset bit in the COR register */
  62. #define TMD_RESET_TIME (500) /* milliseconds */
  63. /* Orinoco TMD specific data */
  64. struct orinoco_tmd_card {
  65. u32 tmd_io;
  66. };
  67. /*
  68. * Do a soft reset of the card using the Configuration Option Register
  69. */
  70. static int orinoco_tmd_cor_reset(struct orinoco_private *priv)
  71. {
  72. hermes_t *hw = &priv->hw;
  73. struct orinoco_tmd_card *card = priv->card;
  74. u32 addr = card->tmd_io;
  75. unsigned long timeout;
  76. u16 reg;
  77. outb(COR_VALUE | COR_RESET, addr);
  78. mdelay(1);
  79. outb(COR_VALUE, addr);
  80. mdelay(1);
  81. /* Just in case, wait more until the card is no longer busy */
  82. timeout = jiffies + (TMD_RESET_TIME * HZ / 1000);
  83. reg = hermes_read_regn(hw, CMD);
  84. while (time_before(jiffies, timeout) && (reg & HERMES_CMD_BUSY)) {
  85. mdelay(1);
  86. reg = hermes_read_regn(hw, CMD);
  87. }
  88. /* Did we timeout ? */
  89. if (reg & HERMES_CMD_BUSY) {
  90. printk(KERN_ERR PFX "Busy timeout\n");
  91. return -ETIMEDOUT;
  92. }
  93. return 0;
  94. }
  95. static int orinoco_tmd_init_one(struct pci_dev *pdev,
  96. const struct pci_device_id *ent)
  97. {
  98. int err = 0;
  99. struct orinoco_private *priv = NULL;
  100. struct orinoco_tmd_card *card;
  101. struct net_device *dev = NULL;
  102. void __iomem *mem;
  103. err = pci_enable_device(pdev);
  104. if (err) {
  105. printk(KERN_ERR PFX "Cannot enable PCI device\n");
  106. return err;
  107. }
  108. err = pci_request_regions(pdev, DRIVER_NAME);
  109. if (err != 0) {
  110. printk(KERN_ERR PFX "Cannot obtain PCI resources\n");
  111. goto fail_resources;
  112. }
  113. mem = pci_iomap(pdev, 2, 0);
  114. if (! mem) {
  115. err = -ENOMEM;
  116. goto fail_iomap;
  117. }
  118. /* Allocate network device */
  119. dev = alloc_orinocodev(sizeof(*card), orinoco_tmd_cor_reset);
  120. if (! dev) {
  121. printk(KERN_ERR PFX "Cannot allocate network device\n");
  122. err = -ENOMEM;
  123. goto fail_alloc;
  124. }
  125. priv = netdev_priv(dev);
  126. card = priv->card;
  127. card->tmd_io = pci_resource_start(pdev, 1);
  128. dev->base_addr = pci_resource_start(pdev, 2);
  129. SET_MODULE_OWNER(dev);
  130. SET_NETDEV_DEV(dev, &pdev->dev);
  131. hermes_struct_init(&priv->hw, mem, HERMES_16BIT_REGSPACING);
  132. printk(KERN_DEBUG PFX "Detected Orinoco/Prism2 TMD device "
  133. "at %s irq:%d, io addr:0x%lx\n", pci_name(pdev), pdev->irq,
  134. dev->base_addr);
  135. err = request_irq(pdev->irq, orinoco_interrupt, SA_SHIRQ,
  136. dev->name, dev);
  137. if (err) {
  138. printk(KERN_ERR PFX "Cannot allocate IRQ %d\n", pdev->irq);
  139. err = -EBUSY;
  140. goto fail_irq;
  141. }
  142. dev->irq = pdev->irq;
  143. err = orinoco_tmd_cor_reset(priv);
  144. if (err) {
  145. printk(KERN_ERR PFX "Initial reset failed\n");
  146. goto fail;
  147. }
  148. err = register_netdev(dev);
  149. if (err) {
  150. printk(KERN_ERR PFX "Cannot register network device\n");
  151. goto fail;
  152. }
  153. pci_set_drvdata(pdev, dev);
  154. return 0;
  155. fail:
  156. free_irq(pdev->irq, dev);
  157. fail_irq:
  158. pci_set_drvdata(pdev, NULL);
  159. free_orinocodev(dev);
  160. fail_alloc:
  161. pci_iounmap(pdev, mem);
  162. fail_iomap:
  163. pci_release_regions(pdev);
  164. fail_resources:
  165. pci_disable_device(pdev);
  166. return err;
  167. }
  168. static void __devexit orinoco_tmd_remove_one(struct pci_dev *pdev)
  169. {
  170. struct net_device *dev = pci_get_drvdata(pdev);
  171. struct orinoco_private *priv = dev->priv;
  172. BUG_ON(! dev);
  173. unregister_netdev(dev);
  174. free_irq(dev->irq, dev);
  175. pci_set_drvdata(pdev, NULL);
  176. free_orinocodev(dev);
  177. pci_iounmap(pdev, priv->hw.iobase);
  178. pci_release_regions(pdev);
  179. pci_disable_device(pdev);
  180. }
  181. static struct pci_device_id orinoco_tmd_pci_id_table[] = {
  182. {0x15e8, 0x0131, PCI_ANY_ID, PCI_ANY_ID,}, /* NDC and OEMs, e.g. pheecom */
  183. {0,},
  184. };
  185. MODULE_DEVICE_TABLE(pci, orinoco_tmd_pci_id_table);
  186. static struct pci_driver orinoco_tmd_driver = {
  187. .name = DRIVER_NAME,
  188. .id_table = orinoco_tmd_pci_id_table,
  189. .probe = orinoco_tmd_init_one,
  190. .remove = __devexit_p(orinoco_tmd_remove_one),
  191. };
  192. static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
  193. " (Joerg Dorchain <joerg@dorchain.net>)";
  194. MODULE_AUTHOR("Joerg Dorchain <joerg@dorchain.net>");
  195. MODULE_DESCRIPTION("Driver for wireless LAN cards using the TMD7160 PCI bridge");
  196. MODULE_LICENSE("Dual MPL/GPL");
  197. static int __init orinoco_tmd_init(void)
  198. {
  199. printk(KERN_DEBUG "%s\n", version);
  200. return pci_module_init(&orinoco_tmd_driver);
  201. }
  202. static void __exit orinoco_tmd_exit(void)
  203. {
  204. pci_unregister_driver(&orinoco_tmd_driver);
  205. ssleep(1);
  206. }
  207. module_init(orinoco_tmd_init);
  208. module_exit(orinoco_tmd_exit);
  209. /*
  210. * Local variables:
  211. * c-indent-level: 8
  212. * c-basic-offset: 8
  213. * tab-width: 8
  214. * End:
  215. */