Skip to contentSkip to conversation

rtc: microchip: Add driver for PolarFire SoC

PATCH In review [email protected] 3 participants 6 messages May 12, 2021 – May 13, 2021

Subsystems (3)
lore
Share & tools
lore

[email protected]

author reviewer
#0 lore raw

cover rtc: microchip: Add driver for PolarFire SoC

From: Daire McNamara <[email protected]>

This patchset adds support for the Microchip PolarFire SoC RTC hardware block.

Daire McNamara (2):
dt-bindings: rtc: microchip: Add Microchip PolarFire host binding
rtc: microchip: Add driver for Microchip PolarFire SoC

 .../bindings/rtc/microchip,mfps-rtc.yaml      |  61 +++
 drivers/rtc/Kconfig                           |   7 +
 drivers/rtc/Makefile                          |   1 +
 drivers/rtc/rtc-mpfs.c                        | 449 ++++++++++++++++++
 4 files changed, 518 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/rtc/microchip,mfps-rtc.yaml
 create mode 100644 drivers/rtc/rtc-mpfs.c

base-commit: acd3d28594536e9096c1ea76c5867d8a68babef6
prerequisite-patch-id: 6f7f70120adfa8e938b97517f0c664e43e8745a0
prerequisite-patch-id: 4ea37008d23838aa2e0658811fe15462f6cdbd87
prerequisite-patch-id: 378c9d7495e56454b7bffbdbc430185dc4e36b90
prerequisite-patch-id: b547bbdf0a800c652cdd1a542b8ce725dfd6fcc9
prerequisite-patch-id: 98fc35868a9b0e284ba666422770fb3a4fe27ed9
prerequisite-patch-id: 28006f331625d755e92cc87ae194e05138f26909
prerequisite-patch-id: 26afc006e51cf743902bf609b537e1558e70f69c

Signature · 1 line
2.25.1
author reviewer
#1 lore raw

PATCH 1/2 dt-bindings: rtc: microchip: Add Microchip PolarFire host binding

From: Daire McNamara <[email protected]>

Add device tree bindings for the Microchip PolarFire real-time clock controller

---
 .../bindings/rtc/microchip,mfps-rtc.yaml      | 61 +++++++++++++++++++
 1 file changed, 61 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/rtc/microchip,mfps-rtc.yaml
Documentation/devicetree/bindings/rtc/microchip,mfps-rtc.yaml new file +61 -0
new file mode 100644
index 000000000000..c82b3e7351e0
@@ -0,0 +1,61 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/rtc/microchip,mfps-rtc.yaml#
+
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Microchip PolarFire Soc (MPFS) RTC Device Tree Bindings
+
+allOf:
+  - $ref: "rtc.yaml#"
+
+maintainers:
+  - Daire McNamara <[email protected]>
+  - Lewis Hanly <[email protected]>
+
+properties:
+  compatible:
+    enum:
+      - microchip,mpfs-rtc
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  prescaler:
+    maxItems: 1
+
+  clocks:
+    maxItems: 1
+
+  clock-names:
+    items:
+      - const: rtc
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - clocks
+  - clock-names
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/clock/microchip,mpfs-clock.h>
+    soc {
+        #address-cells = <2>;
+        #size-cells = <2>;
+        rtc@20124000 {
+            compatible = "microchip,mpfs-rtc";
+            reg = <0 0x20124000 0 0x1000>;
+            clocks = <&clkcfg CLK_RTC>;
+            clock-names = "rtc";
+            interrupts = <80>;
+        };
+    };
+...
Signature · 1 line
2.25.1
maintainer
#2 lore raw

Re: [PATCH v1 1/2] dt-bindings: rtc: microchip: Add Microchip PolarFire host binding

Quoted 11 lines · On Wed, 12 May 2021 12:11:32 +0100, [email protected] wrote:

From: Daire McNamara <[email protected]>

Add device tree bindings for the Microchip PolarFire real-time clock controller

---
 .../bindings/rtc/microchip,mfps-rtc.yaml      | 61 +++++++++++++++++++
 1 file changed, 61 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/rtc/microchip,mfps-rtc.yaml

My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check' on your patch (DT_CHECKER_FLAGS is new in v5.13):

yamllint warnings/errors:

dtschema/dtc warnings/errors:
Documentation/devicetree/bindings/rtc/microchip,mfps-rtc.example.dts:19:18: fatal error: dt-bindings/clock/microchip,mpfs-clock.h: No such file or directory
19 | #include <dt-bindings/clock/microchip,mpfs-clock.h>

      |                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

compilation terminated.
make[1]: *** [scripts/Makefile.lib:380: Documentation/devicetree/bindings/rtc/microchip,mfps-rtc.example.dt.yaml] Error 1 make[1]: *** Waiting for unfinished jobs....
make: *** [Makefile:1416: dt_binding_check] Error 2

See https://patchwork.ozlabs.org/patch/1477539

This check can fail if there are any dependencies. The base for a patch series is generally the most recent rc1.

If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:

pip3 install dtschema --upgrade

Please check and re-submit.

maintainer
#3 lore raw

Re: [PATCH v1 1/2] dt-bindings: rtc: microchip: Add Microchip PolarFire host binding

In reply to [email protected]
Quoted 36 lines · On Wed, May 12, 2021 at 12:11:32PM +0100, [email protected] wrote:

From: Daire McNamara <[email protected]>

Add device tree bindings for the Microchip PolarFire real-time clock controller

---
 .../bindings/rtc/microchip,mfps-rtc.yaml      | 61 +++++++++++++++++++
 1 file changed, 61 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/rtc/microchip,mfps-rtc.yaml
Documentation/devicetree/bindings/rtc/microchip,mfps-rtc.yaml new file +19 -0
new file mode 100644
index 000000000000..c82b3e7351e0
@@ -0,0 +1,61 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/rtc/microchip,mfps-rtc.yaml#
+
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Microchip PolarFire Soc (MPFS) RTC Device Tree Bindings
+
+allOf:
+  - $ref: "rtc.yaml#"
+
+maintainers:
+  - Daire McNamara <[email protected]>
+  - Lewis Hanly <[email protected]>
+
+properties:
+  compatible:
+    enum:

Documentation/devicetree/bindings/rtc/microchip,mfps-rtc.yaml line 29

Quoted 10 lines
Documentation/devicetree/bindings/rtc/microchip,mfps-rtc.yaml new file +10 -0
+      - microchip,mpfs-rtc
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  prescaler:
+    maxItems: 1

An array?

Needs a type, constraints, and vendor prefix.

Documentation/devicetree/bindings/rtc/microchip,mfps-rtc.yaml line 36

Quoted 7 lines
Documentation/devicetree/bindings/rtc/microchip,mfps-rtc.yaml new file +7 -0
+
+  clocks:
+    maxItems: 1
+
+  clock-names:
+    items:
+      - const: rtc

Kind of a pointless name. You don't need *-names when there is only 1.

Quoted 28 lines
Documentation/devicetree/bindings/rtc/microchip,mfps-rtc.yaml new file +25 -0
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - clocks
+  - clock-names
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/clock/microchip,mpfs-clock.h>
+    soc {
+        #address-cells = <2>;
+        #size-cells = <2>;
+        rtc@20124000 {
+            compatible = "microchip,mpfs-rtc";
+            reg = <0 0x20124000 0 0x1000>;
+            clocks = <&clkcfg CLK_RTC>;
+            clock-names = "rtc";
+            interrupts = <80>;
+        };
+    };
+...
Signature · 1 line
2.25.1
author reviewer
#4 lore raw

PATCH 2/2 rtc: microchip: Add driver for Microchip PolarFire SoC

In reply to [email protected]

From: Daire McNamara <[email protected]>

Add support for built-in RTC on Microchip PolarFire SoC

---
 drivers/rtc/Kconfig    |   7 +
 drivers/rtc/Makefile   |   1 +
 drivers/rtc/rtc-mpfs.c | 449 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 457 insertions(+)
 create mode 100644 drivers/rtc/rtc-mpfs.c
drivers/rtc/Kconfig +7 -0
index ce723dc54aa4..12e2308423ee 100644
@@ -1655,6 +1655,13 @@ config RTC_DRV_MPC5121
 	  This driver can also be built as a module. If so, the module
 	  will be called rtc-mpc5121.
 
+config RTC_DRV_MPFS
+	tristate "Microchip PolarFire SoC built-in RTC"
+	depends on SOC_MICROCHIP_POLARFIRE
+	help
+	  If you say yes here you will get support for the
+	  built-in RTC on MPFS.
+
 config RTC_DRV_JZ4740
 	tristate "Ingenic JZ4740 SoC"
 	depends on MIPS || COMPILE_TEST
drivers/rtc/Makefile +1 -0
index 4e930183c170..4a02d3d0278d 100644
@@ -101,6 +101,7 @@ obj-$(CONFIG_RTC_DRV_MCP795)	+= rtc-mcp795.o
 obj-$(CONFIG_RTC_DRV_MESON)	+= rtc-meson.o
 obj-$(CONFIG_RTC_DRV_MOXART)	+= rtc-moxart.o
 obj-$(CONFIG_RTC_DRV_MPC5121)	+= rtc-mpc5121.o
+obj-$(CONFIG_RTC_DRV_MPFS)	+= rtc-mpfs.o
 obj-$(CONFIG_RTC_DRV_MSM6242)	+= rtc-msm6242.o
 obj-$(CONFIG_RTC_DRV_MT2712)	+= rtc-mt2712.o
 obj-$(CONFIG_RTC_DRV_MT6397)	+= rtc-mt6397.o
drivers/rtc/rtc-mpfs.c new file +449 -0

449 lines not on this page · raw message

Signature · 1 line
2.25.1
#5 lore raw

Re: [PATCH v1 2/2] rtc: microchip: Add driver for Microchip PolarFire SoC

Hello,

The subject should be:
rtc: Add driver for Microchip PolarFire SoC

Quoted 17 lines · On 12/05/2021 12:11:33+0100, [email protected] wrote:

From: Daire McNamara <[email protected]>

Add support for built-in RTC on Microchip PolarFire SoC

---
 drivers/rtc/Kconfig    |   7 +
 drivers/rtc/Makefile   |   1 +
 drivers/rtc/rtc-mpfs.c | 449 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 457 insertions(+)
 create mode 100644 drivers/rtc/rtc-mpfs.c
drivers/rtc/Kconfig +0 -0
index ce723dc54aa4..12e2308423ee 100644

drivers/rtc/Kconfig config RTC_DRV_MPC5121 · line 1663

Quoted 9 lines
drivers/rtc/Kconfig +6 -0
@@ -1655,6 +1655,13 @@ config RTC_DRV_MPC5121
 	  This driver can also be built as a module. If so, the module
 	  will be called rtc-mpc5121.
 
+config RTC_DRV_MPFS
+	tristate "Microchip PolarFire SoC built-in RTC"
+	depends on SOC_MICROCHIP_POLARFIRE
+	help
+	  If you say yes here you will get support for the
+	  built-in RTC on MPFS.

MPFS is not really descriptive, can you spell it out completely?

drivers/rtc/Kconfig config RTC_DRV_MPC5121 · line 1664

Quoted 1 line
drivers/rtc/Kconfig +1 -0
+++ b/drivers/rtc/rtc-mpfs.c

Same comment, rtc-mpfs.c is not very descriptive...

drivers/rtc/Kconfig config RTC_DRV_MPC5121

Quoted 8 lines
drivers/rtc/Kconfig +8 -0
+#include <linux/clk.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/rtc.h>
+#include <linux/io.h>

Includes should be sorted alphabetically

drivers/rtc/Kconfig

Quoted 3 lines
drivers/rtc/Kconfig +3 -0
+
+/*
+ * Device Specific Peripheral registers structures

Those are not structures, I don't think this comment is useful

Quoted 49 lines

+ */

drivers/rtc/Kconfig +48 -0
+#define CONTROL_REG		0x00
+#define  CONTROL_RUNNING_BIT		BIT(0)
+#define  CONTROL_START_BIT		BIT(0)
+#define  CONTROL_STOP_BIT		BIT(1)
+#define  CONTROL_ALARM_ON_BIT		BIT(2)
+#define  CONTROL_ALARM_OFF_BIT		BIT(3)
+#define  CONTROL_RESET_BIT		BIT(4)
+#define  CONTROL_UPLOAD_BIT		BIT(5)
+#define  CONTROL_WAKEUP_CLR_BIT		BIT(8)
+#define  CONTROL_WAKEUP_SET_BIT		BIT(9)
+#define  CONTROL_UPDATED_BIT		BIT(10)
+#define  MPFS_RTC_NUM_IRQS		2
+#define MODE_REG		0x04
+#define  MODE_CLOCK_BIT			BIT(0)
+#define   MODE_CLOCK_CALENDAR		1
+#define  MODE_WAKE_EN_BIT		BIT(1)
+#define  MODE_WAKE_RESET_BIT		BIT(2)
+#define  MODE_WAKE_CONTINUE_BIT		BIT(3)
+#define PRESCALER_REG		0x08
+#define ALARM_LOWER_REG		0x0c
+#define ALARM_UPPER_REG		0x10
+#define COMPARE_LOWER_REG	0x14
+#define COMPARE_UPPER_REG	0x18
+#define DATETIME_LOWER_REG	0x20
+#define DATETIME_UPPER_REG	0x24
+#define SECONDS_REG		0x30
+#define MINUTES_REG		0x34
+#define HOURS_REG		0x38
+#define DAY_REG			0x3c
+#define MONTH_REG		0x40
+#define YEAR_REG		0x44
+#define WEEKDAY_REG		0x48
+#define WEEK_REG		0x4c
+
+/*
+ * Linux counts from 1970 but tm_year starts at 1900, MPFS RTC counts from 2000
+ * Account for this difference
+ */
+#define YEAR_OFFSET		(100)
+
+#define MAX_PRESCALER_COUNT	GENMASK(21, 0)
+#define DEFAULT_PRESCALER	999999  /* (1Mhz / prescaler) -1 = 1Hz */
+
+struct mpfs_rtc_dev {
+	struct rtc_device *rtc;
+	void __iomem *base;
+	int wakeup_irq;
+	u32 prescaler;

drivers/rtc/Kconfig

Quoted 10 lines
drivers/rtc/Kconfig +10 -0
+};
+
+static void mpfs_rtc_stop(struct mpfs_rtc_dev *rtcdev)
+{
+	u32 ctrl;
+
+	ctrl = readl(rtcdev->base + CONTROL_REG);
+	ctrl &= ~(CONTROL_STOP_BIT | CONTROL_START_BIT);
+	ctrl |= CONTROL_STOP_BIT;
+	ctrl |= CONTROL_ALARM_OFF_BIT;

stop and start then has the unexpected side effect that it disables the alarm and this happens at boot time.

Quoted 30 lines
drivers/rtc/Kconfig +30 -0
+	writel(ctrl, rtcdev->base + CONTROL_REG);
+}
+
+static void mpfs_rtc_start(struct mpfs_rtc_dev *rtcdev)
+{
+	u32 ctrl;
+
+	ctrl = readl(rtcdev->base + CONTROL_REG);
+	ctrl &= ~(CONTROL_STOP_BIT | CONTROL_START_BIT);
+	ctrl |= CONTROL_START_BIT;
+	writel(ctrl, rtcdev->base + CONTROL_REG);
+}
+
+static void mpfs_rtc_clear_irq(struct mpfs_rtc_dev *rtcdev)
+{
+	u32 val = readl(rtcdev->base + CONTROL_REG);
+
+	val &= ~(CONTROL_ALARM_ON_BIT | CONTROL_STOP_BIT);
+	val |= CONTROL_ALARM_OFF_BIT;
+	writel(val, rtcdev->base + CONTROL_REG);
+	/*
+	 * Ensure that the posted write to the CONTROL_REG register completed before
+	 * returning from this function. Not doing this may result in the interrupt
+	 * only being cleared some time after this function returns.
+	 */
+	(void)readl(rtcdev->base + CONTROL_REG);
+}
+
+static void mpfs_rtc_calendar_mode(struct mpfs_rtc_dev *rtcdev)
+{

drivers/rtc/Kconfig

Quoted 10 lines
drivers/rtc/Kconfig +10 -0
+	u32 val;
+	u32 rtc_running;
+
+	val = readl(rtcdev->base + MODE_REG);
+	val |= MODE_CLOCK_CALENDAR;
+
+	rtc_running = readl(rtcdev->base + CONTROL_REG);
+	if (rtc_running & CONTROL_RUNNING_BIT) {
+		/* Stop the RTC in order to change the mode register content. */
+		mpfs_rtc_stop(rtcdev);

There is now way it is running at this point as your are stopping the RTC unconditionally before calling the function.

Quoted 5 lines
drivers/rtc/Kconfig +5 -0
+		writel(val, rtcdev->base + MODE_REG);
+		mpfs_rtc_start(rtcdev);
+	} else {
+		writel(val, rtcdev->base + MODE_REG);
+	}

drivers/rtc/Kconfig

Quoted 10 lines
drivers/rtc/Kconfig +8 -0
+}
+
 
 
+static void mpfs_rtc_set_prescaler(struct mpfs_rtc_dev *rtcdev, unsigned int prescaler)
+{
+	writel(prescaler, rtcdev->base + PRESCALER_REG);
+}
+
+static inline struct clk *mpfs_rtc_init_clk(struct device *dev)

Why is that inline? This should probably be simply part of the probe function.

Quoted 17 lines
drivers/rtc/Kconfig +17 -0
+{
+	struct clk *clk;
+	int ret;
+
+	clk = devm_clk_get(dev, "rtc");
+	if (IS_ERR(clk))
+		return clk;
+
+	ret = clk_prepare_enable(clk);
+	if (ret)
+		return ERR_PTR(ret);
+
+	devm_add_action_or_reset(dev, (void (*) (void *))clk_disable_unprepare, clk);
+
+	return clk;
+}
+

drivers/rtc/Kconfig

Quoted 10 lines
drivers/rtc/Kconfig +10 -0
+static irqreturn_t mpfs_rtc_wakeup_irq_handler(int irq, void *d)
+{
+	struct mpfs_rtc_dev *rtcdev = d;
+	unsigned long pending;
+
+	pending = readl(rtcdev->base + CONTROL_REG);
+	pending &= CONTROL_ALARM_ON_BIT;
+	mpfs_rtc_clear_irq(rtcdev);
+
+	/* its an alarm */

This comment is not really useful.

Quoted 21 lines
drivers/rtc/Kconfig +21 -0
+	rtc_update_irq(rtcdev->rtc, 1, RTC_IRQF | RTC_AF);
+
+	return IRQ_HANDLED;
+}
+
+static const struct rtc_class_ops mpfs_rtc_ops = {
+	.read_time		= mpfs_rtc_readtime,
+	.set_time		= mpfs_rtc_settime,
+	.read_alarm		= mpfs_rtc_readalarm,
+	.set_alarm		= mpfs_rtc_setalarm,
+	.alarm_irq_enable	= mpfs_rtc_alarm_irq_enable,
+};
+
+static void mpfs_rtc_init(struct mpfs_rtc_dev *rtcdev)
+{
+	u32 ctrl;
+
+	mpfs_rtc_set_prescaler(rtcdev, rtcdev->prescaler);
+
+	mpfs_rtc_stop(rtcdev);
+	mpfs_rtc_calendar_mode(rtcdev);

drivers/rtc/Kconfig

Quoted 10 lines
drivers/rtc/Kconfig +10 -0
+
+	writel(0, rtcdev->base + ALARM_LOWER_REG);
+	writel(0, rtcdev->base + ALARM_UPPER_REG);
+	writel(0, rtcdev->base + COMPARE_LOWER_REG);
+	writel(0, rtcdev->base + COMPARE_UPPER_REG);
+
+	ctrl = readl(rtcdev->base + CONTROL_REG);
+	ctrl &= ~(CONTROL_RESET_BIT | CONTROL_STOP_BIT | CONTROL_START_BIT);
+	ctrl |= CONTROL_RESET_BIT | CONTROL_START_BIT;
+	writel(ctrl, rtcdev->base + CONTROL_REG);

Is this resetting the RTC? If this is the case, then the RTC and the driver are basically useless as the whole goal of the RTC is to keep time when the platform is off.

drivers/rtc/Kconfig

Quoted 3 lines
drivers/rtc/Kconfig +3 -0
+}
+
+static int __init mpfs_rtc_probe(struct platform_device *pdev)

__init on a probe function is a bug

Quoted 7 lines
drivers/rtc/Kconfig +7 -0
+{
+	struct mpfs_rtc_dev *rtcdev;
+	struct clk *clk;
+	int ret;
+
+	rtcdev = devm_kzalloc(&pdev->dev, sizeof(struct mpfs_rtc_dev), GFP_KERNEL);
+	if (!rtcdev)

drivers/rtc/Kconfig

Quoted 10 lines
drivers/rtc/Kconfig +10 -0
+		return -ENOMEM;
+
+	platform_set_drvdata(pdev, rtcdev);
+
+	rtcdev->rtc = devm_rtc_allocate_device(&pdev->dev);
+	if (IS_ERR(rtcdev->rtc))
+		return PTR_ERR(rtcdev->rtc);
+
+	rtcdev->rtc->ops = &mpfs_rtc_ops;
+	rtcdev->rtc->range_max = U32_MAX;

Are you sure about that? I guess this is wrong, especially since you are opencoding the offset instead of properly setting range_min and I think this is the whole goal of switching to calendar mode which seems to be 2000 to 2255.

Actually, I'm not sure why you are using calendar mode as binary mode would be more efficient, won't require offsetting and goes up to year 280707

Quoted 22 lines
drivers/rtc/Kconfig +22 -0
+
+	clk = mpfs_rtc_init_clk(&pdev->dev);
+	if (IS_ERR(clk))
+		return PTR_ERR(clk);
+
+	rtcdev->base = devm_platform_ioremap_resource(pdev, 0);
+	if (IS_ERR(rtcdev->base)) {
+		dev_dbg(&pdev->dev, "invalid ioremap resources\n");
+		return PTR_ERR(rtcdev->base);
+	}
+
+	rtcdev->wakeup_irq = platform_get_irq(pdev, 0);
+	if (rtcdev->wakeup_irq <= 0) {
+		dev_dbg(&pdev->dev, "could not get wakeup irq\n");
+		return rtcdev->wakeup_irq;
+	}
+	ret = devm_request_irq(&pdev->dev, rtcdev->wakeup_irq, mpfs_rtc_wakeup_irq_handler, 0,
+			       dev_name(&pdev->dev), rtcdev);
+	if (ret) {
+		dev_dbg(&pdev->dev, "could not request wakeup irq\n");
+		return ret;
+	}

drivers/rtc/Kconfig

Quoted 10 lines
drivers/rtc/Kconfig +10 -0
+
+	ret = of_property_read_u32(pdev->dev.of_node, "prescaler", &rtcdev->prescaler);
+	if (ret)
+		rtcdev->prescaler = DEFAULT_PRESCALER;
+
+	if (rtcdev->prescaler > MAX_PRESCALER_COUNT) {
+		dev_dbg(&pdev->dev, "invalid prescaler %d\n", rtcdev->prescaler);
+		return -EPERM;
+	}
+

You don't have to read the prescaler value from the device tree, instead, you should provide a second clock, RTCCLK and use its rate to calculate the prescaler.

drivers/rtc/Kconfig

Quoted 2 lines
drivers/rtc/Kconfig +2 -0
+	mpfs_rtc_init(rtcdev);
+

Again don't do that, this renders the RTC useless.

drivers/rtc/Kconfig

Quoted 2 lines
drivers/rtc/Kconfig +2 -0
+	dev_info(&pdev->dev, "Microchip Polarfire SoC RTC\n");
+

The core already prints out messages, don't litter the kernel logs.

drivers/rtc/Kconfig

Quoted 8 lines
drivers/rtc/Kconfig +8 -0
+	device_init_wakeup(&pdev->dev, 1);
+
+	return devm_rtc_register_device(rtcdev->rtc);
+}
+
+static int mpfs_rtc_remove(struct platform_device *pdev)
+{
+	mpfs_rtc_alarm_irq_enable(&pdev->dev, 0);

If the RTC can power up the platform, this should not be done.

Quoted 5 lines
drivers/rtc/Kconfig +5 -0
+	device_init_wakeup(&pdev->dev, 0);
+
+	return 0;
+}
+

drivers/rtc/Kconfig

Quoted 10 lines
drivers/rtc/Kconfig +10 -0
+#ifdef CONFIG_PM_SLEEP
+static int mpfs_rtc_suspend(struct device *dev)
+{
+	struct mpfs_rtc_dev *rtcdev = dev_get_drvdata(dev);
+
+	/* leave the alarm on as a wake source */
+	if (device_may_wakeup(dev))
+		enable_irq_wake(rtcdev->wakeup_irq);
+	else
+		mpfs_rtc_alarm_irq_enable(dev, 0);

Because you call device_init_wakeup(), device_may_wakeup will always be true.

Quoted 4 lines
drivers/rtc/Kconfig +4 -0
+
+	return 0;
+}
+

drivers/rtc/Kconfig

Quoted 10 lines
drivers/rtc/Kconfig +10 -0
+static int mpfs_rtc_resume(struct device *dev)
+{
+	struct mpfs_rtc_dev *rtcdev = dev_get_drvdata(dev);
+
+	/* alarms were left on as a wake source, turn them off */
+	if (device_may_wakeup(dev))
+		disable_irq_wake(rtcdev->wakeup_irq);
+	else
+		mpfs_rtc_alarm_irq_enable(dev, 1);
+

ditto

drivers/rtc/Kconfig

Quoted 5 lines
drivers/rtc/Kconfig +5 -0
+	return 0;
+}
+#endif
+
+static SIMPLE_DEV_PM_OPS(mpfs_rtc_pm_ops, mpfs_rtc_suspend, mpfs_rtc_resume);

Please use dev_pm_set_wake_irq to avoid opencoding all of that.

Quoted 26 lines
drivers/rtc/Kconfig +23 -0
+
+static const struct of_device_id mpfs_rtc_of_match[] = {
+	{ .compatible = "microchip,mpfs-rtc" },
+	{ }
+};
+
+MODULE_DEVICE_TABLE(of, mpfs_rtc_of_match);
+
+static struct platform_driver mpfs_rtc_driver = {
+	.probe = mpfs_rtc_probe,
+	.remove = mpfs_rtc_remove,
+	.driver	= {
+		.name = "mpfs_rtc",
+		.pm = &mpfs_rtc_pm_ops,
+		.of_match_table = mpfs_rtc_of_match,
+	},
+};
+
+module_platform_driver(mpfs_rtc_driver);
+
+MODULE_DESCRIPTION("Real time clock for Microchip Polarfire SoC");
+MODULE_AUTHOR("Daire McNamara <[email protected]>");
+MODULE_LICENSE("GPL v2");
Signature · 1 line
2.25.1
Signature · 3 lines
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com