From 7bb5568c04011aecdeda2e55a0ca69443d497e3b Mon Sep 17 00:00:00 2001 From: Yuval Peress Date: Wed, 11 Nov 2020 10:40:54 -0700 Subject: Zephyr: Migrate i2c implementation to chip family specific file This change simply moves the i2c.c shim to i2c-npcx7.c. BRANCH=none BUG=none TEST=builds with zmake for volteer Signed-off-by: Yuval Peress Change-Id: Ic410787dcf2693dda71681f739c0b74cd47770da Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2532964 Reviewed-by: Paul Fagerburg Commit-Queue: Paul Fagerburg --- zephyr/shim/chip/npcx/CMakeLists.txt | 3 ++- zephyr/shim/chip/npcx/i2c-npcx7.c | 44 ++++++++++++++++++++++++++++++++++++ zephyr/shim/chip/npcx/i2c.c | 44 ------------------------------------ 3 files changed, 46 insertions(+), 45 deletions(-) create mode 100644 zephyr/shim/chip/npcx/i2c-npcx7.c delete mode 100644 zephyr/shim/chip/npcx/i2c.c diff --git a/zephyr/shim/chip/npcx/CMakeLists.txt b/zephyr/shim/chip/npcx/CMakeLists.txt index 377cb652b4..d464cc3e0b 100644 --- a/zephyr/shim/chip/npcx/CMakeLists.txt +++ b/zephyr/shim/chip/npcx/CMakeLists.txt @@ -2,4 +2,5 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -zephyr_sources(i2c.c) +string(TOLOWER "i2c-${CHIP_FAMILY}.c" chip_specific_i2c_shim) +zephyr_sources(${chip_specific_i2c_shim}) diff --git a/zephyr/shim/chip/npcx/i2c-npcx7.c b/zephyr/shim/chip/npcx/i2c-npcx7.c new file mode 100644 index 0000000000..1f6fe6336d --- /dev/null +++ b/zephyr/shim/chip/npcx/i2c-npcx7.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 + +#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/chip/npcx/i2c.c b/zephyr/shim/chip/npcx/i2c.c deleted file mode 100644 index 1f6fe6336d..0000000000 --- a/zephyr/shim/chip/npcx/i2c.c +++ /dev/null @@ -1,44 +0,0 @@ -/* 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 - -#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]; -} -- cgit v1.2.1