1 /*
2  * Copyright 2018 Advanced Micro Devices, Inc.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20  * OTHER DEALINGS IN THE SOFTWARE.
21  *
22  * Authors: AMD
23  *
24  */
25 
26 #include <linux/debugfs.h>
27 
28 #include "dc.h"
29 #include "dc_link.h"
30 
31 #include "amdgpu.h"
32 #include "amdgpu_dm.h"
33 #include "amdgpu_dm_debugfs.h"
34 
35 static ssize_t dp_link_rate_debugfs_read(struct file *f, char __user *buf,
36 				 size_t size, loff_t *pos)
37 {
38 	/* TODO: create method to read link rate */
39 	return 1;
40 }
41 
42 static ssize_t dp_link_rate_debugfs_write(struct file *f, const char __user *buf,
43 				 size_t size, loff_t *pos)
44 {
45 	/* TODO: create method to write link rate */
46 	return 1;
47 }
48 
49 static ssize_t dp_lane_count_debugfs_read(struct file *f, char __user *buf,
50 				 size_t size, loff_t *pos)
51 {
52 	/* TODO: create method to read lane count */
53 	return 1;
54 }
55 
56 static ssize_t dp_lane_count_debugfs_write(struct file *f, const char __user *buf,
57 				 size_t size, loff_t *pos)
58 {
59 	/* TODO: create method to write lane count */
60 	return 1;
61 }
62 
63 static ssize_t dp_voltage_swing_debugfs_read(struct file *f, char __user *buf,
64 				 size_t size, loff_t *pos)
65 {
66 	/* TODO: create method to read voltage swing */
67 	return 1;
68 }
69 
70 static ssize_t dp_voltage_swing_debugfs_write(struct file *f, const char __user *buf,
71 				 size_t size, loff_t *pos)
72 {
73 	/* TODO: create method to write voltage swing */
74 	return 1;
75 }
76 
77 static ssize_t dp_pre_emphasis_debugfs_read(struct file *f, char __user *buf,
78 				 size_t size, loff_t *pos)
79 {
80 	/* TODO: create method to read pre-emphasis */
81 	return 1;
82 }
83 
84 static ssize_t dp_pre_emphasis_debugfs_write(struct file *f, const char __user *buf,
85 				 size_t size, loff_t *pos)
86 {
87 	/* TODO: create method to write pre-emphasis */
88 	return 1;
89 }
90 
91 static ssize_t dp_phy_test_pattern_debugfs_read(struct file *f, char __user *buf,
92 				 size_t size, loff_t *pos)
93 {
94 	/* TODO: create method to read PHY test pattern */
95 	return 1;
96 }
97 
98 static ssize_t dp_phy_test_pattern_debugfs_write(struct file *f, const char __user *buf,
99 				 size_t size, loff_t *pos)
100 {
101 	/* TODO: create method to write PHY test pattern */
102 	return 1;
103 }
104 
105 static const struct file_operations dp_link_rate_fops = {
106 	.owner = THIS_MODULE,
107 	.read = dp_link_rate_debugfs_read,
108 	.write = dp_link_rate_debugfs_write,
109 	.llseek = default_llseek
110 };
111 
112 static const struct file_operations dp_lane_count_fops = {
113 	.owner = THIS_MODULE,
114 	.read = dp_lane_count_debugfs_read,
115 	.write = dp_lane_count_debugfs_write,
116 	.llseek = default_llseek
117 };
118 
119 static const struct file_operations dp_voltage_swing_fops = {
120 	.owner = THIS_MODULE,
121 	.read = dp_voltage_swing_debugfs_read,
122 	.write = dp_voltage_swing_debugfs_write,
123 	.llseek = default_llseek
124 };
125 
126 static const struct file_operations dp_pre_emphasis_fops = {
127 	.owner = THIS_MODULE,
128 	.read = dp_pre_emphasis_debugfs_read,
129 	.write = dp_pre_emphasis_debugfs_write,
130 	.llseek = default_llseek
131 };
132 
133 static const struct file_operations dp_phy_test_pattern_fops = {
134 	.owner = THIS_MODULE,
135 	.read = dp_phy_test_pattern_debugfs_read,
136 	.write = dp_phy_test_pattern_debugfs_write,
137 	.llseek = default_llseek
138 };
139 
140 static const struct {
141 	char *name;
142 	const struct file_operations *fops;
143 } dp_debugfs_entries[] = {
144 		{"link_rate", &dp_link_rate_fops},
145 		{"lane_count", &dp_lane_count_fops},
146 		{"voltage_swing", &dp_voltage_swing_fops},
147 		{"pre_emphasis", &dp_pre_emphasis_fops},
148 		{"phy_test_pattern", &dp_phy_test_pattern_fops}
149 };
150 
151 int connector_debugfs_init(struct amdgpu_dm_connector *connector)
152 {
153 	int i;
154 	struct dentry *ent, *dir = connector->base.debugfs_entry;
155 
156 	if (connector->base.connector_type == DRM_MODE_CONNECTOR_DisplayPort) {
157 		for (i = 0; i < ARRAY_SIZE(dp_debugfs_entries); i++) {
158 			ent = debugfs_create_file(dp_debugfs_entries[i].name,
159 						  0644,
160 						  dir,
161 						  connector,
162 						  dp_debugfs_entries[i].fops);
163 			if (IS_ERR(ent))
164 				return PTR_ERR(ent);
165 		}
166 	}
167 
168 	return 0;
169 }
170 
171