Skip to content

Commit e005a9b

Browse files
Doug Bergeralexandrebelloni
authored andcommitted
rtc: brcmstb-waketimer: support level alarm_irq
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: 24304a8 ("rtc: brcmstb-waketimer: allow use as non-wake alarm") Signed-off-by: Doug Berger <[email protected]> Reviewed-by: Florian Fainelli <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexandre Belloni <[email protected]>
1 parent d4277fa commit e005a9b

File tree

1 file changed

+42
-5
lines changed

1 file changed

+42
-5
lines changed

drivers/rtc/rtc-brcmstb-waketimer.c

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// SPDX-License-Identifier: GPL-2.0-only
22
/*
3-
* Copyright © 2014-2017 Broadcom
3+
* Copyright © 2014-2023 Broadcom
44
*/
55

66
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
@@ -34,6 +34,7 @@ struct brcmstb_waketmr {
3434
u32 rate;
3535
unsigned long rtc_alarm;
3636
bool alarm_en;
37+
bool alarm_expired;
3738
};
3839

3940
#define BRCMSTB_WKTMR_EVENT 0x00
@@ -64,6 +65,11 @@ static inline void brcmstb_waketmr_clear_alarm(struct brcmstb_waketmr *timer)
6465
writel_relaxed(reg - 1, timer->base + BRCMSTB_WKTMR_ALARM);
6566
writel_relaxed(WKTMR_ALARM_EVENT, timer->base + BRCMSTB_WKTMR_EVENT);
6667
(void)readl_relaxed(timer->base + BRCMSTB_WKTMR_EVENT);
68+
if (timer->alarm_expired) {
69+
timer->alarm_expired = false;
70+
/* maintain call balance */
71+
enable_irq(timer->alarm_irq);
72+
}
6773
}
6874

6975
static void brcmstb_waketmr_set_alarm(struct brcmstb_waketmr *timer,
@@ -105,10 +111,17 @@ static irqreturn_t brcmstb_alarm_irq(int irq, void *data)
105111
return IRQ_HANDLED;
106112

107113
if (timer->alarm_en) {
108-
if (!device_may_wakeup(timer->dev))
114+
if (device_may_wakeup(timer->dev)) {
115+
disable_irq_nosync(irq);
116+
timer->alarm_expired = true;
117+
} else {
109118
writel_relaxed(WKTMR_ALARM_EVENT,
110119
timer->base + BRCMSTB_WKTMR_EVENT);
120+
}
111121
rtc_update_irq(timer->rtc, 1, RTC_IRQF | RTC_AF);
122+
} else {
123+
writel_relaxed(WKTMR_ALARM_EVENT,
124+
timer->base + BRCMSTB_WKTMR_EVENT);
112125
}
113126

114127
return IRQ_HANDLED;
@@ -221,8 +234,14 @@ static int brcmstb_waketmr_alarm_enable(struct device *dev,
221234
!brcmstb_waketmr_is_pending(timer))
222235
return -EINVAL;
223236
timer->alarm_en = true;
224-
if (timer->alarm_irq)
237+
if (timer->alarm_irq) {
238+
if (timer->alarm_expired) {
239+
timer->alarm_expired = false;
240+
/* maintain call balance */
241+
enable_irq(timer->alarm_irq);
242+
}
225243
enable_irq(timer->alarm_irq);
244+
}
226245
} else if (!enabled && timer->alarm_en) {
227246
if (timer->alarm_irq)
228247
disable_irq(timer->alarm_irq);
@@ -352,6 +371,17 @@ static int brcmstb_waketmr_suspend(struct device *dev)
352371
return brcmstb_waketmr_prepare_suspend(timer);
353372
}
354373

374+
static int brcmstb_waketmr_suspend_noirq(struct device *dev)
375+
{
376+
struct brcmstb_waketmr *timer = dev_get_drvdata(dev);
377+
378+
/* Catch any alarms occurring prior to noirq */
379+
if (timer->alarm_expired && device_may_wakeup(dev))
380+
return -EBUSY;
381+
382+
return 0;
383+
}
384+
355385
static int brcmstb_waketmr_resume(struct device *dev)
356386
{
357387
struct brcmstb_waketmr *timer = dev_get_drvdata(dev);
@@ -368,10 +398,17 @@ static int brcmstb_waketmr_resume(struct device *dev)
368398

369399
return ret;
370400
}
401+
#else
402+
#define brcmstb_waketmr_suspend NULL
403+
#define brcmstb_waketmr_suspend_noirq NULL
404+
#define brcmstb_waketmr_resume NULL
371405
#endif /* CONFIG_PM_SLEEP */
372406

373-
static SIMPLE_DEV_PM_OPS(brcmstb_waketmr_pm_ops,
374-
brcmstb_waketmr_suspend, brcmstb_waketmr_resume);
407+
static const struct dev_pm_ops brcmstb_waketmr_pm_ops = {
408+
.suspend = brcmstb_waketmr_suspend,
409+
.suspend_noirq = brcmstb_waketmr_suspend_noirq,
410+
.resume = brcmstb_waketmr_resume,
411+
};
375412

376413
static const __maybe_unused struct of_device_id brcmstb_waketmr_of_match[] = {
377414
{ .compatible = "brcm,brcmstb-waketimer" },

0 commit comments

Comments
 (0)