1 #!/usr/bin/python
2 # Python script to automatically generate the IO pad and delay data
3 # Author:- Nikhil Devshatwar
5 # This script uses regdump of the pad registers to figure out the muxmodes
6 # Based on the pad and muxmode, it find out all possible virtual/manual modes
7 # by referring to the PCT XML model. Using the, selection file, script
8 # decides which modes to be selected. Finally it dumps the required array entries
10 # This script depends on following files:-
11 # * XML data files - Shipped with the DRA7xx PCT tool
12 # * Pad register dump - Generate using omapconf dump 0x4a003400 0x4a00380c
13 # * selection file - List of selected virtual/manual modes to be used
15 import xml.etree.ElementTree as ET
16 import re
17 import argparse
19 # Handle the command line arguments
20 parser = argparse.ArgumentParser(prog='iodelay-autogen.py',
21 description='Python script to generate the IOdelay data.\n' \
22 'This script refers to the XML data and automatically generates\n' \
23 'PAD and DELAY data for the same use case.\n' \
24 'Note that only the PADs which are used in the dump are configured.',
25 epilog='Generate the pad and delay data using pad register dumps. For this,\n' \
26 'Run omapconf dump 0x4a003400 0x4a00380c and save the output')
28 parser.add_argument('-d', '--debug', dest='debug',
29 action='store', type=int, choices=[0, 1, 2], default=0,
30 help='set the debug level')
32 parser.add_argument('-i', '--interactive', dest='interactive',
33 action='store', type=int, choices=[0, 1], default=1,
34 help='run interactively with menus for resolving conflicts')
36 parser.add_argument('-f', '--format', dest='format',
37 action='store', type=str, choices=["linux", "uboot", "bios"], default="uboot",
38 help='select the output format to be used')
40 parser.add_argument('-r', '--revision', dest='revision',
41 action='store', type=str, choices=["1.0", "1.1", "2.0"], default="1.1",
42 help='select the silicon revision')
44 parser.add_argument('-p', '--part', dest='part',
45 action='store', type=str, choices=["dra74x", "dra75x", "dra72x"], default="dra74x",
46 help='select the device part')
48 parser.add_argument('-m', '--module', dest='module',
49 action='store', type=str, default="",
50 help='generate only for modules matching the provided RE')
52 parser.add_argument('-s', '--strict', dest='strict',
53 action='store_true',
54 help='strict mode - ask for each pad of the group, do not save selection.\n' \
55 'For some peripherals, same delaymode cannot be used for all the pads.\n' \
56 'Use this mode to select different modes for each pad')
58 parser.add_argument('-g', '--gpio', dest='gpio',
59 action='store_true',
60 help='generate script to read pad data from GPIO')
62 parser.add_argument('-c', '--check', dest='check_xml',
63 action='store_true',
64 help='check consistency of the XML files and other data')
66 args = parser.parse_args()
68 # Some more knobs for developers, Don't want to expose them to cmd line
69 args.resetslew = True
71 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
73 VERSION = "2.4"
75 if (args.part == "dra74x" or args.part == "dra75x"):
76 XML_PATH = "XMLFiles/DRA75x_DRA74x"
77 PART = "DRA75x_DRA74x"
78 PCT_VERSION = "v1.0.10"
79 elif (args.part == "dra72x"):
80 XML_PATH = "XMLFiles/DRA72x"
81 PART = "DRA72x"
82 PCT_VERSION = "v1.0.7"
84 pad_data_xml = XML_PATH + "/CTRL_MODULE_CORE.xml"
85 iod_data_xml = XML_PATH + "/IODELAYCONFIG.xml"
86 model_data_xml = XML_PATH + "/model_" + PART + "_SR" + args.revision + "_" + PCT_VERSION + ".xml"
87 modehelp_file = XML_PATH + "/guidelines_SR" + args.revision + ".txt"
89 pad_file = "ctrl-core.dump"
90 sel_file = "selected-modes.txt"
92 print "iodelay-autogen.py - Python script to generate the IOdelay data."
93 print "v" + VERSION + " using PCT version " + PCT_VERSION
94 print "Parsing PCT data from " + model_data_xml + "..."
95 print ""
97 # Read the XML file database for pad and delay registers
98 pad_xml = ET.parse(pad_data_xml).getroot()
99 iod_xml = ET.parse(iod_data_xml).getroot()
100 model_xml = ET.parse(model_data_xml).getroot()
102 # Functions to parse the input files and build data structures
103 def read_guidelines(fname):
104 modehelp = {}
105 pattern = re.compile('([^\t.]+\w)\t+(.+)')
106 f = open(fname)
107 for line in f.readlines():
108 list = re.match(pattern, line)
109 if ( list == None):
110 continue
111 mode = list.groups(0)[0]
112 info = list.groups(0)[1]
113 modehelp[mode] = info
114 if (args.debug >= 2):
115 print "Help: Mode '%s' is used for '%s'" % (mode, info)
116 return modehelp
118 def read_selmodes(fname):
119 sel = {}
120 pattern = re.compile('(\w+)\W*,\W*(\w*)')
121 f = open(fname)
122 for line in f.readlines():
123 list = re.match(pattern, line)
124 if ( list == None):
125 continue
126 module = list.groups(0)[0]
127 mode = list.groups(0)[1]
128 sel[module] = mode
129 if (args.debug >= 2):
130 print "INFO: Select '%s' for '%s'" % (mode, module)
131 return sel
133 def read_pad_dump(file):
134 regmap = {}
135 pattern = re.compile('.*(0x[0-9A-F]+).*(0x[0-9A-F]+).*')
136 f = open(file, 'r')
137 for line in f:
138 list = re.match(pattern, line)
139 if ( list == None):
140 continue
141 addr = int(list.groups(0)[0], 16)
142 val = int(list.groups(0)[1], 16)
143 #print "PADXML: Addr = %08x Value = %08x" % (addr, val)
144 regmap[addr] = val
145 return regmap
146 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
148 # Helper functions to parse XML nodes and get the desired data
149 # Hugely dependent on the XML format of the PCT files
150 # Uses XPath to search elements with queries and filters
151 # Parse the nodes to generate data in desired format
153 def xml_pad_get_name(offset):
154 padlist = pad_xml.findall("register[@offset='0x%X']" % offset)
155 if (len(padlist) == 0):
156 return "Unknown"
157 else:
158 return padlist[0].get("id")
160 def xml_pad_get_slew(offset):
161 padlist = pad_xml.findall("register[@offset='0x%X']" % offset)
162 if (len(padlist) == 0):
163 return 0x0
164 else:
165 bitlist = padlist[0].findall("bitfield[@begin='19']")
166 if (len(bitlist) == 0):
167 return 0x0
168 else:
169 return int(bitlist[0].get("resetval"), 16)
171 # For DRA72x SoC, for "ball compatibility" purpose, some signals have same muxmode.
172 # CTRL_CORE_ALT_SELECT_MUX register allows to select between one of the signals
173 # Its like a board mux has been added inside the SoC, except it uses same muxmode.
174 def resolve_group(muxmode_str):
175 mmlist = muxmode_str.split(" ")
176 mmlen = len(mmlist)
177 if (mmlen == 1):
178 def_mode = mmlist[0]
179 return mmlist[0]
180 elif (mmlen == 2):
181 def_mode = mmlist[0]
182 grp1_mode = mmlist[1]
183 elif (mmlen == 3):
184 def_mode = mmlist[0]
185 grp1_mode = mmlist[1]
186 grp2_mode = mmlist[2]
187 else:
188 print "ERR: Cannot resolve muxmode group for '%s'" % muxmode_str
190 #HACK for now
191 return def_mode
193 def xml_model_get_signal(offset, muxmode):
194 padlist = pad_xml.findall("register[@offset='0x%X']" % offset)
195 if (len(padlist) == 0):
196 return "Unknown"
197 else:
198 mux_field = padlist[0].findall("./bitfield[@end='0']")
199 if (len(mux_field) == 0):
200 return "Unknown"
201 modes = mux_field[0].findall("./bitenum[@value='%d']" % muxmode)
202 if (len(modes) == 0):
203 return "Unknown"
204 return resolve_group(modes[0].get("id"))
206 def xml_iodelay_get_reg(name):
207 delaylist = iod_xml.findall("register[@id='%s']" % name)
208 if (len(delaylist) == 0):
209 return 0
210 else:
211 offset = delaylist[0].get("offset")
212 #print "IOD: Name = %s Offset = %s" % (del_reg, offset)
213 return int(offset, 16)
215 def xml_get_virtual(mode):
216 vmodes = {}
217 signal = mode.findtext("signal")
218 for virt in mode.findall("virtualmode/mode"):
219 virt_mode = virt.findtext("value")
220 virt_name = virt.findtext("name")
221 if (virt_name == "NA"):
222 continue
223 virt_mode = int(virt_mode)
224 vmodes[virt_name] = virt_mode
225 if (args.debug >= 1):
226 print (" * VIRTUAL: %s [%s] => delaymode = %d" % (signal, virt_name, virt_mode))
227 return vmodes
229 def xml_get_manual(mode):
230 mmodes = {}
231 signal = mode.findtext("signal")
232 for man in mode.findall("manualmode"):
233 regname = man.findtext("cfgreg/name")
234 for sel in man.findall("cfgreg/mode"):
235 adel = sel.findtext("adelay")
236 gdel = sel.findtext("gdelay")
237 man_name = sel.findtext("name")
238 if (man_name == "NA"):
239 continue
240 adel = int(adel)
241 gdel = int(gdel)
242 if (man_name not in mmodes.keys()):
243 mmodes[man_name] = []
244 mmodes[man_name].append((regname, adel, gdel))
245 if (args.debug >= 1):
246 print (" * MANUAL: %s [%s] => delay[%s] = %d, %d" % (signal, man_name, regname, adel, gdel))
247 return mmodes
249 def xml_find_delaymodes(pad_name, muxmode):
250 padlist = model_xml.findall("padDB/clockNode/type/pad")
251 for pad in padlist:
252 if (pad_name == pad.findtext("confregisters/regbit/register")):
253 muxmodes = pad.findall("muxmode")
254 break
255 if not muxmodes:
256 return None
257 for mode in muxmodes:
258 if ("%d" % muxmode == mode.findtext("mode")):
259 virt = xml_get_virtual(mode)
260 man = xml_get_manual(mode)
261 return (virt, man)
262 return None
264 def xml_check_correctness(modehelp):
265 if(args.check_xml == False):
266 return
268 print "###########################################"
269 print "XML correctness checks:"
270 padcore_list = []
271 padmodel_list = []
272 modes = {}
274 # Find all the pads in core XML
275 pad_list = pad_xml.findall("register")
276 for i in pad_list:
277 name = i.get("id")
278 if (re.match("CTRL_CORE_PAD_.*", name) == None):
279 continue
280 padcore_list.append(name)
281 print ">> Total pads defined in core XML = %d" % len(padcore_list)
283 # Find all the pads in model XML
284 pad_list = model_xml.findall("padDB/clockNode/type/pad/confregisters/regbit")
285 for i in pad_list:
286 name = i.findtext("register")
287 padmodel_list.append(name)
288 print ">> Total pads defined in model XML = %d" % len(padmodel_list)
290 # Find all the manual modes
291 manmode_list = model_xml.findall("padDB/clockNode/type/pad/muxmode/manualmode/cfgreg/mode")
292 for i in manmode_list:
293 man_name = i.findtext("name")
294 modes[man_name] = "manual"
295 # Find all the virtual modes
296 virtmode_list = model_xml.findall("padDB/clockNode/type/pad/muxmode/virtualmode/mode")
297 for i in virtmode_list:
298 virt_name = i.findtext("name")
299 modes[virt_name] = "virtual"
300 print ">> Total delaymodes defined in model XML = %d" % len(modes)
302 # Print out all the errors found in the tests
303 print "== Pads defined in core XML but not in model XML =="
304 for i in padcore_list:
305 if (i not in padmodel_list):
306 print "\t%s" % i
307 print "== Pads defined in model XML but not in core XML =="
308 for i in padmodel_list:
309 if (i not in padcore_list):
310 print "\t%s" % i
312 # Check if description for each mode is available
313 print "== Delaymodes missing description in the guidelines.txt =="
314 for i in modes:
315 if (i not in modehelp):
316 print "\t%s" % i
318 # Check if description for unknown mode is documented
319 print "== Delaymodes unused from guidelines.txt =="
320 for i in modehelp:
321 if (i not in modes):
322 print "\t%s" % i
324 print "###########################################"
326 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
328 # Decision point of the script
329 # For each pad/pin, decide what delay method is used
330 # Lookup in the selection file or ask user with a menu
331 def select_mode(pad, pin, module, virt, man, modehelp, sel):
332 modelist = []
333 for modename in virt.keys():
334 modelist.append(modename)
336 for modename in man.keys():
337 modelist.append(modename)
339 if (len(modelist) == 0):
340 return "LEGACY"
342 if (module in sel.keys()):
343 mode = sel[module]
344 if (mode == "SKIP" or mode == "LEGACY" or mode in modelist):
345 return mode
346 else:
347 print("ERR: Invalid delaymode '%s' for module '%s'" % (mode, module))
349 if (args.interactive == 0):
350 print "WARN: No delay modes for %s found, skipping" % module
351 mode = "SKIP"
352 return mode
354 # Display the menu and ask user to select the 'right' mode
355 while True:
356 print ""
357 print "MENU: Select delay mode for %s -> %s" % (pad, pin)
358 i = 0
359 print "MENU: %d: %s \t\t\t%s" % (i, "SKIP", "Skips this module for now")
360 i = 1
361 print "MENU: %d: %s \t\t%s" % (i, "LEGACY", "No external delay config (No virtual/manual needed)")
362 for mode in modelist:
363 i += 1
364 if (mode in modehelp):
365 helptext = modehelp[mode]
366 else:
367 helptext = "Unknown"
368 print "MENU: %d: %s \t\t%s" % (i, mode, helptext)
369 try:
370 choice = int(raw_input("Select delay mode #> "))
371 if (choice == 0):
372 mode = "SKIP"
373 break
374 elif (choice == 1):
375 mode = "LEGACY"
376 break
377 elif (choice >=2 and choice <= len(modelist) + 1):
378 mode = modelist[choice - 2]
379 break
380 print "ERROR: Invalid choice"
381 except ValueError:
382 print "ERROR: Invalid choice"
383 print "MENU: Selected mode is %s" % mode
384 print ""
386 return mode
387 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
389 # Pad read using GPIO - Specific to linux only
390 # As each pad is muxed with a SoC gpio (for most of the pads)
391 # It's possible to read the pad data using gpio datain registers
392 # Dump the linux commands to read the gpio registers and read the pad data
393 def pad_dump_gpio(padconf, per_padconf):
394 print "###########################################"
395 print "# Read %s signals using GPIO DATA-IN registers" % args.module
396 print "# Works only for the input signals"
397 print "###########################################"
398 gpio_data_addrs = (0, 0x4ae10138, 0x48055138, 0x48057138, 0x48059138, 0x4805b138, 0x4805d138, 0x48051138, 0x48053138)
399 for i in padconf:
400 (pad_name, pin_name, addr, val, mode, delayinfo) = i
402 offset = addr - 0x4a002000
403 gpio_name = xml_model_get_signal(offset, 14)
404 matchlist = re.match("GPIO(.)_(.*)", gpio_name)
405 if (matchlist == None):
406 print "ERR: No GPIO for pad %s" % pad_name
407 continue
409 inst = int(matchlist.groups(0)[0])
410 bit = int(matchlist.groups(0)[1])
411 gpio_addr = gpio_data_addrs[inst]
413 print "#Read GPIO%d_%d to sample %s" % (inst, bit, pin_name)
414 print " echo %d > /sys/class/gpio/export 2>/dev/null;" % ((inst - 1) * 32)
415 print " val=`omapconf read 0x%x 2>&1 | grep -v \"support\"`;" % gpio_addr
416 print " status=$((0x$val >> %d & 0x1));" % bit
417 print " echo -e \"%s (%s)\t = $status\";" % (pin_name, gpio_name)
418 print ""
419 print ""
420 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
422 # Generate the final pad and delay data in the required format
423 def format_pad_regs(padconf, per_padconf):
424 print "###########################################"
425 print "Pad data output (with the delay modes)"
426 print "###########################################"
427 if (args.format == "uboot"):
428 uboot_format_pad_regs(padconf, per_padconf)
429 elif (args.format == "linux"):
430 linux_format_pad_regs(padconf, per_padconf)
431 elif (args.format == "bios"):
432 bios_format_pad_regs(padconf, per_padconf)
433 else:
434 print "ERR: Format %s not suppported" % args.format
436 def format_delay_regs(delayconf, per_delayconf):
437 print "#########################################"
438 print "Delay data output (for manual modes)"
439 print "#########################################"
440 if (args.format == "uboot"):
441 uboot_format_delay_regs(delayconf, per_delayconf)
442 elif (args.format == "linux"):
443 linux_format_delay_regs(delayconf, per_delayconf)
444 elif (args.format == "bios"):
445 bios_format_delay_regs(delayconf, per_delayconf)
446 else:
447 print "ERR: Format %s not suppported" % args.format
449 def get_pin_info(val):
450 slew_fast = (val >> 19) & 0x1
451 inp_en = (val >> 18) & 0x1
452 pulltype = (val >> 17) & 0x1
453 pull_dis = (val >> 16) & 0x1
454 pin = "PIN"
455 if (inp_en):
456 pin += "_INPUT"
457 else:
458 pin += "_OUTPUT"
459 if (pull_dis == 0):
460 if (pulltype):
461 pin += "_PULLUP"
462 else:
463 pin += "_PULLDOWN"
464 if (slew_fast):
465 pin += " | SLEWCONTROL"
466 return pin
468 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
470 # Generate output in u-boot format
471 def uboot_format_pad_regs(padconf, per_padconf):
472 print "\nconst struct pad_conf_entry dra74x_core_padconf_array[] = {"
473 for i in padconf:
474 (pad_name, pin_name, addr, val, mode, delayinfo) = i
476 muxmode = val & 0xf
477 (method, data) = delayinfo
478 if (method == "LEGACY"):
479 extramode = ""
480 elif (method == "VIRTUAL"):
481 delaymode = data
482 extramode = " | VIRTUAL_MODE%d" % delaymode
483 elif (method == "MANUAL"):
484 extramode = " | MANUAL_MODE"
485 else:
486 print "ERR: Invalid method %s" % method
488 pin_info = get_pin_info(val) + extramode
489 pad_short = re.sub("CTRL_CORE_PAD_", "", pad_name)
490 comment = (pad_short + "." + pin_name).lower()
492 print "\t{ %s, (M%d | %s) },\t/* %s */" % (pad_short, muxmode, pin_info, comment)
493 print "};\n"
495 def uboot_format_delay_regs(delayconf, per_delayconf):
496 manual_del = []
497 for i in delayconf:
498 (pad_name, pin_name, regname, del_offset, man_name, adel, gdel) = i
500 entry = (del_offset, adel, gdel, regname, pin_name, man_name)
501 manual_del.append(entry)
503 es_rev = args.revision.replace('.', '_')
504 print "\nconst struct iodelay_cfg_entry dra742_es" + es_rev + "_iodelay_cfg_array[] = {"
505 for entry in sorted(manual_del):
506 print "\t{ 0x%04X, %5d, %5d },\t/* %s : %s - %s */" % entry
507 print "};\n"
509 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
511 # Generate output in linux format
512 def linux_format_pad_regs(padconf, per_padconf):
513 print "&dra7_pmx_core {"
514 for per in per_padconf:
516 if (re.match("MMC.*", per) == None):
517 print "WARN: Only MMC padconf is recommended in kernel"
519 # Get the mode from the first entry
520 (pad_name, pin_name, addr, val, mode, delayinfo) = per_padconf[per][0]
522 dtsnode = ("%s_pins_%s" % (per, mode)).lower()
523 print ""
524 print "\t%s: %s {" % (dtsnode, dtsnode)
525 print "\t\tpinctrl-single,pins = <"
526 for i in per_padconf[per]:
527 (pad_name, pin_name, addr, val, mode, delayinfo) = i
529 muxmode = val & 0xf
530 (method, data) = delayinfo
531 if (method == "LEGACY"):
532 extramode = ""
533 elif (method == "VIRTUAL"):
534 delaymode = data
535 extramode = " | MUX_VIRTUAL_MODE%d" % delaymode
536 elif (method == "MANUAL"):
537 extramode = " | MANUAL_MODE"
538 else:
539 print "ERR: Invalid method %s" % method
541 pin_info = get_pin_info(val) + extramode
542 pad_short = re.sub("CTRL_CORE_PAD_", "", pad_name)
543 offset = addr - 0x4a003400
544 comment = (pad_short + "." + pin_name).lower()
546 print "\t\t\t0x%03X\t(%s | MUX_MODE%d)\t/* %s */" % (offset, pin_info, muxmode, comment)
547 print "\t\t>;"
548 print "\t};"
549 print "};\n"
552 def linux_format_delay_regs(delayconf, per_delayconf):
553 print "&dra7_iodelay_core {"
554 for per in per_delayconf.keys():
556 if (re.match("MMC.*", per) == None):
557 print "WARN: Only MMC delayconf is recommended in kernel"
559 # Get the mode from the first entry
560 (pad_name, pin_name, regname, del_offset, mode, adel, gdel) = per_delayconf[per][0]
562 dtsnode = ("%s_iodelay_%s_conf" % (per, mode)).lower()
563 print "\t%s: %s {" % (dtsnode, dtsnode)
564 print "\t\tpinctrl-single,pins = <"
565 for i in per_delayconf[per]:
566 (pad_name, pin_name, regname, del_offset, mode, adel, gdel) = i
568 print "\t\t\t0x%03X (A_DELAY(%d) | G_DELAY(%d))\t/* %s */" % (del_offset, adel, gdel, regname)
569 print "\t\t>;"
570 print "\t};"
571 print "};\n"
573 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
575 # Generate output in bios format
576 def bios_format_pad_regs(padconf, per_padconf):
577 for i in padconf:
578 (pad_name, pin_name, addr, val, mode, delayinfo) = i
580 delaylist = []
581 (method, data) = delayinfo
582 if (method == "VIRTUAL"):
583 virt_mode = data
584 val = val | ( virt_mode<< 4)
585 val = val | (1 << 8)
586 elif (method == "MANUAL"):
587 delaylist = data
588 val = val | (1 << 8)
590 offset = addr - 0x4a003400
591 out_delreg = out_adel = out_gdel = 0
592 in_delreg = in_adel = in_gdel = 0
593 oen_delreg = oen_adel = oen_gdel = 0
595 for j in delaylist:
596 (regname, adel, gdel) = j
597 if (re.match(".*_IN", regname) != None):
598 in_delreg = xml_iodelay_get_reg(regname)
599 in_adel = adel
600 in_gdel = gdel
601 elif (re.match(".*_OEN", regname) != None):
602 oen_delreg = xml_iodelay_get_reg(regname)
603 oen_adel = adel
604 oen_gdel = gdel
605 elif (re.match(".*_OUT", regname) != None):
606 out_delreg = xml_iodelay_get_reg(regname)
607 out_adel = adel
608 out_gdel = gdel
609 indel = "{ 0x%04X, %4d, %4d }" % (in_delreg, in_adel, in_gdel)
610 oendel = "{ 0x%04X, %4d, %4d }" % (oen_delreg, oen_adel, oen_gdel)
611 outdel = "{ 0x%04X, %4d, %4d }" % (out_delreg, out_adel, out_gdel)
612 pin_info = get_pin_info(val)
613 print "\t/* %s -> %s (%s) %s delaymode */" % (pad_name, pin_name, pin_info, method)
614 print "\t{ 0x%03X, 0x%08X, %s, %s, %s }" % (offset, val, indel, oendel, outdel)
616 def bios_format_delay_regs(delayconf, per_delayconf):
617 print "Manual delays are not configured separately"
618 print "Delays are configured as part of the padconf step only"
620 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
622 # Main execution starts here
623 # * Parse all the XML files - Get the pad data and IOdelay data
624 # * Iterate over the pad register dumps
625 # * For each pad, find out the muxmode being used and the pad direction, etc
626 # * For the muxmode being used, find out available virtual/modes
627 # - Dump the virtual/manual modes available (based on options)
628 # - Build up the gpio script to read the pad data using GPIO module
629 # * Select the correct mode to be used
630 # - Check if the mode is described for the peripheral module, (from selected-modes.txt)
631 # - Otherwise ask the user (with a menu) to decide the delaymode
632 # => Update the selection for the whole of the peripheral module
633 # - Worst case, skip the delaymode for this pad
634 # * Build the pad and delay register information
635 # * Create the dump for pad and delay data in linux/u-boot format
636 # * Dump the delaymode selection for each peripheral
637 # * Dump the GPIO script for each peripheral (all pads grouped together)
638 #
640 # Read all the input files and parse the required info
641 modehelp = read_guidelines(modehelp_file)
642 sel = read_selmodes(sel_file)
643 regmap = read_pad_dump(pad_file)
644 reglist = regmap.keys()
646 # List of all the pads being configured
647 padconf = []
648 # List of all the delay registers being configured (for manual mode)
649 delayconf = []
650 # Dictionary of pads grouped by peripheral/module
651 per_padconf = {}
652 # Dictionary of delay registers grouped by peripheral/module
653 per_delayconf = {}
655 xml_check_correctness(modehelp)
657 # Start iterating over each pad
658 for i in range(0, 260):
659 # Find out the muxmode and pad direction, etc
660 addr = 0x4a003400 + i * 4
661 offset = 0x1400 + i * 4
662 dts_offset = offset - 0x1400
664 if (addr not in reglist):
665 print "WARN: Register dump for pad 0x%X not found" % addr
666 continue
667 val = regmap[addr]
668 muxmode = val & 0xf
670 # Find out the pin based on the muxmode
671 pad_name = xml_pad_get_name(offset)
672 pin_name = xml_model_get_signal(offset, muxmode)
673 if (pad_name == "Unknown" or pin_name == "Unknown"):
674 print "WARN: Cannot find out Pad/Pin name for PAD address 0x%X (%s[%s] = %s)" \
675 % (addr, pad_name, muxmode, pin_name)
676 continue
677 if (pin_name == "DRIVER"):
678 continue
680 # Find out if the delaymode for this module is already selected
681 module = re.match("([^_]+)_.*", pin_name).groups(0)[0]
683 if (args.module != "" and re.match("%s" % args.module, module) == None):
684 continue
686 # It is recommended to keep the reset value of the slewcontrol bit
687 # Find out the reset value from XML and update if required
688 if (args.resetslew):
689 val |= (xml_pad_get_slew(offset) & 0x1) << 19
691 if (args.debug >= 1):
692 print "\nPAD: %s: Addr= 0x%08X Value = 0x%08X \"%s\"" \
693 % (pad_name, addr, val, pin_name)
695 # Find out all the possible virtual, manual modes fot the specific pad -> pin combination
696 (virt, man) = xml_find_delaymodes(pad_name, muxmode)
698 if (args.gpio == True):
699 mode = "LEGACY"
700 else:
701 # Need to select one out of allowed modes
702 mode = select_mode(pad_name, pin_name, module, virt, man, modehelp, sel)
704 # Remember the selection for that module, for later reuse
705 if (args.strict == False and module not in sel.keys()):
706 sel[module] = mode
708 if (mode == "SKIP"):
709 continue
710 elif (mode == "LEGACY"):
711 delayinfo = ("LEGACY", "")
712 elif (mode in virt):
713 delayinfo = ("VIRTUAL", virt[mode])
714 elif (mode in man):
715 delayinfo = ("MANUAL", man[mode])
716 else:
717 print "ERR: Unknown mode '%s' selected" % mode
718 continue
720 if (args.debug >= 1):
721 print " => Using mode %s" % mode
722 paddata = (pad_name, pin_name, addr, val, mode, delayinfo)
723 if (module not in per_padconf.keys()):
724 per_padconf[module] = []
725 padconf.append(paddata)
726 per_padconf[module].append(paddata)
728 if(mode not in man):
729 continue
731 # Add the delay data if using manual mode
732 for regval in man[mode]:
733 (regname, adel, gdel) = regval
734 del_offset = xml_iodelay_get_reg(regname)
735 if (del_offset == 0):
736 print "WARN: Can't find delay offset of register %s" % regname
737 break
738 if (args.debug >= 1):
739 print " => Manual delay[%s] = (%d, %d)" % (regname, adel, gdel)
740 delaydata = (pad_name, pin_name, regname, del_offset, mode, adel, gdel)
741 if (module not in per_delayconf.keys()):
742 per_delayconf[module] = []
743 delayconf.append(delaydata)
744 per_delayconf[module].append(delaydata)
746 print ""
747 print "Total PAD registers: %d" % len(padconf)
748 print "Total DELAY registers: %d" % len(delayconf)
749 print ""
751 if(args.gpio == True):
752 pad_dump_gpio(padconf, per_padconf)
753 exit()
755 format_pad_regs(padconf, per_padconf)
756 format_delay_regs(delayconf, per_delayconf)
758 # Dump the final selection for reuse
759 print "Selected modes for each peripheral module\n"
760 for group in sel:
761 print "%s,\t%s" % (group, sel[group])
762 print ""
763 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #