From: Sakari Ailus <sakari.ailus@iki.fi>
To: Frank Li <Frank.Li@nxp.com>
Cc: Michael Riesch <michael.riesch@collabora.com>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Philipp Zabel <p.zabel@pengutronix.de>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Heiko Stuebner <heiko@sntech.de>,
linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
linux-rockchip@lists.infradead.org,
Guoniu Zhou <guoniu.zhou@oss.nxp.com>,
Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
imx@lists.linux.dev
Subject: Re: [PATCH 4/6] media: synopsys: use struct dw_mipi_csi2rx_regs to describe register offsets
Date: Tue, 24 Mar 2026 10:16:46 +0200 [thread overview]
Message-ID: <acJIbvVpmDS__EEg@valkosipuli.retiisi.eu> (raw)
In-Reply-To: <20260210-imx93-dw-csi2-v1-4-69667bb86bfa@nxp.com>
Hi Frank,
On Tue, Feb 10, 2026 at 12:11:11PM -0500, Frank Li wrote:
> Use struct dw_mipi_csi2rx_regs to describe register offsets and support
> new IP versions with differing register layouts.
>
> Add rk3568_regs, matching the previous macro definitions, and pass it as
> driver data retrieved during probe.
>
> No functional change.
>
> Signed-off-by: Frank Li <Frank.Li@nxp.com>
> ---
> drivers/media/platform/synopsys/dw-mipi-csi2rx.c | 96 +++++++++++++++++-------
> 1 file changed, 69 insertions(+), 27 deletions(-)
>
> diff --git a/drivers/media/platform/synopsys/dw-mipi-csi2rx.c b/drivers/media/platform/synopsys/dw-mipi-csi2rx.c
> index 4ad4e3b23448affeeaa932a706653818ba4019ba..6a2966c9e3a2eac661fa1f8610c9f021d6e26cf8 100644
> --- a/drivers/media/platform/synopsys/dw-mipi-csi2rx.c
> +++ b/drivers/media/platform/synopsys/dw-mipi-csi2rx.c
> @@ -24,14 +24,39 @@
> #include <media/v4l2-mc.h>
> #include <media/v4l2-subdev.h>
>
> -#define DW_MIPI_CSI2RX_N_LANES 0x04
> -#define DW_MIPI_CSI2RX_RESETN 0x10
> -#define DW_MIPI_CSI2RX_PHY_STATE 0x14
> -#define DW_MIPI_CSI2RX_ERR1 0x20
> -#define DW_MIPI_CSI2RX_ERR2 0x24
> -#define DW_MIPI_CSI2RX_MSK1 0x28
> -#define DW_MIPI_CSI2RX_MSK2 0x2c
> -#define DW_MIPI_CSI2RX_CONTROL 0x40
> +struct dw_mipi_csi2rx_regs {
> + u32 n_lanes;
> + u32 resetn;
> + u32 phy_state;
> + u32 err1;
> + u32 err2;
> + u32 msk1;
> + u32 msk2;
> + u32 control;
> +};
> +
> +struct dw_mipi_csi2rx_drvdata {
> + const struct dw_mipi_csi2rx_regs *regs;
> +};
> +
> +/* Help check wrong access unexisted register at difference IP version */
> +#define DW_REG_EXIST BIT(31)
> +#define DW_REG(x) (DW_REG_EXIST | (x))
> +
> +static const struct dw_mipi_csi2rx_regs rk3568_regs = {
> + .n_lanes = DW_REG(0x4),
> + .resetn = DW_REG(0x10),
> + .phy_state = DW_REG(0x14),
> + .err1 = DW_REG(0x20),
> + .err2 = DW_REG(0x24),
> + .msk1 = DW_REG(0x28),
> + .msk2 = DW_REG(0x2c),
> + .control = DW_REG(0x40),
> +};
> +
> +static const struct dw_mipi_csi2rx_drvdata rk3568_drvdata = {
"drvdata" is typically used of driver's context struct related to a given
device. This is something else. How about calling it rk3568_devinfo for
instance?
> + .regs = &rk3568_regs,
> +};
>
> #define SW_CPHY_EN(x) ((x) << 0)
> #define SW_DSI_EN(x) ((x) << 4)
> @@ -74,8 +99,35 @@ struct dw_mipi_csi2rx_device {
>
> enum v4l2_mbus_type bus_type;
> u32 lanes_num;
> +
> + const struct dw_mipi_csi2rx_drvdata *drvdata;
> };
>
> +static int
> +dw_mipi_csi2rx_reg_err(struct dw_mipi_csi2rx_device *csi2, const char *name)
> +{
> + dev_err_once(csi2->dev, "access to non-existent register: %s\n", name);
> + return 0;
> +}
> +
> +#define __dw_reg_exist(offset) ((offset) & DW_REG_EXIST)
> +
> +#define dw_reg_exist(csi2, __name) __dw_reg_exist((csi2)->drvdata->regs->__name)
Can you use the same dw_mipi_csi2rx prefix here?
> +
> +#define dw_mipi_csi2rx_write(csi2, __name, value) \
> +({ auto __csi2 = csi2; \
Are there different types being used for csi2? As this there's a single
driver here I'd suppose no?
> + u32 offset = __csi2->drvdata->regs->__name; \
> + __dw_reg_exist(offset) ? \
> + writel(value, __csi2->base_addr + (offset & ~DW_REG_EXIST)) : \
> + dw_mipi_csi2rx_reg_err(__csi2, #__name); })
> +
> +#define dw_mipi_csi2rx_read(csi2, __name) \
> +({ auto __csi2 = csi2; \
> + u32 offset = __csi2->drvdata->regs->__name; \
> + __dw_reg_exist(offset) ? \
> + readl(__csi2->base_addr + (offset & ~DW_REG_EXIST)) : \
> + dw_mipi_csi2rx_reg_err(__csi2, #__name); })
> +
> static const struct v4l2_mbus_framefmt default_format = {
> .width = 3840,
> .height = 2160,
> @@ -188,18 +240,6 @@ static inline struct dw_mipi_csi2rx_device *to_csi2(struct v4l2_subdev *sd)
> return container_of(sd, struct dw_mipi_csi2rx_device, sd);
> }
>
> -static inline void dw_mipi_csi2rx_write(struct dw_mipi_csi2rx_device *csi2,
> - unsigned int addr, u32 val)
> -{
> - writel(val, csi2->base_addr + addr);
> -}
> -
> -static inline u32 dw_mipi_csi2rx_read(struct dw_mipi_csi2rx_device *csi2,
> - unsigned int addr)
> -{
> - return readl(csi2->base_addr + addr);
> -}
> -
> static const struct dw_mipi_csi2rx_format *
> dw_mipi_csi2rx_find_format(struct dw_mipi_csi2rx_device *csi2, u32 mbus_code)
> {
> @@ -265,9 +305,9 @@ static int dw_mipi_csi2rx_start(struct dw_mipi_csi2rx_device *csi2)
> control |= SW_DATATYPE_FS(0x00) | SW_DATATYPE_FE(0x01) |
> SW_DATATYPE_LS(0x02) | SW_DATATYPE_LE(0x03);
>
> - dw_mipi_csi2rx_write(csi2, DW_MIPI_CSI2RX_N_LANES, lanes - 1);
> - dw_mipi_csi2rx_write(csi2, DW_MIPI_CSI2RX_CONTROL, control);
> - dw_mipi_csi2rx_write(csi2, DW_MIPI_CSI2RX_RESETN, 1);
> + dw_mipi_csi2rx_write(csi2, n_lanes, lanes - 1);
> + dw_mipi_csi2rx_write(csi2, control, control);
> + dw_mipi_csi2rx_write(csi2, resetn, 1);
>
> return phy_power_on(csi2->phy);
> }
> @@ -276,9 +316,9 @@ static void dw_mipi_csi2rx_stop(struct dw_mipi_csi2rx_device *csi2)
> {
> phy_power_off(csi2->phy);
>
> - dw_mipi_csi2rx_write(csi2, DW_MIPI_CSI2RX_RESETN, 0);
> - dw_mipi_csi2rx_write(csi2, DW_MIPI_CSI2RX_MSK1, ~0);
> - dw_mipi_csi2rx_write(csi2, DW_MIPI_CSI2RX_MSK2, ~0);
> + dw_mipi_csi2rx_write(csi2, resetn, 0);
> + dw_mipi_csi2rx_write(csi2, msk1, ~0);
> + dw_mipi_csi2rx_write(csi2, msk2, ~0);
> }
>
> static const struct media_entity_operations dw_mipi_csi2rx_media_ops = {
> @@ -632,7 +672,7 @@ static void dw_mipi_csi2rx_unregister(struct dw_mipi_csi2rx_device *csi2)
>
> static const struct of_device_id dw_mipi_csi2rx_of_match[] = {
> {
> - .compatible = "rockchip,rk3568-mipi-csi2",
> + .compatible = "rockchip,rk3568-mipi-csi2", .data = &rk3568_drvdata,
> },
> {}
> };
> @@ -654,6 +694,8 @@ static int dw_mipi_csi2rx_probe(struct platform_device *pdev)
> if (IS_ERR(csi2->base_addr))
> return PTR_ERR(csi2->base_addr);
>
> + csi2->drvdata = device_get_match_data(dev);
> +
> ret = devm_clk_bulk_get_all(dev, &csi2->clks);
> if (ret < 0)
> return dev_err_probe(dev, -ENODEV, "failed to get clocks\n");
>
--
Regards,
Sakari Ailus
next prev parent reply other threads:[~2026-03-24 8:16 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-10 17:11 [PATCH 0/6] media: synopsys: Add imx93 support Frank Li
2026-02-10 17:11 ` [PATCH 1/6] media: synopsys: use devm_reset_control_get_optional_exclusive() Frank Li
2026-02-13 9:25 ` Michael Riesch
2026-02-10 17:11 ` [PATCH 2/6] media: synopsys: only check errors from devm_clk_bulk_get_all() Frank Li
2026-02-13 9:35 ` Michael Riesch
2026-02-10 17:11 ` [PATCH 3/6] media: synopsys: implement .get_frame_desc() callback Frank Li
2026-03-24 8:02 ` Sakari Ailus
2026-02-10 17:11 ` [PATCH 4/6] media: synopsys: use struct dw_mipi_csi2rx_regs to describe register offsets Frank Li
2026-02-13 10:02 ` Michael Riesch
2026-03-24 8:16 ` Sakari Ailus [this message]
2026-02-10 17:11 ` [PATCH 5/6] media: dt-bindings: add NXP i.MX93 compatible string Frank Li
2026-02-11 6:47 ` Krzysztof Kozlowski
2026-02-10 17:11 ` [PATCH 6/6] media: synopsys: add i.MX93 support Frank Li
2026-02-13 10:22 ` Michael Riesch
2026-03-23 19:10 ` [PATCH 0/6] media: synopsys: Add imx93 support Frank Li
2026-03-24 8:01 ` Sakari Ailus
2026-03-24 8:18 ` Sakari Ailus
2026-03-24 9:46 ` Michael Riesch
2026-03-24 10:35 ` Sakari Ailus
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=acJIbvVpmDS__EEg@valkosipuli.retiisi.eu \
--to=sakari.ailus@iki.fi \
--cc=Frank.Li@nxp.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=guoniu.zhou@oss.nxp.com \
--cc=heiko@sntech.de \
--cc=imx@lists.linux.dev \
--cc=krzk+dt@kernel.org \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-rockchip@lists.infradead.org \
--cc=mchehab@kernel.org \
--cc=michael.riesch@collabora.com \
--cc=p.zabel@pengutronix.de \
--cc=robh@kernel.org \
/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