Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 1 | /* |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 2 | * This file is part of wl1251 |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2008 Nokia Corporation |
| 5 | * |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * version 2 as published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, but |
| 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
| 18 | * 02110-1301 USA |
| 19 | * |
| 20 | */ |
| 21 | |
Alexey Dobriyan | a6b7a40 | 2011-06-06 10:43:46 +0000 | [diff] [blame] | 22 | #include <linux/interrupt.h> |
Bob Copeland | 8e639c0 | 2009-08-07 13:33:26 +0300 | [diff] [blame] | 23 | #include <linux/irq.h> |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 24 | #include <linux/module.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 25 | #include <linux/slab.h> |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 26 | #include <linux/crc7.h> |
| 27 | #include <linux/spi/spi.h> |
Ohad Ben-Cohen | c1f9a09 | 2010-09-16 13:16:02 +0200 | [diff] [blame] | 28 | #include <linux/wl12xx.h> |
Sebastian Reichel | 1d207cd | 2014-02-15 00:05:53 +0100 | [diff] [blame] | 29 | #include <linux/gpio.h> |
Sebastian Reichel | e4c2e09 | 2014-02-15 00:05:54 +0100 | [diff] [blame^] | 30 | #include <linux/regulator/consumer.h> |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 31 | |
Kalle Valo | 1367411 | 2009-06-12 14:17:25 +0300 | [diff] [blame] | 32 | #include "wl1251.h" |
Kalle Valo | 9bc6772 | 2010-10-10 11:28:32 +0300 | [diff] [blame] | 33 | #include "reg.h" |
| 34 | #include "spi.h" |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 35 | |
Bob Copeland | b5ed9c1 | 2009-08-07 13:33:49 +0300 | [diff] [blame] | 36 | static irqreturn_t wl1251_irq(int irq, void *cookie) |
| 37 | { |
| 38 | struct wl1251 *wl; |
| 39 | |
| 40 | wl1251_debug(DEBUG_IRQ, "IRQ"); |
| 41 | |
| 42 | wl = cookie; |
| 43 | |
Kalle Valo | 16e711f | 2009-08-07 13:35:04 +0300 | [diff] [blame] | 44 | ieee80211_queue_work(wl->hw, &wl->irq_work); |
Bob Copeland | b5ed9c1 | 2009-08-07 13:33:49 +0300 | [diff] [blame] | 45 | |
| 46 | return IRQ_HANDLED; |
| 47 | } |
| 48 | |
Bob Copeland | af8c78e | 2009-08-07 13:33:34 +0300 | [diff] [blame] | 49 | static struct spi_device *wl_to_spi(struct wl1251 *wl) |
| 50 | { |
| 51 | return wl->if_priv; |
| 52 | } |
| 53 | |
Bob Copeland | 08d9f572 | 2009-08-07 13:33:11 +0300 | [diff] [blame] | 54 | static void wl1251_spi_reset(struct wl1251 *wl) |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 55 | { |
| 56 | u8 *cmd; |
| 57 | struct spi_transfer t; |
| 58 | struct spi_message m; |
| 59 | |
| 60 | cmd = kzalloc(WSPI_INIT_CMD_LEN, GFP_KERNEL); |
| 61 | if (!cmd) { |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 62 | wl1251_error("could not allocate cmd for spi reset"); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 63 | return; |
| 64 | } |
| 65 | |
| 66 | memset(&t, 0, sizeof(t)); |
| 67 | spi_message_init(&m); |
| 68 | |
| 69 | memset(cmd, 0xff, WSPI_INIT_CMD_LEN); |
| 70 | |
| 71 | t.tx_buf = cmd; |
| 72 | t.len = WSPI_INIT_CMD_LEN; |
| 73 | spi_message_add_tail(&t, &m); |
| 74 | |
Bob Copeland | af8c78e | 2009-08-07 13:33:34 +0300 | [diff] [blame] | 75 | spi_sync(wl_to_spi(wl), &m); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 76 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 77 | wl1251_dump(DEBUG_SPI, "spi reset -> ", cmd, WSPI_INIT_CMD_LEN); |
Grazvydas Ignotas | a859e4d | 2012-06-16 22:26:48 +0300 | [diff] [blame] | 78 | |
| 79 | kfree(cmd); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 80 | } |
| 81 | |
Bob Copeland | 8e639c0 | 2009-08-07 13:33:26 +0300 | [diff] [blame] | 82 | static void wl1251_spi_wake(struct wl1251 *wl) |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 83 | { |
| 84 | u8 crc[WSPI_INIT_CMD_CRC_LEN], *cmd; |
| 85 | struct spi_transfer t; |
| 86 | struct spi_message m; |
| 87 | |
| 88 | cmd = kzalloc(WSPI_INIT_CMD_LEN, GFP_KERNEL); |
| 89 | if (!cmd) { |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 90 | wl1251_error("could not allocate cmd for spi init"); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 91 | return; |
| 92 | } |
| 93 | |
| 94 | memset(crc, 0, sizeof(crc)); |
| 95 | memset(&t, 0, sizeof(t)); |
| 96 | spi_message_init(&m); |
| 97 | |
Sachin Kamat | 789e90e | 2013-05-29 15:48:23 +0530 | [diff] [blame] | 98 | /* Set WSPI_INIT_COMMAND |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 99 | * the data is being send from the MSB to LSB |
| 100 | */ |
| 101 | cmd[2] = 0xff; |
| 102 | cmd[3] = 0xff; |
| 103 | cmd[1] = WSPI_INIT_CMD_START | WSPI_INIT_CMD_TX; |
| 104 | cmd[0] = 0; |
| 105 | cmd[7] = 0; |
| 106 | cmd[6] |= HW_ACCESS_WSPI_INIT_CMD_MASK << 3; |
| 107 | cmd[6] |= HW_ACCESS_WSPI_FIXED_BUSY_LEN & WSPI_INIT_CMD_FIXEDBUSY_LEN; |
| 108 | |
| 109 | if (HW_ACCESS_WSPI_FIXED_BUSY_LEN == 0) |
| 110 | cmd[5] |= WSPI_INIT_CMD_DIS_FIXEDBUSY; |
| 111 | else |
| 112 | cmd[5] |= WSPI_INIT_CMD_EN_FIXEDBUSY; |
| 113 | |
| 114 | cmd[5] |= WSPI_INIT_CMD_IOD | WSPI_INIT_CMD_IP | WSPI_INIT_CMD_CS |
| 115 | | WSPI_INIT_CMD_WSPI | WSPI_INIT_CMD_WS; |
| 116 | |
| 117 | crc[0] = cmd[1]; |
| 118 | crc[1] = cmd[0]; |
| 119 | crc[2] = cmd[7]; |
| 120 | crc[3] = cmd[6]; |
| 121 | crc[4] = cmd[5]; |
| 122 | |
| 123 | cmd[4] |= crc7(0, crc, WSPI_INIT_CMD_CRC_LEN) << 1; |
| 124 | cmd[4] |= WSPI_INIT_CMD_END; |
| 125 | |
| 126 | t.tx_buf = cmd; |
| 127 | t.len = WSPI_INIT_CMD_LEN; |
| 128 | spi_message_add_tail(&t, &m); |
| 129 | |
Bob Copeland | af8c78e | 2009-08-07 13:33:34 +0300 | [diff] [blame] | 130 | spi_sync(wl_to_spi(wl), &m); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 131 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 132 | wl1251_dump(DEBUG_SPI, "spi init -> ", cmd, WSPI_INIT_CMD_LEN); |
Grazvydas Ignotas | a859e4d | 2012-06-16 22:26:48 +0300 | [diff] [blame] | 133 | |
| 134 | kfree(cmd); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 135 | } |
| 136 | |
Bob Copeland | 08d9f572 | 2009-08-07 13:33:11 +0300 | [diff] [blame] | 137 | static void wl1251_spi_reset_wake(struct wl1251 *wl) |
| 138 | { |
| 139 | wl1251_spi_reset(wl); |
Bob Copeland | 8e639c0 | 2009-08-07 13:33:26 +0300 | [diff] [blame] | 140 | wl1251_spi_wake(wl); |
Bob Copeland | 08d9f572 | 2009-08-07 13:33:11 +0300 | [diff] [blame] | 141 | } |
| 142 | |
Bob Copeland | 08d9f572 | 2009-08-07 13:33:11 +0300 | [diff] [blame] | 143 | static void wl1251_spi_read(struct wl1251 *wl, int addr, void *buf, |
| 144 | size_t len) |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 145 | { |
| 146 | struct spi_transfer t[3]; |
| 147 | struct spi_message m; |
Kalle Valo | 5262c12 | 2009-06-12 14:14:55 +0300 | [diff] [blame] | 148 | u8 *busy_buf; |
Kalle Valo | 56343a3 | 2009-06-12 14:14:47 +0300 | [diff] [blame] | 149 | u32 *cmd; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 150 | |
Kalle Valo | 56343a3 | 2009-06-12 14:14:47 +0300 | [diff] [blame] | 151 | cmd = &wl->buffer_cmd; |
Kalle Valo | 5262c12 | 2009-06-12 14:14:55 +0300 | [diff] [blame] | 152 | busy_buf = wl->buffer_busyword; |
Kalle Valo | 56343a3 | 2009-06-12 14:14:47 +0300 | [diff] [blame] | 153 | |
| 154 | *cmd = 0; |
| 155 | *cmd |= WSPI_CMD_READ; |
| 156 | *cmd |= (len << WSPI_CMD_BYTE_LENGTH_OFFSET) & WSPI_CMD_BYTE_LENGTH; |
| 157 | *cmd |= addr & WSPI_CMD_BYTE_ADDR; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 158 | |
| 159 | spi_message_init(&m); |
| 160 | memset(t, 0, sizeof(t)); |
| 161 | |
Kalle Valo | 56343a3 | 2009-06-12 14:14:47 +0300 | [diff] [blame] | 162 | t[0].tx_buf = cmd; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 163 | t[0].len = 4; |
| 164 | spi_message_add_tail(&t[0], &m); |
| 165 | |
| 166 | /* Busy and non busy words read */ |
| 167 | t[1].rx_buf = busy_buf; |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 168 | t[1].len = WL1251_BUSY_WORD_LEN; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 169 | spi_message_add_tail(&t[1], &m); |
| 170 | |
| 171 | t[2].rx_buf = buf; |
| 172 | t[2].len = len; |
| 173 | spi_message_add_tail(&t[2], &m); |
| 174 | |
Bob Copeland | af8c78e | 2009-08-07 13:33:34 +0300 | [diff] [blame] | 175 | spi_sync(wl_to_spi(wl), &m); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 176 | |
| 177 | /* FIXME: check busy words */ |
| 178 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 179 | wl1251_dump(DEBUG_SPI, "spi_read cmd -> ", cmd, sizeof(*cmd)); |
| 180 | wl1251_dump(DEBUG_SPI, "spi_read buf <- ", buf, len); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 181 | } |
| 182 | |
Bob Copeland | 08d9f572 | 2009-08-07 13:33:11 +0300 | [diff] [blame] | 183 | static void wl1251_spi_write(struct wl1251 *wl, int addr, void *buf, |
| 184 | size_t len) |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 185 | { |
| 186 | struct spi_transfer t[2]; |
| 187 | struct spi_message m; |
Kalle Valo | 56343a3 | 2009-06-12 14:14:47 +0300 | [diff] [blame] | 188 | u32 *cmd; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 189 | |
Kalle Valo | 56343a3 | 2009-06-12 14:14:47 +0300 | [diff] [blame] | 190 | cmd = &wl->buffer_cmd; |
| 191 | |
| 192 | *cmd = 0; |
| 193 | *cmd |= WSPI_CMD_WRITE; |
| 194 | *cmd |= (len << WSPI_CMD_BYTE_LENGTH_OFFSET) & WSPI_CMD_BYTE_LENGTH; |
| 195 | *cmd |= addr & WSPI_CMD_BYTE_ADDR; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 196 | |
| 197 | spi_message_init(&m); |
| 198 | memset(t, 0, sizeof(t)); |
| 199 | |
Kalle Valo | 56343a3 | 2009-06-12 14:14:47 +0300 | [diff] [blame] | 200 | t[0].tx_buf = cmd; |
| 201 | t[0].len = sizeof(*cmd); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 202 | spi_message_add_tail(&t[0], &m); |
| 203 | |
| 204 | t[1].tx_buf = buf; |
| 205 | t[1].len = len; |
| 206 | spi_message_add_tail(&t[1], &m); |
| 207 | |
Bob Copeland | af8c78e | 2009-08-07 13:33:34 +0300 | [diff] [blame] | 208 | spi_sync(wl_to_spi(wl), &m); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 209 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 210 | wl1251_dump(DEBUG_SPI, "spi_write cmd -> ", cmd, sizeof(*cmd)); |
| 211 | wl1251_dump(DEBUG_SPI, "spi_write buf -> ", buf, len); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 212 | } |
Bob Copeland | 08d9f572 | 2009-08-07 13:33:11 +0300 | [diff] [blame] | 213 | |
Bob Copeland | b5ed9c1 | 2009-08-07 13:33:49 +0300 | [diff] [blame] | 214 | static void wl1251_spi_enable_irq(struct wl1251 *wl) |
| 215 | { |
| 216 | return enable_irq(wl->irq); |
| 217 | } |
| 218 | |
| 219 | static void wl1251_spi_disable_irq(struct wl1251 *wl) |
| 220 | { |
| 221 | return disable_irq(wl->irq); |
| 222 | } |
| 223 | |
Grazvydas Ignotas | cb7bbc7 | 2010-11-04 00:13:47 +0200 | [diff] [blame] | 224 | static int wl1251_spi_set_power(struct wl1251 *wl, bool enable) |
| 225 | { |
Sebastian Reichel | 1d207cd | 2014-02-15 00:05:53 +0100 | [diff] [blame] | 226 | if (gpio_is_valid(wl->power_gpio)) |
| 227 | gpio_set_value(wl->power_gpio, enable); |
Grazvydas Ignotas | cb7bbc7 | 2010-11-04 00:13:47 +0200 | [diff] [blame] | 228 | |
| 229 | return 0; |
| 230 | } |
| 231 | |
Bob Copeland | af8c78e | 2009-08-07 13:33:34 +0300 | [diff] [blame] | 232 | static const struct wl1251_if_operations wl1251_spi_ops = { |
Bob Copeland | 08d9f572 | 2009-08-07 13:33:11 +0300 | [diff] [blame] | 233 | .read = wl1251_spi_read, |
| 234 | .write = wl1251_spi_write, |
| 235 | .reset = wl1251_spi_reset_wake, |
Bob Copeland | b5ed9c1 | 2009-08-07 13:33:49 +0300 | [diff] [blame] | 236 | .enable_irq = wl1251_spi_enable_irq, |
| 237 | .disable_irq = wl1251_spi_disable_irq, |
Grazvydas Ignotas | cb7bbc7 | 2010-11-04 00:13:47 +0200 | [diff] [blame] | 238 | .power = wl1251_spi_set_power, |
Bob Copeland | 08d9f572 | 2009-08-07 13:33:11 +0300 | [diff] [blame] | 239 | }; |
Bob Copeland | 8e639c0 | 2009-08-07 13:33:26 +0300 | [diff] [blame] | 240 | |
Bill Pemberton | b74324d | 2012-12-03 09:56:42 -0500 | [diff] [blame] | 241 | static int wl1251_spi_probe(struct spi_device *spi) |
Bob Copeland | 8e639c0 | 2009-08-07 13:33:26 +0300 | [diff] [blame] | 242 | { |
Luciano Coelho | 946651c | 2014-02-15 00:05:52 +0100 | [diff] [blame] | 243 | struct wl1251_platform_data *pdata; |
Bob Copeland | 8e639c0 | 2009-08-07 13:33:26 +0300 | [diff] [blame] | 244 | struct ieee80211_hw *hw; |
| 245 | struct wl1251 *wl; |
| 246 | int ret; |
| 247 | |
Jingoo Han | 5f4fe16 | 2013-09-10 17:57:05 +0900 | [diff] [blame] | 248 | pdata = dev_get_platdata(&spi->dev); |
Bob Copeland | 8e639c0 | 2009-08-07 13:33:26 +0300 | [diff] [blame] | 249 | if (!pdata) { |
| 250 | wl1251_error("no platform data"); |
| 251 | return -ENODEV; |
| 252 | } |
| 253 | |
| 254 | hw = wl1251_alloc_hw(); |
| 255 | if (IS_ERR(hw)) |
| 256 | return PTR_ERR(hw); |
| 257 | |
| 258 | wl = hw->priv; |
| 259 | |
| 260 | SET_IEEE80211_DEV(hw, &spi->dev); |
Jingoo Han | c49b05a | 2013-04-05 20:36:25 +0000 | [diff] [blame] | 261 | spi_set_drvdata(spi, wl); |
Bob Copeland | af8c78e | 2009-08-07 13:33:34 +0300 | [diff] [blame] | 262 | wl->if_priv = spi; |
Bob Copeland | 8e639c0 | 2009-08-07 13:33:26 +0300 | [diff] [blame] | 263 | wl->if_ops = &wl1251_spi_ops; |
| 264 | |
| 265 | /* This is the only SPI value that we need to set here, the rest |
Sachin Kamat | 789e90e | 2013-05-29 15:48:23 +0530 | [diff] [blame] | 266 | * comes from the board-peripherals file |
| 267 | */ |
Bob Copeland | 8e639c0 | 2009-08-07 13:33:26 +0300 | [diff] [blame] | 268 | spi->bits_per_word = 32; |
| 269 | |
| 270 | ret = spi_setup(spi); |
| 271 | if (ret < 0) { |
| 272 | wl1251_error("spi_setup failed"); |
| 273 | goto out_free; |
| 274 | } |
| 275 | |
Sebastian Reichel | 1d207cd | 2014-02-15 00:05:53 +0100 | [diff] [blame] | 276 | wl->power_gpio = pdata->power_gpio; |
| 277 | |
| 278 | if (gpio_is_valid(wl->power_gpio)) { |
| 279 | ret = devm_gpio_request_one(&spi->dev, wl->power_gpio, |
| 280 | GPIOF_OUT_INIT_LOW, "wl1251 power"); |
| 281 | if (ret) { |
| 282 | wl1251_error("Failed to request gpio: %d\n", ret); |
| 283 | goto out_free; |
| 284 | } |
| 285 | } else { |
| 286 | wl1251_error("set power gpio missing in platform data"); |
| 287 | ret = -ENODEV; |
| 288 | goto out_free; |
Bob Copeland | 8e639c0 | 2009-08-07 13:33:26 +0300 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | wl->irq = spi->irq; |
| 292 | if (wl->irq < 0) { |
| 293 | wl1251_error("irq missing in platform data"); |
Sebastian Reichel | 1d207cd | 2014-02-15 00:05:53 +0100 | [diff] [blame] | 294 | ret = -ENODEV; |
| 295 | goto out_free; |
Bob Copeland | 8e639c0 | 2009-08-07 13:33:26 +0300 | [diff] [blame] | 296 | } |
| 297 | |
David-John Willis | c95cf3d0 | 2009-11-17 18:50:09 +0200 | [diff] [blame] | 298 | wl->use_eeprom = pdata->use_eeprom; |
| 299 | |
Grazvydas Ignotas | f380f2c | 2012-05-18 03:04:08 +0300 | [diff] [blame] | 300 | irq_set_status_flags(wl->irq, IRQ_NOAUTOEN); |
Sebastian Reichel | 1d207cd | 2014-02-15 00:05:53 +0100 | [diff] [blame] | 301 | ret = devm_request_irq(&spi->dev, wl->irq, wl1251_irq, 0, |
| 302 | DRIVER_NAME, wl); |
Bob Copeland | 8e639c0 | 2009-08-07 13:33:26 +0300 | [diff] [blame] | 303 | if (ret < 0) { |
| 304 | wl1251_error("request_irq() failed: %d", ret); |
| 305 | goto out_free; |
| 306 | } |
| 307 | |
Thomas Gleixner | dced35a | 2011-03-28 17:49:12 +0200 | [diff] [blame] | 308 | irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING); |
Bob Copeland | 8e639c0 | 2009-08-07 13:33:26 +0300 | [diff] [blame] | 309 | |
Sebastian Reichel | e4c2e09 | 2014-02-15 00:05:54 +0100 | [diff] [blame^] | 310 | wl->vio = devm_regulator_get(&spi->dev, "vio"); |
| 311 | if (IS_ERR(wl->vio)) { |
| 312 | ret = PTR_ERR(wl->vio); |
| 313 | wl1251_error("vio regulator missing: %d", ret); |
| 314 | goto out_free; |
| 315 | } |
| 316 | |
| 317 | ret = regulator_enable(wl->vio); |
Bob Copeland | 8e639c0 | 2009-08-07 13:33:26 +0300 | [diff] [blame] | 318 | if (ret) |
Sebastian Reichel | 1d207cd | 2014-02-15 00:05:53 +0100 | [diff] [blame] | 319 | goto out_free; |
Bob Copeland | 8e639c0 | 2009-08-07 13:33:26 +0300 | [diff] [blame] | 320 | |
Sebastian Reichel | e4c2e09 | 2014-02-15 00:05:54 +0100 | [diff] [blame^] | 321 | ret = wl1251_init_ieee80211(wl); |
| 322 | if (ret) |
| 323 | goto disable_regulator; |
| 324 | |
Bob Copeland | 8e639c0 | 2009-08-07 13:33:26 +0300 | [diff] [blame] | 325 | return 0; |
| 326 | |
Sebastian Reichel | e4c2e09 | 2014-02-15 00:05:54 +0100 | [diff] [blame^] | 327 | disable_regulator: |
| 328 | regulator_disable(wl->vio); |
| 329 | out_free: |
Bob Copeland | 8e639c0 | 2009-08-07 13:33:26 +0300 | [diff] [blame] | 330 | ieee80211_free_hw(hw); |
| 331 | |
| 332 | return ret; |
| 333 | } |
| 334 | |
Bill Pemberton | b74324d | 2012-12-03 09:56:42 -0500 | [diff] [blame] | 335 | static int wl1251_spi_remove(struct spi_device *spi) |
Bob Copeland | 8e639c0 | 2009-08-07 13:33:26 +0300 | [diff] [blame] | 336 | { |
Jingoo Han | c49b05a | 2013-04-05 20:36:25 +0000 | [diff] [blame] | 337 | struct wl1251 *wl = spi_get_drvdata(spi); |
Bob Copeland | 8e639c0 | 2009-08-07 13:33:26 +0300 | [diff] [blame] | 338 | |
Bob Copeland | b5ed9c1 | 2009-08-07 13:33:49 +0300 | [diff] [blame] | 339 | free_irq(wl->irq, wl); |
Bob Copeland | 8e639c0 | 2009-08-07 13:33:26 +0300 | [diff] [blame] | 340 | wl1251_free_hw(wl); |
Sebastian Reichel | e4c2e09 | 2014-02-15 00:05:54 +0100 | [diff] [blame^] | 341 | regulator_disable(wl->vio); |
Bob Copeland | 8e639c0 | 2009-08-07 13:33:26 +0300 | [diff] [blame] | 342 | |
| 343 | return 0; |
| 344 | } |
| 345 | |
| 346 | static struct spi_driver wl1251_spi_driver = { |
| 347 | .driver = { |
Kalle Valo | 7590a55 | 2010-04-02 15:31:46 +0300 | [diff] [blame] | 348 | .name = DRIVER_NAME, |
Bob Copeland | 8e639c0 | 2009-08-07 13:33:26 +0300 | [diff] [blame] | 349 | .owner = THIS_MODULE, |
| 350 | }, |
| 351 | |
| 352 | .probe = wl1251_spi_probe, |
Bill Pemberton | b74324d | 2012-12-03 09:56:42 -0500 | [diff] [blame] | 353 | .remove = wl1251_spi_remove, |
Bob Copeland | 8e639c0 | 2009-08-07 13:33:26 +0300 | [diff] [blame] | 354 | }; |
| 355 | |
Sachin Kamat | 19a4e68 | 2013-05-29 15:48:22 +0530 | [diff] [blame] | 356 | module_spi_driver(wl1251_spi_driver); |
Bob Copeland | 8e639c0 | 2009-08-07 13:33:26 +0300 | [diff] [blame] | 357 | |
| 358 | MODULE_LICENSE("GPL"); |
Kalle Valo | 31c726f | 2010-08-22 22:46:15 +0300 | [diff] [blame] | 359 | MODULE_AUTHOR("Kalle Valo <kvalo@adurom.com>"); |
Ameya Palande | f148cfd | 2010-07-05 17:12:38 +0300 | [diff] [blame] | 360 | MODULE_ALIAS("spi:wl1251"); |