enable/disable litex irqs based on variant name
[soc.git] / src / soc / litex / florent / libresoc / core.py
index df44741a586e6188e784fc0db88f101098b758da..3bc76798f64cc170f5672336e17c9169bb774920 100644 (file)
@@ -5,8 +5,11 @@ from migen import ClockSignal, ResetSignal, Signal, Instance, Cat
 from litex.soc.interconnect import wishbone as wb
 from litex.soc.cores.cpu import CPU
 
+from soc.config.pinouts import get_pinspecs
+from soc.debug.jtag import Pins
+from c4m.nmigen.jtag.tap import IOType
 
-from libresoc.ls180io import make_uart, make_gpio
+from libresoc.ls180 import io
 from litex.build.generic_platform import ConstraintManager
 
 
@@ -32,6 +35,85 @@ def make_wb_slave(prefix, obj):
         res['o_%s__%s' % (prefix, o)] = getattr(obj, o)
     return res
 
+def make_pad(res, dirn, name, suffix, cpup, iop):
+    cpud, iod = ('i', 'o') if dirn else ('o', 'i')
+    res['%s_%s__core__%s' % (cpud, name, suffix)] = cpup
+    res['%s_%s__pad__%s' % (iod, name, suffix)] = iop
+
+def get_field(rec, name):
+    for f in rec.layout:
+        f = f[0]
+        if f.endswith(name):
+            return getattr(rec, f)
+
+
+def make_jtag_ioconn(res, pin, cpupads, iopads):
+    (fn, pin, iotype, pin_name, scan_idx) = pin
+    #serial_tx__core__o, serial_rx__pad__i,
+    # special-case sdram_clock
+    if pin == 'clock' and fn == 'sdr':
+        cpu = cpupads['sdram_clock']
+        io = iopads['sdram_clock']
+    else:
+        cpu = cpupads[fn]
+        io = iopads[fn]
+    print ("cpupads", cpupads)
+    print ("iopads", iopads)
+    print ("pin", fn, pin, iotype, pin_name)
+    print ("cpu fn", cpu)
+    print ("io fn", io)
+    name = "%s_%s" % (fn, pin)
+    print ("name", name)
+    sigs = []
+
+    if iotype in (IOType.In, IOType.Out):
+        ps = pin.split("_")
+        if pin == 'clock' and fn == 'sdr':
+            cpup = cpu
+            iop = io
+        elif len(ps) == 2 and ps[-1].isdigit():
+            pin, idx = ps
+            idx = int(idx)
+            cpup = getattr(cpu, pin)[idx]
+            iop = getattr(io, pin)[idx]
+        elif pin.isdigit():
+            idx = int(pin)
+            cpup = cpu[idx]
+            iop = io[idx]
+        else:
+            cpup = getattr(cpu, pin)
+            iop = getattr(io, pin)
+
+    if iotype == IOType.Out:
+        # output from the pad is routed through C4M JTAG and so
+        # is an *INPUT* into core.  ls180soc connects this to "real" peripheral
+        make_pad(res, True, name, "o", cpup, iop)
+
+    elif iotype == IOType.In:
+        # input to the pad is routed through C4M JTAG and so
+        # is an *OUTPUT* into core.  ls180soc connects this to "real" peripheral
+        make_pad(res, False, name, "i", cpup, iop)
+
+    elif iotype == IOType.InTriOut:
+        if fn == 'gpio': # sigh decode GPIO special-case
+            idx = int(pin[1:])
+        else:
+            idx = 0
+        cpup, iop = get_field(cpu, "i")[idx], get_field(io, "i")[idx]
+        make_pad(res, False, name, "i", cpup, iop)
+        cpup, iop = get_field(cpu, "o")[idx], get_field(io, "o")[idx]
+        make_pad(res, True, name, "o", cpup, iop)
+        cpup, iop = get_field(cpu, "oe")[idx], get_field(io, "oe")[idx]
+        make_pad(res, True, name, "oe", cpup, iop)
+
+    if iotype in (IOType.In, IOType.InTriOut):
+        sigs.append(("i", 1))
+    if iotype in (IOType.Out, IOType.TriOut, IOType.InTriOut):
+        sigs.append(("o", 1))
+    if iotype in (IOType.TriOut, IOType.InTriOut):
+        sigs.append(("oe", 1))
+
+
 class LibreSoC(CPU):
     name                 = "libre_soc"
     human_name           = "Libre-SoC"
@@ -66,7 +148,10 @@ class LibreSoC(CPU):
         self.platform     = platform
         self.variant      = variant
         self.reset        = Signal()
-        self.interrupt    = Signal(16)
+        irq_en = "noirq" not in variant
+
+        if irq_en:
+            self.interrupt    = Signal(16)
 
         if variant == "standard32":
             self.data_width           = 32
@@ -118,11 +203,12 @@ class LibreSoC(CPU):
             o_memerr_o         = Signal(),   # not connected
             o_pc_o             = Signal(64), # not connected
 
-            # interrupts
-            i_int_level_i      = self.interrupt,
-
         )
 
+        if irq_en:
+            # interrupts
+            self.cpu_params['i_int_level_i'] = self.interrupt
+
         if jtag_en:
             self.cpu_params.update(dict(
                 # JTAG Debug bus
@@ -159,6 +245,48 @@ class LibreSoC(CPU):
         if jtag_en:
             self.cpu_params.update(make_wb_bus("jtag_wb", jtag_wb, simple=True))
 
+        if variant == 'ls180':
+            # urr yuk.  have to expose iopads / pins from core to litex
+            # then back again.  cut _some_ of that out by connecting
+            self.padresources = io()
+            self.pad_cm = ConstraintManager(self.padresources, [])
+            self.cpupads = {}
+            iopads = {}
+            litexmap = {}
+            subset = {'uart', 'mtwi', 'eint', 'gpio', 'mspi0', 'mspi1',
+                      'pwm', 'sd0', 'sdr'}
+            for periph in subset:
+                origperiph = periph
+                num = None
+                if periph[-1].isdigit():
+                    periph, num = periph[:-1], int(periph[-1])
+                print ("periph request", periph, num)
+                if periph == 'mspi':
+                    if num == 0:
+                        periph, num = 'spimaster', None
+                    else:
+                        periph, num = 'spisdcard', None
+                elif periph == 'sdr':
+                    periph = 'sdram'
+                elif periph == 'mtwi':
+                    periph = 'i2c'
+                elif periph == 'sd':
+                    periph, num = 'sdcard', None
+                litexmap[origperiph] = (periph, num)
+                self.cpupads[origperiph] = platform.request(periph, num)
+                iopads[origperiph] = self.pad_cm.request(periph, num)
+                if periph == 'sdram':
+                    # special-case sdram clock
+                    ck = platform.request("sdram_clock")
+                    self.cpupads['sdram_clock'] = ck
+                    ck = self.pad_cm.request("sdram_clock")
+                    iopads['sdram_clock'] = ck
+
+            pinset = get_pinspecs(subset=subset)
+            p = Pins(pinset)
+            for pin in list(p):
+                make_jtag_ioconn(self.cpu_params, pin, self.cpupads, iopads)
+
         # add verilog sources
         self.add_sources(platform)