linux/drivers/staging/rtl8723bs/hal/odm.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0
   2/******************************************************************************
   3 *
   4 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
   5 *
   6 ******************************************************************************/
   7
   8#include "odm_precomp.h"
   9
  10static const u16 dB_Invert_Table[8][12] = {
  11        {1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 4, 4},
  12        {4, 5, 6, 6, 7, 8, 9, 10, 11, 13, 14, 16},
  13        {18, 20, 22, 25, 28, 32, 35, 40, 45, 50, 56, 63},
  14        {71, 79, 89, 100, 112, 126, 141, 158, 178, 200, 224, 251},
  15        {282, 316, 355, 398, 447, 501, 562, 631, 708, 794, 891, 1000},
  16        {1122, 1259, 1413, 1585, 1778, 1995, 2239, 2512, 2818, 3162, 3548, 3981},
  17        {4467, 5012, 5623, 6310, 7079, 7943, 8913, 10000, 11220, 12589, 14125,
  18         15849},
  19        {17783, 19953, 22387, 25119, 28184, 31623, 35481, 39811, 44668, 50119,
  20         56234, 65535}
  21 };
  22
  23/*  Global var */
  24
  25u32 OFDMSwingTable[OFDM_TABLE_SIZE] = {
  26        0x7f8001fe, /*  0, +6.0dB */
  27        0x788001e2, /*  1, +5.5dB */
  28        0x71c001c7, /*  2, +5.0dB */
  29        0x6b8001ae, /*  3, +4.5dB */
  30        0x65400195, /*  4, +4.0dB */
  31        0x5fc0017f, /*  5, +3.5dB */
  32        0x5a400169, /*  6, +3.0dB */
  33        0x55400155, /*  7, +2.5dB */
  34        0x50800142, /*  8, +2.0dB */
  35        0x4c000130, /*  9, +1.5dB */
  36        0x47c0011f, /*  10, +1.0dB */
  37        0x43c0010f, /*  11, +0.5dB */
  38        0x40000100, /*  12, +0dB */
  39        0x3c8000f2, /*  13, -0.5dB */
  40        0x390000e4, /*  14, -1.0dB */
  41        0x35c000d7, /*  15, -1.5dB */
  42        0x32c000cb, /*  16, -2.0dB */
  43        0x300000c0, /*  17, -2.5dB */
  44        0x2d4000b5, /*  18, -3.0dB */
  45        0x2ac000ab, /*  19, -3.5dB */
  46        0x288000a2, /*  20, -4.0dB */
  47        0x26000098, /*  21, -4.5dB */
  48        0x24000090, /*  22, -5.0dB */
  49        0x22000088, /*  23, -5.5dB */
  50        0x20000080, /*  24, -6.0dB */
  51        0x1e400079, /*  25, -6.5dB */
  52        0x1c800072, /*  26, -7.0dB */
  53        0x1b00006c, /*  27. -7.5dB */
  54        0x19800066, /*  28, -8.0dB */
  55        0x18000060, /*  29, -8.5dB */
  56        0x16c0005b, /*  30, -9.0dB */
  57        0x15800056, /*  31, -9.5dB */
  58        0x14400051, /*  32, -10.0dB */
  59        0x1300004c, /*  33, -10.5dB */
  60        0x12000048, /*  34, -11.0dB */
  61        0x11000044, /*  35, -11.5dB */
  62        0x10000040, /*  36, -12.0dB */
  63};
  64
  65u8 CCKSwingTable_Ch1_Ch13[CCK_TABLE_SIZE][8] = {
  66        {0x36, 0x35, 0x2e, 0x25, 0x1c, 0x12, 0x09, 0x04}, /*  0, +0dB */
  67        {0x33, 0x32, 0x2b, 0x23, 0x1a, 0x11, 0x08, 0x04}, /*  1, -0.5dB */
  68        {0x30, 0x2f, 0x29, 0x21, 0x19, 0x10, 0x08, 0x03}, /*  2, -1.0dB */
  69        {0x2d, 0x2d, 0x27, 0x1f, 0x18, 0x0f, 0x08, 0x03}, /*  3, -1.5dB */
  70        {0x2b, 0x2a, 0x25, 0x1e, 0x16, 0x0e, 0x07, 0x03}, /*  4, -2.0dB */
  71        {0x28, 0x28, 0x22, 0x1c, 0x15, 0x0d, 0x07, 0x03}, /*  5, -2.5dB */
  72        {0x26, 0x25, 0x21, 0x1b, 0x14, 0x0d, 0x06, 0x03}, /*  6, -3.0dB */
  73        {0x24, 0x23, 0x1f, 0x19, 0x13, 0x0c, 0x06, 0x03}, /*  7, -3.5dB */
  74        {0x22, 0x21, 0x1d, 0x18, 0x11, 0x0b, 0x06, 0x02}, /*  8, -4.0dB */
  75        {0x20, 0x20, 0x1b, 0x16, 0x11, 0x08, 0x05, 0x02}, /*  9, -4.5dB */
  76        {0x1f, 0x1e, 0x1a, 0x15, 0x10, 0x0a, 0x05, 0x02}, /*  10, -5.0dB */
  77        {0x1d, 0x1c, 0x18, 0x14, 0x0f, 0x0a, 0x05, 0x02}, /*  11, -5.5dB */
  78        {0x1b, 0x1a, 0x17, 0x13, 0x0e, 0x09, 0x04, 0x02}, /*  12, -6.0dB <== default */
  79        {0x1a, 0x19, 0x16, 0x12, 0x0d, 0x09, 0x04, 0x02}, /*  13, -6.5dB */
  80        {0x18, 0x17, 0x15, 0x11, 0x0c, 0x08, 0x04, 0x02}, /*  14, -7.0dB */
  81        {0x17, 0x16, 0x13, 0x10, 0x0c, 0x08, 0x04, 0x02}, /*  15, -7.5dB */
  82        {0x16, 0x15, 0x12, 0x0f, 0x0b, 0x07, 0x04, 0x01}, /*  16, -8.0dB */
  83        {0x14, 0x14, 0x11, 0x0e, 0x0b, 0x07, 0x03, 0x02}, /*  17, -8.5dB */
  84        {0x13, 0x13, 0x10, 0x0d, 0x0a, 0x06, 0x03, 0x01}, /*  18, -9.0dB */
  85        {0x12, 0x12, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01}, /*  19, -9.5dB */
  86        {0x11, 0x11, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01}, /*  20, -10.0dB */
  87        {0x10, 0x10, 0x0e, 0x0b, 0x08, 0x05, 0x03, 0x01}, /*  21, -10.5dB */
  88        {0x0f, 0x0f, 0x0d, 0x0b, 0x08, 0x05, 0x03, 0x01}, /*  22, -11.0dB */
  89        {0x0e, 0x0e, 0x0c, 0x0a, 0x08, 0x05, 0x02, 0x01}, /*  23, -11.5dB */
  90        {0x0d, 0x0d, 0x0c, 0x0a, 0x07, 0x05, 0x02, 0x01}, /*  24, -12.0dB */
  91        {0x0d, 0x0c, 0x0b, 0x09, 0x07, 0x04, 0x02, 0x01}, /*  25, -12.5dB */
  92        {0x0c, 0x0c, 0x0a, 0x09, 0x06, 0x04, 0x02, 0x01}, /*  26, -13.0dB */
  93        {0x0b, 0x0b, 0x0a, 0x08, 0x06, 0x04, 0x02, 0x01}, /*  27, -13.5dB */
  94        {0x0b, 0x0a, 0x09, 0x08, 0x06, 0x04, 0x02, 0x01}, /*  28, -14.0dB */
  95        {0x0a, 0x0a, 0x09, 0x07, 0x05, 0x03, 0x02, 0x01}, /*  29, -14.5dB */
  96        {0x0a, 0x09, 0x08, 0x07, 0x05, 0x03, 0x02, 0x01}, /*  30, -15.0dB */
  97        {0x09, 0x09, 0x08, 0x06, 0x05, 0x03, 0x01, 0x01}, /*  31, -15.5dB */
  98        {0x09, 0x08, 0x07, 0x06, 0x04, 0x03, 0x01, 0x01}        /*  32, -16.0dB */
  99};
 100
 101u8 CCKSwingTable_Ch14[CCK_TABLE_SIZE][8] = {
 102        {0x36, 0x35, 0x2e, 0x1b, 0x00, 0x00, 0x00, 0x00}, /*  0, +0dB */
 103        {0x33, 0x32, 0x2b, 0x19, 0x00, 0x00, 0x00, 0x00}, /*  1, -0.5dB */
 104        {0x30, 0x2f, 0x29, 0x18, 0x00, 0x00, 0x00, 0x00}, /*  2, -1.0dB */
 105        {0x2d, 0x2d, 0x17, 0x17, 0x00, 0x00, 0x00, 0x00}, /*  3, -1.5dB */
 106        {0x2b, 0x2a, 0x25, 0x15, 0x00, 0x00, 0x00, 0x00}, /*  4, -2.0dB */
 107        {0x28, 0x28, 0x24, 0x14, 0x00, 0x00, 0x00, 0x00}, /*  5, -2.5dB */
 108        {0x26, 0x25, 0x21, 0x13, 0x00, 0x00, 0x00, 0x00}, /*  6, -3.0dB */
 109        {0x24, 0x23, 0x1f, 0x12, 0x00, 0x00, 0x00, 0x00}, /*  7, -3.5dB */
 110        {0x22, 0x21, 0x1d, 0x11, 0x00, 0x00, 0x00, 0x00}, /*  8, -4.0dB */
 111        {0x20, 0x20, 0x1b, 0x10, 0x00, 0x00, 0x00, 0x00}, /*  9, -4.5dB */
 112        {0x1f, 0x1e, 0x1a, 0x0f, 0x00, 0x00, 0x00, 0x00}, /*  10, -5.0dB */
 113        {0x1d, 0x1c, 0x18, 0x0e, 0x00, 0x00, 0x00, 0x00}, /*  11, -5.5dB */
 114        {0x1b, 0x1a, 0x17, 0x0e, 0x00, 0x00, 0x00, 0x00}, /*  12, -6.0dB  <== default */
 115        {0x1a, 0x19, 0x16, 0x0d, 0x00, 0x00, 0x00, 0x00}, /*  13, -6.5dB */
 116        {0x18, 0x17, 0x15, 0x0c, 0x00, 0x00, 0x00, 0x00}, /*  14, -7.0dB */
 117        {0x17, 0x16, 0x13, 0x0b, 0x00, 0x00, 0x00, 0x00}, /*  15, -7.5dB */
 118        {0x16, 0x15, 0x12, 0x0b, 0x00, 0x00, 0x00, 0x00}, /*  16, -8.0dB */
 119        {0x14, 0x14, 0x11, 0x0a, 0x00, 0x00, 0x00, 0x00}, /*  17, -8.5dB */
 120        {0x13, 0x13, 0x10, 0x0a, 0x00, 0x00, 0x00, 0x00}, /*  18, -9.0dB */
 121        {0x12, 0x12, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00}, /*  19, -9.5dB */
 122        {0x11, 0x11, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00}, /*  20, -10.0dB */
 123        {0x10, 0x10, 0x0e, 0x08, 0x00, 0x00, 0x00, 0x00}, /*  21, -10.5dB */
 124        {0x0f, 0x0f, 0x0d, 0x08, 0x00, 0x00, 0x00, 0x00}, /*  22, -11.0dB */
 125        {0x0e, 0x0e, 0x0c, 0x07, 0x00, 0x00, 0x00, 0x00}, /*  23, -11.5dB */
 126        {0x0d, 0x0d, 0x0c, 0x07, 0x00, 0x00, 0x00, 0x00}, /*  24, -12.0dB */
 127        {0x0d, 0x0c, 0x0b, 0x06, 0x00, 0x00, 0x00, 0x00}, /*  25, -12.5dB */
 128        {0x0c, 0x0c, 0x0a, 0x06, 0x00, 0x00, 0x00, 0x00}, /*  26, -13.0dB */
 129        {0x0b, 0x0b, 0x0a, 0x06, 0x00, 0x00, 0x00, 0x00}, /*  27, -13.5dB */
 130        {0x0b, 0x0a, 0x09, 0x05, 0x00, 0x00, 0x00, 0x00}, /*  28, -14.0dB */
 131        {0x0a, 0x0a, 0x09, 0x05, 0x00, 0x00, 0x00, 0x00}, /*  29, -14.5dB */
 132        {0x0a, 0x09, 0x08, 0x05, 0x00, 0x00, 0x00, 0x00}, /*  30, -15.0dB */
 133        {0x09, 0x09, 0x08, 0x05, 0x00, 0x00, 0x00, 0x00}, /*  31, -15.5dB */
 134        {0x09, 0x08, 0x07, 0x04, 0x00, 0x00, 0x00, 0x00}        /*  32, -16.0dB */
 135};
 136
 137u32 OFDMSwingTable_New[OFDM_TABLE_SIZE] = {
 138        0x0b40002d, /*  0,  -15.0dB */
 139        0x0c000030, /*  1,  -14.5dB */
 140        0x0cc00033, /*  2,  -14.0dB */
 141        0x0d800036, /*  3,  -13.5dB */
 142        0x0e400039, /*  4,  -13.0dB */
 143        0x0f00003c, /*  5,  -12.5dB */
 144        0x10000040, /*  6,  -12.0dB */
 145        0x11000044, /*  7,  -11.5dB */
 146        0x12000048, /*  8,  -11.0dB */
 147        0x1300004c, /*  9,  -10.5dB */
 148        0x14400051, /*  10, -10.0dB */
 149        0x15800056, /*  11, -9.5dB */
 150        0x16c0005b, /*  12, -9.0dB */
 151        0x18000060, /*  13, -8.5dB */
 152        0x19800066, /*  14, -8.0dB */
 153        0x1b00006c, /*  15, -7.5dB */
 154        0x1c800072, /*  16, -7.0dB */
 155        0x1e400079, /*  17, -6.5dB */
 156        0x20000080, /*  18, -6.0dB */
 157        0x22000088, /*  19, -5.5dB */
 158        0x24000090, /*  20, -5.0dB */
 159        0x26000098, /*  21, -4.5dB */
 160        0x288000a2, /*  22, -4.0dB */
 161        0x2ac000ab, /*  23, -3.5dB */
 162        0x2d4000b5, /*  24, -3.0dB */
 163        0x300000c0, /*  25, -2.5dB */
 164        0x32c000cb, /*  26, -2.0dB */
 165        0x35c000d7, /*  27, -1.5dB */
 166        0x390000e4, /*  28, -1.0dB */
 167        0x3c8000f2, /*  29, -0.5dB */
 168        0x40000100, /*  30, +0dB */
 169        0x43c0010f, /*  31, +0.5dB */
 170        0x47c0011f, /*  32, +1.0dB */
 171        0x4c000130, /*  33, +1.5dB */
 172        0x50800142, /*  34, +2.0dB */
 173        0x55400155, /*  35, +2.5dB */
 174        0x5a400169, /*  36, +3.0dB */
 175        0x5fc0017f, /*  37, +3.5dB */
 176        0x65400195, /*  38, +4.0dB */
 177        0x6b8001ae, /*  39, +4.5dB */
 178        0x71c001c7, /*  40, +5.0dB */
 179        0x788001e2, /*  41, +5.5dB */
 180        0x7f8001fe  /*  42, +6.0dB */
 181};
 182
 183u8 CCKSwingTable_Ch1_Ch13_New[CCK_TABLE_SIZE][8] = {
 184        {0x09, 0x08, 0x07, 0x06, 0x04, 0x03, 0x01, 0x01}, /*   0, -16.0dB */
 185        {0x09, 0x09, 0x08, 0x06, 0x05, 0x03, 0x01, 0x01}, /*   1, -15.5dB */
 186        {0x0a, 0x09, 0x08, 0x07, 0x05, 0x03, 0x02, 0x01}, /*   2, -15.0dB */
 187        {0x0a, 0x0a, 0x09, 0x07, 0x05, 0x03, 0x02, 0x01}, /*   3, -14.5dB */
 188        {0x0b, 0x0a, 0x09, 0x08, 0x06, 0x04, 0x02, 0x01}, /*   4, -14.0dB */
 189        {0x0b, 0x0b, 0x0a, 0x08, 0x06, 0x04, 0x02, 0x01}, /*   5, -13.5dB */
 190        {0x0c, 0x0c, 0x0a, 0x09, 0x06, 0x04, 0x02, 0x01}, /*   6, -13.0dB */
 191        {0x0d, 0x0c, 0x0b, 0x09, 0x07, 0x04, 0x02, 0x01}, /*   7, -12.5dB */
 192        {0x0d, 0x0d, 0x0c, 0x0a, 0x07, 0x05, 0x02, 0x01}, /*   8, -12.0dB */
 193        {0x0e, 0x0e, 0x0c, 0x0a, 0x08, 0x05, 0x02, 0x01}, /*   9, -11.5dB */
 194        {0x0f, 0x0f, 0x0d, 0x0b, 0x08, 0x05, 0x03, 0x01}, /*  10, -11.0dB */
 195        {0x10, 0x10, 0x0e, 0x0b, 0x08, 0x05, 0x03, 0x01}, /*  11, -10.5dB */
 196        {0x11, 0x11, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01}, /*  12, -10.0dB */
 197        {0x12, 0x12, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01}, /*  13, -9.5dB */
 198        {0x13, 0x13, 0x10, 0x0d, 0x0a, 0x06, 0x03, 0x01}, /*  14, -9.0dB */
 199        {0x14, 0x14, 0x11, 0x0e, 0x0b, 0x07, 0x03, 0x02}, /*  15, -8.5dB */
 200        {0x16, 0x15, 0x12, 0x0f, 0x0b, 0x07, 0x04, 0x01}, /*  16, -8.0dB */
 201        {0x17, 0x16, 0x13, 0x10, 0x0c, 0x08, 0x04, 0x02}, /*  17, -7.5dB */
 202        {0x18, 0x17, 0x15, 0x11, 0x0c, 0x08, 0x04, 0x02}, /*  18, -7.0dB */
 203        {0x1a, 0x19, 0x16, 0x12, 0x0d, 0x09, 0x04, 0x02}, /*  19, -6.5dB */
 204        {0x1b, 0x1a, 0x17, 0x13, 0x0e, 0x09, 0x04, 0x02}, /*  20, -6.0dB */
 205        {0x1d, 0x1c, 0x18, 0x14, 0x0f, 0x0a, 0x05, 0x02}, /*  21, -5.5dB */
 206        {0x1f, 0x1e, 0x1a, 0x15, 0x10, 0x0a, 0x05, 0x02}, /*  22, -5.0dB */
 207        {0x20, 0x20, 0x1b, 0x16, 0x11, 0x08, 0x05, 0x02}, /*  23, -4.5dB */
 208        {0x22, 0x21, 0x1d, 0x18, 0x11, 0x0b, 0x06, 0x02}, /*  24, -4.0dB */
 209        {0x24, 0x23, 0x1f, 0x19, 0x13, 0x0c, 0x06, 0x03}, /*  25, -3.5dB */
 210        {0x26, 0x25, 0x21, 0x1b, 0x14, 0x0d, 0x06, 0x03}, /*  26, -3.0dB */
 211        {0x28, 0x28, 0x22, 0x1c, 0x15, 0x0d, 0x07, 0x03}, /*  27, -2.5dB */
 212        {0x2b, 0x2a, 0x25, 0x1e, 0x16, 0x0e, 0x07, 0x03}, /*  28, -2.0dB */
 213        {0x2d, 0x2d, 0x27, 0x1f, 0x18, 0x0f, 0x08, 0x03}, /*  29, -1.5dB */
 214        {0x30, 0x2f, 0x29, 0x21, 0x19, 0x10, 0x08, 0x03}, /*  30, -1.0dB */
 215        {0x33, 0x32, 0x2b, 0x23, 0x1a, 0x11, 0x08, 0x04}, /*  31, -0.5dB */
 216        {0x36, 0x35, 0x2e, 0x25, 0x1c, 0x12, 0x09, 0x04}        /*  32, +0dB */
 217};
 218
 219u8 CCKSwingTable_Ch14_New[CCK_TABLE_SIZE][8] = {
 220        {0x09, 0x08, 0x07, 0x04, 0x00, 0x00, 0x00, 0x00}, /*   0, -16.0dB */
 221        {0x09, 0x09, 0x08, 0x05, 0x00, 0x00, 0x00, 0x00}, /*   1, -15.5dB */
 222        {0x0a, 0x09, 0x08, 0x05, 0x00, 0x00, 0x00, 0x00}, /*   2, -15.0dB */
 223        {0x0a, 0x0a, 0x09, 0x05, 0x00, 0x00, 0x00, 0x00}, /*   3, -14.5dB */
 224        {0x0b, 0x0a, 0x09, 0x05, 0x00, 0x00, 0x00, 0x00}, /*   4, -14.0dB */
 225        {0x0b, 0x0b, 0x0a, 0x06, 0x00, 0x00, 0x00, 0x00}, /*   5, -13.5dB */
 226        {0x0c, 0x0c, 0x0a, 0x06, 0x00, 0x00, 0x00, 0x00}, /*   6, -13.0dB */
 227        {0x0d, 0x0c, 0x0b, 0x06, 0x00, 0x00, 0x00, 0x00}, /*   7, -12.5dB */
 228        {0x0d, 0x0d, 0x0c, 0x07, 0x00, 0x00, 0x00, 0x00}, /*   8, -12.0dB */
 229        {0x0e, 0x0e, 0x0c, 0x07, 0x00, 0x00, 0x00, 0x00}, /*   9, -11.5dB */
 230        {0x0f, 0x0f, 0x0d, 0x08, 0x00, 0x00, 0x00, 0x00}, /*  10, -11.0dB */
 231        {0x10, 0x10, 0x0e, 0x08, 0x00, 0x00, 0x00, 0x00}, /*  11, -10.5dB */
 232        {0x11, 0x11, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00}, /*  12, -10.0dB */
 233        {0x12, 0x12, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00}, /*  13, -9.5dB */
 234        {0x13, 0x13, 0x10, 0x0a, 0x00, 0x00, 0x00, 0x00}, /*  14, -9.0dB */
 235        {0x14, 0x14, 0x11, 0x0a, 0x00, 0x00, 0x00, 0x00}, /*  15, -8.5dB */
 236        {0x16, 0x15, 0x12, 0x0b, 0x00, 0x00, 0x00, 0x00}, /*  16, -8.0dB */
 237        {0x17, 0x16, 0x13, 0x0b, 0x00, 0x00, 0x00, 0x00}, /*  17, -7.5dB */
 238        {0x18, 0x17, 0x15, 0x0c, 0x00, 0x00, 0x00, 0x00}, /*  18, -7.0dB */
 239        {0x1a, 0x19, 0x16, 0x0d, 0x00, 0x00, 0x00, 0x00}, /*  19, -6.5dB */
 240        {0x1b, 0x1a, 0x17, 0x0e, 0x00, 0x00, 0x00, 0x00}, /*  20, -6.0dB */
 241        {0x1d, 0x1c, 0x18, 0x0e, 0x00, 0x00, 0x00, 0x00}, /*  21, -5.5dB */
 242        {0x1f, 0x1e, 0x1a, 0x0f, 0x00, 0x00, 0x00, 0x00}, /*  22, -5.0dB */
 243        {0x20, 0x20, 0x1b, 0x10, 0x00, 0x00, 0x00, 0x00}, /*  23, -4.5dB */
 244        {0x22, 0x21, 0x1d, 0x11, 0x00, 0x00, 0x00, 0x00}, /*  24, -4.0dB */
 245        {0x24, 0x23, 0x1f, 0x12, 0x00, 0x00, 0x00, 0x00}, /*  25, -3.5dB */
 246        {0x26, 0x25, 0x21, 0x13, 0x00, 0x00, 0x00, 0x00}, /*  26, -3.0dB */
 247        {0x28, 0x28, 0x24, 0x14, 0x00, 0x00, 0x00, 0x00}, /*  27, -2.5dB */
 248        {0x2b, 0x2a, 0x25, 0x15, 0x00, 0x00, 0x00, 0x00}, /*  28, -2.0dB */
 249        {0x2d, 0x2d, 0x17, 0x17, 0x00, 0x00, 0x00, 0x00}, /*  29, -1.5dB */
 250        {0x30, 0x2f, 0x29, 0x18, 0x00, 0x00, 0x00, 0x00}, /*  30, -1.0dB */
 251        {0x33, 0x32, 0x2b, 0x19, 0x00, 0x00, 0x00, 0x00}, /*  31, -0.5dB */
 252        {0x36, 0x35, 0x2e, 0x1b, 0x00, 0x00, 0x00, 0x00}        /*  32, +0dB */
 253};
 254
 255u32 TxScalingTable_Jaguar[TXSCALE_TABLE_SIZE] = {
 256        0x081, /*  0,  -12.0dB */
 257        0x088, /*  1,  -11.5dB */
 258        0x090, /*  2,  -11.0dB */
 259        0x099, /*  3,  -10.5dB */
 260        0x0A2, /*  4,  -10.0dB */
 261        0x0AC, /*  5,  -9.5dB */
 262        0x0B6, /*  6,  -9.0dB */
 263        0x0C0, /*  7,  -8.5dB */
 264        0x0CC, /*  8,  -8.0dB */
 265        0x0D8, /*  9,  -7.5dB */
 266        0x0E5, /*  10, -7.0dB */
 267        0x0F2, /*  11, -6.5dB */
 268        0x101, /*  12, -6.0dB */
 269        0x110, /*  13, -5.5dB */
 270        0x120, /*  14, -5.0dB */
 271        0x131, /*  15, -4.5dB */
 272        0x143, /*  16, -4.0dB */
 273        0x156, /*  17, -3.5dB */
 274        0x16A, /*  18, -3.0dB */
 275        0x180, /*  19, -2.5dB */
 276        0x197, /*  20, -2.0dB */
 277        0x1AF, /*  21, -1.5dB */
 278        0x1C8, /*  22, -1.0dB */
 279        0x1E3, /*  23, -0.5dB */
 280        0x200, /*  24, +0  dB */
 281        0x21E, /*  25, +0.5dB */
 282        0x23E, /*  26, +1.0dB */
 283        0x261, /*  27, +1.5dB */
 284        0x285, /*  28, +2.0dB */
 285        0x2AB, /*  29, +2.5dB */
 286        0x2D3, /*  30, +3.0dB */
 287        0x2FE, /*  31, +3.5dB */
 288        0x32B, /*  32, +4.0dB */
 289        0x35C, /*  33, +4.5dB */
 290        0x38E, /*  34, +5.0dB */
 291        0x3C4, /*  35, +5.5dB */
 292        0x3FE  /*  36, +6.0dB */
 293};
 294
 295/*  Local Function predefine. */
 296
 297/* START------------COMMON INFO RELATED--------------- */
 298void odm_CommonInfoSelfInit(PDM_ODM_T pDM_Odm);
 299
 300void odm_CommonInfoSelfUpdate(PDM_ODM_T pDM_Odm);
 301
 302void odm_CmnInfoInit_Debug(PDM_ODM_T pDM_Odm);
 303
 304void odm_BasicDbgMessage(PDM_ODM_T pDM_Odm);
 305
 306/* END------------COMMON INFO RELATED--------------- */
 307
 308/* START---------------DIG--------------------------- */
 309
 310/* Remove by Yuchen */
 311
 312/* END---------------DIG--------------------------- */
 313
 314/* START-------BB POWER SAVE----------------------- */
 315/* Remove BB power Saving by YuChen */
 316/* END---------BB POWER SAVE----------------------- */
 317
 318void odm_RefreshRateAdaptiveMaskCE(PDM_ODM_T pDM_Odm);
 319
 320/* Remove by YuChen */
 321
 322void odm_RSSIMonitorInit(PDM_ODM_T pDM_Odm);
 323
 324void odm_RSSIMonitorCheckCE(PDM_ODM_T pDM_Odm);
 325
 326void odm_RSSIMonitorCheck(PDM_ODM_T pDM_Odm);
 327
 328void odm_SwAntDetectInit(PDM_ODM_T pDM_Odm);
 329
 330void odm_SwAntDivChkAntSwitchCallback(void *FunctionContext);
 331
 332
 333
 334void odm_GlobalAdapterCheck(void);
 335
 336void odm_RefreshRateAdaptiveMask(PDM_ODM_T pDM_Odm);
 337
 338void ODM_TXPowerTrackingCheck(PDM_ODM_T pDM_Odm);
 339
 340void odm_RateAdaptiveMaskInit(PDM_ODM_T pDM_Odm);
 341
 342void odm_TXPowerTrackingThermalMeterInit(PDM_ODM_T pDM_Odm);
 343
 344
 345void odm_TXPowerTrackingInit(PDM_ODM_T pDM_Odm);
 346
 347void odm_TXPowerTrackingCheckCE(PDM_ODM_T pDM_Odm);
 348
 349/* Remove Edca by Yu Chen */
 350
 351
 352#define RxDefaultAnt1           0x65a9
 353#define RxDefaultAnt2           0x569a
 354
 355void odm_InitHybridAntDiv(PDM_ODM_T pDM_Odm);
 356
 357bool odm_StaDefAntSel(
 358        PDM_ODM_T pDM_Odm,
 359        u32 OFDM_Ant1_Cnt,
 360        u32 OFDM_Ant2_Cnt,
 361        u32 CCK_Ant1_Cnt,
 362        u32 CCK_Ant2_Cnt,
 363        u8 *pDefAnt
 364);
 365
 366void odm_SetRxIdleAnt(PDM_ODM_T pDM_Odm, u8 Ant, bool bDualPath);
 367
 368
 369
 370void odm_HwAntDiv(PDM_ODM_T pDM_Odm);
 371
 372
 373/*  */
 374/* 3 Export Interface */
 375/*  */
 376
 377/*  */
 378/*  2011/09/21 MH Add to describe different team necessary resource allocate?? */
 379/*  */
 380void ODM_DMInit(PDM_ODM_T pDM_Odm)
 381{
 382
 383        odm_CommonInfoSelfInit(pDM_Odm);
 384        odm_CmnInfoInit_Debug(pDM_Odm);
 385        odm_DIGInit(pDM_Odm);
 386        odm_NHMCounterStatisticsInit(pDM_Odm);
 387        odm_AdaptivityInit(pDM_Odm);
 388        odm_RateAdaptiveMaskInit(pDM_Odm);
 389        ODM_CfoTrackingInit(pDM_Odm);
 390        ODM_EdcaTurboInit(pDM_Odm);
 391        odm_RSSIMonitorInit(pDM_Odm);
 392        odm_TXPowerTrackingInit(pDM_Odm);
 393
 394        ODM_ClearTxPowerTrackingState(pDM_Odm);
 395
 396        if (*(pDM_Odm->mp_mode) != 1)
 397                odm_PathDiversityInit(pDM_Odm);
 398
 399        odm_DynamicBBPowerSavingInit(pDM_Odm);
 400        odm_DynamicTxPowerInit(pDM_Odm);
 401
 402        odm_SwAntDetectInit(pDM_Odm);
 403}
 404
 405/*  */
 406/*  2011/09/20 MH This is the entry pointer for all team to execute HW out source DM. */
 407/*  You can not add any dummy function here, be care, you can only use DM structure */
 408/*  to perform any new ODM_DM. */
 409/*  */
 410void ODM_DMWatchdog(PDM_ODM_T pDM_Odm)
 411{
 412        odm_CommonInfoSelfUpdate(pDM_Odm);
 413        odm_BasicDbgMessage(pDM_Odm);
 414        odm_FalseAlarmCounterStatistics(pDM_Odm);
 415        odm_NHMCounterStatistics(pDM_Odm);
 416        ODM_RT_TRACE(pDM_Odm, ODM_COMP_DIG, ODM_DBG_LOUD, ("odm_DIG(): RSSI = 0x%x\n", pDM_Odm->RSSI_Min));
 417
 418        odm_RSSIMonitorCheck(pDM_Odm);
 419
 420        /* For CE Platform(SPRD or Tablet) */
 421        /* 8723A or 8189ES platform */
 422        /* NeilChen--2012--08--24-- */
 423        /* Fix Leave LPS issue */
 424        if ((adapter_to_pwrctl(pDM_Odm->Adapter)->pwr_mode != PS_MODE_ACTIVE) /*  in LPS mode */
 425                /*  */
 426                /* (pDM_Odm->SupportICType & (ODM_RTL8723A))|| */
 427                /* (pDM_Odm->SupportICType & (ODM_RTL8188E) &&(&&(((pDM_Odm->SupportInterface  == ODM_ITRF_SDIO))) */
 428                /*  */
 429        ) {
 430                        ODM_RT_TRACE(pDM_Odm, ODM_COMP_DIG, ODM_DBG_LOUD, ("----Step1: odm_DIG is in LPS mode\n"));
 431                        ODM_RT_TRACE(pDM_Odm, ODM_COMP_DIG, ODM_DBG_LOUD, ("---Step2: 8723AS is in LPS mode\n"));
 432                        odm_DIGbyRSSI_LPS(pDM_Odm);
 433        } else
 434                odm_DIG(pDM_Odm);
 435
 436        {
 437                pDIG_T pDM_DigTable = &pDM_Odm->DM_DigTable;
 438
 439                odm_Adaptivity(pDM_Odm, pDM_DigTable->CurIGValue);
 440        }
 441        odm_CCKPacketDetectionThresh(pDM_Odm);
 442
 443        if (*(pDM_Odm->pbPowerSaving) == true)
 444                return;
 445
 446
 447        odm_RefreshRateAdaptiveMask(pDM_Odm);
 448        odm_EdcaTurboCheck(pDM_Odm);
 449        odm_PathDiversity(pDM_Odm);
 450        ODM_CfoTracking(pDM_Odm);
 451
 452        ODM_TXPowerTrackingCheck(pDM_Odm);
 453
 454        /* odm_EdcaTurboCheck(pDM_Odm); */
 455
 456        /* 2010.05.30 LukeLee: For CE platform, files in IC subfolders may not be included to be compiled, */
 457        /*  so compile flags must be left here to prevent from compile errors */
 458        pDM_Odm->PhyDbgInfo.NumQryBeaconPkt = 0;
 459}
 460
 461
 462/*  */
 463/*  Init /.. Fixed HW value. Only init time. */
 464/*  */
 465void ODM_CmnInfoInit(PDM_ODM_T pDM_Odm, ODM_CMNINFO_E CmnInfo, u32 Value)
 466{
 467        /*  */
 468        /*  This section is used for init value */
 469        /*  */
 470        switch (CmnInfo) {
 471        /*  */
 472        /*  Fixed ODM value. */
 473        /*  */
 474        case ODM_CMNINFO_ABILITY:
 475                pDM_Odm->SupportAbility = (u32)Value;
 476                break;
 477
 478        case ODM_CMNINFO_RF_TYPE:
 479                pDM_Odm->RFType = (u8)Value;
 480                break;
 481
 482        case ODM_CMNINFO_PLATFORM:
 483                pDM_Odm->SupportPlatform = (u8)Value;
 484                break;
 485
 486        case ODM_CMNINFO_INTERFACE:
 487                pDM_Odm->SupportInterface = (u8)Value;
 488                break;
 489
 490        case ODM_CMNINFO_MP_TEST_CHIP:
 491                pDM_Odm->bIsMPChip = (u8)Value;
 492                break;
 493
 494        case ODM_CMNINFO_IC_TYPE:
 495                pDM_Odm->SupportICType = Value;
 496                break;
 497
 498        case ODM_CMNINFO_CUT_VER:
 499                pDM_Odm->CutVersion = (u8)Value;
 500                break;
 501
 502        case ODM_CMNINFO_FAB_VER:
 503                pDM_Odm->FabVersion = (u8)Value;
 504                break;
 505
 506        case ODM_CMNINFO_RFE_TYPE:
 507                pDM_Odm->RFEType = (u8)Value;
 508                break;
 509
 510        case    ODM_CMNINFO_RF_ANTENNA_TYPE:
 511                pDM_Odm->AntDivType = (u8)Value;
 512                break;
 513
 514        case ODM_CMNINFO_BOARD_TYPE:
 515                pDM_Odm->BoardType = (u8)Value;
 516                break;
 517
 518        case ODM_CMNINFO_PACKAGE_TYPE:
 519                pDM_Odm->PackageType = (u8)Value;
 520                break;
 521
 522        case ODM_CMNINFO_EXT_LNA:
 523                pDM_Odm->ExtLNA = (u8)Value;
 524                break;
 525
 526        case ODM_CMNINFO_5G_EXT_LNA:
 527                pDM_Odm->ExtLNA5G = (u8)Value;
 528                break;
 529
 530        case ODM_CMNINFO_EXT_PA:
 531                pDM_Odm->ExtPA = (u8)Value;
 532                break;
 533
 534        case ODM_CMNINFO_5G_EXT_PA:
 535                pDM_Odm->ExtPA5G = (u8)Value;
 536                break;
 537
 538        case ODM_CMNINFO_GPA:
 539                pDM_Odm->TypeGPA = (ODM_TYPE_GPA_E)Value;
 540                break;
 541        case ODM_CMNINFO_APA:
 542                pDM_Odm->TypeAPA = (ODM_TYPE_APA_E)Value;
 543                break;
 544        case ODM_CMNINFO_GLNA:
 545                pDM_Odm->TypeGLNA = (ODM_TYPE_GLNA_E)Value;
 546                break;
 547        case ODM_CMNINFO_ALNA:
 548                pDM_Odm->TypeALNA = (ODM_TYPE_ALNA_E)Value;
 549                break;
 550
 551        case ODM_CMNINFO_EXT_TRSW:
 552                pDM_Odm->ExtTRSW = (u8)Value;
 553                break;
 554        case ODM_CMNINFO_PATCH_ID:
 555                pDM_Odm->PatchID = (u8)Value;
 556                break;
 557        case ODM_CMNINFO_BINHCT_TEST:
 558                pDM_Odm->bInHctTest = (bool)Value;
 559                break;
 560        case ODM_CMNINFO_BWIFI_TEST:
 561                pDM_Odm->bWIFITest = (bool)Value;
 562                break;
 563
 564        case ODM_CMNINFO_SMART_CONCURRENT:
 565                pDM_Odm->bDualMacSmartConcurrent = (bool)Value;
 566                break;
 567
 568        /* To remove the compiler warning, must add an empty default statement to handle the other values. */
 569        default:
 570                /* do nothing */
 571                break;
 572        }
 573
 574}
 575
 576
 577void ODM_CmnInfoHook(PDM_ODM_T pDM_Odm, ODM_CMNINFO_E CmnInfo, void *pValue)
 578{
 579        /*  */
 580        /*  Hook call by reference pointer. */
 581        /*  */
 582        switch (CmnInfo) {
 583        /*  */
 584        /*  Dynamic call by reference pointer. */
 585        /*  */
 586        case ODM_CMNINFO_MAC_PHY_MODE:
 587                pDM_Odm->pMacPhyMode = pValue;
 588                break;
 589
 590        case ODM_CMNINFO_TX_UNI:
 591                pDM_Odm->pNumTxBytesUnicast = pValue;
 592                break;
 593
 594        case ODM_CMNINFO_RX_UNI:
 595                pDM_Odm->pNumRxBytesUnicast = pValue;
 596                break;
 597
 598        case ODM_CMNINFO_WM_MODE:
 599                pDM_Odm->pwirelessmode = pValue;
 600                break;
 601
 602        case ODM_CMNINFO_BAND:
 603                pDM_Odm->pBandType = pValue;
 604                break;
 605
 606        case ODM_CMNINFO_SEC_CHNL_OFFSET:
 607                pDM_Odm->pSecChOffset = pValue;
 608                break;
 609
 610        case ODM_CMNINFO_SEC_MODE:
 611                pDM_Odm->pSecurity = pValue;
 612                break;
 613
 614        case ODM_CMNINFO_BW:
 615                pDM_Odm->pBandWidth = pValue;
 616                break;
 617
 618        case ODM_CMNINFO_CHNL:
 619                pDM_Odm->pChannel = pValue;
 620                break;
 621
 622        case ODM_CMNINFO_DMSP_GET_VALUE:
 623                pDM_Odm->pbGetValueFromOtherMac = pValue;
 624                break;
 625
 626        case ODM_CMNINFO_BUDDY_ADAPTOR:
 627                pDM_Odm->pBuddyAdapter = pValue;
 628                break;
 629
 630        case ODM_CMNINFO_DMSP_IS_MASTER:
 631                pDM_Odm->pbMasterOfDMSP = pValue;
 632                break;
 633
 634        case ODM_CMNINFO_SCAN:
 635                pDM_Odm->pbScanInProcess = pValue;
 636                break;
 637
 638        case ODM_CMNINFO_POWER_SAVING:
 639                pDM_Odm->pbPowerSaving = pValue;
 640                break;
 641
 642        case ODM_CMNINFO_ONE_PATH_CCA:
 643                pDM_Odm->pOnePathCCA = pValue;
 644                break;
 645
 646        case ODM_CMNINFO_DRV_STOP:
 647                pDM_Odm->pbDriverStopped =  pValue;
 648                break;
 649
 650        case ODM_CMNINFO_PNP_IN:
 651                pDM_Odm->pbDriverIsGoingToPnpSetPowerSleep =  pValue;
 652                break;
 653
 654        case ODM_CMNINFO_INIT_ON:
 655                pDM_Odm->pinit_adpt_in_progress =  pValue;
 656                break;
 657
 658        case ODM_CMNINFO_ANT_TEST:
 659                pDM_Odm->pAntennaTest =  pValue;
 660                break;
 661
 662        case ODM_CMNINFO_NET_CLOSED:
 663                pDM_Odm->pbNet_closed = pValue;
 664                break;
 665
 666        case ODM_CMNINFO_FORCED_RATE:
 667                pDM_Odm->pForcedDataRate = pValue;
 668                break;
 669
 670        case ODM_CMNINFO_FORCED_IGI_LB:
 671                pDM_Odm->pu1ForcedIgiLb = pValue;
 672                break;
 673
 674        case ODM_CMNINFO_MP_MODE:
 675                pDM_Odm->mp_mode = pValue;
 676                break;
 677
 678        /* case ODM_CMNINFO_RTSTA_AID: */
 679        /* pDM_Odm->pAidMap =  (u8 *)pValue; */
 680        /* break; */
 681
 682        /* case ODM_CMNINFO_BT_COEXIST: */
 683        /* pDM_Odm->BTCoexist = (bool *)pValue; */
 684
 685        /* case ODM_CMNINFO_STA_STATUS: */
 686        /* pDM_Odm->pODM_StaInfo[] = (PSTA_INFO_T)pValue; */
 687        /* break; */
 688
 689        /* case ODM_CMNINFO_PHY_STATUS: */
 690        /* pDM_Odm->pPhyInfo = (ODM_PHY_INFO *)pValue; */
 691        /* break; */
 692
 693        /* case ODM_CMNINFO_MAC_STATUS: */
 694        /* pDM_Odm->pMacInfo = (ODM_MAC_INFO *)pValue; */
 695        /* break; */
 696        /* To remove the compiler warning, must add an empty default statement to handle the other values. */
 697        default:
 698                /* do nothing */
 699                break;
 700        }
 701
 702}
 703
 704
 705void ODM_CmnInfoPtrArrayHook(
 706        PDM_ODM_T pDM_Odm,
 707        ODM_CMNINFO_E CmnInfo,
 708        u16 Index,
 709        void *pValue
 710)
 711{
 712        /*  */
 713        /*  Hook call by reference pointer. */
 714        /*  */
 715        switch (CmnInfo) {
 716        /*  */
 717        /*  Dynamic call by reference pointer. */
 718        /*  */
 719        case ODM_CMNINFO_STA_STATUS:
 720                pDM_Odm->pODM_StaInfo[Index] = (PSTA_INFO_T)pValue;
 721                break;
 722        /* To remove the compiler warning, must add an empty default statement to handle the other values. */
 723        default:
 724                /* do nothing */
 725                break;
 726        }
 727
 728}
 729
 730
 731/*  */
 732/*  Update Band/CHannel/.. The values are dynamic but non-per-packet. */
 733/*  */
 734void ODM_CmnInfoUpdate(PDM_ODM_T pDM_Odm, u32 CmnInfo, u64 Value)
 735{
 736        /*  */
 737        /*  This init variable may be changed in run time. */
 738        /*  */
 739        switch (CmnInfo) {
 740        case ODM_CMNINFO_LINK_IN_PROGRESS:
 741                pDM_Odm->bLinkInProcess = (bool)Value;
 742                break;
 743
 744        case ODM_CMNINFO_ABILITY:
 745                pDM_Odm->SupportAbility = (u32)Value;
 746                break;
 747
 748        case ODM_CMNINFO_RF_TYPE:
 749                pDM_Odm->RFType = (u8)Value;
 750                break;
 751
 752        case ODM_CMNINFO_WIFI_DIRECT:
 753                pDM_Odm->bWIFI_Direct = (bool)Value;
 754                break;
 755
 756        case ODM_CMNINFO_WIFI_DISPLAY:
 757                pDM_Odm->bWIFI_Display = (bool)Value;
 758                break;
 759
 760        case ODM_CMNINFO_LINK:
 761                pDM_Odm->bLinked = (bool)Value;
 762                break;
 763
 764        case ODM_CMNINFO_STATION_STATE:
 765                pDM_Odm->bsta_state = (bool)Value;
 766                break;
 767
 768        case ODM_CMNINFO_RSSI_MIN:
 769                pDM_Odm->RSSI_Min = (u8)Value;
 770                break;
 771
 772        case ODM_CMNINFO_DBG_COMP:
 773                pDM_Odm->DebugComponents = Value;
 774                break;
 775
 776        case ODM_CMNINFO_DBG_LEVEL:
 777                pDM_Odm->DebugLevel = (u32)Value;
 778                break;
 779        case ODM_CMNINFO_RA_THRESHOLD_HIGH:
 780                pDM_Odm->RateAdaptive.HighRSSIThresh = (u8)Value;
 781                break;
 782
 783        case ODM_CMNINFO_RA_THRESHOLD_LOW:
 784                pDM_Odm->RateAdaptive.LowRSSIThresh = (u8)Value;
 785                break;
 786        /*  The following is for BT HS mode and BT coexist mechanism. */
 787        case ODM_CMNINFO_BT_ENABLED:
 788                pDM_Odm->bBtEnabled = (bool)Value;
 789                break;
 790
 791        case ODM_CMNINFO_BT_HS_CONNECT_PROCESS:
 792                pDM_Odm->bBtConnectProcess = (bool)Value;
 793                break;
 794
 795        case ODM_CMNINFO_BT_HS_RSSI:
 796                pDM_Odm->btHsRssi = (u8)Value;
 797                break;
 798
 799        case ODM_CMNINFO_BT_OPERATION:
 800                pDM_Odm->bBtHsOperation = (bool)Value;
 801                break;
 802
 803        case ODM_CMNINFO_BT_LIMITED_DIG:
 804                pDM_Odm->bBtLimitedDig = (bool)Value;
 805                break;
 806
 807        case ODM_CMNINFO_BT_DISABLE_EDCA:
 808                pDM_Odm->bBtDisableEdcaTurbo = (bool)Value;
 809                break;
 810
 811/*
 812        case    ODM_CMNINFO_OP_MODE:
 813                pDM_Odm->OPMode = (u8)Value;
 814                break;
 815
 816        case    ODM_CMNINFO_WM_MODE:
 817                pDM_Odm->WirelessMode = (u8)Value;
 818                break;
 819
 820        case    ODM_CMNINFO_BAND:
 821                pDM_Odm->BandType = (u8)Value;
 822                break;
 823
 824        case    ODM_CMNINFO_SEC_CHNL_OFFSET:
 825                pDM_Odm->SecChOffset = (u8)Value;
 826                break;
 827
 828        case    ODM_CMNINFO_SEC_MODE:
 829                pDM_Odm->Security = (u8)Value;
 830                break;
 831
 832        case    ODM_CMNINFO_BW:
 833                pDM_Odm->BandWidth = (u8)Value;
 834                break;
 835
 836        case    ODM_CMNINFO_CHNL:
 837                pDM_Odm->Channel = (u8)Value;
 838                break;
 839*/
 840        default:
 841                /* do nothing */
 842                break;
 843        }
 844
 845
 846}
 847
 848void odm_CommonInfoSelfInit(PDM_ODM_T pDM_Odm)
 849{
 850        pDM_Odm->bCckHighPower = (bool) PHY_QueryBBReg(pDM_Odm->Adapter, ODM_REG(CCK_RPT_FORMAT, pDM_Odm), ODM_BIT(CCK_RPT_FORMAT, pDM_Odm));
 851        pDM_Odm->RFPathRxEnable = (u8) PHY_QueryBBReg(pDM_Odm->Adapter, ODM_REG(BB_RX_PATH, pDM_Odm), ODM_BIT(BB_RX_PATH, pDM_Odm));
 852
 853        ODM_InitDebugSetting(pDM_Odm);
 854
 855        pDM_Odm->TxRate = 0xFF;
 856}
 857
 858void odm_CommonInfoSelfUpdate(PDM_ODM_T pDM_Odm)
 859{
 860        u8 EntryCnt = 0;
 861        u8 i;
 862        PSTA_INFO_T     pEntry;
 863
 864        if (*(pDM_Odm->pBandWidth) == ODM_BW40M) {
 865                if (*(pDM_Odm->pSecChOffset) == 1)
 866                        pDM_Odm->ControlChannel = *(pDM_Odm->pChannel)-2;
 867                else if (*(pDM_Odm->pSecChOffset) == 2)
 868                        pDM_Odm->ControlChannel = *(pDM_Odm->pChannel)+2;
 869        } else
 870                pDM_Odm->ControlChannel = *(pDM_Odm->pChannel);
 871
 872        for (i = 0; i < ODM_ASSOCIATE_ENTRY_NUM; i++) {
 873                pEntry = pDM_Odm->pODM_StaInfo[i];
 874                if (IS_STA_VALID(pEntry))
 875                        EntryCnt++;
 876        }
 877
 878        if (EntryCnt == 1)
 879                pDM_Odm->bOneEntryOnly = true;
 880        else
 881                pDM_Odm->bOneEntryOnly = false;
 882}
 883
 884void odm_CmnInfoInit_Debug(PDM_ODM_T pDM_Odm)
 885{
 886        ODM_RT_TRACE(pDM_Odm, ODM_COMP_COMMON, ODM_DBG_LOUD, ("odm_CmnInfoInit_Debug ==>\n"));
 887        ODM_RT_TRACE(pDM_Odm, ODM_COMP_COMMON, ODM_DBG_LOUD, ("SupportPlatform =%d\n", pDM_Odm->SupportPlatform));
 888        ODM_RT_TRACE(pDM_Odm, ODM_COMP_COMMON, ODM_DBG_LOUD, ("SupportAbility = 0x%x\n", pDM_Odm->SupportAbility));
 889        ODM_RT_TRACE(pDM_Odm, ODM_COMP_COMMON, ODM_DBG_LOUD, ("SupportInterface =%d\n", pDM_Odm->SupportInterface));
 890        ODM_RT_TRACE(pDM_Odm, ODM_COMP_COMMON, ODM_DBG_LOUD, ("SupportICType = 0x%x\n", pDM_Odm->SupportICType));
 891        ODM_RT_TRACE(pDM_Odm, ODM_COMP_COMMON, ODM_DBG_LOUD, ("CutVersion =%d\n", pDM_Odm->CutVersion));
 892        ODM_RT_TRACE(pDM_Odm, ODM_COMP_COMMON, ODM_DBG_LOUD, ("FabVersion =%d\n", pDM_Odm->FabVersion));
 893        ODM_RT_TRACE(pDM_Odm, ODM_COMP_COMMON, ODM_DBG_LOUD, ("RFType =%d\n", pDM_Odm->RFType));
 894        ODM_RT_TRACE(pDM_Odm, ODM_COMP_COMMON, ODM_DBG_LOUD, ("BoardType =%d\n", pDM_Odm->BoardType));
 895        ODM_RT_TRACE(pDM_Odm, ODM_COMP_COMMON, ODM_DBG_LOUD, ("ExtLNA =%d\n", pDM_Odm->ExtLNA));
 896        ODM_RT_TRACE(pDM_Odm, ODM_COMP_COMMON, ODM_DBG_LOUD, ("ExtPA =%d\n", pDM_Odm->ExtPA));
 897        ODM_RT_TRACE(pDM_Odm, ODM_COMP_COMMON, ODM_DBG_LOUD, ("ExtTRSW =%d\n", pDM_Odm->ExtTRSW));
 898        ODM_RT_TRACE(pDM_Odm, ODM_COMP_COMMON, ODM_DBG_LOUD, ("PatchID =%d\n", pDM_Odm->PatchID));
 899        ODM_RT_TRACE(pDM_Odm, ODM_COMP_COMMON, ODM_DBG_LOUD, ("bInHctTest =%d\n", pDM_Odm->bInHctTest));
 900        ODM_RT_TRACE(pDM_Odm, ODM_COMP_COMMON, ODM_DBG_LOUD, ("bWIFITest =%d\n", pDM_Odm->bWIFITest));
 901        ODM_RT_TRACE(pDM_Odm, ODM_COMP_COMMON, ODM_DBG_LOUD, ("bDualMacSmartConcurrent =%d\n", pDM_Odm->bDualMacSmartConcurrent));
 902
 903}
 904
 905void odm_BasicDbgMessage(PDM_ODM_T pDM_Odm)
 906{
 907        ODM_RT_TRACE(pDM_Odm, ODM_COMP_COMMON, ODM_DBG_LOUD, ("odm_BasicDbgMsg ==>\n"));
 908        ODM_RT_TRACE(pDM_Odm, ODM_COMP_COMMON, ODM_DBG_LOUD, ("bLinked = %d, RSSI_Min = %d,\n",
 909                pDM_Odm->bLinked, pDM_Odm->RSSI_Min));
 910        ODM_RT_TRACE(pDM_Odm, ODM_COMP_COMMON, ODM_DBG_LOUD, ("RxRate = 0x%x, RSSI_A = %d, RSSI_B = %d\n",
 911                pDM_Odm->RxRate, pDM_Odm->RSSI_A, pDM_Odm->RSSI_B));
 912}
 913
 914/* 3 ============================================================ */
 915/* 3 DIG */
 916/* 3 ============================================================ */
 917/*-----------------------------------------------------------------------------
 918 * Function:    odm_DIGInit()
 919 *
 920 * Overview:    Set DIG scheme init value.
 921 *
 922 * Input:               NONE
 923 *
 924 * Output:              NONE
 925 *
 926 * Return:              NONE
 927 *
 928 * Revised History:
 929 *When          Who             Remark
 930 *
 931 *---------------------------------------------------------------------------
 932 */
 933
 934/* Remove DIG by yuchen */
 935
 936/* Remove DIG and FA check by Yu Chen */
 937
 938
 939/* 3 ============================================================ */
 940/* 3 BB Power Save */
 941/* 3 ============================================================ */
 942
 943/* Remove BB power saving by Yuchen */
 944
 945/* 3 ============================================================ */
 946/* 3 RATR MASK */
 947/* 3 ============================================================ */
 948/* 3 ============================================================ */
 949/* 3 Rate Adaptive */
 950/* 3 ============================================================ */
 951
 952void odm_RateAdaptiveMaskInit(PDM_ODM_T pDM_Odm)
 953{
 954        PODM_RATE_ADAPTIVE pOdmRA = &pDM_Odm->RateAdaptive;
 955
 956        pOdmRA->Type = DM_Type_ByDriver;
 957        if (pOdmRA->Type == DM_Type_ByDriver)
 958                pDM_Odm->bUseRAMask = true;
 959        else
 960                pDM_Odm->bUseRAMask = false;
 961
 962        pOdmRA->RATRState = DM_RATR_STA_INIT;
 963        pOdmRA->LdpcThres = 35;
 964        pOdmRA->bUseLdpc = false;
 965        pOdmRA->HighRSSIThresh = 50;
 966        pOdmRA->LowRSSIThresh = 20;
 967}
 968
 969u32 ODM_Get_Rate_Bitmap(
 970        PDM_ODM_T pDM_Odm,
 971        u32 macid,
 972        u32 ra_mask,
 973        u8 rssi_level
 974)
 975{
 976        PSTA_INFO_T     pEntry;
 977        u32 rate_bitmap = 0;
 978        u8 WirelessMode;
 979
 980        pEntry = pDM_Odm->pODM_StaInfo[macid];
 981        if (!IS_STA_VALID(pEntry))
 982                return ra_mask;
 983
 984        WirelessMode = pEntry->wireless_mode;
 985
 986        switch (WirelessMode) {
 987        case ODM_WM_B:
 988                if (ra_mask & 0x0000000c)               /* 11M or 5.5M enable */
 989                        rate_bitmap = 0x0000000d;
 990                else
 991                        rate_bitmap = 0x0000000f;
 992                break;
 993
 994        case (ODM_WM_G):
 995        case (ODM_WM_A):
 996                if (rssi_level == DM_RATR_STA_HIGH)
 997                        rate_bitmap = 0x00000f00;
 998                else
 999                        rate_bitmap = 0x00000ff0;
1000                break;
1001
1002        case (ODM_WM_B|ODM_WM_G):
1003                if (rssi_level == DM_RATR_STA_HIGH)
1004                        rate_bitmap = 0x00000f00;
1005                else if (rssi_level == DM_RATR_STA_MIDDLE)
1006                        rate_bitmap = 0x00000ff0;
1007                else
1008                        rate_bitmap = 0x00000ff5;
1009                break;
1010
1011        case (ODM_WM_B|ODM_WM_G|ODM_WM_N24G):
1012        case (ODM_WM_B|ODM_WM_N24G):
1013        case (ODM_WM_G|ODM_WM_N24G):
1014        case (ODM_WM_A|ODM_WM_N5G):
1015                if (pDM_Odm->RFType == ODM_1T2R || pDM_Odm->RFType == ODM_1T1R) {
1016                        if (rssi_level == DM_RATR_STA_HIGH)
1017                                rate_bitmap = 0x000f0000;
1018                        else if (rssi_level == DM_RATR_STA_MIDDLE)
1019                                rate_bitmap = 0x000ff000;
1020                        else {
1021                                if (*(pDM_Odm->pBandWidth) == ODM_BW40M)
1022                                        rate_bitmap = 0x000ff015;
1023                                else
1024                                        rate_bitmap = 0x000ff005;
1025                        }
1026                } else {
1027                        if (rssi_level == DM_RATR_STA_HIGH)
1028                                rate_bitmap = 0x0f8f0000;
1029                        else if (rssi_level == DM_RATR_STA_MIDDLE)
1030                                rate_bitmap = 0x0f8ff000;
1031                        else {
1032                                if (*(pDM_Odm->pBandWidth) == ODM_BW40M)
1033                                        rate_bitmap = 0x0f8ff015;
1034                                else
1035                                        rate_bitmap = 0x0f8ff005;
1036                        }
1037                }
1038                break;
1039
1040        case (ODM_WM_AC|ODM_WM_G):
1041                if (rssi_level == 1)
1042                        rate_bitmap = 0xfc3f0000;
1043                else if (rssi_level == 2)
1044                        rate_bitmap = 0xfffff000;
1045                else
1046                        rate_bitmap = 0xffffffff;
1047                break;
1048
1049        case (ODM_WM_AC|ODM_WM_A):
1050
1051                if (pDM_Odm->RFType == RF_1T1R) {
1052                        if (rssi_level == 1)                            /*  add by Gary for ac-series */
1053                                rate_bitmap = 0x003f8000;
1054                        else if (rssi_level == 2)
1055                                rate_bitmap = 0x003ff000;
1056                        else
1057                                rate_bitmap = 0x003ff010;
1058                } else {
1059                        if (rssi_level == 1)                            /*  add by Gary for ac-series */
1060                                rate_bitmap = 0xfe3f8000;       /*  VHT 2SS MCS3~9 */
1061                        else if (rssi_level == 2)
1062                                rate_bitmap = 0xfffff000;       /*  VHT 2SS MCS0~9 */
1063                        else
1064                                rate_bitmap = 0xfffff010;       /*  All */
1065                }
1066                break;
1067
1068        default:
1069                if (pDM_Odm->RFType == RF_1T2R)
1070                        rate_bitmap = 0x000fffff;
1071                else
1072                        rate_bitmap = 0x0fffffff;
1073                break;
1074        }
1075
1076        /* printk("%s ==> rssi_level:0x%02x, WirelessMode:0x%02x, rate_bitmap:0x%08x\n", __func__, rssi_level, WirelessMode, rate_bitmap); */
1077        ODM_RT_TRACE(pDM_Odm, ODM_COMP_RA_MASK, ODM_DBG_LOUD, (" ==> rssi_level:0x%02x, WirelessMode:0x%02x, rate_bitmap:0x%08x\n", rssi_level, WirelessMode, rate_bitmap));
1078
1079        return (ra_mask&rate_bitmap);
1080
1081}
1082
1083/*-----------------------------------------------------------------------------
1084* Function:     odm_RefreshRateAdaptiveMask()
1085*
1086* Overview:     Update rate table mask according to rssi
1087*
1088* Input:                NONE
1089*
1090* Output:               NONE
1091*
1092* Return:               NONE
1093*
1094* Revised History:
1095*When           Who             Remark
1096*05/27/2009     hpfan   Create Version 0.
1097*
1098* --------------------------------------------------------------------------
1099*/
1100void odm_RefreshRateAdaptiveMask(PDM_ODM_T pDM_Odm)
1101{
1102
1103        ODM_RT_TRACE(pDM_Odm, ODM_COMP_RA_MASK, ODM_DBG_TRACE, ("odm_RefreshRateAdaptiveMask()---------->\n"));
1104        if (!(pDM_Odm->SupportAbility & ODM_BB_RA_MASK)) {
1105                ODM_RT_TRACE(pDM_Odm, ODM_COMP_RA_MASK, ODM_DBG_TRACE, ("odm_RefreshRateAdaptiveMask(): Return cos not supported\n"));
1106                return;
1107        }
1108        odm_RefreshRateAdaptiveMaskCE(pDM_Odm);
1109}
1110
1111void odm_RefreshRateAdaptiveMaskCE(PDM_ODM_T pDM_Odm)
1112{
1113        u8 i;
1114        struct adapter *padapter =  pDM_Odm->Adapter;
1115
1116        if (padapter->bDriverStopped) {
1117                ODM_RT_TRACE(pDM_Odm, ODM_COMP_RA_MASK, ODM_DBG_TRACE, ("<---- odm_RefreshRateAdaptiveMask(): driver is going to unload\n"));
1118                return;
1119        }
1120
1121        if (!pDM_Odm->bUseRAMask) {
1122                ODM_RT_TRACE(pDM_Odm, ODM_COMP_RA_MASK, ODM_DBG_LOUD, ("<---- odm_RefreshRateAdaptiveMask(): driver does not control rate adaptive mask\n"));
1123                return;
1124        }
1125
1126        /* printk("==> %s\n", __func__); */
1127
1128        for (i = 0; i < ODM_ASSOCIATE_ENTRY_NUM; i++) {
1129                PSTA_INFO_T pstat = pDM_Odm->pODM_StaInfo[i];
1130
1131                if (IS_STA_VALID(pstat)) {
1132                        if (IS_MCAST(pstat->hwaddr))  /* if (psta->mac_id == 1) */
1133                                continue;
1134                        if (IS_MCAST(pstat->hwaddr))
1135                                continue;
1136
1137                        if (true == ODM_RAStateCheck(pDM_Odm, pstat->rssi_stat.UndecoratedSmoothedPWDB, false, &pstat->rssi_level)) {
1138                                ODM_RT_TRACE(pDM_Odm, ODM_COMP_RA_MASK, ODM_DBG_LOUD, ("RSSI:%d, RSSI_LEVEL:%d\n", pstat->rssi_stat.UndecoratedSmoothedPWDB, pstat->rssi_level));
1139                                /* printk("RSSI:%d, RSSI_LEVEL:%d\n", pstat->rssi_stat.UndecoratedSmoothedPWDB, pstat->rssi_level); */
1140                                rtw_hal_update_ra_mask(pstat, pstat->rssi_level);
1141                        }
1142
1143                }
1144        }
1145}
1146
1147/*  Return Value: bool */
1148/*  - true: RATRState is changed. */
1149bool ODM_RAStateCheck(
1150        PDM_ODM_T pDM_Odm,
1151        s32 RSSI,
1152        bool bForceUpdate,
1153        u8 *pRATRState
1154)
1155{
1156        PODM_RATE_ADAPTIVE pRA = &pDM_Odm->RateAdaptive;
1157        const u8 GoUpGap = 5;
1158        u8 HighRSSIThreshForRA = pRA->HighRSSIThresh;
1159        u8 LowRSSIThreshForRA = pRA->LowRSSIThresh;
1160        u8 RATRState;
1161
1162        /*  Threshold Adjustment: */
1163        /*  when RSSI state trends to go up one or two levels, make sure RSSI is high enough. */
1164        /*  Here GoUpGap is added to solve the boundary's level alternation issue. */
1165        switch (*pRATRState) {
1166        case DM_RATR_STA_INIT:
1167        case DM_RATR_STA_HIGH:
1168                break;
1169
1170        case DM_RATR_STA_MIDDLE:
1171                HighRSSIThreshForRA += GoUpGap;
1172                break;
1173
1174        case DM_RATR_STA_LOW:
1175                HighRSSIThreshForRA += GoUpGap;
1176                LowRSSIThreshForRA += GoUpGap;
1177                break;
1178
1179        default:
1180                ODM_RT_ASSERT(pDM_Odm, false, ("wrong rssi level setting %d !", *pRATRState));
1181                break;
1182        }
1183
1184        /*  Decide RATRState by RSSI. */
1185        if (RSSI > HighRSSIThreshForRA)
1186                RATRState = DM_RATR_STA_HIGH;
1187        else if (RSSI > LowRSSIThreshForRA)
1188                RATRState = DM_RATR_STA_MIDDLE;
1189        else
1190                RATRState = DM_RATR_STA_LOW;
1191        /* printk("==>%s, RATRState:0x%02x , RSSI:%d\n", __func__, RATRState, RSSI); */
1192
1193        if (*pRATRState != RATRState || bForceUpdate) {
1194                ODM_RT_TRACE(pDM_Odm, ODM_COMP_RA_MASK, ODM_DBG_LOUD, ("RSSI Level %d -> %d\n", *pRATRState, RATRState));
1195                *pRATRState = RATRState;
1196                return true;
1197        }
1198
1199        return false;
1200}
1201
1202
1203/*  */
1204
1205/* 3 ============================================================ */
1206/* 3 Dynamic Tx Power */
1207/* 3 ============================================================ */
1208
1209/* Remove BY YuChen */
1210
1211/* 3 ============================================================ */
1212/* 3 RSSI Monitor */
1213/* 3 ============================================================ */
1214
1215void odm_RSSIMonitorInit(PDM_ODM_T pDM_Odm)
1216{
1217        pRA_T pRA_Table = &pDM_Odm->DM_RA_Table;
1218
1219        pRA_Table->firstconnect = false;
1220
1221}
1222
1223void odm_RSSIMonitorCheck(PDM_ODM_T pDM_Odm)
1224{
1225        if (!(pDM_Odm->SupportAbility & ODM_BB_RSSI_MONITOR))
1226                return;
1227
1228        odm_RSSIMonitorCheckCE(pDM_Odm);
1229
1230}       /*  odm_RSSIMonitorCheck */
1231
1232static void FindMinimumRSSI(struct adapter *padapter)
1233{
1234        struct hal_com_data     *pHalData = GET_HAL_DATA(padapter);
1235        struct dm_priv *pdmpriv = &pHalData->dmpriv;
1236        PDM_ODM_T pDM_Odm = &(pHalData->odmpriv);
1237
1238        /* 1 1.Determine the minimum RSSI */
1239
1240        if (
1241                (pDM_Odm->bLinked != true) &&
1242                (pdmpriv->EntryMinUndecoratedSmoothedPWDB == 0)
1243        ) {
1244                pdmpriv->MinUndecoratedPWDBForDM = 0;
1245                /* ODM_RT_TRACE(pDM_Odm, COMP_BB_POWERSAVING, DBG_LOUD, ("Not connected to any\n")); */
1246        } else
1247                pdmpriv->MinUndecoratedPWDBForDM = pdmpriv->EntryMinUndecoratedSmoothedPWDB;
1248
1249        /* DBG_8192C("%s =>MinUndecoratedPWDBForDM(%d)\n", __func__, pdmpriv->MinUndecoratedPWDBForDM); */
1250        /* ODM_RT_TRACE(pDM_Odm, COMP_DIG, DBG_LOUD, ("MinUndecoratedPWDBForDM =%d\n", pHalData->MinUndecoratedPWDBForDM)); */
1251}
1252
1253void odm_RSSIMonitorCheckCE(PDM_ODM_T pDM_Odm)
1254{
1255        struct adapter *Adapter = pDM_Odm->Adapter;
1256        struct hal_com_data     *pHalData = GET_HAL_DATA(Adapter);
1257        struct dm_priv *pdmpriv = &pHalData->dmpriv;
1258        int i;
1259        int tmpEntryMaxPWDB = 0, tmpEntryMinPWDB = 0xff;
1260        u8 sta_cnt = 0;
1261        u32 PWDB_rssi[NUM_STA] = {0};/* 0~15]:MACID, [16~31]:PWDB_rssi */
1262        bool FirstConnect = false;
1263        pRA_T pRA_Table = &pDM_Odm->DM_RA_Table;
1264
1265        if (pDM_Odm->bLinked != true)
1266                return;
1267
1268        FirstConnect = (pDM_Odm->bLinked) && (pRA_Table->firstconnect == false);
1269        pRA_Table->firstconnect = pDM_Odm->bLinked;
1270
1271        /* if (check_fwstate(&Adapter->mlmepriv, WIFI_AP_STATE|WIFI_ADHOC_STATE|WIFI_ADHOC_MASTER_STATE) == true) */
1272        {
1273                struct sta_info *psta;
1274
1275                for (i = 0; i < ODM_ASSOCIATE_ENTRY_NUM; i++) {
1276                        psta = pDM_Odm->pODM_StaInfo[i];
1277                        if (IS_STA_VALID(psta)) {
1278                                if (IS_MCAST(psta->hwaddr))  /* if (psta->mac_id == 1) */
1279                                        continue;
1280
1281                                if (psta->rssi_stat.UndecoratedSmoothedPWDB == (-1))
1282                                        continue;
1283
1284                                if (psta->rssi_stat.UndecoratedSmoothedPWDB < tmpEntryMinPWDB)
1285                                        tmpEntryMinPWDB = psta->rssi_stat.UndecoratedSmoothedPWDB;
1286
1287                                if (psta->rssi_stat.UndecoratedSmoothedPWDB > tmpEntryMaxPWDB)
1288                                        tmpEntryMaxPWDB = psta->rssi_stat.UndecoratedSmoothedPWDB;
1289
1290                                if (psta->rssi_stat.UndecoratedSmoothedPWDB != (-1))
1291                                        PWDB_rssi[sta_cnt++] = (psta->mac_id | (psta->rssi_stat.UndecoratedSmoothedPWDB<<16));
1292                        }
1293                }
1294
1295                /* printk("%s ==> sta_cnt(%d)\n", __func__, sta_cnt); */
1296
1297                for (i = 0; i < sta_cnt; i++) {
1298                        if (PWDB_rssi[i] != (0)) {
1299                                if (pHalData->fw_ractrl == true)/*  Report every sta's RSSI to FW */
1300                                        rtl8723b_set_rssi_cmd(Adapter, (u8 *)(&PWDB_rssi[i]));
1301                        }
1302                }
1303        }
1304
1305
1306
1307        if (tmpEntryMaxPWDB != 0)       /*  If associated entry is found */
1308                pdmpriv->EntryMaxUndecoratedSmoothedPWDB = tmpEntryMaxPWDB;
1309        else
1310                pdmpriv->EntryMaxUndecoratedSmoothedPWDB = 0;
1311
1312        if (tmpEntryMinPWDB != 0xff) /*  If associated entry is found */
1313                pdmpriv->EntryMinUndecoratedSmoothedPWDB = tmpEntryMinPWDB;
1314        else
1315                pdmpriv->EntryMinUndecoratedSmoothedPWDB = 0;
1316
1317        FindMinimumRSSI(Adapter);/* get pdmpriv->MinUndecoratedPWDBForDM */
1318
1319        pDM_Odm->RSSI_Min = pdmpriv->MinUndecoratedPWDBForDM;
1320        /* ODM_CmnInfoUpdate(&pHalData->odmpriv , ODM_CMNINFO_RSSI_MIN, pdmpriv->MinUndecoratedPWDBForDM); */
1321}
1322
1323/* 3 ============================================================ */
1324/* 3 Tx Power Tracking */
1325/* 3 ============================================================ */
1326
1327void odm_TXPowerTrackingInit(PDM_ODM_T pDM_Odm)
1328{
1329        odm_TXPowerTrackingThermalMeterInit(pDM_Odm);
1330}
1331
1332static u8 getSwingIndex(PDM_ODM_T pDM_Odm)
1333{
1334        struct adapter *Adapter = pDM_Odm->Adapter;
1335        u8 i = 0;
1336        u32 bbSwing;
1337        u32 swingTableSize;
1338        u32 *pSwingTable;
1339
1340        bbSwing = PHY_QueryBBReg(Adapter, rOFDM0_XATxIQImbalance, 0xFFC00000);
1341
1342        pSwingTable = OFDMSwingTable_New;
1343        swingTableSize = OFDM_TABLE_SIZE;
1344
1345        for (i = 0; i < swingTableSize; ++i) {
1346                u32 tableValue = pSwingTable[i];
1347
1348                if (tableValue >= 0x100000)
1349                        tableValue >>= 22;
1350                if (bbSwing == tableValue)
1351                        break;
1352        }
1353        return i;
1354}
1355
1356void odm_TXPowerTrackingThermalMeterInit(PDM_ODM_T pDM_Odm)
1357{
1358        u8 defaultSwingIndex = getSwingIndex(pDM_Odm);
1359        u8 p = 0;
1360        struct adapter *Adapter = pDM_Odm->Adapter;
1361        struct hal_com_data *pHalData = GET_HAL_DATA(Adapter);
1362
1363
1364        struct dm_priv *pdmpriv = &pHalData->dmpriv;
1365
1366        pdmpriv->bTXPowerTracking = true;
1367        pdmpriv->TXPowercount = 0;
1368        pdmpriv->bTXPowerTrackingInit = false;
1369
1370        if (*(pDM_Odm->mp_mode) != 1)
1371                pdmpriv->TxPowerTrackControl = true;
1372        else
1373                pdmpriv->TxPowerTrackControl = false;
1374
1375
1376        /* MSG_8192C("pdmpriv->TxPowerTrackControl = %d\n", pdmpriv->TxPowerTrackControl); */
1377
1378        /* pDM_Odm->RFCalibrateInfo.TxPowerTrackControl = true; */
1379        pDM_Odm->RFCalibrateInfo.ThermalValue = pHalData->EEPROMThermalMeter;
1380        pDM_Odm->RFCalibrateInfo.ThermalValue_IQK = pHalData->EEPROMThermalMeter;
1381        pDM_Odm->RFCalibrateInfo.ThermalValue_LCK = pHalData->EEPROMThermalMeter;
1382
1383        /*  The index of "0 dB" in SwingTable. */
1384        pDM_Odm->DefaultOfdmIndex = (defaultSwingIndex >= OFDM_TABLE_SIZE) ? 30 : defaultSwingIndex;
1385        pDM_Odm->DefaultCckIndex = 20;
1386
1387        pDM_Odm->BbSwingIdxCckBase = pDM_Odm->DefaultCckIndex;
1388        pDM_Odm->RFCalibrateInfo.CCK_index = pDM_Odm->DefaultCckIndex;
1389
1390        for (p = ODM_RF_PATH_A; p < MAX_RF_PATH; ++p) {
1391                pDM_Odm->BbSwingIdxOfdmBase[p] = pDM_Odm->DefaultOfdmIndex;
1392                pDM_Odm->RFCalibrateInfo.OFDM_index[p] = pDM_Odm->DefaultOfdmIndex;
1393                pDM_Odm->RFCalibrateInfo.DeltaPowerIndex[p] = 0;
1394                pDM_Odm->RFCalibrateInfo.DeltaPowerIndexLast[p] = 0;
1395                pDM_Odm->RFCalibrateInfo.PowerIndexOffset[p] = 0;
1396        }
1397
1398}
1399
1400
1401void ODM_TXPowerTrackingCheck(PDM_ODM_T pDM_Odm)
1402{
1403        odm_TXPowerTrackingCheckCE(pDM_Odm);
1404}
1405
1406void odm_TXPowerTrackingCheckCE(PDM_ODM_T pDM_Odm)
1407{
1408        struct adapter *Adapter = pDM_Odm->Adapter;
1409
1410        if (!(pDM_Odm->SupportAbility & ODM_RF_TX_PWR_TRACK))
1411                return;
1412
1413        if (!pDM_Odm->RFCalibrateInfo.TM_Trigger) { /* at least delay 1 sec */
1414                PHY_SetRFReg(pDM_Odm->Adapter, ODM_RF_PATH_A, RF_T_METER_NEW, (BIT17 | BIT16), 0x03);
1415
1416                /* DBG_871X("Trigger Thermal Meter!!\n"); */
1417
1418                pDM_Odm->RFCalibrateInfo.TM_Trigger = 1;
1419                return;
1420        } else {
1421                /* DBG_871X("Schedule TxPowerTracking direct call!!\n"); */
1422                ODM_TXPowerTrackingCallback_ThermalMeter(Adapter);
1423                pDM_Odm->RFCalibrateInfo.TM_Trigger = 0;
1424        }
1425}
1426
1427/* 3 ============================================================ */
1428/* 3 SW Antenna Diversity */
1429/* 3 ============================================================ */
1430void odm_SwAntDetectInit(PDM_ODM_T pDM_Odm)
1431{
1432        pSWAT_T pDM_SWAT_Table = &pDM_Odm->DM_SWAT_Table;
1433
1434        pDM_SWAT_Table->SWAS_NoLink_BK_Reg92c = rtw_read32(pDM_Odm->Adapter, rDPDT_control);
1435        pDM_SWAT_Table->PreAntenna = MAIN_ANT;
1436        pDM_SWAT_Table->CurAntenna = MAIN_ANT;
1437        pDM_SWAT_Table->SWAS_NoLink_State = 0;
1438}
1439