emul: Run clang-format
Run clang-format on all files touched by improved emulator API pull-request that allowed access to the target device emulator from its bus api without CONTAINER_OF usage. drivers/i2c/i2c_emul.c drivers/spi/spi_emul.c include/zephyr/drivers/emul.h include/zephyr/drivers/espi_emul.h include/zephyr/drivers/i2c_emul.h include/zephyr/drivers/spi_emul.h subsys/emul/emul.c subsys/emul/emul_bmi160.c subsys/emul/espi/emul_espi_host.c subsys/emul/i2c/emul_atmel_at24.c TEST=twister on accel,espi, and eeprom drivers tests Signed-off-by: Aaron Massey <aaronmassey@google.com>
This commit is contained in:
parent
9cb707b814
commit
1028459afd
|
@ -31,8 +31,7 @@ struct espi_emul_data {
|
|||
sys_slist_t callbacks;
|
||||
};
|
||||
|
||||
static struct espi_emul *espi_emul_find(const struct device *dev,
|
||||
unsigned int chipsel)
|
||||
static struct espi_emul *espi_emul_find(const struct device *dev, unsigned int chipsel)
|
||||
{
|
||||
struct espi_emul_data *data = dev->data;
|
||||
sys_snode_t *node;
|
||||
|
@ -60,9 +59,7 @@ static int espi_emul_config(const struct device *dev, struct espi_cfg *cfg)
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int emul_espi_trigger_event(const struct device *dev,
|
||||
struct espi_event *evt)
|
||||
static int emul_espi_trigger_event(const struct device *dev, struct espi_event *evt)
|
||||
{
|
||||
struct espi_emul_data *data = dev->data;
|
||||
|
||||
|
@ -70,8 +67,8 @@ static int emul_espi_trigger_event(const struct device *dev,
|
|||
!(data->cfg.channel_caps & ESPI_CHANNEL_VWIRE)) ||
|
||||
((evt->evt_type & ESPI_BUS_EVENT_OOB_RECEIVED) &&
|
||||
!(data->cfg.channel_caps & ESPI_CHANNEL_OOB)) ||
|
||||
((evt->evt_type & ESPI_BUS_PERIPHERAL_NOTIFICATION)
|
||||
&& !(data->cfg.channel_caps & ESPI_CHANNEL_PERIPHERAL))) {
|
||||
((evt->evt_type & ESPI_BUS_PERIPHERAL_NOTIFICATION) &&
|
||||
!(data->cfg.channel_caps & ESPI_CHANNEL_PERIPHERAL))) {
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
|
@ -87,8 +84,7 @@ static bool espi_emul_get_channel_status(const struct device *dev, enum espi_cha
|
|||
return (data->cfg.channel_caps & ch);
|
||||
}
|
||||
|
||||
static int espi_emul_read_lpc_request(const struct device *dev,
|
||||
enum lpc_peripheral_opcode op,
|
||||
static int espi_emul_read_lpc_request(const struct device *dev, enum lpc_peripheral_opcode op,
|
||||
uint32_t *data)
|
||||
{
|
||||
const struct emul_espi_device_api *api;
|
||||
|
@ -153,7 +149,8 @@ static int espi_emul_send_vwire(const struct device *dev, enum espi_vwire_signal
|
|||
return api->set_vw(emul, vw, level);
|
||||
}
|
||||
|
||||
static int espi_emul_receive_vwire(const struct device *dev, enum espi_vwire_signal vw, uint8_t *level)
|
||||
static int espi_emul_receive_vwire(const struct device *dev, enum espi_vwire_signal vw,
|
||||
uint8_t *level)
|
||||
{
|
||||
const struct emul_espi_device_api *api;
|
||||
struct espi_emul *emul;
|
||||
|
@ -176,7 +173,8 @@ static int espi_emul_receive_vwire(const struct device *dev, enum espi_vwire_sig
|
|||
return api->get_vw(emul, vw, level);
|
||||
}
|
||||
|
||||
static int espi_emul_manage_callback(const struct device *dev, struct espi_callback *callback, bool set)
|
||||
static int espi_emul_manage_callback(const struct device *dev, struct espi_callback *callback,
|
||||
bool set)
|
||||
{
|
||||
struct espi_emul_data *data = dev->data;
|
||||
|
||||
|
@ -198,8 +196,7 @@ static int espi_emul_init(const struct device *dev)
|
|||
return emul_init_for_bus_from_list(dev, list);
|
||||
}
|
||||
|
||||
int espi_emul_register(const struct device *dev, const char *name,
|
||||
struct espi_emul *emul)
|
||||
int espi_emul_register(const struct device *dev, const char *name, struct espi_emul *emul)
|
||||
{
|
||||
struct espi_emul_data *data = dev->data;
|
||||
|
||||
|
@ -212,41 +209,31 @@ int espi_emul_register(const struct device *dev, const char *name,
|
|||
|
||||
/* Device instantiation */
|
||||
static struct emul_espi_driver_api emul_espi_driver_api = {
|
||||
.espi_api = {
|
||||
.config = espi_emul_config,
|
||||
.get_channel_status = espi_emul_get_channel_status,
|
||||
.read_lpc_request = espi_emul_read_lpc_request,
|
||||
.write_lpc_request = espi_emul_write_lpc_request,
|
||||
.send_vwire = espi_emul_send_vwire,
|
||||
.receive_vwire = espi_emul_receive_vwire,
|
||||
.manage_callback = espi_emul_manage_callback
|
||||
},
|
||||
.espi_api = { .config = espi_emul_config,
|
||||
.get_channel_status = espi_emul_get_channel_status,
|
||||
.read_lpc_request = espi_emul_read_lpc_request,
|
||||
.write_lpc_request = espi_emul_write_lpc_request,
|
||||
.send_vwire = espi_emul_send_vwire,
|
||||
.receive_vwire = espi_emul_receive_vwire,
|
||||
.manage_callback = espi_emul_manage_callback },
|
||||
.trigger_event = emul_espi_trigger_event,
|
||||
.find_emul = espi_emul_find,
|
||||
};
|
||||
|
||||
#define EMUL_LINK_AND_COMMA(node_id) \
|
||||
{ \
|
||||
.label = DT_LABEL(node_id), \
|
||||
},
|
||||
|
||||
#define EMUL_LINK_AND_COMMA(node_id) { \
|
||||
.label = DT_LABEL(node_id), \
|
||||
},
|
||||
|
||||
#define ESPI_EMUL_INIT(n) \
|
||||
static const struct emul_link_for_bus emuls_##n[] = { \
|
||||
DT_FOREACH_CHILD(DT_DRV_INST(n), EMUL_LINK_AND_COMMA) \
|
||||
}; \
|
||||
static struct emul_list_for_bus espi_emul_cfg_##n = { \
|
||||
.children = emuls_##n, \
|
||||
.num_children = ARRAY_SIZE(emuls_##n), \
|
||||
}; \
|
||||
static struct espi_emul_data espi_emul_data_##n; \
|
||||
DEVICE_DT_INST_DEFINE(n, \
|
||||
&espi_emul_init, \
|
||||
NULL, \
|
||||
&espi_emul_data_##n, \
|
||||
&espi_emul_cfg_##n, \
|
||||
POST_KERNEL, \
|
||||
CONFIG_ESPI_INIT_PRIORITY, \
|
||||
&emul_espi_driver_api);
|
||||
|
||||
#define ESPI_EMUL_INIT(n) \
|
||||
static const struct emul_link_for_bus emuls_##n[] = { DT_FOREACH_CHILD( \
|
||||
DT_DRV_INST(n), EMUL_LINK_AND_COMMA) }; \
|
||||
static struct emul_list_for_bus espi_emul_cfg_##n = { \
|
||||
.children = emuls_##n, \
|
||||
.num_children = ARRAY_SIZE(emuls_##n), \
|
||||
}; \
|
||||
static struct espi_emul_data espi_emul_data_##n; \
|
||||
DEVICE_DT_INST_DEFINE(n, &espi_emul_init, NULL, &espi_emul_data_##n, &espi_emul_cfg_##n, \
|
||||
POST_KERNEL, CONFIG_ESPI_INIT_PRIORITY, &emul_espi_driver_api);
|
||||
|
||||
DT_INST_FOREACH_STATUS_OKAY(ESPI_EMUL_INIT)
|
||||
|
|
|
@ -74,8 +74,8 @@ static int i2c_emul_get_config(const struct device *dev, uint32_t *dev_config)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int i2c_emul_transfer(const struct device *dev, struct i2c_msg *msgs,
|
||||
uint8_t num_msgs, uint16_t addr)
|
||||
static int i2c_emul_transfer(const struct device *dev, struct i2c_msg *msgs, uint8_t num_msgs,
|
||||
uint16_t addr)
|
||||
{
|
||||
struct i2c_emul *emul;
|
||||
const struct i2c_emul_api *api;
|
||||
|
@ -119,8 +119,7 @@ static int i2c_emul_init(const struct device *dev)
|
|||
return rc;
|
||||
}
|
||||
|
||||
int i2c_emul_register(const struct device *dev, const char *name,
|
||||
struct i2c_emul *emul)
|
||||
int i2c_emul_register(const struct device *dev, const char *name, struct i2c_emul *emul)
|
||||
{
|
||||
struct i2c_emul_data *data = dev->data;
|
||||
|
||||
|
@ -139,28 +138,22 @@ static struct i2c_driver_api i2c_emul_api = {
|
|||
.transfer = i2c_emul_transfer,
|
||||
};
|
||||
|
||||
#define EMUL_LINK_AND_COMMA(node_id) { \
|
||||
.label = DT_LABEL(node_id), \
|
||||
},
|
||||
#define EMUL_LINK_AND_COMMA(node_id) \
|
||||
{ \
|
||||
.label = DT_LABEL(node_id), \
|
||||
},
|
||||
|
||||
#define I2C_EMUL_INIT(n) \
|
||||
static const struct emul_link_for_bus emuls_##n[] = { \
|
||||
DT_FOREACH_CHILD(DT_DRV_INST(n), EMUL_LINK_AND_COMMA) \
|
||||
}; \
|
||||
static struct emul_list_for_bus i2c_emul_cfg_##n = { \
|
||||
.children = emuls_##n, \
|
||||
.num_children = ARRAY_SIZE(emuls_##n), \
|
||||
}; \
|
||||
static struct i2c_emul_data i2c_emul_data_##n = { \
|
||||
.bitrate = DT_INST_PROP(n, clock_frequency), \
|
||||
}; \
|
||||
I2C_DEVICE_DT_INST_DEFINE(n, \
|
||||
i2c_emul_init, \
|
||||
NULL, \
|
||||
&i2c_emul_data_##n, \
|
||||
&i2c_emul_cfg_##n, \
|
||||
POST_KERNEL, \
|
||||
CONFIG_I2C_INIT_PRIORITY, \
|
||||
&i2c_emul_api);
|
||||
#define I2C_EMUL_INIT(n) \
|
||||
static const struct emul_link_for_bus emuls_##n[] = { DT_FOREACH_CHILD( \
|
||||
DT_DRV_INST(n), EMUL_LINK_AND_COMMA) }; \
|
||||
static struct emul_list_for_bus i2c_emul_cfg_##n = { \
|
||||
.children = emuls_##n, \
|
||||
.num_children = ARRAY_SIZE(emuls_##n), \
|
||||
}; \
|
||||
static struct i2c_emul_data i2c_emul_data_##n = { \
|
||||
.bitrate = DT_INST_PROP(n, clock_frequency), \
|
||||
}; \
|
||||
I2C_DEVICE_DT_INST_DEFINE(n, i2c_emul_init, NULL, &i2c_emul_data_##n, &i2c_emul_cfg_##n, \
|
||||
POST_KERNEL, CONFIG_I2C_INIT_PRIORITY, &i2c_emul_api);
|
||||
|
||||
DT_INST_FOREACH_STATUS_OKAY(I2C_EMUL_INIT)
|
||||
|
|
|
@ -46,8 +46,7 @@ uint32_t spi_emul_get_config(const struct device *dev)
|
|||
* @return emulator to use
|
||||
* @return NULL if not found
|
||||
*/
|
||||
static struct spi_emul *spi_emul_find(const struct device *dev,
|
||||
unsigned int chipsel)
|
||||
static struct spi_emul *spi_emul_find(const struct device *dev, unsigned int chipsel)
|
||||
{
|
||||
struct spi_emul_data *data = dev->data;
|
||||
sys_snode_t *node;
|
||||
|
@ -64,10 +63,8 @@ static struct spi_emul *spi_emul_find(const struct device *dev,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static int spi_emul_io(const struct device *dev,
|
||||
const struct spi_config *config,
|
||||
const struct spi_buf_set *tx_bufs,
|
||||
const struct spi_buf_set *rx_bufs)
|
||||
static int spi_emul_io(const struct device *dev, const struct spi_config *config,
|
||||
const struct spi_buf_set *tx_bufs, const struct spi_buf_set *rx_bufs)
|
||||
{
|
||||
struct spi_emul *emul;
|
||||
const struct spi_emul_api *api;
|
||||
|
@ -99,8 +96,7 @@ static int spi_emul_init(const struct device *dev)
|
|||
return emul_init_for_bus_from_list(dev, list);
|
||||
}
|
||||
|
||||
int spi_emul_register(const struct device *dev, const char *name,
|
||||
struct spi_emul *emul)
|
||||
int spi_emul_register(const struct device *dev, const char *name, struct spi_emul *emul)
|
||||
{
|
||||
struct spi_emul_data *data = dev->data;
|
||||
|
||||
|
@ -117,26 +113,20 @@ static struct spi_driver_api spi_emul_api = {
|
|||
.transceive = spi_emul_io,
|
||||
};
|
||||
|
||||
#define EMUL_LINK_AND_COMMA(node_id) { \
|
||||
.label = DT_LABEL(node_id), \
|
||||
},
|
||||
#define EMUL_LINK_AND_COMMA(node_id) \
|
||||
{ \
|
||||
.label = DT_LABEL(node_id), \
|
||||
},
|
||||
|
||||
#define SPI_EMUL_INIT(n) \
|
||||
static const struct emul_link_for_bus emuls_##n[] = { \
|
||||
DT_FOREACH_CHILD(DT_DRV_INST(0), EMUL_LINK_AND_COMMA) \
|
||||
}; \
|
||||
static struct emul_list_for_bus spi_emul_cfg_##n = { \
|
||||
.children = emuls_##n, \
|
||||
.num_children = ARRAY_SIZE(emuls_##n), \
|
||||
}; \
|
||||
static struct spi_emul_data spi_emul_data_##n; \
|
||||
DEVICE_DT_INST_DEFINE(n, \
|
||||
spi_emul_init, \
|
||||
NULL, \
|
||||
&spi_emul_data_##n, \
|
||||
&spi_emul_cfg_##n, \
|
||||
POST_KERNEL, \
|
||||
CONFIG_SPI_INIT_PRIORITY, \
|
||||
&spi_emul_api);
|
||||
#define SPI_EMUL_INIT(n) \
|
||||
static const struct emul_link_for_bus emuls_##n[] = { DT_FOREACH_CHILD( \
|
||||
DT_DRV_INST(0), EMUL_LINK_AND_COMMA) }; \
|
||||
static struct emul_list_for_bus spi_emul_cfg_##n = { \
|
||||
.children = emuls_##n, \
|
||||
.num_children = ARRAY_SIZE(emuls_##n), \
|
||||
}; \
|
||||
static struct spi_emul_data spi_emul_data_##n; \
|
||||
DEVICE_DT_INST_DEFINE(n, spi_emul_init, NULL, &spi_emul_data_##n, &spi_emul_cfg_##n, \
|
||||
POST_KERNEL, CONFIG_SPI_INIT_PRIORITY, &spi_emul_api);
|
||||
|
||||
DT_INST_FOREACH_STATUS_OKAY(SPI_EMUL_INIT)
|
||||
|
|
|
@ -45,8 +45,7 @@ struct emul_list_for_bus {
|
|||
* @param emul Emulator to init
|
||||
* @param parent Parent device that is using the emulator
|
||||
*/
|
||||
typedef int (*emul_init_t)(const struct emul *emul,
|
||||
const struct device *parent);
|
||||
typedef int (*emul_init_t)(const struct emul *emul, const struct device *parent);
|
||||
|
||||
/** An emulator instance */
|
||||
struct emul {
|
||||
|
@ -99,8 +98,7 @@ extern const struct emul __emul_list_end[];
|
|||
* @return 0 if OK
|
||||
* @return negative value on error
|
||||
*/
|
||||
int emul_init_for_bus_from_list(const struct device *dev,
|
||||
const struct emul_list_for_bus *list);
|
||||
int emul_init_for_bus_from_list(const struct device *dev, const struct emul_list_for_bus *list);
|
||||
|
||||
/**
|
||||
* @brief Retrieve the emul structure for an emulator by name
|
||||
|
|
|
@ -44,8 +44,7 @@ struct espi_emul;
|
|||
* @retval 0 If successful.
|
||||
* @retval -EIO General input / output error.
|
||||
*/
|
||||
typedef int (*emul_espi_api_set_vw)(struct espi_emul *emul,
|
||||
enum espi_vwire_signal vw,
|
||||
typedef int (*emul_espi_api_set_vw)(struct espi_emul *emul, enum espi_vwire_signal vw,
|
||||
uint8_t level);
|
||||
|
||||
/**
|
||||
|
@ -59,8 +58,7 @@ typedef int (*emul_espi_api_set_vw)(struct espi_emul *emul,
|
|||
* @retval 0 If successful.
|
||||
* @retval -EIO General input / output error.
|
||||
*/
|
||||
typedef int (*emul_espi_api_get_vw)(struct espi_emul *emul,
|
||||
enum espi_vwire_signal vw,
|
||||
typedef int (*emul_espi_api_get_vw)(struct espi_emul *emul, enum espi_vwire_signal vw,
|
||||
uint8_t *level);
|
||||
|
||||
#ifdef CONFIG_ESPI_PERIPHERAL_ACPI_SHM_REGION
|
||||
|
@ -85,8 +83,7 @@ typedef uintptr_t (*emul_espi_api_get_acpi_shm)(struct espi_emul *emul);
|
|||
* @return emulator to use
|
||||
* @return NULL if not found
|
||||
*/
|
||||
typedef struct espi_emul *(*emul_find_emul)(const struct device *dev,
|
||||
unsigned int chipsel);
|
||||
typedef struct espi_emul *(*emul_find_emul)(const struct device *dev, unsigned int chipsel);
|
||||
|
||||
/**
|
||||
* Triggers an event on the emulator of eSPI controller side which causes
|
||||
|
@ -98,8 +95,7 @@ typedef struct espi_emul *(*emul_find_emul)(const struct device *dev,
|
|||
* @retval 0 If successful.
|
||||
* @retval -EIO General input / output error.
|
||||
*/
|
||||
typedef int (*emul_trigger_event)(const struct device *dev,
|
||||
struct espi_event *evt);
|
||||
typedef int (*emul_trigger_event)(const struct device *dev, struct espi_event *evt);
|
||||
|
||||
/** Definition of the eSPI device emulator API */
|
||||
struct emul_espi_device_api {
|
||||
|
@ -140,8 +136,7 @@ struct emul_espi_driver_api {
|
|||
* @param emul eSPI emulator to use
|
||||
* @return 0 indicating success (always)
|
||||
*/
|
||||
int espi_emul_register(const struct device *dev, const char *name,
|
||||
struct espi_emul *emul);
|
||||
int espi_emul_register(const struct device *dev, const char *name, struct espi_emul *emul);
|
||||
|
||||
/**
|
||||
* Sets the eSPI virtual wire on the host side, which will
|
||||
|
@ -154,8 +149,7 @@ int espi_emul_register(const struct device *dev, const char *name,
|
|||
* @retval 0 If successful.
|
||||
* @retval -EIO General input / output error.
|
||||
*/
|
||||
int emul_espi_host_send_vw(const struct device *espi_dev,
|
||||
enum espi_vwire_signal vw, uint8_t level);
|
||||
int emul_espi_host_send_vw(const struct device *espi_dev, enum espi_vwire_signal vw, uint8_t level);
|
||||
|
||||
/**
|
||||
* Perform port80 write on the emulated host side, which will
|
||||
|
@ -180,7 +174,6 @@ int emul_espi_host_port80_write(const struct device *espi_dev, uint32_t data);
|
|||
uintptr_t emul_espi_host_get_acpi_shm(const struct device *espi_dev);
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -58,8 +58,8 @@ struct i2c_emul {
|
|||
* @retval 0 If successful.
|
||||
* @retval -EIO General input / output error.
|
||||
*/
|
||||
typedef int (*i2c_emul_transfer_t)(struct i2c_emul *emul, struct i2c_msg *msgs,
|
||||
int num_msgs, int addr);
|
||||
typedef int (*i2c_emul_transfer_t)(struct i2c_emul *emul, struct i2c_msg *msgs, int num_msgs,
|
||||
int addr);
|
||||
|
||||
/**
|
||||
* Register an emulated device on the controller
|
||||
|
@ -69,8 +69,7 @@ typedef int (*i2c_emul_transfer_t)(struct i2c_emul *emul, struct i2c_msg *msgs,
|
|||
* @param emul I2C emulator to use
|
||||
* @return 0 indicating success (always)
|
||||
*/
|
||||
int i2c_emul_register(const struct device *dev, const char *name,
|
||||
struct i2c_emul *emul);
|
||||
int i2c_emul_register(const struct device *dev, const char *name, struct i2c_emul *emul);
|
||||
|
||||
/** Definition of the emulator API */
|
||||
struct i2c_emul_api {
|
||||
|
|
|
@ -61,10 +61,8 @@ struct spi_emul {
|
|||
* @retval 0 If successful.
|
||||
* @retval -EIO General input / output error.
|
||||
*/
|
||||
typedef int (*spi_emul_io_t)(struct spi_emul *emul,
|
||||
const struct spi_config *config,
|
||||
const struct spi_buf_set *tx_bufs,
|
||||
const struct spi_buf_set *rx_bufs);
|
||||
typedef int (*spi_emul_io_t)(struct spi_emul *emul, const struct spi_config *config,
|
||||
const struct spi_buf_set *tx_bufs, const struct spi_buf_set *rx_bufs);
|
||||
|
||||
/**
|
||||
* Register an emulated device on the controller
|
||||
|
@ -74,8 +72,7 @@ typedef int (*spi_emul_io_t)(struct spi_emul *emul,
|
|||
* @param emul SPI emulator to use
|
||||
* @return 0 indicating success (always)
|
||||
*/
|
||||
int spi_emul_register(const struct device *dev, const char *name,
|
||||
struct spi_emul *emul);
|
||||
int spi_emul_register(const struct device *dev, const char *name, struct spi_emul *emul);
|
||||
|
||||
/** Definition of the emulator API */
|
||||
struct spi_emul_api {
|
||||
|
|
|
@ -26,8 +26,7 @@ const struct emul *emul_get_binding(const char *name)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
int emul_init_for_bus_from_list(const struct device *dev,
|
||||
const struct emul_list_for_bus *list)
|
||||
int emul_init_for_bus_from_list(const struct device *dev, const struct emul_list_for_bus *list)
|
||||
{
|
||||
const struct emul_list_for_bus *cfg = dev->config;
|
||||
|
||||
|
@ -36,11 +35,9 @@ int emul_init_for_bus_from_list(const struct device *dev,
|
|||
* initialise it.
|
||||
*/
|
||||
const struct emul_link_for_bus *elp;
|
||||
const struct emul_link_for_bus *const end =
|
||||
cfg->children + cfg->num_children;
|
||||
const struct emul_link_for_bus *const end = cfg->children + cfg->num_children;
|
||||
|
||||
LOG_INF("Registering %d emulator(s) for %s", cfg->num_children,
|
||||
dev->name);
|
||||
LOG_INF("Registering %d emulator(s) for %s", cfg->num_children, dev->name);
|
||||
for (elp = cfg->children; elp < end; elp++) {
|
||||
const struct emul *emul = emul_get_binding(elp->label);
|
||||
|
||||
|
@ -49,8 +46,7 @@ int emul_init_for_bus_from_list(const struct device *dev,
|
|||
int rc = emul->init(emul, dev);
|
||||
|
||||
if (rc != 0) {
|
||||
LOG_WRN("Init %s emulator failed: %d\n",
|
||||
elp->label, rc);
|
||||
LOG_WRN("Init %s emulator failed: %d\n", elp->label, rc);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -39,6 +39,8 @@ struct bmi160_emul_data {
|
|||
|
||||
/** Static configuration for the emulator */
|
||||
struct bmi160_emul_cfg {
|
||||
/** Label of the SPI bus this emulator connects to */
|
||||
const char *bus_label;
|
||||
/** Chip registers */
|
||||
uint8_t *reg;
|
||||
union {
|
||||
|
@ -50,7 +52,7 @@ struct bmi160_emul_cfg {
|
|||
};
|
||||
|
||||
/* Names for the PMU components */
|
||||
static const char *const pmu_name[] = {"acc", "gyr", "mag", "INV"};
|
||||
static const char *const pmu_name[] = { "acc", "gyr", "mag", "INV" };
|
||||
|
||||
static void sample_read(struct bmi160_emul_data *data, union bmi160_sample *buf)
|
||||
{
|
||||
|
@ -64,8 +66,8 @@ static void sample_read(struct bmi160_emul_data *data, union bmi160_sample *buf)
|
|||
* acc[y] = 0x0689 // 1 * 1000000 / BMI160_ACC_SCALE(2) + 1
|
||||
* acc[z] = 0x0d11 // 2 * 1000000 / BMI160_ACC_SCALE(2) + 1
|
||||
*/
|
||||
static uint8_t raw_data[] = { 0x01, 0x0b, 0xac, 0x0e, 0x57, 0x12, 0x01, 0x00,
|
||||
0x89, 0x06, 0x11, 0x0d };
|
||||
static uint8_t raw_data[] = { 0x01, 0x0b, 0xac, 0x0e, 0x57, 0x12,
|
||||
0x01, 0x00, 0x89, 0x06, 0x11, 0x0d };
|
||||
|
||||
LOG_INF("Sample read");
|
||||
memcpy(buf->raw, raw_data, ARRAY_SIZE(raw_data));
|
||||
|
@ -98,8 +100,7 @@ static void reg_write(const struct emul *emulator, int regn, int val)
|
|||
break;
|
||||
default:
|
||||
if ((val & BMI160_CMD_PMU_BIT) == BMI160_CMD_PMU_BIT) {
|
||||
int which = (val & BMI160_CMD_PMU_MASK) >>
|
||||
BMI160_CMD_PMU_SHIFT;
|
||||
int which = (val & BMI160_CMD_PMU_MASK) >> BMI160_CMD_PMU_SHIFT;
|
||||
int shift;
|
||||
int pmu_val = val & BMI160_CMD_PMU_VAL_MASK;
|
||||
|
||||
|
@ -117,8 +118,7 @@ static void reg_write(const struct emul *emulator, int regn, int val)
|
|||
}
|
||||
data->pmu_status &= 3 << shift;
|
||||
data->pmu_status |= pmu_val << shift;
|
||||
LOG_INF(" * pmu %s = %x, new status %x",
|
||||
pmu_name[which], pmu_val,
|
||||
LOG_INF(" * pmu %s = %x, new status %x", pmu_name[which], pmu_val,
|
||||
data->pmu_status);
|
||||
} else {
|
||||
LOG_INF("Unknown command %x", val);
|
||||
|
@ -175,10 +175,8 @@ static int reg_read(const struct emul *emulator, int regn)
|
|||
}
|
||||
|
||||
#if BMI160_BUS_SPI
|
||||
static int bmi160_emul_io_spi(struct spi_emul *emul,
|
||||
const struct spi_config *config,
|
||||
const struct spi_buf_set *tx_bufs,
|
||||
const struct spi_buf_set *rx_bufs)
|
||||
static int bmi160_emul_io_spi(struct spi_emul *emul, const struct spi_config *config,
|
||||
const struct spi_buf_set *tx_bufs, const struct spi_buf_set *rx_bufs)
|
||||
{
|
||||
struct bmi160_emul_data *data;
|
||||
const struct spi_buf *tx, *txd, *rxd;
|
||||
|
@ -188,8 +186,7 @@ static int bmi160_emul_io_spi(struct spi_emul *emul,
|
|||
data = CONTAINER_OF(emul, struct bmi160_emul_data, emul_spi);
|
||||
|
||||
__ASSERT_NO_MSG(tx_bufs || rx_bufs);
|
||||
__ASSERT_NO_MSG(!tx_bufs || !rx_bufs ||
|
||||
tx_bufs->count == rx_bufs->count);
|
||||
__ASSERT_NO_MSG(!tx_bufs || !rx_bufs || tx_bufs->count == rx_bufs->count);
|
||||
count = tx_bufs ? tx_bufs->count : rx_bufs->count;
|
||||
|
||||
switch (count) {
|
||||
|
@ -242,8 +239,8 @@ static int bmi160_emul_io_spi(struct spi_emul *emul,
|
|||
#endif
|
||||
|
||||
#if BMI160_BUS_I2C
|
||||
static int bmi160_emul_transfer_i2c(struct i2c_emul *emul, struct i2c_msg *msgs,
|
||||
int num_msgs, int addr)
|
||||
static int bmi160_emul_transfer_i2c(struct i2c_emul *emul, struct i2c_msg *msgs, int num_msgs,
|
||||
int addr)
|
||||
{
|
||||
struct bmi160_emul_data *data;
|
||||
unsigned int val;
|
||||
|
@ -310,8 +307,7 @@ static struct i2c_emul_api bmi160_emul_api_i2c = {
|
|||
};
|
||||
#endif
|
||||
|
||||
static void emul_bosch_bmi160_init(const struct emul *emul,
|
||||
const struct device *parent)
|
||||
static void emul_bosch_bmi160_init(const struct emul *emul, const struct device *parent)
|
||||
{
|
||||
const struct bmi160_emul_cfg *cfg = emul->cfg;
|
||||
struct bmi160_emul_data *data = emul->data;
|
||||
|
@ -334,8 +330,7 @@ static void emul_bosch_bmi160_init(const struct emul *emul,
|
|||
* @param parent Device to emulate (must use BMI160 driver)
|
||||
* @return 0 indicating success (always)
|
||||
*/
|
||||
static int emul_bosch_bmi160_init_spi(const struct emul *emul,
|
||||
const struct device *parent)
|
||||
static int emul_bosch_bmi160_init_spi(const struct emul *emul, const struct device *parent)
|
||||
{
|
||||
const struct bmi160_emul_cfg *cfg = emul->cfg;
|
||||
struct bmi160_emul_data *data = emul->data;
|
||||
|
@ -362,8 +357,7 @@ static int emul_bosch_bmi160_init_spi(const struct emul *emul,
|
|||
* @param parent Device to emulate (must use BMI160 driver)
|
||||
* @return 0 indicating success (always)
|
||||
*/
|
||||
static int emul_bosch_bmi160_init_i2c(const struct emul *emul,
|
||||
const struct device *parent)
|
||||
static int emul_bosch_bmi160_init_i2c(const struct emul *emul, const struct device *parent)
|
||||
{
|
||||
const struct bmi160_emul_cfg *cfg = emul->cfg;
|
||||
struct bmi160_emul_data *data = emul->data;
|
||||
|
@ -379,38 +373,37 @@ static int emul_bosch_bmi160_init_i2c(const struct emul *emul,
|
|||
}
|
||||
#endif
|
||||
|
||||
#define BMI160_EMUL_DATA(n) \
|
||||
static uint8_t bmi160_emul_reg_##n[BMI160_REG_COUNT]; \
|
||||
#define BMI160_EMUL_DATA(n) \
|
||||
static uint8_t bmi160_emul_reg_##n[BMI160_REG_COUNT]; \
|
||||
static struct bmi160_emul_data bmi160_emul_data_##n;
|
||||
|
||||
#define BMI160_EMUL_DEFINE(n, type) \
|
||||
EMUL_DEFINE(emul_bosch_bmi160_init_##type, DT_DRV_INST(n), \
|
||||
&bmi160_emul_cfg_##n, &bmi160_emul_data_##n)
|
||||
#define BMI160_EMUL_DEFINE(n, type) \
|
||||
EMUL_DEFINE(emul_bosch_bmi160_init_##type, DT_DRV_INST(n), &bmi160_emul_cfg_##n, \
|
||||
&bmi160_emul_data_##n)
|
||||
|
||||
/* Instantiation macros used when a device is on a SPI bus */
|
||||
#define BMI160_EMUL_SPI(n) \
|
||||
BMI160_EMUL_DATA(n) \
|
||||
static const struct bmi160_emul_cfg bmi160_emul_cfg_##n = { \
|
||||
.reg = bmi160_emul_reg_##n, \
|
||||
.chipsel = DT_INST_REG_ADDR(n) \
|
||||
}; \
|
||||
#define BMI160_EMUL_SPI(n) \
|
||||
BMI160_EMUL_DATA(n) \
|
||||
static const struct bmi160_emul_cfg bmi160_emul_cfg_##n = { .bus_label = \
|
||||
DT_INST_BUS_LABEL(n), \
|
||||
.reg = bmi160_emul_reg_##n, \
|
||||
.chipsel = \
|
||||
DT_INST_REG_ADDR(n) }; \
|
||||
BMI160_EMUL_DEFINE(n, spi)
|
||||
|
||||
#define BMI160_EMUL_I2C(n) \
|
||||
BMI160_EMUL_DATA(n) \
|
||||
static const struct bmi160_emul_cfg bmi160_emul_cfg_##n = { \
|
||||
.reg = bmi160_emul_reg_##n, \
|
||||
.addr = DT_INST_REG_ADDR(n) \
|
||||
}; \
|
||||
#define BMI160_EMUL_I2C(n) \
|
||||
BMI160_EMUL_DATA(n) \
|
||||
static const struct bmi160_emul_cfg bmi160_emul_cfg_##n = { .bus_label = \
|
||||
DT_INST_BUS_LABEL(n), \
|
||||
.reg = bmi160_emul_reg_##n, \
|
||||
.addr = DT_INST_REG_ADDR(n) }; \
|
||||
BMI160_EMUL_DEFINE(n, i2c)
|
||||
|
||||
/*
|
||||
* Main instantiation macro. Use of COND_CODE_1() selects the right
|
||||
* bus-specific macro at preprocessor time.
|
||||
*/
|
||||
#define BMI160_EMUL(n) \
|
||||
COND_CODE_1(DT_INST_ON_BUS(n, spi), \
|
||||
(BMI160_EMUL_SPI(n)), \
|
||||
(BMI160_EMUL_I2C(n)))
|
||||
#define BMI160_EMUL(n) \
|
||||
COND_CODE_1(DT_INST_ON_BUS(n, spi), (BMI160_EMUL_SPI(n)), (BMI160_EMUL_I2C(n)))
|
||||
|
||||
DT_INST_FOREACH_STATUS_OKAY(BMI160_EMUL)
|
||||
|
|
|
@ -31,33 +31,33 @@ struct vw_data {
|
|||
|
||||
/** Declare the default state of virtual wires */
|
||||
const static struct vw_data vw_state_default[] = {
|
||||
{ ESPI_VWIRE_SIGNAL_SLP_S3, 0, ESPI_MASTER_TO_SLAVE },
|
||||
{ ESPI_VWIRE_SIGNAL_SLP_S4, 0, ESPI_MASTER_TO_SLAVE },
|
||||
{ ESPI_VWIRE_SIGNAL_SLP_S5, 0, ESPI_MASTER_TO_SLAVE },
|
||||
{ ESPI_VWIRE_SIGNAL_SUS_STAT, 0, ESPI_MASTER_TO_SLAVE },
|
||||
{ ESPI_VWIRE_SIGNAL_PLTRST, 0, ESPI_MASTER_TO_SLAVE },
|
||||
{ ESPI_VWIRE_SIGNAL_OOB_RST_WARN, 0, ESPI_MASTER_TO_SLAVE },
|
||||
{ ESPI_VWIRE_SIGNAL_OOB_RST_ACK, 0, ESPI_SLAVE_TO_MASTER },
|
||||
{ ESPI_VWIRE_SIGNAL_WAKE, 0, ESPI_SLAVE_TO_MASTER },
|
||||
{ ESPI_VWIRE_SIGNAL_PME, 0, ESPI_SLAVE_TO_MASTER },
|
||||
{ ESPI_VWIRE_SIGNAL_SLP_S3, 0, ESPI_MASTER_TO_SLAVE },
|
||||
{ ESPI_VWIRE_SIGNAL_SLP_S4, 0, ESPI_MASTER_TO_SLAVE },
|
||||
{ ESPI_VWIRE_SIGNAL_SLP_S5, 0, ESPI_MASTER_TO_SLAVE },
|
||||
{ ESPI_VWIRE_SIGNAL_SUS_STAT, 0, ESPI_MASTER_TO_SLAVE },
|
||||
{ ESPI_VWIRE_SIGNAL_PLTRST, 0, ESPI_MASTER_TO_SLAVE },
|
||||
{ ESPI_VWIRE_SIGNAL_OOB_RST_WARN, 0, ESPI_MASTER_TO_SLAVE },
|
||||
{ ESPI_VWIRE_SIGNAL_OOB_RST_ACK, 0, ESPI_SLAVE_TO_MASTER },
|
||||
{ ESPI_VWIRE_SIGNAL_WAKE, 0, ESPI_SLAVE_TO_MASTER },
|
||||
{ ESPI_VWIRE_SIGNAL_PME, 0, ESPI_SLAVE_TO_MASTER },
|
||||
{ ESPI_VWIRE_SIGNAL_SLV_BOOT_DONE, 0, ESPI_SLAVE_TO_MASTER },
|
||||
{ ESPI_VWIRE_SIGNAL_ERR_FATAL, 0, ESPI_SLAVE_TO_MASTER },
|
||||
{ ESPI_VWIRE_SIGNAL_ERR_FATAL, 0, ESPI_SLAVE_TO_MASTER },
|
||||
{ ESPI_VWIRE_SIGNAL_ERR_NON_FATAL, 0, ESPI_SLAVE_TO_MASTER },
|
||||
{ ESPI_VWIRE_SIGNAL_SLV_BOOT_STS, 0, ESPI_SLAVE_TO_MASTER },
|
||||
{ ESPI_VWIRE_SIGNAL_SCI, 0, ESPI_SLAVE_TO_MASTER },
|
||||
{ ESPI_VWIRE_SIGNAL_SMI, 0, ESPI_SLAVE_TO_MASTER },
|
||||
{ ESPI_VWIRE_SIGNAL_RST_CPU_INIT, 0, ESPI_SLAVE_TO_MASTER },
|
||||
{ ESPI_VWIRE_SIGNAL_HOST_RST_ACK, 0, ESPI_SLAVE_TO_MASTER },
|
||||
{ ESPI_VWIRE_SIGNAL_SLV_BOOT_STS, 0, ESPI_SLAVE_TO_MASTER },
|
||||
{ ESPI_VWIRE_SIGNAL_SCI, 0, ESPI_SLAVE_TO_MASTER },
|
||||
{ ESPI_VWIRE_SIGNAL_SMI, 0, ESPI_SLAVE_TO_MASTER },
|
||||
{ ESPI_VWIRE_SIGNAL_RST_CPU_INIT, 0, ESPI_SLAVE_TO_MASTER },
|
||||
{ ESPI_VWIRE_SIGNAL_HOST_RST_ACK, 0, ESPI_SLAVE_TO_MASTER },
|
||||
{ ESPI_VWIRE_SIGNAL_HOST_RST_WARN, 0, ESPI_MASTER_TO_SLAVE },
|
||||
{ ESPI_VWIRE_SIGNAL_SUS_ACK, 0, ESPI_SLAVE_TO_MASTER },
|
||||
{ ESPI_VWIRE_SIGNAL_DNX_ACK, 0, ESPI_SLAVE_TO_MASTER },
|
||||
{ ESPI_VWIRE_SIGNAL_SUS_WARN, 0, ESPI_MASTER_TO_SLAVE },
|
||||
{ ESPI_VWIRE_SIGNAL_SUS_ACK, 0, ESPI_SLAVE_TO_MASTER },
|
||||
{ ESPI_VWIRE_SIGNAL_DNX_ACK, 0, ESPI_SLAVE_TO_MASTER },
|
||||
{ ESPI_VWIRE_SIGNAL_SUS_WARN, 0, ESPI_MASTER_TO_SLAVE },
|
||||
{ ESPI_VWIRE_SIGNAL_SUS_PWRDN_ACK, 0, ESPI_MASTER_TO_SLAVE },
|
||||
{ ESPI_VWIRE_SIGNAL_SLP_A, 0, ESPI_MASTER_TO_SLAVE },
|
||||
{ ESPI_VWIRE_SIGNAL_SLP_LAN, 0, ESPI_MASTER_TO_SLAVE },
|
||||
{ ESPI_VWIRE_SIGNAL_SLP_WLAN, 0, ESPI_MASTER_TO_SLAVE },
|
||||
{ ESPI_VWIRE_SIGNAL_HOST_C10, 0, ESPI_MASTER_TO_SLAVE },
|
||||
{ ESPI_VWIRE_SIGNAL_DNX_WARN, 0, ESPI_MASTER_TO_SLAVE },
|
||||
{ ESPI_VWIRE_SIGNAL_SLP_A, 0, ESPI_MASTER_TO_SLAVE },
|
||||
{ ESPI_VWIRE_SIGNAL_SLP_LAN, 0, ESPI_MASTER_TO_SLAVE },
|
||||
{ ESPI_VWIRE_SIGNAL_SLP_WLAN, 0, ESPI_MASTER_TO_SLAVE },
|
||||
{ ESPI_VWIRE_SIGNAL_HOST_C10, 0, ESPI_MASTER_TO_SLAVE },
|
||||
{ ESPI_VWIRE_SIGNAL_DNX_WARN, 0, ESPI_MASTER_TO_SLAVE },
|
||||
};
|
||||
|
||||
#define NUMBER_OF_VWIRES ARRAY_SIZE(vw_state_default)
|
||||
|
@ -109,8 +109,7 @@ static void emul_host_init_vw_state(struct espi_host_emul_data *data)
|
|||
* @return index in the array
|
||||
* @return -1 if not found
|
||||
*/
|
||||
static int emul_host_find_index(struct espi_host_emul_data *data,
|
||||
enum espi_vwire_signal vw)
|
||||
static int emul_host_find_index(struct espi_host_emul_data *data, enum espi_vwire_signal vw)
|
||||
{
|
||||
int idx;
|
||||
|
||||
|
@ -123,8 +122,7 @@ static int emul_host_find_index(struct espi_host_emul_data *data,
|
|||
return -1;
|
||||
}
|
||||
|
||||
static int emul_host_set_vw(struct espi_emul *emul, enum espi_vwire_signal vw,
|
||||
uint8_t level)
|
||||
static int emul_host_set_vw(struct espi_emul *emul, enum espi_vwire_signal vw, uint8_t level)
|
||||
{
|
||||
struct espi_host_emul_data *data;
|
||||
int idx;
|
||||
|
@ -142,8 +140,7 @@ static int emul_host_set_vw(struct espi_emul *emul, enum espi_vwire_signal vw,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int emul_host_get_vw(struct espi_emul *emul, enum espi_vwire_signal vw,
|
||||
uint8_t *level)
|
||||
static int emul_host_get_vw(struct espi_emul *emul, enum espi_vwire_signal vw, uint8_t *level)
|
||||
{
|
||||
struct espi_host_emul_data *data;
|
||||
int idx;
|
||||
|
@ -161,8 +158,7 @@ static int emul_host_get_vw(struct espi_emul *emul, enum espi_vwire_signal vw,
|
|||
return 0;
|
||||
}
|
||||
|
||||
int emul_espi_host_send_vw(const struct device *espi_dev, enum espi_vwire_signal vw,
|
||||
uint8_t level)
|
||||
int emul_espi_host_send_vw(const struct device *espi_dev, enum espi_vwire_signal vw, uint8_t level)
|
||||
{
|
||||
struct espi_emul *emul_espi;
|
||||
struct espi_event evt;
|
||||
|
@ -218,8 +214,7 @@ int emul_espi_host_port80_write(const struct device *espi_dev, uint32_t data)
|
|||
#ifdef CONFIG_ESPI_PERIPHERAL_ACPI_SHM_REGION
|
||||
static uintptr_t emul_espi_dev_get_acpi_shm(struct espi_emul *emul)
|
||||
{
|
||||
struct espi_host_emul_data *data =
|
||||
CONTAINER_OF(emul, struct espi_host_emul_data, emul);
|
||||
struct espi_host_emul_data *data = CONTAINER_OF(emul, struct espi_host_emul_data, emul);
|
||||
|
||||
return (uintptr_t)data->shm_acpi_mmap;
|
||||
}
|
||||
|
@ -231,7 +226,7 @@ uintptr_t emul_espi_host_get_acpi_shm(const struct device *espi_dev)
|
|||
|
||||
__ASSERT_NO_MSG(rc == 0);
|
||||
|
||||
return (uintptr_t) shm;
|
||||
return (uintptr_t)shm;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -52,8 +52,7 @@ struct at24_emul_cfg {
|
|||
* @retval 0 If successful
|
||||
* @retval -EIO General input / output error
|
||||
*/
|
||||
static int at24_emul_transfer(struct i2c_emul *emul, struct i2c_msg *msgs,
|
||||
int num_msgs, int addr)
|
||||
static int at24_emul_transfer(struct i2c_emul *emul, struct i2c_msg *msgs, int num_msgs, int addr)
|
||||
{
|
||||
struct at24_emul_data *data;
|
||||
const struct at24_emul_cfg *cfg;
|
||||
|
@ -65,8 +64,7 @@ static int at24_emul_transfer(struct i2c_emul *emul, struct i2c_msg *msgs,
|
|||
cfg = emul->parent->cfg;
|
||||
|
||||
if (cfg->addr != addr) {
|
||||
LOG_ERR("Address mismatch, expected %02x, got %02x", cfg->addr,
|
||||
addr);
|
||||
LOG_ERR("Address mismatch, expected %02x, got %02x", cfg->addr, addr);
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
|
@ -135,8 +133,7 @@ static struct i2c_emul_api at24_emul_api = {
|
|||
* @param parent Device to emulate (must use AT24 driver)
|
||||
* @return 0 indicating success (always)
|
||||
*/
|
||||
static int emul_atmel_at24_init(const struct emul *emul,
|
||||
const struct device *parent)
|
||||
static int emul_atmel_at24_init(const struct emul *emul, const struct device *parent)
|
||||
{
|
||||
const struct at24_emul_cfg *cfg = emul->cfg;
|
||||
struct at24_emul_data *data = emul->data;
|
||||
|
|
Loading…
Reference in a new issue