Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp3115340rwb; Fri, 20 Jan 2023 11:22:15 -0800 (PST) X-Google-Smtp-Source: AMrXdXsUMjbI3ir53PJ5laZiVdiWs7e0ezRUnFP7Y2wtt5xVzzseIAFHSoMilTdTFgDPh9InUBMn X-Received: by 2002:a17:902:e5c9:b0:194:d0ad:53f0 with SMTP id u9-20020a170902e5c900b00194d0ad53f0mr8958870plf.9.1674242534984; Fri, 20 Jan 2023 11:22:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674242534; cv=none; d=google.com; s=arc-20160816; b=zv+TOuJijE+SJExqKyaNVxiW1GXzEQPKxjXY9/cgFFc0GjtN7yhAotMdZBtnYhk7Zg nobzCUfvhx8ZzvkSDaMml9rMz00N8X5qDp/8w9ylx8jV8q44f/Bumx53r7hi3asYEv/1 PA1+p0DYiLvpRNaZSyYe94kpqB6sycQbDNuza4niDTT95e3QAmDSsp6KHYQgzVbTNj6H IgCFCTNX8HwaCTLfvxPBsf0pt9QXBLtdrfZrDRNAssicuzgZDoiq+9nIhrkmeEi2JjJP ugBbPqpm/3epHKj40cYx9VBrWUg1G2VF0ZNy9RDnCcR0DaAPoCD+MSI+6JsuQyYmutk/ L9cQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=uqkC6sovxRXM6xizruGfWT9Cuv1q7uo8QTDLi10Fn4g=; b=g99D6cGoLP3tr6IqzDBCwflNNRhD+AHdkwiCP8SZiKeW4u9fnHJ9m4Mg1Ayiynv+S9 faf1f1BXwQswqcXtr/vrvYoovDJ6XW2UGdZCcC46UEm8dClAY2tdoY7WbVc2bpWkZhsY gOao88MOFCukVtbbQK68QAoYQJ78XFcB9FQT+A+q22hinWBCOJxwgxI6P23EUkDV1Kn/ s7g/KNcdbrFrmAbETQVDtgzGlXU/iZPthd2QuM8P45LX99funGkljs5pp0v8Bq642C4r 5gvc6SjH434nHwkORICXbpWsn/bB9kPT25ktBqGGjVQL6xr3kaLwzq+hLQRlNe86SaKt SXCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=EKuaVn9G; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i24-20020a63d458000000b004ce83ad3030si12291156pgj.269.2023.01.20.11.22.09; Fri, 20 Jan 2023 11:22:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=EKuaVn9G; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230049AbjATTCw (ORCPT + 50 others); Fri, 20 Jan 2023 14:02:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230092AbjATTCm (ORCPT ); Fri, 20 Jan 2023 14:02:42 -0500 Received: from mail-il1-x131.google.com (mail-il1-x131.google.com [IPv6:2607:f8b0:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69F8B3A88; Fri, 20 Jan 2023 11:02:35 -0800 (PST) Received: by mail-il1-x131.google.com with SMTP id i1so3161030ilu.8; Fri, 20 Jan 2023 11:02:35 -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=uqkC6sovxRXM6xizruGfWT9Cuv1q7uo8QTDLi10Fn4g=; b=EKuaVn9G3pyj6UJjR4KsvEGeAKeMW/ybk5bDiRItK543Wilx6Jfd7+C6b2FRBQOjaX XBucpToQF7YKAbHpfvWaRfkUyIy9PYC6mDdD/oo24Z3uLTRohw8SZ/Pysy9V0JIdtv97 hbLKehRGToyuPqdDqIZbFvlpJYEZNsqMkKCYWrLwwZgEfg0aJ7iRAGLWx4ThVSczPTE9 CmN9LSgn34DRhElpbkwKzf3PSE2eQ8MtJxdvsesqaRzo4jry5rlCxm1K6HFQ8jWeO3kT MKI7c/CQR4yUMBdIeUP5H4lhcXicAji0+7Z5K63tO+X7zINQrNm2XF0RPOfmX52zNnCf aOnQ== 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=uqkC6sovxRXM6xizruGfWT9Cuv1q7uo8QTDLi10Fn4g=; b=8Cb9gQN1D3Q1ieMQeOTRU2cg5UpyZRC0aoNEmJhcu7OXrmPK61ml4umgZA/Hwhb4l/ xAxsIRaeR3bDFTXSgDJDVkwr3tlYeP2KDPswiIMe8j3qADHrPb6k4X2TkcJabiQvr5Vp ZGvF2uV5UlTxTNDuV8UjpuEz3fKW0rnzEaS178WHk/hSJFIYzlrHQKyllzGv6rc8Yi+n j+W53pthcmIr+t2Mokbo/JtoL6Fua2LLbPVB6tcb361SG9RLwBG4W9+zFvdS8lrurR/1 ZrJDgwxLQLG/KzGXcrIhY+3/0Zjle6RDMT5GrCHDJUCJyAB2CKFAjB3yjLzzJH9iQpFh 3wKw== X-Gm-Message-State: AFqh2krS1t9UnFfoE+Zvn+EcV9WTOCqrFHnLsOxootXPN+aZTKE3lxHN +6eH5PHeT0EjPmqDKS2KCaQ= X-Received: by 2002:a05:6e02:1562:b0:30f:3736:25ab with SMTP id k2-20020a056e02156200b0030f373625abmr8463918ilu.28.1674241355300; Fri, 20 Jan 2023 11:02:35 -0800 (PST) Received: from stbirv-lnx-3.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id y13-20020a37f60d000000b006fa2b1c3c1esm10379806qkj.58.2023.01.20.11.02.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Jan 2023 11:02:34 -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 6/6] rtc: brcmstb-waketimer: allow use as non-wake alarm Date: Fri, 20 Jan 2023 11:01:47 -0800 Message-Id: <20230120190147.718976-7-opendmb@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230120190147.718976-1-opendmb@gmail.com> References: <20230120190147.718976-1-opendmb@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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 --- 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"); -- 2.25.1