/* vxbMmcStorage.c - MMC driver file for vxBus */
/*
* Copyright (c) 2012-2013, 2015-2018 Wind River Systems, Inc.
*
* The right to copy, distribute, modify or otherwise make use
* of this software may be licensed only pursuant to the terms
* of an applicable Wind River license agreement.
*/
/*
modification history
--------------------
01k,12jul18,j_x masking member busWidth of structure SD_HOST_SPEC for binary
compatible (VXW6-86766)
01j,31may18,d_l limit tranSpeed to 52MHZ (VXW6-86759)
01i,10feb17,d_l set busWidth as BSP selected, default to 4 bit. (VXW6-86099)
01h,25jan16,myt add support for direct bio for SD/eMMC (VXW6-85000)
01g,24dec15,myt get cid info (VXW6-85012)
01f,26oct15,myt add support of reliable write for eMMC (VXW6-84383)
01e,06jan15,myt add support for Bay Trail (VXW6-80833)
01d,11dec13,m_y modify to support request transfer routine
01c,20nov13,e_d remove APIs wrongly published. (WIND00444661)
01b,24sep13,e_d add some advanced functionalities for SD/MMC. (WIND00437987)
01a,12apr12,e_d written based on the vxbFslI2c.c.
*/
/*
DESCRIPTION
This module implements a driver for SD card. This driver checks the device name
to probe driver. If success, the driver will identify this device and mounts the
device to xbd layer.
\ie
SEE ALSO: vxBus
*/
/* includes */
#include <vxWorks.h>
#include <vsbConfig.h>
#include <stdlib.h>
#include <string.h>
#include <semLib.h>
#include <taskLib.h>
#include <stdio.h>
#include <vxBusLib.h>
#include <sioLib.h>
#include <ioLib.h>
#include <math.h>
#include <cacheLib.h>
#include <vxbTimerLib.h>
#include <errnoLib.h>
#include <hwif/util/hwMemLib.h>
#include <hwif/vxbus/vxBus.h>
#include <hwif/util/vxbParamSys.h>
#include <hwif/vxbus/vxbPlbLib.h>
#include <hwif/vxbus/hwConf.h>
#include <drv/xbd/xbd.h>
#include <xbdBlkDev.h>
#include <drv/erf/erfLib.h>
#include <hwif/vxbus/vxbSdLib.h>
#include <../src/hwif/h/vxbus/vxbAccess.h>
#include <../src/hwif/h/storage/vxbMmcStorage.h>
/* defines */
#ifdef MMC_CARD_DBG_ON
#ifdef LOCAL
#undef LOCAL
#define LOCAL
#endif
#define MMC_CARD_DBG_INIT 0x00000001
#define MMC_CARD_DBG_RW 0x00000002
#define MMC_CARD_DBG_SET 0x00000004
#define MMC_CARD_DBG_ALL 0xffffffff
#define MMC_CARD_DBG_OFF 0x00000000
LOCAL UINT32 mmcCardDbgMask = MMC_CARD_DBG_OFF;
IMPORT FUNCPTR _func_logMsg;
#define MMC_CARD_DBG(mask, string, a, b, c, d, e, f) \
if ((mmcCardDbgMask & mask) || (mask == MMC_CARD_DBG_ALL)) \
if (_func_logMsg != NULL) \
(* _func_logMsg)(string, a, b, c, d, e, f)
#else
# define MMC_CARD_DBG(mask, string, a, b, c, d, e, f)
#endif /* MMC_DBG_ON */
LOCAL void mmcStorageInit (VXB_DEVICE_ID);
LOCAL void mmcStorageInit2 (VXB_DEVICE_ID);
LOCAL void mmcStorageConnect (VXB_DEVICE_ID);
LOCAL STATUS mmcStorageBlkRead (void *, XBD_DATA *);
LOCAL STATUS mmcStorageBlkWrite (void *, XBD_DATA *);
LOCAL STATUS mmcStorageBlkRelWrite (void *, XBD_DATA * );
LOCAL STATUS mmcIdentify (VXB_DEVICE_ID);
LOCAL STATUS mmcStatusWaitReadyForData(VXB_DEVICE_ID);
LOCAL STATUS mmcStorageInstUnlink (VXB_DEVICE_ID, void * );
LOCAL BOOL mmcStoragDevProbe (VXB_DEVICE_ID);
LOCAL int mmcStorageIoctl (void *, int, void *);
LOCAL STATUS mmcExtCsdDecode (VXB_DEVICE_ID);
LOCAL STATUS mmcCacheEn (VXB_DEVICE_ID, UINT8);
LOCAL STATUS mmcCacheFlush (VXB_DEVICE_ID);
LOCAL STATUS mmcExtCsdSetPowClass (VXB_DEVICE_ID);
LOCAL STATUS mmcErase (VXB_DEVICE_ID, SECTOR_RANGE *);
LOCAL STATUS mmcSecErase (VXB_DEVICE_ID, SECTOR_RANGE *);
LOCAL STATUS mmcCardIdxAlloc (MMC_CARD_CTRL *);
LOCAL void mmcCardIdxFree (MMC_CARD_CTRL *);
/* locals */
LOCAL device_method_t vxbMmcStorage_methods[] =
{
DEVMETHOD (vxbDrvUnlink, mmcStorageInstUnlink),
DEVMETHOD_END
};
/* locals */
LOCAL DRIVER_INITIALIZATION mmcStoargeFuncs =
{
mmcStorageInit, /* devInstanceInit */
mmcStorageInit2, /* devInstanceInit2 */
mmcStorageConnect /* devConnect */
};
LOCAL DRIVER_REGISTRATION mmcStorageRegistration =
{
NULL, /* pNext */
VXB_DEVID_DEVICE, /* devID */
VXB_BUSID_SD, /* busID = PLB */
VXB_VER_5_0_0, /* vxbVersion */
MMCCARD_NAME, /* drvName */
&mmcStoargeFuncs, /* pDrvBusFuncs */
vxbMmcStorage_methods, /* pMethods */
mmcStoragDevProbe, /* devProbe */
NULL /* pParamDefaults */
};
/* SD/MMC card dev index */
LOCAL UINT32 mmcDevIdx;
/*
* The following two tables defines the maximum data transfer rate
* per one date line - TRAN_SPEED
*/
LOCAL UINT32 mmcCsdTranSpdfUnit[] = {
10000, 100000, 1000000, 10000000
};
LOCAL UINT32 mmcCsdTranSpdTime[] = {
0, 10, 12, 13, 15, 20, 26, 30,
35, 40, 45, 52, 55, 60, 70, 80,
};
/*IMPORT UINT32 sysClkRateGet(void);*/
#ifndef _WRS_CONFIG_SMP
IMPORT volatile UINT64 vxAbsTicks;
#else
IMPORT UINT64 vxAbsTicksGet (void);
#endif /* _WRS_CONFIG_SMP */
/*******************************************************************************
*
* vxbMmcStorageRegister - register vxbSdStorage driver
*
* This is vxbSdStorage register routine.
*
* RETURNS: N/A
*
* \NOMANUAL
*/
void vxbMmcStorageRegister(void)
{
vxbDevRegister ((struct vxbDevRegInfo *)&mmcStorageRegistration);
}
/*******************************************************************************
*
* mmcStoragDevProbe - vxbus probe function
*
* This function is called by vxBus to probe device.
*
* RETURNS: TRUE if probe passes and assumed a valid SD memory card
* (or compatible) device. FALSE otherwise.
*
* ERRNO: N/A
*
* \NOMANUAL
*/
LOCAL BOOL mmcStoragDevProbe
(
VXB_DEVICE_ID pDev
)
{
if (strcmp (pDev->pName, MMC_CARD_NAME) == 0x0)
return TRUE;
else
return FALSE;
}
/*******************************************************************************
*
* mmcStorageInit - VxBus instInit handler
*
* This function implements the VxBus instInit handler for MMC card
* device instance.
*
* RETURNS: N/A
*
* ERRNO: N/A
*
* \NOMANUAL
*/
LOCAL void mmcStorageInit
(
VXB_DEVICE_ID pDev
)
{
MMC_CARD_CTRL * pDrvCtrl;
pDrvCtrl = (MMC_CARD_CTRL *) malloc (sizeof (MMC_CARD_CTRL));
if (pDrvCtrl == NULL)
return;
bzero((char *)pDrvCtrl, sizeof(MMC_CARD_CTRL));
/* save instance ID */
pDrvCtrl->pInst = pDev;
pDev->pDrvCtrl = pDrvCtrl;
/* find the next instance */
vxbNextUnitGet (pDev);
return;
}
/*******************************************************************************
*
* mmcStorageInit2 - mmcStorageInit initialization 2
*
* This routine initialize the mmcStorageInit phase 2
*
* RETURNS: N/A
*
* ERRNO
*
* \NOMANUAL
*/
LOCAL void mmcStorageInit2
(
VXB_DEVICE_ID pDev
)
{
return;
}
/*******************************************************************************
*
* mmcStorageConnect - third level initialization
*
* This routine performs the third level initialization of the mmcStorage
* driver. This routine will identify device parameter.
*
* RETURNS: N/A
*
* ERRNO : N/A
*
* \NOMANUAL
*/
LOCAL void mmcStorageConnect
(
VXB_DEVICE_ID pDev
)
{
mmcIdentify(pDev);
return;
}
/*******************************************************************************
*
* mmcIdentify - identify MMC card in the system
*
* This routine implements the card identify process according to the MMC spec.
*
* RETURNS: OK or ERROR
*
* ERRNO: N/A
*
* \NOMANUAL
*/
LOCAL STATUS mmcIdentify
(
VXB_DEVICE_ID pDev
)
{
STATUS rc;
UINT8 regValue = 0;
UINT32 csize, csizeMulti;
UINT64 blkNum;
SD_HARDWARE * pSdHardWare;
MMC_CARD_CTRL * pDrvCtrl;
SD_HOST_SPEC * pHostSpec;
MMC_INFO *pMmcInfo;
device_t xbdSts;
BLK_XBD_PARAMS blkXbdParams;
pSdHardWare = (SD_HARDWARE *)(pDev->pBusSpecificDevInfo);
if (pSdHardWare == NULL)
retu
评论5