You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2020/12/30 19:52:39 UTC

[GitHub] [incubator-nuttx] acassis opened a new pull request #2628: Add generic efuse driver for NuttX

acassis opened a new pull request #2628:
URL: https://github.com/apache/incubator-nuttx/pull/2628


   ## Summary
   Add generic efuse driver for NuttX
   ## Impact
   Add a new efuse subsystem to NuttX
   ## Testing
   ESP32
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a change in pull request #2628: Add generic efuse driver for NuttX

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on a change in pull request #2628:
URL: https://github.com/apache/incubator-nuttx/pull/2628#discussion_r556275695



##########
File path: drivers/efuse/efuse.c
##########
@@ -0,0 +1,395 @@
+/****************************************************************************
+ * drivers/efuse/efuse.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <string.h>
+#include <fcntl.h>
+#include <assert.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <nuttx/fs/fs.h>
+#include <nuttx/irq.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/power/pm.h>
+#include <nuttx/semaphore.h>
+#include <nuttx/efuse/efuse.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Type Definitions
+ ****************************************************************************/
+
+/* This structure describes the state of the upper half driver */
+
+struct efuse_upperhalf_s
+{
+  sem_t     exclsem;  /* Supports mutual exclusion */
+  FAR char *path;     /* Registration path */
+
+  /* The contained lower-half driver */
+
+  FAR struct efuse_lowerhalf_s *lower;
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int     efuse_open(FAR struct file *filep);
+static int     efuse_close(FAR struct file *filep);
+static ssize_t efuse_read(FAR struct file *filep, FAR char *buffer,
+                          size_t buflen);
+static ssize_t efuse_write(FAR struct file *filep, FAR const char *buffer,
+                           size_t buflen);
+static int     efuse_ioctl(FAR struct file *filep, int cmd,
+                           unsigned long arg);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct file_operations g_efuseops =
+{
+  efuse_open,  /* open */
+  efuse_close, /* close */
+  efuse_read,  /* read */
+  efuse_write, /* write */
+  NULL,        /* seek */
+  efuse_ioctl, /* ioctl */
+  NULL         /* poll */
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: efuse_open
+ *
+ * Description:
+ *   This function is called whenever the efuse timer device is opened.
+ *
+ ****************************************************************************/
+
+static int efuse_open(FAR struct file *filep)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: efuse_close
+ *
+ * Description:
+ *   This function is called when the efuse timer device is closed.
+ *
+ ****************************************************************************/
+
+static int efuse_close(FAR struct file *filep)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: efuse_read
+ *
+ * Description:
+ *   A dummy read method.  This is provided only to satisfy the VFS layer.
+ *
+ ****************************************************************************/
+
+static ssize_t efuse_read(FAR struct file *filep, FAR char *buffer,
+                         size_t buflen)
+{
+  /* Return zero -- usually meaning end-of-file */
+
+  return 0;
+}
+
+/****************************************************************************
+ * Name: efuse_write
+ *
+ * Description:
+ *   A dummy write method.  This is provided only to satisfy the VFS layer.
+ *
+ ****************************************************************************/
+
+static ssize_t efuse_write(FAR struct file *filep, FAR const char *buffer,
+                          size_t buflen)
+{
+  return 0;

Review comment:
       change 0 to buflen?

##########
File path: drivers/efuse/efuse.c
##########
@@ -0,0 +1,395 @@
+/****************************************************************************
+ * drivers/efuse/efuse.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <string.h>
+#include <fcntl.h>
+#include <assert.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <nuttx/fs/fs.h>
+#include <nuttx/irq.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/power/pm.h>
+#include <nuttx/semaphore.h>
+#include <nuttx/efuse/efuse.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Type Definitions
+ ****************************************************************************/
+
+/* This structure describes the state of the upper half driver */
+
+struct efuse_upperhalf_s
+{
+  sem_t     exclsem;  /* Supports mutual exclusion */
+  FAR char *path;     /* Registration path */
+
+  /* The contained lower-half driver */
+
+  FAR struct efuse_lowerhalf_s *lower;
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int     efuse_open(FAR struct file *filep);
+static int     efuse_close(FAR struct file *filep);
+static ssize_t efuse_read(FAR struct file *filep, FAR char *buffer,
+                          size_t buflen);
+static ssize_t efuse_write(FAR struct file *filep, FAR const char *buffer,
+                           size_t buflen);
+static int     efuse_ioctl(FAR struct file *filep, int cmd,
+                           unsigned long arg);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct file_operations g_efuseops =
+{
+  efuse_open,  /* open */
+  efuse_close, /* close */
+  efuse_read,  /* read */
+  efuse_write, /* write */
+  NULL,        /* seek */
+  efuse_ioctl, /* ioctl */
+  NULL         /* poll */
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: efuse_open
+ *
+ * Description:
+ *   This function is called whenever the efuse timer device is opened.
+ *
+ ****************************************************************************/
+
+static int efuse_open(FAR struct file *filep)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: efuse_close
+ *
+ * Description:
+ *   This function is called when the efuse timer device is closed.
+ *
+ ****************************************************************************/
+
+static int efuse_close(FAR struct file *filep)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: efuse_read
+ *
+ * Description:
+ *   A dummy read method.  This is provided only to satisfy the VFS layer.
+ *
+ ****************************************************************************/
+
+static ssize_t efuse_read(FAR struct file *filep, FAR char *buffer,
+                         size_t buflen)
+{
+  /* Return zero -- usually meaning end-of-file */
+
+  return 0;
+}
+
+/****************************************************************************
+ * Name: efuse_write
+ *
+ * Description:
+ *   A dummy write method.  This is provided only to satisfy the VFS layer.
+ *
+ ****************************************************************************/
+
+static ssize_t efuse_write(FAR struct file *filep, FAR const char *buffer,
+                          size_t buflen)
+{
+  return 0;
+}
+
+/****************************************************************************
+ * Name: efuse_ioctl
+ *
+ * Description:
+ *   The standard ioctl method.  This is where ALL of the efuse timer
+ *   work is done.
+ *
+ ****************************************************************************/
+
+static int efuse_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
+{
+  FAR struct inode             *inode = filep->f_inode;
+  FAR struct efuse_upperhalf_s *upper;
+  FAR struct efuse_lowerhalf_s *lower;
+  int                           ret;
+
+  minfo("cmd: %d arg: %lu\n", cmd, arg);
+  upper = inode->i_private;
+  DEBUGASSERT(upper != NULL);
+  lower = upper->lower;
+  DEBUGASSERT(lower != NULL);
+
+  /* Get exclusive access to the device structures */
+
+  ret = nxsem_wait(&upper->exclsem);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  /* Handle built-in ioctl commands */
+
+  switch (cmd)
+    {
+    /* cmd:         EFUSEIOC_READ_FIELD
+     * Description: Read a field
+     * Argument:    A pointer to a struct efuse_param.
+     *              Where the field is an array.
+     *              Each item in the array is a pointer to an efuse_desc_t
+     *              variable.
+     *              An efuse_desc_t variable contains an offset to a field
+     *              or subfield and its size in bits.
+     *              The size param is a redundancy, and it is the sum
+     *              of all subfields sizes from efuse_desc_t in bits.
+     *              The data is a pointer to a pre-allocated space
+     *              where the driver will load the data read from efuse.
+     */
+
+    case EFUSEIOC_READ_FIELD:
+      {
+        FAR struct efuse_param *param =
+                   (FAR struct efuse_param *)((uintptr_t)arg);
+
+        /* Read the efuse */
+
+        DEBUGASSERT(lower->ops->read_field); /* Required */
+        ret = lower->ops->read_field(lower,
+                                     (const efuse_desc_t **) param->field,

Review comment:
       don't neec cast

##########
File path: drivers/efuse/efuse.c
##########
@@ -0,0 +1,395 @@
+/****************************************************************************
+ * drivers/efuse/efuse.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <string.h>
+#include <fcntl.h>
+#include <assert.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <nuttx/fs/fs.h>
+#include <nuttx/irq.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/power/pm.h>
+#include <nuttx/semaphore.h>
+#include <nuttx/efuse/efuse.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Type Definitions
+ ****************************************************************************/
+
+/* This structure describes the state of the upper half driver */
+
+struct efuse_upperhalf_s
+{
+  sem_t     exclsem;  /* Supports mutual exclusion */
+  FAR char *path;     /* Registration path */
+
+  /* The contained lower-half driver */
+
+  FAR struct efuse_lowerhalf_s *lower;
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int     efuse_open(FAR struct file *filep);
+static int     efuse_close(FAR struct file *filep);
+static ssize_t efuse_read(FAR struct file *filep, FAR char *buffer,
+                          size_t buflen);
+static ssize_t efuse_write(FAR struct file *filep, FAR const char *buffer,
+                           size_t buflen);
+static int     efuse_ioctl(FAR struct file *filep, int cmd,
+                           unsigned long arg);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct file_operations g_efuseops =
+{
+  efuse_open,  /* open */
+  efuse_close, /* close */
+  efuse_read,  /* read */
+  efuse_write, /* write */
+  NULL,        /* seek */
+  efuse_ioctl, /* ioctl */
+  NULL         /* poll */
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: efuse_open
+ *
+ * Description:
+ *   This function is called whenever the efuse timer device is opened.
+ *
+ ****************************************************************************/
+
+static int efuse_open(FAR struct file *filep)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: efuse_close
+ *
+ * Description:
+ *   This function is called when the efuse timer device is closed.
+ *
+ ****************************************************************************/
+
+static int efuse_close(FAR struct file *filep)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: efuse_read
+ *
+ * Description:
+ *   A dummy read method.  This is provided only to satisfy the VFS layer.
+ *
+ ****************************************************************************/
+
+static ssize_t efuse_read(FAR struct file *filep, FAR char *buffer,
+                         size_t buflen)
+{
+  /* Return zero -- usually meaning end-of-file */
+
+  return 0;
+}
+
+/****************************************************************************
+ * Name: efuse_write
+ *
+ * Description:
+ *   A dummy write method.  This is provided only to satisfy the VFS layer.
+ *
+ ****************************************************************************/
+
+static ssize_t efuse_write(FAR struct file *filep, FAR const char *buffer,
+                          size_t buflen)
+{
+  return 0;
+}
+
+/****************************************************************************
+ * Name: efuse_ioctl
+ *
+ * Description:
+ *   The standard ioctl method.  This is where ALL of the efuse timer
+ *   work is done.
+ *
+ ****************************************************************************/
+
+static int efuse_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
+{
+  FAR struct inode             *inode = filep->f_inode;
+  FAR struct efuse_upperhalf_s *upper;
+  FAR struct efuse_lowerhalf_s *lower;
+  int                           ret;
+
+  minfo("cmd: %d arg: %lu\n", cmd, arg);
+  upper = inode->i_private;
+  DEBUGASSERT(upper != NULL);
+  lower = upper->lower;
+  DEBUGASSERT(lower != NULL);
+
+  /* Get exclusive access to the device structures */
+
+  ret = nxsem_wait(&upper->exclsem);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  /* Handle built-in ioctl commands */
+
+  switch (cmd)
+    {
+    /* cmd:         EFUSEIOC_READ_FIELD
+     * Description: Read a field
+     * Argument:    A pointer to a struct efuse_param.
+     *              Where the field is an array.
+     *              Each item in the array is a pointer to an efuse_desc_t
+     *              variable.
+     *              An efuse_desc_t variable contains an offset to a field
+     *              or subfield and its size in bits.
+     *              The size param is a redundancy, and it is the sum
+     *              of all subfields sizes from efuse_desc_t in bits.
+     *              The data is a pointer to a pre-allocated space
+     *              where the driver will load the data read from efuse.
+     */
+
+    case EFUSEIOC_READ_FIELD:
+      {
+        FAR struct efuse_param *param =
+                   (FAR struct efuse_param *)((uintptr_t)arg);
+
+        /* Read the efuse */
+
+        DEBUGASSERT(lower->ops->read_field); /* Required */
+        ret = lower->ops->read_field(lower,
+                                     (const efuse_desc_t **) param->field,
+                                     param->data,
+                                     param->size);
+      }
+      break;
+
+    /* cmd:         EFUSEIOC_WRITE_FIELD
+     * Description: Write a field
+     * Argument: A pointer to a struct efuse_param.
+     *           Where the field is an array.
+     *           Each item in the array is a pointer to an efuse_desc_t
+     *           variable.
+     *           An efuse_desc_t variable contains an offset to a field
+     *           or subfield and its size in bits.
+     *           The size param is a redundancy, and it is the sum
+     *           of all subfields sizes from efuse_desc_t in bits.
+     *           The data is a pointer to a pre-allocated space
+     *           where the user wrote the value that he wants
+     *           to write in a field or subfield.
+     */
+
+    case EFUSEIOC_WRITE_FIELD:
+      {
+        FAR struct efuse_param *param =
+                   (FAR struct efuse_param *)((uintptr_t)arg);
+
+        /* Write the efuse */
+
+        DEBUGASSERT(lower->ops->write_field); /* Required */
+        ret = lower->ops->write_field(lower,
+                                      (const efuse_desc_t **) param->field,
+                                      param->data,
+                                      param->size);
+      }
+      break;
+
+    default:
+      {
+        minfo("Forwarding unrecognized cmd: %d arg: %lu\n", cmd, arg);
+
+        /* Ioctls commands that are not recognized by the "upper-half"
+         * driver are forwarded to the lower half driver through this
+         * method.
+         */
+
+        if (lower->ops->ioctl) /* Optional */
+          {
+            ret = lower->ops->ioctl(lower, cmd, arg);
+          }
+        else
+          {
+            ret = -ENOTTY;
+          }
+      }
+      break;
+    }
+
+  nxsem_post(&upper->exclsem);
+  return ret;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: efuse_register
+ *
+ * Description:
+ *   This function binds an instance of a "lower half" efuse driver with
+ *   the "upper half" efuse device and registers that device so that can
+ *   be used by application code.
+ *
+ * Input Parameters:
+ *   dev path - The full path to the driver to be registered in the NuttX
+ *     pseudo-filesystem.  The recommended convention is to name all
+ *     efuse drivers as "/dev/efuse".
+ *   lower - A pointer to an instance of lower half efuse driver.  This
+ *     instance is bound to the efuse driver and must persists as long as
+ *     the driver persists.
+ *
+ * Returned Value:
+ *   On success, a non-NULL handle is returned to the caller.  In the event
+ *   of any failure, a NULL value is returned.
+ *
+ ****************************************************************************/
+
+FAR void *efuse_register(FAR const char *path,
+                         FAR struct efuse_lowerhalf_s *lower)
+{
+  FAR struct efuse_upperhalf_s *upper;
+  int ret;
+
+  DEBUGASSERT(path && lower);
+  minfo("Entry: path=%s\n", path);
+
+  /* Allocate the upper-half data structure */
+
+  upper = (FAR struct efuse_upperhalf_s *)
+          kmm_zalloc(sizeof(struct efuse_upperhalf_s));
+  if (!upper)
+    {
+      merr("Upper half allocation failed\n");
+      goto errout;
+    }
+
+  /* Initialize the efuse timer device structure (it was already zeroed
+   * by kmm_zalloc()).
+   */
+
+  nxsem_init(&upper->exclsem, 0, 1);
+  upper->lower = lower;
+
+  /* Copy the registration path */
+
+  upper->path = strdup(path);
+  if (!upper->path)
+    {
+      merr("Path allocation failed\n");
+      goto errout_with_upper;
+    }
+
+  /* Register the efuse timer device */
+
+  ret = register_driver(path, &g_efuseops, 0666, upper);
+  if (ret < 0)
+    {
+      merr("register_driver failed: %d\n", ret);
+      goto errout_with_path;
+    }
+
+  return (FAR void *)upper;
+
+errout_with_path:
+  kmm_free(upper->path);
+
+errout_with_upper:
+  nxsem_destroy(&upper->exclsem);
+  kmm_free(upper);
+
+errout:
+  return NULL;
+}
+
+/****************************************************************************
+ * Name: efuse_unregister
+ *
+ * Description:
+ *   This function can be called to disable and unregister the efuse
+ *   device driver.
+ *
+ * Input Parameters:
+ *   handle - This is the handle that was returned by efuse_register()
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+void efuse_unregister(FAR void *handle)
+{
+  FAR struct efuse_upperhalf_s *upper;
+  FAR struct efuse_lowerhalf_s *lower;
+
+  /* Recover the pointer to the upper-half driver state */
+
+  upper = (FAR struct efuse_upperhalf_s *)handle;
+  DEBUGASSERT(upper != NULL);
+  lower = upper->lower;
+  DEBUGASSERT(lower != NULL);
+
+  minfo("Unregistering: %s\n", upper->path);
+
+  /* Unregister the efuse timer device */
+
+  unregister_driver(upper->path);
+
+  /* Then free all of the driver resources */
+
+  kmm_free(upper->path);
+  nxsem_destroy(&upper->exclsem);
+  kmm_free(lower);

Review comment:
       should we let caller free lower?

##########
File path: include/nuttx/efuse/efuse.h
##########
@@ -0,0 +1,155 @@
+/****************************************************************************
+ * include/nuttx/efuse/efuse.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_EFUSE_EFUSE_H
+#define __INCLUDE_NUTTX_EFUSE_EFUSE_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs/ioctl.h>
+
+#include <signal.h>
+#include <stdint.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Command:     EFUSEIOC_READ_FIELD
+ * Description: Read a blob of bits from an efuse field.
+ * Arguments:   A structure containing the field[], a dst pointer, and size
+ *              of bits to be read from efuses.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD      _EFUSEIOC(0x0001)
+
+/* Command:     EFUSEIOC_WRITE_FIELD
+ * Description: Write a blob of bits to an efuse's field
+ * Arguments:   A structure containing the field[], the src memory and the
+ *              amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD     _EFUSEIOC(0x0002)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* Structure eFuse field */
+
+struct efuse_desc_s
+{
+  uint16_t   bit_offset; /* Bit offset related to beginning of efuse */
+  uint16_t   bit_count;  /* Length of bit field */
+};
+
+/* Type definition for an eFuse field */
+
+typedef struct efuse_desc_s efuse_desc_t;
+
+/* Structs with the parameters passed to the IOCTLs */
+
+struct efuse_param
+{
+  FAR const efuse_desc_t **field;
+  size_t  size;
+  FAR uint8_t *data;
+};
+
+/* This structure provides the "lower-half" driver operations available to
+ * the "upper-half" driver.
+ */
+
+struct efuse_lowerhalf_s;
+struct efuse_ops_s
+{
+  /* Required methods *******************************************************/
+
+  /* Read an EFUSE bit */
+
+  CODE int (*read_field)(FAR struct efuse_lowerhalf_s *lower,
+                         FAR const efuse_desc_t *field[],
+                         FAR uint8_t *data, size_t bit_size);
+
+  /* Write an EFUSE bit */
+
+  CODE int (*write_field)(FAR struct efuse_lowerhalf_s *lower,
+                          FAR const efuse_desc_t *field[],
+                          FAR const uint8_t *data, size_t bit_size);
+
+  /* Any ioctl commands that are not recognized by the "upper-half" driver
+   * are forwarded to the lower half driver through this method.
+   */
+
+  CODE int (*ioctl)(FAR struct efuse_lowerhalf_s *lower, int cmd,
+                    unsigned long arg);
+};
+
+/* This structure provides the publicly visible representation of the
+ * "lower-half" driver state structure.  "lower half" drivers will have an
+ * internal structure definition that will be cast-compatible with this
+ * structure definitions.
+ */
+
+struct efuse_lowerhalf_s
+{
+  /* Publicly visible portion of the "lower-half" driver state structure. */
+
+  FAR const struct efuse_ops_s  *ops;  /* Lower half operations */
+
+  /* The remainder of the structure is used by the "lower-half" driver
+   * for whatever state storage that it may need.
+   */
+
+  void   *upper;                       /* Pointer to watchdog_upperhalf_s */
+};
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+

Review comment:
       add efuse_register/efuse_unregister prototype here

##########
File path: include/nuttx/efuse/efuse.h
##########
@@ -0,0 +1,155 @@
+/****************************************************************************
+ * include/nuttx/efuse/efuse.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_EFUSE_EFUSE_H
+#define __INCLUDE_NUTTX_EFUSE_EFUSE_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs/ioctl.h>
+
+#include <signal.h>
+#include <stdint.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Command:     EFUSEIOC_READ_FIELD
+ * Description: Read a blob of bits from an efuse field.
+ * Arguments:   A structure containing the field[], a dst pointer, and size
+ *              of bits to be read from efuses.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD      _EFUSEIOC(0x0001)
+
+/* Command:     EFUSEIOC_WRITE_FIELD
+ * Description: Write a blob of bits to an efuse's field
+ * Arguments:   A structure containing the field[], the src memory and the
+ *              amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD     _EFUSEIOC(0x0002)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* Structure eFuse field */
+
+struct efuse_desc_s
+{
+  uint16_t   bit_offset; /* Bit offset related to beginning of efuse */
+  uint16_t   bit_count;  /* Length of bit field */
+};
+
+/* Type definition for an eFuse field */
+
+typedef struct efuse_desc_s efuse_desc_t;
+
+/* Structs with the parameters passed to the IOCTLs */
+
+struct efuse_param
+{
+  FAR const efuse_desc_t **field;

Review comment:
       why not use efuse_desc_t *field?

##########
File path: include/nuttx/efuse/efuse.h
##########
@@ -0,0 +1,155 @@
+/****************************************************************************
+ * include/nuttx/efuse/efuse.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_EFUSE_EFUSE_H
+#define __INCLUDE_NUTTX_EFUSE_EFUSE_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs/ioctl.h>
+
+#include <signal.h>
+#include <stdint.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Command:     EFUSEIOC_READ_FIELD
+ * Description: Read a blob of bits from an efuse field.
+ * Arguments:   A structure containing the field[], a dst pointer, and size
+ *              of bits to be read from efuses.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD      _EFUSEIOC(0x0001)
+
+/* Command:     EFUSEIOC_WRITE_FIELD
+ * Description: Write a blob of bits to an efuse's field
+ * Arguments:   A structure containing the field[], the src memory and the
+ *              amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD     _EFUSEIOC(0x0002)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* Structure eFuse field */
+
+struct efuse_desc_s
+{
+  uint16_t   bit_offset;     /* Bit offset related to beginning of efuse */
+  uint16_t   bit_count;      /* Length of bit field */
+};
+
+/* Type definition for an eFuse field */
+
+typedef struct efuse_desc_s efuse_desc_t;
+
+/* Structs with the parameters passed to the IOCTLs */
+
+struct efuse_param
+{
+  efuse_desc_t **field;
+  size_t  size;
+  uint8_t *data;
+};
+
+/* This structure provides the "lower-half" driver operations available to
+ * the "upper-half" driver.
+ */
+
+struct efuse_lowerhalf_s;
+struct efuse_ops_s
+{
+  /* Required methods *******************************************************/
+
+  /* Read an EFUSE bit */
+
+  CODE int (*read_field)(FAR struct efuse_lowerhalf_s *lower,
+                         const efuse_desc_t *field[],
+                         uint8_t *data, size_t bit_size);
+
+  /* Write an EFUSE bit */
+
+  CODE int (*write_field)(FAR struct efuse_lowerhalf_s *lower,
+                          const efuse_desc_t *field[],
+                          const uint8_t *data, size_t bit_size);
+
+  /* Any ioctl commands that are not recognized by the "upper-half" driver
+   * are forwarded to the lower half driver through this method.
+   */
+
+  CODE int (*ioctl)(FAR struct efuse_lowerhalf_s *lower, int cmd,
+                    unsigned long arg);
+};
+
+/* This structure provides the publicly visible representation of the
+ * "lower-half" driver state structure.  "lower half" drivers will have an
+ * internal structure definition that will be cast-compatible with this
+ * structure definitions.
+ */
+
+struct efuse_lowerhalf_s
+{
+  /* Publicly visible portion of the "lower-half" driver state structure. */
+
+  FAR const struct efuse_ops_s  *ops;  /* Lower half operations */
+
+  /* The remainder of the structure is used by the "lower-half" driver
+   * for whatever state storage that it may need.
+   */
+
+  void   *upper;                       /* Pointer to watchdog_upperhalf_s */

Review comment:
       remove upper, no body use this field.

##########
File path: drivers/efuse/efuse.c
##########
@@ -0,0 +1,395 @@
+/****************************************************************************
+ * drivers/efuse/efuse.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <string.h>
+#include <fcntl.h>
+#include <assert.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <nuttx/fs/fs.h>
+#include <nuttx/irq.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/power/pm.h>
+#include <nuttx/semaphore.h>
+#include <nuttx/efuse/efuse.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Type Definitions
+ ****************************************************************************/
+
+/* This structure describes the state of the upper half driver */
+
+struct efuse_upperhalf_s
+{
+  sem_t     exclsem;  /* Supports mutual exclusion */
+  FAR char *path;     /* Registration path */
+
+  /* The contained lower-half driver */
+
+  FAR struct efuse_lowerhalf_s *lower;
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int     efuse_open(FAR struct file *filep);
+static int     efuse_close(FAR struct file *filep);
+static ssize_t efuse_read(FAR struct file *filep, FAR char *buffer,
+                          size_t buflen);
+static ssize_t efuse_write(FAR struct file *filep, FAR const char *buffer,
+                           size_t buflen);
+static int     efuse_ioctl(FAR struct file *filep, int cmd,
+                           unsigned long arg);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct file_operations g_efuseops =
+{
+  efuse_open,  /* open */
+  efuse_close, /* close */
+  efuse_read,  /* read */
+  efuse_write, /* write */
+  NULL,        /* seek */
+  efuse_ioctl, /* ioctl */
+  NULL         /* poll */
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: efuse_open
+ *
+ * Description:
+ *   This function is called whenever the efuse timer device is opened.
+ *
+ ****************************************************************************/
+
+static int efuse_open(FAR struct file *filep)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: efuse_close
+ *
+ * Description:
+ *   This function is called when the efuse timer device is closed.
+ *
+ ****************************************************************************/
+
+static int efuse_close(FAR struct file *filep)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: efuse_read
+ *
+ * Description:
+ *   A dummy read method.  This is provided only to satisfy the VFS layer.
+ *
+ ****************************************************************************/
+
+static ssize_t efuse_read(FAR struct file *filep, FAR char *buffer,
+                         size_t buflen)
+{
+  /* Return zero -- usually meaning end-of-file */
+
+  return 0;
+}
+
+/****************************************************************************
+ * Name: efuse_write
+ *
+ * Description:
+ *   A dummy write method.  This is provided only to satisfy the VFS layer.
+ *
+ ****************************************************************************/
+
+static ssize_t efuse_write(FAR struct file *filep, FAR const char *buffer,
+                          size_t buflen)
+{
+  return 0;
+}
+
+/****************************************************************************
+ * Name: efuse_ioctl
+ *
+ * Description:
+ *   The standard ioctl method.  This is where ALL of the efuse timer
+ *   work is done.
+ *
+ ****************************************************************************/
+
+static int efuse_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
+{
+  FAR struct inode             *inode = filep->f_inode;
+  FAR struct efuse_upperhalf_s *upper;
+  FAR struct efuse_lowerhalf_s *lower;
+  int                           ret;
+
+  minfo("cmd: %d arg: %lu\n", cmd, arg);
+  upper = inode->i_private;
+  DEBUGASSERT(upper != NULL);
+  lower = upper->lower;
+  DEBUGASSERT(lower != NULL);
+
+  /* Get exclusive access to the device structures */
+
+  ret = nxsem_wait(&upper->exclsem);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  /* Handle built-in ioctl commands */
+
+  switch (cmd)
+    {
+    /* cmd:         EFUSEIOC_READ_FIELD
+     * Description: Read a field
+     * Argument:    A pointer to a struct efuse_param.
+     *              Where the field is an array.
+     *              Each item in the array is a pointer to an efuse_desc_t
+     *              variable.
+     *              An efuse_desc_t variable contains an offset to a field
+     *              or subfield and its size in bits.
+     *              The size param is a redundancy, and it is the sum
+     *              of all subfields sizes from efuse_desc_t in bits.
+     *              The data is a pointer to a pre-allocated space
+     *              where the driver will load the data read from efuse.
+     */
+
+    case EFUSEIOC_READ_FIELD:
+      {
+        FAR struct efuse_param *param =
+                   (FAR struct efuse_param *)((uintptr_t)arg);
+
+        /* Read the efuse */
+
+        DEBUGASSERT(lower->ops->read_field); /* Required */
+        ret = lower->ops->read_field(lower,
+                                     (const efuse_desc_t **) param->field,
+                                     param->data,
+                                     param->size);
+      }
+      break;
+
+    /* cmd:         EFUSEIOC_WRITE_FIELD
+     * Description: Write a field
+     * Argument: A pointer to a struct efuse_param.
+     *           Where the field is an array.
+     *           Each item in the array is a pointer to an efuse_desc_t
+     *           variable.
+     *           An efuse_desc_t variable contains an offset to a field
+     *           or subfield and its size in bits.
+     *           The size param is a redundancy, and it is the sum
+     *           of all subfields sizes from efuse_desc_t in bits.
+     *           The data is a pointer to a pre-allocated space
+     *           where the user wrote the value that he wants
+     *           to write in a field or subfield.
+     */
+
+    case EFUSEIOC_WRITE_FIELD:
+      {
+        FAR struct efuse_param *param =
+                   (FAR struct efuse_param *)((uintptr_t)arg);
+
+        /* Write the efuse */
+
+        DEBUGASSERT(lower->ops->write_field); /* Required */
+        ret = lower->ops->write_field(lower,
+                                      (const efuse_desc_t **) param->field,

Review comment:
       don't need cast

##########
File path: include/nuttx/efuse/efuse.h
##########
@@ -0,0 +1,155 @@
+/****************************************************************************
+ * include/nuttx/efuse/efuse.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_EFUSE_EFUSE_H
+#define __INCLUDE_NUTTX_EFUSE_EFUSE_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs/ioctl.h>
+
+#include <signal.h>
+#include <stdint.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Command:     EFUSEIOC_READ_FIELD
+ * Description: Read a blob of bits from an efuse field.
+ * Arguments:   A structure containing the field[], a dst pointer, and size
+ *              of bits to be read from efuses.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD      _EFUSEIOC(0x0001)
+
+/* Command:     EFUSEIOC_WRITE_FIELD
+ * Description: Write a blob of bits to an efuse's field
+ * Arguments:   A structure containing the field[], the src memory and the
+ *              amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD     _EFUSEIOC(0x0002)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* Structure eFuse field */
+
+struct efuse_desc_s
+{
+  uint16_t   bit_offset; /* Bit offset related to beginning of efuse */
+  uint16_t   bit_count;  /* Length of bit field */
+};
+
+/* Type definition for an eFuse field */
+
+typedef struct efuse_desc_s efuse_desc_t;
+
+/* Structs with the parameters passed to the IOCTLs */
+
+struct efuse_param
+{
+  FAR const efuse_desc_t **field;

Review comment:
       how to represent the end of array, this need document.

##########
File path: include/nuttx/efuse/efuse.h
##########
@@ -0,0 +1,155 @@
+/****************************************************************************
+ * include/nuttx/efuse/efuse.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_EFUSE_EFUSE_H
+#define __INCLUDE_NUTTX_EFUSE_EFUSE_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs/ioctl.h>
+
+#include <signal.h>
+#include <stdint.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Command:     EFUSEIOC_READ_FIELD
+ * Description: Read a blob of bits from an efuse field.
+ * Arguments:   A structure containing the field[], a dst pointer, and size
+ *              of bits to be read from efuses.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD      _EFUSEIOC(0x0001)
+
+/* Command:     EFUSEIOC_WRITE_FIELD
+ * Description: Write a blob of bits to an efuse's field
+ * Arguments:   A structure containing the field[], the src memory and the
+ *              amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD     _EFUSEIOC(0x0002)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* Structure eFuse field */
+
+struct efuse_desc_s
+{
+  uint16_t   bit_offset; /* Bit offset related to beginning of efuse */
+  uint16_t   bit_count;  /* Length of bit field */
+};
+
+/* Type definition for an eFuse field */
+
+typedef struct efuse_desc_s efuse_desc_t;
+
+/* Structs with the parameters passed to the IOCTLs */
+
+struct efuse_param
+{
+  FAR const efuse_desc_t **field;
+  size_t  size;
+  FAR uint8_t *data;

Review comment:
       can we give an example for data layout? For example, if I have an array:
   ```
   {51, 2},
   {60, 4},
   ```
   1. save into two bytes, or into one byte
   2. From LSB or MSB if pack into one byte
   Need document the detail agreement.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] acassis commented on a change in pull request #2628: Add generic efuse driver for NuttX

Posted by GitBox <gi...@apache.org>.
acassis commented on a change in pull request #2628:
URL: https://github.com/apache/incubator-nuttx/pull/2628#discussion_r557443340



##########
File path: include/nuttx/efuse/efuse.h
##########
@@ -0,0 +1,155 @@
+/****************************************************************************
+ * include/nuttx/efuse/efuse.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_EFUSE_EFUSE_H
+#define __INCLUDE_NUTTX_EFUSE_EFUSE_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs/ioctl.h>
+
+#include <signal.h>
+#include <stdint.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Command:     EFUSEIOC_READ_FIELD
+ * Description: Read a blob of bits from an efuse field.
+ * Arguments:   A structure containing the field[], a dst pointer, and size
+ *              of bits to be read from efuses.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD      _EFUSEIOC(0x0001)
+
+/* Command:     EFUSEIOC_WRITE_FIELD
+ * Description: Write a blob of bits to an efuse's field
+ * Arguments:   A structure containing the field[], the src memory and the
+ *              amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD     _EFUSEIOC(0x0002)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* Structure eFuse field */
+
+struct efuse_desc_s
+{
+  uint16_t   bit_offset; /* Bit offset related to beginning of efuse */
+  uint16_t   bit_count;  /* Length of bit field */
+};
+
+/* Type definition for an eFuse field */
+
+typedef struct efuse_desc_s efuse_desc_t;
+
+/* Structs with the parameters passed to the IOCTLs */
+
+struct efuse_param
+{
+  FAR const efuse_desc_t **field;
+  size_t  size;
+  FAR uint8_t *data;

Review comment:
       Normally if a field has less than 8 bit, it will be just a single field (no sub-fields), but there is nothing forbidding it to contain for example two sub-fields of 4-bit (or any other combination). In this case the bits will be copied to the 'data' linearly from efuse bit sequence to the 'data' starting at 'data bit 0'.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] acassis commented on a change in pull request #2628: Add generic efuse driver for NuttX

Posted by GitBox <gi...@apache.org>.
acassis commented on a change in pull request #2628:
URL: https://github.com/apache/incubator-nuttx/pull/2628#discussion_r554444751



##########
File path: include/nuttx/efuse/efuse.h
##########
@@ -0,0 +1,294 @@
+/****************************************************************************
+ * include/nuttx/efuse/efuse.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_EFUSE_EFUSE_H
+#define __INCLUDE_NUTTX_EFUSE_EFUSE_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs/ioctl.h>
+
+#include <signal.h>
+#include <stdint.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Command:     EFUSEIOC_READ_FIELD_BLOB
+ * Description: Read a blob of bits from an efuse field.
+ * Arguments:   A structure containing the field[], a dst pointer, and size
+ *              of bits to be read from efuses.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD_BLOB      _EFUSEIOC(0x0001)
+
+/* Command:     EFUSEIOC_READ_FIELD_BIT
+ * Description: Read of state of an efuse bit.
+ * Arguments:   A structure containing the field to be read.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD_BIT       _EFUSEIOC(0x0002)
+
+/* Command:     EFUSEIOC_WRITE_FIELD_BLOB
+ * Description: Write a blob of bits to an efuse's field
+ * Arguments:   A structure containing the field[], the src memory and the
+ *              amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD_BLOB     _EFUSEIOC(0x0003)
+
+/* Command:     EFUSEIOC_WRITE_FIELD_BIT
+ * Description: Write a bit to an efuse (burn it).
+ * Arguments:   A structure containing bit field.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD_BIT      _EFUSEIOC(0x0004)
+
+/* Command:     EFUSEIOC_GET_FIELD_SIZE
+ * Description: Get the length of the field in bits.
+ * Arguments:   A structure containing the fields.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_GET_FIELD_SIZE       _EFUSEIOC(0x0005)
+
+/* Command:     EFUSEIOC_READ_REG
+ * Description: Read an efuse register.
+ * Arguments:   A structure containing the block number and the register to
+ *              be read.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_REG             _EFUSEIOC(0x0006)
+
+/* Command:     EFUSEIOC_WRITE_REG
+ * Description: Write an efuse register.
+ * Arguments:   A structure containing the block number, the register to
+ *              write and value to be written.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_REG            _EFUSEIOC(0x0007)
+
+/* Command:     EFUSEIOC_READ_BLOCK
+ * Description: Read a key from efuse's block.
+ * Arguments:   A structure containing the block number, the dst_key pointer,
+ *              the offset in bits and the amount of bits to read.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_BLOCK           _EFUSEIOC(0x0008)
+
+/* Command:     EFUSEIOC_WRITE_BLOCK
+ * Description: Write a key to efuse's block.
+ * Arguments:   A structure containing the block number, the src_key pointer,
+ *              the offset in bits and the amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_BLOCK          _EFUSEIOC(0x0009)
+
+/* Command:     EFUSEIOC_BATCH_WRITE_BEGIN
+ * Description: Start a batch operation, the efuse bits will be burned after
+ *              a batch write commit operation.
+ * Arguments:   None
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_BATCH_WRITE_BEGIN    _EFUSEIOC(0x000a)
+
+/* Command:     EFUSEIOC_BATCH_WRITE_CANCEL
+ * Description: Cancel a started batch write operation in progress.
+ * Arguments:   None
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_BATCH_WRITE_CANCEL   _EFUSEIOC(0x000b)
+
+/* Command:     EFUSEIOC_BATCH_WRITE_COMMIT
+ * Description: Commit a batch operation that was in progress.
+ * Arguments:   None
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_BATCH_WRITE_COMMIT   _EFUSEIOC(0x000c)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* Structure eFuse field */
+
+struct efuse_desc_s
+{
+  uint16_t   efuse_block;    /* Block of eFuse */
+  uint16_t   bit_start;      /* Start bit [0..65535] */
+  uint16_t   bit_count;      /* Length of bit field [1..-] */
+};
+
+/* Type definition for an eFuse field */
+
+typedef struct efuse_desc_s efuse_desc_t;
+
+/* Structure range address by blocks */
+
+typedef struct
+{
+  uint32_t start;
+  uint32_t end;
+} efuse_range_addr_t;
+
+/* Structs with the parameters passed to the IOCTLs */
+
+struct efuse_par
+{
+  uint16_t block;
+  uint16_t reg;
+  size_t   bit_offset;
+  size_t   bit_size;
+  uint8_t *data;
+};
+
+struct efuse_par_id
+{
+  efuse_desc_t **field;
+  size_t  size;
+  uint8_t *data;
+};
+
+/* This structure provides the "lower-half" driver operations available to
+ * the "upper-half" driver.
+ */
+
+struct efuse_lowerhalf_s;
+struct efuse_ops_s
+{
+  /* Required methods *******************************************************/
+
+  /* Read an EFUSE bit */
+
+  CODE int (*read_bit)(FAR struct efuse_lowerhalf_s *lower,
+                       const efuse_desc_t *field[],

Review comment:
       But I removed things that were ESP32 specific, like the idea of separating efuses by blocks, now efuse is just a linear stream of bits. All we need to define are the fields with each efuse offset and its bit size.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] acassis commented on a change in pull request #2628: Add generic efuse driver for NuttX

Posted by GitBox <gi...@apache.org>.
acassis commented on a change in pull request #2628:
URL: https://github.com/apache/incubator-nuttx/pull/2628#discussion_r557617211



##########
File path: include/nuttx/efuse/efuse.h
##########
@@ -0,0 +1,155 @@
+/****************************************************************************
+ * include/nuttx/efuse/efuse.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_EFUSE_EFUSE_H
+#define __INCLUDE_NUTTX_EFUSE_EFUSE_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs/ioctl.h>
+
+#include <signal.h>
+#include <stdint.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Command:     EFUSEIOC_READ_FIELD
+ * Description: Read a blob of bits from an efuse field.
+ * Arguments:   A structure containing the field[], a dst pointer, and size
+ *              of bits to be read from efuses.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD      _EFUSEIOC(0x0001)
+
+/* Command:     EFUSEIOC_WRITE_FIELD
+ * Description: Write a blob of bits to an efuse's field
+ * Arguments:   A structure containing the field[], the src memory and the
+ *              amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD     _EFUSEIOC(0x0002)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* Structure eFuse field */
+
+struct efuse_desc_s
+{
+  uint16_t   bit_offset; /* Bit offset related to beginning of efuse */
+  uint16_t   bit_count;  /* Length of bit field */
+};
+
+/* Type definition for an eFuse field */
+
+typedef struct efuse_desc_s efuse_desc_t;
+
+/* Structs with the parameters passed to the IOCTLs */
+
+struct efuse_param
+{
+  FAR const efuse_desc_t **field;
+  size_t  size;
+  FAR uint8_t *data;
+};
+
+/* This structure provides the "lower-half" driver operations available to
+ * the "upper-half" driver.
+ */
+
+struct efuse_lowerhalf_s;
+struct efuse_ops_s
+{
+  /* Required methods *******************************************************/
+
+  /* Read an EFUSE bit */
+
+  CODE int (*read_field)(FAR struct efuse_lowerhalf_s *lower,
+                         FAR const efuse_desc_t *field[],
+                         FAR uint8_t *data, size_t bit_size);
+
+  /* Write an EFUSE bit */
+
+  CODE int (*write_field)(FAR struct efuse_lowerhalf_s *lower,
+                          FAR const efuse_desc_t *field[],
+                          FAR const uint8_t *data, size_t bit_size);
+
+  /* Any ioctl commands that are not recognized by the "upper-half" driver
+   * are forwarded to the lower half driver through this method.
+   */
+
+  CODE int (*ioctl)(FAR struct efuse_lowerhalf_s *lower, int cmd,
+                    unsigned long arg);
+};
+
+/* This structure provides the publicly visible representation of the
+ * "lower-half" driver state structure.  "lower half" drivers will have an
+ * internal structure definition that will be cast-compatible with this
+ * structure definitions.
+ */
+
+struct efuse_lowerhalf_s
+{
+  /* Publicly visible portion of the "lower-half" driver state structure. */
+
+  FAR const struct efuse_ops_s  *ops;  /* Lower half operations */
+
+  /* The remainder of the structure is used by the "lower-half" driver
+   * for whatever state storage that it may need.
+   */
+
+  void   *upper;                       /* Pointer to watchdog_upperhalf_s */
+};
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+

Review comment:
       Hi @xiaoxiang781216, saving the upper pointer is important when we have to exchange information inside the ISR handle, in the ESP32 case we don't use interrupts, but the driver should be prepared for other hardware that eventually will use it. Please see the arch/xtensa/src/esp32/esp32_wdt_lowerhalf.c to understand how it is used.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] acassis commented on a change in pull request #2628: Add generic efuse driver for NuttX

Posted by GitBox <gi...@apache.org>.
acassis commented on a change in pull request #2628:
URL: https://github.com/apache/incubator-nuttx/pull/2628#discussion_r557355538



##########
File path: include/nuttx/efuse/efuse.h
##########
@@ -0,0 +1,155 @@
+/****************************************************************************
+ * include/nuttx/efuse/efuse.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_EFUSE_EFUSE_H
+#define __INCLUDE_NUTTX_EFUSE_EFUSE_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs/ioctl.h>
+
+#include <signal.h>
+#include <stdint.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Command:     EFUSEIOC_READ_FIELD
+ * Description: Read a blob of bits from an efuse field.
+ * Arguments:   A structure containing the field[], a dst pointer, and size
+ *              of bits to be read from efuses.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD      _EFUSEIOC(0x0001)
+
+/* Command:     EFUSEIOC_WRITE_FIELD
+ * Description: Write a blob of bits to an efuse's field
+ * Arguments:   A structure containing the field[], the src memory and the
+ *              amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD     _EFUSEIOC(0x0002)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* Structure eFuse field */
+
+struct efuse_desc_s
+{
+  uint16_t   bit_offset; /* Bit offset related to beginning of efuse */
+  uint16_t   bit_count;  /* Length of bit field */
+};
+
+/* Type definition for an eFuse field */
+
+typedef struct efuse_desc_s efuse_desc_t;
+
+/* Structs with the parameters passed to the IOCTLs */
+
+struct efuse_param
+{
+  FAR const efuse_desc_t **field;
+  size_t  size;
+  FAR uint8_t *data;

Review comment:
       @saramonteiro  The param.size is just a double check to efuse_desc_t bit_size, it is used just to avoid the user pass a wrong ID, but of course we could modify it to be the size of the allocated bytes in param.data if everybody think it is a better idea. @xiaoxiang781216 what do you think?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] acassis commented on a change in pull request #2628: Add generic efuse driver for NuttX

Posted by GitBox <gi...@apache.org>.
acassis commented on a change in pull request #2628:
URL: https://github.com/apache/incubator-nuttx/pull/2628#discussion_r554451149



##########
File path: include/nuttx/efuse/efuse.h
##########
@@ -0,0 +1,294 @@
+/****************************************************************************
+ * include/nuttx/efuse/efuse.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_EFUSE_EFUSE_H
+#define __INCLUDE_NUTTX_EFUSE_EFUSE_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs/ioctl.h>
+
+#include <signal.h>
+#include <stdint.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Command:     EFUSEIOC_READ_FIELD_BLOB
+ * Description: Read a blob of bits from an efuse field.
+ * Arguments:   A structure containing the field[], a dst pointer, and size
+ *              of bits to be read from efuses.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD_BLOB      _EFUSEIOC(0x0001)
+
+/* Command:     EFUSEIOC_READ_FIELD_BIT
+ * Description: Read of state of an efuse bit.
+ * Arguments:   A structure containing the field to be read.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD_BIT       _EFUSEIOC(0x0002)
+
+/* Command:     EFUSEIOC_WRITE_FIELD_BLOB
+ * Description: Write a blob of bits to an efuse's field
+ * Arguments:   A structure containing the field[], the src memory and the
+ *              amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD_BLOB     _EFUSEIOC(0x0003)
+
+/* Command:     EFUSEIOC_WRITE_FIELD_BIT
+ * Description: Write a bit to an efuse (burn it).
+ * Arguments:   A structure containing bit field.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD_BIT      _EFUSEIOC(0x0004)
+
+/* Command:     EFUSEIOC_GET_FIELD_SIZE
+ * Description: Get the length of the field in bits.
+ * Arguments:   A structure containing the fields.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_GET_FIELD_SIZE       _EFUSEIOC(0x0005)
+
+/* Command:     EFUSEIOC_READ_REG
+ * Description: Read an efuse register.
+ * Arguments:   A structure containing the block number and the register to
+ *              be read.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_REG             _EFUSEIOC(0x0006)
+
+/* Command:     EFUSEIOC_WRITE_REG
+ * Description: Write an efuse register.
+ * Arguments:   A structure containing the block number, the register to
+ *              write and value to be written.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_REG            _EFUSEIOC(0x0007)
+
+/* Command:     EFUSEIOC_READ_BLOCK
+ * Description: Read a key from efuse's block.
+ * Arguments:   A structure containing the block number, the dst_key pointer,
+ *              the offset in bits and the amount of bits to read.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_BLOCK           _EFUSEIOC(0x0008)
+
+/* Command:     EFUSEIOC_WRITE_BLOCK
+ * Description: Write a key to efuse's block.
+ * Arguments:   A structure containing the block number, the src_key pointer,
+ *              the offset in bits and the amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_BLOCK          _EFUSEIOC(0x0009)
+
+/* Command:     EFUSEIOC_BATCH_WRITE_BEGIN
+ * Description: Start a batch operation, the efuse bits will be burned after
+ *              a batch write commit operation.
+ * Arguments:   None
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_BATCH_WRITE_BEGIN    _EFUSEIOC(0x000a)
+
+/* Command:     EFUSEIOC_BATCH_WRITE_CANCEL
+ * Description: Cancel a started batch write operation in progress.
+ * Arguments:   None
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_BATCH_WRITE_CANCEL   _EFUSEIOC(0x000b)
+
+/* Command:     EFUSEIOC_BATCH_WRITE_COMMIT
+ * Description: Commit a batch operation that was in progress.
+ * Arguments:   None
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_BATCH_WRITE_COMMIT   _EFUSEIOC(0x000c)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* Structure eFuse field */
+
+struct efuse_desc_s
+{
+  uint16_t   efuse_block;    /* Block of eFuse */
+  uint16_t   bit_start;      /* Start bit [0..65535] */
+  uint16_t   bit_count;      /* Length of bit field [1..-] */
+};
+
+/* Type definition for an eFuse field */
+
+typedef struct efuse_desc_s efuse_desc_t;
+
+/* Structure range address by blocks */
+
+typedef struct
+{
+  uint32_t start;
+  uint32_t end;
+} efuse_range_addr_t;
+
+/* Structs with the parameters passed to the IOCTLs */
+
+struct efuse_par
+{
+  uint16_t block;
+  uint16_t reg;
+  size_t   bit_offset;
+  size_t   bit_size;
+  uint8_t *data;
+};
+
+struct efuse_par_id
+{
+  efuse_desc_t **field;
+  size_t  size;
+  uint8_t *data;
+};
+
+/* This structure provides the "lower-half" driver operations available to
+ * the "upper-half" driver.
+ */
+
+struct efuse_lowerhalf_s;
+struct efuse_ops_s
+{
+  /* Required methods *******************************************************/
+
+  /* Read an EFUSE bit */
+
+  CODE int (*read_bit)(FAR struct efuse_lowerhalf_s *lower,
+                       const efuse_desc_t *field[],

Review comment:
       Yes, exactly it what I did now! I removed the read/write block and read/write reg as you suggested! ;-)




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] xiaoxiang781216 commented on pull request #2628: Add generic efuse driver for NuttX

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on pull request #2628:
URL: https://github.com/apache/incubator-nuttx/pull/2628#issuecomment-760930549


   @acassis the change look perfect, could you squash all patches into one?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] acassis commented on a change in pull request #2628: Add generic efuse driver for NuttX

Posted by GitBox <gi...@apache.org>.
acassis commented on a change in pull request #2628:
URL: https://github.com/apache/incubator-nuttx/pull/2628#discussion_r555972270



##########
File path: include/nuttx/efuse/efuse.h
##########
@@ -0,0 +1,155 @@
+/****************************************************************************
+ * include/nuttx/efuse/efuse.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_EFUSE_EFUSE_H
+#define __INCLUDE_NUTTX_EFUSE_EFUSE_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs/ioctl.h>
+
+#include <signal.h>
+#include <stdint.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Command:     EFUSEIOC_READ_FIELD
+ * Description: Read a blob of bits from an efuse field.
+ * Arguments:   A structure containing the field[], a dst pointer, and size
+ *              of bits to be read from efuses.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD      _EFUSEIOC(0x0001)
+
+/* Command:     EFUSEIOC_WRITE_FIELD
+ * Description: Write a blob of bits to an efuse's field
+ * Arguments:   A structure containing the field[], the src memory and the
+ *              amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD     _EFUSEIOC(0x0002)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* Structure eFuse field */
+
+struct efuse_desc_s
+{
+  uint16_t   bit_offset;     /* Bit offset related to beginning of efuse */
+  uint16_t   bit_count;      /* Length of bit field */
+};
+
+/* Type definition for an eFuse field */
+
+typedef struct efuse_desc_s efuse_desc_t;
+
+/* Structs with the parameters passed to the IOCTLs */
+
+struct efuse_param
+{
+  efuse_desc_t **field;
+  size_t  size;
+  uint8_t *data;

Review comment:
       Initially I was using void *, but all the operations will be over 8-bit bytes, so I decided to keep it as uint8_t




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a change in pull request #2628: Add generic efuse driver for NuttX

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on a change in pull request #2628:
URL: https://github.com/apache/incubator-nuttx/pull/2628#discussion_r557416948



##########
File path: drivers/efuse/efuse.c
##########
@@ -0,0 +1,395 @@
+/****************************************************************************
+ * drivers/efuse/efuse.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <string.h>
+#include <fcntl.h>
+#include <assert.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <nuttx/fs/fs.h>
+#include <nuttx/irq.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/power/pm.h>
+#include <nuttx/semaphore.h>
+#include <nuttx/efuse/efuse.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Type Definitions
+ ****************************************************************************/
+
+/* This structure describes the state of the upper half driver */
+
+struct efuse_upperhalf_s
+{
+  sem_t     exclsem;  /* Supports mutual exclusion */
+  FAR char *path;     /* Registration path */
+
+  /* The contained lower-half driver */
+
+  FAR struct efuse_lowerhalf_s *lower;
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int     efuse_open(FAR struct file *filep);
+static int     efuse_close(FAR struct file *filep);
+static ssize_t efuse_read(FAR struct file *filep, FAR char *buffer,
+                          size_t buflen);
+static ssize_t efuse_write(FAR struct file *filep, FAR const char *buffer,
+                           size_t buflen);
+static int     efuse_ioctl(FAR struct file *filep, int cmd,
+                           unsigned long arg);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct file_operations g_efuseops =
+{
+  efuse_open,  /* open */
+  efuse_close, /* close */
+  efuse_read,  /* read */
+  efuse_write, /* write */
+  NULL,        /* seek */
+  efuse_ioctl, /* ioctl */
+  NULL         /* poll */
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: efuse_open
+ *
+ * Description:
+ *   This function is called whenever the efuse timer device is opened.
+ *
+ ****************************************************************************/
+
+static int efuse_open(FAR struct file *filep)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: efuse_close
+ *
+ * Description:
+ *   This function is called when the efuse timer device is closed.
+ *
+ ****************************************************************************/
+
+static int efuse_close(FAR struct file *filep)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: efuse_read
+ *
+ * Description:
+ *   A dummy read method.  This is provided only to satisfy the VFS layer.
+ *
+ ****************************************************************************/
+
+static ssize_t efuse_read(FAR struct file *filep, FAR char *buffer,
+                         size_t buflen)
+{
+  /* Return zero -- usually meaning end-of-file */
+
+  return 0;
+}
+
+/****************************************************************************
+ * Name: efuse_write
+ *
+ * Description:
+ *   A dummy write method.  This is provided only to satisfy the VFS layer.
+ *
+ ****************************************************************************/
+
+static ssize_t efuse_write(FAR struct file *filep, FAR const char *buffer,
+                          size_t buflen)
+{
+  return 0;
+}
+
+/****************************************************************************
+ * Name: efuse_ioctl
+ *
+ * Description:
+ *   The standard ioctl method.  This is where ALL of the efuse timer
+ *   work is done.
+ *
+ ****************************************************************************/
+
+static int efuse_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
+{
+  FAR struct inode             *inode = filep->f_inode;
+  FAR struct efuse_upperhalf_s *upper;
+  FAR struct efuse_lowerhalf_s *lower;
+  int                           ret;
+
+  minfo("cmd: %d arg: %lu\n", cmd, arg);
+  upper = inode->i_private;
+  DEBUGASSERT(upper != NULL);
+  lower = upper->lower;
+  DEBUGASSERT(lower != NULL);
+
+  /* Get exclusive access to the device structures */
+
+  ret = nxsem_wait(&upper->exclsem);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  /* Handle built-in ioctl commands */
+
+  switch (cmd)
+    {
+    /* cmd:         EFUSEIOC_READ_FIELD
+     * Description: Read a field
+     * Argument:    A pointer to a struct efuse_param.
+     *              Where the field is an array.
+     *              Each item in the array is a pointer to an efuse_desc_t
+     *              variable.
+     *              An efuse_desc_t variable contains an offset to a field
+     *              or subfield and its size in bits.
+     *              The size param is a redundancy, and it is the sum
+     *              of all subfields sizes from efuse_desc_t in bits.
+     *              The data is a pointer to a pre-allocated space
+     *              where the driver will load the data read from efuse.
+     */
+
+    case EFUSEIOC_READ_FIELD:
+      {
+        FAR struct efuse_param *param =
+                   (FAR struct efuse_param *)((uintptr_t)arg);
+
+        /* Read the efuse */
+
+        DEBUGASSERT(lower->ops->read_field); /* Required */
+        ret = lower->ops->read_field(lower,
+                                     (const efuse_desc_t **) param->field,
+                                     param->data,
+                                     param->size);
+      }
+      break;
+
+    /* cmd:         EFUSEIOC_WRITE_FIELD
+     * Description: Write a field
+     * Argument: A pointer to a struct efuse_param.
+     *           Where the field is an array.
+     *           Each item in the array is a pointer to an efuse_desc_t
+     *           variable.
+     *           An efuse_desc_t variable contains an offset to a field
+     *           or subfield and its size in bits.
+     *           The size param is a redundancy, and it is the sum
+     *           of all subfields sizes from efuse_desc_t in bits.
+     *           The data is a pointer to a pre-allocated space
+     *           where the user wrote the value that he wants
+     *           to write in a field or subfield.
+     */
+
+    case EFUSEIOC_WRITE_FIELD:
+      {
+        FAR struct efuse_param *param =
+                   (FAR struct efuse_param *)((uintptr_t)arg);
+
+        /* Write the efuse */
+
+        DEBUGASSERT(lower->ops->write_field); /* Required */
+        ret = lower->ops->write_field(lower,
+                                      (const efuse_desc_t **) param->field,
+                                      param->data,
+                                      param->size);
+      }
+      break;
+
+    default:
+      {
+        minfo("Forwarding unrecognized cmd: %d arg: %lu\n", cmd, arg);
+
+        /* Ioctls commands that are not recognized by the "upper-half"
+         * driver are forwarded to the lower half driver through this
+         * method.
+         */
+
+        if (lower->ops->ioctl) /* Optional */
+          {
+            ret = lower->ops->ioctl(lower, cmd, arg);
+          }
+        else
+          {
+            ret = -ENOTTY;
+          }
+      }
+      break;
+    }
+
+  nxsem_post(&upper->exclsem);
+  return ret;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: efuse_register
+ *
+ * Description:
+ *   This function binds an instance of a "lower half" efuse driver with
+ *   the "upper half" efuse device and registers that device so that can
+ *   be used by application code.
+ *
+ * Input Parameters:
+ *   dev path - The full path to the driver to be registered in the NuttX
+ *     pseudo-filesystem.  The recommended convention is to name all
+ *     efuse drivers as "/dev/efuse".
+ *   lower - A pointer to an instance of lower half efuse driver.  This
+ *     instance is bound to the efuse driver and must persists as long as
+ *     the driver persists.
+ *
+ * Returned Value:
+ *   On success, a non-NULL handle is returned to the caller.  In the event
+ *   of any failure, a NULL value is returned.
+ *
+ ****************************************************************************/
+
+FAR void *efuse_register(FAR const char *path,
+                         FAR struct efuse_lowerhalf_s *lower)
+{
+  FAR struct efuse_upperhalf_s *upper;
+  int ret;
+
+  DEBUGASSERT(path && lower);
+  minfo("Entry: path=%s\n", path);
+
+  /* Allocate the upper-half data structure */
+
+  upper = (FAR struct efuse_upperhalf_s *)
+          kmm_zalloc(sizeof(struct efuse_upperhalf_s));
+  if (!upper)
+    {
+      merr("Upper half allocation failed\n");
+      goto errout;
+    }
+
+  /* Initialize the efuse timer device structure (it was already zeroed
+   * by kmm_zalloc()).
+   */
+
+  nxsem_init(&upper->exclsem, 0, 1);
+  upper->lower = lower;
+
+  /* Copy the registration path */
+
+  upper->path = strdup(path);
+  if (!upper->path)
+    {
+      merr("Path allocation failed\n");
+      goto errout_with_upper;
+    }
+
+  /* Register the efuse timer device */
+
+  ret = register_driver(path, &g_efuseops, 0666, upper);
+  if (ret < 0)
+    {
+      merr("register_driver failed: %d\n", ret);
+      goto errout_with_path;
+    }
+
+  return (FAR void *)upper;
+
+errout_with_path:
+  kmm_free(upper->path);
+
+errout_with_upper:
+  nxsem_destroy(&upper->exclsem);
+  kmm_free(upper);
+
+errout:
+  return NULL;
+}
+
+/****************************************************************************
+ * Name: efuse_unregister
+ *
+ * Description:
+ *   This function can be called to disable and unregister the efuse
+ *   device driver.
+ *
+ * Input Parameters:
+ *   handle - This is the handle that was returned by efuse_register()
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+void efuse_unregister(FAR void *handle)
+{
+  FAR struct efuse_upperhalf_s *upper;
+  FAR struct efuse_lowerhalf_s *lower;
+
+  /* Recover the pointer to the upper-half driver state */
+
+  upper = (FAR struct efuse_upperhalf_s *)handle;
+  DEBUGASSERT(upper != NULL);
+  lower = upper->lower;
+  DEBUGASSERT(lower != NULL);
+
+  minfo("Unregistering: %s\n", upper->path);
+
+  /* Unregister the efuse timer device */
+
+  unregister_driver(upper->path);
+
+  /* Then free all of the driver resources */
+
+  kmm_free(upper->path);
+  nxsem_destroy(&upper->exclsem);
+  kmm_free(lower);

Review comment:
       But I can't find kmm_free(lower) in watchdog_unregister:
   ```
   void watchdog_unregister(FAR void *handle)
   {
     FAR struct watchdog_upperhalf_s *upper;
     FAR struct watchdog_lowerhalf_s *lower;
   
     /* Recover the pointer to the upper-half driver state */
   
     upper = (FAR struct watchdog_upperhalf_s *)handle;
     DEBUGASSERT(upper != NULL);
     lower = upper->lower;
     DEBUGASSERT(lower != NULL);
   
     wdinfo("Unregistering: %s\n", upper->path);
   
   #ifdef CONFIG_WATCHDOG_AUTOMONITOR
     watchdog_automonitor_stop(upper);
   #endif
   
     /* Disable the watchdog timer */
   
     DEBUGASSERT(lower->ops->stop); /* Required */
     lower->ops->stop(lower);
   
     /* Unregister the watchdog timer device */
   
     unregister_driver(upper->path);
   
     /* Then free all of the driver resources */
   
     kmm_free(upper->path);
     nxsem_destroy(&upper->exclsem);
     kmm_free(upper);
   }
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] acassis commented on a change in pull request #2628: Add generic efuse driver for NuttX

Posted by GitBox <gi...@apache.org>.
acassis commented on a change in pull request #2628:
URL: https://github.com/apache/incubator-nuttx/pull/2628#discussion_r556716816



##########
File path: include/nuttx/efuse/efuse.h
##########
@@ -0,0 +1,155 @@
+/****************************************************************************
+ * include/nuttx/efuse/efuse.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_EFUSE_EFUSE_H
+#define __INCLUDE_NUTTX_EFUSE_EFUSE_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs/ioctl.h>
+
+#include <signal.h>
+#include <stdint.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Command:     EFUSEIOC_READ_FIELD
+ * Description: Read a blob of bits from an efuse field.
+ * Arguments:   A structure containing the field[], a dst pointer, and size
+ *              of bits to be read from efuses.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD      _EFUSEIOC(0x0001)
+
+/* Command:     EFUSEIOC_WRITE_FIELD
+ * Description: Write a blob of bits to an efuse's field
+ * Arguments:   A structure containing the field[], the src memory and the
+ *              amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD     _EFUSEIOC(0x0002)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* Structure eFuse field */
+
+struct efuse_desc_s
+{
+  uint16_t   bit_offset; /* Bit offset related to beginning of efuse */
+  uint16_t   bit_count;  /* Length of bit field */
+};
+
+/* Type definition for an eFuse field */
+
+typedef struct efuse_desc_s efuse_desc_t;
+
+/* Structs with the parameters passed to the IOCTLs */
+
+struct efuse_param
+{
+  FAR const efuse_desc_t **field;
+  size_t  size;
+  FAR uint8_t *data;
+};
+
+/* This structure provides the "lower-half" driver operations available to
+ * the "upper-half" driver.
+ */
+
+struct efuse_lowerhalf_s;
+struct efuse_ops_s
+{
+  /* Required methods *******************************************************/
+
+  /* Read an EFUSE bit */
+
+  CODE int (*read_field)(FAR struct efuse_lowerhalf_s *lower,
+                         FAR const efuse_desc_t *field[],
+                         FAR uint8_t *data, size_t bit_size);
+
+  /* Write an EFUSE bit */
+
+  CODE int (*write_field)(FAR struct efuse_lowerhalf_s *lower,
+                          FAR const efuse_desc_t *field[],
+                          FAR const uint8_t *data, size_t bit_size);
+
+  /* Any ioctl commands that are not recognized by the "upper-half" driver
+   * are forwarded to the lower half driver through this method.
+   */
+
+  CODE int (*ioctl)(FAR struct efuse_lowerhalf_s *lower, int cmd,
+                    unsigned long arg);
+};
+
+/* This structure provides the publicly visible representation of the
+ * "lower-half" driver state structure.  "lower half" drivers will have an
+ * internal structure definition that will be cast-compatible with this
+ * structure definitions.
+ */
+
+struct efuse_lowerhalf_s
+{
+  /* Publicly visible portion of the "lower-half" driver state structure. */
+
+  FAR const struct efuse_ops_s  *ops;  /* Lower half operations */
+
+  /* The remainder of the structure is used by the "lower-half" driver
+   * for whatever state storage that it may need.
+   */
+
+  void   *upper;                       /* Pointer to watchdog_upperhalf_s */
+};
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+

Review comment:
       1 - @xiaoxiang781216 I cannot remove *upper, it is used by the arch efuse lowerhalf.
   
   2 - Right I'll add the efuse_register/efuse_unregister prototype in the efuse.h




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a change in pull request #2628: Add generic efuse driver for NuttX

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on a change in pull request #2628:
URL: https://github.com/apache/incubator-nuttx/pull/2628#discussion_r557822826



##########
File path: include/nuttx/efuse/efuse.h
##########
@@ -0,0 +1,155 @@
+/****************************************************************************
+ * include/nuttx/efuse/efuse.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_EFUSE_EFUSE_H
+#define __INCLUDE_NUTTX_EFUSE_EFUSE_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs/ioctl.h>
+
+#include <signal.h>
+#include <stdint.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Command:     EFUSEIOC_READ_FIELD
+ * Description: Read a blob of bits from an efuse field.
+ * Arguments:   A structure containing the field[], a dst pointer, and size
+ *              of bits to be read from efuses.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD      _EFUSEIOC(0x0001)
+
+/* Command:     EFUSEIOC_WRITE_FIELD
+ * Description: Write a blob of bits to an efuse's field
+ * Arguments:   A structure containing the field[], the src memory and the
+ *              amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD     _EFUSEIOC(0x0002)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* Structure eFuse field */
+
+struct efuse_desc_s
+{
+  uint16_t   bit_offset; /* Bit offset related to beginning of efuse */
+  uint16_t   bit_count;  /* Length of bit field */
+};
+
+/* Type definition for an eFuse field */
+
+typedef struct efuse_desc_s efuse_desc_t;
+
+/* Structs with the parameters passed to the IOCTLs */
+
+struct efuse_param
+{
+  FAR const efuse_desc_t **field;
+  size_t  size;
+  FAR uint8_t *data;
+};
+
+/* This structure provides the "lower-half" driver operations available to
+ * the "upper-half" driver.
+ */
+
+struct efuse_lowerhalf_s;
+struct efuse_ops_s
+{
+  /* Required methods *******************************************************/
+
+  /* Read an EFUSE bit */
+
+  CODE int (*read_field)(FAR struct efuse_lowerhalf_s *lower,
+                         FAR const efuse_desc_t *field[],
+                         FAR uint8_t *data, size_t bit_size);
+
+  /* Write an EFUSE bit */
+
+  CODE int (*write_field)(FAR struct efuse_lowerhalf_s *lower,
+                          FAR const efuse_desc_t *field[],
+                          FAR const uint8_t *data, size_t bit_size);
+
+  /* Any ioctl commands that are not recognized by the "upper-half" driver
+   * are forwarded to the lower half driver through this method.
+   */
+
+  CODE int (*ioctl)(FAR struct efuse_lowerhalf_s *lower, int cmd,
+                    unsigned long arg);
+};
+
+/* This structure provides the publicly visible representation of the
+ * "lower-half" driver state structure.  "lower half" drivers will have an
+ * internal structure definition that will be cast-compatible with this
+ * structure definitions.
+ */
+
+struct efuse_lowerhalf_s
+{
+  /* Publicly visible portion of the "lower-half" driver state structure. */
+
+  FAR const struct efuse_ops_s  *ops;  /* Lower half operations */
+
+  /* The remainder of the structure is used by the "lower-half" driver
+   * for whatever state storage that it may need.
+   */
+
+  void   *upper;                       /* Pointer to watchdog_upperhalf_s */
+};
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+

Review comment:
       Yes, I thought this case before, but if the lower half need callback into upper half in ISR process, the normal approach is pass the upper pointer in set_xxx_callback, e.g.:
   ```
     CODE int (*start)(FAR struct oneshot_lowerhalf_s *lower,
                       oneshot_callback_t callback, FAR void *arg,
                                                    ^^^^^^^^^^^^^
                       FAR const struct timespec *ts);
   ```
   Or like esp32_wdt_lowerhalf.c case, save it in the private esp32_wdt_lowerhalf_s not public watchdog_lowerhalf_s.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] acassis commented on a change in pull request #2628: Add generic efuse driver for NuttX

Posted by GitBox <gi...@apache.org>.
acassis commented on a change in pull request #2628:
URL: https://github.com/apache/incubator-nuttx/pull/2628#discussion_r558266312



##########
File path: include/nuttx/efuse/efuse.h
##########
@@ -0,0 +1,155 @@
+/****************************************************************************
+ * include/nuttx/efuse/efuse.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_EFUSE_EFUSE_H
+#define __INCLUDE_NUTTX_EFUSE_EFUSE_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs/ioctl.h>
+
+#include <signal.h>
+#include <stdint.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Command:     EFUSEIOC_READ_FIELD
+ * Description: Read a blob of bits from an efuse field.
+ * Arguments:   A structure containing the field[], a dst pointer, and size
+ *              of bits to be read from efuses.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD      _EFUSEIOC(0x0001)
+
+/* Command:     EFUSEIOC_WRITE_FIELD
+ * Description: Write a blob of bits to an efuse's field
+ * Arguments:   A structure containing the field[], the src memory and the
+ *              amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD     _EFUSEIOC(0x0002)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* Structure eFuse field */
+
+struct efuse_desc_s
+{
+  uint16_t   bit_offset; /* Bit offset related to beginning of efuse */
+  uint16_t   bit_count;  /* Length of bit field */
+};
+
+/* Type definition for an eFuse field */
+
+typedef struct efuse_desc_s efuse_desc_t;
+
+/* Structs with the parameters passed to the IOCTLs */
+
+struct efuse_param
+{
+  FAR const efuse_desc_t **field;
+  size_t  size;
+  FAR uint8_t *data;
+};
+
+/* This structure provides the "lower-half" driver operations available to
+ * the "upper-half" driver.
+ */
+
+struct efuse_lowerhalf_s;
+struct efuse_ops_s
+{
+  /* Required methods *******************************************************/
+
+  /* Read an EFUSE bit */
+
+  CODE int (*read_field)(FAR struct efuse_lowerhalf_s *lower,
+                         FAR const efuse_desc_t *field[],
+                         FAR uint8_t *data, size_t bit_size);
+
+  /* Write an EFUSE bit */
+
+  CODE int (*write_field)(FAR struct efuse_lowerhalf_s *lower,
+                          FAR const efuse_desc_t *field[],
+                          FAR const uint8_t *data, size_t bit_size);
+
+  /* Any ioctl commands that are not recognized by the "upper-half" driver
+   * are forwarded to the lower half driver through this method.
+   */
+
+  CODE int (*ioctl)(FAR struct efuse_lowerhalf_s *lower, int cmd,
+                    unsigned long arg);
+};
+
+/* This structure provides the publicly visible representation of the
+ * "lower-half" driver state structure.  "lower half" drivers will have an
+ * internal structure definition that will be cast-compatible with this
+ * structure definitions.
+ */
+
+struct efuse_lowerhalf_s
+{
+  /* Publicly visible portion of the "lower-half" driver state structure. */
+
+  FAR const struct efuse_ops_s  *ops;  /* Lower half operations */
+
+  /* The remainder of the structure is used by the "lower-half" driver
+   * for whatever state storage that it may need.
+   */
+
+  void   *upper;                       /* Pointer to watchdog_upperhalf_s */
+};
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+

Review comment:
       Right, I will change it!




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] saramonteiro commented on a change in pull request #2628: Add generic efuse driver for NuttX

Posted by GitBox <gi...@apache.org>.
saramonteiro commented on a change in pull request #2628:
URL: https://github.com/apache/incubator-nuttx/pull/2628#discussion_r555259328



##########
File path: drivers/efuse/efuse.c
##########
@@ -0,0 +1,377 @@
+/****************************************************************************
+ * drivers/efuse/efuse.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <string.h>
+#include <fcntl.h>
+#include <assert.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <nuttx/fs/fs.h>
+#include <nuttx/irq.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/power/pm.h>
+#include <nuttx/semaphore.h>
+#include <nuttx/efuse/efuse.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Type Definitions
+ ****************************************************************************/
+
+/* This structure describes the state of the upper half driver */
+
+struct efuse_upperhalf_s
+{
+  sem_t     exclsem;  /* Supports mutual exclusion */
+  FAR char *path;     /* Registration path */
+
+  /* The contained lower-half driver */
+
+  FAR struct efuse_lowerhalf_s *lower;
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int     efuse_open(FAR struct file *filep);
+static int     efuse_close(FAR struct file *filep);
+static ssize_t efuse_read(FAR struct file *filep, FAR char *buffer,
+                          size_t buflen);
+static ssize_t efuse_write(FAR struct file *filep, FAR const char *buffer,
+                           size_t buflen);
+static int     efuse_ioctl(FAR struct file *filep, int cmd,
+                 unsigned long arg);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct file_operations g_efuseops =
+{
+  efuse_open,  /* open */
+  efuse_close, /* close */
+  efuse_read,  /* read */
+  efuse_write, /* write */
+  NULL,        /* seek */
+  efuse_ioctl, /* ioctl */
+  NULL         /* poll */
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: efuse_open
+ *
+ * Description:
+ *   This function is called whenever the efuse timer device is opened.
+ *
+ ****************************************************************************/
+
+static int efuse_open(FAR struct file *filep)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: efuse_close
+ *
+ * Description:
+ *   This function is called when the efuse timer device is closed.
+ *
+ ****************************************************************************/
+
+static int efuse_close(FAR struct file *filep)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: efuse_read
+ *
+ * Description:
+ *   A dummy read method.  This is provided only to satisfy the VFS layer.
+ *
+ ****************************************************************************/
+
+static ssize_t efuse_read(FAR struct file *filep, FAR char *buffer,
+                         size_t buflen)
+{
+  /* Return zero -- usually meaning end-of-file */
+
+  return 0;
+}
+
+/****************************************************************************
+ * Name: efuse_write
+ *
+ * Description:
+ *   A dummy write method.  This is provided only to satisfy the VFS layer.
+ *
+ ****************************************************************************/
+
+static ssize_t efuse_write(FAR struct file *filep, FAR const char *buffer,
+                          size_t buflen)
+{
+  return 0;
+}
+
+/****************************************************************************
+ * Name: efuse_ioctl
+ *
+ * Description:
+ *   The standard ioctl method.  This is where ALL of the efuse timer
+ *   work is done.
+ *
+ ****************************************************************************/
+
+static int efuse_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
+{
+  FAR struct inode             *inode = filep->f_inode;
+  FAR struct efuse_upperhalf_s *upper;
+  FAR struct efuse_lowerhalf_s *lower;
+  int                           ret;
+
+  minfo("cmd: %d arg: %ld\n", cmd, arg);
+  upper = inode->i_private;
+  DEBUGASSERT(upper != NULL);
+  lower = upper->lower;
+  DEBUGASSERT(lower != NULL);
+
+  /* Get exclusive access to the device structures */
+
+  ret = nxsem_wait(&upper->exclsem);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  /* Handle built-in ioctl commands */
+
+  switch (cmd)
+    {
+    /* cmd:         EFUSEIOC_READ_FIELD_BIT
+     * Description: Read a single bit efuse
+     * Argument:    Return variable
+     */

Review comment:
       ```suggestion
       /* cmd:         EFUSEIOC_READ_FIELD
        * Description: Read a field
        * Argument: A pointer to a struct efuse_param. 
        *                  Where the field is an array.
        *                  Each item in the array is a pointer to an efuse_desc_t variable.
        *                  An efuse_desc_t variable contains an offset to a field or subfield and its size in bits.  
        *                  The size param is a redundancy, and it is the sum of all subfields sizes from
        *                  from efuse_desc_t in bits.
        *                  The data is a pointer to a pre-allocated space where the driver will load 
        *                   the data read from efuse.
        */
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] acassis commented on a change in pull request #2628: Add generic efuse driver for NuttX

Posted by GitBox <gi...@apache.org>.
acassis commented on a change in pull request #2628:
URL: https://github.com/apache/incubator-nuttx/pull/2628#discussion_r554146750



##########
File path: drivers/efuse/efuse.c
##########
@@ -0,0 +1,514 @@
+/****************************************************************************
+ * drivers/efuse/efuse.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <string.h>
+#include <fcntl.h>
+#include <assert.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <nuttx/fs/fs.h>
+#include <nuttx/irq.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/power/pm.h>
+#include <nuttx/semaphore.h>
+#include <nuttx/efuse/efuse.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Type Definitions
+ ****************************************************************************/
+
+/* This structure describes the state of the upper half driver */
+
+struct efuse_upperhalf_s
+{
+  sem_t     exclsem;  /* Supports mutual exclusion */
+  FAR char *path;     /* Registration path */
+
+  /* The contained lower-half driver */
+
+  FAR struct efuse_lowerhalf_s *lower;
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int     efuse_open(FAR struct file *filep);
+static int     efuse_close(FAR struct file *filep);
+static ssize_t efuse_read(FAR struct file *filep, FAR char *buffer,
+                          size_t buflen);
+static ssize_t efuse_write(FAR struct file *filep, FAR const char *buffer,
+                           size_t buflen);
+static int     efuse_ioctl(FAR struct file *filep, int cmd,
+                 unsigned long arg);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct file_operations g_efuseops =
+{
+  efuse_open,  /* open */
+  efuse_close, /* close */
+  efuse_read,  /* read */
+  efuse_write, /* write */
+  NULL,        /* seek */
+  efuse_ioctl, /* ioctl */
+  NULL         /* poll */
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: efuse_open
+ *
+ * Description:
+ *   This function is called whenever the efuse timer device is opened.
+ *
+ ****************************************************************************/
+
+static int efuse_open(FAR struct file *filep)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: efuse_close
+ *
+ * Description:
+ *   This function is called when the efuse timer device is closed.
+ *
+ ****************************************************************************/
+
+static int efuse_close(FAR struct file *filep)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: efuse_read
+ *
+ * Description:
+ *   A dummy read method.  This is provided only to satisfy the VFS layer.
+ *
+ ****************************************************************************/
+
+static ssize_t efuse_read(FAR struct file *filep, FAR char *buffer,
+                         size_t buflen)
+{
+  /* Return zero -- usually meaning end-of-file */
+
+  return 0;
+}
+
+/****************************************************************************
+ * Name: efuse_write
+ *
+ * Description:
+ *   A dummy write method.  This is provided only to satisfy the VFS layer.
+ *
+ ****************************************************************************/
+
+static ssize_t efuse_write(FAR struct file *filep, FAR const char *buffer,
+                          size_t buflen)
+{
+  return 0;
+}
+
+/****************************************************************************
+ * Name: efuse_ioctl
+ *
+ * Description:
+ *   The standard ioctl method.  This is where ALL of the efuse timer
+ *   work is done.
+ *
+ ****************************************************************************/
+
+static int efuse_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
+{
+  FAR struct inode             *inode = filep->f_inode;
+  FAR struct efuse_upperhalf_s *upper;
+  FAR struct efuse_lowerhalf_s *lower;
+  int                           ret;
+
+  minfo("cmd: %d arg: %ld\n", cmd, arg);
+  upper = inode->i_private;
+  DEBUGASSERT(upper != NULL);
+  lower = upper->lower;
+  DEBUGASSERT(lower != NULL);
+
+  /* Get exclusive access to the device structures */
+
+  ret = nxsem_wait(&upper->exclsem);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  /* Handle built-in ioctl commands */
+
+  switch (cmd)
+    {
+    /* cmd:         EFUSEIOC_READ_FIELD_BIT
+     * Description: Read a single bit efuse
+     * Argument:    Return variable
+     */
+
+    case EFUSEIOC_READ_FIELD_BIT:
+      {
+        FAR struct efuse_par_id *param =
+                   (FAR struct efuse_par_id *)((uintptr_t)arg);
+
+        /* Read the efuse */
+
+        DEBUGASSERT(lower->ops->read_bit); /* Required */
+        ret = lower->ops->read_bit(lower,
+                                   (const efuse_desc_t **) param->field,
+                                   param->data);
+      }
+      break;
+
+    /* cmd:         EFUSEIOC_WRITE_FIELD_BIT
+     * Description: Write a single bit efuse
+     * Argument:    - efuse ID name
+     *              - value to written (0 or 1)
+     */
+
+    case EFUSEIOC_WRITE_FIELD_BIT:
+      {
+        FAR struct efuse_par_id *param =
+                   (FAR struct efuse_par_id *)((uintptr_t)arg);
+
+        /* Write the efuse */
+
+        DEBUGASSERT(lower->ops->write_bit); /* Required */
+        ret = lower->ops->write_bit(lower,
+                                    (const efuse_desc_t **) param->field,
+                                    *param->data);
+      }
+      break;
+
+    /* cmd:         EFUSEIOC_READ_FIELD_BLOB
+     * Description: Read a blob of N bits from efuse.
+     * Argument:    - efuse_id
+     *              - offset
+     *              - nbits
+     */
+
+    case EFUSEIOC_READ_FIELD_BLOB:
+      {
+        FAR struct efuse_par_id *param;
+
+        /* Read a blob from EFUSEs */
+
+        if (lower->ops->read_blob) /* Optional */
+          {
+            param = (FAR struct efuse_par_id *)((uintptr_t)arg);
+            if (param)
+              {
+                ret = lower->ops->read_blob(lower,
+                                            (const efuse_desc_t **)
+                                              param->field,
+                                            param->data,
+                                            param->size);
+              }
+            else
+              {
+                ret = -EINVAL;
+              }
+          }
+        else
+          {
+            ret = -ENOSYS;
+          }
+      }
+      break;
+
+    /* cmd:         EFUSEIOC_WRITE_FIELD_BLOB
+     * Description: Write a blob of N bits to efuse.
+     * Argument:    - efuse_id
+     *              - blob_bits
+     *              - offset
+     *              - nbits
+     */
+
+    case EFUSEIOC_WRITE_FIELD_BLOB:
+      {
+        FAR struct efuse_par_id *param;
+
+        /* Write a blob to EFUSEs */
+
+        if (lower->ops->write_blob) /* Optional */
+          {
+            param = (FAR struct efuse_par_id *)((uintptr_t)arg);
+            if (param)
+              {
+                ret = lower->ops->write_blob(lower,
+                                             (const efuse_desc_t **)
+                                               param->field,
+                                             param->data,
+                                             param->size);
+              }
+            else
+              {
+                ret = -EINVAL;
+              }
+          }
+        else
+          {
+            ret = -ENOSYS;
+          }
+      }
+      break;
+
+    /* cmd:         EFUSEIOC_READ_REG
+     * Description: Read a 32-bit efuse register
+     * Argument:    - efuse_reg.
+     */
+
+    case EFUSEIOC_READ_REG:
+      {
+        FAR struct efuse_par *param;
+
+        DEBUGASSERT(param != NULL);
+
+        /* Read 32 efuses at once */
+
+        if (lower->ops->read_reg) /* Optional */
+          {
+            param = (FAR struct efuse_par *)((uintptr_t)arg);
+            if (param)
+              {
+                ret = lower->ops->read_reg(lower, param->block,
+                                           param->reg,
+                                           (uint32_t *) param->data);
+              }
+            else
+              {
+                ret = -EINVAL;
+              }
+          }
+        else
+          {
+            ret = -ENOSYS;
+          }
+      }
+      break;
+
+    /* cmd:         EFUSEIOC_WRITE_REG
+     * Description: Read a 32-bits efuses (register block).
+     * Argument:    - efuse_reg
+     *              - efuse_value
+     */
+
+    case EFUSEIOC_WRITE_REG:
+      {
+        FAR struct efuse_par *param;
+
+        /* Write 32 EFUSEs at once */
+
+        if (lower->ops->write_reg) /* Optional */
+          {
+            param = (FAR struct efuse_par *)((uintptr_t)arg);
+            if (param)
+              {
+                lower->ops->write_reg(lower, param->block,
+                                      param->reg, *param->data);
+              }
+            else
+              {
+                ret = -EINVAL;
+              }
+          }
+        else
+          {
+            ret = -ENOSYS;
+          }
+      }
+      break;
+
+    default:
+      {
+        minfo("Forwarding unrecognized cmd: %d arg: %ld\n", cmd, arg);
+
+        /* An ioctl commands that are not recognized by the "upper-half"
+         * driver are forwarded to the lower half driver through this
+         * method.
+         */
+
+        if (lower->ops->ioctl) /* Optional */
+          {
+            ret = lower->ops->ioctl(lower, cmd, arg);
+          }
+        else
+          {
+            ret = -ENOTTY;
+          }
+      }
+      break;
+    }
+
+  nxsem_post(&upper->exclsem);
+  return ret;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: efuse_register
+ *
+ * Description:
+ *   This function binds an instance of a "lower half" efuse driver with
+ *   the "upper half" efuse device and registers that device so that can
+ *   be usedby application code.
+ *
+ * Input Parameters:
+ *   dev path - The full path to the driver to be registers in the NuttX

Review comment:
       Thank you @saramonteiro !




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] acassis commented on a change in pull request #2628: Add generic efuse driver for NuttX

Posted by GitBox <gi...@apache.org>.
acassis commented on a change in pull request #2628:
URL: https://github.com/apache/incubator-nuttx/pull/2628#discussion_r557420652



##########
File path: include/nuttx/efuse/efuse.h
##########
@@ -0,0 +1,155 @@
+/****************************************************************************
+ * include/nuttx/efuse/efuse.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_EFUSE_EFUSE_H
+#define __INCLUDE_NUTTX_EFUSE_EFUSE_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs/ioctl.h>
+
+#include <signal.h>
+#include <stdint.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Command:     EFUSEIOC_READ_FIELD
+ * Description: Read a blob of bits from an efuse field.
+ * Arguments:   A structure containing the field[], a dst pointer, and size
+ *              of bits to be read from efuses.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD      _EFUSEIOC(0x0001)
+
+/* Command:     EFUSEIOC_WRITE_FIELD
+ * Description: Write a blob of bits to an efuse's field
+ * Arguments:   A structure containing the field[], the src memory and the
+ *              amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD     _EFUSEIOC(0x0002)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* Structure eFuse field */
+
+struct efuse_desc_s
+{
+  uint16_t   bit_offset; /* Bit offset related to beginning of efuse */
+  uint16_t   bit_count;  /* Length of bit field */
+};
+
+/* Type definition for an eFuse field */
+
+typedef struct efuse_desc_s efuse_desc_t;
+
+/* Structs with the parameters passed to the IOCTLs */
+
+struct efuse_param
+{
+  FAR const efuse_desc_t **field;

Review comment:
       Ok, I will add a comment in the header file explaining it, thank you!




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] acassis commented on a change in pull request #2628: Add generic efuse driver for NuttX

Posted by GitBox <gi...@apache.org>.
acassis commented on a change in pull request #2628:
URL: https://github.com/apache/incubator-nuttx/pull/2628#discussion_r557418477



##########
File path: drivers/efuse/efuse.c
##########
@@ -0,0 +1,395 @@
+/****************************************************************************
+ * drivers/efuse/efuse.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <string.h>
+#include <fcntl.h>
+#include <assert.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <nuttx/fs/fs.h>
+#include <nuttx/irq.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/power/pm.h>
+#include <nuttx/semaphore.h>
+#include <nuttx/efuse/efuse.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Type Definitions
+ ****************************************************************************/
+
+/* This structure describes the state of the upper half driver */
+
+struct efuse_upperhalf_s
+{
+  sem_t     exclsem;  /* Supports mutual exclusion */
+  FAR char *path;     /* Registration path */
+
+  /* The contained lower-half driver */
+
+  FAR struct efuse_lowerhalf_s *lower;
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int     efuse_open(FAR struct file *filep);
+static int     efuse_close(FAR struct file *filep);
+static ssize_t efuse_read(FAR struct file *filep, FAR char *buffer,
+                          size_t buflen);
+static ssize_t efuse_write(FAR struct file *filep, FAR const char *buffer,
+                           size_t buflen);
+static int     efuse_ioctl(FAR struct file *filep, int cmd,
+                           unsigned long arg);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct file_operations g_efuseops =
+{
+  efuse_open,  /* open */
+  efuse_close, /* close */
+  efuse_read,  /* read */
+  efuse_write, /* write */
+  NULL,        /* seek */
+  efuse_ioctl, /* ioctl */
+  NULL         /* poll */
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: efuse_open
+ *
+ * Description:
+ *   This function is called whenever the efuse timer device is opened.
+ *
+ ****************************************************************************/
+
+static int efuse_open(FAR struct file *filep)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: efuse_close
+ *
+ * Description:
+ *   This function is called when the efuse timer device is closed.
+ *
+ ****************************************************************************/
+
+static int efuse_close(FAR struct file *filep)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: efuse_read
+ *
+ * Description:
+ *   A dummy read method.  This is provided only to satisfy the VFS layer.
+ *
+ ****************************************************************************/
+
+static ssize_t efuse_read(FAR struct file *filep, FAR char *buffer,
+                         size_t buflen)
+{
+  /* Return zero -- usually meaning end-of-file */
+
+  return 0;
+}
+
+/****************************************************************************
+ * Name: efuse_write
+ *
+ * Description:
+ *   A dummy write method.  This is provided only to satisfy the VFS layer.
+ *
+ ****************************************************************************/
+
+static ssize_t efuse_write(FAR struct file *filep, FAR const char *buffer,
+                          size_t buflen)
+{
+  return 0;
+}
+
+/****************************************************************************
+ * Name: efuse_ioctl
+ *
+ * Description:
+ *   The standard ioctl method.  This is where ALL of the efuse timer
+ *   work is done.
+ *
+ ****************************************************************************/
+
+static int efuse_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
+{
+  FAR struct inode             *inode = filep->f_inode;
+  FAR struct efuse_upperhalf_s *upper;
+  FAR struct efuse_lowerhalf_s *lower;
+  int                           ret;
+
+  minfo("cmd: %d arg: %lu\n", cmd, arg);
+  upper = inode->i_private;
+  DEBUGASSERT(upper != NULL);
+  lower = upper->lower;
+  DEBUGASSERT(lower != NULL);
+
+  /* Get exclusive access to the device structures */
+
+  ret = nxsem_wait(&upper->exclsem);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  /* Handle built-in ioctl commands */
+
+  switch (cmd)
+    {
+    /* cmd:         EFUSEIOC_READ_FIELD
+     * Description: Read a field
+     * Argument:    A pointer to a struct efuse_param.
+     *              Where the field is an array.
+     *              Each item in the array is a pointer to an efuse_desc_t
+     *              variable.
+     *              An efuse_desc_t variable contains an offset to a field
+     *              or subfield and its size in bits.
+     *              The size param is a redundancy, and it is the sum
+     *              of all subfields sizes from efuse_desc_t in bits.
+     *              The data is a pointer to a pre-allocated space
+     *              where the driver will load the data read from efuse.
+     */
+
+    case EFUSEIOC_READ_FIELD:
+      {
+        FAR struct efuse_param *param =
+                   (FAR struct efuse_param *)((uintptr_t)arg);
+
+        /* Read the efuse */
+
+        DEBUGASSERT(lower->ops->read_field); /* Required */
+        ret = lower->ops->read_field(lower,
+                                     (const efuse_desc_t **) param->field,
+                                     param->data,
+                                     param->size);
+      }
+      break;
+
+    /* cmd:         EFUSEIOC_WRITE_FIELD
+     * Description: Write a field
+     * Argument: A pointer to a struct efuse_param.
+     *           Where the field is an array.
+     *           Each item in the array is a pointer to an efuse_desc_t
+     *           variable.
+     *           An efuse_desc_t variable contains an offset to a field
+     *           or subfield and its size in bits.
+     *           The size param is a redundancy, and it is the sum
+     *           of all subfields sizes from efuse_desc_t in bits.
+     *           The data is a pointer to a pre-allocated space
+     *           where the user wrote the value that he wants
+     *           to write in a field or subfield.
+     */
+
+    case EFUSEIOC_WRITE_FIELD:
+      {
+        FAR struct efuse_param *param =
+                   (FAR struct efuse_param *)((uintptr_t)arg);
+
+        /* Write the efuse */
+
+        DEBUGASSERT(lower->ops->write_field); /* Required */
+        ret = lower->ops->write_field(lower,
+                                      (const efuse_desc_t **) param->field,
+                                      param->data,
+                                      param->size);
+      }
+      break;
+
+    default:
+      {
+        minfo("Forwarding unrecognized cmd: %d arg: %lu\n", cmd, arg);
+
+        /* Ioctls commands that are not recognized by the "upper-half"
+         * driver are forwarded to the lower half driver through this
+         * method.
+         */
+
+        if (lower->ops->ioctl) /* Optional */
+          {
+            ret = lower->ops->ioctl(lower, cmd, arg);
+          }
+        else
+          {
+            ret = -ENOTTY;
+          }
+      }
+      break;
+    }
+
+  nxsem_post(&upper->exclsem);
+  return ret;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: efuse_register
+ *
+ * Description:
+ *   This function binds an instance of a "lower half" efuse driver with
+ *   the "upper half" efuse device and registers that device so that can
+ *   be used by application code.
+ *
+ * Input Parameters:
+ *   dev path - The full path to the driver to be registered in the NuttX
+ *     pseudo-filesystem.  The recommended convention is to name all
+ *     efuse drivers as "/dev/efuse".
+ *   lower - A pointer to an instance of lower half efuse driver.  This
+ *     instance is bound to the efuse driver and must persists as long as
+ *     the driver persists.
+ *
+ * Returned Value:
+ *   On success, a non-NULL handle is returned to the caller.  In the event
+ *   of any failure, a NULL value is returned.
+ *
+ ****************************************************************************/
+
+FAR void *efuse_register(FAR const char *path,
+                         FAR struct efuse_lowerhalf_s *lower)
+{
+  FAR struct efuse_upperhalf_s *upper;
+  int ret;
+
+  DEBUGASSERT(path && lower);
+  minfo("Entry: path=%s\n", path);
+
+  /* Allocate the upper-half data structure */
+
+  upper = (FAR struct efuse_upperhalf_s *)
+          kmm_zalloc(sizeof(struct efuse_upperhalf_s));
+  if (!upper)
+    {
+      merr("Upper half allocation failed\n");
+      goto errout;
+    }
+
+  /* Initialize the efuse timer device structure (it was already zeroed
+   * by kmm_zalloc()).
+   */
+
+  nxsem_init(&upper->exclsem, 0, 1);
+  upper->lower = lower;
+
+  /* Copy the registration path */
+
+  upper->path = strdup(path);
+  if (!upper->path)
+    {
+      merr("Path allocation failed\n");
+      goto errout_with_upper;
+    }
+
+  /* Register the efuse timer device */
+
+  ret = register_driver(path, &g_efuseops, 0666, upper);
+  if (ret < 0)
+    {
+      merr("register_driver failed: %d\n", ret);
+      goto errout_with_path;
+    }
+
+  return (FAR void *)upper;
+
+errout_with_path:
+  kmm_free(upper->path);
+
+errout_with_upper:
+  nxsem_destroy(&upper->exclsem);
+  kmm_free(upper);
+
+errout:
+  return NULL;
+}
+
+/****************************************************************************
+ * Name: efuse_unregister
+ *
+ * Description:
+ *   This function can be called to disable and unregister the efuse
+ *   device driver.
+ *
+ * Input Parameters:
+ *   handle - This is the handle that was returned by efuse_register()
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+void efuse_unregister(FAR void *handle)
+{
+  FAR struct efuse_upperhalf_s *upper;
+  FAR struct efuse_lowerhalf_s *lower;
+
+  /* Recover the pointer to the upper-half driver state */
+
+  upper = (FAR struct efuse_upperhalf_s *)handle;
+  DEBUGASSERT(upper != NULL);
+  lower = upper->lower;
+  DEBUGASSERT(lower != NULL);
+
+  minfo("Unregistering: %s\n", upper->path);
+
+  /* Unregister the efuse timer device */
+
+  unregister_driver(upper->path);
+
+  /* Then free all of the driver resources */
+
+  kmm_free(upper->path);
+  nxsem_destroy(&upper->exclsem);
+  kmm_free(lower);

Review comment:
       You are right @xiaoxiang781216 I will fix it! Thank you!




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] saramonteiro commented on a change in pull request #2628: Add generic efuse driver for NuttX

Posted by GitBox <gi...@apache.org>.
saramonteiro commented on a change in pull request #2628:
URL: https://github.com/apache/incubator-nuttx/pull/2628#discussion_r555259328



##########
File path: drivers/efuse/efuse.c
##########
@@ -0,0 +1,377 @@
+/****************************************************************************
+ * drivers/efuse/efuse.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <string.h>
+#include <fcntl.h>
+#include <assert.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <nuttx/fs/fs.h>
+#include <nuttx/irq.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/power/pm.h>
+#include <nuttx/semaphore.h>
+#include <nuttx/efuse/efuse.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Type Definitions
+ ****************************************************************************/
+
+/* This structure describes the state of the upper half driver */
+
+struct efuse_upperhalf_s
+{
+  sem_t     exclsem;  /* Supports mutual exclusion */
+  FAR char *path;     /* Registration path */
+
+  /* The contained lower-half driver */
+
+  FAR struct efuse_lowerhalf_s *lower;
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int     efuse_open(FAR struct file *filep);
+static int     efuse_close(FAR struct file *filep);
+static ssize_t efuse_read(FAR struct file *filep, FAR char *buffer,
+                          size_t buflen);
+static ssize_t efuse_write(FAR struct file *filep, FAR const char *buffer,
+                           size_t buflen);
+static int     efuse_ioctl(FAR struct file *filep, int cmd,
+                 unsigned long arg);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct file_operations g_efuseops =
+{
+  efuse_open,  /* open */
+  efuse_close, /* close */
+  efuse_read,  /* read */
+  efuse_write, /* write */
+  NULL,        /* seek */
+  efuse_ioctl, /* ioctl */
+  NULL         /* poll */
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: efuse_open
+ *
+ * Description:
+ *   This function is called whenever the efuse timer device is opened.
+ *
+ ****************************************************************************/
+
+static int efuse_open(FAR struct file *filep)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: efuse_close
+ *
+ * Description:
+ *   This function is called when the efuse timer device is closed.
+ *
+ ****************************************************************************/
+
+static int efuse_close(FAR struct file *filep)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: efuse_read
+ *
+ * Description:
+ *   A dummy read method.  This is provided only to satisfy the VFS layer.
+ *
+ ****************************************************************************/
+
+static ssize_t efuse_read(FAR struct file *filep, FAR char *buffer,
+                         size_t buflen)
+{
+  /* Return zero -- usually meaning end-of-file */
+
+  return 0;
+}
+
+/****************************************************************************
+ * Name: efuse_write
+ *
+ * Description:
+ *   A dummy write method.  This is provided only to satisfy the VFS layer.
+ *
+ ****************************************************************************/
+
+static ssize_t efuse_write(FAR struct file *filep, FAR const char *buffer,
+                          size_t buflen)
+{
+  return 0;
+}
+
+/****************************************************************************
+ * Name: efuse_ioctl
+ *
+ * Description:
+ *   The standard ioctl method.  This is where ALL of the efuse timer
+ *   work is done.
+ *
+ ****************************************************************************/
+
+static int efuse_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
+{
+  FAR struct inode             *inode = filep->f_inode;
+  FAR struct efuse_upperhalf_s *upper;
+  FAR struct efuse_lowerhalf_s *lower;
+  int                           ret;
+
+  minfo("cmd: %d arg: %ld\n", cmd, arg);
+  upper = inode->i_private;
+  DEBUGASSERT(upper != NULL);
+  lower = upper->lower;
+  DEBUGASSERT(lower != NULL);
+
+  /* Get exclusive access to the device structures */
+
+  ret = nxsem_wait(&upper->exclsem);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  /* Handle built-in ioctl commands */
+
+  switch (cmd)
+    {
+    /* cmd:         EFUSEIOC_READ_FIELD_BIT
+     * Description: Read a single bit efuse
+     * Argument:    Return variable
+     */

Review comment:
       ```suggestion
       /* cmd:         EFUSEIOC_READ_FIELD
        * Description: Read a field
        * Argument:  A pointer to a struct efuse_param. 
        *                    Where the field is an array.
        *                    Each item in the array is a pointer to an efuse_desc_t variable.
        *                   An efuse_desc_t variable contains an offset to a field or subfield and its size in bits.  
        *                  The size param is a redundancy, and it is the sum of all subfields sizes from
        *                  from efuse_desc_t in bits.
        *                  The data is a pointer to a pre-allocated space where the driver will load 
        *                   the data read from efuse.
        */
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] acassis commented on pull request #2628: Add generic efuse driver for NuttX

Posted by GitBox <gi...@apache.org>.
acassis commented on pull request #2628:
URL: https://github.com/apache/incubator-nuttx/pull/2628#issuecomment-760941563


   Sure, I will do it now! Thank you very much @xiaoxiang781216 


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a change in pull request #2628: Add generic efuse driver for NuttX

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on a change in pull request #2628:
URL: https://github.com/apache/incubator-nuttx/pull/2628#discussion_r554449792



##########
File path: include/nuttx/efuse/efuse.h
##########
@@ -0,0 +1,294 @@
+/****************************************************************************
+ * include/nuttx/efuse/efuse.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_EFUSE_EFUSE_H
+#define __INCLUDE_NUTTX_EFUSE_EFUSE_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs/ioctl.h>
+
+#include <signal.h>
+#include <stdint.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Command:     EFUSEIOC_READ_FIELD_BLOB
+ * Description: Read a blob of bits from an efuse field.
+ * Arguments:   A structure containing the field[], a dst pointer, and size
+ *              of bits to be read from efuses.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD_BLOB      _EFUSEIOC(0x0001)
+
+/* Command:     EFUSEIOC_READ_FIELD_BIT
+ * Description: Read of state of an efuse bit.
+ * Arguments:   A structure containing the field to be read.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD_BIT       _EFUSEIOC(0x0002)
+
+/* Command:     EFUSEIOC_WRITE_FIELD_BLOB
+ * Description: Write a blob of bits to an efuse's field
+ * Arguments:   A structure containing the field[], the src memory and the
+ *              amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD_BLOB     _EFUSEIOC(0x0003)
+
+/* Command:     EFUSEIOC_WRITE_FIELD_BIT
+ * Description: Write a bit to an efuse (burn it).
+ * Arguments:   A structure containing bit field.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD_BIT      _EFUSEIOC(0x0004)
+
+/* Command:     EFUSEIOC_GET_FIELD_SIZE
+ * Description: Get the length of the field in bits.
+ * Arguments:   A structure containing the fields.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_GET_FIELD_SIZE       _EFUSEIOC(0x0005)
+
+/* Command:     EFUSEIOC_READ_REG
+ * Description: Read an efuse register.
+ * Arguments:   A structure containing the block number and the register to
+ *              be read.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_REG             _EFUSEIOC(0x0006)
+
+/* Command:     EFUSEIOC_WRITE_REG
+ * Description: Write an efuse register.
+ * Arguments:   A structure containing the block number, the register to
+ *              write and value to be written.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_REG            _EFUSEIOC(0x0007)
+
+/* Command:     EFUSEIOC_READ_BLOCK
+ * Description: Read a key from efuse's block.
+ * Arguments:   A structure containing the block number, the dst_key pointer,
+ *              the offset in bits and the amount of bits to read.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_BLOCK           _EFUSEIOC(0x0008)
+
+/* Command:     EFUSEIOC_WRITE_BLOCK
+ * Description: Write a key to efuse's block.
+ * Arguments:   A structure containing the block number, the src_key pointer,
+ *              the offset in bits and the amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_BLOCK          _EFUSEIOC(0x0009)
+
+/* Command:     EFUSEIOC_BATCH_WRITE_BEGIN
+ * Description: Start a batch operation, the efuse bits will be burned after
+ *              a batch write commit operation.
+ * Arguments:   None
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_BATCH_WRITE_BEGIN    _EFUSEIOC(0x000a)
+
+/* Command:     EFUSEIOC_BATCH_WRITE_CANCEL
+ * Description: Cancel a started batch write operation in progress.
+ * Arguments:   None
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_BATCH_WRITE_CANCEL   _EFUSEIOC(0x000b)
+
+/* Command:     EFUSEIOC_BATCH_WRITE_COMMIT
+ * Description: Commit a batch operation that was in progress.
+ * Arguments:   None
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_BATCH_WRITE_COMMIT   _EFUSEIOC(0x000c)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* Structure eFuse field */
+
+struct efuse_desc_s
+{
+  uint16_t   efuse_block;    /* Block of eFuse */
+  uint16_t   bit_start;      /* Start bit [0..65535] */
+  uint16_t   bit_count;      /* Length of bit field [1..-] */
+};
+
+/* Type definition for an eFuse field */
+
+typedef struct efuse_desc_s efuse_desc_t;
+
+/* Structure range address by blocks */
+
+typedef struct
+{
+  uint32_t start;
+  uint32_t end;
+} efuse_range_addr_t;
+
+/* Structs with the parameters passed to the IOCTLs */
+
+struct efuse_par
+{
+  uint16_t block;
+  uint16_t reg;
+  size_t   bit_offset;
+  size_t   bit_size;
+  uint8_t *data;
+};
+
+struct efuse_par_id
+{
+  efuse_desc_t **field;
+  size_t  size;
+  uint8_t *data;
+};
+
+/* This structure provides the "lower-half" driver operations available to
+ * the "upper-half" driver.
+ */
+
+struct efuse_lowerhalf_s;
+struct efuse_ops_s
+{
+  /* Required methods *******************************************************/
+
+  /* Read an EFUSE bit */
+
+  CODE int (*read_bit)(FAR struct efuse_lowerhalf_s *lower,
+                       const efuse_desc_t *field[],

Review comment:
       Since efuse_desc_t is very flexible, doesn't this mean we just need two callback(read/write with efuse_desc_t array) now?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a change in pull request #2628: Add generic efuse driver for NuttX

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on a change in pull request #2628:
URL: https://github.com/apache/incubator-nuttx/pull/2628#discussion_r557459942



##########
File path: include/nuttx/efuse/efuse.h
##########
@@ -0,0 +1,155 @@
+/****************************************************************************
+ * include/nuttx/efuse/efuse.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_EFUSE_EFUSE_H
+#define __INCLUDE_NUTTX_EFUSE_EFUSE_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs/ioctl.h>
+
+#include <signal.h>
+#include <stdint.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Command:     EFUSEIOC_READ_FIELD
+ * Description: Read a blob of bits from an efuse field.
+ * Arguments:   A structure containing the field[], a dst pointer, and size
+ *              of bits to be read from efuses.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD      _EFUSEIOC(0x0001)
+
+/* Command:     EFUSEIOC_WRITE_FIELD
+ * Description: Write a blob of bits to an efuse's field
+ * Arguments:   A structure containing the field[], the src memory and the
+ *              amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD     _EFUSEIOC(0x0002)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* Structure eFuse field */
+
+struct efuse_desc_s
+{
+  uint16_t   bit_offset; /* Bit offset related to beginning of efuse */
+  uint16_t   bit_count;  /* Length of bit field */
+};
+
+/* Type definition for an eFuse field */
+
+typedef struct efuse_desc_s efuse_desc_t;
+
+/* Structs with the parameters passed to the IOCTLs */
+
+struct efuse_param
+{
+  FAR const efuse_desc_t **field;
+  size_t  size;
+  FAR uint8_t *data;

Review comment:
       Ok, please document the layout, thanks.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] acassis commented on a change in pull request #2628: Add generic efuse driver for NuttX

Posted by GitBox <gi...@apache.org>.
acassis commented on a change in pull request #2628:
URL: https://github.com/apache/incubator-nuttx/pull/2628#discussion_r557617455



##########
File path: include/nuttx/efuse/efuse.h
##########
@@ -0,0 +1,155 @@
+/****************************************************************************
+ * include/nuttx/efuse/efuse.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_EFUSE_EFUSE_H
+#define __INCLUDE_NUTTX_EFUSE_EFUSE_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs/ioctl.h>
+
+#include <signal.h>
+#include <stdint.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Command:     EFUSEIOC_READ_FIELD
+ * Description: Read a blob of bits from an efuse field.
+ * Arguments:   A structure containing the field[], a dst pointer, and size
+ *              of bits to be read from efuses.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD      _EFUSEIOC(0x0001)
+
+/* Command:     EFUSEIOC_WRITE_FIELD
+ * Description: Write a blob of bits to an efuse's field
+ * Arguments:   A structure containing the field[], the src memory and the
+ *              amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD     _EFUSEIOC(0x0002)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* Structure eFuse field */
+
+struct efuse_desc_s
+{
+  uint16_t   bit_offset; /* Bit offset related to beginning of efuse */
+  uint16_t   bit_count;  /* Length of bit field */
+};
+
+/* Type definition for an eFuse field */
+
+typedef struct efuse_desc_s efuse_desc_t;
+
+/* Structs with the parameters passed to the IOCTLs */
+
+struct efuse_param
+{
+  FAR const efuse_desc_t **field;
+  size_t  size;
+  FAR uint8_t *data;

Review comment:
       Ok, thank you!




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] acassis commented on pull request #2628: Add generic efuse driver for NuttX

Posted by GitBox <gi...@apache.org>.
acassis commented on pull request #2628:
URL: https://github.com/apache/incubator-nuttx/pull/2628#issuecomment-758565347


   hi @xiaoxiang781216 the building is passing on everything, except MacOS. Could you please help me and/or merge this PR?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] xiaoxiang781216 commented on pull request #2628: Add generic efuse driver for NuttX

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on pull request #2628:
URL: https://github.com/apache/incubator-nuttx/pull/2628#issuecomment-758638614


   @acassis I will take a look tonight.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] acassis commented on a change in pull request #2628: Add generic efuse driver for NuttX

Posted by GitBox <gi...@apache.org>.
acassis commented on a change in pull request #2628:
URL: https://github.com/apache/incubator-nuttx/pull/2628#discussion_r555971036



##########
File path: include/nuttx/efuse/efuse.h
##########
@@ -0,0 +1,155 @@
+/****************************************************************************
+ * include/nuttx/efuse/efuse.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_EFUSE_EFUSE_H
+#define __INCLUDE_NUTTX_EFUSE_EFUSE_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs/ioctl.h>
+
+#include <signal.h>
+#include <stdint.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Command:     EFUSEIOC_READ_FIELD
+ * Description: Read a blob of bits from an efuse field.
+ * Arguments:   A structure containing the field[], a dst pointer, and size
+ *              of bits to be read from efuses.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD      _EFUSEIOC(0x0001)
+
+/* Command:     EFUSEIOC_WRITE_FIELD
+ * Description: Write a blob of bits to an efuse's field
+ * Arguments:   A structure containing the field[], the src memory and the
+ *              amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD     _EFUSEIOC(0x0002)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* Structure eFuse field */
+
+struct efuse_desc_s
+{
+  uint16_t   bit_offset;     /* Bit offset related to beginning of efuse */
+  uint16_t   bit_count;      /* Length of bit field */

Review comment:
       Done




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] acassis commented on a change in pull request #2628: Add generic efuse driver for NuttX

Posted by GitBox <gi...@apache.org>.
acassis commented on a change in pull request #2628:
URL: https://github.com/apache/incubator-nuttx/pull/2628#discussion_r556711018



##########
File path: drivers/efuse/efuse.c
##########
@@ -0,0 +1,395 @@
+/****************************************************************************
+ * drivers/efuse/efuse.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <string.h>
+#include <fcntl.h>
+#include <assert.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <nuttx/fs/fs.h>
+#include <nuttx/irq.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/power/pm.h>
+#include <nuttx/semaphore.h>
+#include <nuttx/efuse/efuse.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Type Definitions
+ ****************************************************************************/
+
+/* This structure describes the state of the upper half driver */
+
+struct efuse_upperhalf_s
+{
+  sem_t     exclsem;  /* Supports mutual exclusion */
+  FAR char *path;     /* Registration path */
+
+  /* The contained lower-half driver */
+
+  FAR struct efuse_lowerhalf_s *lower;
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int     efuse_open(FAR struct file *filep);
+static int     efuse_close(FAR struct file *filep);
+static ssize_t efuse_read(FAR struct file *filep, FAR char *buffer,
+                          size_t buflen);
+static ssize_t efuse_write(FAR struct file *filep, FAR const char *buffer,
+                           size_t buflen);
+static int     efuse_ioctl(FAR struct file *filep, int cmd,
+                           unsigned long arg);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct file_operations g_efuseops =
+{
+  efuse_open,  /* open */
+  efuse_close, /* close */
+  efuse_read,  /* read */
+  efuse_write, /* write */
+  NULL,        /* seek */
+  efuse_ioctl, /* ioctl */
+  NULL         /* poll */
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: efuse_open
+ *
+ * Description:
+ *   This function is called whenever the efuse timer device is opened.
+ *
+ ****************************************************************************/
+
+static int efuse_open(FAR struct file *filep)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: efuse_close
+ *
+ * Description:
+ *   This function is called when the efuse timer device is closed.
+ *
+ ****************************************************************************/
+
+static int efuse_close(FAR struct file *filep)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: efuse_read
+ *
+ * Description:
+ *   A dummy read method.  This is provided only to satisfy the VFS layer.
+ *
+ ****************************************************************************/
+
+static ssize_t efuse_read(FAR struct file *filep, FAR char *buffer,
+                         size_t buflen)
+{
+  /* Return zero -- usually meaning end-of-file */
+
+  return 0;
+}
+
+/****************************************************************************
+ * Name: efuse_write
+ *
+ * Description:
+ *   A dummy write method.  This is provided only to satisfy the VFS layer.
+ *
+ ****************************************************************************/
+
+static ssize_t efuse_write(FAR struct file *filep, FAR const char *buffer,
+                          size_t buflen)
+{
+  return 0;
+}
+
+/****************************************************************************
+ * Name: efuse_ioctl
+ *
+ * Description:
+ *   The standard ioctl method.  This is where ALL of the efuse timer
+ *   work is done.
+ *
+ ****************************************************************************/
+
+static int efuse_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
+{
+  FAR struct inode             *inode = filep->f_inode;
+  FAR struct efuse_upperhalf_s *upper;
+  FAR struct efuse_lowerhalf_s *lower;
+  int                           ret;
+
+  minfo("cmd: %d arg: %lu\n", cmd, arg);
+  upper = inode->i_private;
+  DEBUGASSERT(upper != NULL);
+  lower = upper->lower;
+  DEBUGASSERT(lower != NULL);
+
+  /* Get exclusive access to the device structures */
+
+  ret = nxsem_wait(&upper->exclsem);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  /* Handle built-in ioctl commands */
+
+  switch (cmd)
+    {
+    /* cmd:         EFUSEIOC_READ_FIELD
+     * Description: Read a field
+     * Argument:    A pointer to a struct efuse_param.
+     *              Where the field is an array.
+     *              Each item in the array is a pointer to an efuse_desc_t
+     *              variable.
+     *              An efuse_desc_t variable contains an offset to a field
+     *              or subfield and its size in bits.
+     *              The size param is a redundancy, and it is the sum
+     *              of all subfields sizes from efuse_desc_t in bits.
+     *              The data is a pointer to a pre-allocated space
+     *              where the driver will load the data read from efuse.
+     */
+
+    case EFUSEIOC_READ_FIELD:
+      {
+        FAR struct efuse_param *param =
+                   (FAR struct efuse_param *)((uintptr_t)arg);
+
+        /* Read the efuse */
+
+        DEBUGASSERT(lower->ops->read_field); /* Required */
+        ret = lower->ops->read_field(lower,
+                                     (const efuse_desc_t **) param->field,

Review comment:
       You are right, thank you!

##########
File path: drivers/efuse/efuse.c
##########
@@ -0,0 +1,395 @@
+/****************************************************************************
+ * drivers/efuse/efuse.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <string.h>
+#include <fcntl.h>
+#include <assert.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <nuttx/fs/fs.h>
+#include <nuttx/irq.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/power/pm.h>
+#include <nuttx/semaphore.h>
+#include <nuttx/efuse/efuse.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Type Definitions
+ ****************************************************************************/
+
+/* This structure describes the state of the upper half driver */
+
+struct efuse_upperhalf_s
+{
+  sem_t     exclsem;  /* Supports mutual exclusion */
+  FAR char *path;     /* Registration path */
+
+  /* The contained lower-half driver */
+
+  FAR struct efuse_lowerhalf_s *lower;
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int     efuse_open(FAR struct file *filep);
+static int     efuse_close(FAR struct file *filep);
+static ssize_t efuse_read(FAR struct file *filep, FAR char *buffer,
+                          size_t buflen);
+static ssize_t efuse_write(FAR struct file *filep, FAR const char *buffer,
+                           size_t buflen);
+static int     efuse_ioctl(FAR struct file *filep, int cmd,
+                           unsigned long arg);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct file_operations g_efuseops =
+{
+  efuse_open,  /* open */
+  efuse_close, /* close */
+  efuse_read,  /* read */
+  efuse_write, /* write */
+  NULL,        /* seek */
+  efuse_ioctl, /* ioctl */
+  NULL         /* poll */
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: efuse_open
+ *
+ * Description:
+ *   This function is called whenever the efuse timer device is opened.
+ *
+ ****************************************************************************/
+
+static int efuse_open(FAR struct file *filep)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: efuse_close
+ *
+ * Description:
+ *   This function is called when the efuse timer device is closed.
+ *
+ ****************************************************************************/
+
+static int efuse_close(FAR struct file *filep)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: efuse_read
+ *
+ * Description:
+ *   A dummy read method.  This is provided only to satisfy the VFS layer.
+ *
+ ****************************************************************************/
+
+static ssize_t efuse_read(FAR struct file *filep, FAR char *buffer,
+                         size_t buflen)
+{
+  /* Return zero -- usually meaning end-of-file */
+
+  return 0;
+}
+
+/****************************************************************************
+ * Name: efuse_write
+ *
+ * Description:
+ *   A dummy write method.  This is provided only to satisfy the VFS layer.
+ *
+ ****************************************************************************/
+
+static ssize_t efuse_write(FAR struct file *filep, FAR const char *buffer,
+                          size_t buflen)
+{
+  return 0;
+}
+
+/****************************************************************************
+ * Name: efuse_ioctl
+ *
+ * Description:
+ *   The standard ioctl method.  This is where ALL of the efuse timer
+ *   work is done.
+ *
+ ****************************************************************************/
+
+static int efuse_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
+{
+  FAR struct inode             *inode = filep->f_inode;
+  FAR struct efuse_upperhalf_s *upper;
+  FAR struct efuse_lowerhalf_s *lower;
+  int                           ret;
+
+  minfo("cmd: %d arg: %lu\n", cmd, arg);
+  upper = inode->i_private;
+  DEBUGASSERT(upper != NULL);
+  lower = upper->lower;
+  DEBUGASSERT(lower != NULL);
+
+  /* Get exclusive access to the device structures */
+
+  ret = nxsem_wait(&upper->exclsem);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  /* Handle built-in ioctl commands */
+
+  switch (cmd)
+    {
+    /* cmd:         EFUSEIOC_READ_FIELD
+     * Description: Read a field
+     * Argument:    A pointer to a struct efuse_param.
+     *              Where the field is an array.
+     *              Each item in the array is a pointer to an efuse_desc_t
+     *              variable.
+     *              An efuse_desc_t variable contains an offset to a field
+     *              or subfield and its size in bits.
+     *              The size param is a redundancy, and it is the sum
+     *              of all subfields sizes from efuse_desc_t in bits.
+     *              The data is a pointer to a pre-allocated space
+     *              where the driver will load the data read from efuse.
+     */
+
+    case EFUSEIOC_READ_FIELD:
+      {
+        FAR struct efuse_param *param =
+                   (FAR struct efuse_param *)((uintptr_t)arg);
+
+        /* Read the efuse */
+
+        DEBUGASSERT(lower->ops->read_field); /* Required */
+        ret = lower->ops->read_field(lower,
+                                     (const efuse_desc_t **) param->field,
+                                     param->data,
+                                     param->size);
+      }
+      break;
+
+    /* cmd:         EFUSEIOC_WRITE_FIELD
+     * Description: Write a field
+     * Argument: A pointer to a struct efuse_param.
+     *           Where the field is an array.
+     *           Each item in the array is a pointer to an efuse_desc_t
+     *           variable.
+     *           An efuse_desc_t variable contains an offset to a field
+     *           or subfield and its size in bits.
+     *           The size param is a redundancy, and it is the sum
+     *           of all subfields sizes from efuse_desc_t in bits.
+     *           The data is a pointer to a pre-allocated space
+     *           where the user wrote the value that he wants
+     *           to write in a field or subfield.
+     */
+
+    case EFUSEIOC_WRITE_FIELD:
+      {
+        FAR struct efuse_param *param =
+                   (FAR struct efuse_param *)((uintptr_t)arg);
+
+        /* Write the efuse */
+
+        DEBUGASSERT(lower->ops->write_field); /* Required */
+        ret = lower->ops->write_field(lower,
+                                      (const efuse_desc_t **) param->field,

Review comment:
       Ditto, thanks!




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] saramonteiro commented on a change in pull request #2628: Add generic efuse driver for NuttX

Posted by GitBox <gi...@apache.org>.
saramonteiro commented on a change in pull request #2628:
URL: https://github.com/apache/incubator-nuttx/pull/2628#discussion_r554078069



##########
File path: drivers/efuse/efuse.c
##########
@@ -0,0 +1,514 @@
+/****************************************************************************
+ * drivers/efuse/efuse.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <string.h>
+#include <fcntl.h>
+#include <assert.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <nuttx/fs/fs.h>
+#include <nuttx/irq.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/power/pm.h>
+#include <nuttx/semaphore.h>
+#include <nuttx/efuse/efuse.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Type Definitions
+ ****************************************************************************/
+
+/* This structure describes the state of the upper half driver */
+
+struct efuse_upperhalf_s
+{
+  sem_t     exclsem;  /* Supports mutual exclusion */
+  FAR char *path;     /* Registration path */
+
+  /* The contained lower-half driver */
+
+  FAR struct efuse_lowerhalf_s *lower;
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int     efuse_open(FAR struct file *filep);
+static int     efuse_close(FAR struct file *filep);
+static ssize_t efuse_read(FAR struct file *filep, FAR char *buffer,
+                          size_t buflen);
+static ssize_t efuse_write(FAR struct file *filep, FAR const char *buffer,
+                           size_t buflen);
+static int     efuse_ioctl(FAR struct file *filep, int cmd,
+                 unsigned long arg);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct file_operations g_efuseops =
+{
+  efuse_open,  /* open */
+  efuse_close, /* close */
+  efuse_read,  /* read */
+  efuse_write, /* write */
+  NULL,        /* seek */
+  efuse_ioctl, /* ioctl */
+  NULL         /* poll */
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: efuse_open
+ *
+ * Description:
+ *   This function is called whenever the efuse timer device is opened.
+ *
+ ****************************************************************************/
+
+static int efuse_open(FAR struct file *filep)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: efuse_close
+ *
+ * Description:
+ *   This function is called when the efuse timer device is closed.
+ *
+ ****************************************************************************/
+
+static int efuse_close(FAR struct file *filep)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: efuse_read
+ *
+ * Description:
+ *   A dummy read method.  This is provided only to satisfy the VFS layer.
+ *
+ ****************************************************************************/
+
+static ssize_t efuse_read(FAR struct file *filep, FAR char *buffer,
+                         size_t buflen)
+{
+  /* Return zero -- usually meaning end-of-file */
+
+  return 0;
+}
+
+/****************************************************************************
+ * Name: efuse_write
+ *
+ * Description:
+ *   A dummy write method.  This is provided only to satisfy the VFS layer.
+ *
+ ****************************************************************************/
+
+static ssize_t efuse_write(FAR struct file *filep, FAR const char *buffer,
+                          size_t buflen)
+{
+  return 0;
+}
+
+/****************************************************************************
+ * Name: efuse_ioctl
+ *
+ * Description:
+ *   The standard ioctl method.  This is where ALL of the efuse timer
+ *   work is done.
+ *
+ ****************************************************************************/
+
+static int efuse_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
+{
+  FAR struct inode             *inode = filep->f_inode;
+  FAR struct efuse_upperhalf_s *upper;
+  FAR struct efuse_lowerhalf_s *lower;
+  int                           ret;
+
+  minfo("cmd: %d arg: %ld\n", cmd, arg);

Review comment:
       ```suggestion
     minfo("cmd: %d arg: %lu\n", cmd, arg);
   ```

##########
File path: drivers/efuse/efuse.c
##########
@@ -0,0 +1,514 @@
+/****************************************************************************
+ * drivers/efuse/efuse.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <string.h>
+#include <fcntl.h>
+#include <assert.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <nuttx/fs/fs.h>
+#include <nuttx/irq.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/power/pm.h>
+#include <nuttx/semaphore.h>
+#include <nuttx/efuse/efuse.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Type Definitions
+ ****************************************************************************/
+
+/* This structure describes the state of the upper half driver */
+
+struct efuse_upperhalf_s
+{
+  sem_t     exclsem;  /* Supports mutual exclusion */
+  FAR char *path;     /* Registration path */
+
+  /* The contained lower-half driver */
+
+  FAR struct efuse_lowerhalf_s *lower;
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int     efuse_open(FAR struct file *filep);
+static int     efuse_close(FAR struct file *filep);
+static ssize_t efuse_read(FAR struct file *filep, FAR char *buffer,
+                          size_t buflen);
+static ssize_t efuse_write(FAR struct file *filep, FAR const char *buffer,
+                           size_t buflen);
+static int     efuse_ioctl(FAR struct file *filep, int cmd,
+                 unsigned long arg);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct file_operations g_efuseops =
+{
+  efuse_open,  /* open */
+  efuse_close, /* close */
+  efuse_read,  /* read */
+  efuse_write, /* write */
+  NULL,        /* seek */
+  efuse_ioctl, /* ioctl */
+  NULL         /* poll */
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: efuse_open
+ *
+ * Description:
+ *   This function is called whenever the efuse timer device is opened.
+ *
+ ****************************************************************************/
+
+static int efuse_open(FAR struct file *filep)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: efuse_close
+ *
+ * Description:
+ *   This function is called when the efuse timer device is closed.
+ *
+ ****************************************************************************/
+
+static int efuse_close(FAR struct file *filep)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: efuse_read
+ *
+ * Description:
+ *   A dummy read method.  This is provided only to satisfy the VFS layer.
+ *
+ ****************************************************************************/
+
+static ssize_t efuse_read(FAR struct file *filep, FAR char *buffer,
+                         size_t buflen)
+{
+  /* Return zero -- usually meaning end-of-file */
+
+  return 0;
+}
+
+/****************************************************************************
+ * Name: efuse_write
+ *
+ * Description:
+ *   A dummy write method.  This is provided only to satisfy the VFS layer.
+ *
+ ****************************************************************************/
+
+static ssize_t efuse_write(FAR struct file *filep, FAR const char *buffer,
+                          size_t buflen)
+{
+  return 0;
+}
+
+/****************************************************************************
+ * Name: efuse_ioctl
+ *
+ * Description:
+ *   The standard ioctl method.  This is where ALL of the efuse timer
+ *   work is done.
+ *
+ ****************************************************************************/
+
+static int efuse_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
+{
+  FAR struct inode             *inode = filep->f_inode;
+  FAR struct efuse_upperhalf_s *upper;
+  FAR struct efuse_lowerhalf_s *lower;
+  int                           ret;
+
+  minfo("cmd: %d arg: %ld\n", cmd, arg);
+  upper = inode->i_private;
+  DEBUGASSERT(upper != NULL);
+  lower = upper->lower;
+  DEBUGASSERT(lower != NULL);
+
+  /* Get exclusive access to the device structures */
+
+  ret = nxsem_wait(&upper->exclsem);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  /* Handle built-in ioctl commands */
+
+  switch (cmd)
+    {
+    /* cmd:         EFUSEIOC_READ_FIELD_BIT
+     * Description: Read a single bit efuse
+     * Argument:    Return variable
+     */
+
+    case EFUSEIOC_READ_FIELD_BIT:
+      {
+        FAR struct efuse_par_id *param =
+                   (FAR struct efuse_par_id *)((uintptr_t)arg);
+
+        /* Read the efuse */
+
+        DEBUGASSERT(lower->ops->read_bit); /* Required */
+        ret = lower->ops->read_bit(lower,
+                                   (const efuse_desc_t **) param->field,
+                                   param->data);
+      }
+      break;
+
+    /* cmd:         EFUSEIOC_WRITE_FIELD_BIT
+     * Description: Write a single bit efuse
+     * Argument:    - efuse ID name
+     *              - value to written (0 or 1)
+     */
+
+    case EFUSEIOC_WRITE_FIELD_BIT:
+      {
+        FAR struct efuse_par_id *param =
+                   (FAR struct efuse_par_id *)((uintptr_t)arg);
+
+        /* Write the efuse */
+
+        DEBUGASSERT(lower->ops->write_bit); /* Required */
+        ret = lower->ops->write_bit(lower,
+                                    (const efuse_desc_t **) param->field,
+                                    *param->data);
+      }
+      break;
+
+    /* cmd:         EFUSEIOC_READ_FIELD_BLOB
+     * Description: Read a blob of N bits from efuse.
+     * Argument:    - efuse_id
+     *              - offset
+     *              - nbits
+     */
+
+    case EFUSEIOC_READ_FIELD_BLOB:
+      {
+        FAR struct efuse_par_id *param;
+
+        /* Read a blob from EFUSEs */
+
+        if (lower->ops->read_blob) /* Optional */
+          {
+            param = (FAR struct efuse_par_id *)((uintptr_t)arg);
+            if (param)
+              {
+                ret = lower->ops->read_blob(lower,
+                                            (const efuse_desc_t **)
+                                              param->field,
+                                            param->data,
+                                            param->size);
+              }
+            else
+              {
+                ret = -EINVAL;
+              }
+          }
+        else
+          {
+            ret = -ENOSYS;
+          }
+      }
+      break;
+
+    /* cmd:         EFUSEIOC_WRITE_FIELD_BLOB
+     * Description: Write a blob of N bits to efuse.
+     * Argument:    - efuse_id
+     *              - blob_bits
+     *              - offset
+     *              - nbits
+     */
+
+    case EFUSEIOC_WRITE_FIELD_BLOB:
+      {
+        FAR struct efuse_par_id *param;
+
+        /* Write a blob to EFUSEs */
+
+        if (lower->ops->write_blob) /* Optional */
+          {
+            param = (FAR struct efuse_par_id *)((uintptr_t)arg);
+            if (param)
+              {
+                ret = lower->ops->write_blob(lower,
+                                             (const efuse_desc_t **)
+                                               param->field,
+                                             param->data,
+                                             param->size);
+              }
+            else
+              {
+                ret = -EINVAL;
+              }
+          }
+        else
+          {
+            ret = -ENOSYS;
+          }
+      }
+      break;
+
+    /* cmd:         EFUSEIOC_READ_REG
+     * Description: Read a 32-bit efuse register
+     * Argument:    - efuse_reg.
+     */
+
+    case EFUSEIOC_READ_REG:
+      {
+        FAR struct efuse_par *param;
+
+        DEBUGASSERT(param != NULL);
+
+        /* Read 32 efuses at once */
+
+        if (lower->ops->read_reg) /* Optional */
+          {
+            param = (FAR struct efuse_par *)((uintptr_t)arg);
+            if (param)
+              {
+                ret = lower->ops->read_reg(lower, param->block,
+                                           param->reg,
+                                           (uint32_t *) param->data);
+              }
+            else
+              {
+                ret = -EINVAL;
+              }
+          }
+        else
+          {
+            ret = -ENOSYS;
+          }
+      }
+      break;
+
+    /* cmd:         EFUSEIOC_WRITE_REG
+     * Description: Read a 32-bits efuses (register block).
+     * Argument:    - efuse_reg
+     *              - efuse_value
+     */
+
+    case EFUSEIOC_WRITE_REG:
+      {
+        FAR struct efuse_par *param;
+
+        /* Write 32 EFUSEs at once */
+
+        if (lower->ops->write_reg) /* Optional */
+          {
+            param = (FAR struct efuse_par *)((uintptr_t)arg);
+            if (param)
+              {
+                lower->ops->write_reg(lower, param->block,
+                                      param->reg, *param->data);
+              }
+            else
+              {
+                ret = -EINVAL;
+              }
+          }
+        else
+          {
+            ret = -ENOSYS;
+          }
+      }
+      break;
+
+    default:
+      {
+        minfo("Forwarding unrecognized cmd: %d arg: %ld\n", cmd, arg);

Review comment:
       ```suggestion
           minfo("Forwarding unrecognized cmd: %d arg: %lu\n", cmd, arg);
   ```

##########
File path: drivers/efuse/efuse.c
##########
@@ -0,0 +1,514 @@
+/****************************************************************************
+ * drivers/efuse/efuse.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <string.h>
+#include <fcntl.h>
+#include <assert.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <nuttx/fs/fs.h>
+#include <nuttx/irq.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/power/pm.h>
+#include <nuttx/semaphore.h>
+#include <nuttx/efuse/efuse.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Type Definitions
+ ****************************************************************************/
+
+/* This structure describes the state of the upper half driver */
+
+struct efuse_upperhalf_s
+{
+  sem_t     exclsem;  /* Supports mutual exclusion */
+  FAR char *path;     /* Registration path */
+
+  /* The contained lower-half driver */
+
+  FAR struct efuse_lowerhalf_s *lower;
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int     efuse_open(FAR struct file *filep);
+static int     efuse_close(FAR struct file *filep);
+static ssize_t efuse_read(FAR struct file *filep, FAR char *buffer,
+                          size_t buflen);
+static ssize_t efuse_write(FAR struct file *filep, FAR const char *buffer,
+                           size_t buflen);
+static int     efuse_ioctl(FAR struct file *filep, int cmd,
+                 unsigned long arg);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct file_operations g_efuseops =
+{
+  efuse_open,  /* open */
+  efuse_close, /* close */
+  efuse_read,  /* read */
+  efuse_write, /* write */
+  NULL,        /* seek */
+  efuse_ioctl, /* ioctl */
+  NULL         /* poll */
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: efuse_open
+ *
+ * Description:
+ *   This function is called whenever the efuse timer device is opened.
+ *
+ ****************************************************************************/
+
+static int efuse_open(FAR struct file *filep)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: efuse_close
+ *
+ * Description:
+ *   This function is called when the efuse timer device is closed.
+ *
+ ****************************************************************************/
+
+static int efuse_close(FAR struct file *filep)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: efuse_read
+ *
+ * Description:
+ *   A dummy read method.  This is provided only to satisfy the VFS layer.
+ *
+ ****************************************************************************/
+
+static ssize_t efuse_read(FAR struct file *filep, FAR char *buffer,
+                         size_t buflen)
+{
+  /* Return zero -- usually meaning end-of-file */
+
+  return 0;
+}
+
+/****************************************************************************
+ * Name: efuse_write
+ *
+ * Description:
+ *   A dummy write method.  This is provided only to satisfy the VFS layer.
+ *
+ ****************************************************************************/
+
+static ssize_t efuse_write(FAR struct file *filep, FAR const char *buffer,
+                          size_t buflen)
+{
+  return 0;
+}
+
+/****************************************************************************
+ * Name: efuse_ioctl
+ *
+ * Description:
+ *   The standard ioctl method.  This is where ALL of the efuse timer
+ *   work is done.
+ *
+ ****************************************************************************/
+
+static int efuse_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
+{
+  FAR struct inode             *inode = filep->f_inode;
+  FAR struct efuse_upperhalf_s *upper;
+  FAR struct efuse_lowerhalf_s *lower;
+  int                           ret;
+
+  minfo("cmd: %d arg: %ld\n", cmd, arg);
+  upper = inode->i_private;
+  DEBUGASSERT(upper != NULL);
+  lower = upper->lower;
+  DEBUGASSERT(lower != NULL);
+
+  /* Get exclusive access to the device structures */
+
+  ret = nxsem_wait(&upper->exclsem);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  /* Handle built-in ioctl commands */
+
+  switch (cmd)
+    {
+    /* cmd:         EFUSEIOC_READ_FIELD_BIT
+     * Description: Read a single bit efuse
+     * Argument:    Return variable
+     */
+
+    case EFUSEIOC_READ_FIELD_BIT:
+      {
+        FAR struct efuse_par_id *param =
+                   (FAR struct efuse_par_id *)((uintptr_t)arg);
+
+        /* Read the efuse */
+
+        DEBUGASSERT(lower->ops->read_bit); /* Required */
+        ret = lower->ops->read_bit(lower,
+                                   (const efuse_desc_t **) param->field,
+                                   param->data);
+      }
+      break;
+
+    /* cmd:         EFUSEIOC_WRITE_FIELD_BIT
+     * Description: Write a single bit efuse
+     * Argument:    - efuse ID name
+     *              - value to written (0 or 1)
+     */
+
+    case EFUSEIOC_WRITE_FIELD_BIT:
+      {
+        FAR struct efuse_par_id *param =
+                   (FAR struct efuse_par_id *)((uintptr_t)arg);
+
+        /* Write the efuse */
+
+        DEBUGASSERT(lower->ops->write_bit); /* Required */
+        ret = lower->ops->write_bit(lower,
+                                    (const efuse_desc_t **) param->field,
+                                    *param->data);
+      }
+      break;
+
+    /* cmd:         EFUSEIOC_READ_FIELD_BLOB
+     * Description: Read a blob of N bits from efuse.
+     * Argument:    - efuse_id
+     *              - offset
+     *              - nbits
+     */
+
+    case EFUSEIOC_READ_FIELD_BLOB:
+      {
+        FAR struct efuse_par_id *param;
+
+        /* Read a blob from EFUSEs */
+
+        if (lower->ops->read_blob) /* Optional */
+          {
+            param = (FAR struct efuse_par_id *)((uintptr_t)arg);
+            if (param)
+              {
+                ret = lower->ops->read_blob(lower,
+                                            (const efuse_desc_t **)
+                                              param->field,
+                                            param->data,
+                                            param->size);
+              }
+            else
+              {
+                ret = -EINVAL;
+              }
+          }
+        else
+          {
+            ret = -ENOSYS;
+          }
+      }
+      break;
+
+    /* cmd:         EFUSEIOC_WRITE_FIELD_BLOB
+     * Description: Write a blob of N bits to efuse.
+     * Argument:    - efuse_id
+     *              - blob_bits
+     *              - offset
+     *              - nbits
+     */
+
+    case EFUSEIOC_WRITE_FIELD_BLOB:
+      {
+        FAR struct efuse_par_id *param;
+
+        /* Write a blob to EFUSEs */
+
+        if (lower->ops->write_blob) /* Optional */
+          {
+            param = (FAR struct efuse_par_id *)((uintptr_t)arg);
+            if (param)
+              {
+                ret = lower->ops->write_blob(lower,
+                                             (const efuse_desc_t **)
+                                               param->field,
+                                             param->data,
+                                             param->size);
+              }
+            else
+              {
+                ret = -EINVAL;
+              }
+          }
+        else
+          {
+            ret = -ENOSYS;
+          }
+      }
+      break;
+
+    /* cmd:         EFUSEIOC_READ_REG
+     * Description: Read a 32-bit efuse register
+     * Argument:    - efuse_reg.
+     */
+
+    case EFUSEIOC_READ_REG:
+      {
+        FAR struct efuse_par *param;
+
+        DEBUGASSERT(param != NULL);
+
+        /* Read 32 efuses at once */
+
+        if (lower->ops->read_reg) /* Optional */
+          {
+            param = (FAR struct efuse_par *)((uintptr_t)arg);
+            if (param)
+              {
+                ret = lower->ops->read_reg(lower, param->block,
+                                           param->reg,
+                                           (uint32_t *) param->data);
+              }
+            else
+              {
+                ret = -EINVAL;
+              }
+          }
+        else
+          {
+            ret = -ENOSYS;
+          }
+      }
+      break;
+
+    /* cmd:         EFUSEIOC_WRITE_REG
+     * Description: Read a 32-bits efuses (register block).
+     * Argument:    - efuse_reg
+     *              - efuse_value
+     */
+
+    case EFUSEIOC_WRITE_REG:
+      {
+        FAR struct efuse_par *param;
+
+        /* Write 32 EFUSEs at once */
+
+        if (lower->ops->write_reg) /* Optional */
+          {
+            param = (FAR struct efuse_par *)((uintptr_t)arg);
+            if (param)
+              {
+                lower->ops->write_reg(lower, param->block,
+                                      param->reg, *param->data);
+              }
+            else
+              {
+                ret = -EINVAL;
+              }
+          }
+        else
+          {
+            ret = -ENOSYS;
+          }
+      }
+      break;
+
+    default:
+      {
+        minfo("Forwarding unrecognized cmd: %d arg: %ld\n", cmd, arg);
+
+        /* An ioctl commands that are not recognized by the "upper-half"

Review comment:
       ```suggestion
           /* Ioctls commands that are not recognized by the "upper-half"
   ```

##########
File path: drivers/efuse/efuse.c
##########
@@ -0,0 +1,514 @@
+/****************************************************************************
+ * drivers/efuse/efuse.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <string.h>
+#include <fcntl.h>
+#include <assert.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <nuttx/fs/fs.h>
+#include <nuttx/irq.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/power/pm.h>
+#include <nuttx/semaphore.h>
+#include <nuttx/efuse/efuse.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Type Definitions
+ ****************************************************************************/
+
+/* This structure describes the state of the upper half driver */
+
+struct efuse_upperhalf_s
+{
+  sem_t     exclsem;  /* Supports mutual exclusion */
+  FAR char *path;     /* Registration path */
+
+  /* The contained lower-half driver */
+
+  FAR struct efuse_lowerhalf_s *lower;
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int     efuse_open(FAR struct file *filep);
+static int     efuse_close(FAR struct file *filep);
+static ssize_t efuse_read(FAR struct file *filep, FAR char *buffer,
+                          size_t buflen);
+static ssize_t efuse_write(FAR struct file *filep, FAR const char *buffer,
+                           size_t buflen);
+static int     efuse_ioctl(FAR struct file *filep, int cmd,
+                 unsigned long arg);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct file_operations g_efuseops =
+{
+  efuse_open,  /* open */
+  efuse_close, /* close */
+  efuse_read,  /* read */
+  efuse_write, /* write */
+  NULL,        /* seek */
+  efuse_ioctl, /* ioctl */
+  NULL         /* poll */
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: efuse_open
+ *
+ * Description:
+ *   This function is called whenever the efuse timer device is opened.
+ *
+ ****************************************************************************/
+
+static int efuse_open(FAR struct file *filep)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: efuse_close
+ *
+ * Description:
+ *   This function is called when the efuse timer device is closed.
+ *
+ ****************************************************************************/
+
+static int efuse_close(FAR struct file *filep)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: efuse_read
+ *
+ * Description:
+ *   A dummy read method.  This is provided only to satisfy the VFS layer.
+ *
+ ****************************************************************************/
+
+static ssize_t efuse_read(FAR struct file *filep, FAR char *buffer,
+                         size_t buflen)
+{
+  /* Return zero -- usually meaning end-of-file */
+
+  return 0;
+}
+
+/****************************************************************************
+ * Name: efuse_write
+ *
+ * Description:
+ *   A dummy write method.  This is provided only to satisfy the VFS layer.
+ *
+ ****************************************************************************/
+
+static ssize_t efuse_write(FAR struct file *filep, FAR const char *buffer,
+                          size_t buflen)
+{
+  return 0;
+}
+
+/****************************************************************************
+ * Name: efuse_ioctl
+ *
+ * Description:
+ *   The standard ioctl method.  This is where ALL of the efuse timer
+ *   work is done.
+ *
+ ****************************************************************************/
+
+static int efuse_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
+{
+  FAR struct inode             *inode = filep->f_inode;
+  FAR struct efuse_upperhalf_s *upper;
+  FAR struct efuse_lowerhalf_s *lower;
+  int                           ret;
+
+  minfo("cmd: %d arg: %ld\n", cmd, arg);
+  upper = inode->i_private;
+  DEBUGASSERT(upper != NULL);
+  lower = upper->lower;
+  DEBUGASSERT(lower != NULL);
+
+  /* Get exclusive access to the device structures */
+
+  ret = nxsem_wait(&upper->exclsem);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  /* Handle built-in ioctl commands */
+
+  switch (cmd)
+    {
+    /* cmd:         EFUSEIOC_READ_FIELD_BIT
+     * Description: Read a single bit efuse
+     * Argument:    Return variable
+     */
+
+    case EFUSEIOC_READ_FIELD_BIT:
+      {
+        FAR struct efuse_par_id *param =
+                   (FAR struct efuse_par_id *)((uintptr_t)arg);
+
+        /* Read the efuse */
+
+        DEBUGASSERT(lower->ops->read_bit); /* Required */
+        ret = lower->ops->read_bit(lower,
+                                   (const efuse_desc_t **) param->field,
+                                   param->data);
+      }
+      break;
+
+    /* cmd:         EFUSEIOC_WRITE_FIELD_BIT
+     * Description: Write a single bit efuse
+     * Argument:    - efuse ID name
+     *              - value to written (0 or 1)
+     */
+
+    case EFUSEIOC_WRITE_FIELD_BIT:
+      {
+        FAR struct efuse_par_id *param =
+                   (FAR struct efuse_par_id *)((uintptr_t)arg);
+
+        /* Write the efuse */
+
+        DEBUGASSERT(lower->ops->write_bit); /* Required */
+        ret = lower->ops->write_bit(lower,
+                                    (const efuse_desc_t **) param->field,
+                                    *param->data);
+      }
+      break;
+
+    /* cmd:         EFUSEIOC_READ_FIELD_BLOB
+     * Description: Read a blob of N bits from efuse.
+     * Argument:    - efuse_id
+     *              - offset
+     *              - nbits
+     */
+
+    case EFUSEIOC_READ_FIELD_BLOB:
+      {
+        FAR struct efuse_par_id *param;
+
+        /* Read a blob from EFUSEs */
+
+        if (lower->ops->read_blob) /* Optional */
+          {
+            param = (FAR struct efuse_par_id *)((uintptr_t)arg);
+            if (param)
+              {
+                ret = lower->ops->read_blob(lower,
+                                            (const efuse_desc_t **)
+                                              param->field,
+                                            param->data,
+                                            param->size);
+              }
+            else
+              {
+                ret = -EINVAL;
+              }
+          }
+        else
+          {
+            ret = -ENOSYS;
+          }
+      }
+      break;
+
+    /* cmd:         EFUSEIOC_WRITE_FIELD_BLOB
+     * Description: Write a blob of N bits to efuse.
+     * Argument:    - efuse_id
+     *              - blob_bits
+     *              - offset
+     *              - nbits
+     */
+
+    case EFUSEIOC_WRITE_FIELD_BLOB:
+      {
+        FAR struct efuse_par_id *param;
+
+        /* Write a blob to EFUSEs */
+
+        if (lower->ops->write_blob) /* Optional */
+          {
+            param = (FAR struct efuse_par_id *)((uintptr_t)arg);
+            if (param)
+              {
+                ret = lower->ops->write_blob(lower,
+                                             (const efuse_desc_t **)
+                                               param->field,
+                                             param->data,
+                                             param->size);
+              }
+            else
+              {
+                ret = -EINVAL;
+              }
+          }
+        else
+          {
+            ret = -ENOSYS;
+          }
+      }
+      break;
+
+    /* cmd:         EFUSEIOC_READ_REG
+     * Description: Read a 32-bit efuse register
+     * Argument:    - efuse_reg.
+     */
+
+    case EFUSEIOC_READ_REG:
+      {
+        FAR struct efuse_par *param;
+
+        DEBUGASSERT(param != NULL);
+
+        /* Read 32 efuses at once */
+
+        if (lower->ops->read_reg) /* Optional */
+          {
+            param = (FAR struct efuse_par *)((uintptr_t)arg);
+            if (param)
+              {
+                ret = lower->ops->read_reg(lower, param->block,
+                                           param->reg,
+                                           (uint32_t *) param->data);
+              }
+            else
+              {
+                ret = -EINVAL;
+              }
+          }
+        else
+          {
+            ret = -ENOSYS;
+          }
+      }
+      break;
+
+    /* cmd:         EFUSEIOC_WRITE_REG
+     * Description: Read a 32-bits efuses (register block).
+     * Argument:    - efuse_reg
+     *              - efuse_value
+     */
+
+    case EFUSEIOC_WRITE_REG:
+      {
+        FAR struct efuse_par *param;
+
+        /* Write 32 EFUSEs at once */
+
+        if (lower->ops->write_reg) /* Optional */
+          {
+            param = (FAR struct efuse_par *)((uintptr_t)arg);
+            if (param)
+              {
+                lower->ops->write_reg(lower, param->block,
+                                      param->reg, *param->data);
+              }
+            else
+              {
+                ret = -EINVAL;
+              }
+          }
+        else
+          {
+            ret = -ENOSYS;
+          }
+      }
+      break;
+
+    default:
+      {
+        minfo("Forwarding unrecognized cmd: %d arg: %ld\n", cmd, arg);
+
+        /* An ioctl commands that are not recognized by the "upper-half"
+         * driver are forwarded to the lower half driver through this
+         * method.
+         */
+
+        if (lower->ops->ioctl) /* Optional */
+          {
+            ret = lower->ops->ioctl(lower, cmd, arg);
+          }
+        else
+          {
+            ret = -ENOTTY;
+          }
+      }
+      break;
+    }
+
+  nxsem_post(&upper->exclsem);
+  return ret;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: efuse_register
+ *
+ * Description:
+ *   This function binds an instance of a "lower half" efuse driver with
+ *   the "upper half" efuse device and registers that device so that can
+ *   be usedby application code.

Review comment:
       ```suggestion
    *   be used by application code.
   ```

##########
File path: drivers/efuse/efuse.c
##########
@@ -0,0 +1,514 @@
+/****************************************************************************
+ * drivers/efuse/efuse.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <string.h>
+#include <fcntl.h>
+#include <assert.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <nuttx/fs/fs.h>
+#include <nuttx/irq.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/power/pm.h>
+#include <nuttx/semaphore.h>
+#include <nuttx/efuse/efuse.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Type Definitions
+ ****************************************************************************/
+
+/* This structure describes the state of the upper half driver */
+
+struct efuse_upperhalf_s
+{
+  sem_t     exclsem;  /* Supports mutual exclusion */
+  FAR char *path;     /* Registration path */
+
+  /* The contained lower-half driver */
+
+  FAR struct efuse_lowerhalf_s *lower;
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int     efuse_open(FAR struct file *filep);
+static int     efuse_close(FAR struct file *filep);
+static ssize_t efuse_read(FAR struct file *filep, FAR char *buffer,
+                          size_t buflen);
+static ssize_t efuse_write(FAR struct file *filep, FAR const char *buffer,
+                           size_t buflen);
+static int     efuse_ioctl(FAR struct file *filep, int cmd,
+                 unsigned long arg);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct file_operations g_efuseops =
+{
+  efuse_open,  /* open */
+  efuse_close, /* close */
+  efuse_read,  /* read */
+  efuse_write, /* write */
+  NULL,        /* seek */
+  efuse_ioctl, /* ioctl */
+  NULL         /* poll */
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: efuse_open
+ *
+ * Description:
+ *   This function is called whenever the efuse timer device is opened.
+ *
+ ****************************************************************************/
+
+static int efuse_open(FAR struct file *filep)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: efuse_close
+ *
+ * Description:
+ *   This function is called when the efuse timer device is closed.
+ *
+ ****************************************************************************/
+
+static int efuse_close(FAR struct file *filep)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: efuse_read
+ *
+ * Description:
+ *   A dummy read method.  This is provided only to satisfy the VFS layer.
+ *
+ ****************************************************************************/
+
+static ssize_t efuse_read(FAR struct file *filep, FAR char *buffer,
+                         size_t buflen)
+{
+  /* Return zero -- usually meaning end-of-file */
+
+  return 0;
+}
+
+/****************************************************************************
+ * Name: efuse_write
+ *
+ * Description:
+ *   A dummy write method.  This is provided only to satisfy the VFS layer.
+ *
+ ****************************************************************************/
+
+static ssize_t efuse_write(FAR struct file *filep, FAR const char *buffer,
+                          size_t buflen)
+{
+  return 0;
+}
+
+/****************************************************************************
+ * Name: efuse_ioctl
+ *
+ * Description:
+ *   The standard ioctl method.  This is where ALL of the efuse timer
+ *   work is done.
+ *
+ ****************************************************************************/
+
+static int efuse_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
+{
+  FAR struct inode             *inode = filep->f_inode;
+  FAR struct efuse_upperhalf_s *upper;
+  FAR struct efuse_lowerhalf_s *lower;
+  int                           ret;
+
+  minfo("cmd: %d arg: %ld\n", cmd, arg);
+  upper = inode->i_private;
+  DEBUGASSERT(upper != NULL);
+  lower = upper->lower;
+  DEBUGASSERT(lower != NULL);
+
+  /* Get exclusive access to the device structures */
+
+  ret = nxsem_wait(&upper->exclsem);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  /* Handle built-in ioctl commands */
+
+  switch (cmd)
+    {
+    /* cmd:         EFUSEIOC_READ_FIELD_BIT
+     * Description: Read a single bit efuse
+     * Argument:    Return variable
+     */
+
+    case EFUSEIOC_READ_FIELD_BIT:
+      {
+        FAR struct efuse_par_id *param =
+                   (FAR struct efuse_par_id *)((uintptr_t)arg);
+
+        /* Read the efuse */
+
+        DEBUGASSERT(lower->ops->read_bit); /* Required */
+        ret = lower->ops->read_bit(lower,
+                                   (const efuse_desc_t **) param->field,
+                                   param->data);
+      }
+      break;
+
+    /* cmd:         EFUSEIOC_WRITE_FIELD_BIT
+     * Description: Write a single bit efuse
+     * Argument:    - efuse ID name
+     *              - value to written (0 or 1)
+     */
+
+    case EFUSEIOC_WRITE_FIELD_BIT:
+      {
+        FAR struct efuse_par_id *param =
+                   (FAR struct efuse_par_id *)((uintptr_t)arg);
+
+        /* Write the efuse */
+
+        DEBUGASSERT(lower->ops->write_bit); /* Required */
+        ret = lower->ops->write_bit(lower,
+                                    (const efuse_desc_t **) param->field,
+                                    *param->data);
+      }
+      break;
+
+    /* cmd:         EFUSEIOC_READ_FIELD_BLOB
+     * Description: Read a blob of N bits from efuse.
+     * Argument:    - efuse_id
+     *              - offset
+     *              - nbits
+     */
+
+    case EFUSEIOC_READ_FIELD_BLOB:
+      {
+        FAR struct efuse_par_id *param;
+
+        /* Read a blob from EFUSEs */
+
+        if (lower->ops->read_blob) /* Optional */
+          {
+            param = (FAR struct efuse_par_id *)((uintptr_t)arg);
+            if (param)
+              {
+                ret = lower->ops->read_blob(lower,
+                                            (const efuse_desc_t **)
+                                              param->field,
+                                            param->data,
+                                            param->size);
+              }
+            else
+              {
+                ret = -EINVAL;
+              }
+          }
+        else
+          {
+            ret = -ENOSYS;
+          }
+      }
+      break;
+
+    /* cmd:         EFUSEIOC_WRITE_FIELD_BLOB
+     * Description: Write a blob of N bits to efuse.
+     * Argument:    - efuse_id
+     *              - blob_bits
+     *              - offset
+     *              - nbits
+     */
+
+    case EFUSEIOC_WRITE_FIELD_BLOB:
+      {
+        FAR struct efuse_par_id *param;
+
+        /* Write a blob to EFUSEs */
+
+        if (lower->ops->write_blob) /* Optional */
+          {
+            param = (FAR struct efuse_par_id *)((uintptr_t)arg);
+            if (param)
+              {
+                ret = lower->ops->write_blob(lower,
+                                             (const efuse_desc_t **)
+                                               param->field,
+                                             param->data,
+                                             param->size);
+              }
+            else
+              {
+                ret = -EINVAL;
+              }
+          }
+        else
+          {
+            ret = -ENOSYS;
+          }
+      }
+      break;
+
+    /* cmd:         EFUSEIOC_READ_REG
+     * Description: Read a 32-bit efuse register
+     * Argument:    - efuse_reg.
+     */
+
+    case EFUSEIOC_READ_REG:
+      {
+        FAR struct efuse_par *param;
+
+        DEBUGASSERT(param != NULL);
+
+        /* Read 32 efuses at once */
+
+        if (lower->ops->read_reg) /* Optional */
+          {
+            param = (FAR struct efuse_par *)((uintptr_t)arg);
+            if (param)
+              {
+                ret = lower->ops->read_reg(lower, param->block,
+                                           param->reg,
+                                           (uint32_t *) param->data);
+              }
+            else
+              {
+                ret = -EINVAL;
+              }
+          }
+        else
+          {
+            ret = -ENOSYS;
+          }
+      }
+      break;
+
+    /* cmd:         EFUSEIOC_WRITE_REG
+     * Description: Read a 32-bits efuses (register block).
+     * Argument:    - efuse_reg
+     *              - efuse_value
+     */
+
+    case EFUSEIOC_WRITE_REG:
+      {
+        FAR struct efuse_par *param;
+
+        /* Write 32 EFUSEs at once */
+
+        if (lower->ops->write_reg) /* Optional */
+          {
+            param = (FAR struct efuse_par *)((uintptr_t)arg);
+            if (param)
+              {
+                lower->ops->write_reg(lower, param->block,
+                                      param->reg, *param->data);
+              }
+            else
+              {
+                ret = -EINVAL;
+              }
+          }
+        else
+          {
+            ret = -ENOSYS;
+          }
+      }
+      break;
+
+    default:
+      {
+        minfo("Forwarding unrecognized cmd: %d arg: %ld\n", cmd, arg);
+
+        /* An ioctl commands that are not recognized by the "upper-half"
+         * driver are forwarded to the lower half driver through this
+         * method.
+         */
+
+        if (lower->ops->ioctl) /* Optional */
+          {
+            ret = lower->ops->ioctl(lower, cmd, arg);
+          }
+        else
+          {
+            ret = -ENOTTY;
+          }
+      }
+      break;
+    }
+
+  nxsem_post(&upper->exclsem);
+  return ret;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: efuse_register
+ *
+ * Description:
+ *   This function binds an instance of a "lower half" efuse driver with
+ *   the "upper half" efuse device and registers that device so that can
+ *   be usedby application code.
+ *
+ * Input Parameters:
+ *   dev path - The full path to the driver to be registers in the NuttX

Review comment:
       ```suggestion
    *   dev path - The full path to the driver to be registered in the NuttX
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a change in pull request #2628: Add generic efuse driver for NuttX

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on a change in pull request #2628:
URL: https://github.com/apache/incubator-nuttx/pull/2628#discussion_r557822826



##########
File path: include/nuttx/efuse/efuse.h
##########
@@ -0,0 +1,155 @@
+/****************************************************************************
+ * include/nuttx/efuse/efuse.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_EFUSE_EFUSE_H
+#define __INCLUDE_NUTTX_EFUSE_EFUSE_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs/ioctl.h>
+
+#include <signal.h>
+#include <stdint.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Command:     EFUSEIOC_READ_FIELD
+ * Description: Read a blob of bits from an efuse field.
+ * Arguments:   A structure containing the field[], a dst pointer, and size
+ *              of bits to be read from efuses.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD      _EFUSEIOC(0x0001)
+
+/* Command:     EFUSEIOC_WRITE_FIELD
+ * Description: Write a blob of bits to an efuse's field
+ * Arguments:   A structure containing the field[], the src memory and the
+ *              amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD     _EFUSEIOC(0x0002)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* Structure eFuse field */
+
+struct efuse_desc_s
+{
+  uint16_t   bit_offset; /* Bit offset related to beginning of efuse */
+  uint16_t   bit_count;  /* Length of bit field */
+};
+
+/* Type definition for an eFuse field */
+
+typedef struct efuse_desc_s efuse_desc_t;
+
+/* Structs with the parameters passed to the IOCTLs */
+
+struct efuse_param
+{
+  FAR const efuse_desc_t **field;
+  size_t  size;
+  FAR uint8_t *data;
+};
+
+/* This structure provides the "lower-half" driver operations available to
+ * the "upper-half" driver.
+ */
+
+struct efuse_lowerhalf_s;
+struct efuse_ops_s
+{
+  /* Required methods *******************************************************/
+
+  /* Read an EFUSE bit */
+
+  CODE int (*read_field)(FAR struct efuse_lowerhalf_s *lower,
+                         FAR const efuse_desc_t *field[],
+                         FAR uint8_t *data, size_t bit_size);
+
+  /* Write an EFUSE bit */
+
+  CODE int (*write_field)(FAR struct efuse_lowerhalf_s *lower,
+                          FAR const efuse_desc_t *field[],
+                          FAR const uint8_t *data, size_t bit_size);
+
+  /* Any ioctl commands that are not recognized by the "upper-half" driver
+   * are forwarded to the lower half driver through this method.
+   */
+
+  CODE int (*ioctl)(FAR struct efuse_lowerhalf_s *lower, int cmd,
+                    unsigned long arg);
+};
+
+/* This structure provides the publicly visible representation of the
+ * "lower-half" driver state structure.  "lower half" drivers will have an
+ * internal structure definition that will be cast-compatible with this
+ * structure definitions.
+ */
+
+struct efuse_lowerhalf_s
+{
+  /* Publicly visible portion of the "lower-half" driver state structure. */
+
+  FAR const struct efuse_ops_s  *ops;  /* Lower half operations */
+
+  /* The remainder of the structure is used by the "lower-half" driver
+   * for whatever state storage that it may need.
+   */
+
+  void   *upper;                       /* Pointer to watchdog_upperhalf_s */
+};
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+

Review comment:
       Yes, I thought this case before, but if the lower half need callback into upper half in ISR process, the normal approach is pass the upper pointer in set_xxx_callback, e.g.:
   ```
     CODE int (*start)(FAR struct oneshot_lowerhalf_s *lower,
                       oneshot_callback_t callback, FAR void *arg,
                                                    ^^^^^^^^^^^^^
                       FAR const struct timespec *ts);
   ```
   Or like esp32_wdt_lowerhalf.c case, save it in the private esp32_wdt_lowerhalf_s not public watchdog_lowerhalf_s. The key point here is that upper should be part of the private lowerhalf state if the driver implemenation need that info.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] acassis commented on pull request #2628: Add generic efuse driver for NuttX

Posted by GitBox <gi...@apache.org>.
acassis commented on pull request #2628:
URL: https://github.com/apache/incubator-nuttx/pull/2628#issuecomment-760951349


   > @acassis why not merge into one patch? it doesn't make sense to left the intermediate result in the history.
   
   Ok, I was separating your and Sara commits, but I will squash them all in the original PR


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] acassis commented on pull request #2628: Add generic efuse driver for NuttX

Posted by GitBox <gi...@apache.org>.
acassis commented on pull request #2628:
URL: https://github.com/apache/incubator-nuttx/pull/2628#issuecomment-758654165


   > @acassis I will take a look tonight.
   
   Thank you!


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] acassis commented on a change in pull request #2628: Add generic efuse driver for NuttX

Posted by GitBox <gi...@apache.org>.
acassis commented on a change in pull request #2628:
URL: https://github.com/apache/incubator-nuttx/pull/2628#discussion_r554444510



##########
File path: include/nuttx/efuse/efuse.h
##########
@@ -0,0 +1,294 @@
+/****************************************************************************
+ * include/nuttx/efuse/efuse.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_EFUSE_EFUSE_H
+#define __INCLUDE_NUTTX_EFUSE_EFUSE_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs/ioctl.h>
+
+#include <signal.h>
+#include <stdint.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Command:     EFUSEIOC_READ_FIELD_BLOB
+ * Description: Read a blob of bits from an efuse field.
+ * Arguments:   A structure containing the field[], a dst pointer, and size
+ *              of bits to be read from efuses.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD_BLOB      _EFUSEIOC(0x0001)
+
+/* Command:     EFUSEIOC_READ_FIELD_BIT
+ * Description: Read of state of an efuse bit.
+ * Arguments:   A structure containing the field to be read.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD_BIT       _EFUSEIOC(0x0002)
+
+/* Command:     EFUSEIOC_WRITE_FIELD_BLOB
+ * Description: Write a blob of bits to an efuse's field
+ * Arguments:   A structure containing the field[], the src memory and the
+ *              amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD_BLOB     _EFUSEIOC(0x0003)
+
+/* Command:     EFUSEIOC_WRITE_FIELD_BIT
+ * Description: Write a bit to an efuse (burn it).
+ * Arguments:   A structure containing bit field.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD_BIT      _EFUSEIOC(0x0004)
+
+/* Command:     EFUSEIOC_GET_FIELD_SIZE
+ * Description: Get the length of the field in bits.
+ * Arguments:   A structure containing the fields.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_GET_FIELD_SIZE       _EFUSEIOC(0x0005)
+
+/* Command:     EFUSEIOC_READ_REG
+ * Description: Read an efuse register.
+ * Arguments:   A structure containing the block number and the register to
+ *              be read.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_REG             _EFUSEIOC(0x0006)
+
+/* Command:     EFUSEIOC_WRITE_REG
+ * Description: Write an efuse register.
+ * Arguments:   A structure containing the block number, the register to
+ *              write and value to be written.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_REG            _EFUSEIOC(0x0007)
+
+/* Command:     EFUSEIOC_READ_BLOCK
+ * Description: Read a key from efuse's block.
+ * Arguments:   A structure containing the block number, the dst_key pointer,
+ *              the offset in bits and the amount of bits to read.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_BLOCK           _EFUSEIOC(0x0008)
+
+/* Command:     EFUSEIOC_WRITE_BLOCK
+ * Description: Write a key to efuse's block.
+ * Arguments:   A structure containing the block number, the src_key pointer,
+ *              the offset in bits and the amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_BLOCK          _EFUSEIOC(0x0009)
+
+/* Command:     EFUSEIOC_BATCH_WRITE_BEGIN
+ * Description: Start a batch operation, the efuse bits will be burned after
+ *              a batch write commit operation.
+ * Arguments:   None
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_BATCH_WRITE_BEGIN    _EFUSEIOC(0x000a)
+
+/* Command:     EFUSEIOC_BATCH_WRITE_CANCEL
+ * Description: Cancel a started batch write operation in progress.
+ * Arguments:   None
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_BATCH_WRITE_CANCEL   _EFUSEIOC(0x000b)
+
+/* Command:     EFUSEIOC_BATCH_WRITE_COMMIT
+ * Description: Commit a batch operation that was in progress.
+ * Arguments:   None
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_BATCH_WRITE_COMMIT   _EFUSEIOC(0x000c)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* Structure eFuse field */
+
+struct efuse_desc_s
+{
+  uint16_t   efuse_block;    /* Block of eFuse */
+  uint16_t   bit_start;      /* Start bit [0..65535] */
+  uint16_t   bit_count;      /* Length of bit field [1..-] */
+};
+
+/* Type definition for an eFuse field */
+
+typedef struct efuse_desc_s efuse_desc_t;
+
+/* Structure range address by blocks */
+
+typedef struct
+{
+  uint32_t start;
+  uint32_t end;
+} efuse_range_addr_t;
+
+/* Structs with the parameters passed to the IOCTLs */
+
+struct efuse_par
+{
+  uint16_t block;
+  uint16_t reg;
+  size_t   bit_offset;
+  size_t   bit_size;
+  uint8_t *data;
+};
+
+struct efuse_par_id
+{
+  efuse_desc_t **field;
+  size_t  size;
+  uint8_t *data;
+};
+
+/* This structure provides the "lower-half" driver operations available to
+ * the "upper-half" driver.
+ */
+
+struct efuse_lowerhalf_s;
+struct efuse_ops_s
+{
+  /* Required methods *******************************************************/
+
+  /* Read an EFUSE bit */
+
+  CODE int (*read_bit)(FAR struct efuse_lowerhalf_s *lower,
+                       const efuse_desc_t *field[],

Review comment:
       @xiaoxiang781216 I decided to keep the original array of efuse_desct_t, it brings more flexibility for fields definition. For example, we can define the MAC Addresses separating for bytes to keep a single stream:
   
   ```
   static const efuse_desc_t MAC_FACTORY[] =
   {
     {
       72, 8    /* Factory MAC addr [0], */
     },
     {
       64, 8    /* Factory MAC addr [1], */
     },
     {
       56, 8    /* Factory MAC addr [2], */
     },
     {
       48, 8    /* Factory MAC addr [3], */
     },
     {
       40, 8    /* Factory MAC addr [4], */
     },
     {
       32, 8    /* Factory MAC addr [5], */
     },
   };
   
   
   const efuse_desc_t *ESP_EFUSE_MAC_FACTORY[] =
   {
     &MAC_FACTORY[0],      /* Factory MAC addr [0] */
     &MAC_FACTORY[1],      /* Factory MAC addr [1] */
     &MAC_FACTORY[2],      /* Factory MAC addr [2] */
     &MAC_FACTORY[3],      /* Factory MAC addr [3] */
     &MAC_FACTORY[4],      /* Factory MAC addr [4] */
     &MAC_FACTORY[5],      /* Factory MAC addr [5] */
     NULL
   };
   
   
   static const efuse_desc_t MAC_CUSTOM[] =
   {
     {
       776, 48    /* Custom MAC */
     },
   };
   
   const efuse_desc_t *ESP_EFUSE_MAC_CUSTOM[] =
   {
     &MAC_CUSTOM[0],       /* Custom MAC */
     NULL
   };
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] acassis commented on a change in pull request #2628: Add generic efuse driver for NuttX

Posted by GitBox <gi...@apache.org>.
acassis commented on a change in pull request #2628:
URL: https://github.com/apache/incubator-nuttx/pull/2628#discussion_r556727212



##########
File path: include/nuttx/efuse/efuse.h
##########
@@ -0,0 +1,155 @@
+/****************************************************************************
+ * include/nuttx/efuse/efuse.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_EFUSE_EFUSE_H
+#define __INCLUDE_NUTTX_EFUSE_EFUSE_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs/ioctl.h>
+
+#include <signal.h>
+#include <stdint.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Command:     EFUSEIOC_READ_FIELD
+ * Description: Read a blob of bits from an efuse field.
+ * Arguments:   A structure containing the field[], a dst pointer, and size
+ *              of bits to be read from efuses.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD      _EFUSEIOC(0x0001)
+
+/* Command:     EFUSEIOC_WRITE_FIELD
+ * Description: Write a blob of bits to an efuse's field
+ * Arguments:   A structure containing the field[], the src memory and the
+ *              amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD     _EFUSEIOC(0x0002)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* Structure eFuse field */
+
+struct efuse_desc_s
+{
+  uint16_t   bit_offset; /* Bit offset related to beginning of efuse */
+  uint16_t   bit_count;  /* Length of bit field */
+};
+
+/* Type definition for an eFuse field */
+
+typedef struct efuse_desc_s efuse_desc_t;
+
+/* Structs with the parameters passed to the IOCTLs */
+
+struct efuse_param
+{
+  FAR const efuse_desc_t **field;
+  size_t  size;
+  FAR uint8_t *data;

Review comment:
       The ESP_EFUSE_CONSOLE_DEBUG_DISABLE is defined this way:
   ```
   static const efuse_desc_t CONSOLE_DEBUG_DISABLE[] =
   {
     {
       194, 1   /* Disable ROM BASIC interpreter fallback.
                 * EFUSE_RD_CONSOLE_DEBUG_DISABLE
                 */
     },
   };
   
   const efuse_desc_t *ESP_EFUSE_CONSOLE_DEBUG_DISABLE[] =
   {
     &CONSOLE_DEBUG_DISABLE[0],    /* Disable ROM BASIC interpreter fallback.
                                    * EFUSE_RD_CONSOLE_DEBUG_DISABLE.
                                    */
     NULL
   };
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] saramonteiro commented on a change in pull request #2628: Add generic efuse driver for NuttX

Posted by GitBox <gi...@apache.org>.
saramonteiro commented on a change in pull request #2628:
URL: https://github.com/apache/incubator-nuttx/pull/2628#discussion_r554078414



##########
File path: drivers/efuse/efuse.c
##########
@@ -0,0 +1,514 @@
+/****************************************************************************
+ * drivers/efuse/efuse.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <string.h>
+#include <fcntl.h>
+#include <assert.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <nuttx/fs/fs.h>
+#include <nuttx/irq.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/power/pm.h>
+#include <nuttx/semaphore.h>
+#include <nuttx/efuse/efuse.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Type Definitions
+ ****************************************************************************/
+
+/* This structure describes the state of the upper half driver */
+
+struct efuse_upperhalf_s
+{
+  sem_t     exclsem;  /* Supports mutual exclusion */
+  FAR char *path;     /* Registration path */
+
+  /* The contained lower-half driver */
+
+  FAR struct efuse_lowerhalf_s *lower;
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int     efuse_open(FAR struct file *filep);
+static int     efuse_close(FAR struct file *filep);
+static ssize_t efuse_read(FAR struct file *filep, FAR char *buffer,
+                          size_t buflen);
+static ssize_t efuse_write(FAR struct file *filep, FAR const char *buffer,
+                           size_t buflen);
+static int     efuse_ioctl(FAR struct file *filep, int cmd,
+                 unsigned long arg);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct file_operations g_efuseops =
+{
+  efuse_open,  /* open */
+  efuse_close, /* close */
+  efuse_read,  /* read */
+  efuse_write, /* write */
+  NULL,        /* seek */
+  efuse_ioctl, /* ioctl */
+  NULL         /* poll */
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: efuse_open
+ *
+ * Description:
+ *   This function is called whenever the efuse timer device is opened.
+ *
+ ****************************************************************************/
+
+static int efuse_open(FAR struct file *filep)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: efuse_close
+ *
+ * Description:
+ *   This function is called when the efuse timer device is closed.
+ *
+ ****************************************************************************/
+
+static int efuse_close(FAR struct file *filep)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: efuse_read
+ *
+ * Description:
+ *   A dummy read method.  This is provided only to satisfy the VFS layer.
+ *
+ ****************************************************************************/
+
+static ssize_t efuse_read(FAR struct file *filep, FAR char *buffer,
+                         size_t buflen)
+{
+  /* Return zero -- usually meaning end-of-file */
+
+  return 0;
+}
+
+/****************************************************************************
+ * Name: efuse_write
+ *
+ * Description:
+ *   A dummy write method.  This is provided only to satisfy the VFS layer.
+ *
+ ****************************************************************************/
+
+static ssize_t efuse_write(FAR struct file *filep, FAR const char *buffer,
+                          size_t buflen)
+{
+  return 0;
+}
+
+/****************************************************************************
+ * Name: efuse_ioctl
+ *
+ * Description:
+ *   The standard ioctl method.  This is where ALL of the efuse timer
+ *   work is done.
+ *
+ ****************************************************************************/
+
+static int efuse_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
+{
+  FAR struct inode             *inode = filep->f_inode;
+  FAR struct efuse_upperhalf_s *upper;
+  FAR struct efuse_lowerhalf_s *lower;
+  int                           ret;
+
+  minfo("cmd: %d arg: %ld\n", cmd, arg);
+  upper = inode->i_private;
+  DEBUGASSERT(upper != NULL);
+  lower = upper->lower;
+  DEBUGASSERT(lower != NULL);
+
+  /* Get exclusive access to the device structures */
+
+  ret = nxsem_wait(&upper->exclsem);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  /* Handle built-in ioctl commands */
+
+  switch (cmd)
+    {
+    /* cmd:         EFUSEIOC_READ_FIELD_BIT
+     * Description: Read a single bit efuse
+     * Argument:    Return variable
+     */
+
+    case EFUSEIOC_READ_FIELD_BIT:
+      {
+        FAR struct efuse_par_id *param =
+                   (FAR struct efuse_par_id *)((uintptr_t)arg);
+
+        /* Read the efuse */
+
+        DEBUGASSERT(lower->ops->read_bit); /* Required */
+        ret = lower->ops->read_bit(lower,
+                                   (const efuse_desc_t **) param->field,
+                                   param->data);
+      }
+      break;
+
+    /* cmd:         EFUSEIOC_WRITE_FIELD_BIT
+     * Description: Write a single bit efuse
+     * Argument:    - efuse ID name
+     *              - value to written (0 or 1)
+     */
+
+    case EFUSEIOC_WRITE_FIELD_BIT:
+      {
+        FAR struct efuse_par_id *param =
+                   (FAR struct efuse_par_id *)((uintptr_t)arg);
+
+        /* Write the efuse */
+
+        DEBUGASSERT(lower->ops->write_bit); /* Required */
+        ret = lower->ops->write_bit(lower,
+                                    (const efuse_desc_t **) param->field,
+                                    *param->data);
+      }
+      break;
+
+    /* cmd:         EFUSEIOC_READ_FIELD_BLOB
+     * Description: Read a blob of N bits from efuse.
+     * Argument:    - efuse_id
+     *              - offset
+     *              - nbits
+     */
+
+    case EFUSEIOC_READ_FIELD_BLOB:
+      {
+        FAR struct efuse_par_id *param;
+
+        /* Read a blob from EFUSEs */
+
+        if (lower->ops->read_blob) /* Optional */
+          {
+            param = (FAR struct efuse_par_id *)((uintptr_t)arg);
+            if (param)
+              {
+                ret = lower->ops->read_blob(lower,
+                                            (const efuse_desc_t **)
+                                              param->field,
+                                            param->data,
+                                            param->size);
+              }
+            else
+              {
+                ret = -EINVAL;
+              }
+          }
+        else
+          {
+            ret = -ENOSYS;
+          }
+      }
+      break;
+
+    /* cmd:         EFUSEIOC_WRITE_FIELD_BLOB
+     * Description: Write a blob of N bits to efuse.
+     * Argument:    - efuse_id
+     *              - blob_bits
+     *              - offset
+     *              - nbits
+     */
+
+    case EFUSEIOC_WRITE_FIELD_BLOB:
+      {
+        FAR struct efuse_par_id *param;
+
+        /* Write a blob to EFUSEs */
+
+        if (lower->ops->write_blob) /* Optional */
+          {
+            param = (FAR struct efuse_par_id *)((uintptr_t)arg);
+            if (param)
+              {
+                ret = lower->ops->write_blob(lower,
+                                             (const efuse_desc_t **)
+                                               param->field,
+                                             param->data,
+                                             param->size);
+              }
+            else
+              {
+                ret = -EINVAL;
+              }
+          }
+        else
+          {
+            ret = -ENOSYS;
+          }
+      }
+      break;
+
+    /* cmd:         EFUSEIOC_READ_REG
+     * Description: Read a 32-bit efuse register
+     * Argument:    - efuse_reg.
+     */
+
+    case EFUSEIOC_READ_REG:
+      {
+        FAR struct efuse_par *param;
+
+        DEBUGASSERT(param != NULL);
+
+        /* Read 32 efuses at once */
+
+        if (lower->ops->read_reg) /* Optional */
+          {
+            param = (FAR struct efuse_par *)((uintptr_t)arg);
+            if (param)
+              {
+                ret = lower->ops->read_reg(lower, param->block,
+                                           param->reg,
+                                           (uint32_t *) param->data);
+              }
+            else
+              {
+                ret = -EINVAL;
+              }
+          }
+        else
+          {
+            ret = -ENOSYS;
+          }
+      }
+      break;
+
+    /* cmd:         EFUSEIOC_WRITE_REG
+     * Description: Read a 32-bits efuses (register block).
+     * Argument:    - efuse_reg
+     *              - efuse_value
+     */
+
+    case EFUSEIOC_WRITE_REG:
+      {
+        FAR struct efuse_par *param;
+
+        /* Write 32 EFUSEs at once */
+
+        if (lower->ops->write_reg) /* Optional */
+          {
+            param = (FAR struct efuse_par *)((uintptr_t)arg);
+            if (param)
+              {
+                lower->ops->write_reg(lower, param->block,
+                                      param->reg, *param->data);
+              }
+            else
+              {
+                ret = -EINVAL;
+              }
+          }
+        else
+          {
+            ret = -ENOSYS;
+          }
+      }
+      break;
+
+    default:
+      {
+        minfo("Forwarding unrecognized cmd: %d arg: %ld\n", cmd, arg);

Review comment:
       ```suggestion
           minfo("Forwarding unrecognized cmd: %d arg: %lu\n", cmd, arg);
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] saramonteiro commented on a change in pull request #2628: Add generic efuse driver for NuttX

Posted by GitBox <gi...@apache.org>.
saramonteiro commented on a change in pull request #2628:
URL: https://github.com/apache/incubator-nuttx/pull/2628#discussion_r554078898



##########
File path: drivers/efuse/efuse.c
##########
@@ -0,0 +1,514 @@
+/****************************************************************************
+ * drivers/efuse/efuse.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <string.h>
+#include <fcntl.h>
+#include <assert.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <nuttx/fs/fs.h>
+#include <nuttx/irq.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/power/pm.h>
+#include <nuttx/semaphore.h>
+#include <nuttx/efuse/efuse.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Type Definitions
+ ****************************************************************************/
+
+/* This structure describes the state of the upper half driver */
+
+struct efuse_upperhalf_s
+{
+  sem_t     exclsem;  /* Supports mutual exclusion */
+  FAR char *path;     /* Registration path */
+
+  /* The contained lower-half driver */
+
+  FAR struct efuse_lowerhalf_s *lower;
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int     efuse_open(FAR struct file *filep);
+static int     efuse_close(FAR struct file *filep);
+static ssize_t efuse_read(FAR struct file *filep, FAR char *buffer,
+                          size_t buflen);
+static ssize_t efuse_write(FAR struct file *filep, FAR const char *buffer,
+                           size_t buflen);
+static int     efuse_ioctl(FAR struct file *filep, int cmd,
+                 unsigned long arg);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct file_operations g_efuseops =
+{
+  efuse_open,  /* open */
+  efuse_close, /* close */
+  efuse_read,  /* read */
+  efuse_write, /* write */
+  NULL,        /* seek */
+  efuse_ioctl, /* ioctl */
+  NULL         /* poll */
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: efuse_open
+ *
+ * Description:
+ *   This function is called whenever the efuse timer device is opened.
+ *
+ ****************************************************************************/
+
+static int efuse_open(FAR struct file *filep)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: efuse_close
+ *
+ * Description:
+ *   This function is called when the efuse timer device is closed.
+ *
+ ****************************************************************************/
+
+static int efuse_close(FAR struct file *filep)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: efuse_read
+ *
+ * Description:
+ *   A dummy read method.  This is provided only to satisfy the VFS layer.
+ *
+ ****************************************************************************/
+
+static ssize_t efuse_read(FAR struct file *filep, FAR char *buffer,
+                         size_t buflen)
+{
+  /* Return zero -- usually meaning end-of-file */
+
+  return 0;
+}
+
+/****************************************************************************
+ * Name: efuse_write
+ *
+ * Description:
+ *   A dummy write method.  This is provided only to satisfy the VFS layer.
+ *
+ ****************************************************************************/
+
+static ssize_t efuse_write(FAR struct file *filep, FAR const char *buffer,
+                          size_t buflen)
+{
+  return 0;
+}
+
+/****************************************************************************
+ * Name: efuse_ioctl
+ *
+ * Description:
+ *   The standard ioctl method.  This is where ALL of the efuse timer
+ *   work is done.
+ *
+ ****************************************************************************/
+
+static int efuse_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
+{
+  FAR struct inode             *inode = filep->f_inode;
+  FAR struct efuse_upperhalf_s *upper;
+  FAR struct efuse_lowerhalf_s *lower;
+  int                           ret;
+
+  minfo("cmd: %d arg: %ld\n", cmd, arg);
+  upper = inode->i_private;
+  DEBUGASSERT(upper != NULL);
+  lower = upper->lower;
+  DEBUGASSERT(lower != NULL);
+
+  /* Get exclusive access to the device structures */
+
+  ret = nxsem_wait(&upper->exclsem);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  /* Handle built-in ioctl commands */
+
+  switch (cmd)
+    {
+    /* cmd:         EFUSEIOC_READ_FIELD_BIT
+     * Description: Read a single bit efuse
+     * Argument:    Return variable
+     */
+
+    case EFUSEIOC_READ_FIELD_BIT:
+      {
+        FAR struct efuse_par_id *param =
+                   (FAR struct efuse_par_id *)((uintptr_t)arg);
+
+        /* Read the efuse */
+
+        DEBUGASSERT(lower->ops->read_bit); /* Required */
+        ret = lower->ops->read_bit(lower,
+                                   (const efuse_desc_t **) param->field,
+                                   param->data);
+      }
+      break;
+
+    /* cmd:         EFUSEIOC_WRITE_FIELD_BIT
+     * Description: Write a single bit efuse
+     * Argument:    - efuse ID name
+     *              - value to written (0 or 1)
+     */
+
+    case EFUSEIOC_WRITE_FIELD_BIT:
+      {
+        FAR struct efuse_par_id *param =
+                   (FAR struct efuse_par_id *)((uintptr_t)arg);
+
+        /* Write the efuse */
+
+        DEBUGASSERT(lower->ops->write_bit); /* Required */
+        ret = lower->ops->write_bit(lower,
+                                    (const efuse_desc_t **) param->field,
+                                    *param->data);
+      }
+      break;
+
+    /* cmd:         EFUSEIOC_READ_FIELD_BLOB
+     * Description: Read a blob of N bits from efuse.
+     * Argument:    - efuse_id
+     *              - offset
+     *              - nbits
+     */
+
+    case EFUSEIOC_READ_FIELD_BLOB:
+      {
+        FAR struct efuse_par_id *param;
+
+        /* Read a blob from EFUSEs */
+
+        if (lower->ops->read_blob) /* Optional */
+          {
+            param = (FAR struct efuse_par_id *)((uintptr_t)arg);
+            if (param)
+              {
+                ret = lower->ops->read_blob(lower,
+                                            (const efuse_desc_t **)
+                                              param->field,
+                                            param->data,
+                                            param->size);
+              }
+            else
+              {
+                ret = -EINVAL;
+              }
+          }
+        else
+          {
+            ret = -ENOSYS;
+          }
+      }
+      break;
+
+    /* cmd:         EFUSEIOC_WRITE_FIELD_BLOB
+     * Description: Write a blob of N bits to efuse.
+     * Argument:    - efuse_id
+     *              - blob_bits
+     *              - offset
+     *              - nbits
+     */
+
+    case EFUSEIOC_WRITE_FIELD_BLOB:
+      {
+        FAR struct efuse_par_id *param;
+
+        /* Write a blob to EFUSEs */
+
+        if (lower->ops->write_blob) /* Optional */
+          {
+            param = (FAR struct efuse_par_id *)((uintptr_t)arg);
+            if (param)
+              {
+                ret = lower->ops->write_blob(lower,
+                                             (const efuse_desc_t **)
+                                               param->field,
+                                             param->data,
+                                             param->size);
+              }
+            else
+              {
+                ret = -EINVAL;
+              }
+          }
+        else
+          {
+            ret = -ENOSYS;
+          }
+      }
+      break;
+
+    /* cmd:         EFUSEIOC_READ_REG
+     * Description: Read a 32-bit efuse register
+     * Argument:    - efuse_reg.
+     */
+
+    case EFUSEIOC_READ_REG:
+      {
+        FAR struct efuse_par *param;
+
+        DEBUGASSERT(param != NULL);
+
+        /* Read 32 efuses at once */
+
+        if (lower->ops->read_reg) /* Optional */
+          {
+            param = (FAR struct efuse_par *)((uintptr_t)arg);
+            if (param)
+              {
+                ret = lower->ops->read_reg(lower, param->block,
+                                           param->reg,
+                                           (uint32_t *) param->data);
+              }
+            else
+              {
+                ret = -EINVAL;
+              }
+          }
+        else
+          {
+            ret = -ENOSYS;
+          }
+      }
+      break;
+
+    /* cmd:         EFUSEIOC_WRITE_REG
+     * Description: Read a 32-bits efuses (register block).
+     * Argument:    - efuse_reg
+     *              - efuse_value
+     */
+
+    case EFUSEIOC_WRITE_REG:
+      {
+        FAR struct efuse_par *param;
+
+        /* Write 32 EFUSEs at once */
+
+        if (lower->ops->write_reg) /* Optional */
+          {
+            param = (FAR struct efuse_par *)((uintptr_t)arg);
+            if (param)
+              {
+                lower->ops->write_reg(lower, param->block,
+                                      param->reg, *param->data);
+              }
+            else
+              {
+                ret = -EINVAL;
+              }
+          }
+        else
+          {
+            ret = -ENOSYS;
+          }
+      }
+      break;
+
+    default:
+      {
+        minfo("Forwarding unrecognized cmd: %d arg: %ld\n", cmd, arg);
+
+        /* An ioctl commands that are not recognized by the "upper-half"

Review comment:
       ```suggestion
           /* Ioctls commands that are not recognized by the "upper-half"
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] acassis commented on a change in pull request #2628: Add generic efuse driver for NuttX

Posted by GitBox <gi...@apache.org>.
acassis commented on a change in pull request #2628:
URL: https://github.com/apache/incubator-nuttx/pull/2628#discussion_r557430079



##########
File path: include/nuttx/efuse/efuse.h
##########
@@ -0,0 +1,155 @@
+/****************************************************************************
+ * include/nuttx/efuse/efuse.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_EFUSE_EFUSE_H
+#define __INCLUDE_NUTTX_EFUSE_EFUSE_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs/ioctl.h>
+
+#include <signal.h>
+#include <stdint.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Command:     EFUSEIOC_READ_FIELD
+ * Description: Read a blob of bits from an efuse field.
+ * Arguments:   A structure containing the field[], a dst pointer, and size
+ *              of bits to be read from efuses.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD      _EFUSEIOC(0x0001)
+
+/* Command:     EFUSEIOC_WRITE_FIELD
+ * Description: Write a blob of bits to an efuse's field
+ * Arguments:   A structure containing the field[], the src memory and the
+ *              amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD     _EFUSEIOC(0x0002)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* Structure eFuse field */
+
+struct efuse_desc_s
+{
+  uint16_t   bit_offset; /* Bit offset related to beginning of efuse */
+  uint16_t   bit_count;  /* Length of bit field */
+};
+
+/* Type definition for an eFuse field */
+
+typedef struct efuse_desc_s efuse_desc_t;
+
+/* Structs with the parameters passed to the IOCTLs */
+
+struct efuse_param
+{
+  FAR const efuse_desc_t **field;

Review comment:
       Right, I will replace 'efuse_dest_t **' with *field[], thank you!




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a change in pull request #2628: Add generic efuse driver for NuttX

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on a change in pull request #2628:
URL: https://github.com/apache/incubator-nuttx/pull/2628#discussion_r557421239



##########
File path: include/nuttx/efuse/efuse.h
##########
@@ -0,0 +1,155 @@
+/****************************************************************************
+ * include/nuttx/efuse/efuse.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_EFUSE_EFUSE_H
+#define __INCLUDE_NUTTX_EFUSE_EFUSE_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs/ioctl.h>
+
+#include <signal.h>
+#include <stdint.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Command:     EFUSEIOC_READ_FIELD
+ * Description: Read a blob of bits from an efuse field.
+ * Arguments:   A structure containing the field[], a dst pointer, and size
+ *              of bits to be read from efuses.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD      _EFUSEIOC(0x0001)
+
+/* Command:     EFUSEIOC_WRITE_FIELD
+ * Description: Write a blob of bits to an efuse's field
+ * Arguments:   A structure containing the field[], the src memory and the
+ *              amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD     _EFUSEIOC(0x0002)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* Structure eFuse field */
+
+struct efuse_desc_s
+{
+  uint16_t   bit_offset; /* Bit offset related to beginning of efuse */
+  uint16_t   bit_count;  /* Length of bit field */
+};
+
+/* Type definition for an eFuse field */
+
+typedef struct efuse_desc_s efuse_desc_t;
+
+/* Structs with the parameters passed to the IOCTLs */
+
+struct efuse_param
+{
+  FAR const efuse_desc_t **field;

Review comment:
       But it make the one field read/write more complex. How about use bit_count = 0 to indicate the terminate? BTW should we change the type to:
   ```
   FAR const efuse_desc_t *field[]
   ```
   so we can use the const arrray of efuse_desc_t.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] acassis commented on a change in pull request #2628: Add generic efuse driver for NuttX

Posted by GitBox <gi...@apache.org>.
acassis commented on a change in pull request #2628:
URL: https://github.com/apache/incubator-nuttx/pull/2628#discussion_r556720908



##########
File path: include/nuttx/efuse/efuse.h
##########
@@ -0,0 +1,155 @@
+/****************************************************************************
+ * include/nuttx/efuse/efuse.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_EFUSE_EFUSE_H
+#define __INCLUDE_NUTTX_EFUSE_EFUSE_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs/ioctl.h>
+
+#include <signal.h>
+#include <stdint.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Command:     EFUSEIOC_READ_FIELD
+ * Description: Read a blob of bits from an efuse field.
+ * Arguments:   A structure containing the field[], a dst pointer, and size
+ *              of bits to be read from efuses.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD      _EFUSEIOC(0x0001)
+
+/* Command:     EFUSEIOC_WRITE_FIELD
+ * Description: Write a blob of bits to an efuse's field
+ * Arguments:   A structure containing the field[], the src memory and the
+ *              amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD     _EFUSEIOC(0x0002)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* Structure eFuse field */
+
+struct efuse_desc_s
+{
+  uint16_t   bit_offset; /* Bit offset related to beginning of efuse */
+  uint16_t   bit_count;  /* Length of bit field */
+};
+
+/* Type definition for an eFuse field */
+
+typedef struct efuse_desc_s efuse_desc_t;
+
+/* Structs with the parameters passed to the IOCTLs */
+
+struct efuse_param
+{
+  FAR const efuse_desc_t **field;
+  size_t  size;
+  FAR uint8_t *data;

Review comment:
       ```
   struct efuse_param param;
   param.field = ESP_EFUSE_CONSOLE_DEBUG_DISABLE;
   param.size = 8; /* Number of bits for this efuse field */
   param.data = malloc(param.size / 8 + 1);
   
   ret = ioctl(fd, EFUSEIOC_READ_FIELD, &param);
     if (ret < 0)
       {
         printf("Failed to run ioctl EFUSEIOC_READ_FIELD, error = %d!\n",
                errno);
         close(fd);
         return -EINVAL;
       }
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a change in pull request #2628: Add generic efuse driver for NuttX

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on a change in pull request #2628:
URL: https://github.com/apache/incubator-nuttx/pull/2628#discussion_r555785276



##########
File path: include/nuttx/efuse/efuse.h
##########
@@ -0,0 +1,155 @@
+/****************************************************************************
+ * include/nuttx/efuse/efuse.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_EFUSE_EFUSE_H
+#define __INCLUDE_NUTTX_EFUSE_EFUSE_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs/ioctl.h>
+
+#include <signal.h>
+#include <stdint.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Command:     EFUSEIOC_READ_FIELD
+ * Description: Read a blob of bits from an efuse field.
+ * Arguments:   A structure containing the field[], a dst pointer, and size
+ *              of bits to be read from efuses.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD      _EFUSEIOC(0x0001)
+
+/* Command:     EFUSEIOC_WRITE_FIELD
+ * Description: Write a blob of bits to an efuse's field
+ * Arguments:   A structure containing the field[], the src memory and the
+ *              amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD     _EFUSEIOC(0x0002)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* Structure eFuse field */
+
+struct efuse_desc_s
+{
+  uint16_t   bit_offset;     /* Bit offset related to beginning of efuse */
+  uint16_t   bit_count;      /* Length of bit field */
+};
+
+/* Type definition for an eFuse field */
+
+typedef struct efuse_desc_s efuse_desc_t;
+
+/* Structs with the parameters passed to the IOCTLs */
+
+struct efuse_param
+{
+  efuse_desc_t **field;

Review comment:
       add FAR

##########
File path: include/nuttx/efuse/efuse.h
##########
@@ -0,0 +1,155 @@
+/****************************************************************************
+ * include/nuttx/efuse/efuse.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_EFUSE_EFUSE_H
+#define __INCLUDE_NUTTX_EFUSE_EFUSE_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs/ioctl.h>
+
+#include <signal.h>
+#include <stdint.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Command:     EFUSEIOC_READ_FIELD
+ * Description: Read a blob of bits from an efuse field.
+ * Arguments:   A structure containing the field[], a dst pointer, and size
+ *              of bits to be read from efuses.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD      _EFUSEIOC(0x0001)
+
+/* Command:     EFUSEIOC_WRITE_FIELD
+ * Description: Write a blob of bits to an efuse's field
+ * Arguments:   A structure containing the field[], the src memory and the
+ *              amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD     _EFUSEIOC(0x0002)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* Structure eFuse field */
+
+struct efuse_desc_s
+{
+  uint16_t   bit_offset;     /* Bit offset related to beginning of efuse */
+  uint16_t   bit_count;      /* Length of bit field */
+};
+
+/* Type definition for an eFuse field */
+
+typedef struct efuse_desc_s efuse_desc_t;
+
+/* Structs with the parameters passed to the IOCTLs */
+
+struct efuse_param
+{
+  efuse_desc_t **field;
+  size_t  size;
+  uint8_t *data;
+};
+
+/* This structure provides the "lower-half" driver operations available to
+ * the "upper-half" driver.
+ */
+
+struct efuse_lowerhalf_s;
+struct efuse_ops_s
+{
+  /* Required methods *******************************************************/
+
+  /* Read an EFUSE bit */
+
+  CODE int (*read_field)(FAR struct efuse_lowerhalf_s *lower,
+                         const efuse_desc_t *field[],
+                         uint8_t *data, size_t bit_size);
+
+  /* Write an EFUSE bit */
+
+  CODE int (*write_field)(FAR struct efuse_lowerhalf_s *lower,
+                          const efuse_desc_t *field[],
+                          const uint8_t *data, size_t bit_size);
+
+  /* Any ioctl commands that are not recognized by the "upper-half" driver
+   * are forwarded to the lower half driver through this method.
+   */
+
+  CODE int (*ioctl)(FAR struct efuse_lowerhalf_s *lower, int cmd,
+                    unsigned long arg);
+};
+
+/* This structure provides the publicly visible representation of the
+ * "lower-half" driver state structure.  "lower half" drivers will have an
+ * internal structure definition that will be cast-compatible with this
+ * structure definitions.
+ */
+
+struct efuse_lowerhalf_s
+{
+  /* Publicly visible portion of the "lower-half" driver state structure. */
+
+  FAR const struct efuse_ops_s  *ops;  /* Lower half operations */
+
+  /* The remainder of the structure is used by the "lower-half" driver
+   * for whatever state storage that it may need.
+   */
+
+  void   *upper;                       /* Pointer to watchdog_upperhalf_s */

Review comment:
       should we remove the extra space before upper and ops

##########
File path: drivers/efuse/efuse.c
##########
@@ -0,0 +1,377 @@
+/****************************************************************************
+ * drivers/efuse/efuse.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <string.h>
+#include <fcntl.h>
+#include <assert.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <nuttx/fs/fs.h>
+#include <nuttx/irq.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/power/pm.h>
+#include <nuttx/semaphore.h>
+#include <nuttx/efuse/efuse.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Type Definitions
+ ****************************************************************************/
+
+/* This structure describes the state of the upper half driver */
+
+struct efuse_upperhalf_s
+{
+  sem_t     exclsem;  /* Supports mutual exclusion */
+  FAR char *path;     /* Registration path */
+
+  /* The contained lower-half driver */
+
+  FAR struct efuse_lowerhalf_s *lower;
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int     efuse_open(FAR struct file *filep);
+static int     efuse_close(FAR struct file *filep);
+static ssize_t efuse_read(FAR struct file *filep, FAR char *buffer,
+                          size_t buflen);
+static ssize_t efuse_write(FAR struct file *filep, FAR const char *buffer,
+                           size_t buflen);
+static int     efuse_ioctl(FAR struct file *filep, int cmd,
+                 unsigned long arg);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct file_operations g_efuseops =
+{
+  efuse_open,  /* open */
+  efuse_close, /* close */
+  efuse_read,  /* read */
+  efuse_write, /* write */
+  NULL,        /* seek */
+  efuse_ioctl, /* ioctl */
+  NULL         /* poll */
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: efuse_open
+ *
+ * Description:
+ *   This function is called whenever the efuse timer device is opened.
+ *
+ ****************************************************************************/
+
+static int efuse_open(FAR struct file *filep)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: efuse_close
+ *
+ * Description:
+ *   This function is called when the efuse timer device is closed.
+ *
+ ****************************************************************************/
+
+static int efuse_close(FAR struct file *filep)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: efuse_read
+ *
+ * Description:
+ *   A dummy read method.  This is provided only to satisfy the VFS layer.
+ *
+ ****************************************************************************/
+
+static ssize_t efuse_read(FAR struct file *filep, FAR char *buffer,
+                         size_t buflen)
+{
+  /* Return zero -- usually meaning end-of-file */
+
+  return 0;
+}
+
+/****************************************************************************
+ * Name: efuse_write
+ *
+ * Description:
+ *   A dummy write method.  This is provided only to satisfy the VFS layer.
+ *
+ ****************************************************************************/
+
+static ssize_t efuse_write(FAR struct file *filep, FAR const char *buffer,
+                          size_t buflen)
+{
+  return 0;
+}
+
+/****************************************************************************
+ * Name: efuse_ioctl
+ *
+ * Description:
+ *   The standard ioctl method.  This is where ALL of the efuse timer
+ *   work is done.
+ *
+ ****************************************************************************/
+
+static int efuse_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
+{
+  FAR struct inode             *inode = filep->f_inode;
+  FAR struct efuse_upperhalf_s *upper;
+  FAR struct efuse_lowerhalf_s *lower;
+  int                           ret;
+
+  minfo("cmd: %d arg: %ld\n", cmd, arg);
+  upper = inode->i_private;
+  DEBUGASSERT(upper != NULL);
+  lower = upper->lower;
+  DEBUGASSERT(lower != NULL);
+
+  /* Get exclusive access to the device structures */
+
+  ret = nxsem_wait(&upper->exclsem);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  /* Handle built-in ioctl commands */
+
+  switch (cmd)
+    {
+    /* cmd:         EFUSEIOC_READ_FIELD_BIT
+     * Description: Read a single bit efuse
+     * Argument:    Return variable
+     */
+
+    case EFUSEIOC_READ_FIELD:
+      {
+        FAR struct efuse_param *param =
+                   (FAR struct efuse_param *)((uintptr_t)arg);
+
+        /* Read the efuse */
+
+        DEBUGASSERT(lower->ops->read_bit); /* Required */

Review comment:
       read_field

##########
File path: include/nuttx/efuse/efuse.h
##########
@@ -0,0 +1,155 @@
+/****************************************************************************
+ * include/nuttx/efuse/efuse.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_EFUSE_EFUSE_H
+#define __INCLUDE_NUTTX_EFUSE_EFUSE_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs/ioctl.h>
+
+#include <signal.h>
+#include <stdint.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Command:     EFUSEIOC_READ_FIELD
+ * Description: Read a blob of bits from an efuse field.
+ * Arguments:   A structure containing the field[], a dst pointer, and size
+ *              of bits to be read from efuses.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD      _EFUSEIOC(0x0001)
+
+/* Command:     EFUSEIOC_WRITE_FIELD
+ * Description: Write a blob of bits to an efuse's field
+ * Arguments:   A structure containing the field[], the src memory and the
+ *              amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD     _EFUSEIOC(0x0002)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* Structure eFuse field */
+
+struct efuse_desc_s
+{
+  uint16_t   bit_offset;     /* Bit offset related to beginning of efuse */
+  uint16_t   bit_count;      /* Length of bit field */
+};
+
+/* Type definition for an eFuse field */
+
+typedef struct efuse_desc_s efuse_desc_t;
+
+/* Structs with the parameters passed to the IOCTLs */
+
+struct efuse_param
+{
+  efuse_desc_t **field;
+  size_t  size;
+  uint8_t *data;
+};
+
+/* This structure provides the "lower-half" driver operations available to
+ * the "upper-half" driver.
+ */
+
+struct efuse_lowerhalf_s;
+struct efuse_ops_s
+{
+  /* Required methods *******************************************************/
+
+  /* Read an EFUSE bit */
+
+  CODE int (*read_field)(FAR struct efuse_lowerhalf_s *lower,
+                         const efuse_desc_t *field[],
+                         uint8_t *data, size_t bit_size);
+
+  /* Write an EFUSE bit */
+
+  CODE int (*write_field)(FAR struct efuse_lowerhalf_s *lower,
+                          const efuse_desc_t *field[],
+                          const uint8_t *data, size_t bit_size);
+
+  /* Any ioctl commands that are not recognized by the "upper-half" driver
+   * are forwarded to the lower half driver through this method.
+   */
+
+  CODE int (*ioctl)(FAR struct efuse_lowerhalf_s *lower, int cmd,
+                    unsigned long arg);
+};
+
+/* This structure provides the publicly visible representation of the
+ * "lower-half" driver state structure.  "lower half" drivers will have an
+ * internal structure definition that will be cast-compatible with this
+ * structure definitions.
+ */
+
+struct efuse_lowerhalf_s
+{
+  /* Publicly visible portion of the "lower-half" driver state structure. */
+
+  FAR const struct efuse_ops_s  *ops;  /* Lower half operations */
+
+  /* The remainder of the structure is used by the "lower-half" driver
+   * for whatever state storage that it may need.
+   */
+
+  void   *upper;                       /* Pointer to watchdog_upperhalf_s */

Review comment:
       FAR

##########
File path: include/nuttx/efuse/efuse.h
##########
@@ -0,0 +1,155 @@
+/****************************************************************************
+ * include/nuttx/efuse/efuse.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_EFUSE_EFUSE_H
+#define __INCLUDE_NUTTX_EFUSE_EFUSE_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs/ioctl.h>
+
+#include <signal.h>
+#include <stdint.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Command:     EFUSEIOC_READ_FIELD
+ * Description: Read a blob of bits from an efuse field.
+ * Arguments:   A structure containing the field[], a dst pointer, and size
+ *              of bits to be read from efuses.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD      _EFUSEIOC(0x0001)
+
+/* Command:     EFUSEIOC_WRITE_FIELD
+ * Description: Write a blob of bits to an efuse's field
+ * Arguments:   A structure containing the field[], the src memory and the
+ *              amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD     _EFUSEIOC(0x0002)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* Structure eFuse field */
+
+struct efuse_desc_s
+{
+  uint16_t   bit_offset;     /* Bit offset related to beginning of efuse */
+  uint16_t   bit_count;      /* Length of bit field */
+};
+
+/* Type definition for an eFuse field */
+
+typedef struct efuse_desc_s efuse_desc_t;
+
+/* Structs with the parameters passed to the IOCTLs */
+
+struct efuse_param
+{
+  efuse_desc_t **field;
+  size_t  size;
+  uint8_t *data;
+};
+
+/* This structure provides the "lower-half" driver operations available to
+ * the "upper-half" driver.
+ */
+
+struct efuse_lowerhalf_s;
+struct efuse_ops_s
+{
+  /* Required methods *******************************************************/
+
+  /* Read an EFUSE bit */
+
+  CODE int (*read_field)(FAR struct efuse_lowerhalf_s *lower,
+                         const efuse_desc_t *field[],

Review comment:
       add FAR

##########
File path: include/nuttx/efuse/efuse.h
##########
@@ -0,0 +1,155 @@
+/****************************************************************************
+ * include/nuttx/efuse/efuse.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_EFUSE_EFUSE_H
+#define __INCLUDE_NUTTX_EFUSE_EFUSE_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs/ioctl.h>
+
+#include <signal.h>
+#include <stdint.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Command:     EFUSEIOC_READ_FIELD
+ * Description: Read a blob of bits from an efuse field.
+ * Arguments:   A structure containing the field[], a dst pointer, and size
+ *              of bits to be read from efuses.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD      _EFUSEIOC(0x0001)
+
+/* Command:     EFUSEIOC_WRITE_FIELD
+ * Description: Write a blob of bits to an efuse's field
+ * Arguments:   A structure containing the field[], the src memory and the
+ *              amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD     _EFUSEIOC(0x0002)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* Structure eFuse field */
+
+struct efuse_desc_s
+{
+  uint16_t   bit_offset;     /* Bit offset related to beginning of efuse */
+  uint16_t   bit_count;      /* Length of bit field */
+};
+
+/* Type definition for an eFuse field */
+
+typedef struct efuse_desc_s efuse_desc_t;
+
+/* Structs with the parameters passed to the IOCTLs */
+
+struct efuse_param
+{
+  efuse_desc_t **field;
+  size_t  size;
+  uint8_t *data;
+};
+
+/* This structure provides the "lower-half" driver operations available to
+ * the "upper-half" driver.
+ */
+
+struct efuse_lowerhalf_s;
+struct efuse_ops_s
+{
+  /* Required methods *******************************************************/
+
+  /* Read an EFUSE bit */
+
+  CODE int (*read_field)(FAR struct efuse_lowerhalf_s *lower,
+                         const efuse_desc_t *field[],
+                         uint8_t *data, size_t bit_size);
+
+  /* Write an EFUSE bit */
+
+  CODE int (*write_field)(FAR struct efuse_lowerhalf_s *lower,
+                          const efuse_desc_t *field[],

Review comment:
       how do we know the end of array?

##########
File path: drivers/efuse/efuse.c
##########
@@ -0,0 +1,377 @@
+/****************************************************************************
+ * drivers/efuse/efuse.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <string.h>
+#include <fcntl.h>
+#include <assert.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <nuttx/fs/fs.h>
+#include <nuttx/irq.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/power/pm.h>
+#include <nuttx/semaphore.h>
+#include <nuttx/efuse/efuse.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Type Definitions
+ ****************************************************************************/
+
+/* This structure describes the state of the upper half driver */
+
+struct efuse_upperhalf_s
+{
+  sem_t     exclsem;  /* Supports mutual exclusion */
+  FAR char *path;     /* Registration path */
+
+  /* The contained lower-half driver */
+
+  FAR struct efuse_lowerhalf_s *lower;
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int     efuse_open(FAR struct file *filep);
+static int     efuse_close(FAR struct file *filep);
+static ssize_t efuse_read(FAR struct file *filep, FAR char *buffer,
+                          size_t buflen);
+static ssize_t efuse_write(FAR struct file *filep, FAR const char *buffer,
+                           size_t buflen);
+static int     efuse_ioctl(FAR struct file *filep, int cmd,
+                 unsigned long arg);

Review comment:
       algin with (

##########
File path: include/nuttx/efuse/efuse.h
##########
@@ -0,0 +1,155 @@
+/****************************************************************************
+ * include/nuttx/efuse/efuse.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_EFUSE_EFUSE_H
+#define __INCLUDE_NUTTX_EFUSE_EFUSE_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs/ioctl.h>
+
+#include <signal.h>
+#include <stdint.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Command:     EFUSEIOC_READ_FIELD
+ * Description: Read a blob of bits from an efuse field.
+ * Arguments:   A structure containing the field[], a dst pointer, and size
+ *              of bits to be read from efuses.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD      _EFUSEIOC(0x0001)
+
+/* Command:     EFUSEIOC_WRITE_FIELD
+ * Description: Write a blob of bits to an efuse's field
+ * Arguments:   A structure containing the field[], the src memory and the
+ *              amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD     _EFUSEIOC(0x0002)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* Structure eFuse field */
+
+struct efuse_desc_s
+{
+  uint16_t   bit_offset;     /* Bit offset related to beginning of efuse */
+  uint16_t   bit_count;      /* Length of bit field */
+};
+
+/* Type definition for an eFuse field */
+
+typedef struct efuse_desc_s efuse_desc_t;
+
+/* Structs with the parameters passed to the IOCTLs */
+
+struct efuse_param
+{
+  efuse_desc_t **field;
+  size_t  size;
+  uint8_t *data;
+};
+
+/* This structure provides the "lower-half" driver operations available to
+ * the "upper-half" driver.
+ */
+
+struct efuse_lowerhalf_s;
+struct efuse_ops_s
+{
+  /* Required methods *******************************************************/
+
+  /* Read an EFUSE bit */
+
+  CODE int (*read_field)(FAR struct efuse_lowerhalf_s *lower,
+                         const efuse_desc_t *field[],
+                         uint8_t *data, size_t bit_size);

Review comment:
       add FAR

##########
File path: drivers/efuse/efuse.c
##########
@@ -0,0 +1,377 @@
+/****************************************************************************
+ * drivers/efuse/efuse.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <string.h>
+#include <fcntl.h>
+#include <assert.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <nuttx/fs/fs.h>
+#include <nuttx/irq.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/power/pm.h>
+#include <nuttx/semaphore.h>
+#include <nuttx/efuse/efuse.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Type Definitions
+ ****************************************************************************/
+
+/* This structure describes the state of the upper half driver */
+
+struct efuse_upperhalf_s
+{
+  sem_t     exclsem;  /* Supports mutual exclusion */
+  FAR char *path;     /* Registration path */
+
+  /* The contained lower-half driver */
+
+  FAR struct efuse_lowerhalf_s *lower;
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int     efuse_open(FAR struct file *filep);
+static int     efuse_close(FAR struct file *filep);
+static ssize_t efuse_read(FAR struct file *filep, FAR char *buffer,
+                          size_t buflen);
+static ssize_t efuse_write(FAR struct file *filep, FAR const char *buffer,
+                           size_t buflen);
+static int     efuse_ioctl(FAR struct file *filep, int cmd,
+                 unsigned long arg);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct file_operations g_efuseops =
+{
+  efuse_open,  /* open */
+  efuse_close, /* close */
+  efuse_read,  /* read */
+  efuse_write, /* write */
+  NULL,        /* seek */
+  efuse_ioctl, /* ioctl */
+  NULL         /* poll */
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: efuse_open
+ *
+ * Description:
+ *   This function is called whenever the efuse timer device is opened.
+ *
+ ****************************************************************************/
+
+static int efuse_open(FAR struct file *filep)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: efuse_close
+ *
+ * Description:
+ *   This function is called when the efuse timer device is closed.
+ *
+ ****************************************************************************/
+
+static int efuse_close(FAR struct file *filep)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: efuse_read
+ *
+ * Description:
+ *   A dummy read method.  This is provided only to satisfy the VFS layer.
+ *
+ ****************************************************************************/
+
+static ssize_t efuse_read(FAR struct file *filep, FAR char *buffer,
+                         size_t buflen)
+{
+  /* Return zero -- usually meaning end-of-file */
+
+  return 0;
+}
+
+/****************************************************************************
+ * Name: efuse_write
+ *
+ * Description:
+ *   A dummy write method.  This is provided only to satisfy the VFS layer.
+ *
+ ****************************************************************************/
+
+static ssize_t efuse_write(FAR struct file *filep, FAR const char *buffer,
+                          size_t buflen)
+{
+  return 0;
+}
+
+/****************************************************************************
+ * Name: efuse_ioctl
+ *
+ * Description:
+ *   The standard ioctl method.  This is where ALL of the efuse timer
+ *   work is done.
+ *
+ ****************************************************************************/
+
+static int efuse_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
+{
+  FAR struct inode             *inode = filep->f_inode;
+  FAR struct efuse_upperhalf_s *upper;
+  FAR struct efuse_lowerhalf_s *lower;
+  int                           ret;
+
+  minfo("cmd: %d arg: %ld\n", cmd, arg);
+  upper = inode->i_private;
+  DEBUGASSERT(upper != NULL);
+  lower = upper->lower;
+  DEBUGASSERT(lower != NULL);
+
+  /* Get exclusive access to the device structures */
+
+  ret = nxsem_wait(&upper->exclsem);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  /* Handle built-in ioctl commands */
+
+  switch (cmd)
+    {
+    /* cmd:         EFUSEIOC_READ_FIELD_BIT
+     * Description: Read a single bit efuse
+     * Argument:    Return variable
+     */
+
+    case EFUSEIOC_READ_FIELD:
+      {
+        FAR struct efuse_param *param =
+                   (FAR struct efuse_param *)((uintptr_t)arg);
+
+        /* Read the efuse */
+
+        DEBUGASSERT(lower->ops->read_bit); /* Required */
+        ret = lower->ops->read_field(lower,
+                                     (const efuse_desc_t **) param->field,
+                                     param->data,
+                                     param->size);
+      }
+      break;
+
+    /* cmd:         EFUSEIOC_WRITE_FIELD_BIT
+     * Description: Write a single bit efuse
+     * Argument:    - efuse ID name
+     *              - value to written (0 or 1)
+     */
+
+    case EFUSEIOC_WRITE_FIELD:
+      {
+        FAR struct efuse_param *param =
+                   (FAR struct efuse_param *)((uintptr_t)arg);
+
+        /* Write the efuse */
+
+        DEBUGASSERT(lower->ops->write_bit); /* Required */
+        ret = lower->ops->write_field(lower,
+                                      (const efuse_desc_t **) param->field,
+                                      param->data,
+                                      param->size);
+      }
+      break;
+
+    default:
+      {
+        minfo("Forwarding unrecognized cmd: %d arg: %ld\n", cmd, arg);
+
+        /* An ioctl commands that are not recognized by the "upper-half"
+         * driver are forwarded to the lower half driver through this
+         * method.
+         */
+
+        if (lower->ops->ioctl) /* Optional */
+          {
+            ret = lower->ops->ioctl(lower, cmd, arg);
+          }
+        else
+          {
+            ret = -ENOTTY;
+          }
+      }
+      break;
+    }
+
+  nxsem_post(&upper->exclsem);
+  return ret;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: efuse_register
+ *
+ * Description:
+ *   This function binds an instance of a "lower half" efuse driver with
+ *   the "upper half" efuse device and registers that device so that can
+ *   be usedby application code.
+ *
+ * Input Parameters:
+ *   dev path - The full path to the driver to be registers in the NuttX
+ *     pseudo-filesystem.  The recommended convention is to name all
+ *     efuse drivers as "/dev/efuse".
+ *   lower - A pointer to an instance of lower half efuse driver.  This
+ *     instance is bound to the efuse driver and must persists as long as
+ *     the driver persists.
+ *
+ * Returned Value:
+ *   On success, a non-NULL handle is returned to the caller.  In the event
+ *   of any failure, a NULL value is returned.
+ *
+ ****************************************************************************/
+
+FAR void *efuse_register(FAR const char *path,
+                            FAR struct efuse_lowerhalf_s *lower)

Review comment:
       align

##########
File path: drivers/efuse/efuse.c
##########
@@ -0,0 +1,377 @@
+/****************************************************************************
+ * drivers/efuse/efuse.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <string.h>
+#include <fcntl.h>
+#include <assert.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <nuttx/fs/fs.h>
+#include <nuttx/irq.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/power/pm.h>
+#include <nuttx/semaphore.h>
+#include <nuttx/efuse/efuse.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Type Definitions
+ ****************************************************************************/
+
+/* This structure describes the state of the upper half driver */
+
+struct efuse_upperhalf_s
+{
+  sem_t     exclsem;  /* Supports mutual exclusion */
+  FAR char *path;     /* Registration path */
+
+  /* The contained lower-half driver */
+
+  FAR struct efuse_lowerhalf_s *lower;
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int     efuse_open(FAR struct file *filep);
+static int     efuse_close(FAR struct file *filep);
+static ssize_t efuse_read(FAR struct file *filep, FAR char *buffer,
+                          size_t buflen);
+static ssize_t efuse_write(FAR struct file *filep, FAR const char *buffer,
+                           size_t buflen);
+static int     efuse_ioctl(FAR struct file *filep, int cmd,
+                 unsigned long arg);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct file_operations g_efuseops =
+{
+  efuse_open,  /* open */
+  efuse_close, /* close */
+  efuse_read,  /* read */
+  efuse_write, /* write */
+  NULL,        /* seek */
+  efuse_ioctl, /* ioctl */
+  NULL         /* poll */
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: efuse_open
+ *
+ * Description:
+ *   This function is called whenever the efuse timer device is opened.
+ *
+ ****************************************************************************/
+
+static int efuse_open(FAR struct file *filep)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: efuse_close
+ *
+ * Description:
+ *   This function is called when the efuse timer device is closed.
+ *
+ ****************************************************************************/
+
+static int efuse_close(FAR struct file *filep)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: efuse_read
+ *
+ * Description:
+ *   A dummy read method.  This is provided only to satisfy the VFS layer.
+ *
+ ****************************************************************************/
+
+static ssize_t efuse_read(FAR struct file *filep, FAR char *buffer,
+                         size_t buflen)
+{
+  /* Return zero -- usually meaning end-of-file */
+
+  return 0;
+}
+
+/****************************************************************************
+ * Name: efuse_write
+ *
+ * Description:
+ *   A dummy write method.  This is provided only to satisfy the VFS layer.
+ *
+ ****************************************************************************/
+
+static ssize_t efuse_write(FAR struct file *filep, FAR const char *buffer,
+                          size_t buflen)
+{
+  return 0;
+}
+
+/****************************************************************************
+ * Name: efuse_ioctl
+ *
+ * Description:
+ *   The standard ioctl method.  This is where ALL of the efuse timer
+ *   work is done.
+ *
+ ****************************************************************************/
+
+static int efuse_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
+{
+  FAR struct inode             *inode = filep->f_inode;
+  FAR struct efuse_upperhalf_s *upper;
+  FAR struct efuse_lowerhalf_s *lower;
+  int                           ret;
+
+  minfo("cmd: %d arg: %ld\n", cmd, arg);
+  upper = inode->i_private;
+  DEBUGASSERT(upper != NULL);
+  lower = upper->lower;
+  DEBUGASSERT(lower != NULL);
+
+  /* Get exclusive access to the device structures */
+
+  ret = nxsem_wait(&upper->exclsem);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  /* Handle built-in ioctl commands */
+
+  switch (cmd)
+    {
+    /* cmd:         EFUSEIOC_READ_FIELD_BIT
+     * Description: Read a single bit efuse
+     * Argument:    Return variable
+     */
+
+    case EFUSEIOC_READ_FIELD:
+      {
+        FAR struct efuse_param *param =
+                   (FAR struct efuse_param *)((uintptr_t)arg);
+
+        /* Read the efuse */
+
+        DEBUGASSERT(lower->ops->read_bit); /* Required */
+        ret = lower->ops->read_field(lower,
+                                     (const efuse_desc_t **) param->field,
+                                     param->data,
+                                     param->size);
+      }
+      break;
+
+    /* cmd:         EFUSEIOC_WRITE_FIELD_BIT
+     * Description: Write a single bit efuse
+     * Argument:    - efuse ID name
+     *              - value to written (0 or 1)
+     */
+
+    case EFUSEIOC_WRITE_FIELD:
+      {
+        FAR struct efuse_param *param =
+                   (FAR struct efuse_param *)((uintptr_t)arg);
+
+        /* Write the efuse */
+
+        DEBUGASSERT(lower->ops->write_bit); /* Required */

Review comment:
       write_field

##########
File path: include/nuttx/efuse/efuse.h
##########
@@ -0,0 +1,155 @@
+/****************************************************************************
+ * include/nuttx/efuse/efuse.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_EFUSE_EFUSE_H
+#define __INCLUDE_NUTTX_EFUSE_EFUSE_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs/ioctl.h>
+
+#include <signal.h>
+#include <stdint.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Command:     EFUSEIOC_READ_FIELD
+ * Description: Read a blob of bits from an efuse field.
+ * Arguments:   A structure containing the field[], a dst pointer, and size
+ *              of bits to be read from efuses.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD      _EFUSEIOC(0x0001)
+
+/* Command:     EFUSEIOC_WRITE_FIELD
+ * Description: Write a blob of bits to an efuse's field
+ * Arguments:   A structure containing the field[], the src memory and the
+ *              amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD     _EFUSEIOC(0x0002)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* Structure eFuse field */
+
+struct efuse_desc_s
+{
+  uint16_t   bit_offset;     /* Bit offset related to beginning of efuse */
+  uint16_t   bit_count;      /* Length of bit field */
+};
+
+/* Type definition for an eFuse field */
+
+typedef struct efuse_desc_s efuse_desc_t;
+
+/* Structs with the parameters passed to the IOCTLs */
+
+struct efuse_param
+{
+  efuse_desc_t **field;
+  size_t  size;
+  uint8_t *data;

Review comment:
       add FAR, should we use void * here?

##########
File path: include/nuttx/efuse/efuse.h
##########
@@ -0,0 +1,155 @@
+/****************************************************************************
+ * include/nuttx/efuse/efuse.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_EFUSE_EFUSE_H
+#define __INCLUDE_NUTTX_EFUSE_EFUSE_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs/ioctl.h>
+
+#include <signal.h>
+#include <stdint.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Command:     EFUSEIOC_READ_FIELD
+ * Description: Read a blob of bits from an efuse field.
+ * Arguments:   A structure containing the field[], a dst pointer, and size
+ *              of bits to be read from efuses.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD      _EFUSEIOC(0x0001)
+
+/* Command:     EFUSEIOC_WRITE_FIELD
+ * Description: Write a blob of bits to an efuse's field
+ * Arguments:   A structure containing the field[], the src memory and the
+ *              amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD     _EFUSEIOC(0x0002)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* Structure eFuse field */
+
+struct efuse_desc_s
+{
+  uint16_t   bit_offset;     /* Bit offset related to beginning of efuse */
+  uint16_t   bit_count;      /* Length of bit field */
+};
+
+/* Type definition for an eFuse field */
+
+typedef struct efuse_desc_s efuse_desc_t;
+
+/* Structs with the parameters passed to the IOCTLs */
+
+struct efuse_param
+{
+  efuse_desc_t **field;
+  size_t  size;
+  uint8_t *data;
+};
+
+/* This structure provides the "lower-half" driver operations available to
+ * the "upper-half" driver.
+ */
+
+struct efuse_lowerhalf_s;
+struct efuse_ops_s
+{
+  /* Required methods *******************************************************/
+
+  /* Read an EFUSE bit */
+
+  CODE int (*read_field)(FAR struct efuse_lowerhalf_s *lower,
+                         const efuse_desc_t *field[],
+                         uint8_t *data, size_t bit_size);
+
+  /* Write an EFUSE bit */
+
+  CODE int (*write_field)(FAR struct efuse_lowerhalf_s *lower,
+                          const efuse_desc_t *field[],
+                          const uint8_t *data, size_t bit_size);

Review comment:
       add FAR

##########
File path: include/nuttx/efuse/efuse.h
##########
@@ -0,0 +1,155 @@
+/****************************************************************************
+ * include/nuttx/efuse/efuse.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_EFUSE_EFUSE_H
+#define __INCLUDE_NUTTX_EFUSE_EFUSE_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs/ioctl.h>
+
+#include <signal.h>
+#include <stdint.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Command:     EFUSEIOC_READ_FIELD
+ * Description: Read a blob of bits from an efuse field.
+ * Arguments:   A structure containing the field[], a dst pointer, and size
+ *              of bits to be read from efuses.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD      _EFUSEIOC(0x0001)
+
+/* Command:     EFUSEIOC_WRITE_FIELD
+ * Description: Write a blob of bits to an efuse's field
+ * Arguments:   A structure containing the field[], the src memory and the
+ *              amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD     _EFUSEIOC(0x0002)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* Structure eFuse field */
+
+struct efuse_desc_s
+{
+  uint16_t   bit_offset;     /* Bit offset related to beginning of efuse */
+  uint16_t   bit_count;      /* Length of bit field */

Review comment:
       should we remove the extra space

##########
File path: include/nuttx/efuse/efuse.h
##########
@@ -0,0 +1,155 @@
+/****************************************************************************
+ * include/nuttx/efuse/efuse.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_EFUSE_EFUSE_H
+#define __INCLUDE_NUTTX_EFUSE_EFUSE_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs/ioctl.h>
+
+#include <signal.h>
+#include <stdint.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Command:     EFUSEIOC_READ_FIELD
+ * Description: Read a blob of bits from an efuse field.
+ * Arguments:   A structure containing the field[], a dst pointer, and size
+ *              of bits to be read from efuses.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD      _EFUSEIOC(0x0001)
+
+/* Command:     EFUSEIOC_WRITE_FIELD
+ * Description: Write a blob of bits to an efuse's field
+ * Arguments:   A structure containing the field[], the src memory and the
+ *              amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD     _EFUSEIOC(0x0002)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* Structure eFuse field */
+
+struct efuse_desc_s
+{
+  uint16_t   bit_offset;     /* Bit offset related to beginning of efuse */
+  uint16_t   bit_count;      /* Length of bit field */
+};
+
+/* Type definition for an eFuse field */
+
+typedef struct efuse_desc_s efuse_desc_t;
+
+/* Structs with the parameters passed to the IOCTLs */
+
+struct efuse_param
+{
+  efuse_desc_t **field;

Review comment:
       add const

##########
File path: include/nuttx/efuse/efuse.h
##########
@@ -0,0 +1,155 @@
+/****************************************************************************
+ * include/nuttx/efuse/efuse.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_EFUSE_EFUSE_H
+#define __INCLUDE_NUTTX_EFUSE_EFUSE_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs/ioctl.h>
+
+#include <signal.h>
+#include <stdint.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Command:     EFUSEIOC_READ_FIELD
+ * Description: Read a blob of bits from an efuse field.
+ * Arguments:   A structure containing the field[], a dst pointer, and size
+ *              of bits to be read from efuses.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD      _EFUSEIOC(0x0001)
+
+/* Command:     EFUSEIOC_WRITE_FIELD
+ * Description: Write a blob of bits to an efuse's field
+ * Arguments:   A structure containing the field[], the src memory and the
+ *              amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD     _EFUSEIOC(0x0002)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* Structure eFuse field */
+
+struct efuse_desc_s
+{
+  uint16_t   bit_offset;     /* Bit offset related to beginning of efuse */
+  uint16_t   bit_count;      /* Length of bit field */
+};
+
+/* Type definition for an eFuse field */
+
+typedef struct efuse_desc_s efuse_desc_t;
+
+/* Structs with the parameters passed to the IOCTLs */
+
+struct efuse_param
+{
+  efuse_desc_t **field;
+  size_t  size;
+  uint8_t *data;
+};
+
+/* This structure provides the "lower-half" driver operations available to
+ * the "upper-half" driver.
+ */
+
+struct efuse_lowerhalf_s;
+struct efuse_ops_s
+{
+  /* Required methods *******************************************************/
+
+  /* Read an EFUSE bit */
+
+  CODE int (*read_field)(FAR struct efuse_lowerhalf_s *lower,
+                         const efuse_desc_t *field[],
+                         uint8_t *data, size_t bit_size);

Review comment:
       should we add some comment to describe how the relationship between field and data(I mean the layout)?

##########
File path: include/nuttx/efuse/efuse.h
##########
@@ -0,0 +1,155 @@
+/****************************************************************************
+ * include/nuttx/efuse/efuse.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_EFUSE_EFUSE_H
+#define __INCLUDE_NUTTX_EFUSE_EFUSE_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs/ioctl.h>
+
+#include <signal.h>
+#include <stdint.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Command:     EFUSEIOC_READ_FIELD
+ * Description: Read a blob of bits from an efuse field.
+ * Arguments:   A structure containing the field[], a dst pointer, and size
+ *              of bits to be read from efuses.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD      _EFUSEIOC(0x0001)
+
+/* Command:     EFUSEIOC_WRITE_FIELD
+ * Description: Write a blob of bits to an efuse's field
+ * Arguments:   A structure containing the field[], the src memory and the
+ *              amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD     _EFUSEIOC(0x0002)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* Structure eFuse field */
+
+struct efuse_desc_s
+{
+  uint16_t   bit_offset;     /* Bit offset related to beginning of efuse */
+  uint16_t   bit_count;      /* Length of bit field */
+};
+
+/* Type definition for an eFuse field */
+
+typedef struct efuse_desc_s efuse_desc_t;
+
+/* Structs with the parameters passed to the IOCTLs */
+
+struct efuse_param
+{
+  efuse_desc_t **field;
+  size_t  size;
+  uint8_t *data;
+};
+
+/* This structure provides the "lower-half" driver operations available to
+ * the "upper-half" driver.
+ */
+
+struct efuse_lowerhalf_s;
+struct efuse_ops_s
+{
+  /* Required methods *******************************************************/
+
+  /* Read an EFUSE bit */
+
+  CODE int (*read_field)(FAR struct efuse_lowerhalf_s *lower,
+                         const efuse_desc_t *field[],
+                         uint8_t *data, size_t bit_size);
+
+  /* Write an EFUSE bit */
+
+  CODE int (*write_field)(FAR struct efuse_lowerhalf_s *lower,
+                          const efuse_desc_t *field[],

Review comment:
       add FAR




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] acassis commented on a change in pull request #2628: Add generic efuse driver for NuttX

Posted by GitBox <gi...@apache.org>.
acassis commented on a change in pull request #2628:
URL: https://github.com/apache/incubator-nuttx/pull/2628#discussion_r557642414



##########
File path: include/nuttx/efuse/efuse.h
##########
@@ -0,0 +1,155 @@
+/****************************************************************************
+ * include/nuttx/efuse/efuse.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_EFUSE_EFUSE_H
+#define __INCLUDE_NUTTX_EFUSE_EFUSE_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs/ioctl.h>
+
+#include <signal.h>
+#include <stdint.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Command:     EFUSEIOC_READ_FIELD
+ * Description: Read a blob of bits from an efuse field.
+ * Arguments:   A structure containing the field[], a dst pointer, and size
+ *              of bits to be read from efuses.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD      _EFUSEIOC(0x0001)
+
+/* Command:     EFUSEIOC_WRITE_FIELD
+ * Description: Write a blob of bits to an efuse's field
+ * Arguments:   A structure containing the field[], the src memory and the
+ *              amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD     _EFUSEIOC(0x0002)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* Structure eFuse field */
+
+struct efuse_desc_s
+{
+  uint16_t   bit_offset; /* Bit offset related to beginning of efuse */
+  uint16_t   bit_count;  /* Length of bit field */
+};
+
+/* Type definition for an eFuse field */
+
+typedef struct efuse_desc_s efuse_desc_t;
+
+/* Structs with the parameters passed to the IOCTLs */
+
+struct efuse_param
+{
+  FAR const efuse_desc_t **field;
+  size_t  size;
+  FAR uint8_t *data;

Review comment:
       @xiaoxiang781216 I think now all main issues were addressed. I cannot convert **field to *field[] because it needs to be just a point to the ID, the user application will not allocate or create it, but just do i.e.:
   param.field = ESP_EFUSE_MAC_CUSTOM_CRC;
   Please let me know if everything is fine, if so, please merge it.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] acassis commented on a change in pull request #2628: Add generic efuse driver for NuttX

Posted by GitBox <gi...@apache.org>.
acassis commented on a change in pull request #2628:
URL: https://github.com/apache/incubator-nuttx/pull/2628#discussion_r554146750



##########
File path: drivers/efuse/efuse.c
##########
@@ -0,0 +1,514 @@
+/****************************************************************************
+ * drivers/efuse/efuse.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <string.h>
+#include <fcntl.h>
+#include <assert.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <nuttx/fs/fs.h>
+#include <nuttx/irq.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/power/pm.h>
+#include <nuttx/semaphore.h>
+#include <nuttx/efuse/efuse.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Type Definitions
+ ****************************************************************************/
+
+/* This structure describes the state of the upper half driver */
+
+struct efuse_upperhalf_s
+{
+  sem_t     exclsem;  /* Supports mutual exclusion */
+  FAR char *path;     /* Registration path */
+
+  /* The contained lower-half driver */
+
+  FAR struct efuse_lowerhalf_s *lower;
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int     efuse_open(FAR struct file *filep);
+static int     efuse_close(FAR struct file *filep);
+static ssize_t efuse_read(FAR struct file *filep, FAR char *buffer,
+                          size_t buflen);
+static ssize_t efuse_write(FAR struct file *filep, FAR const char *buffer,
+                           size_t buflen);
+static int     efuse_ioctl(FAR struct file *filep, int cmd,
+                 unsigned long arg);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct file_operations g_efuseops =
+{
+  efuse_open,  /* open */
+  efuse_close, /* close */
+  efuse_read,  /* read */
+  efuse_write, /* write */
+  NULL,        /* seek */
+  efuse_ioctl, /* ioctl */
+  NULL         /* poll */
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: efuse_open
+ *
+ * Description:
+ *   This function is called whenever the efuse timer device is opened.
+ *
+ ****************************************************************************/
+
+static int efuse_open(FAR struct file *filep)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: efuse_close
+ *
+ * Description:
+ *   This function is called when the efuse timer device is closed.
+ *
+ ****************************************************************************/
+
+static int efuse_close(FAR struct file *filep)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: efuse_read
+ *
+ * Description:
+ *   A dummy read method.  This is provided only to satisfy the VFS layer.
+ *
+ ****************************************************************************/
+
+static ssize_t efuse_read(FAR struct file *filep, FAR char *buffer,
+                         size_t buflen)
+{
+  /* Return zero -- usually meaning end-of-file */
+
+  return 0;
+}
+
+/****************************************************************************
+ * Name: efuse_write
+ *
+ * Description:
+ *   A dummy write method.  This is provided only to satisfy the VFS layer.
+ *
+ ****************************************************************************/
+
+static ssize_t efuse_write(FAR struct file *filep, FAR const char *buffer,
+                          size_t buflen)
+{
+  return 0;
+}
+
+/****************************************************************************
+ * Name: efuse_ioctl
+ *
+ * Description:
+ *   The standard ioctl method.  This is where ALL of the efuse timer
+ *   work is done.
+ *
+ ****************************************************************************/
+
+static int efuse_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
+{
+  FAR struct inode             *inode = filep->f_inode;
+  FAR struct efuse_upperhalf_s *upper;
+  FAR struct efuse_lowerhalf_s *lower;
+  int                           ret;
+
+  minfo("cmd: %d arg: %ld\n", cmd, arg);
+  upper = inode->i_private;
+  DEBUGASSERT(upper != NULL);
+  lower = upper->lower;
+  DEBUGASSERT(lower != NULL);
+
+  /* Get exclusive access to the device structures */
+
+  ret = nxsem_wait(&upper->exclsem);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  /* Handle built-in ioctl commands */
+
+  switch (cmd)
+    {
+    /* cmd:         EFUSEIOC_READ_FIELD_BIT
+     * Description: Read a single bit efuse
+     * Argument:    Return variable
+     */
+
+    case EFUSEIOC_READ_FIELD_BIT:
+      {
+        FAR struct efuse_par_id *param =
+                   (FAR struct efuse_par_id *)((uintptr_t)arg);
+
+        /* Read the efuse */
+
+        DEBUGASSERT(lower->ops->read_bit); /* Required */
+        ret = lower->ops->read_bit(lower,
+                                   (const efuse_desc_t **) param->field,
+                                   param->data);
+      }
+      break;
+
+    /* cmd:         EFUSEIOC_WRITE_FIELD_BIT
+     * Description: Write a single bit efuse
+     * Argument:    - efuse ID name
+     *              - value to written (0 or 1)
+     */
+
+    case EFUSEIOC_WRITE_FIELD_BIT:
+      {
+        FAR struct efuse_par_id *param =
+                   (FAR struct efuse_par_id *)((uintptr_t)arg);
+
+        /* Write the efuse */
+
+        DEBUGASSERT(lower->ops->write_bit); /* Required */
+        ret = lower->ops->write_bit(lower,
+                                    (const efuse_desc_t **) param->field,
+                                    *param->data);
+      }
+      break;
+
+    /* cmd:         EFUSEIOC_READ_FIELD_BLOB
+     * Description: Read a blob of N bits from efuse.
+     * Argument:    - efuse_id
+     *              - offset
+     *              - nbits
+     */
+
+    case EFUSEIOC_READ_FIELD_BLOB:
+      {
+        FAR struct efuse_par_id *param;
+
+        /* Read a blob from EFUSEs */
+
+        if (lower->ops->read_blob) /* Optional */
+          {
+            param = (FAR struct efuse_par_id *)((uintptr_t)arg);
+            if (param)
+              {
+                ret = lower->ops->read_blob(lower,
+                                            (const efuse_desc_t **)
+                                              param->field,
+                                            param->data,
+                                            param->size);
+              }
+            else
+              {
+                ret = -EINVAL;
+              }
+          }
+        else
+          {
+            ret = -ENOSYS;
+          }
+      }
+      break;
+
+    /* cmd:         EFUSEIOC_WRITE_FIELD_BLOB
+     * Description: Write a blob of N bits to efuse.
+     * Argument:    - efuse_id
+     *              - blob_bits
+     *              - offset
+     *              - nbits
+     */
+
+    case EFUSEIOC_WRITE_FIELD_BLOB:
+      {
+        FAR struct efuse_par_id *param;
+
+        /* Write a blob to EFUSEs */
+
+        if (lower->ops->write_blob) /* Optional */
+          {
+            param = (FAR struct efuse_par_id *)((uintptr_t)arg);
+            if (param)
+              {
+                ret = lower->ops->write_blob(lower,
+                                             (const efuse_desc_t **)
+                                               param->field,
+                                             param->data,
+                                             param->size);
+              }
+            else
+              {
+                ret = -EINVAL;
+              }
+          }
+        else
+          {
+            ret = -ENOSYS;
+          }
+      }
+      break;
+
+    /* cmd:         EFUSEIOC_READ_REG
+     * Description: Read a 32-bit efuse register
+     * Argument:    - efuse_reg.
+     */
+
+    case EFUSEIOC_READ_REG:
+      {
+        FAR struct efuse_par *param;
+
+        DEBUGASSERT(param != NULL);
+
+        /* Read 32 efuses at once */
+
+        if (lower->ops->read_reg) /* Optional */
+          {
+            param = (FAR struct efuse_par *)((uintptr_t)arg);
+            if (param)
+              {
+                ret = lower->ops->read_reg(lower, param->block,
+                                           param->reg,
+                                           (uint32_t *) param->data);
+              }
+            else
+              {
+                ret = -EINVAL;
+              }
+          }
+        else
+          {
+            ret = -ENOSYS;
+          }
+      }
+      break;
+
+    /* cmd:         EFUSEIOC_WRITE_REG
+     * Description: Read a 32-bits efuses (register block).
+     * Argument:    - efuse_reg
+     *              - efuse_value
+     */
+
+    case EFUSEIOC_WRITE_REG:
+      {
+        FAR struct efuse_par *param;
+
+        /* Write 32 EFUSEs at once */
+
+        if (lower->ops->write_reg) /* Optional */
+          {
+            param = (FAR struct efuse_par *)((uintptr_t)arg);
+            if (param)
+              {
+                lower->ops->write_reg(lower, param->block,
+                                      param->reg, *param->data);
+              }
+            else
+              {
+                ret = -EINVAL;
+              }
+          }
+        else
+          {
+            ret = -ENOSYS;
+          }
+      }
+      break;
+
+    default:
+      {
+        minfo("Forwarding unrecognized cmd: %d arg: %ld\n", cmd, arg);
+
+        /* An ioctl commands that are not recognized by the "upper-half"
+         * driver are forwarded to the lower half driver through this
+         * method.
+         */
+
+        if (lower->ops->ioctl) /* Optional */
+          {
+            ret = lower->ops->ioctl(lower, cmd, arg);
+          }
+        else
+          {
+            ret = -ENOTTY;
+          }
+      }
+      break;
+    }
+
+  nxsem_post(&upper->exclsem);
+  return ret;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: efuse_register
+ *
+ * Description:
+ *   This function binds an instance of a "lower half" efuse driver with
+ *   the "upper half" efuse device and registers that device so that can
+ *   be usedby application code.
+ *
+ * Input Parameters:
+ *   dev path - The full path to the driver to be registers in the NuttX

Review comment:
       Thank you @saramonteiro !

##########
File path: include/nuttx/efuse/efuse.h
##########
@@ -0,0 +1,294 @@
+/****************************************************************************
+ * include/nuttx/efuse/efuse.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_EFUSE_EFUSE_H
+#define __INCLUDE_NUTTX_EFUSE_EFUSE_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs/ioctl.h>
+
+#include <signal.h>
+#include <stdint.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Command:     EFUSEIOC_READ_FIELD_BLOB
+ * Description: Read a blob of bits from an efuse field.
+ * Arguments:   A structure containing the field[], a dst pointer, and size
+ *              of bits to be read from efuses.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD_BLOB      _EFUSEIOC(0x0001)
+
+/* Command:     EFUSEIOC_READ_FIELD_BIT
+ * Description: Read of state of an efuse bit.
+ * Arguments:   A structure containing the field to be read.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD_BIT       _EFUSEIOC(0x0002)
+
+/* Command:     EFUSEIOC_WRITE_FIELD_BLOB
+ * Description: Write a blob of bits to an efuse's field
+ * Arguments:   A structure containing the field[], the src memory and the
+ *              amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD_BLOB     _EFUSEIOC(0x0003)
+
+/* Command:     EFUSEIOC_WRITE_FIELD_BIT
+ * Description: Write a bit to an efuse (burn it).
+ * Arguments:   A structure containing bit field.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD_BIT      _EFUSEIOC(0x0004)
+
+/* Command:     EFUSEIOC_GET_FIELD_SIZE
+ * Description: Get the length of the field in bits.
+ * Arguments:   A structure containing the fields.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_GET_FIELD_SIZE       _EFUSEIOC(0x0005)
+
+/* Command:     EFUSEIOC_READ_REG
+ * Description: Read an efuse register.
+ * Arguments:   A structure containing the block number and the register to
+ *              be read.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_REG             _EFUSEIOC(0x0006)
+
+/* Command:     EFUSEIOC_WRITE_REG
+ * Description: Write an efuse register.
+ * Arguments:   A structure containing the block number, the register to
+ *              write and value to be written.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_REG            _EFUSEIOC(0x0007)
+
+/* Command:     EFUSEIOC_READ_BLOCK
+ * Description: Read a key from efuse's block.
+ * Arguments:   A structure containing the block number, the dst_key pointer,
+ *              the offset in bits and the amount of bits to read.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_BLOCK           _EFUSEIOC(0x0008)
+
+/* Command:     EFUSEIOC_WRITE_BLOCK
+ * Description: Write a key to efuse's block.
+ * Arguments:   A structure containing the block number, the src_key pointer,
+ *              the offset in bits and the amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_BLOCK          _EFUSEIOC(0x0009)
+
+/* Command:     EFUSEIOC_BATCH_WRITE_BEGIN
+ * Description: Start a batch operation, the efuse bits will be burned after
+ *              a batch write commit operation.
+ * Arguments:   None
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_BATCH_WRITE_BEGIN    _EFUSEIOC(0x000a)
+
+/* Command:     EFUSEIOC_BATCH_WRITE_CANCEL
+ * Description: Cancel a started batch write operation in progress.
+ * Arguments:   None
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_BATCH_WRITE_CANCEL   _EFUSEIOC(0x000b)
+
+/* Command:     EFUSEIOC_BATCH_WRITE_COMMIT
+ * Description: Commit a batch operation that was in progress.
+ * Arguments:   None
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_BATCH_WRITE_COMMIT   _EFUSEIOC(0x000c)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* Structure eFuse field */
+
+struct efuse_desc_s
+{
+  uint16_t   efuse_block;    /* Block of eFuse */
+  uint16_t   bit_start;      /* Start bit [0..65535] */
+  uint16_t   bit_count;      /* Length of bit field [1..-] */
+};
+
+/* Type definition for an eFuse field */
+
+typedef struct efuse_desc_s efuse_desc_t;
+
+/* Structure range address by blocks */
+
+typedef struct
+{
+  uint32_t start;
+  uint32_t end;
+} efuse_range_addr_t;
+
+/* Structs with the parameters passed to the IOCTLs */
+
+struct efuse_par
+{
+  uint16_t block;
+  uint16_t reg;
+  size_t   bit_offset;
+  size_t   bit_size;
+  uint8_t *data;
+};
+
+struct efuse_par_id
+{
+  efuse_desc_t **field;
+  size_t  size;
+  uint8_t *data;
+};
+
+/* This structure provides the "lower-half" driver operations available to
+ * the "upper-half" driver.
+ */
+
+struct efuse_lowerhalf_s;
+struct efuse_ops_s
+{
+  /* Required methods *******************************************************/
+
+  /* Read an EFUSE bit */
+
+  CODE int (*read_bit)(FAR struct efuse_lowerhalf_s *lower,
+                       const efuse_desc_t *field[],

Review comment:
       @xiaoxiang781216 I decided to keep the original array of efuse_desct_t, it brings more flexibility for fields definition. For example, we can define the MAC Addresses separating for bytes to keep a single stream:
   
   ```
   static const efuse_desc_t MAC_FACTORY[] =
   {
     {
       72, 8    /* Factory MAC addr [0], */
     },
     {
       64, 8    /* Factory MAC addr [1], */
     },
     {
       56, 8    /* Factory MAC addr [2], */
     },
     {
       48, 8    /* Factory MAC addr [3], */
     },
     {
       40, 8    /* Factory MAC addr [4], */
     },
     {
       32, 8    /* Factory MAC addr [5], */
     },
   };
   
   
   const efuse_desc_t *ESP_EFUSE_MAC_FACTORY[] =
   {
     &MAC_FACTORY[0],      /* Factory MAC addr [0] */
     &MAC_FACTORY[1],      /* Factory MAC addr [1] */
     &MAC_FACTORY[2],      /* Factory MAC addr [2] */
     &MAC_FACTORY[3],      /* Factory MAC addr [3] */
     &MAC_FACTORY[4],      /* Factory MAC addr [4] */
     &MAC_FACTORY[5],      /* Factory MAC addr [5] */
     NULL
   };
   
   
   static const efuse_desc_t MAC_CUSTOM[] =
   {
     {
       776, 48    /* Custom MAC */
     },
   };
   
   const efuse_desc_t *ESP_EFUSE_MAC_CUSTOM[] =
   {
     &MAC_CUSTOM[0],       /* Custom MAC */
     NULL
   };
   ```

##########
File path: include/nuttx/efuse/efuse.h
##########
@@ -0,0 +1,294 @@
+/****************************************************************************
+ * include/nuttx/efuse/efuse.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_EFUSE_EFUSE_H
+#define __INCLUDE_NUTTX_EFUSE_EFUSE_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs/ioctl.h>
+
+#include <signal.h>
+#include <stdint.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Command:     EFUSEIOC_READ_FIELD_BLOB
+ * Description: Read a blob of bits from an efuse field.
+ * Arguments:   A structure containing the field[], a dst pointer, and size
+ *              of bits to be read from efuses.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD_BLOB      _EFUSEIOC(0x0001)
+
+/* Command:     EFUSEIOC_READ_FIELD_BIT
+ * Description: Read of state of an efuse bit.
+ * Arguments:   A structure containing the field to be read.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD_BIT       _EFUSEIOC(0x0002)
+
+/* Command:     EFUSEIOC_WRITE_FIELD_BLOB
+ * Description: Write a blob of bits to an efuse's field
+ * Arguments:   A structure containing the field[], the src memory and the
+ *              amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD_BLOB     _EFUSEIOC(0x0003)
+
+/* Command:     EFUSEIOC_WRITE_FIELD_BIT
+ * Description: Write a bit to an efuse (burn it).
+ * Arguments:   A structure containing bit field.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD_BIT      _EFUSEIOC(0x0004)
+
+/* Command:     EFUSEIOC_GET_FIELD_SIZE
+ * Description: Get the length of the field in bits.
+ * Arguments:   A structure containing the fields.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_GET_FIELD_SIZE       _EFUSEIOC(0x0005)
+
+/* Command:     EFUSEIOC_READ_REG
+ * Description: Read an efuse register.
+ * Arguments:   A structure containing the block number and the register to
+ *              be read.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_REG             _EFUSEIOC(0x0006)
+
+/* Command:     EFUSEIOC_WRITE_REG
+ * Description: Write an efuse register.
+ * Arguments:   A structure containing the block number, the register to
+ *              write and value to be written.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_REG            _EFUSEIOC(0x0007)
+
+/* Command:     EFUSEIOC_READ_BLOCK
+ * Description: Read a key from efuse's block.
+ * Arguments:   A structure containing the block number, the dst_key pointer,
+ *              the offset in bits and the amount of bits to read.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_BLOCK           _EFUSEIOC(0x0008)
+
+/* Command:     EFUSEIOC_WRITE_BLOCK
+ * Description: Write a key to efuse's block.
+ * Arguments:   A structure containing the block number, the src_key pointer,
+ *              the offset in bits and the amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_BLOCK          _EFUSEIOC(0x0009)
+
+/* Command:     EFUSEIOC_BATCH_WRITE_BEGIN
+ * Description: Start a batch operation, the efuse bits will be burned after
+ *              a batch write commit operation.
+ * Arguments:   None
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_BATCH_WRITE_BEGIN    _EFUSEIOC(0x000a)
+
+/* Command:     EFUSEIOC_BATCH_WRITE_CANCEL
+ * Description: Cancel a started batch write operation in progress.
+ * Arguments:   None
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_BATCH_WRITE_CANCEL   _EFUSEIOC(0x000b)
+
+/* Command:     EFUSEIOC_BATCH_WRITE_COMMIT
+ * Description: Commit a batch operation that was in progress.
+ * Arguments:   None
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_BATCH_WRITE_COMMIT   _EFUSEIOC(0x000c)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* Structure eFuse field */
+
+struct efuse_desc_s
+{
+  uint16_t   efuse_block;    /* Block of eFuse */
+  uint16_t   bit_start;      /* Start bit [0..65535] */
+  uint16_t   bit_count;      /* Length of bit field [1..-] */
+};
+
+/* Type definition for an eFuse field */
+
+typedef struct efuse_desc_s efuse_desc_t;
+
+/* Structure range address by blocks */
+
+typedef struct
+{
+  uint32_t start;
+  uint32_t end;
+} efuse_range_addr_t;
+
+/* Structs with the parameters passed to the IOCTLs */
+
+struct efuse_par
+{
+  uint16_t block;
+  uint16_t reg;
+  size_t   bit_offset;
+  size_t   bit_size;
+  uint8_t *data;
+};
+
+struct efuse_par_id
+{
+  efuse_desc_t **field;
+  size_t  size;
+  uint8_t *data;
+};
+
+/* This structure provides the "lower-half" driver operations available to
+ * the "upper-half" driver.
+ */
+
+struct efuse_lowerhalf_s;
+struct efuse_ops_s
+{
+  /* Required methods *******************************************************/
+
+  /* Read an EFUSE bit */
+
+  CODE int (*read_bit)(FAR struct efuse_lowerhalf_s *lower,
+                       const efuse_desc_t *field[],

Review comment:
       But I removed things that were ESP32 specific, like the idea of separating efuses by blocks, now efuse is just a linear stream of bits. All we need to define are the fields with each efuse offset and its bit size.

##########
File path: include/nuttx/efuse/efuse.h
##########
@@ -0,0 +1,294 @@
+/****************************************************************************
+ * include/nuttx/efuse/efuse.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_EFUSE_EFUSE_H
+#define __INCLUDE_NUTTX_EFUSE_EFUSE_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs/ioctl.h>
+
+#include <signal.h>
+#include <stdint.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Command:     EFUSEIOC_READ_FIELD_BLOB
+ * Description: Read a blob of bits from an efuse field.
+ * Arguments:   A structure containing the field[], a dst pointer, and size
+ *              of bits to be read from efuses.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD_BLOB      _EFUSEIOC(0x0001)
+
+/* Command:     EFUSEIOC_READ_FIELD_BIT
+ * Description: Read of state of an efuse bit.
+ * Arguments:   A structure containing the field to be read.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD_BIT       _EFUSEIOC(0x0002)
+
+/* Command:     EFUSEIOC_WRITE_FIELD_BLOB
+ * Description: Write a blob of bits to an efuse's field
+ * Arguments:   A structure containing the field[], the src memory and the
+ *              amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD_BLOB     _EFUSEIOC(0x0003)
+
+/* Command:     EFUSEIOC_WRITE_FIELD_BIT
+ * Description: Write a bit to an efuse (burn it).
+ * Arguments:   A structure containing bit field.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD_BIT      _EFUSEIOC(0x0004)
+
+/* Command:     EFUSEIOC_GET_FIELD_SIZE
+ * Description: Get the length of the field in bits.
+ * Arguments:   A structure containing the fields.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_GET_FIELD_SIZE       _EFUSEIOC(0x0005)
+
+/* Command:     EFUSEIOC_READ_REG
+ * Description: Read an efuse register.
+ * Arguments:   A structure containing the block number and the register to
+ *              be read.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_REG             _EFUSEIOC(0x0006)
+
+/* Command:     EFUSEIOC_WRITE_REG
+ * Description: Write an efuse register.
+ * Arguments:   A structure containing the block number, the register to
+ *              write and value to be written.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_REG            _EFUSEIOC(0x0007)
+
+/* Command:     EFUSEIOC_READ_BLOCK
+ * Description: Read a key from efuse's block.
+ * Arguments:   A structure containing the block number, the dst_key pointer,
+ *              the offset in bits and the amount of bits to read.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_BLOCK           _EFUSEIOC(0x0008)
+
+/* Command:     EFUSEIOC_WRITE_BLOCK
+ * Description: Write a key to efuse's block.
+ * Arguments:   A structure containing the block number, the src_key pointer,
+ *              the offset in bits and the amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_BLOCK          _EFUSEIOC(0x0009)
+
+/* Command:     EFUSEIOC_BATCH_WRITE_BEGIN
+ * Description: Start a batch operation, the efuse bits will be burned after
+ *              a batch write commit operation.
+ * Arguments:   None
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_BATCH_WRITE_BEGIN    _EFUSEIOC(0x000a)
+
+/* Command:     EFUSEIOC_BATCH_WRITE_CANCEL
+ * Description: Cancel a started batch write operation in progress.
+ * Arguments:   None
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_BATCH_WRITE_CANCEL   _EFUSEIOC(0x000b)
+
+/* Command:     EFUSEIOC_BATCH_WRITE_COMMIT
+ * Description: Commit a batch operation that was in progress.
+ * Arguments:   None
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_BATCH_WRITE_COMMIT   _EFUSEIOC(0x000c)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* Structure eFuse field */
+
+struct efuse_desc_s
+{
+  uint16_t   efuse_block;    /* Block of eFuse */
+  uint16_t   bit_start;      /* Start bit [0..65535] */
+  uint16_t   bit_count;      /* Length of bit field [1..-] */
+};
+
+/* Type definition for an eFuse field */
+
+typedef struct efuse_desc_s efuse_desc_t;
+
+/* Structure range address by blocks */
+
+typedef struct
+{
+  uint32_t start;
+  uint32_t end;
+} efuse_range_addr_t;
+
+/* Structs with the parameters passed to the IOCTLs */
+
+struct efuse_par
+{
+  uint16_t block;
+  uint16_t reg;
+  size_t   bit_offset;
+  size_t   bit_size;
+  uint8_t *data;
+};
+
+struct efuse_par_id
+{
+  efuse_desc_t **field;
+  size_t  size;
+  uint8_t *data;
+};
+
+/* This structure provides the "lower-half" driver operations available to
+ * the "upper-half" driver.
+ */
+
+struct efuse_lowerhalf_s;
+struct efuse_ops_s
+{
+  /* Required methods *******************************************************/
+
+  /* Read an EFUSE bit */
+
+  CODE int (*read_bit)(FAR struct efuse_lowerhalf_s *lower,
+                       const efuse_desc_t *field[],

Review comment:
       Yes, exactly it what I did now! I removed the read/write block and read/write reg as you suggested! ;-)




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] saramonteiro commented on a change in pull request #2628: Add generic efuse driver for NuttX

Posted by GitBox <gi...@apache.org>.
saramonteiro commented on a change in pull request #2628:
URL: https://github.com/apache/incubator-nuttx/pull/2628#discussion_r557345542



##########
File path: include/nuttx/efuse/efuse.h
##########
@@ -0,0 +1,155 @@
+/****************************************************************************
+ * include/nuttx/efuse/efuse.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_EFUSE_EFUSE_H
+#define __INCLUDE_NUTTX_EFUSE_EFUSE_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs/ioctl.h>
+
+#include <signal.h>
+#include <stdint.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Command:     EFUSEIOC_READ_FIELD
+ * Description: Read a blob of bits from an efuse field.
+ * Arguments:   A structure containing the field[], a dst pointer, and size
+ *              of bits to be read from efuses.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD      _EFUSEIOC(0x0001)
+
+/* Command:     EFUSEIOC_WRITE_FIELD
+ * Description: Write a blob of bits to an efuse's field
+ * Arguments:   A structure containing the field[], the src memory and the
+ *              amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD     _EFUSEIOC(0x0002)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* Structure eFuse field */
+
+struct efuse_desc_s
+{
+  uint16_t   bit_offset; /* Bit offset related to beginning of efuse */
+  uint16_t   bit_count;  /* Length of bit field */
+};
+
+/* Type definition for an eFuse field */
+
+typedef struct efuse_desc_s efuse_desc_t;
+
+/* Structs with the parameters passed to the IOCTLs */
+
+struct efuse_param
+{
+  FAR const efuse_desc_t **field;
+  size_t  size;
+  FAR uint8_t *data;

Review comment:
       @acassis in this example, shouldn't `param.size` be equal to 1 since it is the sum of the sizes of each element in the array?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] acassis commented on a change in pull request #2628: Add generic efuse driver for NuttX

Posted by GitBox <gi...@apache.org>.
acassis commented on a change in pull request #2628:
URL: https://github.com/apache/incubator-nuttx/pull/2628#discussion_r551313793



##########
File path: include/nuttx/efuse/efuse.h
##########
@@ -0,0 +1,294 @@
+/****************************************************************************
+ * include/nuttx/efuse/efuse.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_EFUSE_EFUSE_H
+#define __INCLUDE_NUTTX_EFUSE_EFUSE_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs/ioctl.h>
+
+#include <signal.h>
+#include <stdint.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Command:     EFUSEIOC_READ_FIELD_BLOB
+ * Description: Read a blob of bits from an efuse field.
+ * Arguments:   A structure containing the field[], a dst pointer, and size
+ *              of bits to be read from efuses.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD_BLOB      _EFUSEIOC(0x0001)
+
+/* Command:     EFUSEIOC_READ_FIELD_BIT
+ * Description: Read of state of an efuse bit.
+ * Arguments:   A structure containing the field to be read.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD_BIT       _EFUSEIOC(0x0002)
+
+/* Command:     EFUSEIOC_WRITE_FIELD_BLOB
+ * Description: Write a blob of bits to an efuse's field
+ * Arguments:   A structure containing the field[], the src memory and the
+ *              amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD_BLOB     _EFUSEIOC(0x0003)
+
+/* Command:     EFUSEIOC_WRITE_FIELD_BIT
+ * Description: Write a bit to an efuse (burn it).
+ * Arguments:   A structure containing bit field.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD_BIT      _EFUSEIOC(0x0004)
+
+/* Command:     EFUSEIOC_GET_FIELD_SIZE
+ * Description: Get the length of the field in bits.
+ * Arguments:   A structure containing the fields.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_GET_FIELD_SIZE       _EFUSEIOC(0x0005)
+
+/* Command:     EFUSEIOC_READ_REG
+ * Description: Read an efuse register.
+ * Arguments:   A structure containing the block number and the register to
+ *              be read.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_REG             _EFUSEIOC(0x0006)
+
+/* Command:     EFUSEIOC_WRITE_REG
+ * Description: Write an efuse register.
+ * Arguments:   A structure containing the block number, the register to
+ *              write and value to be written.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_REG            _EFUSEIOC(0x0007)
+
+/* Command:     EFUSEIOC_READ_BLOCK
+ * Description: Read a key from efuse's block.
+ * Arguments:   A structure containing the block number, the dst_key pointer,
+ *              the offset in bits and the amount of bits to read.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_BLOCK           _EFUSEIOC(0x0008)

Review comment:
       Hi @xiaoxiang781216 read/write a field bit will work with fields of a single bit (a single fuse itself), the operation over reg will take care of 32 fuses just like a ordinary 32-bit register and finally block is an arbitrary size of fuse. This driver was based on existing Espressif eFuse driver, but I agree with you, we could come up with a single operation that will ignore these differences.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] acassis commented on a change in pull request #2628: Add generic efuse driver for NuttX

Posted by GitBox <gi...@apache.org>.
acassis commented on a change in pull request #2628:
URL: https://github.com/apache/incubator-nuttx/pull/2628#discussion_r556723831



##########
File path: drivers/efuse/efuse.c
##########
@@ -0,0 +1,395 @@
+/****************************************************************************
+ * drivers/efuse/efuse.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <string.h>
+#include <fcntl.h>
+#include <assert.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <nuttx/fs/fs.h>
+#include <nuttx/irq.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/power/pm.h>
+#include <nuttx/semaphore.h>
+#include <nuttx/efuse/efuse.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Type Definitions
+ ****************************************************************************/
+
+/* This structure describes the state of the upper half driver */
+
+struct efuse_upperhalf_s
+{
+  sem_t     exclsem;  /* Supports mutual exclusion */
+  FAR char *path;     /* Registration path */
+
+  /* The contained lower-half driver */
+
+  FAR struct efuse_lowerhalf_s *lower;
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int     efuse_open(FAR struct file *filep);
+static int     efuse_close(FAR struct file *filep);
+static ssize_t efuse_read(FAR struct file *filep, FAR char *buffer,
+                          size_t buflen);
+static ssize_t efuse_write(FAR struct file *filep, FAR const char *buffer,
+                           size_t buflen);
+static int     efuse_ioctl(FAR struct file *filep, int cmd,
+                           unsigned long arg);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct file_operations g_efuseops =
+{
+  efuse_open,  /* open */
+  efuse_close, /* close */
+  efuse_read,  /* read */
+  efuse_write, /* write */
+  NULL,        /* seek */
+  efuse_ioctl, /* ioctl */
+  NULL         /* poll */
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: efuse_open
+ *
+ * Description:
+ *   This function is called whenever the efuse timer device is opened.
+ *
+ ****************************************************************************/
+
+static int efuse_open(FAR struct file *filep)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: efuse_close
+ *
+ * Description:
+ *   This function is called when the efuse timer device is closed.
+ *
+ ****************************************************************************/
+
+static int efuse_close(FAR struct file *filep)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: efuse_read
+ *
+ * Description:
+ *   A dummy read method.  This is provided only to satisfy the VFS layer.
+ *
+ ****************************************************************************/
+
+static ssize_t efuse_read(FAR struct file *filep, FAR char *buffer,
+                         size_t buflen)
+{
+  /* Return zero -- usually meaning end-of-file */
+
+  return 0;
+}
+
+/****************************************************************************
+ * Name: efuse_write
+ *
+ * Description:
+ *   A dummy write method.  This is provided only to satisfy the VFS layer.
+ *
+ ****************************************************************************/
+
+static ssize_t efuse_write(FAR struct file *filep, FAR const char *buffer,
+                          size_t buflen)
+{
+  return 0;

Review comment:
       If we return buflen the application will think the passed buffer data was written, but it wasn't. Look the function wdog_write() at drivers/timers/watchdog.c, it is the same idea.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a change in pull request #2628: Add generic efuse driver for NuttX

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on a change in pull request #2628:
URL: https://github.com/apache/incubator-nuttx/pull/2628#discussion_r557419042



##########
File path: include/nuttx/efuse/efuse.h
##########
@@ -0,0 +1,155 @@
+/****************************************************************************
+ * include/nuttx/efuse/efuse.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_EFUSE_EFUSE_H
+#define __INCLUDE_NUTTX_EFUSE_EFUSE_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs/ioctl.h>
+
+#include <signal.h>
+#include <stdint.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Command:     EFUSEIOC_READ_FIELD
+ * Description: Read a blob of bits from an efuse field.
+ * Arguments:   A structure containing the field[], a dst pointer, and size
+ *              of bits to be read from efuses.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD      _EFUSEIOC(0x0001)
+
+/* Command:     EFUSEIOC_WRITE_FIELD
+ * Description: Write a blob of bits to an efuse's field
+ * Arguments:   A structure containing the field[], the src memory and the
+ *              amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD     _EFUSEIOC(0x0002)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* Structure eFuse field */
+
+struct efuse_desc_s
+{
+  uint16_t   bit_offset; /* Bit offset related to beginning of efuse */
+  uint16_t   bit_count;  /* Length of bit field */
+};
+
+/* Type definition for an eFuse field */
+
+typedef struct efuse_desc_s efuse_desc_t;
+
+/* Structs with the parameters passed to the IOCTLs */
+
+struct efuse_param
+{
+  FAR const efuse_desc_t **field;

Review comment:
       Please add comment to describe how the array terminated.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a change in pull request #2628: Add generic efuse driver for NuttX

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on a change in pull request #2628:
URL: https://github.com/apache/incubator-nuttx/pull/2628#discussion_r557418357



##########
File path: include/nuttx/efuse/efuse.h
##########
@@ -0,0 +1,155 @@
+/****************************************************************************
+ * include/nuttx/efuse/efuse.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_EFUSE_EFUSE_H
+#define __INCLUDE_NUTTX_EFUSE_EFUSE_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs/ioctl.h>
+
+#include <signal.h>
+#include <stdint.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Command:     EFUSEIOC_READ_FIELD
+ * Description: Read a blob of bits from an efuse field.
+ * Arguments:   A structure containing the field[], a dst pointer, and size
+ *              of bits to be read from efuses.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD      _EFUSEIOC(0x0001)
+
+/* Command:     EFUSEIOC_WRITE_FIELD
+ * Description: Write a blob of bits to an efuse's field
+ * Arguments:   A structure containing the field[], the src memory and the
+ *              amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD     _EFUSEIOC(0x0002)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* Structure eFuse field */
+
+struct efuse_desc_s
+{
+  uint16_t   bit_offset; /* Bit offset related to beginning of efuse */
+  uint16_t   bit_count;  /* Length of bit field */
+};
+
+/* Type definition for an eFuse field */
+
+typedef struct efuse_desc_s efuse_desc_t;
+
+/* Structs with the parameters passed to the IOCTLs */
+
+struct efuse_param
+{
+  FAR const efuse_desc_t **field;
+  size_t  size;
+  FAR uint8_t *data;
+};
+
+/* This structure provides the "lower-half" driver operations available to
+ * the "upper-half" driver.
+ */
+
+struct efuse_lowerhalf_s;
+struct efuse_ops_s
+{
+  /* Required methods *******************************************************/
+
+  /* Read an EFUSE bit */
+
+  CODE int (*read_field)(FAR struct efuse_lowerhalf_s *lower,
+                         FAR const efuse_desc_t *field[],
+                         FAR uint8_t *data, size_t bit_size);
+
+  /* Write an EFUSE bit */
+
+  CODE int (*write_field)(FAR struct efuse_lowerhalf_s *lower,
+                          FAR const efuse_desc_t *field[],
+                          FAR const uint8_t *data, size_t bit_size);
+
+  /* Any ioctl commands that are not recognized by the "upper-half" driver
+   * are forwarded to the lower half driver through this method.
+   */
+
+  CODE int (*ioctl)(FAR struct efuse_lowerhalf_s *lower, int cmd,
+                    unsigned long arg);
+};
+
+/* This structure provides the publicly visible representation of the
+ * "lower-half" driver state structure.  "lower half" drivers will have an
+ * internal structure definition that will be cast-compatible with this
+ * structure definitions.
+ */
+
+struct efuse_lowerhalf_s
+{
+  /* Publicly visible portion of the "lower-half" driver state structure. */
+
+  FAR const struct efuse_ops_s  *ops;  /* Lower half operations */
+
+  /* The remainder of the structure is used by the "lower-half" driver
+   * for whatever state storage that it may need.
+   */
+
+  void   *upper;                       /* Pointer to watchdog_upperhalf_s */
+};
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+

Review comment:
       I don't unterstand why lowerhalf require upper pointer?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a change in pull request #2628: Add generic efuse driver for NuttX

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on a change in pull request #2628:
URL: https://github.com/apache/incubator-nuttx/pull/2628#discussion_r551321958



##########
File path: include/nuttx/efuse/efuse.h
##########
@@ -0,0 +1,294 @@
+/****************************************************************************
+ * include/nuttx/efuse/efuse.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_EFUSE_EFUSE_H
+#define __INCLUDE_NUTTX_EFUSE_EFUSE_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs/ioctl.h>
+
+#include <signal.h>
+#include <stdint.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Command:     EFUSEIOC_READ_FIELD_BLOB
+ * Description: Read a blob of bits from an efuse field.
+ * Arguments:   A structure containing the field[], a dst pointer, and size
+ *              of bits to be read from efuses.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD_BLOB      _EFUSEIOC(0x0001)
+
+/* Command:     EFUSEIOC_READ_FIELD_BIT
+ * Description: Read of state of an efuse bit.
+ * Arguments:   A structure containing the field to be read.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD_BIT       _EFUSEIOC(0x0002)
+
+/* Command:     EFUSEIOC_WRITE_FIELD_BLOB
+ * Description: Write a blob of bits to an efuse's field
+ * Arguments:   A structure containing the field[], the src memory and the
+ *              amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD_BLOB     _EFUSEIOC(0x0003)
+
+/* Command:     EFUSEIOC_WRITE_FIELD_BIT
+ * Description: Write a bit to an efuse (burn it).
+ * Arguments:   A structure containing bit field.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD_BIT      _EFUSEIOC(0x0004)
+
+/* Command:     EFUSEIOC_GET_FIELD_SIZE
+ * Description: Get the length of the field in bits.
+ * Arguments:   A structure containing the fields.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_GET_FIELD_SIZE       _EFUSEIOC(0x0005)
+
+/* Command:     EFUSEIOC_READ_REG
+ * Description: Read an efuse register.
+ * Arguments:   A structure containing the block number and the register to
+ *              be read.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_REG             _EFUSEIOC(0x0006)
+
+/* Command:     EFUSEIOC_WRITE_REG
+ * Description: Write an efuse register.
+ * Arguments:   A structure containing the block number, the register to
+ *              write and value to be written.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_REG            _EFUSEIOC(0x0007)
+
+/* Command:     EFUSEIOC_READ_BLOCK
+ * Description: Read a key from efuse's block.
+ * Arguments:   A structure containing the block number, the dst_key pointer,
+ *              the offset in bits and the amount of bits to read.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_BLOCK           _EFUSEIOC(0x0008)

Review comment:
       it's better to define a simple and clean interface first, then consider how to map the generic interface to espressif driver api. Otherwise,  other vendor is hard to understand the interface and then provide a reasonable implementation. 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] acassis commented on a change in pull request #2628: Add generic efuse driver for NuttX

Posted by GitBox <gi...@apache.org>.
acassis commented on a change in pull request #2628:
URL: https://github.com/apache/incubator-nuttx/pull/2628#discussion_r556712414



##########
File path: drivers/efuse/efuse.c
##########
@@ -0,0 +1,395 @@
+/****************************************************************************
+ * drivers/efuse/efuse.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <string.h>
+#include <fcntl.h>
+#include <assert.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <nuttx/fs/fs.h>
+#include <nuttx/irq.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/power/pm.h>
+#include <nuttx/semaphore.h>
+#include <nuttx/efuse/efuse.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Type Definitions
+ ****************************************************************************/
+
+/* This structure describes the state of the upper half driver */
+
+struct efuse_upperhalf_s
+{
+  sem_t     exclsem;  /* Supports mutual exclusion */
+  FAR char *path;     /* Registration path */
+
+  /* The contained lower-half driver */
+
+  FAR struct efuse_lowerhalf_s *lower;
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int     efuse_open(FAR struct file *filep);
+static int     efuse_close(FAR struct file *filep);
+static ssize_t efuse_read(FAR struct file *filep, FAR char *buffer,
+                          size_t buflen);
+static ssize_t efuse_write(FAR struct file *filep, FAR const char *buffer,
+                           size_t buflen);
+static int     efuse_ioctl(FAR struct file *filep, int cmd,
+                           unsigned long arg);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct file_operations g_efuseops =
+{
+  efuse_open,  /* open */
+  efuse_close, /* close */
+  efuse_read,  /* read */
+  efuse_write, /* write */
+  NULL,        /* seek */
+  efuse_ioctl, /* ioctl */
+  NULL         /* poll */
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: efuse_open
+ *
+ * Description:
+ *   This function is called whenever the efuse timer device is opened.
+ *
+ ****************************************************************************/
+
+static int efuse_open(FAR struct file *filep)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: efuse_close
+ *
+ * Description:
+ *   This function is called when the efuse timer device is closed.
+ *
+ ****************************************************************************/
+
+static int efuse_close(FAR struct file *filep)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: efuse_read
+ *
+ * Description:
+ *   A dummy read method.  This is provided only to satisfy the VFS layer.
+ *
+ ****************************************************************************/
+
+static ssize_t efuse_read(FAR struct file *filep, FAR char *buffer,
+                         size_t buflen)
+{
+  /* Return zero -- usually meaning end-of-file */
+
+  return 0;
+}
+
+/****************************************************************************
+ * Name: efuse_write
+ *
+ * Description:
+ *   A dummy write method.  This is provided only to satisfy the VFS layer.
+ *
+ ****************************************************************************/
+
+static ssize_t efuse_write(FAR struct file *filep, FAR const char *buffer,
+                          size_t buflen)
+{
+  return 0;
+}
+
+/****************************************************************************
+ * Name: efuse_ioctl
+ *
+ * Description:
+ *   The standard ioctl method.  This is where ALL of the efuse timer
+ *   work is done.
+ *
+ ****************************************************************************/
+
+static int efuse_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
+{
+  FAR struct inode             *inode = filep->f_inode;
+  FAR struct efuse_upperhalf_s *upper;
+  FAR struct efuse_lowerhalf_s *lower;
+  int                           ret;
+
+  minfo("cmd: %d arg: %lu\n", cmd, arg);
+  upper = inode->i_private;
+  DEBUGASSERT(upper != NULL);
+  lower = upper->lower;
+  DEBUGASSERT(lower != NULL);
+
+  /* Get exclusive access to the device structures */
+
+  ret = nxsem_wait(&upper->exclsem);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  /* Handle built-in ioctl commands */
+
+  switch (cmd)
+    {
+    /* cmd:         EFUSEIOC_READ_FIELD
+     * Description: Read a field
+     * Argument:    A pointer to a struct efuse_param.
+     *              Where the field is an array.
+     *              Each item in the array is a pointer to an efuse_desc_t
+     *              variable.
+     *              An efuse_desc_t variable contains an offset to a field
+     *              or subfield and its size in bits.
+     *              The size param is a redundancy, and it is the sum
+     *              of all subfields sizes from efuse_desc_t in bits.
+     *              The data is a pointer to a pre-allocated space
+     *              where the driver will load the data read from efuse.
+     */
+
+    case EFUSEIOC_READ_FIELD:
+      {
+        FAR struct efuse_param *param =
+                   (FAR struct efuse_param *)((uintptr_t)arg);
+
+        /* Read the efuse */
+
+        DEBUGASSERT(lower->ops->read_field); /* Required */
+        ret = lower->ops->read_field(lower,
+                                     (const efuse_desc_t **) param->field,
+                                     param->data,
+                                     param->size);
+      }
+      break;
+
+    /* cmd:         EFUSEIOC_WRITE_FIELD
+     * Description: Write a field
+     * Argument: A pointer to a struct efuse_param.
+     *           Where the field is an array.
+     *           Each item in the array is a pointer to an efuse_desc_t
+     *           variable.
+     *           An efuse_desc_t variable contains an offset to a field
+     *           or subfield and its size in bits.
+     *           The size param is a redundancy, and it is the sum
+     *           of all subfields sizes from efuse_desc_t in bits.
+     *           The data is a pointer to a pre-allocated space
+     *           where the user wrote the value that he wants
+     *           to write in a field or subfield.
+     */
+
+    case EFUSEIOC_WRITE_FIELD:
+      {
+        FAR struct efuse_param *param =
+                   (FAR struct efuse_param *)((uintptr_t)arg);
+
+        /* Write the efuse */
+
+        DEBUGASSERT(lower->ops->write_field); /* Required */
+        ret = lower->ops->write_field(lower,
+                                      (const efuse_desc_t **) param->field,
+                                      param->data,
+                                      param->size);
+      }
+      break;
+
+    default:
+      {
+        minfo("Forwarding unrecognized cmd: %d arg: %lu\n", cmd, arg);
+
+        /* Ioctls commands that are not recognized by the "upper-half"
+         * driver are forwarded to the lower half driver through this
+         * method.
+         */
+
+        if (lower->ops->ioctl) /* Optional */
+          {
+            ret = lower->ops->ioctl(lower, cmd, arg);
+          }
+        else
+          {
+            ret = -ENOTTY;
+          }
+      }
+      break;
+    }
+
+  nxsem_post(&upper->exclsem);
+  return ret;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: efuse_register
+ *
+ * Description:
+ *   This function binds an instance of a "lower half" efuse driver with
+ *   the "upper half" efuse device and registers that device so that can
+ *   be used by application code.
+ *
+ * Input Parameters:
+ *   dev path - The full path to the driver to be registered in the NuttX
+ *     pseudo-filesystem.  The recommended convention is to name all
+ *     efuse drivers as "/dev/efuse".
+ *   lower - A pointer to an instance of lower half efuse driver.  This
+ *     instance is bound to the efuse driver and must persists as long as
+ *     the driver persists.
+ *
+ * Returned Value:
+ *   On success, a non-NULL handle is returned to the caller.  In the event
+ *   of any failure, a NULL value is returned.
+ *
+ ****************************************************************************/
+
+FAR void *efuse_register(FAR const char *path,
+                         FAR struct efuse_lowerhalf_s *lower)
+{
+  FAR struct efuse_upperhalf_s *upper;
+  int ret;
+
+  DEBUGASSERT(path && lower);
+  minfo("Entry: path=%s\n", path);
+
+  /* Allocate the upper-half data structure */
+
+  upper = (FAR struct efuse_upperhalf_s *)
+          kmm_zalloc(sizeof(struct efuse_upperhalf_s));
+  if (!upper)
+    {
+      merr("Upper half allocation failed\n");
+      goto errout;
+    }
+
+  /* Initialize the efuse timer device structure (it was already zeroed
+   * by kmm_zalloc()).
+   */
+
+  nxsem_init(&upper->exclsem, 0, 1);
+  upper->lower = lower;
+
+  /* Copy the registration path */
+
+  upper->path = strdup(path);
+  if (!upper->path)
+    {
+      merr("Path allocation failed\n");
+      goto errout_with_upper;
+    }
+
+  /* Register the efuse timer device */
+
+  ret = register_driver(path, &g_efuseops, 0666, upper);
+  if (ret < 0)
+    {
+      merr("register_driver failed: %d\n", ret);
+      goto errout_with_path;
+    }
+
+  return (FAR void *)upper;
+
+errout_with_path:
+  kmm_free(upper->path);
+
+errout_with_upper:
+  nxsem_destroy(&upper->exclsem);
+  kmm_free(upper);
+
+errout:
+  return NULL;
+}
+
+/****************************************************************************
+ * Name: efuse_unregister
+ *
+ * Description:
+ *   This function can be called to disable and unregister the efuse
+ *   device driver.
+ *
+ * Input Parameters:
+ *   handle - This is the handle that was returned by efuse_register()
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+void efuse_unregister(FAR void *handle)
+{
+  FAR struct efuse_upperhalf_s *upper;
+  FAR struct efuse_lowerhalf_s *lower;
+
+  /* Recover the pointer to the upper-half driver state */
+
+  upper = (FAR struct efuse_upperhalf_s *)handle;
+  DEBUGASSERT(upper != NULL);
+  lower = upper->lower;
+  DEBUGASSERT(lower != NULL);
+
+  minfo("Unregistering: %s\n", upper->path);
+
+  /* Unregister the efuse timer device */
+
+  unregister_driver(upper->path);
+
+  /* Then free all of the driver resources */
+
+  kmm_free(upper->path);
+  nxsem_destroy(&upper->exclsem);
+  kmm_free(lower);

Review comment:
       Yes, please look the watchdog_unregister() at drivers/timers/watchdog.c




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] saramonteiro commented on a change in pull request #2628: Add generic efuse driver for NuttX

Posted by GitBox <gi...@apache.org>.
saramonteiro commented on a change in pull request #2628:
URL: https://github.com/apache/incubator-nuttx/pull/2628#discussion_r554078069



##########
File path: drivers/efuse/efuse.c
##########
@@ -0,0 +1,514 @@
+/****************************************************************************
+ * drivers/efuse/efuse.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <string.h>
+#include <fcntl.h>
+#include <assert.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <nuttx/fs/fs.h>
+#include <nuttx/irq.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/power/pm.h>
+#include <nuttx/semaphore.h>
+#include <nuttx/efuse/efuse.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Type Definitions
+ ****************************************************************************/
+
+/* This structure describes the state of the upper half driver */
+
+struct efuse_upperhalf_s
+{
+  sem_t     exclsem;  /* Supports mutual exclusion */
+  FAR char *path;     /* Registration path */
+
+  /* The contained lower-half driver */
+
+  FAR struct efuse_lowerhalf_s *lower;
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int     efuse_open(FAR struct file *filep);
+static int     efuse_close(FAR struct file *filep);
+static ssize_t efuse_read(FAR struct file *filep, FAR char *buffer,
+                          size_t buflen);
+static ssize_t efuse_write(FAR struct file *filep, FAR const char *buffer,
+                           size_t buflen);
+static int     efuse_ioctl(FAR struct file *filep, int cmd,
+                 unsigned long arg);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct file_operations g_efuseops =
+{
+  efuse_open,  /* open */
+  efuse_close, /* close */
+  efuse_read,  /* read */
+  efuse_write, /* write */
+  NULL,        /* seek */
+  efuse_ioctl, /* ioctl */
+  NULL         /* poll */
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: efuse_open
+ *
+ * Description:
+ *   This function is called whenever the efuse timer device is opened.
+ *
+ ****************************************************************************/
+
+static int efuse_open(FAR struct file *filep)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: efuse_close
+ *
+ * Description:
+ *   This function is called when the efuse timer device is closed.
+ *
+ ****************************************************************************/
+
+static int efuse_close(FAR struct file *filep)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: efuse_read
+ *
+ * Description:
+ *   A dummy read method.  This is provided only to satisfy the VFS layer.
+ *
+ ****************************************************************************/
+
+static ssize_t efuse_read(FAR struct file *filep, FAR char *buffer,
+                         size_t buflen)
+{
+  /* Return zero -- usually meaning end-of-file */
+
+  return 0;
+}
+
+/****************************************************************************
+ * Name: efuse_write
+ *
+ * Description:
+ *   A dummy write method.  This is provided only to satisfy the VFS layer.
+ *
+ ****************************************************************************/
+
+static ssize_t efuse_write(FAR struct file *filep, FAR const char *buffer,
+                          size_t buflen)
+{
+  return 0;
+}
+
+/****************************************************************************
+ * Name: efuse_ioctl
+ *
+ * Description:
+ *   The standard ioctl method.  This is where ALL of the efuse timer
+ *   work is done.
+ *
+ ****************************************************************************/
+
+static int efuse_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
+{
+  FAR struct inode             *inode = filep->f_inode;
+  FAR struct efuse_upperhalf_s *upper;
+  FAR struct efuse_lowerhalf_s *lower;
+  int                           ret;
+
+  minfo("cmd: %d arg: %ld\n", cmd, arg);

Review comment:
       ```suggestion
     minfo("cmd: %d arg: %lu\n", cmd, arg);
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] acassis commented on a change in pull request #2628: Add generic efuse driver for NuttX

Posted by GitBox <gi...@apache.org>.
acassis commented on a change in pull request #2628:
URL: https://github.com/apache/incubator-nuttx/pull/2628#discussion_r551315486



##########
File path: include/nuttx/efuse/efuse.h
##########
@@ -0,0 +1,294 @@
+/****************************************************************************
+ * include/nuttx/efuse/efuse.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_EFUSE_EFUSE_H
+#define __INCLUDE_NUTTX_EFUSE_EFUSE_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs/ioctl.h>
+
+#include <signal.h>
+#include <stdint.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Command:     EFUSEIOC_READ_FIELD_BLOB
+ * Description: Read a blob of bits from an efuse field.
+ * Arguments:   A structure containing the field[], a dst pointer, and size
+ *              of bits to be read from efuses.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD_BLOB      _EFUSEIOC(0x0001)
+
+/* Command:     EFUSEIOC_READ_FIELD_BIT
+ * Description: Read of state of an efuse bit.
+ * Arguments:   A structure containing the field to be read.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD_BIT       _EFUSEIOC(0x0002)
+
+/* Command:     EFUSEIOC_WRITE_FIELD_BLOB
+ * Description: Write a blob of bits to an efuse's field
+ * Arguments:   A structure containing the field[], the src memory and the
+ *              amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD_BLOB     _EFUSEIOC(0x0003)
+
+/* Command:     EFUSEIOC_WRITE_FIELD_BIT
+ * Description: Write a bit to an efuse (burn it).
+ * Arguments:   A structure containing bit field.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD_BIT      _EFUSEIOC(0x0004)
+
+/* Command:     EFUSEIOC_GET_FIELD_SIZE
+ * Description: Get the length of the field in bits.
+ * Arguments:   A structure containing the fields.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_GET_FIELD_SIZE       _EFUSEIOC(0x0005)
+
+/* Command:     EFUSEIOC_READ_REG
+ * Description: Read an efuse register.
+ * Arguments:   A structure containing the block number and the register to
+ *              be read.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_REG             _EFUSEIOC(0x0006)
+
+/* Command:     EFUSEIOC_WRITE_REG
+ * Description: Write an efuse register.
+ * Arguments:   A structure containing the block number, the register to
+ *              write and value to be written.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_REG            _EFUSEIOC(0x0007)
+
+/* Command:     EFUSEIOC_READ_BLOCK
+ * Description: Read a key from efuse's block.
+ * Arguments:   A structure containing the block number, the dst_key pointer,
+ *              the offset in bits and the amount of bits to read.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_BLOCK           _EFUSEIOC(0x0008)
+
+/* Command:     EFUSEIOC_WRITE_BLOCK
+ * Description: Write a key to efuse's block.
+ * Arguments:   A structure containing the block number, the src_key pointer,
+ *              the offset in bits and the amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_BLOCK          _EFUSEIOC(0x0009)
+
+/* Command:     EFUSEIOC_BATCH_WRITE_BEGIN
+ * Description: Start a batch operation, the efuse bits will be burned after
+ *              a batch write commit operation.
+ * Arguments:   None
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_BATCH_WRITE_BEGIN    _EFUSEIOC(0x000a)
+
+/* Command:     EFUSEIOC_BATCH_WRITE_CANCEL
+ * Description: Cancel a started batch write operation in progress.
+ * Arguments:   None
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_BATCH_WRITE_CANCEL   _EFUSEIOC(0x000b)
+
+/* Command:     EFUSEIOC_BATCH_WRITE_COMMIT
+ * Description: Commit a batch operation that was in progress.
+ * Arguments:   None
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_BATCH_WRITE_COMMIT   _EFUSEIOC(0x000c)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* Structure eFuse field */
+
+struct efuse_desc_s
+{
+  uint16_t   efuse_block;    /* Block of eFuse */
+  uint16_t   bit_start;      /* Start bit [0..65535] */
+  uint16_t   bit_count;      /* Length of bit field [1..-] */
+};
+
+/* Type definition for an eFuse field */
+
+typedef struct efuse_desc_s efuse_desc_t;
+
+/* Structure range address by blocks */
+
+typedef struct
+{
+  uint32_t start;
+  uint32_t end;
+} efuse_range_addr_t;
+
+/* Structs with the parameters passed to the IOCTLs */
+
+struct efuse_par
+{
+  uint16_t block;
+  uint16_t reg;
+  size_t   bit_offset;
+  size_t   bit_size;
+  uint8_t *data;
+};
+
+struct efuse_par_id
+{
+  efuse_desc_t **field;
+  size_t  size;
+  uint8_t *data;
+};
+
+/* This structure provides the "lower-half" driver operations available to
+ * the "upper-half" driver.
+ */
+
+struct efuse_lowerhalf_s;
+struct efuse_ops_s
+{
+  /* Required methods *******************************************************/
+
+  /* Read an EFUSE bit */
+
+  CODE int (*read_bit)(FAR struct efuse_lowerhalf_s *lower,
+                       const efuse_desc_t *field[],

Review comment:
       I think that the original idea of passing an array of efuse_desc_t was to be able to read/write multiples fields with a single call, but it is not used in my driver neither in the IDF driver. I will modify it to pass a single structure.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a change in pull request #2628: Add generic efuse driver for NuttX

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on a change in pull request #2628:
URL: https://github.com/apache/incubator-nuttx/pull/2628#discussion_r554449792



##########
File path: include/nuttx/efuse/efuse.h
##########
@@ -0,0 +1,294 @@
+/****************************************************************************
+ * include/nuttx/efuse/efuse.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_EFUSE_EFUSE_H
+#define __INCLUDE_NUTTX_EFUSE_EFUSE_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs/ioctl.h>
+
+#include <signal.h>
+#include <stdint.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Command:     EFUSEIOC_READ_FIELD_BLOB
+ * Description: Read a blob of bits from an efuse field.
+ * Arguments:   A structure containing the field[], a dst pointer, and size
+ *              of bits to be read from efuses.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD_BLOB      _EFUSEIOC(0x0001)
+
+/* Command:     EFUSEIOC_READ_FIELD_BIT
+ * Description: Read of state of an efuse bit.
+ * Arguments:   A structure containing the field to be read.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD_BIT       _EFUSEIOC(0x0002)
+
+/* Command:     EFUSEIOC_WRITE_FIELD_BLOB
+ * Description: Write a blob of bits to an efuse's field
+ * Arguments:   A structure containing the field[], the src memory and the
+ *              amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD_BLOB     _EFUSEIOC(0x0003)
+
+/* Command:     EFUSEIOC_WRITE_FIELD_BIT
+ * Description: Write a bit to an efuse (burn it).
+ * Arguments:   A structure containing bit field.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD_BIT      _EFUSEIOC(0x0004)
+
+/* Command:     EFUSEIOC_GET_FIELD_SIZE
+ * Description: Get the length of the field in bits.
+ * Arguments:   A structure containing the fields.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_GET_FIELD_SIZE       _EFUSEIOC(0x0005)
+
+/* Command:     EFUSEIOC_READ_REG
+ * Description: Read an efuse register.
+ * Arguments:   A structure containing the block number and the register to
+ *              be read.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_REG             _EFUSEIOC(0x0006)
+
+/* Command:     EFUSEIOC_WRITE_REG
+ * Description: Write an efuse register.
+ * Arguments:   A structure containing the block number, the register to
+ *              write and value to be written.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_REG            _EFUSEIOC(0x0007)
+
+/* Command:     EFUSEIOC_READ_BLOCK
+ * Description: Read a key from efuse's block.
+ * Arguments:   A structure containing the block number, the dst_key pointer,
+ *              the offset in bits and the amount of bits to read.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_BLOCK           _EFUSEIOC(0x0008)
+
+/* Command:     EFUSEIOC_WRITE_BLOCK
+ * Description: Write a key to efuse's block.
+ * Arguments:   A structure containing the block number, the src_key pointer,
+ *              the offset in bits and the amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_BLOCK          _EFUSEIOC(0x0009)
+
+/* Command:     EFUSEIOC_BATCH_WRITE_BEGIN
+ * Description: Start a batch operation, the efuse bits will be burned after
+ *              a batch write commit operation.
+ * Arguments:   None
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_BATCH_WRITE_BEGIN    _EFUSEIOC(0x000a)
+
+/* Command:     EFUSEIOC_BATCH_WRITE_CANCEL
+ * Description: Cancel a started batch write operation in progress.
+ * Arguments:   None
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_BATCH_WRITE_CANCEL   _EFUSEIOC(0x000b)
+
+/* Command:     EFUSEIOC_BATCH_WRITE_COMMIT
+ * Description: Commit a batch operation that was in progress.
+ * Arguments:   None
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_BATCH_WRITE_COMMIT   _EFUSEIOC(0x000c)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* Structure eFuse field */
+
+struct efuse_desc_s
+{
+  uint16_t   efuse_block;    /* Block of eFuse */
+  uint16_t   bit_start;      /* Start bit [0..65535] */
+  uint16_t   bit_count;      /* Length of bit field [1..-] */
+};
+
+/* Type definition for an eFuse field */
+
+typedef struct efuse_desc_s efuse_desc_t;
+
+/* Structure range address by blocks */
+
+typedef struct
+{
+  uint32_t start;
+  uint32_t end;
+} efuse_range_addr_t;
+
+/* Structs with the parameters passed to the IOCTLs */
+
+struct efuse_par
+{
+  uint16_t block;
+  uint16_t reg;
+  size_t   bit_offset;
+  size_t   bit_size;
+  uint8_t *data;
+};
+
+struct efuse_par_id
+{
+  efuse_desc_t **field;
+  size_t  size;
+  uint8_t *data;
+};
+
+/* This structure provides the "lower-half" driver operations available to
+ * the "upper-half" driver.
+ */
+
+struct efuse_lowerhalf_s;
+struct efuse_ops_s
+{
+  /* Required methods *******************************************************/
+
+  /* Read an EFUSE bit */
+
+  CODE int (*read_bit)(FAR struct efuse_lowerhalf_s *lower,
+                       const efuse_desc_t *field[],

Review comment:
       Since efuse_desc_t is very flexible, doesn't this mean we just need two callback(read/write with efuse_desc_t array) now?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] saramonteiro commented on a change in pull request #2628: Add generic efuse driver for NuttX

Posted by GitBox <gi...@apache.org>.
saramonteiro commented on a change in pull request #2628:
URL: https://github.com/apache/incubator-nuttx/pull/2628#discussion_r554080968



##########
File path: drivers/efuse/efuse.c
##########
@@ -0,0 +1,514 @@
+/****************************************************************************
+ * drivers/efuse/efuse.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <string.h>
+#include <fcntl.h>
+#include <assert.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <nuttx/fs/fs.h>
+#include <nuttx/irq.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/power/pm.h>
+#include <nuttx/semaphore.h>
+#include <nuttx/efuse/efuse.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Type Definitions
+ ****************************************************************************/
+
+/* This structure describes the state of the upper half driver */
+
+struct efuse_upperhalf_s
+{
+  sem_t     exclsem;  /* Supports mutual exclusion */
+  FAR char *path;     /* Registration path */
+
+  /* The contained lower-half driver */
+
+  FAR struct efuse_lowerhalf_s *lower;
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int     efuse_open(FAR struct file *filep);
+static int     efuse_close(FAR struct file *filep);
+static ssize_t efuse_read(FAR struct file *filep, FAR char *buffer,
+                          size_t buflen);
+static ssize_t efuse_write(FAR struct file *filep, FAR const char *buffer,
+                           size_t buflen);
+static int     efuse_ioctl(FAR struct file *filep, int cmd,
+                 unsigned long arg);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct file_operations g_efuseops =
+{
+  efuse_open,  /* open */
+  efuse_close, /* close */
+  efuse_read,  /* read */
+  efuse_write, /* write */
+  NULL,        /* seek */
+  efuse_ioctl, /* ioctl */
+  NULL         /* poll */
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: efuse_open
+ *
+ * Description:
+ *   This function is called whenever the efuse timer device is opened.
+ *
+ ****************************************************************************/
+
+static int efuse_open(FAR struct file *filep)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: efuse_close
+ *
+ * Description:
+ *   This function is called when the efuse timer device is closed.
+ *
+ ****************************************************************************/
+
+static int efuse_close(FAR struct file *filep)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: efuse_read
+ *
+ * Description:
+ *   A dummy read method.  This is provided only to satisfy the VFS layer.
+ *
+ ****************************************************************************/
+
+static ssize_t efuse_read(FAR struct file *filep, FAR char *buffer,
+                         size_t buflen)
+{
+  /* Return zero -- usually meaning end-of-file */
+
+  return 0;
+}
+
+/****************************************************************************
+ * Name: efuse_write
+ *
+ * Description:
+ *   A dummy write method.  This is provided only to satisfy the VFS layer.
+ *
+ ****************************************************************************/
+
+static ssize_t efuse_write(FAR struct file *filep, FAR const char *buffer,
+                          size_t buflen)
+{
+  return 0;
+}
+
+/****************************************************************************
+ * Name: efuse_ioctl
+ *
+ * Description:
+ *   The standard ioctl method.  This is where ALL of the efuse timer
+ *   work is done.
+ *
+ ****************************************************************************/
+
+static int efuse_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
+{
+  FAR struct inode             *inode = filep->f_inode;
+  FAR struct efuse_upperhalf_s *upper;
+  FAR struct efuse_lowerhalf_s *lower;
+  int                           ret;
+
+  minfo("cmd: %d arg: %ld\n", cmd, arg);
+  upper = inode->i_private;
+  DEBUGASSERT(upper != NULL);
+  lower = upper->lower;
+  DEBUGASSERT(lower != NULL);
+
+  /* Get exclusive access to the device structures */
+
+  ret = nxsem_wait(&upper->exclsem);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  /* Handle built-in ioctl commands */
+
+  switch (cmd)
+    {
+    /* cmd:         EFUSEIOC_READ_FIELD_BIT
+     * Description: Read a single bit efuse
+     * Argument:    Return variable
+     */
+
+    case EFUSEIOC_READ_FIELD_BIT:
+      {
+        FAR struct efuse_par_id *param =
+                   (FAR struct efuse_par_id *)((uintptr_t)arg);
+
+        /* Read the efuse */
+
+        DEBUGASSERT(lower->ops->read_bit); /* Required */
+        ret = lower->ops->read_bit(lower,
+                                   (const efuse_desc_t **) param->field,
+                                   param->data);
+      }
+      break;
+
+    /* cmd:         EFUSEIOC_WRITE_FIELD_BIT
+     * Description: Write a single bit efuse
+     * Argument:    - efuse ID name
+     *              - value to written (0 or 1)
+     */
+
+    case EFUSEIOC_WRITE_FIELD_BIT:
+      {
+        FAR struct efuse_par_id *param =
+                   (FAR struct efuse_par_id *)((uintptr_t)arg);
+
+        /* Write the efuse */
+
+        DEBUGASSERT(lower->ops->write_bit); /* Required */
+        ret = lower->ops->write_bit(lower,
+                                    (const efuse_desc_t **) param->field,
+                                    *param->data);
+      }
+      break;
+
+    /* cmd:         EFUSEIOC_READ_FIELD_BLOB
+     * Description: Read a blob of N bits from efuse.
+     * Argument:    - efuse_id
+     *              - offset
+     *              - nbits
+     */
+
+    case EFUSEIOC_READ_FIELD_BLOB:
+      {
+        FAR struct efuse_par_id *param;
+
+        /* Read a blob from EFUSEs */
+
+        if (lower->ops->read_blob) /* Optional */
+          {
+            param = (FAR struct efuse_par_id *)((uintptr_t)arg);
+            if (param)
+              {
+                ret = lower->ops->read_blob(lower,
+                                            (const efuse_desc_t **)
+                                              param->field,
+                                            param->data,
+                                            param->size);
+              }
+            else
+              {
+                ret = -EINVAL;
+              }
+          }
+        else
+          {
+            ret = -ENOSYS;
+          }
+      }
+      break;
+
+    /* cmd:         EFUSEIOC_WRITE_FIELD_BLOB
+     * Description: Write a blob of N bits to efuse.
+     * Argument:    - efuse_id
+     *              - blob_bits
+     *              - offset
+     *              - nbits
+     */
+
+    case EFUSEIOC_WRITE_FIELD_BLOB:
+      {
+        FAR struct efuse_par_id *param;
+
+        /* Write a blob to EFUSEs */
+
+        if (lower->ops->write_blob) /* Optional */
+          {
+            param = (FAR struct efuse_par_id *)((uintptr_t)arg);
+            if (param)
+              {
+                ret = lower->ops->write_blob(lower,
+                                             (const efuse_desc_t **)
+                                               param->field,
+                                             param->data,
+                                             param->size);
+              }
+            else
+              {
+                ret = -EINVAL;
+              }
+          }
+        else
+          {
+            ret = -ENOSYS;
+          }
+      }
+      break;
+
+    /* cmd:         EFUSEIOC_READ_REG
+     * Description: Read a 32-bit efuse register
+     * Argument:    - efuse_reg.
+     */
+
+    case EFUSEIOC_READ_REG:
+      {
+        FAR struct efuse_par *param;
+
+        DEBUGASSERT(param != NULL);
+
+        /* Read 32 efuses at once */
+
+        if (lower->ops->read_reg) /* Optional */
+          {
+            param = (FAR struct efuse_par *)((uintptr_t)arg);
+            if (param)
+              {
+                ret = lower->ops->read_reg(lower, param->block,
+                                           param->reg,
+                                           (uint32_t *) param->data);
+              }
+            else
+              {
+                ret = -EINVAL;
+              }
+          }
+        else
+          {
+            ret = -ENOSYS;
+          }
+      }
+      break;
+
+    /* cmd:         EFUSEIOC_WRITE_REG
+     * Description: Read a 32-bits efuses (register block).
+     * Argument:    - efuse_reg
+     *              - efuse_value
+     */
+
+    case EFUSEIOC_WRITE_REG:
+      {
+        FAR struct efuse_par *param;
+
+        /* Write 32 EFUSEs at once */
+
+        if (lower->ops->write_reg) /* Optional */
+          {
+            param = (FAR struct efuse_par *)((uintptr_t)arg);
+            if (param)
+              {
+                lower->ops->write_reg(lower, param->block,
+                                      param->reg, *param->data);
+              }
+            else
+              {
+                ret = -EINVAL;
+              }
+          }
+        else
+          {
+            ret = -ENOSYS;
+          }
+      }
+      break;
+
+    default:
+      {
+        minfo("Forwarding unrecognized cmd: %d arg: %ld\n", cmd, arg);
+
+        /* An ioctl commands that are not recognized by the "upper-half"
+         * driver are forwarded to the lower half driver through this
+         * method.
+         */
+
+        if (lower->ops->ioctl) /* Optional */
+          {
+            ret = lower->ops->ioctl(lower, cmd, arg);
+          }
+        else
+          {
+            ret = -ENOTTY;
+          }
+      }
+      break;
+    }
+
+  nxsem_post(&upper->exclsem);
+  return ret;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: efuse_register
+ *
+ * Description:
+ *   This function binds an instance of a "lower half" efuse driver with
+ *   the "upper half" efuse device and registers that device so that can
+ *   be usedby application code.
+ *
+ * Input Parameters:
+ *   dev path - The full path to the driver to be registers in the NuttX

Review comment:
       ```suggestion
    *   dev path - The full path to the driver to be registered in the NuttX
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] acassis commented on a change in pull request #2628: Add generic efuse driver for NuttX

Posted by GitBox <gi...@apache.org>.
acassis commented on a change in pull request #2628:
URL: https://github.com/apache/incubator-nuttx/pull/2628#discussion_r556720908



##########
File path: include/nuttx/efuse/efuse.h
##########
@@ -0,0 +1,155 @@
+/****************************************************************************
+ * include/nuttx/efuse/efuse.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_EFUSE_EFUSE_H
+#define __INCLUDE_NUTTX_EFUSE_EFUSE_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs/ioctl.h>
+
+#include <signal.h>
+#include <stdint.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Command:     EFUSEIOC_READ_FIELD
+ * Description: Read a blob of bits from an efuse field.
+ * Arguments:   A structure containing the field[], a dst pointer, and size
+ *              of bits to be read from efuses.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD      _EFUSEIOC(0x0001)
+
+/* Command:     EFUSEIOC_WRITE_FIELD
+ * Description: Write a blob of bits to an efuse's field
+ * Arguments:   A structure containing the field[], the src memory and the
+ *              amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD     _EFUSEIOC(0x0002)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* Structure eFuse field */
+
+struct efuse_desc_s
+{
+  uint16_t   bit_offset; /* Bit offset related to beginning of efuse */
+  uint16_t   bit_count;  /* Length of bit field */
+};
+
+/* Type definition for an eFuse field */
+
+typedef struct efuse_desc_s efuse_desc_t;
+
+/* Structs with the parameters passed to the IOCTLs */
+
+struct efuse_param
+{
+  FAR const efuse_desc_t **field;
+  size_t  size;
+  FAR uint8_t *data;

Review comment:
       struct efuse_param param;
   param.field = ESP_EFUSE_CONSOLE_DEBUG_DISABLE;
   param.size = 8; /* Number of bits for this efuse field */
   param.data = malloc(param.size / 8 + 1);




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] saramonteiro commented on a change in pull request #2628: Add generic efuse driver for NuttX

Posted by GitBox <gi...@apache.org>.
saramonteiro commented on a change in pull request #2628:
URL: https://github.com/apache/incubator-nuttx/pull/2628#discussion_r555262007



##########
File path: drivers/efuse/efuse.c
##########
@@ -0,0 +1,377 @@
+/****************************************************************************
+ * drivers/efuse/efuse.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <string.h>
+#include <fcntl.h>
+#include <assert.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <nuttx/fs/fs.h>
+#include <nuttx/irq.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/power/pm.h>
+#include <nuttx/semaphore.h>
+#include <nuttx/efuse/efuse.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Type Definitions
+ ****************************************************************************/
+
+/* This structure describes the state of the upper half driver */
+
+struct efuse_upperhalf_s
+{
+  sem_t     exclsem;  /* Supports mutual exclusion */
+  FAR char *path;     /* Registration path */
+
+  /* The contained lower-half driver */
+
+  FAR struct efuse_lowerhalf_s *lower;
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int     efuse_open(FAR struct file *filep);
+static int     efuse_close(FAR struct file *filep);
+static ssize_t efuse_read(FAR struct file *filep, FAR char *buffer,
+                          size_t buflen);
+static ssize_t efuse_write(FAR struct file *filep, FAR const char *buffer,
+                           size_t buflen);
+static int     efuse_ioctl(FAR struct file *filep, int cmd,
+                 unsigned long arg);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct file_operations g_efuseops =
+{
+  efuse_open,  /* open */
+  efuse_close, /* close */
+  efuse_read,  /* read */
+  efuse_write, /* write */
+  NULL,        /* seek */
+  efuse_ioctl, /* ioctl */
+  NULL         /* poll */
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: efuse_open
+ *
+ * Description:
+ *   This function is called whenever the efuse timer device is opened.
+ *
+ ****************************************************************************/
+
+static int efuse_open(FAR struct file *filep)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: efuse_close
+ *
+ * Description:
+ *   This function is called when the efuse timer device is closed.
+ *
+ ****************************************************************************/
+
+static int efuse_close(FAR struct file *filep)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: efuse_read
+ *
+ * Description:
+ *   A dummy read method.  This is provided only to satisfy the VFS layer.
+ *
+ ****************************************************************************/
+
+static ssize_t efuse_read(FAR struct file *filep, FAR char *buffer,
+                         size_t buflen)
+{
+  /* Return zero -- usually meaning end-of-file */
+
+  return 0;
+}
+
+/****************************************************************************
+ * Name: efuse_write
+ *
+ * Description:
+ *   A dummy write method.  This is provided only to satisfy the VFS layer.
+ *
+ ****************************************************************************/
+
+static ssize_t efuse_write(FAR struct file *filep, FAR const char *buffer,
+                          size_t buflen)
+{
+  return 0;
+}
+
+/****************************************************************************
+ * Name: efuse_ioctl
+ *
+ * Description:
+ *   The standard ioctl method.  This is where ALL of the efuse timer
+ *   work is done.
+ *
+ ****************************************************************************/
+
+static int efuse_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
+{
+  FAR struct inode             *inode = filep->f_inode;
+  FAR struct efuse_upperhalf_s *upper;
+  FAR struct efuse_lowerhalf_s *lower;
+  int                           ret;
+
+  minfo("cmd: %d arg: %ld\n", cmd, arg);
+  upper = inode->i_private;
+  DEBUGASSERT(upper != NULL);
+  lower = upper->lower;
+  DEBUGASSERT(lower != NULL);
+
+  /* Get exclusive access to the device structures */
+
+  ret = nxsem_wait(&upper->exclsem);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  /* Handle built-in ioctl commands */
+
+  switch (cmd)
+    {
+    /* cmd:         EFUSEIOC_READ_FIELD_BIT
+     * Description: Read a single bit efuse
+     * Argument:    Return variable
+     */
+
+    case EFUSEIOC_READ_FIELD:
+      {
+        FAR struct efuse_param *param =
+                   (FAR struct efuse_param *)((uintptr_t)arg);
+
+        /* Read the efuse */
+
+        DEBUGASSERT(lower->ops->read_bit); /* Required */
+        ret = lower->ops->read_field(lower,
+                                     (const efuse_desc_t **) param->field,
+                                     param->data,
+                                     param->size);
+      }
+      break;
+
+    /* cmd:         EFUSEIOC_WRITE_FIELD_BIT
+     * Description: Write a single bit efuse
+     * Argument:    - efuse ID name
+     *              - value to written (0 or 1)
+     */

Review comment:
       ```suggestion
       /* cmd:         EFUSEIOC_WRITE_FIELD
        * Description: Write a field
        * Argument: A pointer to a struct efuse_param. 
        *                  Where the field is an array.
        *                  Each item in the array is a pointer to an efuse_desc_t 
        *                  variable.
        *                  An efuse_desc_t variable contains an offset to a field
        *                  or subfield and its size in bits.  
        *                 The size param is a redundancy, and it is the sum 
        *                 of all subfields sizes from efuse_desc_t in bits.
        *                 The data is a pointer to a pre-allocated space
        *                 where the user wrote the value that he wants
        *                 to write in a field or subfield.
        */
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] acassis commented on a change in pull request #2628: Add generic efuse driver for NuttX

Posted by GitBox <gi...@apache.org>.
acassis commented on a change in pull request #2628:
URL: https://github.com/apache/incubator-nuttx/pull/2628#discussion_r555968294



##########
File path: include/nuttx/efuse/efuse.h
##########
@@ -0,0 +1,155 @@
+/****************************************************************************
+ * include/nuttx/efuse/efuse.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_EFUSE_EFUSE_H
+#define __INCLUDE_NUTTX_EFUSE_EFUSE_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs/ioctl.h>
+
+#include <signal.h>
+#include <stdint.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Command:     EFUSEIOC_READ_FIELD
+ * Description: Read a blob of bits from an efuse field.
+ * Arguments:   A structure containing the field[], a dst pointer, and size
+ *              of bits to be read from efuses.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD      _EFUSEIOC(0x0001)
+
+/* Command:     EFUSEIOC_WRITE_FIELD
+ * Description: Write a blob of bits to an efuse's field
+ * Arguments:   A structure containing the field[], the src memory and the
+ *              amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD     _EFUSEIOC(0x0002)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* Structure eFuse field */
+
+struct efuse_desc_s
+{
+  uint16_t   bit_offset;     /* Bit offset related to beginning of efuse */
+  uint16_t   bit_count;      /* Length of bit field */
+};
+
+/* Type definition for an eFuse field */
+
+typedef struct efuse_desc_s efuse_desc_t;
+
+/* Structs with the parameters passed to the IOCTLs */
+
+struct efuse_param
+{
+  efuse_desc_t **field;
+  size_t  size;
+  uint8_t *data;
+};
+
+/* This structure provides the "lower-half" driver operations available to
+ * the "upper-half" driver.
+ */
+
+struct efuse_lowerhalf_s;
+struct efuse_ops_s
+{
+  /* Required methods *******************************************************/
+
+  /* Read an EFUSE bit */
+
+  CODE int (*read_field)(FAR struct efuse_lowerhalf_s *lower,
+                         const efuse_desc_t *field[],
+                         uint8_t *data, size_t bit_size);

Review comment:
       It's described in the efuse.c driver, just above EFUSEIOC_READ_FIELD and EFUSEIOC_WRITE_FIELD




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] saramonteiro commented on a change in pull request #2628: Add generic efuse driver for NuttX

Posted by GitBox <gi...@apache.org>.
saramonteiro commented on a change in pull request #2628:
URL: https://github.com/apache/incubator-nuttx/pull/2628#discussion_r554079668



##########
File path: drivers/efuse/efuse.c
##########
@@ -0,0 +1,514 @@
+/****************************************************************************
+ * drivers/efuse/efuse.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <string.h>
+#include <fcntl.h>
+#include <assert.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <nuttx/fs/fs.h>
+#include <nuttx/irq.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/power/pm.h>
+#include <nuttx/semaphore.h>
+#include <nuttx/efuse/efuse.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Type Definitions
+ ****************************************************************************/
+
+/* This structure describes the state of the upper half driver */
+
+struct efuse_upperhalf_s
+{
+  sem_t     exclsem;  /* Supports mutual exclusion */
+  FAR char *path;     /* Registration path */
+
+  /* The contained lower-half driver */
+
+  FAR struct efuse_lowerhalf_s *lower;
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int     efuse_open(FAR struct file *filep);
+static int     efuse_close(FAR struct file *filep);
+static ssize_t efuse_read(FAR struct file *filep, FAR char *buffer,
+                          size_t buflen);
+static ssize_t efuse_write(FAR struct file *filep, FAR const char *buffer,
+                           size_t buflen);
+static int     efuse_ioctl(FAR struct file *filep, int cmd,
+                 unsigned long arg);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct file_operations g_efuseops =
+{
+  efuse_open,  /* open */
+  efuse_close, /* close */
+  efuse_read,  /* read */
+  efuse_write, /* write */
+  NULL,        /* seek */
+  efuse_ioctl, /* ioctl */
+  NULL         /* poll */
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: efuse_open
+ *
+ * Description:
+ *   This function is called whenever the efuse timer device is opened.
+ *
+ ****************************************************************************/
+
+static int efuse_open(FAR struct file *filep)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: efuse_close
+ *
+ * Description:
+ *   This function is called when the efuse timer device is closed.
+ *
+ ****************************************************************************/
+
+static int efuse_close(FAR struct file *filep)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: efuse_read
+ *
+ * Description:
+ *   A dummy read method.  This is provided only to satisfy the VFS layer.
+ *
+ ****************************************************************************/
+
+static ssize_t efuse_read(FAR struct file *filep, FAR char *buffer,
+                         size_t buflen)
+{
+  /* Return zero -- usually meaning end-of-file */
+
+  return 0;
+}
+
+/****************************************************************************
+ * Name: efuse_write
+ *
+ * Description:
+ *   A dummy write method.  This is provided only to satisfy the VFS layer.
+ *
+ ****************************************************************************/
+
+static ssize_t efuse_write(FAR struct file *filep, FAR const char *buffer,
+                          size_t buflen)
+{
+  return 0;
+}
+
+/****************************************************************************
+ * Name: efuse_ioctl
+ *
+ * Description:
+ *   The standard ioctl method.  This is where ALL of the efuse timer
+ *   work is done.
+ *
+ ****************************************************************************/
+
+static int efuse_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
+{
+  FAR struct inode             *inode = filep->f_inode;
+  FAR struct efuse_upperhalf_s *upper;
+  FAR struct efuse_lowerhalf_s *lower;
+  int                           ret;
+
+  minfo("cmd: %d arg: %ld\n", cmd, arg);
+  upper = inode->i_private;
+  DEBUGASSERT(upper != NULL);
+  lower = upper->lower;
+  DEBUGASSERT(lower != NULL);
+
+  /* Get exclusive access to the device structures */
+
+  ret = nxsem_wait(&upper->exclsem);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  /* Handle built-in ioctl commands */
+
+  switch (cmd)
+    {
+    /* cmd:         EFUSEIOC_READ_FIELD_BIT
+     * Description: Read a single bit efuse
+     * Argument:    Return variable
+     */
+
+    case EFUSEIOC_READ_FIELD_BIT:
+      {
+        FAR struct efuse_par_id *param =
+                   (FAR struct efuse_par_id *)((uintptr_t)arg);
+
+        /* Read the efuse */
+
+        DEBUGASSERT(lower->ops->read_bit); /* Required */
+        ret = lower->ops->read_bit(lower,
+                                   (const efuse_desc_t **) param->field,
+                                   param->data);
+      }
+      break;
+
+    /* cmd:         EFUSEIOC_WRITE_FIELD_BIT
+     * Description: Write a single bit efuse
+     * Argument:    - efuse ID name
+     *              - value to written (0 or 1)
+     */
+
+    case EFUSEIOC_WRITE_FIELD_BIT:
+      {
+        FAR struct efuse_par_id *param =
+                   (FAR struct efuse_par_id *)((uintptr_t)arg);
+
+        /* Write the efuse */
+
+        DEBUGASSERT(lower->ops->write_bit); /* Required */
+        ret = lower->ops->write_bit(lower,
+                                    (const efuse_desc_t **) param->field,
+                                    *param->data);
+      }
+      break;
+
+    /* cmd:         EFUSEIOC_READ_FIELD_BLOB
+     * Description: Read a blob of N bits from efuse.
+     * Argument:    - efuse_id
+     *              - offset
+     *              - nbits
+     */
+
+    case EFUSEIOC_READ_FIELD_BLOB:
+      {
+        FAR struct efuse_par_id *param;
+
+        /* Read a blob from EFUSEs */
+
+        if (lower->ops->read_blob) /* Optional */
+          {
+            param = (FAR struct efuse_par_id *)((uintptr_t)arg);
+            if (param)
+              {
+                ret = lower->ops->read_blob(lower,
+                                            (const efuse_desc_t **)
+                                              param->field,
+                                            param->data,
+                                            param->size);
+              }
+            else
+              {
+                ret = -EINVAL;
+              }
+          }
+        else
+          {
+            ret = -ENOSYS;
+          }
+      }
+      break;
+
+    /* cmd:         EFUSEIOC_WRITE_FIELD_BLOB
+     * Description: Write a blob of N bits to efuse.
+     * Argument:    - efuse_id
+     *              - blob_bits
+     *              - offset
+     *              - nbits
+     */
+
+    case EFUSEIOC_WRITE_FIELD_BLOB:
+      {
+        FAR struct efuse_par_id *param;
+
+        /* Write a blob to EFUSEs */
+
+        if (lower->ops->write_blob) /* Optional */
+          {
+            param = (FAR struct efuse_par_id *)((uintptr_t)arg);
+            if (param)
+              {
+                ret = lower->ops->write_blob(lower,
+                                             (const efuse_desc_t **)
+                                               param->field,
+                                             param->data,
+                                             param->size);
+              }
+            else
+              {
+                ret = -EINVAL;
+              }
+          }
+        else
+          {
+            ret = -ENOSYS;
+          }
+      }
+      break;
+
+    /* cmd:         EFUSEIOC_READ_REG
+     * Description: Read a 32-bit efuse register
+     * Argument:    - efuse_reg.
+     */
+
+    case EFUSEIOC_READ_REG:
+      {
+        FAR struct efuse_par *param;
+
+        DEBUGASSERT(param != NULL);
+
+        /* Read 32 efuses at once */
+
+        if (lower->ops->read_reg) /* Optional */
+          {
+            param = (FAR struct efuse_par *)((uintptr_t)arg);
+            if (param)
+              {
+                ret = lower->ops->read_reg(lower, param->block,
+                                           param->reg,
+                                           (uint32_t *) param->data);
+              }
+            else
+              {
+                ret = -EINVAL;
+              }
+          }
+        else
+          {
+            ret = -ENOSYS;
+          }
+      }
+      break;
+
+    /* cmd:         EFUSEIOC_WRITE_REG
+     * Description: Read a 32-bits efuses (register block).
+     * Argument:    - efuse_reg
+     *              - efuse_value
+     */
+
+    case EFUSEIOC_WRITE_REG:
+      {
+        FAR struct efuse_par *param;
+
+        /* Write 32 EFUSEs at once */
+
+        if (lower->ops->write_reg) /* Optional */
+          {
+            param = (FAR struct efuse_par *)((uintptr_t)arg);
+            if (param)
+              {
+                lower->ops->write_reg(lower, param->block,
+                                      param->reg, *param->data);
+              }
+            else
+              {
+                ret = -EINVAL;
+              }
+          }
+        else
+          {
+            ret = -ENOSYS;
+          }
+      }
+      break;
+
+    default:
+      {
+        minfo("Forwarding unrecognized cmd: %d arg: %ld\n", cmd, arg);
+
+        /* An ioctl commands that are not recognized by the "upper-half"
+         * driver are forwarded to the lower half driver through this
+         * method.
+         */
+
+        if (lower->ops->ioctl) /* Optional */
+          {
+            ret = lower->ops->ioctl(lower, cmd, arg);
+          }
+        else
+          {
+            ret = -ENOTTY;
+          }
+      }
+      break;
+    }
+
+  nxsem_post(&upper->exclsem);
+  return ret;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: efuse_register
+ *
+ * Description:
+ *   This function binds an instance of a "lower half" efuse driver with
+ *   the "upper half" efuse device and registers that device so that can
+ *   be usedby application code.

Review comment:
       ```suggestion
    *   be used by application code.
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] xiaoxiang781216 merged pull request #2628: Add generic efuse driver for NuttX

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 merged pull request #2628:
URL: https://github.com/apache/incubator-nuttx/pull/2628


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] acassis commented on a change in pull request #2628: Add generic efuse driver for NuttX

Posted by GitBox <gi...@apache.org>.
acassis commented on a change in pull request #2628:
URL: https://github.com/apache/incubator-nuttx/pull/2628#discussion_r557446171



##########
File path: include/nuttx/efuse/efuse.h
##########
@@ -0,0 +1,155 @@
+/****************************************************************************
+ * include/nuttx/efuse/efuse.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_EFUSE_EFUSE_H
+#define __INCLUDE_NUTTX_EFUSE_EFUSE_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs/ioctl.h>
+
+#include <signal.h>
+#include <stdint.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Command:     EFUSEIOC_READ_FIELD
+ * Description: Read a blob of bits from an efuse field.
+ * Arguments:   A structure containing the field[], a dst pointer, and size
+ *              of bits to be read from efuses.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD      _EFUSEIOC(0x0001)
+
+/* Command:     EFUSEIOC_WRITE_FIELD
+ * Description: Write a blob of bits to an efuse's field
+ * Arguments:   A structure containing the field[], the src memory and the
+ *              amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD     _EFUSEIOC(0x0002)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* Structure eFuse field */
+
+struct efuse_desc_s
+{
+  uint16_t   bit_offset; /* Bit offset related to beginning of efuse */
+  uint16_t   bit_count;  /* Length of bit field */
+};
+
+/* Type definition for an eFuse field */
+
+typedef struct efuse_desc_s efuse_desc_t;
+
+/* Structs with the parameters passed to the IOCTLs */
+
+struct efuse_param
+{
+  FAR const efuse_desc_t **field;
+  size_t  size;
+  FAR uint8_t *data;

Review comment:
       It is flexible because you can "mount" your 'data' with sub-fields pointing to different bits positions and sizes from efuse hardware map, although I never saw it exercised in the IDF code. Normally the use case is just linear efuse bits. I hope you got the idea!




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] acassis commented on a change in pull request #2628: Add generic efuse driver for NuttX

Posted by GitBox <gi...@apache.org>.
acassis commented on a change in pull request #2628:
URL: https://github.com/apache/incubator-nuttx/pull/2628#discussion_r556719578



##########
File path: include/nuttx/efuse/efuse.h
##########
@@ -0,0 +1,155 @@
+/****************************************************************************
+ * include/nuttx/efuse/efuse.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_EFUSE_EFUSE_H
+#define __INCLUDE_NUTTX_EFUSE_EFUSE_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs/ioctl.h>
+
+#include <signal.h>
+#include <stdint.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Command:     EFUSEIOC_READ_FIELD
+ * Description: Read a blob of bits from an efuse field.
+ * Arguments:   A structure containing the field[], a dst pointer, and size
+ *              of bits to be read from efuses.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD      _EFUSEIOC(0x0001)
+
+/* Command:     EFUSEIOC_WRITE_FIELD
+ * Description: Write a blob of bits to an efuse's field
+ * Arguments:   A structure containing the field[], the src memory and the
+ *              amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD     _EFUSEIOC(0x0002)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* Structure eFuse field */
+
+struct efuse_desc_s
+{
+  uint16_t   bit_offset; /* Bit offset related to beginning of efuse */
+  uint16_t   bit_count;  /* Length of bit field */
+};
+
+/* Type definition for an eFuse field */
+
+typedef struct efuse_desc_s efuse_desc_t;
+
+/* Structs with the parameters passed to the IOCTLs */
+
+struct efuse_param
+{
+  FAR const efuse_desc_t **field;

Review comment:
       The end of array contains a NULL. The arch lowerhalf will be very useful to understand it. I'll submit it just after this generic driver.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] acassis commented on a change in pull request #2628: Add generic efuse driver for NuttX

Posted by GitBox <gi...@apache.org>.
acassis commented on a change in pull request #2628:
URL: https://github.com/apache/incubator-nuttx/pull/2628#discussion_r556720908



##########
File path: include/nuttx/efuse/efuse.h
##########
@@ -0,0 +1,155 @@
+/****************************************************************************
+ * include/nuttx/efuse/efuse.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_EFUSE_EFUSE_H
+#define __INCLUDE_NUTTX_EFUSE_EFUSE_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs/ioctl.h>
+
+#include <signal.h>
+#include <stdint.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Command:     EFUSEIOC_READ_FIELD
+ * Description: Read a blob of bits from an efuse field.
+ * Arguments:   A structure containing the field[], a dst pointer, and size
+ *              of bits to be read from efuses.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD      _EFUSEIOC(0x0001)
+
+/* Command:     EFUSEIOC_WRITE_FIELD
+ * Description: Write a blob of bits to an efuse's field
+ * Arguments:   A structure containing the field[], the src memory and the
+ *              amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD     _EFUSEIOC(0x0002)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* Structure eFuse field */
+
+struct efuse_desc_s
+{
+  uint16_t   bit_offset; /* Bit offset related to beginning of efuse */
+  uint16_t   bit_count;  /* Length of bit field */
+};
+
+/* Type definition for an eFuse field */
+
+typedef struct efuse_desc_s efuse_desc_t;
+
+/* Structs with the parameters passed to the IOCTLs */
+
+struct efuse_param
+{
+  FAR const efuse_desc_t **field;
+  size_t  size;
+  FAR uint8_t *data;

Review comment:
       struct efuse_param param;
   param.field = ESP_EFUSE_CONSOLE_DEBUG_DISABLE;
   param.size = 8; /* Number of bits for this efuse field */
   param.data = malloc(param.size / 8 + 1);
   
   ret = ioctl(fd, EFUSEIOC_READ_FIELD, &param);
     if (ret < 0)
       {
         printf("Failed to run ioctl EFUSEIOC_READ_FIELD, error = %d!\n",
                errno);
         close(fd);
         return -EINVAL;
       }




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] saramonteiro commented on a change in pull request #2628: Add generic efuse driver for NuttX

Posted by GitBox <gi...@apache.org>.
saramonteiro commented on a change in pull request #2628:
URL: https://github.com/apache/incubator-nuttx/pull/2628#discussion_r555259328



##########
File path: drivers/efuse/efuse.c
##########
@@ -0,0 +1,377 @@
+/****************************************************************************
+ * drivers/efuse/efuse.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <string.h>
+#include <fcntl.h>
+#include <assert.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <nuttx/fs/fs.h>
+#include <nuttx/irq.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/power/pm.h>
+#include <nuttx/semaphore.h>
+#include <nuttx/efuse/efuse.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Type Definitions
+ ****************************************************************************/
+
+/* This structure describes the state of the upper half driver */
+
+struct efuse_upperhalf_s
+{
+  sem_t     exclsem;  /* Supports mutual exclusion */
+  FAR char *path;     /* Registration path */
+
+  /* The contained lower-half driver */
+
+  FAR struct efuse_lowerhalf_s *lower;
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int     efuse_open(FAR struct file *filep);
+static int     efuse_close(FAR struct file *filep);
+static ssize_t efuse_read(FAR struct file *filep, FAR char *buffer,
+                          size_t buflen);
+static ssize_t efuse_write(FAR struct file *filep, FAR const char *buffer,
+                           size_t buflen);
+static int     efuse_ioctl(FAR struct file *filep, int cmd,
+                 unsigned long arg);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct file_operations g_efuseops =
+{
+  efuse_open,  /* open */
+  efuse_close, /* close */
+  efuse_read,  /* read */
+  efuse_write, /* write */
+  NULL,        /* seek */
+  efuse_ioctl, /* ioctl */
+  NULL         /* poll */
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: efuse_open
+ *
+ * Description:
+ *   This function is called whenever the efuse timer device is opened.
+ *
+ ****************************************************************************/
+
+static int efuse_open(FAR struct file *filep)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: efuse_close
+ *
+ * Description:
+ *   This function is called when the efuse timer device is closed.
+ *
+ ****************************************************************************/
+
+static int efuse_close(FAR struct file *filep)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: efuse_read
+ *
+ * Description:
+ *   A dummy read method.  This is provided only to satisfy the VFS layer.
+ *
+ ****************************************************************************/
+
+static ssize_t efuse_read(FAR struct file *filep, FAR char *buffer,
+                         size_t buflen)
+{
+  /* Return zero -- usually meaning end-of-file */
+
+  return 0;
+}
+
+/****************************************************************************
+ * Name: efuse_write
+ *
+ * Description:
+ *   A dummy write method.  This is provided only to satisfy the VFS layer.
+ *
+ ****************************************************************************/
+
+static ssize_t efuse_write(FAR struct file *filep, FAR const char *buffer,
+                          size_t buflen)
+{
+  return 0;
+}
+
+/****************************************************************************
+ * Name: efuse_ioctl
+ *
+ * Description:
+ *   The standard ioctl method.  This is where ALL of the efuse timer
+ *   work is done.
+ *
+ ****************************************************************************/
+
+static int efuse_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
+{
+  FAR struct inode             *inode = filep->f_inode;
+  FAR struct efuse_upperhalf_s *upper;
+  FAR struct efuse_lowerhalf_s *lower;
+  int                           ret;
+
+  minfo("cmd: %d arg: %ld\n", cmd, arg);
+  upper = inode->i_private;
+  DEBUGASSERT(upper != NULL);
+  lower = upper->lower;
+  DEBUGASSERT(lower != NULL);
+
+  /* Get exclusive access to the device structures */
+
+  ret = nxsem_wait(&upper->exclsem);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  /* Handle built-in ioctl commands */
+
+  switch (cmd)
+    {
+    /* cmd:         EFUSEIOC_READ_FIELD_BIT
+     * Description: Read a single bit efuse
+     * Argument:    Return variable
+     */

Review comment:
       ```suggestion
       /* cmd:         EFUSEIOC_READ_FIELD
        * Description: Read a field
        * Argument: A pointer to a struct efuse_param. 
        *                  Where the field is an array.
        *                  Each item in the array is a pointer to an efuse_desc_t 
        *                  variable.
        *                  An efuse_desc_t variable contains an offset to a field
        *                  or subfield and its size in bits.  
        *                 The size param is a redundancy, and it is the sum 
        *                 of all subfields sizes from efuse_desc_t in bits.
        *                 The data is a pointer to a pre-allocated space
        *                 where the driver will load the data read from efuse.
        */
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a change in pull request #2628: Add generic efuse driver for NuttX

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on a change in pull request #2628:
URL: https://github.com/apache/incubator-nuttx/pull/2628#discussion_r557423365



##########
File path: include/nuttx/efuse/efuse.h
##########
@@ -0,0 +1,155 @@
+/****************************************************************************
+ * include/nuttx/efuse/efuse.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_EFUSE_EFUSE_H
+#define __INCLUDE_NUTTX_EFUSE_EFUSE_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs/ioctl.h>
+
+#include <signal.h>
+#include <stdint.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Command:     EFUSEIOC_READ_FIELD
+ * Description: Read a blob of bits from an efuse field.
+ * Arguments:   A structure containing the field[], a dst pointer, and size
+ *              of bits to be read from efuses.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD      _EFUSEIOC(0x0001)
+
+/* Command:     EFUSEIOC_WRITE_FIELD
+ * Description: Write a blob of bits to an efuse's field
+ * Arguments:   A structure containing the field[], the src memory and the
+ *              amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD     _EFUSEIOC(0x0002)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* Structure eFuse field */
+
+struct efuse_desc_s
+{
+  uint16_t   bit_offset; /* Bit offset related to beginning of efuse */
+  uint16_t   bit_count;  /* Length of bit field */
+};
+
+/* Type definition for an eFuse field */
+
+typedef struct efuse_desc_s efuse_desc_t;
+
+/* Structs with the parameters passed to the IOCTLs */
+
+struct efuse_param
+{
+  FAR const efuse_desc_t **field;
+  size_t  size;
+  FAR uint8_t *data;

Review comment:
       I am fine, but can you demo how two fields(bit size < 8) save into data, it's important to describe the layout clear to avoid the misunderstanding. BTW, please put the description to the header file too.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a change in pull request #2628: Add generic efuse driver for NuttX

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on a change in pull request #2628:
URL: https://github.com/apache/incubator-nuttx/pull/2628#discussion_r550415972



##########
File path: include/nuttx/efuse/efuse.h
##########
@@ -0,0 +1,294 @@
+/****************************************************************************
+ * include/nuttx/efuse/efuse.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_EFUSE_EFUSE_H
+#define __INCLUDE_NUTTX_EFUSE_EFUSE_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs/ioctl.h>
+
+#include <signal.h>
+#include <stdint.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Command:     EFUSEIOC_READ_FIELD_BLOB
+ * Description: Read a blob of bits from an efuse field.
+ * Arguments:   A structure containing the field[], a dst pointer, and size
+ *              of bits to be read from efuses.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD_BLOB      _EFUSEIOC(0x0001)
+
+/* Command:     EFUSEIOC_READ_FIELD_BIT
+ * Description: Read of state of an efuse bit.
+ * Arguments:   A structure containing the field to be read.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD_BIT       _EFUSEIOC(0x0002)
+
+/* Command:     EFUSEIOC_WRITE_FIELD_BLOB
+ * Description: Write a blob of bits to an efuse's field
+ * Arguments:   A structure containing the field[], the src memory and the
+ *              amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD_BLOB     _EFUSEIOC(0x0003)
+
+/* Command:     EFUSEIOC_WRITE_FIELD_BIT
+ * Description: Write a bit to an efuse (burn it).
+ * Arguments:   A structure containing bit field.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD_BIT      _EFUSEIOC(0x0004)
+
+/* Command:     EFUSEIOC_GET_FIELD_SIZE
+ * Description: Get the length of the field in bits.
+ * Arguments:   A structure containing the fields.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_GET_FIELD_SIZE       _EFUSEIOC(0x0005)
+
+/* Command:     EFUSEIOC_READ_REG
+ * Description: Read an efuse register.
+ * Arguments:   A structure containing the block number and the register to
+ *              be read.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_REG             _EFUSEIOC(0x0006)
+
+/* Command:     EFUSEIOC_WRITE_REG
+ * Description: Write an efuse register.
+ * Arguments:   A structure containing the block number, the register to
+ *              write and value to be written.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_REG            _EFUSEIOC(0x0007)
+
+/* Command:     EFUSEIOC_READ_BLOCK
+ * Description: Read a key from efuse's block.
+ * Arguments:   A structure containing the block number, the dst_key pointer,
+ *              the offset in bits and the amount of bits to read.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_BLOCK           _EFUSEIOC(0x0008)

Review comment:
       @acassis what's difference between field/bit and block/reg? can we unify the read/write interface into one?

##########
File path: include/nuttx/efuse/efuse.h
##########
@@ -0,0 +1,294 @@
+/****************************************************************************
+ * include/nuttx/efuse/efuse.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_EFUSE_EFUSE_H
+#define __INCLUDE_NUTTX_EFUSE_EFUSE_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs/ioctl.h>
+
+#include <signal.h>
+#include <stdint.h>
+
+#ifdef CONFIG_EFUSE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Command:     EFUSEIOC_READ_FIELD_BLOB
+ * Description: Read a blob of bits from an efuse field.
+ * Arguments:   A structure containing the field[], a dst pointer, and size
+ *              of bits to be read from efuses.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD_BLOB      _EFUSEIOC(0x0001)
+
+/* Command:     EFUSEIOC_READ_FIELD_BIT
+ * Description: Read of state of an efuse bit.
+ * Arguments:   A structure containing the field to be read.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_FIELD_BIT       _EFUSEIOC(0x0002)
+
+/* Command:     EFUSEIOC_WRITE_FIELD_BLOB
+ * Description: Write a blob of bits to an efuse's field
+ * Arguments:   A structure containing the field[], the src memory and the
+ *              amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD_BLOB     _EFUSEIOC(0x0003)
+
+/* Command:     EFUSEIOC_WRITE_FIELD_BIT
+ * Description: Write a bit to an efuse (burn it).
+ * Arguments:   A structure containing bit field.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_FIELD_BIT      _EFUSEIOC(0x0004)
+
+/* Command:     EFUSEIOC_GET_FIELD_SIZE
+ * Description: Get the length of the field in bits.
+ * Arguments:   A structure containing the fields.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_GET_FIELD_SIZE       _EFUSEIOC(0x0005)
+
+/* Command:     EFUSEIOC_READ_REG
+ * Description: Read an efuse register.
+ * Arguments:   A structure containing the block number and the register to
+ *              be read.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_REG             _EFUSEIOC(0x0006)
+
+/* Command:     EFUSEIOC_WRITE_REG
+ * Description: Write an efuse register.
+ * Arguments:   A structure containing the block number, the register to
+ *              write and value to be written.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_REG            _EFUSEIOC(0x0007)
+
+/* Command:     EFUSEIOC_READ_BLOCK
+ * Description: Read a key from efuse's block.
+ * Arguments:   A structure containing the block number, the dst_key pointer,
+ *              the offset in bits and the amount of bits to read.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_READ_BLOCK           _EFUSEIOC(0x0008)
+
+/* Command:     EFUSEIOC_WRITE_BLOCK
+ * Description: Write a key to efuse's block.
+ * Arguments:   A structure containing the block number, the src_key pointer,
+ *              the offset in bits and the amount of bits to write.
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_WRITE_BLOCK          _EFUSEIOC(0x0009)
+
+/* Command:     EFUSEIOC_BATCH_WRITE_BEGIN
+ * Description: Start a batch operation, the efuse bits will be burned after
+ *              a batch write commit operation.
+ * Arguments:   None
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_BATCH_WRITE_BEGIN    _EFUSEIOC(0x000a)
+
+/* Command:     EFUSEIOC_BATCH_WRITE_CANCEL
+ * Description: Cancel a started batch write operation in progress.
+ * Arguments:   None
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_BATCH_WRITE_CANCEL   _EFUSEIOC(0x000b)
+
+/* Command:     EFUSEIOC_BATCH_WRITE_COMMIT
+ * Description: Commit a batch operation that was in progress.
+ * Arguments:   None
+ * Return:      Zero (OK) on success.  Minus one will be returned on failure
+ *              with the errno value set appropriately.
+ */
+
+#define EFUSEIOC_BATCH_WRITE_COMMIT   _EFUSEIOC(0x000c)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* Structure eFuse field */
+
+struct efuse_desc_s
+{
+  uint16_t   efuse_block;    /* Block of eFuse */
+  uint16_t   bit_start;      /* Start bit [0..65535] */
+  uint16_t   bit_count;      /* Length of bit field [1..-] */
+};
+
+/* Type definition for an eFuse field */
+
+typedef struct efuse_desc_s efuse_desc_t;
+
+/* Structure range address by blocks */
+
+typedef struct
+{
+  uint32_t start;
+  uint32_t end;
+} efuse_range_addr_t;
+
+/* Structs with the parameters passed to the IOCTLs */
+
+struct efuse_par
+{
+  uint16_t block;
+  uint16_t reg;
+  size_t   bit_offset;
+  size_t   bit_size;
+  uint8_t *data;
+};
+
+struct efuse_par_id
+{
+  efuse_desc_t **field;
+  size_t  size;
+  uint8_t *data;
+};
+
+/* This structure provides the "lower-half" driver operations available to
+ * the "upper-half" driver.
+ */
+
+struct efuse_lowerhalf_s;
+struct efuse_ops_s
+{
+  /* Required methods *******************************************************/
+
+  /* Read an EFUSE bit */
+
+  CODE int (*read_bit)(FAR struct efuse_lowerhalf_s *lower,
+                       const efuse_desc_t *field[],

Review comment:
       why need an array of efuse_desc_t




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] xiaoxiang781216 commented on pull request #2628: Add generic efuse driver for NuttX

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on pull request #2628:
URL: https://github.com/apache/incubator-nuttx/pull/2628#issuecomment-760949883


   @acassis why not merge into one patch? it doesn't make sense to left the intermediate result in the history. 


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org