diff options
author | Caveh Jalali <caveh@chromium.org> | 2021-09-18 00:20:23 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-09-26 01:20:45 +0000 |
commit | ae0593a3d10e60ea3fe8aa8159458e2dfb290292 (patch) | |
tree | 404e8cc3caa6e483a56ea99f96e8077850c4337e | |
parent | c3a408d48055937f131a948734346989fbbe5307 (diff) | |
download | chrome-ec-ae0593a3d10e60ea3fe8aa8159458e2dfb290292.tar.gz |
npcx/i2c: Implement chip_i2c_[gs]et_freq
This implements missing I2C driver functions to get or set the I2C bus
speed on NPCX family chips.
BRANCH=none
BUG=b:201039003
TEST=with follow-on patches, switched I2C bus speed between 400 kHz
and 1 MHz.
Change-Id: Ie0d8de1ca2c4884e52f5fe947ad19a50b0c76fb9
Signed-off-by: Caveh Jalali <caveh@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3170292
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
-rw-r--r-- | chip/npcx/i2c.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/chip/npcx/i2c.c b/chip/npcx/i2c.c index c821b6d066..26935f778f 100644 --- a/chip/npcx/i2c.c +++ b/chip/npcx/i2c.c @@ -1129,6 +1129,55 @@ static void i2c_freq_changed(void) DECLARE_HOOK(HOOK_FREQ_CHANGE, i2c_freq_changed, HOOK_PRIO_DEFAULT); +enum i2c_freq chip_i2c_get_freq(int chip_i2c_port) +{ + int ctrl; + int kbps; + + ctrl = i2c_port_to_controller(chip_i2c_port); + if (ctrl < 0) + return I2C_FREQ_COUNT; + + kbps = i2c_stsobjs[ctrl].kbps; + + if (kbps > 400) + return I2C_FREQ_1000KHZ; + if (kbps > 100) + return I2C_FREQ_400KHZ; + + if (kbps == 100) + return I2C_FREQ_100KHZ; + + return I2C_FREQ_COUNT; +} + +int chip_i2c_set_freq(int chip_i2c_port, enum i2c_freq freq) +{ + int ctrl; + int bus_freq_kbps; + + ctrl = i2c_port_to_controller(chip_i2c_port); + if (ctrl < 0) + return EC_ERROR_INVAL; + + switch (freq) { + case I2C_FREQ_100KHZ: + bus_freq_kbps = 100; + break; + case I2C_FREQ_400KHZ: + bus_freq_kbps = 400; + break; + case I2C_FREQ_1000KHZ: + bus_freq_kbps = 1000; + break; + default: + return EC_ERROR_INVAL; + } + + i2c_port_set_freq(ctrl, bus_freq_kbps); + return EC_SUCCESS; +} + void i2c_init(void) { int i; |