Dear all.
I’m a new comer using Fireprime board and now I’m trying to control the function for charge voltage and current to make battery(Li-ion : 4200mAh 3.7V) charging with Voltage 4.350mV & Current 3A by input board operating 5V from power supply on Android 5.1(Lollipop) that firefly released.
You can see the board layout between battery and board in this photo
Then I modified the dts(device tree) file and c language source code as the following especially Red Color and also you can refer to the attached files for figuring out what amended part I did.
- RK312x-sdk.dtsi
battery {
design_capacity = <2100>;
design_qmax = <2200>;
max_overcharge = <100>;
<font color="red"> /*max_charge_currentmA = <1500>;*/
/*max_charge_voltagemV = <4260>;*/
max_charge_currentmA = <3000>;
max_charge_voltagemV = <4350>;</font>
max_bat_voltagemV = <4200>;
sleep_enter_current = <100>;
sleep_exit_current = <130>;
support_uboot_chrg = <0>;
};
- RK818_battery.c
<1>
static void set_charge_current(struct battery_info *di, int charge_current)
{
u8 usb_ctrl_reg;
battery_read(di->rk818, USB_CTRL_REG, &usb_ctrl_reg, 1);
<font color="red"> //@
//usb_ctrl_reg &= (~0x0f);/* (VLIM_4400MV | ILIM_1200MA) |(0x01 << 7); */
usb_ctrl_reg &= (~0x8f);/* (VLIM_4400MV | ILIM_1200MA) |(0x01 << 7); */</font>
<font color="red"> //@@@KevinHan
//usb_ctrl_reg |= (charge_current | CHRG_CT_EN);
//usb_ctrl_reg |= (charge_current);
usb_ctrl_reg |= ILIM_3000MA;</font>
battery_write(di->rk818, USB_CTRL_REG, &usb_ctrl_reg, 1);
}
<2>
static void rk_battery_charger_init(struct battery_info *di)
{
u8 chrg_ctrl_reg1, usb_ctrl_reg, chrg_ctrl_reg2, chrg_ctrl_reg3;
u8 sup_sts_reg, dcdc_en_reg1;
DBG("%s start\n", __func__);
battery_read(di->rk818, USB_CTRL_REG, &usb_ctrl_reg, 1);
battery_read(di->rk818, CHRG_CTRL_REG1, &chrg_ctrl_reg1, 1);
battery_read(di->rk818, CHRG_CTRL_REG2, &chrg_ctrl_reg2, 1);
battery_read(di->rk818, SUP_STS_REG, &sup_sts_reg, 1);
battery_read(di->rk818, CHRG_CTRL_REG3, &chrg_ctrl_reg3, 1);
DBG("old usb_ctrl_reg = 0x%2x, CHRG_CTRL_REG1 = 0x%2x\n ", usb_ctrl_reg, chrg_ctrl_reg1);
<font color="red"> //@
//usb_ctrl_reg &= (~0x0f);
usb_ctrl_reg &= (~0x8f);</font>
#ifdef SUPPORT_USB_CHARGE
<font color="red"> //@
//usb_ctrl_reg |= (ILIM_450MA | CHRG_CT_EN);
usb_ctrl_reg |= (ILIM_3000MA | CHRG_CT_EN);
//usb_ctrl_reg |= ILIM_3000MA;</font>
#else
<font color="red"> //@
//usb_ctrl_reg |= (ILIM_3000MA | CHRG_CT_EN);
usb_ctrl_reg |= ILIM_3000MA;</font>
#endif
chrg_ctrl_reg1 &= (0x00);
<font color="red"> //@
//chrg_ctrl_reg1 |= (CHRG_EN) | (CHRG_VOL4200 | CHRG_CUR1400mA);
chrg_ctrl_reg1 |= (CHRG_EN) | (CHRG_VOL4350 | CHRG_CUR3000mA);</font>
chrg_ctrl_reg3 |= CHRG_TERM_DIG_SIGNAL;/* digital finish mode*/
chrg_ctrl_reg2 &= ~(0xc0);
chrg_ctrl_reg2 |= FINISH_100MA;
//sup_sts_reg &= ~(0x01 << 3);
//sup_sts_reg |= (0x01 << 2);
//@
//dcdc_en_reg1 |= (0x3 << 5); //enable switch1/2
//dcdc_en_reg1 |= (0x1 << 4); //enable boost
battery_write(di->rk818, CHRG_CTRL_REG3, &chrg_ctrl_reg3, 1);
battery_write(di->rk818, USB_CTRL_REG, &usb_ctrl_reg, 1);
battery_write(di->rk818, CHRG_CTRL_REG1, &chrg_ctrl_reg1, 1);
battery_write(di->rk818, CHRG_CTRL_REG2, &chrg_ctrl_reg2, 1);
battery_write(di->rk818, SUP_STS_REG, &sup_sts_reg, 1);
//@
//battery_write(di->rk818, RK818_DCDC_EN_REG, &dcdc_en_reg1, 1);
debug_reg(di, CHRG_CTRL_REG1, "CHRG_CTRL_REG1");
debug_reg(di, SUP_STS_REG, "SUP_STS_REG");
debug_reg(di, USB_CTRL_REG, "USB_CTRL_REG");
debug_reg(di, CHRG_CTRL_REG1, "CHRG_CTRL_REG1");
DBG("%s end\n", __func__);
}
<3>
static int get_charging_status_type(struct battery_info *di)
{
if (di->ac_online == 1)
set_charge_current(di, ILIM_3000MA);
else
//@@@KevinHan
set_charge_current(di, ILIM_3000MA);
//set_charge_current(di, ILIM_450MA);
}
<4>
static void battery_poweron_status_init(struct battery_info *di)
{
………………………………
<font color="red">//@
//set_charge_current(di, ILIM_450MA);
set_charge_current(di, ILIM_3000MA);</font>
………………………………
}
As a result of measuring of charging current, I got only charging voltage 4.2V current 1.8A that is not my goal , even though the values of RK818 registers are showing suitable configuration in the following kernel log
That means USB_ILIM_SEL is 3A / Charging voltage and current are 4.35V as well as 3A as you can see.
<p>realx-voltage = 0, voltage = 4237, current-avg = 786
fcc = 2100, remain_capacity = 2100, ocv_volt = 3872
diplay_soc = 100, cpapacity_soc = 100</p><p>
AC-ONLINE = 0, USB-ONLINE = 1, charging_status = 4
finish_real_soc = 0, finish_temp_soc = 0
chrg_time = 50, dischrg_time = 0</p><p>
healthd: battery l=100 v=4237 t=2.6 h=2 st=5 c=786 chg=au
dump_debug_info:
GGCON = 0x42, GGSTS = 0x40, RTC = 0x24
SUP_STS_REG = 0xb7, VB_MOD_REG = 0x56
USB_CTRL_REG = 0x7b,
CHRG_CTRL_REG1 = 0xda
CHRG_CTRL_REG2 = 0x a, CHRG_CTRL_REG3 = 0x22
</p>
So I’m wondering that how to configure it up apparently for charging voltage and current( 4.35V and 3A) to the battery
In the case of hooking up the battery directly to power supply without fireprime board by setting up 4.3V for the battery charging test, there is no problem to see that consuming charge current was going up to almost 3A . So Battery has no problem I think.
Is there anyone help to give me some good idea ?
Thanks in advance.
KevinHan.
rk818_battery.zip (17 KB)



