| Teemu Paasikivi | 5129dff | 2010-02-22 08:38:27 +0200 | [diff] [blame] | 1 | /* | 
|  | 2 | * This file is part of wl1271 | 
|  | 3 | * | 
|  | 4 | * Copyright (C) 2009-2010 Nokia Corporation | 
|  | 5 | * | 
|  | 6 | * Contact: Luciano Coelho <luciano.coelho@nokia.com> | 
|  | 7 | * | 
|  | 8 | * This program is free software; you can redistribute it and/or | 
|  | 9 | * modify it under the terms of the GNU General Public License | 
|  | 10 | * version 2 as published by the Free Software Foundation. | 
|  | 11 | * | 
|  | 12 | * This program is distributed in the hope that it will be useful, but | 
|  | 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of | 
|  | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | 
|  | 15 | * General Public License for more details. | 
|  | 16 | * | 
|  | 17 | * You should have received a copy of the GNU General Public License | 
|  | 18 | * along with this program; if not, write to the Free Software | 
|  | 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | 
|  | 20 | * 02110-1301 USA | 
|  | 21 | * | 
|  | 22 | */ | 
|  | 23 |  | 
|  | 24 | #include <linux/irq.h> | 
|  | 25 | #include <linux/module.h> | 
| Teemu Paasikivi | 5129dff | 2010-02-22 08:38:27 +0200 | [diff] [blame] | 26 | #include <linux/vmalloc.h> | 
|  | 27 | #include <linux/mmc/sdio_func.h> | 
|  | 28 | #include <linux/mmc/sdio_ids.h> | 
|  | 29 | #include <linux/mmc/card.h> | 
| Ido Yariv | 11251e7 | 2011-02-28 00:13:58 +0200 | [diff] [blame] | 30 | #include <linux/mmc/host.h> | 
| Ohad Ben-Cohen | 19b8717 | 2010-05-13 12:43:24 +0300 | [diff] [blame] | 31 | #include <linux/gpio.h> | 
| Ohad Ben-Cohen | 09cecc3 | 2010-09-16 01:31:35 +0200 | [diff] [blame] | 32 | #include <linux/wl12xx.h> | 
| Ohad Ben-Cohen | 00cbb3c | 2010-10-08 16:16:16 +0300 | [diff] [blame] | 33 | #include <linux/pm_runtime.h> | 
| Teemu Paasikivi | 5129dff | 2010-02-22 08:38:27 +0200 | [diff] [blame] | 34 |  | 
| Shahar Levi | 00d2010 | 2010-11-08 11:20:10 +0000 | [diff] [blame] | 35 | #include "wl12xx.h" | 
| Teemu Paasikivi | 5129dff | 2010-02-22 08:38:27 +0200 | [diff] [blame] | 36 | #include "wl12xx_80211.h" | 
| Shahar Levi | 00d2010 | 2010-11-08 11:20:10 +0000 | [diff] [blame] | 37 | #include "io.h" | 
| Teemu Paasikivi | 5129dff | 2010-02-22 08:38:27 +0200 | [diff] [blame] | 38 |  | 
| Teemu Paasikivi | 5129dff | 2010-02-22 08:38:27 +0200 | [diff] [blame] | 39 | #ifndef SDIO_VENDOR_ID_TI | 
|  | 40 | #define SDIO_VENDOR_ID_TI		0x0097 | 
|  | 41 | #endif | 
|  | 42 |  | 
|  | 43 | #ifndef SDIO_DEVICE_ID_TI_WL1271 | 
|  | 44 | #define SDIO_DEVICE_ID_TI_WL1271	0x4076 | 
|  | 45 | #endif | 
|  | 46 |  | 
| Felipe Balbi | 33dd74c | 2011-05-14 00:26:18 +0300 | [diff] [blame] | 47 | static const struct sdio_device_id wl1271_devices[] __devinitconst = { | 
| Teemu Paasikivi | 5129dff | 2010-02-22 08:38:27 +0200 | [diff] [blame] | 48 | { SDIO_DEVICE(SDIO_VENDOR_ID_TI, SDIO_DEVICE_ID_TI_WL1271) }, | 
|  | 49 | {} | 
|  | 50 | }; | 
|  | 51 | MODULE_DEVICE_TABLE(sdio, wl1271_devices); | 
|  | 52 |  | 
| Ido Yariv | 0da13da | 2011-03-31 10:06:58 +0200 | [diff] [blame] | 53 | static void wl1271_sdio_set_block_size(struct wl1271 *wl, unsigned int blksz) | 
| Luciano Coelho | a81159e | 2011-03-14 14:05:13 +0200 | [diff] [blame] | 54 | { | 
| Luciano Coelho | a81159e | 2011-03-14 14:05:13 +0200 | [diff] [blame] | 55 | sdio_claim_host(wl->if_priv); | 
| Ido Yariv | 0da13da | 2011-03-31 10:06:58 +0200 | [diff] [blame] | 56 | sdio_set_block_size(wl->if_priv, blksz); | 
| Luciano Coelho | a81159e | 2011-03-14 14:05:13 +0200 | [diff] [blame] | 57 | sdio_release_host(wl->if_priv); | 
|  | 58 | } | 
|  | 59 |  | 
| Teemu Paasikivi | 5129dff | 2010-02-22 08:38:27 +0200 | [diff] [blame] | 60 | static inline struct sdio_func *wl_to_func(struct wl1271 *wl) | 
|  | 61 | { | 
|  | 62 | return wl->if_priv; | 
|  | 63 | } | 
|  | 64 |  | 
|  | 65 | static struct device *wl1271_sdio_wl_to_dev(struct wl1271 *wl) | 
|  | 66 | { | 
|  | 67 | return &(wl_to_func(wl)->dev); | 
|  | 68 | } | 
|  | 69 |  | 
| Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 70 | static irqreturn_t wl1271_hardirq(int irq, void *cookie) | 
| Teemu Paasikivi | 5129dff | 2010-02-22 08:38:27 +0200 | [diff] [blame] | 71 | { | 
|  | 72 | struct wl1271 *wl = cookie; | 
|  | 73 | unsigned long flags; | 
|  | 74 |  | 
|  | 75 | wl1271_debug(DEBUG_IRQ, "IRQ"); | 
|  | 76 |  | 
|  | 77 | /* complete the ELP completion */ | 
|  | 78 | spin_lock_irqsave(&wl->wl_lock, flags); | 
| Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 79 | set_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags); | 
| Teemu Paasikivi | 5129dff | 2010-02-22 08:38:27 +0200 | [diff] [blame] | 80 | if (wl->elp_compl) { | 
|  | 81 | complete(wl->elp_compl); | 
|  | 82 | wl->elp_compl = NULL; | 
|  | 83 | } | 
| Eliad Peller | f44e586 | 2011-05-13 11:57:11 +0300 | [diff] [blame] | 84 |  | 
|  | 85 | if (test_bit(WL1271_FLAG_SUSPENDED, &wl->flags)) { | 
|  | 86 | /* don't enqueue a work right now. mark it as pending */ | 
|  | 87 | set_bit(WL1271_FLAG_PENDING_WORK, &wl->flags); | 
|  | 88 | wl1271_debug(DEBUG_IRQ, "should not enqueue work"); | 
|  | 89 | disable_irq_nosync(wl->irq); | 
|  | 90 | pm_wakeup_event(wl1271_sdio_wl_to_dev(wl), 0); | 
|  | 91 | spin_unlock_irqrestore(&wl->wl_lock, flags); | 
|  | 92 | return IRQ_HANDLED; | 
|  | 93 | } | 
| Teemu Paasikivi | 5129dff | 2010-02-22 08:38:27 +0200 | [diff] [blame] | 94 | spin_unlock_irqrestore(&wl->wl_lock, flags); | 
|  | 95 |  | 
| Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 96 | return IRQ_WAKE_THREAD; | 
| Teemu Paasikivi | 5129dff | 2010-02-22 08:38:27 +0200 | [diff] [blame] | 97 | } | 
|  | 98 |  | 
|  | 99 | static void wl1271_sdio_disable_interrupts(struct wl1271 *wl) | 
|  | 100 | { | 
|  | 101 | disable_irq(wl->irq); | 
|  | 102 | } | 
|  | 103 |  | 
|  | 104 | static void wl1271_sdio_enable_interrupts(struct wl1271 *wl) | 
|  | 105 | { | 
|  | 106 | enable_irq(wl->irq); | 
|  | 107 | } | 
|  | 108 |  | 
| Teemu Paasikivi | 5129dff | 2010-02-22 08:38:27 +0200 | [diff] [blame] | 109 | static void wl1271_sdio_raw_read(struct wl1271 *wl, int addr, void *buf, | 
| Teemu Paasikivi | a3b8ea7 | 2010-03-18 12:26:41 +0200 | [diff] [blame] | 110 | size_t len, bool fixed) | 
| Teemu Paasikivi | 5129dff | 2010-02-22 08:38:27 +0200 | [diff] [blame] | 111 | { | 
|  | 112 | int ret; | 
|  | 113 | struct sdio_func *func = wl_to_func(wl); | 
|  | 114 |  | 
| Teemu Paasikivi | 5129dff | 2010-02-22 08:38:27 +0200 | [diff] [blame] | 115 | if (unlikely(addr == HW_ACCESS_ELP_CTRL_REG_ADDR)) { | 
|  | 116 | ((u8 *)buf)[0] = sdio_f0_readb(func, addr, &ret); | 
| Teemu Paasikivi | a3b8ea7 | 2010-03-18 12:26:41 +0200 | [diff] [blame] | 117 | wl1271_debug(DEBUG_SDIO, "sdio read 52 addr 0x%x, byte 0x%02x", | 
| Teemu Paasikivi | 5129dff | 2010-02-22 08:38:27 +0200 | [diff] [blame] | 118 | addr, ((u8 *)buf)[0]); | 
|  | 119 | } else { | 
|  | 120 | if (fixed) | 
|  | 121 | ret = sdio_readsb(func, buf, addr, len); | 
|  | 122 | else | 
|  | 123 | ret = sdio_memcpy_fromio(func, buf, addr, len); | 
|  | 124 |  | 
| Teemu Paasikivi | 99e5031 | 2010-03-26 12:53:16 +0200 | [diff] [blame] | 125 | wl1271_debug(DEBUG_SDIO, "sdio read 53 addr 0x%x, %zu bytes", | 
| Teemu Paasikivi | 5129dff | 2010-02-22 08:38:27 +0200 | [diff] [blame] | 126 | addr, len); | 
| Teemu Paasikivi | a3b8ea7 | 2010-03-18 12:26:41 +0200 | [diff] [blame] | 127 | wl1271_dump_ascii(DEBUG_SDIO, "data: ", buf, len); | 
| Teemu Paasikivi | 5129dff | 2010-02-22 08:38:27 +0200 | [diff] [blame] | 128 | } | 
|  | 129 |  | 
|  | 130 | if (ret) | 
|  | 131 | wl1271_error("sdio read failed (%d)", ret); | 
| Teemu Paasikivi | 5129dff | 2010-02-22 08:38:27 +0200 | [diff] [blame] | 132 | } | 
|  | 133 |  | 
|  | 134 | static void wl1271_sdio_raw_write(struct wl1271 *wl, int addr, void *buf, | 
| Teemu Paasikivi | a3b8ea7 | 2010-03-18 12:26:41 +0200 | [diff] [blame] | 135 | size_t len, bool fixed) | 
| Teemu Paasikivi | 5129dff | 2010-02-22 08:38:27 +0200 | [diff] [blame] | 136 | { | 
|  | 137 | int ret; | 
|  | 138 | struct sdio_func *func = wl_to_func(wl); | 
|  | 139 |  | 
| Teemu Paasikivi | 5129dff | 2010-02-22 08:38:27 +0200 | [diff] [blame] | 140 | if (unlikely(addr == HW_ACCESS_ELP_CTRL_REG_ADDR)) { | 
|  | 141 | sdio_f0_writeb(func, ((u8 *)buf)[0], addr, &ret); | 
| Teemu Paasikivi | a3b8ea7 | 2010-03-18 12:26:41 +0200 | [diff] [blame] | 142 | wl1271_debug(DEBUG_SDIO, "sdio write 52 addr 0x%x, byte 0x%02x", | 
| Teemu Paasikivi | 5129dff | 2010-02-22 08:38:27 +0200 | [diff] [blame] | 143 | addr, ((u8 *)buf)[0]); | 
|  | 144 | } else { | 
| Teemu Paasikivi | 99e5031 | 2010-03-26 12:53:16 +0200 | [diff] [blame] | 145 | wl1271_debug(DEBUG_SDIO, "sdio write 53 addr 0x%x, %zu bytes", | 
| Teemu Paasikivi | 5129dff | 2010-02-22 08:38:27 +0200 | [diff] [blame] | 146 | addr, len); | 
| Teemu Paasikivi | a3b8ea7 | 2010-03-18 12:26:41 +0200 | [diff] [blame] | 147 | wl1271_dump_ascii(DEBUG_SDIO, "data: ", buf, len); | 
| Teemu Paasikivi | 5129dff | 2010-02-22 08:38:27 +0200 | [diff] [blame] | 148 |  | 
|  | 149 | if (fixed) | 
|  | 150 | ret = sdio_writesb(func, addr, buf, len); | 
|  | 151 | else | 
|  | 152 | ret = sdio_memcpy_toio(func, addr, buf, len); | 
|  | 153 | } | 
| Ohad Ben-Cohen | 49063a0 | 2010-09-07 04:24:21 +0300 | [diff] [blame] | 154 |  | 
| Teemu Paasikivi | 5129dff | 2010-02-22 08:38:27 +0200 | [diff] [blame] | 155 | if (ret) | 
|  | 156 | wl1271_error("sdio write failed (%d)", ret); | 
| Ohad Ben-Cohen | 49063a0 | 2010-09-07 04:24:21 +0300 | [diff] [blame] | 157 | } | 
| Teemu Paasikivi | 5129dff | 2010-02-22 08:38:27 +0200 | [diff] [blame] | 158 |  | 
| Ohad Ben-Cohen | 2cc78ff | 2010-09-16 01:22:04 +0200 | [diff] [blame] | 159 | static int wl1271_sdio_power_on(struct wl1271 *wl) | 
| Ohad Ben-Cohen | 49063a0 | 2010-09-07 04:24:21 +0300 | [diff] [blame] | 160 | { | 
|  | 161 | struct sdio_func *func = wl_to_func(wl); | 
| Ohad Ben-Cohen | 00cbb3c | 2010-10-08 16:16:16 +0300 | [diff] [blame] | 162 | int ret; | 
|  | 163 |  | 
| Ohad Ben-Cohen | 86046da | 2011-05-29 16:36:03 +0300 | [diff] [blame] | 164 | /* If enabled, tell runtime PM not to power off the card */ | 
|  | 165 | if (pm_runtime_enabled(&func->dev)) { | 
|  | 166 | ret = pm_runtime_get_sync(&func->dev); | 
| Ido Yariv | a15f1c4 | 2011-08-22 23:19:49 +0300 | [diff] [blame] | 167 | if (ret < 0) | 
| Ohad Ben-Cohen | 86046da | 2011-05-29 16:36:03 +0300 | [diff] [blame] | 168 | goto out; | 
| Ohad Ben-Cohen | b5d6e5f | 2011-06-26 18:00:11 +0300 | [diff] [blame] | 169 | } else { | 
|  | 170 | /* Runtime PM is disabled: power up the card manually */ | 
|  | 171 | ret = mmc_power_restore_host(func->card->host); | 
|  | 172 | if (ret < 0) | 
|  | 173 | goto out; | 
| Ohad Ben-Cohen | 86046da | 2011-05-29 16:36:03 +0300 | [diff] [blame] | 174 | } | 
| Ohad Ben-Cohen | 49063a0 | 2010-09-07 04:24:21 +0300 | [diff] [blame] | 175 |  | 
|  | 176 | sdio_claim_host(func); | 
|  | 177 | sdio_enable_func(func); | 
| Ohad Ben-Cohen | 2cc78ff | 2010-09-16 01:22:04 +0200 | [diff] [blame] | 178 |  | 
| Ohad Ben-Cohen | 00cbb3c | 2010-10-08 16:16:16 +0300 | [diff] [blame] | 179 | out: | 
|  | 180 | return ret; | 
| Ohad Ben-Cohen | 49063a0 | 2010-09-07 04:24:21 +0300 | [diff] [blame] | 181 | } | 
|  | 182 |  | 
| Ohad Ben-Cohen | 2cc78ff | 2010-09-16 01:22:04 +0200 | [diff] [blame] | 183 | static int wl1271_sdio_power_off(struct wl1271 *wl) | 
| Ohad Ben-Cohen | 49063a0 | 2010-09-07 04:24:21 +0300 | [diff] [blame] | 184 | { | 
|  | 185 | struct sdio_func *func = wl_to_func(wl); | 
| Ido Yariv | 11251e7 | 2011-02-28 00:13:58 +0200 | [diff] [blame] | 186 | int ret; | 
| Ohad Ben-Cohen | 49063a0 | 2010-09-07 04:24:21 +0300 | [diff] [blame] | 187 |  | 
| Ohad Ben-Cohen | 49063a0 | 2010-09-07 04:24:21 +0300 | [diff] [blame] | 188 | sdio_disable_func(func); | 
|  | 189 | sdio_release_host(func); | 
| Ohad Ben-Cohen | 2cc78ff | 2010-09-16 01:22:04 +0200 | [diff] [blame] | 190 |  | 
| Ohad Ben-Cohen | b5d6e5f | 2011-06-26 18:00:11 +0300 | [diff] [blame] | 191 | /* Power off the card manually, even if runtime PM is enabled. */ | 
| Ido Yariv | 11251e7 | 2011-02-28 00:13:58 +0200 | [diff] [blame] | 192 | ret = mmc_power_save_host(func->card->host); | 
|  | 193 | if (ret < 0) | 
|  | 194 | return ret; | 
|  | 195 |  | 
| Ohad Ben-Cohen | 86046da | 2011-05-29 16:36:03 +0300 | [diff] [blame] | 196 | /* If enabled, let runtime PM know the card is powered off */ | 
|  | 197 | if (pm_runtime_enabled(&func->dev)) | 
|  | 198 | ret = pm_runtime_put_sync(&func->dev); | 
|  | 199 |  | 
|  | 200 | return ret; | 
| Teemu Paasikivi | 5129dff | 2010-02-22 08:38:27 +0200 | [diff] [blame] | 201 | } | 
|  | 202 |  | 
| Ohad Ben-Cohen | 2cc78ff | 2010-09-16 01:22:04 +0200 | [diff] [blame] | 203 | static int wl1271_sdio_set_power(struct wl1271 *wl, bool enable) | 
| Teemu Paasikivi | becd551 | 2010-03-18 12:26:27 +0200 | [diff] [blame] | 204 | { | 
| Ohad Ben-Cohen | 49063a0 | 2010-09-07 04:24:21 +0300 | [diff] [blame] | 205 | if (enable) | 
| Ohad Ben-Cohen | 2cc78ff | 2010-09-16 01:22:04 +0200 | [diff] [blame] | 206 | return wl1271_sdio_power_on(wl); | 
| Ohad Ben-Cohen | 49063a0 | 2010-09-07 04:24:21 +0300 | [diff] [blame] | 207 | else | 
| Ohad Ben-Cohen | 2cc78ff | 2010-09-16 01:22:04 +0200 | [diff] [blame] | 208 | return wl1271_sdio_power_off(wl); | 
| Teemu Paasikivi | becd551 | 2010-03-18 12:26:27 +0200 | [diff] [blame] | 209 | } | 
|  | 210 |  | 
| Teemu Paasikivi | 5129dff | 2010-02-22 08:38:27 +0200 | [diff] [blame] | 211 | static struct wl1271_if_operations sdio_ops = { | 
|  | 212 | .read		= wl1271_sdio_raw_read, | 
|  | 213 | .write		= wl1271_sdio_raw_write, | 
| Teemu Paasikivi | becd551 | 2010-03-18 12:26:27 +0200 | [diff] [blame] | 214 | .power		= wl1271_sdio_set_power, | 
| Teemu Paasikivi | 5129dff | 2010-02-22 08:38:27 +0200 | [diff] [blame] | 215 | .dev		= wl1271_sdio_wl_to_dev, | 
|  | 216 | .enable_irq	= wl1271_sdio_enable_interrupts, | 
| Luciano Coelho | a81159e | 2011-03-14 14:05:13 +0200 | [diff] [blame] | 217 | .disable_irq	= wl1271_sdio_disable_interrupts, | 
|  | 218 | .set_block_size = wl1271_sdio_set_block_size, | 
| Teemu Paasikivi | 5129dff | 2010-02-22 08:38:27 +0200 | [diff] [blame] | 219 | }; | 
|  | 220 |  | 
| Teemu Paasikivi | 5129dff | 2010-02-22 08:38:27 +0200 | [diff] [blame] | 221 | static int __devinit wl1271_probe(struct sdio_func *func, | 
|  | 222 | const struct sdio_device_id *id) | 
|  | 223 | { | 
|  | 224 | struct ieee80211_hw *hw; | 
| Ohad Ben-Cohen | 09cecc3 | 2010-09-16 01:31:35 +0200 | [diff] [blame] | 225 | const struct wl12xx_platform_data *wlan_data; | 
| Teemu Paasikivi | 5129dff | 2010-02-22 08:38:27 +0200 | [diff] [blame] | 226 | struct wl1271 *wl; | 
| Ido Yariv | 341b7cd | 2011-03-31 10:07:01 +0200 | [diff] [blame] | 227 | unsigned long irqflags; | 
| Eliad Peller | f795ea8 | 2011-05-13 11:57:12 +0300 | [diff] [blame] | 228 | mmc_pm_flag_t mmcflags; | 
| Teemu Paasikivi | 5129dff | 2010-02-22 08:38:27 +0200 | [diff] [blame] | 229 | int ret; | 
|  | 230 |  | 
|  | 231 | /* We are only able to handle the wlan function */ | 
|  | 232 | if (func->num != 0x02) | 
|  | 233 | return -ENODEV; | 
|  | 234 |  | 
|  | 235 | hw = wl1271_alloc_hw(); | 
|  | 236 | if (IS_ERR(hw)) | 
|  | 237 | return PTR_ERR(hw); | 
|  | 238 |  | 
|  | 239 | wl = hw->priv; | 
|  | 240 |  | 
|  | 241 | wl->if_priv = func; | 
|  | 242 | wl->if_ops = &sdio_ops; | 
|  | 243 |  | 
| Teemu Paasikivi | 5129dff | 2010-02-22 08:38:27 +0200 | [diff] [blame] | 244 | /* Grab access to FN0 for ELP reg. */ | 
|  | 245 | func->card->quirks |= MMC_QUIRK_LENIENT_FN0; | 
|  | 246 |  | 
| Arik Nemtsov | 1d732e8 | 2011-03-18 14:49:57 +0200 | [diff] [blame] | 247 | /* Use block mode for transferring over one block size of data */ | 
|  | 248 | func->card->quirks |= MMC_QUIRK_BLKSZ_FOR_BYTE_MODE; | 
|  | 249 |  | 
| Ohad Ben-Cohen | 09cecc3 | 2010-09-16 01:31:35 +0200 | [diff] [blame] | 250 | wlan_data = wl12xx_get_platform_data(); | 
|  | 251 | if (IS_ERR(wlan_data)) { | 
|  | 252 | ret = PTR_ERR(wlan_data); | 
|  | 253 | wl1271_error("missing wlan platform data: %d", ret); | 
| Teemu Paasikivi | 5129dff | 2010-02-22 08:38:27 +0200 | [diff] [blame] | 254 | goto out_free; | 
|  | 255 | } | 
|  | 256 |  | 
| Ohad Ben-Cohen | 09cecc3 | 2010-09-16 01:31:35 +0200 | [diff] [blame] | 257 | wl->irq = wlan_data->irq; | 
| Ohad Ben-Cohen | 15cea99 | 2010-09-16 01:31:51 +0200 | [diff] [blame] | 258 | wl->ref_clock = wlan_data->board_ref_clock; | 
| Shahar Levi | 5ea417a | 2011-03-06 16:32:11 +0200 | [diff] [blame] | 259 | wl->tcxo_clock = wlan_data->board_tcxo_clock; | 
| Ido Yariv | 341b7cd | 2011-03-31 10:07:01 +0200 | [diff] [blame] | 260 | wl->platform_quirks = wlan_data->platform_quirks; | 
|  | 261 |  | 
|  | 262 | if (wl->platform_quirks & WL12XX_PLATFORM_QUIRK_EDGE_IRQ) | 
|  | 263 | irqflags = IRQF_TRIGGER_RISING; | 
|  | 264 | else | 
|  | 265 | irqflags = IRQF_TRIGGER_HIGH | IRQF_ONESHOT; | 
| Ohad Ben-Cohen | 09cecc3 | 2010-09-16 01:31:35 +0200 | [diff] [blame] | 266 |  | 
| Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 267 | ret = request_threaded_irq(wl->irq, wl1271_hardirq, wl1271_irq, | 
| Ido Yariv | 341b7cd | 2011-03-31 10:07:01 +0200 | [diff] [blame] | 268 | irqflags, | 
| Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 269 | DRIVER_NAME, wl); | 
| Teemu Paasikivi | 5129dff | 2010-02-22 08:38:27 +0200 | [diff] [blame] | 270 | if (ret < 0) { | 
|  | 271 | wl1271_error("request_irq() failed: %d", ret); | 
|  | 272 | goto out_free; | 
|  | 273 | } | 
|  | 274 |  | 
| Eliad Peller | 6bb0433 | 2011-06-06 12:21:55 +0300 | [diff] [blame] | 275 | ret = enable_irq_wake(wl->irq); | 
|  | 276 | if (!ret) { | 
|  | 277 | wl->irq_wake_enabled = true; | 
|  | 278 | device_init_wakeup(wl1271_sdio_wl_to_dev(wl), 1); | 
| Eliad Peller | 2c0f246 | 2011-05-13 11:57:08 +0300 | [diff] [blame] | 279 |  | 
| Eliad Peller | 6bb0433 | 2011-06-06 12:21:55 +0300 | [diff] [blame] | 280 | /* if sdio can keep power while host is suspended, enable wow */ | 
|  | 281 | mmcflags = sdio_get_host_pm_caps(func); | 
|  | 282 | wl1271_debug(DEBUG_SDIO, "sdio PM caps = 0x%x", mmcflags); | 
|  | 283 |  | 
|  | 284 | if (mmcflags & MMC_PM_KEEP_POWER) | 
|  | 285 | hw->wiphy->wowlan.flags = WIPHY_WOWLAN_ANY; | 
|  | 286 | } | 
| Teemu Paasikivi | 5129dff | 2010-02-22 08:38:27 +0200 | [diff] [blame] | 287 | disable_irq(wl->irq); | 
|  | 288 |  | 
|  | 289 | ret = wl1271_init_ieee80211(wl); | 
|  | 290 | if (ret) | 
|  | 291 | goto out_irq; | 
|  | 292 |  | 
|  | 293 | ret = wl1271_register_hw(wl); | 
|  | 294 | if (ret) | 
|  | 295 | goto out_irq; | 
|  | 296 |  | 
| Teemu Paasikivi | 49d7f6d | 2010-02-22 08:38:29 +0200 | [diff] [blame] | 297 | sdio_set_drvdata(func, wl); | 
|  | 298 |  | 
| Ohad Ben-Cohen | 00cbb3c | 2010-10-08 16:16:16 +0300 | [diff] [blame] | 299 | /* Tell PM core that we don't need the card to be powered now */ | 
|  | 300 | pm_runtime_put_noidle(&func->dev); | 
|  | 301 |  | 
| Teemu Paasikivi | 5129dff | 2010-02-22 08:38:27 +0200 | [diff] [blame] | 302 | return 0; | 
|  | 303 |  | 
| Teemu Paasikivi | 5129dff | 2010-02-22 08:38:27 +0200 | [diff] [blame] | 304 | out_irq: | 
|  | 305 | free_irq(wl->irq, wl); | 
|  | 306 |  | 
| Teemu Paasikivi | 5129dff | 2010-02-22 08:38:27 +0200 | [diff] [blame] | 307 | out_free: | 
| Teemu Paasikivi | 3b56dd6 | 2010-03-18 12:26:46 +0200 | [diff] [blame] | 308 | wl1271_free_hw(wl); | 
| Teemu Paasikivi | 5129dff | 2010-02-22 08:38:27 +0200 | [diff] [blame] | 309 |  | 
|  | 310 | return ret; | 
|  | 311 | } | 
|  | 312 |  | 
|  | 313 | static void __devexit wl1271_remove(struct sdio_func *func) | 
|  | 314 | { | 
|  | 315 | struct wl1271 *wl = sdio_get_drvdata(func); | 
|  | 316 |  | 
| Ohad Ben-Cohen | 00cbb3c | 2010-10-08 16:16:16 +0300 | [diff] [blame] | 317 | /* Undo decrement done above in wl1271_probe */ | 
|  | 318 | pm_runtime_get_noresume(&func->dev); | 
|  | 319 |  | 
| Teemu Paasikivi | 3b56dd6 | 2010-03-18 12:26:46 +0200 | [diff] [blame] | 320 | wl1271_unregister_hw(wl); | 
| Eliad Peller | 6bb0433 | 2011-06-06 12:21:55 +0300 | [diff] [blame] | 321 | if (wl->irq_wake_enabled) { | 
|  | 322 | device_init_wakeup(wl1271_sdio_wl_to_dev(wl), 0); | 
|  | 323 | disable_irq_wake(wl->irq); | 
|  | 324 | } | 
| Juuso Oikarinen | 4e23b11 | 2010-08-13 04:46:48 +0200 | [diff] [blame] | 325 | free_irq(wl->irq, wl); | 
| Teemu Paasikivi | 801a673 | 2010-03-18 12:26:42 +0200 | [diff] [blame] | 326 | wl1271_free_hw(wl); | 
| Teemu Paasikivi | 5129dff | 2010-02-22 08:38:27 +0200 | [diff] [blame] | 327 | } | 
|  | 328 |  | 
| Luciano Coelho | f634a4e | 2011-05-18 16:51:26 -0400 | [diff] [blame] | 329 | #ifdef CONFIG_PM | 
| Ohad Ben-Cohen | 674f305 | 2010-10-08 16:16:27 +0300 | [diff] [blame] | 330 | static int wl1271_suspend(struct device *dev) | 
|  | 331 | { | 
|  | 332 | /* Tell MMC/SDIO core it's OK to power down the card | 
|  | 333 | * (if it isn't already), but not to remove it completely */ | 
| Eliad Peller | 039bdb1 | 2011-05-13 11:57:10 +0300 | [diff] [blame] | 334 | struct sdio_func *func = dev_to_sdio_func(dev); | 
|  | 335 | struct wl1271 *wl = sdio_get_drvdata(func); | 
|  | 336 | mmc_pm_flag_t sdio_flags; | 
|  | 337 | int ret = 0; | 
|  | 338 |  | 
|  | 339 | wl1271_debug(DEBUG_MAC80211, "wl1271 suspend. wow_enabled: %d", | 
|  | 340 | wl->wow_enabled); | 
|  | 341 |  | 
|  | 342 | /* check whether sdio should keep power */ | 
|  | 343 | if (wl->wow_enabled) { | 
|  | 344 | sdio_flags = sdio_get_host_pm_caps(func); | 
|  | 345 |  | 
|  | 346 | if (!(sdio_flags & MMC_PM_KEEP_POWER)) { | 
|  | 347 | wl1271_error("can't keep power while host " | 
|  | 348 | "is suspended"); | 
|  | 349 | ret = -EINVAL; | 
|  | 350 | goto out; | 
|  | 351 | } | 
|  | 352 |  | 
|  | 353 | /* keep power while host suspended */ | 
|  | 354 | ret = sdio_set_host_pm_flags(func, MMC_PM_KEEP_POWER); | 
|  | 355 | if (ret) { | 
|  | 356 | wl1271_error("error while trying to keep power"); | 
|  | 357 | goto out; | 
|  | 358 | } | 
| Eliad Peller | f44e586 | 2011-05-13 11:57:11 +0300 | [diff] [blame] | 359 |  | 
|  | 360 | /* release host */ | 
|  | 361 | sdio_release_host(func); | 
| Eliad Peller | 039bdb1 | 2011-05-13 11:57:10 +0300 | [diff] [blame] | 362 | } | 
|  | 363 | out: | 
|  | 364 | return ret; | 
| Ohad Ben-Cohen | 674f305 | 2010-10-08 16:16:27 +0300 | [diff] [blame] | 365 | } | 
|  | 366 |  | 
|  | 367 | static int wl1271_resume(struct device *dev) | 
|  | 368 | { | 
| Eliad Peller | f44e586 | 2011-05-13 11:57:11 +0300 | [diff] [blame] | 369 | struct sdio_func *func = dev_to_sdio_func(dev); | 
|  | 370 | struct wl1271 *wl = sdio_get_drvdata(func); | 
|  | 371 |  | 
|  | 372 | wl1271_debug(DEBUG_MAC80211, "wl1271 resume"); | 
|  | 373 | if (wl->wow_enabled) { | 
|  | 374 | /* claim back host */ | 
|  | 375 | sdio_claim_host(func); | 
|  | 376 | } | 
|  | 377 |  | 
| Ohad Ben-Cohen | 674f305 | 2010-10-08 16:16:27 +0300 | [diff] [blame] | 378 | return 0; | 
|  | 379 | } | 
|  | 380 |  | 
|  | 381 | static const struct dev_pm_ops wl1271_sdio_pm_ops = { | 
|  | 382 | .suspend	= wl1271_suspend, | 
|  | 383 | .resume		= wl1271_resume, | 
|  | 384 | }; | 
| Luciano Coelho | f634a4e | 2011-05-18 16:51:26 -0400 | [diff] [blame] | 385 | #endif | 
| Ohad Ben-Cohen | 674f305 | 2010-10-08 16:16:27 +0300 | [diff] [blame] | 386 |  | 
| Teemu Paasikivi | 5129dff | 2010-02-22 08:38:27 +0200 | [diff] [blame] | 387 | static struct sdio_driver wl1271_sdio_driver = { | 
| Luciano Coelho | f4b5d8d | 2010-04-01 11:38:17 +0300 | [diff] [blame] | 388 | .name		= "wl1271_sdio", | 
| Teemu Paasikivi | 5129dff | 2010-02-22 08:38:27 +0200 | [diff] [blame] | 389 | .id_table	= wl1271_devices, | 
|  | 390 | .probe		= wl1271_probe, | 
|  | 391 | .remove		= __devexit_p(wl1271_remove), | 
| Luciano Coelho | f634a4e | 2011-05-18 16:51:26 -0400 | [diff] [blame] | 392 | #ifdef CONFIG_PM | 
| Ohad Ben-Cohen | 674f305 | 2010-10-08 16:16:27 +0300 | [diff] [blame] | 393 | .drv = { | 
|  | 394 | .pm = &wl1271_sdio_pm_ops, | 
|  | 395 | }, | 
| Luciano Coelho | f634a4e | 2011-05-18 16:51:26 -0400 | [diff] [blame] | 396 | #endif | 
| Teemu Paasikivi | 5129dff | 2010-02-22 08:38:27 +0200 | [diff] [blame] | 397 | }; | 
|  | 398 |  | 
|  | 399 | static int __init wl1271_init(void) | 
|  | 400 | { | 
| Felipe Balbi | 6bdaf79 | 2011-05-14 00:26:20 +0300 | [diff] [blame] | 401 | return sdio_register_driver(&wl1271_sdio_driver); | 
| Teemu Paasikivi | 5129dff | 2010-02-22 08:38:27 +0200 | [diff] [blame] | 402 | } | 
|  | 403 |  | 
|  | 404 | static void __exit wl1271_exit(void) | 
|  | 405 | { | 
|  | 406 | sdio_unregister_driver(&wl1271_sdio_driver); | 
| Teemu Paasikivi | 5129dff | 2010-02-22 08:38:27 +0200 | [diff] [blame] | 407 | } | 
|  | 408 |  | 
|  | 409 | module_init(wl1271_init); | 
|  | 410 | module_exit(wl1271_exit); | 
|  | 411 |  | 
|  | 412 | MODULE_LICENSE("GPL"); | 
| Luciano Coelho | 5245e3a | 2011-03-30 21:31:39 +0300 | [diff] [blame] | 413 | MODULE_AUTHOR("Luciano Coelho <coelho@ti.com>"); | 
| Teemu Paasikivi | 5129dff | 2010-02-22 08:38:27 +0200 | [diff] [blame] | 414 | MODULE_AUTHOR("Juuso Oikarinen <juuso.oikarinen@nokia.com>"); | 
| Arik Nemtsov | c302b2c | 2011-08-17 10:45:48 +0300 | [diff] [blame] | 415 | MODULE_FIRMWARE(WL127X_FW_NAME); | 
| Shahar Levi | 5aa4234 | 2011-03-06 16:32:07 +0200 | [diff] [blame] | 416 | MODULE_FIRMWARE(WL128X_FW_NAME); |