mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Johann Neuhauser <jneuhauser@dh-electronics.com>
To: <linux-kernel@vger.kernel.org>, <linux-doc@vger.kernel.org>
Cc: Johann Neuhauser <jneuhauser@dh-electronics.com>,
	Jonathan Corbet <corbet@lwn.net>,
	Liam Girdwood <lgirdwood@gmail.com>,
	Mark Brown <broonie@kernel.org>
Subject: [PATCH 3/3] docs: regulator: userspace-consumer: Add uevent-based regulator event reporting
Date: Fri, 4 Apr 2025 15:40:09 +0200	[thread overview]
Message-ID: <20250404134009.2610460-4-jneuhauser@dh-electronics.com> (raw)
In-Reply-To: <20250404134009.2610460-1-jneuhauser@dh-electronics.com>

Add detailed documentation for the new uevent-based event reporting
introduced in the regulator userspace-consumer driver.

This documentation explains:
- The new supported regulator events exposed via uevents.
- Methods to monitor these events from userspace using `udevadm`.
- Practical examples for creating udev rules and scripts.

Signed-off-by: Johann Neuhauser <jneuhauser@dh-electronics.com>
---
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Liam Girdwood <lgirdwood@gmail.com>
Cc: linux-doc@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Cc: Mark Brown <broonie@kernel.org>
---
 .../regulator/userspace-consumer.rst          | 92 +++++++++++++++++++
 1 file changed, 92 insertions(+)
 create mode 100644 Documentation/driver-api/regulator/userspace-consumer.rst

diff --git a/Documentation/driver-api/regulator/userspace-consumer.rst b/Documentation/driver-api/regulator/userspace-consumer.rst
new file mode 100644
index 000000000000..308873fd20cb
--- /dev/null
+++ b/Documentation/driver-api/regulator/userspace-consumer.rst
@@ -0,0 +1,92 @@
+============================
+Regulator Userspace Consumer
+============================
+
+This document describes the Userspace Consumer Regulator Driver
+(`drivers/regulator/userspace-consumer.c`) and its userspace interface.
+
+Introduction
+------------
+
+The Userspace Consumer Regulator provides userspace with direct control
+and monitoring of regulator outputs. It now supports reporting regulator
+events directly via uevents, enabling userspace to handle events such as
+overcurrent, voltage changes, enabling/disabling regulators, and more.
+
+Supported Events
+----------------
+
+The driver emits uevents corresponding to the regulator events defined in
+``include/uapi/regulator/regulator.h``.
+
+Currently supported regulator event uevents are:
+
+- ``EVENT=ABORT_DISABLE``
+- ``EVENT=ABORT_VOLTAGE_CHANGE``
+- ``EVENT=DISABLE``
+- ``EVENT=ENABLE``
+- ``EVENT=FAIL``
+- ``EVENT=FORCE_DISABLE``
+- ``EVENT=OVER_CURRENT``
+- ``EVENT=OVER_TEMP``
+- ``EVENT=PRE_DISABLE``
+- ``EVENT=PRE_VOLTAGE_CHANGE``
+- ``EVENT=REGULATION_OUT``
+- ``EVENT=UNDER_VOLTAGE``
+- ``EVENT=VOLTAGE_CHANGE``
+
+Monitoring Events from Userspace
+--------------------------------
+
+Userspace applications can monitor these regulator uevents using ``udevadm``:
+
+.. code-block:: bash
+
+   udevadm monitor -pku
+
+Example output:
+
+.. code-block::
+
+    KERNEL[152.717414] change   /devices/platform/output-usb3 (platform)
+    ACTION=change
+    DEVPATH=/devices/platform/output-usb3
+    SUBSYSTEM=platform
+    NAME=event
+    EVENT=OVER_CURRENT
+    DRIVER=reg-userspace-consumer
+
+Handling Events with Udev Rules
+-------------------------------
+
+Userspace can react to these events by creating udev rules. For example,
+to trigger a script on an OVER_CURRENT event:
+
+.. code-block:: udev
+
+    # /etc/udev/rules.d/99-regulator-events.rules
+    ACTION=="change", SUBSYSTEM=="platform", DRIVER="reg-userspace-consumer", ENV{EVENT}=="OVER_CURRENT", RUN+="/usr/local/bin/handle-regulator-event.sh"
+
+A sample handler script:
+
+.. code-block:: bash
+
+    #!/bin/sh
+    logger "Handle regulator ${EVENT} on ${DEVPATH}"
+    # Add additional handling logic here
+    case "${EVENT}" in
+    OVER_CURRENT)
+      echo disabled > /sys"${DEVPATH}"/state
+    esac
+
+API Stability
+-------------
+
+This interface is considered stable. New regulator events may be added
+in the future, with corresponding documentation updates.
+
+References
+----------
+
+- Kernel Header File: ``include/uapi/regulator/regulator.h``
+- Driver Source: ``drivers/regulator/userspace-consumer.c``
-- 
2.39.5


  parent reply	other threads:[~2025-04-04 13:42 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-04 13:40 [PATCH 0/3] regulator: userspace-consumer: Add regulator event uevents Johann Neuhauser
2025-04-04 13:40 ` [PATCH 1/3] regulator: userspace-consumer: Add uevent reporting for regulator events Johann Neuhauser
2025-04-04 13:40 ` [PATCH 2/3] ABI: sysfs-platform: Document uevent ABI for reg-userspace-consumer Johann Neuhauser
2025-04-04 13:40 ` Johann Neuhauser [this message]
2025-04-04 17:02 ` [PATCH 0/3] regulator: userspace-consumer: Add regulator event uevents Mark Brown
2025-04-07 14:17   ` Johann Neuhauser
2025-04-07 15:57     ` Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250404134009.2610460-4-jneuhauser@dh-electronics.com \
    --to=jneuhauser@dh-electronics.com \
    --cc=broonie@kernel.org \
    --cc=corbet@lwn.net \
    --cc=lgirdwood@gmail.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®