Re: [PATCH v1 2/2] rtc: loongson: Add Loongson-2K0300 support

Binbin Zhou
2025-12-23T09:06:26Z

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