* [PATCH v1 0/2] RTC: Add Loongson-2K0300 support
@ 2025-12-23 6:42 Binbin Zhou
2025-12-23 6:42 ` [PATCH v1 1/2] dt-binding: rtc: loongson: Document Loongson-2K0300 compatible Binbin Zhou
` (2 more replies)
0 siblings, 3 replies; 9+ messages in thread
From: Binbin Zhou @ 2025-12-23 6:42 UTC (permalink / raw)
To: Binbin Zhou, Huacai Chen, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Alexandre Belloni, linux-rtc
Cc: Xiaochuang Mao, Huacai Chen, Xuerui Wang, loongarch, devicetree,
linux-mips, Keguang Zhang, Binbin Zhou
Hi all:
This patch set introduces the Loongson-2K0300 RTC, which has a similar
hardware design to the Loongson-1B, but without the alarm feature.
To Keguang:
Would you have time to test the driver on a Loongson-1?
Thanks.
Binbin
Binbin Zhou (2):
dt-binding: rtc: loongson: Document Loongson-2K0300 compatible
rtc: loongson: Add Loongson-2K0300 support
.../devicetree/bindings/rtc/loongson,rtc.yaml | 13 ++++
drivers/rtc/rtc-loongson.c | 65 +++++++++++++------
2 files changed, 57 insertions(+), 21 deletions(-)
base-commit: 16bd954c93360145bc77cc601e350913fc28182d
--
2.47.3
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v1 1/2] dt-binding: rtc: loongson: Document Loongson-2K0300 compatible
2025-12-23 6:42 [PATCH v1 0/2] RTC: Add Loongson-2K0300 support Binbin Zhou
@ 2025-12-23 6:42 ` Binbin Zhou
2025-12-30 2:15 ` Rob Herring
2025-12-23 6:42 ` [PATCH v1 2/2] rtc: loongson: Add Loongson-2K0300 support Binbin Zhou
2025-12-26 10:03 ` [PATCH v1 0/2] RTC: " Keguang Zhang
2 siblings, 1 reply; 9+ messages in thread
From: Binbin Zhou @ 2025-12-23 6:42 UTC (permalink / raw)
To: Binbin Zhou, Huacai Chen, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Alexandre Belloni, linux-rtc
Cc: Xiaochuang Mao, Huacai Chen, Xuerui Wang, loongarch, devicetree,
linux-mips, Keguang Zhang, Binbin Zhou
Add "loongson,ls2k0300-rtc" dedicated compatible to represent the RTC
interface of the Loongson-2K0300 chip.
Its hardware design is similar to that of the Loongson-1B, but it does
not support the alarm feature.
Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
---
.../devicetree/bindings/rtc/loongson,rtc.yaml | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/Documentation/devicetree/bindings/rtc/loongson,rtc.yaml b/Documentation/devicetree/bindings/rtc/loongson,rtc.yaml
index f89c1f660aee..aac91c79ffdb 100644
--- a/Documentation/devicetree/bindings/rtc/loongson,rtc.yaml
+++ b/Documentation/devicetree/bindings/rtc/loongson,rtc.yaml
@@ -23,6 +23,7 @@ properties:
- loongson,ls1b-rtc
- loongson,ls1c-rtc
- loongson,ls7a-rtc
+ - loongson,ls2k0300-rtc
- loongson,ls2k1000-rtc
- items:
- enum:
@@ -42,6 +43,18 @@ required:
unevaluatedProperties: false
+if:
+ properties:
+ compatible:
+ contains:
+ enum:
+ - loongson,ls1c-rtc
+ - loongson,ls2k0300-rtc
+
+then:
+ properties:
+ interrupts: false
+
examples:
- |
#include <dt-bindings/interrupt-controller/irq.h>
--
2.47.3
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v1 2/2] rtc: loongson: Add Loongson-2K0300 support
2025-12-23 6:42 [PATCH v1 0/2] RTC: Add Loongson-2K0300 support Binbin Zhou
2025-12-23 6:42 ` [PATCH v1 1/2] dt-binding: rtc: loongson: Document Loongson-2K0300 compatible Binbin Zhou
@ 2025-12-23 6:42 ` Binbin Zhou
2025-12-23 8:40 ` Huacai Chen
2025-12-26 10:03 ` [PATCH v1 0/2] RTC: " Keguang Zhang
2 siblings, 1 reply; 9+ messages in thread
From: Binbin Zhou @ 2025-12-23 6:42 UTC (permalink / raw)
To: Binbin Zhou, Huacai Chen, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Alexandre Belloni, linux-rtc
Cc: Xiaochuang Mao, Huacai Chen, Xuerui Wang, loongarch, devicetree,
linux-mips, Keguang Zhang, Binbin Zhou
The Loongson-2K0300's rtc hardware design is similar to that of the
Loongson-1B, but it does not support the alarm feature.
Introduce `LOONGSON_RTC_ALARM_WORKAROUND`, which indicates a chip that
does not support the alarm function, and rewritethe related logic in
`loongson_rtc_alarm_setting()`
Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
---
drivers/rtc/rtc-loongson.c | 65 ++++++++++++++++++++++++++------------
1 file changed, 44 insertions(+), 21 deletions(-)
diff --git a/drivers/rtc/rtc-loongson.c b/drivers/rtc/rtc-loongson.c
index 2ca7ffd5d7a9..6b076bd4e24e 100644
--- a/drivers/rtc/rtc-loongson.c
+++ b/drivers/rtc/rtc-loongson.c
@@ -67,6 +67,7 @@
* Accessing the relevant registers will cause the system to hang.
*/
#define LS1C_RTC_CTRL_WORKAROUND BIT(0)
+#define LOONGSON_RTC_ALARM_WORKAROUND BIT(1)
struct loongson_rtc_config {
u32 pm_offset; /* Offset of PM domain, for RTC alarm wakeup */
@@ -89,7 +90,7 @@ static const struct loongson_rtc_config ls1b_rtc_config = {
static const struct loongson_rtc_config ls1c_rtc_config = {
.pm_offset = 0,
- .flags = LS1C_RTC_CTRL_WORKAROUND,
+ .flags = LS1C_RTC_CTRL_WORKAROUND | LOONGSON_RTC_ALARM_WORKAROUND,
};
static const struct loongson_rtc_config generic_rtc_config = {
@@ -97,6 +98,11 @@ static const struct loongson_rtc_config generic_rtc_config = {
.flags = 0,
};
+static const struct loongson_rtc_config ls2k0300_rtc_config = {
+ .pm_offset = 0x0,
+ .flags = LOONGSON_RTC_ALARM_WORKAROUND,
+};
+
static const struct loongson_rtc_config ls2k1000_rtc_config = {
.pm_offset = 0x800,
.flags = 0,
@@ -299,9 +305,41 @@ static const struct rtc_class_ops loongson_rtc_ops = {
.alarm_irq_enable = loongson_rtc_alarm_irq_enable,
};
+static int loongson_rtc_alarm_setting(struct platform_device *pdev, void __iomem *regs)
+{
+ int ret = 0, alarm_irq;
+ struct device *dev = &pdev->dev;
+ struct loongson_rtc_priv *priv = dev_get_drvdata(dev);
+
+ if (priv->config->flags & LOONGSON_RTC_ALARM_WORKAROUND) {
+ /* Loongson-1C/Loongson-2K0300 RTC does not support alarm */
+ clear_bit(RTC_FEATURE_ALARM, priv->rtcdev->features);
+ return 0;
+ }
+
+ /* Get RTC alarm irq */
+ alarm_irq = platform_get_irq(pdev, 0);
+ if (alarm_irq < 0)
+ return alarm_irq;
+
+ ret = devm_request_irq(dev, alarm_irq, loongson_rtc_isr, 0, "loongson-alarm",
+ priv);
+ if (ret < 0)
+ return ret;
+
+ priv->pm_base = regs - priv->config->pm_offset;
+ device_init_wakeup(dev, true);
+
+ if (has_acpi_companion(dev))
+ acpi_install_fixed_event_handler(ACPI_EVENT_RTC,
+ loongson_rtc_handler, priv);
+
+ return ret;
+}
+
static int loongson_rtc_probe(struct platform_device *pdev)
{
- int ret, alarm_irq;
+ int ret;
void __iomem *regs;
struct loongson_rtc_priv *priv;
struct device *dev = &pdev->dev;
@@ -330,25 +368,9 @@ static int loongson_rtc_probe(struct platform_device *pdev)
return dev_err_probe(dev, PTR_ERR(priv->rtcdev),
"devm_rtc_allocate_device failed\n");
- /* Get RTC alarm irq */
- alarm_irq = platform_get_irq(pdev, 0);
- if (alarm_irq > 0) {
- ret = devm_request_irq(dev, alarm_irq, loongson_rtc_isr,
- 0, "loongson-alarm", priv);
- if (ret < 0)
- return dev_err_probe(dev, ret, "Unable to request irq %d\n",
- alarm_irq);
-
- priv->pm_base = regs - priv->config->pm_offset;
- device_init_wakeup(dev, true);
-
- if (has_acpi_companion(dev))
- acpi_install_fixed_event_handler(ACPI_EVENT_RTC,
- loongson_rtc_handler, priv);
- } else {
- /* Loongson-1C RTC does not support alarm */
- clear_bit(RTC_FEATURE_ALARM, priv->rtcdev->features);
- }
+ ret = loongson_rtc_alarm_setting(pdev, regs);
+ if (ret)
+ return ret;
/* Loongson RTC does not support UIE */
clear_bit(RTC_FEATURE_UPDATE_INTERRUPT, priv->rtcdev->features);
@@ -379,6 +401,7 @@ static const struct of_device_id loongson_rtc_of_match[] = {
{ .compatible = "loongson,ls1b-rtc", .data = &ls1b_rtc_config },
{ .compatible = "loongson,ls1c-rtc", .data = &ls1c_rtc_config },
{ .compatible = "loongson,ls7a-rtc", .data = &generic_rtc_config },
+ { .compatible = "loongson,ls2k0300-rtc", .data = &ls2k0300_rtc_config },
{ .compatible = "loongson,ls2k1000-rtc", .data = &ls2k1000_rtc_config },
{ /* sentinel */ }
};
--
2.47.3
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v1 2/2] rtc: loongson: Add Loongson-2K0300 support
2025-12-23 6:42 ` [PATCH v1 2/2] rtc: loongson: Add Loongson-2K0300 support Binbin Zhou
@ 2025-12-23 8:40 ` Huacai Chen
2025-12-23 9:06 ` Binbin Zhou
0 siblings, 1 reply; 9+ messages in thread
From: Huacai Chen @ 2025-12-23 8:40 UTC (permalink / raw)
To: Binbin Zhou
Cc: Binbin Zhou, Huacai Chen, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Alexandre Belloni, linux-rtc, Xiaochuang Mao,
Xuerui Wang, loongarch, devicetree, linux-mips, Keguang Zhang
Hi, Binbin,
On Tue, Dec 23, 2025 at 2:42 PM Binbin Zhou <zhoubinbin@loongson.cn> wrote:
>
> The Loongson-2K0300's rtc hardware design is similar to that of the
> Loongson-1B, but it does not support the alarm feature.
>
> Introduce `LOONGSON_RTC_ALARM_WORKAROUND`, which indicates a chip that
> does not support the alarm function, and rewritethe related logic in
> `loongson_rtc_alarm_setting()`
>
> Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
> ---
> drivers/rtc/rtc-loongson.c | 65 ++++++++++++++++++++++++++------------
> 1 file changed, 44 insertions(+), 21 deletions(-)
>
> diff --git a/drivers/rtc/rtc-loongson.c b/drivers/rtc/rtc-loongson.c
> index 2ca7ffd5d7a9..6b076bd4e24e 100644
> --- a/drivers/rtc/rtc-loongson.c
> +++ b/drivers/rtc/rtc-loongson.c
> @@ -67,6 +67,7 @@
> * Accessing the relevant registers will cause the system to hang.
> */
> #define LS1C_RTC_CTRL_WORKAROUND BIT(0)
> +#define LOONGSON_RTC_ALARM_WORKAROUND BIT(1)
Can we reuse existing logic, which means "alarm_irq =
platform_get_irq(pdev, 0)" return 0 for LS2K0300?
Huacai
>
> struct loongson_rtc_config {
> u32 pm_offset; /* Offset of PM domain, for RTC alarm wakeup */
> @@ -89,7 +90,7 @@ static const struct loongson_rtc_config ls1b_rtc_config = {
>
> static const struct loongson_rtc_config ls1c_rtc_config = {
> .pm_offset = 0,
> - .flags = LS1C_RTC_CTRL_WORKAROUND,
> + .flags = LS1C_RTC_CTRL_WORKAROUND | LOONGSON_RTC_ALARM_WORKAROUND,
> };
>
> static const struct loongson_rtc_config generic_rtc_config = {
> @@ -97,6 +98,11 @@ static const struct loongson_rtc_config generic_rtc_config = {
> .flags = 0,
> };
>
> +static const struct loongson_rtc_config ls2k0300_rtc_config = {
> + .pm_offset = 0x0,
> + .flags = LOONGSON_RTC_ALARM_WORKAROUND,
> +};
> +
> static const struct loongson_rtc_config ls2k1000_rtc_config = {
> .pm_offset = 0x800,
> .flags = 0,
> @@ -299,9 +305,41 @@ static const struct rtc_class_ops loongson_rtc_ops = {
> .alarm_irq_enable = loongson_rtc_alarm_irq_enable,
> };
>
> +static int loongson_rtc_alarm_setting(struct platform_device *pdev, void __iomem *regs)
> +{
> + int ret = 0, alarm_irq;
> + struct device *dev = &pdev->dev;
> + struct loongson_rtc_priv *priv = dev_get_drvdata(dev);
> +
> + if (priv->config->flags & LOONGSON_RTC_ALARM_WORKAROUND) {
> + /* Loongson-1C/Loongson-2K0300 RTC does not support alarm */
> + clear_bit(RTC_FEATURE_ALARM, priv->rtcdev->features);
> + return 0;
> + }
> +
> + /* Get RTC alarm irq */
> + alarm_irq = platform_get_irq(pdev, 0);
> + if (alarm_irq < 0)
> + return alarm_irq;
> +
> + ret = devm_request_irq(dev, alarm_irq, loongson_rtc_isr, 0, "loongson-alarm",
> + priv);
> + if (ret < 0)
> + return ret;
> +
> + priv->pm_base = regs - priv->config->pm_offset;
> + device_init_wakeup(dev, true);
> +
> + if (has_acpi_companion(dev))
> + acpi_install_fixed_event_handler(ACPI_EVENT_RTC,
> + loongson_rtc_handler, priv);
> +
> + return ret;
> +}
> +
> static int loongson_rtc_probe(struct platform_device *pdev)
> {
> - int ret, alarm_irq;
> + int ret;
> void __iomem *regs;
> struct loongson_rtc_priv *priv;
> struct device *dev = &pdev->dev;
> @@ -330,25 +368,9 @@ static int loongson_rtc_probe(struct platform_device *pdev)
> return dev_err_probe(dev, PTR_ERR(priv->rtcdev),
> "devm_rtc_allocate_device failed\n");
>
> - /* Get RTC alarm irq */
> - alarm_irq = platform_get_irq(pdev, 0);
> - if (alarm_irq > 0) {
> - ret = devm_request_irq(dev, alarm_irq, loongson_rtc_isr,
> - 0, "loongson-alarm", priv);
> - if (ret < 0)
> - return dev_err_probe(dev, ret, "Unable to request irq %d\n",
> - alarm_irq);
> -
> - priv->pm_base = regs - priv->config->pm_offset;
> - device_init_wakeup(dev, true);
> -
> - if (has_acpi_companion(dev))
> - acpi_install_fixed_event_handler(ACPI_EVENT_RTC,
> - loongson_rtc_handler, priv);
> - } else {
> - /* Loongson-1C RTC does not support alarm */
> - clear_bit(RTC_FEATURE_ALARM, priv->rtcdev->features);
> - }
> + ret = loongson_rtc_alarm_setting(pdev, regs);
> + if (ret)
> + return ret;
>
> /* Loongson RTC does not support UIE */
> clear_bit(RTC_FEATURE_UPDATE_INTERRUPT, priv->rtcdev->features);
> @@ -379,6 +401,7 @@ static const struct of_device_id loongson_rtc_of_match[] = {
> { .compatible = "loongson,ls1b-rtc", .data = &ls1b_rtc_config },
> { .compatible = "loongson,ls1c-rtc", .data = &ls1c_rtc_config },
> { .compatible = "loongson,ls7a-rtc", .data = &generic_rtc_config },
> + { .compatible = "loongson,ls2k0300-rtc", .data = &ls2k0300_rtc_config },
> { .compatible = "loongson,ls2k1000-rtc", .data = &ls2k1000_rtc_config },
> { /* sentinel */ }
> };
> --
> 2.47.3
>
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v1 2/2] rtc: loongson: Add Loongson-2K0300 support
2025-12-23 8:40 ` Huacai Chen
@ 2025-12-23 9:06 ` Binbin Zhou
2025-12-23 9:09 ` Huacai Chen
0 siblings, 1 reply; 9+ messages in thread
From: Binbin Zhou @ 2025-12-23 9:06 UTC (permalink / raw)
To: Huacai Chen
Cc: Binbin Zhou, Huacai Chen, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Alexandre Belloni, linux-rtc, Xiaochuang Mao,
Xuerui Wang, loongarch, devicetree, linux-mips, Keguang Zhang
Hi:
On Tue, Dec 23, 2025 at 4:40 PM Huacai Chen <chenhuacai@kernel.org> wrote:
>
> Hi, Binbin,
>
> On Tue, Dec 23, 2025 at 2:42 PM Binbin Zhou <zhoubinbin@loongson.cn> wrote:
> >
> > The Loongson-2K0300's rtc hardware design is similar to that of the
> > Loongson-1B, but it does not support the alarm feature.
> >
> > Introduce `LOONGSON_RTC_ALARM_WORKAROUND`, which indicates a chip that
> > does not support the alarm function, and rewritethe related logic in
> > `loongson_rtc_alarm_setting()`
> >
> > Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
> > ---
> > drivers/rtc/rtc-loongson.c | 65 ++++++++++++++++++++++++++------------
> > 1 file changed, 44 insertions(+), 21 deletions(-)
> >
> > diff --git a/drivers/rtc/rtc-loongson.c b/drivers/rtc/rtc-loongson.c
> > index 2ca7ffd5d7a9..6b076bd4e24e 100644
> > --- a/drivers/rtc/rtc-loongson.c
> > +++ b/drivers/rtc/rtc-loongson.c
> > @@ -67,6 +67,7 @@
> > * Accessing the relevant registers will cause the system to hang.
> > */
> > #define LS1C_RTC_CTRL_WORKAROUND BIT(0)
> > +#define LOONGSON_RTC_ALARM_WORKAROUND BIT(1)
> Can we reuse existing logic, which means "alarm_irq =
> platform_get_irq(pdev, 0)" return 0 for LS2K0300?
First of all, as I understand it, platform_get_irq() doesn't normally
return 0 unless interrupt 0 is configured in the DTS, which doesn't
seem appropriate.
Also, the return value of platform_get_irq() was previously used to
determine if the alarm feature was supported, which is not
particularly accurate. It should be an inherent feature of the chip,
and I think it would be more appropriate to define it in
loongson_rtc_config.
>
> Huacai
>
> >
> > struct loongson_rtc_config {
> > u32 pm_offset; /* Offset of PM domain, for RTC alarm wakeup */
> > @@ -89,7 +90,7 @@ static const struct loongson_rtc_config ls1b_rtc_config = {
> >
> > static const struct loongson_rtc_config ls1c_rtc_config = {
> > .pm_offset = 0,
> > - .flags = LS1C_RTC_CTRL_WORKAROUND,
> > + .flags = LS1C_RTC_CTRL_WORKAROUND | LOONGSON_RTC_ALARM_WORKAROUND,
> > };
> >
> > static const struct loongson_rtc_config generic_rtc_config = {
> > @@ -97,6 +98,11 @@ static const struct loongson_rtc_config generic_rtc_config = {
> > .flags = 0,
> > };
> >
> > +static const struct loongson_rtc_config ls2k0300_rtc_config = {
> > + .pm_offset = 0x0,
> > + .flags = LOONGSON_RTC_ALARM_WORKAROUND,
> > +};
> > +
> > static const struct loongson_rtc_config ls2k1000_rtc_config = {
> > .pm_offset = 0x800,
> > .flags = 0,
> > @@ -299,9 +305,41 @@ static const struct rtc_class_ops loongson_rtc_ops = {
> > .alarm_irq_enable = loongson_rtc_alarm_irq_enable,
> > };
> >
> > +static int loongson_rtc_alarm_setting(struct platform_device *pdev, void __iomem *regs)
> > +{
> > + int ret = 0, alarm_irq;
> > + struct device *dev = &pdev->dev;
> > + struct loongson_rtc_priv *priv = dev_get_drvdata(dev);
> > +
> > + if (priv->config->flags & LOONGSON_RTC_ALARM_WORKAROUND) {
> > + /* Loongson-1C/Loongson-2K0300 RTC does not support alarm */
> > + clear_bit(RTC_FEATURE_ALARM, priv->rtcdev->features);
> > + return 0;
> > + }
> > +
> > + /* Get RTC alarm irq */
> > + alarm_irq = platform_get_irq(pdev, 0);
> > + if (alarm_irq < 0)
> > + return alarm_irq;
> > +
> > + ret = devm_request_irq(dev, alarm_irq, loongson_rtc_isr, 0, "loongson-alarm",
> > + priv);
> > + if (ret < 0)
> > + return ret;
> > +
> > + priv->pm_base = regs - priv->config->pm_offset;
> > + device_init_wakeup(dev, true);
> > +
> > + if (has_acpi_companion(dev))
> > + acpi_install_fixed_event_handler(ACPI_EVENT_RTC,
> > + loongson_rtc_handler, priv);
> > +
> > + return ret;
> > +}
> > +
> > static int loongson_rtc_probe(struct platform_device *pdev)
> > {
> > - int ret, alarm_irq;
> > + int ret;
> > void __iomem *regs;
> > struct loongson_rtc_priv *priv;
> > struct device *dev = &pdev->dev;
> > @@ -330,25 +368,9 @@ static int loongson_rtc_probe(struct platform_device *pdev)
> > return dev_err_probe(dev, PTR_ERR(priv->rtcdev),
> > "devm_rtc_allocate_device failed\n");
> >
> > - /* Get RTC alarm irq */
> > - alarm_irq = platform_get_irq(pdev, 0);
> > - if (alarm_irq > 0) {
> > - ret = devm_request_irq(dev, alarm_irq, loongson_rtc_isr,
> > - 0, "loongson-alarm", priv);
> > - if (ret < 0)
> > - return dev_err_probe(dev, ret, "Unable to request irq %d\n",
> > - alarm_irq);
> > -
> > - priv->pm_base = regs - priv->config->pm_offset;
> > - device_init_wakeup(dev, true);
> > -
> > - if (has_acpi_companion(dev))
> > - acpi_install_fixed_event_handler(ACPI_EVENT_RTC,
> > - loongson_rtc_handler, priv);
> > - } else {
> > - /* Loongson-1C RTC does not support alarm */
> > - clear_bit(RTC_FEATURE_ALARM, priv->rtcdev->features);
> > - }
> > + ret = loongson_rtc_alarm_setting(pdev, regs);
> > + if (ret)
> > + return ret;
> >
> > /* Loongson RTC does not support UIE */
> > clear_bit(RTC_FEATURE_UPDATE_INTERRUPT, priv->rtcdev->features);
> > @@ -379,6 +401,7 @@ static const struct of_device_id loongson_rtc_of_match[] = {
> > { .compatible = "loongson,ls1b-rtc", .data = &ls1b_rtc_config },
> > { .compatible = "loongson,ls1c-rtc", .data = &ls1c_rtc_config },
> > { .compatible = "loongson,ls7a-rtc", .data = &generic_rtc_config },
> > + { .compatible = "loongson,ls2k0300-rtc", .data = &ls2k0300_rtc_config },
> > { .compatible = "loongson,ls2k1000-rtc", .data = &ls2k1000_rtc_config },
> > { /* sentinel */ }
> > };
> > --
> > 2.47.3
> >
> >
--
Thanks.
Binbin
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v1 2/2] rtc: loongson: Add Loongson-2K0300 support
2025-12-23 9:06 ` Binbin Zhou
@ 2025-12-23 9:09 ` Huacai Chen
0 siblings, 0 replies; 9+ messages in thread
From: Huacai Chen @ 2025-12-23 9:09 UTC (permalink / raw)
To: Binbin Zhou
Cc: Binbin Zhou, Huacai Chen, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Alexandre Belloni, linux-rtc, Xiaochuang Mao,
Xuerui Wang, loongarch, devicetree, linux-mips, Keguang Zhang
On Tue, Dec 23, 2025 at 5:06 PM Binbin Zhou <zhoubb.aaron@gmail.com> wrote:
>
> Hi:
>
>
> On Tue, Dec 23, 2025 at 4:40 PM Huacai Chen <chenhuacai@kernel.org> wrote:
> >
> > Hi, Binbin,
> >
> > On Tue, Dec 23, 2025 at 2:42 PM Binbin Zhou <zhoubinbin@loongson.cn> wrote:
> > >
> > > The Loongson-2K0300's rtc hardware design is similar to that of the
> > > Loongson-1B, but it does not support the alarm feature.
> > >
> > > Introduce `LOONGSON_RTC_ALARM_WORKAROUND`, which indicates a chip that
> > > does not support the alarm function, and rewritethe related logic in
> > > `loongson_rtc_alarm_setting()`
> > >
> > > Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
> > > ---
> > > drivers/rtc/rtc-loongson.c | 65 ++++++++++++++++++++++++++------------
> > > 1 file changed, 44 insertions(+), 21 deletions(-)
> > >
> > > diff --git a/drivers/rtc/rtc-loongson.c b/drivers/rtc/rtc-loongson.c
> > > index 2ca7ffd5d7a9..6b076bd4e24e 100644
> > > --- a/drivers/rtc/rtc-loongson.c
> > > +++ b/drivers/rtc/rtc-loongson.c
> > > @@ -67,6 +67,7 @@
> > > * Accessing the relevant registers will cause the system to hang.
> > > */
> > > #define LS1C_RTC_CTRL_WORKAROUND BIT(0)
> > > +#define LOONGSON_RTC_ALARM_WORKAROUND BIT(1)
> > Can we reuse existing logic, which means "alarm_irq =
> > platform_get_irq(pdev, 0)" return 0 for LS2K0300?
>
> First of all, as I understand it, platform_get_irq() doesn't normally
> return 0 unless interrupt 0 is configured in the DTS, which doesn't
> seem appropriate.
>
> Also, the return value of platform_get_irq() was previously used to
> determine if the alarm feature was supported, which is not
> particularly accurate. It should be an inherent feature of the chip,
> and I think it would be more appropriate to define it in
> loongson_rtc_config.
OK, then I think it is better to rename LS1C_RTC_CTRL_WORKAROUND to
LOONGSON_RTC_CTRL_WORKAROUND for consistency.
Huacai
> >
> > Huacai
> >
> > >
> > > struct loongson_rtc_config {
> > > u32 pm_offset; /* Offset of PM domain, for RTC alarm wakeup */
> > > @@ -89,7 +90,7 @@ static const struct loongson_rtc_config ls1b_rtc_config = {
> > >
> > > static const struct loongson_rtc_config ls1c_rtc_config = {
> > > .pm_offset = 0,
> > > - .flags = LS1C_RTC_CTRL_WORKAROUND,
> > > + .flags = LS1C_RTC_CTRL_WORKAROUND | LOONGSON_RTC_ALARM_WORKAROUND,
> > > };
> > >
> > > static const struct loongson_rtc_config generic_rtc_config = {
> > > @@ -97,6 +98,11 @@ static const struct loongson_rtc_config generic_rtc_config = {
> > > .flags = 0,
> > > };
> > >
> > > +static const struct loongson_rtc_config ls2k0300_rtc_config = {
> > > + .pm_offset = 0x0,
> > > + .flags = LOONGSON_RTC_ALARM_WORKAROUND,
> > > +};
> > > +
> > > static const struct loongson_rtc_config ls2k1000_rtc_config = {
> > > .pm_offset = 0x800,
> > > .flags = 0,
> > > @@ -299,9 +305,41 @@ static const struct rtc_class_ops loongson_rtc_ops = {
> > > .alarm_irq_enable = loongson_rtc_alarm_irq_enable,
> > > };
> > >
> > > +static int loongson_rtc_alarm_setting(struct platform_device *pdev, void __iomem *regs)
> > > +{
> > > + int ret = 0, alarm_irq;
> > > + struct device *dev = &pdev->dev;
> > > + struct loongson_rtc_priv *priv = dev_get_drvdata(dev);
> > > +
> > > + if (priv->config->flags & LOONGSON_RTC_ALARM_WORKAROUND) {
> > > + /* Loongson-1C/Loongson-2K0300 RTC does not support alarm */
> > > + clear_bit(RTC_FEATURE_ALARM, priv->rtcdev->features);
> > > + return 0;
> > > + }
> > > +
> > > + /* Get RTC alarm irq */
> > > + alarm_irq = platform_get_irq(pdev, 0);
> > > + if (alarm_irq < 0)
> > > + return alarm_irq;
> > > +
> > > + ret = devm_request_irq(dev, alarm_irq, loongson_rtc_isr, 0, "loongson-alarm",
> > > + priv);
> > > + if (ret < 0)
> > > + return ret;
> > > +
> > > + priv->pm_base = regs - priv->config->pm_offset;
> > > + device_init_wakeup(dev, true);
> > > +
> > > + if (has_acpi_companion(dev))
> > > + acpi_install_fixed_event_handler(ACPI_EVENT_RTC,
> > > + loongson_rtc_handler, priv);
> > > +
> > > + return ret;
> > > +}
> > > +
> > > static int loongson_rtc_probe(struct platform_device *pdev)
> > > {
> > > - int ret, alarm_irq;
> > > + int ret;
> > > void __iomem *regs;
> > > struct loongson_rtc_priv *priv;
> > > struct device *dev = &pdev->dev;
> > > @@ -330,25 +368,9 @@ static int loongson_rtc_probe(struct platform_device *pdev)
> > > return dev_err_probe(dev, PTR_ERR(priv->rtcdev),
> > > "devm_rtc_allocate_device failed\n");
> > >
> > > - /* Get RTC alarm irq */
> > > - alarm_irq = platform_get_irq(pdev, 0);
> > > - if (alarm_irq > 0) {
> > > - ret = devm_request_irq(dev, alarm_irq, loongson_rtc_isr,
> > > - 0, "loongson-alarm", priv);
> > > - if (ret < 0)
> > > - return dev_err_probe(dev, ret, "Unable to request irq %d\n",
> > > - alarm_irq);
> > > -
> > > - priv->pm_base = regs - priv->config->pm_offset;
> > > - device_init_wakeup(dev, true);
> > > -
> > > - if (has_acpi_companion(dev))
> > > - acpi_install_fixed_event_handler(ACPI_EVENT_RTC,
> > > - loongson_rtc_handler, priv);
> > > - } else {
> > > - /* Loongson-1C RTC does not support alarm */
> > > - clear_bit(RTC_FEATURE_ALARM, priv->rtcdev->features);
> > > - }
> > > + ret = loongson_rtc_alarm_setting(pdev, regs);
> > > + if (ret)
> > > + return ret;
> > >
> > > /* Loongson RTC does not support UIE */
> > > clear_bit(RTC_FEATURE_UPDATE_INTERRUPT, priv->rtcdev->features);
> > > @@ -379,6 +401,7 @@ static const struct of_device_id loongson_rtc_of_match[] = {
> > > { .compatible = "loongson,ls1b-rtc", .data = &ls1b_rtc_config },
> > > { .compatible = "loongson,ls1c-rtc", .data = &ls1c_rtc_config },
> > > { .compatible = "loongson,ls7a-rtc", .data = &generic_rtc_config },
> > > + { .compatible = "loongson,ls2k0300-rtc", .data = &ls2k0300_rtc_config },
> > > { .compatible = "loongson,ls2k1000-rtc", .data = &ls2k1000_rtc_config },
> > > { /* sentinel */ }
> > > };
> > > --
> > > 2.47.3
> > >
> > >
>
> --
> Thanks.
> Binbin
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v1 0/2] RTC: Add Loongson-2K0300 support
2025-12-23 6:42 [PATCH v1 0/2] RTC: Add Loongson-2K0300 support Binbin Zhou
2025-12-23 6:42 ` [PATCH v1 1/2] dt-binding: rtc: loongson: Document Loongson-2K0300 compatible Binbin Zhou
2025-12-23 6:42 ` [PATCH v1 2/2] rtc: loongson: Add Loongson-2K0300 support Binbin Zhou
@ 2025-12-26 10:03 ` Keguang Zhang
2 siblings, 0 replies; 9+ messages in thread
From: Keguang Zhang @ 2025-12-26 10:03 UTC (permalink / raw)
To: Binbin Zhou
Cc: Binbin Zhou, Huacai Chen, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Alexandre Belloni, linux-rtc, Xiaochuang Mao,
Huacai Chen, Xuerui Wang, loongarch, devicetree, linux-mips
For the whole series:
Reviewed-by: Keguang Zhang <keguang.zhang@gmail.com>
Tested-by: Keguang Zhang <keguang.zhang@gmail.com> # on LS1B & LS1C
On Tue, Dec 23, 2025 at 2:42 PM Binbin Zhou <zhoubinbin@loongson.cn> wrote:
>
> Hi all:
>
> This patch set introduces the Loongson-2K0300 RTC, which has a similar
> hardware design to the Loongson-1B, but without the alarm feature.
>
> To Keguang:
> Would you have time to test the driver on a Loongson-1?
>
> Thanks.
> Binbin
>
> Binbin Zhou (2):
> dt-binding: rtc: loongson: Document Loongson-2K0300 compatible
> rtc: loongson: Add Loongson-2K0300 support
>
> .../devicetree/bindings/rtc/loongson,rtc.yaml | 13 ++++
> drivers/rtc/rtc-loongson.c | 65 +++++++++++++------
> 2 files changed, 57 insertions(+), 21 deletions(-)
>
>
> base-commit: 16bd954c93360145bc77cc601e350913fc28182d
> --
> 2.47.3
>
--
Best regards,
Keguang Zhang
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v1 1/2] dt-binding: rtc: loongson: Document Loongson-2K0300 compatible
2025-12-23 6:42 ` [PATCH v1 1/2] dt-binding: rtc: loongson: Document Loongson-2K0300 compatible Binbin Zhou
@ 2025-12-30 2:15 ` Rob Herring
2025-12-30 2:31 ` Binbin Zhou
0 siblings, 1 reply; 9+ messages in thread
From: Rob Herring @ 2025-12-30 2:15 UTC (permalink / raw)
To: Binbin Zhou
Cc: Binbin Zhou, Huacai Chen, Krzysztof Kozlowski, Conor Dooley,
Alexandre Belloni, linux-rtc, Xiaochuang Mao, Huacai Chen,
Xuerui Wang, loongarch, devicetree, linux-mips, Keguang Zhang
On Tue, Dec 23, 2025 at 02:42:12PM +0800, Binbin Zhou wrote:
> Add "loongson,ls2k0300-rtc" dedicated compatible to represent the RTC
> interface of the Loongson-2K0300 chip.
>
> Its hardware design is similar to that of the Loongson-1B, but it does
> not support the alarm feature.
>
> Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
> ---
> .../devicetree/bindings/rtc/loongson,rtc.yaml | 13 +++++++++++++
> 1 file changed, 13 insertions(+)
>
> diff --git a/Documentation/devicetree/bindings/rtc/loongson,rtc.yaml b/Documentation/devicetree/bindings/rtc/loongson,rtc.yaml
> index f89c1f660aee..aac91c79ffdb 100644
> --- a/Documentation/devicetree/bindings/rtc/loongson,rtc.yaml
> +++ b/Documentation/devicetree/bindings/rtc/loongson,rtc.yaml
> @@ -23,6 +23,7 @@ properties:
> - loongson,ls1b-rtc
> - loongson,ls1c-rtc
> - loongson,ls7a-rtc
> + - loongson,ls2k0300-rtc
> - loongson,ls2k1000-rtc
> - items:
> - enum:
> @@ -42,6 +43,18 @@ required:
>
> unevaluatedProperties: false
>
> +if:
> + properties:
> + compatible:
> + contains:
> + enum:
> + - loongson,ls1c-rtc
This seems unrelated?
> + - loongson,ls2k0300-rtc
> +
> +then:
> + properties:
> + interrupts: false
> +
> examples:
> - |
> #include <dt-bindings/interrupt-controller/irq.h>
> --
> 2.47.3
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v1 1/2] dt-binding: rtc: loongson: Document Loongson-2K0300 compatible
2025-12-30 2:15 ` Rob Herring
@ 2025-12-30 2:31 ` Binbin Zhou
0 siblings, 0 replies; 9+ messages in thread
From: Binbin Zhou @ 2025-12-30 2:31 UTC (permalink / raw)
To: Rob Herring
Cc: Binbin Zhou, Huacai Chen, Krzysztof Kozlowski, Conor Dooley,
Alexandre Belloni, linux-rtc, Xiaochuang Mao, Huacai Chen,
Xuerui Wang, loongarch, devicetree, linux-mips, Keguang Zhang
Hi Rob:
Thanks for your review.
On Tue, Dec 30, 2025 at 10:15 AM Rob Herring <robh@kernel.org> wrote:
>
> On Tue, Dec 23, 2025 at 02:42:12PM +0800, Binbin Zhou wrote:
> > Add "loongson,ls2k0300-rtc" dedicated compatible to represent the RTC
> > interface of the Loongson-2K0300 chip.
> >
> > Its hardware design is similar to that of the Loongson-1B, but it does
> > not support the alarm feature.
> >
> > Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
> > ---
> > .../devicetree/bindings/rtc/loongson,rtc.yaml | 13 +++++++++++++
> > 1 file changed, 13 insertions(+)
> >
> > diff --git a/Documentation/devicetree/bindings/rtc/loongson,rtc.yaml b/Documentation/devicetree/bindings/rtc/loongson,rtc.yaml
> > index f89c1f660aee..aac91c79ffdb 100644
> > --- a/Documentation/devicetree/bindings/rtc/loongson,rtc.yaml
> > +++ b/Documentation/devicetree/bindings/rtc/loongson,rtc.yaml
> > @@ -23,6 +23,7 @@ properties:
> > - loongson,ls1b-rtc
> > - loongson,ls1c-rtc
> > - loongson,ls7a-rtc
> > + - loongson,ls2k0300-rtc
> > - loongson,ls2k1000-rtc
> > - items:
> > - enum:
> > @@ -42,6 +43,18 @@ required:
> >
> > unevaluatedProperties: false
> >
> > +if:
> > + properties:
> > + compatible:
> > + contains:
> > + enum:
> > + - loongson,ls1c-rtc
>
> This seems unrelated?
Loongson-1C does not support the alarm feature, so the `interrupts`
property is not needed.
Technically, this is my fault and should have been described in the
binding before, just correcting it now.
Perhaps I should have mentioned this in the commit message.
>
> > + - loongson,ls2k0300-rtc
> > +
> > +then:
> > + properties:
> > + interrupts: false
> > +
> > examples:
> > - |
> > #include <dt-bindings/interrupt-controller/irq.h>
> > --
> > 2.47.3
> >
--
Thanks.
Binbin
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2025-12-30 2:32 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-23 6:42 [PATCH v1 0/2] RTC: Add Loongson-2K0300 support Binbin Zhou
2025-12-23 6:42 ` [PATCH v1 1/2] dt-binding: rtc: loongson: Document Loongson-2K0300 compatible Binbin Zhou
2025-12-30 2:15 ` Rob Herring
2025-12-30 2:31 ` Binbin Zhou
2025-12-23 6:42 ` [PATCH v1 2/2] rtc: loongson: Add Loongson-2K0300 support Binbin Zhou
2025-12-23 8:40 ` Huacai Chen
2025-12-23 9:06 ` Binbin Zhou
2025-12-23 9:09 ` Huacai Chen
2025-12-26 10:03 ` [PATCH v1 0/2] RTC: " Keguang Zhang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox