You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2022/09/14 17:55:40 UTC

[incubator-nuttx] branch master updated: risc-v/mpfs: emmcsd: further enhance the clocking

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


The following commit(s) were added to refs/heads/master by this push:
     new ec026c14cb risc-v/mpfs: emmcsd: further enhance the clocking
ec026c14cb is described below

commit ec026c14cb6c440fcfdd0e41d52d5c38ec5ae4b5
Author: Eero Nurkkala <ee...@offcode.fi>
AuthorDate: Wed Sep 14 13:36:13 2022 +0300

    risc-v/mpfs: emmcsd: further enhance the clocking
    
    Simplify the clock mode from the board.h -files. Also make the
    SD clock definable as well.
    
    Co-authored-by: Petro Karashchenko <pe...@gmail.com>
    Signed-off-by: Eero Nurkkala <ee...@offcode.fi>
---
 arch/risc-v/src/mpfs/mpfs_emmcsd.c            | 43 ++++++++++++++-------------
 boards/risc-v/mpfs/icicle/include/board.h     |  8 +++--
 boards/risc-v/mpfs/m100pfsevp/include/board.h |  8 +++--
 3 files changed, 35 insertions(+), 24 deletions(-)

diff --git a/arch/risc-v/src/mpfs/mpfs_emmcsd.c b/arch/risc-v/src/mpfs/mpfs_emmcsd.c
index eac7187629..91dbf1f9d4 100644
--- a/arch/risc-v/src/mpfs/mpfs_emmcsd.c
+++ b/arch/risc-v/src/mpfs/mpfs_emmcsd.c
@@ -147,6 +147,18 @@
 
 #define MPFS_EMMCSD_MODE_LEGACY            0x7u
 
+/* Provide default eMMC CLK_MODE if unset at board.h */
+
+#ifndef MPFS_EMMC_CLK_MODE
+#  define MPFS_EMMC_CLK_MODE MPFS_EMMCSD_MODE_HS200
+#endif
+
+/* Provide default SD-card 4bit clk if unset at board.h */
+
+#ifndef MPFS_SD_CLOCK_4BIT
+#  define MPFS_SD_CLOCK_4BIT MPFS_MMC_CLOCK_25MHZ
+#endif
+
 /* Define the Hardware FIFO size */
 
 #define FIFO_SIZE_IN_BYTES                 64
@@ -296,7 +308,7 @@ struct mpfs_dev_s
 
   const bool         emmc;            /* eMMC or SD */
   int                bus_voltage;     /* Bus voltage */
-  int                bus_speed;       /* eMMC Bus speed */
+  int                bus_mode;        /* eMMC Bus mode */
   bool               jumpers_3v3;     /* Jumper settings: 1v8 or 3v3 */
 
   /* Event support */
@@ -1485,7 +1497,6 @@ static bool mpfs_device_reset(struct sdio_dev_s *dev)
       /* Apply default HW settings */
 
       priv->bus_voltage = MPFS_EMMCSD_3_3V_BUS_VOLTAGE;
-      priv->bus_speed   = MPFS_EMMCSD_MODE_SDR;
       priv->jumpers_3v3 = true;
 
       mpfs_sdcard_init(priv);
@@ -1499,17 +1510,7 @@ static bool mpfs_device_reset(struct sdio_dev_s *dev)
 
       /* The following defines come from the board.h file */
 
-#if defined(MPFS_EMMC_CLK_200MHZ)
-      /* MMCSD_CMD6 with 0x03B90200u isn't used here.  It's just the clk. */
-
-      priv->bus_speed   = MPFS_EMMCSD_MODE_HS200;
-#elif defined(MPFS_EMMC_CLK_50MHZ)
-      /* MMCSD_CMD6 with argument 0x03B90100u isn't used here. */
-
-      priv->bus_speed   = MPFS_EMMCSD_MODE_SDR;
-#else
-      priv->bus_speed   = MPFS_EMMCSD_MODE_LEGACY;
-#endif
+      priv->bus_mode    = MPFS_EMMC_CLK_MODE;
 
       /* Apply proper IOMUX values for the eMMC. This is required especially
        * if this NuttX works as the system bootloader. Otherwise, it's
@@ -1652,9 +1653,9 @@ static bool mpfs_device_reset(struct sdio_dev_s *dev)
             break;
 
           case MPFS_EMMCSD_3_3V_BUS_VOLTAGE:
-            if ((priv->bus_speed != MPFS_EMMCSD_MODE_HS200) &&
-                (priv->bus_speed != MPFS_EMMCSD_MODE_HS400_ES) &&
-                (priv->bus_speed != MPFS_EMMCSD_MODE_HS400))
+            if ((priv->bus_mode != MPFS_EMMCSD_MODE_HS200) &&
+                (priv->bus_mode != MPFS_EMMCSD_MODE_HS400_ES) &&
+                (priv->bus_mode != MPFS_EMMCSD_MODE_HS400))
               {
                 mpfs_set_sdhost_power(priv,
                                       MPFS_EMMCSD_SRS10_3_3V_BUS_VOLTAGE);
@@ -1858,24 +1859,26 @@ static void mpfs_clock(struct sdio_dev_s *dev, enum sdio_clock_e rate)
     /* Enable normal MMC operation clocking */
 
     case CLOCK_MMC_TRANSFER:
-      if (priv->bus_speed == MPFS_EMMCSD_MODE_HS200)
+      if (priv->bus_mode == MPFS_EMMCSD_MODE_HS200)
         {
           clckr = MPFS_MMC_CLOCK_200MHZ;
         }
-      else if (priv->bus_speed == MPFS_EMMCSD_MODE_SDR)
+      else if (priv->bus_mode == MPFS_EMMCSD_MODE_SDR)
         {
           clckr = MPFS_MMC_CLOCK_50MHZ;
         }
       else
         {
-          clckr = MPFS_MMC_CLOCK_26MHZ;
+          /* 26 MHz may not be divided from 200 MHz */
+
+          clckr = MPFS_MMC_CLOCK_25MHZ;
         }
       break;
 
     /* SD normal operation clocking (wide 4-bit mode) */
 
     case CLOCK_SD_TRANSFER_4BIT:
-      clckr = MPFS_MMC_CLOCK_25MHZ;
+      clckr = MPFS_SD_CLOCK_4BIT;
       break;
 
     /* SD normal operation clocking (narrow 1-bit mode) */
diff --git a/boards/risc-v/mpfs/icicle/include/board.h b/boards/risc-v/mpfs/icicle/include/board.h
index ee9ecbbd88..a77ce71cd5 100644
--- a/boards/risc-v/mpfs/icicle/include/board.h
+++ b/boards/risc-v/mpfs/icicle/include/board.h
@@ -37,8 +37,12 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
-#if defined(CONFIG_MMCSD_MMCSUPPORT) && defined(CONFIG_MPFS_EMMCSD)
-#define MPFS_EMMC_CLK_200MHZ
+#ifdef CONFIG_MMCSD_MMCSUPPORT
+#  define MPFS_EMMC_CLK_MODE MPFS_EMMCSD_MODE_HS200
+#endif
+
+#ifdef CONFIG_MMCSD_SDIO
+#  define MPFS_SD_CLOCK_4BIT MPFS_MMC_CLOCK_25MHZ
 #endif
 
 /* Clocking TODO: */
diff --git a/boards/risc-v/mpfs/m100pfsevp/include/board.h b/boards/risc-v/mpfs/m100pfsevp/include/board.h
index 2b0ac5f516..b84d3a873a 100644
--- a/boards/risc-v/mpfs/m100pfsevp/include/board.h
+++ b/boards/risc-v/mpfs/m100pfsevp/include/board.h
@@ -37,8 +37,12 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
-#if defined(CONFIG_MMCSD_MMCSUPPORT) && defined(CONFIG_MPFS_EMMCSD)
-#define MPFS_EMMC_CLK_26MHZ
+#ifdef CONFIG_MMCSD_MMCSUPPORT
+#  define MPFS_EMMC_CLK_MODE MPFS_EMMCSD_MODE_SDR
+#endif
+
+#ifdef CONFIG_MMCSD_SDIO
+#  define MPFS_SD_CLOCK_4BIT MPFS_MMC_CLOCK_25MHZ
 #endif
 
 #ifdef CONFIG_MPFS_EMMCSD_MUX_GPIO