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_catalog.h"
16 #include "dp_display.h"
18 #define DEBUG_NAME "msm_dp"
20 struct dp_debug_private {
22 struct dp_panel *panel;
23 struct drm_connector *connector;
25 struct dp_debug dp_debug;
28 static int dp_debug_show(struct seq_file *seq, void *p)
30 struct dp_debug_private *debug = seq->private;
33 const struct drm_display_mode *drm_mode;
38 drm_mode = &debug->panel->dp_mode.drm_mode;
40 seq_printf(seq, "\tname = %s\n", DEBUG_NAME);
41 seq_printf(seq, "\tdrm_dp_link\n\t\trate = %u\n",
42 debug->panel->link_info.rate);
43 seq_printf(seq, "\t\tnum_lanes = %u\n",
44 debug->panel->link_info.num_lanes);
45 seq_printf(seq, "\t\tcapabilities = %lu\n",
46 debug->panel->link_info.capabilities);
47 seq_printf(seq, "\tdp_panel_info:\n\t\tactive = %dx%d\n",
50 seq_printf(seq, "\t\tback_porch = %dx%d\n",
51 drm_mode->htotal - drm_mode->hsync_end,
52 drm_mode->vtotal - drm_mode->vsync_end);
53 seq_printf(seq, "\t\tfront_porch = %dx%d\n",
54 drm_mode->hsync_start - drm_mode->hdisplay,
55 drm_mode->vsync_start - drm_mode->vdisplay);
56 seq_printf(seq, "\t\tsync_width = %dx%d\n",
57 drm_mode->hsync_end - drm_mode->hsync_start,
58 drm_mode->vsync_end - drm_mode->vsync_start);
59 seq_printf(seq, "\t\tactive_low = %dx%d\n",
60 debug->panel->dp_mode.h_active_low,
61 debug->panel->dp_mode.v_active_low);
62 seq_printf(seq, "\t\th_skew = %d\n",
64 seq_printf(seq, "\t\trefresh rate = %d\n",
65 drm_mode_vrefresh(drm_mode));
66 seq_printf(seq, "\t\tpixel clock khz = %d\n",
68 seq_printf(seq, "\t\tbpp = %d\n",
69 debug->panel->dp_mode.bpp);
71 /* Link Information */
72 seq_printf(seq, "\tdp_link:\n\t\ttest_requested = %d\n",
73 debug->link->sink_request);
74 seq_printf(seq, "\t\tnum_lanes = %d\n",
75 debug->link->link_params.num_lanes);
76 link_params_rate = debug->link->link_params.rate;
77 seq_printf(seq, "\t\tbw_code = %d\n",
78 drm_dp_link_rate_to_bw_code(link_params_rate));
79 lclk = debug->link->link_params.rate * 1000;
80 seq_printf(seq, "\t\tlclk = %lld\n", lclk);
81 seq_printf(seq, "\t\tv_level = %d\n",
82 debug->link->phy_params.v_level);
83 seq_printf(seq, "\t\tp_level = %d\n",
84 debug->link->phy_params.p_level);
88 DEFINE_SHOW_ATTRIBUTE(dp_debug);
90 static int dp_test_data_show(struct seq_file *m, void *data)
92 const struct dp_debug_private *debug = m->private;
93 const struct drm_connector *connector = debug->connector;
96 if (connector->status == connector_status_connected) {
97 bpc = debug->link->test_video.test_bit_depth;
98 seq_printf(m, "hdisplay: %d\n",
99 debug->link->test_video.test_h_width);
100 seq_printf(m, "vdisplay: %d\n",
101 debug->link->test_video.test_v_height);
102 seq_printf(m, "bpc: %u\n",
103 dp_link_bit_depth_to_bpp(bpc) / 3);
110 DEFINE_SHOW_ATTRIBUTE(dp_test_data);
112 static int dp_test_type_show(struct seq_file *m, void *data)
114 const struct dp_debug_private *debug = m->private;
115 const struct drm_connector *connector = debug->connector;
117 if (connector->status == connector_status_connected)
118 seq_printf(m, "%02x", DP_TEST_LINK_VIDEO_PATTERN);
124 DEFINE_SHOW_ATTRIBUTE(dp_test_type);
126 static ssize_t dp_test_active_write(struct file *file,
127 const char __user *ubuf,
128 size_t len, loff_t *offp)
132 const struct dp_debug_private *debug;
133 const struct drm_connector *connector;
136 debug = ((struct seq_file *)file->private_data)->private;
137 connector = debug->connector;
142 input_buffer = memdup_user_nul(ubuf, len);
143 if (IS_ERR(input_buffer))
144 return PTR_ERR(input_buffer);
146 DRM_DEBUG_DRIVER("Copied %d bytes from user\n", (unsigned int)len);
148 if (connector->status == connector_status_connected) {
149 status = kstrtoint(input_buffer, 10, &val);
154 DRM_DEBUG_DRIVER("Got %d for test active\n", val);
155 /* To prevent erroneous activation of the compliance
156 * testing code, only accept an actual value of 1 here
159 debug->panel->video_test = true;
161 debug->panel->video_test = false;
169 static int dp_test_active_show(struct seq_file *m, void *data)
171 struct dp_debug_private *debug = m->private;
172 struct drm_connector *connector = debug->connector;
174 if (connector->status == connector_status_connected) {
175 if (debug->panel->video_test)
186 static int dp_test_active_open(struct inode *inode,
189 return single_open(file, dp_test_active_show,
193 static const struct file_operations test_active_fops = {
194 .owner = THIS_MODULE,
195 .open = dp_test_active_open,
198 .release = single_release,
199 .write = dp_test_active_write
202 static void dp_debug_init(struct dp_debug *dp_debug, struct dentry *root, bool is_edp)
204 struct dp_debug_private *debug = container_of(dp_debug,
205 struct dp_debug_private, dp_debug);
207 debugfs_create_file("dp_debug", 0444, root,
208 debug, &dp_debug_fops);
211 debugfs_create_file("msm_dp_test_active", 0444,
213 debug, &test_active_fops);
215 debugfs_create_file("msm_dp_test_data", 0444,
217 debug, &dp_test_data_fops);
219 debugfs_create_file("msm_dp_test_type", 0444,
221 debug, &dp_test_type_fops);
225 struct dp_debug *dp_debug_get(struct device *dev, struct dp_panel *panel,
226 struct dp_link *link,
227 struct drm_connector *connector,
228 struct dentry *root, bool is_edp)
230 struct dp_debug_private *debug;
231 struct dp_debug *dp_debug;
234 if (!dev || !panel || !link) {
235 DRM_ERROR("invalid input\n");
240 debug = devm_kzalloc(dev, sizeof(*debug), GFP_KERNEL);
246 debug->dp_debug.debug_en = false;
248 debug->panel = panel;
250 dp_debug = &debug->dp_debug;
251 dp_debug->vdisplay = 0;
252 dp_debug->hdisplay = 0;
253 dp_debug->vrefresh = 0;
255 dp_debug_init(dp_debug, root, is_edp);