Lines Matching +full:100 +full:base +full:- +full:t
4 * SPDX-License-Identifier: Apache-2.0
23 #include "i2c-priv.h"
26 ((I2C_Type *)((const struct i2c_mcux_config * const)(dev)->config)->base)
29 I2C_Type *base; member
54 I2C_Type *base = DEV_BASE(dev); in i2c_mcux_configure() local
55 struct i2c_mcux_data *data = dev->data; in i2c_mcux_configure()
56 const struct i2c_mcux_config *config = dev->config; in i2c_mcux_configure()
61 return -EINVAL; in i2c_mcux_configure()
65 return -EINVAL; in i2c_mcux_configure()
70 baudrate = KHZ(100); in i2c_mcux_configure()
79 return -EINVAL; in i2c_mcux_configure()
82 clock_freq = CLOCK_GetFreq(config->clock_source); in i2c_mcux_configure()
83 k_sem_take(&data->lock, K_FOREVER); in i2c_mcux_configure()
84 I2C_MasterSetBaudRate(base, baudrate, clock_freq); in i2c_mcux_configure()
85 k_sem_give(&data->lock); in i2c_mcux_configure()
97 static void i2c_mcux_master_transfer_callback(I2C_Type *base, in i2c_mcux_master_transfer_callback() argument
103 ARG_UNUSED(base); in i2c_mcux_master_transfer_callback()
106 struct i2c_mcux_data *data = dev->data; in i2c_mcux_master_transfer_callback()
109 if (data->cb != NULL) { in i2c_mcux_master_transfer_callback()
112 I2C_MasterTransferAbort(base, &data->handle); in i2c_mcux_master_transfer_callback()
113 i2c_mcux_async_done(dev, data, -EIO); in i2c_mcux_master_transfer_callback()
114 } else if (data->msg == data->num_msgs - 1) { in i2c_mcux_master_transfer_callback()
117 data->msg++; in i2c_mcux_master_transfer_callback()
124 data->callback_status = status; in i2c_mcux_master_transfer_callback()
126 k_sem_give(&data->device_sync_sem); in i2c_mcux_master_transfer_callback()
147 I2C_Type *base = DEV_BASE(dev); in i2c_mcux_transfer() local
148 struct i2c_mcux_data *data = dev->data; in i2c_mcux_transfer()
153 k_sem_take(&data->lock, K_FOREVER); in i2c_mcux_transfer()
157 if (I2C_MSG_ADDR_10_BITS & msgs->flags) { in i2c_mcux_transfer()
158 ret = -ENOTSUP; in i2c_mcux_transfer()
163 transfer.flags = i2c_mcux_convert_flags(msgs->flags); in i2c_mcux_transfer()
165 transfer.direction = (msgs->flags & I2C_MSG_READ) in i2c_mcux_transfer()
169 transfer.data = msgs->buf; in i2c_mcux_transfer()
170 transfer.dataSize = msgs->len; in i2c_mcux_transfer()
175 if (i != 0 && !(msgs->flags & I2C_MSG_RESTART)) { in i2c_mcux_transfer()
180 status = I2C_MasterTransferNonBlocking(base, in i2c_mcux_transfer()
181 &data->handle, &transfer); in i2c_mcux_transfer()
183 /* Return an error if the transfer didn't start successfully in i2c_mcux_transfer()
187 I2C_MasterTransferAbort(base, &data->handle); in i2c_mcux_transfer()
188 ret = -EIO; in i2c_mcux_transfer()
193 k_sem_take(&data->device_sync_sem, K_FOREVER); in i2c_mcux_transfer()
195 /* Return an error if the transfer didn't complete in i2c_mcux_transfer()
198 if (data->callback_status != kStatus_Success) { in i2c_mcux_transfer()
199 I2C_MasterTransferAbort(base, &data->handle); in i2c_mcux_transfer()
200 ret = -EIO; in i2c_mcux_transfer()
208 k_sem_give(&data->lock); in i2c_mcux_transfer()
218 i2c_callback_t cb = data->cb; in i2c_mcux_async_done()
219 void *userdata = data->userdata; in i2c_mcux_async_done()
221 data->msg = 0; in i2c_mcux_async_done()
222 data->msgs = NULL; in i2c_mcux_async_done()
223 data->num_msgs = 0; in i2c_mcux_async_done()
224 data->cb = NULL; in i2c_mcux_async_done()
225 data->userdata = NULL; in i2c_mcux_async_done()
226 data->addr = 0; in i2c_mcux_async_done()
228 k_sem_give(&data->lock); in i2c_mcux_async_done()
237 I2C_Type *base = DEV_BASE(dev); in i2c_mcux_async_iter() local
238 struct i2c_mcux_data *data = dev->data; in i2c_mcux_async_iter()
241 struct i2c_msg *msg = &data->msgs[data->msg]; in i2c_mcux_async_iter()
243 if (I2C_MSG_ADDR_10_BITS & msg->flags) { in i2c_mcux_async_iter()
244 i2c_mcux_async_done(dev, data, -ENOTSUP); in i2c_mcux_async_iter()
249 transfer.flags = i2c_mcux_convert_flags(msg->flags); in i2c_mcux_async_iter()
250 transfer.slaveAddress = data->addr; in i2c_mcux_async_iter()
251 transfer.direction = (msg->flags & I2C_MSG_READ) ? kI2C_Read : kI2C_Write; in i2c_mcux_async_iter()
254 transfer.data = msg->buf; in i2c_mcux_async_iter()
255 transfer.dataSize = msg->len; in i2c_mcux_async_iter()
260 if (data->msg != 0 && !(msg->flags & I2C_MSG_RESTART)) { in i2c_mcux_async_iter()
265 status = I2C_MasterTransferNonBlocking(base, &data->handle, &transfer); in i2c_mcux_async_iter()
267 /* Return an error if the transfer didn't start successfully in i2c_mcux_async_iter()
271 I2C_MasterTransferAbort(base, &data->handle); in i2c_mcux_async_iter()
272 i2c_mcux_async_done(dev, data, -EIO); in i2c_mcux_async_iter()
279 struct i2c_mcux_data *data = dev->data; in i2c_mcux_transfer_cb()
281 int res = k_sem_take(&data->lock, K_NO_WAIT); in i2c_mcux_transfer_cb()
284 return -EWOULDBLOCK; in i2c_mcux_transfer_cb()
287 data->msg = 0; in i2c_mcux_transfer_cb()
288 data->msgs = msgs; in i2c_mcux_transfer_cb()
289 data->num_msgs = num_msgs; in i2c_mcux_transfer_cb()
290 data->addr = addr; in i2c_mcux_transfer_cb()
291 data->cb = cb; in i2c_mcux_transfer_cb()
292 data->userdata = userdata; in i2c_mcux_transfer_cb()
293 data->addr = addr; in i2c_mcux_transfer_cb()
304 I2C_Type *base = DEV_BASE(dev); in i2c_mcux_isr() local
305 struct i2c_mcux_data *data = dev->data; in i2c_mcux_isr()
307 I2C_MasterTransferHandleIRQ(base, &data->handle); in i2c_mcux_isr()
312 I2C_Type *base = DEV_BASE(dev); in i2c_mcux_init() local
313 const struct i2c_mcux_config *config = dev->config; in i2c_mcux_init()
314 struct i2c_mcux_data *data = dev->data; in i2c_mcux_init()
319 k_sem_init(&data->lock, 1, 1); in i2c_mcux_init()
320 k_sem_init(&data->device_sync_sem, 0, K_SEM_MAX_LIMIT); in i2c_mcux_init()
322 clock_freq = CLOCK_GetFreq(config->clock_source); in i2c_mcux_init()
324 I2C_MasterInit(base, &master_config, clock_freq); in i2c_mcux_init()
325 I2C_MasterTransferCreateHandle(base, &data->handle, in i2c_mcux_init()
328 bitrate_cfg = i2c_map_dt_bitrate(config->bitrate); in i2c_mcux_init()
330 error = pinctrl_apply_state(config->pincfg, PINCTRL_STATE_DEFAULT); in i2c_mcux_init()
340 config->irq_config_func(dev); in i2c_mcux_init()
359 .base = (I2C_Type *)DT_INST_REG_ADDR(n),\