Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

wl12xx: move common init code from bus modules to main

Move all common parts from sdio.c and spi.c to main.c, since they now
can be handled as part of the platform driver.

Signed-off-by: Felipe Balbi <balbi@ti.com>
[forward-ported, cleaned-up and rephrased commit message]
[added a bunch of fixes and a new pdata element]
[moved some new code into main.c as well]
Signed-off-by: Luciano Coelho <coelho@ti.com>

authored by

Felipe Balbi and committed by
Luciano Coelho
a390e85c ce2a217c

+185 -313
+6 -5
drivers/net/wireless/wl12xx/io.c
··· 24 24 #include <linux/module.h> 25 25 #include <linux/platform_device.h> 26 26 #include <linux/spi/spi.h> 27 + #include <linux/interrupt.h> 27 28 28 29 #include "wl12xx.h" 29 30 #include "wl12xx_80211.h" ··· 47 46 bool wl1271_set_block_size(struct wl1271 *wl) 48 47 { 49 48 if (wl->if_ops->set_block_size) { 50 - wl->if_ops->set_block_size(wl, WL12XX_BUS_BLOCK_SIZE); 49 + wl->if_ops->set_block_size(wl->dev, WL12XX_BUS_BLOCK_SIZE); 51 50 return true; 52 51 } 53 52 ··· 56 55 57 56 void wl1271_disable_interrupts(struct wl1271 *wl) 58 57 { 59 - wl->if_ops->disable_irq(wl); 58 + disable_irq(wl->irq); 60 59 } 61 60 62 61 void wl1271_enable_interrupts(struct wl1271 *wl) 63 62 { 64 - wl->if_ops->enable_irq(wl); 63 + enable_irq(wl->irq); 65 64 } 66 65 67 66 /* Set the SPI partitions to access the chip addresses ··· 129 128 void wl1271_io_reset(struct wl1271 *wl) 130 129 { 131 130 if (wl->if_ops->reset) 132 - wl->if_ops->reset(wl); 131 + wl->if_ops->reset(wl->dev); 133 132 } 134 133 135 134 void wl1271_io_init(struct wl1271 *wl) 136 135 { 137 136 if (wl->if_ops->init) 138 - wl->if_ops->init(wl); 137 + wl->if_ops->init(wl->dev); 139 138 } 140 139 141 140 void wl1271_top_reg_write(struct wl1271 *wl, int addr, u16 val)
+4 -10
drivers/net/wireless/wl12xx/io.h
··· 51 51 void wl1271_io_reset(struct wl1271 *wl); 52 52 void wl1271_io_init(struct wl1271 *wl); 53 53 54 - static inline struct device *wl1271_wl_to_dev(struct wl1271 *wl) 55 - { 56 - return wl->if_ops->dev(wl); 57 - } 58 - 59 - 60 54 /* Raw target IO, address is not translated */ 61 55 static inline void wl1271_raw_write(struct wl1271 *wl, int addr, void *buf, 62 56 size_t len, bool fixed) 63 57 { 64 - wl->if_ops->write(wl, addr, buf, len, fixed); 58 + wl->if_ops->write(wl->dev, addr, buf, len, fixed); 65 59 } 66 60 67 61 static inline void wl1271_raw_read(struct wl1271 *wl, int addr, void *buf, 68 62 size_t len, bool fixed) 69 63 { 70 - wl->if_ops->read(wl, addr, buf, len, fixed); 64 + wl->if_ops->read(wl->dev, addr, buf, len, fixed); 71 65 } 72 66 73 67 static inline u32 wl1271_raw_read32(struct wl1271 *wl, int addr) ··· 149 155 150 156 static inline void wl1271_power_off(struct wl1271 *wl) 151 157 { 152 - wl->if_ops->power(wl, false); 158 + wl->if_ops->power(wl->dev, false); 153 159 clear_bit(WL1271_FLAG_GPIO_POWER, &wl->flags); 154 160 } 155 161 156 162 static inline int wl1271_power_on(struct wl1271 *wl) 157 163 { 158 - int ret = wl->if_ops->power(wl, true); 164 + int ret = wl->if_ops->power(wl->dev, true); 159 165 if (ret == 0) 160 166 set_bit(WL1271_FLAG_GPIO_POWER, &wl->flags); 161 167
+107 -3
drivers/net/wireless/wl12xx/main.c
··· 32 32 #include <linux/slab.h> 33 33 #include <linux/wl12xx.h> 34 34 #include <linux/sched.h> 35 + #include <linux/interrupt.h> 35 36 36 37 #include "wl12xx.h" 37 38 #include "wl12xx_80211.h" ··· 1068 1067 1069 1068 wl1271_debug(DEBUG_BOOT, "booting firmware %s", fw_name); 1070 1069 1071 - ret = request_firmware(&fw, fw_name, wl1271_wl_to_dev(wl)); 1070 + ret = request_firmware(&fw, fw_name, wl->dev); 1072 1071 1073 1072 if (ret < 0) { 1074 1073 wl1271_error("could not get firmware: %d", ret); ··· 1106 1105 const struct firmware *fw; 1107 1106 int ret; 1108 1107 1109 - ret = request_firmware(&fw, WL12XX_NVS_NAME, wl1271_wl_to_dev(wl)); 1108 + ret = request_firmware(&fw, WL12XX_NVS_NAME, wl->dev); 1110 1109 1111 1110 if (ret < 0) { 1112 1111 wl1271_error("could not get nvs file: %d", ret); ··· 4980 4979 4981 4980 wl->hw->wiphy->reg_notifier = wl1271_reg_notify; 4982 4981 4983 - SET_IEEE80211_DEV(wl->hw, wl1271_wl_to_dev(wl)); 4982 + SET_IEEE80211_DEV(wl->hw, wl->dev); 4984 4983 4985 4984 wl->hw->sta_data_size = sizeof(struct wl1271_station); 4986 4985 wl->hw->vif_data_size = sizeof(struct wl12xx_vif); ··· 5201 5200 } 5202 5201 EXPORT_SYMBOL_GPL(wl1271_free_hw); 5203 5202 5203 + static irqreturn_t wl12xx_hardirq(int irq, void *cookie) 5204 + { 5205 + struct wl1271 *wl = cookie; 5206 + unsigned long flags; 5207 + 5208 + wl1271_debug(DEBUG_IRQ, "IRQ"); 5209 + 5210 + /* complete the ELP completion */ 5211 + spin_lock_irqsave(&wl->wl_lock, flags); 5212 + set_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags); 5213 + if (wl->elp_compl) { 5214 + complete(wl->elp_compl); 5215 + wl->elp_compl = NULL; 5216 + } 5217 + 5218 + if (test_bit(WL1271_FLAG_SUSPENDED, &wl->flags)) { 5219 + /* don't enqueue a work right now. mark it as pending */ 5220 + set_bit(WL1271_FLAG_PENDING_WORK, &wl->flags); 5221 + wl1271_debug(DEBUG_IRQ, "should not enqueue work"); 5222 + disable_irq_nosync(wl->irq); 5223 + pm_wakeup_event(wl->dev, 0); 5224 + spin_unlock_irqrestore(&wl->wl_lock, flags); 5225 + return IRQ_HANDLED; 5226 + } 5227 + spin_unlock_irqrestore(&wl->wl_lock, flags); 5228 + 5229 + return IRQ_WAKE_THREAD; 5230 + } 5231 + 5204 5232 static int __devinit wl12xx_probe(struct platform_device *pdev) 5205 5233 { 5234 + struct wl12xx_platform_data *pdata = pdev->dev.platform_data; 5235 + struct ieee80211_hw *hw; 5236 + struct wl1271 *wl; 5237 + unsigned long irqflags; 5238 + int ret = -ENODEV; 5239 + 5240 + hw = wl1271_alloc_hw(); 5241 + if (IS_ERR(hw)) { 5242 + wl1271_error("can't allocate hw"); 5243 + ret = PTR_ERR(hw); 5244 + goto out; 5245 + } 5246 + 5247 + wl = hw->priv; 5248 + wl->irq = platform_get_irq(pdev, 0); 5249 + wl->ref_clock = pdata->board_ref_clock; 5250 + wl->tcxo_clock = pdata->board_tcxo_clock; 5251 + wl->platform_quirks = pdata->platform_quirks; 5252 + wl->set_power = pdata->set_power; 5253 + wl->dev = &pdev->dev; 5254 + wl->if_ops = pdata->ops; 5255 + 5256 + platform_set_drvdata(pdev, wl); 5257 + 5258 + if (wl->platform_quirks & WL12XX_PLATFORM_QUIRK_EDGE_IRQ) 5259 + irqflags = IRQF_TRIGGER_RISING; 5260 + else 5261 + irqflags = IRQF_TRIGGER_HIGH | IRQF_ONESHOT; 5262 + 5263 + ret = request_threaded_irq(wl->irq, wl12xx_hardirq, wl1271_irq, 5264 + irqflags, 5265 + pdev->name, wl); 5266 + if (ret < 0) { 5267 + wl1271_error("request_irq() failed: %d", ret); 5268 + goto out_free_hw; 5269 + } 5270 + 5271 + ret = enable_irq_wake(wl->irq); 5272 + if (!ret) { 5273 + wl->irq_wake_enabled = true; 5274 + device_init_wakeup(wl->dev, 1); 5275 + if (pdata->pwr_in_suspend) 5276 + hw->wiphy->wowlan.flags = WIPHY_WOWLAN_ANY; 5277 + 5278 + } 5279 + disable_irq(wl->irq); 5280 + 5281 + ret = wl1271_init_ieee80211(wl); 5282 + if (ret) 5283 + goto out_irq; 5284 + 5285 + ret = wl1271_register_hw(wl); 5286 + if (ret) 5287 + goto out_irq; 5288 + 5206 5289 return 0; 5290 + 5291 + out_irq: 5292 + free_irq(wl->irq, wl); 5293 + 5294 + out_free_hw: 5295 + wl1271_free_hw(wl); 5296 + 5297 + out: 5298 + return ret; 5207 5299 } 5208 5300 5209 5301 static int __devexit wl12xx_remove(struct platform_device *pdev) 5210 5302 { 5303 + struct wl1271 *wl = platform_get_drvdata(pdev); 5304 + 5305 + if (wl->irq_wake_enabled) { 5306 + device_init_wakeup(wl->dev, 0); 5307 + disable_irq_wake(wl->irq); 5308 + } 5309 + wl1271_unregister_hw(wl); 5310 + free_irq(wl->irq, wl); 5311 + wl1271_free_hw(wl); 5312 + 5211 5313 return 0; 5212 5314 } 5213 5315
+32 -144
drivers/net/wireless/wl12xx/sdio.c
··· 47 47 48 48 struct wl12xx_sdio_glue { 49 49 struct device *dev; 50 - struct wl1271 *wl; 51 50 struct platform_device *core; 52 51 }; 53 52 ··· 56 57 }; 57 58 MODULE_DEVICE_TABLE(sdio, wl1271_devices); 58 59 59 - static void wl1271_sdio_set_block_size(struct wl1271 *wl, unsigned int blksz) 60 + static void wl1271_sdio_set_block_size(struct device *child, 61 + unsigned int blksz) 60 62 { 61 - sdio_claim_host(wl->if_priv); 62 - sdio_set_block_size(wl->if_priv, blksz); 63 - sdio_release_host(wl->if_priv); 63 + struct wl12xx_sdio_glue *glue = dev_get_drvdata(child->parent); 64 + struct sdio_func *func = dev_to_sdio_func(glue->dev); 65 + 66 + sdio_claim_host(func); 67 + sdio_set_block_size(func, blksz); 68 + sdio_release_host(func); 64 69 } 65 70 66 - static inline struct wl12xx_sdio_glue *wl_to_glue(struct wl1271 *wl) 67 - { 68 - return wl->if_priv; 69 - } 70 - 71 - static struct device *wl1271_sdio_wl_to_dev(struct wl1271 *wl) 72 - { 73 - return wl_to_glue(wl)->dev; 74 - } 75 - 76 - static irqreturn_t wl1271_hardirq(int irq, void *cookie) 77 - { 78 - struct wl1271 *wl = cookie; 79 - unsigned long flags; 80 - 81 - wl1271_debug(DEBUG_IRQ, "IRQ"); 82 - 83 - /* complete the ELP completion */ 84 - spin_lock_irqsave(&wl->wl_lock, flags); 85 - set_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags); 86 - if (wl->elp_compl) { 87 - complete(wl->elp_compl); 88 - wl->elp_compl = NULL; 89 - } 90 - 91 - if (test_bit(WL1271_FLAG_SUSPENDED, &wl->flags)) { 92 - /* don't enqueue a work right now. mark it as pending */ 93 - set_bit(WL1271_FLAG_PENDING_WORK, &wl->flags); 94 - wl1271_debug(DEBUG_IRQ, "should not enqueue work"); 95 - disable_irq_nosync(wl->irq); 96 - pm_wakeup_event(wl1271_sdio_wl_to_dev(wl), 0); 97 - spin_unlock_irqrestore(&wl->wl_lock, flags); 98 - return IRQ_HANDLED; 99 - } 100 - spin_unlock_irqrestore(&wl->wl_lock, flags); 101 - 102 - return IRQ_WAKE_THREAD; 103 - } 104 - 105 - static void wl1271_sdio_disable_interrupts(struct wl1271 *wl) 106 - { 107 - disable_irq(wl->irq); 108 - } 109 - 110 - static void wl1271_sdio_enable_interrupts(struct wl1271 *wl) 111 - { 112 - enable_irq(wl->irq); 113 - } 114 - 115 - static void wl1271_sdio_raw_read(struct wl1271 *wl, int addr, void *buf, 71 + static void wl12xx_sdio_raw_read(struct device *child, int addr, void *buf, 116 72 size_t len, bool fixed) 117 73 { 118 74 int ret; 119 - struct wl12xx_sdio_glue *glue = wl_to_glue(wl); 75 + struct wl12xx_sdio_glue *glue = dev_get_drvdata(child->parent); 120 76 struct sdio_func *func = dev_to_sdio_func(glue->dev); 121 77 122 78 if (unlikely(addr == HW_ACCESS_ELP_CTRL_REG_ADDR)) { ··· 93 139 wl1271_error("sdio read failed (%d)", ret); 94 140 } 95 141 96 - static void wl1271_sdio_raw_write(struct wl1271 *wl, int addr, void *buf, 142 + static void wl12xx_sdio_raw_write(struct device *child, int addr, void *buf, 97 143 size_t len, bool fixed) 98 144 { 99 145 int ret; 100 - struct wl12xx_sdio_glue *glue = wl_to_glue(wl); 146 + struct wl12xx_sdio_glue *glue = dev_get_drvdata(child->parent); 101 147 struct sdio_func *func = dev_to_sdio_func(glue->dev); 102 148 103 149 if (unlikely(addr == HW_ACCESS_ELP_CTRL_REG_ADDR)) { ··· 119 165 wl1271_error("sdio write failed (%d)", ret); 120 166 } 121 167 122 - static int wl1271_sdio_power_on(struct wl1271 *wl) 168 + static int wl12xx_sdio_power_on(struct wl12xx_sdio_glue *glue) 123 169 { 124 170 int ret; 125 - struct wl12xx_sdio_glue *glue = wl_to_glue(wl); 126 171 struct sdio_func *func = dev_to_sdio_func(glue->dev); 127 172 128 173 /* If enabled, tell runtime PM not to power off the card */ ··· 143 190 return ret; 144 191 } 145 192 146 - static int wl1271_sdio_power_off(struct wl1271 *wl) 193 + static int wl12xx_sdio_power_off(struct wl12xx_sdio_glue *glue) 147 194 { 148 195 int ret; 149 - struct wl12xx_sdio_glue *glue = wl_to_glue(wl); 150 196 struct sdio_func *func = dev_to_sdio_func(glue->dev); 151 197 152 198 sdio_disable_func(func); ··· 163 211 return ret; 164 212 } 165 213 166 - static int wl1271_sdio_set_power(struct wl1271 *wl, bool enable) 214 + static int wl12xx_sdio_set_power(struct device *child, bool enable) 167 215 { 216 + struct wl12xx_sdio_glue *glue = dev_get_drvdata(child->parent); 217 + 168 218 if (enable) 169 - return wl1271_sdio_power_on(wl); 219 + return wl12xx_sdio_power_on(glue); 170 220 else 171 - return wl1271_sdio_power_off(wl); 221 + return wl12xx_sdio_power_off(glue); 172 222 } 173 223 174 224 static struct wl1271_if_operations sdio_ops = { 175 - .read = wl1271_sdio_raw_read, 176 - .write = wl1271_sdio_raw_write, 177 - .power = wl1271_sdio_set_power, 178 - .dev = wl1271_sdio_wl_to_dev, 179 - .enable_irq = wl1271_sdio_enable_interrupts, 180 - .disable_irq = wl1271_sdio_disable_interrupts, 225 + .read = wl12xx_sdio_raw_read, 226 + .write = wl12xx_sdio_raw_write, 227 + .power = wl12xx_sdio_set_power, 181 228 .set_block_size = wl1271_sdio_set_block_size, 182 229 }; 183 230 184 231 static int __devinit wl1271_probe(struct sdio_func *func, 185 232 const struct sdio_device_id *id) 186 233 { 187 - struct ieee80211_hw *hw; 188 - const struct wl12xx_platform_data *wlan_data; 189 - struct wl1271 *wl; 234 + struct wl12xx_platform_data *wlan_data; 190 235 struct wl12xx_sdio_glue *glue; 191 236 struct resource res[1]; 192 - unsigned long irqflags; 193 237 mmc_pm_flag_t mmcflags; 194 238 int ret = -ENOMEM; 195 239 ··· 199 251 goto out; 200 252 } 201 253 202 - hw = wl1271_alloc_hw(); 203 - if (IS_ERR(hw)) { 204 - wl1271_error("can't allocate hw"); 205 - ret = PTR_ERR(hw); 206 - goto out_free_glue; 207 - } 208 - 209 - wl = hw->priv; 210 - 211 254 glue->dev = &func->dev; 212 - glue->wl = wl; 213 - 214 - wl->if_priv = glue; 215 - wl->if_ops = &sdio_ops; 216 255 217 256 /* Grab access to FN0 for ELP reg. */ 218 257 func->card->quirks |= MMC_QUIRK_LENIENT_FN0; ··· 211 276 if (IS_ERR(wlan_data)) { 212 277 ret = PTR_ERR(wlan_data); 213 278 wl1271_error("missing wlan platform data: %d", ret); 214 - goto out_free_hw; 279 + goto out_free_glue; 215 280 } 216 281 217 - wl->irq = wlan_data->irq; 218 - wl->ref_clock = wlan_data->board_ref_clock; 219 - wl->tcxo_clock = wlan_data->board_tcxo_clock; 220 - wl->platform_quirks = wlan_data->platform_quirks; 282 + /* if sdio can keep power while host is suspended, enable wow */ 283 + mmcflags = sdio_get_host_pm_caps(func); 284 + wl1271_debug(DEBUG_SDIO, "sdio PM caps = 0x%x", mmcflags); 221 285 222 - if (wl->platform_quirks & WL12XX_PLATFORM_QUIRK_EDGE_IRQ) 223 - irqflags = IRQF_TRIGGER_RISING; 224 - else 225 - irqflags = IRQF_TRIGGER_HIGH | IRQF_ONESHOT; 286 + if (mmcflags & MMC_PM_KEEP_POWER) 287 + wlan_data->pwr_in_suspend = true; 226 288 227 - ret = request_threaded_irq(wl->irq, wl1271_hardirq, wl1271_irq, 228 - irqflags, 229 - DRIVER_NAME, wl); 230 - if (ret < 0) { 231 - wl1271_error("request_irq() failed: %d", ret); 232 - goto out_free_hw; 233 - } 234 - 235 - ret = enable_irq_wake(wl->irq); 236 - if (!ret) { 237 - wl->irq_wake_enabled = true; 238 - device_init_wakeup(wl1271_sdio_wl_to_dev(wl), 1); 239 - 240 - /* if sdio can keep power while host is suspended, enable wow */ 241 - mmcflags = sdio_get_host_pm_caps(func); 242 - wl1271_debug(DEBUG_SDIO, "sdio PM caps = 0x%x", mmcflags); 243 - 244 - if (mmcflags & MMC_PM_KEEP_POWER) 245 - hw->wiphy->wowlan.flags = WIPHY_WOWLAN_ANY; 246 - } 247 - disable_irq(wl->irq); 248 - 249 - ret = wl1271_init_ieee80211(wl); 250 - if (ret) 251 - goto out_irq; 252 - 253 - ret = wl1271_register_hw(wl); 254 - if (ret) 255 - goto out_irq; 289 + wlan_data->ops = &sdio_ops; 256 290 257 291 sdio_set_drvdata(func, glue); 258 292 ··· 232 328 if (!glue->core) { 233 329 wl1271_error("can't allocate platform_device"); 234 330 ret = -ENOMEM; 235 - goto out_unreg_hw; 331 + goto out_free_glue; 236 332 } 237 333 238 334 glue->core->dev.parent = &func->dev; ··· 266 362 out_dev_put: 267 363 platform_device_put(glue->core); 268 364 269 - out_unreg_hw: 270 - wl1271_unregister_hw(wl); 271 - 272 - out_irq: 273 - free_irq(wl->irq, wl); 274 - 275 - out_free_hw: 276 - wl1271_free_hw(wl); 277 - 278 365 out_free_glue: 279 366 kfree(glue); 367 + 280 368 out: 281 369 return ret; 282 370 } ··· 276 380 static void __devexit wl1271_remove(struct sdio_func *func) 277 381 { 278 382 struct wl12xx_sdio_glue *glue = sdio_get_drvdata(func); 279 - struct wl1271 *wl = glue->wl; 280 383 281 384 /* Undo decrement done above in wl1271_probe */ 282 385 pm_runtime_get_noresume(&func->dev); 283 386 284 - wl1271_unregister_hw(wl); 285 - if (wl->irq_wake_enabled) { 286 - device_init_wakeup(wl1271_sdio_wl_to_dev(wl), 0); 287 - disable_irq_wake(wl->irq); 288 - } 289 - free_irq(wl->irq, wl); 290 - wl1271_free_hw(wl); 291 387 platform_device_del(glue->core); 292 388 platform_device_put(glue->core); 293 389 kfree(glue);
+22 -139
drivers/net/wireless/wl12xx/spi.c
··· 72 72 73 73 struct wl12xx_spi_glue { 74 74 struct device *dev; 75 - struct wl1271 *wl; 76 75 struct platform_device *core; 77 76 }; 78 77 79 - static inline struct wl12xx_spi_glue *wl_to_glue(struct wl1271 *wl) 78 + static void wl12xx_spi_reset(struct device *child) 80 79 { 81 - return wl->if_priv; 82 - } 83 - 84 - static struct device *wl1271_spi_wl_to_dev(struct wl1271 *wl) 85 - { 86 - return wl_to_glue(wl)->dev; 87 - } 88 - 89 - static void wl1271_spi_disable_interrupts(struct wl1271 *wl) 90 - { 91 - disable_irq(wl->irq); 92 - } 93 - 94 - static void wl1271_spi_enable_interrupts(struct wl1271 *wl) 95 - { 96 - enable_irq(wl->irq); 97 - } 98 - 99 - static void wl1271_spi_reset(struct wl1271 *wl) 100 - { 101 - struct wl12xx_spi_glue *glue = wl_to_glue(wl); 80 + struct wl12xx_spi_glue *glue = dev_get_drvdata(child->parent); 102 81 u8 *cmd; 103 82 struct spi_transfer t; 104 83 struct spi_message m; ··· 103 124 kfree(cmd); 104 125 } 105 126 106 - static void wl1271_spi_init(struct wl1271 *wl) 127 + static void wl12xx_spi_init(struct device *child) 107 128 { 108 - struct wl12xx_spi_glue *glue = wl_to_glue(wl); 129 + struct wl12xx_spi_glue *glue = dev_get_drvdata(child->parent); 109 130 u8 crc[WSPI_INIT_CMD_CRC_LEN], *cmd; 110 131 struct spi_transfer t; 111 132 struct spi_message m; ··· 160 181 161 182 #define WL1271_BUSY_WORD_TIMEOUT 1000 162 183 163 - static int wl1271_spi_read_busy(struct wl1271 *wl) 184 + static int wl12xx_spi_read_busy(struct device *child) 164 185 { 165 - struct wl12xx_spi_glue *glue = wl_to_glue(wl); 186 + struct wl12xx_spi_glue *glue = dev_get_drvdata(child->parent); 187 + struct wl1271 *wl = dev_get_drvdata(child); 166 188 struct spi_transfer t[1]; 167 189 struct spi_message m; 168 190 u32 *busy_buf; ··· 195 215 return -ETIMEDOUT; 196 216 } 197 217 198 - static void wl1271_spi_raw_read(struct wl1271 *wl, int addr, void *buf, 218 + static void wl12xx_spi_raw_read(struct device *child, int addr, void *buf, 199 219 size_t len, bool fixed) 200 220 { 201 - struct wl12xx_spi_glue *glue = wl_to_glue(wl); 221 + struct wl12xx_spi_glue *glue = dev_get_drvdata(child->parent); 222 + struct wl1271 *wl = dev_get_drvdata(child); 202 223 struct spi_transfer t[2]; 203 224 struct spi_message m; 204 225 u32 *busy_buf; ··· 238 257 spi_sync(to_spi_device(glue->dev), &m); 239 258 240 259 if (!(busy_buf[WL1271_BUSY_WORD_CNT - 1] & 0x1) && 241 - wl1271_spi_read_busy(wl)) { 260 + wl12xx_spi_read_busy(child)) { 242 261 memset(buf, 0, chunk_len); 243 262 return; 244 263 } ··· 263 282 } 264 283 } 265 284 266 - static void wl1271_spi_raw_write(struct wl1271 *wl, int addr, void *buf, 267 - size_t len, bool fixed) 285 + static void wl12xx_spi_raw_write(struct device *child, int addr, void *buf, 286 + size_t len, bool fixed) 268 287 { 269 - struct wl12xx_spi_glue *glue = wl_to_glue(wl); 288 + struct wl12xx_spi_glue *glue = dev_get_drvdata(child->parent); 270 289 struct spi_transfer t[2 * WSPI_MAX_NUM_OF_CHUNKS]; 271 290 struct spi_message m; 272 291 u32 commands[WSPI_MAX_NUM_OF_CHUNKS]; ··· 314 333 spi_sync(to_spi_device(glue->dev), &m); 315 334 } 316 335 317 - static irqreturn_t wl1271_hardirq(int irq, void *cookie) 318 - { 319 - struct wl1271 *wl = cookie; 320 - unsigned long flags; 321 - 322 - wl1271_debug(DEBUG_IRQ, "IRQ"); 323 - 324 - /* complete the ELP completion */ 325 - spin_lock_irqsave(&wl->wl_lock, flags); 326 - set_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags); 327 - if (wl->elp_compl) { 328 - complete(wl->elp_compl); 329 - wl->elp_compl = NULL; 330 - } 331 - spin_unlock_irqrestore(&wl->wl_lock, flags); 332 - 333 - return IRQ_WAKE_THREAD; 334 - } 335 - 336 - static int wl1271_spi_set_power(struct wl1271 *wl, bool enable) 337 - { 338 - if (wl->set_power) 339 - wl->set_power(enable); 340 - 341 - return 0; 342 - } 343 - 344 336 static struct wl1271_if_operations spi_ops = { 345 - .read = wl1271_spi_raw_read, 346 - .write = wl1271_spi_raw_write, 347 - .reset = wl1271_spi_reset, 348 - .init = wl1271_spi_init, 349 - .power = wl1271_spi_set_power, 350 - .dev = wl1271_spi_wl_to_dev, 351 - .enable_irq = wl1271_spi_enable_interrupts, 352 - .disable_irq = wl1271_spi_disable_interrupts, 337 + .read = wl12xx_spi_raw_read, 338 + .write = wl12xx_spi_raw_write, 339 + .reset = wl12xx_spi_reset, 340 + .init = wl12xx_spi_init, 353 341 .set_block_size = NULL, 354 342 }; 355 343 ··· 326 376 { 327 377 struct wl12xx_spi_glue *glue; 328 378 struct wl12xx_platform_data *pdata; 329 - struct ieee80211_hw *hw; 330 - struct wl1271 *wl; 331 379 struct resource res[1]; 332 - unsigned long irqflags; 333 380 int ret = -ENOMEM; 334 381 335 382 pdata = spi->dev.platform_data; ··· 335 388 return -ENODEV; 336 389 } 337 390 391 + pdata->ops = &spi_ops; 392 + 338 393 glue = kzalloc(sizeof(*glue), GFP_KERNEL); 339 394 if (!glue) { 340 395 wl1271_error("can't allocate glue"); 341 396 goto out; 342 397 } 343 398 344 - hw = wl1271_alloc_hw(); 345 - if (IS_ERR(hw)) { 346 - ret = PTR_ERR(hw); 347 - goto out_free_glue; 348 - } 349 - 350 - wl = hw->priv; 351 - 352 399 glue->dev = &spi->dev; 353 - glue->wl = wl; 354 400 355 401 spi_set_drvdata(spi, glue); 356 - wl->if_priv = glue; 357 - 358 - wl->if_ops = &spi_ops; 359 402 360 403 /* This is the only SPI value that we need to set here, the rest 361 404 * comes from the board-peripherals file */ ··· 354 417 ret = spi_setup(spi); 355 418 if (ret < 0) { 356 419 wl1271_error("spi_setup failed"); 357 - goto out_free_hw; 420 + goto out_free_glue; 358 421 } 359 - 360 - wl->set_power = pdata->set_power; 361 - if (!wl->set_power) { 362 - wl1271_error("set power function missing in platform data"); 363 - ret = -ENODEV; 364 - goto out_free_hw; 365 - } 366 - 367 - wl->ref_clock = pdata->board_ref_clock; 368 - wl->tcxo_clock = pdata->board_tcxo_clock; 369 - wl->platform_quirks = pdata->platform_quirks; 370 - 371 - if (wl->platform_quirks & WL12XX_PLATFORM_QUIRK_EDGE_IRQ) 372 - irqflags = IRQF_TRIGGER_RISING; 373 - else 374 - irqflags = IRQF_TRIGGER_HIGH | IRQF_ONESHOT; 375 - 376 - wl->irq = spi->irq; 377 - if (wl->irq < 0) { 378 - wl1271_error("irq missing in platform data"); 379 - ret = -ENODEV; 380 - goto out_free_hw; 381 - } 382 - 383 - ret = request_threaded_irq(wl->irq, wl1271_hardirq, wl1271_irq, 384 - irqflags, 385 - DRIVER_NAME, wl); 386 - if (ret < 0) { 387 - wl1271_error("request_irq() failed: %d", ret); 388 - goto out_free_hw; 389 - } 390 - 391 - disable_irq(wl->irq); 392 - 393 - ret = wl1271_init_ieee80211(wl); 394 - if (ret) 395 - goto out_irq; 396 - 397 - ret = wl1271_register_hw(wl); 398 - if (ret) 399 - goto out_irq; 400 422 401 423 glue->core = platform_device_alloc("wl12xx-spi", -1); 402 424 if (!glue->core) { 403 425 wl1271_error("can't allocate platform_device"); 404 426 ret = -ENOMEM; 405 - goto out_unreg_hw; 427 + goto out_free_glue; 406 428 } 407 429 408 430 glue->core->dev.parent = &spi->dev; ··· 395 499 out_dev_put: 396 500 platform_device_put(glue->core); 397 501 398 - out_unreg_hw: 399 - wl1271_unregister_hw(wl); 400 - 401 - out_irq: 402 - free_irq(wl->irq, wl); 403 - 404 - out_free_hw: 405 - wl1271_free_hw(wl); 406 - 407 502 out_free_glue: 408 503 kfree(glue); 409 504 out: ··· 404 517 static int __devexit wl1271_remove(struct spi_device *spi) 405 518 { 406 519 struct wl12xx_spi_glue *glue = spi_get_drvdata(spi); 407 - struct wl1271 *wl = glue->wl; 408 520 409 - wl1271_unregister_hw(wl); 410 - free_irq(wl->irq, wl); 411 - wl1271_free_hw(wl); 412 521 platform_device_del(glue->core); 413 522 platform_device_put(glue->core); 414 523 kfree(glue);
+8 -9
drivers/net/wireless/wl12xx/wl12xx.h
··· 288 288 }; 289 289 290 290 struct wl1271_if_operations { 291 - void (*read)(struct wl1271 *wl, int addr, void *buf, size_t len, 291 + void (*read)(struct device *child, int addr, void *buf, size_t len, 292 292 bool fixed); 293 - void (*write)(struct wl1271 *wl, int addr, void *buf, size_t len, 293 + void (*write)(struct device *child, int addr, void *buf, size_t len, 294 294 bool fixed); 295 - void (*reset)(struct wl1271 *wl); 296 - void (*init)(struct wl1271 *wl); 297 - int (*power)(struct wl1271 *wl, bool enable); 298 - struct device* (*dev)(struct wl1271 *wl); 299 - void (*enable_irq)(struct wl1271 *wl); 300 - void (*disable_irq)(struct wl1271 *wl); 301 - void (*set_block_size) (struct wl1271 *wl, unsigned int blksz); 295 + void (*reset)(struct device *child); 296 + void (*init)(struct device *child); 297 + int (*power)(struct device *child, bool enable); 298 + void (*set_block_size) (struct device *child, unsigned int blksz); 302 299 }; 303 300 304 301 #define MAX_NUM_KEYS 14 ··· 358 361 struct platform_device *plat_dev; 359 362 struct ieee80211_hw *hw; 360 363 bool mac80211_registered; 364 + 365 + struct device *dev; 361 366 362 367 void *if_priv; 363 368
+2 -2
drivers/net/wireless/wl12xx/wl12xx_platform_data.c
··· 2 2 #include <linux/err.h> 3 3 #include <linux/wl12xx.h> 4 4 5 - static const struct wl12xx_platform_data *platform_data; 5 + static struct wl12xx_platform_data *platform_data; 6 6 7 7 int __init wl12xx_set_platform_data(const struct wl12xx_platform_data *data) 8 8 { ··· 18 18 return 0; 19 19 } 20 20 21 - const struct wl12xx_platform_data *wl12xx_get_platform_data(void) 21 + struct wl12xx_platform_data *wl12xx_get_platform_data(void) 22 22 { 23 23 if (!platform_data) 24 24 return ERR_PTR(-ENODEV);
+4 -1
include/linux/wl12xx.h
··· 54 54 int board_ref_clock; 55 55 int board_tcxo_clock; 56 56 unsigned long platform_quirks; 57 + bool pwr_in_suspend; 58 + 59 + struct wl1271_if_operations *ops; 57 60 }; 58 61 59 62 /* Platform does not support level trigger interrupts */ ··· 76 73 77 74 #endif 78 75 79 - const struct wl12xx_platform_data *wl12xx_get_platform_data(void); 76 + struct wl12xx_platform_data *wl12xx_get_platform_data(void); 80 77 81 78 #endif