Firefly Open Source Community
Title: How to use RK818 PMIC to control charge current and voltage [Print This Page]
Author: kevinhan Time: 2/25/2016 17:27
Title: How to use RK818 PMIC to control charge current and voltage
Last edited by kevinhan In 3/3/2016 15:52 Editor
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.
1. 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>;
- };
Copy the code
2. 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>
- ¡¡¡¡¡¡¡¡¡¡¡¡
- }
Copy the code
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.
<Consuming charging current and input voltage to the fireprime>
- <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>
Copy the code
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.04 KB, Down times: 7
Author: markhal730 Time: 1/17/2026 14:51
I¡¯m in awe of your insights, thank you for sharing your article! The Latest CDT braindumps pdf test questions are free¡ªgood luck with your exam preparations!
Author: georgen662 Time: 1/23/2026 05:20
Thank you for sharing this remarkable article, it truly impressed me. PCNSE reliable braindumps questions questions are essential for your career success¡ªget them for free!
Author: tedbell907 Time: 2/14/2026 02:18
Your article was so impactful, thank you for sharing it. The Valid F5CAB1 exam online exam questions are available for free¡ªunlock your promotion and salary increase!
Author: seanbro867 Time: 2/15/2026 23:55
Thank you for sharing this truly remarkable article! The Valid 1Y0-204 real test questions system helped me secure a promotion and salary increase. Now, I¡¯m sharing it for free. Best of luck in your career!
| Welcome Firefly Open Source Community (https://bbs.t-firefly.com/) |
Powered by Discuz! X3.1 |