orinoco_tmd.c 6.5 KB

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