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