drivers: i2c: add dummy driver for vnd,i2c

We will need this to be able to DEVICE_DT_GET() bus devices from
tests/drivers/build_all in an upcoming commit.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
This commit is contained in:
Martí Bolívar 2021-01-15 16:35:53 -08:00 committed by Anas Nashif
parent 63471ba93b
commit 7bbead6786
5 changed files with 60 additions and 0 deletions

View File

@ -215,6 +215,8 @@
/drivers/i2c/Kconfig.i2c_emul @sjg20
/drivers/i2c/Kconfig.it8xxx2 @GTLin08
/drivers/i2c/slave/*eeprom* @henrikbrixandersen
/drivers/i2c/Kconfig.test @mbolivar-nordic
/drivers/i2c/i2c_test.c @mbolivar-nordic
/drivers/i2s/*litex* @mateusz-holenko @kgugala @pgielda
/drivers/ieee802154/ @jukkar @tbursztyka
/drivers/ieee802154/ieee802154_rf2xx* @jukkar @tbursztyka @nandojve

View File

@ -54,6 +54,8 @@ if(CONFIG_I2C_DW)
endforeach(NUM)
endif()
zephyr_library_sources_ifdef(CONFIG_I2C_TEST i2c_test.c)
zephyr_library_sources_ifdef(CONFIG_USERSPACE i2c_handlers.c)
add_subdirectory_ifdef(CONFIG_I2C_SLAVE slave)

View File

@ -40,6 +40,7 @@ source "drivers/i2c/Kconfig.sam0"
source "drivers/i2c/Kconfig.litex"
source "drivers/i2c/Kconfig.lpc11u6x"
source "drivers/i2c/Kconfig.npcx"
source "drivers/i2c/Kconfig.test"
config I2C_INIT_PRIORITY
int "Init priority"

9
drivers/i2c/Kconfig.test Normal file
View File

@ -0,0 +1,9 @@
# Copyright (c) 2021, Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0
DT_COMPAT_VND_I2C := vnd,i2c
# Hidden option for turning on the dummy driver for vnd,i2c devices
# used in testing.
config I2C_TEST
def_bool $(dt_compat_enabled,$(DT_COMPAT_VND_I2C))

46
drivers/i2c/i2c_test.c Normal file
View File

@ -0,0 +1,46 @@
/*
* Copyright (c) 2021, Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
/*
* This is not a real I2C driver. It is used to instantiate struct
* devices for the "vnd,i2c" devicetree compatible used in test code.
*/
#include <zephyr.h>
#include <drivers/i2c.h>
#define DT_DRV_COMPAT vnd_i2c
static int vnd_i2c_configure(const struct device *dev,
uint32_t dev_config)
{
return -ENOTSUP;
}
static int vnd_i2c_transfer(const struct device *dev,
struct i2c_msg *msgs,
uint8_t num_msgs, uint16_t addr)
{
return -ENOTSUP;
}
static const struct i2c_driver_api vnd_i2c_api = {
.configure = vnd_i2c_configure,
.transfer = vnd_i2c_transfer,
};
static int vnd_i2c_init(const struct device *dev)
{
return 0;
}
#define VND_I2C_INIT(n) \
DEVICE_DT_INST_DEFINE(n, &vnd_i2c_init, device_pm_control_nop, \
NULL, NULL, POST_KERNEL, \
CONFIG_KERNEL_INIT_PRIORITY_DEVICE, \
&vnd_i2c_api);
DT_INST_FOREACH_STATUS_OKAY(VND_I2C_INIT)