Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp326529yba; Fri, 3 May 2019 02:36:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqwE89gHTdwZnG/1ECK2XwhPgCdPnAt7pt8eFrDV/zAcVu7KPSQdPsf/UBsmy9mX+AgYDvye X-Received: by 2002:a62:489d:: with SMTP id q29mr9469690pfi.45.1556876182043; Fri, 03 May 2019 02:36:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556876182; cv=none; d=google.com; s=arc-20160816; b=llpa+kBljewVbYwJW2C+JltatfcnMWDl1hOuV7G70PzKsKXlmZGYk5yFDX8CqtDcW5 N1nmFc9dw5X/l34sqsDE9l0F7BlnroXi6mYh18NHMODtAV/wQffP8zWWM0rPFBbgGJ+R mWYdZ2Ae2HsADEW3VKwiJJ9tKQvkykg94bEyAl4vHMvyscDacnJFJwhU268/es3KDDbF A0ZdCND45kssbrFPqtXTERa8KbcQz/XkOnLJ45hMUpQKpZW/IttEymjnFi0mLcUGsmZR Ql5WZg5a1SK3ZiRvOq23eDa+7jsD5nSkQVd6iE3iDY4hr/1ihHKH8otcHqst0XFZLZVF Z0+A== 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=44GOhPUYTXkb4MIMzFCQ491NRgQzfc4yk5l+QyFiL6g=; b=UKUGWXeIB1kU4jeBC1bKuVgsrR1myqsVCqbHa5kiuNi78yQ56jQ4D0el1RggT9YaFc r1E1MHr12P9PeFiISVGbM1UebJ3/MUFdOhlFIC/R2K+kEKvhYy38f9/ym0fsNCma0Bec xAEQIB5I53gKr4K9rduqi9dFuGvfw+XdSxs10SN4ncuISmAwHleq+RR5AIG154Fp6Lti vBM9lJAiJeJH3B9vqPcgEP4ed4VnSiT9f7sSWgRFWExx0Lv8Y0OvQFjdzaFXi0wqf28s 1UugD64v+7aPHLBf7Qo3NEKjydu4CSbq4HANfAx6eDhrZQ7seGfrVwlIY6bnbGq14gnG ZUDQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t38si1477121pgl.497.2019.05.03.02.36.07; Fri, 03 May 2019 02:36:22 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727059AbfECJct (ORCPT + 99 others); Fri, 3 May 2019 05:32:49 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:26709 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1727005AbfECJcs (ORCPT ); Fri, 3 May 2019 05:32:48 -0400 X-UUID: 421338f0caaf440a869a180a20173452-20190503 X-UUID: 421338f0caaf440a869a180a20173452-20190503 Received: from mtkexhb02.mediatek.inc [(172.21.101.103)] by mailgw02.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 383949267; Fri, 03 May 2019 17:32:42 +0800 Received: from mtkcas08.mediatek.inc (172.21.101.126) by mtkmbs01n2.mediatek.inc (172.21.101.79) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Fri, 3 May 2019 17:32:40 +0800 Received: from mtkslt302.mediatek.inc (10.21.14.115) by mtkcas08.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Fri, 3 May 2019 17:32:41 +0800 From: Hsin-Hsiung Wang To: Lee Jones , Rob Herring , Mark Brown , Matthias Brugger CC: Liam Girdwood , Mark Rutland , Eddie Huang , Sean Wang , Alessandro Zummo , Alexandre Belloni , Hsin-Hsiung Wang , , , , , , , Ran Bi Subject: [PATCH v3 09/10] rtc: mt6397: fix alarm register overwrite Date: Fri, 3 May 2019 17:31:16 +0800 Message-ID: <20190503093117.54830-10-hsin-hsiung.wang@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190503093117.54830-1-hsin-hsiung.wang@mediatek.com> References: <20190503093117.54830-1-hsin-hsiung.wang@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain X-TM-SNTS-SMTP: 935890C05F9D5BE6449D34144142DCABCB0F9718DE15F49E5F1BD564D204A59D2000: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") 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 e9a25ec4d434..f85f1fc29e32 100644 --- a/drivers/rtc/rtc-mt6397.c +++ b/drivers/rtc/rtc-mt6397.c @@ -55,6 +55,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) @@ -111,7 +119,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); @@ -233,12 +241,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--; @@ -259,14 +267,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, -- 2.18.0