drivers: serial: 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
78dd25e79e
commit
9456eca5c0
13 changed files with 52 additions and 1 deletions
|
@ -75,6 +75,10 @@ static int serial_esp32_usb_init(const struct device *dev)
|
|||
const struct serial_esp32_usb_config *config = dev->config;
|
||||
struct serial_esp32_usb_data *data = dev->data;
|
||||
|
||||
if (!device_is_ready(config->clock_dev)) {
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
int ret = clock_control_on(config->clock_dev, config->clock_subsys);
|
||||
|
||||
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
||||
|
|
|
@ -201,6 +201,10 @@ static int uart_esp32_configure(const struct device *dev, const struct uart_conf
|
|||
return ret;
|
||||
}
|
||||
|
||||
if (!device_is_ready(config->clock_dev)) {
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
clock_control_on(config->clock_dev, config->clock_subsys);
|
||||
|
||||
uart_hal_set_sclk(&data->hal, UART_SCLK_APB);
|
||||
|
|
|
@ -347,6 +347,10 @@ static int lpc11u6x_uart0_init(const struct device *dev)
|
|||
return err;
|
||||
}
|
||||
|
||||
if (!device_is_ready(cfg->clock_dev)) {
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
clock_control_on(cfg->clock_dev, (clock_control_subsys_t) cfg->clkid);
|
||||
|
||||
/* Configure baudrate, parity and stop bits */
|
||||
|
|
|
@ -46,6 +46,10 @@ static int uart_mcux_configure(const struct device *dev,
|
|||
uint32_t clock_freq;
|
||||
status_t retval;
|
||||
|
||||
if (!device_is_ready(config->clock_dev)) {
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
if (clock_control_get_rate(config->clock_dev, config->clock_subsys,
|
||||
&clock_freq)) {
|
||||
return -EINVAL;
|
||||
|
|
|
@ -265,6 +265,10 @@ static int mcux_flexcomm_init(const struct device *dev)
|
|||
}
|
||||
#endif /* CONFIG_PINCTRL */
|
||||
|
||||
if (!device_is_ready(config->clock_dev)) {
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
/* Get the clock frequency */
|
||||
if (clock_control_get_rate(config->clock_dev, config->clock_subsys,
|
||||
&clock_freq)) {
|
||||
|
|
|
@ -227,6 +227,10 @@ static int mcux_iuart_init(const struct device *dev)
|
|||
uint32_t clock_freq;
|
||||
int err;
|
||||
|
||||
if (!device_is_ready(config->clock_dev)) {
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
if (clock_control_get_rate(config->clock_dev, config->clock_subsys,
|
||||
&clock_freq)) {
|
||||
return -EINVAL;
|
||||
|
|
|
@ -241,6 +241,10 @@ static int mcux_lpsci_init(const struct device *dev)
|
|||
uint32_t clock_freq;
|
||||
int err;
|
||||
|
||||
if (!device_is_ready(config->clock_dev)) {
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
if (clock_control_get_rate(config->clock_dev, config->clock_subsys,
|
||||
&clock_freq)) {
|
||||
return -EINVAL;
|
||||
|
|
|
@ -883,6 +883,10 @@ static int mcux_lpuart_configure_init(const struct device *dev, const struct uar
|
|||
struct mcux_lpuart_data *data = dev->data;
|
||||
uint32_t clock_freq;
|
||||
|
||||
if (!device_is_ready(config->clock_dev)) {
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
if (clock_control_get_rate(config->clock_dev, config->clock_subsys,
|
||||
&clock_freq)) {
|
||||
return -EINVAL;
|
||||
|
|
|
@ -434,6 +434,11 @@ static int uart_npcx_init(const struct device *dev)
|
|||
uint32_t uart_rate;
|
||||
int ret;
|
||||
|
||||
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);
|
||||
if (ret < 0) {
|
||||
|
|
|
@ -377,7 +377,7 @@ static int uart_ns16550_configure(const struct device *dev,
|
|||
if (dev_cfg->sys_clk_freq != 0U) {
|
||||
pclk = dev_cfg->sys_clk_freq;
|
||||
} else {
|
||||
if (dev_cfg->clock_dev == NULL) {
|
||||
if (!device_is_ready(dev_cfg->clock_dev)) {
|
||||
ret = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
|
|
|
@ -273,6 +273,10 @@ static int uart_rcar_init(const struct device *dev)
|
|||
return ret;
|
||||
}
|
||||
|
||||
if (!device_is_ready(config->clock_dev)) {
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
ret = clock_control_on(config->clock_dev,
|
||||
(clock_control_subsys_t *)&config->mod_clk);
|
||||
if (ret < 0) {
|
||||
|
|
|
@ -254,6 +254,10 @@ static int rv32m1_lpuart_init(const struct device *dev)
|
|||
/* TODO: Don't change if another core has configured */
|
||||
CLOCK_SetIpSrc(config->clock_ip_name, config->clock_ip_src);
|
||||
|
||||
if (!device_is_ready(config->clock_dev)) {
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
if (clock_control_get_rate(config->clock_dev, config->clock_subsys,
|
||||
&clock_freq)) {
|
||||
return -EINVAL;
|
||||
|
|
|
@ -1563,6 +1563,12 @@ static int uart_stm32_init(const struct device *dev)
|
|||
int err;
|
||||
|
||||
__uart_stm32_get_clock(dev);
|
||||
|
||||
if (!device_is_ready(data->clock)) {
|
||||
LOG_ERR("clock control device not ready");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
/* enable clock */
|
||||
err = clock_control_on(data->clock, (clock_control_subsys_t)&config->pclken[0]);
|
||||
if (err != 0) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue