drivers: pwm: 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
9c626a07d4
commit
c8a5d058aa
9 changed files with 45 additions and 0 deletions
|
@ -303,6 +303,11 @@ int pwm_led_esp32_init(const struct device *dev)
|
|||
const struct pwm_ledc_esp32_config *config = dev->config;
|
||||
struct pwm_ledc_esp32_data *data = (struct pwm_ledc_esp32_data *const)(dev)->data;
|
||||
|
||||
if (!device_is_ready(config->clock_dev)) {
|
||||
LOG_ERR("clock control device not ready");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
/* Enable peripheral */
|
||||
clock_control_on(config->clock_dev, config->clock_subsys);
|
||||
|
||||
|
|
|
@ -413,6 +413,11 @@ int mcpwm_esp32_init(const struct device *dev)
|
|||
struct mcpwm_esp32_data *data = (struct mcpwm_esp32_data *const)(dev)->data;
|
||||
struct mcpwm_esp32_channel_config *channel;
|
||||
|
||||
if (!device_is_ready(config->clock_dev)) {
|
||||
LOG_ERR("clock control device not ready");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
/* Enable peripheral */
|
||||
ret = clock_control_on(config->clock_dev, config->clock_subsys);
|
||||
if (ret < 0) {
|
||||
|
|
|
@ -137,6 +137,11 @@ static int pwm_mcux_init(const struct device *dev)
|
|||
status_t status;
|
||||
int i, err;
|
||||
|
||||
if (!device_is_ready(config->clock_dev)) {
|
||||
LOG_ERR("clock control device not ready");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
err = pinctrl_apply_state(config->pincfg, PINCTRL_STATE_DEFAULT);
|
||||
if (err < 0) {
|
||||
return err;
|
||||
|
|
|
@ -404,6 +404,11 @@ static int mcux_ftm_init(const struct device *dev)
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
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,
|
||||
&data->clock_freq)) {
|
||||
LOG_ERR("Could not get clock frequency");
|
||||
|
|
|
@ -283,6 +283,11 @@ static int mcux_pwt_init(const struct device *dev)
|
|||
pwt_config_t *pwt_config = &data->pwt_config;
|
||||
int err;
|
||||
|
||||
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,
|
||||
&data->clock_freq)) {
|
||||
LOG_ERR("could not get clock frequency");
|
||||
|
|
|
@ -142,6 +142,11 @@ static int mcux_tpm_init(const struct device *dev)
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (!device_is_ready(config->clock_dev)) {
|
||||
LOG_ERR("clock control device not ready");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
if (clock_control_on(config->clock_dev, config->clock_subsys)) {
|
||||
LOG_ERR("Could not turn on clock");
|
||||
return -EINVAL;
|
||||
|
|
|
@ -183,6 +183,11 @@ static int pwm_npcx_init(const struct device *dev)
|
|||
NPCX_REG_WORD_ACCESS_CHECK(inst->PRSC, 0xA55A);
|
||||
|
||||
|
||||
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. */
|
||||
ret = clock_control_on(clk_dev, (clock_control_subsys_t *)
|
||||
&config->clk_cfg);
|
||||
|
|
|
@ -147,6 +147,11 @@ static int rv32m1_tpm_init(const struct device *dev)
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (!device_is_ready(config->clock_dev)) {
|
||||
LOG_ERR("clock control device not ready");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
if (clock_control_on(config->clock_dev, config->clock_subsys)) {
|
||||
LOG_ERR("Could not turn on clock");
|
||||
return -EINVAL;
|
||||
|
|
|
@ -636,6 +636,11 @@ static int pwm_stm32_init(const struct device *dev)
|
|||
/* enable clock and store its speed */
|
||||
clk = DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE);
|
||||
|
||||
if (!device_is_ready(clk)) {
|
||||
LOG_ERR("clock control device not ready");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
r = clock_control_on(clk, (clock_control_subsys_t *)&cfg->pclken);
|
||||
if (r < 0) {
|
||||
LOG_ERR("Could not initialize clock (%d)", r);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue