Lines Matching +full:bitrate +full:- +full:data

4  * SPDX-License-Identifier: Apache-2.0
57 uint32_t bitrate; member
67 struct i2c_ra_iic_data *data = (struct i2c_ra_iic_data *const)dev->data; in i2c_ra_iic_configure() local
71 return -EIO; in i2c_ra_iic_configure()
76 data->fsp_config.rate = I2C_MASTER_RATE_STANDARD; in i2c_ra_iic_configure()
79 data->fsp_config.rate = I2C_MASTER_RATE_FAST; in i2c_ra_iic_configure()
82 data->fsp_config.rate = I2C_MASTER_RATE_FASTPLUS; in i2c_ra_iic_configure()
86 return -EIO; in i2c_ra_iic_configure()
90 calc_iic_master_clock_setting(dev, data->fsp_config.rate, in i2c_ra_iic_configure()
91 &data->iic_master_ext_cfg.clock_settings); in i2c_ra_iic_configure()
93 R_IIC_MASTER_Close(&data->ctrl); in i2c_ra_iic_configure()
94 R_IIC_MASTER_Open(&data->ctrl, &data->fsp_config); in i2c_ra_iic_configure()
97 data->dev_config = dev_config; in i2c_ra_iic_configure()
104 struct i2c_ra_iic_data *data = (struct i2c_ra_iic_data *const)dev->data; in i2c_ra_iic_get_config() local
105 *dev_config = data->dev_config; in i2c_ra_iic_get_config()
110 #define OPERATION(msg) (((struct i2c_msg *)msg)->flags & I2C_MSG_RW_MASK)
115 struct i2c_ra_iic_data *data = (struct i2c_ra_iic_data *const)dev->data; in i2c_ra_iic_transfer() local
131 current->flags |= I2C_MSG_RESTART; in i2c_ra_iic_transfer()
142 if (!(next->flags & I2C_MSG_RESTART)) { in i2c_ra_iic_transfer()
147 ret = -EIO; in i2c_ra_iic_transfer()
153 if (current->flags & I2C_MSG_STOP) { in i2c_ra_iic_transfer()
158 ret = -EIO; in i2c_ra_iic_transfer()
162 current->flags |= I2C_MSG_STOP; in i2c_ra_iic_transfer()
172 k_mutex_lock(&data->bus_mutex, K_FOREVER); in i2c_ra_iic_transfer()
178 if (I2C_MSG_ADDR_10_BITS & data->dev_config) { in i2c_ra_iic_transfer()
184 R_IIC_MASTER_SlaveAddressSet(&data->ctrl, addr, addr_mode); in i2c_ra_iic_transfer()
197 if (current->flags & I2C_MSG_READ) { in i2c_ra_iic_transfer()
199 R_IIC_MASTER_Read(&data->ctrl, current->buf, current->len, in i2c_ra_iic_transfer()
200 next != NULL && (next->flags & I2C_MSG_RESTART)); in i2c_ra_iic_transfer()
203 R_IIC_MASTER_Write(&data->ctrl, current->buf, current->len, in i2c_ra_iic_transfer()
204 next != NULL && (next->flags & I2C_MSG_RESTART)); in i2c_ra_iic_transfer()
211 "(65535) while DTC is used for data transfer.", in i2c_ra_iic_transfer()
224 ret = -EIO; in i2c_ra_iic_transfer()
229 k_sem_take(&data->complete_sem, K_FOREVER); in i2c_ra_iic_transfer()
232 switch (data->event) { in i2c_ra_iic_transfer()
235 (current->flags & I2C_MSG_READ) ? "Read" : "Write"); in i2c_ra_iic_transfer()
236 ret = -EIO; in i2c_ra_iic_transfer()
247 num_msgs--; in i2c_ra_iic_transfer()
251 k_mutex_unlock(&data->bus_mutex); in i2c_ra_iic_transfer()
258 const struct device *dev = p_args->p_context; in i2c_ra_iic_callback()
259 struct i2c_ra_iic_data *data = dev->data; in i2c_ra_iic_callback() local
261 data->event = p_args->event; in i2c_ra_iic_callback()
263 k_sem_give(&data->complete_sem); in i2c_ra_iic_callback()
268 const struct i2c_ra_iic_config *config = dev->config; in i2c_ra_iic_init()
269 struct i2c_ra_iic_data *data = (struct i2c_ra_iic_data *)dev->data; in i2c_ra_iic_init() local
274 ret = pinctrl_apply_state(config->pcfg, PINCTRL_STATE_DEFAULT); in i2c_ra_iic_init()
281 k_mutex_init(&data->bus_mutex); in i2c_ra_iic_init()
282 k_sem_init(&data->complete_sem, 0, 1); in i2c_ra_iic_init()
284 switch (data->fsp_config.rate) { in i2c_ra_iic_init()
288 calc_iic_master_clock_setting(dev, data->fsp_config.rate, in i2c_ra_iic_init()
289 &data->iic_master_ext_cfg.clock_settings); in i2c_ra_iic_init()
290 data->iic_master_ext_cfg.timeout_mode = IIC_MASTER_TIMEOUT_MODE_SHORT; in i2c_ra_iic_init()
291 data->iic_master_ext_cfg.timeout_scl_low = IIC_MASTER_TIMEOUT_SCL_LOW_ENABLED; in i2c_ra_iic_init()
293 data->fsp_config.p_extend = &data->iic_master_ext_cfg; in i2c_ra_iic_init()
296 LOG_ERR("%s: Invalid I2C speed rate: %d", __func__, data->fsp_config.rate); in i2c_ra_iic_init()
297 return -ENOTSUP; in i2c_ra_iic_init()
300 fsp_err = R_IIC_MASTER_Open(&data->ctrl, &data->fsp_config); in i2c_ra_iic_init()
304 config->irq_config_func(dev); in i2c_ra_iic_init()
313 const uint32_t noise_filter_stage = config->noise_filter_stage; in calc_iic_master_bitrate()
314 const double rise_time_s = config->rise_time_s; in calc_iic_master_bitrate()
315 const double fall_time_s = config->fall_time_s; in calc_iic_master_bitrate()
316 const uint32_t requested_duty = config->duty_cycle_percent; in calc_iic_master_bitrate()
330 /* Converts all divided numbers to double to avoid data loss. */ in calc_iic_master_bitrate()
333 result->bitrate = in calc_iic_master_bitrate()
335 result->duty = in calc_iic_master_bitrate()
339 result->divider = divider; in calc_iic_master_bitrate()
340 result->brh = brh; in calc_iic_master_bitrate()
341 result->brl = total_brl_brh - brh; in calc_iic_master_bitrate()
342 result->duty_error_percent = in calc_iic_master_bitrate()
343 (result->duty > requested_duty ? result->duty - requested_duty in calc_iic_master_bitrate()
344 : requested_duty - result->duty) / in calc_iic_master_bitrate()
348 " [output] bitrate[%u] duty[%u] divider[%u] brh[%u] brl[%u] " in calc_iic_master_bitrate()
350 __func__, total_brl_brh, brh, divider, result->bitrate, result->duty, in calc_iic_master_bitrate()
351 result->divider, result->brh, result->brl, result->duty_error_percent); in calc_iic_master_bitrate()
357 const struct i2c_ra_iic_config *config = dev->config; in calc_iic_master_clock_setting()
358 const uint32_t noise_filter_stage = config->noise_filter_stage; in calc_iic_master_clock_setting()
359 const double rise_time_s = config->rise_time_s; in calc_iic_master_clock_setting()
360 const double fall_time_s = config->fall_time_s; in calc_iic_master_clock_setting()
361 const uint32_t requested_duty = config->duty_cycle_percent; in calc_iic_master_clock_setting()
377 /* Start with maximum possible bitrate. */ in calc_iic_master_clock_setting()
380 struct ra_iic_master_bitrate bitrate = {}; in calc_iic_master_clock_setting() local
382 calc_iic_master_bitrate(config, min_brl_brh, min_brh, 0, &bitrate); in calc_iic_master_clock_setting()
394 /* If the requested bitrate cannot be achieved with this divider, continue. in calc_iic_master_clock_setting()
398 ceil(((1 / (double)requested_bitrate) - (rise_time_s + fall_time_s)) * in calc_iic_master_clock_setting()
399 divided_pclk - in calc_iic_master_clock_setting()
412 /* Calculate the actual bitrate and duty cycle. */ in calc_iic_master_clock_setting()
422 temp_brh -= 1; in calc_iic_master_clock_setting()
424 if ((temp_brh < min_brh) || ((total_brl_brh - temp_brh) > 31)) { in calc_iic_master_clock_setting()
445 ((total_brl_brh - temp_brh) < min_brh)) { in calc_iic_master_clock_setting()
463 bitrate = temp_bitrate; in calc_iic_master_clock_setting()
468 clk_cfg->brl_value = bitrate.brl; in calc_iic_master_clock_setting()
469 clk_cfg->brh_value = bitrate.brh; in calc_iic_master_clock_setting()
470 clk_cfg->cks_value = bitrate.divider; in calc_iic_master_clock_setting()
473 clk_cfg->brl_value, clk_cfg->brh_value, clk_cfg->cks_value); in calc_iic_master_clock_setting()
498 R_ICU->IELSR[DT_INST_IRQ_BY_NAME(index, rxi, irq)] = \
500 R_ICU->IELSR[DT_INST_IRQ_BY_NAME(index, txi, irq)] = \
502 R_ICU->IELSR[DT_INST_IRQ_BY_NAME(index, tei, irq)] = \
504 R_ICU->IELSR[DT_INST_IRQ_BY_NAME(index, eri, irq)] = \