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 14#define DRIVER_NAME "airport" 15#define PFX DRIVER_NAME ": " 16 17#include <linux/module.h> 18#include <linux/kernel.h> 19#include <linux/init.h> 20#include <linux/delay.h> 21#include <asm/pmac_feature.h> 22 23#include "orinoco.h" 24 25#define AIRPORT_IO_LEN (0x1000) /* one page */ 26 27struct airport { 28 struct macio_dev *mdev; 29 void __iomem *vaddr; 30 unsigned int irq; 31 int irq_requested; 32 int ndev_registered; 33}; 34 35static int 36airport_suspend(struct macio_dev *mdev, pm_message_t state) 37{ 38 struct orinoco_private *priv = dev_get_drvdata(&mdev->ofdev.dev); 39 struct net_device *dev = priv->ndev; 40 struct airport *card = priv->card; 41 unsigned long flags; 42 int err; 43 44 printk(KERN_DEBUG "%s: Airport entering sleep mode\n", dev->name); 45 46 err = orinoco_lock(priv, &flags); 47 if (err) { 48 printk(KERN_ERR "%s: hw_unavailable on PBOOK_SLEEP_NOW\n", 49 dev->name); 50 return 0; 51 } 52 53 orinoco_down(priv); 54 orinoco_unlock(priv, &flags); 55 56 disable_irq(card->irq); 57 pmac_call_feature(PMAC_FTR_AIRPORT_ENABLE, 58 macio_get_of_node(mdev), 0, 0); 59 60 return 0; 61} 62 63static int 64airport_resume(struct macio_dev *mdev) 65{ 66 struct orinoco_private *priv = dev_get_drvdata(&mdev->ofdev.dev); 67 struct net_device *dev = priv->ndev; 68 struct airport *card = priv->card; 69 unsigned long flags; 70 int err; 71 72 printk(KERN_DEBUG "%s: Airport waking up\n", dev->name); 73 74 pmac_call_feature(PMAC_FTR_AIRPORT_ENABLE, 75 macio_get_of_node(mdev), 0, 1); 76 msleep(200); 77 78 enable_irq(card->irq); 79 80 priv->hw.ops->lock_irqsave(&priv->lock, &flags); 81 err = orinoco_up(priv); 82 priv->hw.ops->unlock_irqrestore(&priv->lock, &flags); 83 84 return err; 85} 86 87static int 88airport_detach(struct macio_dev *mdev) 89{ 90 struct orinoco_private *priv = dev_get_drvdata(&mdev->ofdev.dev); 91 struct airport *card = priv->card; 92 93 if (card->ndev_registered) 94 orinoco_if_del(priv); 95 card->ndev_registered = 0; 96 97 if (card->irq_requested) 98 free_irq(card->irq, priv); 99 card->irq_requested = 0; 100 101 if (card->vaddr) 102 iounmap(card->vaddr); 103 card->vaddr = NULL; 104 105 macio_release_resource(mdev, 0); 106 107 pmac_call_feature(PMAC_FTR_AIRPORT_ENABLE, 108 macio_get_of_node(mdev), 0, 0); 109 ssleep(1); 110 111 macio_set_drvdata(mdev, NULL); 112 free_orinocodev(priv); 113 114 return 0; 115} 116 117static int airport_hard_reset(struct orinoco_private *priv) 118{ 119 /* It would be nice to power cycle the Airport for a real hard 120 * reset, but for some reason although it appears to 121 * re-initialize properly, it falls in a screaming heap 122 * shortly afterwards. */ 123 124 return 0; 125} 126 127static int 128airport_attach(struct macio_dev *mdev, const struct of_device_id *match) 129{ 130 struct orinoco_private *priv; 131 struct airport *card; 132 unsigned long phys_addr; 133 hermes_t *hw; 134 135 if (macio_resource_count(mdev) < 1 || macio_irq_count(mdev) < 1) { 136 printk(KERN_ERR PFX "Wrong interrupt/addresses in OF tree\n"); 137 return -ENODEV; 138 } 139 140 /* Allocate space for private device-specific data */ 141 priv = alloc_orinocodev(sizeof(*card), &mdev->ofdev.dev, 142 airport_hard_reset, NULL); 143 if (!priv) { 144 printk(KERN_ERR PFX "Cannot allocate network device\n"); 145 return -ENODEV; 146 } 147 card = priv->card; 148 149 hw = &priv->hw; 150 card->mdev = mdev; 151 152 if (macio_request_resource(mdev, 0, DRIVER_NAME)) { 153 printk(KERN_ERR PFX "can't request IO resource !\n"); 154 free_orinocodev(priv); 155 return -EBUSY; 156 } 157 158 macio_set_drvdata(mdev, priv); 159 160 /* Setup interrupts & base address */ 161 card->irq = macio_irq(mdev, 0); 162 phys_addr = macio_resource_start(mdev, 0); /* Physical address */ 163 printk(KERN_DEBUG PFX "Physical address %lx\n", 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 170 hermes_struct_init(hw, card->vaddr, HERMES_16BIT_REGSPACING); 171 172 /* Power up card */ 173 pmac_call_feature(PMAC_FTR_AIRPORT_ENABLE, 174 macio_get_of_node(mdev), 0, 1); 175 ssleep(1); 176 177 /* Reset it before we get the interrupt */ 178 hw->ops->init(hw); 179 180 if (request_irq(card->irq, orinoco_interrupt, 0, DRIVER_NAME, priv)) { 181 printk(KERN_ERR PFX "Couldn't get IRQ %d\n", card->irq); 182 goto failed; 183 } 184 card->irq_requested = 1; 185 186 /* Initialise the main driver */ 187 if (orinoco_init(priv) != 0) { 188 printk(KERN_ERR PFX "orinoco_init() failed\n"); 189 goto failed; 190 } 191 192 /* Register an interface with the stack */ 193 if (orinoco_if_add(priv, phys_addr, card->irq, NULL) != 0) { 194 printk(KERN_ERR PFX "orinoco_if_add() failed\n"); 195 goto failed; 196 } 197 card->ndev_registered = 1; 198 return 0; 199 failed: 200 airport_detach(mdev); 201 return -ENODEV; 202} /* airport_attach */ 203 204 205static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION 206 " (Benjamin Herrenschmidt <benh@kernel.crashing.org>)"; 207MODULE_AUTHOR("Benjamin Herrenschmidt <benh@kernel.crashing.org>"); 208MODULE_DESCRIPTION("Driver for the Apple Airport wireless card."); 209MODULE_LICENSE("Dual MPL/GPL"); 210 211static struct of_device_id airport_match[] = 212{ 213 { 214 .name = "radio", 215 }, 216 {}, 217}; 218 219MODULE_DEVICE_TABLE(of, airport_match); 220 221static struct macio_driver airport_driver = { 222 .driver = { 223 .name = DRIVER_NAME, 224 .owner = THIS_MODULE, 225 .of_match_table = airport_match, 226 }, 227 .probe = airport_attach, 228 .remove = airport_detach, 229 .suspend = airport_suspend, 230 .resume = airport_resume, 231}; 232 233static int __init 234init_airport(void) 235{ 236 printk(KERN_DEBUG "%s\n", version); 237 238 return macio_register_driver(&airport_driver); 239} 240 241static void __exit 242exit_airport(void) 243{ 244 macio_unregister_driver(&airport_driver); 245} 246 247module_init(init_airport); 248module_exit(exit_airport); 249