-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathc2_mode.py
266 lines (227 loc) · 10.2 KB
/
c2_mode.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
# python3.5 c2_mode.py Modeline "3440x1440_60.00" 157.75 3440 3488 3520 3600 1440 1443 1453 1461 +HSync -Vsync
import sys
def calculate_gcd(x, y):
while y != 0:
(x, y) = (y, x % y)
return x
if __name__ == "__main__":
# parser = argparse.ArgumentParser()
# parser.add_argument('width', type=int, help='width of the screen')
# parser.add_argument('height', type=int, help='height of the screen')
# parser.add_argument('hz', type=int, help='refresh rate in Hz', nargs='?', default=60)
#
# py_args = parser.parse_args()
# width = py_args.width
# height = py_args.height
# hz = py_args.hz
#
# cvt_command_line = ["cvt", str(width), str(height), str(hz)]
# if 60 == hz:
# cvt_command_line.append("-r")
# mode_line = subprocess.check_output(cvt_command_line).decode("utf8").split("\n")[1]
# mode_line = [x for x in mode_line.split(" ") if x]
mode_line = sys.argv[1:]
print(mode_line)
width = int(mode_line[3])
height = int(mode_line[7])
height_2x = 2 * height
hz_float = float(mode_line[1].split("_")[1])
gcd = calculate_gcd(width, height)
aspect_ratio_num = int(width / gcd)
aspect_ratio_den = int(height / gcd)
pixel_clock = float(mode_line[2])
pixel_clock_1000 = int(pixel_clock * 1000)
pixel_clock_10000 = int(pixel_clock * 10000)
pixel_clock_100000 = int(pixel_clock * 100000)
pixel_clock_1000000 = int(pixel_clock * 1000000)
# no idea how to calculaet this
# 48500 was found by looking thru all values
pixel_clock_aml_str = "%02x" % round(pixel_clock_10000 / 48500)
h_total = int(mode_line[6])
h_blank = h_total - width
h_front = int(mode_line[4]) - width
h_sync = int(mode_line[5]) - (width + h_front)
h_back = h_total - (width + h_front + h_sync)
hsync_polarity = 0 if "-" == mode_line[11][0] else 1
v_total = int(mode_line[10])
v_blank = v_total - height
v_front = int(mode_line[8]) - height
v_sync = int(mode_line[9]) - (height + v_front)
v_back = v_total - (height + v_front + v_sync)
vsync_polarity = 0 if "-" == mode_line[12][0] else 1
v_freq = int(hz_float * 1000)
h_freq = int(hz_float * (v_total - 1))
hz = int(round(hz_float))
# 1
print("\n\n\n1) drivers/amlogic/clk/gxbb_hdmi_clk.c: (around line 125)\n")
print(" HPLL_FVCO_RATE({pixel_clock_10000}, 0x{pixel_clock_aml_str}, 0x1, 0, 0),".format(**locals()))
# 2
print("\n\n\n2) drivers/amlogic/clk/gxbb_hdmi_clk.c: (around line 150)\n")
print(" VID_CLK({pixel_clock_1000}, {pixel_clock_10000}, 0, 1, DIV_5, 1),".format(**locals()))
# 3
print("\n\n\n3) drivers/amlogic/clk/gxbb_hdmi_clk.c: (around line 460)\n")
print(""" case {pixel_clock_10000}:
writel(0x580002{pixel_clock_aml_str}, hiu_base + HHI_HDMI_PLL_CNTL);
writel(0x00000000, hiu_base + HHI_HDMI_PLL_CNTL2);
writel(0x0d5c5091, hiu_base + HHI_HDMI_PLL_CNTL3);
writel(0x801da72c, hiu_base + HHI_HDMI_PLL_CNTL4);
writel(0x71486980, hiu_base + HHI_HDMI_PLL_CNTL5);
writel(0x00000e55, hiu_base + HHI_HDMI_PLL_CNTL6);
set_pll(rate_tbl);
pr_info("hpll reg: 0x%x\\n",
readl(hiu_base + HHI_HDMI_PLL_CNTL));
hdmi_update_bits(HHI_HDMI_PLL_CNTL2, 0xffff, 0x4e00);
break;""".format(**locals()))
# 4
print("\n\n\n4) drivers/amlogic/clk/gxbb_hdmi_clk.c: (around line 790)\n")
print(" CTS_XXX_TBL({pixel_clock_1000}, {pixel_clock_1000}, 1, 1),".format(**locals()))
# 5
print("\n\n\n5) drivers/amlogic/clk/gxbb_hdmi_clk.c: (around line 830)\n")
print(" CTS_XXX_TBL({pixel_clock_1000}, {pixel_clock_1000}, 1, 1),".format(**locals()))
# 6
print("\n\n\n6) drivers/amlogic/display/vout/tv_vout.h: (around line 120)\n")
print(" {{TVMODE_{width}x{height}p{hz}hz, VMODE_{width}x{height}p{hz}hz}},".format(**locals()))
# 7
print("\n\n\n7) drivers/amlogic/display/vout/tv_vout.h: (around line 1080)\n")
print(""" {
.name = "%dx%dp%dhz",
.mode = TVMODE_%dx%dp%dhz,
.width = %d,
.height = %d,
.field_height = %d,
.aspect_ratio_num = %d,
.aspect_ratio_den = %d,
.sync_duration_num = %d,
.sync_duration_den = 1,
.video_clk = %d,
},""" % (width, height, hz, width, height, hz, width, height, height, aspect_ratio_num, aspect_ratio_den, hz, pixel_clock_1000000))
# 8
print("\n\n\n8) drivers/amlogic/display/vout/tvregs.h: (around line 440)\n")
print("""static const struct reg_s tvregs_vesa_{width}x{height}_enc[] = {{
{{MREG_END_MARKER, 0 }}
}};""".format(**locals()))
# 9
print("\n\n\n9) drivers/amlogic/hdmi/hdmi_common/hdmi_parameters.c: (around line 1193)\n")
print("""static struct hdmi_format_para fmt_para_vesa_{width}x{height}p{hz}_{aspect_ratio_num}x{aspect_ratio_den} = {{
.vic = HDMIV_{width}x{height}p{hz}hz,
.name = "{width}x{height}p{hz}hz",
.pixel_repetition_factor = 0,
.progress_mode = 1,
.scrambler_en = 0,
.tmds_clk_div40 = 0,
.tmds_clk = {pixel_clock_1000},
.timing = {{
.pixel_freq = {pixel_clock_1000}, // = (h_total * v_total) / 2
.h_freq = {h_freq},
.v_freq = {v_freq},
.vsync_polarity = {vsync_polarity},
.hsync_polarity = {hsync_polarity},
.h_active = {width},
.h_total = {h_total},
.h_blank = {h_blank},
.h_front = {h_front},
.h_sync = {h_sync},
.h_back = {h_back},
.v_active = {height},
.v_total = {v_total},
.v_blank = {v_blank},
.v_front = {v_front},
.v_sync = {v_sync},
.v_back = {v_back},
.v_sync_ln = 1,
}},
}};""".format(**locals()))
# 10
print("\n\n\n10) drivers/amlogic/hdmi/hdmi_common/hdmi_parameters.c: (around line 1193)\n")
print(""" &fmt_para_vesa_{width}x{height}p{hz}_{aspect_ratio_num}x{aspect_ratio_den},""".format(**locals()))
# 11
print("\n\n\n11) drivers/amlogic/hdmi/hdmi_tx_20/hdmi_tx_edid.c: (around line 1632)\n")
print(""" {{"{width}x{height}p{hz}hz", HDMIV_{width}x{height}p{hz}hz}},""".format(**locals()))
# 12
print("\n\n\n12) drivers/amlogic/hdmi/hdmi_tx_20/hdmi_tx_main.c: (around line 986)\n")
print(""" "{width}x{height}p{hz}hz",""".format(**locals()))
# 13
print("\n\n\n13) drivers/amlogic/hdmi/hdmi_tx_20/hdmi_tx_video.c: (around line 611)\n")
print(""" {{
.VIC = HDMIV_{width}x{height}p{hz}hz,
.color_prefer = COLOR_SPACE_RGB444,
.color_depth = hdmi_color_depth_24B,
.bar_info = B_BAR_VERT_HORIZ,
.repeat_time = NO_REPEAT,
.aspect_ratio = TV_ASPECT_RATIO_16_9,
.cc = CC_ITU709,
.ss = SS_SCAN_UNDER,
.sc = SC_SCALE_HORIZ_VERT,
}},""".format(**locals()))
P_ENCP_VIDEO_MAX_PXCNT = h_total - 1
P_ENCP_VIDEO_MAX_LNCNT = v_total - 1
P_ENCP_VIDEO_HAVON_END = int(mode_line[5]) - 1
# 14
print("\n\n\n14) drivers/amlogic/hdmi/hdmi_tx_20/hw/enc_cfg_hw.c: (around line 985)\n")
print("""static const struct reg_s tvregs_{width}x{height}p{hz}hz[] = {{
{{P_VENC_VDAC_SETTING, 0xff,}},
{{P_ENCP_VIDEO_EN, 0,}},
{{P_ENCI_VIDEO_EN, 0,}},
{{P_ENCP_VIDEO_MODE, 0x4040,}},
{{P_ENCP_VIDEO_MODE_ADV, 0x18,}},
{{P_ENCP_VIDEO_MAX_PXCNT, {P_ENCP_VIDEO_MAX_PXCNT},}},
{{P_ENCP_VIDEO_MAX_LNCNT, {P_ENCP_VIDEO_MAX_LNCNT},}},
{{P_ENCP_VIDEO_HAVON_BEGIN, {h_back},}},
{{P_ENCP_VIDEO_HAVON_END, {P_ENCP_VIDEO_HAVON_END},}},
{{P_ENCP_VIDEO_VAVON_BLINE, {v_back},}},
{{P_ENCP_VIDEO_VAVON_ELINE, 1473,}},
{{P_ENCP_VIDEO_HSO_BEGIN, 0,}},
{{P_ENCP_VIDEO_HSO_END, {h_sync},}},
{{P_ENCP_VIDEO_VSO_BEGIN, 0x1E,}},
{{P_ENCP_VIDEO_VSO_END, 0x32,}},
{{P_ENCP_VIDEO_VSO_BLINE, 0x0,}},
{{P_ENCP_VIDEO_VSO_ELINE, {v_sync},}},
{{P_ENCP_VIDEO_EN, 1,}},
{{P_ENCI_VIDEO_EN, 0,}},
{{MREG_END_MARKER, 0}},
}};""".format(**locals()))
# 15
print("\n\n\n15) drivers/amlogic/hdmi/hdmi_tx_20/hw/enc_cfg_hw.c: (around line 1032)\n")
print(""" {{HDMIV_{width}x{height}p{hz}hz, tvregs_{width}x{height}p{hz}hz}},""".format(**locals()))
# 16
print("\n\n\n16) drivers/amlogic/hdmi/hdmi_tx_20/hw/hdmi_tx_hw.c: (around line 360)\n")
print(""" {{HDMIV_{width}x{height}p{hz}hz, 24000, {pixel_clock_10000}, {pixel_clock_1000}, {pixel_clock_1000}, -1, {pixel_clock_1000}}},""".format(**locals()))
# 17
print("\n\n\n17) drivers/amlogic/hdmi/hdmi_tx_20/hw/hdmi_tx_hw.c: (around line 1570)\n")
print(""" case HDMIV_{width}x{height}p{hz}hz:
INTERLACE_MODE = 0;
PIXEL_REPEAT_VENC = 0;
PIXEL_REPEAT_HDMI = 0;
ACTIVE_PIXELS = {width};
ACTIVE_LINES = {height};
LINES_F0 = {v_total};
LINES_F1 = {v_total};
FRONT_PORCH = {h_front};
HSYNC_PIXELS = {h_sync};
BACK_PORCH = {h_back};
EOF_LINES = {v_front};
VSYNC_LINES = {v_sync};
SOF_LINES = {v_back};
TOTAL_FRAMES = 4;
break;""".format(**locals()))
# 18
print("\n\n\n18) include/linux/amlogic/hdmi_tx/hdmi_common.h: (around line 187)\n")
print(""" HDMIV_{width}x{height}p{hz}hz,""".format(**locals()))
# 19
print("\n\n\n19) include/linux/amlogic/vout/vinfo.h: (around line 77)\n")
print(""" VMODE_{width}x{height}p{hz}hz,""".format(**locals()))
# 20
print("\n\n\n20) include/linux/amlogic/vout/vinfo.h: (around line 145)\n")
print(""" TVMODE_{width}x{height}p{hz}hz,""".format(**locals()))
# 21
print("\n\n\n21) drivers/amlogic/display/logo/logo.c: (around line 77)\n")
print(""" {{"{width}x{height}p{hz}hz", TVMODE_{width}x{height}p{hz}hz}},""".format(**locals()))
# 22
print("\n\n\n22) drivers/amlogic/display/osd/osd_fb.c: (around line 417)\n")
print(""" case TVMODE_{width}x{height}p{hz}hz:
fb_def_var[index].xres = {width};
fb_def_var[index].yres = {height};
fb_def_var[index].xres_virtual = {width};
fb_def_var[index].yres_virtual = {height_2x};
fb_def_var[index].bits_per_pixel = 32;
break;""".format(**locals()))