Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp1437627imc; Mon, 11 Mar 2019 13:51:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqz3gYPnGW0RiXR/Kh667R7/axlBs65cC4lo858ZYe29Xs+yoUuCU3jX/Ik9YBV5GHjkDID1 X-Received: by 2002:a62:f517:: with SMTP id n23mr35163322pfh.209.1552337476939; Mon, 11 Mar 2019 13:51:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552337476; cv=none; d=google.com; s=arc-20160816; b=DDvWvmxpoPccO6kSp7klAOFCczWDwWC5UlDaDXZROI34tDf7tA1zxDSlNzYil5MsOc SxSM5JbVA23VQxi6YvKKspqNzS5Y2nOX+jo52sAJnBu0oHVKPPDKbdFp4C7P6r2ySH9C epqvv3p5/qKxQXsSwNrk4E1x352A0ZyABhBx292wyDyNc+rInrKuKzesG7UQntd8Pt/m B43YU6PG9VUE/DRSTW6CS4dcS7BkJ/tRjUR0wFrRwMn0cDKSFW9BYzDNTE+5pW/2aj5h GfHiejCwuuG25pYcZUbzNuVGZp5d+wFuSTwbFIFjhMsx0q3Z49lbhnPXctRd6kBqF7J5 lUdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=zBlfRrlP5Cv8iOIJfxikFgNoCF5i+ZaEiTkGk8DCPGU=; b=ODFbO0sx8EO2lFCx3crX/3AZQNwrSqGdIN7jkLv/rQpqiBYFzojeNIkEikyMkPY6s9 DP4V/JF/1v6lBpUZ6eA1/oc+v0pVTS8qGto1cRx9unGatnqM/4chFdK1spbVJDrRM1wn hhJf5mWb2qIEBJoutRGfh4sGgnYeQ/l94euHDZplhmGHxCGt/loBAZ9jvc2sScojomv6 JdqQxJ0LGJX1ria3JktxCH3QMQxBgISpFcuQ0zIBjLMVaQaEPioH5WJh9mAuyEyWgYz1 ZTqTLrl79rfgT7vdi58RnHSEvjIPLtwJD7fApgURk8DhcZ5/sZdDYYL1E66taPSnSRB4 5vcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=f2b7cfq4; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l16si5750428pgh.509.2019.03.11.13.51.00; Mon, 11 Mar 2019 13:51:16 -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; dkim=pass header.i=@kernel.org header.s=default header.b=f2b7cfq4; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728279AbfCKUug (ORCPT + 99 others); Mon, 11 Mar 2019 16:50:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:37842 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728067AbfCKUuf (ORCPT ); Mon, 11 Mar 2019 16:50:35 -0400 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 13EF221741; Mon, 11 Mar 2019 20:50:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1552337434; bh=WmnWnvhH8xU87ulSyPbAeUXZlyUM3QlsDz8cNEfmt0s=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=f2b7cfq4PQ89SN1Xoi9Ha237YKmHKyacm71MLg50GMSyBhl9qOSATAWSh5ZyuS7GG jY/vEUQWyoFxwjRhDcL48lcZkHhFEZvPUklyhycHtsEq6HF8chQhaBGtmXBdnPj5tr +tUsZzm/aqFKsuTLjt723hDkW+gpYzA0cIkeOKEw= Received: by mail-wm1-f46.google.com with SMTP id a188so481860wmf.3; Mon, 11 Mar 2019 13:50:34 -0700 (PDT) X-Gm-Message-State: APjAAAUpL9/LdspRdlpWjhnKCn/Oxc3p55vS6ACI73f3/k6735FG6zJp Gn6u6J8m1b79AASm9F/T97STRJ+hWQfkqH5P0nc= X-Received: by 2002:a1c:234d:: with SMTP id j74mr75208wmj.130.1552337432486; Mon, 11 Mar 2019 13:50:32 -0700 (PDT) MIME-Version: 1.0 References: <1552275991-34648-1-git-send-email-hsin-hsiung.wang@mediatek.com> <1552275991-34648-9-git-send-email-hsin-hsiung.wang@mediatek.com> In-Reply-To: <1552275991-34648-9-git-send-email-hsin-hsiung.wang@mediatek.com> From: Sean Wang Date: Mon, 11 Mar 2019 13:50:21 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 8/9] rtc: mt6397: fix alarm register overwrite To: Hsin-Hsiung Wang Cc: Lee Jones , Rob Herring , Matthias Brugger , Mark Brown , Eddie Huang , linux-rtc@vger.kernel.org, devicetree@vger.kernel.org, Alexandre Belloni , srv_heupstream , Alessandro Zummo , Marc Zyngier , Ran Bi , Sean Wang , linux-kernel@vger.kernel.org, Liam Girdwood , linux-mediatek@lists.infradead.org, Mark Rutland , linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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