////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2020-2023 Qualcomm Technologies, Inc.
// All Rights Reserved.
// Confidential and Proprietary - Qualcomm Technologies, Inc.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @file  camxcsltfedefs.h
/// @brief TFE Hardware Interface Definition
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#ifndef CAMXCSLTFEDEFS_H
#define CAMXCSLTFEDEFS_H
#include "camxutils.h"

// ISP TFE Resource Type
static const UINT32 TFEResourceIdPort      = 0;

// ISP TFE Usage Type
static const UINT32 TFEResourceUsageSingle = 0;
static const UINT32 TFEResourceUsageDual   = 1;

// ISP TFE Color Pattern
static const UINT32 TFEPatternBayerRGRGRG  = 0;
static const UINT32 TFEPatternBayerGRGRGR  = 1;
static const UINT32 TFEPatternBayerBGBGBG  = 2;
static const UINT32 TFEPatternBayerGBGBGB  = 3;
static const UINT32 TFEPatternYUVYCBYCR    = 4;
static const UINT32 TFEPatternYUVYCRYCB    = 5;
static const UINT32 TFEPatternYUVCBYCRY    = 6;
static const UINT32 TFEPatternYUVCRYCBY    = 7;

// ISP TFE Input Format
static const UINT32 TFEFormatMIPIRaw6      = 1;
static const UINT32 TFEFormatMIPIRaw8      = 2;
static const UINT32 TFEFormatMIPIRaw10     = 3;
static const UINT32 TFEFormatMIPIRaw12     = 4;
static const UINT32 TFEFormatMIPIRaw14     = 5;
static const UINT32 TFEFormatMIPIRaw16     = 6;
static const UINT32 TFEFormatMIPIRaw20     = 7;
static const UINT32 TFEFormatRaw8Private   = 8;
static const UINT32 TFEFormatRaw10Private  = 9;
static const UINT32 TFEFormatRaw12Private  = 10;
static const UINT32 TFEFormatRaw14Private  = 11;
static const UINT32 TFEFormatPlain8        = 12;
static const UINT32 TFEFormatPlain168      = 13;
static const UINT32 TFEFormatPlain1610     = 14;
static const UINT32 TFEFormatPlain1612     = 15;
static const UINT32 TFEFormatPlain1614     = 16;
static const UINT32 TFEFormatPlain1616     = 17;
static const UINT32 TFEFormatPlain3220     = 18;
static const UINT32 TFEFormatPlain64       = 19;
static const UINT32 TFEFormatPlain128      = 20;
static const UINT32 TFEFormatARGB          = 21;
static const UINT32 TFEFormatARGB10        = 22;
static const UINT32 TFEFormatARGB12        = 23;
static const UINT32 TFEormatARGB14         = 24;
static const UINT32 TFEFormatDPCM10610     = 25;
static const UINT32 TFEFormatDPCM10810     = 26;
static const UINT32 TFEFormatDPCM12612     = 27;
static const UINT32 TFEFormatDPCM12812     = 28;
static const UINT32 TFEFormatDPCM14814     = 29;
static const UINT32 TFEFormatDPCM141014    = 30;
static const UINT32 TFEFormatNV21          = 31;
static const UINT32 TFEFormatNV12          = 32;
static const UINT32 TFEFormatTP10          = 33;
static const UINT32 TFEFormatYUV422        = 34;
static const UINT32 TFEFormatPD8           = 35;
static const UINT32 TFEFormatPD10          = 36;
static const UINT32 TFEFormatUBWCNV12      = 37;
static const UINT32 TFEFormatUBWCNV124R    = 38;
static const UINT32 TFEFormatUBWCTP10      = 39;
static const UINT32 TFEFormatUBWCP010      = 40;
static const UINT32 TFEFormatPlain8Swap    = 41;
static const UINT32 TFEFormatPlain810      = 42;
static const UINT32 TFEFormatPlain810Swap  = 43;
static const UINT32 TFEFormatYV12          = 44;
static const UINT32 TFEFormatY             = 45;
static const UINT32 TFEFormatUndefined     = 0xFFFFFFFF;

/* ISP TFE Resource Composite Group ID */
static const UINT32  TFEOutputGroupIdNONE   = 0;
static const UINT32  TFEOutputGroupId0      = 1;
static const UINT32  TFEOutputGroupId1      = 2;
static const UINT32  TFEOutputGroupId2      = 3;
static const UINT32  TFEOutputGroupId3      = 4;
static const UINT32  TFEOutputGroupId4      = 5;
static const UINT32  TFEOutputGroupId5      = 6;
static const UINT32  TFEOutputGroupId6      = 7;
static const UINT32  TFEOutputGroupId7      = 8;
static const UINT32  TFEOutputGroupId8      = 9;
static const UINT32  TFEOutputGroupId9      = 10;
static const UINT32  TFEOutputGroupId10     = 11;
static const UINT32  TFEOutputGroupIdMAX    = 12;

static const UINT16  TFEAcquireCommonVersion0 = 0x1000;     ///< TFE Common Resource structure Version
static const UINT16  TFEAcquireInputVersion0  = 0x2000;     ///< TFE Input Resource structure Version
static const UINT16  TFEAcquireOutputVersion0 = 0x3000;     ///< TFE Output Resource structure Version

static const UINT16  TFEAcquireCommonVersion2 = 0x2000;
static const UINT16  TFEAcquireInputVersion2  = 0x2000;
static const UINT16  TFEAcquireOutputVersion2 = 0x3000;

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

static const UINT32 TFEMaxVC                = 2;
static const UINT32 TFEMaxDT                = 2;

static const UINT32 TFEMaxOutputPorts = 19; ///< Max TFE Output Ports

CAMX_BEGIN_PACKED

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

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

///@ brief TFE DMI read descriptor
struct CSLTFEDMIReadDesciptor
{
    UINT32                       numberOfRegWrites;                      ///< Number of registers to be Wriiten
    UINT32                       numberOfPostWrites;                     ///< NUmber of Post read reg Writes
    CSLTFERegWriteDescriptor     regWriteCmd[TFEMaxDMIConfigWrites];     ///< Array of register Write commands
    CSLTFERegRangeReadDescriptor regRangeCmd;                            ///< register read range command
    CSLTFERegWriteDescriptor     postregWriteCmd[TFEMaxDMIConfigWrites]; ///< Array of register Write commands
} CAMX_PACKED;

///@ brief TFE register read Info
struct CSLTFERegReadInfo
{
    UINT32 readType;                          ///< Read type
    UINT32 reserved;                          ///< Reserved field for future use
    union
    {
        CSLTFERegRangeReadDescriptor regReadCmd; ///< Register read Command
        CSLTFEDMIReadDesciptor       dmiReadCmd; ///< DMI Read Command
    } regDescriptor;
} CAMX_PACKED;

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

///@ brief TFE Reg Dump Descriptor
struct CSLTFERegDumpDescriptor
{
    UINT32            type;                                    ///< Reg Dump Type
    UINT32            bufferOffset;                            ///< Register Dump buffer offset
    UINT32            bufferSize;                              ///< Register Dump buffer Size
    UINT32            numberOfRegReadInfo;                     ///< Number of reg range read
    CSLTFERegReadInfo regReadInfo[TFEMaxNumRegReadInfoRanges]; ///< Register read Info
} CAMX_PACKED;

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

CAMX_END_PACKED

static const UINT32 TFERegDumpTypeTFELeft  = 1;
static const UINT32 TFERegDumpTypeTFERight = 2;
static const UINT32 TFERegDumpTypeCAMNOC   = 3;

static const UINT32 TFERegDumpReadTypeReg = 1;
static const UINT32 TFERegDumpReadTypeDMI = 2;

static const UINT32 TFEWMModeFrameBased = 0x0;  ///< WM Frame based Mode
static const UINT32 TFEWMModeLineBased  = 0x1;  ///< WM Line based Mode

/// @brief ISP TFE output Resource Information
struct CSLTFEOutResourceInfo
{
    UINT32 resourceType;       ///< Resource type
    UINT32 format;             ///< Format of the output
    UINT32 width;              ///< Width of the output image
    UINT32 height;             ///< Height of the output image
    UINT32 stride;             ///< Stride of output image
    UINT32 compositeGroupId;   ///< Composite Group id of the group
    UINT32 secureMode;         ///< Output port to be secure or non-secure
    UINT32 wmMode;             ///< Wm Mode
    UINT32 reserved;           ///< Reserved field
};

/// @brief ISP TFE input resource information
struct CSLTFEInResourceInfo
{
    UINT32                resourceType;      ///< Resource type
    UINT32                laneType;          ///< Lane type (dphy/cphy)
    UINT32                laneNum;           ///< Active lane number
    UINT32                laneConfig;        ///< Lane configurations: 4 bits per lane
    UINT32                VC;                ///< Virtual Channel
    UINT32                DT;                ///< Data Type
    UINT32                format;            ///< Input Image Format
    UINT32                pixPattern;        ///< Pixel Pattern
    UINT32                usageType;         ///< Single ISP or Dual ISP
    UINT32                leftStart;         ///< Left input start offset in pixels
    UINT32                leftStop;          ///< Left input stop offset in pixels
    UINT32                leftWidth;         ///< Left input Width in pixels
    UINT32                rightStart;        ///< Right input start offset in pixels
    UINT32                rightStop;         ///< Right input stop offset in pixels
    UINT32                rightWidth;        ///< Right input Width in pixels
    UINT32                lineStart;         ///< Start offset of the pixel line
    UINT32                lineStop;          ///< Stop offset of the pixel line
    UINT32                height;            ///< Input height in lines
    UINT32                batchSize;         ///< Batch size for HFR mode
    UINT32                DSPMode;           ///< DSP Mode
    UINT32                sensorWidth;       ///< Sensor width
    UINT32                sensorHeight;      ///< Sensor height
    UINT32                sensorHBI;         ///< Sensor HBI value
    UINT32                sensorVBI;         ///< Sensor VBI value
    UINT32                sensorFPS;         ///< Sensor fps
    UINT32                initFrameDrop;     ///< Init frame drop
    UINT32                numberOutResource; ///< Number of the output resource associated
    CSLTFEOutResourceInfo pDataField[1];     ///< Output Resource starting point
};

/// @brief ISP TFE input resource information version 2
struct CSLTFEInResourceInfoVer2
{
    UINT32                resourceType;      ///< Resource type
    UINT32                laneType;          ///< Lane type (dphy/cphy)
    UINT32                laneNum;           ///< Active lane number
    UINT32                laneConfig;        ///< Lane configurations: 4 bits per lane
    UINT32                VC[TFEMaxVC];      ///< Virtual Channel
    UINT32                DT[TFEMaxDT];      ///< Data Type
    UINT32                numValidVCDT;      ///< Num of valid VC DT
    UINT32                format;            ///< Input Image Format
    UINT32                pixPattern;        ///< Pixel Pattern
    UINT32                usageType;         ///< Single ISP or Dual ISP
    UINT32                leftStart;         ///< Left input start offset in pixels
    UINT32                leftStop;          ///< Left input stop offset in pixels
    UINT32                leftWidth;         ///< Left input Width in pixels
    UINT32                rightStart;        ///< Right input start offset in pixels
    UINT32                rightStop;         ///< Right input stop offset in pixels
    UINT32                rightWidth;        ///< Right input Width in pixels
    UINT32                lineStart;         ///< Start offset of the pixel line
    UINT32                lineStop;          ///< Stop offset of the pixel line
    UINT32                height;            ///< Input height in lines
    UINT32                batchSize;         ///< Batch size for HFR mode
    UINT32                DSPMode;           ///< DSP Mode
    UINT32                sensorWidth;       ///< Sensor width
    UINT32                sensorHeight;      ///< Sensor height
    UINT32                sensorHBI;         ///< Sensor HBI value
    UINT32                sensorVBI;         ///< Sensor VBI value
    UINT32                sensorFPS;         ///< Sensor fps
    UINT32                initFrameDrop;     ///< Init frame drop
    UINT32                numberOutResource; ///< Number of the output resource associated
    UINT32                featureFlag;       ///< Feature flags for indicating QCFA, Bayer bin
    UINT32                coreCfg;           ///< Core configuration
    UINT32                reserveField_1;    ///< Reserve field 1
    UINT32                reserveField_2;    ///< Reserve field 2
    UINT32                reserveField_3;    ///< Reserve field 3
    UINT32                reserveField_4;    ///< Reserve field 4
    UINT32                reserveField_5;    ///< Reserve field 5
    UINT32                reserveField_6;    ///< Reserve field 6
    CSLTFEOutResourceInfo pDataField[1];     ///< Output Resource starting point
};

/// @brief ISP TFE resource acquire Information
struct CSLTFEAcquireHWInfo
{
    UINT16 commonInfoVersion;             ///< Common Info Version represents the IFE common resource structure version
                                          ///< currently we dont have any common reosurce strcuture, It is reserved for future
                                          ///< HW changes in KMD
    UINT16 commonInfoSize;                ///< Common Info Size represents IFE common resource strcuture Size
    UINT32 commonInfoOffset;              ///< Common Info Offset represnts the Offset from where the TFE common resource
                                          ///< structure is stored in data
    UINT32 numInputs;                     ///< Number of IFE inpiut resources
    UINT32 inputInfoVersion;              ///< Input Info Strcure Version
    UINT32 inputInfoSize;                 ///< Size of the Input resource
    UINT32 inputInfoOffset;               ///< Offset where the Input resource structure starts in data
    UINT64 data;                          ///< TFE resource data
};

/// @brief ISP TFE clock configuration
struct CSLTFEClockConfig
{
    UINT32 usageType;                    ///< Usage type (Single/Dual)
    UINT32 numRDI;                       ///< Number of RDI votes
    UINT64 leftPixFreq;                  ///< Pixel Clock for Left TFE
    UINT64 rightPixFreq;                 ///< Pixel Clock for Right TFE, valid only if Dual TFE
    UINT64 rdiFreq[1];                   ///< RDI Clocks for TFE
};

/// @brief ISP CSID clock configuraion
struct CSLTFECSIDClockConfig
{
    UINT64                      csidClockFreq;  ///< CSID Clock Frequency
    UINT64                      phyClockFreq;   ///< Phy Clock Frequency
};

/// @brief Bandwidth configuration
struct CSLTFEBwConfigV2
{
    UINT32                     usage_type;      ///< Usage type (Single/Dual)
    UINT32                     num_paths;       ///< Number of axi data paths
    CSLAXIperPathBWVote        axi_path[1];     ///< Per path axi vote info
};

/// @brief TFE WM BW Limit Config
struct CSLTFEWMBWLimitConfig
{
    UINT32 portId;                     ///< TFE CSL PortId
    UINT32 isupdated;                  ///< Is port Enabled
    UINT32 bwLimitCounterLimit[3];   ///< TFE WM BW_LIMIT::COUNTER_LIMIT Config Value
};

/// @brief TFE WM BW Limit Config
struct CSLTFEBWLIMITConfig
{
    UINT32 version;                           ///< version field
    UINT32 numOutputPorts;                     ///< Number Of Output Ports
    struct CSLTFEWMBWLimitConfig BWLimit[3];   ///< TFE WM BW_LIMIT Config port
};

/// @brief TFE WM Config
struct CSLTFEWMConfig
{
    UINT32 portID;         ///< unique ID of output port
    UINT32 mode;           ///< Wm Mode
    UINT32 height;         ///< Height
    UINT32 width;          ///< Image width of the WM port
};

/// @brief TFE Out Config
struct CSLTFEOutConfig
{
    UINT32 numOutputPorts;                                     ///< Number Of Output Ports
    UINT32 reserved;                                           ///< Reserved Field for future use
    struct CSLTFEWMConfig outputPortConfig[TFEMaxOutputPorts]; ///< OutputPortConfig
};

/// @brief TFE Initial Frame drop configuration
struct CSLTFEInitialFrameDropConfig
{
    UINT32  numFrames;          ///< Number of frames to be dropped
    UINT32  version;            ///< API version
};

/// @brief Alignment Offset
struct CSLTFEAlignmentOffsetConfig
{
    UINT32 resource_type; ///< resource type
    UINT32 x_offset;      ///< bufferoffset
    UINT32 y_offset;      ///< bufferoffset
    UINT32 width;         ///< width  resolution
    UINT32 height;        ///< height resolution
    UINT32 stride;        ///< Increased stride
};

/// @brief Alignment Offset
struct CSLTFEAlignmentInfo
{
    UINT32 version;    ///< version field
    UINT32 num_ports;  ///< number of ports
    struct CSLTFEAlignmentOffsetConfig alignmentoffset; ///< alignmentoffset
};

#endif // CAMXCSLTFEDEFS_H
