Skip to content

Commit

Permalink
wrapper to sdio device drivers
Browse files Browse the repository at this point in the history
  • Loading branch information
Jari Nippula committed Jan 30, 2024
1 parent fa56e9e commit b6dcb2d
Show file tree
Hide file tree
Showing 9 changed files with 421 additions and 130 deletions.
4 changes: 4 additions & 0 deletions arch/risc-v/src/mpfs/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ ifeq ($(CONFIG_I2C),y)
CHIP_CSRCS += mpfs_i2c.c
endif

ifneq ($(filter y,$(CONFIG_MPFS_EMMCSD) $(CONFIG_MPFS_COREMMC)),)
CHIP_CSRCS += mpfs_sdio.c
endif

ifeq ($(CONFIG_MPFS_EMMCSD),y)
CHIP_CSRCS += mpfs_emmcsd.c
endif
Expand Down
64 changes: 9 additions & 55 deletions arch/risc-v/src/mpfs/mpfs_coremmc.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@

#include <arch/board/board.h>

#include "mpfs_emmcsd.h"
#include "mpfs_coremmc.h"
#include "riscv_internal.h"
#include "hardware/mpfs_coremmc.h"

#include "mpfs_sdio_dev.h"

/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
Expand Down Expand Up @@ -158,54 +160,6 @@
* Private Types
****************************************************************************/

/* This structure defines the state of the MPFS eMMCSD interface */

struct mpfs_dev_s
{
struct sdio_dev_s dev; /* Standard, base SDIO interface */

const uintptr_t hw_base; /* Base address */
const int plic_irq; /* PLIC interrupt */
bool clk_enabled; /* Clk state */

/* Event support */

sem_t waitsem; /* Implements event waiting */
sdio_eventset_t waitevents; /* Set of events to be waited for */
uint32_t waitmask; /* Interrupt enables for event waiting */
volatile sdio_eventset_t wkupevent; /* The event that caused the wakeup */
struct wdog_s waitwdog; /* Watchdog that handles event timeouts */

/* Callback support */

sdio_statset_t cdstatus; /* Card status */
sdio_eventset_t cbevents; /* Set of events to be cause callbacks */
worker_t callback; /* Registered callback function */
void *cbarg; /* Registered callback argument */
struct work_s cbwork; /* Callback work queue structure */

/* Interrupt mode data transfer support */

uint32_t *buffer; /* Address of current R/W buffer */
size_t remaining; /* Number of bytes remaining in the transfer */
size_t receivecnt; /* Real count to receive */
uint32_t xfrmask; /* Interrupt enables for data transfer */
uint32_t xfr_blkmask; /* Interrupt enables for SB/MB data transfer */

bool widebus; /* Required for DMA support */
bool onebit; /* true: Only 1-bit transfers are supported */

/* Data transfer support */

bool polltransfer; /* Indicate a poll transfer, no DMA */
bool multiblock; /* Indicate a multi-block transfer */

/* Misc */

uint32_t blocksize; /* Current block size */
uint32_t fifo_depth; /* Fifo size, read from the register */
};

union
{
uint32_t w;
Expand Down Expand Up @@ -2277,7 +2231,7 @@ static void mpfs_callback(void *arg)
****************************************************************************/

/****************************************************************************
* Name: sdio_initialize
* Name: mpfs_coremmc_sdio_initialize
*
* Description:
* Initialize SDIO for operation.
Expand All @@ -2291,7 +2245,7 @@ static void mpfs_callback(void *arg)
*
****************************************************************************/

struct sdio_dev_s *sdio_initialize(int slotno)
struct sdio_dev_s *mpfs_coremmc_sdio_initialize(int slotno)
{
struct mpfs_dev_s *priv = &g_coremmc_dev;

Expand All @@ -2308,7 +2262,7 @@ struct sdio_dev_s *sdio_initialize(int slotno)
}

/****************************************************************************
* Name: sdio_mediachange
* Name: mpfs_coremmc_sdio_mediachange
*
* Description:
* Called by board-specific logic -- possible from an interrupt handler --
Expand All @@ -2326,7 +2280,7 @@ struct sdio_dev_s *sdio_initialize(int slotno)
*
****************************************************************************/

void sdio_mediachange(struct sdio_dev_s *dev, bool cardinslot)
void mpfs_coremmc_sdio_mediachange(struct sdio_dev_s *dev, bool cardinslot)
{
struct mpfs_dev_s *priv = (struct mpfs_dev_s *)dev;
sdio_statset_t cdstatus;
Expand Down Expand Up @@ -2359,7 +2313,7 @@ void sdio_mediachange(struct sdio_dev_s *dev, bool cardinslot)
}

/****************************************************************************
* Name: sdio_wrprotect
* Name: mpfs_coremmc_sdio_wrprotect
*
* Description:
* Called by board-specific logic to report if the card in the slot is
Expand All @@ -2374,7 +2328,7 @@ void sdio_mediachange(struct sdio_dev_s *dev, bool cardinslot)
*
****************************************************************************/

void sdio_wrprotect(struct sdio_dev_s *dev, bool wrprotect)
void mpfs_coremmc_sdio_wrprotect(struct sdio_dev_s *dev, bool wrprotect)
{
struct mpfs_dev_s *priv = (struct mpfs_dev_s *)dev;
irqstate_t flags;
Expand Down
12 changes: 6 additions & 6 deletions arch/risc-v/src/mpfs/mpfs_coremmc.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ extern "C"
#endif

/****************************************************************************
* Name: sdio_initialize
* Name: mpfs_coremmc_sdio_initialize
*
* Description:
* Initialize SDIO for operation.
Expand All @@ -63,10 +63,10 @@ extern "C"
****************************************************************************/

struct sdio_dev_s; /* See include/nuttx/sdio.h */
struct sdio_dev_s *sdio_initialize(int slotno);
struct sdio_dev_s *mpfs_coremmc_sdio_initialize(int slotno);

/****************************************************************************
* Name: sdio_mediachange
* Name: mpfs_coremmc_sdio_mediachange
*
* Description:
* Called by board-specific logic -- possibly from an interrupt handler --
Expand All @@ -84,10 +84,10 @@ struct sdio_dev_s *sdio_initialize(int slotno);
*
****************************************************************************/

void sdio_mediachange(struct sdio_dev_s *dev, bool cardinslot);
void mpfs_coremmc_sdio_mediachange(struct sdio_dev_s *dev, bool cardinslot);

/****************************************************************************
* Name: sdio_wrprotect
* Name: mpfs_coremmc_sdio_wrprotect
*
* Description:
* Called by board-specific logic to report if the card in the slot is
Expand All @@ -102,7 +102,7 @@ void sdio_mediachange(struct sdio_dev_s *dev, bool cardinslot);
*
****************************************************************************/

void sdio_wrprotect(struct sdio_dev_s *dev, bool wrprotect);
void mpfs_coremmc_sdio_wrprotect(struct sdio_dev_s *dev, bool wrprotect);

#undef EXTERN
#if defined(__cplusplus)
Expand Down
74 changes: 12 additions & 62 deletions arch/risc-v/src/mpfs/mpfs_emmcsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
#include "hardware/mpfs_emmcsd.h"
#include "hardware/mpfs_mpucfg.h"

#include "mpfs_sdio_dev.h"

/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
Expand Down Expand Up @@ -291,58 +293,6 @@
* Private Types
****************************************************************************/

/* This structure defines the state of the MPFS eMMCSD interface */

struct mpfs_dev_s
{
struct sdio_dev_s dev; /* Standard, base SDIO interface */

const uintptr_t hw_base; /* Base address */
const int plic_irq; /* PLIC interrupt */
bool clk_enabled; /* Clk state */

/* eMMC / SD and HW parameters */

const bool emmc; /* eMMC or SD */
int bus_voltage; /* Bus voltage */
int bus_mode; /* eMMC Bus mode */
bool jumpers_3v3; /* Jumper settings: 1v8 or 3v3 */

/* Event support */

sem_t waitsem; /* Implements event waiting */
sdio_eventset_t waitevents; /* Set of events to be waited for */
uint32_t waitmask; /* Interrupt enables for event waiting */
volatile sdio_eventset_t wkupevent; /* The event that caused the wakeup */
struct wdog_s waitwdog; /* Watchdog that handles event timeouts */

/* Callback support */

sdio_statset_t cdstatus; /* Card status */
sdio_eventset_t cbevents; /* Set of events to be cause callbacks */
worker_t callback; /* Registered callback function */
void *cbarg; /* Registered callback argument */
struct work_s cbwork; /* Callback work queue structure */

/* Interrupt mode data transfer support */

uint32_t *buffer; /* Address of current R/W buffer */
size_t remaining; /* Number of bytes remaining in the transfer */
size_t receivecnt; /* Real count to receive */
uint32_t xfrmask; /* Interrupt enables for data transfer */

bool widebus; /* Required for DMA support */
bool onebit; /* true: Only 1-bit transfers are supported */

/* DMA data transfer support */

bool polltransfer; /* Indicate a poll transfer, no DMA */

/* Misc */

uint32_t blocksize; /* Current block size */
};

/****************************************************************************
* Private Function Prototypes
****************************************************************************/
Expand Down Expand Up @@ -1145,14 +1095,14 @@ static int mpfs_emmcsd_interrupt(int irq, void *context, void *arg)
{
mcinfo("Card inserted!\n");

sdio_mediachange((struct sdio_dev_s *)priv, true);
mpfs_emmcsd_sdio_mediachange((struct sdio_dev_s *)priv, true);
putreg32(MPFS_EMMCSD_SRS12_CIN, MPFS_EMMCSD_SRS12);
}
else if (status & MPFS_EMMCSD_SRS12_CR)
{
mcinfo("Card removed!\n");

sdio_mediachange((struct sdio_dev_s *)priv, false);
mpfs_emmcsd_sdio_mediachange((struct sdio_dev_s *)priv, false);
putreg32(MPFS_EMMCSD_SRS12_CR, MPFS_EMMCSD_SRS12);
}
else
Expand Down Expand Up @@ -3043,7 +2993,7 @@ static void mpfs_callback(void *arg)
****************************************************************************/

/****************************************************************************
* Name: sdio_initialize
* Name: mpfs_emmcsd_sdio_initialize
*
* Description:
* Initialize SDIO for operation.
Expand All @@ -3057,7 +3007,7 @@ static void mpfs_callback(void *arg)
*
****************************************************************************/

struct sdio_dev_s *sdio_initialize(int slotno)
struct sdio_dev_s *mpfs_emmcsd_sdio_initialize(int slotno)
{
struct mpfs_dev_s *priv = NULL;
priv = &g_emmcsd_dev;
Expand All @@ -3068,14 +3018,14 @@ struct sdio_dev_s *sdio_initialize(int slotno)

if (!mpfs_device_reset(&priv->dev))
{
return NULL;
return (struct sdio_dev_s *)NULL;
}

return &priv->dev;
return (struct sdio_dev_s *) &priv->dev;
}

/****************************************************************************
* Name: sdio_mediachange
* Name: mpfs_emmcsd_sdio_mediachange
*
* Description:
* Called by board-specific logic -- possible from an interrupt handler --
Expand All @@ -3093,7 +3043,7 @@ struct sdio_dev_s *sdio_initialize(int slotno)
*
****************************************************************************/

void sdio_mediachange(struct sdio_dev_s *dev, bool cardinslot)
void mpfs_emmcsd_sdio_mediachange(struct sdio_dev_s *dev, bool cardinslot)
{
struct mpfs_dev_s *priv = (struct mpfs_dev_s *)dev;
sdio_statset_t cdstatus;
Expand Down Expand Up @@ -3126,7 +3076,7 @@ void sdio_mediachange(struct sdio_dev_s *dev, bool cardinslot)
}

/****************************************************************************
* Name: sdio_wrprotect
* Name: mpfs_emmcsd_sdio_wrprotect
*
* Description:
* Called by board-specific logic to report if the card in the slot is
Expand All @@ -3141,7 +3091,7 @@ void sdio_mediachange(struct sdio_dev_s *dev, bool cardinslot)
*
****************************************************************************/

void sdio_wrprotect(struct sdio_dev_s *dev, bool wrprotect)
void mpfs_emmcsd_sdio_wrprotect(struct sdio_dev_s *dev, bool wrprotect)
{
struct mpfs_dev_s *priv = (struct mpfs_dev_s *)dev;
irqstate_t flags;
Expand Down
12 changes: 6 additions & 6 deletions arch/risc-v/src/mpfs/mpfs_emmcsd.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ extern "C"
#endif

/****************************************************************************
* Name: sdio_initialize
* Name: mpfs_emmcsd_sdio_initialize
*
* Description:
* Initialize SDIO for operation.
Expand All @@ -63,10 +63,10 @@ extern "C"
****************************************************************************/

struct sdio_dev_s; /* See include/nuttx/sdio.h */
struct sdio_dev_s *sdio_initialize(int slotno);
struct sdio_dev_s *mpfs_emmcsd_sdio_initialize(int slotno);

/****************************************************************************
* Name: sdio_mediachange
* Name: mpfs_emmcsd_sdio_mediachange
*
* Description:
* Called by board-specific logic -- possibly from an interrupt handler --
Expand All @@ -84,10 +84,10 @@ struct sdio_dev_s *sdio_initialize(int slotno);
*
****************************************************************************/

void sdio_mediachange(struct sdio_dev_s *dev, bool cardinslot);
void mpfs_emmcsd_sdio_mediachange(struct sdio_dev_s *dev, bool cardinslot);

/****************************************************************************
* Name: sdio_wrprotect
* Name: mpfs_emmcsd_sdio_wrprotect
*
* Description:
* Called by board-specific logic to report if the card in the slot is
Expand All @@ -102,7 +102,7 @@ void sdio_mediachange(struct sdio_dev_s *dev, bool cardinslot);
*
****************************************************************************/

void sdio_wrprotect(struct sdio_dev_s *dev, bool wrprotect);
void mpfs_emmcsd_sdio_wrprotect(struct sdio_dev_s *dev, bool wrprotect);

#undef EXTERN
#if defined(__cplusplus)
Expand Down
Loading

0 comments on commit b6dcb2d

Please sign in to comment.