Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp5905262ybv; Wed, 12 Feb 2020 02:26:00 -0800 (PST) X-Google-Smtp-Source: APXvYqyI8C2OESdpO4cj847okGkBsJDgv45VT3b9CbLJkMDopyJsRiuPw8WuSwTZvU3tChChgSsN X-Received: by 2002:a05:6830:12d5:: with SMTP id a21mr8847601otq.296.1581503160312; Wed, 12 Feb 2020 02:26:00 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1581503160; cv=pass; d=google.com; s=arc-20160816; b=BMOScsqZzFRZF7QHsYJQkNSITKMB1Sjak3fD6+7kGmn7Oa+hsbgeK5vc/1jFODYrWm q94Rtf8lMViWTESGYpdvH8JEqjFzaBRvvIYRtrri7Ss68WDyQSrjpp8eZnusVd4haNBS nyLs+ogFunSTPHaOyDDu4cUkSddEzcqBm68XBK7MqELRM+aUSTgn+5akEfYSyx26dWgY CM9qjNiPzNVjDrAVed3jq/RQ+Os8DSMlq34+QdGgmaxZ3QwuL3FogZ/F+FaGULZ8LiX6 AV8cLrJw4j7HYa+LlvivsBatkqYGaLzgPnmsl4/Qw+6MREeRQ8piJY4HRojdGNPEdaNs 853w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from:dkim-signature; bh=L5PQ0RqpC2Wpwqq+ketZzRjv26UCHXVFgynBJbfC4rE=; b=ycdsqVwvfo1/d2ZCMNSFW3lCoDFhacH1ubNLXAQoBmwL6jbv1LC+tQKP5zxn6aWtVR pin+yV8ua7zBXy4oVBn6u8Ew2m7bgFiNCqZoiJCiR6Wn4WKI1wiR7HdoqRstBnNWOGtm 4dTWg/WbMhQ1u3hyaAbXHyoiXyofys7sEQUG0pGbTJwf0xqw+FplF6N5AhuvjvhxDxXc MiwnlSu6L2YvCpGpkHFkgqtOjM1QVmLO0uqvHsh6vlCHOKpDNYZBBU1qatTPJQBd+0sx HJsvjfYVErzTc7tdJOU1eq7ZN7iMRYUzI58q1AOnPD1EKYcx7suJinpXXS7UmbHrkmIT 46Zg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@xilinx.onmicrosoft.com header.s=selector2-xilinx-onmicrosoft-com header.b="d/R3EY4O"; arc=pass (i=1 spf=pass spfdomain=xilinx.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 71si690otm.111.2020.02.12.02.25.47; Wed, 12 Feb 2020 02:26:00 -0800 (PST) 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=@xilinx.onmicrosoft.com header.s=selector2-xilinx-onmicrosoft-com header.b="d/R3EY4O"; arc=pass (i=1 spf=pass spfdomain=xilinx.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 S1727361AbgBLKZh (ORCPT + 99 others); Wed, 12 Feb 2020 05:25:37 -0500 Received: from mail-mw2nam12on2076.outbound.protection.outlook.com ([40.107.244.76]:36577 "EHLO NAM12-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725710AbgBLKZg (ORCPT ); Wed, 12 Feb 2020 05:25:36 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NTxLgDZYQOgZH1aOOXB/EYXgbxKTTAXUng4LinGEAjBFfyKHtZhjeYsBBYYFVC0lF7H2/o76Wn9v8FGY1kfNnTX5sPY1RmBXABBkJNffrzkkhKD29IKnjAwDGx04zH6ni5J1/7OEi+vIVZqUy1nuaDUJhcUi5SgOlpUvblwChSqnN8UBFeLgnblGdpzUZKbDKxYGWnXf6bHNZDXo+uZKPSrXhoNae/6R/+iQFLlrGtJ1yk/8nmrBX/4fZIVcuPYQ41lY/oURHFVpq7gP48mb4gq249QE5lDRQ2Xnk+jsbYZJle9QaIcwBHRlF0UDWdZF+gtTifMmLwWc/U29gG4rgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=L5PQ0RqpC2Wpwqq+ketZzRjv26UCHXVFgynBJbfC4rE=; b=f6CrdV2MRpVzZiuNJDsNQtFWmB+ueEEFjSH8NJUoh9Y6tNQ3CvA/45A9LcObYTfe6UyopBDAHhpdY8ceNOGjNNMaBwvuntvAoVjCesqWliXJcj9sHvyX4sdb0MoO+9lf1oex/uDlUFM3koTRyff0sm8mpKUIOc6cs4H+AckJy0jZ0QJilpuqGNLjsZV5Kkl1uCF4VrH+8X33sg5ZLxV0sTDFapDvPGT4DLtHAsSf/HvyTNzKoE65jVzj5qoMITyv2SdZ668hsDsM4lk1MVpJli8s8S6nWpHqOsrJA5WPXvaLTMEwU6Se3KyYL9/DhEIebvx09Gi5k/VPrsHZ4QC7/w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.60.83) smtp.rcpttodomain=towertech.it smtp.mailfrom=xilinx.com; dmarc=bestguesspass action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=L5PQ0RqpC2Wpwqq+ketZzRjv26UCHXVFgynBJbfC4rE=; b=d/R3EY4OqW5BdutpvTrVSI+7/ldOMDlD4BmDe2twKCTSLsqYUn/mQKh7TI5RG2Q3z2yCia3oNGCZmCPTaIc1j5VkSyxfdsKvjNo0OkbW6Rfm9xHtMPpxzR3sMRryyMaNlf5jFGuiKaBrwokNOYo+AcHvyVCOjPrWUeNLC2UOHvg= Received: from BYAPR02CA0065.namprd02.prod.outlook.com (2603:10b6:a03:54::42) by DM6PR02MB6988.namprd02.prod.outlook.com (2603:10b6:5:22c::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2707.21; Wed, 12 Feb 2020 10:24:58 +0000 Received: from CY1NAM02FT031.eop-nam02.prod.protection.outlook.com (2a01:111:f400:7e45::207) by BYAPR02CA0065.outlook.office365.com (2603:10b6:a03:54::42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2707.29 via Frontend Transport; Wed, 12 Feb 2020 10:24:57 +0000 Authentication-Results: spf=pass (sender IP is 149.199.60.83) smtp.mailfrom=xilinx.com; towertech.it; dkim=none (message not signed) header.d=none;towertech.it; dmarc=bestguesspass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.60.83 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.60.83; helo=xsj-pvapsmtpgw01; Received: from xsj-pvapsmtpgw01 (149.199.60.83) by CY1NAM02FT031.mail.protection.outlook.com (10.152.75.180) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.20.2729.22 via Frontend Transport; Wed, 12 Feb 2020 10:24:57 +0000 Received: from unknown-38-66.xilinx.com ([149.199.38.66] helo=xsj-pvapsmtp01) by xsj-pvapsmtpgw01 with esmtp (Exim 4.63) (envelope-from ) id 1j1pCT-0007tp-1J; Wed, 12 Feb 2020 02:24:57 -0800 Received: from [127.0.0.1] (helo=localhost) by xsj-pvapsmtp01 with smtp (Exim 4.63) (envelope-from ) id 1j1pCN-0002z7-SP; Wed, 12 Feb 2020 02:24:51 -0800 Received: from [10.140.6.6] (helo=xhdappanad40.xilinx.com) by xsj-pvapsmtp01 with esmtp (Exim 4.63) (envelope-from ) id 1j1pCE-0002xF-Vj; Wed, 12 Feb 2020 02:24:43 -0800 From: Srinivas Neeli To: a.zummo@towertech.it, alexandre.belloni@bootlin.com, michal.simek@xilinx.com, sgoud@xilinx.com, shubhraj@xilinx.com Cc: linux-rtc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, git@xilinx.com Subject: [PATCH v2] rtc: zynqmp: Clear alarm interrupt status before interrupt enable Date: Wed, 12 Feb 2020 15:54:39 +0530 Message-Id: <1581503079-387-1-git-send-email-srinivas.neeli@xilinx.com> X-Mailer: git-send-email 2.7.4 X-TM-AS-Product-Ver: IMSS-7.1.0.1224-8.2.0.1013-23620.005 X-TM-AS-User-Approved-Sender: Yes;Yes X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:149.199.60.83;IPV:;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(4636009)(376002)(396003)(136003)(39860400002)(346002)(189003)(199004)(70586007)(70206006)(8936002)(2906002)(316002)(4326008)(81166006)(356004)(81156014)(9786002)(6666004)(8676002)(44832011)(36756003)(2616005)(6636002)(336012)(107886003)(26005)(7696005)(5660300002)(426003)(186003)(478600001);DIR:OUT;SFP:1101;SCL:1;SRVR:DM6PR02MB6988;H:xsj-pvapsmtpgw01;FPR:;SPF:Pass;LANG:en;PTR:unknown-60-83.xilinx.com;MX:1;A:1; MIME-Version: 1.0 Content-Type: text/plain X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6978c83d-203a-4334-7012-08d7afa5cf21 X-MS-TrafficTypeDiagnostic: DM6PR02MB6988: X-Microsoft-Antispam-PRVS: X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-Forefront-PRVS: 0311124FA9 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: GJGRO5dcrSFeo+TKf4Sk2P2Sd3u1zwA3PVxaji0o470JB3taNwXKPtZYetBktCY/IL6LsuuUP5fAaq880Gbwk1MR0rIj96WrzC6o6Ptg6emssC8rWxmaAit5SjIioeVRlO4x46BPvnl3EdjrJ8IPHLBdzB3xoo0ZNZNV2FmfHtE0KwekAWd1sBCOVaCmxl0GtXMzJHGqWU3seySdB67CmJXQFvj4xltkDsCQyt78dU4aG2PmvvZn+lD7qbnPwLuccct9gvpoBmzTzYhJVr6w7DgSKgeYNCx6glmoH5hTiAlcQJf89oQJTvTqN1McTtMsjbKS7hAreI0etfootKrq14Oy8QbJTpekzPCvflhZGfNl0iH3gHmYVxnnVgblFCrM7f4TomamlKrUCOYxn5NhZPvIxwKkK/B0iOPpbNBefueRPWxKSCF2JwmgUstQ6Jbq X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Feb 2020 10:24:57.4463 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6978c83d-203a-4334-7012-08d7afa5cf21 X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.60.83];Helo=[xsj-pvapsmtpgw01] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR02MB6988 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Fix multiple occurring interrupts for alarm interrupt. RTC module doesn't clear the alarm interrupt status bit immediately after the interrupt is triggered.This is due to the sticky nature of the alarm interrupt status register. The alarm interrupt status register can be cleared only after the second counter outruns the set alarm value. To fix multiple spurious interrupts, disable alarm interrupt in the handler and clear the status bit before enabling the alarm interrupt. Fixes: 11143c19eb57 ("rtc: add xilinx zynqmp rtc driver") Signed-off-by: Srinivas Neeli --- Changes in V2: Addressed Michal Simek comments - Removed new line in declartion part. - Added new line before return. --- drivers/rtc/rtc-zynqmp.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/drivers/rtc/rtc-zynqmp.c b/drivers/rtc/rtc-zynqmp.c index 5786866c09e9..4b1077e2f826 100644 --- a/drivers/rtc/rtc-zynqmp.c +++ b/drivers/rtc/rtc-zynqmp.c @@ -38,6 +38,8 @@ #define RTC_CALIB_DEF 0x198233 #define RTC_CALIB_MASK 0x1FFFFF +#define RTC_ALRM_MASK BIT(1) +#define RTC_MSEC 1000 struct xlnx_rtc_dev { struct rtc_device *rtc; @@ -123,11 +125,28 @@ static int xlnx_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) static int xlnx_rtc_alarm_irq_enable(struct device *dev, u32 enabled) { struct xlnx_rtc_dev *xrtcdev = dev_get_drvdata(dev); + unsigned int status; + ulong timeout; + + timeout = jiffies + msecs_to_jiffies(RTC_MSEC); + + if (enabled) { + while (1) { + status = readl(xrtcdev->reg_base + RTC_INT_STS); + if (!((status & RTC_ALRM_MASK) == RTC_ALRM_MASK)) + break; + + if (time_after_eq(jiffies, timeout)) { + dev_err(dev, "Time out occur, while clearing alarm status bit\n"); + return -ETIMEDOUT; + } + writel(RTC_INT_ALRM, xrtcdev->reg_base + RTC_INT_STS); + } - if (enabled) writel(RTC_INT_ALRM, xrtcdev->reg_base + RTC_INT_EN); - else + } else { writel(RTC_INT_ALRM, xrtcdev->reg_base + RTC_INT_DIS); + } return 0; } @@ -183,8 +202,8 @@ static irqreturn_t xlnx_rtc_interrupt(int irq, void *id) if (!(status & (RTC_INT_SEC | RTC_INT_ALRM))) return IRQ_NONE; - /* Clear RTC_INT_ALRM interrupt only */ - writel(RTC_INT_ALRM, xrtcdev->reg_base + RTC_INT_STS); + /* Disable RTC_INT_ALRM interrupt only */ + writel(RTC_INT_ALRM, xrtcdev->reg_base + RTC_INT_DIS); if (status & RTC_INT_ALRM) rtc_update_irq(xrtcdev->rtc, 1, RTC_IRQF | RTC_AF); -- 2.7.4