Lines Matching +full:bitrate +full:- +full:data
5 * SPDX-License-Identifier: Apache-2.0
20 #include "i2c-priv.h"
56 /* Data structure */
75 uint32_t bitrate; member
81 struct ifx_xmc4_i2c_data *data = dev->data; in ifx_xmc4_i2c_configure() local
82 const struct ifx_xmc4_i2c_config *config = dev->config; in ifx_xmc4_i2c_configure()
87 return -EIO; in ifx_xmc4_i2c_configure()
92 data->cfg.baudrate = XMC4_I2C_SPEED_STANDARD; in ifx_xmc4_i2c_configure()
95 data->cfg.baudrate = XMC4_I2C_SPEED_FAST; in ifx_xmc4_i2c_configure()
99 return -ERANGE; in ifx_xmc4_i2c_configure()
102 data->dev_config = dev_config; in ifx_xmc4_i2c_configure()
105 if (k_sem_take(&data->operation_sem, K_FOREVER)) { in ifx_xmc4_i2c_configure()
106 return -EIO; in ifx_xmc4_i2c_configure()
109 XMC_I2C_CH_Stop(config->i2c); in ifx_xmc4_i2c_configure()
112 data->cfg.normal_divider_mode = false; in ifx_xmc4_i2c_configure()
113 XMC_I2C_CH_Init(config->i2c, &data->cfg); in ifx_xmc4_i2c_configure()
114 XMC_I2C_CH_SetInputSource(config->i2c, XMC_I2C_CH_INPUT_SCL, config->scl_src); in ifx_xmc4_i2c_configure()
115 XMC_I2C_CH_SetInputSource(config->i2c, XMC_I2C_CH_INPUT_SDA, config->sda_src); in ifx_xmc4_i2c_configure()
116 if (data->dev_config & I2C_MODE_CONTROLLER) { in ifx_xmc4_i2c_configure()
117 XMC_USIC_CH_SetFractionalDivider(config->i2c, in ifx_xmc4_i2c_configure()
121 config->irq_config_func(dev); in ifx_xmc4_i2c_configure()
123 XMC_I2C_CH_Start(config->i2c); in ifx_xmc4_i2c_configure()
124 data->is_configured = true; in ifx_xmc4_i2c_configure()
127 k_sem_give(&data->operation_sem); in ifx_xmc4_i2c_configure()
134 struct ifx_xmc4_i2c_data *data = dev->data; in ifx_xmc4_i2c_get_config() local
135 const struct ifx_xmc4_i2c_config *config = dev->config; in ifx_xmc4_i2c_get_config()
137 if (!data->is_configured) { in ifx_xmc4_i2c_get_config()
140 uint32_t bitrate_cfg = i2c_map_dt_bitrate(config->bitrate); in ifx_xmc4_i2c_get_config()
146 *dev_config = data->dev_config; in ifx_xmc4_i2c_get_config()
155 return -EINVAL; in ifx_xmc4_i2c_msg_validate()
164 struct ifx_xmc4_i2c_data *data = dev->data; in ifx_xmc4_i2c_transfer() local
165 const struct ifx_xmc4_i2c_config *config = dev->config; in ifx_xmc4_i2c_transfer()
172 if (!data->is_configured) { in ifx_xmc4_i2c_transfer()
174 uint32_t bitrate_cfg = i2c_map_dt_bitrate(config->bitrate); in ifx_xmc4_i2c_transfer()
183 if (k_sem_take(&data->operation_sem, K_FOREVER)) { in ifx_xmc4_i2c_transfer()
184 return -EIO; in ifx_xmc4_i2c_transfer()
189 k_sem_give(&data->operation_sem); in ifx_xmc4_i2c_transfer()
190 return -EINVAL; in ifx_xmc4_i2c_transfer()
194 XMC_I2C_CH_ClearStatusFlag(config->i2c, 0xFFFFFFFF); in ifx_xmc4_i2c_transfer()
202 XMC_I2C_CH_MasterRepeatedStart(config->i2c, addr << 1, cmd_type); in ifx_xmc4_i2c_transfer()
204 XMC_I2C_CH_MasterStart(config->i2c, addr << 1, cmd_type); in ifx_xmc4_i2c_transfer()
208 while ((XMC_I2C_CH_GetStatusFlag(config->i2c) & in ifx_xmc4_i2c_transfer()
211 if (XMC_I2C_CH_GetStatusFlag(config->i2c) & in ifx_xmc4_i2c_transfer()
213 k_sem_give(&data->operation_sem); in ifx_xmc4_i2c_transfer()
214 return -EIO; in ifx_xmc4_i2c_transfer()
217 XMC_I2C_CH_ClearStatusFlag(config->i2c, in ifx_xmc4_i2c_transfer()
224 XMC_I2C_CH_MasterTransmit(config->i2c, in ifx_xmc4_i2c_transfer()
228 while ((XMC_I2C_CH_GetStatusFlag(config->i2c) & in ifx_xmc4_i2c_transfer()
231 if (XMC_I2C_CH_GetStatusFlag(config->i2c) & in ifx_xmc4_i2c_transfer()
233 k_sem_give(&data->operation_sem); in ifx_xmc4_i2c_transfer()
234 return -EIO; in ifx_xmc4_i2c_transfer()
237 XMC_I2C_CH_ClearStatusFlag(config->i2c, in ifx_xmc4_i2c_transfer()
241 while (!XMC_USIC_CH_TXFIFO_IsEmpty(config->i2c)) { in ifx_xmc4_i2c_transfer()
242 /* wait until all data is sent by HW */ in ifx_xmc4_i2c_transfer()
243 if (XMC_I2C_CH_GetStatusFlag(config->i2c) & in ifx_xmc4_i2c_transfer()
245 k_sem_give(&data->operation_sem); in ifx_xmc4_i2c_transfer()
246 return -EIO; in ifx_xmc4_i2c_transfer()
250 if (buf_index == (msg[msg_index].len - 1)) { in ifx_xmc4_i2c_transfer()
251 XMC_I2C_CH_MasterReceiveNack(config->i2c); in ifx_xmc4_i2c_transfer()
253 XMC_I2C_CH_MasterReceiveAck(config->i2c); in ifx_xmc4_i2c_transfer()
256 while ((XMC_I2C_CH_GetStatusFlag(config->i2c) & in ifx_xmc4_i2c_transfer()
259 /* wait for data byte from slave */ in ifx_xmc4_i2c_transfer()
260 if (XMC_I2C_CH_GetStatusFlag(config->i2c) & in ifx_xmc4_i2c_transfer()
262 k_sem_give(&data->operation_sem); in ifx_xmc4_i2c_transfer()
263 return -EIO; in ifx_xmc4_i2c_transfer()
266 XMC_I2C_CH_ClearStatusFlag(config->i2c, in ifx_xmc4_i2c_transfer()
271 XMC_I2C_CH_GetReceivedData(config->i2c); in ifx_xmc4_i2c_transfer()
277 XMC_I2C_CH_MasterStop(config->i2c); in ifx_xmc4_i2c_transfer()
282 k_sem_give(&data->operation_sem); in ifx_xmc4_i2c_transfer()
288 struct ifx_xmc4_i2c_data *data = dev->data; in ifx_xmc4_i2c_init() local
289 const struct ifx_xmc4_i2c_config *config = dev->config; in ifx_xmc4_i2c_init()
293 ret = k_sem_init(&data->operation_sem, 1, 1); in ifx_xmc4_i2c_init()
298 ret = k_sem_init(&data->target_sem, 1, 1); in ifx_xmc4_i2c_init()
304 return pinctrl_apply_state(config->pcfg, PINCTRL_STATE_DEFAULT); in ifx_xmc4_i2c_init()
309 struct ifx_xmc4_i2c_data *data = dev->data; in ifx_xmc4_i2c_target_register() local
310 const struct ifx_xmc4_i2c_config *config = dev->config; in ifx_xmc4_i2c_target_register()
314 !cfg->callbacks->read_requested || in ifx_xmc4_i2c_target_register()
315 !cfg->callbacks->read_processed || in ifx_xmc4_i2c_target_register()
316 !cfg->callbacks->write_requested || in ifx_xmc4_i2c_target_register()
317 !cfg->callbacks->write_received || in ifx_xmc4_i2c_target_register()
318 !cfg->callbacks->stop) { in ifx_xmc4_i2c_target_register()
319 return -EINVAL; in ifx_xmc4_i2c_target_register()
322 if (cfg->flags & I2C_TARGET_FLAGS_ADDR_10_BITS) { in ifx_xmc4_i2c_target_register()
323 return -ENOTSUP; in ifx_xmc4_i2c_target_register()
327 if (k_sem_take(&data->target_sem, K_FOREVER)) { in ifx_xmc4_i2c_target_register()
328 return -EIO; in ifx_xmc4_i2c_target_register()
331 data->p_target_config = cfg; in ifx_xmc4_i2c_target_register()
332 data->cfg.address = cfg->address << 1; in ifx_xmc4_i2c_target_register()
334 if (data->is_configured) { in ifx_xmc4_i2c_target_register()
335 uint32_t bitrate; in ifx_xmc4_i2c_target_register() local
337 bitrate = I2C_SPEED_GET(data->dev_config); in ifx_xmc4_i2c_target_register()
338 bitrate_cfg = i2c_map_dt_bitrate(bitrate); in ifx_xmc4_i2c_target_register()
340 bitrate_cfg = i2c_map_dt_bitrate(config->bitrate); in ifx_xmc4_i2c_target_register()
345 k_sem_give(&data->target_sem); in ifx_xmc4_i2c_target_register()
346 return -EIO; in ifx_xmc4_i2c_target_register()
349 k_sem_give(&data->target_sem); in ifx_xmc4_i2c_target_register()
355 struct ifx_xmc4_i2c_data *data = dev->data; in ifx_xmc4_i2c_target_unregister() local
356 const struct ifx_xmc4_i2c_config *config = dev->config; in ifx_xmc4_i2c_target_unregister()
359 if (k_sem_take(&data->operation_sem, K_FOREVER)) { in ifx_xmc4_i2c_target_unregister()
360 return -EIO; in ifx_xmc4_i2c_target_unregister()
363 data->p_target_config = NULL; in ifx_xmc4_i2c_target_unregister()
364 XMC_I2C_CH_DisableEvent(config->i2c, I2C_XMC_EVENTS_MASK); in ifx_xmc4_i2c_target_unregister()
367 k_sem_give(&data->operation_sem); in ifx_xmc4_i2c_target_unregister()
374 struct ifx_xmc4_i2c_data *data = dev->data; in i2c_xmc4_isr() local
375 const struct ifx_xmc4_i2c_config *config = dev->config; in i2c_xmc4_isr()
376 const struct i2c_target_callbacks *callbacks = data->p_target_config->callbacks; in i2c_xmc4_isr()
377 uint32_t status = XMC_I2C_CH_GetStatusFlag(config->i2c); in i2c_xmc4_isr()
380 XMC_I2C_CH_ClearStatusFlag(config->i2c, status); in i2c_xmc4_isr()
384 XMC_USIC_CH_SetTransmitBufferStatus(config->i2c, in i2c_xmc4_isr()
387 callbacks->stop(data->p_target_config); in i2c_xmc4_isr()
391 if (!data->ignore_slave_select && (status & XMC_I2C_CH_STATUS_FLAG_SLAVE_SELECT)) { in i2c_xmc4_isr()
392 data->ignore_slave_select = true; in i2c_xmc4_isr()
396 callbacks->read_requested(data->p_target_config, in i2c_xmc4_isr()
397 &data->target_wr_byte); in i2c_xmc4_isr()
398 XMC_I2C_CH_SlaveTransmit(config->i2c, data->target_wr_byte); in i2c_xmc4_isr()
400 callbacks->write_requested(data->p_target_config); in i2c_xmc4_isr()
406 callbacks->read_processed(data->p_target_config, &data->target_wr_byte); in i2c_xmc4_isr()
407 XMC_I2C_CH_SlaveTransmit(config->i2c, data->target_wr_byte); in i2c_xmc4_isr()
413 callbacks->write_received(data->p_target_config, in i2c_xmc4_isr()
414 XMC_I2C_CH_GetReceivedData(config->i2c)); in i2c_xmc4_isr()
419 data->ignore_slave_select = false; in i2c_xmc4_isr()
422 status = XMC_I2C_CH_GetStatusFlag(config->i2c); in i2c_xmc4_isr()
443 const struct ifx_xmc4_i2c_config *config = dev->config; \
445 uint8_t service_request = (irq_num - USIC_IRQ_MIN) % IRQS_PER_USIC; \
447 XMC_I2C_CH_SelectInterruptNodePointer(config->i2c, \
449 XMC_I2C_CH_SelectInterruptNodePointer(config->i2c, \
452 XMC_I2C_CH_EnableEvent(config->i2c, I2C_XMC_EVENTS_MASK); \
473 .bitrate = DT_INST_PROP_OR(n, clock_frequency, I2C_SPEED_STANDARD), \