Lines Matching full:ctx
55 void i2c_rtio_init(struct i2c_rtio *ctx, const struct device *dev) in i2c_rtio_init() argument
57 k_sem_init(&ctx->lock, 1, 1); in i2c_rtio_init()
58 mpsc_init(&ctx->io_q); in i2c_rtio_init()
59 ctx->txn_curr = NULL; in i2c_rtio_init()
60 ctx->txn_head = NULL; in i2c_rtio_init()
61 ctx->dt_spec.bus = dev; in i2c_rtio_init()
62 ctx->iodev.data = &ctx->dt_spec; in i2c_rtio_init()
63 ctx->iodev.api = &i2c_iodev_api; in i2c_rtio_init()
73 static bool i2c_rtio_next(struct i2c_rtio *ctx, bool completion) in i2c_rtio_next() argument
75 k_spinlock_key_t key = k_spin_lock(&ctx->slock); in i2c_rtio_next()
78 if (!completion && ctx->txn_head != NULL) { in i2c_rtio_next()
79 k_spin_unlock(&ctx->slock, key); in i2c_rtio_next()
83 struct mpsc_node *next = mpsc_pop(&ctx->io_q); in i2c_rtio_next()
87 ctx->txn_head = NULL; in i2c_rtio_next()
88 ctx->txn_curr = NULL; in i2c_rtio_next()
89 k_spin_unlock(&ctx->slock, key); in i2c_rtio_next()
93 ctx->txn_head = CONTAINER_OF(next, struct rtio_iodev_sqe, q); in i2c_rtio_next()
94 ctx->txn_curr = ctx->txn_head; in i2c_rtio_next()
96 k_spin_unlock(&ctx->slock, key); in i2c_rtio_next()
101 bool i2c_rtio_complete(struct i2c_rtio *ctx, int status) in i2c_rtio_complete() argument
105 rtio_iodev_sqe_err(ctx->txn_head, status); in i2c_rtio_complete()
106 return i2c_rtio_next(ctx, true); in i2c_rtio_complete()
110 ctx->txn_curr = rtio_txn_next(ctx->txn_curr); in i2c_rtio_complete()
111 if (ctx->txn_curr) { in i2c_rtio_complete()
115 rtio_iodev_sqe_ok(ctx->txn_head, status); in i2c_rtio_complete()
116 return i2c_rtio_next(ctx, true); in i2c_rtio_complete()
118 bool i2c_rtio_submit(struct i2c_rtio *ctx, struct rtio_iodev_sqe *iodev_sqe) in i2c_rtio_submit() argument
120 mpsc_push(&ctx->io_q, &iodev_sqe->q); in i2c_rtio_submit()
121 return i2c_rtio_next(ctx, false); in i2c_rtio_submit()
124 int i2c_rtio_transfer(struct i2c_rtio *ctx, struct i2c_msg *msgs, uint8_t num_msgs, uint16_t addr) in i2c_rtio_transfer() argument
126 struct rtio_iodev *iodev = &ctx->iodev; in i2c_rtio_transfer()
127 struct rtio *const r = ctx->r; in i2c_rtio_transfer()
132 k_sem_take(&ctx->lock, K_FOREVER); in i2c_rtio_transfer()
134 ctx->dt_spec.addr = addr; in i2c_rtio_transfer()
153 k_sem_give(&ctx->lock); in i2c_rtio_transfer()
157 int i2c_rtio_configure(struct i2c_rtio *ctx, uint32_t i2c_config) in i2c_rtio_configure() argument
159 struct rtio_iodev *iodev = &ctx->iodev; in i2c_rtio_configure()
160 struct rtio *const r = ctx->r; in i2c_rtio_configure()
165 k_sem_take(&ctx->lock, K_FOREVER); in i2c_rtio_configure()
185 k_sem_give(&ctx->lock); in i2c_rtio_configure()
189 int i2c_rtio_recover(struct i2c_rtio *ctx) in i2c_rtio_recover() argument
191 struct rtio_iodev *iodev = &ctx->iodev; in i2c_rtio_recover()
192 struct rtio *const r = ctx->r; in i2c_rtio_recover()
197 k_sem_take(&ctx->lock, K_FOREVER); in i2c_rtio_recover()
216 k_sem_give(&ctx->lock); in i2c_rtio_recover()