From: Jianhong Chen Date: Tue, 20 Jun 2017 01:42:12 +0000 (+0800) Subject: power: rk818-battery: update ts1 current select X-Git-Tag: release-20171130_firefly~4^2~349 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=2bdcc84d452ffecf97fc2312bf39064a825085b9;p=firefly-linux-kernel-4.4.55.git power: rk818-battery: update ts1 current select select 40uA when temperature lower than 0'C, otherwise 60uA. Change-Id: Ib235441c3adb146b8d1746a435875c19b1d8624d Signed-off-by: Jianhong Chen --- diff --git a/drivers/power/rk818_battery.c b/drivers/power/rk818_battery.c index 378fea9e3feb..caa4e23a8a8e 100644 --- a/drivers/power/rk818_battery.c +++ b/drivers/power/rk818_battery.c @@ -383,6 +383,20 @@ static int rk818_bat_get_coulomb_cap(struct rk818_battery *di) return (val / 2390) * di->res_div; } +static int rk818_bat_ts1_cur_init(struct rk818_battery *di, int ua) +{ + u8 buf; + + buf = rk818_bat_read(di, RK818_TS_CTRL_REG); + buf &= TS1_CUR_MSK; + buf |= ((ua - 20) / 20); + rk818_bat_write(di, RK818_TS_CTRL_REG, buf); + + di->pdata->ntc_cur = ua; + + return 0; +} + static int rk818_bat_get_rsoc(struct rk818_battery *di) { int remain_cap; @@ -2576,8 +2590,14 @@ static int rk818_bat_get_ntc_res(struct rk818_battery *di) val |= rk818_bat_read(di, RK818_TS1_ADC_REGL) << 0; val |= rk818_bat_read(di, RK818_TS1_ADC_REGH) << 8; - val = val * NTC_CALC_FACTOR; /*reference voltage 2.2V,current 80ua*/ - DBG("<%s>. ntc_res=%d\n", __func__, val); + if (di->pdata->ntc_cur == 80) + val = val * 7; /* reference voltage 2.2V,current 80ua */ + else if (di->pdata->ntc_cur == 60) + val = val * 9; /* reference voltage 2.2V,current 60ua */ + else if (di->pdata->ntc_cur == 40) + val = val * 13; /* reference voltage 2.2V,current 40ua */ + DBG("<%s>. ntc_res=%d, ntc_cur=%d\n", + __func__, val, di->pdata->ntc_cur); return val; } @@ -2620,6 +2640,10 @@ static void rk818_bat_update_temperature(struct rk818_battery *di) break; } di->temperature = (i + di->pdata->ntc_degree_from) * 10; + if (i + di->pdata->ntc_degree_from <= 0) + rk818_bat_ts1_cur_init(di, 40); + else + rk818_bat_ts1_cur_init(di, 60); rk818_bat_temp_notifier_callback(di->temperature / 10); } } @@ -2913,6 +2937,8 @@ static void rk818_bat_init_ts1_detect(struct rk818_battery *di) if (!di->pdata->ntc_size) return; + rk818_bat_ts1_cur_init(di, 60); + /* ADC_TS1_EN */ buf = rk818_bat_read(di, RK818_ADC_CTRL_REG); buf |= ADC_TS1_EN; diff --git a/drivers/power/rk818_battery.h b/drivers/power/rk818_battery.h index a1deaf34e73e..c5ccec8745d2 100644 --- a/drivers/power/rk818_battery.h +++ b/drivers/power/rk818_battery.h @@ -27,6 +27,7 @@ #define ADC_CUR_EN BIT(6) #define ADC_TS1_EN BIT(5) #define ADC_TS2_EN BIT(4) +#define TS1_CUR_MSK 0xfc /* RK818_GGCON */ #define OCV_SAMP_MIN_MSK 0x0c @@ -126,6 +127,7 @@ struct battery_platform_data { u32 fb_temp; u32 energy_mode; u32 cccv_hour; + u32 ntc_cur; }; enum work_mode {