/* SPDX-License-Identifier: LGPL-2.1-only OR BSD-3-Clause */
/******************************************************************************
 *
 * This file is provided under a dual license.  When you use or
 * distribute this software, you may choose to be licensed under
 * version 2.1 of the GNU Lesser General Public License
 * ("LGPLv2.1 License") or BSD License.
 *
 * LGPLv2.1 License
 *
 * Copyright(C) 2019 MediaTek Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of version 2.1 of the GNU Lesser General Public
 * License as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html for more
 * details.
 *
 * BSD LICENSE
 *
 * Copyright(C) 2019 MediaTek Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *  * Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *  * Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *  * Neither the name of the copyright holder nor the names of its
 *    contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 *****************************************************************************/

/*-----------------------------------------------------------------------------
 * $RCSfile: x_cec.h,v $
 * $Revision: #1 $
 * $Date: 2015/05/29 $
 * $Author: brianpc.huang $
 * $CCRevision: $
 * $SWAuthor: Alec Lu $
 * $MD5HEX: $
 *
 * Description:
 *         This header file contains HDMI CEC driver specific definitions,
 *         which are exported.
 *---------------------------------------------------------------------------*/

#ifndef _X_CEC_H_
#define _X_CEC_H_

/*-----------------------------------------------------------------------------
                    include files
 ----------------------------------------------------------------------------*/
#include "x_common.h"
#include "x_rm.h"

/*-----------------------------------------------------------------------------
                    macros, defines, typedefs, enums
 ----------------------------------------------------------------------------*/
/* Set operations */
#define CEC_SET_TYPE_SEND_MSG               (RM_SET_TYPE_LAST_ENTRY + ((DRV_SET_TYPE_T) 0))
#define CEC_SET_TYPE_NFY_FCT                (RM_SET_TYPE_LAST_ENTRY + ((DRV_SET_TYPE_T) 1))
#define CEC_SET_TYPE_WAKE_UP_CTRL           (RM_SET_TYPE_LAST_ENTRY + ((DRV_SET_TYPE_T) 2))
#define CEC_SET_TYPE_SIGNAL_CEC_READY      ((RM_SET_TYPE_LAST_ENTRY + ((DRV_SET_TYPE_T) 3)) | RM_SET_TYPE_ARG_NO_REF)
#define CEC_SET_TYPE_LOG_ADDR               (RM_SET_TYPE_LAST_ENTRY + ((DRV_SET_TYPE_T) 4))
#define CEC_SET_TYPE_GLOBAL_CEC_CTRL       ((RM_SET_TYPE_LAST_ENTRY + ((DRV_SET_TYPE_T) 5)) | RM_SET_TYPE_ARG_NO_REF)
#define CEC_SET_TYPE_ARC_CTRL                (RM_SET_TYPE_LAST_ENTRY + ((DRV_SET_TYPE_T) 6))
#define CEC_SET_TYPE_ARC_CTRL_WITH_PORT      (RM_SET_TYPE_LAST_ENTRY + ((DRV_SET_TYPE_T) 7))
#define CEC_SET_TYPE_SAD_DATA                (RM_SET_TYPE_LAST_ENTRY + ((DRV_SET_TYPE_T) 8))

#define CEC_GET_TYPE_MSG_ENQUEUE            (RM_GET_TYPE_LAST_ENTRY + ((DRV_GET_TYPE_T) 0))
#define CEC_GET_TYPE_IS_ACT_SRC_RECEIVED    (RM_GET_TYPE_LAST_ENTRY + ((DRV_GET_TYPE_T) 1))

/* 
    CEC_SET_TYPE_SIGNAL_CEC_READY is used to switch CEC control between CEC driver and uP
    - TRUE: CEC driver
    - FALSE: uP
*/

#define CEC_DEV_VNDR_ID_SIZE                ((SIZE_T)   3) 
#define CEC_MAX_OPERAND_SIZE                ((SIZE_T)  16) 
#define CEC_SAD_AUDIO_DATA_BLOCK_SIZE       ((SIZE_T)  30)

/* CEC notify type */
typedef enum
{
    CEC_NFY_TYPE_ACK = 0,
    CEC_NFY_TYPE_FRAME,
    CEC_NFY_TYPE_5V_POWER
}   CEC_NFY_TYPE_T;

/* ACK condition */
typedef enum
{
    CEC_ACK_COND_OK = 0,
    CEC_ACK_COND_NO_RESPONSE   
}   CEC_ACK_COND_T;

/* ACK info */
typedef struct _CEC_ACK_INFO_T
{
    VOID*               pv_tag;
    CEC_ACK_COND_T      e_ack_cond;
}   CEC_ACK_INFO_T;

/* Frame info */
typedef struct _CEC_FRAME_INFO_T
{
    UINT8       ui1_init_addr;
    UINT8       ui1_dest_addr;
    UINT16      ui2_opcode;
    UINT8       aui1_operand[CEC_MAX_OPERAND_SIZE];
    SIZE_T      z_operand_size;
}   CEC_FRAME_INFO_T;

typedef struct _CEC_5V_POWER_INFO_T
{
    BOOL      b_5v_power;
    UINT16    ui2_comp_id;
} CEC_5V_POWER_INFO_T;

/* CEC notification */
typedef struct _CEC_NFY_T
{
    CEC_NFY_TYPE_T      e_nfy_type;

    union
    {
        CEC_ACK_INFO_T      t_ack_info;
        CEC_FRAME_INFO_T    t_frame_info;
        CEC_5V_POWER_INFO_T      t_5v_power_info;
    }   u;
}   CEC_NFY_T;

/* CEC SAD set data */
typedef struct _CEC_SAD_T
{
    BOOL      fgSet;
    UINT8     u1FormatNum;
    UINT8     au1AudioDataBlock[CEC_SAD_AUDIO_DATA_BLOCK_SIZE];
}CEC_SAD_T;

/* Notify function */
typedef VOID (*x_cec_nfy_fct)(CEC_NFY_T* pt_nfy_data,
                              VOID*      pv_nfy_tag,
                              UINT32	 ui4_data);

/* CEC_SET_TYPE_SEND_MSG *****************************************************/
typedef struct _CEC_SEND_MSG_T
{
    VOID*                   pv_tag;
    CEC_FRAME_INFO_T        t_frame_info;
    BOOL                    b_enqueue_ok;
}   CEC_SEND_MSG_T;

/* CEC_SET_TYPE_NFY_FCT ******************************************************/
typedef struct _CEC_NFY_INFO_T
{
    VOID*               pv_nfy_tag;
    x_cec_nfy_fct       pf_cec_nfy;
}   CEC_NFY_INFO_T;

/* CEC_SET_TYPE_WAKE_UP_CTRL *************************************************/
typedef UINT8 CEC_DEV_VNDR_ID_T [CEC_DEV_VNDR_ID_SIZE];           

typedef enum
{
    CEC_FCT_CTRL_OFF = 0,
    CEC_FCT_CTRL_ON
}   CEC_FCT_CTRL_T;

/* CEC version */
typedef enum
{
    CEC_VER_1_1    = 0x00,
    CEC_VER_1_2    = 0x01,
    CEC_VER_1_2A   = 0x02,
    CEC_VER_1_3    = 0x03,
    CEC_VER_1_3A   = 0x04
}   CEC_VER_T;

/* uP wake-up control */
/* e_cec_fct_ctrl is used to determine whether CEC function is supported or not when uP is active */
typedef struct _CEC_WAKE_UP_CTRL_T
{
    CEC_FCT_CTRL_T          e_cec_fct_ctrl;
    CEC_VER_T               e_cec_ver;
    ISO_639_LANG_T          t_menu_lang;
    CEC_DEV_VNDR_ID_T       t_dev_vndr_id; 
    BOOL                    b_tv_auto_pwr_on;   
}   CEC_WAKE_UP_CTRL_T;

/* CEC logical address */
typedef enum
{
    CEC_LOG_ADDR_TV = 0,
    CEC_LOG_ADDR_REC_DEV_1,
    CEC_LOG_ADDR_REC_DEV_2,
    CEC_LOG_ADDR_TUNER_1,
    CEC_LOG_ADDR_PLAYBACK_DEV_1,
    CEC_LOG_ADDR_AUD_SYS,
    CEC_LOG_ADDR_TUNER_2,
    CEC_LOG_ADDR_TUNER_3,
    CEC_LOG_ADDR_PLAYBACK_DEV_2,
    CEC_LOG_ADDR_REC_DEV_3,
    CEC_LOG_ADDR_TUNER_4,
    CEC_LOG_ADDR_PLAYBACK_DEV_3,
    CEC_LOG_ADDR_RESERVED_1,
    CEC_LOG_ADDR_RESERVED_2,
    CEC_LOG_ADDR_FREE_USE,
    CEC_LOG_ADDR_UNREGED_BRDCST,
    CEC_LOG_ADDR_MAX
}   CEC_LOG_ADDR_T;

/* CEC_GET_TYPE_MSG_ENQUEUE **************************************************/
typedef struct _CEC_GET_MSG_ENQUEUE_T
{
    BOOL    b_enqueue_ok;
    
}   CEC_GET_MSG_ENQUEUE_T;

/* CEC_GET_TYPE_IS_ACT_SRC_RECEIVED ******************************************/
typedef struct _CEC_ACT_SRC_REVED_T
{
    BOOL        b_act_src_reved;
    UINT16      ui2_pa;
}   CEC_ACT_SRC_REVED_T;

typedef struct _CEC_ARC_CTRL_T
{
    BOOL        b_enable;
}   CEC_ARC_CTRL_T;


#endif /* _X_CEC_H_ */

