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