Module 14 · Lesson 16 of 92

Wiring interrupts and clocks

Decode GIC interrupt specifiers and connect a peripheral to the clock and reset resources defined by its device tree bindings.

  • Beginner to advanced
  • 9 min read
  • 12 min lab
What you will need

Ubuntu 24.04 in WSL2 or a VM for the written exercises. The examples use Raspberry Pi 4 hardware, and the exercises require no board.

Your place in the module
By the end you can 4 objectives
  • Identify the interrupt controller and specifier width for a peripheral.
  • Translate classic GIC SPI and PPI specifiers into hardware interrupt IDs.
  • Match clock and reset specifiers to their providers and consumer input names.
  • Interpret the target, parent, and rate entries in an assigned clock configuration.
Video coming soonWiring interrupts and clocks
The video for this lesson is being recorded. Read the lesson below in the meantime.
Recall first from Addressing and overriding nodes
  • The immediate parent defines the address and length widths of a child's reg entries.
  • A ranges entry maps a child bus window into its parent's address space.
  • Setting status to okay makes the existing node available to Linux.
01

Connect the interrupt to its controller

4 min read

A node that is enabled still needs its interrupts and clocks pointed at the right controllers. This lesson answers how interrupt-parent and the clock properties wire a peripheral into the GIC and the clock controller.

On Raspberry Pi 4, the BCM2711 device tree describes the first PL011 UART with interrupts = <GIC_SPI 121 IRQ_TYPE_LEVEL_HIGH>;. An engineer comparing that line with the GIC hardware interrupt ID would look for 153. Both numbers describe the same UART interrupt. The kernel's IRQ domain documentation explains why Linux also has a separate IRQ number for the driver.

Read the interrupts property together with its effective interrupt-parent. When a device has an explicit interrupt-parent = <&gicv2>;, that phandle selects the node labeled gicv2. The property can also be supplied by an ancestor. In the Raspberry Pi 4 tree (bcm2711.dtsi), the root node sets interrupt-parent = <&gicv2>;, so a UART below it can have an interrupts property without repeating the phandle. When reviewing a node, find the effective parent before interpreting any of the numbers. A board device whose interrupt pin connects to a GPIO controller uses that controller's binding for the first hop. The GPIO controller can have its own upstream interrupt connection.

The provider declares interrupt-controller; to identify itself as an interrupt controller. Its #interrupt-cells property gives the number of cells in each interrupt specifier. In the Raspberry Pi 4 GIC binding, the width is three. The cells give the interrupt class, the number within that class, and flags. GIC_SPI expands to 0 and GIC_PPI expands to 1. The flags describe the trigger and polarity, such as IRQ_TYPE_LEVEL_HIGH for a source that signals by holding the line high. Use the trigger required by the hardware and allowed by the controller binding. With an ordinary interrupts list and a three-cell parent, six cells describe two interrupts. Each entry uses the same parent.

Raspberry Pi 4 UART interrupt mappingDT SPIindex121GIChardware ID121 + 32 =153Linux IRQmapped byIRQ domainDT SPIindex121GIChardware ID121 + 32 =153Linux IRQmapped byIRQ domain
The Raspberry Pi 4 UART's device tree specifier translates to GIC hardware interrupt ID 153 and then to a Linux IRQ.

An SPI is a Shared Peripheral Interrupt. It is a GIC interrupt source that can be routed to a CPU and is commonly used for an on-chip peripheral such as this UART. The classic GIC binding numbers SPIs from zero relative to the SPI range. GIC hardware IDs for that range start at 32. To translate an SPI specifier into the GIC hardware interrupt ID, add 32. For the UART, 121 + 32 gives 153. If a manual gives the GIC hardware ID as 153, subtract 32 to get the device tree SPI number 121. If a table gives the SPI index directly, use that index as written. Read the column heading and the numbering convention before doing the arithmetic.

A PPI is a Private Peripheral Interrupt. Each CPU has a local instance, as with the Arm architectural timer. The classic binding numbers PPIs from zero relative to hardware ID 16. PPI numbers therefore run from 0 through 15 in the binding. The Arm architectural timer on Raspberry Pi 4 lists four PPIs in bcm2711.dtsi: 13, 14, 11 and 10. PPI 13 (the first entry, the secure physical timer) gives GIC hardware ID 29. The class cell determines which offset to use. Copy the flags from the matching SoC description when the wiring is fixed. The class and number specify the input, and the flags carry separate information about how that input is used.

After interpreting the specifier, the GIC's Linux IRQ domain maps the controller-local hardware interrupt ID, often called a hwirq, to a Linux IRQ number. The driver uses that Linux number when it requests the interrupt. In /proc/interrupts, the number to the left of the colon on a device interrupt row is the Linux IRQ number. The Linux assignment can differ across systems and configurations. When using the Raspberry Pi 4 UART as a reference, read 121 as the device tree SPI index and 153 as the GIC hardware ID. Obtain the Linux IRQ from the running kernel when you need to identify the registered handler.

02

Match clock and reset inputs to providers

3 min read

A peripheral's clocks property lists the clock signals it consumes. Each entry starts with a phandle to a clock provider. The provider's #clock-cells value tells Linux how many argument cells follow that phandle. The clock provider binding defines what those cells mean. A provider with #clock-cells = <1>; can use that argument as an output ID. A single-output fixed clock commonly has #clock-cells = <0>;, so its specifier contains only a phandle. Read each entry using the width of the provider it references.

Here are the clock properties for the first PL011 UART in the Raspberry Pi 4's inherited SoC description. The fragment uses the clocks label and ID definitions already available in that description.

dts
clocks = <&clocks BCM2835_CLOCK_UART>,
         <&clocks BCM2835_CLOCK_VPU>;
clock-names = "uartclk", "apb_pclk";

Both entries reference the same clock provider. The first selects the controller's UART clock output, which supplies the UART's functional clock. The second selects its VPU clock output for the UART's APB interface. The position in clock-names associates "uartclk" with the first entry and "apb_pclk" with the second. The PL011 binding tells you what the peripheral calls its inputs. The clock controller binding and its ID definitions tell you how to select the corresponding outputs. BCM2835_CLOCK_UART is an output selector. The frequency of that output is determined by the clock's configuration.

Clock connections for the first PL011 UARTFirst entrySecond entryProvider&clocks&clocksOutput IDBCM2835_CLOCK_UARTBCM2835_CLOCK_VPUInput nameuartclkapb_pclk
A clock specifier identifies a provider output, and the matching name identifies the peripheral input.

Read the two lists side by side when an inherited node has multiple inputs. Swapping the two specifiers while keeping the names in place would associate each name with the other output. Each ID could still be valid for the provider, so a successful lookup would only tell you that both clocks exist. Confirm which output feeds each input from the SoC description or clock tree. When a board has an external reference source, the schematic can identify the physical clock connection. For a clock supplied within BCM2711, follow the SoC clock tree and the existing device tree. The UART and VPU connections are internal to the chip.

Reset references follow the same pattern of phandle plus provider-specific arguments. A peripheral's resets list points to reset controls. Each provider declares #reset-cells, and its binding defines the arguments. If the peripheral binding specifies reset-names, those names correspond by position to entries in resets. Linux can use the reference to obtain a reset control so the driver can assert or deassert it as needed. A clock supplies timing, while an asserted reset can hold the peripheral in its reset state. A device that requires both resources can have valid clock references and still be held in reset.

The clock and reset providers can be the same node if its binding supplies both kinds of resource, or they can be separate nodes. In either case, decode clocks with #clock-cells and the clock binding, and decode resets with #reset-cells and the reset binding. The shared controller label, if there is one, says where to look up each selector. The property says which kind of resource to look up. Keep the inherited clock and reset connections for fixed SoC hardware unless you have evidence of a different connection. Add reset properties when the peripheral binding describes a reset input and the board or SoC description identifies its provider.

03

Set initial clock parents and rates

3 min read

The UART fragment identifies the source of each clock input. A board description can also request initial settings for a clock. The assigned-clocks property lists the clocks to configure. assigned-clock-parents supplies the desired parent clock for each corresponding target, and assigned-clock-rates supplies its desired rate in hertz. The entries in assigned-clocks and the nonzero entries in assigned-clock-parents are clock specifiers. A target and its proposed parent each identify a provider output according to that provider's clock binding. The provider must support the requested parent selection and rate.

Clock assignments match by positionFirstpositionSecondpositionassigned-clocksFirst targetSecond targetassigned-clock-parents0Desiredparentassigned-clock-ratesDesired rate0
Each position in assigned-clocks identifies the clock whose initial parent or rate the corresponding entries describe.

Follow the positions in these properties in the same order. If you want to set the rate of the first target and the parent of the second target, the first parent entry is <0> and the second parent entry is the desired parent specifier. In assigned-clock-rates, put the requested rate for the first target in the first position. Use a zero for the second target's rate if you include that position. A zero entry skips the corresponding setting, and trailing skipped entries can be omitted. Retain a zero in the middle when a later target has a setting. Removing that placeholder shifts the later setting to the wrong clock. A missing companion property leaves that kind of setting unspecified for every target.

Use clocks and clock-names to describe the inputs the driver will acquire, even when a peripheral node also contains clock assignments. The assignment identifies a clock to configure. The consumer reference identifies the clock used by a peripheral input. A node can refer to the same clock in both lists because the properties serve different purposes. An assignment also leaves runtime clock management to the relevant drivers. A driver can enable or disable a clock as needed and may request another rate later if the hardware and clock framework allow it.

Before placing an assignment in a peripheral node, check who uses the target clock. Consumer-node parent and rate assignments are for clocks with a single user. If a shared clock needs an initial setting, the clock provider node can hold that configuration. Multiple consumers with conflicting assignments for a shared clock describe incompatible settings for the same hardware. Confirm that the controller can derive the requested rate from a supported parent and that the board or peripheral actually requires that initial configuration. The numbers in a clock ID header tell you which output to select. The clock tree and the device's timing requirements tell you which rate to request.

When you review a peripheral node, trace its interrupt to the controller that receives it and check the numbering convention before converting the ID. For each clock or reset entry, check the provider, its selector, and the consumer input that the binding expects. For an assignment, read the target and its settings by position, then check whether the target is shared. Common board nodes and naming rules, the next lesson, takes those connections into the rest of the board description and explains how to name the nodes that carry them.

Key takeaways

  • The interrupt parent determines how Linux interprets each interrupts entry.
  • The classic GIC binding uses class-relative numbers that Linux translates into GIC hardware interrupt IDs.
  • Clock and reset specifiers identify resources in the namespaces of their respective providers.
  • Assigned clock properties set initial parent and rate choices for selected clocks.
Reflect
  1. Explain to a colleague, in two sentences: identify the interrupt controller and specifier width for a peripheral.
  2. Which objective are you least sure about? Re-read that section, then do its exercise in the practice pack.
  3. What surprised you when you ran the commands yourself?
On a real board

Repeat the key commands on your Raspberry Pi or lab board over SSH or the serial console. Note anything that behaves differently from your PC, such as missing tools, a BusyBox shell or a read-only filesystem.

References and further reading

Find your next step

↑ ↓ to move · Enter to open · Esc to close