drivers: spi: 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
9456eca5c0
commit
d6776fe169
6 changed files with 30 additions and 0 deletions
|
@ -164,6 +164,11 @@ static int IRAM_ATTR spi_esp32_configure(const struct device *dev,
|
|||
return 0;
|
||||
}
|
||||
|
||||
if (!device_is_ready(cfg->clock_dev)) {
|
||||
LOG_ERR("clock control device not ready");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
/* enables SPI peripheral */
|
||||
if (clock_control_on(cfg->clock_dev, cfg->clock_subsys)) {
|
||||
LOG_ERR("Could not enable SPI clock");
|
||||
|
|
|
@ -862,6 +862,11 @@ static int spi_stm32_init(const struct device *dev)
|
|||
const struct spi_stm32_config *cfg = dev->config;
|
||||
int err;
|
||||
|
||||
if (!device_is_ready(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE))) {
|
||||
LOG_ERR("clock control device not ready");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
err = clock_control_on(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE),
|
||||
(clock_control_subsys_t) &cfg->pclken[0]);
|
||||
if (err < 0) {
|
||||
|
|
|
@ -632,6 +632,11 @@ static int spi_mcux_configure(const struct device *dev,
|
|||
ctar_config->lastSckToPcsDelayInNanoSec = config->sck_pcs_delay;
|
||||
ctar_config->betweenTransferDelayInNanoSec = config->transfer_delay;
|
||||
|
||||
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;
|
||||
|
|
|
@ -202,6 +202,11 @@ static int spi_mcux_configure(const struct device *dev,
|
|||
|
||||
SPI_MasterGetDefaultConfig(&master_config);
|
||||
|
||||
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)) {
|
||||
|
|
|
@ -215,6 +215,11 @@ static int spi_mcux_configure(const struct device *dev,
|
|||
master_config.lastSckToPcsDelayInNanoSec = config->sck_pcs_delay;
|
||||
master_config.betweenTransferDelayInNanoSec = config->transfer_delay;
|
||||
|
||||
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;
|
||||
|
|
|
@ -186,6 +186,11 @@ static int spi_mcux_configure(const struct device *dev,
|
|||
|
||||
master_config.baudRate = spi_cfg->frequency;
|
||||
|
||||
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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue