summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew McRae <amcrae@google.com>2022-01-11 22:07:11 +1100
committerCommit Bot <commit-bot@chromium.org>2022-01-17 01:26:01 +0000
commitfbd1df9fd7be98200de13388d7ac752a73df6284 (patch)
tree9bf0b42b3be40eef8acd49d1fac6b3ead1d5b112
parentb6d41178f63ea2d930327af5c8015f4db6c74f5c (diff)
downloadchrome-ec-fbd1df9fd7be98200de13388d7ac752a73df6284.tar.gz
nissa: Add some initial sub-board setup for nivviks
Sub-board initial setup for nivviks. V2 - disable port 1 charging task BUG=b:212490923 TEST=zmake configure -b nivviks; flash & run BRANCH=none Signed-off-by: Andrew McRae <amcrae@google.com> Change-Id: I1a41db88053514f8b0b8b5e41ede4f049d6db35b Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3379788 Reviewed-by: Peter Marheine <pmarheine@chromium.org>
-rw-r--r--zephyr/projects/nissa/CMakeLists.txt1
-rw-r--r--zephyr/projects/nissa/include/gpio_map.h13
-rw-r--r--zephyr/projects/nissa/include/gpios.h25
-rw-r--r--zephyr/projects/nissa/nereid_overlay.dts34
-rw-r--r--zephyr/projects/nissa/nivviks_overlay.dts34
-rw-r--r--zephyr/projects/nissa/src/gpios.c32
-rw-r--r--zephyr/projects/nissa/src/nivviks/board_config.c44
-rw-r--r--zephyr/projects/nissa/src/usbc.c58
8 files changed, 205 insertions, 36 deletions
diff --git a/zephyr/projects/nissa/CMakeLists.txt b/zephyr/projects/nissa/CMakeLists.txt
index 71222d97e4..9a6b6fb543 100644
--- a/zephyr/projects/nissa/CMakeLists.txt
+++ b/zephyr/projects/nissa/CMakeLists.txt
@@ -8,6 +8,7 @@ find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
zephyr_include_directories(include)
zephyr_library_sources("src/sub_board.c")
+zephyr_library_sources("src/gpios.c")
if(DEFINED CONFIG_BOARD_NIVVIKS)
project(nivviks)
diff --git a/zephyr/projects/nissa/include/gpio_map.h b/zephyr/projects/nissa/include/gpio_map.h
index bf05e52396..6fa6c1e9f9 100644
--- a/zephyr/projects/nissa/include/gpio_map.h
+++ b/zephyr/projects/nissa/include/gpio_map.h
@@ -76,15 +76,6 @@
#define VOLBTN_INT(pin)
#endif
-#ifdef CONFIG_PLATFORM_EC_USBC
- #define USBC_INT(pin, port) GPIO_INT(pin, \
- GPIO_INT_EDGE_FALLING, \
- usb_c ## port ## _interrupt)
-#else
- #define USBC_INT(pin, port)
-#endif
-
-
#define EC_CROS_GPIO_INTERRUPTS \
WP_INT() \
LID_INT() \
@@ -96,7 +87,5 @@
POWER_SIGNAL_INT(GPIO_PG_EC_DSW_PWROK, GPIO_INT_EDGE_BOTH) \
POWER_SIGNAL_INT(GPIO_PG_EC_RSMRST_ODL, GPIO_INT_EDGE_BOTH) \
POWER_SIGNAL_INT(GPIO_PG_EC_ALL_SYS_PWRGD, GPIO_INT_EDGE_BOTH) \
- AP_PROCHOT_INT(GPIO_EC_PROCHOT_ODL, GPIO_INT_EDGE_BOTH) \
- USBC_INT(GPIO_USB_C0_PD_INT_ODL, 0) \
- USBC_INT(GPIO_USB_C1_PD_INT_ODL, 1)
+ AP_PROCHOT_INT(GPIO_EC_PROCHOT_ODL, GPIO_INT_EDGE_BOTH)
#endif /* __ZEPHYR_GPIO_MAP_H */
diff --git a/zephyr/projects/nissa/include/gpios.h b/zephyr/projects/nissa/include/gpios.h
new file mode 100644
index 0000000000..748bca4c6b
--- /dev/null
+++ b/zephyr/projects/nissa/include/gpios.h
@@ -0,0 +1,25 @@
+/* Copyright 2022 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.
+ */
+
+#ifndef __ZEPHYR_NISSA_GPIOS_H
+#define __ZEPHYR_NISSA_GPIOS_H
+
+#include <devicetree.h>
+#include <drivers/gpio.h>
+
+/*
+ * Nissa board specific GPIOs.
+ * These pins have multiple functions depending
+ * on the sub-board connected.
+ */
+extern const struct gpio_dt_spec gpio_usb_c1_int_odl;
+extern const struct gpio_dt_spec gpio_en_sub_rails_odl;
+extern const struct gpio_dt_spec gpio_usb_c0_int_odl;
+extern const struct gpio_dt_spec gpio_hdmi_en_sub_odl;
+extern const struct gpio_dt_spec gpio_hpd_sub_odl;
+extern const struct gpio_dt_spec gpio_en_sub_usb_a1_vbus;
+extern const struct gpio_dt_spec gpio_sub_usb_a1_ilimit_sdp;
+
+#endif /* __ZEPHYR_NISSA_GPIOS_H */
diff --git a/zephyr/projects/nissa/nereid_overlay.dts b/zephyr/projects/nissa/nereid_overlay.dts
index 5b591bdb0f..7cf6c9e205 100644
--- a/zephyr/projects/nissa/nereid_overlay.dts
+++ b/zephyr/projects/nissa/nereid_overlay.dts
@@ -14,6 +14,40 @@
>;
};
+ named-gpios {
+ /*
+ * Input GPIO when used with type-C port 1
+ */
+ gpio_usb_c1_int_odl: usb_c1_int_odl {
+ status = "disabled";
+ #gpio-cells = <0>;
+ gpios = <&gpioe 6 GPIO_INPUT_PULL_UP>;
+ };
+ /*
+ * Output GPIO when used with HDMI port
+ */
+ gpio_en_sub_rails_odl: en_sub_rails_odl {
+ status = "disabled";
+ #gpio-cells = <0>;
+ gpios = <&gpioe 6 GPIO_OUTPUT>;
+ };
+
+ /*
+ * Alternative use for I2C_PORT_USB_C1_TCPC
+ * when HDMI sub-board connected.
+ */
+ gpio_hdmi_en_sub_odl: hdmi_en_sub_odl {
+ status = "disabled";
+ #gpio-cells = <0>;
+ gpios = <&gpioe 7 GPIO_OPEN_DRAIN>;
+ };
+ gpio_hpd_sub_odl: hdmi_hpd_sub_odl {
+ status = "disabled";
+ #gpio-cells = <0>;
+ gpios = <&gpioe 0 GPIO_INPUT>;
+ };
+ };
+
named-temp-sensors {
memory {
compatible = "cros-ec,temp-sensor-thermistor";
diff --git a/zephyr/projects/nissa/nivviks_overlay.dts b/zephyr/projects/nissa/nivviks_overlay.dts
index 9966473afb..98b62a7915 100644
--- a/zephyr/projects/nissa/nivviks_overlay.dts
+++ b/zephyr/projects/nissa/nivviks_overlay.dts
@@ -22,14 +22,38 @@
named-gpios {
/*
- * TODO(b:212490923): decide what to do with these sorts of
- * signals that have varying function depending on the present
- * sub-board.
+ * The following 2 nodes refer to the same pin, but have
+ * different configuration depending on the sub-board.
+ *
+ * Input GPIO when used with type-C port 1
*/
- gpio_sub_usb_c1_int_odl: sub_usb_c1_int_odl {
+ gpio_usb_c1_int_odl: usb_c1_int_odl {
+ status = "disabled";
#gpio-cells = <0>;
gpios = <&gpio0 2 GPIO_INPUT_PULL_UP>;
- enum-name = "GPIO_USB_C1_PD_INT_ODL";
+ };
+ /*
+ * Output GPIO when used with HDMI port
+ */
+ gpio_en_sub_rails_odl: en_sub_rails_odl {
+ status = "disabled";
+ #gpio-cells = <0>;
+ gpios = <&gpio0 2 GPIO_OUTPUT>;
+ };
+
+ /*
+ * Alternative use for I2C_PORT_USB_C1_TCPC
+ * when HDMI sub-board connected.
+ */
+ gpio_hdmi_en_sub_odl: hdmi_en_sub_odl {
+ status = "disabled";
+ #gpio-cells = <0>;
+ gpios = <&gpiof 4 GPIO_OPEN_DRAIN>;
+ };
+ gpio_hpd_sub_odl: hdmi_hpd_sub_odl {
+ status = "disabled";
+ #gpio-cells = <0>;
+ gpios = <&gpiof 5 GPIO_INPUT>;
};
};
diff --git a/zephyr/projects/nissa/src/gpios.c b/zephyr/projects/nissa/src/gpios.c
new file mode 100644
index 0000000000..6cdfec4d6b
--- /dev/null
+++ b/zephyr/projects/nissa/src/gpios.c
@@ -0,0 +1,32 @@
+/* Copyright 2022 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.
+ */
+
+#include "gpios.h"
+
+/*
+ * gpio reference structures.
+ */
+
+/*
+ * Unfortunately the flags in gpio_dt_spec only allow 8 bits,
+ * and many of our DTS entries GPIO flags exceed that,
+ * so create a new macro that only uses the lower 8 bits.
+ */
+
+#define NISSA_GPIO(x) \
+const struct gpio_dt_spec x = \
+{ \
+ .port = DEVICE_DT_GET(DT_GPIO_CTLR(DT_NODELABEL(x), gpios)), \
+ .pin = DT_GPIO_PIN(DT_NODELABEL(x), gpios), \
+ .dt_flags = 0xFF & (DT_GPIO_FLAGS(DT_NODELABEL(x), gpios)), \
+}
+
+NISSA_GPIO(gpio_usb_c1_int_odl);
+NISSA_GPIO(gpio_en_sub_rails_odl);
+NISSA_GPIO(gpio_usb_c0_int_odl);
+NISSA_GPIO(gpio_hdmi_en_sub_odl);
+NISSA_GPIO(gpio_hpd_sub_odl);
+NISSA_GPIO(gpio_en_sub_usb_a1_vbus);
+NISSA_GPIO(gpio_sub_usb_a1_ilimit_sdp);
diff --git a/zephyr/projects/nissa/src/nivviks/board_config.c b/zephyr/projects/nissa/src/nivviks/board_config.c
index aecaeaef7c..6ceeecbd86 100644
--- a/zephyr/projects/nissa/src/nivviks/board_config.c
+++ b/zephyr/projects/nissa/src/nivviks/board_config.c
@@ -5,25 +5,59 @@
/* Nivviks sub-board hardware configuration */
-#include "gpio.h"
+#include <init.h>
+#include <kernel.h>
+#include <sys/printk.h>
+
+#include "gpios.h"
#include "hooks.h"
+#include "task.h"
+
#include "sub_board.h"
static void nivviks_subboard_init(void)
{
enum nissa_sub_board_type sb = nissa_get_sb_type();
+ /*
+ * Need to initialise board specific GPIOs since the
+ * common init code does not know about them.
+ * Remove once common code initialises all GPIOs, not just
+ * the ones with enum-names.
+ */
+ gpio_pin_configure_dt(&gpio_usb_c0_int_odl,
+ GPIO_INPUT | gpio_usb_c0_int_odl.dt_flags);
if (sb != NISSA_SB_C_A && sb != NISSA_SB_HDMI_A) {
/* Turn off unused USB A1 GPIOs */
+ gpio_pin_configure_dt(&gpio_sub_usb_a1_ilimit_sdp,
+ GPIO_DISCONNECTED);
+ gpio_pin_configure_dt(&gpio_en_sub_usb_a1_vbus,
+ GPIO_DISCONNECTED);
}
if (sb == NISSA_SB_C_A || sb == NISSA_SB_C_LTE) {
/* Enable type-C port 1 */
+ gpio_pin_configure_dt(&gpio_usb_c1_int_odl,
+ GPIO_INPUT |
+ gpio_usb_c1_int_odl.dt_flags);
+ } else {
+ /* Disable the port 1 charger task */
+ task_disable_task(TASK_ID_USB_CHG_P1);
}
if (sb == NISSA_SB_HDMI_A) {
+ /* Disable I2C_PORT_USB_C1_TCPC */
+ /* TODO(b:212490923): Use pinctrl to switch from I2C */
/* Enable HDMI GPIOs */
+ gpio_pin_configure_dt(&gpio_en_sub_rails_odl,
+ GPIO_OUTPUT |
+ GPIO_OUTPUT_INIT_HIGH |
+ gpio_en_sub_rails_odl.dt_flags);
+ gpio_pin_configure_dt(&gpio_hdmi_en_sub_odl,
+ GPIO_OUTPUT |
+ GPIO_OUTPUT_INIT_HIGH |
+ gpio_hdmi_en_sub_odl.dt_flags);
+ /* Configure the interrupt separately */
+ gpio_pin_configure_dt(&gpio_hpd_sub_odl,
+ GPIO_INPUT | gpio_hpd_sub_odl.dt_flags);
}
}
-/*
- * Make sure setup is done after EEPROM is readable.
- */
-DECLARE_HOOK(HOOK_INIT, nivviks_subboard_init, HOOK_PRIO_INIT_I2C + 1);
+DECLARE_HOOK(HOOK_INIT, nivviks_subboard_init, HOOK_PRIO_FIRST+1);
diff --git a/zephyr/projects/nissa/src/usbc.c b/zephyr/projects/nissa/src/usbc.c
index 5d412006ee..7f4f413dc8 100644
--- a/zephyr/projects/nissa/src/usbc.c
+++ b/zephyr/projects/nissa/src/usbc.c
@@ -9,6 +9,8 @@
#include "usb_mux.h"
#include "driver/tcpm/tcpci.h"
#include "driver/tcpm/raa489000.h"
+
+#include "gpios.h"
#include "sub_board.h"
#define CPRINTS(format, args...) cprints(CC_USBCHARGE, format, ## args)
@@ -175,7 +177,7 @@ uint16_t tcpc_get_alert_status(void)
* Therefore, go out and actually read the alert registers to report the
* alert status.
*/
- if (!gpio_get_level(GPIO_USB_C0_PD_INT_ODL)) {
+ if (!gpio_pin_get_dt(&gpio_usb_c0_int_odl)) {
if (!tcpc_read16(0, TCPC_REG_ALERT, &regval)) {
/* The TCPCI Rev 1.0 spec says to ignore bits 14:12. */
if (!(tcpc_config[0].flags & TCPC_FLAGS_TCPCI_REV2_0))
@@ -187,7 +189,7 @@ uint16_t tcpc_get_alert_status(void)
}
if (board_get_usb_pd_port_count() == 2 &&
- !gpio_get_level(GPIO_USB_C1_PD_INT_ODL)) {
+ !gpio_pin_get_dt(&gpio_usb_c1_int_odl)) {
if (!tcpc_read16(1, TCPC_REG_ALERT, &regval)) {
/* TCPCI spec Rev 1.0 says to ignore bits 14:12. */
if (!(tcpc_config[1].flags & TCPC_FLAGS_TCPCI_REV2_0))
@@ -274,20 +276,22 @@ static void usbc_interrupt_trigger(int port)
}
#define USBC_INT_POLL_DATA(port) poll_c ## port ## _int_data
-#define USBC_INT_POLL(port) \
- static void poll_c ## port ## _int (void) \
- { \
- if (!gpio_get_level(GPIO_USB_C ## port ## _PD_INT_ODL)) { \
- usbc_interrupt_trigger(port); \
- hook_call_deferred(&USBC_INT_POLL_DATA(port), \
- USBC_INT_POLL_DELAY_US); \
- } \
+#define USBC_INT_POLL(port) \
+ static void poll_c ## port ## _int (void) \
+ { \
+ if (!gpio_pin_get_dt(&gpio_usb_c ## port ## _int_odl)) { \
+ usbc_interrupt_trigger(port); \
+ hook_call_deferred(&USBC_INT_POLL_DATA(port), \
+ USBC_INT_POLL_DELAY_US); \
+ } \
}
USBC_INT_POLL(0)
USBC_INT_POLL(1)
-void usb_c0_interrupt(enum gpio_signal gpio)
+void usb_c0_interrupt(const struct device *port,
+ struct gpio_callback *cb,
+ gpio_port_pins_t pins)
{
/*
* We've just been called from a falling edge, so there's definitely
@@ -300,17 +304,43 @@ void usb_c0_interrupt(enum gpio_signal gpio)
hook_call_deferred(&USBC_INT_POLL_DATA(0), USBC_INT_POLL_DELAY_US);
}
-void usb_c1_interrupt(enum gpio_signal gpio)
+void usb_c1_interrupt(const struct device *port,
+ struct gpio_callback *cb,
+ gpio_port_pins_t pins)
{
hook_call_deferred(&USBC_INT_POLL_DATA(1), -1);
usbc_interrupt_trigger(1);
hook_call_deferred(&USBC_INT_POLL_DATA(1), USBC_INT_POLL_DELAY_US);
}
+/*
+ * Set up one USB port's interrupt handling.
+ */
+static void usbc_init_interrupt(int port,
+ const struct gpio_dt_spec *gpio,
+ struct gpio_callback *cb_data,
+ gpio_callback_handler_t cb)
+{
+ int ret;
+
+ gpio_init_callback(cb_data, cb, BIT(gpio->pin));
+ gpio_add_callback(gpio->port, cb_data);
+ ret = gpio_pin_interrupt_configure_dt(gpio, GPIO_INT_EDGE_FALLING);
+ if (ret != 0)
+ CPRINTS("USB init interrupt failed on port %d", port);
+}
+
static void usbc_init(void)
{
- gpio_enable_interrupt(GPIO_USB_C0_PD_INT_ODL);
+ static struct gpio_callback c0_callback;
+ static struct gpio_callback c1_callback;
+
+ usbc_init_interrupt(0, &gpio_usb_c0_int_odl,
+ &c0_callback,
+ usb_c0_interrupt);
if (board_get_usb_pd_port_count() == 2)
- gpio_enable_interrupt(GPIO_USB_C1_PD_INT_ODL);
+ usbc_init_interrupt(1, &gpio_usb_c1_int_odl,
+ &c1_callback,
+ usb_c1_interrupt);
}
DECLARE_HOOK(HOOK_INIT, usbc_init, HOOK_PRIO_DEFAULT);