Path: blob/main/sys/contrib/dev/ath/ath_hal/ar9300/ar9300_aic.c
48525 views
/*1* Copyright (c) 2013 Qualcomm Atheros, Inc.2*3* Permission to use, copy, modify, and/or distribute this software for any4* purpose with or without fee is hereby granted, provided that the above5* copyright notice and this permission notice appear in all copies.6*7* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH8* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY9* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,10* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM11* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR12* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR13* PERFORMANCE OF THIS SOFTWARE.14*/151617#include "opt_ah.h"1819#ifdef AH_SUPPORT_AR93002021#include "ah.h"22#include "ah_internal.h"2324#include "ar9300/ar9300.h"25#include "ar9300/ar9300reg.h"26#include "ar9300/ar9300phy.h"2728#if ATH_SUPPORT_AIC2930#define ATH_AIC_TEST_PATTERN 13132struct ath_aic_sram_info {33HAL_BOOL valid;34u_int8_t rot_quad_att_db;35HAL_BOOL vga_quad_sign;36u_int8_t rot_dir_att_db;37HAL_BOOL vga_dir_sign;38u_int8_t com_att_6db;39};4041struct ath_aic_out_info {42int16_t dir_path_gain_lin;43int16_t quad_path_gain_lin;44struct ath_aic_sram_info sram;45};4647#define ATH_AIC_MAX_COM_ATT_DB_TABLE 648#define ATH_AIC_MAX_AIC_LIN_TABLE 6949#define ATH_AIC_MIN_ROT_DIR_ATT_DB 050#define ATH_AIC_MIN_ROT_QUAD_ATT_DB 051#define ATH_AIC_MAX_ROT_DIR_ATT_DB 3752#define ATH_AIC_MAX_ROT_QUAD_ATT_DB 3753#define ATH_AIC_SRAM_AUTO_INCREMENT 0x8000000054#define ATH_AIC_SRAM_GAIN_TABLE_OFFSET 0x28055#define ATH_AIC_SRAM_CAL_OFFSET 0x14056#define ATH_AIC_MAX_CAL_COUNT 557#define ATH_AIC_MEAS_MAG_THRESH 2058#define ATH_AIC_BT_JUPITER_CTRL 0x6682059#define ATH_AIC_BT_AIC_ENABLE 0x02606162static const u_int8_t com_att_db_table[ATH_AIC_MAX_COM_ATT_DB_TABLE] = {630, 3, 9, 15, 21, 27};6465static const u_int16_t aic_lin_table[ATH_AIC_MAX_AIC_LIN_TABLE] = {668191, 7300, 6506, 5799, 5168, 4606, 4105, 3659,673261, 2906, 2590, 2309, 2057, 1834, 1634, 1457,681298, 1157, 1031, 919, 819, 730, 651, 580,69517, 461, 411, 366, 326, 291, 259, 231,70206, 183, 163, 146, 130, 116, 103, 92,7182, 73, 65, 58, 52, 46, 41, 37,7233, 29, 26, 23, 21, 18, 16, 15,7313, 12, 10, 9, 8, 7, 7, 6,745, 5, 4, 4, 3};7576#if ATH_AIC_TEST_PATTERN77static const u_int32_t aic_test_pattern[ATH_AIC_MAX_BT_CHANNEL] = {780x00000, // 0790x00000,800x00000,810x00000,820x00000,830x00000,840x00000,850x00000,860x00000,870x1918d,880x1938d, // 10890x00000,900x1978d,910x19e8d,920x00000,930x00000,940x00000,950x00000,960x00000,970x00000,980x00000, // 20990x00000,1000x00000,1010x1ce8f,1020x00000,1030x00000,1040x00000,1050x00000,1060x1ca93,1070x1c995,1080x00000, // 301090x1c897,1100x1c899,1110x00000,1120x00000,1130x1c79f,1140x00000,1150x1c7a5,1160x1c6ab,1170x00000,1180x00000, // 401190x00000,1200x00000,1210x1c63f,1220x00000,1230x1c52b,1240x1c525,1250x1c523,1260x00000,1270x00000,1280x00000, // 501290x00000,1300x00000,1310x1c617,1320x00000,1330x1c615,1340x1c613,1350x00000,1360x00000,1370x00000,1380x00000, // 601390x1c80f,1400x1c90f,1410x1c90f,1420x1ca0f,1430x1ca0d,1440x1cb0d,1450x00000,1460x00000,1470x00000,1480x00000, // 701490x1d00d,1500x00000,1510x00000,1520x00000,1530x00000,1540x00000,1550x00000,1560x00000157};158#endif159160static void161ar9300_aic_gain_table(struct ath_hal *ah)162{163u_int32_t aic_atten_word[19], i;164165/* Program gain table */166aic_atten_word[0] = (0x1 & 0xf)<<14 | (0x1f & 0x1f)<<9 | (0x0 & 0xf)<<5 |167(0x1f & 0x1f); // -01 dB: 4'd1, 5'd31, 00 dB: 4'd0, 5'd31;168aic_atten_word[1] = (0x3 & 0xf)<<14 | (0x1f & 0x1f)<<9 | (0x2 & 0xf)<<5 |169(0x1f & 0x1f); // -03 dB: 4'd3, 5'd31, -02 dB: 4'd2, 5'd31;170aic_atten_word[2] = (0x5 & 0xf)<<14 | (0x1f & 0x1f)<<9 | (0x4 & 0xf)<<5 |171(0x1f & 0x1f); // -05 dB: 4'd5, 5'd31, -04 dB: 4'd4, 5'd31;172aic_atten_word[3] = (0x1 & 0xf)<<14 | (0x1e & 0x1f)<<9 | (0x0 & 0xf)<<5 |173(0x1e & 0x1f); // -07 dB: 4'd1, 5'd30, -06 dB: 4'd0, 5'd30;174aic_atten_word[4] = (0x3 & 0xf)<<14 | (0x1e & 0x1f)<<9 | (0x2 & 0xf)<<5 |175(0x1e & 0x1f); // -09 dB: 4'd3, 5'd30, -08 dB: 4'd2, 5'd30;176aic_atten_word[5] = (0x5 & 0xf)<<14 | (0x1e & 0x1f)<<9 | (0x4 & 0xf)<<5 |177(0x1e & 0x1f); // -11 dB: 4'd5, 5'd30, -10 dB: 4'd4, 5'd30;178aic_atten_word[6] = (0x1 & 0xf)<<14 | (0xf & 0x1f)<<9 | (0x0 & 0xf)<<5 |179(0xf & 0x1f); // -13 dB: 4'd1, 5'd15, -12 dB: 4'd0, 5'd15;180aic_atten_word[7] = (0x3 & 0xf)<<14 | (0xf & 0x1f)<<9 | (0x2 & 0xf)<<5 |181(0xf & 0x1f); // -15 dB: 4'd3, 5'd15, -14 dB: 4'd2, 5'd15;182aic_atten_word[8] = (0x5 & 0xf)<<14 | (0xf & 0x1f)<<9 | (0x4 & 0xf)<<5 |183(0xf & 0x1f); // -17 dB: 4'd5, 5'd15, -16 dB: 4'd4, 5'd15;184aic_atten_word[9] = (0x1 & 0xf)<<14 | (0x7 & 0x1f)<<9 | (0x0 & 0xf)<<5 |185(0x7 & 0x1f); // -19 dB: 4'd1, 5'd07, -18 dB: 4'd0, 5'd07;186aic_atten_word[10] =(0x3 & 0xf)<<14 | (0x7 & 0x1f)<<9 | (0x2 & 0xf)<<5 |187(0x7 & 0x1f); // -21 dB: 4'd3, 5'd07, -20 dB: 4'd2, 5'd07;188aic_atten_word[11] =(0x5 & 0xf)<<14 | (0x7 & 0x1f)<<9 | (0x4 & 0xf)<<5 |189(0x7 & 0x1f); // -23 dB: 4'd5, 5'd07, -22 dB: 4'd4, 5'd07;190aic_atten_word[12] =(0x7 & 0xf)<<14 | (0x7 & 0x1f)<<9 | (0x6 & 0xf)<<5 |191(0x7 & 0x1f); // -25 dB: 4'd7, 5'd07, -24 dB: 4'd6, 5'd07;192aic_atten_word[13] =(0x3 & 0xf)<<14 | (0x3 & 0x1f)<<9 | (0x2 & 0xf)<<5 |193(0x3 & 0x1f); // -27 dB: 4'd3, 5'd03, -26 dB: 4'd2, 5'd03;194aic_atten_word[14] =(0x5 & 0xf)<<14 | (0x3 & 0x1f)<<9 | (0x4 & 0xf)<<5 |195(0x3 & 0x1f); // -29 dB: 4'd5, 5'd03, -28 dB: 4'd4, 5'd03;196aic_atten_word[15] =(0x1 & 0xf)<<14 | (0x1 & 0x1f)<<9 | (0x0 & 0xf)<<5 |197(0x1 & 0x1f); // -31 dB: 4'd1, 5'd01, -30 dB: 4'd0, 5'd01;198aic_atten_word[16] =(0x3 & 0xf)<<14 | (0x1 & 0x1f)<<9 | (0x2 & 0xf)<<5 |199(0x1 & 0x1f); // -33 dB: 4'd3, 5'd01, -32 dB: 4'd2, 5'd01;200aic_atten_word[17] =(0x5 & 0xf)<<14 | (0x1 & 0x1f)<<9 | (0x4 & 0xf)<<5 |201(0x1 & 0x1f); // -35 dB: 4'd5, 5'd01, -34 dB: 4'd4, 5'd01;202aic_atten_word[18] =(0x7 & 0xf)<<14 | (0x1 & 0x1f)<<9 | (0x6 & 0xf)<<5 |203(0x1 & 0x1f); // -37 dB: 4'd7, 5'd01, -36 dB: 4'd6, 5'd01;204205/* Write to Gain table with auto increment enabled. */206OS_REG_WRITE(ah, (AR_PHY_AIC_SRAM_ADDR_B0 + 0x3000),207(ATH_AIC_SRAM_AUTO_INCREMENT |208ATH_AIC_SRAM_GAIN_TABLE_OFFSET));209210for (i = 0; i < 19; i++) {211OS_REG_WRITE(ah, (AR_PHY_AIC_SRAM_DATA_B0 + 0x3000),212aic_atten_word[i]);213}214215}216217static int16_t218ar9300_aic_find_valid (struct ath_aic_sram_info *cal_sram,219HAL_BOOL dir,220u_int8_t index)221{222int16_t i;223224if (dir) {225/* search forward */226for (i = index + 1; i < ATH_AIC_MAX_BT_CHANNEL; i++) {227if (cal_sram[i].valid) {228break;229}230}231}232else {233/* search backword */234for (i = index - 1; i >= 0; i--) {235if (cal_sram[i].valid) {236break;237}238}239}240if ((i >= ATH_AIC_MAX_BT_CHANNEL) || (i < 0)) {241i = -1;242}243244return i;245}246247static int16_t248ar9300_aic_find_index (u_int8_t type, int16_t value)249{250int16_t i = -1;251252/*253* type 0: aic_lin_table, 1: com_att_db_table254*/255256if (type == 0) {257/* Find in aic_lin_table */258for (i = ATH_AIC_MAX_AIC_LIN_TABLE - 1; i >= 0; i--) {259if (aic_lin_table[i] >= value) {260break;261}262}263}264else if (type == 1) {265/* find in com_att_db_table */266for (i = 0; i < ATH_AIC_MAX_COM_ATT_DB_TABLE; i++) {267if (com_att_db_table[i] > value) {268i--;269break;270}271}272if (i >= ATH_AIC_MAX_COM_ATT_DB_TABLE) {273i = -1;274}275}276277return i;278}279280static HAL_BOOL281ar9300_aic_cal_post_process (struct ath_hal *ah)282{283struct ath_hal_9300 *ahp = AH9300(ah);284struct ath_aic_sram_info cal_sram[ATH_AIC_MAX_BT_CHANNEL];285struct ath_aic_out_info aic_sram[ATH_AIC_MAX_BT_CHANNEL];286u_int32_t dir_path_gain_idx, quad_path_gain_idx, value;287u_int32_t fixed_com_att_db;288int8_t dir_path_sign, quad_path_sign;289int16_t i;290HAL_BOOL ret = AH_TRUE;291292/* Read CAL_SRAM and get valid values. */293HALDEBUG(ah, HAL_DEBUG_BT_COEX, "(AIC) CAL_SRAM:\n");294295for (i = 0; i < ATH_AIC_MAX_BT_CHANNEL; i++) {296OS_REG_WRITE(ah, AR_PHY_AIC_SRAM_ADDR_B1,297(ATH_AIC_SRAM_CAL_OFFSET + i*4));298#if ATH_AIC_TEST_PATTERN299value = aic_test_pattern[i];300#else301value = OS_REG_READ(ah, AR_PHY_AIC_SRAM_DATA_B1);302#endif303cal_sram[i].valid = MS(value, AR_PHY_AIC_SRAM_VALID);304cal_sram[i].rot_quad_att_db = MS(value,305AR_PHY_AIC_SRAM_ROT_QUAD_ATT_DB);306cal_sram[i].vga_quad_sign = MS(value, AR_PHY_AIC_SRAM_VGA_QUAD_SIGN);307cal_sram[i].rot_dir_att_db = MS(value, AR_PHY_AIC_SRAM_ROT_DIR_ATT_DB);308cal_sram[i].vga_dir_sign = MS(value, AR_PHY_AIC_SRAM_VGA_DIR_SIGN);309cal_sram[i].com_att_6db = MS(value, AR_PHY_AIC_SRAM_COM_ATT_6DB);310311HALDEBUG(ah, HAL_DEBUG_BT_COEX,312"(AIC) %2d %2d %2d %2d %2d %2d %2d 0x%05x\n",313i, cal_sram[i].vga_quad_sign,314cal_sram[i].vga_dir_sign,315cal_sram[i].rot_dir_att_db,316cal_sram[i].rot_quad_att_db,317cal_sram[i].com_att_6db,318cal_sram[i].valid,319value);320321if (cal_sram[i].valid) {322dir_path_gain_idx = cal_sram[i].rot_dir_att_db +323com_att_db_table[cal_sram[i].com_att_6db];324quad_path_gain_idx = cal_sram[i].rot_quad_att_db +325com_att_db_table[cal_sram[i].com_att_6db];326dir_path_sign = (cal_sram[i].vga_dir_sign) ? 1 : -1;327quad_path_sign = (cal_sram[i].vga_quad_sign) ? 1 : -1;328aic_sram[i].dir_path_gain_lin = dir_path_sign *329aic_lin_table[dir_path_gain_idx];330aic_sram[i].quad_path_gain_lin = quad_path_sign *331aic_lin_table[quad_path_gain_idx];332}333}334335for (i = 0; i < ATH_AIC_MAX_BT_CHANNEL; i++) {336int16_t start_idx, end_idx;337338if (cal_sram[i].valid) {339continue;340}341342start_idx = ar9300_aic_find_valid(cal_sram, 0, i);343end_idx = ar9300_aic_find_valid(cal_sram, 1, i);344345if (start_idx < 0)346{347/* extrapolation */348start_idx = end_idx;349end_idx = ar9300_aic_find_valid(cal_sram, 1, start_idx);350351if (end_idx < 0) {352HALDEBUG(ah, HAL_DEBUG_BT_COEX,353"(AIC) Error (1): i = %d, start_idx = %d \n",354i, start_idx);355ret = AH_FALSE;356break;357}358aic_sram[i].dir_path_gain_lin =359((aic_sram[start_idx].dir_path_gain_lin -360aic_sram[end_idx].dir_path_gain_lin) *361(start_idx - i) + ((end_idx - i) >> 1)) /362(end_idx - i) +363aic_sram[start_idx].dir_path_gain_lin;364aic_sram[i].quad_path_gain_lin =365((aic_sram[start_idx].quad_path_gain_lin -366aic_sram[end_idx].quad_path_gain_lin) *367(start_idx - i) + ((end_idx - i) >> 1)) /368(end_idx - i) +369aic_sram[start_idx].quad_path_gain_lin;370}371if (end_idx < 0)372{373/* extrapolation */374end_idx = ar9300_aic_find_valid(cal_sram, 0, start_idx);375376if (end_idx < 0) {377HALDEBUG(ah, HAL_DEBUG_BT_COEX,378"(AIC) Error (2): i = %d, start_idx = %d\n",379i, start_idx);380ret = AH_FALSE;381break;382}383aic_sram[i].dir_path_gain_lin =384((aic_sram[start_idx].dir_path_gain_lin -385aic_sram[end_idx].dir_path_gain_lin) *386(i - start_idx) + ((start_idx - end_idx) >> 1)) /387(start_idx - end_idx) +388aic_sram[start_idx].dir_path_gain_lin;389aic_sram[i].quad_path_gain_lin =390((aic_sram[start_idx].quad_path_gain_lin -391aic_sram[end_idx].quad_path_gain_lin) *392(i - start_idx) + ((start_idx - end_idx) >> 1)) /393(start_idx - end_idx) +394aic_sram[start_idx].quad_path_gain_lin;395396}397else {398/* interpolation */399aic_sram[i].dir_path_gain_lin =400(((end_idx - i) * aic_sram[start_idx].dir_path_gain_lin) +401((i - start_idx) * aic_sram[end_idx].dir_path_gain_lin) +402((end_idx - start_idx) >> 1)) /403(end_idx - start_idx);404aic_sram[i].quad_path_gain_lin =405(((end_idx - i) * aic_sram[start_idx].quad_path_gain_lin) +406((i - start_idx) * aic_sram[end_idx].quad_path_gain_lin) +407((end_idx - start_idx) >> 1))/408(end_idx - start_idx);409}410}411412/* From dir/quad_path_gain_lin to sram. */413i = ar9300_aic_find_valid(cal_sram, 1, 0);414if (i < 0) {415HALDEBUG(ah, HAL_DEBUG_BT_COEX,416"(AIC) Error (3): can't find valid. Force it to 0.\n");417i = 0;418ret = AH_FALSE;419}420fixed_com_att_db = com_att_db_table[cal_sram[i].com_att_6db];421422for (i = 0; i < ATH_AIC_MAX_BT_CHANNEL; i++) {423int16_t rot_dir_path_att_db, rot_quad_path_att_db;424425aic_sram[i].sram.vga_dir_sign = (aic_sram[i].dir_path_gain_lin >= 0)426? 1 : 0;427aic_sram[i].sram.vga_quad_sign= (aic_sram[i].quad_path_gain_lin >= 0)428? 1 : 0;429430rot_dir_path_att_db =431ar9300_aic_find_index(0, abs(aic_sram[i].dir_path_gain_lin)) -432fixed_com_att_db;433rot_quad_path_att_db =434ar9300_aic_find_index(0, abs(aic_sram[i].quad_path_gain_lin)) -435fixed_com_att_db;436437aic_sram[i].sram.com_att_6db = ar9300_aic_find_index(1,438fixed_com_att_db);439440aic_sram[i].sram.valid = 1;441aic_sram[i].sram.rot_dir_att_db =442MIN(MAX(rot_dir_path_att_db, ATH_AIC_MIN_ROT_DIR_ATT_DB),443ATH_AIC_MAX_ROT_DIR_ATT_DB);444aic_sram[i].sram.rot_quad_att_db =445MIN(MAX(rot_quad_path_att_db, ATH_AIC_MIN_ROT_QUAD_ATT_DB),446ATH_AIC_MAX_ROT_QUAD_ATT_DB);447}448449HALDEBUG(ah, HAL_DEBUG_BT_COEX, "(AIC) Post processing results:\n");450451for (i = 0; i < ATH_AIC_MAX_BT_CHANNEL; i++) {452ahp->ah_aic_sram[i] = (SM(aic_sram[i].sram.vga_dir_sign,453AR_PHY_AIC_SRAM_VGA_DIR_SIGN) |454SM(aic_sram[i].sram.vga_quad_sign,455AR_PHY_AIC_SRAM_VGA_QUAD_SIGN) |456SM(aic_sram[i].sram.com_att_6db,457AR_PHY_AIC_SRAM_COM_ATT_6DB) |458SM(aic_sram[i].sram.valid,459AR_PHY_AIC_SRAM_VALID) |460SM(aic_sram[i].sram.rot_dir_att_db,461AR_PHY_AIC_SRAM_ROT_DIR_ATT_DB) |462SM(aic_sram[i].sram.rot_quad_att_db,463AR_PHY_AIC_SRAM_ROT_QUAD_ATT_DB));464465466HALDEBUG(ah, HAL_DEBUG_BT_COEX,467"(AIC) ch%02d 0x%05x %2d %2d %2d %2d %2d %2d %d %d\n",468i,469ahp->ah_aic_sram[i],470aic_sram[i].sram.vga_quad_sign,471aic_sram[i].sram.vga_dir_sign,472aic_sram[i].sram.rot_dir_att_db,473aic_sram[i].sram.rot_quad_att_db,474aic_sram[i].sram.com_att_6db,475aic_sram[i].sram.valid,476aic_sram[i].dir_path_gain_lin,477aic_sram[i].quad_path_gain_lin);478}479480return ret;481}482483u_int32_t484ar9300_aic_calibration(struct ath_hal *ah)485{486u_int32_t aic_ctrl_b0[5], aic_ctrl_b1[5];487u_int32_t aic_stat_b0[2], aic_stat_b1[2];488u_int32_t aic_stat, value;489u_int32_t i, cal_count = ATH_AIC_MAX_CAL_COUNT;490struct ath_hal_9300 *ahp = AH9300(ah);491492if (AR_SREV_JUPITER_10(ah)) {493aic_ctrl_b0[0] = AR_PHY_AIC_CTRL_0_B0_10;494aic_ctrl_b0[1] = AR_PHY_AIC_CTRL_1_B0_10;495aic_ctrl_b0[2] = AR_PHY_AIC_CTRL_2_B0_10;496aic_ctrl_b0[3] = AR_PHY_AIC_CTRL_3_B0_10;497aic_ctrl_b1[0] = AR_PHY_AIC_CTRL_0_B1_10;498aic_ctrl_b1[1] = AR_PHY_AIC_CTRL_1_B1_10;499aic_stat_b0[0] = AR_PHY_AIC_STAT_0_B0_10;500aic_stat_b0[1] = AR_PHY_AIC_STAT_1_B0_10;501aic_stat_b1[0] = AR_PHY_AIC_STAT_0_B1_10;502aic_stat_b1[1] = AR_PHY_AIC_STAT_1_B1_10;503}504else {505aic_ctrl_b0[0] = AR_PHY_AIC_CTRL_0_B0_20;506aic_ctrl_b0[1] = AR_PHY_AIC_CTRL_1_B0_20;507aic_ctrl_b0[2] = AR_PHY_AIC_CTRL_2_B0_20;508aic_ctrl_b0[3] = AR_PHY_AIC_CTRL_3_B0_20;509aic_ctrl_b0[4] = AR_PHY_AIC_CTRL_4_B0_20;510aic_ctrl_b1[0] = AR_PHY_AIC_CTRL_0_B1_20;511aic_ctrl_b1[1] = AR_PHY_AIC_CTRL_1_B1_20;512aic_ctrl_b1[4] = AR_PHY_AIC_CTRL_4_B1_20;513aic_stat_b0[0] = AR_PHY_AIC_STAT_0_B0_20;514aic_stat_b0[1] = AR_PHY_AIC_STAT_1_B0_20;515aic_stat_b1[0] = AR_PHY_AIC_STAT_0_B1_20;516aic_stat_b1[1] = AR_PHY_AIC_STAT_1_B1_20;517}518519/* Config LNA gain difference */520OS_REG_WRITE(ah, AR_PHY_BT_COEX_4, 0x22180600);521OS_REG_WRITE(ah, AR_PHY_BT_COEX_5, 0x52443a2e);522523OS_REG_WRITE(ah, aic_ctrl_b0[0],524(SM(0, AR_PHY_AIC_MON_ENABLE) |525SM(40, AR_PHY_AIC_CAL_MAX_HOP_COUNT) |526SM(1, AR_PHY_AIC_CAL_MIN_VALID_COUNT) | //26527SM(37, AR_PHY_AIC_F_WLAN) |528SM(1, AR_PHY_AIC_CAL_CH_VALID_RESET) |529SM(0, AR_PHY_AIC_CAL_ENABLE) |530SM(0x40, AR_PHY_AIC_BTTX_PWR_THR) |531SM(0, AR_PHY_AIC_ENABLE)));532533OS_REG_WRITE(ah, aic_ctrl_b1[0],534(SM(0, AR_PHY_AIC_MON_ENABLE) |535SM(1, AR_PHY_AIC_CAL_CH_VALID_RESET) |536SM(0, AR_PHY_AIC_CAL_ENABLE) |537SM(0x40, AR_PHY_AIC_BTTX_PWR_THR) |538SM(0, AR_PHY_AIC_ENABLE)));539540OS_REG_WRITE(ah, aic_ctrl_b0[1],541(SM(8, AR_PHY_AIC_CAL_BT_REF_DELAY) |542SM(6, AR_PHY_AIC_CAL_ROT_ATT_DB_EST_ISO) |543SM(3, AR_PHY_AIC_CAL_COM_ATT_DB_EST_ISO) |544SM(0, AR_PHY_AIC_BT_IDLE_CFG) |545SM(1, AR_PHY_AIC_STDBY_COND) |546SM(37, AR_PHY_AIC_STDBY_ROT_ATT_DB) |547SM(5, AR_PHY_AIC_STDBY_COM_ATT_DB) |548SM(15, AR_PHY_AIC_RSSI_MAX) |549SM(0, AR_PHY_AIC_RSSI_MIN)));550551OS_REG_WRITE(ah, aic_ctrl_b1[1],552(SM(6, AR_PHY_AIC_CAL_ROT_ATT_DB_EST_ISO) |553SM(3, AR_PHY_AIC_CAL_COM_ATT_DB_EST_ISO) |554SM(15, AR_PHY_AIC_RSSI_MAX) |555SM(0, AR_PHY_AIC_RSSI_MIN)));556557OS_REG_WRITE(ah, aic_ctrl_b0[2],558(SM(44, AR_PHY_AIC_RADIO_DELAY) |559SM(7, AR_PHY_AIC_CAL_STEP_SIZE_CORR) |560SM(12, AR_PHY_AIC_CAL_ROT_IDX_CORR) |561SM(2, AR_PHY_AIC_CAL_CONV_CHECK_FACTOR) |562SM(5, AR_PHY_AIC_ROT_IDX_COUNT_MAX) |563SM(1, AR_PHY_AIC_CAL_SYNTH_TOGGLE) |564SM(1, AR_PHY_AIC_CAL_SYNTH_AFTER_BTRX) |565SM(200, AR_PHY_AIC_CAL_SYNTH_SETTLING)));566567OS_REG_WRITE(ah, aic_ctrl_b0[3],568(SM(20, AR_PHY_AIC_MON_MAX_HOP_COUNT) |569SM(10, AR_PHY_AIC_MON_MIN_STALE_COUNT) |570SM(1, AR_PHY_AIC_MON_PWR_EST_LONG) |571SM(2, AR_PHY_AIC_MON_PD_TALLY_SCALING) |572SM(18, AR_PHY_AIC_MON_PERF_THR) |573SM(1, AR_PHY_AIC_CAL_COM_ATT_DB_FIXED) |574SM(2, AR_PHY_AIC_CAL_TARGET_MAG_SETTING) |575SM(3, AR_PHY_AIC_CAL_PERF_CHECK_FACTOR) |576SM(1, AR_PHY_AIC_CAL_PWR_EST_LONG)));577578ar9300_aic_gain_table(ah);579580/* Need to enable AIC reference signal in BT modem. */581OS_REG_WRITE(ah, ATH_AIC_BT_JUPITER_CTRL,582(OS_REG_READ(ah, ATH_AIC_BT_JUPITER_CTRL) |583ATH_AIC_BT_AIC_ENABLE));584585while (cal_count)586{587/* Start calibration */588OS_REG_CLR_BIT(ah, aic_ctrl_b1[0], AR_PHY_AIC_CAL_ENABLE);589OS_REG_SET_BIT(ah, aic_ctrl_b1[0], AR_PHY_AIC_CAL_CH_VALID_RESET);590OS_REG_SET_BIT(ah, aic_ctrl_b1[0], AR_PHY_AIC_CAL_ENABLE);591592HALDEBUG(ah, HAL_DEBUG_BT_COEX, "(AIC) Start calibration #%d\n",593(ATH_AIC_MAX_CAL_COUNT - cal_count));594595/* Wait until calibration is completed. */596for (i = 0; i < 10000; i++) {597/*598* Use AR_PHY_AIC_CAL_ENABLE bit instead of AR_PHY_AIC_CAL_DONE.599* Sometimes CAL_DONE bit is not asserted.600*/601if ((OS_REG_READ(ah, aic_ctrl_b1[0]) & AR_PHY_AIC_CAL_ENABLE) == 0)602{603HALDEBUG(ah, HAL_DEBUG_BT_COEX, "(AIC) Cal is done at #%d\n", i);604break;605}606OS_DELAY(1);607}608609/* print out status registers */610aic_stat = OS_REG_READ(ah, aic_stat_b1[0]);611HALDEBUG(ah, HAL_DEBUG_BT_COEX,612"(AIC) CAL_DONE = %d, CAL_ACTIVE = %d, MEAS_COUNT = %d\n",613MS(aic_stat, AR_PHY_AIC_CAL_DONE),614MS(aic_stat, AR_PHY_AIC_CAL_ACTIVE),615MS(aic_stat, AR_PHY_AIC_MEAS_COUNT));616HALDEBUG(ah, HAL_DEBUG_BT_COEX,617"(AIC) ANT_ISO = %d, HOP_COUNT = %d, VALID_COUNT = %d\n",618MS(aic_stat, AR_PHY_AIC_CAL_ANT_ISO_EST),619MS(aic_stat, AR_PHY_AIC_CAL_HOP_COUNT),620MS(aic_stat, AR_PHY_AIC_CAL_VALID_COUNT));621HALDEBUG(ah, HAL_DEBUG_BT_COEX,622"(AIC) BT_WEAK = %d, BT_STRONG = %d, , \n",623MS(aic_stat, AR_PHY_AIC_CAL_BT_TOO_WEAK_ERR),624MS(aic_stat, AR_PHY_AIC_CAL_BT_TOO_STRONG_ERR));625626aic_stat = OS_REG_READ(ah, aic_stat_b1[1]);627HALDEBUG(ah, HAL_DEBUG_BT_COEX,628"(AIC) MEAS_MAG_MIN = %d, CAL_AIC_SM = %d, AIC_SM = %d\n",629MS(aic_stat, AR_PHY_AIC_MEAS_MAG_MIN),630MS(aic_stat, AR_PHY_AIC_CAL_AIC_SM),631MS(aic_stat, AR_PHY_AIC_SM));632633if (i >= 10000) {634HALDEBUG(ah, HAL_DEBUG_BT_COEX, "(AIC) Calibration failed.\n");635break;636}637638/* print out calibration result */639if (MS(aic_stat, AR_PHY_AIC_MEAS_MAG_MIN) < ATH_AIC_MEAS_MAG_THRESH) {640for (i = 0; i < ATH_AIC_MAX_BT_CHANNEL; i++) {641OS_REG_WRITE(ah, AR_PHY_AIC_SRAM_ADDR_B1,642(ATH_AIC_SRAM_CAL_OFFSET + i*4));643value = OS_REG_READ(ah, AR_PHY_AIC_SRAM_DATA_B1);644if (value & 0x01) {645HALDEBUG(ah, HAL_DEBUG_BT_COEX,646"(AIC) BT chan %02d: 0x%08x\n", i, value);647}648}649break;650}651cal_count--;652}653654if (!cal_count) {655HALDEBUG(ah, HAL_DEBUG_BT_COEX, "(AIC) Calibration failed2.\n");656}657658/* Disable AIC reference signal in BT modem. */659OS_REG_WRITE(ah, ATH_AIC_BT_JUPITER_CTRL,660(OS_REG_READ(ah, ATH_AIC_BT_JUPITER_CTRL) &661~ATH_AIC_BT_AIC_ENABLE));662663ahp->ah_aic_enabled = ar9300_aic_cal_post_process(ah) ? AH_TRUE : AH_FALSE;664665HALDEBUG(ah, HAL_DEBUG_BT_COEX, "(AIC) ah_aic_enable = %d\n",666ahp->ah_aic_enabled);667return 0;668}669670671u_int32_t672ar9300_aic_start_normal (struct ath_hal *ah)673{674struct ath_hal_9300 *ahp = AH9300(ah);675u_int32_t aic_ctrl0_b1, aic_ctrl1_b0, aic_ctrl1_b1;676int16_t i;677678/* Config LNA gain difference */679OS_REG_WRITE(ah, AR_PHY_BT_COEX_4, 0x22180600);680OS_REG_WRITE(ah, AR_PHY_BT_COEX_5, 0x52443a2e);681682ar9300_aic_gain_table(ah);683684OS_REG_WRITE(ah, AR_PHY_AIC_SRAM_ADDR_B1, ATH_AIC_SRAM_AUTO_INCREMENT);685686for (i = 0; i < ATH_AIC_MAX_BT_CHANNEL; i++) {687OS_REG_WRITE(ah, AR_PHY_AIC_SRAM_DATA_B1, ahp->ah_aic_sram[i]);688}689690if (AR_SREV_JUPITER_10(ah)) {691aic_ctrl0_b1 = AR_PHY_AIC_CTRL_0_B1_10;692aic_ctrl1_b0 = AR_PHY_AIC_CTRL_1_B0_10;693aic_ctrl1_b1 = AR_PHY_AIC_CTRL_1_B1_10;694}695else {696aic_ctrl0_b1 = AR_PHY_AIC_CTRL_0_B1_20;697aic_ctrl1_b0 = AR_PHY_AIC_CTRL_1_B0_20;698aic_ctrl1_b1 = AR_PHY_AIC_CTRL_1_B1_20;699}700701OS_REG_WRITE(ah, aic_ctrl1_b0,702(SM(0, AR_PHY_AIC_BT_IDLE_CFG) |703SM(1, AR_PHY_AIC_STDBY_COND) |704SM(37, AR_PHY_AIC_STDBY_ROT_ATT_DB) |705SM(5, AR_PHY_AIC_STDBY_COM_ATT_DB) |706SM(15, AR_PHY_AIC_RSSI_MAX) |707SM(0, AR_PHY_AIC_RSSI_MIN)));708709OS_REG_WRITE(ah, aic_ctrl1_b1,710(SM(15, AR_PHY_AIC_RSSI_MAX) |711SM(0, AR_PHY_AIC_RSSI_MIN)));712713OS_REG_WRITE(ah, aic_ctrl0_b1,714(SM(0x40, AR_PHY_AIC_BTTX_PWR_THR) |715SM(1, AR_PHY_AIC_ENABLE)));716717ahp->ah_aic_enabled = AH_TRUE;718719HALDEBUG(ah, HAL_DEBUG_BT_COEX, "(AIC) Start normal operation mode.\n");720return 0;721}722#endif723724#endif725726727728729