/*
 * Copyright (c) 2015-2019, Renesas Electronics Corporation.
 * All rights reserved.
 */

#include <stdint.h>
#include <string.h>
#include <stdio.h>
#include <mmio.h>
#include <debug.h>

#include "../V3M/boot_init_dram_regdef_v3m.h"
#include "init_dram_tbl_chk.h"
#include "init_dram_tbl_v3m.h"

int32_t InitDram_regcheck(void)
{
	int32_t		err;

	uint32_t	i;
	uint32_t	dataL;

	err = 0;

	mmio_write_32(DBSC_V3M_DBSYSCNT0, 0x00001234);
	mmio_write_32(DBSC_V3M_DBPDLK0, 0x0000A55A);

	for (i = 0; i < DDR_PHY_REGSET_NUM_V3M; i++) {
		if (DDR_PHY_REGCHK[i/32] & (1U << (i%32))) {
			mmio_write_32(DBSC_V3M_DBPDRGA0, i);
			dataL = mmio_read_32(DBSC_V3M_DBPDRGD0);

			if (dataL != DDR_PHY_REGSET_V3M[i]) {
				ERROR("REG[0x%x] = 0x%x ->  0x%x\n", i, DDR_PHY_REGSET_V3M[i], dataL);
				err = 1;
			}
		}
	}

	mmio_write_32(DBSC_V3M_DBPDLK0, 0x00000000);
	mmio_write_32(DBSC_V3M_DBSYSCNT0, 0x00000000);


	return err;
}
