summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuval Peress <peress@google.com>2021-09-29 22:14:27 -0600
committerCommit Bot <commit-bot@chromium.org>2021-10-01 17:45:28 +0000
commit7d2f528aafc357481e01dfcb00dd1968520b38aa (patch)
treeed71178704fbea9d1b92b038301fab4003abae80
parentcf2017d7ccc9ebd50206c477b08a51d1c6bc4433 (diff)
downloadchrome-ec-7d2f528aafc357481e01dfcb00dd1968520b38aa.tar.gz
zephyr: test: Add a common i2c_emul_api instance
Refactor emulators that all set the same i2c_emul_api to use the same common API. BRANCH=none BUG=none TEST=zmake configure --test zephyr/test/drivers Signed-off-by: Yuval Peress <peress@google.com> Change-Id: I6da6df23c77f0710a24bab8d9f0b7fb6fa14dff2 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3195201 Reviewed-by: Tomasz Michalec <tm@semihalf.com> Reviewed-by: Jeremy Bettis <jbettis@chromium.org>
-rw-r--r--zephyr/emul/emul_bb_retimer.c6
-rw-r--r--zephyr/emul/emul_bma255.c6
-rw-r--r--zephyr/emul/emul_bmi.c6
-rw-r--r--zephyr/emul/emul_common_i2c.c4
-rw-r--r--zephyr/emul/emul_lis2dw12.c6
-rw-r--r--zephyr/emul/emul_ln9310.c6
-rw-r--r--zephyr/emul/emul_smart_battery.c6
-rw-r--r--zephyr/emul/emul_tcs3400.c6
-rw-r--r--zephyr/include/emul/emul_common_i2c.h3
9 files changed, 14 insertions, 35 deletions
diff --git a/zephyr/emul/emul_bb_retimer.c b/zephyr/emul/emul_bb_retimer.c
index b391070b1f..ac7271c357 100644
--- a/zephyr/emul/emul_bb_retimer.c
+++ b/zephyr/emul/emul_bb_retimer.c
@@ -287,10 +287,6 @@ static int bb_emul_access_reg(struct i2c_emul *emul, int reg, int bytes,
/* Device instantiation */
-static struct i2c_emul_api bb_emul_api = {
- .transfer = i2c_common_emul_transfer,
-};
-
/**
* @brief Set up a new BB retimer emulator
*
@@ -309,7 +305,7 @@ static int bb_emul_init(const struct emul *emul,
struct i2c_common_emul_data *data = cfg->data;
int ret;
- data->emul.api = &bb_emul_api;
+ data->emul.api = &i2c_common_emul_api;
data->emul.addr = cfg->addr;
data->i2c = parent;
data->cfg = cfg;
diff --git a/zephyr/emul/emul_bma255.c b/zephyr/emul/emul_bma255.c
index 77b1f5246c..bd41bcde3f 100644
--- a/zephyr/emul/emul_bma255.c
+++ b/zephyr/emul/emul_bma255.c
@@ -950,10 +950,6 @@ static int bma_emul_write_byte(struct i2c_emul *emul, int reg, uint8_t val,
/* Device instantiation */
-static struct i2c_emul_api bma_emul_api = {
- .transfer = i2c_common_emul_transfer,
-};
-
/**
* @brief Set up a new BMA255 emulator
*
@@ -972,7 +968,7 @@ static int bma_emul_init(const struct emul *emul,
struct i2c_common_emul_data *data = cfg->data;
int ret;
- data->emul.api = &bma_emul_api;
+ data->emul.api = &i2c_common_emul_api;
data->emul.addr = cfg->addr;
data->i2c = parent;
data->cfg = cfg;
diff --git a/zephyr/emul/emul_bmi.c b/zephyr/emul/emul_bmi.c
index 7923fe0eb5..fcfe3859bd 100644
--- a/zephyr/emul/emul_bmi.c
+++ b/zephyr/emul/emul_bmi.c
@@ -1020,10 +1020,6 @@ static int bmi_emul_handle_read(struct i2c_emul *emul, int reg, uint8_t *buf,
/* Device instantiation */
-static struct i2c_emul_api bmi_emul_api = {
- .transfer = i2c_common_emul_transfer,
-};
-
/**
* @brief Set up a new BMI emulator
*
@@ -1043,7 +1039,7 @@ static int bmi_emul_init(const struct emul *emul,
struct bmi_emul_data *bmi_data;
int ret;
- data->emul.api = &bmi_emul_api;
+ data->emul.api = &i2c_common_emul_api;
data->emul.addr = cfg->addr;
data->i2c = parent;
data->cfg = cfg;
diff --git a/zephyr/emul/emul_common_i2c.c b/zephyr/emul/emul_common_i2c.c
index bd811f1424..43e7101784 100644
--- a/zephyr/emul/emul_common_i2c.c
+++ b/zephyr/emul/emul_common_i2c.c
@@ -430,3 +430,7 @@ void i2c_common_emul_init(struct i2c_common_emul_data *data)
k_mutex_init(&data->data_mtx);
}
+
+struct i2c_emul_api i2c_common_emul_api = {
+ .transfer = i2c_common_emul_transfer,
+};
diff --git a/zephyr/emul/emul_lis2dw12.c b/zephyr/emul/emul_lis2dw12.c
index 6fa8b31cc9..07fba6091f 100644
--- a/zephyr/emul/emul_lis2dw12.c
+++ b/zephyr/emul/emul_lis2dw12.c
@@ -120,10 +120,6 @@ static int lis2dw12_emul_write_byte(struct i2c_emul *emul, int reg, uint8_t val,
return 0;
}
-static struct i2c_emul_api lis2dw12_emul_api_i2c = {
- .transfer = i2c_common_emul_transfer,
-};
-
static int emul_lis2dw12_init(const struct emul *emul,
const struct device *parent)
{
@@ -131,7 +127,7 @@ static int emul_lis2dw12_init(const struct emul *emul,
const struct i2c_common_emul_cfg *cfg = &(lis2dw12_cfg->common);
struct lis2dw12_emul_data *data = emul->data;
- data->common.emul.api = &lis2dw12_emul_api_i2c;
+ data->common.emul.api = &i2c_common_emul_api;
data->common.emul.addr = cfg->addr;
data->common.emul.parent = emul;
data->common.i2c = parent;
diff --git a/zephyr/emul/emul_ln9310.c b/zephyr/emul/emul_ln9310.c
index d4eaa8e38d..472c1c366e 100644
--- a/zephyr/emul/emul_ln9310.c
+++ b/zephyr/emul/emul_ln9310.c
@@ -138,10 +138,6 @@ enum battery_cell_type board_get_battery_cell_type(void)
return data->battery_cell_type;
}
-static struct i2c_emul_api ln9310_emul_api_i2c = {
- .transfer = i2c_common_emul_transfer,
-};
-
static int ln9310_emul_start_write(struct i2c_emul *emul, int reg)
{
return 0;
@@ -349,7 +345,7 @@ static int emul_ln9310_init(const struct emul *emul,
const struct i2c_common_emul_cfg *cfg = emul->cfg;
struct ln9310_emul_data *data = emul->data;
- data->common.emul.api = &ln9310_emul_api_i2c;
+ data->common.emul.api = &i2c_common_emul_api;
data->common.emul.addr = cfg->addr;
data->common.emul.parent = emul;
data->common.i2c = parent;
diff --git a/zephyr/emul/emul_smart_battery.c b/zephyr/emul/emul_smart_battery.c
index 4b1d87336e..279e08719d 100644
--- a/zephyr/emul/emul_smart_battery.c
+++ b/zephyr/emul/emul_smart_battery.c
@@ -766,10 +766,6 @@ static int sbat_emul_access_reg(struct i2c_emul *emul, int reg, int bytes,
/* Device instantiation */
-static struct i2c_emul_api sbat_emul_api = {
- .transfer = i2c_common_emul_transfer,
-};
-
/**
* @brief Set up a new Smart Battery emulator
*
@@ -788,7 +784,7 @@ static int sbat_emul_init(const struct emul *emul,
struct i2c_common_emul_data *data = cfg->data;
int ret;
- data->emul.api = &sbat_emul_api;
+ data->emul.api = &i2c_common_emul_api;
data->emul.addr = cfg->addr;
data->i2c = parent;
data->cfg = cfg;
diff --git a/zephyr/emul/emul_tcs3400.c b/zephyr/emul/emul_tcs3400.c
index 0fc432e9ff..ccc46bb382 100644
--- a/zephyr/emul/emul_tcs3400.c
+++ b/zephyr/emul/emul_tcs3400.c
@@ -565,10 +565,6 @@ static int tcs_emul_write_byte(struct i2c_emul *emul, int reg, uint8_t val,
/* Device instantiation */
-static struct i2c_emul_api tcs_emul_api = {
- .transfer = i2c_common_emul_transfer,
-};
-
/**
* @brief Set up a new TCS3400 emulator
*
@@ -587,7 +583,7 @@ static int tcs_emul_init(const struct emul *emul,
struct i2c_common_emul_data *data = cfg->data;
int ret;
- data->emul.api = &tcs_emul_api;
+ data->emul.api = &i2c_common_emul_api;
data->emul.addr = cfg->addr;
data->i2c = parent;
data->cfg = cfg;
diff --git a/zephyr/include/emul/emul_common_i2c.h b/zephyr/include/emul/emul_common_i2c.h
index 0457842a71..39711108f0 100644
--- a/zephyr/include/emul/emul_common_i2c.h
+++ b/zephyr/include/emul/emul_common_i2c.h
@@ -276,6 +276,9 @@ struct i2c_common_emul_data {
struct k_mutex data_mtx;
};
+/** A common API that simply links to the i2c_common_emul_transfer function */
+extern struct i2c_emul_api i2c_common_emul_api;
+
/**
* @brief Lock access to emulator properties. After acquiring lock, user
* may change emulator behaviour in multi-thread setup.