* [PATCH 0/7] rtc: ls2x: Add support for the Loongson-2K/LS7A RTC
@ 2022-09-03 9:34 Binbin Zhou
2022-09-03 9:34 ` [PATCH 1/7] " Binbin Zhou
` (7 more replies)
0 siblings, 8 replies; 11+ messages in thread
From: Binbin Zhou @ 2022-09-03 9:34 UTC (permalink / raw)
To: Alessandro Zummo, linux-rtc
Cc: linux-mips, devicetree, loongarch, linux-acpi, Binbin Zhou
Hi all:
The initial DT-base ls2x rtc driver was written by Wang Xuerui, he has
released five versions of patchset before, and all related mail records
are shown below if you are interested:
https://lore.kernel.org/all/?q=ls2x-rtc
In this series of patches, based on the code above, I have added the
following support:
1. Add ACPI-related support, as Loongson-3 + LS7A is now ACPI-base
by default on LoonArch;
2. Add rtc alarm/walarm related functions.
Unfortunately, I have only tested the Loongson-3A4000+LS7A1000/LS7A2000
under LoongArch architecture.
NOTE:
The related functions of rtc alarm/walarm depend on ACPI registers, so rtc
alarm may not be available on the DT-base environment. Such as Loongson-2k/3
under MIPS.
Thanks.
Binbin Zhou (2):
rtc: ls2x: Add support for the Loongson-2K/LS7A RTC
LoongArch: Enable LS2X RTC in loongson3_defconfig
WANG Xuerui (5):
dt-bindings: rtc: Add bindings for LS2X RTC
MIPS: Loongson64: DTS: Add RTC support to LS7A
MIPS: Loongson: Enable LS2X RTC in loongson3_defconfig
MIPS: Loongson64: DTS: Add RTC support to Loongson-2K
MIPS: Loongson: Enable LS2X RTC in loongson2k_defconfig
.../devicetree/bindings/rtc/trivial-rtc.yaml | 2 +
arch/loongarch/configs/loongson3_defconfig | 1 +
.../boot/dts/loongson/loongson64-2k1000.dtsi | 5 +
arch/mips/boot/dts/loongson/ls7a-pch.dtsi | 5 +
arch/mips/configs/loongson2k_defconfig | 1 +
arch/mips/configs/loongson3_defconfig | 1 +
drivers/rtc/Kconfig | 11 +
drivers/rtc/Makefile | 1 +
drivers/rtc/rtc-ls2x.c | 366 ++++++++++++++++++
9 files changed, 393 insertions(+)
create mode 100644 drivers/rtc/rtc-ls2x.c
--
2.31.1
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 1/7] rtc: ls2x: Add support for the Loongson-2K/LS7A RTC
2022-09-03 9:34 [PATCH 0/7] rtc: ls2x: Add support for the Loongson-2K/LS7A RTC Binbin Zhou
@ 2022-09-03 9:34 ` Binbin Zhou
2022-09-03 9:34 ` [PATCH 2/7] LoongArch: Enable LS2X RTC in loongson3_defconfig Binbin Zhou
` (6 subsequent siblings)
7 siblings, 0 replies; 11+ messages in thread
From: Binbin Zhou @ 2022-09-03 9:34 UTC (permalink / raw)
To: Alessandro Zummo, linux-rtc
Cc: linux-mips, devicetree, loongarch, linux-acpi, Binbin Zhou,
Huacai Chen, WANG Xuerui, Alexandre Belloni, Rafael J. Wysocki
This RTC module is integrated into the Loongson-2K SoC and the LS7A
bridge chip. This version is almost entirely rewritten to make use of
current kernel API, and it supports both ACPI and DT.
Signed-off-by: Huacai Chen <chenhuacai@kernel.org>
Signed-off-by: WANG Xuerui <git@xen0n.name>
Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: devicetree@vger.kernel.org
Cc: linux-acpi@vger.kernel.org
Cc: linux-mips@vger.kernel.org
Cc: loongarch@lists.linux.dev
---
drivers/rtc/Kconfig | 11 ++
drivers/rtc/Makefile | 1 +
drivers/rtc/rtc-ls2x.c | 366 +++++++++++++++++++++++++++++++++++++++++
3 files changed, 378 insertions(+)
create mode 100644 drivers/rtc/rtc-ls2x.c
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index b8de25118ad0..7ec64306ab70 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -1338,6 +1338,17 @@ config RTC_DRV_NTXEC
embedded controller found in certain e-book readers designed by the
original design manufacturer Netronix.
+config RTC_DRV_LS2X
+ tristate "Loongson LS2X RTC"
+ depends on (ACPI || OF) && MACH_LOONGSON64 || COMPILE_TEST
+ select REGMAP_MMIO
+ help
+ If you say yes here you get support for the RTC on the Loongson-2K
+ SoC and LS7A bridge, which first appeared on the Loongson-2H.
+
+ This driver can also be built as a module. If so, the module
+ will be called rtc-ls2x.
+
comment "on-CPU RTC drivers"
config RTC_DRV_ASM9260
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index aab22bc63432..d5a467e9eec8 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -83,6 +83,7 @@ obj-$(CONFIG_RTC_DRV_LOONGSON1) += rtc-ls1x.o
obj-$(CONFIG_RTC_DRV_LP8788) += rtc-lp8788.o
obj-$(CONFIG_RTC_DRV_LPC24XX) += rtc-lpc24xx.o
obj-$(CONFIG_RTC_DRV_LPC32XX) += rtc-lpc32xx.o
+obj-$(CONFIG_RTC_DRV_LS2X) += rtc-ls2x.o
obj-$(CONFIG_RTC_DRV_M41T80) += rtc-m41t80.o
obj-$(CONFIG_RTC_DRV_M41T93) += rtc-m41t93.o
obj-$(CONFIG_RTC_DRV_M41T94) += rtc-m41t94.o
diff --git a/drivers/rtc/rtc-ls2x.c b/drivers/rtc/rtc-ls2x.c
new file mode 100644
index 000000000000..816d1b5ade02
--- /dev/null
+++ b/drivers/rtc/rtc-ls2x.c
@@ -0,0 +1,366 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Loongson-2K/7A RTC driver
+ *
+ * Based on the original out-of-tree Loongson-2H RTC driver for Linux 2.6.32,
+ * by Shaozong Liu <liushaozong@loongson.cn>.
+ *
+ * Maintained out-of-tree by Huacai Chen <chenhuacai@kernel.org>.
+ *
+ * Rewritten for mainline by WANG Xuerui <git@xen0n.name>.
+ */
+
+#include <linux/of.h>
+#include <linux/rtc.h>
+#include <linux/acpi.h>
+#include <linux/regmap.h>
+#include <linux/module.h>
+#include <linux/bitfield.h>
+#include <linux/platform_device.h>
+
+#define TOY_TRIM_REG 0x20
+#define TOY_WRITE0_REG 0x24
+#define TOY_WRITE1_REG 0x28
+#define TOY_READ0_REG 0x2c
+#define TOY_READ1_REG 0x30
+#define TOY_MATCH0_REG 0x34
+#define TOY_MATCH1_REG 0x38
+#define TOY_MATCH2_REG 0x3c
+#define RTC_CTRL_REG 0x40
+#define RTC_TRIM_REG 0x60
+#define RTC_WRITE0_REG 0x64
+#define RTC_READ0_REG 0x68
+#define RTC_MATCH0_REG 0x6c
+#define RTC_MATCH1_REG 0x70
+#define RTC_MATCH2_REG 0x74
+
+#define TOY_MON GENMASK(31, 26)
+#define TOY_DAY GENMASK(25, 21)
+#define TOY_HOUR GENMASK(20, 16)
+#define TOY_MIN GENMASK(15, 10)
+#define TOY_SEC GENMASK(9, 4)
+#define TOY_MSEC GENMASK(3, 0)
+
+#define TOY_MATCH_YEAR GENMASK(31, 26)
+#define TOY_MATCH_MON GENMASK(25, 22)
+#define TOY_MATCH_DAY GENMASK(21, 17)
+#define TOY_MATCH_HOUR GENMASK(16, 12)
+#define TOY_MATCH_MIN GENMASK(11, 6)
+#define TOY_MATCH_SEC GENMASK(5, 0)
+
+/* ACPI and RTC offset */
+#define ACPI_RTC_OFFSET 0x100
+
+/* support rtc wakeup */
+#define ACPI_PM1_STS_REG 0x0c
+#define ACPI_PM1_EN_REG 0x10
+#define RTC_EN BIT(10)
+#define RTC_STS BIT(10)
+
+struct ls2x_rtc_priv {
+ int irq;
+ struct regmap *regmap;
+ spinlock_t rtc_reglock;
+ void __iomem *acpi_base;
+ struct rtc_device *rtcdev;
+};
+
+static const struct regmap_config ls2x_rtc_regmap_config = {
+ .reg_bits = 32,
+ .val_bits = 32,
+ .reg_stride = 4,
+};
+
+struct ls2x_rtc_regs {
+ u32 reg0;
+ u32 reg1;
+};
+
+/* IRQ Handlers */
+static irqreturn_t ls2x_irq_handler(int irq, void *id)
+{
+ struct ls2x_rtc_priv *priv = (struct ls2x_rtc_priv *)id;
+
+ rtc_update_irq(priv->rtcdev, 1, RTC_AF | RTC_IRQF);
+
+ return IRQ_HANDLED;
+}
+
+#if defined(CONFIG_ACPI)
+static u32 ls2x_acpi_fix_handler(void *id)
+{
+ int ret;
+ struct ls2x_rtc_priv *priv = (struct ls2x_rtc_priv *)id;
+
+ spin_lock(&priv->rtc_reglock);
+
+ /* Disable acpi rtc enabled */
+ ret = readl(priv->acpi_base + ACPI_PM1_EN_REG) & ~RTC_EN;
+ writel(ret, priv->acpi_base + ACPI_PM1_EN_REG);
+
+ /* Clear acpi rtc interrupt Status */
+ writel(RTC_STS, priv->acpi_base + ACPI_PM1_STS_REG);
+
+ spin_unlock(&priv->rtc_reglock);
+
+ /*
+ * The TOY_MATCH0_REG should be cleared 0 here,
+ * otherwise the interrupt cannot be cleared.
+ * Because the match condition is still satisfied
+ */
+ ret = regmap_write(priv->regmap, TOY_MATCH0_REG, 0);
+ if (unlikely(ret))
+ return ret;
+
+ rtc_update_irq(priv->rtcdev, 1, RTC_AF | RTC_IRQF);
+
+ return 0;
+}
+#endif
+
+static inline void ls2x_rtc_regs_to_time(struct ls2x_rtc_regs *regs,
+ struct rtc_time *tm)
+{
+ tm->tm_year = regs->reg1;
+ tm->tm_sec = FIELD_GET(TOY_SEC, regs->reg0);
+ tm->tm_min = FIELD_GET(TOY_MIN, regs->reg0);
+ tm->tm_hour = FIELD_GET(TOY_HOUR, regs->reg0);
+ tm->tm_mday = FIELD_GET(TOY_DAY, regs->reg0);
+ tm->tm_mon = FIELD_GET(TOY_MON, regs->reg0) - 1;
+}
+
+static inline void ls2x_rtc_time_to_regs(struct rtc_time *tm,
+ struct ls2x_rtc_regs *regs)
+{
+ regs->reg0 = FIELD_PREP(TOY_SEC, tm->tm_sec);
+ regs->reg0 |= FIELD_PREP(TOY_MIN, tm->tm_min);
+ regs->reg0 |= FIELD_PREP(TOY_HOUR, tm->tm_hour);
+ regs->reg0 |= FIELD_PREP(TOY_DAY, tm->tm_mday);
+ regs->reg0 |= FIELD_PREP(TOY_MON, tm->tm_mon + 1);
+ regs->reg1 = tm->tm_year;
+}
+
+static inline void ls2x_rtc_alarm_regs_to_time(struct ls2x_rtc_regs *regs,
+ struct rtc_time *tm)
+{
+ tm->tm_sec = FIELD_GET(TOY_MATCH_SEC, regs->reg0);
+ tm->tm_min = FIELD_GET(TOY_MATCH_MIN, regs->reg0);
+ tm->tm_hour = FIELD_GET(TOY_MATCH_HOUR, regs->reg0);
+ tm->tm_mday = FIELD_GET(TOY_MATCH_DAY, regs->reg0);
+ tm->tm_mon = FIELD_GET(TOY_MATCH_MON, regs->reg0) - 1;
+ /*
+ * The rtc SYS_TOYMATCH0/YEAR bit field is only 6 bits,
+ * so it means 63 years at most. Therefore, The RTC alarm
+ * years can be set from 1900 to 1963.
+ * This causes the initialization of alarm fail during
+ * call __rtc_read_alarm. We add 80 years offset to
+ * ls2x_rtc_read_alarm. After adding the offset,
+ * the RTC alarm clock can be set from 1980 to 2043.
+ */
+ tm->tm_year = FIELD_GET(TOY_MATCH_YEAR, regs->reg0) + 80;
+}
+
+static inline void ls2x_rtc_time_to_alarm_regs(struct rtc_time *tm,
+ struct ls2x_rtc_regs *regs)
+{
+ regs->reg0 = FIELD_PREP(TOY_MATCH_SEC, tm->tm_sec);
+ regs->reg0 |= FIELD_PREP(TOY_MATCH_MIN, tm->tm_min);
+ regs->reg0 |= FIELD_PREP(TOY_MATCH_HOUR, tm->tm_hour);
+ regs->reg0 |= FIELD_PREP(TOY_MATCH_DAY, tm->tm_mday);
+ regs->reg0 |= FIELD_PREP(TOY_MATCH_MON, tm->tm_mon + 1);
+ regs->reg0 |= FIELD_PREP(TOY_MATCH_YEAR, tm->tm_year);
+}
+
+static int ls2x_rtc_read_time(struct device *dev, struct rtc_time *tm)
+{
+ int ret;
+ struct ls2x_rtc_regs regs;
+ struct ls2x_rtc_priv *priv = dev_get_drvdata(dev);
+
+ ret = regmap_read(priv->regmap, TOY_READ1_REG, ®s.reg1);
+ if (unlikely(ret))
+ return ret;
+
+ ret = regmap_read(priv->regmap, TOY_READ0_REG, ®s.reg0);
+ if (unlikely(ret))
+ return ret;
+
+ ls2x_rtc_regs_to_time(®s, tm);
+
+ return 0;
+}
+
+static int ls2x_rtc_set_time(struct device *dev, struct rtc_time *tm)
+{
+ int ret;
+ struct ls2x_rtc_regs regs;
+ struct ls2x_rtc_priv *priv = dev_get_drvdata(dev);
+
+ ls2x_rtc_time_to_regs(tm, ®s);
+
+ ret = regmap_write(priv->regmap, TOY_WRITE0_REG, regs.reg0);
+ if (unlikely(ret))
+ return ret;
+
+ return regmap_write(priv->regmap, TOY_WRITE1_REG, regs.reg1);
+}
+
+static int ls2x_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
+{
+ int ret;
+ struct ls2x_rtc_regs regs;
+ struct ls2x_rtc_priv *priv = dev_get_drvdata(dev);
+
+ ret = regmap_read(priv->regmap, TOY_MATCH0_REG, ®s.reg0);
+ if (unlikely(ret))
+ return ret;
+
+ ls2x_rtc_alarm_regs_to_time(®s, &alrm->time);
+
+#if defined(CONFIG_ACPI)
+ ret = readl(priv->acpi_base + ACPI_PM1_EN_REG);
+ alrm->enabled = !!(ret & RTC_EN);
+#endif
+
+ return 0;
+}
+
+static int ls2x_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled)
+{
+#if defined(CONFIG_ACPI)
+ u32 val;
+ struct ls2x_rtc_priv *priv = dev_get_drvdata(dev);
+
+ /* Enalbe ACPI rtc wakeup */
+ spin_lock(&priv->rtc_reglock);
+ val = readl(priv->acpi_base + ACPI_PM1_EN_REG);
+ if (enabled)
+ val |= RTC_EN;
+ else
+ val &= ~RTC_EN;
+
+ writel(val, priv->acpi_base + ACPI_PM1_EN_REG);
+ spin_unlock(&priv->rtc_reglock);
+#endif
+ return 0;
+}
+
+static int ls2x_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
+{
+ int ret;
+ struct ls2x_rtc_regs regs;
+ struct ls2x_rtc_priv *priv = dev_get_drvdata(dev);
+
+ ls2x_rtc_time_to_alarm_regs(&alrm->time, ®s);
+
+ ret = regmap_write(priv->regmap, TOY_MATCH0_REG, regs.reg0);
+ if (unlikely(ret))
+ return ret;
+
+ return ls2x_rtc_alarm_irq_enable(dev, alrm->enabled);
+}
+
+static struct rtc_class_ops ls2x_rtc_ops = {
+ .read_time = ls2x_rtc_read_time,
+ .set_time = ls2x_rtc_set_time,
+ .read_alarm = ls2x_rtc_read_alarm,
+ .set_alarm = ls2x_rtc_set_alarm,
+ .alarm_irq_enable = ls2x_rtc_alarm_irq_enable,
+};
+
+static int ls2x_rtc_probe(struct platform_device *pdev)
+{
+ int ret;
+ void __iomem *regs;
+ struct ls2x_rtc_priv *priv;
+ struct device *dev = &pdev->dev;
+
+ priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
+ if (unlikely(!priv))
+ return -ENOMEM;
+
+ spin_lock_init(&priv->rtc_reglock);
+
+ priv->irq = platform_get_irq(pdev, 0);
+ if (priv->irq < 0)
+ return priv->irq;
+
+ platform_set_drvdata(pdev, priv);
+
+ regs = devm_platform_ioremap_resource(pdev, 0);
+ if (IS_ERR(regs))
+ return PTR_ERR(regs);
+
+ priv->regmap = devm_regmap_init_mmio(dev, regs,
+ &ls2x_rtc_regmap_config);
+ if (IS_ERR(priv->regmap))
+ return PTR_ERR(priv->regmap);
+
+ priv->rtcdev = devm_rtc_allocate_device(dev);
+ if (IS_ERR(priv->rtcdev))
+ return PTR_ERR(priv->rtcdev);
+
+ /* Due to hardware erratum, all years multiple of 4 are considered
+ * leap year, so only years 2000 through 2099 are usable.
+ *
+ * Previous out-of-tree versions of this driver wrote tm_year directly
+ * into the year register, so epoch 2000 must be used to preserve
+ * semantics on shipped systems.
+ */
+ priv->rtcdev->range_min = RTC_TIMESTAMP_BEGIN_2000;
+ priv->rtcdev->range_max = RTC_TIMESTAMP_END_2099;
+ priv->rtcdev->ops = &ls2x_rtc_ops;
+ clear_bit(RTC_FEATURE_UPDATE_INTERRUPT, priv->rtcdev->features);
+
+#ifdef CONFIG_ACPI
+ priv->acpi_base = regs - ACPI_RTC_OFFSET;
+ acpi_install_fixed_event_handler(ACPI_EVENT_RTC,
+ ls2x_acpi_fix_handler, priv);
+#endif
+
+ ret = devm_request_threaded_irq(dev, priv->irq, NULL,
+ ls2x_irq_handler,
+ IRQF_TRIGGER_RISING | IRQF_ONESHOT,
+ "ls2x-alarm", priv);
+ if (unlikely(ret))
+ return ret;
+
+ if (!device_can_wakeup(&pdev->dev))
+ device_init_wakeup(dev, 1);
+
+ return devm_rtc_register_device(priv->rtcdev);
+}
+
+#ifdef CONFIG_OF
+static const struct of_device_id ls2x_rtc_of_match[] = {
+ { .compatible = "loongson,ls2x-rtc" },
+ { /* sentinel */ },
+};
+MODULE_DEVICE_TABLE(of, ls2x_rtc_of_match);
+#endif
+
+#ifdef CONFIG_ACPI
+static const struct acpi_device_id ls2x_rtc_acpi_match[] = {
+ {"LOON0001"},
+ {}
+};
+MODULE_DEVICE_TABLE(acpi, ls2x_rtc_acpi_match);
+#endif
+
+static struct platform_driver ls2x_rtc_driver = {
+ .probe = ls2x_rtc_probe,
+ .driver = {
+ .name = "ls2x-rtc",
+ .of_match_table = of_match_ptr(ls2x_rtc_of_match),
+ .acpi_match_table = ACPI_PTR(ls2x_rtc_acpi_match),
+ },
+};
+
+module_platform_driver(ls2x_rtc_driver);
+
+MODULE_DESCRIPTION("LS2X RTC driver");
+MODULE_AUTHOR("WANG Xuerui");
+MODULE_AUTHOR("Huacai Chen");
+MODULE_AUTHOR("Binbin Zhou");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:ls2x-rtc");
--
2.31.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 2/7] LoongArch: Enable LS2X RTC in loongson3_defconfig
2022-09-03 9:34 [PATCH 0/7] rtc: ls2x: Add support for the Loongson-2K/LS7A RTC Binbin Zhou
2022-09-03 9:34 ` [PATCH 1/7] " Binbin Zhou
@ 2022-09-03 9:34 ` Binbin Zhou
2022-09-03 10:45 ` Xi Ruoyao
2022-09-03 9:34 ` [PATCH 3/7] dt-bindings: rtc: Add bindings for LS2X RTC Binbin Zhou
` (5 subsequent siblings)
7 siblings, 1 reply; 11+ messages in thread
From: Binbin Zhou @ 2022-09-03 9:34 UTC (permalink / raw)
To: Alessandro Zummo, linux-rtc
Cc: linux-mips, devicetree, loongarch, linux-acpi, Binbin Zhou,
Huacai Chen, WANG Xuerui
This is now supported, enable for Loongson-3 systems.
Other systems are unaffected.
Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: WANG Xuerui <git@xen0n.name>
Cc: loongarch@lists.linux.dev
---
arch/loongarch/configs/loongson3_defconfig | 1 +
1 file changed, 1 insertion(+)
diff --git a/arch/loongarch/configs/loongson3_defconfig b/arch/loongarch/configs/loongson3_defconfig
index 4083d3051109..b240bc4e2021 100644
--- a/arch/loongarch/configs/loongson3_defconfig
+++ b/arch/loongarch/configs/loongson3_defconfig
@@ -660,6 +660,7 @@ CONFIG_USB_GADGET=y
CONFIG_INFINIBAND=m
CONFIG_RTC_CLASS=y
CONFIG_RTC_DRV_EFI=y
+CONFIG_RTC_DRV_LS2X=y
CONFIG_DMADEVICES=y
CONFIG_UIO=m
CONFIG_UIO_PDRV_GENIRQ=m
--
2.31.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 3/7] dt-bindings: rtc: Add bindings for LS2X RTC
2022-09-03 9:34 [PATCH 0/7] rtc: ls2x: Add support for the Loongson-2K/LS7A RTC Binbin Zhou
2022-09-03 9:34 ` [PATCH 1/7] " Binbin Zhou
2022-09-03 9:34 ` [PATCH 2/7] LoongArch: Enable LS2X RTC in loongson3_defconfig Binbin Zhou
@ 2022-09-03 9:34 ` Binbin Zhou
2022-09-03 9:34 ` [PATCH 4/7] MIPS: Loongson64: DTS: Add RTC support to LS7A Binbin Zhou
` (4 subsequent siblings)
7 siblings, 0 replies; 11+ messages in thread
From: Binbin Zhou @ 2022-09-03 9:34 UTC (permalink / raw)
To: Alessandro Zummo, linux-rtc
Cc: linux-mips, devicetree, loongarch, linux-acpi, WANG Xuerui,
Binbin Zhou, Rob Herring, Rob Herring, Huacai Chen
From: WANG Xuerui <git@xen0n.name>
Document the binding for the LS2X RTC block found on the Loongson-2K SoC
and the LS7A bridge, originally appearing on the Loongson-2H.
Signed-off-by: WANG Xuerui <git@xen0n.name>
Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
Acked-by: Rob Herring <robh@kernel.org>
Cc: Rob Herring <robh+dt@kernel.org>
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: devicetree@vger.kernel.org
Cc: linux-mips@vger.kernel.org
Cc: loongarch@lists.linux.dev
---
Documentation/devicetree/bindings/rtc/trivial-rtc.yaml | 2 ++
1 file changed, 2 insertions(+)
diff --git a/Documentation/devicetree/bindings/rtc/trivial-rtc.yaml b/Documentation/devicetree/bindings/rtc/trivial-rtc.yaml
index d9fc120c61cc..4cfb289b5461 100644
--- a/Documentation/devicetree/bindings/rtc/trivial-rtc.yaml
+++ b/Documentation/devicetree/bindings/rtc/trivial-rtc.yaml
@@ -47,6 +47,8 @@ properties:
- isil,isl1218
# Intersil ISL12022 Real-time Clock
- isil,isl12022
+ # Loongson LS2X RTC
+ - loongson,ls2x-rtc
# Real Time Clock Module with I2C-Bus
- microcrystal,rv3028
# Real Time Clock Module with I2C-Bus
--
2.31.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 4/7] MIPS: Loongson64: DTS: Add RTC support to LS7A
2022-09-03 9:34 [PATCH 0/7] rtc: ls2x: Add support for the Loongson-2K/LS7A RTC Binbin Zhou
` (2 preceding siblings ...)
2022-09-03 9:34 ` [PATCH 3/7] dt-bindings: rtc: Add bindings for LS2X RTC Binbin Zhou
@ 2022-09-03 9:34 ` Binbin Zhou
2022-09-03 9:34 ` [PATCH 5/7] MIPS: Loongson: Enable LS2X RTC in loongson3_defconfig Binbin Zhou
` (3 subsequent siblings)
7 siblings, 0 replies; 11+ messages in thread
From: Binbin Zhou @ 2022-09-03 9:34 UTC (permalink / raw)
To: Alessandro Zummo, linux-rtc
Cc: linux-mips, devicetree, loongarch, linux-acpi, WANG Xuerui,
Binbin Zhou, Jiaxun Yang, Rob Herring, Thomas Bogendoerfer,
Qing Zhang, Tiezhu Yang, zhaoxiao
From: WANG Xuerui <git@xen0n.name>
The LS7A RTC module is now supported, enable it.
Signed-off-by: WANG Xuerui <git@xen0n.name>
Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
Acked-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
Cc: Rob Herring <robh+dt@kernel.org>
Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Cc: Qing Zhang <zhangqing@loongson.cn>
Cc: Tiezhu Yang <yangtiezhu@loongson.cn>
Cc: zhaoxiao <zhaoxiao@uniontech.com>
Cc: linux-mips@vger.kernel.org
---
arch/mips/boot/dts/loongson/ls7a-pch.dtsi | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/arch/mips/boot/dts/loongson/ls7a-pch.dtsi b/arch/mips/boot/dts/loongson/ls7a-pch.dtsi
index 2f45fce2cdc4..82035de4774f 100644
--- a/arch/mips/boot/dts/loongson/ls7a-pch.dtsi
+++ b/arch/mips/boot/dts/loongson/ls7a-pch.dtsi
@@ -19,6 +19,11 @@ pic: interrupt-controller@10000000 {
#interrupt-cells = <2>;
};
+ rtc0: rtc@100d0100 {
+ compatible = "loongson,ls2x-rtc";
+ reg = <0 0x100d0100 0 0x78>;
+ };
+
ls7a_uart0: serial@10080000 {
compatible = "ns16550a";
reg = <0 0x10080000 0 0x100>;
--
2.31.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 5/7] MIPS: Loongson: Enable LS2X RTC in loongson3_defconfig
2022-09-03 9:34 [PATCH 0/7] rtc: ls2x: Add support for the Loongson-2K/LS7A RTC Binbin Zhou
` (3 preceding siblings ...)
2022-09-03 9:34 ` [PATCH 4/7] MIPS: Loongson64: DTS: Add RTC support to LS7A Binbin Zhou
@ 2022-09-03 9:34 ` Binbin Zhou
2022-09-03 9:35 ` [PATCH 6/7] MIPS: Loongson64: DTS: Add RTC support to Loongson-2K Binbin Zhou
` (2 subsequent siblings)
7 siblings, 0 replies; 11+ messages in thread
From: Binbin Zhou @ 2022-09-03 9:34 UTC (permalink / raw)
To: Alessandro Zummo, linux-rtc
Cc: linux-mips, devicetree, loongarch, linux-acpi, WANG Xuerui,
Binbin Zhou, Thomas Bogendoerfer, Huacai Chen, Tiezhu Yang,
Youling Tang, Qing Zhang
From: WANG Xuerui <git@xen0n.name>
This is now supported, enable for Loongson-3 systems.
Other systems are unaffected.
Signed-off-by: WANG Xuerui <git@xen0n.name>
Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: Tiezhu Yang <yangtiezhu@loongson.cn>
Cc: Youling Tang <tangyouling@loongson.cn>
Cc: Qing Zhang <zhangqing@loongson.cn>
Cc: linux-mips@vger.kernel.org
---
arch/mips/configs/loongson3_defconfig | 1 +
1 file changed, 1 insertion(+)
diff --git a/arch/mips/configs/loongson3_defconfig b/arch/mips/configs/loongson3_defconfig
index 25ecd15bc952..166c9775de75 100644
--- a/arch/mips/configs/loongson3_defconfig
+++ b/arch/mips/configs/loongson3_defconfig
@@ -321,6 +321,7 @@ CONFIG_USB_SERIAL_OPTION=m
CONFIG_RTC_CLASS=y
CONFIG_RTC_DRV_CMOS=y
CONFIG_RTC_DRV_GOLDFISH=y
+CONFIG_RTC_DRV_LS2X=y
CONFIG_DMADEVICES=y
CONFIG_VIRTIO_PCI=y
CONFIG_VIRTIO_BALLOON=m
--
2.31.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 6/7] MIPS: Loongson64: DTS: Add RTC support to Loongson-2K
2022-09-03 9:34 [PATCH 0/7] rtc: ls2x: Add support for the Loongson-2K/LS7A RTC Binbin Zhou
` (4 preceding siblings ...)
2022-09-03 9:34 ` [PATCH 5/7] MIPS: Loongson: Enable LS2X RTC in loongson3_defconfig Binbin Zhou
@ 2022-09-03 9:35 ` Binbin Zhou
2022-09-03 9:35 ` [PATCH 7/7] MIPS: Loongson: Enable LS2X RTC in loongson2k_defconfig Binbin Zhou
2022-09-03 14:15 ` [PATCH 0/7] rtc: ls2x: Add support for the Loongson-2K/LS7A RTC Huacai Chen
7 siblings, 0 replies; 11+ messages in thread
From: Binbin Zhou @ 2022-09-03 9:35 UTC (permalink / raw)
To: Alessandro Zummo, linux-rtc
Cc: linux-mips, devicetree, loongarch, linux-acpi, WANG Xuerui,
Binbin Zhou, Jiaxun Yang, Rob Herring, Thomas Bogendoerfer,
Huacai Chen, Qing Zhang, Tiezhu Yang, zhaoxiao
From: WANG Xuerui <git@xen0n.name>
The Loongson-2K RTC module is now supported, enable it.
The MMIO address is unclear from the Loongson 2K1000 user manual, I took
it from Loongson's out-of-tree fork of Linux 4.19.
Signed-off-by: WANG Xuerui <git@xen0n.name>
Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
Cc: Jiaxun Yang <jiaxun.yang@flygoat.com>
Cc: Rob Herring <robh+dt@kernel.org>
Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: Qing Zhang <zhangqing@loongson.cn>
Cc: Tiezhu Yang <yangtiezhu@loongson.cn>
Cc: zhaoxiao <zhaoxiao@uniontech.com>
Cc: devicetree@vger.kernel.org
Cc: linux-mips@vger.kernel.org
---
arch/mips/boot/dts/loongson/loongson64-2k1000.dtsi | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/arch/mips/boot/dts/loongson/loongson64-2k1000.dtsi b/arch/mips/boot/dts/loongson/loongson64-2k1000.dtsi
index 8143a61111e3..811a5ab753a2 100644
--- a/arch/mips/boot/dts/loongson/loongson64-2k1000.dtsi
+++ b/arch/mips/boot/dts/loongson/loongson64-2k1000.dtsi
@@ -57,6 +57,11 @@ pm: reset-controller@1fe07000 {
reg = <0 0x1fe07000 0 0x422>;
};
+ rtc0: rtc@1fe07800 {
+ compatible = "loongson,ls2x-rtc";
+ reg = <0 0x1fe07800 0 0x78>;
+ };
+
liointc0: interrupt-controller@1fe11400 {
compatible = "loongson,liointc-2.0";
reg = <0 0x1fe11400 0 0x40>,
--
2.31.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 7/7] MIPS: Loongson: Enable LS2X RTC in loongson2k_defconfig
2022-09-03 9:34 [PATCH 0/7] rtc: ls2x: Add support for the Loongson-2K/LS7A RTC Binbin Zhou
` (5 preceding siblings ...)
2022-09-03 9:35 ` [PATCH 6/7] MIPS: Loongson64: DTS: Add RTC support to Loongson-2K Binbin Zhou
@ 2022-09-03 9:35 ` Binbin Zhou
2022-09-03 14:15 ` [PATCH 0/7] rtc: ls2x: Add support for the Loongson-2K/LS7A RTC Huacai Chen
7 siblings, 0 replies; 11+ messages in thread
From: Binbin Zhou @ 2022-09-03 9:35 UTC (permalink / raw)
To: Alessandro Zummo, linux-rtc
Cc: linux-mips, devicetree, loongarch, linux-acpi, WANG Xuerui,
Binbin Zhou, Jiaxun Yang, Huacai Chen, Tiezhu Yang, Qing Zhang
From: WANG Xuerui <git@xen0n.name>
This is now supported, enable for Loongson-2K systems.
Other systems are unaffected.
Signed-off-by: WANG Xuerui <git@xen0n.name>
Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
Cc: Jiaxun Yang <jiaxun.yang@flygoat.com>
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: Tiezhu Yang <yangtiezhu@loongson.cn>
Cc: Qing Zhang <zhangqing@loongson.cn>
Cc: linux-mips@vger.kernel.org
---
arch/mips/configs/loongson2k_defconfig | 1 +
1 file changed, 1 insertion(+)
diff --git a/arch/mips/configs/loongson2k_defconfig b/arch/mips/configs/loongson2k_defconfig
index e948ca487e2d..e15f34857956 100644
--- a/arch/mips/configs/loongson2k_defconfig
+++ b/arch/mips/configs/loongson2k_defconfig
@@ -280,6 +280,7 @@ CONFIG_USB_SERIAL=m
CONFIG_USB_SERIAL_OPTION=m
CONFIG_RTC_CLASS=y
CONFIG_RTC_DRV_CMOS=y
+CONFIG_RTC_DRV_LS2X=y
CONFIG_DMADEVICES=y
# CONFIG_CPU_HWMON is not set
CONFIG_PM_DEVFREQ=y
--
2.31.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH 2/7] LoongArch: Enable LS2X RTC in loongson3_defconfig
2022-09-03 9:34 ` [PATCH 2/7] LoongArch: Enable LS2X RTC in loongson3_defconfig Binbin Zhou
@ 2022-09-03 10:45 ` Xi Ruoyao
2022-09-03 14:19 ` Huacai Chen
0 siblings, 1 reply; 11+ messages in thread
From: Xi Ruoyao @ 2022-09-03 10:45 UTC (permalink / raw)
To: Binbin Zhou, Alessandro Zummo, linux-rtc
Cc: linux-mips, devicetree, loongarch, linux-acpi, Huacai Chen,
WANG Xuerui
On Sat, 2022-09-03 at 17:34 +0800, Binbin Zhou wrote:
> This is now supported, enable for Loongson-3 systems.
> Other systems are unaffected.
>
> Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
> Cc: Huacai Chen <chenhuacai@kernel.org>
> Cc: WANG Xuerui <git@xen0n.name>
> Cc: loongarch@lists.linux.dev
> ---
> arch/loongarch/configs/loongson3_defconfig | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/arch/loongarch/configs/loongson3_defconfig
> b/arch/loongarch/configs/loongson3_defconfig
> index 4083d3051109..b240bc4e2021 100644
> --- a/arch/loongarch/configs/loongson3_defconfig
> +++ b/arch/loongarch/configs/loongson3_defconfig
> @@ -660,6 +660,7 @@ CONFIG_USB_GADGET=y
> CONFIG_INFINIBAND=m
> CONFIG_RTC_CLASS=y
> CONFIG_RTC_DRV_EFI=y
> +CONFIG_RTC_DRV_LS2X=y
We already have RTC_DRV_EFI=y, IIUC this means we leave LS7A RTC for the
firmware to drive and operate it through EFI service. So is this really
needed for LoongArch systems? And if we enable both RTC_DRV_EFI and
RTC_DRV_LS2X, will some bad thing (a conflict) happen?
--
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 0/7] rtc: ls2x: Add support for the Loongson-2K/LS7A RTC
2022-09-03 9:34 [PATCH 0/7] rtc: ls2x: Add support for the Loongson-2K/LS7A RTC Binbin Zhou
` (6 preceding siblings ...)
2022-09-03 9:35 ` [PATCH 7/7] MIPS: Loongson: Enable LS2X RTC in loongson2k_defconfig Binbin Zhou
@ 2022-09-03 14:15 ` Huacai Chen
7 siblings, 0 replies; 11+ messages in thread
From: Huacai Chen @ 2022-09-03 14:15 UTC (permalink / raw)
To: Binbin Zhou
Cc: Alessandro Zummo, linux-rtc, open list:MIPS, devicetree,
loongarch, ACPI Devel Maling List, Qing Zhang
Hi, Binbin,
On Sat, Sep 3, 2022 at 5:35 PM Binbin Zhou <zhoubinbin@loongson.cn> wrote:
>
> Hi all:
>
> The initial DT-base ls2x rtc driver was written by Wang Xuerui, he has
> released five versions of patchset before, and all related mail records
> are shown below if you are interested:
>
> https://lore.kernel.org/all/?q=ls2x-rtc
>
> In this series of patches, based on the code above, I have added the
> following support:
>
> 1. Add ACPI-related support, as Loongson-3 + LS7A is now ACPI-base
> by default on LoonArch;
> 2. Add rtc alarm/walarm related functions.
>
> Unfortunately, I have only tested the Loongson-3A4000+LS7A1000/LS7A2000
> under LoongArch architecture.
I think Loongson-3A4000 should be Loongson-3A5000 here. And I think
Qing Zhang can help us to test on Loongson-2K platform.
Huacai
>
> NOTE:
> The related functions of rtc alarm/walarm depend on ACPI registers, so rtc
> alarm may not be available on the DT-base environment. Such as Loongson-2k/3
> under MIPS.
>
> Thanks.
>
> Binbin Zhou (2):
> rtc: ls2x: Add support for the Loongson-2K/LS7A RTC
> LoongArch: Enable LS2X RTC in loongson3_defconfig
>
> WANG Xuerui (5):
> dt-bindings: rtc: Add bindings for LS2X RTC
> MIPS: Loongson64: DTS: Add RTC support to LS7A
> MIPS: Loongson: Enable LS2X RTC in loongson3_defconfig
> MIPS: Loongson64: DTS: Add RTC support to Loongson-2K
> MIPS: Loongson: Enable LS2X RTC in loongson2k_defconfig
>
> .../devicetree/bindings/rtc/trivial-rtc.yaml | 2 +
> arch/loongarch/configs/loongson3_defconfig | 1 +
> .../boot/dts/loongson/loongson64-2k1000.dtsi | 5 +
> arch/mips/boot/dts/loongson/ls7a-pch.dtsi | 5 +
> arch/mips/configs/loongson2k_defconfig | 1 +
> arch/mips/configs/loongson3_defconfig | 1 +
> drivers/rtc/Kconfig | 11 +
> drivers/rtc/Makefile | 1 +
> drivers/rtc/rtc-ls2x.c | 366 ++++++++++++++++++
> 9 files changed, 393 insertions(+)
> create mode 100644 drivers/rtc/rtc-ls2x.c
>
> --
> 2.31.1
>
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 2/7] LoongArch: Enable LS2X RTC in loongson3_defconfig
2022-09-03 10:45 ` Xi Ruoyao
@ 2022-09-03 14:19 ` Huacai Chen
0 siblings, 0 replies; 11+ messages in thread
From: Huacai Chen @ 2022-09-03 14:19 UTC (permalink / raw)
To: Xi Ruoyao
Cc: Binbin Zhou, Alessandro Zummo, linux-rtc, open list:MIPS,
devicetree, loongarch, ACPI Devel Maling List, WANG Xuerui
Hi, Ruoyao,
On Sat, Sep 3, 2022 at 6:45 PM Xi Ruoyao <xry111@xry111.site> wrote:
>
> On Sat, 2022-09-03 at 17:34 +0800, Binbin Zhou wrote:
> > This is now supported, enable for Loongson-3 systems.
> > Other systems are unaffected.
> >
> > Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
> > Cc: Huacai Chen <chenhuacai@kernel.org>
> > Cc: WANG Xuerui <git@xen0n.name>
> > Cc: loongarch@lists.linux.dev
> > ---
> > arch/loongarch/configs/loongson3_defconfig | 1 +
> > 1 file changed, 1 insertion(+)
> >
> > diff --git a/arch/loongarch/configs/loongson3_defconfig
> > b/arch/loongarch/configs/loongson3_defconfig
> > index 4083d3051109..b240bc4e2021 100644
> > --- a/arch/loongarch/configs/loongson3_defconfig
> > +++ b/arch/loongarch/configs/loongson3_defconfig
> > @@ -660,6 +660,7 @@ CONFIG_USB_GADGET=y
> > CONFIG_INFINIBAND=m
> > CONFIG_RTC_CLASS=y
> > CONFIG_RTC_DRV_EFI=y
> > +CONFIG_RTC_DRV_LS2X=y
>
> We already have RTC_DRV_EFI=y, IIUC this means we leave LS7A RTC for the
> firmware to drive and operate it through EFI service. So is this really
> needed for LoongArch systems? And if we enable both RTC_DRV_EFI and
> RTC_DRV_LS2X, will some bad thing (a conflict) happen?
Don't worry, please. EFI RTC depends on EFI runtime, so we need an
available RTC if EFI runtime is disabled (by command line or any other
reasons). On the other hand, multi RTCs can perfectly co-exist, they
will be rtc0 and rtc1 under sysfs and rtc0 is the default one.
Huacai
>
> --
> Xi Ruoyao <xry111@xry111.site>
> School of Aerospace Science and Technology, Xidian University
>
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2022-09-03 14:20 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-03 9:34 [PATCH 0/7] rtc: ls2x: Add support for the Loongson-2K/LS7A RTC Binbin Zhou
2022-09-03 9:34 ` [PATCH 1/7] " Binbin Zhou
2022-09-03 9:34 ` [PATCH 2/7] LoongArch: Enable LS2X RTC in loongson3_defconfig Binbin Zhou
2022-09-03 10:45 ` Xi Ruoyao
2022-09-03 14:19 ` Huacai Chen
2022-09-03 9:34 ` [PATCH 3/7] dt-bindings: rtc: Add bindings for LS2X RTC Binbin Zhou
2022-09-03 9:34 ` [PATCH 4/7] MIPS: Loongson64: DTS: Add RTC support to LS7A Binbin Zhou
2022-09-03 9:34 ` [PATCH 5/7] MIPS: Loongson: Enable LS2X RTC in loongson3_defconfig Binbin Zhou
2022-09-03 9:35 ` [PATCH 6/7] MIPS: Loongson64: DTS: Add RTC support to Loongson-2K Binbin Zhou
2022-09-03 9:35 ` [PATCH 7/7] MIPS: Loongson: Enable LS2X RTC in loongson2k_defconfig Binbin Zhou
2022-09-03 14:15 ` [PATCH 0/7] rtc: ls2x: Add support for the Loongson-2K/LS7A RTC Huacai Chen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).