Skip to content

Commit 7eb1ad9

Browse files
Trond-F-Christiansenrlubos
authored andcommitted
[nrf fromtree] sensor: bmm350: Fix I2C register write to use single transaction
The bmm350_prep_reg_write_rtio_async() function was incorrectly using two separate SQEs for register writes, creating two distinct I2C transactions: Before: [START][ADDR+W][REG][RESTART] + [START][ADDR+W][DATA][STOP] Change to use a single SQE for the entire write: After: [START][ADDR+W][REG][DATA][STOP] Signed-off-by: Trond F. Christiansen <[email protected]> (cherry picked from commit 049d368)
1 parent 46ce70c commit 7eb1ad9

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

drivers/sensor/bosch/bmm350/bmm350_bus.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,27 +52,29 @@ static int bmm350_prep_reg_write_rtio_async(const struct bmm350_bus *bus,
5252
{
5353
struct rtio *ctx = bus->rtio.ctx;
5454
struct rtio_iodev *iodev = bus->rtio.iodev;
55-
struct rtio_sqe *write_reg_sqe = rtio_sqe_acquire(ctx);
56-
struct rtio_sqe *write_buf_sqe = rtio_sqe_acquire(ctx);
55+
struct rtio_sqe *write_sqe = rtio_sqe_acquire(ctx);
56+
uint8_t write_buf[2];
5757

58-
if (!write_reg_sqe || !write_buf_sqe) {
58+
if (!write_sqe) {
5959
rtio_sqe_drop_all(ctx);
6060
return -ENOMEM;
6161
}
6262

63-
rtio_sqe_prep_tiny_write(write_reg_sqe, iodev, RTIO_PRIO_NORM, &reg, 1, NULL);
64-
write_reg_sqe->flags |= RTIO_SQE_TRANSACTION;
65-
rtio_sqe_prep_tiny_write(write_buf_sqe, iodev, RTIO_PRIO_NORM, &val, 1, NULL);
63+
write_buf[0] = reg;
64+
write_buf[1] = val;
65+
66+
/* Single I2C transaction: [W(addr), reg, data] */
67+
rtio_sqe_prep_tiny_write(write_sqe, iodev, RTIO_PRIO_NORM, write_buf, 2, NULL);
6668
if (bus->rtio.type == BMM350_BUS_TYPE_I2C) {
67-
write_buf_sqe->iodev_flags |= RTIO_IODEV_I2C_STOP;
69+
write_sqe->iodev_flags |= RTIO_IODEV_I2C_STOP;
6870
}
6971

70-
/** Send back last SQE so it can be concatenated later. */
72+
/** Send back SQE so it can be concatenated later. */
7173
if (out) {
72-
*out = write_buf_sqe;
74+
*out = write_sqe;
7375
}
7476

75-
return 2;
77+
return 1;
7678
}
7779

7880
static int bmm350_reg_read_rtio(const struct bmm350_bus *bus, uint8_t start, uint8_t *buf, int size)

0 commit comments

Comments
 (0)