serial: 8250_dw: Use devm_add_action_or_reset()
Slightly simplify ->probe() and drop a few goto labels by using devm_add_action_or_reset() for clock and reset cleanup. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Link: https://lore.kernel.org/r/20220509172129.37770-1-andriy.shevchenko@linux.intel.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
4088ca3edc
commit
295b09128d
|
@ -484,6 +484,16 @@ static void dw8250_quirks(struct uart_port *p, struct dw8250_data *data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void dw8250_clk_disable_unprepare(void *data)
|
||||||
|
{
|
||||||
|
clk_disable_unprepare(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void dw8250_reset_control_assert(void *data)
|
||||||
|
{
|
||||||
|
reset_control_assert(data);
|
||||||
|
}
|
||||||
|
|
||||||
static int dw8250_probe(struct platform_device *pdev)
|
static int dw8250_probe(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
struct uart_8250_port uart = {}, *up = &uart;
|
struct uart_8250_port uart = {}, *up = &uart;
|
||||||
|
@ -585,35 +595,43 @@ static int dw8250_probe(struct platform_device *pdev)
|
||||||
if (err)
|
if (err)
|
||||||
dev_warn(dev, "could not enable optional baudclk: %d\n", err);
|
dev_warn(dev, "could not enable optional baudclk: %d\n", err);
|
||||||
|
|
||||||
|
err = devm_add_action_or_reset(dev, dw8250_clk_disable_unprepare, data->clk);
|
||||||
|
if (err)
|
||||||
|
return err;
|
||||||
|
|
||||||
if (data->clk)
|
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) {
|
||||||
dev_err(dev, "clock rate not defined\n");
|
dev_err(dev, "clock rate not defined\n");
|
||||||
err = -EINVAL;
|
return -EINVAL;
|
||||||
goto err_clk;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
data->pclk = devm_clk_get_optional(dev, "apb_pclk");
|
data->pclk = devm_clk_get_optional(dev, "apb_pclk");
|
||||||
if (IS_ERR(data->pclk)) {
|
if (IS_ERR(data->pclk))
|
||||||
err = PTR_ERR(data->pclk);
|
return PTR_ERR(data->pclk);
|
||||||
goto err_clk;
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = devm_add_action_or_reset(dev, dw8250_clk_disable_unprepare, data->pclk);
|
||||||
|
if (err)
|
||||||
|
return err;
|
||||||
|
|
||||||
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))
|
||||||
err = PTR_ERR(data->rst);
|
return PTR_ERR(data->rst);
|
||||||
goto err_pclk;
|
|
||||||
}
|
|
||||||
reset_control_deassert(data->rst);
|
reset_control_deassert(data->rst);
|
||||||
|
|
||||||
|
err = devm_add_action_or_reset(dev, dw8250_reset_control_assert, data->rst);
|
||||||
|
if (err)
|
||||||
|
return err;
|
||||||
|
|
||||||
dw8250_quirks(p, data);
|
dw8250_quirks(p, data);
|
||||||
|
|
||||||
/* If the Busy Functionality is not implemented, don't handle it */
|
/* If the Busy Functionality is not implemented, don't handle it */
|
||||||
|
@ -631,10 +649,8 @@ static int dw8250_probe(struct platform_device *pdev)
|
||||||
}
|
}
|
||||||
|
|
||||||
data->data.line = serial8250_register_8250_port(up);
|
data->data.line = serial8250_register_8250_port(up);
|
||||||
if (data->data.line < 0) {
|
if (data->data.line < 0)
|
||||||
err = data->data.line;
|
return data->data.line;
|
||||||
goto err_reset;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Some platforms may provide a reference clock shared between several
|
* Some platforms may provide a reference clock shared between several
|
||||||
|
@ -655,17 +671,6 @@ static int dw8250_probe(struct platform_device *pdev)
|
||||||
pm_runtime_enable(dev);
|
pm_runtime_enable(dev);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
err_reset:
|
|
||||||
reset_control_assert(data->rst);
|
|
||||||
|
|
||||||
err_pclk:
|
|
||||||
clk_disable_unprepare(data->pclk);
|
|
||||||
|
|
||||||
err_clk:
|
|
||||||
clk_disable_unprepare(data->clk);
|
|
||||||
|
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int dw8250_remove(struct platform_device *pdev)
|
static int dw8250_remove(struct platform_device *pdev)
|
||||||
|
@ -683,12 +688,6 @@ static int dw8250_remove(struct platform_device *pdev)
|
||||||
|
|
||||||
serial8250_unregister_port(data->data.line);
|
serial8250_unregister_port(data->data.line);
|
||||||
|
|
||||||
reset_control_assert(data->rst);
|
|
||||||
|
|
||||||
clk_disable_unprepare(data->pclk);
|
|
||||||
|
|
||||||
clk_disable_unprepare(data->clk);
|
|
||||||
|
|
||||||
pm_runtime_disable(dev);
|
pm_runtime_disable(dev);
|
||||||
pm_runtime_put_noidle(dev);
|
pm_runtime_put_noidle(dev);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue