diff --git a/drivers/eeprom/eeprom_at2x_emul.c b/drivers/eeprom/eeprom_at2x_emul.c index 25d079dfa6d..91033c02b4a 100644 --- a/drivers/eeprom/eeprom_at2x_emul.c +++ b/drivers/eeprom/eeprom_at2x_emul.c @@ -81,7 +81,7 @@ static int at24_emul_transfer(const struct emul *target, struct i2c_msg *msgs, return -EIO; } - i2c_dump_msgs_rw("emul", msgs, num_msgs, addr, false); + i2c_dump_msgs_rw(target->dev, msgs, num_msgs, addr, false); switch (num_msgs) { case 1: if (msgs->flags & I2C_MSG_READ) { diff --git a/drivers/fuel_gauge/max17048/emul_max17048.c b/drivers/fuel_gauge/max17048/emul_max17048.c index 3ae1565cb47..a3a09f4c03e 100644 --- a/drivers/fuel_gauge/max17048/emul_max17048.c +++ b/drivers/fuel_gauge/max17048/emul_max17048.c @@ -75,7 +75,7 @@ static int max17048_emul_transfer_i2c(const struct emul *target, struct i2c_msg __ASSERT_NO_MSG(msgs && num_msgs); - i2c_dump_msgs_rw("emul", msgs, num_msgs, addr, false); + i2c_dump_msgs_rw(target->dev, msgs, num_msgs, addr, false); switch (num_msgs) { case 2: if (msgs->flags & I2C_MSG_READ) { diff --git a/drivers/fuel_gauge/sbs_gauge/emul_sbs_gauge.c b/drivers/fuel_gauge/sbs_gauge/emul_sbs_gauge.c index c84a73e75ff..64668d54307 100644 --- a/drivers/fuel_gauge/sbs_gauge/emul_sbs_gauge.c +++ b/drivers/fuel_gauge/sbs_gauge/emul_sbs_gauge.c @@ -233,7 +233,7 @@ static int sbs_gauge_emul_transfer_i2c(const struct emul *target, struct i2c_msg __ASSERT_NO_MSG(msgs && num_msgs); - i2c_dump_msgs_rw("emul", msgs, num_msgs, addr, false); + i2c_dump_msgs_rw(target->dev, msgs, num_msgs, addr, false); switch (num_msgs) { case 2: if (msgs->flags & I2C_MSG_READ) { diff --git a/drivers/i2c/Kconfig b/drivers/i2c/Kconfig index 655d7f6e0bc..8ae217f82bf 100644 --- a/drivers/i2c/Kconfig +++ b/drivers/i2c/Kconfig @@ -32,6 +32,7 @@ config I2C_STATS config I2C_DUMP_MESSAGES bool "Log all I2C transactions" depends on LOG + depends on I2C_LOG_LEVEL_DBG help Dump every I2C transaction to the system log as debug level log messages. diff --git a/drivers/i2c/i2c_common.c b/drivers/i2c/i2c_common.c index aaae974add8..6094ed12c77 100644 --- a/drivers/i2c/i2c_common.c +++ b/drivers/i2c/i2c_common.c @@ -25,10 +25,10 @@ void z_i2c_transfer_signal_cb(const struct device *dev, } #endif -void i2c_dump_msgs_rw(const char *name, const struct i2c_msg *msgs, - uint8_t num_msgs, uint16_t addr, bool dump_read) +void i2c_dump_msgs_rw(const struct device *dev, const struct i2c_msg *msgs, uint8_t num_msgs, + uint16_t addr, bool dump_read) { - LOG_DBG("I2C msg: %s, addr=%x", name, addr); + LOG_DBG("I2C msg: %s, addr=%x", dev->name, addr); for (unsigned int i = 0; i < num_msgs; i++) { const struct i2c_msg *msg = &msgs[i]; const bool is_read = msg->flags & I2C_MSG_READ; diff --git a/drivers/sensor/akm09918c/akm09918c_emul.c b/drivers/sensor/akm09918c/akm09918c_emul.c index 2112acc8c00..a8ce27fd3d3 100644 --- a/drivers/sensor/akm09918c/akm09918c_emul.c +++ b/drivers/sensor/akm09918c/akm09918c_emul.c @@ -76,7 +76,7 @@ static int akm09918c_emul_transfer_i2c(const struct emul *target, struct i2c_msg { struct akm09918c_emul_data *data = target->data; - i2c_dump_msgs_rw("emul", msgs, num_msgs, addr, false); + i2c_dump_msgs_rw(target->dev, msgs, num_msgs, addr, false); if (num_msgs < 1) { LOG_ERR("Invalid number of messages: %d", num_msgs); diff --git a/drivers/sensor/bmi160/emul_bmi160.c b/drivers/sensor/bmi160/emul_bmi160.c index 78fe6d3ef88..3870346cd30 100644 --- a/drivers/sensor/bmi160/emul_bmi160.c +++ b/drivers/sensor/bmi160/emul_bmi160.c @@ -241,7 +241,7 @@ static int bmi160_emul_transfer_i2c(const struct emul *target, struct i2c_msg *m __ASSERT_NO_MSG(msgs && num_msgs); - i2c_dump_msgs_rw("emul", msgs, num_msgs, addr, false); + i2c_dump_msgs_rw(target->dev, msgs, num_msgs, addr, false); switch (num_msgs) { case 2: if (msgs->flags & I2C_MSG_READ) { diff --git a/drivers/usb/bc12/emul_bc12_pi3usb9201.c b/drivers/usb/bc12/emul_bc12_pi3usb9201.c index 6d6842939cd..f798d4d9ac0 100644 --- a/drivers/usb/bc12/emul_bc12_pi3usb9201.c +++ b/drivers/usb/bc12/emul_bc12_pi3usb9201.c @@ -192,7 +192,7 @@ static int pi3usb9201_emul_transfer(const struct emul *target, struct i2c_msg *m return -EIO; } - i2c_dump_msgs("emul", msgs, num_msgs, addr); + i2c_dump_msgs(target->dev, msgs, num_msgs, addr); /* Only single byte register access permitted. Write operations must * consist of 2 write bytes: register offset, register data. Read diff --git a/include/zephyr/drivers/i2c.h b/include/zephyr/drivers/i2c.h index 95d0cf1e9c1..c3ea9bb43eb 100644 --- a/include/zephyr/drivers/i2c.h +++ b/include/zephyr/drivers/i2c.h @@ -488,33 +488,33 @@ static inline bool i2c_is_ready_dt(const struct i2c_dt_spec *spec) * D: R len=01: 6c * @endcode * - * @param name Name of this dump, displayed at the top. + * @param dev Target for the messages being sent. Its name will be printed in the log. * @param msgs Array of messages to dump. * @param num_msgs Number of messages to dump. * @param addr Address of the I2C target device. * @param dump_read Dump data from I2C reads, otherwise only writes have data dumped. */ -void i2c_dump_msgs_rw(const char *name, const struct i2c_msg *msgs, - uint8_t num_msgs, uint16_t addr, bool dump_read); +void i2c_dump_msgs_rw(const struct device *dev, const struct i2c_msg *msgs, uint8_t num_msgs, + uint16_t addr, bool dump_read); /** * @brief Dump out an I2C message, before it is executed. * * This is equivalent to: * - * i2c_dump_msgs_rw(name, msgs, num_msgs, addr, false); + * i2c_dump_msgs_rw(dev, msgs, num_msgs, addr, false); * * The read messages' data isn't dumped. * - * @param name Name of this dump, displayed at the top. + * @param dev Target for the messages being sent. Its name will be printed in the log. * @param msgs Array of messages to dump. * @param num_msgs Number of messages to dump. * @param addr Address of the I2C target device. */ -static inline void i2c_dump_msgs(const char *name, const struct i2c_msg *msgs, +static inline void i2c_dump_msgs(const struct device *dev, const struct i2c_msg *msgs, uint8_t num_msgs, uint16_t addr) { - i2c_dump_msgs_rw(name, msgs, num_msgs, addr, false); + i2c_dump_msgs_rw(dev, msgs, num_msgs, addr, false); } #if defined(CONFIG_I2C_STATS) || defined(__DOXYGEN__) @@ -772,7 +772,7 @@ static inline int z_impl_i2c_transfer(const struct device *dev, i2c_xfer_stats(dev, msgs, num_msgs); if (IS_ENABLED(CONFIG_I2C_DUMP_MESSAGES)) { - i2c_dump_msgs_rw(dev->name, msgs, num_msgs, addr, true); + i2c_dump_msgs_rw(dev, msgs, num_msgs, addr, true); } return res;