From patchwork Wed Aug 30 22:47:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Doug Berger X-Patchwork-Id: 13370810 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 44F55C83F01 for ; Wed, 30 Aug 2023 22:48:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=ZPDlSUCLkZr+jhCD3Tjz4RGa09hz6WxNdIZJiYJzppE=; b=bYRJFq7YGtA4dK 0OODik8LQqf/0HTKsIHuHlxzlEULD8zGylznY6O3cE8ltQE8u35cNy4QZgAyhKIY68bN90//wjBKn vktb+CIyqZ54zjl10Cc2VQyOJeeazJQfoFSeDBVR4sTMlci8swvKkMAXR/Gi7xTa0XrhNMnWEuuIG al1ee6SwDFFpdHdXqViXA8MqSnoaeWw6rjbIzHRVzh0CsdNVsHTBI/lLzuIC/5i34kF+ud9otd4my ZriRhZ7zzl9Mm1ZMYA/MTLGYjarJJdmunPFEwN2dEH/3x1k3s6L0egEpC9Nvq/Ef8j6EXHKsWVvNT xNEwHGEQNS2qNVUkC71Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qbTz0-00EIg5-1a; Wed, 30 Aug 2023 22:48:18 +0000 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qbTyy-00EIfh-2A for linux-arm-kernel@lists.infradead.org; Wed, 30 Aug 2023 22:48:18 +0000 Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-1bf55a81eeaso1303975ad.0 for ; Wed, 30 Aug 2023 15:48:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1693435695; x=1694040495; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=ubwb8ZkSJEXL4N31fP6n7OBgqr01nG/Maz7pQ2R1NuQ=; b=dhDksg2uCLcBEDfq86SWbydmmHD7jFHyFdRQ4qez/xHG66aMLZ1WlRtFv1lN2EN+Cb 8bwhr/eUbOvz32g0UHKnKbXrNIPnvm9NKQVBxLZX+ES6SMoUPGgiLhyKWb/axD63/ANz yNV5ceDFg7zAl5zma7NIhy5nS1Myuq2r+OKFdLQIGV/BAhdmDEFQXdYXITDPolT52VSg XiGvgZE3mmce4+z+rYXMI5VcWb0dGSbyfJcoqO6tHvn8I4TfbBiuG/N8ytzWg84LUoIg FQtbp7mupoeNoqzCCnwpMPz6gT+mKI/CyxCBLA3es6y3z0KPxPxRuimhDSbZ94rGwH/q uOsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693435695; x=1694040495; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ubwb8ZkSJEXL4N31fP6n7OBgqr01nG/Maz7pQ2R1NuQ=; b=jLo5EsjLTrULkVwhXxXCPa7vp0LC5RwZK4laj3KAEfn+iKHugNQZcQE0SpEQR77Yon 4wH2PDMTiYwOzuHxHsCwRBVwTzkfHWiX7s+ODJXHY+wleQgCeoEBxVWzqTkLYiM7l4p0 J/+0WIbcq4+3P9DJNRSwWASw7mMsGO0wvRbzHm8V7GOKhGFUU692RBTFnkCREW2ODFT2 jHr97f81mWf19cZQH70by+1zwAqMwxc1OYuulrdzLvHEawMZVj9eGP9noe0TS5JhzT1B eA470WSJNe5dXLHs/oEhgklGcApm+UTF8tG5EMGHzlnKjt7knr4mpcfNlU2iuKattYf9 hswg== X-Gm-Message-State: AOJu0YyuwI5TFbepC1NF6/jcMLSt1A1UPY+DkJpf8fUhRo/tLR5TZwCy jbzoLNdK8fYmdeH0Yr+5B7k= X-Google-Smtp-Source: AGHT+IEg7W8QFA14h0a2Pzn6H/lPyU7ZJTbFvU8hcWHYERy18kUYUQ8TOQ4nF9eY3kKjASknNVu4Mw== X-Received: by 2002:a17:903:32ce:b0:1bf:120a:a29e with SMTP id i14-20020a17090332ce00b001bf120aa29emr4106996plr.10.1693435694678; Wed, 30 Aug 2023 15:48:14 -0700 (PDT) Received: from stbirv-lnx-1.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id j22-20020a170902759600b001b8ad8382a4sm13010pll.216.2023.08.30.15.48.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Aug 2023 15:48:13 -0700 (PDT) From: Doug Berger To: Alessandro Zummo , Alexandre Belloni Cc: Florian Fainelli , Broadcom internal kernel review list , linux-rtc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Doug Berger Subject: [PATCH] rtc: brcmstb-waketimer: support level alarm_irq Date: Wed, 30 Aug 2023 15:47:47 -0700 Message-Id: <20230830224747.1663044-1-opendmb@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230830_154816_715003_42FFD956 X-CRM114-Status: GOOD ( 22.42 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Some devices (e.g. BCM72112) use an alarm_irq interrupt that is connected to a level interrupt controller rather than an edge interrupt controller. In this case, the interrupt cannot be left enabled by the irq handler while preserving the hardware wake-up signal on wake capable devices or an interrupt storm will occur. The alarm_expired flag is introduced to allow the disabling of the interrupt when an alarm expires and to support balancing the calls to disable_irq() and enable_irq() in accordance with the existing design. Fixes: 24304a87158a ("rtc: brcmstb-waketimer: allow use as non-wake alarm") Signed-off-by: Doug Berger Reviewed-by: Florian Fainelli --- drivers/rtc/rtc-brcmstb-waketimer.c | 47 ++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/drivers/rtc/rtc-brcmstb-waketimer.c b/drivers/rtc/rtc-brcmstb-waketimer.c index 3cdc015692ca..1a65a4e0dc00 100644 --- a/drivers/rtc/rtc-brcmstb-waketimer.c +++ b/drivers/rtc/rtc-brcmstb-waketimer.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-only /* - * Copyright © 2014-2017 Broadcom + * Copyright © 2014-2023 Broadcom */ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt @@ -34,6 +34,7 @@ struct brcmstb_waketmr { u32 rate; unsigned long rtc_alarm; bool alarm_en; + bool alarm_expired; }; #define BRCMSTB_WKTMR_EVENT 0x00 @@ -64,6 +65,11 @@ static inline void brcmstb_waketmr_clear_alarm(struct brcmstb_waketmr *timer) writel_relaxed(reg - 1, timer->base + BRCMSTB_WKTMR_ALARM); writel_relaxed(WKTMR_ALARM_EVENT, timer->base + BRCMSTB_WKTMR_EVENT); (void)readl_relaxed(timer->base + BRCMSTB_WKTMR_EVENT); + if (timer->alarm_expired) { + timer->alarm_expired = false; + /* maintain call balance */ + enable_irq(timer->alarm_irq); + } } static void brcmstb_waketmr_set_alarm(struct brcmstb_waketmr *timer, @@ -105,10 +111,17 @@ static irqreturn_t brcmstb_alarm_irq(int irq, void *data) return IRQ_HANDLED; if (timer->alarm_en) { - if (!device_may_wakeup(timer->dev)) + if (device_may_wakeup(timer->dev)) { + disable_irq_nosync(irq); + timer->alarm_expired = true; + } else { writel_relaxed(WKTMR_ALARM_EVENT, timer->base + BRCMSTB_WKTMR_EVENT); + } rtc_update_irq(timer->rtc, 1, RTC_IRQF | RTC_AF); + } else { + writel_relaxed(WKTMR_ALARM_EVENT, + timer->base + BRCMSTB_WKTMR_EVENT); } return IRQ_HANDLED; @@ -221,8 +234,14 @@ static int brcmstb_waketmr_alarm_enable(struct device *dev, !brcmstb_waketmr_is_pending(timer)) return -EINVAL; timer->alarm_en = true; - if (timer->alarm_irq) + if (timer->alarm_irq) { + if (timer->alarm_expired) { + timer->alarm_expired = false; + /* maintain call balance */ + enable_irq(timer->alarm_irq); + } enable_irq(timer->alarm_irq); + } } else if (!enabled && timer->alarm_en) { if (timer->alarm_irq) disable_irq(timer->alarm_irq); @@ -352,6 +371,17 @@ static int brcmstb_waketmr_suspend(struct device *dev) return brcmstb_waketmr_prepare_suspend(timer); } +static int brcmstb_waketmr_suspend_noirq(struct device *dev) +{ + struct brcmstb_waketmr *timer = dev_get_drvdata(dev); + + /* Catch any alarms occurring prior to noirq */ + if (timer->alarm_expired && device_may_wakeup(dev)) + return -EBUSY; + + return 0; +} + static int brcmstb_waketmr_resume(struct device *dev) { struct brcmstb_waketmr *timer = dev_get_drvdata(dev); @@ -368,10 +398,17 @@ static int brcmstb_waketmr_resume(struct device *dev) return ret; } +#else +#define brcmstb_waketmr_suspend NULL +#define brcmstb_waketmr_suspend_noirq NULL +#define brcmstb_waketmr_resume NULL #endif /* CONFIG_PM_SLEEP */ -static SIMPLE_DEV_PM_OPS(brcmstb_waketmr_pm_ops, - brcmstb_waketmr_suspend, brcmstb_waketmr_resume); +static const struct dev_pm_ops brcmstb_waketmr_pm_ops = { + .suspend = brcmstb_waketmr_suspend, + .suspend_noirq = brcmstb_waketmr_suspend_noirq, + .resume = brcmstb_waketmr_resume, +}; static const __maybe_unused struct of_device_id brcmstb_waketmr_of_match[] = { { .compatible = "brcm,brcmstb-waketimer" },