From patchwork Fri Apr 11 23:33:38 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loc Ho X-Patchwork-Id: 3972391 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 45A999F370 for ; Fri, 11 Apr 2014 23:37:09 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6B1E420353 for ; Fri, 11 Apr 2014 23:37:08 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 835A620351 for ; Fri, 11 Apr 2014 23:37:07 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WYkxW-0000hw-LI; Fri, 11 Apr 2014 23:34:10 +0000 Received: from exprod5og119.obsmtp.com ([64.18.0.189]) by bombadil.infradead.org with smtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WYkxU-0000f2-FD for linux-arm-kernel@lists.infradead.org; Fri, 11 Apr 2014 23:34:08 +0000 Received: from mail-pa0-f43.google.com ([209.85.220.43]) (using TLSv1) by exprod5ob119.postini.com ([64.18.4.12]) with SMTP ID DSNKU0h72pjEFNUjZW/FtCJvpyDITOXn7CwZ@postini.com; Fri, 11 Apr 2014 16:34:08 PDT Received: by mail-pa0-f43.google.com with SMTP id bj1so6006994pad.2 for ; Fri, 11 Apr 2014 16:33:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=RX6jVb7vndrhVlhhibK7o6D8gKOuZ7+pUL/1jz4E7Rc=; b=ekVynd3A3f/d4US/25gXZ8Kyzb3JkbmDG+qCMGuXsrBKMDgTeqjDni4UEcDaM12bll 1o1ajXzratNkeSvIVcEep/ziL+stGVTJyNlUt8Wb2iymQDoav4zEVL3uHg+LXDmmUwmD EtwGWMjoAik9HfNDevYWkADi9dX2EPjps02sUixN6RR6CWp4bbfFlVvHXdl6lqZckfwN WIGOYd9Jqlkxgfv2yvbkt5FGmfZek7YEUmqiJAVrnv9wyxYqA4DOA0g6mmlhJcTvBR/6 9P1OvtE4jOBfN/3vCwixdA4G/BBPyqmH1R2Axn1PLd91MB1BYMgPI/HBFKtTulQMMRPV lU7w== X-Gm-Message-State: ALoCoQnBIVSKKuBk439XIDr4mnMxEAttzsbcniFG7TaA9XqgF8sReokGc9ho6wTQZ/uFUvSUIltoKwgVoal62SMTssuQYV4cHHVN5BIZqfk7DZnZ0ieNy+G9CgDL2V6KrUOOTQSjiSEkTKIKDkfev+zJTk/ZkEwWyQ== X-Received: by 10.67.8.102 with SMTP id dj6mr30733347pad.10.1397259226000; Fri, 11 Apr 2014 16:33:46 -0700 (PDT) X-Received: by 10.67.8.102 with SMTP id dj6mr30733268pad.10.1397259224834; Fri, 11 Apr 2014 16:33:44 -0700 (PDT) Received: from localhost ([198.137.200.11]) by mx.google.com with ESMTPSA id pq3sm18051917pbb.57.2014.04.11.16.33.43 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 11 Apr 2014 16:33:44 -0700 (PDT) From: Loc Ho To: a.zummo@towertech.it Subject: [PATCH] rtc: Fix suspend/resume for APM X-Gene SoC RTC driver Date: Fri, 11 Apr 2014 17:33:38 -0600 Message-Id: <1397259218-20494-1-git-send-email-lho@apm.com> X-Mailer: git-send-email 1.5.5 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140411_163408_534054_4CD72DA5 X-CRM114-Status: GOOD ( 16.04 ) X-Spam-Score: -0.0 (/) Cc: devicetree@vger.kernel.org, rtc-linux@googlegroups.com, jcm@redhat.com, patches@apm.com, Loc Ho , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewed-by: Mark Brown --- 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;