1 // SPDX-License-Identifier: MIT
3 * Copyright © 2023 Intel Corporation
6 #include <linux/debugfs.h>
7 #include <linux/kernel.h>
9 #include <drm/drm_drv.h>
11 #include "intel_display_debugfs_params.h"
13 #include "intel_display_params.h"
16 static int intel_display_param_int_show(struct seq_file *m, void *data)
18 int *value = m->private;
20 seq_printf(m, "%d\n", *value);
25 static int intel_display_param_int_open(struct inode *inode, struct file *file)
27 return single_open(file, intel_display_param_int_show, inode->i_private);
30 static ssize_t intel_display_param_int_write(struct file *file,
31 const char __user *ubuf, size_t len,
34 struct seq_file *m = file->private_data;
35 int *value = m->private;
38 ret = kstrtoint_from_user(ubuf, len, 0, value);
40 /* support boolean values too */
43 ret = kstrtobool_from_user(ubuf, len, &b);
51 static const struct file_operations intel_display_param_int_fops = {
53 .open = intel_display_param_int_open,
55 .write = intel_display_param_int_write,
56 .llseek = default_llseek,
57 .release = single_release,
60 static const struct file_operations intel_display_param_int_fops_ro = {
62 .open = intel_display_param_int_open,
64 .llseek = default_llseek,
65 .release = single_release,
68 /* unsigned int param */
69 static int intel_display_param_uint_show(struct seq_file *m, void *data)
71 unsigned int *value = m->private;
73 seq_printf(m, "%u\n", *value);
78 static int intel_display_param_uint_open(struct inode *inode, struct file *file)
80 return single_open(file, intel_display_param_uint_show, inode->i_private);
83 static ssize_t intel_display_param_uint_write(struct file *file,
84 const char __user *ubuf, size_t len,
87 struct seq_file *m = file->private_data;
88 unsigned int *value = m->private;
91 ret = kstrtouint_from_user(ubuf, len, 0, value);
93 /* support boolean values too */
96 ret = kstrtobool_from_user(ubuf, len, &b);
104 static const struct file_operations intel_display_param_uint_fops = {
105 .owner = THIS_MODULE,
106 .open = intel_display_param_uint_open,
108 .write = intel_display_param_uint_write,
109 .llseek = default_llseek,
110 .release = single_release,
113 static const struct file_operations intel_display_param_uint_fops_ro = {
114 .owner = THIS_MODULE,
115 .open = intel_display_param_uint_open,
117 .llseek = default_llseek,
118 .release = single_release,
121 #define RO(mode) (((mode) & 0222) == 0)
123 __maybe_unused static struct dentry *
124 intel_display_debugfs_create_int(const char *name, umode_t mode,
125 struct dentry *parent, int *value)
127 return debugfs_create_file_unsafe(name, mode, parent, value,
128 RO(mode) ? &intel_display_param_int_fops_ro :
129 &intel_display_param_int_fops);
132 __maybe_unused static struct dentry *
133 intel_display_debugfs_create_uint(const char *name, umode_t mode,
134 struct dentry *parent, unsigned int *value)
136 return debugfs_create_file_unsafe(name, mode, parent, value,
137 RO(mode) ? &intel_display_param_uint_fops_ro :
138 &intel_display_param_uint_fops);
141 #define _intel_display_param_create_file(parent, name, mode, valp) \
145 bool * : debugfs_create_bool, \
146 int * : intel_display_debugfs_create_int, \
147 unsigned int * : intel_display_debugfs_create_uint, \
148 unsigned long * : debugfs_create_ulong, \
149 char ** : debugfs_create_str) \
150 (name, mode, parent, valp); \
153 /* add a subdirectory with files for each intel display param */
154 void intel_display_debugfs_params(struct intel_display *display)
156 struct drm_minor *minor = display->drm->primary;
160 snprintf(dirname, sizeof(dirname), "%s_params", display->drm->driver->name);
161 dir = debugfs_lookup(dirname, minor->debugfs_root);
163 dir = debugfs_create_dir(dirname, minor->debugfs_root);
168 * Note: We could create files for params needing special handling
169 * here. Set mode in params to 0 to skip the generic create file, or
170 * just let the generic create file fail silently with -EEXIST.
173 #define REGISTER(T, x, unused, mode, ...) _intel_display_param_create_file( \
174 dir, #x, mode, &display->params.x);
175 INTEL_DISPLAY_PARAMS_FOR_EACH(REGISTER);