1 // SPDX-License-Identifier: GPL-2.0-only
3 * PiFace Digital, Device Tree Overlay.
4 * Copyright (C) 2020 Thomas Preston <thomas.preston@codethink.co.uk>
6 * The PiFace Digital is a convenient breakout board for the Microchip mcp23s17
7 * SPI GPIO port expander.
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
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.
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
23 * You can tell the driver about these jumper configurations with the
24 * spi-present-mask bitmask:
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 |
35 * Set the dtoverlay config in /boot/config.txt and power off the Raspberry Pi:
37 * $ grep pifacedigital /boot/config.txt
38 * dtoverlay=pifacedigital
39 * $ sudo systemctl poweroff
41 * Attach the PiFace Digital and power on the Raspberry Pi.
42 * Then use the libgpiod tools to query the device:
44 * $ sudo apt install gpiod
45 * $ gpiodetect | grep mcp23s17
46 * gpiochip2 [mcp23s17.0] (16 lines)
48 * Set GPIO outputs 0, 2 and 5:
50 * $ gpioset gpiochip2 0=1 2=1 5=1
52 * Get GPIO status (input GPIO 8..15 are high, because they are active-low):
54 * $ gpioget gpiochip2 {8..15}
57 * And even monitor interrupts:
59 * $ gpiomon gpiochip2 {8..15}
60 * event: FALLING EDGE offset: 11 timestamp: [1597361662.926741667]
61 * event: RISING EDGE offset: 11 timestamp: [1597361663.062555051]
69 compatible = "brcm,bcm2835";
71 /* Disable exposing /dev/spidev0.0 */
79 /* Add the PiFace Digital device node to the spi0.0 device. */
87 pfdigital: pifacedigital@0 {
88 compatible = "microchip,mcp23s17";
91 /* Set devices present with 8-bit mask. */
92 microchip,spi-present-mask = <0x01>;
93 spi-max-frequency = <500000>;
98 /* This device can pass through interrupts. */
100 #interrupt-cells = <2>;
102 /* INTB is connected to GPIO 25.
103 * 0x8 active-low level-sensitive
105 interrupts = <25 0x8>;
106 interrupt-parent = <&gpio>;
108 /* Configure pull-ups on bank B GPIOs */
109 pinctrl-0 = <&pfdigital_irq &pfdigital_pullups>;
110 pinctrl-names = "default";
111 pfdigital_pullups: pinmux {
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).
134 pfdigital_irq: pifacedigital_irq {
136 brcm,function = <0>; /* input */
142 spi-present-mask = <&pfdigital>, "microchip,spi-present-mask:0";