Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* airport.c |
2 | * | |
3 | * A driver for "Hermes" chipset based Apple Airport wireless | |
4 | * card. | |
5 | * | |
47445cb9 | 6 | * Copyright notice & release notes in file main.c |
d14c7c1d | 7 | * |
1da177e4 | 8 | * Note specific to airport stub: |
d14c7c1d | 9 | * |
1da177e4 LT |
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 | ||
1da177e4 LT |
17 | #include <linux/module.h> |
18 | #include <linux/kernel.h> | |
19 | #include <linux/init.h> | |
ef846bf0 | 20 | #include <linux/delay.h> |
1da177e4 | 21 | #include <asm/pmac_feature.h> |
1da177e4 LT |
22 | |
23 | #include "orinoco.h" | |
24 | ||
25 | #define AIRPORT_IO_LEN (0x1000) /* one page */ | |
26 | ||
27 | struct airport { | |
28 | struct macio_dev *mdev; | |
29 | void __iomem *vaddr; | |
ef96b5c9 | 30 | unsigned int irq; |
1da177e4 LT |
31 | int irq_requested; |
32 | int ndev_registered; | |
33 | }; | |
34 | ||
35 | static int | |
05adc3b7 | 36 | airport_suspend(struct macio_dev *mdev, pm_message_t state) |
1da177e4 | 37 | { |
a2608362 DK |
38 | struct orinoco_private *priv = dev_get_drvdata(&mdev->ofdev.dev); |
39 | struct net_device *dev = priv->ndev; | |
ef96b5c9 | 40 | struct airport *card = priv->card; |
1da177e4 LT |
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 | ||
6415f7df | 53 | orinoco_down(priv); |
1da177e4 LT |
54 | orinoco_unlock(priv, &flags); |
55 | ||
ef96b5c9 | 56 | disable_irq(card->irq); |
d14c7c1d AB |
57 | pmac_call_feature(PMAC_FTR_AIRPORT_ENABLE, |
58 | macio_get_of_node(mdev), 0, 0); | |
1da177e4 LT |
59 | |
60 | return 0; | |
61 | } | |
62 | ||
63 | static int | |
64 | airport_resume(struct macio_dev *mdev) | |
65 | { | |
a2608362 DK |
66 | struct orinoco_private *priv = dev_get_drvdata(&mdev->ofdev.dev); |
67 | struct net_device *dev = priv->ndev; | |
ef96b5c9 | 68 | struct airport *card = priv->card; |
1da177e4 LT |
69 | unsigned long flags; |
70 | int err; | |
71 | ||
72 | printk(KERN_DEBUG "%s: Airport waking up\n", dev->name); | |
73 | ||
d14c7c1d AB |
74 | pmac_call_feature(PMAC_FTR_AIRPORT_ENABLE, |
75 | macio_get_of_node(mdev), 0, 1); | |
1da177e4 LT |
76 | msleep(200); |
77 | ||
ef96b5c9 | 78 | enable_irq(card->irq); |
1da177e4 | 79 | |
1da177e4 | 80 | spin_lock_irqsave(&priv->lock, flags); |
6415f7df | 81 | err = orinoco_up(priv); |
1da177e4 LT |
82 | spin_unlock_irqrestore(&priv->lock, flags); |
83 | ||
6415f7df | 84 | return err; |
1da177e4 LT |
85 | } |
86 | ||
87 | static int | |
88 | airport_detach(struct macio_dev *mdev) | |
89 | { | |
a2608362 | 90 | struct orinoco_private *priv = dev_get_drvdata(&mdev->ofdev.dev); |
1da177e4 LT |
91 | struct airport *card = priv->card; |
92 | ||
93 | if (card->ndev_registered) | |
5381956b | 94 | orinoco_if_del(priv); |
1da177e4 LT |
95 | card->ndev_registered = 0; |
96 | ||
97 | if (card->irq_requested) | |
ef96b5c9 | 98 | free_irq(card->irq, priv); |
1da177e4 LT |
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 | ||
d14c7c1d AB |
107 | pmac_call_feature(PMAC_FTR_AIRPORT_ENABLE, |
108 | macio_get_of_node(mdev), 0, 0); | |
1da177e4 LT |
109 | ssleep(1); |
110 | ||
111 | macio_set_drvdata(mdev, NULL); | |
a2608362 | 112 | free_orinocodev(priv); |
1da177e4 LT |
113 | |
114 | return 0; | |
115 | } | |
116 | ||
117 | static 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 | |
1da177e4 LT |
124 | 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 | |
59c51591 | 129 | * into an interrupt loop and the PMU decides to turn us |
1da177e4 | 130 | * off. */ |
ef96b5c9 | 131 | disable_irq(card->irq); |
1da177e4 | 132 | |
d14c7c1d AB |
133 | pmac_call_feature(PMAC_FTR_AIRPORT_ENABLE, |
134 | macio_get_of_node(card->mdev), 0, 0); | |
1da177e4 | 135 | ssleep(1); |
d14c7c1d AB |
136 | pmac_call_feature(PMAC_FTR_AIRPORT_ENABLE, |
137 | macio_get_of_node(card->mdev), 0, 1); | |
1da177e4 LT |
138 | ssleep(1); |
139 | ||
ef96b5c9 | 140 | enable_irq(card->irq); |
1da177e4 LT |
141 | ssleep(1); |
142 | #endif | |
143 | ||
144 | return 0; | |
145 | } | |
146 | ||
147 | static int | |
5e655772 | 148 | airport_attach(struct macio_dev *mdev, const struct of_device_id *match) |
1da177e4 LT |
149 | { |
150 | struct orinoco_private *priv; | |
1da177e4 LT |
151 | struct airport *card; |
152 | unsigned long phys_addr; | |
153 | hermes_t *hw; | |
154 | ||
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 */ | |
a2608362 DK |
161 | priv = alloc_orinocodev(sizeof(*card), &mdev->ofdev.dev, |
162 | airport_hard_reset, NULL); | |
163 | if (!priv) { | |
1da177e4 LT |
164 | printk(KERN_ERR PFX "Cannot allocate network device\n"); |
165 | return -ENODEV; | |
166 | } | |
1da177e4 LT |
167 | card = priv->card; |
168 | ||
169 | hw = &priv->hw; | |
170 | card->mdev = mdev; | |
171 | ||
5381956b | 172 | if (macio_request_resource(mdev, 0, DRIVER_NAME)) { |
1da177e4 | 173 | printk(KERN_ERR PFX "can't request IO resource !\n"); |
a2608362 | 174 | free_orinocodev(priv); |
1da177e4 LT |
175 | return -EBUSY; |
176 | } | |
177 | ||
a2608362 | 178 | macio_set_drvdata(mdev, priv); |
1da177e4 LT |
179 | |
180 | /* Setup interrupts & base address */ | |
ef96b5c9 | 181 | card->irq = macio_irq(mdev, 0); |
1da177e4 LT |
182 | phys_addr = macio_resource_start(mdev, 0); /* Physical address */ |
183 | printk(KERN_DEBUG PFX "Physical address %lx\n", phys_addr); | |
1da177e4 LT |
184 | 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); | |
d14c7c1d | 191 | |
1da177e4 | 192 | /* Power up card */ |
d14c7c1d AB |
193 | pmac_call_feature(PMAC_FTR_AIRPORT_ENABLE, |
194 | macio_get_of_node(mdev), 0, 1); | |
1da177e4 LT |
195 | ssleep(1); |
196 | ||
197 | /* Reset it before we get the interrupt */ | |
198 | hermes_init(hw); | |
199 | ||
ef96b5c9 DK |
200 | if (request_irq(card->irq, orinoco_interrupt, 0, DRIVER_NAME, priv)) { |
201 | printk(KERN_ERR PFX "Couldn't get IRQ %d\n", card->irq); | |
1da177e4 LT |
202 | goto failed; |
203 | } | |
204 | card->irq_requested = 1; | |
205 | ||
8e638267 DK |
206 | /* Initialise the main driver */ |
207 | if (orinoco_init(priv) != 0) { | |
208 | printk(KERN_ERR PFX "orinoco_init() failed\n"); | |
209 | goto failed; | |
210 | } | |
211 | ||
5381956b | 212 | /* Register an interface with the stack */ |
ef96b5c9 | 213 | if (orinoco_if_add(priv, phys_addr, card->irq) != 0) { |
5381956b | 214 | printk(KERN_ERR PFX "orinoco_if_add() failed\n"); |
1da177e4 LT |
215 | goto failed; |
216 | } | |
1da177e4 LT |
217 | card->ndev_registered = 1; |
218 | return 0; | |
219 | failed: | |
220 | airport_detach(mdev); | |
221 | return -ENODEV; | |
222 | } /* airport_attach */ | |
223 | ||
224 | ||
225 | static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION | |
226 | " (Benjamin Herrenschmidt <benh@kernel.crashing.org>)"; | |
227 | MODULE_AUTHOR("Benjamin Herrenschmidt <benh@kernel.crashing.org>"); | |
228 | MODULE_DESCRIPTION("Driver for the Apple Airport wireless card."); | |
229 | MODULE_LICENSE("Dual MPL/GPL"); | |
230 | ||
d14c7c1d | 231 | static struct of_device_id airport_match[] = |
1da177e4 LT |
232 | { |
233 | { | |
234 | .name = "radio", | |
1da177e4 LT |
235 | }, |
236 | {}, | |
237 | }; | |
238 | ||
d14c7c1d | 239 | MODULE_DEVICE_TABLE(of, airport_match); |
5e655772 | 240 | |
d14c7c1d | 241 | static struct macio_driver airport_driver = { |
1da177e4 LT |
242 | .name = DRIVER_NAME, |
243 | .match_table = airport_match, | |
244 | .probe = airport_attach, | |
245 | .remove = airport_detach, | |
246 | .suspend = airport_suspend, | |
247 | .resume = airport_resume, | |
248 | }; | |
249 | ||
250 | static int __init | |
251 | init_airport(void) | |
252 | { | |
253 | printk(KERN_DEBUG "%s\n", version); | |
254 | ||
255 | return macio_register_driver(&airport_driver); | |
256 | } | |
257 | ||
258 | static void __exit | |
259 | exit_airport(void) | |
260 | { | |
d070d855 | 261 | macio_unregister_driver(&airport_driver); |
1da177e4 LT |
262 | } |
263 | ||
264 | module_init(init_airport); | |
265 | module_exit(exit_airport); |