Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp3463150imc; Wed, 13 Mar 2019 19:47:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqygB4R63BUdS6cxGuEw/ert4HERGq23me8YguAoIdVEKIfArZbErJ6zIxAUj5GDhfIaDyLF X-Received: by 2002:a65:5cc7:: with SMTP id b7mr43285419pgt.396.1552531632493; Wed, 13 Mar 2019 19:47:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552531632; cv=none; d=google.com; s=arc-20160816; b=BNIH4R6ufoeT9mtzOBJr99KU1bcVOYyFzcJjPGGEMuVBtJTnJKRvmpMl9vrBW60uOO YjKrI9M5vsfG1TnEAOEc0+2aj/BWQuTtqkg7Hg4MP/EqJYFVJaMsoUlp8PcYn1gOSOlo J/xMt2FWmIqrqOe3GP0DpB4Dw7po0TpoPFeEVHIlNg7+dSQWc3EML0NZPC5QI0sEG511 drnuFp4zS5KIoFe1PI7ahpAfWsGYXJ6rOKp0CRP6OkQzJayLDj3xn5D4OYvCA2VhtKnk t9l1Y2NLesFuvvUUiJPopyFzL0oSSc3d0dki4K8pcX2qbKrfp1oqb2ClJrtT+fl19gZX FnOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :references:in-reply-to:date:cc:to:from:subject:message-id; bh=yxWKoDJbRwnT+jcuVKiBvBRAc/T6rE87Ya22A7kCdvA=; b=lBqnHl/2ZCf233WkO/cfutjTw4HmOksLHfJpyS41w7IVpRU84L6Adg1+H1EqYoJt/J UiIvXphGmMlurQYe5SXKzkHwWPSu+6PPRW/iFJBMY52GIBinK8J0e7gZAndNNP3gSTSf 5Svg0XjpG/vuw0CM5u8bFr2E6vo6MzRhFuJYZEi4zkLrlDVHGo1cEEe0bLVdcC/rnhfq QQCTUgjXJ92RZV3ul3xXQ/EIYD3vT8vatixaZhUIlT9Wp/izbxF9vuqut4QA9uMMKpWl Vo3SK8pmyBN4ME7odtWs2gG+WoxCK2jcsOIfMaWQN2cMa0J5Mf8p9rYt4RPrYCu1EVtF xqlg== 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 31si12690048pld.6.2019.03.13.19.46.54; Wed, 13 Mar 2019 19:47:12 -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 S1727057AbfCNCqe (ORCPT + 99 others); Wed, 13 Mar 2019 22:46:34 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:4787 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726629AbfCNCqe (ORCPT ); Wed, 13 Mar 2019 22:46:34 -0400 X-UUID: 7ea9410bb8704279b19a12cda38dce51-20190314 X-UUID: 7ea9410bb8704279b19a12cda38dce51-20190314 Received: from mtkcas07.mediatek.inc [(172.21.101.84)] by mailgw02.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 1858234063; Thu, 14 Mar 2019 10:46:24 +0800 Received: from MTKCAS36.mediatek.inc (172.27.4.186) by mtkmbs01n2.mediatek.inc (172.21.101.79) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Thu, 14 Mar 2019 10:46:22 +0800 Received: from [10.17.3.153] (172.27.4.253) by MTKCAS36.mediatek.inc (172.27.4.170) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Thu, 14 Mar 2019 10:46:21 +0800 Message-ID: <1552531581.18390.8.camel@mhfsdcap03> Subject: Re: [PATCH v2 8/9] rtc: mt6397: fix alarm register overwrite From: mtk14576 To: Sean Wang CC: , Hsin-Hsiung Wang , Lee Jones , "Rob Herring" , Matthias Brugger , Mark Brown , Eddie Huang , , , Alexandre Belloni , srv_heupstream , Alessandro Zummo , Marc Zyngier , Sean Wang , , Liam Girdwood , , Mark Rutland , Date: Thu, 14 Mar 2019 10:46:21 +0800 In-Reply-To: References: <1552275991-34648-1-git-send-email-hsin-hsiung.wang@mediatek.com> <1552275991-34648-9-git-send-email-hsin-hsiung.wang@mediatek.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.2.3-0ubuntu6 Content-Transfer-Encoding: 7bit MIME-Version: 1.0 X-TM-SNTS-SMTP: BE8084FD0CFCDD336590D1C479EFF7B2D37843178BD9FCE3A754782EC6B2B1672000:8 X-MTK: N Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On Mon, 2019-03-11 at 13:50 -0700, Sean Wang wrote: > Hi, > > On Sun, Mar 10, 2019 at 8:49 PM Hsin-Hsiung Wang > wrote: > > > > 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") > > > > add a Cc: stable@vger.kernel.org here to apply to all stable kernels > for the critical fixup patch. > > > 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; > > + > > Why did we need an additional regmap_bulk_read here? I would suppose > data[RTC_OFFSET_*] & ~(RTC_AL_*_MASK) is always equal to 0. In bootloader, RTC init part need to operate these RTC_AL_* registers high byte for RTC operating mode settings and data storage, while RTC_AL_* low byte was used as alarm register here. So we need an additional regmap_bulk_read here to keep the RTC settings correct. > > It might be another fixup since change is not being mentioned in the > git message. > > > + 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 > > > > > > _______________________________________________ > > Linux-mediatek mailing list > > Linux-mediatek@lists.infradead.org > > http://lists.infradead.org/mailman/listinfo/linux-mediatek