/******************************************************************************
 *
 * Copyright 2013, Silicon Image, Inc.  All rights reserved.
 * No part of this work may be reproduced, modified, distributed, transmitted,
 * transcribed, or translated into any language or computer format, in any form
 * or by any means without written permission of
 * Silicon Image, Inc., 1140 East Arques Avenue, Sunnyvale, California 94085
 *
 *****************************************************************************/
/**
 * @file sii9777_rx_func.h
 *
 * @brief Host Driver for SiI9777 Rx device.
 *
 *****************************************************************************/

#ifndef SII9777_MHL_FUNC_H
#define SII9777_MHL_FUNC_H

#ifdef __cplusplus
extern "C"{
#endif

/***** #include statements ***************************************************/

/***** public functions ******************************************************/

/******************************************************************************/
/**
* @brief
*
* @param[in]   inst	    Driver instance handle obtained by calling Sii9777Create.
*
* @param[out]  pCdSense	Pointer to the enumerator which indicates 
*                       the Cable Detect Sense state: 
*                       SII_9777_CD_SENSE__NONE
*                       SII_9777_CD_SENSE__MHL_CABLE
*
* @retval SiiRetVal_t   See general SII_RETVAL definitions
*
*******************************************************************************/
SiiRetVal_t Sii9777RxCdSenseQuery( SiiInst_t inst, Sii9777CdSense_t* pCdSense );

/******************************************************************************/
/**
* @brief Current MHL version.
*
* This function returns current MHL version.
*
* @param[in]  inst          Driver instance handle obtained by calling Sii9777Create.
* @param[out] pMhlVersion   Pointer to the enumerator which indicates the MHL Version: 
*                           SII_9777_MHL_VERSION__NONE
*                           SII_9777_MHL_VERSION__MHL12
*                           SII_9777_MHL_VERSION__MHL3
*
* @retval     SiiRetVal_t   See general SII_RETVAL definitions
*
*******************************************************************************/
SiiRetVal_t Sii9777MHLVersionQuery( SiiInst_t inst, Sii9777MhlVersion_t* pMhlVersion );

/******************************************************************************/
/**
* @brief Current CBUS mode.
*
* This function returns current Cbus mode.
*
* @param[in]  inst      Driver instance handle obtained by calling Sii9777Create.
* @param[out] pCbusMode Pointer to the enumerator which indicates the Cbus Mode: 
*                       0x00: SII_9777_CBUS_MODE__NONE
*                       0x01: SII_9777_CBUS_MODE__OCBUS
*                       0x02: SII_9777_CBUS_MODE__ECBUS_S
*                       0x04: SII_9777_CBUS_MODE__ECBUS_D
*
* @retval     SiiRetVal_t See general SII_RETVAL definitions
*
*******************************************************************************/
SiiRetVal_t Sii9777CbusModeQuery( SiiInst_t inst, Sii9777CbusMode_t* pCbusMode );

/******************************************************************************/
/**
* @brief Current VBUS power request.
*
* This function returns current VBUS power request.
* MHL device may provide power as in Sink to Source or in Source to Sink directions. 
* The direction is negotiated during the discovery process. 
* The VBUS power switch, however, is outside the SiI9777 
* and must be controlled by the application. 
* The driver generates a SII9777_EVT__VBUS_REQUEST event 
* whenever such control is needed. 
* This function is expected to be called on the notification 
* and returns the request value. 
* The application is required to enable or disable VBUS power 
* according to the request and then call Sii9777VbusRequestGrant() 
* to indicate that the request is processed and allow the MHL device 
* to continue the discovery process or power mode changing.
*
* @param[in]  inst      Driver instance handle obtained by calling Sii9777Create.
* @param[out] pRequest  Pointer to the Enumerator which indicates the Vbus power request states:
*                       SII9777_VBUS_REQ__NONE
*                       SII9777_VBUS_REQ__PROVIDE_POWER
*                       SII9777_VBUS_REQ__REMOVE_POWER
*
* @retval SiiRetVal_t	See general SII_RETVAL definitions
*
*******************************************************************************/
SiiRetVal_t Sii9777VbusRequestQuery( SiiInst_t inst, Sii9777VbusReq_t* pRequest );

/*****************************************************************************/
/**
* @brief get CBUS events
*
* Returns CBUS event status.
*
* @param[in]  inst           	Adapter driver instance returned by @ref Sii9777Create()
* @param[out] poState		Pointer to a variable to copy CBUS events status, \c *poState:
*
*****************************************************************************/
SiiRetVal_t Sii9777CbusEventQuery( SiiInst_t inst, Sii9777CbusEvt_t *pEvt );

/******************************************************************************/
/**
* @brief VBUS power request.
*
* This function must be called by the application after VBUS power request processing. 
* This function must be called only after the VBUS power is provided or removed 
* per the request given through the Sii9777VbusRequestQuery() function. 
* After calling Sii9777VbusRequestGrant(), the request changes to SII9777_VBUS_REQ__NONE 
* until a new request is generated.
*
* @param[in]  inst      Driver instance handle obtained by calling Sii9777Create.
*
* @retval SiiRetVal_t	See general SII_RETVAL definitions
*
*******************************************************************************/
SiiRetVal_t Sii9777VbusRequestGrant( SiiInst_t inst );

/******************************************************************************/
/**
* @brief Local DEVCAP registers writing
*
* This function sets or gets local DEVCAP register values.
*
* @param[in]  inst    Driver instance handle obtained by calling Sii9777Create.
* @param[in]  pData   Pointer to the buffer which indicates the device capability register values.
* @param[in]  offset  Offset of the first DEVCAP register
* @param[in]  length  Number of bytes to read/write.
*
* @retval     SiiRetVal_t See general SII_RETVAL definitions
*
*******************************************************************************/
SiiRetVal_t Sii9777CbusLocalDevcapSet( SiiInst_t inst, uint8_t* pData, uint8_t offset, uint8_t length );
SiiRetVal_t Sii9777CbusLocalDevcapGet( SiiInst_t inst, uint8_t* pData, uint8_t offset, uint8_t length );

/******************************************************************************/
/**
* @brief Local DEVCAP POW field.
*
* This function reads/writes the local DEVCAP POW field. 
* Note1: it is a high level API, which calls Sii9777CbusLocalDevcapSet/ Sii9777CbusLocalDevcapGet.
* Note2: If Sii9777CbusLocalDevcapPowSet is called, 
*        Sii9777CbusDcapChgSend should be called to trigger remote peer device 
*        to read the new DEVCAP register values when Cbus is already connected.
*
* @param[in]  inst      Driver instance handle obtained by calling Sii9777Create.
* @param[out] pbCbusPow Pointer to the Enumerator which indicates the Cbus DEVCAP POW data:
*                        0x00: Remove Vbus power
*                        0x01: Provide Vbus power
*
* @retval SiiRetVal_t	See general SII_RETVAL definitions
*
*******************************************************************************/
SiiRetVal_t Sii9777CbusLocalDevcapPowSet( SiiInst_t inst, Sii9777DevCapVbusPow_t* pbCbusPow );
SiiRetVal_t Sii9777CbusLocalDevcapPowGet( SiiInst_t inst, Sii9777DevCapVbusPow_t* pbCbusPow );

/******************************************************************************/
/**
* @brief Local DEVCAP Video Link Mode field.
*
* This function reads/writes the local DEVCAP Video Link Mode field. 
*  Note1: it is a high level API, which calls Sii9777CbusLocalDevcapSet/ Sii9777CbusLocalDevcapGet.
*  Note2: If Sii9777CbusLocalDevcapVideoLinkModeSet is called, 
*  Sii9777CbusDcapChgSend should be called to trigger remote peer device 
*  to read the new DEVCAP register values when Cbus is already connected.
*
* @param[in]  inst          Driver instance handle obtained by calling Sii9777Create.
* @param[out] pVidLinkMode  Pointer to the Enumerator which indicates the Cbus DEVCAP video link mode data:
*                           0x00: SII_9777_DEVCAP_VID_LINK_MODE__SUPP_NONE
*                           0x01: SII_9777_DEVCAP_VID_LINK_MODE__SUPP_RGB444
*                           0x02: SII_9777_DEVCAP_VID_LINK_MODE__SUPP_YCBCR444
*                           0x04: SII_9777_DEVCAP_VID_LINK_MODE__SUPP_YCBCR422
*                           0x08: SII_9777_DEVCAP_VID_LINK_MODE__SUPP_PPIXEL
*                           0x10: SII_9777_DEVCAP_VID_LINK_MODE__SUPP_ISLANDS
*                           0x20: SII_9777_DEVCAP_VID_LINK_MODE__SUPP_VGA
*
* @retval      SiiRetVal_t  See general SII_RETVAL definitions
*
*******************************************************************************/
SiiRetVal_t Sii9777CbusLocalDevcapVideoLinkModeSet( SiiInst_t inst, Sii9777DevCapVidLinkMode_t* pVidLinkMode );
SiiRetVal_t Sii9777CbusLocalDevcapVideoLinkModeGet( SiiInst_t inst, Sii9777DevCapVidLinkMode_t* pVidLinkMode );

/******************************************************************************/
/**
* @brief Local DEVCAP Audio Link Mode field.
*
* This function reads/writes the local DEVCAP Audio Link Mode field. 
* Note1: it is a high level API, which calls Sii9777CbusLocalDevcapSet/ Sii9777CbusLocalDevcapGet.
* Note2: If Sii9777CbusLocalDevcapAudioLinkModeSet is called, 
* Sii9777CbusDcapChgSend should be called to trigger remote peer device 
* to read the new DEVCAP register values when Cbus is already connected.
*
* @param[in]  inst          Driver instance handle obtained by calling Sii9777Create.
* @param[out] pAudLinkMode  Pointer to the Enumerator which indicates Cbus DEVCAP audio link mode data:
*                           0x00: SII_9777_DEVCAP_AUD_LINK_MODE__NONE
*                           0x01: SII_9777_DEVCAP_AUD_LINK_MODE__AUD_2CH
*                           0x02: SII_9777_DEVCAP_AUD_LINK_MODE__AUD_8CH
*
* @retval SiiRetVal_t	    See general SII_RETVAL definitions
*
*******************************************************************************/
SiiRetVal_t Sii9777CbusLocalDevcapAudioLinkModeSet( SiiInst_t inst, Sii9777DevCapAudLinkMode_t* pAudLinkMode );
SiiRetVal_t Sii9777CbusLocalDevcapAudioLinkModeGet( SiiInst_t inst, Sii9777DevCapAudLinkMode_t* pAudLinkMode );

/******************************************************************************/
/**
* @brief Local DEVCAP Feature Flag field.
*
* This function reads/writes the local DEVCAP Feature Flag field. 
* Note1: it is a high level API, which calls Sii9777CbusLocalDevcapSet/ Sii9777CbusLocalDevcapGet.
* Note2: If Sii9777CbusLocalDevcapFeatureFlagSet is called, 
* Sii9777CbusDcapChgSend should be called to trigger remote peer device 
* to read the new DEVCAP register values when Cbus is already connected.
*
* @param[in]  inst          Driver instance handle obtained by calling Sii9777Create.
*
* @param[out] pFeatureFlag   Pointer to the Enumerator which indicates the Cbus DEVCAP feature flag data:
*                            0x00: SII_9777_DEVCAP_FEATURE_FLAG__NONE
*                            0x01: SII_9777_DEVCAP_FEATURE_FLAG__RCP_SUPPORT
*                            0x02: SII_9777_DEVCAP_FEATURE_FLAG__RAP_SUPPORT
*                            0x04: SII_9777_DEVCAP_FEATURE_FLAG__SP_SUPPORT
*                            0x08: SII_9777_DEVCAP_FEATURE_FLAG__UCP_SEND_SUPPORT
*                            0x10: SII_9777_DEVCAP_FEATURE_FLAG__UCP_RCVD_SUPPORT
*                            0x20: SII_9777_DEVCAP_FEATURE_FLAG__XVYCC_SUPPORT
*                            0x40: SII_9777_DEVCAP_FEATURE_FLAG__RBP_SUPPORT
*
* @retval SiiRetVal_t See general SII_RETVAL definitions
*
*******************************************************************************/
SiiRetVal_t Sii9777CbusLocalDevcapFeatureFlagSet( SiiInst_t inst, Sii9777DevCapFeatureFlag_t* pFeatureFlag );
SiiRetVal_t Sii9777CbusLocalDevcapFeatureFlagGet( SiiInst_t inst, Sii9777DevCapFeatureFlag_t* pFeatureFlag );

/******************************************************************************/
/**
* @brief Local DEVCAP Video Type field.
*
* This function reads/writes the local DEVCAP Video Type field. 
* Note1: it is a high level API, which calls Sii9777CbusLocalDevcapSet/ Sii9777CbusLocalDevcapGet.
* Note2: If Sii9777CbusLocalDevcapVideoTypeSet is called, 
* Sii9777CbusDcapChgSend should be called to trigger remote peer device 
* to read the new DEVCAP register values when Cbus is already connected.
*
* @param[in]  inst          Driver instance handle obtained by calling Sii9777Create.
* @param[out] pVideoType    Pointer to the Enumerator which indicates the Cbus DEVCAP video type data:
*                           0x00: SII_9777_DEVCAP_VIDEO_TYPE__NONE
*                           0x01: SII_9777_DEVCAP_VIDEO_TYPE__VT_GRAPHICS
*                           0x02: SII_9777_DEVCAP_VIDEO_TYPE__VT_PHOTO
*                           0x04: SII_9777_DEVCAP_VIDEO_TYPE__VT_CINEMA
*                           0x08: SII_9777_DEVCAP_VIDEO_TYPE__VT_GAME
*                           0x80: SII_9777_DEVCAP_VIDEO_TYPE__SUPP_VT
*
* @retval SiiRetVal_t See general SII_RETVAL definitions
*
*******************************************************************************/
SiiRetVal_t Sii9777CbusLocalDevcapVideoTypeSet( SiiInst_t inst, Sii9777DevCapVideoType_t* pVideoType );
SiiRetVal_t Sii9777CbusLocalDevcapVideoTypeGet( SiiInst_t inst, Sii9777DevCapVideoType_t* pVideoType );

/******************************************************************************/
/**
* @brief Send DCAP_CHG command to remote peer device.
*
* This function triggers to send DCAP_CHG command to remote peer device.
*
* @param[in]  inst          Driver instance handle obtained by calling Sii9777Create.
*
* @retval SiiRetVal_t	    See general SII_RETVAL definitions
*
* @note refer to event 'SII_DRV_ADAPT_CBUS_EVT__DEVCAP_NOTIFICATION_FAILED & SII_DRV_ADAPT_CBUS_EVT__DEVCAP_NOTIFICATION_SUCCEEDED'
*       to get the sending result
*
*******************************************************************************/
SiiRetVal_t Sii9777CbusDcapChgSend( SiiInst_t inst );

/******************************************************************************/
/**
* @brief Read the new remote DEVCAP values
*
* Whenever a remote peer changes its DEVCAP registers, 
* the local device gets notified and reads the registers into a local cache. 
* After the read is done, the driver issues a SII9777_CBUS_EVT__REMOTE_DEVCAP_CHANGED notification.
* The application is expected to call this function to read the new remote DEVCAP values.
* Note: This function does not create CBUS traffic and reads remote values from the local cache.
*
* @param[in]  inst    Driver instance handle obtained by calling Sii9777Create.
* @param[out] pData   Pointer to the buffer which indicates the device capability register values
* @param[in]  offset  Offset of the first DEVCAP register
* @param[in]  length  Number of bytes to read
*
* @retval     SiiRetVal_t See general SII_RETVAL definitions
*
*******************************************************************************/
SiiRetVal_t Sii9777CbusRemoteDevcapQuery( SiiInst_t inst, uint8_t* pData, uint8_t offset, uint8_t length );

/******************************************************************************/
/**
* @brief local extended DEVCAP register values
*
* Sets or gets local extended DEVCAP register values.
*
* @param[in]  inst    Driver instance handle obtained by calling Sii9777Create.
* @param[out] pData   Pointer to the buffer which indicates the extended device capability register values.
* @param[in]  offset  Offset of the first XDEVCAP register
* @param[in]  length  Number of bytes read/write
*
* @retval    SiiRetVal_t See general SII_RETVAL definitions
*
*******************************************************************************/
SiiRetVal_t Sii9777CbusLocalXDevcapSet( SiiInst_t inst, uint8_t* pData, uint8_t offset, uint8_t length );
SiiRetVal_t Sii9777CbusLocalXDevcapGet( SiiInst_t inst, uint8_t* pData, uint8_t offset, uint8_t length );

/******************************************************************************/
/**
* @brief Remote XDEVCAP registers
*
* Whenever a remote peer changes its DEVCAP registers, 
* the local device gets notified and reads the registers into a local cache. 
* After the read is done, the driver issues a SII9777_CBUS_EVT__REMOTE_DEVCAP_CHANGED notification.
* The application is expected to call this function to read the new remote XDEVCAP values.
* Note: This function does not create CBUS traffic and reads remote values from the local cache.
*
* @param[in]  inst    Driver instance handle obtained by calling Sii9777Create.
* @param[out] pData   Pointer to the buffer which indicates the extended device capability register values
* @param[in]  offset  Offset of the first XDEVCAP register
* @param[in]  length  Number of bytes to read
*
* @retval SiiRetVal_t See general SII_RETVAL definitions
*
*******************************************************************************/
SiiRetVal_t Sii9777CbusRemoteXDevcapQuery( SiiInst_t inst, uint8_t* pData, uint8_t offset, uint8_t length );

/******************************************************************************/
/**
* @brief Remote burst data
*
* This function sends/receives burst data to/from remote device.  
*
* @param[in]  inst    Driver instance handle obtained by calling Sii9777Create.
* @param[out] pData   Pointer to the buffer which indicates the scratch pad register values.
* @param[in]  offset  Offset of the first SCRPAD register
* @param[in]  length  Number of bytes to send/receive.
*
* @retval SiiRetVal_t See general SII_RETVAL definitions
*
*******************************************************************************/
SiiRetVal_t Sii9777CbusBurstSend( SiiInst_t inst, uint8_t* pData, uint8_t offset, uint8_t length );
SiiRetVal_t Sii9777CbusBurstReceive( SiiInst_t inst, uint8_t* pData, uint8_t offset, uint8_t length );

/******************************************************************************************************/
/**
* @brief Read received MSC message
*
* This function sends given MSC message to the remote peer.
*
* @param[in]  inst          Driver instance handle obtained by calling Sii9777Create.
* @param[out] pMscCmd       Pointer to the MSC message.
*
* @retval     SiiRetVal_t   See general SII_RETVAL definitions
*
********************************************************************************************************/
SiiRetVal_t Sii9777CbusMscMsgReceive( SiiInst_t inst, Sii9777MscCmd_t* pMscCmd );
SiiRetVal_t Sii9777CbusMscMsgSend( SiiInst_t inst, Sii9777MscCmd_t* pMscCmd );

#ifdef __cplusplus
}
#endif

#endif // SII9777_MHL_FUNC_H

