pndevmapperd: add unexpected charge stop workaround
authorGrazvydas Ignotas <notasas@gmail.com>
Thu, 4 Aug 2011 22:37:22 +0000 (01:37 +0300)
committerGrazvydas Ignotas <notasas@gmail.com>
Thu, 4 Aug 2011 23:15:37 +0000 (02:15 +0300)
My machine in some real rare cases (once a week or so) just stops
charging without any good reason. What helps here is replugging
the charger or writing to a chip charge register, so we do the later
indirectly every 20 minutes as a workaround.

There have been similar reports in the forums, where user leaves
the machine charging overnight and finds flat battery in the morning,
so hopefully this will help them too.

apps/pndevmapperd.c

index b5301f1..3f860ed 100644 (file)
@@ -869,7 +869,7 @@ void sigalrm_handler ( int n ) {
 
   pnd_log ( pndn_debug, "---[ SIGALRM ]---\n" );
 
 
   pnd_log ( pndn_debug, "---[ SIGALRM ]---\n" );
 
-  static time_t last_charge_check;
+  static time_t last_charge_check, last_charge_worka;
   int batlevel = pnd_device_get_battery_gauge_perc();
   int uamps = 0;
   time_t now;
   int batlevel = pnd_device_get_battery_gauge_perc();
   int uamps = 0;
   time_t now;
@@ -935,6 +935,16 @@ void sigalrm_handler ( int n ) {
         pnd_log ( pndn_debug, "Charge start conditions reached, enabling charging\n" );
         pnd_device_set_charger_enable ( bc_charge_device, 1 );
       }
         pnd_log ( pndn_debug, "Charge start conditions reached, enabling charging\n" );
         pnd_device_set_charger_enable ( bc_charge_device, 1 );
       }
+
+      // for some unknown reason it just stops charging randomly (happens once per week or so),
+      // and does not restart, resulting in a flat battery if machine is unattended.
+      // What seems to help here is writing to chip registers, we can do it here indirectly
+      // by writing to enable. Doing it occasionally should do no harm even with missing charger.
+      if ( batlevel <= bc_startcap && (unsigned int)(now - last_charge_worka) > 20*60 ) {
+        pnd_log ( pndn_debug, "Charge workaround trigger\n" );
+        pnd_device_set_charger_enable ( bc_charge_device, 1 );
+        last_charge_worka = now;
+      }
     }
     last_charge_check = now;
   }
     }
     last_charge_check = now;
   }