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 /include | |
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 'include')
-rw-r--r-- | include/i2c.h | 45 | ||||
-rw-r--r-- | include/i2c_private.h | 56 |
2 files changed, 80 insertions, 21 deletions
diff --git a/include/i2c.h b/include/i2c.h index 247306da7d..b9feac13d8 100644 --- a/include/i2c.h +++ b/include/i2c.h @@ -66,6 +66,9 @@ /* The size of the header for a version 3 response packet sent over I2C. */ #define I2C_RESPONSE_HEADER_SIZE 2 +/* This port allows changing speed at runtime */ +#define I2C_PORT_FLAG_DYNAMIC_SPEED BIT(0) + /* * Supported I2C CLK frequencies. * TODO(crbug.com/549286): Use this enum in i2c_port_t. @@ -113,6 +116,7 @@ struct i2c_port_t { int (*passthru_allowed)(const struct i2c_port_t *port, uint16_t addr_flags); const struct i2c_drv *drv; + uint16_t flags; /* I2C_PORT_FLAG_* flags */ }; extern const struct i2c_port_t i2c_ports[]; @@ -196,27 +200,6 @@ int i2c_xfer_unlocked(const int port, #define I2C_LINE_IDLE (I2C_LINE_SCL_HIGH | I2C_LINE_SDA_HIGH) /** - * Chip-level function to transmit one block of raw data, then receive one - * block of raw data. - * - * This is a low-level chip-dependent function and should only be called by - * i2c_xfer(). - * - * @param port Port to access - * @param slave_addr Slave device address - * @param out Data to send - * @param out_size Number of bytes to send - * @param in Destination buffer for received data - * @param in_size Number of bytes to receive - * @param flags Flags (see I2C_XFER_* above) - * @return EC_SUCCESS, or non-zero if error. - */ -int chip_i2c_xfer(const int port, - const uint16_t slave_addr_flags, - const uint8_t *out, int out_size, - uint8_t *in, int in_size, int flags); - -/** * Return raw I/O line levels (I2C_LINE_*) for a port when port is in alternate * function mode. * @@ -580,4 +563,24 @@ void i2c_end_xfer_notify(const int port, void i2c_trace_notify(int port, uint16_t slave_addr_flags, int direction, const uint8_t *data, size_t size); +/** + * Set bus speed. Only support for ports with I2C_PORT_FLAG_DYNAMIC_SPEED + * flag. + * + * @param port: Port to access + * @param freq: Bus speed. + * + * @return EC_SUCCESS, or non-zero if error. + */ +int i2c_set_freq(int port, enum i2c_freq freq); + +/** + * Chip level function to get bus speed. + * + * @param port: Port to access + * + * @return Bus speed + */ +enum i2c_freq i2c_get_freq(int port); + #endif /* __CROS_EC_I2C_H */ diff --git a/include/i2c_private.h b/include/i2c_private.h new file mode 100644 index 0000000000..8a92884c16 --- /dev/null +++ b/include/i2c_private.h @@ -0,0 +1,56 @@ +/* Copyright 2020 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +/* + * Private chipset-specific implementations that only accessible by + * i2c_master.c. Don't include this directly unless you are implementing + * these functions. + */ +#ifndef __CROS_EC_I2C_PRIVATE_H +#define __CROS_EC_I2C_PRIVATE_H + +#include "i2c.h" + +/** + * Chip-level function to transmit one block of raw data, then receive one + * block of raw data. + * + * This is a low-level chip-dependent function and should only be called by + * i2c_xfer(). + * + * @param port Port to access + * @param slave_addr Slave device address + * @param out Data to send + * @param out_size Number of bytes to send + * @param in Destination buffer for received data + * @param in_size Number of bytes to receive + * @param flags Flags (see I2C_XFER_* above) + * @return EC_SUCCESS, or non-zero if error. + */ +int chip_i2c_xfer(const int port, + const uint16_t slave_addr_flags, + const uint8_t *out, int out_size, + uint8_t *in, int in_size, int flags); + +/** + * Chip level function to set bus speed. + * + * @param port: Port to access + * @param kbps: Bus speed in kbps. + * + * @return EC_SUCCESS, or non-zero if error. + */ +int chip_i2c_set_freq(int port, enum i2c_freq freq); + +/** + * Chip level function to get bus speed. + * + * @param port: Port to access + * + * @return Bus speed + */ +enum i2c_freq chip_i2c_get_freq(int port); + +#endif /* __CROS_EC_I2C_PRIVATE_H */ |