diff options
Diffstat (limited to 'zephyr/shim')
-rw-r--r-- | zephyr/shim/CMakeLists.txt | 6 | ||||
-rw-r--r-- | zephyr/shim/chip/CMakeLists.txt | 35 | ||||
-rw-r--r-- | zephyr/shim/chip/npcx/CMakeLists.txt | 5 | ||||
-rw-r--r-- | zephyr/shim/chip/npcx/i2c.c | 44 | ||||
-rw-r--r-- | zephyr/shim/include/config_chip.h | 15 | ||||
-rw-r--r-- | zephyr/shim/include/i2c/i2c.h | 28 | ||||
-rw-r--r-- | zephyr/shim/src/CMakeLists.txt | 8 | ||||
-rw-r--r-- | zephyr/shim/src/i2c.c | 23 |
8 files changed, 161 insertions, 3 deletions
diff --git a/zephyr/shim/CMakeLists.txt b/zephyr/shim/CMakeLists.txt new file mode 100644 index 0000000000..3add679c23 --- /dev/null +++ b/zephyr/shim/CMakeLists.txt @@ -0,0 +1,6 @@ +# Copyright 2020 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. + +add_subdirectory("src") +add_subdirectory("chip") diff --git a/zephyr/shim/chip/CMakeLists.txt b/zephyr/shim/chip/CMakeLists.txt new file mode 100644 index 0000000000..7a77febaa1 --- /dev/null +++ b/zephyr/shim/chip/CMakeLists.txt @@ -0,0 +1,35 @@ +# Copyright 2020 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. + +# Translate Zephyr CONFIG_SOC_* values to platform/ec CHIP_* values. +if (DEFINED CONFIG_SOC_NPCX7M6FB) + set(CHIP_FAMILY "NPCX7") + set(CHIP_VARIANT "NPCX7M6FB") +endif() + +# Add compile definitions for CHIP_FAMILY_ and CHIP_VARIANT_, these are used +# through the platform/ec code and are often used to branch header definitions +# which are still being used. It is possible that eventually (when we also no +# longer require the platform/ec/chip/... headers) that we'll be able to get +# rid of this. +zephyr_compile_definitions("CHIP_FAMILY_${CHIP_FAMILY}") +zephyr_compile_definitions("CHIP_VARIANT_${CHIP_VARIANT}") + +if ("${CHIP_FAMILY}" MATCHES "^NPCX[0-9]$") + add_subdirectory(npcx) + zephyr_include_directories("${PLATFORM_EC}/chip/npcx") + string(TOLOWER "npcx/i2c-${CHIP_FAMILY}.c" chip_specific_i2c_impl) +endif() + +# Adding chip specific i2c implementation here. These contain the specific +# code used to implement generic information about platform/ec +# port numbers and their properties. As such they're basically the +# platform/ec's abstraction of devicetree and aren't worth replacing +# quite yet until a cleaner picture of how the full migration for i2c +# will be done. +if (DEFINED chip_specific_i2c_impl) + zephyr_sources_ifdef(CONFIG_PLATFORM_EC_I2C + "${PLATFORM_EC}/chip/${chip_specific_i2c_impl}") +endif() + diff --git a/zephyr/shim/chip/npcx/CMakeLists.txt b/zephyr/shim/chip/npcx/CMakeLists.txt new file mode 100644 index 0000000000..377cb652b4 --- /dev/null +++ b/zephyr/shim/chip/npcx/CMakeLists.txt @@ -0,0 +1,5 @@ +# Copyright 2020 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. + +zephyr_sources(i2c.c) diff --git a/zephyr/shim/chip/npcx/i2c.c b/zephyr/shim/chip/npcx/i2c.c new file mode 100644 index 0000000000..1f6fe6336d --- /dev/null +++ b/zephyr/shim/chip/npcx/i2c.c @@ -0,0 +1,44 @@ +/* Copyright 2020 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 <sys/util.h> + +#include "registers.h" +#include "i2c/i2c.h" + +/* Shorthand for getting the device binding for a given devicetree label. */ +#define BINDING_FOR(label) \ + device_get_binding( \ + COND_CODE_1(DT_NODE_HAS_STATUS(DT_NODELABEL(label), okay), \ + (DT_LABEL(DT_NODELABEL(label))), (""))) + +static const struct device *i2c_devices[NPCX_I2C_COUNT]; + +static int init_device_bindings(const struct device *device) +{ + ARG_UNUSED(device); + i2c_devices[NPCX_I2C_PORT0_0] = BINDING_FOR(i2c0_0); + i2c_devices[NPCX_I2C_PORT1_0] = BINDING_FOR(i2c1_0); + i2c_devices[NPCX_I2C_PORT2_0] = BINDING_FOR(i2c2_0); + i2c_devices[NPCX_I2C_PORT3_0] = BINDING_FOR(i2c3_0); +#ifdef CHIP_VARIANT_NPCX7M6G + i2c_devices[NPCX_I2C_PORT4_0] = BINDING_FOR(i2c4_0); +#endif + i2c_devices[NPCX_I2C_PORT4_1] = BINDING_FOR(i2c4_1); + i2c_devices[NPCX_I2C_PORT5_0] = BINDING_FOR(i2c5_0); + i2c_devices[NPCX_I2C_PORT5_1] = BINDING_FOR(i2c5_1); + i2c_devices[NPCX_I2C_PORT6_0] = BINDING_FOR(i2c6_0); + i2c_devices[NPCX_I2C_PORT6_1] = BINDING_FOR(i2c6_1); + i2c_devices[NPCX_I2C_PORT7_0] = BINDING_FOR(i2c7_0); + return 0; +} +SYS_INIT(init_device_bindings, POST_KERNEL, 51); + +const struct device *i2c_get_device_for_port(const int port) +{ + if (port < 0 || port >= NPCX_I2C_COUNT) + return NULL; + return i2c_devices[port]; +} diff --git a/zephyr/shim/include/config_chip.h b/zephyr/shim/include/config_chip.h index 511d934bc5..d767b5ad90 100644 --- a/zephyr/shim/include/config_chip.h +++ b/zephyr/shim/include/config_chip.h @@ -51,4 +51,19 @@ #endif /* CONFIG_PLATFORM_EC_TIMER */ +/* + * Load the chip family specific header. Normally for npcx, this would be done + * by chip/npcx/config_chip.h but since this file is replacing that header + * we'll need (for now) to load it ourselves. Long term, the functions, enums, + * and constants in this header will be replaced by more Zephyr/devicetree + * specific code. + */ +#ifdef CHIP_FAMILY_NPCX7 +#include "config_chip-npcx7.h" +#endif /* CHIP_FAMILY_NPCX7 */ + +#ifdef CONFIG_PLATFORM_EC_I2C +#define CONFIG_I2C +#endif /* CONFIG_PLATFORM_EC_I2C */ + #endif /* __CROS_EC_CONFIG_CHIP_H */ diff --git a/zephyr/shim/include/i2c/i2c.h b/zephyr/shim/include/i2c/i2c.h new file mode 100644 index 0000000000..289f8b753e --- /dev/null +++ b/zephyr/shim/include/i2c/i2c.h @@ -0,0 +1,28 @@ +/* Copyright 2020 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_CHROME_I2C_I2C_H +#define ZEPHYR_CHROME_I2C_I2C_H + +#include <device.h> +#include <devicetree.h> + +/** + * @brief Adaptation of platform/ec's port IDs which map a port/bus to a device. + * + * This function should be implemented per chip and should map the enum value + * defined for the chip for encoding each valid port/bus combination. For + * example, the npcx chip defines the port/bus combinations NPCX_I2C_PORT* under + * chip/npcx/registers-npcx7.h. + * + * Thus, the npcx shim should implement this function to map the enum values + * to the correct devicetree device. + * + * @param port The port to get the device for. + * @return Pointer to the device struct or {@code NULL} if none are available. + */ +const struct device *i2c_get_device_for_port(const int port); + +#endif /* ZEPHYR_CHROME_I2C_I2C_H */ diff --git a/zephyr/shim/src/CMakeLists.txt b/zephyr/shim/src/CMakeLists.txt index 3d7f4b3099..8273ba80a5 100644 --- a/zephyr/shim/src/CMakeLists.txt +++ b/zephyr/shim/src/CMakeLists.txt @@ -3,9 +3,11 @@ # found in the LICENSE file. zephyr_sources(console.c) -zephyr_sources(util.c) zephyr_sources(gpio.c) +zephyr_sources(util.c) + zephyr_sources_ifdef(CONFIG_PLATFORM_EC_HOOKS hooks.c) -zephyr_sources_ifdef(CONFIG_CROS_EC system.c) -zephyr_sources_ifdef(CONFIG_SHIMMED_TASKS tasks.c) zephyr_sources_ifdef(CONFIG_PLATFORM_EC_TIMER hwtimer.c) +zephyr_sources_ifdef(CONFIG_PLATFORM_EC_I2C i2c.c) +zephyr_sources_ifdef(CONFIG_CROS_EC system.c) +zephyr_sources_ifdef(CONFIG_SHIMMED_TASKS tasks.c) diff --git a/zephyr/shim/src/i2c.c b/zephyr/shim/src/i2c.c new file mode 100644 index 0000000000..4420cec41c --- /dev/null +++ b/zephyr/shim/src/i2c.c @@ -0,0 +1,23 @@ +/* Copyright 2020 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 "i2c.h" +#include "i2c/i2c.h" + +/* + * Long term we will not need these, for now they're needed to get things to + * build since these extern symbols are usually defined in + * board/${BOARD}/board.c. + * + * Since all the ports will eventually be handled by device tree. This will + * be removed at that point. + */ +const struct i2c_port_t i2c_ports[] = {}; +const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports); + +int i2c_get_line_levels(int port) +{ + return I2C_LINE_IDLE; +} |