/*******************************************************************************
 * Copyright (c) 2022-2024 Renesas Electronics Corporation. All rights reserved.
 *
 *     RENESAS ELECTRONICS CONFIDENTIAL AND PROPRIETARY
 *
 * This software is provided as reference/sample code under the license
 * agreement between Renesas Electronics Corporation and licensee (the
 * "License Agreement") and shall be treated as specified in the License
 * Agreement.
 * These instructions, statements, and software are the confidential
 * information of Renesas Electronics Corporation. They must be used and
 * modified solely for the purpose for which it was furnished by Renesas
 * Electronics Corporation. All or part of these instructions, statements and
 * software must not be reproduced nor disclosed to any third party in any
 * form, unless permitted by the License Agreement.
 *
 * THIS SOFTWARE IS PROVIDED BY RENESAS ELEOCTRONICS CORPORATION "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
 * SATISFACTORY QUALITY, ACCURACY, TITLE AND NON-INFRINGEMENT ARE DISCLAIMED.
 * IN NO EVENT SHALL RENESAS ELECTRONICS CORPORATION BE LIABLE FOR ANY DIRECT,
 * INDIRECT, INCIDENTAL, SPECIAL, PUNITIVE, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * 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.
 ******************************************************************************/

/*******************************************************************************
 * DESCRIPTION   : ECC driver header
 ******************************************************************************/

#ifndef ECC_PROTECT
#define ECC_PROTECT
#include "remap_register.h"
/* DBSC registers */
#if defined(__RH850G3K__)
#include "mem_io.h"
#include "log.h"
#define DBSC_D_BASE			  (BASE_DBSC_ADDR + 0x14000U)	/* forV4H DBSC0 clk_dbsc region	DBSC1_D_BASE = 0xE67A8000U */
#define DBSC_A_BASE			  (BASE_DBSC_ADDR)	            /* forV4H DBSC0 clk_axim region	DBSC1_A_BASE = 0xE6798000U */
#define ECM_BASE              (BASE_ECC_ADDR)
#else
#include <mmio.h>
#include <debug.h>
#define DBSC_D_BASE			  (0xE67A4000U)	                /* forV4H DBSC0 clk_dbsc region	DBSC1_D_BASE = 0xE67A8000U */
#define DBSC_A_BASE			  (0xE6790000U)	                /* forV4H DBSC0 clk_axim region	DBSC1_A_BASE = 0xE6798000U */
#define ECM_BASE              (0xE6250000U)
#endif/* defined(__RH850G3K__) */

#define RTVRAM_REG_BASE    (0xFFEC0000U)

void edc_axi_enable(void);
void edc_vram_enable(void);

#define DB0SYSCNT0            (DBSC_D_BASE + 0x0100U)
#define DB0SYSCNT0A           (DBSC_A_BASE + 0x0100U)
#define DB1SYSCNT0            (DB0SYSCNT0 +  0x4000U)
#define DB1SYSCNT0A           (DB0SYSCNT0A + 0x8000U)

#define	DBSC_DBACEN0		  (DBSC_A_BASE + 0x0200U)
#define	DBSC_DBACEN1		  (DBSC_DBACEN0 + 0x8000U)

#define ECMWACNTR             (ECM_BASE + 0x0A04U)
#define ECMWPCNTR             (ECM_BASE + 0x0A00U)
#define ECMERRTGTR0           (ECM_BASE + 0x0200U)
#define ECMERRCTLR0           (ECM_BASE + 0x0000U)
#define ECMERRTGTR1           (ECM_BASE + 0x0200U + 0x4U * 1U)
#define ECMERRCTLR1           (ECM_BASE + 0x0000U + 0x4U * 1U)
#define ECMERRTGTR7           (ECM_BASE + 0x0200U + 0x4U * 7U)
#define ECMERRCTLR7           (ECM_BASE + 0x0000U + 0x4U * 7U)
#define ECMERRTGTR17          (ECM_BASE + 0x0200U + 0x4U * 17U)
#define ECMERRCTLR17          (ECM_BASE + 0x0000U + 0x4U * 17U)
#define ECMERRTGTR39          (ECM_BASE + 0x0200U + 0x4U * 39U)
#define ECMERRCTLR39          (ECM_BASE + 0x0000U + 0x4U * 39U)
#define DB0FSCONF00A          (DBSC_A_BASE    + 0x7640U)
#define DB1FSCONF00A          (DB0FSCONF00A   + 0x8000U)
#define DB0FSCONF01A          (DBSC_A_BASE    + 0x7644U)
#define DB1FSCONF01A          (DB0FSCONF01A   + 0x8000U)
#define DB0FSCONF02A          (DBSC_A_BASE    + 0x7648U)
#define DB1FSCONF02A          (DB0FSCONF02A   + 0x8000U)
#define DB0FSCTRL01A          (DBSC_A_BASE    + 0x7604U)
#define DB1FSCTRL01A          (DB0FSCTRL01A   + 0x8000U)
#define DB0FSSTAT01A          (DBSC_A_BASE    + 0x7684U)
#define DB1FSSTAT01A          (DB0FSSTAT01A   + 0x8000U)
#define DB0FSSTAT00A          (DBSC_A_BASE    + 0x7680U)
#define DB1FSSTAT00A          (DB0FSSTAT00A   + 0x8000U)
#define DB0FSINTENB02A        (DBSC_A_BASE    + 0x7088U)
#define DB1FSINTENB02A        (DB0FSINTENB02A + 0x8000U)
#define DB0FSINTENB04A        (DBSC_A_BASE    + 0x7090U)
#define DB1FSINTENB04A        (DB0FSINTENB04A + 0x8000U)

#define DB0FSDRAMECCAREA0     (DBSC_A_BASE + 0x7450U)
#define DB0FSDRAMECCAREA1     (DBSC_A_BASE + 0x7454U)
#define DB1FSDRAMECCAREA0     (DB0FSDRAMECCAREA0 + 0x8000U)
#define DB1FSDRAMECCAREA1     (DB0FSDRAMECCAREA1 + 0x8000U)

#define DB0FSCONFAXI0        (DBSC_A_BASE   + 0x7400U)
#define DB1FSCONFAXI0        (DB0FSCONFAXI0 + 0x8000U)

#define EDC_CFG	              (RTVRAM_REG_BASE + 0x4110U)

/********************* Set by the user *********************/
/* The row address of ECC Protection Area Size for memory rank 0/1 of DBSC0/1 */
#define ECC_PROT_SIZE00        (0x1000U)
#define ECC_PROT_SIZE01        (0x1000U)
#define ECC_PROT_SIZE10        (0x1000U)
#define ECC_PROT_SIZE11        (0x1000U)

/* Start and End row address of ECC Protection area for rank0 of DBSC0/1 */
#define START_ECC_INIT_AREA00   (0x00000000U)
#define START_ECC_INIT_AREA10   (0x00000000U)
#define END_ECC_INIT_AREA00     (0x00000FFFU)
#define END_ECC_INIT_AREA10     (0x00000FFFU)

/* Start and End row address of ECC Protection area for rank1 of DBSC0/1 */
#define START_ECC_INIT_AREA01   (0x00000000U)
#define START_ECC_INIT_AREA11   (0x00000000U)
#define END_ECC_INIT_AREA01     (0x00000FFFU)
#define END_ECC_INIT_AREA11     (0x00000FFFU)
/***********  Other settings cannot be changed ***************/

#endif/* ECC_PROTECT */
