| .. | .. |
|---|
| 22 | 22 | * |
|---|
| 23 | 23 | */ |
|---|
| 24 | 24 | |
|---|
| 25 | +#include <linux/bits.h> |
|---|
| 26 | +#include <linux/errno.h> |
|---|
| 27 | +#include <linux/kernel.h> |
|---|
| 28 | +#include "device.h" |
|---|
| 25 | 29 | #include "mac.h" |
|---|
| 26 | 30 | #include "baseband.h" |
|---|
| 27 | 31 | #include "rf.h" |
|---|
| 28 | 32 | #include "usbpipe.h" |
|---|
| 29 | 33 | |
|---|
| 30 | | -static u8 vnt_vt3184_agc[] = { |
|---|
| 34 | +static const u8 vnt_vt3184_agc[] = { |
|---|
| 31 | 35 | 0x00, 0x00, 0x02, 0x02, 0x04, 0x04, 0x06, 0x06, |
|---|
| 32 | 36 | 0x08, 0x08, 0x0a, 0x0a, 0x0c, 0x0c, 0x0e, 0x0e, /* 0x0f */ |
|---|
| 33 | 37 | 0x10, 0x10, 0x12, 0x12, 0x14, 0x14, 0x16, 0x16, |
|---|
| .. | .. |
|---|
| 74 | 78 | }; |
|---|
| 75 | 79 | |
|---|
| 76 | 80 | /* {{RobertYu:20060515, new BB setting for VT3226D0 */ |
|---|
| 77 | | -static u8 vnt_vt3184_vt3226d0[] = { |
|---|
| 81 | +static const u8 vnt_vt3184_vt3226d0[] = { |
|---|
| 78 | 82 | 0x31, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, |
|---|
| 79 | 83 | 0x70, 0x45, 0x2a, 0x76, 0x00, 0x00, 0x80, 0x00, /* 0x0f */ |
|---|
| 80 | 84 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|---|
| .. | .. |
|---|
| 109 | 113 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* 0xff */ |
|---|
| 110 | 114 | }; |
|---|
| 111 | 115 | |
|---|
| 112 | | -static const u16 vnt_frame_time[MAX_RATE] = { |
|---|
| 113 | | - 10, 20, 55, 110, 24, 36, 48, 72, 96, 144, 192, 216 |
|---|
| 116 | +struct vnt_threshold { |
|---|
| 117 | + u8 bb_pre_ed_rssi; |
|---|
| 118 | + u8 cr_201; |
|---|
| 119 | + u8 cr_206; |
|---|
| 114 | 120 | }; |
|---|
| 115 | 121 | |
|---|
| 116 | | -/* |
|---|
| 117 | | - * Description: Calculate data frame transmitting time |
|---|
| 118 | | - * |
|---|
| 119 | | - * Parameters: |
|---|
| 120 | | - * In: |
|---|
| 121 | | - * preamble_type - Preamble Type |
|---|
| 122 | | - * pkt_type - PK_TYPE_11A, PK_TYPE_11B, PK_TYPE_11GB, PK_TYPE_11GA |
|---|
| 123 | | - * frame_length - Baseband Type |
|---|
| 124 | | - * tx_rate - Tx Rate |
|---|
| 125 | | - * Out: |
|---|
| 126 | | - * |
|---|
| 127 | | - * Return Value: FrameTime |
|---|
| 128 | | - * |
|---|
| 129 | | - */ |
|---|
| 130 | | -unsigned int vnt_get_frame_time(u8 preamble_type, u8 pkt_type, |
|---|
| 131 | | - unsigned int frame_length, u16 tx_rate) |
|---|
| 132 | | -{ |
|---|
| 133 | | - unsigned int frame_time; |
|---|
| 134 | | - unsigned int preamble; |
|---|
| 135 | | - unsigned int tmp; |
|---|
| 136 | | - unsigned int rate = 0; |
|---|
| 122 | +static const struct vnt_threshold al2230_vnt_threshold[] = { |
|---|
| 123 | + {0, 0x00, 0x30}, /* Max sensitivity */ |
|---|
| 124 | + {68, 0x00, 0x36}, |
|---|
| 125 | + {67, 0x00, 0x43}, |
|---|
| 126 | + {66, 0x00, 0x51}, |
|---|
| 127 | + {65, 0x00, 0x62}, |
|---|
| 128 | + {64, 0x00, 0x79}, |
|---|
| 129 | + {63, 0x00, 0x93}, |
|---|
| 130 | + {62, 0x00, 0xb9}, |
|---|
| 131 | + {61, 0x00, 0xe3}, |
|---|
| 132 | + {60, 0x01, 0x18}, |
|---|
| 133 | + {59, 0x01, 0x54}, |
|---|
| 134 | + {58, 0x01, 0xa0}, |
|---|
| 135 | + {57, 0x02, 0x20}, |
|---|
| 136 | + {56, 0x02, 0xa0}, |
|---|
| 137 | + {55, 0x03, 0x00}, |
|---|
| 138 | + {53, 0x06, 0x00}, |
|---|
| 139 | + {51, 0x09, 0x00}, |
|---|
| 140 | + {49, 0x0e, 0x00}, |
|---|
| 141 | + {47, 0x15, 0x00}, |
|---|
| 142 | + {46, 0x1a, 0x00}, |
|---|
| 143 | + {45, 0xff, 0x00} |
|---|
| 144 | +}; |
|---|
| 137 | 145 | |
|---|
| 138 | | - if (tx_rate > RATE_54M) |
|---|
| 139 | | - return 0; |
|---|
| 146 | +static const struct vnt_threshold vt3226_vnt_threshold[] = { |
|---|
| 147 | + {0, 0x00, 0x24}, /* Max sensitivity */ |
|---|
| 148 | + {68, 0x00, 0x2d}, |
|---|
| 149 | + {67, 0x00, 0x36}, |
|---|
| 150 | + {66, 0x00, 0x43}, |
|---|
| 151 | + {65, 0x00, 0x52}, |
|---|
| 152 | + {64, 0x00, 0x68}, |
|---|
| 153 | + {63, 0x00, 0x80}, |
|---|
| 154 | + {62, 0x00, 0x9c}, |
|---|
| 155 | + {61, 0x00, 0xc0}, |
|---|
| 156 | + {60, 0x00, 0xea}, |
|---|
| 157 | + {59, 0x01, 0x30}, |
|---|
| 158 | + {58, 0x01, 0x70}, |
|---|
| 159 | + {57, 0x01, 0xb0}, |
|---|
| 160 | + {56, 0x02, 0x30}, |
|---|
| 161 | + {55, 0x02, 0xc0}, |
|---|
| 162 | + {53, 0x04, 0x00}, |
|---|
| 163 | + {51, 0x07, 0x00}, |
|---|
| 164 | + {49, 0x0a, 0x00}, |
|---|
| 165 | + {47, 0x11, 0x00}, |
|---|
| 166 | + {45, 0x18, 0x00}, |
|---|
| 167 | + {43, 0x26, 0x00}, |
|---|
| 168 | + {42, 0x36, 0x00}, |
|---|
| 169 | + {41, 0xff, 0x00} |
|---|
| 170 | +}; |
|---|
| 140 | 171 | |
|---|
| 141 | | - rate = (unsigned int)vnt_frame_time[tx_rate]; |
|---|
| 142 | | - |
|---|
| 143 | | - if (tx_rate <= 3) { |
|---|
| 144 | | - if (preamble_type == 1) |
|---|
| 145 | | - preamble = 96; |
|---|
| 146 | | - else |
|---|
| 147 | | - preamble = 192; |
|---|
| 148 | | - |
|---|
| 149 | | - frame_time = (frame_length * 80) / rate; |
|---|
| 150 | | - tmp = (frame_time * rate) / 80; |
|---|
| 151 | | - |
|---|
| 152 | | - if (frame_length != tmp) |
|---|
| 153 | | - frame_time++; |
|---|
| 154 | | - |
|---|
| 155 | | - return preamble + frame_time; |
|---|
| 156 | | - } |
|---|
| 157 | | - frame_time = (frame_length * 8 + 22) / rate; |
|---|
| 158 | | - tmp = ((frame_time * rate) - 22) / 8; |
|---|
| 159 | | - |
|---|
| 160 | | - if (frame_length != tmp) |
|---|
| 161 | | - frame_time++; |
|---|
| 162 | | - |
|---|
| 163 | | - frame_time = frame_time * 4; |
|---|
| 164 | | - |
|---|
| 165 | | - if (pkt_type != PK_TYPE_11A) |
|---|
| 166 | | - frame_time += 6; |
|---|
| 167 | | - return 20 + frame_time; |
|---|
| 168 | | -} |
|---|
| 169 | | - |
|---|
| 170 | | -/* |
|---|
| 171 | | - * Description: Calculate Length, Service, and Signal fields of Phy for Tx |
|---|
| 172 | | - * |
|---|
| 173 | | - * Parameters: |
|---|
| 174 | | - * In: |
|---|
| 175 | | - * priv - Device Structure |
|---|
| 176 | | - * frame_length - Tx Frame Length |
|---|
| 177 | | - * tx_rate - Tx Rate |
|---|
| 178 | | - * Out: |
|---|
| 179 | | - * struct vnt_phy_field *phy |
|---|
| 180 | | - * - pointer to Phy Length field |
|---|
| 181 | | - * - pointer to Phy Service field |
|---|
| 182 | | - * - pointer to Phy Signal field |
|---|
| 183 | | - * |
|---|
| 184 | | - * Return Value: none |
|---|
| 185 | | - * |
|---|
| 186 | | - */ |
|---|
| 187 | | -void vnt_get_phy_field(struct vnt_private *priv, u32 frame_length, |
|---|
| 188 | | - u16 tx_rate, u8 pkt_type, struct vnt_phy_field *phy) |
|---|
| 189 | | -{ |
|---|
| 190 | | - u32 bit_count; |
|---|
| 191 | | - u32 count = 0; |
|---|
| 192 | | - u32 tmp; |
|---|
| 193 | | - int ext_bit; |
|---|
| 194 | | - u8 preamble_type = priv->preamble_type; |
|---|
| 195 | | - |
|---|
| 196 | | - bit_count = frame_length * 8; |
|---|
| 197 | | - ext_bit = false; |
|---|
| 198 | | - |
|---|
| 199 | | - switch (tx_rate) { |
|---|
| 200 | | - case RATE_1M: |
|---|
| 201 | | - count = bit_count; |
|---|
| 202 | | - |
|---|
| 203 | | - phy->signal = 0x00; |
|---|
| 204 | | - |
|---|
| 205 | | - break; |
|---|
| 206 | | - case RATE_2M: |
|---|
| 207 | | - count = bit_count / 2; |
|---|
| 208 | | - |
|---|
| 209 | | - if (preamble_type == 1) |
|---|
| 210 | | - phy->signal = 0x09; |
|---|
| 211 | | - else |
|---|
| 212 | | - phy->signal = 0x01; |
|---|
| 213 | | - |
|---|
| 214 | | - break; |
|---|
| 215 | | - case RATE_5M: |
|---|
| 216 | | - count = (bit_count * 10) / 55; |
|---|
| 217 | | - tmp = (count * 55) / 10; |
|---|
| 218 | | - |
|---|
| 219 | | - if (tmp != bit_count) |
|---|
| 220 | | - count++; |
|---|
| 221 | | - |
|---|
| 222 | | - if (preamble_type == 1) |
|---|
| 223 | | - phy->signal = 0x0a; |
|---|
| 224 | | - else |
|---|
| 225 | | - phy->signal = 0x02; |
|---|
| 226 | | - |
|---|
| 227 | | - break; |
|---|
| 228 | | - case RATE_11M: |
|---|
| 229 | | - count = bit_count / 11; |
|---|
| 230 | | - tmp = count * 11; |
|---|
| 231 | | - |
|---|
| 232 | | - if (tmp != bit_count) { |
|---|
| 233 | | - count++; |
|---|
| 234 | | - |
|---|
| 235 | | - if ((bit_count - tmp) <= 3) |
|---|
| 236 | | - ext_bit = true; |
|---|
| 237 | | - } |
|---|
| 238 | | - |
|---|
| 239 | | - if (preamble_type == 1) |
|---|
| 240 | | - phy->signal = 0x0b; |
|---|
| 241 | | - else |
|---|
| 242 | | - phy->signal = 0x03; |
|---|
| 243 | | - |
|---|
| 244 | | - break; |
|---|
| 245 | | - case RATE_6M: |
|---|
| 246 | | - if (pkt_type == PK_TYPE_11A) |
|---|
| 247 | | - phy->signal = 0x9b; |
|---|
| 248 | | - else |
|---|
| 249 | | - phy->signal = 0x8b; |
|---|
| 250 | | - |
|---|
| 251 | | - break; |
|---|
| 252 | | - case RATE_9M: |
|---|
| 253 | | - if (pkt_type == PK_TYPE_11A) |
|---|
| 254 | | - phy->signal = 0x9f; |
|---|
| 255 | | - else |
|---|
| 256 | | - phy->signal = 0x8f; |
|---|
| 257 | | - |
|---|
| 258 | | - break; |
|---|
| 259 | | - case RATE_12M: |
|---|
| 260 | | - if (pkt_type == PK_TYPE_11A) |
|---|
| 261 | | - phy->signal = 0x9a; |
|---|
| 262 | | - else |
|---|
| 263 | | - phy->signal = 0x8a; |
|---|
| 264 | | - |
|---|
| 265 | | - break; |
|---|
| 266 | | - case RATE_18M: |
|---|
| 267 | | - if (pkt_type == PK_TYPE_11A) |
|---|
| 268 | | - phy->signal = 0x9e; |
|---|
| 269 | | - else |
|---|
| 270 | | - phy->signal = 0x8e; |
|---|
| 271 | | - |
|---|
| 272 | | - break; |
|---|
| 273 | | - case RATE_24M: |
|---|
| 274 | | - if (pkt_type == PK_TYPE_11A) |
|---|
| 275 | | - phy->signal = 0x99; |
|---|
| 276 | | - else |
|---|
| 277 | | - phy->signal = 0x89; |
|---|
| 278 | | - |
|---|
| 279 | | - break; |
|---|
| 280 | | - case RATE_36M: |
|---|
| 281 | | - if (pkt_type == PK_TYPE_11A) |
|---|
| 282 | | - phy->signal = 0x9d; |
|---|
| 283 | | - else |
|---|
| 284 | | - phy->signal = 0x8d; |
|---|
| 285 | | - |
|---|
| 286 | | - break; |
|---|
| 287 | | - case RATE_48M: |
|---|
| 288 | | - if (pkt_type == PK_TYPE_11A) |
|---|
| 289 | | - phy->signal = 0x98; |
|---|
| 290 | | - else |
|---|
| 291 | | - phy->signal = 0x88; |
|---|
| 292 | | - |
|---|
| 293 | | - break; |
|---|
| 294 | | - case RATE_54M: |
|---|
| 295 | | - if (pkt_type == PK_TYPE_11A) |
|---|
| 296 | | - phy->signal = 0x9c; |
|---|
| 297 | | - else |
|---|
| 298 | | - phy->signal = 0x8c; |
|---|
| 299 | | - break; |
|---|
| 300 | | - default: |
|---|
| 301 | | - if (pkt_type == PK_TYPE_11A) |
|---|
| 302 | | - phy->signal = 0x9c; |
|---|
| 303 | | - else |
|---|
| 304 | | - phy->signal = 0x8c; |
|---|
| 305 | | - break; |
|---|
| 306 | | - } |
|---|
| 307 | | - |
|---|
| 308 | | - if (pkt_type == PK_TYPE_11B) { |
|---|
| 309 | | - phy->service = 0x00; |
|---|
| 310 | | - if (ext_bit) |
|---|
| 311 | | - phy->service |= 0x80; |
|---|
| 312 | | - phy->len = cpu_to_le16((u16)count); |
|---|
| 313 | | - } else { |
|---|
| 314 | | - phy->service = 0x00; |
|---|
| 315 | | - phy->len = cpu_to_le16((u16)frame_length); |
|---|
| 316 | | - } |
|---|
| 317 | | -} |
|---|
| 172 | +static const struct vnt_threshold vt3342_vnt_threshold[] = { |
|---|
| 173 | + {0, 0x00, 0x38}, /* Max sensitivity */ |
|---|
| 174 | + {66, 0x00, 0x43}, |
|---|
| 175 | + {65, 0x00, 0x52}, |
|---|
| 176 | + {64, 0x00, 0x68}, |
|---|
| 177 | + {63, 0x00, 0x80}, |
|---|
| 178 | + {62, 0x00, 0x9c}, |
|---|
| 179 | + {61, 0x00, 0xc0}, |
|---|
| 180 | + {60, 0x00, 0xea}, |
|---|
| 181 | + {59, 0x01, 0x30}, |
|---|
| 182 | + {58, 0x01, 0x70}, |
|---|
| 183 | + {57, 0x01, 0xb0}, |
|---|
| 184 | + {56, 0x02, 0x30}, |
|---|
| 185 | + {55, 0x02, 0xc0}, |
|---|
| 186 | + {53, 0x04, 0x00}, |
|---|
| 187 | + {51, 0x07, 0x00}, |
|---|
| 188 | + {49, 0x0a, 0x00}, |
|---|
| 189 | + {47, 0x11, 0x00}, |
|---|
| 190 | + {45, 0x18, 0x00}, |
|---|
| 191 | + {43, 0x26, 0x00}, |
|---|
| 192 | + {42, 0x36, 0x00}, |
|---|
| 193 | + {41, 0xff, 0x00} |
|---|
| 194 | +}; |
|---|
| 318 | 195 | |
|---|
| 319 | 196 | /* |
|---|
| 320 | 197 | * Description: Set Antenna mode |
|---|
| .. | .. |
|---|
| 329 | 206 | * Return Value: none |
|---|
| 330 | 207 | * |
|---|
| 331 | 208 | */ |
|---|
| 332 | | -void vnt_set_antenna_mode(struct vnt_private *priv, u8 antenna_mode) |
|---|
| 209 | +int vnt_set_antenna_mode(struct vnt_private *priv, u8 antenna_mode) |
|---|
| 333 | 210 | { |
|---|
| 334 | 211 | switch (antenna_mode) { |
|---|
| 335 | 212 | case ANT_TXA: |
|---|
| .. | .. |
|---|
| 344 | 221 | break; |
|---|
| 345 | 222 | } |
|---|
| 346 | 223 | |
|---|
| 347 | | - vnt_control_out(priv, MESSAGE_TYPE_SET_ANTMD, |
|---|
| 348 | | - (u16)antenna_mode, 0, 0, NULL); |
|---|
| 224 | + return vnt_control_out(priv, MESSAGE_TYPE_SET_ANTMD, |
|---|
| 225 | + (u16)antenna_mode, 0, 0, NULL); |
|---|
| 349 | 226 | } |
|---|
| 350 | 227 | |
|---|
| 351 | 228 | /* |
|---|
| .. | .. |
|---|
| 364 | 241 | |
|---|
| 365 | 242 | int vnt_vt3184_init(struct vnt_private *priv) |
|---|
| 366 | 243 | { |
|---|
| 367 | | - int status; |
|---|
| 244 | + int ret; |
|---|
| 368 | 245 | u16 length; |
|---|
| 369 | | - u8 *addr; |
|---|
| 370 | | - u8 *agc; |
|---|
| 371 | | - u16 length_agc; |
|---|
| 372 | | - u8 array[256]; |
|---|
| 246 | + u8 *addr = NULL; |
|---|
| 247 | + const u8 *c_addr; |
|---|
| 373 | 248 | u8 data; |
|---|
| 374 | 249 | |
|---|
| 375 | | - status = vnt_control_in(priv, MESSAGE_TYPE_READ, 0, |
|---|
| 376 | | - MESSAGE_REQUEST_EEPROM, EEP_MAX_CONTEXT_SIZE, |
|---|
| 377 | | - priv->eeprom); |
|---|
| 378 | | - if (status != STATUS_SUCCESS) |
|---|
| 379 | | - return false; |
|---|
| 250 | + ret = vnt_control_in(priv, MESSAGE_TYPE_READ, 0, MESSAGE_REQUEST_EEPROM, |
|---|
| 251 | + EEP_MAX_CONTEXT_SIZE, priv->eeprom); |
|---|
| 252 | + if (ret) |
|---|
| 253 | + goto end; |
|---|
| 380 | 254 | |
|---|
| 381 | 255 | priv->rf_type = priv->eeprom[EEP_OFS_RFTYPE]; |
|---|
| 382 | 256 | |
|---|
| 383 | 257 | dev_dbg(&priv->usb->dev, "RF Type %d\n", priv->rf_type); |
|---|
| 384 | 258 | |
|---|
| 385 | 259 | if ((priv->rf_type == RF_AL2230) || |
|---|
| 386 | | - (priv->rf_type == RF_AL2230S)) { |
|---|
| 260 | + (priv->rf_type == RF_AL2230S) || |
|---|
| 261 | + (priv->rf_type == RF_AIROHA7230)) { |
|---|
| 387 | 262 | priv->bb_rx_conf = vnt_vt3184_al2230[10]; |
|---|
| 388 | 263 | length = sizeof(vnt_vt3184_al2230); |
|---|
| 389 | 264 | addr = vnt_vt3184_al2230; |
|---|
| 390 | | - agc = vnt_vt3184_agc; |
|---|
| 391 | | - length_agc = sizeof(vnt_vt3184_agc); |
|---|
| 392 | 265 | |
|---|
| 393 | | - priv->bb_vga[0] = 0x1C; |
|---|
| 394 | | - priv->bb_vga[1] = 0x10; |
|---|
| 395 | | - priv->bb_vga[2] = 0x0; |
|---|
| 396 | | - priv->bb_vga[3] = 0x0; |
|---|
| 397 | | - |
|---|
| 398 | | - } else if (priv->rf_type == RF_AIROHA7230) { |
|---|
| 399 | | - priv->bb_rx_conf = vnt_vt3184_al2230[10]; |
|---|
| 400 | | - length = sizeof(vnt_vt3184_al2230); |
|---|
| 401 | | - addr = vnt_vt3184_al2230; |
|---|
| 402 | | - agc = vnt_vt3184_agc; |
|---|
| 403 | | - length_agc = sizeof(vnt_vt3184_agc); |
|---|
| 404 | | - |
|---|
| 405 | | - addr[0xd7] = 0x06; |
|---|
| 266 | + if (priv->rf_type == RF_AIROHA7230) |
|---|
| 267 | + addr[0xd7] = 0x06; |
|---|
| 406 | 268 | |
|---|
| 407 | 269 | priv->bb_vga[0] = 0x1c; |
|---|
| 408 | 270 | priv->bb_vga[1] = 0x10; |
|---|
| .. | .. |
|---|
| 410 | 272 | priv->bb_vga[3] = 0x0; |
|---|
| 411 | 273 | |
|---|
| 412 | 274 | } else if ((priv->rf_type == RF_VT3226) || |
|---|
| 413 | | - (priv->rf_type == RF_VT3226D0)) { |
|---|
| 275 | + (priv->rf_type == RF_VT3226D0) || |
|---|
| 276 | + (priv->rf_type == RF_VT3342A0)) { |
|---|
| 414 | 277 | priv->bb_rx_conf = vnt_vt3184_vt3226d0[10]; |
|---|
| 415 | 278 | length = sizeof(vnt_vt3184_vt3226d0); |
|---|
| 416 | | - addr = vnt_vt3184_vt3226d0; |
|---|
| 417 | | - agc = vnt_vt3184_agc; |
|---|
| 418 | | - length_agc = sizeof(vnt_vt3184_agc); |
|---|
| 279 | + c_addr = vnt_vt3184_vt3226d0; |
|---|
| 419 | 280 | |
|---|
| 420 | 281 | priv->bb_vga[0] = 0x20; |
|---|
| 421 | 282 | priv->bb_vga[1] = 0x10; |
|---|
| .. | .. |
|---|
| 423 | 284 | priv->bb_vga[3] = 0x0; |
|---|
| 424 | 285 | |
|---|
| 425 | 286 | /* Fix VT3226 DFC system timing issue */ |
|---|
| 426 | | - vnt_mac_reg_bits_on(priv, MAC_REG_SOFTPWRCTL2, |
|---|
| 427 | | - SOFTPWRCTL_RFLEOPT); |
|---|
| 428 | | - } else if (priv->rf_type == RF_VT3342A0) { |
|---|
| 429 | | - priv->bb_rx_conf = vnt_vt3184_vt3226d0[10]; |
|---|
| 430 | | - length = sizeof(vnt_vt3184_vt3226d0); |
|---|
| 431 | | - addr = vnt_vt3184_vt3226d0; |
|---|
| 432 | | - agc = vnt_vt3184_agc; |
|---|
| 433 | | - length_agc = sizeof(vnt_vt3184_agc); |
|---|
| 434 | | - |
|---|
| 435 | | - priv->bb_vga[0] = 0x20; |
|---|
| 436 | | - priv->bb_vga[1] = 0x10; |
|---|
| 437 | | - priv->bb_vga[2] = 0x0; |
|---|
| 438 | | - priv->bb_vga[3] = 0x0; |
|---|
| 439 | | - |
|---|
| 440 | | - /* Fix VT3226 DFC system timing issue */ |
|---|
| 441 | | - vnt_mac_reg_bits_on(priv, MAC_REG_SOFTPWRCTL2, |
|---|
| 442 | | - SOFTPWRCTL_RFLEOPT); |
|---|
| 287 | + ret = vnt_mac_reg_bits_on(priv, MAC_REG_SOFTPWRCTL2, |
|---|
| 288 | + SOFTPWRCTL_RFLEOPT); |
|---|
| 289 | + if (ret) |
|---|
| 290 | + goto end; |
|---|
| 443 | 291 | } else { |
|---|
| 444 | | - return true; |
|---|
| 292 | + goto end; |
|---|
| 445 | 293 | } |
|---|
| 446 | 294 | |
|---|
| 447 | | - memcpy(array, addr, length); |
|---|
| 295 | + if (addr) |
|---|
| 296 | + c_addr = addr; |
|---|
| 448 | 297 | |
|---|
| 449 | | - vnt_control_out(priv, MESSAGE_TYPE_WRITE, 0, |
|---|
| 450 | | - MESSAGE_REQUEST_BBREG, length, array); |
|---|
| 298 | + ret = vnt_control_out_blocks(priv, VNT_REG_BLOCK_SIZE, |
|---|
| 299 | + MESSAGE_REQUEST_BBREG, length, c_addr); |
|---|
| 300 | + if (ret) |
|---|
| 301 | + goto end; |
|---|
| 451 | 302 | |
|---|
| 452 | | - memcpy(array, agc, length_agc); |
|---|
| 453 | | - |
|---|
| 454 | | - vnt_control_out(priv, MESSAGE_TYPE_WRITE, 0, |
|---|
| 455 | | - MESSAGE_REQUEST_BBAGC, length_agc, array); |
|---|
| 303 | + ret = vnt_control_out(priv, MESSAGE_TYPE_WRITE, 0, |
|---|
| 304 | + MESSAGE_REQUEST_BBAGC, |
|---|
| 305 | + sizeof(vnt_vt3184_agc), vnt_vt3184_agc); |
|---|
| 306 | + if (ret) |
|---|
| 307 | + goto end; |
|---|
| 456 | 308 | |
|---|
| 457 | 309 | if ((priv->rf_type == RF_VT3226) || |
|---|
| 458 | | - (priv->rf_type == RF_VT3342A0)) { |
|---|
| 459 | | - vnt_control_out_u8(priv, MESSAGE_REQUEST_MACREG, |
|---|
| 460 | | - MAC_REG_ITRTMSET, 0x23); |
|---|
| 461 | | - vnt_mac_reg_bits_on(priv, MAC_REG_PAPEDELAY, 0x01); |
|---|
| 462 | | - } else if (priv->rf_type == RF_VT3226D0) { |
|---|
| 463 | | - vnt_control_out_u8(priv, MESSAGE_REQUEST_MACREG, |
|---|
| 464 | | - MAC_REG_ITRTMSET, 0x11); |
|---|
| 465 | | - vnt_mac_reg_bits_on(priv, MAC_REG_PAPEDELAY, 0x01); |
|---|
| 310 | + (priv->rf_type == RF_VT3342A0) || |
|---|
| 311 | + (priv->rf_type == RF_VT3226D0)) { |
|---|
| 312 | + data = (priv->rf_type == RF_VT3226D0) ? 0x11 : 0x23; |
|---|
| 313 | + |
|---|
| 314 | + ret = vnt_control_out_u8(priv, MESSAGE_REQUEST_MACREG, |
|---|
| 315 | + MAC_REG_ITRTMSET, data); |
|---|
| 316 | + if (ret) |
|---|
| 317 | + goto end; |
|---|
| 318 | + |
|---|
| 319 | + ret = vnt_mac_reg_bits_on(priv, MAC_REG_PAPEDELAY, BIT(0)); |
|---|
| 320 | + if (ret) |
|---|
| 321 | + goto end; |
|---|
| 466 | 322 | } |
|---|
| 467 | 323 | |
|---|
| 468 | | - vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x04, 0x7f); |
|---|
| 469 | | - vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0d, 0x01); |
|---|
| 324 | + ret = vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x04, 0x7f); |
|---|
| 325 | + if (ret) |
|---|
| 326 | + goto end; |
|---|
| 470 | 327 | |
|---|
| 471 | | - vnt_rf_table_download(priv); |
|---|
| 328 | + ret = vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0d, 0x01); |
|---|
| 329 | + if (ret) |
|---|
| 330 | + goto end; |
|---|
| 331 | + |
|---|
| 332 | + ret = vnt_rf_table_download(priv); |
|---|
| 333 | + if (ret) |
|---|
| 334 | + goto end; |
|---|
| 472 | 335 | |
|---|
| 473 | 336 | /* Fix for TX USB resets from vendors driver */ |
|---|
| 474 | | - vnt_control_in(priv, MESSAGE_TYPE_READ, USB_REG4, |
|---|
| 475 | | - MESSAGE_REQUEST_MEM, sizeof(data), &data); |
|---|
| 337 | + ret = vnt_control_in(priv, MESSAGE_TYPE_READ, USB_REG4, |
|---|
| 338 | + MESSAGE_REQUEST_MEM, sizeof(data), &data); |
|---|
| 339 | + if (ret) |
|---|
| 340 | + goto end; |
|---|
| 476 | 341 | |
|---|
| 477 | 342 | data |= 0x2; |
|---|
| 478 | 343 | |
|---|
| 479 | | - vnt_control_out(priv, MESSAGE_TYPE_WRITE, USB_REG4, |
|---|
| 480 | | - MESSAGE_REQUEST_MEM, sizeof(data), &data); |
|---|
| 344 | + ret = vnt_control_out(priv, MESSAGE_TYPE_WRITE, USB_REG4, |
|---|
| 345 | + MESSAGE_REQUEST_MEM, sizeof(data), &data); |
|---|
| 481 | 346 | |
|---|
| 482 | | - return true; |
|---|
| 347 | +end: |
|---|
| 348 | + return ret; |
|---|
| 483 | 349 | } |
|---|
| 484 | 350 | |
|---|
| 485 | 351 | /* |
|---|
| .. | .. |
|---|
| 494 | 360 | * Return Value: none |
|---|
| 495 | 361 | * |
|---|
| 496 | 362 | */ |
|---|
| 497 | | -void vnt_set_short_slot_time(struct vnt_private *priv) |
|---|
| 363 | +int vnt_set_short_slot_time(struct vnt_private *priv) |
|---|
| 498 | 364 | { |
|---|
| 365 | + int ret = 0; |
|---|
| 499 | 366 | u8 bb_vga = 0; |
|---|
| 500 | 367 | |
|---|
| 501 | 368 | if (priv->short_slot_time) |
|---|
| .. | .. |
|---|
| 503 | 370 | else |
|---|
| 504 | 371 | priv->bb_rx_conf |= 0x20; |
|---|
| 505 | 372 | |
|---|
| 506 | | - vnt_control_in_u8(priv, MESSAGE_REQUEST_BBREG, 0xe7, &bb_vga); |
|---|
| 373 | + ret = vnt_control_in_u8(priv, MESSAGE_REQUEST_BBREG, 0xe7, &bb_vga); |
|---|
| 374 | + if (ret) |
|---|
| 375 | + return ret; |
|---|
| 507 | 376 | |
|---|
| 508 | 377 | if (bb_vga == priv->bb_vga[0]) |
|---|
| 509 | 378 | priv->bb_rx_conf |= 0x20; |
|---|
| 510 | 379 | |
|---|
| 511 | | - vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0a, priv->bb_rx_conf); |
|---|
| 380 | + return vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0a, |
|---|
| 381 | + priv->bb_rx_conf); |
|---|
| 512 | 382 | } |
|---|
| 513 | 383 | |
|---|
| 514 | | -void vnt_set_vga_gain_offset(struct vnt_private *priv, u8 data) |
|---|
| 384 | +int vnt_set_vga_gain_offset(struct vnt_private *priv, u8 data) |
|---|
| 515 | 385 | { |
|---|
| 516 | | - vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0xE7, data); |
|---|
| 386 | + int ret; |
|---|
| 387 | + |
|---|
| 388 | + ret = vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0xE7, data); |
|---|
| 389 | + if (ret) |
|---|
| 390 | + return ret; |
|---|
| 517 | 391 | |
|---|
| 518 | 392 | /* patch for 3253B0 Baseband with Cardbus module */ |
|---|
| 519 | 393 | if (priv->short_slot_time) |
|---|
| .. | .. |
|---|
| 521 | 395 | else |
|---|
| 522 | 396 | priv->bb_rx_conf |= 0x20; /* 0010 0000 */ |
|---|
| 523 | 397 | |
|---|
| 524 | | - vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0a, priv->bb_rx_conf); |
|---|
| 398 | + return vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0a, |
|---|
| 399 | + priv->bb_rx_conf); |
|---|
| 525 | 400 | } |
|---|
| 526 | 401 | |
|---|
| 527 | 402 | /* |
|---|
| .. | .. |
|---|
| 536 | 411 | * Return Value: none |
|---|
| 537 | 412 | * |
|---|
| 538 | 413 | */ |
|---|
| 539 | | -void vnt_set_deep_sleep(struct vnt_private *priv) |
|---|
| 414 | +int vnt_set_deep_sleep(struct vnt_private *priv) |
|---|
| 540 | 415 | { |
|---|
| 541 | | - vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0c, 0x17);/* CR12 */ |
|---|
| 542 | | - vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0d, 0xB9);/* CR13 */ |
|---|
| 416 | + int ret = 0; |
|---|
| 417 | + |
|---|
| 418 | + /* CR12 */ |
|---|
| 419 | + ret = vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0c, 0x17); |
|---|
| 420 | + if (ret) |
|---|
| 421 | + return ret; |
|---|
| 422 | + |
|---|
| 423 | + /* CR13 */ |
|---|
| 424 | + return vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0d, 0xB9); |
|---|
| 543 | 425 | } |
|---|
| 544 | 426 | |
|---|
| 545 | | -void vnt_exit_deep_sleep(struct vnt_private *priv) |
|---|
| 427 | +int vnt_exit_deep_sleep(struct vnt_private *priv) |
|---|
| 546 | 428 | { |
|---|
| 547 | | - vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0c, 0x00);/* CR12 */ |
|---|
| 548 | | - vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0d, 0x01);/* CR13 */ |
|---|
| 429 | + int ret = 0; |
|---|
| 430 | + |
|---|
| 431 | + /* CR12 */ |
|---|
| 432 | + ret = vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0c, 0x00); |
|---|
| 433 | + if (ret) |
|---|
| 434 | + return ret; |
|---|
| 435 | + |
|---|
| 436 | + /* CR13 */ |
|---|
| 437 | + return vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0d, 0x01); |
|---|
| 549 | 438 | } |
|---|
| 550 | 439 | |
|---|
| 551 | | -void vnt_update_pre_ed_threshold(struct vnt_private *priv, int scanning) |
|---|
| 440 | +int vnt_update_pre_ed_threshold(struct vnt_private *priv, int scanning) |
|---|
| 552 | 441 | { |
|---|
| 553 | | - u8 cr_201 = 0x0, cr_206 = 0x0; |
|---|
| 554 | | - u8 ed_inx = priv->bb_pre_ed_index; |
|---|
| 442 | + const struct vnt_threshold *threshold = NULL; |
|---|
| 443 | + u8 length; |
|---|
| 444 | + u8 cr_201, cr_206; |
|---|
| 445 | + u8 ed_inx; |
|---|
| 446 | + int ret; |
|---|
| 555 | 447 | |
|---|
| 556 | 448 | switch (priv->rf_type) { |
|---|
| 557 | 449 | case RF_AL2230: |
|---|
| 558 | 450 | case RF_AL2230S: |
|---|
| 559 | 451 | case RF_AIROHA7230: |
|---|
| 560 | | - if (scanning) { /* Max sensitivity */ |
|---|
| 561 | | - ed_inx = 0; |
|---|
| 562 | | - cr_206 = 0x30; |
|---|
| 563 | | - break; |
|---|
| 564 | | - } |
|---|
| 565 | | - |
|---|
| 566 | | - if (priv->bb_pre_ed_rssi <= 45) { |
|---|
| 567 | | - ed_inx = 20; |
|---|
| 568 | | - cr_201 = 0xff; |
|---|
| 569 | | - } else if (priv->bb_pre_ed_rssi <= 46) { |
|---|
| 570 | | - ed_inx = 19; |
|---|
| 571 | | - cr_201 = 0x1a; |
|---|
| 572 | | - } else if (priv->bb_pre_ed_rssi <= 47) { |
|---|
| 573 | | - ed_inx = 18; |
|---|
| 574 | | - cr_201 = 0x15; |
|---|
| 575 | | - } else if (priv->bb_pre_ed_rssi <= 49) { |
|---|
| 576 | | - ed_inx = 17; |
|---|
| 577 | | - cr_201 = 0xe; |
|---|
| 578 | | - } else if (priv->bb_pre_ed_rssi <= 51) { |
|---|
| 579 | | - ed_inx = 16; |
|---|
| 580 | | - cr_201 = 0x9; |
|---|
| 581 | | - } else if (priv->bb_pre_ed_rssi <= 53) { |
|---|
| 582 | | - ed_inx = 15; |
|---|
| 583 | | - cr_201 = 0x6; |
|---|
| 584 | | - } else if (priv->bb_pre_ed_rssi <= 55) { |
|---|
| 585 | | - ed_inx = 14; |
|---|
| 586 | | - cr_201 = 0x3; |
|---|
| 587 | | - } else if (priv->bb_pre_ed_rssi <= 56) { |
|---|
| 588 | | - ed_inx = 13; |
|---|
| 589 | | - cr_201 = 0x2; |
|---|
| 590 | | - cr_206 = 0xa0; |
|---|
| 591 | | - } else if (priv->bb_pre_ed_rssi <= 57) { |
|---|
| 592 | | - ed_inx = 12; |
|---|
| 593 | | - cr_201 = 0x2; |
|---|
| 594 | | - cr_206 = 0x20; |
|---|
| 595 | | - } else if (priv->bb_pre_ed_rssi <= 58) { |
|---|
| 596 | | - ed_inx = 11; |
|---|
| 597 | | - cr_201 = 0x1; |
|---|
| 598 | | - cr_206 = 0xa0; |
|---|
| 599 | | - } else if (priv->bb_pre_ed_rssi <= 59) { |
|---|
| 600 | | - ed_inx = 10; |
|---|
| 601 | | - cr_201 = 0x1; |
|---|
| 602 | | - cr_206 = 0x54; |
|---|
| 603 | | - } else if (priv->bb_pre_ed_rssi <= 60) { |
|---|
| 604 | | - ed_inx = 9; |
|---|
| 605 | | - cr_201 = 0x1; |
|---|
| 606 | | - cr_206 = 0x18; |
|---|
| 607 | | - } else if (priv->bb_pre_ed_rssi <= 61) { |
|---|
| 608 | | - ed_inx = 8; |
|---|
| 609 | | - cr_206 = 0xe3; |
|---|
| 610 | | - } else if (priv->bb_pre_ed_rssi <= 62) { |
|---|
| 611 | | - ed_inx = 7; |
|---|
| 612 | | - cr_206 = 0xb9; |
|---|
| 613 | | - } else if (priv->bb_pre_ed_rssi <= 63) { |
|---|
| 614 | | - ed_inx = 6; |
|---|
| 615 | | - cr_206 = 0x93; |
|---|
| 616 | | - } else if (priv->bb_pre_ed_rssi <= 64) { |
|---|
| 617 | | - ed_inx = 5; |
|---|
| 618 | | - cr_206 = 0x79; |
|---|
| 619 | | - } else if (priv->bb_pre_ed_rssi <= 65) { |
|---|
| 620 | | - ed_inx = 4; |
|---|
| 621 | | - cr_206 = 0x62; |
|---|
| 622 | | - } else if (priv->bb_pre_ed_rssi <= 66) { |
|---|
| 623 | | - ed_inx = 3; |
|---|
| 624 | | - cr_206 = 0x51; |
|---|
| 625 | | - } else if (priv->bb_pre_ed_rssi <= 67) { |
|---|
| 626 | | - ed_inx = 2; |
|---|
| 627 | | - cr_206 = 0x43; |
|---|
| 628 | | - } else if (priv->bb_pre_ed_rssi <= 68) { |
|---|
| 629 | | - ed_inx = 1; |
|---|
| 630 | | - cr_206 = 0x36; |
|---|
| 631 | | - } else { |
|---|
| 632 | | - ed_inx = 0; |
|---|
| 633 | | - cr_206 = 0x30; |
|---|
| 634 | | - } |
|---|
| 452 | + threshold = al2230_vnt_threshold; |
|---|
| 453 | + length = ARRAY_SIZE(al2230_vnt_threshold); |
|---|
| 635 | 454 | break; |
|---|
| 636 | 455 | |
|---|
| 637 | 456 | case RF_VT3226: |
|---|
| 638 | 457 | case RF_VT3226D0: |
|---|
| 639 | | - if (scanning) { /* Max sensitivity */ |
|---|
| 640 | | - ed_inx = 0; |
|---|
| 641 | | - cr_206 = 0x24; |
|---|
| 642 | | - break; |
|---|
| 643 | | - } |
|---|
| 644 | | - |
|---|
| 645 | | - if (priv->bb_pre_ed_rssi <= 41) { |
|---|
| 646 | | - ed_inx = 22; |
|---|
| 647 | | - cr_201 = 0xff; |
|---|
| 648 | | - } else if (priv->bb_pre_ed_rssi <= 42) { |
|---|
| 649 | | - ed_inx = 21; |
|---|
| 650 | | - cr_201 = 0x36; |
|---|
| 651 | | - } else if (priv->bb_pre_ed_rssi <= 43) { |
|---|
| 652 | | - ed_inx = 20; |
|---|
| 653 | | - cr_201 = 0x26; |
|---|
| 654 | | - } else if (priv->bb_pre_ed_rssi <= 45) { |
|---|
| 655 | | - ed_inx = 19; |
|---|
| 656 | | - cr_201 = 0x18; |
|---|
| 657 | | - } else if (priv->bb_pre_ed_rssi <= 47) { |
|---|
| 658 | | - ed_inx = 18; |
|---|
| 659 | | - cr_201 = 0x11; |
|---|
| 660 | | - } else if (priv->bb_pre_ed_rssi <= 49) { |
|---|
| 661 | | - ed_inx = 17; |
|---|
| 662 | | - cr_201 = 0xa; |
|---|
| 663 | | - } else if (priv->bb_pre_ed_rssi <= 51) { |
|---|
| 664 | | - ed_inx = 16; |
|---|
| 665 | | - cr_201 = 0x7; |
|---|
| 666 | | - } else if (priv->bb_pre_ed_rssi <= 53) { |
|---|
| 667 | | - ed_inx = 15; |
|---|
| 668 | | - cr_201 = 0x4; |
|---|
| 669 | | - } else if (priv->bb_pre_ed_rssi <= 55) { |
|---|
| 670 | | - ed_inx = 14; |
|---|
| 671 | | - cr_201 = 0x2; |
|---|
| 672 | | - cr_206 = 0xc0; |
|---|
| 673 | | - } else if (priv->bb_pre_ed_rssi <= 56) { |
|---|
| 674 | | - ed_inx = 13; |
|---|
| 675 | | - cr_201 = 0x2; |
|---|
| 676 | | - cr_206 = 0x30; |
|---|
| 677 | | - } else if (priv->bb_pre_ed_rssi <= 57) { |
|---|
| 678 | | - ed_inx = 12; |
|---|
| 679 | | - cr_201 = 0x1; |
|---|
| 680 | | - cr_206 = 0xb0; |
|---|
| 681 | | - } else if (priv->bb_pre_ed_rssi <= 58) { |
|---|
| 682 | | - ed_inx = 11; |
|---|
| 683 | | - cr_201 = 0x1; |
|---|
| 684 | | - cr_206 = 0x70; |
|---|
| 685 | | - } else if (priv->bb_pre_ed_rssi <= 59) { |
|---|
| 686 | | - ed_inx = 10; |
|---|
| 687 | | - cr_201 = 0x1; |
|---|
| 688 | | - cr_206 = 0x30; |
|---|
| 689 | | - } else if (priv->bb_pre_ed_rssi <= 60) { |
|---|
| 690 | | - ed_inx = 9; |
|---|
| 691 | | - cr_206 = 0xea; |
|---|
| 692 | | - } else if (priv->bb_pre_ed_rssi <= 61) { |
|---|
| 693 | | - ed_inx = 8; |
|---|
| 694 | | - cr_206 = 0xc0; |
|---|
| 695 | | - } else if (priv->bb_pre_ed_rssi <= 62) { |
|---|
| 696 | | - ed_inx = 7; |
|---|
| 697 | | - cr_206 = 0x9c; |
|---|
| 698 | | - } else if (priv->bb_pre_ed_rssi <= 63) { |
|---|
| 699 | | - ed_inx = 6; |
|---|
| 700 | | - cr_206 = 0x80; |
|---|
| 701 | | - } else if (priv->bb_pre_ed_rssi <= 64) { |
|---|
| 702 | | - ed_inx = 5; |
|---|
| 703 | | - cr_206 = 0x68; |
|---|
| 704 | | - } else if (priv->bb_pre_ed_rssi <= 65) { |
|---|
| 705 | | - ed_inx = 4; |
|---|
| 706 | | - cr_206 = 0x52; |
|---|
| 707 | | - } else if (priv->bb_pre_ed_rssi <= 66) { |
|---|
| 708 | | - ed_inx = 3; |
|---|
| 709 | | - cr_206 = 0x43; |
|---|
| 710 | | - } else if (priv->bb_pre_ed_rssi <= 67) { |
|---|
| 711 | | - ed_inx = 2; |
|---|
| 712 | | - cr_206 = 0x36; |
|---|
| 713 | | - } else if (priv->bb_pre_ed_rssi <= 68) { |
|---|
| 714 | | - ed_inx = 1; |
|---|
| 715 | | - cr_206 = 0x2d; |
|---|
| 716 | | - } else { |
|---|
| 717 | | - ed_inx = 0; |
|---|
| 718 | | - cr_206 = 0x24; |
|---|
| 719 | | - } |
|---|
| 458 | + threshold = vt3226_vnt_threshold; |
|---|
| 459 | + length = ARRAY_SIZE(vt3226_vnt_threshold); |
|---|
| 720 | 460 | break; |
|---|
| 721 | 461 | |
|---|
| 722 | 462 | case RF_VT3342A0: |
|---|
| 723 | | - if (scanning) { /* need Max sensitivity */ |
|---|
| 724 | | - ed_inx = 0; |
|---|
| 725 | | - cr_206 = 0x38; |
|---|
| 726 | | - break; |
|---|
| 727 | | - } |
|---|
| 728 | | - |
|---|
| 729 | | - if (priv->bb_pre_ed_rssi <= 41) { |
|---|
| 730 | | - ed_inx = 20; |
|---|
| 731 | | - cr_201 = 0xff; |
|---|
| 732 | | - } else if (priv->bb_pre_ed_rssi <= 42) { |
|---|
| 733 | | - ed_inx = 19; |
|---|
| 734 | | - cr_201 = 0x36; |
|---|
| 735 | | - } else if (priv->bb_pre_ed_rssi <= 43) { |
|---|
| 736 | | - ed_inx = 18; |
|---|
| 737 | | - cr_201 = 0x26; |
|---|
| 738 | | - } else if (priv->bb_pre_ed_rssi <= 45) { |
|---|
| 739 | | - ed_inx = 17; |
|---|
| 740 | | - cr_201 = 0x18; |
|---|
| 741 | | - } else if (priv->bb_pre_ed_rssi <= 47) { |
|---|
| 742 | | - ed_inx = 16; |
|---|
| 743 | | - cr_201 = 0x11; |
|---|
| 744 | | - } else if (priv->bb_pre_ed_rssi <= 49) { |
|---|
| 745 | | - ed_inx = 15; |
|---|
| 746 | | - cr_201 = 0xa; |
|---|
| 747 | | - } else if (priv->bb_pre_ed_rssi <= 51) { |
|---|
| 748 | | - ed_inx = 14; |
|---|
| 749 | | - cr_201 = 0x7; |
|---|
| 750 | | - } else if (priv->bb_pre_ed_rssi <= 53) { |
|---|
| 751 | | - ed_inx = 13; |
|---|
| 752 | | - cr_201 = 0x4; |
|---|
| 753 | | - } else if (priv->bb_pre_ed_rssi <= 55) { |
|---|
| 754 | | - ed_inx = 12; |
|---|
| 755 | | - cr_201 = 0x2; |
|---|
| 756 | | - cr_206 = 0xc0; |
|---|
| 757 | | - } else if (priv->bb_pre_ed_rssi <= 56) { |
|---|
| 758 | | - ed_inx = 11; |
|---|
| 759 | | - cr_201 = 0x2; |
|---|
| 760 | | - cr_206 = 0x30; |
|---|
| 761 | | - } else if (priv->bb_pre_ed_rssi <= 57) { |
|---|
| 762 | | - ed_inx = 10; |
|---|
| 763 | | - cr_201 = 0x1; |
|---|
| 764 | | - cr_206 = 0xb0; |
|---|
| 765 | | - } else if (priv->bb_pre_ed_rssi <= 58) { |
|---|
| 766 | | - ed_inx = 9; |
|---|
| 767 | | - cr_201 = 0x1; |
|---|
| 768 | | - cr_206 = 0x70; |
|---|
| 769 | | - } else if (priv->bb_pre_ed_rssi <= 59) { |
|---|
| 770 | | - ed_inx = 8; |
|---|
| 771 | | - cr_201 = 0x1; |
|---|
| 772 | | - cr_206 = 0x30; |
|---|
| 773 | | - } else if (priv->bb_pre_ed_rssi <= 60) { |
|---|
| 774 | | - ed_inx = 7; |
|---|
| 775 | | - cr_206 = 0xea; |
|---|
| 776 | | - } else if (priv->bb_pre_ed_rssi <= 61) { |
|---|
| 777 | | - ed_inx = 6; |
|---|
| 778 | | - cr_206 = 0xc0; |
|---|
| 779 | | - } else if (priv->bb_pre_ed_rssi <= 62) { |
|---|
| 780 | | - ed_inx = 5; |
|---|
| 781 | | - cr_206 = 0x9c; |
|---|
| 782 | | - } else if (priv->bb_pre_ed_rssi <= 63) { |
|---|
| 783 | | - ed_inx = 4; |
|---|
| 784 | | - cr_206 = 0x80; |
|---|
| 785 | | - } else if (priv->bb_pre_ed_rssi <= 64) { |
|---|
| 786 | | - ed_inx = 3; |
|---|
| 787 | | - cr_206 = 0x68; |
|---|
| 788 | | - } else if (priv->bb_pre_ed_rssi <= 65) { |
|---|
| 789 | | - ed_inx = 2; |
|---|
| 790 | | - cr_206 = 0x52; |
|---|
| 791 | | - } else if (priv->bb_pre_ed_rssi <= 66) { |
|---|
| 792 | | - ed_inx = 1; |
|---|
| 793 | | - cr_206 = 0x43; |
|---|
| 794 | | - } else { |
|---|
| 795 | | - ed_inx = 0; |
|---|
| 796 | | - cr_206 = 0x38; |
|---|
| 797 | | - } |
|---|
| 463 | + threshold = vt3342_vnt_threshold; |
|---|
| 464 | + length = ARRAY_SIZE(vt3342_vnt_threshold); |
|---|
| 798 | 465 | break; |
|---|
| 799 | 466 | } |
|---|
| 800 | 467 | |
|---|
| 468 | + if (!threshold) |
|---|
| 469 | + return -EINVAL; |
|---|
| 470 | + |
|---|
| 471 | + for (ed_inx = scanning ? 0 : length - 1; ed_inx > 0; ed_inx--) { |
|---|
| 472 | + if (priv->bb_pre_ed_rssi <= threshold[ed_inx].bb_pre_ed_rssi) |
|---|
| 473 | + break; |
|---|
| 474 | + } |
|---|
| 475 | + |
|---|
| 476 | + cr_201 = threshold[ed_inx].cr_201; |
|---|
| 477 | + cr_206 = threshold[ed_inx].cr_206; |
|---|
| 478 | + |
|---|
| 801 | 479 | if (ed_inx == priv->bb_pre_ed_index && !scanning) |
|---|
| 802 | | - return; |
|---|
| 480 | + return 0; |
|---|
| 803 | 481 | |
|---|
| 804 | 482 | priv->bb_pre_ed_index = ed_inx; |
|---|
| 805 | 483 | |
|---|
| 806 | 484 | dev_dbg(&priv->usb->dev, "%s bb_pre_ed_rssi %d\n", |
|---|
| 807 | 485 | __func__, priv->bb_pre_ed_rssi); |
|---|
| 808 | 486 | |
|---|
| 809 | | - if (!cr_201 && !cr_206) |
|---|
| 810 | | - return; |
|---|
| 487 | + ret = vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0xc9, cr_201); |
|---|
| 488 | + if (ret) |
|---|
| 489 | + return ret; |
|---|
| 811 | 490 | |
|---|
| 812 | | - vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0xc9, cr_201); |
|---|
| 813 | | - vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0xce, cr_206); |
|---|
| 491 | + return vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0xce, cr_206); |
|---|
| 814 | 492 | } |
|---|
| 815 | 493 | |
|---|