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('-p', '--part', dest='part',
29 action='store', type=str, choices=["dra74x", "dra75x", "dra72x"], default="dra74x",
30 help='select the device part')
32 parser.add_argument('-r', '--revision', dest='revision',
33 action='store', type=str, choices=["1.0", "1.1", "2.0"], default="1.1",
34 help='select the silicon revision')
36 parser.add_argument('-m', '--module', dest='module',
37 action='store', type=str, default="",
38 help='generate only for modules matching the provided RE')
40 parser.add_argument('-f', '--format', dest='format',
41 action='store', type=str, choices=["linux", "uboot", "bios"], default="uboot",
42 help='select the output format to be used')
44 parser.add_argument('-d', '--debug', dest='debug',
45 action='store', type=int, choices=[0, 1, 2, 3, 4], default=0,
46 help='set the debug level - ERR,WARN,INFO,DBG,VERBOSE')
48 parser.add_argument('-i', '--interactive', dest='interactive',
49 action='store', type=int, choices=[0, 1], default=1,
50 help='run interactively with menus for resolving conflicts')
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 probe signals using 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.7"
75 if (args.part == "dra74x" or args.part == "dra75x"):
76 if (args.revision == "1.0" or args.revision == "1.1"):
77 args.revision = "1.x"
78 XML_PATH = "XMLFiles/DRA75x_DRA74x"
79 PART = "DRA75x_DRA74x"
80 PCT_VERSION = "v1.0.16"
81 elif (args.part == "dra72x"):
82 if (args.revision == "1.1"):
83 print "dra72x doesn't have silicon revision 1.1"
84 exit()
85 XML_PATH = "XMLFiles/DRA72x"
86 PART = "DRA72x"
87 PCT_VERSION = "v1.0.9"
89 pad_data_xml = XML_PATH + "/CTRL_MODULE_CORE.xml"
90 iod_data_xml = XML_PATH + "/IODELAYCONFIG.xml"
91 model_data_xml = XML_PATH + "/model_" + PART + "_SR" + args.revision + "_" + PCT_VERSION + ".xml"
92 modehelp_file = XML_PATH + "/guidelines_SR" + args.revision + ".txt"
94 pad_file = "ctrl-core.dump"
95 sel_file = "selected-modes.txt"
97 def trace(level, msg):
98 if (args.debug >= level):
99 print(msg)
100 def verbose(msg):
101 trace(4, "DEBUG: " + msg)
102 def debug(msg, args=None):
103 trace(3, "DEBUG: " + msg)
104 def info(msg):
105 trace(2, "INFO: " + msg)
106 def warn(msg):
107 trace(1, "WARN: " + msg)
108 def error(msg):
109 trace(0, "ERR: " + msg)
111 if (args.interactive):
112 print "iodelay-autogen.py - Python script to generate the IOdelay data."
113 print "v" + VERSION + " using PCT version " + PCT_VERSION
114 print "Parsing PCT data from " + model_data_xml + "..."
115 print ""
117 # Read the XML file database for pad and delay registers
118 pad_xml = ET.parse(pad_data_xml).getroot()
119 iod_xml = ET.parse(iod_data_xml).getroot()
120 model_xml = ET.parse(model_data_xml).getroot()
122 # Functions to parse the input files and build data structures
123 def read_guidelines(fname):
124 modehelp = {}
125 pattern = re.compile('([^\t.]+\w)\t+(.+)')
126 f = open(fname)
127 for line in f.readlines():
128 list = re.match(pattern, line)
129 if ( list == None):
130 continue
131 mode = list.groups(0)[0]
132 info = list.groups(0)[1]
133 modehelp[mode] = info
134 verbose("Guideline: Mode '%30s' => '%s'" % (mode, info))
135 return modehelp
137 def read_selmodes(fname):
138 sel = {}
139 pattern = re.compile('(\w+)\W*,\W*(\w*)')
140 f = open(fname)
141 for line in f.readlines():
142 list = re.match(pattern, line)
143 if ( list == None):
144 continue
145 module = list.groups(0)[0]
146 mode = list.groups(0)[1]
147 sel[module] = mode
148 verbose("Input modes: Select '%s' => '%s'" % (mode, module))
149 return sel
151 def read_pad_dump(file):
152 regmap = {}
153 pattern = re.compile('.*(0x[0-9A-F]+).*(0x[0-9A-F]+).*')
154 f = open(file, 'r')
155 for line in f:
156 list = re.match(pattern, line)
157 if ( list == None):
158 continue
159 addr = int(list.groups(0)[0], 16)
160 val = int(list.groups(0)[1], 16)
161 verbose("XML pad-reg: Addr = %08x Value = %08x" % (addr, val))
162 regmap[addr] = val
163 return regmap
164 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
166 # Helper functions to parse XML nodes and get the desired data
167 # Hugely dependent on the XML format of the PCT files
168 # Uses XPath to search elements with queries and filters
169 # Parse the nodes to generate data in desired format
171 def xml_pad_get_name(offset):
172 padlist = pad_xml.findall("register[@offset='0x%X']" % offset)
173 if (len(padlist) == 0):
174 return "Unknown"
175 else:
176 return padlist[0].get("id")
178 def xml_pad_get_slew(offset):
179 padlist = pad_xml.findall("register[@offset='0x%X']" % offset)
180 if (len(padlist) == 0):
181 return 0x0
182 else:
183 bitlist = padlist[0].findall("bitfield[@begin='19']")
184 if (len(bitlist) == 0):
185 return 0x0
186 else:
187 return int(bitlist[0].get("resetval"), 16)
189 # For DRA72x SoC, for "ball compatibility" purpose, some signals have same muxmode.
190 # CTRL_CORE_ALT_SELECT_MUX register allows to select between one of the signals
191 # Its like a board mux has been added inside the SoC, except it uses same muxmode.
192 def resolve_group(muxmode_str):
193 mmlist = muxmode_str.split(" ")
194 mmlen = len(mmlist)
195 if (mmlen == 1):
196 def_mode = mmlist[0]
197 return mmlist[0]
198 elif (mmlen == 2):
199 def_mode = mmlist[0]
200 grp1_mode = mmlist[1]
201 elif (mmlen == 3):
202 def_mode = mmlist[0]
203 grp1_mode = mmlist[1]
204 grp2_mode = mmlist[2]
205 else:
206 error("Cannot resolve muxmode group for '%s'" % muxmode_str)
208 #HACK for now
209 warn("Not resolving muxmode %s, assuming default %s" % (muxmode_str, def_mode))
210 return def_mode
212 def xml_model_get_signal(offset, muxmode):
213 padlist = pad_xml.findall("register[@offset='0x%X']" % offset)
214 if (len(padlist) == 0):
215 return "Unknown"
216 else:
217 mux_field = padlist[0].findall("./bitfield[@end='0']")
218 if (len(mux_field) == 0):
219 return "Unknown"
220 modes = mux_field[0].findall("./bitenum[@value='%d']" % muxmode)
221 if (len(modes) == 0):
222 return "Unknown"
223 return resolve_group(modes[0].get("id"))
225 def xml_iodelay_get_reg(name):
226 delaylist = iod_xml.findall("register[@id='%s']" % name)
227 if (len(delaylist) == 0):
228 return 0
229 else:
230 offset = delaylist[0].get("offset")
231 verbose("XML delay-reg: Name = %s Offset = %s" % (name, offset))
232 return int(offset, 16)
234 def xml_get_virtual(mode):
235 vmodes = {}
236 signal = mode.findtext("signal")
237 for virt in mode.findall("virtualmode/mode"):
238 virt_mode = virt.findtext("value")
239 virt_name = virt.findtext("name")
240 if (virt_name == "NA"):
241 continue
242 virt_mode = int(virt_mode)
243 vmodes[virt_name] = virt_mode
244 debug(" * VIRTUAL: %s [%s] => delaymode = %d" % (signal, virt_name, virt_mode))
245 return vmodes
247 def xml_get_manual(mode):
248 mmodes = {}
249 signal = mode.findtext("signal")
250 for man in mode.findall("manualmode"):
251 regname = man.findtext("cfgreg/name")
252 for sel in man.findall("cfgreg/mode"):
253 adel = sel.findtext("adelay")
254 gdel = sel.findtext("gdelay")
255 man_name = sel.findtext("name")
256 if (man_name == "NA"):
257 continue
258 adel = int(adel)
259 gdel = int(gdel)
260 if (man_name not in mmodes.keys()):
261 mmodes[man_name] = []
262 mmodes[man_name].append((regname, adel, gdel))
263 debug(" * MANUAL: %s [%s] => delay[%s] = %d, %d" % (signal, man_name, regname, adel, gdel))
264 return mmodes
266 def xml_find_delaymodes(pad_name, muxmode):
267 padlist = model_xml.findall("padDB/clockNode/type/pad")
268 for pad in padlist:
269 if (pad_name == pad.findtext("confregisters/regbit/register")):
270 muxmodes = pad.findall("muxmode")
271 break
272 if not muxmodes:
273 return None
274 for mode in muxmodes:
275 if ("%d" % muxmode == mode.findtext("mode")):
276 virt = xml_get_virtual(mode)
277 man = xml_get_manual(mode)
278 return (virt, man)
279 return None
281 def xml_check_correctness(modehelp):
283 print "###########################################"
284 print "XML correctness checks:"
285 padcore_list = []
286 padmodel_list = []
287 modes = {}
289 # Find all the pads in core XML
290 pad_list = pad_xml.findall("register")
291 for i in pad_list:
292 name = i.get("id")
293 if (re.match("CTRL_CORE_PAD_.*", name) == None):
294 continue
295 padcore_list.append(name)
296 print ">> Total pads defined in core XML = %d" % len(padcore_list)
298 # Find all the pads in model XML
299 pad_list = model_xml.findall("padDB/clockNode/type/pad/confregisters/regbit")
300 for i in pad_list:
301 name = i.findtext("register")
302 padmodel_list.append(name)
303 print ">> Total pads defined in model XML = %d" % len(padmodel_list)
305 # Find all the manual modes
306 manmode_list = model_xml.findall("padDB/clockNode/type/pad/muxmode/manualmode/cfgreg/mode")
307 for i in manmode_list:
308 man_name = i.findtext("name")
309 modes[man_name] = "manual"
310 # Find all the virtual modes
311 virtmode_list = model_xml.findall("padDB/clockNode/type/pad/muxmode/virtualmode/mode")
312 for i in virtmode_list:
313 virt_name = i.findtext("name")
314 modes[virt_name] = "virtual"
315 print ">> Total delaymodes defined in model XML = %d" % len(modes)
317 # Print out all the errors found in the tests
318 print "== Pads defined in core XML but not in model XML =="
319 for i in padcore_list:
320 if (i not in padmodel_list):
321 print "\t%s" % i
322 print "== Pads defined in model XML but not in core XML =="
323 for i in padmodel_list:
324 if (i not in padcore_list):
325 print "\t%s" % i
327 # Check if description for each mode is available
328 print "== Delaymodes missing description in the guidelines.txt =="
329 for i in modes:
330 if (i not in modehelp):
331 print "\t%s" % i
333 # Check if description for unknown mode is documented
334 print "== Delaymodes unused from guidelines.txt =="
335 for i in modehelp:
336 if (i not in modes):
337 print "\t%s" % i
339 print "###########################################"
341 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
343 # Decision point of the script
344 # For each pad/pin, decide what delay method is used
345 # Lookup in the selection file or ask user with a menu
346 def select_mode(pad, pin, module, virt, man, modehelp, sel):
347 modelist = []
348 for modename in virt.keys():
349 modelist.append(modename)
351 for modename in man.keys():
352 modelist.append(modename)
354 if (len(modelist) == 0):
355 return "LEGACY"
357 if (module in sel.keys()):
358 mode = sel[module]
359 if (mode == "SKIP" or mode == "LEGACY" or mode in modelist):
360 return mode
361 else:
362 error("Invalid delaymode '%s' for module '%s'" % (mode, module))
364 if (args.interactive == 0):
365 warn("No delay modes for %s found, skipping" % module)
366 mode = "SKIP"
367 return mode
369 # Display the menu and ask user to select the 'right' mode
370 while True:
371 print ""
372 print "MENU: Select delay mode for %s -> %s" % (pad, pin)
373 i = 0
374 print "MENU: %d: %s \t\t\t%s" % (i, "SKIP", "Skips this module for now")
375 i = 1
376 print "MENU: %d: %s \t\t%s" % (i, "LEGACY", "No external delay config (No virtual/manual needed)")
377 for mode in modelist:
378 i += 1
379 if (mode in modehelp):
380 helptext = modehelp[mode]
381 else:
382 helptext = "Unknown"
383 print "MENU: %d: %s \t\t%s" % (i, mode, helptext)
384 try:
385 choice = int(raw_input("Select delay mode #> "))
386 if (choice == 0):
387 mode = "SKIP"
388 break
389 elif (choice == 1):
390 mode = "LEGACY"
391 break
392 elif (choice >=2 and choice <= len(modelist) + 1):
393 mode = modelist[choice - 2]
394 break
395 print "ERROR: Invalid choice"
396 except ValueError:
397 print "ERROR: Invalid choice"
398 print "MENU: Selected mode is %s" % mode
399 print ""
401 return mode
402 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
404 # Pad read using GPIO - Specific to linux only
405 # As each pad is muxed with a SoC gpio (for most of the pads)
406 # It's possible to read the pad data using gpio datain registers
407 # Change pad register to enable input path and export sysfs
408 # Use sysfs to read the status of GPIO and print in a loop
409 def pad_dump_gpio(padconf, per_padconf):
410 gpio_data_addrs = (0, 0x4ae10138, 0x48055138, 0x48057138, 0x48059138, 0x4805b138, 0x4805d138, 0x48051138, 0x48053138)
411 module = args.module
413 # script header
414 gen_header = "###########################################\n" + \
415 "# Read %s signals using GPIO sysfs\n" % module + \
416 "###########################################\n\n"
417 gen_data = "%s_data=(\n" % module
419 for i in padconf:
420 (pad_name, pin_name, addr, val, mode, delayinfo) = i
422 offset = addr - 0x4a002000
423 gpio_name = xml_model_get_signal(offset, 14)
424 matchlist = re.match("GPIO(.)_(.*)", gpio_name)
425 if (matchlist == None):
426 error("No GPIO for pad %s - cannot read from script" % pad_name)
427 continue
429 inst = int(matchlist.groups(0)[0])
430 bit = int(matchlist.groups(0)[1])
431 gpio_addr = gpio_data_addrs[inst]
432 ngpio = (inst - 1) * 32 + bit
433 pin_short = re.match(".+_(.*)", pin_name).groups(0)[0]
435 gen_data += "\t%s:0x%x:%s:%d:0x%x:%d\n" % (pin_short, addr, gpio_name, ngpio, gpio_addr, bit)
437 gen_data += ")\n\n"
439 # Main script to probe the signal
440 gen_main = "echo; echo Probing %s signals\n\n" % module + \
441 "for data in ${%s_data[@]}\n" % module + \
442 "do\n" + \
443 " pin=`echo $data | cut -d ':' -f1`\n" + \
444 " pad=`echo $data | cut -d ':' -f2`\n" + \
445 " ngpio=`echo $data | cut -d ':' -f4`\n" + \
446 " echo $ngpio > /sys/class/gpio/export 2>/dev/null\n" + \
447 " omapconf set bit $pad 18 1>/dev/null 2>/dev/null\n" + \
448 " printf \"%8s\" $pin\n" + \
449 "done\n" + \
450 "echo\n\n"
452 gen_main += "while true;\n" + \
453 "do\n" + \
454 " for data in ${%s_data[@]}\n" % module + \
455 " do\n" + \
456 "# pin=`echo $data | cut -d ':' -f1`\n" + \
457 "# pad=`echo $data | cut -d ':' -f2`\n" + \
458 "# gpio=`echo $data | cut -d ':' -f3`\n" + \
459 " ngpio=`echo $data | cut -d ':' -f4`\n" + \
460 "# addr=`echo $data | cut -d ':' -f5`\n" + \
461 "# bit=`echo $data | cut -d ':' -f6`\n" + \
462 " val=`cat /sys/class/gpio/gpio$ngpio/value`\n" + \
463 " printf %8d $val \n" + \
464 " done\n" + \
465 " echo\n" + \
466 "done\n\n"
468 gen_footer = "###########################################\n"
470 # Generate the shell script
471 gen_script = gen_header + gen_data + gen_main + gen_footer
472 filename = ("./%s-probe.sh" % module).lower()
473 print "Generating '%s' script..." % filename
474 gen_file = open(filename, "w+")
475 gen_file.write(gen_script)
477 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
479 # Generate the final pad and delay data in the required format
480 def format_pad_regs(padconf, per_padconf):
481 print "######## Pad data output ########"
482 if (args.format == "uboot"):
483 uboot_format_pad_regs(padconf, per_padconf)
484 elif (args.format == "linux"):
485 linux_format_pad_regs(padconf, per_padconf)
486 elif (args.format == "bios"):
487 bios_format_pad_regs(padconf, per_padconf)
488 else:
489 error("Format %s not suppported" % args.format)
491 def format_delay_regs(delayconf, per_delayconf):
492 print "######## Delay data output ########"
493 if (args.format == "uboot"):
494 uboot_format_delay_regs(delayconf, per_delayconf)
495 elif (args.format == "linux"):
496 linux_format_delay_regs(delayconf, per_delayconf)
497 elif (args.format == "bios"):
498 bios_format_delay_regs(delayconf, per_delayconf)
499 else:
500 error("Format %s not suppported" % args.format)
502 def get_pin_info(val):
503 slew_fast = (val >> 19) & 0x1
504 inp_en = (val >> 18) & 0x1
505 pulltype = (val >> 17) & 0x1
506 pull_dis = (val >> 16) & 0x1
507 pin = "PIN"
508 if (inp_en):
509 pin += "_INPUT"
510 else:
511 pin += "_OUTPUT"
512 if (pull_dis == 0):
513 if (pulltype):
514 pin += "_PULLUP"
515 else:
516 pin += "_PULLDOWN"
517 if (slew_fast):
518 pin += " | SLEWCONTROL"
519 return pin
521 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
523 # Generate output in u-boot format
524 def uboot_format_pad_regs(padconf, per_padconf):
525 print "\nconst struct pad_conf_entry dra74x_core_padconf_array[] = {"
526 for i in padconf:
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 = " | VIRTUAL_MODE%d" % delaymode
536 elif (method == "MANUAL"):
537 extramode = " | MANUAL_MODE"
538 else:
539 error("Invalid delay method %s" % method)
541 pin_info = get_pin_info(val) + extramode
542 pad_short = re.sub("CTRL_CORE_PAD_", "", pad_name)
543 comment = (pad_short + "." + pin_name).lower()
545 print "\t{ %s, (M%d | %s) },\t/* %s */" % (pad_short, muxmode, pin_info, comment)
546 print "};\n"
548 def uboot_format_delay_regs(delayconf, per_delayconf):
549 manual_del = []
550 for i in delayconf:
551 (pad_name, pin_name, regname, del_offset, man_name, adel, gdel) = i
553 entry = (del_offset, adel, gdel, regname, pin_name, man_name)
554 manual_del.append(entry)
556 es_rev = args.revision.replace('.', '_')
557 print "\nconst struct iodelay_cfg_entry dra742_es" + es_rev + "_iodelay_cfg_array[] = {"
558 for entry in sorted(manual_del):
559 print "\t{ 0x%04X, %5d, %5d },\t/* %s : %s - %s */" % entry
560 print "};\n"
562 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
564 # Generate output in linux format
565 def linux_format_pad_regs(padconf, per_padconf):
566 print "&dra7_pmx_core {"
567 for per in per_padconf:
569 if (re.match("MMC.*", per) == None):
570 warn("Only MMC padconf is recommended in kernel")
572 # Get the mode from the first entry
573 (pad_name, pin_name, addr, val, mode, delayinfo) = per_padconf[per][0]
575 dtsnode = ("%s_pins_%s" % (per, mode)).lower()
576 print ""
577 print "\t%s: %s {" % (dtsnode, dtsnode)
578 print "\t\tpinctrl-single,pins = <"
579 for i in per_padconf[per]:
580 (pad_name, pin_name, addr, val, mode, delayinfo) = i
582 muxmode = val & 0xf
583 (method, data) = delayinfo
584 if (method == "LEGACY"):
585 extramode = ""
586 elif (method == "VIRTUAL"):
587 delaymode = data
588 extramode = " | MUX_VIRTUAL_MODE%d" % delaymode
589 elif (method == "MANUAL"):
590 extramode = " | MANUAL_MODE"
591 else:
592 warn("Invalid method %s" % method)
594 pin_info = get_pin_info(val) + extramode
595 pad_short = re.sub("CTRL_CORE_PAD_", "", pad_name)
596 offset = addr - 0x4a003400
597 comment = (pad_short + "." + pin_name).lower()
599 print "\t\t\t0x%03X\t(%s | MUX_MODE%d)\t/* %s */" % (offset, pin_info, muxmode, comment)
600 print "\t\t>;"
601 print "\t};"
602 print "};\n"
605 def linux_format_delay_regs(delayconf, per_delayconf):
606 print "&dra7_iodelay_core {"
607 for per in per_delayconf.keys():
609 if (re.match("MMC.*", per) == None):
610 warn("Only MMC delayconf is recommended in kernel")
612 # Get the mode from the first entry
613 (pad_name, pin_name, regname, del_offset, mode, adel, gdel) = per_delayconf[per][0]
615 dtsnode = ("%s_iodelay_%s_conf" % (per, mode)).lower()
616 print "\t%s: %s {" % (dtsnode, dtsnode)
617 print "\t\tpinctrl-single,pins = <"
618 for i in per_delayconf[per]:
619 (pad_name, pin_name, regname, del_offset, mode, adel, gdel) = i
621 print "\t\t\t0x%03X (A_DELAY(%d) | G_DELAY(%d))\t/* %s */" % (del_offset, adel, gdel, regname)
622 print "\t\t>;"
623 print "\t};"
624 print "};\n"
626 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
628 # Generate output in bios format
629 def bios_format_pad_regs(padconf, per_padconf):
630 for i in padconf:
631 (pad_name, pin_name, addr, val, mode, delayinfo) = i
633 delaylist = []
634 (method, data) = delayinfo
635 if (method == "VIRTUAL"):
636 virt_mode = data
637 val = val | ( virt_mode<< 4)
638 val = val | (1 << 8)
639 elif (method == "MANUAL"):
640 delaylist = data
641 val = val | (1 << 8)
643 offset = addr - 0x4a003400
644 out_delreg = out_adel = out_gdel = 0
645 in_delreg = in_adel = in_gdel = 0
646 oen_delreg = oen_adel = oen_gdel = 0
648 for j in delaylist:
649 (regname, adel, gdel) = j
650 if (re.match(".*_IN", regname) != None):
651 in_delreg = xml_iodelay_get_reg(regname)
652 in_adel = adel
653 in_gdel = gdel
654 elif (re.match(".*_OEN", regname) != None):
655 oen_delreg = xml_iodelay_get_reg(regname)
656 oen_adel = adel
657 oen_gdel = gdel
658 elif (re.match(".*_OUT", regname) != None):
659 out_delreg = xml_iodelay_get_reg(regname)
660 out_adel = adel
661 out_gdel = gdel
662 indel = "{ 0x%04X, %4d, %4d , 0}" % (in_delreg, in_adel, in_gdel)
663 oendel = "{ 0x%04X, %4d, %4d , 0}" % (oen_delreg, oen_adel, oen_gdel)
664 outdel = "{ 0x%04X, %4d, %4d , 0}" % (out_delreg, out_adel, out_gdel)
665 pin_info = get_pin_info(val)
666 print "\t/* %s -> %s (%s) %s delaymode */" % (pad_name, pin_name, pin_info, method)
667 print "\t{ 0x%03X, 0x%08X, %s, %s, %s }" % (offset, val, indel, oendel, outdel)
669 def bios_format_delay_regs(delayconf, per_delayconf):
670 debug("Manual delays are not configured separately")
671 debug("Delays are configured as part of the padconf step only")
673 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
675 # Main execution starts here
676 # * Parse all the XML files - Get the pad data and IOdelay data
677 # * Iterate over the pad register dumps
678 # * For each pad, find out the muxmode being used and the pad direction, etc
679 # * For the muxmode being used, find out available virtual/modes
680 # - Dump the virtual/manual modes available (based on options)
681 # - Build up the gpio script to read the pad data using GPIO module
682 # * Select the correct mode to be used
683 # - Check if the mode is described for the peripheral module, (from selected-modes.txt)
684 # - Otherwise ask the user (with a menu) to decide the delaymode
685 # => Update the selection for the whole of the peripheral module
686 # - Worst case, skip the delaymode for this pad
687 # * Build the pad and delay register information
688 # * Create the dump for pad and delay data in linux/u-boot format
689 # * Dump the delaymode selection for each peripheral
690 # * Dump the GPIO script for each peripheral (all pads grouped together)
691 #
693 # Read all the input files and parse the required info
694 modehelp = read_guidelines(modehelp_file)
695 sel = read_selmodes(sel_file)
696 regmap = read_pad_dump(pad_file)
697 reglist = regmap.keys()
699 # List of all the pads being configured
700 padconf = []
701 # List of all the delay registers being configured (for manual mode)
702 delayconf = []
703 # Dictionary of pads grouped by peripheral/module
704 per_padconf = {}
705 # Dictionary of delay registers grouped by peripheral/module
706 per_delayconf = {}
708 if(args.check_xml):
709 xml_check_correctness(modehelp)
710 exit()
712 # Start iterating over each pad
713 for i in range(0, 260):
714 # Find out the muxmode and pad direction, etc
715 addr = 0x4a003400 + i * 4
716 offset = 0x1400 + i * 4
717 dts_offset = offset - 0x1400
719 if (addr not in reglist):
720 warn("Register dump for pad 0x%X not found" % addr)
721 continue
722 val = regmap[addr]
723 muxmode = val & 0xf
725 # Find out the pin based on the muxmode
726 pad_name = xml_pad_get_name(offset)
727 pin_name = xml_model_get_signal(offset, muxmode)
728 if (pad_name == "Unknown" or pin_name == "Unknown"):
729 warn("Cannot find out Pad/Pin name for PAD address 0x%X (%s[%s] = %s)" \
730 % (addr, pad_name, muxmode, pin_name))
731 continue
732 if (pin_name == "DRIVER"):
733 continue
735 # Find out if the delaymode for this module is already selected
736 match = re.match("([^_]+)_.*", pin_name)
737 if (match):
738 module = match.groups(0)[0]
739 else:
740 module = pin_name
742 if (args.module != "" and re.match("%s" % args.module, module) == None):
743 continue
745 # It is recommended to keep the reset value of the slewcontrol bit
746 # Find out the reset value from XML and update if required
747 if (args.resetslew):
748 val |= (xml_pad_get_slew(offset) & 0x1) << 19
750 debug("\nPAD: %s: Addr= 0x%08X Value = 0x%08X \"%s\"" \
751 % (pad_name, addr, val, pin_name))
753 # Find out all the possible virtual, manual modes fot the specific pad -> pin combination
754 (virt, man) = xml_find_delaymodes(pad_name, muxmode)
756 if (args.gpio == True):
757 mode = "LEGACY"
758 else:
759 # Need to select one out of allowed modes
760 mode = select_mode(pad_name, pin_name, module, virt, man, modehelp, sel)
762 # Remember the selection for that module, for later reuse
763 if (args.strict == False and module not in sel.keys()):
764 sel[module] = mode
766 if (mode == "SKIP"):
767 continue
768 elif (mode == "LEGACY"):
769 delayinfo = ("LEGACY", "")
770 elif (mode in virt):
771 delayinfo = ("VIRTUAL", virt[mode])
772 elif (mode in man):
773 delayinfo = ("MANUAL", man[mode])
774 else:
775 error("Unknown mode '%s' selected" % mode)
776 continue
778 debug(" => Using mode %s" % mode)
779 paddata = (pad_name, pin_name, addr, val, mode, delayinfo)
780 if (module not in per_padconf.keys()):
781 per_padconf[module] = []
782 padconf.append(paddata)
783 per_padconf[module].append(paddata)
785 if(mode not in man):
786 continue
788 # Add the delay data if using manual mode
789 for regval in man[mode]:
790 (regname, adel, gdel) = regval
791 del_offset = xml_iodelay_get_reg(regname)
792 if (del_offset == 0):
793 error("Can't find delay offset of register %s" % regname)
794 break
795 debug(" => Manual delay[%s] = (%d, %d)" % (regname, adel, gdel))
796 delaydata = (pad_name, pin_name, regname, del_offset, mode, adel, gdel)
797 if (module not in per_delayconf.keys()):
798 per_delayconf[module] = []
799 delayconf.append(delaydata)
800 per_delayconf[module].append(delaydata)
802 if(args.gpio == True):
803 pad_dump_gpio(padconf, per_padconf)
804 exit()
806 format_pad_regs(padconf, per_padconf)
807 format_delay_regs(delayconf, per_delayconf)
809 if (args.interactive):
810 # Summary of the generated data
811 print ""
812 print "Total PAD registers: %d" % len(padconf)
813 print "Total DELAY registers: %d" % len(delayconf)
814 print ""
815 # Dump the final selection for reuse
816 print "Selected modes for each peripheral module\n"
817 for group in sel:
818 print "%s,\t%s" % (group, sel[group])
819 print ""
820 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #