summaryrefslogtreecommitdiff
path: root/documentation/6.components/device-driver/input
diff options
context:
space:
mode:
Diffstat (limited to 'documentation/6.components/device-driver/input')
-rwxr-xr-xdocumentation/6.components/device-driver/input/dm.md237
-rwxr-xr-xdocumentation/6.components/device-driver/input/input.md59
-rwxr-xr-xdocumentation/6.components/device-driver/input/power.md103
-rwxr-xr-xdocumentation/6.components/device-driver/input/touch.md160
-rwxr-xr-xdocumentation/6.components/device-driver/input/uapi.md162
5 files changed, 721 insertions, 0 deletions
diff --git a/documentation/6.components/device-driver/input/dm.md b/documentation/6.components/device-driver/input/dm.md
new file mode 100755
index 0000000000..d071415564
--- /dev/null
+++ b/documentation/6.components/device-driver/input/dm.md
@@ -0,0 +1,237 @@
+@page page_device_input_dm Input device model (DM)
+
+# Input subsystem under `RT_USING_DM`
+
+The **input core** (`components/drivers/input/input.c`) is built only when **`RT_USING_INPUT`** is enabled. That Kconfig option **`depends on RT_USING_DM`** — there is **no** legacy non-DM input stack in-tree. Drivers publish Linux-style **`EV_*`** events through **`struct rt_input_device`**; consumers attach via **`rt_input_add_handler`** or POSIX **`/dev/inputN`** (@ref page_device_input_uapi).
+
+Event reporting API, polling rules, and pitfalls: @ref page_device_input.
+
+| Topic | Page |
+| --- | --- |
+| Userspace **`open`/`read`/`ioctl`** | @ref page_device_input_uapi |
+| **`rt_touch_device`** bridge | @ref page_device_input_touch |
+| **`KEY_POWER` / `KEY_RESTART`** shutdown/reset | @ref page_device_input_power |
+
+Sources:
+
+| File | Role |
+| --- | --- |
+| **`input.c`** | Global device list, **`rt_dm_ida`** naming (`input0`…), **`rt_input_device_register`** |
+| **`input_power.c`** | @ref page_device_input_power |
+| **`input_touch.c`** | @ref page_device_input_touch |
+| **`input_uapi.c`** | @ref page_device_input_uapi |
+| **`keyboard/`**, **`joystick/`**, **`touchscreen/`**, **`misc/`** | OFW platform/SPI drivers |
+
+---
+
+## Kconfig / build
+
+| Option | Role |
+| --- | --- |
+| **`RT_USING_DM`** | Parent — input cannot be enabled without DM |
+| **`RT_USING_INPUT`** | Core **`input.c`**; selects **`RT_USING_ADT`** + bitmap ADT |
+| **`RT_INPUT_POWER`** | @ref page_device_input_power (default **y**) |
+| **`RT_INPUT_UAPI`** | @ref page_device_input_uapi |
+| **`RT_INPUT_KEYBOARD`** | **`gpio-keys`**, **`adc-keys`** (see sub-options) |
+| **`RT_INPUT_JOYSTICK`** | **`adc-joystick`** |
+| **`RT_INPUT_TOUCHSCREEN`** | @ref page_device_input_touch |
+| **`RT_INPUT_MISC`** | e.g. **`ettus,e3x0-button`** |
+| **`SOC_DM_INPUT_*_DIR`** | BSP adds more platform drivers via **`osource`** in sub-Kconfig |
+
+**Unlike @ref page_device_i2c_dm**, input has **no dedicated `rt_bus`**. Each hardware block is a normal **`struct rt_platform_driver`** (or **`struct rt_spi_driver`**) that embeds or owns **`struct rt_input_device`** and calls **`rt_input_device_register`** from **`probe`**.
+
+---
+
+## Architecture
+
+```
+ Device tree node (compatible = "gpio-keys", "adc-keys", …)
+ |
+ | platform bus match (rt_ofw_node_id) or SPI bus match
+ v
+ driver probe(pdev)
+ |
+ | parse OFW (gpios, io-channels, irq, …)
+ | rt_input_set_capability(idev, EV_KEY|EV_ABS, code)
+ | optional: rt_input_setup_polling / rt_input_setup_touch
+ v
+ rt_input_device_register(idev)
+ |
+ | rt_dm_ida_alloc → name "inputN"
+ | rt_device_register (RT_Device_Class_Char, DEACTIVATE)
+ | [RT_INPUT_UAPI] input_uapi_init
+ | list on input_device_nodes
+ v
+ [RT_INPUT_TOUCHSCREEN] input_touch_register → rt_touch_device
+ [RT_INPUT_POWER] global KEY_POWER / KEY_RESTART handlers
+ |
+ v
+ Hardware IRQ / timer poll → rt_input_report_* → rt_input_sync
+ |
+ v
+ rt_input_event → handlers / UAPI queue
+```
+
+| Layer | Object | Notes |
+| --- | --- | --- |
+| **Input device** | **`struct rt_input_device`** | Embeds **`struct rt_device parent`**; capabilities in bitmaps |
+| **DM naming** | **`input_ida`** in **`input.c`** | **`rt_dm_dev_set_name(&idev->parent, "input%u", id)`** |
+| **Platform binding** | **`RT_PLATFORM_DRIVER_EXPORT`** | Probe/remove on **`struct rt_platform_device`** |
+| **SPI touch** | **`RT_SPI_DRIVER_EXPORT`** | e.g. ADS7846 — see @ref page_device_input_touch |
+
+---
+
+## Core registration (`input.c`)
+
+```c
+rt_err_t rt_input_device_register(struct rt_input_device *idev);
+rt_err_t rt_input_device_unregister(struct rt_input_device *idev);
+```
+
+| Step | Behavior |
+| --- | --- |
+| **Allocate ID** | **`rt_dm_ida_alloc(&input_ida)`** — failure → **`-RT_EFULL`** |
+| **Init lists / lock** | Per-device **`handler_nodes`**, **`rt_spinlock`** |
+| **Register char dev** | **`RT_Device_Class_Char`**, flag **`RT_DEVICE_FLAG_DEACTIVATE`** |
+| **Post-register** | Start poller timer if **`idev->poller`**; **`input_touch_register`**; UAPI fops if enabled |
+| **Unregister** | Refcount check; UAPI/touch teardown; **`rt_dm_ida_free`** |
+
+**Driver pattern** — embed input at a known offset:
+
+```c
+struct my_input {
+ struct rt_input_device parent;
+ /* private */
+};
+
+static void my_report(struct my_input *mi)
+{
+ rt_input_report_key(&mi->parent, KEY_ENTER, 1);
+ rt_input_sync(&mi->parent);
+}
+```
+
+Use **`rt_container_of(idev, struct my_input, parent)`** in poll/IRQ callbacks.
+
+---
+
+## In-tree OFW drivers
+
+| Compatible / binding | Driver file | Bus | Summary |
+| --- | --- | --- | --- |
+| **`gpio-keys`** | **`keyboard/keys-gpio.c`** | platform | Parent node; **each child** → one **`inputN`** per key |
+| **`adc-keys`** | **`keyboard/keys-adc.c`** | platform | **`io-channels`** via @ref page_device_iio_dm; polling |
+| **`adc-joystick`** | **`joystick/js-adc.c`** | platform | Per-child **`reg`**, IIO, **`EV_ABS`** polling |
+| **`ti,ads7846`** … **`ti,xpt2046`** | **`touchscreen/ts-ads7846.c`** | SPI | @ref page_device_input_touch |
+| **`ettus,e3x0-button`** | **`misc/button-e3x0.c`** | platform | IRQ **`press`/`release`** → **`KEY_POWER`** |
+
+### `gpio-keys` (platform + children)
+
+- Parent **`compatible = "gpio-keys"`**; **subnodes** are individual buttons.
+- Each child: **`rt_ofw_get_named_pin`**, property matching **`*,code$`** (e.g. **`linux,code`**), optional **`debounce-interval`**.
+- **One `rt_input_device` per child** (not one device for the whole parent).
+
+### `adc-keys` / `adc-joystick` (IIO consumers)
+
+- Resolve ADC through **`rt_iio_channel_get_by_name`** / **`rt_iio_channel_get_by_index`** (@ref page_device_iio_dm).
+- Default **`poll-interval`** **200 ms** if property missing.
+
+### ADS7846 family (SPI)
+
+- **`RT_SPI_DRIVER_EXPORT(ads7846_driver)`**; regulator, IRQ, worker thread.
+- DT axis/touch properties consumed by **`input_touch_parse`** — @ref page_device_input_touch.
+
+---
+
+## Device tree examples
+
+### GPIO key (child node)
+
+```dts
+gpio-keys {
+ compatible = "gpio-keys";
+
+ power-key {
+ label = "Power";
+ gpios = <&gpio0 5 GPIO_ACTIVE_LOW>;
+ linux,code = <116>; /* KEY_POWER — see page_device_input_power */
+ debounce-interval = <15>;
+ };
+};
+```
+
+### ADC resistor ladder
+
+```dts
+adc-keys {
+ compatible = "adc-keys";
+ io-channels = <&saradc 0>;
+ io-channel-names = "buttons";
+ poll-interval = <100>;
+ keyup-threshold-microvolt = <1800000>;
+
+ up {
+ press-threshold-microvolt = <500000>;
+ linux,code = <103>; /* KEY_UP */
+ };
+};
+```
+
+### SPI resistive touch
+
+```dts
+touch: touchscreen@0 {
+ compatible = "ti,ads7846";
+ reg = <0>;
+ interrupt-parent = <&gpio1>;
+ interrupts = <25 IRQ_TYPE_EDGE_FALLING>;
+ ti,x-min = /bits/ 16 <0>;
+ ti,x-max = /bits/ 16 <4095>;
+ ti,y-min = /bits/ 16 <0>;
+ ti,y-max = /bits/ 16 <4095>;
+ vcc-supply = <&reg_3v3>;
+};
+```
+
+(SPI **`reg`** / **`spi-max-frequency`** belong on the child under the SPI controller node per your BSP.)
+
+---
+
+## New platform input driver checklist
+
+1. Enable **`RT_USING_DM`**, **`RT_USING_OFW`**, **`RT_USING_INPUT`** (and subsystem menu if you add under **`keyboard/`** etc.).
+2. **`struct rt_platform_driver`** with **`ofw_ids[]`** matching Linux binding where possible.
+3. In **`probe`**: allocate driver private struct with **`struct rt_input_device`** embedded first (or pointer field).
+4. **`rt_input_set_capability`** for every **`type`/`code`** you will report; for **`EV_ABS`**, call **`rt_input_set_absinfo`** (after capability allocates **`absinfo`**).
+5. IRQ or **`rt_input_setup_polling`** — poller **`poll`** must not block (@ref page_device_input).
+6. On each logical event frame: **`rt_input_report_*`** then **`rt_input_sync`**.
+7. **`rt_input_device_register`** only when hardware is ready; store private data in **`pdev->parent.user_data`** or **`rt_ofw_data(np)`** for **`remove`**.
+8. **`remove`**: stop IRQ/poller, **`rt_input_device_unregister`**, free memory.
+9. **`RT_PLATFORM_DRIVER_EXPORT(drv)`** (or **`RT_SPI_DRIVER_EXPORT`** on SPI slaves).
+
+---
+
+## Pitfalls
+
+| Issue | Mitigation |
+| --- | --- |
+| **Missing `rt_input_sync`** | Consumers see partial frames — always end with **`rt_input_sync`**. |
+| **Capability after register** | Set capabilities **before** **`rt_input_device_register`**. |
+| **`EV_ABS` without absinfo** | Call **`rt_input_set_capability(EV_ABS, axis)`** then **`rt_input_set_absinfo`**. |
+| **Unregister with open UAPI fd** | Close **`/dev/inputN`** first — @ref page_device_input_uapi |
+| **gpio-keys child vs parent** | Driver registers **per child**; do not expect one **`input0`** for the whole node. |
+| **IIO channel NULL** | Fix DT **`io-channels`** — @ref page_device_iio_dm |
+| **Power handler surprise** | @ref page_device_input_power |
+
+---
+
+## See also
+
+- @ref page_device_input
+- @ref page_device_input_uapi
+- @ref page_device_input_touch
+- @ref page_device_input_power
+- @ref page_device_iio_dm
+- @ref page_device_bus
+- `components/drivers/include/drivers/input.h`
+- `components/drivers/input/Kconfig`
diff --git a/documentation/6.components/device-driver/input/input.md b/documentation/6.components/device-driver/input/input.md
new file mode 100755
index 0000000000..fa45817eab
--- /dev/null
+++ b/documentation/6.components/device-driver/input/input.md
@@ -0,0 +1,59 @@
+@page page_device_input Input subsystem
+
+Device-tree binding and DM registration: @ref page_device_input_dm.
+
+| Topic | Page |
+| --- | --- |
+| Userspace API | @ref page_device_input_uapi |
+| Touch class bridge | @ref page_device_input_touch |
+| Power / restart keys | @ref page_device_input_power |
+
+# Input subsystem (API)
+
+Header: `drivers/input.h`. Typical stack: low-level driver → **`rt_input_event` / reporters** → handlers (GUI, shell) or **`/dev/inputN`** (@ref page_device_input_uapi).
+
+| Path | API |
+| --- | --- |
+| In-kernel listener | **`rt_input_add_handler`** |
+| POSIX process (Smart) | **`open` / `read` / `ioctl` / `poll` on `/dev/inputN`** — @ref page_device_input_uapi |
+| Legacy touch GUI | **`struct rt_touch_device`** — @ref page_device_input_touch |
+
+## When to use the input core
+
+| Use **`rt_input_*`** when… | Consider raw **`rt_device`** read when… |
+| --- | --- |
+| You want **Linux-like** `EV_KEY` / `EV_REL` / `EV_ABS` / multitouch slot semantics and multiple listeners. | You have a **single proprietary** app talking to a vendor IOCTL-only touch stack. |
+| You need **polling** (`**rt_input_setup_polling**`) for GPIO keys without IRQ storms. | GPIO IRQ latency is fine and you do not need unified event routing. |
+
+## Event contract
+
+1. **`rt_input_set_capability`** before **`rt_input_device_register`** so users know which **`type`/`code`** pairs are valid.
+2. For each hardware change, call **`rt_input_report_*`** then **`rt_input_sync`** to close the frame (**`SYN_REPORT`**). Missing **`sync`** merges events poorly for consumers.
+3. **`rt_input_trigger`** routes through optional **`idev->trigger`**—use when you wrap another input device; otherwise **`rt_input_event`** is enough.
+
+## Callback / context rules
+
+- **`rt_input_add_handler` → `callback`**: invoked from **`rt_input_event`** path—assume **thread or workqueue** unless your driver documents IRQ delivery; keep **`callback` short**.
+- **`poller->poll`**: runs on timer tick—**must not block** or take mutexes that can deadlock with the same thread calling **`rt_input_sync`**.
+- **Touch helpers**: **`rt_input_setup_touch`** / **`rt_input_report_touch_*`** require **`RT_INPUT_TOUCHSCREEN`** — @ref page_device_input_touch.
+
+## Registration lifecycle
+
+- **`rt_input_device_register`**: registers underlying **`rt_device`**; failures leave partially init state—clean up partial setup in error paths.
+- **`rt_input_remove_config`**: tears down polling/touch dynamic config before unregister if you toggled features at runtime.
+
+## Pitfalls
+
+- **ABS without `rt_input_set_absinfo`**: consumers cannot clamp—set min/max/resolution for axes you report.
+- **Key autorepeat**: not automatic unless a layer implements it—do not assume Linux repeat behavior.
+- **Re-entrancy**: posting events from inside a handler for the same device can recurse—prefer queueing.
+
+## See also
+
+- @ref page_device_input_dm
+- @ref page_device_input_uapi
+- @ref page_device_input_touch
+- @ref page_device_input_power
+- `components/drivers/include/drivers/input.h`
+- `components/drivers/include/drivers/input_uapi.h`
+- `dt-bindings/input/event-codes.h`
diff --git a/documentation/6.components/device-driver/input/power.md b/documentation/6.components/device-driver/input/power.md
new file mode 100755
index 0000000000..870b559552
--- /dev/null
+++ b/documentation/6.components/device-driver/input/power.md
@@ -0,0 +1,103 @@
+@page page_device_input_power Input power keys
+
+# Power / restart key handlers (`RT_INPUT_POWER`)
+
+**`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: @ref page_device_input_dm. Handler API: @ref page_device_input.
+
+Source: **`components/drivers/input/input_power.c`**.
+
+---
+
+## Kconfig
+
+| 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.
+
+---
+
+## Architecture
+
+```
+ INIT_ENV_EXPORT(input_event_power_init)
+ |
+ +-- power_handler_install(KEY_POWER)
+ +-- power_handler_install(KEY_RESTART)
+ |
+ | (1) tmp_handler: identify=test, callback=power_input_callback
+ | rt_input_add_handler → scans all idevs, counts matches
+ v
+ (2) For each matching input device index:
+ alloc rt_input_handler[N]
+ identify=power_input_identify (binds to Nth device with key)
+ callback=power_input_callback
+ rt_input_add_handler
+ |
+ v
+ Any idev reports KEY_POWER/KEY_RESTART release (value==0)
+ → rt_input_event → handler → shutdown/reset
+```
+
+| 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.
+
+---
+
+## Key actions
+
+| 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).
+
+---
+
+## Interaction with drivers
+
+- **`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.
+- Does **not** require a dedicated compatible string; only the **advertised key code** matters.
+
+If multiple devices expose **`KEY_POWER`**, each gets its own handler instance; any of them can shut down the system on release.
+
+---
+
+## Disabling or overriding
+
+| 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 @ref page_device_input_uapi |
+| **Hold-to-power-off** | Not implemented here — implement in driver (long-press timer) before reporting release |
+
+---
+
+## Pitfalls
+
+| 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) |
+
+---
+
+## See also
+
+- @ref page_device_input_dm — **`gpio-keys`** DT example with **`KEY_POWER`**
+- @ref page_device_input
+- `dt-bindings/input/linux-event-codes.h` (or **`event-codes.h`**)
diff --git a/documentation/6.components/device-driver/input/touch.md b/documentation/6.components/device-driver/input/touch.md
new file mode 100755
index 0000000000..abd81aa904
--- /dev/null
+++ b/documentation/6.components/device-driver/input/touch.md
@@ -0,0 +1,160 @@
+@page page_device_input_touch Input touch bridge
+
+# Touch bridge (`RT_INPUT_TOUCHSCREEN`)
+
+**`input_touch.c`** bridges **`struct rt_input_device`** (Linux-style **`EV_ABS`** / multitouch slots) to **`struct rt_touch_device`** so GUI stacks can use the legacy **touch class** API (**`rt_device_find`**, **`RT_TOUCH_CTRL_*`**, **`rt_hw_touch_isr`**) without duplicating panel drivers.
+
+Input core and OFW drivers (e.g. ADS7846): @ref page_device_input_dm. Event helpers (**`rt_input_setup_touch`**, **`rt_input_report_touch_*`**): @ref page_device_input.
+
+Sources: **`components/drivers/input/input_touch.c`**, **`components/drivers/input/touchscreen/`**.
+
+---
+
+## Kconfig
+
+| Option | Role |
+| --- | --- |
+| **`RT_INPUT_TOUCHSCREEN`** | Build **`input_touch.c`**; **selects `RT_USING_TOUCH`** |
+| **`RT_INPUT_TOUCHSCREEN_ADS7846`** | In-tree SPI resistive driver **`ts-ads7846.c`** |
+| **`SOC_DM_INPUT_TOUCHSCREEN_DIR`** | BSP adds more panel drivers |
+
+Requires **`RT_USING_INPUT`** and **`RT_USING_DM`**.
+
+---
+
+## Architecture
+
+```
+ Panel driver (e.g. ads7846)
+ |
+ | rt_input_set_capability(EV_ABS, …)
+ | rt_input_setup_touch(idev, num_slots, &touch_info)
+ | rt_input_device_register(idev)
+ v
+ input_touch_register (after idev on global list)
+ |
+ | rt_hw_touch_register → device "touchN"
+ | rt_input_add_handler → input_touch_cb
+ v
+ Driver reports: rt_input_report_touch_* / rt_input_sync
+ |
+ v
+ input_touch_cb: EV_ABS → struct rt_touch_data
+ SYN_REPORT → rt_hw_touch_isr()
+ |
+ v
+ GUI: rt_device_read / touch ISR callback
+```
+
+| Object | Role |
+| --- | --- |
+| **`struct input_touch_properties`** | Stored in **`idev->touch`**: DT-derived min/max, invert, swap, slot count |
+| **`struct input_touch_device`** | Embeds **`struct rt_touch_device`** + **`rt_input_handler`** + per-slot **`rt_touch_data`** |
+| **`input_touch_ops`** | **`touch_readpoint`**, **`touch_control`** (range, enable/disable, status) |
+
+**`input_touch_register`** only creates the **`rt_touch_device`** when **`rt_input_setup_touch`** was called with non-NULL **`struct rt_touch_info *info`** ( **`prop->touch_dev`** allocated).
+
+---
+
+## Driver API (`input.h`)
+
+```c
+rt_err_t rt_input_setup_touch(struct rt_input_device *idev,
+ rt_uint32_t num_slots, struct rt_touch_info *info);
+rt_err_t rt_input_parse_touch_position(struct rt_input_device *idev,
+ rt_uint32_t *out_x, rt_uint32_t *out_y);
+rt_bool_t rt_input_report_touch_inactive(struct rt_input_device *idev, rt_bool_t active);
+void rt_input_report_touch_position(struct rt_input_device *idev,
+ rt_uint32_t x, rt_uint32_t y, rt_bool_t multitouch);
+```
+
+| API | Role |
+| --- | --- |
+| **`rt_input_setup_touch`** | Allocate **`idev->touch`**, parse DT, optional multitouch absinfo (**`ABS_MT_SLOT`**, **`ABS_MT_TRACKING_ID`**) |
+| **`num_slots == 0`** | Single-touch (**`ABS_X`/`ABS_Y`**); **`num_slots > 0`** | Multitouch slot protocol |
+| **`rt_input_report_touch_position`** | Apply invert/swap from DT, then **`rt_input_report_abs`** |
+| **`rt_input_report_touch_inactive`** | Emit **`ABS_MT_TRACKING_ID = -1`** on release |
+| **`rt_input_parse_touch_position`** | Map raw x/y through **`touchscreen-inverted-*`** / **`touchscreen-swapped-x-y`** |
+
+Call **`rt_input_setup_touch`** before **`rt_input_device_register`**. **`input_touch_register`** runs inside register after the device is linked globally.
+
+---
+
+## Device tree properties (`input_touch_parse`)
+
+Read from the **`rt_input_device`**'s **`rt_device`** OFW node via **`rt_dm_dev_prop_*`**:
+
+| Property | Effect |
+| --- | --- |
+| **`touchscreen-min-x`**, **`touchscreen-size-x`**, **`touchscreen-fuzz-x`** | Override **`ABS_X`** or **`ABS_MT_POSITION_X`** absinfo |
+| **`touchscreen-min-y`**, **`touchscreen-size-y`**, **`touchscreen-fuzz-y`** | Y axis |
+| **`touchscreen-max-pressure`**, **`touchscreen-fuzz-pressure`** | Pressure axis |
+| **`touchscreen-inverted-x`**, **`touchscreen-inverted-y`** | Flip coordinates in **`rt_input_parse_touch_position`** |
+| **`touchscreen-swapped-x-y`** | Swap X/Y absinfo and coordinates |
+
+Missing properties fall back to values already set by **`rt_input_set_absinfo`** in the panel driver.
+
+---
+
+## Handler translation (`input_touch_cb`)
+
+When **`touch_dev->enabled`**:
+
+| Input event | Touch side |
+| --- | --- |
+| **`ABS_MT_SLOT`** | Select active slot index |
+| **`ABS_MT_TRACKING_ID == -1`** | **`RT_TOUCH_EVENT_UP`**, **`rt_hw_touch_isr`** |
+| **`ABS_MT_TRACKING_ID` valid** | DOWN / MOVE, increment **`down`** count |
+| **`ABS_MT_POSITION_X/Y`** or **`ABS_X/Y`** | Scale raw value to **`range_x`/`range_y`** using absinfo min/max |
+| **`EV_SYN` + `SYN_REPORT`** | **`rt_hw_touch_isr`** (frame complete) |
+
+**`input_touch_readpoint`** returns one **`struct rt_touch_data`** for the current slot (GUI pull model).
+
+---
+
+## Example (driver probe sketch)
+
+```c
+struct rt_touch_info info = {
+ .type = RT_TOUCH_TYPE_CAPACITANCE,
+ .vendor = RT_TOUCH_VENDOR_UNKNOWN,
+ .point_num = 1,
+ .range_x = 800,
+ .range_y = 480,
+};
+
+rt_input_set_capability(idev, EV_ABS, ABS_X);
+rt_input_set_capability(idev, EV_ABS, ABS_Y);
+rt_input_set_absinfo(idev, ABS_X, 0, max_x, 0, 0);
+rt_input_set_absinfo(idev, ABS_Y, 0, max_y, 0, 0);
+
+rt_input_setup_touch(idev, 0, &info); /* 0 slots = single touch */
+rt_input_device_register(idev);
+
+/* in IRQ / thread: */
+rt_input_report_touch_position(idev, x, y, RT_FALSE);
+rt_input_sync(idev);
+```
+
+For multitouch, pass **`num_slots > 0`**, use **`rt_input_report_touch_slot`**, tracking id helpers, then **`rt_input_sync`** per frame.
+
+---
+
+## Pitfalls
+
+| Issue | Mitigation |
+| --- | --- |
+| **`setup_touch` after register** | **`input_touch_register`** won't run correctly — setup before register |
+| **`info == NULL`** | Properties-only mode: no **`rt_touch_device`** exported (handler-only path not used for HW touch register) |
+| **Missing `rt_input_sync`** | Touch ISR won't see a full frame |
+| **ABS range zero** | Scaling in **`input_touch_cb`** divides by **`maximum - minimum`** — set absinfo first |
+| **Unregister order** | **`input_touch_unregister`** from **`rt_input_device_unregister`** — drop touch fd users first |
+
+---
+
+## See also
+
+- @ref page_device_input_dm — **`ti,ads7846`** SPI binding
+- @ref page_device_input
+- @ref page_device_input_uapi — parallel POSIX event path on same **`inputN`**
+- `components/drivers/include/drivers/dev_touch.h`
diff --git a/documentation/6.components/device-driver/input/uapi.md b/documentation/6.components/device-driver/input/uapi.md
new file mode 100755
index 0000000000..4ca1673db3
--- /dev/null
+++ b/documentation/6.components/device-driver/input/uapi.md
@@ -0,0 +1,162 @@
+@page page_device_input_uapi Input userspace API (UAPI)
+
+# Input event UAPI (`RT_INPUT_UAPI`)
+
+**`input_uapi.c`** exposes each **`rt_input_device`** as a **Linux-compatible** character device for POSIX userspace (Smart / LWP + DFS). IOCTLs and **`struct input_event`** are defined in **`drivers/input_uapi.h`** (aligned with **`include/uapi/linux/input.h`**).
+
+DM overview and driver binding: @ref page_device_input_dm. In-kernel reporters and handlers: @ref page_device_input.
+
+Sources: **`components/drivers/input/input_uapi.c`**, **`components/drivers/include/drivers/input_uapi.h`**.
+
+---
+
+## Kconfig
+
+| Option | Default | Role |
+| --- | --- | --- |
+| **`RT_INPUT_UAPI`** | **y** if **`RT_USING_SMART`**, else **n** | Build **`input_uapi.c`**, attach **`dfs_file_ops`** in **`input_uapi_init`** |
+| **`RT_INPUT_UAPI_EVENT_MAX`** | **128** | Ring buffer slots (**`struct input_event`** per device) |
+| **`RT_UAPI_FAKE_BLOCK`** | **y** | **`O_NONBLOCK`** empty **`read`** returns synthetic **`SYN_REPORT`** instead of **`-EAGAIN`** |
+
+**Dependencies**: **`RT_USING_INPUT`**, **`RT_USING_KTIME`**, **`RT_USING_POSIX_DEVIO`**.
+
+---
+
+## Architecture
+
+```
+ rt_input_report_* → rt_input_sync
+ → rt_input_event (input.c)
+ → input_uapi_event (if ref_count > 0)
+ ring buffer + ktime timestamp
+ SYN_REPORT → sync_count++, wake wait_queue
+ → read() / poll(POLLIN) on /dev/inputN
+```
+
+| Hook | When |
+| --- | --- |
+| **`input_uapi_init`** | **`rt_input_device_register`** — allocates **`struct input_uapi`**, sets **`idev->parent.fops`** |
+| **`input_uapi_event`** | Every **`rt_input_event`** while UAPI enabled |
+| **`input_uapi_finit`** | **`rt_input_device_unregister`** — free UAPI state |
+
+Registered device names are **`input0`**, **`input1`**, … (**`rt_dm_ida`** in **`input.c`**). Open via devfs:
+
+```c
+int fd = open("/dev/input0", O_RDONLY);
+```
+
+**`input_uapi_event`** returns without queuing when **`idev->parent.ref_count == 0`** — userspace must **`open`** the node before events appear.
+
+---
+
+## Event format
+
+| | Kernel handler path | UAPI queue |
+| --- | --- | --- |
+| Struct | **`struct rt_input_event`** (`drivers/input.h`) | **`struct input_event`** (`input_uapi.h`) |
+| Time | **`rt_tick_t tick`** | **`struct timeval`** from **`rt_ktime_boottime_get_us`** |
+| Codes | **`dt-bindings/input/event-codes.h`** | Same |
+
+**`struct input_absinfo`** returned by **`EVIOCGABS`** matches **`struct rt_input_absinfo`** (**`RT_ASSERT`** on layout in **`input_uapi_init`**).
+
+---
+
+## Ring buffer and framing
+
+**`struct input_uapi`** holds:
+
+- Atomic **`read_idx`**, **`write_idx`**, **`sync_count`**
+- **`events[RT_INPUT_UAPI_EVENT_MAX]`**
+- Optional **`grabbed_file`** for **`EVIOCGRAB`**
+
+On each kernel event copy, **`write_idx`** advances. When **`type == EV_SYN`** and **`code == SYN_REPORT`**, **`sync_count`** increments and **`rt_wqueue_wakeup`** runs.
+
+**`read`** drains events until the user buffer is full or a **`SYN_REPORT`** completes one frame; each consumed frame decrements **`sync_count`**.
+
+**Overflow**: if the next write would overwrite unread data, the event is **dropped** (warning log). Raise **`RT_INPUT_UAPI_EVENT_MAX`** for high-rate touch streams.
+
+---
+
+## `read()` / `poll()` / `write()`
+
+| Behavior | Detail |
+| --- | --- |
+| **Min size** | **`count != 0`** and **`count < sizeof(struct input_event)`** → **`-EINVAL`** |
+| **`count == 0`** | Allowed (availability check after wait) |
+| **Blocking** | Waits on **`idev->parent.wait_queue`** until **`sync_count > 0`** |
+| **`O_NONBLOCK`** | Empty queue → **`-EAGAIN`**, or fake **`SYN_REPORT`** if **`RT_UAPI_FAKE_BLOCK`** |
+| **`poll`** | **`POLLIN`** when **`sync_count > 0`** (**`O_RDONLY`** / **`O_RDWR`** only) |
+| **`write`** | **`-ENOSYS`** |
+
+**Grab**: if another **`dfs_file`** holds **`EVIOCGRAB`**, **`read`** returns **`-EAGAIN`**.
+
+---
+
+## `ioctl()` (implemented)
+
+| IOCTL | Purpose |
+| --- | --- |
+| **`EVIOCGVERSION`** | **`EV_VERSION`** (`0x010001`) |
+| **`EVIOCGID`** | Virtual ID: bustype **`0x06`**, vendor **`0x5354`**, product **`0x4556`**, version **`RT_VER_NUM >> 16`** |
+| **`EVIOCGNAME(len)`** | Device name (**`inputN`**) |
+| **`EVIOCGPROP(len)`** | Property bitmap (direct-touch bit when buffer large enough) |
+| **`EVIOCGBIT(ev, len)`** | Type bitmap (**`ev==0`**) or **`EV_KEY`/`EV_REL`/`EV_ABS`** maps |
+| **`EVIOCGABS(abs)`** | Axis **`struct input_absinfo`** |
+| **`EVIOCGRAB`** | Exclusive grab; non-zero **`args`** grabs; second grabber **`-EBUSY`** |
+
+**`EVIOCSABS`**, force-feedback, and other Linux input IOCTLs → **`-EINVAL`**.
+
+---
+
+## Userspace example
+
+```c
+#include <fcntl.h>
+#include <unistd.h>
+#include <poll.h>
+#include <drivers/input_uapi.h>
+
+void listen_input0(void)
+{
+ struct input_event ev[64];
+ struct pollfd pfd = { .fd = open("/dev/input0", O_RDONLY), .events = POLLIN };
+
+ for (;;)
+ {
+ if (poll(&pfd, 1, -1) <= 0)
+ continue;
+
+ ssize_t n = read(pfd.fd, ev, sizeof(ev));
+ if (n <= 0)
+ continue;
+
+ for (int i = 0; i < n / (int)sizeof(struct input_event); ++i)
+ {
+ /* ev[i].type, ev[i].code, ev[i].value */
+ }
+ }
+}
+```
+
+Use **`rt_input_add_handler`** in kernel; use UAPI when a POSIX process (e.g. **`evtest`**) reads the same event stream.
+
+---
+
+## Pitfalls
+
+| Issue | Mitigation |
+| --- | --- |
+| **No events before `open`** | **`ref_count`** gate in **`input_uapi_event`** |
+| **Unregister with open fd** | **`rt_input_device_unregister`** checks **`ref_count`** — close fds first |
+| **Grab conflicts** | Release with **`EVIOCGRAB`** and zero argument |
+| **Touch bursts** | Increase **`RT_INPUT_UAPI_EVENT_MAX`** or read faster |
+| **`RT_UAPI_FAKE_BLOCK`** | Disable for strict **`-EAGAIN`** on empty non-blocking reads |
+
+---
+
+## See also
+
+- @ref page_device_input_dm
+- @ref page_device_input
+- `components/drivers/include/drivers/input_uapi.h`
+- `components/drivers/input/Kconfig`