Skip to content

Commit

Permalink
driver: act8865: Add suspending ACT8945A charger
Browse files Browse the repository at this point in the history
Setting the SUSCHG bit of APCH register 0x71 to suspend
charging, so that the PMIC charger function is systematically
disabled after boot.

This function is disabled by default, you can enable it by
make menuconfig.

Signed-off-by: Wenyou Yang <wenyou.yang@atmel.com>
  • Loading branch information
wenyouya committed Jun 24, 2016
1 parent 8da6113 commit 1685427
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Config.in
Expand Up @@ -332,6 +332,14 @@ config CONFIG_DISABLE_ACT8865_I2C
There are some issue about active-semi ACT8865's I2C interface,
which affects the other chip which stands on the same I2C bus, such as MXT touchscreen.

config CONFIG_SUSPEND_ACT8945A_CHARGER
bool "Suspend ACT8945A Charger"
select CONFIG_ACT8865
default n
help
This interface let you to suspend the ACT8945A charger
function after boot.

endmenu

config CONFIG_ACT8865
Expand Down
60 changes: 60 additions & 0 deletions driver/act8865.c
Expand Up @@ -291,3 +291,63 @@ void act8865_workaround(void)
#endif
}
#endif

/**
* ACT8945A Charger Registers Map
*/
/* 0x70: Reserved */
#define ACT8945A_APCH_CFG 0x71
#define ACT8945A_APCH_STATUS 0x78
#define ACT8945A_APCH_CTRL 0x79
#define ACT8945A_APCH_STATE 0x7A

/* ACT8945A_APCH_CFG */
#define APCH_CFG_OVPSET (0x3 << 0)
#define APCH_CFG_PRETIMO (0x3 << 2)
#define APCH_CFG_TOTTIMO (0x3 << 4)
#define APCH_CFG_SUSCHG (0x1 << 7)

/* ACT8945A_APCH_STATE */
#define APCH_STATE_ACINSTAT (0x1 << 1)
#define APCH_STATE_CSTATE (0x3 << 4)
#define APCH_STATE_CSTATE_SHIFT 4
#define APCH_STATE_CSTATE_DISABLED 0x00
#define APCH_STATE_CSTATE_EOC 0x01
#define APCH_STATE_CSTATE_FAST 0x02
#define APCH_STATE_CSTATE_PRE 0x03

#ifdef CONFIG_SUSPEND_ACT8945A_CHARGER
int act8945a_suspend_charger(void)
{
unsigned char data;
int ret;

if (!twi_init_done)
twi_init();

ret = act8865_read(ACT8945A_APCH_CFG, &data);
if (ret)
return -1;

data |= APCH_CFG_SUSCHG;
ret = act8865_write(ACT8945A_APCH_CFG, data);
if (ret)
return -1;

ret = act8865_read(ACT8945A_APCH_STATE, &data);
if (ret)
return -1;

if ((data & APCH_STATE_CSTATE) != APCH_STATE_CSTATE_DISABLED) {
dbg_loud("ACT8945A: Failed to suspend charger\n");
return -1;
}

return 0;
}
#else
int act8945a_suspend_charger(void)
{
return 0;
}
#endif
4 changes: 4 additions & 0 deletions driver/driver_cpp.mk
Expand Up @@ -229,6 +229,10 @@ ifeq ($(CONFIG_DISABLE_ACT8865_I2C), y)
CPPFLAGS += -DCONFIG_DISABLE_ACT8865_I2C
endif

ifeq ($(CONFIG_SUSPEND_ACT8945A_CHARGER), y)
CPPFLAGS += -DCONFIG_SUSPEND_ACT8945A_CHARGER
endif

ifeq ($(CONFIG_PM), y)
CPPFLAGS += -DCONFIG_PM
endif
Expand Down
1 change: 1 addition & 0 deletions include/act8865.h
Expand Up @@ -108,5 +108,6 @@ extern int act8865_check_i2c_disabled(void);

extern int act8865_set_power_saving_mode(void);
extern void act8865_workaround(void);
extern int act8945a_suspend_charger(void);

#endif
2 changes: 2 additions & 0 deletions main.c
Expand Up @@ -78,6 +78,8 @@ int main(void)

#ifdef CONFIG_ACT8865
act8865_workaround();

act8945a_suspend_charger();
#endif

init_load_image(&image);
Expand Down

0 comments on commit 1685427

Please sign in to comment.