/*******************************************************************************
*
* Copyright 2014, 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_common.h
*
* @brief Host Driver for SiI9777 device.
*
*******************************************************************************/

#ifndef SII9777_COMMON_H
#define SII9777_COMMON_H

#ifdef __cplusplus
extern "C"{
#endif


#include "sii9777_platform_api.h"

/*
General RETVAL codes
SII_RETVAL__SUCCESS	    0   Driver instance handle obtained by calling 
                            Sii9777Create. API successfully completed. 
SII_RETVAL__INST_ERR	1   Wrong or Invalid instance passed
SII_RETVAL__HOST_ERR	2   I2C / SPI host interface error
*/

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

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

/******************************************************************************/
/**
* @brief Adapter Driver creation
*
* Allocates resources for Adapter Driver and all child modules.
* This function has to be called before using of any other module function.
* This function also registers a callback function that is called
* when any status change event occurs.
*
* @param[in] devId          Hardware device instantiation identification number.
*                           Set this to 0 for a single Sii9777.
*                           When the system includes more than one instance of Sii9777, 
*						    The user must make sure that each instantiation is created with a unique devId.
*                           devId is passed into the platform host interface layer 
*						    and is used to select a different I2C device address 
*						    or a different SPI chip select signal.
*
* @param[in] pCallbackFunc  Pointer to a call back function invoked by the driver 
*                           when any status change event happens. If set as NULL, the callback is not invoked.
* @param[in] pConfig        Pointer to a static configuration structure containing static
*                           configuration parameters for this driver instantiation.
* @return SiiInst_t         Driver instance handle required by all other functions. 
*                           If equal to zero then creation of instance has failed
*
*******************************************************************************/
SiiInst_t Sii9777Create( SiiPlatformDevId_t devId, Sii9777EventCallbackFunc_t pCallbackFunc, Sii9777Config_t* pConfig );

/******************************************************************************/
/**
* @brief Adapter Driver deletion
*
* Frees resources allocated by Sii9777Create for the driver instance identified by inst and shuts down the driver.
* After this function is called, no other module functions can be called for this driver instance until 
* Sii9777Create() is called again and a new driver handle is received.
*
* @param[in] inst Driver instance handle obtained from calling Sii9777Create. 
*                 This is used by Sii9777Delete to identify the driver instance to delete.
*
*******************************************************************************/
void Sii9777Delete( SiiInst_t inst );

/******************************************************************************/
/**
* @brief Reconfigure and reset
*
* Set: Reconfigures all static parameters and resets device driver.
* Get: Fills in the configuration structure with the current static configuration parameters.
*
* @param[in]  inst        Driver instance handle obtained by calling Sii9777Create.
* @param[in]  pConfig     Pointer to a configuration structure containing static configuration
*                         parameters for driver instantiation or driver re-configration.
*
* @retval     SiiRetVal_t See general SII_RETVAL definitions in the beginning of the file
*
*******************************************************************************/
SiiRetVal_t Sii9777ConfigureSet( SiiInst_t inst, Sii9777Config_t* pConfig );
SiiRetVal_t Sii9777ConfigureGet( SiiInst_t inst, Sii9777Config_t* pConfig );

/******************************************************************************/
/**
* @brief Adapter Driver handle
*
* This function is expected to be called by the user application  each  time 
* the SiI9777 chip generates an interrupt. If the interrupt signal (INT) from 
* the SiI9777 is not connected to application processor, this function must be 
* called periodically with an time interval of no more than 100msec. 
* This function checks if there are any pending notifications from the SiI9777 chip, 
* services them and may generate an SII9777_EVENT   ‘notifications?by calling 
* the Sii9777EevntCallbackFunc_t callback function registered through Sii9777Create().
*
* @param[in]  inst    Driver instance handle obtained by calling Sii9777Create.
*
* @retval See general SII_RETVAL definitions
*
*******************************************************************************/
SiiRetVal_t Sii9777Handle( SiiInst_t inst );

/******************************************************************************/
/**
* @brief Adapter Driver handle
*
* Controls whether SiI9777 is in standby mode or full operational mode.
* In standby mode SiI9777 is configured for low power consumption and TMDS
* impedance termination is turned off. After Sii9777Create has been called
* Sii9777StandbySet(inst, false) must be called in order to enable SiI9777
* device to be fully operational.
* Note : User application can still change configuration while in standby mode. 
* Note : Output ports must still be enabled separately through
*        Sii9777TmdsEnableSet() function.
*
* @param[in]  inst    Driver instance handle obtained by calling Sii9777Create.
* @param[in]  pbOn    true  : Put SiI9777 device in standby mode.
*                     false : Put SiI9777 in full operational mode.
*
* @retval See general SII_RETVAL definitions
*
*******************************************************************************/
SiiRetVal_t Sii9777StandbySet( SiiInst_t inst, bool_t* pbOn );
SiiRetVal_t Sii9777StandbyGet( SiiInst_t inst, bool_t* pbOn );

/******************************************************************************/
/**
* @brief Chip ID inquiry
*
* ChipIdStat should contain 0x9777 after calling.
*
* @param[in]  inst        Driver instance handle obtained by calling Sii9777Create.
* @param[out] pChipIdStat Pointer to a variable in which the chip ID information is returned.  
*
* @retval     See general SII_RETVAL definitions
*
*******************************************************************************/
SiiRetVal_t Sii9777ChipIdQuery( SiiInst_t inst, uint32_t* pChipIdStat );

/******************************************************************************/
/**
* @brief Chip revision
*
* Returns Chip revision number.
*
* @param[in]  inst           Driver instance handle obtained by calling Sii9777Create.
* @param[out] pChipRevStat   Pointer to a variable in which the chip revision information is returned.
*
* @retval     SiiRetVal_t    See general SII_RETVAL definitions in the beginning of the file.
*
*******************************************************************************/
SiiRetVal_t Sii9777ChipRevisionQuery( SiiInst_t inst, uint32_t* pChipRevStat );

/******************************************************************************/
/**
* @brief Product ID
*
* Returns Product ID.
*
* @param[in]  inst              Driver instance handle obtained by calling Sii9777Create.
* @param[out] pProductIdStat    Pointer to a variable in which the product ID information is returned.
*
* @retval     SiiRetVal_t       See general SII_RETVAL definitions in the beginning of the file. 
*
*******************************************************************************/
SiiRetVal_t Sii9777ProductIdQuery( SiiInst_t inst, uint32_t* pProductIdStat );

/******************************************************************************/
/**
* @brief Firmware Version Number
*
* Outputs firmware version number.
*
* @param[in]  inst          Driver instance handle obtained by calling Sii9777Create.
* @param[out] pVersionStat  Pointer to a variable in which the firmware version information is returned.
*
* @retval     SiiRetVal_t   See general SII_RETVAL definitions in the beginning of the file.  
*
*******************************************************************************/
SiiRetVal_t Sii9777FirmwareVersionQuery( SiiInst_t inst, uint32_t* pVersionStat );

/******************************************************************************/
/**
* @brief Firmware build time stamp
*
* Outputs firmware release time in number of seconds since 1/1/1970
*
* @param[in]  inst        Driver instance handle obtained by calling Sii9777Create.
* @param[out] pTimeStamp  Firmware release time in number of seconds since 1/1/1970.
*
* @retval     See general SII_RETVAL definitions  
*
*******************************************************************************/
SiiRetVal_t Sii9777ReleaseTimeStampQuery( SiiInst_t inst, uint32_t* pTimeStamp );

/******************************************************************************/
/**
* @brief Booting status inquiry
*
* Device boot status inquiry. Returns chip boot status.
* SII9777_EVENT__BOOT_DONE event is generated 
* when Boot status changes from SII9777_BOOT_STAT__IN_PROGRESS 
* to SII9777_BOOT_STAT__SUCCESS or SII9777_BOOT_STAT__FAILURE.
*
* @param[in]  inst        Driver instance returned by calling Sii9777Create.
* @param[out] pBootStat   Pointer to a variable to return booting status
*                         SII9777_BOOT_STAT__SUCCESS       Booting is done successfully
*                         SII9777_BOOT_STAT__IN_PROGRESS   Booting is in progress
*                         SII9777_BOOT_STAT__FAILURE       Booting failed
*
* @retval     See general SII_RETVAL definitions  
*
*******************************************************************************/
SiiRetVal_t Sii9777BootStatusQuery( SiiInst_t inst, Sii9777BootStat_t* pBootStat );

/******************************************************************************/
/**
* @brief Event Flags mask request
*
* Controls which events will cause notification handler to be called. 
*
* @param[in]  inst          Driver instance handle obtained by calling Sii9777Create.
* @param[in]  pMask         Pointer to a variable in which the notification mask information is returned.
*                           SII9777_EVENT__BOOT_DONE
*                           SII9777_EVENT__FLASH_DONE
*                           SII9777_EVENT__AV_LINK_CHNG
*                           SII9777_EVENT__AV_MUTE_CHNG
*                           SII9777_EVENT__PLUS_5V_CHNG
*                           SII9777_EVENT__VIDEO_TIMING_CHNG
*                           SII9777_EVENT__VIDEO_FMT_CHNG
*                           SII9777_EVENT__AUDIO_FMT_CHNG
*                           SII9777_EVENT__ISRC_CHNG
*                           SII9777_EVENT__ACP_CHNG
*                           SII9777_EVENT__SPD_CHNG
*                           SII9777_EVENT__HDCP_STATUS_CHNG
*                           SII9777_EVENT__MHL_LINK_CHNG
*                           SII9777_EVENT__CBUS_EVENT
*
* @retval    SiiRetVal_t	See general SII_RETVAL definitions in the beginning of the file
*
*******************************************************************************/
SiiRetVal_t Sii9777EventFlagsMaskSet( SiiInst_t inst, Sii9777EventFlags_t* pFlags );
SiiRetVal_t Sii9777EventFlagsMaskGet( SiiInst_t inst, Sii9777EventFlags_t* pFlags );

/******************************************************************************/
/**
* @brief Event Flags status inquiry
*
* Gets a bitmask of current events. 
* Typically, only un-masked events are returned, 
* since masked events get cleared upon event call-back of Sii9777EventCallbackFunc_t.
*
* @param[in]  inst          Driver instance handle obtained by calling Sii9777Create.
* @param[in]  pMask         Pointer to a variable in which the notification mask information is returned.
*                           SII9777_EVENT__BOOT_DONE
*                           SII9777_EVENT__FLASH_DONE
*                           SII9777_EVENT__AV_LINK_CHNG
*                           SII9777_EVENT__AV_MUTE_CHNG
*                           SII9777_EVENT__PLUS_5V_CHNG
*                           SII9777_EVENT__VIDEO_TIMING_CHNG
*                           SII9777_EVENT__VIDEO_FMT_CHNG
*                           SII9777_EVENT__AUDIO_FMT_CHNG
*                           SII9777_EVENT__ISRC_CHNG
*                           SII9777_EVENT__ACP_CHNG
*                           SII9777_EVENT__SPD_CHNG
*                           SII9777_EVENT__HDCP_STATUS_CHNG
*                           SII9777_EVENT__MHL_LINK_CHNG
*                           SII9777_EVENT__CBUS_EVENT
*
* @retval    SiiRetVal_t	See general SII_RETVAL definitions in the beginning of the file.
*
*******************************************************************************/
SiiRetVal_t Sii9777EventFlagsQuery( SiiInst_t inst, Sii9777EventFlags_t* pFlags );

/******************************************************************************/
/**
* @brief Event Flags clear request
*
* Clear internal event register bits. 
* This function is only needed for unmasked events. 
* Masked events are automatically cleared upon event call-back of Sii9777EventCallbackFunc_t.   
*
* @param[in]  inst          Driver instance handle obtained by calling Sii9777Create.
* @param[in]  pMask         Pointer to a variable containing the notification maskto clear.
*                           SII9777_EVENT__BOOT_DONE
*                           SII9777_EVENT__FLASH_DONE
*                           SII9777_EVENT__AV_LINK_CHNG
*                           SII9777_EVENT__AV_MUTE_CHNG
*                           SII9777_EVENT__PLUS_5V_CHNG
*                           SII9777_EVENT__VIDEO_TIMING_CHNG
*                           SII9777_EVENT__VIDEO_FMT_CHNG
*                           SII9777_EVENT__AUDIO_FMT_CHNG
*                           SII9777_EVENT__ISRC_CHNG
*                           SII9777_EVENT__ACP_CHNG
*                           SII9777_EVENT__SPD_CHNG
*                           SII9777_EVENT__HDCP_STATUS_CHNG
*                           SII9777_EVENT__MHL_LINK_CHNG
*                           SII9777_EVENT__CBUS_EVENT
*
*
* @retval    SiiRetVal_t	See general SII_RETVAL definitions in the beginning of the file.
*
*******************************************************************************/
SiiRetVal_t Sii9777EventFlagsStatusClear( SiiInst_t inst, Sii9777EventFlags_t* pFlags );

/******************************************************************************/
/**
* @brief Gpio configuration set/get
*
* Input / Output configuration. 
* ??enables GPIO to be an output, 
* ??enables GPIO to be an input. 
* By default all GPIOs are configured as input.
*
* @param[in] inst	Driver instance handle obtained by calling Sii9777Create.
* @param[in] pMask	Each bit represents 1 GPIO pin based on the following assignment:
*                   Bit 0   : GPIO0
*                   Bit 1   : GPIO1
*                   Bit 2   : GPIO2
*                   Bit 3   : GPIO3
*                   Bit 4   : GPIO4
*                   Bit 5..7: unused
*
* @retval     SiiRetVal_t See general SII_RETVAL definitions in the beginning of the file
*
*******************************************************************************/
SiiRetVal_t Sii9777GpioConfigSet( SiiInst_t inst, uint16_t* pGpioPins );
SiiRetVal_t Sii9777GpioConfigGet( SiiInst_t inst, uint16_t* pGpioPins );

/******************************************************************************/
/**
* @brief Sets/Clears gpio bits
*
* Controls the level of all output GPIOs. 
* GPIO level can be set high by calling ‘Sii9777ChipGpioSet?
* with the associated GPIO bit set to ?? 
* Low level can be set by calling ‘Sii9777ChipGpioClr?
* with the associated GPIO bit set to ??
*
* @param[in] inst	Driver instance handle obtained by calling Sii9777Create.
* @param[in] pMask	Each bit represents 1 GPIO pin based on the following assignment:
*                   Bit 0   : GPIO0
*                   Bit 1   : GPIO1
*                   Bit 2   : GPIO2
*                   Bit 3   : GPIO3
*                   Bit 4   : GPIO4
*                   Bit 5..7: unused
*
* @retval     SiiRetVal_t See general SII_RETVAL definitions in the beginning of the file
*
*******************************************************************************/
SiiRetVal_t Sii9777GpioOutputSet( SiiInst_t inst, uint16_t* pGpioPins );
SiiRetVal_t Sii9777GpioOutputClr( SiiInst_t inst, uint16_t* pGpioPins );

/******************************************************************************/
/**
* @brief Provides the level status of all gpio signals
*
* @param[in] inst	Driver instance handle obtained by calling Sii9777Create.
* @param[in] pMask	Each bit represents 1 GPIO pin based on the following assignment:
*                   Bit 0   : GPIO0
*                   Bit 1   : GPIO1
*                   Bit 2   : GPIO2
*                   Bit 3   : GPIO3
*                   Bit 4   : GPIO4
*                   Bit 5..7: unused
*
* @retval     SiiRetVal_t See general SII_RETVAL definitions in the beginning of the file
*
*******************************************************************************/
SiiRetVal_t Sii9777GpioQuery( SiiInst_t inst, uint16_t* pGpioPins );

/******************************************************************************/
/**
* @brief Provides mask related to GPIO event control
*
* Any bit that is set causes an event ‘SII9777_EVENT_FLAGS__GPIO_CHNG?
* to be generated as soon if associated GPIO is configured as an input
* and input level was changed either from low to high or from  high to low.
*
* @param[in] inst	Driver instance handle obtained by calling Sii9777Create.
* @param[in] pMask	Bit field in which each bit represents 1 GPIO pin based on the following assignment:
*                   Bit 0   : GPIO0
*                   Bit 1   : GPIO1
*                   ..
*                   ..
*                   Bit 10   : GPIO10
*                   Bit 11   : GPIO11
*                   Bit 12?5 : reserved
*
* @retval     SiiRetVal_t See general SII_RETVAL definitions in the beginning of the file
*
*******************************************************************************/
SiiRetVal_t Sii9777GpioEventMaskSet( SiiInst_t inst, uint16_t*  pGpioPins );
SiiRetVal_t Sii9777GpioEventMaskGet( SiiInst_t inst, uint16_t*  pGpioPins );

/******************************************************************************/
/**
* @brief Firmware update initialization (Obsoleted)
*
* Erases the SPI flash memory containing SiI9777’s firmware.
* This function also sets the firmware image’s byte offset to 0.
*
* @param[in]  inst         Driver instance handle obtained by calling Sii9777Create.
*
* @retval     SiiRetVal_t  See general SII_RETVAL definitions in the beginning of the file.
*
*******************************************************************************/
SiiRetVal_t Sii9777FirmwareInit( SiiInst_t inst );

/******************************************************************************/
/**
* @brief initialize flash operation
*
* Erases the SPI flash memory containing SiI9777’s firmware.
* This function also sets the firmware image’s byte offset to 0.
*
* @param[in]  inst         Driver instance handle obtained by calling Sii9777Create.
* @param[in]  operation    Flash operation code:
*                          SII9777_FLASH_OPERATION__READ
*                          SII9777_FLASH_OPERATION__WRITE
*                          SII9777_FLASH_OPERATION__WRITE_VERIFY
* @param[in]  target       Target :
*                          SII9777_FLASH_TARGET__FULL_DEVICE
*                          SII9777_FLASH_TARGET__EDID_TABLES
*
* @retval     SiiRetVal_t  See general SII_RETVAL definitions in the beginning of the file.
*
*******************************************************************************/
SiiRetVal_t Sii9777FlashInit( SiiInst_t inst, Sii9777FlashOperation_t operation, Sii9777FlashTarget_t target );

/******************************************************************************/
/**
* @brief Firmware update (obsoleted)
*
* Updates SiI9777’s external SPI flash memory with new firmware and power-up default EDID configurations.
* The entire firmware binary is required to be updated by smaller chunks of no more than 256 bytes each. 
* After each update request the user application must wait for the SII_DRV_ADAPT_EVENT__ACCESS_DONE   
* event before updating the calling Sii9777FirmwareUpdate() again or when all data chunks have been sent 
* the user application should call SiiFirmwareRestart to execute new firmware release.  
* Note: User application should always start firmware update procedure with Sii9777FirmwareUpdateInit() 
* before calling Sii9777FirmwareUpdate().
*
* @param[in]  inst     Driver instance handle obtained by calling Sii9777Create.
* @param[in]  pBuffer  Pointer to a memory buffer containing firmware binary.
* @param[in]  length  Number of bytes in the firmware binary. 256 is the maximum length.
*
* @retval     SiiRetVal_t  See general SII_RETVAL definitions in the beginning of the file.
*
*******************************************************************************/
SiiRetVal_t Sii9777FirmwareUpdate( SiiInst_t inst, const uint8_t* pBuffer, uint16_t length );

/******************************************************************************/
/**
* @brief Flash update
*
* Programs SiI9777’s external SPI flash memory with new firmware (including power-up
* default EDID configurations) initiated by ‘Sii9777FirmwareErase()?or  with just
* power-up default EDID configurations initiated by ‘Sii9777EdidErase()?
* Flash programming requires to be updated by chunks of no more than 256 bytes each.
* The internal flash write pointer is incremented after each successful write.
* The user application must wait for SII9777_EVENT_FLAGS__FLASH_DONE before issuing
* a call to Sii9777FlashUpdate with the next chunk of data. Once all data chunks have
* been sent, the user application should call SiiFirmwareRestart to execute the new
* firmware image.  Note: The user application should always initiate flash programming
* sequence with either Sii9777FirmwareErase() or Sii9777EdidErase() before calling
* Sii9777FlashUpdate().
*
* @param[in]  inst     Driver instance handle obtained by calling Sii9777Create.
* @param[in]  pBuffer  Pointer to a memory buffer containing firmware binary.
* @param[in]  length  Number of bytes in the firmware binary. 256 is the maximum length.
*
* @retval     SiiRetVal_t  See general SII_RETVAL definitions in the beginning of the file.
*
*******************************************************************************/
SiiRetVal_t Sii9777FlashUpdate( SiiInst_t inst, uint8_t* pBuffer, uint16_t length );

/******************************************************************************/
/**
* @brief Returns status of flash update operation. (Obsoleted)
*
* This function can optionally be used by user application to find out 
* if latest Sii9777FirmwareInit request or Sii9777FirmwareUpdate request 
* was processed successfully. 
*
* @param[in]  inst      Driver instance handle obtained by calling Sii9777Create.
* @param[out] poStatus  Pointer to a variable in which the status information is returned:
*                       SII9777_FIRMWARE_STATUS__READY
*                       SII9777_FIRMWARE_STATUS__IN_PROGRESS
*                       SII9777_FIRMWARE_STATUS__FAILURE
*
* @retval    SiiRetVal_t  See general SII_RETVAL definitions in the beginning of the file.
*
*******************************************************************************/
SiiRetVal_t Sii9777FirmwareStatusQuery( SiiInst_t inst, Sii9777FlashStat_t* poStatus );

/******************************************************************************/
/**
* @brief Returns status of flash programming operation.
*
* This function can optionally be used by user application to determine the status of
* the last call to either Sii9777FirmwareErase, Sii9777EdidErase or Sii9777FlashUpdate.
* This function can optionally be used by user application to find out 
* if latest Sii9777FirmwareInit request or Sii9777FirmwareUpdate request 
* was processed successfully. 
*
* @param[in]  inst      Driver instance handle obtained by calling Sii9777Create.
* @param[out] poStatus  Pointer to a variable in which the status information is returned:
*                       SII9777_FIRMWARE_STATUS__READY
*                       SII9777_FIRMWARE_STATUS__IN_PROGRESS
*                       SII9777_FIRMWARE_STATUS__FAILURE
*
* @retval    SiiRetVal_t  See general SII_RETVAL definitions in the beginning of the file.
*
*******************************************************************************/
SiiRetVal_t Sii9777FlashStatusQuery( SiiInst_t inst, Sii9777FlashStat_t* poStatus );

/******************************************************************************/
/**
* @brief Restarts SiI9777 device.
*
* Restarts the SiI9777 device. If firmware was updated then SiI9777 will execute this new firmware version.
* Typically, this function is called after firmware has been updated.
* Before firmware is restarted the Sii9777 device will first validate the content 
* of the flash device by executing a checksum (32-bit) verification followed by 
* generating an SII9777_EVENT__BOOT_DONE event.
* The user can inquiry the checksum result through Sii9777BootStatusQuery() function. 
*
* @param[in]  inst        Driver instance handle obtained by calling Sii9777Create.
*
* @retval    SiiRetVal_t  See general SII_RETVAL definitions in the beginning of the file.
*
*******************************************************************************/
SiiRetVal_t Sii9777FirmwareRestart( SiiInst_t inst );

/******************************************************************************/
/**
* @brief Controls Dual-Link mode.
*
* Controls scheme of video split mode.
*
* @param[in]  inst  Driver instance returned by @ref Sii9777Create()
* @param[in]  mode  Video split mode:
*                   - @ref SII9777_DUAL_LINK_MODE__LEFT_RIGHT     Video is splitted/merged by left/right half line
*                   - @ref SII9777_DUAL_LINK_MODE__EVEN_ODD       Video is splitted/merged by even/odd pixel
*                   - @ref SII9777_DUAL_LINK_MODE__PIXEL_REORDER  Video is splitted/merged by pixel reordering
*
* @retval     See general SII_RETVAL definitions
*
*******************************************************************************/
SiiRetVal_t Sii9777DualLinkModeSet( SiiInst_t inst, Sii9777DualLinkMode_t* pDualLinkMode );
SiiRetVal_t Sii9777DualLinkModeGet( SiiInst_t inst, Sii9777DualLinkMode_t* pDualLinkMode );

/******************************************************************************/
/**
* @brief      Controls whether TMDS signals of selected output port 
*             may become active or not.
*             Note : depending on other configuration TMDS output signals may 
*             still remain de-activated despite this setting is enabled.
*
* @param[in]  inst  Driver instance handle obtained by calling Sii9777Create.
*
* @param[in]  port	Output port:
*                   SII9777_TX_PORT__0
*                   SII9777_TX_PORT__1
*                   SII9777_TX_PORT__2
*
* @param[in]  pbOn	true  : Allow TMDS output signals to become active.
*                   false : Forces TMDS output signals to be turned off.
*
* @retval    SiiRetVal_t See general SII_RETVAL definitions 
*
*******************************************************************************/
SiiRetVal_t Sii9777TmdsEnableSet( SiiInst_t inst, Sii9777TxPort_t port, bool_t* pbOn );
SiiRetVal_t Sii9777TmdsEnableGet( SiiInst_t inst, Sii9777TxPort_t port, bool_t* pbOn );

/******************************************************************************/
/**
* @brief      Controls which audio source is inserted to selected HDMI output port.
*
* @param[in]  inst  Driver instance handle obtained by calling Sii9777Create.
*
* @param[in]  port	Output port:
*                   SII9777_TX_PORT__0
*                   SII9777_TX_PORT__1
*                   SII9777_TX_PORT__2
*
* @param[i/o] pAudioSrc
*                   SII9777_AUDIO_SOURCE__NONE     : No Audio transmitted
*                   SII9777_AUDIO_SOURCE__RX       : Audio from Rx0…Rx3
*                   SII9777_AUDIO_SOURCE__I2S      : from I2S input
*                   SII9777_AUDIO_SOURCE__SPDIF    : from S/PDIF input
*
* @retval    SiiRetVal_t See general SII_RETVAL definitions 
*
*******************************************************************************/
SiiRetVal_t Sii9777AudioSourceSet( SiiInst_t inst, Sii9777TxPort_t port, Sii9777AudioSource_t* pAudioSrc );
SiiRetVal_t Sii9777AudioSourceGet( SiiInst_t inst, Sii9777TxPort_t port, Sii9777AudioSource_t* pAudioSrc );

/******************************************************************************/
/**
* @brief Audio format configuration for I2S/SPDIF audio insertion through HDMI transmitters.
*
* This audio format meta data will be send along with inserted audio from I2S/SPDIF input.
*
* @param[in]  inst        Driver instance handle obtained by calling Sii9777Create.
* @param[out] pAudioFmt   Pointer to a buffer to copy the audio format structure  .
*
* @retval SiiRetVal_t	  See general SII_RETVAL definitions
*
*******************************************************************************/
SiiRetVal_t Sii9777I2sSpdifAudioFormatSet( SiiInst_t inst, Sii9777AudioFmt_t *pAudioFmt );
SiiRetVal_t Sii9777I2sSpdifAudioFormatGet( SiiInst_t inst, Sii9777AudioFmt_t *pAudioFmt );

/******************************************************************************/
/**
* @brief Enables/Disables video pixel format conversion
*
* Enables/Disables video pixel format conversion. Pixel format conversion is defined
* between current incoming pixel format and user requested output pixel format.
* Note: not all conversions are supported by Sii9777 device.
*
* @param[in]  inst      Driver instance handle obtained by calling Sii9777Create.
* @param[in]  pEnable   true  : Enable video pixel format conversion
*                       false : Disable video pixel format conversion
*
* @retval     SiiRetVal_t See general SII_RETVAL definitions
*
*******************************************************************************/
SiiRetVal_t Sii9777PixelFormatConversionSet( SiiInst_t inst, bool_t* pEnable );
SiiRetVal_t Sii9777PixelFormatConversionGet( SiiInst_t inst, bool_t* pEnable );

/******************************************************************************/
/**
* @brief 
*
* Returns whether pixel format conversion is currently enabled or disabled. 
* Note : Depending on current incoming pixel format and by the user 
* requested output pixel format,
* pixel format conversion may not be supported by Sii9777 device.
*
* @param[in]  inst      Driver instance handle obtained by calling Sii9777Create.
* @param[in]  pStatus   Returned status:
*                       SII9777_PIX_FRM_CONV__ENABLED
*                       SII9777_PIX_FRM_CONV__DISABLED
*
* @retval     SiiRetVal_t See general SII_RETVAL definitions
*
*******************************************************************************/
SiiRetVal_t Sii9777PixelFormatConversionQuery( SiiInst_t inst, Sii9777PixFmtConv_t* pStatus );

/******************************************************************************/
/**
* @brief 4K horizontal timing conversion setting
*
* Selects 4K horizontal timing conversion setting.
*
* @param[in]  inst      Driver instance handle obtained by calling Sii9777Create.
* @param[in]  smpte4k   Pointer to 4K horizontal timing conversion setting.
*                       SII9777_SMPTE4K__PASSTHRU      No conversion
*                       SII9777_SMPTE4K__4096_TO_3840  SMPTE to CEA timing conversion
*                       SII9777_SMPTE4K__3840_TO_4096  CEA to SMPTE timing conversion
*
* @retval SiiRetVal_t	See general SII_RETVAL definitions
*
*******************************************************************************/
SiiRetVal_t Sii9777Smpte4kSet( SiiInst_t inst, Sii9777Smpte4k_t* smpte4k );
SiiRetVal_t Sii9777Smpte4kGet( SiiInst_t inst, Sii9777Smpte4k_t* smpte4k );

/******************************************************************************/
/**
* @brief Enable/disable TPG
*
* User control to enable / disable video test pattern generator.
*
* @param[in]  inst    Driver instance handle obtained by calling Sii9777Create.
* @param[in]  pbOn    true  : Enable test pattern generator.
*                     false : Disable test pattern generator.
*
* @retval     SiiRetVal_t See general SII_RETVAL definitions
*
*******************************************************************************/
SiiRetVal_t Sii9777TpgEnableSet( SiiInst_t inst, bool_t* pbOn );
SiiRetVal_t Sii9777TpgEnableGet( SiiInst_t inst, bool_t* pbOn );

/******************************************************************************/
/**
* @brief Test video pattern selection control
*
* Selects the output video test pattern.
*
* @param[in]  inst     Driver instance handle obtained by calling Sii9777Create.
* @param[in]  pPattern Test pattern selection enumerator:
*                      SII9777_TPG_PATTERN__RED
*                      SII9777_TPG_PATTERN__GREEN
*                      SII9777_TPG_PATTERN__BLUE
*                      SII9777_TPG_PATTERN__CYAN
*                      SII9777_TPG_PATTERN__MAGENTA
*                      SII9777_TPG_PATTERN__YELLOW
*                      SII9777_TPG_PATTERN__BLACK
*                      SII9777_TPG_PATTERN__WHITE
*                      SII9777_TPG_PATTERN__GRAYSCALE
*                      SII9777_TPG_PATTERN__CHKRBRD
*                      SII9777_TPG_PATTERN__COLORBAR
*                      SII9777_TPG_PATTERN__SPECIAL 
*
* @retval   SiiRetVal_t See general SII_RETVAL definitions
*
*******************************************************************************/
SiiRetVal_t Sii9777TpgPatternSet( SiiInst_t inst, Sii9777TpgPattern_t* pPattern );
SiiRetVal_t Sii9777TpgPatternGet( SiiInst_t inst, Sii9777TpgPattern_t* pPattern );

/******************************************************************************/
/**
* @brief Test pattern generator timing configuration control
*
* Selects the output video resolution.
*
* @param[in]  inst      Driver instance handle obtained by calling Sii9777Create.
* @param[in]  pVidRes   Video resolution enumerator (see ‘SII9777VidRes _t?for all supported formats)
*
* @retval SiiRetVal_t	See general SII_RETVAL definitions
*
*******************************************************************************/
SiiRetVal_t Sii9777TpgVidResSet( SiiInst_t inst, Sii9777VidRes_t* pVidRes );
SiiRetVal_t Sii9777TpgVidResGet( SiiInst_t inst, Sii9777VidRes_t* pVidRes );

/******************************************************************************/
/**
* @brief Controls CMS functionality
*
* Controls the Color Management System to be enabled or disabled.
* Default behavior of the firmware is to let the color management 
* be controlled by the upstream device (bypass enabled).
* This function must be called with pbOn set to false 
* before the remaining CMS API functions can be called. 
*
* @param[in]  inst  Driver instance handle obtained by calling Sii9777Create.
* @param[in]  pbOn  Pointer to a variable containing true or false Boolean values.
*
* @retval SiiRetVal_t See general SII_RETVAL definitions
*
*******************************************************************************/
SiiRetVal_t Sii9777CmsBypassSet( SiiInst_t inst, bool_t* pbOn );
SiiRetVal_t Sii9777CmsBypassGet( SiiInst_t inst, bool_t* pbOn );

/******************************************************************************/
/**
* @brief Controls saturation for a given color
*
* Controls saturation for a given color.
* This control works only if CMS module has been enabled using Sii9777CmsBypassSet().
*
* @param[in]  inst  Driver instance handle obtained by calling Sii9777Create.
* @param[in]  clr   Color index of primary or secondary color
* @param[in]  pSat  Pointer to a variable containing color saturation value (-100...+100)
*
* @retval     SiiRetVal_t See general SII_RETVAL definitions
*
*******************************************************************************/
SiiRetVal_t Sii9777CmsSaturationSet( SiiInst_t inst, Sii9777CmsColor_t clr, int8_t* pSat );
SiiRetVal_t Sii9777CmsSaturationGet( SiiInst_t inst, Sii9777CmsColor_t clr, int8_t* pSat );

/******************************************************************************/
/**
* @brief Controls hue for a given color
*
* Controls hue for a given color.
* This control works only if CMS module has been enabled using Sii9777CmsBypassSet().
*
* @param[in]  inst  Driver instance handle obtained by calling Sii9777Create.
* @param[in]  clr   Color index of primary or secondary color
* @param[in]  pHue  Pointer to a variable containing color hue (Ranges between -100...+100)
*
* @retval SiiRetVal_t See general SII_RETVAL definitions
*
*******************************************************************************/
SiiRetVal_t Sii9777CmsHueSet( SiiInst_t inst, Sii9777CmsColor_t clr, int8_t* pHue );
SiiRetVal_t Sii9777CmsHueGet( SiiInst_t inst, Sii9777CmsColor_t clr, int8_t* pHue );

/******************************************************************************/
/**
* @brief Controls white point temperature for a given color.
*
* Controls white point temperature for a given color.
* This control works only if CMS module has been enabled using Sii9777CmsBypassSet().
*
* @param[in]  inst          Driver instance handle obtained by calling Sii9777Create.
* @param[in]  clr           Color index of primary or secondary color
* @param[in]  pTemperature  Pointer to a variable containing white point temperature in Kelvin 
*                           (Ranges between 4000 and 25000 )
*
* @retval     SiiRetVal_t   See general SII_RETVAL definitions
*
*******************************************************************************/
SiiRetVal_t Sii9777CmsWhitePointTempGet( SiiInst_t inst, Sii9777CmsColor_t clr, int16_t* pTemperature );
SiiRetVal_t Sii9777CmsWhitePointTempSet( SiiInst_t inst, Sii9777CmsColor_t clr, int16_t* pTemperature );

/******************************************************************************/
/**
* @brief
* Read and write of low-level hardware register.
* These functions should only be used upon recommendation from Silicon Image.
*
* @param[in]  inst  Driver instance handle obtained by calling Sii9777Create.
*
* @param[in]  addr	16-bit register address.
*
* @param[in]  pData	Pointer to array of bytes. 
*
* @param[in]  len	Requested number of bytes to be exchanged.
*
* @retval SiiRetVal_t See general SII_RETVAL definitions 
*
*******************************************************************************/
SiiRetVal_t Sii9777ChipRegWrite( SiiInst_t inst, uint16_t  addr, uint8_t*  pData, uint8_t len);
SiiRetVal_t Sii9777ChipRegRead( SiiInst_t inst, uint16_t  addr, uint8_t*  pData, uint8_t len );

/******************************************************************************/
/**
* @brief Service mode access control.
*
* With this function user can enter/exit service mode.
* All on-chip firmware will be frozen when in service mode.
* Service data retrieval pointer is reset everytime when called with bOn = true.
*
* @param[in]  inst          Driver instance handle obtained by calling Sii9777Create.
* @param[in]  bOn           true  : Enter/Reset service mode.
*                           false : Exit service mode.
*
* @retval     SiiRetVal_t   See general SII_RETVAL definitions
*
*******************************************************************************/
SiiRetVal_t Sii9777ServiceModeSet( SiiInst_t inst, bool_t bOn );

/******************************************************************************/
/**
* @brief Service data read-out.
*
* Reads out service data.
* Please write all retrieved service data to file and send file to Silicon Image, Inc.
*
* @param[in]  inst          Driver instance handle obtained by calling Sii9777Create.
* @param[in]  pData         Pointer to array of bytes with length specified by len. 
* @param[in]  len           Requested number of bytes to be exchanged. 
*
* @retval     uint16_t      Returns number of bytes read. Returns ??when all service
*                           data has been received.
*
*******************************************************************************/
uint16_t Sii9777ServiceDataGet( SiiInst_t inst, uint8_t* pData, uint16_t len );

/******************************************************************************/

#ifdef __cplusplus
}
#endif

#endif // SII9777_COMMON_H

