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