diff options
author | Derek Huang <derekhuang@google.com> | 2022-08-22 08:58:47 +0000 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-09-21 02:45:21 +0000 |
commit | cbf2ab787e86524eed964923e54c833b584a814f (patch) | |
tree | d9a7a946c9d010af9bdea50c77a5516b62d7bd8d | |
parent | 242a8ecb5c720f6e008f3c1af9ab5703f15b6f13 (diff) | |
download | chrome-ec-cbf2ab787e86524eed964923e54c833b584a814f.tar.gz |
common/peripheral_charger.c: Refactor pchg_startup() function
pchg_startup() should do:
1. Disable irq.
2. Call reset().
3. Call get_chip_info().
4. Enable irq.
BUG=b:239783274
BRANCH=None
TEST=Check CPS8100 and CPS8200 wireless charger work on Brask.
Signed-off-by: Derek Huang <derekhuang@google.com>
Change-Id: Idf9ab7899ecd42e786c59bc5a153328b9e040b80
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3845339
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
-rw-r--r-- | common/peripheral_charger.c | 17 | ||||
-rw-r--r-- | include/peripheral_charger.h | 15 |
2 files changed, 28 insertions, 4 deletions
diff --git a/common/peripheral_charger.c b/common/peripheral_charger.c index ad7e069e69..5767315a78 100644 --- a/common/peripheral_charger.c +++ b/common/peripheral_charger.c @@ -543,20 +543,33 @@ static void pchg_startup(void) { struct pchg *ctx; int p; + int active_pchg_count = 0; + int rv; CPRINTS("%s", __func__); queue_init(&host_events); for (p = 0; p < pchg_count; p++) { + rv = EC_SUCCESS; ctx = &pchgs[p]; _clear_port(ctx); ctx->mode = PCHG_MODE_NORMAL; + gpio_disable_interrupt(ctx->cfg->irq_pin); board_pchg_power_on(p, 1); ctx->cfg->drv->reset(ctx); - gpio_enable_interrupt(ctx->cfg->irq_pin); + if (ctx->cfg->drv->get_chip_info) + rv = ctx->cfg->drv->get_chip_info(ctx); + if (rv == EC_SUCCESS) { + gpio_enable_interrupt(ctx->cfg->irq_pin); + active_pchg_count++; + } else { + CPRINTS("ERR: Failed to probe P%d", p); + board_pchg_power_on(p, 0); + } } - task_wake(TASK_ID_PCHG); + if (active_pchg_count) + task_wake(TASK_ID_PCHG); } DECLARE_HOOK(HOOK_CHIPSET_STARTUP, pchg_startup, HOOK_PRIO_DEFAULT); diff --git a/include/peripheral_charger.h b/include/peripheral_charger.h index 5b9abdc169..ac193ba2da 100644 --- a/include/peripheral_charger.h +++ b/include/peripheral_charger.h @@ -220,12 +220,23 @@ struct pchg { * Peripheral charger driver */ struct pchg_drv { - /* Reset charger chip. */ + /* + * Reset charger chip. External reset (e.g by GPIO). No + * communication or data access is expected (e.g. no I2C access). + */ int (*reset)(struct pchg *ctx); - /* Initialize the charger. */ + /* + * Initialize the charger. Run setup needed only once per reset + * (e.g. enable I2C, unlock I2C). + */ int (*init)(struct pchg *ctx); /* Enable/disable the charger. */ int (*enable)(struct pchg *ctx, bool enable); + /* + * Get chip info, identify chip and setup function pointers + * (e.g. I2C read function). It needs to work without IRQ. + */ + int (*get_chip_info)(struct pchg *ctx); /* Get event info. */ int (*get_event)(struct pchg *ctx); /* Get battery level. */ |