Skip to contentSkip to conversation

drm/msm: DSI DSC video mode fixes

PATCH In review Jonathan Marek 4 participants 21 messages Nov 14, 2023 – Dec 7, 2023

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v2 cover drm/msm: DSI DSC video mode fixes

v2: added new patches (first two patches) to get DSC video mode running with the upstream DPU driver (tested with the vtdr6130 panel)

Jonathan Marek (6):
drm/msm/dpu: fix video mode DSC for DSI
drm/msm/dsi: set video mode widebus enable bit when widebus is enabled drm/msm/dsi: set VIDEO_COMPRESSION_MODE_CTRL_WC (fix video mode DSC) drm/msm/dsi: add a comment to explain pkt_per_line encoding drm/msm/dsi: support DSC configurations with slice_per_pkt > 1 drm/msm/dsi: fix DSC for the bonded DSI case

 drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.c   |  2 +-
 .../gpu/drm/msm/disp/dpu1/dpu_encoder_phys.h  |  2 +-
 .../drm/msm/disp/dpu1/dpu_encoder_phys_vid.c  | 11 ++++
 drivers/gpu/drm/msm/disp/dpu1/dpu_hw_intf.c   | 13 ++++-
 drivers/gpu/drm/msm/disp/dpu1/dpu_hw_intf.h   |  1 +
 drivers/gpu/drm/msm/dsi/dsi.h                 |  3 +-
 drivers/gpu/drm/msm/dsi/dsi.xml.h             |  1 +
 drivers/gpu/drm/msm/dsi/dsi_host.c            | 50 ++++++++++---------
 drivers/gpu/drm/msm/dsi/dsi_manager.c         |  2 +-
 include/drm/drm_mipi_dsi.h                    |  1 +
 10 files changed, 58 insertions(+), 28 deletions(-)
Signature · 1 line
2.26.1
#1 lore raw

PATCH v2 1/6 drm/msm/dpu: fix video mode DSC for DSI

Add necessary DPU changes for DSC to work with DSI video mode.

Note this changes the logic to enable HCTL to match downstream, it will now be enabled for the no-DSC no-widebus case.

---
 drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.c         |  2 +-
 drivers/gpu/drm/msm/disp/dpu1/dpu_encoder_phys.h    |  2 +-
 .../gpu/drm/msm/disp/dpu1/dpu_encoder_phys_vid.c    | 11 +++++++++++
 drivers/gpu/drm/msm/disp/dpu1/dpu_hw_intf.c         | 13 ++++++++++++-
 drivers/gpu/drm/msm/disp/dpu1/dpu_hw_intf.h         |  1 +
 5 files changed, 26 insertions(+), 3 deletions(-)
drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.c +1 -1
index 1cf7ff6caff4..d745c8678b9d 100644
@@ -2477,7 +2477,7 @@ enum dpu_intf_mode dpu_encoder_get_intf_mode(struct drm_encoder *encoder)
 	return INTF_MODE_NONE;
 }
 
-unsigned int dpu_encoder_helper_get_dsc(struct dpu_encoder_phys *phys_enc)
+unsigned int dpu_encoder_helper_get_dsc(const struct dpu_encoder_phys *phys_enc)
 {
 	struct drm_encoder *encoder = phys_enc->parent;
 	struct dpu_encoder_virt *dpu_enc = to_dpu_encoder_virt(encoder);
drivers/gpu/drm/msm/disp/dpu1/dpu_encoder_phys.h +1 -1
index 6f04c3d56e77..7e27a7da0887 100644
@@ -332,7 +332,7 @@ static inline enum dpu_3d_blend_mode dpu_encoder_helper_get_3d_blend_mode(
  *   used for this encoder.
  * @phys_enc: Pointer to physical encoder structure
  */
-unsigned int dpu_encoder_helper_get_dsc(struct dpu_encoder_phys *phys_enc);
+unsigned int dpu_encoder_helper_get_dsc(const struct dpu_encoder_phys *phys_enc);
 
 /**
  * dpu_encoder_helper_split_config - split display configuration helper function
drivers/gpu/drm/msm/disp/dpu1/dpu_encoder_phys_vid.c +11 -0
index a01fda711883..df10800a9615 100644
@@ -100,6 +100,8 @@ static void drm_mode_to_intf_timing_params(
 	}
 
 	timing->wide_bus_en = dpu_encoder_is_widebus_enabled(phys_enc->parent);
+	if (dpu_encoder_helper_get_dsc(phys_enc))
+		timing->compression_en = true;
 
 	/*
 	 * for DP, divide the horizonal parameters by 2 when
@@ -112,6 +114,15 @@ static void drm_mode_to_intf_timing_params(
 		timing->h_front_porch = timing->h_front_porch >> 1;
 		timing->hsync_pulse_width = timing->hsync_pulse_width >> 1;
 	}
+
+	/*
+	 * for DSI, if compression is enabled, then divide the horizonal active
+	 * timing parameters by compression ratio.
+	 */
+	if (phys_enc->hw_intf->cap->type != INTF_DP && timing->compression_en) {
+		timing->width = timing->width / 3; /* XXX: don't assume 3:1 compression ratio */
+		timing->xres = timing->width;
+	}
 }
 
 static u32 get_horizontal_total(const struct dpu_hw_intf_timing_params *timing)
drivers/gpu/drm/msm/disp/dpu1/dpu_hw_intf.c +12 -1
index e8b8908d3e12..d6fe45a6da2d 100644
@@ -166,10 +166,21 @@ static void dpu_hw_intf_setup_timing_engine(struct dpu_hw_intf *ctx,
 	 * video timing. It is recommended to enable it for all cases, except
 	 * if compression is enabled in 1 pixel per clock mode
 	 */
+	if (!p->compression_en || p->wide_bus_en)
+		intf_cfg2 |= INTF_CFG2_DATA_HCTL_EN;
+
 	if (p->wide_bus_en)
-		intf_cfg2 |= INTF_CFG2_DATABUS_WIDEN | INTF_CFG2_DATA_HCTL_EN;
+		intf_cfg2 |= INTF_CFG2_DATABUS_WIDEN;
 
 	data_width = p->width;
+	if (p->wide_bus_en && !dp_intf)
+		data_width = p->width >> 1;
+
+	if (p->compression_en)
+		intf_cfg2 |= INTF_CFG2_DCE_DATA_COMPRESS;
+
+	if (p->compression_en && dp_intf)
+		DPU_ERROR("missing adjustments for DSC+DP\n");
 
 	hsync_data_start_x = hsync_start_x;
 	hsync_data_end_x =  hsync_start_x + data_width - 1;
drivers/gpu/drm/msm/disp/dpu1/dpu_hw_intf.h +1 -0
index c539025c418b..15a5fdadd0a0 100644
@@ -33,6 +33,7 @@ struct dpu_hw_intf_timing_params {
 	u32 hsync_skew;
 
 	bool wide_bus_en;
+	bool compression_en;
 };
 
 struct dpu_hw_intf_prog_fetch {
Signature · 1 line
2.26.1
#5 lore raw

PATCH v2 2/6 drm/msm/dsi: set video mode widebus enable bit when widebus is enabled

In reply to Jonathan Marek

The value returned by msm_dsi_wide_bus_enabled() doesn't match what the driver is doing in video mode. Fix that by actually enabling widebus for video mode.

Fixes efcbd6f9cdeb ("drm/msm/dsi: Enable widebus for DSI")
---
 drivers/gpu/drm/msm/dsi/dsi.xml.h  | 1 +
 drivers/gpu/drm/msm/dsi/dsi_host.c | 2 ++
 2 files changed, 3 insertions(+)
drivers/gpu/drm/msm/dsi/dsi.xml.h +1 -0
index 2a7d980e12c3..f0b3cdc020a1 100644
@@ -231,6 +231,7 @@ static inline uint32_t DSI_VID_CFG0_TRAFFIC_MODE(enum dsi_traffic_mode val)
 #define DSI_VID_CFG0_HSA_POWER_STOP				0x00010000
 #define DSI_VID_CFG0_HBP_POWER_STOP				0x00100000
 #define DSI_VID_CFG0_HFP_POWER_STOP				0x01000000
+#define DSI_VID_CFG0_DATABUS_WIDEN				0x02000000
 #define DSI_VID_CFG0_PULSE_MODE_HSA_HE				0x10000000
 
 #define REG_DSI_VID_CFG1					0x0000001c
drivers/gpu/drm/msm/dsi/dsi_host.c +2 -0
index deeecdfd6c4e..f2c1cbd08d4d 100644
@@ -745,6 +745,8 @@ static void dsi_ctrl_enable(struct msm_dsi_host *msm_host,
 		data |= DSI_VID_CFG0_TRAFFIC_MODE(dsi_get_traffic_mode(flags));
 		data |= DSI_VID_CFG0_DST_FORMAT(dsi_get_vid_fmt(mipi_fmt));
 		data |= DSI_VID_CFG0_VIRT_CHANNEL(msm_host->channel);
+		if (msm_dsi_host_is_wide_bus_enabled(&msm_host->base))
+			data |= DSI_VID_CFG0_DATABUS_WIDEN;
 		dsi_write(msm_host, REG_DSI_VID_CFG0, data);
 
 		/* Do not swap RGB colors */
Signature · 1 line
2.26.1
#10 lore raw

PATCH v2 3/6 drm/msm/dsi: set VIDEO_COMPRESSION_MODE_CTRL_WC (fix video mode DSC)

In reply to Jonathan Marek

Video mode DSC won't work if this field is not set correctly. Set it to fix video mode DSC (for slice_per_pkt==1 cases at least).

Fixes 08802f515c3 ("drm/msm/dsi: Add support for DSC configuration")
---
 drivers/gpu/drm/msm/dsi/dsi_host.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/msm/dsi/dsi_host.c +3 -0
index f2c1cbd08d4d..66f198e21a7e 100644
@@ -849,6 +849,7 @@ static void dsi_update_dsc_timing(struct msm_dsi_host *msm_host, bool is_cmd_mod
 	u32 slice_per_intf, total_bytes_per_intf;
 	u32 pkt_per_line;
 	u32 eol_byte_num;
+	u32 bytes_per_pkt;
 
 	/* first calculate dsc parameters and then program
 	 * compress mode registers
@@ -856,6 +857,7 @@ static void dsi_update_dsc_timing(struct msm_dsi_host *msm_host, bool is_cmd_mod
 	slice_per_intf = msm_dsc_get_slices_per_intf(dsc, hdisplay);
 
 	total_bytes_per_intf = dsc->slice_chunk_size * slice_per_intf;
+	bytes_per_pkt = dsc->slice_chunk_size; /* * slice_per_pkt; */
 
 	eol_byte_num = total_bytes_per_intf % 3;
 
@@ -893,6 +895,7 @@ static void dsi_update_dsc_timing(struct msm_dsi_host *msm_host, bool is_cmd_mod
 		dsi_write(msm_host, REG_DSI_COMMAND_COMPRESSION_MODE_CTRL, reg_ctrl);
 		dsi_write(msm_host, REG_DSI_COMMAND_COMPRESSION_MODE_CTRL2, reg_ctrl2);
 	} else {
+		reg |= DSI_VIDEO_COMPRESSION_MODE_CTRL_WC(bytes_per_pkt);
 		dsi_write(msm_host, REG_DSI_VIDEO_COMPRESSION_MODE_CTRL, reg);
 	}
 }
Signature · 1 line
2.26.1
#12 lore raw

PATCH v2 4/6 drm/msm/dsi: add a comment to explain pkt_per_line encoding

In reply to Jonathan Marek

Make it clear why the pkt_per_line value is being "divided by 2".

---
 drivers/gpu/drm/msm/dsi/dsi_host.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/msm/dsi/dsi_host.c +2 -0
index 66f198e21a7e..842765063b1b 100644
@@ -877,6 +877,8 @@ static void dsi_update_dsc_timing(struct msm_dsi_host *msm_host, bool is_cmd_mod
 	/* DSI_VIDEO_COMPRESSION_MODE & DSI_COMMAND_COMPRESSION_MODE
 	 * registers have similar offsets, so for below common code use
 	 * DSI_VIDEO_COMPRESSION_MODE_XXXX for setting bits
+	 *
+	 * pkt_per_line is log2 encoded, >>1 works for supported values (1,2,4)
 	 */
 	reg |= DSI_VIDEO_COMPRESSION_MODE_CTRL_PKT_PER_LINE(pkt_per_line >> 1);
 	reg |= DSI_VIDEO_COMPRESSION_MODE_CTRL_EOL_BYTE_NUM(eol_byte_num);
Signature · 1 line
2.26.1
#16 lore raw

PATCH v2 5/6 drm/msm/dsi: support DSC configurations with slice_per_pkt > 1

In reply to Jonathan Marek

Add a dsc_slice_per_pkt field to mipi_dsi_device struct and the necessary changes to msm driver to support this field.

Note that the removed "pkt_per_line = slice_per_intf * slice_per_pkt" comment is incorrect.

---
 drivers/gpu/drm/msm/dsi/dsi_host.c | 25 ++++++++++---------------
 include/drm/drm_mipi_dsi.h         |  1 +
 2 files changed, 11 insertions(+), 15 deletions(-)
drivers/gpu/drm/msm/dsi/dsi_host.c +10 -15
index 842765063b1b..892a463a7e03 100644
@@ -161,6 +161,7 @@ struct msm_dsi_host {
 
 	struct drm_display_mode *mode;
 	struct drm_dsc_config *dsc;
+	unsigned int dsc_slice_per_pkt;
 
 	/* connected device info */
 	unsigned int channel;
@@ -857,17 +858,10 @@ static void dsi_update_dsc_timing(struct msm_dsi_host *msm_host, bool is_cmd_mod
 	slice_per_intf = msm_dsc_get_slices_per_intf(dsc, hdisplay);
 
 	total_bytes_per_intf = dsc->slice_chunk_size * slice_per_intf;
-	bytes_per_pkt = dsc->slice_chunk_size; /* * slice_per_pkt; */
+	bytes_per_pkt = dsc->slice_chunk_size * msm_host->dsc_slice_per_pkt;
 
 	eol_byte_num = total_bytes_per_intf % 3;
-
-	/*
-	 * Typically, pkt_per_line = slice_per_intf * slice_per_pkt.
-	 *
-	 * Since the current driver only supports slice_per_pkt = 1,
-	 * pkt_per_line will be equal to slice per intf for now.
-	 */
-	pkt_per_line = slice_per_intf;
+	pkt_per_line = slice_per_intf / msm_host->dsc_slice_per_pkt;
 
 	if (is_cmd_mode) /* packet data type */
 		reg = DSI_COMMAND_COMPRESSION_MODE_CTRL_STREAM0_DATATYPE(MIPI_DSI_DCS_LONG_WRITE);
@@ -1004,12 +998,8 @@ static void dsi_timing_setup(struct msm_dsi_host *msm_host, bool is_bonded_dsi)
 		else
 			/*
 			 * When DSC is enabled, WC = slice_chunk_size * slice_per_pkt + 1.
-			 * Currently, the driver only supports default value of slice_per_pkt = 1
-			 *
-			 * TODO: Expand mipi_dsi_device struct to hold slice_per_pkt info
-			 *       and adjust DSC math to account for slice_per_pkt.
 			 */
-			wc = msm_host->dsc->slice_chunk_size + 1;
+			wc = msm_host->dsc->slice_chunk_size * msm_host->dsc_slice_per_pkt + 1;
 
 		dsi_write(msm_host, REG_DSI_CMD_MDP_STREAM0_CTRL,
 			DSI_CMD_MDP_STREAM0_CTRL_WORD_COUNT(wc) |
@@ -1636,8 +1626,13 @@ static int dsi_host_attach(struct mipi_dsi_host *host,
 	msm_host->lanes = dsi->lanes;
 	msm_host->format = dsi->format;
 	msm_host->mode_flags = dsi->mode_flags;
-	if (dsi->dsc)
+	if (dsi->dsc) {
 		msm_host->dsc = dsi->dsc;
+		msm_host->dsc_slice_per_pkt = dsi->dsc_slice_per_pkt;
+		/* for backwards compatibility, assume 1 if not set */
+		if (!msm_host->dsc_slice_per_pkt)
+			msm_host->dsc_slice_per_pkt = 1;
+	}
 
 	/* Some gpios defined in panel DT need to be controlled by host */
 	ret = dsi_host_init_panel_gpios(msm_host, &dsi->dev);
include/drm/drm_mipi_dsi.h +1 -0
index c9df0407980c..3e32fa52d94b 100644
@@ -193,6 +193,7 @@ struct mipi_dsi_device {
 	unsigned long hs_rate;
 	unsigned long lp_rate;
 	struct drm_dsc_config *dsc;
+	unsigned int dsc_slice_per_pkt;
 };
 
 #define MIPI_DSI_MODULE_PREFIX "mipi-dsi:"
Signature · 1 line
2.26.1
#19 lore raw

PATCH v2 6/6 drm/msm/dsi: fix DSC for the bonded DSI case

In reply to Jonathan Marek

For the bonded DSI case, DSC pic_width and timing calculations should use the width of a single panel instead of the total combined width.

---
 drivers/gpu/drm/msm/dsi/dsi.h         |  3 ++-
 drivers/gpu/drm/msm/dsi/dsi_host.c    | 20 +++++++++++---------
 drivers/gpu/drm/msm/dsi/dsi_manager.c |  2 +-
 3 files changed, 14 insertions(+), 11 deletions(-)
drivers/gpu/drm/msm/dsi/dsi.h +2 -1
index 28379b1af63f..3a641e69447c 100644
@@ -93,7 +93,8 @@ int msm_dsi_host_power_off(struct mipi_dsi_host *host);
 int msm_dsi_host_set_display_mode(struct mipi_dsi_host *host,
 				  const struct drm_display_mode *mode);
 enum drm_mode_status msm_dsi_host_check_dsc(struct mipi_dsi_host *host,
-					    const struct drm_display_mode *mode);
+					    const struct drm_display_mode *mode,
+					    bool is_bonded_dsi);
 unsigned long msm_dsi_host_get_mode_flags(struct mipi_dsi_host *host);
 int msm_dsi_host_register(struct mipi_dsi_host *host);
 void msm_dsi_host_unregister(struct mipi_dsi_host *host);
drivers/gpu/drm/msm/dsi/dsi_host.c +11 -9
index 892a463a7e03..cf06736e5a60 100644
@@ -940,8 +940,7 @@ static void dsi_timing_setup(struct msm_dsi_host *msm_host, bool is_bonded_dsi)
 			       mode->hdisplay, mode->vdisplay);
 			return;
 		}
-
-		dsc->pic_width = mode->hdisplay;
+		dsc->pic_width = hdisplay;
 		dsc->pic_height = mode->vdisplay;
 		DBG("Mode %dx%d\n", dsc->pic_width, dsc->pic_height);
 
@@ -952,6 +951,11 @@ static void dsi_timing_setup(struct msm_dsi_host *msm_host, bool is_bonded_dsi)
 		if (ret)
 			return;
 
+		if (msm_host->mode_flags & MIPI_DSI_MODE_VIDEO)
+			dsi_update_dsc_timing(msm_host, false, hdisplay);
+		else
+			dsi_update_dsc_timing(msm_host, true, hdisplay);
+
 		/* Divide the display by 3 but keep back/font porch and
 		 * pulse width same
 		 */
@@ -968,9 +972,6 @@ static void dsi_timing_setup(struct msm_dsi_host *msm_host, bool is_bonded_dsi)
 	}
 
 	if (msm_host->mode_flags & MIPI_DSI_MODE_VIDEO) {
-		if (msm_host->dsc)
-			dsi_update_dsc_timing(msm_host, false, mode->hdisplay);
-
 		dsi_write(msm_host, REG_DSI_ACTIVE_H,
 			DSI_ACTIVE_H_START(ha_start) |
 			DSI_ACTIVE_H_END(ha_end));
@@ -989,9 +990,6 @@ static void dsi_timing_setup(struct msm_dsi_host *msm_host, bool is_bonded_dsi)
 			DSI_ACTIVE_VSYNC_VPOS_START(vs_start) |
 			DSI_ACTIVE_VSYNC_VPOS_END(vs_end));
 	} else {		/* command mode */
-		if (msm_host->dsc)
-			dsi_update_dsc_timing(msm_host, true, mode->hdisplay);
-
 		/* image data and 1 byte write_memory_start cmd */
 		if (!msm_host->dsc)
 			wc = hdisplay * dsi_get_bpp(msm_host->format) / 8 + 1;
@@ -2479,7 +2477,8 @@ int msm_dsi_host_set_display_mode(struct mipi_dsi_host *host,
 }
 
 enum drm_mode_status msm_dsi_host_check_dsc(struct mipi_dsi_host *host,
-					    const struct drm_display_mode *mode)
+					    const struct drm_display_mode *mode,
+					    bool is_bonded_dsi)
 {
 	struct msm_dsi_host *msm_host = to_msm_dsi_host(host);
 	struct drm_dsc_config *dsc = msm_host->dsc;
@@ -2489,6 +2488,9 @@ enum drm_mode_status msm_dsi_host_check_dsc(struct mipi_dsi_host *host,
 	if (!msm_host->dsc)
 		return MODE_OK;
 
+	if (is_bonded_dsi)
+		pic_width = mode->hdisplay / 2;
+
 	if (pic_width % dsc->slice_width) {
 		pr_err("DSI: pic_width %d has to be multiple of slice %d\n",
 		       pic_width, dsc->slice_width);
drivers/gpu/drm/msm/dsi/dsi_manager.c +1 -1
index 896f369fdd53..2ca1a7ca3659 100644
@@ -455,7 +455,7 @@ static enum drm_mode_status dsi_mgr_bridge_mode_valid(struct drm_bridge *bridge,
 			return MODE_ERROR;
 	}
 
-	return msm_dsi_host_check_dsc(host, mode);
+	return msm_dsi_host_check_dsc(host, mode, IS_BONDED_DSI());
 }
 
 static const struct drm_bridge_funcs dsi_mgr_bridge_funcs = {
Signature · 1 line
2.26.1
Reviewed-by on v2 2/6
#6 lore raw

Re: [PATCH v2 2/6] drm/msm/dsi: set video mode widebus enable bit when widebus is enabled

In reply to Jonathan Marek
Quoted 11 lines · Jonathan Marek

The value returned by msm_dsi_wide_bus_enabled() doesn't match what the driver is doing in video mode. Fix that by actually enabling widebus for video mode.

Fixes efcbd6f9cdeb ("drm/msm/dsi: Enable widebus for DSI")
---
 drivers/gpu/drm/msm/dsi/dsi.xml.h  | 1 +
 drivers/gpu/drm/msm/dsi/dsi_host.c | 2 ++
 2 files changed, 3 insertions(+)
Signature · 2 lines
With best wishes
Dmitry
#7 lore raw

Re: [PATCH v2 2/6] drm/msm/dsi: set video mode widebus enable bit when widebus is enabled

In reply to Jonathan Marek
Quoted 17 lines · Jonathan Marek

The value returned by msm_dsi_wide_bus_enabled() doesn't match what the driver is doing in video mode. Fix that by actually enabling widebus for video mode.

Fixes efcbd6f9cdeb ("drm/msm/dsi: Enable widebus for DSI")
---
 drivers/gpu/drm/msm/dsi/dsi.xml.h  | 1 +
 drivers/gpu/drm/msm/dsi/dsi_host.c | 2 ++
 2 files changed, 3 insertions(+)
drivers/gpu/drm/msm/dsi/dsi.xml.h +0 -0
index 2a7d980e12c3..f0b3cdc020a1 100644

drivers/gpu/drm/msm/dsi/dsi.xml.h static inline uint32_t DSI_VID_CFG0_TRAFFIC_MODE(enum dsi_traffic_mode val) · line 234

Quoted 4 lines
drivers/gpu/drm/msm/dsi/dsi.xml.h +1 -0
@@ -231,6 +231,7 @@ static inline uint32_t DSI_VID_CFG0_TRAFFIC_MODE(enum dsi_traffic_mode val)
 #define DSI_VID_CFG0_HSA_POWER_STOP                            0x00010000
 #define DSI_VID_CFG0_HBP_POWER_STOP                            0x00100000
 #define DSI_VID_CFG0_HFP_POWER_STOP                            0x01000000
+#define DSI_VID_CFG0_DATABUS_WIDEN                             0x02000000

BTW, could you please push this register to mesa?

Quoted 3 lines
drivers/gpu/drm/msm/dsi/dsi.xml.h +0 -0
 #define DSI_VID_CFG0_PULSE_MODE_HSA_HE                         0x10000000
 
 #define REG_DSI_VID_CFG1                                       0x0000001c
Signature · 2 lines
With best wishes
Dmitry
Reviewed-by on v2 3/6
#11 lore raw

Re: [PATCH v2 3/6] drm/msm/dsi: set VIDEO_COMPRESSION_MODE_CTRL_WC (fix video mode DSC)

In reply to Jonathan Marek
Quoted 9 lines · Jonathan Marek

Video mode DSC won't work if this field is not set correctly. Set it to fix video mode DSC (for slice_per_pkt==1 cases at least).

Fixes 08802f515c3 ("drm/msm/dsi: Add support for DSC configuration")
---
 drivers/gpu/drm/msm/dsi/dsi_host.c | 3 +++
 1 file changed, 3 insertions(+)

--
With best wishes
Dmitry

#13 lore raw

Re: [PATCH v2 4/6] drm/msm/dsi: add a comment to explain pkt_per_line encoding

In reply to Jonathan Marek
Quoted 13 lines · Jonathan Marek

Make it clear why the pkt_per_line value is being "divided by 2".

---
 drivers/gpu/drm/msm/dsi/dsi_host.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/msm/dsi/dsi_host.c +0 -0
index 66f198e21a7e..842765063b1b 100644

drivers/gpu/drm/msm/dsi/dsi_host.c static void dsi_update_dsc_timing(struct msm_dsi_host *msm_host, bool is_cmd_mod · line 883

Quoted 7 lines
drivers/gpu/drm/msm/dsi/dsi_host.c +2 -0
@@ -877,6 +877,8 @@ static void dsi_update_dsc_timing(struct msm_dsi_host *msm_host, bool is_cmd_mod
        /* DSI_VIDEO_COMPRESSION_MODE & DSI_COMMAND_COMPRESSION_MODE
         * registers have similar offsets, so for below common code use
         * DSI_VIDEO_COMPRESSION_MODE_XXXX for setting bits
+        *
+        * pkt_per_line is log2 encoded, >>1 works for supported values (1,2,4)
         */
        reg |= DSI_VIDEO_COMPRESSION_MODE_CTRL_PKT_PER_LINE(pkt_per_line >> 1);

Should we switch to ffs() or fls() instead?

Quoted 4 lines
drivers/gpu/drm/msm/dsi/dsi_host.c +0 -1
        reg |= DSI_VIDEO_COMPRESSION_MODE_CTRL_EOL_BYTE_NUM(eol_byte_num);
--

2.26.1

Signature · 2 lines
With best wishes
Dmitry
#17 lore raw

Re: [PATCH v2 5/6] drm/msm/dsi: support DSC configurations with slice_per_pkt > 1

In reply to Jonathan Marek
Quoted 79 lines · Jonathan Marek

Add a dsc_slice_per_pkt field to mipi_dsi_device struct and the necessary changes to msm driver to support this field.

Note that the removed "pkt_per_line = slice_per_intf * slice_per_pkt" comment is incorrect.

---
 drivers/gpu/drm/msm/dsi/dsi_host.c | 25 ++++++++++---------------
 include/drm/drm_mipi_dsi.h         |  1 +
 2 files changed, 11 insertions(+), 15 deletions(-)
drivers/gpu/drm/msm/dsi/dsi_host.c +10 -15
index 842765063b1b..892a463a7e03 100644
@@ -161,6 +161,7 @@ struct msm_dsi_host {
 
        struct drm_display_mode *mode;
        struct drm_dsc_config *dsc;
+       unsigned int dsc_slice_per_pkt;
 
        /* connected device info */
        unsigned int channel;
@@ -857,17 +858,10 @@ static void dsi_update_dsc_timing(struct msm_dsi_host *msm_host, bool is_cmd_mod
        slice_per_intf = msm_dsc_get_slices_per_intf(dsc, hdisplay);
 
        total_bytes_per_intf = dsc->slice_chunk_size * slice_per_intf;
-       bytes_per_pkt = dsc->slice_chunk_size; /* * slice_per_pkt; */
+       bytes_per_pkt = dsc->slice_chunk_size * msm_host->dsc_slice_per_pkt;
 
        eol_byte_num = total_bytes_per_intf % 3;
-
-       /*
-        * Typically, pkt_per_line = slice_per_intf * slice_per_pkt.
-        *
-        * Since the current driver only supports slice_per_pkt = 1,
-        * pkt_per_line will be equal to slice per intf for now.
-        */
-       pkt_per_line = slice_per_intf;
+       pkt_per_line = slice_per_intf / msm_host->dsc_slice_per_pkt;
 
        if (is_cmd_mode) /* packet data type */
                reg = DSI_COMMAND_COMPRESSION_MODE_CTRL_STREAM0_DATATYPE(MIPI_DSI_DCS_LONG_WRITE);
@@ -1004,12 +998,8 @@ static void dsi_timing_setup(struct msm_dsi_host *msm_host, bool is_bonded_dsi)
                else
                        /*
                         * When DSC is enabled, WC = slice_chunk_size * slice_per_pkt + 1.
-                        * Currently, the driver only supports default value of slice_per_pkt = 1
-                        *
-                        * TODO: Expand mipi_dsi_device struct to hold slice_per_pkt info
-                        *       and adjust DSC math to account for slice_per_pkt.
                         */
-                       wc = msm_host->dsc->slice_chunk_size + 1;
+                       wc = msm_host->dsc->slice_chunk_size * msm_host->dsc_slice_per_pkt + 1;
 
                dsi_write(msm_host, REG_DSI_CMD_MDP_STREAM0_CTRL,
                        DSI_CMD_MDP_STREAM0_CTRL_WORD_COUNT(wc) |
@@ -1636,8 +1626,13 @@ static int dsi_host_attach(struct mipi_dsi_host *host,
        msm_host->lanes = dsi->lanes;
        msm_host->format = dsi->format;
        msm_host->mode_flags = dsi->mode_flags;
-       if (dsi->dsc)
+       if (dsi->dsc) {
                msm_host->dsc = dsi->dsc;
+               msm_host->dsc_slice_per_pkt = dsi->dsc_slice_per_pkt;
+               /* for backwards compatibility, assume 1 if not set */
+               if (!msm_host->dsc_slice_per_pkt)
+                       msm_host->dsc_slice_per_pkt = 1;
+       }
 
        /* Some gpios defined in panel DT need to be controlled by host */
        ret = dsi_host_init_panel_gpios(msm_host, &dsi->dev);
include/drm/drm_mipi_dsi.h +0 -0
index c9df0407980c..3e32fa52d94b 100644

include/drm/drm_mipi_dsi.h struct mipi_dsi_device { · line 196

Quoted 4 lines
include/drm/drm_mipi_dsi.h +1 -0
@@ -193,6 +193,7 @@ struct mipi_dsi_device {
        unsigned long hs_rate;
        unsigned long lp_rate;
        struct drm_dsc_config *dsc;
+       unsigned int dsc_slice_per_pkt;

Missing documentation. Also maybe this chunk should go into a separate patch so that it can gain more attention from DRM maintainers?

Quoted 6 lines
include/drm/drm_mipi_dsi.h +0 -1
 };
 
 #define MIPI_DSI_MODULE_PREFIX "mipi-dsi:"
--

2.26.1

Signature · 2 lines
With best wishes
Dmitry
#20 lore raw

Re: [PATCH v2 6/6] drm/msm/dsi: fix DSC for the bonded DSI case

In reply to Jonathan Marek
Quoted 5 lines · Jonathan Marek

For the bonded DSI case, DSC pic_width and timing calculations should use the width of a single panel instead of the total combined width.

Fixes tag?

I'll wait for the Tested-by by Marijn, otherwise LGTM.

Quoted 25 lines
---
 drivers/gpu/drm/msm/dsi/dsi.h         |  3 ++-
 drivers/gpu/drm/msm/dsi/dsi_host.c    | 20 +++++++++++---------
 drivers/gpu/drm/msm/dsi/dsi_manager.c |  2 +-
 3 files changed, 14 insertions(+), 11 deletions(-)
drivers/gpu/drm/msm/dsi/dsi.h +2 -1
index 28379b1af63f..3a641e69447c 100644
@@ -93,7 +93,8 @@ int msm_dsi_host_power_off(struct mipi_dsi_host *host);
 int msm_dsi_host_set_display_mode(struct mipi_dsi_host *host,
                                  const struct drm_display_mode *mode);
 enum drm_mode_status msm_dsi_host_check_dsc(struct mipi_dsi_host *host,
-                                           const struct drm_display_mode *mode);
+                                           const struct drm_display_mode *mode,
+                                           bool is_bonded_dsi);
 unsigned long msm_dsi_host_get_mode_flags(struct mipi_dsi_host *host);
 int msm_dsi_host_register(struct mipi_dsi_host *host);
 void msm_dsi_host_unregister(struct mipi_dsi_host *host);
drivers/gpu/drm/msm/dsi/dsi_host.c +0 -0
index 892a463a7e03..cf06736e5a60 100644

drivers/gpu/drm/msm/dsi/dsi_host.c static void dsi_timing_setup(struct msm_dsi_host *msm_host, bool is_bonded_dsi) · line 943

Quoted 4 lines
drivers/gpu/drm/msm/dsi/dsi_host.c +0 -1
@@ -940,8 +940,7 @@ static void dsi_timing_setup(struct msm_dsi_host *msm_host, bool is_bonded_dsi)
                               mode->hdisplay, mode->vdisplay);
                        return;
                }
-

Nit: keep it please.

Quoted 73 lines
drivers/gpu/drm/msm/dsi/dsi_host.c +11 -8
-               dsc->pic_width = mode->hdisplay;
+               dsc->pic_width = hdisplay;
                dsc->pic_height = mode->vdisplay;
                DBG("Mode %dx%d\n", dsc->pic_width, dsc->pic_height);
 
@@ -952,6 +951,11 @@ static void dsi_timing_setup(struct msm_dsi_host *msm_host, bool is_bonded_dsi)
                if (ret)
                        return;
 
+               if (msm_host->mode_flags & MIPI_DSI_MODE_VIDEO)
+                       dsi_update_dsc_timing(msm_host, false, hdisplay);
+               else
+                       dsi_update_dsc_timing(msm_host, true, hdisplay);
+
                /* Divide the display by 3 but keep back/font porch and
                 * pulse width same
                 */
@@ -968,9 +972,6 @@ static void dsi_timing_setup(struct msm_dsi_host *msm_host, bool is_bonded_dsi)
        }
 
        if (msm_host->mode_flags & MIPI_DSI_MODE_VIDEO) {
-               if (msm_host->dsc)
-                       dsi_update_dsc_timing(msm_host, false, mode->hdisplay);
-
                dsi_write(msm_host, REG_DSI_ACTIVE_H,
                        DSI_ACTIVE_H_START(ha_start) |
                        DSI_ACTIVE_H_END(ha_end));
@@ -989,9 +990,6 @@ static void dsi_timing_setup(struct msm_dsi_host *msm_host, bool is_bonded_dsi)
                        DSI_ACTIVE_VSYNC_VPOS_START(vs_start) |
                        DSI_ACTIVE_VSYNC_VPOS_END(vs_end));
        } else {                /* command mode */
-               if (msm_host->dsc)
-                       dsi_update_dsc_timing(msm_host, true, mode->hdisplay);
-
                /* image data and 1 byte write_memory_start cmd */
                if (!msm_host->dsc)
                        wc = hdisplay * dsi_get_bpp(msm_host->format) / 8 + 1;
@@ -2479,7 +2477,8 @@ int msm_dsi_host_set_display_mode(struct mipi_dsi_host *host,
 }
 
 enum drm_mode_status msm_dsi_host_check_dsc(struct mipi_dsi_host *host,
-                                           const struct drm_display_mode *mode)
+                                           const struct drm_display_mode *mode,
+                                           bool is_bonded_dsi)
 {
        struct msm_dsi_host *msm_host = to_msm_dsi_host(host);
        struct drm_dsc_config *dsc = msm_host->dsc;
@@ -2489,6 +2488,9 @@ enum drm_mode_status msm_dsi_host_check_dsc(struct mipi_dsi_host *host,
        if (!msm_host->dsc)
                return MODE_OK;
 
+       if (is_bonded_dsi)
+               pic_width = mode->hdisplay / 2;
+
        if (pic_width % dsc->slice_width) {
                pr_err("DSI: pic_width %d has to be multiple of slice %d\n",
                       pic_width, dsc->slice_width);
drivers/gpu/drm/msm/dsi/dsi_manager.c +1 -2
index 896f369fdd53..2ca1a7ca3659 100644
@@ -455,7 +455,7 @@ static enum drm_mode_status dsi_mgr_bridge_mode_valid(struct drm_bridge *bridge,
                        return MODE_ERROR;
        }
 
-       return msm_dsi_host_check_dsc(host, mode);
+       return msm_dsi_host_check_dsc(host, mode, IS_BONDED_DSI());
 }
 
 static const struct drm_bridge_funcs dsi_mgr_bridge_funcs = {
--

2.26.1

Signature · 2 lines
With best wishes
Dmitry
#2 lore raw

Re: [PATCH v2 1/6] drm/msm/dpu: fix video mode DSC for DSI

In reply to Jonathan Marek
Quoted 20 lines · Jonathan Marek

Add necessary DPU changes for DSC to work with DSI video mode.

Note this changes the logic to enable HCTL to match downstream, it will now be enabled for the no-DSC no-widebus case.

---
 drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.c         |  2 +-
 drivers/gpu/drm/msm/disp/dpu1/dpu_encoder_phys.h    |  2 +-
 .../gpu/drm/msm/disp/dpu1/dpu_encoder_phys_vid.c    | 11 +++++++++++
 drivers/gpu/drm/msm/disp/dpu1/dpu_hw_intf.c         | 13 ++++++++++++-
 drivers/gpu/drm/msm/disp/dpu1/dpu_hw_intf.h         |  1 +
 5 files changed, 26 insertions(+), 3 deletions(-)
drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.c +0 -0
index 1cf7ff6caff4..d745c8678b9d 100644

drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.c enum dpu_intf_mode dpu_encoder_get_intf_mode(struct drm_encoder *encoder) · line 2480

Quoted 5 lines
drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.c +1 -1
@@ -2477,7 +2477,7 @@ enum dpu_intf_mode dpu_encoder_get_intf_mode(struct drm_encoder *encoder)
        return INTF_MODE_NONE;
 }
 
-unsigned int dpu_encoder_helper_get_dsc(struct dpu_encoder_phys *phys_enc)
+unsigned int dpu_encoder_helper_get_dsc(const struct dpu_encoder_phys *phys_enc)

Why?

Quoted 30 lines
drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.c +0 -0
 {
        struct drm_encoder *encoder = phys_enc->parent;
        struct dpu_encoder_virt *dpu_enc = to_dpu_encoder_virt(encoder);
drivers/gpu/drm/msm/disp/dpu1/dpu_encoder_phys.h +1 -1
index 6f04c3d56e77..7e27a7da0887 100644
@@ -332,7 +332,7 @@ static inline enum dpu_3d_blend_mode dpu_encoder_helper_get_3d_blend_mode(
  *   used for this encoder.
  * @phys_enc: Pointer to physical encoder structure
  */
-unsigned int dpu_encoder_helper_get_dsc(struct dpu_encoder_phys *phys_enc);
+unsigned int dpu_encoder_helper_get_dsc(const struct dpu_encoder_phys *phys_enc);
 
 /**
  * dpu_encoder_helper_split_config - split display configuration helper function
drivers/gpu/drm/msm/disp/dpu1/dpu_encoder_phys_vid.c +2 -0
index a01fda711883..df10800a9615 100644
@@ -100,6 +100,8 @@ static void drm_mode_to_intf_timing_params(
        }
 
        timing->wide_bus_en = dpu_encoder_is_widebus_enabled(phys_enc->parent);
+       if (dpu_encoder_helper_get_dsc(phys_enc))
+               timing->compression_en = true;
 
        /*
         * for DP, divide the horizonal parameters by 2 when

drivers/gpu/drm/msm/disp/dpu1/dpu_encoder_phys_vid.c static void drm_mode_to_intf_timing_params( · line 123

Quoted 10 lines
drivers/gpu/drm/msm/disp/dpu1/dpu_encoder_phys_vid.c +7 -0
@@ -112,6 +114,15 @@ static void drm_mode_to_intf_timing_params(
                timing->h_front_porch = timing->h_front_porch >> 1;
                timing->hsync_pulse_width = timing->hsync_pulse_width >> 1;
        }
+
+       /*
+        * for DSI, if compression is enabled, then divide the horizonal active
+        * timing parameters by compression ratio.
+        */
+       if (phys_enc->hw_intf->cap->type != INTF_DP && timing->compression_en) {
+               timing->width = timing->width / 3; /* XXX: don't assume 3:1 compression ratio */

Is this /3 from bpp / compressed_bpp?

Quoted 22 lines
drivers/gpu/drm/msm/disp/dpu1/dpu_encoder_phys_vid.c +2 -0
+               timing->xres = timing->width;
+       }
 }
 
 static u32 get_horizontal_total(const struct dpu_hw_intf_timing_params *timing)
drivers/gpu/drm/msm/disp/dpu1/dpu_hw_intf.c +5 -1
index e8b8908d3e12..d6fe45a6da2d 100644
@@ -166,10 +166,21 @@ static void dpu_hw_intf_setup_timing_engine(struct dpu_hw_intf *ctx,
         * video timing. It is recommended to enable it for all cases, except
         * if compression is enabled in 1 pixel per clock mode
         */
+       if (!p->compression_en || p->wide_bus_en)
+               intf_cfg2 |= INTF_CFG2_DATA_HCTL_EN;
+
        if (p->wide_bus_en)
-               intf_cfg2 |= INTF_CFG2_DATABUS_WIDEN | INTF_CFG2_DATA_HCTL_EN;
+               intf_cfg2 |= INTF_CFG2_DATABUS_WIDEN;
 
        data_width = p->width;
+       if (p->wide_bus_en && !dp_intf)

drivers/gpu/drm/msm/disp/dpu1/dpu_hw_intf.c static void dpu_hw_intf_setup_timing_engine(struct dpu_hw_intf *ctx, · line 186

Quoted 10 lines
drivers/gpu/drm/msm/disp/dpu1/dpu_hw_intf.c +7 -0
+               data_width = p->width >> 1;
+
+       if (p->compression_en)
+               intf_cfg2 |= INTF_CFG2_DCE_DATA_COMPRESS;
+
+       if (p->compression_en && dp_intf)
+               DPU_ERROR("missing adjustments for DSC+DP\n");
 
        hsync_data_start_x = hsync_start_x;
        hsync_data_end_x =  hsync_start_x + data_width - 1;

This should go into a separate commit with the proper justification.

Quoted 15 lines
drivers/gpu/drm/msm/disp/dpu1/dpu_hw_intf.h +1 -1
index c539025c418b..15a5fdadd0a0 100644
@@ -33,6 +33,7 @@ struct dpu_hw_intf_timing_params {
        u32 hsync_skew;
 
        bool wide_bus_en;
+       bool compression_en;
 };
 
 struct dpu_hw_intf_prog_fetch {
--

2.26.1

Signature · 2 lines
With best wishes
Dmitry
#3 lore raw

Re: [PATCH v2 1/6] drm/msm/dpu: fix video mode DSC for DSI

Quoted 24 lines · Dmitry Baryshkov
Quoted 23 lines · Jonathan Marek

Add necessary DPU changes for DSC to work with DSI video mode.

Note this changes the logic to enable HCTL to match downstream, it will now be enabled for the no-DSC no-widebus case.

---
  drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.c         |  2 +-
  drivers/gpu/drm/msm/disp/dpu1/dpu_encoder_phys.h    |  2 +-
  .../gpu/drm/msm/disp/dpu1/dpu_encoder_phys_vid.c    | 11 +++++++++++
  drivers/gpu/drm/msm/disp/dpu1/dpu_hw_intf.c         | 13 ++++++++++++-
  drivers/gpu/drm/msm/disp/dpu1/dpu_hw_intf.h         |  1 +
  5 files changed, 26 insertions(+), 3 deletions(-)
drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.c +0 -0
index 1cf7ff6caff4..d745c8678b9d 100644
@@ -2477,7 +2477,7 @@ enum dpu_intf_mode dpu_encoder_get_intf_mode(struct drm_encoder *encoder)
         return INTF_MODE_NONE;
  }
 
Quoted 5 lines

drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.c enum dpu_intf_mode dpu_encoder_get_intf_mode(struct drm_encoder *encoder) · line 2480

Quoted 2 lines
drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.c +1 -1
-unsigned int dpu_encoder_helper_get_dsc(struct dpu_encoder_phys *phys_enc)
+unsigned int dpu_encoder_helper_get_dsc(const struct dpu_encoder_phys *phys_enc)

Why?

drm_mode_to_intf_timing_params has "phys_enc" pointer declared as const, so one of them needs to change to call dpu_encoder_helper_get_dsc

Quoted 27 lines
Quoted 27 lines
drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.c +0 -0
  {
         struct drm_encoder *encoder = phys_enc->parent;
         struct dpu_encoder_virt *dpu_enc = to_dpu_encoder_virt(encoder);
drivers/gpu/drm/msm/disp/dpu1/dpu_encoder_phys.h +1 -1
index 6f04c3d56e77..7e27a7da0887 100644
@@ -332,7 +332,7 @@ static inline enum dpu_3d_blend_mode dpu_encoder_helper_get_3d_blend_mode(
   *   used for this encoder.
   * @phys_enc: Pointer to physical encoder structure
   */
-unsigned int dpu_encoder_helper_get_dsc(struct dpu_encoder_phys *phys_enc);
+unsigned int dpu_encoder_helper_get_dsc(const struct dpu_encoder_phys *phys_enc);
 
  /**
   * dpu_encoder_helper_split_config - split display configuration helper function
drivers/gpu/drm/msm/disp/dpu1/dpu_encoder_phys_vid.c +2 -0
index a01fda711883..df10800a9615 100644
@@ -100,6 +100,8 @@ static void drm_mode_to_intf_timing_params(
         }
 
         timing->wide_bus_en = dpu_encoder_is_widebus_enabled(phys_enc->parent);
+       if (dpu_encoder_helper_get_dsc(phys_enc))
+               timing->compression_en = true;
 
Quoted 16 lines

drivers/gpu/drm/msm/disp/dpu1/dpu_encoder_phys_vid.c static void drm_mode_to_intf_timing_params( · line 123

Quoted 13 lines
drivers/gpu/drm/msm/disp/dpu1/dpu_encoder_phys_vid.c +7 -0
         /*
          * for DP, divide the horizonal parameters by 2 when
@@ -112,6 +114,15 @@ static void drm_mode_to_intf_timing_params(
                 timing->h_front_porch = timing->h_front_porch >> 1;
                 timing->hsync_pulse_width = timing->hsync_pulse_width >> 1;
         }
+
+       /*
+        * for DSI, if compression is enabled, then divide the horizonal active
+        * timing parameters by compression ratio.
+        */
+       if (phys_enc->hw_intf->cap->type != INTF_DP && timing->compression_en) {
+               timing->width = timing->width / 3; /* XXX: don't assume 3:1 compression ratio */

Is this /3 from bpp / compressed_bpp?

It is the compression ratio of DSC for 8bpc (24bpp) compressed to 8bpp. DSI driver doesn't support any other cases so this assumption should be OK for now (the other common ratio is 3.75 for 10bpc compressed to 8bpp - from downstream driver it appears this would mean a division by 3.75 here).

Quoted 30 lines
Quoted 30 lines
drivers/gpu/drm/msm/disp/dpu1/dpu_encoder_phys_vid.c +2 -0
+               timing->xres = timing->width;
+       }
  }
 
  static u32 get_horizontal_total(const struct dpu_hw_intf_timing_params *timing)
drivers/gpu/drm/msm/disp/dpu1/dpu_hw_intf.c +12 -1
index e8b8908d3e12..d6fe45a6da2d 100644
@@ -166,10 +166,21 @@ static void dpu_hw_intf_setup_timing_engine(struct dpu_hw_intf *ctx,
          * video timing. It is recommended to enable it for all cases, except
          * if compression is enabled in 1 pixel per clock mode
          */
+       if (!p->compression_en || p->wide_bus_en)
+               intf_cfg2 |= INTF_CFG2_DATA_HCTL_EN;
+
         if (p->wide_bus_en)
-               intf_cfg2 |= INTF_CFG2_DATABUS_WIDEN | INTF_CFG2_DATA_HCTL_EN;
+               intf_cfg2 |= INTF_CFG2_DATABUS_WIDEN;
 
         data_width = p->width;
+       if (p->wide_bus_en && !dp_intf)
+               data_width = p->width >> 1;
+
+       if (p->compression_en)
+               intf_cfg2 |= INTF_CFG2_DCE_DATA_COMPRESS;
+
+       if (p->compression_en && dp_intf)
+               DPU_ERROR("missing adjustments for DSC+DP\n");
 
Quoted 5 lines

drivers/gpu/drm/msm/disp/dpu1/dpu_hw_intf.c static void dpu_hw_intf_setup_timing_engine(struct dpu_hw_intf *ctx, · line 186

Quoted 2 lines
drivers/gpu/drm/msm/disp/dpu1/dpu_hw_intf.c +0 -0
         hsync_data_start_x = hsync_start_x;
         hsync_data_end_x =  hsync_start_x + data_width - 1;

This should go into a separate commit with the proper justification.

All of it? setting the INTF_CFG2_DCE_DATA_COMPRESS flag at least doesn't make sense to make a separate patch. And DSI widebus is only used with DSC (and always used when available), so IMO also in the scope of this commit.

Quoted 17 lines
Quoted 15 lines
drivers/gpu/drm/msm/disp/dpu1/dpu_hw_intf.h +1 -1
index c539025c418b..15a5fdadd0a0 100644
@@ -33,6 +33,7 @@ struct dpu_hw_intf_timing_params {
         u32 hsync_skew;
 
         bool wide_bus_en;
+       bool compression_en;
  };
 
  struct dpu_hw_intf_prog_fetch {
--

2.26.1

#14 lore raw

Re: [PATCH v2 4/6] drm/msm/dsi: add a comment to explain pkt_per_line encoding

In reply to Dmitry Baryshkov
Quoted 9 lines · Dmitry Baryshkov
Quoted 8 lines · Jonathan Marek

Make it clear why the pkt_per_line value is being "divided by 2".

---
  drivers/gpu/drm/msm/dsi/dsi_host.c | 2 ++
  1 file changed, 2 insertions(+)
Quoted 15 lines

drivers/gpu/drm/msm/dsi/dsi_host.c static void dsi_update_dsc_timing(struct msm_dsi_host *msm_host, bool is_cmd_mod · line 883

Quoted 12 lines
drivers/gpu/drm/msm/dsi/dsi_host.c +2 -0
index 66f198e21a7e..842765063b1b 100644
@@ -877,6 +877,8 @@ static void dsi_update_dsc_timing(struct msm_dsi_host *msm_host, bool is_cmd_mod
         /* DSI_VIDEO_COMPRESSION_MODE & DSI_COMMAND_COMPRESSION_MODE
          * registers have similar offsets, so for below common code use
          * DSI_VIDEO_COMPRESSION_MODE_XXXX for setting bits
+        *
+        * pkt_per_line is log2 encoded, >>1 works for supported values (1,2,4)
          */
         reg |= DSI_VIDEO_COMPRESSION_MODE_CTRL_PKT_PER_LINE(pkt_per_line >> 1);

Should we switch to ffs() or fls() instead?

Just a ffs() on its own can be confusing as well (without the information that only powers of two are possible), I think like this is better.

Quoted 6 lines
Quoted 4 lines
drivers/gpu/drm/msm/dsi/dsi_host.c +0 -1
         reg |= DSI_VIDEO_COMPRESSION_MODE_CTRL_EOL_BYTE_NUM(eol_byte_num);
--

2.26.1

#4 lore raw

Re: [PATCH v2 1/6] drm/msm/dpu: fix video mode DSC for DSI

In reply to Jonathan Marek
Quoted 122 lines · Jonathan Marek
Quoted 25 lines · Dmitry Baryshkov
Quoted 24 lines · Jonathan Marek

Add necessary DPU changes for DSC to work with DSI video mode.

Note this changes the logic to enable HCTL to match downstream, it will now be enabled for the no-DSC no-widebus case.

---
  drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.c         |  2 +- drivers/gpu/drm/msm/disp/dpu1/dpu_encoder_phys.h    |  2 +- .../gpu/drm/msm/disp/dpu1/dpu_encoder_phys_vid.c    | 11 +++++++++++ drivers/gpu/drm/msm/disp/dpu1/dpu_hw_intf.c         | 13 ++++++++++++- drivers/gpu/drm/msm/disp/dpu1/dpu_hw_intf.h         |  1 +

  5 files changed, 26 insertions(+), 3 deletions(-)
drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.c +0 -0
index 1cf7ff6caff4..d745c8678b9d 100644
@@ -2477,7 +2477,7 @@ enum dpu_intf_mode 
 dpu_encoder_get_intf_mode(struct drm_encoder *encoder)
          return INTF_MODE_NONE;
   }
 
Quoted 7 lines

drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.c enum dpu_intf_mode · line 2483

Quoted 4 lines
drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.c +1 -1
-unsigned int dpu_encoder_helper_get_dsc(struct dpu_encoder_phys 
 *phys_enc)
+unsigned int dpu_encoder_helper_get_dsc(const struct 
 dpu_encoder_phys *phys_enc)

Why?

drm_mode_to_intf_timing_params has "phys_enc" pointer declared as const, so one of them needs to change to call dpu_encoder_helper_get_dsc

Quoted 40 lines
Quoted 40 lines

  {
         struct drm_encoder *encoder = phys_enc->parent; struct dpu_encoder_virt *dpu_enc = to_dpu_encoder_virt(encoder);

drivers/gpu/drm/msm/disp/dpu1/dpu_encoder_phys.h +0 -0
index 6f04c3d56e77..7e27a7da0887 100644
@@ -332,7 +332,7 @@ static inline enum dpu_3d_blend_mode 

dpu_encoder_helper_get_3d_blend_mode(
   *   used for this encoder.
   * @phys_enc: Pointer to physical encoder structure */
-unsigned int dpu_encoder_helper_get_dsc(struct dpu_encoder_phys *phys_enc);
+unsigned int dpu_encoder_helper_get_dsc(const struct dpu_encoder_phys *phys_enc);

  /**
   * dpu_encoder_helper_split_config - split display configuration helper function

drivers/gpu/drm/msm/disp/dpu1/dpu_encoder_phys_vid.c +5 -0
index a01fda711883..df10800a9615 100644
@@ -100,6 +100,8 @@ static void drm_mode_to_intf_timing_params(
          }
 
          timing->wide_bus_en = dpu_encoder_is_widebus_enabled(phys_enc->parent);
+       if (dpu_encoder_helper_get_dsc(phys_enc))
+               timing->compression_en = true;
 
          /*
           * for DP, divide the horizonal parameters by 2 when
@@ -112,6 +114,15 @@ static void drm_mode_to_intf_timing_params(
                  timing->h_front_porch = timing->h_front_porch >> 1;
                  timing->hsync_pulse_width = timing->hsync_pulse_width >> 1;
          }
+
+       /*
+        * for DSI, if compression is enabled, then divide the 

horizonal active

Quoted 9 lines
Quoted 6 lines

+        * timing parameters by compression ratio.
+        */
+       if (phys_enc->hw_intf->cap->type != INTF_DP && timing->compression_en) {
+               timing->width = timing->width / 3; /* XXX: don't assume 3:1 compression ratio */

Is this /3 from bpp / compressed_bpp?

It is the compression ratio of DSC for 8bpc (24bpp) compressed to 8bpp. DSI driver doesn't support any other cases so this assumption should be OK for now (the other common ratio is 3.75 for 10bpc compressed to 8bpp
- from downstream driver it appears this would mean a division by 3.75
here).

Quoted 32 lines
Quoted 32 lines

+               timing->xres = timing->width;
+       }
  }

  static u32 get_horizontal_total(const struct dpu_hw_intf_timing_params *timing)

drivers/gpu/drm/msm/disp/dpu1/dpu_hw_intf.c +12 -1
index e8b8908d3e12..d6fe45a6da2d 100644
@@ -166,10 +166,21 @@ static void 
 dpu_hw_intf_setup_timing_engine(struct dpu_hw_intf *ctx,
           * video timing. It is recommended to enable it for all cases, except
           * if compression is enabled in 1 pixel per clock mode
           */
+       if (!p->compression_en || p->wide_bus_en)
+               intf_cfg2 |= INTF_CFG2_DATA_HCTL_EN;
+
          if (p->wide_bus_en)
-               intf_cfg2 |= INTF_CFG2_DATABUS_WIDEN | 
 INTF_CFG2_DATA_HCTL_EN;
+               intf_cfg2 |= INTF_CFG2_DATABUS_WIDEN;
 
          data_width = p->width;
+       if (p->wide_bus_en && !dp_intf)
+               data_width = p->width >> 1;
+
+       if (p->compression_en)
+               intf_cfg2 |= INTF_CFG2_DCE_DATA_COMPRESS;
+
+       if (p->compression_en && dp_intf)
+               DPU_ERROR("missing adjustments for DSC+DP\n");
 
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

         hsync_data_start_x = hsync_start_x; hsync_data_end_x =  hsync_start_x + data_width - 1;

This should go into a separate commit with the proper justification.

All of it? setting the INTF_CFG2_DCE_DATA_COMPRESS flag at least doesn't make sense to make a separate patch. And DSI widebus is only used with DSC (and always used when available), so IMO also in the scope of this commit.

Excuse me for being not precise. I'm more concerned about INTF_CFG2_DATA_HCTL_EN change. They way you have added it doesn't have anything to do with the DSC support. If we ever want to revert just that clause to check anything, we wil have to revert the whole DSC-DSI-video commit, which doesn't seem correct.

Quoted 18 lines
Quoted 18 lines
Quoted 16 lines
drivers/gpu/drm/msm/disp/dpu1/dpu_hw_intf.h +1 -0
index c539025c418b..15a5fdadd0a0 100644
@@ -33,6 +33,7 @@ struct dpu_hw_intf_timing_params {
          u32 hsync_skew;
 
          bool wide_bus_en;
+       bool compression_en;
   };
 
   struct dpu_hw_intf_prog_fetch {
Signature · 1 line
2.26.1
Signature · 2 lines
With best wishes
Dmitry
Reviewed-by
#15 lore raw

Re: [PATCH v2 4/6] drm/msm/dsi: add a comment to explain pkt_per_line encoding

In reply to Jonathan Marek
Quoted 28 lines · Jonathan Marek
Quoted 9 lines · Dmitry Baryshkov
Quoted 8 lines · Jonathan Marek

Make it clear why the pkt_per_line value is being "divided by 2".

---
  drivers/gpu/drm/msm/dsi/dsi_host.c | 2 ++

  1 file changed, 2 insertions(+)
Quoted 17 lines
Quoted 6 lines
drivers/gpu/drm/msm/dsi/dsi_host.c +0 -0
index 66f198e21a7e..842765063b1b 100644
@@ -877,6 +877,8 @@ static void dsi_update_dsc_timing(struct 

msm_dsi_host *msm_host, bool is_cmd_mod

Quoted 8 lines

         /* DSI_VIDEO_COMPRESSION_MODE & DSI_COMMAND_COMPRESSION_MODE
          * registers have similar offsets, so for below common code use
          * DSI_VIDEO_COMPRESSION_MODE_XXXX for setting bits
+        *
+        * pkt_per_line is log2 encoded, >>1 works for supported values (1,2,4)
          */
         reg |= DSI_VIDEO_COMPRESSION_MODE_CTRL_PKT_PER_LINE(pkt_per_line >> 1);

Should we switch to ffs() or fls() instead?

Quoted 1 line

Just a ffs() on its own can be confusing as well (without the information that only powers of two are possible), I think like this is better.

Sounds fair. Could you please then add if (pkt_per_line > 4) drm_warn("pkt_per_line too big");

With that in place:

Quoted 7 lines
Quoted 7 lines
Quoted 5 lines

         reg |= DSI_VIDEO_COMPRESSION_MODE_CTRL_EOL_BYTE_NUM(eol_byte_num);

Signature · 1 line
2.26.1
Signature · 2 lines
With best wishes
Dmitry
reviewer Reviewed-by on v2 2/6
#8 lore raw

Re: [PATCH v2 2/6] drm/msm/dsi: set video mode widebus enable bit when widebus is enabled

In reply to Jonathan Marek
Quoted 6 lines · Jonathan Marek

The value returned by msm_dsi_wide_bus_enabled() doesn't match what the driver is doing in video mode. Fix that by actually enabling widebus for video mode.

Fixes efcbd6f9cdeb ("drm/msm/dsi: Enable widebus for DSI")

Conditional r-b assuming this will be submitted to mesa, otherwise it'll disappear when the next person updates and regenerates these bindings.

Quoted 33 lines
---
 drivers/gpu/drm/msm/dsi/dsi.xml.h  | 1 +
 drivers/gpu/drm/msm/dsi/dsi_host.c | 2 ++
 2 files changed, 3 insertions(+)
drivers/gpu/drm/msm/dsi/dsi.xml.h +1 -0
index 2a7d980e12c3..f0b3cdc020a1 100644
@@ -231,6 +231,7 @@ static inline uint32_t DSI_VID_CFG0_TRAFFIC_MODE(enum dsi_traffic_mode val)
 #define DSI_VID_CFG0_HSA_POWER_STOP				0x00010000
 #define DSI_VID_CFG0_HBP_POWER_STOP				0x00100000
 #define DSI_VID_CFG0_HFP_POWER_STOP				0x01000000
+#define DSI_VID_CFG0_DATABUS_WIDEN				0x02000000
 #define DSI_VID_CFG0_PULSE_MODE_HSA_HE				0x10000000
 
 #define REG_DSI_VID_CFG1					0x0000001c
drivers/gpu/drm/msm/dsi/dsi_host.c +2 -0
index deeecdfd6c4e..f2c1cbd08d4d 100644
@@ -745,6 +745,8 @@ static void dsi_ctrl_enable(struct msm_dsi_host *msm_host,
 		data |= DSI_VID_CFG0_TRAFFIC_MODE(dsi_get_traffic_mode(flags));
 		data |= DSI_VID_CFG0_DST_FORMAT(dsi_get_vid_fmt(mipi_fmt));
 		data |= DSI_VID_CFG0_VIRT_CHANNEL(msm_host->channel);
+		if (msm_dsi_host_is_wide_bus_enabled(&msm_host->base))
+			data |= DSI_VID_CFG0_DATABUS_WIDEN;
 		dsi_write(msm_host, REG_DSI_VID_CFG0, data);
 
 		/* Do not swap RGB colors */
Signature · 1 line
2.26.1
#18 lore raw

Re: [PATCH v2 5/6] drm/msm/dsi: support DSC configurations with slice_per_pkt > 1

In reply to Jonathan Marek
Quoted 5 lines · Jonathan Marek

Add a dsc_slice_per_pkt field to mipi_dsi_device struct and the necessary changes to msm driver to support this field.

Note that the removed "pkt_per_line = slice_per_intf * slice_per_pkt" comment is incorrect.

Hi John,

Thanks for catching the typo.

Quoted 40 lines
---
  drivers/gpu/drm/msm/dsi/dsi_host.c | 25 ++++++++++---------------
  include/drm/drm_mipi_dsi.h         |  1 +
  2 files changed, 11 insertions(+), 15 deletions(-)
drivers/gpu/drm/msm/dsi/dsi_host.c +3 -9
index 842765063b1b..892a463a7e03 100644
@@ -161,6 +161,7 @@ struct msm_dsi_host {
 
  	struct drm_display_mode *mode;
  	struct drm_dsc_config *dsc;
+	unsigned int dsc_slice_per_pkt;
 
  	/* connected device info */
  	unsigned int channel;
@@ -857,17 +858,10 @@ static void dsi_update_dsc_timing(struct msm_dsi_host *msm_host, bool is_cmd_mod
  	slice_per_intf = msm_dsc_get_slices_per_intf(dsc, hdisplay);
 
  	total_bytes_per_intf = dsc->slice_chunk_size * slice_per_intf;
-	bytes_per_pkt = dsc->slice_chunk_size; /* * slice_per_pkt; */
+	bytes_per_pkt = dsc->slice_chunk_size * msm_host->dsc_slice_per_pkt;
 
  	eol_byte_num = total_bytes_per_intf % 3;
-
-	/*
-	 * Typically, pkt_per_line = slice_per_intf * slice_per_pkt.
-	 *
-	 * Since the current driver only supports slice_per_pkt = 1,
-	 * pkt_per_line will be equal to slice per intf for now.
-	 */
-	pkt_per_line = slice_per_intf;
+	pkt_per_line = slice_per_intf / msm_host->dsc_slice_per_pkt;
 
  	if (is_cmd_mode) /* packet data type */
  		reg = DSI_COMMAND_COMPRESSION_MODE_CTRL_STREAM0_DATATYPE(MIPI_DSI_DCS_LONG_WRITE);

drivers/gpu/drm/msm/dsi/dsi_host.c static void dsi_timing_setup(struct msm_dsi_host *msm_host, bool is_bonded_dsi) · line 1002

Quoted 10 lines
drivers/gpu/drm/msm/dsi/dsi_host.c +1 -5
@@ -1004,12 +998,8 @@ static void dsi_timing_setup(struct msm_dsi_host *msm_host, bool is_bonded_dsi)
  		else
  			/*
  			 * When DSC is enabled, WC = slice_chunk_size * slice_per_pkt + 1.
-			 * Currently, the driver only supports default value of slice_per_pkt = 1
-			 *
-			 * TODO: Expand mipi_dsi_device struct to hold slice_per_pkt info
-			 *       and adjust DSC math to account for slice_per_pkt.
  			 */
-			wc = msm_host->dsc->slice_chunk_size + 1;
+			wc = msm_host->dsc->slice_chunk_size * msm_host->dsc_slice_per_pkt + 1;

Maybe we can reuse bytes_per_pkt here.

Quoted 23 lines
drivers/gpu/drm/msm/dsi/dsi_host.c +6 -1
  		dsi_write(msm_host, REG_DSI_CMD_MDP_STREAM0_CTRL,
  			DSI_CMD_MDP_STREAM0_CTRL_WORD_COUNT(wc) |
@@ -1636,8 +1626,13 @@ static int dsi_host_attach(struct mipi_dsi_host *host,
  	msm_host->lanes = dsi->lanes;
  	msm_host->format = dsi->format;
  	msm_host->mode_flags = dsi->mode_flags;
-	if (dsi->dsc)
+	if (dsi->dsc) {
  		msm_host->dsc = dsi->dsc;
+		msm_host->dsc_slice_per_pkt = dsi->dsc_slice_per_pkt;
+		/* for backwards compatibility, assume 1 if not set */
+		if (!msm_host->dsc_slice_per_pkt)
+			msm_host->dsc_slice_per_pkt = 1;
+	}
 
  	/* Some gpios defined in panel DT need to be controlled by host */
  	ret = dsi_host_init_panel_gpios(msm_host, &dsi->dev);
include/drm/drm_mipi_dsi.h +0 -0
index c9df0407980c..3e32fa52d94b 100644

include/drm/drm_mipi_dsi.h struct mipi_dsi_device { · line 195

Quoted 3 lines
include/drm/drm_mipi_dsi.h +0 -0
@@ -193,6 +193,7 @@ struct mipi_dsi_device {
  	unsigned long hs_rate;
  	unsigned long lp_rate;
  	struct drm_dsc_config *dsc;

Any reason for not putting this in drm_dsc_config?

Thanks,

Jessica Zhang

Quoted 7 lines
include/drm/drm_mipi_dsi.h +1 -0
+	unsigned int dsc_slice_per_pkt;
  };
 
  #define MIPI_DSI_MODULE_PREFIX "mipi-dsi:"
Signature · 1 line
2.26.1
Reviewed-by on v2 2/6
#9 lore raw

Re: [PATCH v2 2/6] drm/msm/dsi: set video mode widebus enable bit when widebus is enabled

In reply to Jonathan Marek
Quoted 28 lines · Jonathan Marek

The value returned by msm_dsi_wide_bus_enabled() doesn't match what the driver is doing in video mode. Fix that by actually enabling widebus for video mode.

Fixes efcbd6f9cdeb ("drm/msm/dsi: Enable widebus for DSI")
---
  drivers/gpu/drm/msm/dsi/dsi.xml.h  | 1 +
  drivers/gpu/drm/msm/dsi/dsi_host.c | 2 ++
  2 files changed, 3 insertions(+)
drivers/gpu/drm/msm/dsi/dsi.xml.h +1 -0
index 2a7d980e12c3..f0b3cdc020a1 100644
@@ -231,6 +231,7 @@ static inline uint32_t DSI_VID_CFG0_TRAFFIC_MODE(enum dsi_traffic_mode val)
  #define DSI_VID_CFG0_HSA_POWER_STOP				0x00010000
  #define DSI_VID_CFG0_HBP_POWER_STOP				0x00100000
  #define DSI_VID_CFG0_HFP_POWER_STOP				0x01000000
+#define DSI_VID_CFG0_DATABUS_WIDEN				0x02000000
  #define DSI_VID_CFG0_PULSE_MODE_HSA_HE				0x10000000
 
  #define REG_DSI_VID_CFG1					0x0000001c
drivers/gpu/drm/msm/dsi/dsi_host.c +0 -0
index deeecdfd6c4e..f2c1cbd08d4d 100644

drivers/gpu/drm/msm/dsi/dsi_host.c static void dsi_ctrl_enable(struct msm_dsi_host *msm_host, · line 749

Quoted 5 lines
drivers/gpu/drm/msm/dsi/dsi_host.c +2 -0
@@ -745,6 +745,8 @@ static void dsi_ctrl_enable(struct msm_dsi_host *msm_host,
  		data |= DSI_VID_CFG0_TRAFFIC_MODE(dsi_get_traffic_mode(flags));
  		data |= DSI_VID_CFG0_DST_FORMAT(dsi_get_vid_fmt(mipi_fmt));
  		data |= DSI_VID_CFG0_VIRT_CHANNEL(msm_host->channel);
+		if (msm_dsi_host_is_wide_bus_enabled(&msm_host->base))
+			data |= DSI_VID_CFG0_DATABUS_WIDEN;

Hi Jonathan,

Now that widebus is enabled for video mode, I think you can also drop the TODO here [1]. Other than that, this LGTM.

Thanks,

Jessica Zhang

[1] https://elixir.bootlin.com/linux/v6.7-rc3/source/drivers/gpu/drm/msm/dsi/dsi_host.c#L772

Quoted 6 lines
drivers/gpu/drm/msm/dsi/dsi_host.c +0 -0
  		dsi_write(msm_host, REG_DSI_VID_CFG0, data);
 
  		/* Do not swap RGB colors */
Signature · 1 line
2.26.1