dts: gpio: interrupt controller definition for switches

This commit adds support for enabling interupts in switches module.
Declaring switches as GPIOIn module with with_irq=True
will make dts generation add correct interrupt controller definition.
Also, if SWITCHES_NGPIO constant is defined it will be used to
specify correct number of gpios in dts.

example:
self.submodules.switches = GPIOIn(pads=switches_pads, with_irq=True)
self.add_csr("switches")
self.irq.add("switches", use_loc_if_exists=True)
self.add_constant("SWITCHES_NGPIO", len(switches_pads))
This commit is contained in:
Marek Czerski 2021-03-04 00:58:29 +01:00
parent 04cb8e0e5e
commit d7c0b4c111
1 changed files with 22 additions and 10 deletions

View File

@ -28,7 +28,6 @@ def generate_dts(d, initrd_start=None, initrd_size=None, polling=False):
/ { / {
#address-cells = <1>; #address-cells = <1>;
#size-cells = <1>; #size-cells = <1>;
interrupt-parent = <&intc0>;
""" """
@ -185,6 +184,7 @@ def generate_dts(d, initrd_start=None, initrd_size=None, polling=False):
device_type = "serial"; device_type = "serial";
compatible = "litex,liteuart"; compatible = "litex,liteuart";
reg = <0x{uart_csr_base:x} 0x100>; reg = <0x{uart_csr_base:x} 0x100>;
interrupt-parent = <&intc0>;
{uart_interrupt} {uart_interrupt}
status = "okay"; status = "okay";
}}; }};
@ -203,6 +203,7 @@ def generate_dts(d, initrd_start=None, initrd_size=None, polling=False):
<0x{ethmac_mem_base:x} 0x2000>; <0x{ethmac_mem_base:x} 0x2000>;
tx-fifo-depth = <{ethmac_tx_slots}>; tx-fifo-depth = <{ethmac_tx_slots}>;
rx-fifo-depth = <{ethmac_rx_slots}>; rx-fifo-depth = <{ethmac_rx_slots}>;
interrupt-parent = <&intc0>;
{ethmac_interrupt} {ethmac_interrupt}
status = "okay"; status = "okay";
}}; }};
@ -309,14 +310,25 @@ def generate_dts(d, initrd_start=None, initrd_size=None, polling=False):
# Switches ------------------------------------------------------------------------------------- # Switches -------------------------------------------------------------------------------------
if "switches" in d["csr_bases"]: if "switches" in d["csr_bases"]:
interrupt_specification = ""
if "switches_interrupt" in d["constants"]:
switches_interrupt = d["constants"]["switches_interrupt"]
interrupt_specification = """
interrupt-controller;
#interrupt-cells = <2>;
interrupt-parent = <&intc0>;
interrupts = <{switches_interrupt}>;""".format(switches_interrupt=switches_interrupt)
dts += """ dts += """
switches: gpio@{switches_csr_base:x} {{ switches: gpio@{switches_csr_base:x} {{
compatible = "litex,gpio"; compatible = "litex,gpio";
reg = <0x{switches_csr_base:x} 0x4>; reg = <0x{switches_csr_base:x} 0x4>;
litex,direction = "in"; litex,direction = "in";
gpio-controller;
#gpio-cells = <2>;{interrupt_specification}
status = "disabled"; status = "disabled";
}}; }};
""".format(switches_csr_base=d["csr_bases"]["switches"]) """.format(switches_csr_base=d["csr_bases"]["switches"], interrupt_specification=interrupt_specification)
# SPI ------------------------------------------------------------------------------------------ # SPI ------------------------------------------------------------------------------------------
@ -534,19 +546,19 @@ def generate_dts(d, initrd_start=None, initrd_size=None, polling=False):
if "leds" in d["csr_bases"]: if "leds" in d["csr_bases"]:
dts += """ dts += """
&leds { &leds {{
litex,ngpio = <4>; litex,ngpio = <{ngpio}>;
status = "okay"; status = "okay";
}; }};
""" """.format(ngpio=d["constants"].get('leds_ngpio', 4))
if "switches" in d["csr_bases"]: if "switches" in d["csr_bases"]:
dts += """ dts += """
&switches { &switches {{
litex,ngpio = <4>; litex,ngpio = <{ngpio}>;
status = "okay"; status = "okay";
}; }};
""" """.format(ngpio=d["constants"].get('switches_ngpio', 4))
return dts return dts