xref: /linux/drivers/gpu/drm/msm/dp/dp_debug.c (revision ab8420418c2e67c81549ce483ff6a472c6dc2833)
1d11a9369SAbhinav Kumar // SPDX-License-Identifier: GPL-2.0-only
2d11a9369SAbhinav Kumar /*
3d11a9369SAbhinav Kumar  * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved.
4d11a9369SAbhinav Kumar  */
5d11a9369SAbhinav Kumar 
6d11a9369SAbhinav Kumar #define pr_fmt(fmt)"[drm-dp] %s: " fmt, __func__
7d11a9369SAbhinav Kumar 
8d11a9369SAbhinav Kumar #include <linux/debugfs.h>
9d11a9369SAbhinav Kumar #include <drm/drm_connector.h>
10f913454aSAbhinav Kumar #include <drm/drm_file.h>
11d11a9369SAbhinav Kumar 
12d11a9369SAbhinav Kumar #include "dp_parser.h"
13d11a9369SAbhinav Kumar #include "dp_catalog.h"
14d11a9369SAbhinav Kumar #include "dp_aux.h"
15d11a9369SAbhinav Kumar #include "dp_ctrl.h"
16d11a9369SAbhinav Kumar #include "dp_debug.h"
17d11a9369SAbhinav Kumar #include "dp_display.h"
18d11a9369SAbhinav Kumar 
19f913454aSAbhinav Kumar #define DEBUG_NAME "msm_dp"
20d11a9369SAbhinav Kumar 
21d11a9369SAbhinav Kumar struct dp_debug_private {
22d11a9369SAbhinav Kumar 	struct dp_link *link;
23d11a9369SAbhinav Kumar 	struct dp_panel *panel;
24899b2608SBjorn Andersson 	struct drm_connector *connector;
25d11a9369SAbhinav Kumar 
26d11a9369SAbhinav Kumar 	struct dp_debug dp_debug;
27d11a9369SAbhinav Kumar };
28d11a9369SAbhinav Kumar 
29eea8f024SBjorn Andersson static int dp_debug_show(struct seq_file *seq, void *p)
30d11a9369SAbhinav Kumar {
31eea8f024SBjorn Andersson 	struct dp_debug_private *debug = seq->private;
32d11a9369SAbhinav Kumar 	u64 lclk = 0;
33d11a9369SAbhinav Kumar 	u32 link_params_rate;
34eea8f024SBjorn Andersson 	const struct drm_display_mode *drm_mode;
35d11a9369SAbhinav Kumar 
36d11a9369SAbhinav Kumar 	if (!debug)
37d11a9369SAbhinav Kumar 		return -ENODEV;
38d11a9369SAbhinav Kumar 
39d11a9369SAbhinav Kumar 	drm_mode = &debug->panel->dp_mode.drm_mode;
40d11a9369SAbhinav Kumar 
41eea8f024SBjorn Andersson 	seq_printf(seq, "\tname = %s\n", DEBUG_NAME);
42eea8f024SBjorn Andersson 	seq_printf(seq, "\tdrm_dp_link\n\t\trate = %u\n",
43d11a9369SAbhinav Kumar 			debug->panel->link_info.rate);
44eea8f024SBjorn Andersson 	seq_printf(seq, "\t\tnum_lanes = %u\n",
45d11a9369SAbhinav Kumar 			debug->panel->link_info.num_lanes);
46eea8f024SBjorn Andersson 	seq_printf(seq, "\t\tcapabilities = %lu\n",
47d11a9369SAbhinav Kumar 			debug->panel->link_info.capabilities);
48eea8f024SBjorn Andersson 	seq_printf(seq, "\tdp_panel_info:\n\t\tactive = %dx%d\n",
49d11a9369SAbhinav Kumar 			drm_mode->hdisplay,
50d11a9369SAbhinav Kumar 			drm_mode->vdisplay);
51eea8f024SBjorn Andersson 	seq_printf(seq, "\t\tback_porch = %dx%d\n",
52d11a9369SAbhinav Kumar 			drm_mode->htotal - drm_mode->hsync_end,
53d11a9369SAbhinav Kumar 			drm_mode->vtotal - drm_mode->vsync_end);
54eea8f024SBjorn Andersson 	seq_printf(seq, "\t\tfront_porch = %dx%d\n",
55d11a9369SAbhinav Kumar 			drm_mode->hsync_start - drm_mode->hdisplay,
56d11a9369SAbhinav Kumar 			drm_mode->vsync_start - drm_mode->vdisplay);
57eea8f024SBjorn Andersson 	seq_printf(seq, "\t\tsync_width = %dx%d\n",
58d11a9369SAbhinav Kumar 			drm_mode->hsync_end - drm_mode->hsync_start,
59d11a9369SAbhinav Kumar 			drm_mode->vsync_end - drm_mode->vsync_start);
60eea8f024SBjorn Andersson 	seq_printf(seq, "\t\tactive_low = %dx%d\n",
61d11a9369SAbhinav Kumar 			debug->panel->dp_mode.h_active_low,
62d11a9369SAbhinav Kumar 			debug->panel->dp_mode.v_active_low);
63eea8f024SBjorn Andersson 	seq_printf(seq, "\t\th_skew = %d\n",
64d11a9369SAbhinav Kumar 			drm_mode->hskew);
65eea8f024SBjorn Andersson 	seq_printf(seq, "\t\trefresh rate = %d\n",
66d11a9369SAbhinav Kumar 			drm_mode_vrefresh(drm_mode));
67eea8f024SBjorn Andersson 	seq_printf(seq, "\t\tpixel clock khz = %d\n",
68d11a9369SAbhinav Kumar 			drm_mode->clock);
69eea8f024SBjorn Andersson 	seq_printf(seq, "\t\tbpp = %d\n",
70d11a9369SAbhinav Kumar 			debug->panel->dp_mode.bpp);
71d11a9369SAbhinav Kumar 
72d11a9369SAbhinav Kumar 	/* Link Information */
73eea8f024SBjorn Andersson 	seq_printf(seq, "\tdp_link:\n\t\ttest_requested = %d\n",
74d11a9369SAbhinav Kumar 			debug->link->sink_request);
75eea8f024SBjorn Andersson 	seq_printf(seq, "\t\tnum_lanes = %d\n",
76d11a9369SAbhinav Kumar 			debug->link->link_params.num_lanes);
77d11a9369SAbhinav Kumar 	link_params_rate = debug->link->link_params.rate;
78eea8f024SBjorn Andersson 	seq_printf(seq, "\t\tbw_code = %d\n",
79d11a9369SAbhinav Kumar 			drm_dp_link_rate_to_bw_code(link_params_rate));
80d11a9369SAbhinav Kumar 	lclk = debug->link->link_params.rate * 1000;
81eea8f024SBjorn Andersson 	seq_printf(seq, "\t\tlclk = %lld\n", lclk);
82eea8f024SBjorn Andersson 	seq_printf(seq, "\t\tv_level = %d\n",
83d11a9369SAbhinav Kumar 			debug->link->phy_params.v_level);
84eea8f024SBjorn Andersson 	seq_printf(seq, "\t\tp_level = %d\n",
85d11a9369SAbhinav Kumar 			debug->link->phy_params.p_level);
86d11a9369SAbhinav Kumar 
87eea8f024SBjorn Andersson 	return 0;
88d11a9369SAbhinav Kumar }
89eea8f024SBjorn Andersson DEFINE_SHOW_ATTRIBUTE(dp_debug);
90d11a9369SAbhinav Kumar 
91de3ee254SAbhinav Kumar static int dp_test_data_show(struct seq_file *m, void *data)
92de3ee254SAbhinav Kumar {
93899b2608SBjorn Andersson 	const struct dp_debug_private *debug = m->private;
94899b2608SBjorn Andersson 	const struct drm_connector *connector = debug->connector;
95de3ee254SAbhinav Kumar 	u32 bpc;
96de3ee254SAbhinav Kumar 
97de3ee254SAbhinav Kumar 	if (connector->status == connector_status_connected) {
98de3ee254SAbhinav Kumar 		bpc = debug->link->test_video.test_bit_depth;
99de3ee254SAbhinav Kumar 		seq_printf(m, "hdisplay: %d\n",
100de3ee254SAbhinav Kumar 				debug->link->test_video.test_h_width);
101de3ee254SAbhinav Kumar 		seq_printf(m, "vdisplay: %d\n",
102de3ee254SAbhinav Kumar 				debug->link->test_video.test_v_height);
103de3ee254SAbhinav Kumar 		seq_printf(m, "bpc: %u\n",
104de3ee254SAbhinav Kumar 				dp_link_bit_depth_to_bpc(bpc));
105899b2608SBjorn Andersson 	} else {
106de3ee254SAbhinav Kumar 		seq_puts(m, "0");
107de3ee254SAbhinav Kumar 	}
108de3ee254SAbhinav Kumar 
109de3ee254SAbhinav Kumar 	return 0;
110de3ee254SAbhinav Kumar }
111de3ee254SAbhinav Kumar DEFINE_SHOW_ATTRIBUTE(dp_test_data);
112de3ee254SAbhinav Kumar 
113de3ee254SAbhinav Kumar static int dp_test_type_show(struct seq_file *m, void *data)
114de3ee254SAbhinav Kumar {
115899b2608SBjorn Andersson 	const struct dp_debug_private *debug = m->private;
116899b2608SBjorn Andersson 	const struct drm_connector *connector = debug->connector;
117de3ee254SAbhinav Kumar 
118de3ee254SAbhinav Kumar 	if (connector->status == connector_status_connected)
119de3ee254SAbhinav Kumar 		seq_printf(m, "%02x", DP_TEST_LINK_VIDEO_PATTERN);
120de3ee254SAbhinav Kumar 	else
121de3ee254SAbhinav Kumar 		seq_puts(m, "0");
122de3ee254SAbhinav Kumar 
123de3ee254SAbhinav Kumar 	return 0;
124de3ee254SAbhinav Kumar }
125de3ee254SAbhinav Kumar DEFINE_SHOW_ATTRIBUTE(dp_test_type);
126de3ee254SAbhinav Kumar 
127de3ee254SAbhinav Kumar static ssize_t dp_test_active_write(struct file *file,
128de3ee254SAbhinav Kumar 		const char __user *ubuf,
129de3ee254SAbhinav Kumar 		size_t len, loff_t *offp)
130de3ee254SAbhinav Kumar {
131de3ee254SAbhinav Kumar 	char *input_buffer;
132de3ee254SAbhinav Kumar 	int status = 0;
133899b2608SBjorn Andersson 	const struct dp_debug_private *debug;
134899b2608SBjorn Andersson 	const struct drm_connector *connector;
135de3ee254SAbhinav Kumar 	int val = 0;
136de3ee254SAbhinav Kumar 
137de3ee254SAbhinav Kumar 	debug = ((struct seq_file *)file->private_data)->private;
138899b2608SBjorn Andersson 	connector = debug->connector;
139de3ee254SAbhinav Kumar 
140de3ee254SAbhinav Kumar 	if (len == 0)
141de3ee254SAbhinav Kumar 		return 0;
142de3ee254SAbhinav Kumar 
143de3ee254SAbhinav Kumar 	input_buffer = memdup_user_nul(ubuf, len);
144de3ee254SAbhinav Kumar 	if (IS_ERR(input_buffer))
145de3ee254SAbhinav Kumar 		return PTR_ERR(input_buffer);
146de3ee254SAbhinav Kumar 
147de3ee254SAbhinav Kumar 	DRM_DEBUG_DRIVER("Copied %d bytes from user\n", (unsigned int)len);
148de3ee254SAbhinav Kumar 
149de3ee254SAbhinav Kumar 	if (connector->status == connector_status_connected) {
150de3ee254SAbhinav Kumar 		status = kstrtoint(input_buffer, 10, &val);
151899b2608SBjorn Andersson 		if (status < 0) {
152899b2608SBjorn Andersson 			kfree(input_buffer);
153899b2608SBjorn Andersson 			return status;
154899b2608SBjorn Andersson 		}
155de3ee254SAbhinav Kumar 		DRM_DEBUG_DRIVER("Got %d for test active\n", val);
156de3ee254SAbhinav Kumar 		/* To prevent erroneous activation of the compliance
157de3ee254SAbhinav Kumar 		 * testing code, only accept an actual value of 1 here
158de3ee254SAbhinav Kumar 		 */
159de3ee254SAbhinav Kumar 		if (val == 1)
160de3ee254SAbhinav Kumar 			debug->panel->video_test = true;
161de3ee254SAbhinav Kumar 		else
162de3ee254SAbhinav Kumar 			debug->panel->video_test = false;
163de3ee254SAbhinav Kumar 	}
164de3ee254SAbhinav Kumar 	kfree(input_buffer);
165de3ee254SAbhinav Kumar 
166de3ee254SAbhinav Kumar 	*offp += len;
167de3ee254SAbhinav Kumar 	return len;
168de3ee254SAbhinav Kumar }
169de3ee254SAbhinav Kumar 
170de3ee254SAbhinav Kumar static int dp_test_active_show(struct seq_file *m, void *data)
171de3ee254SAbhinav Kumar {
172de3ee254SAbhinav Kumar 	struct dp_debug_private *debug = m->private;
173899b2608SBjorn Andersson 	struct drm_connector *connector = debug->connector;
174de3ee254SAbhinav Kumar 
175de3ee254SAbhinav Kumar 	if (connector->status == connector_status_connected) {
176de3ee254SAbhinav Kumar 		if (debug->panel->video_test)
177de3ee254SAbhinav Kumar 			seq_puts(m, "1");
178de3ee254SAbhinav Kumar 		else
179de3ee254SAbhinav Kumar 			seq_puts(m, "0");
180899b2608SBjorn Andersson 	} else {
181de3ee254SAbhinav Kumar 		seq_puts(m, "0");
182de3ee254SAbhinav Kumar 	}
183de3ee254SAbhinav Kumar 
184de3ee254SAbhinav Kumar 	return 0;
185de3ee254SAbhinav Kumar }
186de3ee254SAbhinav Kumar 
187de3ee254SAbhinav Kumar static int dp_test_active_open(struct inode *inode,
188de3ee254SAbhinav Kumar 		struct file *file)
189de3ee254SAbhinav Kumar {
190de3ee254SAbhinav Kumar 	return single_open(file, dp_test_active_show,
191de3ee254SAbhinav Kumar 			inode->i_private);
192de3ee254SAbhinav Kumar }
193de3ee254SAbhinav Kumar 
194de3ee254SAbhinav Kumar static const struct file_operations test_active_fops = {
195de3ee254SAbhinav Kumar 	.owner = THIS_MODULE,
196de3ee254SAbhinav Kumar 	.open = dp_test_active_open,
197de3ee254SAbhinav Kumar 	.read = seq_read,
198de3ee254SAbhinav Kumar 	.llseek = seq_lseek,
199de3ee254SAbhinav Kumar 	.release = single_release,
200de3ee254SAbhinav Kumar 	.write = dp_test_active_write
201de3ee254SAbhinav Kumar };
202de3ee254SAbhinav Kumar 
203*ab842041SDmitry Baryshkov static void dp_debug_init(struct dp_debug *dp_debug, struct dentry *root, bool is_edp)
204d11a9369SAbhinav Kumar {
205d11a9369SAbhinav Kumar 	struct dp_debug_private *debug = container_of(dp_debug,
206d11a9369SAbhinav Kumar 			struct dp_debug_private, dp_debug);
207d11a9369SAbhinav Kumar 
208*ab842041SDmitry Baryshkov 	debugfs_create_file("dp_debug", 0444, root,
209d11a9369SAbhinav Kumar 			debug, &dp_debug_fops);
210d11a9369SAbhinav Kumar 
211*ab842041SDmitry Baryshkov 	if (!is_edp) {
212cb3fd74aSAbhinav Kumar 		debugfs_create_file("msm_dp_test_active", 0444,
213*ab842041SDmitry Baryshkov 				    root,
214de3ee254SAbhinav Kumar 				    debug, &test_active_fops);
215de3ee254SAbhinav Kumar 
216cb3fd74aSAbhinav Kumar 		debugfs_create_file("msm_dp_test_data", 0444,
217*ab842041SDmitry Baryshkov 				    root,
218de3ee254SAbhinav Kumar 				    debug, &dp_test_data_fops);
219de3ee254SAbhinav Kumar 
220cb3fd74aSAbhinav Kumar 		debugfs_create_file("msm_dp_test_type", 0444,
221*ab842041SDmitry Baryshkov 				    root,
222de3ee254SAbhinav Kumar 				    debug, &dp_test_type_fops);
223d11a9369SAbhinav Kumar 	}
224*ab842041SDmitry Baryshkov }
225d11a9369SAbhinav Kumar 
226d11a9369SAbhinav Kumar struct dp_debug *dp_debug_get(struct device *dev, struct dp_panel *panel,
2271c5f6051SDmitry Baryshkov 		struct dp_link *link,
228*ab842041SDmitry Baryshkov 		struct drm_connector *connector,
229*ab842041SDmitry Baryshkov 		struct dentry *root, bool is_edp)
230d11a9369SAbhinav Kumar {
231d11a9369SAbhinav Kumar 	struct dp_debug_private *debug;
232d11a9369SAbhinav Kumar 	struct dp_debug *dp_debug;
23331e0889dSChristophe JAILLET 	int rc;
234d11a9369SAbhinav Kumar 
2351c5f6051SDmitry Baryshkov 	if (!dev || !panel || !link) {
236d11a9369SAbhinav Kumar 		DRM_ERROR("invalid input\n");
237d11a9369SAbhinav Kumar 		rc = -EINVAL;
238d11a9369SAbhinav Kumar 		goto error;
239d11a9369SAbhinav Kumar 	}
240d11a9369SAbhinav Kumar 
241d11a9369SAbhinav Kumar 	debug = devm_kzalloc(dev, sizeof(*debug), GFP_KERNEL);
242d11a9369SAbhinav Kumar 	if (!debug) {
243d11a9369SAbhinav Kumar 		rc = -ENOMEM;
244d11a9369SAbhinav Kumar 		goto error;
245d11a9369SAbhinav Kumar 	}
246d11a9369SAbhinav Kumar 
247d11a9369SAbhinav Kumar 	debug->dp_debug.debug_en = false;
248d11a9369SAbhinav Kumar 	debug->link = link;
249d11a9369SAbhinav Kumar 	debug->panel = panel;
250d11a9369SAbhinav Kumar 
251d11a9369SAbhinav Kumar 	dp_debug = &debug->dp_debug;
252d11a9369SAbhinav Kumar 	dp_debug->vdisplay = 0;
253d11a9369SAbhinav Kumar 	dp_debug->hdisplay = 0;
254d11a9369SAbhinav Kumar 	dp_debug->vrefresh = 0;
255d11a9369SAbhinav Kumar 
256*ab842041SDmitry Baryshkov 	dp_debug_init(dp_debug, root, is_edp);
257d11a9369SAbhinav Kumar 
258d11a9369SAbhinav Kumar 	return dp_debug;
259d11a9369SAbhinav Kumar  error:
260d11a9369SAbhinav Kumar 	return ERR_PTR(rc);
261d11a9369SAbhinav Kumar }
262