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

login
register
mail settings
Submitter Łukasz Majewski
Date Sept. 14, 2012, 3:40 p.m.
Message ID <1347637215-4830-16-git-send-email-l.majewski@samsung.com>
Download mbox | patch
Permalink /patch/183960/
State Superseded
Delegated to: Minkyu Kang
Headers show

Comments

Łukasz Majewski - Sept. 14, 2012, 3:40 p.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>
---
 board/samsung/trats/trats.c |   37 +++++++++++++++++++++++++++++++++++++
 1 files changed, 37 insertions(+), 0 deletions(-)
Tom Rini - Sept. 14, 2012, 5:32 p.m.
On Fri, Sep 14, 2012 at 05:40:14PM +0200, Lukasz Majewski wrote:

> The battery connected to Samsung's Trats development board is now
> charged when voltage drops below threshold.
[snip]
> @@ -247,6 +250,40 @@ int power_board_init(void)
>  	pmic_init_max8997();
>  	power_fg_init(I2C_9);
>  	power_muic_init(I2C_5);
> +
> +	chrg = power_chrg_get_type();
> +	debug("CHARGER TYPE: %d\n", chrg);
> +
> +	if (!pmic_charger_bat_present()) {
> +		puts("No battery detected\n");
> +		return -1;
> +	}
> +
> +	power_check_battery(&bat);
> +
> +	if (bat.state == CHARGE && chrg == CHARGER_USB) {
> +		puts("CHARGER ENABLE\n");
> +		if (pmic_charger_state(CHARGER_ENABLE, 450))
> +			return -1;
> +
> +		for (k = 0; pmic_charger_bat_present() &&
> +			     power_chrg_get_type() &&
> +			     bat.state_of_chrg < 5; k++) {
> +			udelay(10000000);
> +			puts(".");
> +			power_update_battery(&bat);
> +
> +			if (k == 100) {
> +				printf(" %d [V]\n", bat.voltage_uV);
> +				k = 0;
> +			}
> +
> +		}
> +
> +		puts("CHARGER DISABLE\n");
> +		pmic_charger_state(CHARGER_DISABLE, 0);
> +	}

If I read this right we'll pause in the middle of start up to charge the
battery for possibly a long time right?  And this could be a while loop
even, yes?  If so to the first one, this really should be under some
sort of CONFIG option.  I know the value of showing proof of concept
type examples in development boards but that should still be an opt-in
thing I would think.
Lukasz Majewski - Sept. 17, 2012, 8:55 p.m.
Hi Tom ,

> If I read this right we'll pause in the middle of start up to charge
> the battery for possibly a long time right?  And this could be a
> while loop even, yes?  If so to the first one, this really should be
> under some sort of CONFIG option.

This is one of the options. Other option is to extend the pmic/power
command to:

pmic charger on/off to recharge battery when needed.

I think, that above is a better solution.

> I know the value of showing proof of concept
> type examples in development boards but that should still be an opt-in
> thing I would think.

Yes, indeed this shall be regarded as a proof-of-concept to show that
battery is automatically charged when needed.

Instead, I think, that it would be a good idea to write a warning on
the u-boot starting (when PMIC driver is initialized):

e.g. WARNING: Battery needs charging (voltage: 3.5V capacity: 8%)

And then user can on its own decide if he/she will charge the battery or
not.

Regards,
Lukasz Majewski
Tom Rini - Sept. 17, 2012, 9:27 p.m.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 09/17/12 13:55, Lukasz Majewski wrote:
> Hi Tom ,
> 
>> If I read this right we'll pause in the middle of start up to
>> charge the battery for possibly a long time right?  And this
>> could be a while loop even, yes?  If so to the first one, this
>> really should be under some sort of CONFIG option.
> 
> This is one of the options. Other option is to extend the
> pmic/power command to:
> 
> pmic charger on/off to recharge battery when needed.
> 
> I think, that above is a better solution.
> 
>> I know the value of showing proof of concept type examples in
>> development boards but that should still be an opt-in thing I
>> would think.
> 
> Yes, indeed this shall be regarded as a proof-of-concept to show
> that battery is automatically charged when needed.
> 
> Instead, I think, that it would be a good idea to write a warning
> on the u-boot starting (when PMIC driver is initialized):
> 
> e.g. WARNING: Battery needs charging (voltage: 3.5V capacity: 8%)
> 
> And then user can on its own decide if he/she will charge the
> battery or not.

Yes, sounds good, thanks!

- -- 
Tom
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://www.enigmail.net/

iQIcBAEBAgAGBQJQV5XMAAoJENk4IS6UOR1WnXYP/iZdtirR6Rflcp/YZSna/ld0
SsW0cW8fGT+Hy44T2pOsd4m0ne/WnTq6EUPJqQ1xs+ZIjj55Uh2ngLdc3/PpMC10
mi+vzm3E1wi8Wm83205r+7DAWnD20JXE413WimaBnP+EbVJzBjtZDFyFwtpvKnFd
G2SyVyUsyBATsMFpfz7yFwNPYB9JoG/XgsLK64nP3wCVt/gSB6hE+ZBrRQgKvvsn
AvQV3JhZbPMSWIj9Qq1qY8ReA2fC5SXBft/mcOt6cee7dTlaTzXkK3dxDQkmzOF8
l1Lhm3h/QMQ6/+mlghk9tZmfR7kXH54Ak0tZWLXQiT86namTymvgQ/SyOE8B0Rf8
p0+rD6X9WcuirhyeoKOmQS/cx6S1evNuPXJiRRGN3Y52nwWEnYlsDyDWEOqqLa70
466hdJhLm14HguJCsRbjs2l+rJ4pRj0WaKio7dq3uk0ojwueZRqSZyI6UEBQLMQU
NBZExliUI+6TNBFVdmpaRe9cKVaDIbmtFWH8yl6xNAsU0MgOH15OsZOdQUO3bTgb
sZPKHWKhiZbS16kMGGdvcb18up1qA/oXZJcnPD/rmyCQ4Tq/Z6eOt9CRwZyLss9p
cUVb2PXJ6X4r6eTaK9HMAAk9zYZkk0pcmZcczsdcNhVv3MJlxwmNEfYY6RXfRdaI
Dh3242syeDsez5ZQ3Uou
=v4oy
-----END PGP SIGNATURE-----

Patch

diff --git a/board/samsung/trats/trats.c b/board/samsung/trats/trats.c
index 6462b30..21050c8 100644
--- a/board/samsung/trats/trats.c
+++ b/board/samsung/trats/trats.c
@@ -39,6 +39,7 @@ 
 #include <power/max8997_pmic.h>
 #include <libtizen.h>
 #include <power/max8997_muic.h>
+#include <power/power_chrg.h>
 #include <power/max17042_fg.h>
 
 #include "setup.h"
@@ -240,6 +241,8 @@  static int pmic_init_max8997(void)
 #ifdef CONFIG_POWER_INIT
 int power_board_init(void)
 {
+	int chrg, k;
+	struct battery bat;
 
 #ifdef CONFIG_PMIC
 	pmic_init(I2C_5);
@@ -247,6 +250,40 @@  int power_board_init(void)
 	pmic_init_max8997();
 	power_fg_init(I2C_9);
 	power_muic_init(I2C_5);
+
+	chrg = power_chrg_get_type();
+	debug("CHARGER TYPE: %d\n", chrg);
+
+	if (!pmic_charger_bat_present()) {
+		puts("No battery detected\n");
+		return -1;
+	}
+
+	power_check_battery(&bat);
+
+	if (bat.state == CHARGE && chrg == CHARGER_USB) {
+		puts("CHARGER ENABLE\n");
+		if (pmic_charger_state(CHARGER_ENABLE, 450))
+			return -1;
+
+		for (k = 0; pmic_charger_bat_present() &&
+			     power_chrg_get_type() &&
+			     bat.state_of_chrg < 5; k++) {
+			udelay(10000000);
+			puts(".");
+			power_update_battery(&bat);
+
+			if (k == 100) {
+				printf(" %d [V]\n", bat.voltage_uV);
+				k = 0;
+			}
+
+		}
+
+		puts("CHARGER DISABLE\n");
+		pmic_charger_state(CHARGER_DISABLE, 0);
+	}
+
 	return 0;
 }
 #endif