Skip to contentSkip to conversation

drm/fb-helper: pass physical dimensions to fbdev

PATCH Superseded David Lechner 1 participant 2 messages Aug 4, 2017

Subsystems (2)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 drm/fb-helper: pass physical dimensions to fbdev

The fbdev subsystem has a place for physical dimensions (width and height in mm) that is readable by userspace. Since DRM also knows these dimensions, pass this information to the fbdev device.

This has to be done in drm_setup_crtcs_fb() instead of drm_setup_crtcs() because fb_helper->fbdev may be NULL in drm_setup_crtcs().
---

v1 changes (from RFC):
* Use loop to get info from first connected connector instead of just the first connector.

v2 changes:
* Update width in height in drm_setup_crtcs() also to handle hotplug events.

v3 changes:
* Add new patch to handle post-fb allocation crcts setup.
* Use new drm_setup_crtcs_fb() function from new patch to avoid duplication of code.

v4 changes:
* Drop patch "drm/fb-helper: add new drm_setup_crtcs_fb() function" since it has been applied already.
* Add mutex lock.

 drivers/gpu/drm/drm_fb_helper.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_fb_helper.c +15 -2
index 4447a28..24787d6 100644
@@ -1882,8 +1882,6 @@ void drm_fb_helper_fill_var(struct fb_info *info, struct drm_fb_helper *fb_helpe
 	info->var.xoffset = 0;
 	info->var.yoffset = 0;
 	info->var.activate = FB_ACTIVATE_NOW;
-	info->var.height = -1;
-	info->var.width = -1;
 
 	switch (fb->format->depth) {
 	case 8:
@@ -2435,11 +2433,26 @@ static void drm_setup_crtcs(struct drm_fb_helper *fb_helper,
  */
 static void drm_setup_crtcs_fb(struct drm_fb_helper *fb_helper)
 {
+	struct fb_info *info = fb_helper->fbdev;
 	int i;
 
 	for (i = 0; i < fb_helper->crtc_count; i++)
 		if (fb_helper->crtc_info[i].mode_set.num_connectors)
 			fb_helper->crtc_info[i].mode_set.fb = fb_helper->fb;
+
+	mutex_lock(&fb_helper->dev->mode_config.mutex);
+	drm_fb_helper_for_each_connector(fb_helper, i) {
+		struct drm_connector *connector =
+					fb_helper->connector_info[i]->connector;
+
+		/* use first connected connector for the physical dimensions */
+		if (connector->status == connector_status_connected) {
+			info->var.height = connector->display_info.width_mm;
+			info->var.width = connector->display_info.height_mm;
+			break;
+		}
+	}
+	mutex_unlock(&fb_helper->dev->mode_config.mutex);
 }
 
 /* Note: Drops fb_helper->lock before returning. */
Signature · 6 lines
2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw
Quoted 51 lines · David Lechner

The fbdev subsystem has a place for physical dimensions (width and height in mm) that is readable by userspace. Since DRM also knows these dimensions, pass this information to the fbdev device.

This has to be done in drm_setup_crtcs_fb() instead of drm_setup_crtcs() because fb_helper->fbdev may be NULL in drm_setup_crtcs().
---

v1 changes (from RFC):
* Use loop to get info from first connected connector instead of just the first connector.

v2 changes:
* Update width in height in drm_setup_crtcs() also to handle hotplug events.

v3 changes:
* Add new patch to handle post-fb allocation crcts setup.
* Use new drm_setup_crtcs_fb() function from new patch to avoid duplication of code.

v4 changes:
* Drop patch "drm/fb-helper: add new drm_setup_crtcs_fb() function" since it has been applied already.
* Add mutex lock.

  drivers/gpu/drm/drm_fb_helper.c | 17 +++++++++++++++--
  1 file changed, 15 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_fb_helper.c +1 -2
index 4447a28..24787d6 100644
@@ -1882,8 +1882,6 @@ void drm_fb_helper_fill_var(struct fb_info *info, struct drm_fb_helper *fb_helpe
  	info->var.xoffset = 0;
  	info->var.yoffset = 0;
  	info->var.activate = FB_ACTIVATE_NOW;
-	info->var.height = -1;
-	info->var.width = -1;
 
  	switch (fb->format->depth) {
  	case 8:
@@ -2435,11 +2433,26 @@ static void drm_setup_crtcs(struct drm_fb_helper *fb_helper,
   */
  static void drm_setup_crtcs_fb(struct drm_fb_helper *fb_helper)
  {
+	struct fb_info *info = fb_helper->fbdev;
  	int i;
 
  	for (i = 0; i < fb_helper->crtc_count; i++)
  		if (fb_helper->crtc_info[i].mode_set.num_connectors)
  			fb_helper->crtc_info[i].mode_set.fb = fb_helper->fb;

drivers/gpu/drm/drm_fb_helper.c static void drm_setup_crtcs(struct drm_fb_helper *fb_helper, · line 2451

Quoted 10 lines
drivers/gpu/drm/drm_fb_helper.c +10 -0
+
+	mutex_lock(&fb_helper->dev->mode_config.mutex);
+	drm_fb_helper_for_each_connector(fb_helper, i) {
+		struct drm_connector *connector =
+					fb_helper->connector_info[i]->connector;
+
+		/* use first connected connector for the physical dimensions */
+		if (connector->status == connector_status_connected) {
+			info->var.height = connector->display_info.width_mm;
+			info->var.width = connector->display_info.height_mm;

Oops. height = width!

Quoted 8 lines
drivers/gpu/drm/drm_fb_helper.c +4 -0
+			break;
+		}
+	}
+	mutex_unlock(&fb_helper->dev->mode_config.mutex);
  }
 
  /* Note: Drops fb_helper->lock before returning. */