diff options
author | Yuval Peress <peress@chromium.org> | 2020-10-28 10:20:08 -0600 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-11-08 03:41:10 +0000 |
commit | 25ae7edffcceb662d5d2ebe92d19bf6f191d8bd5 (patch) | |
tree | 148d8136c062dab69d4a2670f82f87d8d895f07c /zephyr/shim/chip/npcx | |
parent | df5f77987d6707936c13a0e2fee09ddbd84c627a (diff) | |
download | chrome-ec-25ae7edffcceb662d5d2ebe92d19bf6f191d8bd5.tar.gz |
Add chip-specific shim along with i2c module
This change accomplishes 2 things:
1. It refactors the zephyr/shim directory to structure around
chip specific compilation. In this example, we're focusing
on npcx7m6fb which is used in volteer but others can be
added easily.
2. It shims the common/i2c_master.c by providing an alternate
implementation of i2c_xfer_unlocked that calls down to the
Zephyr API i2c_write_read instead of the chip specific
i2c_xfer_no_retry or chip_i2c_xfer_with_notify.
The shim layer is made possible by the addition of
zephyr/shim/include/i2c/i2c.h which adds a functions that
needs to be implemented per chip (npcx7 family in this case)
and allows us to map the current port int which is defined
in chip/${CHIP}/registers.h (chip/npcx/registers-npcx7.h in
our case). This function (i2c_get_device_for_port) maps the
platform/ec port int to a const struct device * which is
needed in the Zephyr I2C APIs.
BRANCH=none
BUG=b:171302975
TEST=clean_build.sh projects/experimental/volteer/ and make BOARD=eve
Signed-off-by: Yuval Peress <peress@chromium.org>
Change-Id: I210f4758337bf384d0d6f103eef8b89126887d11
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2504285
Reviewed-by: Simon Glass <sjg@chromium.org>
Commit-Queue: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'zephyr/shim/chip/npcx')
-rw-r--r-- | zephyr/shim/chip/npcx/CMakeLists.txt | 5 | ||||
-rw-r--r-- | zephyr/shim/chip/npcx/i2c.c | 44 |
2 files changed, 49 insertions, 0 deletions
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]; +} |