summaryrefslogtreecommitdiff
path: root/documentation/6.components/device-driver/pic/pic_examples.md
blob: 6ab3c78ec2f3b78cb9772d4dc2dce05768b032e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
@page page_device_pic_examples PIC platform examples

# Rockchip & Raspberry Pi DM patterns

Concrete BSP references (paths under **`rt-thread/bsp/`**).

---

## Raspberry Pi 4 — GIC root (`dm/dts/bcm2711-rpi-4-b.dts`)

```dts
gicv2: interrupt-controller@40041000 {
    compatible = "arm,gic-400";
    interrupt-controller;
    #interrupt-cells = <3>;
    reg = <0x40041000 0x1000>, <0x40042000 0x2000>;
};
```

- Probed by in-tree **`pic-gicv2.c`** during **`rt_pic_init`**
- All devices: **`interrupt-parent = <&gicv2>`** + **`GIC_SPI n type`**
- Drivers: **`rt_dm_dev_get_irq`** → virtual IRQ → **`rt_pic_attach_irq`**

PCIe **`interrupt-map`** on host points at **`&gicv2 GIC_SPI 143…`**.

---

## Raspberry Pi — BCM2835 mailbox (`dm/mailbox/mailbox-bcm2835.c`)

```c
bcm_mbox->irq = rt_dm_dev_get_irq(dev, 0);
rt_hw_interrupt_install(bcm_mbox->irq, bcm2835_mbox_isr, …);
rt_hw_interrupt_umask(bcm_mbox->irq);
```

Single interrupt line from GIC — no cascade. Shows standard DM consumer pattern.

---

## Rockchip — RK8xx PMIC IRQ (`dm/mfd/rk8xx.c`)

| Piece | Detail |
| --- | --- |
| **Root** | PMIC **`rk8xx->irq`** from SoC GPIO |
| **Child PIC** | **`rk8xx_irqchip`**, **`rt_pic_linear_irq`** |
| **Cascade** | **`rt_pic_cascade(pirq, rk8xx->irq)`** in **`rk8xx_irq_map`** |
| **Demux** | Thread reads **`status_base`** regs → **`rt_pic_handle_isr`** |
| **DT** | **`interrupts = <&rk8xx_intc 0>`** on sub-devices |

Template for **GPIO/PMIC expander** IRQ chips.

---

## Rockchip — PCIe DW INTx (`dm/pci/pcie-dw-rockchip.c`)

| Piece | Detail |
| --- | --- |
| **Child node** | **`legacy-interrupt-controller`** (OFW child) |
| **Child PIC** | **`rockchip_intx_ops`**, 4 lines (**`RT_PCI_INTX_PIN_MAX`**) |
| **`rt_ofw_data(intx_np) = &intx_pic`** | PCI **`interrupt-map`** targets this |
| **Parent ISR** | **`rockchip_pcie_legacy_isr`** on **`legacy`** GIC IRQ |
| **No `RT_PIC_F_IRQ_ROUTING`** | Software poll of legacy status register |

PCI function drivers use **`rt_pci_ofw_irq_parse_and_map`** → maps through **`intx_pic`** → GIC.

---

## Rockchip DM consumers (simple)

Many drivers only use allocated virtual IRQ:

```c
i2c->irq = rt_dm_dev_get_irq(dev, 0);
rt_pic_attach_irq(i2c->irq, handler, i2c, name, flags);
rt_pic_irq_unmask(i2c->irq);
```

Examples: **`i2c-rk3x.c`**, **`spi-rockchip.c`**, **`mailbox-rockchip.c`**.

---

## Choosing a pattern

| Hardware | Pattern | Example |
| --- | --- | --- |
| Single GIC line per device | **`get_irq` + attach** | UART, I2C |
| Aggregated status register | Child PIC + parent ISR poll | RK PCIe INTx |
| Many lines behind one pin | Child PIC + **cascade** | RK8xx PMIC |
| Message-signalled | MSI PIC + PCI | See @ref page_device_pic_msi |

---

## See also

- @ref page_device_pic_cascade
- @ref page_device_pci_ofw