Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of wl1271 |
| 3 | * |
| 4 | * Copyright (C) 2008-2009 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 | |
Teemu Paasikivi | 2d5e82b | 2010-02-22 08:38:21 +0200 | [diff] [blame] | 24 | #include <linux/irq.h> |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 25 | #include <linux/module.h> |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 26 | #include <linux/crc7.h> |
| 27 | #include <linux/spi/spi.h> |
Teemu Paasikivi | 2d5e82b | 2010-02-22 08:38:21 +0200 | [diff] [blame] | 28 | #include <linux/spi/wl12xx.h> |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 29 | |
| 30 | #include "wl1271.h" |
| 31 | #include "wl12xx_80211.h" |
Teemu Paasikivi | 2d5e82b | 2010-02-22 08:38:21 +0200 | [diff] [blame] | 32 | #include "wl1271_io.h" |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 33 | |
Teemu Paasikivi | 760d969 | 2010-02-22 08:38:25 +0200 | [diff] [blame] | 34 | #include "wl1271_reg.h" |
| 35 | |
| 36 | #define WSPI_CMD_READ 0x40000000 |
| 37 | #define WSPI_CMD_WRITE 0x00000000 |
| 38 | #define WSPI_CMD_FIXED 0x20000000 |
| 39 | #define WSPI_CMD_BYTE_LENGTH 0x1FFE0000 |
| 40 | #define WSPI_CMD_BYTE_LENGTH_OFFSET 17 |
| 41 | #define WSPI_CMD_BYTE_ADDR 0x0001FFFF |
| 42 | |
| 43 | #define WSPI_INIT_CMD_CRC_LEN 5 |
| 44 | |
| 45 | #define WSPI_INIT_CMD_START 0x00 |
| 46 | #define WSPI_INIT_CMD_TX 0x40 |
| 47 | /* the extra bypass bit is sampled by the TNET as '1' */ |
| 48 | #define WSPI_INIT_CMD_BYPASS_BIT 0x80 |
| 49 | #define WSPI_INIT_CMD_FIXEDBUSY_LEN 0x07 |
| 50 | #define WSPI_INIT_CMD_EN_FIXEDBUSY 0x80 |
| 51 | #define WSPI_INIT_CMD_DIS_FIXEDBUSY 0x00 |
| 52 | #define WSPI_INIT_CMD_IOD 0x40 |
| 53 | #define WSPI_INIT_CMD_IP 0x20 |
| 54 | #define WSPI_INIT_CMD_CS 0x10 |
| 55 | #define WSPI_INIT_CMD_WS 0x08 |
| 56 | #define WSPI_INIT_CMD_WSPI 0x01 |
| 57 | #define WSPI_INIT_CMD_END 0x01 |
| 58 | |
| 59 | #define WSPI_INIT_CMD_LEN 8 |
| 60 | |
| 61 | #define HW_ACCESS_WSPI_FIXED_BUSY_LEN \ |
| 62 | ((WL1271_BUSY_WORD_LEN - 4) / sizeof(u32)) |
| 63 | #define HW_ACCESS_WSPI_INIT_CMD_MASK 0 |
| 64 | |
Teemu Paasikivi | b42f91b | 2010-02-22 08:38:24 +0200 | [diff] [blame] | 65 | static inline struct spi_device *wl_to_spi(struct wl1271 *wl) |
Teemu Paasikivi | 8197b71 | 2010-02-22 08:38:23 +0200 | [diff] [blame] | 66 | { |
| 67 | return wl->if_priv; |
| 68 | } |
| 69 | |
| 70 | static struct device *wl1271_spi_wl_to_dev(struct wl1271 *wl) |
| 71 | { |
| 72 | return &(wl_to_spi(wl)->dev); |
| 73 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 74 | |
Teemu Paasikivi | 760d969 | 2010-02-22 08:38:25 +0200 | [diff] [blame] | 75 | static void wl1271_spi_disable_interrupts(struct wl1271 *wl) |
Teemu Paasikivi | 54f7e50 | 2010-02-22 08:38:22 +0200 | [diff] [blame] | 76 | { |
| 77 | disable_irq(wl->irq); |
| 78 | } |
| 79 | |
Teemu Paasikivi | 760d969 | 2010-02-22 08:38:25 +0200 | [diff] [blame] | 80 | static void wl1271_spi_enable_interrupts(struct wl1271 *wl) |
Teemu Paasikivi | 54f7e50 | 2010-02-22 08:38:22 +0200 | [diff] [blame] | 81 | { |
| 82 | enable_irq(wl->irq); |
| 83 | } |
| 84 | |
Teemu Paasikivi | 760d969 | 2010-02-22 08:38:25 +0200 | [diff] [blame] | 85 | static void wl1271_spi_reset(struct wl1271 *wl) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 86 | { |
| 87 | u8 *cmd; |
| 88 | struct spi_transfer t; |
| 89 | struct spi_message m; |
| 90 | |
| 91 | cmd = kzalloc(WSPI_INIT_CMD_LEN, GFP_KERNEL); |
| 92 | if (!cmd) { |
| 93 | wl1271_error("could not allocate cmd for spi reset"); |
| 94 | return; |
| 95 | } |
| 96 | |
| 97 | memset(&t, 0, sizeof(t)); |
| 98 | spi_message_init(&m); |
| 99 | |
| 100 | memset(cmd, 0xff, WSPI_INIT_CMD_LEN); |
| 101 | |
| 102 | t.tx_buf = cmd; |
| 103 | t.len = WSPI_INIT_CMD_LEN; |
| 104 | spi_message_add_tail(&t, &m); |
| 105 | |
Teemu Paasikivi | 8197b71 | 2010-02-22 08:38:23 +0200 | [diff] [blame] | 106 | spi_sync(wl_to_spi(wl), &m); |
Juuso Oikarinen | f83cce3 | 2010-03-26 12:53:13 +0200 | [diff] [blame] | 107 | kfree(cmd); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 108 | |
| 109 | wl1271_dump(DEBUG_SPI, "spi reset -> ", cmd, WSPI_INIT_CMD_LEN); |
| 110 | } |
| 111 | |
Teemu Paasikivi | 760d969 | 2010-02-22 08:38:25 +0200 | [diff] [blame] | 112 | static void wl1271_spi_init(struct wl1271 *wl) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 113 | { |
| 114 | u8 crc[WSPI_INIT_CMD_CRC_LEN], *cmd; |
| 115 | struct spi_transfer t; |
| 116 | struct spi_message m; |
| 117 | |
| 118 | cmd = kzalloc(WSPI_INIT_CMD_LEN, GFP_KERNEL); |
| 119 | if (!cmd) { |
| 120 | wl1271_error("could not allocate cmd for spi init"); |
| 121 | return; |
| 122 | } |
| 123 | |
| 124 | memset(crc, 0, sizeof(crc)); |
| 125 | memset(&t, 0, sizeof(t)); |
| 126 | spi_message_init(&m); |
| 127 | |
| 128 | /* |
| 129 | * Set WSPI_INIT_COMMAND |
| 130 | * the data is being send from the MSB to LSB |
| 131 | */ |
| 132 | cmd[2] = 0xff; |
| 133 | cmd[3] = 0xff; |
| 134 | cmd[1] = WSPI_INIT_CMD_START | WSPI_INIT_CMD_TX; |
| 135 | cmd[0] = 0; |
| 136 | cmd[7] = 0; |
| 137 | cmd[6] |= HW_ACCESS_WSPI_INIT_CMD_MASK << 3; |
| 138 | cmd[6] |= HW_ACCESS_WSPI_FIXED_BUSY_LEN & WSPI_INIT_CMD_FIXEDBUSY_LEN; |
| 139 | |
| 140 | if (HW_ACCESS_WSPI_FIXED_BUSY_LEN == 0) |
| 141 | cmd[5] |= WSPI_INIT_CMD_DIS_FIXEDBUSY; |
| 142 | else |
| 143 | cmd[5] |= WSPI_INIT_CMD_EN_FIXEDBUSY; |
| 144 | |
| 145 | cmd[5] |= WSPI_INIT_CMD_IOD | WSPI_INIT_CMD_IP | WSPI_INIT_CMD_CS |
| 146 | | WSPI_INIT_CMD_WSPI | WSPI_INIT_CMD_WS; |
| 147 | |
| 148 | crc[0] = cmd[1]; |
| 149 | crc[1] = cmd[0]; |
| 150 | crc[2] = cmd[7]; |
| 151 | crc[3] = cmd[6]; |
| 152 | crc[4] = cmd[5]; |
| 153 | |
| 154 | cmd[4] |= crc7(0, crc, WSPI_INIT_CMD_CRC_LEN) << 1; |
| 155 | cmd[4] |= WSPI_INIT_CMD_END; |
| 156 | |
| 157 | t.tx_buf = cmd; |
| 158 | t.len = WSPI_INIT_CMD_LEN; |
| 159 | spi_message_add_tail(&t, &m); |
| 160 | |
Teemu Paasikivi | 8197b71 | 2010-02-22 08:38:23 +0200 | [diff] [blame] | 161 | spi_sync(wl_to_spi(wl), &m); |
Juuso Oikarinen | f83cce3 | 2010-03-26 12:53:13 +0200 | [diff] [blame] | 162 | kfree(cmd); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 163 | |
| 164 | wl1271_dump(DEBUG_SPI, "spi init -> ", cmd, WSPI_INIT_CMD_LEN); |
| 165 | } |
| 166 | |
Juuso Oikarinen | 545f1da | 2009-10-08 21:56:23 +0300 | [diff] [blame] | 167 | #define WL1271_BUSY_WORD_TIMEOUT 1000 |
| 168 | |
Juuso Oikarinen | 259da43 | 2010-03-26 12:53:18 +0200 | [diff] [blame] | 169 | static int wl1271_spi_read_busy(struct wl1271 *wl) |
Juuso Oikarinen | 545f1da | 2009-10-08 21:56:23 +0300 | [diff] [blame] | 170 | { |
| 171 | struct spi_transfer t[1]; |
| 172 | struct spi_message m; |
| 173 | u32 *busy_buf; |
| 174 | int num_busy_bytes = 0; |
| 175 | |
Juuso Oikarinen | 545f1da | 2009-10-08 21:56:23 +0300 | [diff] [blame] | 176 | /* |
| 177 | * Read further busy words from SPI until a non-busy word is |
| 178 | * encountered, then read the data itself into the buffer. |
| 179 | */ |
Juuso Oikarinen | 545f1da | 2009-10-08 21:56:23 +0300 | [diff] [blame] | 180 | |
| 181 | num_busy_bytes = WL1271_BUSY_WORD_TIMEOUT; |
| 182 | busy_buf = wl->buffer_busyword; |
| 183 | while (num_busy_bytes) { |
| 184 | num_busy_bytes--; |
| 185 | spi_message_init(&m); |
| 186 | memset(t, 0, sizeof(t)); |
| 187 | t[0].rx_buf = busy_buf; |
| 188 | t[0].len = sizeof(u32); |
Juuso Oikarinen | 259da43 | 2010-03-26 12:53:18 +0200 | [diff] [blame] | 189 | t[0].cs_change = true; |
Juuso Oikarinen | 545f1da | 2009-10-08 21:56:23 +0300 | [diff] [blame] | 190 | spi_message_add_tail(&t[0], &m); |
Teemu Paasikivi | 8197b71 | 2010-02-22 08:38:23 +0200 | [diff] [blame] | 191 | spi_sync(wl_to_spi(wl), &m); |
Juuso Oikarinen | 545f1da | 2009-10-08 21:56:23 +0300 | [diff] [blame] | 192 | |
Juuso Oikarinen | 259da43 | 2010-03-26 12:53:18 +0200 | [diff] [blame] | 193 | if (*busy_buf & 0x1) |
| 194 | return 0; |
Juuso Oikarinen | 545f1da | 2009-10-08 21:56:23 +0300 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | /* The SPI bus is unresponsive, the read failed. */ |
Juuso Oikarinen | 545f1da | 2009-10-08 21:56:23 +0300 | [diff] [blame] | 198 | wl1271_error("SPI read busy-word timeout!\n"); |
Juuso Oikarinen | 259da43 | 2010-03-26 12:53:18 +0200 | [diff] [blame] | 199 | return -ETIMEDOUT; |
Juuso Oikarinen | 545f1da | 2009-10-08 21:56:23 +0300 | [diff] [blame] | 200 | } |
| 201 | |
Teemu Paasikivi | 760d969 | 2010-02-22 08:38:25 +0200 | [diff] [blame] | 202 | static void wl1271_spi_raw_read(struct wl1271 *wl, int addr, void *buf, |
Juuso Oikarinen | 259da43 | 2010-03-26 12:53:18 +0200 | [diff] [blame] | 203 | size_t len, bool fixed) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 204 | { |
| 205 | struct spi_transfer t[3]; |
| 206 | struct spi_message m; |
Juuso Oikarinen | 545f1da | 2009-10-08 21:56:23 +0300 | [diff] [blame] | 207 | u32 *busy_buf; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 208 | u32 *cmd; |
| 209 | |
| 210 | cmd = &wl->buffer_cmd; |
| 211 | busy_buf = wl->buffer_busyword; |
| 212 | |
| 213 | *cmd = 0; |
| 214 | *cmd |= WSPI_CMD_READ; |
| 215 | *cmd |= (len << WSPI_CMD_BYTE_LENGTH_OFFSET) & WSPI_CMD_BYTE_LENGTH; |
| 216 | *cmd |= addr & WSPI_CMD_BYTE_ADDR; |
| 217 | |
| 218 | if (fixed) |
| 219 | *cmd |= WSPI_CMD_FIXED; |
| 220 | |
| 221 | spi_message_init(&m); |
| 222 | memset(t, 0, sizeof(t)); |
| 223 | |
| 224 | t[0].tx_buf = cmd; |
| 225 | t[0].len = 4; |
Juuso Oikarinen | 259da43 | 2010-03-26 12:53:18 +0200 | [diff] [blame] | 226 | t[0].cs_change = true; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 227 | spi_message_add_tail(&t[0], &m); |
| 228 | |
| 229 | /* Busy and non busy words read */ |
| 230 | t[1].rx_buf = busy_buf; |
| 231 | t[1].len = WL1271_BUSY_WORD_LEN; |
Juuso Oikarinen | 259da43 | 2010-03-26 12:53:18 +0200 | [diff] [blame] | 232 | t[1].cs_change = true; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 233 | spi_message_add_tail(&t[1], &m); |
| 234 | |
Teemu Paasikivi | 8197b71 | 2010-02-22 08:38:23 +0200 | [diff] [blame] | 235 | spi_sync(wl_to_spi(wl), &m); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 236 | |
Juuso Oikarinen | 259da43 | 2010-03-26 12:53:18 +0200 | [diff] [blame] | 237 | if (!(busy_buf[WL1271_BUSY_WORD_CNT - 1] & 0x1) && |
| 238 | wl1271_spi_read_busy(wl)) { |
| 239 | memset(buf, 0, len); |
| 240 | return; |
| 241 | } |
| 242 | |
| 243 | spi_message_init(&m); |
| 244 | memset(t, 0, sizeof(t)); |
| 245 | |
| 246 | t[0].rx_buf = buf; |
| 247 | t[0].len = len; |
| 248 | t[0].cs_change = true; |
| 249 | spi_message_add_tail(&t[0], &m); |
| 250 | |
| 251 | spi_sync(wl_to_spi(wl), &m); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 252 | |
| 253 | wl1271_dump(DEBUG_SPI, "spi_read cmd -> ", cmd, sizeof(*cmd)); |
| 254 | wl1271_dump(DEBUG_SPI, "spi_read buf <- ", buf, len); |
| 255 | } |
| 256 | |
Teemu Paasikivi | 760d969 | 2010-02-22 08:38:25 +0200 | [diff] [blame] | 257 | static void wl1271_spi_raw_write(struct wl1271 *wl, int addr, void *buf, |
Juuso Oikarinen | 7462141 | 2009-10-12 15:08:54 +0300 | [diff] [blame] | 258 | size_t len, bool fixed) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 259 | { |
| 260 | struct spi_transfer t[2]; |
| 261 | struct spi_message m; |
| 262 | u32 *cmd; |
| 263 | |
| 264 | cmd = &wl->buffer_cmd; |
| 265 | |
| 266 | *cmd = 0; |
| 267 | *cmd |= WSPI_CMD_WRITE; |
| 268 | *cmd |= (len << WSPI_CMD_BYTE_LENGTH_OFFSET) & WSPI_CMD_BYTE_LENGTH; |
| 269 | *cmd |= addr & WSPI_CMD_BYTE_ADDR; |
| 270 | |
| 271 | if (fixed) |
| 272 | *cmd |= WSPI_CMD_FIXED; |
| 273 | |
| 274 | spi_message_init(&m); |
| 275 | memset(t, 0, sizeof(t)); |
| 276 | |
| 277 | t[0].tx_buf = cmd; |
| 278 | t[0].len = sizeof(*cmd); |
| 279 | spi_message_add_tail(&t[0], &m); |
| 280 | |
| 281 | t[1].tx_buf = buf; |
| 282 | t[1].len = len; |
| 283 | spi_message_add_tail(&t[1], &m); |
| 284 | |
Teemu Paasikivi | 8197b71 | 2010-02-22 08:38:23 +0200 | [diff] [blame] | 285 | spi_sync(wl_to_spi(wl), &m); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 286 | |
| 287 | wl1271_dump(DEBUG_SPI, "spi_write cmd -> ", cmd, sizeof(*cmd)); |
| 288 | wl1271_dump(DEBUG_SPI, "spi_write buf -> ", buf, len); |
| 289 | } |
Teemu Paasikivi | 2d5e82b | 2010-02-22 08:38:21 +0200 | [diff] [blame] | 290 | |
| 291 | static irqreturn_t wl1271_irq(int irq, void *cookie) |
| 292 | { |
| 293 | struct wl1271 *wl; |
| 294 | unsigned long flags; |
| 295 | |
| 296 | wl1271_debug(DEBUG_IRQ, "IRQ"); |
| 297 | |
| 298 | wl = cookie; |
| 299 | |
| 300 | /* complete the ELP completion */ |
| 301 | spin_lock_irqsave(&wl->wl_lock, flags); |
| 302 | if (wl->elp_compl) { |
| 303 | complete(wl->elp_compl); |
| 304 | wl->elp_compl = NULL; |
| 305 | } |
| 306 | |
Juuso Oikarinen | 1e73eb6 | 2010-02-22 08:38:37 +0200 | [diff] [blame] | 307 | if (!test_and_set_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags)) |
| 308 | ieee80211_queue_work(wl->hw, &wl->irq_work); |
| 309 | set_bit(WL1271_FLAG_IRQ_PENDING, &wl->flags); |
Teemu Paasikivi | 2d5e82b | 2010-02-22 08:38:21 +0200 | [diff] [blame] | 310 | spin_unlock_irqrestore(&wl->wl_lock, flags); |
| 311 | |
| 312 | return IRQ_HANDLED; |
| 313 | } |
| 314 | |
Teemu Paasikivi | becd551 | 2010-03-18 12:26:27 +0200 | [diff] [blame] | 315 | static void wl1271_spi_set_power(struct wl1271 *wl, bool enable) |
| 316 | { |
| 317 | if (wl->set_power) |
| 318 | wl->set_power(enable); |
| 319 | } |
| 320 | |
Teemu Paasikivi | 8197b71 | 2010-02-22 08:38:23 +0200 | [diff] [blame] | 321 | static struct wl1271_if_operations spi_ops = { |
| 322 | .read = wl1271_spi_raw_read, |
| 323 | .write = wl1271_spi_raw_write, |
| 324 | .reset = wl1271_spi_reset, |
| 325 | .init = wl1271_spi_init, |
Teemu Paasikivi | becd551 | 2010-03-18 12:26:27 +0200 | [diff] [blame] | 326 | .power = wl1271_spi_set_power, |
Teemu Paasikivi | 8197b71 | 2010-02-22 08:38:23 +0200 | [diff] [blame] | 327 | .dev = wl1271_spi_wl_to_dev, |
| 328 | .enable_irq = wl1271_spi_enable_interrupts, |
| 329 | .disable_irq = wl1271_spi_disable_interrupts |
| 330 | }; |
| 331 | |
Teemu Paasikivi | 2d5e82b | 2010-02-22 08:38:21 +0200 | [diff] [blame] | 332 | static int __devinit wl1271_probe(struct spi_device *spi) |
| 333 | { |
| 334 | struct wl12xx_platform_data *pdata; |
| 335 | struct ieee80211_hw *hw; |
| 336 | struct wl1271 *wl; |
| 337 | int ret; |
| 338 | |
| 339 | pdata = spi->dev.platform_data; |
| 340 | if (!pdata) { |
| 341 | wl1271_error("no platform data"); |
| 342 | return -ENODEV; |
| 343 | } |
| 344 | |
| 345 | hw = wl1271_alloc_hw(); |
| 346 | if (IS_ERR(hw)) |
| 347 | return PTR_ERR(hw); |
| 348 | |
| 349 | wl = hw->priv; |
| 350 | |
| 351 | dev_set_drvdata(&spi->dev, wl); |
Teemu Paasikivi | 8197b71 | 2010-02-22 08:38:23 +0200 | [diff] [blame] | 352 | wl->if_priv = spi; |
| 353 | |
| 354 | wl->if_ops = &spi_ops; |
Teemu Paasikivi | 2d5e82b | 2010-02-22 08:38:21 +0200 | [diff] [blame] | 355 | |
| 356 | /* This is the only SPI value that we need to set here, the rest |
| 357 | * comes from the board-peripherals file */ |
| 358 | spi->bits_per_word = 32; |
| 359 | |
| 360 | ret = spi_setup(spi); |
| 361 | if (ret < 0) { |
| 362 | wl1271_error("spi_setup failed"); |
| 363 | goto out_free; |
| 364 | } |
| 365 | |
| 366 | wl->set_power = pdata->set_power; |
| 367 | if (!wl->set_power) { |
| 368 | wl1271_error("set power function missing in platform data"); |
| 369 | ret = -ENODEV; |
| 370 | goto out_free; |
| 371 | } |
| 372 | |
| 373 | wl->irq = spi->irq; |
| 374 | if (wl->irq < 0) { |
| 375 | wl1271_error("irq missing in platform data"); |
| 376 | ret = -ENODEV; |
| 377 | goto out_free; |
| 378 | } |
| 379 | |
| 380 | ret = request_irq(wl->irq, wl1271_irq, 0, DRIVER_NAME, wl); |
| 381 | if (ret < 0) { |
| 382 | wl1271_error("request_irq() failed: %d", ret); |
| 383 | goto out_free; |
| 384 | } |
| 385 | |
| 386 | set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING); |
| 387 | |
| 388 | disable_irq(wl->irq); |
| 389 | |
Teemu Paasikivi | 2d5e82b | 2010-02-22 08:38:21 +0200 | [diff] [blame] | 390 | ret = wl1271_init_ieee80211(wl); |
| 391 | if (ret) |
Juuso Oikarinen | a1dd818 | 2010-03-18 12:26:31 +0200 | [diff] [blame] | 392 | goto out_irq; |
Teemu Paasikivi | 2d5e82b | 2010-02-22 08:38:21 +0200 | [diff] [blame] | 393 | |
| 394 | ret = wl1271_register_hw(wl); |
| 395 | if (ret) |
Juuso Oikarinen | a1dd818 | 2010-03-18 12:26:31 +0200 | [diff] [blame] | 396 | goto out_irq; |
Teemu Paasikivi | 2d5e82b | 2010-02-22 08:38:21 +0200 | [diff] [blame] | 397 | |
| 398 | wl1271_notice("initialized"); |
| 399 | |
| 400 | return 0; |
| 401 | |
Teemu Paasikivi | 2d5e82b | 2010-02-22 08:38:21 +0200 | [diff] [blame] | 402 | out_irq: |
| 403 | free_irq(wl->irq, wl); |
| 404 | |
| 405 | out_free: |
Teemu Paasikivi | 3b56dd6 | 2010-03-18 12:26:46 +0200 | [diff] [blame] | 406 | wl1271_free_hw(wl); |
Teemu Paasikivi | 2d5e82b | 2010-02-22 08:38:21 +0200 | [diff] [blame] | 407 | |
| 408 | return ret; |
| 409 | } |
| 410 | |
| 411 | static int __devexit wl1271_remove(struct spi_device *spi) |
| 412 | { |
| 413 | struct wl1271 *wl = dev_get_drvdata(&spi->dev); |
| 414 | |
Teemu Paasikivi | 2d5e82b | 2010-02-22 08:38:21 +0200 | [diff] [blame] | 415 | free_irq(wl->irq, wl); |
| 416 | |
Teemu Paasikivi | 3b56dd6 | 2010-03-18 12:26:46 +0200 | [diff] [blame] | 417 | wl1271_unregister_hw(wl); |
Teemu Paasikivi | 2d5e82b | 2010-02-22 08:38:21 +0200 | [diff] [blame] | 418 | wl1271_free_hw(wl); |
| 419 | |
| 420 | return 0; |
| 421 | } |
| 422 | |
| 423 | |
| 424 | static struct spi_driver wl1271_spi_driver = { |
| 425 | .driver = { |
Luciano Coelho | 7fdd50d | 2010-03-26 12:53:10 +0200 | [diff] [blame] | 426 | .name = "wl1271_spi", |
Teemu Paasikivi | 2d5e82b | 2010-02-22 08:38:21 +0200 | [diff] [blame] | 427 | .bus = &spi_bus_type, |
| 428 | .owner = THIS_MODULE, |
| 429 | }, |
| 430 | |
| 431 | .probe = wl1271_probe, |
| 432 | .remove = __devexit_p(wl1271_remove), |
| 433 | }; |
| 434 | |
| 435 | static int __init wl1271_init(void) |
| 436 | { |
| 437 | int ret; |
| 438 | |
| 439 | ret = spi_register_driver(&wl1271_spi_driver); |
| 440 | if (ret < 0) { |
| 441 | wl1271_error("failed to register spi driver: %d", ret); |
| 442 | goto out; |
| 443 | } |
| 444 | |
| 445 | out: |
| 446 | return ret; |
| 447 | } |
| 448 | |
| 449 | static void __exit wl1271_exit(void) |
| 450 | { |
| 451 | spi_unregister_driver(&wl1271_spi_driver); |
| 452 | |
| 453 | wl1271_notice("unloaded"); |
| 454 | } |
| 455 | |
| 456 | module_init(wl1271_init); |
| 457 | module_exit(wl1271_exit); |
| 458 | |
| 459 | MODULE_LICENSE("GPL"); |
| 460 | MODULE_AUTHOR("Luciano Coelho <luciano.coelho@nokia.com>"); |
| 461 | MODULE_AUTHOR("Juuso Oikarinen <juuso.oikarinen@nokia.com>"); |
| 462 | MODULE_FIRMWARE(WL1271_FW_NAME); |