Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1339898yba; Tue, 2 Apr 2019 07:09:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqwT/5R5hY1SHWBpVhb5pU/jSlaNaYcm9QgLfNFEbKDGMvH6SyvBaxKkKZz7Xx866HLq2dqn X-Received: by 2002:a63:be02:: with SMTP id l2mr44708661pgf.48.1554214187656; Tue, 02 Apr 2019 07:09:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554214187; cv=none; d=google.com; s=arc-20160816; b=d5MtA5YIXVaKEpFro8L1CHZh8J/3gApQZ7kAMJM3R36e28sI+NiJZyCQJR4tHzfls+ aXaQpl6tVw/g3Jtrt12Ue5jcM9Q6Ggm+mpYAAkeoT9BlZqp9uwqhLoAvcqXKwNtU6gHF GJHYO09zei5l1JqRsBeuPiVd23vOyU7dRDYvDMGxLE0f+o/JyGbQwqDuXBdaJy/GiGBm bhLvfvAhb6+25mGBVhiLAzCS+6Pf9U7gG+VcUwoK69sY51SDCIzpqwvjxVxsQ0c6YEjw PmrMmOwlDxV8HLyJ3YlshEnE0SSpKZ4acMUFk+LsHcs07jpd+xJcNrVZ4P/S0qmNeMKz 79og== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=l7B80GpUofOJ882A4psDvqiNfjSks4hFdkoqB9/gvv0=; b=uh4rJYu4xG+LDBoUfpRmvyj90cfxp2R/0g+f5Ymsy1dEkUZHJq+S+no5nObANo0LQl OROVI7yYknQCPyoc9rhofdXFp7cfLJURH8iopAQFnhvOBy1hhbqf2WdLxiH2omph2JAx 3Z4aCAetR2qCChd7gGqPkVcoNGTQ9v3S41kMQoZfOsNZ2n+QW5gJj+NZkb6gziht3H7L VJt9a27RFyPGuk2KY0JNi4QvRnLRFaF2u3Q787vjTyH0rnA0VPzsDAwCM8MkzN2LgX6f N4NtwLarXPCLaVPf7dLESNIT/FroGPySRYNvYqEZ0D6ep9pt2mvRwrPRe5knYnL5hRPz 7SpA== 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 t6si10935940pgt.476.2019.04.02.07.09.31; Tue, 02 Apr 2019 07:09: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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731972AbfDBOHY (ORCPT + 99 others); Tue, 2 Apr 2019 10:07:24 -0400 Received: from relay11.mail.gandi.net ([217.70.178.231]:57101 "EHLO relay11.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726903AbfDBOHW (ORCPT ); Tue, 2 Apr 2019 10:07:22 -0400 Received: from localhost (alyon-652-1-60-19.w109-213.abo.wanadoo.fr [109.213.83.19]) (Authenticated sender: alexandre.belloni@bootlin.com) by relay11.mail.gandi.net (Postfix) with ESMTPSA id D5FEA100016; Tue, 2 Apr 2019 14:07:16 +0000 (UTC) Date: Tue, 2 Apr 2019 16:07:15 +0200 From: Alexandre Belloni To: Hsin-Hsiung Wang Cc: Lee Jones , Rob Herring , Matthias Brugger , Mark Brown , Eddie Huang , Marc Zyngier , srv_heupstream@mediatek.com, linux-mediatek@lists.infradead.org, linux-rtc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, Liam Girdwood , Mark Rutland , Sean Wang , Alessandro Zummo , Ran Bi Subject: Re: [PATCH v2 8/9] rtc: mt6397: fix alarm register overwrite Message-ID: <20190402140715.GD22216@piout.net> References: <1552275991-34648-1-git-send-email-hsin-hsiung.wang@mediatek.com> <1552275991-34648-9-git-send-email-hsin-hsiung.wang@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1552275991-34648-9-git-send-email-hsin-hsiung.wang@mediatek.com> User-Agent: Mutt/1.11.3 (2019-02-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/03/2019 11:46:30+0800, 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") > > Signed-off-by: Ran Bi Acked-by: Alexandre Belloni > --- > 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 > -- Alexandre Belloni, Bootlin Embedded Linux and Kernel engineering https://bootlin.com