Lines Matching +full:validity +full:- +full:control
5 * SPDX-License-Identifier: Apache-2.0
32 #include "i2c-priv.h"
50 struct i2c_stm32_data *data = dev->data; in i2c_stm32_get_config()
52 if (!data->is_configured) { in i2c_stm32_get_config()
54 return -EIO; in i2c_stm32_get_config()
57 *config = data->dev_config; in i2c_stm32_get_config()
64 if (data->current_timing.i2c_speed == 100000) { in i2c_stm32_get_config()
66 data->current_timing.periph_clock, in i2c_stm32_get_config()
67 data->current_timing.timing_setting); in i2c_stm32_get_config()
68 } else if (data->current_timing.i2c_speed == 400000) { in i2c_stm32_get_config()
70 data->current_timing.periph_clock, in i2c_stm32_get_config()
71 data->current_timing.timing_setting); in i2c_stm32_get_config()
72 } else if (data->current_timing.i2c_speed == 1000000) { in i2c_stm32_get_config()
74 data->current_timing.periph_clock, in i2c_stm32_get_config()
75 data->current_timing.timing_setting); in i2c_stm32_get_config()
84 const struct i2c_stm32_config *cfg = dev->config; in i2c_stm32_runtime_configure()
85 struct i2c_stm32_data *data = dev->data; in i2c_stm32_runtime_configure()
87 I2C_TypeDef *i2c = cfg->i2c; in i2c_stm32_runtime_configure()
91 if (IS_ENABLED(STM32_I2C_DOMAIN_CLOCK_SUPPORT) && (cfg->pclk_len > 1)) { in i2c_stm32_runtime_configure()
92 if (clock_control_get_rate(clk, (clock_control_subsys_t)&cfg->pclken[1], in i2c_stm32_runtime_configure()
95 return -EIO; in i2c_stm32_runtime_configure()
98 if (clock_control_get_rate(clk, (clock_control_subsys_t)&cfg->pclken[0], in i2c_stm32_runtime_configure()
101 return -EIO; in i2c_stm32_runtime_configure()
105 data->dev_config = config; in i2c_stm32_runtime_configure()
107 k_sem_take(&data->bus_mutex, K_FOREVER); in i2c_stm32_runtime_configure()
110 ret = clock_control_on(clk, (clock_control_subsys_t)&cfg->pclken[0]); in i2c_stm32_runtime_configure()
119 i2c_stm32_set_smbus_mode(dev, data->mode); in i2c_stm32_runtime_configure()
123 if (data->smbalert_active) { in i2c_stm32_runtime_configure()
128 ret = clock_control_off(clk, (clock_control_subsys_t)&cfg->pclken[0]); in i2c_stm32_runtime_configure()
135 k_sem_give(&data->bus_mutex); in i2c_stm32_runtime_configure()
140 #define OPERATION(msg) (((struct i2c_msg *) msg)->flags & I2C_MSG_RW_MASK)
145 struct i2c_stm32_data *data = dev->data; in i2c_stm32_transfer()
149 /* Check for validity of all messages, to prevent having to abort in i2c_stm32_transfer()
158 current->flags |= I2C_MSG_RESTART; in i2c_stm32_transfer()
170 if (!(next->flags & I2C_MSG_RESTART)) { in i2c_stm32_transfer()
171 ret = -EINVAL; in i2c_stm32_transfer()
177 if (current->flags & I2C_MSG_STOP) { in i2c_stm32_transfer()
178 ret = -EINVAL; in i2c_stm32_transfer()
191 k_sem_take(&data->bus_mutex, K_FOREVER); in i2c_stm32_transfer()
208 next_msg_flags = &(next->flags); in i2c_stm32_transfer()
215 num_msgs--; in i2c_stm32_transfer()
224 k_sem_give(&data->bus_mutex); in i2c_stm32_transfer()
234 gpio_pin_set_dt(&config->scl, state); in i2c_stm32_bitbang_set_scl()
241 gpio_pin_set_dt(&config->sda, state); in i2c_stm32_bitbang_set_sda()
248 return gpio_pin_get_dt(&config->sda) == 0 ? 0 : 1; in i2c_stm32_bitbang_get_sda()
253 const struct i2c_stm32_config *config = dev->config; in i2c_stm32_recover_bus()
254 struct i2c_stm32_data *data = dev->data; in i2c_stm32_recover_bus()
266 if (!gpio_is_ready_dt(&config->scl)) { in i2c_stm32_recover_bus()
268 return -EIO; in i2c_stm32_recover_bus()
271 if (!gpio_is_ready_dt(&config->sda)) { in i2c_stm32_recover_bus()
273 return -EIO; in i2c_stm32_recover_bus()
276 k_sem_take(&data->bus_mutex, K_FOREVER); in i2c_stm32_recover_bus()
278 error = gpio_pin_configure_dt(&config->scl, GPIO_OUTPUT_HIGH); in i2c_stm32_recover_bus()
284 error = gpio_pin_configure_dt(&config->sda, GPIO_OUTPUT_HIGH); in i2c_stm32_recover_bus()
292 bitrate_cfg = i2c_map_dt_bitrate(config->bitrate) | I2C_MODE_CONTROLLER; in i2c_stm32_recover_bus()
305 (void)pinctrl_apply_state(config->pcfg, PINCTRL_STATE_DEFAULT); in i2c_stm32_recover_bus()
307 k_sem_give(&data->bus_mutex); in i2c_stm32_recover_bus()
334 const struct i2c_stm32_config *cfg = dev->config; in i2c_stm32_suspend()
338 ret = clock_control_off(clk, (clock_control_subsys_t)&cfg->pclken[0]); in i2c_stm32_suspend()
345 ret = pinctrl_apply_state(cfg->pcfg, PINCTRL_STATE_SLEEP); in i2c_stm32_suspend()
346 if (ret == -ENOENT) { in i2c_stm32_suspend()
361 const struct i2c_stm32_config *cfg = dev->config; in i2c_stm32_activate()
365 ret = pinctrl_apply_state(cfg->pcfg, PINCTRL_STATE_DEFAULT); in i2c_stm32_activate()
373 (clock_control_subsys_t) &cfg->pclken[0]) != 0) { in i2c_stm32_activate()
375 return -EIO; in i2c_stm32_activate()
385 const struct i2c_stm32_config *cfg = dev->config; in i2c_stm32_init()
388 struct i2c_stm32_data *data = dev->data; in i2c_stm32_init()
390 k_sem_init(&data->device_sync_sem, 0, K_SEM_MAX_LIMIT); in i2c_stm32_init()
391 cfg->irq_config_func(dev); in i2c_stm32_init()
394 data->is_configured = false; in i2c_stm32_init()
395 data->mode = I2CSTM32MODE_I2C; in i2c_stm32_init()
402 k_sem_init(&data->bus_mutex, 1, 1); in i2c_stm32_init()
405 LOG_ERR("clock control device not ready"); in i2c_stm32_init()
406 return -ENODEV; in i2c_stm32_init()
411 if (IS_ENABLED(STM32_I2C_DOMAIN_CLOCK_SUPPORT) && (cfg->pclk_len > 1)) { in i2c_stm32_init()
414 (clock_control_subsys_t) &cfg->pclken[1], in i2c_stm32_init()
417 return -EIO; in i2c_stm32_init()
427 I2C_TypeDef *i2c = cfg->i2c; in i2c_stm32_init()
433 bitrate_cfg = i2c_map_dt_bitrate(cfg->bitrate); in i2c_stm32_init()
445 data->is_configured = true; in i2c_stm32_init()
464 return -ENOTSUP; in i2c_stm32_pm_action()
476 struct i2c_stm32_data *data = dev->data; in i2c_stm32_smbalert_set_callback()
478 data->smbalert_cb_func = func; in i2c_stm32_smbalert_set_callback()
479 data->smbalert_cb_dev = cb_dev; in i2c_stm32_smbalert_set_callback()
486 const struct i2c_stm32_config *cfg = dev->config; in i2c_stm32_set_smbus_mode()
487 struct i2c_stm32_data *data = dev->data; in i2c_stm32_set_smbus_mode()
488 I2C_TypeDef *i2c = cfg->i2c; in i2c_stm32_set_smbus_mode()
490 data->mode = mode; in i2c_stm32_set_smbus_mode()
508 LOG_ERR("%s: invalid mode %i", dev->name, mode); in i2c_stm32_set_smbus_mode()
517 struct i2c_stm32_data *data = dev->data; in i2c_stm32_smbalert_enable()
518 const struct i2c_stm32_config *cfg = dev->config; in i2c_stm32_smbalert_enable()
520 data->smbalert_active = true; in i2c_stm32_smbalert_enable()
521 LL_I2C_EnableSMBusAlert(cfg->i2c); in i2c_stm32_smbalert_enable()
522 LL_I2C_EnableIT_ERR(cfg->i2c); in i2c_stm32_smbalert_enable()
523 LL_I2C_Enable(cfg->i2c); in i2c_stm32_smbalert_enable()
528 struct i2c_stm32_data *data = dev->data; in i2c_stm32_smbalert_disable()
529 const struct i2c_stm32_config *cfg = dev->config; in i2c_stm32_smbalert_disable()
531 data->smbalert_active = false; in i2c_stm32_smbalert_disable()
532 LL_I2C_DisableSMBusAlert(cfg->i2c); in i2c_stm32_smbalert_disable()
533 LL_I2C_DisableIT_ERR(cfg->i2c); in i2c_stm32_smbalert_disable()
534 LL_I2C_Disable(cfg->i2c); in i2c_stm32_smbalert_disable()