driver: clock_controller: return values of clock_control apis directly.

return values of clock_control_on()/clock_control_get_rate() directly in
case overwriting error codes.

Signed-off-by: Mulin Chao <MLChao@nuvoton.com>
This commit is contained in:
Mulin Chao 2020-10-14 11:47:20 +08:00 committed by Anas Nashif
commit 507f31472c
7 changed files with 57 additions and 35 deletions

View file

@ -294,20 +294,25 @@ static int uart_npcx_init(const struct device *dev)
const struct device *const clk_dev =
device_get_binding(NPCX_CLK_CTRL_NAME);
uint32_t uart_rate;
int ret;
/* Turn on device clock first */
if (clock_control_on(clk_dev,
(clock_control_subsys_t *) &config->clk_cfg) != 0) {
return -EIO;
/* 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) {
LOG_ERR("Turn on UART clock fail %d", ret);
return ret;
}
/*
* If apb2's clock is not 15MHz, we need to find the other optimized
* values of UPSR and UBAUD for baud rate 115200.
*/
if (clock_control_get_rate(clk_dev,
(clock_control_subsys_t *) &config->clk_cfg, &uart_rate) < 0) {
LOG_ERR("UART clock rate get error.");
ret = clock_control_get_rate(clk_dev, (clock_control_subsys_t *)
&config->clk_cfg, &uart_rate);
if (ret < 0) {
LOG_ERR("Get UART clock rate error %d", ret);
return ret;
}
__ASSERT(uart_rate == 15000000, "Unsupported apb2 clock for UART!");