orinoco_tmd.c 6.3 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 main.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. struct hermes *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 + msecs_to_jiffies(TMD_RESET_TIME);
  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. void __iomem *hermes_io, *bridge_io;
  86. err = pci_enable_device(pdev);
  87. if (err) {
  88. printk(KERN_ERR PFX "Cannot enable PCI device\n");
  89. return err;
  90. }
  91. err = pci_request_regions(pdev, DRIVER_NAME);
  92. if (err) {
  93. printk(KERN_ERR PFX "Cannot obtain PCI resources\n");
  94. goto fail_resources;
  95. }
  96. bridge_io = pci_iomap(pdev, 1, 0);
  97. if (!bridge_io) {
  98. printk(KERN_ERR PFX "Cannot map bridge registers\n");
  99. err = -EIO;
  100. goto fail_map_bridge;
  101. }
  102. hermes_io = pci_iomap(pdev, 2, 0);
  103. if (!hermes_io) {
  104. printk(KERN_ERR PFX "Cannot map chipset registers\n");
  105. err = -EIO;
  106. goto fail_map_hermes;
  107. }
  108. /* Allocate network device */
  109. priv = alloc_orinocodev(sizeof(*card), &pdev->dev,
  110. orinoco_tmd_cor_reset, NULL);
  111. if (!priv) {
  112. printk(KERN_ERR PFX "Cannot allocate network device\n");
  113. err = -ENOMEM;
  114. goto fail_alloc;
  115. }
  116. card = priv->card;
  117. card->bridge_io = bridge_io;
  118. hermes_struct_init(&priv->hw, hermes_io, HERMES_16BIT_REGSPACING);
  119. err = request_irq(pdev->irq, orinoco_interrupt, IRQF_SHARED,
  120. DRIVER_NAME, priv);
  121. if (err) {
  122. printk(KERN_ERR PFX "Cannot allocate IRQ %d\n", pdev->irq);
  123. err = -EBUSY;
  124. goto fail_irq;
  125. }
  126. err = orinoco_tmd_cor_reset(priv);
  127. if (err) {
  128. printk(KERN_ERR PFX "Initial reset failed\n");
  129. goto fail;
  130. }
  131. err = orinoco_init(priv);
  132. if (err) {
  133. printk(KERN_ERR PFX "orinoco_init() failed\n");
  134. goto fail;
  135. }
  136. err = orinoco_if_add(priv, 0, 0, NULL);
  137. if (err) {
  138. printk(KERN_ERR PFX "orinoco_if_add() failed\n");
  139. goto fail;
  140. }
  141. pci_set_drvdata(pdev, priv);
  142. return 0;
  143. fail:
  144. free_irq(pdev->irq, priv);
  145. fail_irq:
  146. free_orinocodev(priv);
  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 orinoco_tmd_remove_one(struct pci_dev *pdev)
  158. {
  159. struct orinoco_private *priv = pci_get_drvdata(pdev);
  160. struct orinoco_pci_card *card = priv->card;
  161. orinoco_if_del(priv);
  162. free_irq(pdev->irq, priv);
  163. free_orinocodev(priv);
  164. pci_iounmap(pdev, priv->hw.iobase);
  165. pci_iounmap(pdev, card->bridge_io);
  166. pci_release_regions(pdev);
  167. pci_disable_device(pdev);
  168. }
  169. static const struct pci_device_id orinoco_tmd_id_table[] = {
  170. {0x15e8, 0x0131, PCI_ANY_ID, PCI_ANY_ID,}, /* NDC and OEMs, e.g. pheecom */
  171. {0,},
  172. };
  173. MODULE_DEVICE_TABLE(pci, orinoco_tmd_id_table);
  174. static struct pci_driver orinoco_tmd_driver = {
  175. .name = DRIVER_NAME,
  176. .id_table = orinoco_tmd_id_table,
  177. .probe = orinoco_tmd_init_one,
  178. .remove = orinoco_tmd_remove_one,
  179. .suspend = orinoco_pci_suspend,
  180. .resume = orinoco_pci_resume,
  181. };
  182. static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
  183. " (Joerg Dorchain <joerg@dorchain.net>)";
  184. MODULE_AUTHOR("Joerg Dorchain <joerg@dorchain.net>");
  185. MODULE_DESCRIPTION("Driver for wireless LAN cards using the TMD7160 PCI bridge");
  186. MODULE_LICENSE("Dual MPL/GPL");
  187. static int __init orinoco_tmd_init(void)
  188. {
  189. printk(KERN_DEBUG "%s\n", version);
  190. return pci_register_driver(&orinoco_tmd_driver);
  191. }
  192. static void __exit orinoco_tmd_exit(void)
  193. {
  194. pci_unregister_driver(&orinoco_tmd_driver);
  195. }
  196. module_init(orinoco_tmd_init);
  197. module_exit(orinoco_tmd_exit);
  198. /*
  199. * Local variables:
  200. * c-indent-level: 8
  201. * c-basic-offset: 8
  202. * tab-width: 8
  203. * End:
  204. */