Index: firmware/export/config-c200.h =================================================================== --- firmware/export/config-c200.h (revision 17423) +++ firmware/export/config-c200.h (working copy) @@ -119,8 +119,8 @@ #define BATTERY_CAPACITY_INC 0 /* capacity increment */ #define BATTERY_TYPES_COUNT 1 /* only one type */ -/* Hardware controlled charging? FIXME */ -#define CONFIG_CHARGING CHARGING_SIMPLE +/* Hardware controlled charging with monitoring of charge status */ +#define CONFIG_CHARGING CHARGING_MONITORING /* define this if the unit can be powered or charged via USB */ #define HAVE_USB_POWER Index: firmware/export/config-e200.h =================================================================== --- firmware/export/config-e200.h (revision 17423) +++ firmware/export/config-e200.h (working copy) @@ -114,8 +114,8 @@ #define BATTERY_CAPACITY_INC 0 /* capacity increment */ #define BATTERY_TYPES_COUNT 1 /* only one type */ -/* Hardware controlled charging? FIXME */ -#define CONFIG_CHARGING CHARGING_SIMPLE +/* Hardware controlled charging with monitoring of charge status */ +#define CONFIG_CHARGING CHARGING_MONITOR /* define this if the unit can be powered or charged via USB */ #define HAVE_USB_POWER Index: firmware/target/arm/sandisk/adc-target.h =================================================================== --- firmware/target/arm/sandisk/adc-target.h (revision 17423) +++ firmware/target/arm/sandisk/adc-target.h (working copy) @@ -38,6 +38,8 @@ #define ADC_I_MICSUP2 11 /* Current of MicSup2 for remote control detection */ #define ADC_VBAT 12 /* Single cell battery voltage */ -#define ADC_UNREG_POWER ADC_BVDD /* For compatibility */ +/* ADC_RTCSUP seems to represent battery voltage better than ADC_BVDD during + charging (ADC_BVDD is way too high) and appears the same in normal use. */ +#define ADC_UNREG_POWER ADC_RTCSUP /* For compatibility */ #endif Index: firmware/target/arm/sandisk/power-c200_e200.c =================================================================== --- firmware/target/arm/sandisk/power-c200_e200.c (revision 17423) +++ firmware/target/arm/sandisk/power-c200_e200.c (working copy) @@ -25,8 +25,18 @@ #include "as3514.h" #include "power.h" +/* mA, 50 - 400 in steps of 50 */ +#define CHARGE_CURRENT (BATTERY_CAPACITY_DEFAULT/3) +/* mV, 3900 - 4250 in steps of 50 */ +#define CHARGE_VOLTAGE 4100 + void power_init(void) { + /* configure charger */ + pp_i2c_send(AS3514_I2C_ADDR, AS3514_CHARGER, (((CHARGE_CURRENT - 50) / 50) << 4) | + (((CHARGE_VOLTAGE - 3900) / 50) << 1)); + /* enable charger interrupts */ + pp_i2c_send(AS3514_I2C_ADDR, AS3514_IRQ_ENRD0, 0xF0); } void power_off(void) @@ -62,6 +72,32 @@ return false; } +bool charging_state(void) +{ + unsigned char status; + + /* check if charging cable is inserted */ + if (!charger_inserted()) { + return false; + } + + /* check CHG_status bit in charger status */ + status = i2c_readbyte(AS3514_I2C_ADDR, AS3514_IRQ_ENRD0); + if ((status & (1 << 5)) == 0) + { + return false; + } + /* check CHG_endofch bit in charger status */ + if ((status & (1 << 6)) != 0) + { + /* set CHG_OFF bit to disable charger */ + pp_i2c_send(AS3514_I2C_ADDR, AS3514_CHARGER, (1 << 0)); + return false; + } + + return true; +} + void ide_power_enable(bool on) { (void)on;