]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - glsdk/iodelay-config.git/blobdiff - iodelay-autogen.py
PCT XML: DRA72x: Migrate to v3.0.7
[glsdk/iodelay-config.git] / iodelay-autogen.py
index 51c19acb41da0bd6458c62b3234fe23991d140ac..d684602bb720ec52462c7451fb85fda5311ec92a 100755 (executable)
@@ -16,18 +16,14 @@ import xml.etree.ElementTree as ET
 import re
 import argparse
 
-pad_data_xml = "XMLFiles/CTRL_MODULE_CORE.xml"
-iod_data_xml = "XMLFiles/IODELAYCONFIG.xml"
-model_data_xml = "XMLFiles/model_DRA75x_DRA74x_SR1.1_v1.0.6.xml"
-modehelp_file = "guidelines.txt"
-
-pad_file = "ctrl-core.dump"
-sel_file = "selected-modes.txt"
-
 # Handle the command line arguments
 parser = argparse.ArgumentParser(prog='iodelay-autogen.py',
-       description='Python script to generate the IOdelay data',
-       epilog='Generate the pad and delay data using pad regdump')
+       description='Python script to generate the IOdelay data.\n' \
+               'This script refers to the XML data and automatically generates\n' \
+               'PAD and DELAY data for the same use case.\n' \
+               'Note that only the PADs which are used in the dump are configured.',
+       epilog='Generate the pad and delay data using pad register dumps. For this,\n' \
+               'Run omapconf dump 0x4a003400 0x4a00380c and save the output')
 
 parser.add_argument('-d', '--debug', dest='debug',
        action='store', type=int, choices=[0, 1, 2], default=0,
@@ -38,20 +34,66 @@ parser.add_argument('-i', '--interactive', dest='interactive',
        help='run interactively with menus for resolving conflicts')
 
 parser.add_argument('-f', '--format', dest='format',
-       action='store', type=str, choices=["linux", "uboot"], default="uboot",
+       action='store', type=str, choices=["linux", "uboot", "bios"], default="uboot",
        help='select the output format to be used')
 
+parser.add_argument('-r', '--revision', dest='revision',
+       action='store', type=str, choices=["1.0", "1.1", "2.0"], default="1.1",
+       help='select the silicon revision')
+
+parser.add_argument('-p', '--part', dest='part',
+       action='store', type=str, choices=["dra74x", "dra75x", "dra72x"], default="dra74x",
+       help='select the device part')
+
 parser.add_argument('-m', '--module', dest='module',
        action='store', type=str, default="",
-       help='generate only for this module')
+       help='generate only for modules matching the provided RE')
+
+parser.add_argument('-s', '--strict', dest='strict',
+       action='store_true',
+       help='strict mode - ask for each pad of the group, do not save selection.\n' \
+               'For some peripherals, same delaymode cannot be used for all the pads.\n' \
+               'Use this mode to select different modes for each pad')
 
 parser.add_argument('-g', '--gpio', dest='gpio',
        action='store_true',
        help='generate script to read pad data from GPIO')
 
+parser.add_argument('-c', '--check', dest='check_xml',
+       action='store_true',
+       help='check consistency of the XML files and other data')
+
 args = parser.parse_args()
+
+# Some more knobs for developers, Don't want to expose them to cmd line
+args.resetslew = True
+
 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
 
+VERSION = "2.4"
+
+if (args.part == "dra74x" or args.part == "dra75x"):
+       XML_PATH = "XMLFiles/DRA75x_DRA74x"
+       PART = "DRA75x_DRA74x"
+       PCT_VERSION = "v1.0.10"
+elif (args.part == "dra72x"):
+       XML_PATH = "XMLFiles/DRA72x"
+       PART = "DRA72x"
+       PCT_VERSION = "v1.0.7"
+
+pad_data_xml   = XML_PATH + "/CTRL_MODULE_CORE.xml"
+iod_data_xml   = XML_PATH + "/IODELAYCONFIG.xml"
+model_data_xml = XML_PATH + "/model_" + PART + "_SR" + args.revision + "_" + PCT_VERSION + ".xml"
+modehelp_file  = XML_PATH + "/guidelines.txt"
+
+pad_file = "ctrl-core.dump"
+sel_file = "selected-modes.txt"
+
+print "iodelay-autogen.py - Python script to generate the IOdelay data."
+print "v" + VERSION + " using PCT version " + PCT_VERSION
+print "Parsing PCT data from " + model_data_xml + "..."
+print ""
+
 # Read the XML file database for pad and delay registers
 pad_xml = ET.parse(pad_data_xml).getroot()
 iod_xml = ET.parse(iod_data_xml).getroot()
@@ -60,7 +102,7 @@ model_xml = ET.parse(model_data_xml).getroot()
 # Functions to parse the input files and build data structures
 def read_guidelines(fname):
        modehelp = {}
-       pattern = re.compile('(.+\w)\t+(.+)')
+       pattern = re.compile('([^\t.]+\w)\t+(.+)')
        f = open(fname)
        for line in f.readlines():
                list = re.match(pattern, line)
@@ -115,7 +157,40 @@ def xml_pad_get_name(offset):
        else:
                return padlist[0].get("id")
 
-def xml_pad_get_pin(offset, muxmode):
+def xml_pad_get_slew(offset):
+       padlist = pad_xml.findall("register[@offset='0x%X']" % offset)
+       if (len(padlist) == 0):
+               return 0x0
+       else:
+               bitlist = padlist[0].findall("bitfield[@begin='19']")
+               if (len(bitlist) == 0):
+                       return 0x0
+               else:
+                       return int(bitlist[0].get("resetval"), 16)
+
+# For DRA72x SoC, for "ball compatibility" purpose, some signals have same muxmode.
+# CTRL_CORE_ALT_SELECT_MUX register allows to select between one of the signals
+# Its like a board mux has been added inside the SoC, except it uses same muxmode.
+def resolve_group(muxmode_str):
+       mmlist = muxmode_str.split(" ")
+       mmlen = len(mmlist)
+       if (mmlen == 1):
+               def_mode = mmlist[0]
+               return mmlist[0]
+       elif (mmlen == 2):
+               def_mode = mmlist[0]
+               grp1_mode = mmlist[1]
+       elif (mmlen == 3):
+               def_mode = mmlist[0]
+               grp1_mode = mmlist[1]
+               grp2_mode = mmlist[2]
+       else:
+               print "ERR: Cannot resolve muxmode group for '%s'" % muxmode_str
+
+       #HACK for now
+       return def_mode
+
+def xml_model_get_signal(offset, muxmode):
        padlist = pad_xml.findall("register[@offset='0x%X']" % offset)
        if (len(padlist) == 0):
                return "Unknown"
@@ -126,7 +201,7 @@ def xml_pad_get_pin(offset, muxmode):
                modes = mux_field[0].findall("./bitenum[@value='%d']" % muxmode)
                if (len(modes) == 0):
                        return "Unknown"
-               return modes[0].get("id")
+               return resolve_group(modes[0].get("id"))
 
 def xml_iodelay_get_reg(name):
        delaylist = iod_xml.findall("register[@id='%s']" % name)
@@ -170,7 +245,6 @@ def xml_get_manual(mode):
                        if (args.debug >= 1):
                                print ("    * MANUAL: %s [%s] => delay[%s] = %d, %d" % (signal, man_name, regname, adel, gdel))
        return mmodes
-               
 
 def xml_find_delaymodes(pad_name, muxmode):
        padlist = model_xml.findall("padDB/clockNode/type/pad")
@@ -186,6 +260,63 @@ def xml_find_delaymodes(pad_name, muxmode):
                        man = xml_get_manual(mode)
                        return (virt, man)
        return None
+
+def xml_check_correctness(modehelp):
+       if(args.check_xml == False):
+               return
+
+       print "###########################################"
+       print "XML correctness checks:"
+       padcore_list = []
+       padmodel_list = []
+       modes = {}
+
+       # Fint all the pads in core XML
+       pad_list = pad_xml.findall("register")
+       for i in pad_list:
+               name = i.get("id")
+               if (re.match("CTRL_CORE_PAD_.*", name) == None):
+                       continue
+               padcore_list.append(name)
+       print ">> Total pads defined in core XML = %d" % len(padcore_list)
+
+       # Find all the pads in model XML
+       pad_list = model_xml.findall("padDB/clockNode/type/pad/confregisters/regbit")
+       for i in pad_list:
+               name = i.findtext("register")
+               padmodel_list.append(name)
+       print ">> Total pads defined in model XML = %d" % len(padmodel_list)
+
+       # Find all the manual modes
+       manmode_list = model_xml.findall("padDB/clockNode/type/pad/muxmode/manualmode/cfgreg/mode")
+       for i in manmode_list:
+               man_name = i.findtext("name")
+               modes[man_name] = "manual"
+       # Find all the virtual modes
+       virtmode_list = model_xml.findall("padDB/clockNode/type/pad/muxmode/virtualmode/mode")
+       for i in virtmode_list:
+               virt_name = i.findtext("name")
+               modes[virt_name] = "virtual"
+       print ">> Total delaymodes defined in model XML = %d" % len(modes)
+
+       # Print out all the errors found in the tests
+       print "== Pads defined in core XML but not in model XML =="
+       for i in padcore_list:
+               if (i not in padmodel_list):
+                       print "\t%s" % i
+       print "== Pads defined in model XML but not in core XML =="
+       for i in padmodel_list:
+               if (i not in padcore_list):
+                       print "\t%s" % i
+
+       # Check if description for each mode is available
+       print "== Delaymodes missing description in the guidelines.txt =="
+       for i in modes:
+               if (i not in modehelp):
+                       print "\t%s" % i
+
+       print "###########################################"
+
 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
 
 # Decision point of the script
@@ -204,15 +335,14 @@ def select_mode(pad, pin, module, virt, man, modehelp, sel):
 
        if (module in sel.keys()):
                mode = sel[module]
-               if (mode == "SKIP" or mode in modelist):
+               if (mode == "SKIP" or mode == "LEGACY" or mode in modelist):
                        return mode
                else:
-                       print("ERR: Invalid delaymode '%s' for module '%s'" & (mode, module))
+                       print("ERR: Invalid delaymode '%s' for module '%s'" % (mode, module))
 
        if (args.interactive == 0):
                print "WARN: No delay modes for %s found, skipping" % module
                mode = "SKIP"
-               sel[module] = mode
                return mode
 
        # Display the menu and ask user to select the 'right' mode
@@ -221,16 +351,25 @@ def select_mode(pad, pin, module, virt, man, modehelp, sel):
                print "MENU: Select delay mode for %s -> %s" % (pad, pin)
                i = 0
                print "MENU: %d: %s \t\t\t%s" % (i, "SKIP", "Skips this module for now")
+               i = 1
+               print "MENU: %d: %s \t\t%s" % (i, "LEGACY", "No external delay config (No virtual/manual needed)")
                for mode in modelist:
                        i += 1
-                       print "MENU: %d: %s \t\t%s" % (i, mode, modehelp[mode])
+                       if (mode in modehelp):
+                               helptext = modehelp[mode]
+                       else:
+                               helptext = "Unknown"
+                       print "MENU: %d: %s \t\t%s" % (i, mode, helptext)
                try:
                        choice = int(raw_input("Select delay mode #> "))
                        if (choice == 0):
                                mode = "SKIP"
                                break
-                       elif (choice >=0 and choice <= len(modelist)):
-                               mode = modelist[choice - 1]
+                       elif (choice == 1):
+                               mode = "LEGACY"
+                               break
+                       elif (choice >=2 and choice <= len(modelist) + 1):
+                               mode = modelist[choice - 2]
                                break
                        print "ERROR: Invalid choice"
                except ValueError:
@@ -238,8 +377,6 @@ def select_mode(pad, pin, module, virt, man, modehelp, sel):
        print "MENU: Selected mode is %s" % mode
        print ""
 
-       # Remember the selection for that module, for later reuse
-       sel[module] = mode
        return mode
 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
 
@@ -248,18 +385,17 @@ def select_mode(pad, pin, module, virt, man, modehelp, sel):
 # It's possible to read the pad data using gpio datain registers
 # Dump the linux commands to read the gpio registers and read the pad data
 def pad_dump_gpio(padconf, per_padconf):
-       if(args.gpio == False):
-               return
-
-       print "# Read pad signals using GPIO DATA-IN registers"
+       print "###########################################"
+       print "# Read %s signals using GPIO DATA-IN registers" % args.module
        print "# Works only for the input signals"
+       print "###########################################"
        gpio_data_addrs = (0, 0x4ae10138, 0x48055138, 0x48057138, 0x48059138, 0x4805b138, 0x4805d138, 0x48051138, 0x48053138)
        for i in padconf:
-               (pad_name, pin_name, addr, val, delayinfo) = i
+               (pad_name, pin_name, addr, val, mode, delayinfo) = i
 
                offset = addr - 0x4a002000
-               gpio_name = xml_pad_get_pin(offset, 14)
-               matchlist = re.match("GPIO(.)_(.)", gpio_name)
+               gpio_name = xml_model_get_signal(offset, 14)
+               matchlist = re.match("GPIO(.)_(.*)", gpio_name)
                if (matchlist == None):
                        print "ERR: No GPIO for pad %s" % pad_name
                        continue
@@ -280,27 +416,32 @@ def pad_dump_gpio(padconf, per_padconf):
 # Generate the final pad and delay data in the required format
 def format_pad_regs(padconf, per_padconf):
        print "###########################################"
-       print "Pad data for u-boot (with the delay modes):"
+       print "Pad data output (with the delay modes)"
        print "###########################################"
        if (args.format == "uboot"):
                uboot_format_pad_regs(padconf, per_padconf)
        elif (args.format == "linux"):
                linux_format_pad_regs(padconf, per_padconf)
+       elif (args.format == "bios"):
+               bios_format_pad_regs(padconf, per_padconf)
        else:
                print "ERR: Format %s not suppported" % args.format
 
 def format_delay_regs(delayconf, per_delayconf):
        print "#########################################"
-       print "Delay data for u-boot (for manual modes):"
+       print "Delay data output (for manual modes)"
        print "#########################################"
        if (args.format == "uboot"):
                uboot_format_delay_regs(delayconf, per_delayconf)
        elif (args.format == "linux"):
                linux_format_delay_regs(delayconf, per_delayconf)
+       elif (args.format == "bios"):
+               bios_format_delay_regs(delayconf, per_delayconf)
        else:
                print "ERR: Format %s not suppported" % args.format
 
 def get_pin_info(val):
+       slew_fast = (val >> 19) & 0x1
        inp_en = (val >> 18) & 0x1
        pulltype = (val >> 17) & 0x1
        pull_dis = (val >> 16) & 0x1
@@ -314,6 +455,8 @@ def get_pin_info(val):
                        pin += "_PULLUP"
                else:
                        pin += "_PULLDOWN"
+       if (slew_fast):
+               pin += " | SLEWCONTROL"
        return pin
 
 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
@@ -322,11 +465,7 @@ def get_pin_info(val):
 def uboot_format_pad_regs(padconf, per_padconf):
        print "\nconst struct pad_conf_entry dra74x_core_padconf_array[] = {"
        for i in padconf:
-               (pad_name, pin_name, addr, val, delayinfo) = i
-
-               if (re.match("MMC.*", pin_name) != None):
-                       print "WARN: Skipping MMC padconf in uboot"
-                       continue
+               (pad_name, pin_name, addr, val, mode, delayinfo) = i
 
                muxmode = val & 0xf
                (method, data) = delayinfo
@@ -348,16 +487,19 @@ def uboot_format_pad_regs(padconf, per_padconf):
        print "};\n"
 
 def uboot_format_delay_regs(delayconf, per_delayconf):
-       print "\nconst struct iodelay_cfg_entry dra742_iodelay_cfg_array[] = {"
+       manual_del = []
        for i in delayconf:
                (pad_name, pin_name, regname, del_offset, man_name, adel, gdel) = i
 
-               if (re.match("MMC.*", pin_name) != None):
-                       print "WARN: Skipping MMC padconf in uboot"
-                       continue
+               entry = (del_offset, adel, gdel, regname, pin_name, man_name)
+               manual_del.append(entry)
 
-               print "\t{ 0x%04X, %5d, %5d },\t/* %s */" % (del_offset, adel, gdel, regname)
+       es_rev = args.revision.replace('.', '_')
+       print "\nconst struct iodelay_cfg_entry dra742_es" + es_rev + "_iodelay_cfg_array[] = {"
+       for entry in sorted(manual_del):
+               print "\t{ 0x%04X, %5d, %5d },\t/* %s : %s - %s */" % entry
        print "};\n"
+
 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
 
 # Generate output in linux format
@@ -366,15 +508,17 @@ def linux_format_pad_regs(padconf, per_padconf):
        for per in per_padconf:
 
                if (re.match("MMC.*", per) == None):
-                       print "ERR: Only MMC padconf is recommended in kernel"
-                       continue
+                       print "WARN: Only MMC padconf is recommended in kernel"
+
+               # Get the mode from the first entry
+               (pad_name, pin_name, addr, val, mode, delayinfo) = per_padconf[per][0]
 
-               dtsnode = ("%s_pins_default" % per).lower()
+               dtsnode = ("%s_pins_%s" % (per, mode)).lower()
                print ""
                print "\t%s: %s {" % (dtsnode, dtsnode)
                print "\t\tpinctrl-single,pins = <"
                for i in per_padconf[per]:
-                       (pad_name, pin_name, addr, val, delayinfo) = i
+                       (pad_name, pin_name, addr, val, mode, delayinfo) = i
 
                        muxmode = val & 0xf
                        (method, data) = delayinfo
@@ -382,7 +526,7 @@ def linux_format_pad_regs(padconf, per_padconf):
                                extramode = ""
                        elif (method == "VIRTUAL"):
                                delaymode = data
-                               extramode = " | VIRTUAL_MODE%d" % delaymode
+                               extramode = " | MUX_VIRTUAL_MODE%d" % delaymode
                        elif (method == "MANUAL"):
                                extramode = " | MANUAL_MODE"
                        else:
@@ -393,7 +537,7 @@ def linux_format_pad_regs(padconf, per_padconf):
                        offset = addr - 0x4a003400
                        comment = (pad_short + "." + pin_name).lower()
 
-                       print "\t\t\t0x%03X\t(%s | MUM_MODE%d)\t/* %s */" % (offset, pin_info, muxmode, comment)
+                       print "\t\t\t0x%03X\t(%s | MUX_MODE%d)\t/* %s */" % (offset, pin_info, muxmode, comment)
                print "\t\t>;"
                print "\t};"
        print "};\n"
@@ -404,8 +548,7 @@ def linux_format_delay_regs(delayconf, per_delayconf):
        for per in per_delayconf.keys():
 
                if (re.match("MMC.*", per) == None):
-                       print "ERR: Only MMC delayconf is recommended in kernel"
-                       continue
+                       print "WARN: Only MMC delayconf is recommended in kernel"
 
                # Get the mode from the first entry
                (pad_name, pin_name, regname, del_offset, mode, adel, gdel) = per_delayconf[per][0]
@@ -416,13 +559,60 @@ def linux_format_delay_regs(delayconf, per_delayconf):
                for i in per_delayconf[per]:
                        (pad_name, pin_name, regname, del_offset, mode, adel, gdel) = i
 
-                       print "\t\t\t0x%03X A_DELAY(%d) | G_DELAY(%d)\t/* %s */" % (del_offset, adel, gdel, regname)
+                       print "\t\t\t0x%03X (A_DELAY(%d) | G_DELAY(%d))\t/* %s */" % (del_offset, adel, gdel, regname)
                print "\t\t>;"
                print "\t};"
        print "};\n"
 
 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
 
+# Generate output in bios format
+def bios_format_pad_regs(padconf, per_padconf):
+       for i in padconf:
+               (pad_name, pin_name, addr, val, mode, delayinfo) = i
+
+               delaylist = []
+               (method, data) = delayinfo
+               if (method == "VIRTUAL"):
+                       virt_mode = data
+                       val = val | ( virt_mode<< 4)
+                       val = val | (1 << 8)
+               elif (method == "MANUAL"):
+                       delaylist = data
+                       val = val | (1 << 8)
+
+               offset = addr - 0x4a003400
+               out_delreg = out_adel = out_gdel = 0
+               in_delreg  = in_adel  = in_gdel  = 0
+               oen_delreg = oen_adel = oen_gdel = 0
+
+               for j in delaylist:
+                       (regname, adel, gdel) = j
+                       if (re.match(".*_IN", regname) != None):
+                               in_delreg = xml_iodelay_get_reg(regname)
+                               in_adel = adel
+                               in_gdel = gdel
+                       elif (re.match(".*_OEN", regname) != None):
+                               oen_delreg = xml_iodelay_get_reg(regname)
+                               oen_adel = adel
+                               oen_gdel = gdel
+                       elif (re.match(".*_OUT", regname) != None):
+                               out_delreg = xml_iodelay_get_reg(regname)
+                               out_adel = adel
+                               out_gdel = gdel
+               indel  = "{ 0x%04X, %4d, %4d }" % (in_delreg,  in_adel,  in_gdel)
+               oendel = "{ 0x%04X, %4d, %4d }" % (oen_delreg, oen_adel, oen_gdel)
+               outdel = "{ 0x%04X, %4d, %4d }" % (out_delreg, out_adel, out_gdel)
+               pin_info = get_pin_info(val)
+               print "\t/* %s -> %s (%s) %s delaymode */" % (pad_name, pin_name, pin_info, method)
+               print "\t{ 0x%03X, 0x%08X, %s, %s, %s }" % (offset, val, indel, oendel, outdel)
+
+def bios_format_delay_regs(delayconf, per_delayconf):
+       print "Manual delays are not configured separately"
+       print "Delays are configured as part of the padconf step only"
+
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+
 # Main execution starts here
 # * Parse all the XML files - Get the pad data and IOdelay data
 # * Iterate over the pad register dumps
@@ -456,6 +646,8 @@ per_padconf = {}
 # Dictionary of delay registers grouped by peripheral/module
 per_delayconf = {}
 
+xml_check_correctness(modehelp)
+
 # Start iterating over each pad
 for i in range(0, 260):
        # Find out the muxmode and pad direction, etc
@@ -471,20 +663,25 @@ for i in range(0, 260):
 
        # Find out the pin based on the muxmode
        pad_name = xml_pad_get_name(offset)
-       pin_name = xml_pad_get_pin(offset, muxmode)
+       pin_name = xml_model_get_signal(offset, muxmode)
        if (pad_name == "Unknown" or pin_name == "Unknown"):
                print "WARN: Cannot find out Pad/Pin name for PAD address 0x%X (%s[%s] = %s)" \
                % (addr, pad_name, muxmode, pin_name)
                continue
-       if (pin_name == "DRIVER OFF"):
+       if (pin_name == "DRIVER"):
                continue
 
        # Find out if the delaymode for this module is already selected
        module = re.match("([^_]+)_.*", pin_name).groups(0)[0]
 
-       if (args.module != "" and args.module != module):
+       if (args.module != "" and re.match("%s" % args.module, module) == None):
                continue
 
+       # It is recommended to keep the reset value of the slewcontrol bit
+       # Find out the reset value from XML and update if required
+       if (args.resetslew):
+               val |= (xml_pad_get_slew(offset) & 0x1) << 19
+
        if (args.debug >= 1):
                print "\nPAD: %s: Addr= 0x%08X Value = 0x%08X \"%s\"" \
                % (pad_name, addr, val, pin_name)
@@ -492,12 +689,19 @@ for i in range(0, 260):
        # Find out all the possible virtual, manual modes fot the specific pad -> pin combination
        (virt, man) = xml_find_delaymodes(pad_name, muxmode)
 
-       # Need to select one out of allowed modes
-       mode = select_mode(pad_name, pin_name, module, virt, man, modehelp, sel)
+       if (args.gpio == True):
+               mode = "LEGACY"
+       else:
+               # Need to select one out of allowed modes
+               mode = select_mode(pad_name, pin_name, module, virt, man, modehelp, sel)
+
+       # Remember the selection for that module, for later reuse
+       if (args.strict == False and module not in sel.keys()):
+               sel[module] = mode
+
        if (mode == "SKIP"):
                continue
-
-       if (mode == "LEGACY"):
+       elif (mode == "LEGACY"):
                delayinfo = ("LEGACY", "")
        elif (mode in virt):
                delayinfo = ("VIRTUAL", virt[mode])
@@ -509,7 +713,7 @@ for i in range(0, 260):
 
        if (args.debug >= 1):
                print "  => Using mode %s" % mode
-       paddata = (pad_name, pin_name, addr, val, delayinfo)
+       paddata = (pad_name, pin_name, addr, val, mode, delayinfo)
        if (module not in per_padconf.keys()):
                per_padconf[module] = []
        padconf.append(paddata)
@@ -538,9 +742,12 @@ print "Total PAD registers: %d" % len(padconf)
 print "Total DELAY registers: %d" % len(delayconf)
 print ""
 
+if(args.gpio == True):
+       pad_dump_gpio(padconf, per_padconf)
+       exit()
+
 format_pad_regs(padconf, per_padconf)
 format_delay_regs(delayconf, per_delayconf)
-pad_dump_gpio(padconf, per_padconf)
 
 # Dump the final selection for reuse
 print "Selected modes for each peripheral module\n"