More integration of Kinetis SDHC driver into NSH

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3902 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo 2011-08-21 17:36:14 +00:00
parent 8cedad6365
commit 593e188f93
3 changed files with 98 additions and 50 deletions

View File

@ -216,6 +216,11 @@
#define _PIN_INT_SHIFT (20) #define _PIN_INT_SHIFT (20)
#define _PIN_INT_MASK (31 << _PIN_INT_SHIFT) #define _PIN_INT_MASK (31 << _PIN_INT_SHIFT)
#define _PIN_INTDMA_MASK (3 << _PIN_INT_SHIFT)
#define _PIN_INTDMA_NONE (0 << _PIN_INT_SHIFT)
#define _PIN_DMA (1 << _PIN_INT_SHIFT)
#define _PIN_INTERRUPT (2 << _PIN_INT_SHIFT)
#define PIN_DMA_RISING (5 << _PIN_INT_SHIFT) /* 00101 DMA Request on rising edge */ #define PIN_DMA_RISING (5 << _PIN_INT_SHIFT) /* 00101 DMA Request on rising edge */
#define PIN_DMA_FALLING (9 << _PIN_INT_SHIFT) /* 01001 DMA Request on falling edge */ #define PIN_DMA_FALLING (9 << _PIN_INT_SHIFT) /* 01001 DMA Request on falling edge */
#define PIN_DMA_BOTH (13 << _PIN_INT_SHIFT) /* 01101 DMA Request on either edge */ #define PIN_DMA_BOTH (13 << _PIN_INT_SHIFT) /* 01101 DMA Request on either edge */
@ -772,6 +777,67 @@ EXTERN void kinetis_dmadump(DMA_HANDLE handle, const struct kinetis_dmaregs_s *r
#endif #endif
#endif #endif
/****************************************************************************
* Name: sdhc_initialize
*
* Description:
* Initialize SDIO for operation.
*
* Input Parameters:
* slotno - Not used.
*
* Returned Values:
* A reference to an SDIO interface structure. NULL is returned on failures.
*
****************************************************************************/
#ifdef CONFIG_KINETIS_SDHC
struct sdio_dev_s;
EXTERN FAR struct sdio_dev_s *sdhc_initialize(int slotno);
#endif
/****************************************************************************
* Name: sdhc_mediachange
*
* Description:
* Called by board-specific logic -- posssible from an interrupt handler --
* in order to signal to the driver that a card has been inserted or
* removed from the slot
*
* Input Parameters:
* dev - An instance of the SDIO driver device state structure.
* cardinslot - true is a card has been detected in the slot; false if a
* card has been removed from the slot. Only transitions
* (inserted->removed or removed->inserted should be reported)
*
* Returned Values:
* None
*
****************************************************************************/
#ifdef CONFIG_KINETIS_SDHC
EXTERN void sdhc_mediachange(FAR struct sdio_dev_s *dev, bool cardinslot);
#endif
/****************************************************************************
* Name: sdio_wrprotect
*
* Description:
* Called by board-specific logic to report if the card in the slot is
* mechanically write protected.
*
* Input Parameters:
* dev - An instance of the SDIO driver device state structure.
* wrprotect - true is a card is writeprotected.
*
* Returned Values:
* None
*
****************************************************************************/
#ifdef CONFIG_KINETIS_SDHC
EXTERN void sdhc_wrprotect(FAR struct sdio_dev_s *dev, bool wrprotect);
#endif
#undef EXTERN #undef EXTERN
#if defined(__cplusplus) #if defined(__cplusplus)
} }

View File

@ -432,7 +432,8 @@ void kinetis_uartconfigure(uintptr_t uart_base, uint32_t baud,
* RWFIFO[RXWATER] = 1: RDRF will be set when the number of queues bytes * RWFIFO[RXWATER] = 1: RDRF will be set when the number of queues bytes
* (1 in this case) is greater than or equal to 1. * (1 in this case) is greater than or equal to 1.
* *
/* Set the watermarks to one and disable the FIFOs */ * Set the watermarks to one/zero and disable the FIFOs
*/
putreg8(1, uart_base+KINETIS_UART_RWFIFO_OFFSET); putreg8(1, uart_base+KINETIS_UART_RWFIFO_OFFSET);
putreg8(0, uart_base+KINETIS_UART_TWFIFO_OFFSET); putreg8(0, uart_base+KINETIS_UART_TWFIFO_OFFSET);

View File

@ -172,8 +172,8 @@
# define SAMPLENDX_BEFORE_SETUP 0 # define SAMPLENDX_BEFORE_SETUP 0
# define SAMPLENDX_BEFORE_ENABLE 1 # define SAMPLENDX_BEFORE_ENABLE 1
# define SAMPLENDX_AFTER_SETUP 2 # define SAMPLENDX_AFTER_SETUP 2
# define SAMPLENDX_END_TRANSFER 3 # define SAMPLENDX_DMA_CALLBACK 3
# define SAMPLENDX_DMA_CALLBACK 4 # define SAMPLENDX_END_TRANSFER 4
# define DEBUG_NSAMPLES 5 # define DEBUG_NSAMPLES 5
# else # else
# define SAMPLENDX_BEFORE_SETUP 0 # define SAMPLENDX_BEFORE_SETUP 0
@ -680,13 +680,13 @@ static void kinetis_dumpsamples(struct kinetis_dev_s *priv)
} }
#endif #endif
kinetis_dumpsample(priv, &g_sampleregs[SAMPLENDX_AFTER_SETUP], "After setup"); kinetis_dumpsample(priv, &g_sampleregs[SAMPLENDX_AFTER_SETUP], "After setup");
kinetis_dumpsample(priv, &g_sampleregs[SAMPLENDX_END_TRANSFER], "End of transfer");
#if defined(CONFIG_DEBUG_DMA) && defined(CONFIG_SDIO_DMA) #if defined(CONFIG_DEBUG_DMA) && defined(CONFIG_SDIO_DMA)
if (priv->dmamode) if (priv->dmamode)
{ {
kinetis_dumpsample(priv, &g_sampleregs[SAMPLENDX_DMA_CALLBACK], "DMA Callback"); kinetis_dumpsample(priv, &g_sampleregs[SAMPLENDX_DMA_CALLBACK], "DMA Callback");
} }
#endif #endif
kinetis_dumpsample(priv, &g_sampleregs[SAMPLENDX_END_TRANSFER], "End of transfer");
} }
#endif #endif
@ -1037,10 +1037,6 @@ static void kinetis_endtransfer(struct kinetis_dev_s *priv, sdio_eventset_t wkup
#ifdef CONFIG_SDIO_DMA #ifdef CONFIG_SDIO_DMA
if (priv->dmamode) if (priv->dmamode)
{ {
/* DMA debug instrumentation */
kinetis_sample(priv, SAMPLENDX_END_TRANSFER);
/* Make sure that the DMA is stopped (it will be stopped automatically /* Make sure that the DMA is stopped (it will be stopped automatically
* on normal transfers, but not necessarily when the transfer terminates * on normal transfers, but not necessarily when the transfer terminates
* on an error condition). * on an error condition).
@ -1054,6 +1050,10 @@ static void kinetis_endtransfer(struct kinetis_dev_s *priv, sdio_eventset_t wkup
priv->remaining = 0; priv->remaining = 0;
/* Debug instrumentation */
kinetis_sample(priv, SAMPLENDX_END_TRANSFER);
/* Is a thread wait for these data transfer complete events? */ /* Is a thread wait for these data transfer complete events? */
if ((priv->waitevents & wkupevent) != 0) if ((priv->waitevents & wkupevent) != 0)
@ -1780,30 +1780,31 @@ static void kinetis_sendcmd(FAR struct sdio_dev_s *dev, uint32_t cmd, uint32_t a
switch (cmd & MMCSD_RESPONSE_MASK) switch (cmd & MMCSD_RESPONSE_MASK)
{ {
case MMCSD_NO_RESPONSE: case MMCSD_NO_RESPONSE: /* No response */
regval |= SDHC_XFERTYP_RSPTYP_NONE; /* No response */ regval |= SDHC_XFERTYP_RSPTYP_NONE;
break; break;
case MMCSD_R1B_RESPONSE: case MMCSD_R1B_RESPONSE: /* Response length 48, check busy & cmdindex*/
regval |= SDHC_XFERTYP_RSPTYP_LEN48BSY; /* Response length 48, check busy */ regval |= (SDHC_XFERTYP_RSPTYP_LEN48BSY | SDHC_XFERTYP_CICEN);
break;
case MMCSD_R1_RESPONSE: case MMCSD_R1_RESPONSE: /* Response length 48, check cmdindex */
case MMCSD_R3_RESPONSE: case MMCSD_R6_RESPONSE:
regval |= (SDHC_XFERTYP_RSPTYP_LEN48 | SDHC_XFERTYP_CICEN);
break;
case MMCSD_R3_RESPONSE: /* Response length 48 */
case MMCSD_R4_RESPONSE: case MMCSD_R4_RESPONSE:
case MMCSD_R5_RESPONSE: case MMCSD_R5_RESPONSE:
case MMCSD_R6_RESPONSE:
case MMCSD_R7_RESPONSE: case MMCSD_R7_RESPONSE:
regval |= SDHC_XFERTYP_RSPTYP_LEN48; /* Response length 48 */ regval |= SDHC_XFERTYP_RSPTYP_LEN48;
break; break;
case MMCSD_R2_RESPONSE: case MMCSD_R2_RESPONSE: /* Response length 136 */
regval |= SDHC_XFERTYP_RSPTYP_LEN136; /* Response length 136 */ regval |= SDHC_XFERTYP_RSPTYP_LEN136;
break; break;
} }
# warning "Missing other settings?"
fvdbg("cmd: %08x arg: %08x regval: %08x\n", cmd, arg, regval);
/* Enable DMA */ /* Enable DMA */
#ifdef CONFIG_SDIO_DMA #ifdef CONFIG_SDIO_DMA
@ -1815,16 +1816,11 @@ static void kinetis_sendcmd(FAR struct sdio_dev_s *dev, uint32_t cmd, uint32_t a
} }
#endif #endif
/* Other bits (revisit -- these probably should not alway be set). /* Other bits? What about CMDTYP? */
*
* CICEN=1: The SDHC will check the index field in the response to see if
* it has the same value as the command index. If it is not, it
* is reported as a command index error.
* Also... what about CMDTYP?
*/
#warning "Revisit" #warning "Revisit"
regval |= SDHC_XFERTYP_CICEN;
fvdbg("cmd: %08x arg: %08x regval: %08x\n", cmd, arg, regval);
/* Set the SDHC Argument value */ /* Set the SDHC Argument value */
@ -2093,9 +2089,6 @@ static int kinetis_waitresponse(FAR struct sdio_dev_s *dev, uint32_t cmd)
static int kinetis_recvshortcrc(FAR struct sdio_dev_s *dev, uint32_t cmd, uint32_t *rshort) static int kinetis_recvshortcrc(FAR struct sdio_dev_s *dev, uint32_t cmd, uint32_t *rshort)
{ {
#ifdef CONFIG_DEBUG
uint32_t respcmd;
#endif
uint32_t regval; uint32_t regval;
int ret = OK; int ret = OK;
@ -2154,19 +2147,6 @@ static int kinetis_recvshortcrc(FAR struct sdio_dev_s *dev, uint32_t cmd, uint32
fdbg("ERROR: CRC failure: %08x\n", regval); fdbg("ERROR: CRC failure: %08x\n", regval);
ret = -EIO; ret = -EIO;
} }
#ifdef CONFIG_DEBUG
else
{
/* Check response received is of desired command */
respcmd = getreg32(KINETIS_SDHC_RESPCMD);
if ((uint8_t)(respcmd & SDHC_RESPCMD_MASK) != (cmd & MMCSD_CMDIDX_MASK))
{
fdbg("ERROR: RESCMD=%02x CMD=%08x\n", respcmd, cmd);
ret = -EINVAL;
}
}
#endif
} }
/* Clear all pending message completion events and return the R1/R6 response */ /* Clear all pending message completion events and return the R1/R6 response */
@ -2461,6 +2441,7 @@ static sdio_eventset_t kinetis_eventwait(FAR struct sdio_dev_s *dev,
priv->xfrflags = 0; priv->xfrflags = 0;
#endif #endif
kinetis_dumpsamples(priv);
return wkupevent; return wkupevent;
} }
@ -2789,7 +2770,7 @@ static void kinetis_callback(void *arg)
****************************************************************************/ ****************************************************************************/
/**************************************************************************** /****************************************************************************
* Name: sdio_initialize * Name: sdhc_initialize
* *
* Description: * Description:
* Initialize SDIO for operation. * Initialize SDIO for operation.
@ -2802,7 +2783,7 @@ static void kinetis_callback(void *arg)
* *
****************************************************************************/ ****************************************************************************/
FAR struct sdio_dev_s *sdio_initialize(int slotno) FAR struct sdio_dev_s *sdhc_initialize(int slotno)
{ {
uint32_t regval; uint32_t regval;
@ -2888,7 +2869,7 @@ FAR struct sdio_dev_s *sdio_initialize(int slotno)
} }
/**************************************************************************** /****************************************************************************
* Name: sdio_mediachange * Name: sdhc_mediachange
* *
* Description: * Description:
* Called by board-specific logic -- posssible from an interrupt handler -- * Called by board-specific logic -- posssible from an interrupt handler --
@ -2906,7 +2887,7 @@ FAR struct sdio_dev_s *sdio_initialize(int slotno)
* *
****************************************************************************/ ****************************************************************************/
void sdio_mediachange(FAR struct sdio_dev_s *dev, bool cardinslot) void sdhc_mediachange(FAR struct sdio_dev_s *dev, bool cardinslot)
{ {
struct kinetis_dev_s *priv = (struct kinetis_dev_s *)dev; struct kinetis_dev_s *priv = (struct kinetis_dev_s *)dev;
uint8_t cdstatus; uint8_t cdstatus;
@ -2951,7 +2932,7 @@ void sdio_mediachange(FAR struct sdio_dev_s *dev, bool cardinslot)
* *
****************************************************************************/ ****************************************************************************/
void sdio_wrprotect(FAR struct sdio_dev_s *dev, bool wrprotect) void sdhc_wrprotect(FAR struct sdio_dev_s *dev, bool wrprotect)
{ {
struct kinetis_dev_s *priv = (struct kinetis_dev_s *)dev; struct kinetis_dev_s *priv = (struct kinetis_dev_s *)dev;
irqstate_t flags; irqstate_t flags;