Skip to contentSkip to conversation

rtc: brcmstb-waketimer: add RTC alarm irq

PATCH Applied Doug Berger 4 participants 6 messages Jan 24, 2023 – Jan 25, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 cover rtc: brcmstb-waketimer: add RTC alarm irq

Support is added for an interrupt that can be triggered from the brcmstb-waketimer hardware while the system is awake.

This interrupt allows the driver to pass the rtctest selftest.

Changes in v2:
- Squashed examples in the bindings document.
- Added Ack from Florian

Doug Berger (2):
dt-bindings: rtc: brcm,brcmstb-waketimer: add alarm interrupt
rtc: brcmstb-waketimer: allow use as non-wake alarm

 .../bindings/rtc/brcm,brcmstb-waketimer.yaml  | 21 ++++---
 drivers/rtc/rtc-brcmstb-waketimer.c           | 55 ++++++++++++++++++-
 2 files changed, 66 insertions(+), 10 deletions(-)
Signature · 1 line
2.25.1
#1 lore raw

PATCH v2 1/2 dt-bindings: rtc: brcm,brcmstb-waketimer: add alarm interrupt

A second interrupt can optionally be specified for this device to be used for generating RTC alarm interrupts.

---
 .../bindings/rtc/brcm,brcmstb-waketimer.yaml  | 21 ++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)
Documentation/devicetree/bindings/rtc/brcm,brcmstb-waketimer.yaml +14 -7
index 9fe079917a98..c6c57636c729 100644
@@ -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>;
     };
Signature · 1 line
2.25.1
Reviewed-by on v2 1/2
#2 lore raw

Re: [PATCH v2 1/2] dt-bindings: rtc: brcm,brcmstb-waketimer: add alarm interrupt

Quoted 8 lines · Doug Berger

A second interrupt can optionally be specified for this device to be used for generating RTC alarm interrupts.

---
 .../bindings/rtc/brcm,brcmstb-waketimer.yaml  | 21 ++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

Best regards,
Krzysztof

#4 lore raw

PATCH v2 2/2 rtc: brcmstb-waketimer: allow use as non-wake alarm

In reply to Doug Berger

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.

---
 drivers/rtc/rtc-brcmstb-waketimer.c | 55 +++++++++++++++++++++++++++--
 1 file changed, 52 insertions(+), 3 deletions(-)
drivers/rtc/rtc-brcmstb-waketimer.c +52 -3
index e25f9fcd6ed1..1efa81cecc27 100644
@@ -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");
Signature · 1 line
2.25.1
maintainer Applied
#5 lore raw
In reply to Doug Berger
Quoted 10 lines · Doug Berger

Support is added for an interrupt that can be triggered from the brcmstb-waketimer hardware while the system is awake.

This interrupt allows the driver to pass the rtctest selftest.

Changes in v2:
- Squashed examples in the bindings document.
- Added Ack from Florian

[...]

Applied, thanks!

[1/2] dt-bindings: rtc: brcm,brcmstb-waketimer: add alarm interrupt

      commit: 6cc7a8262b57db0a2ff6c141bb163c1395b7c4ef
[2/2] rtc: brcmstb-waketimer: allow use as non-wake alarm
      commit: 24304a87158aab01b4ccb9b2638c2c623a9a7bd4

Best regards,

Signature · 3 lines
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com