You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2024/09/24 15:36:59 UTC

(nuttx) 02/08: Added the common interface sending ccc cmd in I3C driver

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

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

commit 9790c3d3168abf7f1335d0ccecc158575dd413f9
Author: yangshuyong <ya...@xiaomi.com>
AuthorDate: Thu Dec 14 20:28:52 2023 +0800

    Added the common interface sending ccc cmd in I3C driver
    
    Signed-off-by: yangshuyong <ya...@xiaomi.com>
---
 drivers/i3c/device.c       |  40 ++++++++++++++++++
 drivers/i3c/master.c       | 102 ++++++++++++++++++++++-----------------------
 include/nuttx/i3c/device.h |  18 ++++++++
 include/nuttx/i3c/master.h |  18 ++++++++
 4 files changed, 127 insertions(+), 51 deletions(-)

diff --git a/drivers/i3c/device.c b/drivers/i3c/device.c
index 388913a3be..06dfa5718e 100644
--- a/drivers/i3c/device.c
+++ b/drivers/i3c/device.c
@@ -244,6 +244,46 @@ void i3c_device_free_ibi(FAR const struct i3c_device *dev)
   i3c_bus_normaluse_unlock(dev->bus);
 }
 
+/****************************************************************************
+ * Name: i3c_device_send_ccc_cmd
+ *
+ * Description:
+ *   This function is used to send a common ccc command.
+ *
+ * Input Parameters:
+ *   dev  - An I3C device descriptor will be used for
+ *   cmd  - The buf of ccc commands to transfer, only one frame at a time
+ *
+ * Returned Value:
+ *   0 or positive if Success, nagative otherwise.
+ ****************************************************************************/
+
+int i3c_device_send_ccc_cmd(FAR const struct i3c_device *dev,
+                            FAR struct i3c_ccc_cmd *cmd)
+{
+  int ret;
+  FAR struct i3c_master_controller *master;
+
+  if (dev == NULL || cmd == NULL)
+    {
+      return -EINVAL;
+    }
+
+  master = i3c_dev_get_master(dev->desc);
+
+  i3c_bus_normaluse_lock(dev->bus);
+
+  ret = i3c_master_send_ccc_cmd_locked(master, cmd);
+  if (ret < 0)
+    {
+      ret = cmd->err;
+    }
+
+  i3c_bus_normaluse_unlock(dev->bus);
+
+  return ret;
+}
+
 /****************************************************************************
  * Name: i3c_master_find_i3c_dev
  *
diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
index d9c21adcc4..a251ca78e3 100644
--- a/drivers/i3c/master.c
+++ b/drivers/i3c/master.c
@@ -351,57 +351,6 @@ static void i3c_ccc_cmd_init(FAR struct i3c_ccc_cmd *cmd, bool rnw,
   cmd->err = I3C_ERROR_UNKNOWN;
 }
 
-/****************************************************************************
- * Name: i3c_master_send_ccc_cmd_locked
- ****************************************************************************/
-
-static int i3c_master_send_ccc_cmd_locked(
-              FAR struct i3c_master_controller *master,
-              FAR struct i3c_ccc_cmd *cmd)
-{
-  int ret;
-
-  if (!cmd || !master)
-    {
-      return -EINVAL;
-    }
-
-  if (master->init_done &&
-      nxmutex_is_locked(&master->bus.lock))
-    {
-      return -EINVAL;
-    }
-
-  if (!master->ops->send_ccc_cmd)
-    {
-      return -ENOTSUP;
-    }
-
-  if ((cmd->id & I3C_CCC_DIRECT) && (!cmd->dests || !cmd->ndests))
-    {
-      return -EINVAL;
-    }
-
-  if (master->ops->supports_ccc_cmd &&
-      !master->ops->supports_ccc_cmd(master, cmd))
-    {
-      return -ENOTSUP;
-    }
-
-  ret = master->ops->send_ccc_cmd(master, cmd);
-  if (ret)
-    {
-      if (cmd->err != I3C_ERROR_UNKNOWN)
-        {
-          return cmd->err;
-        }
-
-      return ret;
-    }
-
-  return 0;
-}
-
 static FAR struct i3c_dev_desc *
 i3c_master_alloc_i3c_dev(FAR struct i3c_master_controller *master,
                          FAR const struct i3c_device_info *info)
@@ -1305,6 +1254,57 @@ static void i3c_unregister_driver(FAR struct i3c_master_controller *master)
  * Public Functions
  ****************************************************************************/
 
+/****************************************************************************
+ * Name: i3c_master_send_ccc_cmd_locked
+ ****************************************************************************/
+
+int i3c_master_send_ccc_cmd_locked(
+              FAR struct i3c_master_controller *master,
+              FAR struct i3c_ccc_cmd *cmd)
+{
+  int ret;
+
+  if (!cmd || !master)
+    {
+      return -EINVAL;
+    }
+
+  if (master->init_done &&
+      nxmutex_is_locked(&master->bus.lock))
+    {
+      return -EINVAL;
+    }
+
+  if (!master->ops->send_ccc_cmd)
+    {
+      return -ENOTSUP;
+    }
+
+  if ((cmd->id & I3C_CCC_DIRECT) && (!cmd->dests || !cmd->ndests))
+    {
+      return -EINVAL;
+    }
+
+  if (master->ops->supports_ccc_cmd &&
+      !master->ops->supports_ccc_cmd(master, cmd))
+    {
+      return -ENOTSUP;
+    }
+
+  ret = master->ops->send_ccc_cmd(master, cmd);
+  if (ret)
+    {
+      if (cmd->err != I3C_ERROR_UNKNOWN)
+        {
+          return cmd->err;
+        }
+
+      return ret;
+    }
+
+  return 0;
+}
+
 /****************************************************************************
  * Name: i3c_bus_normaluse_lock
  *
diff --git a/include/nuttx/i3c/device.h b/include/nuttx/i3c/device.h
index 2dcb6fff76..e8cc3d5f84 100644
--- a/include/nuttx/i3c/device.h
+++ b/include/nuttx/i3c/device.h
@@ -90,6 +90,7 @@
  ****************************************************************************/
 
 struct i3c_device;
+struct i3c_ccc_cmd;
 
 struct i3c_device_id
 {
@@ -417,4 +418,21 @@ FAR const struct i3c_device *i3c_master_find_i3c_dev(
                               FAR struct i3c_master_controller *master,
                               FAR const struct i3c_device_id *id);
 
+/****************************************************************************
+ * Name: i3c_device_send_ccc_cmd
+ *
+ * Description:
+ *   This function is used to send a common ccc command.
+ *
+ * Input Parameters:
+ *   dev - An I3C device descriptor will be used for
+ *   cmd - The buf of ccc commands to transfer, only one frame at a time
+ *
+ * Returned Value:
+ *   0 or positive if Success, nagative otherwise.
+ ****************************************************************************/
+
+int i3c_device_send_ccc_cmd(FAR const struct i3c_device *dev,
+                            FAR struct i3c_ccc_cmd *cmd);
+
 #endif /* __INCLUDE_NUTTX_I3C_DEV_H */
diff --git a/include/nuttx/i3c/master.h b/include/nuttx/i3c/master.h
index 945338abdf..ce7924cdee 100644
--- a/include/nuttx/i3c/master.h
+++ b/include/nuttx/i3c/master.h
@@ -1147,4 +1147,22 @@ int i3c_master_do_daa(FAR struct i3c_master_controller *master);
 int i3c_master_set_info(FAR struct i3c_master_controller *master,
                         FAR const struct i3c_device_info *info);
 
+/****************************************************************************
+ * Name: i3c_master_send_ccc_cmd_locked
+ *
+ * Description:
+ *   Set master ccc command to i3c device of i3c bus
+ *
+ * Input Parameters:
+ *   master -  Master used to send ccc frames on the bus
+ *   cmd    -  Command data to send on the bus
+ *
+ * Returned Value:
+ *   0 in case of success, an negative error code otherwise.
+ ****************************************************************************/
+
+int i3c_master_send_ccc_cmd_locked(
+              FAR struct i3c_master_controller *master,
+              FAR struct i3c_ccc_cmd *cmd);
+
 #endif /* __INCLUDE_NUTTX_I3C_MASTER_H */