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