3 * A driver for "Hermes" chipset based Apple Airport wireless
6 * Copyright notice & release notes in file orinoco.c
8 * Note specific to airport stub:
10 * 0.05 : first version of the new split driver
11 * 0.06 : fix possible hang on powerup, add sleep support
14 #define DRIVER_NAME "airport"
15 #define PFX DRIVER_NAME ": "
17 #include <linux/config.h>
18 #include <linux/module.h>
19 #include <linux/kernel.h>
20 #include <linux/init.h>
21 #include <linux/delay.h>
22 #include <asm/pmac_feature.h>
26 #define AIRPORT_IO_LEN (0x1000) /* one page */
29 struct macio_dev *mdev;
36 airport_suspend(struct macio_dev *mdev, pm_message_t state)
38 struct net_device *dev = dev_get_drvdata(&mdev->ofdev.dev);
39 struct orinoco_private *priv = netdev_priv(dev);
43 printk(KERN_DEBUG "%s: Airport entering sleep mode\n", dev->name);
45 err = orinoco_lock(priv, &flags);
47 printk(KERN_ERR "%s: hw_unavailable on PBOOK_SLEEP_NOW\n",
52 err = __orinoco_down(dev);
54 printk(KERN_WARNING "%s: PBOOK_SLEEP_NOW: Error %d downing interface\n",
57 netif_device_detach(dev);
59 priv->hw_unavailable++;
61 orinoco_unlock(priv, &flags);
63 disable_irq(dev->irq);
64 pmac_call_feature(PMAC_FTR_AIRPORT_ENABLE, macio_get_of_node(mdev), 0, 0);
70 airport_resume(struct macio_dev *mdev)
72 struct net_device *dev = dev_get_drvdata(&mdev->ofdev.dev);
73 struct orinoco_private *priv = netdev_priv(dev);
77 printk(KERN_DEBUG "%s: Airport waking up\n", dev->name);
79 pmac_call_feature(PMAC_FTR_AIRPORT_ENABLE, macio_get_of_node(mdev), 0, 1);
84 err = orinoco_reinit_firmware(dev);
86 printk(KERN_ERR "%s: Error %d re-initializing firmware on PBOOK_WAKE\n",
91 spin_lock_irqsave(&priv->lock, flags);
93 netif_device_attach(dev);
95 priv->hw_unavailable--;
97 if (priv->open && (! priv->hw_unavailable)) {
98 err = __orinoco_up(dev);
100 printk(KERN_ERR "%s: Error %d restarting card on PBOOK_WAKE\n",
105 spin_unlock_irqrestore(&priv->lock, flags);
111 airport_detach(struct macio_dev *mdev)
113 struct net_device *dev = dev_get_drvdata(&mdev->ofdev.dev);
114 struct orinoco_private *priv = netdev_priv(dev);
115 struct airport *card = priv->card;
117 if (card->ndev_registered)
118 unregister_netdev(dev);
119 card->ndev_registered = 0;
121 if (card->irq_requested)
122 free_irq(dev->irq, dev);
123 card->irq_requested = 0;
126 iounmap(card->vaddr);
129 macio_release_resource(mdev, 0);
131 pmac_call_feature(PMAC_FTR_AIRPORT_ENABLE, macio_get_of_node(mdev), 0, 0);
134 macio_set_drvdata(mdev, NULL);
135 free_orinocodev(dev);
140 static int airport_hard_reset(struct orinoco_private *priv)
142 /* It would be nice to power cycle the Airport for a real hard
143 * reset, but for some reason although it appears to
144 * re-initialize properly, it falls in a screaming heap
145 * shortly afterwards. */
147 struct net_device *dev = priv->ndev;
148 struct airport *card = priv->card;
150 /* Vitally important. If we don't do this it seems we get an
151 * interrupt somewhere during the power cycle, since
152 * hw_unavailable is already set it doesn't get ACKed, we get
153 * into an interrupt loop and the the PMU decides to turn us
155 disable_irq(dev->irq);
157 pmac_call_feature(PMAC_FTR_AIRPORT_ENABLE, macio_get_of_node(card->mdev), 0, 0);
159 pmac_call_feature(PMAC_FTR_AIRPORT_ENABLE, macio_get_of_node(card->mdev), 0, 1);
162 enable_irq(dev->irq);
170 airport_attach(struct macio_dev *mdev, const struct of_device_id *match)
172 struct orinoco_private *priv;
173 struct net_device *dev;
174 struct airport *card;
175 unsigned long phys_addr;
178 if (macio_resource_count(mdev) < 1 || macio_irq_count(mdev) < 1) {
179 printk(KERN_ERR PFX "Wrong interrupt/addresses in OF tree\n");
183 /* Allocate space for private device-specific data */
184 dev = alloc_orinocodev(sizeof(*card), airport_hard_reset);
186 printk(KERN_ERR PFX "Cannot allocate network device\n");
189 priv = netdev_priv(dev);
195 if (macio_request_resource(mdev, 0, "airport")) {
196 printk(KERN_ERR PFX "can't request IO resource !\n");
197 free_orinocodev(dev);
201 SET_MODULE_OWNER(dev);
202 SET_NETDEV_DEV(dev, &mdev->ofdev.dev);
204 macio_set_drvdata(mdev, dev);
206 /* Setup interrupts & base address */
207 dev->irq = macio_irq(mdev, 0);
208 phys_addr = macio_resource_start(mdev, 0); /* Physical address */
209 printk(KERN_DEBUG PFX "Physical address %lx\n", phys_addr);
210 dev->base_addr = phys_addr;
211 card->vaddr = ioremap(phys_addr, AIRPORT_IO_LEN);
213 printk(KERN_ERR PFX "ioremap() failed\n");
217 hermes_struct_init(hw, card->vaddr, HERMES_16BIT_REGSPACING);
220 pmac_call_feature(PMAC_FTR_AIRPORT_ENABLE, macio_get_of_node(mdev), 0, 1);
223 /* Reset it before we get the interrupt */
226 if (request_irq(dev->irq, orinoco_interrupt, 0, dev->name, dev)) {
227 printk(KERN_ERR PFX "Couldn't get IRQ %d\n", dev->irq);
230 card->irq_requested = 1;
232 /* Tell the stack we exist */
233 if (register_netdev(dev) != 0) {
234 printk(KERN_ERR PFX "register_netdev() failed\n");
237 printk(KERN_DEBUG PFX "Card registered for interface %s\n", dev->name);
238 card->ndev_registered = 1;
241 airport_detach(mdev);
243 } /* airport_attach */
246 static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
247 " (Benjamin Herrenschmidt <benh@kernel.crashing.org>)";
248 MODULE_AUTHOR("Benjamin Herrenschmidt <benh@kernel.crashing.org>");
249 MODULE_DESCRIPTION("Driver for the Apple Airport wireless card.");
250 MODULE_LICENSE("Dual MPL/GPL");
252 static struct of_device_id airport_match[] =
260 MODULE_DEVICE_TABLE (of, airport_match);
262 static struct macio_driver airport_driver =
265 .match_table = airport_match,
266 .probe = airport_attach,
267 .remove = airport_detach,
268 .suspend = airport_suspend,
269 .resume = airport_resume,
275 printk(KERN_DEBUG "%s\n", version);
277 return macio_register_driver(&airport_driver);
283 return macio_unregister_driver(&airport_driver);
286 module_init(init_airport);
287 module_exit(exit_airport);