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 <[email protected]> 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/[email protected] -- Sashiko AI review ยท https://sashiko.dev/#/patchset/[email protected]?part=12
