Skip to contentSkip to conversation

rtc: Introduce rtc-ti-k3

PATCH Superseded Nishanth Menon 6 participants 11 messages Apr 12, 2022 – Apr 15, 2022

Subsystems (2)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover rtc: Introduce rtc-ti-k3

Hi,

This series adds support for TI K3 RTC as instantiated on TI's AM625 SoC.

Documentation in the current early release version of Technical Reference Manual is incomplete at the moment, but due to be updated later this year.
https://www.ti.com/lit/pdf/spruiv7

Testing log can be found here (20220411 + additional patch to get mmc root fs): https://gist.github.com/nmenon/88c56d63c2e163e7ba1e06f30eee52cc

Nishanth Menon (2):
dt-bindings: rtc: Add TI K3 RTC devicetree bindings documentation
rtc: Introduce ti-k3-rtc

 .../devicetree/bindings/rtc/ti,k3-rtc.yaml    |  87 +++
 drivers/rtc/Kconfig                           |  10 +
 drivers/rtc/Makefile                          |   1 +
 drivers/rtc/rtc-ti-k3.c                       | 687 ++++++++++++++++++
 4 files changed, 785 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/rtc/ti,k3-rtc.yaml
 create mode 100644 drivers/rtc/rtc-ti-k3.c
Signature · 7 lines
2.31.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#1 lore raw

PATCH 1/2 dt-bindings: rtc: Add TI K3 RTC devicetree bindings documentation

This adds the documentation for the devicetree bindings of the Texas Instruments RTC modules on K3 family of SoCs such as AM62x SoCs or newer.

---
 .../devicetree/bindings/rtc/ti,k3-rtc.yaml    | 87 +++++++++++++++++++
 1 file changed, 87 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/rtc/ti,k3-rtc.yaml
Documentation/devicetree/bindings/rtc/ti,k3-rtc.yaml new file +87 -0
new file mode 100644
index 000000000000..16aebb8013a1
@@ -0,0 +1,87 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/rtc/ti,k3-rtc.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Texas Instruments K3 Real Time Clock
+
+maintainers:
+  - Nishanth Menon <[email protected]>
+
+description: |
+  This RTC appears in the AM62x family of SoCs.
+
+properties:
+  compatible:
+    items:
+      - enum:
+          - ti,am62-rtc
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  clocks:
+    items:
+      - description: VBUS Interface clock
+      - description: 32k Clock source (external or internal).
+
+  clock-names:
+    items:
+      - const: "vbus"
+      - const: "osc32k"
+
+  power-domains:
+    maxItems: 1
+
+  assigned-clocks:
+    description: |
+      override default osc32k parent clock reference to the osc32k clock entry
+    maxItems: 1
+
+  assigned-clock-parents:
+    description: |
+      override default osc32k parent clock phandle of the new parent clock of osc32k
+    maxItems: 1
+
+  wakeup-source: true
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - clocks
+  - clock-names
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    rtc@2b1f0000 {
+        compatible = "ti,am62-rtc";
+        reg = <0x2b1f0000 0x100>;
+        interrupts = <GIC_SPI 100 IRQ_TYPE_LEVEL_HIGH>;
+        power-domains = <&bar 0>;
+        clocks = <&foo 0>, <&foo 1>;
+        clock-names = "vbus", "osc32k";
+        wakeup-source;
+    };
+
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    rtc@2b1f0000 {
+        compatible = "ti,am62-rtc";
+        reg = <0x2b1f0000 0x100>;
+        interrupts = <GIC_SPI 100 IRQ_TYPE_LEVEL_HIGH>;
+        power-domains = <&bar 0>;
+        clocks = <&foo 0>, <&foo 1>;
+        clock-names = "vbus", "osc32k";
+        wakeup-source;
+        assigned-clocks = <&foo 1>;
+        assigned-clock-parents = <&foo 2>;
+
+    };
Signature · 7 lines
2.31.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#2 lore raw

Re: [PATCH 1/2] dt-bindings: rtc: Add TI K3 RTC devicetree bindings documentation

Quoted 4 lines · Nishanth Menon

This adds the documentation for the devicetree bindings of the Texas Instruments RTC modules on K3 family of SoCs such as AM62x SoCs or newer.

Thank you for your patch. There is something to discuss/improve.

(...)

Documentation/devicetree/bindings/rtc/ti,k3-rtc.yaml line 17

Quoted 3 lines
Documentation/devicetree/bindings/rtc/ti,k3-rtc.yaml new file +3 -0
+properties:
+  compatible:
+    items:

No need for items. Just enum under the compatible.

Quoted 8 lines
Documentation/devicetree/bindings/rtc/ti,k3-rtc.yaml new file +8 -0
+      - enum:
+          - ti,am62-rtc
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1

Documentation/devicetree/bindings/rtc/ti,k3-rtc.yaml line 35

Quoted 10 lines
Documentation/devicetree/bindings/rtc/ti,k3-rtc.yaml new file +10 -0
+
+  clocks:
+    items:
+      - description: VBUS Interface clock
+      - description: 32k Clock source (external or internal).
+
+  clock-names:
+    items:
+      - const: "vbus"
+      - const: "osc32k"

No quotes.

Documentation/devicetree/bindings/rtc/ti,k3-rtc.yaml line 48

Quoted 13 lines
Documentation/devicetree/bindings/rtc/ti,k3-rtc.yaml new file +13 -0
+
+  power-domains:
+    maxItems: 1
+
+  assigned-clocks:
+    description: |
+      override default osc32k parent clock reference to the osc32k clock entry
+    maxItems: 1
+
+  assigned-clock-parents:
+    description: |
+      override default osc32k parent clock phandle of the new parent clock of osc32k
+    maxItems: 1

Usually assigned-clockXXX are not needed in the bindings. Is here something different? They are put only to indicate something special.

Quoted 28 lines
Documentation/devicetree/bindings/rtc/ti,k3-rtc.yaml new file +28 -0
+
+  wakeup-source: true
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - clocks
+  - clock-names
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    rtc@2b1f0000 {
+        compatible = "ti,am62-rtc";
+        reg = <0x2b1f0000 0x100>;
+        interrupts = <GIC_SPI 100 IRQ_TYPE_LEVEL_HIGH>;
+        power-domains = <&bar 0>;
+        clocks = <&foo 0>, <&foo 1>;
+        clock-names = "vbus", "osc32k";
+        wakeup-source;
+    };
+
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    rtc@2b1f0000 {

Documentation/devicetree/bindings/rtc/ti,k3-rtc.yaml line 86

Quoted 10 lines
Documentation/devicetree/bindings/rtc/ti,k3-rtc.yaml new file +10 -0
+        compatible = "ti,am62-rtc";
+        reg = <0x2b1f0000 0x100>;
+        interrupts = <GIC_SPI 100 IRQ_TYPE_LEVEL_HIGH>;
+        power-domains = <&bar 0>;
+        clocks = <&foo 0>, <&foo 1>;
+        clock-names = "vbus", "osc32k";
+        wakeup-source;
+        assigned-clocks = <&foo 1>;
+        assigned-clock-parents = <&foo 2>;
+

Unneeded blank line.

Quoted 1 line

+ };

Best regards,
Krzysztof

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#3 lore raw

Re: [PATCH 1/2] dt-bindings: rtc: Add TI K3 RTC devicetree bindings documentation

Quoted 5 lines · Krzysztof Kozlowski

Documentation/devicetree/bindings/rtc/ti,k3-rtc.yaml line 17

Quoted 3 lines
Documentation/devicetree/bindings/rtc/ti,k3-rtc.yaml new file +3 -0
+properties:
+  compatible:
+    items:

No need for items. Just enum under the compatible.

Will fix in next rev. Thanks for catching.

Quoted 13 lines
Quoted 13 lines
Documentation/devicetree/bindings/rtc/ti,k3-rtc.yaml new file +12 -0
+      - enum:
+          - ti,am62-rtc
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  clocks:
+    items:
+      - description: VBUS Interface clock
Quoted 8 lines

Documentation/devicetree/bindings/rtc/ti,k3-rtc.yaml line 35

Quoted 6 lines
Documentation/devicetree/bindings/rtc/ti,k3-rtc.yaml new file +6 -0
+      - description: 32k Clock source (external or internal).
+
+  clock-names:
+    items:
+      - const: "vbus"
+      - const: "osc32k"

No quotes.

Uggh.. my bad. yup

Quoted 17 lines
Quoted 4 lines
Documentation/devicetree/bindings/rtc/ti,k3-rtc.yaml new file +3 -0
+
+  power-domains:
+    maxItems: 1

Documentation/devicetree/bindings/rtc/ti,k3-rtc.yaml line 48

Quoted 10 lines
Documentation/devicetree/bindings/rtc/ti,k3-rtc.yaml new file +10 -0
+
+  assigned-clocks:
+    description: |
+      override default osc32k parent clock reference to the osc32k clock entry
+    maxItems: 1
+
+  assigned-clock-parents:
+    description: |
+      override default osc32k parent clock phandle of the new parent clock of osc32k
+    maxItems: 1

Usually assigned-clockXXX are not needed in the bindings. Is here something different? They are put only to indicate something special.

I wonder if I should rather use unevaluatedproperties instead? If I use
additionalProperties: False, then the second example below fails.

Thoughts?

Quoted 33 lines
Quoted 33 lines
Documentation/devicetree/bindings/rtc/ti,k3-rtc.yaml new file +32 -0
+
+  wakeup-source: true
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - clocks
+  - clock-names
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    rtc@2b1f0000 {
+        compatible = "ti,am62-rtc";
+        reg = <0x2b1f0000 0x100>;
+        interrupts = <GIC_SPI 100 IRQ_TYPE_LEVEL_HIGH>;
+        power-domains = <&bar 0>;
+        clocks = <&foo 0>, <&foo 1>;
+        clock-names = "vbus", "osc32k";
+        wakeup-source;
+    };
+
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    rtc@2b1f0000 {
+        compatible = "ti,am62-rtc";
+        reg = <0x2b1f0000 0x100>;
+        interrupts = <GIC_SPI 100 IRQ_TYPE_LEVEL_HIGH>;
+        power-domains = <&bar 0>;
Quoted 8 lines

Documentation/devicetree/bindings/rtc/ti,k3-rtc.yaml line 86

Quoted 6 lines
Documentation/devicetree/bindings/rtc/ti,k3-rtc.yaml new file +6 -0
+        clocks = <&foo 0>, <&foo 1>;
+        clock-names = "vbus", "osc32k";
+        wakeup-source;
+        assigned-clocks = <&foo 1>;
+        assigned-clock-parents = <&foo 2>;
+

Unneeded blank line.

Ack.

Signature · 8 lines
Regards,
Nishanth Menon
Key (0xDDB5849D1736249D) / Fingerprint: F8A2 8693 54EB 8232 17A3  1A34 DDB5 849D 1736 249D

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#4 lore raw

Re: [PATCH 1/2] dt-bindings: rtc: Add TI K3 RTC devicetree bindings documentation

Quoted 10 lines · Nishanth Menon
Quoted 10 lines
Quoted 9 lines
Documentation/devicetree/bindings/rtc/ti,k3-rtc.yaml new file +9 -0
+  assigned-clocks:
+    description: |
+      override default osc32k parent clock reference to the osc32k clock entry
+    maxItems: 1
+
+  assigned-clock-parents:
+    description: |
+      override default osc32k parent clock phandle of the new parent clock of osc32k
+    maxItems: 1
Quoted 6 lines
Quoted 2 lines

Usually assigned-clockXXX are not needed in the bindings. Is here something different? They are put only to indicate something special.

I wonder if I should rather use unevaluatedproperties instead? If I use
additionalProperties: False, then the second example below fails.

Are you sure it fails? I just checked and it worked in my case. This AFAIR was working since some time (or fixed some time ago), so maybe update your dtschema?

Best regards,
Krzysztof

#5 lore raw

Re: [PATCH 1/2] dt-bindings: rtc: Add TI K3 RTC devicetree bindings documentation

Quoted 14 lines · Krzysztof Kozlowski
Quoted 13 lines · Nishanth Menon
Quoted 12 lines

Documentation/devicetree/bindings/rtc/ti,k3-rtc.yaml line 48

Quoted 9 lines
Documentation/devicetree/bindings/rtc/ti,k3-rtc.yaml new file +9 -0
+  assigned-clocks:
+    description: |
+      override default osc32k parent clock reference to the osc32k clock entry
+    maxItems: 1
+
+  assigned-clock-parents:
+    description: |
+      override default osc32k parent clock phandle of the new parent clock of osc32k
+    maxItems: 1

Usually assigned-clockXXX are not needed in the bindings. Is here something different? They are put only to indicate something special.

Quoted 7 lines
Quoted 3 lines

I wonder if I should rather use unevaluatedproperties instead? If I use
additionalProperties: False, then the second example below fails.

Are you sure it fails? I just checked and it worked in my case. This AFAIR was working since some time (or fixed some time ago), so maybe update your dtschema?

Arrgh, Thanks and you are right.
Apologies, I should have cross checked again since developing late last year (understood the min schema currently is 2022.3).

Will fix this up in the repost v2 in a short while.

Signature · 3 lines
Regards,
Nishanth Menon
Key (0xDDB5849D1736249D) / Fingerprint: F8A2 8693 54EB 8232 17A3  1A34 DDB5 849D 1736 249D
maintainer
#6 lore raw

Re: [PATCH 1/2] dt-bindings: rtc: Add TI K3 RTC devicetree bindings documentation

In reply to Nishanth Menon
Quoted 3 lines · Nishanth Menon

This adds the documentation for the devicetree bindings of the Texas Instruments RTC modules on K3 family of SoCs such as AM62x SoCs or newer.

'devicetree bindings documentation' in the subject is redundant. You already said that with 'dt-bindings'.

Rob

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#7 lore raw

PATCH 2/2 rtc: Introduce ti-k3-rtc

In reply to Nishanth Menon

Introduce support for Texas Instruments Real Time Clock controller on newer K3 family of SoCs such as AM62x.

The hardware module that is being supported is the "digital only" version which does'nt have capability of external wakeup sources and external power backup. However, for many practical applications, this should suffice as RTC is operational across low power sequences.

The hardware block by itself is split into two distinct domains internally to further reduce the power consumption with the actual counter block and comparators clocked off a 32k clock source (which based on SoC integration can be sourced by an external crystal) and an register interface block which is driven by the bus clock. While optimal from power perspective, it does create some complicated synchronizations and sequences that one must be wary of in the driver handling.

---
 drivers/rtc/Kconfig     |  10 +
 drivers/rtc/Makefile    |   1 +
 drivers/rtc/rtc-ti-k3.c | 687 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 698 insertions(+)
 create mode 100644 drivers/rtc/rtc-ti-k3.c
drivers/rtc/Kconfig +10 -0
index 41c65b4d2baf..972602af8838 100644
@@ -1922,6 +1922,16 @@ config RTC_DRV_ASPEED
 	  This driver can also be built as a module, if so, the module
 	  will be called "rtc-aspeed".
 
+config RTC_DRV_TI_K3
+	tristate "TI K3 RTC"
+	depends on ARCH_K3 || COMPILE_TEST
+	help
+	  If you say yes here you get support for the Texas Instruments's
+	  Real Time Clock for K3 architecture.
+
+	  This driver can also be built as a module, if so, the module
+	  will be called "rtc-ti-k3".
+
 comment "HID Sensor RTC drivers"
 
 config RTC_DRV_HID_SENSOR_TIME
drivers/rtc/Makefile +1 -0
index 2d827d8261d5..b74128e174d7 100644
@@ -183,3 +183,4 @@ obj-$(CONFIG_RTC_DRV_WM8350)	+= rtc-wm8350.o
 obj-$(CONFIG_RTC_DRV_X1205)	+= rtc-x1205.o
 obj-$(CONFIG_RTC_DRV_XGENE)	+= rtc-xgene.o
 obj-$(CONFIG_RTC_DRV_ZYNQMP)	+= rtc-zynqmp.o
+obj-$(CONFIG_RTC_DRV_TI_K3)	+= rtc-ti-k3.o
drivers/rtc/rtc-ti-k3.c new file +687 -0

687 lines not on this page · raw message

Signature · 7 lines
2.31.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#8 lore raw

Re: [PATCH 2/2] rtc: Introduce ti-k3-rtc

On 4/12/22 2:31 AM, Nishanth Menon wrote:
[...]

drivers/rtc/rtc-ti-k3.c line 96

Quoted 4 lines
drivers/rtc/rtc-ti-k3.c new file +4 -0
+
+static inline u32 k3rtc_readl(struct ti_k3_rtc *priv, u32 offset)
+{
+	return readl(priv->rtc_base + offset);

Could we use regmap in this driver?

[...]

drivers/rtc/rtc-ti-k3.c line 297

Quoted 3 lines
drivers/rtc/rtc-ti-k3.c new file +3 -0
+
+	reg = k3rtc_readl(priv, REG_K3RTC_IRQENABLE_SET_SYS);
+	reg &= K3RTC_EVENT_ON_OFF_BIT;

regmap fields to get rid of all the bitmasking

[...]

drivers/rtc/rtc-ti-k3.c line 496

Quoted 9 lines
drivers/rtc/rtc-ti-k3.c new file +9 -0
+		return 0;
+
+	k3rtc_writel(priv, offset, K3RTC_EVENT_ON_OFF_BIT);
+
+	for (i = 0; i < bytes / 4; i++) {
+		val[i] = k3rtc_readl(priv,
+				     REG_K3RTC_SCRATCH0 + offset + (i * 4));
+	}
+

regmap_bulk_read()

[...]

drivers/rtc/rtc-ti-k3.c line 591

Quoted 5 lines
drivers/rtc/rtc-ti-k3.c new file +5 -0
+
+	priv->rtc_base = devm_platform_ioremap_resource(pdev, 0);
+	if (IS_ERR(priv->rtc_base))
+		return PTR_ERR(priv->rtc_base);
+

devm_regmap_init_mmio(dev, priv->rtc_base, ...)

[...]

Quoted 4 lines
drivers/rtc/rtc-ti-k3.c new file +4 -0
+static struct platform_driver ti_k3_rtc_driver = {
+	.probe = ti_k3_rtc_probe,
+	.driver = {
+		   .name = "rtc-ti-k3",

drivers/rtc/rtc-ti-k3.c line 687

Quoted 10 lines
drivers/rtc/rtc-ti-k3.c new file +10 -0
+		   .of_match_table = ti_k3_rtc_of_match_table,
+		   .pm = &ti_k3_rtc_pm_ops,
+		   },
+};
+module_platform_driver(ti_k3_rtc_driver);
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("TI K3 RTC driver");
+MODULE_AUTHOR("Nishanth Menon");
+MODULE_ALIAS("platform:rtc-ti-k3");

Is MODULE_ALIAS needed here? The MODULE_DEVICE_TABLE above will build the MOD ALIAS table needed for OF loading.

Andrew

#9 lore raw

Re: [PATCH 2/2] rtc: Introduce ti-k3-rtc

In reply to Nishanth Menon

Hi,

Quoted 8 lines · Nishanth Menon
drivers/rtc/rtc-ti-k3.c new file +8 -0
+/**
+ * k3rtc_fence  - Ensure a register sync took place between the two domains
+ * @priv:      pointer to priv data
+ *
+ * Return: 0 if the sync took place, else returns -ETIMEDOUT
+ */
+static int k3rtc_fence(struct ti_k3_rtc *priv)
+{

drivers/rtc/rtc-ti-k3.c line 121

Quoted 10 lines
drivers/rtc/rtc-ti-k3.c new file +10 -0
+	u32 timeout = priv->sync_timeout_us;
+	u32 mask = K3RTC_RD_PEND_BIT | K3RTC_WR_PEND_BIT;
+	u32 val = 0;
+
+	while (timeout--) {
+		val = k3rtc_readl(priv, REG_K3RTC_SYNCPEND);
+		if (!(val & mask))
+			return 0;
+		usleep_range(1, 2);
+	}

readl_poll_timeout() ?

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+	pr_err("RTC Fence timeout: 0x%08x\n", val);

Can we use dev_err()? Provides better indication of the driver throwing error.

Quoted 20 lines
drivers/rtc/rtc-ti-k3.c new file +20 -0
+	return -ETIMEDOUT;
+}
+
+static inline int k3rtc_check_unlocked(struct ti_k3_rtc *priv)
+{
+	u32 val;
+
+	val = k3rtc_readl(priv, REG_K3RTC_GENERAL_CTL);
+	return (val & K3RTC_UNLOCK_BIT) ? 0 : 1;
+}
+
+static int k3rtc_unlock_rtc(struct ti_k3_rtc *priv)
+{
+	u32 timeout = priv->sync_timeout_us;
+	int ret;
+
+	ret = k3rtc_check_unlocked(priv);
+	if (!ret)
+		return ret;
+

drivers/rtc/rtc-ti-k3.c line 153

Quoted 10 lines
drivers/rtc/rtc-ti-k3.c new file +10 -0
+	k3rtc_writel(priv, REG_K3RTC_KICK0, K3RTC_KICK0_UNLOCK_VALUE);
+	k3rtc_writel(priv, REG_K3RTC_KICK1, K3RTC_KICK1_UNLOCK_VALUE);
+
+	/* Skip fence since we are going to check the unlock bit as fence */
+	while (timeout--) {
+		ret = k3rtc_check_unlocked(priv);
+		if (!ret)
+			return ret;
+		usleep_range(1, 2);
+	}

readl_poll_timeout() ?

Quoted 65 lines
drivers/rtc/rtc-ti-k3.c new file +65 -0
+
+	return -ETIMEDOUT;
+}
+
+static int k3rtc_configure(struct device *dev)
+{
+	int ret;
+	u32 ctl;
+	struct ti_k3_rtc *priv = dev_get_drvdata(dev);
+
+	/*
+	 * HWBUG: The compare statemachine is broken if the RTC module
+	 * is NOT unlocked in under one second of boot - which is pretty long
+	 * time from the perspective of Linux driver (module load, u-boot
+	 * shell all can take much longer than this.
+	 *
+	 * In such occurrence, it is assumed that the RTC module is un-usable
+	 */
+	if (priv->soc->unlock_irq_erratum) {
+		ret = k3rtc_check_unlocked(priv);
+		/* If there is an error OR if we are locked, return error */
+		if (ret) {
+			dev_err(dev, HW_ERR "Erratum i2327 unlock QUIRK! Cannot operate!!\n");
+			return -EFAULT;
+		}
+	} else {
+		/* May Need to explicitly unlock first time */
+		ret = k3rtc_unlock_rtc(priv);
+		if (ret) {
+			dev_err(dev, "Failed to unlock(%d)!\n", ret);
+			return ret;
+		}
+	}
+
+	/* Enable Shadow register sync on 32k clk boundary */
+	ctl = k3rtc_readl(priv, REG_K3RTC_GENERAL_CTL);
+	ctl |= K3RTC_O32K_OSC_DEP_EN_BIT;
+	k3rtc_writel(priv, REG_K3RTC_GENERAL_CTL, ctl);
+
+	/*
+	 * Wait at least 2 clk sync time before proceeding further programming.
+	 * This ensures that the 32k based sync is active.
+	 */
+	usleep_range(priv->sync_timeout_us, priv->sync_timeout_us + 5);
+
+	/* We need to ensure fence here to make sure sync here */
+	ret = k3rtc_fence(priv);
+	if (ret) {
+		dev_err(dev, "Failed fence osc_dep enable(%d) - is 32k clk working?!\n",
+			ret);
+		return ret;
+	}
+
+	/* Lets just make sure we get consistent time value */
+	ctl &= ~K3RTC_CNT_FMODE_MASK;
+	/*
+	 * FMODE setting: Reading lower seconds will freeze value on higher
+	 * seconds. This also implies that we must *ALWAYS* read lower seconds
+	 * prior to reading higher seconds
+	 */
+	ctl |= K3RTC_CNT_FMODE_S_CNT_VALUE;
+	k3rtc_writel(priv, REG_K3RTC_GENERAL_CTL, ctl);
+
+	/* Clear any spurious IRQ sources if any */
+	k3rtc_writel(priv, REG_K3RTC_IRQSTATUS_SYS,

drivers/rtc/rtc-ti-k3.c line 228

Quoted 10 lines
drivers/rtc/rtc-ti-k3.c new file +10 -0
+		     K3RTC_EVENT_ON_OFF_BIT | K3RTC_EVENT_OFF_ON_BIT);
+	/* Disable all IRQs */
+	k3rtc_writel(priv, REG_K3RTC_IRQENABLE_CLR_SYS,
+		     K3RTC_EVENT_ON_OFF_BIT | K3RTC_EVENT_OFF_ON_BIT);
+
+	/* And.. Let us Sync the writes in */
+	ret = k3rtc_fence(priv);
+	if (ret) {
+		dev_err(dev, "Failed to fence(%d)!\n", ret);
+		return ret;

nit: this can be dropped as next statement will return error code anyway

Quoted 5 lines
drivers/rtc/rtc-ti-k3.c new file +5 -0
+	}
+
+	return ret;
+}
+

[...]

drivers/rtc/rtc-ti-k3.c line 653

Quoted 13 lines
drivers/rtc/rtc-ti-k3.c new file +13 -0
+
+static const struct ti_k3_rtc_soc_data ti_k3_am62_data = {
+	.unlock_irq_erratum = true,
+};
+
+static const struct of_device_id ti_k3_rtc_of_match_table[] = {
+	{.compatible = "ti,am62-rtc", .data = &ti_k3_am62_data},
+	{}
+};
+MODULE_DEVICE_TABLE(of, ti_k3_rtc_of_match_table);
+
+#ifdef CONFIG_PM_SLEEP
+static int ti_k3_rtc_suspend(struct device *dev)

__maybe_unused preferred instead of #ifdef for better compile coverage
but upto you.

Quoted 17 lines
drivers/rtc/rtc-ti-k3.c new file +17 -0
+{
+	struct ti_k3_rtc *priv = dev_get_drvdata(dev);
+
+	if (device_may_wakeup(dev))
+		enable_irq_wake(priv->irq);
+	return 0;
+}
+
+static int ti_k3_rtc_resume(struct device *dev)
+{
+	struct ti_k3_rtc *priv = dev_get_drvdata(dev);
+
+	if (device_may_wakeup(dev))
+		disable_irq_wake(priv->irq);
+	return 0;
+}
+#endif

drivers/rtc/rtc-ti-k3.c line 680

Quoted 10 lines
drivers/rtc/rtc-ti-k3.c new file +10 -0
+
+static SIMPLE_DEV_PM_OPS(ti_k3_rtc_pm_ops, ti_k3_rtc_suspend, ti_k3_rtc_resume);
+
+static struct platform_driver ti_k3_rtc_driver = {
+	.probe = ti_k3_rtc_probe,
+	.driver = {
+		   .name = "rtc-ti-k3",
+		   .of_match_table = ti_k3_rtc_of_match_table,
+		   .pm = &ti_k3_rtc_pm_ops,
+		   },

Extra tab?

Quoted 8 lines
drivers/rtc/rtc-ti-k3.c new file +7 -1
+};
+module_platform_driver(ti_k3_rtc_driver);
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("TI K3 RTC driver");
+MODULE_AUTHOR("Nishanth Menon");
+MODULE_ALIAS("platform:rtc-ti-k3");
-- 2.31.1
#10 lore raw

Re: [PATCH 2/2] rtc: Introduce ti-k3-rtc

Quoted 24 lines · Vignesh Raghavendra

Hi,

Quoted 8 lines · Nishanth Menon
drivers/rtc/rtc-ti-k3.c new file +8 -0
+/**
+ * k3rtc_fence  - Ensure a register sync took place between the two domains
+ * @priv:      pointer to priv data
+ *
+ * Return: 0 if the sync took place, else returns -ETIMEDOUT
+ */
+static int k3rtc_fence(struct ti_k3_rtc *priv)
+{

drivers/rtc/rtc-ti-k3.c line 121

Quoted 10 lines
drivers/rtc/rtc-ti-k3.c new file +10 -0
+	u32 timeout = priv->sync_timeout_us;
+	u32 mask = K3RTC_RD_PEND_BIT | K3RTC_WR_PEND_BIT;
+	u32 val = 0;
+
+	while (timeout--) {
+		val = k3rtc_readl(priv, REG_K3RTC_SYNCPEND);
+		if (!(val & mask))
+			return 0;
+		usleep_range(1, 2);
+	}

readl_poll_timeout() ?

Quoted 6 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+	pr_err("RTC Fence timeout: 0x%08x\n", val);

Can we use dev_err()? Provides better indication of the driver throwing error.

What would the user do with this information in the kernel logs? Please do not add error strings that will never be used. Returning -ETIMEDOUT is probably enough.

Quoted 3 lines
Quoted 3 lines
drivers/rtc/rtc-ti-k3.c new file +3 -0
+	return -ETIMEDOUT;
+}
+
Signature · 3 lines
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com