/* 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.
 *
 *****************************************************************************/

/*-----------------------------------------------------------------------------
 *
 * $Author: dtvbm11 $
 * $Date: 2015/11/10 $
 * $RCSfile: drv_bnr_int.h,v $
 * $Revision: #1 $
 *
 *---------------------------------------------------------------------------*/
#ifndef _DRV_BNR_INT_H_
#define _DRV_BNR_INT_H_

#ifdef _C_MODEL_
#include "drv_common.h"
#endif

#define BNR_NEW_FW

#define SUPPORT_BNR_SIZE_PHASE_PREDICT

/*
 * definitions
 */
#define _NXNR_BNR_FW_MAX_WIDTH  1920
#define _NXNR_BNR_FW_MAX_HEIGHT 1088

#ifndef BNR_NEW_FW
#define _NXNR_BNR_FW_MAX_SIZE   1920 // max of width and height
#define _NXNR_BNR_FW_MIN_PERIOD     8
#define _NXNR_BNR_FW_MAX_PERIOD     33
#else   // BNR_NEW_FW
#define _NXNR_BNR_FW_MAX_DIMENSION   1920 // max of width and height
#define _NXNR_BNR_FW_MIN_PERIOD     3
#define _NXNR_BNR_FW_MAX_PERIOD     32
#define _NXNR_BNR_FW_MAX_MAJOR_PERIOD       128
#define _NXNR_BNR_FW_MAX_MINOR_PERIOD_COUNT 10
#define _NXNR_HBLK 0
#define _NXNR_VBLK 1
#define _NXNR_DEF_MNR_GAIN 0x16;
#endif  // BNR_NEW_FW

#define _NXNR_BNR_FW_STATE_STOP        -1
#define _NXNR_BNR_FW_STATE_INIT         0
#define _NXNR_BNR_FW_STATE_ACTIVE       1
#define _NXNR_BNR_FW_STATE_VSYNC        2
#define _NXNR_BNR_FW_STATE_DBG          3
#define _NXNR_BNR_FW_STATE_VSYNC_DBG    4

#define _NXNR_VBLK_GROUP_COUNT 2
#define _NXNR_VBLK_GROUP_MEMBER_COUNT 9

#define _NXNR_BNR_FW_LOG_STA              1
#define _NXNR_BNR_FW_LOG_VBLK_PEROID_HIST 2
#define _NXNR_BNR_FW_LOG_HBLK_PEROID_HIST 3

#ifdef SUPPORT_BNR_SIZE_PHASE_PREDICT
#define MAX_NUM_GRID (9)
#define BNR_MAX_SIZE (128)
#define BNR_NODE(n, r) (((n)<<4) | (r))
#define BNR_NODE_N(node) ((node)>>4)
#define BNR_NODE_R(node) ((node)&0xF)
#define BNR_SIZE(p, node) ((p)*BNR_NODE_N(node) + BNR_NODE_R(node))

#define NUM_NODE (28)

typedef struct
{
    UINT32 u4S;
    UINT32 u4P;
    UINT32 u4Start;
    UINT32 u4StartIdx;
    UINT32 u4LsInside;
    UINT32 u4LsOutside;
    UINT8  u1GridPos[MAX_NUM_GRID];
    UINT8  u1PSeq[MAX_NUM_GRID];
} BNR_DESC_T;

#endif

/*
 * forward declarations
 */
#ifdef _C_MODEL_
class CNXNR;
#endif

/*
 * functions
 */
#ifdef _C_MODEL_
void BNR_FW_Initialize ( CNXNR * _pNXNR, const char * _szPatternName );
void BNR_FW_ActiveProcess (void);
void BNR_FW_VSyncProcess (void);
BOOL BNR_FW_IsStop(void);
void BNR_FW_Stop(void);
void BNR_FW_Resume(void);
void BNR_FW_Dbg(void);
void BNR_FW_SetLogCfg(UINT8 u1Sel, UINT32 u4Cnt);
#else
EXTERN void BNR_FW_Initialize(UINT32 u4Width, UINT32 u4Height);
EXTERN void BNR_FW_ActiveProcess (void);
EXTERN void BNR_FW_VSyncProcess (void);
EXTERN BOOL BNR_FW_IsStop(void);
EXTERN void BNR_FW_Stop(void);
EXTERN void BNR_FW_Resume(void);
EXTERN void BNR_FW_Dbg(void);
EXTERN void BNR_FW_SetLogCfg(UINT8 u1Sel, UINT32 u4Cnt);
#endif
#endif //_DRV_BNR_INT_H_
