Back to home page

OSCL-LXR

 
 

    


0001 /* airport.c
0002  *
0003  * A driver for "Hermes" chipset based Apple Airport wireless
0004  * card.
0005  *
0006  * Copyright notice & release notes in file main.c
0007  *
0008  * Note specific to airport stub:
0009  *
0010  *  0.05 : first version of the new split driver
0011  *  0.06 : fix possible hang on powerup, add sleep support
0012  */
0013 
0014 #define DRIVER_NAME "airport"
0015 #define PFX DRIVER_NAME ": "
0016 
0017 #include <linux/module.h>
0018 #include <linux/kernel.h>
0019 #include <linux/init.h>
0020 #include <linux/delay.h>
0021 #include <linux/of_device.h>
0022 #include <asm/pmac_feature.h>
0023 
0024 #include "orinoco.h"
0025 
0026 #define AIRPORT_IO_LEN  (0x1000)    /* one page */
0027 
0028 struct airport {
0029     struct macio_dev *mdev;
0030     void __iomem *vaddr;
0031     unsigned int irq;
0032     int irq_requested;
0033     int ndev_registered;
0034 };
0035 
0036 static int
0037 airport_suspend(struct macio_dev *mdev, pm_message_t state)
0038 {
0039     struct orinoco_private *priv = dev_get_drvdata(&mdev->ofdev.dev);
0040     struct net_device *dev = priv->ndev;
0041     struct airport *card = priv->card;
0042     unsigned long flags;
0043     int err;
0044 
0045     printk(KERN_DEBUG "%s: Airport entering sleep mode\n", dev->name);
0046 
0047     err = orinoco_lock(priv, &flags);
0048     if (err) {
0049         printk(KERN_ERR "%s: hw_unavailable on PBOOK_SLEEP_NOW\n",
0050                dev->name);
0051         return 0;
0052     }
0053 
0054     orinoco_down(priv);
0055     orinoco_unlock(priv, &flags);
0056 
0057     disable_irq(card->irq);
0058     pmac_call_feature(PMAC_FTR_AIRPORT_ENABLE,
0059               macio_get_of_node(mdev), 0, 0);
0060 
0061     return 0;
0062 }
0063 
0064 static int
0065 airport_resume(struct macio_dev *mdev)
0066 {
0067     struct orinoco_private *priv = dev_get_drvdata(&mdev->ofdev.dev);
0068     struct net_device *dev = priv->ndev;
0069     struct airport *card = priv->card;
0070     unsigned long flags;
0071     int err;
0072 
0073     printk(KERN_DEBUG "%s: Airport waking up\n", dev->name);
0074 
0075     pmac_call_feature(PMAC_FTR_AIRPORT_ENABLE,
0076               macio_get_of_node(mdev), 0, 1);
0077     msleep(200);
0078 
0079     enable_irq(card->irq);
0080 
0081     priv->hw.ops->lock_irqsave(&priv->lock, &flags);
0082     err = orinoco_up(priv);
0083     priv->hw.ops->unlock_irqrestore(&priv->lock, &flags);
0084 
0085     return err;
0086 }
0087 
0088 static int
0089 airport_detach(struct macio_dev *mdev)
0090 {
0091     struct orinoco_private *priv = dev_get_drvdata(&mdev->ofdev.dev);
0092     struct airport *card = priv->card;
0093 
0094     if (card->ndev_registered)
0095         orinoco_if_del(priv);
0096     card->ndev_registered = 0;
0097 
0098     if (card->irq_requested)
0099         free_irq(card->irq, priv);
0100     card->irq_requested = 0;
0101 
0102     if (card->vaddr)
0103         iounmap(card->vaddr);
0104     card->vaddr = NULL;
0105 
0106     macio_release_resource(mdev, 0);
0107 
0108     pmac_call_feature(PMAC_FTR_AIRPORT_ENABLE,
0109               macio_get_of_node(mdev), 0, 0);
0110     ssleep(1);
0111 
0112     macio_set_drvdata(mdev, NULL);
0113     free_orinocodev(priv);
0114 
0115     return 0;
0116 }
0117 
0118 static int airport_hard_reset(struct orinoco_private *priv)
0119 {
0120     /* It would be nice to power cycle the Airport for a real hard
0121      * reset, but for some reason although it appears to
0122      * re-initialize properly, it falls in a screaming heap
0123      * shortly afterwards. */
0124 #if 0
0125     struct airport *card = priv->card;
0126 
0127     /* Vitally important.  If we don't do this it seems we get an
0128      * interrupt somewhere during the power cycle, since
0129      * hw_unavailable is already set it doesn't get ACKed, we get
0130      * into an interrupt loop and the PMU decides to turn us
0131      * off. */
0132     disable_irq(card->irq);
0133 
0134     pmac_call_feature(PMAC_FTR_AIRPORT_ENABLE,
0135               macio_get_of_node(card->mdev), 0, 0);
0136     ssleep(1);
0137     pmac_call_feature(PMAC_FTR_AIRPORT_ENABLE,
0138               macio_get_of_node(card->mdev), 0, 1);
0139     ssleep(1);
0140 
0141     enable_irq(card->irq);
0142     ssleep(1);
0143 #endif
0144 
0145     return 0;
0146 }
0147 
0148 static int
0149 airport_attach(struct macio_dev *mdev, const struct of_device_id *match)
0150 {
0151     struct orinoco_private *priv;
0152     struct airport *card;
0153     unsigned long phys_addr;
0154     struct hermes *hw;
0155 
0156     if (macio_resource_count(mdev) < 1 || macio_irq_count(mdev) < 1) {
0157         printk(KERN_ERR PFX "Wrong interrupt/addresses in OF tree\n");
0158         return -ENODEV;
0159     }
0160 
0161     /* Allocate space for private device-specific data */
0162     priv = alloc_orinocodev(sizeof(*card), &mdev->ofdev.dev,
0163                 airport_hard_reset, NULL);
0164     if (!priv) {
0165         printk(KERN_ERR PFX "Cannot allocate network device\n");
0166         return -ENODEV;
0167     }
0168     card = priv->card;
0169 
0170     hw = &priv->hw;
0171     card->mdev = mdev;
0172 
0173     if (macio_request_resource(mdev, 0, DRIVER_NAME)) {
0174         printk(KERN_ERR PFX "can't request IO resource !\n");
0175         free_orinocodev(priv);
0176         return -EBUSY;
0177     }
0178 
0179     macio_set_drvdata(mdev, priv);
0180 
0181     /* Setup interrupts & base address */
0182     card->irq = macio_irq(mdev, 0);
0183     phys_addr = macio_resource_start(mdev, 0);  /* Physical address */
0184     printk(KERN_DEBUG PFX "Physical address %lx\n", phys_addr);
0185     card->vaddr = ioremap(phys_addr, AIRPORT_IO_LEN);
0186     if (!card->vaddr) {
0187         printk(KERN_ERR PFX "ioremap() failed\n");
0188         goto failed;
0189     }
0190 
0191     hermes_struct_init(hw, card->vaddr, HERMES_16BIT_REGSPACING);
0192 
0193     /* Power up card */
0194     pmac_call_feature(PMAC_FTR_AIRPORT_ENABLE,
0195               macio_get_of_node(mdev), 0, 1);
0196     ssleep(1);
0197 
0198     /* Reset it before we get the interrupt */
0199     hw->ops->init(hw);
0200 
0201     if (request_irq(card->irq, orinoco_interrupt, 0, DRIVER_NAME, priv)) {
0202         printk(KERN_ERR PFX "Couldn't get IRQ %d\n", card->irq);
0203         goto failed;
0204     }
0205     card->irq_requested = 1;
0206 
0207     /* Initialise the main driver */
0208     if (orinoco_init(priv) != 0) {
0209         printk(KERN_ERR PFX "orinoco_init() failed\n");
0210         goto failed;
0211     }
0212 
0213     /* Register an interface with the stack */
0214     if (orinoco_if_add(priv, phys_addr, card->irq, NULL) != 0) {
0215         printk(KERN_ERR PFX "orinoco_if_add() failed\n");
0216         goto failed;
0217     }
0218     card->ndev_registered = 1;
0219     return 0;
0220  failed:
0221     airport_detach(mdev);
0222     return -ENODEV;
0223 }               /* airport_attach */
0224 
0225 
0226 static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
0227     " (Benjamin Herrenschmidt <benh@kernel.crashing.org>)";
0228 MODULE_AUTHOR("Benjamin Herrenschmidt <benh@kernel.crashing.org>");
0229 MODULE_DESCRIPTION("Driver for the Apple Airport wireless card.");
0230 MODULE_LICENSE("Dual MPL/GPL");
0231 
0232 static const struct of_device_id airport_match[] = {
0233     {
0234     .name       = "radio",
0235     },
0236     {},
0237 };
0238 
0239 MODULE_DEVICE_TABLE(of, airport_match);
0240 
0241 static struct macio_driver airport_driver = {
0242     .driver = {
0243         .name       = DRIVER_NAME,
0244         .owner      = THIS_MODULE,
0245         .of_match_table = airport_match,
0246     },
0247     .probe      = airport_attach,
0248     .remove     = airport_detach,
0249     .suspend    = airport_suspend,
0250     .resume     = airport_resume,
0251 };
0252 
0253 static int __init
0254 init_airport(void)
0255 {
0256     printk(KERN_DEBUG "%s\n", version);
0257 
0258     return macio_register_driver(&airport_driver);
0259 }
0260 
0261 static void __exit
0262 exit_airport(void)
0263 {
0264     macio_unregister_driver(&airport_driver);
0265 }
0266 
0267 module_init(init_airport);
0268 module_exit(exit_airport);