Skip to content

Commit 635a388

Browse files
JohnWC-Yehamstan
authored andcommitted
fwk: add BQ257X0 charger OOA control api
Add a helper function to enable or disable Out-of-Audio (OOA) in the BQ25770 charger driver. BRANCH=fwk-tulip-29169 BUG=none TEST=verified that toggling OOA via the API updates the CHARGE_OPTION_0 register accordingly Signed-off-by: johnwc_yeh <JohnWC_Yeh@compal.com>
1 parent 30490ed commit 635a388

3 files changed

Lines changed: 61 additions & 5 deletions

File tree

driver/charger/bq25710.c

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@
155155
/* Console output macros */
156156
#define CPRINTF(format, args...) cprintf(CC_CHARGER, format, ##args)
157157

158+
/* Mutex for OPTION0 register, that can be updated from multiple tasks. */
159+
static K_MUTEX_DEFINE(bq25710_option_0_mutex);
160+
158161
#ifdef CONFIG_CHARGER_BQ25710_IDCHG_LIMIT_MA
159162
/*
160163
* If this config option is defined, then the bq25710 needs to remain in
@@ -682,9 +685,13 @@ static enum ec_error_list bq25710_set_mode(int chgnum, int mode)
682685
int rv;
683686
int option;
684687

688+
mutex_lock(&bq25710_option_0_mutex);
689+
685690
rv = bq25710_get_option(chgnum, &option);
686-
if (rv)
691+
if (rv) {
692+
mutex_unlock(&bq25710_option_0_mutex);
687693
return rv;
694+
}
688695

689696
if (mode & CHARGER_CHARGE_INHIBITED)
690697
option = SET_BQ_FIELD(BQ257X0, CHARGE_OPTION_0, CHRG_INHIBIT, 1,
@@ -693,7 +700,10 @@ static enum ec_error_list bq25710_set_mode(int chgnum, int mode)
693700
option = SET_BQ_FIELD(BQ257X0, CHARGE_OPTION_0, CHRG_INHIBIT, 0,
694701
option);
695702

696-
return bq25710_set_option(chgnum, option);
703+
rv = bq25710_set_option(chgnum, option);
704+
705+
mutex_unlock(&bq25710_option_0_mutex);
706+
return rv;
697707
}
698708

699709
static enum ec_error_list bq25710_enable_otg_power(int chgnum, int enabled)
@@ -743,9 +753,13 @@ static enum ec_error_list bq25710_discharge_on_ac(int chgnum, int enable)
743753
{
744754
int rv, option;
745755

756+
mutex_lock(&bq25710_option_0_mutex);
757+
746758
rv = bq25710_get_option(chgnum, &option);
747-
if (rv)
759+
if (rv) {
760+
mutex_unlock(&bq25710_option_0_mutex);
748761
return rv;
762+
}
749763

750764
if (enable)
751765
option = SET_BQ_FIELD(BQ257X0, CHARGE_OPTION_0, EN_LEARN, 1,
@@ -754,7 +768,10 @@ static enum ec_error_list bq25710_discharge_on_ac(int chgnum, int enable)
754768
option = SET_BQ_FIELD(BQ257X0, CHARGE_OPTION_0, EN_LEARN, 0,
755769
option);
756770

757-
return bq25710_set_option(chgnum, option);
771+
rv = bq25710_set_option(chgnum, option);
772+
773+
mutex_unlock(&bq25710_option_0_mutex);
774+
return rv;
758775
}
759776

760777
static enum ec_error_list bq25710_set_input_current_limit(int chgnum,
@@ -915,6 +932,27 @@ int bq25710_set_min_system_voltage(int chgnum, int mv)
915932
return raw_write16(chgnum, BQ25710_REG_MIN_SYSTEM_VOLTAGE, reg);
916933
}
917934

935+
int bq25710_set_ooa(int chgnum, bool enable)
936+
{
937+
int rv, option;
938+
939+
mutex_lock(&bq25710_option_0_mutex);
940+
941+
rv = bq25710_get_option(chgnum, &option);
942+
if (rv) {
943+
mutex_unlock(&bq25710_option_0_mutex);
944+
return rv;
945+
}
946+
947+
option = SET_BQ_FIELD(BQ257X0, CHARGE_OPTION_0, EN_OOA, enable,
948+
option);
949+
950+
rv = bq25710_set_option(chgnum, option);
951+
952+
mutex_unlock(&bq25710_option_0_mutex);
953+
return rv;
954+
}
955+
918956
#ifdef CONFIG_CHARGE_RAMP_HW
919957

920958
static void bq25710_chg_ramp_handle(void)
@@ -1042,8 +1080,13 @@ DECLARE_HOOK(HOOK_CHIPSET_RESUME, bq25710_chipset_startup, HOOK_PRIO_DEFAULT);
10421080
static void bq25710_chipset_suspend(void)
10431081
{
10441082
int reg;
1045-
if (raw_read16(CHARGER_SOLO, BQ25710_REG_CHARGE_OPTION_0, &reg))
1083+
1084+
mutex_lock(&bq25710_option_0_mutex);
1085+
1086+
if (raw_read16(CHARGER_SOLO, BQ25710_REG_CHARGE_OPTION_0, &reg)) {
1087+
mutex_unlock(&bq25710_option_0_mutex);
10461088
return;
1089+
}
10471090

10481091
/*
10491092
* Enable low power mode regardless of current performance mode.
@@ -1052,6 +1095,8 @@ static void bq25710_chipset_suspend(void)
10521095

10531096
reg = SET_BQ_FIELD(BQ257X0, CHARGE_OPTION_0, EN_LWPWR, true, reg);
10541097
raw_write16(CHARGER_SOLO, BQ25710_REG_CHARGE_OPTION_0, reg);
1098+
1099+
mutex_unlock(&bq25710_option_0_mutex);
10551100
}
10561101
DECLARE_HOOK(HOOK_CHIPSET_SUSPEND, bq25710_chipset_suspend, HOOK_PRIO_DEFAULT);
10571102
DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN, bq25710_chipset_suspend, HOOK_PRIO_DEFAULT);

driver/charger/bq25710.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,13 @@ extern const struct charger_drv bq25710_drv;
8989
*/
9090
int bq25710_set_min_system_voltage(int chgnum, int mv);
9191

92+
/**
93+
* Enable or disable Out-of-Audio.
94+
*
95+
* @param chgnum: Index into charger chips
96+
* @param enable true to enable OOA, false to disable.
97+
* @return EC_SUCCESS or error
98+
*/
99+
int bq25710_set_ooa(int chgnum, bool enable);
100+
92101
#endif /* __CROS_EC_BQ25710_H */

driver/charger/bq257x0_regs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
*/
3030
#define BQ257X0_CHARGE_OPTION_0_EN_LWPWR_SHIFT 15
3131
#define BQ257X0_CHARGE_OPTION_0_EN_LWPWR_BITS 1
32+
#define BQ257X0_CHARGE_OPTION_0_EN_OOA_SHIFT 10
33+
#define BQ257X0_CHARGE_OPTION_0_EN_OOA_BITS 1
3234
#define BQ257X0_CHARGE_OPTION_0_EN_LEARN_SHIFT 5
3335
#define BQ257X0_CHARGE_OPTION_0_EN_LEARN_BITS 1
3436
#define BQ257X0_CHARGE_OPTION_0_IADP_GAIN_SHIFT 4

0 commit comments

Comments
 (0)