airport.c 6.6 KB

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