Luciano Coelho | b2ba99f | 2011-11-20 23:32:10 +0200 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of wl1271 |
| 3 | * |
| 4 | * Copyright (C) 2008-2010 Nokia Corporation |
| 5 | * |
| 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 | |
| 22 | #include <linux/module.h> |
| 23 | #include <linux/platform_device.h> |
| 24 | |
Luciano Coelho | ffeb501 | 2011-11-21 18:55:51 +0200 | [diff] [blame] | 25 | #include <linux/err.h> |
| 26 | |
Luciano Coelho | dd5512eb | 2012-04-11 11:03:14 +0300 | [diff] [blame] | 27 | #include <linux/wl12xx.h> |
| 28 | |
Luciano Coelho | b2ba99f | 2011-11-20 23:32:10 +0200 | [diff] [blame] | 29 | #include "../wlcore/wlcore.h" |
Luciano Coelho | ffeb501 | 2011-11-21 18:55:51 +0200 | [diff] [blame] | 30 | #include "../wlcore/debug.h" |
Luciano Coelho | 4ded91c | 2012-04-11 10:54:52 +0300 | [diff] [blame] | 31 | #include "../wlcore/io.h" |
Luciano Coelho | dd5512eb | 2012-04-11 11:03:14 +0300 | [diff] [blame] | 32 | #include "../wlcore/acx.h" |
Arik Nemtsov | b3b4b4b | 2011-12-12 11:41:44 +0200 | [diff] [blame] | 33 | #include "../wlcore/tx.h" |
Arik Nemtsov | cd70f6a | 2011-12-12 12:11:43 +0200 | [diff] [blame] | 34 | #include "../wlcore/rx.h" |
Luciano Coelho | b14684a | 2011-12-12 12:15:08 +0200 | [diff] [blame] | 35 | #include "../wlcore/io.h" |
Luciano Coelho | dd5512eb | 2012-04-11 11:03:14 +0300 | [diff] [blame] | 36 | #include "../wlcore/boot.h" |
Luciano Coelho | ffeb501 | 2011-11-21 18:55:51 +0200 | [diff] [blame] | 37 | |
Luciano Coelho | 0078213 | 2011-11-29 13:38:37 +0200 | [diff] [blame] | 38 | #include "reg.h" |
Luciano Coelho | 25a43d7 | 2011-11-21 20:37:14 +0200 | [diff] [blame] | 39 | |
Arik Nemtsov | 3edab30 | 2011-12-07 23:38:47 +0200 | [diff] [blame] | 40 | #define WL12XX_TX_HW_BLOCK_SPARE_DEFAULT 1 |
| 41 | #define WL12XX_TX_HW_BLOCK_GEM_SPARE 2 |
Arik Nemtsov | b3b4b4b | 2011-12-12 11:41:44 +0200 | [diff] [blame] | 42 | #define WL12XX_TX_HW_BLOCK_SIZE 252 |
Arik Nemtsov | 3edab30 | 2011-12-07 23:38:47 +0200 | [diff] [blame] | 43 | |
Arik Nemtsov | 43a8bc5 | 2011-12-08 00:43:48 +0200 | [diff] [blame] | 44 | static const u8 wl12xx_rate_to_idx_2ghz[] = { |
| 45 | /* MCS rates are used only with 11n */ |
| 46 | 7, /* WL12XX_CONF_HW_RXTX_RATE_MCS7_SGI */ |
| 47 | 7, /* WL12XX_CONF_HW_RXTX_RATE_MCS7 */ |
| 48 | 6, /* WL12XX_CONF_HW_RXTX_RATE_MCS6 */ |
| 49 | 5, /* WL12XX_CONF_HW_RXTX_RATE_MCS5 */ |
| 50 | 4, /* WL12XX_CONF_HW_RXTX_RATE_MCS4 */ |
| 51 | 3, /* WL12XX_CONF_HW_RXTX_RATE_MCS3 */ |
| 52 | 2, /* WL12XX_CONF_HW_RXTX_RATE_MCS2 */ |
| 53 | 1, /* WL12XX_CONF_HW_RXTX_RATE_MCS1 */ |
| 54 | 0, /* WL12XX_CONF_HW_RXTX_RATE_MCS0 */ |
| 55 | |
| 56 | 11, /* WL12XX_CONF_HW_RXTX_RATE_54 */ |
| 57 | 10, /* WL12XX_CONF_HW_RXTX_RATE_48 */ |
| 58 | 9, /* WL12XX_CONF_HW_RXTX_RATE_36 */ |
| 59 | 8, /* WL12XX_CONF_HW_RXTX_RATE_24 */ |
| 60 | |
| 61 | /* TI-specific rate */ |
| 62 | CONF_HW_RXTX_RATE_UNSUPPORTED, /* WL12XX_CONF_HW_RXTX_RATE_22 */ |
| 63 | |
| 64 | 7, /* WL12XX_CONF_HW_RXTX_RATE_18 */ |
| 65 | 6, /* WL12XX_CONF_HW_RXTX_RATE_12 */ |
| 66 | 3, /* WL12XX_CONF_HW_RXTX_RATE_11 */ |
| 67 | 5, /* WL12XX_CONF_HW_RXTX_RATE_9 */ |
| 68 | 4, /* WL12XX_CONF_HW_RXTX_RATE_6 */ |
| 69 | 2, /* WL12XX_CONF_HW_RXTX_RATE_5_5 */ |
| 70 | 1, /* WL12XX_CONF_HW_RXTX_RATE_2 */ |
| 71 | 0 /* WL12XX_CONF_HW_RXTX_RATE_1 */ |
| 72 | }; |
| 73 | |
| 74 | static const u8 wl12xx_rate_to_idx_5ghz[] = { |
| 75 | /* MCS rates are used only with 11n */ |
| 76 | 7, /* WL12XX_CONF_HW_RXTX_RATE_MCS7_SGI */ |
| 77 | 7, /* WL12XX_CONF_HW_RXTX_RATE_MCS7 */ |
| 78 | 6, /* WL12XX_CONF_HW_RXTX_RATE_MCS6 */ |
| 79 | 5, /* WL12XX_CONF_HW_RXTX_RATE_MCS5 */ |
| 80 | 4, /* WL12XX_CONF_HW_RXTX_RATE_MCS4 */ |
| 81 | 3, /* WL12XX_CONF_HW_RXTX_RATE_MCS3 */ |
| 82 | 2, /* WL12XX_CONF_HW_RXTX_RATE_MCS2 */ |
| 83 | 1, /* WL12XX_CONF_HW_RXTX_RATE_MCS1 */ |
| 84 | 0, /* WL12XX_CONF_HW_RXTX_RATE_MCS0 */ |
| 85 | |
| 86 | 7, /* WL12XX_CONF_HW_RXTX_RATE_54 */ |
| 87 | 6, /* WL12XX_CONF_HW_RXTX_RATE_48 */ |
| 88 | 5, /* WL12XX_CONF_HW_RXTX_RATE_36 */ |
| 89 | 4, /* WL12XX_CONF_HW_RXTX_RATE_24 */ |
| 90 | |
| 91 | /* TI-specific rate */ |
| 92 | CONF_HW_RXTX_RATE_UNSUPPORTED, /* WL12XX_CONF_HW_RXTX_RATE_22 */ |
| 93 | |
| 94 | 3, /* WL12XX_CONF_HW_RXTX_RATE_18 */ |
| 95 | 2, /* WL12XX_CONF_HW_RXTX_RATE_12 */ |
| 96 | CONF_HW_RXTX_RATE_UNSUPPORTED, /* WL12XX_CONF_HW_RXTX_RATE_11 */ |
| 97 | 1, /* WL12XX_CONF_HW_RXTX_RATE_9 */ |
| 98 | 0, /* WL12XX_CONF_HW_RXTX_RATE_6 */ |
| 99 | CONF_HW_RXTX_RATE_UNSUPPORTED, /* WL12XX_CONF_HW_RXTX_RATE_5_5 */ |
| 100 | CONF_HW_RXTX_RATE_UNSUPPORTED, /* WL12XX_CONF_HW_RXTX_RATE_2 */ |
| 101 | CONF_HW_RXTX_RATE_UNSUPPORTED /* WL12XX_CONF_HW_RXTX_RATE_1 */ |
| 102 | }; |
| 103 | |
| 104 | static const u8 *wl12xx_band_rate_to_idx[] = { |
| 105 | [IEEE80211_BAND_2GHZ] = wl12xx_rate_to_idx_2ghz, |
| 106 | [IEEE80211_BAND_5GHZ] = wl12xx_rate_to_idx_5ghz |
| 107 | }; |
| 108 | |
| 109 | enum wl12xx_hw_rates { |
| 110 | WL12XX_CONF_HW_RXTX_RATE_MCS7_SGI = 0, |
| 111 | WL12XX_CONF_HW_RXTX_RATE_MCS7, |
| 112 | WL12XX_CONF_HW_RXTX_RATE_MCS6, |
| 113 | WL12XX_CONF_HW_RXTX_RATE_MCS5, |
| 114 | WL12XX_CONF_HW_RXTX_RATE_MCS4, |
| 115 | WL12XX_CONF_HW_RXTX_RATE_MCS3, |
| 116 | WL12XX_CONF_HW_RXTX_RATE_MCS2, |
| 117 | WL12XX_CONF_HW_RXTX_RATE_MCS1, |
| 118 | WL12XX_CONF_HW_RXTX_RATE_MCS0, |
| 119 | WL12XX_CONF_HW_RXTX_RATE_54, |
| 120 | WL12XX_CONF_HW_RXTX_RATE_48, |
| 121 | WL12XX_CONF_HW_RXTX_RATE_36, |
| 122 | WL12XX_CONF_HW_RXTX_RATE_24, |
| 123 | WL12XX_CONF_HW_RXTX_RATE_22, |
| 124 | WL12XX_CONF_HW_RXTX_RATE_18, |
| 125 | WL12XX_CONF_HW_RXTX_RATE_12, |
| 126 | WL12XX_CONF_HW_RXTX_RATE_11, |
| 127 | WL12XX_CONF_HW_RXTX_RATE_9, |
| 128 | WL12XX_CONF_HW_RXTX_RATE_6, |
| 129 | WL12XX_CONF_HW_RXTX_RATE_5_5, |
| 130 | WL12XX_CONF_HW_RXTX_RATE_2, |
| 131 | WL12XX_CONF_HW_RXTX_RATE_1, |
| 132 | WL12XX_CONF_HW_RXTX_RATE_MAX, |
| 133 | }; |
Arik Nemtsov | 3edab30 | 2011-12-07 23:38:47 +0200 | [diff] [blame] | 134 | |
Luciano Coelho | 25a43d7 | 2011-11-21 20:37:14 +0200 | [diff] [blame] | 135 | static struct wlcore_partition_set wl12xx_ptable[PART_TABLE_LEN] = { |
| 136 | [PART_DOWN] = { |
| 137 | .mem = { |
| 138 | .start = 0x00000000, |
| 139 | .size = 0x000177c0 |
| 140 | }, |
| 141 | .reg = { |
| 142 | .start = REGISTERS_BASE, |
| 143 | .size = 0x00008800 |
| 144 | }, |
| 145 | .mem2 = { |
| 146 | .start = 0x00000000, |
| 147 | .size = 0x00000000 |
| 148 | }, |
| 149 | .mem3 = { |
| 150 | .start = 0x00000000, |
| 151 | .size = 0x00000000 |
| 152 | }, |
| 153 | }, |
| 154 | |
Luciano Coelho | 0078213 | 2011-11-29 13:38:37 +0200 | [diff] [blame] | 155 | [PART_BOOT] = { /* in wl12xx we can use a mix of work and down |
| 156 | * partition here */ |
| 157 | .mem = { |
| 158 | .start = 0x00040000, |
| 159 | .size = 0x00014fc0 |
| 160 | }, |
| 161 | .reg = { |
| 162 | .start = REGISTERS_BASE, |
| 163 | .size = 0x00008800 |
| 164 | }, |
| 165 | .mem2 = { |
| 166 | .start = 0x00000000, |
| 167 | .size = 0x00000000 |
| 168 | }, |
| 169 | .mem3 = { |
| 170 | .start = 0x00000000, |
| 171 | .size = 0x00000000 |
| 172 | }, |
| 173 | }, |
| 174 | |
Luciano Coelho | 25a43d7 | 2011-11-21 20:37:14 +0200 | [diff] [blame] | 175 | [PART_WORK] = { |
| 176 | .mem = { |
| 177 | .start = 0x00040000, |
| 178 | .size = 0x00014fc0 |
| 179 | }, |
| 180 | .reg = { |
| 181 | .start = REGISTERS_BASE, |
| 182 | .size = 0x0000a000 |
| 183 | }, |
| 184 | .mem2 = { |
| 185 | .start = 0x003004f8, |
| 186 | .size = 0x00000004 |
| 187 | }, |
| 188 | .mem3 = { |
| 189 | .start = 0x00040404, |
| 190 | .size = 0x00000000 |
| 191 | }, |
| 192 | }, |
| 193 | |
| 194 | [PART_DRPW] = { |
| 195 | .mem = { |
| 196 | .start = 0x00040000, |
| 197 | .size = 0x00014fc0 |
| 198 | }, |
| 199 | .reg = { |
| 200 | .start = DRPW_BASE, |
| 201 | .size = 0x00006000 |
| 202 | }, |
| 203 | .mem2 = { |
| 204 | .start = 0x00000000, |
| 205 | .size = 0x00000000 |
| 206 | }, |
| 207 | .mem3 = { |
| 208 | .start = 0x00000000, |
| 209 | .size = 0x00000000 |
| 210 | } |
| 211 | } |
| 212 | }; |
| 213 | |
Luciano Coelho | 0078213 | 2011-11-29 13:38:37 +0200 | [diff] [blame] | 214 | static const int wl12xx_rtable[REG_TABLE_LEN] = { |
| 215 | [REG_ECPU_CONTROL] = WL12XX_REG_ECPU_CONTROL, |
| 216 | [REG_INTERRUPT_NO_CLEAR] = WL12XX_REG_INTERRUPT_NO_CLEAR, |
| 217 | [REG_INTERRUPT_ACK] = WL12XX_REG_INTERRUPT_ACK, |
| 218 | [REG_COMMAND_MAILBOX_PTR] = WL12XX_REG_COMMAND_MAILBOX_PTR, |
| 219 | [REG_EVENT_MAILBOX_PTR] = WL12XX_REG_EVENT_MAILBOX_PTR, |
| 220 | [REG_INTERRUPT_TRIG] = WL12XX_REG_INTERRUPT_TRIG, |
| 221 | [REG_INTERRUPT_MASK] = WL12XX_REG_INTERRUPT_MASK, |
| 222 | [REG_PC_ON_RECOVERY] = WL12XX_SCR_PAD4, |
| 223 | [REG_CHIP_ID_B] = WL12XX_CHIP_ID_B, |
| 224 | [REG_CMD_MBOX_ADDRESS] = WL12XX_CMD_MBOX_ADDRESS, |
| 225 | |
| 226 | /* data access memory addresses, used with partition translation */ |
| 227 | [REG_SLV_MEM_DATA] = WL1271_SLV_MEM_DATA, |
| 228 | [REG_SLV_REG_DATA] = WL1271_SLV_REG_DATA, |
| 229 | |
| 230 | /* raw data access memory addresses */ |
| 231 | [REG_RAW_FW_STATUS_ADDR] = FW_STATUS_ADDR, |
| 232 | }; |
| 233 | |
Luciano Coelho | 6f7dd16 | 2011-11-29 16:27:31 +0200 | [diff] [blame] | 234 | /* TODO: maybe move to a new header file? */ |
| 235 | #define WL127X_FW_NAME_MULTI "ti-connectivity/wl127x-fw-4-mr.bin" |
| 236 | #define WL127X_FW_NAME_SINGLE "ti-connectivity/wl127x-fw-4-sr.bin" |
| 237 | #define WL127X_PLT_FW_NAME "ti-connectivity/wl127x-fw-4-plt.bin" |
| 238 | |
| 239 | #define WL128X_FW_NAME_MULTI "ti-connectivity/wl128x-fw-4-mr.bin" |
| 240 | #define WL128X_FW_NAME_SINGLE "ti-connectivity/wl128x-fw-4-sr.bin" |
| 241 | #define WL128X_PLT_FW_NAME "ti-connectivity/wl128x-fw-4-plt.bin" |
| 242 | |
Luciano Coelho | b14684a | 2011-12-12 12:15:08 +0200 | [diff] [blame] | 243 | static void wl127x_prepare_read(struct wl1271 *wl, u32 rx_desc, u32 len) |
| 244 | { |
| 245 | if (wl->chip.id != CHIP_ID_1283_PG20) { |
| 246 | struct wl1271_acx_mem_map *wl_mem_map = wl->target_mem_map; |
| 247 | struct wl1271_rx_mem_pool_addr rx_mem_addr; |
| 248 | |
| 249 | /* |
| 250 | * Choose the block we want to read |
| 251 | * For aggregated packets, only the first memory block |
| 252 | * should be retrieved. The FW takes care of the rest. |
| 253 | */ |
| 254 | u32 mem_block = rx_desc & RX_MEM_BLOCK_MASK; |
| 255 | |
| 256 | rx_mem_addr.addr = (mem_block << 8) + |
| 257 | le32_to_cpu(wl_mem_map->packet_memory_pool_start); |
| 258 | |
| 259 | rx_mem_addr.addr_extra = rx_mem_addr.addr + 4; |
| 260 | |
| 261 | wl1271_write(wl, WL1271_SLV_REG_DATA, |
| 262 | &rx_mem_addr, sizeof(rx_mem_addr), false); |
| 263 | } |
| 264 | } |
| 265 | |
Luciano Coelho | 6f7dd16 | 2011-11-29 16:27:31 +0200 | [diff] [blame] | 266 | static int wl12xx_identify_chip(struct wl1271 *wl) |
| 267 | { |
| 268 | int ret = 0; |
| 269 | |
| 270 | switch (wl->chip.id) { |
| 271 | case CHIP_ID_1271_PG10: |
| 272 | wl1271_warning("chip id 0x%x (1271 PG10) support is obsolete", |
| 273 | wl->chip.id); |
| 274 | |
Arik Nemtsov | f83985bb | 2011-12-13 12:11:26 +0200 | [diff] [blame^] | 275 | /* clear the alignment quirk, since we don't support it */ |
| 276 | wl->quirks &= ~WLCORE_QUIRK_TX_BLOCKSIZE_ALIGN; |
| 277 | |
| 278 | wl->quirks |= WLCORE_QUIRK_LEGACY_NVS; |
Luciano Coelho | 6f7dd16 | 2011-11-29 16:27:31 +0200 | [diff] [blame] | 279 | wl->sr_fw_name = WL127X_FW_NAME_SINGLE; |
| 280 | wl->mr_fw_name = WL127X_FW_NAME_MULTI; |
Luciano Coelho | b14684a | 2011-12-12 12:15:08 +0200 | [diff] [blame] | 281 | |
| 282 | /* read data preparation is only needed by wl127x */ |
| 283 | wl->ops->prepare_read = wl127x_prepare_read; |
| 284 | |
Luciano Coelho | 6f7dd16 | 2011-11-29 16:27:31 +0200 | [diff] [blame] | 285 | break; |
| 286 | |
| 287 | case CHIP_ID_1271_PG20: |
| 288 | wl1271_debug(DEBUG_BOOT, "chip id 0x%x (1271 PG20)", |
| 289 | wl->chip.id); |
| 290 | |
Arik Nemtsov | f83985bb | 2011-12-13 12:11:26 +0200 | [diff] [blame^] | 291 | /* clear the alignment quirk, since we don't support it */ |
| 292 | wl->quirks &= ~WLCORE_QUIRK_TX_BLOCKSIZE_ALIGN; |
| 293 | |
| 294 | wl->quirks |= WLCORE_QUIRK_LEGACY_NVS; |
Luciano Coelho | 6f7dd16 | 2011-11-29 16:27:31 +0200 | [diff] [blame] | 295 | wl->plt_fw_name = WL127X_PLT_FW_NAME; |
| 296 | wl->sr_fw_name = WL127X_FW_NAME_SINGLE; |
| 297 | wl->mr_fw_name = WL127X_FW_NAME_MULTI; |
Luciano Coelho | b14684a | 2011-12-12 12:15:08 +0200 | [diff] [blame] | 298 | |
| 299 | /* read data preparation is only needed by wl127x */ |
| 300 | wl->ops->prepare_read = wl127x_prepare_read; |
| 301 | |
Luciano Coelho | 6f7dd16 | 2011-11-29 16:27:31 +0200 | [diff] [blame] | 302 | break; |
| 303 | |
| 304 | case CHIP_ID_1283_PG20: |
| 305 | wl1271_debug(DEBUG_BOOT, "chip id 0x%x (1283 PG20)", |
| 306 | wl->chip.id); |
| 307 | wl->plt_fw_name = WL128X_PLT_FW_NAME; |
| 308 | wl->sr_fw_name = WL128X_FW_NAME_SINGLE; |
| 309 | wl->mr_fw_name = WL128X_FW_NAME_MULTI; |
| 310 | break; |
| 311 | case CHIP_ID_1283_PG10: |
| 312 | default: |
| 313 | wl1271_warning("unsupported chip id: 0x%x", wl->chip.id); |
| 314 | ret = -ENODEV; |
| 315 | goto out; |
| 316 | } |
| 317 | |
| 318 | out: |
| 319 | return ret; |
| 320 | } |
| 321 | |
Luciano Coelho | dd5512eb | 2012-04-11 11:03:14 +0300 | [diff] [blame] | 322 | static void wl12xx_top_reg_write(struct wl1271 *wl, int addr, u16 val) |
| 323 | { |
| 324 | /* write address >> 1 + 0x30000 to OCP_POR_CTR */ |
| 325 | addr = (addr >> 1) + 0x30000; |
| 326 | wl1271_write32(wl, WL12XX_OCP_POR_CTR, addr); |
| 327 | |
| 328 | /* write value to OCP_POR_WDATA */ |
| 329 | wl1271_write32(wl, WL12XX_OCP_DATA_WRITE, val); |
| 330 | |
| 331 | /* write 1 to OCP_CMD */ |
| 332 | wl1271_write32(wl, WL12XX_OCP_CMD, OCP_CMD_WRITE); |
| 333 | } |
| 334 | |
| 335 | static u16 wl12xx_top_reg_read(struct wl1271 *wl, int addr) |
| 336 | { |
| 337 | u32 val; |
| 338 | int timeout = OCP_CMD_LOOP; |
| 339 | |
| 340 | /* write address >> 1 + 0x30000 to OCP_POR_CTR */ |
| 341 | addr = (addr >> 1) + 0x30000; |
| 342 | wl1271_write32(wl, WL12XX_OCP_POR_CTR, addr); |
| 343 | |
| 344 | /* write 2 to OCP_CMD */ |
| 345 | wl1271_write32(wl, WL12XX_OCP_CMD, OCP_CMD_READ); |
| 346 | |
| 347 | /* poll for data ready */ |
| 348 | do { |
| 349 | val = wl1271_read32(wl, WL12XX_OCP_DATA_READ); |
| 350 | } while (!(val & OCP_READY_MASK) && --timeout); |
| 351 | |
| 352 | if (!timeout) { |
| 353 | wl1271_warning("Top register access timed out."); |
| 354 | return 0xffff; |
| 355 | } |
| 356 | |
| 357 | /* check data status and return if OK */ |
| 358 | if ((val & OCP_STATUS_MASK) == OCP_STATUS_OK) |
| 359 | return val & 0xffff; |
| 360 | else { |
| 361 | wl1271_warning("Top register access returned error."); |
| 362 | return 0xffff; |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | static int wl128x_switch_tcxo_to_fref(struct wl1271 *wl) |
| 367 | { |
| 368 | u16 spare_reg; |
| 369 | |
| 370 | /* Mask bits [2] & [8:4] in the sys_clk_cfg register */ |
| 371 | spare_reg = wl12xx_top_reg_read(wl, WL_SPARE_REG); |
| 372 | if (spare_reg == 0xFFFF) |
| 373 | return -EFAULT; |
| 374 | spare_reg |= (BIT(3) | BIT(5) | BIT(6)); |
| 375 | wl12xx_top_reg_write(wl, WL_SPARE_REG, spare_reg); |
| 376 | |
| 377 | /* Enable FREF_CLK_REQ & mux MCS and coex PLLs to FREF */ |
| 378 | wl12xx_top_reg_write(wl, SYS_CLK_CFG_REG, |
| 379 | WL_CLK_REQ_TYPE_PG2 | MCS_PLL_CLK_SEL_FREF); |
| 380 | |
| 381 | /* Delay execution for 15msec, to let the HW settle */ |
| 382 | mdelay(15); |
| 383 | |
| 384 | return 0; |
| 385 | } |
| 386 | |
| 387 | static bool wl128x_is_tcxo_valid(struct wl1271 *wl) |
| 388 | { |
| 389 | u16 tcxo_detection; |
| 390 | |
| 391 | tcxo_detection = wl12xx_top_reg_read(wl, TCXO_CLK_DETECT_REG); |
| 392 | if (tcxo_detection & TCXO_DET_FAILED) |
| 393 | return false; |
| 394 | |
| 395 | return true; |
| 396 | } |
| 397 | |
| 398 | static bool wl128x_is_fref_valid(struct wl1271 *wl) |
| 399 | { |
| 400 | u16 fref_detection; |
| 401 | |
| 402 | fref_detection = wl12xx_top_reg_read(wl, FREF_CLK_DETECT_REG); |
| 403 | if (fref_detection & FREF_CLK_DETECT_FAIL) |
| 404 | return false; |
| 405 | |
| 406 | return true; |
| 407 | } |
| 408 | |
| 409 | static int wl128x_manually_configure_mcs_pll(struct wl1271 *wl) |
| 410 | { |
| 411 | wl12xx_top_reg_write(wl, MCS_PLL_M_REG, MCS_PLL_M_REG_VAL); |
| 412 | wl12xx_top_reg_write(wl, MCS_PLL_N_REG, MCS_PLL_N_REG_VAL); |
| 413 | wl12xx_top_reg_write(wl, MCS_PLL_CONFIG_REG, MCS_PLL_CONFIG_REG_VAL); |
| 414 | |
| 415 | return 0; |
| 416 | } |
| 417 | |
| 418 | static int wl128x_configure_mcs_pll(struct wl1271 *wl, int clk) |
| 419 | { |
| 420 | u16 spare_reg; |
| 421 | u16 pll_config; |
| 422 | u8 input_freq; |
| 423 | |
| 424 | /* Mask bits [3:1] in the sys_clk_cfg register */ |
| 425 | spare_reg = wl12xx_top_reg_read(wl, WL_SPARE_REG); |
| 426 | if (spare_reg == 0xFFFF) |
| 427 | return -EFAULT; |
| 428 | spare_reg |= BIT(2); |
| 429 | wl12xx_top_reg_write(wl, WL_SPARE_REG, spare_reg); |
| 430 | |
| 431 | /* Handle special cases of the TCXO clock */ |
| 432 | if (wl->tcxo_clock == WL12XX_TCXOCLOCK_16_8 || |
| 433 | wl->tcxo_clock == WL12XX_TCXOCLOCK_33_6) |
| 434 | return wl128x_manually_configure_mcs_pll(wl); |
| 435 | |
| 436 | /* Set the input frequency according to the selected clock source */ |
| 437 | input_freq = (clk & 1) + 1; |
| 438 | |
| 439 | pll_config = wl12xx_top_reg_read(wl, MCS_PLL_CONFIG_REG); |
| 440 | if (pll_config == 0xFFFF) |
| 441 | return -EFAULT; |
| 442 | pll_config |= (input_freq << MCS_SEL_IN_FREQ_SHIFT); |
| 443 | pll_config |= MCS_PLL_ENABLE_HP; |
| 444 | wl12xx_top_reg_write(wl, MCS_PLL_CONFIG_REG, pll_config); |
| 445 | |
| 446 | return 0; |
| 447 | } |
| 448 | |
| 449 | /* |
| 450 | * WL128x has two clocks input - TCXO and FREF. |
| 451 | * TCXO is the main clock of the device, while FREF is used to sync |
| 452 | * between the GPS and the cellular modem. |
| 453 | * In cases where TCXO is 32.736MHz or 16.368MHz, the FREF will be used |
| 454 | * as the WLAN/BT main clock. |
| 455 | */ |
| 456 | static int wl128x_boot_clk(struct wl1271 *wl, int *selected_clock) |
| 457 | { |
| 458 | u16 sys_clk_cfg; |
| 459 | |
| 460 | /* For XTAL-only modes, FREF will be used after switching from TCXO */ |
| 461 | if (wl->ref_clock == WL12XX_REFCLOCK_26_XTAL || |
| 462 | wl->ref_clock == WL12XX_REFCLOCK_38_XTAL) { |
| 463 | if (!wl128x_switch_tcxo_to_fref(wl)) |
| 464 | return -EINVAL; |
| 465 | goto fref_clk; |
| 466 | } |
| 467 | |
| 468 | /* Query the HW, to determine which clock source we should use */ |
| 469 | sys_clk_cfg = wl12xx_top_reg_read(wl, SYS_CLK_CFG_REG); |
| 470 | if (sys_clk_cfg == 0xFFFF) |
| 471 | return -EINVAL; |
| 472 | if (sys_clk_cfg & PRCM_CM_EN_MUX_WLAN_FREF) |
| 473 | goto fref_clk; |
| 474 | |
| 475 | /* If TCXO is either 32.736MHz or 16.368MHz, switch to FREF */ |
| 476 | if (wl->tcxo_clock == WL12XX_TCXOCLOCK_16_368 || |
| 477 | wl->tcxo_clock == WL12XX_TCXOCLOCK_32_736) { |
| 478 | if (!wl128x_switch_tcxo_to_fref(wl)) |
| 479 | return -EINVAL; |
| 480 | goto fref_clk; |
| 481 | } |
| 482 | |
| 483 | /* TCXO clock is selected */ |
| 484 | if (!wl128x_is_tcxo_valid(wl)) |
| 485 | return -EINVAL; |
| 486 | *selected_clock = wl->tcxo_clock; |
| 487 | goto config_mcs_pll; |
| 488 | |
| 489 | fref_clk: |
| 490 | /* FREF clock is selected */ |
| 491 | if (!wl128x_is_fref_valid(wl)) |
| 492 | return -EINVAL; |
| 493 | *selected_clock = wl->ref_clock; |
| 494 | |
| 495 | config_mcs_pll: |
| 496 | return wl128x_configure_mcs_pll(wl, *selected_clock); |
| 497 | } |
| 498 | |
| 499 | static int wl127x_boot_clk(struct wl1271 *wl) |
| 500 | { |
| 501 | u32 pause; |
| 502 | u32 clk; |
| 503 | |
| 504 | if (WL127X_PG_GET_MAJOR(wl->hw_pg_ver) < 3) |
| 505 | wl->quirks |= WLCORE_QUIRK_END_OF_TRANSACTION; |
| 506 | |
| 507 | if (wl->ref_clock == CONF_REF_CLK_19_2_E || |
| 508 | wl->ref_clock == CONF_REF_CLK_38_4_E || |
| 509 | wl->ref_clock == CONF_REF_CLK_38_4_M_XTAL) |
| 510 | /* ref clk: 19.2/38.4/38.4-XTAL */ |
| 511 | clk = 0x3; |
| 512 | else if (wl->ref_clock == CONF_REF_CLK_26_E || |
| 513 | wl->ref_clock == CONF_REF_CLK_52_E) |
| 514 | /* ref clk: 26/52 */ |
| 515 | clk = 0x5; |
| 516 | else |
| 517 | return -EINVAL; |
| 518 | |
| 519 | if (wl->ref_clock != CONF_REF_CLK_19_2_E) { |
| 520 | u16 val; |
| 521 | /* Set clock type (open drain) */ |
| 522 | val = wl12xx_top_reg_read(wl, OCP_REG_CLK_TYPE); |
| 523 | val &= FREF_CLK_TYPE_BITS; |
| 524 | wl12xx_top_reg_write(wl, OCP_REG_CLK_TYPE, val); |
| 525 | |
| 526 | /* Set clock pull mode (no pull) */ |
| 527 | val = wl12xx_top_reg_read(wl, OCP_REG_CLK_PULL); |
| 528 | val |= NO_PULL; |
| 529 | wl12xx_top_reg_write(wl, OCP_REG_CLK_PULL, val); |
| 530 | } else { |
| 531 | u16 val; |
| 532 | /* Set clock polarity */ |
| 533 | val = wl12xx_top_reg_read(wl, OCP_REG_CLK_POLARITY); |
| 534 | val &= FREF_CLK_POLARITY_BITS; |
| 535 | val |= CLK_REQ_OUTN_SEL; |
| 536 | wl12xx_top_reg_write(wl, OCP_REG_CLK_POLARITY, val); |
| 537 | } |
| 538 | |
| 539 | wl1271_write32(wl, WL12XX_PLL_PARAMETERS, clk); |
| 540 | |
| 541 | pause = wl1271_read32(wl, WL12XX_PLL_PARAMETERS); |
| 542 | |
| 543 | wl1271_debug(DEBUG_BOOT, "pause1 0x%x", pause); |
| 544 | |
| 545 | pause &= ~(WU_COUNTER_PAUSE_VAL); |
| 546 | pause |= WU_COUNTER_PAUSE_VAL; |
| 547 | wl1271_write32(wl, WL12XX_WU_COUNTER_PAUSE, pause); |
| 548 | |
| 549 | return 0; |
| 550 | } |
| 551 | |
| 552 | static int wl1271_boot_soft_reset(struct wl1271 *wl) |
| 553 | { |
| 554 | unsigned long timeout; |
| 555 | u32 boot_data; |
| 556 | |
| 557 | /* perform soft reset */ |
| 558 | wl1271_write32(wl, WL12XX_SLV_SOFT_RESET, ACX_SLV_SOFT_RESET_BIT); |
| 559 | |
| 560 | /* SOFT_RESET is self clearing */ |
| 561 | timeout = jiffies + usecs_to_jiffies(SOFT_RESET_MAX_TIME); |
| 562 | while (1) { |
| 563 | boot_data = wl1271_read32(wl, WL12XX_SLV_SOFT_RESET); |
| 564 | wl1271_debug(DEBUG_BOOT, "soft reset bootdata 0x%x", boot_data); |
| 565 | if ((boot_data & ACX_SLV_SOFT_RESET_BIT) == 0) |
| 566 | break; |
| 567 | |
| 568 | if (time_after(jiffies, timeout)) { |
| 569 | /* 1.2 check pWhalBus->uSelfClearTime if the |
| 570 | * timeout was reached */ |
| 571 | wl1271_error("soft reset timeout"); |
| 572 | return -1; |
| 573 | } |
| 574 | |
| 575 | udelay(SOFT_RESET_STALL_TIME); |
| 576 | } |
| 577 | |
| 578 | /* disable Rx/Tx */ |
| 579 | wl1271_write32(wl, WL12XX_ENABLE, 0x0); |
| 580 | |
| 581 | /* disable auto calibration on start*/ |
| 582 | wl1271_write32(wl, WL12XX_SPARE_A2, 0xffff); |
| 583 | |
| 584 | return 0; |
| 585 | } |
| 586 | |
| 587 | static int wl12xx_pre_boot(struct wl1271 *wl) |
| 588 | { |
| 589 | int ret = 0; |
| 590 | u32 clk; |
| 591 | int selected_clock = -1; |
| 592 | |
| 593 | if (wl->chip.id == CHIP_ID_1283_PG20) { |
| 594 | ret = wl128x_boot_clk(wl, &selected_clock); |
| 595 | if (ret < 0) |
| 596 | goto out; |
| 597 | } else { |
| 598 | ret = wl127x_boot_clk(wl); |
| 599 | if (ret < 0) |
| 600 | goto out; |
| 601 | } |
| 602 | |
| 603 | /* Continue the ELP wake up sequence */ |
| 604 | wl1271_write32(wl, WL12XX_WELP_ARM_COMMAND, WELP_ARM_COMMAND_VAL); |
| 605 | udelay(500); |
| 606 | |
| 607 | wlcore_set_partition(wl, &wl->ptable[PART_DRPW]); |
| 608 | |
| 609 | /* Read-modify-write DRPW_SCRATCH_START register (see next state) |
| 610 | to be used by DRPw FW. The RTRIM value will be added by the FW |
| 611 | before taking DRPw out of reset */ |
| 612 | |
| 613 | clk = wl1271_read32(wl, WL12XX_DRPW_SCRATCH_START); |
| 614 | |
| 615 | wl1271_debug(DEBUG_BOOT, "clk2 0x%x", clk); |
| 616 | |
| 617 | if (wl->chip.id == CHIP_ID_1283_PG20) |
| 618 | clk |= ((selected_clock & 0x3) << 1) << 4; |
| 619 | else |
| 620 | clk |= (wl->ref_clock << 1) << 4; |
| 621 | |
| 622 | wl1271_write32(wl, WL12XX_DRPW_SCRATCH_START, clk); |
| 623 | |
| 624 | wlcore_set_partition(wl, &wl->ptable[PART_WORK]); |
| 625 | |
| 626 | /* Disable interrupts */ |
| 627 | wlcore_write_reg(wl, REG_INTERRUPT_MASK, WL1271_ACX_INTR_ALL); |
| 628 | |
| 629 | ret = wl1271_boot_soft_reset(wl); |
| 630 | if (ret < 0) |
| 631 | goto out; |
| 632 | |
| 633 | out: |
| 634 | return ret; |
| 635 | } |
| 636 | |
| 637 | static void wl12xx_pre_upload(struct wl1271 *wl) |
| 638 | { |
| 639 | u32 tmp; |
| 640 | |
| 641 | /* write firmware's last address (ie. it's length) to |
| 642 | * ACX_EEPROMLESS_IND_REG */ |
| 643 | wl1271_debug(DEBUG_BOOT, "ACX_EEPROMLESS_IND_REG"); |
| 644 | |
| 645 | wl1271_write32(wl, WL12XX_EEPROMLESS_IND, WL12XX_EEPROMLESS_IND); |
| 646 | |
| 647 | tmp = wlcore_read_reg(wl, REG_CHIP_ID_B); |
| 648 | |
| 649 | wl1271_debug(DEBUG_BOOT, "chip id 0x%x", tmp); |
| 650 | |
| 651 | /* 6. read the EEPROM parameters */ |
| 652 | tmp = wl1271_read32(wl, WL12XX_SCR_PAD2); |
| 653 | |
| 654 | /* WL1271: The reference driver skips steps 7 to 10 (jumps directly |
| 655 | * to upload_fw) */ |
| 656 | |
| 657 | if (wl->chip.id == CHIP_ID_1283_PG20) |
| 658 | wl12xx_top_reg_write(wl, SDIO_IO_DS, HCI_IO_DS_6MA); |
| 659 | } |
| 660 | |
| 661 | static void wl12xx_enable_interrupts(struct wl1271 *wl) |
| 662 | { |
| 663 | u32 polarity; |
| 664 | |
| 665 | polarity = wl12xx_top_reg_read(wl, OCP_REG_POLARITY); |
| 666 | |
| 667 | /* We use HIGH polarity, so unset the LOW bit */ |
| 668 | polarity &= ~POLARITY_LOW; |
| 669 | wl12xx_top_reg_write(wl, OCP_REG_POLARITY, polarity); |
| 670 | |
| 671 | wlcore_write_reg(wl, REG_INTERRUPT_MASK, WL1271_ACX_ALL_EVENTS_VECTOR); |
| 672 | |
| 673 | wlcore_enable_interrupts(wl); |
| 674 | wlcore_write_reg(wl, REG_INTERRUPT_MASK, |
| 675 | WL1271_ACX_INTR_ALL & ~(WL1271_INTR_MASK)); |
| 676 | |
| 677 | wl1271_write32(wl, WL12XX_HI_CFG, HI_CFG_DEF_VAL); |
| 678 | } |
| 679 | |
| 680 | static int wl12xx_boot(struct wl1271 *wl) |
| 681 | { |
| 682 | int ret; |
| 683 | |
| 684 | ret = wl12xx_pre_boot(wl); |
| 685 | if (ret < 0) |
| 686 | goto out; |
| 687 | |
| 688 | ret = wlcore_boot_upload_nvs(wl); |
| 689 | if (ret < 0) |
| 690 | goto out; |
| 691 | |
| 692 | wl12xx_pre_upload(wl); |
| 693 | |
| 694 | ret = wlcore_boot_upload_firmware(wl); |
| 695 | if (ret < 0) |
| 696 | goto out; |
| 697 | |
| 698 | ret = wlcore_boot_run_firmware(wl); |
| 699 | if (ret < 0) |
| 700 | goto out; |
| 701 | |
| 702 | wl12xx_enable_interrupts(wl); |
| 703 | |
| 704 | out: |
| 705 | return ret; |
| 706 | } |
| 707 | |
Luciano Coelho | f16ff75 | 2012-04-11 10:15:46 +0300 | [diff] [blame] | 708 | static void wl12xx_trigger_cmd(struct wl1271 *wl) |
| 709 | { |
| 710 | wlcore_write_reg(wl, REG_INTERRUPT_TRIG, WL12XX_INTR_TRIG_CMD); |
| 711 | } |
| 712 | |
| 713 | static void wl12xx_ack_event(struct wl1271 *wl) |
| 714 | { |
| 715 | wlcore_write_reg(wl, REG_INTERRUPT_TRIG, WL12XX_INTR_TRIG_EVENT_ACK); |
| 716 | } |
| 717 | |
Arik Nemtsov | b3b4b4b | 2011-12-12 11:41:44 +0200 | [diff] [blame] | 718 | static u32 wl12xx_calc_tx_blocks(struct wl1271 *wl, u32 len, u32 spare_blks) |
| 719 | { |
| 720 | u32 blk_size = WL12XX_TX_HW_BLOCK_SIZE; |
| 721 | u32 align_len = wlcore_calc_packet_alignment(wl, len); |
| 722 | |
| 723 | return (align_len + blk_size - 1) / blk_size + spare_blks; |
| 724 | } |
| 725 | |
Arik Nemtsov | 4a3b97ee | 2011-12-12 11:44:27 +0200 | [diff] [blame] | 726 | static void |
| 727 | wl12xx_set_tx_desc_blocks(struct wl1271 *wl, struct wl1271_tx_hw_descr *desc, |
| 728 | u32 blks, u32 spare_blks) |
| 729 | { |
| 730 | if (wl->chip.id == CHIP_ID_1283_PG20) { |
| 731 | desc->wl128x_mem.total_mem_blocks = blks; |
| 732 | } else { |
| 733 | desc->wl127x_mem.extra_blocks = spare_blks; |
| 734 | desc->wl127x_mem.total_mem_blocks = blks; |
| 735 | } |
| 736 | } |
| 737 | |
Arik Nemtsov | 6f266e9 | 2011-12-12 11:47:09 +0200 | [diff] [blame] | 738 | static void |
| 739 | wl12xx_set_tx_desc_data_len(struct wl1271 *wl, struct wl1271_tx_hw_descr *desc, |
| 740 | struct sk_buff *skb) |
| 741 | { |
| 742 | u32 aligned_len = wlcore_calc_packet_alignment(wl, skb->len); |
| 743 | |
| 744 | if (wl->chip.id == CHIP_ID_1283_PG20) { |
| 745 | desc->wl128x_mem.extra_bytes = aligned_len - skb->len; |
| 746 | desc->length = cpu_to_le16(aligned_len >> 2); |
| 747 | |
| 748 | wl1271_debug(DEBUG_TX, |
| 749 | "tx_fill_hdr: hlid: %d len: %d life: %d mem: %d extra: %d", |
| 750 | desc->hlid, |
| 751 | le16_to_cpu(desc->length), |
| 752 | le16_to_cpu(desc->life_time), |
| 753 | desc->wl128x_mem.total_mem_blocks, |
| 754 | desc->wl128x_mem.extra_bytes); |
| 755 | } else { |
| 756 | /* calculate number of padding bytes */ |
| 757 | int pad = aligned_len - skb->len; |
| 758 | desc->tx_attr |= |
| 759 | cpu_to_le16(pad << TX_HW_ATTR_OFST_LAST_WORD_PAD); |
| 760 | |
| 761 | /* Store the aligned length in terms of words */ |
| 762 | desc->length = cpu_to_le16(aligned_len >> 2); |
| 763 | |
| 764 | wl1271_debug(DEBUG_TX, |
| 765 | "tx_fill_hdr: pad: %d hlid: %d len: %d life: %d mem: %d", |
| 766 | pad, desc->hlid, |
| 767 | le16_to_cpu(desc->length), |
| 768 | le16_to_cpu(desc->life_time), |
| 769 | desc->wl127x_mem.total_mem_blocks); |
| 770 | } |
| 771 | } |
| 772 | |
Arik Nemtsov | cd70f6a | 2011-12-12 12:11:43 +0200 | [diff] [blame] | 773 | static enum wl_rx_buf_align |
| 774 | wl12xx_get_rx_buf_align(struct wl1271 *wl, u32 rx_desc) |
| 775 | { |
| 776 | if (rx_desc & RX_BUF_UNALIGNED_PAYLOAD) |
| 777 | return WLCORE_RX_BUF_UNALIGNED; |
| 778 | |
| 779 | return WLCORE_RX_BUF_ALIGNED; |
| 780 | } |
| 781 | |
Arik Nemtsov | 4158149 | 2011-12-12 12:18:17 +0200 | [diff] [blame] | 782 | static u32 wl12xx_get_rx_packet_len(struct wl1271 *wl, void *rx_data, |
| 783 | u32 data_len) |
| 784 | { |
| 785 | struct wl1271_rx_descriptor *desc = rx_data; |
| 786 | |
| 787 | /* invalid packet */ |
| 788 | if (data_len < sizeof(*desc) || |
| 789 | data_len < sizeof(*desc) + desc->pad_len) |
| 790 | return 0; |
| 791 | |
| 792 | return data_len - sizeof(*desc) - desc->pad_len; |
| 793 | } |
| 794 | |
Arik Nemtsov | 53d67a5 | 2011-12-12 11:32:37 +0200 | [diff] [blame] | 795 | static void wl12xx_tx_delayed_compl(struct wl1271 *wl) |
| 796 | { |
| 797 | if (wl->fw_status->tx_results_counter == (wl->tx_results_count & 0xff)) |
| 798 | return; |
| 799 | |
| 800 | wl1271_tx_complete(wl); |
| 801 | } |
| 802 | |
Luciano Coelho | 30d9b4a | 2012-04-11 11:07:28 +0300 | [diff] [blame] | 803 | static bool wl12xx_mac_in_fuse(struct wl1271 *wl) |
| 804 | { |
| 805 | bool supported = false; |
| 806 | u8 major, minor; |
| 807 | |
| 808 | if (wl->chip.id == CHIP_ID_1283_PG20) { |
| 809 | major = WL128X_PG_GET_MAJOR(wl->hw_pg_ver); |
| 810 | minor = WL128X_PG_GET_MINOR(wl->hw_pg_ver); |
| 811 | |
| 812 | /* in wl128x we have the MAC address if the PG is >= (2, 1) */ |
| 813 | if (major > 2 || (major == 2 && minor >= 1)) |
| 814 | supported = true; |
| 815 | } else { |
| 816 | major = WL127X_PG_GET_MAJOR(wl->hw_pg_ver); |
| 817 | minor = WL127X_PG_GET_MINOR(wl->hw_pg_ver); |
| 818 | |
| 819 | /* in wl127x we have the MAC address if the PG is >= (3, 1) */ |
| 820 | if (major == 3 && minor >= 1) |
| 821 | supported = true; |
| 822 | } |
| 823 | |
| 824 | wl1271_debug(DEBUG_PROBE, |
| 825 | "PG Ver major = %d minor = %d, MAC %s present", |
| 826 | major, minor, supported ? "is" : "is not"); |
| 827 | |
| 828 | return supported; |
| 829 | } |
| 830 | |
| 831 | static void wl12xx_get_fuse_mac(struct wl1271 *wl) |
| 832 | { |
| 833 | u32 mac1, mac2; |
| 834 | |
| 835 | wlcore_set_partition(wl, &wl->ptable[PART_DRPW]); |
| 836 | |
| 837 | mac1 = wl1271_read32(wl, WL12XX_REG_FUSE_BD_ADDR_1); |
| 838 | mac2 = wl1271_read32(wl, WL12XX_REG_FUSE_BD_ADDR_2); |
| 839 | |
| 840 | /* these are the two parts of the BD_ADDR */ |
| 841 | wl->fuse_oui_addr = ((mac2 & 0xffff) << 8) + |
| 842 | ((mac1 & 0xff000000) >> 24); |
| 843 | wl->fuse_nic_addr = mac1 & 0xffffff; |
| 844 | |
| 845 | wlcore_set_partition(wl, &wl->ptable[PART_DOWN]); |
| 846 | } |
| 847 | |
Luciano Coelho | 4ded91c | 2012-04-11 10:54:52 +0300 | [diff] [blame] | 848 | static s8 wl12xx_get_pg_ver(struct wl1271 *wl) |
| 849 | { |
| 850 | u32 die_info; |
| 851 | |
| 852 | if (wl->chip.id == CHIP_ID_1283_PG20) |
Luciano Coelho | dd5512eb | 2012-04-11 11:03:14 +0300 | [diff] [blame] | 853 | die_info = wl12xx_top_reg_read(wl, WL128X_REG_FUSE_DATA_2_1); |
Luciano Coelho | 4ded91c | 2012-04-11 10:54:52 +0300 | [diff] [blame] | 854 | else |
Luciano Coelho | dd5512eb | 2012-04-11 11:03:14 +0300 | [diff] [blame] | 855 | die_info = wl12xx_top_reg_read(wl, WL127X_REG_FUSE_DATA_2_1); |
Luciano Coelho | 4ded91c | 2012-04-11 10:54:52 +0300 | [diff] [blame] | 856 | |
| 857 | return (s8) (die_info & PG_VER_MASK) >> PG_VER_OFFSET; |
| 858 | } |
| 859 | |
Luciano Coelho | 30d9b4a | 2012-04-11 11:07:28 +0300 | [diff] [blame] | 860 | static void wl12xx_get_mac(struct wl1271 *wl) |
| 861 | { |
| 862 | if (wl12xx_mac_in_fuse(wl)) |
| 863 | wl12xx_get_fuse_mac(wl); |
| 864 | } |
| 865 | |
Luciano Coelho | 6f7dd16 | 2011-11-29 16:27:31 +0200 | [diff] [blame] | 866 | static struct wlcore_ops wl12xx_ops = { |
Arik Nemtsov | 4a3b97ee | 2011-12-12 11:44:27 +0200 | [diff] [blame] | 867 | .identify_chip = wl12xx_identify_chip, |
| 868 | .boot = wl12xx_boot, |
| 869 | .trigger_cmd = wl12xx_trigger_cmd, |
| 870 | .ack_event = wl12xx_ack_event, |
| 871 | .calc_tx_blocks = wl12xx_calc_tx_blocks, |
| 872 | .set_tx_desc_blocks = wl12xx_set_tx_desc_blocks, |
Arik Nemtsov | 6f266e9 | 2011-12-12 11:47:09 +0200 | [diff] [blame] | 873 | .set_tx_desc_data_len = wl12xx_set_tx_desc_data_len, |
Arik Nemtsov | cd70f6a | 2011-12-12 12:11:43 +0200 | [diff] [blame] | 874 | .get_rx_buf_align = wl12xx_get_rx_buf_align, |
Arik Nemtsov | 4158149 | 2011-12-12 12:18:17 +0200 | [diff] [blame] | 875 | .get_rx_packet_len = wl12xx_get_rx_packet_len, |
Arik Nemtsov | 53d67a5 | 2011-12-12 11:32:37 +0200 | [diff] [blame] | 876 | .tx_immediate_compl = NULL, |
| 877 | .tx_delayed_compl = wl12xx_tx_delayed_compl, |
Arik Nemtsov | 4a3b97ee | 2011-12-12 11:44:27 +0200 | [diff] [blame] | 878 | .get_pg_ver = wl12xx_get_pg_ver, |
| 879 | .get_mac = wl12xx_get_mac, |
Luciano Coelho | 6f7dd16 | 2011-11-29 16:27:31 +0200 | [diff] [blame] | 880 | }; |
| 881 | |
Arik Nemtsov | 96e0c68 | 2011-12-07 21:09:03 +0200 | [diff] [blame] | 882 | struct wl12xx_priv { |
| 883 | }; |
| 884 | |
Luciano Coelho | ffeb501 | 2011-11-21 18:55:51 +0200 | [diff] [blame] | 885 | static int __devinit wl12xx_probe(struct platform_device *pdev) |
| 886 | { |
| 887 | struct wl1271 *wl; |
| 888 | struct ieee80211_hw *hw; |
Arik Nemtsov | 96e0c68 | 2011-12-07 21:09:03 +0200 | [diff] [blame] | 889 | struct wl12xx_priv *priv; |
Luciano Coelho | ffeb501 | 2011-11-21 18:55:51 +0200 | [diff] [blame] | 890 | |
Arik Nemtsov | 96e0c68 | 2011-12-07 21:09:03 +0200 | [diff] [blame] | 891 | hw = wlcore_alloc_hw(sizeof(*priv)); |
Luciano Coelho | ffeb501 | 2011-11-21 18:55:51 +0200 | [diff] [blame] | 892 | if (IS_ERR(hw)) { |
| 893 | wl1271_error("can't allocate hw"); |
| 894 | return PTR_ERR(hw); |
| 895 | } |
| 896 | |
| 897 | wl = hw->priv; |
Luciano Coelho | c31be25 | 2011-11-21 19:25:24 +0200 | [diff] [blame] | 898 | wl->ops = &wl12xx_ops; |
Luciano Coelho | 25a43d7 | 2011-11-21 20:37:14 +0200 | [diff] [blame] | 899 | wl->ptable = wl12xx_ptable; |
Luciano Coelho | 0078213 | 2011-11-29 13:38:37 +0200 | [diff] [blame] | 900 | wl->rtable = wl12xx_rtable; |
Arik Nemtsov | 72b0624 | 2011-12-07 21:21:51 +0200 | [diff] [blame] | 901 | wl->num_tx_desc = 16; |
Arik Nemtsov | 3edab30 | 2011-12-07 23:38:47 +0200 | [diff] [blame] | 902 | wl->normal_tx_spare = WL12XX_TX_HW_BLOCK_SPARE_DEFAULT; |
| 903 | wl->gem_tx_spare = WL12XX_TX_HW_BLOCK_GEM_SPARE; |
Arik Nemtsov | 43a8bc5 | 2011-12-08 00:43:48 +0200 | [diff] [blame] | 904 | wl->band_rate_to_idx = wl12xx_band_rate_to_idx; |
| 905 | wl->hw_tx_rate_tbl_size = WL12XX_CONF_HW_RXTX_RATE_MAX; |
| 906 | wl->hw_min_ht_rate = WL12XX_CONF_HW_RXTX_RATE_MCS0; |
Luciano Coelho | ffeb501 | 2011-11-21 18:55:51 +0200 | [diff] [blame] | 907 | |
| 908 | return wlcore_probe(wl, pdev); |
| 909 | } |
Luciano Coelho | b2ba99f | 2011-11-20 23:32:10 +0200 | [diff] [blame] | 910 | |
| 911 | static const struct platform_device_id wl12xx_id_table[] __devinitconst = { |
| 912 | { "wl12xx", 0 }, |
| 913 | { } /* Terminating Entry */ |
| 914 | }; |
| 915 | MODULE_DEVICE_TABLE(platform, wl12xx_id_table); |
| 916 | |
| 917 | static struct platform_driver wl12xx_driver = { |
Luciano Coelho | ffeb501 | 2011-11-21 18:55:51 +0200 | [diff] [blame] | 918 | .probe = wl12xx_probe, |
Luciano Coelho | b2ba99f | 2011-11-20 23:32:10 +0200 | [diff] [blame] | 919 | .remove = __devexit_p(wlcore_remove), |
| 920 | .id_table = wl12xx_id_table, |
| 921 | .driver = { |
| 922 | .name = "wl12xx_driver", |
| 923 | .owner = THIS_MODULE, |
| 924 | } |
| 925 | }; |
| 926 | |
| 927 | static int __init wl12xx_init(void) |
| 928 | { |
| 929 | return platform_driver_register(&wl12xx_driver); |
| 930 | } |
| 931 | module_init(wl12xx_init); |
| 932 | |
| 933 | static void __exit wl12xx_exit(void) |
| 934 | { |
| 935 | platform_driver_unregister(&wl12xx_driver); |
| 936 | } |
| 937 | module_exit(wl12xx_exit); |
| 938 | |
| 939 | MODULE_LICENSE("GPL v2"); |
| 940 | MODULE_AUTHOR("Luciano Coelho <coelho@ti.com>"); |
Luciano Coelho | 6f7dd16 | 2011-11-29 16:27:31 +0200 | [diff] [blame] | 941 | MODULE_FIRMWARE(WL127X_FW_NAME_SINGLE); |
| 942 | MODULE_FIRMWARE(WL127X_FW_NAME_MULTI); |
| 943 | MODULE_FIRMWARE(WL127X_PLT_FW_NAME); |
| 944 | MODULE_FIRMWARE(WL128X_FW_NAME_SINGLE); |
| 945 | MODULE_FIRMWARE(WL128X_FW_NAME_MULTI); |
| 946 | MODULE_FIRMWARE(WL128X_PLT_FW_NAME); |