Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Svyatoslav Ryhel" <clamor95@gmail.com>
Cc: dri-devel@lists.freedesktop.org, devicetree@vger.kernel.org,
	robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v8 12/12] drm/tegra: Add support for 8-bit CPU interface
Date: Sun, 22 Nov 2026 08:43:06 +0000	[thread overview]
Message-ID: <sashiko-outbox-227839@kernel.org> (raw)
In-Reply-To: <20261122081820.53199-13-clamor95@gmail.com>

Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [High] drm/tegra: duplicate and out-of-order next_bridge
  enable/disable calls
- [Medium] drm/tegra: missing DC stop and idle wait in
  tegra_dbi_atomic_disable()
- [Medium] drm/tegra: premature of_node_put() on dbi_np in
  tegra_dc_dbi_probe()
- [Medium] drm/tegra: NULL next_bridge dereference in DBI atomic
  enable/disable
- [Medium] drm/tegra: unconditional PIN_LDC muxing in
  tegra_dbi_atomic_enable()
--

commit 12a7641d08ff0efca036e7255db62622fe7d77c9
Author: Svyatoslav Ryhel <clamor95@gmail.com>

drm/tegra: Add support for 8-bit CPU interface

This commit adds a DRM bridge and MIPI DBI host driver for the 8-bit CPU
interface on Tegra20 and Tegra30 display controllers, allowing MIPI DCS
commands to be sent to panels that receive video data over RGB.

> diff --git a/drivers/gpu/drm/tegra/dbi.c b/drivers/gpu/drm/tegra/dbi.c
> new file mode 100644
> index 0000000000000..8929f0013462a
> --- /dev/null
> +++ b/drivers/gpu/drm/tegra/dbi.c
> @@ -0,0 +1,592 @@

[ ... ]

> +static void tegra_dbi_atomic_enable(struct drm_bridge *bridge,
> +				    struct drm_atomic_commit *state)
> +{
> +	struct tegra_dbi_priv *priv = bridge_to_tegra_dbi(bridge);
> +	struct drm_bridge *next_bridge = priv->next_bridge;
> +	struct tegra_dc *dc = priv->dc;
> +	void __iomem *disp_cmd = dc->regs + (DC_CMD_DISPLAY_COMMAND << 2);
> +	u32 value;
> +	int ret;
> +
> +	value = tegra_dc_readl(dc, DC_CMD_DISPLAY_COMMAND);
> +	value &= ~DISP_CTRL_MODE_MASK;
> +	tegra_dc_writel(dc, value, DC_CMD_DISPLAY_COMMAND);
> +
> +	/* Disable all options except cursor if enabled */
> +	value = tegra_dc_readl(dc, DC_DISP_DISP_WIN_OPTIONS);
> +	value &= CURSOR_ENABLE;
> +	tegra_dc_writel(dc, value, DC_DISP_DISP_WIN_OPTIONS);
> +
> +	tegra_dc_commit(dc);
> +
> +	/* Ensure the DC is fully idle before reconfiguring pins */
> +	tegra_dc_writel(dc, READ_MUX, DC_CMD_STATE_ACCESS);
> +
> +	ret = readl_relaxed_poll_timeout(disp_cmd, value,
> +					 !(value & DISP_CTRL_MODE_MASK), 1000,
> +					 100000);
> +
> +	tegra_dc_writel(dc, 0, DC_CMD_STATE_ACCESS);
> +	if (ret) {
> +		dev_err(priv->dev, "timeout waiting for DC to become idle\n");
> +		return;
> +	}
> +
> +	tegra_dc_writel(dc, V_PULSE1_ENABLE, DC_DISP_DISP_SIGNAL_OPTIONS0);
> +	tegra_dc_writel(dc, PULSE_POLARITY_LOW, DC_DISP_V_PULSE1_CONTROL);
> +
> +	tegra_dc_writel(dc, PULSE_END(1), DC_DISP_V_PULSE1_POSITION_A);
> +	tegra_dc_writel(dc, 0, DC_DISP_V_PULSE1_POSITION_B);
> +	tegra_dc_writel(dc, 0, DC_DISP_V_PULSE1_POSITION_C);
> +
> +	value = 1 << FRAME_INIT_SEQ_CYCLES_SHIFT |
> +		DC_SIGNAL_VPULSE1 << INIT_SEQ_DC_SIGNAL_SHIFT |
> +		INIT_SEQUENCE_MODE_PLCD | SEND_INIT_SEQUENCE;
> +	tegra_dc_writel(dc, value, DC_DISP_INIT_SEQ_CONTROL);
> +
> +	/* Init cycle 1: WRITE_MEMORY_START, set LCD_PCLK and COMMAND */
> +	tegra_dc_writel(dc, MIPI_DCS_WRITE_MEMORY_START, DC_DISP_SPI_INIT_SEQ_DATA_A);
> +	tegra_dc_writel(dc, 0x0, DC_DISP_SPI_INIT_SEQ_DATA_B);
> +	tegra_dc_writel(dc, 0x0, DC_DISP_SPI_INIT_SEQ_DATA_C);
> +	tegra_dc_writel(dc, BIT(12) | BIT(14), DC_DISP_SPI_INIT_SEQ_DATA_D);
> +
> +	/* Set LDC pin to V Pulse 1 */
> +	value = tegra_dc_readl(dc, DC_COM_PIN_OUTPUT_SELECT(6));
> +	value &= ~PIN_OUTPUT_SELECT_MASK(PIN_OUTPUT_SELECT_LDC);
> +	value |= PIN_OUTPUT_SELECT_F4(PIN_OUTPUT_SELECT_LDC);
> +	tegra_dc_writel(dc, value, DC_COM_PIN_OUTPUT_SELECT(6));

[Severity: Medium]
Does this unconditionally mux V_PULSE1 onto PIN_LDC even when the secondary
8-bit CPU interface (nvidia,interface = 1) is selected?

In tegra_dbi_idx[], the secondary interface uses PIN_LVP0 in
DC_COM_PIN_OUTPUT_SELECT(4) as its D/C signal rather than PIN_LDC.  Because
tegra_rgb_encoder_enable() programs PIN_OUTPUT_SELECT_LVP0 to
PIN_OUTPUT_SELECT_OUT before tegra_dbi_atomic_enable() backs up the pin
registers into com_pin_backup[], restoring com_pin_backup[] leaves PIN_LVP0
in fixed GPIO output mode during scanout instead of driving the per-frame
MIPI_DCS_WRITE_MEMORY_START D/C pulse on the secondary interface.

[ ... ]

> +	/*
> +	 * DBI requires that the next bridge be enabled here in order to
> +	 * send DCS commands, since the interface pins will subsequently be
> +	 * reconfigured for video data.
> +	 *
> +	 * Using the prepare_prev_first flag in the panel will not work,
> +	 * because the DBI bridge requires the panel to be enabled beforehand
> +	 * for proper configuration.
> +	 */
> +	if (next_bridge->funcs && next_bridge->funcs->atomic_enable)
> +		next_bridge->funcs->atomic_enable(next_bridge, state);

[Severity: Medium]
Can next_bridge be NULL here and in tegra_dbi_atomic_disable() if the MIPI
DBI peripheral driver has been unbound?

tegra_dbi_host_detach() calls drm_bridge_clear_and_put(&priv->next_bridge),
setting priv->next_bridge to NULL.  A subsequent modeset or shutdown will
then hit a NULL pointer dereference when evaluating next_bridge->funcs.

> +
> +	tegra_dbi_pin_set(dc, &priv->interface->cs, 0);
> +
> +	priv->active = false;
> +
> +	tegra_dc_writel(dc, 0, DC_CMD_STATE_ACCESS);
> +
> +	for (int i = 0; i <  ARRAY_SIZE(tegra_dbi_pin_regs); i++)
> +		tegra_dc_writel(dc, priv->com_pin_backup[i],
> +				tegra_dbi_pin_regs[i]);
> +
> +	tegra_dc_commit(dc);
> +
> +	value = tegra_dc_readl(dc, DC_CMD_DISPLAY_COMMAND);
> +	value &= ~DISP_CTRL_MODE_MASK;
> +	value |= DISP_CTRL_MODE_C_DISPLAY;
> +	tegra_dc_writel(dc, value, DC_CMD_DISPLAY_COMMAND);
> +}
> +
> +static void tegra_dbi_atomic_disable(struct drm_bridge *bridge,
> +				     struct drm_atomic_commit *state)
> +{
> +	struct tegra_dbi_priv *priv = bridge_to_tegra_dbi(bridge);
> +	struct drm_bridge *next_bridge = priv->next_bridge;
> +	struct tegra_dc *dc = priv->dc;
> +
> +	for (int i = 0; i < ARRAY_SIZE(tegra_dbi_pin_regs); i++)
> +		priv->com_pin_backup[i] = tegra_dc_readl(dc, tegra_dbi_pin_regs[i]);
> +
> +	tegra_dc_writel(dc, WRITE_MUX | READ_MUX, DC_CMD_STATE_ACCESS);
> +
> +	priv->interface->init(priv);
> +	priv->active = true;

[Severity: Medium]
Should tegra_dbi_atomic_disable() stop the DC and wait for it to become idle
before unshadowing DC_CMD_STATE_ACCESS and reconfiguring pins, just as
tegra_dbi_atomic_enable() does?

During modeset disable, drm_atomic_helper_commit_encoder_bridge_disable()
runs before drm_atomic_helper_commit_crtc_disable(), so the DC is still
actively scanning out in DISP_CTRL_MODE_C_DISPLAY with V_PULSE1 frame init
sequences enabled while the pins are switched to GPIO output mode and bit-
banged for DBI commands.

> +
> +	/*
> +	 * DBI requires that the next bridge be disabled here in order to
> +	 * send DCS commands, since the interface pins will subsequently be
> +	 * reconfigured for video data and tegra_rgb_encoder_disable() will
> +	 * be called before drm_panel_unprepare() runs in post_disable.
> +	 */
> +	if (next_bridge->funcs && next_bridge->funcs->atomic_disable)
> +		next_bridge->funcs->atomic_disable(next_bridge, state);

[Severity: High]
As reported by Mikko Perttunen on v5 [1], since tegra_dbi_attach() attaches
priv->next_bridge to encoder->bridge_chain, won't manually calling
next_bridge->funcs->atomic_enable() and atomic_disable() cause both
callbacks to run twice and in the wrong order on disable?

On enable, drm_atomic_bridge_chain_enable() calls tegra_dbi_atomic_enable(),
which invokes next_bridge->funcs->atomic_enable() while priv->active is true,
and then drm_atomic_bridge_chain_enable() advances to priv->next_bridge and
calls next_bridge->funcs->atomic_enable() a second time while priv->active is
false.

On disable, drm_atomic_bridge_chain_disable() walks encoder->bridge_chain in
reverse order and calls next_bridge->funcs->atomic_disable() before
tegra_dbi_atomic_disable() runs.  At that point priv->active is still false
and the pins are in RGB video mode, so tegra_dbi_dbi_command() rejects all
panel disable DCS commands with -ENODEV.  If the panel's disable callback
still returns 0, drm_panel_disable() marks panel->enabled = false on that
failed first call and skips the second call inside tegra_dbi_atomic_disable()
so the panel never receives its disable commands; if it propagates -ENODEV,
the panel disable sequence and its msleep() delays run twice.

[ ... ]

> +int tegra_dc_dbi_probe(struct tegra_dc *dc)
> +{
> +	struct device *dev = dc->dev;
> +	struct device_node *dbi_np __free(device_node) =
> +		of_get_available_child_by_name(dev_of_node(dev), "dbi");
> +	struct mipi_dbi_device *dbidev;
> +	struct tegra_dbi_priv *priv;
> +	struct device_node *np;
> +	u32 interface = 0;
> +	int ret;
> +
> +	/* Missing node means that DBI is not used, continue DC probe */
> +	if (!dbi_np)
> +		return 0;
> +
> +	of_property_read_u32(dbi_np, "nvidia,interface", &interface);
> +	if (interface != 0 && interface != 1)
> +		return dev_err_probe(dev, -EINVAL, "Wrong interface value: %d\n", interface);
> +
> +	priv = devm_drm_bridge_alloc(dev, struct tegra_dbi_priv, bridge,
> +				     &tegra_dbi_funcs);
> +	if (IS_ERR(priv))
> +		return PTR_ERR(priv);
> +
> +	priv->dc = dc;
> +	priv->dev = dev;
> +	priv->interface = &tegra_dbi_idx[interface];
> +
> +	/* Initialize MIPI DBI interface */
> +	mutex_init(&priv->dbi.cmdlock);
> +	priv->dbi.command = tegra_dbi_dbi_command;
> +
> +	priv->dbi_host.dev = dev;
> +	priv->dbi_host.dbi = &priv->dbi;
> +	priv->dbi_host.ops = &tegra_dbi_host_ops;
> +
> +	priv->bridge.of_node = dbi_np;

[Severity: Medium]
Does declaring dbi_np with __free(device_node) drop the OF node reference as
soon as tegra_dc_dbi_probe() returns while priv->bridge.of_node keeps using
the pointer?

Neither devm_drm_bridge_alloc() nor devm_drm_bridge_add() takes a reference
on bridge->of_node, so when tegra_dc_dbi_probe() exits, of_node_put(dbi_np)
releases the reference obtained from of_get_available_child_by_name() before
tegra_dbi_host_attach() and bridge lookup helpers dereference
priv->bridge.of_node.

[1] https://lore.kernel.org/r/weWUeY3nRGCfNVcl2RuY5g@nvidia.com

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261122081820.53199-1-clamor95@gmail.com?part=12

      reply	other threads:[~2026-11-22  8:43 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-22  8:18 [PATCH v8 00/12] drm/tegra: Add support for Tegra20/Tegra30 8-bit CPU interface Svyatoslav Ryhel
2026-11-22  8:18 ` [PATCH v8 01/12] drm: Add MIPI DBI bus support for MIPI DBI Type A and B Svyatoslav Ryhel
2026-11-22  8:18 ` [PATCH v8 02/12] drm/panel: panel-hitachi-tx10d07vm0baa: Convert to use MIPI DBI bus Svyatoslav Ryhel
2026-11-22  8:18 ` [PATCH v8 03/12] drm/panel: panel-hitachi-tx10d07vm0baa: Convert to mipi_dbi_write_seq_multi() Svyatoslav Ryhel
2026-11-22  8:18 ` [PATCH v8 04/12] drm/panel: panel-lg-lh400wv3: Convert to use MIPI DBI bus Svyatoslav Ryhel
2026-11-22  8:18 ` [PATCH v8 05/12] drm/panel: panel-lg-lh400wv3: Convert to mipi_dbi_write_seq_multi() Svyatoslav Ryhel
2026-11-22  8:18 ` [PATCH v8 06/12] drm/tegra: dc: Add elements required by Tegra MIPI DBI Svyatoslav Ryhel
2026-11-22  8:18 ` [PATCH v8 07/12] dt-bindings: display: tegra: Document Tegra20 DSI port Svyatoslav Ryhel
2026-11-22  8:18 ` [PATCH v8 08/12] drm/tegra: output: Make panel parsing configurable Svyatoslav Ryhel
2026-11-22  8:18 ` [PATCH v8 09/12] drm/tegra: Convert to use atomic versions of drm_encoder_helper_funcs Svyatoslav Ryhel
2026-11-22  8:18 ` [PATCH v8 10/12] drm/tegra: rgb: Parameterize configuration based on bus flags Svyatoslav Ryhel
2026-11-22  8:18 ` [PATCH v8 11/12] dt-bindings: display: tegra: Document 8-bit CPU parallel interface Svyatoslav Ryhel
2026-11-22  8:18 ` [PATCH v8 12/12] drm/tegra: Add support for 8-bit CPU interface Svyatoslav Ryhel
2026-11-22  8:43   ` sashiko-bot [this message]

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=sashiko-outbox-227839@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=clamor95@gmail.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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