blob: 77e6c53040a35f80cf8e8092b1c8ebcbcd4bf6f4 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* airport.c
2 *
3 * A driver for "Hermes" chipset based Apple Airport wireless
4 * card.
5 *
David Kilroy47445cb2009-02-04 23:05:48 +00006 * Copyright notice & release notes in file main.c
Andrey Borzenkovd14c7c12009-01-25 23:08:43 +03007 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 * Note specific to airport stub:
Andrey Borzenkovd14c7c12009-01-25 23:08:43 +03009 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 * 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <linux/module.h>
18#include <linux/kernel.h>
19#include <linux/init.h>
Pavel Roskinef846bf2005-09-23 04:18:07 -040020#include <linux/delay.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <asm/pmac_feature.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
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;
David Kilroyef96b5c2009-06-18 23:21:29 +010030 unsigned int irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 int irq_requested;
32 int ndev_registered;
33};
34
35static int
Pavel Machek05adc3b2005-04-16 15:25:25 -070036airport_suspend(struct macio_dev *mdev, pm_message_t state)
Linus Torvalds1da177e2005-04-16 15:20:36 -070037{
David Kilroya2608362009-06-18 23:21:23 +010038 struct orinoco_private *priv = dev_get_drvdata(&mdev->ofdev.dev);
39 struct net_device *dev = priv->ndev;
David Kilroyef96b5c2009-06-18 23:21:29 +010040 struct airport *card = priv->card;
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 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
David Kilroy6415f7d2009-06-18 23:21:30 +010053 orinoco_down(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 orinoco_unlock(priv, &flags);
55
David Kilroyef96b5c2009-06-18 23:21:29 +010056 disable_irq(card->irq);
Andrey Borzenkovd14c7c12009-01-25 23:08:43 +030057 pmac_call_feature(PMAC_FTR_AIRPORT_ENABLE,
58 macio_get_of_node(mdev), 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
60 return 0;
61}
62
63static int
64airport_resume(struct macio_dev *mdev)
65{
David Kilroya2608362009-06-18 23:21:23 +010066 struct orinoco_private *priv = dev_get_drvdata(&mdev->ofdev.dev);
67 struct net_device *dev = priv->ndev;
David Kilroyef96b5c2009-06-18 23:21:29 +010068 struct airport *card = priv->card;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 unsigned long flags;
70 int err;
71
72 printk(KERN_DEBUG "%s: Airport waking up\n", dev->name);
73
Andrey Borzenkovd14c7c12009-01-25 23:08:43 +030074 pmac_call_feature(PMAC_FTR_AIRPORT_ENABLE,
75 macio_get_of_node(mdev), 0, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 msleep(200);
77
David Kilroyef96b5c2009-06-18 23:21:29 +010078 enable_irq(card->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
David Kilroybcad6e82010-05-01 14:05:40 +010080 priv->hw.ops->lock_irqsave(&priv->lock, &flags);
David Kilroy6415f7d2009-06-18 23:21:30 +010081 err = orinoco_up(priv);
David Kilroybcad6e82010-05-01 14:05:40 +010082 priv->hw.ops->unlock_irqrestore(&priv->lock, &flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
David Kilroy6415f7d2009-06-18 23:21:30 +010084 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -070085}
86
87static int
88airport_detach(struct macio_dev *mdev)
89{
David Kilroya2608362009-06-18 23:21:23 +010090 struct orinoco_private *priv = dev_get_drvdata(&mdev->ofdev.dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 struct airport *card = priv->card;
92
93 if (card->ndev_registered)
David Kilroy53819562009-06-18 23:21:28 +010094 orinoco_if_del(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 card->ndev_registered = 0;
96
97 if (card->irq_requested)
David Kilroyef96b5c2009-06-18 23:21:29 +010098 free_irq(card->irq, priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 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
Andrey Borzenkovd14c7c12009-01-25 23:08:43 +0300107 pmac_call_feature(PMAC_FTR_AIRPORT_ENABLE,
108 macio_get_of_node(mdev), 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 ssleep(1);
110
111 macio_set_drvdata(mdev, NULL);
David Kilroya2608362009-06-18 23:21:23 +0100112 free_orinocodev(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
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#if 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 struct airport *card = priv->card;
125
126 /* Vitally important. If we don't do this it seems we get an
127 * interrupt somewhere during the power cycle, since
128 * hw_unavailable is already set it doesn't get ACKed, we get
Michael Opdenacker59c51592007-05-09 08:57:56 +0200129 * into an interrupt loop and the PMU decides to turn us
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 * off. */
David Kilroyef96b5c2009-06-18 23:21:29 +0100131 disable_irq(card->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
Andrey Borzenkovd14c7c12009-01-25 23:08:43 +0300133 pmac_call_feature(PMAC_FTR_AIRPORT_ENABLE,
134 macio_get_of_node(card->mdev), 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 ssleep(1);
Andrey Borzenkovd14c7c12009-01-25 23:08:43 +0300136 pmac_call_feature(PMAC_FTR_AIRPORT_ENABLE,
137 macio_get_of_node(card->mdev), 0, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 ssleep(1);
139
David Kilroyef96b5c2009-06-18 23:21:29 +0100140 enable_irq(card->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 ssleep(1);
142#endif
143
144 return 0;
145}
146
147static int
Jeff Mahoney5e655772005-07-06 15:44:41 -0400148airport_attach(struct macio_dev *mdev, const struct of_device_id *match)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149{
150 struct orinoco_private *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 struct airport *card;
152 unsigned long phys_addr;
Pavel Roskin933d5942011-07-13 11:19:57 -0400153 struct hermes *hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
155 if (macio_resource_count(mdev) < 1 || macio_irq_count(mdev) < 1) {
156 printk(KERN_ERR PFX "Wrong interrupt/addresses in OF tree\n");
157 return -ENODEV;
158 }
159
160 /* Allocate space for private device-specific data */
David Kilroya2608362009-06-18 23:21:23 +0100161 priv = alloc_orinocodev(sizeof(*card), &mdev->ofdev.dev,
162 airport_hard_reset, NULL);
163 if (!priv) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 printk(KERN_ERR PFX "Cannot allocate network device\n");
165 return -ENODEV;
166 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 card = priv->card;
168
169 hw = &priv->hw;
170 card->mdev = mdev;
171
David Kilroy53819562009-06-18 23:21:28 +0100172 if (macio_request_resource(mdev, 0, DRIVER_NAME)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 printk(KERN_ERR PFX "can't request IO resource !\n");
David Kilroya2608362009-06-18 23:21:23 +0100174 free_orinocodev(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 return -EBUSY;
176 }
177
David Kilroya2608362009-06-18 23:21:23 +0100178 macio_set_drvdata(mdev, priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
180 /* Setup interrupts & base address */
David Kilroyef96b5c2009-06-18 23:21:29 +0100181 card->irq = macio_irq(mdev, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 phys_addr = macio_resource_start(mdev, 0); /* Physical address */
183 printk(KERN_DEBUG PFX "Physical address %lx\n", phys_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 card->vaddr = ioremap(phys_addr, AIRPORT_IO_LEN);
185 if (!card->vaddr) {
186 printk(KERN_ERR PFX "ioremap() failed\n");
187 goto failed;
188 }
189
190 hermes_struct_init(hw, card->vaddr, HERMES_16BIT_REGSPACING);
Andrey Borzenkovd14c7c12009-01-25 23:08:43 +0300191
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 /* Power up card */
Andrey Borzenkovd14c7c12009-01-25 23:08:43 +0300193 pmac_call_feature(PMAC_FTR_AIRPORT_ENABLE,
194 macio_get_of_node(mdev), 0, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 ssleep(1);
196
197 /* Reset it before we get the interrupt */
David Kilroyb42f2072010-05-01 14:05:38 +0100198 hw->ops->init(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
David Kilroyef96b5c2009-06-18 23:21:29 +0100200 if (request_irq(card->irq, orinoco_interrupt, 0, DRIVER_NAME, priv)) {
201 printk(KERN_ERR PFX "Couldn't get IRQ %d\n", card->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 goto failed;
203 }
204 card->irq_requested = 1;
205
David Kilroy8e638262009-06-18 23:21:24 +0100206 /* Initialise the main driver */
207 if (orinoco_init(priv) != 0) {
208 printk(KERN_ERR PFX "orinoco_init() failed\n");
209 goto failed;
210 }
211
David Kilroy53819562009-06-18 23:21:28 +0100212 /* Register an interface with the stack */
David Kilroy593ef092010-05-01 14:05:39 +0100213 if (orinoco_if_add(priv, phys_addr, card->irq, NULL) != 0) {
David Kilroy53819562009-06-18 23:21:28 +0100214 printk(KERN_ERR PFX "orinoco_if_add() failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 goto failed;
216 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 card->ndev_registered = 1;
218 return 0;
219 failed:
220 airport_detach(mdev);
221 return -ENODEV;
222} /* airport_attach */
223
224
225static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
226 " (Benjamin Herrenschmidt <benh@kernel.crashing.org>)";
227MODULE_AUTHOR("Benjamin Herrenschmidt <benh@kernel.crashing.org>");
228MODULE_DESCRIPTION("Driver for the Apple Airport wireless card.");
229MODULE_LICENSE("Dual MPL/GPL");
230
Fabian Frederick38481242015-03-17 19:40:22 +0100231static const struct of_device_id airport_match[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 {
Pavel Roskin933d5942011-07-13 11:19:57 -0400233 .name = "radio",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 },
235 {},
236};
237
Andrey Borzenkovd14c7c12009-01-25 23:08:43 +0300238MODULE_DEVICE_TABLE(of, airport_match);
Jeff Mahoney5e655772005-07-06 15:44:41 -0400239
Andrey Borzenkovd14c7c12009-01-25 23:08:43 +0300240static struct macio_driver airport_driver = {
Benjamin Herrenschmidtc2cdf6a2010-06-02 17:09:18 +1000241 .driver = {
Pavel Roskin933d5942011-07-13 11:19:57 -0400242 .name = DRIVER_NAME,
Benjamin Herrenschmidtc2cdf6a2010-06-02 17:09:18 +1000243 .owner = THIS_MODULE,
244 .of_match_table = airport_match,
245 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 .probe = airport_attach,
247 .remove = airport_detach,
248 .suspend = airport_suspend,
249 .resume = airport_resume,
250};
251
252static int __init
253init_airport(void)
254{
255 printk(KERN_DEBUG "%s\n", version);
256
257 return macio_register_driver(&airport_driver);
258}
259
260static void __exit
261exit_airport(void)
262{
Pavel Roskind070d852008-12-09 12:32:15 -0500263 macio_unregister_driver(&airport_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264}
265
266module_init(init_airport);
267module_exit(exit_airport);