drivers: can: 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
68230cb1a7
commit
035c7d2190
6 changed files with 35 additions and 3 deletions
|
@ -67,13 +67,22 @@ static int can_esp32_twai_init(const struct device *dev)
|
|||
const struct can_esp32_twai_config *twai_config = sja1000_config->custom;
|
||||
int err;
|
||||
|
||||
if (!device_is_ready(twai_config->clock_dev)) {
|
||||
LOG_ERR("clock control device not ready");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
err = pinctrl_apply_state(twai_config->pcfg, PINCTRL_STATE_DEFAULT);
|
||||
if (err != 0) {
|
||||
LOG_ERR("failed to configure TWAI pins (err %d)", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
clock_control_on(twai_config->clock_dev, twai_config->clock_subsys);
|
||||
err = clock_control_on(twai_config->clock_dev, twai_config->clock_subsys);
|
||||
if (err != 0) {
|
||||
LOG_ERR("failed to enable CAN clock (err %d)", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
err = can_sja1000_init(dev);
|
||||
if (err != 0) {
|
||||
|
|
|
@ -46,6 +46,11 @@ static int mcux_mcan_init(const struct device *dev)
|
|||
const struct mcux_mcan_config *mcux_config = mcan_config->custom;
|
||||
int err;
|
||||
|
||||
if (!device_is_ready(mcux_config->clock_dev)) {
|
||||
LOG_ERR("clock control device not ready");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_PINCTRL
|
||||
err = pinctrl_apply_state(mcux_config->pincfg, PINCTRL_STATE_DEFAULT);
|
||||
if (err) {
|
||||
|
|
|
@ -941,6 +941,11 @@ static int can_rcar_init(const struct device *dev)
|
|||
}
|
||||
}
|
||||
|
||||
if (!device_is_ready(config->clock_dev)) {
|
||||
LOG_ERR("clock control device not ready");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
/* Configure dt provided device signals when available */
|
||||
ret = pinctrl_apply_state(config->pcfg, PINCTRL_STATE_DEFAULT);
|
||||
if (ret < 0) {
|
||||
|
|
|
@ -520,6 +520,10 @@ static int can_stm32_init(const struct device *dev)
|
|||
}
|
||||
|
||||
clock = DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE);
|
||||
if (!device_is_ready(clock)) {
|
||||
LOG_ERR("clock control device not ready");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
ret = clock_control_on(clock, (clock_control_subsys_t *) &cfg->pclken);
|
||||
if (ret != 0) {
|
||||
|
|
|
@ -72,6 +72,7 @@ static int can_stm32fd_clock_enable(const struct device *dev)
|
|||
int ret;
|
||||
const struct can_mcan_config *mcan_cfg = dev->config;
|
||||
const struct can_stm32fd_config *stm32fd_cfg = mcan_cfg->custom;
|
||||
const struct device *clk = DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE);
|
||||
|
||||
LL_RCC_SetFDCANClockSource(CAN_STM32FD_CLOCK_SOURCE);
|
||||
|
||||
|
@ -82,8 +83,11 @@ static int can_stm32fd_clock_enable(const struct device *dev)
|
|||
LL_RCC_PLL2_EnableDomain_SAI();
|
||||
#endif
|
||||
|
||||
ret = clock_control_on(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE),
|
||||
(clock_control_subsys_t *)&stm32fd_cfg->pclken);
|
||||
if (!device_is_ready(clk)) {
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
ret = clock_control_on(clk, (clock_control_subsys_t *)&stm32fd_cfg->pclken);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -52,6 +52,11 @@ static int can_stm32h7_clock_enable(const struct device *dev)
|
|||
|
||||
LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PLL1Q);
|
||||
|
||||
if (!device_is_ready(clk)) {
|
||||
LOG_ERR("clock control device not ready");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
ret = clock_control_on(clk, (clock_control_subsys_t *)&stm32h7_cfg->pclken);
|
||||
if (ret != 0) {
|
||||
LOG_ERR("failure enabling clock");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue