K230 PMU User Guide#
1. Function introduction#
The PMU module provides 6 input and 2 output ports, each with the following functions:
INT0 is used as the power on and off button by default, supporting long press to power on, long press shutdown event reporting, long press forced shutdown, level or edge event reporting, support debounce, two long press times can be matched
INT1 supports level or edge detection, edge count detection, both support triggering boot and reporting events, support debounce, and edge count values can be configured (it is recommended not to open both detection modes at the same time, the edge detection function will be overridden)
INT2 supports level or edge detection, triggers power-on and report events, and debounces
INT3 supports level or edge detection, triggers power-on and escalation events, and debounces
INT4 supports level or edge detection, triggering power-on and reporting events (edge detection recommended)
INT5 supports level or edge detection, triggering power-on and reporting events (edge detection recommended)
OUTPUT0 is used to control PMICs
OUTPUT1 not used yet
The PMU module also provides a log storage function of 64Byte, of which the last 4Byte is used by the driver and the remaining 60Byte is left to the user
2. User Control#
The PMU can be controlled by the user through the device tree and sysfs, the PMU can be configured through the device tree at system startup, and the PMU can be dynamically configured through sysfs after startup
2.1 PMU Device Tree Configuration#
pmu: pmu@0x91000000 {
compatible = "kendryte, k230-pmu";
reg = <0x0 0x91000000 0x0 0xb0>;
interrupt-parent = <&intc>;
interrupts = <175>;
status = "disabled";
/*
int0 {
force-powerdown-value = <320000>;
power-event-value = <96000>;
debounce-value = <256>;
type = <IRQ_TYPE_EDGE_RISING>;
wakeup;
event;
};
int1 {
debounce-value = <256>;
edge-cnt-type = <IRQ_TYPE_EDGE_RISING>;
edge-cnt-value = <1>;
edge-cnt-wakeup;
edge-cnt-event;
type = <IRQ_TYPE_EDGE_RISING>;
wakeup;
event;
};
int2 {
debounce-value = <256>;
type = <IRQ_TYPE_EDGE_RISING>;
wakeup;
event;
};
int3 {
debounce-value = <256>;
type = <IRQ_TYPE_EDGE_RISING>;
wakeup;
event;
};
int4 {
type = <IRQ_TYPE_EDGE_FALLING>;
wakeup;
event;
};
int5 {
type = <IRQ_TYPE_EDGE_RISING>;
wakeup;
event;
};
rtc {
alarm-wakeup;
alarm-event;
tick-wakeup;
tick-event;
};
*/
};
Key field meanings:
force-powerdown-value
Long press to force shutdown timepower-event-value
Long press on and long press on the shutdown event timedebounce-value
Debounce timetype
Detection type, support rising edge, falling edge, high level, low levelwakeup
Enable power-on to wake up red energyevent
Enable event reportingedge-cnt-type
Detection type, support rising edge, falling edgeedge-cnt-value
Edge count value
All times are measured in (1/32768) seconds, e.g. 327680 for 10 seconds
2.2 PMU file control#
PMU sysfs is located in /sys/devices/platform/soc/91000000.pmu
the directory and the file structure is as follows:
.
|-- driver -> ../../../../bus/platform/drivers/k230-pmu
|-- driver_override
|-- int0
| |-- debounce_value
| |-- event
| |-- force_powerdown_value
| |-- power_event_value
| |-- type
| `-- wakeup
|-- int1
| |-- debounce_value
| |-- edge_cnt_event
| |-- edge_cnt_type
| |-- edge_cnt_value
| |-- edge_cnt_wakeup
| |-- event
| |-- type
| `-- wakeup
|-- int2
| |-- debounce_value
| |-- event
| |-- type
| `-- wakeup
|-- int3
| |-- debounce_value
| |-- event
| |-- type
| `-- wakeup
|-- int4
| |-- event
| |-- type
| `-- wakeup
|-- int5
| |-- event
| |-- type
| `-- wakeup
|-- modalias
|-- of_node -> ../../../../firmware/devicetree/base/soc/pmu@0x91000000
|-- pmu
| |-- pmu_logs
| |-- pmu_regs
| |-- pmu_status
| `-- wakeup_source
|-- rtc
| |-- alarm_event
| |-- alarm_wakeup
| |-- tick_event
| `-- tick_wakeup
|-- subsystem -> ../../../../bus/platform
`-- uevent
Main file features:
pmu/pmu_status
PMU Status (read-only)PMU_RESET
The PMU is powered offSOC_FORCE_PD
The SoC is forced to power downSOC_NORMAL_PD
The SoC is powered off normallySOC_RESET
The SoC is reset
pmu/wakeup_source
system wakeup source (read-only) INT0,INT1,INT2,INT3,INT4,INT5,RTC_ALARM,RTC_TICKpmu/pmu_logs
User LOG file (binary file, 4-byte alignment required for read and write)pmu/pmu_regs
PMU debugging (binary, 4-byte alignment required for read and write)int0/force_powerdown_value
Long press to force shutdown timeint0/power_event_value
Long press on and long press on the shutdown event timeint1/edge_cnt_type
Detection type, valid values “rising”, “falling”int1/edge_cnt_value
Edge count value*/debounce_value
Debounce time*/type
Detection type, valid values “rising”, “falling”, “low”, “high”*/*wakeup
Wake up, valid values “enabled”, “disabled”*/*event
Event reported, valid values “enabled”, “disabled”
For example, enable INT1 rising edge to wake up:
cd /sys/devices/platform/soc/91000000.pmu/int1
echo rising > type
echo enabled > wakeup
For example, enable INT2 falling edge events to be reported:
cd /sys/devices/platform/soc/91000000.pmu/int2
echo falling > type
echo enabled > event
2.3 PMU events are reported#
PMU uses the input subsystem to report events, and the reported event code is so EV_KEY
that users can perform business processing after receiving the corresponding events. For example, after receivingKEY_POWER
the key value, the user can perform shutdown preparation and invoke thepoweroff
shutdown command
You can use the evtest
tool for testing with the following event table:
action |
Key value |
---|---|
INT0 Press and hold to shut down |
KEY_POWER |
INT0 level or edge |
BTN_0 |
INT1 level or edge or edge count |
BTN_1 |
INT2 level or edge |
BTN_2 |
INT3 level or edge |
BTN_3 |
INT4 level or edge |
BTN_4 |
INT5 level or edge |
BTN_5 |
RTC_ALARM |
BTN_6 |
RTC_TICK |
BTN_7 |
2.4 PMU shutdown control#
Use
poweroff
the command shutdownForce shutdown by pressing the INT0 button long (not recommended unless the system is down. Forced shutdown after system downtime will cause PMU to wake up).
3. Hardware connection#
When using a PMU, you need to set up the EVB board as follows
Use the jumper cap to connect PIN13(OUT0) and PIN14(PW_EN) of the J1 interface, taking care to disconnect PIN15(SYS_SW) and PIN16(PW_EN)
Depending on the different wake-up source, PIN2 (SYS_ON_OFF) is connected to the corresponding PIN using a jumper, and the button K1 can control the state of INT, press the button to go high, and release it to low
Wake source
PIN
label
INT0
1
INT0
INT1
3
INT1
INT2
5
INT2
INT3
7
INT3
INT4
9
INT4
INT5
11
INT5
Connection diagram using INT0 as a wake-up source:
4. Precautions#
The PMU module is not enabled by default in the device tree, if you need to use it, enable it in the device tree
When using the PMU module, be sure to wake up the PMU module through any INT, otherwise the kernel will be stuck when initializing the driver