mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-05 19:31:57 -04:00
serial: 8250_dw: Use devm_clk_get_optional() to get the input clock
[ Upstream commit a8afc193558a42d5df724c84436ae3b2446d8a30 ] 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: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Link: https://lore.kernel.org/r/20190925162617.30368-1-andriy.shevchenko@linux.intel.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Stable-dep-of: daeb4037adf7 ("serial: 8250_dw: handle reset control deassert error") Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
12afe2c625
commit
fabb861b50
1 changed files with 32 additions and 43 deletions
|
|
@ -283,9 +283,6 @@ static void dw8250_set_termios(struct uart_port *p, struct ktermios *termios,
|
|||
long rate;
|
||||
int ret;
|
||||
|
||||
if (IS_ERR(d->clk))
|
||||
goto out;
|
||||
|
||||
clk_disable_unprepare(d->clk);
|
||||
rate = clk_round_rate(d->clk, baud * 16);
|
||||
if (rate < 0)
|
||||
|
|
@ -296,8 +293,10 @@ static void dw8250_set_termios(struct uart_port *p, struct ktermios *termios,
|
|||
ret = clk_set_rate(d->clk, rate);
|
||||
clk_prepare_enable(d->clk);
|
||||
|
||||
if (!ret)
|
||||
p->uartclk = rate;
|
||||
if (ret)
|
||||
goto out;
|
||||
|
||||
p->uartclk = rate;
|
||||
|
||||
out:
|
||||
p->status &= ~UPSTAT_AUTOCTS;
|
||||
|
|
@ -473,19 +472,18 @@ static int dw8250_probe(struct platform_device *pdev)
|
|||
device_property_read_u32(dev, "clock-frequency", &p->uartclk);
|
||||
|
||||
/* If there is separate baudclk, get the rate from it. */
|
||||
data->clk = devm_clk_get(dev, "baudclk");
|
||||
if (IS_ERR(data->clk) && PTR_ERR(data->clk) != -EPROBE_DEFER)
|
||||
data->clk = devm_clk_get(dev, NULL);
|
||||
if (IS_ERR(data->clk) && PTR_ERR(data->clk) == -EPROBE_DEFER)
|
||||
return -EPROBE_DEFER;
|
||||
if (!IS_ERR_OR_NULL(data->clk)) {
|
||||
err = clk_prepare_enable(data->clk);
|
||||
if (err)
|
||||
dev_warn(dev, "could not enable optional baudclk: %d\n",
|
||||
err);
|
||||
else
|
||||
p->uartclk = clk_get_rate(data->clk);
|
||||
}
|
||||
data->clk = devm_clk_get_optional(dev, "baudclk");
|
||||
if (data->clk == NULL)
|
||||
data->clk = devm_clk_get_optional(dev, NULL);
|
||||
if (IS_ERR(data->clk))
|
||||
return PTR_ERR(data->clk);
|
||||
|
||||
err = clk_prepare_enable(data->clk);
|
||||
if (err)
|
||||
dev_warn(dev, "could not enable optional baudclk: %d\n", err);
|
||||
|
||||
if (data->clk)
|
||||
p->uartclk = clk_get_rate(data->clk);
|
||||
|
||||
/* If no clock rate is defined, fail. */
|
||||
if (!p->uartclk) {
|
||||
|
|
@ -494,17 +492,16 @@ static int dw8250_probe(struct platform_device *pdev)
|
|||
goto err_clk;
|
||||
}
|
||||
|
||||
data->pclk = devm_clk_get(dev, "apb_pclk");
|
||||
if (IS_ERR(data->pclk) && PTR_ERR(data->pclk) == -EPROBE_DEFER) {
|
||||
err = -EPROBE_DEFER;
|
||||
data->pclk = devm_clk_get_optional(dev, "apb_pclk");
|
||||
if (IS_ERR(data->pclk)) {
|
||||
err = PTR_ERR(data->pclk);
|
||||
goto err_clk;
|
||||
}
|
||||
if (!IS_ERR(data->pclk)) {
|
||||
err = clk_prepare_enable(data->pclk);
|
||||
if (err) {
|
||||
dev_err(dev, "could not enable apb_pclk\n");
|
||||
goto err_clk;
|
||||
}
|
||||
|
||||
err = clk_prepare_enable(data->pclk);
|
||||
if (err) {
|
||||
dev_err(dev, "could not enable apb_pclk\n");
|
||||
goto err_clk;
|
||||
}
|
||||
|
||||
data->rst = devm_reset_control_get_optional_exclusive(dev, NULL);
|
||||
|
|
@ -547,12 +544,10 @@ err_reset:
|
|||
reset_control_assert(data->rst);
|
||||
|
||||
err_pclk:
|
||||
if (!IS_ERR(data->pclk))
|
||||
clk_disable_unprepare(data->pclk);
|
||||
clk_disable_unprepare(data->pclk);
|
||||
|
||||
err_clk:
|
||||
if (!IS_ERR(data->clk))
|
||||
clk_disable_unprepare(data->clk);
|
||||
clk_disable_unprepare(data->clk);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
|
@ -568,11 +563,9 @@ static int dw8250_remove(struct platform_device *pdev)
|
|||
|
||||
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_put_noidle(dev);
|
||||
|
|
@ -605,11 +598,9 @@ static int dw8250_runtime_suspend(struct device *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;
|
||||
}
|
||||
|
|
@ -618,11 +609,9 @@ static int dw8250_runtime_resume(struct device *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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue