airport.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. /* airport.c
  2. *
  3. * A driver for "Hermes" chipset based Apple Airport wireless
  4. * card.
  5. *
  6. * Copyright notice & release notes in file main.c
  7. *
  8. * Note specific to airport stub:
  9. *
  10. * 0.05 : first version of the new split driver
  11. * 0.06 : fix possible hang on powerup, add sleep support
  12. */
  13. #define DRIVER_NAME "airport"
  14. #define PFX DRIVER_NAME ": "
  15. #include <linux/module.h>
  16. #include <linux/kernel.h>
  17. #include <linux/init.h>
  18. #include <linux/delay.h>
  19. #include <asm/pmac_feature.h>
  20. #include "orinoco.h"
  21. #define AIRPORT_IO_LEN (0x1000) /* one page */
  22. struct airport {
  23. struct macio_dev *mdev;
  24. void __iomem *vaddr;
  25. int irq_requested;
  26. int ndev_registered;
  27. };
  28. static int
  29. airport_suspend(struct macio_dev *mdev, pm_message_t state)
  30. {
  31. struct net_device *dev = dev_get_drvdata(&mdev->ofdev.dev);
  32. struct orinoco_private *priv = netdev_priv(dev);
  33. unsigned long flags;
  34. int err;
  35. printk(KERN_DEBUG "%s: Airport entering sleep mode\n", dev->name);
  36. err = orinoco_lock(priv, &flags);
  37. if (err) {
  38. printk(KERN_ERR "%s: hw_unavailable on PBOOK_SLEEP_NOW\n",
  39. dev->name);
  40. return 0;
  41. }
  42. err = __orinoco_down(dev);
  43. if (err)
  44. printk(KERN_WARNING "%s: PBOOK_SLEEP_NOW: Error %d downing interface\n",
  45. dev->name, err);
  46. netif_device_detach(dev);
  47. priv->hw_unavailable++;
  48. orinoco_unlock(priv, &flags);
  49. disable_irq(dev->irq);
  50. pmac_call_feature(PMAC_FTR_AIRPORT_ENABLE,
  51. macio_get_of_node(mdev), 0, 0);
  52. return 0;
  53. }
  54. static int
  55. airport_resume(struct macio_dev *mdev)
  56. {
  57. struct net_device *dev = dev_get_drvdata(&mdev->ofdev.dev);
  58. struct orinoco_private *priv = netdev_priv(dev);
  59. unsigned long flags;
  60. int err;
  61. printk(KERN_DEBUG "%s: Airport waking up\n", dev->name);
  62. pmac_call_feature(PMAC_FTR_AIRPORT_ENABLE,
  63. macio_get_of_node(mdev), 0, 1);
  64. msleep(200);
  65. enable_irq(dev->irq);
  66. err = orinoco_reinit_firmware(dev);
  67. if (err) {
  68. printk(KERN_ERR "%s: Error %d re-initializing firmware on PBOOK_WAKE\n",
  69. dev->name, err);
  70. return 0;
  71. }
  72. spin_lock_irqsave(&priv->lock, flags);
  73. netif_device_attach(dev);
  74. priv->hw_unavailable--;
  75. if (priv->open && (!priv->hw_unavailable)) {
  76. err = __orinoco_up(dev);
  77. if (err)
  78. printk(KERN_ERR "%s: Error %d restarting card on PBOOK_WAKE\n",
  79. dev->name, err);
  80. }
  81. spin_unlock_irqrestore(&priv->lock, flags);
  82. return 0;
  83. }
  84. static int
  85. airport_detach(struct macio_dev *mdev)
  86. {
  87. struct net_device *dev = dev_get_drvdata(&mdev->ofdev.dev);
  88. struct orinoco_private *priv = netdev_priv(dev);
  89. struct airport *card = priv->card;
  90. if (card->ndev_registered)
  91. unregister_netdev(dev);
  92. card->ndev_registered = 0;
  93. if (card->irq_requested)
  94. free_irq(dev->irq, dev);
  95. card->irq_requested = 0;
  96. if (card->vaddr)
  97. iounmap(card->vaddr);
  98. card->vaddr = NULL;
  99. macio_release_resource(mdev, 0);
  100. pmac_call_feature(PMAC_FTR_AIRPORT_ENABLE,
  101. macio_get_of_node(mdev), 0, 0);
  102. ssleep(1);
  103. macio_set_drvdata(mdev, NULL);
  104. free_orinocodev(dev);
  105. return 0;
  106. }
  107. static int airport_hard_reset(struct orinoco_private *priv)
  108. {
  109. /* It would be nice to power cycle the Airport for a real hard
  110. * reset, but for some reason although it appears to
  111. * re-initialize properly, it falls in a screaming heap
  112. * shortly afterwards. */
  113. #if 0
  114. struct net_device *dev = priv->ndev;
  115. struct airport *card = priv->card;
  116. /* Vitally important. If we don't do this it seems we get an
  117. * interrupt somewhere during the power cycle, since
  118. * hw_unavailable is already set it doesn't get ACKed, we get
  119. * into an interrupt loop and the PMU decides to turn us
  120. * off. */
  121. disable_irq(dev->irq);
  122. pmac_call_feature(PMAC_FTR_AIRPORT_ENABLE,
  123. macio_get_of_node(card->mdev), 0, 0);
  124. ssleep(1);
  125. pmac_call_feature(PMAC_FTR_AIRPORT_ENABLE,
  126. macio_get_of_node(card->mdev), 0, 1);
  127. ssleep(1);
  128. enable_irq(dev->irq);
  129. ssleep(1);
  130. #endif
  131. return 0;
  132. }
  133. static int
  134. airport_attach(struct macio_dev *mdev, const struct of_device_id *match)
  135. {
  136. struct orinoco_private *priv;
  137. struct net_device *dev;
  138. struct airport *card;
  139. unsigned long phys_addr;
  140. hermes_t *hw;
  141. if (macio_resource_count(mdev) < 1 || macio_irq_count(mdev) < 1) {
  142. printk(KERN_ERR PFX "Wrong interrupt/addresses in OF tree\n");
  143. return -ENODEV;
  144. }
  145. /* Allocate space for private device-specific data */
  146. dev = alloc_orinocodev(sizeof(*card), &mdev->ofdev.dev,
  147. airport_hard_reset, NULL);
  148. if (!dev) {
  149. printk(KERN_ERR PFX "Cannot allocate network device\n");
  150. return -ENODEV;
  151. }
  152. priv = netdev_priv(dev);
  153. card = priv->card;
  154. hw = &priv->hw;
  155. card->mdev = mdev;
  156. if (macio_request_resource(mdev, 0, "airport")) {
  157. printk(KERN_ERR PFX "can't request IO resource !\n");
  158. free_orinocodev(dev);
  159. return -EBUSY;
  160. }
  161. SET_NETDEV_DEV(dev, &mdev->ofdev.dev);
  162. macio_set_drvdata(mdev, dev);
  163. /* Setup interrupts & base address */
  164. dev->irq = macio_irq(mdev, 0);
  165. phys_addr = macio_resource_start(mdev, 0); /* Physical address */
  166. printk(KERN_DEBUG PFX "Physical address %lx\n", phys_addr);
  167. dev->base_addr = phys_addr;
  168. card->vaddr = ioremap(phys_addr, AIRPORT_IO_LEN);
  169. if (!card->vaddr) {
  170. printk(KERN_ERR PFX "ioremap() failed\n");
  171. goto failed;
  172. }
  173. hermes_struct_init(hw, card->vaddr, HERMES_16BIT_REGSPACING);
  174. /* Power up card */
  175. pmac_call_feature(PMAC_FTR_AIRPORT_ENABLE,
  176. macio_get_of_node(mdev), 0, 1);
  177. ssleep(1);
  178. /* Reset it before we get the interrupt */
  179. hermes_init(hw);
  180. if (request_irq(dev->irq, orinoco_interrupt, 0, dev->name, dev)) {
  181. printk(KERN_ERR PFX "Couldn't get IRQ %d\n", dev->irq);
  182. goto failed;
  183. }
  184. card->irq_requested = 1;
  185. /* Tell the stack we exist */
  186. if (register_netdev(dev) != 0) {
  187. printk(KERN_ERR PFX "register_netdev() failed\n");
  188. goto failed;
  189. }
  190. printk(KERN_DEBUG PFX "Card registered for interface %s\n", dev->name);
  191. card->ndev_registered = 1;
  192. return 0;
  193. failed:
  194. airport_detach(mdev);
  195. return -ENODEV;
  196. } /* airport_attach */
  197. static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
  198. " (Benjamin Herrenschmidt <benh@kernel.crashing.org>)";
  199. MODULE_AUTHOR("Benjamin Herrenschmidt <benh@kernel.crashing.org>");
  200. MODULE_DESCRIPTION("Driver for the Apple Airport wireless card.");
  201. MODULE_LICENSE("Dual MPL/GPL");
  202. static struct of_device_id airport_match[] =
  203. {
  204. {
  205. .name = "radio",
  206. },
  207. {},
  208. };
  209. MODULE_DEVICE_TABLE(of, airport_match);
  210. static struct macio_driver airport_driver = {
  211. .name = DRIVER_NAME,
  212. .match_table = airport_match,
  213. .probe = airport_attach,
  214. .remove = airport_detach,
  215. .suspend = airport_suspend,
  216. .resume = airport_resume,
  217. };
  218. static int __init
  219. init_airport(void)
  220. {
  221. printk(KERN_DEBUG "%s\n", version);
  222. return macio_register_driver(&airport_driver);
  223. }
  224. static void __exit
  225. exit_airport(void)
  226. {
  227. macio_unregister_driver(&airport_driver);
  228. }
  229. module_init(init_airport);
  230. module_exit(exit_airport);