static void GetAudioTrimOffset(int channels) { int Buffer_on_value = 0 , Buffer_offl_value = 0, Buffer_offr_value = 0; const int off_counter = 20, on_counter = 20 , Const_DC_OFFSET = 0;//2048; printk("%s channels = %d\n", __func__, channels); // open headphone and digital part AudDrv_Clk_On(); AudDrv_Emi_Clk_On(); OpenAfeDigitaldl1(true); setHpDcCalibration(AUDIO_ANALOG_DEVICE_OUT_HEADSETR, 0); setHpDcCalibration(AUDIO_ANALOG_DEVICE_OUT_HEADSETL, 0); //get DC value when off //Sammodi Todo, need enable this on Rainier #ifdef RAINIER_NEED_CHECK Buffer_offl_value = PMIC_IMM_GetOneChannelValue(AUXADC_HP_L_CHANNEL, off_counter, 0); #endif printk("%s, Buffer_offl_value = %d \n",__func__, Buffer_offl_value); //Sammodi Todo, need enable this #ifdef RAINIER_NEED_CHECK Buffer_offr_value = PMIC_IMM_GetOneChannelValue(AUXADC_HP_R_CHANNEL, off_counter, 0); #endif printk("%s, Buffer_offr_value = %d \n",__func__, Buffer_offr_value); OpenAnalogHeadphone(true); setHpDcCalibrationGain(AUDIO_ANALOG_DEVICE_OUT_HEADSETR,10); // -1dB, (9-(-1) = 10) setHpDcCalibrationGain(AUDIO_ANALOG_DEVICE_OUT_HEADSETL,10); msleep(10); //Sammodi Todo, need enable this #ifdef RAINIER_NEED_CHECK Buffer_on_value = PMIC_IMM_GetOneChannelValue(AUXADC_HP_L_CHANNEL, on_counter, 0); #endif mHplOffset = Buffer_on_value - Buffer_offl_value + Const_DC_OFFSET; printk("%s, Buffer_on_value = %d Buffer_offl_value = %d mHplOffset = %d \n", __func__,Buffer_on_value, Buffer_offl_value, mHplOffset); //Sammodi Todo, need enable this #ifdef RAINIER_NEED_CHECK Buffer_on_value = PMIC_IMM_GetOneChannelValue(AUXADC_HP_R_CHANNEL, on_counter, 0); #endif mHprOffset = Buffer_on_value - Buffer_offr_value + Const_DC_OFFSET; printk("%s, Buffer_on_value = %d Buffer_offr_value = %d mHprOffset = %d \n", __func__,Buffer_on_value, Buffer_offr_value, mHprOffset); OpenAnalogHeadphone(false); OpenAfeDigitaldl1(false); AudDrv_Emi_Clk_Off(); AudDrv_Clk_Off(); }
static kal_uint32 charging_reset_watch_dog_timer(void *data) { kal_uint32 status = STATUS_OK; kal_uint32 ret = 0; kal_uint8 val=0; int vbat_bal = 0; int check_vbat = 3950; #if 1 // cable plug-out sw workaround ret=mt6333_read_interface(0x04, (&val),0x1, 0); if(val==1) { vbat_bal = PMIC_IMM_GetOneChannelValue(7,3,1); if(vbat_bal > check_vbat) { ret=mt6333_config_interface(0x04, 0x94, 0xFF, 0x0); mdelay(50); ret=mt6333_config_interface(0x04, 0x95, 0xFF, 0x0); } } battery_xlog_printk(BAT_LOG_CRTI, "chr_en=%d, curr_vbat=%d, check_vbat=%d\n", val, vbat_bal, check_vbat); #endif mt6333_set_rg_chrwdt_wr(1); // write 1 to kick chr wdt mt6333_set_rg_chrwdt_td(1); // 32s mt6333_set_rg_chrwdt_en(1); return status; }
static kal_uint32 charging_get_charger_det_status(void *data) { kal_uint32 status = STATUS_OK; #if defined(CHRDET_SW_MODE_EN) kal_uint32 vchr_val=0; vchr_val = PMIC_IMM_GetOneChannelValue(4,5,1); vchr_val = (((330+39)*100*vchr_val)/39)/100; if( vchr_val > 4300 ) { battery_xlog_printk(BAT_LOG_FULL, "[CHRDET_SW_WORKAROUND_EN] upmu_is_chr_det=Y (%d)\n", vchr_val); *(kal_uint32 *)data = KAL_TRUE; } else { battery_xlog_printk(BAT_LOG_FULL, "[CHRDET_SW_WORKAROUND_EN] upmu_is_chr_det=N (%d)\n", vchr_val); *(kal_uint32 *)data = KAL_FALSE; } #else *(kal_bool*)(data) = upmu_get_rgs_chrdet(); #endif if( upmu_get_rgs_chrdet() == 0 ) g_charger_type = CHARGER_UNKNOWN; return status; }
static kal_int32 read_adc_v_i_sense(void *data) { #if defined(CONFIG_POWER_EXT) *(kal_int32*)(data) = 4202; #else *(kal_int32*)(data) = PMIC_IMM_GetOneChannelValue(ISENSE_CHANNEL_NUMBER,*(kal_int32*)(data),1); #endif return STATUS_OK; }
static kal_int32 read_adc_v_bat_sense(void *data) { #if defined(CONFIG_POWER_EXT) *(kal_int32*)(data) = 4201; #else *(kal_int32*)(data) = PMIC_IMM_GetOneChannelValue(MT6350_AUX_BATSNS,*(kal_int32*)(data),1); #endif return STATUS_OK; }
static kal_int32 read_adc_v_charger(void *data) { #if defined(CONFIG_POWER_EXT) *(kal_int32*)(data) = 5001; #else kal_int32 val; val = PMIC_IMM_GetOneChannelValue(VCHARGER_CHANNEL_NUMBER,*(kal_int32*)(data),1); val = (((g_R_CHARGER_1+g_R_CHARGER_2)*100*val)/g_R_CHARGER_2)/100; *(kal_int32*)(data) = val; #endif return STATUS_OK; }
static kal_int32 read_adc_v_charger(void *data) { kal_int32 val; #if defined(CONFIG_POWER_EXT) *(kal_int32*)(data) = 5001; #else val = PMIC_IMM_GetOneChannelValue(MT6350_AUX_VCDT,*(kal_int32*)(data),1); val = (((R_CHARGER_1+R_CHARGER_2)*100*val)/R_CHARGER_2)/100; *(kal_int32*)(data) = val; #endif return STATUS_OK; }
static kal_uint32 charging_get_charging_status(void *data) { kal_uint32 status = STATUS_OK; kal_uint32 ret_val = 0; #ifdef MTK_SWCHR_SW_RECHR int vbat_bal = 0; kal_uint32 ret = 0; ret=mt6333_config_interface(0x2E, 0x00, 0xFF, 0x0); ret_val = mt6333_get_rgs_charge_complete_hw(); if(ret_val == 0x1) { *(kal_uint32 *)data = KAL_TRUE; ret=mt6333_config_interface(0x04, 0x94, 0xFF, 0x0); vbat_bal = PMIC_IMM_GetOneChannelValue(7,3,1); if(vbat_bal <= SWCHR_HW_RECHR_VOLTAGE) { ret=mt6333_config_interface(0x04, 0x95, 0xFF, 0x0); } battery_xlog_printk(BAT_LOG_CRTI, "[MTK_SWCHR_SW_RECHR] Reg[0x04]=0x%x, Reg[0x19]=0x%x, Reg[0x2E]=0x%x, vbat_bal=%d, SWCHR_HW_RECHR_VOLTAGE=%d\n", mt6333_get_reg_value(0x04), mt6333_get_reg_value(0x19), mt6333_get_reg_value(0x2E), vbat_bal, SWCHR_HW_RECHR_VOLTAGE); } else *(kal_uint32 *)data = KAL_FALSE; #else ret_val = mt6333_get_rgs_charge_complete_hw(); if(ret_val == 0x1) *(kal_uint32 *)data = KAL_TRUE; else *(kal_uint32 *)data = KAL_FALSE; #endif return status; }
static kal_int32 read_adc_v_bat_temp(void *data) { #if defined(CONFIG_POWER_EXT) *(kal_int32*)(data) = 0; #else #if defined(MTK_PCB_TBAT_FEATURE) int ret = 0, data[4], i, ret_value = 0, ret_temp = 0; int Channel=1; if( IMM_IsAdcInitReady() == 0 ) { bm_print(BM_LOG_CRTI, "[get_tbat_volt] AUXADC is not ready"); return 0; } i = times; while (i--) { ret_value = IMM_GetOneChannelValue(Channel, data, &ret_temp); ret += ret_temp; bm_print(BM_LOG_FULL, "[get_tbat_volt] ret_temp=%d\n",ret_temp); } ret = ret*1500/4096 ; ret = ret/times; bm_print(BM_LOG_CRTI, "[get_tbat_volt] Battery output mV = %d\n",ret); *(kal_int32*)(data) = ret; #else bm_print(BM_LOG_FULL, "[read_adc_v_charger] return PMIC_IMM_GetOneChannelValue(4,times,1);\n"); *(kal_int32*)(data) = PMIC_IMM_GetOneChannelValue(VBATTEMP_CHANNEL_NUMBER,*(kal_int32*)(data),1); #endif #endif return STATUS_OK; }
static void GetAudioTrimOffset(int channels) { int Buffer_on_value = 0 , Buffer_offl_value = 0, Buffer_offr_value = 0; const int off_counter = 20, on_counter = 20 , Const_DC_OFFSET = 2048; printk("%s channels = %d\n", __func__, channels); // open headphone and digital part AudDrv_Clk_On(); AudDrv_Emi_Clk_On(); OpenAfeDigitaldl1(true); switch (channels) { case AUDIO_OFFSET_TRIM_MUX_HPL: case AUDIO_OFFSET_TRIM_MUX_HPR: { OpenTrimBufferHardware(true); setHpGainZero(); break; } default: break; } // Get HPL off offset SetSdmLevel(AUDIO_SDM_LEVEL_MUTE); msleep(1); setOffsetTrimMux(AUDIO_OFFSET_TRIM_MUX_HPL); setOffsetTrimBufferGain(3); EnableTrimbuffer(true); msleep(1); #if MTK_FPGA Buffer_offl_value = PMIC_IMM_GetOneChannelValue(MT6328_AUX_CH9, off_counter, 0); #else Buffer_offl_value = 0; #endif printk("Buffer_offl_value = %d \n", Buffer_offl_value); EnableTrimbuffer(false); // Get HPR off offset SetSdmLevel(AUDIO_SDM_LEVEL_MUTE); setOffsetTrimMux(AUDIO_OFFSET_TRIM_MUX_HPR); setOffsetTrimBufferGain(3); EnableTrimbuffer(true); msleep(5); #if MTK_FPGA Buffer_offr_value = PMIC_IMM_GetOneChannelValue(MT6328_AUX_CH9, off_counter, 0); #else Buffer_offr_value = 0; #endif printk("Buffer_offr_value = %d \n", Buffer_offr_value); EnableTrimbuffer(false); switch (channels) { case AUDIO_OFFSET_TRIM_MUX_HPL: case AUDIO_OFFSET_TRIM_MUX_HPR: { OpenTrimBufferHardware(false); break; } default: break; } // calibrate HPL offset trim setOffsetTrimMux(AUDIO_OFFSET_TRIM_MUX_HPL); setOffsetTrimBufferGain(3); // EnableTrimbuffer(true); // msleep(5); switch (channels) { case AUDIO_OFFSET_TRIM_MUX_HPL: case AUDIO_OFFSET_TRIM_MUX_HPR: { OpenAnalogHeadphone(true); setHpGainZero(); break; } default: break; } EnableTrimbuffer(true); msleep(10); #ifdef CONFIG_MTK_FPGA Buffer_on_value = PMIC_IMM_GetOneChannelValue(MT6328_AUX_CH9, on_counter, 0); #else Buffer_on_value = 0; #endif mHplOffset = Buffer_on_value - Buffer_offl_value + Const_DC_OFFSET; printk("Buffer_on_value = %d Buffer_offl_value = %d mHplOffset = %d \n", Buffer_on_value, Buffer_offl_value, mHplOffset); EnableTrimbuffer(false); // calibrate HPL offset trim setOffsetTrimMux(AUDIO_OFFSET_TRIM_MUX_HPR); setOffsetTrimBufferGain(3); EnableTrimbuffer(true); msleep(10); #ifdef CONFIG_MTK_FPGA Buffer_on_value = PMIC_IMM_GetOneChannelValue(MT6328_AUX_CH9, on_counter, 0); #else Buffer_on_value = 0; #endif mHprOffset = Buffer_on_value - Buffer_offr_value + Const_DC_OFFSET; printk("Buffer_on_value = %d Buffer_offr_value = %d mHprOffset = %d \n", Buffer_on_value, Buffer_offr_value, mHprOffset); switch (channels) { case AUDIO_OFFSET_TRIM_MUX_HPL: case AUDIO_OFFSET_TRIM_MUX_HPR: OpenAnalogHeadphone(false); break; } setOffsetTrimMux(AUDIO_OFFSET_TRIM_MUX_GROUND); EnableTrimbuffer(false); OpenAfeDigitaldl1(false); SetSdmLevel(AUDIO_SDM_LEVEL_NORMAL); AudDrv_Emi_Clk_Off(); AudDrv_Clk_Off(); }
int get_battery_volt(void) { return PMIC_IMM_GetOneChannelValue(MT6328_AUX_BATSNS_AP, 5, 1); /* return 3900; */ }