📄 mt6188a1_drv.c
字号:
/*****************************************************************************
* Copyright Statement:
* --------------------
* This software is protected by Copyright and the information contained
* herein is confidential. The software may not be copied and the information
* contained herein may not be used or disclosed except with the written
* permission of MediaTek Inc. (C) 2005
*
* BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
* THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
* RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
* AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
* NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
* SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
* SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
* THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
* NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
* SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
*
* BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
* LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
* AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
* OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
* MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
*
* THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
* WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
* LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
* RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
* THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
*
*****************************************************************************/
/*******************************************************************************
*******************************************************************************/
#include "l1audio_def.h"
#if (defined(MT6188A1))
static uint8 cw_cache[74] = {0};
static int32 freq_IF_array[2][3]={{0,0,0},{0,0,0}};//for auto search
static int8 index_count=0;
static int8 max_count=2;
//#define force_mono
#define USE_I2C
/// #define MT6188_DEBUG
//#define MT6188_DEBUG_DUMP_LOG //Option log file
//#define MT6188_timing_cal
//#define __MT6188CR_DISABLE_SOFTMUTE__
#if defined MT6188_DEBUG
static uint8 dbg_cw_readback = 0;
#endif
#if (defined(MT6205B) || defined(MT6208)) && defined(MT6188_DEBUG_DUMP_LOG)
#error "No file system on MT6205!"
#endif
/* MT6188 Control Word */
#define CW(_A,_B) (const)(uint8)((_A << 1) + _B)
/* General propose constant */
#define MT6188 96 /// Device ID of MT6188 = 96
#define OP_WRITE 0 /// Write to MT6188
#define OP_READ 1 /// Read from MT6188
#define MT6188_WRITE 192
#define MT6188_READ 193
#define SET_FREQ_FAIL -1
#define LO_INJECTION 0
#define HI_INJECTION 1
#define RSSI_CHECK_FAIL 2
#define FM_TUNER_GRID 100
#define PRESET_IF 280 /// Preset IF: 280 khz
#define IF_MEASURE_COUNT 5 /// 3 * 1.9 ms = 5.7 ms
#define VCO_LOCKING_TIME 4 /// 4 * 4.615 ms
#define CALIBRATION_FAIL_COUNT_THRESHOLD 5
#if !defined( MT6205B ) && !defined( MT6208 )
#define REF_CLK_32K
#define PRESET_IF_CNT 547 //280000*64/32768 = 546.875274
#define PRESET_IF_DELTA_O 50//52
#define PRESET_IF_OFFSET 15 //offset 8Khz
#define IF_CONVERT_FACTOR 512 /// 32768 / 64 = 512
#else
#define USE_MT6188_AMP
#define REF_CLK_26M
#define PRESET_IF_CNT 529 //280000 * 49152 / 26000000 = 529.33 //265
#define PRESET_IF_DELTA_O 50
#define PRESET_IF_OFFSET 15 //offset 8Khz
#define IF_CONVERT_FACTOR 529 /// 26000000 / 49152 = 529
#endif
#ifdef USE_MT6188_AMP
void ExtSwitchInit(void);
void SwitchExtFMPath(uint8 if_on);
#endif
/* Serial communication interfaces */
void SerialCommInit(void);
void SerialCommRelease(void);
void SerialCommCryClkOn(void);
void SerialCommCryClkOff(void);
void GPIO_WriteIO(char data,char port);
#if defined USE_I2C
void SerialCommStart(void);
void SerialCommStop(void);
uint8 SerialCommTxByte(uint8 data);
void SerialCommRxByte(uint8 *data, uint8 ack);
#elif defined USE_3_WIRE
uint8 SerialCommTxByte(uint8 cw, uint8 data);
void SerialCommRxByte(uint8 cw, uint8 *data);
#endif
typedef struct {
uint8 addr;
uint8 value;
} ctrl_word_setting;
typedef struct {
uint8 addr;
uint8 and;
uint8 or;
} ctrl_word_operation;
extern uint8 const FM_RADIO_INPUT_LEVEL_THRESHOLD;
void FMDrv_Mute(uint8 mute);
void FMDrv_EvaluateRSSIThreshold(void);
/// Global variables for current FM status
static int16 _current_frequency = -1;
static uint8 _current_level = 0x80;
static bool _is_fm_on = false;
static bool _is_fm_mute = false;
static uint8 _rssi_threshold;
static uint8 _valid_rssi = 0;
static uint16 PRESET_IF_CNT_PLUS; //add to adjust IF rounding
static uint8 PRESET_IF_DELTA = PRESET_IF_DELTA_O;
static uint8 PRESET_IF_DELTA_check = 52;
static uint8 RSSI_offset = 0; //RSSI_offset;
static uint8 _rssi_threshold = 0; //FM_RADIO_INPUT_LEVEL_THRESHOLD for engineer mode;
static uint8 mono_flag = 0;
static uint8 Chip_ID = 0;
#ifdef MT6188_DEBUG_DUMP_LOG
extern uint32 video_get_current_time(void);
extern uint32 video_get_duration_ms(uint32 t1);
static kal_uint8 _file_name[] = {"D\0:\0\\\0f\0m\0_\0l\0o\0g\0.\0t\0x\0t\0\0\0"};
static uint32 _data_written;
static uint8 _dbg_str[128];
static FS_HANDLE _file_handle = 0;
static kal_uint8 _channel_name[] = {"D\0:\0\\\0l\0i\0s\0_\0l\0o\0g\0.\0t\0x\0t\0\0\0"};
static uint32 _list_written;
static uint8 _list_str[128];
static FS_HANDLE _file_list = 0;
#endif
static void MT6188_Mute(uint8 mute);
void FMDrv_EvaluateRSSIThreshold(void);
// enginner mode struct
typedef enum group_idx {
mono=0,
stereo,
RSSI_threshold,
IF_count_delta,
GROUP_TOTAL_NUMS
} FACTORY_GROUP_ENUM;
typedef enum item_idx {
Sblend_OFF=0,
Sblend_ON,
ITEM_TOTAL_NUMS
} FACTORY_ITEM_INDEX;
// enginner mode struct
#define POWER_ON_COMMAND_COUNT_V5 62
static const ctrl_word_setting PowerOnSetting_V5[POWER_ON_COMMAND_COUNT_V5] = {
{ CW( 1, 1), 5 },
{ CW( 2, 1), 64 },{ CW( 2, 0), 4 },
{ CW( 3, 1), 28 },{ CW( 3, 0), 49 },
{ CW( 4, 1), 128 },{ CW( 4, 0), 175 },//cw(4,0)199
{ CW( 5, 1), 228 },{ CW( 5, 0), 47 },//47 AGC_off, by joetsou //cw(5,0)175
{ CW( 7, 1), 0 },{ CW( 7, 0), 119 },
{ CW( 8, 1), 134 },{ CW( 8, 0), 89 },
{ CW( 9, 1), 152 },{ CW( 9, 0), 18 },
{ CW( 10, 1), 8 },{ CW( 10, 0), 3 },
{ CW( 11, 1), 129 },{ CW( 11, 0), 5 },
{ CW( 12, 1), 4 },{ CW( 12, 0), 3 },//cw(13, 0)136
{ CW( 13, 1), 32 },{ CW( 13, 0), 137 },//cw(14,0)254,110
{ CW( 14, 1), 255 },{ CW( 14, 0), 255 },
{ CW( 15, 1), 192 },{ CW( 15, 0), 8 },//cw(17, 1)40
{ CW( 16, 1), 8 },{ CW( 16, 0), 104 },
{ CW( 17, 1), 76 },{ CW( 17, 0), 14 },//cw(18, 0)0
{ CW( 18, 1), 6 },{ CW( 18, 0), 138 },//cw(19, 0)16
{ CW( 19, 1), 3 },{ CW( 19, 0), 56 },
{ CW( 21, 1), 167 },{ CW( 21, 0), 68 },//69//CW21_0[0] 0 //diable auto AGC,check with joetsou
{ CW( 22, 1), 68 },{ CW( 22, 0), 71 },
{ CW( 23, 1), 76 },{ CW( 23, 0), 233 },//cw(23, 0)239/233
{ CW( 24, 1), 3 },{ CW( 24, 0), 0 },
{ CW( 30, 1), 136 },{ CW( 30, 0), 136 },
{ CW( 31, 1), 0 },{ CW( 31, 0), 0 },
{ CW( 32, 1), 0 },{ CW( 32, 0), 0 },
{ CW( 33, 1), 0 },{ CW( 33, 0), 0 },//cw(23, 0)239/233
{ CW( 34, 1), 0 },{ CW( 34, 0), 1 },
{ CW( 97, 1), 16 },{ CW( 97, 0), 0 },
{ CW( 98, 1), 128 },{ CW( 98, 0), 0 },
{ CW( 99, 1), 128 },{ CW( 99, 0), 0 },
{ CW( 101, 0), 4 },
{ CW( 103, 1), 4 },{ CW( 103, 0), 32 },
};
#define POWER_ON_COMMAND_COUNT_V4 52
static const ctrl_word_setting PowerOnSetting_V4[POWER_ON_COMMAND_COUNT_V4] = {
{ CW( 1, 1), 0 }, { CW( 1, 0), 10 },
{ CW( 2, 1), 64 }, { CW( 3, 1), 28 },
{ CW( 3, 0), 53 }, { CW( 4, 1), 128 },
{ CW( 4, 0), 183 },{ CW( 5, 1), 100 },//cw(4,0)199
{ CW( 5, 0), 175 },{ CW( 7, 1), 0 }, //175, off_AGC, joetsou //cw(5,0)175
{ CW( 7, 0), 247 },{ CW( 8, 1), 134 },
{ CW( 8, 0), 89 }, { CW( 9, 1), 152 },
{ CW( 9, 0), 18 }, { CW( 10, 1), 0 },
{ CW( 10, 0), 3 }, { CW( 11, 1), 1 },
{ CW( 11, 0), 5 }, { CW( 12, 1), 4 },
{ CW( 12, 0), 3 }, { CW( 13, 1), 0 },
{ CW( 13, 0), 0 },{ CW( 14, 1), 255 },//cw(13, 0)136
{ CW( 14, 0), 246 },{ CW( 15, 1), 255 },//cw(14,0)254,110
{ CW( 15, 0), 252 },{ CW( 16, 1), 108 },
{ CW( 16, 0), 108 },{ CW( 17, 1), 72 },//cw(17, 1)40
{ CW( 17, 0), 204 },{ CW( 18, 1), 6 },
{ CW( 18, 0), 34 }, { CW( 19, 1), 3 },//cw(18, 0)0
{ CW( 19, 0), 92 }, { CW( 21, 1), 0 },//cw(19, 0)16
{ CW( 21, 0), 26 }, { CW( 22, 1), 0 },
{ CW( 22, 0), 2 }, { CW( 23, 1), 3 },
{ CW( 23, 0), 228 },{ CW( 24, 1), 3 },//cw(23, 0)239/233
{ CW( 24, 0), 0 }, { CW( 97, 1), 16 },
{ CW( 97, 0), 0 }, { CW( 98, 1), 128 },
{ CW( 98, 0), 0 }, { CW( 99, 1), 128 },
{ CW( 99, 0), 0 }, { CW( 101,0), 4 },
{ CW( 103,1), 4 }, { CW( 103,0), 32 },
};
#define POWER_ON_COMMAND_COUNT_V3 48
static const ctrl_word_setting PowerOnSetting_V3[POWER_ON_COMMAND_COUNT_V3] = {
{ CW( 1, 1), 0 }, { CW( 1, 0), 10 },
{ CW( 2, 1), 64 }, { CW( 3, 1), 28 },
{ CW( 3, 0), 53 }, { CW( 4, 1), 128 },
{ CW( 4, 0), 199 },{ CW( 5, 1), 100 },
{ CW( 5, 0), 175 },{ CW( 7, 1), 0 },//175 off_AGC_joetsou //cw(5,0)175
{ CW( 7, 0), 247 },{ CW( 8, 1), 134 },
{ CW( 8, 0), 89 }, { CW( 9, 1), 152 },
{ CW( 9, 0), 18 }, { CW( 10, 1), 0 },
{ CW( 10, 0), 3 }, { CW( 11, 1), 1 },
{ CW( 11, 0), 5 }, { CW( 12, 1), 4 },
{ CW( 12, 0), 3 }, { CW( 13, 1), 0 },
{ CW( 13, 0), 136 },{ CW( 14, 1), 255 },
{ CW( 14, 0), 110 },{ CW( 15, 1), 255 },//cw(14,0)254
{ CW( 15, 0), 252 },{ CW( 16, 1), 108 },
{ CW( 16, 0), 108 },{ CW( 17, 1), 40 },
{ CW( 17, 0), 204 },{ CW( 18, 1), 6 },
{ CW( 18, 0), 0 }, { CW( 19, 1), 3 },
{ CW( 19, 0), 16 }, { CW( 23, 1), 3 },
{ CW( 23, 0), 239 },{ CW( 24, 1), 3 },
{ CW( 24, 0), 0 }, { CW( 97, 1), 16 },
{ CW( 97, 0), 0 }, { CW( 98, 1), 128 },
{ CW( 98, 0), 0 }, { CW( 99, 1), 128 },
{ CW( 99, 0), 0 }, { CW( 101,0), 4 },
{ CW( 103,1), 4 }, { CW( 103,0), 32 },
};
#define POWER_OFF_COMMAND_COUNT 2
static const ctrl_word_operation PowerOffProc[POWER_OFF_COMMAND_COUNT] = {
{ CW( 1, 1), 0xBF, 0x40 }, //CW1_1 [6:6] 1
{ CW( 1, 1), 0x9F, 0x20 }, //CW1_1 [6:5] 1
};
// start chip ID = 5
#define CAL_PRESET_COUNT_V5 28
static const ctrl_word_operation CalPresetProcess_V5[CAL_PRESET_COUNT_V5] = {
{ CW( 14, 0), 0x7F, 0x00 }, //CW14_0 [7:7] 0 //S_AUTO,STEREO
{ CW( 14, 0), 0xEF, 0x10 }, //CW14_0 [4:4] 1
{ CW( 5, 1), 0xFB, 0x04 }, //CW5_1 [2:2] 1 //Window_L
{ CW( 3, 0), 0xF8, 0x05 }, //CW3_0 [2:0] 5 //AMP_P,S_DIV_3
{ CW( 3, 0), 0xFE, 0x01 }, //CW3_0 [0:0] 1 //S_DIV_256,S_DIV_128,S_DIV_3
{ CW( 3, 1), 0xE3, 0x1C }, //CW3_1 [4:2] 7 //ISEL
{ CW( 12, 0), 0xFE, 0x01 }, //CW12_0 [0:0] 1 //PLL19K_P
{ CW( 12, 0), 0xFD, 0x02 }, //CW12_0 [1:1] 1 //PLL_19K_P
{ CW( 7, 0), 0xE0, 0x17 }, //CW7_0 [4:0] 23 //VCO_PW,PRE_PW,LO_PW,VER
{ CW( 10, 1), 0xDF, 0x20 }, //CW10_1 [5:5] 1 //FRCKTEST
{ CW( 12, 1), 0xEF, 0x00 }, //CW12_1 [4:4] 0 //EN_TESTMODE_PLL19K
{ CW( 12, 1), 0x1F, 0x00 }, //CW12_1 [7:5] 0 //TEST_OUTSEL_19K[2:0]
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -