Firefly Open Source Community

   Login   |   Register   |
New_Topic
Print Previous Topic Next Topic

How to use RK818 PMIC to control charge current and voltage

18

Credits

0

Prestige

0

Contribution

new registration

Rank: 1

Credits
18

How to use RK818 PMIC to control charge current and voltage

Posted at 2/25/2016 17:27:14      View:3799 | Replies:0        Print      Only Author   [Copy Link] 1#
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
  1.         battery {
  2. design_capacity = <2100>;
  3.                 design_qmax = <2200>;
  4.                 max_overcharge = <100>;
  5. <font color="red">                /*max_charge_currentmA = <1500>;*/
  6.                 /*max_charge_voltagemV = <4260>;*/
  7.                 max_charge_currentmA = <3000>;
  8.                 max_charge_voltagemV = <4350>;</font>
  9.                 max_bat_voltagemV = <4200>;
  10.                 sleep_enter_current = <100>;
  11.                 sleep_exit_current = <130>;
  12.                 support_uboot_chrg = <0>;
  13.         };
Copy the code


2. RK818_battery.c
  1. <1>
  2. static void set_charge_current(struct battery_info *di, int charge_current)
  3. {
  4.         u8 usb_ctrl_reg;

  5.         battery_read(di->rk818, USB_CTRL_REG, &usb_ctrl_reg, 1);

  6. <font color="red">        //@
  7.         //usb_ctrl_reg &= (~0x0f);/* (VLIM_4400MV | ILIM_1200MA) |(0x01 << 7); */
  8.         usb_ctrl_reg &= (~0x8f);/* (VLIM_4400MV | ILIM_1200MA) |(0x01 << 7); */</font>

  9. <font color="red">        //@@@KevinHan        
  10.         //usb_ctrl_reg |= (charge_current | CHRG_CT_EN);
  11.         //usb_ctrl_reg |= (charge_current);
  12.         usb_ctrl_reg |= ILIM_3000MA;</font>        
  13.         
  14.         battery_write(di->rk818, USB_CTRL_REG, &usb_ctrl_reg, 1);
  15. }

  16. <2>
  17. static void rk_battery_charger_init(struct  battery_info *di)
  18. {
  19.         u8 chrg_ctrl_reg1, usb_ctrl_reg, chrg_ctrl_reg2, chrg_ctrl_reg3;
  20.         u8 sup_sts_reg, dcdc_en_reg1;

  21.         DBG("%s  start\n", __func__);
  22.         battery_read(di->rk818, USB_CTRL_REG, &usb_ctrl_reg, 1);
  23.         battery_read(di->rk818, CHRG_CTRL_REG1, &chrg_ctrl_reg1, 1);
  24.         battery_read(di->rk818, CHRG_CTRL_REG2, &chrg_ctrl_reg2, 1);
  25.         battery_read(di->rk818, SUP_STS_REG, &sup_sts_reg, 1);
  26.         battery_read(di->rk818, CHRG_CTRL_REG3, &chrg_ctrl_reg3, 1);


  27.         DBG("old usb_ctrl_reg = 0x%2x, CHRG_CTRL_REG1 = 0x%2x\n ", usb_ctrl_reg, chrg_ctrl_reg1);

  28. <font color="red">        //@
  29.         //usb_ctrl_reg &= (~0x0f);
  30.         usb_ctrl_reg &= (~0x8f);</font>        
  31.         
  32. #ifdef SUPPORT_USB_CHARGE

  33. <font color="red">        //@
  34.         //usb_ctrl_reg |= (ILIM_450MA | CHRG_CT_EN);
  35.         usb_ctrl_reg |= (ILIM_3000MA | CHRG_CT_EN);
  36.         //usb_ctrl_reg |= ILIM_3000MA;</font>        

  37. #else
  38. <font color="red">        //@
  39.         //usb_ctrl_reg |= (ILIM_3000MA | CHRG_CT_EN);
  40.         usb_ctrl_reg |= ILIM_3000MA;</font>        
  41.         
  42. #endif
  43.         chrg_ctrl_reg1 &= (0x00);

  44. <font color="red">        //@
  45.         //chrg_ctrl_reg1 |= (CHRG_EN) | (CHRG_VOL4200 | CHRG_CUR1400mA);
  46.         chrg_ctrl_reg1 |= (CHRG_EN) | (CHRG_VOL4350 | CHRG_CUR3000mA);</font>        

  47.         chrg_ctrl_reg3 |= CHRG_TERM_DIG_SIGNAL;/* digital finish mode*/
  48.         chrg_ctrl_reg2 &= ~(0xc0);
  49.         chrg_ctrl_reg2 |= FINISH_100MA;

  50.         //sup_sts_reg &= ~(0x01 << 3);
  51.         //sup_sts_reg |= (0x01 << 2);

  52.         //@
  53.         //dcdc_en_reg1 |= (0x3 << 5);          //enable switch1/2
  54.         //dcdc_en_reg1 |= (0x1 << 4);          //enable boost

  55.         battery_write(di->rk818, CHRG_CTRL_REG3, &chrg_ctrl_reg3, 1);
  56.         battery_write(di->rk818, USB_CTRL_REG, &usb_ctrl_reg, 1);
  57.         battery_write(di->rk818, CHRG_CTRL_REG1, &chrg_ctrl_reg1, 1);
  58.         battery_write(di->rk818, CHRG_CTRL_REG2, &chrg_ctrl_reg2, 1);
  59.         battery_write(di->rk818, SUP_STS_REG, &sup_sts_reg, 1);

  60.         //@
  61.         //battery_write(di->rk818, RK818_DCDC_EN_REG, &dcdc_en_reg1, 1);

  62.         debug_reg(di, CHRG_CTRL_REG1, "CHRG_CTRL_REG1");
  63.         debug_reg(di, SUP_STS_REG, "SUP_STS_REG");
  64.         debug_reg(di, USB_CTRL_REG, "USB_CTRL_REG");
  65.         debug_reg(di, CHRG_CTRL_REG1, "CHRG_CTRL_REG1");

  66.         DBG("%s  end\n", __func__);
  67. }

  68. <3>
  69. static int  get_charging_status_type(struct battery_info *di)
  70. {
  71.         if (di->ac_online == 1)
  72.                 set_charge_current(di, ILIM_3000MA);
  73.         else
  74.                 //@@@KevinHan
  75.                 set_charge_current(di, ILIM_3000MA);               
  76.                 //set_charge_current(di, ILIM_450MA);
  77. }

  78. <4>
  79. static void battery_poweron_status_init(struct battery_info *di)
  80. {
  81. ………………………………
  82. <font color="red">//@
  83. //set_charge_current(di, ILIM_450MA);               
  84. set_charge_current(di, ILIM_3000MA);</font>
  85. ………………………………
  86. }
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>

  1. <p>realx-voltage = 0, voltage = 4237, current-avg = 786
  2. fcc = 2100, remain_capacity = 2100, ocv_volt = 3872
  3. diplay_soc = 100, cpapacity_soc = 100</p><p>
  4. AC-ONLINE = 0, USB-ONLINE = 1, charging_status = 4
  5. finish_real_soc = 0, finish_temp_soc = 0
  6. chrg_time = 50, dischrg_time = 0</p><p>
  7. healthd: battery l=100 v=4237 t=2.6 h=2 st=5 c=786 chg=au
  8. dump_debug_info:
  9. GGCON = 0x42, GGSTS = 0x40, RTC    = 0x24
  10. SUP_STS_REG  = 0xb7, VB_MOD_REG       = 0x56
  11. USB_CTRL_REG  = 0x7b,
  12. CHRG_CTRL_REG1 = 0xda
  13. CHRG_CTRL_REG2 = 0x a, CHRG_CTRL_REG3 = 0x22
  14. </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

Reply

Use props Report

You need to log in before you can reply Login | Register

This forum Credits Rules

Quick Reply Back to top Back to list