rtc: mxc: Use devm_add_action_or_reset() for calls to clk_disable_unprepare()
Use devm_add_action_or_reset() for calls to clk_disable_unprepare(), which can simplify the error handling, and .remove callback can be dropped. Signed-off-by: Anson Huang <Anson.Huang@nxp.com> Link: https://lore.kernel.org/r/1584349785-27042-1-git-send-email-Anson.Huang@nxp.com Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
This commit is contained in:
parent
df11b323b1
commit
fdc9f0eace
|
@ -307,6 +307,14 @@ static const struct rtc_class_ops mxc_rtc_ops = {
|
||||||
.alarm_irq_enable = mxc_rtc_alarm_irq_enable,
|
.alarm_irq_enable = mxc_rtc_alarm_irq_enable,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static void mxc_rtc_action(void *p)
|
||||||
|
{
|
||||||
|
struct rtc_plat_data *pdata = p;
|
||||||
|
|
||||||
|
clk_disable_unprepare(pdata->clk_ref);
|
||||||
|
clk_disable_unprepare(pdata->clk_ipg);
|
||||||
|
}
|
||||||
|
|
||||||
static int mxc_rtc_probe(struct platform_device *pdev)
|
static int mxc_rtc_probe(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
struct rtc_device *rtc;
|
struct rtc_device *rtc;
|
||||||
|
@ -366,14 +374,20 @@ static int mxc_rtc_probe(struct platform_device *pdev)
|
||||||
|
|
||||||
pdata->clk_ref = devm_clk_get(&pdev->dev, "ref");
|
pdata->clk_ref = devm_clk_get(&pdev->dev, "ref");
|
||||||
if (IS_ERR(pdata->clk_ref)) {
|
if (IS_ERR(pdata->clk_ref)) {
|
||||||
|
clk_disable_unprepare(pdata->clk_ipg);
|
||||||
dev_err(&pdev->dev, "unable to get ref clock!\n");
|
dev_err(&pdev->dev, "unable to get ref clock!\n");
|
||||||
ret = PTR_ERR(pdata->clk_ref);
|
return PTR_ERR(pdata->clk_ref);
|
||||||
goto exit_put_clk_ipg;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = clk_prepare_enable(pdata->clk_ref);
|
ret = clk_prepare_enable(pdata->clk_ref);
|
||||||
|
if (ret) {
|
||||||
|
clk_disable_unprepare(pdata->clk_ipg);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = devm_add_action_or_reset(&pdev->dev, mxc_rtc_action, pdata);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto exit_put_clk_ipg;
|
return ret;
|
||||||
|
|
||||||
rate = clk_get_rate(pdata->clk_ref);
|
rate = clk_get_rate(pdata->clk_ref);
|
||||||
|
|
||||||
|
@ -385,16 +399,14 @@ static int mxc_rtc_probe(struct platform_device *pdev)
|
||||||
reg = RTC_INPUT_CLK_38400HZ;
|
reg = RTC_INPUT_CLK_38400HZ;
|
||||||
else {
|
else {
|
||||||
dev_err(&pdev->dev, "rtc clock is not valid (%lu)\n", rate);
|
dev_err(&pdev->dev, "rtc clock is not valid (%lu)\n", rate);
|
||||||
ret = -EINVAL;
|
return -EINVAL;
|
||||||
goto exit_put_clk_ref;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
reg |= RTC_ENABLE_BIT;
|
reg |= RTC_ENABLE_BIT;
|
||||||
writew(reg, (pdata->ioaddr + RTC_RTCCTL));
|
writew(reg, (pdata->ioaddr + RTC_RTCCTL));
|
||||||
if (((readw(pdata->ioaddr + RTC_RTCCTL)) & RTC_ENABLE_BIT) == 0) {
|
if (((readw(pdata->ioaddr + RTC_RTCCTL)) & RTC_ENABLE_BIT) == 0) {
|
||||||
dev_err(&pdev->dev, "hardware module can't be enabled!\n");
|
dev_err(&pdev->dev, "hardware module can't be enabled!\n");
|
||||||
ret = -EIO;
|
return -EIO;
|
||||||
goto exit_put_clk_ref;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
platform_set_drvdata(pdev, pdata);
|
platform_set_drvdata(pdev, pdata);
|
||||||
|
@ -417,29 +429,10 @@ static int mxc_rtc_probe(struct platform_device *pdev)
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = rtc_register_device(rtc);
|
ret = rtc_register_device(rtc);
|
||||||
if (ret)
|
|
||||||
goto exit_put_clk_ref;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
exit_put_clk_ref:
|
|
||||||
clk_disable_unprepare(pdata->clk_ref);
|
|
||||||
exit_put_clk_ipg:
|
|
||||||
clk_disable_unprepare(pdata->clk_ipg);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mxc_rtc_remove(struct platform_device *pdev)
|
|
||||||
{
|
|
||||||
struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
|
|
||||||
|
|
||||||
clk_disable_unprepare(pdata->clk_ref);
|
|
||||||
clk_disable_unprepare(pdata->clk_ipg);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct platform_driver mxc_rtc_driver = {
|
static struct platform_driver mxc_rtc_driver = {
|
||||||
.driver = {
|
.driver = {
|
||||||
.name = "mxc_rtc",
|
.name = "mxc_rtc",
|
||||||
|
@ -447,7 +440,6 @@ static struct platform_driver mxc_rtc_driver = {
|
||||||
},
|
},
|
||||||
.id_table = imx_rtc_devtype,
|
.id_table = imx_rtc_devtype,
|
||||||
.probe = mxc_rtc_probe,
|
.probe = mxc_rtc_probe,
|
||||||
.remove = mxc_rtc_remove,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module_platform_driver(mxc_rtc_driver)
|
module_platform_driver(mxc_rtc_driver)
|
||||||
|
|
Loading…
Reference in New Issue