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