diff options
author | Jan Dabros <jsd@semihalf.com> | 2021-01-27 21:38:57 +0100 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-02-09 10:34:14 +0000 |
commit | 7852f10868a7cbbb3ae496ff3af82c7cab95e7f1 (patch) | |
tree | bba4221602050b75defcdd74750326515a0efe04 /driver/gl3590.c | |
parent | 0aaea73385103b2facc8ec486e89bbba2d88ccad (diff) | |
download | chrome-ec-7852f10868a7cbbb3ae496ff3af82c7cab95e7f1.tar.gz |
gl3590: Add init function
Add a way to verify whether I2C interface of the hub is ready and
initialize it.
BUG=b:178125550
BRANCH=main
TEST=With consecutive patches applied, verify host hub functionality on
servo_v4p1 board. All USB ports should be usable. Check console logs for
any possible error messages.
Signed-off-by: Jan Dabros <jsd@semihalf.com>
Change-Id: I9a4ad484d07b50e0c497f56bfaf111b47b3b0576
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2674001
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
Diffstat (limited to 'driver/gl3590.c')
-rw-r--r-- | driver/gl3590.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/driver/gl3590.c b/driver/gl3590.c index 6305a011bd..ae0d36159b 100644 --- a/driver/gl3590.c +++ b/driver/gl3590.c @@ -85,10 +85,47 @@ int gl3590_write(int hub, uint8_t reg, uint8_t *data, int count) return rv; } +/* + * Basic initialization of GL3590 I2C interface. + * + * Please note, that I2C interface is online not earlier than ~50ms after + * RESETJ# is deasserted. Platform should check that PGREEN_A_SMD pin is + * asserted. This init function shouldn't be invoked until that time. + */ +void gl3590_init(int hub) +{ + uint8_t tmp; + struct uhub_i2c_iface_t *uhub_p = &uhub_config[hub]; + + if (uhub_p->initialized) + return; + + if (gl3590_read(hub, GL3590_HUB_MODE_REG, &tmp, 1)) { + CPRINTF("GL3590: Cannot read HUB_MODE register"); + return; + } + if ((tmp & GL3590_HUB_MODE_I2C_READY) == 0) + CPRINTF("GL3590 interface isn't ready, consider deferring " + "this init\n"); + + /* Deassert INTR# signal */ + tmp = GL3590_INT_CLEAR; + if (gl3590_write(hub, GL3590_INT_REG, &tmp, 1)) { + CPRINTF("GL3590: Cannot write to INT register"); + return; + }; + + uhub_p->initialized = 1; +} + void gl3590_irq_handler(int hub) { uint8_t buf = 0; uint8_t res_reg[2]; + struct uhub_i2c_iface_t *uhub_p = &uhub_config[hub]; + + if (!uhub_p->initialized) + return; /* Verify that irq is pending */ if (gl3590_read(hub, GL3590_INT_REG, &buf, sizeof(buf))) { @@ -167,6 +204,10 @@ enum ec_error_list gl3590_ufp_pwr(int hub, struct pwr_con_t *pwr) { uint8_t hub_sts, hub_mode; int rv = 0; + struct uhub_i2c_iface_t *uhub_p = &uhub_config[hub]; + + if (!uhub_p->initialized) + return EC_ERROR_HW_INTERNAL; if (gl3590_read(hub, GL3590_HUB_STS_REG, &hub_sts, sizeof(hub_sts))) { CPRINTF("Error reading HUB_STS %d\n", rv); @@ -211,6 +252,10 @@ int gl3590_enable_ports(int hub, uint8_t port_mask, bool enable) uint8_t buf[4] = {0}; uint8_t en_mask = 0; int rv; + struct uhub_i2c_iface_t *uhub_p = &uhub_config[hub]; + + if (!uhub_p->initialized) + return EC_ERROR_HW_INTERNAL; if (!enable) en_mask = port_mask; |