Patchwork [U-Boot,v2,20/21] arm:trats:pmic: Support for charging battery at Samsung's TRATS board

login
register
mail settings
Submitter Łukasz Majewski
Date Oct. 5, 2012, 8:16 a.m.
Message ID <1349425003-32523-21-git-send-email-l.majewski@samsung.com>
Download mbox | patch
Permalink /patch/189446/
State Changes Requested
Delegated to: Stefano Babic
Headers show

Comments

Łukasz Majewski - Oct. 5, 2012, 8:16 a.m.
The battery connected to Samsung's Trats development board is now
charged when voltage drops below threshold.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Cc: Minkyu Kang <mk7.kang@samsung.com>
---
Changes for v2:
- Define separate *p_{} pointer instances for each power device available
  at Trats
- Only basic checks performed
- Core responsible for battery charging moved to separate file -
  ./drivers/power/bat_trats.c
---
 board/samsung/trats/trats.c |   27 +++++++++++++++++++++++++++
 1 files changed, 27 insertions(+), 0 deletions(-)

Patch

diff --git a/board/samsung/trats/trats.c b/board/samsung/trats/trats.c
index f6a62d0..cda5af7 100644
--- a/board/samsung/trats/trats.c
+++ b/board/samsung/trats/trats.c
@@ -282,6 +282,9 @@  static int pmic_init_max8997(void)
 #ifdef CONFIG_POWER_INIT
 int power_board_init(void)
 {
+	int chrg;
+	struct power_battery *pb;
+	struct pmic *p_fg, *p_chrg, *p_muic, *p_bat;
 
 #ifdef CONFIG_PMIC
 	pmic_init(I2C_5);
@@ -290,6 +293,30 @@  int power_board_init(void)
 	power_fg_init(I2C_9);
 	power_muic_init(I2C_5);
 	power_bat_init(0);
+	p_fg = pmic_get("MAX17042_FG");
+	p_chrg = pmic_get("MAX8997_PMIC");
+	p_muic = pmic_get("MAX8997_MUIC");
+	p_bat = pmic_get("BAT_TRATS");
+
+	p_fg->battery_init(p_fg, p_bat);
+	p_chrg->battery_init(p_chrg, p_bat);
+	p_muic->battery_init(p_muic, p_bat);
+
+	p_bat->low_power_mode = trats_low_power_mode;
+	pb = p_bat->pwr_bat;
+	chrg = pb->chrg_type(pb->muic);
+	debug("CHARGER TYPE: %d\n", chrg);
+
+	if (!pb->chrg_bat_present(pb->chrg)) {
+		puts("No battery detected\n");
+		return -1;
+	}
+
+	pb->fg_battery_check(pb->fg, p_bat);
+
+	if (pb->bat->state == CHARGE && chrg == CHARGER_USB)
+		puts("CHARGE Battery !\n");
+
 	return 0;
 }
 #endif