Skip to content

Commit ac4119a

Browse files
ikerexxepopcornmix
authored andcommitted
dtoverlays: enable SPI CS active-high
The documentation isn't very clear explaining how to enable SPI CS active-high and it takes a long time to understand it. Adding a specific overlay as a simple example on how to invert this signal can help understand the solution. Link: https://forums.raspberrypi.com/viewtopic.php?t=378222 Signed-off-by: Iker Pedrosa <ikerpedrosam@gmail.com>
1 parent 3f1911e commit ac4119a

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

arch/arm/boot/dts/overlays/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ dtbo-$(CONFIG_ARCH_BCM2835) += \
260260
spi-rtc.dtbo \
261261
spi0-0cs.dtbo \
262262
spi0-1cs.dtbo \
263+
spi0-1cs-inverted.dtbo \
263264
spi0-2cs.dtbo \
264265
spi1-1cs.dtbo \
265266
spi1-2cs.dtbo \

arch/arm/boot/dts/overlays/README

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4472,6 +4472,14 @@ Params: cs0_pin GPIO pin for CS0 (default 8)
44724472
it for other uses.
44734473

44744474

4475+
Name: spi0-1cs-inverted
4476+
Info: Only use one CS pin for SPI0 and set to active-high
4477+
Load: dtoverlay=spi0-1cs-inverted,<param>=<val>
4478+
Params: cs0_pin GPIO pin for CS0 (default 8)
4479+
no_miso Don't claim and use the MISO pin (9), freeing
4480+
it for other uses.
4481+
4482+
44754483
Name: spi0-2cs
44764484
Info: Change the CS pins for SPI0
44774485
Load: dtoverlay=spi0-2cs,<param>=<val>
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/dts-v1/;
2+
/plugin/;
3+
4+
/*
5+
* There are some devices that need an inverted Chip Select (CS) to select the
6+
* device signal, as an example the AZDelivery 12864 display. That means that
7+
* the CS polarity is active-high. To invert the CS signal the DT needs to set
8+
* the cs-gpio to GPIO_ACTIVE_HIGH (0) in the controller and set the
9+
* spi-cs-high in the peripheral property. On top of that, since this is a
10+
* display the DT also needs to specify the write-only property.
11+
*/
12+
13+
#include <dt-bindings/gpio/gpio.h>
14+
15+
/ {
16+
compatible = "brcm,bcm2835";
17+
18+
fragment@0 {
19+
target = <&spi0_cs_pins>;
20+
frag0: __overlay__ {
21+
brcm,pins = <8>;
22+
};
23+
};
24+
25+
fragment@1 {
26+
target = <&spi0>;
27+
frag1: __overlay__ {
28+
cs-gpios = <&gpio 8 GPIO_ACTIVE_HIGH>;
29+
status = "okay";
30+
};
31+
};
32+
33+
fragment@2 {
34+
target = <&spidev1>;
35+
__overlay__ {
36+
status = "disabled";
37+
};
38+
};
39+
40+
fragment@3 {
41+
target = <&spi0_pins>;
42+
__dormant__ {
43+
brcm,pins = <10 11>;
44+
};
45+
};
46+
47+
fragment@4 {
48+
target = <&spidev0>;
49+
__overlay__ {
50+
spi-cs-high;
51+
};
52+
};
53+
54+
__overrides__ {
55+
cs0_pin = <&frag0>,"brcm,pins:0",
56+
<&frag1>,"cs-gpios:4";
57+
no_miso = <0>,"=3";
58+
};
59+
};

0 commit comments

Comments
 (0)