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/incubator-nuttx.git

commit 4dfd3c9160094823e9b7079d25634cfb33586f33
Author: Jani Paalijarvi <[email protected]>
AuthorDate: Thu Jul 1 13:03:26 2021 +0300

    arch/riscv: Add ARCH_HAVE_SPI_CS_CONTROL for mpfs
    
    Make it possible to override SPI CS function in board logic
    
    Co-authored-by: Jukka Laitinen <[email protected]>
---
 arch/risc-v/Kconfig             |  1 +
 arch/risc-v/src/mpfs/mpfs_spi.c | 84 ++++++++++++++++++++++++++++++++++++++---
 arch/risc-v/src/mpfs/mpfs_spi.h | 26 +++++++++++++
 3 files changed, 106 insertions(+), 5 deletions(-)

diff --git a/arch/risc-v/Kconfig b/arch/risc-v/Kconfig
index e8e812a..3543d3a 100644
--- a/arch/risc-v/Kconfig
+++ b/arch/risc-v/Kconfig
@@ -75,6 +75,7 @@ config ARCH_CHIP_MPFS
         select ARCH_RV64GC
         select ARCH_HAVE_MPU
         select ARCH_HAVE_RESET
+        select ARCH_HAVE_SPI_CS_CONTROL
         select ARCH_HAVE_PWM_MULTICHAN
         ---help---
                MicroChip Polarfire processor (RISC-V 64bit core with GCVX 
extensions).
diff --git a/arch/risc-v/src/mpfs/mpfs_spi.c b/arch/risc-v/src/mpfs/mpfs_spi.c
index e5f7ce8..ec63072 100644
--- a/arch/risc-v/src/mpfs/mpfs_spi.c
+++ b/arch/risc-v/src/mpfs/mpfs_spi.c
@@ -147,8 +147,10 @@ struct mpfs_spi_priv_s
 
 static int mpfs_spi_lock(struct spi_dev_s *dev, bool lock);
 
+#ifdef CONFIG_SPI_CS_CONTROL
 static void mpfs_spi_select(struct spi_dev_s *dev, uint32_t devid,
                             bool selected);
+#endif
 
 static uint32_t mpfs_spi_setfrequency(struct spi_dev_s *dev,
                                       uint32_t frequency);
@@ -188,10 +190,11 @@ static const struct mpfs_spi_config_s mpfs_spi_config =
     .use_irq  = true,
 };
 
-static const struct spi_ops_s mpfs_spi_ops =
+#ifdef CONFIG_MPFS_SPI0
+static const struct spi_ops_s mpfs_spi0_ops =
 {
     .lock             = mpfs_spi_lock,
-    .select           = mpfs_spi_select,
+    .select           = mpfs_spi0_select,
     .setfrequency     = mpfs_spi_setfrequency,
 #ifdef CONFIG_SPI_DELAY_CONTROL
     .setdelay         = mpfs_spi_setdelay,
@@ -218,12 +221,11 @@ static const struct spi_ops_s mpfs_spi_ops =
     .registercallback = NULL,
 };
 
-#ifdef CONFIG_MPFS_SPI0
 static struct mpfs_spi_priv_s g_mpfs_spi0_priv =
 {
   .spi_dev =
               {
-                .ops = &mpfs_spi_ops
+                .ops = &mpfs_spi0_ops
               },
   .config            = &mpfs_spi_config,
   .hw_base           = MPFS_SPI0_LO_BASE,
@@ -232,12 +234,42 @@ static struct mpfs_spi_priv_s g_mpfs_spi0_priv =
   .devid             = 0
 };
 #endif /* CONFIG_MPFS_SPI0 */
+
 #ifdef CONFIG_MPFS_SPI1
+static const struct spi_ops_s mpfs_spi1_ops =
+{
+    .lock             = mpfs_spi_lock,
+    .select           = mpfs_spi1_select,
+    .setfrequency     = mpfs_spi_setfrequency,
+#ifdef CONFIG_SPI_CS_DELAY_CONTROL
+    .setdelay         = mpfs_spi_setdelay,
+#endif
+    .setmode          = mpfs_spi_setmode,
+    .setbits          = mpfs_spi_setbits,
+#ifdef CONFIG_SPI_HWFEATURES
+    .hwfeatures       = mpfs_spi_hwfeatures,
+#endif
+    .status           = mpfs_spi_status,
+#ifdef CONFIG_SPI_CMDDATA
+    .cmddata          = mpfs_spi_cmddata,
+#endif
+    .send             = mpfs_spi_send,
+#ifdef CONFIG_SPI_EXCHANGE
+    .exchange         = mpfs_spi_exchange,
+#else
+    .sndblock         = mpfs_spi_sndblock,
+    .recvblock        = mpfs_spi_recvblock,
+#endif
+#ifdef CONFIG_SPI_TRIGGER
+    .trigger          = mpfs_spi_trigger,
+#endif
+    .registercallback = NULL,
+};
 static struct mpfs_spi_priv_s g_mpfs_spi1_priv =
 {
   .spi_dev =
               {
-                .ops = &mpfs_spi_ops
+                .ops = &mpfs_spi1_ops
               },
   .config            = &mpfs_spi_config,
   .hw_base           = MPFS_SPI1_LO_BASE,
@@ -355,6 +387,7 @@ static int mpfs_spi_lock(struct spi_dev_s *dev, bool lock)
  *
  ****************************************************************************/
 
+#ifdef CONFIG_SPI_CS_CONTROL
 static void mpfs_spi_select(struct spi_dev_s *dev, uint32_t devid,
                             bool selected)
 {
@@ -373,6 +406,47 @@ static void mpfs_spi_select(struct spi_dev_s *dev, 
uint32_t devid,
 
   spiinfo("devid: %u, CS: %s\n", devid, selected ? "select" : "free");
 }
+#endif
+
+/****************************************************************************
+ * Name:  mpfs_spi0/1_select
+ *
+ * Description:
+ *   The external function, mpfs_spi0/1_select.
+ *
+ * Input Parameters:
+ *   dev -       Device-specific state data
+ *   devid - The SPI CS or device number
+ *   selected - true: assert CS, false de-assert CS
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_MPFS_SPI0
+void weak_function mpfs_spi0_select(FAR struct spi_dev_s *dev,
+                        uint32_t devid, bool selected)
+{
+#ifdef CONFIG_SPI_CS_CONTROL
+  mpfs_spi_select(dev, devid, selected);
+#else
+# warning "Missing logic"
+#endif
+}
+#endif /* CONFIG_MPFS_SPI0 */
+
+#ifdef CONFIG_MPFS_SPI1
+void weak_function mpfs_spi1_select(FAR struct spi_dev_s *dev,
+                        uint32_t devid, bool selected)
+{
+#ifdef CONFIG_SPI_CS_CONTROL
+  mpfs_spi_select(dev, devid, selected);
+#else
+# warning "Missing logic"
+#endif
+}
+#endif /* CONFIG_MPFS_SPI1 */
 
 /****************************************************************************
  * Name: mpfs_spi_setfrequency
diff --git a/arch/risc-v/src/mpfs/mpfs_spi.h b/arch/risc-v/src/mpfs/mpfs_spi.h
index f426ad2..ded78a4 100644
--- a/arch/risc-v/src/mpfs/mpfs_spi.h
+++ b/arch/risc-v/src/mpfs/mpfs_spi.h
@@ -75,6 +75,32 @@ struct spi_dev_s *mpfs_spibus_initialize(int port);
 
 int mpfs_spibus_uninitialize(struct spi_dev_s *dev);
 
+/****************************************************************************
+ * Name:  mpfs_spi0/1_select
+ *
+ * Description:
+ *   The external function, mpfs_spi0/1_select
+ *
+ * Input Parameters:
+ *   dev -       Device-specific state data
+ *   devid - The SPI CS or device number
+ *   selected - true: assert CS, false de-assert CS
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_MPFS_SPI0
+void weak_function mpfs_spi0_select(FAR struct spi_dev_s *dev,
+                        uint32_t devid, bool selected);
+#endif
+
+#ifdef CONFIG_MPFS_SPI1
+void weak_function mpfs_spi1_select(FAR struct spi_dev_s *dev,
+                        uint32_t devid, bool selected);
+#endif
+
 #ifdef __cplusplus
 }
 #endif

Reply via email to