summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJes B. Klinke <jbk@chromium.org>2023-03-10 13:59:11 -0800
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-03-14 16:55:53 +0000
commiteb8d42b2eb4107034b3249514a2392ef0db703aa (patch)
tree2f4a3cde3e5f16fe78da66d493de01d674ff7aa6
parent4892dbb98305dbd0c5ca454450fd200bb971e6be (diff)
downloadchrome-ec-eb8d42b2eb4107034b3249514a2392ef0db703aa.tar.gz
board/hyperdebug: Enable all three I2C ports
Allow forwarding to any of the three I2C ports of the HyperDebug board. Also, add an "i2c info" command which lists the I2C ports by symbolic name and index, (the latter to be used when sending binary data via USB.) This also sets the stage for adding "i2c set speed" similarly to what has been done for SPI ports. BUG=b:192262089 TEST=Observed forwarding to I2C2 pins via analyzer Change-Id: I661999cc0bda881cbe6d884eed7905aa5173964c Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4327132 Reviewed-by: Jett Rink <jettrink@chromium.org> Tested-by: Jes Klinke <jbk@chromium.org> Commit-Queue: Jes Klinke <jbk@chromium.org>
-rw-r--r--board/hyperdebug/board.c20
-rw-r--r--board/hyperdebug/board.h1
-rw-r--r--board/hyperdebug/build.mk2
-rw-r--r--board/hyperdebug/i2c.c107
4 files changed, 108 insertions, 22 deletions
diff --git a/board/hyperdebug/board.c b/board/hyperdebug/board.c
index f4a5fadcb4..1872ddcb93 100644
--- a/board/hyperdebug/board.c
+++ b/board/hyperdebug/board.c
@@ -7,7 +7,6 @@
#include "adc.h"
#include "common.h"
#include "ec_version.h"
-#include "i2c.h"
#include "queue_policies.h"
#include "registers.h"
#include "spi.h"
@@ -126,25 +125,6 @@ USB_STREAM_CONFIG(usart5_usb, USB_IFACE_USART5_STREAM,
USB_SPI_CONFIG(usb_spi, USB_IFACE_SPI, USB_EP_SPI, 0);
/******************************************************************************
- * Support I2C bridging over USB.
- */
-
-/* I2C ports */
-const struct i2c_port_t i2c_ports[] = {
- { .name = "controller",
- .port = I2C_PORT_CONTROLLER,
- .kbps = 100,
- .scl = GPIO_CN7_2,
- .sda = GPIO_CN7_4 },
-};
-const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports);
-
-int usb_i2c_board_is_enabled(void)
-{
- return 1;
-}
-
-/******************************************************************************
* Define the strings used in our USB descriptors.
*/
diff --git a/board/hyperdebug/board.h b/board/hyperdebug/board.h
index 7d60059ebe..8271f81e63 100644
--- a/board/hyperdebug/board.h
+++ b/board/hyperdebug/board.h
@@ -152,7 +152,6 @@
#define CONFIG_USB_I2C
#define CONFIG_I2C
#define CONFIG_I2C_CONTROLLER
-#define I2C_PORT_CONTROLLER 0
/* See i2c_ite_flash_support.c for more information about these values */
/*#define CONFIG_ITE_FLASH_SUPPORT */
diff --git a/board/hyperdebug/build.mk b/board/hyperdebug/build.mk
index 51def3a7c2..2d8291043c 100644
--- a/board/hyperdebug/build.mk
+++ b/board/hyperdebug/build.mk
@@ -13,4 +13,4 @@ CHIP_VARIANT:=stm32l552xe
# These files are compiled into RO
chip-ro=bkpdata.o system.o
-board-rw=board.o gpio.o spi.o
+board-rw=board.o gpio.o spi.o i2c.o
diff --git a/board/hyperdebug/i2c.c b/board/hyperdebug/i2c.c
new file mode 100644
index 0000000000..6687b47c38
--- /dev/null
+++ b/board/hyperdebug/i2c.c
@@ -0,0 +1,107 @@
+/* Copyright 2023 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+/* HyperDebug I2C logic and console commands */
+
+#include "common.h"
+#include "console.h"
+#include "gpio.h"
+#include "i2c.h"
+#include "util.h"
+
+/* I2C ports */
+const struct i2c_port_t i2c_ports[] = {
+ { .name = "I2C1",
+ .port = 0,
+ .kbps = 100,
+ .scl = GPIO_CN7_2,
+ .sda = GPIO_CN7_4 },
+ { .name = "I2C2",
+ .port = 1,
+ .kbps = 100,
+ .scl = GPIO_CN9_19,
+ .sda = GPIO_CN9_21 },
+ { .name = "I2C3",
+ .port = 2,
+ .kbps = 100,
+ .scl = GPIO_CN9_11,
+ .sda = GPIO_CN9_9 },
+};
+const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports);
+
+int usb_i2c_board_is_enabled(void)
+{
+ return 1;
+}
+
+/*
+ * Find i2c port by name or by number. Returns an index into i2c_ports[], or on
+ * error a negative value.
+ */
+static int find_i2c_by_name(const char *name)
+{
+ int i;
+ char *e;
+ i = strtoi(name, &e, 0);
+
+ if (!*e && i < i2c_ports_used)
+ return i;
+
+ for (i = 0; i < i2c_ports_used; i++) {
+ if (!strcasecmp(name, i2c_ports[i].name))
+ return i;
+ }
+
+ /* I2C device not found */
+ return -1;
+}
+
+static void print_i2c_info(int index)
+{
+ uint32_t bits_per_second = 100000;
+
+ ccprintf(" %d %s %d bps\n", index, i2c_ports[index].name,
+ bits_per_second);
+
+ /* Flush console to avoid truncating output */
+ cflush();
+}
+
+/*
+ * Get information about one or all I2C ports.
+ */
+static int command_i2c_info(int argc, const char **argv)
+{
+ int i;
+
+ /* If a I2C port is specified, print only that one */
+ if (argc == 3) {
+ int index = find_i2c_by_name(argv[2]);
+ if (index < 0) {
+ ccprintf("I2C port not found\n");
+ return EC_ERROR_PARAM2;
+ }
+
+ print_i2c_info(index);
+ return EC_SUCCESS;
+ }
+
+ /* Otherwise print them all */
+ for (i = 0; i < i2c_ports_used; i++) {
+ print_i2c_info(i);
+ }
+
+ return EC_SUCCESS;
+}
+
+static int command_i2c(int argc, const char **argv)
+{
+ if (argc < 2)
+ return EC_ERROR_PARAM_COUNT;
+ if (!strcasecmp(argv[1], "info"))
+ return command_i2c_info(argc, argv);
+ return EC_ERROR_PARAM1;
+}
+DECLARE_CONSOLE_COMMAND_FLAGS(i2c, command_i2c, "info [PORT]",
+ "I2C bus manipulation", CMD_FLAG_RESTRICTED);