From: Frank Li <Frank.li@oss.nxp.com>
To: Binbin Zhou <zhoubb.aaron@gmail.com>
Cc: Binbin Zhou <zhoubinbin@loongson.cn>,
Huacai Chen <chenhuacai@loongson.cn>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>, Vinod Koul <vkoul@kernel.org>,
Frank Li <Frank.Li@kernel.org>,
dmaengine@vger.kernel.org, Huacai Chen <chenhuacai@kernel.org>,
Xuerui Wang <kernel@xen0n.name>,
loongarch@lists.linux.dev, devicetree@vger.kernel.org,
Keguang Zhang <keguang.zhang@gmail.com>
Subject: Re: [PATCH v2 3/3] dmaengine: loongson: Add Loongson-2K0300 APB DMA mux driver
Date: Wed, 21 Oct 2026 10:05:30 -0500 [thread overview]
Message-ID: <atjUuos9UhJsWU85@SMW015318> (raw)
In-Reply-To: <CAMpQs4Ke44d=ijRPbmZM5FZ0YReRH1U4jFMA=RPKU1VNLsNv+w@mail.gmail.com>
On Wed, Oct 21, 2026 at 05:34:29PM +0800, Binbin Zhou wrote:
> Hi Frank:
>
> On Fri, Oct 16, 2026 at 1:03 AM Frank Li <Frank.li@oss.nxp.com> wrote:
> >
> > On Fri, Oct 09, 2026 at 05:19:34PM +0800, Binbin Zhou wrote:
> > > The Loongson-2K0300 DMA mux is not a standalone DMA controller. It is
> > > implemented as a set of routing fields in the chip global configuration
> > > registers CHIP_CTRL13/14/15, which select which physical channel of the
> > > on-chip CMC DMA controller handles each peripheral DMA request.
> > >
> > > Add a driver that exposes these routing fields as an OF DMA router. The
> > > router's allocation callback validates the <request> <channel> <flags>
> > > specifier, programs the corresponding CHIP_CTRL register field, and then
> > > rewrites the specifier to <channel> <flags> so that the parent CMC DMA
> > > controller's xlate is used.
> > >
> > > Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
> > > ---
> > > MAINTAINERS | 1 +
> > > drivers/dma/loongson/Makefile | 1 +
> > > drivers/dma/loongson/loongson2-apb-dmamux.c | 398 ++++++++++++++++++++
> > > 3 files changed, 400 insertions(+)
> > > create mode 100644 drivers/dma/loongson/loongson2-apb-dmamux.c
> > >
> > > diff --git a/MAINTAINERS b/MAINTAINERS
> > > index 78622b255f88..0b0c6ea41c64 100644
> > > --- a/MAINTAINERS
> > > +++ b/MAINTAINERS
> > > @@ -15355,6 +15355,7 @@ F: Documentation/devicetree/bindings/dma/loongson,ls2k0300-dmamux.yaml
> > > F: Documentation/devicetree/bindings/dma/loongson,ls2x-apbdma.yaml
> > > F: drivers/dma/loongson/loongson2-apb-cmc-dma.c
> > > F: drivers/dma/loongson/loongson2-apb-dma.c
> > > +F: drivers/dma/loongson/loongson2-apb-dmamux.c
> > > F: include/dt-bindings/dma/loongson,ls2k-dmamux.h
> > >
> > > LOONGSON LS2X I2C DRIVER
> > > diff --git a/drivers/dma/loongson/Makefile b/drivers/dma/loongson/Makefile
> > > index 48c19781e729..271fd38fa8f2 100644
> > > --- a/drivers/dma/loongson/Makefile
> > > +++ b/drivers/dma/loongson/Makefile
> > > @@ -2,3 +2,4 @@
> > > obj-$(CONFIG_LOONGSON1_APB_DMA) += loongson1-apb-dma.o
> > > obj-$(CONFIG_LOONGSON2_APB_DMA) += loongson2-apb-dma.o
> > > obj-$(CONFIG_LOONGSON2_APB_CMC_DMA) += loongson2-apb-cmc-dma.o
> > > +obj-$(CONFIG_LOONGSON2_APB_CMC_DMA) += loongson2-apb-dmamux.o
> > > diff --git a/drivers/dma/loongson/loongson2-apb-dmamux.c b/drivers/dma/loongson/loongson2-apb-dmamux.c
> > > new file mode 100644
> > > index 000000000000..01bd3ce4ca25
> > > --- /dev/null
> > > +++ b/drivers/dma/loongson/loongson2-apb-dmamux.c
> > > @@ -0,0 +1,398 @@
> > ...
> > > +static int loongson2_dmamux_set_route(struct loongson2_dmamux *mux, u32 request, u32 channel)
> > > +{
> > > + const struct loongson2_dmamux_map *map;
> > > + u32 reg_val, route_val, high_val = 0;
> > > +
> > > + if (request >= mux->config->num_maps)
> > > + return -EINVAL;
> > > +
> > > + if (channel > mux->config->max_channel)
> > > + return -EINVAL;
> > > +
> > > + map = &mux->config->maps[request];
> > > +
> > > + switch (map->type) {
> > > + case LOONGSON_DMAMUX_PAIR:
> > > + route_val = channel / 2;
> > > + break;
> > > + case LOONGSON_DMAMUX_SINGLE:
> > > + route_val = channel;
> > > + if (map->high_reg)
> > > + high_val = (channel >> 2) & 0x1;
> > > + break;
> > > + default:
> > > + return -EINVAL;
> > > + }
> > > +
> > > + guard(spinlock_irqsave)(&mux->lock);
> > > +
> > > + /* Write the primary register field */
> > > + reg_val = loongson2_dmamux_read(mux, map->reg);
> > > + reg_val &= ~map->mask;
> > > + reg_val |= field_prep(map->mask, route_val);
> > > + loongson2_dmamux_write(mux, map->reg, reg_val);
> > > +
> > > + /* Write the extension register field if present */
> > > + if (map->high_reg) {
> > > + reg_val = loongson2_dmamux_read(mux, map->high_reg);
> > > + reg_val &= ~BIT(map->high_shift);
> > > + reg_val |= high_val << map->high_shift;
> >
> > assign_bit(map->high_shift, ®_val, high_val);
>
> I think `assign_bit()` here is not quite suitable, reg_val is a u32
> (returned by loongson2_dmamux_read()), but assign_bit() expects a
> `volatile unsigned long *`.
>
> How about adding a helper function:
>
> static void loongson2_dmamux_assign_bits(struct loongson2_dmamux *priv,
> unsigned int reg, u32 mask, u32 val)
> {
> u32 reg_val;
>
> reg_val = loongson2_dmamux_read(priv, reg);
> reg_val &= ~mask;
> reg_val |= val & mask;
> loongson2_dmamux_write(priv, reg, reg_val);
> }
>
Okay, if only use once, old code should be fine.
Reviewed-by: Frank Li <Frank.Li@nxp.com>
next prev parent reply other threads:[~2026-10-21 15:05 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-09 9:19 [PATCH v2 0/3] Add Loongson-2K0300 APB DMA mux support Binbin Zhou
2026-10-09 9:19 ` [PATCH v2 1/3] dt-bindings: dma: loongson: Add Loongson-2 DMA mux request IDs Binbin Zhou
2026-10-09 14:38 ` Conor Dooley
2026-10-09 9:19 ` [PATCH v2 2/3] dt-bindings: dma: loongson: Add Loongson-2K0300 DMA mux support Binbin Zhou
2026-10-09 14:43 ` Conor Dooley
2026-10-09 9:19 ` [PATCH v2 3/3] dmaengine: loongson: Add Loongson-2K0300 APB DMA mux driver Binbin Zhou
2026-10-15 17:03 ` Frank Li
2026-10-21 9:34 ` Binbin Zhou
2026-10-21 15:05 ` Frank Li [this message]
2026-10-25 8:19 ` Huacai Chen
2026-10-25 13:49 ` 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=atjUuos9UhJsWU85@SMW015318 \
--to=frank.li@oss.nxp.com \
--cc=Frank.Li@kernel.org \
--cc=chenhuacai@kernel.org \
--cc=chenhuacai@loongson.cn \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dmaengine@vger.kernel.org \
--cc=keguang.zhang@gmail.com \
--cc=kernel@xen0n.name \
--cc=krzk+dt@kernel.org \
--cc=loongarch@lists.linux.dev \
--cc=robh@kernel.org \
--cc=vkoul@kernel.org \
--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