summaryrefslogtreecommitdiff
path: root/include/linux/battery/fuelgauge
diff options
context:
space:
mode:
authorYuval Adam <_@yuv.al>2017-08-30 08:25:59 +0000
committerYuval Adam <_@yuv.al>2017-08-30 08:25:59 +0000
commit8e4bff4cab0ddac6060645b0715210484d02ff40 (patch)
tree3a5c3024371a04692a3a6d9974d001cdff8ebf84 /include/linux/battery/fuelgauge
Initial file dump from open source releaseHEADmaster
Diffstat (limited to 'include/linux/battery/fuelgauge')
-rw-r--r--include/linux/battery/fuelgauge/d2199_fuelgauge.h605
-rw-r--r--include/linux/battery/fuelgauge/dummy_fuelgauge.h312
-rw-r--r--include/linux/battery/fuelgauge/rt5033_fuelgauge.h173
-rw-r--r--include/linux/battery/fuelgauge/rt5033_fuelgauge_impl.h96
-rwxr-xr-xinclude/linux/battery/fuelgauge/sprd27x3_fuelgauge4samsung.h18
-rw-r--r--include/linux/battery/fuelgauge/stc3115_fuelgauge.h285
6 files changed, 1489 insertions, 0 deletions
diff --git a/include/linux/battery/fuelgauge/d2199_fuelgauge.h b/include/linux/battery/fuelgauge/d2199_fuelgauge.h
new file mode 100644
index 00000000..81cc027d
--- /dev/null
+++ b/include/linux/battery/fuelgauge/d2199_fuelgauge.h
@@ -0,0 +1,605 @@
+/*
+ * adc_fuelgauge.h
+ * Samsung ADC Fuel Gauge Header
+ *
+ * Copyright (C) 2012 Samsung Electronics, Inc.
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#ifndef __ADC_FUELGAUGE_H
+#define __ADC_FUELGAUGE_H __FILE__
+
+#include <linux/wakelock.h>
+#include <linux/d2199/d2199_battery.h>
+#include <linux/d2199/d2199_reg.h>
+#include <linux/d2199/core.h>
+
+/* Slave address should be shifted to the right 1bit.
+ * R/W bit should NOT be included.
+ */
+static const char __initdata d2199_battery_banner[] = \
+ "D2199 Battery, (c) 2013 Dialog Semiconductor Ltd.\n";
+
+/***************************************************************************
+ Pre-definition
+***************************************************************************/
+#define FALSE (0)
+#define TRUE (1)
+
+#define ADC_RES_MASK_LSB (0x0F)
+#define ADC_RES_MASK_MSB (0xF0)
+
+#if USED_BATTERY_CAPACITY == BAT_CAPACITY_1800MA
+
+#define ADC_VAL_100_PERCENT 3645 // About 4280mV
+#define CV_START_ADC 3275 // About 4100mV
+#define MAX_FULL_CHARGED_ADC 3788 // About 4350mV
+
+#define D2153_BAT_CHG_FRST_FULL_LVL 4310 // About EOC 160mA
+#define D2153_BAT_CHG_BACK_FULL_LVL 4347 // 4340mV -> 4347mV
+
+#define FIRST_VOLTAGE_DROP_ADC 115
+
+#define FIRST_VOLTAGE_DROP_LL_ADC 340
+#define FIRST_VOLTAGE_DROP_L_ADC 60
+#define FIRST_VOLTAGE_DROP_RL_ADC 25
+
+#define CHARGE_OFFSET_KRNL_H 880
+#define CHARGE_OFFSET_KRNL_L 5
+
+#define CHARGE_ADC_KRNL_H 1700
+#define CHARGE_ADC_KRNL_L 2050
+#define CHARGE_ADC_KRNL_F 2060
+
+#define CHARGE_OFFSET_KRNL 77
+#define CHARGE_OFFSET_KRNL2 50
+
+#define LAST_CHARGING_WEIGHT 80 // 900
+#define VBAT_3_4_VOLTAGE_ADC 1605
+
+#elif USED_BATTERY_CAPACITY == BAT_CAPACITY_2100MA
+#if defined(CONFIG_MACH_WILCOX)
+#define ADC_VAL_100_PERCENT 3686 // About 4300mV
+#elif defined(CONFIG_MACH_CS05)
+#define ADC_VAL_100_PERCENT 3676 // About 4280mV
+#else
+#define ADC_VAL_100_PERCENT 3645 // About 4280mV
+#endif
+
+#define CV_START_ADC 3275 // About 4100mV
+#define MAX_FULL_CHARGED_ADC 3788 // About 4350mV
+
+#define D2153_BAT_CHG_FRST_FULL_LVL 4310 // About EOC 160mA
+#define D2153_BAT_CHG_BACK_FULL_LVL 4340 // About EOC 50mA
+
+#if defined(CONFIG_MACH_WILCOX) || defined(CONFIG_MACH_CS05)
+#define FIRST_VOLTAGE_DROP_ADC 145 // 130 -> 145
+
+#define FIRST_VOLTAGE_DROP_LL_ADC 340
+#define FIRST_VOLTAGE_DROP_L_ADC 60
+#define FIRST_VOLTAGE_DROP_RL_ADC 25
+
+#define CHARGE_OFFSET_KRNL_H 360 // 400 -> 360
+#define CHARGE_OFFSET_KRNL_L 160 // 170 -> 160
+
+#define CHARGE_ADC_KRNL_H 1150 // 1155 -> 1150
+#define CHARGE_ADC_KRNL_L 2304
+#define CHARGE_ADC_KRNL_F 2305
+
+#define CHARGE_OFFSET_KRNL 20
+#define CHARGE_OFFSET_KRNL2 104 // 94 -> 104
+
+#define LAST_CHARGING_WEIGHT 124
+#else
+#define FIRST_VOLTAGE_DROP_ADC 100 // 156
+
+#define FIRST_VOLTAGE_DROP_LL_ADC 340
+#define FIRST_VOLTAGE_DROP_L_ADC 60
+#define FIRST_VOLTAGE_DROP_RL_ADC 25
+
+#define CHARGE_OFFSET_KRNL_H 270
+#define CHARGE_OFFSET_KRNL_L 20
+
+#define CHARGE_ADC_KRNL_H 1700
+#define CHARGE_ADC_KRNL_L 2050
+#define CHARGE_ADC_KRNL_F 2060
+
+#define CHARGE_OFFSET_KRNL 20
+#define CHARGE_OFFSET_KRNL2 50
+
+#define LAST_CHARGING_WEIGHT 55
+#endif
+#define VBAT_3_4_VOLTAGE_ADC 1605
+
+#else
+
+#define ADC_VAL_100_PERCENT 3445
+#define CV_START_ADC 3338
+#define MAX_FULL_CHARGED_ADC 3788 // About 4350mV
+
+#define D2153_BAT_CHG_FRST_FULL_LVL 4160 // About EOC 160mA
+#define D2153_BAT_CHG_BACK_FULL_LVL 4185 // About EOC 60mA
+
+#define FIRST_VOLTAGE_DROP_ADC 165
+
+#define FIRST_VOLTAGE_DROP_LL_ADC 340
+#define FIRST_VOLTAGE_DROP_L_ADC 60
+#define FIRST_VOLTAGE_DROP_RL_ADC 25
+
+#define CHARGE_OFFSET_KRNL_H 880
+#define CHARGE_OFFSET_KRNL_L 5
+
+#define CHARGE_ADC_KRNL_H 1700
+#define CHARGE_ADC_KRNL_L 2050
+#define CHARGE_ADC_KRNL_F 2060
+
+#define CHARGE_OFFSET_KRNL 77
+#define CHARGE_OFFSET_KRNL2 50
+
+#define LAST_CHARGING_WEIGHT 60 // 900
+#define VBAT_3_4_VOLTAGE_ADC 1605
+
+#endif /* USED_BATTERY_CAPACITY == BAT_CAPACITY_????MA */
+
+#define FULL_CAPACITY 1000
+
+#define NORM_NUM 10000
+#define NORM_CHG_NUM 100000
+
+#define DISCHARGE_SLEEP_OFFSET 55 // 45
+#define LAST_VOL_UP_PERCENT 75
+
+
+//////////////////////////////////////////////////////////////////////////////
+// Static Variable Declaration
+//////////////////////////////////////////////////////////////////////////////
+
+static struct sec_fuelgauge_info *gbat = NULL;
+static u8 is_called_by_ticker = 0;
+static u16 ACT_4P2V_ADC = 0;
+static u16 ACT_3P4V_ADC = 0;
+
+
+// This array is for setting ADC_CONT register about each channel.
+static struct adc_cont_in_auto adc_cont_inven[D2199_ADC_CHANNEL_MAX - 1] = {
+ // VBAT_S channel
+ [D2199_ADC_VOLTAGE] = {
+ .adc_preset_val = 0,
+ .adc_cont_val = (D2199_ADC_AUTO_EN_MASK | D2199_ADC_MODE_MASK
+ | D2199_AUTO_VBAT_EN_MASK),
+ .adc_msb_res = D2199_VDD_RES_VBAT_RES_REG,
+ .adc_lsb_res = D2199_ADC_RES_AUTO1_REG,
+ .adc_lsb_mask = ADC_RES_MASK_LSB,
+ },
+ // TEMP_1 channel
+ [D2199_ADC_TEMPERATURE_1] = {
+ .adc_preset_val = D2199_TEMP1_ISRC_EN_MASK,
+ .adc_cont_val = (D2199_ADC_AUTO_EN_MASK | D2199_ADC_MODE_MASK
+ | D2199_TEMP1_ISRC_EN_MASK),
+ .adc_msb_res = D2199_TBAT1_RES_TEMP1_RES_REG,
+ .adc_lsb_res = D2199_ADC_RES_AUTO1_REG,
+ .adc_lsb_mask = ADC_RES_MASK_MSB,
+ },
+ // TEMP_2 channel
+ [D2199_ADC_TEMPERATURE_2] = {
+ .adc_preset_val = D2199_TEMP2_ISRC_EN_MASK,
+ .adc_cont_val = (D2199_ADC_AUTO_EN_MASK | D2199_ADC_MODE_MASK
+ | D2199_TEMP2_ISRC_EN_MASK),
+ .adc_msb_res = D2199_TBAT2_RES_TEMP2_RES_REG,
+ .adc_lsb_res = D2199_ADC_RES_AUTO3_REG,
+ .adc_lsb_mask = ADC_RES_MASK_LSB,
+ },
+ // VF channel
+ [D2199_ADC_VF] = {
+ .adc_preset_val = D2199_AD4_ISRC_ENVF_ISRC_EN_MASK,
+ .adc_cont_val = (D2199_ADC_AUTO_EN_MASK | D2199_ADC_MODE_MASK
+ | D2199_AUTO_VF_EN_MASK
+ | D2199_AD4_ISRC_ENVF_ISRC_EN_MASK),
+ .adc_msb_res = D2199_ADCIN4_RES_VF_RES_REG,
+ .adc_lsb_res = D2199_ADC_RES_AUTO2_REG,
+ .adc_lsb_mask = ADC_RES_MASK_LSB,
+ },
+ // AIN channel
+ [D2199_ADC_AIN] = {
+ .adc_preset_val = 0,
+ .adc_cont_val = (D2199_ADC_AUTO_EN_MASK | D2199_ADC_MODE_MASK
+ | D2199_AUTO_AIN_EN_MASK),
+ .adc_msb_res = D2199_ADCIN5_RES_AIN_RES_REG,
+ .adc_lsb_res = D2199_ADC_RES_AUTO2_REG,
+ .adc_lsb_mask = ADC_RES_MASK_MSB
+ },
+};
+
+/* Table for compensation of charge offset in CC mode */
+static u16 initialize_charge_offset[] = {
+// 500, 600, 700, 800, 900, 1000, 1100, 1200,
+ 18, 22, 26, 30, 34, 36, 40, 44,
+};
+
+static u16 initialize_charge_up_cc[] = {
+// 500, 600, 700, 800, 900, 1000, 1100, 1200,
+ 45
+};
+
+/* LUT for NCP15XW223 thermistor with 10uA current source selected */
+static struct adc2temp_lookuptbl adc2temp_lut = {
+ // Case of NCP03XH223
+#if defined(CONFIG_MACH_BAFFIN) || defined(CONFIG_MACH_BAFFINQ)
+ .adc = { // ADC-12 input value
+ 2516, 1890, 1551, 1218, 950, 911, 802,
+ 652, 505, 437, 362, 300, 252, 210,
+ 192, 175, 150, 128, 110, 100, 92,
+ 86,
+ },
+ .temp = { // temperature (degree K)
+ C2K(-200), C2K(-150), C2K(-100), C2K(-50), C2K(0), C2K(20), C2K(50),
+ C2K(100), C2K(150), C2K(200), C2K(250), C2K(300), C2K(350), C2K(400),
+ C2K(430), C2K(450), C2K(500), C2K(550), C2K(600), C2K(630), C2K(650),
+ C2K(670),
+ },
+#elif defined(CONFIG_MACH_WILCOX) || defined(CONFIG_MACH_CS05)
+ #ifdef CONFIG_MACH_WILCOX_CMCC
+ //For Wilcox TD_SCDMA
+ .adc = { // ADC-12 input value
+ 2000, 1633, 1275, 1031, 831, 772, 685,
+ 554, 471, 388, 314, 268, 224, 196,
+ 180, 167, 148, 125, 107, 102, 97,
+ 83,
+ },
+ #else
+ //For Wilcox CU and Baffin RD
+ .adc = { // ADC-12 input value
+ 2000, 1633, 1275, 1031, 831, 772, 685,
+ 554, 471, 388, 314, 268, 224, 189,
+ 171, 159, 136, 117, 100, 93, 88,
+ 75,
+ },
+ #endif
+ .temp = { // temperature (degree K)
+ C2K(-200), C2K(-150), C2K(-100), C2K(-50), C2K(0), C2K(20), C2K(50),
+ C2K(100), C2K(150), C2K(200), C2K(250), C2K(300), C2K(350), C2K(400),
+ C2K(430), C2K(450), C2K(500), C2K(550), C2K(600), C2K(630), C2K(650),
+ C2K(700),
+ },
+#elif defined(CONFIG_MACH_CS02)
+ .adc = { // ADC-12 input value
+ 2091, 1601, 1246, 1012, 855, 661, 543,
+ 444, 370, 347, 337, 327, 317, 257,
+ 221, 183, 155, 135, 113, 99, 85,
+ 76,
+ },
+ .temp = { // temperature (degree K)
+ C2K(-200), C2K(-150), C2K(-100), C2K(-50), C2K(0), C2K(50), C2K(100),
+ C2K(150), C2K(200), C2K(220), C2K(230), C2K(240), C2K(250), C2K(300),
+ C2K(350), C2K(400), C2K(450), C2K(500), C2K(550), C2K(600), C2K(650),
+ C2K(700),
+ },
+#else
+ .adc = { // ADC-12 input value
+ 1458, 1156, 859, 761, 614, 566, 510,
+ 418, 344, 290, 244, 207, 176, 145,
+ 130, 123, 107, 88, 76, 70, 66,
+ 63,
+ },
+ .temp = { // temperature (degree K)
+ C2K(-200), C2K(-150), C2K(-100), C2K(-50), C2K(0), C2K(20), C2K(50),
+ C2K(100), C2K(150), C2K(200), C2K(250), C2K(300), C2K(350), C2K(400),
+ C2K(430), C2K(450), C2K(500), C2K(550), C2K(600), C2K(630), C2K(650),
+ C2K(670),
+ },
+#endif
+};
+
+static u16 temp_lut_length = (u16)sizeof(adc2temp_lut.adc)/sizeof(u16);
+
+// adc = (vbat-2500)/2000*2^12
+// vbat (mV) = 2500 + adc*2000/2^12
+static struct adc2vbat_lookuptbl adc2vbat_lut = {
+ .adc = {1843, 1946, 2148, 2253, 2458, 2662, 2867, 2683, 3072, 3482,}, // ADC-12 input value
+ .offset = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}, // charging mode ADC offset
+ .vbat = {3400, 3450, 3500, 3600, 3700, 3800, 3900, 4000, 4100, 4200,}, // VBAT (mV)
+};
+
+#if USED_BATTERY_CAPACITY == BAT_CAPACITY_1800MA
+// For CS02 Project
+static struct adc2soc_lookuptbl adc2soc_lut = {
+ .adc_ht = {1843, 1906, 2155, 2310, 2338, 2367, 2563, 2627, 2688, 2762, 2920, 3069, 3249, 3458, ADC_VAL_100_PERCENT,}, // ADC input @ high temp
+ .adc_rt = {1843, 1906, 2155, 2310, 2338, 2367, 2563, 2627, 2688, 2762, 2920, 3069, 3249, 3458, ADC_VAL_100_PERCENT,}, // ADC input @ room temp
+ .adc_rlt = {1843, 1906, 2155, 2310, 2338, 2367, 2563, 2627, 2688, 2762, 2920, 3069, 3249, 3458, ADC_VAL_100_PERCENT,}, // ADC input @ low temp(0)
+ .adc_lt = {1843, 1906, 2155, 2310, 2338, 2367, 2563, 2627, 2688, 2762, 2920, 3069, 3249, 3458, ADC_VAL_100_PERCENT,}, // ADC input @ low temp(0)
+ .adc_lmt = {1843, 1906, 2155, 2310, 2338, 2367, 2563, 2627, 2688, 2762, 2920, 3069, 3249, 3458, ADC_VAL_100_PERCENT,}, // ADC input @ low mid temp(-10)
+ .adc_llt = {1843, 1906, 2155, 2310, 2338, 2367, 2563, 2627, 2688, 2762, 2920, 3069, 3249, 3458, ADC_VAL_100_PERCENT,}, // ADC input @ low low temp(-20)
+ .soc = { 0, 10, 30, 50, 70, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000,}, // SoC in %
+};
+
+//Discharging Weight(Room/Low/low low)
+// latest 0.1C
+//Discharging Weight(Room/Low/low low) // 0, 1, 3, 5, 7, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100
+// This is for 0.1C
+//static u16 adc_weight_section_discharge_1c[] = { 5, 8, 10, 45, 90, 115, 43, 50, 75, 80, 100, 100, 100, 100, 145};
+static u16 adc_weight_section_discharge_1c[] = {110, 160, 230, 280, 240, 101, 17, 13, 18, 33, 34, 68, 95, 125, 195};
+static u16 adc_weight_section_discharge_rlt_1c[] = {110, 160, 230, 280, 240, 101, 17, 13, 18, 33, 34, 68, 95, 125, 195};
+static u16 adc_weight_section_discharge_lt_1c[] = {110, 160, 230, 280, 240, 101, 17, 13, 18, 33, 34, 68, 95, 125, 195};
+static u16 adc_weight_section_discharge_lmt_1c[] = {110, 160, 230, 280, 240, 101, 17, 13, 18, 33, 34, 68, 95, 125, 195};
+static u16 adc_weight_section_discharge_llt_1c[] = {110, 160, 230, 280, 240, 101, 17, 13, 18, 33, 34, 68, 95, 125, 195};
+
+// This is for 0.2C
+//Discharging Weight(Room/Low/low low) // 0, 1, 3, 5, 7, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100
+ //{ 40, 80, 150, 150, 120, 59, 18, 16, 21, 39, 36, 58, 73, 80, 125};
+static u16 adc_weight_section_discharge_2c[] = {140, 180, 190, 150, 120, 105, 18, 16, 21, 39, 36, 58, 73, 80, 125};
+static u16 adc_weight_section_discharge_rlt_2c[] = {140, 180, 190, 150, 120, 105, 18, 16, 21, 39, 36, 58, 73, 80, 125};
+static u16 adc_weight_section_discharge_lt_2c[] = {140, 180, 190, 150, 120, 105, 18, 16, 21, 39, 36, 58, 73, 80, 125};
+static u16 adc_weight_section_discharge_lmt_2c[] = {140, 180, 190, 150, 120, 105, 18, 16, 21, 39, 36, 58, 73, 80, 125};
+static u16 adc_weight_section_discharge_llt_2c[] = {140, 180, 190, 150, 120, 105, 18, 16, 21, 39, 36, 58, 73, 80, 125};
+
+//Charging Weight(Room/Low/low low) // 0, 1, 3, 5, 7, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100
+static u16 adc_weight_section_charge[] = {2950, 355, 265, 66, 45, 93, 32, 33, 42, 92, 97, 110, 120, 90, LAST_CHARGING_WEIGHT};
+static u16 adc_weight_section_charge_rlt[] = {2950, 355, 265, 66, 45, 93, 32, 33, 42, 92, 97, 110, 120, 90, LAST_CHARGING_WEIGHT};
+static u16 adc_weight_section_charge_lt[] = {2950, 355, 265, 66, 45, 93, 32, 33, 42, 92, 97, 110, 120, 90, LAST_CHARGING_WEIGHT};
+static u16 adc_weight_section_charge_lmt[] = {2950, 355, 265, 66, 45, 93, 32, 33, 42, 92, 97, 110, 120, 90, LAST_CHARGING_WEIGHT};
+static u16 adc_weight_section_charge_llt[] = {2950, 355, 265, 66, 45, 93, 32, 33, 42, 92, 97, 110, 120, 90, LAST_CHARGING_WEIGHT};
+
+static struct diff_tbl dischg_diff_tbl = {
+ // 0, 2-1, 4-3, 6-5, 9-7,19-10,29-20,39-30,49-40
+ {173, 173, 143, 8, 15, 54, 40, 37, 50}, // 0.1C
+ {314, 314, 314, 145, 145, 177, 209, 221, 216}, // 0.2C
+};
+
+static u16 fg_reset_drop_offset[] = {172-50, 98-40};
+
+#elif USED_BATTERY_CAPACITY == BAT_CAPACITY_2100MA
+
+#if defined(CONFIG_MACH_WILCOX) || defined(CONFIG_MACH_CS05)
+static struct adc2soc_lookuptbl adc2soc_lut = {
+ .adc_ht = {1843, 1891, 2170, 2314, 2395, 2438, 2573, 2623, 2666, 2746, 2898, 3057, 3246, 3466, ADC_VAL_100_PERCENT,}, // ADC input @ high temp
+ .adc_rt = {1843, 1891, 2170, 2314, 2395, 2438, 2573, 2623, 2666, 2746, 2898, 3057, 3246, 3466, ADC_VAL_100_PERCENT,}, // ADC input @ room temp
+ .adc_rlt = {1843, 1891, 2170, 2314, 2395, 2438, 2573, 2623, 2666, 2746, 2898, 3057, 3246, 3466, ADC_VAL_100_PERCENT,}, // ADC input @ low temp(0)
+ .adc_lt = {1843, 1891, 2170, 2314, 2395, 2438, 2573, 2623, 2666, 2746, 2898, 3057, 3246, 3466, ADC_VAL_100_PERCENT,}, // ADC input @ low temp(0)
+ .adc_lmt = {1843, 1891, 2170, 2314, 2395, 2438, 2573, 2623, 2666, 2746, 2898, 3057, 3246, 3466, ADC_VAL_100_PERCENT,}, // ADC input @ low mid temp(-10)
+ .adc_llt = {1843, 1891, 2170, 2314, 2395, 2438, 2573, 2623, 2666, 2746, 2898, 3057, 3246, 3466, ADC_VAL_100_PERCENT,}, // ADC input @ low low temp(-20)
+ .soc = { 0, 10, 30, 50, 70, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000,}, // SoC in %
+};
+
+// These table are for 0.1C load currents.
+// latest 0.1C
+//Discharging Weight(Room/Low/low low) // 0, 1, 3, 5, 7, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100
+static u16 adc_weight_section_discharge_1c[] = { 41, 123, 84, 36, 18, 25, 12, 10, 19, 32, 41, 60, 82, 94, 303};
+static u16 adc_weight_section_discharge_rlt_1c[] = { 41, 123, 84, 36, 18, 25, 12, 10, 19, 32, 41, 60, 82, 94, 303};
+static u16 adc_weight_section_discharge_lt_1c[] = { 41, 123, 84, 36, 18, 25, 12, 10, 19, 32, 41, 60, 82, 94, 303};
+static u16 adc_weight_section_discharge_lmt_1c[] = { 41, 123, 84, 36, 18, 25, 12, 10, 19, 32, 41, 60, 82, 94, 303};
+static u16 adc_weight_section_discharge_llt_1c[] = { 41, 123, 84, 36, 18, 25, 12, 10, 19, 32, 41, 60, 82, 94, 303};
+
+// These table are for 0.2C load currents.
+//Discharging Weight(Room/Low/low low) // 0, 1, 3, 5, 7, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100
+static u16 adc_weight_section_discharge_2c[] = { 47, 141, 93, 59, 25, 33, 15, 12, 24, 43, 45, 65, 89, 95, 303};
+static u16 adc_weight_section_discharge_rlt_2c[] = { 47, 141, 93, 59, 25, 33, 15, 12, 24, 43, 45, 65, 89, 95, 303};
+static u16 adc_weight_section_discharge_lt_2c[] = { 47, 141, 93, 59, 25, 33, 15, 12, 24, 43, 45, 65, 89, 95, 303};
+static u16 adc_weight_section_discharge_lmt_2c[] = { 47, 141, 93, 59, 25, 33, 15, 12, 24, 43, 45, 65, 89, 95, 303};
+static u16 adc_weight_section_discharge_llt_2c[] = { 47, 141, 93, 59, 25, 33, 15, 12, 24, 43, 45, 65, 89, 95, 303};
+
+#ifdef CONFIG_MACH_WILCOX_CMCC
+// For Wilcox TDSCDMA
+//Charging Weight(Room/Low/low low) // 0, 1, 3, 5, 7, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100
+static u16 adc_weight_section_charge[] = {2950, 954, 468, 317, 89, 73, 26, 22, 42, 79, 88, 106, 120, 115, LAST_CHARGING_WEIGHT};
+static u16 adc_weight_section_charge_rlt[] = {2950, 954, 468, 317, 89, 73, 26, 22, 42, 79, 88, 106, 120, 115, LAST_CHARGING_WEIGHT};
+static u16 adc_weight_section_charge_lt[] = {2950, 954, 468, 317, 89, 73, 26, 22, 42, 79, 88, 106, 120, 115, LAST_CHARGING_WEIGHT};
+static u16 adc_weight_section_charge_lmt[] = {2950, 954, 468, 317, 89, 73, 26, 22, 42, 79, 88, 106, 120, 115, LAST_CHARGING_WEIGHT};
+static u16 adc_weight_section_charge_llt[] = {2950, 954, 468, 317, 89, 73, 26, 22, 42, 79, 88, 106, 120, 115, LAST_CHARGING_WEIGHT};
+#else
+// For Wilcox CU and Baffin RD
+//Charging Weight(Room/Low/low low) // 0, 1, 3, 5, 7, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100
+static u16 adc_weight_section_charge[] = {2950, 954, 468, 325, 102, 94, 33, 30, 52, 101, 112, 132, 141, 115, LAST_CHARGING_WEIGHT};
+static u16 adc_weight_section_charge_rlt[] = {2950, 954, 468, 325, 102, 94, 33, 30, 52, 101, 112, 132, 141, 115, LAST_CHARGING_WEIGHT};
+static u16 adc_weight_section_charge_lt[] = {2950, 954, 468, 325, 102, 94, 33, 30, 52, 101, 112, 132, 141, 115, LAST_CHARGING_WEIGHT};
+static u16 adc_weight_section_charge_lmt[] = {2950, 954, 468, 325, 102, 94, 33, 30, 52, 101, 112, 132, 141, 115, LAST_CHARGING_WEIGHT};
+static u16 adc_weight_section_charge_llt[] = {2950, 954, 468, 325, 102, 94, 33, 30, 52, 101, 112, 132, 141, 115, LAST_CHARGING_WEIGHT};
+#endif
+
+static struct diff_tbl dischg_diff_tbl = {
+ // 0, 1-2, 3-4, 5-6, 7-9,10-19,20-29,30-39,40-49,50-59,60-69,70-79,80-89,90-99, 100
+ {355, 277, 267, 264, 180, 117, 110, 117, 115, 115, 95, 79, 69, 30, 35}, // 0.1C
+ {710, 706, 513, 409, 350, 249, 212, 202, 197, 211, 206, 182, 155, 135, 164}, // 0.2C
+};
+
+static u16 fg_reset_drop_offset[] = {86, 86};
+
+#else
+// For BAFFIN-RD project
+static struct adc2soc_lookuptbl adc2soc_lut = {
+ .adc_ht = {1843, 1911, 2206, 2375, 2395, 2415, 2567, 2623, 2670, 2755, 2921, 3069, 3263, 3490, ADC_VAL_100_PERCENT,}, // ADC input @ high temp
+ .adc_rt = {1843, 1911, 2206, 2375, 2395, 2415, 2567, 2623, 2670, 2755, 2921, 3069, 3263, 3490, ADC_VAL_100_PERCENT,}, // ADC input @ room temp
+ .adc_rlt = {1843, 1911, 2206, 2375, 2395, 2415, 2567, 2623, 2670, 2755, 2921, 3069, 3263, 3490, ADC_VAL_100_PERCENT,}, // ADC input @ low temp(0)
+ .adc_lt = {1843, 1911, 2206, 2375, 2395, 2415, 2567, 2623, 2670, 2755, 2921, 3069, 3263, 3490, ADC_VAL_100_PERCENT,}, // ADC input @ low temp(0)
+ .adc_lmt = {1843, 1911, 2206, 2375, 2395, 2415, 2567, 2623, 2670, 2755, 2921, 3069, 3263, 3490, ADC_VAL_100_PERCENT,}, // ADC input @ low mid temp(-10)
+ .adc_llt = {1843, 1911, 2206, 2375, 2395, 2415, 2567, 2623, 2670, 2755, 2921, 3069, 3263, 3490, ADC_VAL_100_PERCENT,}, // ADC input @ low low temp(-20)
+ .soc = { 0, 10, 30, 50, 70, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000,}, // SoC in %
+};
+
+//Discharging Weight(Room/Low/low low) for 0.1C
+//Discharging Weight(Room/Low/low low) // 0, 1, 3, 5, 7, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100
+//static u16 adc_weight_section_discharge_1c[] = { 50, 95, 75, 15, 15, 25, 10, 10, 17, 28, 32, 54, 75, 100, 295};
+static u16 adc_weight_section_discharge_1c[] = { 49, 40, 15, 10, 14, 23, 10, 10, 17, 28, 32, 54, 75, 100, 295};
+static u16 adc_weight_section_discharge_rlt_1c[] = { 49, 40, 15, 10, 14, 23, 10, 10, 17, 28, 32, 54, 75, 100, 295};
+static u16 adc_weight_section_discharge_lt_1c[] = { 49, 40, 15, 10, 14, 23, 10, 10, 17, 28, 32, 54, 75, 100, 295};
+static u16 adc_weight_section_discharge_lmt_1c[] = { 49, 40, 15, 10, 14, 23, 10, 10, 17, 28, 32, 54, 75, 100, 295};
+static u16 adc_weight_section_discharge_llt_1c[] = { 49, 40, 15, 10, 14, 23, 10, 10, 17, 28, 32, 54, 75, 100, 295};
+
+//Discharging Weight(Room/Low/low low) for 0.2C
+//Discharging Weight(Room/Low/low low) // 0, 1, 3, 5, 7, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100
+//static u16 adc_weight_section_discharge_2c[] = { 50, 245, 210, 24, 18, 40, 14, 12, 23, 38, 37, 54, 75, 75, 265};
+static u16 adc_weight_section_discharge_2c[] = { 50, 215, 201, 24, 19, 42, 15, 13, 24, 38, 37, 54, 75, 75, 265};
+static u16 adc_weight_section_discharge_rlt_2c[] = { 50, 215, 201, 24, 19, 42, 15, 13, 24, 38, 37, 54, 75, 75, 265};
+static u16 adc_weight_section_discharge_lt_2c[] = { 50, 215, 201, 24, 19, 42, 15, 13, 24, 38, 37, 54, 75, 75, 265};
+static u16 adc_weight_section_discharge_lmt_2c[] = { 50, 215, 201, 24, 19, 42, 15, 13, 24, 38, 37, 54, 75, 75, 265};
+static u16 adc_weight_section_discharge_llt_2c[] = { 50, 215, 201, 24, 19, 42, 15, 13, 24, 38, 37, 54, 75, 75, 265};
+
+//Charging Weight(Room/Low/low low) // 0, 1, 3, 5, 7, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100
+//static u16 adc_weight_section_charge[] = {2800, 642, 620, 63, 53, 108, 40, 33, 58, 113, 107, 133, 142, 63, LAST_CHARGING_WEIGHT};
+static u16 adc_weight_section_charge[] = {2800, 642, 620, 63, 53, 106, 37, 31, 54, 108, 102, 130, 147, 70, LAST_CHARGING_WEIGHT};
+static u16 adc_weight_section_charge_rlt[] = {2800, 642, 620, 63, 53, 106, 37, 31, 54, 108, 102, 130, 147, 70, LAST_CHARGING_WEIGHT};
+static u16 adc_weight_section_charge_lt[] = {2800, 642, 620, 63, 53, 106, 37, 31, 54, 108, 102, 130, 147, 70, LAST_CHARGING_WEIGHT};
+static u16 adc_weight_section_charge_lmt[] = {2800, 642, 620, 63, 53, 106, 37, 31, 54, 108, 102, 130, 147, 70, LAST_CHARGING_WEIGHT};
+static u16 adc_weight_section_charge_llt[] = {2800, 642, 620, 63, 53, 106, 37, 31, 54, 108, 102, 130, 147, 70, LAST_CHARGING_WEIGHT};
+
+static struct diff_tbl dischg_diff_tbl = {
+ // 0, 1-2, 3-4, 5-6, 7-9,10-19,20-29,30-39,40-49,50-59,60-69,70-79,80-89,90-99, 100
+ {400, 360, 230, 120, 120, 130, 110, 110, 110, 115, 100, 75, 60, 30, 20}, // 0.1C
+ {635, 465, 270, 245, 220, 245, 230, 225, 217, 245, 245, 213, 178, 153, 250}, // 0.2C
+};
+
+static u16 fg_reset_drop_offset[] = {172, 98};
+
+#endif
+
+#else
+static struct adc2soc_lookuptbl adc2soc_lut = {
+ .adc_ht = {1843, 1906, 2155, 2310, 2338, 2367, 2563, 2627, 2688, 2762, 2920, 3069, 3249, 3458, ADC_VAL_100_PERCENT,}, // ADC input @ high temp
+ .adc_rt = {1843, 1906, 2155, 2310, 2338, 2367, 2563, 2627, 2688, 2762, 2920, 3069, 3249, 3458, ADC_VAL_100_PERCENT,}, // ADC input @ room temp
+ .adc_rlt = {1843, 1906, 2155, 2310, 2338, 2367, 2563, 2627, 2688, 2762, 2920, 3069, 3249, 3458, ADC_VAL_100_PERCENT,}, // ADC input @ low temp(0)
+ .adc_lt = {1843, 1906, 2155, 2310, 2338, 2367, 2563, 2627, 2688, 2762, 2920, 3069, 3249, 3458, ADC_VAL_100_PERCENT,}, // ADC input @ low temp(0)
+ .adc_lmt = {1843, 1906, 2155, 2310, 2338, 2367, 2563, 2627, 2688, 2762, 2920, 3069, 3249, 3458, ADC_VAL_100_PERCENT,}, // ADC input @ low mid temp(-10)
+ .adc_llt = {1843, 1906, 2155, 2310, 2338, 2367, 2563, 2627, 2688, 2762, 2920, 3069, 3249, 3458, ADC_VAL_100_PERCENT,}, // ADC input @ low low temp(-20)
+ .soc = { 0, 10, 30, 50, 70, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000,}, // SoC in %
+};
+
+//Discharging Weight(Room/Low/low low)
+// latest 0.1C
+//Discharging Weight(Room/Low/low low) // 0, 1, 3, 5, 7, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100
+// This is for 0.1C
+//static u16 adc_weight_section_discharge_1c[] = { 5, 8, 10, 45, 90, 115, 43, 50, 75, 80, 100, 100, 100, 100, 145};
+static u16 adc_weight_section_discharge_1c[] = {110, 160, 230, 280, 240, 101, 17, 13, 18, 33, 34, 68, 95, 125, 195};
+static u16 adc_weight_section_discharge_rlt_1c[] = {110, 160, 230, 280, 240, 101, 17, 13, 18, 33, 34, 68, 95, 125, 195};
+static u16 adc_weight_section_discharge_lt_1c[] = {110, 160, 230, 280, 240, 101, 17, 13, 18, 33, 34, 68, 95, 125, 195};
+static u16 adc_weight_section_discharge_lmt_1c[] = {110, 160, 230, 280, 240, 101, 17, 13, 18, 33, 34, 68, 95, 125, 195};
+static u16 adc_weight_section_discharge_llt_1c[] = {110, 160, 230, 280, 240, 101, 17, 13, 18, 33, 34, 68, 95, 125, 195};
+
+// This is for 0.2C
+//Discharging Weight(Room/Low/low low) // 0, 1, 3, 5, 7, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100
+ //{ 40, 80, 150, 150, 120, 59, 18, 16, 21, 39, 36, 58, 73, 80, 125};
+static u16 adc_weight_section_discharge_2c[] = {140, 180, 190, 150, 120, 105, 18, 16, 21, 39, 36, 58, 73, 80, 125};
+static u16 adc_weight_section_discharge_rlt_2c[] = {140, 180, 190, 150, 120, 105, 18, 16, 21, 39, 36, 58, 73, 80, 125};
+static u16 adc_weight_section_discharge_lt_2c[] = {140, 180, 190, 150, 120, 105, 18, 16, 21, 39, 36, 58, 73, 80, 125};
+static u16 adc_weight_section_discharge_lmt_2c[] = {140, 180, 190, 150, 120, 105, 18, 16, 21, 39, 36, 58, 73, 80, 125};
+static u16 adc_weight_section_discharge_llt_2c[] = {140, 180, 190, 150, 120, 105, 18, 16, 21, 39, 36, 58, 73, 80, 125};
+
+//Charging Weight(Room/Low/low low) // 0, 1, 3, 5, 7, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100
+//static u16 adc_weight_section_charge[] = {1000, 90, 110, 95, 68, 38, 14, 13, 15, 32, 35, 36, 40, 36, LAST_CHARGING_WEIGHT};
+static u16 adc_weight_section_charge[] = {1000, 105, 143, 121, 78, 40, 18, 17, 20, 44, 44, 48, 53, 39, LAST_CHARGING_WEIGHT};
+static u16 adc_weight_section_charge_rlt[] = {1000, 105, 143, 121, 78, 40, 18, 17, 20, 44, 44, 48, 53, 39, LAST_CHARGING_WEIGHT};
+static u16 adc_weight_section_charge_lt[] = {1000, 105, 143, 121, 78, 40, 18, 17, 20, 44, 44, 48, 53, 39, LAST_CHARGING_WEIGHT};
+static u16 adc_weight_section_charge_lmt[] = {1000, 105, 143, 121, 78, 40, 18, 17, 20, 44, 44, 48, 53, 39, LAST_CHARGING_WEIGHT};
+static u16 adc_weight_section_charge_llt[] = {1000, 105, 143, 121, 78, 40, 18, 17, 20, 44, 44, 48, 53, 39, LAST_CHARGING_WEIGHT};
+
+static struct diff_tbl dischg_diff_tbl = {
+ // 0, 2-1, 4-3, 6-5, 9-7,19-10,29-20,39-30,49-40
+ {173, 173, 143, 8, 15, 54, 40, 37, 50}, // 0.1C
+ {314, 314, 314, 145, 145, 177, 209, 221, 216}, // 0.2C
+};
+
+static u16 fg_reset_drop_offset[] = {172, 98};
+
+#endif /* USED_BATTERY_CAPACITY == BAT_CAPACITY_????MA */
+
+static u16 adc2soc_lut_length = (u16)sizeof(adc2soc_lut.soc)/sizeof(u16);
+static u16 adc2vbat_lut_length = (u16)sizeof(adc2vbat_lut.offset)/sizeof(u16);
+
+#define SEC_FUELGAUGE_I2C_SLAVEADDR (0x6D >> 1)
+
+#define ADC_HISTORY_SIZE 30
+enum {
+ ADC_CHANNEL_VOLTAGE_AVG = 0,
+ ADC_CHANNEL_VOLTAGE_OCV,
+ ADC_CHANNEL_NUM
+};
+
+/* typedef for MFD */
+#define sec_fuelgauge_dev_t struct d2199
+#define sec_fuelgauge_pdata_t struct d2199_platform_data
+
+struct adc_sample_data {
+ unsigned int cnt;
+ int total_adc;
+ int average_adc;
+ int adc_arr[ADC_HISTORY_SIZE];
+ int index;
+};
+
+struct battery_data_t {
+ unsigned int adc_check_count;
+ unsigned int monitor_polling_time;
+ unsigned int channel_voltage;
+ unsigned int channel_current;
+ const sec_bat_adc_table_data_t *ocv2soc_table;
+ unsigned int ocv2soc_table_size;
+ const sec_bat_adc_table_data_t *adc2vcell_table;
+ unsigned int adc2vcell_table_size;
+ u8 *type_str;
+};
+
+struct sec_fg_info {
+ struct d2199 *pd2199;
+ u8 vdd_hwmon_level;
+ u32 current_level;
+
+ // for voltage
+ u32 origin_volt_adc;
+ u32 current_volt_adc;
+ u32 average_volt_adc;
+ u32 current_voltage;
+ u32 average_voltage;
+ u32 sum_voltage_adc;
+ u8 reset_total_adc;
+ int sum_total_adc;
+
+ // for temperature
+ u32 current_temp_adc;
+ u32 average_temp_adc;
+ int current_temperature;
+ int average_temperature;
+ u32 sum_temperature_adc;
+
+ u32 soc;
+ u32 prev_soc;
+
+ int battery_technology;
+ int battery_present;
+ u32 capacity;
+
+ u16 average_vbat_init_adc;
+ u16 vbat_init_adc[3];
+
+ u16 vf_adc;
+ u32 vf_ohm;
+ u32 vf_lower;
+ u32 vf_upper;
+
+ u32 voltage_adc[AVG_SIZE];
+ u32 temperature_adc[AVG_SIZE];
+ u8 voltage_idx;
+ u8 temperature_idx;
+
+ u8 volt_adc_init_done;
+ u8 temp_adc_init_done;
+ struct wake_lock sleep_monitor_wakeup;
+ struct delayed_work monitor_volt_work;
+ struct delayed_work monitor_temp_work;
+ struct adc_man_res adc_res[D2199_ADC_CHANNEL_MAX];
+ u8 virtual_battery_full;
+ int charging_current;
+
+ u8 adc_mode;
+ struct mutex adclock;
+
+ int (*d2199_read_adc)(struct sec_fuelgauge_info *fuelgauge, adc_channel channel);
+};
+
+#endif /* __ADC_FUELGAUGE_H */
diff --git a/include/linux/battery/fuelgauge/dummy_fuelgauge.h b/include/linux/battery/fuelgauge/dummy_fuelgauge.h
new file mode 100644
index 00000000..41b92e68
--- /dev/null
+++ b/include/linux/battery/fuelgauge/dummy_fuelgauge.h
@@ -0,0 +1,312 @@
+/*
+ * Copyright (C) 2011 STMicroelectronics.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef __STC3115_BATTERY_H_
+#define __STC3115_BATTERY_H_
+
+#include <linux/android_alarm.h>
+
+#define GG_VERSION "2.00a"
+
+/*Function declaration*/
+int STC31xx_SetPowerSavingMode(void);
+int STC31xx_StopPowerSavingMode(void);
+int STC31xx_AlarmSet(void);
+int STC31xx_AlarmStop(void);
+int STC31xx_AlarmGet(void);
+int STC31xx_AlarmClear(void);
+int STC31xx_AlarmSetVoltageThreshold(int VoltThresh);
+int STC31xx_AlarmSetSOCThreshold(int SOCThresh);
+int STC31xx_RelaxTmrSet(int CurrentThreshold);
+
+extern int MainTrim(struct i2c_client *client);
+/* ******************************************************************************** */
+/* STC311x DEVICE SELECTION */
+/* STC3115 version only */
+/* -------------------------------------------------------------------------------- */
+#define STC3115
+#define BATD_UC8
+/* ******************************************************************************** */
+
+
+/* Private define ------------------------------------------------------------*/
+
+
+/* ******************************************************************************** */
+/* SPECIAL FUNCTIONS */
+/* -------------------------------------------------------------------------------- */
+/* */
+/* define TEMPCOMP_SOC to enable SOC temperature compensation */
+#define TEMPCOMP_SOC
+
+/* ******************************************************************************** */
+
+
+/* ******************************************************************************** */
+/* INTERNAL PARAMETERS */
+/* TO BE ADJUSTED ACCORDING TO BATTERY/APPLICATION CHARACTERISTICS */
+/* -------------------------------------------------------------------------------- */
+/* */
+#define BATT_CHG_VOLTAGE 4250 /* min voltage at the end of the charge (mV) */
+#define BATT_MIN_VOLTAGE 3300 /* nearly empty battery detection level (mV) */
+#define MAX_HRSOC 51200 /* 100% in 1/512% units*/
+#define MAX_SOC 1000 /* 100% in 0.1% units */
+/* */
+#define CHG_MIN_CURRENT 200 /* min charge current in mA */
+#define CHG_END_CURRENT 20 /* end charge current in mA */
+#define APP_MIN_CURRENT (-5) /* minimum application current consumption in mA ( <0 !) */
+#define APP_MIN_VOLTAGE 3000 /* application cut-off voltage */
+#define TEMP_MIN_ADJ (-5) /* minimum temperature for gain adjustment */
+
+#define VMTEMPTABLE { 85, 90, 100, 160, 320, 440, 840 } /* normalized VM_CNF at 60, 40, 25, 10, 0, -10C, -20C */
+
+#define AVGFILTER 4 /* average filter constant */
+
+/* ******************************************************************************** */
+
+/* Private define ------------------------------------------------------------*/
+
+#define STC31xx_SLAVE_ADDRESS 0xE0 /* STC31xx 8-bit address byte */
+
+/*Address of the STC311x register --------------------------------------------*/
+#define STC311x_REG_MODE 0x00 /* Mode Register */
+#define STC311x_REG_CTRL 0x01 /* Control and Status Register */
+#define STC311x_REG_SOC 0x02 /* SOC Data (2 bytes) */
+#define STC311x REG_COUNTER 0x04 /* Number of Conversion (2 bytes) */
+#define STC311x_REG_CURRENT 0x06 /* Battery Current (2 bytes) */
+#define STC311x_REG_VOLTAGE 0x08 /* Battery Voltage (2 bytes) */
+#define STC311x_REG_TEMPERATURE 0x0A /* Temperature */
+#define STC311x_REG_CC_ADJ_HIGH 0x0B /* CC adjustement */
+#define STC311x_REG_VM_ADJ_HIGH 0x0C /* VM adjustement */
+#define STC311x_REG_CC_ADJ_LOW 0x19 /* CC adjustement */
+#define STC311x_REG_VM_ADJ_LOW 0x1A /* VM adjustement */
+#define STC311x_ACC_CC_ADJ_HIGH 0x1B /* CC accumulator */
+#define STC311x_ACC_CC_ADJ_LOW 0x1C /* CC accumulator */
+#define STC311x_ACC_VM_ADJ_HIGH 0x1D /* VM accumulator */
+#define STC311x_ACC_VM_ADJ_LOW 0x1E /* VM accumulator */
+#define STC311x_REG_OCV 0x0D /* Battery OCV (2 bytes) */
+#define STC311x_REG_CC_CNF 0x0F /* CC configuration (2 bytes) */
+#define STC311x_REG_VM_CNF 0x11 /* VM configuration (2 bytes) */
+#define STC311x_REG_ALARM_SOC 0x13 /* SOC alarm level */
+#define STC311x_REG_ALARM_VOLTAGE 0x14 /* Low voltage alarm level */
+#define STC311x_REG_CURRENT_THRES 0x15 /* Current threshold for relaxation */
+#define STC311x_REG_RELAX_COUNT 0x16 /* Voltage relaxation counter */
+#define STC311x_REG_RELAX_MAX 0x17 /* Voltage relaxation max count */
+
+/*Bit mask definition*/
+#define STC311x_VMODE 0x01 /* Voltage mode bit mask */
+#define STC311x_ALM_ENA 0x08 /* Alarm enable bit mask */
+#define STC311x_GG_RUN 0x10 /* Alarm enable bit mask */
+#define STC311x_FORCE_CC 0x20 /* Force CC bit mask */
+#define STC311x_FORCE_VM 0x40 /* Force VM bit mask */
+#define STC311x_SOFTPOR 0x11 /* soft reset */
+#define STC311x_CLR_VM_ADJ 0x02 /* Clear VM ADJ register bit mask */
+#define STC311x_CLR_CC_ADJ 0x04 /* Clear CC ADJ register bit mask */
+
+#define STC311x_REG_ID 0x18 /* Chip ID (1 byte) */
+#define STC311x_ID 0x13 /* STC3115 ID */
+#define STC311x_ID_2 0x14 /* STC3115 ID */
+
+#define STC311x_REG_RAM 0x20 /* General Purpose RAM Registers */
+#define RAM_SIZE 16 /* Total RAM size of STC3115 in bytes */
+
+#define STC311x_REG_OCVTAB 0x30
+#define OCVTAB_SIZE 16 /* OCVTAB size of STC3115 in bytes */
+
+#define VCOUNT 4 /* counter value for 1st current/temp measurements */
+
+
+#define M_STAT 0x1010 /* GG_RUN & PORDET mask in STC311x_BattDataTypeDef status word */
+#define M_RST 0x1800 /* BATFAIL & PORDET mask */
+#define M_RUN 0x0010 /* GG_RUN mask in STC311x_BattDataTypeDef status word */
+#define M_GGVM 0x0400 /* GG_VM mask */
+#define M_BATFAIL 0x0800 /* BATFAIL mask*/
+#define M_VMOD 0x0001 /* VMODE mask */
+
+#define OK 0
+
+/* STC311x RAM test word */
+#define RAM_TSTWORD 0x53A9
+
+/* Gas gauge states */
+#define GG_INIT 'I'
+#define GG_RUNNING 'R'
+#define GG_POWERDN 'D'
+
+#define VM_MODE 1
+#define CC_MODE 0
+
+#define STC311x_VF_BATTERY_ON 200
+#define STC311x_VF_BATTERY_OFF 0
+
+/* gas gauge structure definition ------------------------------------*/
+
+#define NTEMP 7
+static const int TempTable[NTEMP] = {60, 40, 25, 10, 0, -10, -20} ; /* temperature table from 60C to -20C (descending order!) */
+static const int DefVMTempTable[NTEMP] = VMTEMPTABLE;
+
+/* Private variables ---------------------------------------------------------*/
+
+/* #define CurrentFactor (24084/SENSERESISTOR) LSB=5.88uV/R= ~24084/R/4096 - convert to mA */
+#define VoltageFactor 9011 /* LSB=2.20mV ~9011/4096 - convert to mV */
+
+
+/* structure of the STC311x battery monitoring parameters */
+typedef struct {
+ int Voltage; /* battery voltage in mV */
+ int Current; /* battery current in mA */
+ int Temperature; /* battery temperature in 0.1C */
+ int SOC; /* battery relative SOC (%) in 0.1% */
+ int OCV;
+ int AvgSOC;
+ int AvgCurrent;
+ int AvgVoltage;
+ int AvgTemperature;
+ int ChargeValue; /* remaining capacity in mAh */
+ int RemTime; /* battery remaining operating time during discharge (min) */
+ int State; /* charge (>0)/discharge(<0) state */
+ int CalStat; /* Internal status */
+ /* -- parameters -- */
+ int Vmode; /* 1=Voltage mode, 0=mixed mode */
+ int Alm_SOC; /* SOC alm level */
+ int Alm_Vbat; /* Vbat alm level */
+ int CC_cnf; /* nominal CC_cnf */
+ int VM_cnf; /* nominal VM cnf */
+ int Cnom; /* nominal capacity in mAh */
+ int Rsense; /* sense resistor */
+ int RelaxCurrent; /* current for relaxation (< C/20) */
+ int Adaptive; /* adaptive mode */
+ int CapDerating[6]; /* capacity derating in 0.1%, for temp = 60, 40, 25, 10, 0, -10 C */
+ int OCVOffset[16]; /* OCV curve adjustment */
+ int OCVOffset2[16]; /* OCV curve adjustment */
+ int ExternalTemperature;
+ int ForceExternalTemperature;
+} GasGauge_DataTypeDef;
+
+/* structure of the STC311x battery monitoring data */
+typedef struct {
+ /* STC311x data */
+ int STC_Status; /* status word */
+ int Vmode; /* 1=Voltage mode, 0=mixed mode */
+ int Voltage; /* voltage in mV */
+ int Current; /* current in mA */
+ int Temperature; /* temperature in 0.1C */
+ int HRSOC; /* uncompensated SOC in 1/512% */
+ int OCV; /* OCV in mV*/
+ int ConvCounter; /* convertion counter */
+ int RelaxTimer; /* current relax timer value */
+ int CC_adj; /* CC adj */
+ int VM_adj; /* VM adj */
+ /* results & internals */
+ int SOC; /* compensated SOC in 0.1% */
+ int AvgSOC; /* in 0.1% */
+ int AvgVoltage;
+ int AvgCurrent;
+ int AvgTemperature;
+ int AccSOC;
+ int AccVoltage;
+ int AccCurrent;
+ int AccTemperature;
+ int BattState;
+ int GG_Mode; /* 1=VM active, 0=CC active */
+ int LastMode;
+ int LastSOC;
+ int LastTemperature;
+ int BattOnline; // BATD
+ int IDCode;
+ /* parameters */
+ int Alm_SOC; /* SOC alm level in % */
+ int Alm_Vbat; /* Vbat alm level in mV */
+ int CC_cnf; /* nominal CC_cnf */
+ int VM_cnf; /* nominal VM cnf */
+ int Cnom; /* nominal capacity is mAh */
+ int Rsense; /* sense resistor in milliOhms */
+ int CurrentFactor;
+ int RelaxThreshold; /* current threshold for VM (mA) */
+ int Adaptive; /* adaptive mode */
+ int VM_TempTable[NTEMP];
+ int CapacityDerating[NTEMP];
+ char OCVOffset[OCVTAB_SIZE];
+ char OCVOffset2[OCVTAB_SIZE];
+} STC311x_BattDataTypeDef;
+
+static STC311x_BattDataTypeDef BattData; /* STC311x data */
+
+/* structure of the STC311x RAM registers for the Gas Gauge algorithm data */
+static union {
+ unsigned char db[RAM_SIZE]; /* last byte holds the CRC */
+ struct {
+ short int TstWord; /* 0-1 */
+ short int HRSOC; /* 2-3 SOC backup */
+ short int CC_cnf; /* 4-5 current CC_cnf */
+ short int VM_cnf; /* 6-7 current VM_cnf */
+ char SOC; /* 8 SOC for trace (in %) */
+ char GG_Status; /* 9 */
+ /* bytes ..RAM_SIZE-2 are free, last byte RAM_SIZE-1 is the CRC */
+ } reg;
+} GG_Ram;
+
+int Capacity_Adjust;
+
+/* -------------------------------------------------------------------------------- */
+/* INTERNAL ANDROID DRIVER PARAMETERS */
+/* TO BE ADJUSTED ACCORDING TO BATTERY/APPLICATION CHARACTERISTICS */
+/* -------------------------------------------------------------------------------- */
+
+#define STC3100_BATTERY_FULL 95
+#define STC311x_DELAY 1000
+
+/* ******************************************************************************** */
+
+/* ******************************************************************************** */
+
+static struct i2c_client *sav_client;
+
+struct stc311x_chip {
+ struct i2c_client *client;
+ struct delayed_work work;
+ struct power_supply battery;
+ struct stc311x_platform_data *pdata;
+
+ /* State Of Connect */
+ int online;
+ /* battery SOC (capacity) */
+ int batt_soc;
+ /* battery voltage */
+ int batt_voltage;
+ /* Current */
+ int batt_current;
+ /* State Of Charge */
+ int status;
+
+};
+
+struct sec_fg_info {
+ int (*battery_online)(void);
+ int (*charger_online)(void);
+ int (*charger_enable)(void);
+ int (*power_supply_register)(struct device *parent, struct power_supply *psy);
+ void (*power_supply_unregister)(struct power_supply *psy);
+
+ int Vmode; /* 1=Voltage mode, 0=mixed mode */
+ int Alm_SOC; /* SOC alm level %*/
+ int Alm_Vbat; /* Vbat alm level mV*/
+ int CC_cnf; /* nominal CC_cnf */
+ int VM_cnf; /* nominal VM cnf */
+ int Cnom; /* nominal capacity in mAh */
+ int Rsense; /* sense resistor mOhms*/
+ int RelaxCurrent; /* current for relaxation in mA (< C/20) */
+ int Adaptive; /* 1=Adaptive mode enabled, 0=Adaptive mode disabled */
+ int CapDerating[7]; /* capacity derating in 0.1%, for temp = 60, 40, 25, 10, 0, -10 °C,-20°C */
+ int OCVOffset[16]; /* OCV curve adjustment */
+ int OCVOffset2[16]; /* OCV curve adjustment */
+ int (*ExternalTemperature) (void); /*External temperature fonction, return °C*/
+ int ForceExternalTemperature; /* 1=External temperature, 0=STC3115 temperature */
+};
+
+#endif
diff --git a/include/linux/battery/fuelgauge/rt5033_fuelgauge.h b/include/linux/battery/fuelgauge/rt5033_fuelgauge.h
new file mode 100644
index 00000000..0a56bdfd
--- /dev/null
+++ b/include/linux/battery/fuelgauge/rt5033_fuelgauge.h
@@ -0,0 +1,173 @@
+/*
+ * drivers/battery/rt5033_fuelgauge.h
+ *
+ * Header of Richtek RT5033 Fuelgauge Driver
+ *
+ * Copyright (C) 2013 Richtek Technology Corp.
+ * Author: Patrick Chang <patrick_chang@richtek.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ */
+
+#ifndef RT5033_FUELGAUGE_H
+#define RT5033_FUELGAUGE_H
+
+#include <linux/i2c.h>
+#include <linux/mfd/rt5033.h>
+
+#ifdef CONFIG_DEBUG_FS
+#include <linux/debugfs.h>
+#endif /* #ifdef CONFIG_DEBUG_FS */
+
+#define FG_DRIVER_VER "2.0.2S"
+
+/* Added by Patrick */
+#define VG_COMP_NR 4
+
+typedef struct {
+ int data[VG_COMP_NR];
+} vg_comp_data_t;
+
+typedef struct {
+ union {
+ int x;
+ int voltage;
+ int soc;
+ };
+ union {
+ int y;
+ int temperature;
+ };
+ union {
+ int data[VG_COMP_NR];
+ vg_comp_data_t vg_comp;
+ int z;
+ int offset;
+ };
+} data_point_t;
+
+typedef struct {
+ int voltNR;
+ int tempNR;
+ data_point_t *vg_comp_data;
+} vg_comp_table_t;
+
+typedef struct {
+ int soc_voltNR;
+ int tempNR;
+ data_point_t *soc_offset_data;
+} soc_offset_table_t;
+
+
+enum {
+ OFFSET_CHARGING = 0,
+ OFFSET_DISCHARGING,
+ OFFSET_SPECIAL,
+ OFFSET_LOW_POWER,
+ OFFSET_NR,
+};
+
+enum {
+ VGCOMP_NORMAL = 0,
+ VGCOMP_IDLE,
+ VGCOMP_NR,
+};
+
+
+struct battery_data_t {
+ const int offset_interpolation_order[2];
+ const int vg_comp_interpolation_order[2];
+ const vg_comp_table_t vg_comp[VGCOMP_NR];
+ const soc_offset_table_t soc_offset[OFFSET_NR];
+ /* crate idle threshold*/
+ const int crate_idle_thres;
+ const int battery_type; /* 4200 or 4350 or 4400 */
+};
+
+#ifdef CONFIG_DEBUG_FS
+enum {
+ RT5033FG_OFFSET_CHARGING_SIZE = 0,
+ RT5033FG_OFFSET_CHARGING_DATA,
+ RT5033FG_OFFSET_DISCHARGING_SIZE,
+ RT5033FG_OFFSET_DISCHARGING_DATA,
+ RT5033FG_OFFSET_SPECIAL_SIZE,
+ RT5033FG_OFFSET_SPECIAL_DATA,
+ RT5033FG_OFFSET_LOW_POWER_SIZE,
+ RT5033FG_OFFSET_LOW_POWER_DATA,
+ RT5033FG_VGCOMP_NORMAL_SIZE,
+ RT5033FG_VGCOMP_NORMAL_DATA,
+ RT5033FG_VGCOMP_IDLE_SIZE,
+ RT5033FG_VGCOMP_IDLE_DATA,
+ RT5033FG_PARAM_LOCK,
+ RT5033FG_VGCOMP_IP_ORDER,
+ RT5033FG_OFFSET_IP_ORDER,
+ RT5033FG_CRATE_IDLE_THRES,
+ RT5033FG_DENTRY_NR,
+};
+
+#define RT5033_DBG_OUT_BUF_SIZE 2048
+
+#endif /* CONFIG_DEBUG_FS */
+
+struct sec_fg_info {
+ /* State Of Connect */
+ int online;
+ /* battery SOC (capacity) */
+ int batt_soc;
+ /* battery voltage */
+ int batt_voltage;
+ /* battery AvgVoltage */
+ int batt_avgvoltage;
+ /* battery OCV */
+ int batt_ocv;
+ /* Current */
+ int batt_current;
+ /* battery Avg Current */
+ int batt_avgcurrent;
+ /* battery temperatue */
+ u32 current_temp_adc;
+ /* crate idle threshold*/
+ int crate_idle_thres;
+
+ struct battery_data_t *comp_pdata;
+
+ struct mutex param_lock;
+ /* copy from platform data /
+ * DTS or update by shell script */
+ int vg_comp_interpolation_order[2];
+ int offset_interpolation_order[2];
+ vg_comp_table_t vg_comp[VGCOMP_NR];
+ soc_offset_table_t soc_offset[OFFSET_NR];
+
+ struct mutex io_lock;
+ struct device *dev;
+ int32_t temperature;; /* 0.1 deg C*/
+ /* register programming */
+ int reg_addr;
+ u8 reg_data[2];
+ uint32_t pre_soc;
+ uint32_t move_avg_offset_cnt;
+ uint32_t flag_full_charge : 1; /* 0 : no , 1 : yes*/
+ uint32_t flag_chg_status : 1; /* 0 : discharging, 1: charging*/
+ uint32_t offs_speci_case : 1;
+ uint32_t init_once : 1;
+ uint32_t volt_alert_flag : 1; /* 0 : nu-occur, 1: occur */
+ uint32_t soc_alert_flag : 1; /* 0 : nu-occur, 1: occur */
+ uint32_t bat_pres_flag : 1; /* 0 : removed, 1: inserted */
+ uint32_t flag_once_full_soc : 1;
+ uint32_t entry_suspend_flag : 1;
+ int32_t irq_ctrl;
+ int battery_type; /* 4200 or 4350 or 4400*/
+
+#ifdef CONFIG_DEBUG_FS
+ struct dentry *dir_dentry;
+ struct dentry *file_dentries[RT5033FG_DENTRY_NR];
+ char dbg_out_buffer[RT5033_DBG_OUT_BUF_SIZE];
+#endif /* #ifdef CONFIG_DEBUG_FS */
+};
+
+
+#endif // RT5033_FUELGAUGE_H
diff --git a/include/linux/battery/fuelgauge/rt5033_fuelgauge_impl.h b/include/linux/battery/fuelgauge/rt5033_fuelgauge_impl.h
new file mode 100644
index 00000000..cfc0a42e
--- /dev/null
+++ b/include/linux/battery/fuelgauge/rt5033_fuelgauge_impl.h
@@ -0,0 +1,96 @@
+/*
+ * drivers/battery/rt5033_fuelgauge-impl.h
+ *
+ * Header of Richtek RT5033 Fuelgauge Driver Implementation
+ *
+ * Copyright (C) 2013 Richtek Technology Corp.
+ * Author: Richtek Gauge Team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ */
+
+#ifndef RT5033_FUELGAUGE_IMPL_H
+#define RT5033_FUELGAUGE_IMPL_H
+
+/* Definitions of RT5033 Fuelgauge Registers */
+
+#define RT5033_OCV_MSB 0x00
+#define RT5033_OCV_LSB 0x01
+#define RT5033_VBAT_MSB 0x02
+#define RT5033_VBAT_LSB 0x03
+#define RT5033_SOC_MSB 0x04
+#define RT5033_SOC_LSB 0x05
+#define RT5033_CRATE 0x08
+#define RT5033_DEVICE_ID 0x09
+#define RT5033_AVG_VOLT_MSB 0x0A
+#define RT5033_AVG_VOLT_LSB 0x0B
+#define RT5033_CONFIG_MSB 0x0C
+#define RT5033_CONFIG_LSB 0x0D
+#define RT5033_FG_IRQ_CTRL 0x10
+#define RT5033_FG_IRQ_FLAG 0x11
+#define RT5033_VOLT_ALRT_TH 0x12
+#define RT5033_SOC_ALRT_TH 0x13
+#define RT5033_VGCOMP1 0x20
+#define RT5033_VGCOMP2 0x21
+#define RT5033_VGCOMP3 0x22
+#define RT5033_VGCOMP4 0x23
+#define RT5033_MFA_MSB 0xFE
+#define RT5033_MFA_LSB 0xFF
+
+#define EOC_LOCK_TH 99 /* unit : % */
+#define VALRT_LOCK_TH 1 /* unit : % */
+#define SMOOTH_SOC_STEP 1 /* unit : % */
+#define CHG_IR_EXCEPT_SOC 10 /* unit : % */
+#define QUICK_ROUTINE_TIME 1 /* unit : sec */
+#define NORMAL_ROUTINE_TIME 30 /* unit : sec */
+#define MFA_CMD_EOC_SOC 0x8664
+#define MFA_CMD_VALRT_SOC 0x8600
+#define SOC_ALRT_TOP 12
+#define SOC_ALRT_HIGH 6
+#define SOC_ALRT_LOW 3
+#define SOC_ALRT_BOTTOM 1
+#define BAT_REMOVAL_SOC 50
+#define ROUNDUP_SOC_TH 5
+#define VALRT_LOCK_TH 1
+#define MFA_CMD_EXIT_HIB 0x7400
+#define MFA_CMD_ENTRY_HIB 0x74AA
+#define FULL_SOC 100
+
+#define VOLT_ALRT_TH 0 //disable /* unit : 20mV*/
+#define VALRT_SOC 0 /* unit : % */
+
+
+#define GAIN_RANGE1 -20
+#define GAIN_RANGE2 5
+#define GAIN_RANGE3 25
+#define GAIN_RANGE4 45
+#define GAIN_TABLE1_INDEX 1
+#define GAIN_TABLE2_INDEX 2
+#define GAIN_TABLE3_INDEX 3
+#define GAIN_TABLE4_INDEX 4
+
+#define OFFS_THRES_DSG_N20 -20
+#define OFFS_THRES_CHG_25 25
+#define OFFS_THRES_DSG_25 25
+#define OFFS_TABLE1_INDEX 1
+#define OFFS_TABLE2_INDEX 2
+#define OFFS_TABLE3_INDEX 3
+#define OFFS_TABLE4_INDEX 4
+
+#define LOOKUP_GAIN 1
+#define LOOKUP_OFFS 2
+
+#define R5_TEMP 10 /* unit : oC */
+#define MFA_CMD_R5_DEFAULT 0x8501
+#define MFA_CMD_R5_LOW_TEMP 0x8503
+
+#define ENABLE_SOC_OFFSET_COMP 0
+#define ENABLE_LOCK_SOC 0
+#define ENABLE_SMOOTH_SOC 0
+#define ENABLE_SOC_IRREVERSIBLE 0
+
+
+#endif // RT5033_FUELGAUGE_IMPL_H
diff --git a/include/linux/battery/fuelgauge/sprd27x3_fuelgauge4samsung.h b/include/linux/battery/fuelgauge/sprd27x3_fuelgauge4samsung.h
new file mode 100755
index 00000000..aa3af8cf
--- /dev/null
+++ b/include/linux/battery/fuelgauge/sprd27x3_fuelgauge4samsung.h
@@ -0,0 +1,18 @@
+
+#ifndef _SPRD27X3_FUELGAUGE4SAMSUNG_H_
+#define _SPRD27X3_FUELGAUGE4SAMSUNG_H_
+
+#include <linux/types.h>
+#include <linux/battery/sec_charger.h>
+#include <linux/battery/sec_fuelgauge.h>
+#include <linux/sprd_battery_common.h>
+#include "../power/sprd_2713_fgu.h"
+#include "../power/sprd_battery.h"
+
+
+struct battery_data_t {
+ struct sprd_battery_platform_data *pdata;
+};
+
+#endif
+
diff --git a/include/linux/battery/fuelgauge/stc3115_fuelgauge.h b/include/linux/battery/fuelgauge/stc3115_fuelgauge.h
new file mode 100644
index 00000000..9df863ce
--- /dev/null
+++ b/include/linux/battery/fuelgauge/stc3115_fuelgauge.h
@@ -0,0 +1,285 @@
+/*
+ * Copyright (C) 2011 STMicroelectronics.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef __STC3115_BATTERY_H_
+#define __STC3115_BATTERY_H_
+
+/* Slave address should be shifted to the right 1bit.
+ * R/W bit should NOT be included.
+ */
+#define GG_VERSION "2.00a"
+
+/* #define CurrentFactor (24084/SENSERESISTOR) LSB=5.88uV/R= ~24084/R/4096 - convert to mA */
+#define VoltageFactor 9011 /* LSB=2.20mV ~9011/4096 - convert to mV */
+
+/* ******************************************************************************** */
+/* STC311x DEVICE SELECTION */
+/* STC3115 version only */
+/* -------------------------------------------------------------------------------- */
+#define STC3115
+#define BATD_UC8
+/* ******************************************************************************** */
+
+/* Private define ------------------------------------------------------------*/
+
+
+/* ******************************************************************************** */
+/* SPECIAL FUNCTIONS */
+/* -------------------------------------------------------------------------------- */
+/* */
+/* define TEMPCOMP_SOC to enable SOC temperature compensation */
+#define TEMPCOMP_SOC
+
+/* ******************************************************************************** */
+
+
+/* ******************************************************************************** */
+/* INTERNAL PARAMETERS */
+/* TO BE ADJUSTED ACCORDING TO BATTERY/APPLICATION CHARACTERISTICS */
+/* -------------------------------------------------------------------------------- */
+/* */
+#define BATT_CHG_VOLTAGE 4100 /* min voltage at the end of the charge (mV) */
+#define BATT_MIN_VOLTAGE 3300 /* nearly empty battery detection level (mV) */
+#define MAX_HRSOC 51200 /* 100% in 1/512% units*/
+#define MAX_SOC 1000 /* 100% in 0.1% units */
+/* */
+#define CHG_MIN_CURRENT 200 /* min charge current in mA */
+#define CHG_END_CURRENT 20 /* end charge current in mA */
+#define APP_MIN_CURRENT (-5) /* minimum application current consumption in mA ( <0 !) */
+#define APP_MIN_VOLTAGE 3000 /* application cut-off voltage */
+#define TEMP_MIN_ADJ (-5) /* minimum temperature for gain adjustment */
+
+#define VMTEMPTABLE { 85, 90, 100, 160, 320, 440, 840 } /* normalized VM_CNF at 60, 40, 25, 10, 0, -10C, -20C */
+
+#define AVGFILTER 4 /* average filter constant */
+
+/* ******************************************************************************** */
+
+
+
+/* Private define ------------------------------------------------------------*/
+
+#define STC31xx_SLAVE_ADDRESS (0xE0>>1) /* STC31xx 8-bit address byte */
+
+/*Address of the STC311x register --------------------------------------------*/
+#define STC311x_REG_MODE 0x00 /* Mode Register */
+#define STC311x_REG_CTRL 0x01 /* Control and Status Register */
+#define STC311x_REG_SOC 0x02 /* SOC Data (2 bytes) */
+#define STC311x_REG_COUNTER 0x04 /* Number of Conversion (2 bytes) */
+#define STC311x_REG_CURRENT 0x06 /* Battery Current (2 bytes) */
+#define STC311x_REG_VOLTAGE 0x08 /* Battery Voltage (2 bytes) */
+#define STC311x_REG_TEMPERATURE 0x0A /* Temperature */
+#define STC311x_REG_CC_ADJ_HIGH 0x0B /* CC adjustement */
+#define STC311x_REG_VM_ADJ_HIGH 0x0C /* VM adjustement */
+#define STC311x_REG_CC_ADJ_LOW 0x19 /* CC adjustement */
+#define STC311x_REG_VM_ADJ_LOW 0x1A /* VM adjustement */
+#define STC311x_ACC_CC_ADJ_HIGH 0x1B /* CC accumulator */
+#define STC311x_ACC_CC_ADJ_LOW 0x1C /* CC accumulator */
+#define STC311x_ACC_VM_ADJ_HIGH 0x1D /* VM accumulator */
+#define STC311x_ACC_VM_ADJ_LOW 0x1E /* VM accumulator */
+#define STC311x_REG_OCV 0x0D /* Battery OCV (2 bytes) */
+#define STC311x_REG_CC_CNF 0x0F /* CC configuration (2 bytes) */
+#define STC311x_REG_VM_CNF 0x11 /* VM configuration (2 bytes) */
+#define STC311x_REG_ALARM_SOC 0x13 /* SOC alarm level */
+#define STC311x_REG_ALARM_VOLTAGE 0x14 /* Low voltage alarm level */
+#define STC311x_REG_CURRENT_THRES 0x15 /* Current threshold for relaxation */
+#define STC311x_REG_RELAX_COUNT 0x16 /* Voltage relaxation counter */
+#define STC311x_REG_RELAX_MAX 0x17 /* Voltage relaxation max count */
+
+/*Bit mask definition*/
+#define STC311x_VMODE 0x01 /* Voltage mode bit mask */
+#define STC311x_ALM_ENA 0x08 /* Alarm enable bit mask */
+#define STC311x_GG_RUN 0x10 /* Alarm enable bit mask */
+#define STC311x_FORCE_CC 0x20 /* Force CC bit mask */
+#define STC311x_FORCE_VM 0x40 /* Force VM bit mask */
+#define STC311x_SOFTPOR 0x11 /* soft reset */
+#define STC311x_CLR_VM_ADJ 0x02 /* Clear VM ADJ register bit mask */
+#define STC311x_CLR_CC_ADJ 0x04 /* Clear CC ADJ register bit mask */
+
+#define STC311x_REG_ID 0x18 /* Chip ID (1 byte) */
+#define STC311x_ID 0x13 /* STC3115 ID */
+#define STC311x_ID_2 0x14 /* STC3115 ID */
+
+#define STC311x_REG_RAM 0x20 /* General Purpose RAM Registers */
+#define RAM_SIZE 16 /* Total RAM size of STC3115 in bytes */
+
+#define STC311x_REG_OCVTAB 0x30
+#define OCVTAB_SIZE 16 /* OCVTAB size of STC3115 in bytes */
+
+#define VCOUNT 4 /* counter value for 1st current/temp measurements */
+
+
+#define M_STAT 0x1010 /* GG_RUN & PORDET mask in STC311x_BattDataTypeDef status word */
+#define M_RST 0x1800 /* BATFAIL & PORDET mask */
+#define M_RUN 0x0010 /* GG_RUN mask in STC311x_BattDataTypeDef status word */
+#define M_GGVM 0x0400 /* GG_VM mask */
+#define M_BATFAIL 0x0800 /* BATFAIL mask*/
+#define M_VMOD 0x0001 /* VMODE mask */
+
+#define OK 0
+
+/* Battery charge state definition for BattState */
+#define BATT_CHARGING 3
+#define BATT_ENDCHARG 2
+#define BATT_FULCHARG 1
+#define BATT_IDLE 0
+#define BATT_DISCHARG (-1)
+#define BATT_LOWBATT (-2)
+
+/* STC311x RAM test word */
+#define RAM_TSTWORD 0x53A9
+
+/* Gas gauge states */
+#define GG_INIT 'I'
+#define GG_RUNNING 'R'
+#define GG_POWERDN 'D'
+
+#define VM_MODE 1
+#define CC_MODE 0
+
+/* gas gauge structure definition ------------------------------------*/
+
+/* Private constants ---------------------------------------------------------*/
+
+#define NTEMP 7
+static const int TempTable[NTEMP] = {60, 40, 25, 10, 0, -10, -20} ; /* temperature table from 60C to -20C (descending order!) */
+static const int DefVMTempTable[NTEMP] = VMTEMPTABLE;
+
+
+struct battery_data_t {
+ int Vmode; /* 1=Voltage mode, 0=mixed mode */
+ int Alm_SOC; /* SOC alm level %*/
+ int Alm_Vbat; /* Vbat alm level mV*/
+ int CC_cnf; /* nominal CC_cnf */
+ int VM_cnf; /* nominal VM cnf */
+ int Cnom; /* nominal capacity in mAh */
+ int Rsense; /* sense resistor mOhms*/
+ int RelaxCurrent; /* current for relaxation in mA (< C/20) */
+ int Adaptive; /* 1=Adaptive mode enabled, 0=Adaptive mode disabled */
+ int CapDerating[7]; /* capacity derating in 0.1%, for temp = 60, 40, 25, 10, 0, -10 C,-20C */
+ int OCVOffset[16]; /* OCV curve adjustment */
+ int OCVOffset2[16]; /* OCV curve adjustment */
+ int (*ExternalTemperature) (void); /*External temperature fonction, return C*/
+ int ForceExternalTemperature; /* 1=External temperature, 0=STC3115 temperature */
+};
+
+struct sec_fg_info {
+ /* State Of Connect */
+ int online;
+ /* battery SOC (capacity) */
+ int batt_soc;
+ /* battery voltage */
+ int batt_voltage;
+ /* battery AvgVoltage */
+ int batt_avgvoltage;
+ /* battery OCV */
+ int batt_ocv;
+ /* Current */
+ int batt_current;
+ /* battery Avg Current */
+ int batt_avgcurrent;
+ /* battery temperatue */
+ int temperature;
+};
+
+typedef struct {
+ /* STC311x data */
+ int STC_Status; /* status word */
+ int Vmode; /* 1=Voltage mode, 0=mixed mode */
+ int Voltage; /* voltage in mV */
+ int Current; /* current in mA */
+ int Temperature; /* temperature in 0.1C */
+ int HRSOC; /* uncompensated SOC in 1/512% */
+ int OCV; /* OCV in mV*/
+ int ConvCounter; /* convertion counter */
+ int RelaxTimer; /* current relax timer value */
+ int CC_adj; /* CC adj */
+ int VM_adj; /* VM adj */
+ /* results & internals */
+ int SOC; /* compensated SOC in 0.1% */
+ int AvgSOC; /* in 0.1% */
+ int AvgVoltage;
+ int AvgCurrent;
+ int AvgTemperature;
+ int AccSOC;
+ int AccVoltage;
+ int AccCurrent;
+ int AccTemperature;
+ int BattState;
+ int GG_Mode; /* 1=VM active, 0=CC active */
+ int LastMode;
+ int LastSOC;
+ int LastTemperature;
+ int BattOnline; // BATD
+ int IDCode;
+ /* parameters */
+ int Alm_SOC; /* SOC alm level in % */
+ int Alm_Vbat; /* Vbat alm level in mV */
+ int CC_cnf; /* nominal CC_cnf */
+ int VM_cnf; /* nominal VM cnf */
+ int Cnom; /* nominal capacity is mAh */
+ int Rsense; /* sense resistor in milliOhms */
+ int CurrentFactor;
+ int RelaxThreshold; /* current threshold for VM (mA) */
+ int Adaptive; /* adaptive mode */
+ int VM_TempTable[NTEMP];
+ int CapacityDerating[NTEMP];
+ char OCVOffset[OCVTAB_SIZE];
+ char OCVOffset2[OCVTAB_SIZE];
+} STC311x_BattDataTypeDef;
+
+static STC311x_BattDataTypeDef BattData; /* STC311x data */
+
+/* structure of the STC311x battery monitoring parameters */
+typedef struct {
+ int Voltage; /* battery voltage in mV */
+ int Current; /* battery current in mA */
+ int Temperature; /* battery temperature in 0.1C */
+ int SOC; /* battery relative SOC (%) in 0.1% */
+ int OCV;
+ int AvgSOC;
+ int AvgCurrent;
+ int AvgVoltage;
+ int AvgTemperature;
+ int ChargeValue; /* remaining capacity in mAh */
+ int RemTime; /* battery remaining operating time during discharge (min) */
+ int State; /* charge (>0)/discharge(<0) state */
+ int CalStat; /* Internal status */
+ /* -- parameters -- */
+ int Vmode; /* 1=Voltage mode, 0=mixed mode */
+ int Alm_SOC; /* SOC alm level */
+ int Alm_Vbat; /* Vbat alm level */
+ int CC_cnf; /* nominal CC_cnf */
+ int VM_cnf; /* nominal VM cnf */
+ int Cnom; /* nominal capacity in mAh */
+ int Rsense; /* sense resistor */
+ int RelaxCurrent; /* current for relaxation (< C/20) */
+ int Adaptive; /* adaptive mode */
+ int CapDerating[6]; /* capacity derating in 0.1%, for temp = 60, 40, 25, 10, 0, -10 C */
+ int OCVOffset[16]; /* OCV curve adjustment */
+ int OCVOffset2[16]; /* OCV curve adjustment */
+ int ExternalTemperature;
+ int ForceExternalTemperature;
+} GasGauge_DataTypeDef;
+
+
+/* structure of the STC311x RAM registers for the Gas Gauge algorithm data */
+static union {
+ unsigned char db[RAM_SIZE]; /* last byte holds the CRC */
+ struct {
+ short int TstWord; /* 0-1 */
+ short int HRSOC; /* 2-3 SOC backup */
+ short int CC_cnf; /* 4-5 current CC_cnf */
+ short int VM_cnf; /* 6-7 current VM_cnf */
+ char SOC; /* 8 SOC for trace (in %) */
+ char GG_Status; /* 9 */
+ /* bytes ..RAM_SIZE-2 are free, last byte RAM_SIZE-1 is the CRC */
+ } reg;
+} GG_Ram;
+
+#endif /* __DUMMY_FUELGAUGE_H */