int _get_t2adc_data_( int ch ) { int ret = 0; int val[5]; int i; struct twl4030_madc_request req; // To control thermal sensor power gpio_set_value(OMAP_GPIO_EN_TEMP_VDD, 1); if ( ch >= 1 && ch <= 7 ){ turn_resources_on_for_adc(); twl_i2c_write_u8( TWL4030_MODULE_USB, SEL_MADC_MCPC, CARKIT_ANA_CTRL ); msleep(100); } req.channels = ( 1 << ch ); req.do_avg = 0; req.method = TWL4030_MADC_SW1; req.active = 0; req.func_cb = NULL; #if 0 twl4030_madc_conversion( &req ); ret = req.rbuf[ch]; #else for ( i = 0; i < 5 ; i++ ) { twl4030_madc_conversion( &req ); val[i] = req.rbuf[ch]; } ret = _get_average_value_( val, 5 ); #endif if ( ch >= 1 && ch <= 7 ){ turn_resources_off_for_adc(); } // To control thermal sensor power gpio_set_value(OMAP_GPIO_EN_TEMP_VDD, 0); return ret; }
int _get_t2adc_data_( int ch ) // ---------------------------------------------------------------------------- // Description : // Input Argument : // Return Value : { int ret = 0; int val[5]; int i; //u8 ana_val; struct twl4030_madc_request req; // mutex_lock( &battery_lock ); // msleep( 100 ); wake_lock(&adc_wakelock); if ( ch >= 1 && ch <= 7 ) { turn_resources_on_for_adc(); //msleep(100); //twl4030_i2c_read_u8(TWL4030_MODULE_USB, &ana_val, CARKIT_ANA_CTRL); twl_i2c_write_u8( TWL4030_MODULE_USB, SEL_MADC_MCPC, CARKIT_ANA_CTRL ); msleep(100); } #if 0 req.channels = ( 1 << ch ); req.do_avg = 0; req.method = TWL4030_MADC_SW1; req.active = 0; req.func_cb = NULL; twl4030_madc_conversion( &req ); ret = req.rbuf[ch]; #else req.channels = ( 1 << ch ); req.do_avg = 0; req.method = TWL4030_MADC_SW1; req.active = 0; req.func_cb = NULL; for ( i = 0; i < 5 ; i++ ) { twl4030_madc_conversion( &req ); val[i] = req.rbuf[ch]; } ret = _get_average_value_( val, 5 ); #endif if ( ch >= 1 && ch <= 7 ) { //twl4030_i2c_write_u8( TWL4030_MODULE_USB, ana_val, CARKIT_ANA_CTRL ); // rechg egkim turn_resources_off_for_adc(); } wake_unlock(&adc_wakelock); // mutex_unlock( &battery_lock ); return ret; }
static bool check_battery_vf( void ) { int count = 0; int val; bool ret = false; #if 0 count = 0; disable_charging( CHARGE_DUR_ACTIVE ); msleep( 100 ); enable_charging( CHARGE_DUR_ACTIVE ); val = gpio_get_value( KCHG_ING_GPIO ); if ( !val ) return true; while ( count < 10 ) { if ( !gpio_get_value( KCHG_ING_GPIO ) ) return true; count++; msleep( 1 ); } if ( !ret && device_config->VF_CHECK_USING_ADC ) { #if 0 int i; int val[5]; for ( i = 0; i < 5 ; i++ ) { val[i] = _get_t2adc_data_( device_config->VF_ADC_PORT ); } count = _get_average_value_( val, 5 ); #else count = _get_t2adc_data_( device_config->VF_ADC_PORT ); #endif printk("vf: %d\n", count); if ( count < 100 ) return true; } disable_charging( CHARGE_DUR_ACTIVE ); #elif 0 if ( device_config->VF_CHECK_USING_ADC ) { int i; int val[5]; for ( i = 0; i < 5 ; i++ ) { val[i] = _get_t2adc_data_( device_config->VF_ADC_PORT ); if ( val[i] >= 100 ) { printk( "vf: %d\n", val[i] ); return false; } msleep( 100 ); } count = _get_average_value_( val, 5 ); printk("vf: %d\n", count); if ( count < 100 ) return true; /* count = _get_t2adc_data_( device_config->VF_ADC_PORT ); printk("vf: %d\n", count); if ( count < 100 ) return true;*/ } else { count = 0; disable_charging( CHARGE_DUR_ACTIVE ); msleep( 100 ); enable_charging( CHARGE_DUR_ACTIVE ); val = gpio_get_value( KCHG_ING_GPIO ); if ( !val ) return true; while ( count < 10 ) { if ( !gpio_get_value( KCHG_ING_GPIO ) ) return true; count++; msleep( 1 ); } disable_charging( CHARGE_DUR_ACTIVE ); } #else count = 0; disable_charging( CHARGE_DUR_ACTIVE ); msleep( 100 ); enable_charging( CHARGE_DUR_ACTIVE ); val = gpio_get_value( KCHG_ING_GPIO ); if ( !val ) { ret = true; } while ( count < 10 ) { if ( !gpio_get_value( KCHG_ING_GPIO ) ) { ret = true; break; } count++; msleep( 1 ); } disable_charging( CHARGE_DUR_ACTIVE ); if ( !ret && device_config->VF_CHECK_USING_ADC ) { int i; int val[5]; for ( i = 0; i < 5 ; i++ ) { val[i] = _get_t2adc_data_( device_config->VF_ADC_PORT ); msleep( 100 ); } count = _get_average_value_( val, 5 ); printk("vf: %d\n", count); if ( count < 200) return true; } #endif return ret; }