summaryrefslogtreecommitdiff
path: root/zephyr
diff options
context:
space:
mode:
authorPeter Marheine <pmarheine@chromium.org>2022-03-31 14:47:45 +1100
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-03-31 06:37:43 +0000
commitb1281f53d17c498a1b61fc27c73789b8d32569b4 (patch)
tree924ddf41a60da6003fdb6d1bd002fcfae8e5ca6e /zephyr
parent1ea4f38e820a1034a9870c4f3062dcaefd0ff5ef (diff)
downloadchrome-ec-b1281f53d17c498a1b61fc27c73789b8d32569b4.tar.gz
nissa/nereid: run sub-board I2C at 1.8V
Board revisions 1 and later will run sub-board I2C at 1.8V to improve bus timing characteristics. Since it's safe to configure the EC for 1.8V operation with the 3.3V bus on board version 0, we'll always set the I2C pins to 1.8V. BUG=b:227517811 TEST=USB-C1 continues to function, and manual inspection of the voltage selection bits (GPE0VS and GPE7VS) in GCR20 indicate 1.8V operation: `rw .b 0xf016e5` reads 0x92 with bits 3 and 5 set for GPE7 and GPE0, respectively. BRANCH=none Signed-off-by: Peter Marheine <pmarheine@chromium.org> Change-Id: Ib2f937fb450088b5154007e4c90d03366297bb2f Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3561601 Reviewed-by: Andrew McRae <amcrae@google.com>
Diffstat (limited to 'zephyr')
-rw-r--r--zephyr/projects/nissa/include/nissa_common.h4
-rw-r--r--zephyr/projects/nissa/src/nereid/usbc.c31
-rw-r--r--zephyr/projects/nissa/src/nivviks/usbc.c5
-rw-r--r--zephyr/projects/nissa/src/sub_board.c6
4 files changed, 42 insertions, 4 deletions
diff --git a/zephyr/projects/nissa/include/nissa_common.h b/zephyr/projects/nissa/include/nissa_common.h
index b0f99b5d05..b5730cac97 100644
--- a/zephyr/projects/nissa/include/nissa_common.h
+++ b/zephyr/projects/nissa/include/nissa_common.h
@@ -23,6 +23,10 @@ extern struct usb_mux usb_muxes[CONFIG_USB_PD_PORT_MAX_COUNT];
enum nissa_sub_board_type nissa_get_sb_type(void);
/**
+ * Configure the I2C lines for the USB-C sub-board as needed.
+ */
+void nissa_configure_c1_sb_i2c(void);
+/**
* Return any necessary mux configuration for the sub-board USB-C port.
*/
const struct usb_mux *nissa_get_c1_sb_mux(void);
diff --git a/zephyr/projects/nissa/src/nereid/usbc.c b/zephyr/projects/nissa/src/nereid/usbc.c
index 2ae7816078..696e21d385 100644
--- a/zephyr/projects/nissa/src/nereid/usbc.c
+++ b/zephyr/projects/nissa/src/nereid/usbc.c
@@ -4,9 +4,12 @@
*/
#include <logging/log.h>
+#include <drivers/i2c.h>
+#include <drivers/pinmux.h>
#include "charge_state_v2.h"
#include "chipset.h"
+#include "cros_board_info.h"
#include "hooks.h"
#include "usb_mux.h"
#include "system.h"
@@ -340,7 +343,6 @@ int pd_snk_is_vbus_provided(int port)
return chg_det;
}
-
const struct usb_mux *nissa_get_c1_sb_mux(void)
{
/*
@@ -357,3 +359,30 @@ const struct usb_mux *nissa_get_c1_sb_mux(void)
return &usbc1_tcpc_mux;
}
+
+void nissa_configure_c1_sb_i2c(void)
+{
+ /*
+ * Board rev 1+ runs I2C at 1.8V, while rev 0 is 3.3. The 3.3V bus still
+ * works with 1.8V configuration, so we always configure the chip for
+ * 1.8V operation.
+ *
+ * There is no API to set pin voltage aside from GPIO, so we hack it
+ * by reconfiguring the pins as 1.8V GPIO then force them back to I2C.
+ * This is fragile, but breakages will be evident because the sub-board
+ * I2C will stop working.
+ */
+ const struct gpio_dt_spec *const scl_pin =
+ GPIO_DT_FROM_NODELABEL(gpio_sb_4);
+ const struct gpio_dt_spec *const sda_pin =
+ GPIO_DT_FROM_NODELABEL(gpio_sb_3);
+ const struct device *const i2c_dev = DEVICE_DT_GET(DT_NODELABEL(i2c4));
+ int rv;
+
+ __ASSERT_NO_MSG(device_is_ready(i2c_dev));
+ gpio_pin_configure_dt(sda_pin, GPIO_INPUT | GPIO_VOLTAGE_1P8);
+ gpio_pin_configure_dt(scl_pin, GPIO_INPUT | GPIO_VOLTAGE_1P8);
+ /* Recover the bus which also switches pins back to I2C function. */
+ rv = i2c_recover_bus(i2c_dev);
+ __ASSERT(rv == 0, "failed to reset I2C bus at 1.8V: %d", rv);
+}
diff --git a/zephyr/projects/nissa/src/nivviks/usbc.c b/zephyr/projects/nissa/src/nivviks/usbc.c
index fa9a4cfaa7..10cacdad2f 100644
--- a/zephyr/projects/nissa/src/nivviks/usbc.c
+++ b/zephyr/projects/nissa/src/nivviks/usbc.c
@@ -281,3 +281,8 @@ const struct usb_mux *nissa_get_c1_sb_mux(void)
};
return &usbc1_anx7483;
}
+
+void nissa_configure_c1_sb_i2c(void)
+{
+ /* Default configuration from dts is I2C. Do nothing. */
+}
diff --git a/zephyr/projects/nissa/src/sub_board.c b/zephyr/projects/nissa/src/sub_board.c
index 0ef2e217b0..4737036245 100644
--- a/zephyr/projects/nissa/src/sub_board.c
+++ b/zephyr/projects/nissa/src/sub_board.c
@@ -101,11 +101,11 @@ static int nissa_subboard_config(const struct device *unused)
GPIO_DISCONNECTED);
}
/*
- * USB-C port: the default configuration has I2C on the I2C pins,
- * but the interrupt line needs to be configured and USB mux
- * configuration provided.
+ * USB-C port: I2C runs over two of the sub-board lines, the interrupt
+ * input needs to be configured, and USB mux configuration provided.
*/
if (sb == NISSA_SB_C_A || sb == NISSA_SB_C_LTE) {
+ nissa_configure_c1_sb_i2c();
/* Configure interrupt input */
gpio_pin_configure_dt(
GPIO_DT_FROM_ALIAS(gpio_usb_c1_int_odl),