* [PATCH] rtc: Fix suspend/resume for APM X-Gene SoC RTC driver
@ 2014-04-11 23:33 Loc Ho
[not found] ` <1397259218-20494-1-git-send-email-lho-qTEPVZfXA3Y@public.gmane.org>
0 siblings, 1 reply; 3+ messages in thread
From: Loc Ho @ 2014-04-11 23:33 UTC (permalink / raw)
To: a.zummo-BfzFCNDTiLLj+vYz1yj4TQ
Cc: rtc-linux-/JYPxA39Uh5TLH3MbocFFw,
devicetree-u79uwXL29TY76Z2rM5mHXA,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
jcm-H+wXaHxf7aLQT0dZR+AlfA, patches-qTEPVZfXA3Y, Loc Ho
This patch fixes suspend/resume functions properly for the APM X-Gene
SoC RTC driver. This patch requires the merged v2 of the APM X-Gene
SoC RTC driver.
Signed-off-by: Loc Ho <lho-qTEPVZfXA3Y@public.gmane.org>
---
drivers/rtc/rtc-xgene.c | 39 ++++++++++++++++++++++++++++++---------
1 files changed, 30 insertions(+), 9 deletions(-)
diff --git a/drivers/rtc/rtc-xgene.c b/drivers/rtc/rtc-xgene.c
index 14129cc..a80d26f 100644
--- a/drivers/rtc/rtc-xgene.c
+++ b/drivers/rtc/rtc-xgene.c
@@ -52,6 +52,7 @@ struct xgene_rtc_dev {
void __iomem *csr_base;
struct clk *clk;
unsigned int irq_wake;
+ unsigned int irq_enabled;
};
static int xgene_rtc_read_time(struct device *dev, struct rtc_time *tm)
@@ -104,15 +105,19 @@ static int xgene_rtc_alarm_irq_enable(struct device *dev, u32 enabled)
return 0;
}
+static int xgene_rtc_alarm_irq_enabled(struct device *dev)
+{
+ struct xgene_rtc_dev *pdata = dev_get_drvdata(dev);
+
+ return readl(pdata->csr_base + RTC_CCR) & RTC_CCR_IE ? 1 : 0;
+}
+
static int xgene_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
{
struct xgene_rtc_dev *pdata = dev_get_drvdata(dev);
- unsigned long rtc_time;
unsigned long alarm_time;
- rtc_time = readl(pdata->csr_base + RTC_CCVR);
rtc_tm_to_time(&alrm->time, &alarm_time);
-
pdata->alarm_time = alarm_time;
writel((u32) pdata->alarm_time, pdata->csr_base + RTC_CMR);
@@ -180,12 +185,16 @@ static int xgene_rtc_probe(struct platform_device *pdev)
dev_err(&pdev->dev, "Couldn't get the clock for RTC\n");
return -ENODEV;
}
- clk_prepare_enable(pdata->clk);
+ ret = clk_prepare_enable(pdata->clk);
+ if (ret)
+ return ret;
/* Turn on the clock and the crystal */
writel(RTC_CCR_EN, pdata->csr_base + RTC_CCR);
- device_init_wakeup(&pdev->dev, 1);
+ ret = device_init_wakeup(&pdev->dev, 1);
+ if (ret)
+ return ret;
pdata->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
&xgene_rtc_ops, THIS_MODULE);
@@ -218,14 +227,20 @@ static int xgene_rtc_suspend(struct device *dev)
int irq;
irq = platform_get_irq(pdev, 0);
+
+ /*
+ * If this RTC alarm will be used for waking the system up,
+ * don't disable it of course. Else we just disable the alarm
+ * and await suspension.
+ */
if (device_may_wakeup(&pdev->dev)) {
if (!enable_irq_wake(irq))
pdata->irq_wake = 1;
} else {
+ pdata->irq_enabled = xgene_rtc_alarm_irq_enabled(dev);
xgene_rtc_alarm_irq_enable(dev, 0);
- clk_disable(pdata->clk);
+ clk_disable_unprepare(pdata->clk);
}
-
return 0;
}
@@ -234,16 +249,22 @@ static int xgene_rtc_resume(struct device *dev)
struct platform_device *pdev = to_platform_device(dev);
struct xgene_rtc_dev *pdata = platform_get_drvdata(pdev);
int irq;
+ int rc;
irq = platform_get_irq(pdev, 0);
+
if (device_may_wakeup(&pdev->dev)) {
if (pdata->irq_wake) {
disable_irq_wake(irq);
pdata->irq_wake = 0;
}
} else {
- clk_enable(pdata->clk);
- xgene_rtc_alarm_irq_enable(dev, 1);
+ rc = clk_prepare_enable(pdata->clk);
+ if (rc) {
+ dev_err(dev, "Unable to enable clock error %d\n", rc);
+ return rc;
+ }
+ xgene_rtc_alarm_irq_enable(dev, pdata->irq_enabled);
}
return 0;
--
1.5.5
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [rtc-linux] [PATCH] rtc: Fix suspend/resume for APM X-Gene SoC RTC driver
[not found] ` <1397259218-20494-1-git-send-email-lho-qTEPVZfXA3Y@public.gmane.org>
@ 2014-04-14 17:21 ` Mark Brown
[not found] ` <20140414172134.GB25182-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
0 siblings, 1 reply; 3+ messages in thread
From: Mark Brown @ 2014-04-14 17:21 UTC (permalink / raw)
To: Loc Ho
Cc: a.zummo-BfzFCNDTiLLj+vYz1yj4TQ, rtc-linux-/JYPxA39Uh5TLH3MbocFFw,
devicetree-u79uwXL29TY76Z2rM5mHXA,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
jcm-H+wXaHxf7aLQT0dZR+AlfA, patches-qTEPVZfXA3Y
[-- Attachment #1: Type: text/plain, Size: 670 bytes --]
On Fri, Apr 11, 2014 at 05:33:38PM -0600, Loc Ho wrote:
> - clk_prepare_enable(pdata->clk);
> + ret = clk_prepare_enable(pdata->clk);
> + if (ret)
> + return ret;
>
> /* Turn on the clock and the crystal */
> writel(RTC_CCR_EN, pdata->csr_base + RTC_CCR);
>
> - device_init_wakeup(&pdev->dev, 1);
> + ret = device_init_wakeup(&pdev->dev, 1);
> + if (ret)
> + return ret;
>
If the init fails you should unprepare (though I suspect the same issue
applies to other things in the probe function anyway). If you fix that
then feel free to add:
Reviewed-by: Mark Brown <broonie-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
or anyway I guess.
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [rtc-linux] [PATCH] rtc: Fix suspend/resume for APM X-Gene SoC RTC driver
[not found] ` <20140414172134.GB25182-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
@ 2014-04-14 17:52 ` Loc Ho
0 siblings, 0 replies; 3+ messages in thread
From: Loc Ho @ 2014-04-14 17:52 UTC (permalink / raw)
To: Mark Brown
Cc: Alessandro Zummo, rtc-linux-/JYPxA39Uh5TLH3MbocFFw,
devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
Jon Masters, patches-qTEPVZfXA3Y@public.gmane.org
Hi,
>> - clk_prepare_enable(pdata->clk);
>> + ret = clk_prepare_enable(pdata->clk);
>> + if (ret)
>> + return ret;
>>
>> /* Turn on the clock and the crystal */
>> writel(RTC_CCR_EN, pdata->csr_base + RTC_CCR);
>>
>> - device_init_wakeup(&pdev->dev, 1);
>> + ret = device_init_wakeup(&pdev->dev, 1);
>> + if (ret)
>> + return ret;
>>
> If the init fails you should unprepare (though I suspect the same issue
> applies to other things in the probe function anyway). If you fix that
> then feel free to add:
>
Okay... This is the only place missed. I don't see issue with other
locations. I will post another version soon.
-Loc
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-04-14 17:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-11 23:33 [PATCH] rtc: Fix suspend/resume for APM X-Gene SoC RTC driver Loc Ho
[not found] ` <1397259218-20494-1-git-send-email-lho-qTEPVZfXA3Y@public.gmane.org>
2014-04-14 17:21 ` [rtc-linux] " Mark Brown
[not found] ` <20140414172134.GB25182-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2014-04-14 17:52 ` Loc Ho
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).