remove redundant registers
[sitara-dss-files/am57xx-dss-files.git] / am57xx-avs-abb-decoder.py
1 #!/usr/bin/python
2 #
3 # Copyright (c) 2021, Texas Instruments Incorporated
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 #
10 # *  Redistributions of source code must retain the above copyright
11 #    notice, this list of conditions and the following disclaimer.
12 #
13 # *  Redistributions in binary form must reproduce the above copyright
14 #    notice, this list of conditions and the following disclaimer in the
15 #    documentation and/or other materials provided with the distribution.
16 #
17 # *  Neither the name of Texas Instruments Incorporated nor the names of
18 #    its contributors may be used to endorse or promote products derived
19 #    from this software without specific prior written permission.
20 #
21 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23 # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28 # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30 # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
31 # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #
34 from __future__ import print_function
35 import re
36 import sys
38 if len(sys.argv) != 2:
39     print()  # Empty line
40     print(sys.argv[0], "help:\n")
41     print("Please pass the rd1 file to this script, e.g.:")
42     print("", sys.argv[0], "am57xx-avs-abb_yyyy-mm-dd_hhmmss.rd1\n")
43     print("Output file will have same base name as input, "
44           "but csv file type.\n")
45     sys.exit(1)
47 # Inputs:
48 #   Data - 32-bit register value
49 #   Upper - Highest bit to keep
50 #   Lower - Lowest bit to keep
51 #   (bit 0 refers to LSB, bit 31 to MSB)
52 # Return: right aligned data
53 def bits32(data, upper, lower):
54     data = data >> lower # unsigned right-shift
55     upper = upper - lower
56     bitmask =  0xFFFFFFFF >> (31 - upper)
57     return (data & bitmask)
59 def get_data(reg_addr):
60     valid = 1
61     try:
62         reg_index = address_list.index(reg_addr)
63     except ValueError:
64         print("Error finding address", hex(reg_addr))
65         valid = 0
66         return (valid, 0)
67     return (valid, data_list[reg_index])
69 # Input: address of CTRL_CORE_STD_FUSE_OPP_VMIN_x register
70 # Returns decoded values for voltage, abb_en, and the ABB LDO voltage
71 def decode_fuse_opp_vmin_reg(reg_addr):
72     valid = 1
73     value = get_data(reg_addr)
74     if value[0]:
75         voltage = bits32(value[1], 11, 0)
76         abb_en = bits32(value[1], 25, 25)
77         vsetabb = bits32(value[1], 24, 20)
78         return (valid, voltage, abb_en, vsetabb)
79     else:
80         return (0, 0, 0, 0)
82 def decode_ldovbb_voltage_ctrl(reg_addr):
83     valid = 1
84     value = get_data(reg_addr)
85     if value[0]:
86         fbb_mux_ctrl = bits32(value[1], 10, 10)
87         fbb_vset_in = bits32(value[1], 9, 5)
88         fbb_vset_out = bits32(value[1], 4, 0)
89     else:
90         valid = 0
91         fbb_mux_ctrl = 0
92         fbb_vset_in = 0
93         fbb_vset_out = 0
94     return (valid, fbb_mux_ctrl, fbb_vset_in, fbb_vset_out)
96 try:
97     rd1 = open(sys.argv[1], "rt")
98 except IOError:
99     print("Error: input file", sys.argv[1], "not accessible.")
100     sys.exit(1)
102 try:
103     csv_filename = sys.argv[1]
104     csv_filename = csv_filename.replace(".rd1", ".csv")
105     csv = open(csv_filename, "w+")
106 except IOError:
107     print("Error creating file", csv_filename)
108     sys.exit(1)
110 # Throw away header row
111 header = rd1.readline()
113 # Read rd1 file into separate lists for address and data
114 address_list = [] # empty list to contain addresses
115 data_list = [] # empty list to contain data
116 for lines in rd1:
117     # Use regular expression to extract address and data from rd1
118     m = re.match(r'(0x[0-9a-fA-F]{8})\s+(0x[0-9a-fA-F]{8})', lines, 0)
119     if m:
120         alphanum1 = m.group(1)  # address (string)
121         alphanum2 = m.group(2)  # data (string)
122         address = int(alphanum1, 16)  # convert from string to number
123         register_value = int(alphanum2, 16)  # convert from string
124         address_list.append(address)
125         data_list.append(register_value)
127 csv_string = "%s,,,,0x%08x,\r\n"
129 # CTRL_WKUP_ID_CODE
130 value = get_data(0x4AE0C204)
131 if value[0]:
132     csv.write(csv_string % ("CTRL_WKUP_ID_CODE",value[1]))
133     if value[1] == 0x0BB5002F:
134         device_type = 574
136 # CTRL_WKUP_STD_FUSE_DIE_ID_0
137 value = get_data(0x4AE0C200)
138 if value[0]:
139     csv.write(csv_string % ("CTRL_WKUP_STD_FUSE_DIE_ID_0",value[1]))
141 # CTRL_WKUP_STD_FUSE_DIE_ID_1
142 value = get_data(0x4AE0C208)
143 if value[0]:
144     csv.write(csv_string % ("CTRL_WKUP_STD_FUSE_DIE_ID_1",value[1]))
146 # CTRL_WKUP_STD_FUSE_DIE_ID_2
147 value = get_data(0x4AE0C20C)
148 if value[0]:
149     csv.write(csv_string % ("CTRL_WKUP_STD_FUSE_DIE_ID_2",value[1]))
151 # CTRL_WKUP_STD_FUSE_DIE_ID_3
152 value = get_data(0x4AE0C210)
153 if value[0]:
154     csv.write(csv_string % ("CTRL_WKUP_STD_FUSE_DIE_ID_3",value[1]))
156 csv.write("\r\n")
158 # CSV files must use \r\n for all line endings
159 # Create header row
160 csv.write("Rail,OPP,Voltage,ABB,ABB_LDO\r\n")
161 csv_string = "%s,%s,%d mV,%d,0x%02x\r\n"
163 # CTRL_CORE_STD_FUSE_OPP_VMIN_IVA_2
164 decoded_params = decode_fuse_opp_vmin_reg(0x4A0025CC)
165 if decoded_params[0]: # print values if found, otherwise just skip
166     csv.write(csv_string % ("IVA","NOM",decoded_params[1],decoded_params[2],decoded_params[3]))
168 # CTRL_CORE_STD_FUSE_OPP_VMIN_IVA_3
169 decoded_params = decode_fuse_opp_vmin_reg(0x4A0025D0)
170 if decoded_params[0]: # print values if found, otherwise just skip
171     csv.write(csv_string % ("IVA","OD",decoded_params[1],decoded_params[2],decoded_params[3]))
173 # CTRL_CORE_STD_FUSE_OPP_VMIN_IVA_4
174 decoded_params = decode_fuse_opp_vmin_reg(0x4A0025D4)
175 if decoded_params[0]: # print values if found, otherwise just skip
176     csv.write(csv_string % ("IVA","HIGH",decoded_params[1],decoded_params[2],decoded_params[3]))
178 # CTRL_CORE_STD_FUSE_OPP_VMIN_IVA_5
179 if device_type == 574:
180     decoded_params = decode_fuse_opp_vmin_reg(0x4A0025C4)
181     if decoded_params[0]: # print values if found, otherwise just skip
182         csv.write(csv_string % ("IVA","PLUS",decoded_params[1],decoded_params[2],decoded_params[3]))
184 # CTRL_CORE_STD_FUSE_OPP_VMIN_DSPEVE_2
185 decoded_params = decode_fuse_opp_vmin_reg(0x4A0025E0)
186 if decoded_params[0]: # print values if found, otherwise just skip
187     csv.write(csv_string % ("DSP","NOM",decoded_params[1],decoded_params[2],decoded_params[3]))
189 # CTRL_CORE_STD_FUSE_OPP_VMIN_DSPEVE_3
190 decoded_params = decode_fuse_opp_vmin_reg(0x4A0025E4)
191 if decoded_params[0]: # print values if found, otherwise just skip
192     csv.write(csv_string % ("DSP","OD",decoded_params[1],decoded_params[2],decoded_params[3]))
194 # CTRL_CORE_STD_FUSE_OPP_VMIN_DSPEVE_4
195 decoded_params = decode_fuse_opp_vmin_reg(0x4A0025E8)
196 if decoded_params[0]: # print values if found, otherwise just skip
197     csv.write(csv_string % ("DSP","HIGH",decoded_params[1],decoded_params[2],decoded_params[3]))
199 # CTRL_CORE_STD_FUSE_OPP_VMIN_DSPEVE_5
200 if device_type == 574:
201     decoded_params = decode_fuse_opp_vmin_reg(0x4A0025D8)
202     if decoded_params[0]: # print values if found, otherwise just skip
203         csv.write(csv_string % ("DSP","PLUS",decoded_params[1],decoded_params[2],decoded_params[3]))
205 # CTRL_CORE_STD_FUSE_OPP_VMIN_CORE_2
206 decoded_params = decode_fuse_opp_vmin_reg(0x4A0025F4)
207 if decoded_params[0]: # print values if found, otherwise just skip
208     csv.write(csv_string % ("VDD","NOM",decoded_params[1],decoded_params[2],decoded_params[3]))
210 # CTRL_CORE_STD_FUSE_OPP_VMIN_GPU_2
211 decoded_params = decode_fuse_opp_vmin_reg(0x4A003B08)
212 if decoded_params[0]: # print values if found, otherwise just skip
213     csv.write(csv_string % ("GPU","NOM",decoded_params[1],decoded_params[2],decoded_params[3]))
215 # CTRL_CORE_STD_FUSE_OPP_VMIN_GPU_3
216 decoded_params = decode_fuse_opp_vmin_reg(0x4A003B0C)
217 if decoded_params[0]: # print values if found, otherwise just skip
218     csv.write(csv_string % ("GPU","OD",decoded_params[1],decoded_params[2],decoded_params[3]))
220 # CTRL_CORE_STD_FUSE_OPP_VMIN_GPU_4
221 decoded_params = decode_fuse_opp_vmin_reg(0x4A003B10)
222 if decoded_params[0]: # print values if found, otherwise just skip
223     csv.write(csv_string % ("GPU","HIGH",decoded_params[1],decoded_params[2],decoded_params[3]))
225 # CTRL_CORE_STD_FUSE_OPP_VMIN_GPU_5
226 if device_type == 574:
227     decoded_params = decode_fuse_opp_vmin_reg(0x4A003B14)
228     if decoded_params[0]: # print values if found, otherwise just skip
229         csv.write(csv_string % ("GPU","PLUS",decoded_params[1],decoded_params[2],decoded_params[3]))
231 # CTRL_CORE_STD_FUSE_OPP_VMIN_MPU_1
232 if device_type == 574:
233     decoded_params = decode_fuse_opp_vmin_reg(0x4A003B1C)
234     if decoded_params[0]: # print values if found, otherwise just skip
235         csv.write(csv_string % ("MPU","LOW",decoded_params[1],decoded_params[2],decoded_params[3]))
237 # CTRL_CORE_STD_FUSE_OPP_VMIN_MPU_2
238 decoded_params = decode_fuse_opp_vmin_reg(0x4A003B20)
239 if decoded_params[0]: # print values if found, otherwise just skip
240     csv.write(csv_string % ("MPU","NOM",decoded_params[1],decoded_params[2],decoded_params[3]))
242 # CTRL_CORE_STD_FUSE_OPP_VMIN_MPU_3
243 decoded_params = decode_fuse_opp_vmin_reg(0x4A003B24)
244 if decoded_params[0]: # print values if found, otherwise just skip
245     csv.write(csv_string % ("MPU","OD",decoded_params[1],decoded_params[2],decoded_params[3]))
247 # CTRL_CORE_STD_FUSE_OPP_VMIN_MPU_4
248 decoded_params = decode_fuse_opp_vmin_reg(0x4A003B28)
249 if decoded_params[0]: # print values if found, otherwise just skip
250     csv.write(csv_string % ("MPU","HIGH",decoded_params[1],decoded_params[2],decoded_params[3]))
252 # CTRL_CORE_STD_FUSE_OPP_VMIN_MPU_5
253 if device_type == 574:
254     decoded_params = decode_fuse_opp_vmin_reg(0x4A003B2C)
255     if decoded_params[0]: # print values if found, otherwise just skip
256         csv.write(csv_string % ("MPU","PLUS",decoded_params[1],decoded_params[2],decoded_params[3]))
258 csv.write("\r\n")
260 # CTRL_CORE_LDOVBB_IVA_VOLTAGE_CTRL
261 decoded_params = decode_ldovbb_voltage_ctrl(0x4A002470)
262 if decoded_params[0]: # print values if found, otherwise just skip
263     csv.write("CTRL_CORE_LDOVBB_IVA_VOLTAGE_CTRL,,,,,")
264     if decoded_params[1]:
265         csv.write("override used,,0x%02x\r\n" % decoded_params[3])
266     else:
267         csv.write("efuse used,,0x%02x\r\n" % decoded_params[2])
269 # CTRL_CORE_LDOVBB_DSPEVE_VOLTAGE_CTRL
270 decoded_params = decode_ldovbb_voltage_ctrl(0x4A00246C)
271 if decoded_params[0]: # print values if found, otherwise just skip
272     csv.write("CTRL_CORE_LDOVBB_DSPEVE_VOLTAGE_CTRL,,,,,")
273     if decoded_params[1]:
274         csv.write("override used,,0x%02x\r\n" % decoded_params[3])
275     else:
276         csv.write("efuse used,,0x%02x\r\n" % decoded_params[2])
278 # CTRL_WKUP_LDOVBB_GPU_VOLTAGE_CTRL
279 decoded_params = decode_ldovbb_voltage_ctrl(0x4AE0C154)
280 if decoded_params[0]: # print values if found, otherwise just skip
281     csv.write("CTRL_WKUP_LDOVBB_GPU_VOLTAGE_CTRL,,,,,")
282     if decoded_params[1]:
283         csv.write("override used,,0x%02x\r\n" % decoded_params[3])
284     else:
285         csv.write("efuse used,,0x%02x\r\n" % decoded_params[2])
287 # CTRL_WKUP_LDOVBB_MPU_VOLTAGE_CTRL
288 decoded_params = decode_ldovbb_voltage_ctrl(0x4AE0C158)
289 if decoded_params[0]: # print values if found, otherwise just skip
290     csv.write("CTRL_WKUP_LDOVBB_MPU_VOLTAGE_CTRL,,,,,")
291     if decoded_params[1]:
292         csv.write("override used,,0x%02x\r\n" % decoded_params[3])
293     else:
294         csv.write("efuse used,,0x%02x\r\n" % decoded_params[2])
296 rd1.close()
297 csv.close()