From 23870cd72f12a3c21371e7f8a5f48febca7b3254 Mon Sep 17 00:00:00 2001 From: LADI RAM SAI Date: Thu, 21 Dec 2023 15:14:53 +0530 Subject: [PATCH] drivers: rtc-pm8xxx: Add support for DeepSleep in RTC driver Add support for the DeepSleep mode for the RTC driver that can be enabled based on a DT property. Change-Id: Id7aab2a1affe26a71194aee0de78e116f1d803a0 Signed-off-by: LADI RAM SAI --- drivers/rtc/rtc-pm8xxx.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/drivers/rtc/rtc-pm8xxx.c b/drivers/rtc/rtc-pm8xxx.c index f5df313b2995..de2ba8bd967b 100644 --- a/drivers/rtc/rtc-pm8xxx.c +++ b/drivers/rtc/rtc-pm8xxx.c @@ -11,6 +11,7 @@ #include #include #include +#include /* RTC Register offsets from RTC CTRL REG */ #define PM8XXX_ALARM_CTRL_OFFSET 0x01 @@ -54,6 +55,7 @@ struct pm8xxx_rtc_regs { * @regs: rtc registers description. * @rtc_dev: device structure. * @ctrl_reg_lock: spinlock protecting access to ctrl_reg. + * @deepsleep_support: deepsleep_support used to check the status of enablement */ struct pm8xxx_rtc { struct rtc_device *rtc; @@ -63,6 +65,7 @@ struct pm8xxx_rtc { const struct pm8xxx_rtc_regs *regs; struct device *rtc_dev; spinlock_t ctrl_reg_lock; + bool deepsleep_support; }; /* @@ -534,6 +537,9 @@ static int pm8xxx_rtc_probe(struct platform_device *pdev) return rc; } + if (of_property_read_bool(pdev->dev.of_node, "qcom,support-deepsleep")) + rtc_dd->deepsleep_support = true; + return 0; } @@ -571,9 +577,29 @@ static int pm8xxx_remove(struct platform_device *pdev) return 0; } +static int pm8xxx_rtc_resume(struct device *dev) +{ + struct pm8xxx_rtc *rtc_dd = dev_get_drvdata(dev); + + if (rtc_dd->deepsleep_support && (pm_suspend_target_state == PM_SUSPEND_MEM)) + return pm8xxx_rtc_restore(dev); + return 0; +} + +static int pm8xxx_rtc_suspend(struct device *dev) +{ + struct pm8xxx_rtc *rtc_dd = dev_get_drvdata(dev); + + if (rtc_dd->deepsleep_support && (pm_suspend_target_state == PM_SUSPEND_MEM)) + return pm8xxx_rtc_freeze(dev); + return 0; +} + static const struct dev_pm_ops pm8xxx_rtc_pm_ops = { .freeze = pm8xxx_rtc_freeze, .restore = pm8xxx_rtc_restore, + .suspend = pm8xxx_rtc_suspend, + .resume = pm8xxx_rtc_resume, }; static struct platform_driver pm8xxx_rtc_driver = {