Commit a8afc193 authored by Andy Shevchenko's avatar Andy Shevchenko Committed by Greg Kroah-Hartman

serial: 8250_dw: Use devm_clk_get_optional() to get the input clock

Simplify the code which fetches the input clock by using
devm_clk_get_optional(). This comes with a small functional change: previously
all errors were ignored except deferred probe. Now all errors are
treated as errors. If no input clock is present devm_clk_get_optional() will
return NULL instead of an error which matches the behavior of the old code.
Signed-off-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20190925162617.30368-1-andriy.shevchenko@linux.intel.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 254cc774
...@@ -280,9 +280,6 @@ static void dw8250_set_termios(struct uart_port *p, struct ktermios *termios, ...@@ -280,9 +280,6 @@ static void dw8250_set_termios(struct uart_port *p, struct ktermios *termios,
long rate; long rate;
int ret; int ret;
if (IS_ERR(d->clk))
goto out;
clk_disable_unprepare(d->clk); clk_disable_unprepare(d->clk);
rate = clk_round_rate(d->clk, baud * 16); rate = clk_round_rate(d->clk, baud * 16);
if (rate < 0) if (rate < 0)
...@@ -293,7 +290,9 @@ static void dw8250_set_termios(struct uart_port *p, struct ktermios *termios, ...@@ -293,7 +290,9 @@ static void dw8250_set_termios(struct uart_port *p, struct ktermios *termios,
ret = clk_set_rate(d->clk, rate); ret = clk_set_rate(d->clk, rate);
clk_prepare_enable(d->clk); clk_prepare_enable(d->clk);
if (!ret) if (ret)
goto out;
p->uartclk = rate; p->uartclk = rate;
out: out:
...@@ -472,19 +471,18 @@ static int dw8250_probe(struct platform_device *pdev) ...@@ -472,19 +471,18 @@ static int dw8250_probe(struct platform_device *pdev)
device_property_read_u32(dev, "clock-frequency", &p->uartclk); device_property_read_u32(dev, "clock-frequency", &p->uartclk);
/* If there is separate baudclk, get the rate from it. */ /* If there is separate baudclk, get the rate from it. */
data->clk = devm_clk_get(dev, "baudclk"); data->clk = devm_clk_get_optional(dev, "baudclk");
if (IS_ERR(data->clk) && PTR_ERR(data->clk) != -EPROBE_DEFER) if (data->clk == NULL)
data->clk = devm_clk_get(dev, NULL); data->clk = devm_clk_get_optional(dev, NULL);
if (IS_ERR(data->clk) && PTR_ERR(data->clk) == -EPROBE_DEFER) if (IS_ERR(data->clk))
return -EPROBE_DEFER; return PTR_ERR(data->clk);
if (!IS_ERR_OR_NULL(data->clk)) {
err = clk_prepare_enable(data->clk); err = clk_prepare_enable(data->clk);
if (err) if (err)
dev_warn(dev, "could not enable optional baudclk: %d\n", dev_warn(dev, "could not enable optional baudclk: %d\n", err);
err);
else if (data->clk)
p->uartclk = clk_get_rate(data->clk); p->uartclk = clk_get_rate(data->clk);
}
/* If no clock rate is defined, fail. */ /* If no clock rate is defined, fail. */
if (!p->uartclk) { if (!p->uartclk) {
...@@ -493,18 +491,17 @@ static int dw8250_probe(struct platform_device *pdev) ...@@ -493,18 +491,17 @@ static int dw8250_probe(struct platform_device *pdev)
goto err_clk; goto err_clk;
} }
data->pclk = devm_clk_get(dev, "apb_pclk"); data->pclk = devm_clk_get_optional(dev, "apb_pclk");
if (IS_ERR(data->pclk) && PTR_ERR(data->pclk) == -EPROBE_DEFER) { if (IS_ERR(data->pclk)) {
err = -EPROBE_DEFER; err = PTR_ERR(data->pclk);
goto err_clk; goto err_clk;
} }
if (!IS_ERR(data->pclk)) {
err = clk_prepare_enable(data->pclk); err = clk_prepare_enable(data->pclk);
if (err) { if (err) {
dev_err(dev, "could not enable apb_pclk\n"); dev_err(dev, "could not enable apb_pclk\n");
goto err_clk; goto err_clk;
} }
}
data->rst = devm_reset_control_get_optional_exclusive(dev, NULL); data->rst = devm_reset_control_get_optional_exclusive(dev, NULL);
if (IS_ERR(data->rst)) { if (IS_ERR(data->rst)) {
...@@ -546,11 +543,9 @@ static int dw8250_probe(struct platform_device *pdev) ...@@ -546,11 +543,9 @@ static int dw8250_probe(struct platform_device *pdev)
reset_control_assert(data->rst); reset_control_assert(data->rst);
err_pclk: err_pclk:
if (!IS_ERR(data->pclk))
clk_disable_unprepare(data->pclk); clk_disable_unprepare(data->pclk);
err_clk: err_clk:
if (!IS_ERR(data->clk))
clk_disable_unprepare(data->clk); clk_disable_unprepare(data->clk);
return err; return err;
...@@ -567,10 +562,8 @@ static int dw8250_remove(struct platform_device *pdev) ...@@ -567,10 +562,8 @@ static int dw8250_remove(struct platform_device *pdev)
reset_control_assert(data->rst); reset_control_assert(data->rst);
if (!IS_ERR(data->pclk))
clk_disable_unprepare(data->pclk); clk_disable_unprepare(data->pclk);
if (!IS_ERR(data->clk))
clk_disable_unprepare(data->clk); clk_disable_unprepare(data->clk);
pm_runtime_disable(dev); pm_runtime_disable(dev);
...@@ -604,10 +597,8 @@ static int dw8250_runtime_suspend(struct device *dev) ...@@ -604,10 +597,8 @@ static int dw8250_runtime_suspend(struct device *dev)
{ {
struct dw8250_data *data = dev_get_drvdata(dev); struct dw8250_data *data = dev_get_drvdata(dev);
if (!IS_ERR(data->clk))
clk_disable_unprepare(data->clk); clk_disable_unprepare(data->clk);
if (!IS_ERR(data->pclk))
clk_disable_unprepare(data->pclk); clk_disable_unprepare(data->pclk);
return 0; return 0;
...@@ -617,10 +608,8 @@ static int dw8250_runtime_resume(struct device *dev) ...@@ -617,10 +608,8 @@ static int dw8250_runtime_resume(struct device *dev)
{ {
struct dw8250_data *data = dev_get_drvdata(dev); struct dw8250_data *data = dev_get_drvdata(dev);
if (!IS_ERR(data->pclk))
clk_prepare_enable(data->pclk); clk_prepare_enable(data->pclk);
if (!IS_ERR(data->clk))
clk_prepare_enable(data->clk); clk_prepare_enable(data->clk);
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment