Lines Matching +full:100 +full:base +full:- +full:t
3 * Copyright 2019-2023, NXP
7 * SPDX-License-Identifier: Apache-2.0
30 #include "i2c-priv.h"
38 ((const struct mcux_lpi2c_config *)(_dev)->config)
39 #define DEV_DATA(_dev) ((struct mcux_lpi2c_data *)(_dev)->data)
74 dev->data)->ctx; in mcux_lpi2c_configure()
82 const struct mcux_lpi2c_config *config = dev->config; in mcux_lpi2c_do_configure()
83 LPI2C_Type *base = (LPI2C_Type *)DEVICE_MMIO_NAMED_GET(dev, reg_base); in mcux_lpi2c_do_configure() local
88 return -EINVAL; in mcux_lpi2c_do_configure()
92 return -EINVAL; in mcux_lpi2c_do_configure()
97 baudrate = KHZ(100); in mcux_lpi2c_do_configure()
106 return -EINVAL; in mcux_lpi2c_do_configure()
109 if (clock_control_get_rate(config->clock_dev, config->clock_subsys, in mcux_lpi2c_do_configure()
111 return -EINVAL; in mcux_lpi2c_do_configure()
114 LPI2C_MasterSetBaudRate(base, clock_freq, baudrate); in mcux_lpi2c_do_configure()
138 struct mcux_lpi2c_data *data = dev->data; in mcux_lpi2c_msg_start()
139 struct i2c_rtio *ctx = data->ctx; in mcux_lpi2c_msg_start()
140 LPI2C_Type *base = (LPI2C_Type *)DEVICE_MMIO_NAMED_GET(dev, reg_base); in mcux_lpi2c_msg_start() local
141 lpi2c_master_transfer_t *transfer = &data->transfer; in mcux_lpi2c_msg_start()
145 return i2c_rtio_complete(ctx, -ENOTSUP); in mcux_lpi2c_msg_start()
149 transfer->flags = mcux_lpi2c_convert_flags(flags); in mcux_lpi2c_msg_start()
154 if (ctx->txn_curr != ctx->txn_head && !(flags & I2C_MSG_RESTART)) { in mcux_lpi2c_msg_start()
155 transfer->flags |= kLPI2C_TransferNoStartFlag; in mcux_lpi2c_msg_start()
158 transfer->slaveAddress = i2c_addr; in mcux_lpi2c_msg_start()
159 transfer->direction = (flags & I2C_MSG_READ) in mcux_lpi2c_msg_start()
161 transfer->subaddress = 0; in mcux_lpi2c_msg_start()
162 transfer->subaddressSize = 0; in mcux_lpi2c_msg_start()
163 transfer->data = buf; in mcux_lpi2c_msg_start()
164 transfer->dataSize = buf_len; in mcux_lpi2c_msg_start()
167 status = LPI2C_MasterTransferNonBlocking(base, in mcux_lpi2c_msg_start()
168 &data->handle, transfer); in mcux_lpi2c_msg_start()
170 /* Return an error if the transfer didn't start successfully in mcux_lpi2c_msg_start()
174 LPI2C_MasterTransferAbort(base, &data->handle); in mcux_lpi2c_msg_start()
175 return i2c_rtio_complete(ctx, -EIO); in mcux_lpi2c_msg_start()
185 struct mcux_lpi2c_data *data = dev->data; in mcux_lpi2c_start()
186 struct i2c_rtio *ctx = data->ctx; in mcux_lpi2c_start()
187 struct rtio_sqe *sqe = &ctx->txn_curr->sqe; in mcux_lpi2c_start()
188 struct i2c_dt_spec *dt_spec = sqe->iodev->data; in mcux_lpi2c_start()
192 switch (sqe->op) { in mcux_lpi2c_start()
194 return mcux_lpi2c_msg_start(dev, I2C_MSG_READ | sqe->iodev_flags, in mcux_lpi2c_start()
195 sqe->rx.buf, sqe->rx.buf_len, dt_spec->addr); in mcux_lpi2c_start()
197 return mcux_lpi2c_msg_start(dev, I2C_MSG_WRITE | sqe->iodev_flags, in mcux_lpi2c_start()
198 (uint8_t *)sqe->tiny_tx.buf, sqe->tiny_tx.buf_len, in mcux_lpi2c_start()
199 dt_spec->addr); in mcux_lpi2c_start()
201 return mcux_lpi2c_msg_start(dev, I2C_MSG_WRITE | sqe->iodev_flags, in mcux_lpi2c_start()
202 (uint8_t *)sqe->tx.buf, sqe->tx.buf_len, in mcux_lpi2c_start()
203 dt_spec->addr); in mcux_lpi2c_start()
205 res = mcux_lpi2c_do_configure(dev, sqe->i2c_config); in mcux_lpi2c_start()
206 return i2c_rtio_complete(data->ctx, res); in mcux_lpi2c_start()
208 LOG_ERR("Invalid op code %d for submission %p\n", sqe->op, (void *)sqe); in mcux_lpi2c_start()
209 return i2c_rtio_complete(data->ctx, -EINVAL); in mcux_lpi2c_start()
215 const struct mcux_lpi2c_config *config = dev->config; in mcux_lpi2c_complete()
216 struct mcux_lpi2c_data *data = dev->data; in mcux_lpi2c_complete()
217 LPI2C_Type *base = (LPI2C_Type *)DEVICE_MMIO_NAMED_GET(dev, reg_base); in mcux_lpi2c_complete() local
218 struct i2c_rtio *const ctx = data->ctx; in mcux_lpi2c_complete()
222 /* Return an error if the transfer didn't complete in mcux_lpi2c_complete()
226 LPI2C_MasterTransferAbort(base, &data->handle); in mcux_lpi2c_complete()
227 ret = -EIO; in mcux_lpi2c_complete()
231 if (data->transfer.dataSize == 0) { in mcux_lpi2c_complete()
232 k_busy_wait(SCAN_DELAY_US(config->bitrate)); in mcux_lpi2c_complete()
233 if (0 != (base->MSR & LPI2C_MSR_NDF_MASK)) { in mcux_lpi2c_complete()
234 LPI2C_MasterTransferAbort(base, &data->handle); in mcux_lpi2c_complete()
235 ret = -EIO; in mcux_lpi2c_complete()
248 struct mcux_lpi2c_data *data = dev->data; in mcux_lpi2c_submit()
249 struct i2c_rtio *const ctx = data->ctx; in mcux_lpi2c_submit()
257 static void mcux_lpi2c_master_transfer_callback(LPI2C_Type *base, in mcux_lpi2c_master_transfer_callback() argument
262 ARG_UNUSED(base); in mcux_lpi2c_master_transfer_callback()
273 dev->data)->ctx; in mcux_lpi2c_transfer()
280 struct mcux_lpi2c_data *data = dev->data; in mcux_lpi2c_isr()
281 LPI2C_Type *base = (LPI2C_Type *)DEVICE_MMIO_NAMED_GET(dev, reg_base); in mcux_lpi2c_isr() local
283 LPI2C_MasterTransferHandleIRQ(base, &data->handle); in mcux_lpi2c_isr()
288 const struct mcux_lpi2c_config *config = dev->config; in mcux_lpi2c_init()
289 struct mcux_lpi2c_data *data = dev->data; in mcux_lpi2c_init()
290 LPI2C_Type *base; in mcux_lpi2c_init() local
297 base = (LPI2C_Type *)DEVICE_MMIO_NAMED_GET(dev, reg_base); in mcux_lpi2c_init()
299 if (!device_is_ready(config->clock_dev)) { in mcux_lpi2c_init()
301 return -ENODEV; in mcux_lpi2c_init()
304 error = pinctrl_apply_state(config->pincfg, PINCTRL_STATE_DEFAULT); in mcux_lpi2c_init()
309 if (clock_control_get_rate(config->clock_dev, config->clock_subsys, in mcux_lpi2c_init()
311 return -EINVAL; in mcux_lpi2c_init()
315 master_config.busIdleTimeout_ns = config->bus_idle_timeout_ns; in mcux_lpi2c_init()
316 LPI2C_MasterInit(base, &master_config, clock_freq); in mcux_lpi2c_init()
317 LPI2C_MasterTransferCreateHandle(base, &data->handle, in mcux_lpi2c_init()
321 bitrate_cfg = i2c_map_dt_bitrate(config->bitrate); in mcux_lpi2c_init()
328 config->irq_config_func(dev); in mcux_lpi2c_init()
330 i2c_rtio_init(data->ctx, dev); in mcux_lpi2c_init()