All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thorsten Schoel <tschoel@web.de>
To: dri-devel@lists.freedesktop.org
Subject: [Patch 3/3] edid override: make edid writable in sysfs
Date: Tue, 24 Apr 2012 10:49:49 +0200	[thread overview]
Message-ID: <1335257389.1563.42.camel@ges14.uni-leipzig.de> (raw)

From: Thorsten Schoel <tschoel at web.de>

Makes class/drm/[CONNECTOR]/edid writable for adding edid overrides.

Signed-off-by: Thorsten Schoel <tschoel at web.de>
---
diff -Nurp infra/drivers/gpu/drm/drm_sysfs.c sysfs/drivers/gpu/drm/drm_sysfs.c
--- infra/drivers/gpu/drm/drm_sysfs.c	2012-01-12 20:42:45.000000000 +0100
+++ sysfs/drivers/gpu/drm/drm_sysfs.c	2012-01-25 22:13:08.000000000 +0100
@@ -21,6 +21,8 @@
 #include "drm_sysfs.h"
 #include "drm_core.h"
 #include "drmP.h"
+#include "drm_edid.h"
+#include "drm_crtc.h"
 
 #define to_drm_minor(d) container_of(d, struct drm_minor, kdev)
 #define to_drm_connector(d) container_of(d, struct drm_connector, kdev)
@@ -228,6 +230,44 @@ static ssize_t edid_show(struct file *fi
 	return count;
 }
 
+static ssize_t edid_override(struct file *filp, struct kobject *kobj,
+			     struct bin_attribute *attr, char *buf, loff_t off,
+			     size_t count)
+{
+	struct device *connector_dev = container_of(kobj, struct device, kobj);
+	struct drm_connector *connector = to_drm_connector(connector_dev);
+	char *connector_name;
+	unsigned char *edid_new;
+
+	connector_name = drm_get_connector_name(connector);
+	
+	if (!count) {
+		drm_edid_override_remove(connector_name);
+		return 0;
+	}
+	
+	/* Only support writing the whole EDID in one piece */
+	if (off)
+		return 0;
+
+	if (count < EDID_LENGTH)
+		return 0;
+	if (count != (buf[0x7e] + 1) * EDID_LENGTH)
+		return 0;
+	
+	edid_new = kmalloc(count, GFP_KERNEL);
+	if (!edid_new)
+		return 0;
+	
+	memcpy(edid_new,  buf, count);
+
+	if (drm_edid_override_set(connector_name, (struct edid *)edid_new) < 0)
+		count = 0;
+	
+	kfree(edid_new);
+	return count;
+}
+
 static ssize_t modes_show(struct device *device,
 			   struct device_attribute *attr,
 			   char *buf)
@@ -341,9 +381,10 @@ static struct device_attribute connector
 
 static struct bin_attribute edid_attr = {
 	.attr.name = "edid",
-	.attr.mode = 0444,
+	.attr.mode = 0644,
 	.size = 0,
 	.read = edid_show,
+	.write = edid_override,
 };
 
 /**
---

                 reply	other threads:[~2012-04-24  8:58 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1335257389.1563.42.camel@ges14.uni-leipzig.de \
    --to=tschoel@web.de \
    --cc=dri-devel@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.