[PATCH 17/17] drm/i915: Add debugfs write and test param parsing function for DP test control

Todd Previte
2014-12-10T23:54:26Z

Adds and implements the 'write' function for the debugfs i915_dp_test_ctrl file.
Also adds in the required parsing function to read in the data from the file
once the user app has written its data to it.

Signed-off-by: Todd Previte <tprevite@gmail.com>
---
drivers/gpu/drm/i915/i915_debugfs.c | 103 ++++++++++++++++++++++++++++++++++++
1 file changed, 103 insertions(+)

diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
index d2cd684..091d62b 100644
--- a/drivers/gpu/drm/i915/i915_debugfs.c
+++ b/drivers/gpu/drm/i915/i915_debugfs.c
@@ -4063,6 +4063,46 @@ static const struct file_operations i915_displayport_config_ctl_fops = {
.write = displayport_config_ctl_write
};

+static int displayport_parse_test_ctl(char *input_buffer,
+ ssize_t buffer_size,
+ struct intel_dp *intel_dp)
+{
+ char *ctrl_lines[DP_TEST_CTRL_LINE_COUNT];
+ int line_count;
+ int test_data;
+ int active;
+ int response;
+ char *conn_name; /* Connector name in the file */
+ char *dp_name; /* Connector name in the intel_dp struct */
+
+ if (!input_buffer)
+ return -EIO;
+
+ line_count = tokenize_dp_config(input_buffer, ctrl_lines);
+ if (line_count != DP_TEST_CTRL_LINE_COUNT)
+ return -EIO;
+
+ conn_name = ctrl_lines[DP_CTRL_PARAM_CONNECTOR];
+ dp_name = intel_dp->attached_connector->base.name;
+
+ if (strncmp(conn_name, dp_name, strlen(dp_name)) == 0) {
+ kstrtol(ctrl_lines[DP_CTRL_PARAM_TEST_DATA],
+ 16,
+ (long *)&test_data);
+ kstrtol(ctrl_lines[DP_CTRL_PARAM_TEST_ACTIVE],
+ 16,
+ (long *)&active);
+ kstrtol(ctrl_lines[DP_CTRL_PARAM_TEST_RESPONSE],
+ 16,
+ (long *)&response);
+ } else {
+ DRM_DEBUG_DRIVER("Connector names don't match\n");
+ return -EIO;
+ }
+
+ return 0;
+}
+
static int displayport_test_ctl_show(struct seq_file *m, void *data)
{
struct drm_device *dev = m->private;
@@ -4109,9 +4149,72 @@ static int displayport_test_ctl_open(struct inode *inode,
return single_open(file, displayport_test_ctl_show, dev);
}

+static ssize_t displayport_test_ctl_write(struct file *file,
+ const char __user *ubuf,
+ size_t len, loff_t *offp)
+{
+ char *input_buffer;
+ int status = 0;
+ struct seq_file *m;
+ struct drm_device *dev;
+ struct drm_connector *connector;
+ struct intel_encoder *intel_encoder;
+ struct intel_connector *intel_connector;
+ struct intel_dp *intel_dp;
+
+ m = file->private_data;
+ if (!m) {
+ status = -ENODEV;
+ return status;
+ }
+ dev = m->private;
+
+ if (!dev) {
+ status = -ENODEV;
+ return status;
+ }
+
+ if (len == 0)
+ return 0;
+
+ input_buffer = kmalloc(len + 1, GFP_KERNEL);
+ if (!input_buffer)
+ return -ENOMEM;
+
+ if (copy_from_user(input_buffer, ubuf, len)) {
+ status = -EFAULT;
+ goto out;
+ }
+
+ input_buffer[len] = '\0';
+ DRM_DEBUG_DRIVER("Copied %d bytes from user\n", (unsigned int)len);
+
+ list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
+ intel_connector = to_intel_connector(connector);
+ intel_encoder = intel_connector->encoder;
+ if (dp_connector_is_valid(connector, 0)) {
+ intel_dp = enc_to_intel_dp(&intel_encoder->base);
+ status = displayport_parse_test_ctl(input_buffer,
+ len,
+ intel_dp);
+ if (status < 0)
+ goto out;
+ }
+ }
+out:
+ kfree(input_buffer);
+ if (status < 0)
+ return status;
+
+ *offp += len;
+ return len;
+
+}
+
static const struct file_operations i915_dp_test_ctl_fops = {
.owner = THIS_MODULE,
.open = displayport_test_ctl_open,
+ .write = displayport_test_ctl_write,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
--
1.9.1