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

#include "loader_if.h"

typedef enum _BELFrmType
{
	I_FRAME=0,
	F_FRAME,
	D_FRAME,
    FRAME_END
} BE_FRM_TYP_T;

typedef enum _BELBootState
{
	I_STATE=1,
	F_STATE,
	D_STATE,
    STATE_END
} BE_BOOT_STATE_T;

typedef enum _BELPktContainer
{
	eDDRI=0,
	eMLFW,
	eLDAT,
	eMAFW,
	eDFW1,
	eDFW2,
	ePDAT,
	eBDAT,
	eNDAT,
	eFDAT,
	eUDAT,
	eBDIX,
	eMINF,
	eBDT0,
	eBDT1,
	eBDT2,
	eBDT3,
	eBDT4,
	eBDT5,
	eBDT6,
	eBDT7,
	eBDT8,
	eBDT9,
	eBDTA,
	eBDTB,
	eBDTC,
	eBDTD,
	eBDTE,
	eBDTF,
	eEND=0xFF
} BE_PKT_CONTAINER_T;

#define LOADER_BE_BOOT_HEAD_KEY  (0x34373533)
#define LOADER_BE_BOOT_FOOT_KEY  (0x33353734)

#define LOADER_BE_BOOT_FRAME_NO_1      (1)
#define LOADER_BE_BOOT_FRAME_NO_2      (2)
#define LOADER_BE_BOOT_FRAME_NO_3      (3)
#define LOADER_BE_BOOT_FRAME_NO_4      (4)
#define LOADER_BE_BOOT_FRAME_NO_5      (5)


#define LOADER_BE_BOOT_TOTAL_FRAME_NO_1      (1)
#define LOADER_BE_BOOT_TOTAL_FRAME_NO_2      (2)
#define LOADER_BE_BOOT_TOTAL_FRAME_NO_3      (3)
#define LOADER_BE_BOOT_TOTAL_FRAME_NO_4      (4)
#define LOADER_BE_BOOT_TOTAL_FRAME_NO_5      (5)

#define LOADER_BE_BOOT_TOTAL_PACKET_NO_1      (1)
#define LOADER_BE_BOOT_TOTAL_PACKET_NO_2      (2)
#define LOADER_BE_BOOT_TOTAL_PACKET_NO_3      (3)
#define LOADER_BE_BOOT_TOTAL_PACKET_NO_4      (4)
#define LOADER_BE_BOOT_TOTAL_PACKET_NO_5      (5)
#define LOADER_BE_BOOT_TOTAL_PACKET_NO_6      (6)
#define LOADER_BE_BOOT_TOTAL_PACKET_NO_7      (7)

#define BEL_BOOT_POWER_ON_GPIO       (GPIO(209))
#define BEL_BOOT_POWER_ON_POLARITY   (0)
#define BEL_BOOT_UP_NOTIFY_GPIO      (GPIO(267))
#define BEL_BOOT_UP_NOTIFY_POLARITY  (1)
#define BEL_BOOT_VX1_REQ_GPIO        (GPIO(50))
#define BEL_BOOT_VX1_REQ_POLARITY    (1)
#define BEL_BOOT_PNL_PWR_NOTIFY_GPIO (GPIO(268))
#define BEL_BOOT_PNL_PWR_NOTIFY_POLARITY  (1)
#define FLASH_BE_BASE_PARTITION       (26)
#define FLASH_BE_MINF_BASE_PARTITION  (38)

static const BE_FRAME_CONFIG_T _arSONYBeCfgTable[] =
{
#if 1//def CC_MTK_LOADER
	{ I_FRAME, I_STATE, LOADER_BE_BOOT_FRAME_NO_1, LOADER_BE_BOOT_HEAD_KEY, 
	  LOADER_BE_BOOT_TOTAL_FRAME_NO_1, LOADER_BE_BOOT_TOTAL_PACKET_NO_1, LOADER_BE_BOOT_FOOT_KEY, 
	  {eDDRI,eEND,eEND,eEND,eEND,eEND,eEND}},
	  
	{ F_FRAME, F_STATE, LOADER_BE_BOOT_FRAME_NO_1, LOADER_BE_BOOT_HEAD_KEY, 
	  LOADER_BE_BOOT_TOTAL_FRAME_NO_1, LOADER_BE_BOOT_TOTAL_PACKET_NO_3, LOADER_BE_BOOT_FOOT_KEY,
	  {eMLFW,eBDIX,eLDAT,eEND,eEND,eEND,eEND}},
	  
	{ F_FRAME, D_STATE, LOADER_BE_BOOT_FRAME_NO_1, LOADER_BE_BOOT_HEAD_KEY,
	  LOADER_BE_BOOT_TOTAL_FRAME_NO_5, LOADER_BE_BOOT_TOTAL_PACKET_NO_1, LOADER_BE_BOOT_FOOT_KEY,
	  {eMAFW,eEND,eEND,eEND,eEND,eEND,eEND}},
	  
	{ D_FRAME, D_STATE, LOADER_BE_BOOT_FRAME_NO_2, LOADER_BE_BOOT_HEAD_KEY,
	  LOADER_BE_BOOT_TOTAL_FRAME_NO_5, LOADER_BE_BOOT_TOTAL_PACKET_NO_2, LOADER_BE_BOOT_FOOT_KEY,
	  {eDFW1,eDFW2,eEND,eEND,eEND,eEND,eEND}},
	  
	{ D_FRAME, D_STATE, LOADER_BE_BOOT_FRAME_NO_3, LOADER_BE_BOOT_HEAD_KEY,
	  LOADER_BE_BOOT_TOTAL_FRAME_NO_5, LOADER_BE_BOOT_TOTAL_PACKET_NO_4, LOADER_BE_BOOT_FOOT_KEY,
	  {eBDAT,eNDAT,ePDAT,eFDAT,eEND,eEND,eEND}},
	  
    { D_FRAME, D_STATE, LOADER_BE_BOOT_FRAME_NO_4, LOADER_BE_BOOT_HEAD_KEY,
      LOADER_BE_BOOT_TOTAL_FRAME_NO_5, LOADER_BE_BOOT_TOTAL_PACKET_NO_5, LOADER_BE_BOOT_FOOT_KEY,
      {eBDT0,eBDT1,eBDT2,eBDT3,eBDT4,eEND,eEND}},

    { D_FRAME, D_STATE, LOADER_BE_BOOT_FRAME_NO_5, LOADER_BE_BOOT_HEAD_KEY,
      LOADER_BE_BOOT_TOTAL_FRAME_NO_5, LOADER_BE_BOOT_TOTAL_PACKET_NO_4, LOADER_BE_BOOT_FOOT_KEY,
      {eBDT5,eBDT6,eBDT7,eBDT8,eEND,eEND,eEND}}
#else	
    { I_FRAME, I_STATE, LOADER_BE_BOOT_FRAME_NO_1, LOADER_BE_BOOT_HEAD_KEY, 
	  LOADER_BE_BOOT_TOTAL_FRAME_NO_1, LOADER_BE_BOOT_TOTAL_PACKET_NO_1, LOADER_BE_BOOT_FOOT_KEY, 
	  {eDDRI,eEND,eEND,eEND,eEND,eEND,eEND}},
	  
	{ F_FRAME, F_STATE, LOADER_BE_BOOT_FRAME_NO_1, LOADER_BE_BOOT_HEAD_KEY, 
	  LOADER_BE_BOOT_TOTAL_FRAME_NO_1, LOADER_BE_BOOT_TOTAL_PACKET_NO_3, LOADER_BE_BOOT_FOOT_KEY,
	  {eMLFW,eBDIX,eLDAT,eEND,eEND,eEND,eEND}},
	  
	{ F_FRAME, D_STATE, LOADER_BE_BOOT_FRAME_NO_1, LOADER_BE_BOOT_HEAD_KEY,
	  LOADER_BE_BOOT_TOTAL_FRAME_NO_3, LOADER_BE_BOOT_TOTAL_PACKET_NO_1, LOADER_BE_BOOT_FOOT_KEY,
	  {eMAFW,eEND,eEND,eEND,eEND,eEND,eEND}},
	  
	{ D_FRAME, D_STATE, LOADER_BE_BOOT_FRAME_NO_2, LOADER_BE_BOOT_HEAD_KEY,
	  LOADER_BE_BOOT_TOTAL_FRAME_NO_3, LOADER_BE_BOOT_TOTAL_PACKET_NO_2, LOADER_BE_BOOT_FOOT_KEY,
	  {eDFW1,eDFW2,eEND,eEND,eEND,eEND,eEND}},
	  
	{ D_FRAME, D_STATE, LOADER_BE_BOOT_FRAME_NO_3, LOADER_BE_BOOT_HEAD_KEY,
	  LOADER_BE_BOOT_TOTAL_FRAME_NO_3, LOADER_BE_BOOT_TOTAL_PACKET_NO_4, LOADER_BE_BOOT_FOOT_KEY,
	  {eBDAT,eNDAT,ePDAT,eFDAT,eEND,eEND,eEND}}

#endif
};

#define BE_FRAME_CONFIG_TABLE     (&_arSONYBeCfgTable)
#define BE_FRAME_CONFIG_SIZE      (sizeof(_arSONYBeCfgTable)/sizeof(BE_FRAME_CONFIG_T))

