Skip to content

Commit

Permalink
mmcsd: support dump cid and csd with mmc-utils
Browse files Browse the repository at this point in the history
Signed-off-by: wanggang26 <[email protected]>
  • Loading branch information
wanggang26 committed Sep 21, 2023
1 parent b406a30 commit 6a1119c
Show file tree
Hide file tree
Showing 6 changed files with 613 additions and 41 deletions.
4 changes: 4 additions & 0 deletions drivers/mmcsd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,9 @@ if(CONFIG_MMCSD)
list(APPEND SRCS mmcsd_spi.c mmcsd_debug.c)
endif()

if(CONFIG_MMCSD_PROCFS)
list(APPEND SRCS mmcsd_procfs.c)
endif()

target_sources(drivers PRIVATE ${SRCS})
endif()
7 changes: 7 additions & 0 deletions drivers/mmcsd/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ config MMCSD_NSLOTS
Number of MMC/SD slots supported by the
driver. Default is one.

config MMCSD_PROCFS
bool "MMCSD proc fs support"
default n
depends on FS_PROCFS_REGISTER
---help---
Enable procfs for mmcsd.

config MMCSD_READONLY
bool "Disable MMC/SD write access"
default n
Expand Down
4 changes: 4 additions & 0 deletions drivers/mmcsd/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ ifeq ($(CONFIG_MMCSD_SPI),y)
CSRCS += mmcsd_spi.c mmcsd_debug.c
endif

ifeq ($(CONFIG_MMCSD_PROCFS),y)
CSRCS += mmcsd_procfs.c
endif

# Include MMC/SD driver build support

DEPPATH += --dep-path mmcsd
Expand Down
42 changes: 42 additions & 0 deletions drivers/mmcsd/mmcsd.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
****************************************************************************/

#include <nuttx/config.h>
#include <nuttx/sdio.h>
#include <stdint.h>
#include <debug.h>

Expand Down Expand Up @@ -59,6 +60,43 @@
* Public Types
****************************************************************************/

/* This structure is contains the unique state of the MMC/SD block driver */

struct mmcsd_state_s
{
FAR struct sdio_dev_s *dev; /* The SDIO device bound to this instance */
uint8_t crefs; /* Open references on the driver */
mutex_t lock; /* Assures mutually exclusive access to the slot */

/* Status flags */

uint8_t probed:1; /* true: mmcsd_probe() discovered a card */
uint8_t widebus:1; /* true: Wide 4-bit bus selected */
uint8_t mediachanged:1; /* true: Media changed since last check */
uint8_t wrbusy:1; /* true: Last transfer was a write, card may be busy */
uint8_t wrprotect:1; /* true: Card is write protected (from CSD) */
uint8_t locked:1; /* true: Media is locked (from R1) */
uint8_t dsrimp:1; /* true: card supports CMD4/DSR setting (from CSD) */
#ifdef CONFIG_SDIO_DMA
uint8_t dma:1; /* true: hardware supports DMA */
#endif

uint8_t mode:2; /* (See MMCSDMODE_* definitions) */
uint8_t type:4; /* Card type (See MMCSD_CARDTYPE_* definitions) */
uint8_t buswidth:4; /* Bus widths supported (SD only) */
sdio_capset_t caps; /* SDIO driver capabilities/limitations */
uint32_t cid[4]; /* CID register */
uint32_t csd[4]; /* CSD register */
uint16_t selblocklen; /* The currently selected block length */
uint16_t rca; /* Relative Card Address (RCS) register */

/* Memory card geometry (extracted from the CSD) */

uint8_t blockshift; /* Log2 of blocksize */
uint16_t blocksize; /* Read block length (== block size) */
uint32_t nblocks; /* Number of blocks */
};

/****************************************************************************
* Public Functions Definitions
****************************************************************************/
Expand All @@ -72,6 +110,10 @@ extern "C"
#define EXTERN extern
#endif

#ifdef CONFIG_MMCSD_PROCFS
void mmcsd_initialize_procfs(void);
#endif

#ifdef CONFIG_MMCSD_DUMPALL
# define mmcsd_dumpbuffer(m,b,l) finfodumpbuffer(m,b,l)
#else
Expand Down
Loading

0 comments on commit 6a1119c

Please sign in to comment.