57d6286dd383c58eba71a4862a53f71558d40d18
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="2.0",
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)
110 def fatal(msg):
111 trace(0, "FATAL: " + msg)
112 exit()
114 if (args.interactive):
115 print "iodelay-autogen.py - Python script to generate the IOdelay data."
116 print "v" + VERSION + " using PCT version " + PCT_VERSION
117 print "Parsing PCT data from " + model_data_xml + "..."
118 print ""
120 # Read the XML file database for pad and delay registers
121 pad_xml = ET.parse(pad_data_xml).getroot()
122 iod_xml = ET.parse(iod_data_xml).getroot()
123 model_xml = ET.parse(model_data_xml).getroot()
125 # Functions to parse the input files and build data structures
126 def read_guidelines(fname):
127 modehelp = {}
128 pattern = re.compile('([^\t.]+\w)\t+(.+)')
129 f = open(fname)
130 for line in f.readlines():
131 list = re.match(pattern, line)
132 if ( list == None):
133 continue
134 mode = list.groups(0)[0]
135 info = list.groups(0)[1]
136 modehelp[mode] = info
137 verbose("Guideline: Mode '%30s' => '%s'" % (mode, info))
138 return modehelp
140 def read_selmodes(fname):
141 sel = {}
142 pattern = re.compile('(\w+)\W*,\W*(\w*)')
143 f = open(fname)
144 for line in f.readlines():
145 list = re.match(pattern, line)
146 if ( list == None):
147 continue
148 module = list.groups(0)[0]
149 mode = list.groups(0)[1]
150 sel[module] = mode
151 verbose("Input modes: Select '%s' => '%s'" % (mode, module))
152 return sel
154 def read_pad_dump(file):
155 regmap = {}
156 pattern = re.compile('.*(0x[0-9A-Fa-f]+).*(0x[0-9A-Fa-f]+).*')
157 f = open(file, 'r')
158 for line in f:
159 list = re.match(pattern, line)
160 if ( list == None):
161 continue
162 addr = int(list.groups(0)[0], 16)
163 val = int(list.groups(0)[1], 16)
164 verbose("XML pad-reg: Addr = %08x Value = %08x" % (addr, val))
165 regmap[addr] = val
166 return regmap
168 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
169 # Read all the input files and parse the required info
170 modehelp = read_guidelines(modehelp_file)
171 sel = read_selmodes(sel_file)
172 regmap = read_pad_dump(pad_file)
173 reglist = regmap.keys()
175 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
177 # Helper functions to parse XML nodes and get the desired data
178 # Hugely dependent on the XML format of the PCT files
179 # Uses XPath to search elements with queries and filters
180 # Parse the nodes to generate data in desired format
182 def xml_pad_get_name(offset):
183 padlist = pad_xml.findall("register[@offset='0x%X']" % offset)
184 if (len(padlist) == 0):
185 return "Unknown"
186 else:
187 return padlist[0].get("id")
189 def xml_pad_get_offset(name):
190 padlist = pad_xml.findall("register[@id='%s']" % name)
191 if (len(padlist) == 0):
192 return None
193 else:
194 return int(padlist[0].get("offset"), 16)
196 def xml_pad_get_slew(offset):
197 padlist = pad_xml.findall("register[@offset='0x%X']" % offset)
198 if (len(padlist) == 0):
199 return 0x0
200 else:
201 bitlist = padlist[0].findall("bitfield[@begin='19']")
202 if (len(bitlist) == 0):
203 return 0x0
204 else:
205 return int(bitlist[0].get("resetval"), 16)
207 # For DRA72x SoC, for "ball compatibility" purpose, some signals have same muxmode.
208 # CTRL_CORE_ALT_SELECT_MUX register allows to select between one of the signals
209 # Its like a board mux has been added inside the SoC, except it uses same muxmode.
210 def resolve_group(muxmode_str):
211 mmlist = muxmode_str.split(" ")
212 mmlen = len(mmlist)
213 if (mmlen == 1):
214 def_mode = mmlist[0]
215 return mmlist[0]
216 elif (mmlen == 2):
217 def_mode = mmlist[0]
218 grp1_mode = mmlist[1]
219 elif (mmlen == 3):
220 def_mode = mmlist[0]
221 grp1_mode = mmlist[1]
222 grp2_mode = mmlist[2]
223 else:
224 error("Cannot resolve muxmode group for '%s'" % muxmode_str)
226 #HACK for now
227 warn("Not resolving muxmode %s, assuming default %s" % (muxmode_str, def_mode))
228 return def_mode
230 def xml_model_get_signal(offset, muxmode):
231 padlist = pad_xml.findall("register[@offset='0x%X']" % offset)
232 if (len(padlist) == 0):
233 return "Unknown"
234 else:
235 mux_field = padlist[0].findall("./bitfield[@end='0']")
236 if (len(mux_field) == 0):
237 return "Unknown"
238 modes = mux_field[0].findall("./bitenum[@value='%d']" % muxmode)
239 if (len(modes) == 0):
240 return "Unknown"
241 return resolve_group(modes[0].get("id"))
243 def xml_iodelay_get_reg(name):
244 delaylist = iod_xml.findall("register[@id='%s']" % name)
245 if (len(delaylist) == 0):
246 return 0
247 else:
248 offset = delaylist[0].get("offset")
249 verbose("XML delay-reg: Name = %s Offset = %s" % (name, offset))
250 return int(offset, 16)
252 def xml_get_virtual(mode):
253 vmodes = {}
254 signal = mode.findtext("signal")
255 for virt in mode.findall("virtualmode/mode"):
256 virt_mode = virt.findtext("value")
257 virt_name = virt.findtext("name")
258 if (virt_name == "NA"):
259 continue
260 virt_mode = int(virt_mode)
261 vmodes[virt_name] = virt_mode
262 debug(" * VIRTUAL: %s [%s] => delaymode = %d" % (signal, virt_name, virt_mode))
263 return vmodes
265 def xml_get_manual(mode):
266 mmodes = {}
267 signal = mode.findtext("signal")
268 for man in mode.findall("manualmode"):
269 regname = man.findtext("cfgreg/name")
270 for sel in man.findall("cfgreg/mode"):
271 adel = sel.findtext("adelay")
272 gdel = sel.findtext("gdelay")
273 man_name = sel.findtext("name")
274 if (man_name == "NA"):
275 continue
276 adel = int(adel)
277 gdel = int(gdel)
278 if (man_name not in mmodes.keys()):
279 mmodes[man_name] = []
280 mmodes[man_name].append((regname, adel, gdel))
281 debug(" * MANUAL: %s [%s] => delay[%s] = %d, %d" % (signal, man_name, regname, adel, gdel))
282 return mmodes
284 def xml_get_additional_mode(orig):
285 additional_mux = orig.findall("additionalMux/confregisters")
286 if (len(additional_mux) == 0):
287 return orig
288 else:
289 additional_mux = additional_mux[0]
290 mux_reg_name = additional_mux.findtext("register")
291 offset = xml_pad_get_offset(mux_reg_name)
293 if (offset == None):
294 error("Could not find register address for register '%s'" % mux_reg_name)
295 fatal("This pin may have virtual/manual modes, Fix XML file")
297 addr = 0x4a002000 + offset
298 if (addr not in reglist):
299 error("register dump lacks data for additional muxes")
300 warn("using default values")
301 muxval = 0x0
302 else:
303 muxval = regmap[addr]
305 values = additional_mux.findall("value")
306 for value in values:
308 option = int(value.findtext("option"))
309 fieldpos = value.findtext("fieldPos")
310 signal = value.findtext("signal").upper()
311 matchlist = re.match("([0-9]+)[:]*([0-9]*)", fieldpos)
313 verbose("++++ Additional mux %s possible" % signal)
314 end = int(matchlist.groups(0)[0])
315 if (matchlist.groups(0)[1] == ""):
316 start = end
317 else:
318 start = int(matchlist.groups(0)[1])
320 muxval = muxval & (1 << end)
321 muxval = muxval >> start
323 if (muxval == option):
324 debug(">>>> Additional mux %s[%s] = %d" % (mux_reg_name, fieldpos, option))
325 debug(">>>> Effective signal = %s" % signal)
326 return value
327 error("None of the additional Mux value matched, using default")
328 return values[0]
330 def xml_find_delaymodes(pad_name, muxmode):
331 padlist = model_xml.findall("padDB/clockNode/type/pad")
332 for pad in padlist:
333 if (pad_name == pad.findtext("confregisters/regbit/register")):
334 muxmodes = pad.findall("muxmode")
335 break
336 if not muxmodes:
337 return None
338 for mode in muxmodes:
339 if ("%d" % muxmode == mode.findtext("mode")):
340 mode = xml_get_additional_mode(mode)
341 virt = xml_get_virtual(mode)
342 man = xml_get_manual(mode)
343 return (virt, man)
344 return None
346 def xml_check_correctness(modehelp):
348 print "###########################################"
349 print "XML correctness checks:"
350 padcore_list = []
351 padmodel_list = []
352 modes = {}
354 # Find all the pads in core XML
355 pad_list = pad_xml.findall("register")
356 for i in pad_list:
357 name = i.get("id")
358 if (re.match("CTRL_CORE_PAD_.*", name) == None):
359 continue
360 padcore_list.append(name)
361 print ">> Total pads defined in core XML = %d" % len(padcore_list)
363 # Find all the pads in model XML
364 pad_list = model_xml.findall("padDB/clockNode/type/pad/confregisters/regbit")
365 for i in pad_list:
366 name = i.findtext("register")
367 padmodel_list.append(name)
368 print ">> Total pads defined in model XML = %d" % len(padmodel_list)
370 # Find all the manual modes
371 manmode_list = model_xml.findall("padDB/clockNode/type/pad/muxmode/manualmode/cfgreg/mode")
372 for i in manmode_list:
373 man_name = i.findtext("name")
374 modes[man_name] = "manual"
375 # Find all the virtual modes
376 virtmode_list = model_xml.findall("padDB/clockNode/type/pad/muxmode/virtualmode/mode")
377 for i in virtmode_list:
378 virt_name = i.findtext("name")
379 modes[virt_name] = "virtual"
380 print ">> Total delaymodes defined in model XML = %d" % len(modes)
382 # Print out all the errors found in the tests
383 print "== Pads defined in core XML but not in model XML =="
384 for i in padcore_list:
385 if (i not in padmodel_list):
386 print "\t%s" % i
387 print "== Pads defined in model XML but not in core XML =="
388 for i in padmodel_list:
389 if (i not in padcore_list):
390 print "\t%s" % i
392 # Check if description for each mode is available
393 print "== Delaymodes missing description in the guidelines.txt =="
394 for i in modes:
395 if (i not in modehelp):
396 print "\t%s" % i
398 # Check if description for unknown mode is documented
399 print "== Delaymodes unused from guidelines.txt =="
400 for i in modehelp:
401 if (i not in modes):
402 print "\t%s" % i
404 print "###########################################"
406 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
408 # Decision point of the script
409 # For each pad/pin, decide what delay method is used
410 # Lookup in the selection file or ask user with a menu
411 def select_mode(pad, pin, module, virt, man, modehelp, sel):
412 modelist = []
413 for modename in virt.keys():
414 modelist.append(modename)
416 for modename in man.keys():
417 modelist.append(modename)
419 if (len(modelist) == 0):
420 return "LEGACY"
422 if (module in sel.keys()):
423 mode = sel[module]
424 if (mode == "SKIP" or mode == "LEGACY" or mode in modelist):
425 return mode
426 else:
427 error("Invalid delaymode '%s' for module '%s'" % (mode, module))
429 if (args.interactive == 0):
430 warn("No delay modes for %s found, skipping" % module)
431 mode = "SKIP"
432 return mode
434 # Display the menu and ask user to select the 'right' mode
435 while True:
436 print ""
437 print "MENU: Select delay mode for %s -> %s" % (pad, pin)
438 i = 0
439 print "MENU: %d: %s \t\t\t%s" % (i, "SKIP", "Skips this module for now")
440 i = 1
441 print "MENU: %d: %s \t\t%s" % (i, "LEGACY", "No external delay config (No virtual/manual needed)")
442 for mode in modelist:
443 i += 1
444 if (mode in modehelp):
445 helptext = modehelp[mode]
446 else:
447 helptext = "Unknown"
448 print "MENU: %d: %s \t\t%s" % (i, mode, helptext)
449 try:
450 choice = int(raw_input("Select delay mode #> "))
451 if (choice == 0):
452 mode = "SKIP"
453 break
454 elif (choice == 1):
455 mode = "LEGACY"
456 break
457 elif (choice >=2 and choice <= len(modelist) + 1):
458 mode = modelist[choice - 2]
459 break
460 print "ERROR: Invalid choice"
461 except ValueError:
462 print "ERROR: Invalid choice"
463 print "MENU: Selected mode is %s" % mode
464 print ""
466 return mode
467 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
469 # Pad read using GPIO - Specific to linux only
470 # As each pad is muxed with a SoC gpio (for most of the pads)
471 # It's possible to read the pad data using gpio datain registers
472 # Change pad register to enable input path and export sysfs
473 # Use sysfs to read the status of GPIO and print in a loop
474 def pad_dump_gpio(padconf, per_padconf):
475 gpio_data_addrs = (0, 0x4ae10138, 0x48055138, 0x48057138, 0x48059138, 0x4805b138, 0x4805d138, 0x48051138, 0x48053138)
476 module = args.module
478 # script header
479 gen_header = "###########################################\n" + \
480 "# Read %s signals using GPIO sysfs\n" % module + \
481 "###########################################\n\n"
482 gen_data = "%s_data=(\n" % module
484 for i in padconf:
485 (pad_name, pin_name, addr, val, mode, delayinfo) = i
487 offset = addr - 0x4a002000
488 gpio_name = xml_model_get_signal(offset, 14)
489 matchlist = re.match("GPIO(.)_(.*)", gpio_name)
490 if (matchlist == None):
491 error("No GPIO for pad %s - cannot read from script" % pad_name)
492 continue
494 inst = int(matchlist.groups(0)[0])
495 bit = int(matchlist.groups(0)[1])
496 gpio_addr = gpio_data_addrs[inst]
497 ngpio = (inst - 1) * 32 + bit
498 pin_short = re.match(".+_(.*)", pin_name).groups(0)[0]
500 gen_data += "\t%s:0x%x:%s:%d:0x%x:%d\n" % (pin_short, addr, gpio_name, ngpio, gpio_addr, bit)
502 gen_data += ")\n\n"
504 # Main script to probe the signal
505 gen_main = "echo; echo Probing %s signals\n\n" % module + \
506 "for data in ${%s_data[@]}\n" % module + \
507 "do\n" + \
508 " pin=`echo $data | cut -d ':' -f1`\n" + \
509 " pad=`echo $data | cut -d ':' -f2`\n" + \
510 " ngpio=`echo $data | cut -d ':' -f4`\n" + \
511 " echo $ngpio > /sys/class/gpio/export 2>/dev/null\n" + \
512 " omapconf set bit $pad 18 1>/dev/null 2>/dev/null\n" + \
513 " printf \"%8s\" $pin\n" + \
514 "done\n" + \
515 "echo\n\n"
517 gen_main += "while true;\n" + \
518 "do\n" + \
519 " for data in ${%s_data[@]}\n" % module + \
520 " do\n" + \
521 "# pin=`echo $data | cut -d ':' -f1`\n" + \
522 "# pad=`echo $data | cut -d ':' -f2`\n" + \
523 "# gpio=`echo $data | cut -d ':' -f3`\n" + \
524 " ngpio=`echo $data | cut -d ':' -f4`\n" + \
525 "# addr=`echo $data | cut -d ':' -f5`\n" + \
526 "# bit=`echo $data | cut -d ':' -f6`\n" + \
527 " val=`cat /sys/class/gpio/gpio$ngpio/value`\n" + \
528 " printf %8d $val \n" + \
529 " done\n" + \
530 " echo\n" + \
531 "done\n\n"
533 gen_footer = "###########################################\n"
535 # Generate the shell script
536 gen_script = gen_header + gen_data + gen_main + gen_footer
537 filename = ("./%s-probe.sh" % module).lower()
538 print "Generating '%s' script..." % filename
539 gen_file = open(filename, "w+")
540 gen_file.write(gen_script)
542 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
544 # Generate the final pad and delay data in the required format
545 def format_pad_regs(padconf, per_padconf):
546 print "######## Pad data output ########"
547 if (args.format == "uboot"):
548 uboot_format_pad_regs(padconf, per_padconf)
549 elif (args.format == "linux"):
550 linux_format_pad_regs(padconf, per_padconf)
551 elif (args.format == "bios"):
552 bios_format_pad_regs(padconf, per_padconf)
553 else:
554 error("Format %s not suppported" % args.format)
556 def format_delay_regs(delayconf, per_delayconf):
557 print "######## Delay data output ########"
558 if (args.format == "uboot"):
559 uboot_format_delay_regs(delayconf, per_delayconf)
560 elif (args.format == "linux"):
561 linux_format_delay_regs(delayconf, per_delayconf)
562 elif (args.format == "bios"):
563 bios_format_delay_regs(delayconf, per_delayconf)
564 else:
565 error("Format %s not suppported" % args.format)
567 def get_pin_info(val):
568 slew_fast = (val >> 19) & 0x1
569 inp_en = (val >> 18) & 0x1
570 pulltype = (val >> 17) & 0x1
571 pull_dis = (val >> 16) & 0x1
572 pin = "PIN"
573 if (inp_en):
574 pin += "_INPUT"
575 else:
576 pin += "_OUTPUT"
577 if (pull_dis == 0):
578 if (pulltype):
579 pin += "_PULLUP"
580 else:
581 pin += "_PULLDOWN"
582 if (slew_fast):
583 pin += " | SLEWCONTROL"
584 return pin
586 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
588 # Generate output in u-boot format
589 def uboot_format_pad_regs(padconf, per_padconf):
590 print "\nconst struct pad_conf_entry dra74x_core_padconf_array[] = {"
591 for i in padconf:
592 (pad_name, pin_name, addr, val, mode, delayinfo) = i
594 muxmode = val & 0xf
595 (method, data) = delayinfo
596 if (method == "LEGACY"):
597 extramode = ""
598 elif (method == "VIRTUAL"):
599 delaymode = data
600 extramode = " | VIRTUAL_MODE%d" % delaymode
601 elif (method == "MANUAL"):
602 extramode = " | MANUAL_MODE"
603 else:
604 error("Invalid delay method %s" % method)
606 pin_info = get_pin_info(val) + extramode
607 pad_short = re.sub("CTRL_CORE_PAD_", "", pad_name)
608 comment = (pad_short + "." + pin_name).lower()
610 print "\t{ %s, (M%d | %s) },\t/* %s */" % (pad_short, muxmode, pin_info, comment)
611 print "};\n"
613 def uboot_format_delay_regs(delayconf, per_delayconf):
614 manual_del = []
615 for i in delayconf:
616 (pad_name, pin_name, regname, del_offset, man_name, adel, gdel) = i
618 entry = (del_offset, adel, gdel, regname, pin_name, man_name)
619 manual_del.append(entry)
621 es_rev = args.revision.replace('.', '_')
622 print "\nconst struct iodelay_cfg_entry dra742_es" + es_rev + "_iodelay_cfg_array[] = {"
623 for entry in sorted(manual_del):
624 print "\t{ 0x%04X, %5d, %5d },\t/* %s : %s - %s */" % entry
625 print "};\n"
627 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
629 # Generate output in linux format
630 def linux_format_pad_regs(padconf, per_padconf):
631 print "&dra7_pmx_core {"
632 for per in per_padconf:
634 if (re.match("MMC.*", per) == None):
635 warn("Only MMC padconf is recommended in kernel")
637 # Get the mode from the first entry
638 (pad_name, pin_name, addr, val, mode, delayinfo) = per_padconf[per][0]
640 dtsnode = ("%s_pins_%s" % (per, mode)).lower()
641 print ""
642 print "\t%s: %s {" % (dtsnode, dtsnode)
643 print "\t\tpinctrl-single,pins = <"
644 for i in per_padconf[per]:
645 (pad_name, pin_name, addr, val, mode, delayinfo) = i
647 muxmode = val & 0xf
648 (method, data) = delayinfo
649 if (method == "LEGACY"):
650 extramode = ""
651 elif (method == "VIRTUAL"):
652 delaymode = data
653 extramode = " | MUX_VIRTUAL_MODE%d" % delaymode
654 elif (method == "MANUAL"):
655 extramode = " | MANUAL_MODE"
656 else:
657 warn("Invalid method %s" % method)
659 pin_info = get_pin_info(val) + extramode
660 pad_short = re.sub("CTRL_CORE_PAD_", "", pad_name)
661 offset = addr - 0x4a003400
662 comment = (pad_short + "." + pin_name).lower()
664 print "\t\t\t0x%03X\t(%s | MUX_MODE%d)\t/* %s */" % (offset, pin_info, muxmode, comment)
665 print "\t\t>;"
666 print "\t};"
667 print "};\n"
670 def linux_format_delay_regs(delayconf, per_delayconf):
671 print "&dra7_iodelay_core {"
672 for per in per_delayconf.keys():
674 if (re.match("MMC.*", per) == None):
675 warn("Only MMC delayconf is recommended in kernel")
677 # Get the mode from the first entry
678 (pad_name, pin_name, regname, del_offset, mode, adel, gdel) = per_delayconf[per][0]
680 dtsnode = ("%s_iodelay_%s_conf" % (per, mode)).lower()
681 print "\t%s: %s {" % (dtsnode, dtsnode)
682 print "\t\tpinctrl-single,pins = <"
683 for i in per_delayconf[per]:
684 (pad_name, pin_name, regname, del_offset, mode, adel, gdel) = i
686 print "\t\t\t0x%03X (A_DELAY(%d) | G_DELAY(%d))\t/* %s */" % (del_offset, adel, gdel, regname)
687 print "\t\t>;"
688 print "\t};"
689 print "};\n"
691 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
693 # Generate output in bios format
694 def bios_format_pad_regs(padconf, per_padconf):
695 for i in padconf:
696 (pad_name, pin_name, addr, val, mode, delayinfo) = i
698 delaylist = []
699 (method, data) = delayinfo
700 if (method == "VIRTUAL"):
701 virt_mode = data
702 val = val | ( virt_mode<< 4)
703 val = val | (1 << 8)
704 elif (method == "MANUAL"):
705 delaylist = data
706 val = val | (1 << 8)
708 offset = addr - 0x4a003400
709 out_delreg = out_adel = out_gdel = 0
710 in_delreg = in_adel = in_gdel = 0
711 oen_delreg = oen_adel = oen_gdel = 0
713 for j in delaylist:
714 (regname, adel, gdel) = j
715 if (re.match(".*_IN", regname) != None):
716 in_delreg = xml_iodelay_get_reg(regname)
717 in_adel = adel
718 in_gdel = gdel
719 elif (re.match(".*_OEN", regname) != None):
720 oen_delreg = xml_iodelay_get_reg(regname)
721 oen_adel = adel
722 oen_gdel = gdel
723 elif (re.match(".*_OUT", regname) != None):
724 out_delreg = xml_iodelay_get_reg(regname)
725 out_adel = adel
726 out_gdel = gdel
727 indel = "{ 0x%04X, %4d, %4d , 0}" % (in_delreg, in_adel, in_gdel)
728 oendel = "{ 0x%04X, %4d, %4d , 0}" % (oen_delreg, oen_adel, oen_gdel)
729 outdel = "{ 0x%04X, %4d, %4d , 0}" % (out_delreg, out_adel, out_gdel)
730 pin_info = get_pin_info(val)
731 print "\t/* %s -> %s (%s) %s delaymode */" % (pad_name, pin_name, pin_info, method)
732 print "\t{ 0x%03X, 0x%08X, %s, %s, %s }" % (offset, val, indel, oendel, outdel)
734 def bios_format_delay_regs(delayconf, per_delayconf):
735 debug("Manual delays are not configured separately")
736 debug("Delays are configured as part of the padconf step only")
738 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
740 # Main execution starts here
741 # * Parse all the XML files - Get the pad data and IOdelay data
742 # * Iterate over the pad register dumps
743 # * For each pad, find out the muxmode being used and the pad direction, etc
744 # * For the muxmode being used, find out available virtual/modes
745 # - Dump the virtual/manual modes available (based on options)
746 # - Build up the gpio script to read the pad data using GPIO module
747 # * Select the correct mode to be used
748 # - Check if the mode is described for the peripheral module, (from selected-modes.txt)
749 # - Otherwise ask the user (with a menu) to decide the delaymode
750 # => Update the selection for the whole of the peripheral module
751 # - Worst case, skip the delaymode for this pad
752 # * Build the pad and delay register information
753 # * Create the dump for pad and delay data in linux/u-boot format
754 # * Dump the delaymode selection for each peripheral
755 # * Dump the GPIO script for each peripheral (all pads grouped together)
756 #
758 # List of all the pads being configured
759 padconf = []
760 # List of all the delay registers being configured (for manual mode)
761 delayconf = []
762 # Dictionary of pads grouped by peripheral/module
763 per_padconf = {}
764 # Dictionary of delay registers grouped by peripheral/module
765 per_delayconf = {}
767 if(args.check_xml):
768 xml_check_correctness(modehelp)
769 exit()
771 # Start iterating over each pad
772 for i in range(0, 260):
773 # Find out the muxmode and pad direction, etc
774 addr = 0x4a003400 + i * 4
775 offset = 0x1400 + i * 4
776 dts_offset = offset - 0x1400
778 if (addr not in reglist):
779 warn("Register dump for pad 0x%X not found" % addr)
780 continue
781 val = regmap[addr]
782 muxmode = val & 0xf
784 # Find out the pin based on the muxmode
785 pad_name = xml_pad_get_name(offset)
786 pin_name = xml_model_get_signal(offset, muxmode)
787 if (pad_name == "Unknown" or pin_name == "Unknown"):
788 warn("Cannot find out Pad/Pin name for PAD address 0x%X (%s[%s] = %s)" \
789 % (addr, pad_name, muxmode, pin_name))
790 continue
791 if (pin_name == "DRIVER"):
792 continue
794 # Find out if the delaymode for this module is already selected
795 match = re.match("([^_]+)_.*", pin_name)
796 if (match):
797 module = match.groups(0)[0]
798 else:
799 module = pin_name
801 if (args.module != "" and re.match("%s" % args.module, module) == None):
802 continue
804 # It is recommended to keep the reset value of the slewcontrol bit
805 # Find out the reset value from XML and update if required
806 if (args.resetslew):
807 val |= (xml_pad_get_slew(offset) & 0x1) << 19
809 debug("PAD: %s: Addr= 0x%08X Value = 0x%08X \"%s\"" \
810 % (pad_name, addr, val, pin_name))
812 # Find out all the possible virtual, manual modes fot the specific pad -> pin combination
813 (virt, man) = xml_find_delaymodes(pad_name, muxmode)
815 if (args.gpio == True):
816 mode = "LEGACY"
817 else:
818 # Need to select one out of allowed modes
819 mode = select_mode(pad_name, pin_name, module, virt, man, modehelp, sel)
821 # Remember the selection for that module, for later reuse
822 if (args.strict == False and module not in sel.keys()):
823 sel[module] = mode
825 if (mode == "SKIP"):
826 continue
827 elif (mode == "LEGACY"):
828 delayinfo = ("LEGACY", "")
829 elif (mode in virt):
830 delayinfo = ("VIRTUAL", virt[mode])
831 elif (mode in man):
832 delayinfo = ("MANUAL", man[mode])
833 else:
834 error("Unknown mode '%s' selected" % mode)
835 continue
837 debug(" => Using mode %s" % mode)
838 paddata = (pad_name, pin_name, addr, val, mode, delayinfo)
839 if (module not in per_padconf.keys()):
840 per_padconf[module] = []
841 padconf.append(paddata)
842 per_padconf[module].append(paddata)
844 if(mode not in man):
845 continue
847 # Add the delay data if using manual mode
848 for regval in man[mode]:
849 (regname, adel, gdel) = regval
850 del_offset = xml_iodelay_get_reg(regname)
851 if (del_offset == 0):
852 error("Can't find delay offset of register %s" % regname)
853 break
854 debug(" => Manual delay[%s] = (%d, %d)" % (regname, adel, gdel))
855 delaydata = (pad_name, pin_name, regname, del_offset, mode, adel, gdel)
856 if (module not in per_delayconf.keys()):
857 per_delayconf[module] = []
858 delayconf.append(delaydata)
859 per_delayconf[module].append(delaydata)
861 if(args.gpio == True):
862 pad_dump_gpio(padconf, per_padconf)
863 exit()
865 format_pad_regs(padconf, per_padconf)
866 format_delay_regs(delayconf, per_delayconf)
868 if (args.interactive):
869 # Summary of the generated data
870 print ""
871 print "Total PAD registers: %d" % len(padconf)
872 print "Total DELAY registers: %d" % len(delayconf)
873 print ""
874 # Dump the final selection for reuse
875 print "Selected modes for each peripheral module\n"
876 for group in sel:
877 print "%s,\t%s" % (group, sel[group])
878 print ""
879 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #