xref: /linux/drivers/gpu/drm/msm/dp/dp_debug.c (revision cb3fd74a03e8dcd6940f7a5739e531db3e1bcd7b)
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 dentry *root;
23d11a9369SAbhinav Kumar 
24d11a9369SAbhinav Kumar 	struct dp_usbpd *usbpd;
25d11a9369SAbhinav Kumar 	struct dp_link *link;
26d11a9369SAbhinav Kumar 	struct dp_panel *panel;
27d11a9369SAbhinav Kumar 	struct drm_connector **connector;
28d11a9369SAbhinav Kumar 	struct device *dev;
29f913454aSAbhinav Kumar 	struct drm_device *drm_dev;
30d11a9369SAbhinav Kumar 
31d11a9369SAbhinav Kumar 	struct dp_debug dp_debug;
32d11a9369SAbhinav Kumar };
33d11a9369SAbhinav Kumar 
34d11a9369SAbhinav Kumar static int dp_debug_check_buffer_overflow(int rc, int *max_size, int *len)
35d11a9369SAbhinav Kumar {
36d11a9369SAbhinav Kumar 	if (rc >= *max_size) {
37d11a9369SAbhinav Kumar 		DRM_ERROR("buffer overflow\n");
38d11a9369SAbhinav Kumar 		return -EINVAL;
39d11a9369SAbhinav Kumar 	}
40d11a9369SAbhinav Kumar 	*len += rc;
41d11a9369SAbhinav Kumar 	*max_size = SZ_4K - *len;
42d11a9369SAbhinav Kumar 
43d11a9369SAbhinav Kumar 	return 0;
44d11a9369SAbhinav Kumar }
45d11a9369SAbhinav Kumar 
46d11a9369SAbhinav Kumar static ssize_t dp_debug_read_info(struct file *file, char __user *user_buff,
47d11a9369SAbhinav Kumar 		size_t count, loff_t *ppos)
48d11a9369SAbhinav Kumar {
49d11a9369SAbhinav Kumar 	struct dp_debug_private *debug = file->private_data;
50d11a9369SAbhinav Kumar 	char *buf;
51d11a9369SAbhinav Kumar 	u32 len = 0, rc = 0;
52d11a9369SAbhinav Kumar 	u64 lclk = 0;
53d11a9369SAbhinav Kumar 	u32 max_size = SZ_4K;
54d11a9369SAbhinav Kumar 	u32 link_params_rate;
55d11a9369SAbhinav Kumar 	struct drm_display_mode *drm_mode;
56d11a9369SAbhinav Kumar 
57d11a9369SAbhinav Kumar 	if (!debug)
58d11a9369SAbhinav Kumar 		return -ENODEV;
59d11a9369SAbhinav Kumar 
60d11a9369SAbhinav Kumar 	if (*ppos)
61d11a9369SAbhinav Kumar 		return 0;
62d11a9369SAbhinav Kumar 
63d11a9369SAbhinav Kumar 	buf = kzalloc(SZ_4K, GFP_KERNEL);
64d11a9369SAbhinav Kumar 	if (!buf)
65d11a9369SAbhinav Kumar 		return -ENOMEM;
66d11a9369SAbhinav Kumar 
67d11a9369SAbhinav Kumar 	drm_mode = &debug->panel->dp_mode.drm_mode;
68d11a9369SAbhinav Kumar 
69d11a9369SAbhinav Kumar 	rc = snprintf(buf + len, max_size, "\tname = %s\n", DEBUG_NAME);
70d11a9369SAbhinav Kumar 	if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
71d11a9369SAbhinav Kumar 		goto error;
72d11a9369SAbhinav Kumar 
73d11a9369SAbhinav Kumar 	rc = snprintf(buf + len, max_size,
74d11a9369SAbhinav Kumar 			"\tdp_panel\n\t\tmax_pclk_khz = %d\n",
75d11a9369SAbhinav Kumar 			debug->panel->max_pclk_khz);
76d11a9369SAbhinav Kumar 	if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
77d11a9369SAbhinav Kumar 		goto error;
78d11a9369SAbhinav Kumar 
79d11a9369SAbhinav Kumar 	rc = snprintf(buf + len, max_size,
80d11a9369SAbhinav Kumar 			"\tdrm_dp_link\n\t\trate = %u\n",
81d11a9369SAbhinav Kumar 			debug->panel->link_info.rate);
82d11a9369SAbhinav Kumar 	if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
83d11a9369SAbhinav Kumar 		goto error;
84d11a9369SAbhinav Kumar 
85d11a9369SAbhinav Kumar 	rc = snprintf(buf + len, max_size,
86d11a9369SAbhinav Kumar 			 "\t\tnum_lanes = %u\n",
87d11a9369SAbhinav Kumar 			debug->panel->link_info.num_lanes);
88d11a9369SAbhinav Kumar 	if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
89d11a9369SAbhinav Kumar 		goto error;
90d11a9369SAbhinav Kumar 
91d11a9369SAbhinav Kumar 	rc = snprintf(buf + len, max_size,
92d11a9369SAbhinav Kumar 			"\t\tcapabilities = %lu\n",
93d11a9369SAbhinav Kumar 			debug->panel->link_info.capabilities);
94d11a9369SAbhinav Kumar 	if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
95d11a9369SAbhinav Kumar 		goto error;
96d11a9369SAbhinav Kumar 
97d11a9369SAbhinav Kumar 	rc = snprintf(buf + len, max_size,
98d11a9369SAbhinav Kumar 			"\tdp_panel_info:\n\t\tactive = %dx%d\n",
99d11a9369SAbhinav Kumar 			drm_mode->hdisplay,
100d11a9369SAbhinav Kumar 			drm_mode->vdisplay);
101d11a9369SAbhinav Kumar 	if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
102d11a9369SAbhinav Kumar 		goto error;
103d11a9369SAbhinav Kumar 
104d11a9369SAbhinav Kumar 	rc = snprintf(buf + len, max_size,
105d11a9369SAbhinav Kumar 			"\t\tback_porch = %dx%d\n",
106d11a9369SAbhinav Kumar 			drm_mode->htotal - drm_mode->hsync_end,
107d11a9369SAbhinav Kumar 			drm_mode->vtotal - drm_mode->vsync_end);
108d11a9369SAbhinav Kumar 	if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
109d11a9369SAbhinav Kumar 		goto error;
110d11a9369SAbhinav Kumar 
111d11a9369SAbhinav Kumar 	rc = snprintf(buf + len, max_size,
112d11a9369SAbhinav Kumar 			"\t\tfront_porch = %dx%d\n",
113d11a9369SAbhinav Kumar 			drm_mode->hsync_start - drm_mode->hdisplay,
114d11a9369SAbhinav Kumar 			drm_mode->vsync_start - drm_mode->vdisplay);
115d11a9369SAbhinav Kumar 	if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
116d11a9369SAbhinav Kumar 		goto error;
117d11a9369SAbhinav Kumar 
118d11a9369SAbhinav Kumar 	rc = snprintf(buf + len, max_size,
119d11a9369SAbhinav Kumar 			"\t\tsync_width = %dx%d\n",
120d11a9369SAbhinav Kumar 			drm_mode->hsync_end - drm_mode->hsync_start,
121d11a9369SAbhinav Kumar 			drm_mode->vsync_end - drm_mode->vsync_start);
122d11a9369SAbhinav Kumar 	if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
123d11a9369SAbhinav Kumar 		goto error;
124d11a9369SAbhinav Kumar 
125d11a9369SAbhinav Kumar 	rc = snprintf(buf + len, max_size,
126d11a9369SAbhinav Kumar 			"\t\tactive_low = %dx%d\n",
127d11a9369SAbhinav Kumar 			debug->panel->dp_mode.h_active_low,
128d11a9369SAbhinav Kumar 			debug->panel->dp_mode.v_active_low);
129d11a9369SAbhinav Kumar 	if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
130d11a9369SAbhinav Kumar 		goto error;
131d11a9369SAbhinav Kumar 
132d11a9369SAbhinav Kumar 	rc = snprintf(buf + len, max_size,
133d11a9369SAbhinav Kumar 			"\t\th_skew = %d\n",
134d11a9369SAbhinav Kumar 			drm_mode->hskew);
135d11a9369SAbhinav Kumar 	if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
136d11a9369SAbhinav Kumar 		goto error;
137d11a9369SAbhinav Kumar 
138d11a9369SAbhinav Kumar 	rc = snprintf(buf + len, max_size,
139d11a9369SAbhinav Kumar 			"\t\trefresh rate = %d\n",
140d11a9369SAbhinav Kumar 			drm_mode_vrefresh(drm_mode));
141d11a9369SAbhinav Kumar 	if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
142d11a9369SAbhinav Kumar 		goto error;
143d11a9369SAbhinav Kumar 
144d11a9369SAbhinav Kumar 	rc = snprintf(buf + len, max_size,
145d11a9369SAbhinav Kumar 			"\t\tpixel clock khz = %d\n",
146d11a9369SAbhinav Kumar 			drm_mode->clock);
147d11a9369SAbhinav Kumar 	if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
148d11a9369SAbhinav Kumar 		goto error;
149d11a9369SAbhinav Kumar 
150d11a9369SAbhinav Kumar 	rc = snprintf(buf + len, max_size,
151d11a9369SAbhinav Kumar 			"\t\tbpp = %d\n",
152d11a9369SAbhinav Kumar 			debug->panel->dp_mode.bpp);
153d11a9369SAbhinav Kumar 	if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
154d11a9369SAbhinav Kumar 		goto error;
155d11a9369SAbhinav Kumar 
156d11a9369SAbhinav Kumar 	/* Link Information */
157d11a9369SAbhinav Kumar 	rc = snprintf(buf + len, max_size,
158d11a9369SAbhinav Kumar 			"\tdp_link:\n\t\ttest_requested = %d\n",
159d11a9369SAbhinav Kumar 			debug->link->sink_request);
160d11a9369SAbhinav Kumar 	if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
161d11a9369SAbhinav Kumar 		goto error;
162d11a9369SAbhinav Kumar 
163d11a9369SAbhinav Kumar 	rc = snprintf(buf + len, max_size,
164d11a9369SAbhinav Kumar 			"\t\tnum_lanes = %d\n",
165d11a9369SAbhinav Kumar 			debug->link->link_params.num_lanes);
166d11a9369SAbhinav Kumar 	if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
167d11a9369SAbhinav Kumar 		goto error;
168d11a9369SAbhinav Kumar 
169d11a9369SAbhinav Kumar 	link_params_rate = debug->link->link_params.rate;
170d11a9369SAbhinav Kumar 	rc = snprintf(buf + len, max_size,
171d11a9369SAbhinav Kumar 			"\t\tbw_code = %d\n",
172d11a9369SAbhinav Kumar 			drm_dp_link_rate_to_bw_code(link_params_rate));
173d11a9369SAbhinav Kumar 	if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
174d11a9369SAbhinav Kumar 		goto error;
175d11a9369SAbhinav Kumar 
176d11a9369SAbhinav Kumar 	lclk = debug->link->link_params.rate * 1000;
177d11a9369SAbhinav Kumar 	rc = snprintf(buf + len, max_size,
178d11a9369SAbhinav Kumar 			"\t\tlclk = %lld\n", lclk);
179d11a9369SAbhinav Kumar 	if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
180d11a9369SAbhinav Kumar 		goto error;
181d11a9369SAbhinav Kumar 
182d11a9369SAbhinav Kumar 	rc = snprintf(buf + len, max_size,
183d11a9369SAbhinav Kumar 			"\t\tv_level = %d\n",
184d11a9369SAbhinav Kumar 			debug->link->phy_params.v_level);
185d11a9369SAbhinav Kumar 	if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
186d11a9369SAbhinav Kumar 		goto error;
187d11a9369SAbhinav Kumar 
188d11a9369SAbhinav Kumar 	rc = snprintf(buf + len, max_size,
189d11a9369SAbhinav Kumar 			"\t\tp_level = %d\n",
190d11a9369SAbhinav Kumar 			debug->link->phy_params.p_level);
191d11a9369SAbhinav Kumar 	if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
192d11a9369SAbhinav Kumar 		goto error;
193d11a9369SAbhinav Kumar 
194d11a9369SAbhinav Kumar 	if (copy_to_user(user_buff, buf, len))
195d11a9369SAbhinav Kumar 		goto error;
196d11a9369SAbhinav Kumar 
197d11a9369SAbhinav Kumar 	*ppos += len;
198d11a9369SAbhinav Kumar 
199d11a9369SAbhinav Kumar 	kfree(buf);
200d11a9369SAbhinav Kumar 	return len;
201d11a9369SAbhinav Kumar  error:
202d11a9369SAbhinav Kumar 	kfree(buf);
203d11a9369SAbhinav Kumar 	return -EINVAL;
204d11a9369SAbhinav Kumar }
205d11a9369SAbhinav Kumar 
206de3ee254SAbhinav Kumar static int dp_test_data_show(struct seq_file *m, void *data)
207de3ee254SAbhinav Kumar {
208de3ee254SAbhinav Kumar 	struct drm_device *dev;
209de3ee254SAbhinav Kumar 	struct dp_debug_private *debug;
210de3ee254SAbhinav Kumar 	struct drm_connector *connector;
211de3ee254SAbhinav Kumar 	struct drm_connector_list_iter conn_iter;
212de3ee254SAbhinav Kumar 	u32 bpc;
213de3ee254SAbhinav Kumar 
214de3ee254SAbhinav Kumar 	debug = m->private;
215de3ee254SAbhinav Kumar 	dev = debug->drm_dev;
216de3ee254SAbhinav Kumar 	drm_connector_list_iter_begin(dev, &conn_iter);
217de3ee254SAbhinav Kumar 	drm_for_each_connector_iter(connector, &conn_iter) {
218de3ee254SAbhinav Kumar 
219de3ee254SAbhinav Kumar 		if (connector->connector_type !=
220de3ee254SAbhinav Kumar 			DRM_MODE_CONNECTOR_DisplayPort)
221de3ee254SAbhinav Kumar 			continue;
222de3ee254SAbhinav Kumar 
223de3ee254SAbhinav Kumar 		if (connector->status == connector_status_connected) {
224de3ee254SAbhinav Kumar 			bpc = debug->link->test_video.test_bit_depth;
225de3ee254SAbhinav Kumar 			seq_printf(m, "hdisplay: %d\n",
226de3ee254SAbhinav Kumar 					debug->link->test_video.test_h_width);
227de3ee254SAbhinav Kumar 			seq_printf(m, "vdisplay: %d\n",
228de3ee254SAbhinav Kumar 					debug->link->test_video.test_v_height);
229de3ee254SAbhinav Kumar 			seq_printf(m, "bpc: %u\n",
230de3ee254SAbhinav Kumar 					dp_link_bit_depth_to_bpc(bpc));
231de3ee254SAbhinav Kumar 		} else
232de3ee254SAbhinav Kumar 			seq_puts(m, "0");
233de3ee254SAbhinav Kumar 	}
234de3ee254SAbhinav Kumar 
235de3ee254SAbhinav Kumar 	drm_connector_list_iter_end(&conn_iter);
236de3ee254SAbhinav Kumar 
237de3ee254SAbhinav Kumar 	return 0;
238de3ee254SAbhinav Kumar }
239de3ee254SAbhinav Kumar DEFINE_SHOW_ATTRIBUTE(dp_test_data);
240de3ee254SAbhinav Kumar 
241de3ee254SAbhinav Kumar static int dp_test_type_show(struct seq_file *m, void *data)
242de3ee254SAbhinav Kumar {
243de3ee254SAbhinav Kumar 	struct dp_debug_private *debug = m->private;
244de3ee254SAbhinav Kumar 	struct drm_device *dev = debug->drm_dev;
245de3ee254SAbhinav Kumar 	struct drm_connector *connector;
246de3ee254SAbhinav Kumar 	struct drm_connector_list_iter conn_iter;
247de3ee254SAbhinav Kumar 
248de3ee254SAbhinav Kumar 	drm_connector_list_iter_begin(dev, &conn_iter);
249de3ee254SAbhinav Kumar 	drm_for_each_connector_iter(connector, &conn_iter) {
250de3ee254SAbhinav Kumar 
251de3ee254SAbhinav Kumar 		if (connector->connector_type !=
252de3ee254SAbhinav Kumar 			DRM_MODE_CONNECTOR_DisplayPort)
253de3ee254SAbhinav Kumar 			continue;
254de3ee254SAbhinav Kumar 
255de3ee254SAbhinav Kumar 		if (connector->status == connector_status_connected)
256de3ee254SAbhinav Kumar 			seq_printf(m, "%02x", DP_TEST_LINK_VIDEO_PATTERN);
257de3ee254SAbhinav Kumar 		else
258de3ee254SAbhinav Kumar 			seq_puts(m, "0");
259de3ee254SAbhinav Kumar 	}
260de3ee254SAbhinav Kumar 	drm_connector_list_iter_end(&conn_iter);
261de3ee254SAbhinav Kumar 
262de3ee254SAbhinav Kumar 	return 0;
263de3ee254SAbhinav Kumar }
264de3ee254SAbhinav Kumar DEFINE_SHOW_ATTRIBUTE(dp_test_type);
265de3ee254SAbhinav Kumar 
266de3ee254SAbhinav Kumar static ssize_t dp_test_active_write(struct file *file,
267de3ee254SAbhinav Kumar 		const char __user *ubuf,
268de3ee254SAbhinav Kumar 		size_t len, loff_t *offp)
269de3ee254SAbhinav Kumar {
270de3ee254SAbhinav Kumar 	char *input_buffer;
271de3ee254SAbhinav Kumar 	int status = 0;
272de3ee254SAbhinav Kumar 	struct dp_debug_private *debug;
273de3ee254SAbhinav Kumar 	struct drm_device *dev;
274de3ee254SAbhinav Kumar 	struct drm_connector *connector;
275de3ee254SAbhinav Kumar 	struct drm_connector_list_iter conn_iter;
276de3ee254SAbhinav Kumar 	int val = 0;
277de3ee254SAbhinav Kumar 
278de3ee254SAbhinav Kumar 	debug = ((struct seq_file *)file->private_data)->private;
279de3ee254SAbhinav Kumar 	dev = debug->drm_dev;
280de3ee254SAbhinav Kumar 
281de3ee254SAbhinav Kumar 	if (len == 0)
282de3ee254SAbhinav Kumar 		return 0;
283de3ee254SAbhinav Kumar 
284de3ee254SAbhinav Kumar 	input_buffer = memdup_user_nul(ubuf, len);
285de3ee254SAbhinav Kumar 	if (IS_ERR(input_buffer))
286de3ee254SAbhinav Kumar 		return PTR_ERR(input_buffer);
287de3ee254SAbhinav Kumar 
288de3ee254SAbhinav Kumar 	DRM_DEBUG_DRIVER("Copied %d bytes from user\n", (unsigned int)len);
289de3ee254SAbhinav Kumar 
290de3ee254SAbhinav Kumar 	drm_connector_list_iter_begin(dev, &conn_iter);
291de3ee254SAbhinav Kumar 	drm_for_each_connector_iter(connector, &conn_iter) {
292de3ee254SAbhinav Kumar 		if (connector->connector_type !=
293de3ee254SAbhinav Kumar 			DRM_MODE_CONNECTOR_DisplayPort)
294de3ee254SAbhinav Kumar 			continue;
295de3ee254SAbhinav Kumar 
296de3ee254SAbhinav Kumar 		if (connector->status == connector_status_connected) {
297de3ee254SAbhinav Kumar 			status = kstrtoint(input_buffer, 10, &val);
298de3ee254SAbhinav Kumar 			if (status < 0)
299de3ee254SAbhinav Kumar 				break;
300de3ee254SAbhinav Kumar 			DRM_DEBUG_DRIVER("Got %d for test active\n", val);
301de3ee254SAbhinav Kumar 			/* To prevent erroneous activation of the compliance
302de3ee254SAbhinav Kumar 			 * testing code, only accept an actual value of 1 here
303de3ee254SAbhinav Kumar 			 */
304de3ee254SAbhinav Kumar 			if (val == 1)
305de3ee254SAbhinav Kumar 				debug->panel->video_test = true;
306de3ee254SAbhinav Kumar 			else
307de3ee254SAbhinav Kumar 				debug->panel->video_test = false;
308de3ee254SAbhinav Kumar 		}
309de3ee254SAbhinav Kumar 	}
310de3ee254SAbhinav Kumar 	drm_connector_list_iter_end(&conn_iter);
311de3ee254SAbhinav Kumar 	kfree(input_buffer);
312de3ee254SAbhinav Kumar 	if (status < 0)
313de3ee254SAbhinav Kumar 		return status;
314de3ee254SAbhinav Kumar 
315de3ee254SAbhinav Kumar 	*offp += len;
316de3ee254SAbhinav Kumar 	return len;
317de3ee254SAbhinav Kumar }
318de3ee254SAbhinav Kumar 
319de3ee254SAbhinav Kumar static int dp_test_active_show(struct seq_file *m, void *data)
320de3ee254SAbhinav Kumar {
321de3ee254SAbhinav Kumar 	struct dp_debug_private *debug = m->private;
322de3ee254SAbhinav Kumar 	struct drm_device *dev = debug->drm_dev;
323de3ee254SAbhinav Kumar 	struct drm_connector *connector;
324de3ee254SAbhinav Kumar 	struct drm_connector_list_iter conn_iter;
325de3ee254SAbhinav Kumar 
326de3ee254SAbhinav Kumar 	drm_connector_list_iter_begin(dev, &conn_iter);
327de3ee254SAbhinav Kumar 	drm_for_each_connector_iter(connector, &conn_iter) {
328de3ee254SAbhinav Kumar 		if (connector->connector_type !=
329de3ee254SAbhinav Kumar 			DRM_MODE_CONNECTOR_DisplayPort)
330de3ee254SAbhinav Kumar 			continue;
331de3ee254SAbhinav Kumar 
332de3ee254SAbhinav Kumar 		if (connector->status == connector_status_connected) {
333de3ee254SAbhinav Kumar 			if (debug->panel->video_test)
334de3ee254SAbhinav Kumar 				seq_puts(m, "1");
335de3ee254SAbhinav Kumar 			else
336de3ee254SAbhinav Kumar 				seq_puts(m, "0");
337de3ee254SAbhinav Kumar 		} else
338de3ee254SAbhinav Kumar 			seq_puts(m, "0");
339de3ee254SAbhinav Kumar 	}
340de3ee254SAbhinav Kumar 	drm_connector_list_iter_end(&conn_iter);
341de3ee254SAbhinav Kumar 
342de3ee254SAbhinav Kumar 	return 0;
343de3ee254SAbhinav Kumar }
344de3ee254SAbhinav Kumar 
345de3ee254SAbhinav Kumar static int dp_test_active_open(struct inode *inode,
346de3ee254SAbhinav Kumar 		struct file *file)
347de3ee254SAbhinav Kumar {
348de3ee254SAbhinav Kumar 	return single_open(file, dp_test_active_show,
349de3ee254SAbhinav Kumar 			inode->i_private);
350de3ee254SAbhinav Kumar }
351de3ee254SAbhinav Kumar 
352d11a9369SAbhinav Kumar static const struct file_operations dp_debug_fops = {
353d11a9369SAbhinav Kumar 	.open = simple_open,
354d11a9369SAbhinav Kumar 	.read = dp_debug_read_info,
355d11a9369SAbhinav Kumar };
356d11a9369SAbhinav Kumar 
357de3ee254SAbhinav Kumar static const struct file_operations test_active_fops = {
358de3ee254SAbhinav Kumar 	.owner = THIS_MODULE,
359de3ee254SAbhinav Kumar 	.open = dp_test_active_open,
360de3ee254SAbhinav Kumar 	.read = seq_read,
361de3ee254SAbhinav Kumar 	.llseek = seq_lseek,
362de3ee254SAbhinav Kumar 	.release = single_release,
363de3ee254SAbhinav Kumar 	.write = dp_test_active_write
364de3ee254SAbhinav Kumar };
365de3ee254SAbhinav Kumar 
366f913454aSAbhinav Kumar static int dp_debug_init(struct dp_debug *dp_debug, struct drm_minor *minor)
367d11a9369SAbhinav Kumar {
368d11a9369SAbhinav Kumar 	int rc = 0;
369d11a9369SAbhinav Kumar 	struct dp_debug_private *debug = container_of(dp_debug,
370d11a9369SAbhinav Kumar 			struct dp_debug_private, dp_debug);
371d11a9369SAbhinav Kumar 
372*cb3fd74aSAbhinav Kumar 	debugfs_create_file("dp_debug", 0444, minor->debugfs_root,
373d11a9369SAbhinav Kumar 			debug, &dp_debug_fops);
374d11a9369SAbhinav Kumar 
375*cb3fd74aSAbhinav Kumar 	debugfs_create_file("msm_dp_test_active", 0444,
376de3ee254SAbhinav Kumar 			minor->debugfs_root,
377de3ee254SAbhinav Kumar 			debug, &test_active_fops);
378de3ee254SAbhinav Kumar 
379*cb3fd74aSAbhinav Kumar 	debugfs_create_file("msm_dp_test_data", 0444,
380de3ee254SAbhinav Kumar 			minor->debugfs_root,
381de3ee254SAbhinav Kumar 			debug, &dp_test_data_fops);
382de3ee254SAbhinav Kumar 
383*cb3fd74aSAbhinav Kumar 	debugfs_create_file("msm_dp_test_type", 0444,
384de3ee254SAbhinav Kumar 			minor->debugfs_root,
385de3ee254SAbhinav Kumar 			debug, &dp_test_type_fops);
386de3ee254SAbhinav Kumar 
387f913454aSAbhinav Kumar 	debug->root = minor->debugfs_root;
388f913454aSAbhinav Kumar 
389d11a9369SAbhinav Kumar 	return rc;
390d11a9369SAbhinav Kumar }
391d11a9369SAbhinav Kumar 
392d11a9369SAbhinav Kumar struct dp_debug *dp_debug_get(struct device *dev, struct dp_panel *panel,
393d11a9369SAbhinav Kumar 		struct dp_usbpd *usbpd, struct dp_link *link,
394f913454aSAbhinav Kumar 		struct drm_connector **connector, struct drm_minor *minor)
395d11a9369SAbhinav Kumar {
396d11a9369SAbhinav Kumar 	int rc = 0;
397d11a9369SAbhinav Kumar 	struct dp_debug_private *debug;
398d11a9369SAbhinav Kumar 	struct dp_debug *dp_debug;
399d11a9369SAbhinav Kumar 
400d11a9369SAbhinav Kumar 	if (!dev || !panel || !usbpd || !link) {
401d11a9369SAbhinav Kumar 		DRM_ERROR("invalid input\n");
402d11a9369SAbhinav Kumar 		rc = -EINVAL;
403d11a9369SAbhinav Kumar 		goto error;
404d11a9369SAbhinav Kumar 	}
405d11a9369SAbhinav Kumar 
406d11a9369SAbhinav Kumar 	debug = devm_kzalloc(dev, sizeof(*debug), GFP_KERNEL);
407d11a9369SAbhinav Kumar 	if (!debug) {
408d11a9369SAbhinav Kumar 		rc = -ENOMEM;
409d11a9369SAbhinav Kumar 		goto error;
410d11a9369SAbhinav Kumar 	}
411d11a9369SAbhinav Kumar 
412d11a9369SAbhinav Kumar 	debug->dp_debug.debug_en = false;
413d11a9369SAbhinav Kumar 	debug->usbpd = usbpd;
414d11a9369SAbhinav Kumar 	debug->link = link;
415d11a9369SAbhinav Kumar 	debug->panel = panel;
416d11a9369SAbhinav Kumar 	debug->dev = dev;
417f913454aSAbhinav Kumar 	debug->drm_dev = minor->dev;
418d11a9369SAbhinav Kumar 	debug->connector = connector;
419d11a9369SAbhinav Kumar 
420d11a9369SAbhinav Kumar 	dp_debug = &debug->dp_debug;
421d11a9369SAbhinav Kumar 	dp_debug->vdisplay = 0;
422d11a9369SAbhinav Kumar 	dp_debug->hdisplay = 0;
423d11a9369SAbhinav Kumar 	dp_debug->vrefresh = 0;
424d11a9369SAbhinav Kumar 
425f913454aSAbhinav Kumar 	rc = dp_debug_init(dp_debug, minor);
426d11a9369SAbhinav Kumar 	if (rc) {
427d11a9369SAbhinav Kumar 		devm_kfree(dev, debug);
428d11a9369SAbhinav Kumar 		goto error;
429d11a9369SAbhinav Kumar 	}
430d11a9369SAbhinav Kumar 
431d11a9369SAbhinav Kumar 	return dp_debug;
432d11a9369SAbhinav Kumar  error:
433d11a9369SAbhinav Kumar 	return ERR_PTR(rc);
434d11a9369SAbhinav Kumar }
435d11a9369SAbhinav Kumar 
436d11a9369SAbhinav Kumar static int dp_debug_deinit(struct dp_debug *dp_debug)
437d11a9369SAbhinav Kumar {
438d11a9369SAbhinav Kumar 	struct dp_debug_private *debug;
439d11a9369SAbhinav Kumar 
440d11a9369SAbhinav Kumar 	if (!dp_debug)
441d11a9369SAbhinav Kumar 		return -EINVAL;
442d11a9369SAbhinav Kumar 
443d11a9369SAbhinav Kumar 	debug = container_of(dp_debug, struct dp_debug_private, dp_debug);
444d11a9369SAbhinav Kumar 
445d11a9369SAbhinav Kumar 	debugfs_remove_recursive(debug->root);
446d11a9369SAbhinav Kumar 
447d11a9369SAbhinav Kumar 	return 0;
448d11a9369SAbhinav Kumar }
449d11a9369SAbhinav Kumar 
450d11a9369SAbhinav Kumar void dp_debug_put(struct dp_debug *dp_debug)
451d11a9369SAbhinav Kumar {
452d11a9369SAbhinav Kumar 	struct dp_debug_private *debug;
453d11a9369SAbhinav Kumar 
454d11a9369SAbhinav Kumar 	if (!dp_debug)
455d11a9369SAbhinav Kumar 		return;
456d11a9369SAbhinav Kumar 
457d11a9369SAbhinav Kumar 	debug = container_of(dp_debug, struct dp_debug_private, dp_debug);
458d11a9369SAbhinav Kumar 
459d11a9369SAbhinav Kumar 	dp_debug_deinit(dp_debug);
460d11a9369SAbhinav Kumar 
461d11a9369SAbhinav Kumar 	devm_kfree(debug->dev, debug);
462d11a9369SAbhinav Kumar }
463