Hi,

I tried to charge my Freerunner with a car charger yesterday but I had no
success.
The reason for this: If there's no USB host connected that tells u-boot to
charge at 500mA it will call pcf50633_usb_maxcurrent with 0 and this
essentially disables charging.

So I made a patch to fix this problem and also some other charger-related
issues:
* I disabled the call to cpu_idle because it breaks USB communication *
LED now only flashes for 10ms instead of 1s, charging should be faster now
* prevent 1s sleep if battery is already charged -> faster startup * Fixed
comment, removed obosolete TODO

I now that there's not much interest in u-boot anymore and it's preferred
to move code into the linux kernel but:
Can anyone please merge this patch?

Thanks,
Philipp
>From a7b5c1f7509b0d97cb5a394953b4ea927b0a4fde Mon Sep 17 00:00:00 2001
From: Philipp Hug <phil...@hug.cx>
Date: Fri, 9 Jan 2009 00:18:32 +0100
Subject: [PATCH] charger fixes
 * Always charge with at least 100mA to support stupid chargers
 * don't call cpu_idle because it breaks USB communication
 * flash LED only for 10ms
 * don't wait 1s if battery is charged already for faster startup
 * fixed some comments

---
 board/neo1973/gta02/gta02.c |   55 ++++++++++++++++++++++--------------------
 1 files changed, 29 insertions(+), 26 deletions(-)

diff --git a/board/neo1973/gta02/gta02.c b/board/neo1973/gta02/gta02.c
index a59a513..4255caa 100644
--- a/board/neo1973/gta02/gta02.c
+++ b/board/neo1973/gta02/gta02.c
@@ -322,6 +322,11 @@ static void set_revision(void)
 
 static void poll_charger(void)
 {
+	/* charge with at least 100 mA otherwise dumb chargers won't work*/
+	if (udc_usb_maxcurrent < 100) {
+		udc_usb_maxcurrent = 100;
+	}
+
 	if (pcf50633_read_charger_type() == 1000)
 		pcf50633_usb_maxcurrent(1000);
 	else /* track what the time-critical udc callback allows us */
@@ -406,46 +411,38 @@ static int battery_is_good(void)
 
 static int wait_for_power(void)
 {
-	/*
-	 * TODO: this function should also check if charger is still attached
-	 * it makes no sense to wait otherwise.
-	*/
-
 	int seconds = 0;
 	int led_cycle = 1;
 	int power = 1;
 
 	while (1) {
 		poll_charger();
+		#if 0
+		/* Print current power setting for debugging */
+		printf("wait_for_power %i\n",pcf50633_usb_last_maxcurrent);
+		#endif
 
 		/* we have plenty of external power but no visible battery ->
 		 * don't hang around trying to charge, try to boot */
 		if (!battery_is_present() && (pcf50633_usb_last_maxcurrent >= 500))
 			break;
 
-		/* cpu_idle sits with interrupts off destroying USB operation
-		 * don't run it unless we are in trouble
+		/*
+		 * Probe the battery only if the current LED cycle is
+		 * about to end, so that it had time to discharge.
+		 * This only works, if the charger is off before
+		 * wait_for_power is called.
+		 * Reason: 1s faster startup time
 		 */
-		if (!battery_is_good())
-			cpu_idle();
-		else
-			udelay(1000000);
+		if (led_cycle && battery_is_good())
+			break;
 
-		if (neo1973_new_second()) {
-			/*
-			 * Probe the battery only if the current LED cycle is
-			 * about to end, so that it had time to discharge.
-			 */
-			if (led_cycle && battery_is_good())
-				break;
-
-			/* check if charger is present, otherwise stop start up */
-			if (!charger_is_present()) {
-				power = 0;
-				break;
-			}
-			seconds++;
+		/* check if charger is present, otherwise stop start up */
+		if (!charger_is_present()) {
+			power = 0;
+			break;
 		}
+		seconds++;
 
 		led_cycle = !seconds || (seconds & 1);
 
@@ -465,6 +462,12 @@ static int wait_for_power(void)
 		 * didn't kill us then don't let it kill us later
 		 */
                 pcf50633_reg_write(PCF50633_REG_OOCSHDWN, 4);
+
+		if (led_cycle)
+			udelay(10000);
+		else
+			udelay(1000000);
+
 	}
 
 	/* switch off the AUX LED */
@@ -564,7 +567,7 @@ woken_by_reset:
 	neo1973_poweroff();
 
 continue_boot:
-	/* Power off if no battery is present and only 100mA is available */
+	/* Power off if no battery is present */
 	if (!wait_for_power())
 		neo1973_poweroff();
 
-- 
1.6.0.4
_______________________________________________
devel mailing list
devel@lists.openmoko.org
https://lists.openmoko.org/mailman/listinfo/devel

Reply via email to