2005-04-17 06:20:36 +08:00
|
|
|
/* airport.c
|
|
|
|
*
|
|
|
|
* A driver for "Hermes" chipset based Apple Airport wireless
|
|
|
|
* card.
|
|
|
|
*
|
2009-02-05 07:05:48 +08:00
|
|
|
* Copyright notice & release notes in file main.c
|
2009-01-26 04:08:43 +08:00
|
|
|
*
|
2005-04-17 06:20:36 +08:00
|
|
|
* Note specific to airport stub:
|
2009-01-26 04:08:43 +08:00
|
|
|
*
|
2005-04-17 06:20:36 +08:00
|
|
|
* 0.05 : first version of the new split driver
|
|
|
|
* 0.06 : fix possible hang on powerup, add sleep support
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define DRIVER_NAME "airport"
|
|
|
|
#define PFX DRIVER_NAME ": "
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/init.h>
|
2005-09-23 16:18:07 +08:00
|
|
|
#include <linux/delay.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <asm/pmac_feature.h>
|
|
|
|
|
|
|
|
#include "orinoco.h"
|
|
|
|
|
|
|
|
#define AIRPORT_IO_LEN (0x1000) /* one page */
|
|
|
|
|
|
|
|
struct airport {
|
|
|
|
struct macio_dev *mdev;
|
|
|
|
void __iomem *vaddr;
|
2009-06-19 06:21:29 +08:00
|
|
|
unsigned int irq;
|
2005-04-17 06:20:36 +08:00
|
|
|
int irq_requested;
|
|
|
|
int ndev_registered;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
2005-04-17 06:25:25 +08:00
|
|
|
airport_suspend(struct macio_dev *mdev, pm_message_t state)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2009-06-19 06:21:23 +08:00
|
|
|
struct orinoco_private *priv = dev_get_drvdata(&mdev->ofdev.dev);
|
|
|
|
struct net_device *dev = priv->ndev;
|
2009-06-19 06:21:29 +08:00
|
|
|
struct airport *card = priv->card;
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned long flags;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
printk(KERN_DEBUG "%s: Airport entering sleep mode\n", dev->name);
|
|
|
|
|
|
|
|
err = orinoco_lock(priv, &flags);
|
|
|
|
if (err) {
|
|
|
|
printk(KERN_ERR "%s: hw_unavailable on PBOOK_SLEEP_NOW\n",
|
|
|
|
dev->name);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-06-19 06:21:30 +08:00
|
|
|
orinoco_down(priv);
|
2005-04-17 06:20:36 +08:00
|
|
|
orinoco_unlock(priv, &flags);
|
|
|
|
|
2009-06-19 06:21:29 +08:00
|
|
|
disable_irq(card->irq);
|
2009-01-26 04:08:43 +08:00
|
|
|
pmac_call_feature(PMAC_FTR_AIRPORT_ENABLE,
|
|
|
|
macio_get_of_node(mdev), 0, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
airport_resume(struct macio_dev *mdev)
|
|
|
|
{
|
2009-06-19 06:21:23 +08:00
|
|
|
struct orinoco_private *priv = dev_get_drvdata(&mdev->ofdev.dev);
|
|
|
|
struct net_device *dev = priv->ndev;
|
2009-06-19 06:21:29 +08:00
|
|
|
struct airport *card = priv->card;
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned long flags;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
printk(KERN_DEBUG "%s: Airport waking up\n", dev->name);
|
|
|
|
|
2009-01-26 04:08:43 +08:00
|
|
|
pmac_call_feature(PMAC_FTR_AIRPORT_ENABLE,
|
|
|
|
macio_get_of_node(mdev), 0, 1);
|
2005-04-17 06:20:36 +08:00
|
|
|
msleep(200);
|
|
|
|
|
2009-06-19 06:21:29 +08:00
|
|
|
enable_irq(card->irq);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-05-01 21:05:40 +08:00
|
|
|
priv->hw.ops->lock_irqsave(&priv->lock, &flags);
|
2009-06-19 06:21:30 +08:00
|
|
|
err = orinoco_up(priv);
|
2010-05-01 21:05:40 +08:00
|
|
|
priv->hw.ops->unlock_irqrestore(&priv->lock, &flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-06-19 06:21:30 +08:00
|
|
|
return err;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
airport_detach(struct macio_dev *mdev)
|
|
|
|
{
|
2009-06-19 06:21:23 +08:00
|
|
|
struct orinoco_private *priv = dev_get_drvdata(&mdev->ofdev.dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
struct airport *card = priv->card;
|
|
|
|
|
|
|
|
if (card->ndev_registered)
|
2009-06-19 06:21:28 +08:00
|
|
|
orinoco_if_del(priv);
|
2005-04-17 06:20:36 +08:00
|
|
|
card->ndev_registered = 0;
|
|
|
|
|
|
|
|
if (card->irq_requested)
|
2009-06-19 06:21:29 +08:00
|
|
|
free_irq(card->irq, priv);
|
2005-04-17 06:20:36 +08:00
|
|
|
card->irq_requested = 0;
|
|
|
|
|
|
|
|
if (card->vaddr)
|
|
|
|
iounmap(card->vaddr);
|
|
|
|
card->vaddr = NULL;
|
|
|
|
|
|
|
|
macio_release_resource(mdev, 0);
|
|
|
|
|
2009-01-26 04:08:43 +08:00
|
|
|
pmac_call_feature(PMAC_FTR_AIRPORT_ENABLE,
|
|
|
|
macio_get_of_node(mdev), 0, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
ssleep(1);
|
|
|
|
|
|
|
|
macio_set_drvdata(mdev, NULL);
|
2009-06-19 06:21:23 +08:00
|
|
|
free_orinocodev(priv);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int airport_hard_reset(struct orinoco_private *priv)
|
|
|
|
{
|
|
|
|
/* It would be nice to power cycle the Airport for a real hard
|
|
|
|
* reset, but for some reason although it appears to
|
|
|
|
* re-initialize properly, it falls in a screaming heap
|
|
|
|
* shortly afterwards. */
|
|
|
|
#if 0
|
|
|
|
struct airport *card = priv->card;
|
|
|
|
|
|
|
|
/* Vitally important. If we don't do this it seems we get an
|
|
|
|
* interrupt somewhere during the power cycle, since
|
|
|
|
* hw_unavailable is already set it doesn't get ACKed, we get
|
2007-05-09 14:57:56 +08:00
|
|
|
* into an interrupt loop and the PMU decides to turn us
|
2005-04-17 06:20:36 +08:00
|
|
|
* off. */
|
2009-06-19 06:21:29 +08:00
|
|
|
disable_irq(card->irq);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-01-26 04:08:43 +08:00
|
|
|
pmac_call_feature(PMAC_FTR_AIRPORT_ENABLE,
|
|
|
|
macio_get_of_node(card->mdev), 0, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
ssleep(1);
|
2009-01-26 04:08:43 +08:00
|
|
|
pmac_call_feature(PMAC_FTR_AIRPORT_ENABLE,
|
|
|
|
macio_get_of_node(card->mdev), 0, 1);
|
2005-04-17 06:20:36 +08:00
|
|
|
ssleep(1);
|
|
|
|
|
2009-06-19 06:21:29 +08:00
|
|
|
enable_irq(card->irq);
|
2005-04-17 06:20:36 +08:00
|
|
|
ssleep(1);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2005-07-07 03:44:41 +08:00
|
|
|
airport_attach(struct macio_dev *mdev, const struct of_device_id *match)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct orinoco_private *priv;
|
|
|
|
struct airport *card;
|
|
|
|
unsigned long phys_addr;
|
|
|
|
hermes_t *hw;
|
|
|
|
|
|
|
|
if (macio_resource_count(mdev) < 1 || macio_irq_count(mdev) < 1) {
|
|
|
|
printk(KERN_ERR PFX "Wrong interrupt/addresses in OF tree\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate space for private device-specific data */
|
2009-06-19 06:21:23 +08:00
|
|
|
priv = alloc_orinocodev(sizeof(*card), &mdev->ofdev.dev,
|
|
|
|
airport_hard_reset, NULL);
|
|
|
|
if (!priv) {
|
2005-04-17 06:20:36 +08:00
|
|
|
printk(KERN_ERR PFX "Cannot allocate network device\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
card = priv->card;
|
|
|
|
|
|
|
|
hw = &priv->hw;
|
|
|
|
card->mdev = mdev;
|
|
|
|
|
2009-06-19 06:21:28 +08:00
|
|
|
if (macio_request_resource(mdev, 0, DRIVER_NAME)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
printk(KERN_ERR PFX "can't request IO resource !\n");
|
2009-06-19 06:21:23 +08:00
|
|
|
free_orinocodev(priv);
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
2009-06-19 06:21:23 +08:00
|
|
|
macio_set_drvdata(mdev, priv);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Setup interrupts & base address */
|
2009-06-19 06:21:29 +08:00
|
|
|
card->irq = macio_irq(mdev, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
phys_addr = macio_resource_start(mdev, 0); /* Physical address */
|
|
|
|
printk(KERN_DEBUG PFX "Physical address %lx\n", phys_addr);
|
|
|
|
card->vaddr = ioremap(phys_addr, AIRPORT_IO_LEN);
|
|
|
|
if (!card->vaddr) {
|
|
|
|
printk(KERN_ERR PFX "ioremap() failed\n");
|
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
hermes_struct_init(hw, card->vaddr, HERMES_16BIT_REGSPACING);
|
2009-01-26 04:08:43 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Power up card */
|
2009-01-26 04:08:43 +08:00
|
|
|
pmac_call_feature(PMAC_FTR_AIRPORT_ENABLE,
|
|
|
|
macio_get_of_node(mdev), 0, 1);
|
2005-04-17 06:20:36 +08:00
|
|
|
ssleep(1);
|
|
|
|
|
|
|
|
/* Reset it before we get the interrupt */
|
2010-05-01 21:05:38 +08:00
|
|
|
hw->ops->init(hw);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-06-19 06:21:29 +08:00
|
|
|
if (request_irq(card->irq, orinoco_interrupt, 0, DRIVER_NAME, priv)) {
|
|
|
|
printk(KERN_ERR PFX "Couldn't get IRQ %d\n", card->irq);
|
2005-04-17 06:20:36 +08:00
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
card->irq_requested = 1;
|
|
|
|
|
2009-06-19 06:21:24 +08:00
|
|
|
/* Initialise the main driver */
|
|
|
|
if (orinoco_init(priv) != 0) {
|
|
|
|
printk(KERN_ERR PFX "orinoco_init() failed\n");
|
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
|
2009-06-19 06:21:28 +08:00
|
|
|
/* Register an interface with the stack */
|
2010-05-01 21:05:39 +08:00
|
|
|
if (orinoco_if_add(priv, phys_addr, card->irq, NULL) != 0) {
|
2009-06-19 06:21:28 +08:00
|
|
|
printk(KERN_ERR PFX "orinoco_if_add() failed\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
card->ndev_registered = 1;
|
|
|
|
return 0;
|
|
|
|
failed:
|
|
|
|
airport_detach(mdev);
|
|
|
|
return -ENODEV;
|
|
|
|
} /* airport_attach */
|
|
|
|
|
|
|
|
|
|
|
|
static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
|
|
|
|
" (Benjamin Herrenschmidt <benh@kernel.crashing.org>)";
|
|
|
|
MODULE_AUTHOR("Benjamin Herrenschmidt <benh@kernel.crashing.org>");
|
|
|
|
MODULE_DESCRIPTION("Driver for the Apple Airport wireless card.");
|
|
|
|
MODULE_LICENSE("Dual MPL/GPL");
|
|
|
|
|
2009-01-26 04:08:43 +08:00
|
|
|
static struct of_device_id airport_match[] =
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
{
|
|
|
|
.name = "radio",
|
|
|
|
},
|
|
|
|
{},
|
|
|
|
};
|
|
|
|
|
2009-01-26 04:08:43 +08:00
|
|
|
MODULE_DEVICE_TABLE(of, airport_match);
|
2005-07-07 03:44:41 +08:00
|
|
|
|
2009-01-26 04:08:43 +08:00
|
|
|
static struct macio_driver airport_driver = {
|
2010-06-02 15:09:18 +08:00
|
|
|
.driver = {
|
|
|
|
.name = DRIVER_NAME,
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.of_match_table = airport_match,
|
|
|
|
},
|
2005-04-17 06:20:36 +08:00
|
|
|
.probe = airport_attach,
|
|
|
|
.remove = airport_detach,
|
|
|
|
.suspend = airport_suspend,
|
|
|
|
.resume = airport_resume,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init
|
|
|
|
init_airport(void)
|
|
|
|
{
|
|
|
|
printk(KERN_DEBUG "%s\n", version);
|
|
|
|
|
|
|
|
return macio_register_driver(&airport_driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit
|
|
|
|
exit_airport(void)
|
|
|
|
{
|
2008-12-10 01:32:15 +08:00
|
|
|
macio_unregister_driver(&airport_driver);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
module_init(init_airport);
|
|
|
|
module_exit(exit_airport);
|