Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp160883pxy; Fri, 30 Apr 2021 02:41:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzSEh7mrynLsHZ69XtKarLzPQ6fyTktWAuJzQA1HbXVuD3N/tnvwwxmgr7Z2SzGPDErXoLX X-Received: by 2002:a65:4341:: with SMTP id k1mr3826057pgq.178.1619775703429; Fri, 30 Apr 2021 02:41:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619775703; cv=none; d=google.com; s=arc-20160816; b=GMYa5OiLl18H9WVviYqc/UsXWeAdkymIW5cUtx7GpiLVfRvmt42aljRSmT81V5jYtk fLMAIbsyUfiaw/Qg5+66zqrqC0vk0g1/Hn+xP/TPUKFPtsrHfixBOlDUZJ8Bn7gUe/rp k84JZ3n0Z1yZzHWtSDMZccyxm64lfSZbPB34Pk+ukNeEc3nQa2bIB7IIRmPL0Tp7nRO6 jP4eqbnHJup70t8itXlkJCxzb17AXjkyoZvvK1AvLO3pl1Io2QBk1Mi3+g52eCrylC8Z UVuXlAjR9isQHuzKJaHt3UEDr90o7nqvRBo9v66gD4nTQ5q+G7RLxWL1/VUXFJh+OpZX HJpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=ZkcLYw6DIbNziAeHkuJv3oOINX5Ba+MXDBKYtk7lfPY=; b=T94YHvzdcdEpLzUdxR7Q5GQLxrSXY5onPy2z6TL+Asel21TivQtLO5SLLu59M1Rzlo RvGKRUlZeX0z4pNHCnB7X4E47lPKrWdxziWtXYmeWvHLiLlM0XShk1NjgT3ergE0m6ob aERfvZgMJzKmXpB4H5rCQdPrqc2W1lbs7SiT3LycaeJXaWEE/6LG0ulQOk2T8z/yOJy6 bMq7clsJ7v1cmSa7aY6dvnwlbGhsSZ/zHOYwmEYtTH68LFAoNuoqh6eBtK4CB/qxA+VE eLAKGa4Sdg5Xf/ghJniPcaD2bqsmc7B98X3OByZNIwCgCvcNS8lF7kV3DhRFIu4lcO5n WdTg== 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 m4si2763620plt.179.2021.04.30.02.41.28; Fri, 30 Apr 2021 02:41:43 -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 S231378AbhD3JkL (ORCPT + 99 others); Fri, 30 Apr 2021 05:40:11 -0400 Received: from mx2.suse.de ([195.135.220.15]:51708 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229543AbhD3JkL (ORCPT ); Fri, 30 Apr 2021 05:40:11 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 1EAC9B080; Fri, 30 Apr 2021 09:39:22 +0000 (UTC) From: Mian Yousaf Kaukab To: a.zummo@towertech.it, alexandre.belloni@bootlin.com Cc: linux-rtc@vger.kernel.org, linux-kernel@vger.kernel.org, biwen.li@nxp.com, Mian Yousaf Kaukab Subject: [PATCH v3] rtc: pcf2127: handle timestamp interrupts Date: Fri, 30 Apr 2021 11:39:25 +0200 Message-Id: <20210430093925.17363-1-ykaukab@suse.de> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org commit 03623b4b041c ("rtc: pcf2127: add tamper detection support") added support for timestamp interrupts. However they are not being handled in the irq handler. If a timestamp interrupt occurs it results in kernel disabling the interrupt and displaying the call trace: [ 121.145580] irq 78: nobody cared (try booting with the "irqpoll" option) ... [ 121.238087] [<00000000c4d69393>] irq_default_primary_handler threaded [<000000000a90d25b>] pcf2127_rtc_irq [rtc_pcf2127] [ 121.248971] Disabling IRQ #78 Handle timestamp interrupts in pcf2127_rtc_irq(). Set a flag to mark the timestamp as valid and only report to sysfs if the flag is set. Signed-off-by: Mian Yousaf Kaukab --- history: v3: -Restore call to pcf2127_wdt_active_ping() in timestamp0_store(). It was removed by mistake. v2: -Add a flag to mark the occurrence of timestamp interrupt -Add Biwen Li in Cc drivers/rtc/rtc-pcf2127.c | 48 +++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/drivers/rtc/rtc-pcf2127.c b/drivers/rtc/rtc-pcf2127.c index d13c20a2adf7..d8dec4cbe39f 100644 --- a/drivers/rtc/rtc-pcf2127.c +++ b/drivers/rtc/rtc-pcf2127.c @@ -94,10 +94,18 @@ #define PCF2127_WD_VAL_MAX 255 #define PCF2127_WD_VAL_DEFAULT 60 +/* Mask for currently enabled interrupts */ +#define PCF2127_CTRL1_IRQ_MASK (PCF2127_BIT_CTRL1_TSF1) +#define PCF2127_CTRL2_IRQ_MASK ( \ + PCF2127_BIT_CTRL2_AF | \ + PCF2127_BIT_CTRL2_WDTF | \ + PCF2127_BIT_CTRL2_TSF2) + struct pcf2127 { struct rtc_device *rtc; struct watchdog_device wdd; struct regmap *regmap; + bool timestamp_valid; }; /* @@ -437,20 +445,33 @@ static int pcf2127_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) static irqreturn_t pcf2127_rtc_irq(int irq, void *dev) { struct pcf2127 *pcf2127 = dev_get_drvdata(dev); - unsigned int ctrl2 = 0; + unsigned int ctrl1, ctrl2; int ret = 0; + ret = regmap_read(pcf2127->regmap, PCF2127_REG_CTRL1, &ctrl1); + if (ret) + return IRQ_NONE; + ret = regmap_read(pcf2127->regmap, PCF2127_REG_CTRL2, &ctrl2); if (ret) return IRQ_NONE; - if (!(ctrl2 & PCF2127_BIT_CTRL2_AF)) + if (!(ctrl1 & PCF2127_CTRL1_IRQ_MASK || ctrl2 & PCF2127_CTRL2_IRQ_MASK)) return IRQ_NONE; - regmap_write(pcf2127->regmap, PCF2127_REG_CTRL2, - ctrl2 & ~(PCF2127_BIT_CTRL2_AF | PCF2127_BIT_CTRL2_WDTF)); + if (ctrl1 & PCF2127_CTRL1_IRQ_MASK) + regmap_write(pcf2127->regmap, PCF2127_REG_CTRL1, + ctrl1 & ~PCF2127_CTRL1_IRQ_MASK); - rtc_update_irq(pcf2127->rtc, 1, RTC_IRQF | RTC_AF); + if (ctrl2 & PCF2127_CTRL2_IRQ_MASK) + regmap_write(pcf2127->regmap, PCF2127_REG_CTRL2, + ctrl2 & ~PCF2127_CTRL2_IRQ_MASK); + + if (ctrl1 & PCF2127_BIT_CTRL1_TSF1 || ctrl2 & PCF2127_BIT_CTRL2_TSF2) + pcf2127->timestamp_valid = true; + + if (ctrl2 & PCF2127_BIT_CTRL2_AF) + rtc_update_irq(pcf2127->rtc, 1, RTC_IRQF | RTC_AF); pcf2127_wdt_active_ping(&pcf2127->wdd); @@ -475,19 +496,7 @@ static ssize_t timestamp0_store(struct device *dev, struct pcf2127 *pcf2127 = dev_get_drvdata(dev->parent); int ret; - ret = regmap_update_bits(pcf2127->regmap, PCF2127_REG_CTRL1, - PCF2127_BIT_CTRL1_TSF1, 0); - if (ret) { - dev_err(dev, "%s: update ctrl1 ret=%d\n", __func__, ret); - return ret; - } - - ret = regmap_update_bits(pcf2127->regmap, PCF2127_REG_CTRL2, - PCF2127_BIT_CTRL2_TSF2, 0); - if (ret) { - dev_err(dev, "%s: update ctrl2 ret=%d\n", __func__, ret); - return ret; - } + pcf2127->timestamp_valid = false; ret = pcf2127_wdt_active_ping(&pcf2127->wdd); if (ret) @@ -524,8 +533,7 @@ static ssize_t timestamp0_show(struct device *dev, if (ret) return ret; - if (!(data[PCF2127_REG_CTRL1] & PCF2127_BIT_CTRL1_TSF1) && - !(data[PCF2127_REG_CTRL2] & PCF2127_BIT_CTRL2_TSF2)) + if (!pcf2127->timestamp_valid) return 0; tm.tm_sec = bcd2bin(data[PCF2127_REG_TS_SC] & 0x7F); -- 2.26.2