Skip to contentSkip to conversation

drm: sysfs: Add to get current mode

PATCH In review Sandy Huang 2 participants 4 messages Aug 5, 2020

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

PATCH 1/1 drm: sysfs: Add to get current mode

add this node to get the current true mode.

---
 drivers/gpu/drm/drm_sysfs.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
drivers/gpu/drm/drm_sysfs.c +30 -0
index 939f0032aab1..f39bcd34853b 100644
@@ -19,6 +19,7 @@
 #include <linux/slab.h>
 
 #include <drm/drm_connector.h>
+#include <drm/drm_crtc.h>
 #include <drm/drm_device.h>
 #include <drm/drm_file.h>
 #include <drm/drm_modes.h>
@@ -236,16 +237,45 @@ static ssize_t modes_show(struct device *device,
 	return written;
 }
 
+static ssize_t current_mode_show(struct device *device,
+		      struct device_attribute *attr,
+		      char *buf)
+{
+	struct drm_connector *connector = to_drm_connector(device);
+	struct drm_display_mode *mode;
+	struct drm_crtc_state *crtc_state;
+	bool interlaced;
+	int written = 0;
+
+	if (!connector->state || !connector->state->crtc)
+		return written;
+
+	crtc_state = connector->state->crtc->state;
+	if (!crtc_state)
+		return written;
+
+	mode = &crtc_state->mode;
+
+	interlaced = !!(mode->flags & DRM_MODE_FLAG_INTERLACE);
+	written += snprintf(buf + written, PAGE_SIZE - written, "%dx%d%s%d\n",
+			    mode->hdisplay, mode->vdisplay,
+			    interlaced ? "i" : "p", drm_mode_vrefresh(mode));
+
+	return written;
+}
+
 static DEVICE_ATTR_RW(status);
 static DEVICE_ATTR_RO(enabled);
 static DEVICE_ATTR_RO(dpms);
 static DEVICE_ATTR_RO(modes);
+static DEVICE_ATTR_RO(current_mode);
 
 static struct attribute *connector_dev_attrs[] = {
 	&dev_attr_status.attr,
 	&dev_attr_enabled.attr,
 	&dev_attr_dpms.attr,
 	&dev_attr_modes.attr,
+	&dev_attr_current_mode.attr,
 	NULL
 };
 
Signature · 1 line
2.17.1
#1 lore raw
Quoted 4 lines · Sandy Huang

add this node to get the current true mode.

Uh what's this for? Since it's sysfs, I guess there's something parsing this, which means we'd kinda need to have that piece too.

If it's just for debugging purposes, then we already have this information in debugfs, together with everything else that's in the atomic modeset state.
-Daniel

Quoted 67 lines
---
 drivers/gpu/drm/drm_sysfs.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
drivers/gpu/drm/drm_sysfs.c +30 -1
index 939f0032aab1..f39bcd34853b 100644
@@ -19,6 +19,7 @@
 #include <linux/slab.h>
 
 #include <drm/drm_connector.h>
+#include <drm/drm_crtc.h>
 #include <drm/drm_device.h>
 #include <drm/drm_file.h>
 #include <drm/drm_modes.h>
@@ -236,16 +237,45 @@ static ssize_t modes_show(struct device *device,
        return written;
 }
 
+static ssize_t current_mode_show(struct device *device,
+                     struct device_attribute *attr,
+                     char *buf)
+{
+       struct drm_connector *connector = to_drm_connector(device);
+       struct drm_display_mode *mode;
+       struct drm_crtc_state *crtc_state;
+       bool interlaced;
+       int written = 0;
+
+       if (!connector->state || !connector->state->crtc)
+               return written;
+
+       crtc_state = connector->state->crtc->state;
+       if (!crtc_state)
+               return written;
+
+       mode = &crtc_state->mode;
+
+       interlaced = !!(mode->flags & DRM_MODE_FLAG_INTERLACE);
+       written += snprintf(buf + written, PAGE_SIZE - written, "%dx%d%s%d\n",
+                           mode->hdisplay, mode->vdisplay,
+                           interlaced ? "i" : "p", drm_mode_vrefresh(mode));
+
+       return written;
+}
+
 static DEVICE_ATTR_RW(status);
 static DEVICE_ATTR_RO(enabled);
 static DEVICE_ATTR_RO(dpms);
 static DEVICE_ATTR_RO(modes);
+static DEVICE_ATTR_RO(current_mode);
 
 static struct attribute *connector_dev_attrs[] = {
        &dev_attr_status.attr,
        &dev_attr_enabled.attr,
        &dev_attr_dpms.attr,
        &dev_attr_modes.attr,
+       &dev_attr_current_mode.attr,
        NULL
 };
 
--

2.17.1

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
#2 lore raw

Hi Daniel

Quoted 11 lines · Daniel Vetter
Quoted 3 lines · Sandy Huang

add this node to get the current true mode.

Uh what's this for? Since it's sysfs, I guess there's something parsing this, which means we'd kinda need to have that piece too.

If it's just for debugging purposes, then we already have this information in debugfs, together with everything else that's in the atomic modeset state.
-Daniel

yes, this is just for debug;

and i get the information what i need from cat /sys/kernel/debug/dri/0/state, thanks.

Quoted 68 lines
Quoted 67 lines
---
  drivers/gpu/drm/drm_sysfs.c | 30 ++++++++++++++++++++++++++++++
  1 file changed, 30 insertions(+)
drivers/gpu/drm/drm_sysfs.c +30 -1
index 939f0032aab1..f39bcd34853b 100644
@@ -19,6 +19,7 @@
  #include <linux/slab.h>
 
  #include <drm/drm_connector.h>
+#include <drm/drm_crtc.h>
  #include <drm/drm_device.h>
  #include <drm/drm_file.h>
  #include <drm/drm_modes.h>
@@ -236,16 +237,45 @@ static ssize_t modes_show(struct device *device,
         return written;
  }
 
+static ssize_t current_mode_show(struct device *device,
+                     struct device_attribute *attr,
+                     char *buf)
+{
+       struct drm_connector *connector = to_drm_connector(device);
+       struct drm_display_mode *mode;
+       struct drm_crtc_state *crtc_state;
+       bool interlaced;
+       int written = 0;
+
+       if (!connector->state || !connector->state->crtc)
+               return written;
+
+       crtc_state = connector->state->crtc->state;
+       if (!crtc_state)
+               return written;
+
+       mode = &crtc_state->mode;
+
+       interlaced = !!(mode->flags & DRM_MODE_FLAG_INTERLACE);
+       written += snprintf(buf + written, PAGE_SIZE - written, "%dx%d%s%d\n",
+                           mode->hdisplay, mode->vdisplay,
+                           interlaced ? "i" : "p", drm_mode_vrefresh(mode));
+
+       return written;
+}
+
  static DEVICE_ATTR_RW(status);
  static DEVICE_ATTR_RO(enabled);
  static DEVICE_ATTR_RO(dpms);
  static DEVICE_ATTR_RO(modes);
+static DEVICE_ATTR_RO(current_mode);
 
  static struct attribute *connector_dev_attrs[] = {
         &dev_attr_status.attr,
         &dev_attr_enabled.attr,
         &dev_attr_dpms.attr,
         &dev_attr_modes.attr,
+       &dev_attr_current_mode.attr,
         NULL
  };
 
--

2.17.1

Signature · 8 lines
Best Regard

黄家钗
Sandy Huang
Addr: 福州市鼓楼区铜盘路软件大道89号福州软件园A区21号楼(350003)
      No. 21 Building, A District, No.89,software Boulevard Fuzhou,Fujian,PRC
Tel:+86 0591-87884919  8690
E-mail:[email protected]
#3 lore raw
Quoted 15 lines · Huang Jiachai

Hi Daniel

Quoted 11 lines · Daniel Vetter
Quoted 3 lines · Sandy Huang

add this node to get the current true mode.

Uh what's this for? Since it's sysfs, I guess there's something parsing this, which means we'd kinda need to have that piece too.

If it's just for debugging purposes, then we already have this information in debugfs, together with everything else that's in the atomic modeset state.
-Daniel

Quoted 4 lines

yes, this is just for debug;

and i get the information what i need from cat
/sys/kernel/debug/dri/0/state, thanks.

Cool, sounds like this is resolved. And if you need any additional debug information about display state, then best to extend that file. It comes with driver hooks, so that you can include any additional driver stuff, or outright read out registers and everything.

Cheers, Daniel

Quoted 81 lines
Quoted 69 lines
Quoted 68 lines
---
  drivers/gpu/drm/drm_sysfs.c | 30 ++++++++++++++++++++++++++++++
  1 file changed, 30 insertions(+)
drivers/gpu/drm/drm_sysfs.c +30 -1
index 939f0032aab1..f39bcd34853b 100644
@@ -19,6 +19,7 @@
  #include <linux/slab.h>
 
  #include <drm/drm_connector.h>
+#include <drm/drm_crtc.h>
  #include <drm/drm_device.h>
  #include <drm/drm_file.h>
  #include <drm/drm_modes.h>
@@ -236,16 +237,45 @@ static ssize_t modes_show(struct device *device,
         return written;
  }
 
+static ssize_t current_mode_show(struct device *device,
+                     struct device_attribute *attr,
+                     char *buf)
+{
+       struct drm_connector *connector = to_drm_connector(device);
+       struct drm_display_mode *mode;
+       struct drm_crtc_state *crtc_state;
+       bool interlaced;
+       int written = 0;
+
+       if (!connector->state || !connector->state->crtc)
+               return written;
+
+       crtc_state = connector->state->crtc->state;
+       if (!crtc_state)
+               return written;
+
+       mode = &crtc_state->mode;
+
+       interlaced = !!(mode->flags & DRM_MODE_FLAG_INTERLACE);
+       written += snprintf(buf + written, PAGE_SIZE - written, "%dx%d%s%d\n",
+                           mode->hdisplay, mode->vdisplay,
+                           interlaced ? "i" : "p", drm_mode_vrefresh(mode));
+
+       return written;
+}
+
  static DEVICE_ATTR_RW(status);
  static DEVICE_ATTR_RO(enabled);
  static DEVICE_ATTR_RO(dpms);
  static DEVICE_ATTR_RO(modes);
+static DEVICE_ATTR_RO(current_mode);
 
  static struct attribute *connector_dev_attrs[] = {
         &dev_attr_status.attr,
         &dev_attr_enabled.attr,
         &dev_attr_dpms.attr,
         &dev_attr_modes.attr,
+       &dev_attr_current_mode.attr,
         NULL
  };
 
--

2.17.1

Signature · 8 lines
Best Regard

黄家钗
Sandy Huang
Addr: 福州市鼓楼区铜盘路软件大道89号福州软件园A区21号楼(350003)
      No. 21 Building, A District, No.89,software Boulevard Fuzhou,Fujian,PRC
Tel:+86 0591-87884919  8690
E-mail:[email protected]
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch