Пример #1
0
/*******************************************************************************
* mvSpiWriteThenWrite - Serialize a command followed by the data over the TX line
*
* DESCRIPTION:
*       Assert the chip select line. Transmit the command buffer followed by
*       the data buffer. Then deassert the CS line.
*
* INPUT:
*       pCmndBuff: Pointer to the command buffer to transmit
*       cmndSize: length of the command size
*		pTxDataBuff: Pointer to the data buffer to transmit
*		txDataSize: length of the data buffer
*
* OUTPUT:
*       None.
*
* RETURN:
*       Success or Error code.
*
*
*******************************************************************************/
MV_STATUS	mvSpiWriteThenWrite (MV_U8* pCmndBuff, MV_U32 cmndSize, MV_U8* pTxDataBuff,
                                 MV_U32 txDataSize)
{
    MV_STATUS ret = MV_OK, tempRet;

    /* check for null parameters */
#ifndef CONFIG_MARVELL
    if(NULL == pTxDataBuff)
    {
        mvOsPrintf("%s ERROR: Null pointer parameter!\n", __FUNCTION__);
        return MV_BAD_PARAM;
    }
#endif

    if (pCmndBuff == NULL)
    {
        mvOsPrintf("%s ERROR: Null pointer parameter!\n", __FUNCTION__);
        return MV_BAD_PARAM;
    }

	/* First assert the chip select */
	if (!currSpiInfo->byteCsAsrt)
		mvSpiCsAssert();

    /* first write the command */
    if ((cmndSize) && (pCmndBuff != NULL))
    {
        if ((tempRet = mvSpiWrite(pCmndBuff, cmndSize)) != MV_OK)
            ret = tempRet;
    }

    /* Then write the data buffer */
#ifndef CONFIG_MARVELL
    if (txDataSize)
#else
    if ((txDataSize) && (pTxDataBuff != NULL))
#endif
    {
        if ((tempRet = mvSpiWrite(pTxDataBuff, txDataSize)) != MV_OK)
            ret = tempRet;
    }

	/* Finally deassert the chip select */
	if (!currSpiInfo->byteCsAsrt)
		mvSpiCsDeassert();

	return ret;
}
Пример #2
0
/*******************************************************************************
* mvSpiWriteThenRead - Serialize a command then read a data buffer
*
* DESCRIPTION:
*       Assert the chip select line. Transmit the command buffer then read
*       the data buffer. Then deassert the CS line.
*
* INPUT:
*       pCmndBuff: Pointer to the command buffer to transmit
*       cmndSize: length of the command size
*		pRxDataBuff: Pointer to the buffer to read the data in
*		txDataSize: length of the data buffer
*
* OUTPUT:
*		pRxDataBuff: Pointer to the buffer holding the data
*
* RETURN:
*       Success or Error code.
*
*
*******************************************************************************/
MV_STATUS mvSpiWriteThenRead (MV_U8* pCmndBuff, MV_U32 cmndSize, MV_U8* pRxDataBuff,
                              MV_U32 rxDataSize,MV_U32 dummyBytesToRead)
{
    MV_STATUS ret = MV_OK, tempRet;
    MV_U8   dummyByte;

    /* check for null parameters */
    if ((pCmndBuff == NULL) && (pRxDataBuff == NULL))
    {
        mvOsPrintf("%s ERROR: Null pointer parameter!\n", __FUNCTION__);
        return MV_BAD_PARAM;
    }

	/* First assert the chip select */
	if (!currSpiInfo->byteCsAsrt)
		mvSpiCsAssert();

    /* first write the command */
    if ((cmndSize) && (pCmndBuff != NULL))
    {
        if ((tempRet = mvSpiWrite(pCmndBuff, cmndSize)) != MV_OK)
            ret = tempRet;
    }

    /* Read dummy bytes before real data.   */
    while(dummyBytesToRead)
    {
        mvSpiRead(&dummyByte,1);
        dummyBytesToRead--;
    }

    /* Then write the data buffer */
    if ((rxDataSize) && (pRxDataBuff != NULL))
    {
        if ((tempRet = mvSpiRead(pRxDataBuff, rxDataSize)) != MV_OK)
            ret = tempRet;
    }

	/* Finally deassert the chip select */
	if (!currSpiInfo->byteCsAsrt)
		mvSpiCsDeassert();

	return ret;
}
Пример #3
0
/*******************************************************************************
* mvSpiReadAndWrite - Read and Write a buffer simultanuousely
*
* DESCRIPTION:
*       Transmit and receive a buffer over the SPI in 16bit chunks. If the
*		buffer size is odd, then the last chunk will be 8bits.
*
* INPUT:
*       pRxBuff: Pointer to the buffer to write the RX info in
*		pTxBuff: Pointer to the buffer holding the TX info
*		buffSize: length of both the pTxBuff and pRxBuff
*
* OUTPUT:
*       pRxBuff: Pointer of the buffer holding the RX data
*
* RETURN:
*       Success or Error code.
*
*
*******************************************************************************/
MV_STATUS mvSpiReadAndWrite(MV_U8* pRxBuff, MV_U8* pTxBuff, MV_U32 buffSize)
{
    MV_STATUS ret;

    /* check for null parameters */
    if ((pRxBuff == NULL) || (pTxBuff == NULL) || (buffSize == 0))
    {
        mvOsPrintf("%s ERROR: Null pointer parameter!\n", __FUNCTION__);
        return MV_BAD_PARAM;
    }

	/* First assert the chip select */
	mvSpiCsAssert();

    ret = mvSpiReadWrite(pRxBuff, pTxBuff, buffSize);

	/* Finally deassert the chip select */
	mvSpiCsDeassert();

	return ret;
}
Пример #4
0
void spi_cs_deactivate(struct spi_slave *slave)
{
	mvSpiCsDeassert(0);
	//writel(readl(&spireg->ctrl) & KWSPI_IRQMASK, &spireg->ctrl);
}