Skip to contentSkip to conversation

drm/panel: lvds: Simplify mode parsing

PATCH Superseded Marek Vasut 3 participants 9 messages Mar 31, 2022 – Apr 2, 2022

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 drm/panel: lvds: Simplify mode parsing

The mode parsing is currently implemented in three steps:
of_get_display_timing() - DT panel-timing to struct display_timing videomode_from_timing() - struct display_timing to struct videomode drm_display_mode_from_videomode() - struct videomode to struct drm_display_mode

Replace all that with simple of_get_drm_panel_display_mode() call, which already populates struct drm_display_mode and then duplicate that mode in panel_lvds_get_modes() each time, since the mode does not change.

Nice bonus is the bus_flags parsed by of_get_drm_panel_display_mode() out of panel-timing DT node, which is used in subsequent patch to fix handling of 'de-active' DT property.

Cc Christoph Niedermaier <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Dmitry Osipenko <[email protected]>
Cc Laurent Pinchart <[email protected]>
Cc Robert Foss <[email protected]>
Cc Sam Ravnborg <[email protected]>
Cc Thomas Zimmermann <[email protected]>

To: [email protected]

---
 drivers/gpu/drm/panel/panel-lvds.c | 28 ++++++----------------------
 1 file changed, 6 insertions(+), 22 deletions(-)
drivers/gpu/drm/panel/panel-lvds.c +6 -22
index 27a1c9923b09..65c6a6e9e223 100644
@@ -30,7 +30,8 @@ struct panel_lvds {
 	const char *label;
 	unsigned int width;
 	unsigned int height;
-	struct videomode video_mode;
+	struct drm_display_mode dmode;
+	u32 bus_flags;
 	unsigned int bus_format;
 	bool data_mirror;
 
@@ -87,16 +88,15 @@ static int panel_lvds_get_modes(struct drm_panel *panel,
 	struct panel_lvds *lvds = to_panel_lvds(panel);
 	struct drm_display_mode *mode;
 
-	mode = drm_mode_create(connector->dev);
+	mode = drm_mode_duplicate(connector->dev, &lvds->dmode);
 	if (!mode)
 		return 0;
 
-	drm_display_mode_from_videomode(&lvds->video_mode, mode);
 	mode->type |= DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
 	drm_mode_probed_add(connector, mode);
 
-	connector->display_info.width_mm = lvds->width;
-	connector->display_info.height_mm = lvds->height;
+	connector->display_info.width_mm = lvds->dmode.width_mm;
+	connector->display_info.height_mm = lvds->dmode.height_mm;
 	drm_display_info_set_bus_formats(&connector->display_info,
 					 &lvds->bus_format, 1);
 	connector->display_info.bus_flags = lvds->data_mirror
@@ -116,7 +116,6 @@ static const struct drm_panel_funcs panel_lvds_funcs = {
 static int panel_lvds_parse_dt(struct panel_lvds *lvds)
 {
 	struct device_node *np = lvds->dev->of_node;
-	struct display_timing timing;
 	int ret;
 
 	ret = of_drm_get_panel_orientation(np, &lvds->orientation);
@@ -125,28 +124,13 @@ static int panel_lvds_parse_dt(struct panel_lvds *lvds)
 		return ret;
 	}
 
-	ret = of_get_display_timing(np, "panel-timing", &timing);
+	ret = of_get_drm_panel_display_mode(np, &lvds->dmode, &lvds->bus_flags);
 	if (ret < 0) {
 		dev_err(lvds->dev, "%pOF: problems parsing panel-timing (%d)\n",
 			np, ret);
 		return ret;
 	}
 
-	videomode_from_timing(&timing, &lvds->video_mode);
-
-	ret = of_property_read_u32(np, "width-mm", &lvds->width);
-	if (ret < 0) {
-		dev_err(lvds->dev, "%pOF: invalid or missing %s DT property\n",
-			np, "width-mm");
-		return -ENODEV;
-	}
-	ret = of_property_read_u32(np, "height-mm", &lvds->height);
-	if (ret < 0) {
-		dev_err(lvds->dev, "%pOF: invalid or missing %s DT property\n",
-			np, "height-mm");
-		return -ENODEV;
-	}
-
 	of_property_read_string(np, "label", &lvds->label);
 
 	ret = drm_of_lvds_get_data_mapping(np);
Signature · 1 line
2.35.1
#1 lore raw

PATCH 2/2 drm/panel: lvds: Use bus_flags from DT panel-timing property

This driver currently rewrites bus_flags based solely on the value of DT property 'data-mirror' and ignores bus_flags which might have been set in DT panel-timing node. Specificaly, the 'de-active' DT property sets DRM_BUS_FLAG_DE_ bus_flags.

Since of_get_drm_panel_display_mode() conveniently parses the bus_flags out of DT panel-timing property, just ORR them with bus_flags inferred from 'data-mirror' DT property and use the result as panel bus_flags.

This fixes handling of panels with 'panel-timing { de-active = <1>; };'.

Cc Christoph Niedermaier <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Dmitry Osipenko <[email protected]>
Cc Laurent Pinchart <[email protected]>
Cc Robert Foss <[email protected]>
Cc Sam Ravnborg <[email protected]>
Cc Thomas Zimmermann <[email protected]>

To: [email protected]

---
 drivers/gpu/drm/panel/panel-lvds.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/gpu/drm/panel/panel-lvds.c +4 -5
index 65c6a6e9e223..f11252fb00fe 100644
@@ -33,7 +33,6 @@ struct panel_lvds {
 	struct drm_display_mode dmode;
 	u32 bus_flags;
 	unsigned int bus_format;
-	bool data_mirror;
 
 	struct regulator *supply;
 
@@ -99,9 +98,7 @@ static int panel_lvds_get_modes(struct drm_panel *panel,
 	connector->display_info.height_mm = lvds->dmode.height_mm;
 	drm_display_info_set_bus_formats(&connector->display_info,
 					 &lvds->bus_format, 1);
-	connector->display_info.bus_flags = lvds->data_mirror
-					  ? DRM_BUS_FLAG_DATA_LSB_TO_MSB
-					  : DRM_BUS_FLAG_DATA_MSB_TO_LSB;
+	connector->display_info.bus_flags = lvds->bus_flags;
 	drm_connector_set_panel_orientation(connector, lvds->orientation);
 
 	return 1;
@@ -142,7 +139,9 @@ static int panel_lvds_parse_dt(struct panel_lvds *lvds)
 
 	lvds->bus_format = ret;
 
-	lvds->data_mirror = of_property_read_bool(np, "data-mirror");
+	lvds->bus_flags |= of_property_read_bool(np, "data-mirror") ?
+			   DRM_BUS_FLAG_DATA_LSB_TO_MSB :
+			   DRM_BUS_FLAG_DATA_MSB_TO_LSB;
 
 	return 0;
 }
Signature · 1 line
2.35.1
maintainer Reviewed-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] drm/panel: lvds: Use bus_flags from DT panel-timing property

Hi Marek,

Thank you for the patch.

Quoted 19 lines · Marek Vasut

This driver currently rewrites bus_flags based solely on the value of DT property 'data-mirror' and ignores bus_flags which might have been set in DT panel-timing node. Specificaly, the 'de-active' DT property sets DRM_BUS_FLAG_DE_ bus_flags.

Since of_get_drm_panel_display_mode() conveniently parses the bus_flags out of DT panel-timing property, just ORR them with bus_flags inferred from 'data-mirror' DT property and use the result as panel bus_flags.

This fixes handling of panels with 'panel-timing { de-active = <1>; };'.

Cc Christoph Niedermaier <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Dmitry Osipenko <[email protected]>
Cc Laurent Pinchart <[email protected]>
Cc Robert Foss <[email protected]>
Cc Sam Ravnborg <[email protected]>
Cc Thomas Zimmermann <[email protected]>
Quoted 1 line

To: [email protected]

Quoted 38 lines
---
 drivers/gpu/drm/panel/panel-lvds.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/gpu/drm/panel/panel-lvds.c +4 -5
index 65c6a6e9e223..f11252fb00fe 100644
@@ -33,7 +33,6 @@ struct panel_lvds {
 	struct drm_display_mode dmode;
 	u32 bus_flags;
 	unsigned int bus_format;
-	bool data_mirror;
 
 	struct regulator *supply;
 
@@ -99,9 +98,7 @@ static int panel_lvds_get_modes(struct drm_panel *panel,
 	connector->display_info.height_mm = lvds->dmode.height_mm;
 	drm_display_info_set_bus_formats(&connector->display_info,
 					 &lvds->bus_format, 1);
-	connector->display_info.bus_flags = lvds->data_mirror
-					  ? DRM_BUS_FLAG_DATA_LSB_TO_MSB
-					  : DRM_BUS_FLAG_DATA_MSB_TO_LSB;
+	connector->display_info.bus_flags = lvds->bus_flags;
 	drm_connector_set_panel_orientation(connector, lvds->orientation);
 
 	return 1;
@@ -142,7 +139,9 @@ static int panel_lvds_parse_dt(struct panel_lvds *lvds)
 
 	lvds->bus_format = ret;
 
-	lvds->data_mirror = of_property_read_bool(np, "data-mirror");
+	lvds->bus_flags |= of_property_read_bool(np, "data-mirror") ?
+			   DRM_BUS_FLAG_DATA_LSB_TO_MSB :
+			   DRM_BUS_FLAG_DATA_MSB_TO_LSB;
 
 	return 0;
 }
Signature · 3 lines
Regards,

Laurent Pinchart
Tested-by on v1 2/2
#3 lore raw

RE: [PATCH 2/2] drm/panel: lvds: Use bus_flags from DT panel-timing property

In reply to Marek Vasut

From: Marek Vasut [mailto:[email protected]]
Sent: Thursday, March 31, 2022 9:24 PM

Quoted 49 lines

This driver currently rewrites bus_flags based solely on the value of DT property 'data-mirror' and ignores bus_flags which might have been set in DT panel-timing node. Specificaly, the 'de-active' DT property sets DRM_BUS_FLAG_DE_ bus_flags.

Since of_get_drm_panel_display_mode() conveniently parses the bus_flags out of DT panel-timing property, just ORR them with bus_flags inferred from 'data-mirror' DT property and use the result as panel bus_flags.

This fixes handling of panels with 'panel-timing { de-active = <1>; };'.

Cc Christoph Niedermaier <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Dmitry Osipenko <[email protected]>
Cc Laurent Pinchart <[email protected]>
Cc Robert Foss <[email protected]>
Cc Sam Ravnborg <[email protected]>
Cc Thomas Zimmermann <[email protected]>

To: [email protected]

---
 drivers/gpu/drm/panel/panel-lvds.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/gpu/drm/panel/panel-lvds.c +1 -4
index 65c6a6e9e223..f11252fb00fe 100644
@@ -33,7 +33,6 @@ struct panel_lvds {
        struct drm_display_mode dmode;
        u32 bus_flags;
        unsigned int bus_format;
-       bool data_mirror;
 
        struct regulator *supply;
 
@@ -99,9 +98,7 @@ static int panel_lvds_get_modes(struct drm_panel *panel,
        connector->display_info.height_mm = lvds->dmode.height_mm;
        drm_display_info_set_bus_formats(&connector->display_info,
                                         &lvds->bus_format, 1);
-       connector->display_info.bus_flags = lvds->data_mirror
-                                         ? DRM_BUS_FLAG_DATA_LSB_TO_MSB
-                                         : DRM_BUS_FLAG_DATA_MSB_TO_LSB;
+       connector->display_info.bus_flags = lvds->bus_flags;
        drm_connector_set_panel_orientation(connector, lvds->orientation);
 
        return 1;

drivers/gpu/drm/panel/panel-lvds.c static int panel_lvds_parse_dt(struct panel_lvds *lvds) · line 147

Quoted 10 lines
drivers/gpu/drm/panel/panel-lvds.c +3 -1
@@ -142,7 +139,9 @@ static int panel_lvds_parse_dt(struct panel_lvds *lvds)
 
        lvds->bus_format = ret;
 
-       lvds->data_mirror = of_property_read_bool(np, "data-mirror");
+       lvds->bus_flags |= of_property_read_bool(np, "data-mirror") ?
+                          DRM_BUS_FLAG_DATA_LSB_TO_MSB :
+                          DRM_BUS_FLAG_DATA_MSB_TO_LSB;
 
        return 0;
 }

Regards
Christoph

maintainer
#4 lore raw
In reply to Marek Vasut

Hi Marek,

Thank you for the patch.

Quoted 32 lines · Marek Vasut

The mode parsing is currently implemented in three steps:
of_get_display_timing() - DT panel-timing to struct display_timing videomode_from_timing() - struct display_timing to struct videomode drm_display_mode_from_videomode() - struct videomode to struct drm_display_mode

Replace all that with simple of_get_drm_panel_display_mode() call, which already populates struct drm_display_mode and then duplicate that mode in panel_lvds_get_modes() each time, since the mode does not change.

Nice bonus is the bus_flags parsed by of_get_drm_panel_display_mode() out of panel-timing DT node, which is used in subsequent patch to fix handling of 'de-active' DT property.

Cc Christoph Niedermaier <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Dmitry Osipenko <[email protected]>
Cc Laurent Pinchart <[email protected]>
Cc Robert Foss <[email protected]>
Cc Sam Ravnborg <[email protected]>
Cc Thomas Zimmermann <[email protected]>

To: [email protected]

---
 drivers/gpu/drm/panel/panel-lvds.c | 28 ++++++----------------------
 1 file changed, 6 insertions(+), 22 deletions(-)
drivers/gpu/drm/panel/panel-lvds.c +0 -0
index 27a1c9923b09..65c6a6e9e223 100644

drivers/gpu/drm/panel/panel-lvds.c struct panel_lvds { · line 33

Quoted 5 lines
drivers/gpu/drm/panel/panel-lvds.c +1 -1
@@ -30,7 +30,8 @@ struct panel_lvds {
 	const char *label;
 	unsigned int width;
 	unsigned int height;
-	struct videomode video_mode;
+	struct drm_display_mode dmode;

"dmode" sounds a bit weird, I would have gone for just "mode", or "display_mode", but I don't mind much.

Quoted 48 lines
drivers/gpu/drm/panel/panel-lvds.c +5 -10
+	u32 bus_flags;
 	unsigned int bus_format;
 	bool data_mirror;
 
@@ -87,16 +88,15 @@ static int panel_lvds_get_modes(struct drm_panel *panel,
 	struct panel_lvds *lvds = to_panel_lvds(panel);
 	struct drm_display_mode *mode;
 
-	mode = drm_mode_create(connector->dev);
+	mode = drm_mode_duplicate(connector->dev, &lvds->dmode);
 	if (!mode)
 		return 0;
 
-	drm_display_mode_from_videomode(&lvds->video_mode, mode);
 	mode->type |= DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
 	drm_mode_probed_add(connector, mode);
 
-	connector->display_info.width_mm = lvds->width;
-	connector->display_info.height_mm = lvds->height;
+	connector->display_info.width_mm = lvds->dmode.width_mm;
+	connector->display_info.height_mm = lvds->dmode.height_mm;
 	drm_display_info_set_bus_formats(&connector->display_info,
 					 &lvds->bus_format, 1);
 	connector->display_info.bus_flags = lvds->data_mirror
@@ -116,7 +116,6 @@ static const struct drm_panel_funcs panel_lvds_funcs = {
 static int panel_lvds_parse_dt(struct panel_lvds *lvds)
 {
 	struct device_node *np = lvds->dev->of_node;
-	struct display_timing timing;
 	int ret;
 
 	ret = of_drm_get_panel_orientation(np, &lvds->orientation);
@@ -125,28 +124,13 @@ static int panel_lvds_parse_dt(struct panel_lvds *lvds)
 		return ret;
 	}
 
-	ret = of_get_display_timing(np, "panel-timing", &timing);
+	ret = of_get_drm_panel_display_mode(np, &lvds->dmode, &lvds->bus_flags);
 	if (ret < 0) {
 		dev_err(lvds->dev, "%pOF: problems parsing panel-timing (%d)\n",
 			np, ret);
 		return ret;
 	}
 
-	videomode_from_timing(&timing, &lvds->video_mode);
-
-	ret = of_property_read_u32(np, "width-mm", &lvds->width);
-	if (ret < 0) {

drivers/gpu/drm/panel/panel-lvds.c static int panel_lvds_parse_dt(struct panel_lvds *lvds) · line 148

Quoted 10 lines
drivers/gpu/drm/panel/panel-lvds.c +0 -10
-		dev_err(lvds->dev, "%pOF: invalid or missing %s DT property\n",
-			np, "width-mm");
-		return -ENODEV;
-	}
-	ret = of_property_read_u32(np, "height-mm", &lvds->height);
-	if (ret < 0) {
-		dev_err(lvds->dev, "%pOF: invalid or missing %s DT property\n",
-			np, "height-mm");
-		return -ENODEV;
-	}

of_get_drm_panel_display_mode() doesn't consider missing width-mm or height-mm properties as an error. Should we check here that ->width_mm and ->height_mm are not 0 ?

Quoted 4 lines
drivers/gpu/drm/panel/panel-lvds.c +0 -1
-
 	of_property_read_string(np, "label", &lvds->label);
 
 	ret = drm_of_lvds_get_data_mapping(np);
Signature · 3 lines
Regards,

Laurent Pinchart
#5 lore raw

On 4/1/22 17:48, Laurent Pinchart wrote:

Hi,

[...]

Quoted 5 lines
Quoted 5 lines
drivers/gpu/drm/panel/panel-lvds.c +0 -0
index 27a1c9923b09..65c6a6e9e223 100644
@@ -30,7 +30,8 @@ struct panel_lvds {
Quoted 8 lines

drivers/gpu/drm/panel/panel-lvds.c struct panel_lvds { · line 33

Quoted 5 lines
drivers/gpu/drm/panel/panel-lvds.c +1 -1
  	const char *label;
  	unsigned int width;
  	unsigned int height;
-	struct videomode video_mode;
+	struct drm_display_mode dmode;

"dmode" sounds a bit weird, I would have gone for just "mode", or "display_mode", but I don't mind much.

That's how the of_get_drm_panel_display_mode() parameter is called in drivers/gpu/drm/drm_modes.c , so I'll just keep it for consistency.

[...]

Quoted 10 lines
Quoted 10 lines
drivers/gpu/drm/panel/panel-lvds.c +0 -10
-	videomode_from_timing(&timing, &lvds->video_mode);
-
-	ret = of_property_read_u32(np, "width-mm", &lvds->width);
-	if (ret < 0) {
-		dev_err(lvds->dev, "%pOF: invalid or missing %s DT property\n",
-			np, "width-mm");
-		return -ENODEV;
-	}
-	ret = of_property_read_u32(np, "height-mm", &lvds->height);
-	if (ret < 0) {
Quoted 8 lines

drivers/gpu/drm/panel/panel-lvds.c static int panel_lvds_parse_dt(struct panel_lvds *lvds) · line 148

Quoted 4 lines
drivers/gpu/drm/panel/panel-lvds.c +0 -4
-		dev_err(lvds->dev, "%pOF: invalid or missing %s DT property\n",
-			np, "height-mm");
-		return -ENODEV;
-	}

of_get_drm_panel_display_mode() doesn't consider missing width-mm or height-mm properties as an error. Should we check here that ->width_mm and ->height_mm are not 0 ?

I wonder whether we should always require valid width-mm and height-mm DT property in of_get_drm_panel_display_mode() instead.

[...]

maintainer
#6 lore raw
Quoted 44 lines · Marek Vasut

On 4/1/22 17:48, Laurent Pinchart wrote:

Hi,

[...]

Quoted 5 lines
Quoted 5 lines
drivers/gpu/drm/panel/panel-lvds.c +0 -0
index 27a1c9923b09..65c6a6e9e223 100644
@@ -30,7 +30,8 @@ struct panel_lvds {
Quoted 8 lines

drivers/gpu/drm/panel/panel-lvds.c struct panel_lvds { · line 33

Quoted 5 lines
drivers/gpu/drm/panel/panel-lvds.c +1 -1
  	const char *label;
  	unsigned int width;
  	unsigned int height;
-	struct videomode video_mode;
+	struct drm_display_mode dmode;

"dmode" sounds a bit weird, I would have gone for just "mode", or "display_mode", but I don't mind much.

That's how the of_get_drm_panel_display_mode() parameter is called in drivers/gpu/drm/drm_modes.c , so I'll just keep it for consistency.

[...]

Quoted 10 lines
Quoted 10 lines
drivers/gpu/drm/panel/panel-lvds.c +0 -10
-	videomode_from_timing(&timing, &lvds->video_mode);
-
-	ret = of_property_read_u32(np, "width-mm", &lvds->width);
-	if (ret < 0) {
-		dev_err(lvds->dev, "%pOF: invalid or missing %s DT property\n",
-			np, "width-mm");
-		return -ENODEV;
-	}
-	ret = of_property_read_u32(np, "height-mm", &lvds->height);
-	if (ret < 0) {
Quoted 8 lines

drivers/gpu/drm/panel/panel-lvds.c static int panel_lvds_parse_dt(struct panel_lvds *lvds) · line 148

Quoted 4 lines
drivers/gpu/drm/panel/panel-lvds.c +0 -4
-		dev_err(lvds->dev, "%pOF: invalid or missing %s DT property\n",
-			np, "height-mm");
-		return -ENODEV;
-	}

of_get_drm_panel_display_mode() doesn't consider missing width-mm or height-mm properties as an error. Should we check here that ->width_mm and ->height_mm are not 0 ?

Quoted 2 lines

I wonder whether we should always require valid width-mm and height-mm DT property in of_get_drm_panel_display_mode() instead.

If that doesn't introduce any regression, that would be my preference too.

Quoted 1 line

[...]

Signature · 3 lines
Regards,

Laurent Pinchart
#7 lore raw
Quoted 45 lines · Laurent Pinchart
Quoted 44 lines · Marek Vasut

On 4/1/22 17:48, Laurent Pinchart wrote:

Hi,

[...]

Quoted 5 lines
Quoted 5 lines
drivers/gpu/drm/panel/panel-lvds.c +0 -0
index 27a1c9923b09..65c6a6e9e223 100644
@@ -30,7 +30,8 @@ struct panel_lvds {
Quoted 8 lines

drivers/gpu/drm/panel/panel-lvds.c struct panel_lvds { · line 33

Quoted 5 lines
drivers/gpu/drm/panel/panel-lvds.c +1 -1
   	const char *label;
   	unsigned int width;
   	unsigned int height;
-	struct videomode video_mode;
+	struct drm_display_mode dmode;

"dmode" sounds a bit weird, I would have gone for just "mode", or "display_mode", but I don't mind much.

That's how the of_get_drm_panel_display_mode() parameter is called in drivers/gpu/drm/drm_modes.c , so I'll just keep it for consistency.

[...]

Quoted 18 lines
Quoted 4 lines
drivers/gpu/drm/panel/panel-lvds.c +0 -4
-	videomode_from_timing(&timing, &lvds->video_mode);
-
-	ret = of_property_read_u32(np, "width-mm", &lvds->width);
-	if (ret < 0) {

drivers/gpu/drm/panel/panel-lvds.c static int panel_lvds_parse_dt(struct panel_lvds *lvds) · line 148

Quoted 10 lines
drivers/gpu/drm/panel/panel-lvds.c +0 -10
-		dev_err(lvds->dev, "%pOF: invalid or missing %s DT property\n",
-			np, "width-mm");
-		return -ENODEV;
-	}
-	ret = of_property_read_u32(np, "height-mm", &lvds->height);
-	if (ret < 0) {
-		dev_err(lvds->dev, "%pOF: invalid or missing %s DT property\n",
-			np, "height-mm");
-		return -ENODEV;
-	}

of_get_drm_panel_display_mode() doesn't consider missing width-mm or height-mm properties as an error. Should we check here that ->width_mm and ->height_mm are not 0 ?

Quoted 5 lines
Quoted 2 lines

I wonder whether we should always require valid width-mm and height-mm DT property in of_get_drm_panel_display_mode() instead.

If that doesn't introduce any regression, that would be my preference too.

I sent out an RFC series, so let's see.

Tested-by on v1 1/2
#8 lore raw
In reply to Marek Vasut

From: Marek Vasut [mailto:[email protected]]
Sent: Thursday, March 31, 2022 9:24 PM

Quoted 91 lines

The mode parsing is currently implemented in three steps:
of_get_display_timing() - DT panel-timing to struct display_timing videomode_from_timing() - struct display_timing to struct videomode drm_display_mode_from_videomode() - struct videomode to struct drm_display_mode

Replace all that with simple of_get_drm_panel_display_mode() call, which already populates struct drm_display_mode and then duplicate that mode in panel_lvds_get_modes() each time, since the mode does not change.

Nice bonus is the bus_flags parsed by of_get_drm_panel_display_mode() out of panel-timing DT node, which is used in subsequent patch to fix handling of 'de-active' DT property.

Cc Christoph Niedermaier <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Dmitry Osipenko <[email protected]>
Cc Laurent Pinchart <[email protected]>
Cc Robert Foss <[email protected]>
Cc Sam Ravnborg <[email protected]>
Cc Thomas Zimmermann <[email protected]>

To: [email protected]

---
 drivers/gpu/drm/panel/panel-lvds.c | 28 ++++++----------------------
 1 file changed, 6 insertions(+), 22 deletions(-)
drivers/gpu/drm/panel/panel-lvds.c +6 -15
index 27a1c9923b09..65c6a6e9e223 100644
@@ -30,7 +30,8 @@ struct panel_lvds {
        const char *label;
        unsigned int width;
        unsigned int height;
-       struct videomode video_mode;
+       struct drm_display_mode dmode;
+       u32 bus_flags;
        unsigned int bus_format;
        bool data_mirror;
 
@@ -87,16 +88,15 @@ static int panel_lvds_get_modes(struct drm_panel *panel,
        struct panel_lvds *lvds = to_panel_lvds(panel);
        struct drm_display_mode *mode;
 
-       mode = drm_mode_create(connector->dev);
+       mode = drm_mode_duplicate(connector->dev, &lvds->dmode);
        if (!mode)
                return 0;
 
-       drm_display_mode_from_videomode(&lvds->video_mode, mode);
        mode->type |= DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
        drm_mode_probed_add(connector, mode);
 
-       connector->display_info.width_mm = lvds->width;
-       connector->display_info.height_mm = lvds->height;
+       connector->display_info.width_mm = lvds->dmode.width_mm;
+       connector->display_info.height_mm = lvds->dmode.height_mm;
        drm_display_info_set_bus_formats(&connector->display_info,
                                         &lvds->bus_format, 1);
        connector->display_info.bus_flags = lvds->data_mirror
@@ -116,7 +116,6 @@ static const struct drm_panel_funcs panel_lvds_funcs = {
 static int panel_lvds_parse_dt(struct panel_lvds *lvds)
 {
        struct device_node *np = lvds->dev->of_node;
-       struct display_timing timing;
        int ret;
 
        ret = of_drm_get_panel_orientation(np, &lvds->orientation);
@@ -125,28 +124,13 @@ static int panel_lvds_parse_dt(struct panel_lvds *lvds)
                return ret;
        }
 
-       ret = of_get_display_timing(np, "panel-timing", &timing);
+       ret = of_get_drm_panel_display_mode(np, &lvds->dmode, &lvds->bus_flags);
        if (ret < 0) {
                dev_err(lvds->dev, "%pOF: problems parsing panel-timing (%d)\n",
                        np, ret);
                return ret;
        }
 
-       videomode_from_timing(&timing, &lvds->video_mode);
-
-       ret = of_property_read_u32(np, "width-mm", &lvds->width);
-       if (ret < 0) {
-               dev_err(lvds->dev, "%pOF: invalid or missing %s DT property\n",
-                       np, "width-mm");
-               return -ENODEV;
-       }

drivers/gpu/drm/panel/panel-lvds.c static int panel_lvds_parse_dt(struct panel_lvds *lvds) · line 136

Quoted 10 lines
drivers/gpu/drm/panel/panel-lvds.c +0 -7
-       ret = of_property_read_u32(np, "height-mm", &lvds->height);
-       if (ret < 0) {
-               dev_err(lvds->dev, "%pOF: invalid or missing %s DT property\n",
-                       np, "height-mm");
-               return -ENODEV;
-       }
-
        of_property_read_string(np, "label", &lvds->label);
 
        ret = drm_of_lvds_get_data_mapping(np);

Regards
Christoph