diff options
author | Ting Shen <phoenixshen@google.com> | 2019-12-16 17:44:57 +0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-01-17 12:31:42 +0000 |
commit | 45427c38df049e4506bf42e17d1ccfd303e1380c (patch) | |
tree | d0ceab265367bcfb1e9ebc2d47222749710fe127 /chip/host | |
parent | 166c22d05730de961b894d954116439d6ff219e7 (diff) | |
download | chrome-ec-45427c38df049e4506bf42e17d1ccfd303e1380c.tar.gz |
i2c: Support changing I2C bus speed at runtime
Add a i2c_set_freq function and let chip drivers add their underlying
implementation.
Also implemented on stm32f0.
BUG=b:143677811,b:78189419
TEST=1) make
2) On kodama, call i2c_set_freq(1, 100) during init.
verify the bus is configured to 100kbps in kodama rev 1
BRANCH=kukui
Change-Id: Iebb5baacf098b3e5649a4bd8ca14acf097d39693
Signed-off-by: Ting Shen <phoenixshen@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1969245
Reviewed-by: Matthew Blecker <matthewb@chromium.org>
Reviewed-by: Jett Rink <jettrink@chromium.org>
Commit-Queue: Ting Shen <phoenixshen@chromium.org>
Tested-by: Ting Shen <phoenixshen@chromium.org>
Diffstat (limited to 'chip/host')
-rw-r--r-- | chip/host/build.mk | 5 | ||||
-rw-r--r-- | chip/host/i2c.c | 21 |
2 files changed, 25 insertions, 1 deletions
diff --git a/chip/host/build.mk b/chip/host/build.mk index f57fe85502..9d77937776 100644 --- a/chip/host/build.mk +++ b/chip/host/build.mk @@ -8,8 +8,9 @@ CORE:=host -chip-y=system.o gpio.o uart.o persistence.o flash.o lpc.o reboot.o i2c.o \ +chip-y=system.o gpio.o uart.o persistence.o flash.o lpc.o reboot.o \ clock.o spi_master.o trng.o + ifndef CONFIG_KEYBOARD_NOT_RAW chip-$(HAS_TASK_KEYSCAN)+=keyboard_raw.o endif @@ -21,6 +22,8 @@ dirs-y += chip/g/dcrypto endif dirs-y += chip/host/dcrypto +chip-$(CONFIG_I2C)+= i2c.o + chip-$(CONFIG_DCRYPTO)+= dcrypto/aes.o chip-$(CONFIG_DCRYPTO)+= dcrypto/app_cipher.o chip-$(CONFIG_DCRYPTO)+= dcrypto/app_key.o diff --git a/chip/host/i2c.c b/chip/host/i2c.c index 5b863c1d41..f474c38ef1 100644 --- a/chip/host/i2c.c +++ b/chip/host/i2c.c @@ -7,6 +7,7 @@ #include "hooks.h" #include "i2c.h" +#include "i2c_private.h" #include "link_defs.h" #include "test_util.h" @@ -95,6 +96,26 @@ int chip_i2c_xfer(const int port, const uint16_t slave_addr_flags, return EC_ERROR_UNKNOWN; } +int chip_i2c_set_freq(int port, enum i2c_freq freq) +{ + return EC_ERROR_UNIMPLEMENTED; +} + +enum i2c_freq chip_i2c_get_freq(int port) +{ + switch (i2c_ports[port].kbps) { + case 1000: + return I2C_FREQ_1000KHZ; + case 400: + return I2C_FREQ_400KHZ; + case 100: + return I2C_FREQ_100KHZ; + } + + /* fallback to 100k */ + return I2C_FREQ_100KHZ; +} + int i2c_raw_get_scl(int port) { return 1; |