orinoco_tmd.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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. *
  30. * The actual driving is done by orinoco.c, this is just resource
  31. * allocation stuff.
  32. *
  33. * This driver is modeled after the orinoco_plx driver. The main
  34. * difference is that the TMD chip has only IO port ranges and doesn't
  35. * provide access to the PCMCIA attribute space.
  36. *
  37. * Pheecom sells cards with the TMD chip as "ASIC version"
  38. */
  39. #define DRIVER_NAME "orinoco_tmd"
  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_VALUE (COR_LEVEL_REQ | COR_FUNC_ENA) /* Enable PC card with interrupt in level trigger */
  50. #define COR_RESET (0x80) /* reset bit in the COR register */
  51. #define TMD_RESET_TIME (500) /* milliseconds */
  52. /*
  53. * Do a soft reset of the card using the Configuration Option Register
  54. */
  55. static int orinoco_tmd_cor_reset(struct orinoco_private *priv)
  56. {
  57. hermes_t *hw = &priv->hw;
  58. struct orinoco_pci_card *card = priv->card;
  59. unsigned long timeout;
  60. u16 reg;
  61. iowrite8(COR_VALUE | COR_RESET, card->bridge_io);
  62. mdelay(1);
  63. iowrite8(COR_VALUE, card->bridge_io);
  64. mdelay(1);
  65. /* Just in case, wait more until the card is no longer busy */
  66. timeout = jiffies + (TMD_RESET_TIME * HZ / 1000);
  67. reg = hermes_read_regn(hw, CMD);
  68. while (time_before(jiffies, timeout) && (reg & HERMES_CMD_BUSY)) {
  69. mdelay(1);
  70. reg = hermes_read_regn(hw, CMD);
  71. }
  72. /* Still busy? */
  73. if (reg & HERMES_CMD_BUSY) {
  74. printk(KERN_ERR PFX "Busy timeout\n");
  75. return -ETIMEDOUT;
  76. }
  77. return 0;
  78. }
  79. static int orinoco_tmd_init_one(struct pci_dev *pdev,
  80. const struct pci_device_id *ent)
  81. {
  82. int err;
  83. struct orinoco_private *priv;
  84. struct orinoco_pci_card *card;
  85. struct net_device *dev;
  86. void __iomem *hermes_io, *bridge_io;
  87. err = pci_enable_device(pdev);
  88. if (err) {
  89. printk(KERN_ERR PFX "Cannot enable PCI device\n");
  90. return err;
  91. }
  92. err = pci_request_regions(pdev, DRIVER_NAME);
  93. if (err) {
  94. printk(KERN_ERR PFX "Cannot obtain PCI resources\n");
  95. goto fail_resources;
  96. }
  97. bridge_io = pci_iomap(pdev, 1, 0);
  98. if (!bridge_io) {
  99. printk(KERN_ERR PFX "Cannot map bridge registers\n");
  100. err = -EIO;
  101. goto fail_map_bridge;
  102. }
  103. hermes_io = pci_iomap(pdev, 2, 0);
  104. if (!hermes_io) {
  105. printk(KERN_ERR PFX "Cannot map chipset registers\n");
  106. err = -EIO;
  107. goto fail_map_hermes;
  108. }
  109. /* Allocate network device */
  110. dev = alloc_orinocodev(sizeof(*card), orinoco_tmd_cor_reset);
  111. if (!dev) {
  112. printk(KERN_ERR PFX "Cannot allocate network device\n");
  113. err = -ENOMEM;
  114. goto fail_alloc;
  115. }
  116. priv = netdev_priv(dev);
  117. card = priv->card;
  118. card->bridge_io = bridge_io;
  119. SET_NETDEV_DEV(dev, &pdev->dev);
  120. hermes_struct_init(&priv->hw, hermes_io, HERMES_16BIT_REGSPACING);
  121. err = request_irq(pdev->irq, orinoco_interrupt, IRQF_SHARED,
  122. dev->name, dev);
  123. if (err) {
  124. printk(KERN_ERR PFX "Cannot allocate IRQ %d\n", pdev->irq);
  125. err = -EBUSY;
  126. goto fail_irq;
  127. }
  128. err = orinoco_tmd_cor_reset(priv);
  129. if (err) {
  130. printk(KERN_ERR PFX "Initial reset failed\n");
  131. goto fail;
  132. }
  133. err = register_netdev(dev);
  134. if (err) {
  135. printk(KERN_ERR PFX "Cannot register network device\n");
  136. goto fail;
  137. }
  138. pci_set_drvdata(pdev, dev);
  139. printk(KERN_DEBUG "%s: " DRIVER_NAME " at %s\n", dev->name,
  140. pci_name(pdev));
  141. return 0;
  142. fail:
  143. free_irq(pdev->irq, dev);
  144. fail_irq:
  145. pci_set_drvdata(pdev, NULL);
  146. free_orinocodev(dev);
  147. fail_alloc:
  148. pci_iounmap(pdev, hermes_io);
  149. fail_map_hermes:
  150. pci_iounmap(pdev, bridge_io);
  151. fail_map_bridge:
  152. pci_release_regions(pdev);
  153. fail_resources:
  154. pci_disable_device(pdev);
  155. return err;
  156. }
  157. static void __devexit orinoco_tmd_remove_one(struct pci_dev *pdev)
  158. {
  159. struct net_device *dev = pci_get_drvdata(pdev);
  160. struct orinoco_private *priv = netdev_priv(dev);
  161. struct orinoco_pci_card *card = priv->card;
  162. unregister_netdev(dev);
  163. free_irq(pdev->irq, dev);
  164. pci_set_drvdata(pdev, NULL);
  165. free_orinocodev(dev);
  166. pci_iounmap(pdev, priv->hw.iobase);
  167. pci_iounmap(pdev, card->bridge_io);
  168. pci_release_regions(pdev);
  169. pci_disable_device(pdev);
  170. }
  171. static struct pci_device_id orinoco_tmd_id_table[] = {
  172. {0x15e8, 0x0131, PCI_ANY_ID, PCI_ANY_ID,}, /* NDC and OEMs, e.g. pheecom */
  173. {0,},
  174. };
  175. MODULE_DEVICE_TABLE(pci, orinoco_tmd_id_table);
  176. static struct pci_driver orinoco_tmd_driver = {
  177. .name = DRIVER_NAME,
  178. .id_table = orinoco_tmd_id_table,
  179. .probe = orinoco_tmd_init_one,
  180. .remove = __devexit_p(orinoco_tmd_remove_one),
  181. .suspend = orinoco_pci_suspend,
  182. .resume = orinoco_pci_resume,
  183. };
  184. static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
  185. " (Joerg Dorchain <joerg@dorchain.net>)";
  186. MODULE_AUTHOR("Joerg Dorchain <joerg@dorchain.net>");
  187. MODULE_DESCRIPTION("Driver for wireless LAN cards using the TMD7160 PCI bridge");
  188. MODULE_LICENSE("Dual MPL/GPL");
  189. static int __init orinoco_tmd_init(void)
  190. {
  191. printk(KERN_DEBUG "%s\n", version);
  192. return pci_register_driver(&orinoco_tmd_driver);
  193. }
  194. static void __exit orinoco_tmd_exit(void)
  195. {
  196. pci_unregister_driver(&orinoco_tmd_driver);
  197. }
  198. module_init(orinoco_tmd_init);
  199. module_exit(orinoco_tmd_exit);
  200. /*
  201. * Local variables:
  202. * c-indent-level: 8
  203. * c-basic-offset: 8
  204. * tab-width: 8
  205. * End:
  206. */