airport.c 6.6 KB

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