summaryrefslogtreecommitdiff
path: root/chip/mchp
diff options
context:
space:
mode:
authorVijay Hiremath <vijay.p.hiremath@intel.com>2021-06-22 11:45:31 -0700
committerCommit Bot <commit-bot@chromium.org>2021-06-30 23:08:35 +0000
commit8ba01c565e1db7edc4338b01f3c3f07a3eea6fdc (patch)
tree8c836f4216b0c8859e6f59063ababbb7c8594fd2 /chip/mchp
parent098bac5f91792203db9ccb731b5349064c14b468 (diff)
downloadchrome-ec-8ba01c565e1db7edc4338b01f3c3f07a3eea6fdc.tar.gz
mchp: Correct assigning I2C controller to a port
Corrected default assignment of controller to I2C port based on the number of I2C ports being used rather than the port in use. This avoids overlapping of I2C controller assignment when the I2C ports used are not greater than MCHP_I2C_CTRL_MAX. BUG=none BRANCH=none TEST=Tested on ADLRVP, default I2C controller assignment is correct. Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com> Change-Id: I875b0f7e94162f923325e9ed07e7549cc760fdf8 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2980432 Reviewed-by: Martin Yan <martin.yan@microchip.corp-partner.google.com> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> Commit-Queue: Aseda Aboagye <aaboagye@chromium.org>
Diffstat (limited to 'chip/mchp')
-rw-r--r--chip/mchp/i2c.c8
-rw-r--r--chip/mchp/i2c_chip.h10
2 files changed, 15 insertions, 3 deletions
diff --git a/chip/mchp/i2c.c b/chip/mchp/i2c.c
index 6125a893ef..9891f4d41e 100644
--- a/chip/mchp/i2c.c
+++ b/chip/mchp/i2c.c
@@ -236,6 +236,9 @@ const struct i2c_bus_clk i2c_freq_tbl[] = {
};
BUILD_ASSERT(ARRAY_SIZE(i2c_freq_tbl) == MCHP_I2C_SUPPORTED_BUS_CLOCKS);
+/* I2C controller assignment to a port */
+static int i2c_p2c[MCHP_I2C_PORT_COUNT];
+
static int get_closest(int lesser, int greater, int target)
{
if (target - i2c_freq_tbl[lesser].freq_khz >=
@@ -935,7 +938,7 @@ __overridable int board_i2c_p2c(int port)
{
if (port < 0 || port >= I2C_PORT_COUNT)
return -1;
- return port % MCHP_I2C_CTRL_MAX;
+ return i2c_p2c[port];
}
/*
@@ -976,6 +979,9 @@ void i2c_init(void)
memset(cdata, 0, sizeof(cdata));
for (i = 0; i < i2c_ports_used; ++i) {
+ /* Assign I2C controller to I2C port */
+ i2c_p2c[i2c_ports[i].port] = i % MCHP_I2C_CTRL_MAX;
+
controller = i2c_port_to_controller(i2c_ports[i].port);
kbps = i2c_ports[i].kbps;
diff --git a/chip/mchp/i2c_chip.h b/chip/mchp/i2c_chip.h
index 35752fe9ca..c8ceb98d04 100644
--- a/chip/mchp/i2c_chip.h
+++ b/chip/mchp/i2c_chip.h
@@ -15,8 +15,14 @@ extern "C" {
/* Place any C interfaces here */
/*
- * function returns the controller for I2C
- * if there is a special assignment, function board.c can override this.
+ * Function returns the controller for I2C.
+ *
+ * Default function assigns controller for I2C port with modulo operation. If
+ * the I2C ports used are greater than MCHP_I2C_CTRL_MAX, then I2C ports will
+ * share the controller. Typically Type-C chips need individual controller per
+ * port because of heavy I2C transactions. Hence, define a board specific
+ * controller assignment when the I2C ports used are greater than
+ * MCHP_I2C_CTRL_MAX.
*/
__override_proto int board_i2c_p2c(int port);