summaryrefslogtreecommitdiff
path: root/chip/host/i2c.c
diff options
context:
space:
mode:
authorTing Shen <phoenixshen@google.com>2019-12-16 17:44:57 +0800
committerCommit Bot <commit-bot@chromium.org>2020-01-17 12:31:42 +0000
commit45427c38df049e4506bf42e17d1ccfd303e1380c (patch)
treed0ceab265367bcfb1e9ebc2d47222749710fe127 /chip/host/i2c.c
parent166c22d05730de961b894d954116439d6ff219e7 (diff)
downloadchrome-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/i2c.c')
-rw-r--r--chip/host/i2c.c21
1 files changed, 21 insertions, 0 deletions
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;