Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp1915985ybk; Thu, 21 May 2020 19:33:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwpWqyfXfK4ALMVBiQCwz6whIKlrXbjQX3t+dn1SQKbH+tgkk+0UAQtCQfRofbuyknsl2G5 X-Received: by 2002:a17:906:34c3:: with SMTP id h3mr6220024ejb.446.1590114826216; Thu, 21 May 2020 19:33:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590114826; cv=none; d=google.com; s=arc-20160816; b=jjcuB/dOjJxjF4GuyGS8KovappcYrLhqbOaKqTbS3pFx7HjAkUO5X2eNfr4DuwKZoo PZ25OCjOEUbqmp3flIQmS70RFGIXsRogfxfCqgKysOGvHMPa2PqZ//4KASPISKaU935n ayebctb6rtF2NFP4hHdsU72eKqY+STsX8p8jSF3qQ2G0cVWvKDNv7AhuT6wtwm3hVNvM KUluYY0D1o0RUiQ51WaewXmCEo15LduMsDD3cM+8o/9/Vi6/mnHDTzi6j8yrbVmhorOg 0h9CW64uazh09G3E8hC3JlDQe7LUUj2AiUUeMp4HQJQSqTSmGmYt4voP6O7rN4EwhzH/ ySOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=g9VC8zgnus9cJp5bC2J4r+4hqBVgkS3tMW8eszRsKYA=; b=bRc4QOa79Zif+DtT6v+xtj6dgClC4B1Xm7IxdidN2rApy88LTdls8zFlFEZjWhCjEf pPP3xXsar0dzR3hvSifJoXIjlmCrFsaMlM95e/34lPQ/cukaHBSDp+0SH8Cv+aYV9w5R BHRHQRg2v5TqLDRR0DtFcxvw7+3hJS5MgSrF5zwBzyckeGvSNrTQtP0IWD8FcLPTqRPm 2S5uYh+K6IXEOMAO9qRKwpWJgwUTkIxeCoUR5sjr7wX+4Gw/AI5vMrDUBjTYOFRMPXQ8 GsdbfxzIYdhMmLoUAO60GsJf5a5CcUPo8lrwjCCZnRRqC1pX21o3+N9MWU2Qlwf2raP6 /7uw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r9si4077537eds.223.2020.05.21.19.33.23; Thu, 21 May 2020 19:33:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727119AbgEVC3v (ORCPT + 99 others); Thu, 21 May 2020 22:29:51 -0400 Received: from inva020.nxp.com ([92.121.34.13]:59248 "EHLO inva020.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726925AbgEVC3t (ORCPT ); Thu, 21 May 2020 22:29:49 -0400 Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id B46D21A0903; Fri, 22 May 2020 04:29:47 +0200 (CEST) Received: from invc005.ap-rdc01.nxp.com (invc005.ap-rdc01.nxp.com [165.114.16.14]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 20F241A08DA; Fri, 22 May 2020 04:29:45 +0200 (CEST) Received: from localhost.localdomain (shlinux2.ap.freescale.net [10.192.224.44]) by invc005.ap-rdc01.nxp.com (Postfix) with ESMTP id B606E402B4; Fri, 22 May 2020 10:29:41 +0800 (SGT) From: Anson Huang To: a.zummo@towertech.it, alexandre.belloni@bootlin.com, linux-rtc@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Linux-imx@nxp.com Subject: [PATCH 2/2] rtc: snvs: Add necessary clock operations for RTC APIs Date: Fri, 22 May 2020 10:19:56 +0800 Message-Id: <1590113996-31845-2-git-send-email-Anson.Huang@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1590113996-31845-1-git-send-email-Anson.Huang@nxp.com> References: <1590113996-31845-1-git-send-email-Anson.Huang@nxp.com> X-Virus-Scanned: ClamAV using ClamSMTP Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There could be still RTC registers access after RTC suspend with clock disabled, need to add clock operations for each RTC API to make sure accessing RTC registers is successfully. Signed-off-by: Anson Huang --- drivers/rtc/rtc-snvs.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/drivers/rtc/rtc-snvs.c b/drivers/rtc/rtc-snvs.c index b9371f4..0263d99 100644 --- a/drivers/rtc/rtc-snvs.c +++ b/drivers/rtc/rtc-snvs.c @@ -148,10 +148,21 @@ static int snvs_rtc_enable(struct snvs_rtc_data *data, bool enable) static int snvs_rtc_read_time(struct device *dev, struct rtc_time *tm) { struct snvs_rtc_data *data = dev_get_drvdata(dev); - unsigned long time = rtc_read_lp_counter(data); + unsigned long time; + int ret; + + if (data->clk) { + ret = clk_enable(data->clk); + if (ret) + return ret; + } + time = rtc_read_lp_counter(data); rtc_time64_to_tm(time, tm); + if (data->clk) + clk_disable(data->clk); + return 0; } @@ -161,6 +172,12 @@ static int snvs_rtc_set_time(struct device *dev, struct rtc_time *tm) unsigned long time = rtc_tm_to_time64(tm); int ret; + if (data->clk) { + ret = clk_enable(data->clk); + if (ret) + return ret; + } + /* Disable RTC first */ ret = snvs_rtc_enable(data, false); if (ret) @@ -173,6 +190,9 @@ static int snvs_rtc_set_time(struct device *dev, struct rtc_time *tm) /* Enable RTC again */ ret = snvs_rtc_enable(data, true); + if (data->clk) + clk_disable(data->clk); + return ret; } @@ -180,6 +200,13 @@ static int snvs_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) { struct snvs_rtc_data *data = dev_get_drvdata(dev); u32 lptar, lpsr; + int ret; + + if (data->clk) { + ret = clk_enable(data->clk); + if (ret) + return ret; + } regmap_read(data->regmap, data->offset + SNVS_LPTAR, &lptar); rtc_time64_to_tm(lptar, &alrm->time); @@ -187,18 +214,33 @@ static int snvs_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) regmap_read(data->regmap, data->offset + SNVS_LPSR, &lpsr); alrm->pending = (lpsr & SNVS_LPSR_LPTA) ? 1 : 0; + if (data->clk) + clk_disable(data->clk); + return 0; } static int snvs_rtc_alarm_irq_enable(struct device *dev, unsigned int enable) { struct snvs_rtc_data *data = dev_get_drvdata(dev); + int ret; + + if (data->clk) { + ret = clk_enable(data->clk); + if (ret) + return ret; + } regmap_update_bits(data->regmap, data->offset + SNVS_LPCR, (SNVS_LPCR_LPTA_EN | SNVS_LPCR_LPWUI_EN), enable ? (SNVS_LPCR_LPTA_EN | SNVS_LPCR_LPWUI_EN) : 0); - return rtc_write_sync_lp(data); + ret = rtc_write_sync_lp(data); + + if (data->clk) + clk_disable(data->clk); + + return ret; } static int snvs_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) @@ -207,6 +249,12 @@ static int snvs_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) unsigned long time = rtc_tm_to_time64(&alrm->time); int ret; + if (data->clk) { + ret = clk_enable(data->clk); + if (ret) + return ret; + } + regmap_update_bits(data->regmap, data->offset + SNVS_LPCR, SNVS_LPCR_LPTA_EN, 0); ret = rtc_write_sync_lp(data); if (ret) @@ -216,6 +264,9 @@ static int snvs_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) /* Clear alarm interrupt status bit */ regmap_write(data->regmap, data->offset + SNVS_LPSR, SNVS_LPSR_LPTA); + if (data->clk) + clk_disable(data->clk); + return snvs_rtc_alarm_irq_enable(dev, alrm->enabled); } -- 2.7.4