script: Initial version of the IOdelay autogen script
authorNikhil Devshatwar <nikhil.nd@ti.com>
Thu, 11 Jun 2015 10:57:41 +0000 (16:27 +0530)
committerNikhil Devshatwar <nikhil.nd@ti.com>
Thu, 11 Jun 2015 10:57:41 +0000 (16:27 +0530)
Signed-off-by: Nikhil Devshatwar <nikhil.nd@ti.com>
config-iodelay-autogen [new file with mode: 0644]
guidelines.txt [new file with mode: 0644]
iodelay-autogen.py [new file with mode: 0755]
selected-modes.txt [new file with mode: 0644]

diff --git a/config-iodelay-autogen b/config-iodelay-autogen
new file mode 100644 (file)
index 0000000..044f578
--- /dev/null
@@ -0,0 +1,8 @@
+[general]
+auto_decide = 0
+dump_all = 0
+dump_gpio = 1
+dump_virtual = 0
+dump_manual = 0
+[gui]
+interactive = 0
diff --git a/guidelines.txt b/guidelines.txt
new file mode 100644 (file)
index 0000000..b8a343f
--- /dev/null
@@ -0,0 +1,80 @@
+========================== Guildelines for selecting mode ==========================
+Following are the guidelines for selecting a specific virtual/manual mode
+DO NOT CHANGE ANYTHING HERE. USE ONLY THE CORRECT MODE NAME IN THE ABOVE LIST
+
+========================== DPI Video Output ==========================
+DSS_VIRTUAL1                   DPI1/2/3 Video Output Default Timings - Falling-edge Clock Reference
+VOUT1_MANUAL1                  DPI1 Video Output Alternate Timings
+VOUT2_IOSET1_MANUAL1           DPI2 Video Output IOSET1 Alternate Timings
+VOUT2_IOSET2_MANUAL1           DPI2 Video Output IOSET2 Alternate Timings
+VOUT3_MANUAL1                  DPI3 Video Output Alternate Timings
+========================== GPMC ==========================
+GPMC_VIRTUAL1                  GPMC Synchronous Mode - 5 Load Timings
+========================== McASP ==========================
+MCASP1_VIRTUAL1_ASYNC_TX       McASP1 Asynchronous Transmit Timings
+MCASP1_VIRTUAL2_SYNC_RX                McASP1 Synchronous Receive Timings
+MCASP1_VIRTUAL3_ASYNC_RX       McASP1 Asynchronous Receive Timings
+MCASP2_VIRTUAL1_ASYNC_RX_80M   McASP2 Asynchronous Receive Timings when ACLKx, AFSX, and AXR are all inputs
+MCASP2_VIRTUAL2_ASYNC_RX       McASP2 Asynchronous Receive Timings
+MCASP2_VIRTUAL3_ASYNC_TX       McASP2 Asynchronous Transmit Timings
+MCASP2_VIRTUAL4_SYNC_RX                McASP2 Synchronous Receive Timings
+MCASP2_VIRTUAL5_SYNC_RX_80M    McASP2 Synchronous Receive Timings when ACLKx, AFSX, and AXR are all inputs
+MCASP3_VIRTUAL2_SYNC_RX                McASP3 Synchronous Receive Timings
+MCASP4_VIRTUAL1_SYNC_RX                McASP4 Synchronous Receive Timings
+MCASP5_VIRTUAL1_SYNC_RX                McASP5 Synchronous Receive Timings
+MCASP6_VIRTUAL1_SYNC_RX                McASP6 Synchronous Receive Timings
+MCASP7_VIRTUAL2_SYNC_RX                McASP7 Synchronous Receive Timings
+MCASP8_VIRTUAL1_SYNC_RX                McASP8 Synchronous Receive Timings
+========================== eMMC/SD/SDIO ==========================
+MMC1_VIRTUAL1                  MMC1 HS, SDR25 Timings (Internal Loopback and Pad Loopback), SDR12 (Internal Loopback)
+MMC1_VIRTUAL2                  SDR50 (Pad Loopback) Timings
+MMC1_VIRTUAL5                  MMC1 DS (Internal Loopback) Timings
+MMC1_VIRTUAL6                  MMC1 SDR50 (Internal Loopback) Timings
+MMC1_VIRTUAL7                  MMC1 DDR50 (Internal Loopback) Timings
+MMC1_DDR_MANUAL1               MMC1 DDR50 (Pad Loopback) Timings
+MMC1_SDR104_MANUAL1            MMC1 SDR104 Timings
+MMC2_DDR_LB_MANUAL1            MMC2 DDR (Internal Loopback) Timings
+MMC2_DDR_1V8_MANUAL1           MMC2 DDR (Pad Loopback) 1.8V Mode Timings
+MMC2_DDR_3V3_MANUAL1           MMC2 DDR (Pad Loopback) 3.3V Mode Timings
+MMC2_HS200_MANUAL1             MMC2 HS200 Timings
+MMC2_STD_HS_LB_MANUAL1         MMC2 Standard (Internal Loopback), High Speed (Internal Loopback) Timings
+MMC3_MANUAL1                   MMC3 DS, SDR12, HS, SDR25 Timings
+MMC3_SDR50_MANUAL1             MMC3 SDR50 Timings
+MMC4_MANUAL1                   MMC4 SDR12, HS, SDR25 Timings
+MMC4_DS_MANUAL1                        MMC4 DS Timings
+========================== PRUSS (hide in Datasheet) ==========================
+PRUSS1_IN_VIRTUAL1             (Hide in Datasheet)
+PRUSS1_OUT_VIRTUAL1            (Hide in Datasheet)
+PRUSS2_IN_VIRTUAL1             (Hide in Datasheet)
+PRUSS2_OUT_VIRTUAL1            (Hide in Datasheet)
+========================== QSPI ==========================
+QSPI1_VIRTUAL1                 QSPI Mode 3 Alternate Timing Mode 1
+QSPI1_VIRTUAL2                 QSPI Mode 3 Alternate Timing Mode 2
+QSPI_MODE0_MANUAL1             QSPI Mode 0 Default Timing Mode
+QSPI_MODE0_MANUAL2             QSPI Mode 0 Alternate Timing Mode 1
+QSPI_MODE0_MANUAL3             QSPI Mode 0 Alternate Timing Mode 2
+========================== GMAC ==========================
+GMAC_RMII1_MANUAL1             GMAC RMII1 Timings
+GMAC_RGMII1_MANUAL1            GMAC RGMII1 Internal Delay Enabled Timings
+GMAC_RGMII2_MANUAL1            GMAC RGMII2 Internal Delay Enabled Timings
+GMAC_RGMII1_MANUAL2            (Hide in Datasheet)
+GMAC_RGMII2_MANUAL2            (Hide in Datasheet)
+========================== MLB ==========================
+MLB_MANUAL1                    MLB 3-Pin and 6-Pin Timings
+========================== VIP ==========================
+VIP1_MANUAL1                   VIN1A/1B/2A Rise-Edge Capture Mode Timings
+VIP1_2B_MANUAL1                        VIN2B Rise-Edge Capture Mode Timings
+VIP1_MANUAL2                   VIN1A/1B/2A Fall-Edge Capture Mode Timings
+VIP1_2B_MANUAL2                        VIN2B Fall-Edge Capture Mode Timings
+VIP2_MANUAL1                   VIN3A/3B IOSET1 Rise-Edge Capture Mode Timings
+VIP2_4A_MANUAL1                        VIN4A IOSET1/2 Rise-Edge Capture Mode Timings
+VIP2_4A_IOSET3_MANUAL1         VIN4A IOSET3 Rise-Edge Capture Mode Timings
+VIP2_4B_MANUAL1                        VIN4B Rise-Edge Capture Mode Timings
+VIP2_3B_IOSET2_MANUAL1         VIN3B IOSET2 Rise-Edge Capture Mode Timings
+VIP2_3B_IOSET2_MANUAL2         VIN3B IOSET2 Fall-Edge Capture Mode Timings
+VIP2_MANUAL2                   VIN3A/3B IOSET1, VIN4A IOSET1/2 Fall-Edge Capture Mode Timings
+VIP2_4A_MANUAL2                        VIN4A IOSET1/2 Fall-Edge Capture Mode Timings
+VIP2_4A_IOSET3_MANUAL2         VIN4A IOSET3 Fall-Edge Capture Mode Timings
+VIP2_4B_MANUAL2                        VIN4B Fall-Edge Capture Mode Timings
+VIP3_MANUAL1                   VIN5A/6A Rise-Edge Capture Mode Timings
+VIP3_MANUAL2                   VIN5A/6A Fall-Edge Capture Mode Timings
diff --git a/iodelay-autogen.py b/iodelay-autogen.py
new file mode 100755 (executable)
index 0000000..695ff74
--- /dev/null
@@ -0,0 +1,321 @@
+#!/usr/bin/python
+#Python script to automatically generate the IO pad and delay data
+#Author:- Nikhil Devshatwar
+
+# This script uses regdump of the pad registers to figure out the muxmodes
+# Based on the pad and muxmode, it find out all possible virtual/manual modes
+# by referring to the PCT XML model. Using the, selection file, script
+# decides which modes to be selected. Finally it dumps the required array entries
+
+# This script depends on following files:-
+# * XML data files     - Shipped with the DRA7xx PCT tool
+# * Pad register dump  - Generate using omapconf dump 0x4a003400 0x4a00380c
+# * selection file     - List of selected virtual/manual modes to be used
+
+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"
+gdl_file = "guidelines.txt"
+
+pad_file = "ctrl-core.dump"
+sel_file = "selected-modes.txt"
+config_file = "config-iodelay-autogen"
+
+import xml.etree.ElementTree as ET
+import ConfigParser as CP
+import re
+
+pad_xml = ET.parse(pad_data_xml).getroot()
+iod_xml = ET.parse(iod_data_xml).getroot()
+model_xml = ET.parse(model_data_xml).getroot()
+config = CP.RawConfigParser()
+config.read(config_file)
+
+def read_pad_file(file):
+       regmap = {}
+       pattern = re.compile('.*(0x[0-9A-F]+).*(0x[0-9A-F]+).*')
+       f = open(file, 'r')
+       for line in f:
+               list = re.match(pattern, line)
+               if ( list == None):
+                       continue
+               addr = int(list.groups(0)[0], 16)
+               val = int(list.groups(0)[1], 16)
+               #print "PADDUMP: Addr = %08x Value = %08x" % (addr, val)
+               regmap[addr] = val
+       return regmap
+
+def pad_get_name(offset):
+       padlist = pad_xml.findall("register[@offset='0x%X']" % offset)
+       if (len(padlist) == 0):
+               return "Unknown"
+       else:
+               return padlist[0].get("id")
+
+def pad_get_pin(offset, muxmode):
+       padlist = pad_xml.findall("register[@offset='0x%X']" % offset)
+       if (len(padlist) == 0):
+               return "Unknown"
+       else:
+               mux_field = padlist[0].findall("./bitfield[@end='0']")
+               if (len(mux_field) == 0):
+                       return "Unknown"
+               modes = mux_field[0].findall("./bitenum[@value='%d']" % muxmode)
+               if (len(modes) == 0):
+                       return "Unknown"
+               return modes[0].get("id")
+
+def pad_dump_gpio(addr, offset, pin_name):
+       gpio_data_addrs = (0, 0x4ae10138, 0x48055138, 0x48057138, 0x48059138, 0x4805b138, 0x4805d138, 0x48051138, 0x48053138)
+       gpio_name = pad_get_pin(offset, 14)
+       matchlist = re.match("GPIO(.)_(.)", gpio_name)
+       if (matchlist == None):
+               return
+       inst = int(matchlist.groups(0)[0])
+       bit = int(matchlist.groups(0)[1])
+       gpio_addr = gpio_data_addrs[inst]
+       print "GPIO: echo %d > /sys/class/gpio/export 2>/dev/null; val=`omapconf read 0x%x 2>&1 | grep -v \"support\"`; status=$((0x$val >> %d & 0x1)); echo -e \"%s (%s)\t = $status\";" % ((inst - 1) * 32, gpio_addr, bit, pin_name, gpio_name)
+
+def iodelay_get_reg(name):
+       delaylist = iod_xml.findall("register[@id='%s']" % name)
+       if (len(delaylist) == 0):
+               return 0
+       else:
+               offset = delaylist[0].get("offset")
+               #print "IOD: Name = %s Offset = %s" % (del_reg, offset)
+               return int(offset, 16)
+
+def virtual_get_modes(mode):
+       list = []
+       signal = mode.findtext("signal")
+       for virt in mode.findall("virtualmode/mode"):
+               virt_mode = virt.findtext("value")
+               virt_name = virt.findtext("name")
+               if (virt_name == "NA"):
+                       continue
+               found = (virt_mode, virt_name)
+               list.append(found)
+               if (config.get("general", "dump_virtual") == "1"):
+                       print ("VIRTUAL: %s %s" % found) + " %s" % signal
+       return list
+
+def manual_get_modes(mode):
+       list = []
+       signal = mode.findtext("signal")
+       for man in mode.findall("manualmode"):
+               regname = man.findtext("cfgreg/name")
+               for sel in man.findall("cfgreg/mode"):
+                       adel = sel.findtext("adelay")
+                       gdel = sel.findtext("gdelay")
+                       man_name = sel.findtext("name")
+                       if (man_name == "NA"):
+                               continue
+                       found = (regname, adel, gdel, man_name)
+                       list.append(found)
+                       if (config.get("general", "dump_manual") == "1"):
+                               print ("MANUAL: %s %s %s %s" % found) + " %s" % signal
+       return list
+               
+
+def model_find_delaymodes(pad_name, muxmode):
+       padlist = model_xml.findall("padDB/clockNode/type/pad")
+       for pad in padlist:
+               if (pad_name == pad.findtext("confregisters/regbit/register")):
+                       muxmodes = pad.findall("muxmode")
+                       break
+       if not muxmodes:
+               return None
+       for mode in muxmodes:
+               if ("%d" % muxmode == mode.findtext("mode")):
+                       virt = virtual_get_modes(mode)
+                       man = manual_get_modes(mode)
+                       return (virt, man)
+       return None
+
+def get_pin_info(val):
+       inp_en = (val >> 18) & 0x1
+       pulltype = (val >> 17) & 0x1
+       pull_dis = (val >> 16) & 0x1
+       pin = "PIN"
+       if (inp_en):
+               pin += "_INPUT"
+       else:
+               pin += "_OUTPUT"
+       if (pull_dis == 0):
+               if (pulltype):
+                       pin += "_PULLUP"
+               else:
+                       pin += "_PULLDOWN"
+       return pin
+
+def read_guidelines(fname):
+       gdl = {}
+       pattern = re.compile('(.+\w)\t+(.+)')
+       f = open(fname)
+       for line in f.readlines():
+               list = re.match(pattern, line)
+               if ( list == None):
+                       continue
+               mode = list.groups(0)[0]
+               info = list.groups(0)[1]
+               gdl[mode] = info
+               #print "GDL: Parsed info<%s> <%s>" % ( mode, info)
+       return gdl
+
+def read_selection(fname):
+       sel = {}
+       pattern = re.compile('(\w+)\W*,\W*(\w*)')
+       f = open(fname)
+       for line in f.readlines():
+               list = re.match(pattern, line)
+               if ( list == None):
+                       continue
+               group = list.groups(0)[0]
+               mode = list.groups(0)[1]
+               sel[group] = mode
+               #print "SEL: Parsed info<%s> <%s>" % (mode, group)
+       return sel
+
+def find_selection(pad, pin, modes, gdl, sel):
+       group = re.match("([^_]+)_.*", pin).groups(0)[0]
+       if (group in sel.keys()):
+               if (sel[group] == "SKIP"):
+                       return sel[group]
+               for mode in modes:
+                       if (sel[group] == mode):
+                               #print "DBG: Found %s mode in selection for %s" % (mode, group)
+                               return mode
+
+       if (config.get("gui", "interactive") == "0"):
+               return "SKIP"
+
+       #print "\nDBG: Selected modes"
+       #print sel
+       while True:
+               print ""
+               print "MENU: Select delay mode for %s -> %s" % (pad, pin)
+               i = 0
+               print "MENU: %d: %s \t\t\t%s" % (i, "SKIP", "Skips this group for now")
+               for mode in modes:
+                       i += 1
+                       print "MENU: %d: %s \t\t%s" % (i, mode, gdl[mode])
+               try:
+                       choice = int(raw_input("Select delay mode #> "))
+                       if (choice == 0):
+                               mode = "SKIP"
+                               break
+                       elif (choice >=0 and choice <= len(modes)):
+                               mode = modes.keys()[choice - 1]
+                               break
+                       print "ERROR: Invalid choice"
+               except ValueError:
+                       print "ERROR: Invalid choice"
+       print "MENU: Selected mode is %s" % mode
+       print ""
+       return mode
+
+#Main execution starts here
+print "IOdelay autogen - Python script to generate the IOdelay data"
+print "Generate the MUX mode data based on the register dumps"
+print ""
+
+gdl = read_guidelines(gdl_file)
+sel = read_selection(sel_file)
+regmap = read_pad_file(pad_file)
+reglist = regmap.keys()
+
+pad_count = 0
+delay_count = 0
+
+for i in range(0, 281):
+       addr = 0x4a003400 + i * 4
+       offset = 0x1400 + i * 4
+       dts_offset = offset - 0x1400
+
+       if (addr not in reglist):
+               print "WARN: Register dump for pad 0x%X not found" % addr
+               continue
+       val = regmap[addr]
+       muxmode = val & 0xf
+       pad_name = pad_get_name(offset)
+       pin_name = pad_get_pin(offset, muxmode)
+       if (pad_name == "Unknown" or pin_name == "Unknown"):
+               print "ERROR: Cannot find out Pad/Pin name for PAD address 0x%X (%s[%s] = %s)" \
+               % (addr, pad_name, muxmode, pin_name)
+               continue
+       if (config.get("general", "dump_all") == "1"):
+               print "DUMP: %30s: Address = 0x%X \tOffset = 0x%X Value = 0x%08X \"%s\"" \
+               % (pad_name, addr, offset, val, pin_name)
+
+       if (config.get("general", "dump_gpio") == "1"):
+               pad_dump_gpio(addr, offset, pin_name)
+#Find out all the possible virtual, manual modes fot the specific pad -> pin combination
+       (virt, man) = model_find_delaymodes(pad_name, muxmode)
+       modes = {}
+       for option in virt:
+               (virt_mode, virt_name) = option
+               extramode = "VIRTUAL_MODE%s" % virt_mode
+               modes[virt_name] = extramode
+
+       for option in man:
+               (regname, a_del, g_del, man_name) = option
+               extramode = "MANUAL_MODE"
+               modes[man_name] = extramode
+
+#Decide the mode to be used:-
+       if (len(modes) == 0):
+               if (config.get("general", "auto_decide") == "0"):
+                       continue
+               #Use Legacy mode
+               extramode = ""
+       else:
+               #Need to select one out of allowed modes
+               mode = find_selection(pad_name, pin_name, modes, gdl, sel)
+               if (mode == "unknown"):
+                       print "ERROR: Unresolved delay modes for %s -> %s" % (pad_name, pin_name)
+                       print modes
+                       break
+
+               #Update the selection for that module
+               group = re.match("([^_]+)_.*", pin_name).groups(0)[0]
+               #print "DBG: Adding %s mode for group %s" % (mode, group)
+               if (mode != "SKIP" or  group not in sel.keys()):
+                       sel[group] = mode
+               if (mode == "SKIP"):
+                       continue
+               extramode = modes[mode]
+
+#Generate the u-boot header for PAD mux array
+       if (extramode == ""):
+               delaymode = ""
+       else:
+               delaymode = " | %s" % extramode
+       pin_info = get_pin_info(val) + delaymode
+       pad_short = re.sub("CTRL_CORE_PAD_", "", pad_name)
+       comment = (pad_short + "." + pin_name).lower()
+       print "PAD:\t{ %s, (M%d | %s) },\t/* %s */" % (pad_short, muxmode, pin_info, comment)
+       pad_count += 1
+
+#Generate the u-boot header for IO delay array
+       if (extramode != "MANUAL_MODE"):
+               continue
+       for option in man:
+               (regname, a_del, g_del, man_name) = option
+               if (man_name != mode):
+                       continue
+               del_offset = iodelay_get_reg(regname)
+               if (del_offset == 0):
+                       print "ERROR: Can't find delay offset of register %s" % regname
+                       break
+               a_del = int(a_del)
+               g_del = int(g_del)
+               print "DELAY:\t{0x%04X, %d, %d},\t/* %s */" \
+                       % (del_offset, a_del, g_del, regname)
+
+       delay_count += 1
+print ""
+print "Total PAD registers: %d, Total DELAY registers: %d" % (pad_count, delay_count)
+#Dump the final selection for reuse
+for group in sel:
+       print "%s,\t%s" % (group, sel[group])
+print ""
diff --git a/selected-modes.txt b/selected-modes.txt
new file mode 100644 (file)
index 0000000..9c8c1a2
--- /dev/null
@@ -0,0 +1,17 @@
+MMC2,   MMC2_DDR_1V8_MANUAL1
+MMC1,   MMC1_VIRTUAL6
+MCASP7, MCASP7_VIRTUAL2_SYNC_RX
+RGMII0, GMAC_RGMII1_MANUAL1
+RGMII1, GMAC_RGMII2_MANUAL1
+MMC4,   MMC4_DS_MANUAL1
+VIN5A,  VIP3_MANUAL1
+MCASP2, SKIP
+VOUT3,  VOUT3_MANUAL1
+VOUT1,  DSS_VIRTUAL1
+MCASP1, MCASP1_VIRTUAL2_SYNC_RX
+VIN6A,  VIP3_MANUAL2
+VIN2A,  VIP1_MANUAL1
+VIN1A,  VIP1_MANUAL2
+VIN3A,  VIP2_MANUAL1
+QSPI1,  SKIP
+