power: rk818-battery: update ts1 current select
authorJianhong Chen <chenjh@rock-chips.com>
Tue, 20 Jun 2017 01:42:12 +0000 (09:42 +0800)
committerHuang, Tao <huangtao@rock-chips.com>
Wed, 21 Jun 2017 06:08:00 +0000 (14:08 +0800)
select 40uA when temperature lower than 0'C, otherwise 60uA.

Change-Id: Ib235441c3adb146b8d1746a435875c19b1d8624d
Signed-off-by: Jianhong Chen <chenjh@rock-chips.com>
drivers/power/rk818_battery.c
drivers/power/rk818_battery.h

index 378fea9e3feb842c3149ccd821d2d4dff42ee899..caa4e23a8a8ec67550db49fc71eb021b1a8bfcca 100644 (file)
@@ -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;
index a1deaf34e73e6d37016502ff6e50d6763c93f6c2..c5ccec8745d2bb704563a2cae3dbf2a1534bd660 100644 (file)
@@ -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 {