Skip to content

Commit

Permalink
Merge pull request #413 from FrameworkComputer/s5_power
Browse files Browse the repository at this point in the history
[modify] control charger psys and acok reference
  • Loading branch information
kiram9 authored Feb 21, 2022
2 parents 78b8e29 + 05d1a55 commit 8109392
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
54 changes: 53 additions & 1 deletion board/hx20/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,56 @@ static void check_chassis_open(int init)
}
}

void charge_psys_onoff(uint8_t enable)
{
int control0 = 0x0000;
int control1 = 0x0000;
int control4 = 0x0000;
int data = 0x0000;

if (i2c_read16(I2C_PORT_CHARGER, ISL9241_ADDR_FLAGS,
ISL9241_REG_CONTROL1, &control1)) {
CPRINTS("read charger control1 fail");
}

if (enable) {
control0 &= ~ISL9241_CONTROL0_NGATE;
control1 &= ~(ISL9241_CONTROL1_IMON | ISL9241_CONTROL1_BGATE);
control1 |= ISL9241_CONTROL1_PSYS;
control4 &= ~ISL9241_CONTROL4_GP_COMPARATOR;
data = 0x0B00;
CPRINTS("Power saving disable");
} else {
control0 |= ISL9241_CONTROL0_NGATE;
control1 |= (ISL9241_CONTROL1_IMON | ISL9241_CONTROL1_BGATE);
control1 &= ~ISL9241_CONTROL1_PSYS;
control4 |= ISL9241_CONTROL4_GP_COMPARATOR;
data = 0x0000;
CPRINTS("Power saving enable");
}


if (i2c_write16(I2C_PORT_CHARGER, ISL9241_ADDR_FLAGS,
ISL9241_REG_ACOK_REFERENCE, data)) {
CPRINTS("Update charger ACOK reference fail");
}

if (i2c_write16(I2C_PORT_CHARGER, ISL9241_ADDR_FLAGS,
ISL9241_REG_CONTROL0, control0)) {
CPRINTS("Update charger control0 fail");
}

if (i2c_write16(I2C_PORT_CHARGER, ISL9241_ADDR_FLAGS,
ISL9241_REG_CONTROL1, control1)) {
CPRINTS("Update charger control1 fail");
}

if (i2c_write16(I2C_PORT_CHARGER, ISL9241_ADDR_FLAGS,
ISL9241_REG_CONTROL4, control4)) {
CPRINTS("Update charger control4 fail");
}
}

/* Initialize board. */
static void board_init(void)
{
Expand Down Expand Up @@ -529,6 +579,7 @@ static void board_chipset_startup(void)
if (version > 6)
gpio_set_level(GPIO_EN_INVPWR, 1);

charge_psys_onoff(1);
}
DECLARE_HOOK(HOOK_CHIPSET_STARTUP,
board_chipset_startup,
Expand All @@ -547,6 +598,7 @@ static void board_chipset_shutdown(void)
if (version > 6)
gpio_set_level(GPIO_EN_INVPWR, 0);

charge_psys_onoff(0);
}
DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN,
board_chipset_shutdown,
Expand Down Expand Up @@ -783,7 +835,7 @@ void charger_update(void)
CPRINTS("update charger!!");

val = ISL9241_CONTROL1_PROCHOT_REF_6800 |
ISL9241_CONTROL1_SWITCH_FREQ | ISL9241_CONTROL1_PSYS;
ISL9241_CONTROL1_SWITCH_FREQ;

if (i2c_write16(I2C_PORT_CHARGER, ISL9241_ADDR_FLAGS,
ISL9241_REG_CONTROL1, val)) {
Expand Down
4 changes: 4 additions & 0 deletions driver/charger/isl9241.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#define ISL9241_REG_CONTROL0 0x39
/* 2: Input Voltage Regulation (0 = Enable (default), 1 = Disable) */
#define ISL9241_CONTROL0_INPUT_VTG_REGULATION BIT(2)
#define ISL9241_CONTROL0_NGATE BIT(12)


#define ISL9241_REG_INFORMATION1 0x3A
Expand All @@ -52,6 +53,8 @@
#define ISL9241_CONTROL1_PROCHOT_REF_6800 (7 << 0)
#define ISL9241_CONTROL1_SWITCH_FREQ (5 << 7)
#define ISL9241_CONTROL1_PSYS BIT(3)
#define ISL9241_CONTROL1_IMON BIT(5)
#define ISL9241_CONTROL1_BGATE BIT(6)
#define ISL9241_CONTROL1_SUPPLEMENTAL_SUPPORT_MODE BIT(10)

/* Configures various charger options */
Expand Down Expand Up @@ -112,6 +115,7 @@
/* 13: Enable VSYS slew rate control (0 - disable, 1 - enable) */
#define ISL9241_CONTROL4_ACOK_PROCHOT BIT(5)
#define ISL9241_CONTROL4_OTG_CURR_PROCHOT BIT(7)
#define ISL9241_CONTROL4_GP_COMPARATOR BIT(12)
#define ISL9241_CONTROL4_SLEW_RATE_CTRL BIT(13)

#define ISL9241_REG_CONTROL5 0x4F
Expand Down

0 comments on commit 8109392

Please sign in to comment.