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

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


The following commit(s) were added to refs/heads/master by this push:
     new 5d7864fbcb drivers/spi: add support for qspi hwfeatures
5d7864fbcb is described below

commit 5d7864fbcb38971938c90d2b2464bd1a57f34dc5
Author: rongyichang <[email protected]>
AuthorDate: Fri Mar 24 16:10:28 2023 +0800

    drivers/spi: add support for qspi hwfeatures
    
    add QSPI_BITORDER and QSPI_WORD_REVERSE hwfeatures
    
    Signed-off-by: rongyichang <[email protected]>
---
 arch/arm/src/nrf52/nrf52_qspi.c        |  3 ++
 arch/arm/src/nrf53/nrf53_qspi.c        |  3 ++
 arch/arm/src/s32k3xx/s32k3xx_qspi.c    |  3 ++
 arch/arm/src/samv7/sam_qspi.c          |  3 ++
 arch/arm/src/stm32f7/stm32_qspi.c      |  3 ++
 arch/arm/src/stm32h7/stm32_qspi.c      |  3 ++
 arch/arm/src/stm32l4/stm32l4_qspi.c    |  3 ++
 arch/xtensa/src/esp32s3/esp32s3_qspi.c |  6 ++++
 drivers/spi/Kconfig                    | 34 ++++++++++++++++++++++
 drivers/spi/qspi_flash.c               |  3 ++
 include/nuttx/spi/qspi.h               | 52 ++++++++++++++++++++++++++++++++++
 11 files changed, 116 insertions(+)

diff --git a/arch/arm/src/nrf52/nrf52_qspi.c b/arch/arm/src/nrf52/nrf52_qspi.c
index c95df57e26..3a4af11374 100644
--- a/arch/arm/src/nrf52/nrf52_qspi.c
+++ b/arch/arm/src/nrf52/nrf52_qspi.c
@@ -123,6 +123,9 @@ static const struct qspi_ops_s g_qspi_ops =
   .setfrequency      = nrf52_qspi_setfrequency,
   .setmode           = nrf52_qspi_setmode,
   .setbits           = nrf52_qspi_setbits,
+#ifdef CONFIG_QSPI_HWFEATURES
+  .hwfeatures        = NULL,
+#endif
   .command           = nrf52_qspi_command,
   .memory            = nrf52_qspi_memory,
   .alloc             = nrf52_qspi_alloc,
diff --git a/arch/arm/src/nrf53/nrf53_qspi.c b/arch/arm/src/nrf53/nrf53_qspi.c
index 7f06a96596..bece954af8 100644
--- a/arch/arm/src/nrf53/nrf53_qspi.c
+++ b/arch/arm/src/nrf53/nrf53_qspi.c
@@ -133,6 +133,9 @@ static const struct qspi_ops_s g_qspi_ops =
   .setfrequency      = nrf53_qspi_setfrequency,
   .setmode           = nrf53_qspi_setmode,
   .setbits           = nrf53_qspi_setbits,
+#ifdef CONFIG_QSPI_HWFEATURES
+  .hwfeatures        = NULL,
+#endif  
   .command           = nrf53_qspi_command,
   .memory            = nrf53_qspi_memory,
   .alloc             = nrf53_qspi_alloc,
diff --git a/arch/arm/src/s32k3xx/s32k3xx_qspi.c 
b/arch/arm/src/s32k3xx/s32k3xx_qspi.c
index 5a6ebcb9b7..e17166171a 100644
--- a/arch/arm/src/s32k3xx/s32k3xx_qspi.c
+++ b/arch/arm/src/s32k3xx/s32k3xx_qspi.c
@@ -210,6 +210,9 @@ static const struct qspi_ops_s g_qspi0ops =
   .setfrequency      = qspi_setfrequency,
   .setmode           = qspi_setmode,
   .setbits           = qspi_setbits,
+#ifdef CONFIG_QSPI_HWFEATURES
+  .hwfeatures        = NULL,
+#endif
   .command           = qspi_command,
   .memory            = qspi_memory,
   .alloc             = qspi_alloc,
diff --git a/arch/arm/src/samv7/sam_qspi.c b/arch/arm/src/samv7/sam_qspi.c
index 1c943340bd..5b666d2287 100644
--- a/arch/arm/src/samv7/sam_qspi.c
+++ b/arch/arm/src/samv7/sam_qspi.c
@@ -292,6 +292,9 @@ static const struct qspi_ops_s g_qspi0ops =
   .setfrequency      = qspi_setfrequency,
   .setmode           = qspi_setmode,
   .setbits           = qspi_setbits,
+#ifdef CONFIG_QSPI_HWFEATURES
+  .hwfeatures        = NULL,
+#endif
   .command           = qspi_command,
   .memory            = qspi_memory,
   .alloc             = qspi_alloc,
diff --git a/arch/arm/src/stm32f7/stm32_qspi.c 
b/arch/arm/src/stm32f7/stm32_qspi.c
index 08bb0643ac..9dfdaaf68e 100644
--- a/arch/arm/src/stm32f7/stm32_qspi.c
+++ b/arch/arm/src/stm32f7/stm32_qspi.c
@@ -325,6 +325,9 @@ static const struct qspi_ops_s g_qspi0ops =
   .setfrequency      = qspi_setfrequency,
   .setmode           = qspi_setmode,
   .setbits           = qspi_setbits,
+#ifdef CONFIG_QSPI_HWFEATURES
+  .hwfeatures        = NULL,
+#endif
   .command           = qspi_command,
   .memory            = qspi_memory,
   .alloc             = qspi_alloc,
diff --git a/arch/arm/src/stm32h7/stm32_qspi.c 
b/arch/arm/src/stm32h7/stm32_qspi.c
index 52f5261e6f..288766536d 100644
--- a/arch/arm/src/stm32h7/stm32_qspi.c
+++ b/arch/arm/src/stm32h7/stm32_qspi.c
@@ -350,6 +350,9 @@ static const struct qspi_ops_s g_qspi0ops =
   .setfrequency      = qspi_setfrequency,
   .setmode           = qspi_setmode,
   .setbits           = qspi_setbits,
+#ifdef CONFIG_QSPI_HWFEATURES
+  .hwfeatures        = NULL,
+#endif
   .command           = qspi_command,
   .memory            = qspi_memory,
   .alloc             = qspi_alloc,
diff --git a/arch/arm/src/stm32l4/stm32l4_qspi.c 
b/arch/arm/src/stm32l4/stm32l4_qspi.c
index 39b6655073..a6e228ccbc 100644
--- a/arch/arm/src/stm32l4/stm32l4_qspi.c
+++ b/arch/arm/src/stm32l4/stm32l4_qspi.c
@@ -323,6 +323,9 @@ static const struct qspi_ops_s g_qspi0ops =
   .setfrequency      = qspi_setfrequency,
   .setmode           = qspi_setmode,
   .setbits           = qspi_setbits,
+#ifdef CONFIG_QSPI_HWFEATURES
+  .hwfeatures        = NULL,
+#endif
   .command           = qspi_command,
   .memory            = qspi_memory,
   .alloc             = qspi_alloc,
diff --git a/arch/xtensa/src/esp32s3/esp32s3_qspi.c 
b/arch/xtensa/src/esp32s3/esp32s3_qspi.c
index 9ac7f1b655..1438522257 100644
--- a/arch/xtensa/src/esp32s3/esp32s3_qspi.c
+++ b/arch/xtensa/src/esp32s3/esp32s3_qspi.c
@@ -289,6 +289,9 @@ static const struct qspi_ops_s esp32s3_spi2_ops =
   .setfrequency = esp32s3_qspi_setfrequency,
   .setmode      = esp32s3_qspi_setmode,
   .setbits      = esp32s3_qspi_setbits,
+#ifdef CONFIG_QSPI_HWFEATURES
+  .hwfeatures   = NULL,
+#endif
   .command      = esp32s3_qspi_command,
   .memory       = esp32s3_qspi_memory,
   .alloc        = esp32s3_qspi_alloc,
@@ -379,6 +382,9 @@ static const struct qspi_ops_s esp32s3_spi3_ops =
   .setfrequency = esp32s3_qspi_setfrequency,
   .setmode      = esp32s3_qspi_setmode,
   .setbits      = esp32s3_qspi_setbits,
+#ifdef CONFIG_QSPI_HWFEATURES
+  .hwfeatures   = NULL,
+#endif
   .command      = esp32s3_qspi_command,
   .memory       = esp32s3_qspi_memory,
   .alloc        = esp32s3_qspi_alloc,
diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
index b305bca922..3395b63b60 100644
--- a/drivers/spi/Kconfig
+++ b/drivers/spi/Kconfig
@@ -15,6 +15,14 @@ config ARCH_HAVE_SPI_BITORDER
        bool
        default n
 
+config ARCH_HAVE_QSPI_BITORDER
+       bool
+       default n
+
+config ARCH_HAVE_QSPI_WORD_REVERSE
+       bool
+       default n
+
 menuconfig SPI
        bool "SPI Driver Support"
        default n
@@ -163,6 +171,32 @@ config SPI_BITORDER
                Enables capability to select MSB- or LSB-first hardware feature 
for
                data transfers.
 
+config QSPI_HWFEATURES
+       bool
+       default n
+       ---help---
+               Selected only if a specific H/W feature is selected.  This is
+               basically the OR of any specific hardware feature and enables
+               the QSPI hwfeatures() interface method.
+
+config QSPI_BITORDER
+       bool "QSPI Bit Order Control"
+       default n
+       select QSPI_HWFEATURES
+       depends on ARCH_HAVE_QSPI_BITORDER
+       ---help---
+               Enables capability to select MSB- or LSB-first hardware feature 
for
+               data transfers.
+
+config QSPI_WORD_REVERSE
+       bool "QSPI word reverse Control"
+       default n
+       select QSPI_HWFEATURES
+       depends on ARCH_HAVE_QSPI_WORD_REVERSE
+       ---help---
+               Enables capability to word reverse hardware feature for
+               data transfers.
+
 config SPI_DELAY_CONTROL
        bool "SPI Delay Control"
        default n
diff --git a/drivers/spi/qspi_flash.c b/drivers/spi/qspi_flash.c
index a5ca33ab47..2c8aa23e20 100644
--- a/drivers/spi/qspi_flash.c
+++ b/drivers/spi/qspi_flash.c
@@ -200,6 +200,9 @@ static const struct qspi_ops_s g_qspiops =
   qspi_flash_setfrequency,      /* setfrequency */
   qspi_flash_setmode,           /* setmode */
   qspi_flash_setbits,           /* setbits */
+#ifdef CONFIG_QSPI_HWFEATURES
+  NULL,                         /* hwfeatures */
+#endif
   qspi_flash_command,           /* command */
   qspi_flash_memory,            /* memory */
   qspi_flash_alloc,             /* alloc */
diff --git a/include/nuttx/spi/qspi.h b/include/nuttx/spi/qspi.h
index fd2de28e8b..469e3a1b3a 100644
--- a/include/nuttx/spi/qspi.h
+++ b/include/nuttx/spi/qspi.h
@@ -113,6 +113,48 @@
 
 #define QSPI_SETBITS(d,b) (d)->ops->setbits(d,b)
 
+/****************************************************************************
+ * Name: QSPI_HWFEATURES
+ *
+ * Description:
+ *   Set hardware-specific feature flags.
+ *
+ * Input Parameters:
+ *   dev      - Device-specific state data
+ *   features - H/W feature flags
+ *
+ * Returned Value:
+ *   Zero (OK) if the selected H/W features are enabled; A negated errno
+ *   value if any H/W feature is not supportable.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_QSPI_HWFEATURES
+  /* If there are multiple QSPI drivers, some may not support hardware
+   * feature selection.
+   */
+
+#  define QSPI_HWFEATURES(d,f) \
+  (((d)->ops->hwfeatures) ? (d)->ops->hwfeatures(d,f) : ((f) == 0 ? OK : 
-ENOSYS))
+
+#  ifdef CONFIG_QSPI_BITORDER
+#    define QSPI_HWFEAT_MSBFIRST                          (0 << 0)
+#    define QSPI_HWFEAT_LSBFIRST                          (1 << 0)
+#  endif
+
+#  ifdef CONFIG_QSPI_WORD_REVERSE
+#    define QSPI_HWFEAT_WORD_REVERSE_DISABLE              (0 << 1)
+#    define QSPI_HWFEAT_WORD_REVERSE_ENABLE               (1 << 1)
+#  endif
+
+#else
+  /* Any attempt to select hardware features with CONFIG_QSPI_HWFEATURES
+   * deselected will return an -ENOSYS error.
+   */
+
+#  define QSPI_HWFEATURES(d,f) (((f) == 0) ? OK : -ENOSYS)
+#endif
+
 /****************************************************************************
  * Name: QSPI_COMMAND
  *
@@ -260,6 +302,12 @@ struct qspi_meminfo_s
   FAR void *buffer;      /* Data buffer */
 };
 
+#ifdef CONFIG_QSPI_HWFEATURES
+/* This is a type wide enough to support all hardware features */
+
+typedef uint8_t qspi_hwfeatures_t;
+#endif
+
 /* The QSPI vtable */
 
 struct qspi_dev_s;
@@ -271,6 +319,10 @@ struct qspi_ops_s
   CODE void      (*setmode)(FAR struct qspi_dev_s *dev,
                     enum qspi_mode_e mode);
   CODE void      (*setbits)(FAR struct qspi_dev_s *dev, int nbits);
+#ifdef CONFIG_QSPI_HWFEATURES
+  CODE int       (*hwfeatures)(FAR struct qspi_dev_s *dev,
+                    qspi_hwfeatures_t features);
+#endif
   CODE int       (*command)(FAR struct qspi_dev_s *dev,
                     FAR struct qspi_cmdinfo_s *cmdinfo);
   CODE int       (*memory)(FAR struct qspi_dev_s *dev,

Reply via email to