FreeBSD/sys/boot/arm/at91/libat91/sd-card.c
//*----------------------------------------------------------------------------
//* \fn    sdcard_4wire
//* \brief  Set bus width to 1-bit or 4-bit according to the parm.
//*
//* Unlike most functions in this file, the return value from this one is
//* bool-ish; returns 0 on failure, 1 on success.
//*----------------------------------------------------------------------------
\fn    sdcard_4wire
\brief  Set bus width to 1-bit or 4-bit according to the parm.

Unlike most functions in this file, the return value from this one is
bool-ish; returns 0 on failure, 1 on success.
\ fn sdcard_4wire \ brief Set bus width to 1 - bit or 4 - bit according to the parm . Unlike most functions in this file the return value from this one is bool - ish ; returns 0 on failure 1 on success .
int
sdcard_use4wire(int use4wire)
{
	volatile int	ret_value;
	do {
		ret_value=MCI_GetStatus();
	}
	while((ret_value > 0) && ((ret_value & AT91C_SR_READY_FOR_DATA) == 0));
	ret_value = MCI_SDCard_SendAppCommand(SDCARD_SET_CLR_CARD_DETECT_CMD, 
					      use4wire ? 0 : 1);
	if (ret_value != AT91C_CMD_SEND_OK)
		return 0;
	ret_value = MCI_SDCard_SendAppCommand(SDCARD_SET_BUS_WIDTH_CMD,
					      use4wire ? AT91C_BUS_WIDTH_4BITS : 
					                 AT91C_BUS_WIDTH_1BIT);
	if (ret_value != AT91C_CMD_SEND_OK)
		return 0;
	if (use4wire) {
		MCI_Device.SDCard_bus_width = AT91C_BUS_WIDTH_4BITS;
		AT91C_BASE_MCI->MCI_SDCR |= AT91C_MCI_SCDBUS;
	} else {
		MCI_Device.SDCard_bus_width = AT91C_BUS_WIDTH_1BIT;
		AT91C_BASE_MCI->MCI_SDCR &= ~AT91C_MCI_SCDBUS;
	}
	return 1;
}
int sdcard_use4wire ( int use4wire ) { volatile int ret_value ; do { ret_value = MCI_GetStatus ( ) ; } while ( ( ret_value > 0 ) && ( ( ret_value & AT91C_SR_READY_FOR_DATA ) == 0 ) ) ; ret_value = MCI_SDCard_SendAppCommand ( SDCARD_SET_CLR_CARD_DETECT_CMD , use4wire ? 0 : 1 ) ; if ( ret_value != AT91C_CMD_SEND_OK ) return 0 ; ret_value = MCI_SDCard_SendAppCommand ( SDCARD_SET_BUS_WIDTH_CMD , use4wire ? AT91C_BUS_WIDTH_4BITS : AT91C_BUS_WIDTH_1BIT ) ; if ( ret_value != AT91C_CMD_SEND_OK ) return 0 ; if ( use4wire ) { MCI_Device . SDCard_bus_width = AT91C_BUS_WIDTH_4BITS ; AT91C_BASE_MCI -> MCI_SDCR |= AT91C_MCI_SCDBUS ; } else { MCI_Device . SDCard_bus_width = AT91C_BUS_WIDTH_1BIT ; AT91C_BASE_MCI -> MCI_SDCR &= ~ AT91C_MCI_SCDBUS ; } return 1 ; }
\fn    sdcard_4wire
\brief  Set bus width to 1-bit or 4-bit according to the parm.
\ fn sdcard_4wire \ brief Set bus width to 1 - bit or 4 - bit according to the parm .
// If going to 4-wire mode, ask the card to turn off the DAT3 card detect // pullup resistor, if going to 1-wire ask it to turn it back on. // Ask the card to go into the requested mode. // Set the MCI device to match the mode we set in the card.