Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp1718897pxb; Fri, 10 Sep 2021 12:09:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwQ/+EYnK82/ZxmsdN15gFtq8BpQJVlhwAAHBA0Pe6d7WpVEsTlN9SHrH9+561ApCU19LU4 X-Received: by 2002:a17:906:4452:: with SMTP id i18mr10546782ejp.374.1631300986009; Fri, 10 Sep 2021 12:09:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631300986; cv=none; d=google.com; s=arc-20160816; b=O0DB2/BEr7rc6vAVfAvCWQ4l7HH2H/VH0u76NGqzS9HLHMjmGWXxc6i+5pukqAGSLb vYXg1/Sexrf3GwCaqMAPPZviP3M7JLGnlhxZ8fbxjaA5Twa5t8w0LcsKqvvffhx94Ghv /OsA1RH9QK+CLkJSg+6j/lrTYM7NXT0obkVcO+UyB1R5ebcYdNnCc1snigsgEfX9gvSs 5Pzbc5mjdKdPlEn0HtkjC4DXsQogcnzIuPHJ7JYX+VR05bMrQhISXw8e/r00Ab7jvlzH rAtl1bKEea1Yxle3PaP4GZgyzA7N2q4/O3X5FfgMfgD6LFgMfAKXgNT4N0z5zhn+zvwa v8PQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=+ytH45YgrLXbcsu3BuJNkUFAa6sCUjE9f7K5VUWjsLQ=; b=WJGq0Qk35LJD+kLNFOvtE4gZm1gLxSNPExaNEpKmDershWWnztVaguXyX5f4n7NY9G Ws7rVx5Az+0AprlQk/z2BBLdoqz3AQmyfu+l+R7a0bvF1ifSqkwqIHYYK2lUivj+f2xp +ZGOTUQJLdT38TD4/i+24qKayo8KOKCWyctJx6KSMosF1Ujs2l6nUX6hWqsKSfVZEsek Itdk0L2M+PwFloKziTE7NCbZUc/B6iwEiHmDGaZdwdKLCOBR5s4ZqohVPz9ftCMJleN7 Mfl7gRb12J1/1gurkxIq7wD0Metl8T0wclbPHDlV+nLefcnLBtxZ1MUaYMqQqyyxZf1T /GXw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t12si2966739edc.33.2021.09.10.12.09.22; Fri, 10 Sep 2021 12:09:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232603AbhIJTGw (ORCPT + 99 others); Fri, 10 Sep 2021 15:06:52 -0400 Received: from relay11.mail.gandi.net ([217.70.178.231]:39271 "EHLO relay11.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229546AbhIJTGv (ORCPT ); Fri, 10 Sep 2021 15:06:51 -0400 Received: (Authenticated sender: alexandre.belloni@bootlin.com) by relay11.mail.gandi.net (Postfix) with ESMTPSA id 8B5BF100002; Fri, 10 Sep 2021 19:05:38 +0000 (UTC) Date: Fri, 10 Sep 2021 21:05:37 +0200 From: Alexandre Belloni To: "jianbin zhang (QUIC)" Cc: "a.zummo@towertech.it" , "linux-kernel@vger.kernel.org" , "linux-rtc@vger.kernel.org" Subject: Re: [PATCH] rtc: Disable alarm irq if alarm is enabled and alarm time is less than or equal to current time Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello, Please format your patch properly. On 10/09/2021 08:36:03+0000, jianbin zhang (QUIC) wrote: > If device is booted up by rtc alarm, the alarm irq will still be enabled and the alarm time is less than current rtc time before any alarm is set or canceled . > > If device is shut down this time, it will boot up automatically as the alarm irq is enabled and alarm time is less than current rtc time. > > > > For the situation that the alarm time and rtc time are equal to boot up the device, we expect irq to be false until another alarm is reconfigured, then irq becomes true again. > > > > So disable alarm irq if alarm is enabled and alarm time is less than or equal to current rtc time. > You should probably fix your driver instead of messing with the core. From what I understand, you have: 1/ set the alarm 2/ shutdown 3/ alarm happens, the device boots 4/ shutdown 5/ alarm irq is still set, device boots again At step 3, your driver has to acknowledge and clear the irq > Signed-off-by: Jinlong Mao > > > Signed-off-by: Jianbin Zhang > > > --- > > drivers/rtc/interface.c | 20 ++++++++++++-------- > > 1 file changed, 12 insertions(+), 8 deletions(-) > > > > diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c index 9a2bd4947007..69ac54a50542 100644 > > --- a/drivers/rtc/interface.c > > +++ b/drivers/rtc/interface.c > > @@ -479,6 +479,15 @@ int rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) } EXPORT_SYMBOL_GPL(rtc_set_alarm); > > +static void rtc_alarm_disable(struct rtc_device *rtc) { > > + if (!rtc->ops || !test_bit(RTC_FEATURE_ALARM, rtc->features) || !rtc->ops->alarm_irq_enable) > > + return; > > + > > + rtc->ops->alarm_irq_enable(rtc->dev.parent, false); > > + trace_rtc_alarm_irq_enable(0, 0); > > +} > > + > > /* Called once per device from rtc_device_register */ int rtc_initialize_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) { @@ -506,6 +515,9 @@ int rtc_initialize_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) > > rtc->aie_timer.enabled = 1; > > timerqueue_add(&rtc->timerqueue, &rtc->aie_timer.node); > > trace_rtc_timer_enqueue(&rtc->aie_timer); > > + } else if (alarm->enabled && (rtc_tm_to_ktime(now) >= > > + rtc->aie_timer.node.expires)) { > > + rtc_alarm_disable(rtc); > > } > > mutex_unlock(&rtc->ops_lock); > > return err; > > @@ -827,14 +839,6 @@ static int rtc_timer_enqueue(struct rtc_device *rtc, struct rtc_timer *timer) > > return 0; > > } > > -static void rtc_alarm_disable(struct rtc_device *rtc) -{ > > - if (!rtc->ops || !test_bit(RTC_FEATURE_ALARM, rtc->features) || !rtc->ops->alarm_irq_enable) > > - return; > > - > > - rtc->ops->alarm_irq_enable(rtc->dev.parent, false); > > - trace_rtc_alarm_irq_enable(0, 0); > > -} > > /** > > * rtc_timer_remove - Removes a rtc_timer from the rtc_device timerqueue > > -- > > 2.17.1 > -- Alexandre Belloni, co-owner and COO, Bootlin Embedded Linux and Kernel engineering https://bootlin.com