diff options
author | Yuval Peress <peress@chromium.org> | 2020-11-13 11:09:40 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-11-20 20:22:22 +0000 |
commit | 8abeefdccbc98eec5e24da971e0bfe0cb2fbf279 (patch) | |
tree | c63ebf756372506f4d7e11b5b05d4e9ee4ca3770 /zephyr | |
parent | 325910fad3177a443048a65177a0b17a58f95d4e (diff) | |
download | chrome-ec-8abeefdccbc98eec5e24da971e0bfe0cb2fbf279.tar.gz |
zephyr: add i2c_ports enum
This change adds an i2c_ports enum based on the devicetree
phandle list 'named-i2c-ports'. Modeled after named-gpios.
Currently, this is only enabled for ztests as it conflicts
with the definitions in config_chip-npcx7.h. But once that
dependency is removed, this enum will become publicly
available.
BUG=b:171302975
BRANCH=none
TEST=../zephyr-chrome/firmware_builder.py test
Cq-Depend: chromium:2546328
Signed-off-by: Yuval Peress <peress@chromium.org>
Change-Id: I8e763da0c867fed383eb333092f191079fb792ea
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2546997
Reviewed-by: Jett Rink <jettrink@chromium.org>
Diffstat (limited to 'zephyr')
-rw-r--r-- | zephyr/shim/include/config_chip.h | 17 | ||||
-rw-r--r-- | zephyr/test/i2c/CMakeLists.txt | 28 | ||||
-rw-r--r-- | zephyr/test/i2c/boards/native_posix.overlay | 22 | ||||
-rw-r--r-- | zephyr/test/i2c/prj.conf | 18 | ||||
-rw-r--r-- | zephyr/test/i2c/src/main.c | 43 | ||||
-rw-r--r-- | zephyr/test/i2c/zmake.yaml | 9 |
6 files changed, 137 insertions, 0 deletions
diff --git a/zephyr/shim/include/config_chip.h b/zephyr/shim/include/config_chip.h index d767b5ad90..64c8afc2ab 100644 --- a/zephyr/shim/include/config_chip.h +++ b/zephyr/shim/include/config_chip.h @@ -6,6 +6,8 @@ #ifndef __CROS_EC_CONFIG_CHIP_H #define __CROS_EC_CONFIG_CHIP_H +#include <devicetree.h> + /* * This file translates Kconfig options to platform/ec options. * @@ -64,6 +66,21 @@ #ifdef CONFIG_PLATFORM_EC_I2C #define CONFIG_I2C + +/* + * Define the i2c_ports enum for Ztests only right now. In full builds this + * will clash with the definitions in config_chip-npcx7.h. Once we've migrated + * away from platform/ec/chip/... files we can remove this guard. + */ +#if defined(CONFIG_ZTEST) && DT_NODE_EXISTS(DT_PATH(named_i2c_ports)) +#define I2C_PORT(id) DT_CAT(I2C_, id) +#define I2C_PORT_WITH_COMMA(id) I2C_PORT(id), +enum i2c_ports { +DT_FOREACH_CHILD(DT_PATH(named_i2c_ports), I2C_PORT_WITH_COMMA) +I2C_PORT_COUNT +}; +#define NAMED_I2C(name) I2C_PORT(DT_PATH(named_i2c_ports, name)) +#endif /* CONFIG_ZTEST && named_i2c_ports */ #endif /* CONFIG_PLATFORM_EC_I2C */ #endif /* __CROS_EC_CONFIG_CHIP_H */ diff --git a/zephyr/test/i2c/CMakeLists.txt b/zephyr/test/i2c/CMakeLists.txt new file mode 100644 index 0000000000..097c31f498 --- /dev/null +++ b/zephyr/test/i2c/CMakeLists.txt @@ -0,0 +1,28 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.13.1) +set(BOARD native_posix) +project(base32) +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) + +# Need to ensure that we are including only zephyr definitions in include files +# We cannot set these via kconfig, since this unit test does not bring in the +# zephyr-chrome repository +zephyr_compile_definitions("CONFIG_ZEPHYR") +zephyr_compile_definitions("CONFIG_PLATFORM_EC_I2C") + +# We need to include the EC include directory and this local test directory +# for the task defines +zephyr_include_directories( + "${PLATFORM_EC}/zephyr/shim/include" + "${PLATFORM_EC}/fuzz" + "${PLATFORM_EC}/test" + "${PLATFORM_EC}/include") + +# Include test file, test under test and console dependency +target_sources(app PRIVATE + src/main.c + "${PLATFORM_EC}/zephyr/shim/src/console.c" + "${PLATFORM_EC}/zephyr/shim/src/i2c.c" + "${PLATFORM_EC}/zephyr/shim/src/util.c" + "${PLATFORM_EC}/common/i2c_master.c") diff --git a/zephyr/test/i2c/boards/native_posix.overlay b/zephyr/test/i2c/boards/native_posix.overlay new file mode 100644 index 0000000000..272be85361 --- /dev/null +++ b/zephyr/test/i2c/boards/native_posix.overlay @@ -0,0 +1,22 @@ +/* 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. + */ + +/ { + named-i2c-ports { + compatible = "i2c-keys"; + accel-0 { + i2c-port = <&bmi_i2c>; + label = "ACCEL_0"; + }; + }; +}; + +&i2c0 { + bmi_i2c: bmi@68 { + compatible = "bosch,bmi160"; + reg = <0x68>; + label = "accel-i2c"; + }; +}; diff --git a/zephyr/test/i2c/prj.conf b/zephyr/test/i2c/prj.conf new file mode 100644 index 0000000000..bbf4d93e8e --- /dev/null +++ b/zephyr/test/i2c/prj.conf @@ -0,0 +1,18 @@ +# 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. + +CONFIG_ZTEST=y +CONFIG_LOG=y + +CONFIG_EMUL=y +CONFIG_I2C=y +CONFIG_I2C_EMUL=y +CONFIG_BMI160=y +CONFIG_EMUL_BMI160=y +CONFIG_SENSOR=y +CONFIG_BMI160_TRIGGER_NONE=y + +# TODO(b/173711210) figure out why SPI is required here when we're not using it. +CONFIG_SPI=y +CONFIG_SPI_EMUL=y diff --git a/zephyr/test/i2c/src/main.c b/zephyr/test/i2c/src/main.c new file mode 100644 index 0000000000..2f8869c775 --- /dev/null +++ b/zephyr/test/i2c/src/main.c @@ -0,0 +1,43 @@ +/* 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 <devicetree.h> +#include <ztest.h> + +#include "common.h" +#include "i2c/i2c.h" + +/* Unused: required for shimming i2c. */ +uint32_t sleep_mask; + +/* Unused: required for shimming i2c. */ +const struct device *i2c_get_device_for_port(int port) +{ + return NULL; +} + +/* Unused: required for shimming i2c. */ +void watchdog_reload(void) +{ +} + +static void test_i2c_port_count(void) +{ + zassert_equal(NAMED_I2C(accel_0), 0, + "accel_0 expected to be 0 but was %d", + NAMED_I2C(accel_0)); + zassert_equal(I2C_PORT_COUNT, 1, + "I2C_PORT_COUNT expected to be 1 but was %d", + I2C_PORT_COUNT); +} + +/* Test case main entry. */ +void test_main(void) +{ + ztest_test_suite(test_i2c, + ztest_user_unit_test(test_i2c_port_count)); + ztest_run_test_suite(test_i2c); +} + diff --git a/zephyr/test/i2c/zmake.yaml b/zephyr/test/i2c/zmake.yaml new file mode 100644 index 0000000000..c784549bb0 --- /dev/null +++ b/zephyr/test/i2c/zmake.yaml @@ -0,0 +1,9 @@ +# 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. + +board: native_posix +supported-zephyr-versions: + - v2.4 +toolchain: zephyr +output-type: elf |