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 msm_dp_debug_private {
21 struct msm_dp_link *link;
22 struct msm_dp_panel *panel;
23 struct drm_connector *connector;
26 static int msm_dp_debug_show(struct seq_file *seq, void *p)
28 struct msm_dp_debug_private *debug = seq->private;
31 const struct drm_display_mode *drm_mode;
36 drm_mode = &debug->panel->msm_dp_mode.drm_mode;
38 seq_printf(seq, "\tname = %s\n", DEBUG_NAME);
39 seq_printf(seq, "\tdrm_dp_link\n\t\trate = %u\n",
40 debug->panel->link_info.rate);
41 seq_printf(seq, "\t\tnum_lanes = %u\n",
42 debug->panel->link_info.num_lanes);
43 seq_printf(seq, "\t\tcapabilities = %lu\n",
44 debug->panel->link_info.capabilities);
45 seq_printf(seq, "\tdp_panel_info:\n\t\tactive = %dx%d\n",
48 seq_printf(seq, "\t\tback_porch = %dx%d\n",
49 drm_mode->htotal - drm_mode->hsync_end,
50 drm_mode->vtotal - drm_mode->vsync_end);
51 seq_printf(seq, "\t\tfront_porch = %dx%d\n",
52 drm_mode->hsync_start - drm_mode->hdisplay,
53 drm_mode->vsync_start - drm_mode->vdisplay);
54 seq_printf(seq, "\t\tsync_width = %dx%d\n",
55 drm_mode->hsync_end - drm_mode->hsync_start,
56 drm_mode->vsync_end - drm_mode->vsync_start);
57 seq_printf(seq, "\t\tactive_low = %dx%d\n",
58 debug->panel->msm_dp_mode.h_active_low,
59 debug->panel->msm_dp_mode.v_active_low);
60 seq_printf(seq, "\t\th_skew = %d\n",
62 seq_printf(seq, "\t\trefresh rate = %d\n",
63 drm_mode_vrefresh(drm_mode));
64 seq_printf(seq, "\t\tpixel clock khz = %d\n",
66 seq_printf(seq, "\t\tbpp = %d\n",
67 debug->panel->msm_dp_mode.bpp);
69 /* Link Information */
70 seq_printf(seq, "\tdp_link:\n\t\ttest_requested = %d\n",
71 debug->link->sink_request);
72 seq_printf(seq, "\t\tnum_lanes = %d\n",
73 debug->link->link_params.num_lanes);
74 link_params_rate = debug->link->link_params.rate;
75 seq_printf(seq, "\t\tbw_code = %d\n",
76 drm_dp_link_rate_to_bw_code(link_params_rate));
77 lclk = debug->link->link_params.rate * 1000;
78 seq_printf(seq, "\t\tlclk = %lld\n", lclk);
79 seq_printf(seq, "\t\tv_level = %d\n",
80 debug->link->phy_params.v_level);
81 seq_printf(seq, "\t\tp_level = %d\n",
82 debug->link->phy_params.p_level);
86 DEFINE_SHOW_ATTRIBUTE(msm_dp_debug);
88 static int msm_dp_test_data_show(struct seq_file *m, void *data)
90 const struct msm_dp_debug_private *debug = m->private;
91 const struct drm_connector *connector = debug->connector;
94 if (connector->status == connector_status_connected) {
95 bpc = debug->link->test_video.test_bit_depth;
96 seq_printf(m, "hdisplay: %d\n",
97 debug->link->test_video.test_h_width);
98 seq_printf(m, "vdisplay: %d\n",
99 debug->link->test_video.test_v_height);
100 seq_printf(m, "bpc: %u\n",
101 msm_dp_link_bit_depth_to_bpp(bpc) / 3);
108 DEFINE_SHOW_ATTRIBUTE(msm_dp_test_data);
110 static int msm_dp_test_type_show(struct seq_file *m, void *data)
112 const struct msm_dp_debug_private *debug = m->private;
113 const struct drm_connector *connector = debug->connector;
115 if (connector->status == connector_status_connected)
116 seq_printf(m, "%02x", DP_TEST_LINK_VIDEO_PATTERN);
122 DEFINE_SHOW_ATTRIBUTE(msm_dp_test_type);
124 static ssize_t msm_dp_test_active_write(struct file *file,
125 const char __user *ubuf,
126 size_t len, loff_t *offp)
130 const struct msm_dp_debug_private *debug;
131 const struct drm_connector *connector;
134 debug = ((struct seq_file *)file->private_data)->private;
135 connector = debug->connector;
140 input_buffer = memdup_user_nul(ubuf, len);
141 if (IS_ERR(input_buffer))
142 return PTR_ERR(input_buffer);
144 DRM_DEBUG_DRIVER("Copied %d bytes from user\n", (unsigned int)len);
146 if (connector->status == connector_status_connected) {
147 status = kstrtoint(input_buffer, 10, &val);
152 DRM_DEBUG_DRIVER("Got %d for test active\n", val);
153 /* To prevent erroneous activation of the compliance
154 * testing code, only accept an actual value of 1 here
157 debug->panel->video_test = true;
159 debug->panel->video_test = false;
167 static int msm_dp_test_active_show(struct seq_file *m, void *data)
169 struct msm_dp_debug_private *debug = m->private;
170 struct drm_connector *connector = debug->connector;
172 if (connector->status == connector_status_connected) {
173 if (debug->panel->video_test)
184 static int msm_dp_test_active_open(struct inode *inode,
187 return single_open(file, msm_dp_test_active_show,
191 static const struct file_operations test_active_fops = {
192 .owner = THIS_MODULE,
193 .open = msm_dp_test_active_open,
196 .release = single_release,
197 .write = msm_dp_test_active_write
200 int msm_dp_debug_init(struct device *dev, struct msm_dp_panel *panel,
201 struct msm_dp_link *link,
202 struct drm_connector *connector,
203 struct dentry *root, bool is_edp)
205 struct msm_dp_debug_private *debug;
207 if (!dev || !panel || !link) {
208 DRM_ERROR("invalid input\n");
212 debug = devm_kzalloc(dev, sizeof(*debug), GFP_KERNEL);
217 debug->panel = panel;
219 debugfs_create_file("dp_debug", 0444, root,
220 debug, &msm_dp_debug_fops);
223 debugfs_create_file("dp_test_active", 0444,
225 debug, &test_active_fops);
227 debugfs_create_file("dp_test_data", 0444,
229 debug, &msm_dp_test_data_fops);
231 debugfs_create_file("dp_test_type", 0444,
233 debug, &msm_dp_test_type_fops);