From patchwork Tue Jan 24 20:14:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Berger X-Patchwork-Id: 13114751 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 12AEEC54EED for ; Tue, 24 Jan 2023 20:15:59 +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:References:In-Reply-To: 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: List-Owner; bh=RwwhtqNfhd3L7tnHYe1dEz/c4tBzSoZmPYIVI5Acahw=; b=HhskH4zdO2+3xA kMviF2TMffe/M/PTlqdyTH3OVfZ0oh6+IZHtSo8DA/yXzD8+5sEDxCIZbj8mXUFLeByaDAIhaa9jn lhyAUZzF9r0YiOYstzM857/QucxxXQ5y67ZSHrcn/tTMW9jnTmcT2m/OCJTSfvcn2QtLN16idSf3d USaed4oOtcN6nM/8rDp88UUOvV8JH2PVLMPNrEUt4K7xdpRM9piElJzatSaAYgL0qFfSf9aDKDvPG o845LAlR+wwZCBbsJFbvTVTO8qCGPGWkyD51habU0znYaMGl+EJBoDV47PSdX/0j0FCNqjp+f0UdH y0lf4M8sT2ccW7MAjMJA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pKPhD-005Anc-Me; Tue, 24 Jan 2023 20:15:07 +0000 Received: from mail-pj1-x1034.google.com ([2607:f8b0:4864:20::1034]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pKPh3-005Al0-32 for linux-arm-kernel@lists.infradead.org; Tue, 24 Jan 2023 20:14:58 +0000 Received: by mail-pj1-x1034.google.com with SMTP id t12-20020a17090aae0c00b00229f4cff534so2118222pjq.1 for ; Tue, 24 Jan 2023 12:14:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ll14lOuViaenf8FjC8Zh9d13ikWCf4/ACX98HmRIznQ=; b=ZAopVKkN0s7Png4zG+tuGkTd3xixUMd69So0uL2bMx5KZYtc59pIqZ4f2v8pmvU3AB Kv95PTiLofjK8wrWBwJZDyZmKerFogMJQE3VWtLiLWEbnfCFI9IBKwP2Fnkao1M50VV6 jPwciYogW4lFiUwTsf7OxNMVtNrC1BOvo7FD2DvB62ARFsUh32Tw3rImxM28KOBudBZx o3DrAhuk052jHvkh1NKylSFBAdr/sH8ccp1r0dbjQOm+qfst19wDunhyd4k4SlIK/bLa lEHCOhLIuivm1krpd8+vkGHCDUaqD+GfMOc/C8jxl1H08Mio2yA+Tl3Jjyf37nv50I1Y o9OQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ll14lOuViaenf8FjC8Zh9d13ikWCf4/ACX98HmRIznQ=; b=oUQ9CaiZKtfI0gZXmGbiD5hNE0ec4L4xz0gjlz+J9C1tv3J1IPSK82Kzq8JINnoe1a UYN3qv1EdwL0WlvblCj98u7EPCf+YwFjRmP1HcUUsRhogqGJIqUJJzBW5IfN+QDa1j71 vLIGWNv2t/Db4zfkcRpzRqECUUocYuNxiCgc1H71Y+UbSOZNKojWo7ne8DoOKATrz16J gedbCq4RffWpc2UPg+YlTsQKuBPuzt8UswfaiPU8YIAIMHJwh8P/UEdW0SRH6OwOqM1M rnPvnG9RRLeIxx4HLFSNLo8SR4iFOuEakNiM1R0am9/TO0IUWzqZJEuGTj+4wd0c2O6c m7fg== X-Gm-Message-State: AFqh2krdtB04lmm4JJ8wSTDsBL5JTroTQOK5tlO85b9wgw4myZSgKSCS OlC+oj9ZRODPq4XEwiatxdHBiDog3Nw= X-Google-Smtp-Source: AMrXdXtSLjjpmIZl5tzMLd8wwiQWRF3O8uIuMF/HEzETMHjTsG/sYrTi7X2oO1JsB5GcOA6m9vZ7Vg== X-Received: by 2002:a17:902:ca13:b0:195:f265:66dc with SMTP id w19-20020a170902ca1300b00195f26566dcmr12490201pld.68.1674591291804; Tue, 24 Jan 2023 12:14:51 -0800 (PST) Received: from stbirv-lnx-3.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id d13-20020a170902728d00b00174f61a7d09sm2057824pll.247.2023.01.24.12.14.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Jan 2023 12:14:51 -0800 (PST) From: Doug Berger To: Alessandro Zummo , Alexandre Belloni Cc: Brian Norris , Markus Mayer , Rob Herring , Krzysztof Kozlowski , Florian Fainelli , Broadcom internal kernel review list , linux-rtc@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Doug Berger Subject: [PATCH v2 1/2] dt-bindings: rtc: brcm,brcmstb-waketimer: add alarm interrupt Date: Tue, 24 Jan 2023 12:14:29 -0800 Message-Id: <20230124201430.2502371-2-opendmb@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230124201430.2502371-1-opendmb@gmail.com> References: <20230124201430.2502371-1-opendmb@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230124_121457_147880_F24E30F2 X-CRM114-Status: GOOD ( 14.11 ) 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 A second interrupt can optionally be specified for this device to be used for generating RTC alarm interrupts. Signed-off-by: Doug Berger Reviewed-by: Krzysztof Kozlowski Acked-by: Florian Fainelli --- .../bindings/rtc/brcm,brcmstb-waketimer.yaml | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/Documentation/devicetree/bindings/rtc/brcm,brcmstb-waketimer.yaml b/Documentation/devicetree/bindings/rtc/brcm,brcmstb-waketimer.yaml index 9fe079917a98..c6c57636c729 100644 --- a/Documentation/devicetree/bindings/rtc/brcm,brcmstb-waketimer.yaml +++ b/Documentation/devicetree/bindings/rtc/brcm,brcmstb-waketimer.yaml @@ -11,7 +11,8 @@ maintainers: description: The Broadcom STB wake-up timer provides a 27Mhz resolution timer, with the - ability to wake up the system from low-power suspend/standby modes. + ability to wake up the system from low-power suspend/standby modes and + optionally generate RTC alarm interrupts. allOf: - $ref: "rtc.yaml#" @@ -24,8 +25,14 @@ properties: maxItems: 1 interrupts: - description: the TIMER interrupt - maxItems: 1 + minItems: 1 + items: + - description: the TIMER interrupt + - description: the ALARM interrupt + description: + The TIMER interrupt wakes the system from low-power suspend/standby modes. + An ALARM interrupt may be specified to interrupt the CPU when an RTC alarm + is enabled. clocks: description: clock reference in the 27MHz domain @@ -35,10 +42,10 @@ additionalProperties: false examples: - | - rtc@f0411580 { + rtc@f041a080 { compatible = "brcm,brcmstb-waketimer"; - reg = <0xf0411580 0x14>; - interrupts = <0x3>; - interrupt-parent = <&aon_pm_l2_intc>; + reg = <0xf041a080 0x14>; + interrupts-extended = <&aon_pm_l2_intc 0x04>, + <&upg_aux_aon_intr2_intc 0x08>; clocks = <&upg_fixed>; }; From patchwork Tue Jan 24 20:14:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Berger X-Patchwork-Id: 13114752 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 84895C54EED for ; Tue, 24 Jan 2023 20:16:06 +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:References:In-Reply-To: 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: List-Owner; bh=iBc77k5Foi73GybUmbhzo4d1KdXgQ7P9P2I3/5bwFQ8=; b=kSZQx0EXZvql7t 33zBEjY8huI68ZQZ/HCvgaSLp/HoCOJ5vSnVaX3YYMgn3EzddN9E8w57KgKIoQHAZHjadioY5pRHx 8qdrGFJk6NITuUyLamboJ6usc0gvZXyU0/kddfuEfpUS7ErzKLo1az99G/k+d5pECTFQSJMbJ9y8l G4LTQe4gbiyR80y+V05RiQAJduVz2pwFZLk36sq+QiP5p92B66raRkdJO7/5lU3IAxrw3Myc9pRPT CHTOJwXfcozSVESyUiKyIUcWJd42WeRLYO8BThcMbP9ZXH7F5IbQk4/FiZRL+qQdl8dvIHc6oG9A+ OgNlTejdMtda6bd4khrA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pKPhL-005ApY-RN; Tue, 24 Jan 2023 20:15:15 +0000 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pKPh3-005AlB-EZ for linux-arm-kernel@lists.infradead.org; Tue, 24 Jan 2023 20:14:59 +0000 Received: by mail-pj1-x102b.google.com with SMTP id n20-20020a17090aab9400b00229ca6a4636so18966224pjq.0 for ; Tue, 24 Jan 2023 12:14:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=oEtY5LynS2vkRPJ1R/kvYmV9SRofdb2LH2C1cStAz2M=; b=YLqMn6DXAHVh1XoLozY4AjSZ2agwCfvhkAMhaBbQlDjZBccFd5CgQll9zu3+eXv+T3 lut752J6pdicDNwtPw0D/+VEKasV0TNfcTCgXpPB0+JjUkK9ObZ5KeUXHB4eBdiCgMkS rAsMHZUlC4kZpqXMwZFqItpHxhcsPA2Noz9zjHKcdCT3BueUIdmHnnQRZNxkxJqrQKcx 73PR4NrdkovewfZ3usoqswNOzbAYl+8khJh3bxc7hzSMHjXLOYeeH6BYtu/OA+CUrS4O 3PzgLegGlYVKJyk9LsJVomZ987ObpTgG9tGRWdgemBqxaQ6xBdhniwDIeH/nvK/6pAuE rP4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oEtY5LynS2vkRPJ1R/kvYmV9SRofdb2LH2C1cStAz2M=; b=ToowjQQJRd6Pa5NJd8DINnf6DVYePE+VsBQWj9dLkIAvXevyJNRlI17kwHqpDytAMY 8S0CGDSoqt0PL52mg537bMPL1BxLgoay0CQbsOKy0RpF8t/XXzWLzjWB8QjP4BEoKGWz 96SpBFOcdPFLbvDLqS758GdB1++IVQ7YbcZWM2ddR8xfX4d7Bd9G52Zj7YjP6uS/yaN2 DoF6stqsw1RLtcxPer/GIVTGNkv5WrwTlubMbhEF5imf+DOWZ2XnzZVyAA2Vcrsef9f/ mupSDAVpnnVLpOXuSMeR9s3DeFFoHCoyt5wmLWcfLOZ255xm/sO5R2adDUk/6TIzUVLT wW2g== X-Gm-Message-State: AO0yUKXz2J5bUNzd7JaVfADdrKNBja/fSFDyjgHtKtUZU6pcWArIl3nZ ZsDs+5L1foTTWgjkYqF8H7M= X-Google-Smtp-Source: AK7set/SVm0TL+nwZtkO3KuT5ojyygCFXTfAneUC4EiVvIR5DnLMNpB8e+WyXau6/07/j3+AxU1FYg== X-Received: by 2002:a05:6a20:6985:b0:bb:a0a2:c37a with SMTP id t5-20020a056a20698500b000bba0a2c37amr4187151pzk.33.1674591293717; Tue, 24 Jan 2023 12:14:53 -0800 (PST) Received: from stbirv-lnx-3.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id d13-20020a170902728d00b00174f61a7d09sm2057824pll.247.2023.01.24.12.14.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Jan 2023 12:14:53 -0800 (PST) From: Doug Berger To: Alessandro Zummo , Alexandre Belloni Cc: Brian Norris , Markus Mayer , Rob Herring , Krzysztof Kozlowski , Florian Fainelli , Broadcom internal kernel review list , linux-rtc@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Doug Berger Subject: [PATCH v2 2/2] rtc: brcmstb-waketimer: allow use as non-wake alarm Date: Tue, 24 Jan 2023 12:14:30 -0800 Message-Id: <20230124201430.2502371-3-opendmb@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230124201430.2502371-1-opendmb@gmail.com> References: <20230124201430.2502371-1-opendmb@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230124_121457_505745_CCF9F0A4 X-CRM114-Status: GOOD ( 24.78 ) 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 The wake interrupt only fires when the system is in a suspend state. Fortunately we have another interrupt that fires in a non-suspend state at the L2 controller UPG_AUX_AON. Add support for this interrupt line so we can use the alarm in a non-wake context. Signed-off-by: Doug Berger Acked-by: Florian Fainelli --- drivers/rtc/rtc-brcmstb-waketimer.c | 55 +++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 3 deletions(-) diff --git a/drivers/rtc/rtc-brcmstb-waketimer.c b/drivers/rtc/rtc-brcmstb-waketimer.c index e25f9fcd6ed1..1efa81cecc27 100644 --- a/drivers/rtc/rtc-brcmstb-waketimer.c +++ b/drivers/rtc/rtc-brcmstb-waketimer.c @@ -28,6 +28,7 @@ struct brcmstb_waketmr { struct device *dev; void __iomem *base; unsigned int wake_irq; + unsigned int alarm_irq; struct notifier_block reboot_notifier; struct clk *clk; u32 rate; @@ -56,6 +57,8 @@ static inline void brcmstb_waketmr_clear_alarm(struct brcmstb_waketmr *timer) { u32 reg; + if (timer->alarm_en && timer->alarm_irq) + disable_irq(timer->alarm_irq); timer->alarm_en = false; reg = readl_relaxed(timer->base + BRCMSTB_WKTMR_COUNTER); writel_relaxed(reg - 1, timer->base + BRCMSTB_WKTMR_ALARM); @@ -88,7 +91,25 @@ static irqreturn_t brcmstb_waketmr_irq(int irq, void *data) { struct brcmstb_waketmr *timer = data; - pm_wakeup_event(timer->dev, 0); + if (!timer->alarm_irq) + pm_wakeup_event(timer->dev, 0); + return IRQ_HANDLED; +} + +static irqreturn_t brcmstb_alarm_irq(int irq, void *data) +{ + struct brcmstb_waketmr *timer = data; + + /* Ignore spurious interrupts */ + if (!brcmstb_waketmr_is_pending(timer)) + return IRQ_HANDLED; + + if (timer->alarm_en) { + if (!device_may_wakeup(timer->dev)) + writel_relaxed(WKTMR_ALARM_EVENT, + timer->base + BRCMSTB_WKTMR_EVENT); + rtc_update_irq(timer->rtc, 1, RTC_IRQF | RTC_AF); + } return IRQ_HANDLED; } @@ -114,7 +135,7 @@ static void wktmr_read(struct brcmstb_waketmr *timer, static int brcmstb_waketmr_prepare_suspend(struct brcmstb_waketmr *timer) { struct device *dev = timer->dev; - int ret = 0; + int ret; if (device_may_wakeup(dev)) { ret = enable_irq_wake(timer->wake_irq); @@ -122,9 +143,17 @@ static int brcmstb_waketmr_prepare_suspend(struct brcmstb_waketmr *timer) dev_err(dev, "failed to enable wake-up interrupt\n"); return ret; } + if (timer->alarm_en && timer->alarm_irq) { + ret = enable_irq_wake(timer->alarm_irq); + if (ret) { + dev_err(dev, "failed to enable rtc interrupt\n"); + disable_irq_wake(timer->wake_irq); + return ret; + } + } } - return ret; + return 0; } /* If enabled as a wakeup-source, arm the timer when powering off */ @@ -192,7 +221,11 @@ static int brcmstb_waketmr_alarm_enable(struct device *dev, !brcmstb_waketmr_is_pending(timer)) return -EINVAL; timer->alarm_en = true; + if (timer->alarm_irq) + enable_irq(timer->alarm_irq); } else if (!enabled && timer->alarm_en) { + if (timer->alarm_irq) + disable_irq(timer->alarm_irq); timer->alarm_en = false; } @@ -269,6 +302,19 @@ static int brcmstb_waketmr_probe(struct platform_device *pdev) if (ret < 0) goto err_clk; + brcmstb_waketmr_clear_alarm(timer); + + /* Attempt to initialize non-wake irq */ + ret = platform_get_irq(pdev, 1); + if (ret > 0) { + timer->alarm_irq = (unsigned int)ret; + ret = devm_request_irq(dev, timer->alarm_irq, brcmstb_alarm_irq, + IRQF_NO_AUTOEN, "brcmstb-waketimer-rtc", + timer); + if (ret < 0) + timer->alarm_irq = 0; + } + timer->reboot_notifier.notifier_call = brcmstb_waketmr_reboot; register_reboot_notifier(&timer->reboot_notifier); @@ -317,6 +363,8 @@ static int brcmstb_waketmr_resume(struct device *dev) return 0; ret = disable_irq_wake(timer->wake_irq); + if (timer->alarm_en && timer->alarm_irq) + disable_irq_wake(timer->alarm_irq); brcmstb_waketmr_clear_alarm(timer); @@ -346,4 +394,5 @@ module_platform_driver(brcmstb_waketmr_driver); MODULE_LICENSE("GPL v2"); MODULE_AUTHOR("Brian Norris"); MODULE_AUTHOR("Markus Mayer"); +MODULE_AUTHOR("Doug Berger"); MODULE_DESCRIPTION("Wake-up timer driver for STB chips");