devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: Binbin Zhou <zhoubb.aaron@gmail.com>
Cc: Binbin Zhou <zhoubinbin@loongson.cn>,
	Huacai Chen <chenhuacai@loongson.cn>,
	 Rob Herring <robh+dt@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	 Conor Dooley <conor+dt@kernel.org>,
	 Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	 Jiri Slaby <jirislaby@kernel.org>,
	Haowei Zheng <zhenghaowei@loongson.cn>,
	 Huacai Chen <chenhuacai@kernel.org>,
	Xuerui Wang <kernel@xen0n.name>,
	 loongarch@lists.linux.dev, devicetree@vger.kernel.org,
	 linux-serial <linux-serial@vger.kernel.org>
Subject: Re: [PATCH v5 2/3] serial: 8250: Add Loongson uart driver support
Date: Thu, 9 Oct 2025 14:46:22 +0300 (EEST)	[thread overview]
Message-ID: <5e33cb28-0f03-519e-10e6-74d5305c1284@linux.intel.com> (raw)
In-Reply-To: <CAMpQs4KS=hd3zvj5KYH7vBXpbEhPLmS61H9dLgnRpBpH+04ChA@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 3608 bytes --]

On Thu, 9 Oct 2025, Binbin Zhou wrote:

> Hi Ilpo:
> 
> Sorry for the late reply and thanks for your detailed review.
> 
> On Tue, Sep 30, 2025 at 7:58 PM Ilpo Järvinen
> <ilpo.jarvinen@linux.intel.com> wrote:
> >
> > On Wed, 24 Sep 2025, Binbin Zhou wrote:
> >
> > > Add the driver for on-chip UART used on Loongson family chips.
> > >
> > > The hardware is similar to 8250, but there are the following
> > > differences:
> > >  - Some chips (such as Loongson-2K2000) have added a fractional division
> > >    register to obtain the required baud rate accurately, so the
> > >    {get,set}_divisor callback is overridden.
> > >  - Due to hardware defects, quirk handling is required for
> > >    UART_MCR/UART_MSR.
> > >
> > > Co-developed-by: Haowei Zheng <zhenghaowei@loongson.cn>
> > > Signed-off-by: Haowei Zheng <zhenghaowei@loongson.cn>
> > > Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
> > > ---

> > > +static unsigned int serial_fixup(struct uart_port *p, unsigned int offset, unsigned int val)
> > > +{
> > > +     struct loongson_uart_data *ddata = p->private_data;
> > > +
> > > +     if (offset == UART_MCR)
> > > +             val ^= ddata->mcr_invert;
> > > +
> > > +     if (offset == UART_MSR)
> > > +             val ^= ddata->msr_invert;

One additional thing, this could use switch/case.

I'd just do:

	...
	case UART_MSR:
		return val ^ ddata->msr_invert;
	default:
		return val;
	}

That way you don't need to use breaks.

> > > +     if (flags & LOONGSON_UART_HAS_FRAC) {
> > > +             uart.port.get_divisor = loongson_frac_get_divisor;
> > > +             uart.port.set_divisor = loongson_frac_set_divisor;
> > > +     }
> > > +
> > > +     if (flags & LOONGSON_UART_QUIRK_MCR)
> > > +             ddata->mcr_invert |= (UART_MCR_RTS | UART_MCR_DTR);
> > > +
> > > +     if (flags & LOONGSON_UART_QUIRK_MSR)
> > > +             ddata->msr_invert |= (UART_MSR_CTS | UART_MSR_DSR);
> >
> > I think it would be better to put these invert masks directly into a
> > struct which is then put into .data. LOONGSON_UART_HAS_FRAC can be bool
> > in that struct.
> 
> I attempted the following refactoring:
> 
> struct loongson_uart_ddata {
>         bool has_frac;
>         u8 mcr_invert;
>         u8 msr_invert;
> };
> 
> static const struct loongson_uart_ddata ls2k0500_uart_data {
>         .has_frac = false,
>         .mcr_invert = UART_MCR_RTS | UART_MCR_DTR,
>         .msr_invert = UART_MSR_CTS | UART_MSR_DSR,
> };
> 
> static const struct loongson_uart_ddata ls2k1500_uart_data {
>         .has_frac = true,
>         .mcr_invert = UART_MCR_RTS | UART_MCR_DTR,
>         .msr_invert = 0,
> };
> 
> struct loongson_uart_priv {
>         int line;
>         struct clk *clk;
>         struct resource *res;
>         struct reset_control *rst;
>         struct loongson_uart_ddata *ddata;

This can and should be const struct as well as those underlying data 
structs are const too.

> };
> 
> .............
> In loongson_uart_probe():
>        priv->ddata = device_get_match_data(dev);
> 
>         if (priv->ddata->has_frac) {
>                 port->get_divisor = loongson_frac_get_divisor;
>                 port->set_divisor = loongson_frac_set_divisor;
>         }
> 
> 
> .............
> static const struct of_device_id loongson_uart_of_ids[] = {
>         { .compatible = "loongson,ls2k0500-uart", .data = ls2k0500_uart_data },
>         { .compatible = "loongson,ls2k1500-uart", .data = ls2k1500_uart_data },
>         { },
> };


-- 
 i.

  reply	other threads:[~2025-10-09 11:46 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-24  6:29 [PATCH v5 0/3] uart: Introduce uart driver for the Loongson family Binbin Zhou
2025-09-24  6:29 ` [PATCH v5 1/3] dt-bindings: serial: 8250: Add Loongson uart compatible Binbin Zhou
2025-09-24 19:19   ` Conor Dooley
2025-09-24  6:29 ` [PATCH v5 2/3] serial: 8250: Add Loongson uart driver support Binbin Zhou
2025-09-24 10:22   ` Greg Kroah-Hartman
2025-09-28  2:48     ` Binbin Zhou
2025-09-29  6:19       ` Jiri Slaby
2025-09-30  3:03         ` Binbin Zhou
2025-10-08 12:16           ` Greg Kroah-Hartman
2025-09-29  6:26   ` Jiri Slaby
2025-09-30  3:07     ` Binbin Zhou
2025-09-30 12:01     ` Ilpo Järvinen
2025-09-30 11:58   ` Ilpo Järvinen
2025-10-09  2:52     ` Binbin Zhou
2025-10-09 11:46       ` Ilpo Järvinen [this message]
2025-09-24  6:29 ` [PATCH v5 3/3] LoongArch: dts: Add uart new compatible string Binbin Zhou

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5e33cb28-0f03-519e-10e6-74d5305c1284@linux.intel.com \
    --to=ilpo.jarvinen@linux.intel.com \
    --cc=chenhuacai@kernel.org \
    --cc=chenhuacai@loongson.cn \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jirislaby@kernel.org \
    --cc=kernel@xen0n.name \
    --cc=krzk+dt@kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=loongarch@lists.linux.dev \
    --cc=robh+dt@kernel.org \
    --cc=zhenghaowei@loongson.cn \
    --cc=zhoubb.aaron@gmail.com \
    --cc=zhoubinbin@loongson.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).