/* Copyright Statement:
 *
 * This software/firmware and related documentation ("MediaTek Software") are
 * protected under relevant copyright laws. The information contained herein is
 * confidential and proprietary to MediaTek Inc. and/or its licensors. Without
 * the prior written permission of MediaTek inc. and/or its licensors, any
 * reproduction, modification, use or disclosure of MediaTek Software, and
 * information contained herein, in whole or in part, shall be strictly
 * prohibited.
 *
 * Copyright  (C) [2020]  MediaTek Inc. All rights reserved.
 *
 * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
 * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
 * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
 * ON AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL
 * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
 * NONINFRINGEMENT. NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH
 * RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
 * INCORPORATED IN, OR SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES
 * TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
 * RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
 * OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN MEDIATEK
 * SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE
 * RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
 * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S
 * ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE
 * RELEASED HEREUNDER WILL BE, AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE
 * MEDIATEK SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
 * CHARGE PAID BY RECEIVER TO MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
 *
 * The following software/firmware and/or related documentation ("MediaTek
 * Software") have been modified by MediaTek Inc. All revisions are subject to
 * any receiver's applicable license agreements with MediaTek Inc.
 */

#ifndef _ROM_TABLE_IMPL_HEADER_
#define _ROM_TABLE_IMPL_HEADER_
#include <linux/list.h>
#include <mtk_romtblo.h>

#define ROMTBL_HEADER_SIZE      (32)
#define ROMTBL_SIZE             (16*1024)
#define ROMTBL_DEVENTRY_SIZE    (15*1024)
#define ROMTBL_REGISTER_SIZE    (16)
#define ROMTBL_REGISTER_PAIR    (4)
#define ROMTBL_CAPABILITY_SIZE  (4)
#define ROMTBL_64BIT_HIGH_BYTE_VALUE  (0x0)
#define GIC_INTERRUPT_BASE      (0x20)
#define MEDIATEK_TV_CHIP_ID_MACHLI	(5896)
#define MEDIATEK_TV_CHIP_ID_MANKS	(5897)
#define MEDIATEK_TV_CHIP_ID_MOKONA	(5876)
#define MEDIATEK_TV_CHIP_ID_MIFFY	(5879)
#define MEDIATEK_TV_CHIP_ID_MOKA	(5873)
#define CHIP_HARDWARE_KEY   "androidboot.vendor.cf.hardware"
#define CHIP_HARDWAREREV_KEY   "androidboot.vendor.cf.hardwarerev"
#define CHIP_ID_CHAR   "MT"
#define CHIP_REVISION_CHAR   "E"
#define BUFFER_SIZE     64
#define CHIP_ID_BYTE_COUNT     (4)
#define HEX_DIG_SIZE    (0x10)
#define BINARY_PRE_BYTE     (4)
#define BIT_PRE_BYTE     (8)
#define DECIMAL_BASE     (10)
#define CHIP_ID_BASE     (22)
#define REVISION_BASE     (18)


enum CHIP_FAMILY_ID{
    MT5896 = 0,
    MT5897,
    MT5876,
    MT5879,
    MT5873,
    NOT_SUPPORT
};

typedef struct{
    int interrupt_base;
    int size;
    struct list_head list;
}ROM_GIC_LIST_T;

typedef struct
{
    unsigned int major_ver;
    unsigned int minor_ver;
    unsigned int chip;
    unsigned int revision;
}romtbl_header;

typedef struct
{
    unsigned short unique_id;                     // 2 Bytes
    unsigned char hw_ip_major_ver;               // 1 Byte
    unsigned char hw_ip_minor_ver;               // 1 Byte
    unsigned short gic_interrupt_num;           // 2 Bytes
    unsigned short register_size;                 // 2 Bytes
    unsigned int register_base_addr;          // 4 Bytes
    unsigned int register_size_array[ROMTBL_REGISTER_SIZE];             // 4 Bytes * 12
    unsigned int register_base_add_array[ROMTBL_REGISTER_SIZE];      // 4 Bytes * 12
    unsigned int capability[ROMTBL_CAPABILITY_SIZE];                // 4 Bytes or 4*4 Bytes Extension
} __attribute__((packed)) romtbl_info;

int romtbl_get_chip_id_info(void);
#endif /* _ROM_TABLE_IMPL_HEADER_ */
