BCM2708: Add core Device Tree support
[platform/kernel/linux-rpi.git] / arch / arm / boot / dts / overlays / pifacedigital-overlay.dts
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * PiFace Digital, Device Tree Overlay.
4  * Copyright (C) 2020 Thomas Preston <thomas.preston@codethink.co.uk>
5  *
6  * The PiFace Digital is a convenient breakout board for the Microchip mcp23s17
7  * SPI GPIO port expander.
8  *
9  * The first eight GPIOs 0..7 (bank A) are connected to eight output terminals
10  * and LEDs, plus two relays on the first two outputs. These output loads are
11  * active-high.
12  *
13  * The next eight GPIOs 8..15 (bank B) are connected to eight input terminals
14  * with four on-board switches connecting them to ground. Inputs devices are
15  * therefore expected to bridge terminals to ground, so the mcp23s17 pullups are
16  * activated for GPIO bank B.
17  *
18  * On PiFace Digital, the mcp23s17 is connected to the Raspberry Pi's SPI0 CS0
19  * bus. Each SPI bus supports up to eight addressable child devices. The PiFace
20  * Digital only supports addresses 0-4, which can be configured by jumpers JP1
21  * and JP2.
22  *
23  * You can tell the driver about these jumper configurations with the
24  * spi-present-mask bitmask:
25  *
26  *     | JP1 | JP2 | dtoverlay line in /boot/config.txt         |
27  *     | --- | --- | ------------------------------------------ |
28  *     |  0  |  0  | dtoverlay=pifacedigital                    |
29  *     |  0  |  0  | dtoverlay=pifacedigital:spi-present-mask=1 |
30  *     |  0  |  1  | dtoverlay=pifacedigital:spi-present-mask=2 |
31  *     |  1  |  0  | dtoverlay=pifacedigital:spi-present-mask=4 |
32  *     |  1  |  1  | dtoverlay=pifacedigital:spi-present-mask=8 |
33  *
34  * # Example
35  * Set the dtoverlay config in /boot/config.txt and power off the Raspberry Pi:
36  *
37  *     $ grep pifacedigital /boot/config.txt
38  *     dtoverlay=pifacedigital
39  *     $ sudo systemctl poweroff
40  *
41  * Attach the PiFace Digital and power on the Raspberry Pi.
42  * Then use the libgpiod tools to query the device:
43  *
44  *     $ sudo apt install gpiod
45  *     $ gpiodetect | grep mcp23s17
46  *     gpiochip2 [mcp23s17.0] (16 lines)
47  *
48  * Set GPIO outputs 0, 2 and 5:
49  *
50  *     $ gpioset gpiochip2 0=1 2=1 5=1
51  *
52  * Get GPIO status (input GPIO 8..15 are high, because they are active-low):
53  *
54  *     $ gpioget gpiochip2 {8..15}
55  *     1 1 1 1 1 1 1 1
56  *
57  * And even monitor interrupts:
58  *
59  *     $ gpiomon gpiochip2 {8..15}
60  *     event: FALLING EDGE offset: 11 timestamp: [1597361662.926741667]
61  *     event:  RISING EDGE offset: 11 timestamp: [1597361663.062555051]
62  *
63  */
64
65 /dts-v1/;
66 /plugin/;
67
68 / {
69         compatible = "brcm,bcm2835";
70
71         /* Disable exposing /dev/spidev0.0 */
72         fragment@0 {
73                 target = <&spidev0>;
74                 __overlay__ {
75                         status = "disabled";
76                 };
77         };
78
79         /* Add the PiFace Digital device node to the spi0.0 device. */
80         fragment@1 {
81                 target = <&spi0>;
82                 __overlay__ {
83                         status = "okay";
84                         #address-cells = <1>;
85                         #size-cells = <0>;
86
87                         pfdigital: pifacedigital@0 {
88                                 compatible = "microchip,mcp23s17";
89                                 reg = <0>;
90
91                                 /* Set devices present with 8-bit mask. */
92                                 microchip,spi-present-mask = <0x01>;
93                                 spi-max-frequency = <500000>;
94
95                                 gpio-controller;
96                                 #gpio-cells = <2>;
97
98                                 /* This device can pass through interrupts. */
99                                 interrupt-controller;
100                                 #interrupt-cells = <2>;
101
102                                 /* INTB is connected to GPIO 25.
103                                  * 0x8 active-low level-sensitive
104                                  */
105                                 interrupts = <25 0x8>;
106                                 interrupt-parent = <&gpio>;
107
108                                 /* Configure pull-ups on bank B GPIOs */
109                                 pinctrl-0 = <&pfdigital_irq &pfdigital_pullups>;
110                                 pinctrl-names = "default";
111                                 pfdigital_pullups: pinmux {
112                                         pins =
113                                                 "gpio8",
114                                                 "gpio9",
115                                                 "gpio10",
116                                                 "gpio11",
117                                                 "gpio12",
118                                                 "gpio13",
119                                                 "gpio14",
120                                                 "gpio15";
121                                         bias-pull-up;
122                                 };
123                         };
124                 };
125         };
126
127         /* PiFace Digital mcp23s17 INTB pin is connected to GPIO 25. The INTB
128          * pin is configured active-low (0 on interrupt), so expect to see
129          * FALLING_EDGE when inputs are bridged to ground (switch is pressed).
130          */
131         fragment@3 {
132                 target = <&gpio>;
133                 __overlay__ {
134                         pfdigital_irq: pifacedigital_irq {
135                                 brcm,pins = <25>;
136                                 brcm,function = <0>; /* input */
137                         };
138                 };
139         };
140
141         __overrides__ {
142                 spi-present-mask = <&pfdigital>, "microchip,spi-present-mask:0";
143         };
144 };