* [PATCH] rtc: brcmstb-waketimer: support level alarm_irq
@ 2023-08-30 22:47 Doug Berger
2023-08-31 23:27 ` Florian Fainelli
2023-10-01 22:15 ` Alexandre Belloni
0 siblings, 2 replies; 4+ messages in thread
From: Doug Berger @ 2023-08-30 22:47 UTC (permalink / raw)
To: Alessandro Zummo, Alexandre Belloni
Cc: Florian Fainelli, Broadcom internal kernel review list, linux-rtc,
linux-arm-kernel, linux-kernel, Doug Berger
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 <opendmb@gmail.com>
---
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" },
--
2.34.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] rtc: brcmstb-waketimer: support level alarm_irq
2023-08-30 22:47 [PATCH] rtc: brcmstb-waketimer: support level alarm_irq Doug Berger
@ 2023-08-31 23:27 ` Florian Fainelli
2023-09-15 18:50 ` Florian Fainelli
2023-10-01 22:15 ` Alexandre Belloni
1 sibling, 1 reply; 4+ messages in thread
From: Florian Fainelli @ 2023-08-31 23:27 UTC (permalink / raw)
To: Doug Berger, Alessandro Zummo, Alexandre Belloni
Cc: Broadcom internal kernel review list, linux-rtc, linux-arm-kernel,
linux-kernel
[-- Attachment #1.1: Type: text/plain, Size: 793 bytes --]
On 8/30/23 15:47, Doug Berger wrote:
> 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 <opendmb@gmail.com>
Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
--
Florian
[-- Attachment #1.2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4221 bytes --]
[-- Attachment #2: Type: text/plain, Size: 176 bytes --]
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] rtc: brcmstb-waketimer: support level alarm_irq
2023-08-31 23:27 ` Florian Fainelli
@ 2023-09-15 18:50 ` Florian Fainelli
0 siblings, 0 replies; 4+ messages in thread
From: Florian Fainelli @ 2023-09-15 18:50 UTC (permalink / raw)
To: Doug Berger, Alessandro Zummo, Alexandre Belloni
Cc: Broadcom internal kernel review list, linux-rtc, linux-arm-kernel,
linux-kernel
[-- Attachment #1.1: Type: text/plain, Size: 915 bytes --]
On 8/31/23 16:27, Florian Fainelli wrote:
> On 8/30/23 15:47, Doug Berger wrote:
>> 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 <opendmb@gmail.com>
>
> Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
Alexandre, any chance you could apply this patch? Thanks!
--
Florian
[-- Attachment #1.2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4221 bytes --]
[-- Attachment #2: Type: text/plain, Size: 176 bytes --]
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] rtc: brcmstb-waketimer: support level alarm_irq
2023-08-30 22:47 [PATCH] rtc: brcmstb-waketimer: support level alarm_irq Doug Berger
2023-08-31 23:27 ` Florian Fainelli
@ 2023-10-01 22:15 ` Alexandre Belloni
1 sibling, 0 replies; 4+ messages in thread
From: Alexandre Belloni @ 2023-10-01 22:15 UTC (permalink / raw)
To: Alessandro Zummo, Doug Berger
Cc: Florian Fainelli, Broadcom internal kernel review list, linux-rtc,
linux-arm-kernel, linux-kernel
On Wed, 30 Aug 2023 15:47:47 -0700, Doug Berger wrote:
> 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.
>
> [...]
Applied, thanks!
[1/1] rtc: brcmstb-waketimer: support level alarm_irq
commit: e005a9b35b464be5b2e0194f717e90e7e496785d
Best regards,
--
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-10-01 22:16 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-30 22:47 [PATCH] rtc: brcmstb-waketimer: support level alarm_irq Doug Berger
2023-08-31 23:27 ` Florian Fainelli
2023-09-15 18:50 ` Florian Fainelli
2023-10-01 22:15 ` Alexandre Belloni
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).