/* Get battery capacity (0~100%) */ int get_fuelgauge_ptg_value( bool is_sleep ) { if (is_sleep == true) { get_batt_info(5, true); } return batt_avg_info.capacity; }
/* Get battery voltage in mV (0~4200mv) count (sampling number), is_sleep=1 (charging during sleep) */ int get_fuelgauge_adc_value( int count, bool is_sleep, bool flag ) { if (is_sleep == true) { get_batt_info(5, true); } if(flag) return batt_avg_info.adc; else return batt_avg_info.voltage; }
static int adcfg_resume(struct platform_device* pdev) { #ifdef FCHG_DBG printk("[ADCFG] %s\n", __func__); #endif get_batt_info(5, false); /* no time to get avg. adc value */ adcfg_lowbat_detect(); queue_delayed_work(adcfg_workq, &adcfg_work, msecs_to_jiffies(BATT_ADC_CHK_INTERVAL)); return 0; }
static void adcfg_work_handler(struct work_struct *work) { static int twl4030_adc_found = false; /* twl4030_madc is a drvier for ADC in TWL4030 PMIC */ /* It is loaded after adc fuelgauge driver. So we have to wait */ if (true == twl4030_adc_found || NULL != driver_find("twl4030_madc", &platform_bus_type)) { twl4030_adc_found = true; get_batt_info(5, false); adcfg_lowbat_detect(); } queue_delayed_work(adcfg_workq, &adcfg_work, msecs_to_jiffies(BATT_ADC_CHK_INTERVAL)); }
static void check_batteries( batt* b ) { GDir *batteryDirectory; const char *battery_name; GList* l; gboolean need_update_display = FALSE; b->use_sysfs = FALSE; if (! (batteryDirectory = g_dir_open(BATTERY_DIRECTORY, 0, NULL))) { if (! (batteryDirectory = g_dir_open(BATTERY_SYSFS_DIRECTORY, 0, NULL))) { g_list_foreach( b->batteries, (GFunc)batt_info_free, NULL ); g_list_free( b->batteries ); b->batteries = NULL; return; } b->use_sysfs = TRUE; } /* Remove dead entries */ for( l = b->batteries; l; ) { GList* next = l->next; batt_info* bi = (batt_info*)l->data; char* path; if (b->use_sysfs) path = g_build_filename( BATTERY_SYSFS_DIRECTORY, bi->name, NULL ); else path = g_build_filename( BATTERY_DIRECTORY, bi->name, NULL ); if( ! g_file_test( path, G_FILE_TEST_EXISTS ) ) /* file no more exists */ { b->batteries = g_list_remove_link( b->batteries, l ); /* remove from the list */ need_update_display = TRUE; } g_free( path ); l = next; } /* Scan the battery directory for available batteries */ while ((battery_name = g_dir_read_name(batteryDirectory))) { if (battery_name[0] != '.'&&strncmp(battery_name, "BAT", 3)==0) { /* find the battery in our list */ for( l = b->batteries; l; l = l->next ) { batt_info* bi = (batt_info*)l->data; if( 0 == strcmp( bi->name, battery_name ) ) break; } if( ! l ) /* not found, this is a new battery */ { batt_info* bi = g_slice_new0( batt_info ); bi->name = g_strdup( battery_name ); /* get battery info & state for the newly added entry */ get_batt_info(bi, b->use_sysfs); get_batt_state(bi, b->use_sysfs); b->batteries = g_list_prepend( b->batteries, bi ); /* add to our list */ need_update_display = TRUE; } } } g_dir_close(batteryDirectory); if( need_update_display ) update_display( b, TRUE ); }