/* Copyright(C) 2019 MediaTek Inc. */
/* SPDX-License-Identifier: GPL-2.0-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 of the GNU General Public License ("GPLv2 License")
 * or BSD License.
 *
 * GPLv2 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 of the GNU 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 http://www.gnu.org/licenses/gpl-2.0.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.
 *
 *****************************************************************************/
#ifndef _MS_UTILS_H_
#define _MS_UTILS_H_

typedef enum {
    E_MS_UTIL_BIN_TYPE_MAIN,
    E_MS_UTIL_BIN_TYPE_DLG,
    E_MS_UTIL_BIN_TYPE_MAX
}EN_MS_UTIL_BIN_TYPE;

typedef enum
{
    E_MS_UTIL_BIN_ACT_OFF,
    E_MS_UTIL_BIN_ACT_FIRST = E_MS_UTIL_BIN_ACT_OFF,
    E_MS_UTIL_BIN_ACT_ON,
    E_MS_UTIL_BIN_ACT_LAST = E_MS_UTIL_BIN_ACT_ON ,
    E_MS_UTIL_BIN_ACT_NO_DLG,
    E_MS_UTIL_BIN_ACT_MAX
}EN_MS_UTIL_BIN_ACT;

typedef enum
{
    E_MS_UTIL_BIN_FILE_NORMAL,
    E_MS_UTIL_BIN_FILE_BACKLIGHT,
    E_MS_UTIL_BIN_FILE_BACKLIGHT_ONLY,
    E_MS_UTIL_BIN_FILE_MAX
}EN_MS_UTIL_BIN_File;

typedef enum
{
    E_MS_UTIL_BLOCK_SIZE_H4V4,
    E_MS_UTIL_BLOCK_SIZE_H4V8,
    E_MS_UTIL_BLOCK_SIZE_H4V16,

    E_MS_UTIL_BLOCK_SIZE_H8V4,
    E_MS_UTIL_BLOCK_SIZE_H8V8,
    E_MS_UTIL_BLOCK_SIZE_H8V16,

    E_MS_UTIL_BLOCK_SIZE_H16V4,
    E_MS_UTIL_BLOCK_SIZE_H16V8,
    E_MS_UTIL_BLOCK_SIZE_H16V16,
    E_MS_UTIL_BLOCK_SIZE_MAX
}EN_MS_UTIL_BLOCK_SIZE;

MS_BOOL init_spi_flash(void);
MS_BOOL read_spi_flash(MS_U8 *pBuf, MS_U32 pos, MS_U32 length);
//MS_BOOL mark_sf_by_mstar(MS_U32 sf_dat_oft, MS_U8 *pdat, MS_U32 dat_len);
//MS_BOOL sf_match_by_mstar(void);
MS_BOOL clear_raw_data_soemcrc(void);
MS_BOOL clear_raw_data(void);
MS_BOOL write_raw_data(MS_U8 *pdat, MS_U32 partition_oft, MS_U32 dat_len);
MS_BOOL write_raw_data_soemcrc(MS_U8 *pdat, MS_U32 partition_oft, MS_U32 dat_len);
MS_BOOL read_raw_data(MS_U8 *pdat, MS_U32 partition_oft, MS_U32 dat_len);
MS_BOOL get_large_memory(MS_PHY *pmem_addr, MS_U32 req_len);

MS_BOOL get_demura_env_bypass_write_fs(MS_BOOL bsti);

void set_demura_bin_type(MS_U8 u8type); // EN_MS_UTIL_BIN_TYPE
MS_U8 get_demura_bin_type(void);

void set_demura_act(MS_U8 act);
MS_U8 get_demura_act(void);

void set_demura_file(MS_U8 file);
MS_U8 get_demura_file(void);
MS_BOOL get_demura_dlg_is_enable(void);
void set_demura_block_size(MS_U8 file);
MS_U8 get_demura_block_size(void);
#endif
