1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved.
6 #define pr_fmt(fmt)"[drm-dp] %s: " fmt, __func__
8 #include <linux/debugfs.h>
9 #include <drm/drm_connector.h>
10 #include <drm/drm_file.h>
12 #include "dp_parser.h"
13 #include "dp_catalog.h"
17 #include "dp_display.h"
19 #define DEBUG_NAME "msm_dp"
21 struct dp_debug_private {
25 struct dp_panel *panel;
26 struct drm_connector *connector;
28 struct drm_device *drm_dev;
30 struct dp_debug dp_debug;
33 static int dp_debug_show(struct seq_file *seq, void *p)
35 struct dp_debug_private *debug = seq->private;
38 const struct drm_display_mode *drm_mode;
43 drm_mode = &debug->panel->dp_mode.drm_mode;
45 seq_printf(seq, "\tname = %s\n", DEBUG_NAME);
46 seq_printf(seq, "\tdrm_dp_link\n\t\trate = %u\n",
47 debug->panel->link_info.rate);
48 seq_printf(seq, "\t\tnum_lanes = %u\n",
49 debug->panel->link_info.num_lanes);
50 seq_printf(seq, "\t\tcapabilities = %lu\n",
51 debug->panel->link_info.capabilities);
52 seq_printf(seq, "\tdp_panel_info:\n\t\tactive = %dx%d\n",
55 seq_printf(seq, "\t\tback_porch = %dx%d\n",
56 drm_mode->htotal - drm_mode->hsync_end,
57 drm_mode->vtotal - drm_mode->vsync_end);
58 seq_printf(seq, "\t\tfront_porch = %dx%d\n",
59 drm_mode->hsync_start - drm_mode->hdisplay,
60 drm_mode->vsync_start - drm_mode->vdisplay);
61 seq_printf(seq, "\t\tsync_width = %dx%d\n",
62 drm_mode->hsync_end - drm_mode->hsync_start,
63 drm_mode->vsync_end - drm_mode->vsync_start);
64 seq_printf(seq, "\t\tactive_low = %dx%d\n",
65 debug->panel->dp_mode.h_active_low,
66 debug->panel->dp_mode.v_active_low);
67 seq_printf(seq, "\t\th_skew = %d\n",
69 seq_printf(seq, "\t\trefresh rate = %d\n",
70 drm_mode_vrefresh(drm_mode));
71 seq_printf(seq, "\t\tpixel clock khz = %d\n",
73 seq_printf(seq, "\t\tbpp = %d\n",
74 debug->panel->dp_mode.bpp);
76 /* Link Information */
77 seq_printf(seq, "\tdp_link:\n\t\ttest_requested = %d\n",
78 debug->link->sink_request);
79 seq_printf(seq, "\t\tnum_lanes = %d\n",
80 debug->link->link_params.num_lanes);
81 link_params_rate = debug->link->link_params.rate;
82 seq_printf(seq, "\t\tbw_code = %d\n",
83 drm_dp_link_rate_to_bw_code(link_params_rate));
84 lclk = debug->link->link_params.rate * 1000;
85 seq_printf(seq, "\t\tlclk = %lld\n", lclk);
86 seq_printf(seq, "\t\tv_level = %d\n",
87 debug->link->phy_params.v_level);
88 seq_printf(seq, "\t\tp_level = %d\n",
89 debug->link->phy_params.p_level);
93 DEFINE_SHOW_ATTRIBUTE(dp_debug);
95 static int dp_test_data_show(struct seq_file *m, void *data)
97 const struct dp_debug_private *debug = m->private;
98 const struct drm_connector *connector = debug->connector;
101 if (connector->status == connector_status_connected) {
102 bpc = debug->link->test_video.test_bit_depth;
103 seq_printf(m, "hdisplay: %d\n",
104 debug->link->test_video.test_h_width);
105 seq_printf(m, "vdisplay: %d\n",
106 debug->link->test_video.test_v_height);
107 seq_printf(m, "bpc: %u\n",
108 dp_link_bit_depth_to_bpc(bpc));
115 DEFINE_SHOW_ATTRIBUTE(dp_test_data);
117 static int dp_test_type_show(struct seq_file *m, void *data)
119 const struct dp_debug_private *debug = m->private;
120 const struct drm_connector *connector = debug->connector;
122 if (connector->status == connector_status_connected)
123 seq_printf(m, "%02x", DP_TEST_LINK_VIDEO_PATTERN);
129 DEFINE_SHOW_ATTRIBUTE(dp_test_type);
131 static ssize_t dp_test_active_write(struct file *file,
132 const char __user *ubuf,
133 size_t len, loff_t *offp)
137 const struct dp_debug_private *debug;
138 const struct drm_connector *connector;
141 debug = ((struct seq_file *)file->private_data)->private;
142 connector = debug->connector;
147 input_buffer = memdup_user_nul(ubuf, len);
148 if (IS_ERR(input_buffer))
149 return PTR_ERR(input_buffer);
151 DRM_DEBUG_DRIVER("Copied %d bytes from user\n", (unsigned int)len);
153 if (connector->status == connector_status_connected) {
154 status = kstrtoint(input_buffer, 10, &val);
159 DRM_DEBUG_DRIVER("Got %d for test active\n", val);
160 /* To prevent erroneous activation of the compliance
161 * testing code, only accept an actual value of 1 here
164 debug->panel->video_test = true;
166 debug->panel->video_test = false;
174 static int dp_test_active_show(struct seq_file *m, void *data)
176 struct dp_debug_private *debug = m->private;
177 struct drm_connector *connector = debug->connector;
179 if (connector->status == connector_status_connected) {
180 if (debug->panel->video_test)
191 static int dp_test_active_open(struct inode *inode,
194 return single_open(file, dp_test_active_show,
198 static const struct file_operations test_active_fops = {
199 .owner = THIS_MODULE,
200 .open = dp_test_active_open,
203 .release = single_release,
204 .write = dp_test_active_write
207 static void dp_debug_init(struct dp_debug *dp_debug, struct drm_minor *minor)
210 struct dp_debug_private *debug = container_of(dp_debug,
211 struct dp_debug_private, dp_debug);
213 snprintf(path, sizeof(path), "msm_dp-%s", debug->connector->name);
215 debug->root = debugfs_create_dir(path, minor->debugfs_root);
217 debugfs_create_file("dp_debug", 0444, debug->root,
218 debug, &dp_debug_fops);
220 debugfs_create_file("msm_dp_test_active", 0444,
222 debug, &test_active_fops);
224 debugfs_create_file("msm_dp_test_data", 0444,
226 debug, &dp_test_data_fops);
228 debugfs_create_file("msm_dp_test_type", 0444,
230 debug, &dp_test_type_fops);
233 struct dp_debug *dp_debug_get(struct device *dev, struct dp_panel *panel,
234 struct dp_link *link,
235 struct drm_connector *connector, struct drm_minor *minor)
237 struct dp_debug_private *debug;
238 struct dp_debug *dp_debug;
241 if (!dev || !panel || !link) {
242 DRM_ERROR("invalid input\n");
247 debug = devm_kzalloc(dev, sizeof(*debug), GFP_KERNEL);
253 debug->dp_debug.debug_en = false;
255 debug->panel = panel;
257 debug->drm_dev = minor->dev;
258 debug->connector = connector;
260 dp_debug = &debug->dp_debug;
261 dp_debug->vdisplay = 0;
262 dp_debug->hdisplay = 0;
263 dp_debug->vrefresh = 0;
265 dp_debug_init(dp_debug, minor);
272 static int dp_debug_deinit(struct dp_debug *dp_debug)
274 struct dp_debug_private *debug;
279 debug = container_of(dp_debug, struct dp_debug_private, dp_debug);
281 debugfs_remove_recursive(debug->root);
286 void dp_debug_put(struct dp_debug *dp_debug)
288 struct dp_debug_private *debug;
293 debug = container_of(dp_debug, struct dp_debug_private, dp_debug);
295 dp_debug_deinit(dp_debug);
297 devm_kfree(debug->dev, debug);