From 88970330f8610c5cd26ea88f8a7b0ddc7da83565 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Barna=C5=9B?= Date: Thu, 17 Feb 2022 16:27:22 +0100 Subject: zephyr: remove the named-ioexes and move ioex logic to gpio MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit removes the named-ioexes node in device tree and moves the io expanders logic to gpio one. The ioex_* functions are now a wrappers to gpio_* ones. BRANCH=main BUG=b:216644442 TEST=zmake testall Change-Id: I61b341a1b968ce376b0420ff05b50f910c75a168 Signed-off-by: Michał Barnaś Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3471601 Reviewed-by: Jeremy Bettis --- include/ioexpander.h | 52 ++++ zephyr/CMakeLists.txt | 2 - zephyr/Kconfig.ioex | 10 +- zephyr/dts/bindings/gpio/gpio-enum-name.yaml | 125 ++++++++ zephyr/dts/bindings/gpio/ioex-enum-name.yaml | 132 --------- zephyr/dts/bindings/gpio/named-ioexes.yaml | 21 -- zephyr/projects/brya/gpio.dts | 12 - zephyr/projects/brya/prj.conf | 1 - .../projects/intelrvp/adlrvp/adlrvp_npcx/gpio.dts | 61 ++++ zephyr/projects/intelrvp/adlrvp/ioex.dts | 80 ----- zephyr/projects/intelrvp/adlrvp/prj.conf | 1 - zephyr/projects/skyrim/gpio.dts | 45 +-- zephyr/projects/skyrim/prj.conf | 1 - zephyr/shim/include/zephyr_gpio_signal.h | 26 +- zephyr/shim/src/ioex.c | 325 +-------------------- 15 files changed, 258 insertions(+), 636 deletions(-) delete mode 100644 zephyr/dts/bindings/gpio/ioex-enum-name.yaml delete mode 100644 zephyr/dts/bindings/gpio/named-ioexes.yaml diff --git a/include/ioexpander.h b/include/ioexpander.h index fb47b874a5..c3023a2236 100644 --- a/include/ioexpander.h +++ b/include/ioexpander.h @@ -7,7 +7,12 @@ #ifndef __CROS_EC_IOEXPANDER_H #define __CROS_EC_IOEXPANDER_H +#ifdef CONFIG_ZEPHYR +#define ioex_signal gpio_signal +#include "gpio.h" +#else enum ioex_signal; /* from gpio_signal.h */ +#endif /* IO expander signal definition structure */ struct ioex_info { @@ -81,6 +86,51 @@ struct ioexpander_config_t { extern struct ioexpander_config_t ioex_config[]; +#ifdef CONFIG_ZEPHYR + +#define ioex_enable_interrupt gpio_enable_interrupt +#define ioex_disable_interrupt gpio_disable_interrupt + +#ifdef CONFIG_GPIO_GET_EXTENDED +inline int ioex_get_flags(enum gpio_signal signal, int *flags) +{ + *flags = gpio_get_flags(signal); + return EC_SUCCESS; +} +#endif + +inline int ioex_set_flags(enum gpio_signal signal, int flags) +{ + gpio_set_flags(signal, flags); + return EC_SUCCESS; +} + +inline int ioex_get_level(enum gpio_signal signal, int *val) +{ + *val = gpio_get_level(signal); + return EC_SUCCESS; +} + +inline int ioex_set_level(enum gpio_signal signal, int val) +{ + gpio_set_level(signal, val); + return EC_SUCCESS; +} + +int ioex_init(int ioex); + +inline const char *ioex_get_name(enum ioex_signal signal) +{ + return gpio_get_name(signal); +} + +inline int signal_is_ioex(int signal) +{ + return 0; +} + +#else + /* * Enable the interrupt for the IOEX signal * @@ -199,4 +249,6 @@ int ioex_save_gpio_state(int ioex, int *state, int state_len); */ int ioex_restore_gpio_state(int ioex, const int *state, int state_len); +#endif /* CONFIG_ZEPHYR */ + #endif /* __CROS_EC_IOEXPANDER_H */ diff --git a/zephyr/CMakeLists.txt b/zephyr/CMakeLists.txt index cae062a13e..feccdd34d4 100644 --- a/zephyr/CMakeLists.txt +++ b/zephyr/CMakeLists.txt @@ -262,8 +262,6 @@ zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_I2C_DEBUG "${PLATFORM_EC}/common/i2c_trace.c") zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_I2C_VIRTUAL_BATTERY "${PLATFORM_EC}/common/virtual_battery.c") -zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_CONSOLE_CMD_IOEX - "${PLATFORM_EC}/common/ioexpander_commands.c") zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_IOEX_CCGXXF "${PLATFORM_EC}/driver/ioexpander/ccgxxf.c") zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_IOEX_IT8801 diff --git a/zephyr/Kconfig.ioex b/zephyr/Kconfig.ioex index 08cedb8d2a..ce020c4fbb 100644 --- a/zephyr/Kconfig.ioex +++ b/zephyr/Kconfig.ioex @@ -15,19 +15,11 @@ if PLATFORM_EC_IOEX config PLATFORM_EC_IOEX_INIT_PRIORITY int "IO expander init priority" range 0 99 - default 52 + default 50 help Sets the priority of function that initializes the IO expander subsystem -config PLATFORM_EC_CONSOLE_CMD_IOEX - bool "Enable shell commands for IO expander" - depends on SHELL - help - Enable shell commands for IO expander. - It will enable ioexget and ioexset commands in EC console - that allow to get and change values of IO expanders pins. - config PLATFORM_EC_IOEX_CROS_DRV bool help diff --git a/zephyr/dts/bindings/gpio/gpio-enum-name.yaml b/zephyr/dts/bindings/gpio/gpio-enum-name.yaml index 1cdb7a43f7..9d7ed31b62 100644 --- a/zephyr/dts/bindings/gpio/gpio-enum-name.yaml +++ b/zephyr/dts/bindings/gpio/gpio-enum-name.yaml @@ -121,3 +121,128 @@ properties: - GPIO_VOLUME_DOWN_L - GPIO_VOLUME_UP_L - GPIO_WARM_RESET_L + - IOEX_5V_DC_DC_MODE_CTRL + - IOEX_ATMEL_MISO + - IOEX_ATMEL_MOSI + - IOEX_ATMEL_RESET_L + - IOEX_ATMEL_SCLK + - IOEX_ATMEL_SS + - IOEX_BAT_LED_AMBER_L + - IOEX_BAT_LED_GREEN_FULL_L + - IOEX_BAT_LED_RED_L + - IOEX_BAT_LED_WHITE_L + - IOEX_BOARD_ID_DET0 + - IOEX_BOARD_ID_DET1 + - IOEX_BOARD_ID_DET2 + - IOEX_C1_CHARGER_LED_AMBER_DB + - IOEX_C1_CHARGER_LED_WHITE_DB + - IOEX_DAC_BUF1_LATCH_FAULT_L + - IOEX_DAC_BUF2_LATCH_FAULT_L + - IOEX_DONGLE_DET + - IOEX_DUT_CHG_EN + - IOEX_EN_PP3300_DP + - IOEX_EN_PP3300_ETH + - IOEX_EN_PP5000_ALT_3P3 + - IOEX_EN_PP5000_USB_A0_VBUS + - IOEX_EN_PP5000_USB_A1_VBUS_DB + - IOEX_EN_PWR_HDMI + - IOEX_EN_PWR_HDMI_DB + - IOEX_EN_USB_A0_5V + - IOEX_EN_USB_A1_5V_DB + - IOEX_EN_USB_A1_5V_DB_OPT1 + - IOEX_EN_USB_A1_5V_DB_OPT2 + - IOEX_EN_VOUT_BUF_CC1 + - IOEX_EN_VOUT_BUF_CC2 + - IOEX_FAULT_CLEAR_CC + - IOEX_HDMI_DATA_EN + - IOEX_HDMI_DATA_EN_DB + - IOEX_HDMI_POWER_EN_DB + - IOEX_HOST_CHRG_DET + - IOEX_HOST_OR_CHG_CTL + - IOEX_ID_1_USB_C0_FRS_EN + - IOEX_ID_1_USB_C0_OC_ODL + - IOEX_ID_1_USB_C0_RT_RST_ODL + - IOEX_ID_1_USB_C1_OC_ODL + - IOEX_ID_1_USB_C2_FRS_EN + - IOEX_ID_1_USB_C2_OC_ODL + - IOEX_ID_1_USB_C2_RT_RST_ODL + - IOEX_KB_BL_EN + - IOEX_LED_BLUE + - IOEX_LED_GREEN + - IOEX_LED_ORANGE + - IOEX_PP3300_DP_FAULT_L + - IOEX_PP5000_SRC_SEL + - IOEX_PPC_ID + - IOEX_PWR_LED_WHITE_L + - IOEX_SBU_FLIP_SEL + - IOEX_SBU_UART_SEL + - IOEX_SYS_PWR_IRQ_ODL + - IOEX_TCA_GPIO_DBG_LED_K_ODL + - IOEX_UART_18_SEL + - IOEX_USB3_A0_FAULT_L + - IOEX_USB3_A0_MUX_EN_L + - IOEX_USB3_A0_MUX_SEL + - IOEX_USB3_A0_PWR_EN + - IOEX_USB3_A1_FAULT_L + - IOEX_USB3_A1_MUX_SEL + - IOEX_USB3_A1_PWR_EN + - IOEX_USB_A0_CHARGE_EN_L + - IOEX_USB_A0_LIMIT_SDP + - IOEX_USB_A0_RETIMER_EN + - IOEX_USB_A0_RETIMER_RST + - IOEX_USB_A1_CHARGE_EN_DB_L + - IOEX_USB_A1_CHARGE_EN_DB_L_OPT1 + - IOEX_USB_A1_CHARGE_EN_DB_L_OPT2 + - IOEX_USB_A1_FAULT_DB_ODL + - IOEX_USB_A1_LIMIT_SDP_DB + - IOEX_USB_A1_RETIMER_EN + - IOEX_USB_A1_RETIMER_EN_OPT1 + - IOEX_USB_A1_RETIMER_EN_OPT2 + - IOEX_USB_A1_RETIMER_RST + - IOEX_USB_A1_RETIMER_RST_DB + - IOEX_USB_C0_BB_RETIMER_LS_EN + - IOEX_USB_C0_BB_RETIMER_RST + - IOEX_USB_C0_C1_OC + - IOEX_USB_C0_DATA_EN + - IOEX_USB_C0_FAULT_ODL + - IOEX_USB_C0_FRS_EN + - IOEX_USB_C0_OC_ODL + - IOEX_USB_C0_PPC_EN_L + - IOEX_USB_C0_PPC_ILIM_3A_EN + - IOEX_USB_C0_RT_RST_ODL + - IOEX_USB_C0_SBU_FLIP + - IOEX_USB_C0_TCPC_FASTSW_CTL_EN + - IOEX_USB_C0_USB_MUX_CNTRL_0 + - IOEX_USB_C0_USB_MUX_CNTRL_1 + - IOEX_USB_C1_BB_RETIMER_LS_EN + - IOEX_USB_C1_BB_RETIMER_RST + - IOEX_USB_C1_DATA_EN + - IOEX_USB_C1_FAULT_ODL + - IOEX_USB_C1_FRS_EN + - IOEX_USB_C1_HPD + - IOEX_USB_C1_HPD_IN_DB + - IOEX_USB_C1_IN_HPD + - IOEX_USB_C1_MUX_RST_DB + - IOEX_USB_C1_OC_ODL + - IOEX_USB_C1_POWER_SWITCH_ID + - IOEX_USB_C1_PPC_EN_L + - IOEX_USB_C1_PPC_ILIM_3A_EN + - IOEX_USB_C1_RT_RST_ODL + - IOEX_USB_C1_SBU_FLIP + - IOEX_USB_C1_TCPC_FASTSW_CTL_EN + - IOEX_USB_C2_BB_RETIMER_LS_EN + - IOEX_USB_C2_BB_RETIMER_RST + - IOEX_USB_C2_C3_OC + - IOEX_USB_C2_FRS_EN + - IOEX_USB_C2_OC_ODL + - IOEX_USB_C2_RT_RST_ODL + - IOEX_USB_C2_USB_MUX_CNTRL_0 + - IOEX_USB_C2_USB_MUX_CNTRL_1 + - IOEX_USB_C3_BB_RETIMER_LS_EN + - IOEX_USB_C3_BB_RETIMER_RST + - IOEX_USB_DUTCHG_FLT_ODL + - IOEX_USBH_PWRDN_L + - IOEX_USERVO_FASTBOOT_MUX_SEL + - IOEX_USERVO_FAULT_L + - IOEX_USERVO_POWER_EN + - IOEX_VBUS_DISCHRG_EN diff --git a/zephyr/dts/bindings/gpio/ioex-enum-name.yaml b/zephyr/dts/bindings/gpio/ioex-enum-name.yaml deleted file mode 100644 index b3d1d92e5a..0000000000 --- a/zephyr/dts/bindings/gpio/ioex-enum-name.yaml +++ /dev/null @@ -1,132 +0,0 @@ -description: Named IOEXes parent node -properties: - enum-name: - type: string - description: - Names used for IO expanders pins - enum: - - IOEX_5V_DC_DC_MODE_CTRL - - IOEX_ATMEL_MISO - - IOEX_ATMEL_MOSI - - IOEX_ATMEL_RESET_L - - IOEX_ATMEL_SCLK - - IOEX_ATMEL_SS - - IOEX_BAT_LED_AMBER_L - - IOEX_BAT_LED_GREEN_FULL_L - - IOEX_BAT_LED_RED_L - - IOEX_BAT_LED_WHITE_L - - IOEX_BOARD_ID_DET0 - - IOEX_BOARD_ID_DET1 - - IOEX_BOARD_ID_DET2 - - IOEX_C1_CHARGER_LED_AMBER_DB - - IOEX_C1_CHARGER_LED_WHITE_DB - - IOEX_DAC_BUF1_LATCH_FAULT_L - - IOEX_DAC_BUF2_LATCH_FAULT_L - - IOEX_DONGLE_DET - - IOEX_DUT_CHG_EN - - IOEX_EN_PP3300_DP - - IOEX_EN_PP3300_ETH - - IOEX_EN_PP5000_ALT_3P3 - - IOEX_EN_PP5000_USB_A0_VBUS - - IOEX_EN_PP5000_USB_A1_VBUS_DB - - IOEX_EN_PWR_HDMI - - IOEX_EN_PWR_HDMI_DB - - IOEX_EN_USB_A0_5V - - IOEX_EN_USB_A1_5V_DB - - IOEX_EN_USB_A1_5V_DB_OPT1 - - IOEX_EN_USB_A1_5V_DB_OPT2 - - IOEX_EN_VOUT_BUF_CC1 - - IOEX_EN_VOUT_BUF_CC2 - - IOEX_FAULT_CLEAR_CC - - IOEX_HDMI_DATA_EN - - IOEX_HDMI_DATA_EN_DB - - IOEX_HDMI_POWER_EN_DB - - IOEX_HOST_CHRG_DET - - IOEX_HOST_OR_CHG_CTL - - IOEX_ID_1_USB_C0_FRS_EN - - IOEX_ID_1_USB_C0_OC_ODL - - IOEX_ID_1_USB_C0_RT_RST_ODL - - IOEX_ID_1_USB_C1_OC_ODL - - IOEX_ID_1_USB_C2_FRS_EN - - IOEX_ID_1_USB_C2_OC_ODL - - IOEX_ID_1_USB_C2_RT_RST_ODL - - IOEX_KB_BL_EN - - IOEX_LED_BLUE - - IOEX_LED_GREEN - - IOEX_LED_ORANGE - - IOEX_PP3300_DP_FAULT_L - - IOEX_PP5000_SRC_SEL - - IOEX_PPC_ID - - IOEX_PWR_LED_WHITE_L - - IOEX_SBU_FLIP_SEL - - IOEX_SBU_UART_SEL - - IOEX_SYS_PWR_IRQ_ODL - - IOEX_TCA_GPIO_DBG_LED_K_ODL - - IOEX_UART_18_SEL - - IOEX_USB3_A0_FAULT_L - - IOEX_USB3_A0_MUX_EN_L - - IOEX_USB3_A0_MUX_SEL - - IOEX_USB3_A0_PWR_EN - - IOEX_USB3_A1_FAULT_L - - IOEX_USB3_A1_MUX_SEL - - IOEX_USB3_A1_PWR_EN - - IOEX_USB_A0_CHARGE_EN_L - - IOEX_USB_A0_LIMIT_SDP - - IOEX_USB_A0_RETIMER_EN - - IOEX_USB_A0_RETIMER_RST - - IOEX_USB_A1_CHARGE_EN_DB_L - - IOEX_USB_A1_CHARGE_EN_DB_L_OPT1 - - IOEX_USB_A1_CHARGE_EN_DB_L_OPT2 - - IOEX_USB_A1_FAULT_DB_ODL - - IOEX_USB_A1_LIMIT_SDP_DB - - IOEX_USB_A1_RETIMER_EN - - IOEX_USB_A1_RETIMER_EN_OPT1 - - IOEX_USB_A1_RETIMER_EN_OPT2 - - IOEX_USB_A1_RETIMER_RST - - IOEX_USB_A1_RETIMER_RST_DB - - IOEX_USB_C0_BB_RETIMER_LS_EN - - IOEX_USB_C0_BB_RETIMER_RST - - IOEX_USB_C0_C1_OC - - IOEX_USB_C0_DATA_EN - - IOEX_USB_C0_FAULT_ODL - - IOEX_USB_C0_FRS_EN - - IOEX_USB_C0_OC_ODL - - IOEX_USB_C0_PPC_EN_L - - IOEX_USB_C0_PPC_ILIM_3A_EN - - IOEX_USB_C0_RT_RST_ODL - - IOEX_USB_C0_SBU_FLIP - - IOEX_USB_C0_TCPC_FASTSW_CTL_EN - - IOEX_USB_C0_USB_MUX_CNTRL_0 - - IOEX_USB_C0_USB_MUX_CNTRL_1 - - IOEX_USB_C1_BB_RETIMER_LS_EN - - IOEX_USB_C1_BB_RETIMER_RST - - IOEX_USB_C1_DATA_EN - - IOEX_USB_C1_FAULT_ODL - - IOEX_USB_C1_FRS_EN - - IOEX_USB_C1_HPD - - IOEX_USB_C1_HPD_IN_DB - - IOEX_USB_C1_IN_HPD - - IOEX_USB_C1_MUX_RST_DB - - IOEX_USB_C1_OC_ODL - - IOEX_USB_C1_POWER_SWITCH_ID - - IOEX_USB_C1_PPC_EN_L - - IOEX_USB_C1_PPC_ILIM_3A_EN - - IOEX_USB_C1_RT_RST_ODL - - IOEX_USB_C1_SBU_FLIP - - IOEX_USB_C1_TCPC_FASTSW_CTL_EN - - IOEX_USB_C2_BB_RETIMER_LS_EN - - IOEX_USB_C2_BB_RETIMER_RST - - IOEX_USB_C2_C3_OC - - IOEX_USB_C2_FRS_EN - - IOEX_USB_C2_OC_ODL - - IOEX_USB_C2_RT_RST_ODL - - IOEX_USB_C2_USB_MUX_CNTRL_0 - - IOEX_USB_C2_USB_MUX_CNTRL_1 - - IOEX_USB_C3_BB_RETIMER_LS_EN - - IOEX_USB_C3_BB_RETIMER_RST - - IOEX_USB_DUTCHG_FLT_ODL - - IOEX_USBH_PWRDN_L - - IOEX_USERVO_FASTBOOT_MUX_SEL - - IOEX_USERVO_FAULT_L - - IOEX_USERVO_POWER_EN - - IOEX_VBUS_DISCHRG_EN diff --git a/zephyr/dts/bindings/gpio/named-ioexes.yaml b/zephyr/dts/bindings/gpio/named-ioexes.yaml deleted file mode 100644 index 8fc2c022c0..0000000000 --- a/zephyr/dts/bindings/gpio/named-ioexes.yaml +++ /dev/null @@ -1,21 +0,0 @@ -description: Named IOEXes parent node - -compatible: "named-ioexes" - -child-binding: - description: Named IOEXes child node - include: ioex-enum-name.yaml - properties: - gpios: - type: phandle-array - required: true - label: - required: true - type: string - description: | - Human readable string describing the net name connected - to the I/O expander pin. - "#gpio-cells": - type: int - required: false - const: 0 diff --git a/zephyr/projects/brya/gpio.dts b/zephyr/projects/brya/gpio.dts index 8769a62e13..9bf93035e8 100644 --- a/zephyr/projects/brya/gpio.dts +++ b/zephyr/projects/brya/gpio.dts @@ -270,45 +270,33 @@ usb_c2_rt_int_odl: usb_c2_rt_int_odl { gpios = <&gpio4 1 GPIO_INPUT>; }; - }; - - named-ioexes { - compatible = "named-ioexes"; - usb_c0_oc_odl { gpios = <&ioex_port1 4 GPIO_ODR_HIGH>; enum-name = "IOEX_USB_C0_OC_ODL"; - label = "IOEX_USB_C0_OC_ODL"; }; usb_c0_frs_en { gpios = <&ioex_port1 6 GPIO_OUTPUT_LOW>; enum-name = "IOEX_USB_C0_FRS_EN"; - label = "IOEX_USB_C0_FRS_EN"; }; usb_c0_rt_rst_odl: usb_c0_rt_rst_odl { gpios = <&ioex_port1 7 GPIO_ODR_HIGH>; enum-name = "IOEX_USB_C0_RT_RST_ODL"; - label = "IOEX_USB_C0_RT_RST_ODL"; }; usb_c2_rt_rst_odl: usb_c2_rt_rst_odl { gpios = <&ioex_port2 2 GPIO_ODR_HIGH>; enum-name = "IOEX_USB_C2_RT_RST_ODL"; - label = "IOEX_USB_C2_RT_RST_ODL"; }; usb_c1_oc_odl { gpios = <&ioex_port2 3 GPIO_ODR_HIGH>; enum-name = "IOEX_USB_C1_OC_ODL"; - label = "IOEX_USB_C1_OC_ODL"; }; usb_c2_oc_odl { gpios = <&ioex_port2 4 GPIO_ODR_HIGH>; enum-name = "IOEX_USB_C2_OC_ODL"; - label = "IOEX_USB_C2_OC_ODL"; }; usb_c2_frs_en { gpios = <&ioex_port2 6 GPIO_OUTPUT_LOW>; enum-name = "IOEX_USB_C2_FRS_EN"; - label = "IOEX_USB_C2_FRS_EN"; }; }; diff --git a/zephyr/projects/brya/prj.conf b/zephyr/projects/brya/prj.conf index abe72aa3a1..c6315e9de5 100644 --- a/zephyr/projects/brya/prj.conf +++ b/zephyr/projects/brya/prj.conf @@ -187,7 +187,6 @@ CONFIG_PWM_SHELL=n #IOEX CONFIG_PLATFORM_EC_IOEX=y -CONFIG_PLATFORM_EC_CONSOLE_CMD_IOEX=y CONFIG_GPIO_NCT38XX=y # TODO(b/188605676): bring these features up diff --git a/zephyr/projects/intelrvp/adlrvp/adlrvp_npcx/gpio.dts b/zephyr/projects/intelrvp/adlrvp/adlrvp_npcx/gpio.dts index a62a5b0333..29d2cd9fee 100644 --- a/zephyr/projects/intelrvp/adlrvp/adlrvp_npcx/gpio.dts +++ b/zephyr/projects/intelrvp/adlrvp/adlrvp_npcx/gpio.dts @@ -274,5 +274,66 @@ gpio_ec_kso_02_inv: ec-kso-02-inv { gpios = <&gpio1 7 (GPIO_OUTPUT_LOW | GPIO_ACTIVE_LOW)>; }; + + usb-c0-bb-retimer-rst { + gpios = <&ioex_c0_port 0 GPIO_OUTPUT_LOW>; + enum-name = "IOEX_USB_C0_BB_RETIMER_RST"; + }; + usb-c0-bb-retimer-ls-en { + gpios = <&ioex_c0_port 1 GPIO_OUTPUT_LOW>; + enum-name = "IOEX_USB_C0_BB_RETIMER_LS_EN"; + }; + usb-c0-usb-mux-cntrl-1 { + gpios = <&ioex_c0_port 4 GPIO_OUTPUT_LOW>; + enum-name = "IOEX_USB_C0_USB_MUX_CNTRL_1"; + }; + usb-c0-usb-mux-cntrl-0 { + gpios = <&ioex_c0_port 5 GPIO_OUTPUT_LOW>; + enum-name = "IOEX_USB_C0_USB_MUX_CNTRL_0"; + }; + usb-c1-bb-retimer-rst { + gpios = <&ioex_c1_port 0 GPIO_OUTPUT_LOW>; + enum-name = "IOEX_USB_C1_BB_RETIMER_RST"; + }; + usb-c1-bb-retimer-ls-en { + gpios = <&ioex_c1_port 1 GPIO_OUTPUT_LOW>; + enum-name = "IOEX_USB_C1_BB_RETIMER_LS_EN"; + }; + usb-c1-hpd { + gpios = <&ioex_c1_port 2 GPIO_OUTPUT_LOW>; + enum-name = "IOEX_USB_C1_HPD"; + }; + usb-c0-c1-oc { + gpios = <&ioex_c1_port 8 GPIO_OUTPUT_HIGH>; + enum-name = "IOEX_USB_C0_C1_OC"; + }; + usb-c2-bb-retimer-rst { + gpios = <&ioex_c2_port 0 GPIO_OUTPUT_LOW>; + enum-name = "IOEX_USB_C2_BB_RETIMER_RST"; + }; + usb-c2-bb-retimer-ls-en { + gpios = <&ioex_c2_port 1 GPIO_OUTPUT_LOW>; + enum-name = "IOEX_USB_C2_BB_RETIMER_LS_EN"; + }; + usb-c2-usb-mux-cntrl-1 { + gpios = <&ioex_c2_port 4 GPIO_OUTPUT_LOW>; + enum-name = "IOEX_USB_C2_USB_MUX_CNTRL_1"; + }; + usb-c2-usb-mux-cntrl-0 { + gpios = <&ioex_c2_port 5 GPIO_OUTPUT_LOW>; + enum-name = "IOEX_USB_C2_USB_MUX_CNTRL_0"; + }; + usb-c3-bb-retimer-rst { + gpios = <&ioex_c3_port 0 GPIO_OUTPUT_LOW>; + enum-name = "IOEX_USB_C3_BB_RETIMER_RST"; + }; + usb-c3-bb-retimer-ls-en { + gpios = <&ioex_c3_port 1 GPIO_OUTPUT_LOW>; + enum-name = "IOEX_USB_C3_BB_RETIMER_LS_EN"; + }; + usb-c2-c3-oc { + gpios = <&ioex_c3_port 8 GPIO_OUTPUT_HIGH>; + enum-name = "IOEX_USB_C2_C3_OC"; + }; }; }; diff --git a/zephyr/projects/intelrvp/adlrvp/ioex.dts b/zephyr/projects/intelrvp/adlrvp/ioex.dts index 1fd1904c46..93117de943 100644 --- a/zephyr/projects/intelrvp/adlrvp/ioex.dts +++ b/zephyr/projects/intelrvp/adlrvp/ioex.dts @@ -4,86 +4,6 @@ */ / { - named-ioexes { - compatible = "named-ioexes"; - - usb-c0-bb-retimer-rst { - gpios = <&ioex_c0_port 0 GPIO_OUTPUT_LOW>; - enum-name = "IOEX_USB_C0_BB_RETIMER_RST"; - label = "USB_C0_BB_RETIMER_RST"; - }; - usb-c0-bb-retimer-ls-en { - gpios = <&ioex_c0_port 1 GPIO_OUTPUT_LOW>; - enum-name = "IOEX_USB_C0_BB_RETIMER_LS_EN"; - label = "USB_C0_BB_RETIMER_LS_EN"; - }; - usb-c0-usb-mux-cntrl-1 { - gpios = <&ioex_c0_port 4 GPIO_OUTPUT_LOW>; - enum-name = "IOEX_USB_C0_USB_MUX_CNTRL_1"; - label = "USB_C0_USB_MUX_CNTRL_1"; - }; - usb-c0-usb-mux-cntrl-0 { - gpios = <&ioex_c0_port 5 GPIO_OUTPUT_LOW>; - enum-name = "IOEX_USB_C0_USB_MUX_CNTRL_0"; - label = "USB_C0_USB_MUX_CNTRL_0"; - }; - usb-c1-bb-retimer-rst { - gpios = <&ioex_c1_port 0 GPIO_OUTPUT_LOW>; - enum-name = "IOEX_USB_C1_BB_RETIMER_RST"; - label = "USB_C1_BB_RETIMER_RST"; - }; - usb-c1-bb-retimer-ls-en { - gpios = <&ioex_c1_port 1 GPIO_OUTPUT_LOW>; - enum-name = "IOEX_USB_C1_BB_RETIMER_LS_EN"; - label = "USB_C1_BB_RETIMER_LS_EN"; - }; - usb-c1-hpd { - gpios = <&ioex_c1_port 2 GPIO_OUTPUT_LOW>; - enum-name = "IOEX_USB_C1_HPD"; - label = "USB_C1_HPD"; - }; - usb-c0-c1-oc { - gpios = <&ioex_c1_port 8 GPIO_OUTPUT_HIGH>; - enum-name = "IOEX_USB_C0_C1_OC"; - label = "USB_C0_C1_OC"; - }; - usb-c2-bb-retimer-rst { - gpios = <&ioex_c2_port 0 GPIO_OUTPUT_LOW>; - enum-name = "IOEX_USB_C2_BB_RETIMER_RST"; - label = "USB_C2_BB_RETIMER_RST"; - }; - usb-c2-bb-retimer-ls-en { - gpios = <&ioex_c2_port 1 GPIO_OUTPUT_LOW>; - enum-name = "IOEX_USB_C2_BB_RETIMER_LS_EN"; - label = "USB_C2_BB_RETIMER_LS_EN"; - }; - usb-c2-usb-mux-cntrl-1 { - gpios = <&ioex_c2_port 4 GPIO_OUTPUT_LOW>; - enum-name = "IOEX_USB_C2_USB_MUX_CNTRL_1"; - label = "USB_C2_USB_MUX_CNTRL_1"; - }; - usb-c2-usb-mux-cntrl-0 { - gpios = <&ioex_c2_port 5 GPIO_OUTPUT_LOW>; - enum-name = "IOEX_USB_C2_USB_MUX_CNTRL_0"; - label = "USB_C2_USB_MUX_CNTRL_0"; - }; - usb-c3-bb-retimer-rst { - gpios = <&ioex_c3_port 0 GPIO_OUTPUT_LOW>; - enum-name = "IOEX_USB_C3_BB_RETIMER_RST"; - label = "USB_C3_BB_RETIMER_RST"; - }; - usb-c3-bb-retimer-ls-en { - gpios = <&ioex_c3_port 1 GPIO_OUTPUT_LOW>; - enum-name = "IOEX_USB_C3_BB_RETIMER_LS_EN"; - label = "USB_C3_BB_RETIMER_LS_EN"; - }; - usb-c2-c3-oc { - gpios = <&ioex_c3_port 8 GPIO_OUTPUT_HIGH>; - enum-name = "IOEX_USB_C2_C3_OC"; - label = "USB_C2_C3_OC"; - }; - }; - /* IOEX_C0_PCA9675 */ ioex-c0 { compatible = "cros,ioex-chip"; diff --git a/zephyr/projects/intelrvp/adlrvp/prj.conf b/zephyr/projects/intelrvp/adlrvp/prj.conf index 9c4ce17c3d..b09d8bd33a 100644 --- a/zephyr/projects/intelrvp/adlrvp/prj.conf +++ b/zephyr/projects/intelrvp/adlrvp/prj.conf @@ -14,4 +14,3 @@ CONFIG_PLATFORM_EC_BATTERY_TYPE_NO_AUTO_DETECT=y # IOEX CONFIG_PLATFORM_EC_IOEX=y CONFIG_PLATFORM_EC_IOEX_PCA9675=y -CONFIG_PLATFORM_EC_CONSOLE_CMD_IOEX=y diff --git a/zephyr/projects/skyrim/gpio.dts b/zephyr/projects/skyrim/gpio.dts index d173b3ea07..c9ea24c044 100644 --- a/zephyr/projects/skyrim/gpio.dts +++ b/zephyr/projects/skyrim/gpio.dts @@ -183,114 +183,93 @@ ec_flprg2 { gpios = <&gpio8 6 GPIO_INPUT_PULL_UP>; }; - }; - - usba-port-enable-list { - compatible = "cros-ec,usba-port-enable-pins"; - enable-pins = <&ioex_en_pp5500_usb_a0_vbus - &ioex_en_pp5500_usb_a1_vbus>; - }; - - vsby-psl-in-list { - /* PSL_IN1/2/4 are used to wake */ - psl-in-pads = <&psl_in1 &psl_in2 &psl_in4>; - status = "okay"; - }; - - named-ioexes { - compatible = "named-ioexes"; usb_c0_tcpc_fastsw_ctl_en { gpios = <&ioex_c0_port0 4 GPIO_OUTPUT_LOW>; enum-name = "IOEX_USB_C0_TCPC_FASTSW_CTL_EN"; - label = "IOEX_USB_C0_TCPC_FASTSW_CTL_EN"; }; usb_c0_ppc_en_l { gpios = <&ioex_c0_port1 0 GPIO_OUTPUT_LOW>; enum-name = "IOEX_USB_C0_PPC_EN_L"; - label = "IOEX_USB_C0_PPC_EN_L"; }; usb_c0_ppc_ilim_3a_en { gpios = <&ioex_c0_port1 1 GPIO_OUTPUT_LOW>; enum-name = "IOEX_USB_C0_PPC_ILIM_3A_EN"; - label = "IOEX_USB_C0_PPC_ILIM_3A_EN"; }; /* TODO: figure out interrupts */ usb_c0_sbu_fault_odl { gpios = <&ioex_c0_port1 2 GPIO_INPUT>; enum-name = "IOEX_USB_C0_FAULT_ODL"; - label = "IOEX_USB_C0_FAULT_ODL"; }; ioex_en_pp5500_usb_a0_vbus: en_pp5500_usb_a0_vbus { gpios = <&ioex_c0_port1 5 GPIO_OUTPUT_LOW>; enum-name = "IOEX_EN_PP5000_USB_A0_VBUS"; - label = "IOEX_EN_PP5000_USB_A0_VBUS"; }; /* TODO: figure out interrupts */ usb_a0_fault_odl { gpios = <&ioex_c0_port1 6 GPIO_INPUT>; enum-name = "IOEX_USB3_A0_FAULT_L"; - label = "IOEX_USB3_A0_FAULT_L"; }; usb_c0_sbu_flip { gpios = <&ioex_c0_port1 7 GPIO_OUTPUT_LOW>; enum-name = "IOEX_USB_C0_SBU_FLIP"; - label = "IOEX_USB_C0_SBU_FLIP"; }; usb_a1_retimer_en { gpios = <&ioex_c1_port0 0 GPIO_OUTPUT_LOW>; enum-name = "IOEX_USB_A1_RETIMER_EN"; - label = "IOEX_USB_A1_RETIMER_EN"; }; usb_a1_retimer_rst { gpios = <&ioex_c1_port0 1 GPIO_OUTPUT_LOW>; enum-name = "IOEX_USB_A1_RETIMER_RST"; - label = "IOEX_USB_A1_RETIMER_RST"; }; usb_c1_in_hpd { gpios = <&ioex_c1_port0 3 GPIO_OUTPUT_LOW>; enum-name = "IOEX_USB_C1_HPD_IN_DB"; - label = "IOEX_USB_C1_IN_HPD"; }; usb_c1_tcpc_fastsw_ctl_en { gpios = <&ioex_c1_port0 4 GPIO_OUTPUT_LOW>; enum-name = "IOEX_USB_C1_TCPC_FASTSW_CTL_EN"; - label = "IOEX_USB_C1_TCPC_FASTSW_CTL_EN"; }; usb_c1_ppc_en_l { gpios = <&ioex_c1_port1 0 GPIO_OUTPUT_LOW>; enum-name = "IOEX_USB_C1_PPC_EN_L"; - label = "IOEX_USB_C1_PPC_EN_L"; }; usb_c1_ppc_ilim_3a_en { gpios = <&ioex_c1_port1 1 GPIO_OUTPUT_LOW>; enum-name = "IOEX_USB_C1_PPC_ILIM_3A_EN"; - label = "IOEX_USB_C1_PPC_ILIM_3A_EN"; }; /* TODO: figure out interrupts */ usb_c1_sbu_fault_odl { gpios = <&ioex_c1_port1 2 GPIO_INPUT>; enum-name = "IOEX_USB_C1_FAULT_ODL"; - label = "IOEX_USB_C1_FAULT_ODL"; }; ioex_en_pp5500_usb_a1_vbus: en_pp5500_usb_a1_vbus { gpios = <&ioex_c1_port1 5 GPIO_OUTPUT_LOW>; enum-name = "IOEX_EN_PP5000_USB_A1_VBUS_DB"; - label = "IOEX_EN_PP5000_USB_A1_VBUS"; }; /* TODO: figure out interrupts */ usb_a1_fault_db_odl { gpios = <&ioex_c1_port1 6 GPIO_INPUT>; enum-name = "IOEX_USB_A1_FAULT_DB_ODL"; - label = "IOEX_USB_A1_FAULT_DB_ODL"; }; usb_c1_sbu_flip { gpios = <&ioex_c1_port1 7 GPIO_OUTPUT_LOW>; enum-name = "IOEX_USB_C1_SBU_FLIP"; - label = "IOEX_USB_C1_SBU_FLIP"; }; }; + + usba-port-enable-list { + compatible = "cros-ec,usba-port-enable-pins"; + enable-pins = <&ioex_en_pp5500_usb_a0_vbus + &ioex_en_pp5500_usb_a1_vbus>; + }; + + vsby-psl-in-list { + /* PSL_IN1/2/4 are used to wake */ + psl-in-pads = <&psl_in1 &psl_in2 &psl_in4>; + status = "okay"; + }; }; /* PSL input pads*/ diff --git a/zephyr/projects/skyrim/prj.conf b/zephyr/projects/skyrim/prj.conf index 1bc9cb8345..bced7e4911 100644 --- a/zephyr/projects/skyrim/prj.conf +++ b/zephyr/projects/skyrim/prj.conf @@ -125,7 +125,6 @@ CONFIG_PLATFORM_EC_USB_PD_VBUS_MEASURE_CHARGER=y # IOEX CONFIG_GPIO_NCT38XX=y -CONFIG_PLATFORM_EC_CONSOLE_CMD_IOEX=y CONFIG_PLATFORM_EC_IOEX=y # Hibernate and wake diff --git a/zephyr/shim/include/zephyr_gpio_signal.h b/zephyr/shim/include/zephyr_gpio_signal.h index 6522224456..265a7cdf9c 100644 --- a/zephyr/shim/include/zephyr_gpio_signal.h +++ b/zephyr/shim/include/zephyr_gpio_signal.h @@ -49,6 +49,10 @@ enum gpio_signal { #endif GPIO_COUNT, GPIO_LIMIT = 0x0FFF, + + IOEX_SIGNAL_START = GPIO_LIMIT + 1, + IOEX_SIGNAL_END = IOEX_SIGNAL_START, + IOEX_LIMIT = 0x1FFF, }; #undef GPIO_SIGNAL_WITH_COMMA @@ -123,28 +127,6 @@ DT_FOREACH_CHILD(DT_PATH(named_gpios), GPIO_DT_PTR_DECL) #endif /* DT_NODE_EXISTS(DT_PATH(named_gpios)) */ -/* - * Define enums for IO expanders and signals - */ -#define IOEX_SIGNAL(id) DT_STRING_UPPER_TOKEN(id, enum_name) -#define IOEX_SIGNAL_WITH_COMMA(id) \ - COND_CODE_1(DT_NODE_HAS_PROP(id, enum_name), (IOEX_SIGNAL(id), ), ()) -enum ioex_signal { - IOEX_SIGNAL_START = GPIO_LIMIT + 1, - /* Used to ensure that the first IOEX signal is same as start */ - __IOEX_PLACEHOLDER = GPIO_LIMIT, -#if DT_NODE_EXISTS(DT_PATH(named_ioexes)) - DT_FOREACH_CHILD(DT_PATH(named_ioexes), IOEX_SIGNAL_WITH_COMMA) -#endif - IOEX_SIGNAL_END, - IOEX_LIMIT = 0x1FFF, -}; -BUILD_ASSERT(IOEX_SIGNAL_END < IOEX_LIMIT); - -#undef IOEX_SIGNAL_WITH_COMMA -#undef IOEX_SIGNAL - -#define IOEX_COUNT (IOEX_SIGNAL_END - IOEX_SIGNAL_START) #define IOEXPANDER_ID_EXPAND(id) ioex_chip_##id #define IOEXPANDER_ID(id) IOEXPANDER_ID_EXPAND(id) diff --git a/zephyr/shim/src/ioex.c b/zephyr/shim/src/ioex.c index 57027f9241..c3bad885b0 100644 --- a/zephyr/shim/src/ioex.c +++ b/zephyr/shim/src/ioex.c @@ -3,279 +3,26 @@ * found in the LICENSE file. */ -#include -#include #include #include #include - +#include "common.h" #ifdef __REQUIRE_ZEPHYR_GPIOS__ #undef __REQUIRE_ZEPHYR_GPIOS__ #endif -#include "gpio.h" -#include "gpio/gpio.h" -#include "i2c.h" #include "ioexpander.h" -#include "system.h" -#include "util.h" - -#if DT_NODE_EXISTS(DT_PATH(named_ioexes)) LOG_MODULE_REGISTER(ioex_shim, LOG_LEVEL_ERR); -struct ioex_gpio_config { - /* IOEX signal name */ - const char *name; - /* Device pointer to GPIO driver */ - const struct device *dev; - /* Bit number of the pin on the IOEX port */ - gpio_pin_t pin; - /* From DTS, excludes interrupts flags */ - gpio_flags_t init_flags; - /* - * Index of CrOS IO expander chip - * If IO expander uses CrOS EC driver, this value will be one - * of the possible from enum ioexpander_id - * otherwise, if using the Zephyr GPIO driver, this will be -1 - */ - int cros_drv_index; - /* Port of IO expander. Valid only if ioex field is not -1 */ - int port; -}; - -#ifdef CONFIG_PLATFORM_EC_IOEX_CROS_DRV -#define IOEX_IS_CROS_DRV(config) (config->cros_drv_index >= 0) -#else +#ifndef CONFIG_PLATFORM_EC_IOEX_CROS_DRV /* * If no legacy cros-ec IOEX drivers are used, we need a stub * symbol for ioex_config[]. Set the IOEX_IS_CROS_DRV to constant 0 * which will cause all these checks to compile out. */ -#define IOEX_IS_CROS_DRV(config) 0 struct ioexpander_config_t ioex_config[0]; #endif -struct ioex_int_config { - const enum ioex_signal signal; - const gpio_flags_t flags; - - void (*const handler)(enum gpio_signal); - struct gpio_callback callback; -}; - -/* Check IOEX interrupts flags */ -#define IOEX_INT(sig, f, cb) \ - BUILD_ASSERT(VALID_GPIO_INTERRUPT_FLAG(f), \ - STRINGIFY(sig) " is not using Zephyr interrupt flags"); -#ifdef EC_CROS_IOEX_INTERRUPTS -EC_CROS_IOEX_INTERRUPTS -#endif -#undef IOEX_INT - -/* Declare handlers */ -#ifdef EC_CROS_IOEX_INTERRUPTS -#define IOEX_INT(arg_signal, arg_flags, arg_handler) \ - void arg_handler(enum gpio_signal); -EC_CROS_IOEX_INTERRUPTS -#undef IOEX_INT -#endif /* EC_CROS_IOEX_INTERRUPTS */ - -#define IOEX_INT(arg_signal, arg_flags, arg_handler) \ -{ \ - .signal = arg_signal, \ - .flags = arg_flags, \ - .handler = arg_handler, \ -}, - -struct ioex_int_config ioex_int_configs[] = { -#ifdef EC_CROS_IOEX_INTERRUPTS - EC_CROS_IOEX_INTERRUPTS -#endif -}; -#undef IOEX_INT - -#define CHIP_FROM_GPIO(id) DT_PARENT(DT_GPIO_CTLR(id, gpios)) - -#define IOEX_GPIO_CONFIG(id) \ - { \ - .name = DT_LABEL(id), \ - .dev = DEVICE_DT_GET(DT_PHANDLE(id, gpios)), \ - .pin = DT_GPIO_PIN(id, gpios), \ - .init_flags = DT_GPIO_FLAGS(id, gpios), \ - .cros_drv_index = \ - COND_CODE_1(DT_NODE_HAS_COMPAT(CHIP_FROM_GPIO(id), \ - cros_ioex_chip), \ - (IOEXPANDER_ID(CHIP_FROM_GPIO(id)), ), \ - (-1,)) \ - .port = DT_REG_ADDR(DT_GPIO_CTLR(id, gpios)) \ - }, - -#define IOEX_INIT_FLAGS(id) 0, - -static const struct ioex_gpio_config ioex_gpio_configs[] = { - DT_FOREACH_CHILD(DT_PATH(named_ioexes), IOEX_GPIO_CONFIG) -}; - -static gpio_flags_t ioex_signals_flags[] = { - DT_FOREACH_CHILD(DT_PATH(named_ioexes), IOEX_INIT_FLAGS) -}; -BUILD_ASSERT(ARRAY_SIZE(ioex_signals_flags) == IOEX_COUNT); - -int signal_is_ioex(int signal) -{ - return ((signal >= IOEX_SIGNAL_START) && (signal < IOEX_SIGNAL_END)); -} - -static struct ioex_int_config *get_interrupt_from_signal( - enum ioex_signal signal) -{ - for (size_t i = 0; i < ARRAY_SIZE(ioex_int_configs); i++) { - if (ioex_int_configs[i].signal == signal) - return &ioex_int_configs[i]; - } - - LOG_ERR("No interrupt defined for GPIO %s", - ioex_gpio_configs[signal - IOEX_SIGNAL_START].name); - - return NULL; -} - -static const struct ioex_gpio_config *ioex_get_signal_info( - enum ioex_signal signal) -{ - const struct ioex_gpio_config *g; - - ASSERT(signal_is_ioex(signal)); - - g = ioex_gpio_configs + signal - IOEX_SIGNAL_START; - - if (IOEX_IS_CROS_DRV(g) && - !(ioex_config[g->cros_drv_index].flags & IOEX_FLAGS_INITIALIZED)) { - LOG_ERR("ioex %s disabled", g->name); - return NULL; - } - - return g; -} - -int ioex_enable_interrupt(enum ioex_signal signal) -{ - struct ioex_int_config *cfg = get_interrupt_from_signal(signal); - int offset = (signal - IOEX_SIGNAL_START); - int res; - - if (!cfg) - return EC_ERROR_PARAM1; - - res = gpio_pin_interrupt_configure(ioex_gpio_configs[offset].dev, - ioex_gpio_configs[offset].pin, - (cfg->flags | GPIO_INT_ENABLE) - & ~GPIO_INT_DISABLE); - - if (res) - LOG_ERR("Can't enable interrupt on %s", - ioex_gpio_configs[offset].name); - - return res; -} - -int ioex_disable_interrupt(enum ioex_signal signal) -{ - struct ioex_int_config *cfg = get_interrupt_from_signal(signal); - int offset = (signal - IOEX_SIGNAL_START); - int res; - - if (!cfg) - return EC_ERROR_PARAM1; - - res = gpio_pin_interrupt_configure(ioex_gpio_configs[offset].dev, - ioex_gpio_configs[offset].pin, - GPIO_INT_DISABLE); - - if (res) - LOG_ERR("Can't disable interrupt on %s", - ioex_gpio_configs[offset].name); - - return res; -} - -int ioex_get_flags(enum ioex_signal signal, int *flags) -{ - if (!signal_is_ioex(signal)) - return EC_ERROR_INVAL; - - *flags = convert_from_zephyr_flags( - ioex_signals_flags[signal - IOEX_SIGNAL_START]); - - return EC_SUCCESS; -} - -int ioex_set_flags(enum ioex_signal signal, int flags) -{ - const struct ioex_gpio_config *g = ioex_get_signal_info(signal); - - if (g == NULL) - return EC_ERROR_INVAL; - - if (gpio_pin_configure(g->dev, - g->pin, - convert_to_zephyr_flags(flags)) < 0) { - return EC_ERROR_UNKNOWN; - } - - ioex_signals_flags[signal - IOEX_SIGNAL_START] = - convert_to_zephyr_flags(flags); - - return EC_SUCCESS; -} - -int ioex_get_level(enum ioex_signal signal, int *val) -{ - const struct ioex_gpio_config *g = ioex_get_signal_info(signal); - int res; - - if (g == NULL) - return EC_ERROR_INVAL; - - res = gpio_pin_get_raw(g->dev, g->pin); - if (res < 0) - return EC_ERROR_UNKNOWN; - - *val = res; - - return EC_SUCCESS; -} - -int ioex_set_level(enum ioex_signal signal, int value) -{ - const struct ioex_gpio_config *g = ioex_get_signal_info(signal); - int res; - - if (g == NULL) - return EC_ERROR_INVAL; - - res = gpio_pin_set_raw(g->dev, g->pin, value); - if (res) - return EC_ERROR_UNKNOWN; - - return EC_SUCCESS; -} - -int ioex_get_port(int ioex, int port, int *val) -{ - return EC_ERROR_UNIMPLEMENTED; -} - -static void ioex_isr(const struct device *port, - struct gpio_callback *cb, - gpio_port_pins_t pins) -{ - struct ioex_int_config *cfg = - CONTAINER_OF(cb, struct ioex_int_config, callback); - - cfg->handler(cfg->signal); -} - int ioex_init(int ioex) { if (!IS_ENABLED(CONFIG_PLATFORM_EC_IOEX_CROS_DRV)) @@ -298,6 +45,7 @@ int ioex_init(int ioex) return EC_SUCCESS; } +#ifdef CONFIG_PLATFORM_EC_IOEX_CROS_DRV static int ioex_init_default(const struct device *unused) { int ret; @@ -316,74 +64,7 @@ static int ioex_init_default(const struct device *unused) LOG_ERR("Can't initialize ioex %d", i); } - /* - * Set all IO expander GPIOs to default flags according to the setting - * in device tree - */ - for (i = 0; i < IOEX_COUNT; i++) { - const struct ioex_gpio_config *g = - ioex_get_signal_info(IOEX_SIGNAL_START + i); - int flags; - - if (!g) - continue; - - flags = g->init_flags; - /* Late-sysJump should not set the output levels */ - if (system_jumped_late()) - flags &= ~(GPIO_LOW | GPIO_HIGH); - - ret = gpio_pin_configure(g->dev, g->pin, flags); - if (ret) - LOG_ERR("Can't configure %s", g->name); - - ioex_signals_flags[i] = g->init_flags; - } - - /* Init interrupts */ - for (i = 0; i < ARRAY_SIZE(ioex_int_configs); i++) { - int offset = ioex_int_configs[i].signal - IOEX_SIGNAL_START; - - gpio_init_callback(&ioex_int_configs[i].callback, - ioex_isr, - BIT(ioex_gpio_configs[offset].pin)); - ret = gpio_add_callback(ioex_gpio_configs[offset].dev, - &ioex_int_configs[i].callback); - if (ret) - LOG_ERR("Can't add callback to %s", - ioex_gpio_configs[offset].name); - } - return 0; } SYS_INIT(ioex_init_default, POST_KERNEL, CONFIG_PLATFORM_EC_IOEX_INIT_PRIORITY); - -const char *ioex_get_name(enum ioex_signal signal) -{ - const struct ioex_gpio_config *g = ioex_get_signal_info(signal); - - if (g == NULL) - return NULL; - - return g->name; -} - -int ioex_get_ioex_flags(enum ioex_signal signal, int *val) -{ - const struct ioex_gpio_config *g = ioex_get_signal_info(signal); - - if (g == NULL) - return EC_ERROR_INVAL; - - if (!IOEX_IS_CROS_DRV(g)) { - /* Zephyr gpio drivers are initialized by internal subsystem */ - *val = IOEX_FLAGS_INITIALIZED; - return EC_SUCCESS; - } - - *val = ioex_config[g->cros_drv_index].flags; - - return EC_SUCCESS; -} - #endif -- cgit v1.2.1