From 211dfb21684d6c197df970fa6b6829858520f47d Mon Sep 17 00:00:00 2001 From: inc <87362+inc@users.noreply.github.com> Date: Fri, 10 Feb 2023 14:00:05 +0100 Subject: [PATCH] support multiple usb_ohci ports --- litex/soc/cores/usb_ohci.py | 55 +++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/litex/soc/cores/usb_ohci.py b/litex/soc/cores/usb_ohci.py index b33e95438..0e55df50b 100644 --- a/litex/soc/cores/usb_ohci.py +++ b/litex/soc/cores/usb_ohci.py @@ -3,6 +3,7 @@ # # Copyright (c) 2021 Dolu1990 # Copyright (c) 2021 Florent Kermarrec +# Copyright (c) 2023 Lone Dynamics Corporation # SPDX-License-Identifier: BSD-2-Clause import os @@ -30,10 +31,15 @@ class USBOHCI(Module): # # # - usb_ios = Record([ - ("dp_i", 1), ("dp_o", 1), ("dp_oe", 1), - ("dm_i", 1), ("dm_o", 1), ("dm_oe", 1), - ]) + pn = len(pads.dp) + + usb_ios = {} + + for i in range(len(pads.dp)): + usb_ios[i] = Record([ + ("dp_i", 1), ("dp_o", 1), ("dp_oe", 1), + ("dm_i", 1), ("dm_o", 1), ("dm_oe", 1), + ]) self.specials += Instance(self.get_netlist_name(), # Clk / Rst. @@ -69,26 +75,29 @@ class USBOHCI(Module): o_io_interrupt = self.interrupt, # USB - i_io_usb_0_dp_read = usb_ios.dp_i, - o_io_usb_0_dp_write = usb_ios.dp_o, - o_io_usb_0_dp_writeEnable = usb_ios.dp_oe, - i_io_usb_0_dm_read = usb_ios.dm_i, - o_io_usb_0_dm_write = usb_ios.dm_o, - o_io_usb_0_dm_writeEnable = usb_ios.dm_oe, - ) - self.specials += SDRTristate( - io = pads.dp, - o = usb_ios.dp_o, - oe = usb_ios.dp_oe, - i = usb_ios.dp_i, - ) - self.specials += SDRTristate( - io = pads.dm, - o = usb_ios.dm_o, - oe = usb_ios.dm_oe, - i = usb_ios.dm_i, + **{f"i_io_usb_{n}_dp_read": usb_ios[n].dp_i for n in range(pn)}, + **{f"o_io_usb_{n}_dp_write": usb_ios[n].dp_o for n in range(pn)}, + **{f"o_io_usb_{n}_dp_writeEnable": usb_ios[n].dp_oe for n in range(pn)}, + **{f"i_io_usb_{n}_dm_read": usb_ios[n].dm_i for n in range(pn)}, + **{f"o_io_usb_{n}_dm_write": usb_ios[n].dm_o for n in range(pn)}, + **{f"o_io_usb_{n}_dm_writeEnable": usb_ios[n].dm_oe for n in range(pn)}, + ) + for i in range(pn): + self.specials += SDRTristate( + io = pads.dp[i], + o = usb_ios[i].dp_o, + oe = usb_ios[i].dp_oe, + i = usb_ios[i].dp_i, + ) + self.specials += SDRTristate( + io = pads.dm[i], + o = usb_ios[i].dm_o, + oe = usb_ios[i].dm_oe, + i = usb_ios[i].dm_i, + ) + self.add_sources(platform) def get_netlist_name(self): @@ -117,7 +126,7 @@ class USBOHCI(Module): gen_args.append(f"--netlist-name={self.get_netlist_name()}") gen_args.append(f"--netlist-directory={vdir}") - cmd = 'cd {path} && sbt "lib/runMain spinal.lib.com.usb.ohci.UsbOhciWishbone {args}"'.format( + cmd = 'cd {path} && sbt "runMain spinal.lib.com.usb.ohci.UsbOhciWishbone {args}"'.format( path=os.path.join(vdir, "ext", "SpinalHDL"), args=" ".join(gen_args)) print("!!! " + cmd) if os.system(cmd) != 0: