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