Skip to content
This repository was archived by the owner on Feb 14, 2025. It is now read-only.

Commit e4f6ba3

Browse files
committed
gpio power off
1 parent cbe0cfa commit e4f6ba3

File tree

4 files changed

+115
-0
lines changed

4 files changed

+115
-0
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@
22

33
个人认为,树莓派应该算是目前开源硬件里学习嵌入式Linux系统最好的工具,里面的设计思路和一些工具是很值得借鉴的,这里主要使用Raspberry Pi 4B进行系统架构分析。
44

5+
## 40 Pin引脚
6+
7+
![Shematic_RPI_40_Pin.png](docs/images/Shematic_RPI_40_Pin.png)
8+
59
## Refers
610

711
## docs
812

913
NO.|文件名称|摘要
1014
:--:|:--|:--
15+
0014| [动态设备树GPIO控制LED](docs/0014_动态设备树GPIO控制LED.md) | 通过使用动态改变设备树,使用内核gpio-poweroff驱动实现LED控制
1116
0013| [开机自动发IP信息邮件](docs/0013_开机自动发IP信息邮件.md) | Python3自动发邮件
1217
0012| [dtparam_dtoverlay_DTS动态设备树](docs/0012_dtparam_dtoverlay_DTS动态设备树.md) | 分析dtparam/dtoverlay本质,为什么能够动态改变设备与驱动的match
1318
0011| [SoC设备树DTS分析](docs/0011_SoC设备树DTS分析.md) | 怎么分析芯片设备树
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# 动态设备树GPIO控制LED
2+
3+
通过使用动态改变设备树,使用内核gpio-poweroff驱动实现LED控制
4+
5+
## 参考文档
6+
7+
* [Device Trees, overlays, and parameters](https://www.raspberrypi.org/documentation/configuration/device-tree.md)
8+
* 2.2: Device Tree parameters
9+
* [Raspberry Pi overlays README](https://github.com/raspberrypi/firmware/blob/master/boot/overlays/README)
10+
* gpio-poweroff
11+
12+
## 原理图
13+
14+
![0014_GPIO_LED_Power_OFF.png](images/0014_GPIO_LED_Power_OFF.png)
15+
16+
## 实践操作
17+
18+
* sudo cat /sys/kernel/debug/gpio
19+
```
20+
gpiochip0: GPIOs 0-53, parent: platform/fe200000.gpio, pinctrl-bcm2835:
21+
gpio-0 (ID_SDA )
22+
gpio-1 (ID_SCL )
23+
gpio-2 (SDA1 )
24+
gpio-3 (SCL1 )
25+
gpio-4 (GPIO_GCLK )
26+
gpio-5 (GPIO5 )
27+
gpio-6 (GPIO6 )
28+
gpio-7 (SPI_CE1_N )
29+
gpio-8 (SPI_CE0_N )
30+
gpio-9 (SPI_MISO )
31+
gpio-10 (SPI_MOSI )
32+
...省略
33+
```
34+
* 加载设备树及驱动:
35+
* /boot/config.txt
36+
* 末尾添加:`dtoverlay=gpio-poweroff,gpiopin=10,export=1`
37+
* 需要重启生效
38+
* sudo dtoverlay gpio-poweroff gpiopin=10 export=1
39+
* 这种方式存在问题,overlay文件系统不生效以后,重启的时候,电平拉不上去,暂不深入解释,自行理解分析
40+
* sudo cat /sys/kernel/debug/gpio
41+
```
42+
gpiochip0: GPIOs 0-53, parent: platform/fe200000.gpio, pinctrl-bcm2835:
43+
gpio-0 (ID_SDA )
44+
gpio-1 (ID_SCL )
45+
gpio-2 (SDA1 )
46+
gpio-3 (SCL1 )
47+
gpio-4 (GPIO_GCLK )
48+
gpio-5 (GPIO5 )
49+
gpio-6 (GPIO6 )
50+
gpio-7 (SPI_CE1_N )
51+
gpio-8 (SPI_CE0_N )
52+
gpio-9 (SPI_MISO )
53+
gpio-10 (SPI_MOSI |power_ctrl ) out lo
54+
...省略
55+
```
56+
* sudo reboot
57+
* sudo shutdown now
58+
* sudo su
59+
* cd /sys/class/gpio/gpio10
60+
* echo 1 > value
61+
* echo 0 > value
62+
* 引出一个新的问题:用户空间原来可以这个控制GPIO口
63+
64+
## overlay分析
65+
66+
* arch/arm/boot/dts/overlays/gpio-poweroff-overlay.dts
67+
```dts
68+
// Definitions for gpio-poweroff module
69+
/dts-v1/;
70+
/plugin/;
71+
72+
/ {
73+
compatible = "brcm,bcm2835";
74+
75+
fragment@0 {
76+
target-path = "/";
77+
__overlay__ {
78+
power_ctrl: power_ctrl {
79+
compatible = "gpio-poweroff";
80+
gpios = <&gpio 26 0>;
81+
force;
82+
};
83+
};
84+
};
85+
86+
fragment@1 {
87+
target = <&gpio>;
88+
__overlay__ {
89+
power_ctrl_pins: power_ctrl_pins {
90+
brcm,pins = <26>;
91+
brcm,function = <1>; // out
92+
};
93+
};
94+
};
95+
96+
__overrides__ {
97+
gpiopin = <&power_ctrl>,"gpios:4",
98+
<&power_ctrl_pins>,"brcm,pins:0";
99+
active_low = <&power_ctrl>,"gpios:8";
100+
input = <&power_ctrl>,"input?";
101+
export = <&power_ctrl>,"export?";
102+
timeout_ms = <&power_ctrl>,"timeout-ms:0";
103+
};
104+
};
105+
```
106+
107+
## 驱动分析
108+
109+
* drivers/power/reset/gpio-poweroff.c
110+
87.3 KB
Loading
315 KB
Loading

0 commit comments

Comments
 (0)