////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
// All rights reserved.
// Confidential and Proprietary - Qualcomm Technologies, Inc.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @file  camxcslifedefs.h
/// @brief IFE Hardware Interface Definition
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#ifndef CAMXCSLIFEDEFS_H
#define CAMXCSLIFEDEFS_H

#include "camxcsl.h"
#include "camxutils.h"

CAMX_NAMESPACE_BEGIN

static const UINT32 CSLIFEOutputFull               = 0x3000;    ///< IFE full pixel path output resource
static const UINT32 CSLIFEOutputDS4                = 0x3001;    ///< IFE 1/4 pixel path output resource
static const UINT32 CSLIFEOutputDS16               = 0x3002;    ///< IFE 1/16 pixel path output resource
static const UINT32 CSLIFEOutputRaw                = 0x3003;    ///< Raw output path
static const UINT32 CSLIFEOutputFD                 = 0x3004;    ///< FD path
static const UINT32 CSLIFEOutputPDAF               = 0x3005;    ///< PDAF path
static const UINT32 CSLIFEOutputRDI0               = 0x3006;    ///< RDI 0 path output resource
static const UINT32 CSLIFEOutputRDI1               = 0x3007;    ///< RDI 1 path output resource
static const UINT32 CSLIFEOutputRDI2               = 0x3008;    ///< RDI 2 path output resource
static const UINT32 CSLIFEOutputRDI3               = 0x3009;    ///< RDI 3 path output resource
static const UINT32 CSLIFEOutputStatsHDRBE         = 0x300A;    ///< Stats HDR BE output resource
static const UINT32 CSLIFEOutputStatsHDRBHIST      = 0x300B;    ///< Stats HDR BHIST output resource
static const UINT32 CSLIFEOutputStatsTLBG          = 0x300C;    ///< Stats Tintless BG output resource
static const UINT32 CSLIFEOutputStatsBF            = 0x300D;    ///< Stats BF output resource
static const UINT32 CSLIFEOutputStatsAWBBG         = 0x300E;    ///< Stats AWB BG output resource
static const UINT32 CSLIFEOutputStatsBHIST         = 0x300F;    ///< Stats BHIST output resource
static const UINT32 CSLIFEOutputStatsRS            = 0x3010;    ///< Stats RS output resource
static const UINT32 CSLIFEOutputStatsCS            = 0x3011;    ///< Stats CS output resource
static const UINT32 CSLIFEOutputStatsIHIST         = 0x3012;    ///< Stats IHIST output resource
static const UINT32 CSLIFEOutputDisplayFull        = 0x3013;    ///< IFE display full pixel path output resource
static const UINT32 CSLIFEOutputDisplayDS4         = 0x3014;    ///< IFE display 1/4 pixel path output resource
static const UINT32 CSLIFEOutputDisplayDS16        = 0x3015;    ///< IFE display 1/16 pixel path output resource
static const UINT32 CSLIFEOutputDualPD             = 0x3016;    ///< Dual PD HW
static const UINT32 CSLIFEOutputRDIRD              = 0x3017;    ///< RDI RD used as fetch engine port
static const UINT32 CSLIFEOutputLCR                = 0x3018;    ///< LCR
static const UINT32 CSLIFEOutputSparsePD           = 0x3019;    ///< SparsePD
static const UINT32 CSLIFEOutputPreProcessedDualPD = 0x301A;    ///< PD PreProcessed Port
static const UINT32 CSLIFEOutputStatsAECBFW        = 0x301B;    ///< BFW Port
static const UINT32 CSLIFEOutputStatsAECBE         = 0x301C;    ///< AEC BE Stats
static const UINT32 CSLIFEOutputStatsLTMDC         = 0x301D;    ///< LTM Stats
static const UINT32 CSLIFEOutputStatsGTMBHIST      = 0x301E;    ///< GTM BHist
static const UINT32 CSLIFELiteOutputStatsBG        = 0x301F;    ///< IFE lite BG stats
static const UINT32 CSLIFELiteOutputPreProcessRaw  = 0x3020;    ///< IFE lite Pre Process Raw Output
static const UINT32 CSLIFEOutputStatsCAF           = 0x3021;    ///< IFE CAF Stats Output Port
static const UINT32 CSLIFEOutputStatsBayerRS       = 0x3022;    ///< IFE Bayer RS Stats Output Port
static const UINT32 CSLIFEOutputParsedData         = 0x3023;    ///< Parsed PD Data Port
static const UINT32 CSLIFEOutputStatsALSCBG        = 0x3024;    ///< Stats ALSC BG output Port
static const UINT32 CSLIFEOutputDS2                = 0x3025;    ///< DS2 output resource
static const UINT32 CSLIFEOutputIR                 = 0x3026;    ///< IFE IR out
static const UINT32 CSLIFEOutputRDI4               = 0x3027;    ///< RDI 4 path output resource
static const UINT32 CSLIFEOutputStatsTMCBHIST      = 0x3028;    ///< TMC BHIST Stats Port
static const UINT32 CSLIFEOutputStatsAFBHIST       = 0x3029;    ///< AF BHIST Stats Port
static const UINT32 CSLIFEOutputStatsAECBHIST      = 0x302A;    ///< AEC BHIST Stats Port
static const UINT32 CSLIFEOutputRDI5               = 0x302B;    ///< RDI 5 path output resource
static const UINT32 CSLIFEOutputAI1                = 0x302C;    ///< IFE video 1/2 pixel path output resource
static const UINT32 CSLIFEOutputAI2                = 0x302D;    ///< IFE video 1/4 pixel path output resource
static const UINT32 CSLIFEOutputStatsIRBG          = 0x302E;    ///< IFE IRBG Stats Port
static const UINT32 CSLIFEOutputStatsIRBhist       = 0x302F;    ///< IFE IRBHist Stats Port
static const UINT32 CSLIFEOutputVirtualRDI0        = 0x3030;    ///< IFE VirtualRDI0
static const UINT32 CSLIFEOutputVirtualRDI1        = 0x3031;    ///< IFE VirtualRDI1
static const UINT32 CSLIFEOutputVirtualRDI2        = 0x3032;    ///< IFE VirtualRDI2
static const UINT32 CSLIFEOutputVirtualRDI3        = 0x3033;    ///< IFE VirtualRDI3
static const UINT32 CSLIFEOutputVirtualRDI4        = 0x3034;    ///< IFE VirtualRDI4
static const UINT32 CSLIFEOutputVirtualRDI5        = 0x3035;    ///< IFE VirtualRDI5
static const UINT32 CSLIFELiteOutputStatsBHIST     = 0x3036;    ///< IFE lite BHIST stats
static const UINT32 CSLIFELiteOutputPreProcessRaw1 = 0x3037;    ///< IFE lite Pre Process Raw Gamma1 Output
static const UINT32 CSLIFELiteOutputPreProcessRaw2 = 0x3038;    ///< IFE lite Pre Process Raw Gamma2 Output
static const UINT32 CSLIFEOutputMax                = 0x3039;    ///< Max Output

// SFE Output Resource Type
static const UINT32 SFEOutputRDI0           = 0x6000;   ///< SFE RDI0 path output resource
static const UINT32 SFEOutputRDI1           = 0x6001;   ///< SFE RDI1 path output resource
static const UINT32 SFEOutputRDI2           = 0x6002;   ///< SFE RDI2 path output resource
static const UINT32 SFEOutputRDI3           = 0x6003;   ///< SFE RDI3 path output resource
static const UINT32 SFEOutputRDI4           = 0x6004;   ///< SFE RDI4 path output resource
static const UINT32 SFEOutputAWBBG0         = 0x6005;   ///< SFE AWB BG Channel0 output resource
static const UINT32 SFEOutputBHIST0         = 0x6006;   ///< SFE BHIST Channel0 output resource
static const UINT32 SFEOutputAWBBG1         = 0x6007;   ///< SFE AWB BG Channel1 output resource
static const UINT32 SFEOutputBHIST1         = 0x6008;   ///< SFE BHIST Channel1 output resource
static const UINT32 SFEOutputAWBBG2         = 0x6009;   ///< SFE AWB BG Channel2 output resource
static const UINT32 SFEOutputBHIST2         = 0x600A;   ///< SFE BHIST Channel2 output resource
static const UINT32 SFEOutputLCR            = 0x600B;   ///< SFE LCR Output resource
static const UINT32 SFEOutputRaw            = 0x600C;   ///< SFE ZSL Raw output resource
static const UINT32 SFEOutputIR             = 0x600D;   ///< SFE IR Raw Output
static const UINT32 SFEOutputBayerRS0       = 0x600E;   ///< SFE Bayer RS 0
static const UINT32 SFEOutputBayerRS1       = 0x600F;   ///< SFE Bayer RS 1
static const UINT32 SFEOutputBayerRS2       = 0x6010;   ///< SFE Bayer RS 2
static const UINT32 SFEOutputHDRMaskCount   = 0x6011;   ///< SFE HDR mask count output
static const UINT32 SFEOutputMax            = 0x6012;   ///< SFE Max output ports

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// CSLIFEPortIdMaxNumPortResourcesOfPlatform
///
/// @brief  Get maximum number of CSL IFE output ports supported in given platform
///
/// @param  titanVersion    CSL camera Titan version
///
/// @return max resources
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
CAMX_INLINE UINT32 CSLIFEPortIdMaxNumPortResourcesOfPlatform(
    const UINT32 titanVersion)
{
    UINT32 maxNumPortResources = 0;

    switch (titanVersion)
    {
        case CSLCameraTitanVersion::CSLTitan880:
        case CSLCameraTitanVersion::CSLTitan860:
            maxNumPortResources = CSLIFEOutputStatsALSCBG - CSLIFEOutputFull + 1;
            break;

        case CSLCameraTitanVersion::CSLTitan780:
            maxNumPortResources = CSLIFEOutputStatsBayerRS - CSLIFEOutputFull + 1;
            break;

        case CSLCameraTitanVersion::CSLTitan680:
        case CSLCameraTitanVersion::CSLTitan695:
        case CSLCameraTitanVersion::CSLTitan696:
        case CSLCameraTitanVersion::CSLTitan690:
        case CSLCameraTitanVersion::CSLTitan692:
            maxNumPortResources = CSLIFELiteOutputPreProcessRaw - CSLIFEOutputFull + 1;
            break;

        case CSLCameraTitanVersion::CSLTitan175:
        case CSLCameraTitanVersion::CSLTitan160:
        case CSLCameraTitanVersion::CSLTitan480:
        case CSLCameraTitanVersion::CSLTitan570:
        case CSLCameraTitanVersion::CSLTitan580:
            maxNumPortResources = CSLIFEOutputSparsePD - CSLIFEOutputFull;
            break;

        // Limit CSL IFE port ID up to CSLIFEOutputStatsIHIST for non CSLTitan175/CSLTitan160 families
        case CSLCameraTitanVersion::CSLTitan170:
        case CSLCameraTitanVersion::CSLTitan150:
        default:
            maxNumPortResources = CSLIFEOutputDisplayFull - CSLIFEOutputFull;
            break;
    }

    return maxNumPortResources;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// CSLSFEPortIdMaxNumPortResourcesOfPlatform
///
/// @brief  Get maximum number of CSL SFE output ports supported in given platform
///
/// @param  titanVersion    CSL camera Titan version
///
/// @return max resources
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
CAMX_INLINE UINT32 CSLSFEPortIdMaxNumPortResourcesOfPlatform(
    const UINT32 titanVersion)
{
    UINT32 maxNumPortResources = 0;

    switch (titanVersion)
    {
        case CSLCameraTitanVersion::CSLTitan880:
        case CSLCameraTitanVersion::CSLTitan860:
            maxNumPortResources = SFEOutputHDRMaskCount - SFEOutputRDI0 + 1;
            break;

        case CSLCameraTitanVersion::CSLTitan780:
            maxNumPortResources = SFEOutputBayerRS2 - SFEOutputRDI0 + 1;
            break;

        case CSLCameraTitanVersion::CSLTitan680:
        case CSLCameraTitanVersion::CSLTitan695:
        case CSLCameraTitanVersion::CSLTitan696:
        case CSLCameraTitanVersion::CSLTitan690:
        case CSLCameraTitanVersion::CSLTitan692:
            maxNumPortResources = SFEOutputRaw - SFEOutputRDI0 + 1;
            break;

        default:
            maxNumPortResources = (SFEOutputMax) - SFEOutputRDI0;
            break;
    }

    return maxNumPortResources;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// CSLIFEPortIndex
///
/// @brief  Map CSL IFE port Id to zero-based index
///
/// @param  portId CSL IFE port Id
///
/// @return index
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
CAMX_INLINE UINT32 CSLIFEPortIndex(
    UINT32 portId)
{
    return  portId - CSLIFEOutputFull;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// CSLSFEPortIndex
///
/// @brief  Map CSL SFE port Id to zero-based index
///
/// @param  portId CSL SFE port Id
///
/// @return index
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
CAMX_INLINE UINT32 CSLSFEPortIndex(
    UINT32 portId)
{
    return  portId - SFEOutputRDI0;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// CSLIFEStatsPortIndex
///
/// @brief  Map CSL IFE stats port Id to zero-based stats port index
///
/// @param  portId CSL IFE stats port Id
///
/// @return index
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
CAMX_INLINE UINT32 CSLIFEStatsPortIndex(
    UINT32 portId, const UINT32 titanVersion)
{
    UINT32 index = 0;
    switch (titanVersion)
    {
        case CSLCameraTitanVersion::CSLTitan680:
        case CSLCameraTitanVersion::CSLTitan695:
        case CSLCameraTitanVersion::CSLTitan696:
        case CSLCameraTitanVersion::CSLTitan690:
        case CSLCameraTitanVersion::CSLTitan692:
        case CSLCameraTitanVersion::CSLTitan780:
        case CSLCameraTitanVersion::CSLTitan860:
        case CSLCameraTitanVersion::CSLTitan880:
            if (CSLIFEOutputStatsIHIST >= portId)
            {
                index = portId - CSLIFEOutputStatsHDRBE;
            }
            else
            {
                index = (portId - CSLIFEOutputPreProcessedDualPD) + (CSLIFEOutputStatsIHIST - CSLIFEOutputStatsHDRBE);
            }
            break;
        default:
            index = portId - CSLIFEOutputStatsHDRBE;
            break;
    }
    return  index;
}

// IFE input resource type
static const UINT32 IFEInputTestGen        = 0x4000;
static const UINT32 IFEInputPHY0           = 0x4001;
static const UINT32 IFEInputPHY1           = 0x4002;
static const UINT32 IFEInputPHY2           = 0x4003;
static const UINT32 IFEInputPHY3           = 0x4004;
static const UINT32 IFEInputPHY4           = 0x4005;
static const UINT32 IFEInputPHY5           = 0x4006;
static const UINT32 IFEInputBusRead        = 0x4007;
static const UINT32 IFEInputCPHYTestGen    = 0x4008;
static const UINT32 IFEInputCPHYTestGen1   = 0x4009;
static const UINT32 IFEInputCPHYTestGen2   = 0x400A;

// SFE Input resource Type
static const UINT32 SFEInputInlinePixel = 0x5000;
static const UINT32 SFEInputInRDI0      = 0x5001;
static const UINT32 SFEInputInRDI1      = 0x5002;
static const UINT32 SFEInputInRDI2      = 0x5003;
static const UINT32 SFEInputMax         = 0x5004;

// IFE input resource Lane Type
static const UINT32 IFELaneTypeDPHY        = 0;
static const UINT32 IFELaneTypeCPHY        = 1;

// IFE usage Types
static const UINT32 IFEUsageInvalid         = 0;
static const UINT32 IFEUsageLeftPixelPath   = 1;
static const UINT32 IFEUsageRighftPixelPath = 2;
static const UINT32 IFEUsageRDIPath         = 3;
static const UINT32 SFEUsageLeftPixelPath   = 4;
static const UINT32 SFEUsageRightPixelPath  = 5;
static const UINT32 SFEUsageRDIPath         = 6;

// IFE Generic Blob types
static const UINT32 IFEGenericBlobTypeHFRConfig                         = 0;
static const UINT32 IFEGenericBlobTypeResourceClockConfig               = 1;
static const UINT32 IFEGenericBlobTypeResourceBWConfig                  = 2;
static const UINT32 IFEGenericBlobTypeUBWCConfig                        = 3;
static const UINT32 IFEGenericBlobTypeCSIDClockConfig                   = 4;
static const UINT32 IFEGenericBlobTypeBusReadConfig                     = 5;
static const UINT32 IFEGenericBlobTypeUBWCConfigV2                      = 6;
static const UINT32 IFEGenericBlobTypeIFETopConfig                      = 7;
static const UINT32 IFEGenericBlobTypeIFEOutConfig                      = 8;
static const UINT32 IFEGenericBlobTypeResourceBWConfigV2                = 9;
static const UINT32 IFEGenericBlobTypeIFEInitialFrameDropConfig         = 10;
static const UINT32 IFEGenericBlobTypeCSIDQCFAConfig                    = 12;
static const UINT32 IFEGenericBlobTypeTestgenCoreConfig                 = 14;
static const UINT32 IFEGenericBlobTypeDynamicModeSwitch                 = 15;
static const UINT32 IFEGenericBlobTypeOfflineBWLimit                    = 16;
static const UINT32 IFEGenericBlobTypeFPSConfig                         = 17;
static const UINT32 IFEGenericBlobTypeINITConfig                        = 18;
static const UINT32 IFEGenericBlobTypeLCRRDIConfig                      = 19;
static const UINT32 SFEGenericBlobTypeFCGConfig                         = 20;
static const UINT32 SFEGenericBlobTypeClockConfig                       = 21;
static const UINT32 SFEGenericBlobTypeCoreConfig                        = 22;
static const UINT32 SFEGenericBlobTypeOutConfig                         = 23;
static const UINT32 SFEGenericBlobTypeHFRConfig                         = 24;
static const UINT32 SFEGenericBlobTypeFEConfig                          = 25;
static const UINT32 SFEGenericBlobTypeScratchBufferConfig               = 26;
static const UINT32 SFEGenericBlobTypeExposureOrderConfig               = 27;
static const UINT32 IFEGenericBlobTypeDRVConfig                         = 28;
static const UINT32 IFEGenericBlobTypeResourceBWConfigV3                = 29;
static const UINT32 IFEGenericBlobTypeTrailingStreamConfig              = 30;
static const UINT32 IFEGenericBlobTypeTrailingScratchBufferConfig       = 31;
static const UINT32 IFEGenericBlobTypeFCGConfig                         = 33;

static const UINT32 IFEMaxDMIConfigWrites      = 5;
static const UINT32 MaxRegDumpOffsets          = 10;  ///< Max Register Dump Offsets, for exmaple IFE Left,
                                                      /// IFE Right and CAMNOC etc

///@ brief IFEBusWRVersion
enum IFEBusWriteHWVersion
{
    IFEBusWriteHWInvalid = 0x0,
    IFEBusWriteHWV1      = 0x00020000,
    IFEBusWriteHWV2      = 0x20000000,
};

///@ brief IFEBusRDVersion
enum IFEBusReadHWVersion
{
    IFEBusReadHInvalid = 0x0,
    IFEBusReadHWV1     = 0x00040000,
};

CAMX_BEGIN_PACKED

///@ brief IFERegWriteDescriptor
struct IFERegWriteDescriptor
{
    UINT32 offset;  ///< Offset of the register that needs to be updated
    UINT32 value;   ///< Value
} CAMX_PACKED;

///@ brief Register read range descriptor
struct IFERegRangeReadDescriptor
{
    UINT32 offset;            ///< register offset
    UINT32 numberOfRegisters; ///< number of registers to be read
} CAMX_PACKED;

///@ brief IFE DMI read descriptor
struct IFEDMIReadDesciptor
{
    UINT32                    numberOfRegWrites;                      ///< Number of registers to be Wriiten
    UINT32                    numberOfPostWrites;                     ///< NUmber of Post read reg Writes
    IFERegWriteDescriptor     regWriteCmd[IFEMaxDMIConfigWrites];     ///< Array of register Write commands
    IFERegRangeReadDescriptor regRangeCmd;                            ///< register read range command
    IFERegWriteDescriptor     postregWriteCmd[IFEMaxDMIConfigWrites]; ///< Array of register Write commands
} CAMX_PACKED;

///@ brief IFE register read Info
struct IFERegReadInfo
{
    UINT32 readType;                          ///< Read type
    UINT32 reserved;                          ///< Reserved field for future use
    union
    {
        IFERegRangeReadDescriptor regReadCmd; ///< Register read Command
        IFEDMIReadDesciptor       dmiReadCmd; ///< DMI Read Command
    } regDescriptor;
} CAMX_PACKED;

///@ brief IFE Reg Dump Output
struct IFERegDumpOutput
{
    UINT64 requestID;     ///< Request ID
    UINT32 numberOfBytes; ///< NUmber of bytes Written
    UINT32 data[1];       ///< Data
} CAMX_PACKED;

///@ brief IFE Reg Dump Descriptor
struct IFERegDumpDescriptor
{
    UINT32          type;                                    ///< Reg Dump Type
    UINT32          bufferOffset;                            ///< Register Dump buffer offset
    UINT32          bufferSize;                              ///< Register Dump buffer Size
    UINT32          numberOfRegReadInfo;                     ///< Number of reg range read
    IFERegReadInfo  regReadInfo[1];                          ///< Register read Info
} CAMX_PACKED;

/// @brief IFE Reg dump Imput Info Whihc specifies the Registor Dump descriptor offsets
struct IFERegDumpInfo
{
    UINT32 numberOfRegDumps;                  ///< Number of Reg Dumps
    UINT32 regDumpOffsets[MaxRegDumpOffsets]; ///< Register Dump
} CAMX_PACKED;

/// @brief ISP Reg Dump info
struct ISPRegDumpInfo
{
    UINT64          regGroupType; ///< Register Group Type
    IFERegReadInfo  regReadInfo;  ///< Register Read Info
} CAMX_PACKED;

CAMX_END_PACKED

static const UINT32 IFERegDumpTypeIFELeft  = 1;
static const UINT32 IFERegDumpTypeIFERight = 2;
static const UINT32 IFERegDumpTypeCAMNOC   = 3;
static const UINT32 CSIDRegDumpTypeWrapper = 4;
static const UINT32 CSIDRegDumpTypeLeft    = 5;
static const UINT32 CSIDRegDumpTypeRight   = 6;
static const UINT32 SFERegDumpTypeLeft     = 7;
static const UINT32 SFERegDumpTypeRight    = 8;

static const UINT32 IFERegDumpReadTypeReg = 1;
static const UINT32 IFERegDumpReadTypeDMI = 2;
CAMX_NAMESPACE_END
#endif // CAMXCSLIFEDEFS_H
