drivers: i2c: check if clock device is ready before accessing
Add check for device_is_ready() before accessing clock control devices. Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
This commit is contained in:
parent
9c71615f83
commit
e84636d010
|
@ -680,6 +680,11 @@ static int IRAM_ATTR i2c_esp32_init(const struct device *dev)
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (!device_is_ready(config->clock_dev)) {
|
||||
LOG_ERR("clock control device not ready");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
clock_control_on(config->clock_dev, config->clock_subsys);
|
||||
|
||||
esp_intr_alloc(config->irq_source, 0, i2c_esp32_isr, (void *)dev, NULL);
|
||||
|
|
|
@ -223,6 +223,11 @@ static int i2c_stm32_init(const struct device *dev)
|
|||
*/
|
||||
k_sem_init(&data->bus_mutex, 1, 1);
|
||||
|
||||
if (!device_is_ready(clock)) {
|
||||
LOG_ERR("clock control device not ready");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
if (clock_control_on(clock,
|
||||
(clock_control_subsys_t *) &cfg->pclken) != 0) {
|
||||
LOG_ERR("i2c: failure enabling clock");
|
||||
|
|
|
@ -314,6 +314,10 @@ static int lpc11u6x_i2c_init(const struct device *dev)
|
|||
return err;
|
||||
}
|
||||
|
||||
if (!device_is_ready(cfg->clock_dev)) {
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
/* Configure clock and de-assert reset for I2Cx */
|
||||
clock_control_on(cfg->clock_dev, (clock_control_subsys_t) cfg->clkid);
|
||||
|
||||
|
|
|
@ -335,6 +335,11 @@ static int mcux_flexcomm_init(const struct device *dev)
|
|||
|
||||
k_sem_init(&data->device_sync_sem, 0, K_SEM_MAX_LIMIT);
|
||||
|
||||
if (!device_is_ready(config->clock_dev)) {
|
||||
LOG_ERR("clock control device not ready");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
/* Get the clock frequency */
|
||||
if (clock_control_get_rate(config->clock_dev, config->clock_subsys,
|
||||
&clock_freq)) {
|
||||
|
|
|
@ -315,6 +315,12 @@ static int mcux_lpi2c_init(const struct device *dev)
|
|||
|
||||
k_sem_init(&data->lock, 1, 1);
|
||||
k_sem_init(&data->device_sync_sem, 0, K_SEM_MAX_LIMIT);
|
||||
|
||||
if (!device_is_ready(config->clock_dev)) {
|
||||
LOG_ERR("clock control device not ready");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
if (clock_control_get_rate(config->clock_dev, config->clock_subsys,
|
||||
&clock_freq)) {
|
||||
return -EINVAL;
|
||||
|
|
|
@ -909,6 +909,11 @@ static int i2c_ctrl_init(const struct device *dev)
|
|||
const struct device *const clk_dev = DEVICE_DT_GET(NPCX_CLK_CTRL_NODE);
|
||||
uint32_t i2c_rate;
|
||||
|
||||
if (!device_is_ready(clk_dev)) {
|
||||
LOG_ERR("clock control device not ready");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
/* Turn on device clock first and get source clock freq. */
|
||||
if (clock_control_on(clk_dev,
|
||||
(clock_control_subsys_t *) &config->clk_cfg) != 0) {
|
||||
|
|
|
@ -321,6 +321,10 @@ static int i2c_rcar_init(const struct device *dev)
|
|||
|
||||
k_sem_init(&data->int_sem, 0, 1);
|
||||
|
||||
if (!device_is_ready(config->clock_dev)) {
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
ret = clock_control_on(config->clock_dev,
|
||||
(clock_control_subsys_t *)&config->mod_clk);
|
||||
|
||||
|
|
|
@ -217,6 +217,11 @@ static int rv32m1_lpi2c_init(const struct device *dev)
|
|||
|
||||
CLOCK_SetIpSrc(config->clock_ip_name, config->clock_ip_src);
|
||||
|
||||
if (!device_is_ready(config->clock_dev)) {
|
||||
LOG_ERR("clock control device not ready");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
err = clock_control_on(config->clock_dev, config->clock_subsys);
|
||||
if (err) {
|
||||
LOG_ERR("Could not turn on clock (err %d)", err);
|
||||
|
|
Loading…
Reference in a new issue