Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp420122ybl; Fri, 23 Aug 2019 02:56:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqwDzHfZaP1vvTm9wI0cxV+tW24cFjMOLU7oyrtDwqrrenhqLPjtaRvScmpbKvvSBBqLXhi/ X-Received: by 2002:a63:724b:: with SMTP id c11mr3302601pgn.30.1566554207783; Fri, 23 Aug 2019 02:56:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566554207; cv=none; d=google.com; s=arc-20160816; b=DVp443qtEqjSJMNzK8/M/NTx0699JJM/e49pblOayjTYpmKkq5EuM0iqnTVvrifYfe cCSMgDg8PZUcAt8XIydhrLUg5GmC1v5tQW7V8GbhU8OMd08Ex4wee1Wf5oCtbHOJKhhj rdDuV0HSiKnjxXNI1oHvezpfSscDPYXZHxo6TCJ3iEmanQUFjYpZpMeRY+A+ujGIdqyg 5cKeQTlM7y1qLMlOkL+QBNpDQdLu5oNF0FOQiqyHZiFg5xn4fUtOEB8n7uwtvwFscool VY6bS3vX7AmjOBfFwxexJyv7Gn9N6rum1L2CAzjiwUABoKxdnERLgbESJcjSaIx9VgX1 wgaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=JiQ0CpTVP/PXoYFE53EIIOjGjiPcL6ftTfEJdZW9sKg=; b=qhDKyMyjy3fn+YlL4Uqw7XXIW5sf54/S4p+fRsFNmFNE6NtbhwGZAfb/ASrApeU5c5 xnLdhjb6UZsfQBEewdDEANimBwaTcsdWRJn29/Tpcn4gwode8GQvJHm1raIGPIKnS6F0 jmxlbXtj2E98XfLeIPBxnpFUg52LcPZ1TfTbHgmLU1eXa5i/QTlgUDYyFWpz3SCVxuHr td2zosZQHSYle7KyyyXu41FVq730CKjOUxQWx1qJuN6kp+HJlba7BrxlbG+oir1TVn8q AUNAMXHKSy4dvk5GFxOi2daULSKi0b0dLeV3+tT11NvNf+qcCmASdow1HrmaARbw6spY Ot9Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b5si2154940pfd.273.2019.08.23.02.56.32; Fri, 23 Aug 2019 02:56:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404217AbfHWDq2 (ORCPT + 99 others); Thu, 22 Aug 2019 23:46:28 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:8831 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1732929AbfHWDpr (ORCPT ); Thu, 22 Aug 2019 23:45:47 -0400 X-UUID: d8874cce2cf84cf6a47dc44f740b502e-20190823 X-UUID: d8874cce2cf84cf6a47dc44f740b502e-20190823 Received: from mtkcas08.mediatek.inc [(172.21.101.126)] by mailgw02.mediatek.com (envelope-from ) (Cellopoint E-mail Firewall v4.1.10 Build 0707 with TLS) with ESMTP id 19840464; Fri, 23 Aug 2019 11:45:42 +0800 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by mtkmbs01n2.mediatek.inc (172.21.101.79) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Fri, 23 Aug 2019 11:45:36 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by MTKCAS06.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Fri, 23 Aug 2019 11:45:36 +0800 From: Hsin-Hsiung Wang To: Lee Jones , Rob Herring , Mark Brown , Matthias Brugger , Alexandre Belloni CC: Mark Rutland , Liam Girdwood , Eddie Huang , Sean Wang , Alessandro Zummo , Hsin-Hsiung Wang , Kate Stewart , Greg Kroah-Hartman , Thomas Gleixner , Richard Fontana , , , , , , , Ran Bi Subject: [PATCH v5 09/10] rtc: mt6397: fix alarm register overwrite Date: Fri, 23 Aug 2019 11:45:30 +0800 Message-ID: <1566531931-9772-10-git-send-email-hsin-hsiung.wang@mediatek.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1566531931-9772-1-git-send-email-hsin-hsiung.wang@mediatek.com> References: <1566531931-9772-1-git-send-email-hsin-hsiung.wang@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain X-TM-SNTS-SMTP: 2E3B4B837B7F74EC272AEACC6B0957C7877B5D51C55DC4AD3990254C0E4EF8972000:8 X-MTK: N Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ran Bi Alarm registers high byte was reserved for other functions. This add mask in alarm registers operation functions. This also fix error condition in interrupt handler. Fixes: fc2979118f3f ("rtc: mediatek: Add MT6397 RTC driver") Acked-by: Alexandre Belloni Signed-off-by: Ran Bi --- drivers/rtc/rtc-mt6397.c | 47 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/drivers/rtc/rtc-mt6397.c b/drivers/rtc/rtc-mt6397.c index b46ed4d..828def7 100644 --- a/drivers/rtc/rtc-mt6397.c +++ b/drivers/rtc/rtc-mt6397.c @@ -47,6 +47,14 @@ #define RTC_AL_SEC 0x0018 +#define RTC_AL_SEC_MASK 0x003f +#define RTC_AL_MIN_MASK 0x003f +#define RTC_AL_HOU_MASK 0x001f +#define RTC_AL_DOM_MASK 0x001f +#define RTC_AL_DOW_MASK 0x0007 +#define RTC_AL_MTH_MASK 0x000f +#define RTC_AL_YEA_MASK 0x007f + #define RTC_PDN2 0x002e #define RTC_PDN2_PWRON_ALARM BIT(4) @@ -103,7 +111,7 @@ static irqreturn_t mtk_rtc_irq_handler_thread(int irq, void *data) irqen = irqsta & ~RTC_IRQ_EN_AL; mutex_lock(&rtc->lock); if (regmap_write(rtc->regmap, rtc->addr_base + RTC_IRQ_EN, - irqen) < 0) + irqen) == 0) mtk_rtc_write_trigger(rtc); mutex_unlock(&rtc->lock); @@ -225,12 +233,12 @@ static int mtk_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alm) alm->pending = !!(pdn2 & RTC_PDN2_PWRON_ALARM); mutex_unlock(&rtc->lock); - tm->tm_sec = data[RTC_OFFSET_SEC]; - tm->tm_min = data[RTC_OFFSET_MIN]; - tm->tm_hour = data[RTC_OFFSET_HOUR]; - tm->tm_mday = data[RTC_OFFSET_DOM]; - tm->tm_mon = data[RTC_OFFSET_MTH]; - tm->tm_year = data[RTC_OFFSET_YEAR]; + tm->tm_sec = data[RTC_OFFSET_SEC] & RTC_AL_SEC_MASK; + tm->tm_min = data[RTC_OFFSET_MIN] & RTC_AL_MIN_MASK; + tm->tm_hour = data[RTC_OFFSET_HOUR] & RTC_AL_HOU_MASK; + tm->tm_mday = data[RTC_OFFSET_DOM] & RTC_AL_DOM_MASK; + tm->tm_mon = data[RTC_OFFSET_MTH] & RTC_AL_MTH_MASK; + tm->tm_year = data[RTC_OFFSET_YEAR] & RTC_AL_YEA_MASK; tm->tm_year += RTC_MIN_YEAR_OFFSET; tm->tm_mon--; @@ -251,14 +259,25 @@ static int mtk_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm) tm->tm_year -= RTC_MIN_YEAR_OFFSET; tm->tm_mon++; - data[RTC_OFFSET_SEC] = tm->tm_sec; - data[RTC_OFFSET_MIN] = tm->tm_min; - data[RTC_OFFSET_HOUR] = tm->tm_hour; - data[RTC_OFFSET_DOM] = tm->tm_mday; - data[RTC_OFFSET_MTH] = tm->tm_mon; - data[RTC_OFFSET_YEAR] = tm->tm_year; - mutex_lock(&rtc->lock); + ret = regmap_bulk_read(rtc->regmap, rtc->addr_base + RTC_AL_SEC, + data, RTC_OFFSET_COUNT); + if (ret < 0) + goto exit; + + data[RTC_OFFSET_SEC] = ((data[RTC_OFFSET_SEC] & ~(RTC_AL_SEC_MASK)) | + (tm->tm_sec & RTC_AL_SEC_MASK)); + data[RTC_OFFSET_MIN] = ((data[RTC_OFFSET_MIN] & ~(RTC_AL_MIN_MASK)) | + (tm->tm_min & RTC_AL_MIN_MASK)); + data[RTC_OFFSET_HOUR] = ((data[RTC_OFFSET_HOUR] & ~(RTC_AL_HOU_MASK)) | + (tm->tm_hour & RTC_AL_HOU_MASK)); + data[RTC_OFFSET_DOM] = ((data[RTC_OFFSET_DOM] & ~(RTC_AL_DOM_MASK)) | + (tm->tm_mday & RTC_AL_DOM_MASK)); + data[RTC_OFFSET_MTH] = ((data[RTC_OFFSET_MTH] & ~(RTC_AL_MTH_MASK)) | + (tm->tm_mon & RTC_AL_MTH_MASK)); + data[RTC_OFFSET_YEAR] = ((data[RTC_OFFSET_YEAR] & ~(RTC_AL_YEA_MASK)) | + (tm->tm_year & RTC_AL_YEA_MASK)); + if (alm->enabled) { ret = regmap_bulk_write(rtc->regmap, rtc->addr_base + RTC_AL_SEC, -- 1.9.1