orinoco_tmd.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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. orinoco_pci_setup_netdev(dev, pdev, 2);
  131. err = orinoco_tmd_cor_reset(priv);
  132. if (err) {
  133. printk(KERN_ERR PFX "Initial reset failed\n");
  134. goto fail;
  135. }
  136. err = register_netdev(dev);
  137. if (err) {
  138. printk(KERN_ERR PFX "Cannot register network device\n");
  139. goto fail;
  140. }
  141. pci_set_drvdata(pdev, dev);
  142. return 0;
  143. fail:
  144. free_irq(pdev->irq, dev);
  145. fail_irq:
  146. pci_set_drvdata(pdev, NULL);
  147. free_orinocodev(dev);
  148. fail_alloc:
  149. pci_iounmap(pdev, hermes_io);
  150. fail_map_hermes:
  151. pci_iounmap(pdev, bridge_io);
  152. fail_map_bridge:
  153. pci_release_regions(pdev);
  154. fail_resources:
  155. pci_disable_device(pdev);
  156. return err;
  157. }
  158. static void __devexit orinoco_tmd_remove_one(struct pci_dev *pdev)
  159. {
  160. struct net_device *dev = pci_get_drvdata(pdev);
  161. struct orinoco_private *priv = dev->priv;
  162. struct orinoco_pci_card *card = priv->card;
  163. unregister_netdev(dev);
  164. free_irq(dev->irq, dev);
  165. pci_set_drvdata(pdev, NULL);
  166. free_orinocodev(dev);
  167. pci_iounmap(pdev, priv->hw.iobase);
  168. pci_iounmap(pdev, card->bridge_io);
  169. pci_release_regions(pdev);
  170. pci_disable_device(pdev);
  171. }
  172. static struct pci_device_id orinoco_tmd_id_table[] = {
  173. {0x15e8, 0x0131, PCI_ANY_ID, PCI_ANY_ID,}, /* NDC and OEMs, e.g. pheecom */
  174. {0,},
  175. };
  176. MODULE_DEVICE_TABLE(pci, orinoco_tmd_id_table);
  177. static struct pci_driver orinoco_tmd_driver = {
  178. .name = DRIVER_NAME,
  179. .id_table = orinoco_tmd_id_table,
  180. .probe = orinoco_tmd_init_one,
  181. .remove = __devexit_p(orinoco_tmd_remove_one),
  182. .suspend = orinoco_pci_suspend,
  183. .resume = orinoco_pci_resume,
  184. };
  185. static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
  186. " (Joerg Dorchain <joerg@dorchain.net>)";
  187. MODULE_AUTHOR("Joerg Dorchain <joerg@dorchain.net>");
  188. MODULE_DESCRIPTION("Driver for wireless LAN cards using the TMD7160 PCI bridge");
  189. MODULE_LICENSE("Dual MPL/GPL");
  190. static int __init orinoco_tmd_init(void)
  191. {
  192. printk(KERN_DEBUG "%s\n", version);
  193. return pci_module_init(&orinoco_tmd_driver);
  194. }
  195. static void __exit orinoco_tmd_exit(void)
  196. {
  197. pci_unregister_driver(&orinoco_tmd_driver);
  198. }
  199. module_init(orinoco_tmd_init);
  200. module_exit(orinoco_tmd_exit);
  201. /*
  202. * Local variables:
  203. * c-indent-level: 8
  204. * c-basic-offset: 8
  205. * tab-width: 8
  206. * End:
  207. */