/* 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:  $
 * $Revision$
 * $Date$
 * $Author$
 * $CCRevision: $
 * $SWAuthor: Lawrance Liu $
 * $MD5HEX:  $
 *
 * Description:
 *         This header file contains PCMCIA/POD/CI/MPOD driver specific
 *         definitions, which are exported.
 *---------------------------------------------------------------------------*/

#ifndef _X_PCMCIA_H_
#define _X_PCMCIA_H_

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

/*-----------------------------------------------------------------------------
                    macros, defines, typedefs, enums
 ----------------------------------------------------------------------------*/
/* Get operations */
#define POD_GET_TYPE_POD_STATE      (RM_GET_TYPE_LAST_ENTRY + ((DRV_GET_TYPE_T) 0))
#define POD_GET_TYPE_ACCESS_MODE    (RM_GET_TYPE_LAST_ENTRY + ((DRV_GET_TYPE_T) 1))
#define POD_GET_TYPE_READ_CIS       (RM_GET_TYPE_LAST_ENTRY + ((DRV_GET_TYPE_T) 2))
#define POD_GET_TYPE_READ_REG       (RM_GET_TYPE_LAST_ENTRY + ((DRV_GET_TYPE_T) 3))
#define POD_GET_TYPE_READ_DATA      (RM_GET_TYPE_LAST_ENTRY + ((DRV_GET_TYPE_T) 4))

/* Set operations */
#define POD_SET_TYPE_RESET          (RM_SET_TYPE_LAST_ENTRY + ((DRV_SET_TYPE_T) 0))
#define POD_SET_TYPE_LOW_LEVEL_INIT (RM_SET_TYPE_LAST_ENTRY + ((DRV_SET_TYPE_T) 1))
#define POD_SET_TYPE_ACCESS_MODE    (RM_SET_TYPE_LAST_ENTRY + ((DRV_SET_TYPE_T) 2))
#define POD_SET_TYPE_MODULE_MODE    (RM_SET_TYPE_LAST_ENTRY + ((DRV_SET_TYPE_T) 3))
#define POD_SET_TYPE_POWER_CTRL     (RM_SET_TYPE_LAST_ENTRY + ((DRV_SET_TYPE_T) 4))
#define POD_SET_TYPE_NFY_FCT        (RM_SET_TYPE_LAST_ENTRY + ((DRV_SET_TYPE_T) 5))
#define POD_SET_TYPE_WRITE_COR      (RM_SET_TYPE_LAST_ENTRY + ((DRV_SET_TYPE_T) 6))
#define POD_SET_TYPE_WRITE_REG      (RM_SET_TYPE_LAST_ENTRY + ((DRV_SET_TYPE_T) 7))
#define POD_SET_TYPE_WRITE_DATA     (RM_SET_TYPE_LAST_ENTRY + ((DRV_SET_TYPE_T) 8))

/* CI specific Get/Set operations */
/* Get operations */
#define CI_GET_TYPE_POD_ACTIVE      (RM_GET_TYPE_LAST_ENTRY + ((DRV_GET_TYPE_T) 0))
#define CI_GET_TYPE_CARD_PRESENT    (RM_GET_TYPE_LAST_ENTRY + ((DRV_GET_TYPE_T) 1))
#define CI_GET_TYPE_CARD_READY      (RM_GET_TYPE_LAST_ENTRY + ((DRV_GET_TYPE_T) 2))
#define CI_GET_TYPE_READ_REG        (RM_GET_TYPE_LAST_ENTRY + ((DRV_GET_TYPE_T) 3))
#define CI_GET_TYPE_READ_COR        (RM_GET_TYPE_LAST_ENTRY + ((DRV_GET_TYPE_T) 4))
#define CI_GET_TYPE_READ_DATA       (RM_GET_TYPE_LAST_ENTRY + ((DRV_GET_TYPE_T) 5))
#define CI_GET_TYPE_RECEIVED_PKT_NUM     (RM_GET_TYPE_LAST_ENTRY + ((DRV_GET_TYPE_T) 6))
#define CI_GET_TYPE_DROPPED_PKT_NUM      (RM_GET_TYPE_LAST_ENTRY + ((DRV_GET_TYPE_T) 7))
#define CI_GET_TYPE_PID_COUNTERS         (RM_GET_TYPE_LAST_ENTRY + ((DRV_GET_TYPE_T) 8))
#define CI_GET_TYPE_PID                  (RM_GET_TYPE_LAST_ENTRY + ((DRV_GET_TYPE_T) 9))
#define CI_GET_TYPE_DEVICE_DATA          (RM_GET_TYPE_LAST_ENTRY + ((DRV_GET_TYPE_T) 10))
#define CI_GET_TYPE_DEVICE_ID            (RM_GET_TYPE_LAST_ENTRY + ((DRV_GET_TYPE_T) 11))
#define CI_GET_TYPE_SECURE_ID            (RM_GET_TYPE_LAST_ENTRY + ((DRV_GET_TYPE_T) 12))
#define CI_GET_TYPE_CARD_CONDITION       (RM_GET_TYPE_LAST_ENTRY + ((DRV_GET_TYPE_T) 13))
/* Set operations */
#define CI_SET_TYPE_INIT_CI            ((RM_SET_TYPE_LAST_ENTRY + ((DRV_SET_TYPE_T) 0)) | RM_SET_TYPE_ARG_NO_REF)
#define CI_SET_TYPE_RESET              (RM_SET_TYPE_LAST_ENTRY + ((DRV_SET_TYPE_T) 1))
#define CI_SET_TYPE_MODULE_MODE        (RM_SET_TYPE_LAST_ENTRY + ((DRV_SET_TYPE_T) 2))
#define CI_SET_TYPE_ACCESS_MODE        (RM_SET_TYPE_LAST_ENTRY + ((DRV_SET_TYPE_T) 3))
#define CI_SET_TYPE_ENABLE_TS          (RM_SET_TYPE_LAST_ENTRY + ((DRV_SET_TYPE_T) 4))
#define CI_SET_TYPE_WRITE_REG          (RM_SET_TYPE_LAST_ENTRY + ((DRV_SET_TYPE_T) 5))
#define CI_SET_TYPE_WRITE_COR           (RM_SET_TYPE_LAST_ENTRY + ((DRV_SET_TYPE_T) 6))
#define CI_SET_TYPE_WRITE_DATA         (RM_SET_TYPE_LAST_ENTRY + ((DRV_SET_TYPE_T) 7))
#define CI_SET_TYPE_RESET_CAM          ((RM_SET_TYPE_LAST_ENTRY + ((DRV_SET_TYPE_T) 8)) | RM_SET_TYPE_ARG_NO_REF)
#define CI_SET_TYPE_CD_ON_OFF           (RM_SET_TYPE_LAST_ENTRY + ((DRV_SET_TYPE_T) 9))
#define CI_SET_TYPE_INTERRUPT          ((RM_SET_TYPE_LAST_ENTRY + ((DRV_SET_TYPE_T) 10))| RM_SET_TYPE_ARG_NO_REF)
#define CI_SET_TYPE_WRORKAROUND_DRV     (RM_SET_TYPE_LAST_ENTRY + ((DRV_SET_TYPE_T) 11))
#define CI_SET_TYPE_FORCE_TS_THROUGH_CARD     (RM_SET_TYPE_LAST_ENTRY + ((DRV_SET_TYPE_T) 12))
#define CI_SET_TYPE_FASTBOOT          ((RM_SET_TYPE_LAST_ENTRY + ((DRV_SET_TYPE_T) 13))| RM_SET_TYPE_ARG_NO_REF)
#define CI_SET_TYPE_DUAL_TUNER_TS_PATH   (RM_SET_TYPE_LAST_ENTRY + ((DRV_SET_TYPE_T) 14))
#define CI_SET_TYPE_CAM_VER          ((RM_SET_TYPE_LAST_ENTRY + ((DRV_SET_TYPE_T) 15))| RM_SET_TYPE_ARG_NO_REF)
#define CI_SET_TYPE_SET_TS_DMX_TO_CARD     (RM_SET_TYPE_LAST_ENTRY + ((DRV_SET_TYPE_T) 16))/*pv_info is BOOL*, TRUE means ts data from DMX, FALSE means ts data from Demod*/
#define CI_SET_TYPE_MW_IDLE           ((RM_SET_TYPE_LAST_ENTRY + ((DRV_SET_TYPE_T) 17)) | RM_SET_TYPE_ARG_NO_REF)
#define CI_SET_TYPE_POWER_ON          ((RM_SET_TYPE_LAST_ENTRY + ((DRV_SET_TYPE_T) 18)) | RM_SET_TYPE_ARG_NO_REF)
#define CI_SET_TYPE_TS_SOURCE        (RM_SET_TYPE_LAST_ENTRY + ((DRV_SET_TYPE_T) 19))

/* End CI specific Get/Set operations */

/* POD state */
#define POD_INSERTED                ((UINT32)   (1 << 0))
#define POD_FREE                    ((UINT32)   (1 << 1))
#define POD_DATA_AVIL               ((UINT32)   (1 << 2))
#define POD_FREE_EXT                ((UINT32)   (1 << 3))
#define POD_DATA_AVIL_EXT           ((UINT32)   (1 << 4))
#define POD_VS1                     ((UINT32)   (1 << 5)) /* Added for DK PODware */
#define POD_VS2                     ((UINT32)   (1 << 6)) /* Added for DK PODware */
#define POD_READY_IREQ              ((UINT32)   (1 << 7)) /* Added for DK PODware */
#define POD_OVERCURRENT             ((UINT32)   (1 << 8)) /* Added for DK PODware */

/* Definitions of POD status register */
#define POD_STS_RE                  ((UINT32)   (1 << 0))
#define POD_STS_WE                  ((UINT32)   (1 << 1))
#define POD_STS_IIR                 ((UINT32)   (1 << 4))
#define POD_STS_FR                  ((UINT32)   (1 << 6))
#define POD_STS_DA                  ((UINT32)   (1 << 7))

/* Definition of POD signals */
#define POD_PIN_SET                 ((UINT32)   0x00000001)

/* POD condition */
typedef enum
{
    POD_COND_REMOVED = 0,
    POD_COND_INSERTED
}   POD_COND_T;

/* CAM codition */
typedef enum
{
    CAM_COND_INIT = 0,
    CAM_COND_ISR
}   CAM_COND_T;
/* POD access mode */
typedef enum
{
    PCMCIA_ATTRIBUTE_MEM = 0,
    PCMCIA_COMMON_MEM,
    POD_DATA_CHANNEL,
    POD_EXTENDED_CHANNEL
}   POD_ACCESS_MODE_T;

/* POD module mode */
typedef enum
{
    MODULE_MODE_PCMCIA = 0,
    MODULE_MODE_POD
}   POD_MODULE_MODE_T;

typedef enum
{
    PCMCIA_DUAL_TUNER_EXT1 = 0,
    PCMCIA_DUAL_TUNER_EXT2,
    PCMCIA_DUAL_TUNER_NONE
} PCMCIA_DUAL_TUNER_TS_TYPE;
typedef enum
{
    PCMCIA_TS_DEMOD = 0,
    PCMCIA_TS_SATIP
} PCMCIA_TS_SOURCE;

/* POD power control */
typedef enum
{
    POD_VCC_OFF_VPP_OFF = 0,
    POD_VCC_33V_VPP_33V,
    POD_VCC_33V_VPP_50V,
}   POD_POWER_CTRL_T;

/* POD cam workaround for driver */
typedef enum
{
    CI_CAM_WORKAROUND_DRV_1 = 0  /* CAM019 can not receive 36Mhz CLK.*/
   ,CI_CAM_WORKAROUND_DRV_2      /* Descramble stream by TREX CAM is slower due to Sync pin and valid of data are not sync.*/
   ,CI_CAM_WORKAROUND_DRV_3      /* SmarCAM need to adjust driving.*/
   ,CI_CAM_WORKAROUND_DRV_4      /* CI driver need to set ts pass cam after SmarDTV CAM inserted.*/
   ,CI_CAM_WORKAROUND_DRV_5      /* Set TV's current tuner type to CI driver. para:0x0: unknown; 1/2/3: T/C/S */
}   CI_CAM_WRORKAROUND_DRV_T;

/* Notify function */
typedef VOID (*x_pod_nfy_fct)(VOID*     pv_nfy_tag,
                              UINT32    ui4_state,
                              UINT32    ui4_data);

/* Notify setting structure */
typedef struct _POD_NFY_INFO_T
{
    VOID*           pv_tag;
    x_pod_nfy_fct   pf_pod_nfy;
}   POD_NFY_INFO_T;

/* Data structure for POD signal control */
typedef struct _POD_SIGNAL_T
{
    UINT32  ui4_set;
    UINT32  ui4_clear;
}   POD_SIGNAL_T;

/* COR info for POD personality change */
typedef struct _POD_COR_INFO_T
{
    UINT16  ui2_cor_address;
    UINT8   ui1_cor_value;
}   POD_COR_INFO_T;

/* Data structure definition */
typedef struct _POD_DATA_INFO_T
{
    SIZE_T  z_data_len;
    UINT8*  pui1_data;
}   POD_DATA_INFO_T;

/* Data structure for register read and write operation */
typedef struct _POD_REG_DATA_INFO_T
{
    UINT8               ui1_reg_addr;
    POD_DATA_INFO_T     t_data_info;
}   POD_REG_DATA_INFO_T;

/* Data structure for set CAM info to workaround in driver */
typedef struct _CI_CAM_WORKAROUND_DRV_INFO_T
{
    CI_CAM_WRORKAROUND_DRV_T  t_cam_workaround;
    VOID*           pv_para;
}   CI_CAM_WORKAROUND_DRV_INFO_T;

/* -----------------------------------------------------------------------------
 * CI specific typedef
 * -----------------------------------------------------------------------------
 */
/* POD Enable TS */
typedef struct _POD_ENABLE_TS_T
{
    BOOL    b_from_ca;
    BOOL    b_pod_ts_mode_enable;
}   POD_ENABLE_TS_T;

/* POD Tuner Attributes */
typedef struct _POD_TUNER_ATTRIBUTE_T
{
    UINT16          ui2_tuner_id;
    DRV_SET_TYPE_T  t_drv_set_type;
    VOID*           pv_ana_attribute;
    SIZE_T          z_ana_attribute_len;
}   POD_TUNER_ATTRIBUTE_T;

/* -----------------------------------------------------------------------------
 * CI Plus specific typedef
 * -----------------------------------------------------------------------------
 */
/* Read Divice data  */
typedef struct _POD_EFUSE_DATA_INFO_T
{
    SIZE_T  z_data_len;
    UINT8*  pui1_data;
}   POD_EFUSE_DATA_INFO_T;

typedef enum
{
    CAM_VERSION_TYPE_CI = 0,
    CAM_VERSION_TYPE_CI_PLUS
}   CAM_VERSION_TYPE_T;

/*-----------------------------------------------------------------------------
                    functions declarations
 ----------------------------------------------------------------------------*/
extern INT32 POD_InitMw(void);

#endif /* _X_PCMCIA_H_ */

