Exemple #1
0
static u32 adi_pdd_Close(
    ADI_DEV_PDD_HANDLE PDDHandle    /* PDD handle */
)
{
    u32 Result = ADI_DEV_RESULT_SUCCESS;

    ADI_USB_DEF   *pDevice = (ADI_USB_DEF *)PDDHandle;

    if (pDevice->DataSemaphoreHandle)
    {
        adi_sem_Delete(pDevice->DataSemaphoreHandle);
        adi_sem_Delete(pDevice->LockSemaphoreHandle);
    }

    /* Close the Class Driver */
    if (pDevice->UseDefaultClassDriver)
    {
        Result = adi_dev_Close(pDevice->ClassDriverHandle);
    }
    /* Close the Controller Driver if the driver owns it*/
    if (pDevice->UseDefaultController)
    {
        Result = adi_dev_Close(pDevice->ControllerHandle);
    }

    /* free the device instance */
    _adi_fss_free(ADI_USB_GEN_HEAPID,(void*)pDevice);

    return(Result);
}
int ReadMACAddress(char * cMacAddress)
{
	u32 Result = ADI_DEV_RESULT_SUCCESS;
	u32 access_mode = ADI_OTP_ACCESS_READ;
	u64 macaddress;
	u16 i=0;
	char *ptr=cMacAddress;
	char MACaddr[6] = { 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd };

	// open the OTP driver
	Result = adi_dev_Open(	adi_dev_ManagerHandle,			// DevMgr handle
							&ADIOTPEntryPoint,				// pdd entry point
							0,								// device instance
							NULL,							// client handle callback identifier
							&DevHandleOTP,					// DevMgr handle for this device
							ADI_DEV_DIRECTION_BIDIRECTIONAL,// data direction for this device
							NULL,							// handle to DmaMgr for this device
							NULL,							// handle to deferred callback service
							OTP_Callback);					// client's callback function

	if (Result != ADI_DEV_RESULT_SUCCESS)
		return 0;

	access_mode = ADI_OTP_ACCESS_READWRITE;

	Result = adi_dev_Control(DevHandleOTP, ADI_OTP_CMD_SET_ACCESS_MODE, &access_mode );
	if (Result != ADI_DEV_RESULT_SUCCESS)
	{
		adi_dev_Close( DevHandleOTP );
		return 0;
	}

	// Set Dataflow method
	Result = adi_dev_Control(DevHandleOTP, ADI_DEV_CMD_SET_DATAFLOW_METHOD, (void *)ADI_DEV_MODE_CHAINED );
	if(Result != ADI_DEV_RESULT_SUCCESS)
	{
		adi_dev_Close( DevHandleOTP );
		return 0;
    }


	Result = otp_read_page(OTP_MAC_ADDRESS_PAGE, ADI_OTP_LOWER_HALF, (u64*)&MACaddr);
	if( Result != ADI_DEV_RESULT_SUCCESS )
		return 0;

	// The MAC address is in reverse order
	// do byte swape
	for(i=0; i<6; i++)
	{
		*ptr++ = MACaddr[5-i];

	}

    adi_dev_Close( DevHandleOTP );

    return 1;

}
Exemple #3
0
/*********************************************************************

    Function: adi_pdd_Close

        Closes down a AD1980 device data port and/or instance

    Parameters:
        hPhysicalDevice - Physical Device Handle of the device to close

    Returns:
        ADI_DEV_RESULT_SUCCESS
            - Successfully closed audio device
        ADI_DEV_RESULT_BAD_PDD_HANDLE
            - Given Physical Device Driver Handle is invalid
        Error return codes from SPORT driver / Device Manager

*********************************************************************/
static u32 adi_pdd_Close(
    ADI_DEV_PDD_HANDLE      hPhysicalDevice
)
{
    /* Return value - assume we're going to be successful   */
    u32                                 nResult = ADI_DEV_RESULT_SUCCESS;
    /* pointer to the device we will be working on */
    ADI_AD1980_DEF                      *poDevice;
    /* Pointer to the audio data port we're working on */
    ADI_AD1980_DRIVER_DATA_PORT_INFO    *poDataPort = (ADI_AD1980_DRIVER_DATA_PORT_INFO *)hPhysicalDevice;

/* for Debug build only - check for errors if required  */
#if defined(ADI_DEV_DEBUG)

    /* Validate the given PDDHandle */
    nResult = ValidatePDDHandle(hPhysicalDevice);

    /* Continue only if the given PDDHandle is valid */
    if (nResult == ADI_DEV_RESULT_SUCCESS)
    {

#endif /* ADI_DEV_DEBUG */

        /* Get the address of device instance to work on */
        poDevice = &gaoAD1980Device[poDataPort->nAudioDevNumber];

        /* IF (Device opened for bi-directional mode) */
        if (poDataPort->eDirection == ADI_DEV_DIRECTION_BIDIRECTIONAL)
        {
            /* Mark both Tx and Rx port direction as undefined */
            poDevice->oAudioTx.eDirection = ADI_DEV_DIRECTION_UNDEFINED;
            poDevice->oAudioRx.eDirection = ADI_DEV_DIRECTION_UNDEFINED;
        }
        /* ELSE (Input and Output dataflow must be operated independently) */
        else
        {
            /* Mark the data port direction as undefined */
            poDataPort->eDirection = ADI_DEV_DIRECTION_UNDEFINED;
        }

        /* IF (Direction of both data ports is undefined) */
        if ((poDevice->oAudioTx.eDirection == ADI_DEV_DIRECTION_UNDEFINED) &&\
            (poDevice->oAudioRx.eDirection == ADI_DEV_DIRECTION_UNDEFINED))
        {
            /* IF (SPORT device is open) */
            if (poDevice->hSport)
            {
                /* Close the SPORT device */
                nResult = adi_dev_Close(poDevice->hSport);
                poDevice->hSport = NULL;
            }
        }

/* for Debug build only */
#if defined(ADI_DEV_DEBUG)
    }
#endif

    return(nResult);
}
Exemple #4
0
static u32 adi_pdd_Close(		// Closes a device
	ADI_DEV_PDD_HANDLE PDDHandle	// PDD handle
) {
	u32 Result;		// return value
	ADI_LCD *pLCD = (ADI_LCD *)PDDHandle;

	// check for errors if required
#if defined(ADI_DEV_DEBUG)
	if ((Result = ValidatePDDHandle(PDDHandle)) != ADI_DEV_RESULT_SUCCESS) return (Result);
#endif
	// close PPI driver
	Result = adi_dev_Close(pLCD->ppiHandle);

#ifdef ADI_DEV_DEBUG
	if (Result != ADI_DEV_RESULT_SUCCESS) return (Result);
#endif

	// mark the device as closed
	pLCD->InUseFlag = FALSE;
	pLCD->ManagerHandle = NULL;
    	pLCD->DMHandle = NULL;
    	pLCD->DMAHandle = NULL;
    	pLCD->DCBHandle = NULL;
    	pLCD->DMCallback = NULL;
    	pLCD->ppiHandle = NULL;

	return(Result);
}
Exemple #5
0
    AdiDeviceResult AdiDevice::Close()
    {
    	ESS_ASSERT(IsOpened());


        AdiDeviceResult result= adi_dev_Close(m_deviceHandle);
        
        if (result.isSuccess())	m_isOpen = false;
        
        return result;
    }
int Lw_Shutdown(ADI_DEV_DEVICE_HANDLE lan_handle)
{
	// shutdown lan
    int result = adi_dev_Control(lan_handle, ADI_ETHER_CMD_SHUTDOWN_DRIVER, NULL);
	if (result != ADI_DEV_RESULT_SUCCESS) return 0;

	// stop LwIP
	//stop_stack();
	
	// close LAN
	result = adi_dev_Close(lan_handle); 
    if (result != ADI_DEV_RESULT_SUCCESS) return 0;

    return 1;
}
Exemple #7
0
/*********************************************************************
*
*	Function:		SPORT_Close
*
*	Description:	Closes the SPORT device	used for ADAV801 audio dataflow
*
*********************************************************************/
static u32 SPORT_Close(	
	ADI_DEV_PDD_HANDLE PDDHandle	// Physical	Device Driver Handle
) {

	//	Pointer	to ADAV801 device driver instance	
	ADI_ADAV801	 *pADAV801 = (ADI_ADAV801 *)PDDHandle;
	u32	Result = ADI_DEV_RESULT_SUCCESS;	// default return code

	// Check if	any	SPORT device is	open
	// if so, close	the	present	SPORT device in	use
	if (pADAV801->sportHandle != NULL)
	{
		// close the present SPORT device
		if ((Result	= adi_dev_Close(pADAV801->sportHandle))!= ADI_DEV_RESULT_SUCCESS)
			return (Result);
			// Mark	SPORT Handle as	NULL indicating	SPORT device is	closed
			pADAV801->sportHandle =	NULL;					
	}
	
	return (Result);
}
Exemple #8
0
static u32 adi_pdd_Close(		// Closes a device
	ADI_DEV_PDD_HANDLE PDDHandle	// PDD handle
) {
	u32 Result;		// return value
	ADI_AD7477A *pAD7477A = (ADI_AD7477A *)PDDHandle;

	// check for errors if required
#if defined(ADI_DEV_DEBUG)
	if ((Result = ValidatePDDHandle(PDDHandle)) != ADI_DEV_RESULT_SUCCESS) return (Result);
#endif

	// close SPI driver
	Result = adi_dev_Close(pAD7477A->spiHandle);
#ifdef ADI_DEV_DEBUG
	if (Result != ADI_DEV_RESULT_SUCCESS) return (Result);
#endif

	// mark the device as closed
	pAD7477A->InUseFlag = FALSE;
	
	return(Result);
}
Exemple #9
0
/*********************************************************************

    Function: adi_pdd_Control

        Senses or Configures AD1980 device registers

    Parameters:
        hPhysicalDevice - Physical Device Handle of the device to work on
        nCommand        - Command ID
        Value           - Command specific value

    Returns:
        ADI_DEV_RESULT_SUCCESS
            - Successfully processed the given command
        DD/SS or AD1980 specific error code

*********************************************************************/
static u32 adi_pdd_Control(
    ADI_DEV_PDD_HANDLE      hPhysicalDevice,
    u32                     nCommand,
    void                    *Value
)
{
    /* u8 type to avoid casts/warnings etc.    */
    u8                                  u8Value;
    /* u32 type to avoid casts/warnings etc.    */
    u32                                 u32Value;
    /* Return value - assume we're going to be successful   */
    u32                                 nResult = ADI_DEV_RESULT_SUCCESS;
    /* pointer to the device we will be working on */
    ADI_AD1980_DEF                      *poDevice;
    /* Pointer to AD1980 Driver init instance */
    ADI_AD1980_INIT_DRIVER              *pInit;
    /* Pointer to the audio data port we're working on */
    ADI_AD1980_DRIVER_DATA_PORT_INFO    *poDataPort = (ADI_AD1980_DRIVER_DATA_PORT_INFO *)hPhysicalDevice;

    /* assign 8 & 32 bit values for the Value argument */
    u32Value = (u32)Value;
    u8Value = (u8)u32Value;

/* for Debug build only - check for errors if required  */
#if defined(ADI_DEV_DEBUG)
    /* Validate the given PDDHandle */
    nResult = ValidatePDDHandle(hPhysicalDevice);

    /* Continue only if the given PDDHandle is valid */
    if (nResult == ADI_DEV_RESULT_SUCCESS)
    {
#endif

        /* Get the address of device instance to work on */
        poDevice = &gaoAD1980Device[poDataPort->nAudioDevNumber];

        /* CASEOF (Command ID)  */
        switch (nCommand)
        {
            /* CASE: Control dataflow */
            case (ADI_DEV_CMD_SET_DATAFLOW):
            /* CASE: Set Dataflow method */
            case (ADI_DEV_CMD_SET_DATAFLOW_METHOD):
                /* IF (AC'97 instance is invalid) */
                if (poDevice->pAC97 == NULL)
                {
                    /* return error (AC'97 instance is invalid) */
                    nResult = ADI_AD1980_RESULT_AC97_INSTANCE_INVALID;
                }
                /* ELSE (AC'97 instance is valid) */
                else
                {
                    /* IF (Data port opened for inbound dataflow) */
                    if (poDataPort->eDirection == ADI_DEV_DIRECTION_INBOUND)
                    {
                        /* IF (Command is to update dataflow status) */
                        if (nCommand == ADI_DEV_CMD_SET_DATAFLOW)
                        {
                            /* Change command to AC'97 specific command to
                               update Rx dataflow for this device */
                            nCommand = ADI_AC97_CMD_SET_RECEIVE_DATAFLOW;
                        }
                        /* ELSE (Command must be to set dataflow method) */
                        else
                        {
                            /* Change command to AC'97 specific command to
                               update Rx dataflow method for this device */
                            nCommand = ADI_AC97_CMD_SET_RECEIVE_DATAFLOW_METHOD;
                        }
                    }
                    /* ELSE IF (Data port opened for outbound dataflow) */
                    else if (poDataPort->eDirection == ADI_DEV_DIRECTION_OUTBOUND)
                    {
                        /* IF (Command is to update dataflow status) */
                        if (nCommand == ADI_DEV_CMD_SET_DATAFLOW)
                        {
                            /* Change command to AC'97 specific command to
                               update Tx dataflow for this device */
                            nCommand = ADI_AC97_CMD_SET_TRANSMIT_DATAFLOW;
                        }
                        /* ELSE (Command must be to set dataflow method) */
                        else
                        {
                            /* Change command to AC'97 specific command to
                               update Tx dataflow method for this device */
                            nCommand = ADI_AC97_CMD_SET_TRANSMIT_DATAFLOW_METHOD;
                        }
                    }
                    /* ELSE (Device is opened for bi-directional dataflow) */
                        /* Pass the command to AC'97 library with out any change */

                    /* Pass command to AC'97 library) */
                    nResult = adi_ac97_Control(poDevice->pAC97,
                                               nCommand,
                                               Value);

                }
                break;

            /* CASE (Initialise AD1980 driver) */
            case (ADI_AD1980_CMD_INIT_DRIVER):

                /* Address of AD1980 driver init structure */
                pInit = (ADI_AD1980_INIT_DRIVER *) Value;

                /* Initialise AC'97 Driver instance */
                nResult = adi_ac97_Init_Instance (Value);

                /* IF (Successfully initialised AC'97 driver instance) */
                if (nResult == ADI_DEV_RESULT_SUCCESS)
                {
                    /* IF (AC'97 Instance was already initialised) */
                    if (poDevice->pAC97 != NULL)
                    {
                        /* Close the SPORT device that is open */
                        nResult = adi_dev_Close(poDevice->hSport);
                    }
                }

                /* IF (Successfully closed the SPORT device opened previously) */
                if (nResult == ADI_DEV_RESULT_SUCCESS)
                {
                    /* save AC'97 driver instance handle */
                    poDevice->pAC97                     = pInit->pAC97;
                    /* AD1980 driver Callback function supplied to the AC'97 driver instance */
                    poDevice->pAC97->CodecCallback      = adi_ad1980_AC97Callback;
                    /* pointer to critical region */
                    poDevice->pAC97->pEnterCriticalArg  = poDevice->pEnterCriticalArg;
                    /* Save the SPORT Device Number */
                    poDevice->nSportDevNumber           = pInit->SportDevNumber;
                    /* Save the Reset Flag ID */
                    poDevice->eResetFlag                = pInit->ResetFlagId;

                    /* Open and Configure SPORT Device connected to AD1980 */
                    nResult = adi_ad1980_SportConfig (poDevice);
                }
                break;

            /* CASE (Update SPORT DMA Bus Width) */
            case (ADI_AC97_CMD_UPDATE_SPORT_DMA_BUS_WIDTH):

                /* IF (The DMA bus width is valid) */
                if ((u32)Value != 0)
                {
                    /* IF (we already have a SPORT device open) */
                    if (poDevice->hSport != NULL)
                    {
                        /* Close the SPORT device that is open */
                        nResult = adi_dev_Close(poDevice->hSport);

                        /* IF (Successfully closed SPORT device) */
                        if (nResult == ADI_DEV_RESULT_SUCCESS)
                        {
                            poDevice->hSport = NULL;
                            /* Update AC'97 instance with new DMA bus width */
                            nResult = adi_ac97_Control(poDevice->pAC97, nCommand, Value);
                        }

                        /* IF (Successfully updated AC'97 instance) */
                        if (nResult == ADI_DEV_RESULT_SUCCESS)
                        {
                            /* Open and Configure SPORT Device connected to AD1980 */
                            nResult = adi_ad1980_SportConfig (poDevice);
                        }
                    }
                    /* ELSE (AC'97 instance is yet to be initialised) */
                    else
                    {
                        /* Save the SPORT DMA bus width */
                        poDevice->nSportDmaBusWidth = (u32)Value;
                    }
                }
                break;

            /* CASE: Set Deferred Callback or Live callback to process AC'97 frames */
            case (ADI_AD1980_CMD_USE_DCB_TO_PROCESS_FRAMES):
                poDevice->hDcbManager = (ADI_DCB_HANDLE)Value;
                break;

            /* CASE: query for processor DMA support */
            case (ADI_DEV_CMD_GET_PERIPHERAL_DMA_SUPPORT):

                /* AD1980 doesn't support DMA, but supports indirectly via SPORT */
                *((u32 *)Value) = false;
                break;

            /* other commands - requires a valid AC'97 instance */
            default:
                /* IF (AC'97 instance is invalid) */
                if (poDevice->pAC97 == NULL)
                {
                    /* return error (AC'97 instance is invalid) */
                    nResult = ADI_AD1980_RESULT_AC97_INSTANCE_INVALID;
                }
                /* ELSE (AC'97 instance is valid) */
                else
                {
                    /* Pass this to register access control function
                       assuming this to be a register access command
                       from the upper level layer calling this driver */
                    nResult = adi_ad1980_RegisterAccess(poDevice, nCommand, Value, false);

                    /* IF (Command not supported by register access function) */
                    if (nResult == ADI_AD1980_RESULT_CMD_NOT_SUPPORTED)
                    {
                        /* try passing this command to AC'97 driver */
                        nResult = adi_ac97_Control(poDevice->pAC97, nCommand, Value);
                    }

                    /* IF (Command not supported by AC'97 driver) */
                    if (nResult == ADI_AC97_RESULT_CMD_NOT_SUPPORTED)
                    {
                        /* IF (SPORT driver is already open) */
                        if (poDevice->hSport != NULL)
                        {
                            /* try passing this command to SPORT */
                            nResult = adi_dev_Control(poDevice->hSport, nCommand, Value);
                        }

                    } /* End of if (Command not supported by AC'97 driver) */

                } /* End of if (AC'97 instance is invalid) */
                break;

        } /* End of switch (Command ID) cases */

/* for Debug build only */
#if defined(ADI_DEV_DEBUG)
    }
#endif

    /* return */
    return(nResult);
}