![]() |
RT-Thread RTOS
An open source embedded real-time operating system
|
**input_power.c** installs global **rt_input_handler** instances that map **KEY_POWER** and **KEY_RESTART** release events to **rt_hw_cpu_shutdown()** and **rt_hw_cpu_reset()**. Any input device that advertises these keys in its capability bitmap can trigger system power actions without a dedicated PMIC driver hook.
DM and keyboard drivers: Input device model (DM). Handler API: Input subsystem.
Source: **components/drivers/input/input_power.c**.
| Option | Default | Role |
|---|---|---|
**RT_INPUT_POWER** | y | Build **input_power.c**, run **input_event_power_init** at env init |
Depends on **RT_USING_INPUT**. Disable on boards where **KEY_POWER** must only be handled by application code.
| Phase | Behavior |
|---|---|
| Probe pass | Temporary handler increments **cap.value** for each **rt_input_device** with **key_map[code]** set |
| Install pass | One persistent handler per matching device; **identify** matches the **current**-th device |
| Runtime | **power_input_callback**: on **value == 0** (key release), call BSP hook |
Handlers return **RT_TRUE** from **callback** to stop further handler dispatch for that event.
| Linux code | Event | Action |
|---|---|---|
**KEY_POWER** (116) | **EV_KEY**, **value == 0** (release) | **rt_hw_cpu_shutdown()** |
**KEY_RESTART** | **EV_KEY**, **value == 0** | **rt_hw_cpu_reset()** |
Press (**value == 1**) does nothing in **input_power.c** — only release triggers power ops.
BSP must implement **rt_hw_cpu_shutdown** / **rt_hw_cpu_reset** (weak symbols or SoC-specific).
gpio-keys** child with **linux,code = <116>** registers an **inputN** with **KEY_POWER** in **key_map** — power handler attaches automatically when **RT_INPUT_POWER** is on.ettus,e3x0-button** reports **KEY_POWER** on IRQ — same path.If multiple devices expose **KEY_POWER**, each gets its own handler instance; any of them can shut down the system on release.
| Goal | Approach |
|---|---|
| No automatic shutdown | Set **RT_INPUT_POWER=n** in Kconfig |
| Custom policy | Disable **RT_INPUT_POWER** and use **rt_input_add_handler** with higher priority logic, or handle **KEY_POWER** only in userspace via Input userspace API (UAPI) |
| Hold-to-power-off | Not implemented here — implement in driver (long-press timer) before reporting release |
| Issue | Mitigation |
|---|---|
| Unexpected shutdown | Any stray **KEY_POWER** release shuts down — verify DT **linux,code** and test harnesses |
| Missing capability | Driver must **rt_input_set_capability(idev, EV_KEY, KEY_POWER)** before register |
| Press-only testing | Release is required — press alone does not call shutdown |
| No matching devices | **power_handler_install** exits early if count is zero (no handlers allocated) |
gpio-keys** DT example with **KEY_POWER**dt-bindings/input/linux-event-codes.h (or **event-codes.h**)