This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 867f977534ec0daa7376c4de2f17a42779976f43
Author: wangshaoxin <[email protected]>
AuthorDate: Wed Sep 9 16:40:42 2026 +0800

    drivers/reset: give reset_control_ops::reset and ::assert a reason
    
    reset and assert are the two places where a reset controller may need more
    than a line id: a controller fronting a peer core acts on a cause, not on a
    piece of hardware, and why the peer is being reset or held is part of the
    request.
    
    Overloading id for that would be wrong in both directions.  A controller
    that really drives hardware would have to dig the line number back out of a
    value it never asked for, and reset_rpmsg would break outright, since it
    puts id on the wire and the remote side matches it against a reset
    control's own id to find the line.
    
    So add a second argument instead.  id keeps its meaning everywhere, and
    reason carries the extra information for the controllers that want it.
    Existing controllers only need their signature widened; reset_rpmsg also
    carries the reason across to the peer so the remote op applies it.
    acquire/release/deassert/status are untouched: they have no event to
    attribute, so a plain line id is all they need.
    
    Expose it to consumers as reset_control_reset_reason() and
    reset_control_assert_reason(), which drive the target with an explicit
    reason handed to the op alongside the line id.  Every element of a reset
    control array gets the same reason, since the reason is orthogonal to the
    line id each element carries.  reset_control_reset() and
    reset_control_assert() become static inline wrappers that pass no reason at
    all, since the line id is not one; a controller that acts on a cause gets
    zero and decides what that means to it.
    
    Also pass the reason through the eic7700x reset controller, the only
    other implementation of reset_control_ops in this tree.
    
    Signed-off-by: wangshaoxin <[email protected]>
---
 arch/risc-v/src/eic7700x/eic7700x_reset_ops.c | 16 +++++----
 drivers/reset/core.c                          | 51 ++++++++++++++++----------
 drivers/reset/reset_rpmsg.c                   | 15 ++++----
 include/nuttx/reset/reset-controller.h        | 11 +++---
 include/nuttx/reset/reset.h                   | 52 ++++++++++++++++++++++++---
 5 files changed, 106 insertions(+), 39 deletions(-)

diff --git a/arch/risc-v/src/eic7700x/eic7700x_reset_ops.c 
b/arch/risc-v/src/eic7700x/eic7700x_reset_ops.c
index 6d026f57512..16d9b521d49 100644
--- a/arch/risc-v/src/eic7700x/eic7700x_reset_ops.c
+++ b/arch/risc-v/src/eic7700x/eic7700x_reset_ops.c
@@ -185,8 +185,9 @@ static int eic7700x_reset_deassert(FAR struct 
reset_controller_dev *rcdev,
  *   the table in eic7700x_reset.c for what counts as that.
  *
  * Input Parameters:
- *   rcdev - The reset controller
- *   id    - The reset line id
+ *   rcdev  - The reset controller
+ *   id     - The reset line id
+ *   reason - Ignored, the lines of this controller carry no cause
  *
  * Returned Value:
  *   OK, -EINVAL if the id names no line, -EROFS if the hardware will not
@@ -195,7 +196,7 @@ static int eic7700x_reset_deassert(FAR struct 
reset_controller_dev *rcdev,
  ****************************************************************************/
 
 static int eic7700x_reset_assert(FAR struct reset_controller_dev *rcdev,
-                                 unsigned int id)
+                                 unsigned int id, unsigned int reason)
 {
   FAR const struct eic7700x_reset_reg_s *desc;
   uintptr_t reg;
@@ -240,8 +241,9 @@ static int eic7700x_reset_assert(FAR struct 
reset_controller_dev *rcdev,
  *   not expect.
  *
  * Input Parameters:
- *   rcdev - The reset controller
- *   id    - The reset line id
+ *   rcdev  - The reset controller
+ *   id     - The reset line id
+ *   reason - Ignored, the lines of this controller carry no cause
  *
  * Returned Value:
  *   OK, or the error eic7700x_reset_assert() refused the line with; a
@@ -250,11 +252,11 @@ static int eic7700x_reset_assert(FAR struct 
reset_controller_dev *rcdev,
  ****************************************************************************/
 
 static int eic7700x_reset_reset(FAR struct reset_controller_dev *rcdev,
-                                unsigned int id)
+                                unsigned int id, unsigned int reason)
 {
   int ret;
 
-  ret = eic7700x_reset_assert(rcdev, id);
+  ret = eic7700x_reset_assert(rcdev, id, reason);
   if (ret < 0)
     {
       return ret;
diff --git a/drivers/reset/core.c b/drivers/reset/core.c
index 93ee2ed1ad7..f313cca67dc 100644
--- a/drivers/reset/core.c
+++ b/drivers/reset/core.c
@@ -78,7 +78,7 @@ rstc_to_array(FAR struct reset_control *rstc)
 }
 
 /****************************************************************************
- * Name: reset_control_array_reset
+ * Name: reset_control_array_reset_reason
  *
  * Description:
  *   This function is used to perform reset operation of a reset control
@@ -86,19 +86,22 @@ rstc_to_array(FAR struct reset_control *rstc)
  *
  * Input Parameters:
  *   resets - An instance of a reset_control_array.
+ *   reason - Reason to hand each element's controller.
  *
  * Returned Value:
  *   A 0 in case of success, otherwise error.
  ****************************************************************************/
 
-static int reset_control_array_reset(FAR struct reset_control_array *resets)
+static int
+reset_control_array_reset_reason(FAR struct reset_control_array *resets,
+                                 unsigned int reason)
 {
   int ret = 0;
   unsigned int i;
 
   for (i = 0; i < resets->num_rstcs; i++)
     {
-      ret = reset_control_reset(resets->rstc[i]);
+      ret = reset_control_reset_reason(resets->rstc[i], reason);
       if (ret < 0)
         {
           return ret;
@@ -109,7 +112,7 @@ static int reset_control_array_reset(FAR struct 
reset_control_array *resets)
 }
 
 /****************************************************************************
- * Name: reset_control_array_assert
+ * Name: reset_control_array_assert_reason
  *
  * Description:
  *   This function is used to perform assert operation of a reset control
@@ -117,19 +120,22 @@ static int reset_control_array_reset(FAR struct 
reset_control_array *resets)
  *
  * Input Parameters:
  *    resets - An instance of a reset_control_array.
+ *    reason - Reason to hand each element's controller.
  *
  * Returned Value:
  *   A 0 in case of success, otherwise error.
  ****************************************************************************/
 
-static int reset_control_array_assert(FAR struct reset_control_array *resets)
+static int
+reset_control_array_assert_reason(FAR struct reset_control_array *resets,
+                                  unsigned int reason)
 {
   int ret = 0;
   unsigned int i;
 
   for (i = 0; i < resets->num_rstcs; i++)
     {
-      ret = reset_control_assert(resets->rstc[i]);
+      ret = reset_control_assert_reason(resets->rstc[i], reason);
       if (ret < 0)
         {
           while (i--)
@@ -817,9 +823,14 @@ reset_control_get(FAR const char *name, int index, bool 
shared,
 }
 
 /****************************************************************************
- * Name: reset_control_reset
+ * Name: reset_control_reset_reason
  *
  * Description:
+ *   Reset the target with an explicit reason, for controllers whose lines
+ *   encode a cause rather than a piece of hardware.  The reason reaches the
+ *   controller unchanged, alongside the reset control's own line id, and
+ *   every element of a reset control array gets the same one.
+ *
  *   On a shared reset line the actual reset pulse is only triggered once for
  *   the lifetime of the reset_control instance: for all but the first caller
  *   this is a no-op.
@@ -827,18 +838,20 @@ reset_control_get(FAR const char *name, int index, bool 
shared,
  *   when reset_control_reset has been used.
  *
  * Input Parameters:
- *   rstc - Reset controller
+ *   rstc   - Reset controller
+ *   reason - Reason to hand the controller, see reset-controller.h
  *
  * Returned Value:
  *   Returns a negative errno if not supported, a positive value if the
  *   reset line is asserted.
  ****************************************************************************/
 
-int reset_control_reset(FAR struct reset_control *rstc)
+int reset_control_reset_reason(FAR struct reset_control *rstc,
+                               unsigned int reason)
 {
   int ret;
 
-  rstinfo("Enter: reset_control_reset\n");
+  rstinfo("Enter: reset_control_reset_reason\n");
 
   if (rstc == NULL)
     {
@@ -848,7 +861,7 @@ int reset_control_reset(FAR struct reset_control *rstc)
 
   if (rstc->array)
     {
-      return reset_control_array_reset(rstc_to_array(rstc));
+      return reset_control_array_reset_reason(rstc_to_array(rstc), reason);
     }
 
   if (!rstc->rcdev->ops->reset)
@@ -877,7 +890,7 @@ int reset_control_reset(FAR struct reset_control *rstc)
         }
     }
 
-  ret = rstc->rcdev->ops->reset(rstc->rcdev, rstc->id);
+  ret = rstc->rcdev->ops->reset(rstc->rcdev, rstc->id, reason);
 
   /* shared:1 and reset failed, triggered_count subtract 1 */
 
@@ -890,7 +903,7 @@ int reset_control_reset(FAR struct reset_control *rstc)
 }
 
 /****************************************************************************
- * Name: reset_control_assert
+ * Name: reset_control_assert_reason
  *
  * Description:
  *   Asserts the reset line.
@@ -906,16 +919,18 @@ int reset_control_reset(FAR struct reset_control *rstc)
  *   return -EBUSY.
  *
  * Input Parameters:
- *   rstc - Reset controller
+ *   rstc   - Reset controller
+ *   reason - Reason to hand the controller, see reset-controller.h
  *
  * Returned Value:
  *   Returns a negative errno if not supported, a positive value if the
  *   reset line is asserted.
  ****************************************************************************/
 
-int reset_control_assert(FAR struct reset_control *rstc)
+int reset_control_assert_reason(FAR struct reset_control *rstc,
+                                unsigned int reason)
 {
-  rstinfo("Enter: reset_control_assert\n");
+  rstinfo("Enter: reset_control_assert_reason\n");
   if (rstc == NULL)
     {
       rsterr("rstc is null\n");
@@ -924,7 +939,7 @@ int reset_control_assert(FAR struct reset_control *rstc)
 
   if (rstc->array)
     {
-      return reset_control_array_assert(rstc_to_array(rstc));
+      return reset_control_array_assert_reason(rstc_to_array(rstc), reason);
     }
 
   if (rstc->shared)
@@ -975,7 +990,7 @@ int reset_control_assert(FAR struct reset_control *rstc)
     }
 
 #undef assert
-  return rstc->rcdev->ops->assert(rstc->rcdev, rstc->id);
+  return rstc->rcdev->ops->assert(rstc->rcdev, rstc->id, reason);
 }
 
 /****************************************************************************
diff --git a/drivers/reset/reset_rpmsg.c b/drivers/reset/reset_rpmsg.c
index 79b437fb7b5..325a7284018 100644
--- a/drivers/reset/reset_rpmsg.c
+++ b/drivers/reset/reset_rpmsg.c
@@ -89,6 +89,7 @@ begin_packed_struct struct rpmsg_reset_msg
 {
   struct reset_rpmsg_header_s    header;
   int                            id;
+  unsigned int                   reason;
   bool                           shared;
   bool                           acquired;
   char                           name[0];
@@ -137,10 +138,10 @@ static int reset_rpmsg_release(FAR struct 
reset_controller_dev *rcdev,
                                unsigned int id);
 
 static int reset_rpmsg_reset(FAR struct reset_controller_dev *rcdev,
-                             unsigned int id);
+                             unsigned int id, unsigned int reason);
 
 static int reset_rpmsg_assert(FAR struct reset_controller_dev *rcdev,
-                              unsigned int id);
+                              unsigned int id, unsigned int reason);
 
 static int reset_rpmsg_deassert(FAR struct reset_controller_dev *rcdev,
                                 unsigned int id);
@@ -390,7 +391,7 @@ static int reset_rpmsg_release(FAR struct 
reset_controller_dev *rcdev,
 }
 
 static int reset_rpmsg_reset(FAR struct reset_controller_dev *rcdev,
-                             unsigned int id)
+                             unsigned int id, unsigned int reason)
 {
   FAR struct rpmsg_endpoint *ept;
   FAR struct rpmsg_reset_msg *msg;
@@ -412,13 +413,14 @@ static int reset_rpmsg_reset(FAR struct 
reset_controller_dev *rcdev,
 
   strlcpy(msg->name, name, len - sizeof(*msg));
   msg->id = id;
+  msg->reason = reason;
   return reset_rpmsg_sendrecv(ept, RESET_RPMSG_RESET,
                               (struct reset_rpmsg_header_s *)msg,
                               len);
 }
 
 static int reset_rpmsg_assert(FAR struct reset_controller_dev *rcdev,
-                              unsigned int id)
+                              unsigned int id, unsigned int reason)
 {
   FAR struct rpmsg_endpoint *ept;
   FAR struct rpmsg_reset_msg *msg;
@@ -440,6 +442,7 @@ static int reset_rpmsg_assert(FAR struct 
reset_controller_dev *rcdev,
 
   strlcpy(msg->name, name, len - sizeof(*msg));
   msg->id = id;
+  msg->reason = reason;
   return reset_rpmsg_sendrecv(ept, RESET_RPMSG_ASSERT,
                               (struct reset_rpmsg_header_s *)msg,
                               len);
@@ -616,7 +619,7 @@ static int reset_rpmsg_reset_handler(FAR struct 
rpmsg_endpoint *ept,
   FAR struct rpmsg_reset_msg *msg = data;
   FAR struct reset_control *rstc = reset_rpmsg_find(ept, msg->name, msg->id);
 
-  msg->header.result = reset_control_reset(rstc);
+  msg->header.result = reset_control_reset_reason(rstc, msg->reason);
   return rpmsg_send(ept, data, len);
 }
 
@@ -627,7 +630,7 @@ static int reset_rpmsg_assert_handler(FAR struct 
rpmsg_endpoint *ept,
   FAR struct rpmsg_reset_msg *msg = data;
   FAR struct reset_control *rstc = reset_rpmsg_find(ept, msg->name, msg->id);
 
-  msg->header.result = reset_control_assert(rstc);
+  msg->header.result = reset_control_assert_reason(rstc, msg->reason);
   return rpmsg_send(ept, data, len);
 }
 
diff --git a/include/nuttx/reset/reset-controller.h 
b/include/nuttx/reset/reset-controller.h
index f7378818901..24e3d4ecf13 100644
--- a/include/nuttx/reset/reset-controller.h
+++ b/include/nuttx/reset/reset-controller.h
@@ -61,8 +61,11 @@ struct reset_lineinfo_s
 
 /* struct reset_control_ops - reset controller driver operations
  * reset: for self-deasserting resets, does all necessary
- *         things to reset the device
- * assert: manually assert the reset line, if supported
+ *         things to reset the device.  reason is passed through from the
+ *         caller for controllers that act on a cause rather than on a piece
+ *         of hardware; a controller driving real hardware only needs id.
+ * assert: manually assert the reset line, if supported.  reason is passed
+ *         through the same way as for reset.
  * deassert: manually deassert the reset line, if supported
  * status: return the status of the reset line, if supported
  */
@@ -74,9 +77,9 @@ struct reset_control_ops
   CODE int (*release)(FAR struct reset_controller_dev *rcdev,
                       unsigned int id);
   CODE int (*reset)(FAR struct reset_controller_dev *rcdev,
-                    unsigned int id);
+                    unsigned int id, unsigned int reason);
   CODE int (*assert)(FAR struct reset_controller_dev *rcdev,
-                     unsigned int id);
+                     unsigned int id, unsigned int reason);
   CODE int (*deassert)(FAR struct reset_controller_dev *rcdev,
                        unsigned int id);
   CODE int (*status)(FAR struct reset_controller_dev *rcdev,
diff --git a/include/nuttx/reset/reset.h b/include/nuttx/reset/reset.h
index cd50deafed7..be5f2718569 100644
--- a/include/nuttx/reset/reset.h
+++ b/include/nuttx/reset/reset.h
@@ -74,31 +74,75 @@ struct reset_control
 
 struct reset_control;
 
+/****************************************************************************
+ * Name: reset_control_reset_reason()
+ *
+ * Description:
+ *   Same as reset_control_reset(), but also hands the controller an explicit
+ *   reason.  For controllers whose lines encode a cause rather than a piece
+ *   of hardware (e.g. reset_ipc), this lets one reset control trigger any
+ *   cause without acquiring one control per line.
+ *
+ * Input Parameters:
+ *   rstc   - a instance of reset control.
+ *   reason - the reason to hand the controller, see reset-controller.h.
+ *
+ ****************************************************************************/
+
+int reset_control_reset_reason(FAR struct reset_control *rstc,
+                               unsigned int reason);
+
 /****************************************************************************
  * Name: reset_control_reset()
  *
  * Description:
- *   this function is used to execute reset ops.
+ *   this function is used to execute reset ops, with no reason to give.  A
+ *   controller that acts on a cause gets zero and decides what that means
+ *   to it.
  *
  * Input Parameters:
  *   rstc - a instance of reset control.
  *
  ****************************************************************************/
 
-int reset_control_reset(FAR struct reset_control *rstc);
+static inline int reset_control_reset(FAR struct reset_control *rstc)
+{
+  return reset_control_reset_reason(rstc, 0);
+}
+
+/****************************************************************************
+ * Name: reset_control_assert_reason()
+ *
+ * Description:
+ *   Same as reset_control_assert(), but also hands the controller an
+ *   explicit reason, the same way reset_control_reset_reason() does for the
+ *   reset op.
+ *
+ * Input Parameters:
+ *   rstc   - an instance of reset control.
+ *   reason - the reason to hand the controller, see reset-controller.h.
+ *
+ ****************************************************************************/
+
+int reset_control_assert_reason(FAR struct reset_control *rstc,
+                                unsigned int reason);
 
 /****************************************************************************
  * Name: reset_control_assert()
  *
  * Description:
- *   This function is used to execute assert ops.
+ *   This function is used to execute assert ops, with no reason to give, as
+ *   for reset_control_reset().
  *
  * Input Parameters:
  *   rstc - An instance of reset control.
  *
  ****************************************************************************/
 
-int reset_control_assert(FAR struct reset_control *rstc);
+static inline int reset_control_assert(FAR struct reset_control *rstc)
+{
+  return reset_control_assert_reason(rstc, 0);
+}
 
 /****************************************************************************
  * Name: reset_control_deassert()

Reply via email to