Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp745565imc; Sun, 10 Mar 2019 20:49:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqwb3+Ein9Qvq7uaXb6+DF7ncYP3kNiV91C9zS0RdkyXCZ1BAlXvqCmBzm8/apFl/0czGRsd X-Received: by 2002:a65:538b:: with SMTP id x11mr17646634pgq.35.1552276176090; Sun, 10 Mar 2019 20:49:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552276176; cv=none; d=google.com; s=arc-20160816; b=Sl+utnnG1NK6Pw8ZAz99iO0pOKdoLcj6Lvgw03gsYOd8MVxE/X5qY6j+jCdysalWtM CIPTJLupFE6S63kVUeZZFlOM8lSWFVyR+OL1J0Q96qDv7zHENl1JS5K/j0cPFt3YsYsw vTCIfF84pN/MBcU/wGAeqO7el2D4r0/VPqpVcSnMMz175Jmi4MsfBAIuLBT0jGq5ktmd PP0fyP2c0rfEMMSjJU5fgnZYnsOMVkjL50n/+ypF+9nelRbbIOvcBG8lHhypD+anS/DD raPwXsu/tJ96Tr/Ddjlk9KsboOldS5+e7CpnuNfIDwk9YoICh65WF91+MX5tXmsRvyuv XKaw== 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=quAZX2R0Xy4vON3KTDhtBrRhbpg6hml7a9OtvFPi0SY=; b=ktfLOwpR1rpF6eHqDka0jv6dacr2ESIlgsz1l6jF2j+VUu4eQ9a+nC5NKsVIzQ6yhJ 8djw8QVZQwfoOrSA7kuS0QgLKmUd2+1HmqMWEqh0uzbinkLjEhmzvqufpFvMCtlpf+d8 Ngyyl7Z9vhHFMVPXe87P4WoBKV4xMVgBn4B11Pi00wuqCASxlwPPf83TJ1lYBazGRKA6 kj+gBQJLDT5Pzn8kJasq/WMkiNNl9wSLxw/MUmvGInBdfA/gtlIqdd1gGoBMToFrxRcf FnFKa1giRKZRmXFACMG2I+3waBgQVZJnYJ6WGblHARLUSH5bSp2PP5sXpzMKuUZqGTjj 9ISg== 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 cn17si4569537plb.139.2019.03.10.20.49.20; Sun, 10 Mar 2019 20:49:36 -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 S1727392AbfCKDs0 (ORCPT + 99 others); Sun, 10 Mar 2019 23:48:26 -0400 Received: from mailgw01.mediatek.com ([210.61.82.183]:45827 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1727380AbfCKDsY (ORCPT ); Sun, 10 Mar 2019 23:48:24 -0400 X-UUID: 25da669196ff4ad1a502733055c99b0b-20190311 X-UUID: 25da669196ff4ad1a502733055c99b0b-20190311 Received: from mtkcas07.mediatek.inc [(172.21.101.84)] by mailgw01.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 790900582; Mon, 11 Mar 2019 11:48:15 +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; Mon, 11 Mar 2019 11:48:08 +0800 Received: from mtkslt302.mediatek.inc (10.21.14.115) by MTKCAS06.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Mon, 11 Mar 2019 11:48:08 +0800 From: Hsin-Hsiung Wang To: Lee Jones , Rob Herring , Matthias Brugger , Mark Brown , Eddie Huang CC: Marc Zyngier , , , , , , , Liam Girdwood , Mark Rutland , Sean Wang , Alessandro Zummo , Alexandre Belloni , Ran Bi Subject: [PATCH v2 8/9] rtc: mt6397: fix alarm register overwrite Date: Mon, 11 Mar 2019 11:46:30 +0800 Message-ID: <1552275991-34648-9-git-send-email-hsin-hsiung.wang@mediatek.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1552275991-34648-1-git-send-email-hsin-hsiung.wang@mediatek.com> References: <1552275991-34648-1-git-send-email-hsin-hsiung.wang@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain X-TM-SNTS-SMTP: D462C1D854FB098073C8CD4BD911D4ADF3E2914E523C0DA2DA6314C89DC79DE62000: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 e9a25ec..f85f1fc 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, -- 1.9.1