Skip to contentSkip to conversation

support for amlogic rtc

PATCH Superseded Xianwei Zhao 5 participants 16 messages Aug 23, 2024 – Sep 3, 2024

Subsystems (3)

v1 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

cover support for amlogic rtc

Add rtc driver and bindigns for the amlogic A113L2 and A113X2 SoCs

---
Yiting Deng (3):
dt-bindings: rtc: Add Amlogic A311L2 and A113X2 rtc
rtc: support for the Amlogic on-chip RTC
MAINTAINERS: Add an entry for Amlogic RTC driver

 .../bindings/rtc/amlogic,amlogic-rtc.yaml          |  66 +++
 MAINTAINERS                                        |   8 +
 drivers/rtc/Kconfig                                |  12 +
 drivers/rtc/Makefile                               |   1 +
 drivers/rtc/rtc-amlogic.c                          | 589 +++++++++++++++++++++
 5 files changed, 676 insertions(+)

---
base-commit: dff71e5c6076314f3eefe700abd6af834c57bd64
change-id: 20240823-rtc-127cd8192a13

Best regards,

Signature · 1 line
Xianwei Zhao <[email protected]>
#1 lore raw

PATCH 1/3 dt-bindings: rtc: Add Amlogic A311L2 and A113X2 rtc

From: Yiting Deng <[email protected]>

Add documentation describing the Amlogic A113L2 and A113X2 rtc controller.

---
 .../bindings/rtc/amlogic,amlogic-rtc.yaml          | 66 ++++++++++++++++++++++
 1 file changed, 66 insertions(+)
Documentation/devicetree/bindings/rtc/amlogic,amlogic-rtc.yaml new file +66 -0
new file mode 100644
index 000000000000..fa3d7838022e
@@ -0,0 +1,66 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+# Copyright (C) 2024 Amlogic, Inc. All rights reserved
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/rtc/amlogic,amlogic-rtc.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Amlogic Real Time Clock controller include a4, a5
+
+maintainers:
+  - Yiting Deng <[email protected]>
+  - Xianwei Zhao <[email protected]>
+
+description:
+  The Amlogic new chips used RTC module.
+
+allOf:
+  - $ref: rtc.yaml#
+
+properties:
+  compatible:
+    enum:
+      - amlogic,a4-rtc
+      - amlogic,a5-rtc
+
+  reg:
+    maxItems: 1
+
+  clocks:
+    items:
+      - description: RTC clock source, available 24M or 32K crystal
+          oscillator source. when using 24M, need to divide 24M into 32K.
+      - description: RTC module accesses the clock of the apb bus.
+
+  clock-names:
+    items:
+      - const: rtc_osc
+      - const: rtc_sys_clk
+
+  interrupts:
+    maxItems: 1
+
+required:
+  - compatible
+  - interrupts
+  - reg
+  - clocks
+  - clock-names
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    apb {
+        #address-cells = <2>;
+        #size-cells = <2>;
+
+        rtc: rtc@8e600 {
+            compatible = "amlogic,a4-rtc";
+            interrupts = <GIC_SPI 131 IRQ_TYPE_EDGE_RISING>;
+            reg = <0x0 0x8e600 0x0 0x38>;
+            clocks = <&xtal_32k>, <&clkc_periphs 1>;
+            clock-names = "rtc_osc", "rtc_sys_clk";
+        };
+    };
Signature · 1 line
2.37.1
#2 lore raw

Re: [PATCH 1/3] dt-bindings: rtc: Add Amlogic A311L2 and A113X2 rtc

Documentation/devicetree/bindings/rtc/amlogic,amlogic-rtc.yaml

Quoted 15 lines · On Fri, Aug 23, 2024 at 05:19:44PM +0800, Xianwei Zhao via B4 Relay wrote:

From: Yiting Deng <[email protected]>

Add documentation describing the Amlogic A113L2 and A113X2 rtc controller.

---
 .../bindings/rtc/amlogic,amlogic-rtc.yaml          | 66 ++++++++++++++++++++++
 1 file changed, 66 insertions(+)
Documentation/devicetree/bindings/rtc/amlogic,amlogic-rtc.yaml new file +0 -0
new file mode 100644
index 000000000000..fa3d7838022e

Filename matching a compatible please.

Quoted 15 lines
Documentation/devicetree/bindings/rtc/amlogic,amlogic-rtc.yaml new file +14 -0
@@ -0,0 +1,66 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+# Copyright (C) 2024 Amlogic, Inc. All rights reserved
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/rtc/amlogic,amlogic-rtc.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Amlogic Real Time Clock controller include a4, a5
+
+maintainers:
+  - Yiting Deng <[email protected]>
+  - Xianwei Zhao <[email protected]>
+
+description:

Documentation/devicetree/bindings/rtc/amlogic,amlogic-rtc.yaml line 24

Quoted 10 lines
Documentation/devicetree/bindings/rtc/amlogic,amlogic-rtc.yaml new file +10 -0
+  The Amlogic new chips used RTC module.
+
+allOf:
+  - $ref: rtc.yaml#
+
+properties:
+  compatible:
+    enum:
+      - amlogic,a4-rtc
+      - amlogic,a5-rtc

The names you have chosen here do not match the patch description. What is going on there?

Quoted 4 lines
Documentation/devicetree/bindings/rtc/amlogic,amlogic-rtc.yaml new file +4 -0
+
+  reg:
+    maxItems: 1
+

Documentation/devicetree/bindings/rtc/amlogic,amlogic-rtc.yaml line 38

Quoted 10 lines
Documentation/devicetree/bindings/rtc/amlogic,amlogic-rtc.yaml new file +10 -0
+  clocks:
+    items:
+      - description: RTC clock source, available 24M or 32K crystal
+          oscillator source. when using 24M, need to divide 24M into 32K.
+      - description: RTC module accesses the clock of the apb bus.
+
+  clock-names:
+    items:
+      - const: rtc_osc
+      - const: rtc_sys_clk

s/_clk//, they're all clocks.

Quoted 11 lines
Documentation/devicetree/bindings/rtc/amlogic,amlogic-rtc.yaml new file +11 -0
+
+  interrupts:
+    maxItems: 1
+
+required:
+  - compatible
+  - interrupts
+  - reg
+  - clocks
+  - clock-names
+

Documentation/devicetree/bindings/rtc/amlogic,amlogic-rtc.yaml line 59

Quoted 10 lines
Documentation/devicetree/bindings/rtc/amlogic,amlogic-rtc.yaml new file +10 -0
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    apb {
+        #address-cells = <2>;
+        #size-cells = <2>;
+
+        rtc: rtc@8e600 {

And the label here can go, you've got no references to it :)

Thanks,
Conor.

Quoted 12 lines
Documentation/devicetree/bindings/rtc/amlogic,amlogic-rtc.yaml new file +7 -0
+            compatible = "amlogic,a4-rtc";
+            interrupts = <GIC_SPI 131 IRQ_TYPE_EDGE_RISING>;
+            reg = <0x0 0x8e600 0x0 0x38>;
+            clocks = <&xtal_32k>, <&clkc_periphs 1>;
+            clock-names = "rtc_osc", "rtc_sys_clk";
+        };
+    };
Signature · 2 lines
-- 
2.37.1
#3 lore raw

Re: [PATCH 1/3] dt-bindings: rtc: Add Amlogic A311L2 and A113X2 rtc

Hi Conor,
Thanks for your reply.

Quoted 24 lines · Conor Dooley

Subject:
Re: [PATCH 1/3] dt-bindings: rtc: Add Amlogic A311L2 and A113X2 rtc From:
Conor Dooley <[email protected]>
Date:
2024/8/23 23:51

To:
[email protected]
CC:
Yiting Deng <[email protected]>, Alexandre Belloni <[email protected]>, Rob Herring <[email protected]>, Krzysztof Kozlowski <[email protected]>, Conor Dooley <[email protected]>, [email protected], [email protected], [email protected], [email protected]

Quoted 10 lines · On Fri, Aug 23, 2024 at 05:19:44PM +0800, Xianwei Zhao via B4 Relay wrote:

From: Yiting Deng<[email protected]>

Add documentation describing the Amlogic A113L2 and A113X2 rtc controller.

---
  .../bindings/rtc/amlogic,amlogic-rtc.yaml          | 66 ++++++++++++++++++++++
  1 file changed, 66 insertions(+)
Quoted 7 lines

Documentation/devicetree/bindings/rtc/amlogic,amlogic-rtc.yaml

Quoted 5 lines
Documentation/devicetree/bindings/rtc/amlogic,amlogic-rtc.yaml new file +0 -0
new file mode 100644
index 000000000000..fa3d7838022e

Filename matching a compatible please.

Will do, modify the name to "amlogic,a4-rtc.yaml".

Quoted 19 lines
Quoted 19 lines
Documentation/devicetree/bindings/rtc/amlogic,amlogic-rtc.yaml new file +18 -0
@@ -0,0 +1,66 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+# Copyright (C) 2024 Amlogic, Inc. All rights reserved
+%YAML 1.2
+---
+$id:http://devicetree.org/schemas/rtc/amlogic,amlogic-rtc.yaml#
+$schema:http://devicetree.org/meta-schemas/core.yaml#
+
+title: Amlogic Real Time Clock controller include a4, a5
+
+maintainers:
+  - Yiting Deng<[email protected]>
+  - Xianwei Zhao<[email protected]>
+
+description:
+  The Amlogic new chips used RTC module.
+
+allOf:
+  - $ref: rtc.yaml#
Quoted 9 lines

Documentation/devicetree/bindings/rtc/amlogic,amlogic-rtc.yaml line 24

Quoted 6 lines
Documentation/devicetree/bindings/rtc/amlogic,amlogic-rtc.yaml new file +6 -0
+
+properties:
+  compatible:
+    enum:
+      - amlogic,a4-rtc
+      - amlogic,a5-rtc

The names you have chosen here do not match the patch description. What is going on there?

Will modify description to "Add Amlogic A4(A311L2) and A5(A113X2) rtc".

Quoted 7 lines
Quoted 7 lines
Documentation/devicetree/bindings/rtc/amlogic,amlogic-rtc.yaml new file +7 -0
+
+  reg:
+    maxItems: 1
+
+  clocks:
+    items:
+      - description: RTC clock source, available 24M or 32K crystal
Quoted 9 lines

Documentation/devicetree/bindings/rtc/amlogic,amlogic-rtc.yaml line 38

Quoted 7 lines
Documentation/devicetree/bindings/rtc/amlogic,amlogic-rtc.yaml new file +7 -0
+          oscillator source. when using 24M, need to divide 24M into 32K.
+      - description: RTC module accesses the clock of the apb bus.
+
+  clock-names:
+    items:
+      - const: rtc_osc
+      - const: rtc_sys_clk

s/_clk//, they're all clocks.

Will do.

Quoted 14 lines
Quoted 14 lines
Documentation/devicetree/bindings/rtc/amlogic,amlogic-rtc.yaml new file +14 -0
+
+  interrupts:
+    maxItems: 1
+
+required:
+  - compatible
+  - interrupts
+  - reg
+  - clocks
+  - clock-names
+
+additionalProperties: false
+
+examples:
Quoted 9 lines

Documentation/devicetree/bindings/rtc/amlogic,amlogic-rtc.yaml line 59

Quoted 7 lines
Documentation/devicetree/bindings/rtc/amlogic,amlogic-rtc.yaml new file +7 -0
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    apb {
+        #address-cells = <2>;
+        #size-cells = <2>;
+
+        rtc: rtc@8e600 {

And the label here can go, you've got no references to it 🙂

Will delte rtc label.

Quoted 13 lines

Thanks,
Conor.

Quoted 10 lines
Documentation/devicetree/bindings/rtc/amlogic,amlogic-rtc.yaml new file +7 -0
+            compatible = "amlogic,a4-rtc";
+            interrupts = <GIC_SPI 131 IRQ_TYPE_EDGE_RISING>;
+            reg = <0x0 0x8e600 0x0 0x38>;
+            clocks = <&xtal_32k>, <&clkc_periphs 1>;
+            clock-names = "rtc_osc", "rtc_sys_clk";
+        };
+    };
Signature · 2 lines
-- 
2.37.1
#4 lore raw

PATCH 2/3 rtc: support for the Amlogic on-chip RTC

In reply to Xianwei Zhao

From: Yiting Deng <[email protected]>

Support for the on-chip RTC found in some of Amlogic's SoCs such as the A113L2 and A113X2.

---
 drivers/rtc/Kconfig       |  12 +
 drivers/rtc/Makefile      |   1 +
 drivers/rtc/rtc-amlogic.c | 589 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 602 insertions(+)
drivers/rtc/Kconfig +12 -0
index 2a95b05982ad..0dd042701c3b 100644
@@ -2043,4 +2043,16 @@ config RTC_DRV_SSD202D
 	  This driver can also be built as a module, if so, the module
 	  will be called "rtc-ssd20xd".
 
+config RTC_DRV_AMLOGIC
+	tristate "Amlogic RTC"
+	depends on ARCH_MESON || COMPILE_TEST
+	select REGMAP_MMIO
+	default y
+	help
+	  If you say yes here you get support for the RTC block on the
+	  Amlogic A113L2(A4) and A113X2(A5) SoCs.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called "rtc-amlogic".
+
 endif # RTC_CLASS
drivers/rtc/Makefile +1 -0
index 3004e372f25f..d4a56ddb4246 100644
@@ -26,6 +26,7 @@ obj-$(CONFIG_RTC_DRV_ABB5ZES3)	+= rtc-ab-b5ze-s3.o
 obj-$(CONFIG_RTC_DRV_ABEOZ9)	+= rtc-ab-eoz9.o
 obj-$(CONFIG_RTC_DRV_ABX80X)	+= rtc-abx80x.o
 obj-$(CONFIG_RTC_DRV_AC100)	+= rtc-ac100.o
+obj-$(CONFIG_RTC_DRV_AMLOGIC)	+= rtc-amlogic.o
 obj-$(CONFIG_RTC_DRV_ARMADA38X)	+= rtc-armada38x.o
 obj-$(CONFIG_RTC_DRV_AS3722)	+= rtc-as3722.o
 obj-$(CONFIG_RTC_DRV_ASM9260)	+= rtc-asm9260.o
drivers/rtc/rtc-amlogic.c new file +589 -0

589 lines not on this page · raw message

Signature · 1 line
2.37.1
#5 lore raw

Re: [PATCH 2/3] rtc: support for the Amlogic on-chip RTC

Quoted 18 lines · On 23/08/2024 11:19, Xianwei Zhao via B4 Relay wrote:

From: Yiting Deng <[email protected]>

Support for the on-chip RTC found in some of Amlogic's SoCs such as the A113L2 and A113X2.

---
 drivers/rtc/Kconfig       |  12 +
 drivers/rtc/Makefile      |   1 +
 drivers/rtc/rtc-amlogic.c | 589 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 602 insertions(+)
drivers/rtc/Kconfig +0 -0
index 2a95b05982ad..0dd042701c3b 100644

drivers/rtc/Kconfig config RTC_DRV_SSD202D · line 2048

Quoted 6 lines
drivers/rtc/Kconfig +3 -0
@@ -2043,4 +2043,16 @@ config RTC_DRV_SSD202D
 	  This driver can also be built as a module, if so, the module
 	  will be called "rtc-ssd20xd".
 
+config RTC_DRV_AMLOGIC
+	tristate "Amlogic RTC"
+	depends on ARCH_MESON || COMPILE_TEST

So the third driver? What is wrong with existing ones? And why this one is named so differently?

Quoted 23 lines
drivers/rtc/Kconfig +9 -0
+	select REGMAP_MMIO
+	default y
+	help
+	  If you say yes here you get support for the RTC block on the
+	  Amlogic A113L2(A4) and A113X2(A5) SoCs.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called "rtc-amlogic".
+
 endif # RTC_CLASS
drivers/rtc/Makefile +1 -0
index 3004e372f25f..d4a56ddb4246 100644
@@ -26,6 +26,7 @@ obj-$(CONFIG_RTC_DRV_ABB5ZES3)	+= rtc-ab-b5ze-s3.o
 obj-$(CONFIG_RTC_DRV_ABEOZ9)	+= rtc-ab-eoz9.o
 obj-$(CONFIG_RTC_DRV_ABX80X)	+= rtc-abx80x.o
 obj-$(CONFIG_RTC_DRV_AC100)	+= rtc-ac100.o
+obj-$(CONFIG_RTC_DRV_AMLOGIC)	+= rtc-amlogic.o
 obj-$(CONFIG_RTC_DRV_ARMADA38X)	+= rtc-armada38x.o
 obj-$(CONFIG_RTC_DRV_AS3722)	+= rtc-as3722.o
 obj-$(CONFIG_RTC_DRV_ASM9260)	+= rtc-asm9260.o
 

drivers/rtc/Makefile obj-$(CONFIG_RTC_DRV_ABB5ZES3) += rtc-ab-b5ze-s3.o

Quoted 10 lines
drivers/rtc/Makefile +9 -0
 
+
+static int aml_rtc_adjust_sec(struct device *dev, u32 match_counter,
+			      int ops, int enable)
+{
+	struct aml_rtc_data *rtc = dev_get_drvdata(dev->parent);
+	u32 reg_val;
+
+	if (!FIELD_FIT(RTC_MATCH_COUNTER, match_counter)) {
+		pr_err("%s: invalid match_counter\n", __func__);

No, do not use pr_, but driver ones.

Quoted 42 lines
drivers/rtc/Makefile +42 -0
+		return -EINVAL;
+	}
+
+	reg_val = FIELD_PREP(RTC_SEC_ADJUST_CTRL, ops)
+		  | FIELD_PREP(RTC_MATCH_COUNTER, match_counter)
+		  | FIELD_PREP(RTC_ADJ_VALID, enable);
+	/* Set sec_adjust_ctrl, match_counter and Valid adjust */
+	regmap_write(rtc->map, RTC_SEC_ADJUST_REG, reg_val);
+
+	return 0;
+}
+
+static int aml_rtc_set_calibration(struct device *dev, u32 calibration)
+{
+	int cal_ops, enable, match_counter;
+	int ret;
+
+	match_counter = FIELD_GET(RTC_MATCH_COUNTER, calibration);
+	cal_ops = FIELD_GET(RTC_SEC_ADJUST_CTRL, calibration);
+	enable = FIELD_GET(RTC_ADJ_VALID, calibration);
+
+	ret = aml_rtc_adjust_sec(dev, match_counter, cal_ops, enable);
+	dev_dbg(dev, "%s: Success to store RTC calibration attribute\n",
+		__func__);
+
+	return ret;
+}
+
+static int aml_rtc_get_calibration(struct device *dev, u32 *calibration)
+{
+	struct aml_rtc_data *rtc = dev_get_drvdata(dev->parent);
+	u32 reg_val;
+
+	regmap_read(rtc->map, RTC_SEC_ADJUST_REG, &reg_val);
+	*calibration = FIELD_GET(RTC_SEC_ADJUST_CTRL | RTC_MATCH_COUNTER, reg_val);
+	/* BIT is only UL defined,and GENMASK has no type, its' donot used together */
+	*calibration |= FIELD_PREP(RTC_ADJ_VALID, FIELD_GET(RTC_ADJ_VALID, reg_val));
+
+	return 0;
+}
+
+/**

drivers/rtc/Makefile

Quoted 10 lines
drivers/rtc/Makefile +10 -0
+ * The calibration value transferred from buf takes bit[18:0] to represent
+ * match_counter, while takes bit[20:19] to represent sec_adjust_ctrl, bit[23]
+ * to represent adj_valid. enable/disable sec_adjust_ctrl and match_counter.
+ * @buf: Separate buf to match_counter, sec_adjust_ctrl and adj_valid
+ *	 match_counter: bit[18:0], value is 0 ~ 0x7fff
+ *	 sec_adjust_ctrl: bit[20:19], value is 0 ~ 2. 3 to insert a second once every
+ *	 match_counter+1 seconds, 2 to swallow a second once every match_counter+1 seconds
+ *	 0 or 1 to no adjustment
+ *	 adj_valid: bit[23], value is 0 or 1, 0 to disable sec_adjust_ctrl and
+ *	 match_counter, and 1 to enable them.

Messed kerneldoc. You have warning shere. Fix it.

drivers/rtc/Makefile

Quoted 10 lines

+ */

drivers/rtc/Makefile +9 -0
+static ssize_t rtc_calibration_store(struct device *dev,
+				     struct device_attribute *attr,
+				     const char *buf, size_t count)
+{
+	int retval;
+	int calibration = 0;
+
+	if (sscanf(buf, " %i ", &calibration) != 1) {
+		dev_err(dev, "Failed to store RTC calibration attribute\n");

Where is the ABI documented?

Quoted 13 lines
drivers/rtc/Makefile +13 -0
+		return -EINVAL;
+	}
+	retval = aml_rtc_set_calibration(dev, calibration);
+
+	return retval ? retval : count;
+}
+
+static ssize_t rtc_calibration_show(struct device *dev,
+				    struct device_attribute *attr, char *buf)
+{
+	int  retval = 0;
+	u32  calibration = 0;
+

drivers/rtc/Makefile

Quoted 10 lines
drivers/rtc/Makefile +10 -0
+	retval = aml_rtc_get_calibration(dev, &calibration);
+	if (retval < 0) {
+		dev_err(dev, "Failed to read RTC calibration attribute\n");
+		sprintf(buf, "0\n");
+		return retval;
+	}
+
+	return sprintf(buf, "0x%x\n", calibration);
+}
+static DEVICE_ATTR_RW(rtc_calibration);

Document the ABI.

Quoted 28 lines
drivers/rtc/Makefile +28 -0
+
+static int rtc_set_div256_adjust(struct device *dev, u32 *value)
+{
+	struct aml_rtc_data *rtc = dev_get_drvdata(dev->parent);
+	u32 div256_adj;
+
+	div256_adj = FIELD_PREP(RTC_DIV256_ADJ_DSR | RTC_DIV256_ADJ_VAL, *value);
+	/*
+	 * AO_RTC_SEC_ADJUST_REG bit 24 insert/remove(1/0) a div256 cycle,
+	 * bit 25 valid/invalid(1/0) div256_adj_val
+	 */
+	regmap_write_bits(rtc->map, RTC_SEC_ADJUST_REG,
+			  RTC_DIV256_ADJ_DSR | RTC_DIV256_ADJ_VAL, div256_adj);
+	/* rtc need about 30ms to adjust its time after written */
+	mdelay(30);
+
+	return 0;
+}
+
+static int rtc_get_div256_adjust(struct device *dev, u32 *value)
+{
+	struct aml_rtc_data *rtc = dev_get_drvdata(dev->parent);
+	u32 reg_val;
+
+	regmap_read(rtc->map, RTC_SEC_ADJUST_REG, &reg_val);
+	*value = FIELD_GET(RTC_DIV256_ADJ_DSR | RTC_DIV256_ADJ_VAL, reg_val);
+
+	return 0;

drivers/rtc/Makefile

Quoted 10 lines
drivers/rtc/Makefile +10 -0
+}
+
+/**
+ * div256 adjust function is controlled using bit[24] and bit[25].
+ * transferred buf takes bit[0] to represent div256 adj val, bit[1]
+ * to represent div256 adj enable/disable. div256 cycle means that adjust
+ * 1/32768/256 once by written once, it's val is equal to 1/128s
+ * @buf: 3: enable div256 adjust and insert a div256 cycle
+ *	 2: enable div256 adjust and remove a div256 cycle
+ *	 1 or 0: disable div256 adjust

Again incorrect kerneldoc.

Quoted 109 lines

+ */

drivers/rtc/Makefile +108 -0
+static ssize_t rtc_div256_adjust_store(struct device *dev,
+				       struct device_attribute *attr,
+				       const char *buf, size_t count)
+{
+	int retval;
+	u32 value = 0;
+
+	if (sscanf(buf, " %i ", &value) != 1) {
+		dev_err(dev, "Failed to store RTC div256 adjust attribute\n");
+		return -EINVAL;
+	}
+	retval = rtc_set_div256_adjust(dev, &value);
+
+	return retval ? retval : count;
+}
+
+static ssize_t rtc_div256_adjust_show(struct device *dev,
+				      struct device_attribute *attr, char *buf)
+{
+	int retval = 0;
+	u32 value = 0;
+
+	retval = rtc_get_div256_adjust(dev, &value);
+	if (retval < 0) {
+		dev_err(dev, "Failed to read RTC div256 adjust attribute\n");
+		sprintf(buf, "0\n");
+		return retval;
+	}
+
+	return sprintf(buf, "0x%x\n", value);
+}
+static DEVICE_ATTR_RW(rtc_div256_adjust);
+
+static struct attribute *aml_rtc_attrs[] = {
+	&dev_attr_rtc_calibration.attr,
+	&dev_attr_rtc_div256_adjust.attr,
+	NULL,
+};
+
+static const struct attribute_group aml_rtc_sysfs_files = {
+	.attrs	= aml_rtc_attrs,
+};
+
+static void aml_rtc_init(struct device *dev, struct aml_rtc_data *rtc)
+{
+	u32 reg_val;
+	u32 rtc_enable;
+
+	regmap_read(rtc->map, RTC_CTRL, &reg_val);
+	rtc_enable = FIELD_GET(RTC_ENABLE, reg_val);
+	if (!rtc_enable) {
+		if (clk_get_rate(rtc->sclk) == OSC_24M) {
+			/* select 24M oscillator */
+			regmap_update_bits(rtc->map, RTC_CTRL, RTC_OSC_SEL, RTC_OSC_SEL);
+
+			/*
+			 * Set RTC oscillator to freq_out to freq_in/((N0*M0+N1*M1)/(M0+M1))
+			 * Enable clock_in gate of oscillator 24MHz
+			 * Set N0 to 733, N1 to 732
+			 */
+			reg_val = FIELD_PREP(RTC_OSCIN_IN_EN, 1)
+				  | FIELD_PREP(RTC_OSCIN_OUT_CFG, 1)
+				  | FIELD_PREP(RTC_OSCIN_OUT_N0M0, RTC_OSCIN_OUT_32K_N0)
+				  | FIELD_PREP(RTC_OSCIN_OUT_N1M1, RTC_OSCIN_OUT_32K_N1);
+			regmap_write_bits(rtc->map, RTC_OSCIN_CTRL0, RTC_OSCIN_IN_EN
+					  | RTC_OSCIN_OUT_CFG | RTC_OSCIN_OUT_N0M0
+					  | RTC_OSCIN_OUT_N1M1, reg_val);
+
+			/* Set M0 to 2, M1 to 3, so freq_out = 32768 Hz*/
+			reg_val = FIELD_PREP(RTC_OSCIN_OUT_N0M0, RTC_OSCIN_OUT_32K_M0)
+				  | FIELD_PREP(RTC_OSCIN_OUT_N1M1, RTC_OSCIN_OUT_32K_M1);
+			regmap_write_bits(rtc->map, RTC_OSCIN_CTRL1, RTC_OSCIN_OUT_N0M0
+					  | RTC_OSCIN_OUT_N1M1, reg_val);
+		} else {
+			/* select 32K oscillator */
+			regmap_write_bits(rtc->map, RTC_CTRL, RTC_OSC_SEL, 0);
+		}
+		/* Enable RTC */
+		regmap_write_bits(rtc->map, RTC_CTRL, RTC_ENABLE, RTC_ENABLE);
+		usleep_range(100, 200);
+	}
+	regmap_write_bits(rtc->map, RTC_INT_MASK,
+			  RTC_ALRM0_IRQ_MSK, RTC_ALRM0_IRQ_MSK);
+	regmap_write_bits(rtc->map, RTC_CTRL, RTC_ALRM0_EN, 0);
+}
+
+static int aml_rtc_probe(struct platform_device *pdev)
+{
+	struct aml_rtc_data *rtc;
+	void __iomem *base;
+	struct clk *core_clk;
+	int ret = 0;
+
+	rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL);
+	if (!rtc)
+		return -ENOMEM;
+
+	rtc->config = of_device_get_match_data(&pdev->dev);
+	if (!rtc->config)
+		return -ENODEV;
+
+	base = devm_platform_ioremap_resource(pdev, 0);
+	if (IS_ERR(base)) {
+		dev_err(&pdev->dev, "resource ioremap failed\n");
+		return PTR_ERR(base);
+	}
+
+	rtc->map = devm_regmap_init_mmio(&pdev->dev, base, &aml_rtc_regmap_config);

drivers/rtc/Makefile

Quoted 10 lines
drivers/rtc/Makefile +10 -0
+	if (IS_ERR(rtc->map)) {
+		dev_err(&pdev->dev, "regmap init failed\n");
+		return PTR_ERR(rtc->map);
+	}
+
+	rtc->irq = platform_get_irq(pdev, 0);
+	if (rtc->irq < 0)
+		return rtc->irq;
+
+	rtc->sclk = devm_clk_get(&pdev->dev, "rtc_osc");

Clock name should be: "osc"

drivers/rtc/Makefile

Quoted 8 lines
drivers/rtc/Makefile +8 -0
+	if (IS_ERR(rtc->sclk))
+		return PTR_ERR(rtc->sclk);
+	if (clk_get_rate(rtc->sclk) != OSC_32K && clk_get_rate(rtc->sclk) != OSC_24M) {
+		dev_err(&pdev->dev, "Invalid clock configuration\n");
+		return -EINVAL;
+	}
+
+	core_clk = devm_clk_get(&pdev->dev, "rtc_sys_clk");

Clock name: "sys"

drivers/rtc/Makefile

Quoted 2 lines
drivers/rtc/Makefile +2 -0
+	if (IS_ERR(core_clk)) {
+		dev_err(&pdev->dev, "failed to get rtc sys clk\n");

Syntax is return dev_err_probe.

Quoted 8 lines
drivers/rtc/Makefile +8 -0
+		return PTR_ERR(core_clk);
+	}
+	clk_prepare_enable(core_clk);
+
+	aml_rtc_init(&pdev->dev, rtc);
+
+	device_init_wakeup(&pdev->dev, 1);
+	platform_set_drvdata(pdev, rtc);

drivers/rtc/Makefile

Quoted 10 lines
drivers/rtc/Makefile +10 -0
+
+	rtc->rtc_dev = devm_rtc_allocate_device(&pdev->dev);
+	if (IS_ERR(rtc->rtc_dev))
+		return PTR_ERR(rtc->rtc_dev);
+
+	ret = devm_request_irq(&pdev->dev, rtc->irq, aml_rtc_handler,
+			       IRQF_ONESHOT, "aml-rtc alarm", rtc);
+	if (ret) {
+		dev_err(&pdev->dev, "IRQ%d request failed, ret = %d\n",
+			rtc->irq, ret);

Your code is buggy. You leave with prepared clock.

Use devm_clk_get_enabled where applicable.

Quoted 26 lines
drivers/rtc/Makefile +26 -0
+		return ret;
+	}
+
+	rtc->rtc_dev->ops = &aml_rtc_ops;
+	rtc->rtc_dev->range_min = 0;
+	rtc->rtc_dev->range_max = U32_MAX;
+
+	ret = rtc_add_group(rtc->rtc_dev, &aml_rtc_sysfs_files);
+	if (ret) {
+		dev_err(&pdev->dev, "Failed to create sysfs group: %d\n", ret);
+		return ret;
+	}
+
+	return devm_rtc_register_device(rtc->rtc_dev);
+}
+
+static int aml_rtc_suspend(struct device *dev)
+{
+	struct aml_rtc_data *rtc = dev_get_drvdata(dev);
+
+	if (device_may_wakeup(dev))
+		enable_irq_wake(rtc->irq);
+
+	return 0;
+}
+

drivers/rtc/Makefile

Quoted 10 lines
drivers/rtc/Makefile +10 -0
+static int aml_rtc_resume(struct device *dev)
+{
+	struct aml_rtc_data *rtc = dev_get_drvdata(dev);
+
+	if (device_may_wakeup(dev))
+		disable_irq_wake(rtc->irq);
+
+	return 0;
+}
+

Where is the remove to cleanup?

Quoted 17 lines
drivers/rtc/Makefile +17 -0
+static SIMPLE_DEV_PM_OPS(aml_rtc_pm_ops,
+			 aml_rtc_suspend, aml_rtc_resume);
+
+static const struct aml_rtc_config a5_rtc_config = {
+};
+
+static const struct aml_rtc_config a4_rtc_config = {
+	.gray_stored = true,
+};
+
+static const struct of_device_id aml_rtc_device_id[] = {
+	{
+		.compatible = "amlogic,a4-rtc",
+		.data = &a4_rtc_config,
+	},
+	{
+		.compatible = "amlogic,a5-rtc",

drivers/rtc/Makefile

Quoted 10 lines
drivers/rtc/Makefile +10 -0
+		.data = &a5_rtc_config,
+	},
+};
+MODULE_DEVICE_TABLE(of, aml_rtc_device_id);
+
+static struct platform_driver aml_rtc_driver = {
+	.probe = aml_rtc_probe,
+	.driver = {
+		.name = "aml-rtc",
+		.of_match_table = of_match_ptr(aml_rtc_device_id),

Drop of_match_ptr. You have a warning here.

drivers/rtc/Makefile

Quoted 2 lines
drivers/rtc/Makefile +2 -0
+		.pm = &aml_rtc_pm_ops,
+	},

Best regards,
Krzysztof

#6 lore raw

Re: [PATCH 2/3] rtc: support for the Amlogic on-chip RTC

Hi Krzysztof,
Thanks for your reply.

Quoted 24 lines · Krzysztof Kozlowski

[ EXTERNAL EMAIL ]

Quoted 21 lines · On 23/08/2024 11:19, Xianwei Zhao via B4 Relay wrote:

From: Yiting Deng <[email protected]>

Support for the on-chip RTC found in some of Amlogic's SoCs such as the A113L2 and A113X2.

---
  drivers/rtc/Kconfig       |  12 +
  drivers/rtc/Makefile      |   1 +
  drivers/rtc/rtc-amlogic.c | 589 ++++++++++++++++++++++++++++++++++++++++++++++
  3 files changed, 602 insertions(+)
drivers/rtc/Kconfig +0 -0
index 2a95b05982ad..0dd042701c3b 100644
@@ -2043,4 +2043,16 @@ config RTC_DRV_SSD202D
         This driver can also be built as a module, if so, the module
         will be called "rtc-ssd20xd".
 
Quoted 7 lines

drivers/rtc/Kconfig config RTC_DRV_SSD202D · line 2048

Quoted 3 lines
drivers/rtc/Kconfig +3 -0
+config RTC_DRV_AMLOGIC
+     tristate "Amlogic RTC"
+     depends on ARCH_MESON || COMPILE_TEST

So the third driver? What is wrong with existing ones? And why this one is named so differently?

This RTC hardware includes a timing function and an alarm function.
But the existing has only timing function, alarm function is using the system clock to implement a virtual alarm. The "meson" string is meaningless, it just keeps going, and now the new hardware uses the normal naming.

Quoted 24 lines
Quoted 22 lines
drivers/rtc/Kconfig +9 -0
+     select REGMAP_MMIO
+     default y
+     help
+       If you say yes here you get support for the RTC block on the
+       Amlogic A113L2(A4) and A113X2(A5) SoCs.
+
+       This driver can also be built as a module. If so, the module
+       will be called "rtc-amlogic".
+
  endif # RTC_CLASS
drivers/rtc/Makefile +1 -0
index 3004e372f25f..d4a56ddb4246 100644
@@ -26,6 +26,7 @@ obj-$(CONFIG_RTC_DRV_ABB5ZES3)      += rtc-ab-b5ze-s3.o
  obj-$(CONFIG_RTC_DRV_ABEOZ9) += rtc-ab-eoz9.o
  obj-$(CONFIG_RTC_DRV_ABX80X) += rtc-abx80x.o
  obj-$(CONFIG_RTC_DRV_AC100)  += rtc-ac100.o
+obj-$(CONFIG_RTC_DRV_AMLOGIC)        += rtc-amlogic.o
  obj-$(CONFIG_RTC_DRV_ARMADA38X)      += rtc-armada38x.o
  obj-$(CONFIG_RTC_DRV_AS3722) += rtc-as3722.o
  obj-$(CONFIG_RTC_DRV_ASM9260)        += rtc-asm9260.o
Quoted 12 lines

drivers/rtc/Makefile

Quoted 9 lines
drivers/rtc/Makefile +9 -0
+
+static int aml_rtc_adjust_sec(struct device *dev, u32 match_counter,
+                           int ops, int enable)
+{
+     struct aml_rtc_data *rtc = dev_get_drvdata(dev->parent);
+     u32 reg_val;
+
+     if (!FIELD_FIT(RTC_MATCH_COUNTER, match_counter)) {
+             pr_err("%s: invalid match_counter\n", __func__);

No, do not use pr_, but driver ones.

Will do.

Quoted 47 lines
Quoted 47 lines
drivers/rtc/Makefile +46 -0
+             return -EINVAL;
+     }
+
+     reg_val = FIELD_PREP(RTC_SEC_ADJUST_CTRL, ops)
+               | FIELD_PREP(RTC_MATCH_COUNTER, match_counter)
+               | FIELD_PREP(RTC_ADJ_VALID, enable);
+     /* Set sec_adjust_ctrl, match_counter and Valid adjust */
+     regmap_write(rtc->map, RTC_SEC_ADJUST_REG, reg_val);
+
+     return 0;
+}
+
+static int aml_rtc_set_calibration(struct device *dev, u32 calibration)
+{
+     int cal_ops, enable, match_counter;
+     int ret;
+
+     match_counter = FIELD_GET(RTC_MATCH_COUNTER, calibration);
+     cal_ops = FIELD_GET(RTC_SEC_ADJUST_CTRL, calibration);
+     enable = FIELD_GET(RTC_ADJ_VALID, calibration);
+
+     ret = aml_rtc_adjust_sec(dev, match_counter, cal_ops, enable);
+     dev_dbg(dev, "%s: Success to store RTC calibration attribute\n",
+             __func__);
+
+     return ret;
+}
+
+static int aml_rtc_get_calibration(struct device *dev, u32 *calibration)
+{
+     struct aml_rtc_data *rtc = dev_get_drvdata(dev->parent);
+     u32 reg_val;
+
+     regmap_read(rtc->map, RTC_SEC_ADJUST_REG, &reg_val);
+     *calibration = FIELD_GET(RTC_SEC_ADJUST_CTRL | RTC_MATCH_COUNTER, reg_val);
+     /* BIT is only UL defined,and GENMASK has no type, its' donot used together */
+     *calibration |= FIELD_PREP(RTC_ADJ_VALID, FIELD_GET(RTC_ADJ_VALID, reg_val));
+
+     return 0;
+}
+
+/**
+ * The calibration value transferred from buf takes bit[18:0] to represent
+ * match_counter, while takes bit[20:19] to represent sec_adjust_ctrl, bit[23]
+ * to represent adj_valid. enable/disable sec_adjust_ctrl and match_counter.
+ * @buf: Separate buf to match_counter, sec_adjust_ctrl and adj_valid
Quoted 9 lines
Quoted 6 lines
+ *    match_counter: bit[18:0], value is 0 ~ 0x7fff
+ *    sec_adjust_ctrl: bit[20:19], value is 0 ~ 2. 3 to insert a second once every
+ *    match_counter+1 seconds, 2 to swallow a second once every match_counter+1 seconds
+ *    0 or 1 to no adjustment
+ *    adj_valid: bit[23], value is 0 or 1, 0 to disable sec_adjust_ctrl and
+ *    match_counter, and 1 to enable them.

Messed kerneldoc. You have warning shere. Fix it.

I will delete it.

Quoted 4 lines
Quoted 4 lines

+ */

drivers/rtc/Makefile +3 -0
+static ssize_t rtc_calibration_store(struct device *dev,
+                                  struct device_attribute *attr,
+                                  const char *buf, size_t count)
Quoted 9 lines

drivers/rtc/Makefile

Quoted 6 lines
drivers/rtc/Makefile +6 -0
+{
+     int retval;
+     int calibration = 0;
+
+     if (sscanf(buf, " %i ", &calibration) != 1) {
+             dev_err(dev, "Failed to store RTC calibration attribute\n");

Where is the ABI documented?

I will move it to the standard RTC API to handle calibration. So here will delete it.

Quoted 17 lines
Quoted 17 lines
drivers/rtc/Makefile +17 -0
+             return -EINVAL;
+     }
+     retval = aml_rtc_set_calibration(dev, calibration);
+
+     return retval ? retval : count;
+}
+
+static ssize_t rtc_calibration_show(struct device *dev,
+                                 struct device_attribute *attr, char *buf)
+{
+     int  retval = 0;
+     u32  calibration = 0;
+
+     retval = aml_rtc_get_calibration(dev, &calibration);
+     if (retval < 0) {
+             dev_err(dev, "Failed to read RTC calibration attribute\n");
+             sprintf(buf, "0\n");
Quoted 9 lines

drivers/rtc/Makefile

Quoted 6 lines
drivers/rtc/Makefile +6 -0
+             return retval;
+     }
+
+     return sprintf(buf, "0x%x\n", calibration);
+}
+static DEVICE_ATTR_RW(rtc_calibration);

Document the ABI.

I will move it to the standard RTC API to handle calibration. So here will delete it.

Quoted 32 lines
Quoted 32 lines
drivers/rtc/Makefile +32 -0
+
+static int rtc_set_div256_adjust(struct device *dev, u32 *value)
+{
+     struct aml_rtc_data *rtc = dev_get_drvdata(dev->parent);
+     u32 div256_adj;
+
+     div256_adj = FIELD_PREP(RTC_DIV256_ADJ_DSR | RTC_DIV256_ADJ_VAL, *value);
+     /*
+      * AO_RTC_SEC_ADJUST_REG bit 24 insert/remove(1/0) a div256 cycle,
+      * bit 25 valid/invalid(1/0) div256_adj_val
+      */
+     regmap_write_bits(rtc->map, RTC_SEC_ADJUST_REG,
+                       RTC_DIV256_ADJ_DSR | RTC_DIV256_ADJ_VAL, div256_adj);
+     /* rtc need about 30ms to adjust its time after written */
+     mdelay(30);
+
+     return 0;
+}
+
+static int rtc_get_div256_adjust(struct device *dev, u32 *value)
+{
+     struct aml_rtc_data *rtc = dev_get_drvdata(dev->parent);
+     u32 reg_val;
+
+     regmap_read(rtc->map, RTC_SEC_ADJUST_REG, &reg_val);
+     *value = FIELD_GET(RTC_DIV256_ADJ_DSR | RTC_DIV256_ADJ_VAL, reg_val);
+
+     return 0;
+}
+
+/**
+ * div256 adjust function is controlled using bit[24] and bit[25].
Quoted 9 lines
Quoted 6 lines

+ * transferred buf takes bit[0] to represent div256 adj val, bit[1]
+ * to represent div256 adj enable/disable. div256 cycle means that adjust
+ * 1/32768/256 once by written once, it's val is equal to 1/128s
+ * @buf: 3: enable div256 adjust and insert a div256 cycle
+ * 2: enable div256 adjust and remove a div256 cycle
+ * 1 or 0: disable div256 adjust

Again incorrect kerneldoc.

This is not used functions, I will delete it.

Quoted 113 lines
Quoted 113 lines

+ */

drivers/rtc/Makefile +112 -0
+static ssize_t rtc_div256_adjust_store(struct device *dev,
+                                    struct device_attribute *attr,
+                                    const char *buf, size_t count)
+{
+     int retval;
+     u32 value = 0;
+
+     if (sscanf(buf, " %i ", &value) != 1) {
+             dev_err(dev, "Failed to store RTC div256 adjust attribute\n");
+             return -EINVAL;
+     }
+     retval = rtc_set_div256_adjust(dev, &value);
+
+     return retval ? retval : count;
+}
+
+static ssize_t rtc_div256_adjust_show(struct device *dev,
+                                   struct device_attribute *attr, char *buf)
+{
+     int retval = 0;
+     u32 value = 0;
+
+     retval = rtc_get_div256_adjust(dev, &value);
+     if (retval < 0) {
+             dev_err(dev, "Failed to read RTC div256 adjust attribute\n");
+             sprintf(buf, "0\n");
+             return retval;
+     }
+
+     return sprintf(buf, "0x%x\n", value);
+}
+static DEVICE_ATTR_RW(rtc_div256_adjust);
+
+static struct attribute *aml_rtc_attrs[] = {
+     &dev_attr_rtc_calibration.attr,
+     &dev_attr_rtc_div256_adjust.attr,
+     NULL,
+};
+
+static const struct attribute_group aml_rtc_sysfs_files = {
+     .attrs  = aml_rtc_attrs,
+};
+
+static void aml_rtc_init(struct device *dev, struct aml_rtc_data *rtc)
+{
+     u32 reg_val;
+     u32 rtc_enable;
+
+     regmap_read(rtc->map, RTC_CTRL, &reg_val);
+     rtc_enable = FIELD_GET(RTC_ENABLE, reg_val);
+     if (!rtc_enable) {
+             if (clk_get_rate(rtc->sclk) == OSC_24M) {
+                     /* select 24M oscillator */
+                     regmap_update_bits(rtc->map, RTC_CTRL, RTC_OSC_SEL, RTC_OSC_SEL);
+
+                     /*
+                      * Set RTC oscillator to freq_out to freq_in/((N0*M0+N1*M1)/(M0+M1))
+                      * Enable clock_in gate of oscillator 24MHz
+                      * Set N0 to 733, N1 to 732
+                      */
+                     reg_val = FIELD_PREP(RTC_OSCIN_IN_EN, 1)
+                               | FIELD_PREP(RTC_OSCIN_OUT_CFG, 1)
+                               | FIELD_PREP(RTC_OSCIN_OUT_N0M0, RTC_OSCIN_OUT_32K_N0)
+                               | FIELD_PREP(RTC_OSCIN_OUT_N1M1, RTC_OSCIN_OUT_32K_N1);
+                     regmap_write_bits(rtc->map, RTC_OSCIN_CTRL0, RTC_OSCIN_IN_EN
+                                       | RTC_OSCIN_OUT_CFG | RTC_OSCIN_OUT_N0M0
+                                       | RTC_OSCIN_OUT_N1M1, reg_val);
+
+                     /* Set M0 to 2, M1 to 3, so freq_out = 32768 Hz*/
+                     reg_val = FIELD_PREP(RTC_OSCIN_OUT_N0M0, RTC_OSCIN_OUT_32K_M0)
+                               | FIELD_PREP(RTC_OSCIN_OUT_N1M1, RTC_OSCIN_OUT_32K_M1);
+                     regmap_write_bits(rtc->map, RTC_OSCIN_CTRL1, RTC_OSCIN_OUT_N0M0
+                                       | RTC_OSCIN_OUT_N1M1, reg_val);
+             } else {
+                     /* select 32K oscillator */
+                     regmap_write_bits(rtc->map, RTC_CTRL, RTC_OSC_SEL, 0);
+             }
+             /* Enable RTC */
+             regmap_write_bits(rtc->map, RTC_CTRL, RTC_ENABLE, RTC_ENABLE);
+             usleep_range(100, 200);
+     }
+     regmap_write_bits(rtc->map, RTC_INT_MASK,
+                       RTC_ALRM0_IRQ_MSK, RTC_ALRM0_IRQ_MSK);
+     regmap_write_bits(rtc->map, RTC_CTRL, RTC_ALRM0_EN, 0);
+}
+
+static int aml_rtc_probe(struct platform_device *pdev)
+{
+     struct aml_rtc_data *rtc;
+     void __iomem *base;
+     struct clk *core_clk;
+     int ret = 0;
+
+     rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL);
+     if (!rtc)
+             return -ENOMEM;
+
+     rtc->config = of_device_get_match_data(&pdev->dev);
+     if (!rtc->config)
+             return -ENODEV;
+
+     base = devm_platform_ioremap_resource(pdev, 0);
+     if (IS_ERR(base)) {
+             dev_err(&pdev->dev, "resource ioremap failed\n");
+             return PTR_ERR(base);
+     }
+
+     rtc->map = devm_regmap_init_mmio(&pdev->dev, base, &aml_rtc_regmap_config);
+     if (IS_ERR(rtc->map)) {
+             dev_err(&pdev->dev, "regmap init failed\n");
+             return PTR_ERR(rtc->map);
+     }
Quoted 9 lines

drivers/rtc/Makefile

Quoted 6 lines
drivers/rtc/Makefile +6 -0
+
+     rtc->irq = platform_get_irq(pdev, 0);
+     if (rtc->irq < 0)
+             return rtc->irq;
+
+     rtc->sclk = devm_clk_get(&pdev->dev, "rtc_osc");

Clock name should be: "osc"

Will do.

Quoted 10 lines

drivers/rtc/Makefile

Quoted 8 lines
drivers/rtc/Makefile +8 -0
+     if (IS_ERR(rtc->sclk))
+             return PTR_ERR(rtc->sclk);
+     if (clk_get_rate(rtc->sclk) != OSC_32K && clk_get_rate(rtc->sclk) != OSC_24M) {
+             dev_err(&pdev->dev, "Invalid clock configuration\n");
+             return -EINVAL;
+     }
+
+     core_clk = devm_clk_get(&pdev->dev, "rtc_sys_clk");

Clock name: "sys"

Will do.

Quoted 6 lines

drivers/rtc/Makefile

Quoted 3 lines
drivers/rtc/Makefile +2 -0
+     if (IS_ERR(core_clk)) {
+             dev_err(&pdev->dev, "failed to get rtc sys clk\n");

Syntax is return dev_err_probe.

Will do.

Quoted 21 lines
Quoted 8 lines
drivers/rtc/Makefile +8 -0
+             return PTR_ERR(core_clk);
+     }
+     clk_prepare_enable(core_clk);
+
+     aml_rtc_init(&pdev->dev, rtc);
+
+     device_init_wakeup(&pdev->dev, 1);
+     platform_set_drvdata(pdev, rtc);

drivers/rtc/Makefile

Quoted 10 lines
drivers/rtc/Makefile +10 -0
+
+     rtc->rtc_dev = devm_rtc_allocate_device(&pdev->dev);
+     if (IS_ERR(rtc->rtc_dev))
+             return PTR_ERR(rtc->rtc_dev);
+
+     ret = devm_request_irq(&pdev->dev, rtc->irq, aml_rtc_handler,
+                            IRQF_ONESHOT, "aml-rtc alarm", rtc);
+     if (ret) {
+             dev_err(&pdev->dev, "IRQ%d request failed, ret = %d\n",
+                     rtc->irq, ret);

Your code is buggy. You leave with prepared clock.

Quoted 2 lines

Use devm_clk_get_enabled where applicable.

Will fix it.

Quoted 30 lines
Quoted 30 lines
drivers/rtc/Makefile +30 -0
+             return ret;
+     }
+
+     rtc->rtc_dev->ops = &aml_rtc_ops;
+     rtc->rtc_dev->range_min = 0;
+     rtc->rtc_dev->range_max = U32_MAX;
+
+     ret = rtc_add_group(rtc->rtc_dev, &aml_rtc_sysfs_files);
+     if (ret) {
+             dev_err(&pdev->dev, "Failed to create sysfs group: %d\n", ret);
+             return ret;
+     }
+
+     return devm_rtc_register_device(rtc->rtc_dev);
+}
+
+static int aml_rtc_suspend(struct device *dev)
+{
+     struct aml_rtc_data *rtc = dev_get_drvdata(dev);
+
+     if (device_may_wakeup(dev))
+             enable_irq_wake(rtc->irq);
+
+     return 0;
+}
+
+static int aml_rtc_resume(struct device *dev)
+{
+     struct aml_rtc_data *rtc = dev_get_drvdata(dev);
+
Quoted 9 lines

drivers/rtc/Makefile

Quoted 6 lines
drivers/rtc/Makefile +6 -0
+     if (device_may_wakeup(dev))
+             disable_irq_wake(rtc->irq);
+
+     return 0;
+}
+

Where is the remove to cleanup?

Will add remove function.

Quoted 21 lines
Quoted 21 lines
drivers/rtc/Makefile +21 -0
+static SIMPLE_DEV_PM_OPS(aml_rtc_pm_ops,
+                      aml_rtc_suspend, aml_rtc_resume);
+
+static const struct aml_rtc_config a5_rtc_config = {
+};
+
+static const struct aml_rtc_config a4_rtc_config = {
+     .gray_stored = true,
+};
+
+static const struct of_device_id aml_rtc_device_id[] = {
+     {
+             .compatible = "amlogic,a4-rtc",
+             .data = &a4_rtc_config,
+     },
+     {
+             .compatible = "amlogic,a5-rtc",
+             .data = &a5_rtc_config,
+     },
+};
+MODULE_DEVICE_TABLE(of, aml_rtc_device_id);
Quoted 9 lines

drivers/rtc/Makefile

Quoted 6 lines
drivers/rtc/Makefile +6 -0
+
+static struct platform_driver aml_rtc_driver = {
+     .probe = aml_rtc_probe,
+     .driver = {
+             .name = "aml-rtc",
+             .of_match_table = of_match_ptr(aml_rtc_device_id),

Drop of_match_ptr. You have a warning here.

Will do.

Quoted 5 lines

drivers/rtc/Makefile

Quoted 2 lines
drivers/rtc/Makefile +2 -0
+             .pm = &aml_rtc_pm_ops,
+     },

Best regards,
Krzysztof

#7 lore raw

Re: [PATCH 2/3] rtc: support for the Amlogic on-chip RTC

In reply to Xianwei Zhao
Quoted 11 lines · On 23/08/2024 17:19:45+0800, Xianwei Zhao via B4 Relay wrote:

From: Yiting Deng <[email protected]>

Support for the on-chip RTC found in some of Amlogic's SoCs such as the A113L2 and A113X2.

---
 drivers/rtc/Kconfig       |  12 +
 drivers/rtc/Makefile      |   1 +
 drivers/rtc/rtc-amlogic.c | 589 ++++++++++++++++++++++++++++++++++++++++++++++

As pointed out, this is the third amlogic driver so the name of the file must be more specific.

Quoted 1 line

+static void aml_set_time(struct aml_rtc_data *rtc, u32 time_sec)

Is indirection necessary, this function is used only once

drivers/rtc/rtc-amlogic.c line 103

Quoted 7 lines
drivers/rtc/rtc-amlogic.c new file +7 -0
+{
+	if (rtc->config->gray_stored)
+		time_sec = binary_to_gray(time_sec);
+	regmap_write(rtc->map, RTC_COUNTER_REG, time_sec);
+}
+
+static u32 aml_read_time(struct aml_rtc_data *rtc)

Ditto

drivers/rtc/rtc-amlogic.c line 113

Quoted 10 lines
drivers/rtc/rtc-amlogic.c new file +10 -0
+{
+	u32 time_sec;
+
+	regmap_read(rtc->map, RTC_REAL_TIME, &time_sec);
+	if (rtc->config->gray_stored)
+		time_sec = gray_to_binary(time_sec);
+	return time_sec;
+}
+
+static u32 aml_read_alarm(struct aml_rtc_data *rtc)

Ditto

drivers/rtc/rtc-amlogic.c line 123

Quoted 10 lines
drivers/rtc/rtc-amlogic.c new file +10 -0
+{
+	u32 alarm_sec;
+
+	regmap_read(rtc->map, RTC_ALARM0_REG, &alarm_sec);
+	if (rtc->config->gray_stored)
+		alarm_sec = gray_to_binary(alarm_sec);
+	return alarm_sec;
+}
+
+static void aml_set_alarm(struct aml_rtc_data *rtc, u32 alarm_sec)

Ditto

drivers/rtc/rtc-amlogic.c line 159

Quoted 12 lines
drivers/rtc/rtc-amlogic.c new file +12 -0
+{
+	if (rtc->config->gray_stored)
+		alarm_sec = binary_to_gray(alarm_sec);
+	regmap_write(rtc->map, RTC_ALARM0_REG, alarm_sec);
+}
+
+static int aml_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
+{
+	struct aml_rtc_data *rtc = dev_get_drvdata(dev);
+	time64_t alarm_sec;
+
+	if (alarm->enabled) {

Why aren't you setting the alarm when it is not enabled?

drivers/rtc/rtc-amlogic.c line 166

Quoted 7 lines
drivers/rtc/rtc-amlogic.c new file +7 -0
+		regmap_update_bits(rtc->map, RTC_CTRL,
+				   RTC_ALRM0_EN, RTC_ALRM0_EN);
+		regmap_update_bits(rtc->map, RTC_INT_MASK,
+				   RTC_ALRM0_IRQ_MSK, 0);
+
+		alarm_sec = rtc_tm_to_time64(&alarm->time);
+		if (alarm_sec > U32_MAX) {

This is never going to happen, the test and error message are not necessary.

Quoted 31 lines
drivers/rtc/rtc-amlogic.c new file +31 -0
+			dev_err(dev, "alarm value invalid!\n");
+			return -EINVAL;
+		}
+		aml_set_alarm(rtc, alarm_sec);
+	}
+	dev_dbg(dev, "%s: alarm->enabled=%d alarm_set=%llds\n", __func__,
+		alarm->enabled, alarm_sec);
+
+	return 0;
+}
+
+static int aml_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
+{
+	struct aml_rtc_data *rtc = dev_get_drvdata(dev);
+	u32 alarm_sec;
+	u32 reg_val;
+	int alarm_enable, alarm_mask;
+
+	alarm_sec = aml_read_alarm(rtc);
+	rtc_time64_to_tm(alarm_sec, &alarm->time);
+
+	regmap_read(rtc->map, RTC_CTRL, &reg_val);
+	alarm_enable = FIELD_GET(RTC_ALRM0_EN, reg_val);
+
+	regmap_read(rtc->map, RTC_INT_MASK, &reg_val);
+	alarm_mask = FIELD_GET(RTC_ALRM0_IRQ_MSK, reg_val);
+
+	alarm->enabled = (alarm_enable && !alarm_mask) ? 1 : 0;
+	dev_dbg(dev, "%s: alarm->enabled=%d alarm=%us\n", __func__,
+		alarm->enabled, alarm_sec);
+

drivers/rtc/rtc-amlogic.c line 234

Quoted 10 lines
drivers/rtc/rtc-amlogic.c new file +10 -0
+	return 0;
+}
+
+static irqreturn_t aml_rtc_handler(int irq, void *data)
+{
+	struct aml_rtc_data *rtc = (struct aml_rtc_data *)data;
+
+	regmap_write(rtc->map, RTC_ALARM0_REG, 0);
+	regmap_update_bits(rtc->map, RTC_INT_CLR,
+			   RTC_ALRM0_IRQ_STATUS, RTC_ALRM0_IRQ_STATUS);

Are you sure regmap_update_bits is necessary here?

Quoted 173 lines
drivers/rtc/rtc-amlogic.c new file +171 -0
+
+	rtc_update_irq(rtc->rtc_dev, 1, RTC_AF | RTC_IRQF);
+
+	return IRQ_HANDLED;
+}
+
 
 
+static int aml_rtc_adjust_sec(struct device *dev, u32 match_counter,
+			      int ops, int enable)
+{
+	struct aml_rtc_data *rtc = dev_get_drvdata(dev->parent);
+	u32 reg_val;
+
+	if (!FIELD_FIT(RTC_MATCH_COUNTER, match_counter)) {
+		pr_err("%s: invalid match_counter\n", __func__);
+		return -EINVAL;
+	}
+
+	reg_val = FIELD_PREP(RTC_SEC_ADJUST_CTRL, ops)
+		  | FIELD_PREP(RTC_MATCH_COUNTER, match_counter)
+		  | FIELD_PREP(RTC_ADJ_VALID, enable);
+	/* Set sec_adjust_ctrl, match_counter and Valid adjust */
+	regmap_write(rtc->map, RTC_SEC_ADJUST_REG, reg_val);
+
+	return 0;
+}
+
+static int aml_rtc_set_calibration(struct device *dev, u32 calibration)
+{
+	int cal_ops, enable, match_counter;
+	int ret;
+
+	match_counter = FIELD_GET(RTC_MATCH_COUNTER, calibration);
+	cal_ops = FIELD_GET(RTC_SEC_ADJUST_CTRL, calibration);
+	enable = FIELD_GET(RTC_ADJ_VALID, calibration);
+
+	ret = aml_rtc_adjust_sec(dev, match_counter, cal_ops, enable);
+	dev_dbg(dev, "%s: Success to store RTC calibration attribute\n",
+		__func__);
+
+	return ret;
+}
+
+static int aml_rtc_get_calibration(struct device *dev, u32 *calibration)
+{
+	struct aml_rtc_data *rtc = dev_get_drvdata(dev->parent);
+	u32 reg_val;
+
+	regmap_read(rtc->map, RTC_SEC_ADJUST_REG, &reg_val);
+	*calibration = FIELD_GET(RTC_SEC_ADJUST_CTRL | RTC_MATCH_COUNTER, reg_val);
+	/* BIT is only UL defined,and GENMASK has no type, its' donot used together */
+	*calibration |= FIELD_PREP(RTC_ADJ_VALID, FIELD_GET(RTC_ADJ_VALID, reg_val));
+
+	return 0;
+}
+
+/**
+ * The calibration value transferred from buf takes bit[18:0] to represent
+ * match_counter, while takes bit[20:19] to represent sec_adjust_ctrl, bit[23]
+ * to represent adj_valid. enable/disable sec_adjust_ctrl and match_counter.
+ * @buf: Separate buf to match_counter, sec_adjust_ctrl and adj_valid
+ *	 match_counter: bit[18:0], value is 0 ~ 0x7fff
+ *	 sec_adjust_ctrl: bit[20:19], value is 0 ~ 2. 3 to insert a second once every
+ *	 match_counter+1 seconds, 2 to swallow a second once every match_counter+1 seconds
+ *	 0 or 1 to no adjustment
+ *	 adj_valid: bit[23], value is 0 or 1, 0 to disable sec_adjust_ctrl and
+ *	 match_counter, and 1 to enable them.
+ */
+static ssize_t rtc_calibration_store(struct device *dev,
+				     struct device_attribute *attr,
+				     const char *buf, size_t count)
+{
+	int retval;
+	int calibration = 0;
+
+	if (sscanf(buf, " %i ", &calibration) != 1) {
+		dev_err(dev, "Failed to store RTC calibration attribute\n");
+		return -EINVAL;
+	}
+	retval = aml_rtc_set_calibration(dev, calibration);
+
+	return retval ? retval : count;
+}
+
+static ssize_t rtc_calibration_show(struct device *dev,
+				    struct device_attribute *attr, char *buf)
+{
+	int  retval = 0;
+	u32  calibration = 0;
+
+	retval = aml_rtc_get_calibration(dev, &calibration);
+	if (retval < 0) {
+		dev_err(dev, "Failed to read RTC calibration attribute\n");
+		sprintf(buf, "0\n");
+		return retval;
+	}
+
+	return sprintf(buf, "0x%x\n", calibration);
+}
+static DEVICE_ATTR_RW(rtc_calibration);
+
+static int rtc_set_div256_adjust(struct device *dev, u32 *value)
+{
+	struct aml_rtc_data *rtc = dev_get_drvdata(dev->parent);
+	u32 div256_adj;
+
+	div256_adj = FIELD_PREP(RTC_DIV256_ADJ_DSR | RTC_DIV256_ADJ_VAL, *value);
+	/*
+	 * AO_RTC_SEC_ADJUST_REG bit 24 insert/remove(1/0) a div256 cycle,
+	 * bit 25 valid/invalid(1/0) div256_adj_val
+	 */
+	regmap_write_bits(rtc->map, RTC_SEC_ADJUST_REG,
+			  RTC_DIV256_ADJ_DSR | RTC_DIV256_ADJ_VAL, div256_adj);
+	/* rtc need about 30ms to adjust its time after written */
+	mdelay(30);
+
+	return 0;
+}
+
+static int rtc_get_div256_adjust(struct device *dev, u32 *value)
+{
+	struct aml_rtc_data *rtc = dev_get_drvdata(dev->parent);
+	u32 reg_val;
+
+	regmap_read(rtc->map, RTC_SEC_ADJUST_REG, &reg_val);
+	*value = FIELD_GET(RTC_DIV256_ADJ_DSR | RTC_DIV256_ADJ_VAL, reg_val);
+
+	return 0;
+}
+
+/**
+ * div256 adjust function is controlled using bit[24] and bit[25].
+ * transferred buf takes bit[0] to represent div256 adj val, bit[1]
+ * to represent div256 adj enable/disable. div256 cycle means that adjust
+ * 1/32768/256 once by written once, it's val is equal to 1/128s
+ * @buf: 3: enable div256 adjust and insert a div256 cycle
+ *	 2: enable div256 adjust and remove a div256 cycle
+ *	 1 or 0: disable div256 adjust
+ */
+static ssize_t rtc_div256_adjust_store(struct device *dev,
+				       struct device_attribute *attr,
+				       const char *buf, size_t count)
+{
+	int retval;
+	u32 value = 0;
+
+	if (sscanf(buf, " %i ", &value) != 1) {
+		dev_err(dev, "Failed to store RTC div256 adjust attribute\n");
+		return -EINVAL;
+	}
+	retval = rtc_set_div256_adjust(dev, &value);
+
+	return retval ? retval : count;
+}
+
+static ssize_t rtc_div256_adjust_show(struct device *dev,
+				      struct device_attribute *attr, char *buf)
+{
+	int retval = 0;
+	u32 value = 0;
+
+	retval = rtc_get_div256_adjust(dev, &value);
+	if (retval < 0) {
+		dev_err(dev, "Failed to read RTC div256 adjust attribute\n");
+		sprintf(buf, "0\n");
+		return retval;
+	}
+
+	return sprintf(buf, "0x%x\n", value);
+}
+static DEVICE_ATTR_RW(rtc_div256_adjust);
+

drivers/rtc/rtc-amlogic.c line 415

Quoted 10 lines
drivers/rtc/rtc-amlogic.c new file +10 -0
+static struct attribute *aml_rtc_attrs[] = {
+	&dev_attr_rtc_calibration.attr,
+	&dev_attr_rtc_div256_adjust.attr,
+	NULL,
+};
+
+static const struct attribute_group aml_rtc_sysfs_files = {
+	.attrs	= aml_rtc_attrs,
+};
+

You must use the standard RTC API to handle calibration, see .read_offset and .set_offset

Quoted 26 lines
drivers/rtc/rtc-amlogic.c new file +26 -0
+static void aml_rtc_init(struct device *dev, struct aml_rtc_data *rtc)
+{
+	u32 reg_val;
+	u32 rtc_enable;
+
+	regmap_read(rtc->map, RTC_CTRL, &reg_val);
+	rtc_enable = FIELD_GET(RTC_ENABLE, reg_val);
+	if (!rtc_enable) {
+		if (clk_get_rate(rtc->sclk) == OSC_24M) {
+			/* select 24M oscillator */
+			regmap_update_bits(rtc->map, RTC_CTRL, RTC_OSC_SEL, RTC_OSC_SEL);
+
+			/*
+			 * Set RTC oscillator to freq_out to freq_in/((N0*M0+N1*M1)/(M0+M1))
+			 * Enable clock_in gate of oscillator 24MHz
+			 * Set N0 to 733, N1 to 732
+			 */
+			reg_val = FIELD_PREP(RTC_OSCIN_IN_EN, 1)
+				  | FIELD_PREP(RTC_OSCIN_OUT_CFG, 1)
+				  | FIELD_PREP(RTC_OSCIN_OUT_N0M0, RTC_OSCIN_OUT_32K_N0)
+				  | FIELD_PREP(RTC_OSCIN_OUT_N1M1, RTC_OSCIN_OUT_32K_N1);
+			regmap_write_bits(rtc->map, RTC_OSCIN_CTRL0, RTC_OSCIN_IN_EN
+					  | RTC_OSCIN_OUT_CFG | RTC_OSCIN_OUT_N0M0
+					  | RTC_OSCIN_OUT_N1M1, reg_val);
+
+			/* Set M0 to 2, M1 to 3, so freq_out = 32768 Hz*/

drivers/rtc/rtc-amlogic.c line 451

Quoted 10 lines
drivers/rtc/rtc-amlogic.c new file +10 -0
+			reg_val = FIELD_PREP(RTC_OSCIN_OUT_N0M0, RTC_OSCIN_OUT_32K_M0)
+				  | FIELD_PREP(RTC_OSCIN_OUT_N1M1, RTC_OSCIN_OUT_32K_M1);
+			regmap_write_bits(rtc->map, RTC_OSCIN_CTRL1, RTC_OSCIN_OUT_N0M0
+					  | RTC_OSCIN_OUT_N1M1, reg_val);
+		} else {
+			/* select 32K oscillator */
+			regmap_write_bits(rtc->map, RTC_CTRL, RTC_OSC_SEL, 0);
+		}
+		/* Enable RTC */
+		regmap_write_bits(rtc->map, RTC_CTRL, RTC_ENABLE, RTC_ENABLE);

This must not be done at probe time, else you loose the important information taht the time has never been set. Instead, it should only be enabled on the first .set_time invocation do you could now in .read_time that the time is currently invalid.

Quoted 7 lines
drivers/rtc/rtc-amlogic.c new file +7 -0
+		usleep_range(100, 200);
+	}
+	regmap_write_bits(rtc->map, RTC_INT_MASK,
+			  RTC_ALRM0_IRQ_MSK, RTC_ALRM0_IRQ_MSK);
+	regmap_write_bits(rtc->map, RTC_CTRL, RTC_ALRM0_EN, 0);
+}
+
Signature · 3 lines
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#8 lore raw

Re: [PATCH 2/3] rtc: support for the Amlogic on-chip RTC

Hi Alexandre,
Thanks for your reply.

Quoted 15 lines · Alexandre Belloni

[ EXTERNAL EMAIL ]

Quoted 11 lines · On 23/08/2024 17:19:45+0800, Xianwei Zhao via B4 Relay wrote:

From: Yiting Deng <[email protected]>

Support for the on-chip RTC found in some of Amlogic's SoCs such as the A113L2 and A113X2.

---
  drivers/rtc/Kconfig       |  12 +
  drivers/rtc/Makefile      |   1 +
  drivers/rtc/rtc-amlogic.c | 589 ++++++++++++++++++++++++++++++++++++++++++++++
Quoted 3 lines

As pointed out, this is the third amlogic driver so the name of the file must be more specific.

This RTC hardware includes a timing function and an alarm function.
But the existing has only timing function, alarm function is using the system clock to implement a virtual alarm. And the relevant register access method is also different.

The "meson" string is meaningless, it just keeps going, and now the new hardware uses the normal naming.

Quoted 4 lines
Quoted 1 line

+static void aml_set_time(struct aml_rtc_data *rtc, u32 time_sec)

Is indirection necessary, this function is used only once

I will delete this function.

Quoted 9 lines

drivers/rtc/rtc-amlogic.c line 103

Quoted 7 lines
drivers/rtc/rtc-amlogic.c new file +7 -0
+{
+     if (rtc->config->gray_stored)
+             time_sec = binary_to_gray(time_sec);
+     regmap_write(rtc->map, RTC_COUNTER_REG, time_sec);
+}
+
+static u32 aml_read_time(struct aml_rtc_data *rtc)

Ditto

I will delete this function.

Quoted 12 lines

drivers/rtc/rtc-amlogic.c line 113

Quoted 10 lines
drivers/rtc/rtc-amlogic.c new file +10 -0
+{
+     u32 time_sec;
+
+     regmap_read(rtc->map, RTC_REAL_TIME, &time_sec);
+     if (rtc->config->gray_stored)
+             time_sec = gray_to_binary(time_sec);
+     return time_sec;
+}
+
+static u32 aml_read_alarm(struct aml_rtc_data *rtc)

Ditto

I will delete this function.

Quoted 12 lines

drivers/rtc/rtc-amlogic.c line 123

Quoted 10 lines
drivers/rtc/rtc-amlogic.c new file +10 -0
+{
+     u32 alarm_sec;
+
+     regmap_read(rtc->map, RTC_ALARM0_REG, &alarm_sec);
+     if (rtc->config->gray_stored)
+             alarm_sec = gray_to_binary(alarm_sec);
+     return alarm_sec;
+}
+
+static void aml_set_alarm(struct aml_rtc_data *rtc, u32 alarm_sec)

Ditto

I will delete this function.

Quoted 6 lines
Quoted 6 lines
drivers/rtc/rtc-amlogic.c new file +6 -0
+{
+     if (rtc->config->gray_stored)
+             alarm_sec = binary_to_gray(alarm_sec);
+     regmap_write(rtc->map, RTC_ALARM0_REG, alarm_sec);
+}
+
Quoted 9 lines

drivers/rtc/rtc-amlogic.c line 159

Quoted 6 lines
drivers/rtc/rtc-amlogic.c new file +6 -0
+static int aml_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
+{
+     struct aml_rtc_data *rtc = dev_get_drvdata(dev);
+     time64_t alarm_sec;
+
+     if (alarm->enabled) {

Why aren't you setting the alarm when it is not enabled?

Will delete this judgment.

Quoted 11 lines

drivers/rtc/rtc-amlogic.c line 166

Quoted 7 lines
drivers/rtc/rtc-amlogic.c new file +7 -0
+             regmap_update_bits(rtc->map, RTC_CTRL,
+                                RTC_ALRM0_EN, RTC_ALRM0_EN);
+             regmap_update_bits(rtc->map, RTC_INT_MASK,
+                                RTC_ALRM0_IRQ_MSK, 0);
+
+             alarm_sec = rtc_tm_to_time64(&alarm->time);
+             if (alarm_sec > U32_MAX) {

This is never going to happen, the test and error message are not necessary.

Indeed, will delete this part of the processing.

Quoted 35 lines
Quoted 35 lines
drivers/rtc/rtc-amlogic.c new file +35 -0
+                     dev_err(dev, "alarm value invalid!\n");
+                     return -EINVAL;
+             }
+             aml_set_alarm(rtc, alarm_sec);
+     }
+     dev_dbg(dev, "%s: alarm->enabled=%d alarm_set=%llds\n", __func__,
+             alarm->enabled, alarm_sec);
+
+     return 0;
+}
+
+static int aml_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
+{
+     struct aml_rtc_data *rtc = dev_get_drvdata(dev);
+     u32 alarm_sec;
+     u32 reg_val;
+     int alarm_enable, alarm_mask;
+
+     alarm_sec = aml_read_alarm(rtc);
+     rtc_time64_to_tm(alarm_sec, &alarm->time);
+
+     regmap_read(rtc->map, RTC_CTRL, &reg_val);
+     alarm_enable = FIELD_GET(RTC_ALRM0_EN, reg_val);
+
+     regmap_read(rtc->map, RTC_INT_MASK, &reg_val);
+     alarm_mask = FIELD_GET(RTC_ALRM0_IRQ_MSK, reg_val);
+
+     alarm->enabled = (alarm_enable && !alarm_mask) ? 1 : 0;
+     dev_dbg(dev, "%s: alarm->enabled=%d alarm=%us\n", __func__,
+             alarm->enabled, alarm_sec);
+
+     return 0;
+}
+
+static irqreturn_t aml_rtc_handler(int irq, void *data)
Quoted 9 lines

drivers/rtc/rtc-amlogic.c line 234

Quoted 6 lines
drivers/rtc/rtc-amlogic.c new file +6 -0
+{
+     struct aml_rtc_data *rtc = (struct aml_rtc_data *)data;
+
+     regmap_write(rtc->map, RTC_ALARM0_REG, 0);
+     regmap_update_bits(rtc->map, RTC_INT_CLR,
+                        RTC_ALRM0_IRQ_STATUS, RTC_ALRM0_IRQ_STATUS);

Are you sure regmap_update_bits is necessary here?

There is only write RTC_ALRM0_IRQ_STATUS, to clear it. will fix it.

Quoted 178 lines
Quoted 178 lines
drivers/rtc/rtc-amlogic.c new file +176 -0
+
+     rtc_update_irq(rtc->rtc_dev, 1, RTC_AF | RTC_IRQF);
+
+     return IRQ_HANDLED;
+}
+
 
 
+static int aml_rtc_adjust_sec(struct device *dev, u32 match_counter,
+                           int ops, int enable)
+{
+     struct aml_rtc_data *rtc = dev_get_drvdata(dev->parent);
+     u32 reg_val;
+
+     if (!FIELD_FIT(RTC_MATCH_COUNTER, match_counter)) {
+             pr_err("%s: invalid match_counter\n", __func__);
+             return -EINVAL;
+     }
+
+     reg_val = FIELD_PREP(RTC_SEC_ADJUST_CTRL, ops)
+               | FIELD_PREP(RTC_MATCH_COUNTER, match_counter)
+               | FIELD_PREP(RTC_ADJ_VALID, enable);
+     /* Set sec_adjust_ctrl, match_counter and Valid adjust */
+     regmap_write(rtc->map, RTC_SEC_ADJUST_REG, reg_val);
+
+     return 0;
+}
+
+static int aml_rtc_set_calibration(struct device *dev, u32 calibration)
+{
+     int cal_ops, enable, match_counter;
+     int ret;
+
+     match_counter = FIELD_GET(RTC_MATCH_COUNTER, calibration);
+     cal_ops = FIELD_GET(RTC_SEC_ADJUST_CTRL, calibration);
+     enable = FIELD_GET(RTC_ADJ_VALID, calibration);
+
+     ret = aml_rtc_adjust_sec(dev, match_counter, cal_ops, enable);
+     dev_dbg(dev, "%s: Success to store RTC calibration attribute\n",
+             __func__);
+
+     return ret;
+}
+
+static int aml_rtc_get_calibration(struct device *dev, u32 *calibration)
+{
+     struct aml_rtc_data *rtc = dev_get_drvdata(dev->parent);
+     u32 reg_val;
+
+     regmap_read(rtc->map, RTC_SEC_ADJUST_REG, &reg_val);
+     *calibration = FIELD_GET(RTC_SEC_ADJUST_CTRL | RTC_MATCH_COUNTER, reg_val);
+     /* BIT is only UL defined,and GENMASK has no type, its' donot used together */
+     *calibration |= FIELD_PREP(RTC_ADJ_VALID, FIELD_GET(RTC_ADJ_VALID, reg_val));
+
+     return 0;
+}
+
+/**
+ * The calibration value transferred from buf takes bit[18:0] to represent
+ * match_counter, while takes bit[20:19] to represent sec_adjust_ctrl, bit[23]
+ * to represent adj_valid. enable/disable sec_adjust_ctrl and match_counter.
+ * @buf: Separate buf to match_counter, sec_adjust_ctrl and adj_valid
+ *    match_counter: bit[18:0], value is 0 ~ 0x7fff
+ *    sec_adjust_ctrl: bit[20:19], value is 0 ~ 2. 3 to insert a second once every
+ *    match_counter+1 seconds, 2 to swallow a second once every match_counter+1 seconds
+ *    0 or 1 to no adjustment
+ *    adj_valid: bit[23], value is 0 or 1, 0 to disable sec_adjust_ctrl and
+ *    match_counter, and 1 to enable them.
+ */
+static ssize_t rtc_calibration_store(struct device *dev,
+                                  struct device_attribute *attr,
+                                  const char *buf, size_t count)
+{
+     int retval;
+     int calibration = 0;
+
+     if (sscanf(buf, " %i ", &calibration) != 1) {
+             dev_err(dev, "Failed to store RTC calibration attribute\n");
+             return -EINVAL;
+     }
+     retval = aml_rtc_set_calibration(dev, calibration);
+
+     return retval ? retval : count;
+}
+
+static ssize_t rtc_calibration_show(struct device *dev,
+                                 struct device_attribute *attr, char *buf)
+{
+     int  retval = 0;
+     u32  calibration = 0;
+
+     retval = aml_rtc_get_calibration(dev, &calibration);
+     if (retval < 0) {
+             dev_err(dev, "Failed to read RTC calibration attribute\n");
+             sprintf(buf, "0\n");
+             return retval;
+     }
+
+     return sprintf(buf, "0x%x\n", calibration);
+}
+static DEVICE_ATTR_RW(rtc_calibration);
+
+static int rtc_set_div256_adjust(struct device *dev, u32 *value)
+{
+     struct aml_rtc_data *rtc = dev_get_drvdata(dev->parent);
+     u32 div256_adj;
+
+     div256_adj = FIELD_PREP(RTC_DIV256_ADJ_DSR | RTC_DIV256_ADJ_VAL, *value);
+     /*
+      * AO_RTC_SEC_ADJUST_REG bit 24 insert/remove(1/0) a div256 cycle,
+      * bit 25 valid/invalid(1/0) div256_adj_val
+      */
+     regmap_write_bits(rtc->map, RTC_SEC_ADJUST_REG,
+                       RTC_DIV256_ADJ_DSR | RTC_DIV256_ADJ_VAL, div256_adj);
+     /* rtc need about 30ms to adjust its time after written */
+     mdelay(30);
+
+     return 0;
+}
+
+static int rtc_get_div256_adjust(struct device *dev, u32 *value)
+{
+     struct aml_rtc_data *rtc = dev_get_drvdata(dev->parent);
+     u32 reg_val;
+
+     regmap_read(rtc->map, RTC_SEC_ADJUST_REG, &reg_val);
+     *value = FIELD_GET(RTC_DIV256_ADJ_DSR | RTC_DIV256_ADJ_VAL, reg_val);
+
+     return 0;
+}
+
+/**
+ * div256 adjust function is controlled using bit[24] and bit[25].
+ * transferred buf takes bit[0] to represent div256 adj val, bit[1]
+ * to represent div256 adj enable/disable. div256 cycle means that adjust
+ * 1/32768/256 once by written once, it's val is equal to 1/128s
+ * @buf: 3: enable div256 adjust and insert a div256 cycle
+ *    2: enable div256 adjust and remove a div256 cycle
+ *    1 or 0: disable div256 adjust
+ */
+static ssize_t rtc_div256_adjust_store(struct device *dev,
+                                    struct device_attribute *attr,
+                                    const char *buf, size_t count)
+{
+     int retval;
+     u32 value = 0;
+
+     if (sscanf(buf, " %i ", &value) != 1) {
+             dev_err(dev, "Failed to store RTC div256 adjust attribute\n");
+             return -EINVAL;
+     }
+     retval = rtc_set_div256_adjust(dev, &value);
+
+     return retval ? retval : count;
+}
+
+static ssize_t rtc_div256_adjust_show(struct device *dev,
+                                   struct device_attribute *attr, char *buf)
+{
+     int retval = 0;
+     u32 value = 0;
+
+     retval = rtc_get_div256_adjust(dev, &value);
+     if (retval < 0) {
+             dev_err(dev, "Failed to read RTC div256 adjust attribute\n");
+             sprintf(buf, "0\n");
+             return retval;
+     }
+
+     return sprintf(buf, "0x%x\n", value);
+}
+static DEVICE_ATTR_RW(rtc_div256_adjust);
+
+static struct attribute *aml_rtc_attrs[] = {
+     &dev_attr_rtc_calibration.attr,
+     &dev_attr_rtc_div256_adjust.attr,
+     NULL,
+};
Quoted 9 lines

drivers/rtc/rtc-amlogic.c line 415

Quoted 5 lines
drivers/rtc/rtc-amlogic.c new file +5 -0
+
+static const struct attribute_group aml_rtc_sysfs_files = {
+     .attrs  = aml_rtc_attrs,
+};
+

You must use the standard RTC API to handle calibration, see .read_offset and .set_offset

Will do.

Quoted 33 lines
Quoted 33 lines
drivers/rtc/rtc-amlogic.c new file +33 -0
+static void aml_rtc_init(struct device *dev, struct aml_rtc_data *rtc)
+{
+     u32 reg_val;
+     u32 rtc_enable;
+
+     regmap_read(rtc->map, RTC_CTRL, &reg_val);
+     rtc_enable = FIELD_GET(RTC_ENABLE, reg_val);
+     if (!rtc_enable) {
+             if (clk_get_rate(rtc->sclk) == OSC_24M) {
+                     /* select 24M oscillator */
+                     regmap_update_bits(rtc->map, RTC_CTRL, RTC_OSC_SEL, RTC_OSC_SEL);
+
+                     /*
+                      * Set RTC oscillator to freq_out to freq_in/((N0*M0+N1*M1)/(M0+M1))
+                      * Enable clock_in gate of oscillator 24MHz
+                      * Set N0 to 733, N1 to 732
+                      */
+                     reg_val = FIELD_PREP(RTC_OSCIN_IN_EN, 1)
+                               | FIELD_PREP(RTC_OSCIN_OUT_CFG, 1)
+                               | FIELD_PREP(RTC_OSCIN_OUT_N0M0, RTC_OSCIN_OUT_32K_N0)
+                               | FIELD_PREP(RTC_OSCIN_OUT_N1M1, RTC_OSCIN_OUT_32K_N1);
+                     regmap_write_bits(rtc->map, RTC_OSCIN_CTRL0, RTC_OSCIN_IN_EN
+                                       | RTC_OSCIN_OUT_CFG | RTC_OSCIN_OUT_N0M0
+                                       | RTC_OSCIN_OUT_N1M1, reg_val);
+
+                     /* Set M0 to 2, M1 to 3, so freq_out = 32768 Hz*/
+                     reg_val = FIELD_PREP(RTC_OSCIN_OUT_N0M0, RTC_OSCIN_OUT_32K_M0)
+                               | FIELD_PREP(RTC_OSCIN_OUT_N1M1, RTC_OSCIN_OUT_32K_M1);
+                     regmap_write_bits(rtc->map, RTC_OSCIN_CTRL1, RTC_OSCIN_OUT_N0M0
+                                       | RTC_OSCIN_OUT_N1M1, reg_val);
+             } else {
+                     /* select 32K oscillator */
+                     regmap_write_bits(rtc->map, RTC_CTRL, RTC_OSC_SEL, 0);
Quoted 9 lines

drivers/rtc/rtc-amlogic.c line 451

Quoted 3 lines
drivers/rtc/rtc-amlogic.c new file +3 -0
+             }
+             /* Enable RTC */
+             regmap_write_bits(rtc->map, RTC_CTRL, RTC_ENABLE, RTC_ENABLE);

This must not be done at probe time, else you loose the important information taht the time has never been set. Instead, it should only be enabled on the first .set_time invocation do you could now in .read_time that the time is currently invalid.

There are some doubts about this place.

You mean that after the system is up, unless the time is set, it will fail to read the time at any time, and the alarm clock will also fail. In this case, the system must set a time.

When read time invlalid, system is will set time.
This part of the logic I see the kernel part has not been implemented, so only the user application has been implemented. Whether this is reasonable, if not set time, you will never use RTC module.

Quoted 12 lines

drivers/rtc/rtc-amlogic.c line 458

Quoted 7 lines
drivers/rtc/rtc-amlogic.c new file +7 -0
+             usleep_range(100, 200);
+     }
+     regmap_write_bits(rtc->map, RTC_INT_MASK,
+                       RTC_ALRM0_IRQ_MSK, RTC_ALRM0_IRQ_MSK);
+     regmap_write_bits(rtc->map, RTC_CTRL, RTC_ALRM0_EN, 0);
+}
+

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

#9 lore raw

Re: [PATCH 2/3] rtc: support for the Amlogic on-chip RTC

Quoted 23 lines · Xianwei Zhao

Hi Alexandre,
Thanks for your reply.

Quoted 15 lines · Alexandre Belloni

[ EXTERNAL EMAIL ]

Quoted 11 lines · On 23/08/2024 17:19:45+0800, Xianwei Zhao via B4 Relay wrote:

From: Yiting Deng <[email protected]>

Support for the on-chip RTC found in some of Amlogic's SoCs such as the A113L2 and A113X2.

---
  drivers/rtc/Kconfig       |  12 +
  drivers/rtc/Makefile      |   1 +
  drivers/rtc/rtc-amlogic.c | 589 ++++++++++++++++++++++++++++++++++++++++++++++
Quoted 3 lines

As pointed out, this is the third amlogic driver so the name of the file must be more specific.

Quoted 7 lines

This RTC hardware includes a timing function and an alarm function. But the existing has only timing function, alarm function is using the system clock to implement a virtual alarm. And the relevant register access method is also different.

The "meson" string is meaningless, it just keeps going, and now the new hardware uses the normal naming.

The proper naming is then definitively not just amlogic, because in 5 year, you are going to say the exact same thing about this driver "register access is different, this is for old SoCs, etc"

amlogc-a4 would be more appropriate.

Quoted 8 lines
Quoted 8 lines

drivers/rtc/rtc-amlogic.c line 451

Quoted 2 lines
drivers/rtc/rtc-amlogic.c new file +2 -0
+             /* Enable RTC */
+             regmap_write_bits(rtc->map, RTC_CTRL, RTC_ENABLE, RTC_ENABLE);

This must not be done at probe time, else you loose the important information taht the time has never been set. Instead, it should only be enabled on the first .set_time invocation do you could now in .read_time that the time is currently invalid.

Quoted 5 lines

There are some doubts about this place.

You mean that after the system is up, unless the time is set, it will fail to read the time at any time, and the alarm clock will also fail. In this case, the system must set a time.

Exactly, reading the time must not succeed if the time is known to be bad.

Quoted 5 lines

When read time invlalid, system is will set time.
This part of the logic I see the kernel part has not been implemented, so only the user application has been implemented. Whether this is reasonable, if not set time, you will never use RTC module.

This is not going to be implemented in the kernel. The kernel can't know what is the proper time to set unless userspace tells it.

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

Re: [PATCH 2/3] rtc: support for the Amlogic on-chip RTC

Hi Alexandre,
Thanks for your reply.

Quoted 31 lines · Alexandre Belloni

[ EXTERNAL EMAIL ]

Quoted 28 lines · Xianwei Zhao

Hi Alexandre,
Thanks for your reply.

Quoted 15 lines · Alexandre Belloni

[ EXTERNAL EMAIL ]

Quoted 11 lines · On 23/08/2024 17:19:45+0800, Xianwei Zhao via B4 Relay wrote:

From: Yiting Deng <[email protected]>

Support for the on-chip RTC found in some of Amlogic's SoCs such as the A113L2 and A113X2.

---
   drivers/rtc/Kconfig       |  12 +
   drivers/rtc/Makefile      |   1 +
   drivers/rtc/rtc-amlogic.c | 589 ++++++++++++++++++++++++++++++++++++++++++++++
Quoted 3 lines

As pointed out, this is the third amlogic driver so the name of the file must be more specific.

This RTC hardware includes a timing function and an alarm function. But the existing has only timing function, alarm function is using the system clock to implement a virtual alarm. And the relevant register access method is also different.

Quoted 9 lines
Quoted 2 lines

The "meson" string is meaningless, it just keeps going, and now the new hardware uses the normal naming.

The proper naming is then definitively not just amlogic, because in 5 year, you are going to say the exact same thing about this driver "register access is different, this is for old SoCs, etc"

amlogc-a4 would be more appropriate.

Will modify driver file name to rtc-amlogic-a4.c

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/rtc/rtc-amlogic.c line 451

Quoted 2 lines
drivers/rtc/rtc-amlogic.c new file +2 -0
+             /* Enable RTC */
+             regmap_write_bits(rtc->map, RTC_CTRL, RTC_ENABLE, RTC_ENABLE);

This must not be done at probe time, else you loose the important information taht the time has never been set. Instead, it should only be enabled on the first .set_time invocation do you could now in .read_time that the time is currently invalid.

Quoted 9 lines
Quoted 5 lines

There are some doubts about this place.

You mean that after the system is up, unless the time is set, it will fail to read the time at any time, and the alarm clock will also fail. In this case, the system must set a time.

Exactly, reading the time must not succeed if the time is known to be bad.

Got it.

Quoted 9 lines
Quoted 5 lines

When read time invlalid, system is will set time.
This part of the logic I see the kernel part has not been implemented, so only the user application has been implemented. Whether this is reasonable, if not set time, you will never use RTC module.

This is not going to be implemented in the kernel. The kernel can't know what is the proper time to set unless userspace tells it.

OK will place enable action in the set_time process.

Quoted 4 lines

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

#11 lore raw

Re: [PATCH 2/3] rtc: support for the Amlogic on-chip RTC

In reply to Xianwei Zhao
kernel test robot noticed the following build warnings:

Hi Xianwei,

kernel test robot noticed the following build warnings:

[auto build test WARNING on dff71e5c6076314f3eefe700abd6af834c57bd64]

url:    https://github.com/intel-lab-lkp/linux/commits/Xianwei-Zhao-via-B4-Relay/dt-bindings-rtc-Add-Amlogic-A311L2-and-A113X2-rtc/20240826-125504
base:   dff71e5c6076314f3eefe700abd6af834c57bd64
patch link:    https://lore.kernel.org/r/20240823-rtc-v1-2-6f70381da283%40amlogic.com
patch subject: [PATCH 2/3] rtc: support for the Amlogic on-chip RTC
config: i386-buildonly-randconfig-003-20240826 (https://download.01.org/0day-ci/archive/20240826/[email protected]/config)
compiler: clang version 18.1.5 (https://github.com/llvm/llvm-project 617a15a9eac96088ae5e9134248d8236e34b91b1)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240826/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

>> drivers/rtc/rtc-amlogic.c:159:6: warning: variable 'alarm_sec' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
     159 |         if (alarm->enabled) {
         |             ^~~~~~~~~~~~~~
   drivers/rtc/rtc-amlogic.c:173:19: note: uninitialized use occurs here
     173 |                 alarm->enabled, alarm_sec);
         |                                 ^~~~~~~~~
   include/linux/dev_printk.h:168:46: note: expanded from macro 'dev_dbg'
     168 |         dev_printk(KERN_DEBUG, dev, dev_fmt(fmt), ##__VA_ARGS__)
         |                                                     ^~~~~~~~~~~
   include/linux/dev_printk.h:129:34: note: expanded from macro 'dev_printk'
     129 |                 _dev_printk(level, dev, fmt, ##__VA_ARGS__);            \
         |                                                ^~~~~~~~~~~
   drivers/rtc/rtc-amlogic.c:159:2: note: remove the 'if' if its condition is always true
     159 |         if (alarm->enabled) {
         |         ^~~~~~~~~~~~~~~~~~~
   drivers/rtc/rtc-amlogic.c:157:20: note: initialize the variable 'alarm_sec' to silence this warning
     157 |         time64_t alarm_sec;
         |                           ^
         |                            = 0
>> drivers/rtc/rtc-amlogic.c:565:34: warning: unused variable 'aml_rtc_device_id' [-Wunused-const-variable]
     565 | static const struct of_device_id aml_rtc_device_id[] = {
         |                                  ^~~~~~~~~~~~~~~~~

2 warnings generated.

vim +159 drivers/rtc/rtc-amlogic.c

153
154 static int aml_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
155 {
156 struct aml_rtc_data *rtc = dev_get_drvdata(dev);
157 time64_t alarm_sec;
158

 > 159		if (alarm->enabled) {

160 regmap_update_bits(rtc->map, RTC_CTRL,
161 RTC_ALRM0_EN, RTC_ALRM0_EN);
162 regmap_update_bits(rtc->map, RTC_INT_MASK,
163 RTC_ALRM0_IRQ_MSK, 0);
164
165 alarm_sec = rtc_tm_to_time64(&alarm->time);
166 if (alarm_sec > U32_MAX) {
167 dev_err(dev, "alarm value invalid!\n");
168 return -EINVAL;
169 }
170 aml_set_alarm(rtc, alarm_sec);
171 }
172 dev_dbg(dev, "%s: alarm->enabled=%d alarm_set=%llds\n", __func__,
173 alarm->enabled, alarm_sec);
174
175 return 0;
176 }
177

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#12 lore raw

Re: [PATCH 2/3] rtc: support for the Amlogic on-chip RTC

In reply to Xianwei Zhao
kernel test robot noticed the following build warnings:

Hi Xianwei,

kernel test robot noticed the following build warnings:

[auto build test WARNING on dff71e5c6076314f3eefe700abd6af834c57bd64]

url:    https://github.com/intel-lab-lkp/linux/commits/Xianwei-Zhao-via-B4-Relay/dt-bindings-rtc-Add-Amlogic-A311L2-and-A113X2-rtc/20240826-125504
base:   dff71e5c6076314f3eefe700abd6af834c57bd64
patch link:    https://lore.kernel.org/r/20240823-rtc-v1-2-6f70381da283%40amlogic.com
patch subject: [PATCH 2/3] rtc: support for the Amlogic on-chip RTC
config: arc-randconfig-002-20240826 (https://download.01.org/0day-ci/archive/20240826/[email protected]/config)
compiler: arc-elf-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240826/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

>> drivers/rtc/rtc-amlogic.c:545:12: warning: 'aml_rtc_resume' defined but not used [-Wunused-function]
     545 | static int aml_rtc_resume(struct device *dev)
         |            ^~~~~~~~~~~~~~
>> drivers/rtc/rtc-amlogic.c:535:12: warning: 'aml_rtc_suspend' defined but not used [-Wunused-function]

535 | static int aml_rtc_suspend(struct device *dev)
| ^~~~~~~~~~~~~~~

vim +/aml_rtc_resume +545 drivers/rtc/rtc-amlogic.c

534

 > 535	static int aml_rtc_suspend(struct device *dev)
   536	{
   537		struct aml_rtc_data *rtc = dev_get_drvdata(dev);
   538	
   539		if (device_may_wakeup(dev))
   540			enable_irq_wake(rtc->irq);
   541	
   542		return 0;
   543	}
   544	
 > 545	static int aml_rtc_resume(struct device *dev)

546 {
547 struct aml_rtc_data *rtc = dev_get_drvdata(dev);
548
549 if (device_may_wakeup(dev))
550 disable_irq_wake(rtc->irq);
551
552 return 0;
553 }
554

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#13 lore raw

PATCH 3/3 MAINTAINERS: Add an entry for Amlogic RTC driver

In reply to Xianwei Zhao

From: Yiting Deng <[email protected]>

Add Amlogic RTC entry to MAINTAINERS to clarify the maintainers

---
 MAINTAINERS | 8 ++++++++
 1 file changed, 8 insertions(+)
MAINTAINERS +8 -0
index 42decde38320..672290dddaaa 100644
@@ -2481,6 +2481,14 @@ F:	drivers/irqchip/irq-mvebu-*
 F:	drivers/pinctrl/mvebu/
 F:	drivers/rtc/rtc-armada38x.c
 
+ARM/Amlogic RTC Driver
+M:	Yiting Deng <[email protected]>
+M:	Xianwei Zhao <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	Documentation/devicetree/bindings/rtc/amlogic,amlogic-rtc.yaml
+F:	drivers/rtc/rtc-amlogic.c
+
 ARM/Mediatek RTC DRIVER
 M:	Eddie Huang <[email protected]>
 M:	Sean Wang <[email protected]>
Signature · 1 line
2.37.1
#14 lore raw

Re: [PATCH 3/3] MAINTAINERS: Add an entry for Amlogic RTC driver

Quoted 15 lines · On 23/08/2024 11:19, Xianwei Zhao via B4 Relay wrote:

From: Yiting Deng <[email protected]>

Add Amlogic RTC entry to MAINTAINERS to clarify the maintainers

---
 MAINTAINERS | 8 ++++++++
 1 file changed, 8 insertions(+)
MAINTAINERS +0 -0
index 42decde38320..672290dddaaa 100644

MAINTAINERS F: drivers/irqchip/irq-mvebu-* · line 2484

Quoted 4 lines
MAINTAINERS +1 -0
@@ -2481,6 +2481,14 @@ F:	drivers/irqchip/irq-mvebu-*
 F:	drivers/pinctrl/mvebu/
 F:	drivers/rtc/rtc-armada38x.c
 
+ARM/Amlogic RTC Driver

"ARM" is for Soc entries, not individual drivers. Drop. Place it correctly and use capital letters.

Best regards,
Krzysztof

#15 lore raw

Re: [PATCH 3/3] MAINTAINERS: Add an entry for Amlogic RTC driver

Hi Krzysztof,
Thanks for your reply.

Quoted 21 lines · Krzysztof Kozlowski

[ EXTERNAL EMAIL ]

Quoted 18 lines · On 23/08/2024 11:19, Xianwei Zhao via B4 Relay wrote:

From: Yiting Deng <[email protected]>

Add Amlogic RTC entry to MAINTAINERS to clarify the maintainers

---
  MAINTAINERS | 8 ++++++++
  1 file changed, 8 insertions(+)
MAINTAINERS +0 -0
index 42decde38320..672290dddaaa 100644
@@ -2481,6 +2481,14 @@ F:     drivers/irqchip/irq-mvebu-*
  F:   drivers/pinctrl/mvebu/
  F:   drivers/rtc/rtc-armada38x.c
 
Quoted 5 lines

MAINTAINERS F: drivers/irqchip/irq-mvebu-* · line 2484

Quoted 1 line
MAINTAINERS +1 -0
+ARM/Amlogic RTC Driver

"ARM" is for Soc entries, not individual drivers. Drop. Place it correctly and use capital letters.

Will do.

Quoted 5 lines

Best regards,
Krzysztof